build: put the generated header under include/ for relocated builds

Previously the generated database/database.h was written to the build
top and exposed with -I${MAGICDIR}.  Out-of-tree that placed the raw
build directory on the compiler's include search path.

Introduce ${GENINC}, the single include dir for generated headers:
  * in-tree  (build top == source top): ${MAGICDIR}, so the header stays
    at $(builddir)/database/database.h and -I${GENINC} is exactly the old
    -I${MAGICDIR} -- behaviour is unchanged.
  * relocated (out-of-tree): ${MAGICDIR}/include, so the header is written
    to $(builddir)/include/database/database.h and only that clean
    include/ dir is on the search path; the raw build top never is.

* scripts/defs.mak.in: derive GENINC from BUILD_TOP vs MAGICSRC; add
  DATABASE_H = ${GENINC}/database/database.h; CPPFLAGS uses -I${GENINC}.
* Makefile.in: the makedbh rule targets ${DATABASE_H} (mkdir its dir);
  every prereq and the distclean use ${DATABASE_H}.
* database/Makefile: the fallback delegate targets ${DATABASE_H}.

Verified: relocated `make modules` builds all 33 module libraries with
the header at build/include/database/database.h and no raw build-top on
any -I line; in-tree the header stays at database/database.h and the
-I set is unchanged.

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 955a61aeda
commit 1bdc3fa12a
3 changed files with 32 additions and 15 deletions
+16 -2
View File
@@ -32,6 +32,20 @@ srcdir := $(MAGICSRC)$(MODULE_SUBPATH)
ifneq ($(MODULE_SUBPATH),)
VPATH := $(srcdir)
endif
# Generated headers (currently just database/database.h) are exposed through a
# single include directory, ${GENINC}:
# * in-tree (build top == source top): the top itself, so the header stays at
# $(builddir)/database/database.h and -I${GENINC} == the old -I${MAGICDIR}.
# * relocated (out-of-tree): a clean $(builddir)/include, so #include
# <database/database.h> resolves under include/ and the raw build top is
# never on the compiler search path.
ifeq ($(BUILD_TOP),$(MAGICSRC))
GENINC := ${MAGICDIR}
else
GENINC := ${MAGICDIR}/include
endif
DATABASE_H := ${GENINC}/database/database.h
# --------------------------------------------------------------------------
prefix = @prefix@
@@ -141,10 +155,10 @@ CXX = @CXX@
### Status: NOT-STABILITY-AFFECTING (if your binary links you are good to continue)
#FEATURE_FLAGS += -DSUPPORT_REMOVE_MALLOC_LEGACY
# -I${MAGICDIR}: build top, for the generated database/database.h
# -I${GENINC}: generated headers (build top in-tree, build/include relocated)
# -I${MAGICSRC}: source top, for "<module>/<header>.h" includes
# -I${srcdir}: this module's source dir, for same-directory headers
CPPFLAGS = -I${MAGICDIR} -I${MAGICSRC} -I${srcdir} @CPPFLAGS@
CPPFLAGS = -I${GENINC} -I${MAGICSRC} -I${srcdir} @CPPFLAGS@
CXXFLAGS = @CXXFLAGS@
# Bundled GNU readline: its headers use <readline/*.h> includes, so the readline
# source's parent directory must be on the include path. Only for the bundled