Subversion Repositories HomeAutomation

Rev

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

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