Skip to content

Instantly share code, notes, and snippets.

@sakrist
Last active November 9, 2022 06:27
Show Gist options
  • Save sakrist/0ceaa98fb16535998020 to your computer and use it in GitHub Desktop.
Save sakrist/0ceaa98fb16535998020 to your computer and use it in GitHub Desktop.
GMP and MPFR compile for iOS
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
#!/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
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} -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"
echo "Configuring for ${ARCH} ${TYPE}..."
./configure --prefix="${CURRENT}/gmplib-${ARCH}-${TYPE}" CC="${CLANG} ${CFLAGS}" LDFLAGS="${CFLAGS}" CPP="${CLANG} -E" CPPFLAGS="${CFLAGS}" \
--host=x86_64-apple-darwin --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"
[ -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!"
#!/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!"
@nijindal
Copy link

I have been trying to build gmp for iOS using the above script. I am able to run the script but it doesn't generate libgmp.a file in lib folder.
I am trying to build it for Min deployment target 7.0 on iOS SDK 8.4.

Console output:

➜  repos  sh build_gmp.sh
++ pwd
+ CURRENT=/Users/nikhil.ji/repos
+ __pr=--print-path
+ __name=xcode-select
++ xcode-select --print-path
+ DEVELOPER=/Applications/Xcode.app/Contents/Developer
+ GMP_VERSION=5.1.3
++ xcrun -sdk iphoneos --show-sdk-version
+ SDKVERSION=8.4
+ MIN_IOS=7.0
+ BITCODE=-fembed-bitcode
+ '[' 8.4 == 9.0 ']'
++ xcrun --sdk macosx --show-sdk-platform-path
+ OSX_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
++ xcrun --sdk macosx --show-sdk-path
+ OSX_SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
++ xcrun --sdk iphoneos --show-sdk-platform-path
+ IPHONEOS_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
++ xcrun --sdk iphoneos --show-sdk-path
+ IPHONEOS_SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk
++ xcrun --sdk iphonesimulator --show-sdk-platform-path
+ IPHONESIMULATOR_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform
++ xcrun --sdk iphonesimulator --show-sdk-path
+ IPHONESIMULATOR_SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk
++ xcrun --sdk iphoneos --find clang
+ CLANG=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
++ xcrun --sdk iphoneos --find clang++
+ CLANGPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
+ downloadGMP
+ '[' '!' -s /Users/nikhil.ji/repos/gmp-5.1.3.tar.bz2 ']'
+ echo 'Downloading GMP'
Downloading GMP
+ curl -L -o /Users/nikhil.ji/repos/gmp-5.1.3.tar.bz2 ftp://ftp.gmplib.org/pub/gmp/gmp-5.1.3.tar.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2145k  100 2145k    0     0   334k      0  0:00:06  0:00:06 --:--:--  528k
+ rm -rf gmp
+ tar xfj gmp-5.1.3.tar.bz2
+ mv gmp-5.1.3 gmp
+ cd gmp
++ pwd
+ CURRENT=/Users/nikhil.ji/repos/gmp
+ build armv7 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+ ARCH=armv7
+ SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk
+ PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+ ARGS=
+ make clean
make: *** No rule to make target `clean'.  Stop.
+ make distclean
make: *** No rule to make target `distclean'.  Stop.
+ export PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ mkdir gmplib-armv7
+ EXTRAS=
+ '[' armv7 '!=' x64_86 ']'
+ EXTRAS='-miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin'
+ CFLAGS='-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin'
+ ./configure --prefix=/Users/nikhil.ji/repos/gmp/gmplib-armv7 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin' 'CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E' 'CPPFLAGS=-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin' --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared
checking build system type... i386-apple-darwin14.4.0
checking host system type... aarch64-apple-darwin
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-apple-darwin-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin  -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin... no
checking for aarch64-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch armv7 -target armv7-apple-darwin
checking whether the C compiler works... no
configure: error: in `/Users/nikhil.ji/repos/gmp':
configure: error: C compiler cannot create executables
See `config.log' for more details
+ echo 'make in progress for armv7'
make in progress for armv7
++ sysctl -n hw.logicalcpu_max
+ make -j 4
+ echo 'install in progress for armv7'
install in progress for armv7
+ make install
+ build arm64 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+ ARCH=arm64
+ SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk
+ PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
+ ARGS=
+ make clean
make: *** No rule to make target `clean'.  Stop.
+ make distclean
make: *** No rule to make target `distclean'.  Stop.
+ export PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ mkdir gmplib-arm64
+ EXTRAS=
+ '[' arm64 '!=' x64_86 ']'
+ EXTRAS='-miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin'
+ CFLAGS='-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin'
+ ./configure --prefix=/Users/nikhil.ji/repos/gmp/gmplib-arm64 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin' 'CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E' 'CPPFLAGS=-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin' --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared
checking build system type... i386-apple-darwin14.4.0
checking host system type... aarch64-apple-darwin
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-apple-darwin-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin  -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin... no
checking for aarch64-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch arm64 -target arm64-apple-darwin
checking whether the C compiler works... no
configure: error: in `/Users/nikhil.ji/repos/gmp':
configure: error: C compiler cannot create executables
See `config.log' for more details
+ echo 'make in progress for arm64'
make in progress for arm64
++ sysctl -n hw.logicalcpu_max
+ make -j 4
+ echo 'install in progress for arm64'
install in progress for arm64
+ make install
+ build i386 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform
+ ARCH=i386
+ SDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk
+ PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform
+ ARGS=
+ make clean
make: *** No rule to make target `clean'.  Stop.
+ make distclean
make: *** No rule to make target `distclean'.  Stop.
+ export PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ mkdir gmplib-i386
+ EXTRAS=
+ '[' i386 '!=' x64_86 ']'
+ EXTRAS='-miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin'
+ CFLAGS='-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin'
+ ./configure --prefix=/Users/nikhil.ji/repos/gmp/gmplib-i386 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin' 'CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E' 'CPPFLAGS=-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin' --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared
checking build system type... i386-apple-darwin14.4.0
checking host system type... aarch64-apple-darwin
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-apple-darwin-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin  -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin... no
checking for aarch64-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -Wno-error -Wno-implicit-function-declaration -miphoneos-version-min=7.0 -no-integrated-as -arch i386 -target i386-apple-darwin
checking whether the C compiler works... no
configure: error: in `/Users/nikhil.ji/repos/gmp':
configure: error: C compiler cannot create executables
See `config.log' for more details
+ echo 'make in progress for i386'
make in progress for i386
++ sysctl -n hw.logicalcpu_max
+ make -j 4
+ echo 'install in progress for i386'
install in progress for i386
+ make install
+ build x64_86 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
+ ARCH=x64_86
+ SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
+ PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
+ ARGS=
+ make clean
make: *** No rule to make target `clean'.  Stop.
+ make distclean
make: *** No rule to make target `distclean'.  Stop.
+ export PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+ mkdir gmplib-x64_86
+ EXTRAS=
+ '[' x64_86 '!=' x64_86 ']'
+ CFLAGS='-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration '
+ ./configure --prefix=/Users/nikhil.ji/repos/gmp/gmplib-x64_86 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration ' 'CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E' 'CPPFLAGS=-fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration ' --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared
checking build system type... i386-apple-darwin14.4.0
checking host system type... aarch64-apple-darwin
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-apple-darwin-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=standard
checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration   -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration ... no
checking for aarch64-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wno-error -Wno-implicit-function-declaration
checking whether the C compiler works... no
configure: error: in `/Users/nikhil.ji/repos/gmp':
configure: error: C compiler cannot create executables
See `config.log' for more details
+ echo 'make in progress for x64_86'
make in progress for x64_86
++ sysctl -n hw.logicalcpu_max
+ make -j 4
+ echo 'install in progress for x64_86'
install in progress for x64_86
+ make install
+ mkdir include
+ cp -r /Users/nikhil.ji/repos/gmp/gmplib-x64_86/include include/
cp: /Users/nikhil.ji/repos/gmp/gmplib-x64_86/include: No such file or directory
+ mkdir lib
+ echo 'doing lipo'
doing lipo
+ lipo /Users/nikhil.ji/repos/gmp/gmplib-armv7/lib/libgmp.a /Users/nikhil.ji/repos/gmp/gmplib-arm64/lib/libgmp.a /Users/nikhil.ji/repos/gmp/gmplib-i386/lib/libgmp.a /Users/nikhil.ji/repos/gmp/gmplib-x64_86/lib/libgmp.a -create -output lib/libgmp.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/nikhil.ji/repos/gmp/gmplib-armv7/lib/libgmp.a (No such file or directory)
+ echo 'lib done'
lib done
+ echo /Users/nikhil.ji/repos/gmp/lib/libgmp.a
/Users/nikhil.ji/repos/gmp/lib/libgmp.a
+ echo /Users/nikhil.ji/repos/gmp/include
/Users/nikhil.ji/repos/gmp/include

@ivme
Copy link

ivme commented Jan 7, 2016

Thanks for the great script!

Note: I found that this script produced a gmp library that did not work with iPhone 5s and later (both physical devices and simulators) because of the switch to x86_64 architecture for iPhone 5s and higher. Although the script does compile a library for the x86_64 architecture and include that library in the universal binary it produces, the x86_64 library it produces is tagged for the OSX platform rather than the iPhoneOS platform (see this post). If you try to link against it in Xcode when building for iPhone 5s or 5s simulator or higher, you get a "building for iOS simulator, but linking in object file built for OSX, for architecture x86_64" error. The solution I found was to replace line 92 of the script with:

build "x84_64" "${IPHONESIMULATOR_SDK}" "${IPHONESIMULATOR_PLATFORM}"

I also changed all of the author's other references to "x64_86" with "x86_64." Not sure that that makes a difference, but I thought it was a typo.

After making this change I was able to link against the fat binary produced by this script with iPhone 5 and 6 Plus hardware and all simulators.

@westinpigott
Copy link

This script is clutch. Thanks so much!

@neteali
Copy link

neteali commented May 31, 2016

GMP script work fine with the ivme corrections.
MPFR script need a path without whitespace (example: /users/Documents/my projects/mprf)

@dangaffey
Copy link

Awesome stuff. Exactly what I needed.

@sakrist
Copy link
Author

sakrist commented Jul 20, 2016

@nijindal If you was thinking get some attention, you need mention name.

@ivme it's actually producing different arch armv7 and arm64 included in one lib. Maybe script is old for now.
Will see if I can share newer version.

thanks guys :)

@himamis
Copy link

himamis commented Mar 8, 2017

Awesome script, thank you very much!
One note though, it seems that the mpfr script doesn't use BITCODE variable in the CFLAGS, while gmp does.

@zwang
Copy link

zwang commented Aug 10, 2017

@sakrist thanks for the great script. Just want I need

@ivme thanks for the fix. It make sense.

Does any one got error after uploading the app to app store? I have a super simple app with the lib embed in the project. When I upload the app with "Include BitCode" checked to the app store, I got an email from app store like below:

We have discovered one or more issues with your recent delivery for "Stage". To process your delivery, the following issues must be corrected:

Invalid Bundle - The app cannot be processed because options not allowed to be embedded in bitcode are detected in the submission. It is likely that you are not building the app with the toolchain provided in Xcode. Rebuild your entire app with the latest GM Xcode and submit the app again.

If I have "Include BitCode" unchecked, then it will be fine.

My build env is iOS SDK 10.3, Xcode 8.3.3. With latest Mac OS X 10.12.6

I create a sample project here (the testGMPLibOnly branch): https://github.com/zwang/TestFactorize/tree/testGMPLibOnly

Thank you in advance for any help.

@podkovyrin
Copy link

Hey, @zwang! Have you solved the issue with bitcode? I'm facing the same issue

@DzmitrySmaliakou
Copy link

@zwang, @podkovyrin, Have you found a solution for bitcode error?

@podkovyrin
Copy link

@DmitrySmolyakov I had, take a look at the prepare command in the following podspec:
https://github.com/dashevo/dashsync-iOS/blob/master/bls-signatures-pod/bls-signatures-pod.podspec

@DzmitrySmaliakou
Copy link

@podkovyrin Thank you! I will take a look

@quaternionboy
Copy link

quaternionboy commented Apr 15, 2021

@sakrist thanks for the script . Looks awesome but I'm not able to generate GMP for iOS:

Downloading GMP
 % Total  % Received % Xferd Average Speed  Time  Time   Time Current
                 Dload Upload  Total  Spent  Left Speed
100 2435k 100 2435k  0   0  367k   0 0:00:06 0:00:06 --:--:-- 498k
GMP /Users/ferran/Documents/Maker/Projects/Metal Generative Framework/CGAL/GMP iOS/C/x/gmp
Configuring for arm64 ios...
Make in progress for arm64 ios...
Install in progress for arm64 ios...
Configuring for x86_64 ios...
Make in progress for x86_64 ios...
Install in progress for x86_64 ios...
cp: /Users/_/Documents/Maker/Projects/Metal Generative Framework/CGAL/GMP iOS/C/x/gmp/gmplib-arm64-ios/include: No such file or directory
Creating Fat library
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/_/Documents/Maker/Projects/Metal Generative Framework/CGAL/GMP iOS/C/x/gmp/gmplib-arm64-ios/lib/libgmp.a (No such file or directory)
Done with GMP!

I tried to fix it without success... Can you take a look, please?

@anatoliy281
Copy link

 Thank you, my good man!

@primetimer
Copy link

Anyone has a hint to use it on AppleSilicon: I get the error:
Building for iOS Simulator, but the linked library 'libgmp.a' was built for iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment