]> git.zerfleddert.de Git - fnordlicht-mini/blame_incremental - firmware/fnordlicht-firmware/Makefile
reference firmware
[fnordlicht-mini] / firmware / fnordlicht-firmware / Makefile
... / ...
CommitLineData
1####################################################
2# fnordlicht-ng Makefile
3####################################################
4
5# ATTENTION:
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
10
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
16
17# controller
18MCU = atmega8
19
20# frequency
21F_CPU = 16000000UL
22
23# main application name (without .hex)
24# eg 'test' when the main function is defined in 'test.c'
25TARGET = fnordlicht
26
27# c sourcecode files
28# eg. 'test.c foo.c foobar/baz.c'
29SRC = $(wildcard *.c)
30
31# asm sourcecode files
32# eg. 'interrupts.S foobar/another.S'
33ASRC =
34
35# headers which should be considered when recompiling
36# eg. 'global.h foobar/important.h'
37HEADERS = $(wildcard *.h)
38
39# include directories (used for both, c and asm)
40# eg '. usbdrv/'
41INCLUDES =
42
43
44# use more debug-flags when compiling
45DEBUG = 0
46
47# default static color program
48CONFIG_SCRIPT_DEFAULT = 1
49# include the script interpreter
50CONFIG_SCRIPT = 1
51# include uart support
52CONFIG_SERIAL = 1
53# include remote command support (needs uart)
54CONFIG_REMOTE = 1
55# secondary pwm output
56CONFIG_SECONDARY_PWM = 1
57# default baudrate
58CONFIG_SERIAL_BAUDRATE = 19200
59# check jumper for master mode
60CONFIG_MASTER_MODE = 1
61
62# avrdude programmer protocol
63PROG = usbasp
64# avrdude programmer device
65DEV = usb
66# further flags for avrdude
67AVRDUDE_FLAGS =
68
69CFLAGS += -DHARDWARE_$(HARDWARE)=1 -DCONFIG_SCRIPT_DEFAULT=$(CONFIG_SCRIPT_DEFAULT)
70CFLAGS += -DCONFIG_SCRIPT=$(CONFIG_SCRIPT) -DCONFIG_SERIAL=$(CONFIG_SERIAL)
71CFLAGS += -DCONFIG_REMOTE=$(CONFIG_REMOTE) -DCONFIG_SECONDARY_PWM=$(CONFIG_SECONDARY_PWM)
72CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
73CFLAGS += -DCONFIG_MASTER_MODE=$(CONFIG_MASTER_MODE)
74
75####################################################
76# 'make' configuration
77####################################################
78CC = avr-gcc
79OBJCOPY = avr-objcopy
80OBJDUMP = avr-objdump
81AS = avr-as
82SIZE = avr-size
83CP = cp
84RM = rm -f
85RMDIR = rm -rf
86MKDIR = mkdir
87AVRDUDE = avrdude
88
89# flags for automatic dependency handling
90DEPFLAGS = -MD -MP -MF .dep/$(@F).d
91
92# flags for the compiler (for .c files)
93CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
94CFLAGS += $(addprefix -I,$(INCLUDES))
95# optimize for size
96CFLAGS += -mcall-prologues
97CFLAGS += --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions
98CFLAGS += -Wl,--relax
99CFLAGS += -fno-split-wide-types
100
101# place each function in an own section and do garbage collection
102CFLAGS += -ffunction-sections -fdata-sections
103CFLAGS += -Wl,--gc-sections
104
105# flags for the compiler (for .S files)
106ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
107ASFLAGS += $(addprefix -I,$(INCLUDES))
108
109# flags for the linker
110LDFLAGS += -mmcu=$(MCU)
111
112# fill in object files
113OBJECTS += $(SRC:.c=.o)
114OBJECTS += $(ASRC:.S=.o)
115
116.PHONY: all
117
118# main make target (moved up here because of the config.mk target)
119all: $(TARGET).hex $(TARGET).bin
120
121# create config.mk (if it does not exist yet)
122$(CURDIR)/config.mk:
123 @$(CP) config.mk.template config.mk
124 @echo "===================================================="
125 @echo "created file $@"
126 @echo 'please tune your settings (especially $$HARDWARE)'
127 @echo "there, then run 'make' again"
128 @echo "===================================================="
129 @exit 1
130
131# include config file
132-include $(CURDIR)/config.mk
133
134# include more debug flags, if $(DEBUG) is 1
135ifeq ($(DEBUG),1)
136 CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes
137 CFLAGS += -Wmissing-declarations -Wredundant-decls
138 CFLAGS += -Wstrict-prototypes -Wshadow -Wbad-function-cast
139 CFLAGS += -Winline -Wpointer-arith -Wsign-compare
140 CFLAGS += -Wunreachable-code -Wdisabled-optimization
141 CFLAGS += -Wcast-align -Wwrite-strings -Wnested-externs -Wundef
142 CFLAGS += -Wa,-adhlns=$(basename $@).lst
143 CFLAGS += -DCONFIG_DEBUG=1
144endif
145
146####################################################
147# avrdude configuration
148####################################################
149ifeq ($(MCU),atmega8)
150 AVRDUDE_MCU=m8
151endif
152ifeq ($(MCU),atmega48)
153 AVRDUDE_MCU=m48
154endif
155ifeq ($(MCU),atmega88)
156 AVRDUDE_MCU=m88
157endif
158ifeq ($(MCU),atmega168)
159 AVRDUDE_MCU=m168
160endif
161
162AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
163
164####################################################
165# make targets
166####################################################
167
168.PHONY: hardware-check clean distclean avrdude-terminal
169
170# check if HARDWARE is set
171hardware-check:
172ifeq ($(HARDWARE),)
173 @echo 'please edit config.mk and set $$HARDWARE'
174 @exit 1
175endif
176
177$(TARGET).elf: hardware-check $(OBJECTS)
178 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
179
180# all objects (.o files) and config.mk
181$(OBJECTS): $(HEADERS) config.mk
182
183# remove all compiled files
184clean:
185 $(RM) $(foreach ext,elf hex eep.hex bin map,$(TARGET).$(ext)) \
186 $(foreach file,$(patsubst %.o,%,$(OBJECTS)),$(foreach ext,o lst lss,$(file).$(ext)))
187
188# additionally remove the dependency makefile and config.mk
189distclean: clean
190 $(RMDIR) .dep
191 $(RM) config.mk
192
193# avrdude-related targets
194install program: program-$(TARGET)
195
196avrdude-terminal:
197 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
198
199program-%: %.hex
200 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$<
201
202program-eeprom-%: %.eep.hex
203 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U eeprom:w:$<
204
205# special programming targets
206%.hex: %.elf
207 $(OBJCOPY) -O ihex -R .eeprom $< $@
208 @echo "===================================================="
209 @echo "$@ compiled for hardware: $(HARDWARE)"
210 @echo "using controller $(MCU)"
211 @echo -n "size for $< is "
212 @$(SIZE) -A $@ | grep '\.sec1' | tr -s ' ' | cut -d" " -f2
213 @echo "===================================================="
214
215# special programming targets
216%.bin: %.elf
217 $(OBJCOPY) -O binary -R .eeprom $< $@
218
219%.eep.hex: %.elf
220 $(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
221
222%.lss: %.elf
223 $(OBJDUMP) -h -S $< > $@
224
225.PHONY: fuses-atmega8-fnordlichtmini-without-bootloader
226
227fuses-atmega8-fnordlichtmini-without-bootloader:
228 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd9:m
229
230-include $(shell $(MKDIR) .dep 2>/dev/null) $(wildcard .dep/*)
Impressum, Datenschutz