build: generate <magic/autoconf/config.h> from configure
Emit an autoconf config header carrying every autoconf define -- at least
all the -D options that appear on the compiler command lines, plus
anything else configure knows -- available to the tree as
#include <magic/autoconf/config.h>
It is built directly from confdefs.h just before AC_OUTPUT (which removes
that file), NOT via AC_CONFIG_HEADERS. This is deliberate:
* AC_CONFIG_HEADERS would rewrite @DEFS@ to -DHAVE_CONFIG_H and move the
defines into the header, changing every compiler command line and
breaking the build until sources #include it. Building from confdefs.h
leaves @DEFS@ (and the whole build) exactly as-is, so the header is a
pure additional artifact with no consumers yet.
* confdefs.h already holds every AC_DEFINE, including the many that have
no autoheader template (CALMA_MODULE, HAVE_READLINE, ...), which
AC_CONFIG_HEADERS/autoheader would have dropped.
Location mirrors the generated database.h (defs.mak GENINC): magic/autoconf/
config.h at the build top when in-tree (build dir == source dir), else
include/magic/autoconf/config.h so the clean -I include/ rule finds it and
the raw build dir stays off the search path. The directory is created on
demand and the header is rewritten on every ./configure. No defs.mak.in
change is needed -- the existing -I${GENINC} already resolves it.
.gitignore: ignore the in-tree magic/autoconf/config.h (out-of-tree it is
under the build dir and already ignored).
Verified: out-of-tree writes include/magic/autoconf/config.h, in-tree
writes magic/autoconf/config.h; both contain the command-line defines
(SIZEOF_VOID_P, CALMA_MODULE, HAVE_*, ...); #include <magic/autoconf/
config.h> resolves via -I${GENINC} from a subdir; @DEFS@ is unchanged
(-DHAVE_CONFIG_H absent) and modules still build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b21b20364b
commit
64d2ad8df7
|
|
@ -22,6 +22,9 @@ reconfigure.sh
|
|||
*/Depend*.tmp
|
||||
.deps/
|
||||
database/database.h
|
||||
# autoconf config header, generated by ./configure (in-tree location; out-of-tree
|
||||
# it lives under the build dir's include/ and is covered by the build-dir rules).
|
||||
magic/autoconf/config.h
|
||||
|
||||
# Editor / OS cruft
|
||||
.*.swp
|
||||
|
|
|
|||
|
|
@ -9398,6 +9398,24 @@ ac_config_files="$ac_config_files scripts/makedbh:scripts/makedbh.in"
|
|||
|
||||
ac_config_files="$ac_config_files rules.mak:rules.mak"
|
||||
|
||||
|
||||
if test "`cd $srcdir && pwd`" = "`pwd`" ; then
|
||||
magic_config_header=magic/autoconf/config.h
|
||||
else
|
||||
magic_config_header=include/magic/autoconf/config.h
|
||||
fi
|
||||
mkdir -p "`dirname $magic_config_header`"
|
||||
{
|
||||
echo "/* $magic_config_header -- generated by configure; DO NOT EDIT. */"
|
||||
echo "/* Every autoconf define (>= all -D options on the compiler lines). */"
|
||||
echo "#ifndef _MAGIC_AUTOCONF_CONFIG_H"
|
||||
echo "#define _MAGIC_AUTOCONF_CONFIG_H 1"
|
||||
grep '^#define ' confdefs.h | sort -u
|
||||
echo "#endif /* _MAGIC_AUTOCONF_CONFIG_H */"
|
||||
} > "$magic_config_header"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: created config header $magic_config_header" >&5
|
||||
$as_echo "$as_me: created config header $magic_config_header" >&6;}
|
||||
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
# tests run on this system so they can be shared between configure
|
||||
|
|
|
|||
|
|
@ -2002,6 +2002,38 @@ dnl Copy rules.mak into the build top (it has no @...@ substitutions; this just
|
|||
dnl places it next to the generated defs.mak so a single ${MAGICDIR} resolves
|
||||
dnl both `include`s in every subdir Makefile out-of-tree).
|
||||
AC_CONFIG_FILES([rules.mak:rules.mak])
|
||||
|
||||
dnl Emit an autoconf config header, available to the tree as
|
||||
dnl #include <magic/autoconf/config.h>
|
||||
dnl It carries every autoconf define (i.e. at least all the -D options that
|
||||
dnl appear on the compiler command lines, plus anything else configure knows).
|
||||
dnl We build it here, from confdefs.h, rather than via AC_CONFIG_HEADERS on
|
||||
dnl purpose: that keeps @DEFS@ (hence the command lines and the whole build)
|
||||
dnl exactly as-is, so the header is a pure additional artifact with no consumers
|
||||
dnl yet. confdefs.h holds every AC_DEFINE and is still present at this point
|
||||
dnl (AC_OUTPUT removes it), so it must run before AC_OUTPUT.
|
||||
dnl
|
||||
dnl Location mirrors the generated database.h (see defs.mak GENINC): at the
|
||||
dnl build top when in-tree (build dir == source dir), else under a clean
|
||||
dnl include/ subdir so the -I include/ rule finds <magic/autoconf/config.h> and
|
||||
dnl the raw build dir is never on the search path. Regenerated on every
|
||||
dnl ./configure; the directory is created on demand.
|
||||
if test "`cd $srcdir && pwd`" = "`pwd`" ; then
|
||||
magic_config_header=magic/autoconf/config.h
|
||||
else
|
||||
magic_config_header=include/magic/autoconf/config.h
|
||||
fi
|
||||
mkdir -p "`dirname $magic_config_header`"
|
||||
{
|
||||
echo "/* $magic_config_header -- generated by configure; DO NOT EDIT. */"
|
||||
echo "/* Every autoconf define (>= all -D options on the compiler lines). */"
|
||||
echo "#ifndef _MAGIC_AUTOCONF_CONFIG_H"
|
||||
echo "#define _MAGIC_AUTOCONF_CONFIG_H 1"
|
||||
grep '^#define ' confdefs.h | sort -u
|
||||
echo "#endif /* _MAGIC_AUTOCONF_CONFIG_H */"
|
||||
} > "$magic_config_header"
|
||||
AC_MSG_NOTICE([created config header $magic_config_header])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
dnl
|
||||
|
|
|
|||
Loading…
Reference in New Issue