Skip to content

Commit 51a442d

Browse files
committed
macos: build gettext from source
Python's configure searches for a usable libintl, which is provided by gettext. If you have a libintl shared library on your system, configure will pick it up and add a dynamic library dependency on it, making binaries non-portable. To work around this, we build gettext from source and have Python statically link against its libintl. The configure workaround feels a bit shady to me. I'm not sure why the test program finding the textdomain symbol fails to build. But we can link against libintl.a and Python functions calling into it seem to work. So who knows.
1 parent 3aa4306 commit 51a442d

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

cpython-unix/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ifeq ($(HOST_PLATFORM),linux64)
4545
NEED_GCC := 1
4646
NEED_MUSL :=
4747
NEED_GDBM := 1
48+
NEED_GETTEXT :=
4849
NEED_X11 := 1
4950
NEED_READLINE := 1
5051
NEED_TIX := 1
@@ -55,6 +56,7 @@ ifeq ($(HOST_PLATFORM),macos)
5556
NEED_GCC :=
5657
NEED_MUSL :=
5758
NEED_GDBM :=
59+
NEED_GETTEXT := 1
5860
NEED_X11 :=
5961
NEED_READLINE :=
6062
NEED_TIX := 1
@@ -128,6 +130,9 @@ $(OUTDIR)/bzip2-$(BZIP2_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(
128130
$(OUTDIR)/gdbm-$(GDBM_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-gdbm.sh
129131
$(RUN_BUILD) gdbm
130132

133+
$(OUTDIR)/gettext-$(GETTEXT_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-gettext.sh
134+
$(RUN_BUILD) gettext
135+
131136
$(OUTDIR)/inputproto-$(INPUTPROTO_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-inputproto.sh
132137
$(RUN_BUILD) inputproto
133138

@@ -260,6 +265,7 @@ PYTHON_DEPENDS := \
260265
$(OUTDIR)/bdb-$(BDB_VERSION)-$(PACKAGE_SUFFIX).tar \
261266
$(OUTDIR)/bzip2-$(BZIP2_VERSION)-$(PACKAGE_SUFFIX).tar \
262267
$(if $(NEED_GDBM),$(OUTDIR)/gdbm-$(GDBM_VERSION)-$(PACKAGE_SUFFIX).tar) \
268+
$(if $(NEED_GETTEXT),$(OUTDIR)/gettext-$(GETTEXT_VERSION)-$(PACKAGE_SUFFIX).tar) \
263269
$(OUTDIR)/libedit-$(LIBEDIT_VERSION)-$(PACKAGE_SUFFIX).tar \
264270
$(OUTDIR)/libffi-$(LIBFFI_VERSION)-$(PACKAGE_SUFFIX).tar \
265271
$(if $(NEED_LIBRESSL),$(OUTDIR)/libressl-$(LIBRESSL_VERSION)-$(PACKAGE_SUFFIX).tar) \

cpython-unix/build-cpython.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ if [ -n "${CPYTHON_LTO}" ]; then
242242
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-lto"
243243
fi
244244

245+
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
246+
# Configure fails to find the textdomain symbol with our libintl
247+
# for some reason. So force it.
248+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_lib_intl_textdomain=yes"
249+
fi
250+
245251
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \
246252
./configure ${CONFIGURE_FLAGS}
247253

cpython-unix/build-gettext.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
set -ex
7+
8+
ROOT=`pwd`
9+
10+
export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH
11+
12+
tar -xf gettext-${GETTEXT_VERSION}.tar.gz
13+
14+
pushd gettext-${GETTEXT_VERSION}
15+
16+
# If libunistring exists on the system, it can get picked up and introduce
17+
# an added dependency. So we force use of the bundled version.
18+
CLFAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \
19+
--build=${BUILD_TRIPLE} \
20+
--target=${TARGET_TRIPLE} \
21+
--prefix=/tools/deps \
22+
--disable-shared \
23+
--disable-java \
24+
--disable-dependency-tracking \
25+
--with-included-libcroco \
26+
--with-included-gettext \
27+
--with-included-glib \
28+
--with-included-libunistring \
29+
--with-included-libxml \
30+
--without-libiconv-prefix \
31+
--without-libintl-prefix \
32+
--without-libncurses-prefix \
33+
--without-libtermcap-prefix \
34+
--without-libxcurses-prefix \
35+
--without-libcurses-prefix \
36+
--without-libtextstyle-prefix \
37+
--without-libunistring-prefix \
38+
--without-libxml2-prefix \
39+
--without-git
40+
41+
make -j ${NUM_CPUS}
42+
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out

cpython-unix/build.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,17 @@ def process_setup_line(line, variant=None):
498498
else:
499499
links.append({"name": libname, "system": True})
500500

501+
if platform == "macos":
502+
# For some reason, Python's build system adds libintl as a link
503+
# against libpythonX.Y/pythonX.Y instead of the _locale extension
504+
# despite the _location extension being the only user of its
505+
# symbols. We add libintl here to work around that.
506+
links.append({"name": "intl", "path_static": "build/lib/libintl.a"})
507+
508+
# And symbols in our built libintl reference iconv symbols. So we
509+
# need to include that dependency as well.
510+
links.append({"name": "iconv", "system": True})
511+
501512
entry = {
502513
"in_core": False,
503514
"init_fn": "PyInit_%s" % extension,
@@ -663,6 +674,10 @@ def build_cpython(
663674
if ncurses:
664675
packages.add("ncurses")
665676

677+
gettext = host_platform == "macos"
678+
if gettext:
679+
packages.add("gettext")
680+
666681
readline = host_platform != "macos"
667682
if readline:
668683
packages.add("readline")
@@ -921,6 +936,7 @@ def main():
921936
"bdb",
922937
"bzip2",
923938
"gdbm",
939+
"gettext",
924940
"inputproto",
925941
"kbproto",
926942
"libffi",

pythonbuild/downloads.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
"licenses": ["GPL-3.0-or-later"],
8686
"license_file": "LICENSE.gdbm.txt",
8787
},
88+
"gettext": {
89+
"url": "https://ftp.gnu.org/pub/gnu/gettext/gettext-0.21.tar.gz",
90+
"size": 24181849,
91+
"sha256": "c77d0da3102aec9c07f43671e60611ebff89a996ef159497ce8e59d075786b12",
92+
"version": "0.21",
93+
},
8894
# gmp 6.2 does not build on wheezy.
8995
"gmp": {
9096
"url": "https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz",

0 commit comments

Comments
 (0)