Module Name:    src
Committed By:   rillig
Date:           Sun May 17 12:36:26 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile
Added Files:
        src/usr.bin/make/unit-tests: include-main.exp include-main.mk
            include-sub.mk include-subsub.mk

Log Message:
usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE


To generate a diff of this commit:
cvs rdiff -u -r1.840 -r1.841 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/include-main.exp \
    src/usr.bin/make/unit-tests/include-main.mk \
    src/usr.bin/make/unit-tests/include-sub.mk \
    src/usr.bin/make/unit-tests/include-subsub.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.840 src/distrib/sets/lists/tests/mi:1.841
--- src/distrib/sets/lists/tests/mi:1.840	Sun May 10 12:34:01 2020
+++ src/distrib/sets/lists/tests/mi	Sun May 17 12:36:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.840 2020/05/10 12:34:01 rillig Exp $
+# $NetBSD: mi,v 1.841 2020/05/17 12:36:26 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4493,6 +4493,10 @@
 ./usr/tests/usr.bin/make/unit-tests/hash.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/impsrc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/impsrc.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-main.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-main.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-sub.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/include-subsub.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/moderrs.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.57 src/usr.bin/make/unit-tests/Makefile:1.58
--- src/usr.bin/make/unit-tests/Makefile:1.57	Sun May 10 12:42:11 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun May 17 12:36:26 2020
@@ -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 \

Added files:

Index: src/usr.bin/make/unit-tests/include-main.exp
diff -u /dev/null src/usr.bin/make/unit-tests/include-main.exp:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-main.exp	Sun May 17 12:36:26 2020
@@ -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
Index: src/usr.bin/make/unit-tests/include-main.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-main.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-main.mk	Sun May 17 12:36:26 2020
@@ -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}
Index: src/usr.bin/make/unit-tests/include-sub.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-sub.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-sub.mk	Sun May 17 12:36:26 2020
@@ -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
Index: src/usr.bin/make/unit-tests/include-subsub.mk
diff -u /dev/null src/usr.bin/make/unit-tests/include-subsub.mk:1.1
--- /dev/null	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/include-subsub.mk	Sun May 17 12:36:26 2020
@@ -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

Reply via email to