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
17 # main application name (without .hex)
18 # eg 'test' when the main function is defined in 'test.c'
22 # eg. 'test.c foo.c foobar/baz.c'
23 SRC
= $(wildcard *.c
) usbdrv
/usbdrv.c
25 # asm sourcecode files
26 # eg. 'interrupts.S foobar/another.S'
27 ASRC
= $(wildcard *.S
) usbdrv
/usbdrvasm.S
29 # headers which should be considered when recompiling
30 # eg. 'global.h foobar/important.h'
31 HEADERS
= $(wildcard *.h
)
33 # include directories (used for both, c and asm)
38 # use more debug-flags when compiling
42 CONFIG_SERIAL_BAUDRATE
= 19200
44 # avrdude programmer protocol
46 # avrdude programmer device
48 # further flags for avrdude
51 CFLAGS
+= -DCONFIG_SERIAL_BAUDRATE
=$(CONFIG_SERIAL_BAUDRATE
)
53 # use a custom linker script
54 LDFLAGS
+= -L
$(CURDIR
)/ldscripts
58 # main make target (moved up here because of the config.mk target)
61 # create config.mk (if it does not exist yet)
63 @
$(CP
) config.mk.template config.mk
64 @echo
"===================================================="
65 @echo
"created file $@"
66 @echo
"please tune your settings there, then run 'make' again"
67 @echo
"===================================================="
71 -include $(CURDIR
)/config.mk
73 ####################################################
74 # 'make' configuration
75 ####################################################
87 # flags for automatic dependency handling
88 DEPFLAGS
= -MD
-MP
-MF .dep
/$(@F
).d
90 # flags for the compiler (for .c files)
91 CFLAGS
+= -g
-Os
-mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
) -std
=gnu99
-fshort-enums
$(DEPFLAGS
)
92 CFLAGS
+= $(addprefix -I
,$(INCLUDES
))
93 CFLAGS
+= -fno-split-wide-types
94 CFLAGS
+= --param inline-call-cost
=2 -finline-limit
=3 -fno-inline-small-functions
95 #CFLAGS += -Wl,--relax
97 # flags for the compiler (for .S files)
98 ASFLAGS
+= -g
-mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
) -x assembler-with-cpp
$(DEPFLAGS
)
99 ASFLAGS
+= $(addprefix -I
,$(INCLUDES
))
101 # flags for the linker
102 LDFLAGS
+= -mmcu
=$(MCU
)
104 # fill in object files
105 OBJECTS
+= $(SRC
:.c
=.o
)
106 OBJECTS
+= $(ASRC
:.S
=.o
)
108 # include more debug flags, if $(DEBUG) is 1
110 CFLAGS
+= -Wall
-W
-Wchar-subscripts
-Wmissing-prototypes
111 CFLAGS
+= -Wmissing-declarations
-Wredundant-decls
112 CFLAGS
+= -Wstrict-prototypes
-Wshadow
-Wbad-function-cast
113 CFLAGS
+= -Winline
-Wpointer-arith
-Wsign-compare
114 CFLAGS
+= -Wunreachable-code
-Wdisabled-optimization
115 CFLAGS
+= -Wcast-align
-Wwrite-strings
-Wnested-externs
-Wundef
116 CFLAGS
+= -Wa
,-adhlns
=$(basename $@
).lst
117 CFLAGS
+= -DCONFIG_DEBUG
=1
120 ####################################################
121 # avrdude configuration
122 ####################################################
123 ifeq ($(MCU
),atmega8
)
126 ifeq ($(MCU
),atmega48
)
129 ifeq ($(MCU
),atmega88
)
132 ifeq ($(MCU
),atmega168
)
136 AVRDUDE_FLAGS
+= -p
$(AVRDUDE_MCU
)
138 ####################################################
140 ####################################################
142 .PHONY
: clean distclean avrdude-terminal
144 $(TARGET
).elf
: $(OBJECTS
)
145 $(CC
) $(CFLAGS
) $(LDFLAGS
) -o
$@
$(OBJECTS
)
147 # all objects (.o files) and config.mk
148 $(OBJECTS
): $(HEADERS
) config.mk
150 # remove all compiled files
152 $(RM
) $(foreach ext
,elf hex eep.hex map
,$(TARGET
).
$(ext
)) \
153 $(foreach file
,$(patsubst %.o
,%,$(OBJECTS
)),$(foreach ext
,o lst lss
,$(file
).
$(ext
)))
155 # additionally remove the dependency makefile and config.mk
160 # avrdude-related targets
161 install program
: program-
$(TARGET
)
164 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -t
167 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U flash
:w
:$<
169 program-eeprom-
%: %.eep.hex
170 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U eeprom
:w
:$<
172 # special programming targets
174 $(OBJCOPY
) -O ihex
-R .eeprom
$< $@
175 @echo
"===================================================="
176 @echo
"$@ compiled for fnordlicht-controller"
177 @echo
"using controller $(MCU)"
178 @echo
-n
"size for $< is "
179 @
$(SIZE
) -A
$@ | grep
'\.sec1' | tr
-s
' ' | cut
-d
" " -f2
180 @echo
"===================================================="
183 $(OBJCOPY
) --set-section-flags
=.eeprom
="alloc,load" --change-section-lma .eeprom
=0 -O ihex
-j .eeprom
$< $@
186 $(OBJDUMP
) -h
-S
$< > $@
188 .PHONY
: fuses-atmega8-fnordlichtmini-with-bootloader fuses-lock
190 fuses-atmega8-fnordlichtmini-with-bootloader
:
191 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lfuse
:w
:0x3f:m
-U hfuse
:w
:0xda:m
193 fuses-atmega8-fnordlichtmini-without-bootloader
:
194 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lfuse
:w
:0x3f:m
-U hfuse
:w
:0xd9:m
197 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -c
$(PROG
) -P
$(DEV
) -U lock
:w
:0x2f:m
199 -include $(shell $(MKDIR
) .dep
2>/dev
/null
) $(wildcard .dep
/*)