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