aboutsummaryrefslogtreecommitdiffstats
path: root/examples/sample.makefile.regen
blob: daac595d6e78a885dc14b0d5cdff380681899e62 (plain)
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
#!/bin/sh
#
# This script attempts to compile the given ASN.1 specification and then
# transforms the resulting Makefile.am.sample tailored to that specification
# into a customized Makefile.
#
# The information which is necessary for this script is passed from the
# Makefile which is going to be replaced with an updated Makefile.
# This is called "boot-strapping" and is frequently the source of inside jokes.
#
# $Id$
#

if test -z "$ASN1PDU"	\
 -o  -z "$ASN1MODULES"	\
 -o  -z "$PROGNAME"	\
; then
	echo "ASN1CMDOPTS=\"$ASN1CMDOPTS\""
	echo "ASN1MODULES=\"$ASN1MODULES\""
	echo "ASN1PDU=\"$ASN1PDU\""
	echo "PROGNAME=\"$PROGNAME\""
	echo "ASN1PDU, ASN1MODULES, and PROGNAME are mandatory"
	exit
fi

../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?

if test ! -f Makefile.am.sample ; then
	echo "Makefile.am.sample is missing"
	exit 1
fi

ASN1DEFPDU=`echo "$ASN1PDU" | tr - _`
CFLAGS="-DPDU=${ASN1DEFPDU}"
if test -f config.h ; then
	CFLAGS="-DHAVE_CONFIG_H $CFLAGS"
fi

set -x
cat Makefile.am.sample						\
	| sed -e "s/^CFLAGS += /CFLAGS += ${CFLAGS} /"		\
	| sed -e "s/^all: /all: ${ASN1PDU}.c /"			\
	| sed -e "s/progname/${PROGNAME}/"			\
	> Makefile.$$

(	echo
	echo "${ASN1PDU}.c: $0 ${ASN1MODULES}"
	echo "	make regen-makefile"
	echo "	@touch ${ASN1PDU}.c"
	echo "	make"
	echo
	echo "regen-makefile:"
	echo "	ASN1CMDOPTS=\"${ASN1CMDOPTS}\" \\"
	echo "	ASN1MODULES=\"${ASN1MODULES}\" \\"
	echo "	ASN1PDU=${ASN1PDU} \\"
	echo "	PROGNAME=${PROGNAME} \\"
	echo "	$0"
	echo
	echo 'check: ${TARGET}'
	echo "	@if test -f sample-${ASN1PDU}-1.[db]er ; then \\"
	echo "	for f in sample-${ASN1PDU}-*.[db]er; do \\"
	echo '	for b in 1 17 33 980 8192; do \'
	echo '	echo "Recoding $$f into XER and back ($$b)..."; \'
	echo '	./${TARGET} -b $$b -iber -oxer $$f > ./.tmp.1.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -ixer -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
	echo '	diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
	echo '	rm -f ./.tmp.[12].$$$$; \'
	echo '	done; done; fi'
	echo "	@if test -f sample-${ASN1PDU}-1.xer ; then \\"
	echo "	for f in sample-${ASN1PDU}-*.xer; do \\"
	echo '	for b in 1 17 33 980 8192; do \'
	echo '	echo "Recoding $$f into DER and back ($$b)..."; \'
	echo '	./${TARGET} -b $$b -ixer -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
	echo '	diff $$f ./.tmp.2.$$$$ || exit 2; \'
	echo '	rm -f ./.tmp.[12].$$$$; \'
	echo '	done; done; fi'
	echo "	@if test -f sample-${ASN1PDU}-1.per ; then \\"
	echo "	for f in sample-${ASN1PDU}-[1-9].per; do \\"
	echo '	for b in 1 17 33 980 8192; do \'
	echo '	echo "Recoding $$f into DER into XER and back ($$b)..."; \'
	echo '	./${TARGET} -b $$b -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -ixer -oder ./.tmp.2.$$$$ > ./.tmp.3.$$$$ || exit 2; \'
	echo '	diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \'
	echo '	rm -f ./.tmp.[123].$$$$; \'
	echo '	done; done; fi'
	echo "	@if test -f sample-${ASN1PDU}-1-padded.per ; then \\"
	echo "	for f in sample-*-[1-9]-padded.per; do \\"
	echo '	pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \'
	echo '	for b in 1 17 33 980 8192; do \'
	echo '	echo "Recoding byte-padded $$f into DER into XER and back ($$b)..."; \'
	echo '	./${TARGET} -b $$b -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
	echo '	./${TARGET} -b $$b -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
	echo '	diff $$f ./.tmp.1.$$$$ || exit 2; \'
	echo '	rm -f ./.tmp.[12].$$$$; \'
	echo '	done; done; fi'
	echo '	@echo ================'
	echo '	@echo All tests passed'
	echo '	@echo ================'
	echo
	echo "distclean: clean"
	echo '	rm -f $(ASN_MODULE_SOURCES)'
	echo '	rm -f $(ASN_MODULE_HEADERS)'
	echo '	rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
	echo "	rm -f Makefile.am.sample"
) >> Makefile.$$

rm Makefile.am.sample || exit $?

mv Makefile.$$ Makefile

set +x
echo
echo "Makefile generation finished"