]> git.zerfleddert.de Git - fnordlicht-mini/blame - firmware/fnordlicht-controller/Makefile
add docs, remove stuff
[fnordlicht-mini] / firmware / fnordlicht-controller / 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# controller
12MCU = atmega168
13
14# frequency
15F_CPU = 16000000UL
16
17# main application name (without .hex)
18# eg 'test' when the main function is defined in 'test.c'
19TARGET = fcontrol
20
21# c sourcecode files
22# eg. 'test.c foo.c foobar/baz.c'
23SRC = $(wildcard *.c) usbdrv/usbdrv.c
24
25# asm sourcecode files
26# eg. 'interrupts.S foobar/another.S'
27ASRC = $(wildcard *.S) usbdrv/usbdrvasm.S
28
29# headers which should be considered when recompiling
30# eg. 'global.h foobar/important.h'
31HEADERS = $(wildcard *.h)
32
33# include directories (used for both, c and asm)
34# eg '. usbdrv/'
35INCLUDES = . usbdrv/
36
37
38# use more debug-flags when compiling
39DEBUG = 0
40
41# default baudrate
42CONFIG_SERIAL_BAUDRATE = 19200
43
44# avrdude programmer protocol
45PROG = usbasp
46# avrdude programmer device
47DEV = usb
48# further flags for avrdude
49AVRDUDE_FLAGS =
50
51CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
52
53# use a custom linker script
54LDFLAGS += -L$(CURDIR)/ldscripts
55
56.PHONY: all
57
58# main make target (moved up here because of the config.mk target)
59all: $(TARGET).hex
60
61# create config.mk (if it does not exist yet)
62$(CURDIR)/config.mk:
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 "===================================================="
68 @exit 1
69
70# include config file
71-include $(CURDIR)/config.mk
72
73####################################################
74# 'make' configuration
75####################################################
76CC = avr-gcc
77OBJCOPY = avr-objcopy
78OBJDUMP = avr-objdump
79AS = avr-as
80SIZE = avr-size
81CP = cp
82RM = rm -f
83RMDIR = rm -rf
84MKDIR = mkdir
85AVRDUDE = avrdude
86
87# flags for automatic dependency handling
88DEPFLAGS = -MD -MP -MF .dep/$(@F).d
89
90# flags for the compiler (for .c files)
91CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
92CFLAGS += $(addprefix -I,$(INCLUDES))
93CFLAGS += -fno-split-wide-types
94CFLAGS += --param inline-call-cost=2 -finline-limit=3 -fno-inline-small-functions
95#CFLAGS += -Wl,--relax
96
97# flags for the compiler (for .S files)
98ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
99ASFLAGS += $(addprefix -I,$(INCLUDES))
100
101# flags for the linker
102LDFLAGS += -mmcu=$(MCU)
103
104# fill in object files
105OBJECTS += $(SRC:.c=.o)
106OBJECTS += $(ASRC:.S=.o)
107
108# include more debug flags, if $(DEBUG) is 1
109ifeq ($(DEBUG),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
118endif
119
120####################################################
121# avrdude configuration
122####################################################
123ifeq ($(MCU),atmega8)
124 AVRDUDE_MCU=m8
125endif
126ifeq ($(MCU),atmega48)
127 AVRDUDE_MCU=m48
128endif
129ifeq ($(MCU),atmega88)
130 AVRDUDE_MCU=m88
131endif
132ifeq ($(MCU),atmega168)
133 AVRDUDE_MCU=m168
134endif
135
136AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
137
138####################################################
139# make targets
140####################################################
141
142.PHONY: clean distclean avrdude-terminal
143
144$(TARGET).elf: $(OBJECTS)
145 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
146
147# all objects (.o files) and config.mk
148$(OBJECTS): $(HEADERS) config.mk
149
150# remove all compiled files
151clean:
152 $(RM) $(foreach ext,elf hex eep.hex map,$(TARGET).$(ext)) \
153 $(foreach file,$(patsubst %.o,%,$(OBJECTS)),$(foreach ext,o lst lss,$(file).$(ext)))
154
155# additionally remove the dependency makefile and config.mk
156distclean: clean
157 $(RMDIR) .dep
158 $(RM) config.mk
159
160# avrdude-related targets
161install program: program-$(TARGET)
162
163avrdude-terminal:
164 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
165
166program-%: %.hex
167 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$<
168
169program-eeprom-%: %.eep.hex
170 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U eeprom:w:$<
171
172# special programming targets
173%.hex: %.elf
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 "===================================================="
181
182%.eep.hex: %.elf
183 $(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
184
185%.lss: %.elf
186 $(OBJDUMP) -h -S $< > $@
187
188.PHONY: fuses-atmega8-fnordlichtmini-with-bootloader fuses-lock
189
190fuses-atmega8-fnordlichtmini-with-bootloader:
191 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xda:m
192
193fuses-atmega8-fnordlichtmini-without-bootloader:
194 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd9:m
195
196fuses-lock:
197 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lock:w:0x2f:m
198
199-include $(shell $(MKDIR) .dep 2>/dev/null) $(wildcard .dep/*)
Impressum, Datenschutz