build: make configure relocatable (out-of-tree)

Enable `mkdir build; cd build; ../configure` to run entirely in the build
directory, with generated config landing there instead of in the source
tree.  This is the autoconf-layer groundwork for a full VPATH build; the
make layer (defs.mak/rules.mak VPATH support, per-dir orchestration) is
still to come, so an out-of-tree `make` is not yet expected to work.

Changes:

* configure (wrapper): run the generated config.status in the *current*
  directory with --srcdir pointing back at the source tree (instead of
  `cd scripts`), so outputs land in the build dir.  Uses an absolute
  basedir so any build-dir location works, not just a subdir of srcdir.

* scripts/configure.in:
  - AC_CONFIG_AUX_DIR(.) -> AC_CONFIG_AUX_DIR(scripts).  Once srcdir
    resolves to the true top (scripts' parent, where rules.mak lives),
    autoconf searches for install-sh/config.sub/... relative to srcdir;
    "." pointed at the wrong place and out-of-tree configure died with
    "cannot find install-sh".
  - Name the .in templates explicitly
    (defs.mak:scripts/defs.mak.in, scripts/makedbh:scripts/makedbh.in)
    so config.status finds them from a separate build dir.  defs.mak is
    written to the build top; makedbh under build/scripts/ to match
    ${SCRIPTS}/makedbh.
  - Drop the trailing `cp defs.mak ..`; defs.mak is now generated in the
    build top directly, and from a build dir the copy would clobber the
    source tree's defs.mak.

* scripts/configure: regenerated with autoconf 2.69.

Verified: out-of-tree `../configure` completes rc=0, writes defs.mak /
scripts/makedbh / config.status into the build dir, records
srcdir=<source top>, and leaves the source tree's tracked files and
generated defs.mak/makedbh untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Darryl L. Miles 2026-07-22 12:20:59 +00:00 committed by R. Timothy Edwards
parent 0518b6914a
commit a4e6289035
3 changed files with 29 additions and 28 deletions

8
configure vendored
View File

@ -9,5 +9,9 @@
# script itself. It also sets up CFLAGS without the default optimizer
# flag (-O2).
basedir=$(dirname "$0")
( CFLAGS=${CFLAGS:-"-g"}; export CFLAGS; cd "${basedir}/scripts" ; ./configure "$@" )
# Run the generated config.status in the *current* directory (which may be a
# separate build directory), with --srcdir pointing back at the source tree, so
# that generated files (defs.mak, makedbh, ...) land in the build directory
# rather than in the source tree.
basedir=$(cd "$(dirname "$0")" && pwd)
( CFLAGS=${CFLAGS:-"-g"}; export CFLAGS; exec "${basedir}/scripts/configure" --srcdir="${basedir}" "$@" )

29
scripts/configure vendored
View File

@ -734,7 +734,6 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
@ -843,7 +842,6 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
@ -1096,15 +1094,6 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1242,7 +1231,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir runstatedir
libdir localedir mandir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@ -1395,7 +1384,6 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@ -2598,7 +2586,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_aux_dir=
for ac_dir in . "$srcdir"/.; do
for ac_dir in scripts "$srcdir"/scripts; do
if test -f "$ac_dir/install-sh"; then
ac_aux_dir=$ac_dir
ac_install_sh="$ac_aux_dir/install-sh -c"
@ -2614,7 +2602,7 @@ for ac_dir in . "$srcdir"/.; do
fi
done
if test -z "$ac_aux_dir"; then
as_fn_error $? "cannot find install-sh, install.sh, or shtool in . \"$srcdir\"/." "$LINENO" 5
as_fn_error $? "cannot find install-sh, install.sh, or shtool in scripts \"$srcdir\"/scripts" "$LINENO" 5
fi
# These three variables are undocumented and unsupported,
@ -9308,9 +9296,9 @@ MAKE_CAIRO=$usingCairo
MAKE_READLINE=$use_bundled_readline
ac_config_files="$ac_config_files defs.mak"
ac_config_files="$ac_config_files defs.mak:scripts/defs.mak.in"
ac_config_files="$ac_config_files makedbh"
ac_config_files="$ac_config_files scripts/makedbh:scripts/makedbh.in"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@ -10019,8 +10007,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"defs.mak") CONFIG_FILES="$CONFIG_FILES defs.mak" ;;
"makedbh") CONFIG_FILES="$CONFIG_FILES makedbh" ;;
"defs.mak") CONFIG_FILES="$CONFIG_FILES defs.mak:scripts/defs.mak.in" ;;
"scripts/makedbh") CONFIG_FILES="$CONFIG_FILES scripts/makedbh:scripts/makedbh.in" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
@ -10441,7 +10429,7 @@ which seems to be undefined. Please make sure it is defined" >&2;}
case $ac_file$ac_mode in
"makedbh":F) chmod +x makedbh ;;
"scripts/makedbh":F) chmod +x scripts/makedbh ;;
esac
done # for ac_tag
@ -10591,4 +10579,3 @@ echo
echo "-----------------------------------------------------------"
echo
cp defs.mak ..

View File

@ -4,7 +4,12 @@ dnl Use autoconf 2.52 or newer.
AC_INIT(magic,, magic-hackers@csl.cornell.edu)
AC_PREREQ(2.52)
AC_CONFIG_SRCDIR(rules.mak)
AC_CONFIG_AUX_DIR(.)
dnl configure.in lives in scripts/, but the source root is its parent (that is
dnl where rules.mak is, so srcdir resolves there). The aux scripts (install-sh,
dnl config.sub, config.guess, missing, mkinstalldirs) live in scripts/, which is
dnl "scripts" relative to that srcdir -- not ".". Using "." breaks out-of-tree
dnl configure with "cannot find install-sh".
AC_CONFIG_AUX_DIR(scripts)
AC_CANONICAL_SYSTEM
@ -1971,8 +1976,12 @@ AC_SUBST(MAKE_GLU, [$usingGLU])
AC_SUBST(MAKE_CAIRO, [$usingCairo])
AC_SUBST(MAKE_READLINE, [$use_bundled_readline])
AC_CONFIG_FILES([defs.mak])
AC_CONFIG_FILES([makedbh], [chmod +x makedbh])
dnl Name the .in templates explicitly (relative to srcdir) so config.status can
dnl find them when run from a separate build directory. Outputs land in the
dnl build directory (config.status' CWD): defs.mak at the build top, makedbh
dnl under build/scripts/ (matching ${SCRIPTS}/makedbh = ${MAGICDIR}/scripts).
AC_CONFIG_FILES([defs.mak:scripts/defs.mak.in])
AC_CONFIG_FILES([scripts/makedbh:scripts/makedbh.in], [chmod +x scripts/makedbh])
AC_OUTPUT
dnl
@ -2087,5 +2096,6 @@ echo
echo "-----------------------------------------------------------"
echo
dnl Put "defs.mak" in the top-level directory
cp defs.mak ..
dnl "defs.mak" is now generated directly into the build top (config.status'
dnl CWD), so the old `cp defs.mak ..` is gone -- from a separate build directory
dnl it would clobber the source tree's copy.