comparison Makefile @ 260:afdddd5f189f prerelease

Synced main Makefile with IDE Makefile
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Mon, 16 May 2016 14:32:21 +0100
parents feadb63cff32
children 4989afa8e994
comparison
equal deleted inserted replaced
259:abd3657016ea 260:afdddd5f189f
1 # BeagleRT 1 # BeagleRT
2 # Low-latency, real-time audio and sensor processing on BeagleBone Black 2 # Low-latency, real-time audio and sensor processing on BeagleBone Black
3 # (c) 2015 Andrew McPherson, Victor Zappi, Giulio Moro 3 # (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan
4 # Centre for Digital Music, Queen Mary University of London 4 # Centre for Digital Music, Queen Mary University of London
5 5
6 # This Makefile is intended for use on the BeagleBone Black itself 6 # This Makefile is intended for use on the BeagleBone Black itself
7 # and not for cross-compiling 7 # and not for cross-compiling
8 8
9 # set the project to be compiled by calling: make all PROJECT=<project_name>
10
11 # if the PROJECT variable is not set, throw an error and exit
12 # otherwise, calling make clean without setting PROJECT results in entire projects directory being rm -rf'ed
13 ifndef PROJECT
14 $(error PROJECT is not set)
15 endif
16
17 PROJECT_DIR := $(abspath projects/$(PROJECT))
18
9 RM := rm -rf 19 RM := rm -rf
10 STATIC_LIBS := ./libprussdrv.a ./libNE10.a 20 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
11 LIBS := -lrt -lnative -lxenomai -lsndfile 21 LIBS := -lrt -lnative -lxenomai -lsndfile
22
12 # refresh library cache and check if libpd is there 23 # refresh library cache and check if libpd is there
13 TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") 24 TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so")
14 ifeq ($(strip $(TEST_LIBPD)), ) 25 ifeq ($(strip $(TEST_LIBPD)), )
15 else 26 else
16 # if libpd is there, link it in 27 # if libpd is there, link it in
41 CXX=g++ 52 CXX=g++
42 CPP_FLAGS += --fast-math 53 CPP_FLAGS += --fast-math
43 C_FLAGS += --fast-math 54 C_FLAGS += --fast-math
44 endif 55 endif
45 56
46 INCLUDES := -I./source -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 57 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
47 58
48 ASM_SRCS := $(wildcard source/*.S) 59 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
49 ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o))) 60 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
50 ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d))) 61 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
51 62
52 C_SRCS := $(wildcard source/*.c) 63 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
53 C_OBJS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.o))) 64 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
54 C_DEPS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.d))) 65 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
55 66
56 CPP_SRCS := $(wildcard source/*.cpp) 67 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
57 CPP_OBJS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.o))) 68 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
58 CPP_DEPS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.d))) 69 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
59 70
60 # Core BeagleRT sources 71 # Core BeagleRT sources
61 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp)) 72 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
62 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o))) 73 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
63 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d))) 74 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
77 debug: C_FLAGS=-g 88 debug: C_FLAGS=-g
78 debug: all 89 debug: all
79 90
80 # syntax = check syntax 91 # syntax = check syntax
81 syntax: SYNTAX_FLAG := -fsyntax-only 92 syntax: SYNTAX_FLAG := -fsyntax-only
82 syntax: BeagleRT 93 syntax: SYNTAX
83 94
84 # Rule for BeagleRT core C++ files 95 # Rule for BeagleRT core C++ files
85 build/core/%.o: ./core/%.cpp 96 build/core/%.o: ./core/%.cpp
86 @echo 'Building file: $<' 97 @echo 'Building $(notdir $<)...'
87 @echo 'Invoking: C++ Compiler' 98 # @echo 'Invoking: C++ Compiler'
88 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 99 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
89 @echo 'Finished building: $<' 100 @echo ' ...done'
90 @echo ' ' 101 @echo ' '
91 102
92 # Rule for user-supplied C++ files 103 # Rule for user-supplied C++ files
93 build/source/%.o: ./source/%.cpp 104 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
94 @echo 'Building file: $<' 105 @echo 'Building $(notdir $<)...'
95 @echo 'Invoking: C++ Compiler' 106 # @echo 'Invoking: C++ Compiler'
96 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 107 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
97 @echo 'Finished building: $<' 108 @echo ' ...done'
98 @echo ' ' 109 @echo ' '
99 110
100 # Rule for user-supplied C files 111 # Rule for user-supplied C files
101 build/source/%.o: ./source/%.c 112 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
102 @echo 'Building file: $<' 113 @echo 'Building $(notdir $<)...'
103 @echo 'Invoking: C Compiler' 114 # @echo 'Invoking: C Compiler'
104 $(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 115 @$(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
105 @echo 'Finished building: $<' 116 @echo ' ...done'
106 @echo ' ' 117 @echo ' '
107 118
108 # Rule for user-supplied assembly files 119 # Rule for user-supplied assembly files
109 build/source/%.o: ./source/%.S 120 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
110 @echo 'Building file: $<' 121 @echo 'Building $(notdir $<)...'
111 @echo 'Invoking: GCC Assembler' 122 # @echo 'Invoking: GCC Assembler'
112 as -o "$@" "$<" 123 @as -o "$@" "$<"
113 @echo 'Finished building: $<' 124 @echo ' ...done'
114 @echo ' ' 125 @echo ' '
115 126
116 # This is a nasty kludge: we want to be able to optionally link in a default 127 # This is a nasty kludge: we want to be able to optionally link in a default
117 # main file if the user hasn't supplied one. We check for the presence of the main() 128 # main file if the user hasn't supplied one. We check for the presence of the main()
118 # function, and conditionally call one of two recursive make targets depending on whether 129 # function, and conditionally call one of two recursive make targets depending on whether
119 # we want to link in the default main file or not. The kludge is the mess of a shell script 130 # we want to link in the default main file or not. The kludge is the mess of a shell script
120 # line below. Surely there's a better way to do this? 131 # line below. Surely there's a better way to do this?
121 BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 132 BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
122 $(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')) 133 $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm $(PROJECT_DIR)/build/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi'))
123 $(MAKE) $(NEXT_TARGET) 134 @$(MAKE) $(NEXT_TARGET)
124 @echo 'Finished building target: $@' 135 # @echo 'Finished building target: $@'
125 @echo ' ' 136 # @echo ' '
126 # $(MAKE) --no-print-directory post-build 137 # $(MAKE) --no-print-directory post-build
127 138
128 # Rule for building BeagleRT including the default main file (no user-supplied main()) 139 # Rule for building BeagleRT including the default main file (no user-supplied main())
129 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 140 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
130 @echo 'Building target: $@' 141 @echo 'Linking default main.cpp...'
131 @echo 'Invoking: C++ Linker' 142 # @echo 'Invoking: C++ Linker'
132 $(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) 143 @$(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_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
133 144 @echo ' ...done'
145
134 # Rule for building BeagleRT without the default main file (user-supplied main()) 146 # Rule for building BeagleRT without the default main file (user-supplied main())
135 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 147 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
136 @echo 'Building target: $@' 148 @echo 'Linking main.cpp from project...'
137 @echo 'Invoking: C++ Linker' 149 # @echo 'Invoking: C++ Linker'
138 $(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) 150 @$(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) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
151 @echo ' ...done'
152
153 # Other Targets:
154 # This rule compiles c and c++ source files without output or linking
155 SYNTAX: $(C_OBJS) $(CPP_OBJS)
139 156
140 # Other Targets: 157 # Remove the project's build objects & binary
141 158 projectclean:
142 # Remove the temporary user-supplied source, plus the objects built from them 159 -$(RM) $(PROJECT_DIR)/build/* $(PROJECT_DIR)/$(PROJECT)
143 sourceclean:
144 -$(RM) source/* build/source/* BeagleRT
145 -@echo ' ' 160 -@echo ' '
146 161
147 # Remove all the built objects, including the core BeagleRT objects 162 # Remove all the built objects, including the core BeagleRT objects
148 distclean: 163 distclean:
149 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT 164 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT
150 -@echo ' ' 165 -@echo ' '
151 166
152 # Remove only the user-generated objects 167 # Remove only the user-generated objects
153 clean: 168 #clean:
154 -$(RM) build/source/* BeagleRT 169 # -$(RM) build/source/* BeagleRT
155 -@echo ' ' 170 # -@echo ' '
156 171
157 post-build: 172 post-build:
158 # Nothing to do here (for now) 173 # Nothing to do here (for now)
159 174
160 .PHONY: all clean distclean sourceclean dependents debug 175 .PHONY: all clean distclean projectclean dependents debug
161 .SECONDARY: post-build 176 .SECONDARY: post-build