comparison Makefile @ 386:e4510c9eee94 prerelease

Makefile: prompt for distclean, cleanup
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 14 Jun 2016 13:53:08 +0100
parents fb5547fe6d99
children fe2f8e00096b 814e85de67e1
comparison
equal deleted inserted replaced
385:fb5547fe6d99 386:e4510c9eee94
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 NO_PROJECT_TARGETS=distclean stop help 9 .DEFAULT_GOAL := Bela
10
11 NO_PROJECT_TARGETS=coreclean distclean stop help
10 NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS) 12 NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS)
11 # Type `$ make help` to get a description of the functionalities of this Makefile. 13 # Type `$ make help` to get a description of the functionalities of this Makefile.
12 help: ## Show this help 14 help: ## Show this help
13 @echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]' 15 @echo 'Usage: make [target] CL=[command line options] [PROJECT=[projectName] | EXAMPLE=[exampleName]]'
14 @echo $(NO_PROJECT_TARGETS_MESSAGE) 16 @printf "\n$(NO_PROJECT_TARGETS_MESSAGE)\n\n"
15 @echo 'Targets: (default: Bela)' 17 @echo 'Targets: (default: $(.DEFAULT_GOAL))'
16 @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | column -t -c 2 -s '#' 18 @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/^\(.*\): .*##\(.*\)/\1:#\2/' | column -t -c 2 -s '#'
17 19
18 # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS 20 # PROJECT or EXAMPLE must be set for targets that are not included in NO_PROJECT_TARGETS
19 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS))) 21 ifeq (,$(filter $(NO_PROJECT_TARGETS),$(MAKECMDGOALS)))
20 ifndef PROJECT 22 ifndef PROJECT
23 endif 25 endif
24 endif 26 endif
25 endif 27 endif
26 28
27 # if we are building an example, just copy it to the projects/ folder 29 # if we are building an example, just copy it to the projects/ folder
28 # and tehn treat it as a project 30 # and then treat it as a project
29 ifdef EXAMPLE 31 ifdef EXAMPLE
30 PROJECT?=exampleTempProject 32 PROJECT?=exampleTempProject
31 PROJECT_DIR?=$(abspath projects/$(PROJECT)) 33 PROJECT_DIR?=$(abspath projects/$(PROJECT))
32 $(shell mkdir -p $(abspath projects)) 34 $(shell mkdir -p $(abspath projects))
33 $(shell rm -rf $(PROJECT_DIR)) 35 $(shell rm -rf $(PROJECT_DIR))
73 else 75 else
74 COMPILER := gcc 76 COMPILER := gcc
75 endif 77 endif
76 endif 78 endif
77 79
78 $(warning $(COMPILER))
79 ifeq ($(COMPILER), clang) 80 ifeq ($(COMPILER), clang)
80 CC=clang 81 CC=clang
81 CXX=clang++ 82 CXX=clang++
82 CPP_FLAGS += -DNDEBUG 83 CPP_FLAGS += -DNDEBUG
83 C_FLAGS += -DNDEBUG 84 C_FLAGS += -DNDEBUG
140 syntax: SYNTAX 141 syntax: SYNTAX
141 142
142 # Rule for Bela core C++ files 143 # Rule for Bela core C++ files
143 build/core/%.o: ./core/%.cpp 144 build/core/%.o: ./core/%.cpp
144 @echo 'Building $(notdir $<)...' 145 @echo 'Building $(notdir $<)...'
145 # @echo 'Invoking: C++ Compiler' 146 # @echo 'Invoking: C++ Compiler $(CXX)'
146 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 147 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
147 @echo ' ...done' 148 @echo ' ...done'
148 @echo ' ' 149 @echo ' '
149 150
150 # Rule for Bela core ASM files 151 # Rule for Bela core ASM files
156 @echo ' ' 157 @echo ' '
157 158
158 # Rule for user-supplied C++ files 159 # Rule for user-supplied C++ files
159 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp 160 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
160 @echo 'Building $(notdir $<)...' 161 @echo 'Building $(notdir $<)...'
161 # @echo 'Invoking: C++ Compiler' 162 @echo 'Invoking: C++ Compiler $(CXX)'
162 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 163 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
163 @echo ' ...done' 164 @echo ' ...done'
164 @echo ' ' 165 @echo ' '
165 166
166 # Rule for user-supplied C files 167 # Rule for user-supplied C files
167 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c 168 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
168 @echo 'Building $(notdir $<)...' 169 @echo 'Building $(notdir $<)...'
169 # @echo 'Invoking: C Compiler' 170 # @echo 'Invoking: C Compiler $(CC)'
170 $(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 171 $(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
171 @echo ' ...done' 172 @echo ' ...done'
172 @echo ' ' 173 @echo ' '
173 174
174 # Rule for user-supplied assembly files 175 # Rule for user-supplied assembly files
196 197
197 projectclean:## Remove the project's build objects & binary 198 projectclean:## Remove the project's build objects & binary
198 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE) 199 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE)
199 -@echo ' ' 200 -@echo ' '
200 201
201 distclean: ## Remove all the projects and the built objects, including the core Bela objects. Use with care. 202 clean: ## Same as projectclean
203 clean: projectclean
204
205 coreclean: ## Remove the core's build objects
206 -$(RM) build/*
207
208 prompt:
209 @printf "Warning: you are about to DELETE the projects/ folder and its content. This operation cannot be undone. Continue? (y/N) "
210 @read REPLY; if [ $$REPLY != y ] && [ $$REPLY != Y ]; then echo "Aborting..."; exit 1; fi
211
212 distclean: ## Restores the Bela folder to a pristine state: remove all the projects source and the built objects, including the core Bela objects.
213 distclean: prompt distcleannoprompt
214
215 distcleannoprompt: ## Same as distclean, but does not prompt for confirmation. Use with care.
202 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE) 216 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE)
203 -@echo ' ' 217 -@echo ' '
204 218
205 runfg: run 219 runfg: run
206 run: ## Run PROJECT in the foreground 220 run: ## Run PROJECT in the foreground
242 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT) 256 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT)
243 257
244 stop: ## Stops any Bela program that is currently running 258 stop: ## Stops any Bela program that is currently running
245 stop: 259 stop:
246 @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; 260 @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;
247 # Remove only the user-generated objects 261
248 clean: projectclean 262 .PHONY: all clean distclean help projectclean nostartup startup startuploop debug run runfg runscreen runscreenfg runscreenfifo stop
249
250 post-build:
251 # Nothing to do here (for now)
252
253 .PHONY: all clean distclean projectclean dependents debug run runfg runscreen stop
254 .SECONDARY: post-build