2017-08-11 05:40:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2018-02-11 01:51:50 +00:00
|
|
|
hash automake || { echo >&2 "Missing automake."; exit 1; }
|
|
|
|
hash autoreconf || { echo >&2 "Missing autoconf."; exit 1; }
|
|
|
|
hash libtool || hash glibtool || { echo >&2 "Missing libtool."; exit 1; }
|
|
|
|
|
2017-08-11 05:40:37 +00:00
|
|
|
cd "${BASH_SOURCE%/*}/../External/libsodium"
|
2018-02-11 04:29:55 +00:00
|
|
|
[[ $1 = clean ]] && { [[ ! -e Makefile ]] || make -s distclean; exit; }
|
2017-09-01 15:16:09 +00:00
|
|
|
[[ -e "${prefix=$PWD/libsodium-ios}/lib/libsodium.a" ]] && exit
|
2017-08-11 05:40:37 +00:00
|
|
|
|
|
|
|
# Prepare
|
2018-02-11 01:51:50 +00:00
|
|
|
autoreconf --verbose --install --symlink 2> >(sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /')
|
2017-08-11 05:40:37 +00:00
|
|
|
rm -rf "${prefix=$PWD/libsodium-ios}"
|
|
|
|
mkdir -p "$prefix/lib" \
|
2017-08-13 20:53:18 +00:00
|
|
|
"${prefix_i386=$prefix/tmp/i386}" \
|
2017-08-11 05:40:37 +00:00
|
|
|
"${prefix_x86_64=$prefix/tmp/x86_64}" \
|
|
|
|
"${prefix_armv7=$prefix/tmp/armv7}" \
|
|
|
|
"${prefix_armv7s=$prefix/tmp/armv7s}" \
|
|
|
|
"${prefix_arm64=$prefix/tmp/arm64}"
|
|
|
|
|
2017-08-13 19:52:08 +00:00
|
|
|
# Targets
|
2017-08-13 20:53:18 +00:00
|
|
|
(
|
|
|
|
## ARCH: i386
|
2018-02-11 01:51:50 +00:00
|
|
|
SDKROOT="$(xcrun --show-sdk-path --sdk iphonesimulator)"
|
|
|
|
PATH="$(xcrun --show-sdk-platform-path --sdk iphonesimulator)/usr/bin:$PATH"
|
2017-08-13 20:53:18 +00:00
|
|
|
export CFLAGS="-arch i386 -isysroot $SDKROOT -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -O2 -g -flto $CFLAGS"
|
|
|
|
export LDFLAGS="-arch i386 -isysroot $SDKROOT -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -flto $LDFLAGS"
|
|
|
|
export CPPFLAGS="$CFLAGS $CPPFLAGS"
|
|
|
|
[[ -e Makefile ]] && make -s distclean
|
2017-09-24 00:14:53 +00:00
|
|
|
./configure --host=i686-apple --disable-shared --enable-minimal --prefix="$prefix_i386"
|
2017-08-13 20:53:18 +00:00
|
|
|
make -j3 install
|
|
|
|
)
|
2017-08-11 05:40:37 +00:00
|
|
|
(
|
|
|
|
## ARCH: x86_64
|
2018-02-11 01:51:50 +00:00
|
|
|
SDKROOT="$(xcrun --show-sdk-path --sdk iphonesimulator)"
|
|
|
|
PATH="$(xcrun --show-sdk-platform-path --sdk iphonesimulator)/usr/bin:$PATH"
|
2017-08-13 19:52:08 +00:00
|
|
|
export CFLAGS="-arch x86_64 -isysroot $SDKROOT -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -O2 -g -flto $CFLAGS"
|
|
|
|
export LDFLAGS="-arch x86_64 -isysroot $SDKROOT -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -flto $LDFLAGS"
|
|
|
|
export CPPFLAGS="$CFLAGS $CPPFLAGS"
|
2017-08-11 05:40:37 +00:00
|
|
|
[[ -e Makefile ]] && make -s distclean
|
2017-09-24 00:14:53 +00:00
|
|
|
./configure --host=x86_64-apple --disable-shared --enable-minimal --prefix="$prefix_x86_64"
|
2017-08-11 05:40:37 +00:00
|
|
|
make -j3 install
|
|
|
|
)
|
|
|
|
(
|
|
|
|
## ARCH: armv7
|
2018-02-11 01:51:50 +00:00
|
|
|
SDKROOT="$(xcrun --show-sdk-path --sdk iphoneos)"
|
|
|
|
PATH="$(xcrun --show-sdk-platform-path --sdk iphoneos)/usr/bin:$PATH"
|
2017-08-13 19:52:08 +00:00
|
|
|
export CFLAGS="-mthumb -arch armv7 -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -O2 -g -flto $CFLAGS"
|
|
|
|
export LDFLAGS="-mthumb -arch armv7 -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -flto $LDFLAGS"
|
|
|
|
export CPPFLAGS="$CFLAGS $CPPFLAGS"
|
2017-08-11 05:40:37 +00:00
|
|
|
[[ -e Makefile ]] && make -s distclean
|
2017-09-24 00:14:53 +00:00
|
|
|
./configure --host=x86_64-apple --target=arm-apple --disable-shared --enable-minimal --prefix="$prefix_armv7"
|
2017-08-11 05:40:37 +00:00
|
|
|
make -j3 install
|
|
|
|
)
|
|
|
|
(
|
|
|
|
## ARCH: armv7s
|
2018-02-11 01:51:50 +00:00
|
|
|
SDKROOT="$(xcrun --show-sdk-path --sdk iphoneos)"
|
|
|
|
PATH="$(xcrun --show-sdk-platform-path --sdk iphoneos)/usr/bin:$PATH"
|
2017-08-13 19:52:08 +00:00
|
|
|
export CFLAGS="-mthumb -arch armv7s -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -O2 -g -flto $CFLAGS"
|
|
|
|
export LDFLAGS="-mthumb -arch armv7s -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -flto $LDFLAGS"
|
|
|
|
export CPPFLAGS="$CFLAGS $CPPFLAGS"
|
2017-08-11 05:40:37 +00:00
|
|
|
[[ -e Makefile ]] && make -s distclean
|
2017-09-24 00:14:53 +00:00
|
|
|
./configure --host=x86_64-apple --target=arm-apple --disable-shared --enable-minimal --prefix="$prefix_armv7s"
|
2017-08-11 05:40:37 +00:00
|
|
|
make -j3 install
|
|
|
|
)
|
|
|
|
(
|
|
|
|
## ARCH: arm64
|
2018-02-11 01:51:50 +00:00
|
|
|
SDKROOT="$(xcrun --show-sdk-path --sdk iphoneos)"
|
|
|
|
PATH="$(xcrun --show-sdk-platform-path --sdk iphoneos)/usr/bin:$PATH"
|
2017-08-13 19:52:08 +00:00
|
|
|
export CFLAGS="-mthumb -arch arm64 -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -O2 -g -flto $CFLAGS"
|
|
|
|
export LDFLAGS="-mthumb -arch arm64 -isysroot $SDKROOT -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET:-8.0} -flto $LDFLAGS"
|
|
|
|
export CPPFLAGS="$CFLAGS $CPPFLAGS"
|
2017-08-11 05:40:37 +00:00
|
|
|
[[ -e Makefile ]] && make -s distclean
|
2017-09-24 00:14:53 +00:00
|
|
|
./configure --host=x86_64-apple --target=arm-apple --disable-shared --enable-minimal --prefix="$prefix_arm64"
|
2017-08-11 05:40:37 +00:00
|
|
|
make -j3 install
|
|
|
|
)
|
|
|
|
|
|
|
|
# Merge Binaries
|
2017-09-01 15:16:09 +00:00
|
|
|
mv -f -- "$prefix_arm64/include" "$prefix/"
|
2017-08-11 05:40:37 +00:00
|
|
|
lipo -create \
|
2017-08-13 22:32:03 +00:00
|
|
|
"$prefix_i386/lib/libsodium.a" \
|
2017-08-11 05:40:37 +00:00
|
|
|
"$prefix_x86_64/lib/libsodium.a" \
|
|
|
|
"$prefix_armv7/lib/libsodium.a" \
|
|
|
|
"$prefix_armv7s/lib/libsodium.a" \
|
|
|
|
"$prefix_arm64/lib/libsodium.a" \
|
|
|
|
-output "$prefix/lib/libsodium.a"
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
rm -rf -- "$prefix/tmp"
|
|
|
|
make -s distclean
|