diff --git a/packages/swi-prolog/build.sh b/packages/swi-prolog/build.sh index 8ba64b26392777..58cd9d995b27d9 100644 --- a/packages/swi-prolog/build.sh +++ b/packages/swi-prolog/build.sh @@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Most popular and complete prolog implementation" TERMUX_PKG_LICENSE="BSD 2-Clause" TERMUX_PKG_MAINTAINER="@termux" TERMUX_PKG_VERSION="9.3.17" +TERMUX_PKG_REVISION=1 TERMUX_PKG_SRCURL=https://www.swi-prolog.org/download/devel/src/swipl-${TERMUX_PKG_VERSION}.tar.gz TERMUX_PKG_SHA256=0c091d56ea8c941e3af760af24134f60e1e06b1379af8dcd42492c82f5b3ac46 TERMUX_PKG_DEPENDS="libandroid-execinfo, libarchive, libcrypt, libgmp, libyaml, ncurses, openssl, ossp-uuid, readline, zlib, pcre2" @@ -33,6 +34,27 @@ termux_pkg_auto_update() { termux_pkg_upgrade_version "$version" } +_do_host_build() { + # Recreate host build directory because previous builds could have been + # of a different word size (e.g. 32bit or 64bit) + rm -rf "$TERMUX_PKG_HOSTBUILD_DIR" + mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR" + cd "$TERMUX_PKG_HOSTBUILD_DIR" + cmake "$TERMUX_PKG_SRCDIR" \ + -G "Ninja" \ + $CMAKE_EXTRA_DEFS \ + -DINSTALL_DOCUMENTATION=OFF \ + -DSWIPL_PACKAGES=ON \ + -DUSE_GMP=OFF \ + -DBUILD_TESTING=ON \ + -DSWIPL_SHARED_LIB=OFF \ + -DSWIPL_PACKAGES_BDB=OFF \ + -DSWIPL_PACKAGES_ODBC=OFF \ + -DSWIPL_PACKAGES_QT=OFF \ + -DSWIPL_PACKAGES_X=OFF + ninja +} + # We do this to produce: # a native host build to produce # boot.prc, INDEX.pl, ssl cetificate tests, @@ -43,32 +65,37 @@ termux_step_host_build() { termux_setup_cmake termux_setup_ninja + CMAKE_EXTRA_DEFS="" + # do an inital host build without the 32-bit flags to get a binary that can be run + # to obtain the correct value for storing in the SWIPL_ABI_FILE + # (using the 32-bit flags during the host build step and not the cross build step + # appears to be one of the causes of https://github.com/termux/termux-packages/issues/22737 ) + # however there could be other potential workarounds, one of which is explained in the thread, + # so it's hard to tell which is objectively the best solution overall. + # With this method, IF the -d flag is used on build-package.sh, that causes the runtime value + # of the swipl binary's abi_version() function to change also, but does not change the value + # detected by this host build binary, so that is an edge case where this method, as currently written, fails. + # the "convert error to warning" method from the thread would not fail that edge case, + # but in that case the actual contents of the "ABI" file and its original behavior of triggering an error + # are not respected, while this method makes an attempt to populate the "ABI" file + # with what seems like the correct value most of the time, and respect swi-prolog's original behavior of + # producing an error and closing if anything at all goes wrong with the "ABI" file. + _do_host_build + SWIPL_ABI="$("$TERMUX_PKG_HOSTBUILD_DIR"/src/swipl --abi-version)" + + # for 32-bit targets, do another host build to get + # the actual host build binaries for everything else (preserves the preexisting behavior + # of the swi-prolog package in every other way that is not the bugged "ABI" file) if [ $TERMUX_ARCH_BITS = 32 ]; then export LDFLAGS=-m32 export CFLAGS=-m32 export CXXFLAGS='-m32 -funwind-tables' CMAKE_EXTRA_DEFS="-DCMAKE_LIBRARY_PATH=/usr/lib/i386-linux-gnu" - else - CMAKE_EXTRA_DEFS="" + _do_host_build + unset LDFLAGS + unset CFLAGS + unset CXXFLAGS fi - - cmake "$TERMUX_PKG_SRCDIR" \ - -G "Ninja" \ - $CMAKE_EXTRA_DEFS \ - -DINSTALL_DOCUMENTATION=OFF \ - -DSWIPL_PACKAGES=ON \ - -DUSE_GMP=OFF \ - -DBUILD_TESTING=ON \ - -DSWIPL_SHARED_LIB=OFF \ - -DSWIPL_PACKAGES_BDB=OFF \ - -DSWIPL_PACKAGES_ODBC=OFF \ - -DSWIPL_PACKAGES_QT=OFF \ - -DSWIPL_PACKAGES_X=OFF - ninja - - unset LDFLAGS - unset CFLAGS - unset CXXFLAGS } termux_step_pre_configure() { @@ -76,7 +103,7 @@ termux_step_pre_configure() { } termux_step_post_make_install() { - # Remove host build because future builds may be - # of a different word size (e.g. 32bit or 64bit) + echo "$SWIPL_ABI" > "$TERMUX_PREFIX"/lib/swipl/ABI + # Remove host build directory to force host build step to always run rm -rf "$TERMUX_PKG_HOSTBUILD_DIR" }