xref: /freebsd/share/mk/bsd.test.mk (revision 839529caa9c35f92b638dbe074655598e7a6bb6f)
1# $FreeBSD$
2#
3# Generic build infrastructure for test programs.
4#
5# This is the only public file that should be included by Makefiles when
6# tests are to be built.  All other *.test.mk files are internal and not
7# to be included directly.
8
9.include <bsd.init.mk>
10
11__<bsd.test.mk>__:
12
13# Third-party software (kyua, etc) prefix.
14LOCALBASE?=	/usr/local
15
16# Tests install directory
17TESTSDIR?=	${TESTSBASE}/${RELDIR:H}
18
19# List of subdirectories containing tests into which to recurse.  This has the
20# same semantics as SUBDIR at build-time.  However, the directories listed here
21# get registered into the run-time test suite definitions so that the test
22# engines know to recurse into these directories.
23#
24# In other words: list here any directories that contain test programs but use
25# SUBDIR for directories that may contain helper binaries and/or data files.
26TESTS_SUBDIRS?=
27
28# If defined, indicates that the tests built by the Makefile are not part of
29# the FreeBSD Test Suite.  The implication of this is that the tests won't be
30# installed under /usr/tests/ and that Kyua won't be able to run them.
31#NOT_FOR_TEST_SUITE=
32
33# List of variables to pass to the tests at run-time via the environment.
34TESTS_ENV?=
35
36# Force all tests in a separate distribution file.
37#
38# We want this to be the case even when the distribution name is already
39# overriden.  For example: we want the tests for programs in the 'games'
40# distribution to end up in the 'tests' distribution; the test programs
41# themselves have all the necessary logic to detect that the games are not
42# installed and thus won't cause false negatives.
43DISTRIBUTION:=	tests
44
45# Ordered list of directories to construct the PATH for the tests.
46TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
47             ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
48TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
49
50# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
51TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
52TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
53
54# List of all tests being built.  The various *.test.mk modules extend this
55# variable as needed.
56_TESTS=
57
58# Pull in the definitions of all supported test interfaces.
59.include <atf.test.mk>
60.include <plain.test.mk>
61.include <tap.test.mk>
62
63# kyua automatically descends directories; only run make check on the
64# top-level directory
65.if !make(check)
66.for ts in ${TESTS_SUBDIRS}
67.if empty(SUBDIR:M${ts})
68SUBDIR+= ${ts}
69.endif
70.endfor
71.endif
72
73# it is rare for test cases to have man pages
74.if !defined(MAN)
75MAN=
76.endif
77
78# tell progs.mk we might want to install things
79PROG_VARS+= BINDIR
80PROGS_TARGETS+= install
81
82.if !defined(NOT_FOR_TEST_SUITE)
83.include <suite.test.mk>
84.endif
85
86.if !target(realcheck)
87realcheck: .PHONY
88	@echo "$@ not defined; skipping"
89.endif
90
91beforecheck realcheck aftercheck check: .PHONY
92.ORDER: beforecheck realcheck aftercheck
93check: beforecheck realcheck aftercheck
94
95.ifdef PROG
96# we came here via bsd.progs.mk below
97# parent will do staging.
98MK_STAGING= no
99.endif
100
101.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
102.include <bsd.progs.mk>
103.endif
104.include <bsd.files.mk>
105
106.if !defined(PROG) && ${MK_STAGING} != "no"
107.if !defined(_SKIP_BUILD)
108# this will handle staging if needed
109_SKIP_STAGING= no
110# but we don't want it to build anything
111_SKIP_BUILD=
112.endif
113.if !empty(PROGS)
114stage_files.prog: ${PROGS}
115.endif
116.include <bsd.prog.mk>
117.endif
118
119.if !target(objwarn)
120.include <bsd.obj.mk>
121.endif
122