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