1 #----------------------------------------------------------------------------
3 # Makefile based on the public domain Makefile by Peter Fleury
5 #----------------------------------------------------------------------------
8 # make all = Make software.
10 # make clean = Clean out built project files.
12 # make coff = Convert ELF to AVR COFF.
14 # make extcoff = Convert ELF to AVR Extended COFF.
16 # make program = Download the hex file to the device, using avrdude.
17 # Please customize the avrdude settings below first!
19 # make debug = Start either simulavr or avarice as specified for debugging,
20 # with avr-gdb or avr-insight as the front end for debugging.
22 # make filename.s = Just compile filename.c into the assembler code only.
24 # make filename.i = Create a preprocessed source file for use in submitting
25 # bug reports to the GCC project.
27 # To rebuild project do "make clean" then "make all".
28 #----------------------------------------------------------------------------
41 # Processor frequency.
42 # This will define a symbol, F_CPU, in all source code files equal to the
43 # processor frequency. You can then use this symbol in your source code to
44 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
45 # automatically to create a 32-bit value in your source code.
49 # Output format. (can be srec, ihex, binary)
53 # Target file name (without extension).
56 # List C source files here. (C dependencies are automatically generated.)
60 # List Assembler source files here.
61 # Make them always end in a capital .S. Files ending in a lowercase .s
62 # will not be considered source files but generated files (assembler
63 # output from the compiler), and will be deleted upon "make clean"!
64 # Even though the DOS/Win* filesystem matches both .s and .S the same,
65 # it will preserve the spelling of the filenames, and gcc itself does
66 # care about how the name is spelled on its command-line.
70 # Optimization level, can be [0, 1, 2, 3, s].
71 # 0 = turn off optimization. s = optimize for size.
72 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
77 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
78 # AVR Studio 4.10 requires dwarf-2.
79 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
83 # List any extra directories to look for include files here.
84 # Each directory must be seperated by a space.
85 # Use forward slashes for directory separators.
86 # For a directory that has spaces, enclose it in quotes.
90 # Compiler flag to set the C Standard level.
92 # gnu89 = c89 plus GCC extensions
93 # c99 = ISO C99 standard (not yet fully implemented)
94 # gnu99 = c99 plus GCC extensions
95 CSTANDARD
= -std
=gnu99
98 # Place -D or -U options here
99 CDEFS
= -DF_CPU
=$(F_CPU
)UL
-DBOOT_START
=${BOOT_START} -DBOOT_PAGES
=${BOOT_PAGES}
102 # Place -I options here
106 #BOOT_LDFLAGS=-Wl,-Ttext=${BOOT_START}
108 #---------------- Compiler Options ----------------
109 # -g*: generate debugging information
110 # -O*: optimization level
111 # -f...: tuning, see GCC manual and avr-libc documentation
112 # -Wall...: warning level
113 # -Wa,...: tell GCC to pass this to the assembler.
114 # -adhlns...: create assembler listing
116 CFLAGS
+= $(CDEFS
) $(CINCS
)
118 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
119 CFLAGS
+= -Wall
-Wstrict-prototypes
120 CFLAGS
+= -Wa
,-adhlns
=$(<:.c
=.lst
)
121 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
122 CFLAGS
+= $(CSTANDARD
)
125 #---------------- Assembler Options ----------------
126 # -Wa,...: tell GCC to pass this to the assembler.
127 # -ahlms: create listing
128 # -gstabs: have the assembler create line number information; note that
129 # for use in COFF files, additional information about filenames
130 # and function names needs to be present in the assembler source
131 # files -- see avr-libc docs [FIXME: not yet described there]
132 ASFLAGS
= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
135 #---------------- Library Options ----------------
136 # Minimalistic printf version
137 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
139 # Floating point printf version (requires MATH_LIB = -lm below)
140 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
142 # If this is left blank, then it will use the Standard printf version.
144 #PRINTF_LIB = $(PRINTF_LIB_MIN)
145 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
148 # Minimalistic scanf version
149 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
151 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
152 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
154 # If this is left blank, then it will use the Standard scanf version.
156 #SCANF_LIB = $(SCANF_LIB_MIN)
157 #SCANF_LIB = $(SCANF_LIB_FLOAT)
163 #---------------- External Memory Options ----------------
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
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
177 #---------------- Linker Options ----------------
178 # -Wl,...: tell GCC to pass this to linker.
179 # -Map: create map file
180 # --cref: add cross reference to map file
181 LDFLAGS
= $(BOOT_LDFLAGS
) -Wl
,-Map
=$(TARGET
).map
,--cref
182 LDFLAGS
+= $(EXTMEMOPTS
)
183 LDFLAGS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
187 #---------------- Programming Options (avrdude) ----------------
189 # Programming hardware: alf avr910 avrisp bascom bsd
190 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
193 # to get a full listing.
196 AVRDUDE_PROGRAMMER ?
= avrisp2
199 # com1 = serial port. Use lpt1 to connect to parallel port.
202 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
203 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
205 AVRDUDE_WRITE_FUSES
= -U lfuse
:w
:${LFUSE}:m
-U hfuse
:w
:${HFUSE}:m \
206 -U efuse
:w
:${EFUSE}:m
208 # Uncomment the following if you want avrdude's erase cycle counter.
209 # Note that this counter needs to be initialized first using -Yn,
210 # see avrdude manual.
211 #AVRDUDE_ERASE_COUNTER = -y
213 # Uncomment the following if you do /not/ wish a verification to be
214 # performed after programming the device.
215 # AVRDUDE_NO_VERIFY = -V
217 # Increase verbosity level. Please use this when submitting bug
218 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
219 # to submit bug reports.
220 #AVRDUDE_VERBOSE = -v -v
222 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
223 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
224 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
225 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
226 AVRDUDE_FLAGS
+= -B
20
229 #---------------- Debugging Options ----------------
231 # For simulavr only - target MCU frequency.
232 DEBUG_MFREQ
= $(F_CPU
)
234 # Set the DEBUG_UI to either gdb or insight.
238 # Set the debugging back-end to either avarice, simulavr.
239 DEBUG_BACKEND
= avarice
240 #DEBUG_BACKEND = simulavr
243 GDBINIT_FILE
= __avr_gdbinit
245 # When using avarice settings for the JTAG
248 # Debugging port used to communicate between GDB / avarice / simulavr.
251 # Debugging host used to communicate between GDB / avarice / simulavr, normally
252 # just set to localhost unless doing some sort of crazy debugging when
253 # avarice is running on a different computer.
254 DEBUG_HOST
= localhost
258 #============================================================================
261 # Define programs and commands.
264 OBJCOPY
= avr-objcopy
265 OBJDUMP
= avr-objdump
276 MSG_ERRORS_NONE
= Errors
: none
277 MSG_BEGIN
= -------- begin
--------
278 MSG_END
= -------- end
--------
279 MSG_SIZE_BEFORE
= Size before
:
280 MSG_SIZE_AFTER
= Size after
:
281 MSG_COFF
= Converting to AVR COFF
:
282 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
283 MSG_FLASH
= Creating load file for Flash
:
284 MSG_EEPROM
= Creating load file for EEPROM
:
285 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
286 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
287 MSG_LINKING
= Linking
:
288 MSG_COMPILING
= Compiling
:
289 MSG_ASSEMBLING
= Assembling
:
290 MSG_CLEANING
= Cleaning project
:
293 # Define all object files.
294 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
296 # Define all listing files.
297 LST
= $(SRC
:.c
=.lst
) $(ASRC
:.S
=.lst
)
300 # Compiler flags to generate dependency files.
301 GENDEPFLAGS
= -MD
-MP
-MF .dep
/$(@F
).d
304 # Combine all necessary flags and optional flags.
305 # Add target processor to flags.
306 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
) $(GENDEPFLAGS
)
307 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
311 all: begin gccversion sizebefore build sizeafter end
313 build
: elf hex eep lss sym
323 # AVR Studio 3.x does not check make's exit code but relies on
324 # the following magic strings to be generated by the compile job.
334 # Display size of file.
335 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
336 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
337 AVRMEM
= avr-mem.sh
$(TARGET
).elf
$(MCU
)
340 @if
test -f
$(TARGET
).elf
; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); \
341 $(AVRMEM
) 2>/dev
/null
; echo
; fi
344 @if
test -f
$(TARGET
).elf
; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); \
345 $(AVRMEM
) 2>/dev
/null
; echo
; fi
349 # Display compiler version information.
355 # Program the device.
356 program
: $(TARGET
).hex
$(TARGET
).eep
357 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
360 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FUSES
)
362 # Generate avr-gdb config/init file which does the following:
363 # define the reset signal, load the target file, connect to target, and set
364 # a breakpoint at main().
366 @
$(REMOVE
) $(GDBINIT_FILE
)
367 @echo
define reset
>> $(GDBINIT_FILE
)
368 @echo SIGNAL SIGHUP
>> $(GDBINIT_FILE
)
369 @echo end
>> $(GDBINIT_FILE
)
370 @echo file
$(TARGET
).elf
>> $(GDBINIT_FILE
)
371 @echo target remote
$(DEBUG_HOST
):$(DEBUG_PORT
) >> $(GDBINIT_FILE
)
372 ifeq ($(DEBUG_BACKEND
),simulavr
)
373 @echo load
>> $(GDBINIT_FILE
)
375 @echo break main
>> $(GDBINIT_FILE
)
377 debug
: gdb-config
$(TARGET
).elf
378 ifeq ($(DEBUG_BACKEND
), avarice
)
379 @echo Starting AVaRICE
- Press enter when
"waiting to connect" message displays.
380 @
$(WINSHELL
) /c start avarice
--jtag
$(JTAG_DEV
) --erase
--program
--file \
381 $(TARGET
).elf
$(DEBUG_HOST
):$(DEBUG_PORT
)
382 @
$(WINSHELL
) /c pause
385 @
$(WINSHELL
) /c start simulavr
--gdbserver
--device
$(MCU
) --clock-freq \
386 $(DEBUG_MFREQ
) --port
$(DEBUG_PORT
)
388 @
$(WINSHELL
) /c start avr-
$(DEBUG_UI
) --command
=$(GDBINIT_FILE
)
391 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
392 COFFCONVERT
=$(OBJCOPY
) --debugging \
393 --change-section-address .data-0x800000 \
394 --change-section-address .bss-0x800000 \
395 --change-section-address .noinit-0x800000 \
396 --change-section-address .eeprom-0x810000
401 @echo
$(MSG_COFF
) $(TARGET
).cof
402 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
405 extcoff
: $(TARGET
).elf
407 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
408 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
412 # Create final output files (.hex, .eep) from ELF output file.
415 @echo
$(MSG_FLASH
) $@
416 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
420 @echo
$(MSG_EEPROM
) $@
421 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
422 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
424 # Create extended listing file from ELF output file.
427 @echo
$(MSG_EXTENDED_LISTING
) $@
428 $(OBJDUMP
) -h
-S
$< > $@
430 # Create a symbol table from ELF output file.
433 @echo
$(MSG_SYMBOL_TABLE
) $@
438 # Link: create ELF output file from object files.
439 .SECONDARY
: $(TARGET
).elf
443 @echo
$(MSG_LINKING
) $@
444 $(CC
) $(ALL_CFLAGS
) $^
--output
$@
$(LDFLAGS
)
447 # Compile: create object files from C source files.
450 @echo
$(MSG_COMPILING
) $<
451 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
454 # Compile: create assembler files from C source files.
456 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
459 # Assemble: create object files from assembler source files.
462 @echo
$(MSG_ASSEMBLING
) $<
463 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
465 # Create preprocessed source for use in sending a bug report.
467 $(CC
) -E
-mmcu
=$(MCU
) -I.
$(CFLAGS
) $< -o
$@
470 # Target: clean project.
471 clean: begin clean_list end
475 @echo
$(MSG_CLEANING
)
476 $(REMOVE
) $(TARGET
).hex
477 $(REMOVE
) $(TARGET
).eep
478 $(REMOVE
) $(TARGET
).cof
479 $(REMOVE
) $(TARGET
).elf
480 $(REMOVE
) $(TARGET
).map
481 $(REMOVE
) $(TARGET
).sym
482 $(REMOVE
) $(TARGET
).lss
485 $(REMOVE
) $(SRC
:.c
=.s
)
486 $(REMOVE
) $(SRC
:.c
=.d
)
492 # Include the dependency files.
493 -include $(shell mkdir .dep
2>/dev
/null
) $(wildcard .dep
/*)
496 # Listing of phony targets.
497 .PHONY
: all begin finish end sizebefore sizeafter gccversion \
498 build elf hex eep lss sym coff extcoff \
499 clean clean_list program debug gdb-config