annotate Makefile @ 377:a430a16d2c02 prerelease

Updated scripts so that the Bela folder on the bbb is ~/Bela. Note: BeagleRT_startup.sh is still the same (because the reference to it needs to be changed in /etc/init.d/ ....
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 11 Jun 2016 01:54:43 +0100
parents ecad1ea0382a
children 9dc5a0ccad25
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
l@260 9 # set the project to be compiled by calling: make all PROJECT=<project_name>
l@260 10
l@260 11 # if the PROJECT variable is not set, throw an error and exit
giuliomoro@265 12 # otherwise, we could have unexpected data loss when calling clean without it
giuliomoro@374 13 NO_PROJECT_TARGETS=distclean stop
giuliomoro@374 14 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS)))
giuliomoro@374 15 ifndef PROJECT
giuliomoro@374 16 ifndef EXAMPLE
giuliomoro@374 17 $(error PROJECT or EXAMPLE should be set when the target is not one of: `$(NO_PROJECT_TARGETS)`)
giuliomoro@374 18 endif
giuliomoro@287 19 endif
l@260 20 endif
l@260 21
giuliomoro@374 22 # if we are building an example, just copy it to the projects/ folder
giuliomoro@374 23 # and tehn treat it as a project
giuliomoro@374 24 ifdef EXAMPLE
giuliomoro@374 25 PROJECT?=exampleTempProject
giuliomoro@374 26 PROJECT_DIR?=$(abspath projects/$(PROJECT))
giuliomoro@374 27 $(shell mkdir -p $(abspath projects)
giuliomoro@374 28 $(shell rm -rf $(PROJECT_DIR))
giuliomoro@374 29 $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR))
giuliomoro@374 30 else
giuliomoro@287 31 PROJECT_DIR := $(abspath projects/$(PROJECT))
giuliomoro@287 32 endif
giuliomoro@287 33
giuliomoro@374 34 ifdef PROJECT
giuliomoro@374 35 $(shell mkdir -p $(PROJECT_DIR)/build)
giuliomoro@287 36 endif
giuliomoro@374 37
giuliomoro@331 38 OUTPUT_FILE?=$(PROJECT_DIR)/$(PROJECT)
giuliomoro@331 39 COMMAND_LINE_OPTIONS?=$(CL)
giuliomoro@331 40 RUN_COMMAND?=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS)
giuliomoro@331 41 BELA_STARTUP_SCRIPT?=/root/BeagleRT_startup.sh
giuliomoro@359 42 BELA_AUDIO_THREAD_NAME?=bela-audio
giuliomoro@377 43 SCREEN_NAME?=Bela
giuliomoro@302 44
giuliomoro@374 45
giuliomoro@64 46 RM := rm -rf
giuliomoro@64 47 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
l@260 48 LIBS := -lrt -lnative -lxenomai -lsndfile
l@260 49
giuliomoro@244 50 # refresh library cache and check if libpd is there
giuliomoro@326 51 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking
giuliomoro@326 52 LIBPD_PATH = /usr/lib/libpd.so
giuliomoro@326 53 TEST_LIBPD := $(shell which $(LIBPD_PATH))
giuliomoro@326 54 ifneq ($(strip $(TEST_LIBPD)), )
giuliomoro@244 55 # if libpd is there, link it in
giuliomoro@244 56 LIBS += -lpd -lpthread_rt
giuliomoro@244 57 endif
giuliomoro@64 58
giuliomoro@241 59 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
giuliomoro@241 60 C_FLAGS := $(CPP_FLAGS)
giuliomoro@241 61
giuliomoro@241 62 ifndef COMPILER
giuliomoro@241 63 # check whether clang is installed
giuliomoro@295 64 # TEST_COMPILER := $(shell which clang)
giuliomoro@302 65 ifneq ($(strip $(TEST_COMPILER)), )
giuliomoro@302 66 if it is installed, use it
giuliomoro@302 67 COMPILER := clang
giuliomoro@302 68 else
giuliomoro@241 69 COMPILER := gcc
giuliomoro@302 70 endif
giuliomoro@241 71 endif
giuliomoro@241 72
giuliomoro@241 73 ifeq ($(COMPILER), clang)
giuliomoro@306 74 CC=clang
giuliomoro@306 75 CXX=clang++
giuliomoro@302 76 CPP_FLAGS += -DNDEBUG
giuliomoro@302 77 C_FLAGS += -DNDEBUG
giuliomoro@241 78 else
giuliomoro@241 79 CC=gcc
giuliomoro@241 80 CXX=g++
giuliomoro@241 81 CPP_FLAGS += --fast-math
giuliomoro@241 82 C_FLAGS += --fast-math
giuliomoro@241 83 endif
giuliomoro@241 84
l@260 85 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 86
l@260 87 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
l@260 88 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
l@260 89 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
giuliomoro@64 90
l@260 91 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
l@260 92 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
l@260 93 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
giuliomoro@64 94
l@260 95 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
l@260 96 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
l@260 97 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
giuliomoro@64 98
giuliomoro@301 99 # Core Bela sources
giuliomoro@186 100 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
giuliomoro@186 101 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
giuliomoro@186 102 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
giuliomoro@64 103
andrewm@318 104 CORE_ASM_SRCS := $(wildcard core/*.S)
andrewm@318 105 CORE_ASM_OBJS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.o)))
andrewm@318 106 CORE_ASM_DEPS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.d)))
andrewm@318 107
andrewm@318 108
giuliomoro@64 109 # Objects for a system-supplied default main() file, if the user
giuliomoro@64 110 # only wants to provide the render functions.
giuliomoro@64 111 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
giuliomoro@64 112 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
giuliomoro@64 113 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
andrewm@68 114
giuliomoro@334 115 Bela: ## Builds the Bela program with all the opimizations
giuliomoro@334 116 Bela: $(OUTPUT_FILE)
giuliomoro@334 117
giuliomoro@301 118 # all = build Bela
giuliomoro@334 119 all: ## Same as Bela
andrewm@69 120 all: SYNTAX_FLAG :=
giuliomoro@301 121 all: Bela
andrewm@68 122
giuliomoro@301 123 # debug = buildBela debug
giuliomoro@334 124 debug: ## Same as Bela but with debug flags and no optimizations
giuliomoro@209 125 debug: CPP_FLAGS=-g
giuliomoro@209 126 debug: C_FLAGS=-g
giuliomoro@209 127 debug: all
giuliomoro@209 128
andrewm@69 129 # syntax = check syntax
giuliomoro@334 130 syntax: ## Only checks syntax
andrewm@69 131 syntax: SYNTAX_FLAG := -fsyntax-only
l@260 132 syntax: SYNTAX
andrewm@69 133
giuliomoro@301 134 # Rule for Bela core C++ files
giuliomoro@64 135 build/core/%.o: ./core/%.cpp
l@260 136 @echo 'Building $(notdir $<)...'
l@260 137 # @echo 'Invoking: C++ Compiler'
l@260 138 @$(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 139 @echo ' ...done'
giuliomoro@64 140 @echo ' '
andrewm@68 141
andrewm@318 142 # Rule for Bela core ASM files
andrewm@318 143 build/core/%.o: ./core/%.S
andrewm@318 144 @echo 'Building $(notdir $<)...'
andrewm@318 145 # @echo 'Invoking: GCC Assembler'
andrewm@318 146 @as -o "$@" "$<"
andrewm@318 147 @echo ' ...done'
andrewm@318 148 @echo ' '
andrewm@318 149
giuliomoro@64 150 # Rule for user-supplied C++ files
l@260 151 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
l@260 152 @echo 'Building $(notdir $<)...'
l@260 153 # @echo 'Invoking: C++ Compiler'
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
giuliomoro@64 158 # Rule for user-supplied C files
l@260 159 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
l@260 160 @echo 'Building $(notdir $<)...'
l@260 161 # @echo 'Invoking: C Compiler'
giuliomoro@287 162 $(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 163 @echo ' ...done'
giuliomoro@64 164 @echo ' '
andrewm@68 165
giuliomoro@64 166 # Rule for user-supplied assembly files
l@260 167 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
l@260 168 @echo 'Building $(notdir $<)...'
l@260 169 # @echo 'Invoking: GCC Assembler'
l@260 170 @as -o "$@" "$<"
l@260 171 @echo ' ...done'
giuliomoro@64 172 @echo ' '
giuliomoro@64 173
giuliomoro@64 174 # This is a nasty kludge: we want to be able to optionally link in a default
giuliomoro@64 175 # main file if the user hasn't supplied one. We check for the presence of the main()
giuliomoro@64 176 # function, and conditionally call one of two recursive make targets depending on whether
giuliomoro@64 177 # we want to link in the default main file or not. The kludge is the mess of a shell script
giuliomoro@64 178 # line below. Surely there's a better way to do this?
giuliomoro@326 179 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
giuliomoro@287 180 $(eval DEFAULT_MAIN_CONDITIONAL := $(shell bash -c 'if [ `nm $(PROJECT_DIR)/build/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "$(DEFAULT_MAIN_OBJS)"; else echo ""; fi'))
giuliomoro@287 181 @echo 'Invoking: C++ linker'
andrewm@318 182 @$(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)
giuliomoro@287 183 @echo 'Finished building target: $@'
giuliomoro@333 184 @sync
l@260 185 # Other Targets:
l@260 186 # This rule compiles c and c++ source files without output or linking
l@260 187 SYNTAX: $(C_OBJS) $(CPP_OBJS)
giuliomoro@64 188
l@260 189 # Remove the project's build objects & binary
l@260 190 projectclean:
giuliomoro@326 191 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE)
giuliomoro@64 192 -@echo ' '
giuliomoro@64 193
giuliomoro@301 194 # Remove all the built objects, including the core Bela objects
giuliomoro@64 195 distclean:
giuliomoro@326 196 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE)
giuliomoro@64 197 -@echo ' '
giuliomoro@64 198
giuliomoro@326 199
giuliomoro@302 200 runfg: run
giuliomoro@334 201 run: ## Run PROJECT in the foreground
giuliomoro@326 202 run: stop Bela
giuliomoro@327 203 @echo "Running $(RUN_COMMAND)"
giuliomoro@327 204 @cd $(PROJECT_DIR) && $(RUN_COMMAND)
giuliomoro@334 205 runscreen: ## Run PROJECT in the background (detached screen)
giuliomoro@302 206 runscreen: stop $(OUTPUT_FILE)
giuliomoro@327 207 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 208 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND)
giuliomoro@334 209 runscreenfg: ## Run PROJECT in a screen in the foreground (can detach with ctrl-a ctrl-d)
giuliomoro@313 210 runscreenfg: stop $(OUTPUT_FILE)
giuliomoro@327 211 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 212 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND)
giuliomoro@313 213 FIFO_NAME=/tmp/belafifo
giuliomoro@334 214 runscreenfifo: ## Same as runscreen, but stdout and stderr are piped to the foreground through a fifo
giuliomoro@313 215 runscreenfifo: stop $(OUTPUT_FILE)
giuliomoro@313 216 @echo "Running $(RUN_COMMAND), piping output to $(FIFO_NAME)"
giuliomoro@313 217 @rm -rf $(FIFO_NAME)
giuliomoro@313 218 @mkfifo $(FIFO_NAME)
giuliomoro@327 219 @cd $(PROJECT_DIR)
giuliomoro@315 220 @screen -S $(SCREEN_NAME) -d -m stdbuf -e 0 -i 0 -o 0 bash -c "$(RUN_COMMAND) &> $(FIFO_NAME)"
giuliomoro@315 221 @cat /tmp/belafifo
giuliomoro@302 222
giuliomoro@331 223 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 224 nostartup: ## No Bela project runs at startup
giuliomoro@331 225 nostartup:
giuliomoro@331 226 @echo "Disabling BeagleRT at startup..."
giuliomoro@344 227 @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 228
giuliomoro@334 229 startuploop: ## Makes PROJECT run at startup and restarts it if it crashes
giuliomoro@331 230 startuploop: Bela
giuliomoro@331 231 @echo "Enabling Bela at startup in a loop..."
giuliomoro@331 232 @$(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 233
giuliomoro@334 234 startup: ## Makes PROJECT run at startup
giuliomoro@331 235 startup: Bela
giuliomoro@331 236 @echo "Enabling Bela at startup..."
giuliomoro@331 237 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 238
giuliomoro@334 239 stop: ## Stops any Bela program that is currently running
giuliomoro@302 240 stop:
giuliomoro@302 241 @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 242 # Remove only the user-generated objects
l@260 243 #clean:
giuliomoro@301 244 # -$(RM) build/source/* Bela
l@260 245 # -@echo ' '
giuliomoro@64 246
giuliomoro@64 247 post-build:
giuliomoro@64 248 # Nothing to do here (for now)
giuliomoro@334 249 help: ## Show this help
giuliomoro@334 250 @echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]'
giuliomoro@334 251 @echo 'Targets: (default: Bela)'
giuliomoro@334 252 @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | column -t -c 2 -s '#'
giuliomoro@64 253
giuliomoro@326 254 .PHONY: all clean distclean projectclean dependents debug run runfg runscreen stop
giuliomoro@64 255 .SECONDARY: post-build