Skip to content

Commit

Permalink
Merge pull request #61 from devsisters/macos-support
Browse files Browse the repository at this point in the history
Fix local build & add macOS support
  • Loading branch information
leenjewel authored Oct 27, 2020
2 parents b7e835d + 15fdd48 commit d55501d
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 62 deletions.
18 changes: 13 additions & 5 deletions tools/build-android-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@

source ./build-common.sh

if [ -z ${arch+x} ]; then
arch=("arm" "arm64" "x86" "x86_64")
fi
if [ -z ${abi+x} ]; then
abi=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")
fi
if [ -z ${api+x} ]; then
api=23
fi

export PLATFORM_TYPE="Android"
export ARCHS=("$arch")
export ABIS=("$abi")
export ABI_TRIPLES=("$arch-linux-android")
export ANDROID_API=$api
export ARCHS=(${arch[@]})
export ABIS=(${abi[@]})
export ANDROID_API=(${api[@]})

# for test
# export ARCHS=("x86_64")
# export ABIS=("x86_64")
# export ABI_TRIPLES=("x86_64-linux-android")

if [[ -z ${ANDROID_NDK_ROOT} ]]; then
echo "ANDROID_NDK_ROOT not defined"
Expand Down
6 changes: 5 additions & 1 deletion tools/build-android-curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-android-common.sh

if [ -z ${version+x} ]; then
version="7.68.0"
fi

init_log_color

TOOLS_ROOT=$(pwd)
Expand Down Expand Up @@ -124,7 +128,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
2 changes: 1 addition & 1 deletion tools/build-android-lz4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
6 changes: 5 additions & 1 deletion tools/build-android-nghttp2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-android-common.sh

if [ -z ${version+x} ]; then
version="1.40.0"
fi

init_log_color

TOOLS_ROOT=$(pwd)
Expand Down Expand Up @@ -115,7 +119,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
6 changes: 5 additions & 1 deletion tools/build-android-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-android-common.sh

if [ -z ${version+x} ]; then
version="1.1.1d"
fi

init_log_color

TOOLS_ROOT=$(pwd)
Expand Down Expand Up @@ -119,7 +123,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
2 changes: 1 addition & 1 deletion tools/build-android-rsync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
2 changes: 1 addition & 1 deletion tools/build-android-xxhash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
2 changes: 1 addition & 1 deletion tools/build-android-zstd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ log_info "${PLATFORM_TYPE} ${LIB_NAME} start..."

for ((i = 0; i < ${#ARCHS[@]}; i++)); do
if [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; then
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ABI_TRIPLES[i]}"
configure_make "${ARCHS[i]}" "${ABIS[i]}" "${ARCHS[i]}-linux-android"
fi
done

Expand Down
47 changes: 30 additions & 17 deletions tools/build-ios-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@

source ./build-common.sh

if [ -z ${api+x} ]; then
api="8.0"
fi
if [ -z ${arch+x} ]; then
arch=("armv7" "arm64" "arm64e" "x86_64")
fi
if [ -z ${sdk+x} ]; then
sdk=("iphoneos" "iphoneos" "iphoneos" "iphonesimulator")
fi
if [ -z ${platform+x} ]; then
platform=("iPhoneOS" "iPhoneOS" "iphoneos" "iPhoneSimulator")
fi

export PLATFORM_TYPE="iOS"
export IOS_MIN_TARGET="$api"
export ARCHS=("$arch")
export SDKS=("$sdk")
export PLATFORMS=("$platform")
export ARCHS=(${arch[@]})
export SDKS=(${sdk[@]})
export PLATFORMS=(${platform[@]})

# for test !!!
# export ARCHS=("armv7")
# export SDKS=("iphoneos")
# export PLATFORMS=("iPhoneOS")

function get_android_arch() {
function get_ios_arch() {
local common_arch=$1
case ${common_arch} in
armv7)
Expand All @@ -49,7 +62,7 @@ function get_android_arch() {
}

function ios_get_build_host() {
local arch=$(get_android_arch $1)
local arch=$(get_ios_arch $1)
case ${arch} in
armv7)
echo "armv7-ios-darwin"
Expand All @@ -69,47 +82,47 @@ function ios_get_build_host() {
esac
}

function set_android_cpu_feature() {
function set_ios_cpu_feature() {
local name=$1
local arch=$(get_android_arch $2)
local arch=$(get_ios_arch $2)
local ios_min_target=$3
local sysroot=$4
case ${arch} in
armv7)
export CC="xcrun -sdk iphoneos clang -arch armv7"
export CXX="xcrun -sdk iphoneos clang++ -arch armv7"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++14 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CXXFLAGS="-std=c++14 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64)
export CC="xcrun -sdk iphoneos clang -arch arm64"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++14 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CXXFLAGS="-std=c++14 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
arm64e)
# -march=armv8.3 ???
export CC="xcrun -sdk iphoneos clang -arch arm64e"
export CXX="xcrun -sdk iphoneos clang++ -arch arm64e"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -isysroot ${sysroot} -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -isysroot ${sysroot} -fembed-bitcode -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++14 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CXXFLAGS="-std=c++14 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -fembed-bitcode -miphoneos-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
x86)
export CC="xcrun -sdk iphonesimulator clang -arch x86"
export CXX="xcrun -sdk iphonesimulator clang++ -arch x86"
export CFLAGS="-arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -isysroot ${sysroot} -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch x86 -target x86-ios-darwin -march=i386 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++14 -arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -DIOS -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CXXFLAGS="-std=c++14 -arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
x86-64)
export CC="xcrun -sdk iphonesimulator clang -arch x86_64"
export CXX="xcrun -sdk iphonesimulator clang++ -arch x86_64"
export CFLAGS="-arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -DIOS -isysroot ${sysroot} -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CFLAGS="-arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -isysroot ${sysroot} -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export LDFLAGS="-arch x86_64 -target x86_64-ios-darwin -march=x86-64 -isysroot ${sysroot} -L${sysroot}/usr/lib "
export CXXFLAGS="-std=c++14 -arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -DIOS -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
export CXXFLAGS="-std=c++14 -arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -mios-simulator-version-min=${ios_min_target} -I${sysroot}/usr/include"
;;
*)
log_error "not support" && exit 1
Expand Down
17 changes: 6 additions & 11 deletions tools/build-ios-curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-ios-common.sh

if [ -z ${version+x} ]; then
version="7.68.0"
fi

TOOLS_ROOT=$(pwd)

SOURCE="$0"
Expand All @@ -45,7 +49,6 @@ echo "https://github.com/curl/curl/releases/download/${LIB_VERSION}/${LIB_NAME}.
# https://github.com/curl/curl/releases/download/curl-7_69_0/curl-7.69.0.tar.gz
# https://github.com/curl/curl/releases/download/curl-7_68_0/curl-7.68.0.tar.gz
DEVELOPER=$(xcode-select -print-path)
SDK_VERSION=$(xcrun -sdk iphoneos --show-sdk-version)
rm -rf "${LIB_DEST_DIR}" "${LIB_NAME}"
[ -f "${LIB_NAME}.tar.gz" ] || curl -LO https://github.com/curl/curl/releases/download/${LIB_VERSION}/${LIB_NAME}.tar.gz >${LIB_NAME}.tar.gz

Expand All @@ -54,6 +57,7 @@ function configure_make() {
ARCH=$1
SDK=$2
PLATFORM=$3
SDK_PATH=$(xcrun -sdk ${SDK} --show-sdk-path)

log_info "configure $ARCH start..."

Expand All @@ -64,15 +68,6 @@ function configure_make() {
pushd .
cd "${LIB_NAME}"

export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"

if [ ! -d ${CROSS_TOP}/SDKs/${CROSS_SDK} ]; then
log_error "ERROR: iOS SDK version:'${SDK_VERSION}' incorrect, SDK in your system is:"
xcodebuild -showsdks | grep iOS
exit -1
fi

PREFIX_DIR="${pwd_path}/../output/ios/curl-${ARCH}"
if [ -d "${PREFIX_DIR}" ]; then
rm -fr "${PREFIX_DIR}"
Expand All @@ -82,7 +77,7 @@ function configure_make() {
OUTPUT_ROOT=${TOOLS_ROOT}/../output/ios/curl-${ARCH}
mkdir -p ${OUTPUT_ROOT}/log

set_android_cpu_feature "nghttp2" "${ARCH}" "${IOS_MIN_TARGET}" "${CROSS_TOP}/SDKs/${CROSS_SDK}"
set_ios_cpu_feature "curl" "${ARCH}" "${IOS_MIN_TARGET}" "${SDK_PATH}"

OPENSSL_OUT_DIR="${pwd_path}/../output/ios/openssl-${ARCH}"
NGHTTP2_OUT_DIR="${pwd_path}/../output/ios/nghttp2-${ARCH}"
Expand Down
17 changes: 6 additions & 11 deletions tools/build-ios-nghttp2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-ios-common.sh

if [ -z ${version+x} ]; then
version="1.40.0"
fi

TOOLS_ROOT=$(pwd)

SOURCE="$0"
Expand All @@ -42,7 +46,6 @@ init_log_color
echo "https://github.com/nghttp2/nghttp2/releases/download/${LIB_VERSION}/${LIB_NAME}.tar.gz"

DEVELOPER=$(xcode-select -print-path)
SDK_VERSION=$(xcrun -sdk iphoneos --show-sdk-version)
rm -rf "${LIB_DEST_DIR}" "${LIB_NAME}"
[ -f "${LIB_NAME}.tar.gz" ] || curl -LO https://github.com/nghttp2/nghttp2/releases/download/${LIB_VERSION}/${LIB_NAME}.tar.gz >${LIB_NAME}.tar.gz

Expand All @@ -51,6 +54,7 @@ function configure_make() {
ARCH=$1
SDK=$2
PLATFORM=$3
SDK_PATH=$(xcrun -sdk ${SDK} --show-sdk-path)

log_info "configure $ARCH start..."

Expand All @@ -61,15 +65,6 @@ function configure_make() {
pushd .
cd "${LIB_NAME}"

export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"

if [ ! -d ${CROSS_TOP}/SDKs/${CROSS_SDK} ]; then
log_error "ERROR: iOS SDK version:'${SDK_VERSION}' incorrect, SDK in your system is:"
xcodebuild -showsdks | grep iOS
exit -1
fi

PREFIX_DIR="${pwd_path}/../output/ios/nghttp2-${ARCH}"
if [ -d "${PREFIX_DIR}" ]; then
rm -fr "${PREFIX_DIR}"
Expand All @@ -79,7 +74,7 @@ function configure_make() {
OUTPUT_ROOT=${TOOLS_ROOT}/../output/ios/nghttp2-${ARCH}
mkdir -p ${OUTPUT_ROOT}/log

set_android_cpu_feature "nghttp2" "${ARCH}" "${IOS_MIN_TARGET}" "${CROSS_TOP}/SDKs/${CROSS_SDK}"
set_ios_cpu_feature "nghttp2" "${ARCH}" "${IOS_MIN_TARGET}" "${SDK_PATH}"

ios_printf_global_params "$ARCH" "$SDK" "$PLATFORM" "$PREFIX_DIR" "$OUTPUT_ROOT"

Expand Down
17 changes: 6 additions & 11 deletions tools/build-ios-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ set -u

source ./build-ios-common.sh

if [ -z ${version+x} ]; then
version="1.1.1d"
fi

TOOLS_ROOT=$(pwd)

SOURCE="$0"
Expand All @@ -46,7 +50,6 @@ echo "https://www.openssl.org/source/${LIB_NAME}.tar.gz"
# https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz
# https://github.com/openssl/openssl/archive/OpenSSL_1_1_1f.tar.gz
DEVELOPER=$(xcode-select -print-path)
SDK_VERSION=$(xcrun -sdk iphoneos --show-sdk-version)
rm -rf "${LIB_DEST_DIR}" "${LIB_NAME}"
[ -f "${LIB_NAME}.tar.gz" ] || curl https://www.openssl.org/source/${LIB_NAME}.tar.gz >${LIB_NAME}.tar.gz

Expand All @@ -55,6 +58,7 @@ function configure_make() {
ARCH=$1
SDK=$2
PLATFORM=$3
SDK_PATH=$(xcrun -sdk ${SDK} --show-sdk-path)

log_info "configure $ARCH start..."

Expand All @@ -65,15 +69,6 @@ function configure_make() {
pushd .
cd "${LIB_NAME}"

export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"

if [ ! -d ${CROSS_TOP}/SDKs/${CROSS_SDK} ]; then
log_error "ERROR: iOS SDK version:'${SDK_VERSION}' incorrect, SDK in your system is:"
xcodebuild -showsdks | grep iOS
exit -1
fi

PREFIX_DIR="${pwd_path}/../output/ios/openssl-${ARCH}"
if [ -d "${PREFIX_DIR}" ]; then
rm -fr "${PREFIX_DIR}"
Expand All @@ -83,7 +78,7 @@ function configure_make() {
OUTPUT_ROOT=${TOOLS_ROOT}/../output/ios/openssl-${ARCH}
mkdir -p ${OUTPUT_ROOT}/log

set_android_cpu_feature "nghttp2" "${ARCH}" "${IOS_MIN_TARGET}" "${CROSS_TOP}/SDKs/${CROSS_SDK}"
set_ios_cpu_feature "openssl" "${ARCH}" "${IOS_MIN_TARGET}" "${SDK_PATH}"

ios_printf_global_params "$ARCH" "$SDK" "$PLATFORM" "$PREFIX_DIR" "$OUTPUT_ROOT"

Expand Down
Loading

0 comments on commit d55501d

Please sign in to comment.