From 358618dfd57a21e4f14b51d396e4224a0a1f5b23 Mon Sep 17 00:00:00 2001
From: witiko <witiko@gmail.com>
Date: Thu, 16 Apr 2015 20:31:01 +0200
Subject: [PATCH] Updated the Makefile

The new target `uninstall` removes the files of the package from
the TeX directory structure. The `dist` and `dist-clean` structure
creates a browsable and a TeX directory structure-compliant
archives containing the files of the package.
---
 Makefile | 86 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 71 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index d71a3b2..4fd27f7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-.PHONY: all explode clean clean-all install
+.PHONY: all clean dist dist-clean explode implode install uninstall
 
 SUBMAKEFILES=logo/mu logo/mu/color locale style style/mu
 CLASSFILES=fithesis.cls fithesis2.cls fithesis3.cls
@@ -6,14 +6,17 @@ STYLEFILES=style/*.sty style/*/*.sty style/*/*.clo
 LOGOFILES=logo/*/*.eps logo/*/color/*.eps logo/*/*.pdf logo/*/color/*.pdf
 LOCALEFILES=locale/*.def locale/*/*.def locale/*/*/*.def
 DTXFILES=*.dtx locale/*.dtx style/*.dtx style/*/*.dtx
+INSFILES=*.ins locale/*.ins style/*.ins style/*/*.ins
+MAKEFILES=Makefile */Makefile */*/Makefile */*/*/Makefile
 RESOURCES=$(STYLEFILES) $(LOGOFILES) $(LOCALEFILES)
-SOURCES=$(DTXFILES) Makefile docstrip.cfg
+SOURCEFILES=$(DTXFILES) $(INSFILES) docstrip.cfg
 AUXFILES=example.aux example.log example.out example.toc example.lot example.lof example.bib fithesis.aux fithesis.log fithesis.toc fithesis.ind fithesis.idx fithesis.out fithesis.ilg fithesis.gls fithesis.glo fithesis.hd
 MANUAL=fithesis.pdf
 PDFSOURCES=fithesis.dtx example.tex
 PDFFILES=$(MANUAL) example.pdf
+TDSFILE=fithesis3.tds.zip
 DISTFILE=fithesis3.zip
-TEXFILES=$(CLASSFILES) $(RESOURCES)
+LATEXFILES=$(CLASSFILES) $(RESOURCES)
 TEXLIVEDIR=$(shell kpsewhich -var-value TEXMFLOCAL)
 
 # This pseudo-target creates the class files, typesets both
@@ -25,7 +28,10 @@ all:
 
 # This pseudo-target creates the class files and typesets
 # both the example file and the technical documentation
-explode: fithesis3.cls $(PDFFILES) $(DISTFILE)
+explode: fithesis3.cls $(PDFFILES)
+
+# This pseudo-target creates the distribution archives.
+dist: all $(TDSFILE) $(DISTFILE)
 
 # This target creates the class files.
 fithesis3.cls: fithesis.ins fithesis.dtx
@@ -44,30 +50,80 @@ example.pdf: example.tex fithesis3.cls $(RESOURCES)
 	pdflatex $<
 	pdflatex $<
 
+# This target generates a TeX directory structure file
+$(TDSFILE): $(LATEXFILES) $(SOURCEFILES) $(PDFFILES) $(PDFSOURCES)
+	DIR=`mktemp -d` && \
+	make install to="$$DIR" nohash=true && \
+  (cd "$$DIR" && zip -r -v -nw $@ *) && \
+	mv "$$DIR"/$@ $@ && rm -rf "$$DIR"
+
 # This target generates a distribution file
-$(DISTFILE): $(TEXFILES) $(SOURCES) $(PDFFILES) $(PDFSOURCES)
-	zip -r -v $@ $^
+$(DISTFILE): $(LATEXFILES) $(SOURCEFILES) $(MAKEFILES) $(PDFFILES) $(PDFSOURCES)
+	DIR=`mktemp -d` && mkdir "$$DIR/fithesis3" && \
+	cp --verbose $(TDSFILE) "$$DIR" && \
+	cp --parents --verbose $^ "$$DIR/fithesis3" && \
+  (cd "$$DIR" && zip -r -v -nw $@ *) && \
+	mv "$$DIR"/$@ $@ && rm -rf "$$DIR"
 
 # This pseudo-target installs the class files and
-# the technical documentation into the folder structure
-# of the TeXLive package, whose root directory is
-# specified within the "to" argument.
+# the technical documentation into the TeX directory
+# structure, whose root directory is specified within
+# the "to" argument. Specify "nohash=true", if you wish
+# to forgo the reindexing of the package database.
 install:
 	@if [ -z "$(to)" ]; then \
-	  printf "Usage: make to=DIRECTORY install-texlive\nDetected TeXLive directory: %s\n" $(TEXLIVEDIR); \
+	  printf "Usage: make install to=DIRECTORY\nDetected TeXLive directory: %s\n" $(TEXLIVEDIR); \
 	  exit 1; \
-  fi
+	fi
+	
+	# Class, locale, style and logo files
 	mkdir --parents "$(to)/tex/latex/fithesis3"
-	cp --parents --verbose $(TEXFILES) "$(to)/tex/latex/fithesis3"
+	cp --parents --verbose $(LATEXFILES) "$(to)/tex/latex/fithesis3"
+	
+	# Source files
+	mkdir --parents "$(to)/source/latex/fithesis3"
+	cp --parents --verbose $(SOURCEFILES) "$(to)/source/latex/fithesis3"
+	
+	# Documentation
 	mkdir --parents "$(to)/doc/latex/fithesis3"
 	cp $(MANUAL) "$(to)/doc/latex/fithesis3/manual.pdf"
-	texhash
+
+	# Rebuild the hash
+	[ "$(nohash)" = "true" ] || texhash
+
+# This pseudo-target installs the class files and
+# the technical documentation into the TeX directory
+# structure, whose root directory is specified within
+# the "to" argument. Specify "nohash=true", if you wish
+# to forgo the reindexing of the package database.
+uninstall:
+	@if [ -z "$(from)" ]; then \
+	  printf "Usage: make uninstall from=DIRECTORY\nDetected TeXLive directory: %s\n" $(TEXLIVEDIR); \
+	  exit 1; \
+	fi
+	
+	# Class, locale, style and logo files
+	rm -rf "$(from)/tex/latex/fithesis3"
+	
+	# Source files
+	rm -rf "$(from)/source/latex/fithesis3"
+	
+	# Documentation
+	rm "$(from)/doc/latex/fithesis3/manual.pdf"
+	rmdir "$(from)/doc/latex/fithesis3/"
+
+	# Rebuild the hash
+	[ "$(nohash)" = "true" ] || texhash
 
 # This pseudo-target removes any existing auxiliary files.
 clean:
 	rm -f $(AUXFILES)
 
+# This pseudo-target removes the distribution archives.
+dist-clean:
+	rm -f $(DISTFILE) $(TDSFILE)
+
 # This pseudo-target removes any makeable files.
-implode: clean
-	rm -f $(PDFFILES) $(CLASSFILES) $(DISTFILE)
+implode: clean dist-clean
+	rm -f $(PDFFILES) $(CLASSFILES)
 	for dir in $(SUBMAKEFILES); do make implode -C "$$dir"; done
-- 
GitLab