OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [gas/] [depend.c] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
/* depend.c - Handle dependency tracking.
/* depend.c - Handle dependency tracking.
   Copyright 1997, 1998, 2000, 2001, 2003, 2007 Free Software Foundation, Inc.
   Copyright 1997, 1998, 2000, 2001, 2003, 2007 Free Software Foundation, Inc.
 
 
   This file is part of GAS, the GNU Assembler.
   This file is part of GAS, the GNU Assembler.
 
 
   GAS is free software; you can redistribute it and/or modify
   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
 
 
   GAS is distributed in the hope that it will be useful,
   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to the Free
   along with GAS; see the file COPYING.  If not, write to the Free
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */
   02110-1301, USA.  */
 
 
#include "as.h"
#include "as.h"
 
 
/* The file to write to, or NULL if no dependencies being kept.  */
/* The file to write to, or NULL if no dependencies being kept.  */
static char * dep_file = NULL;
static char * dep_file = NULL;
 
 
struct dependency
struct dependency
  {
  {
    char * file;
    char * file;
    struct dependency * next;
    struct dependency * next;
  };
  };
 
 
/* All the files we depend on.  */
/* All the files we depend on.  */
static struct dependency * dep_chain = NULL;
static struct dependency * dep_chain = NULL;
 
 
/* Current column in output file.  */
/* Current column in output file.  */
static int column = 0;
static int column = 0;
 
 
static int quote_string_for_make (FILE *, char *);
static int quote_string_for_make (FILE *, char *);
static void wrap_output (FILE *, char *, int);
static void wrap_output (FILE *, char *, int);
 
 
/* Number of columns allowable.  */
/* Number of columns allowable.  */
#define MAX_COLUMNS 72
#define MAX_COLUMNS 72


/* Start saving dependencies, to be written to FILENAME.  If this is
/* Start saving dependencies, to be written to FILENAME.  If this is
   never called, then dependency tracking is simply skipped.  */
   never called, then dependency tracking is simply skipped.  */
 
 
void
void
start_dependencies (char *filename)
start_dependencies (char *filename)
{
{
  dep_file = filename;
  dep_file = filename;
}
}
 
 
/* Noticed a new filename, so try to register it.  */
/* Noticed a new filename, so try to register it.  */
 
 
void
void
register_dependency (char *filename)
register_dependency (char *filename)
{
{
  struct dependency *dep;
  struct dependency *dep;
 
 
  if (dep_file == NULL)
  if (dep_file == NULL)
    return;
    return;
 
 
  for (dep = dep_chain; dep != NULL; dep = dep->next)
  for (dep = dep_chain; dep != NULL; dep = dep->next)
    {
    {
      if (!strcmp (filename, dep->file))
      if (!strcmp (filename, dep->file))
        return;
        return;
    }
    }
 
 
  dep = (struct dependency *) xmalloc (sizeof (struct dependency));
  dep = (struct dependency *) xmalloc (sizeof (struct dependency));
  dep->file = xstrdup (filename);
  dep->file = xstrdup (filename);
  dep->next = dep_chain;
  dep->next = dep_chain;
  dep_chain = dep;
  dep_chain = dep;
}
}
 
 
/* Quote a file name the way `make' wants it, and print it to FILE.
/* Quote a file name the way `make' wants it, and print it to FILE.
   If FILE is NULL, do no printing, but return the length of the
   If FILE is NULL, do no printing, but return the length of the
   quoted string.
   quoted string.
 
 
   This code is taken from gcc with only minor changes.  */
   This code is taken from gcc with only minor changes.  */
 
 
static int
static int
quote_string_for_make (FILE *file, char *src)
quote_string_for_make (FILE *file, char *src)
{
{
  char *p = src;
  char *p = src;
  int i = 0;
  int i = 0;
 
 
  for (;;)
  for (;;)
    {
    {
      char c = *p++;
      char c = *p++;
 
 
      switch (c)
      switch (c)
        {
        {
        case '\0':
        case '\0':
        case ' ':
        case ' ':
        case '\t':
        case '\t':
          {
          {
            /* GNU make uses a weird quoting scheme for white space.
            /* GNU make uses a weird quoting scheme for white space.
               A space or tab preceded by 2N+1 backslashes represents
               A space or tab preceded by 2N+1 backslashes represents
               N backslashes followed by space; a space or tab
               N backslashes followed by space; a space or tab
               preceded by 2N backslashes represents N backslashes at
               preceded by 2N backslashes represents N backslashes at
               the end of a file name; and backslashes in other
               the end of a file name; and backslashes in other
               contexts should not be doubled.  */
               contexts should not be doubled.  */
            char *q;
            char *q;
 
 
            for (q = p - 1; src < q && q[-1] == '\\'; q--)
            for (q = p - 1; src < q && q[-1] == '\\'; q--)
              {
              {
                if (file)
                if (file)
                  putc ('\\', file);
                  putc ('\\', file);
                i++;
                i++;
              }
              }
          }
          }
          if (!c)
          if (!c)
            return i;
            return i;
          if (file)
          if (file)
            putc ('\\', file);
            putc ('\\', file);
          i++;
          i++;
          goto ordinary_char;
          goto ordinary_char;
 
 
        case '$':
        case '$':
          if (file)
          if (file)
            putc (c, file);
            putc (c, file);
          i++;
          i++;
          /* Fall through.  This can mishandle things like "$(" but
          /* Fall through.  This can mishandle things like "$(" but
             there's no easy fix.  */
             there's no easy fix.  */
        default:
        default:
        ordinary_char:
        ordinary_char:
          /* This can mishandle characters in the string "\0\n%*?[\\~";
          /* This can mishandle characters in the string "\0\n%*?[\\~";
             exactly which chars are mishandled depends on the `make' version.
             exactly which chars are mishandled depends on the `make' version.
             We know of no portable solution for this;
             We know of no portable solution for this;
             even GNU make 3.76.1 doesn't solve the problem entirely.
             even GNU make 3.76.1 doesn't solve the problem entirely.
             (Also, '\0' is mishandled due to our calling conventions.)  */
             (Also, '\0' is mishandled due to our calling conventions.)  */
          if (file)
          if (file)
            putc (c, file);
            putc (c, file);
          i++;
          i++;
          break;
          break;
        }
        }
    }
    }
}
}
 
 
/* Append some output to the file, keeping track of columns and doing
/* Append some output to the file, keeping track of columns and doing
   wrapping as necessary.  */
   wrapping as necessary.  */
 
 
static void
static void
wrap_output (FILE *f, char *string, int spacer)
wrap_output (FILE *f, char *string, int spacer)
{
{
  int len = quote_string_for_make (NULL, string);
  int len = quote_string_for_make (NULL, string);
 
 
  if (len == 0)
  if (len == 0)
    return;
    return;
 
 
  if (column
  if (column
      && (MAX_COLUMNS
      && (MAX_COLUMNS
          - 1 /* spacer */
          - 1 /* spacer */
          - 2 /* ` \'   */
          - 2 /* ` \'   */
          < column + len))
          < column + len))
    {
    {
      fprintf (f, " \\\n ");
      fprintf (f, " \\\n ");
      column = 0;
      column = 0;
      if (spacer == ' ')
      if (spacer == ' ')
        spacer = '\0';
        spacer = '\0';
    }
    }
 
 
  if (spacer == ' ')
  if (spacer == ' ')
    {
    {
      putc (spacer, f);
      putc (spacer, f);
      ++column;
      ++column;
    }
    }
 
 
  quote_string_for_make (f, string);
  quote_string_for_make (f, string);
  column += len;
  column += len;
 
 
  if (spacer == ':')
  if (spacer == ':')
    {
    {
      putc (spacer, f);
      putc (spacer, f);
      ++column;
      ++column;
    }
    }
}
}
 
 
/* Print dependency file.  */
/* Print dependency file.  */
 
 
void
void
print_dependencies (void)
print_dependencies (void)
{
{
  FILE *f;
  FILE *f;
  struct dependency *dep;
  struct dependency *dep;
 
 
  if (dep_file == NULL)
  if (dep_file == NULL)
    return;
    return;
 
 
  f = fopen (dep_file, FOPEN_WT);
  f = fopen (dep_file, FOPEN_WT);
  if (f == NULL)
  if (f == NULL)
    {
    {
      as_warn (_("can't open `%s' for writing"), dep_file);
      as_warn (_("can't open `%s' for writing"), dep_file);
      return;
      return;
    }
    }
 
 
  column = 0;
  column = 0;
  wrap_output (f, out_file_name, ':');
  wrap_output (f, out_file_name, ':');
  for (dep = dep_chain; dep != NULL; dep = dep->next)
  for (dep = dep_chain; dep != NULL; dep = dep->next)
    wrap_output (f, dep->file, ' ');
    wrap_output (f, dep->file, ' ');
 
 
  putc ('\n', f);
  putc ('\n', f);
 
 
  if (fclose (f))
  if (fclose (f))
    as_warn (_("can't close `%s'"), dep_file);
    as_warn (_("can't close `%s'"), dep_file);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.