Esempio n. 1
0
/* Define __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__.  */
static void
define__GNUC__ (void)
{
  /* The format of the version string, enforced below, is
     ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
  const char *q, *v = version_string;

  while (*v && ! ISDIGIT (*v))
    v++;
  if (!*v || (v > version_string && v[-1] != '-'))
    abort ();

  q = v;
  while (ISDIGIT (*v))
    v++;
  builtin_define_with_value_n ("__GNUC__", q, v - q);
  if (c_dialect_cxx ())
    builtin_define_with_value_n ("__GNUG__", q, v - q);

  if (*v != '.' || !ISDIGIT (v[1]))
    abort ();
  q = ++v;
  while (ISDIGIT (*v))
    v++;
  builtin_define_with_value_n ("__GNUC_MINOR__", q, v - q);

  if (*v == '.')
    {
      if (!ISDIGIT (v[1]))
	abort ();
      q = ++v;
      while (ISDIGIT (*v))
	v++;
      builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", q, v - q);
    }
  else
    builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1);

  if (*v && *v != ' ' && *v != '-')
    abort ();
}
Esempio n. 2
0
/* Define __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__.  */
static void
define__GNUC__ (void)
{
  /* The format of the version string, enforced below, is
     ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
  const char *q, *v = version_string;

  while (*v && !ISDIGIT (*v))
    v++;
  gcc_assert (*v && (v <= version_string || v[-1] == '-'));

  q = v;
  while (ISDIGIT (*v))
    v++;
  builtin_define_with_value_n ("__GNUC__", q, v - q);
  if (c_dialect_cxx ())
    builtin_define_with_value_n ("__GNUG__", q, v - q);

  gcc_assert (*v == '.' && ISDIGIT (v[1]));

  q = ++v;
  while (ISDIGIT (*v))
    v++;
  builtin_define_with_value_n ("__GNUC_MINOR__", q, v - q);

  if (*v == '.')
    {
      gcc_assert (ISDIGIT (v[1]));
      q = ++v;
      while (ISDIGIT (*v))
	v++;
      builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", q, v - q);
    }
  else
    builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1);

  gcc_assert (!*v || *v == ' ' || *v == '-');

  /* LLVM LOCAL no version number */
#ifdef CONFIG_DARWIN_H
#ifndef LLVM_VERSION_INFO

  /* APPLE LOCAL begin Apple version */
  {
    /* This chunk of code defines __APPLE_CC__ from the version
       string.  It expects to see a substring of the version string of
       the form "build NNNN)", where each N is a digit, and the first
       N is nonzero (there can be 4 or 5 digits).  It will abort() if
       these conditions are not met, since that usually means that
       someone's broken the version string.  */
    const char *vt;
    
    vt = strstr (version_string, "build ");
    if (vt == NULL)
      abort ();
    vt += strlen ("build ");
    if (! ISDIGIT (*vt))
      abort ();
    for (q = vt; *q != 0 && ISDIGIT (*q); q++)
      ;
    if (q == vt || *q != ')')
      abort ();
    if ((q - vt != 4 && q - vt != 5) || *vt == '0')
      abort ();
    builtin_define_with_value_n ("__APPLE_CC__", vt, q - vt);
  }
  /* APPLE LOCAL end Apple version */

  /* LLVM LOCAL begin version number */
#else
  /* This chunk of code defines __APPLE_CC__ from the version
     string.  It expects to see a substring of the version string of
     the form "build NNNN)", where each N is a digit, and the first
     N is nonzero (there can be 4 or 5 digits).  It will abort() if
     these conditions are not met, since that usually means that
     someone's broken the version string.  */

  /* LLVM builds multiple different ways.  For example, for official releases,
     the version number is something like "1.8".  We don't want to disable
     __APPLE_CC__ entirely, as this breaks system headers.  If the build number
     is not a 4-digit code, just define __APPLE_CC__ to 1 instead of abort()ing
     as per above comment.
   */
  {
    const char *vt;

    vt = strstr (version_string, "build ");
    if (vt == NULL) {
      builtin_define_with_value_n ("__APPLE_CC__", "1", 1);
      return;
    }

    vt += strlen ("build ");
    if (! ISDIGIT (*vt)) {
      builtin_define_with_value_n ("__APPLE_CC__", "1", 1);
      return;
    }
    for (q = vt; *q != 0 && ISDIGIT (*q); q++)
      ;
    if (q == vt || *q != ')') {
      builtin_define_with_value_n ("__APPLE_CC__", "1", 1);
      return;
    }

    if ((q - vt != 4 && q - vt != 5) || *vt == '0')
      builtin_define_with_value_n ("__APPLE_CC__", "1", 1);
    else
      builtin_define_with_value_n ("__APPLE_CC__", vt, q - vt);
  }
#endif /*LLVM_VERSION_INFO*/
#endif /*CONFIG_DARWIN_H*/
  /* LLVM LOCAL end version number */
}