2018-04-16 21:30:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Outputs a new PATH setting that is prefixed by the path to the
|
|
|
|
# Android cross-compiler toolchain to use for a given Android version.
|
|
|
|
#
|
|
|
|
# For Android 5, force PIE build flags
|
|
|
|
#
|
|
|
|
# Since the ghc-android wrappers actually hardcode the path to the
|
|
|
|
# toolchain, and we want to wrap the toolchain programs, the binaries
|
2018-04-16 21:47:35 +00:00
|
|
|
# are moved to .orig and replaced by wrappers.
|
2018-04-16 21:30:21 +00:00
|
|
|
|
|
|
|
androidversion="$1"
|
|
|
|
|
|
|
|
# Allow running from the top or inside this directory.
|
|
|
|
if [ -e abiversion ]; then
|
2018-04-16 21:34:27 +00:00
|
|
|
top=.
|
2018-04-16 21:30:21 +00:00
|
|
|
else
|
2018-04-16 21:34:27 +00:00
|
|
|
top=standalone/android
|
2018-04-16 21:30:21 +00:00
|
|
|
fi
|
|
|
|
|
2018-04-16 21:34:27 +00:00
|
|
|
wrap () {
|
|
|
|
sed -e "s!PROG!$1!" -e "s!OPTS!$3!" < $top/wrapper.pl > "$2"
|
|
|
|
chmod +x "$2"
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:30:21 +00:00
|
|
|
# location to toolchain as installed by ghc-android
|
2018-04-16 21:34:27 +00:00
|
|
|
androidtoolchain="$HOME/.ghc/$(cat $top/abiversion)/bin"
|
2018-04-16 21:30:21 +00:00
|
|
|
|
2018-04-16 22:31:10 +00:00
|
|
|
for f in $(find "$androidtoolchain" -maxdepth 1 -type f -printf '%f\n' | grep -v \.orig); do
|
2018-04-16 21:30:21 +00:00
|
|
|
bin="$androidtoolchain/$f"
|
2018-04-16 21:47:35 +00:00
|
|
|
orig="$androidtoolchain/$f.orig"
|
2018-04-16 21:30:21 +00:00
|
|
|
if [ ! -e "$orig" ]; then
|
|
|
|
cp -a "$bin" "$orig"
|
|
|
|
fi
|
|
|
|
if [ "$androidversion" = 5 ]; then
|
|
|
|
case "$f" in
|
|
|
|
*-ld*)
|
|
|
|
wrap "$orig" "$bin" "-pie"
|
|
|
|
;;
|
|
|
|
*-gcc)
|
|
|
|
wrap "$orig" "$bin" "-pie -fPIE"
|
|
|
|
;;
|
|
|
|
*'-g++')
|
|
|
|
wrap "$orig" "$bin" "-pie -fPIE"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
cp -a "$orig" "$bin"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
cp -a "$orig" "$bin"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$androidtoolchain:$PATH"
|