xref: /freebsd/cddl/usr.sbin/dtrace/tests/tools/genmakefiles.sh (revision 93e779a26c651610ac6e7986d67ecc9ed2cadcbf)
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    if [ "$basedir" = proc ]; then
38        special="
39LDADD.tst.sigwait.exe+= -lrt
40DPADD.tst.sigwait.exe+= \${LIBRT}
41"
42    elif [ "$basedir" = uctf ]; then
43        special="
44WITH_CTF=YES
45"
46    fi
47
48    local makefile=$(mktemp)
49    cat <<__EOF__ > $makefile
50# \$FreeBSD$
51
52#
53# This Makefile was generated by \$srcdir${ORIGINDIR#${TOPDIR}}/genmakefiles.sh.
54#
55
56TESTFILES= \\
57$tfiles
58
59TESTEXES= \\
60$texes
61
62CFILES= \\
63$tcfiles
64
65$special
66.include "../../dtrace.test.mk"
67__EOF__
68
69    mv -f $makefile ${ORIGINDIR}/../common/${basedir}/Makefile
70}
71
72set -e
73
74if [ $# -ne 0 ]; then
75    usage
76fi
77
78readonly ORIGINDIR=$(realpath $(dirname $0))
79readonly TOPDIR=$(realpath ${ORIGINDIR}/../../../../..)
80readonly CONTRIB_TESTDIR=${TOPDIR}/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common
81
82# Generate a Makefile for each test group under common/.
83for dir in $(find ${CONTRIB_TESTDIR} -mindepth 1 -maxdepth 1 -type d); do
84    genmakefile $(basename $dir)
85done
86