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