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