Skip to content

Commit

Permalink
unix: install m4 and autoconf
Browse files Browse the repository at this point in the history
A future commit will introduce patches to configure.ac, which means we
need to run autoconf. As macOS doesn't provide a sufficient autoconf
and we want to use the same version of autoconf everywhere, it makes
sense to build autoconf from source for all targets.

So this commit does that.

Autoconf requires m4, so we need to build and install m4 as well.
  • Loading branch information
indygreg committed Oct 2, 2022
1 parent 069a157 commit 7b0bd9b
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cpython-unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ endif

toolchain: $(TOOLCHAIN_TARGET)

AUTOCONF_DEPENDS = \
$(PYTHON_DEP_DEPENDS) \
$(HERE)/build-autoconf.sh \
$(OUTDIR)/m4-$(M4_VERSION)-$(PACKAGE_SUFFIX).tar \
$(NULL)

$(OUTDIR)/autoconf-$(AUTOCONF_VERSION)-$(PACKAGE_SUFFIX).tar: $(AUTOCONF_DEPENDS)
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) autoconf

$(OUTDIR)/bdb-$(BDB_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-bdb.sh
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) bdb

Expand Down Expand Up @@ -147,6 +156,9 @@ LIBXCB_DEPENDS = \
$(OUTDIR)/libxcb-$(LIBXCB_VERSION)-$(PACKAGE_SUFFIX).tar: $(LIBXCB_DEPENDS)
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_XCB) libxcb

$(OUTDIR)/m4-$(M4_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-m4.sh
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) m4

$(OUTDIR)/ncurses-$(NCURSES_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-ncurses.sh
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) ncurses

Expand Down Expand Up @@ -229,11 +241,13 @@ PYTHON_DEPENDS := \
$(PYTHON_SUPPORT_FILES) \
$(OUTDIR)/versions/VERSION.pip \
$(OUTDIR)/versions/VERSION.setuptools \
$(if $(NEED_AUTOCONF),$(OUTDIR)/autoconf-$(AUTOCONF_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_BDB),$(OUTDIR)/bdb-$(BDB_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_BZIP2),$(OUTDIR)/bzip2-$(BZIP2_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_GDBM),$(OUTDIR)/gdbm-$(GDBM_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_LIBEDIT),$(OUTDIR)/libedit-$(LIBEDIT_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_LIBFFI),$(OUTDIR)/libffi-$(LIBFFI_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_m4),$(OUTDIR)/m4-$(M4_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_NCURSES),$(OUTDIR)/ncurses-$(NCURSES_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_OPENSSL),$(OUTDIR)/openssl-$(OPENSSL_VERSION)-$(PACKAGE_SUFFIX).tar) \
$(if $(NEED_PATCHELF),$(OUTDIR)/patchelf-$(PATCHELF_VERSION)-$(PACKAGE_SUFFIX).tar) \
Expand Down
21 changes: 21 additions & 0 deletions cpython-unix/build-autoconf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

set -ex

ROOT=`pwd`

export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH

tar -xf autoconf-${AUTOCONF_VERSION}.tar.gz

pushd autoconf-${AUTOCONF_VERSION}

CC="${HOST_CC}" CXX="${HOST_CXX}" CFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure \
--build=${BUILD_TRIPLE} \
--prefix=/tools/host

make -j ${NUM_CPUS}
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out
20 changes: 20 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:${TOOLS_PATH}/
# environment variable.
export LLVM_PROFDATA=${TOOLS_PATH}/${TOOLCHAIN}/bin/llvm-profdata

# autoconf has some paths hardcoded into scripts. These paths just work in
# the containerized build environment. But from macOS the paths are wrong.
# Explicitly point to the proper path via environment variable overrides.
export AUTOCONF=${TOOLS_PATH}/host/bin/autoconf
export AUTOHEADER=${TOOLS_PATH}/host/bin/autoheader
export AUTOM4TE=${TOOLS_PATH}/host/bin/autom4te
export autom4te_perllibdir=${TOOLS_PATH}/host/share/autoconf
export AC_MACRODIR=${TOOLS_PATH}/host/share/autoconf
export M4=${TOOLS_PATH}/host/bin/m4

# The share/autoconf/autom4te.cfg file also hard-codes some paths. Rewrite
# those to the real tools path.
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
sed_args="-i '' -e"
else
sed_args="-i"
fi

sed ${sed_args} "s|/tools/host|${TOOLS_PATH}/host|g" ${TOOLS_PATH}/host/share/autoconf/autom4te.cfg

# We force linking of external static libraries by removing the shared
# libraries. This is hacky. But we're building in a temporary container
# and it gets the job done.
Expand Down
21 changes: 21 additions & 0 deletions cpython-unix/build-m4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

set -ex

ROOT=`pwd`

export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH

tar -xf m4-${M4_VERSION}.tar.xz

pushd m4-${M4_VERSION}

CC="${HOST_CC}" CXX="${HOST_CXX}" CFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_HOST_CFLAGS} -fPIC" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure \
--build=${BUILD_TRIPLE} \
--prefix=/tools/host

make -j ${NUM_CPUS}
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out
17 changes: 16 additions & 1 deletion cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,20 @@ def main():
elif action == "musl":
build_musl(client, get_image(client, ROOT, BUILD, "gcc"), host_platform)

elif action == "autoconf":
simple_build(
settings,
client,
get_image(client, ROOT, BUILD, docker_image),
action,
host_platform=host_platform,
target_triple=target_triple,
optimizations=optimizations,
dest_archive=dest_archive,
tools_path="host",
extra_archives=["m4"],
)

elif action == "libedit":
build_libedit(
settings,
Expand Down Expand Up @@ -1014,6 +1028,7 @@ def main():
"kbproto",
"libffi",
"libpthread-stubs",
"m4",
"ncurses",
"openssl",
"patchelf",
Expand All @@ -1028,7 +1043,7 @@ def main():
"xz",
"zlib",
):
tools_path = "host" if action == "patchelf" else "deps"
tools_path = "host" if action in ("m4", "patchelf") else "deps"

simple_build(
settings,
Expand Down
Loading

0 comments on commit 7b0bd9b

Please sign in to comment.