Multiple BSDmakefile issues

BSDmakefile, the make script for *BSD platforms had the following defects.

1. The output of which(1) was not redirected to /dev/null and it got printed
every time make was launched. Also the $(.TARGETS) target did not have
.SILENT dependency and would print the call to gmake, which was also
inconsistent with the rest of the BSDmakefile.

2. GNU make would be called twice if any target was given:

    $ make show-version-full
    /usr/local/bin/gmake
    12.0.0-dev-68-ee5b102142+gitea-1.22.0
    "gmake"  "--no-print-directory" show-version-full
    12.0.0-dev-68-ee5b102142+gitea-1.22.0

For reasons that I don't fully understand, the first call came from .DEFAULT,
and the other from $(.TARGETS).

3. Invalid use of $(.TARGETS) instead of $@ in build commands would cause
multiple more invocations if more than one target was specified, for example:

    $ make -f BSDmakefile show-version-minor show-version-major
    /usr/local/bin/gmake
    12.0
    12
    "gmake"  "--no-print-directory" show-version-minor show-version-major
    12.0
    12
    "gmake"  "--no-print-directory" show-version-minor show-version-major
    12.0
    12

Here gmake is called three times in total.

After this change:

  • the default rule EMPTY is called if no explicit target is specified in
    the command line,
  • otherwise $(.TARGETS) are expanded and called one by one,
  • .DONE has been removed; it was not used anywhere and it is not a keyword,
  • FRC (a.k.a. FORCE) is not needed as adding to .PHONY is sufficient,
  • $(JARG) has been moved before current target $@ as this is a command line
    switch; it's spurious as parallel compilation is not supported anyway.
This commit is contained in:
Matt Latusek 2025-04-02 21:15:35 +00:00
parent ee5b102142
commit 5646c95bfc

View file

@ -48,11 +48,12 @@ GPREFIX =
.endif
.BEGIN: .SILENT
which $(GMAKE) || (printf "Error: GNU Make is required!\n\n" 1>&2 && false)
which $(GMAKE) >/dev/null || (printf "Error: GNU Make is required!\n\n" 1>&2 && false)
.PHONY: FRC
$(.TARGETS): FRC
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
.PHONY: EMPTY
EMPTY: .SILENT
$(GMAKE) $(GPREFIX) $(GARGS) $(JARG)
.DONE .DEFAULT: .SILENT
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
.PHONY: $(.TARGETS)
$(.TARGETS): .SILENT
$(GMAKE) $(GPREFIX) $(GARGS) $(JARG) $@