-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
74 lines (60 loc) · 2.34 KB
/
Makefile
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
tex_content = tex4ebook $(wildcard *.sty) $(wildcard *.4ht) $(wildcard *.tex) tex4ebook-tidyconf.conf
lua_content = $(wildcard *.lua)
doc_file = tex4ebook-doc.pdf
TEXMFHOME = $(shell kpsewhich -var-value=TEXMFHOME)
INSTALL_DIR = $(TEXMFHOME)/tex/latex/tex4ebook
LUA_DIR = $(TEXMFHOME)/scripts/lua/tex4ebook
MANUAL_DIR = $(TEXMFHOME)/doc/latex/tex4ebook
BIN_DIR = /usr/local/bin
# expand the bin directory
SYSTEM_DIR = $(realpath $(BIN_DIR))
EXECUTABLE = $(SYSTEM_DIR)/tex4ebook
BUILD_DIR = build
BUILD_TEX4EBOOK = $(BUILD_DIR)/tex4ebook/
VERSION:= undefined
DATE:= undefined
ifeq ($(strip $(shell git rev-parse --is-inside-work-tree 2>/dev/null)),true)
VERSION:= $(shell git --no-pager describe --abbrev=0 --tags --always )
DATE:= $(firstword $(shell git --no-pager show --date=short --format="%ad" --name-only))
endif
# use sudo for install to a destination directory outside of $HOME
ifeq ($(findstring home,$(SYSTEM_DIR)),home)
SUDO:=
else
SUDO:=sudo
endif
ifeq ("$(wildcard $(EXECUTABLE))","")
INSTALL_COMMAND:=$(SUDO) ln -s $(INSTALL_DIR)/tex4ebook $(EXECUTABLE)
else
INSTALL_COMMAND:=
endif
all: doc
.PHONY: tags
tags:
ifeq ($(strip $(shell git rev-parse --is-inside-work-tree 2>/dev/null)),true)
git fetch --tags
endif
doc: $(doc_file) readme.tex
tex4ebook-doc.pdf: tex4ebook-doc.tex readme.tex changelog.tex tags
latexmk -pdf -pdflatex='lualatex "\def\version{${VERSION}}\def\gitdate{${DATE}}\input{%S}"' tex4ebook-doc.tex
readme.tex: README.md
pandoc -f markdown+definition_lists+inline_notes+autolink_bare_uris -t LaTeX README.md > readme.tex
changelog.tex: CHANGELOG.md
pandoc -f markdown+definition_lists -t LaTeX CHANGELOG.md > changelog.tex
build: doc $(tex_content) $(lua_content)
@rm -rf build
@mkdir -p $(BUILD_TEX4EBOOK)
@cp $(tex_content) $(lua_content) tex4ebook-doc.pdf $(BUILD_TEX4EBOOK)
@cat tex4ebook | sed -e "s/{{version}}/${VERSION}/" > $(BUILD_TEX4EBOOK)tex4ebook
@cat tex4ebook.sty | sed -e "s/{{version}}/${VERSION}/" | sed -e "s/{{date}}/${DATE}/" > $(BUILD_TEX4EBOOK)tex4ebook.sty
@cp README.md $(BUILD_TEX4EBOOK)README
cd $(BUILD_DIR) && zip -r tex4ebook.zip tex4ebook
install: doc $(tex_content) $(lua_content)
mkdir -p $(INSTALL_DIR)
mkdir -p $(MANUAL_DIR)
mkdir -p $(LUA_DIR)
cp $(tex_content) $(INSTALL_DIR)
cp $(lua_content) $(LUA_DIR)
cp $(doc_file) $(MANUAL_DIR)
chmod +x $(INSTALL_DIR)/tex4ebook
$(INSTALL_COMMAND)