aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/unit-tests')
-rw-r--r--contrib/bmake/unit-tests/Makefile263
-rw-r--r--contrib/bmake/unit-tests/Makefile.config.in5
-rw-r--r--contrib/bmake/unit-tests/cmd-errors-jobs.exp12
-rw-r--r--contrib/bmake/unit-tests/cmd-errors-jobs.mk12
-rw-r--r--contrib/bmake/unit-tests/cmd-errors-lint.exp2
-rw-r--r--contrib/bmake/unit-tests/cmd-errors.exp12
-rw-r--r--contrib/bmake/unit-tests/cmd-errors.mk12
-rwxr-xr-xcontrib/bmake/unit-tests/cmd-interrupt.exp1
-rwxr-xr-xcontrib/bmake/unit-tests/cmd-interrupt.mk4
-rw-r--r--contrib/bmake/unit-tests/cmdline-undefined.exp24
-rw-r--r--contrib/bmake/unit-tests/cmdline-undefined.mk16
-rw-r--r--contrib/bmake/unit-tests/cmdline.exp7
-rw-r--r--contrib/bmake/unit-tests/cmdline.mk24
-rw-r--r--contrib/bmake/unit-tests/comment.mk10
-rw-r--r--contrib/bmake/unit-tests/compat-error.mk27
-rw-r--r--contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp4
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-eq.mk9
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-ge.mk4
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-gt.mk6
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-le.mk4
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-lt.mk4
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-numeric-ne.mk4
-rw-r--r--contrib/bmake/unit-tests/cond-cmp-numeric.exp12
-rw-r--r--contrib/bmake/unit-tests/cond-cmp-numeric.mk27
-rw-r--r--contrib/bmake/unit-tests/cond-cmp-string.exp16
-rw-r--r--contrib/bmake/unit-tests/cond-cmp-string.mk32
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-unary.exp2
-rwxr-xr-xcontrib/bmake/unit-tests/cond-cmp-unary.mk37
-rw-r--r--contrib/bmake/unit-tests/cond-eof.exp9
-rw-r--r--contrib/bmake/unit-tests/cond-eof.mk20
-rw-r--r--contrib/bmake/unit-tests/cond-func-defined.exp10
-rw-r--r--contrib/bmake/unit-tests/cond-func-defined.mk21
-rw-r--r--contrib/bmake/unit-tests/cond-func-empty.exp4
-rw-r--r--contrib/bmake/unit-tests/cond-func-empty.mk150
-rw-r--r--contrib/bmake/unit-tests/cond-func-exists.mk6
-rw-r--r--contrib/bmake/unit-tests/cond-func-make.exp1
-rw-r--r--contrib/bmake/unit-tests/cond-func-make.mk7
-rw-r--r--contrib/bmake/unit-tests/cond-func.exp18
-rw-r--r--contrib/bmake/unit-tests/cond-func.mk42
-rw-r--r--contrib/bmake/unit-tests/cond-late.exp2
-rw-r--r--contrib/bmake/unit-tests/cond-late.mk17
-rw-r--r--contrib/bmake/unit-tests/cond-op-and-lint.exp2
-rw-r--r--contrib/bmake/unit-tests/cond-op-and-lint.mk3
-rw-r--r--contrib/bmake/unit-tests/cond-op-and.exp5
-rw-r--r--contrib/bmake/unit-tests/cond-op-and.mk42
-rw-r--r--contrib/bmake/unit-tests/cond-op-not.exp12
-rw-r--r--contrib/bmake/unit-tests/cond-op-not.mk8
-rw-r--r--contrib/bmake/unit-tests/cond-op-or-lint.exp2
-rw-r--r--contrib/bmake/unit-tests/cond-op-or-lint.mk3
-rw-r--r--contrib/bmake/unit-tests/cond-op-or.exp5
-rw-r--r--contrib/bmake/unit-tests/cond-op-or.mk42
-rw-r--r--contrib/bmake/unit-tests/cond-op-parentheses.exp7
-rw-r--r--contrib/bmake/unit-tests/cond-op-parentheses.mk41
-rw-r--r--contrib/bmake/unit-tests/cond-op.exp35
-rw-r--r--contrib/bmake/unit-tests/cond-op.mk55
-rw-r--r--contrib/bmake/unit-tests/cond-short.exp11
-rw-r--r--contrib/bmake/unit-tests/cond-short.mk228
-rw-r--r--contrib/bmake/unit-tests/cond-token-number.exp9
-rw-r--r--contrib/bmake/unit-tests/cond-token-number.mk43
-rw-r--r--contrib/bmake/unit-tests/cond-token-plain.exp63
-rw-r--r--contrib/bmake/unit-tests/cond-token-plain.mk109
-rw-r--r--contrib/bmake/unit-tests/cond-token-string.exp23
-rw-r--r--contrib/bmake/unit-tests/cond-token-string.mk39
-rw-r--r--contrib/bmake/unit-tests/cond-token-var.exp8
-rw-r--r--contrib/bmake/unit-tests/cond-token-var.mk22
-rwxr-xr-xcontrib/bmake/unit-tests/cond-undef-lint.exp11
-rwxr-xr-xcontrib/bmake/unit-tests/cond-undef-lint.mk9
-rw-r--r--contrib/bmake/unit-tests/cond1.exp23
-rw-r--r--contrib/bmake/unit-tests/cond1.mk114
-rw-r--r--contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp4
-rw-r--r--contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk4
-rw-r--r--contrib/bmake/unit-tests/dep-duplicate.exp4
-rw-r--r--contrib/bmake/unit-tests/dep-duplicate.mk27
-rw-r--r--contrib/bmake/unit-tests/dep-op-missing.exp4
-rw-r--r--contrib/bmake/unit-tests/dep-op-missing.mk13
-rwxr-xr-xcontrib/bmake/unit-tests/dep-var.exp26
-rwxr-xr-xcontrib/bmake/unit-tests/dep-var.mk32
-rw-r--r--contrib/bmake/unit-tests/dep-wildcards.exp2
-rw-r--r--contrib/bmake/unit-tests/dep-wildcards.mk8
-rw-r--r--contrib/bmake/unit-tests/dep.exp6
-rw-r--r--contrib/bmake/unit-tests/dep.mk28
-rw-r--r--contrib/bmake/unit-tests/depsrc-ignore.exp2
-rw-r--r--contrib/bmake/unit-tests/depsrc-meta.exp2
-rw-r--r--contrib/bmake/unit-tests/depsrc-meta.mk21
-rw-r--r--contrib/bmake/unit-tests/depsrc-use.exp4
-rw-r--r--contrib/bmake/unit-tests/depsrc-use.mk21
-rw-r--r--contrib/bmake/unit-tests/depsrc-usebefore.exp46
-rw-r--r--contrib/bmake/unit-tests/depsrc-usebefore.mk109
-rw-r--r--contrib/bmake/unit-tests/depsrc-wait.exp13
-rw-r--r--contrib/bmake/unit-tests/depsrc-wait.mk22
-rw-r--r--contrib/bmake/unit-tests/depsrc.exp1
-rw-r--r--contrib/bmake/unit-tests/depsrc.mk14
-rw-r--r--contrib/bmake/unit-tests/deptgt-begin.exp4
-rw-r--r--contrib/bmake/unit-tests/deptgt-begin.mk12
-rw-r--r--contrib/bmake/unit-tests/deptgt-default.exp1
-rw-r--r--contrib/bmake/unit-tests/deptgt-default.mk17
-rw-r--r--contrib/bmake/unit-tests/deptgt-delete_on_error.exp4
-rw-r--r--contrib/bmake/unit-tests/deptgt-delete_on_error.mk2
-rw-r--r--contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk4
-rw-r--r--contrib/bmake/unit-tests/deptgt-end-fail.mk4
-rw-r--r--contrib/bmake/unit-tests/deptgt-error.exp10
-rw-r--r--contrib/bmake/unit-tests/deptgt-error.mk22
-rw-r--r--contrib/bmake/unit-tests/deptgt-ignore.exp12
-rw-r--r--contrib/bmake/unit-tests/deptgt-ignore.mk30
-rw-r--r--contrib/bmake/unit-tests/deptgt-interrupt.exp3
-rw-r--r--contrib/bmake/unit-tests/deptgt-interrupt.mk9
-rw-r--r--contrib/bmake/unit-tests/deptgt-main.exp1
-rw-r--r--contrib/bmake/unit-tests/deptgt-main.mk27
-rw-r--r--contrib/bmake/unit-tests/deptgt-makeflags.exp4
-rw-r--r--contrib/bmake/unit-tests/deptgt-makeflags.mk31
-rw-r--r--contrib/bmake/unit-tests/deptgt-notparallel.exp8
-rw-r--r--contrib/bmake/unit-tests/deptgt-notparallel.mk18
-rw-r--r--contrib/bmake/unit-tests/deptgt-order.exp7
-rw-r--r--contrib/bmake/unit-tests/deptgt-order.mk4
-rw-r--r--contrib/bmake/unit-tests/deptgt-path-suffix.exp5
-rw-r--r--contrib/bmake/unit-tests/deptgt-path-suffix.mk10
-rw-r--r--contrib/bmake/unit-tests/deptgt-phony.exp41
-rw-r--r--contrib/bmake/unit-tests/deptgt-phony.mk27
-rw-r--r--contrib/bmake/unit-tests/deptgt-posix.exp (renamed from contrib/bmake/unit-tests/envfirst.exp)0
-rw-r--r--contrib/bmake/unit-tests/deptgt-posix.mk123
-rw-r--r--contrib/bmake/unit-tests/deptgt-silent-jobs.exp7
-rw-r--r--contrib/bmake/unit-tests/deptgt-silent-jobs.mk34
-rw-r--r--contrib/bmake/unit-tests/deptgt.exp19
-rw-r--r--contrib/bmake/unit-tests/deptgt.mk16
-rw-r--r--contrib/bmake/unit-tests/dir.mk8
-rwxr-xr-xcontrib/bmake/unit-tests/directive-dinclude.exp5
-rwxr-xr-xcontrib/bmake/unit-tests/directive-dinclude.mk25
-rw-r--r--contrib/bmake/unit-tests/directive-elif.exp36
-rw-r--r--contrib/bmake/unit-tests/directive-elif.mk25
-rw-r--r--contrib/bmake/unit-tests/directive-elifdef.mk21
-rw-r--r--contrib/bmake/unit-tests/directive-elifndef.mk23
-rw-r--r--contrib/bmake/unit-tests/directive-else.exp16
-rw-r--r--contrib/bmake/unit-tests/directive-else.mk14
-rw-r--r--contrib/bmake/unit-tests/directive-endfor.exp2
-rw-r--r--contrib/bmake/unit-tests/directive-endfor.mk3
-rw-r--r--contrib/bmake/unit-tests/directive-endif.exp10
-rw-r--r--contrib/bmake/unit-tests/directive-endif.mk28
-rw-r--r--contrib/bmake/unit-tests/directive-error.exp2
-rw-r--r--contrib/bmake/unit-tests/directive-error.mk3
-rw-r--r--contrib/bmake/unit-tests/directive-export-gmake.exp7
-rw-r--r--contrib/bmake/unit-tests/directive-export-gmake.mk48
-rw-r--r--contrib/bmake/unit-tests/directive-export-impl.exp24
-rw-r--r--contrib/bmake/unit-tests/directive-export.exp3
-rw-r--r--contrib/bmake/unit-tests/directive-export.mk27
-rw-r--r--contrib/bmake/unit-tests/directive-for-break.exp5
-rw-r--r--contrib/bmake/unit-tests/directive-for-break.mk66
-rw-r--r--contrib/bmake/unit-tests/directive-for-empty.exp27
-rw-r--r--contrib/bmake/unit-tests/directive-for-empty.mk124
-rw-r--r--contrib/bmake/unit-tests/directive-for-errors.exp33
-rw-r--r--contrib/bmake/unit-tests/directive-for-errors.mk57
-rw-r--r--contrib/bmake/unit-tests/directive-for-escape.exp180
-rw-r--r--contrib/bmake/unit-tests/directive-for-escape.mk230
-rwxr-xr-xcontrib/bmake/unit-tests/directive-for-generating-endif.exp8
-rwxr-xr-xcontrib/bmake/unit-tests/directive-for-generating-endif.mk6
-rw-r--r--contrib/bmake/unit-tests/directive-for-if.exp8
-rw-r--r--contrib/bmake/unit-tests/directive-for-if.mk89
-rw-r--r--contrib/bmake/unit-tests/directive-for-lines.exp12
-rw-r--r--contrib/bmake/unit-tests/directive-for-lines.mk12
-rw-r--r--contrib/bmake/unit-tests/directive-for-null.exp2
-rw-r--r--contrib/bmake/unit-tests/directive-for-null.mk10
-rwxr-xr-xcontrib/bmake/unit-tests/directive-for.exp60
-rwxr-xr-xcontrib/bmake/unit-tests/directive-for.mk245
-rwxr-xr-xcontrib/bmake/unit-tests/directive-hyphen-include.exp5
-rwxr-xr-xcontrib/bmake/unit-tests/directive-hyphen-include.mk22
-rw-r--r--contrib/bmake/unit-tests/directive-if.exp29
-rw-r--r--contrib/bmake/unit-tests/directive-if.mk23
-rw-r--r--contrib/bmake/unit-tests/directive-ifdef.exp3
-rw-r--r--contrib/bmake/unit-tests/directive-ifdef.mk44
-rw-r--r--contrib/bmake/unit-tests/directive-ifmake.exp20
-rw-r--r--contrib/bmake/unit-tests/directive-ifmake.mk48
-rw-r--r--contrib/bmake/unit-tests/directive-ifndef.exp2
-rw-r--r--contrib/bmake/unit-tests/directive-ifndef.mk67
-rwxr-xr-xcontrib/bmake/unit-tests/directive-include-fatal.exp2
-rwxr-xr-xcontrib/bmake/unit-tests/directive-include-fatal.mk3
-rw-r--r--contrib/bmake/unit-tests/directive-include-guard.exp104
-rw-r--r--contrib/bmake/unit-tests/directive-include-guard.mk638
-rwxr-xr-xcontrib/bmake/unit-tests/directive-include.exp11
-rwxr-xr-xcontrib/bmake/unit-tests/directive-include.mk59
-rw-r--r--contrib/bmake/unit-tests/directive-info.exp24
-rw-r--r--contrib/bmake/unit-tests/directive-info.mk32
-rw-r--r--contrib/bmake/unit-tests/directive-misspellings.exp84
-rw-r--r--contrib/bmake/unit-tests/directive-misspellings.mk46
-rwxr-xr-xcontrib/bmake/unit-tests/directive-sinclude.exp5
-rwxr-xr-xcontrib/bmake/unit-tests/directive-sinclude.mk18
-rw-r--r--contrib/bmake/unit-tests/directive-undef.exp6
-rw-r--r--contrib/bmake/unit-tests/directive-undef.mk49
-rw-r--r--contrib/bmake/unit-tests/directive-unexport-env.exp8
-rw-r--r--contrib/bmake/unit-tests/directive-unexport-env.mk8
-rw-r--r--contrib/bmake/unit-tests/directive-unexport.exp8
-rw-r--r--contrib/bmake/unit-tests/directive-unexport.mk5
-rw-r--r--contrib/bmake/unit-tests/directive-warning.exp12
-rw-r--r--contrib/bmake/unit-tests/directive-warning.mk16
-rw-r--r--contrib/bmake/unit-tests/directive.exp12
-rw-r--r--contrib/bmake/unit-tests/directive.mk22
-rw-r--r--contrib/bmake/unit-tests/doterror.mk3
-rw-r--r--contrib/bmake/unit-tests/envfirst.mk44
-rw-r--r--contrib/bmake/unit-tests/error.exp6
-rw-r--r--contrib/bmake/unit-tests/error.mk5
-rw-r--r--contrib/bmake/unit-tests/escape.exp36
-rw-r--r--contrib/bmake/unit-tests/escape.mk7
-rw-r--r--contrib/bmake/unit-tests/export-env.mk6
-rw-r--r--contrib/bmake/unit-tests/export.exp2
-rw-r--r--contrib/bmake/unit-tests/export.mk4
-rw-r--r--contrib/bmake/unit-tests/forloop.exp20
-rw-r--r--contrib/bmake/unit-tests/forloop.mk53
-rw-r--r--contrib/bmake/unit-tests/forsubst.exp2
-rw-r--r--contrib/bmake/unit-tests/forsubst.mk22
-rw-r--r--contrib/bmake/unit-tests/hanoi-include.mk40
-rw-r--r--contrib/bmake/unit-tests/include-main.exp30
-rw-r--r--contrib/bmake/unit-tests/include-main.mk10
-rw-r--r--contrib/bmake/unit-tests/include-sub.inc (renamed from contrib/bmake/unit-tests/include-sub.mk)12
-rw-r--r--contrib/bmake/unit-tests/include-subsub.inc9
-rw-r--r--contrib/bmake/unit-tests/include-subsub.mk9
-rw-r--r--contrib/bmake/unit-tests/job-output-null.exp8
-rw-r--r--contrib/bmake/unit-tests/job-output-null.mk49
-rw-r--r--contrib/bmake/unit-tests/jobs-error-indirect.exp2
-rw-r--r--contrib/bmake/unit-tests/jobs-error-nested-make.exp2
-rw-r--r--contrib/bmake/unit-tests/jobs-error-nested.exp4
-rwxr-xr-xcontrib/bmake/unit-tests/lint.exp2
-rwxr-xr-xcontrib/bmake/unit-tests/lint.mk4
-rwxr-xr-xcontrib/bmake/unit-tests/make-exported.mk4
-rw-r--r--contrib/bmake/unit-tests/meta-cmd-cmp.exp16
-rw-r--r--contrib/bmake/unit-tests/meta-cmd-cmp.mk40
-rw-r--r--contrib/bmake/unit-tests/meta-ignore.inc63
-rw-r--r--contrib/bmake/unit-tests/moderrs.exp20
-rw-r--r--contrib/bmake/unit-tests/moderrs.mk6
-rw-r--r--contrib/bmake/unit-tests/modmatch.exp17
-rw-r--r--contrib/bmake/unit-tests/modmatch.mk30
-rw-r--r--contrib/bmake/unit-tests/modmisc.exp1
-rw-r--r--contrib/bmake/unit-tests/modmisc.mk10
-rw-r--r--contrib/bmake/unit-tests/modts.exp14
-rw-r--r--contrib/bmake/unit-tests/modts.mk47
-rw-r--r--contrib/bmake/unit-tests/modword.exp126
-rw-r--r--contrib/bmake/unit-tests/modword.mk161
-rw-r--r--contrib/bmake/unit-tests/objdir-writable.exp8
-rw-r--r--contrib/bmake/unit-tests/objdir-writable.mk15
-rw-r--r--contrib/bmake/unit-tests/opt-debug-cond.exp5
-rw-r--r--contrib/bmake/unit-tests/opt-debug-cond.mk22
-rw-r--r--contrib/bmake/unit-tests/opt-debug-curdir.mk10
-rw-r--r--contrib/bmake/unit-tests/opt-debug-errors-jobs.exp10
-rw-r--r--contrib/bmake/unit-tests/opt-debug-errors-jobs.mk14
-rw-r--r--contrib/bmake/unit-tests/opt-debug-file.exp13
-rw-r--r--contrib/bmake/unit-tests/opt-debug-file.mk53
-rw-r--r--contrib/bmake/unit-tests/opt-debug-for.exp12
-rw-r--r--contrib/bmake/unit-tests/opt-debug-graph1.exp12
-rw-r--r--contrib/bmake/unit-tests/opt-debug-graph2.exp10
-rw-r--r--contrib/bmake/unit-tests/opt-debug-graph3.exp10
-rw-r--r--contrib/bmake/unit-tests/opt-debug-hash.exp7
-rw-r--r--contrib/bmake/unit-tests/opt-debug-hash.mk10
-rw-r--r--contrib/bmake/unit-tests/opt-debug-jobs.mk4
-rw-r--r--contrib/bmake/unit-tests/opt-debug-lint.exp12
-rw-r--r--contrib/bmake/unit-tests/opt-debug-lint.mk13
-rw-r--r--contrib/bmake/unit-tests/opt-debug-loud.mk6
-rw-r--r--contrib/bmake/unit-tests/opt-debug-parse.exp25
-rw-r--r--contrib/bmake/unit-tests/opt-debug-parse.mk37
-rw-r--r--contrib/bmake/unit-tests/opt-debug-var.exp6
-rw-r--r--contrib/bmake/unit-tests/opt-debug-var.mk30
-rw-r--r--contrib/bmake/unit-tests/opt-debug-x-trace.exp2
-rw-r--r--contrib/bmake/unit-tests/opt-debug-x-trace.mk10
-rw-r--r--contrib/bmake/unit-tests/opt-define.mk42
-rw-r--r--contrib/bmake/unit-tests/opt-env.mk51
-rw-r--r--contrib/bmake/unit-tests/opt-file.mk16
-rw-r--r--contrib/bmake/unit-tests/opt-jobs-internal.exp7
-rw-r--r--contrib/bmake/unit-tests/opt-jobs-internal.mk11
-rw-r--r--contrib/bmake/unit-tests/opt-jobs-no-action.mk4
-rw-r--r--contrib/bmake/unit-tests/opt-jobs.mk56
-rw-r--r--contrib/bmake/unit-tests/opt-keep-going-indirect.exp32
-rw-r--r--contrib/bmake/unit-tests/opt-keep-going-indirect.mk90
-rw-r--r--contrib/bmake/unit-tests/opt-query.exp24
-rw-r--r--contrib/bmake/unit-tests/opt-query.mk69
-rw-r--r--contrib/bmake/unit-tests/opt-raw.mk16
-rw-r--r--contrib/bmake/unit-tests/opt-silent.exp2
-rw-r--r--contrib/bmake/unit-tests/opt-silent.mk8
-rw-r--r--contrib/bmake/unit-tests/opt-tracefile.exp11
-rw-r--r--contrib/bmake/unit-tests/opt-tracefile.mk18
-rw-r--r--contrib/bmake/unit-tests/opt-version.exp2
-rw-r--r--contrib/bmake/unit-tests/opt-version.mk12
-rw-r--r--contrib/bmake/unit-tests/opt-warnings-as-errors.exp4
-rw-r--r--contrib/bmake/unit-tests/opt-warnings-as-errors.mk4
-rw-r--r--contrib/bmake/unit-tests/opt-where-am-i.exp3
-rw-r--r--contrib/bmake/unit-tests/opt-where-am-i.mk14
-rw-r--r--contrib/bmake/unit-tests/opt-x-reduce-exported.exp4
-rw-r--r--contrib/bmake/unit-tests/opt-x-reduce-exported.mk22
-rw-r--r--contrib/bmake/unit-tests/opt.mk4
-rw-r--r--contrib/bmake/unit-tests/parse-var.mk126
-rw-r--r--contrib/bmake/unit-tests/parse.exp6
-rw-r--r--contrib/bmake/unit-tests/parse.mk55
-rw-r--r--contrib/bmake/unit-tests/posix.mk7
-rw-r--r--contrib/bmake/unit-tests/recursive.exp4
-rw-r--r--contrib/bmake/unit-tests/recursive.mk17
-rwxr-xr-xcontrib/bmake/unit-tests/sh-dots.mk6
-rw-r--r--contrib/bmake/unit-tests/sh-flags.exp72
-rw-r--r--contrib/bmake/unit-tests/sh-leading-at.exp1
-rw-r--r--contrib/bmake/unit-tests/sh-leading-at.mk6
-rw-r--r--contrib/bmake/unit-tests/sh-leading-hyphen.exp10
-rw-r--r--contrib/bmake/unit-tests/sh-leading-hyphen.mk19
-rw-r--r--contrib/bmake/unit-tests/sh-leading-plus.exp2
-rw-r--r--contrib/bmake/unit-tests/sh-leading-plus.mk6
-rw-r--r--contrib/bmake/unit-tests/sh.mk5
-rw-r--r--contrib/bmake/unit-tests/shell-sh.mk4
-rw-r--r--contrib/bmake/unit-tests/suff-incomplete.exp12
-rw-r--r--contrib/bmake/unit-tests/suff-main-several.exp42
-rw-r--r--contrib/bmake/unit-tests/suff-rebuild.exp22
-rw-r--r--contrib/bmake/unit-tests/suff-transform-debug.exp12
-rw-r--r--contrib/bmake/unit-tests/suff-use.exp7
-rw-r--r--contrib/bmake/unit-tests/suff-use.mk50
-rw-r--r--contrib/bmake/unit-tests/unexport.mk4
-rw-r--r--contrib/bmake/unit-tests/var-class-cmdline.exp4
-rw-r--r--contrib/bmake/unit-tests/var-class-global.mk8
-rw-r--r--contrib/bmake/unit-tests/var-class-local-legacy.mk8
-rw-r--r--contrib/bmake/unit-tests/var-class-local.exp5
-rw-r--r--contrib/bmake/unit-tests/var-class-local.mk45
-rw-r--r--contrib/bmake/unit-tests/var-class.mk9
-rw-r--r--contrib/bmake/unit-tests/var-eval-short.exp16
-rw-r--r--contrib/bmake/unit-tests/var-eval-short.mk39
-rw-r--r--contrib/bmake/unit-tests/var-op-append.mk50
-rw-r--r--contrib/bmake/unit-tests/var-op-assign.exp4
-rw-r--r--contrib/bmake/unit-tests/var-op-assign.mk6
-rw-r--r--contrib/bmake/unit-tests/var-op-default.mk8
-rw-r--r--contrib/bmake/unit-tests/var-op-expand.exp8
-rw-r--r--contrib/bmake/unit-tests/var-op-expand.mk124
-rw-r--r--contrib/bmake/unit-tests/var-op-shell.exp12
-rw-r--r--contrib/bmake/unit-tests/var-op-shell.mk37
-rw-r--r--contrib/bmake/unit-tests/var-op-sunsh.mk47
-rw-r--r--contrib/bmake/unit-tests/var-readonly.exp4
-rw-r--r--contrib/bmake/unit-tests/var-readonly.mk27
-rw-r--r--contrib/bmake/unit-tests/var-recursive.exp17
-rw-r--r--contrib/bmake/unit-tests/var-recursive.mk20
-rw-r--r--contrib/bmake/unit-tests/var-scope-cmdline.exp4
-rw-r--r--contrib/bmake/unit-tests/var-scope-cmdline.mk (renamed from contrib/bmake/unit-tests/var-class-cmdline.mk)10
-rw-r--r--contrib/bmake/unit-tests/var-scope-env.exp (renamed from contrib/bmake/unit-tests/var-class-env.exp)0
-rw-r--r--contrib/bmake/unit-tests/var-scope-env.mk (renamed from contrib/bmake/unit-tests/var-class-env.mk)2
-rw-r--r--contrib/bmake/unit-tests/var-scope-global.exp (renamed from contrib/bmake/unit-tests/var-class-global.exp)0
-rw-r--r--contrib/bmake/unit-tests/var-scope-global.mk18
-rw-r--r--contrib/bmake/unit-tests/var-scope-local-legacy.exp6
-rw-r--r--contrib/bmake/unit-tests/var-scope-local-legacy.mk35
-rw-r--r--contrib/bmake/unit-tests/var-scope-local.exp71
-rw-r--r--contrib/bmake/unit-tests/var-scope-local.mk270
-rw-r--r--contrib/bmake/unit-tests/var-scope.exp (renamed from contrib/bmake/unit-tests/var-class-local-legacy.exp)0
-rw-r--r--contrib/bmake/unit-tests/var-scope.mk9
-rw-r--r--contrib/bmake/unit-tests/varcmd.mk6
-rw-r--r--contrib/bmake/unit-tests/vardebug.exp30
-rw-r--r--contrib/bmake/unit-tests/vardebug.mk32
-rw-r--r--contrib/bmake/unit-tests/varmisc.exp5
-rw-r--r--contrib/bmake/unit-tests/varmisc.mk34
-rw-r--r--contrib/bmake/unit-tests/varmod-assign-shell.exp14
-rw-r--r--contrib/bmake/unit-tests/varmod-assign-shell.mk37
-rw-r--r--contrib/bmake/unit-tests/varmod-assign.exp44
-rw-r--r--contrib/bmake/unit-tests/varmod-assign.mk169
-rw-r--r--contrib/bmake/unit-tests/varmod-defined.exp8
-rw-r--r--contrib/bmake/unit-tests/varmod-defined.mk23
-rw-r--r--contrib/bmake/unit-tests/varmod-edge.exp44
-rw-r--r--contrib/bmake/unit-tests/varmod-edge.mk29
-rw-r--r--contrib/bmake/unit-tests/varmod-gmtime.exp20
-rw-r--r--contrib/bmake/unit-tests/varmod-gmtime.mk83
-rw-r--r--contrib/bmake/unit-tests/varmod-head.exp10
-rw-r--r--contrib/bmake/unit-tests/varmod-head.mk65
-rw-r--r--contrib/bmake/unit-tests/varmod-ifelse.exp73
-rw-r--r--contrib/bmake/unit-tests/varmod-ifelse.mk166
-rw-r--r--contrib/bmake/unit-tests/varmod-indirect.exp36
-rw-r--r--contrib/bmake/unit-tests/varmod-indirect.mk65
-rw-r--r--contrib/bmake/unit-tests/varmod-l-name-to-value.mk4
-rw-r--r--contrib/bmake/unit-tests/varmod-localtime.exp20
-rw-r--r--contrib/bmake/unit-tests/varmod-localtime.mk45
-rw-r--r--contrib/bmake/unit-tests/varmod-loop-delete.exp4
-rw-r--r--contrib/bmake/unit-tests/varmod-loop-delete.mk34
-rw-r--r--contrib/bmake/unit-tests/varmod-loop-varname.exp16
-rw-r--r--contrib/bmake/unit-tests/varmod-loop-varname.mk17
-rw-r--r--contrib/bmake/unit-tests/varmod-loop.exp16
-rw-r--r--contrib/bmake/unit-tests/varmod-loop.mk73
-rwxr-xr-xcontrib/bmake/unit-tests/varmod-match-escape.exp10
-rwxr-xr-xcontrib/bmake/unit-tests/varmod-match-escape.mk55
-rw-r--r--contrib/bmake/unit-tests/varmod-match.exp26
-rw-r--r--contrib/bmake/unit-tests/varmod-match.mk356
-rw-r--r--contrib/bmake/unit-tests/varmod-mtime.exp14
-rw-r--r--contrib/bmake/unit-tests/varmod-mtime.mk125
-rw-r--r--contrib/bmake/unit-tests/varmod-no-match.mk98
-rw-r--r--contrib/bmake/unit-tests/varmod-order-numeric.exp (renamed from contrib/bmake/unit-tests/var-class.exp)0
-rw-r--r--contrib/bmake/unit-tests/varmod-order-numeric.mk59
-rw-r--r--contrib/bmake/unit-tests/varmod-order-reverse.mk9
-rw-r--r--contrib/bmake/unit-tests/varmod-order-shuffle.mk24
-rw-r--r--contrib/bmake/unit-tests/varmod-order-string.exp1
-rw-r--r--contrib/bmake/unit-tests/varmod-order-string.mk28
-rw-r--r--contrib/bmake/unit-tests/varmod-order.exp27
-rw-r--r--contrib/bmake/unit-tests/varmod-order.mk116
-rw-r--r--contrib/bmake/unit-tests/varmod-path.mk14
-rw-r--r--contrib/bmake/unit-tests/varmod-quote-dollar.exp3
-rw-r--r--contrib/bmake/unit-tests/varmod-quote-dollar.mk13
-rw-r--r--contrib/bmake/unit-tests/varmod-range.exp21
-rw-r--r--contrib/bmake/unit-tests/varmod-range.mk36
-rw-r--r--contrib/bmake/unit-tests/varmod-remember.mk69
-rw-r--r--contrib/bmake/unit-tests/varmod-root.exp10
-rw-r--r--contrib/bmake/unit-tests/varmod-root.mk37
-rw-r--r--contrib/bmake/unit-tests/varmod-select-words.exp125
-rw-r--r--contrib/bmake/unit-tests/varmod-select-words.mk165
-rw-r--r--contrib/bmake/unit-tests/varmod-shell.exp10
-rw-r--r--contrib/bmake/unit-tests/varmod-shell.mk10
-rw-r--r--contrib/bmake/unit-tests/varmod-subst-regex.mk57
-rw-r--r--contrib/bmake/unit-tests/varmod-subst.mk139
-rw-r--r--contrib/bmake/unit-tests/varmod-sun-shell.exp11
-rw-r--r--contrib/bmake/unit-tests/varmod-sun-shell.mk7
-rw-r--r--contrib/bmake/unit-tests/varmod-sysv.exp2
-rw-r--r--contrib/bmake/unit-tests/varmod-sysv.mk11
-rw-r--r--contrib/bmake/unit-tests/varmod-to-abs.exp4
-rw-r--r--contrib/bmake/unit-tests/varmod-to-abs.mk5
-rw-r--r--contrib/bmake/unit-tests/varmod-to-lower.mk15
-rw-r--r--contrib/bmake/unit-tests/varmod-to-separator.exp26
-rw-r--r--contrib/bmake/unit-tests/varmod-to-separator.mk107
-rw-r--r--contrib/bmake/unit-tests/varmod-undefined.mk8
-rw-r--r--contrib/bmake/unit-tests/varmod-unique.mk35
-rw-r--r--contrib/bmake/unit-tests/varmod.exp10
-rw-r--r--contrib/bmake/unit-tests/varmod.mk68
-rw-r--r--contrib/bmake/unit-tests/varname-dollar.exp8
-rw-r--r--contrib/bmake/unit-tests/varname-dollar.mk6
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-jobs.exp7
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-jobs.mk43
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp10
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk7
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp10
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk7
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp10
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk7
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-mode.exp30
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-mode.mk41
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-pid.mk18
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-ppid.mk25
-rw-r--r--contrib/bmake/unit-tests/varname-dot-make-save_dollars.mk130
-rw-r--r--contrib/bmake/unit-tests/varname-dot-makeflags.exp11
-rw-r--r--contrib/bmake/unit-tests/varname-dot-makeflags.mk42
-rw-r--r--contrib/bmake/unit-tests/varname-dot-makeoverrides.exp7
-rw-r--r--contrib/bmake/unit-tests/varname-dot-makeoverrides.mk25
-rw-r--r--contrib/bmake/unit-tests/varname-dot-newline.exp3
-rw-r--r--contrib/bmake/unit-tests/varname-dot-newline.mk32
-rw-r--r--contrib/bmake/unit-tests/varname-dot-parsedir.exp6
-rw-r--r--contrib/bmake/unit-tests/varname-dot-parsedir.mk12
-rw-r--r--contrib/bmake/unit-tests/varname-dot-parsefile.exp6
-rw-r--r--contrib/bmake/unit-tests/varname-dot-parsefile.mk12
-rwxr-xr-xcontrib/bmake/unit-tests/varname-dot-shell.exp30
-rw-r--r--contrib/bmake/unit-tests/varname-dot-suffixes.exp39
-rw-r--r--contrib/bmake/unit-tests/varname-dot-suffixes.mk105
-rw-r--r--contrib/bmake/unit-tests/varname-empty.exp31
-rwxr-xr-xcontrib/bmake/unit-tests/varname-empty.mk4
-rw-r--r--contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk4
-rw-r--r--contrib/bmake/unit-tests/varname-makeflags.exp20
-rw-r--r--contrib/bmake/unit-tests/varname-makeflags.mk188
-rw-r--r--contrib/bmake/unit-tests/varname.exp6
-rw-r--r--contrib/bmake/unit-tests/varname.mk49
-rw-r--r--contrib/bmake/unit-tests/varparse-dynamic.exp4
-rw-r--r--contrib/bmake/unit-tests/varparse-dynamic.mk11
-rw-r--r--contrib/bmake/unit-tests/varparse-errors.exp22
-rw-r--r--contrib/bmake/unit-tests/varparse-errors.mk52
-rw-r--r--contrib/bmake/unit-tests/varparse-mod.mk6
-rw-r--r--contrib/bmake/unit-tests/varparse-undef-partial.mk13
-rw-r--r--contrib/bmake/unit-tests/varquote.exp3
-rw-r--r--contrib/bmake/unit-tests/varquote.mk14
455 files changed, 10210 insertions, 3081 deletions
diff --git a/contrib/bmake/unit-tests/Makefile b/contrib/bmake/unit-tests/Makefile
index 784223a56652..6c41bf811dcf 100644
--- a/contrib/bmake/unit-tests/Makefile
+++ b/contrib/bmake/unit-tests/Makefile
@@ -1,6 +1,6 @@
-# $Id: Makefile,v 1.148 2021/06/16 19:18:56 sjg Exp $
+# $Id: Makefile,v 1.211 2024/03/10 17:46:44 sjg Exp $
#
-# $NetBSD: Makefile,v 1.279 2021/06/16 09:39:48 rillig Exp $
+# $NetBSD: Makefile,v 1.342 2024/01/07 02:07:44 sjg Exp $
#
# Unit tests for make(1)
#
@@ -25,10 +25,6 @@
# named makefile (*.mk), with its own set of expected results (*.exp),
# and it should be added to the TESTS list.
#
-# A few *.mk files are helper files for other tests (such as include-sub.mk)
-# and are thus not added to TESTS. Such files must be ignored in
-# src/tests/usr.bin/make/t_make.sh.
-#
.MAIN: all
@@ -36,6 +32,21 @@
.MAKE.OS?= ${uname -s:L:sh}
.MAKE.UID?= ${id -u:L:sh}
+# for many tests we need a TMPDIR that will not collide
+# with other users.
+.if ${.OBJDIR} != ${.CURDIR}
+# easy
+TMPDIR:= ${.OBJDIR}/tmp
+.elif defined(TMPDIR)
+TMPDIR:= ${TMPDIR}/uid${.MAKE.UID}
+.else
+TMPDIR:= /tmp/uid${.MAKE.UID}
+.endif
+# make sure it exists
+.if !exist(${TMPDIR})
+_!= mkdir -p ${TMPDIR}
+.endif
+
# Each test is in a sub-makefile.
# Keep the list sorted.
# Any test that is commented out must be ignored in
@@ -83,7 +94,6 @@ TESTS+= cond-token-plain
TESTS+= cond-token-string
TESTS+= cond-token-var
TESTS+= cond-undef-lint
-TESTS+= cond1
TESTS+= counter
TESTS+= counter-append
TESTS+= dep
@@ -91,8 +101,10 @@ TESTS+= dep-colon
TESTS+= dep-colon-bug-cross-file
TESTS+= dep-double-colon
TESTS+= dep-double-colon-indep
+TESTS+= dep-duplicate
TESTS+= dep-exclam
TESTS+= dep-none
+TESTS+= dep-op-missing
TESTS+= dep-percent
TESTS+= dep-var
TESTS+= dep-wildcards
@@ -140,9 +152,11 @@ TESTS+= deptgt-order
TESTS+= deptgt-path
TESTS+= deptgt-path-suffix
TESTS+= deptgt-phony
+TESTS+= deptgt-posix
TESTS+= deptgt-precious
TESTS+= deptgt-shell
TESTS+= deptgt-silent
+TESTS+= deptgt-silent-jobs
TESTS+= deptgt-stale
TESTS+= deptgt-suffixes
TESTS+= dir
@@ -164,9 +178,12 @@ TESTS+= directive-export-impl
TESTS+= directive-export-gmake
TESTS+= directive-export-literal
TESTS+= directive-for
+TESTS+= directive-for-break
+TESTS+= directive-for-empty
TESTS+= directive-for-errors
TESTS+= directive-for-escape
TESTS+= directive-for-generating-endif
+TESTS+= directive-for-if
TESTS+= directive-for-lines
TESTS+= directive-for-null
TESTS+= directive-hyphen-include
@@ -178,6 +195,7 @@ TESTS+= directive-ifndef
TESTS+= directive-ifnmake
TESTS+= directive-include
TESTS+= directive-include-fatal
+TESTS+= directive-include-guard
TESTS+= directive-info
TESTS+= directive-misspellings
TESTS+= directive-sinclude
@@ -188,21 +206,18 @@ TESTS+= directive-warning
TESTS+= dollar
TESTS+= doterror
TESTS+= dotwait
-TESTS+= envfirst
TESTS+= error
TESTS+= # escape # broken by reverting POSIX changes
TESTS+= export
TESTS+= export-all
TESTS+= export-env
TESTS+= export-variants
-TESTS+= forloop
-TESTS+= forsubst
TESTS+= gnode-submake
TESTS+= hanoi-include
TESTS+= impsrc
TESTS+= include-main
TESTS+= job-flags
-#TESTS+= job-output-long-lines
+TESTS+= job-output-long-lines
TESTS+= job-output-null
TESTS+= jobs-empty-commands
TESTS+= jobs-empty-commands-error
@@ -213,10 +228,7 @@ TESTS+= lint
TESTS+= make-exported
TESTS+= meta-cmd-cmp
TESTS+= moderrs
-TESTS+= modmatch
TESTS+= modmisc
-TESTS+= modts
-TESTS+= modword
.if ${.MAKE.UID} > 0
TESTS+= objdir-writable
.endif
@@ -237,7 +249,7 @@ TESTS+= opt-debug-graph1
TESTS+= opt-debug-graph2
TESTS+= opt-debug-graph3
TESTS+= opt-debug-hash
-#TESTS+= opt-debug-jobs
+TESTS+= opt-debug-jobs
TESTS+= opt-debug-lint
TESTS+= opt-debug-loud
TESTS+= opt-debug-meta
@@ -258,6 +270,7 @@ TESTS+= opt-jobs
TESTS+= opt-jobs-internal
TESTS+= opt-jobs-no-action
TESTS+= opt-keep-going
+TESTS+= opt-keep-going-indirect
TESTS+= opt-keep-going-multiple
TESTS+= opt-m-include-dir
TESTS+= opt-no-action
@@ -272,10 +285,12 @@ TESTS+= opt-touch-jobs
TESTS+= opt-tracefile
TESTS+= opt-var-expanded
TESTS+= opt-var-literal
+TESTS+= opt-version
TESTS+= opt-warnings-as-errors
TESTS+= opt-where-am-i
TESTS+= opt-x-reduce-exported
TESTS+= order
+TESTS+= parse
TESTS+= parse-var
TESTS+= phony-end
TESTS+= posix
@@ -313,17 +328,19 @@ TESTS+= suff-transform-debug
TESTS+= suff-transform-endless
TESTS+= suff-transform-expand
TESTS+= suff-transform-select
+TESTS+= suff-use
TESTS+= sunshcmd
TESTS+= ternary
TESTS+= unexport
TESTS+= unexport-env
TESTS+= use-inference
-TESTS+= var-class
-TESTS+= var-class-cmdline
-TESTS+= var-class-env
-TESTS+= var-class-global
-TESTS+= var-class-local
-TESTS+= var-class-local-legacy
+TESTS+= var-readonly
+TESTS+= var-scope
+TESTS+= var-scope-cmdline
+TESTS+= var-scope-env
+TESTS+= var-scope-global
+TESTS+= var-scope-local
+TESTS+= var-scope-local-legacy
TESTS+= var-eval-short
TESTS+= var-op
TESTS+= var-op-append
@@ -339,6 +356,7 @@ TESTS+= varfind
TESTS+= varmisc
TESTS+= varmod
TESTS+= varmod-assign
+TESTS+= varmod-assign-shell
TESTS+= varmod-defined
TESTS+= varmod-edge
TESTS+= varmod-exclam-shell
@@ -351,13 +369,17 @@ TESTS+= varmod-indirect
TESTS+= varmod-l-name-to-value
TESTS+= varmod-localtime
TESTS+= varmod-loop
+TESTS+= varmod-loop-delete
TESTS+= varmod-loop-varname
TESTS+= varmod-match
TESTS+= varmod-match-escape
+TESTS+= varmod-mtime
TESTS+= varmod-no-match
TESTS+= varmod-order
+TESTS+= varmod-order-numeric
TESTS+= varmod-order-reverse
TESTS+= varmod-order-shuffle
+TESTS+= varmod-order-string
TESTS+= varmod-path
TESTS+= varmod-quote
TESTS+= varmod-quote-dollar
@@ -398,12 +420,20 @@ TESTS+= varname-dot-make-makefiles
TESTS+= varname-dot-make-meta-bailiwick
TESTS+= varname-dot-make-meta-created
TESTS+= varname-dot-make-meta-files
+.if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != ""
+# these tests will not work if TMPDIR is or is a subdir of
+# /tmp or /var/tmp
+.if ${.MAKE.PATH_FILEMON:N/dev/*} != "" || exists(${.MAKE.PATH_FILEMON})
TESTS+= varname-dot-make-meta-ignore_filter
TESTS+= varname-dot-make-meta-ignore_paths
TESTS+= varname-dot-make-meta-ignore_patterns
+TESTS+= varname-dot-make-path_filemon
+.else
+.warning Skipping tests that require ${.MAKE.PATH_FILEMON}
+.endif
+.endif
TESTS+= varname-dot-make-meta-prefix
TESTS+= varname-dot-make-mode
-TESTS+= varname-dot-make-path_filemon
TESTS+= varname-dot-make-pid
TESTS+= varname-dot-make-ppid
TESTS+= varname-dot-make-save_dollars
@@ -415,6 +445,7 @@ TESTS+= varname-dot-parsedir
TESTS+= varname-dot-parsefile
TESTS+= varname-dot-path
TESTS+= varname-dot-shell
+TESTS+= varname-dot-suffixes
TESTS+= varname-dot-targets
TESTS+= varname-empty
TESTS+= varname-make
@@ -428,14 +459,73 @@ TESTS+= varparse-dynamic
TESTS+= varparse-errors
TESTS+= varparse-mod
TESTS+= varparse-undef-partial
-TESTS+= varquote
+
+# some shells have quirks
+_shell := ${.SHELL:tA:T}
+.if ${_shell} == "dash"
+# dash fails -x output
+BROKEN_TESTS+= opt-debug-x-trace
+.elif ${_shell} == "ksh"
+BROKEN_TESTS+= sh-flags
+.endif
+
+.if ${UTC_1:Uno} == ""
+# this will not work if UTC_1 is set empty
+BROKEN_TESTS+= varmod-localtime
+.endif
+
+.if ${.MAKE.OS:NCYGWIN*} == ""
+BROKEN_TESTS+= \
+ export \
+ opt-chdir \
+ opt-keep-going-indirect \
+
+.endif
+
+
+.if ${.MAKE.OS:NDarwin} == ""
+BROKEN_TESTS+= shell-ksh
+.endif
+
+.if ${.MAKE.OS:MIRIX*} != ""
+BROKEN_TESTS+= \
+ cmd-interrupt \
+ deptgt-interrupt \
+ job-output-null \
+ opt-chdir \
+ opt-debug-x-trace \
+ sh-leading-hyphen \
+
+.endif
+
+.if ${.MAKE.OS} == "SCO_SV"
+BROKEN_TESTS+= \
+ opt-debug-graph[23] \
+ varmod-localtime \
+ varmod-to-separator \
+
+.if ${_shell} == "bash"
+BROKEN_TESTS+= job-output-null
+.else
+BROKEN_TESTS+= \
+ cmd-interrupt \
+ job-flags \
+
+.endif
+.endif
+
+# Some tests just do not work on some platforms or environments
+# so allow for some filtering.
+.if !empty(BROKEN_TESTS)
+.warning Skipping broken tests: ${BROKEN_TESTS:O:u}
+TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
+.endif
# Ideas for more tests:
# char-0020-space.mk
# char-005C-backslash.mk
# escape-cond-str.mk
# escape-cond-func-arg.mk
-# escape-cond-func-arg.mk
# escape-varmod.mk
# escape-varmod-define.mk
# escape-varmod-match.mk
@@ -453,18 +543,20 @@ TESTS+= varquote
# Additional environment variables for some of the tests.
# The base environment is -i PATH="$PATH".
ENV.depsrc-optional+= TZ=UTC
-ENV.envfirst= FROM_ENV=value-from-env
+ENV.deptgt-phony+= MAKESYSPATH=.
+ENV.directive-undef= ENV_VAR=env-value
+ENV.opt-env= FROM_ENV=value-from-env
+ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}}
ENV.varmisc= FROM_ENV=env
ENV.varmisc+= FROM_ENV_BEFORE=env
ENV.varmisc+= FROM_ENV_AFTER=env
-ENV.varmod-localtime+= TZ=Europe/Berlin
+ENV.varmod-localtime+= TZ=${UTC_1:UEurope/Berlin}
ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
# Override make flags for some of the tests; default is -k.
# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
# settings FLAGS.test=-dv here, since that is closer to the test code.
FLAGS.cond-func-make= via-cmdline
-FLAGS.directive-ifmake= first second
FLAGS.doterror= # none, especially not -k
FLAGS.jobs-error-indirect= # none, especially not -k
FLAGS.jobs-error-nested= # none, especially not -k
@@ -472,9 +564,14 @@ FLAGS.jobs-error-nested-make= # none, especially not -k
FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
# Some tests need extra postprocessing.
-SED_CMDS.dir= ${:D remove output from -DCLEANUP mode }
-SED_CMDS.dir+= -e '/^OpenDirs_Done:/d'
-SED_CMDS.dir+= -e '/^CachedDir /d'
+SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd}
+SED_CMDS.dir= ${STD_SED_CMDS.dd}
+SED_CMDS.directive-include-guard= \
+ -e '/\.MAKEFLAGS/d' \
+ -e '/^Parsing line/d' \
+ -e '/^SetFilenameVars:/d' \
+ -e '/^ParseDependency/d' \
+ -e '/^ParseEOF:/d'
SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
SED_CMDS.export-all= ${SED_CMDS.export}
SED_CMDS.export-env= ${SED_CMDS.export}
@@ -490,10 +587,17 @@ SED_CMDS.job-output-long-lines= \
${:D marker should always be at the beginning of the line. } \
-e '/^aa*--- job-b ---$$/d' \
-e '/^bb*--- job-a ---$$/d'
-SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,'
+SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' \
+ -e '/name/s,file,File,' \
+ -e 's,no such,No such,' \
+ -e 's,Filename,File name,'
+
+# meta line numbers can vary based on filemon implementation
+SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,'
SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2}
SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3}
+SED_CMDS.opt-debug-hash= -e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,'
SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
@@ -504,6 +608,7 @@ SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex}
SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
+SED_CMDS.opt-where-am-i= -e '/usr.obj/d'
# For Compat_RunCommand, useShell == false.
SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
# For Compat_RunCommand, useShell == true.
@@ -511,25 +616,33 @@ SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
+SED_CMDS.shell-csh= ${STD_SED_CMDS.white-space}
+SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell}
SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
+SED_CMDS.var-op-shell+= ${STD_SED_CMDS.white-space}
SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
+SED_CMDS.varmod-mtime+= -e "s,': .*,': <ENOENT>,"
SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex}
+SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp}
+SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
+SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore}
+SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore}
SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
-SED_CMDS.varname-empty= -e 's,${.CURDIR},<curdir>,g'
-SED_CMDS.varname-empty+= -e '/\.PARSEDIR/d'
-SED_CMDS.varname-empty+= -e '/\.SHELL/d'
+SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
# Some tests need an additional round of postprocessing.
+POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/'
POSTPROC.gnode-submake= awk '/Input graph/, /^$$/'
+POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,'
# Some tests reuse other tests, which makes them unnecessarily fragile.
export-all.rawout: export.mk
@@ -540,16 +653,23 @@ unexport-env.rawout: export.mk
# Some standard sed commands, to be used in the SED_CMDS above.
+# In tests that use the debugging option -dd, ignore debugging output that is
+# only logged in -DCLEANUP mode.
+STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d'
+STD_SED_CMDS.dd+= -e '/^CachedDir /d'
+
# Omit details such as process IDs from the output of the -dg1 option.
-STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,'
+STD_SED_CMDS.dg1= -e '/\#.* \.$$/d'
STD_SED_CMDS.dg1+= -e '/\.MAKE.PATH_FILEMON/d'
-STD_SED_CMDS.dg1+= -e '/^MAKE_VERSION/d;/^\#.*\/mk/d'
+STD_SED_CMDS.dg1+= -e '/^\#.*\/mk/d'
STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,'
STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
+STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,'
STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
+STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d'
STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1}
STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
@@ -593,15 +713,24 @@ STD_SED_CMDS.hide-from-output= \
# bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
# dash dash: 1: cannot open /nonexistent: No such file
#
+STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},'
STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,'
+STD_SED_CMDS.shell+= -e 's,: command not found,: not found,'
+
+STD_SED_CMDS.white-space= -e 's, *, ,g' -e 's, *$$,,'
# The actual error messages for a failed regcomp or regexec differ between the
# implementations.
STD_SED_CMDS.regex= \
-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
+# Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'.
+# See STD_SED_CMDS.dg2 for timestamps from the debug log.
+STD_SED_CMDS.timestamp= \
+ -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [12][0-9][0-9][0-9],<timestamp>,'
+
# End of the configuration helpers section.
.-include "Makefile.inc"
@@ -645,31 +774,26 @@ LANG= C
_MKMSG_TEST= :
.endif
-
-# for many tests we need a TMPDIR that will not collide
-# with other users.
-.if ${.OBJDIR} != ${.CURDIR}
-# easy
-TMPDIR:= ${.OBJDIR}/tmp
-.elif defined(TMPDIR)
-TMPDIR:= ${TMPDIR}/uid${.MAKE.UID}
-.else
-TMPDIR:= /tmp/uid${.MAKE.UID}
-.endif
-# make sure it exists
-.if !exist(${TMPDIR})
-x!= echo; mkdir -p ${TMPDIR}
+# Some Linux systems such as Fedora have deprecated egrep in favor of grep -E.
+.if ${.MAKE.OS:NLinux} == ""
+EGREP= grep -E
.endif
-
-MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc
+# Keep the classical definition for all other systems. Just as the bmake code
+# is kept compatible with C90, the tests are kept compatible with systems that
+# are several decades old and don't follow modern POSIX standards.
+EGREP?= egrep
+
+MAKE_TEST_ENV= EGREP="${EGREP}"
+MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100
+MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510
MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
.if ${.MAKE.OS} == "NetBSD"
-LIMIT_RESOURCES?= ulimit -v 200000
+LIMIT_RESOURCES?= ulimit -v 300000
.endif
LIMIT_RESOURCES?= :
-# Each test is run in a sub-make, to keep the tests for interfering with
+# Each test is run in a sub-make, to keep the tests from interfering with
# each other, and because they use different environment variables and
# command line options.
.SUFFIXES: .mk .rawout .out
@@ -687,23 +811,38 @@ LIMIT_RESOURCES?= :
echo $$status > ${.TARGET:R}.status
@mv ${.TARGET}.tmp ${.TARGET}
-# Postprocess the test output so that the results can be compared.
+# Postprocess the test output to make the output platform-independent.
#
+# Replace anything after 'stopped in' with unit-tests
+_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
+# Allow the test files to be placed anywhere.
+_SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
+_SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
+_SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g'
+# canonicalize ${.OBJDIR} and ${.CURDIR}
+_SED_CMDS+= -e 's,${.CURDIR},<curdir>,g'
+.if ${.OBJDIR} != ${.CURDIR}
+# yes this is inaccurate but none of the tests expect <objdir> anywhere
+# which we get depending on how MAKEOBJDIR is set.
+_SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g'
+.endif
# always pretend .MAKE was called 'make'
_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
-_SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
_SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
-# replace anything after 'stopped in' with unit-tests
-_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
-_SED_CMDS+= -e 's,${TMPDIR},TMPDIR,g'
-# strip ${.CURDIR}/ from the output
-_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
+_SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,'
+_SED_CMDS+= -e 's,<curdir>/,,g'
_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
-# on AT&T derrived systems; false exits 255 not 1
+_SED_CMDS+= -e '/MAKE_VERSION/d'
+_SED_CMDS+= -e '/EGREP=/d'
+
+# on AT&T derived systems: false exits 255 not 1
.if ${.MAKE.OS:N*BSD} != ""
_SED_CMDS+= -e 's,\(Error code\) 255,\1 1,'
.endif
+.if ${.SHELL:T} == "ksh"
+_SED_CMDS+= -e '/^set [+-]v/d'
+.endif
.rawout.out:
@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
diff --git a/contrib/bmake/unit-tests/Makefile.config.in b/contrib/bmake/unit-tests/Makefile.config.in
index 0fe24f08d2f9..30049eaa7c26 100644
--- a/contrib/bmake/unit-tests/Makefile.config.in
+++ b/contrib/bmake/unit-tests/Makefile.config.in
@@ -1,4 +1,7 @@
-# $Id: Makefile.config.in,v 1.1 2018/12/30 17:14:24 sjg Exp $
+# $Id: Makefile.config.in,v 1.4 2022/09/09 18:44:56 sjg Exp $
srcdir= @srcdir@
+EGREP= @egrep@
+TOOL_DIFF?= @diff@
DIFF_FLAGS?= @diff_u@
+UTC_1= @UTC_1@
diff --git a/contrib/bmake/unit-tests/cmd-errors-jobs.exp b/contrib/bmake/unit-tests/cmd-errors-jobs.exp
index 9ed0557975b3..d0a6e51eb84d 100644
--- a/contrib/bmake/unit-tests/cmd-errors-jobs.exp
+++ b/contrib/bmake/unit-tests/cmd-errors-jobs.exp
@@ -1,9 +1,9 @@
-: undefined eol
+: undefined--eol
make: Unclosed variable "UNCLOSED"
-: unclosed-variable
-make: Unclosed variable expression (expecting '}') for "UNCLOSED"
-: unclosed-modifier
+: unclosed-variable-
+make: Unclosed expression, expecting '}' for "UNCLOSED"
+: unclosed-modifier-
make: Unknown modifier "Z"
-: unknown-modifier eol
-: end eol
+: unknown-modifier--eol
+: end-eol
exit status 0
diff --git a/contrib/bmake/unit-tests/cmd-errors-jobs.mk b/contrib/bmake/unit-tests/cmd-errors-jobs.mk
index 8462a2e3497e..b3dc982de35f 100644
--- a/contrib/bmake/unit-tests/cmd-errors-jobs.mk
+++ b/contrib/bmake/unit-tests/cmd-errors-jobs.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cmd-errors-jobs.mk,v 1.1 2020/12/27 05:11:40 rillig Exp $
+# $NetBSD: cmd-errors-jobs.mk,v 1.2 2022/09/25 12:51:37 rillig Exp $
#
# Demonstrate how errors in variable expansions affect whether the commands
# are actually executed in jobs mode.
@@ -9,24 +9,24 @@ all: undefined unclosed-variable unclosed-modifier unknown-modifier end
# Undefined variables are not an error. They expand to empty strings.
undefined:
- : $@ ${UNDEFINED} eol
+ : $@-${UNDEFINED}-eol
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unclosed-variable:
- : $@ ${UNCLOSED
+ : $@-${UNCLOSED
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unclosed-modifier:
- : $@ ${UNCLOSED:
+ : $@-${UNCLOSED:
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unknown-modifier:
- : $@ ${UNKNOWN:Z} eol
+ : $@-${UNKNOWN:Z}-eol
end:
- : $@ eol
+ : $@-eol
# XXX: As of 2020-11-02, despite the parse errors, the exit status is 0.
diff --git a/contrib/bmake/unit-tests/cmd-errors-lint.exp b/contrib/bmake/unit-tests/cmd-errors-lint.exp
index 90b63bbcb08e..bdf4ae1a17e8 100644
--- a/contrib/bmake/unit-tests/cmd-errors-lint.exp
+++ b/contrib/bmake/unit-tests/cmd-errors-lint.exp
@@ -1,7 +1,7 @@
: undefined
make: Unclosed variable "UNCLOSED"
: unclosed-variable
-make: Unclosed variable expression (expecting '}') for "UNCLOSED"
+make: Unclosed expression, expecting '}' for "UNCLOSED"
: unclosed-modifier
make: Unknown modifier "Z"
: unknown-modifier
diff --git a/contrib/bmake/unit-tests/cmd-errors.exp b/contrib/bmake/unit-tests/cmd-errors.exp
index 9ed0557975b3..d0a6e51eb84d 100644
--- a/contrib/bmake/unit-tests/cmd-errors.exp
+++ b/contrib/bmake/unit-tests/cmd-errors.exp
@@ -1,9 +1,9 @@
-: undefined eol
+: undefined--eol
make: Unclosed variable "UNCLOSED"
-: unclosed-variable
-make: Unclosed variable expression (expecting '}') for "UNCLOSED"
-: unclosed-modifier
+: unclosed-variable-
+make: Unclosed expression, expecting '}' for "UNCLOSED"
+: unclosed-modifier-
make: Unknown modifier "Z"
-: unknown-modifier eol
-: end eol
+: unknown-modifier--eol
+: end-eol
exit status 0
diff --git a/contrib/bmake/unit-tests/cmd-errors.mk b/contrib/bmake/unit-tests/cmd-errors.mk
index 356fe1a3e4a2..6d3880684bcf 100644
--- a/contrib/bmake/unit-tests/cmd-errors.mk
+++ b/contrib/bmake/unit-tests/cmd-errors.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cmd-errors.mk,v 1.4 2020/12/27 05:11:40 rillig Exp $
+# $NetBSD: cmd-errors.mk,v 1.5 2022/09/25 12:51:37 rillig Exp $
#
# Demonstrate how errors in variable expansions affect whether the commands
# are actually executed in compat mode.
@@ -7,24 +7,24 @@ all: undefined unclosed-variable unclosed-modifier unknown-modifier end
# Undefined variables are not an error. They expand to empty strings.
undefined:
- : $@ ${UNDEFINED} eol
+ : $@-${UNDEFINED}-eol
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unclosed-variable:
- : $@ ${UNCLOSED
+ : $@-${UNCLOSED
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unclosed-modifier:
- : $@ ${UNCLOSED:
+ : $@-${UNCLOSED:
# XXX: As of 2020-11-01, this command is executed even though it contains
# parse errors.
unknown-modifier:
- : $@ ${UNKNOWN:Z} eol
+ : $@-${UNKNOWN:Z}-eol
end:
- : $@ eol
+ : $@-eol
# XXX: As of 2020-11-02, despite the parse errors, the exit status is 0.
diff --git a/contrib/bmake/unit-tests/cmd-interrupt.exp b/contrib/bmake/unit-tests/cmd-interrupt.exp
index 91f4439e7bea..242db1d9507d 100755
--- a/contrib/bmake/unit-tests/cmd-interrupt.exp
+++ b/contrib/bmake/unit-tests/cmd-interrupt.exp
@@ -2,7 +2,6 @@
make: *** cmd-interrupt-ordinary removed
interrupt-ordinary: ok
> cmd-interrupt-phony
-make: *** cmd-interrupt-phony removed
interrupt-phony: ok
> cmd-interrupt-precious
interrupt-precious: ok
diff --git a/contrib/bmake/unit-tests/cmd-interrupt.mk b/contrib/bmake/unit-tests/cmd-interrupt.mk
index fa0d85fc9063..140651b55c62 100755
--- a/contrib/bmake/unit-tests/cmd-interrupt.mk
+++ b/contrib/bmake/unit-tests/cmd-interrupt.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cmd-interrupt.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: cmd-interrupt.mk,v 1.4 2023/03/18 22:20:12 sjg Exp $
#
# Tests for interrupting a command.
#
@@ -30,7 +30,7 @@ interrupt-ordinary:
interrupt-phony: .PHONY
@${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-phony || true
# The ././ is necessary to work around the file cache.
- @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? error : ok }
+ @echo ${.TARGET}: ${exists(././cmd-interrupt-phony) :? ok : error }
interrupt-precious: .PRECIOUS
@${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-precious || true
diff --git a/contrib/bmake/unit-tests/cmdline-undefined.exp b/contrib/bmake/unit-tests/cmdline-undefined.exp
index 977ceee6dbf5..197f6da60131 100644
--- a/contrib/bmake/unit-tests/cmdline-undefined.exp
+++ b/contrib/bmake/unit-tests/cmdline-undefined.exp
@@ -1,17 +1,17 @@
The = assignment operator
-make: "cmdline-undefined.mk" line 29: From the command line: Undefined is .
-make: "cmdline-undefined.mk" line 30: From .MAKEFLAGS '=': Undefined is .
-make: "cmdline-undefined.mk" line 31: From .MAKEFLAGS ':=': Undefined is .
-make: "cmdline-undefined.mk" line 35: From the command line: Undefined is now defined.
-make: "cmdline-undefined.mk" line 36: From .MAKEFLAGS '=': Undefined is now defined.
-make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is now defined.
+make: "cmdline-undefined.mk" line 31: From the command line: Undefined is .
+make: "cmdline-undefined.mk" line 34: From .MAKEFLAGS '=': Undefined is .
+make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is .
+make: "cmdline-undefined.mk" line 43: From the command line: Undefined is now defined.
+make: "cmdline-undefined.mk" line 46: From .MAKEFLAGS '=': Undefined is now defined.
+make: "cmdline-undefined.mk" line 49: From .MAKEFLAGS ':=': Undefined is now defined.
The := assignment operator
-make: "cmdline-undefined.mk" line 29: From the command line: Undefined is .
-make: "cmdline-undefined.mk" line 30: From .MAKEFLAGS '=': Undefined is .
-make: "cmdline-undefined.mk" line 31: From .MAKEFLAGS ':=': Undefined is .
-make: "cmdline-undefined.mk" line 35: From the command line: Undefined is now defined.
-make: "cmdline-undefined.mk" line 36: From .MAKEFLAGS '=': Undefined is now defined.
-make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is now defined.
+make: "cmdline-undefined.mk" line 31: From the command line: Undefined is .
+make: "cmdline-undefined.mk" line 34: From .MAKEFLAGS '=': Undefined is .
+make: "cmdline-undefined.mk" line 37: From .MAKEFLAGS ':=': Undefined is .
+make: "cmdline-undefined.mk" line 43: From the command line: Undefined is now defined.
+make: "cmdline-undefined.mk" line 46: From .MAKEFLAGS '=': Undefined is now defined.
+make: "cmdline-undefined.mk" line 49: From .MAKEFLAGS ':=': Undefined is now defined.
exit status 0
diff --git a/contrib/bmake/unit-tests/cmdline-undefined.mk b/contrib/bmake/unit-tests/cmdline-undefined.mk
index 5a3375cbbfb8..81b44518dd41 100644
--- a/contrib/bmake/unit-tests/cmdline-undefined.mk
+++ b/contrib/bmake/unit-tests/cmdline-undefined.mk
@@ -1,6 +1,6 @@
-# $NetBSD: cmdline-undefined.mk,v 1.2 2020/11/04 04:49:33 rillig Exp $
+# $NetBSD: cmdline-undefined.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $
#
-# Tests for undefined variable expressions in the command line.
+# Tests for undefined expressions in the command line.
all:
# When the command line is parsed, variable assignments using the
@@ -26,14 +26,26 @@ all:
.MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.'
.MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.'
+# expect+2: From the command line: Undefined is .
+# expect+1: From the command line: Undefined is .
.info From the command line: ${CMDLINE}
+# expect+2: From .MAKEFLAGS '=': Undefined is .
+# expect+1: From .MAKEFLAGS '=': Undefined is .
.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
+# expect+2: From .MAKEFLAGS ':=': Undefined is .
+# expect+1: From .MAKEFLAGS ':=': Undefined is .
.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
UNDEFINED?= now defined
+# expect+2: From the command line: Undefined is now defined.
+# expect+1: From the command line: Undefined is now defined.
.info From the command line: ${CMDLINE}
+# expect+2: From .MAKEFLAGS '=': Undefined is now defined.
+# expect+1: From .MAKEFLAGS '=': Undefined is now defined.
.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
+# expect+2: From .MAKEFLAGS ':=': Undefined is now defined.
+# expect+1: From .MAKEFLAGS ':=': Undefined is now defined.
.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
print-undefined:
diff --git a/contrib/bmake/unit-tests/cmdline.exp b/contrib/bmake/unit-tests/cmdline.exp
index 596281ab0a1f..5700da3295fb 100644
--- a/contrib/bmake/unit-tests/cmdline.exp
+++ b/contrib/bmake/unit-tests/cmdline.exp
@@ -1,5 +1,8 @@
makeobjdir-direct:
-show-objdir: TMPDIR/6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5
+show-objdir: <tmpdir>/6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5
makeobjdir-indirect:
-show-objdir: TMPDIR/a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45/
+show-objdir: <tmpdir>/a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45/
+space-and-comment:
+value # no comment $
+value # no comment $
exit status 0
diff --git a/contrib/bmake/unit-tests/cmdline.mk b/contrib/bmake/unit-tests/cmdline.mk
index f82e7f967ef8..a24d46208e52 100644
--- a/contrib/bmake/unit-tests/cmdline.mk
+++ b/contrib/bmake/unit-tests/cmdline.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cmdline.mk,v 1.3 2021/02/06 18:26:03 sjg Exp $
+# $NetBSD: cmdline.mk,v 1.4 2022/06/10 18:58:07 rillig Exp $
#
# Tests for command line parsing and related special variables.
@@ -11,6 +11,7 @@ DIR12= ${TMPBASE}/${SUB1}/${SUB2}
all: prepare-dirs
all: makeobjdir-direct makeobjdir-indirect
+all: space-and-comment
prepare-dirs:
@rm -rf ${DIR2} ${DIR12}
@@ -34,3 +35,24 @@ makeobjdir-indirect:
show-objdir:
@echo $@: ${.OBJDIR:Q}
+
+
+# Variable assignments in the command line are handled differently from
+# variable assignments in makefiles. In the command line, trailing whitespace
+# is preserved, and the '#' does not start a comment. This is because the
+# low-level parsing from ParseRawLine does not take place.
+#
+# Preserving '#' and trailing whitespace has the benefit that when passing
+# such values to sub-makes via MAKEFLAGS, no special encoding is needed.
+# Leading whitespace in the variable value is discarded though, which makes
+# the behavior inconsistent.
+space-and-comment: .PHONY
+ @echo $@:
+
+ @env -i \
+ ${MAKE} -r -f /dev/null ' VAR= value # no comment ' -v VAR \
+ | sed 's,$$,$$,'
+
+ @env -i MAKEFLAGS="' VAR= value # no comment '" \
+ ${MAKE} -r -f /dev/null -v VAR \
+ | sed 's,$$,$$,'
diff --git a/contrib/bmake/unit-tests/comment.mk b/contrib/bmake/unit-tests/comment.mk
index d4fb041104a7..a3bf781b9a67 100644
--- a/contrib/bmake/unit-tests/comment.mk
+++ b/contrib/bmake/unit-tests/comment.mk
@@ -1,4 +1,4 @@
-# $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: comment.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
# Demonstrate how comments are written in makefiles.
@@ -15,13 +15,15 @@ on and on.
# Comments can be indented with spaces, but that is rather unusual.
# Comments can be indented with a tab.
- # These are not shell commands, they are just makefile comments.
+ # Since parse.c 1.127 from 2007-01-01, these are not shell commands,
+ # they are just makefile comments. Before that commit, these comments
+ # triggered the error message "Unassociated shell command".
.if 1 # There can be comments after conditions.
.endif # And after the closing directive.
VAR= # This comment makes the variable value empty.
- # ParseGetLine removes any whitespace before the
+ # ParseRawLine removes any whitespace before the
# comment.
.if ${VAR} != ""
. error
@@ -53,7 +55,7 @@ VAR= \# # Both in the assignment.
# Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
# To keep the parsing code simple, any "[#" does not start a comment, even
-# outside of a variable expression.
+# outside of an expression.
WORDS= ${VAR:[#]} [#
.if ${WORDS} != "1 [#"
. error
diff --git a/contrib/bmake/unit-tests/compat-error.mk b/contrib/bmake/unit-tests/compat-error.mk
index 4cbc48d4b6bb..bcfeb14ac408 100644
--- a/contrib/bmake/unit-tests/compat-error.mk
+++ b/contrib/bmake/unit-tests/compat-error.mk
@@ -1,17 +1,24 @@
-# $NetBSD: compat-error.mk,v 1.3 2020/12/13 19:33:53 rillig Exp $
+# $NetBSD: compat-error.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $
#
# Test detailed error handling in compat mode.
#
-# Until 2020-12-13, .ERROR_TARGET was success3, which was wrong.
-# Since compat.c 1.215 from 2020-12-13, it is 'fail1', which is the first
-# failed top-level target. XXX: Even better would be if .ERROR_TARGET were
-# the smallest target that caused the build to fail, even if it were a
-# sub-sub-sub-dependency of a top-level target.
+# Make several targets that alternately succeed and fail.
#
-# XXX: As of 2020-12-13, .ERROR_CMD is empty, which is wrong.
+# The first failing top-level target is recorded in '.ERROR_TARGET'. While
+# this information may give a hint as to which target failed, it would be more
+# useful at that point to know the actual target that failed, or the complete
+# chain from root cause to top-level target.
+#
+# Historic bugs
+# Before compat.c 1.215 from 2020-12-13, '.ERROR_TARGET' was 'success3',
+# which was obviously wrong.
+#
+# Bugs
+# As of 2020-12-13, '.ERROR_CMD' is empty, which does not provide any
+# insight into the command that actually failed.
#
# See also:
-# Compat_Run
+# Compat_MakeAll
#
# The commit that added the NULL command to gn->commands:
# CVS: 1994.06.06.22.45.??
@@ -20,10 +27,10 @@
# 2020: LstNode_SetNull(cmdNode);
#
# The commit that skipped NULL commands for .ERROR_CMD:
-# CVS: 2016.08.11.19.53.??
+# CVS: 2016.08.11.19.53.17
# Git: 58b23478b7353d46457089e726b07a49197388e4
-.MAKEFLAGS: success1 fail1 success2 fail2 success3
+.MAKEFLAGS: -k success1 fail1 success2 fail2 success3
success1 success2 success3:
: Making ${.TARGET} out of nothing.
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp
index 72d3d935755b..059007f00c84 100644
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.exp
@@ -1,5 +1,5 @@
-make: "cond-cmp-numeric-eq.mk" line 67: Malformed conditional (!(12345 = 12345))
-make: "cond-cmp-numeric-eq.mk" line 74: Malformed conditional (!(12345 === 12345))
+make: "cond-cmp-numeric-eq.mk" line 68: Malformed conditional (!(12345 = 12345))
+make: "cond-cmp-numeric-eq.mk" line 76: Malformed conditional (!(12345 === 12345))
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk
index c6b39876e75e..1d0ade26087e 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-eq.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-eq.mk,v 1.5 2020/11/08 21:47:59 rillig Exp $
+# $NetBSD: cond-cmp-numeric-eq.mk,v 1.7 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the == operator in .if conditions.
@@ -40,7 +40,7 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
@@ -64,6 +64,7 @@
.endif
# There is no = operator for numbers.
+# expect+1: Malformed conditional (!(12345 = 12345))
.if !(12345 = 12345)
. error
.else
@@ -71,11 +72,9 @@
.endif
# There is no === operator for numbers either.
+# expect+1: Malformed conditional (!(12345 === 12345))
.if !(12345 === 12345)
. error
.else
. error
.endif
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk
index e64be7f0c1a8..62975f950c2a 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-ge.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-ge.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-cmp-numeric-ge.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the >= operator in .if conditions.
@@ -62,7 +62,7 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk
index 1cdcc9891d6f..6134f7daf3fe 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-gt.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-cmp-numeric-gt.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the > operator in .if conditions.
@@ -61,11 +61,11 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
-.if 1.000000000000000001 > 1.000000000000000002
+.if 1.000000000000000002 > 1.000000000000000001
. error
.endif
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk
index 05f5e8dba312..231db76ba618 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-le.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-le.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-cmp-numeric-le.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the <= operator in .if conditions.
@@ -62,7 +62,7 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk
index b0dddd591543..9529fa9ff0eb 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-lt.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-cmp-numeric-lt.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the < operator in .if conditions.
@@ -61,7 +61,7 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk b/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk
index 0a366a905a21..e311d21f0a54 100755
--- a/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric-ne.mk,v 1.2 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-cmp-numeric-ne.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
#
# Tests for numeric comparisons with the != operator in .if conditions.
@@ -37,7 +37,7 @@
. error
.endif
-# As of 2020-08-23, numeric comparison is implemented as parsing both sides
+# Numeric comparison works by parsing both sides
# as double, and then performing a normal comparison. The range of double is
# typically 16 or 17 significant digits, therefore these two numbers seem to
# be equal.
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric.exp b/contrib/bmake/unit-tests/cond-cmp-numeric.exp
index 4a97b6879e7a..69a8a1e4fca0 100644
--- a/contrib/bmake/unit-tests/cond-cmp-numeric.exp
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric.exp
@@ -1,11 +1,15 @@
CondParser_Eval: !(${:UINF} > 1e100)
-make: "cond-cmp-numeric.mk" line 11: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 15: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric
CondParser_Eval: ${:UNaN} > NaN
-make: "cond-cmp-numeric.mk" line 16: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 21: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric
CondParser_Eval: !(${:UNaN} == NaN)
-lhs = "NaN", rhs = "NaN", op = ==
+Comparing "NaN" == "NaN"
CondParser_Eval: 123 ! 123
-make: "cond-cmp-numeric.mk" line 34: Malformed conditional (123 ! 123)
+make: "cond-cmp-numeric.mk" line 38: Malformed conditional (123 ! 123)
+CondParser_Eval: ${:U 123} < 124
+Comparing 123.000000 < 124.000000
+CondParser_Eval: ${:U123 } < 124
+make: "cond-cmp-numeric.mk" line 54: Comparison with '<' requires both operands '123 ' and '124' to be numeric
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-cmp-numeric.mk b/contrib/bmake/unit-tests/cond-cmp-numeric.mk
index b1ec3e719d47..e025b99b27cd 100644
--- a/contrib/bmake/unit-tests/cond-cmp-numeric.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-numeric.mk
@@ -1,6 +1,9 @@
-# $NetBSD: cond-cmp-numeric.mk,v 1.4 2020/11/08 22:56:16 rillig Exp $
+# $NetBSD: cond-cmp-numeric.mk,v 1.7 2023/03/04 08:07:29 rillig Exp $
#
# Tests for numeric comparisons in .if conditions.
+#
+# See also:
+# cond-token-number.mk
.MAKEFLAGS: -dc
@@ -8,11 +11,13 @@
# Even if strtod(3) parses "INF" as +Infinity, make does not accept this
# since it is not really a number; see TryParseNumber.
+# expect+1: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric
.if !(${:UINF} > 1e100)
. error
.endif
# Neither is NaN a number; see TryParseNumber.
+# expect+1: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric
.if ${:UNaN} > NaN
. error
.endif
@@ -29,13 +34,27 @@
# whether the operator is valid, leaving the rest of the work to the
# evaluation functions EvalCompareNum and EvalCompareStr. Ensure that this
# parse error is properly reported.
-#
-# XXX: The warning message does not mention the actual operator.
+# expect+1: Malformed conditional (123 ! 123)
.if 123 ! 123
. error
.else
. error
.endif
+# Leading spaces are allowed for numbers.
+# See EvalCompare and TryParseNumber.
+.if ${:U 123} < 124
+.else
+. error
+.endif
+
+# Trailing spaces are NOT allowed for numbers.
+# See EvalCompare and TryParseNumber.
+# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric
+.if ${:U123 } < 124
+. error
+.else
+. error
+.endif
+
all:
- @:;
diff --git a/contrib/bmake/unit-tests/cond-cmp-string.exp b/contrib/bmake/unit-tests/cond-cmp-string.exp
index a10341ed2121..e0aabfdadca4 100644
--- a/contrib/bmake/unit-tests/cond-cmp-string.exp
+++ b/contrib/bmake/unit-tests/cond-cmp-string.exp
@@ -1,11 +1,11 @@
-make: "cond-cmp-string.mk" line 18: Malformed conditional (str != str)
-make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing")
-make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value"))
-make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value"))
-make: "cond-cmp-string.mk" line 113: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 120: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 127: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 134: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 19: Malformed conditional (str != str)
+make: "cond-cmp-string.mk" line 44: Malformed conditional ("string" != "str""ing")
+make: "cond-cmp-string.mk" line 52: Malformed conditional (!("value" = "value"))
+make: "cond-cmp-string.mk" line 60: Malformed conditional (!("value" === "value"))
+make: "cond-cmp-string.mk" line 118: Comparison with '<' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 126: Comparison with '<=' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 134: Comparison with '>' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 142: Comparison with '>=' requires both operands 'string' and 'string' to be numeric
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-cmp-string.mk b/contrib/bmake/unit-tests/cond-cmp-string.mk
index 9f3e731b2eb0..7b13ebf2212b 100644
--- a/contrib/bmake/unit-tests/cond-cmp-string.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-string.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-string.mk,v 1.14 2021/01/19 19:54:57 rillig Exp $
+# $NetBSD: cond-cmp-string.mk,v 1.18 2023/11/19 21:47:52 rillig Exp $
#
# Tests for string comparisons in .if conditions.
@@ -15,18 +15,19 @@
# The left-hand side of the comparison must be enclosed in quotes.
# This one is not enclosed in quotes and thus generates an error message.
+# expect+1: Malformed conditional (str != str)
.if str != str
. error
.endif
-# The left-hand side of the comparison requires that any variable expression
+# The left-hand side of the comparison requires that any expression
# is defined.
#
# The variable named "" is never defined, nevertheless it can be used as a
-# starting point for variable expressions. Applying the :U modifier to such
+# starting point for expressions. Applying the :U modifier to such
# an undefined expression turns it into a defined expression.
#
-# See ApplyModifier_Defined and VEF_DEF.
+# See ApplyModifier_Defined and DEF_DEFINED.
.if ${:Ustr} != "str"
. error
.endif
@@ -39,6 +40,7 @@
# It is not possible to concatenate two string literals to form a single
# string. In C, Python and the shell this is possible, but not in make.
+# expect+1: Malformed conditional ("string" != "str""ing")
.if "string" != "str""ing"
. error
.else
@@ -46,6 +48,7 @@
.endif
# There is no = operator for strings.
+# expect+1: Malformed conditional (!("value" = "value"))
.if !("value" = "value")
. error
.else
@@ -53,19 +56,20 @@
.endif
# There is no === operator for strings either.
+# expect+1: Malformed conditional (!("value" === "value"))
.if !("value" === "value")
. error
.else
. error
.endif
-# A variable expression can be enclosed in double quotes.
+# An expression can be enclosed in double quotes.
.if ${:Uword} != "${:Uword}"
. error
.endif
# Between 2003-01-01 (maybe even earlier) and 2020-10-30, adding one of the
-# characters " \t!=><" directly after a variable expression resulted in a
+# characters " \t!=><" directly after an expression resulted in a
# "Malformed conditional", even though the string was well-formed.
.if ${:Uword } != "${:Uword} "
. error
@@ -85,12 +89,12 @@
. error
.endif
-# Adding another variable expression to the string literal works though.
+# Adding another expression to the string literal works though.
.if ${:Uword} != "${:Uwo}${:Urd}"
. error
.endif
-# Adding a space at the beginning of the quoted variable expression works
+# Adding a space at the beginning of the quoted expression works
# though.
.if ${:U word } != " ${:Uword} "
. error
@@ -110,6 +114,7 @@
.endif
# Strings cannot be compared relationally, only for equality.
+# expect+1: Comparison with '<' requires both operands 'string' and 'string' to be numeric
.if "string" < "string"
. error
.else
@@ -117,6 +122,7 @@
.endif
# Strings cannot be compared relationally, only for equality.
+# expect+1: Comparison with '<=' requires both operands 'string' and 'string' to be numeric
.if "string" <= "string"
. error
.else
@@ -124,6 +130,7 @@
.endif
# Strings cannot be compared relationally, only for equality.
+# expect+1: Comparison with '>' requires both operands 'string' and 'string' to be numeric
.if "string" > "string"
. error
.else
@@ -131,8 +138,17 @@
.endif
# Strings cannot be compared relationally, only for equality.
+# expect+1: Comparison with '>=' requires both operands 'string' and 'string' to be numeric
.if "string" >= "string"
. error
.else
. error
.endif
+
+# Two variables with different values compare unequal.
+VAR1= value1
+VAR2= value2
+.if ${VAR1} != ${VAR2}
+.else
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/cond-cmp-unary.exp b/contrib/bmake/unit-tests/cond-cmp-unary.exp
index 89f90dc1651f..c5b800122eb9 100755
--- a/contrib/bmake/unit-tests/cond-cmp-unary.exp
+++ b/contrib/bmake/unit-tests/cond-cmp-unary.exp
@@ -1,2 +1,2 @@
-make: "cond-cmp-unary.mk" line 53: This is only reached because of a bug in EvalNotEmpty.
+make: "cond-cmp-unary.mk" line 54: This is only reached because of a bug in EvalTruthy.
exit status 0
diff --git a/contrib/bmake/unit-tests/cond-cmp-unary.mk b/contrib/bmake/unit-tests/cond-cmp-unary.mk
index 168de0f30e3f..80626a279358 100755
--- a/contrib/bmake/unit-tests/cond-cmp-unary.mk
+++ b/contrib/bmake/unit-tests/cond-cmp-unary.mk
@@ -1,11 +1,11 @@
-# $NetBSD: cond-cmp-unary.mk,v 1.2 2020/11/11 07:30:11 rillig Exp $
+# $NetBSD: cond-cmp-unary.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
# Tests for unary comparisons in .if conditions, that is, comparisons with
# a single operand. If the operand is a number, it is compared to zero,
# if it is a string, it is tested for emptiness.
-# The number 0 evaluates to false.
-.if 0
+# The number 0 in all its various representations evaluates to false.
+.if 0 || 0.0 || 0e0 || 0.0e0 || 0.0e10
. error
.endif
@@ -24,35 +24,52 @@
. error
.endif
-# The empty string may come from a variable expression.
+# The empty string may come from an expression.
#
-# XXX: As of 2020-11-11, this empty string is interpreted "as a number" in
-# EvalNotEmpty, which is plain wrong. The bug is in TryParseNumber.
+# XXX: As of 2023-06-01, this empty string is interpreted "as a number" in
+# EvalTruthy, which is plain wrong. The bug is in TryParseNumber.
.if ${:U}
. error
.endif
-# A variable expression that is not surrounded by quotes is interpreted
+# An expression that is not surrounded by quotes is interpreted
# as a number if possible, otherwise as a string.
.if ${:U0}
. error
.endif
-# A non-zero number from a variable expression evaluates to true.
+# A non-zero number from an expression evaluates to true.
.if !${:U12345}
. error
.endif
# A string of whitespace should evaluate to false.
#
-# XXX: As of 2020-11-11, the implementation in EvalNotEmpty does not skip
+# XXX: As of 2023-06-01, the implementation in EvalTruthy does not skip
# whitespace before testing for the end. This was probably an oversight in
# a commit from 1992-04-15 saying "A variable is empty when it just contains
# spaces".
.if ${:U }
-. info This is only reached because of a bug in EvalNotEmpty.
+# expect+1: This is only reached because of a bug in EvalTruthy.
+. info This is only reached because of a bug in EvalTruthy.
.else
. error
.endif
+# The condition '${VAR:M*}' is almost equivalent to '${VAR:M*} != ""'. The
+# only case where they differ is for a single word whose numeric value is zero.
+.if ${:U0:M*}
+. error
+.endif
+.if ${:U0:M*} == ""
+. error
+.endif
+# Multiple words cannot be parsed as a single number, thus evaluating to true.
+.if !${:U0 0:M*}
+. error
+.endif
+.if ${:U0 0:M*} == ""
+. error
+.endif
+
all: # nothing
diff --git a/contrib/bmake/unit-tests/cond-eof.exp b/contrib/bmake/unit-tests/cond-eof.exp
index 3b1e6eb1f056..58a74d854d91 100644
--- a/contrib/bmake/unit-tests/cond-eof.exp
+++ b/contrib/bmake/unit-tests/cond-eof.exp
@@ -1,9 +1,6 @@
-side effect
-make: "cond-eof.mk" line 15: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2})
-side effect
-make: "cond-eof.mk" line 17: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2})
-side effect
-make: "cond-eof.mk" line 19: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2})
+make: "cond-eof.mk" line 17: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2})
+make: "cond-eof.mk" line 20: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2})
+make: "cond-eof.mk" line 23: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-eof.mk b/contrib/bmake/unit-tests/cond-eof.mk
index 08f432bc4593..a5f7ce95f89e 100644
--- a/contrib/bmake/unit-tests/cond-eof.mk
+++ b/contrib/bmake/unit-tests/cond-eof.mk
@@ -1,20 +1,24 @@
-# $NetBSD: cond-eof.mk,v 1.2 2020/12/14 20:28:09 rillig Exp $
+# $NetBSD: cond-eof.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
-# Tests for parsing conditions, especially the end of such conditions, which
-# are represented as the token TOK_EOF.
+# Tests for parsing the end of '.if' conditions, which are represented as the
+# token TOK_EOF.
+
SIDE_EFFECT= ${:!echo 'side effect' 1>&2!}
SIDE_EFFECT2= ${:!echo 'side effect 2' 1>&2!}
# In the following conditions, ${SIDE_EFFECT} is the position of the first
-# parse error. It is always fully evaluated, even if it were not necessary
-# to expand the variable expression. This is because these syntax errors are
-# an edge case that does not occur during normal operation, therefore there
-# is no need to optimize for this case, and it would slow down the common
-# case as well.
+# parse error. Before cond.c 1.286 from 2021-12-10, it was always fully
+# evaluated, even if it was not necessary to expand the expression.
+# These syntax errors are an edge case that does not occur during normal
+# operation. Still, it is easy to avoid evaluating these expressions, just in
+# case they have side effects.
+# expect+1: Malformed conditional (0 ${SIDE_EFFECT} ${SIDE_EFFECT2})
.if 0 ${SIDE_EFFECT} ${SIDE_EFFECT2}
.endif
+# expect+1: Malformed conditional (1 ${SIDE_EFFECT} ${SIDE_EFFECT2})
.if 1 ${SIDE_EFFECT} ${SIDE_EFFECT2}
.endif
+# expect+1: Malformed conditional ((0) ${SIDE_EFFECT} ${SIDE_EFFECT2})
.if (0) ${SIDE_EFFECT} ${SIDE_EFFECT2}
.endif
diff --git a/contrib/bmake/unit-tests/cond-func-defined.exp b/contrib/bmake/unit-tests/cond-func-defined.exp
index 878f56de2ecc..d556f3b982b3 100644
--- a/contrib/bmake/unit-tests/cond-func-defined.exp
+++ b/contrib/bmake/unit-tests/cond-func-defined.exp
@@ -1,8 +1,8 @@
-make: "cond-func-defined.mk" line 23: Missing closing parenthesis for defined()
-make: "cond-func-defined.mk" line 33: Missing closing parenthesis for defined()
-make: "cond-func-defined.mk" line 45: In .for loops, variable expressions for the loop variables are
-make: "cond-func-defined.mk" line 46: substituted at evaluation time. There is no actual variable
-make: "cond-func-defined.mk" line 47: involved, even if it feels like it.
+make: "cond-func-defined.mk" line 24: Missing closing parenthesis for defined()
+make: "cond-func-defined.mk" line 34: Missing closing parenthesis for defined()
+make: "cond-func-defined.mk" line 47: In .for loops, expressions for the loop variables are
+make: "cond-func-defined.mk" line 49: substituted at evaluation time. There is no actual variable
+make: "cond-func-defined.mk" line 51: involved, even if it feels like it.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-func-defined.mk b/contrib/bmake/unit-tests/cond-func-defined.mk
index 2aa49ccbf147..14597398bc62 100644
--- a/contrib/bmake/unit-tests/cond-func-defined.mk
+++ b/contrib/bmake/unit-tests/cond-func-defined.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-defined.mk,v 1.7 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: cond-func-defined.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the defined() function in .if conditions.
@@ -20,16 +20,17 @@ ${:UA B}= variable name with spaces
.endif
# The argument of a function must not directly contain whitespace.
+# expect+1: Missing closing parenthesis for defined()
.if !defined(A B)
. error
.endif
-# If necessary, the whitespace can be generated by a variable expression.
+# If necessary, the whitespace can be generated by an expression.
.if !defined(${:UA B})
. error
.endif
-# Parse error: missing closing parenthesis; see ParseFuncArg.
+# expect+1: Missing closing parenthesis for defined()
.if defined(DEF
. error
.else
@@ -42,11 +43,19 @@ ${:UA B}= variable name with spaces
. if defined(var)
. error
. else
-. info In .for loops, variable expressions for the loop variables are
+# expect+1: In .for loops, expressions for the loop variables are
+. info In .for loops, expressions for the loop variables are
+# expect+1: substituted at evaluation time. There is no actual variable
. info substituted at evaluation time. There is no actual variable
+# expect+1: involved, even if it feels like it.
. info involved, even if it feels like it.
. endif
.endfor
-all:
- @:;
+# Neither of the conditions is true. Before July 2020, the right-hand
+# condition was evaluated even though it was irrelevant.
+.if defined(UNDEF) && ${UNDEF:Mx} != ""
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/cond-func-empty.exp b/contrib/bmake/unit-tests/cond-func-empty.exp
index 77a4edd47f49..1d955124d1c6 100644
--- a/contrib/bmake/unit-tests/cond-func-empty.exp
+++ b/contrib/bmake/unit-tests/cond-func-empty.exp
@@ -1,5 +1,5 @@
-make: "cond-func-empty.mk" line 152: Unclosed variable "WORD"
-make: "cond-func-empty.mk" line 152: Malformed conditional (empty(WORD)
+make: "cond-func-empty.mk" line 168: Unclosed variable "WORD"
+make: "cond-func-empty.mk" line 168: Malformed conditional (empty(WORD)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-func-empty.mk b/contrib/bmake/unit-tests/cond-func-empty.mk
index 11a990cbbce1..057b175a7693 100644
--- a/contrib/bmake/unit-tests/cond-func-empty.mk
+++ b/contrib/bmake/unit-tests/cond-func-empty.mk
@@ -1,18 +1,19 @@
-# $NetBSD: cond-func-empty.mk,v 1.14 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.24 2023/12/19 19:33:40 rillig Exp $
#
-# Tests for the empty() function in .if conditions, which tests a variable
+# Tests for the empty() function in .if conditions, which tests an
# expression for emptiness.
#
-# Note that the argument in the parentheses is indeed a variable name,
-# optionally followed by variable modifiers.
+# Note that the argument in the parentheses is a variable name, not an
+# expression. That name may be followed by ':...' modifiers.
#
.undef UNDEF
EMPTY= # empty
SPACE= ${:U }
+ZERO= 0
WORD= word
-# An undefined variable is empty.
+# An undefined variable counts as empty.
.if !empty(UNDEF)
. error
.endif
@@ -24,15 +25,13 @@ WORD= word
. error
.endif
-# The :S modifier replaces the empty value with an actual word. The
-# expression is now no longer empty, but it is still possible to see whether
-# the expression was based on an undefined variable. The expression has the
-# flag VEF_UNDEF.
-#
-# The expression does not have the flag VEF_DEF though, therefore it is still
-# considered undefined. Yes, indeed, undefined but not empty. There are a
-# few variable modifiers that turn an undefined expression into a defined
-# expression, among them :U and :D, but not :S.
+# The :S modifier replaces the empty value with an actual word. After
+# applying the :S modifier to the expression, its value is 'empty', so it is
+# no longer empty, but it is still based on an undefined variable. There are
+# a few modifiers that turn an undefined expression into a defined expression,
+# among them :U and :D, but not :S. Therefore, at the end of evaluating the
+# expression, the expression is still undefined, so its final value becomes an
+# empty string.
#
# XXX: This is hard to explain to someone who doesn't know these
# implementation details.
@@ -41,23 +40,25 @@ WORD= word
. error
.endif
-# The :U modifier modifies expressions based on undefined variables
-# (DEF_UNDEF) by adding the DEF_DEFINED flag, which marks the expression
-# as "being interesting enough to be further processed".
+# The :U modifier changes the state of a previously undefined expression from
+# DEF_UNDEF to DEF_DEFINED. This marks the expression as "being interesting
+# enough to be further processed".
#
.if empty(UNDEF:S,^$,value,W:Ufallback)
. error
.endif
-# And now to the surprising part. Applying the following :S modifier to the
-# undefined expression makes it non-empty, but the marker VEF_UNDEF is
-# preserved nevertheless. The :U modifier that follows only looks at the
-# VEF_UNDEF flag to decide whether the variable is defined or not. This kind
-# of makes sense since the :U modifier tests the _variable_, not the
+# When an expression is based on an undefined variable, its modifiers interact
+# in sometimes surprising ways. Applying the :S modifier to the undefined
+# expression makes its value non-empty, but doesn't change that the expression
+# is based on an undefined variable. The :U modifier that follows only looks
+# at the definedness state to decide whether the variable is defined or not.
+# This kind of makes sense since the :U modifier tests the _variable_, not the
# _expression_.
#
-# But since the variable was undefined to begin with, the fallback value from
-# the :U modifier is used in this expression.
+# Since the variable was undefined to begin with, the fallback value from the
+# :U modifier is used in this expression, instead of keeping the 'value' from
+# the :S modifier.
#
.if ${UNDEF:S,^$,value,W:Ufallback} != "fallback"
. error
@@ -78,12 +79,24 @@ WORD= word
. error
.endif
-# The empty variable named "" gets a fallback value of " ", which counts as
-# empty.
+# The variable ZERO has the numeric value 0, but is not empty. This is a
+# subtle difference between using either 'empty(ZERO)' or the expression
+# '${ZERO}' in a condition.
+.if empty(ZERO)
+. error
+.elif ${ZERO}
+. error
+.elif ${ZERO} == ""
+. error
+.endif
+
+# The following example constructs an expression with the variable name ""
+# and the value " ". This expression counts as empty since the value contains
+# only whitespace.
#
# Contrary to the other functions in conditionals, the trailing space is not
# stripped off, as can be seen in the -dv debug log. If the space had been
-# stripped, it wouldn't make a difference in this case.
+# stripped, it wouldn't make a difference in this case, but in other cases.
#
.if !empty(:U )
. error
@@ -92,20 +105,22 @@ WORD= word
# Now the variable named " " gets a non-empty value, which demonstrates that
# neither leading nor trailing spaces are trimmed in the argument of the
# function. If the spaces were trimmed, the variable name would be "" and
-# that variable is indeed undefined. Since ParseEmptyArg calls Var_Parse
-# without VARE_UNDEFERR, the value of the undefined variable is
-# returned as an empty string.
+# that variable is indeed undefined. Since CondParser_FuncCallEmpty calls
+# Var_Parse without VARE_UNDEFERR, the value of the undefined variable ""
+# would be returned as an empty string.
${:U }= space
.if empty( )
. error
.endif
-# The value of the following expression is " word", which is not empty.
+# The value of the following expression is " word", which is not empty. To be
+# empty, _all_ characters in the expression value have to be whitespace, not
+# only the first.
.if empty(:U word)
. error
.endif
-# The :L modifier creates a variable expression that has the same value as
+# The :L modifier creates an expression that has the same value as
# its name, which both are "VAR" in this case. The value is therefore not
# empty.
.if empty(VAR:L)
@@ -123,19 +138,19 @@ ${:U }= space
. error
.endif
-# Ensure that variable expressions that appear as part of the argument are
-# properly parsed. Typical use cases for this are .for loops, which are
-# expanded to exactly these ${:U} expressions.
+# Ensure that expressions that appear as part of the function call
+# argument are properly parsed. Typical use cases for this are .for loops,
+# which are expanded to exactly these ${:U} expressions.
#
-# If everything goes well, the argument expands to "WORD", and that variable
-# is defined at the beginning of this file. The surrounding 'W' and 'D'
-# ensure that the parser in ParseEmptyArg has the correct position, both
-# before and after the call to Var_Parse.
+# The argument expands to "WORD", and that variable is defined at the
+# beginning of this file. The surrounding 'W' and 'D' ensure that
+# CondParser_FuncCallEmpty keeps track of the parsing position, both before
+# and after the call to Var_Parse.
.if empty(W${:UOR}D)
. error
.endif
-# There may be spaces at the outside of the parentheses.
+# There may be spaces outside the parentheses.
# Spaces inside the parentheses are interpreted as part of the variable name.
.if ! empty ( WORD )
. error
@@ -148,37 +163,60 @@ ${:U WORD }= variable name with spaces
. error
.endif
-# Parse error: missing closing parenthesis.
+# expect+2: Unclosed variable "WORD"
+# expect+1: Malformed conditional (empty(WORD)
.if empty(WORD
. error
.else
. error
.endif
-# Between 2020-06-28 and var.c 1.226 from 2020-07-02, this paragraph generated
-# a wrong error message "Variable VARNAME is recursive".
+# Since cond.c 1.76 from 2020-06-28 and before var.c 1.226 from 2020-07-02,
+# the following example generated a wrong error message "Variable VARNAME is
+# recursive".
+#
+# Since at least 1993, the manual page claimed that irrelevant parts of
+# conditions were not evaluated, but that was wrong for a long time. The
+# expressions in irrelevant parts of the condition were actually evaluated,
+# they just allowed undefined variables to be used in the conditions. These
+# unnecessary evaluations were fixed in several commits, starting with var.c
+# 1.226 from 2020-07-02.
#
-# The bug was that the !empty() condition was evaluated, even though this was
-# not necessary since the defined() condition already evaluated to false.
+# In this example, the variable "VARNAME2" is not defined, so evaluation of
+# the condition should have stopped at this point, and the rest of the
+# condition should have been processed in parse-only mode. The right-hand
+# side containing the '!empty' was evaluated though, as it had always been.
#
# When evaluating the !empty condition, the variable name was parsed as
-# "VARNAME${:U2}", but without expanding any nested variable expression, in
-# this case the ${:U2}. Therefore, the variable name came out as simply
-# "VARNAME". Since this variable name should have been discarded quickly after
-# parsing it, this unrealistic variable name should have done no harm.
-#
-# The variable expression was expanded though, and this was wrong. The
-# expansion was done without VARE_WANTRES (called VARF_WANTRES back
-# then) though. This had the effect that the ${:U1} from the value of VARNAME
+# "VARNAME${:U2}", but without expanding any nested expression, in
+# this case the ${:U2}. The expression '${:U2}' was replaced with an empty
+# string, the resulting variable name was thus "VARNAME". This conceptually
+# wrong variable name should have been discarded quickly after parsing it, to
+# prevent it from doing any harm.
+#
+# The expression was expanded, and this was wrong. The
+# expansion was done without VARE_WANTRES (called VARF_WANTRES back then)
+# though. This had the effect that the ${:U1} from the value of VARNAME
# expanded to an empty string. This in turn created the seemingly recursive
# definition VARNAME=${VARNAME}, and that definition was never meant to be
# expanded.
#
-# This was fixed by expanding nested variable expressions in the variable name
+# This was fixed by expanding nested expressions in the variable name
# only if the flag VARE_WANTRES is given.
VARNAME= ${VARNAME${:U1}}
.if defined(VARNAME${:U2}) && !empty(VARNAME${:U2})
.endif
-all:
- @:;
+
+# If the word 'empty' is not followed by '(', it is not a function call but an
+# ordinary bare word. This bare word is interpreted as 'defined(empty)', and
+# since there is no variable named 'empty', the condition evaluates to false.
+.if empty
+. error
+.endif
+
+empty= # defined but empty
+.if empty
+.else
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/cond-func-exists.mk b/contrib/bmake/unit-tests/cond-func-exists.mk
index 48d7e727dc3f..40228cd44902 100644
--- a/contrib/bmake/unit-tests/cond-func-exists.mk
+++ b/contrib/bmake/unit-tests/cond-func-exists.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-exists.mk,v 1.6 2020/11/30 20:12:29 rillig Exp $
+# $NetBSD: cond-func-exists.mk,v 1.7 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the exists() function in .if conditions.
@@ -17,7 +17,7 @@
.endif
# The only way to escape characters that would otherwise influence the parser
-# is to enclose them in a variable expression. For function arguments,
+# is to enclose them in an expression. For function arguments,
# neither the backslash nor the dollar sign act as escape character.
.if exists(\.)
. error
@@ -27,7 +27,7 @@
. error
.endif
-# The argument to the function can have several variable expressions.
+# The argument to the function can have several expressions.
# See cond-func.mk for the characters that cannot be used directly.
.if !exists(${.PARSEDIR}/${.PARSEFILE})
. error
diff --git a/contrib/bmake/unit-tests/cond-func-make.exp b/contrib/bmake/unit-tests/cond-func-make.exp
index 922203b72cbf..04ef6e29fee1 100644
--- a/contrib/bmake/unit-tests/cond-func-make.exp
+++ b/contrib/bmake/unit-tests/cond-func-make.exp
@@ -1,3 +1,4 @@
+make: "cond-func-make.mk" line 24: warning: Unfinished character list in pattern argument '[' to function 'make'
: via-cmdline
: via-dot-makeflags
exit status 0
diff --git a/contrib/bmake/unit-tests/cond-func-make.mk b/contrib/bmake/unit-tests/cond-func-make.mk
index d75b69bcf98f..15bc9f04d4e0 100644
--- a/contrib/bmake/unit-tests/cond-func-make.mk
+++ b/contrib/bmake/unit-tests/cond-func-make.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-make.mk,v 1.3 2020/09/25 20:11:06 rillig Exp $
+# $NetBSD: cond-func-make.mk,v 1.5 2023/06/23 04:56:54 rillig Exp $
#
# Tests for the make() function in .if conditions, which tests whether
# the argument has been passed as a target via the command line or later
@@ -20,5 +20,10 @@
. error
.endif
+# expect+1: warning: Unfinished character list in pattern argument '[' to function 'make'
+.if make([)
+. error
+.endif
+
via-cmdline via-dot-makeflags:
: $@
diff --git a/contrib/bmake/unit-tests/cond-func.exp b/contrib/bmake/unit-tests/cond-func.exp
index 855b9e5210fd..eeaa89445887 100644
--- a/contrib/bmake/unit-tests/cond-func.exp
+++ b/contrib/bmake/unit-tests/cond-func.exp
@@ -1,12 +1,12 @@
-make: "cond-func.mk" line 36: Missing closing parenthesis for defined()
-make: "cond-func.mk" line 51: Missing closing parenthesis for defined()
-make: "cond-func.mk" line 54: Missing closing parenthesis for defined()
-make: "cond-func.mk" line 94: The empty variable is never defined.
-make: "cond-func.mk" line 102: A plain function name is parsed as !empty(...).
-make: "cond-func.mk" line 109: A plain function name is parsed as !empty(...).
-make: "cond-func.mk" line 119: Symbols may start with a function name.
-make: "cond-func.mk" line 124: Symbols may start with a function name.
-make: "cond-func.mk" line 130: Malformed conditional (defined()
+make: "cond-func.mk" line 37: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 53: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 57: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 98: The empty variable is never defined.
+make: "cond-func.mk" line 108: A plain function name is parsed as defined(...).
+make: "cond-func.mk" line 116: A plain function name is parsed as defined(...).
+make: "cond-func.mk" line 127: Symbols may start with a function name.
+make: "cond-func.mk" line 133: Symbols may start with a function name.
+make: "cond-func.mk" line 139: Missing closing parenthesis for defined()
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-func.mk b/contrib/bmake/unit-tests/cond-func.mk
index 4ff43b72ef88..aabd31b4db46 100644
--- a/contrib/bmake/unit-tests/cond-func.mk
+++ b/contrib/bmake/unit-tests/cond-func.mk
@@ -1,12 +1,12 @@
-# $NetBSD: cond-func.mk,v 1.9 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: cond-func.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $
#
# Tests for those parts of the functions in .if conditions that are common
# among several functions.
#
-# The below test uses the function defined(...) since it has no side-effects,
-# the other functions (except empty(...)) would work equally well. The
-# function empty is special because it uses a different parsing algorithm for
-# its argument.
+# The below test uses the 'defined' function since it has no side-effects.
+# The other functions would work equally well, except for 'empty', which
+# parses its argument differently from the other functions.
+#
DEF= defined
${:UA B}= variable name with spaces
@@ -33,11 +33,12 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
.endif
# The argument of a function must not directly contain whitespace.
+# expect+1: Missing closing parenthesis for defined()
.if !defined(A B)
. error
.endif
-# If necessary, the whitespace can be generated by a variable expression.
+# If necessary, the whitespace can be generated by an expression.
.if !defined(${:UA B})
. error
.endif
@@ -48,9 +49,11 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
#
# It's not entirely clear why these characters are forbidden.
# The most plausible reason seems to be typo detection.
+# expect+1: Missing closing parenthesis for defined()
.if !defined(A&B)
. error
.endif
+# expect+1: Missing closing parenthesis for defined()
.if !defined(A|B)
. error
.endif
@@ -74,7 +77,7 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
# There may be spaces around the operators and parentheses, and even
# inside the parentheses. The spaces inside the parentheses are not
-# allowed for the empty() function (see cond-func-empty.mk), therefore
+# allowed for the 'empty' function (see cond-func-empty.mk), therefore
# they are typically omitted for the other functions as well.
.if ! defined ( DEF )
. error
@@ -91,22 +94,26 @@ ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
.if defined()
. error
.else
+# expect+1: The empty variable is never defined.
. info The empty variable is never defined.
.endif
-# The plain word 'defined' is interpreted as '!empty(defined)'.
+# The plain word 'defined' is interpreted as 'defined(defined)', see
+# CondParser_ComparisonOrLeaf.
# That variable is not defined (yet).
.if defined
. error
.else
-. info A plain function name is parsed as !empty(...).
+# expect+1: A plain function name is parsed as defined(...).
+. info A plain function name is parsed as defined(...).
.endif
-# If a variable named 'defined' is actually defined and not empty, the plain
-# symbol 'defined' evaluates to true.
-defined= non-empty
+# If a variable named 'defined' is actually defined, the bare word 'defined'
+# is interpreted as 'defined(defined)', and the condition evaluates to true.
+defined= # defined but empty
.if defined
-. info A plain function name is parsed as !empty(...).
+# expect+1: A plain function name is parsed as defined(...).
+. info A plain function name is parsed as defined(...).
.else
. error
.endif
@@ -116,22 +123,21 @@ defined= non-empty
.if defined-var
. error
.else
+# expect+1: Symbols may start with a function name.
. info Symbols may start with a function name.
.endif
-defined-var= non-empty
+defined-var= # defined but empty
.if defined-var
+# expect+1: Symbols may start with a function name.
. info Symbols may start with a function name.
.else
. error
.endif
-# Missing closing parenthesis when parsing the function argument.
+# expect+1: Missing closing parenthesis for defined()
.if defined(
. error
.else
. error
.endif
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/cond-late.exp b/contrib/bmake/unit-tests/cond-late.exp
index e179e8c74cc4..703677da634c 100644
--- a/contrib/bmake/unit-tests/cond-late.exp
+++ b/contrib/bmake/unit-tests/cond-late.exp
@@ -1,4 +1,4 @@
-make: Bad conditional expression ' != "no"' in ' != "no"?:'
+make: Bad conditional expression ' != "no"' before '?:'
yes
no
exit status 0
diff --git a/contrib/bmake/unit-tests/cond-late.mk b/contrib/bmake/unit-tests/cond-late.mk
index 4df3df2cf1d4..8e3d41f60001 100644
--- a/contrib/bmake/unit-tests/cond-late.mk
+++ b/contrib/bmake/unit-tests/cond-late.mk
@@ -1,11 +1,12 @@
-# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: cond-late.mk,v 1.6 2023/12/10 20:12:28 rillig Exp $
#
-# Using the :? modifier, variable expressions can contain conditional
+# Using the :? modifier, expressions can contain conditional
# expressions that are evaluated late, at expansion time.
#
-# Any variables appearing in these
-# conditions are expanded before parsing the condition. This is
-# different from many other places.
+# Any expressions appearing in these conditions are expanded before parsing
+# the condition. This is different from conditions in .if directives, where
+# expressions are evaluated individually and only as far as necessary, see
+# cond-short.mk.
#
# Because of this, variables that are used in these lazy conditions
# should not contain double-quotes, or the parser will probably fail.
@@ -22,10 +23,14 @@ COND.false= "yes" != "yes"
# If the order of evaluation were to change to first parse the condition
# and then expand the variables, the output would change from the
# current "yes no" to "yes yes", since both variables are non-empty.
+# expect: yes
+# expect: no
cond-literal:
@echo ${ ${COND.true} :?yes:no}
@echo ${ ${COND.false} :?yes:no}
-VAR+= ${${UNDEF} != "no":?:}
+VAR= ${${UNDEF} != "no":?:}
+# expect-reset
+# expect: make: Bad conditional expression ' != "no"' before '?:'
.if empty(VAR:Mpattern)
.endif
diff --git a/contrib/bmake/unit-tests/cond-op-and-lint.exp b/contrib/bmake/unit-tests/cond-op-and-lint.exp
index 8817fd0d658b..0f2cdb0028f9 100644
--- a/contrib/bmake/unit-tests/cond-op-and-lint.exp
+++ b/contrib/bmake/unit-tests/cond-op-and-lint.exp
@@ -1,4 +1,4 @@
-make: "cond-op-and-lint.mk" line 9: Unknown operator '&'
+make: "cond-op-and-lint.mk" line 10: Unknown operator '&'
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-and-lint.mk b/contrib/bmake/unit-tests/cond-op-and-lint.mk
index 6262339016f5..bac4566314b0 100644
--- a/contrib/bmake/unit-tests/cond-op-and-lint.mk
+++ b/contrib/bmake/unit-tests/cond-op-and-lint.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-and-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+# $NetBSD: cond-op-and-lint.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the && operator in .if conditions, in lint mode.
@@ -6,6 +6,7 @@
# The '&' operator is not allowed in lint mode.
# It is not used in practice anyway.
+# expect+1: Unknown operator '&'
.if 0 & 0
. error
.else
diff --git a/contrib/bmake/unit-tests/cond-op-and.exp b/contrib/bmake/unit-tests/cond-op-and.exp
index 173b6861a98b..6d5a14b211cc 100644
--- a/contrib/bmake/unit-tests/cond-op-and.exp
+++ b/contrib/bmake/unit-tests/cond-op-and.exp
@@ -1,4 +1,7 @@
-make: "cond-op-and.mk" line 43: Malformed conditional (0 &&& 0)
+make: "cond-op-and.mk" line 37: Malformed conditional (0 || (${DEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 42: Malformed conditional (0 || (${UNDEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 45: Malformed conditional (0 || (!${UNDEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 75: Malformed conditional (0 &&& 0)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-and.mk b/contrib/bmake/unit-tests/cond-op-and.mk
index 83c694f15723..19a0672ba44e 100644
--- a/contrib/bmake/unit-tests/cond-op-and.mk
+++ b/contrib/bmake/unit-tests/cond-op-and.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-and.mk,v 1.5 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-op-and.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $
#
# Tests for the && operator in .if conditions.
@@ -18,11 +18,42 @@
. error
.endif
+
# The right-hand side is not evaluated since the left-hand side is already
# false.
.if 0 && ${UNDEF}
.endif
+# When an outer condition makes the inner '&&' condition irrelevant, neither
+# of its operands must be evaluated.
+#
+.if 1 || (${UNDEF} && ${UNDEF})
+.endif
+
+# Test combinations of outer '||' with inner '&&', to ensure that the operands
+# of the inner '&&' are only evaluated if necessary.
+DEF= defined
+# expect+1: Malformed conditional (0 || (${DEF} && ${UNDEF}))
+.if 0 || (${DEF} && ${UNDEF})
+.endif
+.if 0 || (!${DEF} && ${UNDEF})
+.endif
+# expect+1: Malformed conditional (0 || (${UNDEF} && ${UNDEF}))
+.if 0 || (${UNDEF} && ${UNDEF})
+.endif
+# expect+1: Malformed conditional (0 || (!${UNDEF} && ${UNDEF}))
+.if 0 || (!${UNDEF} && ${UNDEF})
+.endif
+.if 1 || (${DEF} && ${UNDEF})
+.endif
+.if 1 || (!${DEF} && ${UNDEF})
+.endif
+.if 1 || (${UNDEF} && ${UNDEF})
+.endif
+.if 1 || (!${UNDEF} && ${UNDEF})
+.endif
+
+
# The && operator may be abbreviated as &. This is not widely known though
# and is also not documented in the manual page.
@@ -40,9 +71,14 @@
.endif
# There is no operator &&&.
+# expect+1: Malformed conditional (0 &&& 0)
.if 0 &&& 0
. error
.endif
-all:
- @:;
+# The '&&' operator must be preceded by whitespace, otherwise it becomes part
+# of the preceding bare word. The condition is parsed as '"1&&" != "" && 1'.
+.if 1&& && 1
+.else
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/cond-op-not.exp b/contrib/bmake/unit-tests/cond-op-not.exp
index 440670ca7249..fcdceee9af21 100644
--- a/contrib/bmake/unit-tests/cond-op-not.exp
+++ b/contrib/bmake/unit-tests/cond-op-not.exp
@@ -1,9 +1,9 @@
-make: "cond-op-not.mk" line 29: Not empty evaluates to true.
-make: "cond-op-not.mk" line 37: Not space evaluates to false.
-make: "cond-op-not.mk" line 41: Not 0 evaluates to true.
-make: "cond-op-not.mk" line 49: Not 1 evaluates to false.
-make: "cond-op-not.mk" line 55: Not word evaluates to false.
-make: "cond-op-not.mk" line 59: Malformed conditional (!)
+make: "cond-op-not.mk" line 30: Not empty evaluates to true.
+make: "cond-op-not.mk" line 39: Not space evaluates to false.
+make: "cond-op-not.mk" line 44: Not 0 evaluates to true.
+make: "cond-op-not.mk" line 53: Not 1 evaluates to false.
+make: "cond-op-not.mk" line 60: Not word evaluates to false.
+make: "cond-op-not.mk" line 65: Malformed conditional (!)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-not.mk b/contrib/bmake/unit-tests/cond-op-not.mk
index ffd5bc89e4bf..28f835fa3cbd 100644
--- a/contrib/bmake/unit-tests/cond-op-not.mk
+++ b/contrib/bmake/unit-tests/cond-op-not.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-not.mk,v 1.7 2021/01/19 17:49:13 rillig Exp $
+# $NetBSD: cond-op-not.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the ! operator in .if conditions, which negates its argument.
@@ -26,6 +26,7 @@
.endif
.if !${:U}
+# expect+1: Not empty evaluates to true.
. info Not empty evaluates to true.
.else
. info Not empty evaluates to false.
@@ -34,10 +35,12 @@
.if !${:U }
. info Not space evaluates to true.
.else
+# expect+1: Not space evaluates to false.
. info Not space evaluates to false.
.endif
.if !${:U0}
+# expect+1: Not 0 evaluates to true.
. info Not 0 evaluates to true.
.else
. info Not 0 evaluates to false.
@@ -46,16 +49,19 @@
.if !${:U1}
. info Not 1 evaluates to true.
.else
+# expect+1: Not 1 evaluates to false.
. info Not 1 evaluates to false.
.endif
.if !${:Uword}
. info Not word evaluates to true.
.else
+# expect+1: Not word evaluates to false.
. info Not word evaluates to false.
.endif
# A single exclamation mark is a parse error.
+# expect+1: Malformed conditional (!)
.if !
. error
.else
diff --git a/contrib/bmake/unit-tests/cond-op-or-lint.exp b/contrib/bmake/unit-tests/cond-op-or-lint.exp
index 8abae99b6c4c..0fb1d0dae166 100644
--- a/contrib/bmake/unit-tests/cond-op-or-lint.exp
+++ b/contrib/bmake/unit-tests/cond-op-or-lint.exp
@@ -1,4 +1,4 @@
-make: "cond-op-or-lint.mk" line 9: Unknown operator '|'
+make: "cond-op-or-lint.mk" line 10: Unknown operator '|'
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-or-lint.mk b/contrib/bmake/unit-tests/cond-op-or-lint.mk
index aa29e9a6c2f2..9ece9d5c9af6 100644
--- a/contrib/bmake/unit-tests/cond-op-or-lint.mk
+++ b/contrib/bmake/unit-tests/cond-op-or-lint.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-or-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+# $NetBSD: cond-op-or-lint.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the || operator in .if conditions, in lint mode.
@@ -6,6 +6,7 @@
# The '|' operator is not allowed in lint mode.
# It is not used in practice anyway.
+# expect+1: Unknown operator '|'
.if 0 | 0
. error
.else
diff --git a/contrib/bmake/unit-tests/cond-op-or.exp b/contrib/bmake/unit-tests/cond-op-or.exp
index 7888a475e3e4..b10bc4bf7c52 100644
--- a/contrib/bmake/unit-tests/cond-op-or.exp
+++ b/contrib/bmake/unit-tests/cond-op-or.exp
@@ -1,4 +1,7 @@
-make: "cond-op-or.mk" line 43: Malformed conditional (0 ||| 0)
+make: "cond-op-or.mk" line 47: Malformed conditional (1 && (!${DEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 50: Malformed conditional (1 && (${UNDEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 53: Malformed conditional (1 && (!${UNDEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 75: Malformed conditional (0 ||| 0)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-or.mk b/contrib/bmake/unit-tests/cond-op-or.mk
index c6993e7c277e..165408f3c130 100644
--- a/contrib/bmake/unit-tests/cond-op-or.mk
+++ b/contrib/bmake/unit-tests/cond-op-or.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-or.mk,v 1.6 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-op-or.mk,v 1.11 2023/12/17 09:44:00 rillig Exp $
#
# Tests for the || operator in .if conditions.
@@ -18,11 +18,42 @@
. error
.endif
+
# The right-hand side is not evaluated since the left-hand side is already
# true.
.if 1 || ${UNDEF}
.endif
+# When an outer condition makes the inner '||' condition irrelevant, neither
+# of its operands must be evaluated. This had been wrong in cond.c 1.283 from
+# 2021-12-09 and was reverted in cond.c 1.284 an hour later.
+.if 0 && (!defined(UNDEF) || ${UNDEF})
+.endif
+
+# Test combinations of outer '&&' with inner '||', to ensure that the operands
+# of the inner '||' is only evaluated if necessary.
+DEF= defined
+.if 0 && (${DEF} || ${UNDEF})
+.endif
+.if 0 && (!${DEF} || ${UNDEF})
+.endif
+.if 0 && (${UNDEF} || ${UNDEF})
+.endif
+.if 0 && (!${UNDEF} || ${UNDEF})
+.endif
+.if 1 && (${DEF} || ${UNDEF})
+.endif
+# expect+1: Malformed conditional (1 && (!${DEF} || ${UNDEF}))
+.if 1 && (!${DEF} || ${UNDEF})
+.endif
+# expect+1: Malformed conditional (1 && (${UNDEF} || ${UNDEF}))
+.if 1 && (${UNDEF} || ${UNDEF})
+.endif
+# expect+1: Malformed conditional (1 && (!${UNDEF} || ${UNDEF}))
+.if 1 && (!${UNDEF} || ${UNDEF})
+.endif
+
+
# The || operator may be abbreviated as |. This is not widely known though
# and is also not documented in the manual page.
@@ -40,9 +71,14 @@
.endif
# There is no operator |||.
+# expect+1: Malformed conditional (0 ||| 0)
.if 0 ||| 0
. error
.endif
-all:
- @:;
+# The '||' operator must be preceded by whitespace, otherwise it becomes part
+# of the preceding bare word. The condition is parsed as '"1||" != "" || 0'.
+.if 1|| || 0
+.else
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/cond-op-parentheses.exp b/contrib/bmake/unit-tests/cond-op-parentheses.exp
index b44093304100..1daad92b2682 100644
--- a/contrib/bmake/unit-tests/cond-op-parentheses.exp
+++ b/contrib/bmake/unit-tests/cond-op-parentheses.exp
@@ -1,6 +1,7 @@
-make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112.
-make: "cond-op-parentheses.mk" line 19: Malformed conditional (()
-make: "cond-op-parentheses.mk" line 29: Malformed conditional ())
+make: "cond-op-parentheses.mk" line 22: Comparison with '>' requires both operands '3' and '(2' to be numeric
+make: "cond-op-parentheses.mk" line 25: Malformed conditional ((3) > 2)
+make: "cond-op-parentheses.mk" line 44: Malformed conditional (()
+make: "cond-op-parentheses.mk" line 58: Malformed conditional ())
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op-parentheses.mk b/contrib/bmake/unit-tests/cond-op-parentheses.mk
index ca288cad5826..b6c9bd3c0e9d 100644
--- a/contrib/bmake/unit-tests/cond-op-parentheses.mk
+++ b/contrib/bmake/unit-tests/cond-op-parentheses.mk
@@ -1,8 +1,29 @@
-# $NetBSD: cond-op-parentheses.mk,v 1.4 2021/01/19 17:49:13 rillig Exp $
+# $NetBSD: cond-op-parentheses.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $
#
-# Tests for parentheses in .if conditions.
+# Tests for parentheses in .if conditions, which group expressions to override
+# the precedence of the operators '!', '&&' and '||'. Parentheses cannot be
+# used to form arithmetic expressions such as '(3+4)' though.
-# TODO: Implementation
+# Contrary to the C family of programming languages, the outermost condition
+# does not have to be enclosed in parentheses.
+.if defined(VAR)
+. error
+.elif !1
+. error
+.endif
+
+# Parentheses cannot enclose numbers as there is no need for it. Make does
+# not implement any arithmetic functions in its condition parser. If
+# absolutely necessary, use expr(1).
+#
+# XXX: It's inconsistent that the right operand has unbalanced parentheses.
+#
+# expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric
+.if 3 > (2)
+.endif
+# expect+1: Malformed conditional ((3) > 2)
+.if (3) > 2
+.endif
# Test for deeply nested conditions.
.if (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \
@@ -10,12 +31,16 @@
1 \
)))))))))))))))))))))))))))))))))))))))))))))))))))))))) \
))))))))))))))))))))))))))))))))))))))))))))))))))))))))
-. info Parentheses can be nested at least to depth 112.
+# Parentheses can be nested at least to depth 112. There is nothing special
+# about this number though, much higher numbers work as well, at least on
+# NetBSD. The actual limit depends on the allowed call stack depth for C code
+# of the platform. Anyway, 112 should be enough for all practical purposes.
.else
. error
.endif
# An unbalanced opening parenthesis is a parse error.
+# expect+1: Malformed conditional (()
.if (
. error
.else
@@ -24,8 +49,12 @@
# An unbalanced closing parenthesis is a parse error.
#
-# As of 2021-01-19, CondParser_Term returned TOK_RPAREN even though this
-# function promised to only ever return TOK_TRUE, TOK_FALSE or TOK_ERROR.
+# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
+# even though the documentation of that function promised to only ever return
+# TOK_TRUE, TOK_FALSE or TOK_ERROR. In cond.c 1.241, the return type of that
+# function was changed to a properly restricted enum type, to prevent this bug
+# from occurring again.
+# expect+1: Malformed conditional ())
.if )
. error
.else
diff --git a/contrib/bmake/unit-tests/cond-op.exp b/contrib/bmake/unit-tests/cond-op.exp
index 28e8d48e2697..33bab484a6c8 100644
--- a/contrib/bmake/unit-tests/cond-op.exp
+++ b/contrib/bmake/unit-tests/cond-op.exp
@@ -1,20 +1,21 @@
-make: "cond-op.mk" line 50: Malformed conditional ("!word" == !word)
-make: "cond-op.mk" line 75: Malformed conditional (0 ${ERR::=evaluated})
-make: "cond-op.mk" line 79: After detecting a parse error, the rest is evaluated.
-make: "cond-op.mk" line 83: Parsing continues until here.
-make: "cond-op.mk" line 86: A B C => (A || B) && C A || B && C A || (B && C)
-make: "cond-op.mk" line 93: 0 0 0 => 0 0 0
-make: "cond-op.mk" line 93: 0 0 1 => 0 0 0
-make: "cond-op.mk" line 93: 0 1 0 => 0 0 0
-make: "cond-op.mk" line 93: 0 1 1 => 1 1 1
-make: "cond-op.mk" line 93: 1 0 0 => 0 1 1
-make: "cond-op.mk" line 93: 1 0 1 => 1 1 1
-make: "cond-op.mk" line 93: 1 1 0 => 0 1 1
-make: "cond-op.mk" line 93: 1 1 1 => 1 1 1
-make: "cond-op.mk" line 104: Malformed conditional (1 &&)
-make: "cond-op.mk" line 112: Malformed conditional (0 &&)
-make: "cond-op.mk" line 120: Malformed conditional (1 ||)
-make: "cond-op.mk" line 129: Malformed conditional (0 ||)
+make: "cond-op.mk" line 51: Malformed conditional ("!word" == !word)
+make: "cond-op.mk" line 72: Malformed conditional (0 ${ERR::=evaluated})
+make: "cond-op.mk" line 77: A misplaced expression after 0 is not evaluated.
+make: "cond-op.mk" line 82: Malformed conditional (1 ${ERR::=evaluated})
+make: "cond-op.mk" line 87: A misplaced expression after 1 is not evaluated.
+make: "cond-op.mk" line 93: A B C => (A || B) && C A || B && C A || (B && C)
+make: "cond-op.mk" line 108: 0 0 0 => 0 0 0
+make: "cond-op.mk" line 108: 0 0 1 => 0 0 0
+make: "cond-op.mk" line 108: 0 1 0 => 0 0 0
+make: "cond-op.mk" line 108: 0 1 1 => 1 1 1
+make: "cond-op.mk" line 108: 1 0 0 => 0 1 1
+make: "cond-op.mk" line 108: 1 0 1 => 1 1 1
+make: "cond-op.mk" line 108: 1 1 0 => 0 1 1
+make: "cond-op.mk" line 108: 1 1 1 => 1 1 1
+make: "cond-op.mk" line 120: Malformed conditional (1 &&)
+make: "cond-op.mk" line 129: Malformed conditional (0 &&)
+make: "cond-op.mk" line 138: Malformed conditional (1 ||)
+make: "cond-op.mk" line 148: Malformed conditional (0 ||)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-op.mk b/contrib/bmake/unit-tests/cond-op.mk
index 2ed451c90391..6371e4db0594 100644
--- a/contrib/bmake/unit-tests/cond-op.mk
+++ b/contrib/bmake/unit-tests/cond-op.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op.mk,v 1.13 2021/01/19 18:20:30 rillig Exp $
+# $NetBSD: cond-op.mk,v 1.16 2023/06/01 20:56:35 rillig Exp $
#
# Tests for operators like &&, ||, ! in .if conditions.
#
@@ -47,6 +47,7 @@
# appear unquoted. If any, it must be enclosed in quotes.
# In any case, it is not interpreted as a negation of an unquoted string.
# See CondParser_String.
+# expect+1: Malformed conditional ("!word" == !word)
.if "!word" == !word
. error
.endif
@@ -58,31 +59,37 @@
. error
.endif
-# As soon as the parser sees the '$', it knows that the condition will
-# be malformed. Therefore there is no point in evaluating it.
+# In the following malformed conditions, as soon as the parser sees the '$'
+# after the '0' or the '1', it knows that the condition will be malformed.
+# Therefore there is no point in evaluating the misplaced expression.
#
-# As of 2021-01-20, that part of the condition is evaluated nevertheless,
-# since CondParser_Or just requests the next token, without restricting
-# the token to the expected tokens. If the parser were to restrict the
-# valid follow tokens for the token "0" to those that can actually produce
-# a correct condition (which in this case would be comparison operators,
-# TOK_AND, TOK_OR or TOK_RPAREN), the variable expression would not have
-# to be evaluated.
-#
-# This would add a good deal of complexity to the code though, for almost
-# no benefit, especially since most expressions and conditions are side
-# effect free.
+# Before cond.c 1.286 from 2021-12-10, the extra expression was evaluated
+# nevertheless, since CondParser_Or and CondParser_And asked for the expanded
+# next token, even though in this position of the condition, only comparison
+# operators, TOK_AND, TOK_OR or TOK_RPAREN are allowed.
+.undef ERR
+# expect+1: Malformed conditional (0 ${ERR::=evaluated})
.if 0 ${ERR::=evaluated}
. error
.endif
-.if ${ERR:Uundefined} == evaluated
-. info After detecting a parse error, the rest is evaluated.
+.if ${ERR:Uundefined} == undefined
+# expect+1: A misplaced expression after 0 is not evaluated.
+. info A misplaced expression after 0 is not evaluated.
+.endif
+
+.undef ERR
+# expect+1: Malformed conditional (1 ${ERR::=evaluated})
+.if 1 ${ERR::=evaluated}
+. error
+.endif
+.if ${ERR:Uundefined} == undefined
+# expect+1: A misplaced expression after 1 is not evaluated.
+. info A misplaced expression after 1 is not evaluated.
.endif
-# Just in case that parsing should ever stop on the first error.
-.info Parsing continues until here.
# Demonstration that '&&' has higher precedence than '||'.
+# expect+1: A B C => (A || B) && C A || B && C A || (B && C)
.info A B C => (A || B) && C A || B && C A || (B && C)
.for a in 0 1
. for b in 0 1
@@ -90,6 +97,14 @@
. for r1 in ${ ($a || $b) && $c :?1:0}
. for r2 in ${ $a || $b && $c :?1:0}
. for r3 in ${ $a || ($b && $c) :?1:0}
+# expect+8: 0 0 0 => 0 0 0
+# expect+7: 0 0 1 => 0 0 0
+# expect+6: 0 1 0 => 0 0 0
+# expect+5: 0 1 1 => 1 1 1
+# expect+4: 1 0 0 => 0 1 1
+# expect+3: 1 0 1 => 1 1 1
+# expect+2: 1 1 0 => 0 1 1
+# expect+1: 1 1 1 => 1 1 1
. info $a $b $c => ${r1} ${r2} ${r3}
. endfor
. endfor
@@ -101,6 +116,7 @@
# This condition is obviously malformed. It is properly detected and also
# was properly detected before 2021-01-19, but only because the left hand
# side of the '&&' evaluated to true.
+# expect+1: Malformed conditional (1 &&)
.if 1 &&
. error
.else
@@ -109,6 +125,7 @@
# This obviously malformed condition was not detected as such before cond.c
# 1.238 from 2021-01-19.
+# expect+1: Malformed conditional (0 &&)
.if 0 &&
. error
.else
@@ -117,6 +134,7 @@
# This obviously malformed condition was not detected as such before cond.c
# 1.238 from 2021-01-19.
+# expect+1: Malformed conditional (1 ||)
.if 1 ||
. error
.else
@@ -126,6 +144,7 @@
# This condition is obviously malformed. It is properly detected and also
# was properly detected before 2021-01-19, but only because the left hand
# side of the '||' evaluated to false.
+# expect+1: Malformed conditional (0 ||)
.if 0 ||
. error
.else
diff --git a/contrib/bmake/unit-tests/cond-short.exp b/contrib/bmake/unit-tests/cond-short.exp
index 2865dcb6ef33..44681b57ebc1 100644
--- a/contrib/bmake/unit-tests/cond-short.exp
+++ b/contrib/bmake/unit-tests/cond-short.exp
@@ -7,10 +7,7 @@ expected M pattern
expected or
expected or exists
expected or empty
-defined(V42) && ${V42} > 0: Ok
-defined(V66) && ( "${iV2}" < ${V42} ): Ok
-1 || ${iV1} < ${V42}: Ok
-1 || ${iV2:U2} < ${V42}: Ok
-0 || ${iV1} <= ${V42}: Ok
-0 || ${iV2:U2} < ${V42}: Ok
-exit status 0
+make: "cond-short.mk" line 231: Comparison with '<' requires both operands '' and '42' to be numeric
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/cond-short.mk b/contrib/bmake/unit-tests/cond-short.mk
index 113c3fd08fed..bcdf372ca6e6 100644
--- a/contrib/bmake/unit-tests/cond-short.mk
+++ b/contrib/bmake/unit-tests/cond-short.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.16 2021/03/14 11:49:37 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.23 2023/11/19 22:32:44 rillig Exp $
#
# Demonstrates that in conditions, the right-hand side of an && or ||
# is only evaluated if it can actually influence the result.
@@ -9,10 +9,23 @@
# Before 2020-06-28, the right-hand side of an && or || operator was always
# evaluated, which was wrong. In cond.c 1.69 and var.c 1.197 on 2015-10-11,
# Var_Parse got a new parameter named 'wantit'. Since then it would have been
-# possible to skip evaluation of irrelevant variable expressions and only
+# possible to skip evaluation of irrelevant expressions and only
# parse them. They were still evaluated though, the only difference to
-# relevant variable expressions was that in the irrelevant variable
-# expressions, undefined variables were allowed.
+# relevant expressions was that in the irrelevant
+# expressions, undefined variables were allowed. This allowed for conditions
+# like 'defined(VAR) && ${VAR:S,from,to,} != ""', which no longer produced an
+# error message 'Malformed conditional', but the irrelevant expression was
+# still evaluated.
+#
+# Since the initial commit on 1993-03-21, the manual page has been saying that
+# make 'will only evaluate a conditional as far as is necessary to determine',
+# but that was wrong. The code in cond.c 1.1 from 1993-03-21 looks good since
+# it calls Var_Parse(condExpr, VAR_CMD, doEval,&varSpecLen,&doFree), but the
+# definition of Var_Parse did not call the third parameter 'doEval', as would
+# be expected, but instead 'err', accompanied by the comment 'TRUE if
+# undefined variables are an error'. This subtle difference between 'do not
+# evaluate at all' and 'allow undefined variables' led to the unexpected
+# evaluation.
#
# See also:
# var-eval-short.mk, for short-circuited variable modifiers
@@ -109,7 +122,9 @@ VAR= # empty again, for the following tests
.if 0 || empty(${echo "expected or empty" 1>&2 :L:sh})
.endif
-# Unreachable nested conditions are skipped completely as well.
+# Unreachable nested conditions are skipped completely as well. These skipped
+# lines may even contain syntax errors. This allows to skip syntactically
+# incompatible new features in older versions of make.
.if 0
. if ${echo "unexpected nested and" 1>&2 :L:sh}
@@ -120,28 +135,32 @@ VAR= # empty again, for the following tests
.elif ${echo "unexpected nested or" 1>&2 :L:sh}
.endif
-# make sure these do not cause complaint
-#.MAKEFLAGS: -dc
-# TODO: Rewrite this whole section and check all the conditions and variables.
-# Several of the assumptions are probably wrong here.
-# TODO: replace 'x=' with '.info' or '.error'.
-V42= 42
-iV1= ${V42}
-iV2= ${V66}
+NUMBER= 42
+INDIR_NUMBER= ${NUMBER}
+INDIR_UNDEF= ${UNDEF}
-.if defined(V42) && ${V42} > 0
-x= Ok
+.if defined(NUMBER) && ${NUMBER} > 0
.else
-x= Fail
+. error
.endif
-x!= echo 'defined(V42) && $${V42} > 0: $x' >&2; echo
-# With cond.c 1.76 from 2020-07-03, the following condition triggered a
-# warning: "String comparison operator should be either == or !=".
-# This was because the variable expression ${iV2} was defined, but the
-# contained variable V66 was undefined. The left-hand side of the comparison
-# therefore evaluated to the string "${V66}", which is obviously not a number.
+# Starting with var.c 1.226 from from 2020-07-02, the following condition
+# triggered a warning: "String comparison operator should be either == or !=".
+#
+# The left-hand side of the '&&' evaluated to false, which should have made
+# the right-hand side irrelevant.
+#
+# On the right-hand side of the '&&', the expression ${INDIR_UNDEF} was
+# defined and had the value '${UNDEF}', but the nested variable UNDEF was
+# undefined. The right hand side "${INDIR_UNDEF}" still needed to be parsed,
+# and in parse-only mode, the "value" of the parsed expression was the
+# uninterpreted variable value, in this case '${UNDEF}'. And even though the
+# right hand side of the '&&' should have been irrelevant, the two sides of
+# the comparison were still parsed and evaluated. Comparing these two values
+# numerically was not possible since the string '${UNDEF}' is not a number,
+# so the comparison fell back to string comparison, which then complained
+# about the '>' operator.
#
# This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant
# comparisons. Instead, they are only parsed and then discarded.
@@ -149,59 +168,94 @@ x!= echo 'defined(V42) && $${V42} > 0: $x' >&2; echo
# At that time, there was not enough debug logging to see the details in the
# -dA log. To actually see it, add debug logging at the beginning and end of
# Var_Parse.
-.if defined(V66) && ( ${iV2} < ${V42} )
-x= Fail
-.else
-x= Ok
+.if defined(UNDEF) && ${INDIR_UNDEF} < ${NUMBER}
+. error
+.endif
+# Adding a ':U' modifier to the irrelevant expression didn't help, as that
+# expression was only parsed, not evaluated. The resulting literal string
+# '${INDIR_UNDEF:U2}' was not numeric either, for the same reason as above.
+.if defined(UNDEF) && ${INDIR_UNDEF:U2} < ${NUMBER}
+. error
.endif
-# XXX: This condition doesn't match the one above. The quotes are missing
-# above. This is a crucial detail since without quotes, the variable
-# expression ${iV2} evaluates to "${V66}", and with quotes, it evaluates to ""
-# since undefined variables are allowed and expand to an empty string.
-x!= echo 'defined(V66) && ( "$${iV2}" < $${V42} ): $x' >&2; echo
-.if 1 || ${iV1} < ${V42}
-x= Ok
-.else
-x= Fail
+
+# Since cond.c 1.76 from 2020.06.28 and before var.c 1.225 from 2020.07.01,
+# the following snippet resulted in the error message 'Variable VAR is
+# recursive'. The condition '0' evaluated to false, which made the right-hand
+# side of the '&&' irrelevant. Back then, irrelevant condition parts were
+# still evaluated, but in "irrelevant mode", which allowed undefined variables
+# to occur in expressions. In this mode, the variable name 'VAR' was
+# unnecessarily evaluated, resulting in the expression '${VAR${:U1}}'. In
+# this expression, the variable name was 'VAR${:U1}', and of this variable
+# name, only the fixed part 'VAR' was evaluated, without the part '${:U1}'.
+# This partial evaluation led to the wrong error message about 'VAR' being
+# recursive.
+VAR= ${VAR${:U1}}
+.if 0 && !empty(VAR)
.endif
-x!= echo '1 || $${iV1} < $${V42}: $x' >&2; echo
-# With cond.c 1.76 from 2020-07-03, the following condition triggered a
-# warning: "String comparison operator should be either == or !=".
-# This was because the variable expression ${iV2} was defined, but the
-# contained variable V66 was undefined. The left-hand side of the comparison
-# therefore evaluated to the string "${V66}", which is obviously not a number.
+
+# Enclosing the expression in double quotes changes how that expression is
+# evaluated. In irrelevant expressions that are enclosed in double quotes,
+# expressions based on undefined variables are allowed and evaluate to an
+# empty string.
#
-# This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant
-# comparisons. Instead, they are only parsed and then discarded.
+# The manual page stated from at least 1993 on that irrelevant conditions were
+# not evaluated, but that was wrong. These conditions were evaluated, the
+# only difference was that undefined variables in them didn't trigger an
+# error. Since numeric conditions are quite rare, this subtle difference
+# didn't catch much attention, as most other conditions such as pattern
+# matches or equality comparisons worked fine and never produced error
+# messages.
+.if defined(UNDEF) && "${INDIR_UNDEF}" < ${NUMBER}
+. error
+.endif
+
+# Since the condition is relevant, the indirect undefined variable is
+# evaluated as usual, resolving nested undefined expressions to an empty
+# string.
#
-# At that time, there was not enough debug logging to see the details in the
-# -dA log. To actually see it, add debug logging at the beginning and end of
-# Var_Parse.
-.if 1 || ${iV2:U2} < ${V42}
-x= Ok
+# Comparing an empty string numerically is not possible, however, make has an
+# ugly hack in TryParseNumber that treats an empty string as a valid numerical
+# value, thus hiding bugs in the makefile.
+.if ${INDIR_UNDEF} < ${NUMBER}
+# only due to the ugly hack
+.else
+. error
+.endif
+
+# Due to the quotes around the left-hand side of the '<', the operand is
+# marked as a string, thus preventing a numerical comparison.
+#
+# expect+1: Comparison with '<' requires both operands '' and '42' to be numeric
+.if "${INDIR_UNDEF}" < ${NUMBER}
+. info yes
.else
-x= Fail
+. info no
.endif
-x!= echo '1 || $${iV2:U2} < $${V42}: $x' >&2; echo
-# the same expressions are fine when the lhs is expanded
-# ${iV1} expands to 42
-.if 0 || ${iV1} <= ${V42}
-x= Ok
+# The right-hand side of '||' is irrelevant and thus not evaluated.
+.if 1 || ${INDIR_NUMBER} < ${NUMBER}
.else
-x= Fail
+. error
+.endif
+
+# The right-hand side of '||' is relevant and thus evaluated normally.
+.if 0 || ${INDIR_NUMBER} < ${NUMBER}
+. error
.endif
-x!= echo '0 || $${iV1} <= $${V42}: $x' >&2; echo
-# ${iV2:U2} expands to 2
-.if 0 || ${iV2:U2} < ${V42}
-x= Ok
+# The right-hand side of '||' evaluates to an empty string, as the variable
+# 'INDIR_UNDEF' is defined, therefore the modifier ':U2' has no effect.
+# Comparing an empty string numerically is not possible, however, make has an
+# ugly hack in TryParseNumber that treats an empty string as a valid numerical
+# value, thus hiding bugs in the makefile.
+.if 0 || ${INDIR_UNDEF:U2} < ${NUMBER}
+# only due to the ugly hack
.else
-x= Fail
+. error
.endif
-x!= echo '0 || $${iV2:U2} < $${V42}: $x' >&2; echo
+
# The right-hand side of the '&&' is irrelevant since the left-hand side
# already evaluates to false. Before cond.c 1.79 from 2020-07-09, it was
@@ -211,4 +265,56 @@ x!= echo '0 || $${iV2:U2} < $${V42}: $x' >&2; echo
. error
.endif
+
+# Ensure that irrelevant conditions do not influence the result of the whole
+# condition. As of cond.c 1.302 from 2021-12-11, an irrelevant function call
+# evaluated to true (see CondParser_FuncCall and CondParser_FuncCallEmpty), an
+# irrelevant comparison evaluated to false (see CondParser_Comparison).
+#
+# An irrelevant true bubbles up to the outermost CondParser_And, where it is
+# ignored. An irrelevant false bubbles up to the outermost CondParser_Or,
+# where it is ignored.
+#
+# If the condition parser should ever be restructured, the bubbling up of the
+# irrelevant evaluation results might show up accidentally. Prevent this.
+DEF= defined
+.undef UNDEF
+
+.if 0 && defined(DEF)
+. error
+.endif
+
+.if 1 && defined(DEF)
+.else
+. error
+.endif
+
+.if 0 && defined(UNDEF)
+. error
+.endif
+
+.if 1 && defined(UNDEF)
+. error
+.endif
+
+.if 0 || defined(DEF)
+.else
+. error
+.endif
+
+.if 1 || defined(DEF)
+.else
+. error
+.endif
+
+.if 0 || defined(UNDEF)
+. error
+.endif
+
+.if 1 || defined(UNDEF)
+.else
+. error
+.endif
+
+
all:
diff --git a/contrib/bmake/unit-tests/cond-token-number.exp b/contrib/bmake/unit-tests/cond-token-number.exp
index b5bfaf95d575..d05833b4e01b 100644
--- a/contrib/bmake/unit-tests/cond-token-number.exp
+++ b/contrib/bmake/unit-tests/cond-token-number.exp
@@ -1,8 +1,7 @@
-make: "cond-token-number.mk" line 15: Malformed conditional (-0)
-make: "cond-token-number.mk" line 25: Malformed conditional (+0)
-make: "cond-token-number.mk" line 35: Malformed conditional (!-1)
-make: "cond-token-number.mk" line 45: Malformed conditional (!+1)
-make: "cond-token-number.mk" line 80: End of the tests.
+make: "cond-token-number.mk" line 16: Malformed conditional (-0)
+make: "cond-token-number.mk" line 27: Malformed conditional (+0)
+make: "cond-token-number.mk" line 38: Malformed conditional (!-1)
+make: "cond-token-number.mk" line 49: Malformed conditional (!+1)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-token-number.mk b/contrib/bmake/unit-tests/cond-token-number.mk
index 93e2646a60eb..7e73f8b76f94 100644
--- a/contrib/bmake/unit-tests/cond-token-number.mk
+++ b/contrib/bmake/unit-tests/cond-token-number.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-number.mk,v 1.5 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-token-number.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $
#
# Tests for number tokens in .if conditions.
#
@@ -12,6 +12,7 @@
# accepted by the condition parser.
#
# See the ch_isdigit call in CondParser_String.
+# expect+1: Malformed conditional (-0)
.if -0
. error
.else
@@ -22,6 +23,7 @@
# accepted by the condition parser.
#
# See the ch_isdigit call in CondParser_String.
+# expect+1: Malformed conditional (+0)
.if +0
. error
.else
@@ -32,6 +34,7 @@
# accepted by the condition parser.
#
# See the ch_isdigit call in CondParser_String.
+# expect+1: Malformed conditional (!-1)
.if !-1
. error
.else
@@ -42,19 +45,20 @@
# accepted by the condition parser.
#
# See the ch_isdigit call in CondParser_String.
+# expect+1: Malformed conditional (!+1)
.if !+1
. error
.else
. error
.endif
-# When the number comes from a variable expression though, it may be signed.
+# When the number comes from an expression though, it may be signed.
# XXX: This is inconsistent.
.if ${:U+0}
. error
.endif
-# When the number comes from a variable expression though, it may be signed.
+# When the number comes from an expression though, it may be signed.
# XXX: This is inconsistent.
.if !${:U+1}
. error
@@ -69,14 +73,37 @@
. error
.endif
-# This is not a hexadecimal number, even though it has an x.
-# It is interpreted as a string instead, effectively meaning defined(3x4).
+# This is not a hexadecimal number, even though it has an x. It is
+# interpreted as a string instead. In a plain '.if', such a token evaluates
+# to true if it is non-empty. In other '.if' directives, such a token is
+# evaluated by either FuncDefined or FuncMake.
.if 3x4
.else
. error
.endif
-# Ensure that parsing continues until here.
-.info End of the tests.
+# Make can do radix conversion from hex.
+HEX= dead
+.if 0x${HEX} == 57005
+.else
+. error
+.endif
+
+# Very small numbers round to 0.
+.if 12345e-400
+. error
+.endif
+.if 12345e-200
+.else
+. error
+.endif
+
+# Very large numbers round up to infinity on IEEE 754 implementations, or to
+# the largest representable number (VAX); in particular, make does not fall
+# back to checking whether a variable of that name is defined.
+.if 12345e400
+.else
+. error
+.endif
-all: # nothing
+all:
diff --git a/contrib/bmake/unit-tests/cond-token-plain.exp b/contrib/bmake/unit-tests/cond-token-plain.exp
index 24cfa6bcbc82..8044f3bac826 100644
--- a/contrib/bmake/unit-tests/cond-token-plain.exp
+++ b/contrib/bmake/unit-tests/cond-token-plain.exp
@@ -1,54 +1,63 @@
CondParser_Eval: ${:Uvalue} != value
-lhs = "value", rhs = "value", op = !=
+Comparing "value" != "value"
CondParser_Eval: ${:U} != "
-lhs = "", rhs = "", op = !=
+Comparing "" != ""
CondParser_Eval: ${:U#hash} != "#hash"
-lhs = "#hash", rhs = "#hash", op = !=
+Comparing "#hash" != "#hash"
CondParser_Eval: ${:U\\} != "\\
-lhs = "\", rhs = "\", op = !=
+Comparing "\" != "\"
CondParser_Eval: ${:U#hash} != #hash
-lhs = "#hash", rhs = "#hash", op = !=
+Comparing "#hash" != "#hash"
CondParser_Eval: 0 # This is treated as a comment, but why?
-CondParser_Eval: ${0 # comment :?yes:no} != no
-CondParser_Eval: 0 # comment
-lhs = "no", rhs = "no", op = !=
-CondParser_Eval: ${1 # comment :?yes:no} != yes
-CondParser_Eval: 1 # comment
-lhs = "yes", rhs = "yes", op = !=
+CondParser_Eval: ${0 # comment:?yes:no} != no
+CondParser_Eval: 0 # comment
+Comparing "no" != "no"
+CondParser_Eval: ${1 # comment:?yes:no} != yes
+CondParser_Eval: 1 # comment
+Comparing "yes" != "yes"
CondParser_Eval: ${UNDEF:Uundefined}!=undefined
-lhs = "undefined", rhs = "undefined", op = !=
+Comparing "undefined" != "undefined"
CondParser_Eval: ${UNDEF:U12345}>12345
-lhs = 12345.000000, rhs = 12345.000000, op = >
+Comparing 12345.000000 > 12345.000000
CondParser_Eval: ${UNDEF:U12345}<12345
-lhs = 12345.000000, rhs = 12345.000000, op = <
+Comparing 12345.000000 < 12345.000000
CondParser_Eval: (${UNDEF:U0})||0
CondParser_Eval: ${:Uvar}&&name != "var&&name"
-lhs = "var&&name", rhs = "var&&name", op = !=
+Comparing "var&&name" != "var&&name"
CondParser_Eval: ${:Uvar}||name != "var||name"
-lhs = "var||name", rhs = "var||name", op = !=
+Comparing "var||name" != "var||name"
CondParser_Eval: bare
-make: "cond-token-plain.mk" line 102: A bare word is treated like defined(...), and the variable 'bare' is not defined.
+make: "cond-token-plain.mk" line 106: A bare word is treated like defined(...), and the variable 'bare' is not defined.
CondParser_Eval: VAR
-make: "cond-token-plain.mk" line 107: A bare word is treated like defined(...).
+make: "cond-token-plain.mk" line 113: A bare word is treated like defined(...).
CondParser_Eval: V${:UA}R
-make: "cond-token-plain.mk" line 114: ok
+make: "cond-token-plain.mk" line 121: ok
CondParser_Eval: V${UNDEF}AR
-make: "cond-token-plain.mk" line 122: Undefined variables in bare words expand to an empty string.
+make: "cond-token-plain.mk" line 130: Undefined variables in bare words expand to an empty string.
CondParser_Eval: 0${:Ux00}
-make: "cond-token-plain.mk" line 130: Numbers can be composed from literals and variable expressions.
+make: "cond-token-plain.mk" line 139: Numbers can be composed from literals and expressions.
CondParser_Eval: 0${:Ux01}
-make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
+make: "cond-token-plain.mk" line 144: Numbers can be composed from literals and expressions.
CondParser_Eval: "" ==
-make: "cond-token-plain.mk" line 140: Missing right-hand-side of operator '=='
+make: "cond-token-plain.mk" line 151: Missing right-hand side of operator '=='
CondParser_Eval: == ""
-make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
+make: "cond-token-plain.mk" line 160: Malformed conditional (== "")
CondParser_Eval: \\
-make: "cond-token-plain.mk" line 163: The variable '\\' is not defined.
+make: "cond-token-plain.mk" line 176: The variable '\\' is not defined.
CondParser_Eval: \\
-make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined.
+make: "cond-token-plain.mk" line 182: Now the variable '\\' is defined.
CondParser_Eval: "unquoted\"quoted" != unquoted"quoted
-lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = !=
+Comparing "unquoted"quoted" != "unquoted"quoted"
CondParser_Eval: $$$$$$$$ != ""
+make: "cond-token-plain.mk" line 197: Malformed conditional ($$$$$$$$ != "")
+CondParser_Eval: left == right
+make: "cond-token-plain.mk" line 206: Malformed conditional (left == right)
+CondParser_Eval: ${0:?:} || left == right
+CondParser_Eval: 0
+make: "cond-token-plain.mk" line 212: Malformed conditional (${0:?:} || left == right)
+CondParser_Eval: left == right || ${0:?:}
+make: "cond-token-plain.mk" line 217: Malformed conditional (left == right || ${0:?:})
+make: "cond-token-plain.mk" line 236: Malformed conditional (VAR.${IF_COUNT::+=1} != "")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-token-plain.mk b/contrib/bmake/unit-tests/cond-token-plain.mk
index 89f2247e077c..79fcc771a855 100644
--- a/contrib/bmake/unit-tests/cond-token-plain.mk
+++ b/contrib/bmake/unit-tests/cond-token-plain.mk
@@ -1,17 +1,18 @@
-# $NetBSD: cond-token-plain.mk,v 1.10 2021/01/21 14:08:09 rillig Exp $
+# $NetBSD: cond-token-plain.mk,v 1.19 2023/11/19 21:47:52 rillig Exp $
#
# Tests for plain tokens (that is, string literals without quotes)
-# in .if conditions.
+# in .if conditions. These are also called bare words.
.MAKEFLAGS: -dc
+# The word 'value' after the '!=' is a bare word.
.if ${:Uvalue} != value
. error
.endif
-# Malformed condition since comment parsing is done in an early phase
-# and removes the '#' and everything behind it long before the condition
-# parser gets to see it.
+# Using a '#' in a string literal in a condition leads to a malformed
+# condition since comment parsing is done in an early phase and removes the
+# '#' and everything after it long before the condition parser gets to see it.
#
# XXX: The error message is missing for this malformed condition.
# The right-hand side of the comparison is just a '"', before unescaping.
@@ -32,7 +33,10 @@
# in a very early parsing phase.
#
# See https://gnats.netbsd.org/19596 for example makefiles demonstrating the
-# original problems. This workaround is probably not needed anymore.
+# original problems. At that time, the parser didn't recognize the comment in
+# the line '.else # comment3'. This workaround is not needed anymore since
+# comments are stripped in an earlier phase. See "case '#'" in
+# CondParser_Token.
#
# XXX: Missing error message for the malformed condition. The right-hand
# side before unescaping is double-quotes, backslash, backslash.
@@ -59,10 +63,10 @@
# anybody really use this? This is neither documented nor obvious since
# the '#' is escaped. It's much clearer to write a comment in the line
# above the condition.
-.if ${0 \# comment :?yes:no} != no
+.if ${0 \# comment:?yes:no} != no
. error
.endif
-.if ${1 \# comment :?yes:no} != yes
+.if ${1 \# comment:?yes:no} != yes
. error
.endif
@@ -85,7 +89,7 @@
# a coincidence that the '!' is both used in the '!=' comparison operator
# as well as for negating a comparison result.
#
-# The boolean operators '&' and '|' don't terminate a comparison operand.
+# The characters '&' and '|' are part of the comparison operand.
.if ${:Uvar}&&name != "var&&name"
. error
.endif
@@ -93,24 +97,27 @@
. error
.endif
-# A bare word may appear alone in a condition, without any comparison
-# operator. It is implicitly converted into defined(bare).
+# A bare word may occur alone in a condition, without any comparison
+# operator. It is interpreted as the function call 'defined(bare)'.
.if bare
. error
.else
+# expect+1: A bare word is treated like defined(...), and the variable 'bare' is not defined.
. info A bare word is treated like defined(...), and the variable $\
'bare' is not defined.
.endif
VAR= defined
.if VAR
+# expect+1: A bare word is treated like defined(...).
. info A bare word is treated like defined(...).
.else
. error
.endif
-# Bare words may be intermixed with variable expressions.
+# Bare words may be intermixed with expressions.
.if V${:UA}R
+# expect+1: ok
. info ok
.else
. error
@@ -119,6 +126,7 @@ VAR= defined
# In bare words, even undefined variables are allowed. Without the bare
# words, undefined variables are not allowed. That feels inconsistent.
.if V${UNDEF}AR
+# expect+1: Undefined variables in bare words expand to an empty string.
. info Undefined variables in bare words expand to an empty string.
.else
. error
@@ -127,16 +135,19 @@ VAR= defined
.if 0${:Ux00}
. error
.else
-. info Numbers can be composed from literals and variable expressions.
+# expect+1: Numbers can be composed from literals and expressions.
+. info Numbers can be composed from literals and expressions.
.endif
.if 0${:Ux01}
-. info Numbers can be composed from literals and variable expressions.
+# expect+1: Numbers can be composed from literals and expressions.
+. info Numbers can be composed from literals and expressions.
.else
. error
.endif
# If the right-hand side is missing, it's a parse error.
+# expect+1: Missing right-hand side of operator '=='
.if "" ==
. error
.else
@@ -145,6 +156,7 @@ VAR= defined
# If the left-hand side is missing, it's a parse error as well, but without
# a specific error message.
+# expect+1: Malformed conditional (== "")
.if == ""
. error
.else
@@ -152,7 +164,7 @@ VAR= defined
.endif
# The '\\' is not a line continuation. Neither is it an unquoted string
-# literal. Instead, it is parsed as a function argument (ParseFuncArg),
+# literal. Instead, it is parsed as a bare word (ParseWord),
# and in that context, the backslash is just an ordinary character. The
# function argument thus stays '\\' (2 backslashes). This string is passed
# to FuncDefined, and since there is no variable named '\\', the condition
@@ -160,11 +172,13 @@ VAR= defined
.if \\
. error
.else
+# expect+1: The variable '\\' is not defined.
. info The variable '\\' is not defined.
.endif
${:U\\\\}= backslash
.if \\
+# expect+1: Now the variable '\\' is defined.
. info Now the variable '\\' is defined.
.else
. error
@@ -179,14 +193,75 @@ ${:U\\\\}= backslash
# FIXME: In CondParser_String, Var_Parse returns var_Error without a
# corresponding error message.
+# expect+1: Malformed conditional ($$$$$$$$ != "")
.if $$$$$$$$ != ""
. error
.else
. error
.endif
+# In a condition in an .if directive, the left-hand side must not be an
+# unquoted string literal.
+# expect+1: Malformed conditional (left == right)
+.if left == right
+.endif
+# Before cond.c 1.276 from 2021-09-21, an expression containing the
+# modifier ':?:' allowed unquoted string literals for the rest of the
+# condition. This was an unintended implementation mistake.
+# expect+1: Malformed conditional (${0:?:} || left == right)
+.if ${0:?:} || left == right
+.endif
+# This affected only the comparisons after the expression, so the following
+# was still a syntax error.
+# expect+1: Malformed conditional (left == right || ${0:?:})
+.if left == right || ${0:?:}
+.endif
+
# See cond-token-string.mk for similar tests where the condition is enclosed
# in "quotes".
-all:
- @:;
+.MAKEFLAGS: -d0
+
+
+# As of cond.c 1.320 from 2021-12-30, the code in CondParser_ComparisonOrLeaf
+# looks suspicious of evaluating the expression twice: first for parsing a
+# bare word and second for parsing the left-hand side of a comparison.
+#
+# In '.if' directives, the left-hand side of a comparison must not be a bare
+# word though, and this keeps CondParser_Leaf from evaluating the expression
+# for the second time. The right-hand side of a comparison may be a bare
+# word, but that side has no risk of being parsed more than once.
+#
+# expect+1: Malformed conditional (VAR.${IF_COUNT::+=1} != "")
+.if VAR.${IF_COUNT::+=1} != ""
+. error
+.else
+. error
+.endif
+.if ${IF_COUNT} != "1"
+. error
+.endif
+
+# A different situation is when CondParser.leftUnquotedOK is true. This
+# situation arises in expressions of the form ${cond:?yes:no}. As of
+# 2021-12-30, the condition in such an expression is evaluated before parsing
+# the condition, see varmod-ifelse.mk. To pass an expression to the
+# condition parser, it needs to be escaped. This rarely happens in practice,
+# in most cases the conditions are simple enough that it doesn't matter
+# whether the condition is first evaluated and then parsed, or vice versa.
+# A half-baked attempt at hiding this implementation detail is
+# CondParser.leftUnquotedOK, but that is a rather leaky abstraction.
+
+#.MAKEFLAGS: -dcv
+COND= VAR.$${MOD_COUNT::+=1}
+.if ${${COND} == "VAR.":?yes:no} != "yes"
+. error
+.endif
+
+# The value "1 1" demonstrates that the expression ${MOD_COUNT::+=1} was
+# evaluated twice. In practice, expressions that occur in conditions do not
+# have side effects, making this problem rather academic, but it is there.
+.if ${MOD_COUNT} != "1 1"
+. error
+.endif
+#.MAKEFLAGS: -d0
diff --git a/contrib/bmake/unit-tests/cond-token-string.exp b/contrib/bmake/unit-tests/cond-token-string.exp
index 45f9993457d3..db07adcb2d09 100644
--- a/contrib/bmake/unit-tests/cond-token-string.exp
+++ b/contrib/bmake/unit-tests/cond-token-string.exp
@@ -1,18 +1,21 @@
-make: "cond-token-string.mk" line 13: Unknown modifier "Z"
-make: "cond-token-string.mk" line 13: Malformed conditional ("" != "${:Uvalue:Z}")
-make: "cond-token-string.mk" line 22: xvalue is not defined.
-make: "cond-token-string.mk" line 28: Malformed conditional (x${:Uvalue} == "")
-make: "cond-token-string.mk" line 37: Expected.
+make: "cond-token-string.mk" line 15: Unknown modifier "Z"
+make: "cond-token-string.mk" line 15: Malformed conditional ("" != "${:Uvalue:Z}")
+make: "cond-token-string.mk" line 25: xvalue is not defined.
+make: "cond-token-string.mk" line 32: Malformed conditional (x${:Uvalue} == "")
+make: "cond-token-string.mk" line 42: Expected.
CondParser_Eval: "UNDEF"
-make: "cond-token-string.mk" line 46: The string literal "UNDEF" is not empty.
+make: "cond-token-string.mk" line 52: The string literal "UNDEF" is not empty.
CondParser_Eval: " "
-make: "cond-token-string.mk" line 55: The string literal " " is not empty, even though it consists of whitespace only.
+make: "cond-token-string.mk" line 61: The string literal " " is not empty, even though it consists of whitespace only.
CondParser_Eval: "${UNDEF}"
-make: "cond-token-string.mk" line 64: An undefined variable in quotes expands to an empty string, which then evaluates to false.
+make: "cond-token-string.mk" line 71: An undefined variable in quotes expands to an empty string, which then evaluates to false.
CondParser_Eval: "${:Uvalue}"
-make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true.
+make: "cond-token-string.mk" line 77: A nonempty expression evaluates to true.
CondParser_Eval: "${:U}"
-make: "cond-token-string.mk" line 76: An empty variable evaluates to false.
+make: "cond-token-string.mk" line 86: An empty variable evaluates to false.
+CondParser_Eval: ("${VAR}")
+CondParser_Eval: "quoted" == quoted
+Comparing "quoted" == "quoted"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-token-string.mk b/contrib/bmake/unit-tests/cond-token-string.mk
index a92d3a896116..d13c68da134a 100644
--- a/contrib/bmake/unit-tests/cond-token-string.mk
+++ b/contrib/bmake/unit-tests/cond-token-string.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 rillig Exp $
+# $NetBSD: cond-token-string.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
#
# Tests for quoted string literals in .if conditions.
#
@@ -9,7 +9,9 @@
# TODO: Implementation
# Cover the code in CondParser_String that frees the memory after parsing
-# a variable expression based on an undefined variable.
+# an expression based on an undefined variable.
+# expect+2: Malformed conditional ("" != "${:Uvalue:Z}")
+# expect+1: Unknown modifier "Z"
.if "" != "${:Uvalue:Z}"
. error
.else
@@ -19,12 +21,14 @@
.if x${:Uvalue}
. error
.else
+# expect+1: xvalue is not defined.
. info xvalue is not defined.
.endif
# The 'x' produces a "Malformed conditional" since the left-hand side of a
-# comparison in an .if directive must be either a variable expression, a
+# comparison in an .if directive must be either an expression, a
# quoted string literal or a number that starts with a digit.
+# expect+1: Malformed conditional (x${:Uvalue} == "")
.if x${:Uvalue} == ""
. error
.else
@@ -34,6 +38,7 @@
# In plain words, a '\' can be used to escape any character, just as in
# double-quoted string literals. See CondParser_String.
.if \x${:Uvalue} == "xvalue"
+# expect+1: Expected.
. info Expected.
.else
. error
@@ -43,6 +48,7 @@
# A string in quotes is checked whether it is not empty.
.if "UNDEF"
+# expect+1: The string literal "UNDEF" is not empty.
. info The string literal "UNDEF" is not empty.
.else
. error
@@ -51,6 +57,7 @@
# A space is not empty as well.
# This differs from many other places where whitespace is trimmed.
.if " "
+# expect+1: The string literal " " is not empty, even though it consists of whitespace only.
. info The string literal " " is not empty, even though it consists of $\
whitespace only.
.else
@@ -60,12 +67,14 @@
.if "${UNDEF}"
. error
.else
+# expect+1: An undefined variable in quotes expands to an empty string, which then evaluates to false.
. info An undefined variable in quotes expands to an empty string, which $\
then evaluates to false.
.endif
.if "${:Uvalue}"
-. info A nonempty variable expression evaluates to true.
+# expect+1: A nonempty expression evaluates to true.
+. info A nonempty expression evaluates to true.
.else
. error
.endif
@@ -73,10 +82,28 @@
.if "${:U}"
. error
.else
+# expect+1: An empty variable evaluates to false.
. info An empty variable evaluates to false.
.endif
+# A non-empty string evaluates to true, no matter if it's a literal string or
+# if it contains expressions. The parentheses are not necessary for
+# the parser, in this case their only purpose is to make the code harder to
+# read for humans.
+VAR= value
+.if ("${VAR}")
+.else
+. error
+.endif
+
+# In the conditions in .if directives, the left-hand side of a comparison must
+# be enclosed in quotes. The right-hand side does not need to be enclosed in
+# quotes.
+.if "quoted" == quoted
+.else
+. error
+.endif
+
.MAKEFLAGS: -d0
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/cond-token-var.exp b/contrib/bmake/unit-tests/cond-token-var.exp
index fcd92d12a3da..d84ca56e981b 100644
--- a/contrib/bmake/unit-tests/cond-token-var.exp
+++ b/contrib/bmake/unit-tests/cond-token-var.exp
@@ -1,7 +1,7 @@
-make: "cond-token-var.mk" line 20: ok
-make: "cond-token-var.mk" line 27: Malformed conditional (${UNDEF} == ${DEF})
-make: "cond-token-var.mk" line 33: Malformed conditional (${DEF} == ${UNDEF})
-make: "cond-token-var.mk" line 42: Malformed conditional (${UNDEF})
+make: "cond-token-var.mk" line 21: ok
+make: "cond-token-var.mk" line 28: Malformed conditional (${UNDEF} == ${DEF})
+make: "cond-token-var.mk" line 34: Malformed conditional (${DEF} == ${UNDEF})
+make: "cond-token-var.mk" line 44: Malformed conditional (${UNDEF})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-token-var.mk b/contrib/bmake/unit-tests/cond-token-var.mk
index 168c63c46ac1..c6471756a3dd 100644
--- a/contrib/bmake/unit-tests/cond-token-var.mk
+++ b/contrib/bmake/unit-tests/cond-token-var.mk
@@ -1,11 +1,11 @@
-# $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $
+# $NetBSD: cond-token-var.mk,v 1.8 2023/11/19 21:47:52 rillig Exp $
#
-# Tests for variable expressions in .if conditions.
+# Tests for expressions in .if conditions.
#
-# Note the fine distinction between a variable and a variable expression.
-# A variable has a name and a value. To access the value, one writes a
-# variable expression of the form ${VAR}. This is a simple variable
-# expression. Variable expressions can get more complicated by adding
+# Note the fine distinction between a variable and an expression.
+# A variable has a name and a value. To access the value, one writes an
+# expression of the form ${VAR}. This is a simple
+# expression. Expressions can get more complicated by adding
# variable modifiers such as in ${VAR:Mpattern}.
#
# XXX: Strictly speaking, variable modifiers should be called expression
@@ -17,19 +17,20 @@ DEF= defined
# A defined variable may appear on either side of the comparison.
.if ${DEF} == ${DEF}
+# expect+1: ok
. info ok
.else
. error
.endif
# A variable that appears on the left-hand side must be defined.
-# The following line thus generates a parse error.
+# expect+1: Malformed conditional (${UNDEF} == ${DEF})
.if ${UNDEF} == ${DEF}
. error
.endif
# A variable that appears on the right-hand side must be defined.
-# The following line thus generates a parse error.
+# expect+1: Malformed conditional (${DEF} == ${UNDEF})
.if ${DEF} == ${UNDEF}
. error
.endif
@@ -39,6 +40,7 @@ DEF= defined
.endif
# An undefined variable on its own generates a parse error.
+# expect+1: Malformed conditional (${UNDEF})
.if ${UNDEF}
.endif
@@ -47,7 +49,7 @@ DEF= defined
.if ${UNDEF:U}
.endif
-# If the value of the variable expression is a number, it is compared against
+# If the value of the expression is a number, it is compared against
# zero.
.if ${:U0}
. error
@@ -56,7 +58,7 @@ DEF= defined
. error
.endif
-# If the value of the variable expression is not a number, any non-empty
+# If the value of the expression is not a number, any non-empty
# value evaluates to true, even if there is only whitespace.
.if ${:U}
. error
diff --git a/contrib/bmake/unit-tests/cond-undef-lint.exp b/contrib/bmake/unit-tests/cond-undef-lint.exp
index 2c4feb0376ff..efab46113f67 100755
--- a/contrib/bmake/unit-tests/cond-undef-lint.exp
+++ b/contrib/bmake/unit-tests/cond-undef-lint.exp
@@ -1,7 +1,10 @@
-make: "cond-undef-lint.mk" line 23: Variable "UNDEF" is undefined
-make: "cond-undef-lint.mk" line 38: Variable "UNDEF" is undefined
-make: "cond-undef-lint.mk" line 38: Variable "VAR." is undefined
-make: "cond-undef-lint.mk" line 49: Variable "VAR.defined" is undefined
+make: "cond-undef-lint.mk" line 25: Variable "UNDEF" is undefined
+make: "cond-undef-lint.mk" line 25: Malformed conditional (${UNDEF})
+make: "cond-undef-lint.mk" line 43: Variable "UNDEF" is undefined
+make: "cond-undef-lint.mk" line 43: Variable "VAR." is undefined
+make: "cond-undef-lint.mk" line 43: Malformed conditional (${VAR.${UNDEF}})
+make: "cond-undef-lint.mk" line 56: Variable "VAR.defined" is undefined
+make: "cond-undef-lint.mk" line 56: Malformed conditional (${VAR.${DEF}})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/cond-undef-lint.mk b/contrib/bmake/unit-tests/cond-undef-lint.mk
index 9dfd1bd53252..6fd353dc60e2 100755
--- a/contrib/bmake/unit-tests/cond-undef-lint.mk
+++ b/contrib/bmake/unit-tests/cond-undef-lint.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-undef-lint.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-undef-lint.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Tests for defined and undefined variables in .if conditions, in lint mode.
#
@@ -20,6 +20,8 @@ DEF= defined
.endif
# Since the condition fails to evaluate, neither of the branches is taken.
+# expect+2: Malformed conditional (${UNDEF})
+# expect+1: Variable "UNDEF" is undefined
.if ${UNDEF}
. error
.else
@@ -35,6 +37,9 @@ DEF= defined
#
# TODO: Suppress the error message "Variable VAR. is undefined". That part
# of the expression must not be evaluated at all.
+# expect+3: Variable "UNDEF" is undefined
+# expect+2: Variable "VAR." is undefined
+# expect+1: Malformed conditional (${VAR.${UNDEF}})
.if ${VAR.${UNDEF}}
. error
.else
@@ -46,6 +51,8 @@ DEF= defined
# TODO: This pattern looks a lot like CFLAGS.${OPSYS}, which is at least
# debatable. Or would any practical use of CFLAGS.${OPSYS} be via an indirect
# expression, as in the next example?
+# expect+2: Variable "VAR.defined" is undefined
+# expect+1: Malformed conditional (${VAR.${DEF}})
.if ${VAR.${DEF}}
. error
.else
diff --git a/contrib/bmake/unit-tests/cond1.exp b/contrib/bmake/unit-tests/cond1.exp
deleted file mode 100644
index 8b65d782524d..000000000000
--- a/contrib/bmake/unit-tests/cond1.exp
+++ /dev/null
@@ -1,23 +0,0 @@
-make: "cond1.mk" line 80: warning: extra else
-make: "cond1.mk" line 90: warning: extra else
-2 is prime
-A='other' B='unknown' C='clever' o='no,no'
-Passed:
- var
- ("var")
- (var != var)
- var != var
- !((var != var) && defined(name))
- var == quoted
-
-1 is not prime
-2 is prime
-3 is prime
-4 is not prime
-5 is prime
-
-make: String comparison operator must be either == or !=
-make: Bad conditional expression '"0" > 0' in '"0" > 0?OK:No'
-
-OK
-exit status 0
diff --git a/contrib/bmake/unit-tests/cond1.mk b/contrib/bmake/unit-tests/cond1.mk
deleted file mode 100644
index 53908c2dacf1..000000000000
--- a/contrib/bmake/unit-tests/cond1.mk
+++ /dev/null
@@ -1,114 +0,0 @@
-# $NetBSD: cond1.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $
-
-# TODO: Convert these tests into tutorial form.
-# TODO: Split these tests by topic.
-# TODO: Use better variable names and expression values that actually express
-# the intended behavior. uname(1) has nothing to do with conditions.
-
-# hard code these!
-TEST_UNAME_S= NetBSD
-TEST_UNAME_M= sparc
-TEST_MACHINE= i386
-
-.if ${TEST_UNAME_S}
-Ok=var,
-.endif
-.if ("${TEST_UNAME_S}")
-Ok+=(\"var\"),
-.endif
-.if (${TEST_UNAME_M} != ${TEST_MACHINE})
-Ok+=(var != var),
-.endif
-.if ${TEST_UNAME_M} != ${TEST_MACHINE}
-Ok+= var != var,
-.endif
-.if !((${TEST_UNAME_M} != ${TEST_MACHINE}) && defined(X))
-Ok+= !((var != var) && defined(name)),
-.endif
-# from bsd.obj.mk
-MKOBJ?=no
-.if ${MKOBJ} == "no"
-o= no
-Ok+= var == "quoted",
-.else
-.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
-.if defined(notMAKEOBJDIRPREFIX)
-o=${MAKEOBJDIRPREFIX}${__curdir}
-.else
-o= ${MAKEOBJDIR}
-.endif
-.endif
-o= o
-.endif
-
-# repeat the above to check we get the same result
-.if ${MKOBJ} == "no"
-o2= no
-.else
-.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
-.if defined(notMAKEOBJDIRPREFIX)
-o2=${MAKEOBJDIRPREFIX}${__curdir}
-.else
-o2= ${MAKEOBJDIR}
-.endif
-.endif
-o2= o
-.endif
-
-PRIMES=2 3 5 7 11
-NUMBERS=1 2 3 4 5
-
-n=2
-.if ${PRIMES:M$n} == ""
-X=not
-.else
-X=
-.endif
-
-.if ${MACHINE_ARCH} == no-such
-A=one
-.else
-.if ${MACHINE_ARCH} == not-this
-.if ${MACHINE_ARCH} == something-else
-A=unlikely
-.else
-A=no
-.endif
-.endif
-A=other
-# We expect an extra else warning - we're not skipping here
-.else
-A=this should be an error
-.endif
-
-.if $X != ""
-.if $X == not
-B=one
-.else
-B=other
-# We expect an extra else warning - we are skipping here
-.else
-B=this should be an error
-.endif
-.else
-B=unknown
-.endif
-
-.if "quoted" == quoted
-C=clever
-.else
-C=dim
-.endif
-
-.if defined(nosuch) && ${nosuch:Mx} != ""
-# this should not happen
-.info nosuch is x
-.endif
-
-all:
- @echo "$n is $X prime"
- @echo "A='$A' B='$B' C='$C' o='$o,${o2}'"
- @echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
- @echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} prime${.newline}@}"
- @echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}"
- @echo "${${NoSuchNumber:U42} > 0:?OK:No}"
diff --git a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp
index 855b575c48bc..a8ef9d0707af 100644
--- a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp
+++ b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.exp
@@ -1,4 +1,4 @@
-make: "dep-colon-bug-cross-file.mk" line 31: warning: duplicate script for target "all" ignored
-make: "dep-colon-bug-cross-file.mk" line 40: warning: using previous script for "all" defined here
+make: "dep-colon-bug-cross-file.mk" line 32: warning: duplicate script for target "all" ignored
+make: "dep-colon-bug-cross-file.mk" line 42: warning: using previous script for "all" defined here
: pass 1
exit status 0
diff --git a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk
index 57fbf478163c..930358af2871 100644
--- a/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk
+++ b/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk
@@ -1,4 +1,4 @@
-# $NetBSD: dep-colon-bug-cross-file.mk,v 1.4 2020/09/27 09:53:41 rillig Exp $
+# $NetBSD: dep-colon-bug-cross-file.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
#
# Until 2020-09-25, the very last dependency group of a top-level makefile
# was not finished properly. This made it possible to add further commands
@@ -28,6 +28,7 @@ PASS?= 1
.if ${PASS} == 2
all:
+# expect+1: warning: duplicate script for target "all" ignored
: pass 2
.endif
@@ -37,5 +38,6 @@ PASS= 2
.MAKEFLAGS: -f ${.PARSEDIR:q}/${.PARSEFILE:q}
all:
+# expect+1: warning: using previous script for "all" defined here
: pass 1
.endif
diff --git a/contrib/bmake/unit-tests/dep-duplicate.exp b/contrib/bmake/unit-tests/dep-duplicate.exp
new file mode 100644
index 000000000000..039145f8fd97
--- /dev/null
+++ b/contrib/bmake/unit-tests/dep-duplicate.exp
@@ -0,0 +1,4 @@
+make: "dep-duplicate.inc" line 1: warning: duplicate script for target "all" ignored
+make: "dep-duplicate.main" line 3: warning: using previous script for "all" defined here
+main-output
+exit status 0
diff --git a/contrib/bmake/unit-tests/dep-duplicate.mk b/contrib/bmake/unit-tests/dep-duplicate.mk
new file mode 100644
index 000000000000..6f64ba1c1981
--- /dev/null
+++ b/contrib/bmake/unit-tests/dep-duplicate.mk
@@ -0,0 +1,27 @@
+# $NetBSD: dep-duplicate.mk,v 1.3 2022/01/20 19:24:53 rillig Exp $
+#
+# Test for a target whose commands are defined twice. This generates a
+# warning, not an error, so ensure that the correct commands are kept.
+#
+# Also ensure that the diagnostics mention the correct file in case of
+# included files. Since parse.c 1.231 from 2018-12-22 and before parse.c
+# 1.653 from 2022-01-20, the wrong filename had been printed if the file of
+# the first commands section was included by its relative path.
+
+all: .PHONY
+ @exec > dep-duplicate.main; \
+ echo '# empty line 1'; \
+ echo '# empty line 2'; \
+ echo 'all:; @echo main-output'; \
+ echo '.include "dep-duplicate.inc"'
+
+ @exec > dep-duplicate.inc; \
+ echo 'all:; @echo inc-output'
+
+ # The main file must be specified using a relative path, just like the
+ # default 'makefile' or 'Makefile', to produce the same result when
+ # run via ATF or 'make test'.
+ @${MAKE} -r -f dep-duplicate.main
+
+ @rm -f dep-duplicate.main
+ @rm -f dep-duplicate.inc
diff --git a/contrib/bmake/unit-tests/dep-op-missing.exp b/contrib/bmake/unit-tests/dep-op-missing.exp
new file mode 100644
index 000000000000..9b42c5080122
--- /dev/null
+++ b/contrib/bmake/unit-tests/dep-op-missing.exp
@@ -0,0 +1,4 @@
+make: "dep-op-missing.tmp" line 1: Invalid line 'target'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 0
diff --git a/contrib/bmake/unit-tests/dep-op-missing.mk b/contrib/bmake/unit-tests/dep-op-missing.mk
new file mode 100644
index 000000000000..2079f3c19871
--- /dev/null
+++ b/contrib/bmake/unit-tests/dep-op-missing.mk
@@ -0,0 +1,13 @@
+# $NetBSD: dep-op-missing.mk,v 1.1 2021/12/14 00:02:57 rillig Exp $
+#
+# Test for a missing dependency operator, in a line with trailing whitespace.
+
+# Before parse.c 1.578 from 2021-12-14, there was some unreachable error
+# handling code in ParseDependencyOp. This test tried to reach it and failed.
+# To reach that point, there would have to be trailing whitespace in the line,
+# but that is removed in an early stage of parsing.
+
+all: .PHONY
+ @printf 'target ' > dep-op-missing.tmp
+ @${MAKE} -r -f dep-op-missing.tmp || exit 0
+ @rm dep-op-missing.tmp
diff --git a/contrib/bmake/unit-tests/dep-var.exp b/contrib/bmake/unit-tests/dep-var.exp
index d32aca455ceb..cc229d32e6d4 100755
--- a/contrib/bmake/unit-tests/dep-var.exp
+++ b/contrib/bmake/unit-tests/dep-var.exp
@@ -1,4 +1,28 @@
-make: Malformed variable expression at "$)"
+Var_Parse: ${UNDEF1} (eval-defined)
+Global: .ALLTARGETS = all
+Global: .ALLTARGETS = all ${DEF2}
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3}
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1
+Global: INDIRECT_1 = 2-$${INDIRECT_2}-2
+Global: INDIRECT_2 = 3-$${INDIRECT_3}-3
+Global: INDIRECT_3 = indirect
+Global: UNDEF1 = undef1
+Global: DEF2 = def2
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$)
+Var_Parse: ${:U\$)}: (eval-defined)
+Evaluating modifier ${:U...} on value "" (eval-defined, undefined)
+Result of ${:U\$)} is "$)" (eval-defined, defined)
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b
+Var_Parse: $INDIRECT_2-2-1 $): (parse-only)
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1
+Var_Parse: $): (parse-only)
+Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1 $)
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
+make: Malformed expression at "$)"
def2
a-def2-b
1-2-NDIRECT_2-2-1
diff --git a/contrib/bmake/unit-tests/dep-var.mk b/contrib/bmake/unit-tests/dep-var.mk
index 4503424e31ab..8c1636bbdec2 100755
--- a/contrib/bmake/unit-tests/dep-var.mk
+++ b/contrib/bmake/unit-tests/dep-var.mk
@@ -1,17 +1,19 @@
-# $NetBSD: dep-var.mk,v 1.6 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: dep-var.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $
#
# Tests for variable references in dependency declarations.
#
# Uh oh, this feels so strange that probably nobody uses it. But it seems to
# be the only way to reach the lower half of SuffExpandChildren.
-# XXX: The -dv log says:
-# Var_Parse: ${UNDEF1} with VARE_UNDEFERR|VARE_WANTRES
-# but no error message is generated for this line.
-# The variable expression ${UNDEF1} simply expands to an empty string.
+.MAKEFLAGS: -dv
+
+# expect: Var_Parse: ${UNDEF1} (eval-defined)
+# Even though undefined expressions should lead to errors, no error message is
+# generated for this line. The expression ${UNDEF1} simply expands
+# to an empty string.
all: ${UNDEF1}
-# Using a double dollar in order to circumvent immediate variable expansion
+# Using a double dollar in order to circumvent immediate expression expansion
# feels like unintended behavior. At least the manual page says nothing at
# all about defined or undefined variables in dependency lines.
#
@@ -20,10 +22,10 @@ all: ${UNDEF1}
all: $${DEF2} a-$${DEF2}-b
# This variable is not defined at all.
-# XXX: The -dv log says:
-# Var_Parse: ${UNDEF3} with VARE_UNDEFERR|VARE_WANTRES
+# XXX: The -dv log says later when expanding the sources of 'all':
+# Var_Parse: ${UNDEF3} (eval-defined)
# but no error message is generated for this line, just like for UNDEF1.
-# The variable expression ${UNDEF3} simply expands to an empty string.
+# The expression ${UNDEF3} simply expands to an empty string.
all: $${UNDEF3}
# Try out how many levels of indirection are really expanded in dependency
@@ -61,7 +63,7 @@ INDIRECT_3= indirect
UNDEF1= undef1
DEF2= def2
-# Cover the code in SuffExpandChildren that deals with malformed variable
+# Cover the code in SuffExpandChildren that deals with malformed
# expressions.
#
# This seems to be an edge case that never happens in practice, and it would
@@ -81,8 +83,14 @@ all: $$$$)
# Since 2020-09-13, this generates a parse error in lint mode (-dL), but not
# in normal mode since ParseDependency does not handle any errors after
# calling Var_Parse.
+# expect: Var_Parse: ${:U\$)}: (eval-defined)
+# expect: Var_Parse: $INDIRECT_2-2-1 $): (parse-only)
+# expect: Var_Parse: $): (parse-only)
undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1 ${:U\$)}:
@echo ${.TARGET:Q}
-# XXX: Why is the exit status still 0, even though Parse_Error is called
-# with PARSE_FATAL in SuffExpandChildren?
+.MAKEFLAGS: -d0
+
+# XXX: The exit status is still 0, even though Parse_Error is called with
+# PARSE_FATAL in SuffExpandChildren. The exit status is only affected by
+# parse errors when they occur in the parsing phase, see Parse_File.
diff --git a/contrib/bmake/unit-tests/dep-wildcards.exp b/contrib/bmake/unit-tests/dep-wildcards.exp
index fb8a44e2c80a..45eafb5d2693 100644
--- a/contrib/bmake/unit-tests/dep-wildcards.exp
+++ b/contrib/bmake/unit-tests/dep-wildcards.exp
@@ -2,8 +2,10 @@ dep-colon-bug-cross-file.mk
dep-colon.mk
dep-double-colon-indep.mk
dep-double-colon.mk
+dep-duplicate.mk
dep-exclam.mk
dep-none.mk
+dep-op-missing.mk
dep-percent.mk
dep-var.mk
dep-wildcards.mk
diff --git a/contrib/bmake/unit-tests/dep-wildcards.mk b/contrib/bmake/unit-tests/dep-wildcards.mk
index 781b149f5a70..b3e2f14a07c3 100644
--- a/contrib/bmake/unit-tests/dep-wildcards.mk
+++ b/contrib/bmake/unit-tests/dep-wildcards.mk
@@ -1,4 +1,4 @@
-# $NetBSD: dep-wildcards.mk,v 1.3 2020/09/08 05:33:05 rillig Exp $
+# $NetBSD: dep-wildcards.mk,v 1.4 2023/06/21 12:27:50 rillig Exp $
#
# Tests for wildcards such as *.c in dependency declarations.
@@ -7,3 +7,9 @@ all: ${.PARSEDIR}/dep-*.mk
# The :O is necessary since the result of the dependency resolution
# does not order the directory entries itself.
@printf '%s\n' ${.ALLSRC:T:O}
+
+# This is not a wildcard rule as implemented by GNU make, as those rules would
+# use '%' instead of '*'. Instead, the pattern '*.target' is a file pattern
+# in the current working directory. As there are no such files, the target
+# list becomes empty, and the source pattern '*.source' is not even expanded.
+*.target: *.source
diff --git a/contrib/bmake/unit-tests/dep.exp b/contrib/bmake/unit-tests/dep.exp
index 39a9383953dd..6b7f0fabb12b 100644
--- a/contrib/bmake/unit-tests/dep.exp
+++ b/contrib/bmake/unit-tests/dep.exp
@@ -1 +1,5 @@
-exit status 0
+make: "dep.mk" line 11: Inconsistent operator for only-colon
+make: "dep.mk" line 13: Inconsistent operator for only-colon
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/dep.mk b/contrib/bmake/unit-tests/dep.mk
index b2463dfc6458..53fadc789b13 100644
--- a/contrib/bmake/unit-tests/dep.mk
+++ b/contrib/bmake/unit-tests/dep.mk
@@ -1,8 +1,30 @@
-# $NetBSD: dep.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: dep.mk,v 1.4 2023/06/01 07:27:30 rillig Exp $
#
# Tests for dependency declarations, such as "target: sources".
-# TODO: Implementation
+.MAIN: all
+
+# As soon as a target is defined using one of the dependency operators, it is
+# restricted to this dependency operator and cannot use the others anymore.
+only-colon:
+# expect+1: Inconsistent operator for only-colon
+only-colon!
+# expect+1: Inconsistent operator for only-colon
+only-colon::
+# Ensure that the target still has the original operator. If it hadn't, there
+# would be another error message.
+only-colon:
+
+
+# Before parse.c 1.158 from 2009-10-07, the parser broke dependency lines at
+# the first ';', without parsing expressions as such. It interpreted the
+# first ';' as the separator between the dependency and its commands, and the
+# '^' as a shell command.
+all: for-subst
+.for file in ${.PARSEFILE}
+for-subst: ${file:S;^;./;g}
+ @echo ".for with :S;... OK"
+.endfor
+
all:
- @:;
diff --git a/contrib/bmake/unit-tests/depsrc-ignore.exp b/contrib/bmake/unit-tests/depsrc-ignore.exp
index 162f10ddc17b..608671f58ed8 100644
--- a/contrib/bmake/unit-tests/depsrc-ignore.exp
+++ b/contrib/bmake/unit-tests/depsrc-ignore.exp
@@ -1,8 +1,8 @@
ignore-errors begin
false ignore-errors
+*** Error code 1 (ignored)
ignore-errors end
all begin
-*** Error code 1 (ignored)
false all
*** Error code 1 (continuing)
diff --git a/contrib/bmake/unit-tests/depsrc-meta.exp b/contrib/bmake/unit-tests/depsrc-meta.exp
index 77e27582f7da..6f17dcf0ba8a 100644
--- a/contrib/bmake/unit-tests/depsrc-meta.exp
+++ b/contrib/bmake/unit-tests/depsrc-meta.exp
@@ -2,4 +2,6 @@ Skipping meta for actual-test: no commands
Skipping meta for .END: .SPECIAL
Targets from meta mode:
| TARGET depsrc-meta-target
+Targets from meta mode in jobs mode:
+| TARGET depsrc-meta-target
exit status 0
diff --git a/contrib/bmake/unit-tests/depsrc-meta.mk b/contrib/bmake/unit-tests/depsrc-meta.mk
index d41aad9a9c96..7cd5fdf265ab 100644
--- a/contrib/bmake/unit-tests/depsrc-meta.mk
+++ b/contrib/bmake/unit-tests/depsrc-meta.mk
@@ -1,31 +1,30 @@
-# $NetBSD: depsrc-meta.mk,v 1.4 2020/11/27 08:39:07 rillig Exp $
+# $NetBSD: depsrc-meta.mk,v 1.7 2022/03/02 19:32:15 sjg Exp $
#
# Tests for the special source .META in dependency declarations.
# TODO: Implementation
# TODO: Explanation
-.if make(actual-test)
+.MAIN: all
+.if make(actual-test)
.MAKEFLAGS: -dM
-.MAKE.MODE= meta curDirOk=true
+.MAKE.MODE= meta curDirOk=true nofilemon
+.endif
actual-test: depsrc-meta-target
depsrc-meta-target: .META
@> ${.TARGET}-file
@rm -f ${.TARGET}-file
-.elif make(check-results)
-
check-results:
- @echo 'Targets from meta mode:'
+ @echo 'Targets from meta mode${.MAKE.JOBS:D in jobs mode}:'
@awk '/^TARGET/ { print "| " $$0 }' depsrc-meta-target.meta
@rm depsrc-meta-target.meta
-.else
-
all:
- @${MAKE} -f ${MAKEFILE} actual-test
- @${MAKE} -f ${MAKEFILE} check-results
+ @${MAKE} -r -f ${MAKEFILE} actual-test
+ @${MAKE} -r -f ${MAKEFILE} check-results
-.endif
+ @${MAKE} -r -f ${MAKEFILE} actual-test -j1
+ @${MAKE} -r -f ${MAKEFILE} check-results -j1
diff --git a/contrib/bmake/unit-tests/depsrc-use.exp b/contrib/bmake/unit-tests/depsrc-use.exp
index c9810bda462d..d31b9e70eb30 100644
--- a/contrib/bmake/unit-tests/depsrc-use.exp
+++ b/contrib/bmake/unit-tests/depsrc-use.exp
@@ -2,5 +2,9 @@ first 1
first 2
second 1
second 2
+first-first 1
+first-first 2
+first-second 1
+first-second 2
directly
exit status 0
diff --git a/contrib/bmake/unit-tests/depsrc-use.mk b/contrib/bmake/unit-tests/depsrc-use.mk
index 17836cd39e23..ea2cf25bfb6a 100644
--- a/contrib/bmake/unit-tests/depsrc-use.mk
+++ b/contrib/bmake/unit-tests/depsrc-use.mk
@@ -1,13 +1,28 @@
-# $NetBSD: depsrc-use.mk,v 1.4 2020/08/22 12:30:57 rillig Exp $
+# $NetBSD: depsrc-use.mk,v 1.6 2022/04/18 14:38:24 rillig Exp $
#
# Tests for the special source .USE in dependency declarations,
# which allows to append common commands to other targets.
+#
+# See also:
+# .USEBEFORE
+# depsrc-usebefore.mk
+
+# Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally
+# regarded as a candidate for the main target. On the other hand, a .USE
+# target was not.
+not-a-main-candidate: .USE
all: action directly
-first: .USE
+first: .USE first-first first-second
@echo first 1 # Using ${.TARGET} here would expand to "action"
@echo first 2
+first-first: .USE
+ @echo first-first 1
+ @echo first-first 2
+first-second: .USE
+ @echo first-second 1
+ @echo first-second 2
second: .USE
@echo second 1
@@ -17,7 +32,7 @@ second: .USE
# This may happen as the result of expanding a .for loop.
empty: .USE
-# It's possible but uncommon to directly make a .USEBEFORE target.
+# It's possible but uncommon to directly make a .USE target.
directly: .USE
@echo directly
diff --git a/contrib/bmake/unit-tests/depsrc-usebefore.exp b/contrib/bmake/unit-tests/depsrc-usebefore.exp
index c9810bda462d..d84299b66275 100644
--- a/contrib/bmake/unit-tests/depsrc-usebefore.exp
+++ b/contrib/bmake/unit-tests/depsrc-usebefore.exp
@@ -1,6 +1,42 @@
-first 1
-first 2
-second 1
-second 2
-directly
+after-2-before-2 1
+after-2-before-2 2
+after-2-before-1 1
+after-2-before-1 2
+after-1-before-2 1
+after-1-before-2 2
+after-1-before-1 1
+after-1-before-1 2
+before-2-before-2 1
+before-2-before-2 2
+before-2-before-1 1
+before-2-before-1 2
+before-1-before-2 1
+before-1-before-2 2
+before-1-before-1 1
+before-1-before-1 2
+before-2 1
+before-2 2
+before-1 1
+before-1 2
+after-1 1
+after-1 2
+after-2 1
+after-2 2
+before-1-after-1 1
+before-1-after-1 2
+before-1-after-2 1
+before-1-after-2 2
+before-2-after-1 1
+before-2-after-1 2
+before-2-after-2 1
+before-2-after-2 2
+after-1-after-1 1
+after-1-after-1 2
+after-1-after-2 1
+after-1-after-2 2
+after-2-after-1 1
+after-2-after-1 2
+after-2-after-2 1
+after-2-after-2 2
+`directly' is up to date.
exit status 0
diff --git a/contrib/bmake/unit-tests/depsrc-usebefore.mk b/contrib/bmake/unit-tests/depsrc-usebefore.mk
index 001cfb0d71c1..672fb7144856 100644
--- a/contrib/bmake/unit-tests/depsrc-usebefore.mk
+++ b/contrib/bmake/unit-tests/depsrc-usebefore.mk
@@ -1,28 +1,115 @@
-# $NetBSD: depsrc-usebefore.mk,v 1.6 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: depsrc-usebefore.mk,v 1.9 2022/04/18 14:41:42 rillig Exp $
#
# Tests for the special source .USEBEFORE in dependency declarations,
# which allows to prepend common commands to other targets.
#
+# If a target depends on several .USE or .USEBEFORE nodes, the commands get
+# appended or prepended in declaration order. For .USE nodes, this is the
+# expected order, for .USEBEFORE nodes the order is somewhat reversed, and for
+# .USE or .USEBEFORE nodes that depend on other .USE or .USEBEFORE nodes, it
+# gets even more complicated.
+#
# See also:
# .USE
# depsrc-use.mk
-all: action directly
+# Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally
+# regarded as a candidate for the main target. On the other hand, a .USE
+# target was not.
+not-a-main-candidate: .USEBEFORE
+
+all:
+ @${MAKE} -r -f ${MAKEFILE} ordering
+ @${MAKE} -r -f ${MAKEFILE} directly
+
+ordering: before-1 before-2 after-1 after-2
+
+before-1: .USEBEFORE before-1-before-1 before-1-before-2 before-1-after-1 before-1-after-2
+ @echo before-1 1
+ @echo before-1 2
+
+before-1-before-1: .USEBEFORE
+ @echo before-1-before-1 1
+ @echo before-1-before-1 2
+
+before-1-before-2: .USEBEFORE
+ @echo before-1-before-2 1
+ @echo before-1-before-2 2
+
+before-1-after-1: .USE
+ @echo before-1-after-1 1
+ @echo before-1-after-1 2
+
+before-1-after-2: .USE
+ @echo before-1-after-2 1
+ @echo before-1-after-2 2
+
+before-2: .USEBEFORE before-2-before-1 before-2-before-2 before-2-after-1 before-2-after-2
+ @echo before-2 1
+ @echo before-2 2
+
+before-2-before-1: .USEBEFORE
+ @echo before-2-before-1 1
+ @echo before-2-before-1 2
+
+before-2-before-2: .USEBEFORE
+ @echo before-2-before-2 1
+ @echo before-2-before-2 2
-first: .USEBEFORE
- @echo first 1 # Using ${.TARGET} here would expand to "action"
- @echo first 2 # Using ${.TARGET} here would expand to "action"
+before-2-after-1: .USE
+ @echo before-2-after-1 1
+ @echo before-2-after-1 2
-second: .USEBEFORE
- @echo second 1
- @echo second 2
+before-2-after-2: .USE
+ @echo before-2-after-2 1
+ @echo before-2-after-2 2
+
+after-1: .USE after-1-before-1 after-1-before-2 after-1-after-1 after-1-after-2
+ @echo after-1 1
+ @echo after-1 2
+
+after-1-before-1: .USEBEFORE
+ @echo after-1-before-1 1
+ @echo after-1-before-1 2
+
+after-1-before-2: .USEBEFORE
+ @echo after-1-before-2 1
+ @echo after-1-before-2 2
+
+after-1-after-1: .USE
+ @echo after-1-after-1 1
+ @echo after-1-after-1 2
+
+after-1-after-2: .USE
+ @echo after-1-after-2 1
+ @echo after-1-after-2 2
+
+after-2: .USE after-2-before-1 after-2-before-2 after-2-after-1 after-2-after-2
+ @echo after-2 1
+ @echo after-2 2
+
+after-2-before-1: .USEBEFORE
+ @echo after-2-before-1 1
+ @echo after-2-before-1 2
+
+after-2-before-2: .USEBEFORE
+ @echo after-2-before-2 1
+ @echo after-2-before-2 2
+
+after-2-after-1: .USE
+ @echo after-2-after-1 1
+ @echo after-2-after-1 2
+
+after-2-after-2: .USE
+ @echo after-2-after-2 1
+ @echo after-2-after-2 2
# It is possible but uncommon to have a .USEBEFORE target with no commands.
# This may happen as the result of expanding a .for loop.
empty: .USEBEFORE
-# It is possible but uncommon to directly make a .USEBEFORE target.
+# It is technically possible to directly make a .USEBEFORE target, but it
+# doesn't make sense since GNode_IsOODate considers such a target to always be
+# up to date.
directly: .USEBEFORE
@echo directly
-
-action: second first empty
diff --git a/contrib/bmake/unit-tests/depsrc-wait.exp b/contrib/bmake/unit-tests/depsrc-wait.exp
index d1a60fbaa6e6..36bcb0678151 100644
--- a/contrib/bmake/unit-tests/depsrc-wait.exp
+++ b/contrib/bmake/unit-tests/depsrc-wait.exp
@@ -1,13 +1,18 @@
---- a ---
echo a
a
---- b1 ---
echo b1
b1
---- b ---
echo b
b
---- x ---
echo x
x
+: Making 3a
+: Making 3a
+: Making 3a
+: Making 3b
+: Making 3b
+: Making 3b
+: Making 3c
+: Making 3c
+: Making 3c
exit status 0
diff --git a/contrib/bmake/unit-tests/depsrc-wait.mk b/contrib/bmake/unit-tests/depsrc-wait.mk
index 95b0ea96e0a5..ab974d47c29d 100644
--- a/contrib/bmake/unit-tests/depsrc-wait.mk
+++ b/contrib/bmake/unit-tests/depsrc-wait.mk
@@ -1,9 +1,15 @@
-# $NetBSD: depsrc-wait.mk,v 1.3 2020/09/07 18:40:32 rillig Exp $
+# $NetBSD: depsrc-wait.mk,v 1.4 2022/05/07 17:49:47 rillig Exp $
#
# Tests for the special source .WAIT in dependency declarations,
# which adds a sequence point between the nodes to its left and the nodes
# to its right.
+all: .PHONY
+ @${MAKE} -r -f ${MAKEFILE} x
+ @${MAKE} -r -f ${MAKEFILE} three-by-three
+
+
+.if make(x)
# Even though the build could run massively parallel, the .WAIT imposes a
# strict ordering in this example, which forces the targets to be made in
# exactly this order.
@@ -19,3 +25,17 @@ b: b1
echo b
b1:
echo b1
+.endif
+
+
+# There are 3 groups of 3 targets, with .WAIT barriers in between. Each of
+# these groups has to be made completely before starting the next group.
+# See Makefile, POSTPROC for the postprocessing that takes place.
+.if make(three-by-three)
+.MAKEFLAGS: -j5
+.MAKE.MODE+= randomize-targets
+
+three-by-three: .WAIT 3a1 3a2 3a3 .WAIT 3b1 3b2 3b3 .WAIT 3c1 3c2 3c3 .WAIT
+3a1 3a2 3a3 3b1 3b2 3b3 3c1 3c2 3c3:
+ : Making ${.TARGET}
+.endif
diff --git a/contrib/bmake/unit-tests/depsrc.exp b/contrib/bmake/unit-tests/depsrc.exp
index 06165e6f9ac4..147ea8b24371 100644
--- a/contrib/bmake/unit-tests/depsrc.exp
+++ b/contrib/bmake/unit-tests/depsrc.exp
@@ -1,4 +1,5 @@
: 'Undefined variables are expanded directly in the dependency'
: 'declaration. They are not preserved and maybe expanded later.'
: 'This is in contrast to local variables such as ${.TARGET}.'
+: Making .UNKNOWN from nothing.
exit status 0
diff --git a/contrib/bmake/unit-tests/depsrc.mk b/contrib/bmake/unit-tests/depsrc.mk
index ab9d04c1d3a4..4e5752c97184 100644
--- a/contrib/bmake/unit-tests/depsrc.mk
+++ b/contrib/bmake/unit-tests/depsrc.mk
@@ -1,7 +1,7 @@
-# $NetBSD: depsrc.mk,v 1.4 2020/12/22 19:38:44 rillig Exp $
+# $NetBSD: depsrc.mk,v 1.5 2021/12/13 23:38:54 rillig Exp $
#
# Tests for special sources (those starting with a dot, followed by
-# uppercase letters) in dependency declarations, such as .PHONY.
+# uppercase letters) in dependency declarations, such as '.PHONY'.
# TODO: Implementation
@@ -14,13 +14,19 @@ target: .PHONY source-${DEFINED_LATER}
DEFINED_LATER= later
#
source-: .PHONY
+ # This section applies.
: 'Undefined variables are expanded directly in the dependency'
: 'declaration. They are not preserved and maybe expanded later.'
: 'This is in contrast to local variables such as $${.TARGET}.'
source-later: .PHONY
+ # This section doesn't apply.
: 'Undefined variables are tried to be expanded in a dependency'
: 'declaration. If that fails because the variable is undefined,'
: 'the expression is preserved and tried to be expanded later.'
-all:
- @:;
+# Sources that look like keywords but are not known are interpreted as
+# ordinary sources.
+target: .UNKNOWN
+
+.UNKNOWN:
+ : Making ${.TARGET} from ${.ALLSRC:S,^$,nothing,W}.
diff --git a/contrib/bmake/unit-tests/deptgt-begin.exp b/contrib/bmake/unit-tests/deptgt-begin.exp
index abc80afe9964..db4c7d7dfa13 100644
--- a/contrib/bmake/unit-tests/deptgt-begin.exp
+++ b/contrib/bmake/unit-tests/deptgt-begin.exp
@@ -1,5 +1,5 @@
-make: "deptgt-begin.mk" line 17: warning: duplicate script for target ".BEGIN" ignored
-make: "deptgt-begin.mk" line 8: warning: using previous script for ".BEGIN" defined here
+make: "deptgt-begin.mk" line 19: warning: duplicate script for target ".BEGIN" ignored
+make: "deptgt-begin.mk" line 9: warning: using previous script for ".BEGIN" defined here
: parse time
: Making before-begin before .BEGIN.
: .BEGIN
diff --git a/contrib/bmake/unit-tests/deptgt-begin.mk b/contrib/bmake/unit-tests/deptgt-begin.mk
index b71d78f371ed..8b9842641a2d 100644
--- a/contrib/bmake/unit-tests/deptgt-begin.mk
+++ b/contrib/bmake/unit-tests/deptgt-begin.mk
@@ -1,9 +1,10 @@
-# $NetBSD: deptgt-begin.mk,v 1.5 2020/11/15 22:28:08 rillig Exp $
+# $NetBSD: deptgt-begin.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the special target .BEGIN in dependency declarations,
# which is a container for commands that are run before any other
# commands from the shell lines.
+# expect+2: warning: using previous script for ".BEGIN" defined here
.BEGIN:
: $@
@@ -13,6 +14,7 @@
# add its commands after this.
#
# There are several ways to resolve this situation, which are detailed below.
+# expect+2: warning: duplicate script for target ".BEGIN" ignored
.BEGIN:
: Making another $@.
@@ -25,8 +27,8 @@ before-begin: .PHONY .NOTMAIN
# Another way is to define a custom target and make that a .USE dependency.
# For the .BEGIN target, .USE dependencies do not work though, since in
-# Compat_Run, the .USE and .USEBEFORE nodes are expanded right after the
-# .BEGIN target has been run, which is too late.
+# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
+# .BEGIN target has been made, which is too late.
.BEGIN: use
use: .USE .NOTMAIN
: Making $@ from a .USE dependency.
@@ -35,8 +37,8 @@ use: .USE .NOTMAIN
# .BEGIN target.
#
# For the .BEGIN target, .USEBEFORE dependencies do not work though, since in
-# Compat_Run, the .USE and .USEBEFORE nodes are expanded right after the
-# .BEGIN target has been run, which is too late.
+# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
+# .BEGIN target has been made, which is too late.
.BEGIN: use-before
use-before: .USEBEFORE .NOTMAIN
: Making $@ from a .USEBEFORE dependency.
diff --git a/contrib/bmake/unit-tests/deptgt-default.exp b/contrib/bmake/unit-tests/deptgt-default.exp
index 39a9383953dd..09fca899f063 100644
--- a/contrib/bmake/unit-tests/deptgt-default.exp
+++ b/contrib/bmake/unit-tests/deptgt-default.exp
@@ -1 +1,2 @@
+Default command is making 'not-a-target' from 'not-a-target'.
exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-default.mk b/contrib/bmake/unit-tests/deptgt-default.mk
index 814eaf72aed3..bf5f16536561 100644
--- a/contrib/bmake/unit-tests/deptgt-default.mk
+++ b/contrib/bmake/unit-tests/deptgt-default.mk
@@ -1,8 +1,17 @@
-# $NetBSD: deptgt-default.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-default.mk,v 1.3 2021/12/01 23:56:29 rillig Exp $
#
-# Tests for the special target .DEFAULT in dependency declarations.
+# Tests for the special target .DEFAULT in dependency declarations, which
+# attaches its associated commands to all targets that don't specify any way
+# to create them.
-# TODO: Implementation
+all: test-default not-a-target
+
+test-default: .PHONY
+
+has-commands: .PHONY
+ @echo 'Making ${.TARGET} from ${.IMPSRC}.'
+
+.DEFAULT: dependency-is-ignored
+ @echo "Default command is making '${.TARGET}' from '${.IMPSRC}'."
all:
- @:;
diff --git a/contrib/bmake/unit-tests/deptgt-delete_on_error.exp b/contrib/bmake/unit-tests/deptgt-delete_on_error.exp
index 9d9f1dc3e5ec..e60aa01351e2 100644
--- a/contrib/bmake/unit-tests/deptgt-delete_on_error.exp
+++ b/contrib/bmake/unit-tests/deptgt-delete_on_error.exp
@@ -7,10 +7,8 @@ make: *** deptgt-delete_on_error-regular removed
make: *** deptgt-delete_on_error-regular-delete removed
> deptgt-delete_on_error-phony; false
*** Error code 1 (continuing)
-make: *** deptgt-delete_on_error-phony removed
> deptgt-delete_on_error-phony-delete; false
*** Error code 1 (continuing)
-make: *** deptgt-delete_on_error-phony-delete removed
> deptgt-delete_on_error-precious; false
*** Error code 1 (continuing)
> deptgt-delete_on_error-precious-delete; false
@@ -18,6 +16,7 @@ make: *** deptgt-delete_on_error-phony-delete removed
Stop.
make: stopped in unit-tests
+*** Error code 1 (ignored)
Parallel mode
> deptgt-delete_on_error-regular; false
@@ -47,5 +46,4 @@ make: stopped in unit-tests
make: stopped in unit-tests
*** Error code 1 (ignored)
-*** Error code 1 (ignored)
exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-delete_on_error.mk b/contrib/bmake/unit-tests/deptgt-delete_on_error.mk
index e6d0610f4672..2309e67c01a5 100644
--- a/contrib/bmake/unit-tests/deptgt-delete_on_error.mk
+++ b/contrib/bmake/unit-tests/deptgt-delete_on_error.mk
@@ -1,4 +1,4 @@
- # $NetBSD: deptgt-delete_on_error.mk,v 1.3 2020/10/25 21:31:00 rillig Exp $
+# $NetBSD: deptgt-delete_on_error.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the special target .DELETE_ON_ERROR in dependency declarations,
# which controls whether the target is deleted if a shell command fails or
diff --git a/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk b/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk
index 29346b8321fe..dc921bcfda2c 100644
--- a/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk
+++ b/contrib/bmake/unit-tests/deptgt-end-fail-indirect.mk
@@ -1,10 +1,10 @@
-# $NetBSD: deptgt-end-fail-indirect.mk,v 1.2 2020/12/06 21:22:04 rillig Exp $
+# $NetBSD: deptgt-end-fail-indirect.mk,v 1.3 2022/05/07 08:01:20 rillig Exp $
#
# Tests for an error in a dependency of the .END node.
#
# Before 2020-11-25, an error in the .END target did not print the "Stop."
# and exited with status 0. The cause for this was a missing condition in
-# Compat_Run in the handling of the .END node.
+# Compat_MakeAll in the handling of the .END node.
all:
: $@
diff --git a/contrib/bmake/unit-tests/deptgt-end-fail.mk b/contrib/bmake/unit-tests/deptgt-end-fail.mk
index 57cdc7da8679..c77127f26091 100644
--- a/contrib/bmake/unit-tests/deptgt-end-fail.mk
+++ b/contrib/bmake/unit-tests/deptgt-end-fail.mk
@@ -1,11 +1,11 @@
-# $NetBSD: deptgt-end-fail.mk,v 1.6 2020/12/07 01:04:07 rillig Exp $
+# $NetBSD: deptgt-end-fail.mk,v 1.7 2022/05/07 08:01:20 rillig Exp $
#
# Tests for an errors in the main target, its dependencies,
# the .END node and its dependencies.
#
# Before 2020-11-25, an error in the .END target did not print the "Stop.",
# even though this was intended. The cause for this was a missing condition
-# in Compat_Run, in the code handling the .END node.
+# in Compat_MakeAll, in the code handling the .END node.
test: .PHONY
diff --git a/contrib/bmake/unit-tests/deptgt-error.exp b/contrib/bmake/unit-tests/deptgt-error.exp
index 39a9383953dd..48e2f90954cf 100644
--- a/contrib/bmake/unit-tests/deptgt-error.exp
+++ b/contrib/bmake/unit-tests/deptgt-error.exp
@@ -1 +1,9 @@
-exit status 0
+false fails
+*** Error code 1 (continuing)
+
+Stop.
+make: stopped in unit-tests
+ERROR_INFO='This information is printed on 'errors'.'
+Making sub-error as prerequisite.
+Making .ERROR out of nothing.
+exit status 1
diff --git a/contrib/bmake/unit-tests/deptgt-error.mk b/contrib/bmake/unit-tests/deptgt-error.mk
index 5d515b95afc3..67f94e6999f7 100644
--- a/contrib/bmake/unit-tests/deptgt-error.mk
+++ b/contrib/bmake/unit-tests/deptgt-error.mk
@@ -1,9 +1,21 @@
-# $NetBSD: deptgt-error.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-error.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
#
# Tests for the special target .ERROR in dependency declarations, which
-# collects commands that are run when another target fails.
+# is made when another target fails.
-# TODO: Implementation
+all: .PHONY
+ false fails
-all:
- @:;
+.ERROR:
+ @echo 'Making ${.TARGET} out of nothing.'
+
+.ERROR: sub-error
+sub-error: .PHONY
+ @echo 'Making ${.TARGET} as prerequisite.'
+
+# Before making the '.ERROR' target, these variable values are printed.
+MAKE_PRINT_VAR_ON_ERROR= ERROR_INFO
+
+# Use single quotes to demonstrate that the output is only informational, it
+# does not use any established escaping mechanism.
+ERROR_INFO= This information is ${:Uprinted} on 'errors'.
diff --git a/contrib/bmake/unit-tests/deptgt-ignore.exp b/contrib/bmake/unit-tests/deptgt-ignore.exp
index 39a9383953dd..2aa1311c8ff7 100644
--- a/contrib/bmake/unit-tests/deptgt-ignore.exp
+++ b/contrib/bmake/unit-tests/deptgt-ignore.exp
@@ -1 +1,11 @@
-exit status 0
+error-failed before
+*** Error code 1 (continuing)
+error-ignored before
+*** Error code 1 (ignored)
+error-ignored after
+Making depends-on-ignored from error-ignored.
+`all' not remade because of errors.
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/deptgt-ignore.mk b/contrib/bmake/unit-tests/deptgt-ignore.mk
index 49c14d2cfd43..a0191847e69f 100644
--- a/contrib/bmake/unit-tests/deptgt-ignore.mk
+++ b/contrib/bmake/unit-tests/deptgt-ignore.mk
@@ -1,9 +1,31 @@
-# $NetBSD: deptgt-ignore.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-ignore.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
#
# Tests for the special target .IGNORE in dependency declarations, which
# does not stop if a command from this target exits with a non-zero status.
+#
+# This test only applies to compatibility mode. In jobs mode such as with
+# '-j1', all commands for a single target are bundled into a single shell
+# program, which is a different implementation technique, the .IGNORE applies
+# there as well.
+
+.MAKEFLAGS: -d0 # force stdout to be unbuffered
+
+all: depends-on-failed depends-on-ignored
+.PHONY: all depends-on-failed depends-on-ignored error-failed error-ignored
+
+error-failed error-ignored:
+ @echo '${.TARGET} before'
+ @false
+ @echo '${.TARGET} after'
+
+depends-on-failed: error-failed
+ @echo 'Making ${.TARGET} from ${.ALLSRC}.'
+depends-on-ignored: error-ignored
+ @echo 'Making ${.TARGET} from ${.ALLSRC}.'
-# TODO: Implementation
+# Even though the command 'false' in the middle fails, the remaining commands
+# are still run. After that, the target is marked made, so targets depending
+# on the target with the ignored commands are made.
+.IGNORE: error-ignored
-all:
- @:;
+#.MAKEFLAGS: -dg2
diff --git a/contrib/bmake/unit-tests/deptgt-interrupt.exp b/contrib/bmake/unit-tests/deptgt-interrupt.exp
index 39a9383953dd..e59bdc7d7c41 100644
--- a/contrib/bmake/unit-tests/deptgt-interrupt.exp
+++ b/contrib/bmake/unit-tests/deptgt-interrupt.exp
@@ -1 +1,2 @@
-exit status 0
+Ctrl-C
+exit status 130
diff --git a/contrib/bmake/unit-tests/deptgt-interrupt.mk b/contrib/bmake/unit-tests/deptgt-interrupt.mk
index d94009a52e05..9a3b4d9e81c9 100644
--- a/contrib/bmake/unit-tests/deptgt-interrupt.mk
+++ b/contrib/bmake/unit-tests/deptgt-interrupt.mk
@@ -1,10 +1,11 @@
-# $NetBSD: deptgt-interrupt.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-interrupt.mk,v 1.4 2022/01/22 21:50:41 rillig Exp $
#
# Tests for the special target .INTERRUPT in dependency declarations, which
# collects commands to be run when make is interrupted while building another
# target.
-# TODO: Implementation
-
all:
- @:;
+ @kill -INT ${.MAKE.PID}
+
+.INTERRUPT:
+ @echo 'Ctrl-C'
diff --git a/contrib/bmake/unit-tests/deptgt-main.exp b/contrib/bmake/unit-tests/deptgt-main.exp
index 39a9383953dd..40c9a2c3cb8f 100644
--- a/contrib/bmake/unit-tests/deptgt-main.exp
+++ b/contrib/bmake/unit-tests/deptgt-main.exp
@@ -1 +1,2 @@
+This target real-main is the one that is made.
exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-main.mk b/contrib/bmake/unit-tests/deptgt-main.mk
index 84d05dc25ed6..184b6f3f73bb 100644
--- a/contrib/bmake/unit-tests/deptgt-main.mk
+++ b/contrib/bmake/unit-tests/deptgt-main.mk
@@ -1,10 +1,29 @@
-# $NetBSD: deptgt-main.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-main.mk,v 1.4 2022/01/23 21:48:59 rillig Exp $
#
# Tests for the special target .MAIN in dependency declarations, which defines
# the main target. This main target is built if no target has been specified
# on the command line or via MAKEFLAGS.
-# TODO: Implementation
+# The first target becomes the main target by default. It can be overridden
+# though.
+all: .PHONY
+ @echo 'This target is not made.'
-all:
- @:;
+# This target is not the first to be defined, but it lists '.MAIN' as one of
+# its sources. The word '.MAIN' only has a special meaning when it appears as
+# a _target_ in a dependency declaration, not as a _source_. It is thus
+# ignored.
+depsrc-main: .PHONY .MAIN
+ @echo 'This target is not made either.'
+
+# This target is the first to be marked with '.MAIN', so it replaces the
+# previous main target, which was 'all'.
+.MAIN: real-main
+real-main: .PHONY
+ @echo 'This target ${.TARGET} is the one that is made.'
+
+# This target is marked with '.MAIN' but there already is a main target. The
+# attribute '.MAIN' is thus ignored.
+.MAIN: too-late
+too-late: .PHONY
+ @echo 'This target comes too late, there is already a .MAIN target.'
diff --git a/contrib/bmake/unit-tests/deptgt-makeflags.exp b/contrib/bmake/unit-tests/deptgt-makeflags.exp
index 11043bc5110c..ea29f76ad464 100644
--- a/contrib/bmake/unit-tests/deptgt-makeflags.exp
+++ b/contrib/bmake/unit-tests/deptgt-makeflags.exp
@@ -1,9 +1,9 @@
-Global:delete DOLLAR (not found)
+Global: ignoring delete 'DOLLAR' as it is not found
Command: DOLLAR = $$$$
Global: .MAKEOVERRIDES = VAR DOLLAR
CondParser_Eval: ${DOLLAR} != "\$\$"
Var_Parse: ${DOLLAR} != "\$\$" (eval-defined)
-lhs = "$$", rhs = "$$", op = !=
+Comparing "$$" != "$$"
Global: .MAKEFLAGS = -r -k -D VAR -D VAR -d cv -d
Global: .MAKEFLAGS = -r -k -D VAR -D VAR -d cv -d 0
make: Unterminated quoted string [make VAR=initial UNBALANCED=']
diff --git a/contrib/bmake/unit-tests/deptgt-makeflags.mk b/contrib/bmake/unit-tests/deptgt-makeflags.mk
index 0a0f410e14c4..2f8b00743e3f 100644
--- a/contrib/bmake/unit-tests/deptgt-makeflags.mk
+++ b/contrib/bmake/unit-tests/deptgt-makeflags.mk
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt-makeflags.mk,v 1.6 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: deptgt-makeflags.mk,v 1.9 2023/11/19 22:32:44 rillig Exp $
#
# Tests for the special target .MAKEFLAGS in dependency declarations,
# which adds command line options later, at parse time.
@@ -65,9 +65,9 @@
.endif
# Next try at defining another newline variable. Since whitespace around the
-# variable value is trimmed, two empty variable expressions surround the
+# variable value is trimmed, two empty expressions ${:U} surround the
# literal newline now. This prevents the newline from being skipped during
-# parsing. The ':=' assignment operator expands the empty variable
+# parsing. The ':=' assignment operator expands the empty
# expressions, leaving only the newline as the variable value.
#
# This is one of the very few ways (maybe even the only one) to inject literal
@@ -81,6 +81,31 @@
.endif
#.MAKEFLAGS: -d0
+# Now do the same for the other escape sequences; see Substring_Words.
+.MAKEFLAGS: CHAR_BS:="$${:U}\b$${:U}"
+.MAKEFLAGS: CHAR_FF:="$${:U}\f$${:U}"
+.MAKEFLAGS: CHAR_NL:="$${:U}\n$${:U}"
+.MAKEFLAGS: CHAR_CR:="$${:U}\r$${:U}"
+.MAKEFLAGS: CHAR_TAB:="$${:U}\t$${:U}"
+
+# Note: backspace is not whitespace, it is a control character.
+.if ${CHAR_BS:C,^[[:cntrl:]]$,found,W} != "found"
+. error
+.endif
+.if ${CHAR_FF:C,^[[:space:]]$,found,W} != "found"
+. error
+.endif
+.if ${CHAR_NL:C,^[[:space:]]$,found,W} != "found"
+. error
+.endif
+.if ${CHAR_CR:C,^[[:space:]]$,found,W} != "found"
+. error
+.endif
+.if ${CHAR_TAB:C,^[[:space:]]$,found,W} != "found"
+. error
+.endif
+
+
# Unbalanced quotes produce an error message. If they occur anywhere in the
# command line, the whole command line is skipped.
.MAKEFLAGS: VAR=previous
diff --git a/contrib/bmake/unit-tests/deptgt-notparallel.exp b/contrib/bmake/unit-tests/deptgt-notparallel.exp
index 39a9383953dd..1e4d8ad7befb 100644
--- a/contrib/bmake/unit-tests/deptgt-notparallel.exp
+++ b/contrib/bmake/unit-tests/deptgt-notparallel.exp
@@ -1 +1,9 @@
+: Making 1 out of nothing.
+: Making 2 out of nothing.
+: Making 3 out of nothing.
+: Making 4 out of nothing.
+: Making 5 out of nothing.
+: Making 6 out of nothing.
+: Making 7 out of nothing.
+: Making 8 out of nothing.
exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-notparallel.mk b/contrib/bmake/unit-tests/deptgt-notparallel.mk
index db08aa9d3558..8d32ed8f2461 100644
--- a/contrib/bmake/unit-tests/deptgt-notparallel.mk
+++ b/contrib/bmake/unit-tests/deptgt-notparallel.mk
@@ -1,8 +1,16 @@
-# $NetBSD: deptgt-notparallel.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-notparallel.mk,v 1.3 2021/12/13 23:38:54 rillig Exp $
#
-# Tests for the special target .NOTPARALLEL in dependency declarations.
+# Tests for the special target .NOTPARALLEL in dependency declarations, which
+# prevents the job module from doing anything in parallel, by setting the
+# maximum jobs to 1. This only applies to the current make, it is not
+# exported to submakes.
-# TODO: Implementation
+.MAKEFLAGS: -j4
-all:
- @:;
+# Set opts.maxJobs back to 1. Without this line, the output would be in
+# random order, interleaved with separators like '--- 1 ---'.
+.NOTPARALLEL:
+
+all: 1 2 3 4 5 6 7 8
+1 2 3 4 5 6 7 8: .PHONY
+ : Making ${.TARGET} out of nothing.
diff --git a/contrib/bmake/unit-tests/deptgt-order.exp b/contrib/bmake/unit-tests/deptgt-order.exp
index 5f7dde0ac69d..ecbf03fcc572 100644
--- a/contrib/bmake/unit-tests/deptgt-order.exp
+++ b/contrib/bmake/unit-tests/deptgt-order.exp
@@ -1,3 +1,10 @@
+Parsing line 15: .ORDER: three one
+ParseDependency(.ORDER: three one)
+# .ORDER forces 'three' to be made before 'one'
+# three, unmade, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS, flags none
+# one, unmade, type OP_DEPENDS|OP_PHONY, flags none
+Parsing line 16: .MAKEFLAGS: -d0
+ParseDependency(.MAKEFLAGS: -d0)
: 'Making two out of one.'
: 'Making three out of two.'
: 'Making all out of three.'
diff --git a/contrib/bmake/unit-tests/deptgt-order.mk b/contrib/bmake/unit-tests/deptgt-order.mk
index f241331ae1e1..88f5958425dd 100644
--- a/contrib/bmake/unit-tests/deptgt-order.mk
+++ b/contrib/bmake/unit-tests/deptgt-order.mk
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt-order.mk,v 1.3 2021/06/17 15:25:33 rillig Exp $
+# $NetBSD: deptgt-order.mk,v 1.4 2021/12/13 23:38:54 rillig Exp $
#
# Tests for the special target .ORDER in dependency declarations.
@@ -11,7 +11,9 @@ three: two
# This .ORDER creates a circular dependency since 'three' depends on 'one'
# but 'one' is supposed to be built after 'three'.
+.MAKEFLAGS: -dp
.ORDER: three one
+.MAKEFLAGS: -d0
# XXX: The circular dependency should be detected here.
all: three
diff --git a/contrib/bmake/unit-tests/deptgt-path-suffix.exp b/contrib/bmake/unit-tests/deptgt-path-suffix.exp
index 39a9383953dd..228a29851f48 100644
--- a/contrib/bmake/unit-tests/deptgt-path-suffix.exp
+++ b/contrib/bmake/unit-tests/deptgt-path-suffix.exp
@@ -1 +1,4 @@
-exit status 0
+make: "deptgt-path-suffix.mk" line 8: Suffix '.c' not defined (yet)
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/deptgt-path-suffix.mk b/contrib/bmake/unit-tests/deptgt-path-suffix.mk
index 3a7e697bc748..494a076a5520 100644
--- a/contrib/bmake/unit-tests/deptgt-path-suffix.mk
+++ b/contrib/bmake/unit-tests/deptgt-path-suffix.mk
@@ -1,8 +1,16 @@
-# $NetBSD: deptgt-path-suffix.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-path-suffix.mk,v 1.3 2021/12/13 23:38:54 rillig Exp $
#
# Tests for the special target .PATH.suffix in dependency declarations.
# TODO: Implementation
+# expect+1: Suffix '.c' not defined (yet)
+.PATH.c: ..
+
+.SUFFIXES: .c
+
+# Now the suffix is defined, and the path is recorded.
+.PATH.c: ..
+
all:
@:;
diff --git a/contrib/bmake/unit-tests/deptgt-phony.exp b/contrib/bmake/unit-tests/deptgt-phony.exp
index 39a9383953dd..1c379b32a33b 100644
--- a/contrib/bmake/unit-tests/deptgt-phony.exp
+++ b/contrib/bmake/unit-tests/deptgt-phony.exp
@@ -1 +1,42 @@
+Expanding "depsrc-phony-pr-15164-*-wildcard"...
+Expanding "deptgt-phony-pr-15164-*-wildcard"...
+Searching for .depend ...
+ failed.
+Searching for .depend ...
+ . ...
+ failed.
+Wildcard expanding "all"...
+Searching for all ...
+ failed.
+Found 'all' as '(not found)'
+SuffFindDeps "all"
+ No known suffix on all. Using .NULL suffix
+adding suffix rules
+Wildcard expanding "depsrc-phony-pr-15164-*-wildcard"...
+Expanding "depsrc-phony-pr-15164-*-wildcard"...
+
+Wildcard expanding "deptgt-phony-pr-15164-*-wildcard"...
+Expanding "deptgt-phony-pr-15164-*-wildcard"...
+
+Searching for all ...
+ failed.
+SuffFindDeps "depsrc-phony-pr-15164"
+ No valid suffix on depsrc-phony-pr-15164
+SuffFindDeps "deptgt-phony-pr-15164"
+ No valid suffix on deptgt-phony-pr-15164
+: Making depsrc-phony-pr-15164
+: Making deptgt-phony-pr-15164
+Wildcard expanding "all"...
+Searching for all ...
+ failed.
+Found 'all' as '(not found)'
+SuffFindDeps ".END"
+ No known suffix on .END. Using .NULL suffix
+adding suffix rules
+Searching for .END ...
+ failed.
+Wildcard expanding ".END"...
+Searching for .END ...
+ failed.
+Found '.END' as '(not found)'
exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-phony.mk b/contrib/bmake/unit-tests/deptgt-phony.mk
index 7f9909fa89a2..d5616e0edd96 100644
--- a/contrib/bmake/unit-tests/deptgt-phony.mk
+++ b/contrib/bmake/unit-tests/deptgt-phony.mk
@@ -1,8 +1,31 @@
-# $NetBSD: deptgt-phony.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-phony.mk,v 1.3 2022/02/11 23:44:18 rillig Exp $
#
# Tests for the special target .PHONY in dependency declarations.
# TODO: Implementation
all:
- @:;
+
+
+# https://gnats.netbsd.org/15164 describes that .PHONY targets are still
+# looked up in directories, even though .PHONY means that these targets do
+# _not_ correspond to actual files.
+#
+# expect: Expanding "depsrc-phony-pr-15164-*-wildcard"...
+# expect: Expanding "deptgt-phony-pr-15164-*-wildcard"...
+.MAKEFLAGS: -dds
+depsrc-phony-pr-15164: .PHONY
+ : Making ${.TARGET}
+depsrc-phony-pr-15164-*-wildcard: .PHONY
+ : Making ${.TARGET}
+
+.PHONY: deptgt-phony-pr-15164
+deptgt-phony-pr-15164:
+ : Making ${.TARGET}
+
+.PHONY: deptgt-phony-pr-15164-*-wildcard
+deptgt-phony-pr-15164-*-wildcard:
+ : Making ${.TARGET}
+
+all: depsrc-phony-pr-15164 depsrc-phony-pr-15164-*-wildcard
+all: deptgt-phony-pr-15164 deptgt-phony-pr-15164-*-wildcard
diff --git a/contrib/bmake/unit-tests/envfirst.exp b/contrib/bmake/unit-tests/deptgt-posix.exp
index 39a9383953dd..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/envfirst.exp
+++ b/contrib/bmake/unit-tests/deptgt-posix.exp
diff --git a/contrib/bmake/unit-tests/deptgt-posix.mk b/contrib/bmake/unit-tests/deptgt-posix.mk
new file mode 100644
index 000000000000..bf29dbfbd627
--- /dev/null
+++ b/contrib/bmake/unit-tests/deptgt-posix.mk
@@ -0,0 +1,123 @@
+# $NetBSD: deptgt-posix.mk,v 1.4 2022/05/07 21:24:52 rillig Exp $
+#
+# Tests for the special target '.POSIX', which enables POSIX mode.
+#
+# As of 2022-04-18, when parsing the dependency line '.POSIX', the variable
+# '%POSIX' is defined and <posix.mk> is included, if it exists. Other than
+# that, POSIX support is still incomplete, the exact set of supported features
+# needs to be cross-checked with the POSIX specification.
+#
+# At the point of '.POSIX:', <sys.mk> has been loaded already, unless the
+# option '-r' was given. This means that an implementation of <posix.mk> must
+# work both with and without the system rules from <sys.mk> being in effect.
+#
+# Implementation note: this test needs to run isolated from the usual tests
+# directory to prevent unit-tests/posix.mk from interfering with the posix.mk
+# from the system directory that this test uses; since at least 1997, the
+# directive '.include <file>' has been looking in the current directory first
+# before searching the file in the system search path, as described in
+# https://gnats.netbsd.org/15163.
+#
+# See also:
+# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
+
+TESTTMP= ${TMPDIR:U/tmp}/make.test.deptgt-posix
+SYSDIR= ${TESTTMP}/sysdir
+MAIN_MK= ${TESTTMP}/main.mk
+INCLUDED_MK= ${TESTTMP}/included.mk
+
+all: .PHONY
+.SILENT:
+
+set-up-sysdir: .USEBEFORE
+ mkdir -p ${SYSDIR}
+ printf '%s\n' > ${SYSDIR}/sys.mk \
+ 'CC=sys-cc' \
+ 'SEEN_SYS_MK=yes'
+ printf '%s\n' > ${SYSDIR}/posix.mk \
+ 'CC=posix-cc'
+
+check-is-posix: .USE
+ printf '%s\n' >> ${MAIN_MK} \
+ '.if $${CC} != "posix-cc"' \
+ '. error' \
+ '.endif' \
+ '.if $${%POSIX} != "1003.2"' \
+ '. error' \
+ '.endif' \
+ 'all: .PHONY'
+
+check-not-posix: .USE
+ printf '%s\n' >> ${MAIN_MK} \
+ '.if $${CC} != "sys-cc"' \
+ '. error' \
+ '.endif' \
+ '.if defined(%POSIX)' \
+ '. error' \
+ '.endif' \
+ 'all: .PHONY'
+
+check-not-seen-sys-mk: .USE
+ printf '%s\n' >> ${MAIN_MK} \
+ '.if defined(SEEN_SYS_MK)' \
+ '. error' \
+ '.endif'
+
+run: .USE
+ (cd "${TESTTMP}" && MAKEFLAGS=${MAKEFLAGS.${.TARGET}:Q} ${MAKE} \
+ -m "${SYSDIR}" -f ${MAIN_MK:T})
+ rm -rf ${TESTTMP}
+
+# If the main makefile has a '.for' loop as its first non-comment line, a
+# strict reading of POSIX 2018 makes the makefile non-conforming.
+all: after-for
+after-for: .PHONY set-up-sysdir check-not-posix run
+ printf '%s\n' > ${MAIN_MK} \
+ '# comment' \
+ '' \
+ '.for i in once' \
+ '.POSIX:' \
+ '.endfor'
+
+# If the main makefile has an '.if' conditional as its first non-comment line,
+# a strict reading of POSIX 2018 makes the makefile non-conforming.
+all: after-if
+after-if: .PHONY set-up-sysdir check-not-posix run
+ printf '%s\n' > ${MAIN_MK} \
+ '# comment' \
+ '' \
+ '.if 1' \
+ '.POSIX:' \
+ '.endif'
+
+# If the main makefile first includes another makefile and that included
+# makefile tries to switch to POSIX mode, that's too late.
+all: in-included-file
+in-included-file: .PHONY set-up-sysdir check-not-posix run
+ printf 'include included.mk\n' > ${MAIN_MK}
+ printf '.POSIX:\n' > ${INCLUDED_MK}
+
+# If the main makefile switches to POSIX mode in its very first line, before
+# and comment lines or empty lines, that works.
+all: in-first-line
+in-first-line: .PHONY set-up-sysdir check-is-posix run
+ printf '%s\n' > ${MAIN_MK} \
+ '.POSIX:'
+
+# The only allowed lines before switching to POSIX mode are comment lines.
+# POSIX defines comment lines as "blank lines, empty lines, and lines with
+# <number-sign> ('#') as the first character".
+all: after-comment-lines
+after-comment-lines: .PHONY set-up-sysdir check-is-posix run
+ printf '%s\n' > ${MAIN_MK} \
+ '# comment' \
+ '' \
+ '.POSIX:'
+
+# Running make with the option '-r' skips the builtin rules from <sys.mk>.
+# In that mode, '.POSIX:' just loads <posix.mk>, which works as well.
+MAKEFLAGS.no-builtins= -r
+all: no-builtins
+no-builtins: .PHONY set-up-sysdir check-is-posix check-not-seen-sys-mk run
+ printf '%s\n' > ${MAIN_MK} \
+ '.POSIX:'
diff --git a/contrib/bmake/unit-tests/deptgt-silent-jobs.exp b/contrib/bmake/unit-tests/deptgt-silent-jobs.exp
new file mode 100644
index 000000000000..4d8a73b36139
--- /dev/null
+++ b/contrib/bmake/unit-tests/deptgt-silent-jobs.exp
@@ -0,0 +1,7 @@
+compat: testing 1
+compat: testing 2
+compat: testing 3
+jobs: testing 1
+jobs: testing 2
+jobs: testing 3
+exit status 0
diff --git a/contrib/bmake/unit-tests/deptgt-silent-jobs.mk b/contrib/bmake/unit-tests/deptgt-silent-jobs.mk
new file mode 100644
index 000000000000..aed85932281b
--- /dev/null
+++ b/contrib/bmake/unit-tests/deptgt-silent-jobs.mk
@@ -0,0 +1,34 @@
+# $NetBSD: deptgt-silent-jobs.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
+#
+# Ensure that the special dependency target '.SILENT' only affects the amount
+# of output, but not the kind of error handling.
+#
+# History:
+# In job.c 1.83 from 2003.12.20.00.18.22, in an attempt to fix
+# https://gnats.netbsd.org/18573, commands that suppressed error
+# handling were output in jobs mode, even when the global '.SILENT'
+# was set. This was fixed in job.c 1.452 from 2022-02-12.
+#
+# See also:
+# https://gnats.netbsd.org/45356
+
+all: compat jobs
+.PHONY: all compat jobs test
+
+.SILENT:
+test:
+ @echo '${VARIANT}: testing 1'
+ -echo '${VARIANT}: testing 2'
+ echo '${VARIANT}: testing 3'
+
+# expect: compat: testing 1
+# expect: compat: testing 2
+# expect: compat: testing 3
+compat:
+ @${MAKE} -r -f ${MAKEFILE} test VARIANT=compat
+
+# expect: jobs: testing 1
+# expect: jobs: testing 2
+# expect: jobs: testing 3
+jobs:
+ @${MAKE} -r -f ${MAKEFILE} test VARIANT=jobs -j1
diff --git a/contrib/bmake/unit-tests/deptgt.exp b/contrib/bmake/unit-tests/deptgt.exp
index bdac2aee3e6c..00d312685de9 100644
--- a/contrib/bmake/unit-tests/deptgt.exp
+++ b/contrib/bmake/unit-tests/deptgt.exp
@@ -1,14 +1,17 @@
-make: "deptgt.mk" line 10: warning: Extra target ignored
-make: "deptgt.mk" line 28: Unassociated shell command ": command3 # parse error, since targets == NULL"
-ParseReadLine (34): '${:U}: empty-source'
+make: "deptgt.mk" line 11: warning: Extra target '.PHONY' ignored
+make: "deptgt.mk" line 30: Unassociated shell command ": command3 # parse error, since targets == NULL"
+Parsing line 36: ${:U}: empty-source
ParseDependency(: empty-source)
-ParseReadLine (35): ' : command for empty targets list'
-ParseReadLine (36): ': empty-source'
+Parsing line 37: : command for empty targets list
+Parsing line 38: : empty-source
ParseDependency(: empty-source)
-ParseReadLine (37): ' : command for empty targets list'
-ParseReadLine (38): '.MAKEFLAGS: -d0'
+Parsing line 39: : command for empty targets list
+Parsing line 40: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
-make: "deptgt.mk" line 46: Unknown modifier "Z"
+make: "deptgt.mk" line 49: Unknown modifier "Z"
+make: "deptgt.mk" line 52: warning: Extra target 'ordinary' ignored
+make: "deptgt.mk" line 55: warning: Extra target (ordinary) ignored
+make: "deptgt.mk" line 58: warning: Special and mundane targets don't mix. Mundane ones ignored
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/deptgt.mk b/contrib/bmake/unit-tests/deptgt.mk
index 15d7e59aeced..30b8399191bd 100644
--- a/contrib/bmake/unit-tests/deptgt.mk
+++ b/contrib/bmake/unit-tests/deptgt.mk
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt.mk,v 1.11 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: deptgt.mk,v 1.16 2023/12/17 09:44:00 rillig Exp $
#
# Tests for special targets like .BEGIN or .SUFFIXES in dependency
# declarations.
@@ -7,6 +7,7 @@
# Just in case anyone tries to compile several special targets in a single
# dependency line: That doesn't work, and make immediately rejects it.
+# expect+1: warning: Extra target '.PHONY' ignored
.SUFFIXES .PHONY: .c.o
# The following lines demonstrate how 'targets' is set and reset during
@@ -25,10 +26,11 @@ target1 target2: sources # targets := [target1, target2]
: command1 # targets == [target1, target2]
: command2 # targets == [target1, target2]
VAR=value # targets := NULL
+# expect+1: Unassociated shell command ": command3 # parse error, since targets == NULL"
: command3 # parse error, since targets == NULL
# In a dependency declaration, the list of targets can be empty.
-# It doesn't matter whether the empty string is generated by a variable
+# It doesn't matter whether the empty string is generated by an
# expression or whether it is just omitted.
.MAKEFLAGS: -dp
${:U}: empty-source
@@ -43,7 +45,17 @@ ${:U}: empty-source
# expansion would be to use the variable modifier '::=' to modify the
# targets. This in turn would be such an extreme and unreliable edge case
# that nobody uses it.
+# expect+1: Unknown modifier "Z"
$$$$$$$${:U:Z}:
+# expect+1: warning: Extra target 'ordinary' ignored
+.END ordinary:
+
+# expect+1: warning: Extra target (ordinary) ignored
+.PATH ordinary:
+
+# expect+1: warning: Special and mundane targets don't mix. Mundane ones ignored
+ordinary .PATH:
+
all:
@:;
diff --git a/contrib/bmake/unit-tests/dir.mk b/contrib/bmake/unit-tests/dir.mk
index 36fe2baf978c..956285393489 100644
--- a/contrib/bmake/unit-tests/dir.mk
+++ b/contrib/bmake/unit-tests/dir.mk
@@ -1,8 +1,10 @@
-# $NetBSD: dir.mk,v 1.9 2021/01/23 10:48:49 rillig Exp $
+# $NetBSD: dir.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $
#
# Tests for dir.c.
-.MAKEFLAGS: -m / # hide /usr/share/mk from the debug log
+# hide /usr/share/mk from the debug log
+.SYSPATH:
+.SYSPATH: /
# Dependency lines may use braces for expansion.
# See DirExpandCurly for the implementation.
@@ -65,7 +67,7 @@ fetch fetch-post extract extract-post:
# The expansions may have duplicates.
# When the source of the dependency line is expanded later, each of the
-# expanded words will be the same.
+# expanded words resolves to the same node.
all: dup-{1,1,1,1,1,1,1}
dup-1:
diff --git a/contrib/bmake/unit-tests/directive-dinclude.exp b/contrib/bmake/unit-tests/directive-dinclude.exp
index 39a9383953dd..8f71e42c0515 100755
--- a/contrib/bmake/unit-tests/directive-dinclude.exp
+++ b/contrib/bmake/unit-tests/directive-dinclude.exp
@@ -1 +1,4 @@
-exit status 0
+make: "directive-dinclude-error.inc" line 1: Invalid line 'syntax error'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-dinclude.mk b/contrib/bmake/unit-tests/directive-dinclude.mk
index 94fa5fb4429b..7fccff413cd6 100755
--- a/contrib/bmake/unit-tests/directive-dinclude.mk
+++ b/contrib/bmake/unit-tests/directive-dinclude.mk
@@ -1,9 +1,24 @@
-# $NetBSD: directive-dinclude.mk,v 1.1 2020/09/13 09:20:23 rillig Exp $
+# $NetBSD: directive-dinclude.mk,v 1.3 2023/08/19 10:52:13 rillig Exp $
#
# Tests for the .dinclude directive, which includes another file,
-# typically named .depend.
+# silently skipping it if it cannot be opened. This is primarily used for
+# including '.depend' files, that's where the 'd' comes from.
+#
+# The 'silently skipping' only applies to the case where the file cannot be
+# opened. Parse errors and other errors are handled the same way as in the
+# other .include directives.
+
+# No complaint that there is no such file.
+.dinclude "${.CURDIR}/directive-dinclude-nonexistent.inc"
+
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.dinclude "${MAKEFILE}/subdir"
-# TODO: Implementation
+# Errors that are not related to opening the file are still reported.
+# expect: make: "directive-dinclude-error.inc" line 1: Invalid line 'syntax error'
+_!= echo 'syntax error' > directive-dinclude-error.inc
+.dinclude "${.CURDIR}/directive-dinclude-error.inc"
+_!= rm directive-dinclude-error.inc
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive-elif.exp b/contrib/bmake/unit-tests/directive-elif.exp
index 6856494023d7..15dd6bf1430b 100644
--- a/contrib/bmake/unit-tests/directive-elif.exp
+++ b/contrib/bmake/unit-tests/directive-elif.exp
@@ -1,21 +1,21 @@
-make: "directive-elif.mk" line 47: Unknown directive "elsif"
-make: "directive-elif.mk" line 52: This branch is taken.
-make: "directive-elif.mk" line 60: Unknown directive "elsif"
-make: "directive-elif.mk" line 63: This branch is taken.
-make: "directive-elif.mk" line 69: This branch is taken.
-make: "directive-elif.mk" line 89: Unknown directive "elsif"
-make: "directive-elif.mk" line 90: This misspelling is detected.
-make: "directive-elif.mk" line 91: This branch is taken because of the .else.
-make: "directive-elif.mk" line 109: What happens on misspelling in a skipped branch?
-make: "directive-elif.mk" line 119: else
-make: "directive-elif.mk" line 122: What happens on misspelling in a taken branch?
-make: "directive-elif.mk" line 124: 1-then
-make: "directive-elif.mk" line 125: Unknown directive "elsif"
-make: "directive-elif.mk" line 126: 1-elsif
-make: "directive-elif.mk" line 127: Unknown directive "elsif"
-make: "directive-elif.mk" line 128: 2-elsif
-make: "directive-elif.mk" line 134: if-less elif
-make: "directive-elif.mk" line 139: warning: extra elif
+make: "directive-elif.mk" line 48: Unknown directive "elsif"
+make: "directive-elif.mk" line 54: This branch is taken.
+make: "directive-elif.mk" line 62: Unknown directive "elsif"
+make: "directive-elif.mk" line 66: This branch is taken.
+make: "directive-elif.mk" line 73: This branch is taken.
+make: "directive-elif.mk" line 94: Unknown directive "elsif"
+make: "directive-elif.mk" line 96: This misspelling is detected.
+make: "directive-elif.mk" line 98: This branch is taken because of the .else.
+make: "directive-elif.mk" line 117: What happens on misspelling in a skipped branch?
+make: "directive-elif.mk" line 128: else
+make: "directive-elif.mk" line 132: What happens on misspelling in a taken branch?
+make: "directive-elif.mk" line 135: 1-then
+make: "directive-elif.mk" line 137: Unknown directive "elsif"
+make: "directive-elif.mk" line 139: 1-elsif
+make: "directive-elif.mk" line 141: Unknown directive "elsif"
+make: "directive-elif.mk" line 143: 2-elsif
+make: "directive-elif.mk" line 149: if-less elif
+make: "directive-elif.mk" line 154: warning: extra elif
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-elif.mk b/contrib/bmake/unit-tests/directive-elif.mk
index e7b89beec4e9..d6500cc1e872 100644
--- a/contrib/bmake/unit-tests/directive-elif.mk
+++ b/contrib/bmake/unit-tests/directive-elif.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-elif.mk,v 1.7 2020/12/19 19:49:01 rillig Exp $
+# $NetBSD: directive-elif.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .elif directive.
#
@@ -44,28 +44,32 @@
# Misspelling '.elsif' below an .if branch that is taken.
.if 1
# This misspelling is in an active branch and is therefore detected.
+# expect+1: Unknown directive "elsif"
.elsif 0
# The only thing that make detects here is a misspelled directive, make
# doesn't recognize that it was meant to be a conditional directive.
# Therefore the branch continues here, even though the '.elsif' condition
# evaluates to false.
+# expect+1: This branch is taken.
. info This branch is taken.
.endif
# Misspelling '.elsif' below an .if branch that is taken.
.if 1
-# As of 2020-12-19, the misspelling is in an active branch and is therefore
-# detected.
+# The misspelling is in an active branch and is therefore detected.
+# expect+1: Unknown directive "elsif"
.elsif 1
# Since both conditions evaluate to true, this branch is taken no matter
# whether make detects a misspelling or not.
+# expect+1: This branch is taken.
. info This branch is taken.
.endif
# Misspelling '.elsif' in a skipped branch below a branch that was taken.
.if 1
+# expect+1: This branch is taken.
. info This branch is taken.
.elif 0
. info This branch is not taken.
@@ -86,8 +90,11 @@
# Misspelling '.elsif' in an .else branch that is taken.
.if 0
.else
+# expect+1: Unknown directive "elsif"
.elsif 1
+# expect+1: This misspelling is detected.
. info This misspelling is detected.
+# expect+1: This branch is taken because of the .else.
. info This branch is taken because of the .else.
.endif
@@ -106,6 +113,7 @@
.endif
+# expect+1: What happens on misspelling in a skipped branch?
.info What happens on misspelling in a skipped branch?
.if 0
. info 0-then
@@ -116,26 +124,33 @@
. info XXX: This misspelling is not detected.
. info 2-elsif
.else
+# expect+1: else
. info else
.endif
+# expect+1: What happens on misspelling in a taken branch?
.info What happens on misspelling in a taken branch?
.if 1
+# expect+1: 1-then
. info 1-then
+# expect+1: Unknown directive "elsif"
.elsif 1
+# expect+1: 1-elsif
. info 1-elsif
+# expect+1: Unknown directive "elsif"
.elsif 2
+# expect+1: 2-elsif
. info 2-elsif
.else
. info else
.endif
-# Expect: "if-less elif"
+# expect+1: if-less elif
.elif 0
.if 1
.else
-# Expect: "warning: extra elif"
+# expect+1: warning: extra elif
.elif
.endif
diff --git a/contrib/bmake/unit-tests/directive-elifdef.mk b/contrib/bmake/unit-tests/directive-elifdef.mk
index f960c1513e8e..e835bccc0d40 100644
--- a/contrib/bmake/unit-tests/directive-elifdef.mk
+++ b/contrib/bmake/unit-tests/directive-elifdef.mk
@@ -1,8 +1,21 @@
-# $NetBSD: directive-elifdef.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-elifdef.mk,v 1.4 2022/02/09 21:09:24 rillig Exp $
#
-# Tests for the .elifdef directive.
+# Tests for the .elifdef directive, which is seldom used. Instead of writing
+# '.elifdef VAR', the usual form is the more general '.elif defined(VAR)'.
-# TODO: Implementation
+# At this point, VAR is not defined, so the condition evaluates to false.
+.if 0
+.elifdef VAR
+. error
+.endif
+
+VAR= # defined
+
+# At this point, VAR is defined, so the condition evaluates to true.
+.if 0
+.elifdef VAR
+.else
+. error
+.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/directive-elifndef.mk b/contrib/bmake/unit-tests/directive-elifndef.mk
index 19bb66c11b01..87aaf2fdd9ac 100644
--- a/contrib/bmake/unit-tests/directive-elifndef.mk
+++ b/contrib/bmake/unit-tests/directive-elifndef.mk
@@ -1,8 +1,23 @@
-# $NetBSD: directive-elifndef.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-elifndef.mk,v 1.3 2022/01/22 21:50:41 rillig Exp $
#
-# Tests for the .elifndef directive.
+# Tests for the .elifndef directive, which is an obscure form of writing the
+# more usual '.elif !defined(VAR)'.
-# TODO: Implementation
+# At this point, VAR is not yet defined, and due to the 'n' in 'elifndef' the
+# condition evaluates to true.
+.if 0
+.elifndef VAR && VAR || VAR
+.else
+. error
+.endif
+
+VAR= # defined
+
+# At this point, VAR is defined, and due to the 'n' in 'elifndef' the
+# condition evaluates to false.
+.if 0
+.elifndef VAR && VAR || VAR
+. error
+.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/directive-else.exp b/contrib/bmake/unit-tests/directive-else.exp
index 138e893ffa88..992b60e9308b 100644
--- a/contrib/bmake/unit-tests/directive-else.exp
+++ b/contrib/bmake/unit-tests/directive-else.exp
@@ -1,11 +1,11 @@
-make: "directive-else.mk" line 14: The .else directive does not take arguments.
-make: "directive-else.mk" line 15: ok
-make: "directive-else.mk" line 19: ok
-make: "directive-else.mk" line 21: The .else directive does not take arguments.
-make: "directive-else.mk" line 26: if-less else
-make: "directive-else.mk" line 32: ok
-make: "directive-else.mk" line 33: warning: extra else
-make: "directive-else.mk" line 45: The .else directive does not take arguments.
+make: "directive-else.mk" line 14: The .else directive does not take arguments
+make: "directive-else.mk" line 16: ok
+make: "directive-else.mk" line 21: ok
+make: "directive-else.mk" line 23: The .else directive does not take arguments
+make: "directive-else.mk" line 29: if-less else
+make: "directive-else.mk" line 36: ok
+make: "directive-else.mk" line 38: warning: extra else
+make: "directive-else.mk" line 51: The .else directive does not take arguments
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-else.mk b/contrib/bmake/unit-tests/directive-else.mk
index 794057110ef7..cda671907217 100644
--- a/contrib/bmake/unit-tests/directive-else.mk
+++ b/contrib/bmake/unit-tests/directive-else.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-else.mk,v 1.7 2020/12/14 22:17:11 rillig Exp $
+# $NetBSD: directive-else.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the .else directive.
#
@@ -10,26 +10,31 @@
.if 0
. warning must not be reached
-# The .else directive does not take any arguments.
+# expect+1: The .else directive does not take arguments
.else 123
+# expect+1: ok
. info ok
.endif
.if 1
+# expect+1: ok
. info ok
-# The .else directive does not take any arguments.
+# expect+1: The .else directive does not take arguments
.else 123
. warning must not be reached
.endif
# An .else without a corresponding .if is an error.
+# expect+1: if-less else
.else
# Accidental extra .else directives are detected too.
.if 0
. warning must not be reached
.else
+# expect+1: ok
. info ok
+# expect+1: warning: extra else
.else
. info After an extra .else, everything is skipped.
.endif
@@ -40,8 +45,9 @@
.else # comment
.endif
-# A variable expression does count as an argument, even if it is empty.
+# An expression does count as an argument, even if it is empty.
.if 0
+# expect+1: The .else directive does not take arguments
.else ${:U}
.endif
diff --git a/contrib/bmake/unit-tests/directive-endfor.exp b/contrib/bmake/unit-tests/directive-endfor.exp
index 7e243a8f67e6..8b77c0b31307 100644
--- a/contrib/bmake/unit-tests/directive-endfor.exp
+++ b/contrib/bmake/unit-tests/directive-endfor.exp
@@ -1,4 +1,4 @@
-make: "directive-endfor.mk" line 9: for-less endfor
+make: "directive-endfor.mk" line 10: for-less endfor
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-endfor.mk b/contrib/bmake/unit-tests/directive-endfor.mk
index b0c37f388504..93119156fb89 100644
--- a/contrib/bmake/unit-tests/directive-endfor.mk
+++ b/contrib/bmake/unit-tests/directive-endfor.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-endfor.mk,v 1.1 2020/12/30 14:50:08 rillig Exp $
+# $NetBSD: directive-endfor.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $
#
# Test for the directive .endfor, which ends a .for loop.
#
@@ -6,4 +6,5 @@
# directive-for.mk
# An .endfor without a corresponding .for is a parse error.
+# expect+1: for-less endfor
.endfor
diff --git a/contrib/bmake/unit-tests/directive-endif.exp b/contrib/bmake/unit-tests/directive-endif.exp
index 286d85244eae..c88cc97c44c5 100644
--- a/contrib/bmake/unit-tests/directive-endif.exp
+++ b/contrib/bmake/unit-tests/directive-endif.exp
@@ -1,8 +1,8 @@
-make: "directive-endif.mk" line 18: The .endif directive does not take arguments.
-make: "directive-endif.mk" line 23: The .endif directive does not take arguments.
-make: "directive-endif.mk" line 33: The .endif directive does not take arguments.
-make: "directive-endif.mk" line 39: The .endif directive does not take arguments.
-make: "directive-endif.mk" line 45: Unknown directive "endifx"
+make: "directive-endif.mk" line 16: The .endif directive does not take arguments
+make: "directive-endif.mk" line 21: The .endif directive does not take arguments
+make: "directive-endif.mk" line 32: The .endif directive does not take arguments
+make: "directive-endif.mk" line 39: The .endif directive does not take arguments
+make: "directive-endif.mk" line 44: Unknown directive "endifx"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-endif.mk b/contrib/bmake/unit-tests/directive-endif.mk
index 10dd6ce22ce8..5e01382af5f2 100644
--- a/contrib/bmake/unit-tests/directive-endif.mk
+++ b/contrib/bmake/unit-tests/directive-endif.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-endif.mk,v 1.5 2020/12/14 21:56:17 rillig Exp $
+# $NetBSD: directive-endif.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .endif directive.
#
@@ -8,18 +8,16 @@
# See also:
# Cond_EvalLine
-# TODO: Implementation
-
.MAKEFLAGS: -dL
-# Error: .endif does not take arguments
.if 0
-# Since 2020-12-15, complain about the extra text after the 'endif'.
+# Since 2020-12-15:
+# expect+1: The .endif directive does not take arguments
.endif 0
-# Error: .endif does not take arguments
.if 1
-# Since 2020-12-15, complain about the extra text after the 'endif'.
+# Since 2020-12-15:
+# expect+1: The .endif directive does not take arguments
.endif 1
# Comments are allowed after an '.endif'.
@@ -29,21 +27,19 @@
# Only whitespace and comments are allowed after an '.endif', but nothing
# else.
.if 1
-# Since 2020-12-15, complain about the extra text after the 'endif'.
+# Since 2020-12-15:
+# expect+1: The .endif directive does not take arguments
.endif0
# Only whitespace and comments are allowed after an '.endif', but nothing
# else.
.if 1
-# Since 2020-12-15, complain about the extra text after the 'endif'.
+# Since 2020-12-15:
+# expect+1: The .endif directive does not take arguments
.endif/
-# After an '.endif', no other letter must occur. This 'endifx' is not
-# parsed as an 'endif', therefore another '.endif' must follow to balance
-# the directives.
+# After an '.endif', no other letter must occur.
.if 1
+# expect+1: Unknown directive "endifx"
.endifx
-.endif # to close the preceding '.if'
-
-all:
- @:;
+.endif # to close the preceding '.if'
diff --git a/contrib/bmake/unit-tests/directive-error.exp b/contrib/bmake/unit-tests/directive-error.exp
index bad12326a514..8ce33160e67f 100644
--- a/contrib/bmake/unit-tests/directive-error.exp
+++ b/contrib/bmake/unit-tests/directive-error.exp
@@ -1,4 +1,4 @@
-make: "directive-error.mk" line 13: message
+make: "directive-error.mk" line 14: message
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-error.mk b/contrib/bmake/unit-tests/directive-error.mk
index 135db2159dd2..f35a9da3a018 100644
--- a/contrib/bmake/unit-tests/directive-error.mk
+++ b/contrib/bmake/unit-tests/directive-error.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-error.mk,v 1.5 2021/01/27 00:02:38 rillig Exp $
+# $NetBSD: directive-error.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .error directive, which prints an error message and exits
# immediately, unlike other "fatal" parse errors, which continue to parse
@@ -10,4 +10,5 @@
# Before parse.c 1.532 from 2021-01-27, the ".error" issued an irrelevant
# message saying "parsing warnings being treated as errors".
.MAKEFLAGS: -W
+# expect+1: message
.error message
diff --git a/contrib/bmake/unit-tests/directive-export-gmake.exp b/contrib/bmake/unit-tests/directive-export-gmake.exp
index 39a9383953dd..c37d3b2d8591 100644
--- a/contrib/bmake/unit-tests/directive-export-gmake.exp
+++ b/contrib/bmake/unit-tests/directive-export-gmake.exp
@@ -1 +1,6 @@
-exit status 0
+make: "directive-export-gmake.mk" line 71: Invalid line 'export VAR=${:U1}', expanded to 'export VAR=1'
+make: "directive-export-gmake.mk" line 85: 16:00:00
+make: "directive-export-gmake.mk" line 92: Variable/Value missing from "export"
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-export-gmake.mk b/contrib/bmake/unit-tests/directive-export-gmake.mk
index d94cd9debf64..de79470bf305 100644
--- a/contrib/bmake/unit-tests/directive-export-gmake.mk
+++ b/contrib/bmake/unit-tests/directive-export-gmake.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export-gmake.mk,v 1.3 2020/11/17 20:16:44 rillig Exp $
+# $NetBSD: directive-export-gmake.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $
#
# Tests for the export directive (without leading dot), as in GNU make.
@@ -60,5 +60,47 @@ export VAR=an ${UNDEF} variable
. error
.endif
-all:
- @:;
+
+# The body of the .for loop expands to 'export VAR=${:U1}', and the 'export'
+# directive is only recognized if the line does not contain a ':', to allow
+# 'export' to be a regular target.
+.for value in 1
+# XXX: The ':' in this line is inside an expression and should thus not be
+# interpreted as a dependency operator.
+# expect+1: Invalid line 'export VAR=${:U1}', expanded to 'export VAR=1'
+export VAR=${value}
+.endfor
+
+
+# The 'export' directive expands expressions, but the expressions must not
+# contain a ':', due to the overly strict parser. The indirect expressions
+# may contain a ':', though.
+#
+# As a side effect, this test demonstrates that the 'export' directive exports
+# the environment variable immediately, other than the '.export' directive,
+# which defers that action if the variable value contains a '$'.
+INDIRECT_TZ= ${:UAmerica/Los_Angeles}
+export TZ=${INDIRECT_TZ}
+# expect+1: 16:00:00
+.info ${%T:L:localtime=86400}
+
+
+# The '=' must be present in the unexpanded line, it cannot be generated by
+# an expression.
+EQ= =
+# expect+1: Variable/Value missing from "export"
+export EQ_VAR${EQ}eq-value
+.if ${:!env!:MEQ_VAR=*}
+. error
+.endif
+
+
+# The variable name must be given directly, it is not expanded. The name of
+# the exported variable thus starts with a '$', and that name may be filtered
+# out by the platform.
+INDIRECT_NAME= I_NAME
+INDIRECT_VALUE= indirect value
+export ${INDIRECT_NAME}=${INDIRECT_VALUE}
+.if ${:!env!:MI_NAME=*}
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/directive-export-impl.exp b/contrib/bmake/unit-tests/directive-export-impl.exp
index 740daa605129..fada441f5e92 100644
--- a/contrib/bmake/unit-tests/directive-export-impl.exp
+++ b/contrib/bmake/unit-tests/directive-export-impl.exp
@@ -1,19 +1,20 @@
-ParseReadLine (21): 'UT_VAR= <${REF}>'
+Parsing line 21: UT_VAR= <${REF}>
Global: UT_VAR = <${REF}>
-ParseReadLine (28): '.export UT_VAR'
+Parsing line 28: .export UT_VAR
Global: .MAKE.EXPORTED = UT_VAR
-ParseReadLine (32): ': ${UT_VAR:N*}'
+Parsing line 32: : ${UT_VAR:N*}
Var_Parse: ${UT_VAR:N*} (eval-defined)
Var_Parse: ${REF}> (eval-defined)
Evaluating modifier ${UT_VAR:N...} on value "<>"
Pattern for ':N' is "*"
-ModifyWords: split "<>" into 1 words
+ModifyWords: split "<>" into 1 word
Result of ${UT_VAR:N*} is ""
ParseDependency(: )
CondParser_Eval: ${:!echo "\$UT_VAR"!} != "<>"
Var_Parse: ${:!echo "\$UT_VAR"!} != "<>" (eval-defined)
Evaluating modifier ${:!...} on value "" (eval-defined, undefined)
Modifier part: "echo "$UT_VAR""
+Capturing the output of command "echo "$UT_VAR""
Var_Parse: ${.MAKE.EXPORTED:O:u} (eval)
Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_VAR"
Result of ${.MAKE.EXPORTED:O} is "UT_VAR"
@@ -22,21 +23,22 @@ Result of ${.MAKE.EXPORTED:u} is "UT_VAR"
Var_Parse: ${UT_VAR} (eval)
Var_Parse: ${REF}> (eval)
Result of ${:!echo "\$UT_VAR"!} is "<>" (eval-defined, defined)
-lhs = "<>", rhs = "<>", op = !=
-ParseReadLine (50): ': ${UT_VAR:N*}'
+Comparing "<>" != "<>"
+Parsing line 50: : ${UT_VAR:N*}
Var_Parse: ${UT_VAR:N*} (eval-defined)
Var_Parse: ${REF}> (eval-defined)
Evaluating modifier ${UT_VAR:N...} on value "<>"
Pattern for ':N' is "*"
-ModifyWords: split "<>" into 1 words
+ModifyWords: split "<>" into 1 word
Result of ${UT_VAR:N*} is ""
ParseDependency(: )
-ParseReadLine (54): 'REF= defined'
+Parsing line 54: REF= defined
Global: REF = defined
CondParser_Eval: ${:!echo "\$UT_VAR"!} != "<defined>"
Var_Parse: ${:!echo "\$UT_VAR"!} != "<defined>" (eval-defined)
Evaluating modifier ${:!...} on value "" (eval-defined, undefined)
Modifier part: "echo "$UT_VAR""
+Capturing the output of command "echo "$UT_VAR""
Var_Parse: ${.MAKE.EXPORTED:O:u} (eval)
Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_VAR"
Result of ${.MAKE.EXPORTED:O} is "UT_VAR"
@@ -45,11 +47,11 @@ Result of ${.MAKE.EXPORTED:u} is "UT_VAR"
Var_Parse: ${UT_VAR} (eval)
Var_Parse: ${REF}> (eval)
Result of ${:!echo "\$UT_VAR"!} is "<defined>" (eval-defined, defined)
-lhs = "<defined>", rhs = "<defined>", op = !=
-ParseReadLine (62): 'all:'
+Comparing "<defined>" != "<defined>"
+Parsing line 62: all:
ParseDependency(all:)
Global: .ALLTARGETS = all
-ParseReadLine (63): '.MAKEFLAGS: -d0'
+Parsing line 63: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d cpv -d
Global: .MAKEFLAGS = -r -k -d cpv -d 0
diff --git a/contrib/bmake/unit-tests/directive-export.exp b/contrib/bmake/unit-tests/directive-export.exp
index 39a9383953dd..774a814570e3 100644
--- a/contrib/bmake/unit-tests/directive-export.exp
+++ b/contrib/bmake/unit-tests/directive-export.exp
@@ -1 +1,4 @@
+make: "directive-export.mk" line 56: 00:00:00
+make: "directive-export.mk" line 61: 00:00:00
+make: "directive-export.mk" line 64: 16:00:00
exit status 0
diff --git a/contrib/bmake/unit-tests/directive-export.mk b/contrib/bmake/unit-tests/directive-export.mk
index 942d4b371bbd..08109814bcfd 100644
--- a/contrib/bmake/unit-tests/directive-export.mk
+++ b/contrib/bmake/unit-tests/directive-export.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export.mk,v 1.8 2021/02/16 19:01:18 rillig Exp $
+# $NetBSD: directive-export.mk,v 1.10 2023/11/19 09:45:19 rillig Exp $
#
# Tests for the .export directive.
#
@@ -35,10 +35,33 @@ VAR= value $$ ${INDIRECT}
.export ${:U}
-# Trigger the "This isn't going to end well" in ExportVarEnv.
+# Before a child process is started, whether for the '!=' assignment operator
+# or for the ':sh' modifier, all variables that were marked for being exported
+# are expanded and then exported. If expanding such a variable requires
+# running a child command, the marked-as-exported variables would need to be
+# exported first, ending in an endless loop. To avoid this endless loop,
+# don't export the variables while preparing a child process, see
+# ExportVarEnv.
EMPTY_SHELL= ${:sh}
.export EMPTY_SHELL # only marked for export at this point
_!= :;: # Force the variable to be actually exported.
+# If the '.export' directive exports a variable whose value contains a '$',
+# the actual export action is deferred until a subprocess is started, assuming
+# that only subprocesses access the environment variables. The ':localtime'
+# modifier depends on the 'TZ' environment variable, without any subprocess.
+export TZ=${UTC}
+# expect+1: 00:00:00
+.info ${%T:L:localtime=86400}
+INDIRECT_TZ= ${:UAmerica/Los_Angeles}
+TZ= ${INDIRECT_TZ}
+.export TZ
+# expect+1: 00:00:00
+.info ${%T:L:localtime=86400}
+_!= echo 'force exporting the environment variables'
+# expect+1: 16:00:00
+.info ${%T:L:localtime=86400}
+
+
all:
diff --git a/contrib/bmake/unit-tests/directive-for-break.exp b/contrib/bmake/unit-tests/directive-for-break.exp
new file mode 100644
index 000000000000..64941448141c
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-break.exp
@@ -0,0 +1,5 @@
+make: "directive-for-break.mk" line 45: break outside of for loop
+make: "directive-for-break.mk" line 65: The .break directive does not take arguments
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-break.mk b/contrib/bmake/unit-tests/directive-for-break.mk
new file mode 100644
index 000000000000..d9290d38c215
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-break.mk
@@ -0,0 +1,66 @@
+# $NetBSD: directive-for-break.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
+#
+# Tests for .break in .for loops, which immediately terminates processing of
+# the surrounding .for loop.
+
+
+# .break terminates the loop early.
+# This is usually done within a conditional.
+.for i in 1 2 3 4 5 6 7 8
+. if $i == 3
+I= $i
+. break
+I= unreached
+. endif
+.endfor
+.if $I != "3"
+. error
+.endif
+
+
+# The .break only breaks out of the immediately surrounding .for loop, any
+# other .for loops are continued normally.
+.for outer in o1 o2 o3
+. for inner in i1 i2 i3
+. if ${outer} == o2 && ${inner} == i2
+. break
+. endif
+COMBINED+= ${outer}-${inner}
+. endfor
+.endfor
+# Only o2-i2 and o2-i3 are missing.
+.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3"
+. error
+.endif
+
+
+# A .break outside the context of a .for loop is an error.
+.if $I == 0
+# No parse error, even though the .break occurs outside a .for loop, since
+# lines from inactive branches are only parsed as far as necessary to see
+# whether they belong to an .if/.elif/.else/.endif chain.
+. break
+.else
+# expect+1: break outside of for loop
+. break
+.endif
+
+
+# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23,
+# the following paragraph generated the wrong error message '4294967294 open
+# conditionals'.
+.if 1
+. if 2
+. for var in value
+. if 3
+. break
+. endif
+. endfor
+. endif
+.endif
+
+
+.for i in 1
+# expect+1: The .break directive does not take arguments
+. break 1
+.endfor
diff --git a/contrib/bmake/unit-tests/directive-for-empty.exp b/contrib/bmake/unit-tests/directive-for-empty.exp
new file mode 100644
index 000000000000..5cc3ac846b36
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-empty.exp
@@ -0,0 +1,27 @@
+make: "directive-for-empty.mk" line 22: 2
+make: "directive-for-empty.mk" line 38: Missing argument for ".error"
+make: "directive-for-empty.mk" line 38: Missing argument for ".error"
+make: "directive-for-empty.mk" line 38: Missing argument for ".error"
+For: end for 1
+For: loop body with i = value:
+# The identifier 'empty' can only be used in conditions such as .if, .ifdef or
+# .elif. In other lines the string 'empty(' must be preserved.
+CPPFLAGS+= -Dmessage="empty(i)"
+# There may be whitespace between 'empty' and '('.
+.if ! empty (i)
+. error
+.endif
+# Even in conditions, the string 'empty(' is not always a function call, it
+# can occur in a string literal as well.
+.if "empty\(i)" != "empty(i)"
+. error
+.endif
+# In comments like 'empty(i)', the text must be preserved as well.
+#
+# Conditions, including function calls to 'empty', can not only occur in
+# condition directives, they can also occur in the modifier ':?', see
+# varmod-ifelse.mk.
+CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}"
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-empty.mk b/contrib/bmake/unit-tests/directive-for-empty.mk
new file mode 100644
index 000000000000..1c4cb0f1ad27
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-empty.mk
@@ -0,0 +1,124 @@
+# $NetBSD: directive-for-empty.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $
+#
+# Tests for .for loops containing conditions of the form 'empty(var:...)'.
+#
+# When a .for loop is expanded, expressions in the body of the loop
+# are replaced with expressions containing the variable values. This
+# replacement is a bit naive but covers most of the practical cases. The one
+# popular exception is the condition 'empty(var:Modifiers)', which does not
+# look like an expression and is thus not replaced.
+#
+# See also:
+# https://gnats.netbsd.org/43821
+
+
+# In the body of the .for loop, the expression '${i:M*2*}' is replaced with
+# '${:U11:M*2*}', '${:U12:M*2*}', '${:U13:M*2*}', one after another. This
+# replacement creates the impression that .for variables were real variables,
+# when in fact they aren't.
+.for i in 11 12 13
+. if ${i:M*2*}
+# expect+1: 2
+.info 2
+. endif
+.endfor
+
+
+# In conditions, the function call to 'empty' does not look like an
+# expression, therefore it is not replaced. Since there is no global variable
+# named 'i', this expression makes for a leaky abstraction. If the .for
+# variables were real variables, calling 'empty' would work on them as well.
+.for i in 11 12 13
+# Asking for an empty iteration variable does not make sense as the .for loop
+# splits the iteration items into words, and such a word cannot be empty.
+. if empty(i)
+# expect+3: Missing argument for ".error"
+# expect+2: Missing argument for ".error"
+# expect+1: Missing argument for ".error"
+. error # due to the leaky abstraction
+. endif
+# The typical way of using 'empty' with variables from .for loops is pattern
+# matching using the modifiers ':M' or ':N'.
+. if !empty(i:M*2*)
+. if ${i} != "12"
+. error
+. endif
+. endif
+.endfor
+
+
+# The idea of replacing every occurrences of 'empty(i' in the body of a .for
+# loop would be naive and require many special cases, as there are many cases
+# that need to be considered when deciding whether the token 'empty' is a
+# function call or not, as demonstrated by the following examples. For
+# expressions like '${i:Modifiers}', this is simpler as a single
+# dollar almost always starts an expression. For counterexamples and
+# edge cases, see directive-for-escape.mk. Adding another such tricky detail
+# is out of the question.
+.MAKEFLAGS: -df
+.for i in value
+# The identifier 'empty' can only be used in conditions such as .if, .ifdef or
+# .elif. In other lines the string 'empty(' must be preserved.
+CPPFLAGS+= -Dmessage="empty(i)"
+# There may be whitespace between 'empty' and '('.
+.if ! empty (i)
+. error
+.endif
+# Even in conditions, the string 'empty(' is not always a function call, it
+# can occur in a string literal as well.
+.if "empty\(i)" != "empty(i)"
+. error
+.endif
+# In comments like 'empty(i)', the text must be preserved as well.
+#
+# Conditions, including function calls to 'empty', can not only occur in
+# condition directives, they can also occur in the modifier ':?', see
+# varmod-ifelse.mk.
+CPPFLAGS+= -Dmacro="${empty(i):?empty:not-empty}"
+.endfor
+.MAKEFLAGS: -d0
+
+
+# An idea to work around the above problems is to collect the variables from
+# the .for loops in a separate scope. To match the current behavior, there
+# has to be one scope per included file. There may be .for loops using the
+# same variable name in files that include each other:
+#
+# outer.mk: .for i in outer
+# . info $i # outer
+# . include "inner.mk"
+# inner.mk: . info $i # (undefined)
+# . for i in inner
+# . info $i # inner
+# . endfor
+# . info $i # (undefined)
+# outer.mk: . info $i # outer
+# .endfor
+#
+# This might be regarded another leaky abstraction, but it is in fact useful
+# that variables from .for loops can only affect expressions in the current
+# file. If variables from .for loops were implemented as global variables,
+# they might interact between files.
+#
+# To emulate this exact behavior for the function 'empty', each file in the
+# stack of included files needs its own scope that is independent from the
+# other files.
+#
+# Another tricky detail are nested .for loops in a single file that use the
+# same variable name. These are generally avoided by developers, as they
+# would be difficult to understand for humans as well. Technically, they are
+# possible though. Assuming there are two nested .for loops, both using the
+# variable 'i'. When the inner .for loop ends, the inner 'i' needs to be
+# removed from the scope, which would need to make the outer 'i' visible
+# again. This would suggest to use one variable scope per .for loop.
+#
+# Using a separate scope has the benefit that Var_Parse already allows for
+# a custom scope to be passed as parameter. This would have another side
+# effect though. There are several modifiers that actually modify variables,
+# and these modifications happen in the scope that is passed to Var_Parse.
+# This would mean that the combination of a .for variable and the modifiers
+# '::=', '::+=', '::?=', '::!=' and ':_' would lead to different behavior than
+# before.
+
+# TODO: Add code that demonstrates the current interaction between variables
+# from .for loops and the modifiers mentioned above.
diff --git a/contrib/bmake/unit-tests/directive-for-errors.exp b/contrib/bmake/unit-tests/directive-for-errors.exp
index da5eee473ec2..115a6af5b069 100644
--- a/contrib/bmake/unit-tests/directive-for-errors.exp
+++ b/contrib/bmake/unit-tests/directive-for-errors.exp
@@ -1,22 +1,17 @@
-make: "directive-for-errors.mk" line 7: Unknown directive "fori"
-make: "directive-for-errors.mk" line 8: warning:
-make: "directive-for-errors.mk" line 9: for-less endfor
-make: "directive-for-errors.mk" line 19: Unknown directive "for"
-make: "directive-for-errors.mk" line 20: warning:
-make: "directive-for-errors.mk" line 21: for-less endfor
-make: "directive-for-errors.mk" line 37: Dollar $ 1 1 and backslash 2 2 2.
-make: "directive-for-errors.mk" line 37: Dollar $ 3 3 and backslash 4 4 4.
-make: "directive-for-errors.mk" line 43: no iteration variables in for
-make: "directive-for-errors.mk" line 47: warning: Should not be reached.
-make: "directive-for-errors.mk" line 48: for-less endfor
-make: "directive-for-errors.mk" line 53: Wrong number of words (5) in .for substitution list with 3 variables
-make: "directive-for-errors.mk" line 64: missing `in' in for
-make: "directive-for-errors.mk" line 66: warning: Should not be reached.
-make: "directive-for-errors.mk" line 67: for-less endfor
-make: "directive-for-errors.mk" line 73: Unknown modifier "Z"
-make: "directive-for-errors.mk" line 74: warning: Should not be reached.
-make: "directive-for-errors.mk" line 74: warning: Should not be reached.
-make: "directive-for-errors.mk" line 74: warning: Should not be reached.
+make: "directive-for-errors.mk" line 9: Unknown directive "fori"
+make: "directive-for-errors.mk" line 10: warning: <>
+make: "directive-for-errors.mk" line 11: for-less endfor
+make: "directive-for-errors.mk" line 25: Unknown directive "for"
+make: "directive-for-errors.mk" line 26: warning: <>
+make: "directive-for-errors.mk" line 27: for-less endfor
+make: "directive-for-errors.mk" line 44: invalid character '$' in .for loop variable name
+make: "directive-for-errors.mk" line 52: no iteration variables in for
+make: "directive-for-errors.mk" line 64: Wrong number of words (5) in .for substitution list with 3 variables
+make: "directive-for-errors.mk" line 78: missing `in' in for
+make: "directive-for-errors.mk" line 89: Unknown modifier "Z"
+make: "directive-for-errors.mk" line 90: warning: Should not be reached.
+make: "directive-for-errors.mk" line 90: warning: Should not be reached.
+make: "directive-for-errors.mk" line 90: warning: Should not be reached.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-errors.mk b/contrib/bmake/unit-tests/directive-for-errors.mk
index 602ecbf32e4e..94362847cdfd 100644
--- a/contrib/bmake/unit-tests/directive-for-errors.mk
+++ b/contrib/bmake/unit-tests/directive-for-errors.mk
@@ -1,45 +1,54 @@
-# $NetBSD: directive-for-errors.mk,v 1.3 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: directive-for-errors.mk,v 1.9 2023/12/19 19:33:40 rillig Exp $
#
# Tests for error handling in .for loops.
+
# A .for directive must be followed by whitespace, everything else results
# in a parse error.
+# expect+1: Unknown directive "fori"
.fori in 1 2 3
-. warning ${i}
+. warning <${i}>
.endfor
+# expect-2: warning: <>
+# expect-2: for-less endfor
+
# A slash is not whitespace, therefore this is not parsed as a .for loop.
#
# XXX: The error message is misleading though. As of 2020-12-31, it says
-# "Unknown directive "for"", but that directive is actually known. This is
+# 'Unknown directive "for"', but that directive is actually known. This is
# because ForEval does not detect the .for loop as such, so parsing
# continues in ParseLine > ParseDependencyLine > ParseDependency >
# ParseDependencyTargets > ParseErrorNoDependency, and there the directive
# name is parsed a bit differently.
+# expect+1: Unknown directive "for"
.for/i in 1 2 3
-. warning ${i}
+. warning <${i}>
.endfor
+# expect-2: warning: <>
+# expect-2: for-less endfor
-# As of 2020-12-31, the variable name can be an arbitrary word, it just needs
-# to be separated by whitespace. Even '$' and '\' are valid variable names,
-# which is not useful in practice.
-#
-# The '$$' is not replaced with the values '1' or '3' from the .for loop,
-# instead it is kept as-is, and when the .info directive expands its argument,
-# each '$$' gets replaced with a single '$'. The "long variable expression"
-# ${$} gets replaced though, even though this would be a parse error everywhere
-# outside a .for loop.
+
+# Before for.c 1.173 from 2023-05-08, the variable name could be an arbitrary
+# word, it only needed to be separated by whitespace. Even '$' and '\' were
+# valid variable names, which was not useful in practice.
#
-# The '\' on the other hand is treated as a normal variable name.
+# The '$$' was not replaced with the values '1' or '3' from the .for loop,
+# instead it was kept as-is, and when the .info directive expanded its
+# argument, each '$$' got replaced with a single '$'. The "long
+# expression" ${$} got replaced though, even though this would be a parse
+# error everywhere outside a .for loop.
${:U\$}= dollar # see whether the "variable" '$' is local
${:U\\}= backslash # see whether the "variable" '\' is local
+# expect+1: invalid character '$' in .for loop variable name
.for $ \ in 1 2 3 4
. info Dollar $$ ${$} $($) and backslash $\ ${\} $(\).
.endfor
# If there are no variables, there is no point in expanding the .for loop
-# since this would end up in an endless loop, each time consuming 0 of the
-# 3 values.
+# since this would end up in an endless loop, consuming 0 of the 3 values in
+# each iteration.
+# expect+1: no iteration variables in for
.for in 1 2 3
# XXX: This should not be reached. It should be skipped, as already done
# when the number of values is not a multiple of the number of variables,
@@ -47,29 +56,39 @@ ${:U\\}= backslash # see whether the "variable" '\' is local
. warning Should not be reached.
.endfor
+
# There are 3 variables and 5 values. These 5 values cannot be split evenly
# among the variables, therefore the loop is not expanded at all, it is
-# rather skipped.
+# skipped instead.
+# expect+1: Wrong number of words (5) in .for substitution list with 3 variables
.for a b c in 1 2 3 4 5
. warning Should not be reached.
.endfor
+
# The list of values after the 'in' may be empty, no matter if this emptiness
-# comes from an empty expansion or even from a syntactically empty line.
+# comes from an expanded expression or from a syntactically empty line.
.for i in
. info Would be reached if there were items to loop over.
.endfor
+
# A missing 'in' should parse the .for loop but skip the body.
-.for i : k
+# expect+1: missing `in' in for
+.for i over k
# XXX: As of 2020-12-31, this line is reached once.
. warning Should not be reached.
.endfor
+
# A malformed modifier should be detected and skip the body of the loop.
#
# XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore
# the loop body is expanded as if no error had happened.
+# expect+1: Unknown modifier "Z"
.for i in 1 2 ${:U3:Z} 4
. warning Should not be reached.
.endfor
+# expect-2: warning: Should not be reached.
+# expect-3: warning: Should not be reached.
+# expect-4: warning: Should not be reached.
diff --git a/contrib/bmake/unit-tests/directive-for-escape.exp b/contrib/bmake/unit-tests/directive-for-escape.exp
index 59d4c2324f15..6c84b7780e84 100644
--- a/contrib/bmake/unit-tests/directive-for-escape.exp
+++ b/contrib/bmake/unit-tests/directive-for-escape.exp
@@ -1,57 +1,76 @@
For: end for 1
-For: loop body:
+For: loop body with chars = !"#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~:
. info ${:U!"#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~}
-make: Unclosed variable expression, expecting '}' for modifier "U!"" of variable "" with value "!""
+make: Unclosed expression, expecting '}' for modifier "U!"" of variable "" with value "!""
make: "directive-for-escape.mk" line 19: !"
For: end for 1
-For: loop body:
+For: loop body with chars = !"\\#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~:
. info ${:U!"\\\\#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~}
-make: Unclosed variable expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\"
-make: "directive-for-escape.mk" line 29: !"\\
+make: Unclosed expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\"
+make: "directive-for-escape.mk" line 30: !"\\
For: end for 1
-For: loop body:
+For: loop body with i = $:
. info ${:U\$}
-make: "directive-for-escape.mk" line 41: $
-For: loop body:
+make: "directive-for-escape.mk" line 45: $
+For: loop body with i = ${V}:
. info ${:U${V}}
-make: "directive-for-escape.mk" line 41: value
-For: loop body:
+make: "directive-for-escape.mk" line 45: value
+For: loop body with i = ${V:=-with-modifier}:
. info ${:U${V:=-with-modifier}}
-make: "directive-for-escape.mk" line 41: value-with-modifier
-For: loop body:
+make: "directive-for-escape.mk" line 45: value-with-modifier
+For: loop body with i = $(V):
. info ${:U$(V)}
-make: "directive-for-escape.mk" line 41: value
-For: loop body:
+make: "directive-for-escape.mk" line 45: value
+For: loop body with i = $(V:=-with-modifier):
. info ${:U$(V:=-with-modifier)}
-make: "directive-for-escape.mk" line 41: value-with-modifier
+make: "directive-for-escape.mk" line 45: value-with-modifier
For: end for 1
-For: loop body:
+For: loop body with i = $:
+. info ${:U\$}
+make: "directive-for-escape.mk" line 60: $
+For: loop body with i = ${V}:
+. info ${:U${V}}
+make: "directive-for-escape.mk" line 60: value
+For: loop body with i = ${V:=-with-modifier}:
+. info ${:U${V:=-with-modifier}}
+make: "directive-for-escape.mk" line 60: value-with-modifier
+For: loop body with i = $(V):
+. info ${:U$(V)}
+make: "directive-for-escape.mk" line 60: value
+For: loop body with i = $(V:=-with-modifier):
+. info ${:U$(V:=-with-modifier)}
+make: "directive-for-escape.mk" line 60: value-with-modifier
+For: end for 1
+For: loop body with i = ${UNDEF:U\$\$:
+# ${:U\${UNDEF\:U\\$\\$}
+For: loop body with i = {{}}:
+# ${:U{{\}\}}
+For: loop body with i = end}:
+# ${:Uend\}}
+For: end for 1
+For: loop body with i = ${UNDEF:U\$\$:
. info ${:U\${UNDEF\:U\\$\\$}
-make: "directive-for-escape.mk" line 55: ${UNDEF:U\$
-For: loop body:
+make: "directive-for-escape.mk" line 115: ${UNDEF:U\backslash$
+For: loop body with i = {{}}:
. info ${:U{{\}\}}
-make: "directive-for-escape.mk" line 55: {{}}
-For: loop body:
+make: "directive-for-escape.mk" line 115: {{}}
+For: loop body with i = end}:
. info ${:Uend\}}
-make: "directive-for-escape.mk" line 55: end}
+make: "directive-for-escape.mk" line 115: end}
For: end for 1
-For: loop body:
+For: loop body with i = begin<${UNDEF:Ufallback:N{{{}}}}>end:
. info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end}
-make: "directive-for-escape.mk" line 67: begin<fallback>end
+make: "directive-for-escape.mk" line 136: begin<fallback>end
For: end for 1
-For: loop body:
+For: loop body with i = $:
. info ${:U\$}
-make: "directive-for-escape.mk" line 75: $
+make: "directive-for-escape.mk" line 145: $
+make: "directive-for-escape.mk" line 154: invalid character ':' in .for loop variable name
For: end for 1
-For: loop body:
-. info ${NUMBERS} ${:Ureplaced}
-make: "directive-for-escape.mk" line 83: one two three replaced
+make: "directive-for-escape.mk" line 164: invalid character '}' in .for loop variable name
For: end for 1
-For: loop body:
-. info ${:Ureplaced}
-make: "directive-for-escape.mk" line 93: replaced
For: end for 1
-For: loop body:
+For: loop body with i = inner:
. info . $$i: ${:Uinner}
. info . $${i}: ${:Uinner}
. info . $${i:M*}: ${:Uinner:M*}
@@ -62,14 +81,89 @@ For: loop body:
. info . $${i2}: ${i2}
. info . $${i,}: ${i,}
. info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
-make: "directive-for-escape.mk" line 101: . $i: inner
-make: "directive-for-escape.mk" line 102: . ${i}: inner
-make: "directive-for-escape.mk" line 103: . ${i:M*}: inner
-make: "directive-for-escape.mk" line 104: . $(i): inner
-make: "directive-for-escape.mk" line 105: . $(i:M*): inner
-make: "directive-for-escape.mk" line 106: . ${i${:U}}: outer
-make: "directive-for-escape.mk" line 107: . ${i\}}: inner}
-make: "directive-for-escape.mk" line 108: . ${i2}: two
-make: "directive-for-escape.mk" line 109: . ${i,}: comma
-make: "directive-for-escape.mk" line 110: . adjacent: innerinnerinnerinner
-exit status 0
+make: "directive-for-escape.mk" line 173: . $i: inner
+make: "directive-for-escape.mk" line 174: . ${i}: inner
+make: "directive-for-escape.mk" line 175: . ${i:M*}: inner
+make: "directive-for-escape.mk" line 176: . $(i): inner
+make: "directive-for-escape.mk" line 177: . $(i:M*): inner
+make: "directive-for-escape.mk" line 178: . ${i${:U}}: outer
+make: "directive-for-escape.mk" line 179: . ${i\}}: inner}
+make: "directive-for-escape.mk" line 180: . ${i2}: two
+make: "directive-for-escape.mk" line 181: . ${i,}: comma
+make: "directive-for-escape.mk" line 182: . adjacent: innerinnerinnerinner
+make: "directive-for-escape.mk" line 201: invalid character '$' in .for loop variable name
+For: end for 1
+make: "directive-for-escape.mk" line 213: eight and no cents.
+For: end for 1
+make: "directive-for-escape.mk" line 226: newline in .for value
+make: "directive-for-escape.mk" line 226: newline in .for value
+For: loop body with i = "
+":
+. info short: ${:U" "}
+. info long: ${:U" "}
+make: "directive-for-escape.mk" line 227: short: " "
+make: "directive-for-escape.mk" line 228: long: " "
+For: end for 1
+For: loop body with i = "
+":
+For: end for 1
+Parse_PushInput: .for loop in directive-for-escape.mk, line 244
+make: "directive-for-escape.mk" line 244: newline in .for value
+ in .for loop from directive-for-escape.mk:244 with i = "
+"
+For: loop body with i = "
+":
+: ${:U" "}
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk'
+Parsing line 245: : ${:U" "}
+ParseDependency(: " ")
+ParseEOF: returning to file directive-for-escape.mk, line 247
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk'
+Parsing line 247: .MAKEFLAGS: -d0
+ParseDependency(.MAKEFLAGS: -d0)
+For: end for 1
+For: loop body with i = #:
+# ${:U#}
+For: loop body with i = \\#:
+# ${:U\\\\#}
+For: end for 1
+For: loop body with i = $:
+# ${:U\$}
+For: loop body with i = $i:
+# ${:U$i}
+For: loop body with i = $(i):
+# ${:U$(i)}
+For: loop body with i = ${i}:
+# ${:U${i}}
+For: loop body with i = $$:
+# ${:U$$}
+For: loop body with i = $$$$:
+# ${:U$$$$}
+For: loop body with i = ${:U\$\$}:
+# ${:U${:U\$\$}}
+For: end for 1
+For: loop body with i = ${.TARGET}:
+# ${:U${.TARGET}}
+For: loop body with i = ${.TARGET}:
+# ${:U${.TARGET}}
+For: loop body with i = $${.TARGET}:
+# ${:U$${.TARGET\}}
+For: loop body with i = $${.TARGET}:
+# ${:U$${.TARGET\}}
+For: end for 1
+For: loop body with i = (((:
+# ${:U(((}
+For: loop body with i = {{{:
+# ${:U{{{}
+For: loop body with i = ))):
+# ${:U)))}
+For: loop body with i = }}}:
+# ${:U\}\}\}}
+For: end for 1
+For: loop body with , = 1:
+# $$i $i
+# VAR= $$i $i ${a:S,from${:U1}to,}
+VAR= $$i $i ${a:S,from${:U1}to,}
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-escape.mk b/contrib/bmake/unit-tests/directive-for-escape.mk
index babc4b8c6e88..16df5b1db4e3 100644
--- a/contrib/bmake/unit-tests/directive-for-escape.mk
+++ b/contrib/bmake/unit-tests/directive-for-escape.mk
@@ -1,9 +1,8 @@
-# $NetBSD: directive-for-escape.mk,v 1.7 2021/02/15 07:58:19 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.23 2023/11/19 22:32:44 rillig Exp $
#
# Test escaping of special characters in the iteration values of a .for loop.
# These values get expanded later using the :U variable modifier, and this
-# escaping and unescaping must pass all characters and strings effectively
-# unmodified.
+# escaping and unescaping must pass all characters and strings unmodified.
.MAKEFLAGS: -df
@@ -12,12 +11,14 @@
# This could be considered a bug.
ASCII= !"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~
+
# XXX: As of 2020-12-31, the '#' is not preserved in the expanded body of
-# the loop since it would not need only the escaping for the :U variable
-# modifier but also the escaping for the line-end comment.
+# the loop. Not only would it need the escaping for the variable modifier
+# ':U' but also the escaping for the line-end comment.
.for chars in ${ASCII}
. info ${chars}
.endfor
+# expect-2: !"
# As of 2020-12-31, using 2 backslashes before be '#' would treat the '#'
# as comment character. Using 3 backslashes doesn't help either since
@@ -28,44 +29,113 @@ ASCII.2020-12-31= !"\\\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~
.for chars in ${ASCII.2020-12-31}
. info ${chars}
.endfor
+# expect-2: !"\\
-# Cover the code in for_var_len.
+# Cover the code in ExprLen.
#
# XXX: It is unexpected that the variable V gets expanded in the loop body.
-# The double '$$' should prevent exactly this. Probably nobody was
-# adventurous enough to use literal dollar signs in the values of a .for
-# loop.
+# The double '$$' should intuitively prevent exactly this. Probably nobody
+# was adventurous enough to use literal dollar signs in the values of a .for
+# loop, allowing this edge case to go unnoticed for years.
+#
+# See for.c, function ExprLen.
V= value
VALUES= $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier)
.for i in ${VALUES}
. info $i
.endfor
+# expect: . info ${:U\$}
+# expect-3: $
+# expect: . info ${:U${V}}
+# expect-5: value
+# expect: . info ${:U${V:=-with-modifier}}
+# expect-7: value-with-modifier
+# expect: . info ${:U$(V)}
+# expect-9: value
+# expect: . info ${:U$(V:=-with-modifier)}
+# expect-11: value-with-modifier
+#
+# Providing the loop items directly has the same effect.
+.for i in $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier)
+. info $i
+.endfor
+# expect: . info ${:U\$}
+# expect-3: $
+# expect: . info ${:U${V}}
+# expect-5: value
+# expect-6: value-with-modifier
+# expect-7: value
+# expect-8: value-with-modifier
-# Try to cover the code for nested '{}' in for_var_len, without success.
+# Try to cover the code for nested '{}' in ExprLen, without success.
#
-# The value of the variable VALUES is not meant to be a variable expression.
+# The value of the variable VALUES is not meant to be an expression.
# Instead, it is meant to represent literal text, the only escaping mechanism
# being that each '$' is written as '$$'.
+VALUES= $${UNDEF:U\$$\$$ {{}} end}
#
# The .for loop splits ${VALUES} into 3 words, at the space characters, since
-# these are not escaped.
-VALUES= $${UNDEF:U\$$\$$ {{}} end}
-# XXX: Where in the code does the '\$\$' get converted into a single '\$'?
+# the '$$' is an ordinary character and the spaces are not escaped.
+# Word 1 is '${UNDEF:U\$\$'
+# Word 2 is '{{}}'
+# Word 3 is 'end}'
+#
+# Each of these words is now inserted in the body of the .for loop.
+.for i in ${VALUES}
+# $i
+.endfor
+#
+# When these words are injected into the body of the .for loop, each inside a
+# '${:U...}' expression, the result is:
+#
+# expect: For: loop body with i = ${UNDEF:U\$\$:
+# expect: # ${:U\${UNDEF\:U\\$\\$}
+# expect: For: loop body with i = {{}}:
+# expect: # ${:U{{\}\}}
+# expect: For: loop body with i = end}:
+# expect: # ${:Uend\}}
+# expect: For: end for 1
+#
+# The first of these expressions is the most interesting one, due to its many
+# special characters. This expression is properly balanced:
+#
+# Text Meaning Explanation
+# \$ $ escaped
+# { { ordinary text
+# UNDEF UNDEF ordinary text
+# \: : escaped
+# U U ordinary text
+# \\ \ escaped
+# $\ (expr) an expression, the variable name is '\'
+# \$ $ escaped
+#
+# To make the expression '$\' visible, define it to an actual word:
+${:U\\}= backslash
.for i in ${VALUES}
. info $i
.endfor
+#
+# expect-3: ${UNDEF:U\backslash$
+# expect-4: {{}}
+# expect-5: end}
+#
+# FIXME: There was no expression '$\' in the original text of the variable
+# 'VALUES', that's a surprise in the parser.
+
-# Second try to cover the code for nested '{}' in for_var_len.
+# Second try to cover the code for nested '{}' in ExprLen.
#
-# XXX: It is wrong that for_var_len requires the braces to be balanced.
+# XXX: It is not the job of ExprLen to parse an expression, it is naive to
+# expect ExprLen to get all the details right in just a few lines of code.
# Each variable modifier has its own inconsistent way of parsing nested
-# variable expressions, braces and parentheses. (Compare ':M', ':S', and
+# expressions, braces and parentheses. (Compare ':M', ':S', and
# ':D' for details.) The only sensible thing to do is therefore to let
# Var_Parse do all the parsing work.
VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end
.for i in ${VALUES}
. info $i
.endfor
+# expect-2: begin<fallback>end
# A single trailing dollar doesn't happen in practice.
# The dollar sign is correctly passed through to the body of the .for loop.
@@ -74,21 +144,23 @@ VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end
.for i in ${:U\$}
. info ${i}
.endfor
+# expect-2: $
-# As of 2020-12-31, the name of the iteration variable can even contain
-# colons, which then affects variable expressions having this exact modifier.
-# This is clearly an unintended side effect of the implementation.
+# Before for.c 1.173 from 2023-05-08, the name of the iteration variable
+# could contain colons, which affected expressions having this exact
+# modifier. This possibility was neither intended nor documented.
NUMBERS= one two three
+# expect+1: invalid character ':' in .for loop variable name
.for NUMBERS:M*e in replaced
. info ${NUMBERS} ${NUMBERS:M*e}
.endfor
-# As of 2020-12-31, the name of the iteration variable can contain braces,
-# which gets even more surprising than colons, since it allows to replace
-# sequences of variable expressions. There is no practical use case for
-# this, though.
+# Before for.c 1.173 from 2023-05-08, the name of the iteration variable
+# could contain braces, which allowed to replace sequences of
+# expressions. This possibility was neither intended nor documented.
BASENAME= one
EXT= .c
+# expect+1: invalid character '}' in .for loop variable name
.for BASENAME}${EXT in replaced
. info ${BASENAME}${EXT}
.endfor
@@ -109,5 +181,113 @@ i,= comma
. info . $${i,}: ${i,}
. info . adjacent: $i${i}${i:M*}$i
.endfor
+# expect-11: . $i: inner
+# expect-11: . ${i}: inner
+# expect-11: . ${i:M*}: inner
+# expect-11: . $(i): inner
+# expect-11: . $(i:M*): inner
+# expect-11: . ${i${:U}}: outer
+# expect-11: . ${i\}}: inner}
+# expect-11: . ${i2}: two
+# expect-11: . ${i,}: comma
+# expect-11: . adjacent: innerinnerinnerinner
+
+# Before for.c 1.173 from 2023-05-08, the variable name could be a single '$'
+# since there was no check on valid variable names. ForLoop_SubstVarShort
+# skipped "stupid" variable names though, but ForLoop_SubstVarLong naively
+# parsed the body of the loop, substituting each '${$}' with an actual
+# '${:Udollar}'.
+# expect+1: invalid character '$' in .for loop variable name
+.for $ in dollar
+. info eight $$$$$$$$ and no cents.
+. info eight ${$}${$}${$}${$} and no cents.
+.endfor
+# Outside a .for loop, '${$}' is interpreted differently. The outer '$' starts
+# an expression. The inner '$' is followed by a '}' and is thus a
+# silent syntax error, the '$' is skipped. The variable name is thus '', and
+# since since there is never a variable named '', the whole expression '${$}'
+# evaluates to an empty string.
+closing-brace= } # guard against an
+${closing-brace}= <closing-brace> # alternative interpretation
+# expect+1: eight and no cents.
+.info eight ${$}${$}${$}${$} and no cents.
-all:
+# What happens if the values from the .for loop contain a literal newline?
+# Before for.c 1.144 from 2021-06-25, the newline was passed verbatim to the
+# body of the .for loop, where it was then interpreted as a literal newline,
+# leading to syntax errors such as "Unclosed variable expression" in the upper
+# line and "Invalid line type" in the lower line.
+#
+# The error message occurs in the line of the .for loop since that's the place
+# where the body of the .for loop is constructed, and at this point the
+# newline character gets replaced with a plain space.
+# expect+2: newline in .for value
+# expect+1: newline in .for value
+.for i in "${.newline}"
+. info short: $i
+. info long: ${i}
+.endfor
+# expect-3: short: " "
+# expect-3: long: " "
+
+# No error since the newline character is not actually used.
+.for i in "${.newline}"
+.endfor
+
+# Between for.c 1.161 from 2022-01-08 and before for.c 1.163 from 2022-01-09,
+# a newline character in a .for loop led to a crash since at the point where
+# the error message including the stack trace is printed, the body of the .for
+# loop is assembled, and at that point, ForLoop.nextItem had already been
+# advanced.
+.MAKEFLAGS: -dp
+# expect+1: newline in .for value
+.for i in "${.newline}"
+: $i
+.endfor
+.MAKEFLAGS: -d0
+
+.MAKEFLAGS: -df
+.for i in \# \\\#
+# $i
+.endfor
+
+.for i in $$ $$i $$(i) $${i} $$$$ $$$$$$$$ $${:U\$$\$$}
+# $i
+.endfor
+
+# The expression '${.TARGET}' must be preserved as it is one of the 7 built-in
+# target-local variables. See for.c 1.45 from 2009-01-14.
+.for i in ${.TARGET} $${.TARGET} $$${.TARGET} $$$${.TARGET}
+# $i
+.endfor
+# expect: # ${:U${.TARGET}}
+# XXX: Why does '$' result in the same text as '$$'?
+# expect: # ${:U${.TARGET}}
+# XXX: Why does the '$$' before the '${.TARGET}' lead to an escaped '}'?
+# expect: # ${:U$${.TARGET\}}
+# XXX: Why does '$' result in the same text as '$$'?
+# XXX: Why does the '$$' before the '${.TARGET}' lead to an escaped '}'?
+# expect: # ${:U$${.TARGET\}}
+
+.for i in ((( {{{ ))) }}}
+# $i
+.endfor
+
+
+# When generating the body of a .for loop, recognizing the expressions is done
+# using simple heuristics. These can go wrong in ambiguous cases like this.
+# The variable name ',' is unusual as it is not a pronounceable name, but the
+# same principle applies for other names as well. In this case, the text '$,'
+# is replaced with the expression '${:U1}', even though the text does not
+# represent an expression.
+.for , in 1
+# $$i $i
+# VAR= $$i $i ${a:S,from$,to,}
+VAR= $$i $i ${a:S,from$,to,}
+.endfor
+# expect: # $$i $i
+# expect: # VAR= $$i $i ${a:S,from${:U1}to,}
+# expect: VAR= $$i $i ${a:S,from${:U1}to,}
+#
+# When the above variable is evaluated, make will complain about the
+# unfinished modifier ':S', as it is missing a comma.
diff --git a/contrib/bmake/unit-tests/directive-for-generating-endif.exp b/contrib/bmake/unit-tests/directive-for-generating-endif.exp
index 9e1301abf96f..ecdeb0962202 100755
--- a/contrib/bmake/unit-tests/directive-for-generating-endif.exp
+++ b/contrib/bmake/unit-tests/directive-for-generating-endif.exp
@@ -1,7 +1,7 @@
-make: "directive-for-generating-endif.mk" line 21: if-less endif
-make: "directive-for-generating-endif.mk" line 21: if-less endif
-make: "directive-for-generating-endif.mk" line 21: if-less endif
-make: "directive-for-generating-endif.mk" line 0: 3 open conditionals
+make: "directive-for-generating-endif.mk" line 24: if-less endif
+make: "directive-for-generating-endif.mk" line 24: if-less endif
+make: "directive-for-generating-endif.mk" line 24: if-less endif
+make: "directive-for-generating-endif.mk" line 30: 3 open conditionals
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-generating-endif.mk b/contrib/bmake/unit-tests/directive-for-generating-endif.mk
index b4d709551003..3079ad3353c2 100755
--- a/contrib/bmake/unit-tests/directive-for-generating-endif.mk
+++ b/contrib/bmake/unit-tests/directive-for-generating-endif.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-generating-endif.mk,v 1.1 2020/08/29 18:50:25 rillig Exp $
+# $NetBSD: directive-for-generating-endif.mk,v 1.2 2023/06/01 20:56:35 rillig Exp $
#
# Test whether a .for loop can be used to generate multiple .endif
# directives to close nested .if directives. Depending on the exact
@@ -18,8 +18,12 @@
. if 2
. if 3
.for i in 3 2 1
+# expect+3: if-less endif
+# expect+2: if-less endif
+# expect+1: if-less endif
.endif
.endfor
all:
@:;
+# expect+1: 3 open conditionals
diff --git a/contrib/bmake/unit-tests/directive-for-if.exp b/contrib/bmake/unit-tests/directive-for-if.exp
new file mode 100644
index 000000000000..f30171f4db87
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-if.exp
@@ -0,0 +1,8 @@
+make: "directive-for-if.mk" line 51: if-less endif
+make: "directive-for-if.mk" line 51: if-less endif
+make: "directive-for-if.mk" line 51: if-less endif
+VAR1
+VAR3
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for-if.mk b/contrib/bmake/unit-tests/directive-for-if.mk
new file mode 100644
index 000000000000..f5a20279cc97
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-for-if.mk
@@ -0,0 +1,89 @@
+# $NetBSD: directive-for-if.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $
+#
+# Test for a .for directive that contains an .if directive.
+#
+# Before for.c 1.39 from 2008-12-21, when expanding the variables of a .for
+# loop, their values were placed verbatim in the expanded body. Since then,
+# each variable value expands to an expression of the form ${:Uvalue}.
+#
+# Before that change, the following adventurous code was possible:
+#
+# .for directive in if ifdef ifndef
+# . ${directive} "1" != "0"
+# . endif
+# .endfor
+#
+# A more practical usage of the .for loop that often led to surprises was the
+# following:
+#
+# .for var in VAR1 VAR2 VAR3
+# . if ${var} != "VAR2"
+# . endif
+# .endfor
+#
+# The .for loop body expanded to this string:
+#
+# . if VAR1 != "VAR2"
+# . endif
+#
+# Since bare words were not allowed at the left-hand side of a condition,
+# make complained about a "Malformed conditional", which was surprising since
+# the code before expanding the .for loop body looked quite well.
+#
+# In cond.c 1.48 from 2008-11-29, just a month before the expansion of .for
+# loops changed from plain textual value to using expressions of the form
+# ${:Uvalue}, this surprising behavior was documented in the code, and a
+# workaround was implemented that allowed bare words when they are followed
+# by either '!' or '=', as part of the operators '!=' or '=='.
+#
+# Since cond.c 1.68 from 2015-05-05, bare words are allowed on the left-hand
+# side of a condition, but that applies only to expression of the form
+# ${${cond} :? then : else}, it does not apply to conditions in ordinary .if
+# directives.
+
+# The following snippet worked in 2005, when the variables from the .for loop
+# expanded to their bare textual value.
+.for directive in if ifdef ifndef
+. ${directive} "1" != "0"
+# expect+3: if-less endif
+# expect+2: if-less endif
+# expect+1: if-less endif
+. endif
+.endfor
+# In 2021, the above code does not generate an error message, even though the
+# code looks clearly malformed. This is due to the '!', which is interpreted
+# as a dependency operator, similar to ':' and '::'. The parser turns this
+# line into a dependency with the 3 targets '.', 'if', '"1"' and the 2 sources
+# '=' and '"0"'. Since that line is not interpreted as an '.if' directive,
+# the error message 'if-less endif' makes sense.
+
+# In 2005, make complained:
+#
+# .if line: Malformed conditional (VAR1 != "VAR2")
+# .endif line: if-less endif
+# .endif line: Need an operator
+#
+# 2008.11.30.22.37.55 does not complain about the left-hand side ${var}.
+.for var in VAR1 VAR2 VAR3
+. if ${var} != "VAR2"
+_!= echo "${var}" 1>&2; echo # In 2005, '.info' was not invented yet.
+. endif
+.endfor
+
+# Before for.c 1.39 from 2008-12-21, a common workaround was to surround the
+# expression from the .for loop with '"'. Such a string literal
+# has been allowed since cond.c 1.23 from 2004-04-13. Between that commit and
+# the one from 2008, the parser would still get confused if the value from the
+# .for loop contained '"', which was effectively a code injection.
+#
+# Surrounding ${var} with quotes disabled the check for typos though. For
+# ordinary variables, referring to an undefined variable on the left-hand side
+# of the comparison resulted in a "Malformed conditional". Since the .for
+# loop was usually close to the .if clause, this was not a problem in
+# practice.
+.for var in VAR1 VAR2 VAR3
+. if "${var}" != "VAR2"
+. endif
+.endfor
+
+all:
diff --git a/contrib/bmake/unit-tests/directive-for-lines.exp b/contrib/bmake/unit-tests/directive-for-lines.exp
index 7aeaaa4a7002..857b4829083b 100644
--- a/contrib/bmake/unit-tests/directive-for-lines.exp
+++ b/contrib/bmake/unit-tests/directive-for-lines.exp
@@ -1,9 +1,9 @@
-make: "directive-for-lines.mk" line 23: expect 23
-make: "directive-for-lines.mk" line 23: expect 23
-make: "directive-for-lines.mk" line 30: expect 30
-make: "directive-for-lines.mk" line 23: expect 23
-make: "directive-for-lines.mk" line 23: expect 23
-make: "directive-for-lines.mk" line 30: expect 30
+make: "directive-for-lines.mk" line 27: expect 23
+make: "directive-for-lines.mk" line 27: expect 23
+make: "directive-for-lines.mk" line 36: expect 30
+make: "directive-for-lines.mk" line 27: expect 23
+make: "directive-for-lines.mk" line 27: expect 23
+make: "directive-for-lines.mk" line 36: expect 30
make: no target to make.
make: stopped in unit-tests
diff --git a/contrib/bmake/unit-tests/directive-for-lines.mk b/contrib/bmake/unit-tests/directive-for-lines.mk
index 96d659426882..cae4e0a38897 100644
--- a/contrib/bmake/unit-tests/directive-for-lines.mk
+++ b/contrib/bmake/unit-tests/directive-for-lines.mk
@@ -1,9 +1,9 @@
-# $NetBSD: directive-for-lines.mk,v 1.3 2020/12/19 12:40:00 rillig Exp $
+# $NetBSD: directive-for-lines.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the line numbers that are reported in .for loops.
#
-# Between 2007-01-01 (git 4d3c468f96e1080e, parse.c 1.127) and 2020-12-19
-# (parse.c 1.494), the line numbers for the .info directives and error
+# Since parse.c 1.127 from 2007-01-01 and before parse.c 1.494 from
+# 2020-12-19, the line numbers for the .info directives and error
# messages inside .for loops had been wrong since ParseGetLine skipped empty
# lines, even when collecting the lines for the .for loop body.
@@ -20,6 +20,10 @@
VAR= \
multi-line
+# expect+4: expect 23
+# expect+3: expect 23
+# expect+2: expect 23
+# expect+1: expect 23
.info expect 23
.endfor
@@ -27,6 +31,8 @@ VAR= \
# comment \
# continued comment
+# expect+2: expect 30
+# expect+1: expect 30
.info expect 30
.endfor
diff --git a/contrib/bmake/unit-tests/directive-for-null.exp b/contrib/bmake/unit-tests/directive-for-null.exp
index 37a7d68925ed..dee26de25e63 100644
--- a/contrib/bmake/unit-tests/directive-for-null.exp
+++ b/contrib/bmake/unit-tests/directive-for-null.exp
@@ -1,5 +1,5 @@
make: "(stdin)" line 2: Zero byte read from file
-make: "(stdin)" line 2: Unexpected end of file in for loop.
+make: "(stdin)" line 2: Unexpected end of file in .for loop
make: "(stdin)" line 3: Zero byte read from file
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
diff --git a/contrib/bmake/unit-tests/directive-for-null.mk b/contrib/bmake/unit-tests/directive-for-null.mk
index a374f508dd55..fb2d440ee1ba 100644
--- a/contrib/bmake/unit-tests/directive-for-null.mk
+++ b/contrib/bmake/unit-tests/directive-for-null.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-null.mk,v 1.1 2020/12/19 16:00:17 rillig Exp $
+# $NetBSD: directive-for-null.mk,v 1.3 2022/06/12 15:03:27 rillig Exp $
#
# Test for parsing a .for loop that accidentally contains a null byte.
#
@@ -9,11 +9,15 @@
# make: "(stdin)" line 3: Zero byte read from file
#
# The one about "end of file" might be misleading but is due to the
-# implementation. On both errors and EOF, ParseGetLine returns NULL.
+# implementation. On both errors and EOF, ParseRawLine returns NULL.
#
# The one about the "zero byte" in line 3 is surprising since the only
# line that contains a null byte is line 2.
all: .PHONY
- @printf '%s\n' '.for i in 1 2 3' 'VAR=value' '.endfor' | tr 'l' '\0' \
+ @printf '%s\n' \
+ '.for i in 1 2 3' \
+ 'VAR=value' \
+ '.endfor' \
+ | tr 'l' '\0' \
| ${MAKE} -f -
diff --git a/contrib/bmake/unit-tests/directive-for.exp b/contrib/bmake/unit-tests/directive-for.exp
index 4e882aad7b68..0d0313c4e7b0 100755
--- a/contrib/bmake/unit-tests/directive-for.exp
+++ b/contrib/bmake/unit-tests/directive-for.exp
@@ -1,24 +1,42 @@
-make: "directive-for.mk" line 108: outer
-make: "directive-for.mk" line 133: a:\ a:\file.txt
-make: "directive-for.mk" line 133: d:\\
-make: "directive-for.mk" line 133: d:\\file.txt
-make: "directive-for.mk" line 140: ( ( (
-make: "directive-for.mk" line 140: [ [ [
-make: "directive-for.mk" line 140: { { {
-make: "directive-for.mk" line 140: ) ) )
-make: "directive-for.mk" line 140: ] ] ]
-make: "directive-for.mk" line 140: } } }
-make: "directive-for.mk" line 140: (()) (()) (())
-make: "directive-for.mk" line 140: [[]] [[]] [[]]
-make: "directive-for.mk" line 140: {{}} {{}} {{}}
-make: "directive-for.mk" line 140: )( )( )(
-make: "directive-for.mk" line 140: ][ ][ ][
-make: "directive-for.mk" line 140: }{ }{ }{
-make: "directive-for.mk" line 148: outer value value
-make: "directive-for.mk" line 148: outer "quoted" \"quoted\"
-make: "directive-for.mk" line 154: Unknown modifier "Z"
-make: "directive-for.mk" line 155: XXX: Not reached word1
-make: "directive-for.mk" line 155: XXX: Not reached word3
+make: "directive-for.mk" line 117: outer
+make: "directive-for.mk" line 135: a:\ a:\file.txt
+make: "directive-for.mk" line 135: d:\\
+make: "directive-for.mk" line 135: d:\\file.txt
+make: "directive-for.mk" line 146: ( ( (
+make: "directive-for.mk" line 146: [ [ [
+make: "directive-for.mk" line 146: { { {
+make: "directive-for.mk" line 146: ) ) )
+make: "directive-for.mk" line 146: ] ] ]
+make: "directive-for.mk" line 146: } } }
+make: "directive-for.mk" line 146: (()) (()) (())
+make: "directive-for.mk" line 146: [[]] [[]] [[]]
+make: "directive-for.mk" line 146: {{}} {{}} {{}}
+make: "directive-for.mk" line 146: )( )( )(
+make: "directive-for.mk" line 146: ][ ][ ][
+make: "directive-for.mk" line 146: }{ }{ }{
+make: "directive-for.mk" line 166: invalid character ':' in .for loop variable name
+make: "directive-for.mk" line 173: invalid character '$' in .for loop variable name
+make: "directive-for.mk" line 185: invalid character '$' in .for loop variable name
+make: "directive-for.mk" line 210: Unknown modifier "Z"
+make: "directive-for.mk" line 211: XXX: Should not reach word1
+make: "directive-for.mk" line 211: XXX: Should not reach before--after
+make: "directive-for.mk" line 211: XXX: Should not reach word3
+make: "directive-for.mk" line 219: no iteration variables in for
+make: "directive-for.mk" line 245: 1 open conditional
+make: "directive-for.mk" line 261: for-less endfor
+make: "directive-for.mk" line 262: if-less endif
+make: "directive-for.mk" line 270: if-less endif
+For: new loop 2
+For: end for 2
+For: end for 1
+For: loop body with outer = o:
+.\
+ for inner in i
+.\
+ endfor
+For: end for 1
+For: loop body with inner = i:
+make: "directive-for.mk" line 318: newline-item=(a)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-for.mk b/contrib/bmake/unit-tests/directive-for.mk
index 153762509b7a..becc314226dc 100755
--- a/contrib/bmake/unit-tests/directive-for.mk
+++ b/contrib/bmake/unit-tests/directive-for.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for.mk,v 1.10 2020/12/27 09:58:35 rillig Exp $
+# $NetBSD: directive-for.mk,v 1.24 2023/12/06 22:28:20 rillig Exp $
#
# Tests for the .for directive.
#
@@ -8,11 +8,13 @@
# .for _FILE_ in values
# .for .FILE. in values
# .for _f_ in values
-
-# Using the .for loop, lists of values can be produced.
-# In simple cases, the :@var@${var}@ variable modifier can be used to
-# reach the same effects.
#
+# See also:
+# varmod-loop.mk The ':@var@...@' modifier
+
+# A typical use case for a .for loop is to populate a variable with a list of
+# values depending on other variables. In simple cases, the same effect can
+# be achieved using the ':@var@${var}@' modifier.
.undef NUMBERS
.for num in 1 2 3
NUMBERS+= ${num}
@@ -21,8 +23,9 @@ NUMBERS+= ${num}
. error
.endif
+
# The .for loop also works for multiple iteration variables.
-# This is something that the variable modifier :@ cannot do.
+# This is something that the modifier :@ cannot do as easily.
.for name value in VARNAME value NAME2 value2
${name}= ${value}
.endfor
@@ -30,12 +33,12 @@ ${name}= ${value}
. error
.endif
+
# The .for loop splits the items at whitespace, taking quotes into account,
-# just like the :M or :S variable modifiers.
-#
-# Until 2012-06-03, it had split the items exactly at whitespace, without
-# taking the quotes into account. This had resulted in 10 words.
+# just like the :M or :S modifiers.
#
+# Until 2012-06-03, the .for loop had split the items exactly at whitespace,
+# without taking the quotes into account. This had resulted in 10 words.
.undef WORDS
.for var in one t\ w\ o "three three" 'four four' `five six`
WORDS+= counted
@@ -44,16 +47,19 @@ WORDS+= counted
. error
.endif
+
# In the body of the .for loop, the iteration variables can be accessed
# like normal variables, even though they are not really variables.
#
-# Instead, the expression ${var} is transformed into ${:U1}, ${:U2} and so
-# on, before the loop body is evaluated.
+# Instead, before interpreting the body of the .for loop, the body is
+# generated by replacing each expression ${var} with ${:U1}, ${:U2} and so
+# on.
#
-# A notable effect of this implementation technique is that the .for
+# A noticeable effect of this implementation technique is that the .for
# iteration variables and the normal global variables live in separate
-# namespaces and do not influence each other.
-#
+# namespaces and do not influence each other. The "scope" of the .for loop
+# variables is restricted to the current makefile, it does not reach over to
+# any included makefiles.
var= value before
var2= value before
.for var var2 in 1 2 3 4
@@ -66,9 +72,8 @@ var2= value before
.endif
# Everything from the paragraph above also applies if the loop body is
-# empty, even if there is no actual iteration since the loop items are
-# also empty.
-#
+# empty. In this particular example, the items to be iterated are empty as
+# well.
var= value before
var2= value before
.for var var2 in ${:U}
@@ -80,13 +85,15 @@ var2= value before
. warning After the .for loop, var2 must still have its original value.
.endif
-# Until 2008-12-21, the values of the iteration variables were simply
-# inserted as plain text and then parsed as usual, which made it possible
-# to achieve all kinds of strange effects.
+# Before for.c 1.39 from 2008-12-21, the values of the iteration variables
+# were simply inserted as plain text and then parsed as usual, which made it
+# possible to achieve all kinds of strange effects, such as generating '.if'
+# directives or inserting '$' characters in random places, thereby changing
+# how following '$' are interpreted.
#
-# Before that date, the .for loop expanded to:
+# Before that date, the .for loop below expanded to:
# EXPANSION+= value
-# Since that date, the .for loop expands to:
+# Since that date, the .for loop below expands to:
# EXPANSION${:U+}= value
#
EXPANSION= before
@@ -102,13 +109,16 @@ EXPANSION${plus}= value
.endif
# When the outer .for loop is expanded, it sees the expression ${i} and
-# expands it. The inner loop then has nothing more to expand.
+# expands it. The inner loop then only sees the expression ${:Uouter} and
+# has nothing more to expand.
.for i in outer
. for i in inner
+# expect+1: outer
. info ${i}
. endfor
.endfor
+
# From https://gnats.netbsd.org/29985.
#
# Until 2008-12-21, the .for loop was expanded by replacing the variable
@@ -121,39 +131,190 @@ EXPANSION${plus}= value
# like "a:\ a:\file.txt" that ended in a single backslash. Since then, the
# variable values have been replaced with expressions of the form ${:U...},
# which are not interpreted as code anymore.
-#
-# As of 2020-09-22, a comment in for.c says that it may be possible to
-# produce an "unwanted substitution", but there is no demonstration code yet.
-#
-# The above changes prevent a backslash at the end of a word from being
-# interpreted as part of the code. Because of this, the trailingBackslash
-# hack in Var_Subst is no longer needed and as of 2020-09-22, has been
-# removed.
.for path in a:\ a:\file.txt d:\\ d:\\file.txt
. info ${path}
.endfor
+# expect-2: a:\ a:\file.txt
+# expect-3: d:\\
+# expect-4: d:\\file.txt
+
# Ensure that braces and parentheses are properly escaped by the .for loop.
# Each line must print the same word 3 times.
-# See GetEscapes.
+# See ForLoop_SubstBody.
.for v in ( [ { ) ] } (()) [[]] {{}} )( ][ }{
. info $v ${v} $(v)
.endfor
+# expect-02: ( ( (
+# expect-03: [ [ [
+# expect-04: { { {
+# expect-05: ) ) )
+# expect-06: ] ] ]
+# expect-07: } } }
+# expect-08: (()) (()) (())
+# expect-09: [[]] [[]] [[]]
+# expect-10: {{}} {{}} {{}}
+# expect-11: )( )( )(
+# expect-12: ][ ][ ][
+# expect-13: }{ }{ }{
-# As of 2020-10-25, the variable names may contain arbitrary characters,
-# except for whitespace. This allows for creative side effects. Hopefully
-# nobody is misusing this "feature".
+# Before 2023-05-09, the variable names could contain arbitrary characters,
+# except for whitespace, allowing for creative side effects, as usual for
+# arbitrary code injection.
var= outer
+# expect+1: invalid character ':' in .for loop variable name
.for var:Q in value "quoted"
-. info ${var} ${var:Q} ${var:Q:Q}
+. info <${var}> <${var:Q}> <${var:Q:Q}>
+.endfor
+
+# Before 2023-05-09, when variable names could contain '$', the short
+# expression '$$' was preserved, the long expressions were substituted.
+# expect+1: invalid character '$' in .for loop variable name
+.for $ in value
+. info <$$> <${$}> <$($)>
+.endfor
+
+
+# https://gnats.netbsd.org/53146 mentions the idea of using a dynamic
+# variable name in .for loops, based on some other variable. The .for loops
+# are already tricky enough to understand in detail, even without this
+# possibility, therefore the variable names are restricted to using harmless
+# characters only.
+INDIRECT= direct
+# expect+1: invalid character '$' in .for loop variable name
+.for $(INDIRECT) in value
+# If the variable name could be chosen dynamically, the iteration variable
+# might have been 'direct', thereby expanding the expression '${direct}'.
+. info <$(INDIRECT)> <$(direct)> <$($(INDIRECT))>
+.endfor
+
+
+# Regular global variables and the "variables" from the .for loop don't
+# interfere with each other. In the following snippet, the variable 'DIRECT'
+# is used both as a global variable, as well as an iteration variable in the
+# .for loop. The expression '${INDIRECT}' refers to the global variable, not
+# to the one from the .for loop.
+DIRECT= global
+INDIRECT= ${DIRECT}
+.for DIRECT in iteration
+. if "${DIRECT} ${INDIRECT}" != "iteration global"
+. error
+. endif
.endfor
# XXX: A parse error or evaluation error in the items of the .for loop
-# should skip the whole loop. As of 2020-12-27, the loop is expanded twice.
-.for var in word1 ${:Uword2:Z} word3
-. info XXX: Not reached ${var}
+# should skip the whole loop. As of 2023-05-09, the loop is expanded as
+# usual.
+# expect+1: Unknown modifier "Z"
+.for var in word1 before-${:Uword2:Z}-after word3
+. info XXX: Should not reach ${var}
+.endfor
+# expect-2: XXX: Should not reach word1
+# expect-3: XXX: Should not reach before--after
+# expect-4: XXX: Should not reach word3
+
+
+# An empty list of variables to the left of the 'in' is a parse error.
+.for in value # expect+0: no iteration variables in for
+. error
+.endfor
+
+# An empty list of iteration values to the right of the 'in' is accepted.
+# Unlike in the shell, it is not a parse error.
+.for var in
+. error
+.endfor
+
+# If the iteration values become empty after expanding the expressions, the
+# body of the loop is not evaluated. It is not a parse error.
+.for var in ${:U}
+. error
+.endfor
+
+
+# The loop body can be empty.
+.for var in 1 2 3
+.endfor
+
+
+# A mismatched .if inside a .for loop is detected each time when the loop body
+# is processed.
+.for var in value
+. if 0
+.endfor # expect+0: 1 open conditional
+
+# If there are no iteration values, the loop body is not processed, and the
+# check for mismatched conditionals is not performed.
+.for var in ${:U}
+. if 0
+.endfor
+
+
+# When a .for without the corresponding .endfor occurs in an inactive branch
+# of an .if, the .for directive is just skipped, it does not even need a
+# corresponding .endfor. In other words, the behavior of the parser depends
+# on the actual values of the conditions in the .if clauses.
+.if 0
+. for var in value # does not need a corresponding .endfor
+.endif
+.endfor # expect+0: for-less endfor
+.endif # expect+0: if-less endif
+
+
+# When a .for without the corresponding .endfor occurs in an active branch of
+# an .if, the parser just counts the number of .for and .endfor directives,
+# without looking at any other directives.
+.if 1
+. for var in value
+. endif # expect+0: if-less endif
+. endfor # no 'for-less endfor'
+.endif # no 'if-less endif'
+
+
+# Before for.c 1.172 from 2023-05-08, when make parsed a .for loop, it
+# assumed that there was no line continuation between the '.' and the 'for'
+# or 'endfor', as there is no practical reason to break the line at this
+# point.
+#
+# When make scanned the outer .for loop, it did not recognize the inner .for
+# loop as such and instead treated it as an unknown directive. The body of
+# the outer .for loop thus ended above the '.endfor'.
+#
+# When make scanned the inner .for loop, it did not recognize the inner
+# .endfor as such, which led to a parse error 'Unexpected end of file in .for
+# loop' from the '.endfor' line, followed by a second parse error 'for-less
+# .endfor' from the '.\\n endfor' line.
+.MAKEFLAGS: -df
+.for outer in o
+.\
+ for inner in i
+.\
+ endfor
+.endfor
+.MAKEFLAGS: -d0
+
+
+# When there is a variable definition 'scope=cmdline' from the command line
+# (which has higher precedence than global variables) and a .for loop iterates
+# over a variable of the same name, the expression '${scope}' expands to the
+# value from the .for loop. This is because when the body of the .for loop is
+# expanded, the expression '${scope}' is textually replaced with ${:Uloop}',
+# without resolving any other variable names (ForLoop_SubstBody). Later, when
+# the body of the .for loop is actually interpreted, the body text doesn't
+# contain the word 'scope' anymore.
+.MAKEFLAGS: scope=cmdline
+.for scope in loop
+. if ${scope} != "loop"
+. error
+. endif
.endfor
-all:
- @:;
+
+# Since at least 1993, iteration stops at the first newline.
+# Back then, the .newline variable didn't exist, therefore it was unlikely
+# that a newline ever occurred.
+.for var in a${.newline}b${.newline}c
+. info newline-item=(${var})
+.endfor
+# expect-2: newline-item=(a)
diff --git a/contrib/bmake/unit-tests/directive-hyphen-include.exp b/contrib/bmake/unit-tests/directive-hyphen-include.exp
index 39a9383953dd..308a444890d5 100755
--- a/contrib/bmake/unit-tests/directive-hyphen-include.exp
+++ b/contrib/bmake/unit-tests/directive-hyphen-include.exp
@@ -1 +1,4 @@
-exit status 0
+make: "directive-hyphen-include-error.inc" line 1: Invalid line 'syntax error'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-hyphen-include.mk b/contrib/bmake/unit-tests/directive-hyphen-include.mk
index 8c851be43215..de3b68ae52b3 100755
--- a/contrib/bmake/unit-tests/directive-hyphen-include.mk
+++ b/contrib/bmake/unit-tests/directive-hyphen-include.mk
@@ -1,9 +1,23 @@
-# $NetBSD: directive-hyphen-include.mk,v 1.1 2020/09/13 09:20:23 rillig Exp $
+# $NetBSD: directive-hyphen-include.mk,v 1.3 2023/08/19 10:52:13 rillig Exp $
#
# Tests for the .-include directive, which includes another file,
# silently skipping it if it cannot be opened.
+#
+# The 'silently skipping' only applies to the case where the file cannot be
+# opened. Parse errors and other errors are handled the same way as in the
+# other .include directives.
+
+# No complaint that there is no such file.
+.-include "${.CURDIR}/directive-hyphen-include-nonexistent.inc"
+
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.-include "${MAKEFILE}/subdir"
-# TODO: Implementation
+# Errors that are not related to opening the file are still reported.
+# expect: make: "directive-hyphen-include-error.inc" line 1: Invalid line 'syntax error'
+_!= echo 'syntax error' > directive-hyphen-include-error.inc
+.-include "${.CURDIR}/directive-hyphen-include-error.inc"
+_!= rm directive-hyphen-include-error.inc
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive-if.exp b/contrib/bmake/unit-tests/directive-if.exp
index 89a394fc0f22..34ba63d034dd 100644
--- a/contrib/bmake/unit-tests/directive-if.exp
+++ b/contrib/bmake/unit-tests/directive-if.exp
@@ -1,17 +1,18 @@
-make: "directive-if.mk" line 13: 0 evaluates to false.
-make: "directive-if.mk" line 17: 1 evaluates to true.
-make: "directive-if.mk" line 40: Unknown directive "ifx"
-make: "directive-if.mk" line 41: This is not conditional.
-make: "directive-if.mk" line 42: if-less else
-make: "directive-if.mk" line 43: This is not conditional.
-make: "directive-if.mk" line 44: if-less endif
-make: "directive-if.mk" line 47: Malformed conditional ()
-make: "directive-if.mk" line 57: Quotes in plain words are probably a mistake.
-make: "directive-if.mk" line 66: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 70: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 76: Don't do this, always put a space around comparison operators.
-make: "directive-if.mk" line 82: Don't do this, always put a space after a directive.
-make: "directive-if.mk" line 86: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 14: 0 evaluates to false.
+make: "directive-if.mk" line 19: 1 evaluates to true.
+make: "directive-if.mk" line 43: Unknown directive "ifx"
+make: "directive-if.mk" line 45: This is not conditional.
+make: "directive-if.mk" line 47: if-less else
+make: "directive-if.mk" line 49: This is not conditional.
+make: "directive-if.mk" line 51: if-less endif
+make: "directive-if.mk" line 55: Malformed conditional ()
+make: "directive-if.mk" line 66: Quotes in plain words are probably a mistake.
+make: "directive-if.mk" line 76: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 81: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 88: Don't do this, always put a space around comparison operators.
+make: "directive-if.mk" line 95: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 100: Don't do this, always put a space after a directive.
+make: "directive-if.mk" line 108: Unknown directive "ifn"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-if.mk b/contrib/bmake/unit-tests/directive-if.mk
index b1ad2396b398..7a68c0041415 100644
--- a/contrib/bmake/unit-tests/directive-if.mk
+++ b/contrib/bmake/unit-tests/directive-if.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-if.mk,v 1.9 2020/12/19 22:33:11 rillig Exp $
+# $NetBSD: directive-if.mk,v 1.12 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .if directive.
#
@@ -10,10 +10,12 @@
.if 0
. error
.else
+# expect+1: 0 evaluates to false.
. info 0 evaluates to false.
.endif
.if 1
+# expect+1: 1 evaluates to true.
. info 1 evaluates to true.
.else
. error
@@ -37,13 +39,19 @@
# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
# are interpreted as ordinary directives, producing the error messages
# "if-less else" and "if-less endif".
+# expect+1: Unknown directive "ifx"
.ifx 123
+# expect+1: This is not conditional.
.info This is not conditional.
+# expect+1: if-less else
.else
+# expect+1: This is not conditional.
.info This is not conditional.
+# expect+1: if-less endif
.endif
# Missing condition.
+# expect+1: Malformed conditional ()
.if
. error
.else
@@ -54,6 +62,7 @@
# though, which are kept. The quotes need not be balanced. The next space
# ends the word, and the remaining " || 1" is parsed as "or true".
.if ${:Uplain"""""} == plain""""" || 1
+# expect+1: Quotes in plain words are probably a mistake.
. info Quotes in plain words are probably a mistake.
# XXX: Accepting quotes in plain words is probably a mistake as well.
.else
@@ -63,27 +72,37 @@
.if0
. error
.else
+# expect+1: Don't do this, always put a space after a directive.
. info Don't do this, always put a space after a directive.
.endif
.if${:U-3}
+# expect+1: Don't do this, always put a space after a directive.
. info Don't do this, always put a space after a directive.
.else
. error
.endif
.if${:U-3}>-4
+# expect+1: Don't do this, always put a space around comparison operators.
. info Don't do this, always put a space around comparison operators.
.else
. error
.endif
.if(1)
+# expect+1: Don't do this, always put a space after a directive.
. info Don't do this, always put a space after a directive.
.endif
.if!0
+# expect+1: Don't do this, always put a space after a directive.
. info Don't do this, always put a space after a directive.
.endif
-all:
+
+# The directives '.ifdef' and '.ifmake' can be negated by inserting an 'n'.
+# This doesn't work for a plain '.if' though.
+#
+# expect+1: Unknown directive "ifn"
+.ifn 0
diff --git a/contrib/bmake/unit-tests/directive-ifdef.exp b/contrib/bmake/unit-tests/directive-ifdef.exp
index 1a1358988f39..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/directive-ifdef.exp
+++ b/contrib/bmake/unit-tests/directive-ifdef.exp
@@ -1,4 +1 @@
-make: "directive-ifdef.mk" line 12: Function calls in .ifdef are possible.
-make: "directive-ifdef.mk" line 23: String literals are tested for emptiness.
-make: "directive-ifdef.mk" line 27: String literals are tested for emptiness. Whitespace is non-empty.
exit status 0
diff --git a/contrib/bmake/unit-tests/directive-ifdef.mk b/contrib/bmake/unit-tests/directive-ifdef.mk
index 12f3648e8b2c..8a60fb4a2669 100644
--- a/contrib/bmake/unit-tests/directive-ifdef.mk
+++ b/contrib/bmake/unit-tests/directive-ifdef.mk
@@ -1,33 +1,51 @@
-# $NetBSD: directive-ifdef.mk,v 1.4 2021/01/21 23:03:41 rillig Exp $
+# $NetBSD: directive-ifdef.mk,v 1.5 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the .ifdef directive.
-
-# TODO: Implementation
+# Tests for the .ifdef directive, which evaluates bare words by calling
+# 'defined(word)'.
DEFINED= defined
+# There is no variable named 'UNDEF', therefore the condition evaluates to
+# false.
+.ifdef UNDEF
+. error
+.endif
+
+# There is a variable named 'DEFINED', so the condition evaluates to true.
+.ifdef DEFINED
+.else
+. error
+.endif
+
+# Since a bare word is an abbreviation for 'defined(word)', these can be
+# used to construct complex conditions.
+.ifdef UNDEF && DEFINED
+. error
+.endif
+.ifdef UNDEF || DEFINED
+.else
+. error
+.endif
+
# It looks redundant to have a call to defined() in an .ifdef, but it's
-# possible. The .ifdef only affects plain symbols, not function calls.
+# possible. The '.ifdef' only affects bare words, not function calls.
.ifdef defined(DEFINED)
-. info Function calls in .ifdef are possible.
.else
. error
.endif
-# String literals are handled the same in all variants of the .if directive.
-# They evaluate to true if they are not empty. Whitespace counts as non-empty
-# as well.
+# String literals are handled the same in all variants of the '.if' directive,
+# they evaluate to true if they are not empty, therefore this particular
+# example looks confusing and is thus not found in practice.
.ifdef ""
. error
.else
-. info String literals are tested for emptiness.
.endif
+# Whitespace counts as non-empty as well.
.ifdef " "
-. info String literals are tested for emptiness. Whitespace is non-empty.
.else
. error
.endif
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive-ifmake.exp b/contrib/bmake/unit-tests/directive-ifmake.exp
index fd4bcae151a0..e607726fd87c 100644
--- a/contrib/bmake/unit-tests/directive-ifmake.exp
+++ b/contrib/bmake/unit-tests/directive-ifmake.exp
@@ -1,11 +1,15 @@
-make: "directive-ifmake.mk" line 13: ok: positive condition works
-make: "directive-ifmake.mk" line 24: ok: negation works
-make: "directive-ifmake.mk" line 33: ok: double negation works
-make: "directive-ifmake.mk" line 40: ok: both mentioned
-make: "directive-ifmake.mk" line 47: ok: only those mentioned
-make: "directive-ifmake.mk" line 57: Targets can even be added at parse time.
-make: "directive-ifmake.mk" line 75: ok
+make: "directive-ifmake.mk" line 14: ok: positive condition works
+make: "directive-ifmake.mk" line 26: ok: negation works
+make: "directive-ifmake.mk" line 36: ok: double negation works
+make: "directive-ifmake.mk" line 44: ok: both mentioned
+make: "directive-ifmake.mk" line 52: ok: only those mentioned
+make: "directive-ifmake.mk" line 63: Targets can even be added at parse time.
+make: "directive-ifmake.mk" line 82: ok
: first
: second
: late-target
-exit status 0
+make: don't know how to make !edge (continuing)
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-ifmake.mk b/contrib/bmake/unit-tests/directive-ifmake.mk
index 4d49add72626..fa0a56c60030 100644
--- a/contrib/bmake/unit-tests/directive-ifmake.mk
+++ b/contrib/bmake/unit-tests/directive-ifmake.mk
@@ -1,26 +1,28 @@
-# $NetBSD: directive-ifmake.mk,v 1.8 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: directive-ifmake.mk,v 1.12 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the .ifmake directive, which provides a shortcut for asking
# whether a certain target is requested to be made from the command line.
#
# TODO: Describe why the shortcut may be useful (if it's useful at all),
-# instead of sticking to the simple '.if' only.
+# instead of using the more general '.if make(target)'.
-# The targets 'first' and 'second' are passed in on the command line.
+.MAKEFLAGS: first second
# This is the most basic form.
.ifmake first
+# expect+1: ok: positive condition works
. info ok: positive condition works
.else
. warning positive condition fails
.endif
-# The not operator works as expected.
-# An alternative interpretation were that this condition is asking whether
-# the target "!first" was requested. To distinguish this, see the next test.
+# The '!' is interpreted as 'not'. A possible alternative interpretation of
+# this condition is whether the target named "!first" was requested. To
+# distinguish these cases, see the next test.
.ifmake !first
. warning unexpected
.else
+# expect+1: ok: negation works
. info ok: negation works
.endif
@@ -30,6 +32,7 @@
# exclamation mark were part of the name instead, the name would be '!!first',
# and such a target was not requested to be made.
.ifmake !!first
+# expect+1: ok: double negation works
. info ok: double negation works
.else
. warning double negation fails
@@ -37,6 +40,7 @@
# Multiple targets can be combined using the && and || operators.
.ifmake first && second
+# expect+1: ok: both mentioned
. info ok: both mentioned
.else
. warning && does not work as expected
@@ -44,6 +48,7 @@
# Negation also works in complex conditions.
.ifmake first && !unmentioned
+# expect+1: ok: only those mentioned
. info ok: only those mentioned
.else
. warning && with ! does not work as expected
@@ -54,6 +59,7 @@
# possible to extend the targets to be made.
.MAKEFLAGS: late-target
.ifmake late-target
+# expect+1: Targets can even be added at parse time.
. info Targets can even be added at parse time.
.else
. info No, targets cannot be added at parse time anymore.
@@ -69,14 +75,40 @@
. error
.endif
-# A condition that consists of a variable expression only (without any
+# A condition that consists of an expression only (without any
# comparison operator) can be used with .if and the other .ifxxx directives.
.ifmake ${:Ufirst}
+# expect+1: ok
. info ok
.else
. error
.endif
-first second unmentioned late-target:
+# As an edge case, a target can actually be named "!first" on the command
+# line. There is no way to define a target of this name though since in a
+# dependency line, a plain '!' is interpreted as a dependency operator.
+
+.MAKEFLAGS: !edge
+.ifmake edge
+. error
+.endif
+
+# The '\!edge' in the following condition is parsed as a bare word. For such
+# a bare word, there is no escaping mechanism so the backslash passes through.
+# Since the condition function 'make' accepts a pattern instead of a plain
+# target name, the '\' is finally discarded in Str_Match.
+.ifmake \!edge
+.else
+. error
+.endif
+
+# In a dependency line, a plain '!' is interpreted as a dependency operator
+# (the other two are ':' and '::'). If the '!' is escaped by a '\', as
+# implemented in ParseDependencyTargetWord, the additional backslash is never
+# removed though. The target name thus becomes '\!edge' instead of the
+# intended '!edge'. Defining a target whose name contains a '!' will either
+# require additional tricks, or it may even be impossible.
+
+first second unmentioned late-target \!edge:
: $@
diff --git a/contrib/bmake/unit-tests/directive-ifndef.exp b/contrib/bmake/unit-tests/directive-ifndef.exp
index c653f6344429..d018e78616bc 100644
--- a/contrib/bmake/unit-tests/directive-ifndef.exp
+++ b/contrib/bmake/unit-tests/directive-ifndef.exp
@@ -1,2 +1,2 @@
-make: "directive-ifndef.mk" line 10: guarded section
+make: "directive-ifndef.mk" line 14: guarded section
exit status 0
diff --git a/contrib/bmake/unit-tests/directive-ifndef.mk b/contrib/bmake/unit-tests/directive-ifndef.mk
index bf509ef8075e..44eec55b4a87 100644
--- a/contrib/bmake/unit-tests/directive-ifndef.mk
+++ b/contrib/bmake/unit-tests/directive-ifndef.mk
@@ -1,12 +1,16 @@
-# $NetBSD: directive-ifndef.mk,v 1.6 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: directive-ifndef.mk,v 1.9 2023/10/19 18:24:33 rillig Exp $
#
# Tests for the .ifndef directive, which can be used for multiple-inclusion
# guards. In contrast to C, where #ifndef and #define nicely line up the
# macro name, there is no such syntax in make. Therefore, it is more
# common to use .if !defined(GUARD) instead.
+#
+# See also:
+# directive-include-guard.mk
.ifndef GUARD
GUARD= # defined
+# expect+1: guarded section
. info guarded section
.endif
@@ -20,5 +24,64 @@ GUARD= # defined
. info guarded section
.endif
+
+# The '.ifndef' directive can be used with multiple arguments, even negating
+# them. Since these conditions are confusing for humans, they should be
+# replaced with easier-to-understand plain '.if' directives.
+DEFINED=
+.ifndef UNDEFINED && UNDEFINED
+.else
+. error
+.endif
+.ifndef UNDEFINED && DEFINED
+. error
+.endif
+.ifndef DEFINED && DEFINED
+. error
+.endif
+.ifndef !UNDEFINED && !UNDEFINED
+. error
+.endif
+.ifndef !UNDEFINED && !DEFINED
+. error
+.endif
+.ifndef !DEFINED && !DEFINED
+.else
+. error
+.endif
+
+
+# The negation from the 'if-not-defined' directive only applies to bare words,
+# but not to numbers, quoted strings or expressions. Those are evaluated
+# without extra negation, just like in a plain '.if' directive.
+.ifndef 0
+. error
+.endif
+.ifndef 1
+.else
+. error
+.endif
+.ifndef ""
+. error
+.endif
+.ifndef "word"
+.else
+. error
+.endif
+.ifndef ${:UUNDEFINED}
+.else
+. error
+.endif
+.ifndef ${:UDEFINED}
+. error
+.endif
+.ifndef ${:U0}
+. error
+.endif
+.ifndef ${:U1}
+.else
+. error
+.endif
+
+
all:
- @:;
diff --git a/contrib/bmake/unit-tests/directive-include-fatal.exp b/contrib/bmake/unit-tests/directive-include-fatal.exp
index c8ca97a0fd5f..cae0fc97a59d 100755
--- a/contrib/bmake/unit-tests/directive-include-fatal.exp
+++ b/contrib/bmake/unit-tests/directive-include-fatal.exp
@@ -1,4 +1,4 @@
-make: "directive-include-fatal.mk" line 13: Malformed conditional (${UNDEF})
+make: "directive-include-fatal.mk" line 14: Malformed conditional (${UNDEF})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-include-fatal.mk b/contrib/bmake/unit-tests/directive-include-fatal.mk
index 6744f9e80e5c..d4ed26f2a4aa 100755
--- a/contrib/bmake/unit-tests/directive-include-fatal.mk
+++ b/contrib/bmake/unit-tests/directive-include-fatal.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include-fatal.mk,v 1.3 2021/02/01 22:16:57 rillig Exp $
+# $NetBSD: directive-include-fatal.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Test for the .include directive combined with fatal errors.
#
@@ -10,6 +10,7 @@
# the "fatals" counter.
# Using an undefined variable in a condition generates a fatal error.
+# expect+1: Malformed conditional (${UNDEF})
.if ${UNDEF}
.endif
diff --git a/contrib/bmake/unit-tests/directive-include-guard.exp b/contrib/bmake/unit-tests/directive-include-guard.exp
new file mode 100644
index 000000000000..70d23a19fe7c
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-include-guard.exp
@@ -0,0 +1,104 @@
+Parse_PushInput: file variable-ifndef.tmp, line 1
+Skipping 'variable-ifndef.tmp' because 'VARIABLE_IFNDEF' is defined
+Parse_PushInput: file variable-ifndef-reuse.tmp, line 1
+Skipping 'variable-ifndef-reuse.tmp' because 'VARIABLE_IFNDEF' is defined
+Parse_PushInput: file variable-ifndef-zero.tmp, line 1
+Parse_PushInput: file variable-ifndef-zero.tmp, line 1
+Parse_PushInput: file variable-ifndef-one.tmp, line 1
+Parse_PushInput: file variable-ifndef-one.tmp, line 1
+Parse_PushInput: file comments.tmp, line 1
+Skipping 'comments.tmp' because 'COMMENTS' is defined
+Parse_PushInput: file variable-if.tmp, line 1
+Skipping 'variable-if.tmp' because 'VARIABLE_IF' is defined
+Parse_PushInput: file variable-if-reuse.tmp, line 1
+Skipping 'variable-if-reuse.tmp' because 'VARIABLE_IF' is defined
+Parse_PushInput: file variable-if-triple-negation.tmp, line 1
+Parse_PushInput: file variable-if-triple-negation.tmp, line 1
+Parse_PushInput: file variable-if-spaced.tmp, line 1
+Parse_PushInput: file variable-if-spaced.tmp, line 1
+Parse_PushInput: file variable-if-parenthesized.tmp, line 1
+Parse_PushInput: file variable-if-parenthesized.tmp, line 1
+Parse_PushInput: file variable-ifdef-negated.tmp, line 1
+Parse_PushInput: file variable-ifdef-negated.tmp, line 1
+Parse_PushInput: file variable-name-mismatch.tmp, line 1
+Parse_PushInput: file variable-name-mismatch.tmp, line 1
+Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1
+Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1
+Parse_PushInput: file variable-name-exclamation.tmp, line 1
+Parse_PushInput: file variable-name-exclamation.tmp, line 1
+Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1
+Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1
+Parse_PushInput: file variable-name-parentheses.tmp, line 1
+Parse_PushInput: file variable-name-parentheses.tmp, line 1
+Parse_PushInput: file variable-ifndef-plus.tmp, line 1
+Parse_PushInput: file variable-ifndef-plus.tmp, line 1
+Parse_PushInput: file variable-if-plus.tmp, line 1
+Parse_PushInput: file variable-if-plus.tmp, line 1
+Parse_PushInput: file variable-ifndef-indirect.tmp, line 1
+Parse_PushInput: file variable-ifndef-indirect.tmp, line 1
+Parse_PushInput: file variable-if-indirect.tmp, line 1
+Parse_PushInput: file variable-if-indirect.tmp, line 1
+Parse_PushInput: file variable-assign-indirect.tmp, line 1
+Skipping 'variable-assign-indirect.tmp' because 'VARIABLE_ASSIGN_INDIRECT' is defined
+Parse_PushInput: file variable-assign-late.tmp, line 1
+Skipping 'variable-assign-late.tmp' because 'VARIABLE_ASSIGN_LATE' is defined
+Parse_PushInput: file variable-assign-nested.tmp, line 1
+Parse_PushInput: .for loop in variable-assign-nested.tmp, line 3
+Skipping 'variable-assign-nested.tmp' because 'VARIABLE_ASSIGN_NESTED' is defined
+Parse_PushInput: file variable-already-defined.tmp, line 1
+Skipping 'variable-already-defined.tmp' because 'VARIABLE_ALREADY_DEFINED' is defined
+Parse_PushInput: file variable-defined-then-undefined.tmp, line 1
+Parse_PushInput: file variable-defined-then-undefined.tmp, line 1
+Parse_PushInput: file variable-two-times.tmp, line 1
+Parse_PushInput: file variable-two-times.tmp, line 1
+Parse_PushInput: file variable-clash.tmp, line 1
+Skipping 'variable-clash.tmp' because 'VARIABLE_IF' is defined
+Parse_PushInput: file variable-swapped.tmp, line 1
+Parse_PushInput: file variable-swapped.tmp, line 1
+Parse_PushInput: file variable-undef-between.tmp, line 1
+Parse_PushInput: file variable-undef-between.tmp, line 1
+Parse_PushInput: file variable-undef-inside.tmp, line 1
+Parse_PushInput: file variable-undef-inside.tmp, line 1
+Parse_PushInput: file variable-not-defined.tmp, line 1
+Parse_PushInput: file variable-not-defined.tmp, line 1
+Parse_PushInput: file elif.tmp, line 1
+Parse_PushInput: file elif.tmp, line 1
+Parse_PushInput: file elif-reuse.tmp, line 1
+Parse_PushInput: file elif-reuse.tmp, line 1
+Parse_PushInput: file else.tmp, line 1
+Parse_PushInput: file else.tmp, line 1
+Parse_PushInput: file else-reuse.tmp, line 1
+Parse_PushInput: file else-reuse.tmp, line 1
+Parse_PushInput: file inner-if-elif-else.tmp, line 1
+Skipping 'inner-if-elif-else.tmp' because 'INNER_IF_ELIF_ELSE' is defined
+Parse_PushInput: file target.tmp, line 1
+Skipping 'target.tmp' because '__target.tmp__' is defined
+Parse_PushInput: file target-sys.tmp, line 1
+Skipping 'target-sys.tmp' because '__<target-sys.tmp>__' is defined
+Parse_PushInput: file target-indirect.tmp, line 1
+Skipping 'target-indirect.tmp' because 'target-indirect.tmp' is defined
+Parse_PushInput: file target-indirect-PARSEFILE.tmp, line 1
+Skipping 'target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined
+Parse_PushInput: file target-indirect-PARSEFILE2.tmp, line 1
+Skipping 'target-indirect-PARSEFILE2.tmp' because '__target-indirect-PARSEFILE2.tmp__' is defined
+Parse_PushInput: file subdir/target-indirect-PARSEFILE.tmp, line 1
+Skipping 'subdir/target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined
+Parse_PushInput: file target-indirect-PARSEDIR-PARSEFILE.tmp, line 1
+Skipping 'target-indirect-PARSEDIR-PARSEFILE.tmp' because '__target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined
+Parse_PushInput: file subdir/target-indirect-PARSEDIR-PARSEFILE.tmp, line 1
+Skipping 'subdir/target-indirect-PARSEDIR-PARSEFILE.tmp' because '__subdir/target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined
+Parse_PushInput: file target-unguarded.tmp, line 1
+Parse_PushInput: file target-unguarded.tmp, line 1
+Parse_PushInput: file target-plus.tmp, line 1
+Parse_PushInput: file target-plus.tmp, line 1
+Parse_PushInput: file target-already-defined.tmp, line 1
+Skipping 'target-already-defined.tmp' because 'target-already-defined' is defined
+Parse_PushInput: file target-name-exclamation.tmp, line 1
+Parse_PushInput: file target-name-exclamation.tmp, line 1
+Parse_PushInput: file target-name-parenthesized.tmp, line 1
+Parse_PushInput: file target-name-parenthesized.tmp, line 1
+Parse_PushInput: file target-call-parenthesized.tmp, line 1
+Parse_PushInput: file target-call-parenthesized.tmp, line 1
+Parse_PushInput: file multiline.tmp, line 1
+Skipping 'multiline.tmp' because 'MULTILINE' is defined
+exit status 0
diff --git a/contrib/bmake/unit-tests/directive-include-guard.mk b/contrib/bmake/unit-tests/directive-include-guard.mk
new file mode 100644
index 000000000000..85c0242c2009
--- /dev/null
+++ b/contrib/bmake/unit-tests/directive-include-guard.mk
@@ -0,0 +1,638 @@
+# $NetBSD: directive-include-guard.mk,v 1.16 2023/12/17 14:07:22 rillig Exp $
+#
+# Tests for multiple-inclusion guards in makefiles.
+#
+# A file that is guarded by a multiple-inclusion guard has one of the
+# following forms:
+#
+# .ifndef GUARD_VARIABLE
+# .endif
+#
+# .if !defined(GUARD_VARIABLE)
+# .endif
+#
+# .if !target(guard-target)
+# .endif
+#
+# When such a file is included for the second or later time, and the guard
+# variable or the guard target is defined, the file is skipped completely, as
+# including it would not have any effect, not even on the special variable
+# '.MAKE.MAKEFILES', as that variable skips duplicate pathnames.
+#
+# See also:
+# https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
+
+# Each of the following test cases creates a temporary file named after the
+# test case and writes some lines of text to that file. That file is then
+# included twice, to see whether the second '.include' is skipped.
+
+
+# This is the canonical form of a variable-based multiple-inclusion guard.
+CASES+= variable-ifndef
+LINES.variable-ifndef= \
+ '.ifndef VARIABLE_IFNDEF' \
+ 'VARIABLE_IFNDEF=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef.tmp, line 1
+# expect: Skipping 'variable-ifndef.tmp' because 'VARIABLE_IFNDEF' is defined
+
+# A file that reuses a guard from a previous file (or whose guard is defined
+# for any other reason) is only processed once, to see whether it is guarded.
+# Its content is skipped, therefore the syntax error is not detected.
+CASES+= variable-ifndef-reuse
+LINES.variable-ifndef-reuse= \
+ '.ifndef VARIABLE_IFNDEF' \
+ 'syntax error' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-reuse.tmp, line 1
+# expect: Skipping 'variable-ifndef-reuse.tmp' because 'VARIABLE_IFNDEF' is defined
+
+# The guard variable cannot be a number, as numbers are interpreted
+# differently from bare words.
+CASES+= variable-ifndef-zero
+LINES.variable-ifndef-zero= \
+ '.ifndef 0e0' \
+ 'syntax error' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-zero.tmp, line 1
+# expect: Parse_PushInput: file variable-ifndef-zero.tmp, line 1
+
+# The guard variable cannot be a number, as numbers are interpreted
+# differently from bare words.
+CASES+= variable-ifndef-one
+LINES.variable-ifndef-one= \
+ '.ifndef 1' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-one.tmp, line 1
+# expect: Parse_PushInput: file variable-ifndef-one.tmp, line 1
+
+# Comments and empty lines do not affect the multiple-inclusion guard.
+CASES+= comments
+LINES.comments= \
+ '\# comment' \
+ '' \
+ '.ifndef COMMENTS' \
+ '\# comment' \
+ 'COMMENTS=\#comment' \
+ '.endif' \
+ '\# comment'
+# expect: Parse_PushInput: file comments.tmp, line 1
+# expect: Skipping 'comments.tmp' because 'COMMENTS' is defined
+
+# An alternative form uses the 'defined' function. It is more verbose than
+# the canonical form but avoids the '.ifndef' directive, as that directive is
+# not commonly used.
+CASES+= variable-if
+LINES.variable-if= \
+ '.if !defined(VARIABLE_IF)' \
+ 'VARIABLE_IF=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if.tmp, line 1
+# expect: Skipping 'variable-if.tmp' because 'VARIABLE_IF' is defined
+
+# A file that reuses a guard from a previous file (or whose guard is defined
+# for any other reason) is only processed once, to see whether it is guarded.
+# Its content is skipped, therefore the syntax error is not detected.
+CASES+= variable-if-reuse
+LINES.variable-if-reuse= \
+ '.if !defined(VARIABLE_IF)' \
+ 'syntax error' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-reuse.tmp, line 1
+# expect: Skipping 'variable-if-reuse.tmp' because 'VARIABLE_IF' is defined
+
+# Triple negation is so uncommon that it's not recognized, even though it has
+# the same effect as a single negation.
+CASES+= variable-if-triple-negation
+LINES.variable-if-triple-negation= \
+ '.if !!!defined(VARIABLE_IF_TRIPLE_NEGATION)' \
+ 'VARIABLE_IF_TRIPLE_NEGATION=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-triple-negation.tmp, line 1
+# expect: Parse_PushInput: file variable-if-triple-negation.tmp, line 1
+
+# If the guard variable is enclosed in spaces, it does not have an effect, as
+# that form is not common in practice.
+CASES+= variable-if-spaced
+LINES.variable-if-spaced= \
+ '.if !defined( VARIABLE_IF_SPACED )' \
+ 'VARIABLE_IF_SPACED=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-spaced.tmp, line 1
+# expect: Parse_PushInput: file variable-if-spaced.tmp, line 1
+
+# If the guard variable condition is enclosed in parentheses, it does not have
+# an effect, as that form is not common in practice.
+CASES+= variable-if-parenthesized
+LINES.variable-if-parenthesized= \
+ '.if (!defined(VARIABLE_IF_PARENTHESIZED))' \
+ 'VARIABLE_IF_PARENTHESIZED=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-parenthesized.tmp, line 1
+# expect: Parse_PushInput: file variable-if-parenthesized.tmp, line 1
+
+# A conditional other than '.if' or '.ifndef' does not guard the file, even if
+# it is otherwise equivalent to the above accepted forms.
+CASES+= variable-ifdef-negated
+LINES.variable-ifdef-negated= \
+ '.ifdef !VARIABLE_IFDEF_NEGATED' \
+ 'VARIABLE_IFDEF_NEGATED=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifdef-negated.tmp, line 1
+# expect: Parse_PushInput: file variable-ifdef-negated.tmp, line 1
+
+# The variable names in the '.if' and the assignment must be the same.
+CASES+= variable-name-mismatch
+LINES.variable-name-mismatch= \
+ '.ifndef VARIABLE_NAME_MISMATCH' \
+ 'VARIABLE_NAME_DIFFERENT=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-name-mismatch.tmp, line 1
+# expect: Parse_PushInput: file variable-name-mismatch.tmp, line 1
+
+# If the guard variable condition is enclosed in parentheses, it does not have
+# an effect, as that form is not common in practice.
+CASES+= variable-ifndef-parenthesized
+LINES.variable-ifndef-parenthesized= \
+ '.ifndef (VARIABLE_IFNDEF_PARENTHESIZED)' \
+ 'VARIABLE_IFNDEF_PARENTHESIZED=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1
+# expect: Parse_PushInput: file variable-ifndef-parenthesized.tmp, line 1
+
+# The variable name '!VARNAME' cannot be used in an '.ifndef' directive, as
+# the '!' would be a negation. It is syntactically valid in a '.if !defined'
+# condition, but this case is so uncommon that the guard mechanism doesn't
+# accept '!' in the guard variable name. Furthermore, when defining the
+# variable, the character '!' has to be escaped, to prevent it from being
+# interpreted as the '!' dependency operator.
+CASES+= variable-name-exclamation
+LINES.variable-name-exclamation= \
+ '.if !defined(!VARIABLE_NAME_EXCLAMATION)' \
+ '${:U!}VARIABLE_NAME_EXCLAMATION=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-name-exclamation.tmp, line 1
+# expect: Parse_PushInput: file variable-name-exclamation.tmp, line 1
+
+# In general, a variable name can contain a '!' in the middle, as that
+# character is interpreted as an ordinary character in conditions as well as
+# on the left side of a variable assignment. For guard variable names, the
+# '!' is not supported in any place, though.
+CASES+= variable-name-exclamation-middle
+LINES.variable-name-exclamation-middle= \
+ '.ifndef VARIABLE_NAME!MIDDLE' \
+ 'VARIABLE_NAME!MIDDLE=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1
+# expect: Parse_PushInput: file variable-name-exclamation-middle.tmp, line 1
+
+# A variable name can contain balanced parentheses, at least in conditions and
+# on the left side of a variable assignment. There are enough places in make
+# where parentheses or braces are handled inconsistently to make this naming
+# choice a bad idea, therefore these characters are not allowed in guard
+# variable names.
+CASES+= variable-name-parentheses
+LINES.variable-name-parentheses= \
+ '.ifndef VARIABLE_NAME(&)PARENTHESES' \
+ 'VARIABLE_NAME(&)PARENTHESES=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-name-parentheses.tmp, line 1
+# expect: Parse_PushInput: file variable-name-parentheses.tmp, line 1
+
+# The guard condition must consist of only the guard variable, nothing else.
+CASES+= variable-ifndef-plus
+LINES.variable-ifndef-plus= \
+ '.ifndef VARIABLE_IFNDEF_PLUS && VARIABLE_IFNDEF_SECOND' \
+ 'VARIABLE_IFNDEF_PLUS=' \
+ 'VARIABLE_IFNDEF_SECOND=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-plus.tmp, line 1
+# expect: Parse_PushInput: file variable-ifndef-plus.tmp, line 1
+
+# The guard condition must consist of only the guard variable, nothing else.
+CASES+= variable-if-plus
+LINES.variable-if-plus= \
+ '.if !defined(VARIABLE_IF_PLUS) && !defined(VARIABLE_IF_SECOND)' \
+ 'VARIABLE_IF_PLUS=' \
+ 'VARIABLE_IF_SECOND=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-plus.tmp, line 1
+# expect: Parse_PushInput: file variable-if-plus.tmp, line 1
+
+# The variable name in an '.ifndef' guard must be given directly, it must not
+# contain any '$' expression.
+CASES+= variable-ifndef-indirect
+LINES.variable-ifndef-indirect= \
+ '.ifndef $${VARIABLE_IFNDEF_INDIRECT:L}' \
+ 'VARIABLE_IFNDEF_INDIRECT=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-ifndef-indirect.tmp, line 1
+# expect: Parse_PushInput: file variable-ifndef-indirect.tmp, line 1
+
+# The variable name in an '.if' guard must be given directly, it must not
+# contain any '$' expression.
+CASES+= variable-if-indirect
+LINES.variable-if-indirect= \
+ '.if !defined($${VARIABLE_IF_INDIRECT:L})' \
+ 'VARIABLE_IF_INDIRECT=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-if-indirect.tmp, line 1
+# expect: Parse_PushInput: file variable-if-indirect.tmp, line 1
+
+# The variable name in the guard condition must only contain alphanumeric
+# characters and underscores. The place where the guard variable is defined
+# is more flexible, as long as the variable is defined at the point where the
+# file is included the next time.
+CASES+= variable-assign-indirect
+LINES.variable-assign-indirect= \
+ '.ifndef VARIABLE_ASSIGN_INDIRECT' \
+ '$${VARIABLE_ASSIGN_INDIRECT:L}=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-assign-indirect.tmp, line 1
+# expect: Skipping 'variable-assign-indirect.tmp' because 'VARIABLE_ASSIGN_INDIRECT' is defined
+
+# The time at which the guard variable is defined doesn't matter, as long as
+# it is defined at the point where the file is included the next time.
+CASES+= variable-assign-late
+LINES.variable-assign-late= \
+ '.ifndef VARIABLE_ASSIGN_LATE' \
+ 'VARIABLE_ASSIGN_LATE_OTHER=' \
+ 'VARIABLE_ASSIGN_LATE=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-assign-late.tmp, line 1
+# expect: Skipping 'variable-assign-late.tmp' because 'VARIABLE_ASSIGN_LATE' is defined
+
+# The time at which the guard variable is defined doesn't matter, as long as
+# it is defined at the point where the file is included the next time.
+CASES+= variable-assign-nested
+LINES.variable-assign-nested= \
+ '.ifndef VARIABLE_ASSIGN_NESTED' \
+ '. if 1' \
+ '. for i in once' \
+ 'VARIABLE_ASSIGN_NESTED=' \
+ '. endfor' \
+ '. endif' \
+ '.endif'
+# expect: Parse_PushInput: file variable-assign-nested.tmp, line 1
+# expect: Skipping 'variable-assign-nested.tmp' because 'VARIABLE_ASSIGN_NESTED' is defined
+
+# If the guard variable is defined before the file is included for the first
+# time, the file is considered guarded as well. In such a case, the parser
+# skips almost all lines, as they are irrelevant, but the structure of the
+# top-level '.if/.endif' conditional can be determined reliably enough to
+# decide whether the file is guarded.
+CASES+= variable-already-defined
+LINES.variable-already-defined= \
+ '.ifndef VARIABLE_ALREADY_DEFINED' \
+ 'VARIABLE_ALREADY_DEFINED=' \
+ '.endif'
+VARIABLE_ALREADY_DEFINED=
+# expect: Parse_PushInput: file variable-already-defined.tmp, line 1
+# expect: Skipping 'variable-already-defined.tmp' because 'VARIABLE_ALREADY_DEFINED' is defined
+
+# If the guard variable is defined before the file is included the first time,
+# the file is processed but its content is skipped. If that same guard
+# variable is undefined when the file is included the second time, the file is
+# processed as usual.
+CASES+= variable-defined-then-undefined
+LINES.variable-defined-then-undefined= \
+ '.ifndef VARIABLE_DEFINED_THEN_UNDEFINED' \
+ '.endif'
+VARIABLE_DEFINED_THEN_UNDEFINED=
+UNDEF_BETWEEN.variable-defined-then-undefined= \
+ VARIABLE_DEFINED_THEN_UNDEFINED
+# expect: Parse_PushInput: file variable-defined-then-undefined.tmp, line 1
+# expect: Parse_PushInput: file variable-defined-then-undefined.tmp, line 1
+
+# The whole file content must be guarded by a single '.if' conditional, not by
+# several, as each of these conditionals would require its separate guard.
+# This case is not expected to occur in practice, as the two parts would
+# rather be split into separate files.
+CASES+= variable-two-times
+LINES.variable-two-times= \
+ '.ifndef VARIABLE_TWO_TIMES_1' \
+ 'VARIABLE_TWO_TIMES_1=' \
+ '.endif' \
+ '.ifndef VARIABLE_TWO_TIMES_2' \
+ 'VARIABLE_TWO_TIMES_2=' \
+ '.endif'
+# expect: Parse_PushInput: file variable-two-times.tmp, line 1
+# expect: Parse_PushInput: file variable-two-times.tmp, line 1
+
+# When multiple files use the same guard variable name, the optimization of
+# skipping the file affects each of these files.
+#
+# Choosing unique guard names is the responsibility of the makefile authors.
+# A typical pattern of guard variable names is '${PROJECT}_${DIR}_${FILE}_MK'.
+# System-provided files typically start the guard names with '_'.
+CASES+= variable-clash
+LINES.variable-clash= \
+ ${LINES.variable-if}
+# expect: Parse_PushInput: file variable-clash.tmp, line 1
+# expect: Skipping 'variable-clash.tmp' because 'VARIABLE_IF' is defined
+
+# The conditional must come before the assignment, otherwise the conditional
+# is useless, as it always evaluates to false.
+CASES+= variable-swapped
+LINES.variable-swapped= \
+ 'SWAPPED=' \
+ '.ifndef SWAPPED' \
+ '. error' \
+ '.endif'
+# expect: Parse_PushInput: file variable-swapped.tmp, line 1
+# expect: Parse_PushInput: file variable-swapped.tmp, line 1
+
+# If the guard variable is undefined between the first and the second time the
+# file is included, the guarded file is included again.
+CASES+= variable-undef-between
+LINES.variable-undef-between= \
+ '.ifndef VARIABLE_UNDEF_BETWEEN' \
+ 'VARIABLE_UNDEF_BETWEEN=' \
+ '.endif'
+UNDEF_BETWEEN.variable-undef-between= \
+ VARIABLE_UNDEF_BETWEEN
+# expect: Parse_PushInput: file variable-undef-between.tmp, line 1
+# expect: Parse_PushInput: file variable-undef-between.tmp, line 1
+
+# If the guard variable is undefined while the file is included the first
+# time, the guard does not have an effect, and the file is included again.
+CASES+= variable-undef-inside
+LINES.variable-undef-inside= \
+ '.ifndef VARIABLE_UNDEF_INSIDE' \
+ 'VARIABLE_UNDEF_INSIDE=' \
+ '.undef VARIABLE_UNDEF_INSIDE' \
+ '.endif'
+# expect: Parse_PushInput: file variable-undef-inside.tmp, line 1
+# expect: Parse_PushInput: file variable-undef-inside.tmp, line 1
+
+# If the file does not define the guard variable, the guard does not have an
+# effect, and the file is included again.
+CASES+= variable-not-defined
+LINES.variable-not-defined= \
+ '.ifndef VARIABLE_NOT_DEFINED' \
+ '.endif'
+# expect: Parse_PushInput: file variable-not-defined.tmp, line 1
+# expect: Parse_PushInput: file variable-not-defined.tmp, line 1
+
+# The outermost '.if' must not have an '.elif' branch.
+CASES+= elif
+LINES.elif= \
+ '.ifndef ELIF' \
+ 'ELIF=' \
+ '.elif 1' \
+ '.endif'
+# expect: Parse_PushInput: file elif.tmp, line 1
+# expect: Parse_PushInput: file elif.tmp, line 1
+
+# When a file with an '.if/.elif/.endif' conditional at the top level is
+# included, it is never optimized, as one of its branches is taken.
+CASES+= elif-reuse
+LINES.elif-reuse= \
+ '.ifndef ELIF' \
+ 'syntax error' \
+ '.elif 1' \
+ '.endif'
+# expect: Parse_PushInput: file elif-reuse.tmp, line 1
+# expect: Parse_PushInput: file elif-reuse.tmp, line 1
+
+# The outermost '.if' must not have an '.else' branch.
+CASES+= else
+LINES.else= \
+ '.ifndef ELSE' \
+ 'ELSE=' \
+ '.else' \
+ '.endif'
+# expect: Parse_PushInput: file else.tmp, line 1
+# expect: Parse_PushInput: file else.tmp, line 1
+
+# When a file with an '.if/.else/.endif' conditional at the top level is
+# included, it is never optimized, as one of its branches is taken.
+CASES+= else-reuse
+LINES.else-reuse= \
+ '.ifndef ELSE' \
+ 'syntax error' \
+ '.else' \
+ '.endif'
+# expect: Parse_PushInput: file else-reuse.tmp, line 1
+# expect: Parse_PushInput: file else-reuse.tmp, line 1
+
+# The inner '.if' directives may have an '.elif' or '.else', and it doesn't
+# matter which of their branches are taken.
+CASES+= inner-if-elif-else
+LINES.inner-if-elif-else= \
+ '.ifndef INNER_IF_ELIF_ELSE' \
+ 'INNER_IF_ELIF_ELSE=' \
+ '. if 0' \
+ '. elif 0' \
+ '. else' \
+ '. endif' \
+ '. if 0' \
+ '. elif 1' \
+ '. else' \
+ '. endif' \
+ '. if 1' \
+ '. elif 1' \
+ '. else' \
+ '. endif' \
+ '.endif'
+# expect: Parse_PushInput: file inner-if-elif-else.tmp, line 1
+# expect: Skipping 'inner-if-elif-else.tmp' because 'INNER_IF_ELIF_ELSE' is defined
+
+# The guard can also be a target instead of a variable. Using a target as a
+# guard has the benefit that a target cannot be undefined once it is defined.
+# The target should be declared '.NOTMAIN'. Since the target names are
+# usually chosen according to a pattern that doesn't interfere with real
+# target names, they don't need to be declared '.PHONY' as they don't generate
+# filesystem operations.
+CASES+= target
+LINES.target= \
+ '.if !target(__target.tmp__)' \
+ '__target.tmp__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target.tmp, line 1
+# expect: Skipping 'target.tmp' because '__target.tmp__' is defined
+
+# When used for system files, the target name may include '<' and '>', for
+# symmetry with the '.include <sys.mk>' directive. The characters '<' and '>'
+# are ordinary characters.
+CASES+= target-sys
+LINES.target-sys= \
+ '.if !target(__<target-sys.tmp>__)' \
+ '__<target-sys.tmp>__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-sys.tmp, line 1
+# expect: Skipping 'target-sys.tmp' because '__<target-sys.tmp>__' is defined
+
+# The target name may include variable references. These references are
+# expanded as usual. Due to the current implementation, the expressions are
+# evaluated twice: Once for checking whether the condition evaluates to true,
+# and once for determining the guard name. This double evaluation should not
+# matter in practice, as guard expressions are expected to be simple,
+# deterministic and without side effects.
+CASES+= target-indirect
+LINES.target-indirect= \
+ '.if !target($${target-indirect.tmp:L})' \
+ 'target-indirect.tmp: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-indirect.tmp, line 1
+# expect: Skipping 'target-indirect.tmp' because 'target-indirect.tmp' is defined
+
+# A common form of guard target is __${.PARSEFILE}__. This form can only be
+# used if all files using this form have unique basenames. To get a robust
+# pattern based on the same idea, use __${.PARSEDIR}/${.PARSEFILE}__ instead.
+# This form does not work when the basename contains whitespace characters, as
+# it is not possible to define a target with whitespace, not even by cheating.
+CASES+= target-indirect-PARSEFILE
+LINES.target-indirect-PARSEFILE= \
+ '.if !target(__$${.PARSEFILE}__)' \
+ '__$${.PARSEFILE}__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-indirect-PARSEFILE.tmp, line 1
+# expect: Skipping 'target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined
+
+# Two files with different basenames can both use the same syntactic pattern
+# for the target guard name, as the expressions expand to different strings.
+CASES+= target-indirect-PARSEFILE2
+LINES.target-indirect-PARSEFILE2= \
+ '.if !target(__$${.PARSEFILE}__)' \
+ '__$${.PARSEFILE}__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-indirect-PARSEFILE2.tmp, line 1
+# expect: Skipping 'target-indirect-PARSEFILE2.tmp' because '__target-indirect-PARSEFILE2.tmp__' is defined
+
+# Using plain .PARSEFILE without .PARSEDIR leads to name clashes. The include
+# guard is the same as in the test case 'target-indirect-PARSEFILE', as the
+# guard name only contains the basename but not the directory name. So even
+# without defining the guard target, the file is considered guarded.
+CASES+= subdir/target-indirect-PARSEFILE
+LINES.subdir/target-indirect-PARSEFILE= \
+ '.if !target(__$${.PARSEFILE}__)' \
+ '.endif'
+# expect: Parse_PushInput: file subdir/target-indirect-PARSEFILE.tmp, line 1
+# expect: Skipping 'subdir/target-indirect-PARSEFILE.tmp' because '__target-indirect-PARSEFILE.tmp__' is defined
+
+# Another common form of guard target is __${.PARSEDIR}/${.PARSEFILE}__
+# or __${.PARSEDIR:tA}/${.PARSEFILE}__ to be truly unique.
+CASES+= target-indirect-PARSEDIR-PARSEFILE
+LINES.target-indirect-PARSEDIR-PARSEFILE= \
+ '.if !target(__$${.PARSEDIR}/$${.PARSEFILE}__)' \
+ '__$${.PARSEDIR}/$${.PARSEFILE}__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-indirect-PARSEDIR-PARSEFILE.tmp, line 1
+# expect: Skipping 'target-indirect-PARSEDIR-PARSEFILE.tmp' because '__target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined
+# The actual target starts with '__${.OBJDIR}/', see the .rawout file, but the
+# string '${.OBJDIR}/' gets stripped in post processing.
+
+# Using the combination of '.PARSEDIR' and '.PARSEFILE', a file in a
+# subdirectory gets a different guard target name than the previous one.
+CASES+= subdir/target-indirect-PARSEDIR-PARSEFILE
+LINES.subdir/target-indirect-PARSEDIR-PARSEFILE= \
+ '.if !target(__$${.PARSEDIR}/$${.PARSEFILE}__)' \
+ '__$${.PARSEDIR}/$${.PARSEFILE}__: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file subdir/target-indirect-PARSEDIR-PARSEFILE.tmp, line 1
+# expect: Skipping 'subdir/target-indirect-PARSEDIR-PARSEFILE.tmp' because '__subdir/target-indirect-PARSEDIR-PARSEFILE.tmp__' is defined
+# The actual target starts with '__${.OBJDIR}/', see the .rawout file, but the
+# string '${.OBJDIR}/' gets stripped in post processing.
+
+# If the guard target is not defined when including the file the next time,
+# the file is processed again.
+CASES+= target-unguarded
+LINES.target-unguarded= \
+ '.if !target(target-unguarded)' \
+ '.endif'
+# expect: Parse_PushInput: file target-unguarded.tmp, line 1
+# expect: Parse_PushInput: file target-unguarded.tmp, line 1
+
+# The guard condition must consist of only the guard target, nothing else.
+CASES+= target-plus
+LINES.target-plus= \
+ '.if !target(target-plus) && 1' \
+ 'target-plus: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-plus.tmp, line 1
+# expect: Parse_PushInput: file target-plus.tmp, line 1
+
+# If the guard target is defined before the file is included the first time,
+# the file is read once and then considered guarded.
+CASES+= target-already-defined
+LINES.target-already-defined= \
+ '.if !target(target-already-defined)' \
+ 'target-already-defined: .NOTMAIN' \
+ '.endif'
+target-already-defined: .NOTMAIN
+# expect: Parse_PushInput: file target-already-defined.tmp, line 1
+# expect: Skipping 'target-already-defined.tmp' because 'target-already-defined' is defined
+
+# A target name cannot contain the character '!'. In the condition, the '!'
+# is syntactically valid, but in the dependency declaration line, the '!' is
+# interpreted as the '!' dependency operator, no matter whether it occurs at
+# the beginning or in the middle of a target name. Escaping it as '${:U!}'
+# doesn't work, as the whole line is first expanded and then scanned for the
+# dependency operator. Escaping it as '\!' doesn't work either, even though
+# the '\' escapes the '!' from being a dependency operator, but when reading
+# the target name, the '\' is kept, resulting in the target name
+# '\!target-name-exclamation' instead of '!target-name-exclamation'.
+CASES+= target-name-exclamation
+LINES.target-name-exclamation= \
+ '.if !target(!target-name-exclamation)' \
+ '\!target-name-exclamation: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-name-exclamation.tmp, line 1
+# expect: Parse_PushInput: file target-name-exclamation.tmp, line 1
+
+# If the guard target name is enclosed in spaces, it does not have an effect,
+# as that form is not common in practice.
+CASES+= target-name-parenthesized
+LINES.target-name-parenthesized= \
+ '.if !target( target-name-parenthesized )' \
+ 'target-name-parenthesized: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-name-parenthesized.tmp, line 1
+# expect: Parse_PushInput: file target-name-parenthesized.tmp, line 1
+
+# If the guard target condition is enclosed in parentheses, it does not have
+# an effect, as that form is not common in practice.
+CASES+= target-call-parenthesized
+LINES.target-call-parenthesized= \
+ '.if (!target(target-call-parenthesized))' \
+ 'target-call-parenthesized: .NOTMAIN' \
+ '.endif'
+# expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1
+# expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1
+
+# If the '.if' or '.ifndef' directive spans more than a single line, it is
+# still recognized as a guard condition. This case is entirely uncommon, but
+# at the point where the guard condition is checked, line continuations have
+# already been converted to spaces.
+CASES+= multiline
+LINES.multiline= \
+ '.\' \
+ ' ifndef \' \
+ ' MULTILINE' \
+ 'MULTILINE=' \
+ '.endif'
+# expect: Parse_PushInput: file multiline.tmp, line 1
+# expect: Skipping 'multiline.tmp' because 'MULTILINE' is defined
+
+
+# Now run all test cases by including each of the files twice and looking at
+# the debug output. The files that properly guard against multiple inclusion
+# generate a 'Skipping' line, the others repeat the 'Parse_PushInput' line.
+#
+# Some debug output lines are suppressed in the .exp file, see ./Makefile.
+.for i in ${CASES}
+. for fname in $i.tmp
+_:= ${fname:H:N.:@dir@${:!mkdir -p ${dir}!}@}
+_!= printf '%s\n' ${LINES.$i} > ${fname}
+.MAKEFLAGS: -dp
+.include "${.CURDIR}/${fname}"
+.undef ${UNDEF_BETWEEN.$i:U}
+.include "${.CURDIR}/${fname}"
+.MAKEFLAGS: -d0
+_!= rm ${fname}
+_:= ${fname:H:N.:@dir@${:!rmdir ${dir}!}@}
+. endfor
+.endfor
+
+all:
diff --git a/contrib/bmake/unit-tests/directive-include.exp b/contrib/bmake/unit-tests/directive-include.exp
index af56eefb2b88..de94b751b33a 100755
--- a/contrib/bmake/unit-tests/directive-include.exp
+++ b/contrib/bmake/unit-tests/directive-include.exp
@@ -1,8 +1,13 @@
CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
-lhs = "directive-include.mk null", rhs = "directive-include.mk null", op = !=
+Comparing "directive-include.mk null" != "directive-include.mk null"
CondParser_Eval: ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
-lhs = "directive-include.mk null", rhs = "directive-include.mk null", op = !=
-make: "directive-include.mk" line 25: Could not find nonexistent.mk
+Comparing "directive-include.mk null" != "directive-include.mk null"
+make: "directive-include.mk" line 26: Could not find nonexistent.mk
+make: "directive-include.mk" line 49: Could not find "
+make: "directive-include.mk" line 56: Unknown modifier "Z"
+make: "directive-include.mk" line 56: Could not find nonexistent.mk
+make: "directive-include.mk" line 61: Cannot open /nonexistent
+make: "directive-include.mk" line 66: Invalid line 'include'
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-include.mk b/contrib/bmake/unit-tests/directive-include.mk
index d36914b25a63..2517b4be6930 100755
--- a/contrib/bmake/unit-tests/directive-include.mk
+++ b/contrib/bmake/unit-tests/directive-include.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include.mk,v 1.5 2020/11/21 14:59:11 rillig Exp $
+# $NetBSD: directive-include.mk,v 1.13 2023/08/19 10:52:14 rillig Exp $
#
# Tests for the .include directive, which includes another file.
@@ -22,6 +22,7 @@
. error
.endif
+# expect+1: Could not find nonexistent.mk
.include "nonexistent.mk"
.include "/dev/null" # size 0
# including a directory technically succeeds, but shouldn't.
@@ -30,5 +31,59 @@
# As of 2020-11-21, anything after the delimiter '"' is ignored.
.include "/dev/null" and ignore anything in the rest of the line.
+# The filename to be included can contain expressions.
+DEV= null
+.include "/dev/${DEV}"
+
+# Expressions in double quotes or angle quotes are first parsed naively, to
+# find the closing '"'. In a second step, the expressions are expanded. This
+# means that the expressions cannot include the characters '"' or '>'. This
+# restriction is not practically relevant since the expressions inside
+# '.include' directives are typically kept as simple as possible.
+#
+# If the whole line were expanded before parsing, the filename to be included
+# would be empty, and the closing '"' would be in the trailing part of the
+# line, which is ignored as of 2021-12-03.
+DQUOT= "
+# expect+1: Could not find "
+.include "${DQUOT}"
+
+# When the expression in a filename cannot be evaluated, the failing
+# expression is skipped and the file is included nevertheless.
+# FIXME: Add proper error handling, no file must be included here.
+# expect+2: Could not find nonexistent.mk
+# expect+1: Unknown modifier "Z"
+.include "nonexistent${:U123:Z}.mk"
+
+# The traditional include directive is seldom used.
+include /dev/null # comment
+# expect+1: Cannot open /nonexistent
+include /nonexistent # comment
+sinclude /nonexistent # comment
+include ${:U/dev/null} # comment
+include /dev/null /dev/null
+# expect+1: Invalid line 'include'
+include
+
+# XXX: trailing whitespace in diagnostic, missing quotes around filename
+### TODO: expect+1: Could not find
+# The following include directive behaves differently, depending on whether
+# the current file has a slash or is a relative filename. In the first case,
+# make opens the directory of the current file and tries to read from it,
+# resulting in the error message """ line 1: Zero byte read from file".
+# In the second case, the error message is "Could not find ", without quotes
+# or any other indicator for the empty filename at the end of the line.
+#include ${:U}
+
+
+# Since parse.c 1.612 from 2022-01-01 and before parse.c 1.620 from
+# 2022-01-07, including an empty regular file called bmake_malloc(0), which
+# may return a null pointer. On OpenBSD, this led to a segmentation fault in
+# Buf_InitSize, which assumes that bmake_malloc never returns NULL, just like
+# all other places in the code.
+_!= > directive-include-empty
+.include "${.CURDIR}/directive-include-empty"
+_!= rm directive-include-empty
+
+
all:
- @:;
diff --git a/contrib/bmake/unit-tests/directive-info.exp b/contrib/bmake/unit-tests/directive-info.exp
index 2652c191460c..397d9d31ef38 100644
--- a/contrib/bmake/unit-tests/directive-info.exp
+++ b/contrib/bmake/unit-tests/directive-info.exp
@@ -1,15 +1,15 @@
-make: "directive-info.mk" line 11: begin .info tests
-make: "directive-info.mk" line 12: Unknown directive "inf"
-make: "directive-info.mk" line 13: Missing argument for ".info"
-make: "directive-info.mk" line 14: message
-make: "directive-info.mk" line 15: indented message
-make: "directive-info.mk" line 16: Unknown directive "information"
-make: "directive-info.mk" line 17: Unknown directive "information"
-make: "directive-info.mk" line 22: Missing argument for ".info"
-make: "directive-info.mk" line 23: Missing argument for ".info"
-make: "directive-info.mk" line 26: Unknown directive "info-message"
-make: "directive-info.mk" line 27: no-target: no-source
-make: "directive-info.mk" line 36: expect line 30 for multi-line message
+make: "directive-info.mk" line 12: begin .info tests
+make: "directive-info.mk" line 14: Unknown directive "inf"
+make: "directive-info.mk" line 16: Missing argument for ".info"
+make: "directive-info.mk" line 18: message
+make: "directive-info.mk" line 20: indented message
+make: "directive-info.mk" line 22: Unknown directive "information"
+make: "directive-info.mk" line 24: Unknown directive "information"
+make: "directive-info.mk" line 30: Missing argument for ".info"
+make: "directive-info.mk" line 32: Missing argument for ".info"
+make: "directive-info.mk" line 36: Unknown directive "info-message"
+make: "directive-info.mk" line 38: no-target: no-source
+make: "directive-info.mk" line 47: expect line 35 for multi-line message
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-info.mk b/contrib/bmake/unit-tests/directive-info.mk
index 5feea0cde565..ab550555d44f 100644
--- a/contrib/bmake/unit-tests/directive-info.mk
+++ b/contrib/bmake/unit-tests/directive-info.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-info.mk,v 1.8 2020/12/19 22:33:11 rillig Exp $
+# $NetBSD: directive-info.mk,v 1.11 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .info directive.
#
@@ -8,32 +8,42 @@
# TODO: Implementation
+# expect+1: begin .info tests
.info begin .info tests
+# expect+1: Unknown directive "inf"
.inf # misspelled
-.info # "Missing argument"
+# expect+1: Missing argument for ".info"
+.info
+# expect+1: message
.info message
+# expect+1: indented message
.info indented message
+# expect+1: Unknown directive "information"
.information
+# expect+1: Unknown directive "information"
.information message # Accepted before 2020-12-13 01:07:54.
.info.man: # not a message, but possibly a suffix rule
# Even if lines would have trailing whitespace, this would be trimmed by
-# ParseGetLine.
+# ParseRawLine.
+# expect+1: Missing argument for ".info"
.info
+# expect+1: Missing argument for ".info"
.info # comment
.info: message # This is a dependency declaration.
+# expect+1: Unknown directive "info-message"
.info-message # This is an unknown directive.
+# expect+1: no-target: no-source
.info no-target: no-source # This is a .info directive, not a dependency.
# See directive.mk for more tests of this kind.
-# Since at least 2002-01-01, the line number that is used in error messages
-# and the .info directives is the number of completely read lines. For the
-# following multi-line directive, this means that the reported line number is
-# the one of the last line, not the first line.
-.info expect line 30 for\
+# Since at least 2002-01-01 and before parse.c 1.639 from 2022-01-08, the line
+# number that is used in error messages and the .info directives was the
+# number of completely read lines. For the following multi-line directive,
+# this meant that the reported line number was the one of the last line, not
+# of the first line.
+# expect+1: expect line 35 for multi-line message
+.info expect line 35 for\
multi$\
-line message
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/directive-misspellings.exp b/contrib/bmake/unit-tests/directive-misspellings.exp
index e51d8473b305..a00615926740 100644
--- a/contrib/bmake/unit-tests/directive-misspellings.exp
+++ b/contrib/bmake/unit-tests/directive-misspellings.exp
@@ -1,45 +1,45 @@
-make: "directive-misspellings.mk" line 12: Unknown directive "dinclud"
-make: "directive-misspellings.mk" line 14: Unknown directive "dincludx"
-make: "directive-misspellings.mk" line 15: .include filename must be delimited by '"' or '<'
-make: "directive-misspellings.mk" line 17: Unknown directive "erro"
-make: "directive-misspellings.mk" line 18: Unknown directive "errox"
-make: "directive-misspellings.mk" line 22: Unknown directive "expor"
-make: "directive-misspellings.mk" line 24: Unknown directive "exporx"
-make: "directive-misspellings.mk" line 25: Unknown directive "exports"
-make: "directive-misspellings.mk" line 27: Unknown directive "export-en"
-make: "directive-misspellings.mk" line 30: Unknown directive "export-environment"
-make: "directive-misspellings.mk" line 32: Unknown directive "export-litera"
-make: "directive-misspellings.mk" line 34: Unknown directive "export-literax"
-make: "directive-misspellings.mk" line 35: Unknown directive "export-literally"
-make: "directive-misspellings.mk" line 37: Unknown directive "-includ"
-make: "directive-misspellings.mk" line 39: Unknown directive "-includx"
-make: "directive-misspellings.mk" line 40: .include filename must be delimited by '"' or '<'
-make: "directive-misspellings.mk" line 42: Unknown directive "includ"
-make: "directive-misspellings.mk" line 43: Could not find file
-make: "directive-misspellings.mk" line 44: Unknown directive "includx"
-make: "directive-misspellings.mk" line 45: .include filename must be delimited by '"' or '<'
-make: "directive-misspellings.mk" line 47: Unknown directive "inf"
-make: "directive-misspellings.mk" line 48: msg
-make: "directive-misspellings.mk" line 49: Unknown directive "infx"
-make: "directive-misspellings.mk" line 50: Unknown directive "infos"
-make: "directive-misspellings.mk" line 52: Unknown directive "sinclud"
-make: "directive-misspellings.mk" line 54: Unknown directive "sincludx"
-make: "directive-misspellings.mk" line 55: .include filename must be delimited by '"' or '<'
-make: "directive-misspellings.mk" line 57: Unknown directive "unde"
-make: "directive-misspellings.mk" line 59: Unknown directive "undex"
-make: "directive-misspellings.mk" line 60: Unknown directive "undefs"
-make: "directive-misspellings.mk" line 62: Unknown directive "unexpor"
-make: "directive-misspellings.mk" line 64: Unknown directive "unexporx"
-make: "directive-misspellings.mk" line 65: Unknown directive "unexports"
-make: "directive-misspellings.mk" line 67: Unknown directive "unexport-en"
-make: "directive-misspellings.mk" line 69: The directive .unexport-env does not take arguments
-make: "directive-misspellings.mk" line 70: Unknown directive "unexport-enx"
-make: "directive-misspellings.mk" line 71: Unknown directive "unexport-envs"
-make: "directive-misspellings.mk" line 73: Unknown directive "warn"
-make: "directive-misspellings.mk" line 74: Unknown directive "warnin"
-make: "directive-misspellings.mk" line 75: warning: msg
-make: "directive-misspellings.mk" line 76: Unknown directive "warninx"
-make: "directive-misspellings.mk" line 77: Unknown directive "warnings"
+make: "directive-misspellings.mk" line 13: Unknown directive "dinclud"
+make: "directive-misspellings.mk" line 16: Unknown directive "dincludx"
+make: "directive-misspellings.mk" line 18: .include filename must be delimited by '"' or '<'
+make: "directive-misspellings.mk" line 21: Unknown directive "erro"
+make: "directive-misspellings.mk" line 23: Unknown directive "errox"
+make: "directive-misspellings.mk" line 28: Unknown directive "expor"
+make: "directive-misspellings.mk" line 31: Unknown directive "exporx"
+make: "directive-misspellings.mk" line 33: Unknown directive "exports"
+make: "directive-misspellings.mk" line 36: Unknown directive "export-en"
+make: "directive-misspellings.mk" line 40: Unknown directive "export-environment"
+make: "directive-misspellings.mk" line 43: Unknown directive "export-litera"
+make: "directive-misspellings.mk" line 46: Unknown directive "export-literax"
+make: "directive-misspellings.mk" line 48: Unknown directive "export-literally"
+make: "directive-misspellings.mk" line 51: Unknown directive "-includ"
+make: "directive-misspellings.mk" line 54: Unknown directive "-includx"
+make: "directive-misspellings.mk" line 56: .include filename must be delimited by '"' or '<'
+make: "directive-misspellings.mk" line 59: Unknown directive "includ"
+make: "directive-misspellings.mk" line 61: Could not find file
+make: "directive-misspellings.mk" line 63: Unknown directive "includx"
+make: "directive-misspellings.mk" line 65: .include filename must be delimited by '"' or '<'
+make: "directive-misspellings.mk" line 68: Unknown directive "inf"
+make: "directive-misspellings.mk" line 70: msg
+make: "directive-misspellings.mk" line 72: Unknown directive "infx"
+make: "directive-misspellings.mk" line 74: Unknown directive "infos"
+make: "directive-misspellings.mk" line 77: Unknown directive "sinclud"
+make: "directive-misspellings.mk" line 80: Unknown directive "sincludx"
+make: "directive-misspellings.mk" line 82: .include filename must be delimited by '"' or '<'
+make: "directive-misspellings.mk" line 85: Unknown directive "unde"
+make: "directive-misspellings.mk" line 88: Unknown directive "undex"
+make: "directive-misspellings.mk" line 90: Unknown directive "undefs"
+make: "directive-misspellings.mk" line 93: Unknown directive "unexpor"
+make: "directive-misspellings.mk" line 96: Unknown directive "unexporx"
+make: "directive-misspellings.mk" line 98: Unknown directive "unexports"
+make: "directive-misspellings.mk" line 101: Unknown directive "unexport-en"
+make: "directive-misspellings.mk" line 104: The directive .unexport-env does not take arguments
+make: "directive-misspellings.mk" line 106: Unknown directive "unexport-enx"
+make: "directive-misspellings.mk" line 108: Unknown directive "unexport-envs"
+make: "directive-misspellings.mk" line 111: Unknown directive "warn"
+make: "directive-misspellings.mk" line 113: Unknown directive "warnin"
+make: "directive-misspellings.mk" line 115: warning: msg
+make: "directive-misspellings.mk" line 117: Unknown directive "warninx"
+make: "directive-misspellings.mk" line 119: Unknown directive "warnings"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-misspellings.mk b/contrib/bmake/unit-tests/directive-misspellings.mk
index 5f479f03b7f1..0014076d041f 100644
--- a/contrib/bmake/unit-tests/directive-misspellings.mk
+++ b/contrib/bmake/unit-tests/directive-misspellings.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-misspellings.mk,v 1.3 2020/12/13 01:10:22 rillig Exp $
+# $NetBSD: directive-misspellings.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Tests for misspelled directives.
#
@@ -9,71 +9,111 @@
# ".information" were aliases to ".info" since the code for these diagnostic
# directives just skipped any letters following the "error", "warn" or "info".
+# expect+1: Unknown directive "dinclud"
.dinclud "file"
.dinclude "file"
+# expect+1: Unknown directive "dincludx"
.dincludx "file"
+# expect+1: .include filename must be delimited by '"' or '<'
.dincludes "file" # XXX: the 's' is not meant to be a filename
+# expect+1: Unknown directive "erro"
.erro msg
+# expect+1: Unknown directive "errox"
.errox msg
# no .error since that would exit immediately
# no .errors since that would exit immediately, even with the typo
+# expect+1: Unknown directive "expor"
.expor varname
.export varname
+# expect+1: Unknown directive "exporx"
.exporx varname
+# expect+1: Unknown directive "exports"
.exports varname # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "export-en"
.export-en # Accepted before 2020-12-13 01:07:54.
.export-env
.export-env extra argument # XXX: undetected extra argument
+# expect+1: Unknown directive "export-environment"
.export-environment # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "export-litera"
.export-litera varname # Accepted before 2020-12-13 01:07:54.
.export-literal varname
+# expect+1: Unknown directive "export-literax"
.export-literax varname # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "export-literally"
.export-literally varname # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "-includ"
.-includ "file"
.-include "file"
+# expect+1: Unknown directive "-includx"
.-includx "file"
+# expect+1: .include filename must be delimited by '"' or '<'
.-includes "file" # XXX: the 's' is not meant to be a filename
+# expect+1: Unknown directive "includ"
.includ "file"
+# expect+1: Could not find file
.include "file"
+# expect+1: Unknown directive "includx"
.includx "file"
+# expect+1: .include filename must be delimited by '"' or '<'
.includex "file" # XXX: the 's' is not meant to be a filename
+# expect+1: Unknown directive "inf"
.inf msg
+# expect+1: msg
.info msg
+# expect+1: Unknown directive "infx"
.infx msg
+# expect+1: Unknown directive "infos"
.infos msg # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "sinclud"
.sinclud "file"
.sinclude "file"
+# expect+1: Unknown directive "sincludx"
.sincludx "file"
+# expect+1: .include filename must be delimited by '"' or '<'
.sincludes "file" # XXX: the 's' is not meant to be a filename
+# expect+1: Unknown directive "unde"
.unde varname
.undef varname
+# expect+1: Unknown directive "undex"
.undex varname
+# expect+1: Unknown directive "undefs"
.undefs varname # Accepted before 2020-12-13 01:07:54.
+# expect+1: Unknown directive "unexpor"
.unexpor varname
.unexport varname
+# expect+1: Unknown directive "unexporx"
.unexporx varname
+# expect+1: Unknown directive "unexports"
.unexports varname # Accepted before 2020-12-12 18:00:18.
+# expect+1: Unknown directive "unexport-en"
.unexport-en # Accepted before 2020-12-12 18:11:42.
.unexport-env
+# expect+1: The directive .unexport-env does not take arguments
.unexport-env extra argument # Accepted before 2020-12-12 18:00:18.
+# expect+1: Unknown directive "unexport-enx"
.unexport-enx # Accepted before 2020-12-12 18:00:18.
+# expect+1: Unknown directive "unexport-envs"
.unexport-envs # Accepted before 2020-12-12 18:00:18.
+# expect+1: Unknown directive "warn"
.warn msg
+# expect+1: Unknown directive "warnin"
.warnin msg
+# expect+1: warning: msg
.warning msg
+# expect+1: Unknown directive "warninx"
.warninx msg
+# expect+1: Unknown directive "warnings"
.warnings msg # Accepted before 2020-12-13 01:07:54.
-
-all:
diff --git a/contrib/bmake/unit-tests/directive-sinclude.exp b/contrib/bmake/unit-tests/directive-sinclude.exp
index 39a9383953dd..5e8ecd710dc6 100755
--- a/contrib/bmake/unit-tests/directive-sinclude.exp
+++ b/contrib/bmake/unit-tests/directive-sinclude.exp
@@ -1 +1,4 @@
-exit status 0
+make: "directive-include-error.inc" line 1: Invalid line 'syntax error'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/directive-sinclude.mk b/contrib/bmake/unit-tests/directive-sinclude.mk
index 1932e7b3ba13..58912c644a7e 100755
--- a/contrib/bmake/unit-tests/directive-sinclude.mk
+++ b/contrib/bmake/unit-tests/directive-sinclude.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-sinclude.mk,v 1.2 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: directive-sinclude.mk,v 1.5 2023/08/19 10:52:14 rillig Exp $
#
# Tests for the .sinclude directive, which includes another file,
# silently skipping it if it cannot be opened.
@@ -7,7 +7,17 @@
# opened. Parse errors and other errors are handled the same way as in the
# other .include directives.
-# TODO: Implementation
+# No complaint that there is no such file.
+.sinclude "${.CURDIR}/directive-include-nonexistent.inc"
-all:
- @:;
+# No complaint either, even though the operating system error is ENOTDIR, not
+# ENOENT.
+.sinclude "${MAKEFILE}/subdir"
+
+# Errors that are not related to opening the file are still reported.
+# expect: make: "directive-include-error.inc" line 1: Invalid line 'syntax error'
+_!= echo 'syntax error' > directive-include-error.inc
+.sinclude "${.CURDIR}/directive-include-error.inc"
+_!= rm directive-include-error.inc
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive-undef.exp b/contrib/bmake/unit-tests/directive-undef.exp
index 56c871429397..f3957a990e18 100644
--- a/contrib/bmake/unit-tests/directive-undef.exp
+++ b/contrib/bmake/unit-tests/directive-undef.exp
@@ -1,6 +1,6 @@
-make: "directive-undef.mk" line 29: The .undef directive requires an argument
-make: "directive-undef.mk" line 86: Unknown modifier "Z"
-make: "directive-undef.mk" line 103: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore.
+make: "directive-undef.mk" line 30: The .undef directive requires an argument
+make: "directive-undef.mk" line 88: Unknown modifier "Z"
+make: "directive-undef.mk" line 105: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-undef.mk b/contrib/bmake/unit-tests/directive-undef.mk
index 41ea6b5bf8fa..ef047fefe177 100644
--- a/contrib/bmake/unit-tests/directive-undef.mk
+++ b/contrib/bmake/unit-tests/directive-undef.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-undef.mk,v 1.10 2021/02/16 18:02:19 rillig Exp $
+# $NetBSD: directive-undef.mk,v 1.13 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .undef directive.
#
@@ -26,6 +26,7 @@
# to delete the variable with the empty name, which never exists; see
# varname-empty.mk. Since var.c 1.737 from 2020-12-19, .undef complains
# about a missing argument.
+# expect+1: The .undef directive requires an argument
.undef
@@ -43,11 +44,11 @@
3= 3
${:U1 2 3}= one two three
VARNAMES= 1 2 3
-.undef ${VARNAMES} # undefines the variable "1 2 3"
-.if !defined(${:U1 2 3})
+.undef ${VARNAMES} # undefines the variables "1", "2" and "3"
+.if ${${:U1 2 3}} != "one two three" # still there
. error
.endif
-.if ${1:U_}${2:U_}${3:U_} != "___" # these are still defined
+.if ${1:U_}${2:U_}${3:U_} != "___" # these have been undefined
. error
.endif
@@ -83,6 +84,7 @@ ${DOLLAR}= dollar
#
# As of var.c 1.762, this doesn't happen though because the error handling
# in Var_Parse and Var_Subst is not done properly.
+# expect+1: Unknown modifier "Z"
.undef ${VARNAMES:L:Z}
@@ -99,9 +101,48 @@ UT_EXPORTED= exported-value
. error
.endif
.if ${.MAKE.EXPORTED:MUT_EXPORTED}
+# expect+1: warning: UT_EXPORTED is still listed in .MAKE.EXPORTED even though spaceit is not exported anymore.
. warning UT_EXPORTED is still listed in .MAKE.EXPORTED even though $\
it is not exported anymore.
.endif
+# When an exported variable is undefined, the variable is removed both from
+# the global scope as well as from the environment.
+DIRECT= direct
+INDIRECT= in-${DIRECT}
+.export DIRECT INDIRECT
+.if ${DIRECT} != "direct"
+. error
+.endif
+.if ${INDIRECT} != "in-direct"
+. error
+.endif
+
+# Deletes the variables from the global scope and also from the environment.
+# This applies to both variables, even though 'INDIRECT' is not actually
+# exported yet since it refers to another variable.
+.undef DIRECT # Separate '.undef' directives,
+.undef INDIRECT # for backwards compatibility.
+
+.if ${DIRECT:Uundefined} != "undefined"
+. error
+.endif
+.if ${INDIRECT:Uundefined} != "undefined"
+. error
+.endif
+
+
+# Since var.c 1.570 from 2020-10-06 and before var.c 1.1014 from 2022-03-26,
+# make ran into an assertion failure when trying to undefine a variable that
+# was based on an environment variable.
+.if ${ENV_VAR} != "env-value" # see ./Makefile, ENV.directive-undef
+. error
+.endif
+ENV_VAR+= appended # moves the short-lived variable to the
+ # global scope
+.undef ENV_VAR # removes the variable from both the global
+ # scope and from the environment
+
+
all:
diff --git a/contrib/bmake/unit-tests/directive-unexport-env.exp b/contrib/bmake/unit-tests/directive-unexport-env.exp
index 6d653e65fd32..663034cee12c 100644
--- a/contrib/bmake/unit-tests/directive-unexport-env.exp
+++ b/contrib/bmake/unit-tests/directive-unexport-env.exp
@@ -1,16 +1,16 @@
-make: "directive-unexport-env.mk" line 13: Unknown directive "unexport-en"
-make: "directive-unexport-env.mk" line 15: Unknown directive "unexport-environment"
+make: "directive-unexport-env.mk" line 14: Unknown directive "unexport-en"
+make: "directive-unexport-env.mk" line 17: Unknown directive "unexport-environment"
Global: UT_EXPORTED = value
Global: UT_UNEXPORTED = value
Global: .MAKE.EXPORTED = UT_EXPORTED
-make: "directive-unexport-env.mk" line 21: The directive .unexport-env does not take arguments
+make: "directive-unexport-env.mk" line 24: The directive .unexport-env does not take arguments
Var_Parse: ${.MAKE.EXPORTED:O:u} (eval)
Evaluating modifier ${.MAKE.EXPORTED:O} on value "UT_EXPORTED"
Result of ${.MAKE.EXPORTED:O} is "UT_EXPORTED"
Evaluating modifier ${.MAKE.EXPORTED:u} on value "UT_EXPORTED"
Result of ${.MAKE.EXPORTED:u} is "UT_EXPORTED"
Unexporting "UT_EXPORTED"
-Global:delete .MAKE.EXPORTED
+Global: delete .MAKE.EXPORTED
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
make: Fatal errors encountered -- cannot continue
diff --git a/contrib/bmake/unit-tests/directive-unexport-env.mk b/contrib/bmake/unit-tests/directive-unexport-env.mk
index ef58ae732e6d..e56e47865011 100644
--- a/contrib/bmake/unit-tests/directive-unexport-env.mk
+++ b/contrib/bmake/unit-tests/directive-unexport-env.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-unexport-env.mk,v 1.7 2020/12/12 18:11:42 rillig Exp $
+# $NetBSD: directive-unexport-env.mk,v 1.9 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .unexport-env directive.
#
@@ -10,16 +10,18 @@
# TODO: Implementation
+# expect+1: Unknown directive "unexport-en"
.unexport-en # misspelled
.unexport-env # ok
+# expect+1: Unknown directive "unexport-environment"
.unexport-environment # misspelled
.MAKEFLAGS: -dv
UT_EXPORTED= value
UT_UNEXPORTED= value
.export UT_EXPORTED
+# expect+1: The directive .unexport-env does not take arguments
.unexport-env UT_EXPORTED UT_UNEXPORTED
.MAKEFLAGS: -d0
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive-unexport.exp b/contrib/bmake/unit-tests/directive-unexport.exp
index d59fb4713259..b084daf5d147 100644
--- a/contrib/bmake/unit-tests/directive-unexport.exp
+++ b/contrib/bmake/unit-tests/directive-unexport.exp
@@ -1,5 +1,5 @@
-make: "directive-unexport.mk" line 18: UT_A=a UT_B=b UT_C=c
-make: "directive-unexport.mk" line 19: UT_A UT_B UT_C
-make: "directive-unexport.mk" line 27: UT_A=a UT_B=b UT_C=c
-make: "directive-unexport.mk" line 28:
+make: "directive-unexport.mk" line 19: UT_A=a UT_B=b UT_C=c
+make: "directive-unexport.mk" line 21: UT_A UT_B UT_C
+make: "directive-unexport.mk" line 30: UT_A=a UT_B=b UT_C=c
+make: "directive-unexport.mk" line 31:
exit status 0
diff --git a/contrib/bmake/unit-tests/directive-unexport.mk b/contrib/bmake/unit-tests/directive-unexport.mk
index efc103efedf6..e759fe3e35f2 100644
--- a/contrib/bmake/unit-tests/directive-unexport.mk
+++ b/contrib/bmake/unit-tests/directive-unexport.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-unexport.mk,v 1.7 2020/12/13 01:07:54 rillig Exp $
+# $NetBSD: directive-unexport.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the .unexport directive.
#
@@ -15,7 +15,9 @@ UT_C= c
.export UT_A UT_B UT_C
# Show the exported variables and their values.
+# expect+1: UT_A=a UT_B=b UT_C=c
.info ${:!env|sort|grep '^UT_'!}
+# expect+1: UT_A UT_B UT_C
.info ${.MAKE.EXPORTED}
# XXX: Now try to unexport all of them. The variables are still exported
@@ -24,6 +26,7 @@ UT_C= c
*= asterisk
.unexport *
+# expect+1: UT_A=a UT_B=b UT_C=c
.info ${:!env|sort|grep '^UT_'!}
.info ${.MAKE.EXPORTED}
diff --git a/contrib/bmake/unit-tests/directive-warning.exp b/contrib/bmake/unit-tests/directive-warning.exp
index b08b3207392c..6fbeed91df0f 100644
--- a/contrib/bmake/unit-tests/directive-warning.exp
+++ b/contrib/bmake/unit-tests/directive-warning.exp
@@ -1,11 +1,11 @@
-make: "directive-warning.mk" line 11: Unknown directive "warn"
+make: "directive-warning.mk" line 10: Unknown directive "warn"
make: "directive-warning.mk" line 12: Unknown directive "warn"
-make: "directive-warning.mk" line 13: Unknown directive "warnin"
make: "directive-warning.mk" line 14: Unknown directive "warnin"
-make: "directive-warning.mk" line 15: Missing argument for ".warning"
-make: "directive-warning.mk" line 16: warning: message
-make: "directive-warning.mk" line 17: Unknown directive "warnings"
-make: "directive-warning.mk" line 18: Unknown directive "warnings"
+make: "directive-warning.mk" line 16: Unknown directive "warnin"
+make: "directive-warning.mk" line 18: Missing argument for ".warning"
+make: "directive-warning.mk" line 19: warning: message
+make: "directive-warning.mk" line 21: Unknown directive "warnings"
+make: "directive-warning.mk" line 23: Unknown directive "warnings"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive-warning.mk b/contrib/bmake/unit-tests/directive-warning.mk
index d586c9fed170..bf0683f8911f 100644
--- a/contrib/bmake/unit-tests/directive-warning.mk
+++ b/contrib/bmake/unit-tests/directive-warning.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive-warning.mk,v 1.6 2020/12/19 22:33:11 rillig Exp $
+# $NetBSD: directive-warning.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $
#
# Tests for the .warning directive.
#
@@ -6,16 +6,20 @@
# produced the wrong error message "Unknown directive". Since parse.c 1.503
# from 2020-12-19, the correct "Missing argument" is produced.
-# TODO: Implementation
-
+# expect+1: Unknown directive "warn"
.warn # misspelled
+# expect+1: Unknown directive "warn"
.warn message # misspelled
+# expect+1: Unknown directive "warnin"
.warnin # misspelled
+# expect+1: Unknown directive "warnin"
.warnin message # misspelled
+# expect+1: Missing argument for ".warning"
.warning # "Missing argument"
-.warning message # ok
+.warning message # expect+0: warning: message
+# expect+1: Unknown directive "warnings"
.warnings # misspelled
+# expect+1: Unknown directive "warnings"
.warnings messages # Accepted before 2020-12-13 01:07:54.
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/directive.exp b/contrib/bmake/unit-tests/directive.exp
index ee866b7ee2b3..cad8a9bb97e0 100644
--- a/contrib/bmake/unit-tests/directive.exp
+++ b/contrib/bmake/unit-tests/directive.exp
@@ -1,12 +1,14 @@
-make: "directive.mk" line 9: Unknown directive "indented"
make: "directive.mk" line 10: Unknown directive "indented"
-make: "directive.mk" line 11: Unknown directive "indented"
-make: "directive.mk" line 15: Unknown directive "info"
-Global: .info =
+make: "directive.mk" line 12: Unknown directive "indented"
+make: "directive.mk" line 14: Unknown directive "indented"
+make: "directive.mk" line 19: Unknown directive ""
+Global: .info = # (empty)
Global: .info = value
-make: "directive.mk" line 26: := value
+make: "directive.mk" line 31: := value
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
+make: "directive.mk" line 40: Invalid line 'target-without-colon'
+make: "directive.mk" line 43: Invalid line 'target-without-colon another-target'
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/directive.mk b/contrib/bmake/unit-tests/directive.mk
index d463ce4f009a..61938360dfc7 100644
--- a/contrib/bmake/unit-tests/directive.mk
+++ b/contrib/bmake/unit-tests/directive.mk
@@ -1,4 +1,4 @@
-# $NetBSD: directive.mk,v 1.4 2020/11/15 11:57:00 rillig Exp $
+# $NetBSD: directive.mk,v 1.9 2023/11/19 22:32:44 rillig Exp $
#
# Tests for the preprocessing directives, such as .if or .info.
@@ -6,23 +6,28 @@
# Unknown directives are correctly named in the error messages,
# even if they are indented.
+# expect+1: Unknown directive "indented"
.indented none
+# expect+1: Unknown directive "indented"
. indented 2 spaces
+# expect+1: Unknown directive "indented"
. indented tab
-# Directives must be written directly, not indirectly via variable
+# Directives must be written directly, not indirectly via
# expressions.
+# expect+1: Unknown directive ""
.${:Uinfo} directives cannot be indirect
# There is no directive called '.target', therefore this is parsed as a
# dependency declaration with 2 targets and 1 source.
.target target: source
-# This looks ambiguous. It could be either an .info message or a variable
-# assignment. It is a variable assignment.
+# The following lines demonstrate how the parser tells an .info message apart
+# from a variable assignment to ".info", which syntactically is very similar.
.MAKEFLAGS: -dv
-.info:= value
+.info:= value # This is a variable assignment.
.info?= value # This is a variable assignment as well.
+# expect+1: := value
.info := value # The space after the '.info' makes this
# a directive.
.MAKEFLAGS: -d0
@@ -31,5 +36,8 @@
# Not even the space after the '.info' can change anything about this.
.${:Uinfo} : source
-all:
- @:;
+# expect+1: Invalid line 'target-without-colon'
+target-without-colon
+
+# expect+1: Invalid line 'target-without-colon another-target'
+target-without-colon another-target
diff --git a/contrib/bmake/unit-tests/doterror.mk b/contrib/bmake/unit-tests/doterror.mk
index d46fb3581a25..0f3698ad5cf2 100644
--- a/contrib/bmake/unit-tests/doterror.mk
+++ b/contrib/bmake/unit-tests/doterror.mk
@@ -1,4 +1,4 @@
-# $NetBSD: doterror.mk,v 1.2 2020/10/24 08:34:59 rillig Exp $
+# $NetBSD: doterror.mk,v 1.3 2023/06/01 20:56:35 rillig Exp $
.BEGIN:
@@ -17,4 +17,3 @@ happy:
sad:
@echo and now: $@; exit 1
-
diff --git a/contrib/bmake/unit-tests/envfirst.mk b/contrib/bmake/unit-tests/envfirst.mk
deleted file mode 100644
index 60a331a5db64..000000000000
--- a/contrib/bmake/unit-tests/envfirst.mk
+++ /dev/null
@@ -1,44 +0,0 @@
-# $NetBSD: envfirst.mk,v 1.5 2021/02/04 21:42:47 rillig Exp $
-#
-# The -e option makes environment variables stronger than global variables.
-
-.MAKEFLAGS: -e
-
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-# Try to override the variable; this does not have any effect.
-FROM_ENV= value-from-mk
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-# Try to append to the variable; this also doesn't have any effect.
-FROM_ENV+= appended
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-# The default assignment also cannot change the variable.
-FROM_ENV?= default
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-# Neither can the assignment modifiers.
-.if ${FROM_ENV::=from-condition}
-.endif
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-# Even .undef doesn't work since it only affects the global scope,
-# which is independent from the environment variables.
-.undef FROM_ENV
-.if ${FROM_ENV} != value-from-env
-. error ${FROM_ENV}
-.endif
-
-all:
- @: nothing
diff --git a/contrib/bmake/unit-tests/error.exp b/contrib/bmake/unit-tests/error.exp
index 3adc099a4625..e782664498bf 100644
--- a/contrib/bmake/unit-tests/error.exp
+++ b/contrib/bmake/unit-tests/error.exp
@@ -1,6 +1,6 @@
-make: "error.mk" line 6: just FYI
-make: "error.mk" line 7: warning: this could be serious
-make: "error.mk" line 8: this is fatal
+make: "error.mk" line 7: just FYI
+make: "error.mk" line 9: warning: this could be serious
+make: "error.mk" line 11: this is fatal
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/error.mk b/contrib/bmake/unit-tests/error.mk
index 0029b3bc6aa9..2383e60da6fb 100644
--- a/contrib/bmake/unit-tests/error.mk
+++ b/contrib/bmake/unit-tests/error.mk
@@ -1,10 +1,13 @@
-# $NetBSD: error.mk,v 1.3 2020/11/03 17:38:45 rillig Exp $
+# $NetBSD: error.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Demonstrate that the .error directive exits immediately, without
# continuing parsing until the end of the file.
+# expect+1: just FYI
.info just FYI
+# expect+1: warning: this could be serious
.warning this could be serious
+# expect+1: this is fatal
.error this is fatal
.info this is not reached because of the .error above
diff --git a/contrib/bmake/unit-tests/escape.exp b/contrib/bmake/unit-tests/escape.exp
index 6238e27b0191..ff9c8b7cf811 100644
--- a/contrib/bmake/unit-tests/escape.exp
+++ b/contrib/bmake/unit-tests/escape.exp
@@ -1,5 +1,4 @@
var-1bs
-printf "%s=:%s:\n" VAR1BS 111\\111; printf "%s=:%s:\n" VAR1BSa 111\\aaa; printf "%s=:%s:\n" VAR1BSA 111\\aaa; printf "%s=:%s:\n" VAR1BSda 111\\\$\{a\}; printf "%s=:%s:\n" VAR1BSdA 111\\\$\{A\}; printf "%s=:%s:\n" VAR1BSc 111\#\ backslash\ escapes\ comment\ char,\ so\ this\ is\ part\ of\ the\ value; printf "%s=:%s:\n" VAR1BSsc 111\\\ ;
VAR1BS=:111\111:
VAR1BSa=:111\aaa:
VAR1BSA=:111\aaa:
@@ -8,25 +7,22 @@ VAR1BSdA=:111\${A}:
VAR1BSc=:111# backslash escapes comment char, so this is part of the value:
VAR1BSsc=:111\ :
var-2bs
-printf "%s=:%s:\n" VAR2BS 222\\\\222; printf "%s=:%s:\n" VAR2BSa 222\\\\aaa; printf "%s=:%s:\n" VAR2BSA 222\\\\aaa; printf "%s=:%s:\n" VAR2BSda 222\\\\\$\{a\}; printf "%s=:%s:\n" VAR2BSdA 222\\\\\$\{A\}; printf "%s=:%s:\n" VAR2BSc 222\\\\; printf "%s=:%s:\n" VAR2BSsc 222\\\\;
-VAR2BS=:222\\222:
-VAR2BSa=:222\\aaa:
-VAR2BSA=:222\\aaa:
-VAR2BSda=:222\\${a}:
-VAR2BSdA=:222\\${A}:
-VAR2BSc=:222\\:
-VAR2BSsc=:222\\:
-var-1bsnl
-printf "%s=:%s:\n" VAR1BSNL 111\ 111; printf "%s=:%s:\n" VAR1BSNLa 111\ aaa; printf "%s=:%s:\n" VAR1BSNLA 111\ aaa; printf "%s=:%s:\n" VAR1BSNLda 111\ \$\{a\}; printf "%s=:%s:\n" VAR1BSNLdA 111\ \$\{A\}; printf "%s=:%s:\n" VAR1BSNLc 111; printf "%s=:%s:\n" VAR1BSNLsc 111;
-VAR1BSNL=:111 111:
-VAR1BSNLa=:111 aaa:
-VAR1BSNLA=:111 aaa:
-VAR1BSNLda=:111 ${a}:
-VAR1BSNLdA=:111 ${A}:
-VAR1BSNLc=:111:
-VAR1BSNLsc=:111:
+VAR2.BS=:222\\222:
+VAR2.BS.a=:222\\aaa:
+VAR2.BS.A=:222\\aaa:
+VAR2.BS.d.a=:222\\${a}:
+VAR2.BS.d.A=:222\\${A}:
+VAR2.BS.c=:222\\:
+VAR2.BS.s.c=:222\\:
+var-1bs-nl
+VAR1.BS-NL=:111 111:
+VAR1.BS-NL.a=:111 aaa:
+VAR1.BS-NL.A=:111 aaa:
+VAR1.BS-NL.d-a=:111 ${a}:
+VAR1.BS-NL.d-A=:111 ${A}:
+VAR1.BS-NL.c=:111:
+VAR1.BS-NL.s-c=:111:
var-2bsnl
-printf "%s=:%s:\n" VAR2BSNL 222\\\\; printf "%s=:%s:\n" VAR2BSNLa 222\\\\; printf "%s=:%s:\n" VAR2BSNLA 222\\\\; printf "%s=:%s:\n" VAR2BSNLda 222\\\\; printf "%s=:%s:\n" VAR2BSNLdA 222\\\\; printf "%s=:%s:\n" VAR2BSNLc 222\\\\; printf "%s=:%s:\n" VAR2BSNLsc 222\\\\;
VAR2BSNL=:222\\:
VAR2BSNLa=:222\\:
VAR2BSNLA=:222\\:
@@ -35,7 +31,6 @@ VAR2BSNLdA=:222\\:
VAR2BSNLc=:222\\:
VAR2BSNLsc=:222\\:
var-3bsnl
-printf "%s=:%s:\n" VAR3BSNL 333\\\\\ 333=; printf "%s=:%s:\n" VAR3BSNLa 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLA 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLda 333\\\\\ \$\{a\}=; printf "%s=:%s:\n" VAR3BSNLdA 333\\\\\ \$\{A\}=; printf "%s=:%s:\n" VAR3BSNLc 333\\\\; printf "%s=:%s:\n" VAR3BSNLsc 333\\\\;
VAR3BSNL=:333\\ 333=:
VAR3BSNLa=:333\\ aaa=:
VAR3BSNLA=:333\\ aaa=:
@@ -44,7 +39,6 @@ VAR3BSNLdA=:333\\ ${A}=:
VAR3BSNLc=:333\\:
VAR3BSNLsc=:333\\:
var-1bsnl-space
-printf "%s=:%s:\n" VAR1BSNL00 first\ line; printf "%s=:%s:\n" VAR1BSNL0 first\ line\ no\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLs first\ line\ one\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLss first\ line\ two\ spaces\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLt first\ line\ one\ tab\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLtt first\ line\ two\ tabs\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLxx first\ line\ many\ spaces\ and\ tabs\ \[\ \ \ \ \]\ on\ second\ line;
VAR1BSNL00=:first line:
VAR1BSNL0=:first line no space on second line:
VAR1BSNLs=:first line one space on second line:
diff --git a/contrib/bmake/unit-tests/escape.mk b/contrib/bmake/unit-tests/escape.mk
index 8bdd3ad2ab49..a363a19f1946 100644
--- a/contrib/bmake/unit-tests/escape.mk
+++ b/contrib/bmake/unit-tests/escape.mk
@@ -1,4 +1,4 @@
-# $NetBSD: escape.mk,v 1.14 2020/11/03 17:38:45 rillig Exp $
+# $NetBSD: escape.mk,v 1.15 2023/10/19 18:24:33 rillig Exp $
#
# Test backslash escaping.
@@ -53,7 +53,7 @@ should continue the comment. \
__printvars: .USE .MADE
@echo ${.TARGET}
- ${.ALLSRC:@v@ printf "%s=:%s:\n" ${v:Q} ${${v}:Q}; @}
+ @${.ALLSRC:@v@ printf "%s=:%s:\n" ${v:Q} ${${v}:Q}; @}
# Embedded backslash in variable should be taken literally.
#
@@ -83,7 +83,8 @@ all: var-2bs
var-2bs: .PHONY __printvars VAR2BS VAR2BSa VAR2BSA VAR2BSda VAR2BSdA \
VAR2BSc VAR2BSsc
-# Backslash-newline in a variable setting is replaced by a single space.
+# In a variable assignment, when the sequence <backslash><newline> occurs at
+# the end of a physical line, it is replaced with a single space.
#
VAR1BSNL= 111\
111
diff --git a/contrib/bmake/unit-tests/export-env.mk b/contrib/bmake/unit-tests/export-env.mk
index 1605b1a71d61..80653f4bb3c9 100644
--- a/contrib/bmake/unit-tests/export-env.mk
+++ b/contrib/bmake/unit-tests/export-env.mk
@@ -1,4 +1,4 @@
-# $NetBSD: export-env.mk,v 1.4 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: export-env.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
# our normal .export, subsequent changes affect the environment
UT_TEST= this
@@ -21,7 +21,3 @@ UT_LIT= literal ${UT_TEST}
all:
@echo make:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=${$v};@}
@echo env:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=$${$v};@}
-
-
-
-
diff --git a/contrib/bmake/unit-tests/export.exp b/contrib/bmake/unit-tests/export.exp
index 648d1283fb64..5049b0e35b3b 100644
--- a/contrib/bmake/unit-tests/export.exp
+++ b/contrib/bmake/unit-tests/export.exp
@@ -1,5 +1,5 @@
MAKELEVEL=1
-TMPDIR=TMPDIR
+TMPDIR=<tmpdir>
UT_DOLLAR=This is $UT_FU
UT_FOO=foobar is fubar
UT_FU=fubar
diff --git a/contrib/bmake/unit-tests/export.mk b/contrib/bmake/unit-tests/export.mk
index 94e3a862dce1..38670eaaaf48 100644
--- a/contrib/bmake/unit-tests/export.mk
+++ b/contrib/bmake/unit-tests/export.mk
@@ -1,4 +1,4 @@
-# $NetBSD: export.mk,v 1.10 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: export.mk,v 1.12 2022/09/09 18:36:15 sjg Exp $
UT_TEST= export
UT_FOO= foo${BAR}
@@ -40,7 +40,7 @@ BAR= bar is ${UT_FU}
.MAKE.EXPORTED+= UT_ZOO UT_TEST
-FILTER_CMD?= egrep -v '^(MAKEFLAGS|MALLOC_OPTIONS|PATH|PWD|SHLVL|_|&)='
+FILTER_CMD?= ${EGREP} -v '^(MAKEFLAGS|MALLOC_.*|PATH|PWD|SHLVL|_|&)='
all:
@env | ${FILTER_CMD} | sort
diff --git a/contrib/bmake/unit-tests/forloop.exp b/contrib/bmake/unit-tests/forloop.exp
deleted file mode 100644
index 422711b41247..000000000000
--- a/contrib/bmake/unit-tests/forloop.exp
+++ /dev/null
@@ -1,20 +0,0 @@
-make: "forloop.mk" line 14: x=one
-make: "forloop.mk" line 14: x="two and three"
-make: "forloop.mk" line 14: x=four
-make: "forloop.mk" line 14: x="five"
-make: "forloop.mk" line 20: x=-I/this
-make: "forloop.mk" line 20: x=-I"This or that"
-make: "forloop.mk" line 20: x=-Ithat
-make: "forloop.mk" line 20: x="-DTHIS=\"this and that\""
-make: "forloop.mk" line 27: cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-make: "forloop.mk" line 41: newline-item=(a)
-make: "forloop.mk" line 47: a=one b="two and three"
-make: "forloop.mk" line 47: a=four b="five"
-make: "forloop.mk" line 47: a=ONE b="TWO AND THREE"
-make: "forloop.mk" line 47: a=FOUR b="FIVE"
-We expect an error next:
-make: "forloop.mk" line 46: Wrong number of words (9) in .for substitution list with 2 variables
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-OK
-exit status 0
diff --git a/contrib/bmake/unit-tests/forloop.mk b/contrib/bmake/unit-tests/forloop.mk
deleted file mode 100644
index cef05cbe4c61..000000000000
--- a/contrib/bmake/unit-tests/forloop.mk
+++ /dev/null
@@ -1,53 +0,0 @@
-# $NetBSD: forloop.mk,v 1.7 2020/11/03 17:37:57 rillig Exp $
-
-all: for-loop
-
-LIST= one "two and three" four "five"
-
-.if make(for-fail)
-for-fail:
-
-XTRA_LIST= xtra
-.else
-
-. for x in ${LIST}
-. info x=$x
-. endfor
-
-CFL= -I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-cfl=
-. for x in ${CFL}
-. info x=$x
-. if empty(cfl)
-cfl= $x
-. else
-cfl+= $x
-. endif
-. endfor
-. info cfl=${cfl}
-
-. if ${cfl} != ${CFL}
-. error ${.newline}${cfl} != ${.newline}${CFL}
-. endif
-
-. for a b in ${EMPTY}
-. info a=$a b=$b
-. endfor
-
-# Since at least 1993, iteration stops at the first newline.
-# Back then, the .newline variable didn't exist, therefore it was unlikely
-# that a newline ever occurred.
-. for var in a${.newline}b${.newline}c
-. info newline-item=(${var})
-. endfor
-
-.endif # for-fail
-
-.for a b in ${LIST} ${LIST:tu} ${XTRA_LIST}
-. info a=$a b=$b
-.endfor
-
-for-loop:
- @echo We expect an error next:
- @(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} for-fail) && \
- { echo "Oops that should have failed!"; exit 1; } || echo OK
diff --git a/contrib/bmake/unit-tests/forsubst.exp b/contrib/bmake/unit-tests/forsubst.exp
deleted file mode 100644
index 0a98c00aff30..000000000000
--- a/contrib/bmake/unit-tests/forsubst.exp
+++ /dev/null
@@ -1,2 +0,0 @@
-.for with :S;... OK
-exit status 0
diff --git a/contrib/bmake/unit-tests/forsubst.mk b/contrib/bmake/unit-tests/forsubst.mk
deleted file mode 100644
index 9f293ab7f94e..000000000000
--- a/contrib/bmake/unit-tests/forsubst.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-# $NetBSD: forsubst.mk,v 1.3 2020/11/03 17:59:27 rillig Exp $
-#
-# The parser used to break dependency lines at ';' without regard for
-# substitution patterns. Back then, the first ';' was interpreted as the
-# separator between the dependency and its commands. This (perhaps coupled
-# with the new handling of .for variables in ${:U<value>...) caused
-# interesting results for lines like:
-#
-# .for file in ${LIST}
-# for-subst: ${file:S;^;${here}/;g}
-# .endfor
-#
-# See the commit to unit-tests/forsubst (without the .mk) from 2009-10-07.
-
-all: for-subst
-
-here := ${.PARSEDIR}
-# this should not run foul of the parser
-.for file in ${.PARSEFILE}
-for-subst: ${file:S;^;${here}/;g}
- @echo ".for with :S;... OK"
-.endfor
diff --git a/contrib/bmake/unit-tests/hanoi-include.mk b/contrib/bmake/unit-tests/hanoi-include.mk
index 3ad0a751845a..f243af83d1df 100644
--- a/contrib/bmake/unit-tests/hanoi-include.mk
+++ b/contrib/bmake/unit-tests/hanoi-include.mk
@@ -1,41 +1,49 @@
-# $NetBSD: hanoi-include.mk,v 1.1 2020/10/03 17:30:54 rillig Exp $
+# $NetBSD: hanoi-include.mk,v 1.5 2023/10/19 18:24:33 rillig Exp $
#
-# Implements the Towers of Hanoi puzzle, thereby demonstrating a bunch of
+# Implements the Towers of Hanoi puzzle, demonstrating a bunch of more or less
# useful programming techniques:
#
-# * default assignment using the ?= assignment operator
-# * including the same file recursively
-# * extracting the current value of a variable using the .for loop
-# * using shell commands for calculations since make is a text processor
-# * using the :: dependency operator for adding commands to a target
-# * on-the-fly variable assignment expressions using the ::= modifier
+# * default assignment using the ?= assignment operator
+# * including the same file recursively (rather unusual)
+# * extracting the current value of a variable using the .for loop
+# * using the :: dependency operator for adding commands to a target
+# * on-the-fly variable assignment expressions using the ::= modifier
#
# usage:
-# env N=3 make -f hanoi-include.mk
-# endless loop:
-# make -f hanoi-include.mk N=3
+# env N=3 make -r -f hanoi-include.mk
+#
+# Specifying N in the command line instead of in the environment would produce
+# an endless loop, since variables from the command line cannot be overridden
+# by global variables:
+# make -r -f hanoi-include.mk N=3
N?= 5 # Move this number of disks ...
FROM?= A # ... from this stack ...
VIA?= B # ... via this stack ...
TO?= C # ... to this stack.
-.if $N == 1
+# Since make has no built-in arithmetic functions, convert N to a list of
+# words and use the built-in word counting instead.
+.if ${N:[#]} == 1
+N:= count ${:U:${:Urange=$N}} # 'count' + one word for every disk
+.endif
+
+.if ${N:[#]} == 2
. for from to in ${FROM} ${TO}
all::
@echo "Move the upper disk from stack ${from} to stack ${to}."
. endfor
.else
-_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
+_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
. include "${.PARSEDIR}/${.PARSEFILE}"
-_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
+_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${TO}} ${TO::=${TMP}}
. for from to in ${FROM} ${TO}
all::
@echo "Move the upper disk from stack ${from} to stack ${to}."
. endfor
-_:= ${N::!=expr $N - 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
+_:= ${N::=${N:[1..-2]}} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
. include "${.PARSEDIR}/${.PARSEFILE}"
-_:= ${N::!=expr $N + 1} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
+_:= ${N::+=D} ${TMP::=${VIA}} ${VIA::=${FROM}} ${FROM::=${TMP}}
.endif
diff --git a/contrib/bmake/unit-tests/include-main.exp b/contrib/bmake/unit-tests/include-main.exp
index c8a670a1c14a..fcc38247109f 100644
--- a/contrib/bmake/unit-tests/include-main.exp
+++ b/contrib/bmake/unit-tests/include-main.exp
@@ -1,17 +1,17 @@
-make: "include-main.mk" line 14: main-before-ok
-make: "include-main.mk" line 21: main-before-for-ok
-make: "include-sub.mk" line 4: sub-before-ok
-make: "include-sub.mk" line 14: sub-before-for-ok
-ParseReadLine (5): '. info subsub-ok'
-make: "include-subsub.mk" line 5: subsub-ok
- in .for loop from include-sub.mk:31
- in .for loop from include-sub.mk:30
- in .for loop from include-sub.mk:29
- in .include from include-main.mk:27
-ParseReadLine (6): '.MAKEFLAGS: -d0'
+make: "include-main.mk" line 15: main-before-ok
+make: "include-main.mk" line 23: main-before-for-ok
+make: "include-sub.inc" line 4: sub-before-ok
+make: "include-sub.inc" line 14: sub-before-for-ok
+Parsing line 5: . info subsub-ok
+make: "include-subsub.inc" line 5: subsub-ok
+ in .for loop from include-sub.inc:31 with i = include
+ in .for loop from include-sub.inc:30 with i = nested
+ in .for loop from include-sub.inc:29 with i = deeply
+ in include-main.mk:29
+Parsing line 6: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
-make: "include-sub.mk" line 38: sub-after-ok
-make: "include-sub.mk" line 45: sub-after-for-ok
-make: "include-main.mk" line 30: main-after-ok
-make: "include-main.mk" line 37: main-after-for-ok
+make: "include-sub.inc" line 38: sub-after-ok
+make: "include-sub.inc" line 45: sub-after-for-ok
+make: "include-main.mk" line 33: main-after-ok
+make: "include-main.mk" line 41: main-after-for-ok
exit status 0
diff --git a/contrib/bmake/unit-tests/include-main.mk b/contrib/bmake/unit-tests/include-main.mk
index d3f122aef718..373bbdea1721 100644
--- a/contrib/bmake/unit-tests/include-main.mk
+++ b/contrib/bmake/unit-tests/include-main.mk
@@ -1,16 +1,17 @@
-# $NetBSD: include-main.mk,v 1.6 2021/01/22 00:44:55 rillig Exp $
+# $NetBSD: include-main.mk,v 1.9 2023/06/01 20:56:35 rillig Exp $
#
# Until 2020-09-05, the .INCLUDEDFROMFILE magic variable did 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 before 2020-09-05 it was the "filename in which
-# the latest .include happened". See parse.c, function ParseSetIncludeFile.
+# the latest .include happened". See parse.c, function SetParseFile.
#
# Since 2020-09-05, the .INCLUDEDFROMDIR and .INCLUDEDFROMFILE variables
# properly handle nested includes and even .for loops.
.if !defined(.INCLUDEDFROMFILE)
+# expect+1: main-before-ok
. info main-before-ok
.else
. warning main-before-fail(${.INCLUDEDFROMFILE})
@@ -18,15 +19,17 @@
.for i in once
. if !defined(.INCLUDEDFROMFILE)
+# expect+1: main-before-for-ok
. info main-before-for-ok
. else
. warning main-before-for-fail(${.INCLUDEDFROMFILE})
. endif
.endfor
-.include "include-sub.mk"
+.include "include-sub.inc"
.if !defined(.INCLUDEDFROMFILE)
+# expect+1: main-after-ok
. info main-after-ok
.else
. warning main-after-fail(${.INCLUDEDFROMFILE})
@@ -34,6 +37,7 @@
.for i in once
. if !defined(.INCLUDEDFROMFILE)
+# expect+1: main-after-for-ok
. info main-after-for-ok
. else
. warning main-after-for-fail(${.INCLUDEDFROMFILE})
diff --git a/contrib/bmake/unit-tests/include-sub.mk b/contrib/bmake/unit-tests/include-sub.inc
index 0b8dc77398ab..f26f14c9d84f 100644
--- a/contrib/bmake/unit-tests/include-sub.mk
+++ b/contrib/bmake/unit-tests/include-sub.inc
@@ -1,4 +1,4 @@
-# $NetBSD: include-sub.mk,v 1.7 2020/11/02 19:07:09 rillig Exp $
+# $NetBSD: include-sub.inc,v 1.1 2023/01/19 23:26:14 rillig Exp $
.if ${.INCLUDEDFROMFILE} == "include-main.mk"
. info sub-before-ok
@@ -20,16 +20,16 @@
# To see the variable 'includes' in action:
#
# Breakpoints:
-# Parse_File at "Vector_Push(&includes)"
-# ParseMessage at entry
+# Parse_PushInput at "Vector_Push(&includes)"
+# HandleMessage at entry
# Watches:
-# ((const IFile *[10])(*includes.items))
-# *curFile
+# ((const IncludedFile *[10])(*includes.items))
+# *CurFile()
.for i in deeply
. for i in nested
. for i in include
-.include "include-subsub.mk"
+.include "include-subsub.inc"
. endfor
. endfor
.endfor
diff --git a/contrib/bmake/unit-tests/include-subsub.inc b/contrib/bmake/unit-tests/include-subsub.inc
new file mode 100644
index 000000000000..79a6a3770090
--- /dev/null
+++ b/contrib/bmake/unit-tests/include-subsub.inc
@@ -0,0 +1,9 @@
+# $NetBSD: include-subsub.inc,v 1.1 2023/01/19 23:26:14 rillig Exp $
+
+.if ${.INCLUDEDFROMFILE} == "include-sub.inc"
+.MAKEFLAGS: -dp
+. info subsub-ok
+.MAKEFLAGS: -d0
+.else
+. warning subsub-fail(${.INCLUDEDFROMFILE})
+.endif
diff --git a/contrib/bmake/unit-tests/include-subsub.mk b/contrib/bmake/unit-tests/include-subsub.mk
deleted file mode 100644
index 476d75f79556..000000000000
--- a/contrib/bmake/unit-tests/include-subsub.mk
+++ /dev/null
@@ -1,9 +0,0 @@
-# $NetBSD: include-subsub.mk,v 1.4 2021/01/26 23:44:56 rillig Exp $
-
-.if ${.INCLUDEDFROMFILE} == "include-sub.mk"
-.MAKEFLAGS: -dp
-. info subsub-ok
-.MAKEFLAGS: -d0
-.else
-. warning subsub-fail(${.INCLUDEDFROMFILE})
-.endif
diff --git a/contrib/bmake/unit-tests/job-output-null.exp b/contrib/bmake/unit-tests/job-output-null.exp
index af9b4e64dba3..628ec54a1a6b 100644
--- a/contrib/bmake/unit-tests/job-output-null.exp
+++ b/contrib/bmake/unit-tests/job-output-null.exp
@@ -1,4 +1,6 @@
-hello
-hello
-hello world without newline, hello world without newline, hello world without newline.
+1 trailing
+2a trailing
+2b trailing
+2c trailing
+3a without newline, 3b without newline.
exit status 0
diff --git a/contrib/bmake/unit-tests/job-output-null.mk b/contrib/bmake/unit-tests/job-output-null.mk
index 7620bdf6a7ba..04786dba4096 100644
--- a/contrib/bmake/unit-tests/job-output-null.mk
+++ b/contrib/bmake/unit-tests/job-output-null.mk
@@ -1,32 +1,55 @@
-# $NetBSD: job-output-null.mk,v 1.1 2021/04/15 19:02:29 rillig Exp $
+# $NetBSD: job-output-null.mk,v 1.4 2022/09/03 08:03:27 rillig Exp $
#
# Test how null bytes in the output of a command are handled. Make processes
# them using null-terminated strings, which may cut off some of the output.
#
-# As of 2021-04-15, make handles null bytes from the child process
-# inconsistently. It's an edge case though since typically the child
-# processes output text.
+# Before job.c 1.454 from 2022-09-03, make handled null bytes in the output
+# from the child process inconsistently. It's an edge case though since
+# typically the child processes output text.
+
+# Note: The printf commands used in this test must only use a single format
+# string, without parameters. This is because it is implementation-dependent
+# how many times the command 'printf "fmt%s" "" "" ""' calls write(2).
+#
+# NetBSD /bin/sh 1 x write("fmtfmtfmt")
+# Dash 1 x write("fmtfmtfmt")
+# NetBSD /bin/ksh 3 x write("fmt") (via /bin/printf)
+# Bash 5 3 x write("fmt")
+#
+# In the latter case the output may arrive in 1 to 3 parts, depending on the
+# exact timing, which in this test makes a crucial difference since before
+# job.c 1.454 from 2022-09-03, the outcome of the test depended on whether
+# there was a '\n' in each of the blocks from the output. Depending on the
+# exact timing, the output of that test varied, its possible values were '2a',
+# '2a 2b', '2a 2c', '2a 2b 2c'.
.MAKEFLAGS: -j1 # force jobs mode
all: .PHONY
- # The null byte from the command output is kept as-is.
- # See CollectOutput, which looks like it intended to replace these
- # null bytes with simple spaces.
- @printf 'hello\0world%s\n' ''
+ # The null byte from the command output is replaced with a single
+ # space by CollectOutput.
+ @printf '1\0trailing\n'
+ # expect: 1 trailing
# Give the parent process a chance to see the above output, but not
# yet the output from the next printf command.
@sleep 1
- # All null bytes from the command output are kept as-is.
- @printf 'hello\0world%s\n' '' '' '' '' '' ''
+ # Each null byte from the command output is replaced with a single
+ # space.
+ @printf '2a\0trailing\n''2b\0trailing\n''2c\0trailing\n'
+ # expect: 2a trailing
+ # expect: 2b trailing
+ # expect: 2c trailing
@sleep 1
- # The null bytes are replaced with spaces since they are not followed
- # by a newline.
+ # Each null byte from the command output is replaced with a single
+ # space. Because there is no trailing newline in the output, these
+ # null bytes were replaced with spaces even before job.c 1.454 from
+ # 2022-09-03, unlike in the cases above.
#
# The three null bytes in a row test whether this output is
# compressed to a single space like in DebugFailedTarget. It isn't.
- @printf 'hello\0world\0without\0\0\0newline%s' ', ' ', ' '.'
+ @printf '3a\0without\0\0\0newline, 3b\0without\0\0\0newline.'
+ # expect: 3a without newline, 3b without newline.
diff --git a/contrib/bmake/unit-tests/jobs-error-indirect.exp b/contrib/bmake/unit-tests/jobs-error-indirect.exp
index 5c5a3801f4f6..79843a235666 100644
--- a/contrib/bmake/unit-tests/jobs-error-indirect.exp
+++ b/contrib/bmake/unit-tests/jobs-error-indirect.exp
@@ -2,7 +2,7 @@ false
*** [indirect] Error code 1
make: stopped in unit-tests
-1 error
+make: 1 error
make: stopped in unit-tests
exit status 2
diff --git a/contrib/bmake/unit-tests/jobs-error-nested-make.exp b/contrib/bmake/unit-tests/jobs-error-nested-make.exp
index 88c32ab8d1f6..2baf893c6623 100644
--- a/contrib/bmake/unit-tests/jobs-error-nested-make.exp
+++ b/contrib/bmake/unit-tests/jobs-error-nested-make.exp
@@ -3,7 +3,7 @@ false
*** [nested] Error code 1
make: stopped in unit-tests
-1 error
+make: 1 error
make: stopped in unit-tests
diff --git a/contrib/bmake/unit-tests/jobs-error-nested.exp b/contrib/bmake/unit-tests/jobs-error-nested.exp
index f96b5d016777..873613d40d48 100644
--- a/contrib/bmake/unit-tests/jobs-error-nested.exp
+++ b/contrib/bmake/unit-tests/jobs-error-nested.exp
@@ -3,13 +3,13 @@ false
*** [nested] Error code 1
make: stopped in unit-tests
-1 error
+make: 1 error
make: stopped in unit-tests
*** [all] Error code 2
make: stopped in unit-tests
-1 error
+make: 1 error
make: stopped in unit-tests
exit status 2
diff --git a/contrib/bmake/unit-tests/lint.exp b/contrib/bmake/unit-tests/lint.exp
index d7068b5e006a..db2290c040cd 100755
--- a/contrib/bmake/unit-tests/lint.exp
+++ b/contrib/bmake/unit-tests/lint.exp
@@ -1,4 +1,4 @@
-make: In the :@ modifier of "VAR", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: In the :@ modifier of "VAR", the variable name "${:Ubar:S,b,v,}" must not contain a dollar
y@:Q}
xvaluey
exit status 2
diff --git a/contrib/bmake/unit-tests/lint.mk b/contrib/bmake/unit-tests/lint.mk
index 5db417639d0b..431143c644ee 100755
--- a/contrib/bmake/unit-tests/lint.mk
+++ b/contrib/bmake/unit-tests/lint.mk
@@ -1,4 +1,4 @@
-# $NetBSD: lint.mk,v 1.4 2021/01/30 13:50:18 rillig Exp $
+# $NetBSD: lint.mk,v 1.5 2023/11/19 21:47:52 rillig Exp $
#
# Demonstrates stricter checks that are only enabled in lint mode, using the
# option -dL.
@@ -6,7 +6,7 @@
# Before main.c 1.421 from 2020-11-01, make exited successfully even though
# the error message had been issued as PARSE_FATAL. This was because back
# then, make checked for parse errors only after parsing each top-level
-# makefile, in Parse_File. After that, when expanding variable expressions
+# makefile, in Parse_File. After that, when expanding expressions
# in shell commands, the parse errors were not checked again.
# Ouch: as of 2020-08-03, the variable is malformed and parsing stops
diff --git a/contrib/bmake/unit-tests/make-exported.mk b/contrib/bmake/unit-tests/make-exported.mk
index 58cb15183b8d..363ea2733a47 100755
--- a/contrib/bmake/unit-tests/make-exported.mk
+++ b/contrib/bmake/unit-tests/make-exported.mk
@@ -1,4 +1,4 @@
-# $NetBSD: make-exported.mk,v 1.6 2020/10/05 19:27:48 rillig Exp $
+# $NetBSD: make-exported.mk,v 1.7 2022/09/09 18:36:15 sjg Exp $
#
# As of 2020-08-09, the code in Var_Export is shared between the .export
# directive and the .MAKE.EXPORTED variable. This leads to non-obvious
@@ -22,4 +22,4 @@ UT_VAR= ${UNEXPANDED}
.MAKE.EXPORTED= -literal UT_VAR
all:
- @env | sort | egrep '^UT_|make-exported-value' || true
+ @env | sort | ${EGREP} '^UT_|make-exported-value' || true
diff --git a/contrib/bmake/unit-tests/meta-cmd-cmp.exp b/contrib/bmake/unit-tests/meta-cmd-cmp.exp
index bfc52123e3b2..dc63da3b346b 100644
--- a/contrib/bmake/unit-tests/meta-cmd-cmp.exp
+++ b/contrib/bmake/unit-tests/meta-cmd-cmp.exp
@@ -34,4 +34,20 @@ vs
Building .meta-cmd-cmp.cmp2
This line not compared FLAGS=
Skipping meta for .END: .SPECIAL
+filter0:
+Building .meta-cmd-cmp.filter
+Skipping meta for .END: .SPECIAL
+filter1:
+.meta-cmd-cmp.filter.meta: 2: a build command has changed
+@echo ccache cc -c foo.c > .meta-cmd-cmp.filter
+vs
+@echo cc -c foo.c > .meta-cmd-cmp.filter
+Building .meta-cmd-cmp.filter
+Skipping meta for .END: .SPECIAL
+filter2:
+`.meta-cmd-cmp.filter' is up to date.
+Skipping meta for .END: .SPECIAL
+filter3:
+`.meta-cmd-cmp.filter' is up to date.
+Skipping meta for .END: .SPECIAL
exit status 0
diff --git a/contrib/bmake/unit-tests/meta-cmd-cmp.mk b/contrib/bmake/unit-tests/meta-cmd-cmp.mk
index a1c0f7c10063..a410ea0dbd07 100644
--- a/contrib/bmake/unit-tests/meta-cmd-cmp.mk
+++ b/contrib/bmake/unit-tests/meta-cmd-cmp.mk
@@ -1,15 +1,15 @@
-# $NetBSD: meta-cmd-cmp.mk,v 1.2 2020/12/05 22:51:34 sjg Exp $
+# $NetBSD: meta-cmd-cmp.mk,v 1.6 2022/03/02 19:32:15 sjg Exp $
#
# Tests META_MODE command line comparison
#
.MAIN: all
-.MAKE.MODE= meta verbose silent=yes curdirok=yes
+.MAKE.MODE= meta verbose silent=yes curdirok=yes nofilemon
tf:= .${.PARSEFILE:R}
.if ${.TARGETS:Nall} == ""
-all: prep one two change1 change2 post
+all: prep one two change1 change2 filter0 filter1 filter2 filter3 post
CLEANFILES= ${tf}*
@@ -22,6 +22,7 @@ FLAGS?=
FLAGS2?=
tests= ${tf}.cmp ${tf}.nocmp ${tf}.cmp2
+filter_tests= ${tf}.filter
${tf}.cmp:
@echo FLAGS=${FLAGS:Uempty} > $@
@@ -35,7 +36,20 @@ ${tf}.cmp2:
@echo FLAGS2=${FLAGS2:Uempty} > $@
@echo This line not compared FLAGS=${FLAGS:Uempty} ${.OODATE:MNOMETA_CMP}
-# these do the same
+COMPILER_WRAPPERS= ccache distcc icecc
+WRAPPER?= ccache
+.ifdef WITH_CMP_FILTER
+.MAKE.META.CMP_FILTER+= ${COMPILER_WRAPPERS:S,^,N,}
+.endif
+.ifdef WITH_LOCAL_CMP_FILTER
+# local variable
+${tf}.filter: .MAKE.META.CMP_FILTER= ${COMPILER_WRAPPERS:S,^,N,}
+.endif
+
+${tf}.filter:
+ @echo ${WRAPPER} cc -c foo.c > $@
+
+# these do the same
one two: .PHONY
@echo $@:
@${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} ${tests}
@@ -48,5 +62,23 @@ change2: .PHONY
@echo $@:
@${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} FLAGS2=changed ${tests}
+filter0: .PHONY
+ @echo $@:
+ @${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} ${filter_tests}
+
+filter1: .PHONY
+ @echo $@:
+ @${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} WRAPPER= ${filter_tests}
+
+filter2: .PHONY
+ @echo $@:
+ @${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} -DWITH_CMP_FILTER \
+ WRAPPER=distcc ${filter_tests}
+
+filter3: .PHONY
+ @echo $@:
+ @${.MAKE} -dM -r -C ${.CURDIR} -f ${MAKEFILE} -DWITH_LOCAL_CMP_FILTER \
+ WRAPPER=icecc ${filter_tests}
+
# don't let gcov mess up the results
.MAKE.META.IGNORE_PATTERNS+= *.gcda
diff --git a/contrib/bmake/unit-tests/meta-ignore.inc b/contrib/bmake/unit-tests/meta-ignore.inc
new file mode 100644
index 000000000000..ed74f4d79017
--- /dev/null
+++ b/contrib/bmake/unit-tests/meta-ignore.inc
@@ -0,0 +1,63 @@
+# $NetBSD: meta-ignore.inc,v 1.2 2023/02/25 19:30:32 sjg Exp $
+
+# common logic for testing .MAKE.META.IGNORE_*
+
+# we want a directory outside of .OBJDIR to drop a file
+# that our meta file refers to.
+# Note: these tests will not work if TMPDIR is /tmp or /var/tmp
+# or a subdir thereof
+IGNORE:= ${TMPDIR}/ignore
+OBJ:= ${TMPDIR}/obj
+
+# this is always ignored so make sure it isn't used above
+TMPDIR= /tmp/nothanks
+
+all: one two three
+
+setup:
+ @mkdir -p ${IGNORE} ${OBJ}
+ @echo > ${IGNORE}/check
+ @rm -f ${OBJ}/check-ignore
+
+makefile:= ${.INCLUDEDFROMDIR}/${.INCLUDEDFROMFILE}
+TEST:= ${.INCLUDEDFROMFILE:R:C,.*meta-,,:S,-,_,g:tu}
+
+DESC.one= Initialize check-ignore.meta
+DESC.two= Use .MAKE.META.${TEST} - check-ignore is up to date
+DESC.three= Skip .MAKE.META.${TEST} - check-ignore is out of date
+
+# just in case someone runs us with -jN
+.ORDER: one two three
+one two three: .MAKE setup
+ @echo "${DESC.${.TARGET}}"; \
+ ${MAKE} -C ${.CURDIR} -f ${makefile} check-ignore parent=${.TARGET}
+
+.if make(check-ignore)
+.MAKEFLAGS: -dM
+.MAKE.MODE = meta verbose silent=yes
+.OBJDIR: ${OBJ}
+.if ${parent} == "two"
+.if ${TEST} == "IGNORE_PATHS"
+# this is a prefix list - any path that matches
+# one of these prefixes will be ignored
+.MAKE.META.IGNORE_PATHS = ${IGNORE}
+.elif ${TEST} == "IGNORE_PATTERNS"
+# more flexible but more expensive
+# this example is equivalent to M*/ignore/*
+# a match means ignore
+.MAKE.META.IGNORE_PATTERNS = */ignore/*
+.elif ${TEST} == "IGNORE_FILTER"
+# this is the most flexible, but also most expensive
+# if this expands to nothing - ignore the path
+.MAKE.META.IGNORE_FILTER = N${IGNORE}/*
+.endif
+.endif
+
+# : < just reads from ${IGNORE}/check
+# so that our filemon trace will have a reference to it
+# we ensure it is always newer than the target.
+check-ignore: .META .NOPATH
+ @: < ${IGNORE}/check > ${.TARGET}
+ @sleep 1; echo ${.TARGET} > ${IGNORE}/check
+
+.endif
diff --git a/contrib/bmake/unit-tests/moderrs.exp b/contrib/bmake/unit-tests/moderrs.exp
index 9d8bd308c36c..6b41241b6800 100644
--- a/contrib/bmake/unit-tests/moderrs.exp
+++ b/contrib/bmake/unit-tests/moderrs.exp
@@ -9,13 +9,13 @@ make: Unknown modifier "Z"
VAR:Z=before-inner}-after
unclosed-direct:
-want: Unclosed variable expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable"
-make: Unclosed variable expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable"
+want: Unclosed expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable"
+make: Unclosed expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable"
VAR:S,V,v,=Thevariable
unclosed-indirect:
-want: Unclosed variable expression after indirect modifier, expecting '}' for variable "VAR"
-make: Unclosed variable expression after indirect modifier, expecting '}' for variable "VAR"
+want: Unclosed expression after indirect modifier, expecting '}' for variable "VAR"
+make: Unclosed expression after indirect modifier, expecting '}' for variable "VAR"
VAR:S,V,v,=Thevariable
unfinished-indirect:
@@ -33,7 +33,7 @@ make: Unfinished modifier for "UNDEF" ('@' missing)
1 2 3
loop-close:
-make: Unclosed variable expression, expecting '}' for modifier "@var@${var}}...@" of variable "UNDEF" with value "1}... 2}... 3}..."
+make: Unclosed expression, expecting '}' for modifier "@var@${var}}...@" of variable "UNDEF" with value "1}... 2}... 3}..."
1}... 2}... 3}...
1}... 2}... 3}...
@@ -67,7 +67,7 @@ make: Unfinished modifier for "VAR" (',' missing)
4:
make: Unfinished modifier for "VAR" (',' missing)
5:
-make: Unclosed variable expression, expecting '}' for modifier "S,from,to," of variable "VAR" with value "TheVariable"
+make: Unclosed expression, expecting '}' for modifier "S,from,to," of variable "VAR" with value "TheVariable"
6: TheVariable
7: TheVariable
@@ -82,7 +82,7 @@ make: Unfinished modifier for "VAR" (',' missing)
4:
make: Unfinished modifier for "VAR" (',' missing)
5:
-make: Unclosed variable expression, expecting '}' for modifier "C,from,to," of variable "VAR" with value "TheVariable"
+make: Unclosed expression, expecting '}' for modifier "C,from,to," of variable "VAR" with value "TheVariable"
6: TheVariable
7: TheVariable
@@ -124,13 +124,13 @@ make: Unknown modifier "__"
mod-sysv-parse:
make: Unknown modifier "3"
-make: Unclosed variable expression, expecting '}' for modifier "3" of variable "FIB" with value ""
+make: Unclosed expression, expecting '}' for modifier "3" of variable "FIB" with value ""
make: Unknown modifier "3="
-make: Unclosed variable expression, expecting '}' for modifier "3=" of variable "FIB" with value ""
+make: Unclosed expression, expecting '}' for modifier "3=" of variable "FIB" with value ""
make: Unknown modifier "3=x3"
-make: Unclosed variable expression, expecting '}' for modifier "3=x3" of variable "FIB" with value ""
+make: Unclosed expression, expecting '}' for modifier "3=x3" of variable "FIB" with value ""
1 1 2 x3 5 8 1x3 21 34
diff --git a/contrib/bmake/unit-tests/moderrs.mk b/contrib/bmake/unit-tests/moderrs.mk
index ffd920314c5d..bde263af4079 100644
--- a/contrib/bmake/unit-tests/moderrs.mk
+++ b/contrib/bmake/unit-tests/moderrs.mk
@@ -1,4 +1,4 @@
-# $NetBSD: moderrs.mk,v 1.30 2021/06/21 08:28:37 rillig Exp $
+# $NetBSD: moderrs.mk,v 1.31 2023/11/19 22:32:44 rillig Exp $
#
# various modifier error tests
@@ -34,11 +34,11 @@ mod-unknown-indirect: print-header print-footer
@echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after'
unclosed-direct: print-header print-footer
- @echo 'want: Unclosed variable expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"'
+ @echo 'want: Unclosed expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"'
@echo VAR:S,V,v,=${VAR:S,V,v,
unclosed-indirect: print-header print-footer
- @echo 'want: Unclosed variable expression after indirect modifier, expecting $'}$' for variable "VAR"'
+ @echo 'want: Unclosed expression after indirect modifier, expecting $'}$' for variable "VAR"'
@echo VAR:${MOD_TERM},=${VAR:${MOD_S}
unfinished-indirect: print-header print-footer
diff --git a/contrib/bmake/unit-tests/modmatch.exp b/contrib/bmake/unit-tests/modmatch.exp
deleted file mode 100644
index fcaf6c02ed69..000000000000
--- a/contrib/bmake/unit-tests/modmatch.exp
+++ /dev/null
@@ -1,17 +0,0 @@
-LIB=a X_LIBS:M${LIB${LIB:tu}} is "/tmp/liba.a"
-LIB=a X_LIBS:M*/lib${LIB}.a is "/tmp/liba.a"
-LIB=a X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBA.A"
-LIB=b X_LIBS:M${LIB${LIB:tu}} is ""
-LIB=b X_LIBS:M*/lib${LIB}.a is ""
-LIB=b X_LIBS:M*/lib${LIB}.a:tu is ""
-LIB=c X_LIBS:M${LIB${LIB:tu}} is ""
-LIB=c X_LIBS:M*/lib${LIB}.a is ""
-LIB=c X_LIBS:M*/lib${LIB}.a:tu is ""
-LIB=d X_LIBS:M${LIB${LIB:tu}} is "/tmp/libd.a"
-LIB=d X_LIBS:M*/lib${LIB}.a is "/tmp/libd.a"
-LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A"
-LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a"
-LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a"
-LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A"
-Mscanner=OK
-exit status 0
diff --git a/contrib/bmake/unit-tests/modmatch.mk b/contrib/bmake/unit-tests/modmatch.mk
deleted file mode 100644
index 7dcacf09da6d..000000000000
--- a/contrib/bmake/unit-tests/modmatch.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-# $NetBSD: modmatch.mk,v 1.9 2020/10/24 08:50:17 rillig Exp $
-#
-# Tests for the :M and :S modifiers.
-
-X= a b c d e
-
-.for x in $X
-LIB${x:tu}= /tmp/lib$x.a
-.endfor
-
-X_LIBS= ${LIBA} ${LIBD} ${LIBE}
-
-LIB?= a
-
-var= head
-res= no
-.if !empty(var:M${:Uhead\:tail:C/:.*//})
-res= OK
-.endif
-
-all: show-libs
-
-show-libs:
- @for x in $X; do ${.MAKE} -f ${MAKEFILE} show LIB=$$x; done
- @echo "Mscanner=${res}"
-
-show:
- @echo 'LIB=${LIB} X_LIBS:M$${LIB$${LIB:tu}} is "${X_LIBS:M${LIB${LIB:tu}}}"'
- @echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a is "${X_LIBS:M*/lib${LIB}.a}"'
- @echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a:tu is "${X_LIBS:M*/lib${LIB}.a:tu}"'
diff --git a/contrib/bmake/unit-tests/modmisc.exp b/contrib/bmake/unit-tests/modmisc.exp
index 10475e65ee0f..f243511ab491 100644
--- a/contrib/bmake/unit-tests/modmisc.exp
+++ b/contrib/bmake/unit-tests/modmisc.exp
@@ -6,7 +6,6 @@ path='/bin':'/tmp':'/':'/no/such/dir'
path_/usr/xbin=/opt/xbin/
paths=/bin /tmp / /no/such/dir /opt/xbin
PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN
-The answer is 42
S:
C:
@:
diff --git a/contrib/bmake/unit-tests/modmisc.mk b/contrib/bmake/unit-tests/modmisc.mk
index 9ace35c15162..4868abef92f1 100644
--- a/contrib/bmake/unit-tests/modmisc.mk
+++ b/contrib/bmake/unit-tests/modmisc.mk
@@ -1,4 +1,4 @@
-# $NetBSD: modmisc.mk,v 1.52 2020/12/20 19:29:06 rillig Exp $
+# $NetBSD: modmisc.mk,v 1.53 2023/06/16 07:20:45 rillig Exp $
#
# miscellaneous modifier tests
@@ -15,14 +15,10 @@ MOD_HOMES= S,/home/,/homes/,
MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
MOD_SEP= S,:, ,g
-all: modvar modvarloop modsysv emptyvar undefvar
+all: modvar modvarloop emptyvar undefvar
all: mod-quote
all: mod-break-many-words
-# See also sysv.mk.
-modsysv:
- @echo "The answer is ${libfoo.a:L:libfoo.a=42}"
-
# Demonstrates modifiers that are given indirectly from a variable.
modvar:
@echo "path='${path}'"
@@ -60,6 +56,6 @@ undefvar:
mod-quote:
@echo $@: new${.newline:Q}${.newline:Q}line
-# Cover the bmake_realloc in Str_Words.
+# Cover the bmake_realloc in Substring_Words.
mod-break-many-words:
@echo $@: ${UNDEF:U:range=500:[#]}
diff --git a/contrib/bmake/unit-tests/modts.exp b/contrib/bmake/unit-tests/modts.exp
deleted file mode 100644
index 18837016add4..000000000000
--- a/contrib/bmake/unit-tests/modts.exp
+++ /dev/null
@@ -1,14 +0,0 @@
-make: Bad modifier ":tx" for variable "LIST"
-LIST:tx="}"
-make: Bad modifier ":ts\X" for variable "LIST"
-LIST:ts/x:tu="\X:tu}"
-FU_mod-ts="a/b/cool"
-FU_mod-ts:ts:T="cool" == cool?
-B.${AAA:ts}="Baaa" == Baaa?
-:ts :S => aaxBbxaaxbbxaaxbb
-:ts :S space => axa a axc
-:ts :S space :M => axaxaxaxc
-:ts :S => axa a axc
-:ts :S :@ => axa a axc
-:ts :S :@ :M => axaxaxaxc
-exit status 0
diff --git a/contrib/bmake/unit-tests/modts.mk b/contrib/bmake/unit-tests/modts.mk
deleted file mode 100644
index 4776c5818ea5..000000000000
--- a/contrib/bmake/unit-tests/modts.mk
+++ /dev/null
@@ -1,47 +0,0 @@
-# $NetBSD: modts.mk,v 1.8 2020/11/03 18:42:33 rillig Exp $
-
-LIST= one two three four five six
-
-FU_mod-ts= a / b / cool
-
-AAA= a a a
-B.aaa= Baaa
-
-all: mod-ts mod-ts-space
-
-# Use print or printf iff they are builtin.
-# XXX note that this causes problems, when make decides
-# there is no need to use a shell, so avoid where possible.
-.if ${(type print) 2> /dev/null || echo:L:sh:Mbuiltin} != ""
-PRINT= print -r --
-.elif ${(type printf) 2> /dev/null || echo:L:sh:Mbuiltin} != ""
-PRINT= printf '%s\n'
-.else
-PRINT= echo
-.endif
-
-mod-ts:
- @${PRINT} 'LIST:tx="${LIST:tx}"'
- @${PRINT} 'LIST:ts/x:tu="${LIST:ts\X:tu}"'
- @${PRINT} 'FU_$@="${FU_${@:ts}:ts}"'
- @${PRINT} 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?'
- @${PRINT} 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?'
-
-mod-ts-space:
- # After the :ts modifier, the whole string is interpreted as a single
- # word since all spaces have been replaced with x.
- @${PRINT} ':ts :S => '${aa bb aa bb aa bb:L:tsx:S,b,B,:Q}
-
- # The :ts modifier also applies to word separators that are added
- # afterwards.
- @${PRINT} ':ts :S space => '${a ababa c:L:tsx:S,b, ,g:Q}
- @${PRINT} ':ts :S space :M => '${a ababa c:L:tsx:S,b, ,g:M*:Q}
-
- # Not all modifiers behave this way though. Some of them always use
- # a space as word separator instead of the :ts separator.
- # This seems like an oversight during implementation.
- @${PRINT} ':ts :S => '${a ababa c:L:tsx:S,b, ,g:Q}
- @${PRINT} ':ts :S :@ => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:Q}
-
- # A final :M* modifier applies the :ts separator again, though.
- @${PRINT} ':ts :S :@ :M => '${a ababa c:L:tsx:S,b, ,g:@v@${v}@:M*:Q}
diff --git a/contrib/bmake/unit-tests/modword.exp b/contrib/bmake/unit-tests/modword.exp
deleted file mode 100644
index 02e9974c02d6..000000000000
--- a/contrib/bmake/unit-tests/modword.exp
+++ /dev/null
@@ -1,126 +0,0 @@
-make: Bad modifier ":[]" for variable "LIST"
-LIST:[]="" is an error
-LIST:[0]="one two three four five six"
-LIST:[0x0]="one two three four five six"
-LIST:[000]="one two three four five six"
-LIST:[*]="one two three four five six"
-LIST:[@]="one two three four five six"
-LIST:[0]:C/ /,/="one,two three four five six"
-LIST:[0]:C/ /,/g="one,two,three,four,five,six"
-LIST:[0]:C/ /,/1g="one,two,three,four,five,six"
-LIST:[*]:C/ /,/="one,two three four five six"
-LIST:[*]:C/ /,/g="one,two,three,four,five,six"
-LIST:[*]:C/ /,/1g="one,two,three,four,five,six"
-LIST:[@]:C/ /,/="one two three four five six"
-LIST:[@]:C/ /,/g="one two three four five six"
-LIST:[@]:C/ /,/1g="one two three four five six"
-LIST:[@]:[0]:C/ /,/="one,two three four five six"
-LIST:[0]:[@]:C/ /,/="one two three four five six"
-LIST:[@]:[*]:C/ /,/="one,two three four five six"
-LIST:[*]:[@]:C/ /,/="one two three four five six"
-EMPTY=""
-EMPTY:[#]="1" == 1 ?
-ESCAPEDSPACE="\ "
-ESCAPEDSPACE:[#]="1" == 1 ?
-REALLYSPACE=" "
-REALLYSPACE:[#]="1" == 1 ?
-LIST:[#]="6"
-LIST:[0]:[#]="1" == 1 ?
-LIST:[*]:[#]="1" == 1 ?
-LIST:[@]:[#]="6"
-LIST:[1]:[#]="1"
-LIST:[1..3]:[#]="3"
-EMPTY:[1]=""
-ESCAPEDSPACE="\ "
-ESCAPEDSPACE:[1]="\ "
-REALLYSPACE=" "
-REALLYSPACE:[1]="" == "" ?
-REALLYSPACE:[*]:[1]=" " == " " ?
-LIST:[1]="one"
-make: Bad modifier ":[1.]" for variable "LIST"
-LIST:[1.]="" is an error
-make: Bad modifier ":[1]." for variable "LIST"
-LIST:[1].="}" is an error
-LIST:[2]="two"
-LIST:[6]="six"
-LIST:[7]=""
-LIST:[999]=""
-make: Bad modifier ":[-]" for variable "LIST"
-LIST:[-]="" is an error
-make: Bad modifier ":[--]" for variable "LIST"
-LIST:[--]="" is an error
-LIST:[-1]="six"
-LIST:[-2]="five"
-LIST:[-6]="one"
-LIST:[-7]=""
-LIST:[-999]=""
-LONGLIST:[17]="17"
-LONGLIST:[0x11]="17"
-LONGLIST:[021]="17"
-LIST:[0]:[1]="one two three four five six"
-LIST:[*]:[1]="one two three four five six"
-LIST:[@]:[1]="one"
-LIST:[0]:[2]=""
-LIST:[*]:[2]=""
-LIST:[@]:[2]="two"
-LIST:[*]:C/ /,/:[2]=""
-LIST:[*]:C/ /,/:[*]:[2]=""
-LIST:[*]:C/ /,/:[@]:[2]="three"
-LONGLIST:[012..0x12]="10 11 12 13 14 15 16 17 18"
-make: Bad modifier ":[1.]" for variable "LIST"
-LIST:[1.]="" is an error
-make: Bad modifier ":[1..]" for variable "LIST"
-LIST:[1..]="" is an error
-make: Bad modifier ":[1.. ]" for variable "LIST"
-LIST:[1.. ]="" is an error
-LIST:[1..1]="one"
-make: Bad modifier ":[1..1.]" for variable "LIST"
-LIST:[1..1.]="" is an error
-LIST:[1..2]="one two"
-LIST:[2..1]="two one"
-LIST:[3..-2]="three four five"
-LIST:[-4..4]="three four"
-make: Bad modifier ":[0..1]" for variable "LIST"
-LIST:[0..1]="" is an error
-make: Bad modifier ":[-1..0]" for variable "LIST"
-LIST:[-1..0]="" is an error
-LIST:[-1..1]="six five four three two one"
-LIST:[0..0]="one two three four five six"
-LIST:[3..99]="three four five six"
-LIST:[-3..-99]="four three two one"
-LIST:[-99..-3]="one two three four"
-HASH="#" == "#" ?
-LIST:[${HASH}]="6"
-LIST:[${ZERO}]="one two three four five six"
-LIST:[${ZERO}x${ONE}]="one"
-LIST:[${ONE}]="one"
-LIST:[${MINUSONE}]="six"
-LIST:[${STAR}]="one two three four five six"
-LIST:[${AT}]="one two three four five six"
-make: Bad modifier ":[${EMPTY" for variable "LIST"
-LIST:[${EMPTY}]="" is an error
-LIST:[${LONGLIST:[21]:S/2//}]="one"
-LIST:[${LIST:[#]}]="six"
-LIST:[${LIST:[${HASH}]}]="six"
-LIST:[ -1.. +3]="six five four three"
-LIST:S/ /,/="one two three four five six"
-LIST:S/ /,/W="one,two three four five six"
-LIST:S/ /,/gW="one,two,three,four,five,six"
-EMPTY:S/^/,/=","
-EMPTY:S/^/,/W=","
-LIST:C/ /,/="one two three four five six"
-LIST:C/ /,/W="one,two three four five six"
-LIST:C/ /,/gW="one,two,three,four,five,six"
-EMPTY:C/^/,/=","
-EMPTY:C/^/,/W=","
-LIST:tW="one two three four five six"
-LIST:tw="one two three four five six"
-LIST:tW:C/ /,/="one,two three four five six"
-LIST:tW:C/ /,/g="one,two,three,four,five,six"
-LIST:tW:C/ /,/1g="one,two,three,four,five,six"
-LIST:tw:C/ /,/="one two three four five six"
-LIST:tw:C/ /,/g="one two three four five six"
-LIST:tw:C/ /,/1g="one two three four five six"
-LIST:tw:tW:C/ /,/="one,two three four five six"
-LIST:tW:tw:C/ /,/="one two three four five six"
-exit status 0
diff --git a/contrib/bmake/unit-tests/modword.mk b/contrib/bmake/unit-tests/modword.mk
deleted file mode 100644
index 95bb1fec78c3..000000000000
--- a/contrib/bmake/unit-tests/modword.mk
+++ /dev/null
@@ -1,161 +0,0 @@
-# $NetBSD: modword.mk,v 1.6 2021/03/14 16:00:07 rillig Exp $
-#
-# Test behaviour of new :[] modifier
-# TODO: When was this modifier new?
-
-all: mod-squarebrackets mod-S-W mod-C-W mod-tW-tw
-
-LIST= one two three
-LIST+= four five six
-LONGLIST= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-
-EMPTY= # the space should be ignored
-ESCAPEDSPACE= \ # escaped space before the '#'
-REALLYSPACE:= ${EMPTY:C/^/ /W}
-HASH= \#
-AT= @
-STAR= *
-ZERO= 0
-ONE= 1
-MINUSONE= -1
-
-mod-squarebrackets: mod-squarebrackets-0-star-at \
- mod-squarebrackets-hash \
- mod-squarebrackets-n \
- mod-squarebrackets-start-end \
- mod-squarebrackets-nested \
- mod-squarebrackets-space
-
-mod-squarebrackets-0-star-at:
- @echo 'LIST:[]="${LIST:[]}" is an error'
- @echo 'LIST:[0]="${LIST:[0]}"'
- @echo 'LIST:[0x0]="${LIST:[0x0]}"'
- @echo 'LIST:[000]="${LIST:[000]}"'
- @echo 'LIST:[*]="${LIST:[*]}"'
- @echo 'LIST:[@]="${LIST:[@]}"'
- @echo 'LIST:[0]:C/ /,/="${LIST:[0]:C/ /,/}"'
- @echo 'LIST:[0]:C/ /,/g="${LIST:[0]:C/ /,/g}"'
- @echo 'LIST:[0]:C/ /,/1g="${LIST:[0]:C/ /,/1g}"'
- @echo 'LIST:[*]:C/ /,/="${LIST:[*]:C/ /,/}"'
- @echo 'LIST:[*]:C/ /,/g="${LIST:[*]:C/ /,/g}"'
- @echo 'LIST:[*]:C/ /,/1g="${LIST:[*]:C/ /,/1g}"'
- @echo 'LIST:[@]:C/ /,/="${LIST:[@]:C/ /,/}"'
- @echo 'LIST:[@]:C/ /,/g="${LIST:[@]:C/ /,/g}"'
- @echo 'LIST:[@]:C/ /,/1g="${LIST:[@]:C/ /,/1g}"'
- @echo 'LIST:[@]:[0]:C/ /,/="${LIST:[@]:[0]:C/ /,/}"'
- @echo 'LIST:[0]:[@]:C/ /,/="${LIST:[0]:[@]:C/ /,/}"'
- @echo 'LIST:[@]:[*]:C/ /,/="${LIST:[@]:[*]:C/ /,/}"'
- @echo 'LIST:[*]:[@]:C/ /,/="${LIST:[*]:[@]:C/ /,/}"'
-
-mod-squarebrackets-hash:
- @echo 'EMPTY="${EMPTY}"'
- @echo 'EMPTY:[#]="${EMPTY:[#]}" == 1 ?'
- @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
- @echo 'ESCAPEDSPACE:[#]="${ESCAPEDSPACE:[#]}" == 1 ?'
- @echo 'REALLYSPACE="${REALLYSPACE}"'
- @echo 'REALLYSPACE:[#]="${REALLYSPACE:[#]}" == 1 ?'
- @echo 'LIST:[#]="${LIST:[#]}"'
- @echo 'LIST:[0]:[#]="${LIST:[0]:[#]}" == 1 ?'
- @echo 'LIST:[*]:[#]="${LIST:[*]:[#]}" == 1 ?'
- @echo 'LIST:[@]:[#]="${LIST:[@]:[#]}"'
- @echo 'LIST:[1]:[#]="${LIST:[1]:[#]}"'
- @echo 'LIST:[1..3]:[#]="${LIST:[1..3]:[#]}"'
-
-mod-squarebrackets-n:
- @echo 'EMPTY:[1]="${EMPTY:[1]}"'
- @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
- @echo 'ESCAPEDSPACE:[1]="${ESCAPEDSPACE:[1]}"'
- @echo 'REALLYSPACE="${REALLYSPACE}"'
- @echo 'REALLYSPACE:[1]="${REALLYSPACE:[1]}" == "" ?'
- @echo 'REALLYSPACE:[*]:[1]="${REALLYSPACE:[*]:[1]}" == " " ?'
- @echo 'LIST:[1]="${LIST:[1]}"'
- @echo 'LIST:[1.]="${LIST:[1.]}" is an error'
- @echo 'LIST:[1].="${LIST:[1].}" is an error'
- @echo 'LIST:[2]="${LIST:[2]}"'
- @echo 'LIST:[6]="${LIST:[6]}"'
- @echo 'LIST:[7]="${LIST:[7]}"'
- @echo 'LIST:[999]="${LIST:[999]}"'
- @echo 'LIST:[-]="${LIST:[-]}" is an error'
- @echo 'LIST:[--]="${LIST:[--]}" is an error'
- @echo 'LIST:[-1]="${LIST:[-1]}"'
- @echo 'LIST:[-2]="${LIST:[-2]}"'
- @echo 'LIST:[-6]="${LIST:[-6]}"'
- @echo 'LIST:[-7]="${LIST:[-7]}"'
- @echo 'LIST:[-999]="${LIST:[-999]}"'
- @echo 'LONGLIST:[17]="${LONGLIST:[17]}"'
- @echo 'LONGLIST:[0x11]="${LONGLIST:[0x11]}"'
- @echo 'LONGLIST:[021]="${LONGLIST:[021]}"'
- @echo 'LIST:[0]:[1]="${LIST:[0]:[1]}"'
- @echo 'LIST:[*]:[1]="${LIST:[*]:[1]}"'
- @echo 'LIST:[@]:[1]="${LIST:[@]:[1]}"'
- @echo 'LIST:[0]:[2]="${LIST:[0]:[2]}"'
- @echo 'LIST:[*]:[2]="${LIST:[*]:[2]}"'
- @echo 'LIST:[@]:[2]="${LIST:[@]:[2]}"'
- @echo 'LIST:[*]:C/ /,/:[2]="${LIST:[*]:C/ /,/:[2]}"'
- @echo 'LIST:[*]:C/ /,/:[*]:[2]="${LIST:[*]:C/ /,/:[*]:[2]}"'
- @echo 'LIST:[*]:C/ /,/:[@]:[2]="${LIST:[*]:C/ /,/:[@]:[2]}"'
- @echo 'LONGLIST:[012..0x12]="${LONGLIST:[012..0x12]}"'
-
-mod-squarebrackets-start-end:
- @echo 'LIST:[1.]="${LIST:[1.]}" is an error'
- @echo 'LIST:[1..]="${LIST:[1..]}" is an error'
- @echo 'LIST:[1.. ]="${LIST:[1.. ]}" is an error'
- @echo 'LIST:[1..1]="${LIST:[1..1]}"'
- @echo 'LIST:[1..1.]="${LIST:[1..1.]}" is an error'
- @echo 'LIST:[1..2]="${LIST:[1..2]}"'
- @echo 'LIST:[2..1]="${LIST:[2..1]}"'
- @echo 'LIST:[3..-2]="${LIST:[3..-2]}"'
- @echo 'LIST:[-4..4]="${LIST:[-4..4]}"'
- @echo 'LIST:[0..1]="${LIST:[0..1]}" is an error'
- @echo 'LIST:[-1..0]="${LIST:[-1..0]}" is an error'
- @echo 'LIST:[-1..1]="${LIST:[-1..1]}"'
- @echo 'LIST:[0..0]="${LIST:[0..0]}"'
- @echo 'LIST:[3..99]="${LIST:[3..99]}"'
- @echo 'LIST:[-3..-99]="${LIST:[-3..-99]}"'
- @echo 'LIST:[-99..-3]="${LIST:[-99..-3]}"'
-
-mod-squarebrackets-nested:
- @echo 'HASH="${HASH}" == "#" ?'
- @echo 'LIST:[$${HASH}]="${LIST:[${HASH}]}"'
- @echo 'LIST:[$${ZERO}]="${LIST:[${ZERO}]}"'
- @echo 'LIST:[$${ZERO}x$${ONE}]="${LIST:[${ZERO}x${ONE}]}"'
- @echo 'LIST:[$${ONE}]="${LIST:[${ONE}]}"'
- @echo 'LIST:[$${MINUSONE}]="${LIST:[${MINUSONE}]}"'
- @echo 'LIST:[$${STAR}]="${LIST:[${STAR}]}"'
- @echo 'LIST:[$${AT}]="${LIST:[${AT}]}"'
- @echo 'LIST:[$${EMPTY}]="${LIST:[${EMPTY}]}" is an error'
- @echo 'LIST:[$${LONGLIST:[21]:S/2//}]="${LIST:[${LONGLIST:[21]:S/2//}]}"'
- @echo 'LIST:[$${LIST:[#]}]="${LIST:[${LIST:[#]}]}"'
- @echo 'LIST:[$${LIST:[$${HASH}]}]="${LIST:[${LIST:[${HASH}]}]}"'
-
-mod-squarebrackets-space:
- # As of 2020-11-01, it is possible to have spaces before the numbers
- # but not after them. This is an unintended side-effect of using
- # strtol for parsing the numbers.
- @echo 'LIST:[ -1.. +3]="${LIST:[ -1.. +3]}"'
-
-mod-C-W:
- @echo 'LIST:C/ /,/="${LIST:C/ /,/}"'
- @echo 'LIST:C/ /,/W="${LIST:C/ /,/W}"'
- @echo 'LIST:C/ /,/gW="${LIST:C/ /,/gW}"'
- @echo 'EMPTY:C/^/,/="${EMPTY:C/^/,/}"'
- @echo 'EMPTY:C/^/,/W="${EMPTY:C/^/,/W}"'
-
-mod-S-W:
- @echo 'LIST:S/ /,/="${LIST:S/ /,/}"'
- @echo 'LIST:S/ /,/W="${LIST:S/ /,/W}"'
- @echo 'LIST:S/ /,/gW="${LIST:S/ /,/gW}"'
- @echo 'EMPTY:S/^/,/="${EMPTY:S/^/,/}"'
- @echo 'EMPTY:S/^/,/W="${EMPTY:S/^/,/W}"'
-
-mod-tW-tw:
- @echo 'LIST:tW="${LIST:tW}"'
- @echo 'LIST:tw="${LIST:tw}"'
- @echo 'LIST:tW:C/ /,/="${LIST:tW:C/ /,/}"'
- @echo 'LIST:tW:C/ /,/g="${LIST:tW:C/ /,/g}"'
- @echo 'LIST:tW:C/ /,/1g="${LIST:tW:C/ /,/1g}"'
- @echo 'LIST:tw:C/ /,/="${LIST:tw:C/ /,/}"'
- @echo 'LIST:tw:C/ /,/g="${LIST:tw:C/ /,/g}"'
- @echo 'LIST:tw:C/ /,/1g="${LIST:tw:C/ /,/1g}"'
- @echo 'LIST:tw:tW:C/ /,/="${LIST:tw:tW:C/ /,/}"'
- @echo 'LIST:tW:tw:C/ /,/="${LIST:tW:tw:C/ /,/}"'
diff --git a/contrib/bmake/unit-tests/objdir-writable.exp b/contrib/bmake/unit-tests/objdir-writable.exp
index 9c507f647f8c..dc5cd706349e 100644
--- a/contrib/bmake/unit-tests/objdir-writable.exp
+++ b/contrib/bmake/unit-tests/objdir-writable.exp
@@ -1,5 +1,5 @@
-make warning: TMPDIR/roobj: Permission denied.
-/tmp
-TMPDIR/roobj
-TMPDIR/roobj
+make: warning: <tmpdir>/roobj: Permission denied.
+<tmpdir>
+<tmpdir>/roobj
+<tmpdir>/roobj
exit status 0
diff --git a/contrib/bmake/unit-tests/objdir-writable.mk b/contrib/bmake/unit-tests/objdir-writable.mk
index 9fc1c69afb56..03a42c485dbe 100644
--- a/contrib/bmake/unit-tests/objdir-writable.mk
+++ b/contrib/bmake/unit-tests/objdir-writable.mk
@@ -1,8 +1,9 @@
-# $NetBSD: objdir-writable.mk,v 1.4 2020/11/14 07:36:00 sjg Exp $
+# $NetBSD: objdir-writable.mk,v 1.7 2022/02/09 21:24:29 rillig Exp $
# test checking for writable objdir
-RO_OBJDIR?= ${TMPDIR:U/tmp}/roobj
+TMPDIR?= /tmp
+RO_OBJDIR?= ${TMPDIR}/roobj
.if make(do-objdir)
# this should succeed
@@ -13,19 +14,19 @@ do-objdir:
all: no-objdir ro-objdir explicit-objdir
# make it now
-x!= echo; mkdir -p ${RO_OBJDIR}; chmod 555 ${RO_OBJDIR}
+_!= mkdir -p ${RO_OBJDIR}
+_!= chmod 555 ${RO_OBJDIR}
.END: rm-objdir
rm-objdir:
@rmdir ${RO_OBJDIR}
no-objdir:
- @MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C /tmp -V .OBJDIR
+ @MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C ${TMPDIR} -V .OBJDIR
ro-objdir:
- @MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C /tmp -V .OBJDIR MAKE_OBJDIR_CHECK_WRITABLE=no
+ @MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C ${TMPDIR} -V .OBJDIR MAKE_OBJDIR_CHECK_WRITABLE=no
explicit-objdir:
- @MAKEOBJDIR=/tmp ${.MAKE} -r -f ${MAKEFILE:tA} -C /tmp do-objdir -V .OBJDIR
+ @MAKEOBJDIR=${TMPDIR} ${.MAKE} -r -f ${MAKEFILE:tA} -C ${TMPDIR} do-objdir -V .OBJDIR
.endif
-
diff --git a/contrib/bmake/unit-tests/opt-debug-cond.exp b/contrib/bmake/unit-tests/opt-debug-cond.exp
index 39a9383953dd..01f73a4cfad5 100644
--- a/contrib/bmake/unit-tests/opt-debug-cond.exp
+++ b/contrib/bmake/unit-tests/opt-debug-cond.exp
@@ -1 +1,6 @@
+CondParser_Eval: ${:U12345} > ${:U55555}
+Comparing 12345.000000 > 55555.000000
+CondParser_Eval: "string" != "string"
+Comparing "string" != "string"
+CondParser_Eval: "nonempty"
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-debug-cond.mk b/contrib/bmake/unit-tests/opt-debug-cond.mk
index 2b9d1029c7d9..28ad59587789 100644
--- a/contrib/bmake/unit-tests/opt-debug-cond.mk
+++ b/contrib/bmake/unit-tests/opt-debug-cond.mk
@@ -1,10 +1,24 @@
-# $NetBSD: opt-debug-cond.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-cond.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
#
# Tests for the -dc command line option, which adds debug logging for the
# evaluation of conditional expressions, such as in .if directives and
# ${cond:?then:else} expressions.
-# TODO: Implementation
+.MAKEFLAGS: -dc
-all:
- @:;
+# expect: CondParser_Eval: ${:U12345} > ${:U55555}
+# expect: Comparing 12345.000000 > 55555.000000
+.if ${:U12345} > ${:U55555}
+
+# expect: CondParser_Eval: "string" != "string"
+# expect: Comparing "string" != "string"
+.elif "string" != "string"
+
+# expect: CondParser_Eval: "nonempty"
+.elif "nonempty"
+
+.endif
+
+.MAKEFLAGS: -d0
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-debug-curdir.mk b/contrib/bmake/unit-tests/opt-debug-curdir.mk
index 3c37d2988675..ac5750e7e18c 100644
--- a/contrib/bmake/unit-tests/opt-debug-curdir.mk
+++ b/contrib/bmake/unit-tests/opt-debug-curdir.mk
@@ -1,8 +1,8 @@
-# $NetBSD: opt-debug-curdir.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-curdir.mk,v 1.2 2022/01/23 16:09:38 rillig Exp $
#
-# Tests for the -dC command line option, which does nothing, as of 2020-09-05.
+# Tests for the -dC command line option, which does nothing, as of 2020-09-05,
+# as the string "DEBUG(CWD" does not occur in the source code.
-# TODO: Implementation
+.MAKEFLAGS: -dC
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-debug-errors-jobs.exp b/contrib/bmake/unit-tests/opt-debug-errors-jobs.exp
index 25eb2b470b72..c957c7736b32 100644
--- a/contrib/bmake/unit-tests/opt-debug-errors-jobs.exp
+++ b/contrib/bmake/unit-tests/opt-debug-errors-jobs.exp
@@ -24,6 +24,8 @@ line2
*** Failed target: fail-newline
*** Failed commands:
echo 'line1${.newline}line2'; false
+ => echo 'line1
+line2'; false
*** [fail-newline] Error code 1
make: stopped in unit-tests
@@ -45,4 +47,12 @@ word1 word2
*** [fail-multiline-intention] Error code 1
make: stopped in unit-tests
+
+*** Failed target: fail-vars
+*** Failed commands:
+ @${COMPILE_C} ${COMPILE_C_FLAGS}
+ => @false c-compiler flag1 -macro="several words"
+*** [fail-vars] Error code 1
+
+make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/opt-debug-errors-jobs.mk b/contrib/bmake/unit-tests/opt-debug-errors-jobs.mk
index 83b50987a752..007a5f37e08a 100644
--- a/contrib/bmake/unit-tests/opt-debug-errors-jobs.mk
+++ b/contrib/bmake/unit-tests/opt-debug-errors-jobs.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-errors-jobs.mk,v 1.1 2021/04/27 16:20:06 rillig Exp $
+# $NetBSD: opt-debug-errors-jobs.mk,v 1.2 2021/11/27 23:56:11 rillig Exp $
#
# Tests for the -de command line option, which adds debug logging for
# failed commands and targets; since 2021-04-27 also in jobs mode.
@@ -10,6 +10,7 @@ all: fail-escaped-space
all: fail-newline
all: fail-multiline
all: fail-multiline-intention
+all: fail-vars
fail-spaces:
echo '3 spaces'; false
@@ -34,3 +35,14 @@ fail-multiline:
fail-multiline-intention:
echo 'word1' \
'word2'; false
+
+# In makefiles that rely heavily on abstracted variables, it is not possible
+# to determine the actual command from the unexpanded command alone. To help
+# debugging these issues (for example in NetBSD's build.sh), output the
+# expanded command as well whenever it differs from the unexpanded command.
+# Since 2021-11-28.
+COMPILE_C= false c-compiler
+COMPILE_C_DEFS= macro="several words"
+COMPILE_C_FLAGS=flag1 ${COMPILE_C_DEFS:@def@-${def}@}
+fail-vars:
+ @${COMPILE_C} ${COMPILE_C_FLAGS}
diff --git a/contrib/bmake/unit-tests/opt-debug-file.exp b/contrib/bmake/unit-tests/opt-debug-file.exp
index 39a9383953dd..8bdaca612310 100644
--- a/contrib/bmake/unit-tests/opt-debug-file.exp
+++ b/contrib/bmake/unit-tests/opt-debug-file.exp
@@ -1 +1,12 @@
-exit status 0
+make: "opt-debug-file.mk" line 44: This goes to stderr only, once.
+make: "opt-debug-file.mk" line 47: This goes to stderr only, once.
+make: "opt-debug-file.mk" line 50: This goes to stderr, and in addition to the debug log.
+CondParser_Eval: ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1
+Comparing 1.000000 != 1.000000
+make: Missing delimiter for modifier ':S'
+make: Missing delimiter for modifier ':S'
+make: Missing delimiter for modifier ':S'
+CondParser_Eval: ${:!cat opt-debug-file.debuglog!:Mdelimiter:[#]} != 1
+Comparing 1.000000 != 1.000000
+Cannot open debug file "/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog"
+exit status 2
diff --git a/contrib/bmake/unit-tests/opt-debug-file.mk b/contrib/bmake/unit-tests/opt-debug-file.mk
index 1ed477ef3c40..e6c23c4faa1a 100644
--- a/contrib/bmake/unit-tests/opt-debug-file.mk
+++ b/contrib/bmake/unit-tests/opt-debug-file.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-file.mk,v 1.4 2020/10/05 19:27:48 rillig Exp $
+# $NetBSD: opt-debug-file.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the -dF command line option, which redirects the debug log
# to a file instead of writing it to stderr.
@@ -11,14 +11,16 @@
VAR= value ${:Uexpanded}
# Hide the logging output for the remaining actions.
-# As of 2020-10-03, it is not possible to disable debug logging again.
+# Before main.c 1.362 from 2020-10-03, it was not possible to disable debug
+# logging again. Since then, an easier way is the undocumented option '-d0'.
.MAKEFLAGS: -dF/dev/null
# Make sure that the debug logging file contains some logging.
DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!}
# Grmbl. Because of the := operator in the above line, the variable
-# value contains ${:Uexpanded}. This variable expression is expanded
-# upon further processing. Therefore, don't read from untrusted input.
+# value contains ${:Uexpanded}. This expression is expanded
+# when it is used in the condition below. Therefore, be careful when storing
+# untrusted input in variables.
#.MAKEFLAGS: -dc -dFstderr
.if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*}
. error ${DEBUG_OUTPUT}
@@ -26,12 +28,47 @@ DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!}
# To get the unexpanded text that was actually written to the debug log
# file, the content of that log file must not be stored in a variable.
-# XXX: In the :M modifier, a dollar is escaped as '$$', not '\$'.
+#
+# XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'. This
+# escaping scheme unnecessarily differs from all other modifiers.
.if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*}
. error
.endif
-_!= rm opt-debug-file.debuglog
+.MAKEFLAGS: -d0
+
+
+# See Parse_Error.
+.MAKEFLAGS: -dFstdout
+# expect+1: This goes to stderr only, once.
+. info This goes to stderr only, once.
+.MAKEFLAGS: -dFstderr
+# expect+1: This goes to stderr only, once.
+. info This goes to stderr only, once.
+.MAKEFLAGS: -dFopt-debug-file.debuglog
+# expect+1: This goes to stderr, and in addition to the debug log.
+. info This goes to stderr, and in addition to the debug log.
+.MAKEFLAGS: -dFstderr -d0c
+.if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1
+. error
+.endif
+
+
+# See ApplyModifier_Subst, which calls Error.
+.MAKEFLAGS: -dFstdout
+: This goes to stderr only, once. ${:U:S
+.MAKEFLAGS: -dFstderr
+: This goes to stderr only, once. ${:U:S
+.MAKEFLAGS: -dFopt-debug-file.debuglog
+: This goes to stderr, and in addition to the debug log. ${:U:S
+.MAKEFLAGS: -dFstderr -d0c
+.if ${:!cat opt-debug-file.debuglog!:Mdelimiter:[#]} != 1
+. error
+.endif
+
-all:
- @:;
+# If the debug log file cannot be opened, make prints an error message and
+# exits immediately since the debug log file is usually selected from the
+# command line.
+_:= ${:!rm opt-debug-file.debuglog!}
+.MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog
diff --git a/contrib/bmake/unit-tests/opt-debug-for.exp b/contrib/bmake/unit-tests/opt-debug-for.exp
index ea811b9bfcf5..a8f63b85fec3 100644
--- a/contrib/bmake/unit-tests/opt-debug-for.exp
+++ b/contrib/bmake/unit-tests/opt-debug-for.exp
@@ -1,22 +1,22 @@
For: new loop 2
For: end for 2
For: end for 1
-For: loop body:
+For: loop body with outer = a:
. for inner in 1 2
VAR.${:Ua}${inner}= value
. endfor
For: end for 1
-For: loop body:
+For: loop body with inner = 1:
VAR.${:Ua}${:U1}= value
-For: loop body:
+For: loop body with inner = 2:
VAR.${:Ua}${:U2}= value
-For: loop body:
+For: loop body with outer = b:
. for inner in 1 2
VAR.${:Ub}${inner}= value
. endfor
For: end for 1
-For: loop body:
+For: loop body with inner = 1:
VAR.${:Ub}${:U1}= value
-For: loop body:
+For: loop body with inner = 2:
VAR.${:Ub}${:U2}= value
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-debug-graph1.exp b/contrib/bmake/unit-tests/opt-debug-graph1.exp
index 4d4aa0c3faea..26777a671119 100644
--- a/contrib/bmake/unit-tests/opt-debug-graph1.exp
+++ b/contrib/bmake/unit-tests/opt-debug-graph1.exp
@@ -16,11 +16,12 @@
#*** Global Variables:
.ALLTARGETS = all made-target made-target-no-sources made-source unmade-target unmade-sources unmade-silent-source unmade-target-no-sources
.CURDIR = <curdir>
-.INCLUDES =
-.LIBS =
+.INCLUDES = # (empty)
+.LIBS = # (empty)
.MAKE = <details omitted>
.MAKE.DEPENDFILE = <details omitted>
.MAKE.GID = <details omitted>
+.MAKE.JOBS.C = <details omitted>
.MAKE.LEVEL = <details omitted>
.MAKE.MAKEFILES = <details omitted>
.MAKE.MAKEFILE_PREFERENCE = <details omitted>
@@ -29,12 +30,12 @@
.MAKE.PPID = <details omitted>
.MAKE.UID = <details omitted>
.MAKEFLAGS = -r -k -d g1
-.MAKEOVERRIDES =
+.MAKEOVERRIDES = # (empty)
.OBJDIR = <curdir>
.PATH = . <curdir>
-.TARGETS =
+.TARGETS = # (empty)
.newline =
-
+# (ends with space)
MACHINE = <details omitted>
MACHINE_ARCH = <details omitted>
MAKE = <details omitted>
@@ -46,7 +47,6 @@ MFLAGS = -r -k -d g1
# Stats: 0 hits 2 misses 0 near misses 0 losers (0%)
# refs hits directory
# 1 0 <curdir>
-# 1 0 .
#*** Suffixes:
#*** Transformations:
diff --git a/contrib/bmake/unit-tests/opt-debug-graph2.exp b/contrib/bmake/unit-tests/opt-debug-graph2.exp
index 03f02719618e..a5a51413fd38 100644
--- a/contrib/bmake/unit-tests/opt-debug-graph2.exp
+++ b/contrib/bmake/unit-tests/opt-debug-graph2.exp
@@ -50,11 +50,12 @@ all : made-target error-target aborted-target
#*** Global Variables:
.ALLTARGETS = made-target error-target aborted-target aborted-target-dependency all .END
.CURDIR = <curdir>
-.INCLUDES =
-.LIBS =
+.INCLUDES = # (empty)
+.LIBS = # (empty)
.MAKE = <details omitted>
.MAKE.DEPENDFILE = <details omitted>
.MAKE.GID = <details omitted>
+.MAKE.JOBS.C = <details omitted>
.MAKE.LEVEL = <details omitted>
.MAKE.MAKEFILES = <details omitted>
.MAKE.MAKEFILE_PREFERENCE = <details omitted>
@@ -63,12 +64,12 @@ all : made-target error-target aborted-target
.MAKE.PPID = <details omitted>
.MAKE.UID = <details omitted>
.MAKEFLAGS = -r -k -d g2
-.MAKEOVERRIDES =
+.MAKEOVERRIDES = # (empty)
.OBJDIR = <curdir>
.PATH = . <curdir>
.TARGETS = all
.newline =
-
+# (ends with space)
MACHINE = <details omitted>
MACHINE_ARCH = <details omitted>
MAKE = <details omitted>
@@ -81,7 +82,6 @@ MFLAGS = -r -k -d g2
# Stats: 0 hits 4 misses 0 near misses 0 losers (0%)
# refs hits directory
# 1 0 <curdir>
-# 1 0 .
#*** Suffixes:
#*** Transformations:
diff --git a/contrib/bmake/unit-tests/opt-debug-graph3.exp b/contrib/bmake/unit-tests/opt-debug-graph3.exp
index f2966442eb26..ff88400668fa 100644
--- a/contrib/bmake/unit-tests/opt-debug-graph3.exp
+++ b/contrib/bmake/unit-tests/opt-debug-graph3.exp
@@ -50,11 +50,12 @@ all : made-target error-target aborted-target
#*** Global Variables:
.ALLTARGETS = made-target error-target aborted-target aborted-target-dependency all .END
.CURDIR = <curdir>
-.INCLUDES =
-.LIBS =
+.INCLUDES = # (empty)
+.LIBS = # (empty)
.MAKE = <details omitted>
.MAKE.DEPENDFILE = <details omitted>
.MAKE.GID = <details omitted>
+.MAKE.JOBS.C = <details omitted>
.MAKE.LEVEL = <details omitted>
.MAKE.MAKEFILES = <details omitted>
.MAKE.MAKEFILE_PREFERENCE = <details omitted>
@@ -63,12 +64,12 @@ all : made-target error-target aborted-target
.MAKE.PPID = <details omitted>
.MAKE.UID = <details omitted>
.MAKEFLAGS = -r -k -d g3
-.MAKEOVERRIDES =
+.MAKEOVERRIDES = # (empty)
.OBJDIR = <curdir>
.PATH = . <curdir>
.TARGETS = all
.newline =
-
+# (ends with space)
MACHINE = <details omitted>
MACHINE_ARCH = <details omitted>
MAKE = <details omitted>
@@ -81,7 +82,6 @@ MFLAGS = -r -k -d g3
# Stats: 0 hits 4 misses 0 near misses 0 losers (0%)
# refs hits directory
# 1 0 <curdir>
-# 1 0 .
#*** Suffixes:
#*** Transformations:
diff --git a/contrib/bmake/unit-tests/opt-debug-hash.exp b/contrib/bmake/unit-tests/opt-debug-hash.exp
index 39a9383953dd..194b08daa5f2 100644
--- a/contrib/bmake/unit-tests/opt-debug-hash.exp
+++ b/contrib/bmake/unit-tests/opt-debug-hash.exp
@@ -1 +1,6 @@
-exit status 0
+make: "opt-debug-hash.mk" line 12: Missing argument for ".error"
+make: Fatal errors encountered -- cannot continue
+HashTable targets: size=16 numEntries=0 maxchain=0
+HashTable Global variables: size=16 numEntries=<entries> maxchain=3
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/opt-debug-hash.mk b/contrib/bmake/unit-tests/opt-debug-hash.mk
index c8cb99acd261..a1b21e145bf0 100644
--- a/contrib/bmake/unit-tests/opt-debug-hash.mk
+++ b/contrib/bmake/unit-tests/opt-debug-hash.mk
@@ -1,10 +1,12 @@
-# $NetBSD: opt-debug-hash.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-hash.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the -dh command line option, which adds debug logging for
# hash tables. Even more detailed logging is available by compiling
# make with -DDEBUG_HASH_LOOKUP.
-# TODO: Implementation
+.MAKEFLAGS: -dh
-all:
- @:;
+# Force a parse error, to demonstrate the newline character in the diagnostic
+# that had been missing before parse.c 1.655 from 2022-01-22.
+# expect+1: Missing argument for ".error"
+.error
diff --git a/contrib/bmake/unit-tests/opt-debug-jobs.mk b/contrib/bmake/unit-tests/opt-debug-jobs.mk
index f3732df7e25d..ac63bb9c5e86 100644
--- a/contrib/bmake/unit-tests/opt-debug-jobs.mk
+++ b/contrib/bmake/unit-tests/opt-debug-jobs.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-jobs.mk,v 1.5 2020/11/12 21:54:52 rillig Exp $
+# $NetBSD: opt-debug-jobs.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the -dj command line option, which adds debug logging about
# running jobs in multiple shells.
@@ -11,7 +11,7 @@
all:
# Only the actual command is logged.
- # To see the evaluation of the variable expressions, use -dv.
+ # To see the evaluation of the expressions, use -dv.
: ${:Uexpanded} expression
# Undefined variables expand to empty strings.
diff --git a/contrib/bmake/unit-tests/opt-debug-lint.exp b/contrib/bmake/unit-tests/opt-debug-lint.exp
index 05b341b30dae..5a6510bd029a 100644
--- a/contrib/bmake/unit-tests/opt-debug-lint.exp
+++ b/contrib/bmake/unit-tests/opt-debug-lint.exp
@@ -1,8 +1,10 @@
-make: "opt-debug-lint.mk" line 19: Variable "X" is undefined
-make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined
-make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L"
-make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P"
-make: "opt-debug-lint.mk" line 69: Unknown modifier "${"
+make: "opt-debug-lint.mk" line 21: Variable "X" is undefined
+make: "opt-debug-lint.mk" line 21: Malformed conditional ($X)
+make: "opt-debug-lint.mk" line 45: Variable "UNDEF" is undefined
+make: "opt-debug-lint.mk" line 45: Malformed conditional (${UNDEF})
+make: "opt-debug-lint.mk" line 67: Missing delimiter ':' after modifier "L"
+make: "opt-debug-lint.mk" line 67: Missing delimiter ':' after modifier "P"
+make: "opt-debug-lint.mk" line 76: Unknown modifier "${"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/opt-debug-lint.mk b/contrib/bmake/unit-tests/opt-debug-lint.mk
index 155e1a3de3be..042bfd51d35b 100644
--- a/contrib/bmake/unit-tests/opt-debug-lint.mk
+++ b/contrib/bmake/unit-tests/opt-debug-lint.mk
@@ -1,7 +1,7 @@
-# $NetBSD: opt-debug-lint.mk,v 1.14 2021/03/14 10:57:12 rillig Exp $
+# $NetBSD: opt-debug-lint.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the -dL command line option, which runs additional checks
-# to catch common mistakes, such as unclosed variable expressions.
+# to catch common mistakes, such as unclosed expressions.
.MAKEFLAGS: -dL
@@ -16,6 +16,8 @@
#
# See also:
# cond-undef-lint.mk
+# expect+2: Malformed conditional ($X)
+# expect+1: Variable "X" is undefined
.if $X
. error
.endif
@@ -38,6 +40,8 @@
# hoping for the caller to print an error message. This resulted in the
# well-known "Malformed conditional" error message, even though the
# conditional was well-formed and the only error was an undefined variable.
+# expect+2: Malformed conditional (${UNDEF})
+# expect+1: Variable "UNDEF" is undefined
.if ${UNDEF}
. error
.endif
@@ -58,6 +62,8 @@ ${UNDEF}: ${UNDEF}
# Since 2020-10-03, in lint mode the variable modifier must be separated
# by colons. See varparse-mod.mk.
+# expect+2: Missing delimiter ':' after modifier "L"
+# expect+1: Missing delimiter ':' after modifier "P"
.if ${value:LPL} != "value"
. error
.endif
@@ -66,6 +72,7 @@ ${UNDEF}: ${UNDEF}
# variable modifier had to be separated by colons. This was wrong though
# since make always fell back trying to parse the indirect modifier as a
# SysV modifier.
+# expect+1: Unknown modifier "${"
.if ${value:${:UL}PL} != "LPL}" # FIXME: "LPL}" is unexpected here.
. error ${value:${:UL}PL}
.endif
@@ -84,7 +91,7 @@ ${UNDEF}: ${UNDEF}
#
# Before var.c 1.856 from 2021-03-14, this regular expression was then
# compiled even though that was not necessary for checking the syntax at the
-# level of variable expressions. The unexpanded '$' then resulted in a wrong
+# level of expressions. The unexpanded '$' then resulted in a wrong
# error message.
#
# This only happened in lint mode since in default mode the early check for
diff --git a/contrib/bmake/unit-tests/opt-debug-loud.mk b/contrib/bmake/unit-tests/opt-debug-loud.mk
index 38a3c7d7a8e1..5ea1f90ff7be 100644
--- a/contrib/bmake/unit-tests/opt-debug-loud.mk
+++ b/contrib/bmake/unit-tests/opt-debug-loud.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-loud.mk,v 1.4 2020/10/05 19:27:48 rillig Exp $
+# $NetBSD: opt-debug-loud.mk,v 1.5 2023/12/19 19:33:40 rillig Exp $
#
# Tests for the -dl command line option, which prints the commands before
# running them, ignoring the command line option for silent mode (-s) as
@@ -8,8 +8,8 @@
.MAKEFLAGS: -dl -s
.SILENT:
-# The -dl command line option does not affect commands that are run during
-# variable expansion, such as :!cmd! or :sh.
+# The -dl command line option does not affect commands that are run when
+# evaluating expressions and their modifiers, such as :!cmd! or :sh.
.if ${:!echo word!} != "word"
. error
.endif
diff --git a/contrib/bmake/unit-tests/opt-debug-parse.exp b/contrib/bmake/unit-tests/opt-debug-parse.exp
index 39a9383953dd..811c6b45dce5 100644
--- a/contrib/bmake/unit-tests/opt-debug-parse.exp
+++ b/contrib/bmake/unit-tests/opt-debug-parse.exp
@@ -1 +1,26 @@
+Parse_PushInput: .for loop in opt-debug-parse.mk, line 16
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 21: .info trace with multi-line .for loop head
+make: "opt-debug-parse.mk" line 21: trace with multi-line .for loop head
+ in .for loop from opt-debug-parse.mk:16 with var = value
+ParseEOF: returning to file opt-debug-parse.mk, line 23
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 26: .include "/dev/null"
+Parse_PushInput: file /dev/null, line 1
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `null'
+SetFilenameVars: ${.INCLUDEDFROMDIR} = <some-dir> ${.INCLUDEDFROMFILE} = `opt-debug-parse.mk'
+ParseEOF: returning to file opt-debug-parse.mk, line 27
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk'
+Parse_PushInput: .for loop in opt-debug-parse.mk, line 31
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 34: .info trace
+make: "opt-debug-parse.mk" line 34: trace
+ in .for loop from opt-debug-parse.mk:31 with a = 1, b = 2, c = 3
+Parsing line 34: .info trace
+make: "opt-debug-parse.mk" line 34: trace
+ in .for loop from opt-debug-parse.mk:31 with a = 4, b = 5, c = 6
+ParseEOF: returning to file opt-debug-parse.mk, line 36
+SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 38: .MAKEFLAGS: -d0
+ParseDependency(.MAKEFLAGS: -d0)
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-debug-parse.mk b/contrib/bmake/unit-tests/opt-debug-parse.mk
index 3427b68beb96..347537015b52 100644
--- a/contrib/bmake/unit-tests/opt-debug-parse.mk
+++ b/contrib/bmake/unit-tests/opt-debug-parse.mk
@@ -1,9 +1,40 @@
-# $NetBSD: opt-debug-parse.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-parse.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the -dp command line option, which adds debug logging about
# makefile parsing.
+.MAKEFLAGS: -dp
+
# TODO: Implementation
-all:
- @:;
+# Before parse.c 1.639 from 2022-01-08, PrintStackTrace and other diagnostics
+# printed a wrong line number, using the last line before the loop body, while
+# it should rather be the line number where the .for loop starts.
+#
+# Before parse.c 1.643 from 2022-01-08, PrintStackTrace tried to be too clever
+# by merging stack trace entries, printing confusing line numbers as a result.
+.for \
+ var \
+ in \
+ value
+# expect+1: trace with multi-line .for loop head
+.info trace with multi-line .for loop head
+.endfor
+
+# Before parse.c 1.641 from 2022-01-08, the debug log said it returned to
+# the line of the '.include' instead of the line following it.
+.include "/dev/null"
+
+
+# In .for loops with multiple variables, the variable details are included in
+# the stack trace, just as with a single variable.
+.for a b c in 1 2 3 ${:U4 5 6}
+# expect+2: trace
+# expect+1: trace
+.info trace
+.endfor
+
+
+.MAKEFLAGS: -d0
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-debug-var.exp b/contrib/bmake/unit-tests/opt-debug-var.exp
index 39a9383953dd..5e9d10c671f1 100644
--- a/contrib/bmake/unit-tests/opt-debug-var.exp
+++ b/contrib/bmake/unit-tests/opt-debug-var.exp
@@ -1 +1,7 @@
+Global: ASSIGNED = value
+Global: SUBST = # (empty)
+Global: SUBST = value
+Var_Parse: y(ASSIGNED) (eval)
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-debug-var.mk b/contrib/bmake/unit-tests/opt-debug-var.mk
index 4d0ef9447324..9017f18e81d3 100644
--- a/contrib/bmake/unit-tests/opt-debug-var.mk
+++ b/contrib/bmake/unit-tests/opt-debug-var.mk
@@ -1,9 +1,31 @@
-# $NetBSD: opt-debug-var.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-var.mk,v 1.3 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the -dv command line option, which adds debug logging about
# variable assignment and evaluation.
-# TODO: Implementation
+.MAKEFLAGS: -dv
-all:
- @:;
+# expect: Global: ASSIGNED = value
+ASSIGNED= value
+
+# TODO: Explain why the empty assignment "Global: SUBST = " is needed.
+# expect: Global: SUBST = value
+SUBST:= value
+
+.if defined(ASSIGNED)
+.endif
+
+# The usual form of expressions is ${VAR}. The form $(VAR) is used
+# less often as it can be visually confused with the shell construct for
+# capturing the output of a subshell, which looks the same.
+#
+# In conditions, a call to the function 'empty' is syntactically similar to
+# the form $(VAR), only that the initial '$' is the 'y' of 'empty'.
+#
+# expect: Var_Parse: y(ASSIGNED) (eval)
+.if !empty(ASSIGNED)
+.endif
+
+.MAKEFLAGS: -d0
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-debug-x-trace.exp b/contrib/bmake/unit-tests/opt-debug-x-trace.exp
index 39a9383953dd..abd4a61e2d82 100644
--- a/contrib/bmake/unit-tests/opt-debug-x-trace.exp
+++ b/contrib/bmake/unit-tests/opt-debug-x-trace.exp
@@ -1 +1,3 @@
++ echo 'Counting 1 2 3 4 5 6 7'
+Counting 1 2 3 4 5 6 7
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-debug-x-trace.mk b/contrib/bmake/unit-tests/opt-debug-x-trace.mk
index 0936ba506966..54c04a9a4cf8 100644
--- a/contrib/bmake/unit-tests/opt-debug-x-trace.mk
+++ b/contrib/bmake/unit-tests/opt-debug-x-trace.mk
@@ -1,10 +1,12 @@
-# $NetBSD: opt-debug-x-trace.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $
+# $NetBSD: opt-debug-x-trace.mk,v 1.2 2022/01/23 16:09:38 rillig Exp $
#
# Tests for the -dx command line option, which runs shell commands with
# the -x option, thereby printing the actual commands as they are
# executed.
-# TODO: Implementation
+.MAKEFLAGS: -dx
-all:
- @:;
+# expect: + echo 'Counting 1 2 3 4 5 6 7'
+# expect: Counting 1 2 3 4 5 6 7
+all: .PHONY
+ @echo 'Counting ${:U:range=7}'
diff --git a/contrib/bmake/unit-tests/opt-define.mk b/contrib/bmake/unit-tests/opt-define.mk
index ce0516ba44bc..f508a9b1592f 100644
--- a/contrib/bmake/unit-tests/opt-define.mk
+++ b/contrib/bmake/unit-tests/opt-define.mk
@@ -1,8 +1,40 @@
-# $NetBSD: opt-define.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-define.mk,v 1.4 2022/06/12 14:27:06 rillig Exp $
#
-# Tests for the -D command line option.
+# Tests for the -D command line option, which defines global variables to the
+# value 1, like in the C preprocessor.
-# TODO: Implementation
+.MAKEFLAGS: -DVAR
-all:
- @:;
+# The variable has the exact value "1", not "1.0".
+.if ${VAR} != "1"
+. error
+.endif
+
+# The variable can be overwritten by assigning another value to it. This
+# would not be possible if the variable had been specified on the command line
+# as 'VAR=1' instead of '-DVAR'.
+VAR= overwritten
+.if ${VAR} != "overwritten"
+. error
+.endif
+
+# The variable can be undefined. If the variable had been defined in the
+# "Internal" or in the "Command" scope instead, undefining it would have no
+# effect.
+.undef VAR
+.if defined(VAR)
+. error
+.endif
+
+# The C preprocessor allows to define a macro with a specific value. Make
+# behaves differently, it defines a variable with the name 'VAR=value' and the
+# value 1.
+.MAKEFLAGS: -DVAR=value
+.if defined(VAR)
+. error
+.endif
+.if ${VAR=value} != "1"
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-env.mk b/contrib/bmake/unit-tests/opt-env.mk
index 32e95ef41f5a..125fc6ff9518 100644
--- a/contrib/bmake/unit-tests/opt-env.mk
+++ b/contrib/bmake/unit-tests/opt-env.mk
@@ -1,8 +1,49 @@
-# $NetBSD: opt-env.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-env.mk,v 1.4 2022/03/26 13:32:31 rillig Exp $
#
-# Tests for the -e command line option.
+# Tests for the -e command line option, which looks up environment variables
+# before those from the global scope. It has no influence on variables from
+# the command line though.
+#
+# This option is required by POSIX.
+
+# The variable FROM_ENV is defined in ./Makefile.
+
+.MAKEFLAGS: -e
+
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
+
+# Try to override the variable; this does not have any effect.
+FROM_ENV= value-from-mk
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
+
+# Try to append to the variable; this also doesn't have any effect.
+FROM_ENV+= appended
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
+
+# The default assignment also cannot change the variable.
+FROM_ENV?= default
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
+
+# Neither can the assignment modifiers.
+.if ${FROM_ENV::=from-condition}
+.endif
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
-# TODO: Implementation
+# Even .undef doesn't work since it only affects the global scope,
+# which is independent from the environment variables.
+.undef FROM_ENV
+.if ${FROM_ENV} != value-from-env
+. error ${FROM_ENV}
+.endif
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-file.mk b/contrib/bmake/unit-tests/opt-file.mk
index b7a1c09e6d16..5085fe126af8 100644
--- a/contrib/bmake/unit-tests/opt-file.mk
+++ b/contrib/bmake/unit-tests/opt-file.mk
@@ -1,6 +1,7 @@
-# $NetBSD: opt-file.mk,v 1.12 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.15 2022/03/26 13:32:31 rillig Exp $
#
-# Tests for the -f command line option.
+# Tests for the -f command line option, which adds a makefile to the list of
+# files that are parsed.
# TODO: Implementation
@@ -10,16 +11,19 @@ all: file-ending-in-backslash-mmap
all: line-with-trailing-whitespace
all: file-containing-null-byte
-# Passing '-' as the filename reads from stdin. This is unusual but possible.
+# When the filename is '-', the input comes from stdin. This is unusual but
+# possible.
#
# In the unlikely case where a file ends in a backslash instead of a newline,
-# that backslash is trimmed. See ParseGetLine.
+# that backslash is trimmed. See ReadLowLevelLine.
#
# make-2014.01.01.00.00.00 invoked undefined behavior, reading text from
# outside of the file buffer.
#
# printf '%s' 'VAR=value\' \
-# | MALLOC_OPTIONS=JA make-2014.01.01.00.00.00 -r -f - -V VAR -dA 2>&1 \
+# | MALLOC_OPTIONS="JA" \
+# MALLOC_CONF="junk:true" \
+# make-2014.01.01.00.00.00 -r -f - -V VAR -dA 2>&1 \
# | less
#
# The debug output shows how make happily uses freshly allocated memory (the
@@ -48,7 +52,7 @@ file-ending-in-backslash-mmap: .PHONY
# Since parse.c 1.511 from 2020-12-22, an assertion in ParseGetLine failed
# for lines that contained trailing whitespace. Worked around in parse.c
-# 1.513, properly fixed in parse.c 1.514.
+# 1.513, properly fixed in parse.c 1.514 from 2020-12-22.
line-with-trailing-whitespace: .PHONY
@printf '%s' 'VAR=$@ ' > opt-file-trailing-whitespace
@${MAKE} -r -f opt-file-trailing-whitespace -V VAR
diff --git a/contrib/bmake/unit-tests/opt-jobs-internal.exp b/contrib/bmake/unit-tests/opt-jobs-internal.exp
index 39a9383953dd..470bdbddd0f8 100644
--- a/contrib/bmake/unit-tests/opt-jobs-internal.exp
+++ b/contrib/bmake/unit-tests/opt-jobs-internal.exp
@@ -1 +1,6 @@
-exit status 0
+make: internal error -- J option malformed (garbage)
+usage: make [-BeikNnqrSstWwX]
+ [-C directory] [-D variable] [-d flags] [-f makefile]
+ [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]
+ [-V variable] [-v variable] [variable=value] [target ...]
+exit status 2
diff --git a/contrib/bmake/unit-tests/opt-jobs-internal.mk b/contrib/bmake/unit-tests/opt-jobs-internal.mk
index 5426807ca98b..44755a797751 100644
--- a/contrib/bmake/unit-tests/opt-jobs-internal.mk
+++ b/contrib/bmake/unit-tests/opt-jobs-internal.mk
@@ -1,8 +1,9 @@
-# $NetBSD: opt-jobs-internal.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-jobs-internal.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $
#
# Tests for the (intentionally undocumented) -J command line option.
+#
+# Only test the error handling here, the happy path is covered in other tests
+# as a side effect.
-# TODO: Implementation
-
-all:
- @:;
+# expect: make: internal error -- J option malformed (garbage)
+.MAKEFLAGS: -Jgarbage
diff --git a/contrib/bmake/unit-tests/opt-jobs-no-action.mk b/contrib/bmake/unit-tests/opt-jobs-no-action.mk
index 19d82c5bf4b8..fe720c9e0e61 100644
--- a/contrib/bmake/unit-tests/opt-jobs-no-action.mk
+++ b/contrib/bmake/unit-tests/opt-jobs-no-action.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-jobs-no-action.mk,v 1.9 2021/04/04 09:58:51 rillig Exp $
+# $NetBSD: opt-jobs-no-action.mk,v 1.10 2022/05/08 06:51:27 rillig Exp $
#
# Tests for the combination of the options -j and -n, which prints the
# commands instead of actually running them.
@@ -21,7 +21,7 @@
# The shell attributes are handled by Job_ParseShell.
# The shell attributes 'quiet' and 'echo' don't need a trailing newline,
# this is handled by the [0] != '\0' checks in Job_ParseShell.
-# The '\#' is handled by ParseGetLine.
+# The '\#' is handled by ParseRawLine.
# The '\n' is handled by Str_Words in Job_ParseShell.
# The '$$' is handled by Var_Subst in ParseDependencyLine.
.SHELL: \
diff --git a/contrib/bmake/unit-tests/opt-jobs.mk b/contrib/bmake/unit-tests/opt-jobs.mk
index 7d54d08a8421..ce84e47e91e1 100644
--- a/contrib/bmake/unit-tests/opt-jobs.mk
+++ b/contrib/bmake/unit-tests/opt-jobs.mk
@@ -1,8 +1,54 @@
-# $NetBSD: opt-jobs.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-jobs.mk,v 1.5 2023/09/10 16:25:32 sjg Exp $
#
-# Tests for the -j command line option.
+# Tests for the -j command line option, which creates the targets in parallel.
-# TODO: Implementation
-all:
- @:;
+# The option '-j <integer>' specifies the number of targets that can be made
+# in parallel.
+ARGS= 0 1 2 8 08 017 0x10 -5 1000
+EXPECT.0= argument '0' to option '-j' must be a positive number (exit 2)
+EXPECT.1= 1
+EXPECT.2= 2
+EXPECT.8= 8
+EXPECT.08= argument '08' to option '-j' must be a positive number (exit 2)
+EXPECT.017= 15
+EXPECT.0x10= 16
+EXPECT.-5= argument '-5' to option '-j' must be a positive number (exit 2)
+EXPECT.1000= 1000
+
+.for arg in ${ARGS}
+OUTPUT!= ${MAKE} -r -f /dev/null -j ${arg} -v .MAKE.JOBS 2>&1 || echo "(exit $$?)"
+. if ${OUTPUT:[2..-1]} != ${EXPECT.${arg}}
+. warning ${arg}:${.newline} have: ${OUTPUT:[2..-1]}${.newline} want: ${EXPECT.${arg}}
+. endif
+.endfor
+
+
+# The options '-j <float>' and '-j <integer>C' multiply the given number with
+# the number of available CPUs.
+ARGS= 0.0 0C 0.0C .00001 .00001C 1C 1CPUs 1.2 .5e1C 07.5C 08.5C
+EXPECT.0.0= argument '0.0' to option '-j' must be a positive number (exit 2)
+EXPECT.0C= <integer> # rounded up to 1C
+EXPECT.0.0C= argument '0.0C' to option '-j' must be a positive number (exit 2)
+EXPECT..00001= argument '.00001' to option '-j' must be a positive number (exit 2)
+EXPECT..00001C= argument '.00001C' to option '-j' must be a positive number (exit 2)
+EXPECT.1C= <integer>
+EXPECT.1CPUs= <integer>
+EXPECT.1.2= <integer>
+EXPECT..5e1C= <integer> # unlikely to occur in practice
+EXPECT.07.5C= <integer>
+EXPECT.08.5C= argument '08.5C' to option '-j' must be a positive number (exit 2)
+
+.if ${.MAKE.JOBS.C} == "yes"
+. for arg in ${ARGS}
+OUTPUT!= ${MAKE} -r -f /dev/null -j ${arg} -v .MAKE.JOBS 2>&1 || echo "(exit $$?)"
+. if ${OUTPUT:C,^[0-9]+$,numeric,W} == numeric
+OUTPUT= <integer>
+. endif
+. if ${OUTPUT:[2..-1]} != ${EXPECT.${arg}}
+. warning ${arg}:${.newline} have: ${OUTPUT:[2..-1]}${.newline} want: ${EXPECT.${arg}}
+. endif
+. endfor
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-keep-going-indirect.exp b/contrib/bmake/unit-tests/opt-keep-going-indirect.exp
new file mode 100644
index 000000000000..0c00c75395fa
--- /dev/null
+++ b/contrib/bmake/unit-tests/opt-keep-going-indirect.exp
@@ -0,0 +1,32 @@
+direct compat
+false
+*** Error code 1 (continuing)
+
+Stop.
+make: stopped in unit-tests
+exited 1
+
+direct jobs
+false
+*** [direct] Error code 1
+
+make: stopped in unit-tests
+exited 1
+
+indirect compat
+false
+*** Error code 1 (continuing)
+`indirect' not remade because of errors.
+
+Stop.
+make: stopped in unit-tests
+exited 1
+
+indirect jobs
+false
+*** [direct] Error code 1
+
+make: stopped in unit-tests
+exited 1
+
+exit status 0
diff --git a/contrib/bmake/unit-tests/opt-keep-going-indirect.mk b/contrib/bmake/unit-tests/opt-keep-going-indirect.mk
new file mode 100644
index 000000000000..22f7be945f71
--- /dev/null
+++ b/contrib/bmake/unit-tests/opt-keep-going-indirect.mk
@@ -0,0 +1,90 @@
+# $NetBSD: opt-keep-going-indirect.mk,v 1.2 2022/02/12 20:05:36 rillig Exp $
+#
+# Tests for the -k command line option, which stops building a target as soon
+# as an error is detected, but continues building the other, independent
+# targets, as far as possible.
+#
+# History:
+# In 1993, the exit status for the option '-k' was always 0, even if a
+# direct or an indirect target failed.
+#
+# Since 2000.12.30.02.05.21, the word '(continuing)' is missing in jobs
+# mode, both for direct as well as indirect targets.
+#
+# Since 2001.10.16.18.50.12, the exit status for a direct failure in
+# compat mode is the correct 1, while jobs mode and indirect failures
+# still return the wrong exit status 0. The number of empty lines
+# between the various error messages differs between the modes, for no
+# reason.
+#
+# At 2006.11.17.22.07.39, the exit status for direct failures in both
+# modes and for indirect failures in jobs mode was fixed to the correct
+# 1. The exit status for indirect failures in compat mode is still the
+# wrong 0. On the downside, a failed indirect target in jobs mode is no
+# longer listed as "not remade because of errors".
+#
+# At 2016.08.26.23.28.39, the additional empty line for a direct failure
+# in compat mode was removed, making it consistent with a direct failure
+# in jobs mode. This left only one inconsistency, in that indirect
+# failures in jobs mode (by far the most common when building large
+# projects) did not produce any empty line.
+#
+# Since 2020.12.07.00.53.30, the exit status is consistently 1 for
+# failures in all 4 modes.
+#
+# Bugs:
+# The output in case of a failure needlessly differs between compat and
+# jobs mode. As of 2022-02-12, compat mode outputs '(continuing)' while
+# jobs mode doesn't. In compat mode, the output does not mention which
+# target failed.
+#
+# See also:
+# https://gnats.netbsd.org/49720
+
+.PHONY: all direct indirect
+
+# The 'set +e' was necessary in 2003, when the shell was run with '-e' by
+# default.
+# The 'env -i' prevents that the environment variable MAKEFLAGS is passed down
+# to the child processes.
+all:
+ @echo 'direct compat'
+ @set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct; echo "exited $$?"
+ @echo
+
+ @echo 'direct jobs'
+ @set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct -j1; echo "exited $$?"
+ @echo
+
+ @echo 'indirect compat'
+ @set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect; echo "exited $$?"
+ @echo
+
+ @echo 'indirect jobs'
+ @set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect -j1; echo "exited $$?"
+ @echo
+
+indirect: direct
+direct:
+ false
+
+# TODO: Mention the target that failed, maybe even the chain of targets.
+# expect: direct compat
+# expect: *** Error code 1 (continuing)
+# expect: exited 1
+
+# TODO: Add '(continuing)'.
+# expect: direct jobs
+# expect: *** [direct] Error code 1
+# expect: exited 1
+
+# TODO: Mention the target that failed, maybe even the chain of targets.
+# expect: indirect compat
+# expect: *** Error code 1 (continuing)
+# expect: exited 1
+
+# TODO: Add '(continuing)'.
+# TODO: Add 'not remade because of errors'.
+# expect: indirect jobs
+# expect: *** [direct] Error code 1
+# expect: exited 1
diff --git a/contrib/bmake/unit-tests/opt-query.exp b/contrib/bmake/unit-tests/opt-query.exp
index 38025dcf4d3a..0ba62780d844 100644
--- a/contrib/bmake/unit-tests/opt-query.exp
+++ b/contrib/bmake/unit-tests/opt-query.exp
@@ -1,2 +1,24 @@
+Making commands:
command during parsing
-exit status 1
+commands: query status 1
+
+Making opt-query-file.out-of-date in compat mode:
+opt-query-file.out-of-date in compat mode: query status 1
+
+Making opt-query-file.up-to-date in compat mode:
+`opt-query-file.up-to-date' is up to date.
+opt-query-file.up-to-date in compat mode: query status 0
+
+Making phony in compat mode:
+phony in compat mode: query status 1
+
+Making opt-query-file.out-of-date in jobs mode:
+opt-query-file.out-of-date in jobs mode: query status 1
+
+Making opt-query-file.up-to-date in jobs mode:
+opt-query-file.up-to-date in jobs mode: query status 0
+
+Making phony in jobs mode:
+phony in jobs mode: query status 1
+
+exit status 0
diff --git a/contrib/bmake/unit-tests/opt-query.mk b/contrib/bmake/unit-tests/opt-query.mk
index 0a7d5219a8fe..3554d69afad6 100644
--- a/contrib/bmake/unit-tests/opt-query.mk
+++ b/contrib/bmake/unit-tests/opt-query.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-query.mk,v 1.4 2020/11/09 20:50:56 rillig Exp $
+# $NetBSD: opt-query.mk,v 1.7 2022/08/18 05:37:05 rillig Exp $
#
# Tests for the -q command line option.
#
@@ -6,7 +6,57 @@
# None of the commands in the targets are run, not even those that are
# prefixed with '+'.
-.MAKEFLAGS: -q
+# This test consists of several parts:
+#
+# main Delegates to the actual tests.
+#
+# commands Ensures that none of the targets is made.
+#
+# variants Ensures that the up-to-date status is correctly
+# reported in both compat and jobs mode, and for several
+# kinds of make targets.
+PART?= main
+
+.if ${PART} == "main"
+
+all: .PHONY variants cleanup
+
+_!= touch -f opt-query-file.up-to-date
+
+variants: .PHONY
+
+. for target in commands
+ @echo 'Making ${target}':
+ @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \
+ && echo "${target}: query status $$?" \
+ || echo "${target}: query status $$?"
+ @echo
+. endfor
+
+. for mode in compat jobs
+. for target in opt-query-file.out-of-date opt-query-file.up-to-date phony
+ @echo 'Making ${target} in ${mode} mode':
+ @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=variants \
+ && echo "${target} in ${mode} mode: query status $$?" \
+ || echo "${target} in ${mode} mode: query status $$?"
+ @echo
+. endfor
+. endfor
+
+# Between 1994 and before 2022-08-17, the exit status for '-q' was always 1,
+# the cause for that exit code varied over time though.
+#
+# expect: opt-query-file.out-of-date in compat mode: query status 1
+# expect: opt-query-file.up-to-date in compat mode: query status 0
+# expect: phony in compat mode: query status 1
+# expect: opt-query-file.out-of-date in jobs mode: query status 1
+# expect: opt-query-file.up-to-date in jobs mode: query status 0
+# expect: phony in jobs mode: query status 1
+
+cleanup: .PHONY
+ @rm -f opt-query-file.up-to-date
+
+.elif ${PART} == "commands"
# This command cannot be prevented from being run since it is used at parse
# time, and any later variable assignments may depend on its result.
@@ -18,9 +68,18 @@
@+echo '$@: run always'
# None of these commands are run.
-all:
+commands:
@echo '$@: hidden command'
@+echo '$@: run always'
-
-# The exit status 1 is because the "all" target has to be made, that is,
+# The exit status 1 is because the "commands" target has to be made, that is,
# it is not up-to-date.
+
+.elif ${PART} == "variants"
+
+opt-query-file.out-of-date: ${MAKEFILE}
+opt-query-file.up-to-date: ${MAKEFILE}
+phony: .PHONY
+
+.else
+. error Invalid part '${PART}'
+.endif
diff --git a/contrib/bmake/unit-tests/opt-raw.mk b/contrib/bmake/unit-tests/opt-raw.mk
index d3591bb99dab..91caffcd72ae 100644
--- a/contrib/bmake/unit-tests/opt-raw.mk
+++ b/contrib/bmake/unit-tests/opt-raw.mk
@@ -1,8 +1,14 @@
-# $NetBSD: opt-raw.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-raw.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $
#
-# Tests for the -r command line option.
+# Tests for the -r command line option, which skips the system-defined default
+# rules from <sys.mk>.
-# TODO: Implementation
+# To provide a clean testing environment without unintended side effects,
+# these unit tests run make with the option '-r' by default. This means there
+# are no predefined suffixes and no predefined tools.
-all:
- @:;
+.if defined(CC)
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/opt-silent.exp b/contrib/bmake/unit-tests/opt-silent.exp
index 39a9383953dd..8863b8a2965d 100644
--- a/contrib/bmake/unit-tests/opt-silent.exp
+++ b/contrib/bmake/unit-tests/opt-silent.exp
@@ -1 +1,3 @@
+message
+silent message
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-silent.mk b/contrib/bmake/unit-tests/opt-silent.mk
index 7822d46ac48a..01e5b18e2b12 100644
--- a/contrib/bmake/unit-tests/opt-silent.mk
+++ b/contrib/bmake/unit-tests/opt-silent.mk
@@ -1,8 +1,10 @@
-# $NetBSD: opt-silent.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-silent.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $
#
# Tests for the -s command line option.
-# TODO: Implementation
+.MAKEFLAGS: -s
+# No matter whether a command is prefixed by '@' or not, it is not echoed.
all:
- @:;
+ echo 'message'
+ @echo 'silent message'
diff --git a/contrib/bmake/unit-tests/opt-tracefile.exp b/contrib/bmake/unit-tests/opt-tracefile.exp
index 39a9383953dd..0e815606d34f 100644
--- a/contrib/bmake/unit-tests/opt-tracefile.exp
+++ b/contrib/bmake/unit-tests/opt-tracefile.exp
@@ -1 +1,12 @@
+Making dependency1 from <nothing>.
+Making dependency2 from <nothing>.
+Making trace from dependency1 dependency2.
+0 BEG
+1 JOB
+1 DON
+1 JOB
+1 DON
+1 JOB
+1 DON
+0 END
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-tracefile.mk b/contrib/bmake/unit-tests/opt-tracefile.mk
index b62392ca913c..291824680606 100644
--- a/contrib/bmake/unit-tests/opt-tracefile.mk
+++ b/contrib/bmake/unit-tests/opt-tracefile.mk
@@ -1,8 +1,16 @@
-# $NetBSD: opt-tracefile.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-tracefile.mk,v 1.5 2021/12/06 22:35:20 rillig Exp $
#
-# Tests for the -T command line option.
+# Tests for the command line option '-T', which in jobs mode appends a trace
+# record to a trace log whenever a job is started or completed.
-# TODO: Implementation
+all: .PHONY
+ @rm -f opt-tracefile.log
+ @${MAKE} -f ${MAKEFILE} -j1 -Topt-tracefile.log trace
+ # Remove timestamps, process IDs and directory paths.
+ @awk '{ print $$2, $$3 }' opt-tracefile.log
+ @rm opt-tracefile.log
-all:
- @:;
+trace dependency1 dependency2: .PHONY
+ @echo 'Making ${.TARGET} from ${.ALLSRC:S,^$,<nothing>,W}.'
+
+trace: dependency1 dependency2
diff --git a/contrib/bmake/unit-tests/opt-version.exp b/contrib/bmake/unit-tests/opt-version.exp
new file mode 100644
index 000000000000..1636aafc11e5
--- /dev/null
+++ b/contrib/bmake/unit-tests/opt-version.exp
@@ -0,0 +1,2 @@
+
+exit status 0
diff --git a/contrib/bmake/unit-tests/opt-version.mk b/contrib/bmake/unit-tests/opt-version.mk
new file mode 100644
index 000000000000..cdba9180ec01
--- /dev/null
+++ b/contrib/bmake/unit-tests/opt-version.mk
@@ -0,0 +1,12 @@
+# $NetBSD: opt-version.mk,v 1.2 2022/05/08 07:27:50 rillig Exp $
+#
+# Tests for the command line option '--version', which may be expected to
+# output the version number of make. NetBSD's make does not have a version
+# number, but the bmake distribution created from it has.
+
+# As of 2021-12-23, the output is a single empty line since the '--' does not
+# end the command line options. Command line parsing then continues as if
+# nothing had happened, and the '-version' is split into '-v ersion', which is
+# interpreted as "print the expanded variable named 'ersion'".
+
+.MAKEFLAGS: --version
diff --git a/contrib/bmake/unit-tests/opt-warnings-as-errors.exp b/contrib/bmake/unit-tests/opt-warnings-as-errors.exp
index 1db56b753bed..87d1db249a20 100644
--- a/contrib/bmake/unit-tests/opt-warnings-as-errors.exp
+++ b/contrib/bmake/unit-tests/opt-warnings-as-errors.exp
@@ -1,6 +1,6 @@
-make: "opt-warnings-as-errors.mk" line 12: warning: message 1
+make: "opt-warnings-as-errors.mk" line 13: warning: message 1
make: parsing warnings being treated as errors
-make: "opt-warnings-as-errors.mk" line 13: warning: message 2
+make: "opt-warnings-as-errors.mk" line 15: warning: message 2
parsing continues
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
diff --git a/contrib/bmake/unit-tests/opt-warnings-as-errors.mk b/contrib/bmake/unit-tests/opt-warnings-as-errors.mk
index c29343f960a7..3896dad10f1a 100644
--- a/contrib/bmake/unit-tests/opt-warnings-as-errors.mk
+++ b/contrib/bmake/unit-tests/opt-warnings-as-errors.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt-warnings-as-errors.mk,v 1.5 2021/01/27 00:02:38 rillig Exp $
+# $NetBSD: opt-warnings-as-errors.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the -W command line option, which turns warnings into errors.
#
@@ -9,7 +9,9 @@
.MAKEFLAGS: -W
+# expect+1: warning: message 1
.warning message 1
+# expect+1: warning: message 2
.warning message 2
_!= echo 'parsing continues' 1>&2
diff --git a/contrib/bmake/unit-tests/opt-where-am-i.exp b/contrib/bmake/unit-tests/opt-where-am-i.exp
index 39a9383953dd..e64df44b83b7 100644
--- a/contrib/bmake/unit-tests/opt-where-am-i.exp
+++ b/contrib/bmake/unit-tests/opt-where-am-i.exp
@@ -1 +1,4 @@
+make: Entering directory `/'
+make: Leaving directory `/'
+make: Leaving directory `<curdir>'
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-where-am-i.mk b/contrib/bmake/unit-tests/opt-where-am-i.mk
index 9158a598174c..f1eeca920a32 100644
--- a/contrib/bmake/unit-tests/opt-where-am-i.mk
+++ b/contrib/bmake/unit-tests/opt-where-am-i.mk
@@ -1,8 +1,14 @@
-# $NetBSD: opt-where-am-i.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-where-am-i.mk,v 1.4 2022/01/27 02:24:46 sjg Exp $
#
-# Tests for the -w command line option.
+# Tests for the -w command line option, which outputs the current directory
+# at the beginning and end of running make. This is useful when building
+# large source trees that involve several nested make calls.
-# TODO: Implementation
+# The first "Entering directory" is missing since the below .MAKEFLAGS comes
+# too late for it.
+.MAKEFLAGS: -w
all:
- @:;
+.if ${.CURDIR} != "/"
+ @MAKE_OBJDIR_CHECK_WRITABLE=no ${MAKE} -r -f ${MAKEFILE:tA} -C /
+.endif
diff --git a/contrib/bmake/unit-tests/opt-x-reduce-exported.exp b/contrib/bmake/unit-tests/opt-x-reduce-exported.exp
index 39a9383953dd..99570f2c30cb 100644
--- a/contrib/bmake/unit-tests/opt-x-reduce-exported.exp
+++ b/contrib/bmake/unit-tests/opt-x-reduce-exported.exp
@@ -1 +1,5 @@
+ordinary:
+BEFORE=before
+submake:
+BEFORE=before
exit status 0
diff --git a/contrib/bmake/unit-tests/opt-x-reduce-exported.mk b/contrib/bmake/unit-tests/opt-x-reduce-exported.mk
index 7ee8e7c7eff0..a42a85d21a53 100644
--- a/contrib/bmake/unit-tests/opt-x-reduce-exported.mk
+++ b/contrib/bmake/unit-tests/opt-x-reduce-exported.mk
@@ -1,8 +1,20 @@
-# $NetBSD: opt-x-reduce-exported.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: opt-x-reduce-exported.mk,v 1.3 2022/05/08 07:27:50 rillig Exp $
#
-# Tests for the -x command line option.
+# Tests for the -X command line option, which prevents variables passed on the
+# command line from being exported to the environment of child commands.
-# TODO: Implementation
+# The variable 'BEFORE' is exported, the variable 'AFTER' isn't.
+.MAKEFLAGS: BEFORE=before -X AFTER=after
-all:
- @:;
+all: .PHONY ordinary submake
+
+ordinary: .PHONY
+ @echo 'ordinary:'
+ @env | sort | grep -e '^BEFORE' -e '^AFTER'
+
+submake: .PHONY
+ @echo 'submake:'
+ @${MAKE} -r -f ${MAKEFILE} show-env
+
+show-env: .PHONY
+ @env | sort | grep -e '^BEFORE' -e '^AFTER'
diff --git a/contrib/bmake/unit-tests/opt.mk b/contrib/bmake/unit-tests/opt.mk
index 0931a66d3d15..939d5ec35aeb 100644
--- a/contrib/bmake/unit-tests/opt.mk
+++ b/contrib/bmake/unit-tests/opt.mk
@@ -1,4 +1,4 @@
-# $NetBSD: opt.mk,v 1.6 2020/11/18 01:06:59 sjg Exp $
+# $NetBSD: opt.mk,v 1.7 2023/02/25 00:07:08 rillig Exp $
#
# Tests for the command line options.
@@ -7,7 +7,7 @@
all: .IGNORE
# The options from the top-level make are passed to the sub-makes via
# the environment variable MAKEFLAGS. This is where the " -r -k -d 0"
- # comes from. See MainParseArg.
+ # comes from. See MainParseOption.
${MAKE} -r -f /dev/null -V MAKEFLAGS
@echo
diff --git a/contrib/bmake/unit-tests/parse-var.mk b/contrib/bmake/unit-tests/parse-var.mk
index bd6c59f0e5cb..b35726e76efc 100644
--- a/contrib/bmake/unit-tests/parse-var.mk
+++ b/contrib/bmake/unit-tests/parse-var.mk
@@ -1,13 +1,129 @@
-# $NetBSD: parse-var.mk,v 1.1 2020/10/04 06:53:15 rillig Exp $
+# $NetBSD: parse-var.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
+#
+# Tests for parsing expressions.
+#
+# TODO: Add systematic tests for all of the below combinations.
+#
+# Written form:
+# short form
+# long form with braces endc == '}'
+# long form with parentheses endc == ')'
+# indirect modifiers endc == '\0'
+#
+# Based on:
+# undefined variable
+# global variable
+# command-line variable
+# environment variable
+# target-local variable
+# legacy variable '@F'
+#
+# VarEvalMode:
+# parse
+# eval
+# eval-undeferr
+# eval-keep-dollar
+# eval-keep-undef
+# eval-keep-dollar-undef
+#
+# Global mode:
+# without -dL
+# with -dL
+#
+# Modifiers:
+# no
+# yes, stay undefined
+# convert to defined
+# indirect modifiers, involving changes to VarEvalMode
+#
+# Error conditions:
+# for the short form, EOF after the '$'
+# for the short form, each character
+# for the long forms, EOF right after '${'
+# for the long forms, EOF after the variable name
+# for the long forms, EOF after the ':'
+# for the long forms, EOF after parsing a modifier
+# for the long forms, ':}'
+# for each modifier: syntactic error
+# for each modifier: evaluation error
+#
+# Context:
+# in a condition, only operand, unquoted
+# in a condition, only operand, quoted
+# in a condition, left-hand side, unquoted
+# in a condition, left-hand side, quoted
+# in a condition, right-hand side, unquoted
+# in a condition, right-hand side, quoted
+# left-hand side of a variable assignment
+# right-hand side of a ':=' variable assignment
+# right-hand side of a '!=' variable assignment
+# shell command in a target
+# .info directive
+# dependency line
+# items in a .for loop
+# everywhere else Var_Parse is called
+#
+# Further influences:
+# multi-level evaluations like 'other=${OTHER}' with OTHER='$$ ${THIRD}'
+#
+# Effects:
+# How much does the parsing position advance (pp)?
+# What's the value of the expression (return value)?
+# What error messages are printed (Parse_Error)?
+# What no-effect error messages are printed (Error)?
+# What error messages should be printed but aren't?
+# What other side effects are there?
.MAKEFLAGS: -dL
-# In variable assignments, there may be spaces on the left-hand side of the
-# assignment, but only if they occur inside variable expressions.
+# In variable assignments, there may be spaces in the middle of the left-hand
+# side of the assignment, but only if they occur inside expressions.
+# Leading spaces (but not tabs) are possible but unusual.
+# Trailing spaces are common in some coding styles, others omit them.
VAR.${:U param }= value
.if ${VAR.${:U param }} != "value"
. error
.endif
-all:
- @:;
+# Since var.c 1.323 from 2020-07-26 18:11 and until var.c 1.1047 from
+# 2023-02-18, the exact way of parsing an expression with subexpressions
+# depended on whether the expression was actually evaluated or merely parsed.
+#
+# If it was evaluated, nested expressions were parsed correctly, parsing each
+# modifier according to its exact definition (see varmod.mk).
+#
+# If the expression was merely parsed but not evaluated (for example, because
+# its value would not influence the outcome of the condition, or during the
+# first pass of the ':@var@body@' modifier), and the expression contained a
+# modifier, and that modifier contained a nested expression, the nested
+# expression was not parsed correctly. Instead, make only counted the opening
+# and closing delimiters, which failed for nested modifiers with unbalanced
+# braces.
+
+#.MAKEFLAGS: -dcpv
+# Keep these braces outside the conditions below, to keep them simple to
+# understand. If the expression ${BRACE_PAIR:...} had been replaced with the
+# literal ${:U{}}, the '}' would have to be escaped, but not the '{'. This
+# asymmetry would have made the example even more complicated to understand.
+BRACE_PAIR= {}
+# In this test word, the below conditions will replace the '{{}' in the middle
+# with the string '<lbraces>'.
+BRACE_GROUP= {{{{}}}}
+
+# The inner ':S' modifier turns the word '{}' into '{{}'.
+# The outer ':S' modifier then replaces '{{}' with '<lbraces>'.
+# Due to the always-true condition '1', the outer expression is relevant and
+# is parsed correctly.
+.if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
+.endif
+# Due to the always-false condition '0', the outer expression is irrelevant.
+# In this case, in the parts of the outer ':S' modifier, the expression parser
+# only counted the braces, and since the inner expression '${BRACE_PAIR:...}'
+# contains more '{' than '}', parsing failed with the error message 'Unfinished
+# modifier for "BRACE_GROUP"'. Fixed in var.c 1.1047 from 2023-02-18.
+.if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
+.endif
+#.MAKEFLAGS: -d0
+
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/parse.exp b/contrib/bmake/unit-tests/parse.exp
new file mode 100644
index 000000000000..cc8c450d51ac
--- /dev/null
+++ b/contrib/bmake/unit-tests/parse.exp
@@ -0,0 +1,6 @@
+make: "parse.mk" line 7: Invalid line '<<<<<< old'
+make: "parse.mk" line 14: Invalid line '>>>>>> new'
+make: "parse.mk" line 25: Invalid line 'one-target ${:U }', expanded to 'one-target '
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/parse.mk b/contrib/bmake/unit-tests/parse.mk
new file mode 100644
index 000000000000..80a51f2de11e
--- /dev/null
+++ b/contrib/bmake/unit-tests/parse.mk
@@ -0,0 +1,55 @@
+# $NetBSD: parse.mk,v 1.7 2023/08/19 11:09:02 rillig Exp $
+#
+# Test those parts of the parsing that do not belong in any of the other
+# categories.
+
+# expect+1: Invalid line '<<<<<< old'
+<<<<<< old
+
+# No diagnostic since the following line is parsed as a variable assignment,
+# even though the variable name is empty. See also varname-empty.mk.
+====== middle
+
+# expect+1: Invalid line '>>>>>> new'
+>>>>>> new
+
+
+# Since parse.c 1.578 from 2021-12-14 and before parse.c 1.681 from
+# 2022-07-24, if a line of a makefile could only be a dependency specification
+# but didn't contain any of the dependency operators ':', '!', '::' and its
+# expansion ended with a space, make read a single byte from the memory beyond
+# the expanded line's terminating '\0'.
+#
+# https://bugs.freebsd.org/265119
+# expect+1: Invalid line 'one-target ${:U }', expanded to 'one-target '
+one-target ${:U }
+
+
+# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from
+# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for
+# a variable assignment in a dependency line with trailing whitespace. Lines
+# without trailing whitespace were not affected. Global variable assignments
+# were guaranteed to have no trailing whitespace and were thus not affected.
+#
+# Try to reproduce some variants that may lead to a crash, depending on the
+# memory allocator. To get a crash, the terminating '\0' of the line must be
+# the last byte of a memory page. The expression '${:U}' forces this trailing
+# whitespace.
+
+# On FreeBSD x86_64, a crash could in some cases be forced using the following
+# line, which has length 47, and if the memory for the expanded line starts at
+# 0xXXXX_XXd0, the terminating '\0' may end up at 0xXXXX_Xfff:
+Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U}
+
+# The following line has length 4095 after being expanded, so line[4095] ==
+# '\0'. If the line is
+# allocated on a page boundary and the following page is not mapped, this line
+# leads to a segmentation fault.
+${:U:range=511:@_@1234567@:ts.}: 12345 ${:U}
+
+# The following line has length 8191, so line[8191] == '\0'. If the line is
+# allocated on a page boundary and the following page is not mapped, this line
+# leads to a segmentation fault.
+${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U}
+
+12345:
diff --git a/contrib/bmake/unit-tests/posix.mk b/contrib/bmake/unit-tests/posix.mk
index fc4cbead3263..43219258306e 100644
--- a/contrib/bmake/unit-tests/posix.mk
+++ b/contrib/bmake/unit-tests/posix.mk
@@ -1,4 +1,4 @@
-# $NetBSD: posix.mk,v 1.2 2020/10/24 08:34:59 rillig Exp $
+# $NetBSD: posix.mk,v 1.3 2022/01/23 18:15:29 rillig Exp $
all: x plus subs err
@@ -14,11 +14,10 @@ plus:
subs:
@echo make -n
- @${.MAKE} -f ${MAKEFILE} -n plus
+ @${.MAKE} -r -f ${MAKEFILE} -n plus
@echo make -n -j1
- @${.MAKE} -f ${MAKEFILE} -n -j1 plus
+ @${.MAKE} -r -f ${MAKEFILE} -n -j1 plus
err:
@(echo Now we expect an error...; exit 1)
@echo "Oops! you shouldn't see this!"
-
diff --git a/contrib/bmake/unit-tests/recursive.exp b/contrib/bmake/unit-tests/recursive.exp
index 36cd1c989532..f63b7a54049e 100644
--- a/contrib/bmake/unit-tests/recursive.exp
+++ b/contrib/bmake/unit-tests/recursive.exp
@@ -1,5 +1,5 @@
-make: "recursive.mk" line 36: Unclosed variable "MISSING_PAREN"
-make: "recursive.mk" line 37: Unclosed variable "MISSING_BRACE"
+make: "recursive.mk" line 38: Unclosed variable "MISSING_PAREN"
+make: "recursive.mk" line 40: Unclosed variable "MISSING_BRACE"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/recursive.mk b/contrib/bmake/unit-tests/recursive.mk
index 5265cec59a2d..b97c4b37eabb 100644
--- a/contrib/bmake/unit-tests/recursive.mk
+++ b/contrib/bmake/unit-tests/recursive.mk
@@ -1,4 +1,4 @@
-# $NetBSD: recursive.mk,v 1.5 2021/03/15 12:15:03 rillig Exp $
+# $NetBSD: recursive.mk,v 1.7 2023/10/19 18:24:33 rillig Exp $
#
# In -dL mode, a variable may get expanded before it makes sense.
# This would stop make from doing anything since the "recursive" error
@@ -8,22 +8,23 @@
# whether there are unclosed variables. The variable value is therefore
# parsed with VARE_PARSE_ONLY for that purpose.
#
-# Seen in pkgsrc/x11/libXfixes, and probably many more package that use
-# GNU Automake.
.MAKEFLAGS: -dL
+
AM_V_lt= ${am__v_lt_${V}}
am__v_lt_= ${am__v_lt_${AM_DEFAULT_VERBOSITY}}
am__v_lt_0= --silent
am__v_lt_1=
-# On 2020-08-06, make reported: "Variable am__v_lt_ is recursive."
+# Since parse.c 1.243 from 2020-07-31 and before parse.c 1.249 from
+# 2020-08-06, when make ran in -dL mode, it reported: "Variable am__v_lt_ is
+# recursive."
+#
+# Seen in pkgsrc/x11/libXfixes, and probably many more package that use
+# GNU Automake.
libXfixes_la_LINK= ... ${AM_V_lt} ...
-# somewhere later ...
-AM_DEFAULT_VERBOSITY= 1
-
# The purpose of the -dL flag is to detect unclosed variables. This
# can be achieved by just parsing the variable and not evaluating it.
@@ -33,6 +34,8 @@ AM_DEFAULT_VERBOSITY= 1
# therefore that's acceptable. In most practical cases, the missing
# brace would be detected directly in the line where it is produced.
MISSING_BRACE_INDIRECT:= ${:U\${MISSING_BRACE}
+# expect+1: Unclosed variable "MISSING_PAREN"
UNCLOSED= $(MISSING_PAREN
+# expect+1: Unclosed variable "MISSING_BRACE"
UNCLOSED= ${MISSING_BRACE
UNCLOSED= ${MISSING_BRACE_INDIRECT}
diff --git a/contrib/bmake/unit-tests/sh-dots.mk b/contrib/bmake/unit-tests/sh-dots.mk
index f85af9025e55..5294a4175b63 100755
--- a/contrib/bmake/unit-tests/sh-dots.mk
+++ b/contrib/bmake/unit-tests/sh-dots.mk
@@ -1,4 +1,4 @@
-# $NetBSD: sh-dots.mk,v 1.3 2020/10/25 22:04:24 rillig Exp $
+# $NetBSD: sh-dots.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the special shell command line "...", which does not run the
# commands below it but appends them to the list of commands that are run
@@ -29,8 +29,8 @@ commented: .IGNORE
... # Run the below commands later
@echo commented delayed ${.TARGET}
-# The dots don't have to be written literally, they can also come from a
-# variable expression.
+# The dots don't have to be written literally, they can also come from an
+# expression.
indirect:
@echo indirect regular
${:U...}
diff --git a/contrib/bmake/unit-tests/sh-flags.exp b/contrib/bmake/unit-tests/sh-flags.exp
index 2fec7de2dd99..265826217985 100644
--- a/contrib/bmake/unit-tests/sh-flags.exp
+++ b/contrib/bmake/unit-tests/sh-flags.exp
@@ -1102,7 +1102,6 @@ opt-_j____-tgt-__s-cmd-__s
running
opt-_j____-tgt-__s-cmd-_i_
-echo running; false
running
*** [opt-_j____-tgt-__s-cmd-_i_] Error code 1 (ignored)
@@ -1117,7 +1116,6 @@ opt-_j____-tgt-__s-cmd-a_s
running
opt-_j____-tgt-__s-cmd-ai_
-echo running; false
running
*** [opt-_j____-tgt-__s-cmd-ai_] Error code 1 (ignored)
@@ -1170,7 +1168,6 @@ running
*** [opt-_j____-tgt-_is-cmd-__s] Error code 1 (ignored)
opt-_j____-tgt-_is-cmd-_i_
-echo running; false
running
*** [opt-_j____-tgt-_is-cmd-_i_] Error code 1 (ignored)
@@ -1187,7 +1184,6 @@ running
*** [opt-_j____-tgt-_is-cmd-a_s] Error code 1 (ignored)
opt-_j____-tgt-_is-cmd-ai_
-echo running; false
running
*** [opt-_j____-tgt-_is-cmd-ai_] Error code 1 (ignored)
@@ -1234,7 +1230,6 @@ opt-_j____-tgt-a_s-cmd-__s
running
opt-_j____-tgt-a_s-cmd-_i_
-echo running; false
running
*** [opt-_j____-tgt-a_s-cmd-_i_] Error code 1 (ignored)
@@ -1249,7 +1244,6 @@ opt-_j____-tgt-a_s-cmd-a_s
running
opt-_j____-tgt-a_s-cmd-ai_
-echo running; false
running
*** [opt-_j____-tgt-a_s-cmd-ai_] Error code 1 (ignored)
@@ -1302,7 +1296,6 @@ running
*** [opt-_j____-tgt-ais-cmd-__s] Error code 1 (ignored)
opt-_j____-tgt-ais-cmd-_i_
-echo running; false
running
*** [opt-_j____-tgt-ais-cmd-_i_] Error code 1 (ignored)
@@ -1319,7 +1312,6 @@ running
*** [opt-_j____-tgt-ais-cmd-a_s] Error code 1 (ignored)
opt-_j____-tgt-ais-cmd-ai_
-echo running; false
running
*** [opt-_j____-tgt-ais-cmd-ai_] Error code 1 (ignored)
@@ -1496,7 +1488,6 @@ opt-_j_n__-tgt-a_s-cmd-__s
running
opt-_j_n__-tgt-a_s-cmd-_i_
-echo running; false
running
opt-_j_n__-tgt-a_s-cmd-_is
@@ -1509,7 +1500,6 @@ opt-_j_n__-tgt-a_s-cmd-a_s
running
opt-_j_n__-tgt-a_s-cmd-ai_
-echo running; false
running
opt-_j_n__-tgt-a_s-cmd-ais
@@ -1550,7 +1540,6 @@ opt-_j_n__-tgt-ais-cmd-__s
running
opt-_j_n__-tgt-ais-cmd-_i_
-echo running; false
running
opt-_j_n__-tgt-ais-cmd-_is
@@ -1563,7 +1552,6 @@ opt-_j_n__-tgt-ais-cmd-a_s
running
opt-_j_n__-tgt-ais-cmd-ai_
-echo running; false
running
opt-_j_n__-tgt-ais-cmd-ais
@@ -1612,12 +1600,10 @@ opt-_jl___-tgt-__s-cmd-__s
running
opt-_jl___-tgt-__s-cmd-_i_
-echo running; false
running
*** [opt-_jl___-tgt-__s-cmd-_i_] Error code 1 (ignored)
opt-_jl___-tgt-__s-cmd-_is
-echo running; false
running
*** [opt-_jl___-tgt-__s-cmd-_is] Error code 1 (ignored)
@@ -1628,12 +1614,10 @@ opt-_jl___-tgt-__s-cmd-a_s
running
opt-_jl___-tgt-__s-cmd-ai_
-echo running; false
running
*** [opt-_jl___-tgt-__s-cmd-ai_] Error code 1 (ignored)
opt-_jl___-tgt-__s-cmd-ais
-echo running; false
running
*** [opt-_jl___-tgt-__s-cmd-ais] Error code 1 (ignored)
@@ -1686,12 +1670,10 @@ running
*** [opt-_jl___-tgt-_is-cmd-__s] Error code 1 (ignored)
opt-_jl___-tgt-_is-cmd-_i_
-echo running; false
running
*** [opt-_jl___-tgt-_is-cmd-_i_] Error code 1 (ignored)
opt-_jl___-tgt-_is-cmd-_is
-echo running; false
running
*** [opt-_jl___-tgt-_is-cmd-_is] Error code 1 (ignored)
@@ -1704,12 +1686,10 @@ running
*** [opt-_jl___-tgt-_is-cmd-a_s] Error code 1 (ignored)
opt-_jl___-tgt-_is-cmd-ai_
-echo running; false
running
*** [opt-_jl___-tgt-_is-cmd-ai_] Error code 1 (ignored)
opt-_jl___-tgt-_is-cmd-ais
-echo running; false
running
*** [opt-_jl___-tgt-_is-cmd-ais] Error code 1 (ignored)
@@ -1756,12 +1736,10 @@ opt-_jl___-tgt-a_s-cmd-__s
running
opt-_jl___-tgt-a_s-cmd-_i_
-echo running; false
running
*** [opt-_jl___-tgt-a_s-cmd-_i_] Error code 1 (ignored)
opt-_jl___-tgt-a_s-cmd-_is
-echo running; false
running
*** [opt-_jl___-tgt-a_s-cmd-_is] Error code 1 (ignored)
@@ -1772,12 +1750,10 @@ opt-_jl___-tgt-a_s-cmd-a_s
running
opt-_jl___-tgt-a_s-cmd-ai_
-echo running; false
running
*** [opt-_jl___-tgt-a_s-cmd-ai_] Error code 1 (ignored)
opt-_jl___-tgt-a_s-cmd-ais
-echo running; false
running
*** [opt-_jl___-tgt-a_s-cmd-ais] Error code 1 (ignored)
@@ -1830,12 +1806,10 @@ running
*** [opt-_jl___-tgt-ais-cmd-__s] Error code 1 (ignored)
opt-_jl___-tgt-ais-cmd-_i_
-echo running; false
running
*** [opt-_jl___-tgt-ais-cmd-_i_] Error code 1 (ignored)
opt-_jl___-tgt-ais-cmd-_is
-echo running; false
running
*** [opt-_jl___-tgt-ais-cmd-_is] Error code 1 (ignored)
@@ -1848,12 +1822,10 @@ running
*** [opt-_jl___-tgt-ais-cmd-a_s] Error code 1 (ignored)
opt-_jl___-tgt-ais-cmd-ai_
-echo running; false
running
*** [opt-_jl___-tgt-ais-cmd-ai_] Error code 1 (ignored)
opt-_jl___-tgt-ais-cmd-ais
-echo running; false
running
*** [opt-_jl___-tgt-ais-cmd-ais] Error code 1 (ignored)
@@ -2032,11 +2004,9 @@ opt-_jln__-tgt-a_s-cmd-__s
running
opt-_jln__-tgt-a_s-cmd-_i_
-echo running; false
running
opt-_jln__-tgt-a_s-cmd-_is
-echo running; false
running
opt-_jln__-tgt-a_s-cmd-a__
@@ -2046,11 +2016,9 @@ opt-_jln__-tgt-a_s-cmd-a_s
running
opt-_jln__-tgt-a_s-cmd-ai_
-echo running; false
running
opt-_jln__-tgt-a_s-cmd-ais
-echo running; false
running
opt-_jln__-tgt-ai_-cmd-___
@@ -2092,11 +2060,9 @@ opt-_jln__-tgt-ais-cmd-__s
running
opt-_jln__-tgt-ais-cmd-_i_
-echo running; false
running
opt-_jln__-tgt-ais-cmd-_is
-echo running; false
running
opt-_jln__-tgt-ais-cmd-a__
@@ -2106,11 +2072,9 @@ opt-_jln__-tgt-ais-cmd-a_s
running
opt-_jln__-tgt-ais-cmd-ai_
-echo running; false
running
opt-_jln__-tgt-ais-cmd-ais
-echo running; false
running
opt-i_____-tgt-___-cmd-___
@@ -3278,7 +3242,6 @@ running
*** [opt-ij____-tgt-__s-cmd-__s] Error code 1 (ignored)
opt-ij____-tgt-__s-cmd-_i_
-echo running; false
running
*** [opt-ij____-tgt-__s-cmd-_i_] Error code 1 (ignored)
@@ -3295,7 +3258,6 @@ running
*** [opt-ij____-tgt-__s-cmd-a_s] Error code 1 (ignored)
opt-ij____-tgt-__s-cmd-ai_
-echo running; false
running
*** [opt-ij____-tgt-__s-cmd-ai_] Error code 1 (ignored)
@@ -3348,7 +3310,6 @@ running
*** [opt-ij____-tgt-_is-cmd-__s] Error code 1 (ignored)
opt-ij____-tgt-_is-cmd-_i_
-echo running; false
running
*** [opt-ij____-tgt-_is-cmd-_i_] Error code 1 (ignored)
@@ -3365,7 +3326,6 @@ running
*** [opt-ij____-tgt-_is-cmd-a_s] Error code 1 (ignored)
opt-ij____-tgt-_is-cmd-ai_
-echo running; false
running
*** [opt-ij____-tgt-_is-cmd-ai_] Error code 1 (ignored)
@@ -3418,7 +3378,6 @@ running
*** [opt-ij____-tgt-a_s-cmd-__s] Error code 1 (ignored)
opt-ij____-tgt-a_s-cmd-_i_
-echo running; false
running
*** [opt-ij____-tgt-a_s-cmd-_i_] Error code 1 (ignored)
@@ -3435,7 +3394,6 @@ running
*** [opt-ij____-tgt-a_s-cmd-a_s] Error code 1 (ignored)
opt-ij____-tgt-a_s-cmd-ai_
-echo running; false
running
*** [opt-ij____-tgt-a_s-cmd-ai_] Error code 1 (ignored)
@@ -3488,7 +3446,6 @@ running
*** [opt-ij____-tgt-ais-cmd-__s] Error code 1 (ignored)
opt-ij____-tgt-ais-cmd-_i_
-echo running; false
running
*** [opt-ij____-tgt-ais-cmd-_i_] Error code 1 (ignored)
@@ -3505,7 +3462,6 @@ running
*** [opt-ij____-tgt-ais-cmd-a_s] Error code 1 (ignored)
opt-ij____-tgt-ais-cmd-ai_
-echo running; false
running
*** [opt-ij____-tgt-ais-cmd-ai_] Error code 1 (ignored)
@@ -3686,7 +3642,6 @@ opt-ij_n__-tgt-a_s-cmd-__s
running
opt-ij_n__-tgt-a_s-cmd-_i_
-echo running; false
running
opt-ij_n__-tgt-a_s-cmd-_is
@@ -3699,7 +3654,6 @@ opt-ij_n__-tgt-a_s-cmd-a_s
running
opt-ij_n__-tgt-a_s-cmd-ai_
-echo running; false
running
opt-ij_n__-tgt-a_s-cmd-ais
@@ -3740,7 +3694,6 @@ opt-ij_n__-tgt-ais-cmd-__s
running
opt-ij_n__-tgt-ais-cmd-_i_
-echo running; false
running
opt-ij_n__-tgt-ais-cmd-_is
@@ -3753,7 +3706,6 @@ opt-ij_n__-tgt-ais-cmd-a_s
running
opt-ij_n__-tgt-ais-cmd-ai_
-echo running; false
running
opt-ij_n__-tgt-ais-cmd-ais
@@ -3808,12 +3760,10 @@ running
*** [opt-ijl___-tgt-__s-cmd-__s] Error code 1 (ignored)
opt-ijl___-tgt-__s-cmd-_i_
-echo running; false
running
*** [opt-ijl___-tgt-__s-cmd-_i_] Error code 1 (ignored)
opt-ijl___-tgt-__s-cmd-_is
-echo running; false
running
*** [opt-ijl___-tgt-__s-cmd-_is] Error code 1 (ignored)
@@ -3826,12 +3776,10 @@ running
*** [opt-ijl___-tgt-__s-cmd-a_s] Error code 1 (ignored)
opt-ijl___-tgt-__s-cmd-ai_
-echo running; false
running
*** [opt-ijl___-tgt-__s-cmd-ai_] Error code 1 (ignored)
opt-ijl___-tgt-__s-cmd-ais
-echo running; false
running
*** [opt-ijl___-tgt-__s-cmd-ais] Error code 1 (ignored)
@@ -3884,12 +3832,10 @@ running
*** [opt-ijl___-tgt-_is-cmd-__s] Error code 1 (ignored)
opt-ijl___-tgt-_is-cmd-_i_
-echo running; false
running
*** [opt-ijl___-tgt-_is-cmd-_i_] Error code 1 (ignored)
opt-ijl___-tgt-_is-cmd-_is
-echo running; false
running
*** [opt-ijl___-tgt-_is-cmd-_is] Error code 1 (ignored)
@@ -3902,12 +3848,10 @@ running
*** [opt-ijl___-tgt-_is-cmd-a_s] Error code 1 (ignored)
opt-ijl___-tgt-_is-cmd-ai_
-echo running; false
running
*** [opt-ijl___-tgt-_is-cmd-ai_] Error code 1 (ignored)
opt-ijl___-tgt-_is-cmd-ais
-echo running; false
running
*** [opt-ijl___-tgt-_is-cmd-ais] Error code 1 (ignored)
@@ -3960,12 +3904,10 @@ running
*** [opt-ijl___-tgt-a_s-cmd-__s] Error code 1 (ignored)
opt-ijl___-tgt-a_s-cmd-_i_
-echo running; false
running
*** [opt-ijl___-tgt-a_s-cmd-_i_] Error code 1 (ignored)
opt-ijl___-tgt-a_s-cmd-_is
-echo running; false
running
*** [opt-ijl___-tgt-a_s-cmd-_is] Error code 1 (ignored)
@@ -3978,12 +3920,10 @@ running
*** [opt-ijl___-tgt-a_s-cmd-a_s] Error code 1 (ignored)
opt-ijl___-tgt-a_s-cmd-ai_
-echo running; false
running
*** [opt-ijl___-tgt-a_s-cmd-ai_] Error code 1 (ignored)
opt-ijl___-tgt-a_s-cmd-ais
-echo running; false
running
*** [opt-ijl___-tgt-a_s-cmd-ais] Error code 1 (ignored)
@@ -4036,12 +3976,10 @@ running
*** [opt-ijl___-tgt-ais-cmd-__s] Error code 1 (ignored)
opt-ijl___-tgt-ais-cmd-_i_
-echo running; false
running
*** [opt-ijl___-tgt-ais-cmd-_i_] Error code 1 (ignored)
opt-ijl___-tgt-ais-cmd-_is
-echo running; false
running
*** [opt-ijl___-tgt-ais-cmd-_is] Error code 1 (ignored)
@@ -4054,12 +3992,10 @@ running
*** [opt-ijl___-tgt-ais-cmd-a_s] Error code 1 (ignored)
opt-ijl___-tgt-ais-cmd-ai_
-echo running; false
running
*** [opt-ijl___-tgt-ais-cmd-ai_] Error code 1 (ignored)
opt-ijl___-tgt-ais-cmd-ais
-echo running; false
running
*** [opt-ijl___-tgt-ais-cmd-ais] Error code 1 (ignored)
@@ -4242,11 +4178,9 @@ opt-ijln__-tgt-a_s-cmd-__s
running
opt-ijln__-tgt-a_s-cmd-_i_
-echo running; false
running
opt-ijln__-tgt-a_s-cmd-_is
-echo running; false
running
opt-ijln__-tgt-a_s-cmd-a__
@@ -4256,11 +4190,9 @@ opt-ijln__-tgt-a_s-cmd-a_s
running
opt-ijln__-tgt-a_s-cmd-ai_
-echo running; false
running
opt-ijln__-tgt-a_s-cmd-ais
-echo running; false
running
opt-ijln__-tgt-ai_-cmd-___
@@ -4302,11 +4234,9 @@ opt-ijln__-tgt-ais-cmd-__s
running
opt-ijln__-tgt-ais-cmd-_i_
-echo running; false
running
opt-ijln__-tgt-ais-cmd-_is
-echo running; false
running
opt-ijln__-tgt-ais-cmd-a__
@@ -4316,10 +4246,8 @@ opt-ijln__-tgt-ais-cmd-a_s
running
opt-ijln__-tgt-ais-cmd-ai_
-echo running; false
running
opt-ijln__-tgt-ais-cmd-ais
-echo running; false
running
exit status 0
diff --git a/contrib/bmake/unit-tests/sh-leading-at.exp b/contrib/bmake/unit-tests/sh-leading-at.exp
index 8347fda085f7..8197a0d2b71a 100644
--- a/contrib/bmake/unit-tests/sh-leading-at.exp
+++ b/contrib/bmake/unit-tests/sh-leading-at.exp
@@ -3,4 +3,5 @@ space after @
echo 'echoed'
echoed
3
+whitespace in leading part
exit status 0
diff --git a/contrib/bmake/unit-tests/sh-leading-at.mk b/contrib/bmake/unit-tests/sh-leading-at.mk
index 9f98005ec088..cff3d4da1263 100644
--- a/contrib/bmake/unit-tests/sh-leading-at.mk
+++ b/contrib/bmake/unit-tests/sh-leading-at.mk
@@ -1,4 +1,4 @@
-# $NetBSD: sh-leading-at.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: sh-leading-at.mk,v 1.6 2023/01/19 19:55:27 rillig Exp $
#
# Tests for shell commands preceded by an '@', to suppress printing
# the command to stdout.
@@ -16,3 +16,7 @@ all:
# The leading '@' can be repeated.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@echo '3'
+
+ # Since 2023-01-17, the leading '@', '+' and '-' may contain
+ # whitespace, for compatibility with GNU make.
+ @ @ @ echo 'whitespace in leading part'
diff --git a/contrib/bmake/unit-tests/sh-leading-hyphen.exp b/contrib/bmake/unit-tests/sh-leading-hyphen.exp
index 39a9383953dd..50bcbbf9bb71 100644
--- a/contrib/bmake/unit-tests/sh-leading-hyphen.exp
+++ b/contrib/bmake/unit-tests/sh-leading-hyphen.exp
@@ -1 +1,11 @@
+true
+false
+*** Error code 1 (ignored)
+unknown-command 'needed for needshell in compat.c'
+unknown-command: not found
+*** Error code 127 (ignored)
+unknown-long-option 'needed for needshell in compat.c'
+unknown-long-option: not found
+*** Error code 127 (ignored)
+whitespace in leading part
exit status 0
diff --git a/contrib/bmake/unit-tests/sh-leading-hyphen.mk b/contrib/bmake/unit-tests/sh-leading-hyphen.mk
index d760abb9afdd..08b50a2ddc42 100644
--- a/contrib/bmake/unit-tests/sh-leading-hyphen.mk
+++ b/contrib/bmake/unit-tests/sh-leading-hyphen.mk
@@ -1,4 +1,4 @@
-# $NetBSD: sh-leading-hyphen.mk,v 1.3 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: sh-leading-hyphen.mk,v 1.4 2023/01/19 19:55:27 rillig Exp $
#
# Tests for shell commands preceded by a '-', to ignore the exit status of
# the command line.
@@ -11,4 +11,19 @@
# TODO: Implementation
all:
- @:;
+ -true
+ -false
+
+ # An undefined variable expands to an empty string, without warning.
+ # This is used in practice for prefixing tool names or for DESTDIR.
+ # The '-' before 'unknown' is interpreted by make as '.IGNORE' flag.
+ ${UNDEF}-unknown-command 'needed for needshell in compat.c'
+
+ # Expanding undefined variables may lead to strange error messages
+ # when the shell interprets single-character options as commands
+ # instead.
+ ${UNDEF} --unknown-long-option 'needed for needshell in compat.c'
+
+ # Since 2023-01-17, the leading '@', '+' and '-' may contain
+ # whitespace, for compatibility with GNU make.
+ - - - @echo 'whitespace in leading part'
diff --git a/contrib/bmake/unit-tests/sh-leading-plus.exp b/contrib/bmake/unit-tests/sh-leading-plus.exp
index eb586d29f1c2..8cc26deaacb5 100644
--- a/contrib/bmake/unit-tests/sh-leading-plus.exp
+++ b/contrib/bmake/unit-tests/sh-leading-plus.exp
@@ -1,4 +1,6 @@
echo 'this command is not run'
echo 'this command is run'
this command is run
+echo 'whitespace in leading part'
+whitespace in leading part
exit status 0
diff --git a/contrib/bmake/unit-tests/sh-leading-plus.mk b/contrib/bmake/unit-tests/sh-leading-plus.mk
index ff57b4a38a7d..83e7e7a15e24 100644
--- a/contrib/bmake/unit-tests/sh-leading-plus.mk
+++ b/contrib/bmake/unit-tests/sh-leading-plus.mk
@@ -1,4 +1,4 @@
-# $NetBSD: sh-leading-plus.mk,v 1.4 2020/11/09 20:50:56 rillig Exp $
+# $NetBSD: sh-leading-plus.mk,v 1.5 2023/01/19 19:55:27 rillig Exp $
#
# Tests for shell commands preceded by a '+', to run them even if
# the command line option -n is given.
@@ -8,3 +8,7 @@
all:
@echo 'this command is not run'
@+echo 'this command is run'
+
+ # Since 2023-01-17, the leading '@', '+' and '-' may contain
+ # whitespace, for compatibility with GNU make.
+ + + + @echo 'whitespace in leading part'
diff --git a/contrib/bmake/unit-tests/sh.mk b/contrib/bmake/unit-tests/sh.mk
index f79a4099e990..3bbedf4d678a 100644
--- a/contrib/bmake/unit-tests/sh.mk
+++ b/contrib/bmake/unit-tests/sh.mk
@@ -1,7 +1,10 @@
-# $NetBSD: sh.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: sh.mk,v 1.3 2022/01/23 16:09:38 rillig Exp $
#
# Tests for running shell commands from the targets, or from the != variable
# assignment operator or the :sh variable modifier.
+#
+# See also:
+# var-op-shell.mk for the assignment operator '!='
# TODO: Implementation
diff --git a/contrib/bmake/unit-tests/shell-sh.mk b/contrib/bmake/unit-tests/shell-sh.mk
index b3d4f18bbac9..5f7b04716ee1 100644
--- a/contrib/bmake/unit-tests/shell-sh.mk
+++ b/contrib/bmake/unit-tests/shell-sh.mk
@@ -1,9 +1,9 @@
-# $NetBSD: shell-sh.mk,v 1.1 2020/10/03 14:39:36 rillig Exp $
+# $NetBSD: shell-sh.mk,v 1.2 2023/12/24 16:48:30 sjg Exp $
#
# Tests for using a bourne shell for running the commands.
# This is the default shell, so there's nothing surprising.
-.SHELL: name="sh" path="sh"
+.SHELL: name="sh"
all:
: normal
diff --git a/contrib/bmake/unit-tests/suff-incomplete.exp b/contrib/bmake/unit-tests/suff-incomplete.exp
index 2331436d378e..acb5f0542dbe 100644
--- a/contrib/bmake/unit-tests/suff-incomplete.exp
+++ b/contrib/bmake/unit-tests/suff-incomplete.exp
@@ -1,17 +1,17 @@
-ParseReadLine (9): '.SUFFIXES:'
+Parsing line 9: .SUFFIXES:
ParseDependency(.SUFFIXES:)
Clearing all suffixes
-ParseReadLine (11): '.SUFFIXES: .a .b .c'
+Parsing line 11: .SUFFIXES: .a .b .c
ParseDependency(.SUFFIXES: .a .b .c)
Adding suffix ".a"
Adding suffix ".b"
Adding suffix ".c"
-ParseReadLine (17): '.a.b:'
+Parsing line 17: .a.b:
ParseDependency(.a.b:)
defining transformation from `.a' to `.b'
inserting ".a" (1) at end of list
inserting ".b" (2) at end of list
-ParseReadLine (21): '.a.c: ${.PREFIX}.dependency'
+Parsing line 21: .a.c: ${.PREFIX}.dependency
deleting incomplete transformation from `.a' to `.b'
ParseDependency(.a.c: ${.PREFIX}.dependency)
defining transformation from `.a' to `.c'
@@ -20,10 +20,10 @@ inserting ".c" (3) at end of list
# LinkSource: added child .a.c - ${.PREFIX}.dependency
# .a.c, unmade, type OP_DEPENDS|OP_TRANSFORM, flags none
# ${.PREFIX}.dependency, unmade, type none, flags none
-ParseReadLine (23): '.DEFAULT:'
+Parsing line 23: .DEFAULT:
transformation .a.c complete
ParseDependency(.DEFAULT:)
-ParseReadLine (24): ' : Making ${.TARGET} from ${.IMPSRC} all ${.ALLSRC} by default.'
+Parsing line 24: : Making ${.TARGET} from ${.IMPSRC} all ${.ALLSRC} by default.
transformation .DEFAULT complete
Wildcard expanding "all"...
SuffFindDeps "all"
diff --git a/contrib/bmake/unit-tests/suff-main-several.exp b/contrib/bmake/unit-tests/suff-main-several.exp
index 09fa6d63bffa..4391610be742 100644
--- a/contrib/bmake/unit-tests/suff-main-several.exp
+++ b/contrib/bmake/unit-tests/suff-main-several.exp
@@ -1,11 +1,11 @@
-ParseReadLine (8): '.1.2 .1.3 .1.4:'
+Parsing line 8: .1.2 .1.3 .1.4:
ParseDependency(.1.2 .1.3 .1.4:)
Setting main node to ".1.2"
-ParseReadLine (9): ' : Making ${.TARGET} from ${.IMPSRC}.'
-ParseReadLine (14): 'next-main:'
+Parsing line 9: : Making ${.TARGET} from ${.IMPSRC}.
+Parsing line 14: next-main:
ParseDependency(next-main:)
-ParseReadLine (15): ' : Making ${.TARGET}'
-ParseReadLine (19): '.SUFFIXES: .1 .2 .3 .4'
+Parsing line 15: : Making ${.TARGET}
+Parsing line 19: .SUFFIXES: .1 .2 .3 .4
ParseDependency(.SUFFIXES: .1 .2 .3 .4)
Adding suffix ".1"
Adding suffix ".2"
@@ -26,42 +26,42 @@ defining transformation from `.1' to `.4'
inserting ".1" (1) at end of list
inserting ".4" (4) at end of list
Setting main node to "next-main"
-ParseReadLine (24): '.SUFFIXES:'
+Parsing line 24: .SUFFIXES:
ParseDependency(.SUFFIXES:)
Clearing all suffixes
-ParseReadLine (32): '.SUFFIXES: .4 .3 .2 .1'
+Parsing line 32: .SUFFIXES: .4 .3 .2 .1
ParseDependency(.SUFFIXES: .4 .3 .2 .1)
Adding suffix ".4"
Adding suffix ".3"
Adding suffix ".2"
Adding suffix ".1"
-ParseReadLine (33): '.SUFFIXES:'
+Parsing line 33: .SUFFIXES:
ParseDependency(.SUFFIXES:)
Clearing all suffixes
-ParseReadLine (34): '.SUFFIXES: .1 .2 .3 .4'
+Parsing line 34: .SUFFIXES: .1 .2 .3 .4
ParseDependency(.SUFFIXES: .1 .2 .3 .4)
Adding suffix ".1"
Adding suffix ".2"
Adding suffix ".3"
Adding suffix ".4"
-ParseReadLine (35): '.SUFFIXES:'
+Parsing line 35: .SUFFIXES:
ParseDependency(.SUFFIXES:)
Clearing all suffixes
-ParseReadLine (36): '.SUFFIXES: .4 .3 .2 .1'
+Parsing line 36: .SUFFIXES: .4 .3 .2 .1
ParseDependency(.SUFFIXES: .4 .3 .2 .1)
Adding suffix ".4"
Adding suffix ".3"
Adding suffix ".2"
Adding suffix ".1"
-ParseReadLine (38): 'suff-main-several.1:'
+Parsing line 38: suff-main-several.1:
ParseDependency(suff-main-several.1:)
-ParseReadLine (39): ' : Making ${.TARGET} out of nothing.'
-ParseReadLine (40): 'next-main: suff-main-several.{2,3,4}'
+Parsing line 39: : Making ${.TARGET} out of nothing.
+Parsing line 40: next-main: suff-main-several.{2,3,4}
ParseDependency(next-main: suff-main-several.{2,3,4})
# LinkSource: added child next-main - suff-main-several.{2,3,4}
# next-main, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
# suff-main-several.{2,3,4}, unmade, type none, flags none
-ParseReadLine (42): '.MAKEFLAGS: -d0 -dg1'
+Parsing line 42: .MAKEFLAGS: -d0 -dg1
ParseDependency(.MAKEFLAGS: -d0 -dg1)
#*** Input graph:
# .1.2, unmade, type OP_TRANSFORM, flags none
@@ -81,11 +81,12 @@ ParseDependency(.MAKEFLAGS: -d0 -dg1)
#*** Global Variables:
.ALLTARGETS = .1.2 .1.3 .1.4 next-main suff-main-several.1 suff-main-several.{2,3,4}
.CURDIR = <curdir>
-.INCLUDES =
-.LIBS =
+.INCLUDES = # (empty)
+.LIBS = # (empty)
.MAKE = <details omitted>
.MAKE.DEPENDFILE = <details omitted>
.MAKE.GID = <details omitted>
+.MAKE.JOBS.C = <details omitted>
.MAKE.LEVEL = <details omitted>
.MAKE.MAKEFILES = <details omitted>
.MAKE.MAKEFILE_PREFERENCE = <details omitted>
@@ -94,12 +95,12 @@ ParseDependency(.MAKEFLAGS: -d0 -dg1)
.MAKE.PPID = <details omitted>
.MAKE.UID = <details omitted>
.MAKEFLAGS = -r -k -d mps -d 0 -d g1
-.MAKEOVERRIDES =
+.MAKEOVERRIDES = # (empty)
.OBJDIR = <curdir>
.PATH = . <curdir>
-.TARGETS =
+.TARGETS = # (empty)
.newline =
-
+# (ends with space)
MACHINE = <details omitted>
MACHINE_ARCH = <details omitted>
MAKE = <details omitted>
@@ -111,7 +112,6 @@ MFLAGS = -r -k -d mps -d 0 -d g1
# Stats: 0 hits 2 misses 0 near misses 0 losers (0%)
# refs hits directory
# 1 0 <curdir>
-# 1 0 .
#*** Suffixes:
# ".4" (num 1, ref 1)
diff --git a/contrib/bmake/unit-tests/suff-rebuild.exp b/contrib/bmake/unit-tests/suff-rebuild.exp
index 7ef53ae2e151..8c0979537524 100644
--- a/contrib/bmake/unit-tests/suff-rebuild.exp
+++ b/contrib/bmake/unit-tests/suff-rebuild.exp
@@ -1,36 +1,36 @@
-ParseReadLine (10): '.SUFFIXES:'
+Parsing line 10: .SUFFIXES:
ParseDependency(.SUFFIXES:)
Clearing all suffixes
-ParseReadLine (12): '.SUFFIXES: .a .b .c'
+Parsing line 12: .SUFFIXES: .a .b .c
ParseDependency(.SUFFIXES: .a .b .c)
Adding suffix ".a"
Adding suffix ".b"
Adding suffix ".c"
-ParseReadLine (14): 'suff-rebuild-example.a:'
+Parsing line 14: suff-rebuild-example.a:
ParseDependency(suff-rebuild-example.a:)
Adding "suff-rebuild-example.a" to all targets.
-ParseReadLine (15): ' : Making ${.TARGET} out of nothing.'
-ParseReadLine (17): '.a.b:'
+Parsing line 15: : Making ${.TARGET} out of nothing.
+Parsing line 17: .a.b:
ParseDependency(.a.b:)
defining transformation from `.a' to `.b'
inserting ".a" (1) at end of list
inserting ".b" (2) at end of list
-ParseReadLine (18): ' : Making ${.TARGET} from ${.IMPSRC}.'
-ParseReadLine (19): '.b.c:'
+Parsing line 18: : Making ${.TARGET} from ${.IMPSRC}.
+Parsing line 19: .b.c:
transformation .a.b complete
ParseDependency(.b.c:)
defining transformation from `.b' to `.c'
inserting ".b" (2) at end of list
inserting ".c" (3) at end of list
-ParseReadLine (20): ' : Making ${.TARGET} from ${.IMPSRC}.'
-ParseReadLine (21): '.c:'
+Parsing line 20: : Making ${.TARGET} from ${.IMPSRC}.
+Parsing line 21: .c:
transformation .b.c complete
ParseDependency(.c:)
defining transformation from `.c' to `'
inserting ".c" (3) at end of list
inserting "" (0) at end of list
-ParseReadLine (22): ' : Making ${.TARGET} from ${.IMPSRC}.'
-ParseReadLine (44): '.SUFFIXES: .c .b .a'
+Parsing line 22: : Making ${.TARGET} from ${.IMPSRC}.
+Parsing line 44: .SUFFIXES: .c .b .a
transformation .c complete
ParseDependency(.SUFFIXES: .c .b .a)
Adding ".END" to all targets.
diff --git a/contrib/bmake/unit-tests/suff-transform-debug.exp b/contrib/bmake/unit-tests/suff-transform-debug.exp
index 0634ff616d0d..5d632a22f80a 100644
--- a/contrib/bmake/unit-tests/suff-transform-debug.exp
+++ b/contrib/bmake/unit-tests/suff-transform-debug.exp
@@ -7,11 +7,12 @@
#*** Global Variables:
.ALLTARGETS = all
.CURDIR = <curdir>
-.INCLUDES =
-.LIBS =
+.INCLUDES = # (empty)
+.LIBS = # (empty)
.MAKE = <details omitted>
.MAKE.DEPENDFILE = <details omitted>
.MAKE.GID = <details omitted>
+.MAKE.JOBS.C = <details omitted>
.MAKE.LEVEL = <details omitted>
.MAKE.MAKEFILES = <details omitted>
.MAKE.MAKEFILE_PREFERENCE = <details omitted>
@@ -20,12 +21,12 @@
.MAKE.PPID = <details omitted>
.MAKE.UID = <details omitted>
.MAKEFLAGS = -r -k -d g1
-.MAKEOVERRIDES =
+.MAKEOVERRIDES = # (empty)
.OBJDIR = <curdir>
.PATH = . <curdir>
-.TARGETS =
+.TARGETS = # (empty)
.newline =
-
+# (ends with space)
MACHINE = <details omitted>
MACHINE_ARCH = <details omitted>
MAKE = <details omitted>
@@ -37,7 +38,6 @@ MFLAGS = -r -k -d g1
# Stats: 0 hits 2 misses 0 near misses 0 losers (0%)
# refs hits directory
# 1 0 <curdir>
-# 1 0 .
#*** Suffixes:
# ".a" (num 1, ref 2)
diff --git a/contrib/bmake/unit-tests/suff-use.exp b/contrib/bmake/unit-tests/suff-use.exp
new file mode 100644
index 000000000000..4a9374d8e156
--- /dev/null
+++ b/contrib/bmake/unit-tests/suff-use.exp
@@ -0,0 +1,7 @@
+: 'Making demo.c out of nothing'
+make: don't know how to make demo.o (continuing)
+`all' not remade because of errors.
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/suff-use.mk b/contrib/bmake/unit-tests/suff-use.mk
new file mode 100644
index 000000000000..b648545e1f5c
--- /dev/null
+++ b/contrib/bmake/unit-tests/suff-use.mk
@@ -0,0 +1,50 @@
+# $NetBSD: suff-use.mk,v 1.2 2022/02/09 21:09:24 rillig Exp $
+#
+# This test combines a .USE node with suffix rules, trying to add an
+# additional command before and after successful compilation of a .c file.
+#
+# History:
+# make-2001.11.12.21.58.18
+# | : 'Making demo.c out of nothing'
+# | make: don't know how to make demo.o. Stop
+# |
+# | make: stopped in <curdir>
+# | exit status 2
+# make-2007.10.11.21.19.28
+#
+# make-2014.08.23.15.05.40
+# | : 'Making demo.c out of nothing'
+# | : 'Compiling demo.c to demo.o'
+# | exit status 0
+# make-2014.09.05.06.57.20
+#
+# make-2014.09.07.20.55.34
+# | : 'Making demo.c out of nothing'
+# | make: don't know how to make demo.o. Stop
+# |
+# | make: stopped in <curdir>
+# | exit status 2
+# ...
+#
+# See also:
+# https://gnats.netbsd.org/20993
+
+
+.SUFFIXES: .c .o
+
+all: demo.o
+
+.c.o:
+ : 'Compiling ${.IMPSRC} to ${.TARGET}'
+
+demo.c:
+ : 'Making ${.TARGET} out of nothing'
+
+using-before: .USEBEFORE
+ : 'Before making ${.TARGET} from ${.ALLSRCS}'
+
+using-after: .USE
+ : 'After making ${.TARGET} from ${.ALLSRCS}'
+
+# expect: make: don't know how to make demo.o (continuing)
+.c.o: using-before using-after
diff --git a/contrib/bmake/unit-tests/unexport.mk b/contrib/bmake/unit-tests/unexport.mk
index 4363aaac3eee..4bcc5b21ca02 100644
--- a/contrib/bmake/unit-tests/unexport.mk
+++ b/contrib/bmake/unit-tests/unexport.mk
@@ -1,4 +1,4 @@
-# $NetBSD: unexport.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: unexport.mk,v 1.6 2023/10/19 18:24:33 rillig Exp $
# pick up a bunch of exported vars
FILTER_CMD= grep ^UT_
@@ -10,7 +10,7 @@ UT_TEST= unexport
# Until 2020-08-08, Var_UnExport had special handling for '\n', that code
# was not reachable though. At that point, backslash-newline has already
-# been replaced with a simple space, and variables are not yet expanded.
+# been replaced with a simple space, and expressions are not yet expanded.
UT_BEFORE_NL= before
UT_AFTER_NL= after
.export UT_BEFORE_NL UT_AFTER_NL
diff --git a/contrib/bmake/unit-tests/var-class-cmdline.exp b/contrib/bmake/unit-tests/var-class-cmdline.exp
deleted file mode 100644
index 6df2155ca7eb..000000000000
--- a/contrib/bmake/unit-tests/var-class-cmdline.exp
+++ /dev/null
@@ -1,4 +0,0 @@
-make: "var-class-cmdline.mk" line 67: global
-make: "var-class-cmdline.mk" line 76: makeflags
-makeflags
-exit status 0
diff --git a/contrib/bmake/unit-tests/var-class-global.mk b/contrib/bmake/unit-tests/var-class-global.mk
deleted file mode 100644
index 81345ffda463..000000000000
--- a/contrib/bmake/unit-tests/var-class-global.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-# $NetBSD: var-class-global.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
-#
-# Tests for global variables, which are the most common variables.
-
-# TODO: Implementation
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/var-class-local-legacy.mk b/contrib/bmake/unit-tests/var-class-local-legacy.mk
deleted file mode 100644
index bfd9733fd42b..000000000000
--- a/contrib/bmake/unit-tests/var-class-local-legacy.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-# $NetBSD: var-class-local-legacy.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
-#
-# Tests for legacy target-local variables, such as ${<F} or ${@D}.
-
-# TODO: Implementation
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/var-class-local.exp b/contrib/bmake/unit-tests/var-class-local.exp
deleted file mode 100644
index db85b47cae06..000000000000
--- a/contrib/bmake/unit-tests/var-class-local.exp
+++ /dev/null
@@ -1,5 +0,0 @@
-: Making var-class-local.c out of nothing.
-: Making var-class-local.o from var-class-local.c.
-: Making basename "var-class-local.o" in "." from "var-class-local.c" in ".".
-: all overwritten
-exit status 0
diff --git a/contrib/bmake/unit-tests/var-class-local.mk b/contrib/bmake/unit-tests/var-class-local.mk
deleted file mode 100644
index f9d56e539ff0..000000000000
--- a/contrib/bmake/unit-tests/var-class-local.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-# $NetBSD: var-class-local.mk,v 1.5 2020/11/05 18:08:39 rillig Exp $
-#
-# Tests for target-local variables, such as ${.TARGET} or $@.
-
-# TODO: Implementation
-
-# Ensure that the name of the variable is exactly the given one.
-# The variable "@" is an alias for ".TARGET", so the implementation might
-# canonicalize these aliases at some point, and that might be surprising.
-# This aliasing happens for single-character variable names like $@ or $<
-# (see VarFind, CanonicalVarname), but not for braced or parenthesized
-# expressions like ${@}, ${.TARGET} ${VAR:Mpattern} (see Var_Parse,
-# ParseVarname).
-.if ${@:L} != "@"
-. error
-.endif
-.if ${.TARGET:L} != ".TARGET"
-. error
-.endif
-.if ${@F:L} != "@F"
-. error
-.endif
-.if ${@D:L} != "@D"
-. error
-.endif
-
-all:
-
-.SUFFIXES: .c .o
-
-var-class-local.c:
- : Making ${.TARGET} out of nothing.
-
-.c.o:
- : Making ${.TARGET} from ${.IMPSRC}.
-
- # The local variables @F, @D, <F, <D are legacy forms.
- # See the manual page for details.
- : Making basename "${@F}" in "${@D}" from "${<F}" in "${<D}".
-
-all: var-class-local.o
- # The ::= modifier overwrites the .TARGET variable in the node
- # 'all', not in the global scope. This can be seen with the -dv
- # option, looking for "all:@ = overwritten".
- : ${.TARGET} ${.TARGET::=overwritten}${.TARGET}
diff --git a/contrib/bmake/unit-tests/var-class.mk b/contrib/bmake/unit-tests/var-class.mk
deleted file mode 100644
index b20fca565e16..000000000000
--- a/contrib/bmake/unit-tests/var-class.mk
+++ /dev/null
@@ -1,9 +0,0 @@
-# $NetBSD: var-class.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
-#
-# Tests for the different variable classes (local, command-line, global,
-# environment), and which of them takes precedence over the others.
-
-# TODO: Implementation
-
-all:
- @:;
diff --git a/contrib/bmake/unit-tests/var-eval-short.exp b/contrib/bmake/unit-tests/var-eval-short.exp
index ae0aff7d7c2c..14e3d372f198 100644
--- a/contrib/bmake/unit-tests/var-eval-short.exp
+++ b/contrib/bmake/unit-tests/var-eval-short.exp
@@ -1,26 +1,26 @@
-make: "var-eval-short.mk" line 41: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar.
-make: "var-eval-short.mk" line 41: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
-make: "var-eval-short.mk" line 79: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 79: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
-make: "var-eval-short.mk" line 93: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 93: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
+make: "var-eval-short.mk" line 46: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar
+make: "var-eval-short.mk" line 46: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
Parsing modifier ${0:?...}
+Var_Parse: ${FAIL}then:${FAIL}else} (parse-only)
Modifier part: "${FAIL}then"
+Var_Parse: ${FAIL}else} (parse-only)
Modifier part: "${FAIL}else"
Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
-ParseReadLine (158): 'DEFINED= defined'
+Parsing line 167: DEFINED= defined
Global: DEFINED = defined
CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
Parsing modifier ${DEFINED:L}
Result of ${DEFINED:L} is "defined" (parse-only, regular)
Parsing modifier ${DEFINED:?...}
+Var_Parse: ${FAIL}then:${FAIL}else} (parse-only)
Modifier part: "${FAIL}then"
+Var_Parse: ${FAIL}else} (parse-only)
Modifier part: "${FAIL}else"
Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
-ParseReadLine (161): '.MAKEFLAGS: -d0'
+Parsing line 170: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d cpv -d
Global: .MAKEFLAGS = -r -k -d cpv -d 0
diff --git a/contrib/bmake/unit-tests/var-eval-short.mk b/contrib/bmake/unit-tests/var-eval-short.mk
index 41782f0d7823..2b25d82e96b8 100644
--- a/contrib/bmake/unit-tests/var-eval-short.mk
+++ b/contrib/bmake/unit-tests/var-eval-short.mk
@@ -1,12 +1,13 @@
-# $NetBSD: var-eval-short.mk,v 1.5 2021/04/04 13:35:26 rillig Exp $
+# $NetBSD: var-eval-short.mk,v 1.11 2023/10/19 18:24:33 rillig Exp $
#
# Tests for each variable modifier to ensure that they only do the minimum
-# necessary computations. If the result of the expression is not needed, they
-# should only parse the modifier but not actually evaluate it.
+# necessary computations. If the result of the expression is irrelevant,
+# the modifier should only be parsed. The modifier should not be evaluated,
+# but if it is evaluated for simplicity of the code (such as ':ts'), it must
+# not have any observable side effects.
#
# See also:
# var.c, the comment starting with 'The ApplyModifier functions'
-# ApplyModifier, for the order of the modifiers
# ParseModifierPart, for evaluating nested expressions
# cond-short.mk
@@ -17,6 +18,8 @@ FAIL= ${:!echo unexpected 1>&2!}
# is ignored as well. To do that, it is necessary to step through the code of
# each modifier.
+# TODO: Test the modifiers in the same order as they occur in ApplyModifier.
+
.if 0 && ${FAIL}
.endif
@@ -38,19 +41,21 @@ FAIL= ${:!echo unexpected 1>&2!}
# after the loop, when undefining the temporary global loop variable.
# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
# variable name.
+# expect+2: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar
+# expect+1: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
.if 0 && ${:Uword:@${FAIL}@expr@}
.endif
.if 0 && ${:Uword:@var@${FAIL}@}
.endif
-# Before var.c,v 1.877 from 2021-03-14, the modifier ':[...]' did not expand
+# Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand
# the nested expression ${FAIL} and then tried to parse the unexpanded text,
# which failed since '$' is not a valid range character.
.if 0 && ${:Uword:[${FAIL}]}
.endif
-# Before var.c,v 1.867 from 2021-03-14, the modifier ':_' defined the variable
+# Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable
# even though the whole expression should have only been parsed, not
# evaluated.
.if 0 && ${:Uword:_=VAR}
@@ -58,11 +63,13 @@ FAIL= ${:!echo unexpected 1>&2!}
. error
.endif
-# Before var.c,v 1.856 from 2021-03-14, the modifier ':C' did not expand the
-# nested expression ${FAIL} and then tried to compile the unexpanded text as a
-# regular expression, which failed both because of the '{FAIL}', which is not
-# a valid repetition, and because of the '****', which are repeated
-# repetitions as well.
+# Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the
+# nested expression ${FAIL}, which is correct, and then tried to compile the
+# unexpanded text as a regular expression, which is unnecessary since the
+# right-hand side of the '&&' cannot influence the outcome of the condition.
+# Compiling the regular expression then failed both because of the '{FAIL}',
+# which is not a valid repetition of the form '{1,5}', and because of the
+# '****', which are repeated repetitions as well.
# '${FAIL}'
.if 0 && ${:Uword:C,${FAIL}****,,}
.endif
@@ -74,8 +81,9 @@ DEFINED= # defined
.if 0 && ${:Uword:E}
.endif
-# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since
-# ':gmtime' does not expand its argument.
+# Before var.c 1.1050 from 2023-05-09, the ':gmtime' modifier produced the
+# error message 'Invalid time value: ${FAIL}}' since it did not expand its
+# argument.
.if 0 && ${:Uword:gmtime=${FAIL}}
.endif
@@ -88,8 +96,9 @@ DEFINED= # defined
.if 0 && ${value:L}
.endif
-# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since
-# ':localtime' does not expand its argument.
+# Before var.c 1.1050 from 2023-05-09, the ':localtime' modifier produced the
+# error message 'Invalid time value: ${FAIL}}' since it did not expand its
+# argument.
.if 0 && ${:Uword:localtime=${FAIL}}
.endif
diff --git a/contrib/bmake/unit-tests/var-op-append.mk b/contrib/bmake/unit-tests/var-op-append.mk
index 420ee376b75d..e16b89139cc1 100644
--- a/contrib/bmake/unit-tests/var-op-append.mk
+++ b/contrib/bmake/unit-tests/var-op-append.mk
@@ -1,7 +1,20 @@
-# $NetBSD: var-op-append.mk,v 1.9 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: var-op-append.mk,v 1.12 2023/11/02 05:46:26 rillig Exp $
#
-# Tests for the += variable assignment operator, which appends to a variable,
-# creating it if necessary.
+# Tests for the '+=' variable assignment operator, which appends to a
+# variable, creating it if necessary.
+#
+# See also
+# var-op.mk
+#
+# Standards
+# The '+=' variable assignment operator is planned to be added in
+# POSIX.1-202x.
+#
+# This implementation does not support the immediate-expansion macros
+# specified in POSIX.1-202x. All variables are delayed-expansion.
+#
+# History
+# The '+=' variable assignment operator was added before 1993-03-21.
# Appending to an undefined variable is possible.
# The variable is created, and no extra space is added before the value.
@@ -26,7 +39,7 @@ VAR+= # empty
# '+=' assignment operator. As far as possible, the '+' is interpreted as
# part of the assignment operator.
#
-# See Parse_Var
+# See Parse_Var, AdjustVarassignOp.
C++= value
.if ${C+} != "value" || defined(C++)
. error
@@ -43,4 +56,33 @@ VAR.${:U\$\$\$\$\$\$\$\$}+= dollars
. error
.endif
+
+# Appending to an environment variable in the global scope creates a global
+# variable of the same name, taking its initial value from the environment
+# variable. After the assignment, the environment variable is left as-is,
+# the value of the global variable is not synced back to the environment
+# variable.
+export ENV_PLUS_GLOBAL=from-env-value
+ENV_PLUS_GLOBAL+= appended-value
+.if ${ENV_PLUS_GLOBAL} != "from-env-value appended-value"
+. error
+.endif
+EXPORTED!= echo "$$ENV_PLUS_GLOBAL"
+.if ${EXPORTED} != "from-env-value"
+. error
+.endif
+
+# Appending to an environment variable in the command line scope ignores the
+# environment variable.
+export ENV_PLUS_COMMAND=from-env-value
+.MAKEFLAGS: ENV_PLUS_COMMAND+=appended-command
+.if ${ENV_PLUS_COMMAND} != "appended-command"
+. error ${ENV_PLUS_COMMAND}
+.endif
+EXPORTED!= echo "$$ENV_PLUS_GLOBAL"
+.if ${EXPORTED} != "from-env-value"
+. error
+.endif
+
+
all:
diff --git a/contrib/bmake/unit-tests/var-op-assign.exp b/contrib/bmake/unit-tests/var-op-assign.exp
index 73e580403d78..5fad47ca67c4 100644
--- a/contrib/bmake/unit-tests/var-op-assign.exp
+++ b/contrib/bmake/unit-tests/var-op-assign.exp
@@ -1,6 +1,6 @@
this will be evaluated later
-make: "var-op-assign.mk" line 59: Invalid line type
-make: "var-op-assign.mk" line 93: Parsing still continues until here.
+make: "var-op-assign.mk" line 60: Invalid line 'VARIABLE NAME= variable value'
+make: "var-op-assign.mk" line 95: Parsing still continues until here.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/var-op-assign.mk b/contrib/bmake/unit-tests/var-op-assign.mk
index 18ecf8d0d5ed..a900c28a918d 100644
--- a/contrib/bmake/unit-tests/var-op-assign.mk
+++ b/contrib/bmake/unit-tests/var-op-assign.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-assign.mk,v 1.8 2021/03/15 19:15:04 rillig Exp $
+# $NetBSD: var-op-assign.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the = variable assignment operator, which overwrites an existing
# variable or creates it.
@@ -56,6 +56,7 @@ VAR= ${:! echo 'this will be evaluated later' 1>&2 !}
# In a variable assignment, the variable name must consist of a single word.
# The following line therefore generates a parse error.
+# expect+1: Invalid line 'VARIABLE NAME= variable value'
VARIABLE NAME= variable value
# But if the whitespace appears inside parentheses or braces, everything is
@@ -65,7 +66,7 @@ VARIABLE NAME= variable value
# neither contain parentheses nor braces. This is only a side-effect from
# the implementation of the parser, which cheats when parsing a variable
# name. It only counts parentheses and braces instead of properly parsing
-# nested variable expressions such as VAR.${param}.
+# nested expressions such as VAR.${param}.
#
VAR(spaces in parentheses)= ()
VAR{spaces in braces}= {}
@@ -90,6 +91,7 @@ VARNAME_BRACES= VAR{spaces in braces}
# unexpected variable values.
#
# Therefore, just output an info message.
+# expect+1: Parsing still continues until here.
.info Parsing still continues until here.
all:
diff --git a/contrib/bmake/unit-tests/var-op-default.mk b/contrib/bmake/unit-tests/var-op-default.mk
index ca4fbcc27c88..9d07ddf39e41 100644
--- a/contrib/bmake/unit-tests/var-op-default.mk
+++ b/contrib/bmake/unit-tests/var-op-default.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-default.mk,v 1.3 2020/12/07 21:35:43 rillig Exp $
+# $NetBSD: var-op-default.mk,v 1.5 2023/11/19 22:32:44 rillig Exp $
#
# Tests for the ?= variable assignment operator, which only assigns
# if the variable is still undefined.
@@ -45,7 +45,7 @@ i?= default
# and 'VAR.${param}' expand to 'VAR.param', and the second '?=' assignment
# has no effect.
#
-# Since 2000.05.11.07.43.42 it has been possible to use nested variable
+# Since 2000.05.11.07.43.42 it has been possible to use nested
# expressions in variable names, which made make much more versatile.
# On 2008.03.31.00.12.21, this particular case of the '?=' operator has been
# fixed. Before, the '?=' operator had not expanded the variable name
@@ -61,8 +61,8 @@ VAR.${:Uparam}?= not used
# Now demonstrate that the variable name is indeed expanded exactly once.
# This is tricky to measure correctly since there are many inconsistencies
-# in and around the code that expands variable expressions in the various
-# places where variable expressions can occur. If in doubt, enable the
+# in and around the code that expands expressions in the various
+# places where expressions can occur. If in doubt, enable the
# following debug flags to see what happens:
#.MAKEFLAGS: -dcpv
EXPAND_NAME= EXPAND.$$$$ # The full variable name is EXPAND.$$
diff --git a/contrib/bmake/unit-tests/var-op-expand.exp b/contrib/bmake/unit-tests/var-op-expand.exp
index 39a9383953dd..5ea4e6b6954c 100644
--- a/contrib/bmake/unit-tests/var-op-expand.exp
+++ b/contrib/bmake/unit-tests/var-op-expand.exp
@@ -1 +1,7 @@
-exit status 0
+make: "var-op-expand.mk" line 274: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 278: warning: XXX Neither branch should be taken.
+make: "var-op-expand.mk" line 283: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 285: warning: XXX Neither branch should be taken.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/var-op-expand.mk b/contrib/bmake/unit-tests/var-op-expand.mk
index ff62668a8ada..76b90bf72b56 100644
--- a/contrib/bmake/unit-tests/var-op-expand.mk
+++ b/contrib/bmake/unit-tests/var-op-expand.mk
@@ -1,9 +1,15 @@
-# $NetBSD: var-op-expand.mk,v 1.11 2021/01/01 23:07:48 sjg Exp $
+# $NetBSD: var-op-expand.mk,v 1.19 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the := variable assignment operator, which expands its
# right-hand side.
+#
+# See also:
+# varname-dot-make-save_dollars.mk
-.MAKE.SAVE_DOLLARS:= yes
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
+.MAKE.SAVE_DOLLARS:= yes
# If the right-hand side does not contain a dollar sign, the ':=' assignment
# operator has the same effect as the '=' assignment operator.
@@ -14,9 +20,9 @@ VAR:= value
# When a ':=' assignment is performed, its right-hand side is evaluated and
# expanded as far as possible. Contrary to other situations, '$$' and
-# variable expressions based on undefined variables are preserved though.
+# expressions based on undefined variables are preserved though.
#
-# Whether a variable expression is undefined or not is determined at the end
+# Whether an expression is undefined or not is determined at the end
# of evaluating the expression. The consequence is that ${:Ufallback} expands
# to "fallback"; initially this expression is undefined since it is based on
# the variable named "", which is guaranteed to be never defined, but at the
@@ -31,7 +37,7 @@ VAR:= $$ $$$$ $$$$$$$$
.endif
-# reference to a variable containing a literal dollar sign
+# reference to a variable containing literal dollar signs
REF= $$ $$$$ $$$$$$$$
VAR:= ${REF}
REF= too late
@@ -43,6 +49,9 @@ REF= too late
# reference to an undefined variable
.undef UNDEF
VAR:= <${UNDEF}>
+.if ${VAR} != "<>"
+. error
+.endif
UNDEF= after
.if ${VAR} != "<after>"
. error
@@ -62,6 +71,9 @@ REF= too late
# expression with an indirect modifier referring to an undefined variable
.undef UNDEF
VAR:= ${:${UNDEF}}
+.if ${VAR} != ""
+. error
+.endif
UNDEF= Uwas undefined
.if ${VAR} != "was undefined"
. error
@@ -93,6 +105,9 @@ UNDEF= Uwas undefined
REF2= <${REF3}>
REF= ${REF2}
VAR:= ${REF}
+.if ${VAR} != "<>"
+. error
+.endif
REF3= too late
.if ${VAR} != "<too late>"
. error
@@ -174,5 +189,104 @@ VAR_SUBST_${UNDEF}:= assigned by ':='
. error
.endif
+
+# The following test case demonstrates that the variable 'LATER' is preserved
+# in the ':=' assignment since the variable 'LATER' is not yet defined.
+# After the assignment to 'LATER', evaluating the variable 'INDIRECT'
+# evaluates 'LATER' as well.
+#
+.undef LATER
+INDIRECT:= ${LATER:S,value,replaced,}
+.if ${INDIRECT} != ""
+. error
+.endif
+LATER= late-value
+.if ${INDIRECT} != "late-replaced"
+. error
+.endif
+
+
+# Same as the test case above, except for the additional modifier ':tl' when
+# evaluating the variable 'INDIRECT'. Nothing surprising here.
+.undef LATER
+.undef later
+INDIRECT:= ${LATER:S,value,replaced,}
+.if ${INDIRECT:tl} != ""
+. error
+.endif
+LATER= uppercase-value
+later= lowercase-value
+.if ${INDIRECT:tl} != "uppercase-replaced"
+. error
+.endif
+
+
+# Similar to the two test cases above, the situation gets a bit more involved
+# here, due to the double indirection. The variable 'indirect' is supposed to
+# be the lowercase version of the variable 'INDIRECT'.
+#
+# The assignment operator ':=' for the variable 'INDIRECT' could be a '=' as
+# well, it wouldn't make a difference in this case. The crucial detail is the
+# assignment operator ':=' for the variable 'indirect'. During this
+# assignment, the variable modifier ':S,value,replaced,' is converted to
+# lowercase, which turns 'S' into 's', thus producing an unknown modifier.
+# In this case, make issues a warning, but in cases where the modifier
+# includes a '=', the modifier would be interpreted as a SysV-style
+# substitution like '.c=.o', and make would not issue a warning, leading to
+# silent unexpected behavior.
+#
+# As of 2021-11-20, the actual behavior is unexpected. Fixing it is not
+# trivial. When the assignment to 'indirect' takes place, the expressions
+# from the nested expression could be preserved, like this:
+#
+# Start with:
+#
+# indirect:= ${INDIRECT:tl}
+#
+# Since INDIRECT is defined, expand it, remembering that the modifier
+# ':tl' must still be applied to the final result.
+#
+# indirect:= ${LATER:S,value,replaced,} \
+# OK \
+# ${LATER:value=sysv}
+#
+# The variable 'LATER' is not defined. An idea may be to append the
+# remaining modifier ':tl' to each expression that is starting with an
+# undefined variable, resulting in:
+#
+# indirect:= ${LATER:S,value,replaced,:tl} \
+# OK \
+# ${LATER:value=sysv:tl}
+#
+# This would work for the first expression. The second expression ends
+# with the SysV modifier ':from=to', and when this modifier is parsed,
+# it consumes all characters until the end of the expression, which in
+# this case would replace the suffix 'value' with the literal 'sysv:tl',
+# ignoring that the ':tl' was intended to be an additional modifier.
+#
+# Due to all of this, this surprising behavior is not easy to fix.
+#
+.undef LATER
+.undef later
+INDIRECT:= ${LATER:S,value,replaced,} OK ${LATER:value=sysv}
+indirect:= ${INDIRECT:tl}
+# expect+1: Unknown modifier "s,value,replaced,"
+.if ${indirect} != " ok "
+. error
+.else
+# expect+1: warning: XXX Neither branch should be taken.
+. warning XXX Neither branch should be taken.
+.endif
+LATER= uppercase-value
+later= lowercase-value
+# expect+1: Unknown modifier "s,value,replaced,"
+.if ${indirect} != "uppercase-replaced ok uppercase-sysv"
+# expect+1: warning: XXX Neither branch should be taken.
+. warning XXX Neither branch should be taken.
+.else
+. error
+.endif
+
+
all:
@:;
diff --git a/contrib/bmake/unit-tests/var-op-shell.exp b/contrib/bmake/unit-tests/var-op-shell.exp
index 890bfa43c38e..0837cd4f832e 100644
--- a/contrib/bmake/unit-tests/var-op-shell.exp
+++ b/contrib/bmake/unit-tests/var-op-shell.exp
@@ -1,7 +1,11 @@
-make: "var-op-shell.mk" line 28: warning: "echo "failed"; false" returned non-zero status
-make: "var-op-shell.mk" line 34: warning: "false" returned non-zero status
-make: "var-op-shell.mk" line 56: warning: "kill $$" exited on a signal
+make: "var-op-shell.mk" line 32: warning: "echo "failed"; false" returned non-zero status
+make: "var-op-shell.mk" line 39: warning: "false" returned non-zero status
+make: "var-op-shell.mk" line 62: warning: "kill $$" exited on a signal
/bin/no/such/command: not found
-make: "var-op-shell.mk" line 62: warning: "/bin/no/such/command" returned non-zero status
+make: "var-op-shell.mk" line 69: warning: "/bin/no/such/command" returned non-zero status
stderr
+Capturing the output of command "echo '$$$$'"
+Global: OUTPUT = $$$$
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
exit status 0
diff --git a/contrib/bmake/unit-tests/var-op-shell.mk b/contrib/bmake/unit-tests/var-op-shell.mk
index 0fdc54fc6041..4441efaf4a90 100644
--- a/contrib/bmake/unit-tests/var-op-shell.mk
+++ b/contrib/bmake/unit-tests/var-op-shell.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-shell.mk,v 1.4 2021/02/06 04:55:08 sjg Exp $
+# $NetBSD: var-op-shell.mk,v 1.8 2024/01/05 23:36:45 rillig Exp $
#
# Tests for the != variable assignment operator, which runs its right-hand
# side through the shell.
@@ -15,7 +15,7 @@ OUTPUT!= echo "success"'ful'
# an empty output produced the error message "Couldn't read shell's output
# for \"%s\"".
#
-# The error message is still there but reserved for technical errors.
+# The error message is still in Cmd_Exec but reserved for technical errors.
# It may be possible to trigger the error message by killing the shell after
# reading part of its output.
OUTPUT!= true
@@ -24,13 +24,18 @@ OUTPUT!= true
.endif
# The output of a shell command that failed is processed nevertheless.
-# TODO: Make this an error in lint mode.
+# Unlike the other places that run external commands (expression modifier
+# '::!=', expression modifier ':!...!'), a failed command generates only a
+# warning, not an "error". These "errors" are ignored in default mode, for
+# compatibility, but not in lint mode (-dL).
+# expect+1: warning: "echo "failed"; false" returned non-zero status
OUTPUT!= echo "failed"; false
.if ${OUTPUT} != "failed"
. error
.endif
# A command with empty output may fail as well.
+# expect+1: warning: "false" returned non-zero status
OUTPUT!= false
.if ${OUTPUT} != ""
. error
@@ -53,12 +58,14 @@ OUTPUT!= echo "before"; false; echo "after"
# This should result in a warning about "exited on a signal".
# This used to be kill -14 (SIGALRM), but that stopped working on
# Darwin18 after recent update.
+# expect+1: warning: "kill $$" exited on a signal
OUTPUT!= kill $$$$
.if ${OUTPUT} != ""
. error
.endif
# A nonexistent command produces a non-zero exit status.
+# expect+1: warning: "/bin/no/such/command" returned non-zero status
OUTPUT!= /bin/no/such/command
.if ${OUTPUT} != ""
. error
@@ -78,4 +85,28 @@ OUTPUT!= echo '$$$$$$$$'
. error
.endif
+
+# As a debugging aid, log the exact command that is run via the shell.
+.MAKEFLAGS: -dv
+OUTPUT!= echo '$$$$$$$$'
+.MAKEFLAGS: -d0
+
+
+# Since main.c 1.607 from 2024-01-05, long shell commands are not run directly
+# via '$shell -c $command', they are first written to a temporary file that is
+# then fed to the shell via '$shell $tmpfile'.
+OUTPUT_SHORT!= echo "$$0"
+OUTPUT_LONG!= echo "$$0" || : ${:U:range=1000}
+# When running '$shell -c $command', '$0' in the shell evaluates to the name
+# of the shell.
+.if ${OUTPUT_SHORT} != ${.SHELL:T}
+. error
+.endif
+# When running '$shell $tmpfile', '$0' in the shell evaluates to the name of
+# the temporary file.
+.if !${OUTPUT_LONG:M*/make*}
+. error
+.endif
+
+
all:
diff --git a/contrib/bmake/unit-tests/var-op-sunsh.mk b/contrib/bmake/unit-tests/var-op-sunsh.mk
index 0d15b8c88b92..520cedc93515 100644
--- a/contrib/bmake/unit-tests/var-op-sunsh.mk
+++ b/contrib/bmake/unit-tests/var-op-sunsh.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-sunsh.mk,v 1.8 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: var-op-sunsh.mk,v 1.10 2022/02/09 21:09:24 rillig Exp $
#
# Tests for the :sh= variable assignment operator, which runs its right-hand
# side through the shell. It is a seldom-used alternative to the !=
@@ -24,9 +24,12 @@ VAR :sh = echo colon-sh-spaced
# This was neither documented by NetBSD make nor by Solaris make and was
# an implementation error.
#
-# Since 2020-10-04, this is a normal variable assignment using the '='
-# assignment operator.
+# Since 2020-10-04, this is a normal variable assignment to the variable named
+# 'VAR:shell', using the '=' assignment operator.
VAR:shell= echo colon-shell
+# The variable name needs to be generated using a ${:U...} expression because
+# it is not possible to express the ':' as part of a literal variable name,
+# see ParseVarname.
.if ${${:UVAR\:shell}} != "echo colon-shell"
. error
.endif
@@ -95,30 +98,52 @@ VAR :sh :sh :sh :sh= echo multiple
# expanding nested expressions, the token ' :sh' can be used to add arbitrary
# text between the variable name and the assignment operator, it just has to
# be enclosed in braces or parentheses.
+#
+# Since the text to the left of the assignment operator '=' does not end with
+# ':sh', the effective assignment operator becomes '=', not '!='.
VAR :sh(Put a comment here)= comment in parentheses
.if ${VAR} != "comment in parentheses"
. error
.endif
# The unintended comment can include multiple levels of nested braces and
-# parentheses, they don't even need to be balanced since they are only
-# counted by Parse_IsVar and ignored by Parse_Var.
+# parentheses. Braces and parentheses are interchangeable, that is, a '(' can
+# be closed by either ')' or '}'. These braces and parentheses are only
+# counted by Parse_IsVar, in particular Parse_Var doesn't see them.
VAR :sh{Put}((((a}{comment}}}}{here}= comment in braces
.if ${VAR} != "comment in braces"
. error
.endif
-# Syntactically, the ':sh' modifier can be combined with the '+=' assignment
-# operator. In such a case the ':sh' modifier is silently ignored.
+# The assignment modifier ':sh' can be combined with the assignment operator
+# '+='. In such a case the ':sh' is silently ignored, and the effective
+# assignment operator is '+='.
#
-# XXX: This combination should not be allowed at all.
+# XXX: This combination should not be allowed at all, as it is confusing.
VAR= one
VAR :sh += echo two
.if ${VAR} != "one echo two"
. error ${VAR}
.endif
-# TODO: test VAR:sh!=command
+# The assignment modifier ':sh' can be combined with the assignment operator
+# '!='. In such a case the ':sh' is silently ignored, and the effective
+# assignment operator is '!=', just like with '+=' or the other compound
+# assignment operators.
+#
+# XXX: This combination should not be allowed at all, as it is confusing.
+VAR :sh != echo echo echo echo spaces-around
+.if ${VAR} != "echo echo echo spaces-around"
+. error ${VAR}
+.endif
+
+# If there is no space between the variable name and the assignment modifier
+# ':sh', the ':sh' becomes part of the variable name, as the parser only
+# expects a single assignment modifier to the left of the '=', which in this
+# case is the '!'.
+VAR:sh != echo echo echo echo space-after
+.if ${${:UVAR\:sh}} != "echo echo echo space-after"
+. error ${${:UVAR\:sh}}
+.endif
-all:
- @:;
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/var-readonly.exp b/contrib/bmake/unit-tests/var-readonly.exp
new file mode 100644
index 000000000000..ae266753ee71
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-readonly.exp
@@ -0,0 +1,4 @@
+Global: ignoring delete 'N' as it is read-only
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
+exit status 0
diff --git a/contrib/bmake/unit-tests/var-readonly.mk b/contrib/bmake/unit-tests/var-readonly.mk
new file mode 100644
index 000000000000..e9ff6f38819f
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-readonly.mk
@@ -0,0 +1,27 @@
+# $NetBSD: var-readonly.mk,v 1.4 2023/12/20 08:42:10 rillig Exp $
+
+# the answer
+N = 42
+.READONLY: N
+# this should be ignored
+N = 666
+.if ${N} != 42
+.error N ($N) should be 42
+.endif
+
+# undef should fail
+.MAKEFLAGS: -dv
+.undef N
+.ifndef N
+.error N should not be undef'd
+.endif
+.MAKEFLAGS: -d0
+
+.NOREADONLY: N
+# now we can change it
+N = 69
+.if ${N} == 42
+.error N should not be 42
+.endif
+
+all:
diff --git a/contrib/bmake/unit-tests/var-recursive.exp b/contrib/bmake/unit-tests/var-recursive.exp
index 9739d8bcca13..5415dc93a53d 100644
--- a/contrib/bmake/unit-tests/var-recursive.exp
+++ b/contrib/bmake/unit-tests/var-recursive.exp
@@ -1,12 +1,19 @@
-make: "var-recursive.mk" line 20: still there
-Variable DIRECT is recursive.
+make: "var-recursive.mk" line 21: still there
+make: Variable DIRECT is recursive.
+ in var-recursive.mk:22
make: stopped in unit-tests
-Variable INDIRECT1 is recursive.
+make: Variable INDIRECT1 is recursive.
+ in var-recursive.mk:29
make: stopped in unit-tests
-make: "var-recursive.mk" line 35: ok
-Variable V is recursive.
+make: "var-recursive.mk" line 37: ok
+make: Variable V is recursive.
+ in var-recursive.mk:45
+
+make: stopped in unit-tests
+: OK
+In a command near "var-recursive.mk" line 57: make[1]: Variable VAR is recursive.
make: stopped in unit-tests
exit status 0
diff --git a/contrib/bmake/unit-tests/var-recursive.mk b/contrib/bmake/unit-tests/var-recursive.mk
index da1fb696d655..72231656673c 100644
--- a/contrib/bmake/unit-tests/var-recursive.mk
+++ b/contrib/bmake/unit-tests/var-recursive.mk
@@ -1,9 +1,9 @@
-# $NetBSD: var-recursive.mk,v 1.2 2020/10/31 13:45:00 rillig Exp $
+# $NetBSD: var-recursive.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
-# Tests for variable expressions that refer to themselves and thus
+# Tests for expressions that refer to themselves and thus
# cannot be evaluated.
-TESTS= direct indirect conditional short
+TESTS= direct indirect conditional short target
# Since make exits immediately when it detects a recursive expression,
# the actual tests are run in sub-makes.
@@ -17,6 +17,7 @@ all:
.elif ${TEST} == direct
DIRECT= ${DIRECT} # Defining a recursive variable is not yet an error.
+# expect+1: still there
. info still there # Therefore this line is printed.
. info ${DIRECT} # But expanding the variable is an error.
@@ -32,6 +33,7 @@ INDIRECT2= ${INDIRECT1}
# The variable refers to itself, but only in the branch of a condition that
# is never satisfied and is thus not evaluated.
CONDITIONAL= ${1:?ok:${CONDITIONAL}}
+# expect+1: ok
. info ${CONDITIONAL}
.elif ${TEST} == short
@@ -42,6 +44,18 @@ CONDITIONAL= ${1:?ok:${CONDITIONAL}}
V= $V
. info $V
+.elif ${TEST} == target
+
+# If a recursive variable is accessed in a command of a target, the makefiles
+# are not parsed anymore, so there is no location information from the
+# .includes and .for directives. In such a case, use the location of the last
+# command of the target to provide at least a hint to the location.
+VAR= ${VAR}
+target:
+ : OK
+ : ${VAR}
+ : OK
+
.else
. error Unknown test "${TEST}"
.endif
diff --git a/contrib/bmake/unit-tests/var-scope-cmdline.exp b/contrib/bmake/unit-tests/var-scope-cmdline.exp
new file mode 100644
index 000000000000..c663a9069a9f
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-cmdline.exp
@@ -0,0 +1,4 @@
+make: "var-scope-cmdline.mk" line 72: global
+make: "var-scope-cmdline.mk" line 82: makeflags
+makeflags
+exit status 0
diff --git a/contrib/bmake/unit-tests/var-class-cmdline.mk b/contrib/bmake/unit-tests/var-scope-cmdline.mk
index 679e051bb242..5c0f246a0a22 100644
--- a/contrib/bmake/unit-tests/var-class-cmdline.mk
+++ b/contrib/bmake/unit-tests/var-scope-cmdline.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-class-cmdline.mk,v 1.5 2021/02/23 21:59:31 rillig Exp $
+# $NetBSD: var-scope-cmdline.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $
#
# Tests for variables specified on the command line.
#
@@ -55,15 +55,20 @@
# temporary loop variable after finishing the loop. It was probably not
# intended back then that a side effect of this seemingly simple change was
# that both global and cmdline variables could now be undefined at will as a
-# side effect of evaluating a variable expression. As of 2021-02-23, this is
+# side effect of evaluating an expression. As of 2021-02-23, this is
# still possible.
#
# Most cmdline variables are set at the very beginning, when parsing the
# command line arguments. Using the special target '.MAKEFLAGS', it is
# possible to set cmdline variables at any later time.
+#
+# See also:
+# varcmd.mk
+# varname-makeflags.mk
# A normal global variable, without any cmdline variable nearby.
VAR= global
+# expect+1: global
.info ${VAR}
# The global variable is "overridden" by simply deleting it and then
@@ -73,6 +78,7 @@ VAR= global
#
# See varmod-loop.mk for a non-obvious way to undefine a cmdline variable.
.MAKEFLAGS: VAR=makeflags
+# expect+1: makeflags
.info ${VAR}
# If Var_SetWithFlags should ever forget to delete the global variable,
diff --git a/contrib/bmake/unit-tests/var-class-env.exp b/contrib/bmake/unit-tests/var-scope-env.exp
index 39a9383953dd..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/var-class-env.exp
+++ b/contrib/bmake/unit-tests/var-scope-env.exp
diff --git a/contrib/bmake/unit-tests/var-class-env.mk b/contrib/bmake/unit-tests/var-scope-env.mk
index 6e6b4891d3fd..d58ad7c6f2e2 100644
--- a/contrib/bmake/unit-tests/var-class-env.mk
+++ b/contrib/bmake/unit-tests/var-scope-env.mk
@@ -1,4 +1,4 @@
-# $NetBSD: var-class-env.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: var-scope-env.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $
#
# Tests for variables specified in the process environment.
diff --git a/contrib/bmake/unit-tests/var-class-global.exp b/contrib/bmake/unit-tests/var-scope-global.exp
index 39a9383953dd..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/var-class-global.exp
+++ b/contrib/bmake/unit-tests/var-scope-global.exp
diff --git a/contrib/bmake/unit-tests/var-scope-global.mk b/contrib/bmake/unit-tests/var-scope-global.mk
new file mode 100644
index 000000000000..02ed8fe701c0
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-global.mk
@@ -0,0 +1,18 @@
+# $NetBSD: var-scope-global.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $
+#
+# Tests for global variables, which are the most common variables.
+
+# Global variables can be assigned and appended to.
+GLOBAL= value
+GLOBAL+= addition
+.if ${GLOBAL} != "value addition"
+. error
+.endif
+
+# Global variables can be removed from their scope.
+.undef GLOBAL
+.if defined(GLOBAL)
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/var-scope-local-legacy.exp b/contrib/bmake/unit-tests/var-scope-local-legacy.exp
new file mode 100644
index 000000000000..33ce145fb8fd
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-local-legacy.exp
@@ -0,0 +1,6 @@
+: LEN4=undef_
+: XY=undef_
+: AF=undef_
+: %D=undef_ %F=undef_
+: @D=global-value_ @F=all_
+exit status 0
diff --git a/contrib/bmake/unit-tests/var-scope-local-legacy.mk b/contrib/bmake/unit-tests/var-scope-local-legacy.mk
new file mode 100644
index 000000000000..70bc20fd9848
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-local-legacy.mk
@@ -0,0 +1,35 @@
+# $NetBSD: var-scope-local-legacy.mk,v 1.3 2023/12/17 14:07:22 rillig Exp $
+#
+# Tests for legacy target-local variables, such as ${<F} or ${@D}.
+
+
+# In the global or command line scopes, the legacy forms are not recognized,
+# as the target-specific variables are not available either. The expressions
+# are retained so that they can be resolved later, in the target scope.
+.if "${@D}" != "\${@D}"
+. error
+.endif
+
+# It's possible to define variables of the legacy name in the global or
+# command line scope, and they override the target-local variables, leading to
+# unnecessary confusion.
+@D= global-value
+.if "${@D}" != "global-value"
+. error
+.endif
+
+
+all: .PHONY
+ # Only variables of length 2 can be legacy, this one cannot.
+ : LEN4=${LEN4:Uundef}_
+ # The second character of the name must be 'D' or 'F'.
+ : XY=${XY:Uundef}_
+ # The first character must name one of the 7 predefined local
+ # variables, 'A' is not such a character.
+ : AF=${AF:Uundef}_
+ # The variable '.MEMBER' is undefined, therefore '%D' and '%F' are
+ # undefined as well.
+ : %D=${%D:Uundef}_ %F=${%F:Uundef}_
+ # The directory name of the target is shadowed by the global variable,
+ # it would be '.' otherwise. The basename is 'all'.
+ : @D=${@D:Uundef}_ @F=${@F:Uundef}_
diff --git a/contrib/bmake/unit-tests/var-scope-local.exp b/contrib/bmake/unit-tests/var-scope-local.exp
new file mode 100644
index 000000000000..eddf5985a0ed
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-local.exp
@@ -0,0 +1,71 @@
+Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one
+Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one two
+Var_Parse: ${.MAKE.TARGET_LOCAL_VARIABLES} (eval)
+one: ignoring ' = three' as the variable name '' expands to empty
+two: ignoring ' = three' as the variable name '' expands to empty
+Global: one two = # (empty)
+Global: one two = three
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
+target-rule.ext: @ = <target-rule.ext>
+target-rule.ext: % = <undefined>
+target-rule.ext: ? = <>
+target-rule.ext: < = <undefined>
+target-rule.ext: * = <target-rule.ext>
+dir/subdir/target-rule.ext: @ = <dir/subdir/target-rule.ext>
+dir/subdir/target-rule.ext: % = <undefined>
+dir/subdir/target-rule.ext: ? = <>
+dir/subdir/target-rule.ext: < = <undefined>
+dir/subdir/target-rule.ext: * = <dir/subdir/target-rule.ext>
+target-rule.ir-gen-from: @ = <target-rule.ir-gen-from>
+target-rule.ir-gen-from: % = <undefined>
+target-rule.ir-gen-from: ? = <>
+target-rule.ir-gen-from: < = <undefined>
+target-rule.ir-gen-from: * = <target-rule>
+dir/subdir/target-rule-dir.ir-gen-from: @ = <dir/subdir/target-rule-dir.ir-gen-from>
+dir/subdir/target-rule-dir.ir-gen-from: % = <undefined>
+dir/subdir/target-rule-dir.ir-gen-from: ? = <>
+dir/subdir/target-rule-dir.ir-gen-from: < = <undefined>
+dir/subdir/target-rule-dir.ir-gen-from: * = <dir/subdir/target-rule-dir>
+inference-rule.ir-to: @ = <inference-rule.ir-to>
+inference-rule.ir-to: % = <undefined>
+inference-rule.ir-to: ? = <inference-rule.ir-from>
+inference-rule.ir-to: < = <inference-rule.ir-from>
+inference-rule.ir-to: * = <inference-rule>
+dir/subdir/inference-rule.ir-to: @ = <dir/subdir/inference-rule.ir-to>
+dir/subdir/inference-rule.ir-to: % = <undefined>
+dir/subdir/inference-rule.ir-to: ? = <dir/subdir/inference-rule.ir-from>
+dir/subdir/inference-rule.ir-to: < = <dir/subdir/inference-rule.ir-from>
+dir/subdir/inference-rule.ir-to: * = <dir/subdir/inference-rule>
+inference-rule-chain.ir-from: @ = <inference-rule-chain.ir-from>
+inference-rule-chain.ir-from: % = <undefined>
+inference-rule-chain.ir-from: ? = <inference-rule-chain.ir-gen-from>
+inference-rule-chain.ir-from: < = <inference-rule-chain.ir-gen-from>
+inference-rule-chain.ir-from: * = <inference-rule-chain>
+inference-rule-chain.ir-to: @ = <inference-rule-chain.ir-to>
+inference-rule-chain.ir-to: % = <undefined>
+inference-rule-chain.ir-to: ? = <inference-rule-chain.ir-from>
+inference-rule-chain.ir-to: < = <inference-rule-chain.ir-from>
+inference-rule-chain.ir-to: * = <inference-rule-chain>
+dir/subdir/inference-rule-chain.ir-from: @ = <dir/subdir/inference-rule-chain.ir-from>
+dir/subdir/inference-rule-chain.ir-from: % = <undefined>
+dir/subdir/inference-rule-chain.ir-from: ? = <dir/subdir/inference-rule-chain.ir-gen-from>
+dir/subdir/inference-rule-chain.ir-from: < = <dir/subdir/inference-rule-chain.ir-gen-from>
+dir/subdir/inference-rule-chain.ir-from: * = <dir/subdir/inference-rule-chain>
+dir/subdir/inference-rule-chain.ir-to: @ = <dir/subdir/inference-rule-chain.ir-to>
+dir/subdir/inference-rule-chain.ir-to: % = <undefined>
+dir/subdir/inference-rule-chain.ir-to: ? = <dir/subdir/inference-rule-chain.ir-from>
+dir/subdir/inference-rule-chain.ir-to: < = <dir/subdir/inference-rule-chain.ir-from>
+dir/subdir/inference-rule-chain.ir-to: * = <dir/subdir/inference-rule-chain>
+: Making var-scope-local.c out of nothing.
+: Making var-scope-local.o from var-scope-local.c.
+: Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".".
+Making var-scope-local-assign.o with make 'local' and env 'local'.
+Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
+Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-default.o with make 'global' and env 'global'.
+Making var-scope-local-subst.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-shell.o with make 'output' and env 'output'.
+Making .USE var-scope-local-use.o with make 'global' and env 'global'.
+: all overwritten
+exit status 0
diff --git a/contrib/bmake/unit-tests/var-scope-local.mk b/contrib/bmake/unit-tests/var-scope-local.mk
new file mode 100644
index 000000000000..7a031373e7da
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope-local.mk
@@ -0,0 +1,270 @@
+# $NetBSD: var-scope-local.mk,v 1.11 2024/03/05 23:07:58 rillig Exp $
+#
+# Tests for target-local variables, such as ${.TARGET} or $@. These variables
+# are relatively short-lived as they are created just before making the
+# target. In contrast, global variables are typically created when the
+# makefiles are read in.
+#
+# The 7 built-in target-local variables are listed in the manual page. They
+# are defined just before the target is actually made. Additional
+# target-local variables can be defined in dependency lines like
+# 'target: VAR=value', one at a time.
+
+.MAIN: all
+
+# Target-local variables in a target rule
+#
+# In target rules, '$*' only strips the extension off the pathname if the
+# extension is listed in '.SUFFIXES'.
+#
+# expect: target-rule.ext: * = <target-rule.ext>
+all: target-rule.ext dir/subdir/target-rule.ext
+target-rule.ext dir/subdir/target-rule.ext: .PHONY
+ @echo '$@: @ = <${@:Uundefined}>'
+ @echo '$@: % = <${%:Uundefined}>'
+ @echo '$@: ? = <${?:Uundefined}>'
+ @echo '$@: < = <${<:Uundefined}>'
+ @echo '$@: * = <${*:Uundefined}>'
+
+.SUFFIXES: .ir-gen-from .ir-from .ir-to
+
+# In target rules, '$*' strips the extension off the pathname of the target
+# if the extension is listed in '.SUFFIXES'.
+#
+# expect: target-rule.ir-gen-from: * = <target-rule>
+all: target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from
+target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from:
+ @echo '$@: @ = <${@:Uundefined}>'
+ @echo '$@: % = <${%:Uundefined}>'
+ @echo '$@: ? = <${?:Uundefined}>'
+ @echo '$@: < = <${<:Uundefined}>'
+ @echo '$@: * = <${*:Uundefined}>'
+
+.ir-from.ir-to:
+ @echo '$@: @ = <${@:Uundefined}>'
+ @echo '$@: % = <${%:Uundefined}>'
+ @echo '$@: ? = <${?:Uundefined}>'
+ @echo '$@: < = <${<:Uundefined}>'
+ @echo '$@: * = <${*:Uundefined}>'
+.ir-gen-from.ir-from:
+ @echo '$@: @ = <${@:Uundefined}>'
+ @echo '$@: % = <${%:Uundefined}>'
+ @echo '$@: ? = <${?:Uundefined}>'
+ @echo '$@: < = <${<:Uundefined}>'
+ @echo '$@: * = <${*:Uundefined}>'
+
+# Target-local variables in an inference rule
+all: inference-rule.ir-to dir/subdir/inference-rule.ir-to
+inference-rule.ir-from: .PHONY
+dir/subdir/inference-rule.ir-from: .PHONY
+
+# Target-local variables in a chain of inference rules
+all: inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to
+inference-rule-chain.ir-gen-from: .PHONY
+dir/subdir/inference-rule-chain.ir-gen-from: .PHONY
+
+# The run-time 'check' directives from above happen after the parse-time
+# 'check' directives from below.
+#
+# expect-reset
+
+# Deferred evaluation during parsing
+#
+# The target-local variables can be used in expressions, just like other
+# variables. When these expressions are evaluated outside of a target, these
+# expressions are not yet expanded, instead their text is preserved, to allow
+# these expressions to expand right in time when the target-local variables
+# are actually set.
+#
+# Conditions from .if directives are evaluated in the scope of the command
+# line, which means that variables from the command line, from the global
+# scope and from the environment are resolved, in this precedence order (but
+# see the command line option '-e'). In that phase, expressions involving
+# target-local variables need to be preserved, including the exact names of
+# the variables.
+#
+# Each of the built-in target-local variables has two equivalent names, for
+# example '@' is equivalent to '.TARGET'. The implementation might
+# canonicalize these aliases at some point, and that might be surprising.
+# This aliasing happens for single-character variable names like $@ or $<
+# (see VarFind, CanonicalVarname), but not for braced or parenthesized
+# expressions like ${@}, ${.TARGET} ${VAR:Mpattern} (see Var_Parse,
+# ParseVarname).
+#
+# In the following condition, make expands '$@' to the long-format alias
+# '$(.TARGET)'; note that the alias is not written with braces, as would be
+# common in BSD makefiles, but with parentheses. This alternative spelling
+# behaves the same though.
+.if $@ != "\$\(.TARGET)"
+. error
+.endif
+# In the long form of writing a target-local variable, the text of the
+# expression is preserved exactly as written, no matter whether it is written
+# with '{' or '('.
+.if ${@} != "\$\{@}"
+. error
+.endif
+.if $(@) != "\$\(@)"
+. error
+.endif
+# If the expression contains modifiers, the behavior depends on the
+# actual modifiers. The modifier ':M' keeps the expression in the state
+# 'undefined'. Since the expression is still undefined after evaluating all
+# the modifiers, the value of the expression is discarded and the expression
+# text is used instead. This preserves the expressions based on target-local
+# variables as long as possible.
+.if ${@:M*} != "\$\{@:M*}"
+. error
+.endif
+# In the following examples, the expressions are based on target-local
+# variables but use the modifier ':L', which turns an undefined expression
+# into a defined one. At the end of evaluating the expression, the state of
+# the expression is not 'undefined' anymore. The value of the expression
+# is the name of the variable, since that's what the modifier ':L' does.
+.if ${@:L} != "@"
+. error
+.endif
+.if ${.TARGET:L} != ".TARGET"
+. error
+.endif
+.if ${@F:L} != "@F"
+. error
+.endif
+.if ${@D:L} != "@D"
+. error
+.endif
+
+
+# Custom local variables
+#
+# Additional target-local variables may be defined in dependency lines.
+.MAKEFLAGS: -dv
+# In the following line, the ':=' may either be interpreted as an assignment
+# operator or as the dependency operator ':', followed by an empty variable
+# name and the assignment operator '='. It is the latter since in an
+# assignment, the left-hand side must be a single word or empty.
+#
+# The empty variable name is expanded twice, once for 'one' and once for
+# 'two'.
+# expect: one: ignoring ' = three' as the variable name '' expands to empty
+# expect: two: ignoring ' = three' as the variable name '' expands to empty
+one two:=three
+# If the two targets to the left are generated by an expression, the
+# line is parsed as a variable assignment since its left-hand side is a single
+# word.
+# expect: Global: one two = three
+${:Uone two}:=three
+.MAKEFLAGS: -d0
+
+
+.SUFFIXES: .c .o
+
+# One of the dynamic target-local variables is '.TARGET'. Since this is not
+# a suffix transformation rule, the variable '.IMPSRC' is not defined.
+# expect: : Making var-scope-local.c out of nothing.
+var-scope-local.c:
+ : Making ${.TARGET} ${.IMPSRC:Dfrom ${.IMPSRC}:Uout of nothing}.
+
+# This is a suffix transformation rule, so both '.TARGET' and '.IMPSRC' are
+# defined.
+# expect: : Making var-scope-local.o from var-scope-local.c.
+# expect: : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".".
+.c.o:
+ : Making ${.TARGET} from ${.IMPSRC}.
+
+ # The local variables @F, @D, <F, <D are legacy forms.
+ # See the manual page for details.
+ : Making basename "${@F}" in "${@D}" from "${<F}" in "${<D}".
+
+# expect: : all overwritten
+all: var-scope-local.o
+ # The ::= modifier overwrites the .TARGET variable in the node
+ # 'all', not in the global scope. This can be seen with the -dv
+ # option, looking for "all: @ = overwritten".
+ : ${.TARGET} ${.TARGET::=overwritten}${.TARGET}
+
+
+# Begin tests for custom target-local variables, for all 5 variable assignment
+# operators.
+all: var-scope-local-assign.o
+all: var-scope-local-append.o
+all: var-scope-local-append-global.o
+all: var-scope-local-default.o
+all: var-scope-local-subst.o
+all: var-scope-local-shell.o
+
+var-scope-local-assign.o \
+var-scope-local-append.o \
+var-scope-local-append-global.o \
+var-scope-local-default.o \
+var-scope-local-subst.o \
+var-scope-local-shell.o:
+ @echo "Making ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'."
+
+# Target-local variables are enabled by default. Force them to be enabled
+# just in case a test above has disabled them.
+.MAKE.TARGET_LOCAL_VARIABLES= yes
+
+VAR= global
+.export VAR
+
+# If the sources of a dependency line look like a variable assignment, make
+# treats them as such. There is only a single variable assignment per
+# dependency line, which makes whitespace around the assignment operator
+# irrelevant.
+#
+# expect-reset
+# expect: Making var-scope-local-assign.o with make 'local' and env 'local'.
+var-scope-local-assign.o: VAR= local
+
+# Assignments using '+=' do *not* look up the global value, instead they only
+# look up the variable in the target's own scope.
+var-scope-local-append.o: VAR+= local
+# Once a variable is defined in the target-local scope, appending using '+='
+# behaves as expected. Note that the expression '${.TARGET}' is not resolved
+# when parsing the dependency line, its evaluation is deferred until the
+# target is actually made.
+# expect: Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
+var-scope-local-append.o: VAR += to ${.TARGET}
+# To access the value of a global variable, use an expression. This
+# expression is expanded before parsing the whole dependency line. Since the
+# expansion happens to the right of the dependency operator ':', the expanded
+# text does not influence parsing of the dependency line. Since the expansion
+# happens to the right of the assignment operator '=', the expanded text does
+# not influence the parsing of the variable assignment. The effective
+# variable assignment, after expanding the whole line first, is thus
+# 'VAR= global+local'.
+# expect: Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'.
+var-scope-local-append-global.o: VAR= ${VAR}+local
+
+var-scope-local-default.o: VAR ?= first
+var-scope-local-default.o: VAR ?= second
+# XXX: '?=' does look at the global variable. That's a long-standing
+# inconsistency between the assignment operators '+=' and '?='. See
+# Var_AppendExpand and VarAssign_Eval.
+# expect: Making var-scope-local-default.o with make 'global' and env 'global'.
+
+# Using the variable assignment operator ':=' provides another way of
+# accessing a global variable and extending it with local modifications. The
+# '$' has to be written as '$$' though to survive the expansion of the
+# dependency line as a whole. After that, the parser sees the variable
+# assignment as 'VAR := ${VAR}+local' and searches for the variable 'VAR' in
+# the usual scopes, picking up the variable from the global scope.
+# expect: Making var-scope-local-subst.o with make 'global+local' and env 'global+local'.
+var-scope-local-subst.o: VAR := $${VAR}+local
+
+# The variable assignment operator '!=' assigns the output of the shell
+# command, as everywhere else. The shell command is run when the dependency
+# line is parsed.
+var-scope-local-shell.o: VAR != echo output
+
+
+# While VAR=use will be set for a .USE node, it will never be seen since only
+# the ultimate target's context is searched; the variable assignments from the
+# .USE target are not copied to the ultimate target's.
+# expect: Making .USE var-scope-local-use.o with make 'global' and env 'global'.
+a_use: .USE VAR=use
+ @echo "Making .USE ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'."
+
+all: var-scope-local-use.o
+var-scope-local-use.o: a_use
diff --git a/contrib/bmake/unit-tests/var-class-local-legacy.exp b/contrib/bmake/unit-tests/var-scope.exp
index 39a9383953dd..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/var-class-local-legacy.exp
+++ b/contrib/bmake/unit-tests/var-scope.exp
diff --git a/contrib/bmake/unit-tests/var-scope.mk b/contrib/bmake/unit-tests/var-scope.mk
new file mode 100644
index 000000000000..cbbcea526d54
--- /dev/null
+++ b/contrib/bmake/unit-tests/var-scope.mk
@@ -0,0 +1,9 @@
+# $NetBSD: var-scope.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $
+#
+# Tests for the different variable scopes (local, command-line, global,
+# environment), and which of them takes precedence over the others.
+
+# TODO: Implementation
+
+all:
+ @:;
diff --git a/contrib/bmake/unit-tests/varcmd.mk b/contrib/bmake/unit-tests/varcmd.mk
index 12739df30926..ec0cf96ed75c 100644
--- a/contrib/bmake/unit-tests/varcmd.mk
+++ b/contrib/bmake/unit-tests/varcmd.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varcmd.mk,v 1.6 2021/02/16 19:43:09 rillig Exp $
+# $NetBSD: varcmd.mk,v 1.7 2023/04/07 05:54:16 rillig Exp $
#
# Test behaviour of recursive make and vars set on command line.
#
@@ -12,6 +12,10 @@
# be rewritten to make it clear why there is a difference and why this is
# actually intended. Removing that large block of code makes only this test
# and vardebug.mk fail, which is not enough.
+#
+# See also:
+# var-scope-cmdline.mk
+# varname-makeflags.mk
FU= fu
FOO?= foo
diff --git a/contrib/bmake/unit-tests/vardebug.exp b/contrib/bmake/unit-tests/vardebug.exp
index 6d00acc977af..a0aa6a301800 100644
--- a/contrib/bmake/unit-tests/vardebug.exp
+++ b/contrib/bmake/unit-tests/vardebug.exp
@@ -1,13 +1,13 @@
-Global:delete FROM_CMDLINE (not found)
-Command: FROM_CMDLINE =
+Global: ignoring delete 'FROM_CMDLINE' as it is not found
+Command: FROM_CMDLINE = # (empty)
Global: .MAKEOVERRIDES = FROM_CMDLINE
Global: VAR = added
Global: VAR = overwritten
-Global:delete VAR
-Global:delete VAR (not found)
-Var_SetExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored
-Var_AppendExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored
-Global: FROM_CMDLINE = overwritten ignored!
+Global: delete VAR
+Global: ignoring delete 'VAR' as it is not found
+Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty
+Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty
+Global: ignoring 'FROM_CMDLINE = overwritten' due to a command line variable of the same name
Global: VAR = 1
Global: VAR = 1 2
Global: VAR = 1 2 3
@@ -43,25 +43,25 @@ Result of ${:Uvalue} is "value" (eval-defined, defined)
Indirect modifier "M*e" from "${:UM*e}"
Evaluating modifier ${:M...} on value "value" (eval-defined, defined)
Pattern for ':M' is "*e"
-ModifyWords: split "value" into 1 words
+ModifyWords: split "value" into 1 word
Result of ${:M*e} is "value" (eval-defined, defined)
Evaluating modifier ${:M...} on value "value" (eval-defined, defined)
Pattern for ':M' is "valu[e]"
-ModifyWords: split "value" into 1 words
+ModifyWords: split "value" into 1 word
Result of ${:Mvalu[e]} is "value" (eval-defined, defined)
-Global:delete VAR
+Global: delete VAR
Var_Parse: ${:Uvariable:unknown} (eval-defined)
Evaluating modifier ${:U...} on value "" (eval-defined, undefined)
Result of ${:Uvariable} is "variable" (eval-defined, defined)
Evaluating modifier ${:u...} on value "variable" (eval-defined, defined)
-make: "vardebug.mk" line 44: Unknown modifier "unknown"
+make: "vardebug.mk" line 63: Unknown modifier "unknown"
Result of ${:unknown} is error (eval-defined, defined)
-make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown})
+make: "vardebug.mk" line 63: Malformed conditional (${:Uvariable:unknown})
Var_Parse: ${UNDEFINED} (eval-defined)
-make: "vardebug.mk" line 53: Malformed conditional (${UNDEFINED})
-Global:delete .SHELL (not found)
+make: "vardebug.mk" line 73: Malformed conditional (${UNDEFINED})
+Global: ignoring delete '.SHELL' as it is not found
Command: .SHELL = </path/to/shell>
-Command: .SHELL = overwritten ignored (read-only)
+Command: ignoring '.SHELL = overwritten' as it is read-only
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
make: Fatal errors encountered -- cannot continue
diff --git a/contrib/bmake/unit-tests/vardebug.mk b/contrib/bmake/unit-tests/vardebug.mk
index 4a16a7f2797f..b9b094772b54 100644
--- a/contrib/bmake/unit-tests/vardebug.mk
+++ b/contrib/bmake/unit-tests/vardebug.mk
@@ -1,32 +1,46 @@
-# $NetBSD: vardebug.mk,v 1.7 2021/02/04 21:42:47 rillig Exp $
+# $NetBSD: vardebug.mk,v 1.9 2023/12/20 09:46:00 rillig Exp $
#
# Demonstrates the debugging output for var.c.
.MAKEFLAGS: -dv FROM_CMDLINE=
+# expect: Global: VAR = added
VAR= added # VarAdd
+# expect: Global: VAR = overwritten
VAR= overwritten # Var_Set
-.undef VAR # Var_Delete (found)
-.undef VAR # Var_Delete (not found)
+# expect: Global: delete VAR
+.undef VAR
+# expect: Global: ignoring delete 'VAR' as it is not found
+.undef VAR
# The variable with the empty name cannot be set at all.
+# expect: Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty
${:U}= empty name # Var_Set
+# expect: Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty
${:U}+= empty name # Var_Append
FROM_CMDLINE= overwritten # Var_Set (ignored)
+# expect: Global: VAR = 1
VAR= 1
+# expect: Global: VAR = 1 2
VAR+= 2
+# expect: Global: VAR = 1 2 3
VAR+= 3
+# expect: Pattern for ':M' is "[2]"
+# expect: Result of ${VAR:M[2]} is "2"
.if ${VAR:M[2]} # ModifyWord_Match
.endif
-.if ${VAR:N[2]} # ModifyWord_NoMatch (no debug output)
+# expect: Pattern for ':N' is "[2]"
+# expect: Result of ${VAR:N[2]} is "1 3"
+.if ${VAR:N[2]} # ModifyWord_NoMatch
.endif
.if ${VAR:S,2,two,} # ParseModifierPart
.endif
+# expect: Result of ${VAR:Q} is "1\ 2\ 3"
.if ${VAR:Q} # VarQuote
.endif
@@ -34,13 +48,18 @@ VAR+= 3
.endif
# ApplyModifiers, "Got ..."
+# expect: Result of ${:Mvalu[e]} is "value" (eval-defined, defined)
.if ${:Uvalue:${:UM*e}:Mvalu[e]}
.endif
+# expect: Global: delete VAR
.undef ${:UVAR} # Var_Delete
# When ApplyModifiers results in an error, this appears in the debug log
# as "is error", without surrounding quotes.
+# expect: Result of ${:unknown} is error (eval-defined, defined)
+# expect+2: Malformed conditional (${:Uvariable:unknown})
+# expect+1: Unknown modifier "unknown"
.if ${:Uvariable:unknown}
.endif
@@ -50,15 +69,14 @@ VAR+= 3
# There is a specialized error message for "Undefined variable", but as of
# 2020-08-08, that is not covered by any unit tests. It might even be
# unreachable.
+# expect+1: Malformed conditional (${UNDEFINED})
.if ${UNDEFINED}
.endif
# By default, .SHELL is not defined and thus can be set. As soon as it is
# accessed, it is initialized in the command line scope (during VarFind),
# where it is set to read-only. Assigning to it is ignored.
+# expect: Command: ignoring '.SHELL = overwritten' as it is read-only
.MAKEFLAGS: .SHELL=overwritten
.MAKEFLAGS: -d0
-
-all:
- @:
diff --git a/contrib/bmake/unit-tests/varmisc.exp b/contrib/bmake/unit-tests/varmisc.exp
index f56f72d0ab9c..61e6a49963a0 100644
--- a/contrib/bmake/unit-tests/varmisc.exp
+++ b/contrib/bmake/unit-tests/varmisc.exp
@@ -17,12 +17,9 @@ false
FALSE
do not evaluate or expand :? if discarding
is set
-year=2016 month=04 day=01
-date=20160401
Version=123.456.789 == 123456789
Literal=3.4.5 == 3004005
We have target specific vars
-MAN= make.1
save-dollars: 0 = $
save-dollars: 1 = $$
save-dollars: 2 = $$
@@ -54,7 +51,7 @@ make: Unclosed variable "UNCLOSED"
make: Unclosed variable "UNCLOSED"
make: Unclosed variable "PATTERN"
-make: Unclosed variable expression, expecting '}' for modifier "M${PATTERN" of variable "UNCLOSED" with value ""
+make: Unclosed expression, expecting '}' for modifier "M${PATTERN" of variable "UNCLOSED" with value ""
make: Unclosed variable "param"
make: Unclosed variable "UNCLOSED."
diff --git a/contrib/bmake/unit-tests/varmisc.mk b/contrib/bmake/unit-tests/varmisc.mk
index e5ab375d8f39..f6a0e4da2d88 100644
--- a/contrib/bmake/unit-tests/varmisc.mk
+++ b/contrib/bmake/unit-tests/varmisc.mk
@@ -1,10 +1,10 @@
-# $Id: varmisc.mk,v 1.23 2021/02/05 20:02:30 sjg Exp $
-# $NetBSD: varmisc.mk,v 1.30 2021/02/04 21:42:47 rillig Exp $
+# $Id: varmisc.mk,v 1.26 2023/11/25 01:39:31 sjg Exp $
+# $NetBSD: varmisc.mk,v 1.33 2023/10/19 18:24:33 rillig Exp $
#
# Miscellaneous variable tests.
all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
- strftime cmpv manok
+ cmpv
all: save-dollars
all: export-appended
all: parse-dynamic
@@ -47,13 +47,6 @@ NQ_none:
@echo do not evaluate or expand :? if discarding
@echo ${VSET:U${1:L:?${True}:${False}}}
-April1= 1459494000
-
-# slightly contorted syntax to use utc via variable
-strftime:
- @echo ${year=%Y month=%m day=%d:L:gmtime=1459494000}
- @echo date=${%Y%m%d:L:${gmtime=${April1}:L}}
-
# big jumps to handle 3 digits per step
M_cmpv.units= 1 1000 1000000
M_cmpv= S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
@@ -66,24 +59,16 @@ cmpv:
@echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
@echo We have ${${.TARGET:T}.only}
-# catch misshandling of nested vars in .for loop
-MAN=
-MAN1= make.1
-.for s in 1 2
-. if defined(MAN$s) && !empty(MAN$s)
-MAN+= ${MAN$s}
-. endif
-.endfor
-
-manok:
- @echo MAN=${MAN}
+# Test parsing of boolean values.
# begin .MAKE.SAVE_DOLLARS; see Var_SetWithFlags and ParseBoolean.
SD_VALUES= 0 1 2 False True false true Yes No yes no On Off ON OFF on off
SD_4_DOLLARS= $$$$
.for val in ${SD_VALUES}
-.MAKE.SAVE_DOLLARS:= ${val} # Must be := since a simple = has no effect.
+# The assignment must be done using ':=' since a simple '=' would be
+# interpreted as 'yes', due to the leading '$'; see ParseBoolean.
+.MAKE.SAVE_DOLLARS:= ${val}
SD.${val}:= ${SD_4_DOLLARS}
.endfor
.MAKE.SAVE_DOLLARS:= yes
@@ -92,6 +77,7 @@ save-dollars:
.for val in ${SD_VALUES}
@printf '%s: %-8s = %s\n' $@ ${val} ${SD.${val}:Q}
.endfor
+# end .MAKE.SAVE_DOLLARS
# Appending to an undefined variable does not add a space in front.
.undef APPENDED
@@ -127,10 +113,10 @@ VAR.${PARAM}+= 2
.if ${VAR.+} != "1 2"
. error "${VAR.+}"
.endif
-.for param in + ! ?
+.for param in : + ! ?
VAR.${param}= ${param}
.endfor
-.if ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?"
+.if ${VAR.${:U\:}} != ":" || ${VAR.+} != "+" || ${VAR.!} != "!" || ${VAR.?} != "?"
. error "${VAR.+}" "${VAR.!}" "${VAR.?}"
.endif
diff --git a/contrib/bmake/unit-tests/varmod-assign-shell.exp b/contrib/bmake/unit-tests/varmod-assign-shell.exp
new file mode 100644
index 000000000000..b7c6cd223f24
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-assign-shell.exp
@@ -0,0 +1,14 @@
+make: "varmod-assign-shell.mk" line 28: warning: "echo output; false" returned non-zero status
+Global: _ = # (empty)
+Var_Parse: ${ASSIGNED::!=echo output; ${:Ufalse}} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${ASSIGNED::...} on value "previous" (eval-keep-dollar-and-undefined, regular)
+Modifier part: "echo output; false"
+Capturing the output of command "echo output; false"
+make: "echo output; false" returned non-zero status
+Result of ${ASSIGNED::!=echo output; ${:Ufalse}} is "" (eval-keep-dollar-and-undefined, regular)
+Global: _ = # (empty)
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
+DIRECT=output
+ASSIGNED=previous
+exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-assign-shell.mk b/contrib/bmake/unit-tests/varmod-assign-shell.mk
new file mode 100644
index 000000000000..6158bac14eaa
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-assign-shell.mk
@@ -0,0 +1,37 @@
+# $NetBSD: varmod-assign-shell.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
+#
+# Tests for the variable modifier '::!=', which assigns the output of a shell
+# command to the variable, but only if the command exited successfully. This
+# is different from the other places that capture the output of an external
+# command (variable assignment operator '!=', expression modifier ':sh',
+# expression modifier ':!...!'), which also use the output when the shell
+# command fails or crashes.
+#
+# The variable modifier '::!=' and its close relatives have been around since
+# var.c 1.45 from 2000-06-01.
+#
+# Before 2020.08.25.21.16.53, the variable modifier '::!=' had a bug for
+# unsuccessful commands, it put the previous value of the variable into the
+# error message instead of the command that was executed. That's where the
+# counterintuitive error message 'make: "previous" returned non-zero status'
+# comes from.
+#
+# BUGS
+# Even though the variable modifier '::!=' produces an error message,
+# the exit status of make is still 0.
+#
+# Having an error message instead of a warning like for the variable
+# assignment operator '!=' is another unnecessary inconsistency.
+
+DIRECT= previous
+# expect+1: warning: "echo output; false" returned non-zero status
+DIRECT!= echo output; false
+
+ASSIGNED= previous
+.MAKEFLAGS: -dv # to see the actual command
+_:= ${ASSIGNED::!=echo output; ${:Ufalse}}
+.MAKEFLAGS: -d0
+
+all:
+ @echo DIRECT=${DIRECT:Q}
+ @echo ASSIGNED=${ASSIGNED:Q}
diff --git a/contrib/bmake/unit-tests/varmod-assign.exp b/contrib/bmake/unit-tests/varmod-assign.exp
index 1e43714d500b..f258f92ea05b 100644
--- a/contrib/bmake/unit-tests/varmod-assign.exp
+++ b/contrib/bmake/unit-tests/varmod-assign.exp
@@ -12,18 +12,31 @@ Var_Parse: ${${VARNAME}} != "assigned-value" (eval-defined)
Var_Parse: ${VARNAME}} != "assigned-value" (eval-defined)
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
-mod-assign: first=1.
-mod-assign: last=3.
-mod-assign: appended=1 2 3.
-1
-2
-3
-mod-assign: ran:3.
-mod-assign: global: 1, 3, 1 2 3, 3.
-mod-assign-nested: then1t1
-mod-assign-nested: else2e2
-mod-assign-nested: then3t3
-mod-assign-nested: else4e4
+Var_Parse: ${CMD_CMD_VAR::=new-value} || ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined)
+Evaluating modifier ${CMD_CMD_VAR::...} on value "cmd-value"
+Modifier part: "new-value"
+Command: CMD_CMD_VAR = new-value
+Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR
+Result of ${CMD_CMD_VAR::=new-value} is ""
+Var_Parse: ${CMD_GLOBAL_VAR::=new-value} || ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined)
+Evaluating modifier ${CMD_GLOBAL_VAR::...} on value "global-value"
+Modifier part: "new-value"
+Global: CMD_GLOBAL_VAR = new-value
+Result of ${CMD_GLOBAL_VAR::=new-value} is ""
+Var_Parse: ${CMD_ENV_VAR::=new-value} || "${CMD_NEW_VAR::=new-value}" (eval-defined)
+Evaluating modifier ${CMD_ENV_VAR::...} on value "env-value"
+Modifier part: "new-value"
+Global: CMD_ENV_VAR = new-value
+Result of ${CMD_ENV_VAR::=new-value} is ""
+Var_Parse: ${CMD_NEW_VAR::=new-value}" (eval)
+Evaluating modifier ${CMD_NEW_VAR::...} on value "" (eval, undefined)
+Modifier part: "new-value"
+Global: ignoring delete 'CMD_NEW_VAR' as it is not found
+Command: CMD_NEW_VAR = new-value
+Global: .MAKEOVERRIDES = FIRST LAST LAST LAST APPENDED RAN RAN RAN IT1 THEN1 IE2 ELSE2 CMD_CMD_VAR CMD_CMD_VAR CMD_NEW_VAR
+Result of ${CMD_NEW_VAR::=new-value} is "" (eval, undefined)
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0
make: Bad modifier ":" for variable ""
mod-assign-empty: value}
make: Bad modifier ":" for variable ""
@@ -37,4 +50,11 @@ make: Unfinished modifier for "ASSIGN" ('}' missing)
ok=word
make: " echo word; false " returned non-zero status
err=previous
+Command: TARGET_CMD_VAR = cmd-value
+Global: TARGET_GLOBAL_VAR = global-value
+target: TARGET_TARGET_VAR = target-value
+target: TARGET_TARGET_VAR = new-value
+Global: TARGET_GLOBAL_VAR = new-value
+Global: TARGET_ENV_VAR = new-value
+target: TARGET_NEW_VAR = new-value
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-assign.mk b/contrib/bmake/unit-tests/varmod-assign.mk
index f50c654f5bcf..f7112c47c935 100644
--- a/contrib/bmake/unit-tests/varmod-assign.mk
+++ b/contrib/bmake/unit-tests/varmod-assign.mk
@@ -1,70 +1,85 @@
-# $NetBSD: varmod-assign.mk,v 1.12 2021/03/15 18:56:38 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.19 2024/01/07 11:42:22 rillig Exp $
#
# Tests for the obscure ::= variable modifiers, which perform variable
# assignments during evaluation, just like the = operator in C.
-all: mod-assign
-all: mod-assign-nested
+.if !make(target)
+
all: mod-assign-empty
all: mod-assign-parse
all: mod-assign-shell-error
-mod-assign:
- # The ::?= modifier applies the ?= assignment operator 3 times.
- # The ?= operator only has an effect for the first time, therefore
- # the variable FIRST ends up with the value 1.
- @echo $@: ${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}.
-
- # The ::= modifier applies the = assignment operator 3 times.
- # The = operator overwrites the previous value, therefore the
- # variable LAST ends up with the value 3.
- @echo $@: ${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}.
-
- # The ::+= modifier applies the += assignment operator 3 times.
- # The += operator appends 3 times to the variable, therefore
- # the variable APPENDED ends up with the value "1 2 3".
- @echo $@: ${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}.
-
- # The ::!= modifier applies the != assignment operator 3 times.
- # The side effects of the shell commands are visible in the output.
- # Just as with the ::= modifier, the last value is stored in the
- # RAN variable.
- @echo $@: ${echo.1 echo.2 echo.3:L:@i@${RAN::!=${i:C,.*,&; & 1>\&2,:S,., ,g}}@} ran:${RAN}.
-
- # The assignments happen in the global scope and thus are
- # preserved even after the shell command has been run.
- @echo $@: global: ${FIRST:Q}, ${LAST:Q}, ${APPENDED:Q}, ${RAN:Q}.
-
-mod-assign-nested:
- # The condition "1" is true, therefore THEN1 gets assigned a value,
- # and IT1 as well. Nothing surprising here.
- @echo $@: ${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}}${THEN1}${ELSE1}${IT1}${IE1}
-
- # The condition "0" is false, therefore ELSE1 gets assigned a value,
- # and IE1 as well. Nothing surprising here as well.
- @echo $@: ${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}}${THEN2}${ELSE2}${IT2}${IE2}
-
- # The same effects happen when the variables are defined elsewhere.
- @echo $@: ${SINK3:Q}
- @echo $@: ${SINK4:Q}
-SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}}${THEN3}${ELSE3}${IT3}${IE3}
-SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}}${THEN4}${ELSE4}${IT4}${IE4}
+# In the following loop expression,
+# the '::?=' modifier applies the assignment operator '?=' 3 times. The
+# operator '?=' only has an effect for the first time, therefore the variable
+# FIRST ends up with the value 1.
+.if "${1 2 3:L:@i@${FIRST::?=$i}@} first=${FIRST}" != " first=1"
+. error
+.endif
+
+# In the following loop expression,
+# the modifier '::=' applies the assignment operator '=' 3 times. The
+# operator '=' overwrites the previous value, therefore the variable LAST ends
+# up with the value 3.
+.if "${1 2 3:L:@i@${LAST::=$i}@} last=${LAST}" != " last=3"
+. error
+.endif
+
+# In the following loop expression,
+# the modifier '::+=' applies the assignment operator '+=' 3 times. The
+# operator '+=' appends 3 times to the variable, therefore the variable
+# APPENDED ends up with the value "1 2 3".
+.if "${1 2 3:L:@i@${APPENDED::+=$i}@} appended=${APPENDED}" != " appended=1 2 3"
+. error
+.endif
+
+# In the following loop expression,
+# the modifier '::!=' applies the assignment operator '!=' 3 times. Just as
+# with the modifier '::=', the last value is stored in the RAN variable.
+.if "${1 2 3:L:@i@${RAN::!=${i:%=echo '<%>';}}@} ran=${RAN}" != " ran=<3>"
+. error
+.endif
+
+# When a '::=' modifier is evaluated as part of an .if condition, it happens
+# in the command line scope.
+.if "${FIRST}, ${LAST}, ${APPENDED}, ${RAN}" != "1, 3, 1 2 3, <3>"
+. error
+.endif
+
+# Tests for nested assignments, which are hard to read and therefore seldom
+# used in practice.
+
+# The condition "1" is true, therefore THEN1 gets assigned a value,
+# and the inner IT1 as well. Nothing surprising here.
+.if "${1:?${THEN1::=then1${IT1::=t1}}:${ELSE1::=else1${IE1::=e1}}} ${THEN1}${ELSE1}${IT1}${IE1}" != " then1t1"
+. error
+.endif
+
+# The condition "0" is false, therefore ELSE2 gets assigned a value,
+# and the inner IE2 as well. Nothing surprising here as well.
+.if "${0:?${THEN2::=then2${IT2::=t2}}:${ELSE2::=else2${IE2::=e2}}} ${THEN2}${ELSE2}${IT2}${IE2}" != " else2e2"
+. error
+.endif
+
+# The same effects happen when the variables are defined elsewhere.
+SINK3:= ${1:?${THEN3::=then3${IT3::=t3}}:${ELSE3::=else3${IE3::=e3}}} ${THEN3}${ELSE3}${IT3}${IE3}
+SINK4:= ${0:?${THEN4::=then4${IT4::=t4}}:${ELSE4::=else4${IE4::=e4}}} ${THEN4}${ELSE4}${IT4}${IE4}
+.if ${SINK3} != " then3t3"
+. error
+.endif
+.if ${SINK4} != " else4e4"
+. error
+.endif
mod-assign-empty:
# Assigning to the empty variable would obviously not work since that
# variable is write-protected. Therefore it is rejected early with a
# "Bad modifier" message.
- #
- # XXX: The error message is hard to read since the variable name is
- # empty. This leads to a trailing space in the error message.
@echo $@: ${::=value}
# In this variant, it is not as obvious that the name of the
# expression is empty. Assigning to it is rejected as well, with the
# same "Bad modifier" message.
- #
- # XXX: The error message is hard to read since the variable name is
- # empty. This leads to a trailing space in the error message.
@echo $@: ${:Uvalue::=overwritten}
# The :L modifier sets the value of the expression to its variable
@@ -75,7 +90,8 @@ mod-assign-empty:
mod-assign-parse:
# The modifier for assignment operators starts with a ':'.
# An 'x' after that is an invalid modifier.
- @echo ${ASSIGN::x} # 'x' is an unknown assignment operator
+ # expect: make: Unknown modifier ":x"
+ @echo ${ASSIGN::x}
# When parsing an assignment operator fails because the operator is
# incomplete, make falls back to the SysV modifier.
@@ -106,7 +122,7 @@ APPEND.dollar= $${APPEND.indirect}
.endif
-# The assignment modifier can be used in a variable expression that is
+# The assignment modifier can be used in an expression that is
# enclosed in parentheses. In such a case, parsing stops at the first ')',
# not at the first '}'.
VAR= previous
@@ -139,3 +155,54 @@ ${VARNAME}= initial-value # Sets 'VAR.${param}' to 'expanded'.
. error
.endif
.MAKEFLAGS: -d0
+
+
+# Conditional directives are evaluated in command line scope. An assignment
+# modifier that creates a new variable creates it in the command line scope.
+# Existing variables are updated in their previous scope, and environment
+# variables are created in the global scope, as in other situations.
+.MAKEFLAGS: CMD_CMD_VAR=cmd-value
+CMD_GLOBAL_VAR=global-value
+export CMD_ENV_VAR=env-value
+.MAKEFLAGS: -dv
+# expect-reset
+# expect: Command: CMD_CMD_VAR = new-value
+# expect: Global: CMD_GLOBAL_VAR = new-value
+# expect: Global: CMD_ENV_VAR = new-value
+# expect: Global: ignoring delete 'CMD_NEW_VAR' as it is not found
+# expect: Command: CMD_NEW_VAR = new-value
+.if ${CMD_CMD_VAR::=new-value} \
+ || ${CMD_GLOBAL_VAR::=new-value} \
+ || ${CMD_ENV_VAR::=new-value} \
+ || "${CMD_NEW_VAR::=new-value}"
+. error
+.endif
+.MAKEFLAGS: -d0
+
+# Run the 'target' test in a separate sub-make, with reduced debug logging.
+all: run-target
+run-target: .PHONY
+ @${MAKE} -r -f ${MAKEFILE} -dv target 2>&1 | grep ': TARGET_'
+
+.else # make(target)
+
+# The commands of a target are evaluated in target scope. An assignment
+# modifier that creates a new variable creates it in the target scope.
+# Existing variables are updated in their previous scope, and environment
+# variables are created in the global scope, as in other situations.
+#
+# expect: target: TARGET_TARGET_VAR = new-value
+# expect: Global: TARGET_GLOBAL_VAR = new-value
+# expect: Global: TARGET_ENV_VAR = new-value
+# expect: target: TARGET_NEW_VAR = new-value
+.MAKEFLAGS: TARGET_CMD_VAR=cmd-value
+TARGET_GLOBAL_VAR=global-value
+export TARGET_ENV_VAR=env-value
+target: .PHONY TARGET_TARGET_VAR=target-value
+ : ${TARGET_TARGET_VAR::=new-value}
+ : ${TARGET_CMD_VAR::=new-value}
+ : ${TARGET_GLOBAL_VAR::=new-value}
+ : ${TARGET_ENV_VAR::=new-value}
+ : ${TARGET_NEW_VAR::=new-value}
+
+.endif
diff --git a/contrib/bmake/unit-tests/varmod-defined.exp b/contrib/bmake/unit-tests/varmod-defined.exp
index 2f7d4dbf4baa..d82a292292a4 100644
--- a/contrib/bmake/unit-tests/varmod-defined.exp
+++ b/contrib/bmake/unit-tests/varmod-defined.exp
@@ -1,5 +1,5 @@
Global: 8_DOLLARS = $$$$$$$$
-Global: VAR =
+Global: VAR = # (empty)
Var_Parse: ${8_DOLLARS} (eval-keep-dollar-and-undefined)
Global: VAR = $$$$$$$$
Var_Parse: ${VAR:D${8_DOLLARS}} (eval-keep-dollar-and-undefined)
@@ -11,11 +11,11 @@ Var_Parse: ${VAR:@var@${8_DOLLARS}@} (eval-keep-dollar-and-undefined)
Evaluating modifier ${VAR:@...} on value "$$$$$$$$" (eval-keep-dollar-and-undefined, regular)
Modifier part: "var"
Modifier part: "${8_DOLLARS}"
-ModifyWords: split "$$$$$$$$" into 1 words
+ModifyWords: split "$$$$$$$$" into 1 word
Global: var = $$$$$$$$
Var_Parse: ${8_DOLLARS} (eval-keep-undefined)
-ModifyWord_Loop: in "$$$$$$$$", replace "var" with "${8_DOLLARS}" to "$$$$"
-Global:delete var
+ModifyWord_Loop: expand "${8_DOLLARS}" to "$$$$"
+Global: delete var
Result of ${VAR:@var@${8_DOLLARS}@} is "$$$$" (eval-keep-dollar-and-undefined, regular)
Global: VAR = $$$$
Global: .MAKEFLAGS = -r -k -d v -d
diff --git a/contrib/bmake/unit-tests/varmod-defined.mk b/contrib/bmake/unit-tests/varmod-defined.mk
index a44b9f993146..2ee9def9e164 100644
--- a/contrib/bmake/unit-tests/varmod-defined.mk
+++ b/contrib/bmake/unit-tests/varmod-defined.mk
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-defined.mk,v 1.11 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-defined.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :D variable modifier, which returns the given string
# if the variable is defined. It is closely related to the :U modifier.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
DEF= defined
@@ -43,10 +46,10 @@ DEF= defined
. error
.endif
-# Like in several other places in variable expressions, when
+# Like in several other places in expressions, when
# ApplyModifier_Defined calls Var_Parse, double dollars lead to a parse
# error that is silently ignored. This makes all dollar signs disappear,
-# except for the last, which is a well-formed variable expression.
+# except for the last, which is a well-formed expression.
#
.if ${DEF:D$$$$$${DEF}} != "defined"
. error
@@ -55,7 +58,7 @@ DEF= defined
# Any other text is written without any further escaping. In contrast
# to the :M modifier, parentheses and braces do not need to be nested.
# Instead, the :D modifier is implemented sanely by parsing nested
-# expressions as such, without trying any shortcuts. See ApplyModifier_Match
+# expressions as such, without trying any shortcuts. See ParseModifier_Match
# for an inferior variant.
#
.if ${DEF:D!&((((} != "!&(((("
@@ -101,5 +104,13 @@ VAR:= ${VAR:D${8_DOLLARS}}
VAR:= ${VAR:@var@${8_DOLLARS}@}
.MAKEFLAGS: -d0
-all:
- @:;
+
+# Before var.c 1.1030 from 2022-08-24, the following expression caused an
+# out-of-bounds read when parsing the indirect ':U' modifier.
+M_U_backslash:= ${:UU\\}
+.if ${:${M_U_backslash}} != "\\"
+. error
+.endif
+
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varmod-edge.exp b/contrib/bmake/unit-tests/varmod-edge.exp
index d9db72b2e2ef..c2477f16e950 100644
--- a/contrib/bmake/unit-tests/varmod-edge.exp
+++ b/contrib/bmake/unit-tests/varmod-edge.exp
@@ -1,27 +1,27 @@
-make: "varmod-edge.mk" line 166: ok M-paren
-make: "varmod-edge.mk" line 166: ok M-mixed
-make: "varmod-edge.mk" line 166: ok M-unescape
-make: Unclosed variable expression, expecting '}' for modifier "U*)" of variable "" with value "*)"
-make: "varmod-edge.mk" line 166: ok M-nest-mix
-make: "varmod-edge.mk" line 166: ok M-nest-brk
-make: "varmod-edge.mk" line 166: ok M-pat-err
-make: "varmod-edge.mk" line 166: ok M-bsbs
-make: "varmod-edge.mk" line 166: ok M-bs1-par
-make: "varmod-edge.mk" line 166: ok M-bs2-par
-make: "varmod-edge.mk" line 166: ok M-128
-make: "varmod-edge.mk" line 166: ok eq-ext
-make: "varmod-edge.mk" line 166: ok eq-q
-make: "varmod-edge.mk" line 166: ok eq-bs
+make: "varmod-edge.mk" line 184: ok M-paren
+make: "varmod-edge.mk" line 184: ok M-mixed
+make: "varmod-edge.mk" line 184: ok M-unescape
+make: Unclosed expression, expecting '}' for modifier "U*)" of variable "" with value "*)"
+make: "varmod-edge.mk" line 184: ok M-nest-mix
+make: "varmod-edge.mk" line 184: ok M-nest-brk
+make: "varmod-edge.mk" line 184: ok M-pat-err
+make: "varmod-edge.mk" line 184: ok M-bsbs
+make: "varmod-edge.mk" line 184: ok M-bs1-par
+make: "varmod-edge.mk" line 184: ok M-bs2-par
+make: "varmod-edge.mk" line 184: ok M-128
+make: "varmod-edge.mk" line 184: ok eq-ext
+make: "varmod-edge.mk" line 184: ok eq-q
+make: "varmod-edge.mk" line 184: ok eq-bs
make: Unfinished modifier for "INP.eq-esc" ('=' missing)
-make: "varmod-edge.mk" line 166: ok eq-esc
-make: "varmod-edge.mk" line 166: ok colon
-make: "varmod-edge.mk" line 165: Unknown modifier ":"
-make: "varmod-edge.mk" line 165: Unknown modifier ":"
-make: "varmod-edge.mk" line 166: ok colons
-make: "varmod-edge.mk" line 175: Unknown modifier "Z"
-make: "varmod-edge.mk" line 175: Malformed conditional (${:Z})
+make: "varmod-edge.mk" line 184: ok eq-esc
+make: "varmod-edge.mk" line 184: ok colon
+make: "varmod-edge.mk" line 167: Unknown modifier ":"
+make: "varmod-edge.mk" line 167: Unknown modifier ":"
+make: "varmod-edge.mk" line 184: ok colons
+make: "varmod-edge.mk" line 195: Unknown modifier "Z"
+make: "varmod-edge.mk" line 195: Malformed conditional (${:Z})
make: Unfinished modifier for "" (',' missing)
-make: "varmod-edge.mk" line 188: Malformed conditional (${:S,})
+make: "varmod-edge.mk" line 209: Malformed conditional (${:S,})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-edge.mk b/contrib/bmake/unit-tests/varmod-edge.mk
index 762053d281a3..91220d99e47d 100644
--- a/contrib/bmake/unit-tests/varmod-edge.mk
+++ b/contrib/bmake/unit-tests/varmod-edge.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.16 2021/02/23 15:56:30 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.19 2023/11/19 22:06:15 rillig Exp $
#
# Tests for edge cases in variable modifiers.
#
@@ -16,7 +16,7 @@ MOD.M-paren= ${INP.M-paren:M(*)}
EXP.M-paren= (parentheses) ()
# The first closing brace matches the opening parenthesis.
-# The second closing brace actually ends the variable expression.
+# The second closing brace actually ends the expression.
#
# XXX: This is unexpected but rarely occurs in practice.
TESTS+= M-mixed
@@ -40,7 +40,7 @@ EXP.M-unescape= \(\{}\):
# as open_parens + open_braces == closing_parens + closing_braces. This
# means that ( and } form a matching pair.
#
-# Nested variable expressions are not parsed as such. Instead, only the
+# Nested expressions are not parsed as such. Instead, only the
# parentheses and braces are counted. This leads to a parse error since
# the nested expression is not "${:U*)}" but only "${:U*)", which is
# missing the closing brace. The expression is evaluated anyway.
@@ -51,7 +51,7 @@ TESTS+= M-nest-mix
INP.M-nest-mix= (parentheses)
MOD.M-nest-mix= ${INP.M-nest-mix:M${:U*)}}
EXP.M-nest-mix= (parentheses)}
-# make: Unclosed variable expression, expecting '}' for modifier "U*)" of variable "" with value "*)"
+# make: Unclosed expression, expecting '}' for modifier "U*)" of variable "" with value "*)"
# In contrast to parentheses and braces, the brackets are not counted
# when the :M modifier is parsed since Makefile variables only take the
@@ -162,7 +162,25 @@ MOD.colons= ${INP.colons::::}
EXP.colons= # empty
.for test in ${TESTS}
+# expect+2: Unknown modifier ":"
+# expect+1: Unknown modifier ":"
. if ${MOD.${test}} == ${EXP.${test}}
+# expect+16: ok M-paren
+# expect+15: ok M-mixed
+# expect+14: ok M-unescape
+# expect+13: ok M-nest-mix
+# expect+12: ok M-nest-brk
+# expect+11: ok M-pat-err
+# expect+10: ok M-bsbs
+# expect+09: ok M-bs1-par
+# expect+08: ok M-bs2-par
+# expect+07: ok M-128
+# expect+06: ok eq-ext
+# expect+05: ok eq-q
+# expect+04: ok eq-bs
+# expect+03: ok eq-esc
+# expect+02: ok colon
+# expect+01: ok colons
. info ok ${test}
. else
. warning error in ${test}: expected "${EXP.${test}}", got "${MOD.${test}}"
@@ -172,6 +190,8 @@ EXP.colons= # empty
# Even in expressions based on an unnamed variable, there may be errors.
# XXX: The error message should mention the variable name of the expression,
# even though that name is empty in this case.
+# expect+2: Malformed conditional (${:Z})
+# expect+1: Unknown modifier "Z"
.if ${:Z}
. error
.else
@@ -185,6 +205,7 @@ EXP.colons= # empty
# modifier for (',' missing)", having two spaces in a row.
#
# XXX: The error message should report the filename:lineno.
+# expect+1: Malformed conditional (${:S,})
.if ${:S,}
. error
.else
diff --git a/contrib/bmake/unit-tests/varmod-gmtime.exp b/contrib/bmake/unit-tests/varmod-gmtime.exp
index 5d5806b92d26..bbb8bd547bd5 100644
--- a/contrib/bmake/unit-tests/varmod-gmtime.exp
+++ b/contrib/bmake/unit-tests/varmod-gmtime.exp
@@ -1,13 +1,13 @@
-make: "varmod-gmtime.mk" line 57: Invalid time value: ${:U1593536400}} != "mtime=11593536400}"
-make: "varmod-gmtime.mk" line 57: Malformed conditional (${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}")
-make: "varmod-gmtime.mk" line 67: Invalid time value: -1} != ""
-make: "varmod-gmtime.mk" line 67: Malformed conditional (${:L:gmtime=-1} != "")
-make: "varmod-gmtime.mk" line 76: Invalid time value: 1} != ""
-make: "varmod-gmtime.mk" line 76: Malformed conditional (${:L:gmtime= 1} != "")
-make: "varmod-gmtime.mk" line 119: Invalid time value: 10000000000000000000000000000000} != ""
-make: "varmod-gmtime.mk" line 119: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
-make: "varmod-gmtime.mk" line 130: Invalid time value: error} != ""
-make: "varmod-gmtime.mk" line 130: Malformed conditional (${:L:gmtime=error} != "")
+make: "varmod-gmtime.mk" line 61: Invalid time value "-1"
+make: "varmod-gmtime.mk" line 61: Malformed conditional (${:L:gmtime=-1} != "")
+make: "varmod-gmtime.mk" line 72: Invalid time value " 1"
+make: "varmod-gmtime.mk" line 72: Malformed conditional (${:L:gmtime= 1} != "")
+make: "varmod-gmtime.mk" line 120: Invalid time value "10000000000000000000000000000000"
+make: "varmod-gmtime.mk" line 120: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
+make: "varmod-gmtime.mk" line 133: Invalid time value "error"
+make: "varmod-gmtime.mk" line 133: Malformed conditional (${:L:gmtime=error} != "")
+make: "varmod-gmtime.mk" line 144: Invalid time value "100000S,1970,bad,"
+make: "varmod-gmtime.mk" line 144: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-gmtime.mk b/contrib/bmake/unit-tests/varmod-gmtime.mk
index cb3d4e7eb241..c30f5edbecc2 100644
--- a/contrib/bmake/unit-tests/varmod-gmtime.mk
+++ b/contrib/bmake/unit-tests/varmod-gmtime.mk
@@ -1,7 +1,10 @@
-# $NetBSD: varmod-gmtime.mk,v 1.10 2021/01/19 05:26:34 rillig Exp $
+# $NetBSD: varmod-gmtime.mk,v 1.21 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :gmtime variable modifier, which formats a timestamp
# using strftime(3) in UTC.
+#
+# See also:
+# varmod-localtime.mk
.if ${TZ:Uundefined} != "undefined" # see unit-tests/Makefile
. error
@@ -41,20 +44,9 @@
.endif
-# As of 2020-08-16, it is not possible to pass the seconds via a
-# variable expression. This is because parsing of the :gmtime
-# modifier stops at the '$' and returns to ApplyModifiers.
-#
-# There, a colon would be skipped but not a dollar.
-# Parsing therefore continues at the '$' of the ${:U159...}, looking
-# for an ordinary variable modifier.
-#
-# At this point, the ${:U} is expanded and interpreted as a variable
-# modifier, which results in the error message "Unknown modifier '1'".
-#
-# If ApplyModifier_Gmtime were to pass its argument through
-# ParseModifierPart, this would work.
-.if ${%Y:L:gmtime=${:U1593536400}} != "mtime=11593536400}"
+# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the
+# seconds via an expression.
+.if ${%Y:L:gmtime=${:U1593536400}} != "2020"
. error
.endif
@@ -64,6 +56,8 @@
# 1970. Going back 50 years in the past is not a practical use case for
# make. Therefore, since var.c 1.631, negative time stamps produce a
# parse error.
+# expect+2: Invalid time value "-1"
+# expect+1: Malformed conditional (${:L:gmtime=-1} != "")
.if ${:L:gmtime=-1} != ""
. error
.else
@@ -73,8 +67,12 @@
# Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
# because it would make sense but just as a side-effect from using strtoul.
+# expect+2: Invalid time value " 1"
+# expect+1: Malformed conditional (${:L:gmtime= 1} != "")
.if ${:L:gmtime= 1} != ""
. error
+.else
+. error
.endif
@@ -115,7 +113,10 @@
# ULONG_MAX, which got converted to -1. This resulted in a time stamp of
# the second before 1970.
#
-# Since var.c 1.631, the overflow is detected and produces a parse error.
+# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a
+# parse error.
+# expect+2: Invalid time value "10000000000000000000000000000000"
+# expect+1: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
.if ${:L:gmtime=10000000000000000000000000000000} != ""
. error
.else
@@ -127,11 +128,61 @@
# stopped after the '=', and the remaining string was parsed for more variable
# modifiers. Because of the unknown modifier 'e' from the 'error', the whole
# variable value was discarded and thus not printed.
+# expect+2: Invalid time value "error"
+# expect+1: Malformed conditional (${:L:gmtime=error} != "")
.if ${:L:gmtime=error} != ""
. error
.else
. error
.endif
+# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly
+# followed by the next modifier, without a ':' separator. This was the same
+# bug as for the ':L' and ':P' modifiers.
+# expect+2: Invalid time value "100000S,1970,bad,"
+# expect+1: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad")
+.if ${%Y:L:gmtime=100000S,1970,bad,} != "bad"
+. error
+.endif
+
+
+# Before var.c 1.1062 from 2023-08-19, ':gmtime' but not ':localtime' reported
+# wrong values for '%s', depending on the operating system and the timezone.
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=Europe/Berlin
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=America/Los_Angeles
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+export TZ=UTC
+.for t in ${%s:L:gmtime} ${%s:L:localtime}
+TIMESTAMPS+= $t
+.endfor
+.for a b in ${TIMESTAMPS:[1]} ${TIMESTAMPS:@t@$t $t@} ${TIMESTAMPS:[-1]}
+. if $a > $b
+. warning timestamp $a > $b
+. endif
+.endfor
+
+
+.if ${year=%Y month=%m day=%d:L:gmtime=1459494000} != "year=2016 month=04 day=01"
+. error
+.endif
+# Slightly contorted syntax to convert a UTC timestamp from an expression to a
+# formatted timestamp.
+.if ${%Y%m%d:L:${gmtime=${:U1459494000}:L}} != "20160401"
+. error
+.endif
+
all:
diff --git a/contrib/bmake/unit-tests/varmod-head.exp b/contrib/bmake/unit-tests/varmod-head.exp
index 651844439f5f..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/varmod-head.exp
+++ b/contrib/bmake/unit-tests/varmod-head.exp
@@ -1,11 +1 @@
-head (dirname) of 'a/b/c' is 'a/b'
-head (dirname) of 'def' is '.'
-head (dirname) of 'a.b.c' is '.'
-head (dirname) of 'a.b/c' is 'a.b'
-head (dirname) of 'a' is '.'
-head (dirname) of 'a.a' is '.'
-head (dirname) of '.gitignore' is '.'
-head (dirname) of 'a' is '.'
-head (dirname) of 'a.a' is '.'
-head (dirname) of 'trailing/' is 'trailing'
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-head.mk b/contrib/bmake/unit-tests/varmod-head.mk
index 66347b4bce61..f1a135cb328d 100644
--- a/contrib/bmake/unit-tests/varmod-head.mk
+++ b/contrib/bmake/unit-tests/varmod-head.mk
@@ -1,9 +1,64 @@
-# $NetBSD: varmod-head.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $
+# $NetBSD: varmod-head.mk,v 1.5 2022/07/10 21:11:49 rillig Exp $
#
# Tests for the :H variable modifier, which returns the dirname of
# each of the words in the variable value.
-all:
-.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/
- @echo "head (dirname) of '"${path:Q}"' is '"${path:H:Q}"'"
-.endfor
+.if ${:U a/b/c :H} != "a/b"
+. error
+.endif
+
+.if ${:U def :H} != "."
+. error
+.endif
+
+.if ${:U a.b.c :H} != "."
+. error
+.endif
+
+.if ${:U a.b/c :H} != "a.b"
+. error
+.endif
+
+.if ${:U a :H} != "."
+. error
+.endif
+
+.if ${:U a.a :H} != "."
+. error
+.endif
+
+.if ${:U .gitignore :H} != "."
+. error
+.endif
+
+.if ${:U trailing/ :H} != "trailing"
+. error
+.endif
+
+.if ${:U /abs/dir/file :H} != "/abs/dir"
+. error
+.endif
+
+.if ${:U rel/dir/file :H} != "rel/dir"
+. error
+.endif
+
+# The head of "/" was an empty string before 2020.07.20.14.50.41, leading to
+# the output "before after", with two spaces. Since 2020.07.20.14.50.41, the
+# output is "before after", discarding the empty word.
+.if ${:U before/ / after/ :H} == "before after"
+# OK
+.elif ${:U before/ / after/ :H} == "before after"
+# No '.info' to keep the file compatible with old make versions.
+_!= echo "The modifier ':H' generates an empty word." 1>&2; echo
+.else
+. error
+.endif
+
+# An empty list is split into a single empty word.
+# The dirname of this empty word is ".".
+.if ${:U :H} != "."
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varmod-ifelse.exp b/contrib/bmake/unit-tests/varmod-ifelse.exp
index e42e39525f1c..653fe104ddaa 100644
--- a/contrib/bmake/unit-tests/varmod-ifelse.exp
+++ b/contrib/bmake/unit-tests/varmod-ifelse.exp
@@ -1,32 +1,51 @@
-make: Bad conditional expression 'variable expression == "literal"' in 'variable expression == "literal"?bad:bad'
-make: "varmod-ifelse.mk" line 27: Malformed conditional (${${:Uvariable expression} == "literal":?bad:bad})
-make: Bad conditional expression ' == ""' in ' == ""?bad-assign:bad-assign'
-make: Bad conditional expression ' == ""' in ' == ""?bad-cond:bad-cond'
-make: "varmod-ifelse.mk" line 44: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond})
-make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no'
-make: "varmod-ifelse.mk" line 66: Malformed conditional (${1 == == 2:?yes:no} != "")
+make: Bad conditional expression 'bare words == "literal"' before '?bad:bad'
+make: "varmod-ifelse.mk" line 28: Malformed conditional (${${:Ubare words} == "literal":?bad:bad})
+make: Bad conditional expression ' == ""' before '?bad-assign:bad-assign'
+make: Bad conditional expression ' == ""' before '?bad-cond:bad-cond'
+make: "varmod-ifelse.mk" line 46: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond})
+make: Bad conditional expression '1 == == 2' before '?yes:no'
+make: "varmod-ifelse.mk" line 69: Malformed conditional (${1 == == 2:?yes:no} != "")
CondParser_Eval: "${1 == == 2:?yes:no}" != ""
CondParser_Eval: 1 == == 2
-lhs = 1.000000, rhs = 0.000000, op = ==
-make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no'
-lhs = "", rhs = "", op = !=
-make: "varmod-ifelse.mk" line 92: warning: Oops, the parse error should have been propagated.
-CondParser_Eval: ${ ${:U\$}{VAR} == value :?ok:bad} != "ok"
-CondParser_Eval: ${VAR} == value
-lhs = "value", rhs = "value", op = ==
-lhs = "ok", rhs = "ok", op = !=
-make: "varmod-ifelse.mk" line 153: no.
-make: "varmod-ifelse.mk" line 154: String comparison operator must be either == or !=
-make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
-make: "varmod-ifelse.mk" line 154: .
-make: Bad conditional expression 'string == "literal" && >= 10' in 'string == "literal" && >= 10?yes:no'
-make: "varmod-ifelse.mk" line 159: .
-make: Bad conditional expression 'string == "literal" || >= 10' in 'string == "literal" || >= 10?yes:no'
-make: "varmod-ifelse.mk" line 160: .
-make: "varmod-ifelse.mk" line 167: true
-make: "varmod-ifelse.mk" line 169: false
-make: Bad conditional expression ' ' in ' ?true:false'
-make: "varmod-ifelse.mk" line 171:
+Comparing 1.000000 == 0.000000
+make: Bad conditional expression '1 == == 2' before '?yes:no'
+Comparing "" != ""
+make: "varmod-ifelse.mk" line 96: warning: Oops, the parse error should have been propagated.
+CondParser_Eval: ${ ${:U\$}{VAR} == value:?ok:bad} != "ok"
+CondParser_Eval: ${VAR} == value
+Comparing "value" == "value"
+Comparing "ok" != "ok"
+make: "varmod-ifelse.mk" line 158: no.
+make: "varmod-ifelse.mk" line 162: Comparison with '>=' requires both operands 'no' and '10' to be numeric
+make: Bad conditional expression 'string == "literal" || no >= 10' before '?yes:no'
+make: "varmod-ifelse.mk" line 162: .
+make: Bad conditional expression 'string == "literal" && >= 10' before '?yes:no'
+make: "varmod-ifelse.mk" line 169: .
+make: Bad conditional expression 'string == "literal" || >= 10' before '?yes:no'
+make: "varmod-ifelse.mk" line 172: .
+make: "varmod-ifelse.mk" line 180: <true>
+make: "varmod-ifelse.mk" line 183: <false>
+make: Bad conditional expression ' ' before '?true:false'
+make: "varmod-ifelse.mk" line 186: <>
+CondParser_Eval: 0 && ${1:?${:Uthen0:S,}},,}:${:Uelse0:S,}},,}} != "not evaluated"
+CondParser_Eval: 1 && ${0:?${:Uthen1:S,}},,}:${:Uelse1:S,}},,}} != "else1"
+CondParser_Eval: 0
+Comparing "else1" != "else1"
+CondParser_Eval: 2 && ${1:?${:Uthen2:S,}},,}:${:Uelse2:S,}},,}} != "then2"
+CondParser_Eval: 1
+Comparing "then2" != "then2"
+CondParser_Eval: ${DELAYED} == "one"
+Comparing "two" == "one"
+make: "varmod-ifelse.mk" line 282: no
+CondParser_Eval: ${DELAYED} == "two"
+Comparing "two" == "two"
+make: "varmod-ifelse.mk" line 284: yes
+CondParser_Eval: ${DELAYED} == "one"
+Comparing "two" == "one"
+make: "varmod-ifelse.mk" line 287: no
+CondParser_Eval: ${DELAYED} == "two"
+Comparing "two" == "two"
+make: "varmod-ifelse.mk" line 290: yes
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-ifelse.mk b/contrib/bmake/unit-tests/varmod-ifelse.mk
index 0e16032a6543..5c8b55d92717 100644
--- a/contrib/bmake/unit-tests/varmod-ifelse.mk
+++ b/contrib/bmake/unit-tests/varmod-ifelse.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.17 2021/06/11 13:01:28 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.26 2023/12/10 20:12:28 rillig Exp $
#
# Tests for the ${cond:?then:else} variable modifier, which evaluates either
# the then-expression or the else-expression, depending on the condition.
@@ -11,20 +11,21 @@
# TODO: Implementation
# The variable name of the expression is expanded and then taken as the
-# condition. In this case it becomes:
+# condition. In the below example it becomes:
#
-# variable expression == "variable expression"
+# bare words == "literal"
#
# This confuses the parser, which expects an operator instead of the bare
# word "expression". If the name were expanded lazily, everything would be
# fine since the condition would be:
#
-# ${:Uvariable expression} == "literal"
+# ${:Ubare words} == "literal"
#
# Evaluating the variable name lazily would require additional code in
# Var_Parse and ParseVarname, it would be more useful and predictable
# though.
-.if ${${:Uvariable expression} == "literal":?bad:bad}
+# expect+1: Malformed conditional (${${:Ubare words} == "literal":?bad:bad})
+.if ${${:Ubare words} == "literal":?bad:bad}
. error
.else
. error
@@ -41,6 +42,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
# "Undefined variable" error message is generated.
# The difference to the ':=' variable assignment is the additional
# "Malformed conditional" error message.
+# expect+1: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond})
.if ${${UNDEF} == "":?bad-cond:bad-cond}
. error
.else
@@ -59,10 +61,11 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
# This line generates 2 error messages. The first comes from evaluating the
# malformed conditional "1 == == 2", which is reported as "Bad conditional
-# expression" by ApplyModifier_IfElse. The variable expression containing that
+# expression" by ApplyModifier_IfElse. The expression containing that
# conditional therefore returns a parse error from Var_Parse, and this parse
# error propagates to CondEvalExpression, where the "Malformed conditional"
# comes from.
+# expect+1: Malformed conditional (${1 == == 2:?yes:no} != "")
.if ${1 == == 2:?yes:no} != ""
. error
.else
@@ -76,7 +79,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
# XXX: The left-hand side is enclosed in quotes. This results in Var_Parse
# being called without VARE_UNDEFERR. When ApplyModifier_IfElse
# returns AMR_CLEANUP as result, Var_Parse returns varUndefined since the
-# value of the variable expression is still undefined. CondParser_String is
+# value of the expression is still undefined. CondParser_String is
# then supposed to do proper error handling, but since varUndefined is local
# to var.c, it cannot distinguish this return value from an ordinary empty
# string. The left-hand side of the comparison is therefore just an empty
@@ -89,15 +92,16 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
.if "${1 == == 2:?yes:no}" != ""
. error
.else
+# expect+1: warning: Oops, the parse error should have been propagated.
. warning Oops, the parse error should have been propagated.
.endif
.MAKEFLAGS: -d0
-# As of 2020-12-10, the variable "name" is first expanded, and the result of
-# this expansion is then taken as the condition. To force the variable
+# As of 2020-12-10, the variable "VAR" is first expanded, and the result of
+# this expansion is then taken as the condition. To force the
# expression in the condition to be evaluated at exactly the right point,
# the '$' of the intended '${VAR}' escapes from the parser in form of the
-# expression ${:U\$}. Because of this escaping, the variable "name" and thus
+# expression ${:U\$}. Because of this escaping, the variable "VAR" and thus
# the condition ends up as "${VAR} == value", just as intended.
#
# This hack does not work for variables from .for loops since these are
@@ -106,7 +110,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
# from the parser of the .for loop body. See ForLoop_SubstVarLong.
.MAKEFLAGS: -dc
VAR= value
-.if ${ ${:U\$}{VAR} == value :?ok:bad} != "ok"
+.if ${ ${:U\$}{VAR} == value:?ok:bad} != "ok"
. error
.endif
.MAKEFLAGS: -d0
@@ -133,7 +137,7 @@ VAR= value
# When parsing such an expression, the parser used to be strict. It first
# evaluated the left-hand side of the operator '&&' and then started parsing
# the right-hand side 'no >= 10'. The word 'no' is obviously a string
-# literal, not enclosed in quotes, which is ok, even on the left-hand side of
+# literal, not enclosed in quotes, which is OK, even on the left-hand side of
# the comparison operator, but only because this is a condition in the
# modifier ':?'. In an ordinary directive '.if', this would be a parse error.
# For strings, only the comparison operators '==' and '!=' are defined,
@@ -150,13 +154,21 @@ VAR= value
# instead of just saying that the whole condition is bad.
STRING= string
NUMBER= no # not really a number
+# expect+1: no.
.info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
+# expect+3: Comparison with '>=' requires both operands 'no' and '10' to be numeric
+# expect: make: Bad conditional expression 'string == "literal" || no >= 10' before '?yes:no'
+# expect+1: .
.info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.
# The following situation occasionally occurs with MKINET6 or similar
# variables.
NUMBER= # empty, not really a number either
+# expect: make: Bad conditional expression 'string == "literal" && >= 10' before '?yes:no'
+# expect+1: .
.info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
+# expect: make: Bad conditional expression 'string == "literal" || >= 10' before '?yes:no'
+# expect+1: .
.info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.
# CondParser_LeafToken handles [0-9-+] specially, treating them as a number.
@@ -164,8 +176,132 @@ PLUS= +
ASTERISK= *
EMPTY= # empty
# "true" since "+" is not the empty string.
-.info ${${PLUS} :?true:false}
+# expect+1: <true>
+.info <${${PLUS} :?true:false}>
# "false" since the variable named "*" is not defined.
-.info ${${ASTERISK} :?true:false}
+# expect+1: <false>
+.info <${${ASTERISK} :?true:false}>
# syntax error since the condition is completely blank.
-.info ${${EMPTY} :?true:false}
+# expect+1: <>
+.info <${${EMPTY} :?true:false}>
+
+
+# Since the condition of the '?:' modifier is expanded before being parsed and
+# evaluated, it is common practice to enclose expressions in quotes, to avoid
+# producing syntactically invalid conditions such as ' == value'. This only
+# works if the expanded values neither contain quotes nor backslashes. For
+# strings containing quotes or backslashes, the '?:' modifier should not be
+# used.
+PRIMES= 2 3 5 7 11
+.if ${1 2 3 4 5:L:@n@$n:${ ("${PRIMES:M$n}" != "") :?prime:not_prime}@} != \
+ "1:not_prime 2:prime 3:prime 4:not_prime 5:prime"
+. error
+.endif
+
+# When parsing the modifier ':?', there are 3 possible cases:
+#
+# 1. The whole expression is only parsed.
+# 2. The expression is parsed and the 'then' branch is evaluated.
+# 3. The expression is parsed and the 'else' branch is evaluated.
+#
+# In all of these cases, the expression must be parsed in the same way,
+# especially when one of the branches contains unbalanced '{}' braces.
+#
+# At 2020-01-01, the expressions from the 'then' and 'else' branches were
+# parsed differently, depending on whether the branch was taken or not. When
+# the branch was taken, the parser recognized that in the modifier ':S,}},,',
+# the '}}' were ordinary characters. When the branch was not taken, the
+# parser only counted balanced '{' and '}', ignoring any escaping or other
+# changes in the interpretation.
+#
+# In var.c 1.285 from 2020-07-20, the parsing of the expressions changed so
+# that in both cases the expression is parsed in the same way, taking the
+# unbalanced braces in the ':S' modifiers into account. This change was not
+# on purpose, the commit message mentioned 'has the same effect', which was a
+# wrong assumption.
+#
+# In var.c 1.323 from 2020-07-26, the unintended fix from var.c 1.285 was
+# reverted, still not knowing about the difference between regular parsing and
+# balanced-mode parsing.
+#
+# In var.c 1.1028 from 2022-08-08, there was another attempt at fixing this
+# inconsistency in parsing, but since that broke parsing of the modifier ':@',
+# it was reverted in var.c 1.1029 from 2022-08-23.
+#
+# In var.c 1.1047 from 2023-02-18, the inconsistency in parsing was finally
+# fixed. The modifier ':@' now parses the body in balanced mode, while
+# everywhere else the modifier parts have their subexpressions parsed in the
+# same way, no matter whether they are evaluated or not.
+#
+# The modifiers ':@' and ':?' are similar in that they conceptually contain
+# text to be evaluated later or conditionally, still they parse that text
+# differently. The crucial difference is that the body of the modifier ':@'
+# is always parsed using balanced mode. The modifier ':?', on the other hand,
+# must parse both of its branches in the same way, no matter whether they are
+# evaluated or not. Since balanced mode and standard mode are incompatible,
+# it's impossible to use balanced mode in the modifier ':?'.
+.MAKEFLAGS: -dc
+.if 0 && ${1:?${:Uthen0:S,}},,}:${:Uelse0:S,}},,}} != "not evaluated"
+# At 2020-01-07, the expression evaluated to 'then0,,}}', even though it was
+# irrelevant as the '0' had already been evaluated to 'false'.
+. error
+.endif
+.if 1 && ${0:?${:Uthen1:S,}},,}:${:Uelse1:S,}},,}} != "else1"
+. error
+.endif
+.if 2 && ${1:?${:Uthen2:S,}},,}:${:Uelse2:S,}},,}} != "then2"
+# At 2020-01-07, the whole expression evaluated to 'then2,,}}' instead of the
+# expected 'then2'. The 'then' branch of the ':?' modifier was parsed
+# normally, parsing and evaluating the ':S' modifier, thereby treating the
+# '}}' as ordinary characters and resulting in 'then2'. The 'else' branch was
+# parsed in balanced mode, ignoring that the inner '}}' were ordinary
+# characters. The '}}' were thus interpreted as the end of the 'else' branch
+# and the whole expression. This left the trailing ',,}}', which together
+# with the 'then2' formed the result 'then2,,}}'.
+. error
+.endif
+
+
+# Since the condition is taken from the variable name of the expression, not
+# from its value, it is evaluated early. It is possible though to construct
+# conditions that are evaluated lazily, at exactly the right point. There is
+# no way to escape a '$' directly in the variable name, but there are
+# alternative ways to bring a '$' into the condition.
+#
+# In an indirect condition using the ':U' modifier, each '$', ':' and
+# '}' must be escaped as '\$', '\:' and '\}', respectively, but '{' must
+# not be escaped.
+#
+# In an indirect condition using a separate variable, each '$' must be
+# escaped as '$$'.
+#
+# These two forms allow the variables to contain arbitrary characters, as the
+# condition parser does not see them.
+DELAYED= two
+# expect+1: no
+.info ${ ${:U \${DELAYED\} == "one"}:?yes:no}
+# expect+1: yes
+.info ${ ${:U \${DELAYED\} == "two"}:?yes:no}
+INDIRECT_COND1= $${DELAYED} == "one"
+# expect+1: no
+.info ${ ${INDIRECT_COND1}:?yes:no}
+INDIRECT_COND2= $${DELAYED} == "two"
+# expect+1: yes
+.info ${ ${INDIRECT_COND2}:?yes:no}
+
+
+.MAKEFLAGS: -d0
+
+
+# In the modifier parts for the 'then' and 'else' branches, subexpressions are
+# parsed in by inspecting the actual modifiers. In 2008, 2015, 2020, 2022 and
+# 2023, the exact parsing algorithm switched a few times, counting balanced
+# braces instead of proper subexpressions, which meant that unbalanced braces
+# were parsed differently, depending on whether the branch was active or not.
+BRACES= }}}
+NO= ${0:?${BRACES:S,}}},yes,}:${BRACES:S,}}},no,}}
+YES= ${1:?${BRACES:S,}}},yes,}:${BRACES:S,}}},no,}}
+BOTH= <${YES}> <${NO}>
+.if ${BOTH} != "<yes> <no>"
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/varmod-indirect.exp b/contrib/bmake/unit-tests/varmod-indirect.exp
index 63ed988d0c0e..ecf52033ee4b 100644
--- a/contrib/bmake/unit-tests/varmod-indirect.exp
+++ b/contrib/bmake/unit-tests/varmod-indirect.exp
@@ -1,40 +1,40 @@
make: "varmod-indirect.mk" line 19: Unknown modifier "${"
make: "varmod-indirect.mk" line 52: Unknown modifier "${"
-make: "varmod-indirect.mk" line 55: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression.
-make: "varmod-indirect.mk" line 140: before
-make: "varmod-indirect.mk" line 140: after
-make: "varmod-indirect.mk" line 146: before
-make: "varmod-indirect.mk" line 146: after
-make: "varmod-indirect.mk" line 152: before
-make: "varmod-indirect.mk" line 152: after
-make: "varmod-indirect.mk" line 156: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 157: before
-make: "varmod-indirect.mk" line 157: after
-ParseReadLine (166): '_:= before ${UNDEF} after'
-Global: _ =
+make: "varmod-indirect.mk" line 54: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression.
+make: "varmod-indirect.mk" line 143: before
+make: "varmod-indirect.mk" line 143: after
+make: "varmod-indirect.mk" line 151: before
+make: "varmod-indirect.mk" line 151: after
+make: "varmod-indirect.mk" line 159: before
+make: "varmod-indirect.mk" line 159: after
+make: "varmod-indirect.mk" line 164: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 167: before
+make: "varmod-indirect.mk" line 167: after
+Parsing line 176: _:= before ${UNDEF} after
+Global: _ = # (empty)
Var_Parse: ${UNDEF} after (eval-keep-dollar-and-undefined)
Global: _ = before ${UNDEF} after
-ParseReadLine (169): '_:= before ${UNDEF:${:US,a,a,}} after'
+Parsing line 179: _:= before ${UNDEF:${:US,a,a,}} after
Var_Parse: ${UNDEF:${:US,a,a,}} after (eval-keep-dollar-and-undefined)
Indirect modifier "S,a,a," from "${:US,a,a,}"
Evaluating modifier ${UNDEF:S...} on value "" (eval-keep-dollar-and-undefined, undefined)
Modifier part: "a"
Modifier part: "a"
-ModifyWords: split "" into 1 words
+ModifyWords: split "" into 1 word
Result of ${UNDEF:S,a,a,} is "" (eval-keep-dollar-and-undefined, undefined)
Global: _ = before ${UNDEF:S,a,a,} after
-ParseReadLine (179): '_:= before ${UNDEF:${:U}} after'
+Parsing line 189: _:= before ${UNDEF:${:U}} after
Var_Parse: ${UNDEF:${:U}} after (eval-keep-dollar-and-undefined)
Indirect modifier "" from "${:U}"
Global: _ = before ${UNDEF:} after
-ParseReadLine (184): '_:= before ${UNDEF:${:UZ}} after'
+Parsing line 195: _:= before ${UNDEF:${:UZ}} after
Var_Parse: ${UNDEF:${:UZ}} after (eval-keep-dollar-and-undefined)
Indirect modifier "Z" from "${:UZ}"
Evaluating modifier ${UNDEF:Z} on value "" (eval-keep-dollar-and-undefined, undefined)
-make: "varmod-indirect.mk" line 184: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 195: Unknown modifier "Z"
Result of ${UNDEF:Z} is error (eval-keep-dollar-and-undefined, undefined)
Global: _ = before ${UNDEF:Z} after
-ParseReadLine (186): '.MAKEFLAGS: -d0'
+Parsing line 197: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d 0 -d pv -d
Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 0
diff --git a/contrib/bmake/unit-tests/varmod-indirect.mk b/contrib/bmake/unit-tests/varmod-indirect.mk
index fa58997cc849..99e7215aa639 100644
--- a/contrib/bmake/unit-tests/varmod-indirect.mk
+++ b/contrib/bmake/unit-tests/varmod-indirect.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.9 2021/03/15 20:00:50 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.18 2024/02/04 10:03:10 rillig Exp $
#
# Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
# These can be used for very basic purposes like converting a string to either
@@ -11,11 +11,11 @@
# To apply a modifier indirectly via another variable, the whole
-# modifier must be put into a single variable expression.
+# modifier must be put into a single expression.
# The following expression generates a parse error since its indirect
-# modifier contains more than a sole variable expression.
+# modifier contains more than a sole expression.
#
-# expect+1: Unknown modifier '$'
+# expect+1: Unknown modifier "${"
.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
. warning unexpected
.endif
@@ -47,9 +47,10 @@
# error. Because of this parse error, this feature cannot be used reasonably
# in practice.
#
-# expect+1: Unknown modifier '$'
+# expect+2: Unknown modifier "${"
#.MAKEFLAGS: -dvc
.if ${value:L:${:UM*}S,value,replaced,} == "M*S,value,replaced,}"
+# expect+1: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression.
. warning FIXME: this expression should have resulted in a parse $\
error rather than returning the unparsed portion of the $\
expression.
@@ -70,20 +71,20 @@
.endif
-# The nested variable expression expands to "tu", and this is interpreted as
+# The nested expression expands to "tu", and this is interpreted as
# a variable modifier for the value "Upper", resulting in "UPPER".
.if ${Upper:L:${:Utu}} != "UPPER"
. error
.endif
-# The nested variable expression expands to "tl", and this is interpreted as
+# The nested expression expands to "tl", and this is interpreted as
# a variable modifier for the value "Lower", resulting in "lower".
.if ${Lower:L:${:Utl}} != "lower"
. error
.endif
-# The nested variable expression is ${1 != 1:?Z:tl}, consisting of the
+# The nested expression is ${1 != 1:?Z:tl}, consisting of the
# condition "1 != 1", the then-branch "Z" and the else-branch "tl". Since
# the condition evaluates to false, the then-branch is ignored (it would
# have been an unknown modifier anyway) and the ":tl" modifier is applied.
@@ -132,28 +133,37 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}}
.MAKEFLAGS: -d0
-# In contrast to the .if conditions, the .for loop allows undefined variable
+# In contrast to the .if conditions, the .for loop allows undefined
# expressions. These expressions expand to empty strings.
# An undefined expression without any modifiers expands to an empty string.
.for var in before ${UNDEF} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# An undefined expression with only modifiers that keep the expression
# undefined expands to an empty string.
.for var in before ${UNDEF:${:US,a,a,}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# Even in an indirect modifier based on an undefined variable, the value of
# the expression in Var_Parse is a simple empty string.
.for var in before ${UNDEF:${:U}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# An error in an indirect modifier.
+# expect+1: Unknown modifier "Z"
.for var in before ${UNDEF:${:UZ}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
@@ -162,10 +172,10 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}}
# a variable assignment using ':='.
.MAKEFLAGS: -dpv
-# The undefined variable expression is kept as-is.
+# The undefined expression is kept as-is.
_:= before ${UNDEF} after
-# The undefined variable expression is kept as-is.
+# The undefined expression is kept as-is.
_:= before ${UNDEF:${:US,a,a,}} after
# XXX: The subexpression ${:U} is fully defined, therefore it is expanded.
@@ -179,8 +189,9 @@ _:= before ${UNDEF:${:US,a,a,}} after
_:= before ${UNDEF:${:U}} after
# XXX: This expands to ${UNDEF:Z}, which will behave differently if the
-# variable '_' is used in a context where the variable expression ${_} is
+# variable '_' is used in a context where the expression ${_} is
# parsed but not evaluated.
+# expect+1: Unknown modifier "Z"
_:= before ${UNDEF:${:UZ}} after
.MAKEFLAGS: -d0
@@ -190,7 +201,7 @@ _:= before ${UNDEF:${:UZ}} after
# When evaluating indirect modifiers, these modifiers may expand to ':tW',
# which modifies the interpretation of the expression value. This modified
# interpretation only lasts until the end of the indirect modifier, it does
-# not influence the outer variable expression.
+# not influence the outer expression.
.if ${1 2 3:L:tW:[#]} != 1 # direct :tW applies to the :[#]
. error
.endif
@@ -202,7 +213,7 @@ _:= before ${UNDEF:${:UZ}} after
# When evaluating indirect modifiers, these modifiers may expand to ':ts*',
# which modifies the interpretation of the expression value. This modified
# interpretation only lasts until the end of the indirect modifier, it does
-# not influence the outer variable expression.
+# not influence the outer expression.
#
# In this first expression, the direct ':ts*' has no effect since ':U' does not
# treat the expression value as a list of words but as a single word. It has
@@ -244,4 +255,28 @@ _:= before ${UNDEF:${:UZ}} after
. error
.endif
-all:
+
+# In parse-only mode, the indirect modifiers must not be evaluated.
+#
+# Before var.c 1.1098 from 2024-02-04, the expression for an indirect modifier
+# was partially evaluated (only the variable value, without applying any
+# modifiers) and then interpreted as modifiers to the main expression.
+#
+# The expression ${:UZ} starts with the value "", and in parse-only mode, the
+# modifier ':UZ' does not modify the expression value. This results in an
+# empty string for the indirect modifiers, generating no warning.
+.if 0 && ${VAR:${:UZ}}
+.endif
+# The expression ${M_invalid} starts with the value "Z", which is an unknown
+# modifier. Trying to apply this unknown modifier generated a warning.
+M_invalid= Z
+.if 0 && ${VAR:${M_invalid}}
+.endif
+# The ':S' modifier does not change the expression value in parse-only mode,
+# keeping the "Z", which is then skipped in parse-only mode.
+.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
+.endif
+# The ':@' modifier does not change the expression value in parse-only mode,
+# keeping the "Z", which is then skipped in parse-only mode.
+.if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}
+.endif
diff --git a/contrib/bmake/unit-tests/varmod-l-name-to-value.mk b/contrib/bmake/unit-tests/varmod-l-name-to-value.mk
index 354622cf098b..e87e68967544 100644
--- a/contrib/bmake/unit-tests/varmod-l-name-to-value.mk
+++ b/contrib/bmake/unit-tests/varmod-l-name-to-value.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-l-name-to-value.mk,v 1.7 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varmod-l-name-to-value.mk,v 1.8 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :L modifier, which returns the variable name as the new value.
@@ -28,7 +28,7 @@
.endif
# Between 2020-09-22 (var.c 1.527) and 2020-09-30 (var.c 1.553), there was
-# a bug in the evaluation of variable expressions. Indirect modifiers like
+# a bug in the evaluation of expressions. Indirect modifiers like
# the below :L did not update the definedness of the enclosing expression.
# This resulted in a wrong "Malformed conditional".
.if ${value:${:UL}} == ""
diff --git a/contrib/bmake/unit-tests/varmod-localtime.exp b/contrib/bmake/unit-tests/varmod-localtime.exp
index ed4d4f053c61..a7c3ff6ab932 100644
--- a/contrib/bmake/unit-tests/varmod-localtime.exp
+++ b/contrib/bmake/unit-tests/varmod-localtime.exp
@@ -1,13 +1,13 @@
-make: "varmod-localtime.mk" line 57: Invalid time value: ${:U1593536400}} != "mtime=11593536400}"
-make: "varmod-localtime.mk" line 57: Malformed conditional (${%Y:L:localtime=${:U1593536400}} != "mtime=11593536400}")
-make: "varmod-localtime.mk" line 67: Invalid time value: -1} != ""
-make: "varmod-localtime.mk" line 67: Malformed conditional (${:L:localtime=-1} != "")
-make: "varmod-localtime.mk" line 76: Invalid time value: 1} != ""
-make: "varmod-localtime.mk" line 76: Malformed conditional (${:L:localtime= 1} != "")
-make: "varmod-localtime.mk" line 119: Invalid time value: 10000000000000000000000000000000} != ""
-make: "varmod-localtime.mk" line 119: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "")
-make: "varmod-localtime.mk" line 130: Invalid time value: error} != ""
-make: "varmod-localtime.mk" line 130: Malformed conditional (${:L:localtime=error} != "")
+make: "varmod-localtime.mk" line 61: Invalid time value "-1"
+make: "varmod-localtime.mk" line 61: Malformed conditional (${:L:localtime=-1} != "")
+make: "varmod-localtime.mk" line 72: Invalid time value " 1"
+make: "varmod-localtime.mk" line 72: Malformed conditional (${:L:localtime= 1} != "")
+make: "varmod-localtime.mk" line 120: Invalid time value "10000000000000000000000000000000"
+make: "varmod-localtime.mk" line 120: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "")
+make: "varmod-localtime.mk" line 133: Invalid time value "error"
+make: "varmod-localtime.mk" line 133: Malformed conditional (${:L:localtime=error} != "")
+make: "varmod-localtime.mk" line 144: Invalid time value "100000S,1970,bad,"
+make: "varmod-localtime.mk" line 144: Malformed conditional (${%Y:L:localtime=100000S,1970,bad,} != "bad")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-localtime.mk b/contrib/bmake/unit-tests/varmod-localtime.mk
index f2867b61f8e9..f6fcc61a7fa6 100644
--- a/contrib/bmake/unit-tests/varmod-localtime.mk
+++ b/contrib/bmake/unit-tests/varmod-localtime.mk
@@ -1,9 +1,12 @@
-# $NetBSD: varmod-localtime.mk,v 1.8 2021/01/19 05:26:34 rillig Exp $
+# $NetBSD: varmod-localtime.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :localtime variable modifier, which formats a timestamp
# using strftime(3) in local time.
+#
+# See also:
+# varmod-gmtime.mk
-.if ${TZ} != "Europe/Berlin" # see unit-tests/Makefile
+.if ${TZ:Uno:NEurope/Berlin:NUTC-1} != "" # see unit-tests/Makefile
. error
.endif
@@ -41,20 +44,9 @@
.endif
-# As of 2020-08-16, it is not possible to pass the seconds via a
-# variable expression. This is because parsing of the :localtime
-# modifier stops at the '$' and returns to ApplyModifiers.
-#
-# There, a colon would be skipped but not a dollar.
-# Parsing therefore continues at the '$' of the ${:U159...}, looking
-# for an ordinary variable modifier.
-#
-# At this point, the ${:U} is expanded and interpreted as a variable
-# modifier, which results in the error message "Unknown modifier '1'".
-#
-# If ApplyModifier_Localtime were to pass its argument through
-# ParseModifierPart, this would work.
-.if ${%Y:L:localtime=${:U1593536400}} != "mtime=11593536400}"
+# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the
+# seconds via an expression.
+.if ${%Y:L:localtime=${:U1593536400}} != "2020"
. error
.endif
@@ -64,6 +56,8 @@
# 1970. Going back 50 years in the past is not a practical use case for
# make. Therefore, since var.c 1.631, negative time stamps produce a
# parse error.
+# expect+2: Invalid time value "-1"
+# expect+1: Malformed conditional (${:L:localtime=-1} != "")
.if ${:L:localtime=-1} != ""
. error
.else
@@ -73,8 +67,12 @@
# Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
# because it would make sense but just as a side-effect from using strtoul.
+# expect+2: Invalid time value " 1"
+# expect+1: Malformed conditional (${:L:localtime= 1} != "")
.if ${:L:localtime= 1} != ""
. error
+.else
+. error
.endif
@@ -115,7 +113,10 @@
# ULONG_MAX, which got converted to -1. This resulted in a time stamp of
# the second before 1970.
#
-# Since var.c 1.631, the overflow is detected and produces a parse error.
+# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a
+# parse error.
+# expect+2: Invalid time value "10000000000000000000000000000000"
+# expect+1: Malformed conditional (${:L:localtime=10000000000000000000000000000000} != "")
.if ${:L:localtime=10000000000000000000000000000000} != ""
. error
.else
@@ -127,11 +128,21 @@
# stopped after the '=', and the remaining string was parsed for more variable
# modifiers. Because of the unknown modifier 'e' from the 'error', the whole
# variable value was discarded and thus not printed.
+# expect+2: Invalid time value "error"
+# expect+1: Malformed conditional (${:L:localtime=error} != "")
.if ${:L:localtime=error} != ""
. error
.else
. error
.endif
+# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly
+# followed by the next modifier, without a ':' separator. This was the same
+# bug as for the ':L' and ':P' modifiers.
+# expect+2: Invalid time value "100000S,1970,bad,"
+# expect+1: Malformed conditional (${%Y:L:localtime=100000S,1970,bad,} != "bad")
+.if ${%Y:L:localtime=100000S,1970,bad,} != "bad"
+. error
+.endif
all:
diff --git a/contrib/bmake/unit-tests/varmod-loop-delete.exp b/contrib/bmake/unit-tests/varmod-loop-delete.exp
new file mode 100644
index 000000000000..47a2f74545a3
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-loop-delete.exp
@@ -0,0 +1,4 @@
+make: "varmod-loop-delete.mk" line 20: Cannot delete variable "VAR" while it is used
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-loop-delete.mk b/contrib/bmake/unit-tests/varmod-loop-delete.mk
new file mode 100644
index 000000000000..1ec6d361949d
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-loop-delete.mk
@@ -0,0 +1,34 @@
+# $NetBSD: varmod-loop-delete.mk,v 1.3 2023/06/01 20:56:35 rillig Exp $
+#
+# Tests for the variable modifier ':@', which as a side effect allows to
+# delete an arbitrary variable.
+
+# A side effect of the modifier ':@' is that the loop variable is created as
+# an actual variable in the current evaluation scope (Command/Global/target),
+# and at the end of the loop, this variable is deleted. Since var.c 1.204
+# from 2016-02-18 and before var.c 1.963 from 2021-12-05, a variable could be
+# deleted while it was in use, leading to a use-after-free bug.
+#
+# See Var_Parse, comment 'the value of the variable must not change'.
+
+# Set up the variable that deletes itself when it is evaluated.
+VAR= ${:U:@VAR@@} rest of the value
+
+# In an assignment, the scope is 'Global'. Since the variable 'VAR' is
+# defined in the global scope, it deletes itself.
+# expect+1: Cannot delete variable "VAR" while it is used
+EVAL:= ${VAR}
+.if ${EVAL} != " rest of the value"
+. error
+.endif
+
+VAR= ${:U:@VAR@@} rest of the value
+all: .PHONY
+ # In the command that is associated with a target, the scope is the
+ # one from the target. That scope only contains a few variables like
+ # '.TARGET', '.ALLSRC', '.IMPSRC'. Make does not expect that these
+ # variables get modified from the outside.
+ #
+ # There is no variable named 'VAR' in the local scope, so nothing
+ # happens.
+ : $@: '${VAR}'
diff --git a/contrib/bmake/unit-tests/varmod-loop-varname.exp b/contrib/bmake/unit-tests/varmod-loop-varname.exp
index 9170307bd2a0..2060b51c31df 100644
--- a/contrib/bmake/unit-tests/varmod-loop-varname.exp
+++ b/contrib/bmake/unit-tests/varmod-loop-varname.exp
@@ -1,11 +1,11 @@
-make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
-make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
-make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
-make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 18: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar
+make: "varmod-loop-varname.mk" line 18: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 89: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar
+make: "varmod-loop-varname.mk" line 89: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 96: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar
+make: "varmod-loop-varname.mk" line 96: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 103: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar
+make: "varmod-loop-varname.mk" line 103: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-loop-varname.mk b/contrib/bmake/unit-tests/varmod-loop-varname.mk
index d51e2ba76a42..6f7436f277da 100644
--- a/contrib/bmake/unit-tests/varmod-loop-varname.mk
+++ b/contrib/bmake/unit-tests/varmod-loop-varname.mk
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-loop-varname.mk,v 1.2 2021/04/04 13:35:26 rillig Exp $
+# $NetBSD: varmod-loop-varname.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the first part of the variable modifier ':@var@...@', which
# contains the variable name to use during the loop.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
@@ -10,8 +13,12 @@
# dynamically. There was no practical use-case for this.
# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
# variable name.
+# expect+2: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar
+# expect+1: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
.if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+"
. error
+.else
+. error
.endif
@@ -77,16 +84,22 @@ RES3= 3
# There's no point in allowing a dollar sign in that position.
# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
# variable name.
+# expect+2: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar
+# expect+1: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
.if ${1 2 3:L:@v$@($v)@} != "(1) (2) (3)"
. error
.else
. error
.endif
+# expect+2: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar
+# expect+1: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
.if ${1 2 3:L:@v$$@($v)@} != "() () ()"
. error
.else
. error
.endif
+# expect+2: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar
+# expect+1: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
.if ${1 2 3:L:@v$$$@($v)@} != "() () ()"
. error
.else
@@ -99,7 +112,7 @@ RES3= 3
#
# As of 2020-10-18, the :@ modifier is implemented by actually setting a
# variable in the scope of the expression and deleting it again after the
-# loop. This is different from the .for loops, which substitute the variable
+# loop. This is different from the .for loops, which substitute the
# expression with ${:Uvalue}, leading to different unwanted side effects.
#
# To make the behavior more predictable, the :@ modifier should restore the
diff --git a/contrib/bmake/unit-tests/varmod-loop.exp b/contrib/bmake/unit-tests/varmod-loop.exp
index a4704973f6e2..356946f63a9b 100644
--- a/contrib/bmake/unit-tests/varmod-loop.exp
+++ b/contrib/bmake/unit-tests/varmod-loop.exp
@@ -1,10 +1,10 @@
-ParseReadLine (75): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
+Parsing line 91: USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$
CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$"
-lhs = "$$$$ $$$$ $$$$", rhs = "$$$$ $$$$ $$$$", op = !=
-ParseReadLine (80): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
+Comparing "$$$$ $$$$ $$$$" != "$$$$ $$$$ $$$$"
+Parsing line 96: SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}
CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$"
-lhs = "$$ $$$$ $$$$", rhs = "$$ $$$$ $$$$", op = !=
-ParseReadLine (105): '.MAKEFLAGS: -d0'
+Comparing "$$ $$$$ $$$$" != "$$ $$$$ $$$$"
+Parsing line 121: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
:varname-overwriting-target: :x1y x2y x3y: ::
mod-loop-dollar:1:
@@ -13,4 +13,10 @@ mod-loop-dollar:$3$:
mod-loop-dollar:$${word}$$:
mod-loop-dollar:$$5$$:
mod-loop-dollar:$$${word}$$$:
+: t=$(( ${t:-0} + 1 ))
+: dollar=end
+: backslash=\ end
+: dollar=$ at=@ backslash=\ end
+: dollar=$$ at=@@ backslash=\\ end
+: dollar=$$ at=@@ backslash=\\ end
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-loop.mk b/contrib/bmake/unit-tests/varmod-loop.mk
index 4fdaa3ff4e61..64cc6ca85043 100644
--- a/contrib/bmake/unit-tests/varmod-loop.mk
+++ b/contrib/bmake/unit-tests/varmod-loop.mk
@@ -1,7 +1,24 @@
-# $NetBSD: varmod-loop.mk,v 1.15 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.24 2023/11/19 21:47:52 rillig Exp $
#
-# Tests for the :@var@...${var}...@ variable modifier.
+# Tests for the expression modifier ':@var@body@', which replaces each word of
+# the expression with the expanded body, which may contain references to the
+# variable 'var'. For example, '${1 2 3:L:@word@<${word}>@}' encloses each
+# word in angle quotes, resulting in '<1> <2> <3>'.
+#
+# The variable name can be chosen freely, except that it must not contain a
+# '$'. For simplicity and readability, variable names should only use the
+# characters 'A-Za-z0-9'.
+#
+# The body may contain subexpressions in the form '${...}' or '$(...)'. These
+# subexpressions differ from everywhere else in makefiles in that the parser
+# only scans '${...}' for balanced '{' and '}', likewise for '$(...)'. Any
+# other '$' is left as-is during parsing. Later, when the body is expanded
+# for each word, each '$$' is interpreted as a single '$', and the remaining
+# '$' are interpreted as expressions, like when evaluating a regular variable.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
all: varname-overwriting-target
@@ -16,7 +33,6 @@ varname-overwriting-target:
@echo :$@: :${:U1 2 3:@\@@x${@}y@}: :$@:
-
# Demonstrate that it is possible to generate dollar signs using the
# :@ modifier.
#
@@ -36,7 +52,7 @@ mod-loop-dollar:
#
# As of 2020-10-18, the :@ modifier is implemented by actually setting a
# variable in the scope of the expression and deleting it again after the
-# loop. This is different from the .for loops, which substitute the variable
+# loop. This is different from the .for loops, which substitute the
# expression with ${:Uvalue}, leading to different unwanted side effects.
#
# To make the behavior more predictable, the :@ modifier should restore the
@@ -95,7 +111,7 @@ SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}
# The variable SUBST_CONTAINING_LOOP therefore gets assigned the raw value
# "$$$$ $$$$$$$$ $$$$$$$$".
#
-# The variable expression in the condition then expands this raw stored value
+# The expression in the condition then expands this raw stored value
# once, resulting in "$$ $$$$ $$$$". The effects from VARE_KEEP_DOLLAR no
# longer take place since they had only been active during the evaluation of
# the variable assignment.
@@ -184,6 +200,47 @@ CMDLINE= global # needed for deleting the environment
.endif
-# TODO: Actually trigger the undefined behavior (use after free) that was
-# already suspected in Var_Parse, in the comment 'the value of the variable
-# must not change'.
+# In the loop body text of the ':@' modifier, a literal '$' is written as '$$',
+# not '\$'. In the following example, each '$$' turns into a single '$',
+# except for '$i', which is replaced with the then-current value '1' of the
+# iteration variable.
+#
+# See parse-var.mk, keyword 'BRACE_GROUP'.
+all: varmod-loop-literal-dollar
+varmod-loop-literal-dollar: .PHONY
+ : ${:U1:@i@ t=$$(( $${t:-0} + $i ))@}
+
+
+# When parsing the loop body, each '\$', '\@' and '\\' is unescaped to '$',
+# '@' and '\', respectively; all other backslashes are retained.
+#
+# In practice, the '$' is not escaped as '\$', as there is a second round of
+# unescaping '$$' to '$' later when the loop body is expanded after setting the
+# iteration variable.
+#
+# After the iteration variable has been set, the loop body is expanded with
+# this unescaping, regardless of whether .MAKE.SAVE_DOLLARS is set or not:
+# $$ a literal '$'
+# $x, ${var}, $(var) a nested expression
+# any other character itself
+all: escape-modifier
+escape-modifier: .PHONY
+ # In the first round, '\$ ' is unescaped to '$ ', and since the
+ # variable named ' ' is not defined, the expression '$ ' expands to an
+ # empty string.
+ # expect: : dollar=end
+ : ${:U1:@i@ dollar=\$ end@}
+
+ # Like in other modifiers, '\ ' is preserved, since ' ' is not one of
+ # the characters that _must_ be escaped.
+ # expect: : backslash=\ end
+ : ${:U1:@i@ backslash=\ end@}
+
+ # expect: : dollar=$ at=@ backslash=\ end
+ : ${:U1:@i@ dollar=\$\$ at=\@ backslash=\\ end@}
+ # expect: : dollar=$$ at=@@ backslash=\\ end
+ : ${:U1:@i@ dollar=\$\$\$\$ at=\@\@ backslash=\\\\ end@}
+ # expect: : dollar=$$ at=@@ backslash=\\ end
+ : ${:U1:@i@ dollar=$$$$ at=\@\@ backslash=\\\\ end@}
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varmod-match-escape.exp b/contrib/bmake/unit-tests/varmod-match-escape.exp
index 42cdd7a87ac9..9a8f9ccf6082 100755
--- a/contrib/bmake/unit-tests/varmod-match-escape.exp
+++ b/contrib/bmake/unit-tests/varmod-match-escape.exp
@@ -10,7 +10,7 @@ Evaluating modifier ${SPECIALS:M...} on value "\: : \\ * \*"
Pattern for ':M' is ":"
ModifyWords: split "\: : \\ * \*" into 5 words
Result of ${SPECIALS:M\:${:U}} is ":"
-lhs = ":", rhs = ":", op = !=
+Comparing ":" != ":"
Global: VALUES = : :: :\:
CondParser_Eval: ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:}
Var_Parse: ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:} (eval-defined)
@@ -29,11 +29,13 @@ Result of ${:U\:} is ":" (eval-defined, defined)
Pattern for ':M' is ":\:"
ModifyWords: split ": :: :\:" into 3 words
Result of ${VALUES:M${:U\:}\:} is "::"
-lhs = ":", rhs = "::", op = !=
-make: "varmod-match-escape.mk" line 42: warning: XXX: Oops
+Comparing ":" != "::"
+make: "varmod-match-escape.mk" line 43: warning: XXX: Oops
Global: .MAKEFLAGS = -r -k -d cv -d
Global: .MAKEFLAGS = -r -k -d cv -d 0
-make: "varmod-match-escape.mk" line 67: Dollar followed by nothing
+make: "varmod-match-escape.mk" line 69: Dollar followed by nothing
+make: "varmod-match-escape.mk" line 110: warning: Unfinished character list in pattern '[A-]' of modifier ':M'
+make: "varmod-match-escape.mk" line 110: warning: Unfinished character list in pattern '[^A-]' of modifier ':M'
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-match-escape.mk b/contrib/bmake/unit-tests/varmod-match-escape.mk
index 5ac69f964a68..1da3918fe1a5 100755
--- a/contrib/bmake/unit-tests/varmod-match-escape.mk
+++ b/contrib/bmake/unit-tests/varmod-match-escape.mk
@@ -1,8 +1,8 @@
-# $NetBSD: varmod-match-escape.mk,v 1.7 2021/04/03 11:08:40 rillig Exp $
+# $NetBSD: varmod-match-escape.mk,v 1.12 2023/11/19 21:47:52 rillig Exp $
#
# As of 2020-08-01, the :M and :N modifiers interpret backslashes differently,
-# depending on whether there was a variable expression somewhere before the
-# first backslash or not. See ApplyModifier_Match, "copy = true".
+# depending on whether there was an expression somewhere before the
+# first backslash or not. See ParseModifier_Match, "copy = true".
#
# Apart from the different and possibly confusing debug output, there is no
# difference in behavior. When parsing the modifier text, only \{, \} and \:
@@ -18,27 +18,28 @@ SPECIALS= \: : \\ * \*
.endif
# And now both cases combined: A single modifier with both an escaped ':'
-# as well as a variable expression that expands to a ':'.
+# as well as an expression that expands to a ':'.
#
-# XXX: As of 2020-11-01, when an escaped ':' occurs before the variable
+# XXX: As of 2020-11-01, when an escaped ':' occurs before the
# expression, the whole modifier text is subject to unescaping '\:' to ':',
-# before the variable expression is expanded. This means that the '\:' in
-# the variable expression is expanded as well, turning ${:U\:} into a simple
+# before the expression is expanded. This means that the '\:' in
+# the expression is expanded as well, turning ${:U\:} into a simple
# ${:U:}, which silently expands to an empty string, instead of generating
# an error message.
#
# XXX: As of 2020-11-01, the modifier on the right-hand side of the
-# comparison is parsed differently though. First, the variable expression
+# comparison is parsed differently though. First, the expression
# is parsed, resulting in ':' and needSubst=true. After that, the escaped
# ':' is seen, and this time, copy=true is not executed but stays copy=false.
# Therefore the escaped ':' is kept as-is, and the final pattern becomes
# ':\:'.
#
-# If ApplyModifier_Match had used the same parsing algorithm as Var_Subst,
+# If ParseModifier_Match had used the same parsing algorithm as Var_Subst,
# both patterns would end up as '::'.
#
VALUES= : :: :\:
.if ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:}
+# expect+1: warning: XXX: Oops
. warning XXX: Oops
.endif
@@ -52,7 +53,7 @@ VALUES= : :: :\:
.endif
# XXX: As of 2020-11-01, unlike all other variable modifiers, '\$' is not
-# parsed as an escaped '$'. Instead, ApplyModifier_Match first scans for
+# parsed as an escaped '$'. Instead, ParseModifier_Match first scans for
# the ':' at the end of the modifier, which results in the pattern '\$'.
# No unescaping takes place since the pattern neither contained '\:' nor
# '\{' nor '\}'. But the text is expanded, and a lonely '$' at the end
@@ -64,6 +65,7 @@ VALUES= : :: :\:
# In lint mode, the case of a lonely '$' is covered with an error message.
.MAKEFLAGS: -dL
+# expect+1: Dollar followed by nothing
.if ${:U\$:M\$} != ""
. error
.endif
@@ -75,12 +77,41 @@ VALUES= : :: :\:
#
# TODO: Str_Match("a-z]", "[a-z]")
# TODO: Str_Match("012", "[0-]]")
-# TODO: Str_Match("0]", "[0-]]")
-# TODO: Str_Match("1]", "[0-]]")
# TODO: Str_Match("[", "[[]")
# TODO: Str_Match("]", "[]")
# TODO: Str_Match("]", "[[-]]")
+# Demonstrate an inconsistency between positive and negative character lists
+# when the range ends with the character ']'.
+#
+# 'A' begins the range, 'B' is in the middle of the range, ']' ends the range,
+# 'a' is outside the range.
+WORDS= A A] A]] B B] B]] ] ]] ]]] a a] a]]
+# The ']' is part of the character range and at the same time ends the
+# character list.
+EXP.[A-]= A B ]
+# The first ']' is part of the character range and at the same time ends the
+# character list.
+EXP.[A-]]= A] B] ]]
+# The first ']' is part of the character range and at the same time ends the
+# character list.
+EXP.[A-]]]= A]] B]] ]]]
+# For negative character lists, the ']' ends the character range but does not
+# end the character list.
+# XXX: This is unnecessarily inconsistent but irrelevant in practice as there
+# is no practical need for a character range that ends at ']'.
+EXP.[^A-]= a
+EXP.[^A-]]= a
+EXP.[^A-]]]= a]
+
+.for pattern in [A-] [A-]] [A-]]] [^A-] [^A-]] [^A-]]]
+# expect+2: warning: Unfinished character list in pattern '[A-]' of modifier ':M'
+# expect+1: warning: Unfinished character list in pattern '[^A-]' of modifier ':M'
+. if ${WORDS:M${pattern}} != ${EXP.${pattern}}
+. warning ${pattern}: ${WORDS:M${pattern}} != ${EXP.${pattern}}
+. endif
+.endfor
+
# In brackets, the backslash is just an ordinary character.
# Outside brackets, it is an escape character for a few special characters.
# TODO: Str_Match("\\", "[\\-]]")
diff --git a/contrib/bmake/unit-tests/varmod-match.exp b/contrib/bmake/unit-tests/varmod-match.exp
index 080e9e0f74de..e4e0783a7b15 100644
--- a/contrib/bmake/unit-tests/varmod-match.exp
+++ b/contrib/bmake/unit-tests/varmod-match.exp
@@ -1,12 +1,14 @@
-CondParser_Eval: ${NUMBERS:M[A-Z]*} != "One Two Three Four"
-lhs = "One Two Three Four", rhs = "One Two Three Four", op = !=
-CondParser_Eval: ${NUMBERS:M[^A-Z]*} != "five six seven"
-lhs = "five six seven", rhs = "five six seven", op = !=
-CondParser_Eval: ${NUMBERS:M[^s]*[ex]} != "One Three five"
-lhs = "One Three five", rhs = "One Three five", op = !=
-CondParser_Eval: ${:U****************:M****************b}
-CondParser_Eval: ${:Ua \$ sign:M*$$*} != "\$"
-lhs = "$", rhs = "$", op = !=
-CondParser_Eval: ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
-lhs = "any-asterisk", rhs = "any-asterisk", op = !=
-exit status 0
+make: "varmod-match.mk" line 289: warning: Unfinished character list in pattern 'a[' of modifier ':M'
+make: "varmod-match.mk" line 297: warning: Unfinished character list in pattern 'a[^' of modifier ':M'
+make: "varmod-match.mk" line 305: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 313: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 322: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 336: warning: Unfinished character list in pattern '?[\' of modifier ':M'
+make: "varmod-match.mk" line 344: warning: Unfinished character range in pattern '[x-' of modifier ':M'
+make: "varmod-match.mk" line 356: warning: Unfinished character range in pattern '[^x-' of modifier ':M'
+make: "varmod-match.mk" line 364: warning: Unfinished character list in pattern '[' of modifier ':M'
+make: "varmod-match.mk" line 364: Unknown modifier "]"
+make: "varmod-match.mk" line 364: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-match.mk b/contrib/bmake/unit-tests/varmod-match.mk
index 9b56fb451eda..d93d1839192d 100644
--- a/contrib/bmake/unit-tests/varmod-match.mk
+++ b/contrib/bmake/unit-tests/varmod-match.mk
@@ -1,42 +1,234 @@
-# $NetBSD: varmod-match.mk,v 1.6 2020/11/15 18:33:41 rillig Exp $
+# $NetBSD: varmod-match.mk,v 1.20 2023/12/17 23:19:02 rillig Exp $
#
-# Tests for the :M variable modifier, which filters words that match the
+# Tests for the ':M' modifier, which keeps only those words that match the
# given pattern.
#
-# See ApplyModifier_Match and ModifyWord_Match for the implementation.
+# Table of contents
+#
+# 1. Pattern characters '*', '?' and '\'
+# 2. Character lists and character ranges
+# 3. Parsing and escaping
+# 4. Interaction with other modifiers
+# 5. Performance
+# 6. Error handling
+# 7. Historical bugs
+#
+# See ApplyModifier_Match, ParseModifier_Match, ModifyWord_Match and
+# Str_Match.
+
+
+# 1. Pattern characters '*', '?' and '\'
+#
+# * matches 0 or more characters
+# ? matches 1 character
+# \x matches the character 'x'
+
+# The pattern is anchored both at the beginning and at the end of the word.
+# Since the pattern 'e' does not contain any pattern matching characters, it
+# matches exactly the word 'e', twice.
+.if ${a c e aa cc ee e f g:L:Me} != "e e"
+. error
+.endif
+
+# The pattern character '?' matches exactly 1 character, the pattern character
+# '*' matches 0 or more characters. The whole pattern matches all words that
+# start with 's' and have 3 or more characters.
+.if ${One Two Three Four five six seven:L:Ms??*} != "six seven"
+. error
+.endif
+
+# Ensure that a pattern without placeholders only matches itself.
+.if ${a aa aaa b ba baa bab:L:Ma} != "a"
+. error
+.endif
+
+# Ensure that a pattern that ends with '*' is properly anchored at the
+# beginning.
+.if ${a aa aaa b ba baa bab:L:Ma*} != "a aa aaa"
+. error
+.endif
-.MAKEFLAGS: -dc
+# Ensure that a pattern that starts with '*' is properly anchored at the end.
+.if ${a aa aaa b ba baa bab:L:M*a} != "a aa aaa ba baa"
+. error
+.endif
+
+# Test the fast code path for '*' followed by a regular character.
+.if ${:U file.c file.*c file.h file\.c :M*.c} != "file.c file\\.c"
+. error
+.endif
+# Ensure that the fast code path correctly handles the backslash.
+.if ${:U file.c file.*c file.h file\.c :M*\.c} != "file.c file\\.c"
+. error
+.endif
+# Ensure that the fast code path correctly handles '\*'.
+.if ${:U file.c file.*c file.h file\.c :M*\*c} != "file.*c"
+. error
+.endif
+# Ensure that the partial match '.c' doesn't confuse the fast code path.
+.if ${:U file.c.cc file.cc.cc file.cc.c :M*.cc} != "file.c.cc file.cc.cc"
+. error
+.endif
+# Ensure that the substring '.cc' doesn't confuse the fast code path for '.c'.
+.if ${:U file.c.cc file.cc.cc file.cc.c :M*.c} != "file.cc.c"
+. error
+.endif
-NUMBERS= One Two Three Four five six seven
+
+# 2. Character lists and character ranges
+#
+# [...] matches 1 character from the listed characters
+# [^...] matches 1 character from the unlisted characters
+# [a-z] matches 1 character from the range 'a' to 'z'
+# [z-a] matches 1 character from the range 'a' to 'z'
# Only keep words that start with an uppercase letter.
-.if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
+.if ${One Two Three Four five six seven:L:M[A-Z]*} != "One Two Three Four"
. error
.endif
# Only keep words that start with a character other than an uppercase letter.
-.if ${NUMBERS:M[^A-Z]*} != "five six seven"
+.if ${One Two Three Four five six seven:L:M[^A-Z]*} != "five six seven"
+. error
+.endif
+
+# [] matches never
+.if ${ ab a[]b a[b a b :L:M[]} != ""
+. error
+.endif
+
+# a[]b matches never
+.if ${ ab a[]b a[b a b [ ] :L:Ma[]b} != ""
+. error
+.endif
+
+# [^] matches exactly 1 arbitrary character
+.if ${ ab a[]b a[b a b [ ] :L:M[^]} != "a b [ ]"
+. error
+.endif
+
+# a[^]b matches 'a', then exactly 1 arbitrary character, then 'b'
+.if ${ ab a[]b a[b a b :L:Ma[^]b} != "a[b"
+. error
+.endif
+
+# [Nn0] matches exactly 1 character from the set 'N', 'n', '0'
+.if ${ a b N n 0 Nn0 [ ] :L:M[Nn0]} != "N n 0"
+. error
+.endif
+
+# [a-c] matches exactly 1 character from the range 'a' to 'c'
+.if ${ A B C a b c d [a-c] [a] :L:M[a-c]} != "a b c"
+. error
+.endif
+
+# [c-a] matches the same as [a-c]
+.if ${ A B C a b c d [a-c] [a] :L:M[c-a]} != "a b c"
+. error
+.endif
+
+# [^a-c67]
+# matches a single character, except for 'a', 'b', 'c', '6' or
+# '7'
+.if ${ A B C a b c d 5 6 7 8 [a-c] [a] :L:M[^a-c67]} != "A B C d 5 8"
+. error
+.endif
+
+# [\] matches a single backslash; no escaping takes place in
+# character ranges
+# Without the 'b' in the below words, the backslash would end a word and thus
+# influence how the string is split into words.
+WORDS= a\b a[\]b ab a\\b
+.if ${WORDS:Ma[\]b} != "a\\b"
+. error
+.endif
+
+# [[-]] May look like it would match a single '[', '\' or ']', but
+# the inner ']' has two roles: it is the upper bound of the
+# character range as well as the closing character of the
+# character list. The outer ']' is just a regular character.
+WORDS= [ ] [] \] ]]
+.if ${WORDS:M[[-]]} != "[] \\] ]]"
+. error
+.endif
+
+# [b[-]a]
+# Same as for '[[-]]': the character list stops at the first
+# ']', and the 'a]' is treated as a literal string.
+WORDS= [a \a ]a []a \]a ]]a [a] \a] ]a] ba]
+.if ${WORDS:M[b[-]a]} != "[a] \\a] ]a] ba]"
+. error
+.endif
+
+# [-] Matches a single '-' since the '-' only becomes part of a
+# character range if it is preceded and followed by another
+# character.
+WORDS= - -]
+.if ${WORDS:M[-]} != "-"
. error
.endif
# Only keep words that don't start with s and at the same time end with
# either of [ex].
#
-# This test case ensures that the negation from the first character class
-# does not propagate to the second character class.
-.if ${NUMBERS:M[^s]*[ex]} != "One Three five"
+# This test case ensures that the negation from the first character list
+# '[^s]' does not propagate to the second character list '[ex]'.
+.if ${One Two Three Four five six seven:L:M[^s]*[ex]} != "One Three five"
. error
.endif
-# Before 2020-06-13, this expression took quite a long time in Str_Match,
-# calling itself 601080390 times for 16 asterisks.
-.if ${:U****************:M****************b}
+
+# 3. Parsing and escaping
+#
+# * matches 0 or more characters
+# ? matches 1 character
+# \ outside a character list, escapes the following character
+# [ starts a character list for matching 1 character
+# ] ends a character list for matching 1 character
+# - in a character list, forms a character range
+# ^ at the beginning of a character list, negates the list
+# ( while parsing the pattern, starts a nesting level
+# ) while parsing the pattern, ends a nesting level
+# { while parsing the pattern, starts a nesting level
+# } while parsing the pattern, ends a nesting level
+# : while parsing the pattern, terminates the pattern
+# $ while parsing the pattern, starts a nested expression
+# # in a line except a shell command, starts a comment
+
+# The pattern can come from an expression. For single-letter
+# variables, either the short form or the long form can be used, just as
+# everywhere else.
+PRIMES= 2 3 5 7 11
+n= 2
+.if ${PRIMES:M$n} != "2"
+. error
+.endif
+.if ${PRIMES:M${n}} != "2"
+. error
+.endif
+.if ${PRIMES:M${:U2}} != "2"
+. error
+.endif
+
+# : terminates the pattern
+.if ${ A * :L:M:} != ""
+. error
+.endif
+
+# \: matches a colon
+.if ${ ${:U\: \:\:} :L:M\:} != ":"
+. error
+.endif
+
+# ${:U\:} matches a colon
+.if ${ ${:U\:} ${:U\:\:} :L:M${:U\:}} != ":"
+. error
.endif
# To match a dollar sign in a word, double it.
#
-# This is different from the :S and :C variable modifiers, where a '$'
-# has to be escaped as '\$'.
+# This is different from the :S and :C modifiers, where a '$' has to be
+# escaped as '\$'.
.if ${:Ua \$ sign:M*$$*} != "\$"
. error
.endif
@@ -45,7 +237,7 @@ NUMBERS= One Two Three Four five six seven
# interpreted as a backslash followed by whatever expression the
# '$' starts.
#
-# This differs from the :S, :C and several other variable modifiers.
+# This differs from the :S, :C and several other modifiers.
${:U*}= asterisk
.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
. error
@@ -56,5 +248,133 @@ ${:U*}= asterisk
# TODO: ${VAR:M${UNBALANCED}}
# TODO: ${VAR:M${:U(((\}\}\}}}
-all:
- @:;
+
+# 4. Interaction with other modifiers
+
+# The modifier ':tW' prevents splitting at whitespace. Even leading and
+# trailing whitespace is preserved.
+.if ${ plain string :L:tW:M*} != " plain string "
+. error
+.endif
+
+# Without the modifier ':tW', the string is split into words. All whitespace
+# around and between the words is normalized to a single space.
+.if ${ plain string :L:M*} != "plain string"
+. error
+.endif
+
+
+# 5. Performance
+
+# Before 2020-06-13, this expression called Str_Match 601,080,390 times.
+# Since 2020-06-13, this expression calls Str_Match 1 time.
+.if ${:U****************:M****************b}
+.endif
+
+# Before 2023-06-22, this expression called Str_Match 2,621,112 times.
+# Adding another '*?' to the pattern called Str_Match 20,630,572 times.
+# Adding another '*?' to the pattern called Str_Match 136,405,672 times.
+# Adding another '*?' to the pattern called Str_Match 773,168,722 times.
+# Adding another '*?' to the pattern called Str_Match 3,815,481,072 times.
+# Since 2023-06-22, Str_Match no longer backtracks.
+.if ${:U..................................................b:M*?*?*?*?*?a}
+.endif
+
+
+# 6. Error handling
+
+# [ Incomplete empty character list, never matches.
+WORDS= a a[
+# expect+1: warning: Unfinished character list in pattern 'a[' of modifier ':M'
+.if ${WORDS:Ma[} != ""
+. error
+.endif
+
+# [^ Incomplete negated empty character list, matches any single
+# character.
+WORDS= a a[ aX
+# expect+1: warning: Unfinished character list in pattern 'a[^' of modifier ':M'
+.if ${WORDS:Ma[^} != "a[ aX"
+. error
+.endif
+
+# [-x1-3 Incomplete character list, matches those elements that can be
+# parsed without lookahead.
+WORDS= - + x xx 0 1 2 3 4 [x1-3
+# expect+1: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
+.if ${WORDS:M[-x1-3} != "- x 1 2 3"
+. error
+.endif
+
+# *[-x1-3 Incomplete character list after a wildcard, matches those
+# words that end with one of the characters from the list.
+WORDS= - + x xx 0 1 2 3 4 00 01 10 11 000 001 010 011 100 101 110 111 [x1-3
+# expect+1: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
+.if ${WORDS:M*[-x1-3} != "- x xx 1 2 3 01 11 001 011 101 111 [x1-3"
+. warning ${WORDS:M*[-x1-3}
+.endif
+
+# [^-x1-3
+# Incomplete negated character list, matches any character
+# except those elements that can be parsed without lookahead.
+WORDS= - + x xx 0 1 2 3 4 [x1-3
+# expect+1: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
+.if ${WORDS:M[^-x1-3} != "+ 0 4"
+. error
+.endif
+
+# [\ Incomplete character list containing a single '\'.
+#
+# A word can only end with a backslash if the preceding
+# character is a backslash as well; in all other cases the final
+# backslash would escape the following space, making the space
+# part of the word. Only the very last word of a string can be
+# '\', as there is no following space that could be escaped.
+WORDS= \\ \a ${:Ux\\}
+PATTERN= ${:U?[\\}
+# expect+1: warning: Unfinished character list in pattern '?[\' of modifier ':M'
+.if ${WORDS:M${PATTERN}} != "\\\\ x\\"
+. error
+.endif
+
+# [x- Incomplete character list containing an incomplete character
+# range, matches only the 'x'.
+WORDS= [x- x x- y
+# expect+1: warning: Unfinished character range in pattern '[x-' of modifier ':M'
+.if ${WORDS:M[x-} != "x"
+. error
+.endif
+
+# [^x- Incomplete negated character list containing an incomplete
+# character range; matches each word that does not have an 'x'
+# at the position of the character list.
+#
+# XXX: Even matches strings that are longer than a single
+# character.
+WORDS= [x- x x- y yyyyy
+# expect+1: warning: Unfinished character range in pattern '[^x-' of modifier ':M'
+.if ${WORDS:M[^x-} != "[x- y yyyyy"
+. error
+.endif
+
+# [:] matches never since the ':' starts the next modifier
+# expect+3: warning: Unfinished character list in pattern '[' of modifier ':M'
+# expect+2: Unknown modifier "]"
+# expect+1: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
+.if ${ ${:U\:} ${:U\:\:} :L:M[:]} != ":"
+. error
+.else
+. error
+.endif
+
+
+# 7. Historical bugs
+
+# Before var.c 1.1031 from 2022-08-24, the following expressions caused an
+# out-of-bounds read beyond the indirect ':M' modifiers.
+.if ${:U:${:UM\\}} # The ':M' pattern need not be unescaped, the
+. error # resulting pattern is '\', it never matches
+.endif # anything.
+.if ${:U:${:UM\\\:\\}} # The ':M' pattern must be unescaped, the
+. error # resulting pattern is ':\', it never matches
+.endif # anything.
diff --git a/contrib/bmake/unit-tests/varmod-mtime.exp b/contrib/bmake/unit-tests/varmod-mtime.exp
new file mode 100644
index 000000000000..039173feddc3
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-mtime.exp
@@ -0,0 +1,14 @@
+make: "varmod-mtime.mk" line 47: Invalid argument '123x' for modifier ':mtime'
+make: "varmod-mtime.mk" line 47: Malformed conditional (${no/such/file:L:mtime=123x})
+make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file1': <ENOENT>
+make: "varmod-mtime.mk" line 70: Cannot determine mtime for 'no/such/file2': <ENOENT>
+make: "varmod-mtime.mk" line 70: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
+make: "varmod-mtime.mk" line 81: Invalid argument 'errorhandler-no' for modifier ':mtime'
+make: "varmod-mtime.mk" line 81: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
+make: "varmod-mtime.mk" line 90: Invalid argument 'warn' for modifier ':mtime'
+make: "varmod-mtime.mk" line 90: Malformed conditional (${MAKEFILE:mtime=warn} > 0)
+make: "varmod-mtime.mk" line 115: Unknown modifier "mtim"
+make: "varmod-mtime.mk" line 115: Malformed conditional (${anything:L:mtim})
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-mtime.mk b/contrib/bmake/unit-tests/varmod-mtime.mk
new file mode 100644
index 000000000000..298756e152c1
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-mtime.mk
@@ -0,0 +1,125 @@
+# $NetBSD: varmod-mtime.mk,v 1.9 2023/12/17 14:07:22 rillig Exp $
+#
+# Tests for the ':mtime' variable modifier, which maps each word of the
+# expression to that file's modification time.
+
+# Note: strftime() uses mktime() for %s and mktime() assumes localtime
+# so this should match time()
+start:= ${%s:L:localtime} # see varmod-gmtime.mk, keyword '%s'
+
+
+# Ensure that this makefile exists and has a modification time. If the file
+# didn't exist, the ':mtime' modifier would return the current time.
+.if ${MAKEFILE:mtime} >= ${start}
+. error
+.endif
+
+
+# For a file that doesn't exist, the ':mtime' modifier returns the current
+# time, without an error or warning message. The returned timestamp differs
+# from the 'now' that is used when updating the timestamps in archives or for
+# touching files using the '-t' option, which is taken once when make is
+# started.
+not_found_mtime:= ${no/such/file:L:mtime}
+.if ${not_found_mtime} < ${start}
+. error
+.endif
+
+
+# The ':mtime' modifier accepts a timestamp in seconds as an optional
+# argument. This timestamp is used as a fallback in case the file's time
+# cannot be determined, without any error or warning message.
+.if ${no/such/file:L:mtime=0} != "0"
+. error
+.endif
+
+
+# The fallback timestamp must start with a digit, and it is interpreted as a
+# decimal integer.
+.if ${no/such/file:L:mtime=00042} != "42"
+. error
+.endif
+
+
+# The fallback timestamp must only be an integer, without trailing characters.
+# expect+2: Invalid argument '123x' for modifier ':mtime'
+# expect+1: Malformed conditional (${no/such/file:L:mtime=123x})
+.if ${no/such/file:L:mtime=123x}
+. error
+.else
+. error
+.endif
+
+
+# The timestamp of a newly created file must be at least as great as the
+# timestamp when parsing of this makefile started.
+COOKIE= ${TMPDIR:U/tmp}/varmod-mtime.cookie
+_!= touch ${COOKIE}
+.if ${COOKIE:mtime=0} < ${start}
+. error ${COOKIE:mtime=0} < ${start}
+.endif
+_!= rm -f ${COOKIE}
+
+
+# If the optional argument of the ':mtime' modifier is the word 'error', the
+# modifier fails with an error message, once for each affected file.
+#
+# expect+3: Cannot determine mtime for 'no/such/file1': <ENOENT>
+# expect+2: Cannot determine mtime for 'no/such/file2': <ENOENT>
+# expect+1: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
+.if ${no/such/file1 no/such/file2:L:mtime=error}
+. error
+.else
+. error
+.endif
+
+
+# Only the word 'error' is a special argument to the ':mtime' modifier, all
+# other words result in a parse error.
+# expect+2: Invalid argument 'errorhandler-no' for modifier ':mtime'
+# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
+.if ${MAKEFILE:mtime=errorhandler-no} > 0
+.else
+. error
+.endif
+
+
+# Only the word 'error' can be used as a fallback argument to the modifier.
+# expect+2: Invalid argument 'warn' for modifier ':mtime'
+# expect+1: Malformed conditional (${MAKEFILE:mtime=warn} > 0)
+.if ${MAKEFILE:mtime=warn} > 0
+. error
+.else
+. error
+.endif
+
+
+# Ensure that the fallback for a missing modification time is indeed the
+# current time, and not any later time.
+end:= ${%s:L:gmtime}
+.if ${not_found_mtime} > ${end}
+. error
+.endif
+
+
+# If the expression is irrelevant, the ':mtime' modifier is only parsed, it
+# does not perform any filesystem operations.
+.if 0 && ${no/such/file:L:mtime=error}
+. error
+.endif
+
+
+# If there is a typo in the modifier name, it does not match.
+# expect+2: Unknown modifier "mtim"
+# expect+1: Malformed conditional (${anything:L:mtim})
+.if ${anything:L:mtim}
+. error
+.else
+. error
+.endif
+
+
+# An empty word list results in an empty mtime list.
+.if ${:U:mtime} != ""
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/varmod-no-match.mk b/contrib/bmake/unit-tests/varmod-no-match.mk
index 2acb27e2e727..c03b4bf94e70 100644
--- a/contrib/bmake/unit-tests/varmod-no-match.mk
+++ b/contrib/bmake/unit-tests/varmod-no-match.mk
@@ -1,9 +1,97 @@
-# $NetBSD: varmod-no-match.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-no-match.mk,v 1.3 2023/02/26 06:08:06 rillig Exp $
#
-# Tests for the :N variable modifier, which filters words that do not match
-# the given pattern.
+# Tests for the expression modifier ':N', which filters words that do not
+# match the given pattern.
+
+
+# Keep all words except for 'two'.
+.if ${:U one two three :Ntwo} != "one three"
+. error
+.endif
+
+# Keep all words except those starting with 't'.
+# See varmod-match.mk for the details of pattern matching.
+.if ${:U one two three four six :Nt*} != "one four six"
+. error
+.endif
+
+
+# Idiom: normalize whitespace
+#
+# The modifier ':N' can be used with an empty pattern. As that pattern never
+# matches a word, the only effect is that the string is split into words and
+# then joined again, thereby normalizing whitespace around and between the
+# words. And even though the 'N' in ':N' might serve as a mnemonic for
+# "normalize whitespace", this idiom is not used in practice, resorting to the
+# much more common ':M*' to "select all words" instead.
+.if ${:U :N} != ""
+. error
+.endif
+.if ${:U one two three :N} != "one two three"
+. error
+.endif
+.if ${:U one two three :M*} != "one two three"
+. error
+.endif
+
+
+# Idiom: single-word expression equals any of several words or patterns
+#
+# If an expression is guaranteed to consist of a single word, the modifier
+# ':N' can be chained to compare the expression to several words or even
+# patterns in a sequence. If one of the patterns matches, the final
+# expression will be the empty string.
+#
+.if ${:U word :None:Ntwo:Nthree} != ""
+# good
+.else
+. error
+.endif
+.if ${:U two :None:Ntwo:Nthree} != ""
+. error
+.else
+# good
+.endif
+#
+# The modifier ':N' is seldom used in general since positive matches with ':M'
+# are easier to grasp. Chaining the ':N' modifier is even more difficult to
+# grasp due to the many negations involved.
+#
+# The final '!= ""' adds to the confusion because at first glance, the
+# condition may look like '${VAR} != ""', which for a single-word variable is
+# always true.
+#
+# The '!= ""' can be omitted if the expression cannot have the numeric value
+# 0, which is common in practice. In that form, each ':N' can be pronounced
+# as 'neither' or 'nor', which makes the expression sound more natural.
+#
+.if ${:U word :None:Ntwo:Nthree}
+# good
+.else
+. error
+.endif
+.if ${:U two :None:Ntwo:Nthree}
+. error
+.else
+# good
+.endif
+#
+# Replacing the '${...} != ""' with '!empty(...)' doesn't improve the
+# situation as the '!' adds another level of negations, and the word 'empty'
+# is a negation on its own, thereby creating a triple negation. Furthermore,
+# due to the '!empty', the expression to be evaluated no longer starts with
+# '$' and is thus more difficult to spot quickly.
+#
+.if !empty(:U word :None:Ntwo:Nthree)
+# good
+.else
+. error
+.endif
+.if !empty(:U two :None:Ntwo:Nthree)
+. error
+.else
+# good
+.endif
-# TODO: Implementation
all:
- @:;
diff --git a/contrib/bmake/unit-tests/var-class.exp b/contrib/bmake/unit-tests/varmod-order-numeric.exp
index 39a9383953dd..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/var-class.exp
+++ b/contrib/bmake/unit-tests/varmod-order-numeric.exp
diff --git a/contrib/bmake/unit-tests/varmod-order-numeric.mk b/contrib/bmake/unit-tests/varmod-order-numeric.mk
new file mode 100644
index 000000000000..62212bd265ad
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-order-numeric.mk
@@ -0,0 +1,59 @@
+# $NetBSD: varmod-order-numeric.mk,v 1.8 2022/09/27 19:18:45 rillig Exp $
+#
+# Tests for the variable modifiers ':On', which returns the words, sorted in
+# ascending numeric order, and for ':Orn' and ':Onr', which additionally
+# reverse the order.
+#
+# The variable modifiers ':On', ':Onr' and ':Orn' were added in var.c 1.939
+# from 2021-07-30.
+
+# This list contains only 32-bit numbers since the make code needs to conform
+# to C90, which does not necessarily provide integer types larger than 32 bit.
+# Make uses 'long long' for C99 or later, and 'long' for older C versions.
+#
+# To get 53-bit integers even in C90, it would be possible to switch to
+# 'double' instead, but that would allow floating-point numbers as well, which
+# is out of scope for this variable modifier.
+NUMBERS= 3 5 7 1 42 -42 5K -3m 1M 1k -2G
+
+.if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M"
+. error ${NUMBERS:On}
+.endif
+
+.if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
+. error ${NUMBERS:Orn}
+.endif
+
+# Both ':Onr' and ':Orn' have the same effect.
+.if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
+. error ${NUMBERS:Onr}
+.endif
+
+# Duplicate numbers are preserved in the output. In this case the
+# equal-valued numbers are spelled the same, so they are indistinguishable in
+# the output.
+DUPLICATES= 3 1 2 2 1 1 # subsequence of https://oeis.org/A034002
+.if ${DUPLICATES:On} != "1 1 1 2 2 3"
+. error ${DUPLICATES:On}
+.endif
+
+# If there are several numbers that have the same integer value, they are
+# returned in unspecified order.
+SAME_VALUE:= ${:U 79 80 0x0050 81 :On}
+.if ${SAME_VALUE} != "79 80 0x0050 81" && ${SAME_VALUE} != "79 0x0050 80 81"
+. error ${SAME_VALUE}
+.endif
+
+# Hexadecimal and octal numbers can be sorted as well.
+MIXED_BASE= 0 010 0x7 9
+.if ${MIXED_BASE:On} != "0 0x7 010 9"
+. error ${MIXED_BASE:On}
+.endif
+
+# The measurement units for suffixes are k, M, G, but not T.
+# The string '3T' evaluates to 3, the string 'x' evaluates as '0'.
+.if ${4 3T 2M x:L:On} != "x 3T 4 2M"
+. error
+.endif
+
+all:
diff --git a/contrib/bmake/unit-tests/varmod-order-reverse.mk b/contrib/bmake/unit-tests/varmod-order-reverse.mk
index 1a6d2d766f76..c3be8d0f7817 100644
--- a/contrib/bmake/unit-tests/varmod-order-reverse.mk
+++ b/contrib/bmake/unit-tests/varmod-order-reverse.mk
@@ -1,13 +1,12 @@
-# $NetBSD: varmod-order-reverse.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varmod-order-reverse.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
#
# Tests for the :Or variable modifier, which returns the words, sorted in
# descending order.
-NUMBERS= one two three four five six seven eight nine ten
+WORDS= one two three four five six seven eight nine ten
-.if ${NUMBERS:Or} != "two three ten six seven one nine four five eight"
-. error ${NUMBERS:Or}
+.if ${WORDS:Or} != "two three ten six seven one nine four five eight"
+. error ${WORDS:Or}
.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/varmod-order-shuffle.mk b/contrib/bmake/unit-tests/varmod-order-shuffle.mk
index 185141b6c4a5..e9898600355a 100644
--- a/contrib/bmake/unit-tests/varmod-order-shuffle.mk
+++ b/contrib/bmake/unit-tests/varmod-order-shuffle.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-order-shuffle.mk,v 1.6 2020/11/09 20:16:33 rillig Exp $
+# $NetBSD: varmod-order-shuffle.mk,v 1.8 2023/02/26 06:08:06 rillig Exp $
#
# Tests for the :Ox variable modifier, which returns the words of the
# variable, shuffled.
@@ -6,12 +6,13 @@
# The variable modifier :Ox is available since 2005-06-01.
#
# As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
-# This makes the random numbers completely predictable since there is no other
-# part of make that uses random numbers.
+# This makes the random numbers completely predictable since the only other
+# part of make that uses random numbers is the 'randomize-targets' mode, which
+# is off by default.
#
# Tags: probabilistic
-NUMBERS= one two three four five six seven eight nine ten
+WORDS= one two three four five six seven eight nine ten
# Note that 1 in every 10! trials two independently generated
# randomized orderings will be the same. The test framework doesn't
@@ -20,24 +21,23 @@ NUMBERS= one two three four five six seven eight nine ten
# lets the whole test fail once in 1.209.600 runs, on average.
# Create two shuffles using the := assignment operator.
-shuffled1:= ${NUMBERS:Ox}
-shuffled2:= ${NUMBERS:Ox}
+shuffled1:= ${WORDS:Ox}
+shuffled2:= ${WORDS:Ox}
.if ${shuffled1} == ${shuffled2}
. error ${shuffled1} == ${shuffled2}
.endif
# Sorting the list before shuffling it has no effect.
-shuffled1:= ${NUMBERS:O:Ox}
-shuffled2:= ${NUMBERS:O:Ox}
+shuffled1:= ${WORDS:O:Ox}
+shuffled2:= ${WORDS:O:Ox}
.if ${shuffled1} == ${shuffled2}
. error ${shuffled1} == ${shuffled2}
.endif
# Sorting after shuffling must produce the original numbers.
-sorted:= ${NUMBERS:Ox:O}
-.if ${sorted} != ${NUMBERS:O}
-. error ${sorted} != ${NUMBERS:O}
+sorted:= ${WORDS:Ox:O}
+.if ${sorted} != ${WORDS:O}
+. error ${sorted} != ${WORDS:O}
.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/varmod-order-string.exp b/contrib/bmake/unit-tests/varmod-order-string.exp
new file mode 100644
index 000000000000..39a9383953dd
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-order-string.exp
@@ -0,0 +1 @@
+exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-order-string.mk b/contrib/bmake/unit-tests/varmod-order-string.mk
new file mode 100644
index 000000000000..bb0a145ba825
--- /dev/null
+++ b/contrib/bmake/unit-tests/varmod-order-string.mk
@@ -0,0 +1,28 @@
+# $NetBSD: varmod-order-string.mk,v 1.2 2021/08/03 04:46:49 rillig Exp $
+#
+# Tests for the :O variable modifier, which returns the words, sorted in
+# ascending order.
+
+# Simple words are sorted lexicographically.
+WORDS= one two three four five six seven eight nine ten
+.if ${WORDS:O} != "eight five four nine one seven six ten three two"
+. error ${WORDS:O}
+.endif
+
+# Double quotes and single quotes delimit words, while backticks are just
+# regular characters. Therefore '`in' is a separate word from 'backticks`',
+# and the additional spaces between them are removed.
+QUOTED_WORDS= none "double quoted" 'single quoted' `in backticks`
+.if ${QUOTED_WORDS:O} != "\"double quoted\" 'single quoted' `in backticks` none"
+. error ${QUOTED_WORDS:O}
+.endif
+
+# Numbers are sorted lexicographically as well.
+# To sort the words numerically, use ':On' instead; since var.c 1.939 from
+# 2021-07-30.
+NUMBERS= -100g -50m -7k -50 -13 0 000 13 50 5k1 7k 50m 100G
+.if ${NUMBERS:O} != "-100g -13 -50 -50m -7k 0 000 100G 13 50 50m 5k1 7k"
+. error ${NUMBERS:O}
+.endif
+
+all:
diff --git a/contrib/bmake/unit-tests/varmod-order.exp b/contrib/bmake/unit-tests/varmod-order.exp
index 94c3cb694886..12d0bff75157 100644
--- a/contrib/bmake/unit-tests/varmod-order.exp
+++ b/contrib/bmake/unit-tests/varmod-order.exp
@@ -1,7 +1,26 @@
-make: Bad modifier ":OX" for variable "NUMBERS"
-make: "varmod-order.mk" line 13: Undefined variable "${NUMBERS:OX"
-make: Bad modifier ":OxXX" for variable "NUMBERS"
-make: "varmod-order.mk" line 16: Undefined variable "${NUMBERS:Ox"
+make: Bad modifier ":OX" for variable "WORDS"
+make: "varmod-order.mk" line 16: Undefined variable "${WORDS:OX"
+make: Bad modifier ":OxXX" for variable "WORDS"
+make: "varmod-order.mk" line 21: Undefined variable "${WORDS:Ox"
+make: Unclosed expression, expecting '}' for modifier "O" of variable "WORDS" with value "eight five four nine one seven six ten three two"
+make: Unclosed expression, expecting '}' for modifier "On" of variable "NUMBERS" with value "1 2 3 4 5 6 7 8 9 10"
+make: Unclosed expression, expecting '}' for modifier "Onr" of variable "NUMBERS" with value "10 9 8 7 6 5 4 3 2 1"
+make: Bad modifier ":Oxn" for variable "NUMBERS"
+make: "varmod-order.mk" line 33: Malformed conditional (${NUMBERS:Oxn})
+make: Bad modifier ":On_typo" for variable "NUMBERS"
+make: "varmod-order.mk" line 44: Malformed conditional (${NUMBERS:On_typo})
+make: Bad modifier ":Onr_typo" for variable "NUMBERS"
+make: "varmod-order.mk" line 54: Malformed conditional (${NUMBERS:Onr_typo})
+make: Bad modifier ":Orn_typo" for variable "NUMBERS"
+make: "varmod-order.mk" line 64: Malformed conditional (${NUMBERS:Orn_typo})
+make: Bad modifier ":Onn" for variable "NUMBERS"
+make: "varmod-order.mk" line 76: Malformed conditional (${NUMBERS:Onn})
+make: Bad modifier ":Onrr" for variable "NUMBERS"
+make: "varmod-order.mk" line 86: Malformed conditional (${NUMBERS:Onrr})
+make: Bad modifier ":Orrn" for variable "NUMBERS"
+make: "varmod-order.mk" line 96: Malformed conditional (${NUMBERS:Orrn})
+make: Bad modifier ":On=Off" for variable "SWITCH"
+make: "varmod-order.mk" line 111: Malformed conditional (${SWITCH:On=Off} != "Off")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-order.mk b/contrib/bmake/unit-tests/varmod-order.mk
index 675b6efec5e7..67919543a93e 100644
--- a/contrib/bmake/unit-tests/varmod-order.mk
+++ b/contrib/bmake/unit-tests/varmod-order.mk
@@ -1,19 +1,117 @@
-# $NetBSD: varmod-order.mk,v 1.5 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varmod-order.mk,v 1.11 2023/06/01 20:56:35 rillig Exp $
#
-# Tests for the :O variable modifier, which returns the words, sorted in
-# ascending order.
+# Tests for the :O variable modifier and its variants, which either sort the
+# words of the value or shuffle them.
-NUMBERS= one two three four five six seven eight nine ten
+WORDS= one two three four five six seven eight nine ten
+NUMBERS= 8 5 4 9 1 7 6 10 3 2 # in English alphabetical order
-.if ${NUMBERS:O} != "eight five four nine one seven six ten three two"
-. error ${NUMBERS:O}
+.if ${WORDS:O} != "eight five four nine one seven six ten three two"
+. error ${WORDS:O}
.endif
# Unknown modifier "OX"
-_:= ${NUMBERS:OX}
+# FIXME: The error message is wrong.
+# expect+1: Undefined variable "${WORDS:OX"
+_:= ${WORDS:OX}
# Unknown modifier "OxXX"
-_:= ${NUMBERS:OxXX}
+# FIXME: The error message is wrong.
+# expect+1: Undefined variable "${WORDS:Ox"
+_:= ${WORDS:OxXX}
+
+# Missing closing brace, to cover the error handling code.
+_:= ${WORDS:O
+_:= ${NUMBERS:On
+_:= ${NUMBERS:Onr
+
+# Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
+# combined.
+#
+# expect: make: Bad modifier ":Oxn" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Oxn})
+.if ${NUMBERS:Oxn}
+. error
+.else
+. error
+.endif
+
+# Extra characters after ':On' are detected and diagnosed.
+# TODO: Add line number information to the "Bad modifier" diagnostic.
+#
+# expect: make: Bad modifier ":On_typo" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:On_typo})
+.if ${NUMBERS:On_typo}
+. error
+.else
+. error
+.endif
+
+# Extra characters after ':Onr' are detected and diagnosed.
+#
+# expect: make: Bad modifier ":Onr_typo" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Onr_typo})
+.if ${NUMBERS:Onr_typo}
+. error
+.else
+. error
+.endif
+
+# Extra characters after ':Orn' are detected and diagnosed.
+#
+# expect: make: Bad modifier ":Orn_typo" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Orn_typo})
+.if ${NUMBERS:Orn_typo}
+. error
+.else
+. error
+.endif
+
+# Repeating the 'n' is not supported. In the typical use cases, the sorting
+# criteria are fixed, not computed, therefore allowing this redundancy does
+# not make sense.
+#
+# expect: make: Bad modifier ":Onn" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Onn})
+.if ${NUMBERS:Onn}
+. error
+.else
+. error
+.endif
+
+# Repeating the 'r' is not supported as well, for the same reasons as above.
+#
+# expect: make: Bad modifier ":Onrr" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Onrr})
+.if ${NUMBERS:Onrr}
+. error
+.else
+. error
+.endif
+
+# Repeating the 'r' is not supported as well, for the same reasons as above.
+#
+# expect: make: Bad modifier ":Orrn" for variable "NUMBERS"
+# expect+1: Malformed conditional (${NUMBERS:Orrn})
+.if ${NUMBERS:Orrn}
+. error
+.else
+. error
+.endif
+
+
+# If a modifier that starts with ':O' is not one of the known sort or shuffle
+# forms, it is a parse error. Several other modifiers such as ':H' or ':u'
+# fall back to the SysV modifier, for example, ':H=new' is not the standard
+# ':H' modifier but instead replaces a trailing 'H' with 'new' in each word.
+# There is no such fallback for the ':O' modifiers.
+SWITCH= On
+# expect: make: Bad modifier ":On=Off" for variable "SWITCH"
+# expect+1: Malformed conditional (${SWITCH:On=Off} != "Off")
+.if ${SWITCH:On=Off} != "Off"
+. error
+.else
+. error
+.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/varmod-path.mk b/contrib/bmake/unit-tests/varmod-path.mk
index ebbf755ddbec..25d4e3899b99 100644
--- a/contrib/bmake/unit-tests/varmod-path.mk
+++ b/contrib/bmake/unit-tests/varmod-path.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-path.mk,v 1.3 2020/08/23 08:10:49 rillig Exp $
+# $NetBSD: varmod-path.mk,v 1.4 2023/05/10 15:53:32 rillig Exp $
#
# Tests for the :P variable modifier, which looks up the path for a given
# target.
@@ -7,11 +7,12 @@
# as of 2020-08-23 it is nevertheless resolved to a path. This is probably
# unintended.
#
-# The real target is located in a subdirectory, and its full path is returned.
-# If it had been in the current directory, the difference between its path and
-# its name would not be visible.
+# In this test, the real target is located in a subdirectory, and its full
+# path is returned. If it had been in the current directory, the difference
+# between its path and its name would not be visible.
#
-# The enoent target does not exist, therefore the target name is returned.
+# The enoent target does not exist, therefore the plain name of the target
+# is returned.
.MAIN: all
@@ -20,7 +21,8 @@ _!= mkdir varmod-path.subdir
_!= > varmod-path.subdir/varmod-path.phony
_!= > varmod-path.subdir/varmod-path.real
-# To have an effect, this .PATH declaration must be after the directory is created.
+# To have an effect, this .PATH declaration must be processed after the
+# directory has been created.
.PATH: varmod-path.subdir
varmod-path.phony: .PHONY
diff --git a/contrib/bmake/unit-tests/varmod-quote-dollar.exp b/contrib/bmake/unit-tests/varmod-quote-dollar.exp
index 39a9383953dd..f12b0280e6f7 100644
--- a/contrib/bmake/unit-tests/varmod-quote-dollar.exp
+++ b/contrib/bmake/unit-tests/varmod-quote-dollar.exp
@@ -1 +1,4 @@
+!"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~
+!"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~
+ !"#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-quote-dollar.mk b/contrib/bmake/unit-tests/varmod-quote-dollar.mk
index fedbe8a10f4b..8e68282c536d 100644
--- a/contrib/bmake/unit-tests/varmod-quote-dollar.mk
+++ b/contrib/bmake/unit-tests/varmod-quote-dollar.mk
@@ -1,10 +1,17 @@
-# $NetBSD: varmod-quote-dollar.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-quote-dollar.mk,v 1.4 2022/05/08 10:14:40 rillig Exp $
#
# Tests for the :q variable modifier, which quotes the string for the shell
# and doubles dollar signs, to prevent them from being interpreted by a
# child process of make.
-# TODO: Implementation
+# The newline and space characters at the beginning of this string are passed
+# to the child make. When the child make parses the variable assignment, it
+# discards the leading space characters.
+ASCII_CHARS= ${.newline} !"\#$$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~
all:
- @:;
+ @${MAKE} -r -f /dev/null \
+ CHARS=${ASCII_CHARS:q} \
+ TWICE=${ASCII_CHARS:q}${ASCII_CHARS:q} \
+ -V CHARS \
+ -V TWICE
diff --git a/contrib/bmake/unit-tests/varmod-range.exp b/contrib/bmake/unit-tests/varmod-range.exp
index f4ada11ebde6..9b0dad40a78e 100644
--- a/contrib/bmake/unit-tests/varmod-range.exp
+++ b/contrib/bmake/unit-tests/varmod-range.exp
@@ -1,13 +1,14 @@
-make: "varmod-range.mk" line 53: Invalid number "x}Rest" != "Rest"" for ':range' modifier
-make: "varmod-range.mk" line 53: Malformed conditional ("${:U:range=x}Rest" != "Rest")
-make: "varmod-range.mk" line 62: Unknown modifier "x0"
-make: "varmod-range.mk" line 62: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
-make: "varmod-range.mk" line 78: Unknown modifier "rang"
-make: "varmod-range.mk" line 78: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
-make: "varmod-range.mk" line 85: Unknown modifier "rango"
-make: "varmod-range.mk" line 85: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
-make: "varmod-range.mk" line 92: Unknown modifier "ranger"
-make: "varmod-range.mk" line 92: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
+make: "varmod-range.mk" line 43: Malformed conditional (${:range=5} != "")
+make: "varmod-range.mk" line 67: Invalid number "x}Rest" != "Rest"" for ':range' modifier
+make: "varmod-range.mk" line 67: Malformed conditional ("${:U:range=x}Rest" != "Rest")
+make: "varmod-range.mk" line 78: Unknown modifier "x0"
+make: "varmod-range.mk" line 78: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
+make: "varmod-range.mk" line 96: Unknown modifier "rang"
+make: "varmod-range.mk" line 96: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
+make: "varmod-range.mk" line 105: Unknown modifier "rango"
+make: "varmod-range.mk" line 105: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
+make: "varmod-range.mk" line 114: Unknown modifier "ranger"
+make: "varmod-range.mk" line 114: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-range.mk b/contrib/bmake/unit-tests/varmod-range.mk
index d63525248e58..920001096054 100644
--- a/contrib/bmake/unit-tests/varmod-range.mk
+++ b/contrib/bmake/unit-tests/varmod-range.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-range.mk,v 1.7 2020/11/01 14:36:25 rillig Exp $
+# $NetBSD: varmod-range.mk,v 1.10 2023/12/17 14:07:22 rillig Exp $
#
# Tests for the :range variable modifier, which generates sequences
# of integers from the given range.
@@ -7,7 +7,7 @@
# modword.mk
# The :range modifier generates a sequence of integers, one number per
-# word of the variable expression's value.
+# word of the expression's value.
.if ${a b c:L:range} != "1 2 3"
. error
.endif
@@ -19,20 +19,32 @@
.endif
# The :range modifier takes the number of words from the value of the
-# variable expression. If that expression is undefined, the range is
+# expression. If that expression is undefined, the range is
# undefined as well. This should not come as a surprise.
.if "${:range}" != ""
. error
.endif
+# An empty expression results in a sequence of a single number, even though
+# the expression contains 0 words.
+.if ${:U:range} != "1"
+. error
+.endif
+
# The :range modifier can be given a parameter, which makes the generated
-# range independent from the value or the name of the variable expression.
-#
-# XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
-# expression into a defined one. This looks like an oversight.
+# range independent from the value or the name of the expression.
.if "${:range=5}" != ""
. error
.endif
+# XXX: As of 2023-12-17, the ':range=n' modifier does not turn the undefined
+# expression into a defined one, even though it does not depend on the value
+# of the expression. This looks like an oversight.
+# expect+1: Malformed conditional (${:range=5} != "")
+.if ${:range=5} != ""
+. error
+.else
+. error
+.endif
# Negative ranges don't make sense.
# As of 2020-11-01, they are accepted though, using up all available memory.
@@ -50,6 +62,8 @@
#
# Since 2020-11-01, the parser issues a more precise "Invalid number" error
# instead.
+# expect+2: Invalid number "x}Rest" != "Rest"" for ':range' modifier
+# expect+1: Malformed conditional ("${:U:range=x}Rest" != "Rest")
.if "${:U:range=x}Rest" != "Rest"
. error
.else
@@ -59,6 +73,8 @@
# The upper limit of the range must always be given in decimal.
# This parse error stops at the 'x', trying to parse it as a variable
# modifier.
+# expect+2: Unknown modifier "x0"
+# expect+1: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
.if "${:U:range=0x0}Rest" != "Rest"
. error
.else
@@ -75,6 +91,8 @@
#.endif
# modifier name too short
+# expect+2: Unknown modifier "rang"
+# expect+1: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
.if "${a b c:L:rang}Rest" != "Rest"
. error
.else
@@ -82,6 +100,8 @@
.endif
# misspelled modifier name
+# expect+2: Unknown modifier "rango"
+# expect+1: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
.if "${a b c:L:rango}Rest" != "Rest"
. error
.else
@@ -89,6 +109,8 @@
.endif
# modifier name too long
+# expect+2: Unknown modifier "ranger"
+# expect+1: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
.if "${a b c:L:ranger}Rest" != "Rest"
. error
.else
diff --git a/contrib/bmake/unit-tests/varmod-remember.mk b/contrib/bmake/unit-tests/varmod-remember.mk
index 403811759672..e92b2d2c4012 100644
--- a/contrib/bmake/unit-tests/varmod-remember.mk
+++ b/contrib/bmake/unit-tests/varmod-remember.mk
@@ -1,30 +1,62 @@
-# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $
+# $NetBSD: varmod-remember.mk,v 1.9 2023/02/09 22:21:57 rillig Exp $
#
-# Tests for the :_ modifier, which saves the current variable value
+# Tests for the :_ modifier, which saves the current expression value
# in the _ variable or another, to be used later again.
-.if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3"
+
+# The ':_' modifier is typically used in situations where the value of an
+# expression is needed at the same time as a sequence of numbers. In these
+# cases, the value of the expression is saved in the temporary variable '_',
+# from where it is taken later in the same expression.
+ABC= ${A B C:L:_:range:@i@$i=${_:[$i]}@}
+DEF= ${D E F:L:_:range:@i@$i=${_:[$i]}@}
+GHI= ${G H I:L:_:range:@i@$i=${_:[$i]}@}
+
+ABC.global:= ${ABC} # is evaluated in the global scope
+.if ${ABC.global} != "1=A 2=B 3=C"
+. error
+.endif
+
+.if ${DEF} != "1=D 2=E 3=F" # is evaluated in the command line scope
+. error
+.endif
+
+# Before var.c 1.1040 from 2023-02-09, the temporary variable '_' was placed
+# in the scope of the current evaluation, which meant that after the first
+# ':_' modifier had been evaluated in command line scope, all further
+# evaluations in global scope could not overwrite the variable '_' anymore,
+# as the command line scope takes precedence over the global scope.
+# The expression ${GHI} therefore evaluated to '1=D 2=E 3=F', reusing the
+# value of '_' from the previous evaluation in command line scope.
+GHI.global:= ${GHI} # is evaluated in the global scope
+.if ${GHI.global} != "1=G 2=H 3=I"
. error
.endif
+
# In the parameterized form, having the variable name on the right side of
-# the = assignment operator is confusing. In almost all other situations
-# the variable name is on the left-hand side of the = operator. Luckily
-# this modifier is only rarely needed.
+# the = assignment operator looks confusing. In almost all other situations,
+# the variable name is on the left-hand side of the = operator, therefore
+# '_=SAVED' looks like it would copy 'SAVED' to '_'. Luckily, this modifier
+# is only rarely needed.
.if ${1 2 3:L:@var@${var:_=SAVED:}@} != "1 2 3"
. error
.elif ${SAVED} != "3"
. error
.endif
-# The ':_' modifier takes a variable name as optional argument. This variable
-# name can refer to other variables, though this was rather an implementation
-# oversight than an intended feature. The variable name stops at the first
-# '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable
-# names.
+
+# The ':_' modifier takes a variable name as optional argument. Before var.c
+# 1.867 from 2021-03-14, this variable name could refer to other variables,
+# such as in 'VAR.$p'. It was not possible to refer to 'VAR.${param}' though,
+# as that form caused a parse error. The cause for the parse error in
+# '${...:_=VAR.${param}}' is that the variable name is parsed in an ad-hoc
+# manner, stopping at the first ':', ')' or '}', without taking any nested
+# expressions into account. Due to this inconsistency that short expressions
+# are possible but long expressions aren't, the name of the temporary variable
+# is no longer expanded.
#
-# Because of all these edge-casey conditions, this "feature" has been removed
-# in var.c 1.867 from 2021-03-14.
+# TODO: Warn about the unusual variable name '$S'.
S= INDIRECT_VARNAME
.if ${value:L:@var@${var:_=$S}@} != "value"
. error
@@ -32,4 +64,15 @@ S= INDIRECT_VARNAME
. error
.endif
+
+# When a variable using ':_' refers to another variable that also uses ':_',
+# the value of the temporary variable '_' from the inner expression leaks into
+# the evaluation of the outer expression. If the expressions were evaluated
+# independently, the last word of the result would be outer_='outer' instead.
+INNER= ${inner:L:_:@i@$i inner_='$_'@}
+OUTER= ${outer:L:_:@o@$o ${INNER} outer_='$_'@}
+.if ${OUTER} != "outer inner inner_='inner' outer_='inner'"
+.endif
+
+
all:
diff --git a/contrib/bmake/unit-tests/varmod-root.exp b/contrib/bmake/unit-tests/varmod-root.exp
index 2c99cd3ef4c7..39a9383953dd 100644
--- a/contrib/bmake/unit-tests/varmod-root.exp
+++ b/contrib/bmake/unit-tests/varmod-root.exp
@@ -1,11 +1 @@
-root of 'a/b/c' is 'a/b/c'
-root of 'def' is 'def'
-root of 'a.b.c' is 'a.b'
-root of 'a.b/c' is 'a'
-root of 'a' is 'a'
-root of 'a.a' is 'a'
-root of '.gitignore' is ''
-root of 'a' is 'a'
-root of 'a.a' is 'a'
-root of 'trailing/' is 'trailing/'
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-root.mk b/contrib/bmake/unit-tests/varmod-root.mk
index 1e3159733df0..cf88491df799 100644
--- a/contrib/bmake/unit-tests/varmod-root.mk
+++ b/contrib/bmake/unit-tests/varmod-root.mk
@@ -1,9 +1,38 @@
-# $NetBSD: varmod-root.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $
+# $NetBSD: varmod-root.mk,v 1.5 2021/12/05 22:31:58 rillig Exp $
#
# Tests for the :R variable modifier, which returns the filename root
# without the extension.
+.if ${a/b/c:L:R} != "a/b/c"
+. error
+.endif
+
+.if ${def:L:R} != "def"
+. error
+.endif
+
+.if ${a.b.c:L:R} != "a.b"
+. error
+.endif
+
+.if ${a.b/c:L:R} != "a"
+. error
+.endif
+
+.if ${a:L:R} != "a"
+. error
+.endif
+
+.if ${a.a:L:R} != "a"
+. error
+.endif
+
+.if ${.gitignore:L:R} != ""
+. error
+.endif
+
+.if ${trailing/:L:R} != "trailing/"
+. error
+.endif
+
all:
-.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/
- @echo "root of '"${path:Q}"' is '"${path:R:Q}"'"
-.endfor
diff --git a/contrib/bmake/unit-tests/varmod-select-words.exp b/contrib/bmake/unit-tests/varmod-select-words.exp
index 39a9383953dd..02e9974c02d6 100644
--- a/contrib/bmake/unit-tests/varmod-select-words.exp
+++ b/contrib/bmake/unit-tests/varmod-select-words.exp
@@ -1 +1,126 @@
+make: Bad modifier ":[]" for variable "LIST"
+LIST:[]="" is an error
+LIST:[0]="one two three four five six"
+LIST:[0x0]="one two three four five six"
+LIST:[000]="one two three four five six"
+LIST:[*]="one two three four five six"
+LIST:[@]="one two three four five six"
+LIST:[0]:C/ /,/="one,two three four five six"
+LIST:[0]:C/ /,/g="one,two,three,four,five,six"
+LIST:[0]:C/ /,/1g="one,two,three,four,five,six"
+LIST:[*]:C/ /,/="one,two three four five six"
+LIST:[*]:C/ /,/g="one,two,three,four,five,six"
+LIST:[*]:C/ /,/1g="one,two,three,four,five,six"
+LIST:[@]:C/ /,/="one two three four five six"
+LIST:[@]:C/ /,/g="one two three four five six"
+LIST:[@]:C/ /,/1g="one two three four five six"
+LIST:[@]:[0]:C/ /,/="one,two three four five six"
+LIST:[0]:[@]:C/ /,/="one two three four five six"
+LIST:[@]:[*]:C/ /,/="one,two three four five six"
+LIST:[*]:[@]:C/ /,/="one two three four five six"
+EMPTY=""
+EMPTY:[#]="1" == 1 ?
+ESCAPEDSPACE="\ "
+ESCAPEDSPACE:[#]="1" == 1 ?
+REALLYSPACE=" "
+REALLYSPACE:[#]="1" == 1 ?
+LIST:[#]="6"
+LIST:[0]:[#]="1" == 1 ?
+LIST:[*]:[#]="1" == 1 ?
+LIST:[@]:[#]="6"
+LIST:[1]:[#]="1"
+LIST:[1..3]:[#]="3"
+EMPTY:[1]=""
+ESCAPEDSPACE="\ "
+ESCAPEDSPACE:[1]="\ "
+REALLYSPACE=" "
+REALLYSPACE:[1]="" == "" ?
+REALLYSPACE:[*]:[1]=" " == " " ?
+LIST:[1]="one"
+make: Bad modifier ":[1.]" for variable "LIST"
+LIST:[1.]="" is an error
+make: Bad modifier ":[1]." for variable "LIST"
+LIST:[1].="}" is an error
+LIST:[2]="two"
+LIST:[6]="six"
+LIST:[7]=""
+LIST:[999]=""
+make: Bad modifier ":[-]" for variable "LIST"
+LIST:[-]="" is an error
+make: Bad modifier ":[--]" for variable "LIST"
+LIST:[--]="" is an error
+LIST:[-1]="six"
+LIST:[-2]="five"
+LIST:[-6]="one"
+LIST:[-7]=""
+LIST:[-999]=""
+LONGLIST:[17]="17"
+LONGLIST:[0x11]="17"
+LONGLIST:[021]="17"
+LIST:[0]:[1]="one two three four five six"
+LIST:[*]:[1]="one two three four five six"
+LIST:[@]:[1]="one"
+LIST:[0]:[2]=""
+LIST:[*]:[2]=""
+LIST:[@]:[2]="two"
+LIST:[*]:C/ /,/:[2]=""
+LIST:[*]:C/ /,/:[*]:[2]=""
+LIST:[*]:C/ /,/:[@]:[2]="three"
+LONGLIST:[012..0x12]="10 11 12 13 14 15 16 17 18"
+make: Bad modifier ":[1.]" for variable "LIST"
+LIST:[1.]="" is an error
+make: Bad modifier ":[1..]" for variable "LIST"
+LIST:[1..]="" is an error
+make: Bad modifier ":[1.. ]" for variable "LIST"
+LIST:[1.. ]="" is an error
+LIST:[1..1]="one"
+make: Bad modifier ":[1..1.]" for variable "LIST"
+LIST:[1..1.]="" is an error
+LIST:[1..2]="one two"
+LIST:[2..1]="two one"
+LIST:[3..-2]="three four five"
+LIST:[-4..4]="three four"
+make: Bad modifier ":[0..1]" for variable "LIST"
+LIST:[0..1]="" is an error
+make: Bad modifier ":[-1..0]" for variable "LIST"
+LIST:[-1..0]="" is an error
+LIST:[-1..1]="six five four three two one"
+LIST:[0..0]="one two three four five six"
+LIST:[3..99]="three four five six"
+LIST:[-3..-99]="four three two one"
+LIST:[-99..-3]="one two three four"
+HASH="#" == "#" ?
+LIST:[${HASH}]="6"
+LIST:[${ZERO}]="one two three four five six"
+LIST:[${ZERO}x${ONE}]="one"
+LIST:[${ONE}]="one"
+LIST:[${MINUSONE}]="six"
+LIST:[${STAR}]="one two three four five six"
+LIST:[${AT}]="one two three four five six"
+make: Bad modifier ":[${EMPTY" for variable "LIST"
+LIST:[${EMPTY}]="" is an error
+LIST:[${LONGLIST:[21]:S/2//}]="one"
+LIST:[${LIST:[#]}]="six"
+LIST:[${LIST:[${HASH}]}]="six"
+LIST:[ -1.. +3]="six five four three"
+LIST:S/ /,/="one two three four five six"
+LIST:S/ /,/W="one,two three four five six"
+LIST:S/ /,/gW="one,two,three,four,five,six"
+EMPTY:S/^/,/=","
+EMPTY:S/^/,/W=","
+LIST:C/ /,/="one two three four five six"
+LIST:C/ /,/W="one,two three four five six"
+LIST:C/ /,/gW="one,two,three,four,five,six"
+EMPTY:C/^/,/=","
+EMPTY:C/^/,/W=","
+LIST:tW="one two three four five six"
+LIST:tw="one two three four five six"
+LIST:tW:C/ /,/="one,two three four five six"
+LIST:tW:C/ /,/g="one,two,three,four,five,six"
+LIST:tW:C/ /,/1g="one,two,three,four,five,six"
+LIST:tw:C/ /,/="one two three four five six"
+LIST:tw:C/ /,/g="one two three four five six"
+LIST:tw:C/ /,/1g="one two three four five six"
+LIST:tw:tW:C/ /,/="one,two three four five six"
+LIST:tW:tw:C/ /,/="one two three four five six"
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-select-words.mk b/contrib/bmake/unit-tests/varmod-select-words.mk
index a9df25f9ff32..910b67a24e39 100644
--- a/contrib/bmake/unit-tests/varmod-select-words.mk
+++ b/contrib/bmake/unit-tests/varmod-select-words.mk
@@ -1,9 +1,166 @@
-# $NetBSD: varmod-select-words.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-select-words.mk,v 1.4 2022/01/23 16:09:38 rillig Exp $
#
# Tests for the :[...] variable modifier, which selects a single word
# or a range of words from a variable.
+#
+# History:
+# The variable modifier ':[...]' was added on 2003-09-27.
+#
+# See also:
+# modword.mk (should be migrated here)
+
+all: mod-squarebrackets mod-S-W mod-C-W mod-tW-tw
+
+LIST= one two three four five six
+LONGLIST= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
+
+EMPTY= # the space should be ignored
+ESCAPEDSPACE= \ # escaped space before the '#', the actual value is '\ '
+REALLYSPACE:= ${:U }
+HASH= \#
+AT= @
+STAR= *
+ZERO= 0
+ONE= 1
+MINUSONE= -1
+
+mod-squarebrackets: mod-squarebrackets-0-star-at \
+ mod-squarebrackets-hash \
+ mod-squarebrackets-n \
+ mod-squarebrackets-start-end \
+ mod-squarebrackets-nested \
+ mod-squarebrackets-space
+
+mod-squarebrackets-0-star-at:
+ @echo 'LIST:[]="${LIST:[]}" is an error'
+ @echo 'LIST:[0]="${LIST:[0]}"'
+ @echo 'LIST:[0x0]="${LIST:[0x0]}"'
+ @echo 'LIST:[000]="${LIST:[000]}"'
+ @echo 'LIST:[*]="${LIST:[*]}"'
+ @echo 'LIST:[@]="${LIST:[@]}"'
+ @echo 'LIST:[0]:C/ /,/="${LIST:[0]:C/ /,/}"'
+ @echo 'LIST:[0]:C/ /,/g="${LIST:[0]:C/ /,/g}"'
+ @echo 'LIST:[0]:C/ /,/1g="${LIST:[0]:C/ /,/1g}"'
+ @echo 'LIST:[*]:C/ /,/="${LIST:[*]:C/ /,/}"'
+ @echo 'LIST:[*]:C/ /,/g="${LIST:[*]:C/ /,/g}"'
+ @echo 'LIST:[*]:C/ /,/1g="${LIST:[*]:C/ /,/1g}"'
+ @echo 'LIST:[@]:C/ /,/="${LIST:[@]:C/ /,/}"'
+ @echo 'LIST:[@]:C/ /,/g="${LIST:[@]:C/ /,/g}"'
+ @echo 'LIST:[@]:C/ /,/1g="${LIST:[@]:C/ /,/1g}"'
+ @echo 'LIST:[@]:[0]:C/ /,/="${LIST:[@]:[0]:C/ /,/}"'
+ @echo 'LIST:[0]:[@]:C/ /,/="${LIST:[0]:[@]:C/ /,/}"'
+ @echo 'LIST:[@]:[*]:C/ /,/="${LIST:[@]:[*]:C/ /,/}"'
+ @echo 'LIST:[*]:[@]:C/ /,/="${LIST:[*]:[@]:C/ /,/}"'
+
+mod-squarebrackets-hash:
+ @echo 'EMPTY="${EMPTY}"'
+ @echo 'EMPTY:[#]="${EMPTY:[#]}" == 1 ?'
+ @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
+ @echo 'ESCAPEDSPACE:[#]="${ESCAPEDSPACE:[#]}" == 1 ?'
+ @echo 'REALLYSPACE="${REALLYSPACE}"'
+ @echo 'REALLYSPACE:[#]="${REALLYSPACE:[#]}" == 1 ?'
+ @echo 'LIST:[#]="${LIST:[#]}"'
+ @echo 'LIST:[0]:[#]="${LIST:[0]:[#]}" == 1 ?'
+ @echo 'LIST:[*]:[#]="${LIST:[*]:[#]}" == 1 ?'
+ @echo 'LIST:[@]:[#]="${LIST:[@]:[#]}"'
+ @echo 'LIST:[1]:[#]="${LIST:[1]:[#]}"'
+ @echo 'LIST:[1..3]:[#]="${LIST:[1..3]:[#]}"'
+
+mod-squarebrackets-n:
+ @echo 'EMPTY:[1]="${EMPTY:[1]}"'
+ @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
+ @echo 'ESCAPEDSPACE:[1]="${ESCAPEDSPACE:[1]}"'
+ @echo 'REALLYSPACE="${REALLYSPACE}"'
+ @echo 'REALLYSPACE:[1]="${REALLYSPACE:[1]}" == "" ?'
+ @echo 'REALLYSPACE:[*]:[1]="${REALLYSPACE:[*]:[1]}" == " " ?'
+ @echo 'LIST:[1]="${LIST:[1]}"'
+ @echo 'LIST:[1.]="${LIST:[1.]}" is an error'
+ @echo 'LIST:[1].="${LIST:[1].}" is an error'
+ @echo 'LIST:[2]="${LIST:[2]}"'
+ @echo 'LIST:[6]="${LIST:[6]}"'
+ @echo 'LIST:[7]="${LIST:[7]}"'
+ @echo 'LIST:[999]="${LIST:[999]}"'
+ @echo 'LIST:[-]="${LIST:[-]}" is an error'
+ @echo 'LIST:[--]="${LIST:[--]}" is an error'
+ @echo 'LIST:[-1]="${LIST:[-1]}"'
+ @echo 'LIST:[-2]="${LIST:[-2]}"'
+ @echo 'LIST:[-6]="${LIST:[-6]}"'
+ @echo 'LIST:[-7]="${LIST:[-7]}"'
+ @echo 'LIST:[-999]="${LIST:[-999]}"'
+ @echo 'LONGLIST:[17]="${LONGLIST:[17]}"'
+ @echo 'LONGLIST:[0x11]="${LONGLIST:[0x11]}"'
+ @echo 'LONGLIST:[021]="${LONGLIST:[021]}"'
+ @echo 'LIST:[0]:[1]="${LIST:[0]:[1]}"'
+ @echo 'LIST:[*]:[1]="${LIST:[*]:[1]}"'
+ @echo 'LIST:[@]:[1]="${LIST:[@]:[1]}"'
+ @echo 'LIST:[0]:[2]="${LIST:[0]:[2]}"'
+ @echo 'LIST:[*]:[2]="${LIST:[*]:[2]}"'
+ @echo 'LIST:[@]:[2]="${LIST:[@]:[2]}"'
+ @echo 'LIST:[*]:C/ /,/:[2]="${LIST:[*]:C/ /,/:[2]}"'
+ @echo 'LIST:[*]:C/ /,/:[*]:[2]="${LIST:[*]:C/ /,/:[*]:[2]}"'
+ @echo 'LIST:[*]:C/ /,/:[@]:[2]="${LIST:[*]:C/ /,/:[@]:[2]}"'
+ @echo 'LONGLIST:[012..0x12]="${LONGLIST:[012..0x12]}"'
+
+mod-squarebrackets-start-end:
+ @echo 'LIST:[1.]="${LIST:[1.]}" is an error'
+ @echo 'LIST:[1..]="${LIST:[1..]}" is an error'
+ @echo 'LIST:[1.. ]="${LIST:[1.. ]}" is an error'
+ @echo 'LIST:[1..1]="${LIST:[1..1]}"'
+ @echo 'LIST:[1..1.]="${LIST:[1..1.]}" is an error'
+ @echo 'LIST:[1..2]="${LIST:[1..2]}"'
+ @echo 'LIST:[2..1]="${LIST:[2..1]}"'
+ @echo 'LIST:[3..-2]="${LIST:[3..-2]}"'
+ @echo 'LIST:[-4..4]="${LIST:[-4..4]}"'
+ @echo 'LIST:[0..1]="${LIST:[0..1]}" is an error'
+ @echo 'LIST:[-1..0]="${LIST:[-1..0]}" is an error'
+ @echo 'LIST:[-1..1]="${LIST:[-1..1]}"'
+ @echo 'LIST:[0..0]="${LIST:[0..0]}"'
+ @echo 'LIST:[3..99]="${LIST:[3..99]}"'
+ @echo 'LIST:[-3..-99]="${LIST:[-3..-99]}"'
+ @echo 'LIST:[-99..-3]="${LIST:[-99..-3]}"'
+
+mod-squarebrackets-nested:
+ @echo 'HASH="${HASH}" == "#" ?'
+ @echo 'LIST:[$${HASH}]="${LIST:[${HASH}]}"'
+ @echo 'LIST:[$${ZERO}]="${LIST:[${ZERO}]}"'
+ @echo 'LIST:[$${ZERO}x$${ONE}]="${LIST:[${ZERO}x${ONE}]}"'
+ @echo 'LIST:[$${ONE}]="${LIST:[${ONE}]}"'
+ @echo 'LIST:[$${MINUSONE}]="${LIST:[${MINUSONE}]}"'
+ @echo 'LIST:[$${STAR}]="${LIST:[${STAR}]}"'
+ @echo 'LIST:[$${AT}]="${LIST:[${AT}]}"'
+ @echo 'LIST:[$${EMPTY}]="${LIST:[${EMPTY}]}" is an error'
+ @echo 'LIST:[$${LONGLIST:[21]:S/2//}]="${LIST:[${LONGLIST:[21]:S/2//}]}"'
+ @echo 'LIST:[$${LIST:[#]}]="${LIST:[${LIST:[#]}]}"'
+ @echo 'LIST:[$${LIST:[$${HASH}]}]="${LIST:[${LIST:[${HASH}]}]}"'
+
+mod-squarebrackets-space:
+ # As of 2020-11-01, it is possible to have spaces before the numbers
+ # but not after them. This is an unintended side-effect of using
+ # strtol for parsing the numbers.
+ @echo 'LIST:[ -1.. +3]="${LIST:[ -1.. +3]}"'
+
+mod-C-W:
+ @echo 'LIST:C/ /,/="${LIST:C/ /,/}"'
+ @echo 'LIST:C/ /,/W="${LIST:C/ /,/W}"'
+ @echo 'LIST:C/ /,/gW="${LIST:C/ /,/gW}"'
+ @echo 'EMPTY:C/^/,/="${EMPTY:C/^/,/}"'
+ @echo 'EMPTY:C/^/,/W="${EMPTY:C/^/,/W}"'
-# TODO: Implementation
+mod-S-W:
+ @echo 'LIST:S/ /,/="${LIST:S/ /,/}"'
+ @echo 'LIST:S/ /,/W="${LIST:S/ /,/W}"'
+ @echo 'LIST:S/ /,/gW="${LIST:S/ /,/gW}"'
+ @echo 'EMPTY:S/^/,/="${EMPTY:S/^/,/}"'
+ @echo 'EMPTY:S/^/,/W="${EMPTY:S/^/,/W}"'
-all:
- @:;
+mod-tW-tw:
+ @echo 'LIST:tW="${LIST:tW}"'
+ @echo 'LIST:tw="${LIST:tw}"'
+ @echo 'LIST:tW:C/ /,/="${LIST:tW:C/ /,/}"'
+ @echo 'LIST:tW:C/ /,/g="${LIST:tW:C/ /,/g}"'
+ @echo 'LIST:tW:C/ /,/1g="${LIST:tW:C/ /,/1g}"'
+ @echo 'LIST:tw:C/ /,/="${LIST:tw:C/ /,/}"'
+ @echo 'LIST:tw:C/ /,/g="${LIST:tw:C/ /,/g}"'
+ @echo 'LIST:tw:C/ /,/1g="${LIST:tw:C/ /,/1g}"'
+ @echo 'LIST:tw:tW:C/ /,/="${LIST:tw:tW:C/ /,/}"'
+ @echo 'LIST:tW:tw:C/ /,/="${LIST:tW:tw:C/ /,/}"'
diff --git a/contrib/bmake/unit-tests/varmod-shell.exp b/contrib/bmake/unit-tests/varmod-shell.exp
index 9aef0c9e5acc..208ef953728b 100644
--- a/contrib/bmake/unit-tests/varmod-shell.exp
+++ b/contrib/bmake/unit-tests/varmod-shell.exp
@@ -1,3 +1,13 @@
make: "echo word; false" returned non-zero status
make: "echo word; false" returned non-zero status
+Global: _ = # (empty)
+Var_Parse: ${:!echo word; ${:Ufalse}!} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${:!...} on value "" (eval-keep-dollar-and-undefined, undefined)
+Modifier part: "echo word; false"
+Capturing the output of command "echo word; false"
+make: "echo word; false" returned non-zero status
+Result of ${:!echo word; ${:Ufalse}!} is "word" (eval-keep-dollar-and-undefined, defined)
+Global: _ = word
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-shell.mk b/contrib/bmake/unit-tests/varmod-shell.mk
index c736042f80a0..d449709cee0f 100644
--- a/contrib/bmake/unit-tests/varmod-shell.mk
+++ b/contrib/bmake/unit-tests/varmod-shell.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-shell.mk,v 1.6 2021/02/14 20:16:17 rillig Exp $
+# $NetBSD: varmod-shell.mk,v 1.7 2022/01/10 20:32:29 rillig Exp $
#
# Tests for the ':!cmd!' variable modifier, which runs the shell command
# given by the variable modifier and returns its output.
@@ -20,8 +20,7 @@
#
# Between 2000-04-29 and 2020-11-17, the error message mentioned the previous
# value of the expression (which is usually an empty string) instead of the
-# command that was executed. It's strange that such a simple bug could
-# survive such a long time.
+# command that was executed.
.if ${:!echo word; false!} != "word"
. error
.endif
@@ -29,4 +28,9 @@
. error
.endif
+
+.MAKEFLAGS: -dv # to see the actual command
+_:= ${:!echo word; ${:Ufalse}!}
+.MAKEFLAGS: -d0
+
all:
diff --git a/contrib/bmake/unit-tests/varmod-subst-regex.mk b/contrib/bmake/unit-tests/varmod-subst-regex.mk
index 197691d73aad..c1ffc4580d3a 100644
--- a/contrib/bmake/unit-tests/varmod-subst-regex.mk
+++ b/contrib/bmake/unit-tests/varmod-subst-regex.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-subst-regex.mk,v 1.7 2021/06/21 08:17:39 rillig Exp $
+# $NetBSD: varmod-subst-regex.mk,v 1.11 2023/12/18 11:13:51 rillig Exp $
#
# Tests for the :C,from,to, variable modifier.
@@ -10,7 +10,7 @@ all: mod-regex-limits
all: mod-regex-errors
all: unmatched-subexpression
-# The variable expression expands to 4 words. Of these words, none matches
+# The expression expands to 4 words. Of these words, none matches
# the regular expression "a b" since these words don't contain any
# whitespace.
.if ${:Ua b b c:C,a b,,} != "a b b c"
@@ -18,7 +18,7 @@ all: unmatched-subexpression
.endif
# Using the '1' modifier does not change anything. The '1' modifier just
-# means to apply at most 1 replacement in the whole variable expression.
+# means to apply at most 1 replacement in the whole expression.
.if ${:Ua b b c:C,a b,,1} != "a b b c"
. error
.endif
@@ -84,9 +84,54 @@ all: unmatched-subexpression
. error
.endif
+
+# Like the ':S' modifier, the ':C' modifier matches on an expression
+# that contains no words at all, but only if the regular expression matches an
+# empty string, for example, when the regular expression is anchored at the
+# beginning or the end of the word. An unanchored regular expression that
+# matches the empty string is uncommon in practice, as it would match before
+# each character of the word.
+.if "<${:U:S,,unanchored,}> <${:U:C,.?,unanchored,}>" != "<> <unanchored>"
+. error
+.endif
+.if "<${:U:S,^,prefix,}> <${:U:C,^,prefix,}>" != "<prefix> <prefix>"
+. error
+.endif
+.if "<${:U:S,$,suffix,}> <${:U:C,$,suffix,}>" != "<suffix> <suffix>"
+. error
+.endif
+.if "<${:U:S,^$,whole,}> <${:U:C,^$,whole,}>" != "<whole> <whole>"
+. error
+.endif
+.if "<${:U:S,,unanchored,g}> <${:U:C,.?,unanchored,g}>" != "<> <unanchored>"
+. error
+.endif
+.if "<${:U:S,^,prefix,g}> <${:U:C,^,prefix,g}>" != "<prefix> <prefix>"
+. error
+.endif
+.if "<${:U:S,$,suffix,g}> <${:U:C,$,suffix,g}>" != "<suffix> <suffix>"
+. error
+.endif
+.if "<${:U:S,^$,whole,g}> <${:U:C,^$,whole,g}>" != "<whole> <whole>"
+. error
+.endif
+.if "<${:U:S,,unanchored,W}> <${:U:C,.?,unanchored,W}>" != "<> <unanchored>"
+. error
+.endif
+.if "<${:U:S,^,prefix,W}> <${:U:C,^,prefix,W}>" != "<prefix> <prefix>"
+. error
+.endif
+.if "<${:U:S,$,suffix,W}> <${:U:C,$,suffix,W}>" != "<suffix> <suffix>"
+. error
+.endif
+.if "<${:U:S,^$,whole,W}> <${:U:C,^$,whole,W}>" != "<whole> <whole>"
+. error
+.endif
+
+
# Multiple asterisks form an invalid regular expression. This produces an
# error message and (as of 2020-08-28) stops parsing in the middle of the
-# variable expression. The unparsed part of the expression is then copied
+# expression. The unparsed part of the expression is then copied
# verbatim to the output, which is unexpected and can lead to strange shell
# commands being run.
mod-regex-compile-error:
@@ -101,7 +146,7 @@ mod-regex-limits:
@echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q}
@echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q}
# The :C modifier only handles single-digit capturing groups,
- # which is more than enough for daily use.
+ # which is enough for all practical use cases.
@echo $@:capture:${:UabcdefghijABCDEFGHIJrest:C,(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.),\9\8\7\6\5\4\3\2\1\0\10\11\12,}
mod-regex-errors:
@@ -109,7 +154,7 @@ mod-regex-errors:
# If the replacement pattern produces a parse error because of an
# unknown modifier, the parse error is ignored in ParseModifierPart
- # and the faulty variable expression expands to "".
+ # and the faulty expression expands to "".
@echo $@: ${word:L:C,.*,x${:U:Z}y,W}
# In regular expressions with alternatives, not all capturing groups are
diff --git a/contrib/bmake/unit-tests/varmod-subst.mk b/contrib/bmake/unit-tests/varmod-subst.mk
index 85f41e499ab7..2903d36445f8 100644
--- a/contrib/bmake/unit-tests/varmod-subst.mk
+++ b/contrib/bmake/unit-tests/varmod-subst.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-subst.mk,v 1.8 2021/05/14 19:37:16 rillig Exp $
+# $NetBSD: varmod-subst.mk,v 1.14 2023/12/18 11:13:51 rillig Exp $
#
# Tests for the :S,from,to, variable modifier.
@@ -9,83 +9,180 @@ all: mod-subst-dollar
WORDS= sequences of letters
+# The empty pattern never matches anything, except if it is anchored at the
+# beginning or the end of the word.
.if ${WORDS:S,,,} != ${WORDS}
-. warning The empty pattern matches something.
+. error
.endif
+# The :S modifier flag '1' is applied exactly once.
.if ${WORDS:S,e,*,1} != "s*quences of letters"
-. warning The :S modifier flag '1' is not applied exactly once.
+. error
.endif
+# The :S modifier flag '1' is applied to the first occurrence, no matter if
+# the occurrence is in the first word or not.
.if ${WORDS:S,f,*,1} != "sequences o* letters"
-. warning The :S modifier flag '1' is only applied to the first word,\
- not to the first occurrence.
+. error
.endif
+# The :S modifier replaces every first match per word.
.if ${WORDS:S,e,*,} != "s*quences of l*tters"
-. warning The :S modifier does not replace every first match per word.
+. error
.endif
+# The :S modifier flag 'g' replaces every occurrence.
.if ${WORDS:S,e,*,g} != "s*qu*nc*s of l*tt*rs"
-. warning The :S modifier flag 'g' does not replace every occurrence.
+. error
.endif
+# The '^' in the search pattern anchors the pattern at the beginning of each
+# word, thereby matching a prefix.
.if ${WORDS:S,^sequ,occurr,} != "occurrences of letters"
-. warning The :S modifier fails for a short match anchored at the start.
+. error
.endif
+# The :S modifier with a '^' anchor replaces the whole word if that word is
+# exactly the pattern.
.if ${WORDS:S,^of,with,} != "sequences with letters"
-. warning The :S modifier fails for an exact match anchored at the start.
+. error
.endif
+# The :S modifier does not match if the pattern is longer than the word.
.if ${WORDS:S,^office,does not match,} != ${WORDS}
-. warning The :S modifier matches a too long pattern anchored at the start.
+. warning
.endif
+# The '$' in the search pattern anchors the pattern at the end of each word,
+# thereby matching a suffix.
.if ${WORDS:S,f$,r,} != "sequences or letters"
-. warning The :S modifier fails for a short match anchored at the end.
+. error
.endif
+# The :S modifier with a '$' anchor replaces at most one occurrence per word.
.if ${WORDS:S,s$,,} != "sequence of letter"
-. warning The :S modifier fails to replace one occurrence per word.
+. error
.endif
+# The :S modifier with a '$' anchor replaces the whole word if that word is
+# exactly the pattern.
.if ${WORDS:S,of$,,} != "sequences letters"
-. warning The :S modifier fails for an exact match anchored at the end.
+. error
.endif
+# The :S modifier with a '$' anchor and a pattern that is longer than a word
+# cannot match that word.
.if ${WORDS:S,eof$,,} != ${WORDS}
-. warning The :S modifier matches a too long pattern anchored at the end.
+. warning
.endif
+# The :S modifier with the '^' and '$' anchors matches an exact word.
.if ${WORDS:S,^of$,,} != "sequences letters"
-. warning The :S modifier does not match a word anchored at both ends.
+. error
.endif
+# The :S modifier with the '^' and '$' anchors does not match a word that
+# starts with the pattern but is longer than the pattern.
.if ${WORDS:S,^o$,,} != ${WORDS}
-. warning The :S modifier matches a prefix anchored at both ends.
+. error
.endif
+# The :S modifier with the '^' and '$' anchors does not match a word that ends
+# with the pattern but is longer than the pattern.
.if ${WORDS:S,^f$,,} != ${WORDS}
-. warning The :S modifier matches a suffix anchored at both ends.
+. error
.endif
+# The :S modifier with the '^' and '$' anchors does not match a word if the
+# pattern ends with the word but is longer than the word.
.if ${WORDS:S,^eof$,,} != ${WORDS}
-. warning The :S modifier matches a too long prefix anchored at both ends.
+. error
.endif
+# The :S modifier with the '^' and '$' anchors does not match a word if the
+# pattern starts with the word but is longer than the word.
.if ${WORDS:S,^office$,,} != ${WORDS}
-. warning The :S modifier matches a too long suffix anchored at both ends.
+. error
.endif
+# Except for the '^' and '$' anchors, the pattern does not contain any special
+# characters, so the '*' from the pattern would only match a literal '*' in a
+# word.
.if ${WORDS:S,*,replacement,} != ${WORDS}
-. error The '*' seems to be interpreted as a wildcard of some kind.
+. error
.endif
+# Except for the '^' and '$' anchors, the pattern does not contain any special
+# characters, so the '.' from the pattern would only match a literal '.' in a
+# word.
.if ${WORDS:S,.,replacement,} != ${WORDS}
-. error The '.' seems to be interpreted as a wildcard of some kind.
+. error
.endif
+# The '&' in the replacement is a placeholder for the text matched by the
+# pattern.
+.if ${:Uvalue:S,^val,&,} != "value"
+. error
+.endif
+.if ${:Uvalue:S,ue$,&,} != "value"
+. error
+.endif
+.if ${:Uvalue:S,^val,&-&-&,} != "val-val-value"
+. error
+.endif
+.if ${:Uvalue:S,ue$,&-&-&,} != "value-ue-ue"
+. error
+.endif
+
+
+# When a word is replaced with nothing, the remaining words are separated by a
+# single space, not two.
+.if ${1 2 3:L:S,2,,} != "1 3"
+. error
+.endif
+
+
+# In an empty expression, the ':S' modifier matches a single time, but only if
+# the search string is empty and anchored at either the beginning or the end
+# of the word.
+.if ${:U:S,,out-of-nothing,} != ""
+. error
+.endif
+.if ${:U:S,^,out-of-nothing,} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,$,out-of-nothing,} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,^$,out-of-nothing,} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,,out-of-nothing,g} != ""
+. error
+.endif
+.if ${:U:S,^,out-of-nothing,g} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,$,out-of-nothing,g} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,^$,out-of-nothing,g} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,,out-of-nothing,W} != ""
+. error
+.endif
+.if ${:U:S,^,out-of-nothing,W} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,$,out-of-nothing,W} != "out-of-nothing"
+. error
+.endif
+.if ${:U:S,^$,out-of-nothing,W} != "out-of-nothing"
+. error
+.endif
+
+
mod-subst:
@echo $@:
@echo :${:Ua b b c:S,a b,,:Q}:
diff --git a/contrib/bmake/unit-tests/varmod-sun-shell.exp b/contrib/bmake/unit-tests/varmod-sun-shell.exp
index 5087bc66d943..7f661ff6e79e 100644
--- a/contrib/bmake/unit-tests/varmod-sun-shell.exp
+++ b/contrib/bmake/unit-tests/varmod-sun-shell.exp
@@ -1,2 +1,13 @@
make: "echo word; false" returned non-zero status
+Global: _ = # (empty)
+Var_Parse: ${echo word; ${:Ufalse}:L:sh} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${echo word; false:L} on value "" (eval-keep-dollar-and-undefined, undefined)
+Result of ${echo word; false:L} is "echo word; false" (eval-keep-dollar-and-undefined, defined)
+Evaluating modifier ${echo word; false:s...} on value "echo word; false" (eval-keep-dollar-and-undefined, defined)
+Capturing the output of command "echo word; false"
+make: "echo word; false" returned non-zero status
+Result of ${echo word; false:sh} is "word" (eval-keep-dollar-and-undefined, defined)
+Global: _ = word
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-sun-shell.mk b/contrib/bmake/unit-tests/varmod-sun-shell.mk
index 712b36bc7030..97acc5bd8c0f 100644
--- a/contrib/bmake/unit-tests/varmod-sun-shell.mk
+++ b/contrib/bmake/unit-tests/varmod-sun-shell.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sun-shell.mk,v 1.1 2021/02/14 20:16:17 rillig Exp $
+# $NetBSD: varmod-sun-shell.mk,v 1.2 2022/01/10 20:32:29 rillig Exp $
#
# Tests for the :sh variable modifier, which runs the shell command
# given by the variable value and returns its output.
@@ -18,4 +18,9 @@
. error
.endif
+
+.MAKEFLAGS: -dv # to see the actual command
+_:= ${echo word; ${:Ufalse}:L:sh}
+.MAKEFLAGS: -d0
+
all:
diff --git a/contrib/bmake/unit-tests/varmod-sysv.exp b/contrib/bmake/unit-tests/varmod-sysv.exp
index 59275857f98a..6a3728c3c0fc 100644
--- a/contrib/bmake/unit-tests/varmod-sysv.exp
+++ b/contrib/bmake/unit-tests/varmod-sysv.exp
@@ -1,5 +1,5 @@
make: Unfinished modifier for "word214" ('=' missing)
-make: "varmod-sysv.mk" line 214: Malformed conditional (${word214:L:from${:D=}to})
+make: "varmod-sysv.mk" line 215: Malformed conditional (${word214:L:from${:D=}to})
word modifier result
'' = ""
suffix = "suffix"
diff --git a/contrib/bmake/unit-tests/varmod-sysv.mk b/contrib/bmake/unit-tests/varmod-sysv.mk
index 712c1731717b..0f92e1df7032 100644
--- a/contrib/bmake/unit-tests/varmod-sysv.mk
+++ b/contrib/bmake/unit-tests/varmod-sysv.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sysv.mk,v 1.14 2021/04/12 16:09:57 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the variable modifier ':from=to', which replaces the suffix
# "from" with "to". It can also use '%' as a wildcard.
@@ -49,7 +49,7 @@
. error
.endif
-# In the modifier ':from=to', both parts can contain variable expressions.
+# In the modifier ':from=to', both parts can contain expressions.
.if ${one two:L:${:Uone}=${:U1}} != "1 two"
. error
.endif
@@ -69,7 +69,7 @@
.endif
# The replacement string can contain spaces, thereby changing the number
-# of words in the variable expression.
+# of words in the expression.
.if ${In:L:%=% ${:Uthe Sun}} != "In the Sun"
. error
.endif
@@ -206,11 +206,12 @@
. error
.endif
-# This is not a SysV modifier since the nested variable expression expands
+# This is not a SysV modifier since the nested expression expands
# to an empty string. The '=' in it should be irrelevant during parsing.
# XXX: As of 2020-12-05, this expression generates an "Unfinished modifier"
# error, while the correct error message would be "Unknown modifier" since
# there is no modifier named "fromto".
+# expect+1: Malformed conditional (${word214:L:from${:D=}to})
.if ${word214:L:from${:D=}to}
. error
.endif
@@ -220,7 +221,7 @@
# "fromto}...". The next modifier is a SysV modifier. ApplyModifier_SysV
# parses the modifier as "from${:D=}to", ending at the '}'. Next, the two
# parts of the modifier are parsed using ParseModifierPart, which scans
-# differently, properly handling nested variable expressions. The two parts
+# differently, properly handling nested expressions. The two parts
# are now "fromto}..." and "replaced".
.if "${:Ufromto\}...:from${:D=}to}...=replaced}" != "replaced"
. error
diff --git a/contrib/bmake/unit-tests/varmod-to-abs.exp b/contrib/bmake/unit-tests/varmod-to-abs.exp
index 426b4d39744f..4506d5ea8175 100644
--- a/contrib/bmake/unit-tests/varmod-to-abs.exp
+++ b/contrib/bmake/unit-tests/varmod-to-abs.exp
@@ -1,5 +1,5 @@
-make: "varmod-to-abs.mk" line 18: does-not-exist.c
make: "varmod-to-abs.mk" line 19: does-not-exist.c
+make: "varmod-to-abs.mk" line 21: does-not-exist.c
cached_realpath: varmod-to-abs.mk -> varmod-to-abs.mk
-make: "varmod-to-abs.mk" line 23: varmod-to-abs.mk
+make: "varmod-to-abs.mk" line 26: varmod-to-abs.mk
exit status 0
diff --git a/contrib/bmake/unit-tests/varmod-to-abs.mk b/contrib/bmake/unit-tests/varmod-to-abs.mk
index 7f23318487e3..bc4722068988 100644
--- a/contrib/bmake/unit-tests/varmod-to-abs.mk
+++ b/contrib/bmake/unit-tests/varmod-to-abs.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-to-abs.mk,v 1.5 2020/11/15 05:48:17 rillig Exp $
+# $NetBSD: varmod-to-abs.mk,v 1.6 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the :tA variable modifier, which returns the absolute path for
# each of the words in the variable value.
@@ -15,11 +15,14 @@
# keeping the cache, just like the GNode for global variables.
.MAKEFLAGS: -dd
does-not-exist.c= /dev/null
+# expect+1: does-not-exist.c
.info ${does-not-exist.c:L:tA}
+# expect+1: does-not-exist.c
.info ${does-not-exist.c:L:tA}
# The output of the following line is modified by the global _SED_CMDS in
# unit-tests/Makefile. See the .rawout file for the truth.
+# expect+1: varmod-to-abs.mk
.info ${MAKEFILE:tA}
.MAKEFLAGS: -d0
diff --git a/contrib/bmake/unit-tests/varmod-to-lower.mk b/contrib/bmake/unit-tests/varmod-to-lower.mk
index 19d3406054b7..44116fd3eee2 100644
--- a/contrib/bmake/unit-tests/varmod-to-lower.mk
+++ b/contrib/bmake/unit-tests/varmod-to-lower.mk
@@ -1,7 +1,7 @@
-# $NetBSD: varmod-to-lower.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: varmod-to-lower.mk,v 1.6 2022/11/29 23:54:55 rillig Exp $
#
-# Tests for the :tl variable modifier, which returns the words in the
-# variable value, converted to lowercase.
+# Tests for the :tl variable modifier, which converts the expression value
+# to lowercase.
#
# TODO: What about non-ASCII characters? ISO-8859-1, UTF-8?
@@ -17,5 +17,10 @@
. error
.endif
-all:
- @:;
+# The ':tl' modifier works on the whole string, without splitting it into
+# words.
+.if ${:Umultiple spaces:tl} != "multiple spaces"
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varmod-to-separator.exp b/contrib/bmake/unit-tests/varmod-to-separator.exp
index c6e8ce98a21a..a7d4ddb20147 100644
--- a/contrib/bmake/unit-tests/varmod-to-separator.exp
+++ b/contrib/bmake/unit-tests/varmod-to-separator.exp
@@ -1,19 +1,25 @@
-make: "varmod-to-separator.mk" line 107: Invalid character number: 400:tu}
-make: "varmod-to-separator.mk" line 107: Malformed conditional (${WORDS:[1..3]:ts\400:tu})
-make: "varmod-to-separator.mk" line 121: Invalid character number: 100:tu}
-make: "varmod-to-separator.mk" line 121: Malformed conditional (${WORDS:[1..3]:ts\x100:tu})
+make: "varmod-to-separator.mk" line 155: Invalid character number at "400:tu}"
+make: "varmod-to-separator.mk" line 155: Malformed conditional (${WORDS:[1..3]:ts\400:tu})
+make: "varmod-to-separator.mk" line 171: Invalid character number at "100:tu}"
+make: "varmod-to-separator.mk" line 171: Malformed conditional (${WORDS:[1..3]:ts\x100:tu})
make: Bad modifier ":ts\-300" for variable "WORDS"
-make: "varmod-to-separator.mk" line 128: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
+make: "varmod-to-separator.mk" line 179: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
make: Bad modifier ":ts\8" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 136: Malformed conditional (${1 2 3:L:ts\8:tu})
+make: "varmod-to-separator.mk" line 188: Malformed conditional (${1 2 3:L:ts\8:tu})
make: Bad modifier ":ts\100L" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 143: Malformed conditional (${1 2 3:L:ts\100L})
+make: "varmod-to-separator.mk" line 196: Malformed conditional (${1 2 3:L:ts\100L})
make: Bad modifier ":ts\x40g" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 150: Malformed conditional (${1 2 3:L:ts\x40g})
+make: "varmod-to-separator.mk" line 204: Malformed conditional (${1 2 3:L:ts\x40g})
make: Bad modifier ":tx" for variable "WORDS"
-make: "varmod-to-separator.mk" line 158: Malformed conditional (${WORDS:tx} != "anything")
+make: "varmod-to-separator.mk" line 214: Malformed conditional (${WORDS:tx})
+make: Bad modifier ":ts\X" for variable "WORDS"
+make: "varmod-to-separator.mk" line 223: Malformed conditional (${WORDS:ts\X})
make: Bad modifier ":t\X" for variable "WORDS"
-make: "varmod-to-separator.mk" line 165: Malformed conditional (${WORDS:t\X} != "anything")
+make: "varmod-to-separator.mk" line 232: Malformed conditional (${WORDS:t\X} != "anything")
+make: Bad modifier ":ts\69" for variable ""
+make: "varmod-to-separator.mk" line 249: Malformed conditional (${:Ua b:ts\69})
+make: "varmod-to-separator.mk" line 258: Invalid character number at "1F60E}"
+make: "varmod-to-separator.mk" line 258: Malformed conditional (${:Ua b:ts\x1F60E})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod-to-separator.mk b/contrib/bmake/unit-tests/varmod-to-separator.mk
index 08c6126ecc68..57a7bd84ec44 100644
--- a/contrib/bmake/unit-tests/varmod-to-separator.mk
+++ b/contrib/bmake/unit-tests/varmod-to-separator.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-to-separator.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: varmod-to-separator.mk,v 1.13 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :ts variable modifier, which joins the words of the variable
# using an arbitrary character as word separator.
@@ -39,7 +39,7 @@ WORDS= one two three four five six
# quote though, or other special characters like dollar or backslash.
#
# This example also demonstrates that the closing brace is not interpreted
-# as a separator, but as the closing delimiter of the whole variable
+# as a separator, but as the closing delimiter of the whole
# expression.
.if ${WORDS:tu:ts} != "ONETWOTHREEFOURFIVESIX"
. warning Colon as separator does not work.
@@ -80,6 +80,52 @@ WORDS= one two three four five six
. warning The :ts modifier followed by an :S modifier does not work.
.endif
+# After the modifier ':ts/', the expression value is a single word since all
+# spaces have been replaced with '/'. This single word does not start with
+# 'two', which makes the modifier ':S' a no-op.
+.if ${WORDS:ts/:S/^two/2/} != "one/two/three/four/five/six"
+. error
+.endif
+
+# After the :ts modifier, the whole string is interpreted as a single
+# word since all spaces have been replaced with x. Because of this single
+# word, only the first 'b' is replaced with 'B'.
+.if ${aa bb aa bb aa bb:L:tsx:S,b,B,} != "aaxBbxaaxbbxaaxbb"
+. error
+.endif
+
+# The :ts modifier also applies to word separators that are added
+# afterwards. First, the modifier ':tsx' joins the 3 words, then the modifier
+# ':S' replaces the 2 'b's with spaces. These spaces are part of the word,
+# so when the words are joined at the end of the modifier ':S', there is only
+# a single word, and the custom separator from the modifier ':tsx' has no
+# effect.
+.if ${a ababa c:L:tsx:S,b, ,g} != "axa a axc"
+. error
+.endif
+
+# Adding the modifier ':M*' at the end of the above chain splits the
+# expression value and then joins it again. At this point of splitting, the
+# newly added spaces are treated as word separators, resulting in 3 words.
+# When these 3 words are joined, the separator from the modifier ':tsx' is
+# used.
+.if ${a ababa c:L:tsx:S,b, ,g:M*} != "axaxaxaxc"
+. error
+.endif
+
+# Not all modifiers use the separator from the previous modifier ':ts' though.
+# The modifier ':@' always uses a space as word separator instead. This has
+# probably been an oversight during implementation. For consistency, the
+# result should rather be "axaxaxaxc", as in the previous example.
+.if ${a ababa c:L:tsx:S,b, ,g:@v@$v@} != "axa a axc"
+. error
+.endif
+
+# Adding a final :M* modifier applies the :ts separator again, though.
+.if ${a ababa c:L:tsx:S,b, ,g:@v@${v}@:M*} != "axaxaxaxc"
+. error
+.endif
+
# The separator can be \n, which is a newline.
.if ${WORDS:[1..3]:ts\n} != "one${.newline}two${.newline}three"
. warning The separator \n does not produce a newline.
@@ -104,6 +150,8 @@ WORDS= one two three four five six
# for an unsigned character though.
#
# Since 2020-11-01, these out-of-bounds values are rejected.
+# expect+2: Invalid character number at "400:tu}"
+# expect+1: Malformed conditional (${WORDS:[1..3]:ts\400:tu})
.if ${WORDS:[1..3]:ts\400:tu}
. warning The separator \400 is accepted even though it is out of bounds.
.else
@@ -118,6 +166,8 @@ WORDS= one two three four five six
# The hexadecimal number must be in the range of an unsigned char.
#
# Since 2020-11-01, these out-of-bounds values are rejected.
+# expect+2: Invalid character number at "100:tu}"
+# expect+1: Malformed conditional (${WORDS:[1..3]:ts\x100:tu})
.if ${WORDS:[1..3]:ts\x100:tu}
. warning The separator \x100 is accepted even though it is out of bounds.
.else
@@ -125,6 +175,7 @@ WORDS= one two three four five six
.endif
# Negative numbers are not allowed for the separator character.
+# expect+1: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
.if ${WORDS:[1..3]:ts\-300:tu}
. warning The separator \-300 is accepted even though it is negative.
.else
@@ -133,6 +184,7 @@ WORDS= one two three four five six
# The character number is interpreted as octal number by default.
# The digit '8' is not an octal digit though.
+# expect+1: Malformed conditional (${1 2 3:L:ts\8:tu})
.if ${1 2 3:L:ts\8:tu}
. warning The separator \8 is accepted even though it is not octal.
.else
@@ -140,6 +192,7 @@ WORDS= one two three four five six
.endif
# Trailing characters after the octal character number are rejected.
+# expect+1: Malformed conditional (${1 2 3:L:ts\100L})
.if ${1 2 3:L:ts\100L}
. warning The separator \100L is accepted even though it contains an 'L'.
.else
@@ -147,6 +200,7 @@ WORDS= one two three four five six
.endif
# Trailing characters after the hexadecimal character number are rejected.
+# expect+1: Malformed conditional (${1 2 3:L:ts\x40g})
.if ${1 2 3:L:ts\x40g}
. warning The separator \x40g is accepted even though it contains a 'g'.
.else
@@ -155,21 +209,54 @@ WORDS= one two three four five six
# In the :t modifier, the :t must be followed by any of A, l, s, u.
-.if ${WORDS:tx} != "anything"
-. info This line is not reached because of the malformed condition.
-. info If this line were reached, it would be visible in the -dcpv log.
+# expect: make: Bad modifier ":tx" for variable "WORDS"
+# expect+1: Malformed conditional (${WORDS:tx})
+.if ${WORDS:tx}
+. error
+.else
+. error
+.endif
+
+# The word separator can only be a single character.
+# expect: make: Bad modifier ":ts\X" for variable "WORDS"
+# expect+1: Malformed conditional (${WORDS:ts\X})
+.if ${WORDS:ts\X}
+. error
+.else
+. error
.endif
# After the backslash, only n, t, an octal number, or x and a hexadecimal
# number are allowed.
+# expect+1: Malformed conditional (${WORDS:t\X} != "anything")
.if ${WORDS:t\X} != "anything"
. info This line is not reached.
.endif
-# TODO: This modifier used to accept decimal numbers as well, in the form
-# ':ts\120'. When has this been changed to octal, and what happens now
-# for ':ts\90' ('Z' in decimal ASCII, undefined in octal)?
-# TODO: :ts\x1F600
+# Since 2003.07.23.18.06.46 and before 2016.03.07.20.20.35, the modifier ':ts'
+# interpreted an "octal escape" as decimal if the first digit was not '0'.
+.if ${:Ua b:ts\61} != "a1b" # decimal would have been "a=b"
+. error
+.endif
-all:
+# Since the character escape is always interpreted as octal, let's see what
+# happens for non-octal digits. From 2003.07.23.18.06.46 to
+# 2016.02.27.16.20.06, the result was '1E2', since 2016.03.07.20.20.35 make no
+# longer accepts this escape and complains.
+# expect: make: Bad modifier ":ts\69" for variable ""
+# expect+1: Malformed conditional (${:Ua b:ts\69})
+.if ${:Ua b:ts\69}
+. error
+.else
+. error
+.endif
+
+# Try whether bmake is Unicode-ready.
+# expect+2: Invalid character number at "1F60E}"
+# expect+1: Malformed conditional (${:Ua b:ts\x1F60E})
+.if ${:Ua b:ts\x1F60E} # U+1F60E "smiling face with sunglasses"
+. error
+.else
+. error
+.endif
diff --git a/contrib/bmake/unit-tests/varmod-undefined.mk b/contrib/bmake/unit-tests/varmod-undefined.mk
index e06fc73244ab..fd56ffd35e30 100644
--- a/contrib/bmake/unit-tests/varmod-undefined.mk
+++ b/contrib/bmake/unit-tests/varmod-undefined.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-undefined.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: varmod-undefined.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the :U variable modifier, which returns the given string
# if the variable is undefined.
@@ -19,17 +19,17 @@
.endif
# .endfor
-# The variable expressions in the text of the :U modifier may be arbitrarily
+# The expressions in the text of the :U modifier may be arbitrarily
# nested.
.if ${:U${:Unested}${${${:Udeeply}}}} != nested
. error
.endif
-# The nested variable expressions may contain braces, and these braces don't
+# The nested expressions may contain braces, and these braces don't
# need to match pairwise. In the following example, the :S modifier uses '{'
# as delimiter, which confuses both editors and humans because the opening
-# and # closing braces don't match anymore. It's syntactically valid though.
+# and closing braces don't match anymore. It's syntactically valid though.
# For more similar examples, see varmod-subst.mk, mod-subst-delimiter.
.if ${:U${:Uvalue:S{a{X{}} != vXlue
diff --git a/contrib/bmake/unit-tests/varmod-unique.mk b/contrib/bmake/unit-tests/varmod-unique.mk
index 04d04a575af1..7fef35b69211 100644
--- a/contrib/bmake/unit-tests/varmod-unique.mk
+++ b/contrib/bmake/unit-tests/varmod-unique.mk
@@ -1,47 +1,46 @@
-# $NetBSD: varmod-unique.mk,v 1.5 2021/05/30 20:26:41 rillig Exp $
+# $NetBSD: varmod-unique.mk,v 1.6 2021/12/05 22:37:58 rillig Exp $
#
# Tests for the :u variable modifier, which discards adjacent duplicate
# words.
-.if ${:U1 2 1:u} != "1 2 1"
-. warning The :u modifier only merges _adjacent_ duplicate words.
+.if ${1 2 1:L:u} != "1 2 1"
+. warning The modifier ':u' only merges _adjacent_ duplicate words.
.endif
-.if ${:U1 2 2 3:u} != "1 2 3"
-. warning The :u modifier must merge adjacent duplicate words.
+.if ${1 2 2 3:L:u} != "1 2 3"
+. warning The modifier ':u' must merge adjacent duplicate words.
.endif
-.if ${:U:u} != ""
-. warning The :u modifier must do nothing with an empty word list.
+.if ${:L:u} != ""
+. warning The modifier ':u' must do nothing with an empty word list.
.endif
-.if ${:U :u} != ""
+.if ${ :L:u} != ""
. warning The modifier ':u' must normalize the whitespace.
.endif
-.if ${:Uword:u} != "word"
-. warning The :u modifier must do nothing with a single-element word list.
+.if ${word:L:u} != "word"
+. warning The modifier ':u' must do nothing with a single-element word list.
.endif
-.if ${:U word :u} != "word"
+.if ${ word :L:u} != "word"
. warning The modifier ':u' must normalize the whitespace.
.endif
-.if ${:U1 1 1 1 1 1 1 1:u} != "1"
-. warning The :u modifier must merge _all_ adjacent duplicate words.
+.if ${1 1 1 1 1 1 1 1:L:u} != "1"
+. warning The modifier ':u' must merge _all_ adjacent duplicate words.
.endif
-.if ${:U 1 2 1 1 :u} != "1 2 1"
-. warning The :u modifier must normalize whitespace between the words.
+.if ${ 1 2 1 1 :L:u} != "1 2 1"
+. warning The modifier ':u' must normalize whitespace between the words.
.endif
-.if ${:U1 1 1 1 2:u} != "1 2"
+.if ${1 1 1 1 2:L:u} != "1 2"
. warning Duplicate words at the beginning must be merged.
.endif
-.if ${:U1 2 2 2 2:u} != "1 2"
+.if ${1 2 2 2 2:L:u} != "1 2"
. warning Duplicate words at the end must be merged.
.endif
all:
- @:;
diff --git a/contrib/bmake/unit-tests/varmod.exp b/contrib/bmake/unit-tests/varmod.exp
index e36c4ded9b47..9ba0cb1d278b 100644
--- a/contrib/bmake/unit-tests/varmod.exp
+++ b/contrib/bmake/unit-tests/varmod.exp
@@ -1,8 +1,8 @@
-make: "varmod.mk" line 42: To escape a dollar, use \$, not $$, at "$$:L} != """
-make: "varmod.mk" line 42: Invalid variable name ':', at "$:L} != """
-make: "varmod.mk" line 47: Dollar followed by nothing
-make: "varmod.mk" line 56: Missing delimiter ':' after modifier "P"
-make: "varmod.mk" line 57: Missing argument for ".error"
+make: "varmod.mk" line 101: To escape a dollar, use \$, not $$, at "$$:L} != """
+make: "varmod.mk" line 101: Invalid variable name ':', at "$:L} != """
+make: "varmod.mk" line 107: Dollar followed by nothing
+make: "varmod.mk" line 117: Missing delimiter ':' after modifier "P"
+make: "varmod.mk" line 119: Missing argument for ".error"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varmod.mk b/contrib/bmake/unit-tests/varmod.mk
index 21ddf9103251..45707ab9b886 100644
--- a/contrib/bmake/unit-tests/varmod.mk
+++ b/contrib/bmake/unit-tests/varmod.mk
@@ -1,11 +1,68 @@
-# $NetBSD: varmod.mk,v 1.5 2020/12/19 22:33:11 rillig Exp $
+# $NetBSD: varmod.mk,v 1.10 2024/02/03 00:20:23 sjg Exp $
#
# Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
+#
+# See also:
+# varparse-errors.mk
+
+# As of 2022-08-06, the possible behaviors during parsing are:
+#
+# * `strict`: the parsing style used by most modifiers:
+# * either uses `ParseModifierPart` or parses the modifier literal
+# * other modifiers may follow, separated by a ':'
+#
+# * `greedy`: calls `ParseModifierPart` with `ch->endc`; this means
+# that no further modifiers are parsed in that expression.
+#
+# * `no-colon`: after parsing this modifier, the following modifier
+# does not need to be separated by a colon.
+# Omitting this colon is bad style.
+#
+# * `individual`: parsing this modifier does not follow the common
+# pattern of calling `ParseModifierPart`.
+#
+# The SysV column says whether a parse error in the modifier falls back
+# trying the `:from=to` System V modifier.
+#
+# | **Operator** | **Behavior** | **Remarks** | **SysV** |
+# |--------------|--------------|--------------------|----------|
+# | `!` | no-colon | | no |
+# | `:=` | greedy | | yes |
+# | `?:` | greedy | | no |
+# | `@` | no-colon | | no |
+# | `C` | no-colon | | no |
+# | `D` | individual | custom parser | N/A |
+# | `E` | strict | | yes |
+# | `H` | strict | | yes |
+# | `L` | no-colon | | N/A |
+# | `M` | individual | custom parser | N/A |
+# | `N` | individual | custom parser | N/A |
+# | `O` | strict | only literal value | no |
+# | `P` | no-colon | | N/A |
+# | `Q` | strict | | yes |
+# | `R` | strict | | yes |
+# | `S` | no-colon | | N/A |
+# | `T` | strict | | N/A |
+# | `U` | individual | custom parser | N/A |
+# | `[` | strict | | no |
+# | `_` | individual | strcspn | yes |
+# | `gmtime` | strict | only literal value | yes |
+# | `hash` | strict | | N/A |
+# | `localtime` | strict | only literal value | yes |
+# | `q` | strict | | yes |
+# | `range` | strict | | N/A |
+# | `sh` | strict | | N/A |
+# | `t` | strict | | no |
+# | `u` | strict | | yes |
+# | `from=to` | greedy | SysV, fallback | N/A |
+
+# These tests assume
+.MAKE.SAVE_DOLLARS = yes
DOLLAR1= $$
DOLLAR2= ${:U\$}
-# To get a single '$' sign in the value of a variable expression, it has to
+# To get a single '$' sign in the value of an expression, it has to
# be written as '$$' in a literal variable value.
#
# See Var_Parse, where it calls Var_Subst.
@@ -39,21 +96,26 @@ DOLLAR2= ${:U\$}
# For compatibility, make does not print these error messages in normal mode.
# Should it?
.MAKEFLAGS: -dL
+# expect+2: To escape a dollar, use \$, not $$, at "$$:L} != """
+# expect+1: Invalid variable name ':', at "$:L} != """
.if ${$$:L} != ""
. error
.endif
# A '$' followed by nothing is an error as well.
+# expect+1: Dollar followed by nothing
.if ${:Uword:@word@${word}$@} != "word"
. error
.endif
# The variable modifier :P does not fall back to the SysV modifier.
# Therefore the modifier :P=RE generates a parse error.
-# XXX: The .error should not be reached since the variable expression is
+# XXX: The .error should not be reached since the expression is
# malformed, and this error should be propagated up to Cond_EvalLine.
VAR= STOP
+# expect+1: Missing delimiter ':' after modifier "P"
.if ${VAR:P=RE} != "STORE"
+# expect+1: Missing argument for ".error"
. error
.endif
diff --git a/contrib/bmake/unit-tests/varname-dollar.exp b/contrib/bmake/unit-tests/varname-dollar.exp
index c880e82f0170..4f7c2ebbdf12 100644
--- a/contrib/bmake/unit-tests/varname-dollar.exp
+++ b/contrib/bmake/unit-tests/varname-dollar.exp
@@ -1,5 +1,5 @@
-make: "varname-dollar.mk" line 16: dollar is $.
-make: "varname-dollar.mk" line 17: dollar in braces is .
-make: "varname-dollar.mk" line 25: dollar is $.
-make: "varname-dollar.mk" line 26: dollar in braces is dollar.
+make: "varname-dollar.mk" line 17: dollar is $.
+make: "varname-dollar.mk" line 19: dollar in braces is .
+make: "varname-dollar.mk" line 28: dollar is $.
+make: "varname-dollar.mk" line 30: dollar in braces is dollar.
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dollar.mk b/contrib/bmake/unit-tests/varname-dollar.mk
index d1db9f833306..e60c9dd43e8f 100644
--- a/contrib/bmake/unit-tests/varname-dollar.mk
+++ b/contrib/bmake/unit-tests/varname-dollar.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varname-dollar.mk,v 1.3 2020/08/19 05:40:06 rillig Exp $
+# $NetBSD: varname-dollar.mk,v 1.4 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the expression "$$", which looks as if it referred to a variable,
# but simply expands to a single '$' sign.
@@ -13,7 +13,9 @@ DOLLAR= $$
# At this point, the variable '$' is not defined. Therefore the second line
# returns an empty string.
+# expect+1: dollar is $.
.info dollar is $$.
+# expect+1: dollar in braces is .
.info dollar in braces is ${${DOLLAR}}.
# Now overwrite the '$' variable to see whether '$$' really expands to that
@@ -22,7 +24,9 @@ ${DOLLAR}= dollar
# At this point, the variable '$' is defined, therefore its value is printed
# in the second .info directive.
+# expect+1: dollar is $.
.info dollar is $$.
+# expect+1: dollar in braces is dollar.
.info dollar in braces is ${${DOLLAR}}.
all:
diff --git a/contrib/bmake/unit-tests/varname-dot-make-jobs.exp b/contrib/bmake/unit-tests/varname-dot-make-jobs.exp
index 39a9383953dd..a899c5d38418 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-jobs.exp
+++ b/contrib/bmake/unit-tests/varname-dot-make-jobs.exp
@@ -1 +1,8 @@
+undefined
+1
+--- echo ---
+5
+--- echo ---
+20
+1
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-make-jobs.mk b/contrib/bmake/unit-tests/varname-dot-make-jobs.mk
index 1e99b3d28ea8..5ed62c180eed 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-jobs.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-jobs.mk
@@ -1,8 +1,43 @@
-# $NetBSD: varname-dot-make-jobs.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-jobs.mk,v 1.5 2023/09/10 16:25:32 sjg Exp $
#
-# Tests for the special .MAKE.JOBS variable.
+# Tests for the special .MAKE.JOBS variable, which is defined in jobs mode
+# only. There it contains the number of jobs that may run in parallel.
-# TODO: Implementation
+.MAIN: all
+
+echo: .PHONY
+ @echo ${.MAKE.JOBS:Uundefined}
all:
- @:;
+ @${MAKE} -r -f ${MAKEFILE} echo
+ @${MAKE} -r -f ${MAKEFILE} echo -j1
+ @${MAKE} -r -f ${MAKEFILE} echo -j5
+ @${MAKE} -r -f ${MAKEFILE} echo -j20
+ @${MAKE} -r -f ${MAKEFILE} echo -j00000000000000000000000000000001
+
+.if !make(echo) && ${.MAKE.JOBS.C} == "yes"
+# These results will not be static, we need NCPU
+# to compute expected results.
+all: jC
+
+NCPU!= ${MAKE} -r -f /dev/null -jC -V .MAKE.JOBS
+
+# If -j arg is floating point or ends in C;
+# .MAKE.JOBS is a multiple of _SC_NPROCESSORS_ONLN
+# No news is good news here.
+jCvals ?= 1 1.2 2
+
+jC:
+ @for j in ${jCvals}; do \
+ e=`echo "${NCPU} * $$j" | bc | sed 's/\.[0-9]*//'`; \
+ g=`${MAKE} -r -f /dev/null -V .MAKE.JOBS -j$${j}C`; \
+ test $$g = $$e || echo "$$g != $$e"; \
+ done
+
+.endif
+
+# expect: undefined
+# expect: 1
+# expect: 5
+# expect: 20
+# expect: 1
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp
index 39a9383953dd..045d26dc080e 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.exp
@@ -1 +1,11 @@
+Initialize check-ignore.meta
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
+Use .MAKE.META.IGNORE_FILTER - check-ignore is up to date
+`check-ignore' is up to date.
+Skipping meta for .END: .SPECIAL
+Skip .MAKE.META.IGNORE_FILTER - check-ignore is out of date
+<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target...
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk
index c41aec4acdf8..0adf6a202857 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_filter.mk
@@ -1,8 +1,5 @@
-# $NetBSD: varname-dot-make-meta-ignore_filter.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-meta-ignore_filter.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $
#
# Tests for the special .MAKE.META.IGNORE_FILTER variable.
-# TODO: Implementation
-
-all:
- @:;
+.include "meta-ignore.inc"
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp
index 39a9383953dd..161d09c2eff4 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.exp
@@ -1 +1,11 @@
+Initialize check-ignore.meta
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
+Use .MAKE.META.IGNORE_PATHS - check-ignore is up to date
+`check-ignore' is up to date.
+Skipping meta for .END: .SPECIAL
+Skip .MAKE.META.IGNORE_PATHS - check-ignore is out of date
+<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target...
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk
index 4ae34f51608b..2c58849af0be 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_paths.mk
@@ -1,8 +1,5 @@
-# $NetBSD: varname-dot-make-meta-ignore_paths.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-meta-ignore_paths.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $
#
# Tests for the special .MAKE.META.IGNORE_PATHS variable.
-# TODO: Implementation
-
-all:
- @:;
+.include "meta-ignore.inc"
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp
index 39a9383953dd..ebc1c0c6261c 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.exp
@@ -1 +1,11 @@
+Initialize check-ignore.meta
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
+Use .MAKE.META.IGNORE_PATTERNS - check-ignore is up to date
+`check-ignore' is up to date.
+Skipping meta for .END: .SPECIAL
+Skip .MAKE.META.IGNORE_PATTERNS - check-ignore is out of date
+<tmpdir>/obj/check-ignore.meta: <line>: file '<tmpdir>/ignore/check' is newer than the target...
+Building <tmpdir>/obj/check-ignore
+Skipping meta for .END: .SPECIAL
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk
index ea9fc49f1718..d3d6e065857d 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-meta-ignore_patterns.mk
@@ -1,8 +1,5 @@
-# $NetBSD: varname-dot-make-meta-ignore_patterns.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-meta-ignore_patterns.mk,v 1.3 2023/02/23 05:20:45 sjg Exp $
#
# Tests for the special .MAKE.META.IGNORE_PATTERNS variable.
-# TODO: Implementation
-
-all:
- @:;
+.include "meta-ignore.inc"
diff --git a/contrib/bmake/unit-tests/varname-dot-make-mode.exp b/contrib/bmake/unit-tests/varname-dot-make-mode.exp
index 39a9383953dd..fa033e718b0c 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-mode.exp
+++ b/contrib/bmake/unit-tests/varname-dot-make-mode.exp
@@ -1 +1,31 @@
+randomize compat mode:
+: Making a
+: Making a
+: Making a
+: Making b
+: Making b
+: Making b
+: Making c
+: Making c
+: Making c
+randomize jobs mode (-j1):
+: Making a
+: Making a
+: Making a
+: Making b
+: Making b
+: Making b
+: Making c
+: Making c
+: Making c
+randomize jobs mode (-j5):
+: Making a
+: Making a
+: Making a
+: Making b
+: Making b
+: Making b
+: Making c
+: Making c
+: Making c
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-make-mode.mk b/contrib/bmake/unit-tests/varname-dot-make-mode.mk
index ee75a54ebd74..169aa17cdc36 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-mode.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-mode.mk
@@ -1,8 +1,41 @@
-# $NetBSD: varname-dot-make-mode.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-mode.mk,v 1.3 2022/05/07 17:49:47 rillig Exp $
#
# Tests for the special .MAKE.MODE variable.
-# TODO: Implementation
+# TODO: test .MAKE.MODE "meta", or see meta mode tests.
+# TODO: test .MAKE.MODE "compat"
-all:
- @:;
+
+# See Makefile, POSTPROC for the postprocessing that takes place.
+# See the .rawout file for the raw output before stripping the digits.
+all: .PHONY make-mode-randomize-targets
+
+
+# By adding the word "randomize-targets" to the variable .MAKE.MODE, the
+# targets are not made in declaration order, but rather in random order. This
+# mode helps to find undeclared dependencies between files.
+#
+# History
+# Added on 2022-05-07.
+#
+# See also
+# https://gnats.netbsd.org/45226
+make-mode-randomize-targets: .PHONY
+ @echo "randomize compat mode:"
+ @${MAKE} -r -f ${MAKEFILE} randomize-targets
+
+ @echo "randomize jobs mode (-j1):"
+ @${MAKE} -r -f ${MAKEFILE} -j1 randomize-targets
+
+ @echo "randomize jobs mode (-j5):"
+ @${MAKE} -r -f ${MAKEFILE} -j5 randomize-targets | grep '^:'
+
+.if make(randomize-targets)
+randomize-targets: .WAIT a1 a2 a3 .WAIT b1 b2 b3 .WAIT c1 c2 c3 .WAIT
+a1 a2 a3 b1 b2 b3 c1 c2 c3:
+ : Making ${.TARGET}
+
+# .MAKE.MODE is evaluated after parsing all files, so it suffices to switch
+# the mode after defining the targets.
+.MAKE.MODE+= randomize-targets
+.endif
diff --git a/contrib/bmake/unit-tests/varname-dot-make-pid.mk b/contrib/bmake/unit-tests/varname-dot-make-pid.mk
index bea114d33547..d7ef5bfd5c44 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-pid.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-pid.mk
@@ -1,8 +1,16 @@
-# $NetBSD: varname-dot-make-pid.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-pid.mk,v 1.3 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the special .MAKE.PID variable.
+# Tests for the special .MAKE.PID variable, which contains the process ID of
+# the make process itself.
-# TODO: Implementation
+# The process ID must be a positive integer.
+.if ${.MAKE.PID:C,[0-9],,g} != ""
+. error
+.elif !(${.MAKE.PID} > 0)
+. error
+.endif
-all:
- @:;
+# Ensure that the process exists.
+_!= kill -0 ${.MAKE.PID}
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varname-dot-make-ppid.mk b/contrib/bmake/unit-tests/varname-dot-make-ppid.mk
index c9471542ca35..91f13fd2feec 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-ppid.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-ppid.mk
@@ -1,8 +1,23 @@
-# $NetBSD: varname-dot-make-ppid.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-ppid.mk,v 1.3 2022/01/23 21:48:59 rillig Exp $
#
-# Tests for the special .MAKE.PPID variable.
+# Tests for the special .MAKE.PPID variable, which contains the process ID of
+# make's parent process.
-# TODO: Implementation
+# The parent process ID must be a positive integer.
+.if ${.MAKE.PPID:C,[0-9],,g} != ""
+. error
+.elif !(${.MAKE.PPID} > 0)
+. error
+.endif
-all:
- @:;
+# Ensure that the process exists.
+_!= kill -0 ${.MAKE.PPID}
+
+# The parent process ID must be different from the process ID. If they were
+# the same, make would run as process 1, which is not a good idea because make
+# is not prepared to clean up after other processes.
+.if ${.MAKE.PPID} == ${.MAKE.PID}
+. error
+.endif
+
+all: .PHONY
diff --git a/contrib/bmake/unit-tests/varname-dot-make-save_dollars.mk b/contrib/bmake/unit-tests/varname-dot-make-save_dollars.mk
index 97f37a646d2d..31f228c220b2 100644
--- a/contrib/bmake/unit-tests/varname-dot-make-save_dollars.mk
+++ b/contrib/bmake/unit-tests/varname-dot-make-save_dollars.mk
@@ -1,8 +1,130 @@
-# $NetBSD: varname-dot-make-save_dollars.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-save_dollars.mk,v 1.7 2021/12/03 18:43:52 rillig Exp $
#
-# Tests for the special .MAKE.SAVE_DOLLARS variable.
+# Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether
+# the assignment operator ':=' converts '$$' to a single '$' or keeps it
+# as-is.
+#
+# See also:
+# var-op-expand.mk for ':=' in general
+# varmisc.mk for parsing the boolean values
+
+# Initially, the variable .MAKE.SAVE_DOLLARS is undefined. At this point the
+# behavior of the assignment operator ':=' depends. NetBSD's usr.bin/make
+# preserves the '$$' as-is, while the bmake distribution replaces '$$' with
+# '$'.
+.if ${.MAKE.SAVE_DOLLARS:Uundefined} != "undefined"
+. error
+.endif
+
+
+# When dollars are preserved, this setting not only applies to literal
+# dollars, but also to those that come indirectly from other expressions.
+DOLLARS= $$$$$$$$
+.MAKE.SAVE_DOLLARS= yes
+VAR:= ${DOLLARS}
+# The reduction from 8 '$' to 4 '$' happens when ${VAR} is evaluated in the
+# condition; .MAKE.SAVE_DOLLARS only applies at the moment where the
+# assignment is performed using ':='.
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+# When dollars are preserved, this setting not only applies to literal
+# dollars, but also to those that come indirectly from other expressions.
+DOLLARS= $$$$$$$$
+.MAKE.SAVE_DOLLARS= no
+VAR:= ${DOLLARS}
+.if ${VAR} != "\$\$"
+. error
+.endif
+
+# The 'yes' preserves the dollars from the literal.
+.MAKE.SAVE_DOLLARS= yes
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+# The 'no' converts each '$$' to '$'.
+.MAKE.SAVE_DOLLARS= no
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$"
+. error
+.endif
+
+# It's even possible to change the dollar interpretation in the middle of
+# evaluating an expression, but there is no practical need for it.
+.MAKE.SAVE_DOLLARS= no
+VAR:= $$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
+.if ${VAR} != "\$--\$\$"
+. error
+.endif
+
+# The '$' from the ':U' expressions do not appear as literal '$$' to the
+# parser (no matter whether directly or indirectly), they only appear as '$$'
+# in the value of an expression, therefore .MAKE.SAVE_DOLLARS doesn't apply
+# here.
+.MAKE.SAVE_DOLLARS= no
+VAR:= ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
+.if ${VAR} != "\$\$--\$\$"
+. error
+.endif
+
+# Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
+# does not restore the default behavior.
+.MAKE.SAVE_DOLLARS= no
+.undef .MAKE.SAVE_DOLLARS
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$"
+. error
+.endif
+
+# Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
+# does not restore the default behavior.
+.MAKE.SAVE_DOLLARS= yes
+.undef .MAKE.SAVE_DOLLARS
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+# The variable '.MAKE.SAVE_DOLLARS' not only affects literal '$$' on the
+# right-hand side of the assignment operator ':=', it also affects dollars
+# in indirect expressions.
+#
+# In this example, it affects the command in CMD itself, not the result of
+# running that command.
+.MAKE.SAVE_DOLLARS= no
+CMD= echo '$$$$$$$$'
+VAR:= ${CMD:sh}
+.if ${VAR} != "\$\$"
+. error
+.endif
+
+.MAKE.SAVE_DOLLARS= yes
+CMD= echo '$$$$$$$$'
+VAR:= ${CMD:sh}
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+
+# In the modifier ':@var@body@', .MAKE.SAVE_DOLLARS does not affect the body.
+# In both cases, each '$$' is replaced with a single '$', no matter whether
+# directly or indirectly via another expression.
+.MAKE.SAVE_DOLLARS= no
+DOLLARS= $$$$$$$$
+VAR:= ${word:L:@word@$$$$$$$$-${DOLLARS}@}
+.if ${VAR} != "\$\$-\$\$"
+. error
+.endif
+
+.MAKE.SAVE_DOLLARS= yes
+DOLLARS= $$$$$$$$
+VAR:= ${word:L:@word@$$$$$$$$-${DOLLARS}@}
+.if ${VAR} != "\$\$-\$\$"
+. error
+.endif
-# TODO: Implementation
all:
- @:;
diff --git a/contrib/bmake/unit-tests/varname-dot-makeflags.exp b/contrib/bmake/unit-tests/varname-dot-makeflags.exp
index dbf96469f86b..8004ab40a363 100644
--- a/contrib/bmake/unit-tests/varname-dot-makeflags.exp
+++ b/contrib/bmake/unit-tests/varname-dot-makeflags.exp
@@ -1,3 +1,10 @@
-echo "$MAKEFLAGS"
- -r -k -d 00000 -D VARNAME WITH SPACES
+make: "varname-dot-makeflags.mk" line 11: MAKEFLAGS=<undefined>
+make: "varname-dot-makeflags.mk" line 13: .MAKEFLAGS=< -r -k>
+make: "varname-dot-makeflags.mk" line 15: .MAKEOVERRIDES=<>
+make: "varname-dot-makeflags.mk" line 21: MAKEFLAGS=<undefined>
+make: "varname-dot-makeflags.mk" line 23: .MAKEFLAGS=< -r -k -D VARNAME -r>
+make: "varname-dot-makeflags.mk" line 25: .MAKEOVERRIDES=< VAR>
+runtime: MAKEFLAGS=< -r -k -D VARNAME -r VAR=value>
+runtime: .MAKEFLAGS=< -r -k -D VARNAME -r>
+runtime: .MAKEOVERRIDES=< VAR>
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-makeflags.mk b/contrib/bmake/unit-tests/varname-dot-makeflags.mk
index 10d1903022cb..ffb09decb70e 100644
--- a/contrib/bmake/unit-tests/varname-dot-makeflags.mk
+++ b/contrib/bmake/unit-tests/varname-dot-makeflags.mk
@@ -1,15 +1,39 @@
-# $NetBSD: varname-dot-makeflags.mk,v 1.1 2020/12/01 20:37:30 rillig Exp $
+# $NetBSD: varname-dot-makeflags.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
#
# Tests for the special .MAKEFLAGS variable, which collects almost all
# command line arguments and passes them on to any child processes via
# the environment variable MAKEFLAGS (without leading '.').
+#
+# See also:
+# varname-dot-makeoverrides.mk
+
+# expect+1: MAKEFLAGS=<undefined>
+.info MAKEFLAGS=<${MAKEFLAGS:Uundefined}>
+# expect+1: .MAKEFLAGS=< -r -k>
+.info .MAKEFLAGS=<${.MAKEFLAGS}>
+# expect+1: .MAKEOVERRIDES=<>
+.info .MAKEOVERRIDES=<${.MAKEOVERRIDES:Uundefined}>
+
+# Append an option with argument, a plain option and a variable assignment.
+.MAKEFLAGS: -DVARNAME -r VAR=value
+
+# expect+1: MAKEFLAGS=<undefined>
+.info MAKEFLAGS=<${MAKEFLAGS:Uundefined}>
+# expect+1: .MAKEFLAGS=< -r -k -D VARNAME -r>
+.info .MAKEFLAGS=<${.MAKEFLAGS}>
+# expect+1: .MAKEOVERRIDES=< VAR>
+.info .MAKEOVERRIDES=<${.MAKEOVERRIDES}>
-# When options are parsed, the option and its argument are appended as
-# separate words to .MAKEFLAGS. Special characters in the option argument
-# are not quoted though. It seems to have not been necessary at least from
-# 1993 until 2020.
-.MAKEFLAGS: -d00000 -D"VARNAME WITH SPACES"
+# The environment variable 'MAKEFLAGS' is not available to child processes
+# when parsing the makefiles. This is different from exported variables,
+# which are already available during parse time.
+.if ${:!echo "\${MAKEFLAGS-undef}"!} != "undef"
+. error
+.endif
-all:
- echo "$$MAKEFLAGS"
- @:;
+# After parsing, the environment variable 'MAKEFLAGS' is set based on the
+# special variables '.MAKEFLAGS' and '.MAKEOVERRIDES'.
+runtime:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @echo '$@: .MAKEFLAGS=<'${.MAKEFLAGS:Q}'>'
+ @echo '$@: .MAKEOVERRIDES=<'${.MAKEOVERRIDES:Q}'>'
diff --git a/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp b/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp
index 39a9383953dd..78c0296f8d76 100644
--- a/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp
+++ b/contrib/bmake/unit-tests/varname-dot-makeoverrides.exp
@@ -1 +1,8 @@
+all: overrides=<>
+make -f varname-dot-makeoverrides.mk stage_1 VAR=value
+stage_1: overrides=< VAR>
+make -f varname-dot-makeoverrides.mk stage_2
+stage_2: overrides=< VAR>
+make -f varname-dot-makeoverrides.mk stage_3
+stage_3: overrides=< VAR>
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk b/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk
index a897f4667175..f3f3897f8aa4 100644
--- a/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk
+++ b/contrib/bmake/unit-tests/varname-dot-makeoverrides.mk
@@ -1,8 +1,23 @@
-# $NetBSD: varname-dot-makeoverrides.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-makeoverrides.mk,v 1.5 2023/02/25 06:54:08 rillig Exp $
#
-# Tests for the special .MAKE.MAKEOVERRIDES variable.
-
-# TODO: Implementation
+# Tests for the special .MAKEOVERRIDES variable, which lists the names of the
+# variables that are passed on to child processes via the MAKEFLAGS
+# environment variable.
+#
+# See also:
+# varname-dot-makeflags.mk
all:
- @:;
+ @echo '$@: overrides=<'${.MAKEOVERRIDES:Uundefined:Q}'>'
+ ${MAKE} -f ${MAKEFILE} stage_1 VAR=value
+
+stage_1:
+ @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>'
+ ${MAKE} -f ${MAKEFILE} stage_2
+
+stage_2:
+ @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>'
+ ${MAKE} -f ${MAKEFILE} stage_3
+
+stage_3:
+ @echo '$@: overrides=<'${.MAKEOVERRIDES:Q}'>'
diff --git a/contrib/bmake/unit-tests/varname-dot-newline.exp b/contrib/bmake/unit-tests/varname-dot-newline.exp
index 13943539bf3b..684fb5799752 100644
--- a/contrib/bmake/unit-tests/varname-dot-newline.exp
+++ b/contrib/bmake/unit-tests/varname-dot-newline.exp
@@ -1,4 +1,5 @@
-make: "varname-dot-newline.mk" line 16: The .newline variable can be overwritten. Just don't do that.
first
second
+backslash newline: <\
+>
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-newline.mk b/contrib/bmake/unit-tests/varname-dot-newline.mk
index 0565d244f298..1940dc2a990d 100644
--- a/contrib/bmake/unit-tests/varname-dot-newline.mk
+++ b/contrib/bmake/unit-tests/varname-dot-newline.mk
@@ -1,23 +1,31 @@
-# $NetBSD: varname-dot-newline.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varname-dot-newline.mk,v 1.6 2023/01/26 20:48:18 sjg Exp $
#
-# Tests for the special .newline variable.
+# Tests for the special .newline variable, which contains a single newline
+# character (U+000A).
+
+
+# https://austingroupbugs.net/view.php?id=1549 proposes:
+# > After all macro expansion is complete, when an escaped <newline> is
+# > found in a command line in a makefile, the command line that is executed
+# > shall contain the <backslash>, the <newline>, and the next line, except
+# > that the first character of the next line shall not be included if it is
+# > a <tab>.
#
-# Contrary to the special variable named "" that is used in expressions like
-# ${:Usome-value}, the variable ".newline" is not protected against
-# modification. Nobody exploits that though.
+# The above quote assumes that each resulting <newline> character has a "next
+# line", but that's not how the .newline variable works.
+BACKSLASH_NEWLINE:= \${.newline}
+
+
+# Check that .newline is read-only
NEWLINE:= ${.newline}
.newline= overwritten
-.if ${.newline} == ${NEWLINE}
-. info The .newline variable cannot be overwritten. Good.
-.else
-. info The .newline variable can be overwritten. Just don't do that.
+.if ${.newline} != ${NEWLINE}
+. error The .newline variable can be overwritten. It should be read-only.
.endif
-# Restore the original value.
-.newline= ${NEWLINE}
-
all:
@echo 'first${.newline}second'
+ @echo 'backslash newline: <${BACKSLASH_NEWLINE}>'
diff --git a/contrib/bmake/unit-tests/varname-dot-parsedir.exp b/contrib/bmake/unit-tests/varname-dot-parsedir.exp
index c0bc56f41d6e..4ac953c813cd 100644
--- a/contrib/bmake/unit-tests/varname-dot-parsedir.exp
+++ b/contrib/bmake/unit-tests/varname-dot-parsedir.exp
@@ -1,5 +1,5 @@
-make: "varname-dot-parsedir.mk" line 28: At this point, .PARSEDIR is undefined.
-make: "<normalized>" line 34: The location can be faked in some cases.
-make: "varname-dot-parsedir.mk" line 38: The location is no longer fake.
+make: "varname-dot-parsedir.mk" line 37: At this point, .PARSEDIR is undefined.
+make: "<normalized>" line 43: The location can be faked in some cases.
+make: "varname-dot-parsedir.mk" line 48: The location is no longer fake.
At run time, .PARSEDIR is undefined.
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-parsedir.mk b/contrib/bmake/unit-tests/varname-dot-parsedir.mk
index 7c74419ddd10..525fdbd5636f 100644
--- a/contrib/bmake/unit-tests/varname-dot-parsedir.mk
+++ b/contrib/bmake/unit-tests/varname-dot-parsedir.mk
@@ -1,7 +1,15 @@
-# $NetBSD: varname-dot-parsedir.mk,v 1.6 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: varname-dot-parsedir.mk,v 1.8 2023/06/21 07:30:50 rillig Exp $
#
# Tests for the special .PARSEDIR variable, which contains the directory part
# of the file that is currently parsed.
+#
+# See also
+# varname-dot-includedfromdir.mk
+# varname-dot-includedfromfile.mk
+# varname-dot-parsefile.mk
+#
+# History
+# .PARSEDIR and .PARSEFILE were added on 1999-08-09.
# The .PARSEDIR may be absolute or relative, therefore there is not much that
# can be tested here.
@@ -25,6 +33,7 @@
#
# The .rawout file contains the full path to the current directory.
# In the .out file, it is filtered out.
+# expect+1: At this point, .PARSEDIR is undefined.
.info At this point, .PARSEDIR is undefined.
# There is absolutely no point in faking the location of the file that is
@@ -35,6 +44,7 @@
# After including another file, .PARSEDIR is reset.
.include "/dev/null"
+# expect+1: The location is no longer fake.
.info The location is no longer fake.
all:
diff --git a/contrib/bmake/unit-tests/varname-dot-parsefile.exp b/contrib/bmake/unit-tests/varname-dot-parsefile.exp
index b61f01c01ab7..651666ebcf24 100644
--- a/contrib/bmake/unit-tests/varname-dot-parsefile.exp
+++ b/contrib/bmake/unit-tests/varname-dot-parsefile.exp
@@ -1,5 +1,5 @@
-make: "varname-dot-parsefile.mk" line 23: At this point, .PARSEFILE is undefined.
-make: "<normalized>" line 29: The location can be faked in some cases.
-make: "varname-dot-parsefile.mk" line 33: The location is no longer fake.
+make: "varname-dot-parsefile.mk" line 32: At this point, .PARSEFILE is undefined.
+make: "<normalized>" line 38: The location can be faked in some cases.
+make: "varname-dot-parsefile.mk" line 43: The location is no longer fake.
At run time, .PARSEFILE is undefined.
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-parsefile.mk b/contrib/bmake/unit-tests/varname-dot-parsefile.mk
index 17b48a5f77ec..0a6ed3c378e0 100644
--- a/contrib/bmake/unit-tests/varname-dot-parsefile.mk
+++ b/contrib/bmake/unit-tests/varname-dot-parsefile.mk
@@ -1,7 +1,15 @@
-# $NetBSD: varname-dot-parsefile.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: varname-dot-parsefile.mk,v 1.7 2023/06/21 07:30:50 rillig Exp $
#
# Tests for the special .PARSEFILE variable, which contains the basename part
# of the file that is currently parsed.
+#
+# See also
+# varname-dot-includedfromdir.mk
+# varname-dot-includedfromfile.mk
+# varname-dot-parsedir.mk
+#
+# History
+# .PARSEDIR and .PARSEFILE were added on 1999-08-09.
.if ${.PARSEFILE} != "varname-dot-parsefile.mk"
. error
@@ -20,6 +28,7 @@
# The variable .PARSEFILE is indirectly used by the .info directive,
# via PrintLocation.
+# expect+1: At this point, .PARSEFILE is undefined.
.info At this point, .PARSEFILE is undefined.
# There is absolutely no point in faking the location of the file that is
@@ -30,6 +39,7 @@
# After including another file, .PARSEFILE is reset.
.include "/dev/null"
+# expect+1: The location is no longer fake.
.info The location is no longer fake.
all:
diff --git a/contrib/bmake/unit-tests/varname-dot-shell.exp b/contrib/bmake/unit-tests/varname-dot-shell.exp
index bfbcfc960182..22c2afe218a9 100755
--- a/contrib/bmake/unit-tests/varname-dot-shell.exp
+++ b/contrib/bmake/unit-tests/varname-dot-shell.exp
@@ -1,31 +1,31 @@
-ParseReadLine (10): 'ORIG_SHELL:= ${.SHELL}'
-Global: ORIG_SHELL =
+Parsing line 10: ORIG_SHELL:= ${.SHELL}
+Global: ORIG_SHELL = # (empty)
Var_Parse: ${.SHELL} (eval-keep-dollar-and-undefined)
-Global:delete .SHELL (not found)
+Global: ignoring delete '.SHELL' as it is not found
Command: .SHELL = (details omitted)
Global: ORIG_SHELL = (details omitted)
-ParseReadLine (12): '.SHELL= overwritten'
-Global: .SHELL = overwritten
+Parsing line 12: .SHELL= overwritten
+Global: ignoring '.SHELL = overwritten' due to a command line variable of the same name
CondParser_Eval: ${.SHELL} != ${ORIG_SHELL}
Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined)
Var_Parse: ${ORIG_SHELL} (eval-defined)
-lhs = "(details omitted)", rhs = "(details omitted)", op = !=
-ParseReadLine (19): '.MAKEFLAGS: .SHELL+=appended'
+Comparing "(details omitted)" != "(details omitted)"
+Parsing line 19: .MAKEFLAGS: .SHELL+=appended
ParseDependency(.MAKEFLAGS: .SHELL+=appended)
-Ignoring append to .SHELL since it is read-only
+Command: ignoring '.SHELL += appended' as it is read-only
CondParser_Eval: ${.SHELL} != ${ORIG_SHELL}
Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined)
Var_Parse: ${ORIG_SHELL} (eval-defined)
-lhs = "(details omitted)", rhs = "(details omitted)", op = !=
-ParseReadLine (27): '.undef .SHELL'
-Global:delete .SHELL
-ParseReadLine (28): '.SHELL= newly overwritten'
-Global: .SHELL = newly overwritten
+Comparing "(details omitted)" != "(details omitted)"
+Parsing line 27: .undef .SHELL
+Global: ignoring delete '.SHELL' as it is not found
+Parsing line 28: .SHELL= newly overwritten
+Global: ignoring '.SHELL = newly overwritten' due to a command line variable of the same name
CondParser_Eval: ${.SHELL} != ${ORIG_SHELL}
Var_Parse: ${.SHELL} != ${ORIG_SHELL} (eval-defined)
Var_Parse: ${ORIG_SHELL} (eval-defined)
-lhs = "(details omitted)", rhs = "(details omitted)", op = !=
-ParseReadLine (33): '.MAKEFLAGS: -d0'
+Comparing "(details omitted)" != "(details omitted)"
+Parsing line 33: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d cpv -d
Global: .MAKEFLAGS = -r -k -d cpv -d 0
diff --git a/contrib/bmake/unit-tests/varname-dot-suffixes.exp b/contrib/bmake/unit-tests/varname-dot-suffixes.exp
new file mode 100644
index 000000000000..230ba36d56ed
--- /dev/null
+++ b/contrib/bmake/unit-tests/varname-dot-suffixes.exp
@@ -0,0 +1,39 @@
+Global: ignoring delete '.SUFFIXES' as it is not found
+Global: .MAKEFLAGS = -r -k -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0
+Global: ignoring '.SUFFIXES = set' as it is read-only
+Global: ignoring '.SUFFIXES = append' as it is read-only
+Global: _ = # (empty)
+Var_Parse: ${.SUFFIXES::=assign} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${.SUFFIXES::...} on value ".c .o .1 .err .tar.gz" (eval-keep-dollar-and-undefined, regular)
+Modifier part: "assign"
+Global: ignoring '.SUFFIXES = assign' as it is read-only
+Result of ${.SUFFIXES::=assign} is "" (eval-keep-dollar-and-undefined, regular)
+Global: _ = # (empty)
+Var_Parse: ${preserve:L:_=.SUFFIXES} (eval-keep-dollar-and-undefined)
+Evaluating modifier ${preserve:L} on value "" (eval-keep-dollar-and-undefined, undefined)
+Result of ${preserve:L} is "preserve" (eval-keep-dollar-and-undefined, defined)
+Evaluating modifier ${preserve:_...} on value "preserve" (eval-keep-dollar-and-undefined, defined)
+Global: ignoring '.SUFFIXES = preserve' as it is read-only
+Result of ${preserve:_=.SUFFIXES} is "preserve" (eval-keep-dollar-and-undefined, defined)
+Global: _ = preserve
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0
+Var_Parse: ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" (eval-defined)
+Evaluating modifier ${1 2:L} on value "" (eval-defined, undefined)
+Result of ${1 2:L} is "1 2" (eval-defined, defined)
+Evaluating modifier ${1 2:@...} on value "1 2" (eval-defined, defined)
+Modifier part: ".SUFFIXES"
+Modifier part: "${.SUFFIXES}"
+ModifyWords: split "1 2" into 2 words
+Command: ignoring '.SUFFIXES = 1' as it is read-only
+Var_Parse: ${.SUFFIXES} (eval-defined)
+ModifyWord_Loop: expand "${.SUFFIXES}" to ".c .o .1 .err .tar.gz"
+Command: ignoring '.SUFFIXES = 2' as it is read-only
+Var_Parse: ${.SUFFIXES} (eval-defined)
+ModifyWord_Loop: expand "${.SUFFIXES}" to ".c .o .1 .err .tar.gz"
+Command: ignoring delete '.SUFFIXES' as it is not found
+Result of ${1 2:@.SUFFIXES@${.SUFFIXES}@} is ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" (eval-defined, defined)
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d
+Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d 0
+exit status 0
diff --git a/contrib/bmake/unit-tests/varname-dot-suffixes.mk b/contrib/bmake/unit-tests/varname-dot-suffixes.mk
new file mode 100644
index 000000000000..27521f621cb0
--- /dev/null
+++ b/contrib/bmake/unit-tests/varname-dot-suffixes.mk
@@ -0,0 +1,105 @@
+# $NetBSD: varname-dot-suffixes.mk,v 1.5 2023/12/20 09:03:09 rillig Exp $
+#
+# Tests for the special "variable" .SUFFIXES, which lists the suffixes that
+# have been registered for use in suffix transformation rules. Suffixes are
+# listed even if there is no actual transformation rule that uses them.
+#
+# The name '.SUFFIXES' does not refer to a real variable, instead it can be
+# used as a starting "variable name" for expressions like ${.SUFFIXES} or
+# ${.SUFFIXES:M*o}.
+
+# In the beginning, there are no suffix rules, the expression is thus empty.
+.if ${.SUFFIXES} != ""
+.endif
+
+# There is no actual variable named '.SUFFIXES', it is all made up.
+.if defined(.SUFFIXES)
+. error
+.endif
+
+# The suffixes list is still empty, and so is the "variable" '.SUFFIXES'.
+.if !empty(.SUFFIXES)
+. error
+.endif
+
+.SUFFIXES: .c .o .1 .err
+
+# The suffixes are listed in declaration order.
+.if ${.SUFFIXES} != ".c .o .1 .err"
+. error
+.endif
+
+# There is still no actual variable named '.SUFFIXES', it is all made up.
+.if defined(.SUFFIXES)
+. error
+.endif
+
+# Now the suffixes list is not empty anymore. It may seem strange that there
+# is no variable named '.SUFFIXES' but evaluating '${.SUFFIXES}' nevertheless
+# returns something. For all practical use cases, it's good enough though.
+.if empty(.SUFFIXES)
+. error
+.endif
+
+.SUFFIXES: .tar.gz
+
+# Changes to the suffixes list are reflected immediately.
+.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
+. error
+.endif
+
+# Deleting .SUFFIXES has no effect since there is no actual variable of that
+# name.
+.MAKEFLAGS: -dv
+# expect: Global: ignoring delete '.SUFFIXES' as it is not found
+.undef .SUFFIXES
+.MAKEFLAGS: -d0
+.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
+. error
+.endif
+
+# The list of suffixes can only be modified using dependency declarations, any
+# attempt at setting the variable named '.SUFFIXES' is rejected.
+.MAKEFLAGS: -dv
+# expect: Global: ignoring '.SUFFIXES = set' as it is read-only
+.SUFFIXES= set
+# expect: Global: ignoring '.SUFFIXES = append' as it is read-only
+.SUFFIXES+= append
+# expect: Global: ignoring '.SUFFIXES = assign' as it is read-only
+_:= ${.SUFFIXES::=assign}
+# expect: Global: ignoring '.SUFFIXES = preserve' as it is read-only
+_:= ${preserve:L:_=.SUFFIXES}
+.MAKEFLAGS: -d0
+
+# Using the name '.SUFFIXES' in a .for loop looks strange because these
+# variable names are typically in singular form, and .for loops do not use
+# real variables either, they are made up as well, see directive-for.mk. The
+# replacement mechanism for the iteration variables takes precedence.
+.for .SUFFIXES in .c .o
+. if ${.SUFFIXES} != ".c" && ${.SUFFIXES} != ".o"
+. error
+. endif
+.endfor
+
+# After the .for loop, the expression '${.SUFFIXES}' refers to the list of
+# suffixes again.
+.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
+. error
+.endif
+
+# Using the name '.SUFFIXES' in the modifier ':@var@body@' does not create an
+# actual variable either. Like in the .for loop, choosing the name
+# '.SUFFIXES' for the iteration variable is unusual. In ODE Make, the
+# convention for these iteration variables is to have dots at both ends, so
+# the name would be '.SUFFIXES.', furthermore the name of the iteration
+# variable is typically in singular form.
+.MAKEFLAGS: -dv
+# expect: Command: ignoring '.SUFFIXES = 1' as it is read-only
+# expect: Command: ignoring '.SUFFIXES = 2' as it is read-only
+# expect: Command: ignoring delete '.SUFFIXES' as it is not found
+.if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz"
+. error
+.endif
+.MAKEFLAGS: -d0
+
+all:
diff --git a/contrib/bmake/unit-tests/varname-empty.exp b/contrib/bmake/unit-tests/varname-empty.exp
index ec225c6973c8..2165784933e4 100644
--- a/contrib/bmake/unit-tests/varname-empty.exp
+++ b/contrib/bmake/unit-tests/varname-empty.exp
@@ -1,25 +1,22 @@
-Var_SetExpand: variable name "${:U}" expands to empty string, with value "cmdline-u" - ignored
-Var_SetExpand: variable name "" expands to empty string, with value "cmdline-plain" - ignored
+Command: ignoring ' = cmdline-u' as the variable name '${:U}' expands to empty
+Command: ignoring ' = cmdline-plain' as the variable name '' expands to empty
Global: .CURDIR = <curdir>
Var_Parse: ${MAKE_OBJDIR_CHECK_WRITABLE} (eval)
-Global: .OBJDIR = <curdir>
-Global:delete .PATH (not found)
-Global: .PATH = .
-Global: .PATH = . <curdir>
-Global: .TARGETS =
+Global: .TARGETS = # (empty)
Internal: MAKEFILE = varname-empty.mk
Global: .MAKE.MAKEFILES = varname-empty.mk
Global: .PARSEFILE = varname-empty.mk
-Global:delete .INCLUDEDFROMDIR (not found)
-Global:delete .INCLUDEDFROMFILE (not found)
-Var_SetExpand: variable name "" expands to empty string, with value "default" - ignored
-Var_SetExpand: variable name "" expands to empty string, with value "assigned" - ignored
-SetVar: variable name is empty - ignored
-Var_SetExpand: variable name "" expands to empty string, with value "" - ignored
-Var_SetExpand: variable name "" expands to empty string, with value "subst" - ignored
-Var_SetExpand: variable name "" expands to empty string, with value "shell-output" - ignored
-Var_SetExpand: variable name "${:U}" expands to empty string, with value "assigned indirectly" - ignored
-Var_AppendExpand: variable name "${:U}" expands to empty string, with value "appended indirectly" - ignored
+Global: ignoring delete '.INCLUDEDFROMDIR' as it is not found
+Global: ignoring delete '.INCLUDEDFROMFILE' as it is not found
+Global: ignoring ' = default' as the variable name '' expands to empty
+Global: ignoring ' = assigned' as the variable name '' expands to empty
+Global: ignoring ' = appended' as the variable name is empty
+Global: ignoring ' = ' as the variable name '' expands to empty
+Global: ignoring ' = subst' as the variable name '' expands to empty
+Capturing the output of command "echo 'shell-output'"
+Global: ignoring ' = shell-output' as the variable name '' expands to empty
+Global: ignoring ' = assigned indirectly' as the variable name '${:U}' expands to empty
+Global: ignoring ' += appended indirectly' as the variable name '${:U}' expands to empty
Global: .MAKEFLAGS = -r -d v -d
Global: .MAKEFLAGS = -r -d v -d 0
out: fallback
diff --git a/contrib/bmake/unit-tests/varname-empty.mk b/contrib/bmake/unit-tests/varname-empty.mk
index f077d2ec07b4..e018a5d44894 100755
--- a/contrib/bmake/unit-tests/varname-empty.mk
+++ b/contrib/bmake/unit-tests/varname-empty.mk
@@ -1,9 +1,9 @@
-# $NetBSD: varname-empty.mk,v 1.9 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: varname-empty.mk,v 1.10 2023/11/19 21:47:52 rillig Exp $
#
# Tests for the special variable with the empty name.
#
# There is no variable named "" at all, and this fact is used a lot in
-# variable expressions of the form ${:Ufallback}. These expressions are
+# expressions of the form ${:Ufallback}. These expressions are
# based on the variable named "" and use the :U modifier to assign a
# fallback value to the expression (but not to the variable).
#
diff --git a/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk b/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk
index 10a9647fbd1e..b422f25ff12e 100644
--- a/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk
+++ b/contrib/bmake/unit-tests/varname-make_print_var_on_error-jobs.mk
@@ -1,9 +1,9 @@
-# $NetBSD: varname-make_print_var_on_error-jobs.mk,v 1.3 2021/02/04 21:33:14 rillig Exp $
+# $NetBSD: varname-make_print_var_on_error-jobs.mk,v 1.4 2023/11/19 22:32:44 rillig Exp $
#
# Tests for the special MAKE_PRINT_VAR_ON_ERROR variable, which prints the
# values of selected variables on error.
#
-# The variable .ERROR_CMD contains all commands of the target, with variable
+# The variable .ERROR_CMD contains all commands of the target, with
# expressions expanded, just as they were printed to the shell command file.
#
# The commands in .ERROR_CMD are space-separated. Since each command usually
diff --git a/contrib/bmake/unit-tests/varname-makeflags.exp b/contrib/bmake/unit-tests/varname-makeflags.exp
index 39a9383953dd..c1354177ca47 100644
--- a/contrib/bmake/unit-tests/varname-makeflags.exp
+++ b/contrib/bmake/unit-tests/varname-makeflags.exp
@@ -1 +1,21 @@
+spaces_stage_0: MAKEFLAGS=< -r -k >
+spaces_stage_0: env MAKEFLAGS=< -r -k >
+spaces_stage_1: MAKEFLAGS=< -r -k -d 00000 -D VARNAME WITH SPACES >
+spaces_stage_1: env MAKEFLAGS=< -r -k -d 00000 -D VARNAME WITH SPACES >
+dollars_stage_0: MAKEFLAGS=< -r -k >
+dollars_stage_1: env MAKEFLAGS=< -r -k DOLLARS=\$\{varname\}>
+dollars_stage_1: MAKEFLAGS=< -r -k DOLLARS=\{varname\}>
+dollars_stage_1: MAKEFLAGS:q=< -r -k DOLLARS=\{varname\}>
+dollars_stage_2: env MAKEFLAGS=< -r -k DOLLARS=>
+dollars_stage_2: dollars=<>
+dollars_stage_2: MAKEFLAGS=< -r -k DOLLARS=>
+dollars_stage_3: env MAKEFLAGS=< -r -k DOLLARS=>
+dollars_stage_3: dollars=<>
+dollars_stage_3: MAKEFLAGS=< -r -k DOLLARS=>
+append_stage_0: MAKEFLAGS=< -r -k >
+append_stage_1: MAKEFLAGS=< -r -k -D before-0 -D after-0 VAR0=value>
+append_stage_2: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 VAR0=value VAR1=value>
+append_stage_3: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 -D before-2 -D after-2 VAR0=value VAR1=value VAR2=value>
+override_stage_1: run MAKEFLAGS=< -r -k STAGE=1 VAR=value>
+override_stage_2: STAGE=<2> VAR=<value>
exit status 0
diff --git a/contrib/bmake/unit-tests/varname-makeflags.mk b/contrib/bmake/unit-tests/varname-makeflags.mk
index 3b4fd91c3f57..4173c5a92095 100644
--- a/contrib/bmake/unit-tests/varname-makeflags.mk
+++ b/contrib/bmake/unit-tests/varname-makeflags.mk
@@ -1,26 +1,182 @@
-# $NetBSD: varname-makeflags.mk,v 1.3 2020/12/01 20:37:30 rillig Exp $
+# $NetBSD: varname-makeflags.mk,v 1.8 2023/06/01 07:27:30 rillig Exp $
#
-# Tests for the special MAKEFLAGS variable, which is basically just a normal
-# environment variable. It is closely related to .MAKEFLAGS but captures the
-# state of .MAKEFLAGS at the very beginning of make, before any makefiles are
-# read.
+# Tests for the environment variable 'MAKEFLAGS', from which additional
+# command line arguments are read before the actual command line arguments.
+#
+# After reading the makefiles and before making the targets, the arguments
+# that were collected in '.MAKEFLAGS' and '.MAKEOVERRIDES' are written back to
+# the environment variable 'MAKEFLAGS'.
+
+all: spaces_stage_0 dollars_stage_0 append_stage_0 override_stage_0
-# TODO: Implementation
-.MAKEFLAGS: -d0
+.if !make(*stage*)
# The unit tests are run with an almost empty environment. In particular,
-# the variable MAKEFLAGS is not set. The '.MAKEFLAGS:' above also doesn't
-# influence the environment variable MAKEFLAGS, therefore it is still
-# undefined at this point.
-.if ${MAKEFLAGS:Uundefined} != "undefined"
-. error
-.endif
+# the variable MAKEFLAGS is not set.
+. if ${MAKEFLAGS:Uundefined} != "undefined"
+. error
+. endif
# The special variable .MAKEFLAGS is influenced though.
# See varname-dot-makeflags.mk for more details.
-.if ${.MAKEFLAGS} != " -r -k -d 0"
-. error
+. if ${.MAKEFLAGS} != " -r -k"
+. error
+. endif
+
+
+# In POSIX mode, the environment variable MAKEFLAGS can contain letters only,
+# for compatibility. These letters are exploded to form regular options.
+OUTPUT!= env MAKEFLAGS=ikrs ${MAKE} -f /dev/null -v .MAKEFLAGS
+. if ${OUTPUT} != " -i -k -r -s -V .MAKEFLAGS"
+. error
+. endif
+
+# As soon as there is a single non-alphabetic character in the environment
+# variable MAKEFLAGS, it is no longer split. In this example, the word
+# "d0ikrs" is treated as a target, but the option '-v' prevents any targets
+# from being built.
+OUTPUT!= env MAKEFLAGS=d0ikrs ${MAKE} -r -f /dev/null -v .MAKEFLAGS
+. if ${OUTPUT} != " -r -V .MAKEFLAGS"
+. error ${OUTPUT}
+. endif
+
+.endif
+
+
+# When options are parsed, the option and its argument are appended as
+# separate words to the MAKEFLAGS for the child processes. Special characters
+# in the option arguments are not quoted though.
+spaces_stage_0:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>"
+ @${MAKE} -f ${MAKEFILE} spaces_stage_1 -d00000 -D"VARNAME WITH SPACES"
+
+# At this point, the 'VARNAME WITH SPACES' is no longer recognizable as a
+# single command line argument. In practice, variable names don't contain
+# spaces.
+spaces_stage_1:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>"
+
+
+# Demonstrate that '$' characters are altered when they are passed on to child
+# make processes via MAKEFLAGS.
+dollars_stage_0:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+
+ # The '$$$$' becomes a literal '$$' when building the '${MAKE}'
+ # command line, making the actual argument 'DOLLARS=$${varname}'.
+ # At this stage, MAKEFLAGS is not yet involved.
+ @${MAKE} -f ${MAKEFILE} dollars_stage_1 DOLLARS='$$$${varname}'
+
+.if make(dollars_stage_1)
+# At this point, the variable 'DOLLARS' contains '$${varname}', which
+# evaluates to a literal '$' followed by '{varname}'.
+. if ${DOLLARS} != "\${varname}"
+. error
+. endif
+.endif
+dollars_stage_1:
+ # At this point, the stage 1 make provides the environment variable
+ # 'MAKEFLAGS' to its child processes, even if the child process is not
+ # another make.
+ #
+ # expect: dollars_stage_1: env MAKEFLAGS=< -r -k DOLLARS=\$\{varname\}>
+ #
+ # The 'DOLLARS=\$\{varname\}' assignment is escaped so that the stage
+ # 2 make will see it as a single word.
+ @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>"
+
+ # At this point, evaluating the environment variable 'MAKEFLAGS' leads
+ # to strange side effects as the string '\$\{varname\}' is interpreted
+ # as:
+ #
+ # \ a literal string of a single backslash
+ # $\ the value of the variable named '\'
+ # {varname\} a literal string
+ #
+ # Since the variable named '\' is not defined, the resulting value is
+ # '\{varname\}'. Make doesn't handle isolated '$' characters in
+ # strings well, instead each '$' has to be part of a '$$' or be part
+ # of a subexpression like '${VAR}'.
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+
+ # The modifier ':q' preserves a '$$' in an expression value instead of
+ # expanding it to a single '$', but it's already too late, as that
+ # modifier applies after the expression has been evaluated. Except
+ # for debug logging, there is no way to process strings that contain
+ # isolated '$'.
+ @echo '$@: MAKEFLAGS:q=<'${MAKEFLAGS:q}'>'
+
+ @${MAKE} -f ${MAKEFILE} dollars_stage_2
+
+.if make(dollars_stage_2)
+# At this point, the variable 'DOLLARS' contains '${varname}', and since
+# 'varname' is undefined, that expression evaluates to an empty string.
+. if ${DOLLARS} != ""
+. error
+. endif
+varname= varvalue
+. if ${DOLLARS} != "varvalue"
+. error
+. endif
+. undef varname
+.endif
+dollars_stage_2:
+ @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>"
+ @echo '$@: dollars=<'${DOLLARS:Q}'>'
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -f ${MAKEFILE} dollars_stage_3
+
+dollars_stage_3:
+ @echo "$@: env MAKEFLAGS=<$$MAKEFLAGS>"
+ @echo '$@: dollars=<'${DOLLARS:Uundefined:Q}'>'
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+
+
+# Demonstrates in which exact order the MAKEFLAGS are built from the parent
+# MAKEFLAGS and the flags from the command line, in particular that variable
+# assignments are passed at the end, after the options.
+append_stage_0:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -Dbefore-0 -f ${MAKEFILE} append_stage_1 VAR0=value -Dafter-0
+
+append_stage_1:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -Dbefore-1 -f ${MAKEFILE} append_stage_2 VAR1=value -Dafter-1
+
+append_stage_2:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -Dbefore-2 -f ${MAKEFILE} append_stage_3 VAR2=value -Dafter-2
+
+append_stage_3:
+ @echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+
+
+# Demonstrates the implementation details of 'MAKEFLAGS', in particular that
+# it is an environment variable rather than a global variable.
+override_stage_0:
+ @${MAKE} -f ${MAKEFILE} STAGE=1 VAR=value override_stage_1
+
+.if make(override_stage_1)
+# While parsing the makefiles, 'MAKEFLAGS' is the value of the environment
+# variable, in this case provided by stage 0.
+. if ${MAKEFLAGS:M*} != "-r -k"
+. error
+. endif
+MAKEFLAGS= overridden # temporarily override it
+. if ${MAKEFLAGS} != "overridden"
+. error
+. endif
+.undef MAKEFLAGS # make the environment variable visible again
+. if ${MAKEFLAGS:M*} != "-r -k"
+. error
+. endif
.endif
+override_stage_1:
+ @echo '$@: run MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -f ${MAKEFILE} STAGE=2 override_stage_2
-all:
+override_stage_2:
+ @echo '$@: STAGE=<${STAGE}> VAR=<${VAR}>'
diff --git a/contrib/bmake/unit-tests/varname.exp b/contrib/bmake/unit-tests/varname.exp
index 942532b654d5..640f228f8a51 100644
--- a/contrib/bmake/unit-tests/varname.exp
+++ b/contrib/bmake/unit-tests/varname.exp
@@ -5,13 +5,13 @@ Var_Parse: ${VARNAME} (eval)
Global: VAR((( = 3 open parentheses
Var_Parse: ${VAR(((}}}}" != "3 open parentheses}}}" (eval)
Global: .ALLTARGETS = VAR(((=)
-make: "varname.mk" line 30: No closing parenthesis in archive specification
-make: "varname.mk" line 30: Error in archive specification: "VAR"
+make: "varname.mk" line 32: No closing parenthesis in archive specification
+make: "varname.mk" line 32: Error in archive specification: "VAR"
Var_Parse: ${:UVAR\(\(\(}= try2 (eval-defined)
Evaluating modifier ${:U...} on value "" (eval-defined, undefined)
Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (eval-defined, defined)
Global: .ALLTARGETS = VAR(((=) VAR\(\(\(=
-make: "varname.mk" line 35: Invalid line type
+make: "varname.mk" line 38: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2'
Var_Parse: ${VARNAME} (eval)
Global: VAR((( = try3
Global: .MAKEFLAGS = -r -k -d v -d
diff --git a/contrib/bmake/unit-tests/varname.mk b/contrib/bmake/unit-tests/varname.mk
index f586c7602cb7..cad0a10fe563 100644
--- a/contrib/bmake/unit-tests/varname.mk
+++ b/contrib/bmake/unit-tests/varname.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varname.mk,v 1.8 2020/11/02 22:59:48 rillig Exp $
+# $NetBSD: varname.mk,v 1.14 2023/11/19 21:47:52 rillig Exp $
#
# Tests for special variables, such as .MAKE or .PARSEDIR.
# And for variable names in general.
@@ -12,7 +12,7 @@ VAR{{{}}}= 3 braces
. error
.endif
-# In variable expressions, the parser works differently. It doesn't treat
+# In expressions, the parser works differently. It doesn't treat
# braces and parentheses equally, therefore the first closing brace already
# marks the end of the variable name.
VARNAME= VAR(((
@@ -27,11 +27,14 @@ ${VARNAME}= 3 open parentheses
# This is not a variable assignment since the parentheses and braces are not
# balanced. At the end of the line, there are still 3 levels open, which
# means the variable name is not finished.
+# expect+2: Error in archive specification: "VAR"
+# expect+1: No closing parenthesis in archive specification
${:UVAR(((}= try1
# On the left-hand side of a variable assignments, the backslash is not parsed
# as an escape character, therefore the parentheses still count to the nesting
# level, which at the end of the line is still 3. Therefore this is not a
# variable assignment as well.
+# expect+1: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2'
${:UVAR\(\(\(}= try2
# To assign to a variable with an arbitrary name, the variable name has to
# come from an external source, not the text that is parsed in the assignment
@@ -41,4 +44,46 @@ ${VARNAME}= try3
.MAKEFLAGS: -d0
+# All variable names of a scope are stored in the same hash table, using a
+# simple hash function. Ensure that HashTable_Find handles collisions
+# correctly and that the correct variable is looked up. The strings "0x" and
+# "1Y" have the same hash code, as 31 * '0' + 'x' == 31 * '1' + 'Y'.
+V.0x= 0x
+V.1Y= 1Y
+.if ${V.0x} != "0x" || ${V.1Y} != "1Y"
+. error
+.endif
+
+# The string "ASDZguv", when used as a prefix of a variable name, keeps the
+# hash code unchanged, its own hash code is 0.
+ASDZguvV.0x= 0x
+ASDZguvV.1Y= 1Y
+.if ${ASDZguvV.0x} != "0x"
+. error
+.elif ${ASDZguvV.1Y} != "1Y"
+. error
+.endif
+
+# Ensure that variables with the same hash code whose name is a prefix of the
+# other can be accessed. In this case, the shorter variable name is defined
+# first to make it appear later in the bucket of the hash table.
+ASDZguv= once
+ASDZguvASDZguv= twice
+.if ${ASDZguv} != "once"
+. error
+.elif ${ASDZguvASDZguv} != "twice"
+. error
+.endif
+
+# Ensure that variables with the same hash code whose name is a prefix of the
+# other can be accessed. In this case, the longer variable name is defined
+# first to make it appear later in the bucket of the hash table.
+ASDZguvASDZguv.param= twice
+ASDZguv.param= once
+.if ${ASDZguv.param} != "once"
+. error
+.elif ${ASDZguvASDZguv.param} != "twice"
+. error
+.endif
+
all:
diff --git a/contrib/bmake/unit-tests/varparse-dynamic.exp b/contrib/bmake/unit-tests/varparse-dynamic.exp
index a2ff29413167..caf8424fa91a 100644
--- a/contrib/bmake/unit-tests/varparse-dynamic.exp
+++ b/contrib/bmake/unit-tests/varparse-dynamic.exp
@@ -1,5 +1,5 @@
-make: "varparse-dynamic.mk" line 8: Malformed conditional (${.TARGEX})
-make: "varparse-dynamic.mk" line 10: Malformed conditional (${.TARGXX})
+make: "varparse-dynamic.mk" line 9: Malformed conditional (${.TARGEX})
+make: "varparse-dynamic.mk" line 12: Malformed conditional (${.TARGXX})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varparse-dynamic.mk b/contrib/bmake/unit-tests/varparse-dynamic.mk
index d4d165017a7f..40f43b049b13 100644
--- a/contrib/bmake/unit-tests/varparse-dynamic.mk
+++ b/contrib/bmake/unit-tests/varparse-dynamic.mk
@@ -1,12 +1,14 @@
-# $NetBSD: varparse-dynamic.mk,v 1.5 2021/02/22 20:38:55 rillig Exp $
+# $NetBSD: varparse-dynamic.mk,v 1.8 2023/11/19 22:32:44 rillig Exp $
# Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped
# the last character in the variable name.
-# To trigger the bug, the variable must not be defined.
+# To trigger the bug, the variable had to be undefined.
.if ${.TARGET} # exact match, may be undefined
.endif
+# expect+1: Malformed conditional (${.TARGEX})
.if ${.TARGEX} # 1 character difference, must be defined
.endif
+# expect+1: Malformed conditional (${.TARGXX})
.if ${.TARGXX} # 2 characters difference, must be defined
.endif
@@ -22,7 +24,7 @@
.endif
# If a dynamic variable is expanded in a non-local scope, the expression
-# based on this variable is not expanded. But there may be nested variable
+# based on this variable is not expanded. But there may be nested
# expressions in the modifiers, and these are kept unexpanded as well.
.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
. error
@@ -30,6 +32,3 @@
.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
. error
.endif
-
-all:
- @:
diff --git a/contrib/bmake/unit-tests/varparse-errors.exp b/contrib/bmake/unit-tests/varparse-errors.exp
index 27589e0b21af..4193bea181c9 100644
--- a/contrib/bmake/unit-tests/varparse-errors.exp
+++ b/contrib/bmake/unit-tests/varparse-errors.exp
@@ -1,5 +1,25 @@
make: "varparse-errors.mk" line 38: Unknown modifier "Z"
-make: "varparse-errors.mk" line 46: Unknown modifier "Z"
+make: "varparse-errors.mk" line 47: Unknown modifier "Z"
+make: Bad modifier ":OX" for variable ""
+make: "varparse-errors.mk" line 71: Undefined variable "${:U:OX"
+make: Bad modifier ":OX" for variable ""
+make: Bad modifier ":OX" for variable ""
+make: "varparse-errors.mk" line 71: Undefined variable "${:U:OX"
+make: Bad modifier ":OX" for variable ""
+make: Unclosed expression, expecting '}' for modifier "Q" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "sh" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "tA" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "tsX" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "ts" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "ts\040" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "u" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "H" of variable "" with value "."
+make: Unclosed expression, expecting '}' for modifier "[1]" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "hash" of variable "" with value "b2af338b"
+make: Unclosed expression, expecting '}' for modifier "range" of variable "" with value "1"
+make: Unclosed expression, expecting '}' for modifier "_" of variable "" with value ""
+make: Unclosed expression, expecting '}' for modifier "gmtime" of variable "" with value "<timestamp>"
+make: Unclosed expression, expecting '}' for modifier "localtime" of variable "" with value "<timestamp>"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff --git a/contrib/bmake/unit-tests/varparse-errors.mk b/contrib/bmake/unit-tests/varparse-errors.mk
index f0947bb9410a..fc94d9dd3d18 100644
--- a/contrib/bmake/unit-tests/varparse-errors.mk
+++ b/contrib/bmake/unit-tests/varparse-errors.mk
@@ -1,12 +1,11 @@
-# $NetBSD: varparse-errors.mk,v 1.4 2021/03/15 12:15:03 rillig Exp $
+# $NetBSD: varparse-errors.mk,v 1.11 2023/11/19 22:32:44 rillig Exp $
-# Tests for parsing and evaluating all kinds of variable expressions.
+# Tests for parsing and evaluating all kinds of expressions.
#
# This is the basis for redesigning the error handling in Var_Parse and
# Var_Subst, collecting typical and not so typical use cases.
#
# See also:
-# VarParseResult
# Var_Parse
# Var_Subst
@@ -18,13 +17,13 @@ INDIRECT= An ${:Uindirect} value.
REF_UNDEF= A reference to an ${UNDEF}undefined variable.
-ERR_UNCLOSED= An ${UNCLOSED variable expression.
+ERR_UNCLOSED= An ${UNCLOSED expression.
ERR_BAD_MOD= An ${:Uindirect:Z} expression with an unknown modifier.
ERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}.
-# In a conditional, a variable expression that is not enclosed in quotes is
+# In a conditional, an expression that is not enclosed in quotes is
# expanded using the mode VARE_UNDEFERR.
# The variable itself must be defined.
# It may refer to undefined variables though.
@@ -35,6 +34,7 @@ ERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}.
# As of 2020-12-01, errors in the variable name are silently ignored.
# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
# in an error message and a non-zero exit status.
+# expect+1: Unknown modifier "Z"
VAR.${:U:Z}= unknown modifier in the variable name
.if ${VAR.} != "unknown modifier in the variable name"
. error
@@ -43,9 +43,49 @@ VAR.${:U:Z}= unknown modifier in the variable name
# As of 2020-12-01, errors in the variable name are silently ignored.
# Since var.c 1.754 from 2020-12-20, unknown modifiers at parse time result
# in an error message and a non-zero exit status.
+# expect+1: Unknown modifier "Z"
VAR.${:U:Z}post= unknown modifier with text in the variable name
.if ${VAR.post} != "unknown modifier with text in the variable name"
. error
.endif
-all:
+# Demonstrate an edge case in which the 'static' for 'errorReported' in
+# Var_Subst actually makes a difference, preventing "a plethora of messages".
+# Given that this is an edge case and the error message is wrong and thus
+# misleading anyway, that piece of code is probably not necessary. The wrong
+# condition was added in var.c 1.185 from 2014-05-19.
+#
+# To trigger this difference, the variable assignment must use the assignment
+# operator ':=' to make VarEvalMode_ShouldKeepUndef return true. There must
+# be 2 expressions that create a parse error, which in this case is ':OX'.
+# These expressions must be nested in some way. The below expressions are
+# minimal, that is, removing any part of it destroys the effect.
+#
+# Without the 'static', there would be one more message like this:
+# Undefined variable "${:U:OX"
+#
+#.MAKEFLAGS: -dv
+IND= ${:OX}
+# expect+2: Undefined variable "${:U:OX"
+# expect+1: Undefined variable "${:U:OX"
+_:= ${:U:OX:U${IND}} ${:U:OX:U${IND}}
+#.MAKEFLAGS: -d0
+
+
+# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier'
+# or 'Bad modifier' when in fact the modifier was entirely correct, it was
+# just not delimited by either ':' or '}' but instead by '\0'.
+UNCLOSED:= ${:U:Q
+UNCLOSED:= ${:U:sh
+UNCLOSED:= ${:U:tA
+UNCLOSED:= ${:U:tsX
+UNCLOSED:= ${:U:ts
+UNCLOSED:= ${:U:ts\040
+UNCLOSED:= ${:U:u
+UNCLOSED:= ${:U:H
+UNCLOSED:= ${:U:[1]
+UNCLOSED:= ${:U:hash
+UNCLOSED:= ${:U:range
+UNCLOSED:= ${:U:_
+UNCLOSED:= ${:U:gmtime
+UNCLOSED:= ${:U:localtime
diff --git a/contrib/bmake/unit-tests/varparse-mod.mk b/contrib/bmake/unit-tests/varparse-mod.mk
index 0b4cbf6ca40a..c5fa6f5ece71 100644
--- a/contrib/bmake/unit-tests/varparse-mod.mk
+++ b/contrib/bmake/unit-tests/varparse-mod.mk
@@ -1,6 +1,6 @@
-# $NetBSD: varparse-mod.mk,v 1.1 2020/10/02 20:34:59 rillig Exp $
+# $NetBSD: varparse-mod.mk,v 1.2 2023/11/19 21:47:52 rillig Exp $
-# Tests for parsing variable expressions with modifiers.
+# Tests for parsing expressions with modifiers.
# As of 2020-10-02, the below condition does not result in a parse error.
# The condition contains two separate mistakes. The first mistake is that
@@ -8,7 +8,7 @@
# there is a stray '}' at the end of the whole condition.
#
# As of 2020-10-02, the actual parse result of this condition is a single
-# variable expression with 2 modifiers. The first modifier is
+# expression with 2 modifiers. The first modifier is
# ":!echo "\$VAR"} !". Afterwards, the parser optionally skips a ':' (at the
# bottom of ApplyModifiers) and continues with the next modifier, in this case
# "= "value"", which is interpreted as a SysV substitution modifier with an
diff --git a/contrib/bmake/unit-tests/varparse-undef-partial.mk b/contrib/bmake/unit-tests/varparse-undef-partial.mk
index 27f44d79b31a..9a5704265086 100644
--- a/contrib/bmake/unit-tests/varparse-undef-partial.mk
+++ b/contrib/bmake/unit-tests/varparse-undef-partial.mk
@@ -1,7 +1,7 @@
-# $NetBSD: varparse-undef-partial.mk,v 1.3 2020/11/04 05:10:01 rillig Exp $
+# $NetBSD: varparse-undef-partial.mk,v 1.5 2024/01/07 11:39:04 rillig Exp $
# When an undefined variable is expanded in a ':=' assignment, only the
-# initial '$' of the variable expression is skipped by the parser, while
+# initial '$' of the expression is skipped by the parser, while
# the remaining expression is evaluated. In edge cases this can lead to
# a completely different interpretation of the partially expanded text.
@@ -11,11 +11,10 @@ PARAM= :Q
# The expression ${VAR.${PARAM}} refers to the variable named "VAR.:Q",
# with the ":Q" being part of the name. This variable is not defined,
-# therefore the initial '$' of that whole expression is skipped by the
-# parser (see Var_Subst, the Buf_AddByte in the else branch) and the rest
-# of the expression is expanded as usual.
+# therefore the initial '$' of that whole expression is skipped by the parser
+# (see VarSubstExpr) and the rest of the expression is expanded as usual.
#
-# The resulting variable expression is ${VAR.:Q}, which means that the
+# The resulting expression is ${VAR.:Q}, which means that the
# interpretation of the ":Q" has changed from being part of the variable
# name to being a variable modifier. This is a classical code injection.
EVAL:= ${LIST}
@@ -37,7 +36,7 @@ ${:UVAR.\:Q}= var-dot with parameter :Q
# In contrast to the previous line, evaluating the original LIST again now
# produces a different result since the variable named "VAR.:Q" is now
# defined. It is expanded as usual, interpreting the ":Q" as part of the
-# variable name, as would be expected from reading the variable expression.
+# variable name, as would be expected from reading the expression.
EVAL:= ${LIST}
.if ${EVAL} != "defined var-dot with parameter :Q end"
. error ${EVAL}
diff --git a/contrib/bmake/unit-tests/varquote.exp b/contrib/bmake/unit-tests/varquote.exp
deleted file mode 100644
index 63107bfd34f5..000000000000
--- a/contrib/bmake/unit-tests/varquote.exp
+++ /dev/null
@@ -1,3 +0,0 @@
--fdebug-prefix-map=$NETBSDSRCDIR=/usr/src -fdebug-regex-map=/usr/src/(.*)/obj$=/usr/obj/\1
--fdebug-prefix-map=$NETBSDSRCDIR=/usr/src -fdebug-regex-map=/usr/src/(.*)/obj$=/usr/obj/\1
-exit status 0
diff --git a/contrib/bmake/unit-tests/varquote.mk b/contrib/bmake/unit-tests/varquote.mk
deleted file mode 100644
index fb8b1066ac15..000000000000
--- a/contrib/bmake/unit-tests/varquote.mk
+++ /dev/null
@@ -1,14 +0,0 @@
-# $NetBSD: varquote.mk,v 1.4 2018/12/16 18:53:34 christos Exp $
-#
-# Test VAR:q modifier
-
-.if !defined(REPROFLAGS)
-REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src
-REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj$$=/usr/obj/\1'
-all:
- @${MAKE} -f ${MAKEFILE} REPROFLAGS=${REPROFLAGS:S/\$/&&/g:Q}
- @${MAKE} -f ${MAKEFILE} REPROFLAGS=${REPROFLAGS:q}
-.else
-all:
- @printf "%s %s\n" ${REPROFLAGS}
-.endif