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 EXAMPLE:=that
|
giuliomoro@287
|
29 endif
|
giuliomoro@287
|
30
|
giuliomoro@302
|
31 SCREEN_NAME?=BeagleRT
|
giuliomoro@302
|
32
|
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@302
|
49 COMPILER=clang
|
giuliomoro@241
|
50 ifndef COMPILER
|
giuliomoro@241
|
51 # check whether clang is installed
|
giuliomoro@295
|
52 # TEST_COMPILER := $(shell which clang)
|
giuliomoro@302
|
53 ifneq ($(strip $(TEST_COMPILER)), )
|
giuliomoro@302
|
54 if it is installed, use it
|
giuliomoro@302
|
55 COMPILER := clang
|
giuliomoro@302
|
56 else
|
giuliomoro@241
|
57 COMPILER := gcc
|
giuliomoro@302
|
58 endif
|
giuliomoro@241
|
59 endif
|
giuliomoro@241
|
60
|
giuliomoro@241
|
61 ifeq ($(COMPILER), clang)
|
giuliomoro@302
|
62 CC=/root/clang/bin/clang
|
giuliomoro@302
|
63 CXX=/root/clang/bin/clang++
|
giuliomoro@302
|
64 CPP_FLAGS += -DNDEBUG
|
giuliomoro@302
|
65 C_FLAGS += -DNDEBUG
|
giuliomoro@241
|
66 else
|
giuliomoro@241
|
67 CC=gcc
|
giuliomoro@241
|
68 CXX=g++
|
giuliomoro@241
|
69 CPP_FLAGS += --fast-math
|
giuliomoro@241
|
70 C_FLAGS += --fast-math
|
giuliomoro@241
|
71 endif
|
giuliomoro@241
|
72
|
l@260
|
73 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
|
74
|
l@260
|
75 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
|
l@260
|
76 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
|
l@260
|
77 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
|
giuliomoro@64
|
78
|
l@260
|
79 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
|
l@260
|
80 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
|
l@260
|
81 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
|
giuliomoro@64
|
82
|
l@260
|
83 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
|
l@260
|
84 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
|
l@260
|
85 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
86
|
giuliomoro@301
|
87 # Core Bela sources
|
giuliomoro@186
|
88 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
|
giuliomoro@186
|
89 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
|
giuliomoro@186
|
90 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
91
|
giuliomoro@64
|
92 # Objects for a system-supplied default main() file, if the user
|
giuliomoro@64
|
93 # only wants to provide the render functions.
|
giuliomoro@64
|
94 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
|
giuliomoro@64
|
95 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
|
giuliomoro@64
|
96 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
|
andrewm@68
|
97
|
giuliomoro@301
|
98 # all = build Bela
|
andrewm@69
|
99 all: SYNTAX_FLAG :=
|
giuliomoro@301
|
100 all: Bela
|
andrewm@68
|
101
|
giuliomoro@301
|
102 # debug = buildBela debug
|
giuliomoro@209
|
103 debug: CPP_FLAGS=-g
|
giuliomoro@209
|
104 debug: C_FLAGS=-g
|
giuliomoro@209
|
105 debug: all
|
giuliomoro@209
|
106
|
andrewm@69
|
107 # syntax = check syntax
|
andrewm@69
|
108 syntax: SYNTAX_FLAG := -fsyntax-only
|
l@260
|
109 syntax: SYNTAX
|
andrewm@69
|
110
|
giuliomoro@302
|
111
|
giuliomoro@302
|
112
|
giuliomoro@301
|
113 # Rule for Bela core C++ files
|
giuliomoro@64
|
114 build/core/%.o: ./core/%.cpp
|
l@260
|
115 @echo 'Building $(notdir $<)...'
|
l@260
|
116 # @echo 'Invoking: C++ Compiler'
|
l@260
|
117 @$(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
|
118 @echo ' ...done'
|
giuliomoro@64
|
119 @echo ' '
|
andrewm@68
|
120
|
giuliomoro@64
|
121 # Rule for user-supplied C++ files
|
l@260
|
122 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
|
l@260
|
123 @echo 'Building $(notdir $<)...'
|
l@260
|
124 # @echo 'Invoking: C++ Compiler'
|
l@260
|
125 @$(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
|
126 @echo ' ...done'
|
giuliomoro@64
|
127 @echo ' '
|
andrewm@68
|
128
|
giuliomoro@64
|
129 # Rule for user-supplied C files
|
l@260
|
130 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
|
l@260
|
131 @echo 'Building $(notdir $<)...'
|
l@260
|
132 # @echo 'Invoking: C Compiler'
|
giuliomoro@287
|
133 $(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
|
134 @echo ' ...done'
|
giuliomoro@64
|
135 @echo ' '
|
andrewm@68
|
136
|
giuliomoro@64
|
137 # Rule for user-supplied assembly files
|
l@260
|
138 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
|
l@260
|
139 @echo 'Building $(notdir $<)...'
|
l@260
|
140 # @echo 'Invoking: GCC Assembler'
|
l@260
|
141 @as -o "$@" "$<"
|
l@260
|
142 @echo ' ...done'
|
giuliomoro@64
|
143 @echo ' '
|
giuliomoro@64
|
144
|
giuliomoro@64
|
145 # This is a nasty kludge: we want to be able to optionally link in a default
|
giuliomoro@64
|
146 # main file if the user hasn't supplied one. We check for the presence of the main()
|
giuliomoro@64
|
147 # function, and conditionally call one of two recursive make targets depending on whether
|
giuliomoro@64
|
148 # we want to link in the default main file or not. The kludge is the mess of a shell script
|
giuliomoro@64
|
149 # line below. Surely there's a better way to do this?
|
giuliomoro@301
|
150 Bela: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
|
giuliomoro@287
|
151 $(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
|
152 @echo 'Invoking: C++ linker'
|
giuliomoro@287
|
153 @$(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_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
|
giuliomoro@287
|
154 @echo 'Finished building target: $@'
|
andrewm@68
|
155
|
l@260
|
156 # Other Targets:
|
l@260
|
157 # This rule compiles c and c++ source files without output or linking
|
l@260
|
158 SYNTAX: $(C_OBJS) $(CPP_OBJS)
|
giuliomoro@64
|
159
|
l@260
|
160 # Remove the project's build objects & binary
|
l@260
|
161 projectclean:
|
l@260
|
162 -$(RM) $(PROJECT_DIR)/build/* $(PROJECT_DIR)/$(PROJECT)
|
giuliomoro@64
|
163 -@echo ' '
|
giuliomoro@64
|
164
|
giuliomoro@301
|
165 # Remove all the built objects, including the core Bela objects
|
giuliomoro@64
|
166 distclean:
|
giuliomoro@301
|
167 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) Bela
|
giuliomoro@64
|
168 -@echo ' '
|
giuliomoro@287
|
169 OUTPUT_FILE="$(PROJECT_DIR)/$(PROJECT)"
|
giuliomoro@64
|
170
|
giuliomoro@301
|
171 $(OUTPUT_FILE): Bela
|
giuliomoro@302
|
172 runfg: run
|
giuliomoro@287
|
173 run: $(OUTPUT_FILE)
|
giuliomoro@287
|
174 @echo "Running $(OUTPUT_FILE)"
|
giuliomoro@287
|
175 @$(OUTPUT_FILE)
|
giuliomoro@302
|
176
|
giuliomoro@302
|
177 runscreen: stop $(OUTPUT_FILE)
|
giuliomoro@302
|
178 runscreen:
|
giuliomoro@302
|
179 @echo "Running $(OUTPUT_FILE) in a screen"
|
giuliomoro@302
|
180
|
giuliomoro@302
|
181 BELA_AUDIO_THREAD_NAME=beaglert-audio
|
giuliomoro@302
|
182 stop:
|
giuliomoro@302
|
183 @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
|
184 # Remove only the user-generated objects
|
l@260
|
185 #clean:
|
giuliomoro@301
|
186 # -$(RM) build/source/* Bela
|
l@260
|
187 # -@echo ' '
|
giuliomoro@64
|
188
|
giuliomoro@64
|
189 post-build:
|
giuliomoro@64
|
190 # Nothing to do here (for now)
|
giuliomoro@64
|
191
|
giuliomoro@287
|
192 .PHONY: all clean distclean projectclean dependents debug run
|
giuliomoro@64
|
193 .SECONDARY: post-build
|