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