giuliomoro@64
|
1 # BeagleRT
|
giuliomoro@64
|
2 # Low-latency, real-time audio and sensor processing on BeagleBone Black
|
giuliomoro@64
|
3 # (c) 2015 Andrew McPherson, Victor Zappi, Giulio Moro
|
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
|
giuliomoro@64
|
9 RM := rm -rf
|
giuliomoro@64
|
10 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
|
giuliomoro@231
|
11 LIBS := -lrt -lnative -lxenomai -lsndfile -lpd
|
giuliomoro@64
|
12
|
giuliomoro@241
|
13 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
|
giuliomoro@241
|
14 C_FLAGS := $(CPP_FLAGS)
|
giuliomoro@241
|
15
|
giuliomoro@241
|
16 ifndef COMPILER
|
giuliomoro@241
|
17 # check whether clang is installed
|
giuliomoro@241
|
18 TEST_COMPILER := $(shell which clang)
|
giuliomoro@241
|
19 ifneq ($(strip $(TEST_COMPILER)), )
|
giuliomoro@241
|
20 # if it is installed, use it
|
giuliomoro@241
|
21 COMPILER := clang
|
giuliomoro@241
|
22 else
|
giuliomoro@241
|
23 COMPILER := gcc
|
giuliomoro@241
|
24 endif
|
giuliomoro@241
|
25 endif
|
giuliomoro@241
|
26
|
giuliomoro@241
|
27 ifeq ($(COMPILER), clang)
|
giuliomoro@241
|
28 CC=clang
|
giuliomoro@241
|
29 CXX=clang++
|
giuliomoro@241
|
30 CPP_FLAGS +=
|
giuliomoro@241
|
31 C _FLAGS +=
|
giuliomoro@241
|
32 else
|
giuliomoro@241
|
33 CC=gcc
|
giuliomoro@241
|
34 CXX=g++
|
giuliomoro@241
|
35 CPP_FLAGS += --fast-math
|
giuliomoro@241
|
36 C_FLAGS += --fast-math
|
giuliomoro@241
|
37 endif
|
giuliomoro@241
|
38
|
giuliomoro@186
|
39 INCLUDES := -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
|
40
|
giuliomoro@64
|
41 ASM_SRCS := $(wildcard source/*.S)
|
giuliomoro@64
|
42 ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o)))
|
giuliomoro@64
|
43 ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d)))
|
giuliomoro@64
|
44
|
giuliomoro@64
|
45 C_SRCS := $(wildcard source/*.c)
|
giuliomoro@64
|
46 C_OBJS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.o)))
|
giuliomoro@64
|
47 C_DEPS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.d)))
|
giuliomoro@64
|
48
|
giuliomoro@64
|
49 CPP_SRCS := $(wildcard source/*.cpp)
|
giuliomoro@64
|
50 CPP_OBJS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.o)))
|
giuliomoro@64
|
51 CPP_DEPS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
52
|
giuliomoro@64
|
53 # Core BeagleRT sources
|
giuliomoro@186
|
54 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
|
giuliomoro@186
|
55 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
|
giuliomoro@186
|
56 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
|
giuliomoro@64
|
57
|
giuliomoro@64
|
58 # Objects for a system-supplied default main() file, if the user
|
giuliomoro@64
|
59 # only wants to provide the render functions.
|
giuliomoro@64
|
60 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
|
giuliomoro@64
|
61 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
|
giuliomoro@64
|
62 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
|
andrewm@68
|
63
|
giuliomoro@209
|
64 # all = build BeagleRT
|
andrewm@69
|
65 all: SYNTAX_FLAG :=
|
giuliomoro@64
|
66 all: BeagleRT
|
andrewm@68
|
67
|
giuliomoro@209
|
68 # debug = buildBeagleRT debug
|
giuliomoro@209
|
69 debug: CPP_FLAGS=-g
|
giuliomoro@209
|
70 debug: C_FLAGS=-g
|
giuliomoro@209
|
71 debug: all
|
giuliomoro@209
|
72
|
andrewm@69
|
73 # syntax = check syntax
|
andrewm@69
|
74 syntax: SYNTAX_FLAG := -fsyntax-only
|
andrewm@69
|
75 syntax: BeagleRT
|
andrewm@69
|
76
|
giuliomoro@64
|
77 # Rule for BeagleRT core C++ files
|
giuliomoro@64
|
78 build/core/%.o: ./core/%.cpp
|
giuliomoro@64
|
79 @echo 'Building file: $<'
|
giuliomoro@241
|
80 @echo 'Invoking: C++ Compiler'
|
giuliomoro@241
|
81 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
|
giuliomoro@64
|
82 @echo 'Finished building: $<'
|
giuliomoro@64
|
83 @echo ' '
|
andrewm@68
|
84
|
giuliomoro@64
|
85 # Rule for user-supplied C++ files
|
giuliomoro@64
|
86 build/source/%.o: ./source/%.cpp
|
giuliomoro@64
|
87 @echo 'Building file: $<'
|
giuliomoro@241
|
88 @echo 'Invoking: C++ Compiler'
|
giuliomoro@241
|
89 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
|
giuliomoro@64
|
90 @echo 'Finished building: $<'
|
giuliomoro@64
|
91 @echo ' '
|
andrewm@68
|
92
|
giuliomoro@64
|
93 # Rule for user-supplied C files
|
giuliomoro@64
|
94 build/source/%.o: ./source/%.c
|
giuliomoro@64
|
95 @echo 'Building file: $<'
|
giuliomoro@241
|
96 @echo 'Invoking: C Compiler'
|
giuliomoro@241
|
97 $(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
|
giuliomoro@64
|
98 @echo 'Finished building: $<'
|
giuliomoro@64
|
99 @echo ' '
|
andrewm@68
|
100
|
giuliomoro@64
|
101 # Rule for user-supplied assembly files
|
giuliomoro@64
|
102 build/source/%.o: ./source/%.S
|
giuliomoro@64
|
103 @echo 'Building file: $<'
|
giuliomoro@64
|
104 @echo 'Invoking: GCC Assembler'
|
giuliomoro@64
|
105 as -o "$@" "$<"
|
giuliomoro@64
|
106 @echo 'Finished building: $<'
|
giuliomoro@64
|
107 @echo ' '
|
giuliomoro@64
|
108
|
giuliomoro@64
|
109 # This is a nasty kludge: we want to be able to optionally link in a default
|
giuliomoro@64
|
110 # main file if the user hasn't supplied one. We check for the presence of the main()
|
giuliomoro@64
|
111 # function, and conditionally call one of two recursive make targets depending on whether
|
giuliomoro@64
|
112 # we want to link in the default main file or not. The kludge is the mess of a shell script
|
giuliomoro@64
|
113 # line below. Surely there's a better way to do this?
|
giuliomoro@64
|
114 BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
|
giuliomoro@64
|
115 $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm build/source/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi'))
|
giuliomoro@64
|
116 $(MAKE) $(NEXT_TARGET)
|
giuliomoro@64
|
117 @echo 'Finished building target: $@'
|
giuliomoro@64
|
118 @echo ' '
|
giuliomoro@64
|
119 # $(MAKE) --no-print-directory post-build
|
andrewm@68
|
120
|
giuliomoro@64
|
121 # Rule for building BeagleRT including the default main file (no user-supplied main())
|
giuliomoro@64
|
122 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
|
giuliomoro@64
|
123 @echo 'Building target: $@'
|
giuliomoro@241
|
124 @echo 'Invoking: C++ Linker'
|
giuliomoro@241
|
125 $(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 "BeagleRT" $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
|
giuliomoro@64
|
126
|
giuliomoro@64
|
127 # Rule for building BeagleRT without the default main file (user-supplied main())
|
giuliomoro@64
|
128 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
|
giuliomoro@64
|
129 @echo 'Building target: $@'
|
giuliomoro@241
|
130 @echo 'Invoking: C++ Linker'
|
giuliomoro@241
|
131 $(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 "BeagleRT" $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
|
giuliomoro@64
|
132
|
giuliomoro@64
|
133 # Other Targets:
|
giuliomoro@64
|
134
|
giuliomoro@64
|
135 # Remove the temporary user-supplied source, plus the objects built from them
|
giuliomoro@64
|
136 sourceclean:
|
giuliomoro@64
|
137 -$(RM) source/* build/source/* BeagleRT
|
giuliomoro@64
|
138 -@echo ' '
|
giuliomoro@64
|
139
|
giuliomoro@64
|
140 # Remove all the built objects, including the core BeagleRT objects
|
giuliomoro@64
|
141 distclean:
|
giuliomoro@64
|
142 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT
|
giuliomoro@64
|
143 -@echo ' '
|
giuliomoro@64
|
144
|
giuliomoro@64
|
145 # Remove only the user-generated objects
|
giuliomoro@64
|
146 clean:
|
giuliomoro@64
|
147 -$(RM) build/source/* BeagleRT
|
giuliomoro@64
|
148 -@echo ' '
|
giuliomoro@64
|
149
|
giuliomoro@64
|
150 post-build:
|
giuliomoro@64
|
151 # Nothing to do here (for now)
|
giuliomoro@64
|
152
|
giuliomoro@209
|
153 .PHONY: all clean distclean sourceclean dependents debug
|
giuliomoro@64
|
154 .SECONDARY: post-build
|