blob: a9fb5593ed5c0504e3241f32556f7ebd4d4d0628 [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 Walkinb5cdc5d2017-09-15 21:57:46 -070041args=$(echo "$source_short" | sed -E -e 's/\.c+$//')
Lev Walkin700df492017-08-10 14:59:15 -070042
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 Walkin24cf97d2017-09-15 20:34:25 -070069CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O1
Lev Walkin40846582017-09-13 23:02:03 +000070CFLAGS += -DSRCDIR=../${srcdir} ${CODECS_FLAGS}
Lev Walkinb5cdc5d2017-09-15 21:57:46 -070071CXXFLAGS = \${CFLAGS} ${CXXFLAGS}
Lev Walkin700df492017-08-10 14:59:15 -070072LDFLAGS = ${LDFLAGS:-}
73
74CC ?= ${CC}
Lev Walkinb5cdc5d2017-09-15 21:57:46 -070075CXX ?= ${CXX}
Lev Walkin700df492017-08-10 14:59:15 -070076
77all: compiled-module
78 \$(MAKE) check-executable
79
80check-executable: \$(OBJS)
81 @rm -f *.core
Lev Walkin40846582017-09-13 23:02:03 +000082 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o check-executable \$(OBJS) -lm
Lev Walkin700df492017-08-10 14:59:15 -070083
84# Compile the corresponding .asn1 spec.
85compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c
86 ${abs_top_builddir}/asn1c/asn1c \\
87 -S ${abs_top_srcdir}/skeletons \\
88 -Wdebug-compiler \\
89 ${AFLAGS} ${asn_module}
90 rm -f converter-sample.c
91 @touch compiled-module
92
93check-succeeded: compiled-module
94 \$(MAKE) check-executable
95 @rm -f check-succeeded
96 ./check-executable
97 @touch check-succeeded
98
99check: check-succeeded
100
101clean:
102 @rm -f *.o check-executable
103TARGETS
104
105# Create a BSD- or GNU-specific Makefile for the project.
106produce_specific_makefile() {
107 local make_type=$1
108 local make_file="$testdir/${make_type}makefile"
109
110 if [ ${make_type} = "BSD" ]; then
111 cat <<-OBJECTS > ${make_file}
112 ${AUTOGENERATED}
Lev Walkinb5cdc5d2017-09-15 21:57:46 -0700113 SRCS_C!=find . -name \*.c
114 SRCS_CXX!=find . -name \*.cc
115 OBJS=\${SRCS_C:.c=.o} ${SRCS_CXX:.cc=.o}
Lev Walkin700df492017-08-10 14:59:15 -0700116 .sinclude <Makefile.targets>
117 OBJECTS
118 else
119 cat <<-OBJECTS > ${make_file}
120 ${AUTOGENERATED}
Lev Walkinb5cdc5d2017-09-15 21:57:46 -0700121 OBJS =\$(patsubst %.c,%.o,\$(wildcard *.c))
122 OBJS+=\$(patsubst %.cc,%.o,\$(wildcard *.cc))
Lev Walkin700df492017-08-10 14:59:15 -0700123 -include Makefile.targets
124 OBJECTS
125 fi
126
127}
128
129produce_specific_makefile BSD
130produce_specific_makefile GNU
131
132# Perform building and checking
133${TEST_DRIVER} make -C "$testdir" check
134
135# Make sure the test is not marked as failed any longer.
136rm -f "${testdir}-FAILED"