-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
203 lines (161 loc) · 5.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# 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)
examples = $(wildcard ex*.yang) \
$(wildcard *ex*.json) \
$(wildcard *ex*.xml)
.PHONY: latest all clean
all: $(next).txt
latest: $(draft).txt $(draft).html
back.xml: back.src.xml
./mk-back $< > $@
ietf-yang-schema-mount.tree: ietf-yang-schema-mount.yang
pyang -f tree --tree-line-length 68 $< > $@
idnits: $(next).txt
$(idnits) $<
.PHONY: validate validate_ex1
validate:
pyang --ietf --max-line-length 69 ietf-yang-schema-mount.yang
pyang example-logical-devices.yang
pyang example-network-manager-fixed.yang
pyang example-network-manager-arbitrary.yang
$(MAKE) validate_ex1
$(MAKE) validate_yang_lib_ex1_device
$(MAKE) validate_yang_lib_ex1_lne
$(MAKE) validate_sm_ex1_lne
$(MAKE) validate_sm_ex1_device
validate_ex1: .ex1.xml
yang2dsdl -x -j -v $< ietf-yang-schema-mount.yang; \
.INTERMEDIATE: .ex1.xml
.ex1.xml: ex1.xml
echo "<data xmlns='urn:ietf:params:xml:ns:netconf:base:1.0'>" > $@; \
cat $< >> $@; \
echo "</data>" >> $@
OLD_YANG_LIBRARY=${PYANG_XSLT_DIR}/../modules/ietf/ietf-yang-library.yang
NEW_YANG_LIBRARY=../../netconf-wg/rfc7895bis/ietf-yang-library.yang
.INTERMEDIATE: old-ietf-yang-library.jtox new-ietf-yang-library.jtox
old-ietf-yang-library.jtox:
pyang -f jtox ${OLD_YANG_LIBRARY} > $@
new-ietf-yang-library.jtox:
pyang --max-status current -f jtox ${NEW_YANG_LIBRARY} > $@
.INTERMEDIATE: .yang-library-ex1-device.xml .yang-library-ex1-lne.xml
.yang-library-ex1-device.xml: .yang-library-ex1-device.json \
new-ietf-yang-library.jtox
json2xml new-ietf-yang-library.jtox $< > $@
.yang-library-ex1-lne.xml: .yang-library-ex1-lne.json \
old-ietf-yang-library.jtox
json2xml old-ietf-yang-library.jtox $< > $@
validate_yang_lib_ex1_device: .yang-library-ex1-device.xml
yang2dsdl -c -x -j -v $< ${NEW_YANG_LIBRARY}
validate_yang_lib_ex1_lne: .yang-library-ex1-lne.xml
yang2dsdl -x -j -v $< ${OLD_YANG_LIBRARY}
.INTERMEDIATE: ietf-yang-schema-mount.jtox
ietf-yang-schema-mount.jtox: ietf-yang-schema-mount.yang
pyang -f jtox $< > $@
.INTERMEDIATE: .schema-mounts-ex1-device.xml .schema-mounts-ex1-lne.xml
.schema-mounts-ex1-%.xml: .schema-mounts-ex1-%.json \
ietf-yang-schema-mount.jtox
json2xml ietf-yang-schema-mount.jtox $< > $@
validate_sm_ex1_lne: .schema-mounts-ex1-lne.xml
yang2dsdl -x -j -v $< ietf-yang-schema-mount.yang
validate_sm_ex1_device: .schema-mounts-ex1-device.xml
yang2dsdl -x -j -v $< ietf-yang-schema-mount.yang
.INTERMEDIATE: .%.json .%.json
.%.json: %.json
cat $< | awk -F\\ '/(.*)\\/ { printf "%s", $$1; next } { print $$0 }' >\
$@
clean: clean_ex
-rm -f ietf-yang-schema-mount.tree
-rm -f $(draft).txt $(draft).html index.html back.xml
-rm -f $(next).txt $(next).html
-rm -f $(draft)-[0-9][0-9].xml
ifeq (.md,$(draft_type))
-rm -f $(draft).xml
endif
ifeq (.org,$(draft_type))
-rm -f $(draft).xml
endif
clean_ex:
-rm -f *.rng *.dsrl *.sch
$(next).xml: ietf-yang-schema-mount.yang \
ietf-yang-schema-mount.tree \
back.xml $(examples)
$(next).xml: $(draft).xml
sed -e"s/$(basename $<)-latest/$(basename $@)/" $< > $@
.INTERMEDIATE: $(draft).xml
%.xml: %.md
$(kramdown-rfc2629) $< > $@
%.xml: %.org
$(oxtradoc) -m outline-to-xml -n "$(basename $<)-latest" $< > $@
%.txt: %.xml
$(xml2rfc) $< -o $@ --text
ifeq "$(shell uname -s 2>/dev/null)" "Darwin"
sed_i := sed -i ''
else
sed_i := sed -i
endif
%.html: %.xml
$(xml2rfc) $< -o $@ --html
$(sed_i) -f .addstyle.sed $@
### 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 "ci-bot@example.com"
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