-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
130 lines (105 loc) · 3.44 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
# In case your system doesn't have any of these tools:
# https://pypi.python.org/pypi/xml2rfc
# https://github.com/cabo/kramdown-rfc2629
# https://github.com/Juniper/libslax/tree/master/doc/oxtradoc
# https://tools.ietf.org/tools/idnits/
xml2rfc ?= xml2rfc
kramdown-rfc2629 ?= kramdown-rfc2629
oxtradoc ?= oxtradoc
idnits ?= idnits
draft := $(basename $(lastword $(sort $(wildcard draft-*.xml)) $(sort $(wildcard draft-*.md)) $(sort $(wildcard draft-*.org)) ))
ifeq (,$(draft))
$(warning No file named draft-*.md or draft-*.xml or draft-*.org)
$(error Read README.md for setup instructions)
endif
draft_type := $(suffix $(firstword $(wildcard $(draft).md $(draft).org $(draft).xml) ))
current_ver := $(shell git tag | grep '$(draft)-[0-9][0-9]' | tail -1 | sed -e"s/.*-//")
ifeq "${current_ver}" ""
next_ver ?= 00
else
next_ver ?= $(shell printf "%.2d" $$((1$(current_ver)-99)))
endif
next := $(draft)-$(next_ver)
.PHONY: latest submit clean
#latest: $(draft).txt $(draft).html
default: $(next).xml $(next).txt $(next).html
idnits: $(next).txt
$(idnits) $<
clean:
-rm -f $(draft)-[0-9][0-9].xml
-rm -f $(draft)-[0-9][0-9].v2v3.xml
-rm -f $(draft)-[0-9][0-9].txt
-rm -f $(draft)-[0-9][0-9].html
-rm -f metadata.min.js
ifeq (md,$(draft_type))
-rm -f $(draft).xml
endif
ifeq (org,$(draft_type))
-rm -f $(draft).xml
endif
$(next).xml: $(draft).xml
sed -e"s/$(basename $<)-latest/$(basename $@)/" -e"s/YYYY-MM-DD/$(shell date +%Y-%m-%d)/" $< > $@
#sed -e"s/YYYY-MM-DD/$(shell date +%Y-%m-%d)/" ietf-restconf-list-pagination.yang > ietf-restconf-list-pagination\@$(shell date +%Y-%m-%d).yang
#sed -e"s/YYYY-MM-DD/$(shell date +%Y-%m-%d)/" includes/example-module.yang > includes/example-module\@$(shell date +%Y-%m-%d).yang
cd includes && ./validate-all.sh && ./gen-trees.sh && cd ..
./.insert-figures.sh $@ > tmp && mv tmp $@
@rm -f refs/*-tree*.txt
xml2rfc --v2v3 $@
.INTERMEDIATE: $(draft).xml
%.xml: %.md
$(kramdown-rfc2629) $< > $@
%.xml: %.org
$(oxtradoc) -m outline-to-xml -n "$@" $< > $@
%.txt: %.xml
$(xml2rfc) --v3 $< -o $@ --text
@if [[ "$next_ver" -ne "00" ]]; then idnits $@; fi
ifeq "$(shell uname -s 2>/dev/null)" "Darwin"
sed_i := sed -i ''
else
sed_i := sed -i
endif
%.html: %.xml
$(xml2rfc) --v3 $< -o $@ --html
### Below this deals with updating gh-pages
GHPAGES_TMP := /tmp/ghpages$(shell echo $$$$)
.TRANSIENT: $(GHPAGES_TMP)
ifeq (,$(TRAVIS_COMMIT))
GIT_ORIG := $(shell git branch | grep '*' | cut -c 3-)
else
GIT_ORIG := $(TRAVIS_COMMIT)
endif
# Only run upload if we are local or on the master branch
IS_LOCAL := $(if $(TRAVIS),,true)
ifeq (master,$(TRAVIS_BRANCH))
IS_MASTER := $(findstring false,$(TRAVIS_PULL_REQUEST))
else
IS_MASTER :=
endif
index.html: $(draft).html
cp $< $@
ghpages: index.html $(draft).txt
ifneq (,$(or $(IS_LOCAL),$(IS_MASTER)))
mkdir $(GHPAGES_TMP)
cp -f $^ $(GHPAGES_TMP)
git clean -qfdX
ifeq (true,$(TRAVIS))
git config user.email "[email protected]"
git config user.name "Travis CI Bot"
git checkout -q --orphan gh-pages
git rm -qr --cached .
git clean -qfd
git pull -qf origin gh-pages --depth=5
else
git checkout gh-pages
git pull
endif
mv -f $(GHPAGES_TMP)/* $(CURDIR)
git add $^
if test `git status -s | wc -l` -gt 0; then git commit -m "Script updating gh-pages."; fi
ifneq (,$(GH_TOKEN))
@echo git push https://github.com/$(TRAVIS_REPO_SLUG).git gh-pages
@git push https://$(GH_TOKEN)@github.com/$(TRAVIS_REPO_SLUG).git gh-pages
endif
-git checkout -qf "$(GIT_ORIG)"
-rm -rf $(GHPAGES_TMP)
endif