Rev 73 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | #-------------------------------------------------------------------- |
2 | # MCU name |
||
3 | MCU = atmega168 |
||
32 | holgerb | 4 | F_CPU = 8000000 |
1 | ingob | 5 | #------------------------------------------------------------------- |
58 | killagreg | 6 | #BOARD = 10 |
7 | BOARD = 11 |
||
69 | killagreg | 8 | #OPTION = HEADTRACKER |
9 | |||
41 | killagreg | 10 | VERSION_MAJOR = 0 |
67 | killagreg | 11 | VERSION_MINOR = 23 |
12 | VERSION_PATCH = 0 |
||
32 | holgerb | 13 | |
67 | killagreg | 14 | VERSION_SERIAL_MAJOR = 11 # Serial Protocol Major Version |
47 | killagreg | 15 | VERSION_SERIAL_MINOR = 0 # Serial Protocol Minor Version |
59 | killagreg | 16 | NC_I2C_COMPATIBLE = 3 # I2C Protocol Version |
1 | ingob | 17 | #------------------------------------------------------------------- |
18 | |||
38 | killagreg | 19 | # get SVN revision |
20 | REV := $(shell sh -c "cat .svn/entries | sed -n '4p'") |
||
21 | |||
1 | ingob | 22 | # Output format. (can be srec, ihex, binary) |
23 | FORMAT = ihex |
||
24 | |||
25 | # Target file name (without extension). |
||
26 | |||
41 | killagreg | 27 | ifeq ($(VERSION_PATCH), 0) |
28 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)a_SVN$(REV) |
||
29 | endif |
||
30 | ifeq ($(VERSION_PATCH), 1) |
||
31 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)b_SVN$(REV) |
||
32 | endif |
||
33 | ifeq ($(VERSION_PATCH), 2) |
||
34 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)c_SVN$(REV) |
||
35 | endif |
||
36 | ifeq ($(VERSION_PATCH), 3) |
||
37 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)d_SVN$(REV) |
||
38 | endif |
||
39 | ifeq ($(VERSION_PATCH), 4) |
||
40 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)e_SVN$(REV) |
||
41 | endif |
||
42 | ifeq ($(VERSION_PATCH), 5) |
||
43 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)f_SVN$(REV) |
||
44 | endif |
||
45 | ifeq ($(VERSION_PATCH), 6) |
||
46 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)g_SVN$(REV) |
||
47 | endif |
||
48 | ifeq ($(VERSION_PATCH), 7) |
||
49 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)h_SVN$(REV) |
||
50 | endif |
||
51 | ifeq ($(VERSION_PATCH), 8) |
||
52 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)i_SVN$(REV) |
||
53 | endif |
||
54 | ifeq ($(VERSION_PATCH), 9) |
||
55 | TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)j_SVN$(REV) |
||
56 | endif |
||
57 | |||
58 | |||
1 | ingob | 59 | # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization. |
60 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
||
73 | killagreg | 61 | OPT = s |
1 | ingob | 62 | |
63 | ########################################################################################################## |
||
64 | # List C source files here. (C dependencies are automatically generated.) |
||
58 | killagreg | 65 | SRC = main.c uart.c timer0.c analog.c twislave.c led.c menu.c printf_P.c |
1 | ingob | 66 | ########################################################################################################## |
67 | |||
68 | |||
69 | # List Assembler source files here. |
||
70 | # Make them always end in a capital .S. Files ending in a lowercase .s |
||
71 | # will not be considered source files but generated files (assembler |
||
72 | # output from the compiler), and will be deleted upon "make clean"! |
||
73 | # Even though the DOS/Win* filesystem matches both .s and .S the same, |
||
74 | # it will preserve the spelling of the filenames, and gcc itself does |
||
75 | # care about how the name is spelled on its command-line. |
||
76 | ASRC = |
||
77 | |||
78 | |||
79 | # List any extra directories to look for include files here. |
||
80 | # Each directory must be seperated by a space. |
||
81 | EXTRAINCDIRS = |
||
82 | |||
83 | |||
32 | holgerb | 84 | CDEFS = -DF_CPU=$(F_CPU)UL |
85 | |||
1 | ingob | 86 | # Optional compiler flags. |
87 | # -g: generate debugging information (for GDB, or for COFF conversion) |
||
88 | # -O*: optimization level |
||
89 | # -f...: tuning, see gcc manual and avr-libc documentation |
||
90 | # -Wall...: warning level |
||
91 | # -Wa,...: tell GCC to pass this to the assembler. |
||
92 | # -ahlms: create assembler listing |
||
58 | killagreg | 93 | CFLAGS = -O$(OPT) \ |
1 | ingob | 94 | -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \ |
95 | -Wall -Wstrict-prototypes \ |
||
96 | -Wa,-adhlns=$(<:.c=.lst) \ |
||
97 | $(patsubst %,-I%,$(EXTRAINCDIRS)) |
||
98 | |||
99 | |||
100 | # Set a "language standard" compiler flag. |
||
101 | # Unremark just one line below to set the language standard to use. |
||
102 | # gnu99 = C99 + GNU extensions. See GCC manual for more information. |
||
103 | #CFLAGS += -std=c89 |
||
104 | #CFLAGS += -std=gnu89 |
||
105 | #CFLAGS += -std=c99 |
||
106 | CFLAGS += -std=gnu99 |
||
32 | holgerb | 107 | CFLAGS += $(CDEFS) |
73 | killagreg | 108 | |
109 | # shrink code size |
||
110 | CFLAGS += -mtiny-stack |
||
111 | #CFLAGS += -fno-inline-functions |
||
112 | CFLAGS += -mcall-prologues |
||
113 | |||
47 | killagreg | 114 | CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_PATCH=$(VERSION_PATCH) -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR) -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR) -DBOARD=$(BOARD) -DNC_I2C_COMPATIBLE=$(NC_I2C_COMPATIBLE) |
1 | ingob | 115 | |
69 | killagreg | 116 | ifeq ($(OPTION), HEADTRACKER) |
117 | CFLAGS += -DHEADTRACKER |
||
1 | ingob | 118 | endif |
119 | |||
120 | |||
121 | |||
122 | # Optional assembler flags. |
||
123 | # -Wa,...: tell GCC to pass this to the assembler. |
||
124 | # -ahlms: create listing |
||
125 | # -gstabs: have the assembler create line number information; note that |
||
126 | # for use in COFF files, additional information about filenames |
||
127 | # and function names needs to be present in the assembler source |
||
128 | # files -- see avr-libc docs [FIXME: not yet described there] |
||
129 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
||
130 | |||
131 | |||
132 | |||
133 | # Optional linker flags. |
||
134 | # -Wl,...: tell GCC to pass this to linker. |
||
135 | # -Map: create map file |
||
136 | # --cref: add cross reference to map file |
||
137 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
||
138 | |||
139 | |||
140 | |||
141 | # Additional libraries |
||
142 | |||
143 | # Minimalistic printf version |
||
144 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_min |
||
145 | |||
146 | # Floating point printf version (requires -lm below) |
||
147 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt |
||
148 | |||
149 | # -lm = math library |
||
150 | LDFLAGS += -lm |
||
151 | |||
152 | |||
153 | |||
154 | |||
155 | # Programming support using avrdude. Settings and variables. |
||
156 | |||
157 | # Programming hardware: alf avr910 avrisp bascom bsd |
||
158 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
||
159 | # |
||
160 | # Type: avrdude -c ? |
||
161 | # to get a full listing. |
||
162 | # |
||
163 | |||
164 | AVRDUDE_PROGRAMMER = dt006 |
||
165 | #AVRDUDE_PROGRAMMER = stk200 |
||
166 | |||
167 | #AVRDUDE_PORT = com1 # programmer connected to serial device |
||
168 | AVRDUDE_PORT = lpt1 # programmer connected to parallel port |
||
169 | |||
170 | AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
||
171 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
||
172 | |||
173 | AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
||
174 | |||
175 | # Uncomment the following if you want avrdude's erase cycle counter. |
||
176 | # Note that this counter needs to be initialized first using -Yn, |
||
177 | # see avrdude manual. |
||
178 | #AVRDUDE_ERASE += -y |
||
179 | |||
180 | # Uncomment the following if you do /not/ wish a verification to be |
||
181 | # performed after programming the device. |
||
182 | #AVRDUDE_FLAGS += -V -E noreset |
||
183 | |||
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 |
||
73 | killagreg | 222 | LIMITS = $(SIZE) --mcu=$(MCU) -C $(TARGET).elf |
1 | ingob | 223 | |
224 | |||
225 | |||
226 | # Define Messages |
||
227 | # English |
||
228 | MSG_ERRORS_NONE = Errors: none |
||
229 | MSG_BEGIN = -------- begin -------- |
||
230 | MSG_END = -------- end -------- |
||
231 | MSG_SIZE_BEFORE = Size before: |
||
232 | MSG_SIZE_AFTER = Size after: |
||
233 | MSG_COFF = Converting to AVR COFF: |
||
234 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
||
235 | MSG_FLASH = Creating load file for Flash: |
||
236 | MSG_EEPROM = Creating load file for EEPROM: |
||
237 | MSG_EXTENDED_LISTING = Creating Extended Listing: |
||
238 | MSG_SYMBOL_TABLE = Creating Symbol Table: |
||
239 | MSG_LINKING = Linking: |
||
240 | MSG_COMPILING = Compiling: |
||
241 | MSG_ASSEMBLING = Assembling: |
||
242 | MSG_CLEANING = Cleaning project: |
||
243 | |||
244 | |||
245 | |||
246 | |||
247 | # Define all object files. |
||
248 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
||
249 | |||
250 | # Define all listing files. |
||
251 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) |
||
252 | |||
253 | # Combine all necessary flags and optional flags. |
||
254 | # Add target processor to flags. |
||
255 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) |
||
256 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
||
257 | |||
258 | |||
259 | |||
260 | # Default target. |
||
261 | all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \ |
||
262 | $(TARGET).lss $(TARGET).sym sizeafter finished end |
||
263 | |||
264 | |||
265 | # Eye candy. |
||
266 | # AVR Studio 3.x does not check make's exit code but relies on |
||
267 | # the following magic strings to be generated by the compile job. |
||
268 | begin: |
||
269 | @echo |
||
270 | @echo $(MSG_BEGIN) |
||
271 | |||
272 | finished: |
||
273 | @echo $(MSG_ERRORS_NONE) |
||
274 | |||
275 | end: |
||
276 | @echo $(MSG_END) |
||
277 | @echo |
||
278 | |||
279 | |||
280 | # Display size of file. |
||
281 | sizebefore: |
||
73 | killagreg | 282 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); $(LIMITS); echo; fi |
1 | ingob | 283 | |
284 | sizeafter: |
||
73 | killagreg | 285 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); $(LIMITS); echo; fi |
1 | ingob | 286 | |
287 | |||
288 | |||
289 | # Display compiler version information. |
||
290 | gccversion : |
||
291 | @$(CC) --version |
||
292 | |||
293 | |||
294 | |||
295 | |||
296 | # Convert ELF to COFF for use in debugging / simulating in |
||
297 | # AVR Studio or VMLAB. |
||
298 | COFFCONVERT=$(OBJCOPY) --debugging \ |
||
299 | --change-section-address .data-0x800000 \ |
||
300 | --change-section-address .bss-0x800000 \ |
||
301 | --change-section-address .noinit-0x800000 \ |
||
302 | --change-section-address .eeprom-0x810000 |
||
303 | |||
304 | |||
305 | coff: $(TARGET).elf |
||
306 | @echo |
||
307 | @echo $(MSG_COFF) $(TARGET).cof |
||
308 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
||
309 | |||
310 | |||
311 | extcoff: $(TARGET).elf |
||
312 | @echo |
||
313 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
||
314 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
||
315 | |||
316 | |||
317 | |||
318 | |||
319 | # Program the device. |
||
320 | program: $(TARGET).hex $(TARGET).eep |
||
321 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
||
322 | |||
323 | |||
324 | |||
325 | |||
326 | # Create final output files (.hex, .eep) from ELF output file. |
||
327 | %.hex: %.elf |
||
328 | @echo |
||
329 | @echo $(MSG_FLASH) $@ |
||
330 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
||
331 | |||
332 | %.eep: %.elf |
||
333 | @echo |
||
334 | @echo $(MSG_EEPROM) $@ |
||
335 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
||
336 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
||
337 | |||
338 | # Create extended listing file from ELF output file. |
||
339 | %.lss: %.elf |
||
340 | @echo |
||
341 | @echo $(MSG_EXTENDED_LISTING) $@ |
||
342 | $(OBJDUMP) -h -S $< > $@ |
||
343 | |||
344 | # Create a symbol table from ELF output file. |
||
345 | %.sym: %.elf |
||
346 | @echo |
||
347 | @echo $(MSG_SYMBOL_TABLE) $@ |
||
348 | avr-nm -n $< > $@ |
||
349 | |||
350 | |||
351 | |||
352 | # Link: create ELF output file from object files. |
||
353 | .SECONDARY : $(TARGET).elf |
||
354 | .PRECIOUS : $(OBJ) |
||
355 | %.elf: $(OBJ) |
||
356 | @echo |
||
357 | @echo $(MSG_LINKING) $@ |
||
358 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) |
||
359 | |||
360 | |||
361 | # Compile: create object files from C source files. |
||
362 | %.o : %.c |
||
363 | @echo |
||
364 | @echo $(MSG_COMPILING) $< |
||
365 | $(CC) -c $(ALL_CFLAGS) $< -o $@ |
||
366 | |||
367 | |||
368 | # Compile: create assembler files from C source files. |
||
369 | %.s : %.c |
||
370 | $(CC) -S $(ALL_CFLAGS) $< -o $@ |
||
371 | |||
372 | |||
373 | # Assemble: create object files from assembler source files. |
||
374 | %.o : %.S |
||
375 | @echo |
||
376 | @echo $(MSG_ASSEMBLING) $< |
||
377 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
||
378 | |||
379 | |||
380 | |||
381 | |||
382 | |||
383 | |||
384 | # Target: clean project. |
||
385 | clean: begin clean_list finished end |
||
386 | |||
387 | clean_list : |
||
388 | @echo |
||
389 | @echo $(MSG_CLEANING) |
||
72 | killagreg | 390 | $(REMOVE) MK3Mag_*.hex |
391 | $(REMOVE) MK3Mag_*.eep |
||
392 | $(REMOVE) $(TARGET).obj |
||
1 | ingob | 393 | $(REMOVE) $(TARGET).cof |
72 | killagreg | 394 | $(REMOVE) MK3Mag_*.elf |
395 | $(REMOVE) MK3Mag_*.map |
||
1 | ingob | 396 | $(REMOVE) $(TARGET).obj |
397 | $(REMOVE) $(TARGET).a90 |
||
72 | killagreg | 398 | $(REMOVE) MK3Mag_*.sym |
1 | ingob | 399 | $(REMOVE) $(TARGET).lnk |
72 | killagreg | 400 | $(REMOVE) MK3Mag_*.lss |
1 | ingob | 401 | $(REMOVE) $(OBJ) |
402 | $(REMOVE) $(LST) |
||
403 | $(REMOVE) $(SRC:.c=.s) |
||
404 | $(REMOVE) $(SRC:.c=.d) |
||
405 | |||
406 | |||
407 | # Automatically generate C source code dependencies. |
||
408 | # (Code originally taken from the GNU make user manual and modified |
||
409 | # (See README.txt Credits).) |
||
410 | # |
||
411 | # Note that this will work with sh (bash) and sed that is shipped with WinAVR |
||
412 | # (see the SHELL variable defined above). |
||
413 | # This may not work with other shells or other seds. |
||
414 | # |
||
415 | %.d: %.c |
||
416 | set -e; $(CC) -MM $(ALL_CFLAGS) $< \ |
||
417 | | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \ |
||
418 | [ -s $@ ] || rm -f $@ |
||
419 | |||
420 | |||
421 | # Remove the '-' if you want to see the dependency files generated. |
||
422 | -include $(SRC:.c=.d) |
||
423 | |||
424 | |||
425 | |||
426 | # Listing of phony targets. |
||
427 | .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \ |
||
428 | clean clean_list program |
||
429 |