-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (52 loc) · 2.32 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
# Makefile for XMPP XEP Dash Docset.
# Use this to build a new version of the docset based on the latest XEP state.
# Docset generation options.
NAME := XEPs
DESCRIPTION := Protocol Extensions for XMPP
REMOTE_URL := https://xmpp.org/extensions
# Build-time dependencies.
ENVSUBST = $(call find-cmd,envsubst)
SQLITE = $(call find-cmd,sqlite3)
TAR = $(call find-cmd,tar)
GIT = $(call find-cmd,git)
# Directory aliases.
ROOTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BUILDDIR := $(ROOTDIR)build/
CONTENTDIR := $(BUILDDIR)$(NAME).docset/Contents/
XEPDIR := $(ROOTDIR)xeps/
# Default Makefile options.
XEPS := $(patsubst $(XEPDIR)xep-%.xml,$(CONTENTDIR)Resources/Documents/xep-%.html,$(wildcard $(XEPDIR)xep-????.xml))
VERBOSE :=
## Build and archive docset.
build: $(BUILDDIR)$(NAME).tgz
## Update XEPs in submodule.
update:
$Q $(GIT) submodule update --remote --recursive
## Remove all temporary build files.
clean:
$Q rm -Rf $(BUILDDIR)
$(CONTENTDIR)Info.plist: template/Info.plist
$Q mkdir -p $(@D)
$Q $(ENVSUBST) < $< > $@
$(BUILDDIR)$(NAME).docset/icon.png: template/xmpp-logo.png
$Q mkdir -p $(@D)
$Q cp -f $< $@
$(CONTENTDIR)Resources/docSet.dsidx: template/docSet.dsidx
$Q mkdir -p $(@D)
$Q cp -f $< $@
$(CONTENTDIR)Resources/Documents/xep-%.html: $(XEPDIR)xep-%.xml | $(CONTENTDIR)Resources/docSet.dsidx
$Q mkdir -p $(@D)
$Q $(SQLITE) $(CONTENTDIR)Resources/docSet.dsidx "REPLACE INTO searchIndex(name, type, path) VALUES ('$(subst ','',$(call extract-title,$<))', 'Guide', 'xep-$*.html');"
$Q $(MAKE) -C $(XEPDIR) xep-$*.html OUTDIR=$(@D)
$(BUILDDIR)$(NAME).tgz: $(XEPS) $(CONTENTDIR)Info.plist
$Q $(TAR) --create --gzip --file $(BUILDDIR)$(NAME).tgz -C $(BUILDDIR) $(NAME).docset
.PHONY: build update clean
# Conditional command echo control.
Q := $(if $(VERBOSE),,@)
# Find and return full path to command by name, or throw error if none can be found in PATH.
# Example use: $(call find-cmd,ls)
find-cmd = $(or $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))),$(error "Command '$(1)' not found in PATH"))
# Extract XEP title from XML file.
extract-title = $(shell printf '%s: %s' "$(shell basename $(1) .xml | tr '[:lower:]' '[:upper:]')" "$(shell awk -F '[<>]' '/<title>/ {print $$3; exit}' $(1))")
# Exported variables for templated files.
export NAME DESCRIPTION REMOTE_URL