forked from louberger/dlep-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
194 lines (169 loc) · 6.47 KB
/
Makefile.common
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
#Crazy makefile authored by Lou Berger <[email protected]>
#Modified by Christian Hopps <[email protected]>
#The author makes no claim/restriction on use. It is provided "AS IS".
#This file is considered a hack and not production grade by the author
#Assumes the basename of draft xml file, e.g., <basename>.xml is set as
#DRAFT
SHELL = bash
#YANG related variables
MODELS := $(shell awk '/^<CODE BEGINS>/{print gensub(/"/,"","g",gensub(/@.*/,".yang",1,$$4))}' $(DRAFT).xml)
TREES := $(MODELS:.yang=.tree)
#assumes standard yang modules installed in ~/.yang, ../yang or ../../yang, customize as needed
# e.g., based on a 'cd .. ; git clone https://github.com/YangModels/yang.git'
YANG_REPO = https://github.com/YangModels/yang.git
YANG_DEFAULT_DIR = ~/.yang
YANGIMPORT_BASE := $(shell if [ -e ../yang ] ; then echo ../yang/ ; else if [ -e ../../yang/ ] ; then echo ../../yang/ ; else if [ -e $(YANG_DEFAULT_DIR) ] ; then echo $(YANG_DEFAULT_DIR)/; else echo YANG_IMPORT_NOT_FOUND ; fi ; fi ; fi)
PLUGPATH = $(shell echo `find . $(YANGIMPORT_BASE) -name '[a-z]*.yang' | sed 's,/[a-z0-9A-Z@_\-]*.yang$$,,' | uniq | grep -v vendor` | tr \ :)
PYTHONPATH := $(shell echo `find /usr/lib* /usr/local/lib* -name site-packages | tail -1 ` | tr \ :)
DATE := $(shell date +%F)
#I-D related
WITHXML2RFC := $(shell which xml2rfc > /dev/null 2>&1 ; echo $$? )
ID_DIR = IDs
REVS := $(shell grep docName $(DRAFT).xml | sed 's/.*docName="//'| sed 's/".*//' | awk -F- '{v=$$NF; printf "%02d %02d %02d",v-1,v,v+1}')
PREV_REV := $(word 1, $(REVS))
REV := $(word 2, $(REVS))
NEXT_REV := $(word 3, $(REVS))
OLD = $(ID_DIR)/$(DRAFT)-$(PREV_REV)
NEW = $(ID_DIR)/$(DRAFT)-$(REV)
%.tree: %.yang
@if grep -q '^ *revision *$(DATE)' $< ; then \
echo $< revision is up to date ; \
else \
echo Updating $< revision date ; \
rm -f $<.prev; cp -pf $< $<.prev ; \
sed 's/revision.\(\|\"\)[0-9]*\-[0-9]*\-[0-9]*\(\|\"\)/revision \1'$(DATE)'\2/' < $<.prev > $< ; \
diff $<.prev $< || exit 0 ; \
fi
@echo Generating $@
@PYTHONPATH=$(PYTHONPATH) pyang --ietf -f tree --tree-line-length 76 -p $(PLUGPATH) $< > $@ || exit 0
%.jsonxsl: %.yang
@echo Generating $@
@PYTHONPATH=$(PYTHONPATH) pyang -f jsonxsl -p $(PLUGPATH) $< > $@ || exit 0
%.txt: %.xml
@if [ $(WITHXML2RFC) == 0 ] ; then \
if [ -e $@ ]; then rm -f [email protected]; cp -pf $@ [email protected] > /dev/null 2>&1 ; fi ;\
xml2rfc --legacy $< -o $@ ; \
if [ -f [email protected] ] ; then diff [email protected] $@ || exit 0 ; fi ; \
fi
%.html: %.xml
@if [ $(WITHXML2RFC) == 0 ] ; then \
if [ -e $@ ]; then rm -f [email protected]; cp -pf $@ [email protected] > /dev/null 2>&1 ; fi ;\
xml2rfc --legacy --html $< -o $@ ; \
fi
all: $(YANGIMPORT_BASE) $(TREES) xml2rfc $(DRAFT).txt $(DRAFT).html
$(YANGIMPORT_BASE):
@if [ "$(MODELS)" != "" ] ; then \
echo "Unable to find Standard YANG modules."; \
echo "To fix and create $(YANG_DEFAULT_DIR), type 'make yangbase'"; \
exit 1 ; \
fi
checkyang: $(YANGIMPORT_BASE)
@if [ "$(MODELS)" != "" ] ; then \
for f in $(MODELS); do \
echo "Checking $$f" ; \
PYTHONPATH=$(PYTHONPATH) pyang --verbose -p $(PLUGPATH) $$f ; \
done ; \
fi
yangbase:
@if [ "$(YANGIMPORT_BASE)" == "YANG_IMPORT_NOT_FOUND" ] ; then \
echo "Creating $(YANG_DEFAULT_DIR) from $(YANG_REPO)" ; \
git clone $(YANG_REPO) $(YANG_DEFAULT_DIR) ; \
echo "Modules can be updated via 'make yangbase' in the future." ; \
else \
(cd $(YANGIMPORT_BASE) ; git pull) ; \
fi
trees: $(TREES)
vars: $(YANGIMPORT_BASE)
@echo PYTHONPATH=$(PYTHONPATH)
@echo PLUGPATH=$(PLUGPATH)
@echo YANGIMPORT_BASE=$(YANGIMPORT_BASE)
@echo MODELS=$(MODELS)
@echo TREES=$(TREES)
@echo DATE=$(DATE)
@echo DRAFT=$(DRAFT)
@which xml2rfc
@echo WITHXML2RFC=$(WITHXML2RFC)
@echo PREV_REV=$(PREV_REV)
@echo REV=$(REV)
@echo NEXT_REV=$(NEXT_REV)
@echo OLD=$(OLD)
@echo NEW=$(NEW)
xml2rfc:
@if [ $(WITHXML2RFC) != 0 ] ; then \
echo "$@ not found, please run 'pip install $@'" ; \
exit 1 ; \
fi
$(DRAFT).xml: $(YANGIMPORT_BASE) $(MODELS)
@rm -f [email protected]; cp -p $@ [email protected]
@for model in $? ; do if [ "$$model" != "$(YANGIMPORT_BASE)" ] ; then \
rm -f [email protected]; cp -p $@ [email protected] ; \
echo Updating $@ based on $$model ; \
base=`echo $$model | cut -d. -f 1` ; \
echo $${base};\
start_stop=(`awk 'BEGIN{pout=1} \
/^<CODE BEGINS> file .'$${base}'@/ \
{pout=0; print NR-1;} \
pout == 0 && /^<CODE E/ \
{pout=1; print NR;}' [email protected]`) ; \
head -$${start_stop[0]} [email protected] > $@ ; \
echo '<CODE BEGINS> file "'$${base}'@'`date +%F`'.yang"'>> $@;\
cat $$model >> $@ ; \
tail -n +$${start_stop[1]} [email protected] >> $@ ; \
rm -f [email protected] ; \
fi ; done
diff -bw [email protected] $@ || exit 0
$(DRAFT)-diff.txt: $(DRAFT).txt
@echo "Generating diff of $(OLD).txt and $(DRAFT).txt > $@..."
if [ -f $(OLD).txt ] ; then \
sdiff --ignore-space-change --expand-tabs -w 168 $(OLD).txt $(DRAFT).txt | \
cut -c84-170 | sed 's/. *//' \
| grep -v '^ <$$' | grep -v '^<$$' > $@ ;\
fi
idnits: $(DRAFT).txt
@if [ ! -f idnits ] ; then \
rm -f $@ ;\
wget https://raw.githubusercontent.com/ietf-tools/idnits/main/idnits ;\
chmod 755 idnits ;\
fi
./idnits $(DRAFT).txt > [email protected]
@cat [email protected]
@grep -q 'Summary: 0 error' [email protected]
id: $(DRAFT).txt $(DRAFT).html
@if [ ! -e $(ID_DIR) ] ; then \
echo "Creating $(ID_DIR) directory" ;\
mkdir $(ID_DIR) ;\
git add $(ID_DIR) ;\
fi
@if [ -f "$(NEW).xml" ] ; then \
echo "" ;\
echo "$(NEW).xml already exists, not overwriting!" ;\
diff -sq $(DRAFT).xml $(NEW).xml ;\
echo "" ;\
else \
echo "Copying to $(NEW).{xml,txt,html}" ;\
echo "" ;\
cp -p $(DRAFT).xml $(NEW).xml ;\
cp -p $(DRAFT).txt $(NEW).txt ;\
cp -p $(DRAFT).html $(NEW).html ;\
git add $(NEW).xml $(NEW).txt $(NEW).html ;\
git commit -m "$(DRAFT): Adding ID rev $(REV)" $(NEW).xml $(NEW).txt $(NEW).html ;\
ls -lt $(DRAFT).* $(NEW).* ;\
echo "Bumping rev $(REV)->$(NEXT_REV)" ;\
sed -i 's/$(DRAFT)-$(REV)/$(DRAFT)-$(NEXT_REV)/' $(DRAFT).xml ;\
git diff $(DRAFT).xml ;\
git commit -m "$(DRAFT): Bumping rev $(REV)->$(NEXT_REV)" $(DRAFT).xml ;\
git log --stat HEAD~2... ;\
fi
rmid:
@echo "Reverting last 2 changes:"
@git log --stat HEAD~2...
@ls -l $(OLD).xml $(OLD).txt $(OLD).html
@echo -n "Hit <ctrl>-C to abort, or <CR> to continue: "
@read t
@git reset HEAD~2
@git checkout $(DRAFT).xml
@rm -f $(OLD).xml $(OLD).txt $(OLD).html
@echo "Restored $(DRAFT).xml"
twt:
sed 's/\(docName=.*\)'$(REV)'/\1'$(NEXT_REV)'/' < $(NEW).xml > $(DRAFT).xml
git diff $(DRAFT).xml