Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Lev Walkin | 4373916 | 2006-09-17 03:53:11 +0000 | [diff] [blame] | 2 | # |
| 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 Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 13 | |
Lev Walkin | c51cdd4 | 2006-09-17 00:20:47 +0000 | [diff] [blame] | 14 | if test -z "$ASN1PDU" \ |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 15 | -o -z "$ASN1MODULES" \ |
| 16 | -o -z "$PROGNAME" \ |
Lev Walkin | c51cdd4 | 2006-09-17 00:20:47 +0000 | [diff] [blame] | 17 | ; then |
Lev Walkin | 444e739 | 2006-09-15 22:45:40 +0000 | [diff] [blame] | 18 | echo "ASN1CMDOPTS=\"$ASN1CMDOPTS\"" |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 19 | echo "ASN1MODULES=\"$ASN1MODULES\"" |
Lev Walkin | 444e739 | 2006-09-15 22:45:40 +0000 | [diff] [blame] | 20 | echo "ASN1PDU=\"$ASN1PDU\"" |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 21 | echo "PROGNAME=\"$PROGNAME\"" |
Lev Walkin | 444e739 | 2006-09-15 22:45:40 +0000 | [diff] [blame] | 22 | echo "ASN1PDU, ASN1MODULES, and PROGNAME are mandatory" |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 23 | exit |
| 24 | fi |
| 25 | |
| 26 | ../../asn1c/asn1c -S ../../skeletons ${ASN1CMDOPTS} ${ASN1MODULES} || exit $? |
| 27 | |
Lev Walkin | c51cdd4 | 2006-09-17 00:20:47 +0000 | [diff] [blame] | 28 | if test ! -f Makefile.am.sample ; then |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 29 | echo "Makefile.am.sample is missing" |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 33 | ASN1DEFPDU=`echo "$ASN1PDU" | tr - _` |
| 34 | CFLAGS="-DPDU=${ASN1DEFPDU}" |
Lev Walkin | cc7c94e | 2006-09-17 04:01:29 +0000 | [diff] [blame] | 35 | if test -f config.h ; then |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 36 | CFLAGS="-DHAVE_CONFIG_H $CFLAGS" |
Lev Walkin | 4373916 | 2006-09-17 03:53:11 +0000 | [diff] [blame] | 37 | fi |
| 38 | |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 39 | set -x |
| 40 | cat Makefile.am.sample \ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 41 | | sed -e "s/^CFLAGS += /CFLAGS += ${CFLAGS} /" \ |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 42 | | sed -e "s/^all: /all: ${ASN1PDU}.c /" \ |
| 43 | | sed -e "s/progname/${PROGNAME}/" \ |
| 44 | > Makefile.$$ |
| 45 | |
| 46 | ( echo |
Lev Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 47 | echo "${ASN1PDU}.c: $0 ${ASN1MODULES}" |
Lev Walkin | 4373916 | 2006-09-17 03:53:11 +0000 | [diff] [blame] | 48 | echo " make regen-makefile" |
| 49 | echo " @touch ${ASN1PDU}.c" |
| 50 | echo " make" |
| 51 | echo |
| 52 | echo "regen-makefile:" |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 53 | echo " ASN1CMDOPTS=\"${ASN1CMDOPTS}\" \\" |
| 54 | echo " ASN1MODULES=\"${ASN1MODULES}\" \\" |
| 55 | echo " ASN1PDU=${ASN1PDU} \\" |
| 56 | echo " PROGNAME=${PROGNAME} \\" |
| 57 | echo " $0" |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 58 | echo |
Lev Walkin | c744a02 | 2006-09-15 18:33:25 +0000 | [diff] [blame] | 59 | echo 'check: ${TARGET}' |
Lev Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 60 | echo " @if test -f sample-${ASN1PDU}-1.[db]er ; then \\" |
| 61 | echo " for f in sample-${ASN1PDU}-*.[db]er; do \\" |
Lev Walkin | c744a02 | 2006-09-15 18:33:25 +0000 | [diff] [blame] | 62 | echo ' echo "Recoding $$f into XER and back..."; \' |
Lev Walkin | bc69177 | 2006-09-17 11:02:53 +0000 | [diff] [blame] | 63 | 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 Walkin | c744a02 | 2006-09-15 18:33:25 +0000 | [diff] [blame] | 71 | echo ' done; fi' |
Lev Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 72 | echo " @if test -f sample-${ASN1PDU}-1.xer ; then \\" |
| 73 | echo " for f in sample-${ASN1PDU}-*.xer; do \\" |
Lev Walkin | 8c2ca0b | 2006-09-17 06:31:08 +0000 | [diff] [blame] | 74 | echo ' echo "Recoding $$f into DER and back..."; \' |
Lev Walkin | bc69177 | 2006-09-17 11:02:53 +0000 | [diff] [blame] | 75 | 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 Walkin | 8c2ca0b | 2006-09-17 06:31:08 +0000 | [diff] [blame] | 83 | echo ' done; fi' |
Lev Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 84 | echo " @if test -f sample-${ASN1PDU}-1.per ; then \\" |
| 85 | echo " for f in sample-${ASN1PDU}-[1-9].per; do \\" |
Lev Walkin | 8c2ca0b | 2006-09-17 06:31:08 +0000 | [diff] [blame] | 86 | echo ' echo "Recoding $$f into DER into XER and back..."; \' |
Lev Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 87 | 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 Walkin | bc69177 | 2006-09-17 11:02:53 +0000 | [diff] [blame] | 94 | echo ' ./${TARGET} -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \' |
| 95 | echo ' ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \' |
Lev Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 96 | 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 Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 100 | 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 Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 103 | echo ' echo "Recoding byte-padded $$f into DER into XER and back..."; \' |
Lev Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 104 | 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 Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 108 | 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 Walkin | 0091881 | 2006-09-18 21:19:32 +0000 | [diff] [blame^] | 111 | 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 Walkin | bc69177 | 2006-09-17 11:02:53 +0000 | [diff] [blame] | 114 | echo ' diff $$f ./.tmp.1.$$$$ || exit 2; \' |
Lev Walkin | c33a59e | 2006-09-18 20:04:14 +0000 | [diff] [blame] | 115 | echo ' rm -f ./.tmp.[1234].$$$$; \' |
Lev Walkin | 8c2ca0b | 2006-09-17 06:31:08 +0000 | [diff] [blame] | 116 | echo ' done; fi' |
Lev Walkin | c744a02 | 2006-09-15 18:33:25 +0000 | [diff] [blame] | 117 | echo ' @echo ================' |
| 118 | echo ' @echo All tests passed' |
| 119 | echo ' @echo ================' |
| 120 | echo |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 121 | echo "distclean: clean" |
Lev Walkin | 4fe13ff | 2006-09-17 02:57:40 +0000 | [diff] [blame] | 122 | echo ' rm -f $(ASN_MODULE_SOURCES)' |
| 123 | echo ' rm -f $(ASN_MODULE_HEADERS)' |
Lev Walkin | 2fd86de | 2006-09-13 02:10:23 +0000 | [diff] [blame] | 124 | echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)' |
| 125 | echo " rm -f Makefile.am.sample" |
| 126 | ) >> Makefile.$$ |
| 127 | |
| 128 | rm Makefile.am.sample || exit $? |
| 129 | |
| 130 | mv Makefile.$$ Makefile |
| 131 | |
| 132 | set +x |
| 133 | echo |
| 134 | echo "Makefile generation finished" |