]> git.sur5r.net Git - freertos/blob - Demo/AVR_ATMega323_WinAVR/makefile
First version under SVN is V4.0.1
[freertos] / Demo / AVR_ATMega323_WinAVR / makefile
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
4 #\r
5 # Additional material for this makefile was submitted by:\r
6 #  Tim Henigan\r
7 #  Peter Fleury\r
8 #  Reiner Patommel\r
9 #  Sander Pool\r
10 #  Frederik Rouleau\r
11 #  Markus Pfaff\r
12 #\r
13 # On command line:\r
14 #\r
15 # make all = Make software.\r
16 #\r
17 # make clean = Clean out built project files.\r
18 #\r
19 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).\r
20 #\r
21 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio\r
22 #                4.07 or greater).\r
23 #\r
24 # make program = Download the hex file to the device, using avrdude.  Please\r
25 #                customize the avrdude settings below first!\r
26 #\r
27 # make filename.s = Just compile filename.c into the assembler code only\r
28 #\r
29 # To rebuild project do "make clean" then "make all".\r
30 #\r
31 \r
32 \r
33 # MCU name\r
34 MCU = atmega323\r
35 \r
36 # Output format. (can be srec, ihex, binary)\r
37 FORMAT = ihex\r
38 \r
39 # Target file name (without extension).\r
40 TARGET = rtosdemo\r
41 \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
44 OPT = s\r
45 \r
46 \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
51 \r
52 SRC     = \\r
53 main.c \\r
54 ParTest/ParTest.c \\r
55 serial/serial.c \\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
65 \r
66 \r
67 # If there is more than one source file, append them above, or modify and\r
68 # uncomment the following:\r
69 #SRC += foo.c bar.c\r
70 \r
71 # You can also wrap lines by appending a backslash to the end of the line:\r
72 #SRC += baz.c \\r
73 #xyzzy.c\r
74 \r
75 \r
76 \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
84 ASRC = \r
85 \r
86 \r
87 # List any extra directories to look for include files here.\r
88 #     Each directory must be seperated by a space.\r
89 EXTRAINCDIRS = \r
90 \r
91 \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
99 \r
100 DEBUG_LEVEL=-g\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
103 \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
107 $(WARNINGS) \\r
108 -Wa,-adhlns=$(<:.c=.lst) \\r
109 $(patsubst %,-I%,$(EXTRAINCDIRS))\r
110 \r
111 \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
119 \r
120 \r
121 \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
130 \r
131 \r
132 \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
138 \r
139 \r
140 \r
141 # Additional libraries\r
142 \r
143 # Minimalistic printf version\r
144 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min\r
145 \r
146 # Floating point printf version (requires -lm below)\r
147 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt\r
148 \r
149 # -lm = math library\r
150 LDFLAGS += -lm\r
151 \r
152 \r
153 \r
154 \r
155 # Programming support using avrdude. Settings and variables.\r
156 \r
157 # Programming hardware: alf avr910 avrisp bascom bsd \r
158 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500\r
159 #\r
160 # Type: avrdude -c ?\r
161 # to get a full listing.\r
162 #\r
163 AVRDUDE_PROGRAMMER = stk500\r
164 \r
165 \r
166 AVRDUDE_PORT = com1        # programmer connected to serial device\r
167 #AVRDUDE_PORT = lpt1    # programmer connected to parallel port\r
168 \r
169 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex\r
170 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r
171 \r
172 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r
173 \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
178 \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
182 \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
187 \r
188 \r
189 \r
190 \r
191 # ---------------------------------------------------------------------------\r
192 \r
193 # Define directories, if needed.\r
194 DIRAVR = c:/winavr\r
195 DIRAVRBIN = $(DIRAVR)/bin\r
196 DIRAVRUTILS = $(DIRAVR)/utils/bin\r
197 DIRINC = .\r
198 DIRLIB = $(DIRAVR)/avr/lib\r
199 \r
200 \r
201 # Define programs and commands.\r
202 SHELL = sh\r
203 \r
204 CC = avr-gcc\r
205 \r
206 OBJCOPY = avr-objcopy\r
207 OBJDUMP = avr-objdump\r
208 SIZE = avr-size\r
209 \r
210 \r
211 # Programming support using avrdude.\r
212 AVRDUDE = avrdude\r
213 \r
214 \r
215 REMOVE = rm -f\r
216 COPY = cp\r
217 \r
218 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
219 ELFSIZE = $(SIZE) -A $(TARGET).elf\r
220 \r
221 \r
222 \r
223 # Define Messages\r
224 # English\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
240 \r
241 \r
242 \r
243 \r
244 # Define all object files.\r
245 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) \r
246 \r
247 # Define all listing files.\r
248 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)\r
249 \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
254 \r
255 \r
256 \r
257 # Default target.\r
258 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \\r
259         $(TARGET).lss $(TARGET).sym sizeafter finished end\r
260 \r
261 \r
262 # Eye candy.\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
265 begin:\r
266         @echo\r
267         @echo $(MSG_BEGIN)\r
268 \r
269 finished:\r
270         @echo $(MSG_ERRORS_NONE)\r
271 \r
272 end:\r
273         @echo $(MSG_END)\r
274         @echo\r
275 \r
276 \r
277 # Display size of file.\r
278 sizebefore:\r
279         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi\r
280 \r
281 sizeafter:\r
282         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi\r
283 \r
284 \r
285 \r
286 # Display compiler version information.\r
287 gccversion : \r
288         @$(CC) --version\r
289 \r
290 \r
291 \r
292 \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
300 \r
301 \r
302 coff: $(TARGET).elf\r
303         @echo\r
304         @echo $(MSG_COFF) $(TARGET).cof\r
305         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r
306 \r
307 \r
308 extcoff: $(TARGET).elf\r
309         @echo\r
310         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r
311         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r
312 \r
313 \r
314 \r
315 \r
316 # Program the device.  \r
317 program: $(TARGET).hex $(TARGET).eep\r
318         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r
319 \r
320 \r
321 \r
322 \r
323 # Create final output files (.hex, .eep) from ELF output file.\r
324 %.hex: %.elf\r
325         @echo
326         @echo $(MSG_FLASH) $@
327         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@\r
328 \r
329 %.eep: %.elf\r
330         @echo
331         @echo $(MSG_EEPROM) $@
332         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
333         --change-section-lma .eeprom=0 -O $(FORMAT) $< $@\r
334 \r
335 # Create extended listing file from ELF output file.\r
336 %.lss: %.elf\r
337         @echo
338         @echo $(MSG_EXTENDED_LISTING) $@
339         $(OBJDUMP) -h -S $< > $@\r
340 \r
341 # Create a symbol table from ELF output file.
342 %.sym: %.elf
343         @echo
344         @echo $(MSG_SYMBOL_TABLE) $@
345         avr-nm -n $< > $@\r
346 \r
347 \r
348 \r
349 # Link: create ELF output file from object files.\r
350 .SECONDARY : $(TARGET).elf\r
351 .PRECIOUS : $(OBJ)\r
352 %.elf: $(OBJ)\r
353         @echo\r
354         @echo $(MSG_LINKING) $@\r
355         $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)\r
356 \r
357 \r
358 # Compile: create object files from C source files.\r
359 %.o : %.c\r
360         @echo\r
361         @echo $(MSG_COMPILING) $<\r
362         $(CC) -c $(ALL_CFLAGS) $< -o $@\r
363 \r
364 \r
365 # Compile: create assembler files from C source files.\r
366 %.s : %.c\r
367         $(CC) -S $(ALL_CFLAGS) $< -o $@\r
368 \r
369 \r
370 # Assemble: create object files from assembler source files.\r
371 %.o : %.S\r
372         @echo\r
373         @echo $(MSG_ASSEMBLING) $<\r
374         $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
375 \r
376 \r
377 \r
378 \r
379 \r
380 \r
381 # Target: clean project.\r
382 clean: begin clean_list finished end\r
383 \r
384 clean_list :\r
385         @echo
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
398         $(REMOVE) $(OBJ)\r
399         $(REMOVE) $(LST)\r
400         $(REMOVE) $(SRC:.c=.s)\r
401         $(REMOVE) $(SRC:.c=.d)\r
402 \r
403 \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
407 #\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
411 #\r
412 %.d: %.c\r
413         set -e; $(CC) -MM $(ALL_CFLAGS) $< \\r
414         | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \\r
415         [ -s $@ ] || rm -f $@\r
416 \r
417 \r
418 # Remove the '-' if you want to see the dependency files generated.\r
419 -include $(SRC:.c=.d)\r
420 \r
421 \r
422 \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
426 \r