annotate Makefile @ 553:e545ce04cf2c prerelease

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