Rev 784 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 361 | andfri | 1 | # $Id: Makefile 784 2008-05-06 16:18:17Z arune $ |
| 769 | arune | 2 | BIOS_VERSION = 0x1339 |
| 361 | andfri | 3 | |
| 554 | andfri | 4 | # Paths: set default pathnames if they are not |
| 5 | # passed on from parent Makefile. |
||
| 6 | ifndef TARGET |
||
| 7 | TARGET = bios |
||
| 8 | endif |
||
| 9 | ifndef LIBDIR |
||
| 10 | LIBDIR = . |
||
| 11 | endif |
||
| 12 | ifndef SRCDIR |
||
| 13 | SRCDIR = bios |
||
| 14 | endif |
||
| 15 | ifndef CFGDIR |
||
| 16 | CFGDIR = .. |
||
| 17 | endif |
||
| 18 | LIBNAME = lib$(TARGET) |
||
| 361 | andfri | 19 | |
| 554 | andfri | 20 | include $(CFGDIR)/bios.inc |
| 361 | andfri | 21 | |
| 554 | andfri | 22 | # VPATH: setup search path for source files. |
| 23 | vpath |
||
| 24 | vpath %.c $(SRCDIR):$(LIBDIR) |
||
| 25 | vpath %.S $(SRCDIR):$(LIBDIR) |
||
| 26 | |||
| 27 | # List source files here. (C dependencies are automatically generated.) |
||
| 28 | SOURCES = vectors.S \ |
||
| 29 | bios_export.c \ |
||
| 30 | bios.c \ |
||
| 31 | flash.c |
||
| 32 | |||
| 361 | andfri | 33 | ifeq ($(CAN_CONTROLLER),MCP2515) |
| 554 | andfri | 34 | SOURCES += drivers/can/mcp2515/mcp2515.c |
| 361 | andfri | 35 | CAN_DRIVER_H = \<drivers/can/mcp2515/mcp2515.h\> |
| 36 | endif |
||
| 37 | |||
| 554 | andfri | 38 | # Start address for linking pass 1, will be overridden for optimizing pass |
| 39 | #BIOS_START = 0x100 |
||
| 361 | andfri | 40 | |
| 554 | andfri | 41 | # Optimization level, can be [0, 1, 2, 3, s]. |
| 42 | # 0 = turn off optimization. s = optimize for size. |
||
| 43 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
||
| 44 | OPT = s |
||
| 45 | #OPT = 3 |
||
| 361 | andfri | 46 | |
| 554 | andfri | 47 | # Debugging format. |
| 48 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. |
||
| 49 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. |
||
| 50 | DEBUG = stabs |
||
| 51 | #DEBUG = dwarf-2 |
||
| 361 | andfri | 52 | |
| 554 | andfri | 53 | # List any extra directories to look for include files here. |
| 54 | # Each directory must be separated by a space. |
||
| 55 | EXTRAINCDIRS = $(LIBDIR) $(SRCDIR) |
||
| 361 | andfri | 56 | |
| 554 | andfri | 57 | # Compiler flag to set the C Standard level. |
| 58 | # c89 - "ANSI" C |
||
| 59 | # gnu89 - c89 plus GCC extensions |
||
| 60 | # c99 - ISO C99 standard (not yet fully implemented) |
||
| 61 | # gnu99 - c99 plus GCC extensions |
||
| 62 | CSTANDARD = -std=gnu99 |
||
| 361 | andfri | 63 | |
| 554 | andfri | 64 | # Place -D or -U options here |
| 65 | CDEFS = -DF_CPU=$(F_CPU) \ |
||
| 66 | -DCAN_DRIVER_H=$(CAN_DRIVER_H) \ |
||
| 67 | -DBIOS_VERSION=$(BIOS_VERSION) |
||
| 361 | andfri | 68 | |
| 554 | andfri | 69 | # Place -I options here |
| 70 | CINCS = |
||
| 361 | andfri | 71 | |
| 72 | |||
| 554 | andfri | 73 | # Compiler flags. |
| 74 | # -g*: generate debugging information |
||
| 75 | # -O*: optimization level |
||
| 76 | # -f...: tuning, see GCC manual and avr-libc documentation |
||
| 77 | # -Wall...: warning level |
||
| 78 | # -Wa,...: tell GCC to pass this to the assembler. |
||
| 79 | # -adhlns...: create assembler listing |
||
| 80 | CFLAGS = -mmcu=$(MCU) -I. |
||
| 81 | CFLAGS += -g$(DEBUG) |
||
| 82 | CFLAGS += $(CDEFS) $(CINCS) |
||
| 83 | CFLAGS += -O$(OPT) |
||
| 84 | CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
||
| 85 | CFLAGS += -Wall -Wstrict-prototypes |
||
| 86 | CFLAGS += -Wa,-adhlns=$(@:.o=.lst) |
||
| 87 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
||
| 88 | CFLAGS += $(CSTANDARD) |
||
| 556 | andfri | 89 | CFLAGS += $(GENDEPFLAGS) |
| 361 | andfri | 90 | |
| 91 | |||
| 92 | |||
| 554 | andfri | 93 | # Assembler flags. |
| 94 | # -Wa,...: tell GCC to pass this to the assembler. |
||
| 95 | # -ahlms: create listing |
||
| 96 | # -gstabs: have the assembler create line number information; note that |
||
| 97 | # for use in COFF files, additional information about filenames |
||
| 98 | # and function names needs to be present in the assembler source |
||
| 99 | # files -- see avr-libc docs [FIXME: not yet described there] |
||
| 100 | ##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
||
| 101 | ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp |
||
| 102 | ASFLAGS += -Wa,-g$(DEBUG) |
||
| 438 | eqlazer | 103 | |
| 104 | |||
| 554 | andfri | 105 | #Additional libraries. |
| 437 | eqlazer | 106 | |
| 554 | andfri | 107 | # Minimalistic printf version |
| 108 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
||
| 438 | eqlazer | 109 | |
| 554 | andfri | 110 | # Floating point printf version (requires MATH_LIB = -lm below) |
| 111 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
||
| 469 | arune | 112 | |
| 554 | andfri | 113 | PRINTF_LIB = |
| 361 | andfri | 114 | |
| 554 | andfri | 115 | # Minimalistic scanf version |
| 116 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
||
| 361 | andfri | 117 | |
| 554 | andfri | 118 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
| 119 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
||
| 361 | andfri | 120 | |
| 554 | andfri | 121 | SCANF_LIB = |
| 550 | andfri | 122 | |
| 554 | andfri | 123 | MATH_LIB = -lm |
| 361 | andfri | 124 | |
| 554 | andfri | 125 | # External memory options |
| 361 | andfri | 126 | |
| 554 | andfri | 127 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
| 128 | # used for variables (.data/.bss) and heap (malloc()). |
||
| 129 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
||
| 361 | andfri | 130 | |
| 554 | andfri | 131 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
| 132 | # only used for heap (malloc()). |
||
| 133 | #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
||
| 361 | andfri | 134 | |
| 554 | andfri | 135 | EXTMEMOPTS = |
| 136 | |||
| 137 | BIOS_START = $(shell $(AWK) '/0x[0-9a-f]+.*__bios_optimal_start/ { print $$1 }' bios.map) |
||
| 138 | BIOSOPTS = -Wl,--defsym,__bios_start=$(BIOS_START),--defsym,__boot_start=$(BOOT_START),-T$(LIBDIR)/ldscripts/$(MCU).ld |
||
| 139 | |||
| 140 | # Linker flags. |
||
| 141 | # -Wl,...: tell GCC to pass this to linker. |
||
| 142 | # -Map: create map file |
||
| 143 | # --cref: add cross reference to map file |
||
| 560 | andfri | 144 | LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map,--cref |
| 554 | andfri | 145 | LDFLAGS += $(EXTMEMOPTS) |
| 146 | LDFLAGS += $(BIOSOPTS) |
||
| 147 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
||
| 148 | |||
| 149 | # --------------------------------------------------------------------------- |
||
| 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 |
||
| 621 | noddan | 162 | AR = avr-ar |
| 769 | arune | 163 | UUIDGEN = uuidgen |
| 784 | arune | 164 | # on BSD/MAC this should be MD5SUM = md5 |
| 769 | arune | 165 | MD5SUM = md5sum |
| 166 | CUT = cut |
||
| 167 | GREP = grep |
||
| 554 | andfri | 168 | |
| 169 | |||
| 170 | # Define Messages |
||
| 171 | # English |
||
| 172 | MSG_ERRORS_NONE = Errors: none |
||
| 173 | MSG_BEGIN = -------- begin -------- |
||
| 174 | MSG_END = -------- end -------- |
||
| 175 | MSG_SIZE_BEFORE = Size before: |
||
| 176 | MSG_SIZE_AFTER = Size after: |
||
| 177 | MSG_COFF = Converting to AVR COFF: |
||
| 178 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
||
| 179 | MSG_FLASH = Creating load file for Flash: |
||
| 180 | MSG_EEPROM = Creating load file for EEPROM: |
||
| 181 | MSG_EXTENDED_LISTING = Creating Extended Listing: |
||
| 182 | MSG_SYMBOL_TABLE = Creating Symbol Table: |
||
| 183 | MSG_LINKING = Linking: |
||
| 184 | MSG_COMPILING = Compiling: |
||
| 185 | MSG_ASSEMBLING = Assembling: |
||
| 186 | MSG_DEPEND = Generating dependencies: |
||
| 187 | MSG_CLEANING = Cleaning project: |
||
| 188 | MSG_CREATE = Creating: |
||
| 189 | |||
| 190 | # Define all object files. |
||
| 191 | OBJ = $(filter %.o,$(SOURCES:.c=.o) $(SOURCES:.S=.o)) |
||
| 192 | |||
| 193 | # Define all listing files. |
||
| 194 | LST = $(OBJ:.o=.lst) |
||
| 195 | |||
| 196 | # Define all dependency files. |
||
| 556 | andfri | 197 | DEP = $(OBJ:.o=.d) |
| 554 | andfri | 198 | |
| 199 | BUILDDIRS = $(sort $(filter-out ./,$(dir $(OBJ)))) |
||
| 200 | |||
| 201 | # Compiler flags to generate dependency files. |
||
| 556 | andfri | 202 | GENDEPFLAGS = -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" |
| 554 | andfri | 203 | |
| 204 | # Default target. |
||
| 556 | andfri | 205 | all: sizebefore buildtree build lib sizeafter |
| 554 | andfri | 206 | |
| 207 | build: elf hex eep lss sym |
||
| 208 | |||
| 209 | elf: $(TARGET).elf |
||
| 210 | hex: $(TARGET).hex |
||
| 211 | eep: $(TARGET).eep |
||
| 212 | lss: $(TARGET).lss |
||
| 213 | sym: $(TARGET).sym |
||
| 214 | |||
| 556 | andfri | 215 | buildtree: $(BUILDDIRS) |
| 216 | |||
| 554 | andfri | 217 | # Display size of file. |
| 218 | HEXSIZE = $(SIZE) --target=ihex $(TARGET).hex |
||
| 219 | ELFSIZE = $(SIZE) $(TARGET).elf |
||
| 220 | sizebefore: |
||
| 221 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi |
||
| 222 | |||
| 223 | sizeafter: |
||
| 224 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi |
||
| 225 | |||
| 226 | # Generate config.h from bios.inc |
||
| 769 | arune | 227 | HWID = `$(UUIDGEN) | $(MD5SUM) | $(CUT) -c 1-8` |
| 554 | andfri | 228 | config.h: $(CFGDIR)/bios.inc |
| 361 | andfri | 229 | @echo Generating $@ |
| 773 | arune | 230 | @cat $^ | $(AWK) -v apa=0x$(HWID) 'BEGIN { } /.*/ {sub(/^NODE_HW_ID=<GENERATE_HW>/,"NODE_HW_ID="apa)}{print} END { }' > $^ |
| 621 | noddan | 231 | @echo "/* This file is automatically generated. Do not edit. */" > $@ |
| 232 | @echo "" >> $@ |
||
| 783 | arune | 233 | @echo "#ifndef CONFIG_H_" >> $@ |
| 234 | @echo "#define CONFIG_H_" >> $@ |
||
| 235 | @echo "" >> $@ |
||
| 773 | arune | 236 | @cat $^ | $(AWK) 'BEGIN { FS="=" } /^[^#].*=.*/ { print "#define "$$1,$$2 } END { }' >> $@ |
| 783 | arune | 237 | @echo "" >> $@ |
| 238 | @echo "#endif /*CONFIG_H_*/" >> $@ |
||
| 773 | arune | 239 | |
| 783 | arune | 240 | # above echos does not use \n due to different handling on different os:es? |
| 773 | arune | 241 | |
| 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 { }' >> $@ |
||
| 769 | arune | 244 | |
| 554 | andfri | 245 | # Display compiler version information. |
| 246 | gccversion : |
||
| 247 | @$(CC) --version |
||
| 248 | |||
| 249 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
||
| 250 | COFFCONVERT=$(OBJCOPY) --debugging \ |
||
| 251 | --change-section-address .data-0x800000 \ |
||
| 252 | --change-section-address .bss-0x800000 \ |
||
| 253 | --change-section-address .noinit-0x800000 \ |
||
| 254 | --change-section-address .eeprom-0x810000 |
||
| 255 | |||
| 256 | |||
| 257 | coff: $(TARGET).elf |
||
| 258 | @echo $(MSG_COFF) $(TARGET).cof |
||
| 259 | @$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
||
| 260 | |||
| 261 | extcoff: $(TARGET).elf |
||
| 262 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
||
| 263 | @$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
||
| 264 | |||
| 265 | # Create final output files (.hex, .eep) from ELF output file. |
||
| 266 | %.hex: %.elf |
||
| 267 | @echo $(MSG_FLASH) $@ |
||
| 561 | andfri | 268 | @$(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@ |
| 554 | andfri | 269 | |
| 270 | %.eep: %.elf |
||
| 271 | @echo $(MSG_EEPROM) $@ |
||
| 272 | -@$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
||
| 273 | --change-section-lma .eeprom=0 -O ihex $< $@ |
||
| 274 | |||
| 275 | # Create extended listing file from ELF output file. |
||
| 276 | %.lss: %.elf |
||
| 277 | @echo $(MSG_EXTENDED_LISTING) $@ |
||
| 278 | @$(OBJDUMP) -h -S $< > $@ |
||
| 279 | |||
| 280 | # Create a symbol table from ELF output file. |
||
| 281 | %.sym: %.elf |
||
| 282 | @echo $(MSG_SYMBOL_TABLE) $@ |
||
| 283 | @$(NM) -n $< > $@ |
||
| 284 | |||
| 285 | # Link: create ELF output file from object files. |
||
| 286 | .SECONDARY : $(TARGET).elf |
||
| 287 | #.PRECIOUS : $(OBJ) |
||
| 288 | $(TARGET)_pass1.elf: override BIOS_START=0x100 |
||
| 289 | $(TARGET)_pass1.elf: config.h $(OBJ) |
||
| 290 | @echo Linking pass 1: |
||
| 291 | @$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS) |
||
| 292 | |||
| 293 | $(TARGET).elf: config.h $(OBJ) | $(TARGET)_pass1.elf |
||
| 294 | @echo Linking pass 2: Optimizing flash usage |
||
| 295 | @$(CC) $(LDFLAGS) -o $@ $(filter %.o,$^) $(LIBS) |
||
| 296 | |||
| 297 | $(LIBNAME).S: $(TARGET).elf |
||
| 361 | andfri | 298 | @echo Generating $@ |
| 554 | andfri | 299 | @$(AWK) '$$1 ~ /0x[0-9a-f]+/ && /BIOS_/ { print "\t.set "$$2","$$1"\n\t.global "$$2 }' $(TARGET).map > $@ |
| 361 | andfri | 300 | |
| 554 | andfri | 301 | bios.h: $(LIBDIR)/drivers/can/can.h $(LIBDIR)/bios/bios_export.h |
| 361 | andfri | 302 | @echo Generating $@ |
| 621 | noddan | 303 | @echo "/* This file is automatically generated. Do not edit. */" > $@ |
| 304 | @echo "" >> $@ |
||
| 305 | @echo "#ifndef BIOS_H_" >> $@ |
||
| 306 | @echo "#define BIOS_H_" >> $@ |
||
| 307 | @echo "" >> $@ |
||
| 361 | andfri | 308 | @cat $^ >> $@ |
| 621 | noddan | 309 | @echo "" >> $@ |
| 310 | @echo "#endif /*BIOS_H_*/" >> $@ |
||
| 361 | andfri | 311 | |
| 554 | andfri | 312 | lib: bios.h $(LIBNAME).a($(LIBNAME).o) |
| 361 | andfri | 313 | |
| 554 | andfri | 314 | # Compile: create object files from C source files. |
| 315 | %.o : %.c |
||
| 316 | @echo $(MSG_COMPILING) $< |
||
| 317 | @$(CC) -c $(CFLAGS) $< -o $@ |
||
| 361 | andfri | 318 | |
| 554 | andfri | 319 | # Compile: create assembler files from C source files. |
| 320 | %.s : %.c |
||
| 321 | @$(CC) -S $(CFLAGS) $< -o $@ |
||
| 361 | andfri | 322 | |
| 554 | andfri | 323 | # Assemble: create object files from assembler source files. |
| 324 | %.o : %.S |
||
| 325 | @echo $(MSG_ASSEMBLING) $< |
||
| 326 | @$(CC) -c $(ASFLAGS) $< -o $@ |
||
| 361 | andfri | 327 | |
| 554 | andfri | 328 | # Depends: create dependency files from c source files. |
| 556 | andfri | 329 | #%.d : %.c | $(BUILDDIRS) |
| 330 | # @echo $(MSG_DEPEND) $< |
||
| 331 | # @$(CC) -c $(CFLAGS) $(GENDEPFLAGS) $< |
||
| 361 | andfri | 332 | |
| 554 | andfri | 333 | # Buildtree: create directories for output files. |
| 334 | $(BUILDDIRS) : |
||
| 335 | @echo $(MSG_CREATE) $@ |
||
| 336 | @$(MKDIR) -p $@ |
||
| 361 | andfri | 337 | |
| 554 | andfri | 338 | # Target: clean project. |
| 339 | clean: |
||
| 340 | @echo $(MSG_CLEANING) |
||
| 341 | $(RM) $(TARGET).eep |
||
| 342 | $(RM) $(TARGET).cof |
||
| 343 | $(RM) $(TARGET)_pass1.elf |
||
| 344 | $(RM) $(TARGET).elf |
||
| 345 | $(RM) $(TARGET).sym |
||
| 346 | $(RM) $(TARGET).lss |
||
| 347 | $(RM) $(OBJ) |
||
| 348 | $(RM) $(DEP) |
||
| 349 | $(RM) $(LST) |
||
| 350 | $(RM) $(LIBNAME).S |
||
| 351 | $(RM) config.h |
||
| 352 | $(RM) -r drivers |
||
| 361 | andfri | 353 | |
| 554 | andfri | 354 | # Include the dependency files. |
| 556 | andfri | 355 | ifneq ($(MAKECMDGOALS),clean) |
| 356 | ifneq ($(strip $(DEP)),) |
||
| 554 | andfri | 357 | -include $(DEP) |
| 556 | andfri | 358 | endif |
| 359 | endif |
||
| 362 | andfri | 360 | |
| 554 | andfri | 361 | # Listing of phony targets. |
| 362 | .PHONY : all sizebefore sizeafter build \ |
||
| 363 | elf hex eep lss sym coff extcoff clean \ |
||
| 364 | gccversion lib |
||
| 361 | andfri | 365 |