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