annotate Makefile @ 461:26b3b87437fb prerelease

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