blob: 95c177945531b963ddc5e07274beaa421c10523b [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
47 echo "${ASN1PDU}.c: $0"
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}'
60 echo " @if test -f ./sample-${ASN1PDU}-1.[db]er ; then \\"
61 echo " for f in ./sample-${ASN1PDU}-*.[db]er; do \\"
62 echo ' echo "Recoding $$f into XER and back..."; \'
63 echo ' ./${TARGET} -iber -oxer $$f > ./.tmp.1.$$ || exit 2; \'
64 echo ' ./${TARGET} -ixer -oxer ./.tmp.1.$$ > ./.tmp.2.$$ || exit 2; \'
65 echo ' diff ./.tmp.1.$$ ./.tmp.2.$$ || exit 2; \'
66 echo ' rm -f ./.tmp.[12].$$; \'
67 echo ' done; fi'
Lev Walkin8c2ca0b2006-09-17 06:31:08 +000068 echo " @if test -f ./sample-${ASN1PDU}-1.xer ; then \\"
69 echo " for f in ./sample-${ASN1PDU}-*.xer; do \\"
70 echo ' echo "Recoding $$f into DER and back..."; \'
71 echo ' ./${TARGET} -ixer -oder $$f > ./.tmp.1.$$ || exit 2; \'
72 echo ' ./${TARGET} -iber -oxer ./.tmp.1.$$ > ./.tmp.2.$$ || exit 2; \'
73 echo ' diff $$f ./.tmp.2.$$ || exit 2; \'
74 echo ' rm -f ./.tmp.[12].$$; \'
75 echo ' done; fi'
76 echo " @if test -f ./sample-${ASN1PDU}-1.per ; then \\"
77 echo " for f in ./sample-${ASN1PDU}-*.per; do \\"
78 echo ' echo "Recoding $$f into DER into XER and back..."; \'
79 echo ' ./${TARGET} -iper -oder $$f > ./.tmp.1.$$ || exit 2; \'
80 echo ' ./${TARGET} -ider -oxer ./.tmp.1.$$ > ./.tmp.2.$$ || exit 2; \'
81 echo ' ./${TARGET} -ixer -oper ./.tmp.2.$$ > ./.tmp.1.$$ || exit 2; \'
82 echo ' diff $$f ./.tmp.1.$$ || exit 2; \'
83 echo ' rm -f ./.tmp.[12].$$; \'
84 echo ' done; fi'
Lev Walkinc744a022006-09-15 18:33:25 +000085 echo ' @echo ================'
86 echo ' @echo All tests passed'
87 echo ' @echo ================'
88 echo
Lev Walkin2fd86de2006-09-13 02:10:23 +000089 echo "distclean: clean"
Lev Walkin4fe13ff2006-09-17 02:57:40 +000090 echo ' rm -f $(ASN_MODULE_SOURCES)'
91 echo ' rm -f $(ASN_MODULE_HEADERS)'
Lev Walkin2fd86de2006-09-13 02:10:23 +000092 echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
93 echo " rm -f Makefile.am.sample"
94) >> Makefile.$$
95
96rm Makefile.am.sample || exit $?
97
98mv Makefile.$$ Makefile
99
100set +x
101echo
102echo "Makefile generation finished"