xref: /freebsd/cddl/usr.sbin/dtrace/tests/tools/genmakefiles.sh (revision f0cfa1b168014f56c02b83e5f28412cc5f78d117)
1# $FreeBSD$
2
3usage()
4{
5    cat <<__EOF__ >&2
6usage: $(basename $0)
7
8This script regenerates the DTrace test suite makefiles. It should be run
9whenever \$srcdir/cddl/contrib/opensolaris/cmd/dtrace/test/tst is modified.
10__EOF__
11    exit 1
12}
13
14# Format a file list for use in a make(1) variable assignment: take the
15# basename of each input file and append " \" to it.
16fmtflist()
17{
18    awk 'function bn(f) {
19        sub(".*/", "", f)
20        return f
21    }
22    {print "    ", bn($1), " \\"}'
23}
24
25genmakefile()
26{
27    local basedir=$1
28
29    local tdir=${CONTRIB_TESTDIR}/${basedir}
30    local tfiles=$(find $tdir -type f -a \
31        \( -name \*.d -o -name \*.ksh -o -name \*.out \) | sort | fmtflist)
32    local tcfiles=$(find $tdir -type f -a -name \*.c | sort | fmtflist)
33    local texes=$(find $tdir -type f -a -name \*.exe | sort | fmtflist)
34
35    # One-off variable definitions.
36    local special
37    case "$basedir" in
38    proc)
39        special="
40LIBADD.tst.sigwait.exe+= rt
41"
42        ;;
43    raise)
44	special="
45TEST_METADATA.t_dtrace_contrib+=	required_memory=\"4g\"
46"
47        ;;
48    safety)
49	special="
50TEST_METADATA.t_dtrace_contrib+=	required_memory=\"4g\"
51"
52        ;;
53    uctf)
54        special="
55WITH_CTF=YES
56
57CFLAGS.tst.chasestrings.exe+= -m32
58"
59        ;;
60    esac
61
62    local makefile=$(mktemp)
63    cat <<__EOF__ > $makefile
64# \$FreeBSD$
65
66#
67# This Makefile was generated by \$srcdir${ORIGINDIR#${TOPDIR}}/genmakefiles.sh.
68#
69
70PACKAGE=	tests
71
72\${PACKAGE}FILES= \\
73$tfiles
74
75TESTEXES= \\
76$texes
77
78CFILES= \\
79$tcfiles
80
81$special
82.include "../../dtrace.test.mk"
83__EOF__
84
85    mv -f $makefile ${ORIGINDIR}/../common/${basedir}/Makefile
86}
87
88set -e
89
90if [ $# -ne 0 ]; then
91    usage
92fi
93
94export LC_ALL=C
95
96readonly ORIGINDIR=$(realpath $(dirname $0))
97readonly TOPDIR=$(realpath ${ORIGINDIR}/../../../../..)
98readonly CONTRIB_TESTDIR=${TOPDIR}/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common
99
100# Generate a Makefile for each test group under common/.
101for dir in $(find ${CONTRIB_TESTDIR} -mindepth 1 -maxdepth 1 -type d); do
102    genmakefile $(basename $dir)
103done
104