-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
120 lines (89 loc) · 3.05 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
#!make
SHELL := /bin/bash
# Ensure the xml2rfc cache directory exists locally
IGNORE := $(shell mkdir -p $(HOME)/.cache/xml2rfc)
# Detect number of cores (e.g. for bundle install)
ifeq ($(OS),Windows_NT)
CORES := $(shell nproc --all)
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CORES := $(shell grep -c '^$$' /proc/cpuinfo)
endif
ifeq ($(UNAME_S),Darwin)
CORES := $(shell sysctl -n hw.ncpu)
endif
ifeq ($(UNAME_S),FreeBSD)
CORES := $(shell sysctl -n hw.ncpu)
endif
endif
SRC := $(filter-out README.adoc, $(wildcard sources/*.adoc))
OTHER_ADOC_SRC := $(wildcard sources/sections*/*.adoc)
CSV_SRC := $(wildcard sources/data/*.csv)
DERIVED_YAML := $(patsubst %.csv,%.yaml,$(CSV_SRC))
LUTAML_SRC := $(wildcard sources/models/*.lutaml)
DERIVED_PNG := $(patsubst sources/models/%.lutaml,sources/images/%.png,$(LUTAML_SRC))
DERIVED_SVG := $(patsubst sources/models/%.lutaml,sources/images/%.svg,$(LUTAML_SRC))
DERIVED_SRC := $(DERIVED_YAML) $(DERIVED_PNG) $(DERIVED_SVG)
SUPPLEMENTARY_SRC := $(OTHER_ADOC_SRC) $(DERIVED_SRC)
RELATON_CACHE_DIR := relaton
RELATON_CACHE := $(wildcard $(RELATON_CACHE_DIR)/*/*/*.xml)
RELATON_CACHE_dynamic ?=
OUT_DIR := site
ULTIMATE_TARGET := $(OUT_DIR)/index.html
define print_vars
$(info "DERIVED_YAML $(DERIVED_YAML)")
$(info "src $(SRC)")
$(info "formats $(FORMATS)")
$(info "RELATON_CACHE_dynamic $(RELATON_CACHE_dynamic)")
endef
.PHONY: all
all: build
.PHONY: prep
prep:
bundle install
.PHONY: debug
debug:
$(call print_vars)
sources/images/%.png: sources/models/%.lutaml
bundle exec lutaml -t png -o $@ $<
sources/images/%.svg: sources/models/%.lutaml
bundle exec lutaml -t svg -o $@ $<
%.yaml: %.csv
bundle exec structured_csv_to_yaml $^
@sed -i.bkup -e $$'1 i\\\n# This is a generated file. Do not edit it!' $@
@sed -i.bkup -e $$'2 i\\\n# Edit the corresponding csv file \($^\) instead.' $@
@sed -i.bkup -e $$'3 i\\\n# This file is generated by https://github.com/riboseinc/csv2yaml' $@
@sed -i.bkup -e $$'4 i\\\n# Please check in this file.' $@
.PHONY: patch
patch: patch-relaton-cache
relaton_timestamp := 2021-07-29
relaton_cache_to_patch := relaton/cache/iso/iso_639_all_parts.xml
.PHONY: patch-relaton-cache
patch-relaton-cache:
@if ! grep -q $(relaton_timestamp) $(relaton_cache_to_patch); then \
sed -i '' -e 's/fetched>....-..-..</fetched>$(relaton_timestamp)</' \
$(relaton_cache_to_patch); \
{ patch -N -t -r - -p0 < ./patches/relaton.patch && sleep 1 && touch $(relaton_cache_to_patch) ; } || : ; \
fi
$(ULTIMATE_TARGET): $(if $(RELATON_CACHE_dynamic),$(RELATON_CACHE),) metanorma.yml $(SRC) $(SUPPLEMENTARY_SRC)
bundle exec metanorma site generate --agree-to-terms . -c metanorma.yml
.PHONY: build
build: $(ULTIMATE_TARGET) patch debug
make RELATON_CACHE_dynamic="1" $(ULTIMATE_TARGET)
.PHONY: open
open: open-html
.PHONY: clean-all
clean-all: clean clean-cache
.PHONY: clean-cache
clean-cache:
rm -rf $(RELATON_CACHE_DIR)
.PHONY: clean
clean:
rm -rf $(OUT_DIR) $(DERIVED_SRC)
.PHONY: version
version:
bundle exec metanorma --version
.PHONY: test
test:
scripts/run_tests