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 | |
| 31 | args=$(echo "$source_short" | sed -e 's/\.c[c]*$//') |
| 32 | |
| 33 | OFS=$IFS |
| 34 | IFS="." |
| 35 | set $args |
| 36 | shift |
| 37 | IFS=$OFS |
| 38 | AFLAGS="$*" |
| 39 | |
| 40 | # Assume the test fails. Will be removed when it passes well. |
| 41 | testdir=test-${args} |
| 42 | if [ -f "${testdir}-FAILED" ]; then |
| 43 | rm -rf "${testdir}" |
| 44 | fi |
| 45 | touch "${testdir}-FAILED" |
| 46 | |
| 47 | mkdir -p "${testdir}" |
| 48 | ln -fns "../${source_full}" "${testdir}" |
| 49 | |
| 50 | asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1) |
| 51 | |
| 52 | AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}" |
| 53 | |
| 54 | # Create a common Makefile for the project |
| 55 | cat <<TARGETS > "${testdir}/Makefile.targets" |
| 56 | ${AUTOGENERATED} |
| 57 | |
| 58 | COMMON_FLAGS= -I. -I${abs_top_srcdir}/skeletons |
| 59 | CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O0 |
| 60 | CPPFLAGS = -DSRCDIR=../${srcdir} |
| 61 | CXXFLAGS = \${COMMON_FLAGS} ${CXXFLAGS} |
| 62 | LDFLAGS = ${LDFLAGS:-} |
| 63 | |
| 64 | CC ?= ${CC} |
| 65 | |
| 66 | all: compiled-module |
| 67 | \$(MAKE) check-executable |
| 68 | |
| 69 | check-executable: \$(OBJS) |
| 70 | @rm -f *.core |
| 71 | \$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(LDFLAGS) -o check-executable \$(OBJS) -L${abs_top_builddir}/skeletons/.libs -lasn1cskeletons -lm |
| 72 | |
| 73 | # Compile the corresponding .asn1 spec. |
| 74 | compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c |
| 75 | ${abs_top_builddir}/asn1c/asn1c \\ |
| 76 | -S ${abs_top_srcdir}/skeletons \\ |
| 77 | -Wdebug-compiler \\ |
| 78 | ${AFLAGS} ${asn_module} |
| 79 | rm -f converter-sample.c |
| 80 | @touch compiled-module |
| 81 | |
| 82 | check-succeeded: compiled-module |
| 83 | \$(MAKE) check-executable |
| 84 | @rm -f check-succeeded |
| 85 | ./check-executable |
| 86 | @touch check-succeeded |
| 87 | |
| 88 | check: check-succeeded |
| 89 | |
| 90 | clean: |
| 91 | @rm -f *.o check-executable |
| 92 | TARGETS |
| 93 | |
| 94 | # Create a BSD- or GNU-specific Makefile for the project. |
| 95 | produce_specific_makefile() { |
| 96 | local make_type=$1 |
| 97 | local make_file="$testdir/${make_type}makefile" |
| 98 | |
| 99 | if [ ${make_type} = "BSD" ]; then |
| 100 | cat <<-OBJECTS > ${make_file} |
| 101 | ${AUTOGENERATED} |
| 102 | SRCS!=find . -name \*.c |
| 103 | OBJS=\${SRCS:.c=.o} |
| 104 | .sinclude <Makefile.targets> |
| 105 | OBJECTS |
| 106 | else |
| 107 | cat <<-OBJECTS > ${make_file} |
| 108 | ${AUTOGENERATED} |
| 109 | OBJS=\$(patsubst %.c,%.o,\$(wildcard *.c)) |
| 110 | -include Makefile.targets |
| 111 | OBJECTS |
| 112 | fi |
| 113 | |
| 114 | } |
| 115 | |
| 116 | produce_specific_makefile BSD |
| 117 | produce_specific_makefile GNU |
| 118 | |
| 119 | # Perform building and checking |
| 120 | ${TEST_DRIVER} make -C "$testdir" check |
| 121 | |
| 122 | # Make sure the test is not marked as failed any longer. |
| 123 | rm -f "${testdir}-FAILED" |