Advertisement
Guest User

Makefile

a guest
Oct 6th, 2009
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1.  
  2. TARGET = main
  3. PORT = /dev/ttyUSB*
  4. UPLOAD_RATE = 57600
  5. AVRDUDE_PROGRAMMER = stk500v1
  6. MCU = atmega328p
  7. F_CPU = 16000000
  8.  
  9. ############################################################################
  10. # Below here nothing should be changed...
  11.  
  12. ARDUINO = ./arduino
  13.  
  14. SRC = $(ARDUINO)/pins_arduino.c \
  15. $(ARDUINO)/wiring.c \
  16. $(ARDUINO)/wiring_analog.c \
  17. $(ARDUINO)/wiring_digital.c \
  18. $(ARDUINO)/wiring_pulse.c \
  19. $(ARDUINO)/wiring_shift.c \
  20. $(ARDUINO)/WInterrupts.c \
  21.  
  22. CXXSRC = $(ARDUINO)/HardwareSerial.cpp \
  23. $(ARDUINO)/WMath.cpp \
  24. $(ARDUINO)/Print.cpp \
  25.  
  26. EXTRACXX =
  27.  
  28. EXTRACXX =
  29.  
  30.  
  31. # Debugging format.
  32. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  33. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  34. DEBUG = stabs
  35.  
  36.  
  37. # Compiler flag to set the C Standard level.
  38. # c89 - "ANSI" C
  39. # gnu89 - c89 plus GCC extensions
  40. # c99 - ISO C99 standard (not yet fully implemented)
  41. # gnu99 - c99 plus GCC extensions
  42. #CSTANDARD = -std=gnu99
  43. #CDEBUG = -g$(DEBUG)
  44. #CWARN = -Wall -Wstrict-prototypes
  45. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  46. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  47.  
  48. CFLAGS = -g -Os -w -ffunction-sections -fdata-sections -g$(DEBUG) -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. -I$(ARDUINO)
  49. CXXFLAGS = -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. -I$(ARDUINO)
  50. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  51. LDFLAGS = -lm
  52.  
  53.  
  54. # Programming support using avrdude. Settings and variables.
  55. AVRDUDE_PORT = $(PORT)
  56. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  57. AVRDUDE_FLAGS = -V -F -C /etc/avrdude.conf -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(UPLOAD_RATE)
  58.  
  59. # Program settings
  60. CC = avr-gcc
  61. CXX = avr-g++
  62. OBJCOPY = avr-objcopy
  63. OBJDUMP = avr-objdump
  64. AR = avr-ar
  65. SIZE = avr-size
  66. NM = avr-nm
  67. AVRDUDE = avrdude
  68.  
  69. # Define all object files.
  70. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  71.  
  72. # Define all listing files.
  73. LST = $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) $(ASRC:.S=.lst)
  74.  
  75. # Combine all necessary flags and optional flags.
  76. # Add target processor to flags.
  77. ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  78.  
  79.  
  80. # Default target.
  81. all: build sizeafter
  82.  
  83. build: elf eep hex
  84.  
  85. elf: $(TARGET).elf
  86. hex: $(TARGET).hex
  87. eep: $(TARGET).eep
  88. lss: $(TARGET).lss
  89. sym: $(TARGET).sym
  90.  
  91. # Program the device.
  92. upload: $(TARGET).hex
  93. stty -F $(AVRDUDE_PORT) hupcl
  94. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  95.  
  96.  
  97. # Display size of file.
  98. HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
  99. ELFSIZE = $(SIZE) $(TARGET).elf
  100. sizebefore:
  101. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
  102.  
  103. sizeafter:
  104. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
  105.  
  106.  
  107. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  108. #COFFCONVERT=$(OBJCOPY) --debugging \
  109. # --change-section-address .data-0x800000 \
  110. # --change-section-address .bss-0x800000 \
  111. # --change-section-address .noinit-0x800000 \
  112. # --change-section-address .eeprom-0x810000
  113.  
  114.  
  115. #coff: $(TARGET).elf
  116. # $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
  117. #
  118. #
  119. #extcoff: $(TARGET).elf
  120. # $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
  121.  
  122.  
  123. .SUFFIXES: .elf .hex .eep .lss .sym
  124.  
  125. .elf.hex:
  126. $(OBJCOPY) -O ihex -R .eeprom $< $@
  127.  
  128. .elf.eep:
  129. $(OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@
  130.  
  131. # Create extended listing file from ELF output file.
  132. .elf.lss:
  133. $(OBJDUMP) -h -S $< > $@
  134.  
  135. # Create a symbol table from ELF output file.
  136. .elf.sym:
  137. $(NM) -n $< > $@
  138.  
  139. # Link: create ELF output file from library.
  140. $(TARGET).elf: $(TARGET).cpp core.a
  141. $(CC) -Os -Wl,--gc-sections -mmcu=$(MCU) $(CXXDEFS) -o $@ $(TARGET).cpp core.a -L. $(LDFLAGS)
  142.  
  143.  
  144. core.a: $(OBJ)
  145. @for i in $(OBJ); do echo $(AR) rcs core.a $$i; $(AR) rcs core.a $$i; done
  146.  
  147.  
  148. # Compile: create object files from C++ source files.
  149. .cpp.o:
  150. $(CXX) -c $(CXXFLAGS) $< -o $@
  151.  
  152. # Compile: create object files from C source files.
  153. .c.o:
  154. $(CC) -c $(CFLAGS) $< -o $@
  155.  
  156.  
  157. # Compile: create assembler files from C source files.
  158. .c.s:
  159. $(CC) -S $(CFLAGS) $< -o $@
  160.  
  161.  
  162. # Assemble: create object files from assembler source files.
  163. .S.o:
  164. $(CC) -c $(ASFLAGS) $< -o $@
  165.  
  166.  
  167. # Automatic dependencies
  168. %.d: %.c
  169. $(CC) -M $(CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  170.  
  171. %.d: %.cpp
  172. $(CXX) -M $(CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  173.  
  174.  
  175. # Target: clean project.
  176. clean:
  177. rm -f $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
  178. $(TARGET).map $(TARGET).sym $(TARGET).lss core.a \
  179. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
  180.  
  181. .PHONY: all build elf hex eep lss sym program coff extcoff clean sizebefore sizeafter
  182.  
  183.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement