1*548bfc56SSimon J. Gerraty# $NetBSD: opt-m-include-dir.mk,v 1.5 2024/04/30 16:13:34 sjg Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the -m command line option, which adds a directory to the 42c3632d1SSimon J. Gerraty# search path for the .include <...> directive. 52c3632d1SSimon J. Gerraty# 62c3632d1SSimon J. Gerraty# The .../canary.mk special argument starts searching in the current 72c3632d1SSimon J. Gerraty# directory and walks towards the file system root, until it finds a 82c3632d1SSimon J. Gerraty# directory that contains a file called canary.mk. 92c3632d1SSimon J. Gerraty# 102c3632d1SSimon J. Gerraty# To set up this scenario, the file step2.mk is created deep in a hierarchy 112c3632d1SSimon J. Gerraty# of subdirectories. Another file called opt-m-step3.mk is created a few 122c3632d1SSimon J. Gerraty# steps up in the directory hierarchy, serving as the canary file. 132c3632d1SSimon J. Gerraty# 142c3632d1SSimon J. Gerraty# Next to the canary file, there is opt-m-step3.mk. This file is found 152c3632d1SSimon J. Gerraty# by mentioning its simple name in an .include directive. It defines the 162c3632d1SSimon J. Gerraty# target "step2" that is needed by "step2.mk". 172c3632d1SSimon J. Gerraty 182c3632d1SSimon J. Gerraty.if ${.PARSEFILE:T} == "opt-m-include-dir.mk" 192c3632d1SSimon J. Gerraty 202c3632d1SSimon J. Gerraty# Set up the other files needed for this test. 212c3632d1SSimon J. Gerraty 222c3632d1SSimon J. GerratyTEST_DIR:= ${.PARSEFILE:R}.tmp/sub/sub/sub/workdir 232c3632d1SSimon J. GerratyCANARY_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-canary.mk 242c3632d1SSimon J. GerratyACTUAL_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-step3.mk 25*548bfc56SSimon J. GerratyWANTED_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-check.mk 262c3632d1SSimon J. Gerraty 272c3632d1SSimon J. Gerraty_!= mkdir -p ${TEST_DIR} 282c3632d1SSimon J. Gerraty_!= > ${CANARY_FILE} 292c3632d1SSimon J. Gerraty_!= cp ${MAKEFILE} ${TEST_DIR}/step2.mk 302c3632d1SSimon J. Gerraty_!= cp ${MAKEFILE} ${ACTUAL_FILE} 31*548bfc56SSimon J. Gerraty_!= echo CHECK=ok > ${WANTED_FILE} 32*548bfc56SSimon J. Gerraty_!= echo CHECK=${WANTED_FILE:T} found in .CURDIR > ${TEST_DIR}/${WANTED_FILE:T} 332c3632d1SSimon J. Gerraty 342c3632d1SSimon J. Gerratystep1: 352c3632d1SSimon J. Gerraty @${.MAKE} -C ${TEST_DIR} -f step2.mk step2 362c3632d1SSimon J. Gerraty 372c3632d1SSimon J. Gerraty.END: 382c3632d1SSimon J. Gerraty @rm -rf ${MAKEFILE:R}.tmp 392c3632d1SSimon J. Gerraty 402c3632d1SSimon J. Gerraty.elif ${.PARSEFILE:T} == "step2.mk" 412c3632d1SSimon J. Gerraty 422c3632d1SSimon J. Gerraty# This is the file deep in the directory hierarchy. It sets up the 432c3632d1SSimon J. Gerraty# search path for the .include <...> directive and then includes a 442c3632d1SSimon J. Gerraty# single file from that search path. 452c3632d1SSimon J. Gerraty 462c3632d1SSimon J. Gerraty# This option adds .tmp/sub to the search path for .include <...>. 472c3632d1SSimon J. Gerraty.MAKEFLAGS: -m .../opt-m-canary.mk 482c3632d1SSimon J. Gerraty 492c3632d1SSimon J. Gerraty# This option does not add any directory to the search path since the 502c3632d1SSimon J. Gerraty# canary file does not exist. 512c3632d1SSimon J. Gerraty.MAKEFLAGS: -m .../does-not-exist 522c3632d1SSimon J. Gerraty 532c3632d1SSimon J. Gerraty.include <opt-m-step3.mk> 542c3632d1SSimon J. Gerraty 552c3632d1SSimon J. Gerraty.elif ${.PARSEFILE:T} == "opt-m-step3.mk" 562c3632d1SSimon J. Gerraty 572c3632d1SSimon J. Gerraty# This file is included by step2.mk. 58*548bfc56SSimon J. Gerraty.include <opt-m-check.mk> 592c3632d1SSimon J. Gerraty 602c3632d1SSimon J. Gerratystep2: 61*548bfc56SSimon J. Gerraty @echo ${CHECK} 622c3632d1SSimon J. Gerraty 632c3632d1SSimon J. Gerraty.else 642c3632d1SSimon J. Gerraty. error 652c3632d1SSimon J. Gerraty.endif 66