-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
177 lines (134 loc) · 4.09 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Auto-generated by Cimas: Do not edit it manually!
# See https://github.com/metanorma/cimas
#!make
SHELL := /bin/bash
# Ensure the xml2rfc cache directory exists locally
IGNORE := $(shell mkdir -p $(HOME)/.cache/xml2rfc)
SRC := $(shell yq r metanorma.yml metanorma.source.files | cut -c 3-)
ifeq ($(SRC),null)
SRC :=
endif
ifeq ($(SRC),ll)
SRC :=
endif
ifeq ($(SRC),)
BUILT := $(shell yq r metanorma.yml metanorma.source.built_targets | cut -d ':' -f 1 | tr -s '\n' ' ')
ifeq ($(BUILT),null)
SRC :=
endif
ifeq ($(BUILT),ll)
SRC :=
endif
ifeq ($(BUILT),)
SRC := $(filter-out README.adoc, $(wildcard sources/*.adoc))
else
XML := $(patsubst sources/%,documents/%,$(BUILT))
endif
endif
FORMATS := $(shell yq r metanorma.yml metanorma.formats | tr -d '[:space:]' | tr -s '-' ' ')
ifeq ($(FORMATS),)
FORMAT_MARKER := mn-output-
FORMATS := $(shell grep "$(FORMAT_MARKER)" $(SRC) | cut -f 2 -d " " | tr "," "\\n" | sort | uniq | tr "\\n" " ")
endif
XML ?= $(patsubst sources/%,documents/%,$(patsubst %.adoc,%.xml,$(SRC)))
HTML := $(patsubst %.xml,%.html,$(XML))
ifdef METANORMA_DOCKER
PREFIX_CMD := echo "Running via docker..."; docker run -v "$$(pwd)":/metanorma/ $(METANORMA_DOCKER)
else
PREFIX_CMD := echo "Running locally..."; bundle exec
endif
_OUT_FILES := $(foreach FORMAT,$(FORMATS),$(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]'))
OUT_FILES := $(foreach F,$(_OUT_FILES),$($F))
define print_vars
$(info "src $(SRC)")
$(info "xml $(XML)")
$(info "formats $(FORMATS)")
endef
all: documents.html
$(call print_vars)
documents:
mkdir -p $@
documents/%.html: documents/%.xml | documents
${PREFIX_CMD} metanorma $<
documents/%.xml: sources/%.xml | documents
mkdir -p $(dir $@)
mv $< $@
# Build canonical XML output
# If XML file is provided, copy it over
# Otherwise, build the xml using adoc
sources/%.xml: | bundle
BUILT_TARGET="$(shell yq r metanorma.yml metanorma.source.built_targets[$@])"; \
if [ "$$BUILT_TARGET" = "" ] || [ "$$BUILT_TARGET" = "null" ]; then \
BUILT_TARGET=$@; \
$(PREFIX_CMD) metanorma -x xml "$${BUILT_TARGET//xml/adoc}"; \
else \
if [ -f "$$BUILT_TARGET" ] && [ "$${BUILT_TARGET##*.}" == "xml" ]; then \
cp "$$BUILT_TARGET" $@; \
else \
$(PREFIX_CMD) metanorma -x xml $$BUILT_TARGET; \
cp "$${BUILT_TARGET//adoc/xml}" $@; \
fi \
fi
documents.rxl: $(XML) $(HTML)
${PREFIX_CMD} relaton concatenate \
-t "$(shell yq r metanorma.yml relaton.collection.name)" \
-g "$(shell yq r metanorma.yml relaton.collection.organization)" \
documents $@
documents.html: documents.rxl
$(PREFIX_CMD) relaton xml2html documents.rxl
%.adoc:
define FORMAT_TASKS
OUT_FILES-$(FORMAT) := $($(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]'))
open-$(FORMAT):
open $$(OUT_FILES-$(FORMAT))
clean-$(FORMAT):
rm -f $$(OUT_FILES-$(FORMAT))
$(FORMAT): clean-$(FORMAT) $$(OUT_FILES-$(FORMAT))
.PHONY: clean-$(FORMAT)
endef
$(foreach FORMAT,$(FORMATS),$(eval $(FORMAT_TASKS)))
open: open-html
clean:
rm -rf documents documents.{html,rxl} published *_images $(OUT_FILES)
bundle:
ifndef METANORMA_DOCKER
bundle install --jobs 4 --retry 3
endif
$(call print_vars)
.PHONY: bundle all open clean
#
# Watch-related jobs
#
.PHONY: watch serve watch-serve
NODE_BINS := onchange live-serve run-p
NODE_BIN_DIR := node_modules/.bin
NODE_PACKAGE_PATHS := $(foreach PACKAGE_NAME,$(NODE_BINS),$(NODE_BIN_DIR)/$(PACKAGE_NAME))
$(NODE_PACKAGE_PATHS): package.json
npm i
watch: $(NODE_BIN_DIR)/onchange
make all
$< $(ALL_SRC) -- make all
define WATCH_TASKS
watch-$(FORMAT): $(NODE_BIN_DIR)/onchange
make $(FORMAT)
$$< $$(SRC_$(FORMAT)) -- make $(FORMAT)
.PHONY: watch-$(FORMAT)
endef
$(foreach FORMAT,$(FORMATS),$(eval $(WATCH_TASKS)))
serve: $(NODE_BIN_DIR)/live-server revealjs-css reveal.js
export PORT=$${PORT:-8123} ; \
port=$${PORT} ; \
for html in $(HTML); do \
$< --entry-file=$$html --port=$${port} --ignore="*.html,*.xml,Makefile,Gemfile.*,package.*.json" --wait=1000 & \
port=$$(( port++ )) ;\
done
watch-serve: $(NODE_BIN_DIR)/run-p
$< watch serve
#
# Deploy jobs
#
publish: published
published: documents.html
mkdir -p $@ && \
cp -a documents $@/ && \
cp $< $@/index.html;