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