Subversion Repositories HomeAutomation

Rev

Rev 784 | Rev 891 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 784 Rev 890
Line 1... Line 1...
1
# $Id: Makefile 784 2008-05-06 16:18:17Z arune $
1
# $Id: Makefile 890 2008-07-16 13:43:32Z arune $
2
BIOS_VERSION   = 0x1339
2
BIOS_VERSION   = 0x1339
3
 
3
 
4
# Paths: set default pathnames if they are not
4
# Paths: set default pathnames if they are not
5
# passed on from parent Makefile.
5
# passed on from parent Makefile.
6
ifndef TARGET
6
ifndef TARGET
Line 16... Line 16...
16
CFGDIR = ..
16
CFGDIR = ..
17
endif
17
endif
18
LIBNAME = lib$(TARGET)
18
LIBNAME = lib$(TARGET)
19
 
19
 
20
include $(CFGDIR)/bios.inc
20
include $(CFGDIR)/bios.inc
-
 
21
include $(CFGDIR)/../system.inc
-
 
22
 
-
 
23
ifndef AWK
-
 
24
	STOP! This is because you have not defined build-binaries in system.inc
-
 
25
	Please update system.inc.template from SVN and then copy the build binaries definitions to your system.inc
-
 
26
endif
21
 
27
 
22
# VPATH: setup search path for source files.
28
# VPATH: setup search path for source files.
23
vpath
29
vpath
24
vpath %.c $(SRCDIR):$(LIBDIR)
30
vpath %.c $(SRCDIR):$(LIBDIR)
25
vpath %.S $(SRCDIR):$(LIBDIR)
31
vpath %.S $(SRCDIR):$(LIBDIR)
Line 99... Line 105...
99
#             files -- see avr-libc docs [FIXME: not yet described there]
105
#             files -- see avr-libc docs [FIXME: not yet described there]
100
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
106
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
101
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp
107
ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp
102
ASFLAGS += -Wa,-g$(DEBUG)
108
ASFLAGS += -Wa,-g$(DEBUG)
103
 
109
 
104
 
110
 
105
#Additional libraries.
111
#Additional libraries.
106
 
112
 
107
# Minimalistic printf version
113
# Minimalistic printf version
108
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
114
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
109
 
115
 
110
# Floating point printf version (requires MATH_LIB = -lm below)
116
# Floating point printf version (requires MATH_LIB = -lm below)
111
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
117
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
112
 
118
 
113
PRINTF_LIB = 
119
PRINTF_LIB = 
114
 
120
 
115
# Minimalistic scanf version
121
# Minimalistic scanf version
116
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
122
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
117
 
123
 
118
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
124
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
119
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
125
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
120
 
126
 
121
SCANF_LIB = 
127
SCANF_LIB = 
122
 
128
 
123
MATH_LIB = -lm
129
MATH_LIB = -lm
124
 
130
 
125
# External memory options
131
# External memory options
126
 
132
 
127
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
133
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
128
# used for variables (.data/.bss) and heap (malloc()).
134
# used for variables (.data/.bss) and heap (malloc()).
129
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
135
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
Line 145... Line 151...
145
LDFLAGS += $(EXTMEMOPTS)
151
LDFLAGS += $(EXTMEMOPTS)
146
LDFLAGS += $(BIOSOPTS)
152
LDFLAGS += $(BIOSOPTS)
147
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
153
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
148
 
154
 
149
# ---------------------------------------------------------------------------
155
# ---------------------------------------------------------------------------
150
 
-
 
151
# Define programs and commands.
-
 
152
SHELL = sh
-
 
153
CC = avr-gcc
-
 
154
AWK = awk
-
 
155
OBJCOPY = avr-objcopy
-
 
156
OBJDUMP = avr-objdump
-
 
157
SIZE = avr-size
-
 
158
NM = avr-nm
-
 
159
RM = rm -f
-
 
160
CP = cp
-
 
161
MKDIR = mkdir
-
 
162
AR = avr-ar
-
 
163
UUIDGEN = uuidgen
-
 
164
# on BSD/MAC this should be MD5SUM = md5
-
 
165
MD5SUM = md5sum
-
 
166
CUT = cut
-
 
167
GREP = grep
-
 
168
 
-
 
169
 
156
 
170
# Define Messages
157
# Define Messages
171
# English
158
# English
172
MSG_ERRORS_NONE = Errors: none
159
MSG_ERRORS_NONE = Errors: none
173
MSG_BEGIN = -------- begin --------
160
MSG_BEGIN = -------- begin --------
Line 198... Line 185...
198
 
185
 
199
BUILDDIRS = $(sort $(filter-out ./,$(dir $(OBJ))))
186
BUILDDIRS = $(sort $(filter-out ./,$(dir $(OBJ))))
200
 
187
 
201
# Compiler flags to generate dependency files.
188
# Compiler flags to generate dependency files.
202
GENDEPFLAGS = -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"
189
GENDEPFLAGS = -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"
-
 
190
 
-
 
191
check_binaries:
-
 
192
ifndef AWK
-
 
193
	@echo 
-
 
194
	@echo ERROR! This is because you have not defined build-binaries in system.inc
-
 
195
	@echo Please update system.inc.template from SVN and then copy the build binaries definitions to your system.inc
-
 
196
	@echo 
-
 
197
	@false
-
 
198
endif
203
 
199
 
204
# Default target.
200
# Default target.
205
all: sizebefore buildtree build lib sizeafter
201
all: check_binaries sizebefore buildtree build lib sizeafter
206
 
202
 
207
build: elf hex eep lss sym
203
build: elf hex eep lss sym
208
 
204
 
209
elf: $(TARGET).elf
205
elf: $(TARGET).elf
210
hex: $(TARGET).hex
206
hex: $(TARGET).hex
Line 216... Line 212...
216
 
212
 
217
# Display size of file.
213
# Display size of file.
218
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
214
HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex
219
ELFSIZE = $(SIZE) $(TARGET).elf
215
ELFSIZE = $(SIZE) $(TARGET).elf
220
sizebefore:
216
sizebefore:
221
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
217
	@if [ -f $(TARGET).elf ]; then $(ECHO); $(ECHO) $(MSG_SIZE_BEFORE); $(ELFSIZE); $(ECHO); fi
222
 
218
 
223
sizeafter:
219
sizeafter:
224
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
220
	@if [ -f $(TARGET).elf ]; then $(ECHO); $(ECHO) $(MSG_SIZE_AFTER); $(ELFSIZE); $(ECHO); fi
225
 
221
 
226
# Generate config.h from bios.inc
222
# Generate config.h from bios.inc
227
HWID = `$(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8`
223
#HWID = `$(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8`
-
 
224
HWID := $(shell $(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8)
228
config.h: $(CFGDIR)/bios.inc
225
config.h: $(CFGDIR)/bios.inc
229
	@echo Generating $@
226
	@$(ECHO) Generating $@
230
	@cat $^ | $(AWK) -v apa=0x$(HWID) &apos;BEGIN {  } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END {  }' > $^
227
	@$(CAT) $^ | $(AWK) -v apa=0x$(HWID) &apos;BEGIN {  } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END {  }' > tmpfile
-
 
228
	@$(CAT) tmpfile > $^
-
 
229
	@$(RM) tmpfile
231
	@echo "/* This file is automatically generated. Do not edit. */" > $@
230
	@$(ECHO) "/* This file is automatically generated. Do not edit. */" > $@
232
	@echo "" >> $@
231
	@$(ECHO) "" >> $@
233
	@echo "#ifndef CONFIG_H_" >> $@
232
	@$(ECHO) "#ifndef CONFIG_H_" >> $@
234
	@echo "#define CONFIG_H_" >> $@
233
	@$(ECHO) "#define CONFIG_H_" >> $@
235
	@echo "" >> $@
234
	@$(ECHO) "" >> $@
236
	@cat $^ | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
235
	@$(CAT) $^ | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
237
	@echo "" >> $@
236
	@$(ECHO) "" >> $@
238
	@echo "#endif /*CONFIG_H_*/" >> $@
237
	@$(ECHO) "#endif /*CONFIG_H_*/" >> $@
239
 
238
 
240
# above echos does not use \n due to different handling on different os:es?
239
# above echos does not use \n due to different handling on different os:es?
-
 
240
#	@$(CAT) $^ | $(AWK) -v apa=0x$(HWID) 'BEGIN {  } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END {  }' > $^
241
 
241
 
242
#	@cat $^ | $(GREP) "<GENERATE_HW>" | $(AWK) -v apa=0x$(HWID) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,apa } END {  }' >> $@
242
#	@$(CAT) $^ | $(GREP) "<GENERATE_HW>" | $(AWK) -v apa=0x$(HWID) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,apa } END {  }' >> $@
243
#	@cat $^ | $(GREP) -v "<GENERATE_HW>" | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
243
#	@$(CAT) $^ | $(GREP) -v "<GENERATE_HW>" | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END {  }' >> $@
244
	
244
	
245
# Display compiler version information.
245
# Display compiler version information.
246
gccversion : 
246
gccversion : 
247
	@$(CC) --version
247
	@$(CC) --version
248
 
248
 
Line 253... Line 253...
253
--change-section-address .noinit-0x800000 \
253
--change-section-address .noinit-0x800000 \
254
--change-section-address .eeprom-0x810000 
254
--change-section-address .eeprom-0x810000 
255
 
255
 
256
 
256
 
257
coff: $(TARGET).elf
257
coff: $(TARGET).elf
258
	@echo $(MSG_COFF) $(TARGET).cof
258
	@$(ECHO) $(MSG_COFF) $(TARGET).cof
259
	@$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
259
	@$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
260
 
260
 
261
extcoff: $(TARGET).elf
261
extcoff: $(TARGET).elf
262
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
262
	@$(ECHO) $(MSG_EXTENDED_COFF) $(TARGET).cof
263
	@$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
263
	@$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
264
 
264
 
265
# Create final output files (.hex, .eep) from ELF output file.
265
# Create final output files (.hex, .eep) from ELF output file.
266
%.hex: %.elf
266
%.hex: %.elf
267
	@echo $(MSG_FLASH) $@
267
	@$(ECHO) $(MSG_FLASH) $@
268
	@$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
268
	@$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@
269
 
269
 
270
%.eep: %.elf
270
%.eep: %.elf
271
	@echo $(MSG_EEPROM) $@
271
	@$(ECHO) $(MSG_EEPROM) $@
272
	-@$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
272
	-@$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
273
	--change-section-lma .eeprom=0 -O ihex $< $@
273
	--change-section-lma .eeprom=0 -O ihex $< $@
274
 
274
 
275
# Create extended listing file from ELF output file.
275
# Create extended listing file from ELF output file.
276
%.lss: %.elf
276
%.lss: %.elf
277
	@echo $(MSG_EXTENDED_LISTING) $@
277
	@$(ECHO) $(MSG_EXTENDED_LISTING) $@
278
	@$(OBJDUMP) -h -S $< > $@
278
	@$(OBJDUMP) -h -S $< > $@
279
 
279
 
280
# Create a symbol table from ELF output file.
280
# Create a symbol table from ELF output file.
281
%.sym: %.elf
281
%.sym: %.elf
282
	@echo $(MSG_SYMBOL_TABLE) $@
282
	@$(ECHO) $(MSG_SYMBOL_TABLE) $@
283
	@$(NM) -n $< > $@
283
	@$(NM) -n $< > $@
284
 
284
 
285
# Link: create ELF output file from object files.
285
# Link: create ELF output file from object files.
286
.SECONDARY : $(TARGET).elf
286
.SECONDARY : $(TARGET).elf
287
#.PRECIOUS : $(OBJ)
287
#.PRECIOUS : $(OBJ)
288
$(TARGET)_pass1.elf: override BIOS_START=0x100
288
$(TARGET)_pass1.elf: override BIOS_START=0x100
289
$(TARGET)_pass1.elf: config.h $(OBJ)
289
$(TARGET)_pass1.elf: config.h $(OBJ)
290
	@echo Linking pass 1:
290
	@$(ECHO) Linking pass 1:
291
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
291
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
292
 
292
 
293
$(TARGET).elf: config.h $(OBJ) | $(TARGET)_pass1.elf
293
$(TARGET).elf: config.h $(OBJ) | $(TARGET)_pass1.elf
294
	@echo Linking pass 2: Optimizing flash usage
294
	@$(ECHO) Linking pass 2: Optimizing flash usage
295
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
295
	@$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
296
 
296
 
297
$(LIBNAME).S: $(TARGET).elf
297
$(LIBNAME).S: $(TARGET).elf
298
	@echo Generating $@
298
	@$(ECHO) Generating $@
299
	@$(AWK) '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(TARGET).map > $@
299
	@$(AWK) '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(TARGET).map > $@
300
 
300
 
301
bios.h: $(LIBDIR)/drivers/can/can.h $(LIBDIR)/bios/bios_export.h
301
bios.h: $(LIBDIR)/drivers/can/can.h $(LIBDIR)/bios/bios_export.h
302
	@echo Generating $@
302
	@$(ECHO) Generating $@
303
	@echo "/* This file is automatically generated. Do not edit. */" > $@
303
	@$(ECHO) "/* This file is automatically generated. Do not edit. */" > $@
304
	@echo "" >> $@
304
	@$(ECHO) "" >> $@
305
	@echo "#ifndef BIOS_H_" >> $@
305
	@$(ECHO) "#ifndef BIOS_H_" >> $@
306
	@echo "#define BIOS_H_" >> $@
306
	@$(ECHO) "#define BIOS_H_" >> $@
307
	@echo "" >> $@
307
	@$(ECHO) "" >> $@
308
	@cat $^ >> $@
308
	@$(CAT) $^ >> $@
309
	@echo "" >> $@
309
	@$(ECHO) "" >> $@
310
	@echo "#endif /*BIOS_H_*/" >> $@
310
	@$(ECHO) "#endif /*BIOS_H_*/" >> $@
311
 
311
 
312
lib: bios.h $(LIBNAME).a($(LIBNAME).o)
312
lib: bios.h $(LIBNAME).a($(LIBNAME).o)
313
 
313
 
314
# Compile: create object files from C source files.
314
# Compile: create object files from C source files.
315
%.o : %.c
315
%.o : %.c
316
	@echo $(MSG_COMPILING) $<
316
	@$(ECHO) $(MSG_COMPILING) $<
317
	@$(CC) -c $(CFLAGS) $< -o $@ 
317
	@$(CC) -c $(CFLAGS) $< -o $@ 
318
 
318
 
319
# Compile: create assembler files from C source files.
319
# Compile: create assembler files from C source files.
320
%.s : %.c
320
%.s : %.c
321
	@$(CC) -S $(CFLAGS) $< -o $@
321
	@$(CC) -S $(CFLAGS) $< -o $@
322
 
322
 
323
# Assemble: create object files from assembler source files.
323
# Assemble: create object files from assembler source files.
324
%.o : %.S
324
%.o : %.S
325
	@echo $(MSG_ASSEMBLING) $<
325
	@$(ECHO) $(MSG_ASSEMBLING) $<
326
	@$(CC) -c $(ASFLAGS) $< -o $@
326
	@$(CC) -c $(ASFLAGS) $< -o $@
327
 
327
 
328
# Depends: create dependency files from c source files.
328
# Depends: create dependency files from c source files.
329
#%.d : %.c | $(BUILDDIRS)
329
#%.d : %.c | $(BUILDDIRS)
330
#	@echo $(MSG_DEPEND) $<
330
#	@$(ECHO) $(MSG_DEPEND) $<
331
#	@$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $<
331
#	@$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $<
332
 
332
 
333
# Buildtree: create directories for output files.
333
# Buildtree: create directories for output files.
334
$(BUILDDIRS) :
334
$(BUILDDIRS) :
335
	@echo $(MSG_CREATE) $@
335
	@$(ECHO) $(MSG_CREATE) $@
336
	@$(MKDIR) -p $@
336
	@$(MKDIR) -p $@
337
 
337
 
338
# Target: clean project.
338
# Target: clean project.
339
clean: 
339
clean: 
340
	@echo $(MSG_CLEANING)
340
	@$(ECHO) $(MSG_CLEANING)
341
	$(RM) $(TARGET).eep
341
	$(RM) $(TARGET).eep
342
	$(RM) $(TARGET).cof
342
	$(RM) $(TARGET).cof
343
	$(RM) $(TARGET)_pass1.elf
343
	$(RM) $(TARGET)_pass1.elf
344
	$(RM) $(TARGET).elf
344
	$(RM) $(TARGET).elf
345
	$(RM) $(TARGET).sym
345
	$(RM) $(TARGET).sym
Line 359... Line 359...
359
endif
359
endif
360
 
360
 
361
# Listing of phony targets.
361
# Listing of phony targets.
362
.PHONY : all sizebefore sizeafter build \
362
.PHONY : all sizebefore sizeafter build \
363
elf hex eep lss sym coff extcoff clean \
363
elf hex eep lss sym coff extcoff clean \
364
gccversion lib
364
gccversion lib check_binaries
365
 
365