refactor(ghc-libs): rename ghc to ghc-libs
- seperate ghc libraries from ghc bins - enable dynamic libs for ghc * ghc-libs is further seperated into static and dynamic packages * enabling dynamic support will reduce package size as well as there performance on device. closes #5973 Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
This commit is contained in:
parent
037adfd9ea
commit
80f7a2a0df
@ -0,0 +1,17 @@
|
||||
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
|
||||
index d222b3b..95a9942 100644
|
||||
--- a/compiler/main/DynFlags.hs
|
||||
+++ b/compiler/main/DynFlags.hs
|
||||
@@ -4662,6 +4662,12 @@ default_PIC platform =
|
||||
(OSDarwin, ArchAArch64) -> [Opt_PIC]
|
||||
(OSLinux, ArchAArch64) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
(OSLinux, ArchARM {}) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSLinux, ArchX86) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSLinux, ArchX86_64) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSUnknown, ArchARM {}) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSUnknown, ArchAArch64) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSUnknown, ArchX86) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
+ (OSUnknown, ArchX86_64) -> [Opt_PIC, Opt_ExternalDynamicRefs]
|
||||
(OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
|
||||
-- OpenBSD since 5.3 release
|
||||
-- (1 May 2013) we need to
|
@ -1,8 +1,18 @@
|
||||
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
|
||||
index b3312b0..b0e3d90 100644
|
||||
--- a/compiler/main/SysTools.hs
|
||||
+++ b/compiler/main/SysTools.hs
|
||||
@@ -414,11 +414,7 @@ linkDynLib dflags0 o_files dep_packages
|
||||
--- ghc-8.10.7/rts/package.conf.in 2021-08-18 17:30:16.000000000 +0530
|
||||
+++ ghc-8.10.7-patch/rts/package.conf.in 2022-02-02 15:19:26.221569951 +0530
|
||||
@@ -26,9 +26,7 @@
|
||||
hs-libraries: "HSrts" FFI_LIB
|
||||
|
||||
extra-libraries:
|
||||
-#if defined(HAVE_LIBM)
|
||||
"m" /* for ldexp() */
|
||||
-#endif
|
||||
#if defined(HAVE_LIBRT)
|
||||
, "rt"
|
||||
#endif
|
||||
--- ghc-8.10.7/compiler/main/SysTools.hs 2021-06-29 12:54:51.000000000 +0530
|
||||
+++ ghc-8.10.7-patch/compiler/main/SysTools.hs 2022-02-02 15:17:37.251569993 +0530
|
||||
@@ -424,11 +424,7 @@
|
||||
-- math-y things are used (which we assume to include all programs). See #14022.
|
||||
libmLinkOpts :: [Option]
|
||||
libmLinkOpts =
|
||||
@ -14,17 +24,3 @@ index b3312b0..b0e3d90 100644
|
||||
|
||||
getPkgFrameworkOpts :: DynFlags -> Platform -> [InstalledUnitId] -> IO [String]
|
||||
getPkgFrameworkOpts dflags platform dep_packages
|
||||
diff --git a/rts/package.conf.in b/rts/package.conf.in
|
||||
index e4cb159..7a234cd 100644
|
||||
--- a/rts/package.conf.in
|
||||
+++ b/rts/package.conf.in
|
||||
@@ -26,9 +26,7 @@ library-dirs: TOP"/rts/dist/build" FFI_LIB_DIR LIBDW_LIB_DIR
|
||||
hs-libraries: "HSrts" FFI_LIB
|
||||
|
||||
extra-libraries:
|
||||
-#if defined(HAVE_LIBM)
|
||||
"m" /* for ldexp() */
|
||||
-#endif
|
||||
#if defined(HAVE_LIBRT)
|
||||
, "rt"
|
||||
#endif
|
153
packages/ghc-libs/build.sh
Normal file
153
packages/ghc-libs/build.sh
Normal file
@ -0,0 +1,153 @@
|
||||
TERMUX_PKG_HOMEPAGE=https://www.haskell.org/ghc/
|
||||
TERMUX_PKG_DESCRIPTION="The Glasgow Haskell Compiler - Dynamic Libraries"
|
||||
TERMUX_PKG_LICENSE="BSD 2-Clause, BSD 3-Clause, LGPL-2.1"
|
||||
TERMUX_PKG_MAINTAINER="Aditya Alok <dev.aditya.alok@gmail.com>"
|
||||
TERMUX_PKG_VERSION=8.10.7
|
||||
TERMUX_PKG_SRCURL="https://downloads.haskell.org/~ghc/${TERMUX_PKG_VERSION}/ghc-${TERMUX_PKG_VERSION}-src.tar.xz"
|
||||
TERMUX_PKG_SHA256=e3eef6229ce9908dfe1ea41436befb0455fefb1932559e860ad4c606b0d03c9d
|
||||
TERMUX_PKG_DEPENDS="iconv, libffi, ncurses, libgmp"
|
||||
TERMUX_PKG_BUILD_IN_SRC=true
|
||||
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
|
||||
--disable-ld-override
|
||||
--build=x86_64-unknown-linux
|
||||
--host=x86_64-unknown-linux
|
||||
--with-system-libffi
|
||||
--with-ffi-includes=${TERMUX_PREFIX}/include
|
||||
--with-ffi-libraries=${TERMUX_PREFIX}/lib
|
||||
--with-gmp-includes=${TERMUX_PREFIX}/include
|
||||
--with-gmp-libraries=${TERMUX_PREFIX}/lib
|
||||
--with-iconv-includes=${TERMUX_PREFIX}/include
|
||||
--with-iconv-libraries=${TERMUX_PREFIX}/lib
|
||||
--with-curses-libraries=${TERMUX_PREFIX}/lib
|
||||
--with-curses-includes=${TERMUX_PREFIX}/include
|
||||
--with-curses-libraries-stage0=/usr/lib
|
||||
"
|
||||
# ghc-pkg is in this package. Here ghci is lib not bin.
|
||||
TERMUX_PKG_PROVIDES="haskekl-ghc-pkg, haskell-ghci"
|
||||
TERMUX_PKG_CONFLICTS="haskell-ghci"
|
||||
TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS="lib/**/*.hi lib/**/*.o"
|
||||
|
||||
termux_step_pre_configure() {
|
||||
termux_setup_ghc
|
||||
|
||||
_TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}"
|
||||
[ "${TERMUX_ARCH}" = "arm" ] && _TERMUX_HOST_PLATFORM="armv7a-linux-androideabi"
|
||||
|
||||
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --target=${_TERMUX_HOST_PLATFORM}"
|
||||
|
||||
_WRAPPER_BIN="${TERMUX_PKG_BUILDDIR}/_wrapper/bin"
|
||||
mkdir -p "${_WRAPPER_BIN}"
|
||||
|
||||
for tool in llc opt; do
|
||||
local wrapper="${_WRAPPER_BIN}/${tool}"
|
||||
cat >"$wrapper" <<-EOF
|
||||
#!$(command -v sh)
|
||||
exec /usr/lib/llvm-12/bin/${tool} "\$@"
|
||||
EOF
|
||||
chmod 0700 "$wrapper"
|
||||
done
|
||||
|
||||
local ar_wrapper="${_WRAPPER_BIN}/${_TERMUX_HOST_PLATFORM}-ar"
|
||||
cat >"$ar_wrapper" <<-EOF
|
||||
#!$(command -v sh)
|
||||
exec $(command -v ${AR}) "\$@"
|
||||
EOF
|
||||
chmod 0700 "$ar_wrapper"
|
||||
|
||||
local strip_wrapper="${_WRAPPER_BIN}/${_TERMUX_HOST_PLATFORM}-strip"
|
||||
cat >"$strip_wrapper" <<-EOF
|
||||
#!$(command -v sh)
|
||||
exec $(command -v ${STRIP}) "\$@"
|
||||
EOF
|
||||
chmod 0700 "$strip_wrapper"
|
||||
|
||||
export PATH="${_WRAPPER_BIN}:${PATH}"
|
||||
export LIBTOOL="$(command -v libtool)"
|
||||
|
||||
local EXTRA_FLAGS="-O -optl-Wl,-rpath=${TERMUX_PREFIX}/lib -optl-Wl,--enable-new-dtags"
|
||||
|
||||
[ "${TERMUX_ARCH}" != "i686" ] && EXTRA_FLAGS+=" -fllvm"
|
||||
|
||||
# Suppress warnings for LLVM 13
|
||||
sed -i 's/LlvmMaxVersion=13/LlvmMaxVersion=14/' configure.ac
|
||||
|
||||
cp mk/build.mk.sample mk/build.mk
|
||||
cat >>mk/build.mk <<-EOF
|
||||
SRC_HC_OPTS = -O -H64m
|
||||
GhcStage1HcOpts = -O
|
||||
GhcStage2HcOpts = ${EXTRA_FLAGS}
|
||||
GhcLibHcOpts = ${EXTRA_FLAGS}
|
||||
BuildFlavour = quick-cross
|
||||
GhcLibWays = v dyn
|
||||
STRIP_CMD = ${STRIP}
|
||||
BUILD_PROF_LIBS = NO
|
||||
HADDOCK_DOCS = NO
|
||||
BUILD_SPHINX_HTML = NO
|
||||
BUILD_SPHINX_PDF = NO
|
||||
BUILD_MAN = NO
|
||||
WITH_TERMINFO = YES
|
||||
DYNAMIC_GHC_PROGRAMS = YES
|
||||
SplitSections = YES
|
||||
StripLibraries = YES
|
||||
EOF
|
||||
|
||||
patch -p1 <<-EOF
|
||||
--- ghc-8.10.7/rules/build-package-data.mk 2021-06-21 12:24:36.000000000 +0530
|
||||
+++ ghc-8.10.7-patch/rules/build-package-data.mk 2022-01-27 20:31:28.901997265 +0530
|
||||
@@ -68,6 +68,12 @@
|
||||
\$1_\$2_CONFIGURE_LDFLAGS = \$\$(SRC_LD_OPTS) \$\$(\$1_LD_OPTS) \$\$(\$1_\$2_LD_OPTS)
|
||||
\$1_\$2_CONFIGURE_CPPFLAGS = \$\$(SRC_CPP_OPTS) \$\$(CONF_CPP_OPTS_STAGE\$3) \$\$(\$1_CPP_OPTS) \$\$(\$1_\$2_CPP_OPTS)
|
||||
|
||||
+ifneq "\$3" "0"
|
||||
+ \$1_\$2_CONFIGURE_LDFLAGS += $LDFLAGS
|
||||
+ \$1_\$2_CONFIGURE_CPPFLAGS += $CPPFLAGS
|
||||
+ \$1_\$2_CONFIGURE_CFLAGS += $CFLAGS
|
||||
+endif
|
||||
+
|
||||
\$1_\$2_CONFIGURE_OPTS += --configure-option=CFLAGS="\$\$(\$1_\$2_CONFIGURE_CFLAGS)"
|
||||
\$1_\$2_CONFIGURE_OPTS += --configure-option=LDFLAGS="\$\$(\$1_\$2_CONFIGURE_LDFLAGS)"
|
||||
\$1_\$2_CONFIGURE_OPTS += --configure-option=CPPFLAGS="\$\$(\$1_\$2_CONFIGURE_CPPFLAGS)"
|
||||
EOF
|
||||
|
||||
./boot
|
||||
}
|
||||
|
||||
termux_step_make_install() {
|
||||
make install-strip INSTALL="$(command -v install) --strip-program=${STRIP}"
|
||||
}
|
||||
|
||||
termux_step_post_make_install() {
|
||||
# We may build GHC with `llc-9` etc., but only `llc` is present in Termux
|
||||
sed -i 's/"LLVM llc command", "llc.*"/"LLVM llc command", "llc"/' \
|
||||
"${TERMUX_PREFIX}/lib/ghc-${TERMUX_PKG_VERSION}/settings"
|
||||
sed -i 's/"LLVM opt command", "opt.*"/"LLVM opt command", "opt"/' \
|
||||
"${TERMUX_PREFIX}/lib/ghc-${TERMUX_PKG_VERSION}/settings"
|
||||
|
||||
sed -i 's|"/usr/bin/libtool"|"libtool"|' \
|
||||
"${TERMUX_PREFIX}/lib/ghc-${TERMUX_PKG_VERSION}/settings"
|
||||
}
|
||||
|
||||
termux_step_install_license() {
|
||||
install -Dm600 -t "${TERMUX_PREFIX}/share/doc/ghc" "${TERMUX_PKG_SRCDIR}/LICENSE"
|
||||
}
|
||||
|
||||
termux_step_create_debscripts() {
|
||||
cat <<-EOF >./postinst
|
||||
#!${TERMUX_PREFIX}/bin/sh
|
||||
if [ "${TERMUX_PACKAGE_FORMAT}" = "pacman" ] || [ "\$1" = "configure" ] || [ "\$1" = "abort-upgrade" ]; then
|
||||
if [ -x "${TERMUX_PREFIX}/bin/update-alternatives" ]; then
|
||||
update-alternatives \
|
||||
--install ${TERMUX_PREFIX}/bin/haskell-compiler haskell-compiler ${TERMUX_PREFIX}/bin/ghc 20
|
||||
fi
|
||||
fi
|
||||
EOF
|
||||
|
||||
cat <<-EOF >./prerm
|
||||
#!${TERMUX_PREFIX}/bin/sh
|
||||
if [ "${TERMUX_PACKAGE_FORMAT}" = "pacman" ] || [ "\$1" != "upgrade" ] && [ "\$1" != "dist-upgrade" ]; then
|
||||
if [ -x "${TERMUX_PREFIX}/bin/update-alternatives" ]; then
|
||||
update-alternatives --remove haskell-compiler ${TERMUX_PREFIX}/bin/ghc
|
||||
fi
|
||||
fi
|
||||
EOF
|
||||
}
|
37
packages/ghc-libs/correct-host-triplet.patch
Normal file
37
packages/ghc-libs/correct-host-triplet.patch
Normal file
@ -0,0 +1,37 @@
|
||||
From: Aditya Alok <dev.aditya.alok@gmail.com>
|
||||
|
||||
Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
|
||||
|
||||
--- ghc-8.10.7/libraries/Cabal/Cabal/Distribution/Simple.hs 2022-02-09 09:22:38.381445950 +0530
|
||||
+++ ghc-8.10.7-patch/libraries/Cabal/Cabal/Distribution/Simple.hs 2022-03-05 12:03:02.509066261 +0530
|
||||
@@ -105,10 +105,20 @@
|
||||
import Distribution.Compat.Environment (getEnvironment)
|
||||
import Distribution.Compat.GetShortPathName (getShortPathName)
|
||||
|
||||
-import Data.List (unionBy, (\\))
|
||||
+import Data.List (unionBy, (\\), take, drop, isInfixOf)
|
||||
|
||||
import Distribution.PackageDescription.Parsec
|
||||
|
||||
+correctHostTriplet :: String -> String
|
||||
+correctHostTriplet s = do
|
||||
+ if isInfixOf "-android" s
|
||||
+ then
|
||||
+ let arch = take (length s -8) ( drop 0 s ) -- drop "-android"
|
||||
+ in
|
||||
+ if arch == "arm" then "armv7a" else arch ++ "-linux-"
|
||||
+ ++ if arch == "arm" then "androideabi" else "android"
|
||||
+ else s
|
||||
+
|
||||
-- | A simple implementation of @main@ for a Cabal setup script.
|
||||
-- It reads the package description file using IO, and performs the
|
||||
-- action specified on the command line.
|
||||
@@ -754,7 +764,7 @@
|
||||
overEnv = ("CFLAGS", Just cflagsEnv) :
|
||||
[("PATH", Just pathEnv) | not (null extraPath)]
|
||||
hp = hostPlatform lbi
|
||||
- maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
|
||||
+ maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ correctHostTriplet (show (pretty hp))]
|
||||
args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
|
||||
shProg = simpleProgram "sh"
|
||||
progDb = modifyProgramSearchPath
|
11
packages/ghc-libs/fix-target-elf-check.patch
Normal file
11
packages/ghc-libs/fix-target-elf-check.patch
Normal file
@ -0,0 +1,11 @@
|
||||
--- ghc-8.10.7/mk/config.mk.in 2021-06-21 12:24:36.000000000 +0530
|
||||
+++ ghc-8.10.7-patch/mk/config.mk.in 2022-02-04 13:18:15.667333665 +0530
|
||||
@@ -105,7 +105,7 @@
|
||||
WITH_TERMINFO=YES
|
||||
endif
|
||||
|
||||
-ifeq "$(findstring $(TargetOS_CPP),linux freebsd dragonfly openbsd netbsd solaris2 kfreebsdgnu haiku linux-android)" ""
|
||||
+ifeq "$(findstring $(TargetOS_CPP),linux freebsd dragonfly openbsd netbsd solaris2 kfreebsdgnu haiku linux_android)" ""
|
||||
TargetElf = NO
|
||||
else
|
||||
TargetElf = YES
|
11
packages/ghc-libs/ghc.subpackage.sh
Normal file
11
packages/ghc-libs/ghc.subpackage.sh
Normal file
@ -0,0 +1,11 @@
|
||||
TERMUX_SUBPKG_DESCRIPTION="The Glasgow Haskell Compiler"
|
||||
TERMUX_SUBPKG_DEPENDS="binutils, llvm, clang"
|
||||
|
||||
TERMUX_SUBPKG_INCLUDE="lib/ghc-${TERMUX_PKG_VERSION}/ghc-${TERMUX_PKG_VERSION}"
|
||||
|
||||
for f in $(find ${TERMUX_PREFIX}/lib/ghc-${TERMUX_PKG_VERSION}/bin -type f -not -name "ghc-pkg*" -print); do
|
||||
TERMUX_SUBPKG_INCLUDE+=" ${f/${TERMUX_PREFIX}\//}"
|
||||
done
|
||||
for f in $(find ${TERMUX_PREFIX}/bin -type f -not -name "ghc-pkg*" -print); do
|
||||
TERMUX_SUBPKG_INCLUDE+=" ${f/${TERMUX_PREFIX}\//}"
|
||||
done
|
11
packages/ghc-libs/set-default-prefix.patch
Normal file
11
packages/ghc-libs/set-default-prefix.patch
Normal file
@ -0,0 +1,11 @@
|
||||
--- ghc-8.10.7/libraries/Cabal/Cabal/Distribution/Simple/InstallDirs.hs 2021-05-25 20:11:34.000000000 +0530
|
||||
+++ ghc-8.10.7-patch/libraries/Cabal/Cabal/Distribution/Simple/InstallDirs.hs 2022-02-03 22:24:07.081585076 +0530
|
||||
@@ -193,7 +193,7 @@
|
||||
else case buildOS of
|
||||
Windows -> do windowsProgramFilesDir <- getWindowsProgramFilesDir
|
||||
return (windowsProgramFilesDir </> "Haskell")
|
||||
- _ -> return "/usr/local"
|
||||
+ _ -> return "@TERMUX_PREFIX@"
|
||||
installLibDir <-
|
||||
case buildOS of
|
||||
Windows -> return "$prefix"
|
17
packages/ghc-libs/utils-extra-ghc-opts.patch
Normal file
17
packages/ghc-libs/utils-extra-ghc-opts.patch
Normal file
@ -0,0 +1,17 @@
|
||||
--- ghc-8.10.7/rules/package-config.mk 2022-02-09 09:22:35.911445951 +0530
|
||||
+++ ghc-8.10.7-patch/rules/package-config.mk 2022-02-11 09:40:05.957999047 +0530
|
||||
@@ -55,6 +55,14 @@
|
||||
$1_$2_MORE_HC_OPTS += -rtsopts
|
||||
endif
|
||||
|
||||
+ifneq "$3" "0"
|
||||
+ifneq (,$(findstring utils/,$1))
|
||||
+# Found a package that needs to be built in the utils directory
|
||||
+$1_$2_MORE_HC_OPTS += -optl-Wl,-rpath=@TERMUX_PREFIX@/lib
|
||||
+$1_$2_MORE_HC_OPTS += -optl-Wl,--enable-new-dtags
|
||||
+endif
|
||||
+endif
|
||||
+
|
||||
# Used by pretty_commands.mk
|
||||
label_$1_$2_CC=CC
|
||||
label_$1_$2_AS=AS
|
@ -1,17 +0,0 @@
|
||||
--- ghc-8.10.1/compiler/main/DynFlags.hs.orig 2020-06-13 08:56:50.595808526 +0100
|
||||
+++ ghc-8.10.1/compiler/main/DynFlags.hs 2020-06-13 08:57:24.770000253 +0100
|
||||
@@ -4624,6 +4624,14 @@
|
||||
default_PIC platform =
|
||||
case (platformOS platform, platformArch platform) of
|
||||
(OSDarwin, ArchX86_64) -> [Opt_PIC]
|
||||
+ (OSLinux, ArchARM{}) -> [Opt_PIC]
|
||||
+ (OSLinux, ArchARM64) -> [Opt_PIC]
|
||||
+ (OSLinux, ArchX86) -> [Opt_PIC]
|
||||
+ (OSLinux, ArchX86_64) -> [Opt_PIC]
|
||||
+ (OSUnknown, ArchARM{}) -> [Opt_PIC]
|
||||
+ (OSUnknown, ArchARM64) -> [Opt_PIC]
|
||||
+ (OSUnknown, ArchX86) -> [Opt_PIC]
|
||||
+ (OSUnknown, ArchX86_64) -> [Opt_PIC]
|
||||
(OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
|
||||
-- OpenBSD since 5.3 release
|
||||
-- (1 May 2013) we need to
|
@ -1,175 +0,0 @@
|
||||
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 <<EOF
|
||||
--- a/rules/build-package-data.mk.orig 2020-06-09 23:44:52.013029077 +0000
|
||||
+++ b/rules/build-package-data.mk 2020-06-09 23:45:10.589149807 +0000
|
||||
@@ -108,6 +108,15 @@
|
||||
\$1_\$2_CONFIGURE_OPTS += --configure-option=--host=\$(TargetPlatformFull)
|
||||
endif
|
||||
|
||||
+ifneq "\$3" "0"
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=--host=$TERMUX_HOST_PLATFORM --configure-option=CXX=$CXX --configure-option=LD=$LD --configure-option=AR=$AR
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=AS=$AS --configure-option=CC=$CC --configure-option=RANLIB=$RANLIB --configure-option=READELF=$READELF
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=OBJCOPY=$OBJCOPY --configure-option=OBJDUMP=$OBJDUMP --configure-option=--with-system-libffi
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=--with-ffi-includes=$TERMUX_PREFIX/include --configure-option=--with-ffi-libraries=$TERMUX_PREFIX/lib
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=--with-iconv-includes=$TERMUX_PREFIX/include --configure-option=--with-iconv-libraries=$TERMUX_PREFIX/lib
|
||||
+\$1_\$2_CONFIGURE_OPTS += --configure-option=--with-curses-includes=$TERMUX_PREFIX/include/ncursesw --configure-option=--with-curses-libraries=$TERMUX_PREFIX/lib
|
||||
+endif
|
||||
+
|
||||
ifeq "\$3" "0"
|
||||
\$1_\$2_CONFIGURE_OPTS += \$\$(BOOT_PKG_CONSTRAINTS)
|
||||
endif
|
||||
EOF
|
||||
|
||||
export TERMUX_LD="$LD"
|
||||
|
||||
unset AR
|
||||
unset AS
|
||||
unset CC
|
||||
export CFLAGS=""
|
||||
unset CPP
|
||||
export CPPFLAGS=""
|
||||
unset CXXFLAGS
|
||||
unset CXX
|
||||
export LDFLAGS=""
|
||||
unset LD
|
||||
unset PKG_CONFIG
|
||||
unset RANLIB
|
||||
unset READELF
|
||||
unset OBJCOPY
|
||||
unset OBJDUMP
|
||||
|
||||
autoreconf
|
||||
}
|
||||
|
||||
termux_step_post_make_install() {
|
||||
# We may build GHC with `llc-9` etc., but only `llc` is present in Termux
|
||||
sed -i 's/"LLVM llc command", "llc.*"/"LLVM llc command", "llc"/' "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/settings"
|
||||
sed -i 's/"LLVM opt command", "opt.*"/"LLVM opt command", "opt"/' "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/settings"
|
||||
|
||||
if [ "$DYNAMIC_GHC_PROGRAMS" = "YES" ]; then
|
||||
# Hack to turn the binaries' rpath from something relative to the build environment
|
||||
# into something that matches Termux's FHS. patchelf needs to be installed on the host.
|
||||
while IFS= read -r -d '' bin; do
|
||||
local curr_rpath="$(patchelf --print-rpath "$bin" 2>/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"
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
--- a/mk/config.mk.in
|
||||
+++ b/mk/config.mk.in
|
||||
@@ -547,9 +547,9 @@
|
||||
|
||||
# why no LD=@LD@ ?
|
||||
LD_STAGE0 = @LD_STAGE0@
|
||||
-LD_STAGE1 = $(LD)
|
||||
-LD_STAGE2 = $(LD)
|
||||
-LD_STAGE3 = $(LD)
|
||||
+LD_STAGE1 = $(TERMUX_LD)
|
||||
+LD_STAGE2 = $(TERMUX_LD)
|
||||
+LD_STAGE3 = $(TERMUX_LD)
|
||||
|
||||
# Cross-compiling options
|
||||
# See Note [CrossCompiling vs Stage1Only]
|
@ -1,28 +0,0 @@
|
||||
Description: Use the stage1 binaries for install
|
||||
In order to be able to perform a cross-build, we need to use
|
||||
the stage1 binaries during installation. Both ghc and ghc-pkg
|
||||
are run during the install target and therefore must be able
|
||||
to run on the build machine.
|
||||
.
|
||||
Author: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
|
||||
Last-Update: 2017-01-29
|
||||
|
||||
Index: ghc-8.8.1+dfsg1/ghc.mk
|
||||
===================================================================
|
||||
--- ghc-8.8.1+dfsg1.orig/ghc.mk
|
||||
+++ ghc-8.8.1+dfsg1/ghc.mk
|
||||
@@ -963,8 +963,12 @@
|
||||
# Install packages in the right order, so that ghc-pkg doesn't complain.
|
||||
# Also, install ghc-pkg first.
|
||||
ifeq "$(Windows_Host)" "NO"
|
||||
-INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
|
||||
-INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
|
||||
+# Use the inplace/stage1 versions for installation,
|
||||
+# since the installed versions are built for the target
|
||||
+#INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
|
||||
+#INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
|
||||
+INSTALLED_GHC_REAL=$(CURDIR)/inplace/bin/ghc-stage1
|
||||
+INSTALLED_GHC_PKG_REAL=$(CURDIR)/utils/ghc-pkg/dist/build/tmp/ghc-pkg
|
||||
else
|
||||
INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
|
||||
INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
|
37
packages/haskell-cabal/correct-host-triplet.patch
Normal file
37
packages/haskell-cabal/correct-host-triplet.patch
Normal file
@ -0,0 +1,37 @@
|
||||
From: Aditya Alok <dev.aditya.alok@gmail.com>
|
||||
|
||||
Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
|
||||
|
||||
--- Cabal-3.6.2.0/src/Distribution/Simple.hs 2001-09-09 07:16:40.000000000 +0530
|
||||
+++ Cabal-3.6.2.0-patch/src/Distribution/Simple.hs 2022-02-17 23:18:09.477872143 +0530
|
||||
@@ -108,10 +108,20 @@
|
||||
import Distribution.Compat.Environment (getEnvironment)
|
||||
import Distribution.Compat.GetShortPathName (getShortPathName)
|
||||
|
||||
-import Data.List (unionBy, (\\))
|
||||
+import Data.List (unionBy, drop, take, isInfixOf, (\\))
|
||||
|
||||
import Distribution.PackageDescription.Parsec
|
||||
|
||||
+correctHostTriplet :: String -> String
|
||||
+correctHostTriplet s = do
|
||||
+ if isInfixOf "-android" s
|
||||
+ then
|
||||
+ let arch = take (length s -8) ( drop 0 s ) -- drop "-android"
|
||||
+ in
|
||||
+ if arch == "arm" then "armv7a" else arch ++ "-linux-"
|
||||
+ ++ if arch == "arm" then "androideabi" else "android"
|
||||
+ else s
|
||||
+
|
||||
-- | A simple implementation of @main@ for a Cabal setup script.
|
||||
-- It reads the package description file using IO, and performs the
|
||||
-- action specified on the command line.
|
||||
@@ -722,7 +732,7 @@
|
||||
overEnv = ("CFLAGS", Just cflagsEnv) :
|
||||
[("PATH", Just pathEnv) | not (null extraPath)]
|
||||
hp = hostPlatform lbi
|
||||
- maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
|
||||
+ maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ correctHostTriplet (show (pretty hp))]
|
||||
args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
|
||||
shProg = simpleProgram "sh"
|
||||
progDb = modifyProgramSearchPath
|
Loading…
Reference in New Issue
Block a user