blob: 5072c1890ba0a04df3215b2bed292632ad50241d [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
Lev Walkinaf250192006-09-21 01:51:57 +000026if test -x ../../asn1c/asn1c ; then
27 echo "Compiling ${ASN1MODULES} using local compiler"
28 ../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?
29else
30 echo "Compiling ${ASN1MODULES} using system compiler"
31 asn1c ${ASN1CMDOPTS} ${ASN1MODULES} || exit $?
32fi
Lev Walkin2fd86de2006-09-13 02:10:23 +000033
Lev Walkinc51cdd42006-09-17 00:20:47 +000034if test ! -f Makefile.am.sample ; then
Lev Walkin2fd86de2006-09-13 02:10:23 +000035 echo "Makefile.am.sample is missing"
36 exit 1
37fi
38
Lev Walkina9532f42006-09-17 04:52:50 +000039ASN1DEFPDU=`echo "$ASN1PDU" | tr - _`
40CFLAGS="-DPDU=${ASN1DEFPDU}"
Lev Walkincc7c94e2006-09-17 04:01:29 +000041if test -f config.h ; then
Lev Walkina9532f42006-09-17 04:52:50 +000042 CFLAGS="-DHAVE_CONFIG_H $CFLAGS"
Lev Walkin43739162006-09-17 03:53:11 +000043fi
44
Lev Walkin2fd86de2006-09-13 02:10:23 +000045set -x
46cat Makefile.am.sample \
Lev Walkina9532f42006-09-17 04:52:50 +000047 | sed -e "s/^CFLAGS += /CFLAGS += ${CFLAGS} /" \
Lev Walkin2fd86de2006-09-13 02:10:23 +000048 | sed -e "s/^all: /all: ${ASN1PDU}.c /" \
49 | sed -e "s/progname/${PROGNAME}/" \
50 > Makefile.$$
Lev Walkinaf250192006-09-21 01:51:57 +000051set +x
Lev Walkin2fd86de2006-09-13 02:10:23 +000052
53( echo
Lev Walkinc33a59e2006-09-18 20:04:14 +000054 echo "${ASN1PDU}.c: $0 ${ASN1MODULES}"
Lev Walkin43739162006-09-17 03:53:11 +000055 echo " make regen-makefile"
56 echo " @touch ${ASN1PDU}.c"
57 echo " make"
58 echo
59 echo "regen-makefile:"
Lev Walkin2fd86de2006-09-13 02:10:23 +000060 echo " ASN1CMDOPTS=\"${ASN1CMDOPTS}\" \\"
61 echo " ASN1MODULES=\"${ASN1MODULES}\" \\"
62 echo " ASN1PDU=${ASN1PDU} \\"
63 echo " PROGNAME=${PROGNAME} \\"
64 echo " $0"
Lev Walkin2fd86de2006-09-13 02:10:23 +000065 echo
Lev Walkinc744a022006-09-15 18:33:25 +000066 echo 'check: ${TARGET}'
Lev Walkin00918812006-09-18 21:19:32 +000067 echo " @if test -f sample-${ASN1PDU}-1.[db]er ; then \\"
68 echo " for f in sample-${ASN1PDU}-*.[db]er; do \\"
Lev Walkin13afe532006-09-18 21:30:04 +000069 echo ' for b in 1 17 33 980 8192; do \'
70 echo ' echo "Recoding $$f into XER and back ($$b)..."; \'
71 echo ' ./${TARGET} -b $$b -iber -oxer $$f > ./.tmp.1.$$$$ || exit 2; \'
72 echo ' ./${TARGET} -b $$b -ixer -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
Lev Walkinbc691772006-09-17 11:02:53 +000073 echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
74 echo ' rm -f ./.tmp.[12].$$$$; \'
Lev Walkin13afe532006-09-18 21:30:04 +000075 echo ' done; done; fi'
Lev Walkin00918812006-09-18 21:19:32 +000076 echo " @if test -f sample-${ASN1PDU}-1.xer ; then \\"
77 echo " for f in sample-${ASN1PDU}-*.xer; do \\"
Lev Walkin13afe532006-09-18 21:30:04 +000078 echo ' for b in 1 17 33 980 8192; do \'
79 echo ' echo "Recoding $$f into DER and back ($$b)..."; \'
80 echo ' ./${TARGET} -b $$b -ixer -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
81 echo ' ./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
Lev Walkinbc691772006-09-17 11:02:53 +000082 echo ' diff $$f ./.tmp.2.$$$$ || exit 2; \'
83 echo ' rm -f ./.tmp.[12].$$$$; \'
Lev Walkin13afe532006-09-18 21:30:04 +000084 echo ' done; done; fi'
Lev Walkin00918812006-09-18 21:19:32 +000085 echo " @if test -f sample-${ASN1PDU}-1.per ; then \\"
86 echo " for f in sample-${ASN1PDU}-[1-9].per; do \\"
Lev Walkin13afe532006-09-18 21:30:04 +000087 echo ' for b in 1 17 33 980 8192; do \'
88 echo ' echo "Recoding $$f into DER into XER and back ($$b)..."; \'
89 echo ' ./${TARGET} -b $$b -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
90 echo ' ./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
91 echo ' ./${TARGET} -b $$b -ixer -oder ./.tmp.2.$$$$ > ./.tmp.3.$$$$ || exit 2; \'
Lev Walkinc33a59e2006-09-18 20:04:14 +000092 echo ' diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \'
Lev Walkin13afe532006-09-18 21:30:04 +000093 echo ' rm -f ./.tmp.[123].$$$$; \'
94 echo ' done; done; fi'
Lev Walkin00918812006-09-18 21:19:32 +000095 echo " @if test -f sample-${ASN1PDU}-1-padded.per ; then \\"
96 echo " for f in sample-*-[1-9]-padded.per; do \\"
97 echo ' pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \'
Lev Walkin13afe532006-09-18 21:30:04 +000098 echo ' for b in 1 17 33 980 8192; do \'
99 echo ' echo "Recoding byte-padded $$f into DER into XER and back ($$b)..."; \'
100 echo ' ./${TARGET} -b $$b -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
101 echo ' ./${TARGET} -b $$b -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
102 echo ' ./${TARGET} -b $$b -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
Lev Walkinbc691772006-09-17 11:02:53 +0000103 echo ' diff $$f ./.tmp.1.$$$$ || exit 2; \'
Lev Walkin13afe532006-09-18 21:30:04 +0000104 echo ' rm -f ./.tmp.[12].$$$$; \'
105 echo ' done; done; fi'
Lev Walkinc744a022006-09-15 18:33:25 +0000106 echo ' @echo ================'
107 echo ' @echo All tests passed'
108 echo ' @echo ================'
109 echo
Lev Walkin2fd86de2006-09-13 02:10:23 +0000110 echo "distclean: clean"
Lev Walkin4fe13ff2006-09-17 02:57:40 +0000111 echo ' rm -f $(ASN_MODULE_SOURCES)'
112 echo ' rm -f $(ASN_MODULE_HEADERS)'
Lev Walkin2fd86de2006-09-13 02:10:23 +0000113 echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
114 echo " rm -f Makefile.am.sample"
115) >> Makefile.$$
116
Lev Walkinaf250192006-09-21 01:51:57 +0000117set -x
118mv Makefile.$$ Makefile || exit $?
Lev Walkin2fd86de2006-09-13 02:10:23 +0000119rm Makefile.am.sample || exit $?
Lev Walkin2fd86de2006-09-13 02:10:23 +0000120set +x
Lev Walkinaf250192006-09-21 01:51:57 +0000121
Lev Walkin2fd86de2006-09-13 02:10:23 +0000122echo
123echo "Makefile generation finished"