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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [libcpp/] [makedepend.c] - Diff between revs 38 and 154

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

Rev 38 Rev 154
/* Dependency generator utility.
/* Dependency generator utility.
   Copyright (C) 2004 Free Software Foundation, Inc.
   Copyright (C) 2004 Free Software Foundation, Inc.
   Contributed by Zack Weinberg, May 2004
   Contributed by Zack Weinberg, May 2004
 
 
This program is free software; you can redistribute it and/or modify it
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
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 2, or (at your option) any
later version.
later version.
 
 
This program is distributed in the hope that it will be useful,
This program 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 this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 
 In other words, you are welcome to use, share and improve this program.
 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
 You are forbidden to forbid anyone else to use, share and improve
 what you give them.   Help stamp out software-hoarding!  */
 what you give them.   Help stamp out software-hoarding!  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "line-map.h"
#include "line-map.h"
#include "cpplib.h"
#include "cpplib.h"
#include "getopt.h"
#include "getopt.h"
#include "mkdeps.h"
#include "mkdeps.h"
 
 
const char *progname;
const char *progname;
const char *vpath;
const char *vpath;
 
 
static const char *output_file;
static const char *output_file;
static bool had_errors;
static bool had_errors;
 
 
/* Option lists, to give to cpplib before each input file.  */
/* Option lists, to give to cpplib before each input file.  */
struct cmd_line_macro
struct cmd_line_macro
{
{
  struct cmd_line_macro *next;
  struct cmd_line_macro *next;
  bool is_undef;
  bool is_undef;
  const char *macro;
  const char *macro;
};
};
 
 
static struct cmd_line_macro *cmd_line_macros;
static struct cmd_line_macro *cmd_line_macros;
static cpp_dir *cmd_line_searchpath;
static cpp_dir *cmd_line_searchpath;
 
 
static void
static void
add_clm (const char *macro, bool is_undef)
add_clm (const char *macro, bool is_undef)
{
{
  struct cmd_line_macro *clm = XNEW (struct cmd_line_macro);
  struct cmd_line_macro *clm = XNEW (struct cmd_line_macro);
  clm->next = cmd_line_macros;
  clm->next = cmd_line_macros;
  clm->is_undef = is_undef;
  clm->is_undef = is_undef;
  clm->macro = macro;
  clm->macro = macro;
  cmd_line_macros = clm;
  cmd_line_macros = clm;
}
}
 
 
static void
static void
add_dir (char *name, bool sysp)
add_dir (char *name, bool sysp)
{
{
  cpp_dir *dir = XNEW (cpp_dir);
  cpp_dir *dir = XNEW (cpp_dir);
  dir->next = cmd_line_searchpath;
  dir->next = cmd_line_searchpath;
  dir->name = name;
  dir->name = name;
  dir->sysp = sysp;
  dir->sysp = sysp;
  dir->construct = 0;
  dir->construct = 0;
  dir->user_supplied_p = 1;
  dir->user_supplied_p = 1;
  cmd_line_searchpath = dir;
  cmd_line_searchpath = dir;
}
}
 
 
/* Command line processing.  */
/* Command line processing.  */
 
 
static void ATTRIBUTE_NORETURN
static void ATTRIBUTE_NORETURN
usage (int errcode)
usage (int errcode)
{
{
  fprintf (stderr,
  fprintf (stderr,
"usage: %s [-vh] [-V vpath] [-Dname[=def]...] [-Uname] [-Idir...] [-o file] sources...\n",
"usage: %s [-vh] [-V vpath] [-Dname[=def]...] [-Uname] [-Idir...] [-o file] sources...\n",
           progname);
           progname);
  exit (errcode);
  exit (errcode);
}
}
 
 
static int
static int
parse_options (int argc, char **argv)
parse_options (int argc, char **argv)
{
{
  static const struct option longopts[] = {
  static const struct option longopts[] = {
    { "--help", no_argument, 0, 'h' },
    { "--help", no_argument, 0, 'h' },
    { 0, 0, 0, 0 }
    { 0, 0, 0, 0 }
  };
  };
 
 
  for (;;)
  for (;;)
    switch (getopt_long (argc, argv, "hD:U:I:J:o:V:", longopts, 0))
    switch (getopt_long (argc, argv, "hD:U:I:J:o:V:", longopts, 0))
      {
      {
      case 'h': usage (0);
      case 'h': usage (0);
      case 'D': add_clm (optarg, false); break;
      case 'D': add_clm (optarg, false); break;
      case 'U': add_clm (optarg, true);  break;
      case 'U': add_clm (optarg, true);  break;
      case 'I': add_dir (optarg, false); break;
      case 'I': add_dir (optarg, false); break;
      case 'J': add_dir (optarg, true);  break;
      case 'J': add_dir (optarg, true);  break;
      case 'o':
      case 'o':
        if (output_file)
        if (output_file)
          {
          {
            fprintf (stderr, "%s: too many output files\n", progname);
            fprintf (stderr, "%s: too many output files\n", progname);
            usage (2);
            usage (2);
          }
          }
        output_file = optarg;
        output_file = optarg;
        break;
        break;
      case 'V':
      case 'V':
        if (vpath)
        if (vpath)
          {
          {
            fprintf (stderr, "%s: too many vpaths\n", progname);
            fprintf (stderr, "%s: too many vpaths\n", progname);
            usage (2);
            usage (2);
          }
          }
        vpath = optarg;
        vpath = optarg;
        break;
        break;
      case '?':
      case '?':
        usage (2);  /* getopt has issued the error message.  */
        usage (2);  /* getopt has issued the error message.  */
 
 
      case -1: /* end of options */
      case -1: /* end of options */
        if (optind == argc)
        if (optind == argc)
          {
          {
            fprintf (stderr, "%s: no input files\n", progname);
            fprintf (stderr, "%s: no input files\n", progname);
            usage (2);
            usage (2);
          }
          }
        return optind;
        return optind;
 
 
      default:
      default:
        abort ();
        abort ();
      }
      }
}
}
 
 
/* Set up cpplib from command line options.  */
/* Set up cpplib from command line options.  */
static cpp_reader *
static cpp_reader *
reader_init (struct line_maps *line_table)
reader_init (struct line_maps *line_table)
{
{
  cpp_reader *reader;
  cpp_reader *reader;
  cpp_options *options;
  cpp_options *options;
 
 
  linemap_init (line_table);
  linemap_init (line_table);
  reader = cpp_create_reader (CLK_GNUC89, 0, line_table);
  reader = cpp_create_reader (CLK_GNUC89, 0, line_table);
 
 
  /* Ignore warnings and errors (we don't have access to system
  /* Ignore warnings and errors (we don't have access to system
     headers).  Request dependency output.  */
     headers).  Request dependency output.  */
  options = cpp_get_options (reader);
  options = cpp_get_options (reader);
  options->inhibit_warnings = 1;
  options->inhibit_warnings = 1;
  options->inhibit_errors = 1;
  options->inhibit_errors = 1;
  options->deps.style = DEPS_USER;
  options->deps.style = DEPS_USER;
 
 
  /* Further initialization.  */
  /* Further initialization.  */
  cpp_post_options (reader);
  cpp_post_options (reader);
  cpp_init_iconv (reader);
  cpp_init_iconv (reader);
  cpp_set_include_chains (reader, cmd_line_searchpath, cmd_line_searchpath,
  cpp_set_include_chains (reader, cmd_line_searchpath, cmd_line_searchpath,
                          false);
                          false);
  if (vpath)
  if (vpath)
    {
    {
      struct deps *deps = cpp_get_deps (reader);
      struct deps *deps = cpp_get_deps (reader);
      deps_add_vpath (deps, vpath);
      deps_add_vpath (deps, vpath);
    }
    }
 
 
  return reader;
  return reader;
}
}
 
 
/* Process one input source file.  */
/* Process one input source file.  */
static void
static void
process_file (const char *file)
process_file (const char *file)
{
{
  struct line_maps line_table;
  struct line_maps line_table;
  cpp_reader *reader = reader_init (&line_table);
  cpp_reader *reader = reader_init (&line_table);
 
 
  if (!cpp_read_main_file (reader, file))
  if (!cpp_read_main_file (reader, file))
    had_errors = true;
    had_errors = true;
  else
  else
    {
    {
      struct cmd_line_macro *clm;
      struct cmd_line_macro *clm;
 
 
      cpp_init_builtins (reader, true);
      cpp_init_builtins (reader, true);
      for (clm = cmd_line_macros; clm; clm = clm->next)
      for (clm = cmd_line_macros; clm; clm = clm->next)
        (clm->is_undef ? cpp_undef : cpp_define) (reader, clm->macro);
        (clm->is_undef ? cpp_undef : cpp_define) (reader, clm->macro);
 
 
      cpp_scan_nooutput (reader);
      cpp_scan_nooutput (reader);
      if (cpp_finish (reader, stdout))
      if (cpp_finish (reader, stdout))
        had_errors = true;
        had_errors = true;
    }
    }
  cpp_destroy (reader);
  cpp_destroy (reader);
  linemap_free (&line_table);
  linemap_free (&line_table);
}
}
 
 
/* Master control.  */
/* Master control.  */
 
 
int
int
main(int argc, char **argv)
main(int argc, char **argv)
{
{
  int first_input, i;
  int first_input, i;
 
 
  progname = argv[0];
  progname = argv[0];
  xmalloc_set_program_name (progname);
  xmalloc_set_program_name (progname);
 
 
  first_input = parse_options (argc, argv);
  first_input = parse_options (argc, argv);
  if (output_file)
  if (output_file)
    if (!freopen (output_file, "w", stdout))
    if (!freopen (output_file, "w", stdout))
      {
      {
        perror (output_file);
        perror (output_file);
        return 1;
        return 1;
      }
      }
 
 
  for (i = first_input; i < argc; i++)
  for (i = first_input; i < argc; i++)
    process_file (argv[i]);
    process_file (argv[i]);
 
 
  return had_errors;
  return had_errors;
}
}
 
 

powered by: WebSVN 2.1.0

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