trennfix/sw: Was not as beautiful as expected. Now it's better!
[eisenbahn.git] / trennfix / sw / Makefile
CommitLineData
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
dc41eb22 30CONFIG?=trennfix_0.4
54de37bf 31
7c08d02a 32include mk/${CONFIG}.mk
54de37bf 33
93cb14d4
PH
34INCLUDES+=-I mm/include -I include
35SRC+= mm/src/mm_switch.c
36CFLAGS+=-D__HW_CONF_HEADER__="<config/${CONFIG}.h>"
54de37bf
PH
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)
50FORMAT = ihex
51
52
53# Target file name (without extension).
93cb14d4 54TARGET = trennfix
54de37bf
PH
55
56# List C source files here. (C dependencies are automatically generated.)
57#SRC ?= main.c
58
59
54de37bf
PH
60ASRC =
61
54de37bf
PH
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.)
65OPT = 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.
72DEBUG = 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.
79EXTRAINCDIRS =
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
87CSTANDARD = -std=gnu99
88
89
90# Place -D or -U options here
91CDEFS = -DF_CPU=$(F_CPU)UL -DBOOT_START=${BOOT_START} -DBOOT_PAGES=${BOOT_PAGES}
92
93
94# Place -I options here
95CINCS =
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
107CFLAGS += -g$(DEBUG)
108CFLAGS += $(CDEFS) $(CINCS)
109CFLAGS += -O$(OPT)
110CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
111CFLAGS += -Wall -Wstrict-prototypes
112CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
113CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
114CFLAGS += $(CSTANDARD)
93cb14d4 115CFLAGS += $(INCLUDES)
54de37bf
PH
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]
125ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
126
127
128#---------------- Library Options ----------------
129# Minimalistic printf version
130PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
131
132# Floating point printf version (requires MATH_LIB = -lm below)
133PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
134
135# If this is left blank, then it will use the Standard printf version.
136PRINTF_LIB =
137#PRINTF_LIB = $(PRINTF_LIB_MIN)
138#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
139
140
141# Minimalistic scanf version
142SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
143
144# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
145SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
146
147# If this is left blank, then it will use the Standard scanf version.
148SCANF_LIB =
149#SCANF_LIB = $(SCANF_LIB_MIN)
150#SCANF_LIB = $(SCANF_LIB_FLOAT)
151
152
153MATH_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
166EXTMEMOPTS =
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
174LDFLAGS = $(BOOT_LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
175LDFLAGS += $(EXTMEMOPTS)
176LDFLAGS += $(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
189AVRDUDE_PROGRAMMER ?= avrisp2
190
191
192# com1 = serial port. Use lpt1 to connect to parallel port.
193AVRDUDE_PORT ?= usb
194
195AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
196#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
197
198AVRDUDE_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
215AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
216AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
217AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
218AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
d0047978 219AVRDUDE_FLAGS += -B 6
54de37bf
PH
220
221
222#---------------- Debugging Options ----------------
223
224# For simulavr only - target MCU frequency.
225DEBUG_MFREQ = $(F_CPU)
226
227# Set the DEBUG_UI to either gdb or insight.
228# DEBUG_UI = gdb
229DEBUG_UI = insight
230
231# Set the debugging back-end to either avarice, simulavr.
232DEBUG_BACKEND = avarice
233#DEBUG_BACKEND = simulavr
234
235# GDB Init Filename.
236GDBINIT_FILE = __avr_gdbinit
237
238# When using avarice settings for the JTAG
239JTAG_DEV = /dev/com1
240
241# Debugging port used to communicate between GDB / avarice / simulavr.
242DEBUG_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.
247DEBUG_HOST = localhost
248
249
250
251#============================================================================
252
253
254# Define programs and commands.
255SHELL = sh
256CC = avr-gcc
257OBJCOPY = avr-objcopy
258OBJDUMP = avr-objdump
259SIZE = avr-size
260NM = avr-nm
261AVRDUDE = avrdude
262REMOVE = rm -rf
263COPY = cp
264WINSHELL = cmd
265
266
267# Define Messages
268# English
269MSG_ERRORS_NONE = Errors: none
270MSG_BEGIN = -------- begin --------
271MSG_END = -------- end --------
272MSG_SIZE_BEFORE = Size before:
273MSG_SIZE_AFTER = Size after:
274MSG_COFF = Converting to AVR COFF:
275MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
276MSG_FLASH = Creating load file for Flash:
277MSG_EEPROM = Creating load file for EEPROM:
278MSG_EXTENDED_LISTING = Creating Extended Listing:
279MSG_SYMBOL_TABLE = Creating Symbol Table:
280MSG_LINKING = Linking:
281MSG_COMPILING = Compiling:
282MSG_ASSEMBLING = Assembling:
283MSG_CLEANING = Cleaning project:
284
285
286# Define all object files.
287OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
288
289# Define all listing files.
290LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
291
292
293# Compiler flags to generate dependency files.
294GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
295
296
297# Combine all necessary flags and optional flags.
298# Add target processor to flags.
299ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
300ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
301
302
303# Default target.
304all: begin gccversion sizebefore build sizeafter end
305
306build: elf hex eep lss sym
307
308elf: $(TARGET).elf
309hex: $(TARGET).hex
310eep: $(TARGET).eep
311lss: $(TARGET).lss
312sym: $(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.
318begin:
319 @echo
320 @echo $(MSG_BEGIN)
321
322end:
323 @echo $(MSG_END)
324 @echo
325
326
327# Display size of file.
328HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
329ELFSIZE = $(SIZE) -A $(TARGET).elf
330AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
331
332sizebefore:
333 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
334 $(AVRMEM) 2>/dev/null; echo; fi
335
336sizeafter:
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.
343gccversion :
344 @$(CC) --version
345
346
347
348# Program the device.
349program: $(TARGET).hex $(TARGET).eep
350 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
351
352fuses:
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().
358gdb-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)
365ifeq ($(DEBUG_BACKEND),simulavr)
366 @echo load >> $(GDBINIT_FILE)
367endif
368 @echo break main >> $(GDBINIT_FILE)
369
370debug: gdb-config $(TARGET).elf
371ifeq ($(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
377else
378 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
379 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
380endif
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.
385COFFCONVERT=$(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
392coff: $(TARGET).elf
393 @echo
394 @echo $(MSG_COFF) $(TARGET).cof
395 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
396
397
398extcoff: $(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.
464clean: begin clean_list end
465
466clean_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 \
491build elf hex eep lss sym coff extcoff \
492clean clean_list program debug gdb-config
493