- indent
homebrew:
packages:
- - gnu-indent
- - doxygen
- openssl
- - indent
+ - doxygen
+ - findent
+ update: true
jobs:
include:
arch: s390x
dist: bionic
env: VALGRIND=true ANALYSIS=true COVERAGE=true DOXYGEN=true
+ - os: osx
+ osx_image: xcode10.1
+ name: iPhoneOS, armv7, iOS
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=armv7-apple-ios
+ - OPENSSL_HOST=ios-cross
+ - IOS_CPU=armv7s
+ - IOS_SDK=iPhoneOS
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: iPhoneOS, arm64, iOS
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=aarch64-apple-ios
+ - OPENSSL_HOST=ios64-cross
+ - IOS_CPU=arm64
+ - IOS_SDK=iPhoneOS
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: AppleTVOS, arm64, iOS
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=aarch64-apple-ios
+ - OPENSSL_HOST=ios64-cross
+ - IOS_CPU=arm64
+ - IOS_SDK=AppleTVOS
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: WatchOS, armv7, iOS
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=armv7-apple-ios
+ - OPENSSL_HOST=ios-cross
+ - IOS_CPU=armv7k
+ - IOS_SDK=WatchOS
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: iPhoneSimulator, i386, OS X
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=i386-apple-ios
+ - OPENSSL_HOST=iphoneos-cross
+ - IOS_CPU=i386
+ - IOS_SDK=iPhoneSimulator
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: iPhoneSimulator, x86_64, OS X
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=x86_64-apple-ios
+ - OPENSSL_HOST=iphoneos-cross
+ - IOS_CPU=x86_64
+ - IOS_SDK=iPhoneSimulator
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: AppleTVSimulator, x86_64, OS X
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=x86_64-apple-ios
+ - OPENSSL_HOST=iphoneos-cross
+ - IOS_CPU=x86_64
+ - IOS_SDK=AppleTVSimulator
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
+ - os: osx
+ osx_image: xcode10.1
+ name: WatchSimulator, i386, OS X
+ arch: amd64
+ env:
+ - IOS=yes
+ - AUTOTOOLS_HOST=i386-apple-ios
+ - OPENSSL_HOST=iphoneos-cross
+ - IOS_CPU=i386
+ - IOS_SDK=WatchSimulator
+ - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
- os: linux
name: Android armv7a, Linux, Amd64
compiler: clang
- |
if [ "$ANDROID" = "yes" ]; then
./contrib/android/install_tools.sh
+ elif [ "$IOS" = "yes" ]; then
+ ./contrib/ios/install_tools.sh
fi
script:
elif [ "$ASAN" = "true" ]; then
export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=address"
./test/test_ci.sh
+ elif [ "$IOS" = "yes" ]; then
+ export AUTOTOOLS_BUILD="$(./config.guess)"
+ export PKG_CONFIG_PATH="$IOS_PREFIX/lib/pkgconfig"
+ source ./contrib/ios/setenv_ios.sh
+ ./contrib/ios/install_openssl.sh
+ ./contrib/ios/bootstrap_ldns.sh
+ ./configure \
+ --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \
+ --prefix="$IOS_PREFIX" \
+ --with-ssl="$IOS_PREFIX" --disable-gost \
+ --with-drill --with-examples
+ make -j 2
+ make install
elif [ "$ANDROID" = "yes" ]; then
export AUTOTOOLS_BUILD="$(./config.guess)"
export PKG_CONFIG_PATH="$ANDROID_PREFIX/lib/pkgconfig"
AC_CHECK_HEADERS([winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT])
# end mingw32 tests
+# Check for Apple header. This uncovers TARGET_OS_IPHONE, TARGET_OS_TV or TARGET_OS_WATCH
+AC_CHECK_HEADERS([TargetConditionals.h])
+
ACX_DETERMINE_EXT_FLAGS_UNBOUND
AC_C_INLINE
echo "Running libtoolize"
if [ -n "$(command -v glibtoolize)" ]; then
rm -f config.guess config.sub
- if ! glibtool -ci ; then
+ if ! glibtoolize -ci ; then
echo "Failed to libtoolize (glibtoolize)"
exit 1
fi
#!/usr/bin/env bash
-# This step should install tools needed for all packages - OpenSSL and Unbound
+# This step should install tools needed for all packages - OpenSSL and LDNS
echo "Updating tools"
sudo apt-get -qq update
-sudo apt-get -qq install --no-install-recommends curl wget tar zip unzip perl openjdk-8-jdk autoconf automake libtool pkg-config
+sudo apt-get -qq install --no-install-recommends curl wget tar zip unzip patch perl openjdk-8-jdk autoconf automake libtool pkg-config
# Android builds run config.guess early to determine BUILD and HOST. We need to add config.guess
# and config.sub now. Later, bootstrap_ldns.sh will handle the complete bootrap of LDNS.
#!/usr/bin/env bash
-# Error checking
+# ====================================================================
+# Sets the cross compile environment for Android
+#
+# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM.
+# Heavily modified by JWW for Crypto++.
+# Updated by Skycoder42 for current recommendations for Android.
+# Modified by JWW for LDNS.
+# ====================================================================
+
+#########################################
+##### Some validation #####
+#########################################
+
+if [ -z "$ANDROID_API" ]; then
+ echo "ANDROID_API is not set. Please set it"
+ [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
+fi
+
+if [ -z "$ANDROID_CPU" ]; then
+ echo "ANDROID_CPU is not set. Please set it"
+ [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
+fi
+
if [ ! -d "$ANDROID_NDK_ROOT" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it."
echo "NDK root is $ANDROID_NDK_ROOT"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
+# cryptest-android.sh may run this script without sourcing.
+if [ "$0" = "${BASH_SOURCE[0]}" ]; then
+ echo "setenv-android.sh is usually sourced, but not this time."
+fi
+
#####################################################################
# Need to set THIS_HOST to darwin-x86_64, linux-x86_64,
-# windows-x86_64 or windows.
+# windows, or windows-x86_64
if [[ "$(uname -s | grep -i -c darwin)" -ne 0 ]]; then
THIS_HOST=darwin-x86_64
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
-AOSP_TOOLCHAIN_ROOT="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST"
-AOSP_TOOLCHAIN_PATH="$AOSP_TOOLCHAIN_ROOT/bin"
-AOSP_SYSROOT="$AOSP_TOOLCHAIN_ROOT/sysroot"
-
-# Error checking
-if [ ! -d "$AOSP_TOOLCHAIN_ROOT" ]; then
- echo "ERROR: AOSP_TOOLCHAIN_ROOT is not a valid path. Please set it."
- echo "Root is $AOSP_TOOLCHAIN_ROOT"
- [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
-fi
+ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST/bin"
+ANDROID_SYSROOT="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST/sysroot"
# Error checking
-if [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then
- echo "ERROR: AOSP_TOOLCHAIN_PATH is not a valid path. Please set it."
- echo "Path is $AOSP_TOOLCHAIN_PATH"
+if [ ! -d "$ANDROID_TOOLCHAIN" ]; then
+ echo "ERROR: ANDROID_TOOLCHAIN is not a valid path. Please set it."
+ echo "Path is $ANDROID_TOOLCHAIN"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -d "$AOSP_SYSROOT" ]; then
- echo "ERROR: AOSP_SYSROOT is not a valid path. Please set it."
- echo "Path is $AOSP_SYSROOT"
+if [ ! -d "$ANDROID_SYSROOT" ]; then
+ echo "ERROR: ANDROID_SYSROOT is not a valid path. Please set it."
+ echo "Path is $ANDROID_SYSROOT"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
-AOSP_CPU=$(tr '[:upper:]' '[:lower:]' <<< "$ANDROID_CPU")
+THE_ARCH=$(tr '[:upper:]' '[:lower:]' <<< "$ANDROID_CPU")
# https://developer.android.com/ndk/guides/abis.html
-case "$AOSP_CPU" in
- armeabi|armv7a|armv7-a|armeabi-v7a)
+case "$THE_ARCH" in
+ armv7*|armeabi*)
CC="armv7a-linux-androideabi$ANDROID_API-clang"
CXX="armv7a-linux-androideabi$ANDROID_API-clang++"
LD="arm-linux-androideabi-ld"
CXXFLAGS="-march=armv7-a -mthumb -mfloat-abi=softfp -funwind-tables -fexceptions -frtti"
;;
- armv8|armv8a|aarch64|arm64|arm64-v8a)
+ armv8*|aarch64|arm64)
CC="aarch64-linux-android$ANDROID_API-clang"
CXX="aarch64-linux-android$ANDROID_API-clang++"
LD="aarch64-linux-android-ld"
echo "ERROR: Unknown architecture $ANDROID_CPU"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
;;
-
esac
#####################################################################
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$CC" ]; then
echo "ERROR: Failed to find Android clang. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$CXX" ]; then
echo "ERROR: Failed to find Android clang++. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$RANLIB" ]; then
echo "ERROR: Failed to find Android ranlib. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$AR" ]; then
echo "ERROR: Failed to find Android ar. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$AS" ]; then
echo "ERROR: Failed to find Android as. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
-if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then
+if [ ! -e "$ANDROID_TOOLCHAIN/$LD" ]; then
echo "ERROR: Failed to find Android ld. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
-LENGTH=${#AOSP_TOOLCHAIN_PATH}
+LENGTH=${#ANDROID_TOOLCHAIN}
SUBSTR=${PATH:0:$LENGTH}
-if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then
- export PATH="$AOSP_TOOLCHAIN_PATH:$PATH"
+if [ "$SUBSTR" != "$ANDROID_TOOLCHAIN" ]; then
+ export PATH="$ANDROID_TOOLCHAIN:$PATH"
fi
#####################################################################
export ANDROID_SYSROOT="$AOSP_SYSROOT"
export CPPFLAGS="-D__ANDROID_API__=$ANDROID_API"
export CFLAGS="$CFLAGS --sysroot=$AOSP_SYSROOT"
-export CXXFLAGS="$CXXFLAGS --sysroot=$AOSP_SYSROOT"
+export CXXFLAGS="$CXXFLAGS -stdlib=libc++ --sysroot=$AOSP_SYSROOT"
#####################################################################
-echo "AOSP_TOOLCHAIN_PATH: $AOSP_TOOLCHAIN_PATH"
+echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"
+echo "CPP: $(command -v "$CPP")"
echo "CC: $(command -v "$CC")"
echo "CXX: $(command -v "$CXX")"
echo "LD: $(command -v "$LD")"
--- /dev/null
+#### iPhoneOS/iOS
+#
+# It takes recent enough Xcode to use following two targets. It shouldn't
+# be a problem by now, but if they don't work, original targets below
+# that depend on manual definition of environment variables should still
+# work...
+#
+my %targets = (
+ "ios-common" => {
+ template => 1,
+ inherit_from => [ "darwin-common" ],
+ sys_id => "iOS",
+ disable => [ "engine", "async" ],
+ },
+ "ios-xcrun" => {
+ inherit_from => [ "ios-common", asm("armv4_asm") ],
+ bn_ops => [ "BN_LLONG", "RC4_CHAR" ],
+ perlasm_scheme => "ios32",
+ },
+ "ios64-xcrun" => {
+ inherit_from => [ "ios-common", asm("aarch64_asm") ],
+ bn_ops => [ "SIXTY_FOUR_BIT_LONG", "RC4_CHAR" ],
+ perlasm_scheme => "ios64",
+ },
+ "iossimulator-xcrun" => {
+ inherit_from => [ "ios-common" ],
+ },
+
+ "iphoneos-cross" => {
+ inherit_from => [ "ios-common" ],
+ cflags => add("-Wall -fno-common"),
+ },
+ "ios-cross" => {
+ inherit_from => [ "ios-xcrun" ],
+ cflags => add("-Wall -fno-common"),
+ },
+ "ios64-cross" => {
+ inherit_from => [ "ios64-xcrun" ],
+ cflags => add("-Wall -fno-common"),
+ },
+);
--- /dev/null
+#!/usr/bin/env bash
+
+if ! git submodule update --init; then
+ echo "Failed to init submodule"
+ exit 1
+fi
+
+echo "AUTOTOOLS_BUILD: $AUTOTOOLS_BUILD"
+echo "AUTOTOOLS_HOST: $AUTOTOOLS_HOST"
+
+# libtool complains about our updated config.guess and config.sub.
+# Remove them to get through bootstrap. Re-add them after libtoolize.
+
+echo "Running libtoolize"
+if [ -n "$(command -v glibtoolize)" ]; then
+ rm -f config.guess config.sub
+ if ! glibtoolize -ci ; then
+ echo "Failed to libtoolize (glibtoolize)"
+ exit 1
+ fi
+elif [ -n "$(command -v libtoolize)" ]; then
+ rm -f config.guess config.sub
+ if ! libtoolize -ci ; then
+ echo "Failed to libtoolize (libtoolize)"
+ exit 1
+ fi
+else
+ echo "Failed to find a libtool"
+ exit 1
+fi
+
+echo "Updating config.guess"
+if ! wget -q -O config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'; then
+ echo "Failed to download config.guess"
+fi
+
+echo "Updating config.sub"
+if ! wget -q -O config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'; then
+ echo "Failed to download config.sub"
+fi
+
+echo "Fixing config permissions"
+chmod a+x config.guess config.sub
+if [ -n "$(command -v xattr 2>/dev/null)" ]; then
+ xattr -d com.apple.quarantine config.guess 2>/dev/null
+ xattr -d com.apple.quarantine config.sub 2>/dev/null
+fi
+
+echo "Running autoreconf"
+if ! autoreconf -fi ; then
+ echo "Failed to autoreconf"
+ exit 1
+fi
+
+exit 0
--- /dev/null
+#!/usr/bin/env bash
+
+echo "Downloading OpenSSL"
+if ! curl -L -k -s -o openssl-1.1.1d.tar.gz https://www.openssl.org/source/openssl-1.1.1d.tar.gz;
+then
+ echo "Failed to download OpenSSL"
+ exit 1
+fi
+
+echo "Unpacking OpenSSL"
+rm -rf ./openssl-1.1.1d
+if ! tar -xf openssl-1.1.1d.tar.gz;
+then
+ echo "Failed to unpack OpenSSL"
+ exit 1
+fi
+
+cd openssl-1.1.1d || exit 1
+
+if ! cp ../contrib/ios/15-ios.conf Configurations/; then
+ echo "Failed to copy OpenSSL ios config"
+ exit 1
+fi
+
+# ocsp.c:947:23: error: 'fork' is unavailable: not available on tvOS
+# ocsp.c:978:23: error: 'fork' is unavailable: not available on watchOS
+# Also see https://github.com/openssl/openssl/issues/7607.
+if ! patch -u -p0 < ../contrib/ios/openssl.patch; then
+ echo "Failed to patch OpenSSL"
+ exit 1
+fi
+
+echo "Configuring OpenSSL"
+if ! ./Configure "$OPENSSL_HOST" -DNO_FORK no-comp no-asm no-hw no-engine no-tests no-unit-test \
+ --prefix="$IOS_PREFIX" --openssldir="$IOS_PREFIX"; then
+ echo "Failed to configure OpenSSL"
+ exit 1
+fi
+
+echo "Building OpenSSL"
+if ! make; then
+ echo "Failed to build OpenSSL"
+ exit 1
+fi
+
+echo "Installing OpenSSL"
+if ! make install_sw; then
+ echo "Failed to install OpenSSL"
+ exit 1
+fi
+
+exit 0
--- /dev/null
+#!/usr/bin/env bash
+
+# This step should install tools needed for all packages - OpenSSL and LDNS
+echo "Updating tools"
+brew update 1>/dev/null
+echo "Installing tools"
+brew install autoconf automake libtool pkg-config curl perl 1>/dev/null
--- /dev/null
+--- apps/speed.c
++++ apps/speed.c
+@@ -99,6 +99,13 @@
+ #endif
+ #include <openssl/modes.h>
+
++/* fork() breaks AppleTVOS, WatchOS, AppleTVSimulator and WatchSimulator */
++/* Users should configure with -DNO_FORK */
++#if defined(NO_FORK)
++# undef HAVE_FORK
++# define HAVE_FORK 0
++#endif
++
+ #ifndef HAVE_FORK
+ # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
+ # define HAVE_FORK 0
+@@ -110,6 +117,7 @@
+ #if HAVE_FORK
+ # undef NO_FORK
+ #else
++# undef NO_FORK
+ # define NO_FORK
+ #endif
+
+--- apps/ocsp.c
++++ apps/ocsp.c
+@@ -36,6 +36,13 @@
+ # include <openssl/x509v3.h>
+ # include <openssl/rand.h>
+
++/* fork() breaks AppleTVOS, WatchOS, AppleTVSimulator and WatchSimulator */
++/* Users should configure with -DNO_FORK */
++#if defined(NO_FORK)
++# undef HAVE_FORK
++# define HAVE_FORK 0
++#endif
++
+ #ifndef HAVE_FORK
+ # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
+ # define HAVE_FORK 0
+@@ -47,6 +54,7 @@
+ #if HAVE_FORK
+ # undef NO_FORK
+ #else
++# undef NO_FORK
+ # define NO_FORK
+ #endif
+
--- /dev/null
+#!/usr/bin/env bash
+
+# ====================================================================
+# Sets the cross compile environment for Xcode/iOS
+#
+# Based upon OpenSSL's setenv-ios.sh by TH, JW, and SM.
+# Heavily modified by JWW for Crypto++.
+# Modified by JWW for LDNS.
+# ====================================================================
+
+#########################################
+##### Some validation #####
+#########################################
+
+# In the past we could mostly infer arch or cpu from the SDK (and
+# mostly vice-versa). Nowadays we need it set for us because Apple
+# platforms can be either 32-bit or 64-bit.
+
+if [ -z "$IOS_SDK" ]; then
+ echo "IOS_SDK is not set. Please set it"
+ [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
+fi
+
+if [ -z "$IOS_CPU" ]; then
+ echo "IOS_CPU is not set. Please set it"
+ [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
+fi
+
+# cryptest-ios.sh may run this script without sourcing.
+if [ "$0" = "${BASH_SOURCE[0]}" ]; then
+ echo "setenv-ios.sh is usually sourced, but not this time."
+fi
+
+#########################################
+##### Small Fixups, if needed #####
+#########################################
+
+if [[ "$IOS_SDK" == "iPhone" ]]; then
+ IOS_SDK=iPhoneOS
+fi
+
+if [[ "$IOS_SDK" == "iPhoneOSSimulator" ]]; then
+ IOS_SDK=iPhoneSimulator
+fi
+
+if [[ "$IOS_SDK" == "TV" || "$IOS_SDK" == "AppleTV" ]]; then
+ IOS_SDK=AppleTVOS
+fi
+
+if [[ "$IOS_SDK" == "Watch" || "$IOS_SDK" == "AppleWatch" ]]; then
+ IOS_SDK=WatchOS
+fi
+
+if [[ "$IOS_CPU" == "aarch64" || "$IOS_CPU" == "armv8"* ]] ; then
+ IOS_CPU=arm64
+fi
+
+########################################
+##### Environment #####
+########################################
+
+# The flags below were tested with Xcode 8 on Travis. If
+# you use downlevel versions of Xcode, then you can push
+# xxx-version-min=n lower. For example, Xcode 6 can use
+# -miphoneos-version-min=5.
+
+# iPhones can be either 32-bit or 64-bit
+if [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "armv7"* ]]; then
+ MIN_VER=-miphoneos-version-min=6
+elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "arm64" ]]; then
+ MIN_VER=-miphoneos-version-min=6
+
+# Fixups for convenience
+elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "i386" ]]; then
+ IOS_SDK=iPhoneSimulator
+ # MIN_VER=-miphoneos-version-min=6
+ MIN_VER=-miphonesimulator-version-min=6
+elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "x86_64" ]]; then
+ IOS_SDK=iPhoneSimulator
+ # MIN_VER=-miphoneos-version-min=6
+ MIN_VER=-miphonesimulator-version-min=6
+
+# Simulator builds
+elif [[ "$IOS_SDK" == "iPhoneSimulator" && "$IOS_CPU" == "i386" ]]; then
+ MIN_VER=-miphonesimulator-version-min=6
+elif [[ "$IOS_SDK" == "iPhoneSimulator" && "$IOS_CPU" == "x86_64" ]]; then
+ MIN_VER=-miphonesimulator-version-min=6
+
+# Apple TV can be 32-bit Intel (1st gen), 32-bit ARM (2nd, 3rd gen) or 64-bit ARM (4th gen)
+elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "i386" ]]; then
+ MIN_VER=-mappletvos-version-min=6
+elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "armv7"* ]]; then
+ MIN_VER=-mappletvos-version-min=6
+elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "arm64" ]]; then
+ MIN_VER=-mappletvos-version-min=6
+
+# Simulator builds
+elif [[ "$IOS_SDK" == "AppleTVSimulator" && "$IOS_CPU" == "i386" ]]; then
+ MIN_VER=-mappletvsimulator-version-min=6
+elif [[ "$IOS_SDK" == "AppleTVSimulator" && "$IOS_CPU" == "x86_64" ]]; then
+ MIN_VER=-mappletvsimulator-version-min=6
+
+# Watch can be either 32-bit or 64-bit ARM. TODO: figure out which
+# -mwatchos-version-min=n is needed for arm64. 9 is not enough.
+elif [[ "$IOS_SDK" == "WatchOS" && "$IOS_CPU" == "armv7"* ]]; then
+ MIN_VER=-mwatchos-version-min=6
+elif [[ "$IOS_SDK" == "WatchOS" && "$IOS_CPU" == "arm64" ]]; then
+ MIN_VER=-mwatchos-version-min=10
+
+# Simulator builds. TODO: figure out which -watchos-version-min=n
+# is needed for arm64. 6 compiles and links, but is it correct?
+elif [[ "$IOS_SDK" == "WatchSimulator" && "$IOS_CPU" == "i386" ]]; then
+ MIN_VER=-mwatchsimulator-version-min=6
+elif [[ "$IOS_SDK" == "WatchSimulator" && "$IOS_CPU" == "x86_64" ]]; then
+ MIN_VER=-mwatchsimulator-version-min=6
+
+# And the final catch-all
+else
+ echo "IOS_SDK and IOS_CPU are not valid. Please fix them"
+ [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
+fi
+
+#####################################################################
+
+# Xcode 6 and below cannot handle -miphonesimulator-version-min
+# Fix it so the simulator will compile as expected. This trick
+# may work on other SDKs, but it was not tested.
+
+if [ -n "$(command -v xcodebuild 2>/dev/null)" ]; then
+ # Output of xcodebuild is similar to "Xcode 6.2". The first cut gets
+ # the dotted decimal value. The second cut gets the major version.
+ XCODE_VERSION=$(xcodebuild -version 2>/dev/null | head -n 1 | cut -f2 -d" " | cut -f1 -d".")
+ if [ -z "$XCODE_VERSION" ]; then XCODE_VERSION=100; fi
+
+ if [ "$XCODE_VERSION" -le 6 ]; then
+ MIN_VER="${MIN_VER//iphonesimulator/iphoneos}"
+ fi
+fi
+
+#####################################################################
+
+# Allow a user override? I think we should be doing this. The use case is,
+# move /Applications/Xcode somewhere else for a side-by-side installation.
+if [ -z "${XCODE_DEVELOPER-}" ]; then
+ XCODE_DEVELOPER=$(xcode-select -print-path 2>/dev/null)
+fi
+
+if [ ! -d "$XCODE_DEVELOPER" ]; then
+ echo "ERROR: unable to find XCODE_DEVELOPER directory."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# XCODE_DEVELOPER_SDK is the SDK location.
+XCODE_DEVELOPER_SDK="$XCODE_DEVELOPER/Platforms/$IOS_SDK.platform"
+
+if [ ! -d "$XCODE_DEVELOPER_SDK" ]; then
+ echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
+ echo " Is the SDK supported by Xcode and installed?"
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# XCODE_TOOLCHAIN is the location of the actual compiler tools.
+if [ -d "$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then
+ XCODE_TOOLCHAIN="$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
+elif [ -d "$XCODE_DEVELOPER_SDK/Developer/usr/bin/" ]; then
+ XCODE_TOOLCHAIN="$XCODE_DEVELOPER_SDK/Developer/usr/bin/"
+fi
+
+if [ -z "$XCODE_TOOLCHAIN" ] || [ ! -d "$XCODE_TOOLCHAIN" ]; then
+ echo "ERROR: unable to find Xcode cross-compiler tools."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# XCODE_SDK is the SDK name/version being used - adjust the list as appropriate.
+# For example, remove 4.3, 6.2, and 6.1 if they are not installed. We go back to
+# the 1.0 SDKs because Apple WatchOS uses low numbers, like 2.0 and 2.1.
+XCODE_SDK=
+for i in $(seq -f "%.1f" 30.0 -0.1 1.0)
+do
+ if [ -d "$XCODE_DEVELOPER_SDK/Developer/SDKs/$IOS_SDK$i.sdk" ]; then
+ XCODE_SDK="$IOS_SDK$i.sdk"
+ break
+ fi
+done
+
+# Error checking
+if [ -z "$XCODE_SDK" ]; then
+ echo "ERROR: unable to find a SDK."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+IOS_SYSROOT="$XCODE_DEVELOPER_SDK/Developer/SDKs/$XCODE_SDK"
+
+if [ -z "$IOS_SYSROOT" ] || [ ! -d "$IOS_SYSROOT" ]; then
+ echo "ERROR: unable to find IOS_SYSROOT directory."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+#####################################################################
+
+# We want to set AR=libtool and ARFLAGS="-static -o",
+# but I am not sure Autotools can handle it.
+CPP=cpp; CC=clang; CXX=clang++; LD=ld
+AS=as; AR=ar; RANLIB=ranlib; STRIP=strip
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$CC" ]; then
+ echo "ERROR: Failed to find iOS clang. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$CXX" ]; then
+ echo "ERROR: Failed to find iOS clang++. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$RANLIB" ]; then
+ echo "ERROR: Failed to find iOS ranlib. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$AR" ]; then
+ echo "ERROR: Failed to find iOS ar. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$AS" ]; then
+ echo "ERROR: Failed to find iOS as. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+# Error checking
+if [ ! -e "$XCODE_TOOLCHAIN/$LD" ]; then
+ echo "ERROR: Failed to find iOS ld. Please edit this script."
+ [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
+fi
+
+#####################################################################
+
+LENGTH=${#XCODE_TOOLCHAIN}
+SUBSTR=${PATH:0:$LENGTH}
+if [ "$SUBSTR" != "$XCODE_TOOLCHAIN" ]; then
+ export PATH="$XCODE_TOOLCHAIN":"$PATH"
+fi
+
+#####################################################################
+
+export CPP CC CXX LD AS AR RANLIB STRIP
+export IOS_SYSROOT
+export CFLAGS="-arch $IOS_CPU $MIN_VER --sysroot=$IOS_SYSROOT"
+export CXXFLAGS="-arch $IOS_CPU $MIN_VER -stdlib-libc++ --sysroot=$IOS_SYSROOT"
+
+#####################################################################
+
+echo "XCODE_TOOLCHAIN: $XCODE_TOOLCHAIN"
+
+echo "CPP: $(command -v "$CPP")"
+echo "CC: $(command -v "$CC")"
+echo "CXX: $(command -v "$CXX")"
+echo "LD: $(command -v "$LD")"
+echo "AS: $(command -v "$AS")"
+echo "AR: $(command -v "$AR")"
+
+echo "IOS_SYSROOT: $IOS_SYSROOT"
+
+echo "CPPFLAGS: $CPPFLAGS"
+echo "CFLAGS: $CFLAGS"
+echo "CXXFLAGS: $CXXFLAGS"
+
+[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0
#include <errno.h>
#include <signal.h>
+#ifdef HAVE_TARGETCONDITIONALS_H
+#include <TargetConditionals.h>
+#endif
+
+#if defined(TARGET_OS_TV) || defined(TARGET_OS_WATCH)
+#undef HAVE_FORK
+#endif
+
#define INBUF_SIZE 4096 /* max size for incoming queries */
#define DEFAULT_PORT 53 /* default if no -p port is specified */
#define CONN_BACKLOG 256 /* connections queued up for tcp */