OSDN Git Service

Replace | with || in TARGET_HAS_SINCOS.
[pf3gnuchains/gcc-fork.git] / gcc / config / darwin-driver.c
1 /* Additional functions for the GCC driver on Darwin native.
2    Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #ifndef CROSS_DIRECTORY_STRUCTURE
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "gcc.h"
27 #include <sys/sysctl.h>
28 #include "xregex.h"
29
30 /* When running on a Darwin system and using that system's headers and
31    libraries, default the -mmacosx-version-min flag to be the version
32    of the system on which the compiler is running.  */
33
34 void
35 darwin_default_min_version (int * argc_p, char *** argv_p)
36 {
37   const int argc = *argc_p;
38   char ** const argv = *argv_p;
39   int i;
40   char osversion[32];
41   size_t osversion_len = sizeof (osversion) - 1;
42   static int osversion_name[2] = { CTL_KERN, KERN_OSRELEASE };
43   char * version_p;
44   char * version_pend;
45   int major_vers;
46   char minor_vers[6];
47   static char new_flag[sizeof ("-mmacosx-version-min=10.0.0") + 6];
48
49   /* If the command-line is empty, just return.  */
50   if (argc <= 1)
51     return;
52   /* Don't do this if the user has specified -b or -V at the start
53      of the command-line.  */
54   if (argv[1][0] == '-'
55       && (argv[1][1] == 'V' ||
56           ((argv[1][1] == 'b') && (NULL != strchr(argv[1] + 2,'-')))))
57     return;
58   
59   /* Don't do this if the user specified -mmacosx-version-min= or
60      -mno-macosx-version-min.  */
61   for (i = 1; i < argc; i++)
62     if (argv[i][0] == '-')
63       {
64         const char * const p = argv[i];
65         if (strncmp (p, "-mno-macosx-version-min", 23) == 0
66             || strncmp (p, "-mmacosx-version-min", 20) == 0)
67           return;
68         
69         /* It doesn't count if it's an argument to a different switch.  */
70         if (p[0] == '-'
71             && ((SWITCH_TAKES_ARG (p[1]) > (p[2] != 0))
72                 || WORD_SWITCH_TAKES_ARG (p + 1)))
73           i++;
74       }
75
76   /* Retrieve the deployment target from the environment and insert
77      it as a flag.  */
78   {
79     const char * macosx_deployment_target;
80     macosx_deployment_target = getenv ("MACOSX_DEPLOYMENT_TARGET");
81     if (macosx_deployment_target
82         /* Apparently, an empty string for MACOSX_DEPLOYMENT_TARGET means
83            "use the default".  Or, possibly "use 10.1".  We choose
84            to ignore the environment variable, as if it was never set.  */
85         && macosx_deployment_target[0])
86       {
87         ++*argc_p;
88         *argv_p = XNEWVEC (char *, *argc_p);
89         (*argv_p)[0] = argv[0];
90         (*argv_p)[1] = concat ("-mmacosx-version-min=",
91                                macosx_deployment_target, NULL);
92         memcpy (*argv_p + 2, argv + 1, (argc - 1) * sizeof (char *));
93         return;
94       }
95   }
96
97   /* Determine the version of the running OS.  If we can't, warn user,
98      and do nothing.  */
99   if (sysctl (osversion_name, ARRAY_SIZE (osversion_name), osversion,
100               &osversion_len, NULL, 0) == -1)
101     {
102       warning (0, "sysctl for kern.osversion failed: %m");
103       return;
104     }
105
106   /* Try to parse the first two parts of the OS version number.  Warn
107      user and return if it doesn't make sense.  */
108   if (! ISDIGIT (osversion[0]))
109     goto parse_failed;
110   major_vers = osversion[0] - '0';
111   version_p = osversion + 1;
112   if (ISDIGIT (*version_p))
113     major_vers = major_vers * 10 + (*version_p++ - '0');
114   if (major_vers > 4 + 9)
115     goto parse_failed;
116   if (*version_p++ != '.')
117     goto parse_failed;
118   version_pend = strchr(version_p, '.');
119   if (!version_pend)
120     goto parse_failed;
121   if (! ISDIGIT (*version_p))
122     goto parse_failed;
123   strncpy(minor_vers, version_p, version_pend - version_p);
124   minor_vers[version_pend - version_p] = '\0';
125   
126   /* The major kernel version number is 4 plus the second OS version
127      component.  */
128   if (major_vers - 4 <= 4)
129     /* On 10.4 and earlier, the old linker is used which does not
130        support three-component system versions.  */
131     sprintf (new_flag, "-mmacosx-version-min=10.%d", major_vers - 4);
132   else
133     sprintf (new_flag, "-mmacosx-version-min=10.%d.%s", major_vers - 4,
134              minor_vers);
135
136   /* Add the new flag.  */
137   ++*argc_p;
138   *argv_p = XNEWVEC (char *, *argc_p);
139   (*argv_p)[0] = argv[0];
140   (*argv_p)[1] = new_flag;
141   memcpy (*argv_p + 2, argv + 1, (argc - 1) * sizeof (char *));
142   return;
143   
144  parse_failed:
145   warning (0, "couldn't understand kern.osversion %q.*s",
146            (int) osversion_len, osversion);
147   return;
148 }
149
150 #endif /* CROSS_DIRECTORY_STRUCTURE */