Guest User

Untitled

a guest
Nov 28th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #!/bin/ruby
  2. require 'fileutils'
  3. VARIANT='standard' #where to get the `pins_arduino.h` file
  4. CPUFREQ="16000000UL"
  5. MCU="atmega328p"
  6.  
  7. CFLAGS="-Os -Wl,--gc-sections -ffunction-sections -fdata-sections"
  8. CPPFLAGS="-Os -Wl,--gc-sections -ffunction-sections -fdata-sections"
  9.  
  10. ARFLAGS=""
  11.  
  12. CC="avr-gcc"
  13. CPP="avr-g++"
  14. AR="avr-ar"
  15.  
  16.  
  17. SOURCES="src"
  18. OUTPUTS="output"
  19.  
  20. def getfiles(dir, ending)
  21. t=""
  22. Dir["#{dir}/*.#{ending}"].each{ |f| t+='"'+File.basename(f)+'" '; }
  23. t
  24. end
  25.  
  26. def domake(src, action, objs,hdrs, cppflags, cflags, arflags, out, lib)
  27. `make -C #{src} #{action} OBJS="#{objs}" CPPFLAGS="#{CPPFLAGS} #{cppflags}" CFLAGS="#{CFLAGS} #{cflags}"\
  28. ARFLAGS="#{arflags}" OUTPUTS="#{out}" HDRS="#{hdrs}" LIBOUT="#{lib}" \
  29. AR="#{AR}" CC="#{CC}" CPP="#{CPP}" `
  30. #make sure to redirect STDOUT to STDERR so it's visible
  31. end
  32.  
  33. if ARGV.length < 2
  34. puts 'usage: ./build.rb action library'
  35. exit
  36. end
  37.  
  38.  
  39. #`mkdir -p output/include` #syntax error
  40. #`mkdir -p output/lib`
  41. require 'fileutils'
  42. FileUtils.mkdir_p 'output/include'
  43. FileUtils.mkdir_p 'output/lib'
  44. `cp variants/#{VARIANT}/pins_arduino.h #{OUTPUTS}/include/`
  45.  
  46. action=ARGV[0]
  47. library=ARGV[1]
  48.  
  49. dir="#{SOURCES}/#{library}"
  50. `cp template.makefile #{SOURCES}/#{library}/Makefile`
  51. objs=getfiles(dir, "o");
  52. out="../../#{OUTPUTS}"
  53. hdrs=getfiles(dir, "h")
  54. cflags="-I#{out}/include -I./ -I./utility/ -I../../variants/#{VARIANT} -I\"../../#{OUTPUTS}/include\" -mmcu=#{MCU} -DF_CPU=#{CPUFREQ}"
  55. cppflags=cflags
  56. arflags=""
  57.  
  58. domake("#{dir}", action, objs, hdrs, cppflags, cflags, arflags, out, "lib#{library}.a")
  59.  
  60. `rm -f "#{SOURCES}/#{library}/Makefile"`
  61. `mv #{SOURCES}/#{library}/lib#{library}.a #{OUTPUTS}/lib/`
Advertisement
Add Comment
Please, Sign In to add comment