Skip to content

Commit 25a07d3

Browse files
committed
unix: improve ncurses cross-compiling
Previously, cross-compiles only worked on Apple and x86_64 -> i686. Upcoming commits to introduce ARM Linux cross-compiles uncovered more issues. This commit contains changes to work around those. We have to save and restore CC to get the host build to use the correct compiler. We also need to munge the path to the host compiler to use the host GCC present in the new cross-compile environment. And we need to disable application stripping, since `strip` doesn't recognize the target. This is probably the hackiest change. But I couldn't figure out (only spent minimal effort though) on how to get ncurses's build system to use the correct `strip` binary.
1 parent aeb1eae commit 25a07d3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

cpython-unix/build-ncurses.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ tar -xf ncurses-${NCURSES_VERSION}.tar.gz
1919
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
2020
echo "building host ncurses to provide modern tic for cross-compile"
2121

22+
OLD_CC=${CC}
23+
unset CC
24+
2225
pushd ncurses-${NCURSES_VERSION}
2326
./configure --prefix=${TOOLS_PATH}/host --without-cxx --without-tests --without-manpages --enable-widec
2427
make -j ${NUM_CPUS}
2528
make -j ${NUM_CPUS} install
2629

30+
export CC=${OLD_CC}
31+
2732
popd
2833

2934
# Nuke and re-pave the source directory.
@@ -33,18 +38,32 @@ fi
3338

3439
pushd ncurses-${NCURSES_VERSION}
3540

41+
# `make install` will strip installed programs (like tic) by default. This is
42+
# fine. However, cross-compiles can run into issues where `strip` doesn't
43+
# recognize the target architecture. We could fix this by overriding strip.
44+
# But we don't care about the installed binaries, so we simply disable
45+
# stripping of the binaries.
3646
CONFIGURE_FLAGS="
3747
--build=${BUILD_TRIPLE}
3848
--host=${TARGET_TRIPLE}
3949
--prefix=/tools/deps
4050
--without-cxx
4151
--without-tests
4252
--without-manpages
53+
--disable-stripping
4354
--enable-widec"
4455

45-
# ncurses wants --with-build-cc when cross-compiling.
56+
# ncurses wants --with-build-cc when cross-compiling. But it insists on CC
57+
# and this value not being equal, even though using the same binary with
58+
# different compiler flags is doable!
4659
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
47-
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=${TOOLS_PATH}/${TOOLCHAIN}/bin/clang"
60+
# Look for and use our Clang toolchain by default. If not present, fall
61+
# back to likely path to system GCC.
62+
if [ -e "${TOOLS_PATH}/${TOOLCHAIN}/bin/clang" ]; then
63+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=${TOOLS_PATH}/${TOOLCHAIN}/bin/clang"
64+
else
65+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=/usr/bin/x86_64-linux-gnu-gcc"
66+
fi
4867
fi
4968

5069
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then

0 commit comments

Comments
 (0)