build: accept @srcdir@-substituted subdir Makefiles

Enabler for the Makefile -> Makefile.in migration.  No module is
converted yet; behaviour is identical.

* scripts/defs.mak.in: dual-mode.  A module converted to Makefile.in will
  set `srcdir` (and VPATH) from @srcdir@ before including defs.mak; only
  derive them (the $(abspath)/$(patsubst) srcdir computation) when it
  did not -- `ifeq ($(origin srcdir),undefined)`.  BUILD_TOP (needed by
  GENINC) is computed either way.

* Makefile.in: route every subdir recursion through a single helper,
      $(call submake,<dir>,<goal>)
  which uses the generated build Makefile if config.status made one there
  (a converted Makefile.in) and otherwise falls back to the source
  Makefile with -f.  Today nothing is converted, so out-of-tree always
  takes the -f path and in-tree uses the (identical) static Makefile
  natively.  clean/ keeps its own no-mkdir variant.  readline/ is
  intentionally never converted and always takes -f.

* .gitignore: document the migration policy -- each converted module adds
  its generated "<dir>/Makefile" here in the same commit so an in-tree
  build can never commit a generated Makefile.  (None converted yet.)

Verified in-tree and out-of-tree: `configure && make && make install`
each produce 376 files with the header in the right place (database/
database.h in-tree, include/database/database.h relocated), 27/28 docs,
source tree clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
Darryl L. Miles
2026-07-26 14:54:11 -04:00
committed by R. Timothy Edwards
co-authored by Claude Opus 4.8
parent 64d2ad8df7
commit 242d415788
3 changed files with 39 additions and 13 deletions
+6
View File
@@ -21,6 +21,11 @@ MAGICSRC = @abs_top_srcdir@
# subpath = "/tiles", or "" at the top
# srcdir = $(MAGICSRC)$(subpath)
BUILD_TOP := $(abspath $(MAGICDIR))
# Dual mode: a module converted to Makefile.in sets `srcdir` (and VPATH) from
# @srcdir@ *before* including this file, so we only derive them when it did not.
# This lets the two kinds of Makefile coexist during the migration. BUILD_TOP
# (needed by GENINC below) is computed either way.
ifeq ($(origin srcdir),undefined)
# Anchored prefix strip (patsubst matches the whole word, so BUILD_TOP must be a
# leading prefix): "" at the build top, "/tiles" in a subdir. Unlike $(subst …)
# this cannot mis-fire if BUILD_TOP happens to recur later in the path.
@@ -32,6 +37,7 @@ srcdir := $(MAGICSRC)$(MODULE_SUBPATH)
ifneq ($(MODULE_SUBPATH),)
VPATH := $(srcdir)
endif
endif
# Generated headers (currently just database/database.h) are exposed through a
# single include directory, ${GENINC}: