1# $NetBSD: opt-m-include-dir.mk,v 1.5 2024/04/30 16:13:34 sjg Exp $
2#
3# Tests for the -m command line option, which adds a directory to the
4# search path for the .include <...> directive.
5#
6# The .../canary.mk special argument starts searching in the current
7# directory and walks towards the file system root, until it finds a
8# directory that contains a file called canary.mk.
9#
10# To set up this scenario, the file step2.mk is created deep in a hierarchy
11# of subdirectories.  Another file called opt-m-step3.mk is created a few
12# steps up in the directory hierarchy, serving as the canary file.
13#
14# Next to the canary file, there is opt-m-step3.mk.  This file is found
15# by mentioning its simple name in an .include directive.  It defines the
16# target "step2" that is needed by "step2.mk".
17
18.if ${.PARSEFILE:T} == "opt-m-include-dir.mk"
19
20# Set up the other files needed for this test.
21
22TEST_DIR:=	${.PARSEFILE:R}.tmp/sub/sub/sub/workdir
23CANARY_FILE:=	${.PARSEFILE:R}.tmp/sub/opt-m-canary.mk
24ACTUAL_FILE:=	${.PARSEFILE:R}.tmp/sub/opt-m-step3.mk
25WANTED_FILE:=	${.PARSEFILE:R}.tmp/sub/opt-m-check.mk
26
27_!=	mkdir -p ${TEST_DIR}
28_!=	> ${CANARY_FILE}
29_!=	cp ${MAKEFILE} ${TEST_DIR}/step2.mk
30_!=	cp ${MAKEFILE} ${ACTUAL_FILE}
31_!=	echo CHECK=ok > ${WANTED_FILE}
32_!=	echo CHECK=${WANTED_FILE:T} found in .CURDIR > ${TEST_DIR}/${WANTED_FILE:T}
33
34step1:
35	@${.MAKE} -C ${TEST_DIR} -f step2.mk step2
36
37.END:
38	@rm -rf ${MAKEFILE:R}.tmp
39
40.elif ${.PARSEFILE:T} == "step2.mk"
41
42# This is the file deep in the directory hierarchy.  It sets up the
43# search path for the .include <...> directive and then includes a
44# single file from that search path.
45
46# This option adds .tmp/sub to the search path for .include <...>.
47.MAKEFLAGS: -m .../opt-m-canary.mk
48
49# This option does not add any directory to the search path since the
50# canary file does not exist.
51.MAKEFLAGS: -m .../does-not-exist
52
53.include <opt-m-step3.mk>
54
55.elif ${.PARSEFILE:T} == "opt-m-step3.mk"
56
57# This file is included by step2.mk.
58.include <opt-m-check.mk>
59
60step2:
61	@echo ${CHECK}
62
63.else
64.  error
65.endif
66