2 #######################################
9 #######################################
17 include mk
/hw
/${HW}.mk
20 INCLUDES
+=-I mm
/include -I
include -I.
21 CFLAGS
+=-D__HW_CONF_HEADER__
="<config/${CONFIG}.h>"
23 CFLAGS
+= -mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
)UL
25 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
26 CFLAGS
+= -Wall
-Wstrict-prototypes
27 CFLAGS
+= -Os
-gdwarf-2
28 CFLAGS
+= -Wa
,-adhlns
=$(<:.c
=.lst
)
29 CFLAGS
+= -MD
$(@
:.c
:.d
)
32 ASFLAGS
+= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
-mmcu
=$(MCU
)
33 ASFLAGS
+= -x assembler-with-cpp
35 #---------------- Library Options ----------------
36 # Minimalistic printf version
37 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
39 # Floating point printf version (requires MATH_LIB = -lm below)
40 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
42 # If this is left blank, then it will use the Standard printf version.
44 #PRINTF_LIB = $(PRINTF_LIB_MIN)
45 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
47 # Minimalistic scanf version
48 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
50 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
51 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
53 # If this is left blank, then it will use the Standard scanf version.
55 #SCANF_LIB = $(SCANF_LIB_MIN)
56 #SCANF_LIB = $(SCANF_LIB_FLOAT)
58 LDFLAGS
= -Wl
,-Map
=$(@
:.elf
=.map
),--cref
59 LIBS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
61 #---------------- Programming Options (avrdude) ----------------
63 # Programming hardware: alf avr910 avrisp bascom bsd
64 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
67 # to get a full listing.
69 AVRDUDE_PROGRAMMER ?
= avrisp2
71 # com1 = serial port. Use lpt1 to connect to parallel port.
74 AVRDUDE_WRITE_FUSES
= -U lfuse
:w
:${LFUSE}:m
-U hfuse
:w
:${HFUSE}:m \
77 # Uncomment the following if you want avrdude's erase cycle counter.
78 # Note that this counter needs to be initialized first using -Yn,
80 #AVRDUDE_ERASE_COUNTER = -y
82 # Uncomment the following if you do /not/ wish a verification to be
83 # performed after programming the device.
84 # AVRDUDE_NO_VERIFY = -V
86 # Increase verbosity level. Please use this when submitting bug
87 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
88 # to submit bug reports.
89 #AVRDUDE_VERBOSE = -v -v
91 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
92 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
93 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
94 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
97 # Define programs and commands.
100 OBJCOPY
= avr-objcopy
101 OBJDUMP
= avr-objdump
107 define SELECT_DEFAULT_template
=
115 program
: $(1)_program
121 cleanall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_clean
)
122 buildall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_build
)
124 .PHONY
: clean build program cleanall buildall
all
126 $(eval
$(call SELECT_DEFAULT_template
, $(PROG
)))
128 # Create final output files (.hex, .eep) from ELF output file.
131 $(Q
)$(OBJCOPY
) -O ihex
-R .fuse
-R .eeprom
$< $@
135 $(Q
)$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
136 --change-section-lma .eeprom
=0 -O ihex
$< $@
138 # Create extended listing file from ELF output file.
141 $(Q
)$(OBJDUMP
) -h
-S
$< > $@
143 # Create a symbol table from ELF output file.
148 # Link: create ELF output file from object files.
151 $(Q
)$(CC
) $(CFLAGS
) $^
-o
$@
$(LDFLAGS
)
153 # Compile: create object files from C source files.
154 $(BUILD_DIR
)/%.o
: %.c Makefile
$(wildcard mk
/hw
/*)
157 $(Q
)$(CC
) -c
$(CFLAGS
) $< -o
$@
159 # Compile: create assembler files from C source files.
162 $(Q
)$(CC
) -S
$(CFLAGS
) $< -o
$@
164 # Assemble: create object files from assembler source files.
168 $(Q
)$(CC
) -c
$(ASFLAGS
) $< -o
$@
170 ########################### The big template for each program ##################
171 define PROGRAM_template
=
174 @echo
"$(1) Objects: " $$($(1)_OBJS
)
176 # Determine program's object files
177 $(1)_OBJS
=$$(foreach obj
, $$($(1)_SRC
:.c
=.o
), $(BUILD_DIR
)/$$(obj
))
178 $(1)_OBJS
+=$$($(1)_ASRC
:.S
=.o
)
180 # Collect all listing files - for cleanup
181 $(1)_LST
+= $$($(1)_SRC
:.c
=.lst
) $$($(1)_ASRC
:.S
=.lst
)
184 $(1).elf
: $$($(1)_OBJS
)
186 $(1)_program
: $(1).hex
$(1).eep
188 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
) -U flash
:w
:$(1).hex
-U eeprom
:w
:$(1).eep
190 $(1)_fuses.bin
: $(1).elf
192 $(Q
)$(OBJCOPY
) -j .fuse
$(1).elf
-O binary
$$@
195 $(1)_fuses
: $(1)_fuses.bin
197 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
)\
198 -U lfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$2}'):m \
199 -U hfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$3}'):m \
200 -U efuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| head
-n1 |awk
'{print $$$$4}'):m
204 $(Q
) $(SIZE
) -A
$(1).elf
206 # Target: clean project.
216 $(Q
)$(RM
) $$($(1)_OBJS
)
217 $(Q
)$(RM
) $$($(1)_LST
)
218 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.s
)
219 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.d
)
220 $(Q
)$(RM
) $(1)_fuses.bin
221 $(Q
) rm -rf
$(BUILD_DIR
)/
223 $(1)_build
: $(1).hex
$(1)_size
225 -include $$($(1)_OBJS
:.o
=.d
)
227 .PRECIOUS
: $$($(1)_OBJS
)
228 .PHONY
: $(1) $(1)_clean
$(1)_size
$(1)_build
232 ################################################################################
234 $(foreach prog
,$(PROGRAMS
),$(eval
$(call PROGRAM_template
,$(prog
))))