make: ensure '.include <makefile>' respects MAKESYSPATH

Since Dir_FindFile is used by '.include' and its variants,
and will first search .CURDIR unless the give path starts with
".DOTLAST".

Update unit-tests/opt-m-include-dir to test this.
This commit is contained in:
sjg 2024-04-30 16:13:33 +00:00
parent 9b67dda14d
commit 7e10b2067b
3 changed files with 11 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.613 2024/04/27 17:33:46 rillig Exp $ */
/* $NetBSD: main.c,v 1.614 2024/04/30 16:13:33 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: main.c,v 1.613 2024/04/27 17:33:46 rillig Exp $");
MAKE_RCSID("$NetBSD: main.c,v 1.614 2024/04/30 16:13:33 sjg Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@ -1156,6 +1156,8 @@ InitDefSysIncPath(char *syspath)
else
syspath = bmake_strdup(syspath);
/* do NOT search .CURDIR first for .include <makefile> */
SearchPath_Add(defSysIncPath, ".DOTLAST");
for (start = syspath; *start != '\0'; start = p) {
for (p = start; *p != '\0' && *p != ':'; p++)
continue;

View File

@ -2,7 +2,7 @@ Expanding "depsrc-phony-pr-15164-*-wildcard"...
Expanding "deptgt-phony-pr-15164-*-wildcard"...
Searching for .depend ...
failed.
Searching for .depend ...
Searching for .depend ...[dot last]...
/usr/share/mk ...
failed.
Wildcard expanding "all"...

View File

@ -1,4 +1,4 @@
# $NetBSD: opt-m-include-dir.mk,v 1.4 2020/09/01 20:14:34 rillig Exp $
# $NetBSD: opt-m-include-dir.mk,v 1.5 2024/04/30 16:13:34 sjg Exp $
#
# Tests for the -m command line option, which adds a directory to the
# search path for the .include <...> directive.
@ -22,11 +22,14 @@
TEST_DIR:= ${.PARSEFILE:R}.tmp/sub/sub/sub/workdir
CANARY_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-canary.mk
ACTUAL_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-step3.mk
WANTED_FILE:= ${.PARSEFILE:R}.tmp/sub/opt-m-check.mk
_!= mkdir -p ${TEST_DIR}
_!= > ${CANARY_FILE}
_!= cp ${MAKEFILE} ${TEST_DIR}/step2.mk
_!= cp ${MAKEFILE} ${ACTUAL_FILE}
_!= echo CHECK=ok > ${WANTED_FILE}
_!= echo CHECK=${WANTED_FILE:T} found in .CURDIR > ${TEST_DIR}/${WANTED_FILE:T}
step1:
@${.MAKE} -C ${TEST_DIR} -f step2.mk step2
@ -52,9 +55,10 @@ step1:
.elif ${.PARSEFILE:T} == "opt-m-step3.mk"
# This file is included by step2.mk.
.include <opt-m-check.mk>
step2:
@echo ok
@echo ${CHECK}
.else
. error