2 #######################################
6 # Default program to build
11 #######################################
19 include mk
/hw
/${HW}.mk
22 INCLUDES
+=-I mm
/include -I
include -I.
23 CFLAGS
+=-D__HW_CONF_HEADER__
="<config/${CONFIG}.h>"
25 CFLAGS
+= -mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
)UL
27 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
28 CFLAGS
+= -Wall
-Wstrict-prototypes
29 CFLAGS
+= -Os
-gdwarf-2
30 CFLAGS
+= -Wa
,-adhlns
=$(<:.c
=.lst
)
31 CFLAGS
+= -MD
$(@
:.c
:.d
)
34 ASFLAGS
+= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
-mmcu
=$(MCU
)
35 ASFLAGS
+= -x assembler-with-cpp
37 #---------------- Library Options ----------------
38 # Minimalistic printf version
39 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
41 # Floating point printf version (requires MATH_LIB = -lm below)
42 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
44 # If this is left blank, then it will use the Standard printf version.
46 #PRINTF_LIB = $(PRINTF_LIB_MIN)
47 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
49 # Minimalistic scanf version
50 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
52 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
53 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
55 # If this is left blank, then it will use the Standard scanf version.
57 #SCANF_LIB = $(SCANF_LIB_MIN)
58 #SCANF_LIB = $(SCANF_LIB_FLOAT)
60 LDFLAGS
= -Wl
,-Map
=$(@
:.elf
=.map
),--cref
61 LIBS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
63 #---------------- Programming Options (avrdude) ----------------
65 # Programming hardware: alf avr910 avrisp bascom bsd
66 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
69 # to get a full listing.
71 AVRDUDE_PROGRAMMER ?
= avrisp2
73 # com1 = serial port. Use lpt1 to connect to parallel port.
76 AVRDUDE_WRITE_FUSES
= -U lfuse
:w
:${LFUSE}:m
-U hfuse
:w
:${HFUSE}:m \
79 # Uncomment the following if you want avrdude's erase cycle counter.
80 # Note that this counter needs to be initialized first using -Yn,
82 #AVRDUDE_ERASE_COUNTER = -y
84 # Uncomment the following if you do /not/ wish a verification to be
85 # performed after programming the device.
86 # AVRDUDE_NO_VERIFY = -V
88 # Increase verbosity level. Please use this when submitting bug
89 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
90 # to submit bug reports.
91 #AVRDUDE_VERBOSE = -v -v
93 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
94 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
95 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
96 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
99 # Define programs and commands.
102 OBJCOPY
= avr-objcopy
103 OBJDUMP
= avr-objdump
109 define SELECT_DEFAULT_template
=
117 program
: $(1)_program
125 cleanall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_clean
)
126 buildall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_build
)
128 .PHONY
: clean build program cleanall buildall
all
130 $(eval
$(call SELECT_DEFAULT_template
, $(PROG
)))
132 # Create final output files (.hex, .eep) from ELF output file.
135 $(Q
)$(OBJCOPY
) -O ihex
-R .fuse
-R .eeprom
$< $@
139 $(Q
)$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
140 --change-section-lma .eeprom
=0 -O ihex
$< $@
142 # Create extended listing file from ELF output file.
145 $(Q
)$(OBJDUMP
) -h
-S
$< > $@
147 # Create a symbol table from ELF output file.
152 # Link: create ELF output file from object files.
155 $(Q
)$(CC
) $(CFLAGS
) $^
-o
$@
$(LDFLAGS
)
157 # Compile: create object files from C source files.
158 $(BUILD_DIR
)/%.o
: %.c Makefile
$(wildcard mk
/hw
/*)
161 $(Q
)$(CC
) -c
$(CFLAGS
) $< -o
$@
163 # Compile: create assembler files from C source files.
166 $(Q
)$(CC
) -S
$(CFLAGS
) $< -o
$@
168 # Assemble: create object files from assembler source files.
172 $(Q
)$(CC
) -c
$(ASFLAGS
) $< -o
$@
174 ########################### The big template for each program ##################
175 define PROGRAM_template
=
178 @echo
"$(1) Objects: " $$($(1)_OBJS
)
180 # Determine program's object files
181 $(1)_OBJS
=$$(foreach obj
, $$($(1)_SRC
:.c
=.o
), $(BUILD_DIR
)/$$(obj
))
182 $(1)_OBJS
+=$$($(1)_ASRC
:.S
=.o
)
184 # Collect all listing files - for cleanup
185 $(1)_LST
+= $$($(1)_SRC
:.c
=.lst
) $$($(1)_ASRC
:.S
=.lst
)
188 $(1).elf
: $$($(1)_OBJS
)
190 $(1)_program
: $(1).hex
$(1).eep
192 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
) -U flash
:w
:$(1).hex
-U eeprom
:w
:$(1).eep
194 $(1)_fuses.bin
: $(1).elf
196 $(Q
)$(OBJCOPY
) -j .fuse
$(1).elf
-O binary
$$@
199 $(1)_fuses
: $(1)_fuses.bin
201 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
)\
202 -U lfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$2}'):m \
203 -U hfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$3}'):m \
204 -U efuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| head
-n1 |awk
'{print $$$$4}'):m
208 $(Q
) $(SIZE
) -A
$(1).elf
210 # Target: clean project.
220 $(Q
)$(RM
) $$($(1)_OBJS
)
221 $(Q
)$(RM
) $$($(1)_LST
)
222 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.s
)
223 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.d
)
224 $(Q
)$(RM
) $(1)_fuses.bin
225 $(Q
) rm -rf
$(BUILD_DIR
)/
227 $(1)_build
: $(1).hex
$(1)_size
229 -include $$($(1)_OBJS
:.o
=.d
)
231 .PRECIOUS
: $$($(1)_OBJS
)
232 .PHONY
: $(1) $(1)_clean
$(1)_size
$(1)_build
236 ################################################################################
238 $(foreach prog
,$(PROGRAMS
),$(eval
$(call PROGRAM_template
,$(prog
))))