~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to Flintrock/bistro-hd/Makefile

  • Committer: Selene Scriven
  • Date: 2014-07-24 06:46:30 UTC
  • Revision ID: ubuntu@toykeeper.net-20140724064630-k1fk2o5ppso2owhj
Started adding contributions from DrJones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#Makefile for bistro-HD,  
2
 
# Flintrock 2017 (with some contributions from atmel studio), GPLV3 I suppose, whatever, basically I don't care.
3
 
#
4
 
 
5
 
#### Define where your custom firmware configurations are ############
6
 
CONFIG_DIR := configs
7
 
 
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
11
 
 
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
20
 
FIRMWARES45 += 
21
 
FIRMWARES85 +=
22
 
FIRMWARES := $(FIRMWARES13) $(FIRMWARES25) $(FIRMWARES45) $(FIRMWARES85)
23
 
 
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
34
 
 
35
 
#Uncomment next to skip battcheck builds, speeds things up a bit:
36
 
#NO_BATTCHECK
37
 
 
38
 
########### Define where your compiling programs live #####################
39
 
 
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/
45
 
 
46
 
else
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
50
 
 
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.
55
 
 
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..
59
 
endif
60
 
 
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
64
 
 
65
 
PACKAGE_DIR := C:\firmware\HD
66
 
7ZIP := C:\Program Files\7-Zip\7z.exe
67
 
 
68
 
 
69
 
#############################You probably don't need to edit below here##############################
70
 
 
71
 
ifneq ($(OS),Windows_NT)
72
 
  EXE:=
73
 
else
74
 
  SHELL := cmd.exe
75
 
  EXE:=.exe
76
 
endif
77
 
 
78
 
############Define the output directories###################
79
 
HEX_DIR := .\hex
80
 
PREPROCESS_DIR := .\Preprocessor-output
81
 
# where the .elf files go, just left around for size determination:
82
 
BIN_DIR := .\bin
83
 
 
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)
89
 
 
90
 
 
91
 
# The following seems uneccessary
92
 
#SPECDIR := C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\
93
 
 
94
 
##########Compiler Options##################
95
 
 
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
101
 
 
102
 
#### define groups of attinys based on minimum capability ###
103
 
 
104
 
ATTINYS13 := 13 25 45 85
105
 
ATTINYS25 := 25 45 85
106
 
ATTINYS45 := 45 85
107
 
ATTINYS85 := 85
108
 
 
109
 
 
110
 
#construct combinations of firmwares and attinys to build.
111
 
 
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)
117
 
 
118
 
ifdef ONE_BUILD
119
 
# override build list
120
 
 BUILDS := $(ONE_BUILD)
121
 
endif
122
 
 
123
 
ALLBUILDS := $(BUILDS)
124
 
 
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)
128
 
 
129
 
ifndef NO_BATTCHECK
130
 
 ALLBUILDS += $(BATTCHECK_BUILDS)
131
 
endif
132
 
 
133
 
#$(TARGETS:%.hex=.o)
134
 
#       C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe 
135
 
 
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: $@
142
 
 
143
 
 
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: $@
152
 
 
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: $@
160
 
 
161
 
 
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
169
 
        mv temp.txt $@
170
 
        @echo Finished building: $@
171
 
 
172
 
#phony target that does nothing.
173
 
#$(BATTCHECK_PREPROC):;
174
 
 
175
 
 
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
182
 
%.hex: %.o %.i
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"
197
 
        cp $@ $(HEX_DIR)
198
 
        cp $(@:%.hex=%.i) $(PREPROCESS_DIR) || exit 0
199
 
        cp $(@:%.hex=%.elf) $(BIN_DIR) || exit 0
200
 
        @echo Finished building target: $@
201
 
 
202
 
# Need to force the order, can't just use prerequisites.
203
 
all: 
204
 
        make clean 
205
 
        make $(ALLBUILDS) 
206
 
        make tidy 
207
 
        make sizes 
208
 
 
209
 
#tidy cleans everything but the copied hex:
210
 
tidy: 
211
 
        @rm -f *.o || exit 0
212
 
        @rm -f *.i *.hex *.elf *.lss *.eep *.map *.srec *.usersignatures || exit 0
213
 
        
214
 
packit:
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
220
 
 
221
 
#clean does tidy and removes the hex
222
 
clean:  tidy
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
227
 
 
228
 
sizes: 
229
 
        "$(AVR_SIZE)" $(BIN_DIR)/*.elf 
230
 
 
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.
234
 
 
235
 
nothing:;
236
 
 
237
 
.PHONY:tidy sizes $(BATTCHECK_PREPROC) packit nothing
238