comparison Makefile @ 553:e545ce04cf2c prerelease

Updated Makefile to take LDFLAGS=, LDLIBS=, CFLAGS=, CPPFLAGS=
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 17:13:45 +0100
parents 3980b707634d
children
comparison
equal deleted inserted replaced
551:c6ccaf53381a 553:e545ce04cf2c
7 ## and not for cross-compiling # 7 ## and not for cross-compiling #
8 ## available command line options: # 8 ## available command line options: #
9 ## EXAMPLE= -- name of the folder in examples/ to be copied to projects/ and built 9 ## EXAMPLE= -- name of the folder in examples/ to be copied to projects/ and built
10 ## PROJECT= -- name of the folder in projects/ to be built 10 ## PROJECT= -- name of the folder in projects/ to be built
11 ## CL= -- list of command line options to pass to the program when running 11 ## CL= -- list of command line options to pass to the program when running
12 ## INCLUDES= -- list of additional include paths to pass to the compiler 12 ## CPPFLAGS= -- list of additional flags passed to the C++ compiler
13 ## CPP_FLAGS= -- list of additional flags passed to the C++ compiler 13 ## CFLAGS= -- list of additional flags passed to the C compiler
14 ## C_FLAGS= -- list of additional flags passed to the C compiler
15 ## COMPILER= -- compiler to use (clang or gcc) 14 ## COMPILER= -- compiler to use (clang or gcc)
16 ## LIBS= -- libs to link in 15 ## LDFLAGS= -- linker flags (e.g.: -L. )
16 ## LDLIBS= -- libs to link in (e.g.: -lm )
17 ## AT= -- used instead of @ to silence the output. Defaults AT=@, use AT= for a very verbose output 17 ## AT= -- used instead of @ to silence the output. Defaults AT=@, use AT= for a very verbose output
18 ### 18 ###
19 ##available targets: # 19 ##available targets: #
20 .DEFAULT_GOAL := Bela 20 .DEFAULT_GOAL := Bela
21 21
79 endif 79 endif
80 QUIET?=false 80 QUIET?=false
81 81
82 RM := rm -rf 82 RM := rm -rf
83 STATIC_LIBS := ./libprussdrv.a ./libNE10.a 83 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
84 override LIBS += -lrt -lnative -lxenomai -lsndfile 84 LIBS = -lrt -lnative -lxenomai -lsndfile
85 85
86 # refresh library cache and check if libpd is there 86 # refresh library cache and check if libpd is there
87 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking 87 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking
88 LIBPD_PATH = /usr/lib/libpd.so 88 LIBPD_PATH = /usr/lib/libpd.so
89 TEST_LIBPD := $(shell which $(LIBPD_PATH)) 89 TEST_LIBPD := $(shell which $(LIBPD_PATH))
90 ifneq ($(strip $(TEST_LIBPD)), ) 90 ifneq ($(strip $(TEST_LIBPD)), )
91 # if libpd is there, link it in 91 # if libpd is there, link it in
92 LIBS += -lpd -lpthread_rt 92 LIBS += -lpd -lpthread_rt
93 endif 93 endif
94 DEFAULT_CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize 94 INCLUDES := -I$(PROJECT_DIR) -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include
95 override CPP_FLAGS := $(DEFAULT_CPP_FLAGS) $(CPP_FLAGS) 95 DEFAULT_CPPFLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
96 override C_FLAGS := $(DEFAULT_CPP_FLAGS) $(C_FLAGS) 96 DEFAULT_CFLAGS := $(DEFAULT_CPPFLAGS)
97
98 97
99 ifndef COMPILER 98 ifndef COMPILER
100 # check whether clang is installed 99 # check whether clang is installed
101 TEST_COMPILER := $(shell which clang) 100 TEST_COMPILER := $(shell which clang)
102 ifneq ($(strip $(TEST_COMPILER)), ) 101 ifneq ($(strip $(TEST_COMPILER)), )
108 endif 107 endif
109 108
110 ifeq ($(COMPILER), clang) 109 ifeq ($(COMPILER), clang)
111 CC=clang 110 CC=clang
112 CXX=clang++ 111 CXX=clang++
113 CPP_FLAGS += -DNDEBUG 112 DEFAULT_CPPFLAGS += -DNDEBUG
114 C_FLAGS += -DNDEBUG 113 DEFAULT_CFLAGS += -DNDEBUG
115 else 114 else
116 ifeq ($(COMPILER), gcc) 115 ifeq ($(COMPILER), gcc)
117 CC=gcc 116 CC=gcc
118 CXX=g++ 117 CXX=g++
119 CPP_FLAGS += --fast-math 118 DEFAULT_CPPFLAGS += --fast-math
120 C_FLAGS += --fast-math 119 DEFAULT_CFLAGS += --fast-math
121 endif 120 endif
122 endif 121 endif
123
124 DEFAULT_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
125 override INCLUDES += $(DEFAULT_INCLUDES)
126 122
127 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S) 123 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
128 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o))) 124 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
129 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d))) 125 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
130 126
168 all: SYNTAX_FLAG := 164 all: SYNTAX_FLAG :=
169 all: Bela 165 all: Bela
170 166
171 # debug = buildBela debug 167 # debug = buildBela debug
172 debug: ## Same as Bela but with debug flags and no optimizations 168 debug: ## Same as Bela but with debug flags and no optimizations
173 debug: CPP_FLAGS=-g 169 debug: DEFAULT_CPPFLAGS=-g
174 debug: C_FLAGS=-g 170 debug: DEFAULT_CFLAGS=-g
175 debug: all 171 debug: all
176 172
177 # syntax = check syntax 173 # syntax = check syntax
178 syntax: ## Only checks syntax 174 syntax: ## Only checks syntax
179 syntax: SYNTAX_FLAG := -fsyntax-only 175 syntax: SYNTAX_FLAG := -fsyntax-only
181 177
182 # Rule for Bela core C++ files 178 # Rule for Bela core C++ files
183 build/core/%.o: ./core/%.cpp 179 build/core/%.o: ./core/%.cpp
184 $(AT) echo 'Building $(notdir $<)...' 180 $(AT) echo 'Building $(notdir $<)...'
185 # $(AT) echo 'Invoking: C++ Compiler $(CXX)' 181 # $(AT) echo 'Invoking: C++ Compiler $(CXX)'
186 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 182 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(DEFAULT_CPPFLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" $(CPPFLAGS)
187 $(AT) echo ' ...done' 183 $(AT) echo ' ...done'
188 $(AT) echo ' ' 184 $(AT) echo ' '
189 185
190 # Rule for Bela core ASM files 186 # Rule for Bela core ASM files
191 build/core/%.o: ./core/%.S 187 build/core/%.o: ./core/%.S
197 193
198 # Rule for user-supplied C++ files 194 # Rule for user-supplied C++ files
199 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp 195 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
200 $(AT) echo 'Building $(notdir $<)...' 196 $(AT) echo 'Building $(notdir $<)...'
201 # $(AT) echo 'Invoking: C++ Compiler $(CXX)' 197 # $(AT) echo 'Invoking: C++ Compiler $(CXX)'
202 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 198 $(AT) $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(DEFAULT_CPPFLAGS) -Wall -c -fmessage-length=1 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" $(CPPFLAGS)
203 $(AT) echo ' ...done' 199 $(AT) echo ' ...done'
204 $(AT) echo ' ' 200 $(AT) echo ' '
205 201
206 # Rule for user-supplied C files 202 # Rule for user-supplied C files
207 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c 203 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
208 $(AT) echo 'Building $(notdir $<)...' 204 $(AT) echo 'Building $(notdir $<)...'
209 # $(AT) echo 'Invoking: C Compiler $(CC)' 205 # $(AT) echo 'Invoking: C Compiler $(CC)'
210 $(AT) $(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 206 $(AT) $(CC) $(SYNTAX_FLAG) $(INCLUDES) $(DEFAULT_CFLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 $(CFLAGS)
211 $(AT) echo ' ...done' 207 $(AT) echo ' ...done'
212 $(AT) echo ' ' 208 $(AT) echo ' '
213 209
214 # Rule for user-supplied assembly files 210 # Rule for user-supplied assembly files
215 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S 211 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
229 $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : ')) 225 $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : '))
230 $(AT) #If there is a .pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) 226 $(AT) #If there is a .pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS)
231 $(eval DEFAULT_PD_CONDITIONAL :=\ 227 $(eval DEFAULT_PD_CONDITIONAL :=\
232 $(shell bash -c '{ ls $(PROJECT_DIR)/*.pd &>/dev/null && [ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep "render.*BelaContext" | wc -l` -eq 0 ]; } && echo '$(DEFAULT_PD_OBJS)' || : ' )) 228 $(shell bash -c '{ ls $(PROJECT_DIR)/*.pd &>/dev/null && [ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep "render.*BelaContext" | wc -l` -eq 0 ]; } && echo '$(DEFAULT_PD_OBJS)' || : ' ))
233 $(AT) echo 'Linking...' 229 $(AT) echo 'Linking...'
234 $(AT) $(CXX) $(SYNTAX_FLAG) $(LDFLAGS) -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_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) 230 $(AT) $(CXX) $(SYNTAX_FLAG) $(LDFLAGS) -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_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) $(LDLIBS)
235 $(AT) echo ' ...done' 231 $(AT) echo ' ...done'
236 232
237 # Other Targets: 233 # Other Targets:
238 projectclean: ## Remove the PROJECT's build objects & binary 234 projectclean: ## Remove the PROJECT's build objects & binary
239 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE) 235 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE)
254 250
255 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care. 251 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care.
256 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE) 252 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE)
257 -@echo ' ' 253 -@echo ' '
258 254
259 $(warning C_FLAGS $(C_FLAGS))
260 $(warning CPP_FLAGS $(CPP_FLAGS))
261 $(warning LIBS $(LIBS))
262 $(warning INCLUDES $(INCLUDES))
263 runfg: run 255 runfg: run
264 run: ## Run PROJECT in the foreground 256 run: ## Run PROJECT in the foreground
265 run: stop Bela 257 run: stop Bela
266 $(AT) echo "Running $(RUN_COMMAND)" 258 $(AT) echo "Running $(RUN_COMMAND)"
267 $(AT) sync& cd $(RUN_FROM) && $(RUN_COMMAND) 259 $(AT) sync& cd $(RUN_FROM) && $(RUN_COMMAND)