From 6a63dbeb9d47bd60db28f9c0e839a83ec322fdfb Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Wed, 19 Oct 2016 14:36:32 +0200
Subject: [PATCH] configure: set min version flags for builds on mac

---
 acinclude.m4 | 40 +++++++++++++++++++++++++++++++++++++++-
 configure.ac |  2 ++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 312efcb..ed3270f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -3,11 +3,11 @@
 #  Project                     ___| | | |  _ \| |
 #                             / __| | | | |_) | |
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
 # are also available at https://curl.haxx.se/docs/copyright.html.
 #
@@ -3197,5 +3197,43 @@ TEST EINVAL TEST
   else
     # without -P
     CPPPFLAG=""
   fi
 ])
+
+
+dnl CURL_MAC_CFLAGS
+dnl
+dnl Check if -mmacosx-version-min or -miphoneos-version-min are set manually,
+dnl otherwise do. And set -Werror=partial-availability.
+dnl
+
+AC_DEFUN([CURL_MAC_CFLAGS], [
+
+  tst_cflags="no"
+  case $host_os in
+    darwin*)
+      tst_cflags="yes"
+      ;;
+  esac
+
+  AC_MSG_CHECKING([for good-to-use Mac CFLAGS])
+  AC_MSG_RESULT([$tst_cflags]);
+
+  if test "$tst_cflags" = "yes"; then
+    AC_MSG_CHECKING([for *version-min in CFLAGS])
+    min=""
+    if test -z "`echo $CFLAGS | grep mmacosx-version-min`"; then
+      if test -z "`echo $CFLAGS | grep miphoneos-version-min`"; then
+        min="-mmacosx-version-min=10.5"
+        CFLAGS="$CFLAGS $min"
+      fi
+    fi
+    if test -z "$min"; then
+      AC_MSG_RESULT([set by user])
+    else
+      AC_MSG_RESULT([$min set])
+    fi
+    CFLAGS="$CFLAGS -Werror=partial-availability"
+  fi
+
+])
diff --git a/configure.ac b/configure.ac
index 0626b38..83cfbff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -355,10 +355,12 @@ case X-"$curl_cv_native_windows" in
     curl_cv_header_winber_h="no"
     ;;
 esac
 CURL_CHECK_WIN32_LARGEFILE
 
+CURL_MAC_CFLAGS
+
 dnl ************************************************************
 dnl switch off particular protocols
 dnl
 AC_MSG_CHECKING([whether to support http])
 AC_ARG_ENABLE(http,
-- 
2.6.3

