From 14165661f54ecb5ac9a938495ca3e1420e0df3f4 Mon Sep 17 00:00:00 2001
From: Albert Graef <aggraef@gmail.com>
Date: Sun, 8 Jan 2017 06:47:02 +0100
Subject: [PATCH] debuild: Make it possible to install purr-data along with
 pd-l2ork.

---
 debuild/Makefile         |  2 ++
 debuild/debian/control   |  2 --
 debuild/debian/rules     | 41 +++++++++++++++++++++++-----------------
 debuild/userconfig.patch | 31 ++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+), 19 deletions(-)
 create mode 100644 debuild/userconfig.patch

diff --git a/debuild/Makefile b/debuild/Makefile
index 5466d5088..f4cb6be0e 100644
--- a/debuild/Makefile
+++ b/debuild/Makefile
@@ -80,6 +80,8 @@ deb: $(debsrc) $(addprefix debian/nwjs/, $(nwjs))
 # (patch from pd-extended by Hans-Christoph Steiner, modified for pd-l2ork).
 # This can be removed once Ubuntu 12.04 finally goes the way of the dodo.
 #	cd $(debdist) && patch -p1 < ../precise-configure.patch
+# Patch the user config dir name so that purr-data can coexist with pd-l2ork.
+	cd $(debdist) && patch -Np1 < ../userconfig.patch
 # Make sure to copy the Debian files which may have uncommitted changes.
 # Then run debuild to create the package.
 	cd $(debdist) && cp -R ../debian . && debuild $(DEBUILD_FLAGS)
diff --git a/debuild/debian/control b/debuild/debian/control
index 1cda46f25..1ae51ff90 100644
--- a/debuild/debian/control
+++ b/debuild/debian/control
@@ -10,8 +10,6 @@ Package: purr-data
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}, python, python-tk, tkpng, tclxapian, fluid-soundfont-gm
 Recommends: xdg-utils, pulseaudio-utils, tap-plugins, ladspa-foo-plugins, invada-studio-plugins-ladspa, blepvco, swh-plugins, mcp-plugins, cmt, blop, omins, ubuntustudio-audio-plugins, rev-plugins, dssi-utils, vco-plugins, wah-plugins, fil-plugins, mda-lv2
-Provides: pd-l2ork
-Replaces: pd-l2ork
 Description:  Interactive multimedia programming environment (NW.js variant)
  This is Jonathan Wilkes' nw.js variant of Pd-L2Ork, nick-named
  "Purr-Data". Basically, it is Pd-L2Ork with the Tk GUI replaced
diff --git a/debuild/debian/rules b/debuild/debian/rules
index 28f6980fc..5da272b15 100755
--- a/debuild/debian/rules
+++ b/debuild/debian/rules
@@ -13,6 +13,13 @@ else
 arch = ia32
 endif
 
+# Installation prefix. This must be something other than /usr if you want to
+# install Purr Data alongside Pd-L2Ork. Note that some items such as desktop
+# files and icons will still be installed under /usr so that the system finds
+# them, but they will be renamed to prevent name clashes with files from the
+# pd-l2ork package.
+prefix = /opt/purr-data
+
 %:
 	dh $@
 
@@ -21,28 +28,28 @@ override_dh_auto_configure:
 override_dh_auto_build:
 # Copy the nw.js sources to where purr-data wants them.
 	tar -xf debian/nwjs/$(nwjspkg)-$(arch).tar.gz && rm -rf pd/nw/nw && mv $(nwjspkg)-$(arch) pd/nw/nw
-	cd l2ork_addons && ./tar_em_up.sh -B -n
+	cd l2ork_addons && (export inst_dir=$(prefix); ./tar_em_up.sh -B -n)
 
 override_dh_auto_install:
 	mkdir -p debian/purr-data && mv packages/linux_make/build/* debian/purr-data
+# Create a link to the executable.
+	mkdir -p debian/purr-data/usr/bin && ln -sf $(prefix)/bin/pd-l2ork debian/purr-data/usr/bin/purr-data
+# Create links to the include and lib directories.
+	mkdir -p debian/purr-data/usr/include && ln -sf $(prefix)/include/pd-l2ork debian/purr-data/usr/include/purr-data
+	mkdir -p debian/purr-data/usr/lib && ln -sf $(prefix)/lib/pd-l2ork debian/purr-data/usr/lib/purr-data
 # Remove some unneeded files.
-	cd debian/purr-data/ && rm -f Makefile README.txt
-#	cd debian/purr-data/usr/lib/pd-l2ork/bin && rm -f DejaVuSansMono.ttf
-	cd debian/purr-data/usr/share/applications && rm -f pd-l2ork-k12*.desktop
-	cd debian/purr-data/usr/lib/pd-l2ork/extra && rm -rf */*.pd_linux_o */*.la
-# Move cyclist and pdsend/pdreceive to the pd-l2ork lib directory to prevent
-# conflicts with other packages providing these files.
-	cd debian/purr-data/usr/bin && mv pdsend pdreceive cyclist ../lib/pd-l2ork/bin
-# Also remove the corresponding man pages.
-	cd debian/purr-data/usr/share/man/man1 && rm -rf pdsend.* pdreceive.*
-# Move the Gem include files into the pd-l2ork include directory to prevent
-# conflicts with other packages providing these files.
-	cd debian/purr-data/usr && mv include/Gem include/pd-l2ork
-# Edit the Gem pkgconfig file accordingly and rename it.
-	cd debian/purr-data/usr/lib/pkgconfig && sed -e 's?/include?/include/pd-l2ork?g' -e 's?/lib/pd/extra?/lib/pd-l2ork/extra?g' < Gem.pc > pd-l2ork-Gem.pc && rm -f Gem.pc
+	cd debian/purr-data/ && rm -rf Makefile README.txt etc usr/share/emacs
+	cd debian/purr-data$(prefix)/lib/pd-l2ork/extra && rm -rf */*.pd_linux_o */*.la
+# Edit the library paths in the default user.settings file.
+	cd debian/purr-data$(prefix)/lib/pd-l2ork && sed -e "s!/usr/lib/pd-l2ork!$(prefix)/lib/pd-l2ork!g" -i default.settings
+# Replace the pd-l2ork desktop/mime files and icons with purr-data ones.
+	cd debian/purr-data/usr/share/applications && (sed -e 's/pd-l2ork/purr-data/g' -e 's/Pd-L2Ork/Purr-Data/g' < pd-l2ork.desktop > purr-data.desktop) && (sed -e 's/pd-l2ork/purr-data/g' -e 's/Pd-L2Ork/Purr-Data/g' < pd-l2ork-debug.desktop > purr-data-debug.desktop) && rm -f pd-l2ork*.desktop
+	cd debian/purr-data/usr/share/mime/packages && (sed -e 's/pd-l2ork/purr-data/g' < pd-l2ork.xml > purr-data.xml) && rm -f pd-l2ork.xml
+	cd debian/purr-data/usr/share/icons/hicolor/128x128/apps/ && rm -f pd-l2ork-k12*.png && mv pd-l2ork.png purr-data.png && mv pd-l2ork-red.png purr-data-red.png
+	cd debian/purr-data/usr/share/icons/hicolor/128x128/mimetypes/ && mv text-x-pd-l2ork.png text-x-purr-data.png
 # Sanitize permissions.
-	cd debian/purr-data && chmod -R go-w * && chmod -R a+r * && chmod a-x usr/lib/pd-l2ork/default.settings
-	find debian/purr-data/usr/lib/pd-l2ork/bin/nw -executable -not -type d | xargs chmod a+x
+	cd debian/purr-data && chmod -R go-w * && chmod -R a+r * && chmod a-x .$(prefix)/lib/pd-l2ork/default.settings
+	find debian/purr-data$(prefix)/lib/pd-l2ork/bin/nw -executable -not -type d | xargs chmod a+x
 	find debian/purr-data -executable -name '*.pd_linux' | xargs chmod a-x
 	find debian/purr-data -executable -name '*.pd' | xargs chmod a-x
 	find debian/purr-data -executable -name '*.txt' | xargs chmod a-x
diff --git a/debuild/userconfig.patch b/debuild/userconfig.patch
new file mode 100644
index 000000000..b5ec5ff5e
--- /dev/null
+++ b/debuild/userconfig.patch
@@ -0,0 +1,31 @@
+diff --git a/pd/src/s_file.c b/pd/src/s_file.c
+index 1c18096f..576e4c36 100644
+--- a/pd/src/s_file.c
++++ b/pd/src/s_file.c
+@@ -62,7 +62,7 @@ static void sys_initloadpreferences( void)
+              sys_libdir->s_name);
+ 
+     if (homedir)
+-        snprintf(user_prefs_file, FILENAME_MAX, "%s/.pd-l2ork/user.settings", homedir);
++        snprintf(user_prefs_file, FILENAME_MAX, "%s/.purr-data/user.settings", homedir);
+     if (stat(user_prefs_file, &statbuf) == 0) 
+         strncpy(filenamebuf, user_prefs_file, FILENAME_MAX);
+     else if (stat(default_prefs_file, &statbuf) == 0)
+@@ -143,7 +143,7 @@ static void sys_initsavepreferences( void)
+ 
+     if (!homedir)
+         return;
+-    snprintf(filenamebuf, FILENAME_MAX, "%s/.pd-l2ork", homedir);
++    snprintf(filenamebuf, FILENAME_MAX, "%s/.purr-data", homedir);
+     filenamebuf[FILENAME_MAX-1] = 0;
+     if (stat(filenamebuf, &statbuf) || !S_ISDIR(statbuf.st_mode)) {
+       // user config dir doesn't exist yet, try to create it
+@@ -152,7 +152,7 @@ static void sys_initsavepreferences( void)
+ 	return;
+       }
+     }
+-    snprintf(filenamebuf, FILENAME_MAX, "%s/.pd-l2ork/user.settings", homedir);
++    snprintf(filenamebuf, FILENAME_MAX, "%s/.purr-data/user.settings", homedir);
+     filenamebuf[FILENAME_MAX-1] = 0;
+     if ((sys_prefsavefp = fopen(filenamebuf, "w")) == NULL)
+     {
-- 
GitLab