114ecce5sjg# $NetBSD: opt-m-include-dir.mk,v 1.4 2020/09/01 20:14:34 rillig Exp $
214ecce5sjg#
314ecce5sjg# Tests for the -m command line option, which adds a directory to the
414ecce5sjg# search path for the .include <...> directive.
514ecce5sjg#
614ecce5sjg# The .../canary.mk special argument starts searching in the current
714ecce5sjg# directory and walks towards the file system root, until it finds a
814ecce5sjg# directory that contains a file called canary.mk.
914ecce5sjg#
1014ecce5sjg# To set up this scenario, the file step2.mk is created deep in a hierarchy
1114ecce5sjg# of subdirectories.  Another file called opt-m-step3.mk is created a few
1214ecce5sjg# steps up in the directory hierarchy, serving as the canary file.
1314ecce5sjg#
1414ecce5sjg# Next to the canary file, there is opt-m-step3.mk.  This file is found
1514ecce5sjg# by mentioning its simple name in an .include directive.  It defines the
1614ecce5sjg# target "step2" that is needed by "step2.mk".
1714ecce5sjg
1814ecce5sjg.if ${.PARSEFILE:T} == "opt-m-include-dir.mk"
1914ecce5sjg
2014ecce5sjg# Set up the other files needed for this test.
2114ecce5sjg
2214ecce5sjgTEST_DIR:=	${.PARSEFILE:R}.tmp/sub/sub/sub/workdir
2314ecce5sjgCANARY_FILE:=	${.PARSEFILE:R}.tmp/sub/opt-m-canary.mk
2414ecce5sjgACTUAL_FILE:=	${.PARSEFILE:R}.tmp/sub/opt-m-step3.mk
2514ecce5sjg
2614ecce5sjg_!=	mkdir -p ${TEST_DIR}
2714ecce5sjg_!=	> ${CANARY_FILE}
2814ecce5sjg_!=	cp ${MAKEFILE} ${TEST_DIR}/step2.mk
2914ecce5sjg_!=	cp ${MAKEFILE} ${ACTUAL_FILE}
3014ecce5sjg
3114ecce5sjgstep1:
3214ecce5sjg	@${.MAKE} -C ${TEST_DIR} -f step2.mk step2
3314ecce5sjg
3414ecce5sjg.END:
3514ecce5sjg	@rm -rf ${MAKEFILE:R}.tmp
3614ecce5sjg
3714ecce5sjg.elif ${.PARSEFILE:T} == "step2.mk"
3814ecce5sjg
3914ecce5sjg# This is the file deep in the directory hierarchy.  It sets up the
4014ecce5sjg# search path for the .include <...> directive and then includes a
4114ecce5sjg# single file from that search path.
4214ecce5sjg
4314ecce5sjg# This option adds .tmp/sub to the search path for .include <...>.
4414ecce5sjg.MAKEFLAGS: -m .../opt-m-canary.mk
4514ecce5sjg
4614ecce5sjg# This option does not add any directory to the search path since the
4714ecce5sjg# canary file does not exist.
4814ecce5sjg.MAKEFLAGS: -m .../does-not-exist
4914ecce5sjg
5014ecce5sjg.include <opt-m-step3.mk>
5114ecce5sjg
5214ecce5sjg.elif ${.PARSEFILE:T} == "opt-m-step3.mk"
5314ecce5sjg
5414ecce5sjg# This file is included by step2.mk.
5514ecce5sjg
5614ecce5sjgstep2:
5714ecce5sjg	@echo ok
5814ecce5sjg
5914ecce5sjg.else
6014ecce5sjg.  error
6114ecce5sjg.endif
62