aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 2dc72eb99284b9501e689e3788262acd2fd38539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
NAME  = ekdosis
SHELL = bash
CMP   = lualatex-dev
PWD   = $(shell pwd)
#VERS  = $(shell ltxfileinfo -v $(NAME).dtx|sed -e 's/^v//')
VERS := $(shell typeoutfileinfo $(NAME).dtx | egrep -o '\+.*$$' | awk '{ print $$6 }' | sed -e 's/^v//')
LOCAL = $(shell kpsewhich --var-value TEXMFLOCAL)
UTREE = $(shell kpsewhich --var-value TEXMFHOME)
HOMEDIR := $$HOME
SAMPLES := samples

exts := md html ins dtx el
files := AUTHORS.md LICENSE
zfiles := {AUTHORS.md,LICENSE}
findopts := $(foreach ext,$(exts),-or -iname "*.$(ext)")
findfiles := $(foreach file,$(files), -or -iname "$(file)")

define do_documentation
	$(CMP) --shell-escape --recorder --interaction=nonstopmode $(NAME).dtx >/dev/null
endef

all:	sty $(NAME).pdf

testsamples:
	if [ ! -d $(SAMPLES) ] ; \
	then echo "$(SAMPLES)/ directory is needed. Aborting." && exit 1 ; \
	fi

sty: clean
	$(CMP) $(NAME).ins >/dev/null

$(NAME).pdf: testsamples $(NAME).dtx
	@ echo "Making the sample files first..."
	@ $(MAKE) --directory=$(SAMPLES) >/dev/null
	@ echo "Done making samples"
	@ echo "Building the documentation of $(NAME) with $(CMP). Please be patient..."
	@ $(do_documentation)
	@ echo "Now calling biber"
	@ biber $(NAME) >/dev/null
	@ echo "Returning to $(CMP)..."
	@ for run in {1..4}; do $(do_documentation); done
	@ echo "Building indexes..."
	@ if [ -f $(NAME).glo ]; then makeindex -q -s gglo.ist -o $(NAME).gls $(NAME).glo; fi
	@ if [ -f $(NAME).idx ]; then makeindex -q -s gind.ist -o $(NAME).ind $(NAME).idx; fi
	@ echo "Final runs of $(CMP)..."
	@ for run in {1..7}; do $(do_documentation); done
	@ echo "Done"

samples: clean sty
	$(MAKE) --directory=$(SAMPLES)

clean: testsamples
	@ echo "Cleaning $(NAME) directory"
	rm -f $(NAME).bib $(PWD)/TMP/*.bib
	rm -rf .backup
	rm -rf auto
	find ./ -iname "*~" -or -iname "*.pdf" -or -iname "*_out*.tex" | xargs rm -rf
	find ./* -type f -iname "Makefile" $(findopts) $(findfiles) > ls-R
	find ./* -type f -iname "*.tex" | grep '/samples/' >> ls-R
	rsync -aPr --files-from=ls-R . .backup
	rm -rf *
	cp -p -r .backup/* .
	rm -rf .backup

pandoc:
	pandoc README.md -o about.html

auctex:
	emacs --batch -f batch-byte-compile ekdosis.el &>/dev/null
	if [ ! -d "$(HOMEDIR)/.emacs.d/auctex/style" ]; then \
	mkdir -p $(HOMEDIR)/.emacs.d/auctex/style; \
	fi
	cp $(NAME)*.{el,elc} $(HOMEDIR)/.emacs.d/auctex/style

distclean: clean uninst

uninst:
	rm -rf $(UTREE)/{tex,source,doc}/lualatex/$(NAME)
	rm -rf $(HOMEDIR)/.emacs.d/auctex/style/$(NAME).{el,elc}

inst: uninst auctex all
	@ echo "Installing $(NAME) locally"
	mkdir -p $(UTREE)/{tex,source,doc}/lualatex/$(NAME)
	cp $(NAME).dtx $(UTREE)/source/lualatex/$(NAME)
	cp $(NAME).sty $(UTREE)/tex/lualatex/$(NAME)
	cp $(NAME).lua $(UTREE)/tex/lualatex/$(NAME)
	cp $(NAME).pdf $(files) $(UTREE)/doc/lualatex/$(NAME)
	cp -r samples/ $(UTREE)/doc/lualatex/$(NAME)
	@ echo "Installation complete. Happy TeXing!"

local: uninst auctex
	$(CMP) $(NAME).ins
	mkdir -p $(UTREE)/{tex,source,doc}/lualatex/$(NAME)
	cp $(NAME).sty $(UTREE)/tex/lualatex/$(NAME)
	cp $(NAME).lua $(UTREE)/tex/lualatex/$(NAME)
	if [ -e "$(NAME).pdf" ]; then cp $(NAME).pdf $(files) $(UTREE)/doc/lualatex/$(NAME) &&\
	cp -r $(SAMPLES)/ $(UTREE)/doc/lualatex/$(NAME); fi

install: all
	sudo mkdir -p $(LOCAL)/{tex,source,doc}/latex/$(NAME)
	sudo cp $(NAME).dtx $(LOCAL)/source/latex/$(NAME)
	sudo cp $(NAME).sty $(LOCAL)/tex/latex/$(NAME)
	sudo cp $(NAME).pdf $(files) $(LOCAL)/doc/latex/$(NAME)
	cp -r $(SAMPLES)/ $(LOCAL)/doc/latex/$(NAME)

uninstall:
	rm -rf $(LOCAL)/{tex,source,doc}/latex/$(NAME)

zip: all
	ln -sf . $(NAME)
	zip -Drq $(PWD)/$(NAME)-$(VERS).zip $(NAME)/{$(zfiles),samples,README.md,$(NAME).{pdf,sty,lua,el}}
	rm $(NAME)

hal: clean
	zip -Drq $(PWD)/$(NAME)-$(VERS).zip *

package: distclean all
	mkdir $(NAME)/
	cp Makefile README.md $(NAME).{ins,dtx,pdf,el} $(NAME)/
	cp -r samples/ $(NAME)/
	mkdir -p tex/lualatex/$(NAME)/
	cp *.lua *.sty tex/lualatex/$(NAME)/
	mkdir -p doc/lualatex/$(NAME)/
	cp $(files) README.md *.el *.pdf doc/lualatex/$(NAME)/
	cp -r samples/ doc/lualatex/$(NAME)/
	mkdir -p source/lualatex/$(NAME)/
	cp Makefile *.ins *.dtx source/lualatex/$(NAME)/
	zip -r $(NAME).tds.zip tex doc source
	rm -rf tex/ source/ doc/
	tar czf $(NAME)-$(VERS).tar.gz $(NAME).tds.zip $(NAME)/
	rm -rf $(NAME)/

.SILENT: testsamples
.PHONY: all clean distclean pandoc inst local uninst install uninstall zip hal package samples testsamples