blob: a382423a8f22f49fcdde95343ad3eab9ad941cc9 [file] [log] [blame]
vlm94c92c02006-09-13 02:10:23 +00001#!/bin/sh
vlm13d1c512006-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#
vlm94c92c02006-09-13 02:10:23 +000013
vlmfa58cc72006-09-17 00:20:47 +000014if test -z "$ASN1PDU" \
vlm94c92c02006-09-13 02:10:23 +000015 -o -z "$ASN1MODULES" \
16 -o -z "$PROGNAME" \
vlmfa58cc72006-09-17 00:20:47 +000017; then
vlmebfee8e2006-09-15 22:45:40 +000018 echo "ASN1CMDOPTS=\"$ASN1CMDOPTS\""
vlm94c92c02006-09-13 02:10:23 +000019 echo "ASN1MODULES=\"$ASN1MODULES\""
vlmebfee8e2006-09-15 22:45:40 +000020 echo "ASN1PDU=\"$ASN1PDU\""
vlm94c92c02006-09-13 02:10:23 +000021 echo "PROGNAME=\"$PROGNAME\""
vlmebfee8e2006-09-15 22:45:40 +000022 echo "ASN1PDU, ASN1MODULES, and PROGNAME are mandatory"
vlm94c92c02006-09-13 02:10:23 +000023 exit
24fi
25
vlmd99294a2006-09-23 02:52:12 +000026CMDOPTS="-pdu=${ASN1PDU} ${ASN1CMDOPTS} ${ASN1MODULES}"
27
vlm60928922006-09-21 01:51:57 +000028if test -x ../../asn1c/asn1c ; then
29 echo "Compiling ${ASN1MODULES} using local compiler"
vlmd99294a2006-09-23 02:52:12 +000030 ../../asn1c/asn1c -S ../../skeletons ${CMDOPTS} || exit $?
vlm60928922006-09-21 01:51:57 +000031else
32 echo "Compiling ${ASN1MODULES} using system compiler"
vlmd99294a2006-09-23 02:52:12 +000033 asn1c ${CMDOPTS} || exit $?
vlm60928922006-09-21 01:51:57 +000034fi
vlm94c92c02006-09-13 02:10:23 +000035
vlmfa58cc72006-09-17 00:20:47 +000036if test ! -f Makefile.am.sample ; then
vlm94c92c02006-09-13 02:10:23 +000037 echo "Makefile.am.sample is missing"
38 exit 1
39fi
40
vlmd99294a2006-09-23 02:52:12 +000041EXTRA_CFLAGS=""
vlm70c232d2006-09-17 04:01:29 +000042if test -f config.h ; then
vlmd6132a62006-09-23 02:56:19 +000043 EXTRA_CFLAGS="-DHAVE_CONFIG_H"
vlm13d1c512006-09-17 03:53:11 +000044fi
45
vlm94c92c02006-09-13 02:10:23 +000046set -x
47cat Makefile.am.sample \
vlmd99294a2006-09-23 02:52:12 +000048 | sed -e "s/^CFLAGS += /CFLAGS += ${EXTRA_CFLAGS} /" \
vlm94c92c02006-09-13 02:10:23 +000049 | sed -e "s/^all: /all: ${ASN1PDU}.c /" \
50 | sed -e "s/progname/${PROGNAME}/" \
51 > Makefile.$$
vlm60928922006-09-21 01:51:57 +000052set +x
vlm94c92c02006-09-13 02:10:23 +000053
54( echo
vlmf49ca902006-09-18 20:04:14 +000055 echo "${ASN1PDU}.c: $0 ${ASN1MODULES}"
vlm13d1c512006-09-17 03:53:11 +000056 echo " make regen-makefile"
57 echo " @touch ${ASN1PDU}.c"
58 echo " make"
59 echo
60 echo "regen-makefile:"
vlm94c92c02006-09-13 02:10:23 +000061 echo " ASN1CMDOPTS=\"${ASN1CMDOPTS}\" \\"
62 echo " ASN1MODULES=\"${ASN1MODULES}\" \\"
63 echo " ASN1PDU=${ASN1PDU} \\"
64 echo " PROGNAME=${PROGNAME} \\"
65 echo " $0"
vlm94c92c02006-09-13 02:10:23 +000066 echo
vlme0fb1e82006-09-15 18:33:25 +000067 echo 'check: ${TARGET}'
vlmde70d692006-09-18 21:19:32 +000068 echo " @if test -f sample-${ASN1PDU}-1.[db]er ; then \\"
69 echo " for f in sample-${ASN1PDU}-*.[db]er; do \\"
vlm774407b2006-09-18 21:30:04 +000070 echo ' for b in 1 17 33 980 8192; do \'
71 echo ' echo "Recoding $$f into XER and back ($$b)..."; \'
72 echo ' ./${TARGET} -b $$b -iber -oxer $$f > ./.tmp.1.$$$$ || exit 2; \'
73 echo ' ./${TARGET} -b $$b -ixer -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
vlme7e9bd92006-09-17 11:02:53 +000074 echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \'
75 echo ' rm -f ./.tmp.[12].$$$$; \'
vlm774407b2006-09-18 21:30:04 +000076 echo ' done; done; fi'
vlmde70d692006-09-18 21:19:32 +000077 echo " @if test -f sample-${ASN1PDU}-1.xer ; then \\"
78 echo " for f in sample-${ASN1PDU}-*.xer; do \\"
vlm774407b2006-09-18 21:30:04 +000079 echo ' for b in 1 17 33 980 8192; do \'
80 echo ' echo "Recoding $$f into DER and back ($$b)..."; \'
81 echo ' ./${TARGET} -b $$b -ixer -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
82 echo ' ./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
vlme7e9bd92006-09-17 11:02:53 +000083 echo ' diff $$f ./.tmp.2.$$$$ || exit 2; \'
84 echo ' rm -f ./.tmp.[12].$$$$; \'
vlm774407b2006-09-18 21:30:04 +000085 echo ' done; done; fi'
vlmde70d692006-09-18 21:19:32 +000086 echo " @if test -f sample-${ASN1PDU}-1.per ; then \\"
87 echo " for f in sample-${ASN1PDU}-[1-9].per; do \\"
vlm774407b2006-09-18 21:30:04 +000088 echo ' for b in 1 17 33 980 8192; do \'
89 echo ' echo "Recoding $$f into DER into XER and back ($$b)..."; \'
90 echo ' ./${TARGET} -b $$b -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
91 echo ' ./${TARGET} -b $$b -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
92 echo ' ./${TARGET} -b $$b -ixer -oder ./.tmp.2.$$$$ > ./.tmp.3.$$$$ || exit 2; \'
vlmf49ca902006-09-18 20:04:14 +000093 echo ' diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \'
vlm774407b2006-09-18 21:30:04 +000094 echo ' rm -f ./.tmp.[123].$$$$; \'
95 echo ' done; done; fi'
vlmde70d692006-09-18 21:19:32 +000096 echo " @if test -f sample-${ASN1PDU}-1-padded.per ; then \\"
97 echo " for f in sample-*-[1-9]-padded.per; do \\"
98 echo ' pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \'
vlm774407b2006-09-18 21:30:04 +000099 echo ' for b in 1 17 33 980 8192; do \'
100 echo ' echo "Recoding byte-padded $$f into DER into XER and back ($$b)..."; \'
101 echo ' ./${TARGET} -b $$b -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \'
102 echo ' ./${TARGET} -b $$b -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \'
103 echo ' ./${TARGET} -b $$b -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \'
vlme7e9bd92006-09-17 11:02:53 +0000104 echo ' diff $$f ./.tmp.1.$$$$ || exit 2; \'
vlm774407b2006-09-18 21:30:04 +0000105 echo ' rm -f ./.tmp.[12].$$$$; \'
106 echo ' done; done; fi'
vlme0fb1e82006-09-15 18:33:25 +0000107 echo ' @echo ================'
108 echo ' @echo All tests passed'
109 echo ' @echo ================'
110 echo
vlm94c92c02006-09-13 02:10:23 +0000111 echo "distclean: clean"
vlm66cea382006-09-17 02:57:40 +0000112 echo ' rm -f $(ASN_MODULE_SOURCES)'
113 echo ' rm -f $(ASN_MODULE_HEADERS)'
vlm94c92c02006-09-13 02:10:23 +0000114 echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
115 echo " rm -f Makefile.am.sample"
116) >> Makefile.$$
117
vlm60928922006-09-21 01:51:57 +0000118set -x
119mv Makefile.$$ Makefile || exit $?
vlm94c92c02006-09-13 02:10:23 +0000120rm Makefile.am.sample || exit $?
vlm94c92c02006-09-13 02:10:23 +0000121set +x
vlm60928922006-09-21 01:51:57 +0000122
vlm94c92c02006-09-13 02:10:23 +0000123echo
124echo "Makefile generation finished"