Commit | Line | Data |
---|---|---|
54de37bf PH |
1 | #---------------------------------------------------------------------------- |
2 | # | |
3 | # Makefile based on the public domain Makefile by Peter Fleury | |
4 | # | |
5 | #---------------------------------------------------------------------------- | |
6 | # On command line: | |
7 | # | |
8 | # make all = Make software. | |
9 | # | |
10 | # make clean = Clean out built project files. | |
11 | # | |
12 | # make coff = Convert ELF to AVR COFF. | |
13 | # | |
14 | # make extcoff = Convert ELF to AVR Extended COFF. | |
15 | # | |
16 | # make program = Download the hex file to the device, using avrdude. | |
17 | # Please customize the avrdude settings below first! | |
18 | # | |
19 | # make debug = Start either simulavr or avarice as specified for debugging, | |
20 | # with avr-gdb or avr-insight as the front end for debugging. | |
21 | # | |
22 | # make filename.s = Just compile filename.c into the assembler code only. | |
23 | # | |
24 | # make filename.i = Create a preprocessed source file for use in submitting | |
25 | # bug reports to the GCC project. | |
26 | # | |
27 | # To rebuild project do "make clean" then "make all". | |
28 | #---------------------------------------------------------------------------- | |
29 | ||
30 | HW?=default | |
31 | ||
32 | CONFIG ?= config.make | |
33 | include ${CONFIG} | |
34 | ||
35 | #test: | |
36 | # echo ${BOOT_PAGES} | |
37 | ||
38 | # MCU name | |
39 | #MCU ?= atmega328 | |
40 | ||
41 | # Processor frequency. | |
42 | # This will define a symbol, F_CPU, in all source code files equal to the | |
43 | # processor frequency. You can then use this symbol in your source code to | |
44 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | |
45 | # automatically to create a 32-bit value in your source code. | |
46 | #F_CPU ?= 20000000 | |
47 | ||
48 | ||
49 | # Output format. (can be srec, ihex, binary) | |
50 | FORMAT = ihex | |
51 | ||
52 | ||
53 | # Target file name (without extension). | |
54 | TARGET = weiche1 | |
55 | ||
56 | # List C source files here. (C dependencies are automatically generated.) | |
57 | #SRC ?= main.c | |
58 | ||
59 | ||
60 | # List Assembler source files here. | |
61 | # Make them always end in a capital .S. Files ending in a lowercase .s | |
62 | # will not be considered source files but generated files (assembler | |
63 | # output from the compiler), and will be deleted upon "make clean"! | |
64 | # Even though the DOS/Win* filesystem matches both .s and .S the same, | |
65 | # it will preserve the spelling of the filenames, and gcc itself does | |
66 | # care about how the name is spelled on its command-line. | |
67 | ASRC = | |
68 | ||
69 | ||
70 | # Optimization level, can be [0, 1, 2, 3, s]. | |
71 | # 0 = turn off optimization. s = optimize for size. | |
72 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) | |
73 | OPT = s | |
74 | ||
75 | ||
76 | # Debugging format. | |
77 | # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. | |
78 | # AVR Studio 4.10 requires dwarf-2. | |
79 | # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. | |
80 | DEBUG = dwarf-2 | |
81 | ||
82 | ||
83 | # List any extra directories to look for include files here. | |
84 | # Each directory must be seperated by a space. | |
85 | # Use forward slashes for directory separators. | |
86 | # For a directory that has spaces, enclose it in quotes. | |
87 | EXTRAINCDIRS = | |
88 | ||
89 | ||
90 | # Compiler flag to set the C Standard level. | |
91 | # c89 = "ANSI" C | |
92 | # gnu89 = c89 plus GCC extensions | |
93 | # c99 = ISO C99 standard (not yet fully implemented) | |
94 | # gnu99 = c99 plus GCC extensions | |
95 | CSTANDARD = -std=gnu99 | |
96 | ||
97 | ||
98 | # Place -D or -U options here | |
99 | CDEFS = -DF_CPU=$(F_CPU)UL -DBOOT_START=${BOOT_START} -DBOOT_PAGES=${BOOT_PAGES} | |
100 | ||
101 | ||
102 | # Place -I options here | |
103 | CINCS = | |
104 | ||
105 | # Bootloader LDFLAGS | |
106 | #BOOT_LDFLAGS=-Wl,-Ttext=${BOOT_START} | |
107 | ||
108 | #---------------- Compiler Options ---------------- | |
109 | # -g*: generate debugging information | |
110 | # -O*: optimization level | |
111 | # -f...: tuning, see GCC manual and avr-libc documentation | |
112 | # -Wall...: warning level | |
113 | # -Wa,...: tell GCC to pass this to the assembler. | |
114 | # -adhlns...: create assembler listing | |
115 | CFLAGS += -g$(DEBUG) | |
116 | CFLAGS += $(CDEFS) $(CINCS) | |
117 | CFLAGS += -O$(OPT) | |
118 | CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums | |
119 | CFLAGS += -Wall -Wstrict-prototypes | |
120 | CFLAGS += -Wa,-adhlns=$(<:.c=.lst) | |
121 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | |
122 | CFLAGS += $(CSTANDARD) | |
123 | ||
124 | ||
125 | #---------------- Assembler Options ---------------- | |
126 | # -Wa,...: tell GCC to pass this to the assembler. | |
127 | # -ahlms: create listing | |
128 | # -gstabs: have the assembler create line number information; note that | |
129 | # for use in COFF files, additional information about filenames | |
130 | # and function names needs to be present in the assembler source | |
131 | # files -- see avr-libc docs [FIXME: not yet described there] | |
132 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs | |
133 | ||
134 | ||
135 | #---------------- Library Options ---------------- | |
136 | # Minimalistic printf version | |
137 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min | |
138 | ||
139 | # Floating point printf version (requires MATH_LIB = -lm below) | |
140 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt | |
141 | ||
142 | # If this is left blank, then it will use the Standard printf version. | |
143 | PRINTF_LIB = | |
144 | #PRINTF_LIB = $(PRINTF_LIB_MIN) | |
145 | #PRINTF_LIB = $(PRINTF_LIB_FLOAT) | |
146 | ||
147 | ||
148 | # Minimalistic scanf version | |
149 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min | |
150 | ||
151 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) | |
152 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt | |
153 | ||
154 | # If this is left blank, then it will use the Standard scanf version. | |
155 | SCANF_LIB = | |
156 | #SCANF_LIB = $(SCANF_LIB_MIN) | |
157 | #SCANF_LIB = $(SCANF_LIB_FLOAT) | |
158 | ||
159 | ||
160 | MATH_LIB = -lm | |
161 | ||
162 | ||
163 | #---------------- External Memory Options ---------------- | |
164 | ||
165 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | |
166 | # used for variables (.data/.bss) and heap (malloc()). | |
167 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff | |
168 | ||
169 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | |
170 | # only used for heap (malloc()). | |
171 | #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff | |
172 | ||
173 | EXTMEMOPTS = | |
174 | ||
175 | ||
176 | ||
177 | #---------------- Linker Options ---------------- | |
178 | # -Wl,...: tell GCC to pass this to linker. | |
179 | # -Map: create map file | |
180 | # --cref: add cross reference to map file | |
181 | LDFLAGS = $(BOOT_LDFLAGS) -Wl,-Map=$(TARGET).map,--cref | |
182 | LDFLAGS += $(EXTMEMOPTS) | |
183 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) | |
184 | ||
185 | ||
186 | ||
187 | #---------------- Programming Options (avrdude) ---------------- | |
188 | ||
189 | # Programming hardware: alf avr910 avrisp bascom bsd | |
190 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 | |
191 | # | |
192 | # Type: avrdude -c ? | |
193 | # to get a full listing. | |
194 | # | |
195 | ||
196 | AVRDUDE_PROGRAMMER ?= avrisp2 | |
197 | ||
198 | ||
199 | # com1 = serial port. Use lpt1 to connect to parallel port. | |
200 | AVRDUDE_PORT ?= usb | |
201 | ||
202 | AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex | |
203 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep | |
204 | ||
205 | AVRDUDE_WRITE_FUSES = -U lfuse:w:${LFUSE}:m -U hfuse:w:${HFUSE}:m \ | |
206 | -U efuse:w:${EFUSE}:m | |
207 | ||
208 | # Uncomment the following if you want avrdude's erase cycle counter. | |
209 | # Note that this counter needs to be initialized first using -Yn, | |
210 | # see avrdude manual. | |
211 | #AVRDUDE_ERASE_COUNTER = -y | |
212 | ||
213 | # Uncomment the following if you do /not/ wish a verification to be | |
214 | # performed after programming the device. | |
215 | # AVRDUDE_NO_VERIFY = -V | |
216 | ||
217 | # Increase verbosity level. Please use this when submitting bug | |
218 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> | |
219 | # to submit bug reports. | |
220 | #AVRDUDE_VERBOSE = -v -v | |
221 | ||
222 | AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) | |
223 | AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) | |
224 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) | |
225 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) | |
226 | AVRDUDE_FLAGS += -B 20 | |
227 | ||
228 | ||
229 | #---------------- Debugging Options ---------------- | |
230 | ||
231 | # For simulavr only - target MCU frequency. | |
232 | DEBUG_MFREQ = $(F_CPU) | |
233 | ||
234 | # Set the DEBUG_UI to either gdb or insight. | |
235 | # DEBUG_UI = gdb | |
236 | DEBUG_UI = insight | |
237 | ||
238 | # Set the debugging back-end to either avarice, simulavr. | |
239 | DEBUG_BACKEND = avarice | |
240 | #DEBUG_BACKEND = simulavr | |
241 | ||
242 | # GDB Init Filename. | |
243 | GDBINIT_FILE = __avr_gdbinit | |
244 | ||
245 | # When using avarice settings for the JTAG | |
246 | JTAG_DEV = /dev/com1 | |
247 | ||
248 | # Debugging port used to communicate between GDB / avarice / simulavr. | |
249 | DEBUG_PORT = 4242 | |
250 | ||
251 | # Debugging host used to communicate between GDB / avarice / simulavr, normally | |
252 | # just set to localhost unless doing some sort of crazy debugging when | |
253 | # avarice is running on a different computer. | |
254 | DEBUG_HOST = localhost | |
255 | ||
256 | ||
257 | ||
258 | #============================================================================ | |
259 | ||
260 | ||
261 | # Define programs and commands. | |
262 | SHELL = sh | |
263 | CC = avr-gcc | |
264 | OBJCOPY = avr-objcopy | |
265 | OBJDUMP = avr-objdump | |
266 | SIZE = avr-size | |
267 | NM = avr-nm | |
268 | AVRDUDE = avrdude | |
269 | REMOVE = rm -rf | |
270 | COPY = cp | |
271 | WINSHELL = cmd | |
272 | ||
273 | ||
274 | # Define Messages | |
275 | # English | |
276 | MSG_ERRORS_NONE = Errors: none | |
277 | MSG_BEGIN = -------- begin -------- | |
278 | MSG_END = -------- end -------- | |
279 | MSG_SIZE_BEFORE = Size before: | |
280 | MSG_SIZE_AFTER = Size after: | |
281 | MSG_COFF = Converting to AVR COFF: | |
282 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: | |
283 | MSG_FLASH = Creating load file for Flash: | |
284 | MSG_EEPROM = Creating load file for EEPROM: | |
285 | MSG_EXTENDED_LISTING = Creating Extended Listing: | |
286 | MSG_SYMBOL_TABLE = Creating Symbol Table: | |
287 | MSG_LINKING = Linking: | |
288 | MSG_COMPILING = Compiling: | |
289 | MSG_ASSEMBLING = Assembling: | |
290 | MSG_CLEANING = Cleaning project: | |
291 | ||
292 | ||
293 | # Define all object files. | |
294 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) | |
295 | ||
296 | # Define all listing files. | |
297 | LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) | |
298 | ||
299 | ||
300 | # Compiler flags to generate dependency files. | |
301 | GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d | |
302 | ||
303 | ||
304 | # Combine all necessary flags and optional flags. | |
305 | # Add target processor to flags. | |
306 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) | |
307 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) | |
308 | ||
309 | ||
310 | # Default target. | |
311 | all: begin gccversion sizebefore build sizeafter end | |
312 | ||
313 | build: elf hex eep lss sym | |
314 | ||
315 | elf: $(TARGET).elf | |
316 | hex: $(TARGET).hex | |
317 | eep: $(TARGET).eep | |
318 | lss: $(TARGET).lss | |
319 | sym: $(TARGET).sym | |
320 | ||
321 | ||
322 | # Eye candy. | |
323 | # AVR Studio 3.x does not check make's exit code but relies on | |
324 | # the following magic strings to be generated by the compile job. | |
325 | begin: | |
326 | @echo | |
327 | @echo $(MSG_BEGIN) | |
328 | ||
329 | end: | |
330 | @echo $(MSG_END) | |
331 | @echo | |
332 | ||
333 | ||
334 | # Display size of file. | |
335 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex | |
336 | ELFSIZE = $(SIZE) -A $(TARGET).elf | |
337 | AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) | |
338 | ||
339 | sizebefore: | |
340 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ | |
341 | $(AVRMEM) 2>/dev/null; echo; fi | |
342 | ||
343 | sizeafter: | |
344 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ | |
345 | $(AVRMEM) 2>/dev/null; echo; fi | |
346 | ||
347 | ||
348 | ||
349 | # Display compiler version information. | |
350 | gccversion : | |
351 | @$(CC) --version | |
352 | ||
353 | ||
354 | ||
355 | # Program the device. | |
356 | program: $(TARGET).hex $(TARGET).eep | |
357 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) | |
358 | ||
359 | fuses: | |
360 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSES) | |
361 | ||
362 | # Generate avr-gdb config/init file which does the following: | |
363 | # define the reset signal, load the target file, connect to target, and set | |
364 | # a breakpoint at main(). | |
365 | gdb-config: | |
366 | @$(REMOVE) $(GDBINIT_FILE) | |
367 | @echo define reset >> $(GDBINIT_FILE) | |
368 | @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) | |
369 | @echo end >> $(GDBINIT_FILE) | |
370 | @echo file $(TARGET).elf >> $(GDBINIT_FILE) | |
371 | @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) | |
372 | ifeq ($(DEBUG_BACKEND),simulavr) | |
373 | @echo load >> $(GDBINIT_FILE) | |
374 | endif | |
375 | @echo break main >> $(GDBINIT_FILE) | |
376 | ||
377 | debug: gdb-config $(TARGET).elf | |
378 | ifeq ($(DEBUG_BACKEND), avarice) | |
379 | @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. | |
380 | @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ | |
381 | $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) | |
382 | @$(WINSHELL) /c pause | |
383 | ||
384 | else | |
385 | @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ | |
386 | $(DEBUG_MFREQ) --port $(DEBUG_PORT) | |
387 | endif | |
388 | @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) | |
389 | ||
390 | ||
391 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. | |
392 | COFFCONVERT=$(OBJCOPY) --debugging \ | |
393 | --change-section-address .data-0x800000 \ | |
394 | --change-section-address .bss-0x800000 \ | |
395 | --change-section-address .noinit-0x800000 \ | |
396 | --change-section-address .eeprom-0x810000 | |
397 | ||
398 | ||
399 | coff: $(TARGET).elf | |
400 | @echo | |
401 | @echo $(MSG_COFF) $(TARGET).cof | |
402 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof | |
403 | ||
404 | ||
405 | extcoff: $(TARGET).elf | |
406 | @echo | |
407 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof | |
408 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof | |
409 | ||
410 | ||
411 | ||
412 | # Create final output files (.hex, .eep) from ELF output file. | |
413 | %.hex: %.elf | |
414 | @echo | |
415 | @echo $(MSG_FLASH) $@ | |
416 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ | |
417 | ||
418 | %.eep: %.elf | |
419 | @echo | |
420 | @echo $(MSG_EEPROM) $@ | |
421 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ | |
422 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ | |
423 | ||
424 | # Create extended listing file from ELF output file. | |
425 | %.lss: %.elf | |
426 | @echo | |
427 | @echo $(MSG_EXTENDED_LISTING) $@ | |
428 | $(OBJDUMP) -h -S $< > $@ | |
429 | ||
430 | # Create a symbol table from ELF output file. | |
431 | %.sym: %.elf | |
432 | @echo | |
433 | @echo $(MSG_SYMBOL_TABLE) $@ | |
434 | $(NM) -n $< > $@ | |
435 | ||
436 | ||
437 | ||
438 | # Link: create ELF output file from object files. | |
439 | .SECONDARY : $(TARGET).elf | |
440 | .PRECIOUS : $(OBJ) | |
441 | %.elf: $(OBJ) | |
442 | @echo | |
443 | @echo $(MSG_LINKING) $@ | |
444 | $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) | |
445 | ||
446 | ||
447 | # Compile: create object files from C source files. | |
448 | %.o : %.c Makefile | |
449 | @echo | |
450 | @echo $(MSG_COMPILING) $< | |
451 | $(CC) -c $(ALL_CFLAGS) $< -o $@ | |
452 | ||
453 | ||
454 | # Compile: create assembler files from C source files. | |
455 | %.s : %.c Makefile | |
456 | $(CC) -S $(ALL_CFLAGS) $< -o $@ | |
457 | ||
458 | ||
459 | # Assemble: create object files from assembler source files. | |
460 | %.o : %.S | |
461 | @echo | |
462 | @echo $(MSG_ASSEMBLING) $< | |
463 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ | |
464 | ||
465 | # Create preprocessed source for use in sending a bug report. | |
466 | %.i : %.c | |
467 | $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ | |
468 | ||
469 | ||
470 | # Target: clean project. | |
471 | clean: begin clean_list end | |
472 | ||
473 | clean_list : | |
474 | @echo | |
475 | @echo $(MSG_CLEANING) | |
476 | $(REMOVE) $(TARGET).hex | |
477 | $(REMOVE) $(TARGET).eep | |
478 | $(REMOVE) $(TARGET).cof | |
479 | $(REMOVE) $(TARGET).elf | |
480 | $(REMOVE) $(TARGET).map | |
481 | $(REMOVE) $(TARGET).sym | |
482 | $(REMOVE) $(TARGET).lss | |
483 | $(REMOVE) $(OBJ) | |
484 | $(REMOVE) $(LST) | |
485 | $(REMOVE) $(SRC:.c=.s) | |
486 | $(REMOVE) $(SRC:.c=.d) | |
487 | $(REMOVE) .dep | |
488 | $(REMOVE) *~ | |
489 | ||
490 | ||
491 | ||
492 | # Include the dependency files. | |
493 | -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) | |
494 | ||
495 | ||
496 | # Listing of phony targets. | |
497 | .PHONY : all begin finish end sizebefore sizeafter gccversion \ | |
498 | build elf hex eep lss sym coff extcoff \ | |
499 | clean clean_list program debug gdb-config | |
500 |