Rev 67 | Rev 72 | Go to most recent revision | 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.) |
||
57 | killagreg | 61 | OPT = 2 |
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) |
47 | killagreg | 108 | 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 | 109 | |
69 | killagreg | 110 | ifeq ($(OPTION), HEADTRACKER) |
111 | CFLAGS += -DHEADTRACKER |
||
1 | ingob | 112 | endif |
113 | |||
114 | |||
115 | |||
116 | # Optional assembler flags. |
||
117 | # -Wa,...: tell GCC to pass this to the assembler. |
||
118 | # -ahlms: create listing |
||
119 | # -gstabs: have the assembler create line number information; note that |
||
120 | # for use in COFF files, additional information about filenames |
||
121 | # and function names needs to be present in the assembler source |
||
122 | # files -- see avr-libc docs [FIXME: not yet described there] |
||
123 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
||
124 | |||
125 | |||
126 | |||
127 | # Optional linker flags. |
||
128 | # -Wl,...: tell GCC to pass this to linker. |
||
129 | # -Map: create map file |
||
130 | # --cref: add cross reference to map file |
||
131 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
||
132 | |||
133 | |||
134 | |||
135 | # Additional libraries |
||
136 | |||
137 | # Minimalistic printf version |
||
138 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_min |
||
139 | |||
140 | # Floating point printf version (requires -lm below) |
||
141 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt |
||
142 | |||
143 | # -lm = math library |
||
144 | LDFLAGS += -lm |
||
145 | |||
146 | |||
147 | |||
148 | |||
149 | # Programming support using avrdude. Settings and variables. |
||
150 | |||
151 | # Programming hardware: alf avr910 avrisp bascom bsd |
||
152 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
||
153 | # |
||
154 | # Type: avrdude -c ? |
||
155 | # to get a full listing. |
||
156 | # |
||
157 | |||
158 | AVRDUDE_PROGRAMMER = dt006 |
||
159 | #AVRDUDE_PROGRAMMER = stk200 |
||
160 | |||
161 | #AVRDUDE_PORT = com1 # programmer connected to serial device |
||
162 | AVRDUDE_PORT = lpt1 # programmer connected to parallel port |
||
163 | |||
164 | AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
||
165 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
||
166 | |||
167 | AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
||
168 | |||
169 | # Uncomment the following if you want avrdude's erase cycle counter. |
||
170 | # Note that this counter needs to be initialized first using -Yn, |
||
171 | # see avrdude manual. |
||
172 | #AVRDUDE_ERASE += -y |
||
173 | |||
174 | # Uncomment the following if you do /not/ wish a verification to be |
||
175 | # performed after programming the device. |
||
176 | #AVRDUDE_FLAGS += -V -E noreset |
||
177 | |||
178 | |||
179 | # Increase verbosity level. Please use this when submitting bug |
||
180 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
||
181 | # to submit bug reports. |
||
182 | #AVRDUDE_FLAGS += -v -v |
||
183 | |||
184 | |||
185 | |||
186 | |||
187 | # --------------------------------------------------------------------------- |
||
188 | |||
189 | # Define directories, if needed. |
||
190 | DIRAVR = c:/winavr |
||
191 | DIRAVRBIN = $(DIRAVR)/bin |
||
192 | DIRAVRUTILS = $(DIRAVR)/utils/bin |
||
193 | DIRINC = . |
||
194 | DIRLIB = $(DIRAVR)/avr/lib |
||
195 | |||
196 | |||
197 | # Define programs and commands. |
||
198 | SHELL = sh |
||
199 | |||
200 | CC = avr-gcc |
||
201 | |||
202 | OBJCOPY = avr-objcopy |
||
203 | OBJDUMP = avr-objdump |
||
204 | SIZE = avr-size |
||
205 | |||
206 | |||
207 | # Programming support using avrdude. |
||
208 | AVRDUDE = avrdude |
||
209 | |||
210 | |||
211 | REMOVE = rm -f |
||
212 | COPY = cp |
||
213 | |||
214 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
||
215 | ELFSIZE = $(SIZE) -A $(TARGET).elf |
||
216 | |||
217 | |||
218 | |||
219 | # Define Messages |
||
220 | # English |
||
221 | MSG_ERRORS_NONE = Errors: none |
||
222 | MSG_BEGIN = -------- begin -------- |
||
223 | MSG_END = -------- end -------- |
||
224 | MSG_SIZE_BEFORE = Size before: |
||
225 | MSG_SIZE_AFTER = Size after: |
||
226 | MSG_COFF = Converting to AVR COFF: |
||
227 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
||
228 | MSG_FLASH = Creating load file for Flash: |
||
229 | MSG_EEPROM = Creating load file for EEPROM: |
||
230 | MSG_EXTENDED_LISTING = Creating Extended Listing: |
||
231 | MSG_SYMBOL_TABLE = Creating Symbol Table: |
||
232 | MSG_LINKING = Linking: |
||
233 | MSG_COMPILING = Compiling: |
||
234 | MSG_ASSEMBLING = Assembling: |
||
235 | MSG_CLEANING = Cleaning project: |
||
236 | |||
237 | |||
238 | |||
239 | |||
240 | # Define all object files. |
||
241 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
||
242 | |||
243 | # Define all listing files. |
||
244 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) |
||
245 | |||
246 | # Combine all necessary flags and optional flags. |
||
247 | # Add target processor to flags. |
||
248 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) |
||
249 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
||
250 | |||
251 | |||
252 | |||
253 | # Default target. |
||
254 | all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \ |
||
255 | $(TARGET).lss $(TARGET).sym sizeafter finished end |
||
256 | |||
257 | |||
258 | # Eye candy. |
||
259 | # AVR Studio 3.x does not check make's exit code but relies on |
||
260 | # the following magic strings to be generated by the compile job. |
||
261 | begin: |
||
262 | @echo |
||
263 | @echo $(MSG_BEGIN) |
||
264 | |||
265 | finished: |
||
266 | @echo $(MSG_ERRORS_NONE) |
||
267 | |||
268 | end: |
||
269 | @echo $(MSG_END) |
||
270 | @echo |
||
271 | |||
272 | |||
273 | # Display size of file. |
||
274 | sizebefore: |
||
275 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi |
||
276 | |||
277 | sizeafter: |
||
278 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi |
||
279 | |||
280 | |||
281 | |||
282 | # Display compiler version information. |
||
283 | gccversion : |
||
284 | @$(CC) --version |
||
285 | |||
286 | |||
287 | |||
288 | |||
289 | # Convert ELF to COFF for use in debugging / simulating in |
||
290 | # AVR Studio or VMLAB. |
||
291 | COFFCONVERT=$(OBJCOPY) --debugging \ |
||
292 | --change-section-address .data-0x800000 \ |
||
293 | --change-section-address .bss-0x800000 \ |
||
294 | --change-section-address .noinit-0x800000 \ |
||
295 | --change-section-address .eeprom-0x810000 |
||
296 | |||
297 | |||
298 | coff: $(TARGET).elf |
||
299 | @echo |
||
300 | @echo $(MSG_COFF) $(TARGET).cof |
||
301 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
||
302 | |||
303 | |||
304 | extcoff: $(TARGET).elf |
||
305 | @echo |
||
306 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
||
307 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
||
308 | |||
309 | |||
310 | |||
311 | |||
312 | # Program the device. |
||
313 | program: $(TARGET).hex $(TARGET).eep |
||
314 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
||
315 | |||
316 | |||
317 | |||
318 | |||
319 | # Create final output files (.hex, .eep) from ELF output file. |
||
320 | %.hex: %.elf |
||
321 | @echo |
||
322 | @echo $(MSG_FLASH) $@ |
||
323 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
||
324 | |||
325 | %.eep: %.elf |
||
326 | @echo |
||
327 | @echo $(MSG_EEPROM) $@ |
||
328 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
||
329 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
||
330 | |||
331 | # Create extended listing file from ELF output file. |
||
332 | %.lss: %.elf |
||
333 | @echo |
||
334 | @echo $(MSG_EXTENDED_LISTING) $@ |
||
335 | $(OBJDUMP) -h -S $< > $@ |
||
336 | |||
337 | # Create a symbol table from ELF output file. |
||
338 | %.sym: %.elf |
||
339 | @echo |
||
340 | @echo $(MSG_SYMBOL_TABLE) $@ |
||
341 | avr-nm -n $< > $@ |
||
342 | |||
343 | |||
344 | |||
345 | # Link: create ELF output file from object files. |
||
346 | .SECONDARY : $(TARGET).elf |
||
347 | .PRECIOUS : $(OBJ) |
||
348 | %.elf: $(OBJ) |
||
349 | @echo |
||
350 | @echo $(MSG_LINKING) $@ |
||
351 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) |
||
352 | |||
353 | |||
354 | # Compile: create object files from C source files. |
||
355 | %.o : %.c |
||
356 | @echo |
||
357 | @echo $(MSG_COMPILING) $< |
||
358 | $(CC) -c $(ALL_CFLAGS) $< -o $@ |
||
359 | |||
360 | |||
361 | # Compile: create assembler files from C source files. |
||
362 | %.s : %.c |
||
363 | $(CC) -S $(ALL_CFLAGS) $< -o $@ |
||
364 | |||
365 | |||
366 | # Assemble: create object files from assembler source files. |
||
367 | %.o : %.S |
||
368 | @echo |
||
369 | @echo $(MSG_ASSEMBLING) $< |
||
370 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
||
371 | |||
372 | |||
373 | |||
374 | |||
375 | |||
376 | |||
377 | # Target: clean project. |
||
378 | clean: begin clean_list finished end |
||
379 | |||
380 | clean_list : |
||
381 | @echo |
||
382 | @echo $(MSG_CLEANING) |
||
383 | # $(REMOVE) $(TARGET).hex |
||
384 | # $(REMOVE) $(TARGET).eep |
||
385 | # $(REMOVE) $(TARGET).obj |
||
386 | $(REMOVE) $(TARGET).cof |
||
387 | $(REMOVE) $(TARGET).elf |
||
388 | $(REMOVE) $(TARGET).map |
||
389 | $(REMOVE) $(TARGET).obj |
||
390 | $(REMOVE) $(TARGET).a90 |
||
391 | $(REMOVE) $(TARGET).sym |
||
392 | $(REMOVE) $(TARGET).lnk |
||
393 | $(REMOVE) $(TARGET).lss |
||
394 | $(REMOVE) $(OBJ) |
||
395 | $(REMOVE) $(LST) |
||
396 | $(REMOVE) $(SRC:.c=.s) |
||
397 | $(REMOVE) $(SRC:.c=.d) |
||
398 | |||
399 | |||
400 | # Automatically generate C source code dependencies. |
||
401 | # (Code originally taken from the GNU make user manual and modified |
||
402 | # (See README.txt Credits).) |
||
403 | # |
||
404 | # Note that this will work with sh (bash) and sed that is shipped with WinAVR |
||
405 | # (see the SHELL variable defined above). |
||
406 | # This may not work with other shells or other seds. |
||
407 | # |
||
408 | %.d: %.c |
||
409 | set -e; $(CC) -MM $(ALL_CFLAGS) $< \ |
||
410 | | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \ |
||
411 | [ -s $@ ] || rm -f $@ |
||
412 | |||
413 | |||
414 | # Remove the '-' if you want to see the dependency files generated. |
||
415 | -include $(SRC:.c=.d) |
||
416 | |||
417 | |||
418 | |||
419 | # Listing of phony targets. |
||
420 | .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \ |
||
421 | clean clean_list program |
||
422 |