]> git.zerfleddert.de Git - fnordlicht-mini/blame - firmware/fnordlicht-firmware/Makefile
fix config.mk file header comment
[fnordlicht-mini] / firmware / fnordlicht-firmware / Makefile
CommitLineData
ec1bef8e 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
ec1bef8e 59
60# avrdude programmer protocol
61PROG = usbasp
62# avrdude programmer device
63DEV = usb
64# further flags for avrdude
65AVRDUDE_FLAGS =
66
67CFLAGS += -DHARDWARE_$(HARDWARE)=1 -DCONFIG_SCRIPT_DEFAULT=$(CONFIG_SCRIPT_DEFAULT)
68CFLAGS += -DCONFIG_SCRIPT=$(CONFIG_SCRIPT) -DCONFIG_SERIAL=$(CONFIG_SERIAL)
69CFLAGS += -DCONFIG_REMOTE=$(CONFIG_REMOTE) -DCONFIG_SECONDARY_PWM=$(CONFIG_SECONDARY_PWM)
70CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
ec1bef8e 71
72####################################################
73# 'make' configuration
74####################################################
75CC = avr-gcc
76OBJCOPY = avr-objcopy
77OBJDUMP = avr-objdump
78AS = avr-as
79SIZE = avr-size
80CP = cp
81RM = rm -f
82RMDIR = rm -rf
83MKDIR = mkdir
84AVRDUDE = avrdude
85
86# flags for automatic dependency handling
87DEPFLAGS = -MD -MP -MF .dep/$(@F).d
88
89# flags for the compiler (for .c files)
90CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
91CFLAGS += $(addprefix -I,$(INCLUDES))
92# optimize for size
93CFLAGS += -mcall-prologues
94CFLAGS += --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions
95CFLAGS += -Wl,--relax
96CFLAGS += -fno-split-wide-types
97
98# place each function in an own section and do garbage collection
99CFLAGS += -ffunction-sections -fdata-sections
100CFLAGS += -Wl,--gc-sections
101
102# flags for the compiler (for .S files)
103ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
104ASFLAGS += $(addprefix -I,$(INCLUDES))
105
106# flags for the linker
107LDFLAGS += -mmcu=$(MCU)
108
109# fill in object files
110OBJECTS += $(SRC:.c=.o)
111OBJECTS += $(ASRC:.S=.o)
112
113.PHONY: all
114
115# main make target (moved up here because of the config.mk target)
116all: $(TARGET).hex $(TARGET).bin
117
118# create config.mk (if it does not exist yet)
119$(CURDIR)/config.mk:
120 @$(CP) config.mk.template config.mk
121 @echo "===================================================="
122 @echo "created file $@"
123 @echo 'please tune your settings (especially $$HARDWARE)'
124 @echo "there, then run 'make' again"
125 @echo "===================================================="
126 @exit 1
127
128# include config file
129-include $(CURDIR)/config.mk
130
131# include more debug flags, if $(DEBUG) is 1
132ifeq ($(DEBUG),1)
133 CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes
134 CFLAGS += -Wmissing-declarations -Wredundant-decls
135 CFLAGS += -Wstrict-prototypes -Wshadow -Wbad-function-cast
136 CFLAGS += -Winline -Wpointer-arith -Wsign-compare
137 CFLAGS += -Wunreachable-code -Wdisabled-optimization
138 CFLAGS += -Wcast-align -Wwrite-strings -Wnested-externs -Wundef
139 CFLAGS += -Wa,-adhlns=$(basename $@).lst
140 CFLAGS += -DCONFIG_DEBUG=1
141endif
142
143####################################################
144# avrdude configuration
145####################################################
146ifeq ($(MCU),atmega8)
147 AVRDUDE_MCU=m8
148endif
149ifeq ($(MCU),atmega48)
150 AVRDUDE_MCU=m48
151endif
152ifeq ($(MCU),atmega88)
153 AVRDUDE_MCU=m88
154endif
155ifeq ($(MCU),atmega168)
156 AVRDUDE_MCU=m168
157endif
158
159AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
160
161####################################################
162# make targets
163####################################################
164
165.PHONY: hardware-check clean distclean avrdude-terminal
166
167# check if HARDWARE is set
168hardware-check:
169ifeq ($(HARDWARE),)
170 @echo 'please edit config.mk and set $$HARDWARE'
171 @exit 1
172endif
173
174$(TARGET).elf: hardware-check $(OBJECTS)
175 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
176
177# all objects (.o files) and config.mk
178$(OBJECTS): $(HEADERS) config.mk
179
180# remove all compiled files
181clean:
182 $(RM) $(foreach ext,elf hex eep.hex bin map,$(TARGET).$(ext)) \
183 $(foreach file,$(patsubst %.o,%,$(OBJECTS)),$(foreach ext,o lst lss,$(file).$(ext)))
184
185# additionally remove the dependency makefile and config.mk
186distclean: clean
187 $(RMDIR) .dep
188 $(RM) config.mk
189
190# avrdude-related targets
191install program: program-$(TARGET)
192
193avrdude-terminal:
194 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
195
196program-%: %.hex
197 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$<
198
06e73f09 199program-eeprom-%: %.eep.bincs
200 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U eeprom:w:$<:r
ec1bef8e 201
202# special programming targets
203%.hex: %.elf
204 $(OBJCOPY) -O ihex -R .eeprom $< $@
205 @echo "===================================================="
206 @echo "$@ compiled for hardware: $(HARDWARE)"
207 @echo "using controller $(MCU)"
208 @echo -n "size for $< is "
209 @$(SIZE) -A $@ | grep '\.sec1' | tr -s ' ' | cut -d" " -f2
210 @echo "===================================================="
211
212# special programming targets
213%.bin: %.elf
214 $(OBJCOPY) -O binary -R .eeprom $< $@
215
216%.eep.hex: %.elf
217 $(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
218
e658ca23 219NODEID ?= 1
220
06e73f09 221%.bincs: %.bin
e658ca23 222 ../tools/patcheeprom $(NODEID) < $< > $@
06e73f09 223
185257f0 224%.eep.bin: %.elf
225 $(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O binary -j .eeprom $< $@
226
ec1bef8e 227%.lss: %.elf
228 $(OBJDUMP) -h -S $< > $@
229
35e64c00 230.PHONY: fuses
ec1bef8e 231
35e64c00
MG
232fuses:
233 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd1:m
ec1bef8e 234
235-include $(shell $(MKDIR) .dep 2>/dev/null) $(wildcard .dep/*)
Impressum, Datenschutz