[commit: ghc] ghc-8.2: Always allow -staticlib (f9f8f81)
git at git.haskell.org
git at git.haskell.org
Sun Dec 23 18:47:02 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.2
Link : http://ghc.haskell.org/trac/ghc/changeset/f9f8f8173daa28af6b6b863d2761c89a0a98b568/ghc
>---------------------------------------------------------------
commit f9f8f8173daa28af6b6b863d2761c89a0a98b568
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date: Tue Jul 11 11:57:48 2017 -0400
Always allow -staticlib
the `-staticlib` flag is currently only supported on apple platforms,
due to the avaiablity of libtool (the apple version, which is unlike the
gnu version). This however prevents the use of -staticlib in cases
where it would be beneficial as well. The functionality that
`-staticlib` uses from `libtool` can be stubbed with a small script like
the following:
```
name=${0##*/}
target=${name%-*}
set -e
ldflags_L=()
ldflags_l=()
output=""
inputs=()
STATIC=0
DYNAMIC=1
mode=$DYNAMIC
verbose=0
function find_lib () {
lib=$1; shift 1;
for dir in $@; do
if [ -f "$dir/$lib" ]; then
echo "$dir/$lib"
break
fi
done
}
while [ "$#" -gt 0 ]; do
case "$1" in
-v|--verbose) verbose=1; shift 1;;
-o) output="$2"; shift 2;;
-L*) ldflags_L+=("${1:2:${#1}-2}"); shift 1;;
-l*) ldflags_l+=("lib${1:2:${#1}-2}.a"); shift 1;;
-static) mode=$STATIC; shift 1;;
-dynamic) mode=$DYNAMIC; shift 1;;
-Wl,*) ldflags+=("${1#*,}"); shift 1;;
-*) echo "unknown option: $1" >&2; exit 1;;
*) inputs+=("$1"); shift 1;;
esac
done
if [ ! $mode == $STATIC ]; then
echo "-dynamic not supported!" >&2; exit 1;
fi
MRI="create ${output}\n"
for input in "${ldflags_l[@]}"; do
lib=$(find_lib $input ${ldflags_L[@]})
if [ -z $lib ]; then
echo "Failed to find lib $input" >&2
exit 1
else
MRI+="addlib $lib\n"
continue
fi
done
for input in "${inputs[@]}"; do
MRI+="addmod $input\n"
done
MRI+="save\nend\n"
echo -e "$MRI" | $target-ar -M
$target-ranlib $output
```
if `ar` supports MRI scripts.
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3706
(cherry picked from commit b8f33bc6b738b0378976e42b79369f0e53b680c7)
>---------------------------------------------------------------
f9f8f8173daa28af6b6b863d2761c89a0a98b568
compiler/main/DriverPipeline.hs | 5 +----
docs/users_guide/phases.rst | 8 +++-----
utils/mkUserGuidePart/Options/Linking.hs | 7 ++++---
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index b301ece..a4fe735 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -2063,10 +2063,7 @@ linkDynLibCheck dflags o_files dep_packages
linkStaticLibCheck :: DynFlags -> [String] -> [InstalledUnitId] -> IO ()
linkStaticLibCheck dflags o_files dep_packages
- = do
- when (platformOS (targetPlatform dflags) `notElem` [OSiOS, OSDarwin]) $
- throwGhcExceptionIO (ProgramError "Static archive creation only supported on Darwin/OS X/iOS")
- linkBinary' True dflags o_files dep_packages
+ = linkBinary' True dflags o_files dep_packages
-- -----------------------------------------------------------------------------
-- Running CPP
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst
index afb3a8b..6288961 100644
--- a/docs/users_guide/phases.rst
+++ b/docs/users_guide/phases.rst
@@ -551,11 +551,9 @@ for example).
.. ghc-flag:: -staticlib
- On Darwin/OS X/iOS only, link all passed files into a static library
- suitable for linking into an iOS (when using a cross-compiler) or
- Mac Xcode project. To control the name, use the :ghc-flag:`-o ⟨file⟩` option
- as usual. The default name is ``liba.a``. This should nearly always
- be passed when compiling for iOS with a cross-compiler.
+ Link all passed files into a static library suitable for linking.
+ To control the name, use the :ghc-flag:`-o` ⟨name⟩ option
+ as usual. The default name is ``liba.a``.
.. ghc-flag:: -L ⟨dir⟩
diff --git a/utils/mkUserGuidePart/Options/Linking.hs b/utils/mkUserGuidePart/Options/Linking.hs
index 23e32fa..f0b6ea5 100644
--- a/utils/mkUserGuidePart/Options/Linking.hs
+++ b/utils/mkUserGuidePart/Options/Linking.hs
@@ -11,9 +11,10 @@ linkingOptions =
}
, flag { flagName = "-staticlib"
, flagDescription =
- "On Darwin/OS X/iOS only, generate a standalone static library " ++
- "(as opposed to an executable). This is the usual way to " ++
- "compile for iOS."
+ "Generate a standalone static library (as opposed to an " ++
+ "executable). This is useful when cross compiling. The " ++
+ "library together with all its dependencies ends up in in a " ++
+ "single static library that can be linked against."
, flagType = DynamicFlag
}
, flag { flagName = "-fPIC"
More information about the ghc-commits
mailing list