Mercurial > hg > beaglert
comparison Makefile @ 548:3980b707634d prerelease
Added makefile command line options
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 24 Jun 2016 04:49:40 +0100 |
parents | d0414ec15f63 |
children | e545ce04cf2c |
comparison
equal
deleted
inserted
replaced
541:c301cc07ae11 | 548:3980b707634d |
---|---|
1 # Bela | 1 # Bela |
2 # Low-latency, real-time audio and sensor processing on BeagleBone Black | 2 # Low-latency, real-time audio and sensor processing on BeagleBone Black |
3 # (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan | 3 # (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan |
4 # Centre for Digital Music, Queen Mary University of London | 4 # Centre for Digital Music, Queen Mary University of London |
5 | 5 |
6 # This Makefile is intended for use on the BeagleBone Black itself | 6 ## This Makefile is intended for use on the BeagleBone Black itself # |
7 # and not for cross-compiling | 7 ## and not for cross-compiling # |
8 | 8 ## available command line options: # |
9 ## EXAMPLE= -- name of the folder in examples/ to be copied to projects/ and built | |
10 ## PROJECT= -- name of the folder in projects/ to be built | |
11 ## CL= -- list of command line options to pass to the program when running | |
12 ## INCLUDES= -- list of additional include paths to pass to the compiler | |
13 ## CPP_FLAGS= -- list of additional flags passed to the C++ compiler | |
14 ## C_FLAGS= -- list of additional flags passed to the C compiler | |
15 ## COMPILER= -- compiler to use (clang or gcc) | |
16 ## LIBS= -- libs to link in | |
17 ## AT= -- used instead of @ to silence the output. Defaults AT=@, use AT= for a very verbose output | |
18 ### | |
19 ##available targets: # | |
9 .DEFAULT_GOAL := Bela | 20 .DEFAULT_GOAL := Bela |
10 | 21 |
22 AT?=@ | |
11 NO_PROJECT_TARGETS=help coreclean distclean stop nostartup idestart idestop idestartup idenostartup connect ideconnect update checkupdate updateunsafe | 23 NO_PROJECT_TARGETS=help coreclean distclean stop nostartup idestart idestop idestartup idenostartup connect ideconnect update checkupdate updateunsafe |
12 NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS) | 24 NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS) |
13 # list of targets that automatically activate the QUIET=true flag | 25 # list of targets that automatically activate the QUIET=true flag |
14 QUIET_TARGETS=runide | 26 QUIET_TARGETS=runide |
15 | 27 |
16 # Type `$ make help` to get a description of the functionalities of this Makefile. | 28 # Type `$ make help` to get a description of the functionalities of this Makefile. |
17 help: ## Show this help | 29 help: ## Show this help |
18 @echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]' | 30 $(AT) echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]' |
19 @printf "\n$(NO_PROJECT_TARGETS_MESSAGE)\n\n" | 31 $(AT) printf "\n$(NO_PROJECT_TARGETS_MESSAGE)\n\n" |
20 @echo 'Targets: (default: $(.DEFAULT_GOAL))' | 32 $(AT) echo 'Targets: (default: $(.DEFAULT_GOAL))' |
21 @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | column -t -c 2 -s '#' | 33 $(AT) echo list: $(MAKEFILE_LIST) |
34 $(AT) fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | sed -e 's/^\(.*\)= .* -- \(.*\)/\1=#\2/' | sed 's/^##//' | awk -F"#" '{ printf "%-18s %-1s\n", $$1, $$2}' | |
22 | 35 |
23 # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS | 36 # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS |
24 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS))) | 37 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS))) |
25 ifndef PROJECT | 38 ifndef PROJECT |
26 ifndef EXAMPLE | 39 ifndef EXAMPLE |
66 endif | 79 endif |
67 QUIET?=false | 80 QUIET?=false |
68 | 81 |
69 RM := rm -rf | 82 RM := rm -rf |
70 STATIC_LIBS := ./libprussdrv.a ./libNE10.a | 83 STATIC_LIBS := ./libprussdrv.a ./libNE10.a |
71 LIBS := -lrt -lnative -lxenomai -lsndfile | 84 override LIBS += -lrt -lnative -lxenomai -lsndfile |
72 | 85 |
73 # refresh library cache and check if libpd is there | 86 # refresh library cache and check if libpd is there |
74 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking | 87 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking |
75 LIBPD_PATH = /usr/lib/libpd.so | 88 LIBPD_PATH = /usr/lib/libpd.so |
76 TEST_LIBPD := $(shell which $(LIBPD_PATH)) | 89 TEST_LIBPD := $(shell which $(LIBPD_PATH)) |
77 ifneq ($(strip $(TEST_LIBPD)), ) | 90 ifneq ($(strip $(TEST_LIBPD)), ) |
78 # if libpd is there, link it in | 91 # if libpd is there, link it in |
79 LIBS += -lpd -lpthread_rt | 92 LIBS += -lpd -lpthread_rt |
80 endif | 93 endif |
81 | 94 DEFAULT_CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize |
82 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize | 95 override CPP_FLAGS := $(DEFAULT_CPP_FLAGS) $(CPP_FLAGS) |
83 C_FLAGS := $(CPP_FLAGS) | 96 override C_FLAGS := $(DEFAULT_CPP_FLAGS) $(C_FLAGS) |
97 | |
84 | 98 |
85 ifndef COMPILER | 99 ifndef COMPILER |
86 # check whether clang is installed | 100 # check whether clang is installed |
87 TEST_COMPILER := $(shell which clang) | 101 TEST_COMPILER := $(shell which clang) |
88 ifneq ($(strip $(TEST_COMPILER)), ) | 102 ifneq ($(strip $(TEST_COMPILER)), ) |
96 ifeq ($(COMPILER), clang) | 110 ifeq ($(COMPILER), clang) |
97 CC=clang | 111 CC=clang |
98 CXX=clang++ | 112 CXX=clang++ |
99 CPP_FLAGS += -DNDEBUG | 113 CPP_FLAGS += -DNDEBUG |
100 C_FLAGS += -DNDEBUG | 114 C_FLAGS += -DNDEBUG |
101 else | 115 else |
102 CC=gcc | 116 ifeq ($(COMPILER), gcc) |
103 CXX=g++ | 117 CC=gcc |
104 CPP_FLAGS += --fast-math | 118 CXX=g++ |
105 C_FLAGS += --fast-math | 119 CPP_FLAGS += --fast-math |
106 endif | 120 C_FLAGS += --fast-math |
107 | 121 endif |
108 INCLUDES := -I$(PROJECT_DIR) -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 | 122 endif |
123 | |
124 DEFAULT_INCLUDES := -I$(PROJECT_DIR) -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 | |
125 override INCLUDES += $(DEFAULT_INCLUDES) | |
109 | 126 |
110 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S) | 127 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S) |
111 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o))) | 128 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o))) |
112 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d))) | 129 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d))) |
113 | 130 |
162 syntax: SYNTAX_FLAG := -fsyntax-only | 179 syntax: SYNTAX_FLAG := -fsyntax-only |
163 syntax: $(PROJECT_OBJS) | 180 syntax: $(PROJECT_OBJS) |
164 | 181 |
165 # Rule for Bela core C++ files | 182 # Rule for Bela core C++ files |
166 build/core/%.o: ./core/%.cpp | 183 build/core/%.o: ./core/%.cpp |
167 @echo 'Building $(notdir $<)...' | 184 $(AT) echo 'Building $(notdir $<)...' |
168 # @echo 'Invoking: C++ Compiler $(CXX)' | 185 # $(AT) echo 'Invoking: C++ Compiler $(CXX)' |
169 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" | 186 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" |
170 @echo ' ...done' | 187 $(AT) echo ' ...done' |
171 @echo ' ' | 188 $(AT) echo ' ' |
172 | 189 |
173 # Rule for Bela core ASM files | 190 # Rule for Bela core ASM files |
174 build/core/%.o: ./core/%.S | 191 build/core/%.o: ./core/%.S |
175 @echo 'Building $(notdir $<)...' | 192 $(AT) echo 'Building $(notdir $<)...' |
176 # @echo 'Invoking: GCC Assembler' | 193 # $(AT) echo 'Invoking: GCC Assembler' |
177 @as -o "$@" "$<" | 194 $(AT) as -o "$@" "$<" |
178 @echo ' ...done' | 195 $(AT) echo ' ...done' |
179 @echo ' ' | 196 $(AT) echo ' ' |
180 | 197 |
181 # Rule for user-supplied C++ files | 198 # Rule for user-supplied C++ files |
182 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp | 199 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp |
183 @echo 'Building $(notdir $<)...' | 200 $(AT) echo 'Building $(notdir $<)...' |
184 # @echo 'Invoking: C++ Compiler $(CXX)' | 201 # $(AT) echo 'Invoking: C++ Compiler $(CXX)' |
185 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" | 202 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" |
186 @echo ' ...done' | 203 $(AT) echo ' ...done' |
187 @echo ' ' | 204 $(AT) echo ' ' |
188 | 205 |
189 # Rule for user-supplied C files | 206 # Rule for user-supplied C files |
190 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c | 207 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c |
191 @echo 'Building $(notdir $<)...' | 208 $(AT) echo 'Building $(notdir $<)...' |
192 # @echo 'Invoking: C Compiler $(CC)' | 209 # $(AT) echo 'Invoking: C Compiler $(CC)' |
193 @$(CC) $(SYNTAX_FLAG) $(INCLUDES) $(C_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 | 210 $(AT) $(CC) $(SYNTAX_FLAG) $(INCLUDES) $(C_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 |
194 @echo ' ...done' | 211 $(AT) echo ' ...done' |
195 @echo ' ' | 212 $(AT) echo ' ' |
196 | 213 |
197 # Rule for user-supplied assembly files | 214 # Rule for user-supplied assembly files |
198 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S | 215 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S |
199 @echo 'Building $(notdir $<)...' | 216 $(AT) echo 'Building $(notdir $<)...' |
200 # @echo 'Invoking: GCC Assembler' | 217 # $(AT) echo 'Invoking: GCC Assembler' |
201 @as -o "$@" "$<" | 218 $(AT) as -o "$@" "$<" |
202 @echo ' ...done' | 219 $(AT) echo ' ...done' |
203 @echo ' ' | 220 $(AT) echo ' ' |
204 | 221 |
205 # This is a nasty kludge: we want to be able to optionally link in a default | 222 # This is a nasty kludge: we want to be able to optionally link in a default |
206 # main file if the user hasn't supplied one. We check for the presence of the main() | 223 # main file if the user hasn't supplied one. We check for the presence of the main() |
207 # function, and conditionally call one of two recursive make targets depending on whether | 224 # function, and conditionally call one of two recursive make targets depending on whether |
208 # we want to link in the default main file or not. The kludge is the mess of a shell script | 225 # we want to link in the default main file or not. The kludge is the mess of a shell script |
209 # line below. Surely there's a better way to do this? | 226 # line below. Surely there's a better way to do this? |
210 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_PD_OBJS) | 227 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_PD_OBJS) |
211 $(eval DEFAULT_MAIN_CONDITIONAL :=\ | 228 $(eval DEFAULT_MAIN_CONDITIONAL :=\ |
212 $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : ')) | 229 $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : ')) |
213 @#If there is a .pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) | 230 $(AT) #If there is a .pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) |
214 $(eval DEFAULT_PD_CONDITIONAL :=\ | 231 $(eval DEFAULT_PD_CONDITIONAL :=\ |
215 $(shell bash -c '{ ls $(PROJECT_DIR)/*.pd &>/dev/null && [ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep "render.*BelaContext" | wc -l` -eq 0 ]; } && echo '$(DEFAULT_PD_OBJS)' || : ' )) | 232 $(shell bash -c '{ ls $(PROJECT_DIR)/*.pd &>/dev/null && [ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep "render.*BelaContext" | wc -l` -eq 0 ]; } && echo '$(DEFAULT_PD_OBJS)' || : ' )) |
216 @echo 'Linking...' | 233 $(AT) echo 'Linking...' |
217 @$(CXX) $(SYNTAX_FLAG) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "$(PROJECT_DIR)/$(PROJECT)" $(CORE_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) | 234 $(AT) $(CXX) $(SYNTAX_FLAG) $(LDFLAGS) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "$(PROJECT_DIR)/$(PROJECT)" $(CORE_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) |
218 @echo ' ...done' | 235 $(AT) echo ' ...done' |
219 | 236 |
220 # Other Targets: | 237 # Other Targets: |
221 projectclean:## Remove the PROJECT's build objects & binary | 238 projectclean: ## Remove the PROJECT's build objects & binary |
222 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE) | 239 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE) |
223 -@echo ' ' | 240 -@echo ' ' |
224 | 241 |
225 clean: ## Same as projectclean | 242 clean: ## Same as projectclean |
226 clean: projectclean | 243 clean: projectclean |
227 | 244 |
228 coreclean: ## Remove the core's build objects | 245 coreclean: ## Remove the core's build objects |
229 -$(RM) build/core/* | 246 -$(RM) build/core/* |
230 | 247 |
231 prompt: | 248 prompt: |
232 @printf "Warning: you are about to DELETE the projects/ folder and its content. This operation cannot be undone. Continue? (y/N) " | 249 $(AT) printf "Warning: you are about to DELETE the projects/ folder and its content. This operation cannot be undone. Continue? (y/N) " |
233 @read REPLY; if [ $$REPLY != y ] && [ $$REPLY != Y ]; then echo "Aborting..."; exit 1; fi | 250 $(AT) read REPLY; if [ $$REPLY != y ] && [ $$REPLY != Y ]; then echo "Aborting..."; exit 1; fi |
234 | 251 |
235 distclean: ## Restores the Bela folder to a pristine state: remove all the projects source and the built objects, including the core Bela objects. | 252 distclean: ## Restores the Bela folder to a pristine state: remove all the projects source and the built objects, including the core Bela objects. |
236 distclean: prompt distcleannoprompt | 253 distclean: prompt distcleannoprompt |
237 | 254 |
238 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care. | 255 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care. |
239 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE) | 256 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE) |
240 -@echo ' ' | 257 -@echo ' ' |
241 | 258 |
259 $(warning C_FLAGS $(C_FLAGS)) | |
260 $(warning CPP_FLAGS $(CPP_FLAGS)) | |
261 $(warning LIBS $(LIBS)) | |
262 $(warning INCLUDES $(INCLUDES)) | |
242 runfg: run | 263 runfg: run |
243 run: ## Run PROJECT in the foreground | 264 run: ## Run PROJECT in the foreground |
244 run: stop Bela | 265 run: stop Bela |
245 @echo "Running $(RUN_COMMAND)" | 266 $(AT) echo "Running $(RUN_COMMAND)" |
246 @sync& cd $(RUN_FROM) && $(RUN_COMMAND) | 267 $(AT) sync& cd $(RUN_FROM) && $(RUN_COMMAND) |
247 runide: ## Run PROJECT for IDE (foreground, no buffering) | 268 runide: ## Run PROJECT for IDE (foreground, no buffering) |
248 runide: stop Bela | 269 runide: stop Bela |
249 @sync& cd $(RUN_FROM) && $(RUN_IDE_COMMAND) | 270 $(AT) sync& cd $(RUN_FROM) && $(RUN_IDE_COMMAND) |
250 runscreen: ## Run PROJECT in the background (detached screen) | 271 runscreen: ## Run PROJECT in the background (detached screen) |
251 runscreen: stop $(OUTPUT_FILE) | 272 runscreen: stop $(OUTPUT_FILE) |
252 @echo "Running $(RUN_COMMAND) in a screen" | 273 $(AT) echo "Running $(RUN_COMMAND) in a screen" |
253 @cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND) | 274 $(AT) cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND) |
254 runscreenfg: ## Run PROJECT in a screen in the foreground (can detach with ctrl-a ctrl-d) | 275 runscreenfg: ## Run PROJECT in a screen in the foreground (can detach with ctrl-a ctrl-d) |
255 runscreenfg: stop $(OUTPUT_FILE) | 276 runscreenfg: stop $(OUTPUT_FILE) |
256 @echo "Running $(RUN_COMMAND) in a screen" | 277 $(AT) echo "Running $(RUN_COMMAND) in a screen" |
257 @cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND) | 278 $(AT) cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND) |
258 | 279 |
259 STARTUP_COMMAND=printf "\#!/bin/sh\n\#\n\# This file is autogenerated by Bela. Do not edit!\n\necho Running Bela...\nscreen -S $(SCREEN_NAME) -d -m %s $(RUN_COMMAND) %s\n" | 280 STARTUP_COMMAND=printf "\#!/bin/sh\n\#\n\# This file is autogenerated by Bela. Do not edit!\n\necho Running Bela...\nscreen -S $(SCREEN_NAME) -d -m %s $(RUN_COMMAND) %s\n" |
260 nostartup: ## No Bela project runs at startup | 281 nostartup: ## No Bela project runs at startup |
261 nostartup: | 282 nostartup: |
262 @echo "Disabling Bela at startup..." | 283 $(AT) echo "Disabling Bela at startup..." |
263 @printf "#!/bin/sh\n#\n\n# This file is autogenerated by Bela. Do not edit!\n\n# Run on startup disabled -- nothing to do here\n" > $(BELA_STARTUP_SCRIPT) | 284 $(AT) printf "#!/bin/sh\n#\n\n# This file is autogenerated by Bela. Do not edit!\n\n# Run on startup disabled -- nothing to do here\n" > $(BELA_STARTUP_SCRIPT) |
264 | 285 |
265 startuploop: ## Makes PROJECT run at startup and restarts it if it crashes | 286 startuploop: ## Makes PROJECT run at startup and restarts it if it crashes |
266 startuploop: Bela | 287 startuploop: Bela |
267 @echo "Enabling Bela at startup in a loop..." | 288 $(AT) echo "Enabling Bela at startup in a loop..." |
268 @$(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT) | 289 $(AT) $(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT) |
269 | 290 |
270 startup: ## Makes PROJECT run at startup | 291 startup: ## Makes PROJECT run at startup |
271 startup: Bela | 292 startup: Bela |
272 @echo "Enabling Bela at startup..." | 293 $(AT) echo "Enabling Bela at startup..." |
273 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT) | 294 $(AT) $(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT) |
274 @chmod +x $(BELA_STARTUP_SCRIPT) | 295 $(AT) chmod +x $(BELA_STARTUP_SCRIPT) |
275 stop: ## Stops any Bela program that is currently running | 296 stop: ## Stops any Bela program that is currently running |
276 stop: | 297 stop: |
277 @PID=`grep $(BELA_AUDIO_THREAD_NAME) /proc/xenomai/stat | cut -d " " -f 5 | sed s/\s//g`; if [ -z $$PID ]; then [ $(QUIET) = true ] || echo "No process to kill"; else [ $(QUIET) = true ] || echo "Killing old Bela process $$PID"; kill -2 $$PID; fi; screen -X -S $(SCREEN_NAME) quit > /dev/null; exit 0; | 298 $(AT) PID=`grep $(BELA_AUDIO_THREAD_NAME) /proc/xenomai/stat | cut -d " " -f 5 | sed s/\s//g`; if [ -z $$PID ]; then [ $(QUIET) = true ] || echo "No process to kill"; else [ $(QUIET) = true ] || echo "Killing old Bela process $$PID"; kill -2 $$PID; fi; screen -X -S $(SCREEN_NAME) quit > /dev/null; exit 0; |
278 | 299 |
279 connect: ## Connects to the running Bela program (if any), can detach with ctrl-a ctrl-d. | 300 connect: ## Connects to the running Bela program (if any), can detach with ctrl-a ctrl-d. |
280 @screen -r -S $(SCREEN_NAME) | 301 $(AT) screen -r -S $(SCREEN_NAME) |
281 | 302 |
282 idestart: ## Starts the on-board IDE | 303 idestart: ## Starts the on-board IDE |
283 idestart: idestop | 304 idestart: idestop |
284 @printf "Starting IDE..." | 305 $(AT) printf "Starting IDE..." |
285 @$(BELA_IDE_RUN_COMMAND) | 306 $(AT) $(BELA_IDE_RUN_COMMAND) |
286 @printf "done\n" | 307 $(AT) printf "done\n" |
287 | 308 |
288 idestop: ## Stops the on-board IDE | 309 idestop: ## Stops the on-board IDE |
289 @printf "Stopping currently running IDE..." | 310 $(AT) printf "Stopping currently running IDE..." |
290 @screen -X -S $(BELA_IDE_SCREEN_NAME) quit > /dev/null; exit 0; | 311 $(AT) screen -X -S $(BELA_IDE_SCREEN_NAME) quit > /dev/null; exit 0; |
291 @printf "done\n" | 312 $(AT) printf "done\n" |
292 | 313 |
293 BELA_IDE_STARTUP_COMMAND=printf '\#!/bin/sh\n\#\n\# This file is autogenerated by Bela. Do not edit!\n\necho Running the Bela IDE...\n$(BELA_IDE_RUN_COMMAND)\n' > $(BELA_IDE_STARTUP_SCRIPT) | 314 BELA_IDE_STARTUP_COMMAND=printf '\#!/bin/sh\n\#\n\# This file is autogenerated by Bela. Do not edit!\n\necho Running the Bela IDE...\n$(BELA_IDE_RUN_COMMAND)\n' > $(BELA_IDE_STARTUP_SCRIPT) |
294 | 315 |
295 idestartup: ## Enables the IDE at startup | 316 idestartup: ## Enables the IDE at startup |
296 @echo "Enabling the IDE at startup" | 317 $(AT) echo "Enabling the IDE at startup" |
297 @$(BELA_IDE_STARTUP_COMMAND) | 318 $(AT) $(BELA_IDE_STARTUP_COMMAND) |
298 @chmod +x $(BELA_IDE_STARTUP_SCRIPT) | 319 $(AT) chmod +x $(BELA_IDE_STARTUP_SCRIPT) |
299 | 320 |
300 idenostartup: ## Disables the IDE at startup | 321 idenostartup: ## Disables the IDE at startup |
301 @echo "Disabling the IDE at startup" | 322 $(AT) echo "Disabling the IDE at startup" |
302 @printf "#!/bin/sh\n#\n\n# This file is autogenerated by Bela. Do not edit!\n\n# The Bela IDE is disabled on startup.\n" > $(BELA_IDE_STARTUP_SCRIPT) | 323 $(AT) printf "#!/bin/sh\n#\n\n# This file is autogenerated by Bela. Do not edit!\n\n# The Bela IDE is disabled on startup.\n" > $(BELA_IDE_STARTUP_SCRIPT) |
303 | 324 |
304 ideconnect: ## Brings in the foreground the IDE that currently is running in a screen (if any), can detach with ctrl-a ctrl-d. | 325 ideconnect: ## Brings in the foreground the IDE that currently is running in a screen (if any), can detach with ctrl-a ctrl-d. |
305 @screen -r -S $(BELA_IDE_SCREEN_NAME) | 326 $(AT) screen -r -S $(BELA_IDE_SCREEN_NAME) |
306 | 327 |
307 BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | 328 BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) |
308 UPDATES_DIR?=/root/Bela/updates | 329 UPDATES_DIR?=/root/Bela/updates |
309 UPDATE_SOURCE_DIR_BASE?=/tmp/belaUpdate | 330 UPDATE_SOURCE_DIR_BASE?=/tmp/belaUpdate |
310 UPDATE_SOURCE_DIR=$(UPDATE_SOURCE_DIR_BASE)/Bela | 331 UPDATE_SOURCE_DIR=$(UPDATE_SOURCE_DIR_BASE)/Bela |
312 UPDATE_BELA_PATCH?=/tmp/belaPatch | 333 UPDATE_BELA_PATCH?=/tmp/belaPatch |
313 UPDATE_BELA_BACKUP?=/tmp/belaBak | 334 UPDATE_BELA_BACKUP?=/tmp/belaBak |
314 UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak | 335 UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak |
315 | 336 |
316 updateclean: ## Cleans the $(UPDATES_DIR) folder | 337 updateclean: ## Cleans the $(UPDATES_DIR) folder |
317 @[ -n $(UPDATE_DIR) ] && rm -rf $(UPDATE_DIR) && mkdir -p $(UPDATE_DIR) | 338 $(AT) [ -n $(UPDATE_DIR) ] && rm -rf $(UPDATE_DIR) && mkdir -p $(UPDATE_DIR) |
318 | 339 |
319 checkupdate: ## Unzips the zip file in $(UPDATES_DIR) and checks that it contains a valid | 340 checkupdate: ## Unzips the zip file in $(UPDATES_DIR) and checks that it contains a valid |
320 @echo Validating archive... | 341 $(AT) echo Validating archive... |
321 @cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"` | 342 $(AT) cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"` |
322 @#TODO: heuristics on available space. Use unzip -l and df | 343 $(AT) #TODO: heuristics on available space. Use unzip -l and df |
323 @echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'` | 344 $(AT) echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'` |
324 @# Delete and re-create the temp directory (first, make sure it is not an empty string!) | 345 $(AT) # Delete and re-create the temp directory (first, make sure it is not an empty string!) |
325 @[ -n $(UPDATE_SOURCE_DIR_BASE) ] && rm -rf $(UPDATE_SOURCE_DIR_BASE) && mkdir -p $(UPDATE_SOURCE_DIR_BASE) | 346 $(AT) [ -n $(UPDATE_SOURCE_DIR_BASE) ] && rm -rf $(UPDATE_SOURCE_DIR_BASE) && mkdir -p $(UPDATE_SOURCE_DIR_BASE) |
326 @echo Unzipping archive... | 347 $(AT) echo Unzipping archive... |
327 @cd $(UPDATE_SOURCE_DIR_BASE) && unzip -qq $(UPDATES_DIR)/*zip | 348 $(AT) cd $(UPDATE_SOURCE_DIR_BASE) && unzip -qq $(UPDATES_DIR)/*zip |
328 #TODO: this should not be needed. Remove comments. Strip the top-level folder ( if there is only one ) | 349 #TODO: this should not be needed. Remove comments. Strip the top-level folder ( if there is only one ) |
329 #@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\ | 350 #@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\ |
330 [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR) | 351 [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR) |
331 | 352 |
332 @echo Validating unzipped archive... | 353 $(AT) echo Validating unzipped archive... |
333 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ | 354 $(AT) cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ |
334 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } | 355 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } |
335 @echo ...done | 356 $(AT) echo ...done |
336 UPDATE_LOG?=~/update.log | 357 UPDATE_LOG?=~/update.log |
337 LOG=>> $(UPDATE_LOG) 2>&1 | 358 LOG=>> $(UPDATE_LOG) 2>&1 |
338 updateunsafe: ## Installs the update from $(UPDATES_DIR) in a more brick-friendly way | 359 updateunsafe: ## Installs the update from $(UPDATES_DIR) in a more brick-friendly way |
339 @echo > $(UPDATE_LOG) | 360 $(AT) echo > $(UPDATE_LOG) |
340 # Re-perform the check, just in case ... | 361 # Re-perform the check, just in case ... |
341 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ | 362 $(AT) cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ |
342 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } | 363 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } |
343 @cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(BELA_DIR) ./update_board -y --no-frills | 364 $(AT) cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(BELA_DIR) ./update_board -y --no-frills |
344 @screen -S update-Bela -d -m bash -c "echo Restart the IDE $(LOG) &&\ | 365 $(AT) screen -S update-Bela -d -m bash -c "echo Restart the IDE $(LOG) &&\ |
345 $(MAKE) --no-print-directory idestart $(LOG) && echo Update succesful $(LOG);" $(LOG) | 366 $(MAKE) --no-print-directory idestart $(LOG) && echo Update succesful $(LOG);" $(LOG) |
346 update: ## Installs the update from $(UPDATES_DIR) | 367 update: ## Installs the update from $(UPDATES_DIR) |
347 update: stop | 368 update: stop |
348 @# Truncate the log file | 369 $(AT) # Truncate the log file |
349 @echo > $(UPDATE_LOG) | 370 $(AT) echo > $(UPDATE_LOG) |
350 @echo Re-perform the check, just in case ... >> $(UPDATE_LOG) | 371 $(AT) echo Re-perform the check, just in case ... >> $(UPDATE_LOG) |
351 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ | 372 $(AT) cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ |
352 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } | 373 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } |
353 @[ -n $(UPDATE_BELA_PATCH) ] && mkdir -p $(UPDATE_BELA_PATCH) | 374 $(AT) [ -n $(UPDATE_BELA_PATCH) ] && mkdir -p $(UPDATE_BELA_PATCH) |
354 @#TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target | 375 $(AT) #TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target |
355 @$(MAKE) --no-print-directory coreclean | 376 $(AT) $(MAKE) --no-print-directory coreclean |
356 @echo Backing up $(BELA_DIR) to $(UPDATE_BELA_PATCH) ... | tee -a $(UPDATE_LOG) | 377 $(AT) echo Backing up $(BELA_DIR) to $(UPDATE_BELA_PATCH) ... | tee -a $(UPDATE_LOG) |
357 @rsync -a --delete-during --exclude Documentation $(BELA_DIR)/ $(UPDATE_BELA_PATCH) | 378 $(AT) rsync -a --delete-during --exclude Documentation $(BELA_DIR)/ $(UPDATE_BELA_PATCH) |
358 @echo Backing up $(BELA_DIR) to $(UPDATE_BELA_BACKUP) ... | tee -a $(UPDATE_LOG) | 379 $(AT) echo Backing up $(BELA_DIR) to $(UPDATE_BELA_BACKUP) ... | tee -a $(UPDATE_LOG) |
359 @[ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP) | 380 $(AT) [ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP) |
360 @rsync -a --delete-during $(BELA_DIR)/ $(UPDATE_BELA_BACKUP) | 381 $(AT) rsync -a --delete-during $(BELA_DIR)/ $(UPDATE_BELA_BACKUP) |
361 @echo Running update script... | tee -a $(UPDATE_LOG) | 382 $(AT) echo Running update script... | tee -a $(UPDATE_LOG) |
362 @cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_PATCH) ./update_board -y --no-frills | 383 $(AT) cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_PATCH) ./update_board -y --no-frills |
363 @echo Restoring directory structure... | tee -a $(UPDATE_LOG) | 384 $(AT) # If everything went ok, we now have the updated version of $(BELA_DIR) in $(UPDATE_BELA_PATCH) and a backup of $(BELA_DIR) in $(UPDATE_BELA_BACKUP) |
364 @screen -S update-Bela -d -m bash -c '\ | 385 $(AT) # So let's operate the magic swap. $(BELA_DIR) is moved to $(UPDATE_BELA_MV_BACKUP) and $(UPDATE_BELA_PATCH) is moved to $(BELA_DIR). |
386 $(AT) # If something goes wrong at thie stage, you can always find your old $(BELA_DIR) folder at $(UPDATE_BELA_BACKUP) | |
387 $(AT) # The fun part is that this Makefile is moved as well... | |
388 $(AT) # We are about to kill the IDE, so just in case you are running this from within the IDE, we run the remainder of this update in a screen. | |
389 $(AT) # Output will be logged to $(UPDATE_LOG) | |
390 $(AT) echo Restoring directory structure... | tee -a $(UPDATE_LOG) | |
391 $(AT) screen -S update-Bela -d -m bash -c '\ | |
365 [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\ | 392 [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\ |
366 echo Kill the IDE $(LOG) && \ | 393 echo Kill the IDE $(LOG) && \ |
367 $(MAKE) --no-print-directory idestop $(LOG) &&\ | 394 $(MAKE) --no-print-directory idestop $(LOG) &&\ |
368 mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_PATCH) $(BELA_DIR) $(LOG) &&\ | 395 mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_PATCH) $(BELA_DIR) $(LOG) &&\ |
369 echo Hope we are still alive here $(LOG) &&\ | 396 echo Hope we are still alive here $(LOG) &&\ |