Mac上交叉编译iOS静态库

本文主要以fftw为例子,进行iOS静态库的编译。

环境要求:

➜  ~ xcodebuild -version
Xcode 9.4.1
Build version 9F2000

运行脚本如下:

#!/bin/sh

xcodebuild -version
xcodeversion_current=`xcodebuild -version`
xcodeversion="7.3.1"
result=$(echo $xcodeversion_current | grep "$xcodeversion")
echo $result
if [[ "$result" != "" ]]
then
  echo "此时Xcode版本设置错误,请运行命令 'sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer' 来更换Xcode版本 "
  exit
fi

# build for iOS / Mac
# changed by 10mitri
# original:
# http://stackoverflow.com/questions/3588904/how-to-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project-in


# this is the folder where the libs will be generated
export OUTPUT_DIR=a_ios-libs

# Select toolchains folder
export XCODE_TOOLCHAINS=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain


#$(CURRENT_ARCH)

build_target()
{
    PLATFORM=$1
    ARCH=$2
    SDK_VERSION=$3
    CONFIGURE_HOST=$4
    IOS_DEPLOYMENT_TARGET=$5

    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDK_VERSION.sdk

    export CPPFLAGS="-I$SDKROOT/usr/include/ -mfpu=neon"
    export CFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -mfpu=neon -O3"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode -mfpu=neon"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode -mfpu=neon"

    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo -------------- BUILD TARGET
    echo -------------- PLATFORM : $PLATFORM
    echo -------------- ARCH : $ARCH
    echo -------------- SDK_VERSION : $SDK_VERSION
    echo -------------- HOST : $CONFIGURE_HOST
    echo -------------- MIN iOS : $IOS_DEPLOYMENT_TARGET
    echo -------------- SDK PATH : $SDKROOT
    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo ---------------------------------------------------

    #sleep 3

    make clean

    ./configure --host=$CONFIGURE_HOST --enable-float  --enable-$ARCH-cntvct

    make -j4

    mkdir $OUTPUT_DIR/$ARCH

    # Copy the lib
    cp .libs/libfftw3f.a $OUTPUT_DIR/$ARCH/libfftw3f.a

    unset CPPFLAGS CFLAGS LD CXX CC
}


mkdir $OUTPUT_DIR

rm -rf $OUTPUT_DIR/*

# Copy the header file too, just for convenience
cp api/fftw3.h $OUTPUT_DIR/fftw3.h

#build_target "iPhoneOS" "armv7s" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "armv7" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "arm64" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneSimulator" "x86_64" "11.4" "x86_64-apple-darwin" "7.0"
build_target "iPhoneSimulator" "i386" "11.4" "i386-apple-darwin" "7.0"

#build_target "MacOSX" "x86_64" "11.4" "i386-apple-darwin" "7.0"

你可能感兴趣的:(Mac上交叉编译iOS静态库)