2020-06-20 21:43:34 +02:00
|
|
|
# Utility function to setup a GHC toolchain.
|
|
|
|
termux_setup_ghc() {
|
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
2022-03-07 11:26:29 +01:00
|
|
|
local TERMUX_GHC_VERSION=8.10.7
|
2020-06-20 21:43:34 +02:00
|
|
|
local TERMUX_GHC_TEMP_FOLDER="${TERMUX_COMMON_CACHEDIR}/ghc-${TERMUX_GHC_VERSION}"
|
|
|
|
local TERMUX_GHC_TAR="${TERMUX_GHC_TEMP_FOLDER}.tar.xz"
|
2020-10-22 21:45:33 +02:00
|
|
|
local TERMUX_GHC_RUNTIME_FOLDER
|
|
|
|
|
|
|
|
if [ "${TERMUX_PACKAGES_OFFLINE-false}" = "true" ]; then
|
|
|
|
TERMUX_GHC_RUNTIME_FOLDER="${TERMUX_SCRIPTDIR}/build-tools/ghc-${TERMUX_GHC_VERSION}-runtime"
|
|
|
|
else
|
|
|
|
TERMUX_GHC_RUNTIME_FOLDER="${TERMUX_COMMON_CACHEDIR}/ghc-${TERMUX_GHC_VERSION}-runtime"
|
|
|
|
fi
|
2020-06-20 21:43:34 +02:00
|
|
|
|
|
|
|
export PATH="$TERMUX_GHC_RUNTIME_FOLDER/bin:$PATH"
|
|
|
|
|
2022-03-07 11:26:29 +01:00
|
|
|
[ -d "$TERMUX_GHC_RUNTIME_FOLDER" ] && return
|
2020-06-20 21:43:34 +02:00
|
|
|
|
|
|
|
termux_download "https://downloads.haskell.org/~ghc/${TERMUX_GHC_VERSION}/ghc-${TERMUX_GHC_VERSION}-x86_64-deb10-linux.tar.xz" \
|
|
|
|
"$TERMUX_GHC_TAR" \
|
2022-03-07 11:26:29 +01:00
|
|
|
a13719bca87a0d3ac0c7d4157a4e60887009a7f1a8dbe95c4759ec413e086d30
|
2020-06-20 21:43:34 +02:00
|
|
|
|
|
|
|
rm -Rf "$TERMUX_GHC_TEMP_FOLDER"
|
|
|
|
tar xf "$TERMUX_GHC_TAR" -C "$TERMUX_COMMON_CACHEDIR"
|
|
|
|
|
2022-03-07 11:26:29 +01:00
|
|
|
(
|
|
|
|
set -e
|
2020-06-20 21:43:34 +02:00
|
|
|
unset CC CXX CFLAGS CXXFLAGS CPPFLAGS LDFLAGS AR AS CPP LD RANLIB READELF STRIP
|
|
|
|
cd "$TERMUX_GHC_TEMP_FOLDER"
|
|
|
|
./configure --prefix="$TERMUX_GHC_RUNTIME_FOLDER"
|
|
|
|
make install
|
|
|
|
)
|
|
|
|
|
2022-03-07 11:26:29 +01:00
|
|
|
# Cabal passes a host string to the libraries' configure scripts that isn't valid.
|
|
|
|
# After this patch we need to always pass --configure-option=--host=${TERMUX_HOST_PLATFORM}
|
|
|
|
# to Setup.hs configure.
|
|
|
|
(
|
|
|
|
CABAL_TEMP_FOLDER="$(mktemp -d cabal.XXXXXX)"
|
|
|
|
cd "${CABAL_TEMP_FOLDER}"
|
|
|
|
|
|
|
|
mkdir -p Cabal-3.6.2.0
|
|
|
|
curl -Ls \
|
|
|
|
https://hackage.haskell.org/package/Cabal-3.6.2.0/Cabal-3.6.2.0.tar.gz |
|
|
|
|
tar xzf - -C Cabal-3.6.2.0 --strip-components=1
|
|
|
|
|
|
|
|
cd Cabal-3.6.2.0
|
|
|
|
sed -i 's/maybeHostFlag = i/maybeHostFlag = [] -- i/' src/Distribution/Simple.hs
|
|
|
|
|
|
|
|
runhaskell Setup configure --prefix="${TERMUX_GHC_RUNTIME_FOLDER}"
|
|
|
|
runhaskell Setup build
|
|
|
|
runhaskell Setup install
|
|
|
|
ghc-pkg recache
|
|
|
|
)
|
|
|
|
rm -Rf "$TERMUX_GHC_TEMP_FOLDER" "$TERMUX_GHC_TAR"
|
2020-06-20 21:43:34 +02:00
|
|
|
else
|
2022-02-02 15:45:36 +01:00
|
|
|
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' ghc 2>/dev/null)" != "installed" ]] ||
|
2022-03-07 11:26:29 +01:00
|
|
|
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q ghc 2>/dev/null)" ]]; then
|
2020-06-20 21:43:34 +02:00
|
|
|
echo "Package 'ghc' is not installed."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|