xref: /freebsd/cddl/usr.sbin/dtrace/tests/tools/genmakefiles.sh (revision ef36b3f75658d201edb495068db5e1be49593de5)
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"
57        ;;
58    esac
59
60    local makefile=$(mktemp)
61    cat <<__EOF__ > $makefile
62# \$FreeBSD$
63
64#
65# This Makefile was generated by \$srcdir${ORIGINDIR#${TOPDIR}}/genmakefiles.sh.
66#
67
68PACKAGE=	tests
69
70\${PACKAGE}FILES= \\
71$tfiles
72
73TESTEXES= \\
74$texes
75
76CFILES= \\
77$tcfiles
78
79$special
80.include "../../dtrace.test.mk"
81__EOF__
82
83    mv -f $makefile ${ORIGINDIR}/../common/${basedir}/Makefile
84}
85
86set -e
87
88if [ $# -ne 0 ]; then
89    usage
90fi
91
92export LC_ALL=C
93
94readonly ORIGINDIR=$(realpath $(dirname $0))
95readonly TOPDIR=$(realpath ${ORIGINDIR}/../../../../..)
96readonly CONTRIB_TESTDIR=${TOPDIR}/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common
97
98# Generate a Makefile for each test group under common/.
99for dir in $(find ${CONTRIB_TESTDIR} -mindepth 1 -maxdepth 1 -type d); do
100    genmakefile $(basename $dir)
101done
102