* support/cpp/output.h, support/cpp/opts-common.c,
[fw/sdcc] / support / cpp / libcpp / mkdeps.c
index d4c838e7d4abde3228943cf649d2286164897b13..05bd8072f53f3ead861b3cd9f07066f6500e2a44 100644 (file)
@@ -1,10 +1,11 @@
 /* Dependency generator for Makefile fragments.
-   Copyright (C) 2000, 2001, 2003, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2003, 2007, 2008, 2009
+   Free Software Foundation, Inc.
    Contributed by Zack Weinberg, Mar 2000
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
+Free Software Foundation; either version 3, or (at your option) any
 later version.
 
 This program is distributed in the hope that it will be useful,
@@ -13,8 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+along with this program; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.
 
  In other words, you are welcome to use, share and improve this program.
  You are forbidden to forbid anyone else to use, share and improve
@@ -30,8 +31,8 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 struct deps
 {
   const char **targetv;
-  unsigned int ntargets;       /* number of slots actually occupied */
-  unsigned int targets_size;   /* amt of allocated space - in words */
+  unsigned int ntargets;        /* number of slots actually occupied */
+  unsigned int targets_size;    /* amt of allocated space - in words */
 
   const char **depv;
   unsigned int ndeps;
@@ -62,25 +63,30 @@ munge (const char *filename)
   for (p = filename, len = 0; *p; p++, len++)
     {
       switch (*p)
-       {
-       case ' ':
-       case '\t':
-         /* GNU make uses a weird quoting scheme for white space.
-            A space or tab preceded by 2N+1 backslashes represents
-            N backslashes followed by space; a space or tab
-            preceded by 2N backslashes represents N backslashes at
-            the end of a file name; and backslashes in other
-            contexts should not be doubled.  */
-         for (q = p - 1; filename <= q && *q == '\\';  q--)
-           len++;
-         len++;
-         break;
-
-       case '$':
-         /* '$' is quoted by doubling it.  */
-         len++;
-         break;
-       }
+        {
+        case ' ':
+        case '\t':
+          /* GNU make uses a weird quoting scheme for white space.
+             A space or tab preceded by 2N+1 backslashes represents
+             N backslashes followed by space; a space or tab
+             preceded by 2N backslashes represents N backslashes at
+             the end of a file name; and backslashes in other
+             contexts should not be doubled.  */
+          for (q = p - 1; filename <= q && *q == '\\';  q--)
+            len++;
+          len++;
+          break;
+
+        case '$':
+          /* '$' is quoted by doubling it.  */
+          len++;
+          break;
+
+        case '#':
+          /* '#' is quoted with a backslash.  */
+          len++;
+          break;
+        }
     }
 
   /* Now we know how big to make the buffer.  */
@@ -89,21 +95,25 @@ munge (const char *filename)
   for (p = filename, dst = buffer; *p; p++, dst++)
     {
       switch (*p)
-       {
-       case ' ':
-       case '\t':
-         for (q = p - 1; filename <= q && *q == '\\';  q--)
-           *dst++ = '\\';
-         *dst++ = '\\';
-         break;
-
-       case '$':
-         *dst++ = '$';
-         break;
-
-       default:
-         /* nothing */;
-       }
+        {
+        case ' ':
+        case '\t':
+          for (q = p - 1; filename <= q && *q == '\\';  q--)
+            *dst++ = '\\';
+          *dst++ = '\\';
+          break;
+
+        case '$':
+          *dst++ = '$';
+          break;
+
+        case '#':
+          *dst++ = '\\';
+          break;
+
+        default:
+          /* nothing */;
+        }
       *dst = *p;
     }
 
@@ -120,24 +130,24 @@ apply_vpath (struct deps *d, const char *t)
     {
       unsigned int i;
       for (i = 0; i < d->nvpaths; i++)
-       {
-         if (!strncmp (d->vpathv[i], t, d->vpathlv[i]))
-           {
-             const char *p = t + d->vpathlv[i];
-             if (!IS_DIR_SEPARATOR (*p))
-               goto not_this_one;
-
-             /* Do not simplify $(vpath)/../whatever.  ??? Might not
-                be necessary. */
-             if (p[1] == '.' && p[2] == '.' && IS_DIR_SEPARATOR (p[3]))
-               goto not_this_one;
-
-             /* found a match */
-             t = t + d->vpathlv[i] + 1;
-             break;
-           }
-       not_this_one:;
-       }
+        {
+          if (!strncmp (d->vpathv[i], t, d->vpathlv[i]))
+            {
+              const char *p = t + d->vpathlv[i];
+              if (!IS_DIR_SEPARATOR (*p))
+                goto not_this_one;
+
+              /* Do not simplify $(vpath)/../whatever.  ??? Might not
+                 be necessary. */
+              if (p[1] == '.' && p[2] == '.' && IS_DIR_SEPARATOR (p[3]))
+                goto not_this_one;
+
+              /* found a match */
+              t = t + d->vpathlv[i] + 1;
+              break;
+            }
+        not_this_one:;
+        }
     }
 
   /* Remove leading ./ in any case.  */
@@ -145,9 +155,9 @@ apply_vpath (struct deps *d, const char *t)
     {
       t += 2;
       /* If we removed a leading ./, then also remove any /s after the
-        first.  */
+         first.  */
       while (IS_DIR_SEPARATOR (t[0]))
-       ++t;
+        ++t;
     }
 
   return t;
@@ -169,21 +179,21 @@ deps_free (struct deps *d)
   if (d->targetv)
     {
       for (i = 0; i < d->ntargets; i++)
-       free ((void *) d->targetv[i]);
+        free ((void *) d->targetv[i]);
       free (d->targetv);
     }
 
   if (d->depv)
     {
       for (i = 0; i < d->ndeps; i++)
-       free ((void *) d->depv[i]);
+        free ((void *) d->depv[i]);
       free (d->depv);
     }
 
   if (d->vpathv)
     {
       for (i = 0; i < d->nvpaths; i++)
-       free ((void *) d->vpathv[i]);
+        free ((void *) d->vpathv[i]);
       free (d->vpathv);
       free (d->vpathlv);
     }
@@ -232,6 +242,7 @@ deps_add_default_target (cpp_reader *pfile, const char *tgt)
 #endif
       const char *start = lbasename (tgt);
       char *o;
+
       char *suffix;
       const char *obj_ext;
 
@@ -248,7 +259,6 @@ deps_add_default_target (cpp_reader *pfile, const char *tgt)
         obj_ext = CPP_OPTION (pfile, obj_ext);
 
       o = (char *) alloca (strlen (start) + strlen (obj_ext) + 1);
-
       strcpy (o, start);
 
       suffix = strrchr (o, '.');
@@ -288,14 +298,14 @@ deps_add_vpath (struct deps *d, const char *vpath)
       memcpy (copy, elem, len);
       copy[len] = '\0';
       if (*p == ':')
-       p++;
+        p++;
 
       if (d->nvpaths == d->vpaths_size)
-       {
-         d->vpaths_size = d->vpaths_size * 2 + 8;
-         d->vpathv = XRESIZEVEC (const char *, d->vpathv, d->vpaths_size);
-         d->vpathlv = XRESIZEVEC (size_t, d->vpathlv, d->vpaths_size);
-       }
+        {
+          d->vpaths_size = d->vpaths_size * 2 + 8;
+          d->vpathv = XRESIZEVEC (const char *, d->vpathv, d->vpaths_size);
+          d->vpathlv = XRESIZEVEC (size_t, d->vpathlv, d->vpaths_size);
+        }
       d->vpathv[d->nvpaths] = copy;
       d->vpathlv[d->nvpaths] = len;
       d->nvpaths++;
@@ -315,37 +325,39 @@ deps_write (const struct deps *d, FILE *fp, unsigned int colmax)
     {
       size = strlen (d->targetv[i]);
       column += size;
-      if (colmax && column > colmax)
-       {
-         fputs (" \\\n ", fp);
-         column = 1 + size;
-       }
       if (i)
-       {
-         putc (' ', fp);
-         column++;
-       }
+        {
+          if (colmax && column > colmax)
+            {
+              fputs (" \\\n ", fp);
+              column = 1 + size;
+            }
+          else
+            {
+              putc (' ', fp);
+              column++;
+            }
+        }
       fputs (d->targetv[i], fp);
     }
 
   putc (':', fp);
-  putc (' ', fp);
-  column += 2;
+  column++;
 
   for (i = 0; i < d->ndeps; i++)
     {
       size = strlen (d->depv[i]);
       column += size;
       if (colmax && column > colmax)
-       {
-         fputs (" \\\n ", fp);
-         column = 1 + size;
-       }
-      if (i)
-       {
-         putc (' ', fp);
-         column++;
-       }
+        {
+          fputs (" \\\n ", fp);
+          column = 1 + size;
+        }
+      else
+        {
+          putc (' ', fp);
+          column++;
+        }
       fputs (d->depv[i], fp);
     }
   putc ('\n', fp);
@@ -415,14 +427,14 @@ deps_restore (struct deps *deps, FILE *fd, const char *self)
     {
       /* Read in # bytes in string.  */
       if (fread (&num_to_read, 1, sizeof (size_t), fd) != sizeof (size_t))
-       return -1;
+        return -1;
       if (buf_size < num_to_read + 1)
-       {
-         buf_size = num_to_read + 1 + 127;
-         buf = XRESIZEVEC (char, buf, buf_size);
-       }
+        {
+          buf_size = num_to_read + 1 + 127;
+          buf = XRESIZEVEC (char, buf, buf_size);
+        }
       if (fread (buf, 1, num_to_read, fd) != num_to_read)
-       return -1;
+        return -1;
       buf[num_to_read] = '\0';
 
       /* Generate makefile dependencies from .pch if -nopch-deps.  */