annotate Makefile @ 387:47612dcb44de prerelease

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