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