annotate Makefile @ 394:b6b13f669174 prerelease

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