Lev Walkin | 700df49 | 2017-08-10 14:59:15 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # |
| 4 | # This script is designed to quickly create lots of files in underlying |
| 5 | # test-* directories, do lots of other magic stuff and exit cleanly. |
| 6 | # |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | if [ "x$1" = "x" ]; then |
| 11 | echo "Usage: $0 <check-NN.c>" |
| 12 | exit |
| 13 | fi |
| 14 | |
| 15 | srcdir="${srcdir:-.}" |
| 16 | abs_top_srcdir="${abs_top_srcdir:-$(pwd)/../../}" |
| 17 | abs_top_builddir="${abs_top_builddir:-$(pwd)/../../}" |
| 18 | |
| 19 | if echo "$*" | grep -q -- -- ; then |
| 20 | TEST_DRIVER=$(echo "$*" | sed -e 's/ -- .*/ -- /g') |
| 21 | source_full=$(echo "$*" | sed -e 's/.* //g') |
| 22 | else |
| 23 | TEST_DRIVER="" |
| 24 | source_full="$1" |
| 25 | fi |
| 26 | |
| 27 | # Compute the .asn1 spec name by the given file name. |
| 28 | source_short=$(echo "$source_full" | sed -e 's/.*\///') |
| 29 | testno=$(echo "$source_short" | cut -f2 -d'-' | cut -f1 -d'.') |
| 30 | |
Lev Walkin | 122002e | 2017-08-25 12:55:25 -0700 | [diff] [blame] | 31 | CODECS_FLAGS="" |
| 32 | has_oer=$(echo "$source_short" | grep "gen-OER" || :) |
| 33 | if [ ! "$has_oer" ]; then |
| 34 | CODECS_FLAGS="${CODECS_FLAGS} -DASN_DISABLE_OER_SUPPORT" |
| 35 | fi |
| 36 | has_per=$(echo "$source_short" | grep "gen-PER" || :) |
| 37 | if [ ! "$has_per" ]; then |
| 38 | CODECS_FLAGS="${CODECS_FLAGS} -DASN_DISABLE_PER_SUPPORT" |
| 39 | fi |
| 40 | |
Lev Walkin | 700df49 | 2017-08-10 14:59:15 -0700 | [diff] [blame] | 41 | args=$(echo "$source_short" | sed -e 's/\.c[c]*$//') |
| 42 | |
| 43 | OFS=$IFS |
| 44 | IFS="." |
| 45 | set $args |
| 46 | shift |
| 47 | IFS=$OFS |
| 48 | AFLAGS="$*" |
| 49 | |
| 50 | # Assume the test fails. Will be removed when it passes well. |
| 51 | testdir=test-${args} |
| 52 | if [ -f "${testdir}-FAILED" ]; then |
| 53 | rm -rf "${testdir}" |
| 54 | fi |
| 55 | touch "${testdir}-FAILED" |
| 56 | |
| 57 | mkdir -p "${testdir}" |
| 58 | ln -fns "../${source_full}" "${testdir}" |
| 59 | |
| 60 | asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1) |
| 61 | |
| 62 | AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}" |
| 63 | |
| 64 | # Create a common Makefile for the project |
| 65 | cat <<TARGETS > "${testdir}/Makefile.targets" |
| 66 | ${AUTOGENERATED} |
| 67 | |
Lev Walkin | 026055f | 2017-08-27 01:28:59 -0700 | [diff] [blame] | 68 | COMMON_FLAGS= -I. |
Lev Walkin | 700df49 | 2017-08-10 14:59:15 -0700 | [diff] [blame] | 69 | CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O0 |
Lev Walkin | 122002e | 2017-08-25 12:55:25 -0700 | [diff] [blame] | 70 | CPPFLAGS = -DSRCDIR=../${srcdir} ${CODECS_FLAGS} |
Lev Walkin | 700df49 | 2017-08-10 14:59:15 -0700 | [diff] [blame] | 71 | CXXFLAGS = \${COMMON_FLAGS} ${CXXFLAGS} |
| 72 | LDFLAGS = ${LDFLAGS:-} |
| 73 | |
| 74 | CC ?= ${CC} |
| 75 | |
| 76 | all: compiled-module |
| 77 | \$(MAKE) check-executable |
| 78 | |
| 79 | check-executable: \$(OBJS) |
| 80 | @rm -f *.core |
Lev Walkin | 026055f | 2017-08-27 01:28:59 -0700 | [diff] [blame] | 81 | \$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(LDFLAGS) -o check-executable \$(OBJS) -lm |
Lev Walkin | 700df49 | 2017-08-10 14:59:15 -0700 | [diff] [blame] | 82 | |
| 83 | # Compile the corresponding .asn1 spec. |
| 84 | compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c |
| 85 | ${abs_top_builddir}/asn1c/asn1c \\ |
| 86 | -S ${abs_top_srcdir}/skeletons \\ |
| 87 | -Wdebug-compiler \\ |
| 88 | ${AFLAGS} ${asn_module} |
| 89 | rm -f converter-sample.c |
| 90 | @touch compiled-module |
| 91 | |
| 92 | check-succeeded: compiled-module |
| 93 | \$(MAKE) check-executable |
| 94 | @rm -f check-succeeded |
| 95 | ./check-executable |
| 96 | @touch check-succeeded |
| 97 | |
| 98 | check: check-succeeded |
| 99 | |
| 100 | clean: |
| 101 | @rm -f *.o check-executable |
| 102 | TARGETS |
| 103 | |
| 104 | # Create a BSD- or GNU-specific Makefile for the project. |
| 105 | produce_specific_makefile() { |
| 106 | local make_type=$1 |
| 107 | local make_file="$testdir/${make_type}makefile" |
| 108 | |
| 109 | if [ ${make_type} = "BSD" ]; then |
| 110 | cat <<-OBJECTS > ${make_file} |
| 111 | ${AUTOGENERATED} |
| 112 | SRCS!=find . -name \*.c |
| 113 | OBJS=\${SRCS:.c=.o} |
| 114 | .sinclude <Makefile.targets> |
| 115 | OBJECTS |
| 116 | else |
| 117 | cat <<-OBJECTS > ${make_file} |
| 118 | ${AUTOGENERATED} |
| 119 | OBJS=\$(patsubst %.c,%.o,\$(wildcard *.c)) |
| 120 | -include Makefile.targets |
| 121 | OBJECTS |
| 122 | fi |
| 123 | |
| 124 | } |
| 125 | |
| 126 | produce_specific_makefile BSD |
| 127 | produce_specific_makefile GNU |
| 128 | |
| 129 | # Perform building and checking |
| 130 | ${TEST_DRIVER} make -C "$testdir" check |
| 131 | |
| 132 | # Make sure the test is not marked as failed any longer. |
| 133 | rm -f "${testdir}-FAILED" |