blob: f075ed99f704bc779640f96bd50f337737dd09b6 [file] [log] [blame]
Lev Walkin700df492017-08-10 14:59:15 -07001#!/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
8set -e
9
10if [ "x$1" = "x" ]; then
11 echo "Usage: $0 <check-NN.c>"
12 exit
13fi
14
15srcdir="${srcdir:-.}"
16abs_top_srcdir="${abs_top_srcdir:-$(pwd)/../../}"
17abs_top_builddir="${abs_top_builddir:-$(pwd)/../../}"
18
19if echo "$*" | grep -q -- -- ; then
20 TEST_DRIVER=$(echo "$*" | sed -e 's/ -- .*/ -- /g')
21 source_full=$(echo "$*" | sed -e 's/.* //g')
22else
23 TEST_DRIVER=""
24 source_full="$1"
25fi
26
27# Compute the .asn1 spec name by the given file name.
28source_short=$(echo "$source_full" | sed -e 's/.*\///')
29testno=$(echo "$source_short" | cut -f2 -d'-' | cut -f1 -d'.')
30
Lev Walkin122002e2017-08-25 12:55:25 -070031CODECS_FLAGS=""
32has_oer=$(echo "$source_short" | grep "gen-OER" || :)
33if [ ! "$has_oer" ]; then
34 CODECS_FLAGS="${CODECS_FLAGS} -DASN_DISABLE_OER_SUPPORT"
35fi
36has_per=$(echo "$source_short" | grep "gen-PER" || :)
37if [ ! "$has_per" ]; then
38 CODECS_FLAGS="${CODECS_FLAGS} -DASN_DISABLE_PER_SUPPORT"
39fi
40
Lev Walkin700df492017-08-10 14:59:15 -070041args=$(echo "$source_short" | sed -e 's/\.c[c]*$//')
42
43OFS=$IFS
44IFS="."
45set $args
46shift
47IFS=$OFS
48AFLAGS="$*"
49
50# Assume the test fails. Will be removed when it passes well.
51testdir=test-${args}
52if [ -f "${testdir}-FAILED" ]; then
53 rm -rf "${testdir}"
54fi
55touch "${testdir}-FAILED"
56
57mkdir -p "${testdir}"
58ln -fns "../${source_full}" "${testdir}"
59
60asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1)
61
62AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}"
63
64# Create a common Makefile for the project
65cat <<TARGETS > "${testdir}/Makefile.targets"
66${AUTOGENERATED}
67
Lev Walkin026055f2017-08-27 01:28:59 -070068COMMON_FLAGS= -I.
Lev Walkin700df492017-08-10 14:59:15 -070069CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O0
Lev Walkin122002e2017-08-25 12:55:25 -070070CPPFLAGS = -DSRCDIR=../${srcdir} ${CODECS_FLAGS}
Lev Walkin700df492017-08-10 14:59:15 -070071CXXFLAGS = \${COMMON_FLAGS} ${CXXFLAGS}
72LDFLAGS = ${LDFLAGS:-}
73
74CC ?= ${CC}
75
76all: compiled-module
77 \$(MAKE) check-executable
78
79check-executable: \$(OBJS)
80 @rm -f *.core
Lev Walkin026055f2017-08-27 01:28:59 -070081 \$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(LDFLAGS) -o check-executable \$(OBJS) -lm
Lev Walkin700df492017-08-10 14:59:15 -070082
83# Compile the corresponding .asn1 spec.
84compiled-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
92check-succeeded: compiled-module
93 \$(MAKE) check-executable
94 @rm -f check-succeeded
95 ./check-executable
96 @touch check-succeeded
97
98check: check-succeeded
99
100clean:
101 @rm -f *.o check-executable
102TARGETS
103
104# Create a BSD- or GNU-specific Makefile for the project.
105produce_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
126produce_specific_makefile BSD
127produce_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.
133rm -f "${testdir}-FAILED"