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@287
|
29
|
giuliomoro@302
|
30 SCREEN_NAME?=BeagleRT
|
giuliomoro@302
|
31
|
giuliomoro@304
|
32 #TODO: run these lines only if the command is not syntax or
|
giuliomoro@267
|
33 $(shell mkdir -p $(PROJECT_DIR)/build)
|
giuliomoro@64
|
34 RM := rm -rf
|
giuliomoro@64
|
35 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
|
l@260
|
36 LIBS := -lrt -lnative -lxenomai -lsndfile
|
l@260
|
37
|
giuliomoro@244
|
38 # refresh library cache and check if libpd is there
|
giuliomoro@244
|
39 TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so")
|
giuliomoro@244
|
40 ifeq ($(strip $(TEST_LIBPD)), )
|
giuliomoro@244
|
41 else
|
giuliomoro@244
|
42 # if libpd is there, link it in
|
giuliomoro@244
|
43 LIBS += -lpd -lpthread_rt
|
giuliomoro@244
|
44 endif
|
giuliomoro@64
|
45
|
giuliomoro@241
|
46 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
|
giuliomoro@241
|
47 C_FLAGS := $(CPP_FLAGS)
|
giuliomoro@241
|
48
|
giuliomoro@241
|
49 ifndef COMPILER
|
giuliomoro@241
|
50 # check whether clang is installed
|
giuliomoro@295
|
51 # TEST_COMPILER := $(shell which clang)
|
giuliomoro@302
|
52 ifneq ($(strip $(TEST_COMPILER)), )
|
giuliomoro@302
|
53 if it is installed, use it
|
giuliomoro@302
|
54 COMPILER := clang
|
giuliomoro@302
|
55 else
|
giuliomoro@241
|
56 COMPILER := gcc
|
giuliomoro@302
|
57 endif
|
giuliomoro@241
|
58 endif
|
giuliomoro@241
|
59
|
giuliomoro@241
|
60 ifeq ($(COMPILER), clang)
|
giuliomoro@306
|
61 CC=clang
|
giuliomoro@306
|
62 CXX=clang++
|
giuliomoro@302
|
63 CPP_FLAGS += -DNDEBUG
|
giuliomoro@302
|
64 C_FLAGS += -DNDEBUG
|
giuliomoro@241
|
65 else
|
giuliomoro@241
|
66 CC=gcc
|
giuliomoro@241
|
67 CXX=g++
|
giuliomoro@241
|
68 CPP_FLAGS += --fast-math
|
giuliomoro@241
|
69 C_FLAGS += --fast-math
|
giuliomoro@241
|
70 endif
|
giuliomoro@241
|
71
|
l@260
|
72 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
|
73
|
l@260
|
74 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
|
l@260
|
75 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
|
l@260
|
76 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
|
giuliomoro@64
|
77
|
l@260
|
78 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
|
l@260
|
79 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
|
l@260
|
80 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
|
giuliomoro@64
|
81
|
l@260
|
82 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
|
l@260
|
83 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
|
l@260
|
84 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
85
|
giuliomoro@301
|
86 # Core Bela sources
|
giuliomoro@186
|
87 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
|
giuliomoro@186
|
88 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
|
giuliomoro@186
|
89 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
90
|
andrewm@318
|
91 CORE_ASM_SRCS := $(wildcard core/*.S)
|
andrewm@318
|
92 CORE_ASM_OBJS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.o)))
|
andrewm@318
|
93 CORE_ASM_DEPS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.d)))
|
andrewm@318
|
94
|
andrewm@318
|
95
|
giuliomoro@64
|
96 # Objects for a system-supplied default main() file, if the user
|
giuliomoro@64
|
97 # only wants to provide the render functions.
|
giuliomoro@64
|
98 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
|
giuliomoro@64
|
99 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
|
giuliomoro@64
|
100 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
|
andrewm@68
|
101
|
giuliomoro@301
|
102 # all = build Bela
|
andrewm@69
|
103 all: SYNTAX_FLAG :=
|
giuliomoro@301
|
104 all: Bela
|
andrewm@68
|
105
|
giuliomoro@301
|
106 # debug = buildBela debug
|
giuliomoro@209
|
107 debug: CPP_FLAGS=-g
|
giuliomoro@209
|
108 debug: C_FLAGS=-g
|
giuliomoro@209
|
109 debug: all
|
giuliomoro@209
|
110
|
andrewm@69
|
111 # syntax = check syntax
|
andrewm@69
|
112 syntax: SYNTAX_FLAG := -fsyntax-only
|
l@260
|
113 syntax: SYNTAX
|
andrewm@69
|
114
|
giuliomoro@302
|
115
|
giuliomoro@302
|
116
|
giuliomoro@301
|
117 # Rule for Bela core C++ files
|
giuliomoro@64
|
118 build/core/%.o: ./core/%.cpp
|
l@260
|
119 @echo 'Building $(notdir $<)...'
|
l@260
|
120 # @echo 'Invoking: C++ Compiler'
|
l@260
|
121 @$(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
|
122 @echo ' ...done'
|
giuliomoro@64
|
123 @echo ' '
|
andrewm@68
|
124
|
andrewm@318
|
125 # Rule for Bela core ASM files
|
andrewm@318
|
126 build/core/%.o: ./core/%.S
|
andrewm@318
|
127 @echo 'Building $(notdir $<)...'
|
andrewm@318
|
128 # @echo 'Invoking: GCC Assembler'
|
andrewm@318
|
129 @as -o "$@" "$<"
|
andrewm@318
|
130 @echo ' ...done'
|
andrewm@318
|
131 @echo ' '
|
andrewm@318
|
132
|
giuliomoro@64
|
133 # Rule for user-supplied C++ files
|
l@260
|
134 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
|
l@260
|
135 @echo 'Building $(notdir $<)...'
|
l@260
|
136 # @echo 'Invoking: C++ Compiler'
|
l@260
|
137 @$(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
|
138 @echo ' ...done'
|
giuliomoro@64
|
139 @echo ' '
|
andrewm@68
|
140
|
giuliomoro@64
|
141 # Rule for user-supplied C files
|
l@260
|
142 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
|
l@260
|
143 @echo 'Building $(notdir $<)...'
|
l@260
|
144 # @echo 'Invoking: C Compiler'
|
giuliomoro@287
|
145 $(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
|
146 @echo ' ...done'
|
giuliomoro@64
|
147 @echo ' '
|
andrewm@68
|
148
|
giuliomoro@64
|
149 # Rule for user-supplied assembly files
|
l@260
|
150 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
|
l@260
|
151 @echo 'Building $(notdir $<)...'
|
l@260
|
152 # @echo 'Invoking: GCC Assembler'
|
l@260
|
153 @as -o "$@" "$<"
|
l@260
|
154 @echo ' ...done'
|
giuliomoro@64
|
155 @echo ' '
|
giuliomoro@64
|
156
|
giuliomoro@64
|
157 # This is a nasty kludge: we want to be able to optionally link in a default
|
giuliomoro@64
|
158 # main file if the user hasn't supplied one. We check for the presence of the main()
|
giuliomoro@64
|
159 # function, and conditionally call one of two recursive make targets depending on whether
|
giuliomoro@64
|
160 # we want to link in the default main file or not. The kludge is the mess of a shell script
|
giuliomoro@64
|
161 # line below. Surely there's a better way to do this?
|
andrewm@318
|
162 Bela: $(CORE_ASM_OBJS) $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
|
giuliomoro@287
|
163 $(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
|
164 @echo 'Invoking: C++ linker'
|
andrewm@318
|
165 @$(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
|
166 @echo 'Finished building target: $@'
|
andrewm@68
|
167
|
l@260
|
168 # Other Targets:
|
l@260
|
169 # This rule compiles c and c++ source files without output or linking
|
l@260
|
170 SYNTAX: $(C_OBJS) $(CPP_OBJS)
|
giuliomoro@64
|
171
|
l@260
|
172 # Remove the project's build objects & binary
|
l@260
|
173 projectclean:
|
l@260
|
174 -$(RM) $(PROJECT_DIR)/build/* $(PROJECT_DIR)/$(PROJECT)
|
giuliomoro@64
|
175 -@echo ' '
|
giuliomoro@64
|
176
|
giuliomoro@301
|
177 # Remove all the built objects, including the core Bela objects
|
giuliomoro@64
|
178 distclean:
|
giuliomoro@301
|
179 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) Bela
|
giuliomoro@64
|
180 -@echo ' '
|
giuliomoro@287
|
181 OUTPUT_FILE="$(PROJECT_DIR)/$(PROJECT)"
|
giuliomoro@64
|
182
|
giuliomoro@301
|
183 $(OUTPUT_FILE): Bela
|
giuliomoro@313
|
184 COMMAND_LINE_OPTIONS=$(CL)
|
giuliomoro@313
|
185 RUN_COMMAND=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS)
|
giuliomoro@302
|
186 runfg: run
|
giuliomoro@304
|
187 run: stop $(OUTPUT_FILE)
|
giuliomoro@313
|
188 echo "Running $(RUN_COMMAND)"
|
giuliomoro@313
|
189 $(RUN_COMMAND)
|
giuliomoro@302
|
190 runscreen: stop $(OUTPUT_FILE)
|
giuliomoro@313
|
191 echo "Running $(RUN_COMMAND) in a screen"
|
giuliomoro@313
|
192 screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND)
|
giuliomoro@313
|
193 runscreenfg: stop $(OUTPUT_FILE)
|
giuliomoro@313
|
194 echo "Running $(RUN_COMMAND) in a screen"
|
giuliomoro@313
|
195 screen -S $(SCREEN_NAME) -m $(RUN_COMMAND)
|
giuliomoro@313
|
196 FIFO_NAME=/tmp/belafifo
|
giuliomoro@313
|
197 runscreenfifo: stop $(OUTPUT_FILE)
|
giuliomoro@313
|
198 @echo "Running $(RUN_COMMAND), piping output to $(FIFO_NAME)"
|
giuliomoro@313
|
199 @rm -rf $(FIFO_NAME)
|
giuliomoro@313
|
200 @mkfifo $(FIFO_NAME)
|
giuliomoro@315
|
201 @screen -S $(SCREEN_NAME) -d -m stdbuf -e 0 -i 0 -o 0 bash -c "$(RUN_COMMAND) &> $(FIFO_NAME)"
|
giuliomoro@315
|
202 @cat /tmp/belafifo
|
giuliomoro@302
|
203
|
giuliomoro@302
|
204 BELA_AUDIO_THREAD_NAME=beaglert-audio
|
giuliomoro@302
|
205 stop:
|
giuliomoro@302
|
206 @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
|
207 # Remove only the user-generated objects
|
l@260
|
208 #clean:
|
giuliomoro@301
|
209 # -$(RM) build/source/* Bela
|
l@260
|
210 # -@echo ' '
|
giuliomoro@64
|
211
|
giuliomoro@64
|
212 post-build:
|
giuliomoro@64
|
213 # Nothing to do here (for now)
|
giuliomoro@64
|
214
|
giuliomoro@287
|
215 .PHONY: all clean distclean projectclean dependents debug run
|
giuliomoro@64
|
216 .SECONDARY: post-build
|