Commit | Line | Data |
---|---|---|
54de37bf | 1 | |
f12652df | 2 | ####################################### |
54de37bf | 3 | |
f12652df PH |
4 | HW?=trennfix_0.4 |
5 | PROG?=smokefix | |
54de37bf | 6 | |
f12652df | 7 | ####################################### |
54de37bf | 8 | |
54de37bf | 9 | |
f12652df PH |
10 | ####################################### |
11 | # VERBOSITY CONTROL | |
12 | ifeq ($(V),) | |
13 | Q=@ | |
14 | else | |
15 | Q= | |
16 | endif | |
54de37bf | 17 | |
f12652df PH |
18 | include mk/hw/${HW}.mk |
19 | include mk/prog/*.mk | |
54de37bf | 20 | |
f12652df PH |
21 | INCLUDES+=-I mm/include -I include -I. |
22 | CFLAGS+=-D__HW_CONF_HEADER__="<config/${CONFIG}.h>" | |
54de37bf | 23 | |
f12652df PH |
24 | CFLAGS += -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL |
25 | CFLAGS += -std=gnu99 | |
54de37bf PH |
26 | CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
27 | CFLAGS += -Wall -Wstrict-prototypes | |
f12652df | 28 | CFLAGS += -Os -gdwarf-2 |
54de37bf | 29 | CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
f12652df | 30 | CFLAGS += -MD $(@:.c:.d) |
93cb14d4 | 31 | CFLAGS += $(INCLUDES) |
54de37bf | 32 | |
f12652df PH |
33 | ASFLAGS += -Wa,-adhlns=$(<:.S=.lst),-gstabs -mmcu=$(MCU) |
34 | ASFLAGS += -x assembler-with-cpp | |
54de37bf PH |
35 | |
36 | #---------------- Library Options ---------------- | |
37 | # Minimalistic printf version | |
38 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min | |
39 | ||
40 | # Floating point printf version (requires MATH_LIB = -lm below) | |
41 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt | |
42 | ||
43 | # If this is left blank, then it will use the Standard printf version. | |
44 | PRINTF_LIB = | |
45 | #PRINTF_LIB = $(PRINTF_LIB_MIN) | |
46 | #PRINTF_LIB = $(PRINTF_LIB_FLOAT) | |
47 | ||
54de37bf PH |
48 | # Minimalistic scanf version |
49 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min | |
50 | ||
51 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) | |
52 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt | |
53 | ||
54 | # If this is left blank, then it will use the Standard scanf version. | |
55 | SCANF_LIB = | |
56 | #SCANF_LIB = $(SCANF_LIB_MIN) | |
57 | #SCANF_LIB = $(SCANF_LIB_FLOAT) | |
58 | ||
f12652df PH |
59 | LDFLAGS = -Wl,-Map=$(@:.elf=.map),--cref |
60 | LIBS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) | |
54de37bf PH |
61 | |
62 | #---------------- Programming Options (avrdude) ---------------- | |
63 | ||
64 | # Programming hardware: alf avr910 avrisp bascom bsd | |
65 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 | |
66 | # | |
67 | # Type: avrdude -c ? | |
68 | # to get a full listing. | |
69 | # | |
54de37bf PH |
70 | AVRDUDE_PROGRAMMER ?= avrisp2 |
71 | ||
54de37bf PH |
72 | # com1 = serial port. Use lpt1 to connect to parallel port. |
73 | AVRDUDE_PORT ?= usb | |
74 | ||
54de37bf PH |
75 | AVRDUDE_WRITE_FUSES = -U lfuse:w:${LFUSE}:m -U hfuse:w:${HFUSE}:m \ |
76 | -U efuse:w:${EFUSE}:m | |
77 | ||
78 | # Uncomment the following if you want avrdude's erase cycle counter. | |
79 | # Note that this counter needs to be initialized first using -Yn, | |
80 | # see avrdude manual. | |
81 | #AVRDUDE_ERASE_COUNTER = -y | |
82 | ||
83 | # Uncomment the following if you do /not/ wish a verification to be | |
84 | # performed after programming the device. | |
85 | # AVRDUDE_NO_VERIFY = -V | |
86 | ||
87 | # Increase verbosity level. Please use this when submitting bug | |
88 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> | |
89 | # to submit bug reports. | |
90 | #AVRDUDE_VERBOSE = -v -v | |
91 | ||
92 | AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) | |
93 | AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) | |
94 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) | |
95 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) | |
f12652df | 96 | AVRDUDE_FLAGS += -B 5 |
54de37bf PH |
97 | |
98 | # Define programs and commands. | |
99 | SHELL = sh | |
100 | CC = avr-gcc | |
101 | OBJCOPY = avr-objcopy | |
102 | OBJDUMP = avr-objdump | |
103 | SIZE = avr-size | |
104 | NM = avr-nm | |
105 | AVRDUDE = avrdude | |
f12652df | 106 | RM = rm -rf |
54de37bf | 107 | |
f12652df PH |
108 | define SELECT_DEFAULT_template = |
109 | elf: $(1).elf | |
110 | hex: $(1).hex | |
111 | eep: $(1).eep | |
112 | lss: $(1).lss | |
113 | sym: $(1).sym | |
114 | clean: $(1)_clean | |
115 | build: $(1)_build | |
116 | program: $(1)_program | |
117 | fuses: $(1)_fuses | |
118 | endef | |
54de37bf | 119 | |
f12652df | 120 | all: build |
54de37bf | 121 | |
f12652df PH |
122 | cleanall: $(foreach prog, $(PROGRAMS), $(prog)_clean) |
123 | buildall: $(foreach prog, $(PROGRAMS), $(prog)_build) | |
54de37bf | 124 | |
f12652df | 125 | .PHONY: clean build program cleanall buildall all |
54de37bf | 126 | |
f12652df | 127 | $(eval $(call SELECT_DEFAULT_template, $(PROG))) |
54de37bf PH |
128 | |
129 | # Create final output files (.hex, .eep) from ELF output file. | |
130 | %.hex: %.elf | |
f12652df PH |
131 | @echo HEX $@ |
132 | $(Q)$(OBJCOPY) -O ihex -R .fuse -R .eeprom $< $@ | |
54de37bf PH |
133 | |
134 | %.eep: %.elf | |
f12652df PH |
135 | @echo EEP $@ |
136 | $(Q)$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ | |
137 | --change-section-lma .eeprom=0 -O ihex $< $@ | |
54de37bf PH |
138 | |
139 | # Create extended listing file from ELF output file. | |
140 | %.lss: %.elf | |
f12652df PH |
141 | @echo LSS $@ |
142 | $(Q)$(OBJDUMP) -h -S $< > $@ | |
54de37bf PH |
143 | |
144 | # Create a symbol table from ELF output file. | |
145 | %.sym: %.elf | |
f12652df PH |
146 | @echo SYM $@ |
147 | $(Q)$(NM) -n $< > $@ | |
54de37bf PH |
148 | |
149 | # Link: create ELF output file from object files. | |
54de37bf | 150 | %.elf: $(OBJ) |
f12652df PH |
151 | @echo LD $@ |
152 | $(Q)$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | |
54de37bf PH |
153 | |
154 | # Compile: create object files from C source files. | |
155 | %.o : %.c Makefile | |
f12652df PH |
156 | @echo CC $@ |
157 | $(Q)$(CC) -c $(CFLAGS) $< -o $@ | |
54de37bf PH |
158 | |
159 | # Compile: create assembler files from C source files. | |
160 | %.s : %.c Makefile | |
f12652df PH |
161 | @echo CC-ASM $< |
162 | $(Q)$(CC) -S $(CFLAGS) $< -o $@ | |
54de37bf PH |
163 | |
164 | # Assemble: create object files from assembler source files. | |
165 | %.o : %.S | |
f12652df PH |
166 | @echo ASM $@ |
167 | $(Q)$(CC) -c $(ASFLAGS) $< -o $@ | |
54de37bf | 168 | |
f12652df PH |
169 | ########################### The big template for each program ################## |
170 | define PROGRAM_template= | |
54de37bf | 171 | |
f12652df PH |
172 | # Determine program's object files |
173 | $(1)_OBJS=$$($(1)_SRC:.c=.o) | |
174 | $(1)_OBJS+=$$($(1)_ASRC:.S=.o) | |
54de37bf | 175 | |
f12652df PH |
176 | # Collect all listing files - for cleanup |
177 | $(1)_LST += $$($(1)_SRC:.c=.lst) $$($(1)_ASRC:.S=.lst) | |
54de37bf | 178 | |
f12652df PH |
179 | $(1): $(1).elf |
180 | $(1).elf: $$($(1)_OBJS) | |
54de37bf | 181 | |
f12652df PH |
182 | $(1)_program : $(1).hex $(1).eep |
183 | @echo PROG $(1) | |
184 | $(Q)$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(1).hex -U eeprom:w:$(1).eep | |
54de37bf | 185 | |
f12652df PH |
186 | $(1)_unfug: |
187 | @echo UNFUG $$@ | |
54de37bf | 188 | |
f12652df PH |
189 | $(1)_fuses.bin: $(1).elf |
190 | @echo OBJCOPY $$@ | |
191 | $(Q)$(OBJCOPY) -j .fuse $(1).elf -O binary $$@ | |
192 | $(Q)chmod -x $$@ | |
54de37bf | 193 | |
f12652df PH |
194 | $(1)_fuses: $(1)_fuses.bin |
195 | @echo FUSES $$@ | |
196 | $(Q)$(AVRDUDE) $(AVRDUDE_FLAGS)\ | |
197 | -U lfuse:w:0x$$$$(hd $(1)_fuses.bin| awk '{print $$$$2}'):m \ | |
198 | -U hfuse:w:0x$$$$(hd $(1)_fuses.bin| awk '{print $$$$3}'):m \ | |
199 | -U efuse:w:0x$$$$(hd $(1)_fuses.bin| head -n1 |awk '{print $$$$4}'):m | |
54de37bf | 200 | |
f12652df PH |
201 | $(1)_size: $(1).elf |
202 | @echo; echo | |
203 | $(Q) $(SIZE) -A $(1).elf | |
54de37bf | 204 | |
f12652df PH |
205 | # Target: clean project. |
206 | $(1)_clean: | |
207 | @echo CLEAN $(1) | |
208 | $(Q)$(RM) $(1).hex | |
209 | $(Q)$(RM) $(1).eep | |
210 | $(Q)$(RM) $(1).cof | |
211 | $(Q)$(RM) $(1).elf | |
212 | $(Q)$(RM) $(1).map | |
213 | $(Q)$(RM) $(1).sym | |
214 | $(Q)$(RM) $(1).lss | |
215 | $(Q)$(RM) $$($(1)_OBJS) | |
216 | $(Q)$(RM) $$($(1)_LST) | |
217 | $(Q)$(RM) $$($(1)_SRC:.c=.s) | |
218 | $(Q)$(RM) $$($(1)_SRC:.c=.d) | |
219 | @$(Q)$(RM) $(1)_fuses.bin | |
220 | ||
221 | $(1)_build: $(1).hex $(1)_size | |
222 | ||
223 | -include $$($(1)_OBJS:.o=.d) | |
224 | ||
225 | .PRECIOUS : $$($(1)_OBJS) | |
226 | .PHONY: $(1) $(1)_clean $(1)_size $(1)_build | |
227 | ||
228 | ############# | |
229 | endef | |
230 | ################################################################################ | |
231 | ||
232 | $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog)))) |