Subversion Repositories HomeAutomation

Rev

Rev 1908 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
361 andfri 1
# $Id: Makefile 2285 2014-04-16 20:12:57Z arune $
1908 arune 2
BIOS_VERSION   = 0x1342
361 andfri 3
 
554 andfri 4
# Paths: set default pathnames if they are not
5
# passed on from parent Makefile.
6
ifndef TARGET
7
TARGET = bios
8
endif
9
ifndef LIBDIR
10
LIBDIR = .
11
endif
12
ifndef SRCDIR
13
SRCDIR = bios
14
endif
15
ifndef CFGDIR
16
CFGDIR = ..
17
endif
18
LIBNAME = lib$(TARGET)
361 andfri 19
 
554 andfri 20
include $(CFGDIR)/bios.inc
890 arune 21
include $(CFGDIR)/../system.inc
361 andfri 22
 
554 andfri 23
# VPATH: setup search path for source files.
24
vpath
25
vpath %.c $(SRCDIR):$(LIBDIR)
26
vpath %.S $(SRCDIR):$(LIBDIR)
27
 
28
# List source files here. (C dependencies are automatically generated.)
29
SOURCES =	vectors.S \
30
			bios_export.c \
31
			bios.c \
32
			flash.c
33
 
361 andfri 34
ifeq ($(CAN_CONTROLLER),MCP2515)
554 andfri 35
SOURCES += drivers/can/mcp2515/mcp2515.c
361 andfri 36
CAN_DRIVER_H = \<drivers/can/mcp2515/mcp2515.h\>
37
endif
38
 
554 andfri 39
# Start address for linking pass 1, will be overridden for optimizing pass
40
#BIOS_START = 0x100
361 andfri 41
 
554 andfri 42
# Optimization level, can be [0, 1, 2, 3, s]. 
43
# 0 = turn off optimization. s = optimize for size.
44
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
45
OPT = s
46
#OPT = 3
361 andfri 47
 
554 andfri 48
# Debugging format.
49
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
50
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
51
DEBUG = stabs
52
#DEBUG = dwarf-2
361 andfri 53
 
554 andfri 54
# List any extra directories to look for include files here.
55
# Each directory must be separated by a space.
56
EXTRAINCDIRS = $(LIBDIR) $(SRCDIR)
361 andfri 57
 
554 andfri 58
# Compiler flag to set the C Standard level.
59
# c89   - "ANSI" C
60
# gnu89 - c89 plus GCC extensions
61
# c99   - ISO C99 standard (not yet fully implemented)
62
# gnu99 - c99 plus GCC extensions
63
CSTANDARD = -std=gnu99
361 andfri 64
 
554 andfri 65
# Place -D or -U options here
66
CDEFS = -DF_CPU=$(F_CPU) \
67
		-DCAN_DRIVER_H=$(CAN_DRIVER_H) \
68
		-DBIOS_VERSION=$(BIOS_VERSION)
361 andfri 69
 
554 andfri 70
# Place -I options here
71
CINCS =
361 andfri 72
 
73
 
554 andfri 74
# Compiler flags.
75
#  -g*:          generate debugging information
76
#  -O*:          optimization level
77
#  -f...:        tuning, see GCC manual and avr-libc documentation
78
#  -Wall...:     warning level
79
#  -Wa,...:      tell GCC to pass this to the assembler.
80
#    -adhlns...: create assembler listing
81
CFLAGS = -mmcu=$(MCU) -I.
82
CFLAGS += -g$(DEBUG)
83
CFLAGS += $(CDEFS) $(CINCS)
84
CFLAGS += -O$(OPT)
85
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
86
CFLAGS += -Wall -Wstrict-prototypes
87
CFLAGS += -Wa,-adhlns=$(@:.o=.lst)
88
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
89
CFLAGS += $(CSTANDARD)
556 andfri 90
CFLAGS += $(GENDEPFLAGS)
361 andfri 91
 
92
 
93
 
554 andfri 94
# Assembler flags.
95
#  -Wa,...:   tell GCC to pass this to the assembler.
96
#  -ahlms:    create listing
97
#  -gstabs:   have the assembler create line number information; note that
98
#             for use in COFF files, additional information about filenames
99
#             and function names needs to be present in the assembler source
100
#             files -- see avr-libc docs [FIXME: not yet described there]
101
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
102
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp
103
ASFLAGS += -Wa,-g$(DEBUG)
438 eqlazer 104
 
105
 
554 andfri 106
#Additional libraries.
437 eqlazer 107
 
554 andfri 108
# Minimalistic printf version
109
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
438 eqlazer 110
 
554 andfri 111
# Floating point printf version (requires MATH_LIB = -lm below)
112
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
469 arune 113
 
554 andfri 114
PRINTF_LIB = 
361 andfri 115
 
554 andfri 116
# Minimalistic scanf version
117
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
361 andfri 118
 
554 andfri 119
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
120
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
361 andfri 121
 
554 andfri 122
SCANF_LIB = 
550 andfri 123
 
554 andfri 124
MATH_LIB = -lm
361 andfri 125
 
554 andfri 126
# External memory options
361 andfri 127
 
554 andfri 128
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
129
# used for variables (.data/.bss) and heap (malloc()).
130
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
361 andfri 131
 
554 andfri 132
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
133
# only used for heap (malloc()).
134
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
361 andfri 135
 
554 andfri 136
EXTMEMOPTS =
137
 
138
BIOS_START = $(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map)
139
BIOSOPTS = -Wl,--defsym,__bios_start=$(BIOS_START),--defsym,__boot_start=$(BOOT_START),-T$(LIBDIR)/ldscripts/$(MCU).ld
140
 
141
# Linker flags.
142
#  -Wl,...:     tell GCC to pass this to linker.
143
#    -Map:      create map file
144
#    --cref:    add cross reference to  map file
560 andfri 145
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map,--cref
554 andfri 146
LDFLAGS += $(EXTMEMOPTS)
147
LDFLAGS += $(BIOSOPTS)
148
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
149
 
150
# ---------------------------------------------------------------------------
151
 
152
# Define Messages
153
# English
154
MSG_ERRORS_NONE = Errors: none
155
MSG_BEGIN = -------- begin --------
156
MSG_END = --------  end  --------
157
MSG_SIZE_BEFORE = Size before: 
158
MSG_SIZE_AFTER = Size after:
159
MSG_COFF = Converting to AVR COFF:
160
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
161
MSG_FLASH = Creating load file for Flash:
162
MSG_EEPROM = Creating load file for EEPROM:
163
MSG_EXTENDED_LISTING = Creating Extended Listing:
164
MSG_SYMBOL_TABLE = Creating Symbol Table:
165
MSG_LINKING = Linking:
166
MSG_COMPILING = Compiling:
167
MSG_ASSEMBLING = Assembling:
168
MSG_DEPEND = Generating dependencies:
169
MSG_CLEANING = Cleaning project:
170
MSG_CREATE = Creating:
171
 
172
# Define all object files.
173
OBJ = $(filter %.o,$(SOURCES:.c=.o) $(SOURCES:.S=.o))
174
 
175
# Define all listing files.
176
LST = $(OBJ:.o=.lst)
177
 
178
# Define all dependency files.
556 andfri 179
DEP = $(OBJ:.o=.d)
554 andfri 180
 
181
BUILDDIRS = $(sort $(filter-out ./,$(dir $(OBJ))))
182
 
183
# Compiler flags to generate dependency files.
2285 arune 184
GENDEPFLAGS = -MMD -MP
554 andfri 185
 
186
# Default target.
890 arune 187
all: check_binaries sizebefore buildtree build lib sizeafter
554 andfri 188
 
189
build: elf hex eep lss sym
190
 
191
elf: $(TARGET).elf
192
hex: $(TARGET).hex
193
eep: $(TARGET).eep
194
lss: $(TARGET).lss 
195
sym: $(TARGET).sym
196
 
556 andfri 197
buildtree: $(BUILDDIRS)
198
 
554 andfri 199
# Display size of file.
200
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
201
ELFSIZE = $(SIZE) $(TARGET).elf
202
sizebefore:
890 arune 203
	@if [ -f $(TARGET).elf ]; then $(ECHO); $(ECHO) $(MSG_SIZE_BEFORE); $(ELFSIZE); $(ECHO); fi
554 andfri 204
 
205
sizeafter:
890 arune 206
	@if [ -f $(TARGET).elf ]; then $(ECHO); $(ECHO) $(MSG_SIZE_AFTER); $(ELFSIZE); $(ECHO); fi
554 andfri 207
 
208
# Generate config.h from bios.inc
890 arune 209
#HWID = `$(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8`
210
HWID := $(shell $(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8)
554 andfri 211
config.h: $(CFGDIR)/bios.inc
890 arune 212
	@$(ECHO) Generating $@
213
	@$(CAT) $^ | $(AWK) -v apa=0x$(HWID) 'BEGIN {  } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END {  }' > tmpfile
214
	@$(CAT) tmpfile > $^
215
	@$(RM) tmpfile
216
	@$(ECHO) "/* This file is automatically generated. Do not edit. */" > $@
217
	@$(ECHO) "" >> $@
218
	@$(ECHO) "#ifndef CONFIG_H_" >> $@
219
	@$(ECHO) "#define CONFIG_H_" >> $@
220
	@$(ECHO) "" >> $@
221
	@$(CAT) $^ | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
222
	@$(ECHO) "" >> $@
223
	@$(ECHO) "#endif /*CONFIG_H_*/" >> $@
773 arune 224
 
783 arune 225
# above echos does not use \n due to different handling on different os:es?
890 arune 226
#	@$(CAT) $^ | $(AWK) -v apa=0x$(HWID) 'BEGIN {  } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END {  }' > $^
773 arune 227
 
890 arune 228
#	@$(CAT) $^ | $(GREP) "<GENERATE_HW>" | $(AWK) -v apa=0x$(HWID) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,apa } END {  }' >> $@
229
#	@$(CAT) $^ | $(GREP) -v "<GENERATE_HW>" | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
769 arune 230
 
554 andfri 231
# Display compiler version information.
232
gccversion : 
233
	@$(CC) --version
234
 
235
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
236
COFFCONVERT=$(OBJCOPY) --debugging \
237
--change-section-address .data-0x800000 \
238
--change-section-address .bss-0x800000 \
239
--change-section-address .noinit-0x800000 \
240
--change-section-address .eeprom-0x810000 
241
 
242
 
243
coff: $(TARGET).elf
890 arune 244
	@$(ECHO) $(MSG_COFF) $(TARGET).cof
554 andfri 245
	@$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
246
 
247
extcoff: $(TARGET).elf
890 arune 248
	@$(ECHO) $(MSG_EXTENDED_COFF) $(TARGET).cof
554 andfri 249
	@$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
250
 
251
# Create final output files (.hex, .eep) from ELF output file.
252
%.hex: %.elf
890 arune 253
	@$(ECHO) $(MSG_FLASH) $@
561 andfri 254
	@$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
554 andfri 255
 
256
%.eep: %.elf
890 arune 257
	@$(ECHO) $(MSG_EEPROM) $@
554 andfri 258
	-@$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
259
	--change-section-lma .eeprom=0 -O ihex $< $@
260
 
261
# Create extended listing file from ELF output file.
262
%.lss: %.elf
890 arune 263
	@$(ECHO) $(MSG_EXTENDED_LISTING) $@
554 andfri 264
	@$(OBJDUMP) -h -S $< > $@
265
 
266
# Create a symbol table from ELF output file.
267
%.sym: %.elf
890 arune 268
	@$(ECHO) $(MSG_SYMBOL_TABLE) $@
554 andfri 269
	@$(NM) -n $< > $@
270
 
271
# Link: create ELF output file from object files.
272
.SECONDARY : $(TARGET).elf
273
#.PRECIOUS : $(OBJ)
274
$(TARGET)_pass1.elf: override BIOS_START=0x100
275
$(TARGET)_pass1.elf: config.h $(OBJ)
890 arune 276
	@$(ECHO) Linking pass 1:
554 andfri 277
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
278
 
279
$(TARGET).elf: config.h $(OBJ) | $(TARGET)_pass1.elf
890 arune 280
	@$(ECHO) Linking pass 2: Optimizing flash usage
554 andfri 281
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
282
 
283
$(LIBNAME).S: $(TARGET).elf
890 arune 284
	@$(ECHO) Generating $@
554 andfri 285
	@$(AWK) '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(TARGET).map > $@
361 andfri 286
 
554 andfri 287
bios.h: $(LIBDIR)/drivers/can/can.h $(LIBDIR)/bios/bios_export.h
890 arune 288
	@$(ECHO) Generating $@
289
	@$(ECHO) "/* This file is automatically generated. Do not edit. */" > $@
290
	@$(ECHO) "" >> $@
291
	@$(ECHO) "#ifndef BIOS_H_" >> $@
292
	@$(ECHO) "#define BIOS_H_" >> $@
293
	@$(ECHO) "" >> $@
294
	@$(CAT) $^ >> $@
295
	@$(ECHO) "" >> $@
296
	@$(ECHO) "#endif /*BIOS_H_*/" >> $@
361 andfri 297
 
554 andfri 298
lib: bios.h $(LIBNAME).a($(LIBNAME).o)
361 andfri 299
 
554 andfri 300
# Compile: create object files from C source files.
301
%.o : %.c
890 arune 302
	@$(ECHO) $(MSG_COMPILING) $<
554 andfri 303
	@$(CC) -c $(CFLAGS) $< -o $@ 
361 andfri 304
 
554 andfri 305
# Compile: create assembler files from C source files.
306
%.s : %.c
307
	@$(CC) -S $(CFLAGS) $< -o $@
361 andfri 308
 
554 andfri 309
# Assemble: create object files from assembler source files.
310
%.o : %.S
890 arune 311
	@$(ECHO) $(MSG_ASSEMBLING) $<
554 andfri 312
	@$(CC) -c $(ASFLAGS) $< -o $@
361 andfri 313
 
554 andfri 314
# Buildtree: create directories for output files.
315
$(BUILDDIRS) :
890 arune 316
	@$(ECHO) $(MSG_CREATE) $@
554 andfri 317
	@$(MKDIR) -p $@
361 andfri 318
 
554 andfri 319
# Target: clean project.
320
clean: 
890 arune 321
	@$(ECHO) $(MSG_CLEANING)
554 andfri 322
	$(RM) $(TARGET).eep
323
	$(RM) $(TARGET).cof
324
	$(RM) $(TARGET)_pass1.elf
325
	$(RM) $(TARGET).elf
326
	$(RM) $(TARGET).sym
327
	$(RM) $(TARGET).lss
328
	$(RM) $(OBJ)
329
	$(RM) $(DEP)
330
	$(RM) $(LST)
331
	$(RM) $(LIBNAME).S
332
	$(RM) config.h
333
	$(RM) -r drivers
361 andfri 334
 
891 arune 335
check_binaries:
336
ifndef AWK
337
	@echo 
338
	@echo ERROR! This is because you have not defined build-binaries in system.inc
339
	@echo Please update system.inc.template from SVN and then copy the build binaries definitions to your system.inc
340
	@echo 
341
	@false
342
endif
343
 
554 andfri 344
# Include the dependency files.
556 andfri 345
ifneq ($(MAKECMDGOALS),clean)
346
ifneq ($(strip $(DEP)),)
554 andfri 347
-include $(DEP)
556 andfri 348
endif
349
endif
362 andfri 350
 
554 andfri 351
# Listing of phony targets.
352
.PHONY : all sizebefore sizeafter build \
353
elf hex eep lss sym coff extcoff clean \
890 arune 354
gccversion lib check_binaries
361 andfri 355