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