giuliomoro@301: # Bela giuliomoro@64: # Low-latency, real-time audio and sensor processing on BeagleBone Black l@260: # (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan giuliomoro@64: # Centre for Digital Music, Queen Mary University of London giuliomoro@64: giuliomoro@548: ## This Makefile is intended for use on the BeagleBone Black itself # giuliomoro@548: ## and not for cross-compiling # giuliomoro@548: ## available command line options: # giuliomoro@548: ## EXAMPLE= -- name of the folder in examples/ to be copied to projects/ and built giuliomoro@548: ## PROJECT= -- name of the folder in projects/ to be built giuliomoro@548: ## CL= -- list of command line options to pass to the program when running giuliomoro@553: ## CPPFLAGS= -- list of additional flags passed to the C++ compiler giuliomoro@553: ## CFLAGS= -- list of additional flags passed to the C compiler giuliomoro@548: ## COMPILER= -- compiler to use (clang or gcc) giuliomoro@553: ## LDFLAGS= -- linker flags (e.g.: -L. ) giuliomoro@553: ## LDLIBS= -- libs to link in (e.g.: -lm ) giuliomoro@548: ## AT= -- used instead of @ to silence the output. Defaults AT=@, use AT= for a very verbose output giuliomoro@548: ### giuliomoro@548: ##available targets: # giuliomoro@386: .DEFAULT_GOAL := Bela giuliomoro@386: giuliomoro@548: AT?=@ giuliomoro@459: NO_PROJECT_TARGETS=help coreclean distclean stop nostartup idestart idestop idestartup idenostartup connect ideconnect update checkupdate updateunsafe giuliomoro@385: NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS) giuliomoro@424: # list of targets that automatically activate the QUIET=true flag giuliomoro@424: QUIET_TARGETS=runide giuliomoro@424: giuliomoro@385: # Type `$ make help` to get a description of the functionalities of this Makefile. giuliomoro@385: help: ## Show this help giuliomoro@548: $(AT) echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]' giuliomoro@548: $(AT) printf "\n$(NO_PROJECT_TARGETS_MESSAGE)\n\n" giuliomoro@548: $(AT) echo 'Targets: (default: $(.DEFAULT_GOAL))' giuliomoro@548: $(AT) echo list: $(MAKEFILE_LIST) giuliomoro@548: $(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: giuliomoro@385: # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS giuliomoro@374: ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS))) giuliomoro@374: ifndef PROJECT giuliomoro@374: ifndef EXAMPLE giuliomoro@385: $(error $(NO_PROJECT_TARGETS_MESSAGE)) giuliomoro@374: endif giuliomoro@287: endif l@260: endif l@260: giuliomoro@374: # if we are building an example, just copy it to the projects/ folder giuliomoro@386: # and then treat it as a project giuliomoro@374: ifdef EXAMPLE giuliomoro@394: #you can alternatively specify PROJECT= along with EXAMPLE= giuliomoro@374: PROJECT?=exampleTempProject giuliomoro@374: PROJECT_DIR?=$(abspath projects/$(PROJECT)) andrewm@380: $(shell mkdir -p $(abspath projects)) giuliomoro@374: $(shell rm -rf $(PROJECT_DIR)) giuliomoro@374: $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR)) giuliomoro@374: else giuliomoro@287: PROJECT_DIR := $(abspath projects/$(PROJECT)) giuliomoro@287: endif giuliomoro@287: giuliomoro@374: ifdef PROJECT giuliomoro@393: $(shell mkdir -p $(PROJECT_DIR)/build build/core) giuliomoro@287: endif giuliomoro@374: giuliomoro@331: OUTPUT_FILE?=$(PROJECT_DIR)/$(PROJECT) giuliomoro@331: COMMAND_LINE_OPTIONS?=$(CL) giuliomoro@446: RUN_FROM?=$(PROJECT_DIR) giuliomoro@331: RUN_COMMAND?=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS) giuliomoro@396: RUN_IDE_COMMAND?=stdbuf -i0 -o0 -e0 $(RUN_COMMAND) giuliomoro@401: BELA_STARTUP_SCRIPT?=/root/Bela_startup.sh giuliomoro@359: BELA_AUDIO_THREAD_NAME?=bela-audio giuliomoro@377: SCREEN_NAME?=Bela giuliomoro@399: BELA_IDE_STARTUP_SCRIPT?=/root/Bela_node.sh giuliomoro@393: BELA_IDE_HOME?=/root/Bela/IDE giuliomoro@400: # 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: BELA_IDE_SCREEN_NAME?=IDE-Bela giuliomoro@440: 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: BELA_IDE_STOP_COMMAND?=screen -X -S $(BELA_IDE_SCREEN_NAME) quit > /dev/null giuliomoro@374: giuliomoro@424: ifneq (,$(filter $(QUIET_TARGETS),$(MAKECMDGOALS))) giuliomoro@424: QUIET=true giuliomoro@424: endif giuliomoro@424: QUIET?=false giuliomoro@424: giuliomoro@64: RM := rm -rf giuliomoro@64: STATIC_LIBS := ./libprussdrv.a ./libNE10.a giuliomoro@553: LIBS = -lrt -lnative -lxenomai -lsndfile l@260: giuliomoro@244: # refresh library cache and check if libpd is there giuliomoro@326: #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking giuliomoro@326: LIBPD_PATH = /usr/lib/libpd.so giuliomoro@326: TEST_LIBPD := $(shell which $(LIBPD_PATH)) giuliomoro@326: ifneq ($(strip $(TEST_LIBPD)), ) giuliomoro@244: # if libpd is there, link it in giuliomoro@244: LIBS += -lpd -lpthread_rt giuliomoro@244: endif giuliomoro@553: INCLUDES := -I$(PROJECT_DIR) -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include giuliomoro@553: DEFAULT_CPPFLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize giuliomoro@553: DEFAULT_CFLAGS := $(DEFAULT_CPPFLAGS) giuliomoro@241: giuliomoro@241: ifndef COMPILER giuliomoro@241: # check whether clang is installed giuliomoro@385: TEST_COMPILER := $(shell which clang) giuliomoro@302: ifneq ($(strip $(TEST_COMPILER)), ) giuliomoro@385: #if it is installed, use it giuliomoro@302: COMPILER := clang giuliomoro@302: else giuliomoro@241: COMPILER := gcc giuliomoro@302: endif giuliomoro@241: endif giuliomoro@241: giuliomoro@241: ifeq ($(COMPILER), clang) giuliomoro@306: CC=clang giuliomoro@306: CXX=clang++ giuliomoro@553: DEFAULT_CPPFLAGS += -DNDEBUG giuliomoro@553: DEFAULT_CFLAGS += -DNDEBUG giuliomoro@548: else giuliomoro@548: ifeq ($(COMPILER), gcc) giuliomoro@548: CC=gcc giuliomoro@548: CXX=g++ giuliomoro@553: DEFAULT_CPPFLAGS += --fast-math giuliomoro@553: DEFAULT_CFLAGS += --fast-math giuliomoro@548: endif giuliomoro@241: endif giuliomoro@241: l@260: ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S) l@260: ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o))) l@260: ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d))) giuliomoro@64: l@260: C_SRCS := $(wildcard $(PROJECT_DIR)/*.c) l@260: C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o))) l@260: C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d))) giuliomoro@64: l@260: CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp) l@260: CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o))) l@260: CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d))) giuliomoro@64: giuliomoro@383: PROJECT_OBJS = $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) giuliomoro@383: giuliomoro@301: # Core Bela sources giuliomoro@463: CORE_CPP_SRCS = $(filter-out core/default_main.cpp core/default_libpd_render.cpp, $(wildcard core/*.cpp)) giuliomoro@186: CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o))) giuliomoro@186: CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d))) giuliomoro@64: andrewm@318: CORE_ASM_SRCS := $(wildcard core/*.S) andrewm@318: CORE_ASM_OBJS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.o))) andrewm@318: CORE_ASM_DEPS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.d))) andrewm@318: andrewm@318: giuliomoro@64: # Objects for a system-supplied default main() file, if the user giuliomoro@64: # only wants to provide the render functions. giuliomoro@64: DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp giuliomoro@64: DEFAULT_MAIN_OBJS := ./build/core/default_main.o giuliomoro@64: DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d andrewm@68: giuliomoro@463: # Objects for a system-supplied default render() file for libpd projects, giuliomoro@463: # if the user only wants to provide the Pd files. giuliomoro@463: DEFAULT_PD_CPP_SRCS := ./core/default_libpd_render.cpp giuliomoro@463: DEFAULT_PD_OBJS := ./build/core/default_libpd_render.o giuliomoro@463: DEFAULT_PD_CPP_DEPS := ./build/core/default_libpd_render.d giuliomoro@463: giuliomoro@463: Bela: ## Builds the Bela program with all the optimizations giuliomoro@334: Bela: $(OUTPUT_FILE) giuliomoro@334: giuliomoro@301: # all = build Bela giuliomoro@334: all: ## Same as Bela andrewm@69: all: SYNTAX_FLAG := giuliomoro@301: all: Bela andrewm@68: giuliomoro@301: # debug = buildBela debug giuliomoro@334: debug: ## Same as Bela but with debug flags and no optimizations giuliomoro@553: debug: DEFAULT_CPPFLAGS=-g giuliomoro@553: debug: DEFAULT_CFLAGS=-g giuliomoro@209: debug: all giuliomoro@209: andrewm@69: # syntax = check syntax giuliomoro@334: syntax: ## Only checks syntax andrewm@69: syntax: SYNTAX_FLAG := -fsyntax-only giuliomoro@478: syntax: $(PROJECT_OBJS) andrewm@69: giuliomoro@301: # Rule for Bela core C++ files giuliomoro@64: build/core/%.o: ./core/%.cpp giuliomoro@548: $(AT) echo 'Building $(notdir $<)...' giuliomoro@548: # $(AT) echo 'Invoking: C++ Compiler $(CXX)' giuliomoro@553: $(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: $(AT) echo ' ...done' giuliomoro@548: $(AT) echo ' ' andrewm@68: andrewm@318: # Rule for Bela core ASM files andrewm@318: build/core/%.o: ./core/%.S giuliomoro@548: $(AT) echo 'Building $(notdir $<)...' giuliomoro@548: # $(AT) echo 'Invoking: GCC Assembler' giuliomoro@548: $(AT) as -o "$@" "$<" giuliomoro@548: $(AT) echo ' ...done' giuliomoro@548: $(AT) echo ' ' andrewm@318: giuliomoro@64: # Rule for user-supplied C++ files l@260: $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp giuliomoro@548: $(AT) echo 'Building $(notdir $<)...' giuliomoro@548: # $(AT) echo 'Invoking: C++ Compiler $(CXX)' giuliomoro@553: $(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: $(AT) echo ' ...done' giuliomoro@548: $(AT) echo ' ' andrewm@68: giuliomoro@64: # Rule for user-supplied C files l@260: $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c giuliomoro@548: $(AT) echo 'Building $(notdir $<)...' giuliomoro@548: # $(AT) echo 'Invoking: C Compiler $(CC)' giuliomoro@553: $(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: $(AT) echo ' ...done' giuliomoro@548: $(AT) echo ' ' andrewm@68: giuliomoro@64: # Rule for user-supplied assembly files l@260: $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S giuliomoro@548: $(AT) echo 'Building $(notdir $<)...' giuliomoro@548: # $(AT) echo 'Invoking: GCC Assembler' giuliomoro@548: $(AT) as -o "$@" "$<" giuliomoro@548: $(AT) echo ' ...done' giuliomoro@548: $(AT) echo ' ' giuliomoro@64: giuliomoro@64: # This is a nasty kludge: we want to be able to optionally link in a default giuliomoro@64: # main file if the user hasn't supplied one. We check for the presence of the main() giuliomoro@64: # function, and conditionally call one of two recursive make targets depending on whether giuliomoro@64: # we want to link in the default main file or not. The kludge is the mess of a shell script giuliomoro@64: # line below. Surely there's a better way to do this? giuliomoro@467: $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_PD_OBJS) giuliomoro@463: $(eval DEFAULT_MAIN_CONDITIONAL :=\ giuliomoro@463: $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : ')) giuliomoro@548: $(AT) #If there is a .pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) giuliomoro@463: $(eval DEFAULT_PD_CONDITIONAL :=\ giuliomoro@470: $(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: $(AT) echo 'Linking...' giuliomoro@553: $(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: $(AT) echo ' ...done' l@387: l@260: # Other Targets: giuliomoro@548: projectclean: ## Remove the PROJECT's build objects & binary giuliomoro@326: -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE) giuliomoro@64: -@echo ' ' giuliomoro@64: giuliomoro@386: clean: ## Same as projectclean giuliomoro@386: clean: projectclean giuliomoro@386: giuliomoro@386: coreclean: ## Remove the core's build objects giuliomoro@394: -$(RM) build/core/* giuliomoro@386: giuliomoro@386: prompt: giuliomoro@548: $(AT) printf "Warning: you are about to DELETE the projects/ folder and its content. This operation cannot be undone. Continue? (y/N) " giuliomoro@548: $(AT) read REPLY; if [ $$REPLY != y ] && [ $$REPLY != Y ]; then echo "Aborting..."; exit 1; fi giuliomoro@386: giuliomoro@386: 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: distclean: prompt distcleannoprompt giuliomoro@386: giuliomoro@386: distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care. giuliomoro@326: -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE) giuliomoro@64: -@echo ' ' giuliomoro@64: giuliomoro@302: runfg: run giuliomoro@334: run: ## Run PROJECT in the foreground giuliomoro@326: run: stop Bela giuliomoro@548: $(AT) echo "Running $(RUN_COMMAND)" giuliomoro@548: $(AT) sync& cd $(RUN_FROM) && $(RUN_COMMAND) giuliomoro@424: runide: ## Run PROJECT for IDE (foreground, no buffering) giuliomoro@424: runide: stop Bela giuliomoro@548: $(AT) sync& cd $(RUN_FROM) && $(RUN_IDE_COMMAND) giuliomoro@334: runscreen: ## Run PROJECT in the background (detached screen) giuliomoro@302: runscreen: stop $(OUTPUT_FILE) giuliomoro@548: $(AT) echo "Running $(RUN_COMMAND) in a screen" giuliomoro@548: $(AT) cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND) giuliomoro@334: runscreenfg: ## Run PROJECT in a screen in the foreground (can detach with ctrl-a ctrl-d) giuliomoro@313: runscreenfg: stop $(OUTPUT_FILE) giuliomoro@548: $(AT) echo "Running $(RUN_COMMAND) in a screen" giuliomoro@548: $(AT) cd $(RUN_FROM) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND) giuliomoro@302: giuliomoro@331: 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: nostartup: ## No Bela project runs at startup giuliomoro@331: nostartup: giuliomoro@548: $(AT) echo "Disabling Bela at startup..." giuliomoro@548: $(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: giuliomoro@334: startuploop: ## Makes PROJECT run at startup and restarts it if it crashes giuliomoro@331: startuploop: Bela giuliomoro@548: $(AT) echo "Enabling Bela at startup in a loop..." giuliomoro@548: $(AT) $(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT) giuliomoro@331: giuliomoro@334: startup: ## Makes PROJECT run at startup giuliomoro@331: startup: Bela giuliomoro@548: $(AT) echo "Enabling Bela at startup..." giuliomoro@548: $(AT) $(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT) giuliomoro@548: $(AT) chmod +x $(BELA_STARTUP_SCRIPT) giuliomoro@334: stop: ## Stops any Bela program that is currently running giuliomoro@302: stop: giuliomoro@548: $(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: giuliomoro@417: connect: ## Connects to the running Bela program (if any), can detach with ctrl-a ctrl-d. giuliomoro@548: $(AT) screen -r -S $(SCREEN_NAME) giuliomoro@417: giuliomoro@409: idestart: ## Starts the on-board IDE giuliomoro@410: idestart: idestop giuliomoro@548: $(AT) printf "Starting IDE..." giuliomoro@548: $(AT) $(BELA_IDE_RUN_COMMAND) giuliomoro@548: $(AT) printf "done\n" giuliomoro@393: giuliomoro@393: idestop: ## Stops the on-board IDE giuliomoro@548: $(AT) printf "Stopping currently running IDE..." giuliomoro@548: $(AT) screen -X -S $(BELA_IDE_SCREEN_NAME) quit > /dev/null; exit 0; giuliomoro@548: $(AT) printf "done\n" giuliomoro@393: giuliomoro@440: 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: giuliomoro@399: idestartup: ## Enables the IDE at startup giuliomoro@548: $(AT) echo "Enabling the IDE at startup" giuliomoro@548: $(AT) $(BELA_IDE_STARTUP_COMMAND) giuliomoro@548: $(AT) chmod +x $(BELA_IDE_STARTUP_SCRIPT) giuliomoro@393: giuliomoro@393: idenostartup: ## Disables the IDE at startup giuliomoro@548: $(AT) echo "Disabling the IDE at startup" giuliomoro@548: $(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: giuliomoro@417: 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: $(AT) screen -r -S $(BELA_IDE_SCREEN_NAME) giuliomoro@417: giuliomoro@448: BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) giuliomoro@448: UPDATES_DIR?=/root/Bela/updates giuliomoro@453: UPDATE_SOURCE_DIR_BASE?=/tmp/belaUpdate giuliomoro@453: UPDATE_SOURCE_DIR=$(UPDATE_SOURCE_DIR_BASE)/Bela giuliomoro@448: UPDATE_REQUIRED_PATHS?=scripts include core scripts/update_board giuliomoro@453: UPDATE_BELA_PATCH?=/tmp/belaPatch giuliomoro@448: UPDATE_BELA_BACKUP?=/tmp/belaBak giuliomoro@448: UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak giuliomoro@448: giuliomoro@448: updateclean: ## Cleans the $(UPDATES_DIR) folder giuliomoro@548: $(AT) [ -n $(UPDATE_DIR) ] && rm -rf $(UPDATE_DIR) && mkdir -p $(UPDATE_DIR) giuliomoro@448: giuliomoro@448: checkupdate: ## Unzips the zip file in $(UPDATES_DIR) and checks that it contains a valid giuliomoro@548: $(AT) echo Validating archive... giuliomoro@548: $(AT) cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"` giuliomoro@548: $(AT) #TODO: heuristics on available space. Use unzip -l and df giuliomoro@548: $(AT) echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'` giuliomoro@548: $(AT) # Delete and re-create the temp directory (first, make sure it is not an empty string!) giuliomoro@548: $(AT) [ -n $(UPDATE_SOURCE_DIR_BASE) ] && rm -rf $(UPDATE_SOURCE_DIR_BASE) && mkdir -p $(UPDATE_SOURCE_DIR_BASE) giuliomoro@548: $(AT) echo Unzipping archive... giuliomoro@548: $(AT) cd $(UPDATE_SOURCE_DIR_BASE) && unzip -qq $(UPDATES_DIR)/*zip giuliomoro@458: #TODO: this should not be needed. Remove comments. Strip the top-level folder ( if there is only one ) giuliomoro@453: #@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\ giuliomoro@448: [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR) giuliomoro@458: giuliomoro@548: $(AT) echo Validating unzipped archive... giuliomoro@548: $(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: [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } giuliomoro@548: $(AT) echo ...done giuliomoro@448: UPDATE_LOG?=~/update.log giuliomoro@448: LOG=>> $(UPDATE_LOG) 2>&1 giuliomoro@459: updateunsafe: ## Installs the update from $(UPDATES_DIR) in a more brick-friendly way giuliomoro@548: $(AT) echo > $(UPDATE_LOG) giuliomoro@459: # Re-perform the check, just in case ... giuliomoro@548: $(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: [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } giuliomoro@548: $(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: $(AT) screen -S update-Bela -d -m bash -c "echo Restart the IDE $(LOG) &&\ giuliomoro@459: $(MAKE) --no-print-directory idestart $(LOG) && echo Update succesful $(LOG);" $(LOG) giuliomoro@448: update: ## Installs the update from $(UPDATES_DIR) giuliomoro@448: update: stop giuliomoro@548: $(AT) # Truncate the log file giuliomoro@548: $(AT) echo > $(UPDATE_LOG) giuliomoro@548: $(AT) echo Re-perform the check, just in case ... >> $(UPDATE_LOG) giuliomoro@548: $(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: [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } giuliomoro@548: $(AT) [ -n $(UPDATE_BELA_PATCH) ] && mkdir -p $(UPDATE_BELA_PATCH) giuliomoro@548: $(AT) #TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target giuliomoro@548: $(AT) $(MAKE) --no-print-directory coreclean giuliomoro@548: $(AT) echo Backing up $(BELA_DIR) to $(UPDATE_BELA_PATCH) ... | tee -a $(UPDATE_LOG) giuliomoro@548: $(AT) rsync -a --delete-during --exclude Documentation $(BELA_DIR)/ $(UPDATE_BELA_PATCH) giuliomoro@548: $(AT) echo Backing up $(BELA_DIR) to $(UPDATE_BELA_BACKUP) ... | tee -a $(UPDATE_LOG) giuliomoro@548: $(AT) [ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP) giuliomoro@548: $(AT) rsync -a --delete-during $(BELA_DIR)/ $(UPDATE_BELA_BACKUP) giuliomoro@548: $(AT) echo Running update script... | tee -a $(UPDATE_LOG) giuliomoro@548: $(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: $(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: $(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: $(AT) # If something goes wrong at thie stage, you can always find your old $(BELA_DIR) folder at $(UPDATE_BELA_BACKUP) giuliomoro@548: $(AT) # The fun part is that this Makefile is moved as well... giuliomoro@548: $(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: $(AT) # Output will be logged to $(UPDATE_LOG) giuliomoro@548: $(AT) echo Restoring directory structure... | tee -a $(UPDATE_LOG) giuliomoro@548: $(AT) screen -S update-Bela -d -m bash -c '\ giuliomoro@448: [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\ giuliomoro@448: echo Kill the IDE $(LOG) && \ giuliomoro@448: $(MAKE) --no-print-directory idestop $(LOG) &&\ giuliomoro@453: mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_PATCH) $(BELA_DIR) $(LOG) &&\ giuliomoro@448: echo Hope we are still alive here $(LOG) &&\ giuliomoro@448: echo Restart the IDE $(LOG) &&\ giuliomoro@448: make --no-print-directory -C $(BELA_DIR) idestart $(LOG) &&\ giuliomoro@448: echo Update succesful $(LOG); \ giuliomoro@448: ' $(LOG) giuliomoro@448: giuliomoro@526: .PHONY: all clean distclean help projectclean nostartup startup startuploop debug run runfg runscreen runscreenfg stop idestart idestop idestartup idenostartup ideconnect connect update checkupdate updateunsafe