From fbff0b71681578bcb479b24e8e6d3989d0573cd0 Mon Sep 17 00:00:00 2001
From: "J.F.J. Laros" <j.f.j.laros@lumc.nl>
Date: Fri, 14 Mar 2014 17:34:16 +0100
Subject: [PATCH] Switched to general LaTeX Makefile, made links relative in
 the mkpres script.

---
 Makefile  | 173 ++++++++++++++++++++++++++++++++++++++++++++++--------
 mkpres.sh |  33 ++++++-----
 2 files changed, 167 insertions(+), 39 deletions(-)

diff --git a/Makefile b/Makefile
index 1bae0e3..c93bd6b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,44 +1,167 @@
-# Makefile
+# Makefile for LaTeX documents.
 #
 
-LATEX = latex
-BIBTEX = bibtex
-DVIPS = dvips
-PS2PDF = ps2pdf14
-GNUPLOT = gnuplot
+# LaTeX core binaries.
+TEX := latex
+BIBTEX := bibtex
+GLOSSARY := makeglossaries
 
-PDF = $(addsuffix .pdf, $(basename $(shell grep -l '\\begin{document' *.tex)))
-BIB = $(addsuffix .bbl, $(basename $(shell grep -l '\\nocite{\|\\cite{' *.tex)))
-EPS = $(addsuffix .eps, $(basename $(shell ls *.gnp)))
+# Conversion to other formats.
+DVIPS := dvips
+PS2PDF := ps2pdf14
+LATEX2RTF := latex2rtf
+LIBREOFFICE := libreoffice
 
+# Pictures.
+DIA := dia
+CONVERT := convert
+GNUPLOT := gnuplot
+FONTSIZE := 20
 
-all: $(EPS) $(BIB) $(PDF) clean
+# Load the configuration file.
+-include config.mkc
+
+# Find the input files.
+SRC := $(basename $(shell grep -l '\\begin{document}' *.tex))
+PIC := $(basename $(shell ls *.dia))
+GNP := $(basename $(shell ls *.gnp))
+
+# Output.
+PDF := $(addsuffix .pdf, $(SRC))
+RTF := $(addsuffix .rtf, $(SRC))
+DOC := $(addsuffix .docx, $(SRC))
+
+# Temporary files.
+TMP := blg log nav out snm toc dvi aux idx vrb ps glg glo ist
+PNG := $(addsuffix .png, $(PIC))
+TNP := $(addsuffix .tnp, $(GNP))
+
+# Semi-permanent files.
+BIB := $(addsuffix .bbl, $(SRC))
+GLS := $(addsuffix .gls, $(GLS))
+EPS := $(addsuffix .eps, $(PIC) $(GNP))
+
+# Do not delete the semi-permanent files automatically.
+.PRECIOUS: $(BIB) $(GLS) $(EPS)
+
+# Disable built-in rules.
+.SUFFIXES:
+
+# Targets that are not associated with files.
+.PHONY: all rtf doc clean distclean release
+
+
+# Main targets
+
+all: $(PDF)
+
+rtf: $(RTF)
+
+doc: $(DOC)
 
 clean:
-	rm -f *.blg *.log *.nav *.out *.snm *.toc *.dvi *.aux *.vrb
+	rm -f $(foreach I, $(TMP), $(addsuffix .$I, $(SRC))) $(PNG) $(TNP)
+
+distclean: clean
+	rm -f $(PDF) $(RTF) $(DOC) $(BIB) $(EPS)
 
 release: all clean
 
-distclean: clean
-	rm -f $(BIB) $(PDF) $(EPS)
 
-%.aux: %.tex
-	$(LATEX) $^
-	rm $(addsuffix .dvi, $(basename $^))
+# Picture targets.
+
+%.png: %.dia
+	$(DIA) -e $@ -t png-libart $<
+
+%.eps: %.png
+	$(CONVERT) $< $@
+
+%.tnp: %.gnp $(DEP)
+	echo "set terminal postscript color eps font \"default,$(FONTSIZE)\"" > $@ ;\
+	cat $< >> $@
+
+%.eps: %.tnp
+	$(GNUPLOT) < $< > $@
+
 
-%.bbl: %.aux
+# BibTeX targets (called recursively).
+
+%.blg: %.aux
 	$(BIBTEX) $(basename $^)
 
-%.dvi: %.tex
-	$(LATEX) $^
-	$(LATEX) $^
-	$(LATEX) $^
+%.bbl: %.blg
+	@
+
+# Glossary targets (called recursively).
+
+%.glg: %.aux
+	$(GLOSSARY) $*
+
+%.glo: %.glg
+	@
+
+%.ist: %.glg
+	@
+
+%.gls: %.aux %.glg %.glo %.ist
+	@
+
+# LaTeX build targets.
+
+%.aux: %.tex $(EPS)
+	$(TEX) $< ;\
+	if (grep -s "LaTeX Warning: Citation" $*.log); then \
+	  $(MAKE) $*.bbl ;\
+	  $(TEX) $< ;\
+	fi ;\
+	if (grep -s "No file $*.gls" $*.log); then \
+	  $(MAKE) $*.gls ;\
+	fi ;\
+	while (grep -s "Rerun to get cross-references right." $*.log); do \
+	  $(TEX) $< ;\
+	done ;\
+	while (grep -s "LaTeX Warning: There were undefined references" $*.log); do \
+	  $(TEX) $< ;\
+	done ;\
+	while (grep -s "Package rerunfilecheck Warning: File" $*.log); do \
+	  $(TEX) $< ;\
+	done
+
+%.log: %.aux
+	@
+
+%.dvi: %.aux
+	@
 
-%.ps: %.dvi
-	$(DVIPS) $^ -o $@
+%.idx: %.aux
+	@
+
+%.nav: %.aux
+	@
+
+%.out: %.aux
+	@
+
+%.snm: %.aux
+	@
+
+%.toc: %.aux
+	@
+
+%.vrb: %.aux
+	@
+
+%.ps: %.dvi %.log %.aux %.idx %.nav %.out %.snm %.toc %.vrb
+	$(DVIPS) $< -o $@
+
+
+# Output targets.
 
 %.pdf: %.ps
 	$(PS2PDF) $^
 
-%.eps: %.gnp
-	$(GNUPLOT) < $<
+%.rtf: %.tex %.dvi %.log %.aux %.idx %.nav %.out %.snm %.toc %.vrb
+	$(LATEX2RTF) -o $@ $<
+
+%.docx: %.rtf
+	$(LIBREOFFICE) --headless --invisible --convert-to docx $< -o $@
diff --git a/mkpres.sh b/mkpres.sh
index 67c4135..f8f244b 100644
--- a/mkpres.sh
+++ b/mkpres.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 if ! [ -n "$1" ]; then
   echo "Usage: $0 <directory>"
@@ -10,17 +10,22 @@ if [ -e $1 ]; then
   exit
 fi
 
-here=`pwd`
-
 mkdir $1
-ln -s $here/lumc_logo.eps $1/
-ln -s $here/lumc_logo_small.eps $1/
-ln -s $here/ul_logo.eps $1/
-ln -s $here/lgtc_logo.eps $1/
-ln -s $here/nbic_logo.eps $1/
-ln -s $here/nwo_logo_en.eps $1/
-ln -s $here/ngi_logo.eps $1/
-ln -s $here/gen2phen_logo.eps $1/
-ln -s $here/Makefile $1/
-ln -s $here/beamerthemelumc.sty $1/
-cp presentation.tex $1/
+
+source=$(cd $1; pwd)
+target=$(pwd)
+
+common_part=$source
+back=
+while [ "${target#$common_part}" = "${target}" ]; do
+  common_part=$(dirname $common_part)
+  back="../${back}"
+done
+
+cp presentation.tex $1
+
+links=$(ls Makefile *.eps *.sty)
+cd $1
+for i in $links; do
+  ln -s ${back}${target#$common_part/}/${i}
+done
-- 
GitLab