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