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