TERMUX_PKG_HOMEPAGE=https://www.haskell.org/ghc/ TERMUX_PKG_DESCRIPTION="The Glasgow Haskell Compilation system" TERMUX_PKG_LICENSE="BSD 2-Clause, BSD 3-Clause, LGPL-2.1" TERMUX_PKG_MAINTAINER="@termux" TERMUX_PKG_VERSION=8.10.1 TERMUX_PKG_REVISION=6 TERMUX_PKG_SRCURL=http://downloads.haskell.org/~ghc/${TERMUX_PKG_VERSION}/ghc-${TERMUX_PKG_VERSION}-src.tar.xz TERMUX_PKG_SHA256=4e3b07f83a266b3198310f19f71e371ebce97c769b14f0d688f4cbf2a2a1edf5 TERMUX_PKG_DEPENDS="binutils, clang, iconv, libffi, llvm, ncurses" TERMUX_PKG_BUILD_IN_SRC=true TERMUX_PKG_NO_STATICSPLIT=true TERMUX_PKG_EXTRA_CONFIGURE_ARGS=" --disable-ld-override --build=x86_64-unknown-linux --host=x86_64-unknown-linux" TERMUX_PKG_BLACKLISTED_ARCHES="arm" DYNAMIC_GHC_PROGRAMS=NO termux_step_pre_configure() { termux_setup_ghc _WRAPPER_BIN=$TERMUX_PKG_BUILDDIR/_wrapper/bin mkdir -p $_WRAPPER_BIN _WRAPPER_AR=$_WRAPPER_BIN/$TERMUX_HOST_PLATFORM-ar cat > $_WRAPPER_AR <<-EOF #!$(command -v sh) exec $(command -v $AR) "\$@" EOF chmod 0700 $_WRAPPER_AR for cmd in llc opt; do local wrapper="$_WRAPPER_BIN/$cmd" cat > "$wrapper" <<-EOF #!$(command -v sh) exec /usr/lib/llvm-10/bin/${cmd} "\$@" EOF chmod 0700 "$wrapper" done export PATH=$_WRAPPER_BIN:$PATH TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --target=${TERMUX_HOST_PLATFORM}" # After stage 0, cabal passes a host string to the libraries' configure scripts that isn't valid. # We set one ourselves anyway, so this simply isn't needed. sed -i 's/maybeHostFlag = i/maybeHostFlag = [] -- i/' libraries/Cabal/Cabal/Distribution/Simple.hs # Android will only run PIE executables, so --no-pie, like GHC suggests, is out. GHC relies on relocations. # Combine PIE and -Wl,-r together, and the linker will tell you those flags are mutually exclusive. # This poses a problem as we need both. If you let the compiler handle it, then apparently all's well. sed -i 's/"-Wl,-r"/"-r"/' compiler/main/DriverPipeline.hs cp mk/build.mk.sample mk/build.mk cat >> mk/build.mk <<-EOF SRC_HC_OPTS += -optc-Wno-unused-label -optc-Wno-unused-but-set-variable SRC_HC_OPTS += -optc-Wno-unused-variable -optc-Wno-unused-function SRC_HC_OPTS += -optc-Wno-unused-command-line-argument -optc-Wno-unknown-warning-option GhcStage2HcOpts += -optl-Wl,--enable-new-dtags INTEGER_LIBRARY = integer-simple SplitSections = YES BuildFlavour = quick-cross HADDOCK_DOCS = NO BUILD_SPHINX_HTML = NO BUILD_SPHINX_PS = NO BUILD_SPHINX_PDF = NO DYNAMIC_GHC_PROGRAMS = $DYNAMIC_GHC_PROGRAMS GhcLibWays = v BUILD_MAN = NO #STRIP_CMD = $STRIP EOF # If choosing to build a GHC dynamically linked to its libs, then # $TERMUX_PREFIX/lib automatically gets added to the rpath that's generated if [ "$DYNAMIC_GHC_PROGRAMS" != "YES" ]; then echo "GhcStage2HcOpts += -optl-Wl,-rpath=$TERMUX_PREFIX/lib" >> mk/build.mk fi # So... this is fun. If these options are initially passed to the configure script, # then building stage 0 breaks, because it's meant to run on the host with the # host's libs. But of course, we need to link to Termux's libffi etc. and use the # cross-compiler when building something to run on Android in the later stages patch -Np1 </dev/null)" if [ -n "$curr_rpath" ]; then local paths_to_prepend=() local new_rpath=() IFS=':' read -ra paths <<< "$curr_rpath" for i in "${!paths[@]}"; do # Prioritise non-Haskell library paths if [[ ${paths[$i]} != *ghc-$TERMUX_PKG_VERSION* ]]; then paths_to_prepend+=("${paths[$i]}") continue fi local fixed_path="${paths[$i]/\/dist-install\/build}" if [ "$fixed_path" != "${paths[$i]}" ]; then # Naïvely correct the path to a Haskell library fixed_path="${fixed_path##*/}" fixed_path=$(echo "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/$fixed_path-"[[:digit:]]*) new_rpath+=("$fixed_path") else # This may be the path to RTS, which does not have a version number in the folder name # and nor is it apparently expected to be found in dist-install fixed_path="${paths[$i]/\/dist\/build}" if [ "$fixed_path" != "${paths[$i]}" ]; then new_rpath+=("$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/${fixed_path##*/}") else new_rpath+=("$fixed_path") fi fi done # Make sure the standard Termux library path is the first entry [[ ! " ${paths_to_prepend[@]} " =~ " $TERMUX_PREFIX/lib " ]] && paths_to_prepend=("$TERMUX_PREFIX/lib" "${paths_to_prepend[@]}") # This isn't in the original rpath at all, but is needed paths_to_prepend+=("$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/ghc-$TERMUX_PKG_VERSION") local OIFS="$IFS" local IFS=':' printf -v new_rpath "%s:%s" "${paths_to_prepend[*]}" "${new_rpath[*]}" IFS="$OIFS" patchelf --set-rpath "$new_rpath" "$bin" fi done < <(find "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/bin/" -type f -print0) fi } termux_step_install_license() { install -Dm600 -t "$TERMUX_PREFIX/share/doc/ghc" "$TERMUX_PKG_SRCDIR/LICENSE" }