]> git.sur5r.net Git - freertos/blob - Demo/AVR_ATMega323_WinAVR/makefile
Changes to the AVR demo's. IAR demo updated with new critical section method.
[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 regtest.c \\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
67 \r
68 \r
69 # If there is more than one source file, append them above, or modify and\r
70 # uncomment the following:\r
71 #SRC += foo.c bar.c\r
72 \r
73 # You can also wrap lines by appending a backslash to the end of the line:\r
74 #SRC += baz.c \\r
75 #xyzzy.c\r
76 \r
77 \r
78 \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
86 ASRC = \r
87 \r
88 \r
89 # List any extra directories to look for include files here.\r
90 #     Each directory must be seperated by a space.\r
91 EXTRAINCDIRS = \r
92 \r
93 \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
101 \r
102 DEBUG_LEVEL=-g\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
105 \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
109 $(WARNINGS) \\r
110 -Wa,-adhlns=$(<:.c=.lst) \\r
111 $(patsubst %,-I%,$(EXTRAINCDIRS))\r
112 \r
113 \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
121 \r
122 \r
123 \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
132 \r
133 \r
134 \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
140 \r
141 \r
142 \r
143 # Additional libraries\r
144 \r
145 # Minimalistic printf version\r
146 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min\r
147 \r
148 # Floating point printf version (requires -lm below)\r
149 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt\r
150 \r
151 # -lm = math library\r
152 LDFLAGS += -lm\r
153 \r
154 \r
155 \r
156 \r
157 # Programming support using avrdude. Settings and variables.\r
158 \r
159 # Programming hardware: alf avr910 avrisp bascom bsd \r
160 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500\r
161 #\r
162 # Type: avrdude -c ?\r
163 # to get a full listing.\r
164 #\r
165 AVRDUDE_PROGRAMMER = stk500\r
166 \r
167 \r
168 AVRDUDE_PORT = com1        # programmer connected to serial device\r
169 #AVRDUDE_PORT = lpt1    # programmer connected to parallel port\r
170 \r
171 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex\r
172 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r
173 \r
174 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r
175 \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
180 \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
184 \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
189 \r
190 \r
191 \r
192 \r
193 # ---------------------------------------------------------------------------\r
194 \r
195 # Define directories, if needed.\r
196 DIRAVR = c:/winavr\r
197 DIRAVRBIN = $(DIRAVR)/bin\r
198 DIRAVRUTILS = $(DIRAVR)/utils/bin\r
199 DIRINC = .\r
200 DIRLIB = $(DIRAVR)/avr/lib\r
201 \r
202 \r
203 # Define programs and commands.\r
204 SHELL = sh\r
205 \r
206 CC = avr-gcc\r
207 \r
208 OBJCOPY = avr-objcopy\r
209 OBJDUMP = avr-objdump\r
210 SIZE = avr-size\r
211 \r
212 \r
213 # Programming support using avrdude.\r
214 AVRDUDE = avrdude\r
215 \r
216 \r
217 REMOVE = rm -f\r
218 COPY = cp\r
219 \r
220 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
221 ELFSIZE = $(SIZE) -A $(TARGET).elf\r
222 \r
223 \r
224 \r
225 # Define Messages\r
226 # English\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
242 \r
243 \r
244 \r
245 \r
246 # Define all object files.\r
247 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) \r
248 \r
249 # Define all listing files.\r
250 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)\r
251 \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
256 \r
257 \r
258 \r
259 # Default target.\r
260 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \\r
261         $(TARGET).lss $(TARGET).sym sizeafter finished end\r
262 \r
263 \r
264 # Eye candy.\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
267 begin:\r
268         @echo\r
269         @echo $(MSG_BEGIN)\r
270 \r
271 finished:\r
272         @echo $(MSG_ERRORS_NONE)\r
273 \r
274 end:\r
275         @echo $(MSG_END)\r
276         @echo\r
277 \r
278 \r
279 # Display size of file.\r
280 sizebefore:\r
281         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi\r
282 \r
283 sizeafter:\r
284         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi\r
285 \r
286 \r
287 \r
288 # Display compiler version information.\r
289 gccversion : \r
290         @$(CC) --version\r
291 \r
292 \r
293 \r
294 \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
302 \r
303 \r
304 coff: $(TARGET).elf\r
305         @echo\r
306         @echo $(MSG_COFF) $(TARGET).cof\r
307         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r
308 \r
309 \r
310 extcoff: $(TARGET).elf\r
311         @echo\r
312         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r
313         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r
314 \r
315 \r
316 \r
317 \r
318 # Program the device.  \r
319 program: $(TARGET).hex $(TARGET).eep\r
320         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r
321 \r
322 \r
323 \r
324 \r
325 # Create final output files (.hex, .eep) from ELF output file.\r
326 %.hex: %.elf\r
327         @echo
328         @echo $(MSG_FLASH) $@
329         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@\r
330 \r
331 %.eep: %.elf\r
332         @echo
333         @echo $(MSG_EEPROM) $@
334         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
335         --change-section-lma .eeprom=0 -O $(FORMAT) $< $@\r
336 \r
337 # Create extended listing file from ELF output file.\r
338 %.lss: %.elf\r
339         @echo
340         @echo $(MSG_EXTENDED_LISTING) $@
341         $(OBJDUMP) -h -S $< > $@\r
342 \r
343 # Create a symbol table from ELF output file.
344 %.sym: %.elf
345         @echo
346         @echo $(MSG_SYMBOL_TABLE) $@
347         avr-nm -n $< > $@\r
348 \r
349 \r
350 \r
351 # Link: create ELF output file from object files.\r
352 .SECONDARY : $(TARGET).elf\r
353 .PRECIOUS : $(OBJ)\r
354 %.elf: $(OBJ)\r
355         @echo\r
356         @echo $(MSG_LINKING) $@\r
357         $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)\r
358 \r
359 \r
360 # Compile: create object files from C source files.\r
361 %.o : %.c\r
362         @echo\r
363         @echo $(MSG_COMPILING) $<\r
364         $(CC) -c $(ALL_CFLAGS) $< -o $@\r
365 \r
366 \r
367 # Compile: create assembler files from C source files.\r
368 %.s : %.c\r
369         $(CC) -S $(ALL_CFLAGS) $< -o $@\r
370 \r
371 \r
372 # Assemble: create object files from assembler source files.\r
373 %.o : %.S\r
374         @echo\r
375         @echo $(MSG_ASSEMBLING) $<\r
376         $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
377 \r
378 \r
379 \r
380 \r
381 \r
382 \r
383 # Target: clean project.\r
384 clean: begin clean_list finished end\r
385 \r
386 clean_list :\r
387         @echo
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
400         $(REMOVE) $(OBJ)\r
401         $(REMOVE) $(LST)\r
402         $(REMOVE) $(SRC:.c=.s)\r
403         $(REMOVE) $(SRC:.c=.d)\r
404 \r
405 \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
409 #\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
413 #\r
414 %.d: %.c\r
415         set -e; $(CC) -MM $(ALL_CFLAGS) $< \\r
416         | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \\r
417         [ -s $@ ] || rm -f $@\r
418 \r
419 \r
420 # Remove the '-' if you want to see the dependency files generated.\r
421 -include $(SRC:.c=.d)\r
422 \r
423 \r
424 \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
428 \r