From 44c4a01453dd799ac64a0b6171aafbc573b90a4d Mon Sep 17 00:00:00 2001
From: Albert Graef <aggraef@gmail.com>
Date: Sat, 10 Mar 2018 14:30:42 +0100
Subject: [PATCH] Add light build option.

---
 Makefile                     | 14 ++++++++++++++
 externals/Makefile           | 11 +++++++++--
 l2ork_addons/tar_em_up.sh    | 21 +++++++++++++++++----
 packages/Makefile            |  4 +++-
 packages/linux_make/Makefile |  2 ++
 packages/win32_inno/Makefile |  6 +++++-
 6 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index e33557582..7795b7066 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,10 @@
 # `tar_em_up.sh -tk`), bypassing Gem which takes an eternity to compile; please
 # check the tar_em_up.sh script for details
 
+# light: like `incremental`, but does a light build (equivalent to
+# `tar_em_up.sh -tkl`) which only includes the most essential externals;
+# please check the tar_em_up.sh script for details
+
 # checkout: convenience target to check out all submodules in preparation for
 # a subsequent build (the `all`, `incremental` and `dist` targets also do this
 # automatically when needed)
@@ -36,6 +40,13 @@
 
 # NOTES:
 
+# The incremental and light builds assume an existing staging area
+# (packages/*/build directory) which is *not* cleaned before installing. This
+# makes it possible to update the existing staging area after recompiling just
+# a part of the system (all but Gem in the case of "incremental", only the
+# Pd core and a few essential externals in the case of "light"). Use `make
+# clean` beforehand if you want to install into a clean staging area.
+
 # The realclean and dist targets use git commands and thus only work in a
 # working copy of the git repo, not in the static tarball snapshots produced
 # by the dist target.
@@ -65,6 +76,9 @@ all:
 incremental:
 	cd l2ork_addons && $(env) ./tar_em_up.sh -tk
 
+light:
+	cd l2ork_addons && $(env) ./tar_em_up.sh -tkl
+
 checkout:
 	git submodule update --init
 
diff --git a/externals/Makefile b/externals/Makefile
index c2bf4caad..c05ba7d2f 100644
--- a/externals/Makefile
+++ b/externals/Makefile
@@ -129,7 +129,13 @@ CXXFLAGS = $(CFLAGS)
 #
 # WARNING!  this MUST be all on one line because the automatic package
 # building scripts rely on it being that way.
+ifeq ($(LIGHT),yes)
+# minimal set of extensions for the "light" build
+LIB_TARGETS = loaders-libdir pddp
+INCREMENTAL = yes
+else
 LIB_TARGETS = adaptive arraysize autotune bassemu boids bsaylor comport creb cxc cyclone disis earplug ekext ext13 fftease fluid freeverb ggee hcs iem_ambi iem_bin_ambi iemlib iemgui iemguts iem_adaptfilt iemmatrix iemxmlrpc iem_delay iem_roomsim iem_spec2 iem_tab jasch_lib loaders-libdir lyonpotpourri mapping markex maxlib mjlib moocow moonlib motex mrpeach oscx pan pdcontainer pddp pdogg plugin pmpd rjlib sigpack smlib tof unauthorized vbap windowing zexy
+endif
 
 # DISABLED: flatgui
 
@@ -147,8 +153,9 @@ else
     ifneq ($(shell uname -r | sed 's|10\.[0-9][0-9]*\.[0-9][0-9]*|10|'),10)
       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)
+  else ifneq ($(LIGHT),yes)
+    # 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 iem16
     else
diff --git a/l2ork_addons/tar_em_up.sh b/l2ork_addons/tar_em_up.sh
index a7d7247bd..7afc75d0e 100755
--- a/l2ork_addons/tar_em_up.sh
+++ b/l2ork_addons/tar_em_up.sh
@@ -21,6 +21,7 @@ then
 	echo "     -f    full tarball installer (incremental)"
 	echo "     -F    full tarball installer (complete recompile)"
 	echo "     -k    keep previous build products"
+	echo "     -l    do a light build (only essential externals)"
 	echo "     -n    skip package creation (-bB, -fF)"
 	echo "     -r    build a Raspberry Pi deb (incremental)"
 	echo "     -R    build a Raspberry Pi deb (complete recompile)"
@@ -57,8 +58,9 @@ inno=0
 dmg=0
 any=0
 clean=1
+light=0
 
-while getopts ":bBcfFknRrTtXzZ" Option
+while getopts ":bBcfFklnRrTtXzZ" Option
 do case $Option in
 		b)		deb=1
 				inst_dir=${inst_dir:-/usr};;
@@ -74,6 +76,8 @@ do case $Option in
 
 		k)		clean=0;;
 
+		l)		light=1;;
+
 		n)		pkg=0;;
 
 		R)		deb=2
@@ -103,6 +107,13 @@ done
 
 inst_dir=${inst_dir:-/usr/local}
 
+# configure a light build if requested
+if [ $light -gt 0 ]; then
+    export LIGHT=yes
+else
+    export LIGHT=
+fi
+
 export TAR_EM_UP_PREFIX=$inst_dir
 
 # Get the OS we're running under, normalized to names that can be used
@@ -315,7 +326,7 @@ then
 	if [[ $os == "win" ]]; then
 		echo "Making Windows package..."
 		echo `pwd`
-		make install INCREMENTAL=$INCREMENTAL && make package
+		make install INCREMENTAL=$INCREMENTAL LIGHT=$LIGHT && make package
 	elif [[ $os == "osx" ]]; then
 		echo "Making OSX package (dmg)..."
 		echo `pwd`
@@ -332,7 +343,7 @@ then
 		cd ../../l2ork_addons
 	elif [[ $os == "osx" ]]; then
 		cd ../../l2ork_addons
-	else
+	elif [ $light -eq 0 ]; then
 		cd ../../l2ork_addons/spectdelay/spectdelay~
 		./linux-install.sh
 		cp -f spectdelay~.pd_linux ../../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
@@ -340,9 +351,11 @@ then
 		cp -f array* ../../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
 		# return to l2ork_addons folder
 		cd ../../
+	else
+		cd ../../l2ork_addons
 	fi
 	# install raspberry pi externals (if applicable)
-	if [ $inno -eq 0 -a $dmg -eq 0 ]; then
+	if [ $inno -eq 0 -a $dmg -eq 0 -a $light -eq 0 ]; then
 		cd raspberry_pi
 		./makeall.sh
 		cp -f disis_gpio/disis_gpio.pd_linux ../../packages/linux_make/build$inst_dir/lib/pd-l2ork/extra
diff --git a/packages/Makefile b/packages/Makefile
index 69ae8def8..d99f98331 100644
--- a/packages/Makefile
+++ b/packages/Makefile
@@ -193,7 +193,9 @@ devel_install: pd_devel_install
 #------------------------------------------------------------------------------
 # abstractions_install
 abstractions_install:
+ifneq ($(LIGHT),yes)
 	$(MAKE) -C $(abstractions_src) $(DEST_PATHS) install
+endif
 
 #------------------------------------------------------------------------------
 # extensions_install
@@ -204,7 +206,7 @@ extensions_install:
 #------------------------------------------------------------------------------
 # externals_install
 externals_install: 
-	$(MAKE) -C $(externals_src) $(DEST_PATHS) install INCREMENTAL=$(INCREMENTAL)
+	$(MAKE) -C $(externals_src) $(DEST_PATHS) install INCREMENTAL=$(INCREMENTAL) LIGHT=$(LIGHT)
 
 
 #------------------------------------------------------------------------------
diff --git a/packages/linux_make/Makefile b/packages/linux_make/Makefile
index 86f62d8ef..909df4ba2 100644
--- a/packages/linux_make/Makefile
+++ b/packages/linux_make/Makefile
@@ -83,10 +83,12 @@ tarbz2: installer_settings installer_makefile installer_readme
 
 # Any special staging for the "Burrito Supreme" installer goes here.
 debstage: $(bindir)
+ifneq ($(LIGHT),yes)
 # add K12 mode
 	cp -rf ../../l2ork_addons/K12/ $(DESTDIR)$(libpddir)/extra/
 # add arduino library
 	cp -rf ../../externals/hardware/arduino $(DESTDIR)$(libpddir)/extra/
+endif
 # free desktop menu, mime, and icon support
 # perhaps the icons should go in /usr/share/pixmaps like 'scribus'
 	install -d $(DESTDIR)/usr/share/icons/hicolor/128x128/apps
diff --git a/packages/win32_inno/Makefile b/packages/win32_inno/Makefile
index f8711f27a..7211ef564 100755
--- a/packages/win32_inno/Makefile
+++ b/packages/win32_inno/Makefile
@@ -62,7 +62,7 @@ install: pd_install prebuilt_install lib_install exe_install
 
 
 prebuilt_install:
-	$(MAKE) -C $(packages_src) $(DEST_PATHS) extended_install INCREMENTAL=$(INCREMENTAL)
+	$(MAKE) -C $(packages_src) $(DEST_PATHS) extended_install INCREMENTAL=$(INCREMENTAL) LIGHT=$(LIGHT)
 	$(MAKE) -C $(packages_src) $(DEST_PATHS) doc_format
 	install -p pd-settings.reg $(DESTDIR)$(prefix)
 
@@ -95,6 +95,7 @@ lib_install:
 	install -p $(bin_src)/libvorbisenc-2.dll  $(DESTDIR)$(bindir)/
 	install -p $(bin_src)/libvorbisfile-3.dll  $(DESTDIR)$(bindir)/
 	install -p $(bin_src)/libmp3lame-0.dll  $(DESTDIR)$(bindir)/
+ifneq ($(LIGHT),yes)
 	# I think these two are needed for zexy/matchbox and zexy/regex
 	install -p $(bin_src)/libsystre-0.dll $(DESTDIR)$(bindir)/
 	install -p $(bin_src)/libtre-5.dll $(DESTDIR)$(bindir)/
@@ -127,6 +128,7 @@ lib_install:
 	-install -p $(DESTDIR)/extra/Gem/gem_model*.dll $(DESTDIR)$(bindir)/
 	-install -p $(DESTDIR)/extra/Gem/gem_record*.dll $(DESTDIR)$(bindir)/
 	-install -p $(DESTDIR)/extra/Gem/gem_video*.dll $(DESTDIR)$(bindir)/
+endif
 # these stay with pd.exe
 # if these are installed, include them in the build root
 	-install -p $(system32)/msvcp71.dll   $(DESTDIR)$(bindir)
@@ -135,12 +137,14 @@ lib_install:
 	install -p $(bin_src)/libwinpthread-1.dll $(DESTDIR)$(bindir)
 	install -p $(bin_src)/libgcc_s_dw2-1.dll $(DESTDIR)$(bindir)
 	install -p $(bin_src)/libstdc++-6.dll $(DESTDIR)$(bindir)
+ifneq ($(LIGHT),yes)
 # lyonpotpourri compiles its own shared lib. On Windows it needs to be
 # in the path of the pd executable in order to get loaded. (There's probably
 # also a way to add the external lib's path but I don't know how to do that.)
 	install -p $(DESTDIR)/extra/lyonpotpourri/liblyonpotpourri.dll $(DESTDIR)$(bindir)
 # fftease also uses a shared lib...
 	install -p $(DESTDIR)/extra/fftease/libfftease.dll $(DESTDIR)$(bindir)
+endif
 
 
 exe_install:
-- 
GitLab