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