1 ####################################################
2 # fnordlicht-ng Makefile
3 ####################################################
6 # Any of these variables are overridden with the values from the file
7 # "config.mk", you can tune your settings there. The file "config.mk" is not
8 # under version control.
9 # Just run 'make' to create a "config.mk" with the default settings
11 # hardware type, possible values (default is unset):
12 # ATTENTION: please configure in config.mk, this is just included here for reference!
13 # - fnordlicht -- original fnordlicht hardware
14 # - fnordlichtmini -- fnordlichtmini hardware
15 #HARDWARE = fnordlicht
23 # main application name (without .hex)
24 # eg 'test' when the main function is defined in 'test.c'
28 # eg. 'test.c foo.c foobar/baz.c'
31 # asm sourcecode files
32 # eg. 'interrupts.S foobar/another.S'
33 ASRC
= $(wildcard *.S
)
35 # headers which should be considered when recompiling
36 # eg. 'global.h foobar/important.h'
37 HEADERS
= $(wildcard *.h
)
39 # include directories (used for both, c and asm)
44 # use more debug-flags when compiling
48 CONFIG_SERIAL_BAUDRATE
= 19200
50 # avrdude programmer protocol
52 # avrdude programmer device
54 # further flags for avrdude
57 CFLAGS
+= -DHARDWARE_
$(HARDWARE
)=1
58 CFLAGS
+= -DCONFIG_SERIAL_BAUDRATE
=$(CONFIG_SERIAL_BAUDRATE
)
60 # use a custom linker script
61 LDFLAGS
+= -L
$(CURDIR
)/ldscripts
65 # main make target (moved up here because of the config.mk target)
68 # create config.mk (if it does not exist yet)
70 @
$(CP
) config.mk.template config.mk
71 @echo
"===================================================="
72 @echo
"created file $@"
73 @echo
'please tune your settings (especially $$HARDWARE)'
74 @echo
"there, then run 'make' again"
75 @echo
"===================================================="
79 -include $(CURDIR
)/config.mk
81 # bootloader section start
84 # atmega8 with 1024 words bootloader:
85 # bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address)
86 #BOOT_SECTION_START = 0x1800
88 # atmega8 with 512 words bootloader:
89 # bootloader section starts at 0xe00 (word-address) == 0x1c00 (byte-address)
90 BOOT_SECTION_START
= 0x1c00
91 # 7kb data memory (raw memory minus bootloader space)
94 # use custom linker script
97 ifeq ($(MCU
),atmega88
)
98 # atmega88 with 1024 words bootloader:
99 # bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address)
100 #BOOT_SECTION_START = 0x1800
102 # atmega88 with 512 words bootloader:
103 # bootloader section starts at 0xe00 (word-address) == 0x1c00 (byte-address)
104 BOOT_SECTION_START
= 0x1c00
105 # 7kb data memory (raw memory minus bootloader space)
108 # use custom linker script
111 ifeq ($(MCU
),atmega168
)
112 # atmega168 with 1024 words bootloader:
113 # bootloader section starts at 0x1c00 (word-address) == 0x3800 (byte-address)
114 #BOOT_SECTION_START = 0x3800
116 # atmega168 with 512 words bootloader:
117 # bootloader section starts at 0x1e00 (word-address) == 0x3c00 (byte-address)
118 BOOT_SECTION_START
= 0x3c00
119 # 15kb data memory (raw memory minus bootloader space)
122 # use custom linker script
126 LDFLAGS
+= -Wl
,--section-start
=.text
=$(BOOT_SECTION_START
)
127 CFLAGS
+= -DBOOT_SECTION_START
=$(BOOT_SECTION_START
)
130 ####################################################
131 # 'make' configuration
132 ####################################################
134 OBJCOPY
= avr-objcopy
135 OBJDUMP
= avr-objdump
144 # flags for automatic dependency handling
145 DEPFLAGS
= -MD
-MP
-MF .dep
/$(@F
).d
147 # flags for the compiler (for .c files)
148 CFLAGS
+= -g
-Os
-mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
) -std
=gnu99
-fshort-enums
$(DEPFLAGS
)
149 CFLAGS
+= $(addprefix -I
,$(INCLUDES
))
150 CFLAGS
+= -fno-split-wide-types
151 CFLAGS
+= --param inline-call-cost
=2 -finline-limit
=3 -fno-inline-small-functions
152 CFLAGS
+= -Wl
,--relax
154 # flags for the compiler (for .S files)
155 ASFLAGS
+= -g
-mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
) -x assembler-with-cpp
$(DEPFLAGS
)
156 ASFLAGS
+= $(addprefix -I
,$(INCLUDES
))
158 # flags for the linker
159 LDFLAGS
+= -mmcu
=$(MCU
)
161 # fill in object files
162 OBJECTS
+= $(SRC
:.c
=.o
)
163 OBJECTS
+= $(ASRC
:.S
=.o
)
165 # include more debug flags, if $(DEBUG) is 1
167 CFLAGS
+= -Wall
-W
-Wchar-subscripts
-Wmissing-prototypes
168 CFLAGS
+= -Wmissing-declarations
-Wredundant-decls
169 CFLAGS
+= -Wstrict-prototypes
-Wshadow
-Wbad-function-cast
170 CFLAGS
+= -Winline
-Wpointer-arith
-Wsign-compare
171 CFLAGS
+= -Wunreachable-code
-Wdisabled-optimization
172 CFLAGS
+= -Wcast-align
-Wwrite-strings
-Wnested-externs
-Wundef
173 CFLAGS
+= -Wa
,-adhlns
=$(basename $@
).lst
174 CFLAGS
+= -DCONFIG_DEBUG
=1
177 ####################################################
178 # avrdude configuration
179 ####################################################
180 ifeq ($(MCU
),atmega8
)
183 ifeq ($(MCU
),atmega48
)
186 ifeq ($(MCU
),atmega88
)
189 ifeq ($(MCU
),atmega168
)
193 AVRDUDE_FLAGS
+= -p
$(AVRDUDE_MCU
)
195 ####################################################
197 ####################################################
199 .PHONY
: hardware-check
clean distclean avrdude-terminal
201 # check if HARDWARE is set
204 @echo
'please edit config.mk and set $$HARDWARE'
208 $(TARGET
).elf
: hardware-check
$(OBJECTS
)
209 $(CC
) $(CFLAGS
) $(LDFLAGS
) -o
$@
$(OBJECTS
)
211 # all objects (.o files) and config.mk
212 $(OBJECTS
): $(HEADERS
) config.mk
214 # remove all compiled files
216 $(RM
) $(foreach ext
,elf hex eep.hex map
,$(TARGET
).
$(ext
)) \
217 $(foreach file
,$(patsubst %.o
,%,$(OBJECTS
)),$(foreach ext
,o lst lss
,$(file
).
$(ext
)))
219 # additionally remove the dependency makefile and config.mk
224 # avrdude-related targets
225 install program
: program-
$(TARGET
)
228 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -t
231 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U flash
:w
:$< -U lock
:w
:0x2f:m
233 program-eeprom-
%: %.eep.hex
234 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U eeprom
:w
:$<
236 # special programming targets
238 $(OBJCOPY
) -O ihex
-R .eeprom
$< $@
239 @echo
"===================================================="
240 @echo
"$@ compiled for hardware: $(HARDWARE)"
241 @echo
"using controller $(MCU)"
242 @echo
-n
"size for $< is "
243 @
$(SIZE
) -A
$@ | grep
'\.sec1' | tr
-s
' ' | cut
-d
" " -f2
244 @echo
"===================================================="
247 $(OBJCOPY
) --set-section-flags
=.eeprom
="alloc,load" --change-section-lma .eeprom
=0 -O ihex
-j .eeprom
$< $@
250 $(OBJDUMP
) -h
-S
$< > $@
252 .PHONY
: fuses-atmega8-fnordlichtmini-with-bootloader fuses-lock
254 fuses-atmega8-fnordlichtmini-with-bootloader
:
255 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lfuse
:w
:0x3f:m
-U hfuse
:w
:0xda:m
257 fuses-atmega8-fnordlichtmini-without-bootloader
:
258 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lfuse
:w
:0x3f:m
-U hfuse
:w
:0xd9:m
261 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lock
:w
:0x2f:m
263 -include $(shell $(MKDIR
) .dep
2>/dev
/null
) $(wildcard .dep
/*)