From ba088bf2250e766ecf55d7bfd3a3de035c6de115 Mon Sep 17 00:00:00 2001
From: Edric Milaret <edric.ladent-milaret@savoirfairelinux.com>
Date: Thu, 2 Jun 2016 13:49:48 -0400
Subject: [PATCH] contrib: allow ios build

Change-Id: Ib5deee2d0172f92febe72d4d3a57a7c3334414c4
Tuleap: #313
---
 contrib/bootstrap       |  5 +++--
 contrib/src/get-arch.sh |  8 ++++++++
 contrib/src/main.mak    | 20 +++++++++++++-------
 3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/contrib/bootstrap b/contrib/bootstrap
index cdfc54c0b5..f8a0de84d9 100755
--- a/contrib/bootstrap
+++ b/contrib/bootstrap
@@ -132,11 +132,11 @@ check_ios_sdk()
 {
    if test -z "$SDKROOT"
    then
-      SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
+      SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk
       echo "SDKROOT not specified, assuming $SDKROOT"
    else
       SDKROOT="$SDKROOT"
-      fi
+   fi
 
    if [ ! -d "${SDKROOT}" ]
    then
@@ -144,6 +144,7 @@ check_ios_sdk()
       exit 1
    fi
    add_make "IOS_SDK=${SDKROOT}"
+   add_make "IOS_TARGET_PLATFORM=${IOS_TARGET_PLATFORM}"
 }
 
 check_macosx_sdk()
diff --git a/contrib/src/get-arch.sh b/contrib/src/get-arch.sh
index 2df77de83c..b1ad429d71 100755
--- a/contrib/src/get-arch.sh
+++ b/contrib/src/get-arch.sh
@@ -19,6 +19,14 @@ case "$HOST" in
 	powerpc64-*|ppc64-*)
 		ARCH="ppc64"
 		;;
+	aarch64-*)
+	if $HAVE_IOS
+	then
+		ARCH="arm64"
+	else
+		ARCH="aarch64"
+	fi
+		;;
 	*-*)
 		ARCH="${HOST%%-*}"
 		;;
diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index 505d23c8f4..2bd3929c8a 100644
--- a/contrib/src/main.mak
+++ b/contrib/src/main.mak
@@ -151,20 +151,26 @@ endif
 CCAS=$(CC) -c
 
 ifdef HAVE_IOS
+MIN_IOS_VERSION=8.0
+
 CC=xcrun clang
 CXX=xcrun clang++
-ifdef HAVE_NEON
-AS=perl $(abspath ../../extras/tools/build/bin/gas-preprocessor.pl) $(CC)
-CCAS=gas-preprocessor.pl $(CC) -c
-else
 CCAS=$(CC) -c
-endif
 AR=xcrun ar
 LD=xcrun ld
 STRIP=xcrun strip
 RANLIB=xcrun ranlib
-EXTRA_CFLAGS += $(CFLAGS)
-EXTRA_LDFLAGS += $(LDFLAGS)
+
+EXTRA_CFLAGS=-arch $(ARCH) -isysroot $(IOS_SDK)
+ifeq ($(IOS_TARGET_PLATFORM),iPhoneOS)
+EXTRA_CFLAGS += -miphoneos-version-min=$(MIN_IOS_VERSION) -fembed-bitcode
+else
+EXTRA_CFLAGS += -mios-simulator-version-min=$(MIN_IOS_VERSION)
+endif
+
+EXTRA_CXXFLAGS=$(EXTRA_CFLAGS) -std=c++11 -stdlib=libc++
+EXTRA_LDFLAGS=$(EXTRA_CFLAGS)
+
 endif
 
 ifdef HAVE_WIN32
-- 
GitLab