diff mbox

[Darwin] Make the darwin port a little more friendly to X and Native X cases

Message ID 1B026D35-1C4C-42E2-B729-A1AFF1B2F0FA@sandoe-acoustics.co.uk
State New
Headers show

Commit Message

Iain Sandoe Sept. 7, 2011, 11:30 a.m. UTC
I found myself building a lot of X's and native X's recently - linux - 
 > darwin; i686-darwin -> ppc-darwin ; i686-darwin9 -> x86_64-darwin10.

Amongst other issues (primarily wrong auto-host.h decisions) there is  
an issue that the target headers (and some GCC code) make use of  
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ which does not get set  
(IMHO) sensibly for CROSS_DIRECTORY_STRUCTURE.

In fact, as things stand, darwin-driver.c pretty much ignores any  
attempt to control the value for that case.

---

So I did the following;
when CROSS_DIRECTORY_STRUCTURE is set - we pick a default for the osx- 
version-min that is set by the target header.
we also allow the user to override this with MACOSX_DEPLOYMENT_TARGET.

Attached is a tidied version (which is currently bootstrapping as a  
check) of the one I have been using.

WDYT?
ok for trunk (after a re-check)?

gcc:

	*config/darwin-driver.c (darwin_find_version_from_kernel): New  
routine cut from...
	... (darwin_default_min_version): amended to provide defaults for the  
cross
	directory case. (darwin_driver_init): call darwin_default_min_version  
unconditionally.
	* config/darwin.h (DEF_MIN_OSX_VERSION): New.
	* config/darwin9.h: Likewise.
	* config/darwin10.h: Likewise.
	* config/rs6000/darwin7.h: Likewise.

Comments

Mike Stump Sept. 7, 2011, 4:53 p.m. UTC | #1
On Sep 7, 2011, at 4:30 AM, Iain Sandoe wrote:
> I found myself building a lot of X's and native X's recently - linux -> darwin; i686-darwin -> ppc-darwin ; i686-darwin9 -> x86_64-darwin10.

> ok for trunk (after a re-check)?

Ok.  I like cross building...
diff mbox

Patch

Index: gcc/config/rs6000/darwin7.h
===================================================================
--- gcc/config/rs6000/darwin7.h	(revision 178631)
+++ gcc/config/rs6000/darwin7.h	(working copy)
@@ -28,3 +28,6 @@  along with GCC; see the file COPYING3.  If not see
 #define LIB_SPEC "%{!static:\
   %:version-compare(!< 10.3 mmacosx-version-min= -lmx)\
   -lSystem}"
+
+#undef DEF_MIN_OSX_VERSION
+#define DEF_MIN_OSX_VERSION "10.3.9"
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 178631)
+++ gcc/config/darwin.h	(working copy)
@@ -945,4 +945,8 @@  extern void darwin_driver_init (unsigned int *,str
 #undef SUPPORTS_INIT_PRIORITY
 #define SUPPORTS_INIT_PRIORITY 0
 
+/* When building cross-compilers (and native crosses) we shall default to 
+   providing an osx-version-min of this unless overridden by the User.  */
+#define DEF_MIN_OSX_VERSION "10.4"
+
 #endif /* CONFIG_DARWIN_H */
Index: gcc/config/darwin10.h
===================================================================
--- gcc/config/darwin10.h	(revision 178631)
+++ gcc/config/darwin10.h	(working copy)
@@ -27,3 +27,6 @@  along with GCC; see the file COPYING3.  If not see
 "%:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) \
    %{!static:%{!static-libgcc: \
       %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } %G %L"
+
+#undef DEF_MIN_OSX_VERSION
+#define DEF_MIN_OSX_VERSION "10.6"
Index: gcc/config/darwin-driver.c
===================================================================
--- gcc/config/darwin-driver.c	(revision 178631)
+++ gcc/config/darwin-driver.c	(working copy)
@@ -29,9 +29,74 @@  along with GCC; see the file COPYING3.  If not see
 #include <sys/sysctl.h>
 #include "xregex.h"
 
+static bool
+darwin_find_version_from_kernel (char *new_flag)
+{
+  char osversion[32];
+  size_t osversion_len = sizeof (osversion) - 1;
+  static int osversion_name[2] = { CTL_KERN, KERN_OSRELEASE };
+  int major_vers;
+  char minor_vers[6];
+  char * version_p;
+  char * version_pend;
+
+  /* Determine the version of the running OS.  If we can't, warn user,
+     and do nothing.  */
+  if (sysctl (osversion_name, ARRAY_SIZE (osversion_name), osversion,
+	      &osversion_len, NULL, 0) == -1)
+    {
+      warning (0, "sysctl for kern.osversion failed: %m");
+      return false;
+    }
+
+  /* Try to parse the first two parts of the OS version number.  Warn
+     user and return if it doesn't make sense.  */
+  if (! ISDIGIT (osversion[0]))
+    goto parse_failed;
+  major_vers = osversion[0] - '0';
+  version_p = osversion + 1;
+  if (ISDIGIT (*version_p))
+    major_vers = major_vers * 10 + (*version_p++ - '0');
+  if (major_vers > 4 + 9)
+    goto parse_failed;
+  if (*version_p++ != '.')
+    goto parse_failed;
+  version_pend = strchr(version_p, '.');
+  if (!version_pend)
+    goto parse_failed;
+  if (! ISDIGIT (*version_p))
+    goto parse_failed;
+  strncpy(minor_vers, version_p, version_pend - version_p);
+  minor_vers[version_pend - version_p] = '\0';
+  
+  /* The major kernel version number is 4 plus the second OS version
+     component.  */
+  if (major_vers - 4 <= 4)
+    /* On 10.4 and earlier, the old linker is used which does not
+       support three-component system versions.  */
+    sprintf (new_flag, "10.%d", major_vers - 4);
+  else
+    sprintf (new_flag, "10.%d.%s", major_vers - 4,
+	     minor_vers);
+
+  return true;
+
+ parse_failed:
+  warning (0, "couldn%'t understand kern.osversion %q.*s",
+	   (int) osversion_len, osversion);
+  return false;
+}
+
+#endif
+
 /* When running on a Darwin system and using that system's headers and
    libraries, default the -mmacosx-version-min flag to be the version
-   of the system on which the compiler is running.  */
+   of the system on which the compiler is running.  
+   
+   When building cross or native cross compilers, default to the OSX
+   version of the target (as provided by the most specific target header
+   included in tm.h).  This may be overidden by setting the flag explicitly
+   (or by the MACOSX_DEPLOYMENT_TARGET environment).  */
 
 static void
 darwin_default_min_version (unsigned int *decoded_options_count,
@@ -40,13 +105,6 @@  darwin_default_min_version (unsigned int *decoded_
   const unsigned int argc = *decoded_options_count;
   struct cl_decoded_option *const argv = *decoded_options;
   unsigned int i;
-  char osversion[32];
-  size_t osversion_len = sizeof (osversion) - 1;
-  static int osversion_name[2] = { CTL_KERN, KERN_OSRELEASE };
-  char * version_p;
-  char * version_pend;
-  int major_vers;
-  char minor_vers[6];
   static char new_flag[sizeof ("10.0.0") + 6];
 
   /* If the command-line is empty, just return.  */
@@ -82,45 +140,21 @@  darwin_default_min_version (unsigned int *decoded_
       }
   }
 
-  /* Determine the version of the running OS.  If we can't, warn user,
-     and do nothing.  */
-  if (sysctl (osversion_name, ARRAY_SIZE (osversion_name), osversion,
-	      &osversion_len, NULL, 0) == -1)
-    {
-      warning (0, "sysctl for kern.osversion failed: %m");
-      return;
-    }
+#ifndef CROSS_DIRECTORY_STRUCTURE
 
-  /* Try to parse the first two parts of the OS version number.  Warn
-     user and return if it doesn't make sense.  */
-  if (! ISDIGIT (osversion[0]))
-    goto parse_failed;
-  major_vers = osversion[0] - '0';
-  version_p = osversion + 1;
-  if (ISDIGIT (*version_p))
-    major_vers = major_vers * 10 + (*version_p++ - '0');
-  if (major_vers > 4 + 9)
-    goto parse_failed;
-  if (*version_p++ != '.')
-    goto parse_failed;
-  version_pend = strchr(version_p, '.');
-  if (!version_pend)
-    goto parse_failed;
-  if (! ISDIGIT (*version_p))
-    goto parse_failed;
-  strncpy(minor_vers, version_p, version_pend - version_p);
-  minor_vers[version_pend - version_p] = '\0';
-  
-  /* The major kernel version number is 4 plus the second OS version
-     component.  */
-  if (major_vers - 4 <= 4)
-    /* On 10.4 and earlier, the old linker is used which does not
-       support three-component system versions.  */
-    sprintf (new_flag, "10.%d", major_vers - 4);
-  else
-    sprintf (new_flag, "10.%d.%s", major_vers - 4,
-	     minor_vers);
+ /* Try to find the version from the kernel, if we fail - we print a message 
+    and give up.  */
+ if (!darwin_find_version_from_kernel (new_flag))
+   return;
 
+#else
+
+ /* For cross-compilers, default to the target OS version. */
+
+ strncpy (new_flag, DEF_MIN_OSX_VERSION, sizeof (new_flag));
+
+#endif /* CROSS_DIRECTORY_STRUCTURE */
+
   /* Add the new flag.  */
   ++*decoded_options_count;
   *decoded_options = XNEWVEC (struct cl_decoded_option,
@@ -132,14 +166,8 @@  darwin_default_min_version (unsigned int *decoded_
 	  (argc - 1) * sizeof (struct cl_decoded_option));
   return;
   
- parse_failed:
-  warning (0, "couldn%'t understand kern.osversion %q.*s",
-	   (int) osversion_len, osversion);
-  return;
 }
 
-#endif /* CROSS_DIRECTORY_STRUCTURE */
-
 /* Translate -filelist and -framework options in *DECODED_OPTIONS
    (size *DECODED_OPTIONS_COUNT) to use -Xlinker so that they are
    considered to be linker inputs in the case that no other inputs are
@@ -192,7 +220,5 @@  darwin_driver_init (unsigned int *decoded_options_
 	}
     }
 
-#ifndef CROSS_DIRECTORY_STRUCTURE
   darwin_default_min_version (decoded_options_count, decoded_options);
-#endif
 }
Index: gcc/config/darwin9.h
===================================================================
--- gcc/config/darwin9.h	(revision 178631)
+++ gcc/config/darwin9.h	(working copy)
@@ -51,3 +51,7 @@  along with GCC; see the file COPYING3.  If not see
     fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",		\
 	     _new_size, floor_log2 ((ALIGN) / BITS_PER_UNIT));		\
   } while (0)
+
+#undef DEF_MIN_OSX_VERSION
+#define DEF_MIN_OSX_VERSION "10.5"
+