blob: 57a0daef07fe29b2f8c12d0bdb9d12ef72996a34 [file] [log] [blame]
Lev Walkin2fd86de2006-09-13 02:10:23 +00001#!/bin/sh
Lev Walkin43739162006-09-17 03:53:11 +00002#
3# This script attempts to compile the given ASN.1 specification and then
4# transforms the resulting Makefile.am.sample tailored to that specification
5# into a customized Makefile.
6#
7# The information which is necessary for this script is passed from the
8# Makefile which is going to be replaced with an updated Makefile.
9# This is called "boot-strapping" and is frequently the source of inside jokes.
10#
11# $Id$
12#
Lev Walkin2fd86de2006-09-13 02:10:23 +000013
Lev Walkinc51cdd42006-09-17 00:20:47 +000014if test -z "$ASN1PDU" \
Lev Walkin2fd86de2006-09-13 02:10:23 +000015 -o -z "$ASN1MODULES" \
16 -o -z "$PROGNAME" \
Lev Walkinc51cdd42006-09-17 00:20:47 +000017; then
Lev Walkin444e7392006-09-15 22:45:40 +000018 echo "ASN1CMDOPTS=\"$ASN1CMDOPTS\""
Lev Walkin2fd86de2006-09-13 02:10:23 +000019 echo "ASN1MODULES=\"$ASN1MODULES\""
Lev Walkin444e7392006-09-15 22:45:40 +000020 echo "ASN1PDU=\"$ASN1PDU\""
Lev Walkin2fd86de2006-09-13 02:10:23 +000021 echo "PROGNAME=\"$PROGNAME\""
Lev Walkin444e7392006-09-15 22:45:40 +000022 echo "ASN1PDU, ASN1MODULES, and PROGNAME are mandatory"
Lev Walkin2fd86de2006-09-13 02:10:23 +000023 exit
24fi
25
26../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?
27
Lev Walkinc51cdd42006-09-17 00:20:47 +000028if test ! -f Makefile.am.sample ; then
Lev Walkin2fd86de2006-09-13 02:10:23 +000029 echo "Makefile.am.sample is missing"
30 exit 1
31fi
32
Lev Walkina9532f42006-09-17 04:52:50 +000033ASN1DEFPDU=`echo "$ASN1PDU" | tr - _`
34CFLAGS="-DPDU=${ASN1DEFPDU}"
Lev Walkincc7c94e2006-09-17 04:01:29 +000035if test -f config.h ; then
Lev Walkina9532f42006-09-17 04:52:50 +000036 CFLAGS="-DHAVE_CONFIG_H $CFLAGS"
Lev Walkin43739162006-09-17 03:53:11 +000037fi
38
Lev Walkin2fd86de2006-09-13 02:10:23 +000039set -x
40cat Makefile.am.sample \
Lev Walkina9532f42006-09-17 04:52:50 +000041 | sed -e "s/^CFLAGS += /CFLAGS += ${CFLAGS} /" \
Lev Walkin2fd86de2006-09-13 02:10:23 +000042 | sed -e "s/^all: /all: ${ASN1PDU}.c /" \
43 | sed -e "s/progname/${PROGNAME}/" \
44 > Makefile.$$
45
46( echo
Lev Walkinc33a59e2006-09-18 20:04:14 +000047 echo "${ASN1PDU}.c: $0 ${ASN1MODULES}"
Lev Walkin43739162006-09-17 03:53:11 +000048 echo " make regen-makefile"
49 echo " @touch ${ASN1PDU}.c"
50 echo " make"
51 echo
52 echo "regen-makefile:"
Lev Walkin2fd86de2006-09-13 02:10:23 +000053 echo " ASN1CMDOPTS=\"${ASN1CMDOPTS}\" \\"
54 echo " ASN1MODULES=\"${ASN1MODULES}\" \\"
55 echo " ASN1PDU=${ASN1PDU} \\"
56 echo " PROGNAME=${PROGNAME} \\"
57 echo " $0"
Lev Walkin2fd86de2006-09-13 02:10:23 +000058 echo
Lev Walkinc744a022006-09-15 18:33:25 +000059 echo 'check: ${TARGET}'
Lev Walkin00918812006-09-18 21:19:32 +000060 echo " @if test -f sample-${ASN1PDU}-1.[db]er ; then \\"
61 echo " for f in sample-${ASN1PDU}-*.[db]er; do \\"
Lev Walkinc744a022006-09-15 18:33:25 +000062 echo ' echo "Recoding $$f into XER and back..."; \'
Lev Walkinbc691772006-09-17 11:02:53 +000063 echo ' ./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
64 echo ' ./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \'
65 echo ' ./${TARGET} -iber -oxer -b 33 $$f > ./.tmp.1.$$$$ || exit 2; \'
66 echo ' ./${TARGET} -iber -oxer -b 980 $$f > ./.tmp.1.$$$$ || exit 2; \'
67 echo ' ./${TARGET} -iber -oxer $$f > ./.tmp.1.$$$$ || exit 2; \'
68 echo ' ./${TARGET} -ixer -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
69 echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
70 echo ' rm -f ./.tmp.[12].$$$$; \'
Lev Walkinc744a022006-09-15 18:33:25 +000071 echo ' done; fi'
Lev Walkin00918812006-09-18 21:19:32 +000072 echo " @if test -f sample-${ASN1PDU}-1.xer ; then \\"
73 echo " for f in sample-${ASN1PDU}-*.xer; do \\"
Lev Walkin8c2ca0b2006-09-17 06:31:08 +000074 echo ' echo "Recoding $$f into DER and back..."; \'
Lev Walkinbc691772006-09-17 11:02:53 +000075 echo ' ./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
76 echo ' ./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \'
77 echo ' ./${TARGET} -ixer -oder -b 33 $$f > ./.tmp.1.$$$$ || exit 2; \'
78 echo ' ./${TARGET} -ixer -oder -b 980 $$f > ./.tmp.1.$$$$ || exit 2; \'
79 echo ' ./${TARGET} -ixer -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
80 echo ' ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
81 echo ' diff $$f ./.tmp.2.$$$$ || exit 2; \'
82 echo ' rm -f ./.tmp.[12].$$$$; \'
Lev Walkin8c2ca0b2006-09-17 06:31:08 +000083 echo ' done; fi'
Lev Walkin00918812006-09-18 21:19:32 +000084 echo " @if test -f sample-${ASN1PDU}-1.per ; then \\"
85 echo " for f in sample-${ASN1PDU}-[1-9].per; do \\"
Lev Walkin8c2ca0b2006-09-17 06:31:08 +000086 echo ' echo "Recoding $$f into DER into XER and back..."; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +000087 echo ' ./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
88 echo ' ./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \'
89 echo ' ./${TARGET} -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \'
90 echo ' ./${TARGET} -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \'
91 echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
92 echo ' diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \'
93 echo ' diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \'
Lev Walkinbc691772006-09-17 11:02:53 +000094 echo ' ./${TARGET} -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
95 echo ' ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +000096 echo ' ./${TARGET} -ixer -oder ./.tmp.2.$$$$ > ./.tmp.3.$$$$ || exit 2; \'
97 echo ' diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \'
98 echo ' rm -f ./.tmp.[1234].$$$$; \'
99 echo ' done; fi'
Lev Walkin00918812006-09-18 21:19:32 +0000100 echo " @if test -f sample-${ASN1PDU}-1-padded.per ; then \\"
101 echo " for f in sample-*-[1-9]-padded.per; do \\"
102 echo ' pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +0000103 echo ' echo "Recoding byte-padded $$f into DER into XER and back..."; \'
Lev Walkin00918812006-09-18 21:19:32 +0000104 echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \'
105 echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \'
106 echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \'
107 echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +0000108 echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
109 echo ' diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \'
110 echo ' diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \'
Lev Walkin00918812006-09-18 21:19:32 +0000111 echo ' ./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
112 echo ' ./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
113 echo ' ./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
Lev Walkinbc691772006-09-17 11:02:53 +0000114 echo ' diff $$f ./.tmp.1.$$$$ || exit 2; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +0000115 echo ' rm -f ./.tmp.[1234].$$$$; \'
Lev Walkin8c2ca0b2006-09-17 06:31:08 +0000116 echo ' done; fi'
Lev Walkinc744a022006-09-15 18:33:25 +0000117 echo ' @echo ================'
118 echo ' @echo All tests passed'
119 echo ' @echo ================'
120 echo
Lev Walkin2fd86de2006-09-13 02:10:23 +0000121 echo "distclean: clean"
Lev Walkin4fe13ff2006-09-17 02:57:40 +0000122 echo ' rm -f $(ASN_MODULE_SOURCES)'
123 echo ' rm -f $(ASN_MODULE_HEADERS)'
Lev Walkin2fd86de2006-09-13 02:10:23 +0000124 echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
125 echo " rm -f Makefile.am.sample"
126) >> Makefile.$$
127
128rm Makefile.am.sample || exit $?
129
130mv Makefile.$$ Makefile
131
132set +x
133echo
134echo "Makefile generation finished"