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
56 $(SOURCE_DIR)/tasks.c \
\r
57 $(SOURCE_DIR)/queue.c \
\r
58 $(SOURCE_DIR)/list.c \
\r
59 $(SOURCE_DIR)/portable/MemMang/heap_1.c \
\r
60 $(PORT_DIR)/port.c \
\r
61 $(DEMO_DIR)/flash.c \
\r
62 $(DEMO_DIR)/integer.c \
\r
63 $(DEMO_DIR)/PollQ.c \
\r
64 $(DEMO_DIR)/comtest.c
\r
67 # If there is more than one source file, append them above, or modify and
\r
68 # uncomment the following:
\r
71 # You can also wrap lines by appending a backslash to the end of the line:
\r
77 # List Assembler source files here.
\r
78 # Make them always end in a capital .S. Files ending in a lowercase .s
\r
79 # will not be considered source files but generated files (assembler
\r
80 # output from the compiler), and will be deleted upon "make clean"!
\r
81 # Even though the DOS/Win* filesystem matches both .s and .S the same,
\r
82 # it will preserve the spelling of the filenames, and gcc itself does
\r
83 # care about how the name is spelled on its command-line.
\r
87 # List any extra directories to look for include files here.
\r
88 # Each directory must be seperated by a space.
\r
92 # Optional compiler flags.
\r
93 # -g: generate debugging information (for GDB, or for COFF conversion)
\r
94 # -O*: optimization level
\r
95 # -f...: tuning, see gcc manual and avr-libc documentation
\r
96 # -Wall...: warning level
\r
97 # -Wa,...: tell GCC to pass this to the assembler.
\r
98 # -ahlms: create assembler listing
\r
101 WARNINGS=-Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare \
\r
102 -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused
\r
104 CFLAGS = -D GCC_MEGA_AVR -I. -I../../Source/include -I../Common/include \
\r
105 $(DEBUG_LEVEL) -O$(OPT) \
\r
106 -fsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
\r
108 -Wa,-adhlns=$(<:.c=.lst) \
\r
109 $(patsubst %,-I%,$(EXTRAINCDIRS))
\r
112 # Set a "language standard" compiler flag.
\r
113 # Unremark just one line below to set the language standard to use.
\r
114 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
\r
115 #CFLAGS += -std=c89
\r
116 #CFLAGS += -std=gnu89
\r
117 #CFLAGS += -std=c99
\r
118 CFLAGS += -std=gnu99
\r
122 # Optional assembler flags.
\r
123 # -Wa,...: tell GCC to pass this to the assembler.
\r
124 # -ahlms: create listing
\r
125 # -gstabs: have the assembler create line number information; note that
\r
126 # for use in COFF files, additional information about filenames
\r
127 # and function names needs to be present in the assembler source
\r
128 # files -- see avr-libc docs [FIXME: not yet described there]
\r
129 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
\r
133 # Optional linker flags.
\r
134 # -Wl,...: tell GCC to pass this to linker.
\r
135 # -Map: create map file
\r
136 # --cref: add cross reference to map file
\r
137 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
\r
141 # Additional libraries
\r
143 # Minimalistic printf version
\r
144 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
\r
146 # Floating point printf version (requires -lm below)
\r
147 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
\r
149 # -lm = math library
\r
155 # Programming support using avrdude. Settings and variables.
\r
157 # Programming hardware: alf avr910 avrisp bascom bsd
\r
158 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
\r
160 # Type: avrdude -c ?
\r
161 # to get a full listing.
\r
163 AVRDUDE_PROGRAMMER = stk500
\r
166 AVRDUDE_PORT = com1 # programmer connected to serial device
\r
167 #AVRDUDE_PORT = lpt1 # programmer connected to parallel port
\r
169 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
\r
170 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
\r
172 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
\r
174 # Uncomment the following if you want avrdude's erase cycle counter.
\r
175 # Note that this counter needs to be initialized first using -Yn,
\r
176 # see avrdude manual.
\r
177 #AVRDUDE_ERASE += -y
\r
179 # Uncomment the following if you do /not/ wish a verification to be
\r
180 # performed after programming the device.
\r
181 #AVRDUDE_FLAGS += -V
\r
183 # Increase verbosity level. Please use this when submitting bug
\r
184 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
\r
185 # to submit bug reports.
\r
186 #AVRDUDE_FLAGS += -v -v
\r
191 # ---------------------------------------------------------------------------
\r
193 # Define directories, if needed.
\r
195 DIRAVRBIN = $(DIRAVR)/bin
\r
196 DIRAVRUTILS = $(DIRAVR)/utils/bin
\r
198 DIRLIB = $(DIRAVR)/avr/lib
\r
201 # Define programs and commands.
\r
206 OBJCOPY = avr-objcopy
\r
207 OBJDUMP = avr-objdump
\r
211 # Programming support using avrdude.
\r
218 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
\r
219 ELFSIZE = $(SIZE) -A $(TARGET).elf
\r
225 MSG_ERRORS_NONE = Errors: none
\r
226 MSG_BEGIN = -------- begin --------
\r
227 MSG_END = -------- end --------
\r
228 MSG_SIZE_BEFORE = Size before:
\r
229 MSG_SIZE_AFTER = Size after:
\r
230 MSG_COFF = Converting to AVR COFF:
\r
231 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
\r
232 MSG_FLASH = Creating load file for Flash:
\r
233 MSG_EEPROM = Creating load file for EEPROM:
\r
234 MSG_EXTENDED_LISTING = Creating Extended Listing:
\r
235 MSG_SYMBOL_TABLE = Creating Symbol Table:
\r
236 MSG_LINKING = Linking:
\r
237 MSG_COMPILING = Compiling:
\r
238 MSG_ASSEMBLING = Assembling:
\r
239 MSG_CLEANING = Cleaning project:
\r
244 # Define all object files.
\r
245 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
\r
247 # Define all listing files.
\r
248 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
\r
250 # Combine all necessary flags and optional flags.
\r
251 # Add target processor to flags.
\r
252 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
\r
253 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
\r
258 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
\r
259 $(TARGET).lss $(TARGET).sym sizeafter finished end
\r
263 # AVR Studio 3.x does not check make's exit code but relies on
\r
264 # the following magic strings to be generated by the compile job.
\r
270 @echo $(MSG_ERRORS_NONE)
\r
277 # Display size of file.
\r
279 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
\r
282 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
\r
286 # Display compiler version information.
\r
293 # Convert ELF to COFF for use in debugging / simulating in
\r
294 # AVR Studio or VMLAB.
\r
295 COFFCONVERT=$(OBJCOPY) --debugging \
\r
296 --change-section-address .data-0x800000 \
\r
297 --change-section-address .bss-0x800000 \
\r
298 --change-section-address .noinit-0x800000 \
\r
299 --change-section-address .eeprom-0x810000
\r
302 coff: $(TARGET).elf
\r
304 @echo $(MSG_COFF) $(TARGET).cof
\r
305 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
\r
308 extcoff: $(TARGET).elf
\r
310 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
\r
311 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
\r
316 # Program the device.
\r
317 program: $(TARGET).hex $(TARGET).eep
\r
318 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
\r
323 # Create final output files (.hex, .eep) from ELF output file.
\r
326 @echo $(MSG_FLASH) $@
327 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
\r
331 @echo $(MSG_EEPROM) $@
332 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
\r
333 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
\r
335 # Create extended listing file from ELF output file.
\r
338 @echo $(MSG_EXTENDED_LISTING) $@
339 $(OBJDUMP) -h -S $< > $@
\r
341 # Create a symbol table from ELF output file.
344 @echo $(MSG_SYMBOL_TABLE) $@
349 # Link: create ELF output file from object files.
\r
350 .SECONDARY : $(TARGET).elf
\r
354 @echo $(MSG_LINKING) $@
\r
355 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
\r
358 # Compile: create object files from C source files.
\r
361 @echo $(MSG_COMPILING) $<
\r
362 $(CC) -c $(ALL_CFLAGS) $< -o $@
\r
365 # Compile: create assembler files from C source files.
\r
367 $(CC) -S $(ALL_CFLAGS) $< -o $@
\r
370 # Assemble: create object files from assembler source files.
\r
373 @echo $(MSG_ASSEMBLING) $<
\r
374 $(CC) -c $(ALL_ASFLAGS) $< -o $@
\r
381 # Target: clean project.
\r
382 clean: begin clean_list finished end
\r
386 @echo $(MSG_CLEANING)
387 $(REMOVE) $(TARGET).hex
\r
388 $(REMOVE) $(TARGET).eep
\r
389 $(REMOVE) $(TARGET).obj
\r
390 $(REMOVE) $(TARGET).cof
\r
391 $(REMOVE) $(TARGET).elf
\r
392 $(REMOVE) $(TARGET).map
\r
393 $(REMOVE) $(TARGET).obj
\r
394 $(REMOVE) $(TARGET).a90
\r
395 $(REMOVE) $(TARGET).sym
\r
396 $(REMOVE) $(TARGET).lnk
\r
397 $(REMOVE) $(TARGET).lss
\r
400 $(REMOVE) $(SRC:.c=.s)
\r
401 $(REMOVE) $(SRC:.c=.d)
\r
404 # Automatically generate C source code dependencies.
\r
405 # (Code originally taken from the GNU make user manual and modified
\r
406 # (See README.txt Credits).)
\r
408 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
\r
409 # (see the SHELL variable defined above).
\r
410 # This may not work with other shells or other seds.
\r
413 set -e; $(CC) -MM $(ALL_CFLAGS) $< \
\r
414 | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
\r
415 [ -s $@ ] || rm -f $@
\r
418 # Remove the '-' if you want to see the dependency files generated.
\r
419 -include $(SRC:.c=.d)
\r
423 # Listing of phony targets.
\r
424 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
\r
425 clean clean_list program
\r