TheLegace

Makefil

Sep 7th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 4.30 KB | None | 0 0
  1. ## Makefile for Atmel AVR programs and associated utilities
  2. ## Copyleft (!C) Mark A. Post, 2007
  3.  
  4. # Target environment
  5. FREQUENCY=14745600
  6. #FREQUENCY=1843200
  7. #FREQUENCY=8000000
  8. #FREQUENCY=1000000
  9. BAUDRATE=115200
  10. #BAUDRATE=9600
  11. MCU=atmega644p
  12. #MCU=atmega1281
  13. #MCU=atmega168
  14. #MCU=attiny461
  15. #MCU=attiny2313
  16. PROG_METHOD=avrispmkII
  17. #PROG_METHOD=stk500v2
  18. PORT=usb
  19. #PORT=/dev/ttyUSB1
  20.  
  21. # Development environment
  22. CC=avr-gcc
  23. DEVCC=gcc
  24. OBJCOPY=avr-objcopy
  25. STRIP=avr-strip
  26. PROG=avrdude
  27. OBJDUMP=avr-objdump
  28. AR=avr-ar
  29.  
  30. # Build options
  31. CDEFINES=-DF_CPU=$(FREQUENCY) -DBAUD=$(BAUDRATE)
  32. #for <4MHz MCU, OPTS=-B 4, reliable at -B 10 for USB
  33. ifeq ($(PORT),usb)
  34.     OPTS=-B 10
  35. else
  36.     OPTS=-B 2
  37. endif
  38. #for optimization: CFLAGS=-mmcu=$(MCU) -Wall -Os -mcall-prologues
  39. #WARNING: any optimization levels above -O0 may cause instability
  40. CFLAGS=-mmcu=$(MCU) -Wall $(CDEFINES) -O0 -Iyaml-0.1.4/include
  41. #for i686 and x86_64 in Gentoo Linux:
  42. LDFLAGS=-L. -lm -lc -lm -luavr -L/usr/i686-pc-linux-gnu/avr/lib -L/usr/x86_64-pc-linux-gnu/avr/lib
  43.  
  44. # Libraries
  45. LIBS=libuavr.a
  46. LIBSRCS=\
  47.     lib/general.c\
  48.     lib/interrupt.c\
  49.     lib/timer.c\
  50.     lib/serial.c\
  51.     lib/spi.c\
  52.     lib/i2c.c\
  53.     lib/adc.c\
  54.     lib/eeprom.c\
  55.     lib/motor.c\
  56.     lib/terminal.c\
  57.     $(NULL)
  58. LIBOBJS=$(LIBSRCS:.c=.o)
  59.  
  60. YAML=libyaml.a
  61. YAMLSRCS=yaml-0.1.4/src/yaml_private.h \
  62.     yaml-0.1.4/src/api.c\
  63.     yaml-0.1.4/src/reader.c\
  64.     yaml-0.1.4/src/scanner.c\
  65.     yaml-0.1.4/src/parser.c\
  66.     yaml-0.1.4/src/loader.c writer.c\
  67.     yaml-0.1.4/src/emitter.c\
  68.     yaml-0.1.4/src/dumper.c\
  69.     $(NULL)
  70. YAMLOBJS=$(YAMLSRCS:.c=.o)
  71.  
  72. # Rules
  73. %: %.hex
  74.  
  75. %.o: %.c
  76.     $(CC) -c $^ -o $@ $(CFLAGS)
  77.  
  78. %.bin: %.o $(LIBS)
  79.     $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
  80.  
  81. %.asm: %.bin
  82.     $(OBJDUMP) -S -d $^ > $@
  83.  
  84. %-stripped: %.bin
  85.     $(STRIP) $^ -o $@
  86.  
  87. %.srec: %-stripped
  88.     $(OBJCOPY) -O srec $^ $@
  89.  
  90. %.hex: %-stripped
  91.     $(OBJCOPY) -O ihex $^ $@
  92.  
  93. # Targets
  94. default: getd sendd
  95.  
  96. getd: getd.c
  97.     $(DEVCC) -o getd getd.c
  98. sendd: sendd.c
  99.     $(DEVCC) -o sendd sendd.c
  100.  
  101. libs: $(LIBS)
  102.  
  103. libuavr.a: $(LIBOBJS)
  104.     $(AR) rcs $@ $?
  105. libyaml.a: $(YAMLOBJS)
  106.     $(AR) rcs $@ $?
  107.    
  108. clean:
  109.     rm -f *.srec *.o *.bin *.asm $(LIBOBJS) $(LIBS)
  110.  
  111. erase:
  112. #   $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --erase
  113.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -e
  114.  
  115. program_%: %.srec
  116. #   $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --upload if=$^
  117.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:w:$^:s
  118.  
  119. verify_%: %.srec
  120. #   $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --verify if=$^
  121.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:v:$^:s
  122.  
  123. download_%: %.srec
  124. #   $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --download of=$^
  125.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:r:$^:s
  126.  
  127. # Fuses:
  128. fuse-nojtag:
  129.     #ATMega Fuses: turn off JTAG on hfuse
  130.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U hfuse:w:0xD9:m
  131.  
  132. fuse-intclk1:
  133.     #ATMega Fuses: set to internal 8MHz/8 oscillator on lfuse
  134.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x62:m
  135.  
  136. fuse-intclk8:
  137.     #ATMega Fuses: set to internal 8MHz/1 oscillator on lfuse
  138.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xE2:m
  139.  
  140. fuse-extclkd:
  141.     #ATMega Fuses: set to external 8-16MHz/8 crystal oscillator on lfuse
  142.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x6E:m
  143.  
  144. fuse-extclk1:
  145.     #ATMega Fuses: set to external 1-8MHz/1 crystal oscillator on lfuse
  146.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xEC:m
  147.  
  148. fuse-extclk8:
  149.     #ATMega Fuses: set to external 8-16MHz/1 crystal oscillator on lfuse
  150.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xEE:m
  151.  
  152. fuse-extclkfs:
  153.     #ATMega Fuses: set to external full-swing crystal oscillator on lfuse
  154.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xF7:m
  155.  
  156. fuse-extclkfsd:
  157.     #ATMega Fuses: set to external full-swing crystal oscillator/8 on lfuse
  158.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x77:m
  159.  
  160. fuses: fuse-nojtag fuse-extclkfs
  161.  
  162. status:
  163.     #Verbose output to test connection and fuses
  164.     $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -v
  165.  
  166. printm:
  167.     $(CC) -dM -E - < /dev/null
Advertisement
Add Comment
Please, Sign In to add comment