blob: 7d04ab4eaa68e9a23071e527b3da0820894b8606 [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
31args=$(echo "$source_short" | sed -e 's/\.c[c]*$//')
32
33OFS=$IFS
34IFS="."
35set $args
36shift
37IFS=$OFS
38AFLAGS="$*"
39
40# Assume the test fails. Will be removed when it passes well.
41testdir=test-${args}
42if [ -f "${testdir}-FAILED" ]; then
43 rm -rf "${testdir}"
44fi
45touch "${testdir}-FAILED"
46
47mkdir -p "${testdir}"
48ln -fns "../${source_full}" "${testdir}"
49
50asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1)
51
52AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}"
53
54# Create a common Makefile for the project
55cat <<TARGETS > "${testdir}/Makefile.targets"
56${AUTOGENERATED}
57
58COMMON_FLAGS= -I. -I${abs_top_srcdir}/skeletons
59CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O0
60CPPFLAGS = -DSRCDIR=../${srcdir}
61CXXFLAGS = \${COMMON_FLAGS} ${CXXFLAGS}
62LDFLAGS = ${LDFLAGS:-}
63
64CC ?= ${CC}
65
66all: compiled-module
67 \$(MAKE) check-executable
68
69check-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.
74compiled-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
82check-succeeded: compiled-module
83 \$(MAKE) check-executable
84 @rm -f check-succeeded
85 ./check-executable
86 @touch check-succeeded
87
88check: check-succeeded
89
90clean:
91 @rm -f *.o check-executable
92TARGETS
93
94# Create a BSD- or GNU-specific Makefile for the project.
95produce_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
116produce_specific_makefile BSD
117produce_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.
123rm -f "${testdir}-FAILED"