Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 63 | jimmy | 1 | # Hey Emacs, this is a -*- makefile -*- |
| 2 | # |
||
| 3 | # WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al. |
||
| 4 | # Released to the Public Domain |
||
| 5 | # Please read the make user manual! |
||
| 6 | # |
||
| 7 | # Additional material for this makefile was submitted by: |
||
| 8 | # Tim Henigan |
||
| 9 | # Peter Fleury |
||
| 10 | # Reiner Patommel |
||
| 11 | # Sander Pool |
||
| 12 | # Frederik Rouleau |
||
| 13 | # Markus Pfaff |
||
| 14 | # |
||
| 15 | # On command line: |
||
| 16 | # |
||
| 17 | # make all = Make software. |
||
| 18 | # |
||
| 19 | # make clean = Clean out built project files. |
||
| 20 | # |
||
| 21 | # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB). |
||
| 22 | # |
||
| 23 | # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio |
||
| 24 | # 4.07 or greater). |
||
| 25 | # |
||
| 26 | # make program = Download the hex file to the device, using avrdude. Please |
||
| 27 | # customize the avrdude settings below first! |
||
| 28 | # |
||
| 29 | # make filename.s = Just compile filename.c into the assembler code only |
||
| 30 | # |
||
| 31 | # To rebuild project do "make clean" then "make all". |
||
| 32 | # |
||
| 33 | |||
| 34 | ######## |
||
| 35 | # Differences from WinAVR 20040720 sample: |
||
| 36 | # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum) |
||
| 37 | # - F_OSC Define in CFLAGS and AFLAGS |
||
| 38 | |||
| 39 | |||
| 40 | # MCU name |
||
| 41 | #MCU = atmega32 |
||
| 42 | MCU = atmega8 |
||
| 43 | #MCU = atmega16 |
||
| 44 | |||
| 45 | |||
| 46 | # Main Oscillator Frequency |
||
| 47 | ##F_OSC = 1000000 |
||
| 48 | ##F_OSC = 1843200 |
||
| 49 | ##F_OSC = 2000000 |
||
| 50 | ##F_OSC = 3686400 |
||
| 51 | ##F_OSC = 4000000 |
||
| 52 | ##F_OSC = 8000000 |
||
| 53 | F_OSC = 11059200 |
||
| 54 | ##F_OSC = 16000000 |
||
| 55 | |||
| 56 | # Output format. (can be srec, ihex, binary) |
||
| 57 | FORMAT = ihex |
||
| 58 | |||
| 59 | |||
| 60 | # Target file name (without extension). |
||
| 61 | TARGET = main |
||
| 62 | |||
| 63 | LIBDIR = ../lib/src/ |
||
| 64 | |||
| 65 | |||
| 66 | # List C source files here. (C dependencies are automatically generated.) |
||
| 67 | SRC = $(TARGET).c\ |
||
| 68 | $(LIBDIR)mcu/uart.c\ |
||
| 69 | $(LIBDIR)mcu/timebase.c\ |
||
| 70 | $(LIBDIR)can/can.c\ |
||
| 71 | $(LIBDIR)can/mcp2515/mcp2515.c |
||
| 72 | |||
| 73 | # List Assembler source files here. |
||
| 74 | # Make them always end in a capital .S. Files ending in a lowercase .s |
||
| 75 | # will not be considered source files but generated files (assembler |
||
| 76 | # output from the compiler), and will be deleted upon "make clean"! |
||
| 77 | # Even though the DOS/Win* filesystem matches both .s and .S the same, |
||
| 78 | # it will preserve the spelling of the filenames, and gcc itself does |
||
| 79 | # care about how the name is spelled on its command-line. |
||
| 80 | ASRC = |
||
| 81 | |||
| 82 | |||
| 83 | # Optimization level, can be [0, 1, 2, 3, s]. |
||
| 84 | # 0 = turn off optimization. s = optimize for size. |
||
| 85 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
||
| 86 | OPT = s |
||
| 87 | #OPT = 3 |
||
| 88 | |||
| 89 | # Debugging format. |
||
| 90 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. |
||
| 91 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. |
||
| 92 | #DEBUG = stabs |
||
| 93 | DEBUG = dwarf-2 |
||
| 94 | |||
| 95 | # List any extra directories to look for include files here. |
||
| 96 | # Each directory must be seperated by a space. |
||
| 97 | EXTRAINCDIRS = $(LIBDIR)/can $(LIBDIR)/can/mcp2515 $(LIBDIR)/mcu |
||
| 98 | |||
| 99 | # Compiler flag to set the C Standard level. |
||
| 100 | # c89 - "ANSI" C |
||
| 101 | # gnu89 - c89 plus GCC extensions |
||
| 102 | # c99 - ISO C99 standard (not yet fully implemented) |
||
| 103 | # gnu99 - c99 plus GCC extensions |
||
| 104 | CSTANDARD = -std=gnu99 |
||
| 105 | |||
| 106 | # Place -D or -U options here |
||
| 107 | CDEFS = |
||
| 108 | |||
| 109 | # Place -I options here |
||
| 110 | CINCS = |
||
| 111 | |||
| 112 | |||
| 113 | # Compiler flags. |
||
| 114 | # -g*: generate debugging information |
||
| 115 | # -O*: optimization level |
||
| 116 | # -f...: tuning, see GCC manual and avr-libc documentation |
||
| 117 | # -Wall...: warning level |
||
| 118 | # -Wa,...: tell GCC to pass this to the assembler. |
||
| 119 | # -adhlns...: create assembler listing |
||
| 120 | CFLAGS = -g$(DEBUG) |
||
| 121 | CFLAGS += $(CDEFS) $(CINCS) |
||
| 122 | CFLAGS += -O$(OPT) |
||
| 123 | CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
||
| 124 | CFLAGS += -Wall -Wstrict-prototypes |
||
| 125 | CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
||
| 126 | CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
||
| 127 | CFLAGS += $(CSTANDARD) |
||
| 128 | CFLAGS += -DF_OSC=$(F_OSC) |
||
| 129 | |||
| 130 | |||
| 131 | |||
| 132 | # Assembler flags. |
||
| 133 | # -Wa,...: tell GCC to pass this to the assembler. |
||
| 134 | # -ahlms: create listing |
||
| 135 | # -gstabs: have the assembler create line number information; note that |
||
| 136 | # for use in COFF files, additional information about filenames |
||
| 137 | # and function names needs to be present in the assembler source |
||
| 138 | # files -- see avr-libc docs [FIXME: not yet described there] |
||
| 139 | ##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
||
| 140 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG) |
||
| 141 | ASFLAGS += -DF_OSC=$(F_OSC) |
||
| 142 | |||
| 143 | |||
| 144 | #Additional libraries. |
||
| 145 | |||
| 146 | # Minimalistic printf version |
||
| 147 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
||
| 148 | |||
| 149 | # Floating point printf version (requires MATH_LIB = -lm below) |
||
| 150 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
||
| 151 | |||
| 152 | PRINTF_LIB = |
||
| 153 | |||
| 154 | # Minimalistic scanf version |
||
| 155 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
||
| 156 | |||
| 157 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
||
| 158 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
||
| 159 | |||
| 160 | SCANF_LIB = |
||
| 161 | |||
| 162 | MATH_LIB = -lm |
||
| 163 | |||
| 164 | # External memory options |
||
| 165 | |||
| 166 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
||
| 167 | # used for variables (.data/.bss) and heap (malloc()). |
||
| 168 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
||
| 169 | |||
| 170 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
||
| 171 | # only used for heap (malloc()). |
||
| 172 | #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
||
| 173 | |||
| 174 | EXTMEMOPTS = |
||
| 175 | |||
| 176 | # Linker flags. |
||
| 177 | # -Wl,...: tell GCC to pass this to linker. |
||
| 178 | # -Map: create map file |
||
| 179 | # --cref: add cross reference to map file |
||
| 180 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
||
| 181 | LDFLAGS += $(EXTMEMOPTS) |
||
| 182 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | # Programming support using avrdude. Settings and variables. |
||
| 188 | |||
| 189 | # Programming hardware: alf avr910 avrisp bascom bsd |
||
| 190 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
||
| 191 | # |
||
| 192 | # Type: avrdude -c ? |
||
| 193 | # to get a full listing. |
||
| 194 | # |
||
| 195 | AVRDUDE_PROGRAMMER = avrispv2 |
||
| 196 | |||
| 197 | # com1 = serial port. Use lpt1 to connect to parallel port. |
||
| 198 | AVRDUDE_PORT = com1 # programmer connected to serial device |
||
| 199 | AVRDUDE_BAUD = 115200 |
||
| 200 | |||
| 201 | AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex |
||
| 202 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
||
| 203 | |||
| 204 | |||
| 205 | # Uncomment the following if you want avrdude's erase cycle counter. |
||
| 206 | # Note that this counter needs to be initialized first using -Yn, |
||
| 207 | # see avrdude manual. |
||
| 208 | #AVRDUDE_ERASE_COUNTER = -y |
||
| 209 | |||
| 210 | # Uncomment the following if you do /not/ wish a verification to be |
||
| 211 | # performed after programming the device. |
||
| 212 | #AVRDUDE_NO_VERIFY = -V |
||
| 213 | |||
| 214 | # Increase verbosity level. Please use this when submitting bug |
||
| 215 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
||
| 216 | # to submit bug reports. |
||
| 217 | #AVRDUDE_VERBOSE = -v -v |
||
| 218 | |||
| 219 | AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD) |
||
| 220 | AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
||
| 221 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
||
| 222 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | # --------------------------------------------------------------------------- |
||
| 227 | |||
| 228 | # Define directories, if needed. |
||
| 229 | DIRAVR = c:/progra~1/winavr |
||
| 230 | DIRAVRBIN = $(DIRAVR)/bin |
||
| 231 | DIRAVRUTILS = $(DIRAVR)/utils/bin |
||
| 232 | DIRINC = . |
||
| 233 | DIRLIB = $(DIRAVR)/avr/lib |
||
| 234 | |||
| 235 | |||
| 236 | # Define programs and commands. |
||
| 237 | SHELL = sh |
||
| 238 | CC = avr-gcc |
||
| 239 | OBJCOPY = avr-objcopy |
||
| 240 | OBJDUMP = avr-objdump |
||
| 241 | SIZE = avr-size |
||
| 242 | NM = avr-nm |
||
| 243 | AVRDUDE = avrdude |
||
| 244 | REMOVE = rm -f |
||
| 245 | COPY = cp |
||
| 246 | |||
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | # Define Messages |
||
| 251 | # English |
||
| 252 | MSG_ERRORS_NONE = Errors: none |
||
| 253 | MSG_BEGIN = -------- begin -------- |
||
| 254 | MSG_END = -------- end -------- |
||
| 255 | MSG_SIZE_BEFORE = Size before: |
||
| 256 | MSG_SIZE_AFTER = Size after: |
||
| 257 | MSG_COFF = Converting to AVR COFF: |
||
| 258 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
||
| 259 | MSG_FLASH = Creating load file for Flash: |
||
| 260 | MSG_EEPROM = Creating load file for EEPROM: |
||
| 261 | MSG_EXTENDED_LISTING = Creating Extended Listing: |
||
| 262 | MSG_SYMBOL_TABLE = Creating Symbol Table: |
||
| 263 | MSG_LINKING = Linking: |
||
| 264 | MSG_COMPILING = Compiling: |
||
| 265 | MSG_ASSEMBLING = Assembling: |
||
| 266 | MSG_CLEANING = Cleaning project: |
||
| 267 | |||
| 268 | |||
| 269 | |||
| 270 | |||
| 271 | # Define all object files. |
||
| 272 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
||
| 273 | |||
| 274 | # Define all listing files. |
||
| 275 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) |
||
| 276 | |||
| 277 | |||
| 278 | # Compiler flags to generate dependency files. |
||
| 279 | ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d |
||
| 280 | GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
||
| 281 | |||
| 282 | # Combine all necessary flags and optional flags. |
||
| 283 | # Add target processor to flags. |
||
| 284 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
||
| 285 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | |||
| 291 | # Default target. |
||
| 292 | all: begin gccversion sizebefore build sizeafter finished end |
||
| 293 | |||
| 294 | build: elf hex eep lss sym |
||
| 295 | |||
| 296 | elf: $(TARGET).elf |
||
| 297 | hex: $(TARGET).hex |
||
| 298 | eep: $(TARGET).eep |
||
| 299 | lss: $(TARGET).lss |
||
| 300 | sym: $(TARGET).sym |
||
| 301 | |||
| 302 | |||
| 303 | |||
| 304 | # Eye candy. |
||
| 305 | # AVR Studio 3.x does not check make's exit code but relies on |
||
| 306 | # the following magic strings to be generated by the compile job. |
||
| 307 | begin: |
||
| 308 | @echo |
||
| 309 | @echo $(MSG_BEGIN) |
||
| 310 | |||
| 311 | finished: |
||
| 312 | @echo $(MSG_ERRORS_NONE) |
||
| 313 | |||
| 314 | end: |
||
| 315 | @echo $(MSG_END) |
||
| 316 | @echo |
||
| 317 | |||
| 318 | |||
| 319 | # Display size of file. |
||
| 320 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
||
| 321 | ELFSIZE = $(SIZE) -A $(TARGET).elf |
||
| 322 | sizebefore: |
||
| 323 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi |
||
| 324 | |||
| 325 | sizeafter: |
||
| 326 | @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi |
||
| 327 | |||
| 328 | |||
| 329 | |||
| 330 | # Display compiler version information. |
||
| 331 | gccversion : |
||
| 332 | @$(CC) --version |
||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | # Program the device. |
||
| 337 | program: $(TARGET).hex $(TARGET).eep |
||
| 338 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
||
| 339 | |||
| 340 | #programlock: |
||
| 341 | # $(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m |
||
| 342 | |||
| 343 | #programinit: |
||
| 344 | # $(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m |
||
| 345 | |||
| 346 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
||
| 347 | COFFCONVERT=$(OBJCOPY) --debugging \ |
||
| 348 | --change-section-address .data-0x800000 \ |
||
| 349 | --change-section-address .bss-0x800000 \ |
||
| 350 | --change-section-address .noinit-0x800000 \ |
||
| 351 | --change-section-address .eeprom-0x810000 |
||
| 352 | |||
| 353 | |||
| 354 | coff: $(TARGET).elf |
||
| 355 | @echo |
||
| 356 | @echo $(MSG_COFF) $(TARGET).cof |
||
| 357 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
||
| 358 | |||
| 359 | |||
| 360 | extcoff: $(TARGET).elf |
||
| 361 | @echo |
||
| 362 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
||
| 363 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
||
| 364 | |||
| 365 | |||
| 366 | |||
| 367 | # Create final output files (.hex, .eep) from ELF output file. |
||
| 368 | %.hex: %.elf |
||
| 369 | @echo |
||
| 370 | @echo $(MSG_FLASH) $@ |
||
| 371 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
||
| 372 | |||
| 373 | %.eep: %.elf |
||
| 374 | @echo |
||
| 375 | @echo $(MSG_EEPROM) $@ |
||
| 376 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
||
| 377 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
||
| 378 | |||
| 379 | # Create extended listing file from ELF output file. |
||
| 380 | %.lss: %.elf |
||
| 381 | @echo |
||
| 382 | @echo $(MSG_EXTENDED_LISTING) $@ |
||
| 383 | $(OBJDUMP) -h -S $< > $@ |
||
| 384 | |||
| 385 | # Create a symbol table from ELF output file. |
||
| 386 | %.sym: %.elf |
||
| 387 | @echo |
||
| 388 | @echo $(MSG_SYMBOL_TABLE) $@ |
||
| 389 | $(NM) -n $< > $@ |
||
| 390 | |||
| 391 | |||
| 392 | |||
| 393 | # Link: create ELF output file from object files. |
||
| 394 | .SECONDARY : $(TARGET).elf |
||
| 395 | .PRECIOUS : $(OBJ) |
||
| 396 | %.elf: $(OBJ) |
||
| 397 | @echo |
||
| 398 | @echo $(MSG_LINKING) $@ |
||
| 399 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) |
||
| 400 | |||
| 401 | |||
| 402 | # Compile: create object files from C source files. |
||
| 403 | %.o : %.c |
||
| 404 | @echo |
||
| 405 | @echo $(MSG_COMPILING) $< |
||
| 406 | $(CC) -c $(ALL_CFLAGS) $< -o $@ |
||
| 407 | |||
| 408 | |||
| 409 | # Compile: create assembler files from C source files. |
||
| 410 | %.s : %.c |
||
| 411 | $(CC) -S $(ALL_CFLAGS) $< -o $@ |
||
| 412 | |||
| 413 | |||
| 414 | # Assemble: create object files from assembler source files. |
||
| 415 | %.o : %.S |
||
| 416 | @echo |
||
| 417 | @echo $(MSG_ASSEMBLING) $< |
||
| 418 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
||
| 419 | |||
| 420 | |||
| 421 | |||
| 422 | # Target: clean project. |
||
| 423 | clean: begin clean_list finished end |
||
| 424 | |||
| 425 | clean_list : |
||
| 426 | @echo |
||
| 427 | @echo $(MSG_CLEANING) |
||
| 428 | $(REMOVE) $(TARGET).hex |
||
| 429 | $(REMOVE) $(TARGET).eep |
||
| 430 | $(REMOVE) $(TARGET).obj |
||
| 431 | $(REMOVE) $(TARGET).cof |
||
| 432 | $(REMOVE) $(TARGET).elf |
||
| 433 | $(REMOVE) $(TARGET).map |
||
| 434 | $(REMOVE) $(TARGET).obj |
||
| 435 | $(REMOVE) $(TARGET).a90 |
||
| 436 | $(REMOVE) $(TARGET).sym |
||
| 437 | $(REMOVE) $(TARGET).lnk |
||
| 438 | $(REMOVE) $(TARGET).lss |
||
| 439 | $(REMOVE) $(OBJ) |
||
| 440 | $(REMOVE) $(LST) |
||
| 441 | $(REMOVE) $(SRC:.c=.s) |
||
| 442 | $(REMOVE) $(SRC:.c=.d) |
||
| 443 | $(REMOVE) .dep/* |
||
| 444 | |||
| 445 | |||
| 446 | |||
| 447 | # Include the dependency files. |
||
| 448 | -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
||
| 449 | |||
| 450 | |||
| 451 | # Listing of phony targets. |
||
| 452 | .PHONY : all begin finish end sizebefore sizeafter gccversion \ |
||
| 453 | build elf hex eep lss sym coff extcoff \ |
||
| 454 | clean clean_list program programlock programinit |
||
| 455 |