1 # Hey Emacs, this is a -*- makefile -*-
\r
2 #----------------------------------------------------------------------------
\r
3 # WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
\r
5 # Released to the Public Domain
\r
7 # Additional material for this makefile was written by:
\r
17 #----------------------------------------------------------------------------
\r
20 # make all = Make software.
\r
22 # make clean = Clean out built project files.
\r
24 # make coff = Convert ELF to AVR COFF.
\r
26 # make extcoff = Convert ELF to AVR Extended COFF.
\r
28 # make program = Download the hex file to the device, using avrdude.
\r
29 # Please customize the avrdude settings below first!
\r
31 # make debug = Start either simulavr or avarice as specified for debugging,
\r
32 # with avr-gdb or avr-insight as the front end for debugging.
\r
34 # make filename.s = Just compile filename.c into the assembler code only.
\r
36 # make filename.i = Create a preprocessed source file for use in submitting
\r
37 # bug reports to the GCC project.
\r
39 # To rebuild project do "make clean" then "make all".
\r
40 #----------------------------------------------------------------------------
\r
47 # Processor frequency.
\r
48 # This will define a symbol, F_CPU, in all source code files equal to the
\r
49 # processor frequency. You can then use this symbol in your source code to
\r
50 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
\r
51 # automatically to create a 32-bit value in your source code.
\r
52 # Typical values are:
\r
68 # Output format. (can be srec, ihex, binary)
\r
72 # Target file name (without extension).
\r
76 # Object files directory
\r
77 # To put object files in current directory, use a dot (.), do NOT make
\r
78 # this an empty or blank macro!
\r
81 # List C source files here. (C dependencies are automatically generated.)
\r
82 SRC = main.c adc.c commands.c dac.c LCD_Driver.c LCD_functions.c parser.c printf.c timer.c usart.c
\r
84 # List C++ source files here. (C dependencies are automatically generated.)
\r
88 # List Assembler source files here.
\r
89 # Make them always end in a capital .S. Files ending in a lowercase .s
\r
90 # will not be considered source files but generated files (assembler
\r
91 # output from the compiler), and will be deleted upon "make clean"!
\r
92 # Even though the DOS/Win* filesystem matches both .s and .S the same,
\r
93 # it will preserve the spelling of the filenames, and gcc itself does
\r
94 # care about how the name is spelled on its command-line.
\r
98 # Optimization level, can be [0, 1, 2, 3, s].
\r
99 # 0 = turn off optimization. s = optimize for size.
\r
100 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
\r
104 # Debugging format.
\r
105 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
\r
106 # AVR Studio 4.10 requires dwarf-2.
\r
107 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
\r
111 # List any extra directories to look for include files here.
\r
112 # Each directory must be seperated by a space.
\r
113 # Use forward slashes for directory separators.
\r
114 # For a directory that has spaces, enclose it in quotes.
\r
118 # Compiler flag to set the C Standard level.
\r
120 # gnu89 = c89 plus GCC extensions
\r
121 # c99 = ISO C99 standard (not yet fully implemented)
\r
122 # gnu99 = c99 plus GCC extensions
\r
123 CSTANDARD = -std=gnu99
\r
126 # Place -D or -U options here for C sources
\r
127 CDEFS = -DF_CPU=$(F_CPU)UL
\r
130 # Place -D or -U options here for C++ sources
\r
131 CPPDEFS = -DF_CPU=$(F_CPU)UL
\r
132 #CPPDEFS += -D__STDC_LIMIT_MACROS
\r
133 #CPPDEFS += -D__STDC_CONSTANT_MACROS
\r
137 #---------------- Compiler Options C ----------------
\r
138 # -g*: generate debugging information
\r
139 # -O*: optimization level
\r
140 # -f...: tuning, see GCC manual and avr-libc documentation
\r
141 # -Wall...: warning level
\r
142 # -Wa,...: tell GCC to pass this to the assembler.
\r
143 # -adhlns...: create assembler listing
\r
144 CFLAGS = -g$(DEBUG)
\r
147 CFLAGS += -funsigned-char
\r
148 CFLAGS += -funsigned-bitfields
\r
149 CFLAGS += -fpack-struct
\r
150 CFLAGS += -fshort-enums
\r
151 CFLAGS += -fno-inline-small-functions
\r
152 CFLAGS += -fno-split-wide-types
\r
153 CFLAGS += -fno-tree-scev-cprop
\r
154 CFLAGS += -ffunction-sections
\r
155 CFLAGS += -fdata-sections
\r
157 CFLAGS += -Wstrict-prototypes
\r
158 #CFLAGS += -mshort-calls
\r
159 #CFLAGS += -fno-unit-at-a-time
\r
161 #CFLAGS += -Wunreachable-code
\r
162 #CFLAGS += -Wsign-compare
\r
163 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
\r
164 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
\r
165 CFLAGS += $(CSTANDARD)
\r
168 #---------------- Compiler Options C++ ----------------
\r
169 # -g*: generate debugging information
\r
170 # -O*: optimization level
\r
171 # -f...: tuning, see GCC manual and avr-libc documentation
\r
172 # -Wall...: warning level
\r
173 # -Wa,...: tell GCC to pass this to the assembler.
\r
174 # -adhlns...: create assembler listing
\r
175 CPPFLAGS = -g$(DEBUG)
\r
176 CPPFLAGS += $(CPPDEFS)
\r
177 CPPFLAGS += -O$(OPT)
\r
178 CPPFLAGS += -funsigned-char
\r
179 CPPFLAGS += -funsigned-bitfields
\r
180 CPPFLAGS += -fpack-struct
\r
181 CPPFLAGS += -fshort-enums
\r
182 CPPFLAGS += -fno-exceptions
\r
185 #CPPFLAGS += -mshort-calls
\r
186 #CPPFLAGS += -fno-unit-at-a-time
\r
187 #CPPFLAGS += -Wstrict-prototypes
\r
188 #CPPFLAGS += -Wunreachable-code
\r
189 #CPPFLAGS += -Wsign-compare
\r
190 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
\r
191 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
\r
192 #CPPFLAGS += $(CSTANDARD)
\r
195 #---------------- Assembler Options ----------------
\r
196 # -Wa,...: tell GCC to pass this to the assembler.
\r
197 # -ahlms: create listing
\r
198 # -gstabs: have the assembler create line number information; note that
\r
199 # for use in COFF files, additional information about filenames
\r
200 # and function names needs to be present in the assembler source
\r
201 # files -- see avr-libc docs [FIXME: not yet described there]
\r
202 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
\r
203 # dump that will be displayed for a given single line of source input.
\r
204 ASFLAGS = -Wa,-adhlns=$(<:.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
\r
207 #---------------- Library Options ----------------
\r
208 # Minimalistic printf version
\r
209 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
\r
211 # Floating point printf version (requires MATH_LIB = -lm below)
\r
212 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
\r
214 # If this is left blank, then it will use the Standard printf version.
\r
216 #PRINTF_LIB = $(PRINTF_LIB_MIN)
\r
217 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
\r
220 # Minimalistic scanf version
\r
221 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
\r
223 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
\r
224 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
\r
226 # If this is left blank, then it will use the Standard scanf version.
\r
228 #SCANF_LIB = $(SCANF_LIB_MIN)
\r
229 #SCANF_LIB = $(SCANF_LIB_FLOAT)
\r
235 # List any extra directories to look for libraries here.
\r
236 # Each directory must be seperated by a space.
\r
237 # Use forward slashes for directory separators.
\r
238 # For a directory that has spaces, enclose it in quotes.
\r
243 #---------------- External Memory Options ----------------
\r
245 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
\r
246 # used for variables (.data/.bss) and heap (malloc()).
\r
247 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
\r
249 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
\r
250 # only used for heap (malloc()).
\r
251 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
\r
257 #---------------- Linker Options ----------------
\r
258 # -Wl,...: tell GCC to pass this to linker.
\r
259 # -Map: create map file
\r
260 # --cref: add cross reference to map file
\r
261 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
\r
262 LDFLAGS += -Wl,--relax
\r
263 LDFLAGS += -Wl,--gc-sections
\r
264 LDFLAGS += $(EXTMEMOPTS)
\r
265 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
\r
266 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
\r
267 #LDFLAGS += -T linker_script.x
\r
271 #---------------- Programming Options (avrdude) ----------------
\r
273 # Programming hardware: alf avr910 avrisp bascom bsd
\r
274 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
\r
276 # Type: avrdude -c ?
\r
277 # to get a full listing.
\r
279 # AVRDUDE_PROGRAMMER = stk500
\r
280 AVRDUDE_PROGRAMMER = butterfly
\r
282 # com1 = serial port. Use lpt1 to connect to parallel port.
\r
283 AVRDUDE_PORT = com2 # programmer connected to serial device
\r
285 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
\r
286 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
\r
289 # Uncomment the following if you want avrdude's erase cycle counter.
\r
290 # Note that this counter needs to be initialized first using -Yn,
\r
291 # see avrdude manual.
\r
292 #AVRDUDE_ERASE_COUNTER = -y
\r
294 # Uncomment the following if you do /not/ wish a verification to be
\r
295 # performed after programming the device.
\r
296 #AVRDUDE_NO_VERIFY = -V
\r
298 # Increase verbosity level. Please use this when submitting bug
\r
299 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
\r
300 # to submit bug reports.
\r
301 #AVRDUDE_VERBOSE = -v -v
\r
303 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
\r
304 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
\r
305 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
\r
306 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
\r
310 #---------------- Debugging Options ----------------
\r
312 # For simulavr only - target MCU frequency.
\r
313 DEBUG_MFREQ = $(F_CPU)
\r
315 # Set the DEBUG_UI to either gdb or insight.
\r
319 # Set the debugging back-end to either avarice, simulavr.
\r
320 DEBUG_BACKEND = avarice
\r
321 #DEBUG_BACKEND = simulavr
\r
323 # GDB Init Filename.
\r
324 GDBINIT_FILE = __avr_gdbinit
\r
326 # When using avarice settings for the JTAG
\r
327 JTAG_DEV = /dev/com1
\r
329 # Debugging port used to communicate between GDB / avarice / simulavr.
\r
332 # Debugging host used to communicate between GDB / avarice / simulavr, normally
\r
333 # just set to localhost unless doing some sort of crazy debugging when
\r
334 # avarice is running on a different computer.
\r
335 DEBUG_HOST = localhost
\r
339 #============================================================================
\r
342 # Define programs and commands.
\r
345 OBJCOPY = avr-objcopy
\r
346 OBJDUMP = avr-objdump
\r
359 MSG_ERRORS_NONE = Errors: none
\r
360 MSG_BEGIN = -------- begin --------
\r
361 MSG_END = -------- end --------
\r
362 MSG_SIZE_BEFORE = Size before:
\r
363 MSG_SIZE_AFTER = Size after:
\r
364 MSG_COFF = Converting to AVR COFF:
\r
365 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
\r
366 MSG_FLASH = Creating load file for Flash:
\r
367 MSG_EEPROM = Creating load file for EEPROM:
\r
368 MSG_EXTENDED_LISTING = Creating Extended Listing:
\r
369 MSG_SYMBOL_TABLE = Creating Symbol Table:
\r
370 MSG_LINKING = Linking:
\r
371 MSG_COMPILING = Compiling C:
\r
372 MSG_COMPILING_CPP = Compiling C++:
\r
373 MSG_ASSEMBLING = Assembling:
\r
374 MSG_CLEANING = Cleaning project:
\r
375 MSG_CREATING_LIBRARY = Creating library:
\r
380 # Define all object files.
\r
381 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
\r
383 # Define all listing files.
\r
384 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
\r
387 # Compiler flags to generate dependency files.
\r
388 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
\r
391 # Combine all necessary flags and optional flags.
\r
392 # Add target processor to flags.
\r
393 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
\r
394 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
\r
395 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
\r
402 all: begin gccversion sizebefore build sizeafter end
\r
404 # Change the build target to build a HEX file or a library.
\r
405 build: elf hex eep lss sym
\r
414 LIBNAME=lib$(TARGET).a
\r
420 # AVR Studio 3.x does not check make's exit code but relies on
\r
421 # the following magic strings to be generated by the compile job.
\r
431 # Display size of file.
\r
432 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
\r
433 ELFSIZE = $(SIZE) -A $(TARGET).elf
\r
436 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
\r
439 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
\r
442 # Display compiler version information.
\r
448 # Program the device.
\r
449 program: $(TARGET).hex $(TARGET).eep
\r
450 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
\r
453 # Generate avr-gdb config/init file which does the following:
\r
454 # define the reset signal, load the target file, connect to target, and set
\r
455 # a breakpoint at main().
\r
457 @$(REMOVE) $(GDBINIT_FILE)
\r
458 @echo define reset >> $(GDBINIT_FILE)
\r
459 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
\r
460 @echo end >> $(GDBINIT_FILE)
\r
461 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
\r
462 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
\r
463 ifeq ($(DEBUG_BACKEND),simulavr)
\r
464 @echo load >> $(GDBINIT_FILE)
\r
466 @echo break main >> $(GDBINIT_FILE)
\r
468 debug: gdb-config $(TARGET).elf
\r
469 ifeq ($(DEBUG_BACKEND), avarice)
\r
470 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
\r
471 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
\r
472 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
\r
473 @$(WINSHELL) /c pause
\r
476 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
\r
477 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
\r
479 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
\r
484 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
\r
485 COFFCONVERT = $(OBJCOPY) --debugging
\r
486 COFFCONVERT += --change-section-address .data-0x800000
\r
487 COFFCONVERT += --change-section-address .bss-0x800000
\r
488 COFFCONVERT += --change-section-address .noinit-0x800000
\r
489 COFFCONVERT += --change-section-address .eeprom-0x810000
\r
493 coff: $(TARGET).elf
\r
495 @echo $(MSG_COFF) $(TARGET).cof
\r
496 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
\r
499 extcoff: $(TARGET).elf
\r
501 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
\r
502 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
\r
506 # Create final output files (.hex, .eep) from ELF output file.
\r
509 @echo $(MSG_FLASH) $@
\r
510 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
\r
514 @echo $(MSG_EEPROM) $@
\r
515 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
\r
516 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
\r
518 # Create extended listing file from ELF output file.
\r
521 @echo $(MSG_EXTENDED_LISTING) $@
\r
522 $(OBJDUMP) -h -S $< > $@
\r
524 # Create a symbol table from ELF output file.
\r
527 @echo $(MSG_SYMBOL_TABLE) $@
\r
532 # Create library from object files.
\r
533 .SECONDARY : $(TARGET).a
\r
537 @echo $(MSG_CREATING_LIBRARY) $@
\r
541 # Link: create ELF output file from object files.
\r
542 .SECONDARY : $(TARGET).elf
\r
546 @echo $(MSG_LINKING) $@
\r
547 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
\r
550 # Compile: create object files from C source files.
\r
551 $(OBJDIR)/%.o : %.c
\r
553 @echo $(MSG_COMPILING) $<
\r
554 $(CC) -c $(ALL_CFLAGS) $< -o $@
\r
557 # Compile: create object files from C++ source files.
\r
558 $(OBJDIR)/%.o : %.cpp
\r
560 @echo $(MSG_COMPILING_CPP) $<
\r
561 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
\r
564 # Compile: create assembler files from C source files.
\r
566 $(CC) -S $(ALL_CFLAGS) $< -o $@
\r
569 # Compile: create assembler files from C++ source files.
\r
571 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
\r
574 # Assemble: create object files from assembler source files.
\r
575 $(OBJDIR)/%.o : %.S
\r
577 @echo $(MSG_ASSEMBLING) $<
\r
578 $(CC) -c $(ALL_ASFLAGS) $< -o $@
\r
581 # Create preprocessed source for use in sending a bug report.
\r
583 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
\r
586 # Target: clean project.
\r
587 clean: begin clean_list end
\r
591 @echo $(MSG_CLEANING)
\r
592 $(REMOVE) $(TARGET).hex
\r
593 $(REMOVE) $(TARGET).eep
\r
594 $(REMOVE) $(TARGET).cof
\r
595 $(REMOVE) $(TARGET).elf
\r
596 $(REMOVE) $(TARGET).map
\r
597 $(REMOVE) $(TARGET).sym
\r
598 $(REMOVE) $(TARGET).lss
\r
599 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
\r
600 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
\r
601 $(REMOVE) $(SRC:.c=.s)
\r
602 $(REMOVE) $(SRC:.c=.d)
\r
603 $(REMOVE) $(SRC:.c=.i)
\r
607 # Create object files directory
\r
608 $(shell mkdir $(OBJDIR) 2>/dev/null)
\r
611 # Include the dependency files.
\r
612 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
\r
615 # Listing of phony targets.
\r
616 .PHONY : all begin finish end sizebefore sizeafter gccversion \
\r
617 build elf hex eep lss sym coff extcoff \
\r
618 clean clean_list program debug gdb-config
\r
620 upload : $(TARGET).hex
\r
621 avrdude -p m169 -c butterfly -P /dev/ttyUSB0 -U flash:w:$(TARGET).hex
\r