xref: /freebsd/cddl/usr.sbin/dtrace/tests/tools/genmakefiles.sh (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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 class=$1
28    local group=$2
29
30    local tdir=${CONTRIB_TESTDIR}/${class}/${group}
31    local tfiles=$(find $tdir -type f -a \
32        \( -name \*.d -o -name \*.ksh -o -name \*.out \) | sort | fmtflist)
33    local tcfiles=$(find $tdir -type f -a -name \*.c | sort | fmtflist)
34    local texes=$(find $tdir -type f -a -name \*.exe | sort | fmtflist)
35
36    # One-off variable definitions.
37    local special
38    case "$group" in
39    proc)
40        special="
41LIBADD.tst.sigwait.exe+= rt
42"
43        ;;
44    raise)
45	special="
46TEST_METADATA.t_dtrace_contrib+=	required_memory=\"4g\"
47"
48        ;;
49    safety)
50	special="
51TEST_METADATA.t_dtrace_contrib+=	required_memory=\"4g\"
52"
53        ;;
54    uctf)
55        special="
56WITH_CTF=YES
57"
58        ;;
59    esac
60
61    local makefile=$(mktemp)
62    cat <<__EOF__ > $makefile
63# \$FreeBSD$
64
65#
66# This Makefile was generated by \$srcdir${ORIGINDIR#${TOPDIR}}/genmakefiles.sh.
67#
68
69PACKAGE=	tests
70
71\${PACKAGE}FILES= \\
72$tfiles
73
74TESTEXES= \\
75$texes
76
77CFILES= \\
78$tcfiles
79
80$special
81.include "../../dtrace.test.mk"
82__EOF__
83
84    mv -f $makefile ${ORIGINDIR}/../${class}/${group}/Makefile
85}
86
87set -e
88
89if [ $# -ne 0 ]; then
90    usage
91fi
92
93export LC_ALL=C
94
95readonly ORIGINDIR=$(realpath $(dirname $0))
96readonly TOPDIR=$(realpath ${ORIGINDIR}/../../../../..)
97readonly CONTRIB_TESTDIR=${TOPDIR}/cddl/contrib/opensolaris/cmd/dtrace/test/tst
98
99for class in common i386 amd64; do
100    for group in $(find ${CONTRIB_TESTDIR}/$class -mindepth 1 -maxdepth 1 -type d); do
101        genmakefile $class $(basename $group)
102    done
103done
104