changeset 463:c47709e8b5c9 prerelease

Makefile automatically links in default_libpd_render.cpp if there is a _main.pd file and there is no render symbol
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 20 Jun 2016 15:10:12 +0100
parents d9a4fc5357e7
children 8fcfbfb32aa0 1d585c5fa663
files Makefile
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Jun 20 14:09:43 2016 +0100
+++ b/Makefile	Mon Jun 20 15:10:12 2016 +0100
@@ -122,7 +122,7 @@
 PROJECT_OBJS = $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS)
 
 # Core Bela sources
-CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
+CORE_CPP_SRCS = $(filter-out core/default_main.cpp core/default_libpd_render.cpp, $(wildcard core/*.cpp))
 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
 
@@ -137,7 +137,13 @@
 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
 
-Bela: ## Builds the Bela program with all the opimizations
+# Objects for a system-supplied default render() file for libpd projects,
+# if the user only wants to provide the Pd files.
+DEFAULT_PD_CPP_SRCS := ./core/default_libpd_render.cpp
+DEFAULT_PD_OBJS := ./build/core/default_libpd_render.o
+DEFAULT_PD_CPP_DEPS := ./build/core/default_libpd_render.d
+
+Bela: ## Builds the Bela program with all the optimizations
 Bela: $(OUTPUT_FILE)
 
 # all = build Bela 
@@ -202,9 +208,14 @@
 # we want to link in the default main file or not. The kludge is the mess of a shell script
 # line below. Surely there's a better way to do this?
 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(PROJECT_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
-	$(eval DEFAULT_MAIN_CONDITIONAL := $(shell bash -c 'if [ `nm $(PROJECT_OBJS) | grep -w T | grep -w main | wc -l` == '0' ]; then echo "$(DEFAULT_MAIN_OBJS)"; else echo ""; fi'))
+	$(eval DEFAULT_MAIN_CONDITIONAL :=\
+	    $(shell bash -c '[ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w main | wc -l` == '0' ] && echo "$(DEFAULT_MAIN_OBJS)" || : '))
+	@#If there is a _main.pd file AND there is no "render" symbol then link in the $(DEFAULT_PD_OBJS) 
+	$(eval DEFAULT_PD_CONDITIONAL :=\
+	    $(shell bash -c '{ [ -f "$(PROJECT_DIR)/_main.pd" ] && [ `nm $(PROJECT_OBJS) 2>/dev/null | grep -w T | grep -w render | wc -l` = '0' ]; } && echo '$(DEFAULT_PD_OBJS)' || : ' ))
+	@echo $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL)
 	@echo 'Linking...'
-	@$(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_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
+	$(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_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(DEFAULT_PD_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
 	@echo ' ...done'
 	
 # Other Targets: