-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·126 lines (110 loc) · 3.93 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
#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
DRAFT = draft-bjorklund-netmod-yang-tree-diagrams
MODELS =
#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 = ../yang
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 \
sed -e '/docName="/!d;s/.*docName="\([^"]*\)".*/\1/' $(DRAFT).xml | \
awk -F- '{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 "'`date +%F`'"/' < $<.prev > $<
@diff $<.prev $< || exit 0
@echo Generating $@
@PYTHONPATH=$(PYTHONPATH) pyang --ietf -f tree -p $(PLUGPATH) $< > $@ || exit 0
%.txt: %.xml
rm -f [email protected]
if [ -f $@ ]; then cp -pf $@ [email protected]; fi
xml2rfc $<
if [ -f [email protected] ]; then diff [email protected] $@; fi || exit 0
%.html: %.xml
@if [ $(WITHXML2RFC) == 0 ] ; then \
rm -f [email protected]; cp -pf $@ [email protected] ; \
xml2rfc --html $< ; \
fi
all: $(TREES) $(DRAFT).txt $(DRAFT).html
clean:
rm -f *.txt *.html *.prev *.tree
vars:
@echo PYTHONPATH=$(PYTHONPATH)
@echo PLUGPATH=$(PLUGPATH)
@echo PREV_REV=$(PREV_REV)
@echo REV=$(REV)
@echo OLD=$(OLD)
$(DRAFT).xml: $(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` ; \
start_stop=(`awk 'BEGIN{pout=1} \
/^<CODE BEGINS> file .'$${base}'/ \
{pout=0; print NR-1;} \
pout == 0 && /^<CODE E/ \
{pout=1; print NR;} \
END{print "0 0"}' [email protected]`) ; \
echo start_stop=$${start_stop[0]},$${start_stop[1]} ; \
if [ $${start_stop[0]} -gt 0 ] ; then \
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
@if [ -f [email protected] ]; then diff -bw [email protected] $@; fi || 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
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