aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 69649269ce042f06456e2e3eb5ea0b7ce9c2a103 (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
NAME  = ekdosis
SHELL = bash
CMP   = lualatex-dev
PWD   = $(shell pwd)
VERS  = $(shell ltxfileinfo -v $(NAME).dtx|sed -e 's/^v//')
LOCAL = $(shell kpsewhich --var-value TEXMFLOCAL)
UTREE = $(shell kpsewhich --var-value TEXMFHOME)
HOMEDIR := $$HOME

exts := md html ins dtx el
texsamples := $(basename $(wildcard $(PWD)/samples/*.tex))
texsamplesout := $(notdir $(basename $(wildcard $(PWD)/samples/*.tex)))
findopts := $(foreach ext,$(exts),-or -iname "*.$(ext)")

define dosamples
	$(CMP) --output-dir=$(PWD)/TMP --shell-escape $1 >/dev/null
	$(CMP) --output-dir=$(PWD)/TMP --shell-escape $1 >/dev/null
	$(CMP) --output-dir=$(PWD)/TMP --shell-escape $1 >/dev/null
	$(CMP) --output-dir=$(PWD)/TMP --shell-escape $1 >/dev/null
endef

all:	sty $(NAME).pdf

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

$(NAME).pdf: $(NAME).dtx
	@ echo "Make the sample files first..."
	if [ ! -d $(PWD)/TMP ]; then mkdir $(PWD)/TMP; fi
	$(foreach file,$(texsamples), $(call dosamples, $(file)))
	mv TMP/*.pdf samples/
	mv $(texsamplesout)-tei.xml samples/
	@ echo "Build the documentation of $(NAME)..."
	$(CMP) --shell-escape -recorder -interaction=batchmode $(NAME).dtx >/dev/null
	biber $(NAME) >/dev/null
	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
	$(CMP) --shell-escape --recorder --interaction=nonstopmode $(NAME).dtx > /dev/null
	$(CMP) --shell-escape --recorder --interaction=nonstopmode $(NAME).dtx > /dev/null
	$(CMP) --shell-escape --recorder --interaction=nonstopmode $(NAME).dtx > /dev/null
	$(CMP) --shell-escape --recorder --interaction=nonstopmode $(NAME).dtx > /dev/null

samples: clean sty
	if [ ! -d $(PWD)/TMP ]; then mkdir $(PWD)/TMP; fi
	$(foreach file,$(texsamples), $(call dosamples, $(file)))
	mv TMP/*{\.pdf,-tei\.xml} samples/

clean:
	rm -rf auto
	rm -f $(NAME).bib $(PWD)/TMP/*.bib
	rm -rf .backup
	find -iname "*~" -or -iname "*.pdf" | xargs rm -rf
	find ./* -type f -iname "Makefile" $(findopts) > 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 -s README.md -o about.html

auctex:
	if [ ! -d "$(HOMEDIR)/.emacs.d/auctex/auto" ]; then \
	mkdir -p $(HOMEDIR)/.emacs.d/auctex/auto; \
	fi
	cp $(NAME)*.el $(HOMEDIR)/.emacs.d/auctex/auto

distclean: clean uninst

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

inst: uninst auctex all
	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 $(UTREE)/doc/lualatex/$(NAME)
	cp -r samples/ $(UTREE)/doc/lualatex/$(NAME)

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)

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

package: distclean all
	mkdir $(NAME)/
	cp Makefile README.md $(NAME).{ins,dtx,pdf} $(NAME)/
	cp -r samples/ $(NAME)/
	mkdir -p tex/lualatex/$(NAME)/
	cp *.lua *.sty tex/lualatex/$(NAME)/
	mkdir -p doc/lualatex/$(NAME)/
	cp 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)/

.PHONY: all clean distclean inst local uninst install uninstall zip package samples