From 349308ef01b15b20b42da357cba2661e89c60582 Mon Sep 17 00:00:00 2001
From: mazmazz <mar.marcoz@outlook.com>
Date: Mon, 26 Nov 2018 23:54:55 -0500
Subject: [PATCH] Do not clean files before source building

---
 assets/debian/README.Debian  | 17 ++++++++++++-----
 assets/debian/rules          | 35 ++++++++++++++++++++++++-----------
 assets/debian/source/options |  1 -
 debian/README.Debian         | 11 +++++++----
 4 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/assets/debian/README.Debian b/assets/debian/README.Debian
index b0c13337d..95ac42dda 100644
--- a/assets/debian/README.Debian
+++ b/assets/debian/README.Debian
@@ -12,7 +12,7 @@ with apt-key add. Thanks!
  -- Callum Dickinson <gcfreak_ag20@hotmail.com>  Fri, 26 Nov 2010 18:25:31 +1300
 
 
-Building for Launchpad PPA
+Signing for Launchpad PPA
 
 First, follow the above instructions to generate a GnuPG key with your identity. You will need
 to publish the fingerprint of that key to Ubuntu's key server.
@@ -26,20 +26,27 @@ upload signed source packages and publish them onto your PPA.
 IF YOU UPLOAD A PACKAGE and Launchpad does NOT send you a confirmation or rejection email, that
 means your key is not set up correctly with your Launchpad account.
 
+
+Building for Launchpad PPA
+
 Use these steps to prepare building a source package for Launchpad:
 
-   -2. Highly recommend copying the assets/ folder to outside your repo folder, or else the asset
+    1. Highly recommend copying the assets/ folder to outside your repo folder, or else the asset
        files may be included in the main source package, when you build that.
-   -1. cd [wherever-your-assets-folder-is]/assets/
-    0. debuild -T clean (optional, if you already have asset files)
+    2. cd [wherever-your-assets-folder-is]/assets/
+    3. debuild -T clean (optional, if you already have asset files)
 
 Building the source package is a two-step process:
 
-    1. debuild -T build (this downloads the asset files from srb2.org)
+    1. debuild -T pre-source (this downloads the asset files from srb2.org if necessary)
     2. debuild -S -nc
         * Builds the source package for Launchpad, including the asset files
         * -nc keeps dpkg from cleaning the assets/ folder, which would remove the files that must
           be packaged.
+    3. rm ./NOCLEAN
+        * This is a HACK file to prevent Launchpad from cleaning the asset files before building.
+          A copy of this file is in the source package, so we don't need it anymore and
+          we can delete it. If it stays in the assets/ folder, the next clean will be skipped.
 
 Then follow the instructions at <https://help.launchpad.net/Packaging/PPA/Uploading> to upload
 to your PPA and have Launchpad build your binary deb packages.
diff --git a/assets/debian/rules b/assets/debian/rules
index 7b8f32169..f79659d96 100755
--- a/assets/debian/rules
+++ b/assets/debian/rules
@@ -62,6 +62,13 @@ build:
 		fi; \
 	done
 
+pre-source: build
+	# HACK HACK HACK: Force Launchpad to not clean by creating this
+	# file and storing it in the source package.
+	# We do this so the asset files are not deleted before build
+	# In Launchpad, we can't download the assets from srb2.org because DNS does not work
+	> $(RESOURCEDIR)/NOCLEAN
+
 binary-indep:
 	# Generate install folder file
 	echo $(DATADIR) > $(DIR)/debian/$(PACKAGE).install
@@ -100,16 +107,22 @@ binary: binary-indep
 	dh_builddeb
 
 clean:
-	$(RM) $(RESOURCEDIR)/*.wad
-	$(RM) $(RESOURCEDIR)/*.dta
-	$(RM) $(RESOURCEDIR)/*.plr
-	$(RM) $(RESOURCEDIR)/*.wpn
-	$(RM) $(RESOURCEDIR)/*.srb
-	$(RM) $(RESOURCEDIR)/*.dll
-	$(RM) $(RESOURCEDIR)/*.txt
-	$(RM) $(DIR)/debian/tmp/*
-	$(RM) $(DIR)/debian/$(PACKAGE).install
-	$(RM) $(DIR)/debian/files
-	$(RM) $(DIR)/debian/source/include-binaries
+	if [ ! -f $(RESOURCEDIR)/NOCLEAN ]; then \
+		$(RM) $(RESOURCEDIR)/*.wad; \
+		$(RM) $(RESOURCEDIR)/*.dta; \
+		$(RM) $(RESOURCEDIR)/*.plr; \
+		$(RM) $(RESOURCEDIR)/*.wpn; \
+		$(RM) $(RESOURCEDIR)/*.srb; \
+		$(RM) $(RESOURCEDIR)/*.dll; \
+		$(RM) $(RESOURCEDIR)/*.txt; \
+		$(RM) $(DIR)/debian/tmp/*; \
+		$(RM) $(DIR)/debian/$(PACKAGE).install; \
+		$(RM) $(DIR)/debian/files; \
+		$(RM) $(DIR)/debian/source/include-binaries; \
+	else
+		echo Clean was ignored because of $(RESOURCEDIR)/NOCLEAN file. Run clean again if you need to!; \
+		echo Deleting $(RESOURCEDIR)/NOCLEAN...; \
+		$(RM) $(RESOURCEDIR)/NOCLEAN; \
+	fi
 
 .PHONY: all clean binary binary-arch binary-indep build
diff --git a/assets/debian/source/options b/assets/debian/source/options
index d383111a2..8b331485a 100644
--- a/assets/debian/source/options
+++ b/assets/debian/source/options
@@ -1,2 +1 @@
 tar-ignore = "tmp/*"
-no-pre-clean
diff --git a/debian/README.Debian b/debian/README.Debian
index 6ab440eb9..0e61580f0 100644
--- a/debian/README.Debian
+++ b/debian/README.Debian
@@ -11,7 +11,7 @@ and give them to your users to install with apt-key add. Thanks!
  -- Callum Dickinson <gcfreak_ag20@hotmail.com>  Fri, 26 Nov 2010 18:25:31 +1300
 
 
-Building for Launchpad PPA
+Signing for Launchpad PPA
 
 First, follow the above instructions to generate a GnuPG key with your identity. You will need
 to publish the fingerprint of that key to Ubuntu's key server.
@@ -25,13 +25,16 @@ upload signed source packages and publish them onto your PPA.
 IF YOU UPLOAD A PACKAGE and Launchpad does NOT send you a confirmation or rejection email, that
 means your key is not set up correctly with your Launchpad account.
 
+
+Building for Launchpad PPA
+
 Use these steps to prepare building a source package for Launchpad:
 
-   -2. cd [srb2repo]
-   -1. git reset --hard; git clean -fd; git clean -fx;
+    1. cd [srb2repo]
+    2. git reset --hard; git clean -fd; git clean -fx;
        * Resets your repo folder to a committed state and removes untracked files
        * If you built srb2-data in the assets/ folder, MAKE SURE THAT FOLDER DOES NOT HAVE ASSETS,
-         OR THEY WILL BE INCLUDED IN THE MAIN SOURCE PACKAGE! (for some reason)
+         OR THEY WILL BE INCLUDED IN THE MAIN SOURCE PACKAGE!
 
 Building the source package takes just one step:
 
-- 
GitLab