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