From a3d593e7fe371f2baedcd4ebecf6b9babdca4014 Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 17 May 2020 12:36:26 +0000 Subject: usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE --- usr.bin/make/unit-tests/Makefile | 3 ++- usr.bin/make/unit-tests/include-main.exp | 6 ++++++ usr.bin/make/unit-tests/include-main.mk | 30 ++++++++++++++++++++++++++++++ usr.bin/make/unit-tests/include-sub.mk | 17 +++++++++++++++++ usr.bin/make/unit-tests/include-subsub.mk | 7 +++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 usr.bin/make/unit-tests/include-main.exp create mode 100644 usr.bin/make/unit-tests/include-main.mk create mode 100644 usr.bin/make/unit-tests/include-sub.mk create mode 100644 usr.bin/make/unit-tests/include-subsub.mk (limited to 'usr.bin/make') diff --git a/usr.bin/make/unit-tests/Makefile b/usr.bin/make/unit-tests/Makefile index bc3f0b7a056..65a5882a5e9 100644 --- a/usr.bin/make/unit-tests/Makefile +++ b/usr.bin/make/unit-tests/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.57 2020/05/10 12:42:11 rillig Exp $ +# $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $ # # Unit tests for make(1) # The main targets are: @@ -35,6 +35,7 @@ TESTNAMES= \ forloop \ forsubst \ hash \ + include-main \ misc \ moderrs \ modmatch \ diff --git a/usr.bin/make/unit-tests/include-main.exp b/usr.bin/make/unit-tests/include-main.exp new file mode 100644 index 00000000000..7a55c6e97dc --- /dev/null +++ b/usr.bin/make/unit-tests/include-main.exp @@ -0,0 +1,6 @@ +main-before-ok +sub-before-ok +subsub-ok +sub-after-fail(include-sub.mk) +main-after-fail(include-sub.mk) +exit status 0 diff --git a/usr.bin/make/unit-tests/include-main.mk b/usr.bin/make/unit-tests/include-main.mk new file mode 100644 index 00000000000..452b6102a5c --- /dev/null +++ b/usr.bin/make/unit-tests/include-main.mk @@ -0,0 +1,30 @@ +# $NetBSD: include-main.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $ +# +# Demonstrates that the .INCLUDEDFROMFILE magic variable does not behave +# as described in the manual page. +# +# The manual page says that it is the "filename of the file this Makefile +# was included from", while in reality it is the "filename in which the +# latest .include happened". +# + +.if !defined(.INCLUDEDFROMFILE) +LOG+= main-before-ok +.else +. for f in ${.INCLUDEDFROMFILE} +LOG+= main-before-fail\(${f:Q}\) +. endfor +.endif + +.include "include-sub.mk" + +.if !defined(.INCLUDEDFROMFILE) +LOG+= main-after-ok +.else +. for f in ${.INCLUDEDFROMFILE} +LOG+= main-after-fail\(${f:Q}\) +. endfor +.endif + +all: + @printf '%s\n' ${LOG} diff --git a/usr.bin/make/unit-tests/include-sub.mk b/usr.bin/make/unit-tests/include-sub.mk new file mode 100644 index 00000000000..28856fcc6e6 --- /dev/null +++ b/usr.bin/make/unit-tests/include-sub.mk @@ -0,0 +1,17 @@ +# $NetBSD: include-sub.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $ + +.if ${.INCLUDEDFROMFILE} == "include-main.mk" +LOG+= sub-before-ok +.else +LOG+= sub-before-fail +.endif + +.include "include-subsub.mk" + +.if ${.INCLUDEDFROMFILE} == "include-main.mk" +LOG+= sub-after-ok +.else +. for f in ${.INCLUDEDFROMFILE} +LOG+= sub-after-fail\(${f:Q}\) +. endfor +.endif diff --git a/usr.bin/make/unit-tests/include-subsub.mk b/usr.bin/make/unit-tests/include-subsub.mk new file mode 100644 index 00000000000..e8fa1186f41 --- /dev/null +++ b/usr.bin/make/unit-tests/include-subsub.mk @@ -0,0 +1,7 @@ +# $NetBSD: include-subsub.mk,v 1.1 2020/05/17 12:36:26 rillig Exp $ + +.if ${.INCLUDEDFROMFILE:T} == "include-sub.mk" +LOG+= subsub-ok +.else +LOG+= subsub-fail +.endif -- cgit