-
-
Save himamis/64a880d26df9a886cb37e0fea1e6e7e4 to your computer and use it in GitHub Desktop.
GMP and MPFR compile for iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First need run build_gmp.sh then build_mpfr.sh | |
./build_gmp.sh -ios --min-ios-version 10.0 | |
./build_mpfr.sh -ios --min-ios-version 10.0 | |
./build_gmp.sh -osx --min-macosx-version 10.14 | |
./build_mpfr.sh -osx --min-macosx-version 10.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#=============================================================================== | |
# Filename: build_gmp.sh | |
# Created by Volodymyr Boichentsov on 18/09/2015. | |
# Copyright © 2015 3D4Medical. All rights reserved. | |
# Property of 3D4Medical. | |
#=============================================================================== | |
#-emit-obj -fembed-bitcode -disable-llvm-optzns -O3 | |
BUILD_IOS= | |
BUILD_OSX= | |
unknownParameter() | |
{ | |
if [[ -n $2 && $2 != "" ]]; then | |
echo Unknown argument \"$2\" for parameter $1. | |
else | |
echo Unknown argument $1 | |
fi | |
die | |
} | |
parseArgs() | |
{ | |
while [ "$1" != "" ]; do | |
case $1 in | |
-ios) | |
BUILD_IOS=1 | |
;; | |
-osx) | |
BUILD_OSX=1 | |
;; | |
--min-ios-version) | |
if [ -n $2 ]; then | |
SDKVERSION=$2 | |
shift | |
else | |
missingParameter $1 | |
fi | |
;; | |
--min-macosx-version) | |
if [ -n $2 ]; then | |
SDKVERSION=$2 | |
shift | |
else | |
missingParameter $1 | |
fi | |
;; | |
*) | |
unknownParameter $1 | |
;; | |
esac | |
shift | |
done | |
} | |
parseArgs $@ | |
if [[ -z $BUILD_IOS && -z $BUILD_OSX ]]; then | |
BUILD_IOS=1 | |
fi | |
CURRENT=`pwd` | |
# if [ -d "${CURRENT}/gmp/gmplib" ]; then | |
# exit | |
# fi | |
__pr="--print-path" | |
__name="xcode-select" | |
DEVELOPER=`${__name} ${__pr}` | |
GMP_VERSION="6.1.0" | |
if [[ -z $SDKVERSION ]]; then | |
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` | |
fi | |
OSX_PLATFORM=`xcrun --sdk macosx --show-sdk-platform-path` | |
OSX_SDK=`xcrun --sdk macosx --show-sdk-path` | |
IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path` | |
IPHONEOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` | |
IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path` | |
IPHONESIMULATOR_SDK=`xcrun --sdk iphonesimulator --show-sdk-path` | |
CLANG=`xcrun --sdk iphoneos --find clang` | |
CLANGPP=`xcrun --sdk iphoneos --find clang++` | |
BITCODE_FLAGS=" -disable-llvm-optzns -O3" | |
downloadGMP() | |
{ | |
if [ ! -d "${CURRENT}/gmp" ]; then | |
echo "Downloading GMP" | |
curl -L -o "${CURRENT}/gmp-${GMP_VERSION}.tar.bz2" http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 | |
tar xfj "gmp-${GMP_VERSION}.tar.bz2" | |
mv gmp-${GMP_VERSION} gmp | |
rm "gmp-${GMP_VERSION}.tar.bz2" | |
fi | |
} | |
build() | |
{ | |
ARCH=$1 | |
SDK=$2 | |
PLATFORM=$3 | |
ARGS=$4 | |
TYPE=$5 | |
POSTFIX=$6 | |
make clean &> "${CURRENT}/clean.log" | |
make distclean &> "${CURRENT}/clean.log" | |
export PATH="${PLATFORM}/Developer/usr/bin:${DEVELOPER}/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" | |
if [ -d "gmplib-${ARCH}-${TYPE}" ] ; then | |
rm -rf "gmplib-${ARCH}-${TYPE}" | |
fi | |
mkdir "gmplib-${ARCH}-${TYPE}" | |
EXTRAS="-arch ${ARCH}" | |
if [ "${TYPE}" == "ios" ]; then | |
EXTRAS="$EXTRAS -miphoneos-version-min=${SDKVERSION} -fembed-bitcode -target ${ARCH}-apple-ios${SDKVERSION}${POSTFIX}" | |
fi | |
if [ "${TYPE}" == "osx" ]; then | |
echo "macOS deployment target ${SDKVERSION}" | |
EXTRAS="$EXTRAS -mmacosx-version-min=${SDKVERSION} " | |
fi | |
if [ "${ARCH}" == "i386" ]; then | |
EXTRAS="${EXTRAS} -m32" | |
fi | |
CFLAGS=" ${BITCODE_FLAGS} -isysroot ${SDK} -Wno-error -Wno-implicit-function-declaration ${EXTRAS} -fvisibility=hidden" | |
echo "Configuring for ${ARCH} ${TYPE}..." | |
./configure --prefix="${CURRENT}/gmplib-${ARCH}-${TYPE}" CC="${CLANG} ${CFLAGS}" LDFLAGS="${CFLAGS}" CPP="${CLANG} -E" CPPFLAGS="${CFLAGS}" \ | |
--host=aarch64-apple-darwin20.4.0 --disable-assembly --enable-static --disable-shared ${ARGS} &> "${CURRENT}/gmplib-${ARCH}-${TYPE}-configure.log" | |
echo "Make in progress for ${ARCH} ${TYPE}..." | |
make -j`sysctl -n hw.logicalcpu_max` &> "${CURRENT}/gmplib-${ARCH}-${TYPE}-build.log" | |
# if [ "${ARCH}" == "i386" ]; then | |
# echo "check in progress for ${ARCH}" | |
# make check &> "${CURRENT}/gmplib-${ARCH}-check.log" | |
# fi | |
echo "Install in progress for ${ARCH} ${TYPE}..." | |
make install &> "${CURRENT}/gmplib-${ARCH}-${TYPE}-install.log" | |
} | |
downloadGMP | |
cd gmp | |
CURRENT=`pwd` | |
echo "GMP $CURRENT" | |
if [[ -n $BUILD_IOS ]]; then | |
# build "armv7" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" | |
# build "armv7s" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" | |
build "arm64" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" "" | |
# build "i386" "${IPHONESIMULATOR_SDK}" "${IPHONESIMULATOR_PLATFORM}" "" "ios" | |
build "x86_64" "${IPHONESIMULATOR_SDK}" "${IPHONESIMULATOR_PLATFORM}" "" "ios" "-simulator" | |
[ -d gmplib/ios ] || mkdir -p gmplib/ios | |
cp -r "${CURRENT}/gmplib-arm64-ios/include" gmplib/include | |
echo "Creating Fat library" | |
lipo \ | |
"${CURRENT}/gmplib-arm64-ios/lib/libgmp.a" \ | |
"${CURRENT}/gmplib-x86_64-ios/lib/libgmp.a" \ | |
-create -output "${CURRENT}/gmplib/ios/libgmp.a" | |
# "${CURRENT}/gmplib-armv7-ios/lib/libgmp.a" | |
# "${CURRENT}/gmplib-i386-ios/lib/libgmp.a" | |
fi | |
if [[ -n $BUILD_OSX ]]; then | |
# build "i386" "${OSX_SDK}" "${OSX_PLATFORM}" "ABI=32" "osx" | |
build "x86_64" "${OSX_SDK}" "${OSX_PLATFORM}" "ABI=64" "osx" | |
[ -d gmplib/osx ] || mkdir -p gmplib/osx | |
cp -r "${CURRENT}/gmplib-x86_64-osx/include" gmplib/include | |
echo "Creating Fat library" | |
cp "${CURRENT}/gmplib-x86_64-osx/lib/libgmp.a" "${CURRENT}/gmplib/osx/libgmp.a" | |
# lipo \ | |
# "${CURRENT}/gmplib-i386-osx/lib/libgmp.a" \ | |
# "${CURRENT}/gmplib-x86_64-osx/lib/libgmp.a" \ | |
# -create -output "${CURRENT}/gmplib/osx/libgmp.a" | |
fi | |
echo "Done with GMP!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#=============================================================================== | |
# Filename: build_mpfr.sh | |
# Author: Volodymyr Boichentsov | |
# Copyright: (c) Copyright 2015 3D4Medical.com | |
# Licence: Only for 3D4Medical.com company needs | |
#=============================================================================== | |
BUILD_IOS= | |
BUILD_OSX= | |
unknownParameter() | |
{ | |
if [[ -n $2 && $2 != "" ]]; then | |
echo Unknown argument \"$2\" for parameter $1. | |
else | |
echo Unknown argument $1 | |
fi | |
die | |
} | |
parseArgs() | |
{ | |
while [ "$1" != "" ]; do | |
case $1 in | |
-ios) | |
BUILD_IOS=1 | |
;; | |
-osx) | |
BUILD_OSX=1 | |
;; | |
--min-ios-version) | |
if [ -n $2 ]; then | |
SDKVERSION=$2 | |
shift | |
else | |
missingParameter $1 | |
fi | |
;; | |
--min-macosx-version) | |
if [ -n $2 ]; then | |
SDKVERSION=$2 | |
shift | |
else | |
missingParameter $1 | |
fi | |
;; | |
*) | |
unknownParameter $1 | |
;; | |
esac | |
shift | |
done | |
} | |
parseArgs $@ | |
if [[ -z $BUILD_IOS && -z $BUILD_OSX ]]; then | |
BUILD_IOS=1 | |
fi | |
CURRENT=`pwd` | |
# if [ -d "${CURRENT}/mpfr/mpfrlib" ]; then | |
# exit | |
# fi | |
__pr="--print-path" | |
__name="xcode-select" | |
DEVELOPER=`${__name} ${__pr}` | |
MPFR_VERSION="3.1.3" | |
if [[ -z $SDKVERSION ]]; then | |
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` | |
fi | |
BITCODE_FLAGS=" -disable-llvm-optzns -O3" | |
if [ "${SDKVERSION}" == "9.0" ]; then | |
BITCODE_FLAGS="" | |
fi | |
OSX_PLATFORM=`xcrun --sdk macosx --show-sdk-platform-path` | |
OSX_SDK=`xcrun --sdk macosx --show-sdk-path` | |
IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path` | |
IPHONEOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` | |
IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path` | |
IPHONESIMULATOR_SDK=`xcrun --sdk iphonesimulator --show-sdk-path` | |
CLANG=`xcrun --sdk iphoneos --find clang` | |
CLANGPP=`xcrun --sdk iphoneos --find clang++` | |
downloadMPFR() | |
{ | |
if [ ! -d "${CURRENT}/mpfr" ]; then | |
echo "Downloading MPFR" | |
curl -L -o "${CURRENT}/mpfr-${MPFR_VERSION}.tar.bz2" http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.bz2 | |
tar xfj "mpfr-${MPFR_VERSION}.tar.bz2" | |
mv mpfr-${MPFR_VERSION} mpfr | |
rm "mpfr-${MPFR_VERSION}.tar.bz2" | |
fi | |
} | |
build() | |
{ | |
ARCH=$1 | |
SDK=$2 | |
PLATFORM=$3 | |
ARGS=$4 | |
TYPE=$5 | |
make clean &> "${CURRENT}/clean.log" | |
make distclean &> "${CURRENT}/clean.log" | |
export PATH="${PLATFORM}/Developer/usr/bin:${DEVELOPER}/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" | |
if [ -d "mpfrlib-${ARCH}-${TYPE}" ] ; then | |
rm -rf "mpfrlib-${ARCH}-${TYPE}" | |
fi | |
mkdir "mpfrlib-${ARCH}-${TYPE}" | |
EXTRAS="-arch ${ARCH}" | |
if [ "${TYPE}" == "ios" ]; then | |
EXTRAS="${EXTRAS} -miphoneos-version-min=${SDKVERSION} -no-integrated-as -target ${ARCH}-apple-darwin" | |
fi | |
if [ "${TYPE}" == "osx" ]; then | |
echo "macOS deployment target ${SDKVERSION}" | |
EXTRAS="${EXTRAS} -mmacosx-version-min=${SDKVERSION} " | |
fi | |
if [ "${ARCH}" == "i386" ]; then | |
EXTRAS="${EXTRAS} -m32" | |
fi | |
CFLAGS=" ${BITCODE_FLAGS} -isysroot ${SDK} -Wno-error -Wno-implicit-function-declaration ${EXTRAS} -fvisibility=hidden" | |
GMP_LIB_PATH="${CURRENT}/../gmp/gmplib-${ARCH}-${TYPE}" | |
GMP_PATH="${CURRENT}/../gmp" | |
echo "Configuring for ${ARCH} ${TYPE}..." | |
./configure --prefix="${CURRENT}/mpfrlib-${ARCH}-${TYPE}" CC="${CLANG} ${CFLAGS}" CPP="${CLANG} -E" --with-gmp="${GMP_LIB_PATH}" \ | |
--host=x86_64-apple-darwin --disable-assembly --enable-static --disable-shared ${ARGS} &> "${CURRENT}/mpfrlib-${ARCH}-${TYPE}-configure.log" | |
echo "Make in progress for ${ARCH} ${TYPE}..." | |
make -j`sysctl -n hw.logicalcpu_max` &> "${CURRENT}/mpfrlib-${ARCH}-${TYPE}-build.log" | |
# if [ "${ARCH}" == "i386" ]; then | |
# echo "check in progress for ${ARCH}" | |
# make check &> "${CURRENT}/mpfrlib-${ARCH}-check.log" | |
# fi | |
echo "Install in progress for ${ARCH} ${TYPE}..." | |
make install &> "${CURRENT}/mpfrlib-${ARCH}-${TYPE}-install.log" | |
} | |
downloadMPFR | |
cd mpfr | |
CURRENT=`pwd` | |
if [[ -n $BUILD_IOS ]]; then | |
# build "armv7" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" | |
# build "armv7s" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" | |
build "arm64" "${IPHONEOS_SDK}" "${IPHONEOS_PLATFORM}" "" "ios" | |
# build "i386" "${IPHONESIMULATOR_SDK}" "${IPHONESIMULATOR_PLATFORM}" "" "ios" | |
build "x86_64" "${IPHONESIMULATOR_SDK}" "${IPHONESIMULATOR_PLATFORM}" "" "ios" | |
[ -d mpfrlib/ios ] || mkdir -p mpfrlib/ios | |
cp -r "${CURRENT}/mpfrlib-arm64-ios/include" mpfrlib/include | |
echo "Creating Fat library" | |
lipo \ | |
"${CURRENT}/mpfrlib-arm64-ios/lib/libmpfr.a" \ | |
"${CURRENT}/mpfrlib-x86_64-ios/lib/libmpfr.a" \ | |
-create -output "${CURRENT}/mpfrlib/ios/libmpfr.a" | |
# "${CURRENT}/mpfrlib-armv7-ios/lib/libmpfr.a" | |
# "${CURRENT}/mpfrlib-i386-ios/lib/libmpfr.a" | |
fi | |
if [[ -n $BUILD_OSX ]]; then | |
# build "i386" "${OSX_SDK}" "${OSX_PLATFORM}" "" "osx" | |
build "x86_64" "${OSX_SDK}" "${OSX_PLATFORM}" "" "osx" | |
[ -d mpfrlib/osx ] || mkdir -p mpfrlib/osx | |
cp -r "${CURRENT}/mpfrlib-x86_64-osx/include" mpfrlib/include | |
echo "Creating Fat library" | |
cp "${CURRENT}/mpfrlib-x86_64-osx/lib/libmpfr.a" "${CURRENT}/mpfrlib/osx/libmpfr.a" | |
# lipo \ | |
# "${CURRENT}/mpfrlib-i386-osx/lib/libmpfr.a" \ | |
# "${CURRENT}/mpfrlib-x86_64-osx/lib/libmpfr.a" \ | |
# -create -output "${CURRENT}/mpfrlib/osx/libmpfr.a" | |
fi | |
echo "Done with MPFR!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment