From 0f8d90e09746ffee8f352323d60933c4549f89ed Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sun, 25 Sep 2016 21:00:07 -0400
Subject: [PATCH] automate some of Matt Barber's build instructions for OSX

---
 externals/Makefile                            |   8 +-
 packages/darwin_app/Info.plist.in             |   2 +-
 packages/darwin_app/Makefile                  |  99 ++++++++++--------
 packages/darwin_app/{pd.icns => app.icns}     | Bin
 .../{pd-file.icns => document.icns}           | Bin
 .../darwin_app/embed-MacOSX-dependencies.sh   |  22 ++--
 ...st => org.puredata.pd-l2ork.default.plist} |  28 ++---
 7 files changed, 84 insertions(+), 75 deletions(-)
 rename packages/darwin_app/{pd.icns => app.icns} (100%)
 rename packages/darwin_app/{pd-file.icns => document.icns} (100%)
 rename packages/darwin_app/{org.puredata.pdextended.default.plist => org.puredata.pd-l2ork.default.plist} (91%)

diff --git a/externals/Makefile b/externals/Makefile
index 91be851e2..a1cb85ca0 100644
--- a/externals/Makefile
+++ b/externals/Makefile
@@ -140,16 +140,16 @@ ifeq ($(OS_NAME),windows)
 else
   ifeq ($(OS_NAME),darwin)
 # on Mac OS X 10.6/Snow Leopard don't build hid since it needs Carbon
-    LIB_TARGETS += pdp gem2pdp iem16 apple
+    LIB_TARGETS += iem16 apple
     ifneq ($(shell uname -r | sed 's|10\.[0-9][0-9]*\.[0-9][0-9]*|10|'),10)
-      LIB_TARGETS += hid
+      LIB_TARGETS +=
     endif
   else
     # GNU/Linux, BSD, IRIX, etc. (we use exported variable INCREMENTAL to avoid rebuilding entire Gem lib that takes a long time to compile)
     ifeq ($(INCREMENTAL),yes)
-    	LIB_TARGETS += hid pdp gem2pdp iem16
+	LIB_TARGETS += hid iem16
     else
-    	LIB_TARGETS += gem hid pdp gem2pdp iem16
+	LIB_TARGETS += gem hid iem16
     endif
   endif
 endif
diff --git a/packages/darwin_app/Info.plist.in b/packages/darwin_app/Info.plist.in
index 7f38d7fa2..3ebbcba9d 100644
--- a/packages/darwin_app/Info.plist.in
+++ b/packages/darwin_app/Info.plist.in
@@ -32,7 +32,7 @@
 	<key>CFBundleInfoDictionaryVersion</key>
 	<string>6.0</string>
 	<key>CFBundleName</key>
-	<string>PD_APP_NAME</string>
+	<string>PD_SHORT_NAME</string>
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
diff --git a/packages/darwin_app/Makefile b/packages/darwin_app/Makefile
index f2498354e..abdcae562 100644
--- a/packages/darwin_app/Makefile
+++ b/packages/darwin_app/Makefile
@@ -6,8 +6,9 @@ export MACOSX_DEPLOYMENT_TARGET = 10.4
 CWD := $(shell pwd)
 BUILD_BASE = $(CWD)/build
 PD_APP_NAME = $(PACKAGE_NAME)
+PD_SHORT_NAME = "Purr-Data"
 PD_APP_CONTENTS = $(BUILD_BASE)/$(PD_APP_NAME).app/Contents
-DESTDIR = $(PD_APP_CONTENTS)/Resources
+DESTDIR = $(PD_APP_CONTENTS)/Resources/app.nw
 
 cvs_root_dir := $(shell cd $(CWD)/../.. && pwd)
 BUILDLAYOUT_DIR = $(cvs_root_dir)/packages
@@ -61,10 +62,12 @@ all:
 install: darwin_app
 
 #------------------------------------------------------------------------------#
-darwin_app: darwin_app_core extended_install rez_install darwin_app_embed_libs spotlight_importer_install
+darwin_app: darwin_app_core extended_install darwin_app_embed_libs spotlight_importer_install
 	@echo " "
 	@echo "Pd.app build succeeded!"
 
+NWFILES = $(foreach file,$(wildcard $(cvs_root_dir)/pd/nw/*),$(DESTDIR)/bin/$(notdir $(file)))
+
 extended_install:
 # on Mac OS X 10.6/Snow Leopard don't build Gem since it needs Carbon
 ifeq ($(shell uname -r | sed 's|10\.[0-9][0-9]*\.[0-9][0-9]*|10|'),10)
@@ -78,6 +81,16 @@ ifeq ($(shell uname -r | sed 's|10\.[0-9][0-9]*\.[0-9][0-9]*|10|'),10)
 else
 	$(MAKE) -C $(packages_src) $(DEST_PATHS) extended_install
 endif
+	# Huge kludge to move all the nw.js files in $DESTDIR/bin to
+	# $DESTDIR. We need to do this because the nw.js app expects
+	# package.json to be inside $DESTDIR. So all the rest of the
+	# supporting GUI files must be there, too
+	-mv $(NWFILES) $(DESTDIR)
+	# remove the extra nw.js binary
+	rm -rf $(DESTDIR)/nw
+	# remove the broken pd-l2ork symlink from bin/
+	rm $(DESTDIR)/bin/pd-l2ork
+	install -p $(cvs_root_dir)/pd/bin/pd-l2ork $(DESTDIR)/bin
 
 #------------------------------------------------------------------------------#
 # this target is for when you already have a pre-built Pd.app and you
@@ -93,44 +106,47 @@ extended_app_install:
 # build a standalone Wish.app from the installed Tcl/Tk Frameworks
 darwin_app_wrapper: Info.plist
 # Wish
-	install -d "$(PD_APP_CONTENTS)/MacOS"
-	install -m0755 -p \
-		"$(WISH_CONTENTS)/MacOS/$(WISH_NAME)" "$(PD_APP_CONTENTS)/MacOS"
-	install -d "$(PD_APP_CONTENTS)/Resources"
+	install -d "$(BUILD_BASE)"
+	rsync -ax $(cvs_root_dir)/pd/nw/nw/nwjs.app/ $(BUILD_BASE)/$(PD_APP_NAME).app/
+#	install -d "$(PD_APP_CONTENTS)/MacOS"
+	#install -m0755 -p \
+	#	"$(WISH_CONTENTS)/MacOS/$(WISH_NAME)" "$(PD_APP_CONTENTS)/MacOS"
+	#install -d "$(PD_APP_CONTENTS)/Resources"
 # only embed the Tcl/Tk Frameworks if not building against the built-in ones
-ifneq (/System,$(findstring /System,$(WISH_FRAMEWORKS_SOURCE)))
-	install -d $(PD_APP_CONTENTS)/Frameworks \
-		$(PD_APP_CONTENTS)/Frameworks/Tcl.framework \
-		$(PD_APP_CONTENTS)/Frameworks/Tk.framework
-	ditto $(WISH_FRAMEWORKS_SOURCE)/Tcl.framework \
-		$(PD_APP_CONTENTS)/Frameworks/Tcl.framework/
-	ditto $(WISH_FRAMEWORKS_SOURCE)/Tk.framework \
-		$(PD_APP_CONTENTS)/Frameworks/Tk.framework/
-	rm -rf $(PD_APP_CONTENTS)/Frameworks/Tcl.framework/{,/Versions/8.4}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh} && \
-	rm -rf $(PD_APP_CONTENTS)/Frameworks/Tk.framework/{,/Versions/8.4}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh}
-	chmod -R u+w $(PD_APP_CONTENTS)/Frameworks
+#ifneq (/System,$(findstring /System,$(WISH_FRAMEWORKS_SOURCE)))
+	#install -d $(PD_APP_CONTENTS)/Frameworks \
+	#	$(PD_APP_CONTENTS)/Frameworks/Tcl.framework \
+	#	$(PD_APP_CONTENTS)/Frameworks/Tk.framework
+	#ditto $(WISH_FRAMEWORKS_SOURCE)/Tcl.framework \
+	#	$(PD_APP_CONTENTS)/Frameworks/Tcl.framework/
+	#ditto $(WISH_FRAMEWORKS_SOURCE)/Tk.framework \
+	#	$(PD_APP_CONTENTS)/Frameworks/Tk.framework/
+	#rm -rf $(PD_APP_CONTENTS)/Frameworks/Tcl.framework/{,/Versions/8.4}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh} && \
+	#rm -rf $(PD_APP_CONTENTS)/Frameworks/Tk.framework/{,/Versions/8.4}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh}
+	#chmod -R u+w $(PD_APP_CONTENTS)/Frameworks
 # from http://tktoolkit.cvs.sourceforge.net/tktoolkit/tk/macosx/GNUmakefile
-	fix_install_id ( ) { \
-	    chmod -R a+w "$$1"; \
-	    install_name_tool -id $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
-	    chmod -R a-w "$$1"; \
-	} && \
-	fix_install_name ( ) { \
-	    chmod -R a+w "$$1"; \
-	    install_name_tool -change $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {print \$$1; sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
-	    chmod -R a-w "$$1"; \
-	} && \
-	fix_install_id $(PD_APP_CONTENTS)/Frameworks/Tcl.framework/Tcl Tcl && \
-	fix_install_id $(PD_APP_CONTENTS)/Frameworks/Tk.framework/Tk Tk && \
-	fix_install_name "$(PD_APP_CONTENTS)/MacOS/$(WISH_NAME)" Tcl && \
-	fix_install_name "$(PD_APP_CONTENTS)/MacOS/$(WISH_NAME)" Tk
-endif # NOT /System
+	#fix_install_id ( ) { \
+	#    chmod -R a+w "$$1"; \
+	#    install_name_tool -id $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
+	#    chmod -R a-w "$$1"; \
+	#} && \
+	#fix_install_name ( ) { \
+	#    chmod -R a+w "$$1"; \
+	#    install_name_tool -change $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {print \$$1; sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
+	#    chmod -R a-w "$$1"; \
+	#} && \
+	#fix_install_id $(PD_APP_CONTENTS)/Frameworks/Tcl.framework/Tcl Tcl && \
+	#fix_install_id $(PD_APP_CONTENTS)/Frameworks/Tk.framework/Tk Tk && \
+	#fix_install_name "$(PD_APP_CONTENTS)/MacOS/$(WISH_NAME)" Tcl && \
+	#fix_install_name "$(PD_APP_CONTENTS)/MacOS/$(WISH_NAME)" Tk
+#endif # NOT /System
 # set up app wrapper
-	install -d "$(PD_APP_CONTENTS)/Resources"
-	install -m0644 -p Info.plist "$(PD_APP_CONTENTS)"
+	install -d "$(PD_APP_CONTENTS)/Resources/app.nw"
+	# The nw.js app has its own Info.plist
+	#install -m0644 -p Info.plist "$(PD_APP_CONTENTS)"
 	install -m0644 -p *.icns  "$(PD_APP_CONTENTS)/Resources"
-	mv "$(PD_APP_CONTENTS)/MacOS/${WISH_NAME}" \
-		"$(PD_APP_CONTENTS)/MacOS/${PD_APP_NAME}"
+	#mv "$(PD_APP_CONTENTS)/MacOS/${WISH_NAME}" \
+	#	"$(PD_APP_CONTENTS)/MacOS/${PD_APP_NAME}"
 
 #------------------------------------------------------------------------------#
 # generate Info.plist using PD_APP_NAME and PD_VERSION
@@ -138,6 +154,7 @@ Info.plist: CFBUNDLEVERSION_DATE := $(shell date +%Y.%m.%d)
 Info.plist: Info.plist.in 
 	cat Info.plist.in | \
 		sed 's/PD_APP_NAME/$(PD_APP_NAME)/' | \
+		sed 's/PD_SHORT_NAME/$(PD_SHORT_NAME)/' | \
 		sed 's/CFBUNDLESHORTVERSIONSTRING/$(PD_MAJOR_VERSION).$(PD_MINOR_VERSION).$(PD_BUGFIX_VERSION)/' | \
 		sed 's/CFBUNDLEVERSION/$(CFBUNDLEVERSION_DATE)/' > \
 		Info.plist
@@ -155,8 +172,8 @@ rez_install:
 
 darwin_app_embed_libs:
 # embed libquicktime plugins
-	install -d $(PD_APP_CONTENTS)/lib/libquicktime1
-	install -p /sw/lib/libquicktime1/*.so $(PD_APP_CONTENTS)/lib/libquicktime1
+	#install -d $(PD_APP_CONTENTS)/lib/libquicktime1
+	#install -p /sw/lib/libquicktime1/*.so $(PD_APP_CONTENTS)/lib/libquicktime1
 	./embed-MacOSX-dependencies.sh $(PD_APP_CONTENTS)
 
 # shortcut to install the readme on non-Extended builds
@@ -178,11 +195,11 @@ darwin_app_core: darwin_app_wrapper
 		test -e pdextended || ln -s pd pdextended
 # support for Info Panel Plugins mgmt
 	cd "$(PD_APP_CONTENTS)" && ln -s Resources/extra Plugins
-	install -p -m0644 org.puredata.pdextended.default.plist "$(PD_APP_CONTENTS)/"
+	install -p -m0644 org.puredata.pd-l2ork.default.plist "$(PD_APP_CONTENTS)/Resources/"
 # since Pd-vanilla on Mac OS X doesn't have an 'include/pd' folder,
 # Pd-extended will mimic Pd-vanilla's include/pd until Pd-vanilla gets one
-	ln -s pdextended "$(PD_APP_CONTENTS)/Resources/include/pd"
-	ln -s pd/m_pd.h "$(PD_APP_CONTENTS)/Resources/include/m_pd.h"
+	ln -s pdextended "$(PD_APP_CONTENTS)/Resources/app.nw/include/pd"
+	ln -s pd/m_pd.h "$(PD_APP_CONTENTS)/Resources/app.nw/include/m_pd.h"
 
 
 #==============================================================================#
diff --git a/packages/darwin_app/pd.icns b/packages/darwin_app/app.icns
similarity index 100%
rename from packages/darwin_app/pd.icns
rename to packages/darwin_app/app.icns
diff --git a/packages/darwin_app/pd-file.icns b/packages/darwin_app/document.icns
similarity index 100%
rename from packages/darwin_app/pd-file.icns
rename to packages/darwin_app/document.icns
diff --git a/packages/darwin_app/embed-MacOSX-dependencies.sh b/packages/darwin_app/embed-MacOSX-dependencies.sh
index 0ac4363fe..3eea432b8 100755
--- a/packages/darwin_app/embed-MacOSX-dependencies.sh
+++ b/packages/darwin_app/embed-MacOSX-dependencies.sh
@@ -22,17 +22,17 @@ PD_APP_LIB=$PD_APP_CONTENTS/$LIB_DIR
 echo " "
 
 for pd_darwin in `find $PD_APP_CONTENTS -name '*.pd_darwin'`; do
-	LIBS=`otool -L $pd_darwin | sed -n 's|.*/sw/lib/\(.*\.dylib\).*|\1|p'`
+	LIBS=`otool -L $pd_darwin | sed -n 's|.*/opt/local/lib/\(.*\.dylib\).*|\1|p'`
 	if [ "x$LIBS" != "x" ]; then
 		echo "`echo $pd_darwin | sed 's|.*/\(.*\.pd_darwin$\)|\1|'` is using:"
 		for lib in $LIBS; do
 			echo "    $lib"
 			install -d $PD_APP_LIB
-			install -p /sw/lib/$lib $PD_APP_LIB
+			install -p /opt/local/lib/$lib $PD_APP_LIB
 			new_lib=`echo $lib | sed 's|.*/\(.*\.dylib\)|\1|'`
 			# @executable_path starts from Contents/Resources/bin/pd
 			install_name_tool -id @executable_path/../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
-			install_name_tool -change /sw/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $pd_darwin
+			install_name_tool -change /opt/local/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $pd_darwin
 		done
 		echo " "
 	fi
@@ -40,7 +40,7 @@ done
 
 # check for .so plugins used by libquicktime and others
 for so in $PD_APP_LIB/*/*.so; do
-	LIBS=`otool -L $so | sed -n 's|.*/sw/lib/\(.*\.dylib\).*|\1|p'`
+	LIBS=`otool -L $so | sed -n 's|.*/opt/local/lib/\(.*\.dylib\).*|\1|p'`
 	if [ "x$LIBS" != "x" ]; then
 		echo "`echo $so | sed 's|.*/\(lib.*/.*\.so\)|\1|'` is using:"
 		for lib in $LIBS; do
@@ -49,17 +49,17 @@ for so in $PD_APP_LIB/*/*.so; do
 			if [ -e  $PD_APP_LIB/$new_lib ]; then
 				echo "$PD_APP_LIB/$new_lib already exists, skipping copy."
 			else
-				install -vp /sw/lib/$lib $PD_APP_LIB
+				install -vp /opt/local/lib/$lib $PD_APP_LIB
 			fi
 			# @executable_path starts from Contents/Resources/bin/pd
-			install_name_tool -change /sw/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $so
+			install_name_tool -change /opt/local/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $so
 		done
 		echo " "
 	fi
 done
 
 for dylib in $PD_APP_LIB/*.dylib; do
-	LIBS=`otool -L $dylib | sed -n 's|.*/sw/lib/\(.*\.dylib\).*|\1|p'`
+	LIBS=`otool -L $dylib | sed -n 's|.*/opt/local/lib/\(.*\.dylib\).*|\1|p'`
 	if [ "x$LIBS" != "x" ]; then
 		echo "`echo $dylib | sed 's|.*/\(.*\.dylib\)|\1|'` is using:"
 		for lib in $LIBS; do
@@ -68,11 +68,11 @@ for dylib in $PD_APP_LIB/*.dylib; do
 			if [ -e  $PD_APP_LIB/$new_lib ]; then
 				echo "$PD_APP_LIB/$new_lib already exists, skipping copy."
 			else
-				install -vp /sw/lib/$lib $PD_APP_LIB
+				install -vp /opt/local/lib/$lib $PD_APP_LIB
 			fi
 			# @executable_path starts from Contents/Resources/bin/pd
 			install_name_tool -id @executable_path/../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
-			install_name_tool -change /sw/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $dylib
+			install_name_tool -change /opt/local/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $dylib
 		done
 		echo " "
 	fi
@@ -89,11 +89,11 @@ for dylib in $PD_APP_LIB/*.dylib; do
 			if [ -e  $PD_APP_LIB/$new_lib ]; then
 				echo "$PD_APP_LIB/$new_lib already exists, skipping copy."
 			else
-				install -vp /sw/lib/$lib $PD_APP_LIB
+				install -vp /opt/local/lib/$lib $PD_APP_LIB
 			fi
 			# @executable_path starts from Contents/Resources/bin/pd
 			install_name_tool -id @executable_path/../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
-			install_name_tool -change /sw/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $dylib
+			install_name_tool -change /opt/local/lib/$lib @executable_path/../../$LIB_DIR/$new_lib $dylib
 		done
 		echo " "
 	fi
diff --git a/packages/darwin_app/org.puredata.pdextended.default.plist b/packages/darwin_app/org.puredata.pd-l2ork.default.plist
similarity index 91%
rename from packages/darwin_app/org.puredata.pdextended.default.plist
rename to packages/darwin_app/org.puredata.pd-l2ork.default.plist
index e8fcaa195..b12028281 100644
--- a/packages/darwin_app/org.puredata.pdextended.default.plist
+++ b/packages/darwin_app/org.puredata.pd-l2ork.default.plist
@@ -51,35 +51,27 @@
 	<key>loadlib22</key>
 	<string>smlib</string>
 	<key>loadlib23</key>
-	<string>toxy</string>
-	<key>loadlib24</key>
 	<string>unauthorized</string>
-	<key>loadlib25</key>
+	<key>loadlib24</key>
 	<string>vbap</string>
-	<key>loadlib26</key>
+	<key>loadlib25</key>
 	<string>pan</string>
-	<key>loadlib27</key>
+	<key>loadlib26</key>
 	<string>hcs</string>
-	<key>loadlib28</key>
+	<key>loadlib27</key>
 	<string>jmmmp</string>
-	<key>loadlib29</key>
+	<key>loadlib28</key>
 	<string>ext13</string>
-	<key>loadlib30</key>
+	<key>loadlib29</key>
 	<string>ggee</string>
-	<key>loadlib31</key>
+	<key>loadlib30</key>
 	<string>iem_anything</string>
-	<key>loadlib32</key>
-	<string>flib</string>
-	<key>loadlib33</key>
+	<key>loadlib31</key>
 	<string>ekext</string>
-	<key>loadlib34</key>
-	<string>flatspace</string>
-	<key>loadlib35</key>
+	<key>loadlib32</key>
 	<string>pdp</string>
-	<key>loadlib36</key>
-	<string>pidip</string>
 	<key>nloadlib</key>
-	<string>36</string>
+	<string>32</string>
 	<key>path1</key>
 	<string>/System/Library/Fonts</string>
 	<key>path2</key>
-- 
GitLab