-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
executable file
·149 lines (130 loc) · 4.82 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
#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
MODELS := $(shell awk '/^<CODE BEGINS>/{print gensub(/\"/,"","g",gensub(/@.*/,".yang",1,$$4))}' $(DRAFT).xml)
#assumes standard yang modules installed in ../yang, customize as needed
# e.g., based on a 'cd .. ; git clone https://github.com/YangModels/yang.git'
YANGIMPORT_BASE := $(shell if [ -e ../yang ] ; then echo ../yang ; else if [ -e ../../yang ] ; then echo ../../yang ; else echo YANG_IMPORT_NOT_FOUND ; fi ; fi)
PLUGPATH := $(shell echo `find . $(YANGIMPORT_BASE) -name \*.yang | sed 's,/[a-z0-9A-Z@_\-]*.yang$$,,' | uniq` | tr \ :)
PYTHONPATH := $(shell echo `find /usr/lib* /usr/local/lib* -name site-packages ` | tr \ :)
WITHXML2RFC := $(shell which xml2rfc > /dev/null 2>&1 ; echo $$? )
ID_DIR = IDs
REVS := $(shell grep docName $(DRAFT).xml | tr '"\->' ' ' | \
awk '{printf "%02d %02d",$$NF-1,$$NF}')
PREV_REV := $(word 1, $(REVS))
REV := $(word 2, $(REVS))
OLD = $(ID_DIR)/$(DRAFT)-$(PREV_REV)
NEW = $(ID_DIR)/$(DRAFT)-$(REV)
TREES := $(MODELS:.yang=.tree)
%.tree: %.yang
@echo Updating $< revision date
@rm -f $<.prev; cp -pf $< $<.prev
@sed 's/revision.\(\|\"\)[0-9]*\-[0-9]*\-[0-9]*\(\|\"\)/revision \1'`date +%F`'\2/' < $<.prev > $<
@diff $<.prev $< || exit 0
@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 \
rm -f [email protected]; cp -pf $@ [email protected] > /dev/null 2>&1 ; \
xml2rfc $< -o $@ ; \
if [ -f [email protected] ] ; then diff [email protected] $@ || exit 0 ; fi ; \
fi
%.html: %.xml
@if [ $(WITHXML2RFC) == 0 ] ; then \
rm -f [email protected]; cp -pf $@ [email protected] > /dev/null 2>&1 ; \
xml2rfc --html $< -o $@ ; \
fi
%.raw: %.xml
@if [ $(WITHXML2RFC) == 0 ] ; then \
rm -f [email protected]; cp -pf $@ [email protected] > /dev/null 2>&1 ; \
xml2rfc --raw $< -o $@ ; \
fi
all: $(YANGIMPORT_BASE) $(TREES) $(DRAFT).txt $(DRAFT).html $(DRAFT).raw
$(YANGIMPORT_BASE):
@if [ "$(MODELS)" != "" ] ; then \
echo "Unable to find Standard YANG modules in parent dirs"; \
echo "to fix type:"; \
echo " (cd .. ; git clone https://github.com/YangModels/yang.git)"; \
exit 1 ; \
fi
vars:
which xml2rfc
@echo WITHXML2RFC=$(WITHXML2RFC)
@echo PYTHONPATH=$(PYTHONPATH)
@echo PLUGPATH=$(PLUGPATH)
@echo YANGIMPORT_BASE=$(YANGIMPORT_BASE)
@echo MODELS=$(MODELS)
@echo TREES=$(TREES)
@echo PREV_REV=$(PREV_REV)
@echo REV=$(REV)
@echo OLD=$(OLD)
$(DRAFT).xml: $(YANGIMPORT_BASE) $(MODELS)
@rm -f [email protected]; cp -p $@ [email protected]
@for model in $? ; do \
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] ; \
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 http://tools.ietf.org/tools/idnits/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 ;\
ls -lt $(DRAFT).* $(NEW).* ;\
fi
rmid:
@echo "Removing:"
@ls -l $(NEW).xml $(NEW).txt $(NEW).html
@echo -n "Hit <ctrl>-C to abort, or <CR> to continue: "
@read t
@rm -f $(NEW).xml $(NEW).txt $(NEW).html
@git rm $(NEW).xml $(NEW).txt $(NEW).html
trees: $(TREES)