1 # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
2 # Released to the Public Domain
3 # Please read the make user manual!
5 # Additional material for this makefile was submitted by:
15 # make all = Make software.
17 # make clean = Clean out built project files.
19 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
21 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24 # make program = Download the hex file to the device, using avrdude. Please
25 # customize the avrdude settings below first!
27 # make filename.s = Just compile filename.c into the assembler code only
29 # To rebuild project do "make clean" then "make all".
36 # Output format. (can be srec, ihex, binary)
39 # Target file name (without extension).
42 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
43 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
47 # List C source files here. (C dependencies are automatically generated.)
48 DEMO_DIR = ../Common/Minimal
49 SOURCE_DIR = ../../Source
50 PORT_DIR = ../../Source/portable/GCC/ATMega323
57 $(SOURCE_DIR)/tasks.c \
58 $(SOURCE_DIR)/queue.c \
59 $(SOURCE_DIR)/list.c \
60 $(SOURCE_DIR)/croutine.c \
61 $(SOURCE_DIR)/portable/MemMang/heap_1.c \
63 $(DEMO_DIR)/crflash.c \
64 $(DEMO_DIR)/integer.c \
69 # If there is more than one source file, append them above, or modify and
70 # uncomment the following:
73 # You can also wrap lines by appending a backslash to the end of the line:
79 # List Assembler source files here.
80 # Make them always end in a capital .S. Files ending in a lowercase .s
81 # will not be considered source files but generated files (assembler
82 # output from the compiler), and will be deleted upon "make clean"!
83 # Even though the DOS/Win* filesystem matches both .s and .S the same,
84 # it will preserve the spelling of the filenames, and gcc itself does
85 # care about how the name is spelled on its command-line.
89 # List any extra directories to look for include files here.
90 # Each directory must be seperated by a space.
94 # Optional compiler flags.
95 # -g: generate debugging information (for GDB, or for COFF conversion)
96 # -O*: optimization level
97 # -f...: tuning, see gcc manual and avr-libc documentation
98 # -Wall...: warning level
99 # -Wa,...: tell GCC to pass this to the assembler.
100 # -ahlms: create assembler listing
103 WARNINGS=-Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare \
104 -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused
106 CFLAGS = -D GCC_MEGA_AVR -I. -I../../Source/include -I../Common/include \
107 $(DEBUG_LEVEL) -O$(OPT) \
108 -fsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
110 -Wa,-adhlns=$(<:.c=.lst) \
111 $(patsubst %,-I%,$(EXTRAINCDIRS))
114 # Set a "language standard" compiler flag.
115 # Unremark just one line below to set the language standard to use.
116 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
118 #CFLAGS += -std=gnu89
124 # Optional assembler flags.
125 # -Wa,...: tell GCC to pass this to the assembler.
126 # -ahlms: create listing
127 # -gstabs: have the assembler create line number information; note that
128 # for use in COFF files, additional information about filenames
129 # and function names needs to be present in the assembler source
130 # files -- see avr-libc docs [FIXME: not yet described there]
131 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
135 # Optional linker flags.
136 # -Wl,...: tell GCC to pass this to linker.
137 # -Map: create map file
138 # --cref: add cross reference to map file
139 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
143 # Additional libraries
145 # Minimalistic printf version
146 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
148 # Floating point printf version (requires -lm below)
149 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
157 # Programming support using avrdude. Settings and variables.
159 # Programming hardware: alf avr910 avrisp bascom bsd
160 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
163 # to get a full listing.
165 AVRDUDE_PROGRAMMER = stk500
168 AVRDUDE_PORT = com1 # programmer connected to serial device
169 #AVRDUDE_PORT = lpt1 # programmer connected to parallel port
171 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
172 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
174 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
176 # Uncomment the following if you want avrdude's erase cycle counter.
177 # Note that this counter needs to be initialized first using -Yn,
178 # see avrdude manual.
181 # Uncomment the following if you do /not/ wish a verification to be
182 # performed after programming the device.
185 # Increase verbosity level. Please use this when submitting bug
186 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
187 # to submit bug reports.
188 #AVRDUDE_FLAGS += -v -v
193 # ---------------------------------------------------------------------------
195 # Define directories, if needed.
197 DIRAVRBIN = $(DIRAVR)/bin
198 DIRAVRUTILS = $(DIRAVR)/utils/bin
200 DIRLIB = $(DIRAVR)/avr/lib
203 # Define programs and commands.
208 OBJCOPY = avr-objcopy
209 OBJDUMP = avr-objdump
213 # Programming support using avrdude.
220 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
221 ELFSIZE = $(SIZE) -A $(TARGET).elf
227 MSG_ERRORS_NONE = Errors: none
228 MSG_BEGIN = -------- begin --------
229 MSG_END = -------- end --------
230 MSG_SIZE_BEFORE = Size before:
231 MSG_SIZE_AFTER = Size after:
232 MSG_COFF = Converting to AVR COFF:
233 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
234 MSG_FLASH = Creating load file for Flash:
235 MSG_EEPROM = Creating load file for EEPROM:
236 MSG_EXTENDED_LISTING = Creating Extended Listing:
237 MSG_SYMBOL_TABLE = Creating Symbol Table:
238 MSG_LINKING = Linking:
239 MSG_COMPILING = Compiling:
240 MSG_ASSEMBLING = Assembling:
241 MSG_CLEANING = Cleaning project:
246 # Define all object files.
247 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
249 # Define all listing files.
250 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
252 # Combine all necessary flags and optional flags.
253 # Add target processor to flags.
254 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
255 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
260 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
261 $(TARGET).lss $(TARGET).sym sizeafter finished end
265 # AVR Studio 3.x does not check make's exit code but relies on
266 # the following magic strings to be generated by the compile job.
272 @echo $(MSG_ERRORS_NONE)
279 # Display size of file.
281 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
284 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
288 # Display compiler version information.
295 # Convert ELF to COFF for use in debugging / simulating in
296 # AVR Studio or VMLAB.
297 COFFCONVERT=$(OBJCOPY) --debugging \
298 --change-section-address .data-0x800000 \
299 --change-section-address .bss-0x800000 \
300 --change-section-address .noinit-0x800000 \
301 --change-section-address .eeprom-0x810000
306 @echo $(MSG_COFF) $(TARGET).cof
307 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
310 extcoff: $(TARGET).elf
312 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
313 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
318 # Program the device.
319 program: $(TARGET).hex $(TARGET).eep
320 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
325 # Create final output files (.hex, .eep) from ELF output file.
328 @echo $(MSG_FLASH) $@
329 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
333 @echo $(MSG_EEPROM) $@
334 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
335 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
337 # Create extended listing file from ELF output file.
340 @echo $(MSG_EXTENDED_LISTING) $@
341 $(OBJDUMP) -h -S $< > $@
343 # Create a symbol table from ELF output file.
346 @echo $(MSG_SYMBOL_TABLE) $@
351 # Link: create ELF output file from object files.
352 .SECONDARY : $(TARGET).elf
356 @echo $(MSG_LINKING) $@
357 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
360 # Compile: create object files from C source files.
363 @echo $(MSG_COMPILING) $<
364 $(CC) -c $(ALL_CFLAGS) $< -o $@
367 # Compile: create assembler files from C source files.
369 $(CC) -S $(ALL_CFLAGS) $< -o $@
372 # Assemble: create object files from assembler source files.
375 @echo $(MSG_ASSEMBLING) $<
376 $(CC) -c $(ALL_ASFLAGS) $< -o $@
383 # Target: clean project.
384 clean: begin clean_list finished end
388 @echo $(MSG_CLEANING)
389 $(REMOVE) $(TARGET).hex
390 $(REMOVE) $(TARGET).eep
391 $(REMOVE) $(TARGET).obj
392 $(REMOVE) $(TARGET).cof
393 $(REMOVE) $(TARGET).elf
394 $(REMOVE) $(TARGET).map
395 $(REMOVE) $(TARGET).obj
396 $(REMOVE) $(TARGET).a90
397 $(REMOVE) $(TARGET).sym
398 $(REMOVE) $(TARGET).lnk
399 $(REMOVE) $(TARGET).lss
402 $(REMOVE) $(SRC:.c=.s)
403 $(REMOVE) $(SRC:.c=.d)
406 # Automatically generate C source code dependencies.
407 # (Code originally taken from the GNU make user manual and modified
408 # (See README.txt Credits).)
410 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
411 # (see the SHELL variable defined above).
412 # This may not work with other shells or other seds.
415 set -e; $(CC) -MM $(ALL_CFLAGS) $< \
416 | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
417 [ -s $@ ] || rm -f $@
420 # Remove the '-' if you want to see the dependency files generated.
421 -include $(SRC:.c=.d)
425 # Listing of phony targets.
426 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
427 clean clean_list program