annotate Makefile @ 400:adb4fafbeaef prerelease

Fixed 'make stop' kills IDE
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 15 Jun 2016 01:48:22 +0100
parents ff60102d5f39
children 00c3bbea4faf
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@400 11 NO_PROJECT_TARGETS=coreclean distclean stop help iderun idestop idestartup idenostartup
giuliomoro@385 12 NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS)
giuliomoro@385 13 # Type `$ make help` to get a description of the functionalities of this Makefile.
giuliomoro@385 14 help: ## Show this help
giuliomoro@385 15 @echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]'
giuliomoro@386 16 @printf "\n$(NO_PROJECT_TARGETS_MESSAGE)\n\n"
giuliomoro@386 17 @echo 'Targets: (default: $(.DEFAULT_GOAL))'
giuliomoro@385 18 @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | column -t -c 2 -s '#'
l@260 19
giuliomoro@385 20 # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS
giuliomoro@374 21 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS)))
giuliomoro@374 22 ifndef PROJECT
giuliomoro@374 23 ifndef EXAMPLE
giuliomoro@385 24 $(error $(NO_PROJECT_TARGETS_MESSAGE))
giuliomoro@374 25 endif
giuliomoro@287 26 endif
l@260 27 endif
l@260 28
giuliomoro@374 29 # if we are building an example, just copy it to the projects/ folder
giuliomoro@386 30 # and then treat it as a project
giuliomoro@374 31 ifdef EXAMPLE
giuliomoro@394 32 #you can alternatively specify PROJECT= along with EXAMPLE=
giuliomoro@374 33 PROJECT?=exampleTempProject
giuliomoro@374 34 PROJECT_DIR?=$(abspath projects/$(PROJECT))
andrewm@380 35 $(shell mkdir -p $(abspath projects))
giuliomoro@374 36 $(shell rm -rf $(PROJECT_DIR))
giuliomoro@374 37 $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR))
giuliomoro@374 38 else
giuliomoro@287 39 PROJECT_DIR := $(abspath projects/$(PROJECT))
giuliomoro@287 40 endif
giuliomoro@287 41
giuliomoro@374 42 ifdef PROJECT
giuliomoro@393 43 $(shell mkdir -p $(PROJECT_DIR)/build build/core)
giuliomoro@287 44 endif
giuliomoro@374 45
giuliomoro@331 46 OUTPUT_FILE?=$(PROJECT_DIR)/$(PROJECT)
giuliomoro@331 47 COMMAND_LINE_OPTIONS?=$(CL)
giuliomoro@331 48 RUN_COMMAND?=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS)
giuliomoro@396 49 RUN_IDE_COMMAND?=stdbuf -i0 -o0 -e0 $(RUN_COMMAND)
l@389 50 BELA_STARTUP_SCRIPT?=/root/BeagleRT_startup.sh
giuliomoro@359 51 BELA_AUDIO_THREAD_NAME?=bela-audio
giuliomoro@377 52 SCREEN_NAME?=Bela
giuliomoro@399 53 BELA_IDE_STARTUP_SCRIPT?=/root/Bela_node.sh
giuliomoro@393 54 BELA_IDE_HOME?=/root/Bela/IDE
giuliomoro@400 55 # 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 56 BELA_IDE_SCREEN_NAME?=IDE-Bela
giuliomoro@393 57 BELA_IDE_RUN_COMMAND?=cd $(BELA_IDE_HOME) && screen -S $(BELA_IDE_SCREEN_NAME) -d -m node index.js
giuliomoro@393 58 BELA_IDE_STOP_COMMAND?=screen -X -S $(BELA_IDE_SCREEN_NAME) quit > /dev/null
giuliomoro@374 59
giuliomoro@64 60 RM := rm -rf
giuliomoro@64 61 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
l@260 62 LIBS := -lrt -lnative -lxenomai -lsndfile
l@260 63
giuliomoro@244 64 # refresh library cache and check if libpd is there
giuliomoro@326 65 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking
giuliomoro@326 66 LIBPD_PATH = /usr/lib/libpd.so
giuliomoro@326 67 TEST_LIBPD := $(shell which $(LIBPD_PATH))
giuliomoro@326 68 ifneq ($(strip $(TEST_LIBPD)), )
giuliomoro@244 69 # if libpd is there, link it in
giuliomoro@244 70 LIBS += -lpd -lpthread_rt
giuliomoro@244 71 endif
giuliomoro@64 72
giuliomoro@241 73 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
giuliomoro@241 74 C_FLAGS := $(CPP_FLAGS)
giuliomoro@241 75
giuliomoro@241 76 ifndef COMPILER
giuliomoro@241 77 # check whether clang is installed
giuliomoro@385 78 TEST_COMPILER := $(shell which clang)
giuliomoro@302 79 ifneq ($(strip $(TEST_COMPILER)), )
giuliomoro@385 80 #if it is installed, use it
giuliomoro@302 81 COMPILER := clang
giuliomoro@302 82 else
giuliomoro@241 83 COMPILER := gcc
giuliomoro@302 84 endif
giuliomoro@241 85 endif
giuliomoro@241 86
giuliomoro@241 87 ifeq ($(COMPILER), clang)
giuliomoro@306 88 CC=clang
giuliomoro@306 89 CXX=clang++
giuliomoro@302 90 CPP_FLAGS += -DNDEBUG
giuliomoro@302 91 C_FLAGS += -DNDEBUG
giuliomoro@241 92 else
giuliomoro@241 93 CC=gcc
giuliomoro@241 94 CXX=g++
giuliomoro@241 95 CPP_FLAGS += --fast-math
giuliomoro@241 96 C_FLAGS += --fast-math
giuliomoro@241 97 endif
giuliomoro@241 98
l@260 99 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 100
l@260 101 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
l@260 102 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
l@260 103 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
giuliomoro@64 104
l@260 105 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
l@260 106 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
l@260 107 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
giuliomoro@64 108
l@260 109 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
l@260 110 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
l@260 111 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
giuliomoro@64 112
giuliomoro@383 113 PROJECT_OBJS = $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS)
giuliomoro@383 114
giuliomoro@301 115 # Core Bela sources
giuliomoro@186 116 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
giuliomoro@186 117 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
giuliomoro@186 118 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
giuliomoro@64 119
andrewm@318 120 CORE_ASM_SRCS := $(wildcard core/*.S)
andrewm@318 121 CORE_ASM_OBJS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.o)))
andrewm@318 122 CORE_ASM_DEPS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.d)))
andrewm@318 123
andrewm@318 124
giuliomoro@64 125 # Objects for a system-supplied default main() file, if the user
giuliomoro@64 126 # only wants to provide the render functions.
giuliomoro@64 127 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
giuliomoro@64 128 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
giuliomoro@64 129 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
andrewm@68 130
giuliomoro@334 131 Bela: ## Builds the Bela program with all the opimizations
giuliomoro@334 132 Bela: $(OUTPUT_FILE)
giuliomoro@334 133
giuliomoro@301 134 # all = build Bela
giuliomoro@334 135 all: ## Same as Bela
andrewm@69 136 all: SYNTAX_FLAG :=
giuliomoro@301 137 all: Bela
andrewm@68 138
giuliomoro@301 139 # debug = buildBela debug
giuliomoro@334 140 debug: ## Same as Bela but with debug flags and no optimizations
giuliomoro@209 141 debug: CPP_FLAGS=-g
giuliomoro@209 142 debug: C_FLAGS=-g
giuliomoro@209 143 debug: all
giuliomoro@209 144
andrewm@69 145 # syntax = check syntax
giuliomoro@334 146 syntax: ## Only checks syntax
andrewm@69 147 syntax: SYNTAX_FLAG := -fsyntax-only
l@260 148 syntax: SYNTAX
andrewm@69 149
giuliomoro@301 150 # Rule for Bela core C++ files
giuliomoro@64 151 build/core/%.o: ./core/%.cpp
l@260 152 @echo 'Building $(notdir $<)...'
giuliomoro@386 153 # @echo 'Invoking: C++ Compiler $(CXX)'
l@260 154 @$(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 155 @echo ' ...done'
giuliomoro@64 156 @echo ' '
andrewm@68 157
andrewm@318 158 # Rule for Bela core ASM files
andrewm@318 159 build/core/%.o: ./core/%.S
andrewm@318 160 @echo 'Building $(notdir $<)...'
andrewm@318 161 # @echo 'Invoking: GCC Assembler'
andrewm@318 162 @as -o "$@" "$<"
andrewm@318 163 @echo ' ...done'
andrewm@318 164 @echo ' '
andrewm@318 165
giuliomoro@64 166 # Rule for user-supplied C++ files
l@260 167 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
l@260 168 @echo 'Building $(notdir $<)...'
l@389 169 # @echo 'Invoking: C++ Compiler $(CXX)'
l@260 170 @$(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 171 @echo ' ...done'
giuliomoro@64 172 @echo ' '
andrewm@68 173
giuliomoro@64 174 # Rule for user-supplied C files
l@260 175 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
l@260 176 @echo 'Building $(notdir $<)...'
giuliomoro@386 177 # @echo 'Invoking: C Compiler $(CC)'
giuliomoro@287 178 $(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 179 @echo ' ...done'
giuliomoro@64 180 @echo ' '
andrewm@68 181
giuliomoro@64 182 # Rule for user-supplied assembly files
l@260 183 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
l@260 184 @echo 'Building $(notdir $<)...'
l@260 185 # @echo 'Invoking: GCC Assembler'
l@260 186 @as -o "$@" "$<"
l@260 187 @echo ' ...done'
giuliomoro@64 188 @echo ' '
giuliomoro@64 189
giuliomoro@64 190 # This is a nasty kludge: we want to be able to optionally link in a default
giuliomoro@64 191 # main file if the user hasn't supplied one. We check for the presence of the main()
giuliomoro@64 192 # function, and conditionally call one of two recursive make targets depending on whether
giuliomoro@64 193 # we want to link in the default main file or not. The kludge is the mess of a shell script
giuliomoro@64 194 # line below. Surely there's a better way to do this?
giuliomoro@383 195 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
giuliomoro@383 196 $(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 197 @echo 'Linking...'
andrewm@318 198 @$(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 199 @echo ' ...done'
l@387 200
l@260 201 # Other Targets:
l@260 202 # This rule compiles c and c++ source files without output or linking
l@260 203 SYNTAX: $(C_OBJS) $(CPP_OBJS)
giuliomoro@64 204
giuliomoro@385 205 projectclean:## Remove the project's build objects & binary
giuliomoro@326 206 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE)
giuliomoro@64 207 -@echo ' '
giuliomoro@64 208
giuliomoro@386 209 clean: ## Same as projectclean
giuliomoro@386 210 clean: projectclean
giuliomoro@386 211
giuliomoro@386 212 coreclean: ## Remove the core's build objects
giuliomoro@394 213 -$(RM) build/core/*
giuliomoro@386 214
giuliomoro@386 215 prompt:
giuliomoro@386 216 @printf "Warning: you are about to DELETE the projects/ folder and its content. This operation cannot be undone. Continue? (y/N) "
giuliomoro@386 217 @read REPLY; if [ $$REPLY != y ] && [ $$REPLY != Y ]; then echo "Aborting..."; exit 1; fi
giuliomoro@386 218
giuliomoro@386 219 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 220 distclean: prompt distcleannoprompt
giuliomoro@386 221
giuliomoro@386 222 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care.
giuliomoro@326 223 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE)
giuliomoro@64 224 -@echo ' '
giuliomoro@64 225
giuliomoro@302 226 runfg: run
giuliomoro@334 227 run: ## Run PROJECT in the foreground
giuliomoro@326 228 run: stop Bela
giuliomoro@327 229 @echo "Running $(RUN_COMMAND)"
l@387 230 @cd $(PROJECT_DIR) && sync& $(RUN_COMMAND)
l@387 231 runide: ## Run PROJECT for IDE (foreground, without stop or build, suppressed output, no buffering)
l@387 232 runide: Bela
l@387 233 @cd $(PROJECT_DIR) && sync& $(RUN_IDE_COMMAND)
giuliomoro@334 234 runscreen: ## Run PROJECT in the background (detached screen)
giuliomoro@302 235 runscreen: stop $(OUTPUT_FILE)
giuliomoro@327 236 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 237 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND)
giuliomoro@334 238 runscreenfg: ## Run PROJECT in a screen in the foreground (can detach with ctrl-a ctrl-d)
giuliomoro@313 239 runscreenfg: stop $(OUTPUT_FILE)
giuliomoro@327 240 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 241 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND)
giuliomoro@313 242 FIFO_NAME=/tmp/belafifo
giuliomoro@334 243 runscreenfifo: ## Same as runscreen, but stdout and stderr are piped to the foreground through a fifo
giuliomoro@313 244 runscreenfifo: stop $(OUTPUT_FILE)
giuliomoro@313 245 @echo "Running $(RUN_COMMAND), piping output to $(FIFO_NAME)"
giuliomoro@313 246 @rm -rf $(FIFO_NAME)
giuliomoro@313 247 @mkfifo $(FIFO_NAME)
giuliomoro@327 248 @cd $(PROJECT_DIR)
giuliomoro@315 249 @screen -S $(SCREEN_NAME) -d -m stdbuf -e 0 -i 0 -o 0 bash -c "$(RUN_COMMAND) &> $(FIFO_NAME)"
giuliomoro@315 250 @cat /tmp/belafifo
giuliomoro@302 251
giuliomoro@331 252 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 253 nostartup: ## No Bela project runs at startup
giuliomoro@331 254 nostartup:
andrewm@391 255 @echo "Disabling Bela at startup..."
giuliomoro@344 256 @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 257
giuliomoro@334 258 startuploop: ## Makes PROJECT run at startup and restarts it if it crashes
giuliomoro@331 259 startuploop: Bela
giuliomoro@331 260 @echo "Enabling Bela at startup in a loop..."
giuliomoro@331 261 @$(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 262
giuliomoro@334 263 startup: ## Makes PROJECT run at startup
giuliomoro@331 264 startup: Bela
giuliomoro@331 265 @echo "Enabling Bela at startup..."
giuliomoro@331 266 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 267
giuliomoro@334 268 stop: ## Stops any Bela program that is currently running
giuliomoro@302 269 stop:
giuliomoro@302 270 @PID=`grep $(BELA_AUDIO_THREAD_NAME) /proc/xenomai/stat | cut -d " " -f 5 | sed s/\s//g`; if [ -z $$PID ]; then echo "No process to kill"; else echo "Killing old Bela process $$PID"; kill -2 $$PID; fi; screen -X -S $(SCREEN_NAME) quit > /dev/null; exit 0;
giuliomoro@64 271
giuliomoro@393 272 iderun: ## Starts the on-board IDE
giuliomoro@393 273 iderun:
giuliomoro@393 274 $(BELA_IDE_RUN_COMMAND)
giuliomoro@393 275
giuliomoro@393 276 idestop: ## Stops the on-board IDE
giuliomoro@393 277 @echo TODO
giuliomoro@393 278 @exit 1
giuliomoro@393 279
giuliomoro@393 280 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 281
giuliomoro@399 282 idestartup: ## Enables the IDE at startup
giuliomoro@393 283 @echo "Enabling the IDE at startup"
giuliomoro@393 284 $(BELA_IDE_STARTUP_COMMAND)
giuliomoro@393 285 @chmod +x $(BELA_IDE_STARTUP_SCRIPT)
giuliomoro@393 286
giuliomoro@393 287 idenostartup: ## Disables the IDE at startup
giuliomoro@393 288 @echo "Disabling the IDE at startup"
giuliomoro@393 289 @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@393 290 .PHONY: all clean distclean help projectclean nostartup startup startuploop debug run runfg runscreen runscreenfg runscreenfifo stop iderun idestop iderunup idenostartup