1
#Makefile for bistro-HD,
2
# Flintrock 2017 (with some contributions from atmel studio), GPLV3 I suppose, whatever, basically I don't care.
5
#### Define where your custom firmware configurations are ############
8
###### define firmwares to build based on minimum attiny they can run on#############
9
# Versions for all compatible attiny's will be built unless ONE_BUILD is defined.
10
# These must correspond to config headers named like config_<FIRMWARE-NAME>.h
12
FIRMWARES13 += biscotti-HD
13
# unforutnately BLFA6_EMU doesn't actually fit on an attiny13 yet:
14
#FIRMWARES13 += BLFA6_EMU-HD
15
FIRMWARES25 += BLFA6_EMU-HD
16
FIRMWARES25 += default-HD TAv1-OTC-HD TAv1-OTSM-HD TAv1-OTSM-LDO-HD classic-HD tripledown-HD eswitch-TA-HD
17
FIRMWARES25 += dual-switch-dumbclick-TA-HD dual-switch-noinit-TA-HD dual-switch-turboclick-TA-HD 4channel-dual-switch-HD
18
FIRMWARES25 += dual-switch-OTSM-TA-HD eswitch-Q8-fetplusone-HD TAv1-OTC-NODIVIDER-1SONLY-HD eswitch-TA-VCCREAD-INDICATOR-HD
19
FIRMWARES25 += TAv1-OTSM-LDO-fetonly-HD TAv1-OTSM-fetonly-HD eswitch-TA-FETONLY-VCCREAD-INDICATOR-HD
22
FIRMWARES := $(FIRMWARES13) $(FIRMWARES25) $(FIRMWARES45) $(FIRMWARES85)
24
# Uncomment next to override multiple builds and build one specific file.
25
# Must be named like bistr-<config-name>-attinyXX.hex, where XX is a valid attiny model number.
26
# (Actually can include multiple individual builds per line too or using += )
27
#ONE_BUILD := bistro-biscotti-HD-attiny13.hex
28
#ONE_BUILD := bistro-dual-switch-OTS-attiny25.hex
29
#ONE_BUILD := bistro-TAv1-OTSM-HD-attiny25.hex bistro-4channel-dual-switch-HD-attiny25.hex
30
#ONE_BUILD := bistro-eswitch-TA-HD-attiny25.hex
31
#ONE_BUILD := bistro-BLFA6_EMU-HD-attiny13.hex
32
#ONE_BUILD := bistro-eswitch-Q8-fetplusone-HD-attiny85.hex
33
#ONE_BUILD := bistro-TAv1-OTC-NODIVIDER-1SONLY-HD-attiny25.hex
35
#Uncomment next to skip battcheck builds, speeds things up a bit:
38
########### Define where your compiling programs live #####################
40
ifneq ($(OS),Windows_NT)
41
###For linux using files installed directly into / from Atmel
42
AVR_DIR:=/arduino-1.8.5
43
GCC_DIR:=$(AVR_DIR)/hardware/tools/avr/bin
44
INCLUDES:=$(AVR_DIR)/hardware/tools/avr/avr/
47
###For Atmel studio 7.0:
48
GCC_DIR := C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin
49
INCLUDES := C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include
51
###Or using WinAVR version: 20100110 (the latest version but still works)
52
#GCC_DIR := C:\WinAVR-20100110\bin
53
#INCLUDES := C:\WinAVR-20100110\avr\include\avr
54
# That's more outdated than the atmel version but seems to work.
56
# The next one should work, with atmel's gnu toolchain, available here:http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx
57
#GCC_DIR := C:\avr8-gnu-toolchain\bin
58
#Not sure of the include path..
61
#Files to pack up to copy it all
62
PACKAGE_FILES := bistro-HD.c *.h THE_MANUAL.htm license.txt buildall-AS.bat buildall-WinAVR.bat Makefile configs modegroups hex
63
PACKAGE_FILES += flashany_attiny13.bat flashany_attiny25.bat flashany_attiny45.bat flashany_attiny85.bat clearhexassoc.reg CHANGES.txt
65
PACKAGE_DIR := C:\firmware\HD
66
7ZIP := C:\Program Files\7-Zip\7z.exe
69
#############################You probably don't need to edit below here##############################
71
ifneq ($(OS),Windows_NT)
78
############Define the output directories###################
80
PREPROCESS_DIR := .\Preprocessor-output
81
# where the .elf files go, just left around for size determination:
84
#############Define where all the bits and pieces are #####################
85
GCC := $(GCC_DIR)/avr-gcc$(EXE)
86
OBJ_COPY := $(GCC_DIR)/avr-objcopy$(EXE)
87
OBJ_DUMP := $(GCC_DIR)/avr-objdump$(EXE)
88
AVR_SIZE := $(GCC_DIR)/avr-size$(EXE)
91
# The following seems uneccessary
92
#SPECDIR := C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\
94
##########Compiler Options##################
96
C_FLAGS := -x c -funsigned-char -funsigned-bitfields -Os -finline-functions-called-once
97
C_FLAGS += -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -std=gnu99
98
C_FLAGS += -fverbose-asm
99
LDD_FLAGS := -Wl,--start-group -Wl,--end-group -Wl,--gc-sections
100
#LDD_FLAGS += -Wl,-lm
102
#### define groups of attinys based on minimum capability ###
104
ATTINYS13 := 13 25 45 85
105
ATTINYS25 := 25 45 85
110
#construct combinations of firmwares and attinys to build.
112
BUILDS13 := $(foreach X,$(FIRMWARES13),$(foreach Y,$(ATTINYS13),bistro-$X-attiny$Y.hex))
113
BUILDS25 := $(foreach X,$(FIRMWARES25),$(foreach Y,$(ATTINYS25),bistro-$X-attiny$Y.hex))
114
BUILDS45 := $(foreach X,$(FIRMWARES45),$(foreach Y,$(ATTINYS45),bistro-$X-attiny$Y.hex))
115
BUILDS85 := $(foreach X,$(FIRMWARES85),$(foreach Y,$(ATTINYS45),bistro-$X-attiny$Y.hex))
116
BUILDS := $(BUILDS13) $(BUILDS25) $(BUILDS45) $(BUILDS85)
119
# override build list
120
BUILDS := $(ONE_BUILD)
123
ALLBUILDS := $(BUILDS)
125
BATTCHECK_BUILDS := $(BUILDS:bistro%.hex=battcheck%.hex)
126
# We don't need preprocessor files for battcheck builds, so need a phony target for them.
127
BATTCHECK_PREPROC := $(BUILDS:bistro%.hex=battcheck%.i)
130
ALLBUILDS += $(BATTCHECK_BUILDS)
134
# C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe
136
# A rule to make a generic myprogram.hex from a file myprogram.c
137
# This is not really implemented at the moment. The linker section below still parses the attiny version from the program name anyway.
138
$(PROGRAMS:%.hex=%.o): ./%.c
139
@echo Building file: $@
140
"$(GCC)" -c $(C_FLAGS) -I"$(INCLUDES)" -mmcu=attiny$(ATTINY) -o "$@" -DATTINY=$(ATTINY) "$<"
141
@echo Finished building: $@
144
#These build all the specific firmware-attinyXX.hex combination
145
# removed this: -B "$(SPECDIR)$(MCU)" ... seems uneeded and makes compiling with WinAVR difficult
146
$(BUILDS:%.hex=%.o): ./bistro-HD.c
147
@echo Building file: $@
148
$(eval MCU=$(lastword $(subst -, ,$(basename $@))))
149
$(eval HOWTINY=$(subst attiny,,$(MCU)))
150
"$(GCC)" -c $(C_FLAGS) -I"$(INCLUDES)" -mmcu=$(MCU) -o "$@" -DCONFIG_FILE_H=\"$(CONFIG_DIR)/config_$(@:bistro-%-$(MCU).o=%.h)\" -DATTINY=$(HOWTINY) "$<"
151
@echo Finished building: $@
153
#This makes battcheck versions of each build
154
$(BATTCHECK_BUILDS:%.hex=%.o): ./bistro-HD.c
155
@echo Building file: $@
156
$(eval MCU=$(lastword $(subst -, ,$(basename $@))))
157
$(eval HOWTINY=$(subst attiny,,$(MCU)))
158
"$(GCC)" -c $(C_FLAGS) -I"$(INCLUDES)" -mmcu=$(MCU) -o "$@" -DVOLTAGE_CAL="" -DCONFIG_FILE_H=\"$(CONFIG_DIR)/config_$(@:battcheck-%-$(MCU).o=%.h)\" -DATTINY=$(HOWTINY) "$<"
159
@echo Finished building: $@
162
# removed this: -B "$(SPECDIR)$(MCU)"
163
$(BUILDS:%.hex=%.i): ./bistro-HD.c
164
@echo Building file: $@
165
$(eval MCU=$(lastword $(subst -, ,$(basename $@))))
166
$(eval HOWTINY=$(subst attiny,,$(MCU)))
167
"$(GCC)" -E -P $(C_FLAGS) -I"$(INCLUDES)" -mmcu=$(MCU) -o "$@" -DCONFIG_FILE_H=\"$(CONFIG_DIR)/config_$(@:bistro-%-$(MCU).i=%.h)\" -DATTINY=$(HOWTINY) "$<"
168
cat license.txt $@ > temp.txt
170
@echo Finished building: $@
172
#phony target that does nothing.
173
#$(BATTCHECK_PREPROC):;
176
#This is rule is more more specialized than it appears
177
#It requires a target file with a name basename-attinyXX.hex and parses the attiny version from the target.
178
# specifically the names should be like bistro-<config>-attinyXX.hex
179
# actually this hex builder only requires something-attinyXX.hex so is more general
180
# but the .o file targets above require bistro-<config> or battcheck-<config>
181
#removed -B "$(SPECDIR)/$(MCU)" from gcc line
183
mkdir $(HEX_DIR) || exit 0
184
mkdir $(BIN_DIR) || exit 0
185
mkdir $(PREPROCESS_DIR) || exit 0
186
$(eval MCU=$(lastword $(subst -, ,$(basename $@))))
187
$(eval HOWTINY=$(subst attiny,,$(MCU)))
188
@echo Building target: $@
189
# This part is essentially from atmel's automatic make file, just with abstraction added and the attiny version parsing.
190
"$(GCC)" -o "$(basename $@).elf" "$(basename $@).o" $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="$(basename $@).map" $(LDD_FLAGS) -mmcu=$(MCU)
191
@echo Finished building $(@:%.hex=%.elf)
192
"$(OBJ_COPY)" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "$(basename $@).elf" "$(basename $@).hex"
193
"$(OBJ_COPY)" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "$(basename $@).elf" "$(basename $@).eep" || exit 0
194
"$(OBJ_DUMP)" -h -S "$(basename $@).elf" > $(basename $@).lss
195
"$(OBJ_COPY)" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "$(basename $@).elf" "$(basename $@).srec"
196
# "$(AVR_SIZE)" "$(basename $@).elf"
198
cp $(@:%.hex=%.i) $(PREPROCESS_DIR) || exit 0
199
cp $(@:%.hex=%.elf) $(BIN_DIR) || exit 0
200
@echo Finished building target: $@
202
# Need to force the order, can't just use prerequisites.
209
#tidy cleans everything but the copied hex:
212
@rm -f *.i *.hex *.elf *.lss *.eep *.map *.srec *.usersignatures || exit 0
215
# always good to hard code part of an rm -rf, prevents accidental deletion of whole hard-drive:
216
rm -rf $(PACKAGE_DIR)\bistro-HD || exit 0
217
mkdir $(PACKAGE_DIR)\bistro-HD || exit 0
218
cp -rf $(PACKAGE_FILES) $(PACKAGE_DIR)\bistro-HD
219
$(7ZIP) a -tzip $(PACKAGE_DIR)\bistro-HD.zip $(PACKAGE_DIR)\bistro-HD
221
#clean does tidy and removes the hex
223
rm -f *.hex *.elf *.i *.o || exit 0
224
rm -f $(HEX_DIR)/*.hex || exit 0
225
rm -f $(BIN_DIR)/*.elf || exit 0
226
rm -f $(PREPROCESS_DIR)/*.i || exit 0
229
"$(AVR_SIZE)" $(BIN_DIR)/*.elf
231
#Atmel studio insists on a clean steap, but you can change the target name of it.
232
#Make clean isn't always desirable, if for example you're trying to make packit.
233
#So, a target to do nothing.
237
.PHONY:tidy sizes $(BATTCHECK_PREPROC) packit nothing