]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-controller/Makefile
remove master mode, disable uart tx
[fnordlicht-mini] / firmware / fnordlicht-controller / Makefile
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
12 MCU = atmega168
13
14 # frequency
15 F_CPU = 16000000UL
16
17 # main application name (without .hex)
18 # eg 'test' when the main function is defined in 'test.c'
19 TARGET = fcontrol
20
21 # c sourcecode files
22 # eg. 'test.c foo.c foobar/baz.c'
23 SRC = $(wildcard *.c) usbdrv/usbdrv.c
24
25 # asm sourcecode files
26 # eg. 'interrupts.S foobar/another.S'
27 ASRC = $(wildcard *.S) usbdrv/usbdrvasm.S
28
29 # headers which should be considered when recompiling
30 # eg. 'global.h foobar/important.h'
31 HEADERS = $(wildcard *.h)
32
33 # include directories (used for both, c and asm)
34 # eg '. usbdrv/'
35 INCLUDES = . usbdrv/
36
37
38 # use more debug-flags when compiling
39 DEBUG = 0
40
41 # default baudrate
42 CONFIG_SERIAL_BAUDRATE = 19200
43
44 # avrdude programmer protocol
45 PROG = usbasp
46 # avrdude programmer device
47 DEV = usb
48 # further flags for avrdude
49 AVRDUDE_FLAGS =
50
51 CFLAGS += -DCONFIG_SERIAL_BAUDRATE=$(CONFIG_SERIAL_BAUDRATE)
52
53 # use a custom linker script
54 LDFLAGS += -L$(CURDIR)/ldscripts
55
56 .PHONY: all
57
58 # main make target (moved up here because of the config.mk target)
59 all: $(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 ####################################################
76 CC = avr-gcc
77 OBJCOPY = avr-objcopy
78 OBJDUMP = avr-objdump
79 AS = avr-as
80 SIZE = avr-size
81 CP = cp
82 RM = rm -f
83 RMDIR = rm -rf
84 MKDIR = mkdir
85 AVRDUDE = avrdude
86
87 # flags for automatic dependency handling
88 DEPFLAGS = -MD -MP -MF .dep/$(@F).d
89
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
96
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))
100
101 # flags for the linker
102 LDFLAGS += -mmcu=$(MCU)
103
104 # fill in object files
105 OBJECTS += $(SRC:.c=.o)
106 OBJECTS += $(ASRC:.S=.o)
107
108 # include more debug flags, if $(DEBUG) is 1
109 ifeq ($(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
118 endif
119
120 ####################################################
121 # avrdude configuration
122 ####################################################
123 ifeq ($(MCU),atmega8)
124 AVRDUDE_MCU=m8
125 endif
126 ifeq ($(MCU),atmega48)
127 AVRDUDE_MCU=m48
128 endif
129 ifeq ($(MCU),atmega88)
130 AVRDUDE_MCU=m88
131 endif
132 ifeq ($(MCU),atmega168)
133 AVRDUDE_MCU=m168
134 endif
135
136 AVRDUDE_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
151 clean:
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
156 distclean: clean
157 $(RMDIR) .dep
158 $(RM) config.mk
159
160 # avrdude-related targets
161 install program: program-$(TARGET)
162
163 avrdude-terminal:
164 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
165
166 program-%: %.hex
167 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$<
168
169 program-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
190 fuses-atmega8-fnordlichtmini-with-bootloader:
191 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xda:m
192
193 fuses-atmega8-fnordlichtmini-without-bootloader:
194 $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U lfuse:w:0x3f:m -U hfuse:w:0xd9:m
195
196 fuses-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