diff --git a/Makefile.in b/Makefile.in index ac25a365..7b8c06bf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -44,21 +44,23 @@ defs.mak: config: ${MAGICSRC}/configure -tcllibrary: database/database.h modules +tcllibrary: ${DATABASE_H} modules @echo --- making Tcl shared libraries for dir in ${PROGRAMS}; do \ mkdir -p $$dir && ${MAKE} -C $$dir -f ${MAGICSRC}/$$dir/Makefile tcl-main || exit 1; done -mains: database/database.h modules libs +mains: ${DATABASE_H} modules libs @echo --- making main programs for dir in ${PROGRAMS}; do \ mkdir -p $$dir && ${MAKE} -C $$dir -f ${MAGICSRC}/$$dir/Makefile main || exit 1; done # makedbh is the one generated helper script; it lives in the *build* tree. -database/database.h: ${MAGICSRC}/database/database.h.in - @echo --- making header file database/database.h - @mkdir -p database - ${MAGICDIR}/scripts/makedbh ${MAGICSRC}/database/database.h.in database/database.h +# ${DATABASE_H} is $(builddir)/database/database.h in-tree, or +# $(builddir)/include/database/database.h when relocated (see defs.mak GENINC). +${DATABASE_H}: ${MAGICSRC}/database/database.h.in + @echo --- making header file ${DATABASE_H} + @mkdir -p $(dir ${DATABASE_H}) + ${MAGICDIR}/scripts/makedbh ${MAGICSRC}/database/database.h.in ${DATABASE_H} # tiles xyz => tiles/libtiles.o xyz/libxyz.o MODULES_SUBDIR := $(shell for i in ${MODULES}; do echo "$${i}/lib$${i}.o"; done) @@ -70,14 +72,14 @@ ${MODULES_SUBDIR}: FORCE @d=$(dir $@); mkdir -p $$d && ${MAKE} -C $$d -f ${MAGICSRC}/$${d}Makefile module .PHONY: modules -modules: database/database.h depend ${MODULES_SUBDIR} +modules: ${DATABASE_H} depend ${MODULES_SUBDIR} ${LIBS_SUBDIR}: FORCE @d=$(dir $@); mkdir -p $$d && ${MAKE} -C $$d -f ${MAGICSRC}/$${d}Makefile lib # Force the tiles/utils modules to exist first for libdatabase.a .PHONY: libs -libs: database/database.h depend tiles/libtiles.o utils/libutils.o ${LIBS_SUBDIR} +libs: ${DATABASE_H} depend tiles/libtiles.o utils/libutils.o ${LIBS_SUBDIR} # # extcheck - utility tool @@ -94,7 +96,7 @@ SUBDIRS_FILTERED := $(shell echo ${MODULES} ${PROGRAMS} ${SUBDIRS} | tr ' ' '\n' SUBDIRS_DEPEND = $(addsuffix /Depend, ${SUBDIRS_FILTERED}) -${SUBDIRS_DEPEND}: database/database.h +${SUBDIRS_DEPEND}: ${DATABASE_H} @echo --- making dependencies @d=$(dir $@); mkdir -p $$d && ${MAKE} -C $$d -f ${MAGICSRC}/$${d}Makefile depend @@ -162,7 +164,7 @@ distclean: ${RM} defs.mak old.defs.mak ${RM} scripts/makedbh scripts/default.conf ${RM} config.log config.status - ${RM} database/database.h + ${RM} ${DATABASE_H} ${RM} scripts/magic.spec magic-${VERSION} magic-${VERSION}.tgz ${RM} *.log diff --git a/database/Makefile b/database/Makefile index a8fb133f..d9115015 100644 --- a/database/Makefile +++ b/database/Makefile @@ -25,8 +25,9 @@ LIB_OBJS += ${MAGICDIR}/tiles/libtiles.o ${MAGICDIR}/utils/libutils.o # start of top level build) and removed last (near the end of a top level clean). #CLEANS += database.h -# This is delegated back to the top level Makefile -database.h: ${MAGICDIR}/database/database.h.in - ${MAKE} -C ${MAGICDIR} database/database.h +# This is delegated back to the top level Makefile, which owns ${DATABASE_H} +# (its location varies with in-tree vs relocated builds -- see defs.mak GENINC). +database.h: ${MAGICSRC}/database/database.h.in + ${MAKE} -C ${MAGICDIR} $(patsubst ${MAGICDIR}/%,%,${DATABASE_H}) include ${MAGICDIR}/rules.mak diff --git a/scripts/defs.mak.in b/scripts/defs.mak.in index 7c34faf3..44bd6ab0 100755 --- a/scripts/defs.mak.in +++ b/scripts/defs.mak.in @@ -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 +# 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 "/
.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 includes, so the readline # source's parent directory must be on the include path. Only for the bundled