OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [config/] [alpha/] [vms-ld.c] - Diff between revs 38 and 154

Only display areas with differences | Details | Blame | View Log

Rev 38 Rev 154
/* VMS linker wrapper.
/* VMS linker wrapper.
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2007
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2007
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Douglas B. Rupp (rupp@gnat.com).
   Contributed by Douglas B. Rupp (rupp@gnat.com).
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC 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.
 
 
GCC is distributed in the hope that it will be useful,
GCC 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 GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
/* This program is a wrapper around the VMS linker.
/* This program is a wrapper around the VMS linker.
   It translates Unix style command line options into corresponding
   It translates Unix style command line options into corresponding
   VMS style qualifiers and then spawns the VMS linker.  */
   VMS style qualifiers and then spawns the VMS linker.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
 
 
typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
 
 
#undef PATH_SEPARATOR
#undef PATH_SEPARATOR
#undef PATH_SEPARATOR_STR
#undef PATH_SEPARATOR_STR
#define PATH_SEPARATOR ','
#define PATH_SEPARATOR ','
#define PATH_SEPARATOR_STR ","
#define PATH_SEPARATOR_STR ","
 
 
/* Local variable declarations.  */
/* Local variable declarations.  */
 
 
/* File specification for vms-dwarf2.o.  */
/* File specification for vms-dwarf2.o.  */
static char *vmsdwarf2spec = 0;
static char *vmsdwarf2spec = 0;
 
 
/* File specification for vms-dwarf2eh.o.  */
/* File specification for vms-dwarf2eh.o.  */
static char *vmsdwarf2ehspec = 0;
static char *vmsdwarf2ehspec = 0;
 
 
/* verbose = 1 if -v passed.  */
/* verbose = 1 if -v passed.  */
static int verbose = 0;
static int verbose = 0;
 
 
/* save_temps = 1 if -save-temps passed.  */
/* save_temps = 1 if -save-temps passed.  */
static int save_temps = 0;
static int save_temps = 0;
 
 
/* By default don't generate executable file if there are errors
/* By default don't generate executable file if there are errors
   in the link. Override with --noinhibit-exec.  */
   in the link. Override with --noinhibit-exec.  */
static int inhibit_exec = 1;
static int inhibit_exec = 1;
 
 
/* debug = 1 if -g passed.  */
/* debug = 1 if -g passed.  */
static int debug = 0;
static int debug = 0;
 
 
/* By default prefer to link with shareable image libraries.
/* By default prefer to link with shareable image libraries.
   Override with -static.  */
   Override with -static.  */
static int staticp = 0;
static int staticp = 0;
 
 
/* By default generate an executable, not a shareable image library.
/* By default generate an executable, not a shareable image library.
   Override with -shared.  */
   Override with -shared.  */
static int share = 0;
static int share = 0;
 
 
/* Remember if IDENTIFICATION given on command line.  */
/* Remember if IDENTIFICATION given on command line.  */
static int ident = 0;
static int ident = 0;
 
 
/* Keep track of arg translations.  */
/* Keep track of arg translations.  */
static int link_arg_max = -1;
static int link_arg_max = -1;
static const char **link_args = 0;
static const char **link_args = 0;
static int link_arg_index = -1;
static int link_arg_index = -1;
 
 
/* Keep track of filenames */
/* Keep track of filenames */
static char optfilefullname [267];
static char optfilefullname [267];
static char *sharefilename = 0;
static char *sharefilename = 0;
static char *exefilename = 0;
static char *exefilename = 0;
 
 
/* System search dir list. Leave blank since link handles this
/* System search dir list. Leave blank since link handles this
   internally.  */
   internally.  */
static char *system_search_dirs = "";
static char *system_search_dirs = "";
 
 
/* Search dir list passed on command line (with -L).  */
/* Search dir list passed on command line (with -L).  */
static char *search_dirs;
static char *search_dirs;
 
 
/* Local function declarations.  */
/* Local function declarations.  */
 
 
/* Add STR to the list of arguments to pass to the linker. Expand the list as
/* Add STR to the list of arguments to pass to the linker. Expand the list as
   necessary to accommodate.  */
   necessary to accommodate.  */
static void addarg (const char *);
static void addarg (const char *);
 
 
/* Check to see if NAME is a regular file, i.e. not a directory */
/* Check to see if NAME is a regular file, i.e. not a directory */
static int is_regular_file (char *);
static int is_regular_file (char *);
 
 
/* Translate a Unix syntax file specification FILESPEC into VMS syntax.
/* Translate a Unix syntax file specification FILESPEC into VMS syntax.
   If indicators of VMS syntax found, return input string.  */
   If indicators of VMS syntax found, return input string.  */
static char *to_host_file_spec (char *);
static char *to_host_file_spec (char *);
 
 
/* Locate the library named LIB_NAME in the set of paths PATH_VAL.  */
/* Locate the library named LIB_NAME in the set of paths PATH_VAL.  */
static char *locate_lib (char *, char *);
static char *locate_lib (char *, char *);
 
 
/* Given a library name NAME, i.e. foo,  Look for libfoo.lib and then
/* Given a library name NAME, i.e. foo,  Look for libfoo.lib and then
   libfoo.a in the set of directories we are allowed to search in.  */
   libfoo.a in the set of directories we are allowed to search in.  */
static const char *expand_lib (char *);
static const char *expand_lib (char *);
 
 
/* Preprocess the number of args P_ARGC in ARGV.
/* Preprocess the number of args P_ARGC in ARGV.
   Look for special flags, etc. that must be handled first.  */
   Look for special flags, etc. that must be handled first.  */
static void preprocess_args (int *, char **);
static void preprocess_args (int *, char **);
 
 
/* Preprocess the number of args P_ARGC in ARGV.  Look for
/* Preprocess the number of args P_ARGC in ARGV.  Look for
   special flags, etc. that must be handled for the VMS linker.  */
   special flags, etc. that must be handled for the VMS linker.  */
static void process_args (int *, char **);
static void process_args (int *, char **);
 
 
/* Action routine called by decc$to_vms. NAME is a file name or
/* Action routine called by decc$to_vms. NAME is a file name or
   directory name. TYPE is unused.  */
   directory name. TYPE is unused.  */
static int translate_unix (char *, int);
static int translate_unix (char *, int);
 
 
int main (int, char **);
int main (int, char **);


static void
static void
addarg (const char *str)
addarg (const char *str)
{
{
  int i;
  int i;
 
 
  if (++link_arg_index >= link_arg_max)
  if (++link_arg_index >= link_arg_max)
    {
    {
      const char **new_link_args
      const char **new_link_args
        = (const char **) xcalloc (link_arg_max + 1000, sizeof (char *));
        = (const char **) xcalloc (link_arg_max + 1000, sizeof (char *));
 
 
      for (i = 0; i <= link_arg_max; i++)
      for (i = 0; i <= link_arg_max; i++)
        new_link_args [i] = link_args [i];
        new_link_args [i] = link_args [i];
 
 
      if (link_args)
      if (link_args)
        free (link_args);
        free (link_args);
 
 
      link_arg_max += 1000;
      link_arg_max += 1000;
      link_args = new_link_args;
      link_args = new_link_args;
    }
    }
 
 
  link_args [link_arg_index] = str;
  link_args [link_arg_index] = str;
}
}
 
 
static char *
static char *
locate_lib (char *lib_name, char *path_val)
locate_lib (char *lib_name, char *path_val)
{
{
  int lib_len = strlen (lib_name);
  int lib_len = strlen (lib_name);
  char *eptr, *sptr;
  char *eptr, *sptr;
 
 
  for (sptr = path_val; *sptr; sptr = eptr)
  for (sptr = path_val; *sptr; sptr = eptr)
    {
    {
      char *buf, *ptr;
      char *buf, *ptr;
 
 
      while (*sptr == PATH_SEPARATOR)
      while (*sptr == PATH_SEPARATOR)
        sptr ++;
        sptr ++;
 
 
      eptr = strchr (sptr, PATH_SEPARATOR);
      eptr = strchr (sptr, PATH_SEPARATOR);
      if (eptr == 0)
      if (eptr == 0)
        eptr = strchr (sptr, 0);
        eptr = strchr (sptr, 0);
 
 
      buf = alloca ((eptr-sptr) + lib_len + 4 + 2);
      buf = alloca ((eptr-sptr) + lib_len + 4 + 2);
      strncpy (buf, sptr, eptr-sptr);
      strncpy (buf, sptr, eptr-sptr);
      buf [eptr-sptr] = 0;
      buf [eptr-sptr] = 0;
      strcat (buf, "/");
      strcat (buf, "/");
      strcat (buf, lib_name);
      strcat (buf, lib_name);
      ptr = strchr (buf, 0);
      ptr = strchr (buf, 0);
 
 
      if (debug || staticp)
      if (debug || staticp)
        {
        {
          /* For debug or static links, look for shareable image libraries
          /* For debug or static links, look for shareable image libraries
             last.  */
             last.  */
          strcpy (ptr, ".a");
          strcpy (ptr, ".a");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
 
 
          strcpy (ptr, ".olb");
          strcpy (ptr, ".olb");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
 
 
          strcpy (ptr, ".exe");
          strcpy (ptr, ".exe");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
        }
        }
      else
      else
        {
        {
          /* Otherwise look for shareable image libraries first.  */
          /* Otherwise look for shareable image libraries first.  */
          strcpy (ptr, ".exe");
          strcpy (ptr, ".exe");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
 
 
          strcpy (ptr, ".a");
          strcpy (ptr, ".a");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
 
 
          strcpy (ptr, ".olb");
          strcpy (ptr, ".olb");
          if (is_regular_file (buf))
          if (is_regular_file (buf))
            return xstrdup (to_host_file_spec (buf));
            return xstrdup (to_host_file_spec (buf));
        }
        }
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
static const char *
static const char *
expand_lib (char *name)
expand_lib (char *name)
{
{
  char *lib, *lib_path;
  char *lib, *lib_path;
 
 
  if (strcmp (name, "c") == 0)
  if (strcmp (name, "c") == 0)
    /* IEEE VAX C compatible library for non-prefixed (e.g. no DECC$)
    /* IEEE VAX C compatible library for non-prefixed (e.g. no DECC$)
       C RTL functions.  */
       C RTL functions.  */
    return "sys$library:vaxcrtltx.olb";
    return "sys$library:vaxcrtltx.olb";
 
 
  else if (strcmp (name, "m") == 0)
  else if (strcmp (name, "m") == 0)
    /* No separate library for math functions */
    /* No separate library for math functions */
    return "";
    return "";
 
 
  else
  else
    {
    {
      lib = xmalloc (strlen (name) + 14);
      lib = xmalloc (strlen (name) + 14);
 
 
      strcpy (lib, "lib");
      strcpy (lib, "lib");
      strcat (lib, name);
      strcat (lib, name);
      lib_path = locate_lib (lib, search_dirs);
      lib_path = locate_lib (lib, search_dirs);
 
 
      if (lib_path)
      if (lib_path)
        return lib_path;
        return lib_path;
    }
    }
 
 
  fprintf (stderr,
  fprintf (stderr,
           "Couldn't locate library: lib%s.exe, lib%s.a or lib%s.olb\n",
           "Couldn't locate library: lib%s.exe, lib%s.a or lib%s.olb\n",
           name, name, name);
           name, name, name);
 
 
  exit (1);
  exit (1);
}
}
 
 
static int
static int
is_regular_file (char *name)
is_regular_file (char *name)
{
{
  int ret;
  int ret;
  struct stat statbuf;
  struct stat statbuf;
 
 
  ret = stat (name, &statbuf);
  ret = stat (name, &statbuf);
  return !ret && S_ISREG (statbuf.st_mode);
  return !ret && S_ISREG (statbuf.st_mode);
}
}
 
 
static void
static void
preprocess_args (int *p_argc, char **argv)
preprocess_args (int *p_argc, char **argv)
{
{
  int i;
  int i;
 
 
  for (i = 1; i < *p_argc; i++)
  for (i = 1; i < *p_argc; i++)
    if (strlen (argv[i]) >= 6 && strncmp (argv[i], "-shared", 7) == 0)
    if (strlen (argv[i]) >= 6 && strncmp (argv[i], "-shared", 7) == 0)
      share = 1;
      share = 1;
 
 
  for (i = 1; i < *p_argc; i++)
  for (i = 1; i < *p_argc; i++)
    if (strcmp (argv[i], "-o") == 0)
    if (strcmp (argv[i], "-o") == 0)
      {
      {
        char *buff, *ptr;
        char *buff, *ptr;
        int out_len;
        int out_len;
        int len;
        int len;
 
 
        i++;
        i++;
        ptr = to_host_file_spec (argv[i]);
        ptr = to_host_file_spec (argv[i]);
        exefilename = xstrdup (ptr);
        exefilename = xstrdup (ptr);
        out_len = strlen (ptr);
        out_len = strlen (ptr);
        buff = xmalloc (out_len + 18);
        buff = xmalloc (out_len + 18);
 
 
        if (share)
        if (share)
          strcpy (buff, "/share=");
          strcpy (buff, "/share=");
        else
        else
          strcpy (buff, "/exe=");
          strcpy (buff, "/exe=");
 
 
        strcat (buff, ptr);
        strcat (buff, ptr);
        addarg (buff);
        addarg (buff);
 
 
        if (share)
        if (share)
          {
          {
            sharefilename = xmalloc (out_len+5);
            sharefilename = xmalloc (out_len+5);
            if (ptr == strchr (argv[i], ']'))
            if (ptr == strchr (argv[i], ']'))
              strcpy (sharefilename, ++ptr);
              strcpy (sharefilename, ++ptr);
            else if (ptr == strchr (argv[i], ':'))
            else if (ptr == strchr (argv[i], ':'))
              strcpy (sharefilename, ++ptr);
              strcpy (sharefilename, ++ptr);
            else if (ptr == strrchr (argv[i], '/'))
            else if (ptr == strrchr (argv[i], '/'))
              strcpy (sharefilename, ++ptr);
              strcpy (sharefilename, ++ptr);
            else
            else
              strcpy (sharefilename, argv[i]);
              strcpy (sharefilename, argv[i]);
 
 
            len = strlen (sharefilename);
            len = strlen (sharefilename);
            if (strncasecmp (&sharefilename[len-4], ".exe", 4) == 0)
            if (strncasecmp (&sharefilename[len-4], ".exe", 4) == 0)
              sharefilename[len-4] = 0;
              sharefilename[len-4] = 0;
 
 
            for (ptr = sharefilename; *ptr; ptr++)
            for (ptr = sharefilename; *ptr; ptr++)
              *ptr = TOUPPER (*ptr);
              *ptr = TOUPPER (*ptr);
          }
          }
      }
      }
}
}
 
 
static void
static void
process_args (int *p_argc, char **argv)
process_args (int *p_argc, char **argv)
{
{
  int i;
  int i;
 
 
  for (i = 1; i < *p_argc; i++)
  for (i = 1; i < *p_argc; i++)
    {
    {
      if (strlen (argv[i]) < 2)
      if (strlen (argv[i]) < 2)
        continue;
        continue;
 
 
      if (strncmp (argv[i], "-L", 2) == 0)
      if (strncmp (argv[i], "-L", 2) == 0)
        {
        {
          char *nbuff, *ptr;
          char *nbuff, *ptr;
          int new_len, search_dirs_len;
          int new_len, search_dirs_len;
 
 
          ptr = &argv[i][2];
          ptr = &argv[i][2];
          new_len = strlen (ptr);
          new_len = strlen (ptr);
          search_dirs_len = strlen (search_dirs);
          search_dirs_len = strlen (search_dirs);
 
 
          nbuff = xmalloc (new_len + 1);
          nbuff = xmalloc (new_len + 1);
          strcpy (nbuff, ptr);
          strcpy (nbuff, ptr);
 
 
          /* Remove trailing slashes.  */
          /* Remove trailing slashes.  */
          while (new_len > 1 && nbuff [new_len - 1] == '/')
          while (new_len > 1 && nbuff [new_len - 1] == '/')
            {
            {
              nbuff [new_len - 1] = 0;
              nbuff [new_len - 1] = 0;
              new_len--;
              new_len--;
            }
            }
 
 
          search_dirs = xrealloc (search_dirs, search_dirs_len + new_len + 2);
          search_dirs = xrealloc (search_dirs, search_dirs_len + new_len + 2);
          if (search_dirs_len > 0)
          if (search_dirs_len > 0)
            strcat (search_dirs, PATH_SEPARATOR_STR);
            strcat (search_dirs, PATH_SEPARATOR_STR);
 
 
          strcat (search_dirs, nbuff);
          strcat (search_dirs, nbuff);
          free (nbuff);
          free (nbuff);
        }
        }
 
 
      /* -v turns on verbose option here and is passed on to gcc.  */
      /* -v turns on verbose option here and is passed on to gcc.  */
      else if (strcmp (argv[i], "-v") == 0)
      else if (strcmp (argv[i], "-v") == 0)
        verbose = 1;
        verbose = 1;
      else if (strcmp (argv[i], "-g0") == 0)
      else if (strcmp (argv[i], "-g0") == 0)
        addarg ("/notraceback");
        addarg ("/notraceback");
      else if (strncmp (argv[i], "-g", 2) == 0)
      else if (strncmp (argv[i], "-g", 2) == 0)
        {
        {
          addarg ("/debug");
          addarg ("/debug");
          debug = 1;
          debug = 1;
        }
        }
      else if (strcmp (argv[i], "-static") == 0)
      else if (strcmp (argv[i], "-static") == 0)
        staticp = 1;
        staticp = 1;
      else if (strcmp (argv[i], "-map") == 0)
      else if (strcmp (argv[i], "-map") == 0)
        {
        {
          char *buff, *ptr;
          char *buff, *ptr;
 
 
          buff = xmalloc (strlen (exefilename) + 5);
          buff = xmalloc (strlen (exefilename) + 5);
          strcpy (buff, exefilename);
          strcpy (buff, exefilename);
          ptr = strchr (buff, '.');
          ptr = strchr (buff, '.');
          if (ptr)
          if (ptr)
            *ptr = 0;
            *ptr = 0;
 
 
          strcat (buff, ".map");
          strcat (buff, ".map");
          addarg ("/map=");
          addarg ("/map=");
          addarg (buff);
          addarg (buff);
          addarg ("/full");
          addarg ("/full");
        }
        }
      else if (strcmp (argv[i], "-save-temps") == 0)
      else if (strcmp (argv[i], "-save-temps") == 0)
        save_temps = 1;
        save_temps = 1;
      else if (strcmp (argv[i], "--noinhibit-exec") == 0)
      else if (strcmp (argv[i], "--noinhibit-exec") == 0)
        inhibit_exec = 0;
        inhibit_exec = 0;
    }
    }
}
}
 
 
/* The main program.  Spawn the VMS linker after fixing up the Unix-like flags
/* The main program.  Spawn the VMS linker after fixing up the Unix-like flags
   and args to be what the VMS linker wants.  */
   and args to be what the VMS linker wants.  */
 
 
int
int
main (int argc, char **argv)
main (int argc, char **argv)
{
{
  int i;
  int i;
  char cwdev [128], *devptr;
  char cwdev [128], *devptr;
  int devlen;
  int devlen;
  int optfd;
  int optfd;
  FILE *optfile;
  FILE *optfile;
  char *cwd = getcwd (0, 1024);
  char *cwd = getcwd (0, 1024);
  char *optfilename;
  char *optfilename;
 
 
  devptr = strchr (cwd, ':');
  devptr = strchr (cwd, ':');
  devlen = (devptr - cwd) + 1;
  devlen = (devptr - cwd) + 1;
  strncpy (cwdev, cwd, devlen);
  strncpy (cwdev, cwd, devlen);
  cwdev [devlen] = '\0';
  cwdev [devlen] = '\0';
 
 
  search_dirs = xstrdup (system_search_dirs);
  search_dirs = xstrdup (system_search_dirs);
 
 
  addarg ("link");
  addarg ("link");
 
 
  /* Pass to find args that have to be append first.  */
  /* Pass to find args that have to be append first.  */
  preprocess_args (&argc , argv);
  preprocess_args (&argc , argv);
 
 
  /* Pass to find the rest of the args.  */
  /* Pass to find the rest of the args.  */
  process_args (&argc , argv);
  process_args (&argc , argv);
 
 
  /* Create a temp file to hold args, otherwise we can easily exceed the VMS
  /* Create a temp file to hold args, otherwise we can easily exceed the VMS
     command line length limits.  */
     command line length limits.  */
  optfilename = alloca (strlen ("LDXXXXXX") + 1);
  optfilename = alloca (strlen ("LDXXXXXX") + 1);
  strcpy (optfilename, "LDXXXXXX");
  strcpy (optfilename, "LDXXXXXX");
  optfd = mkstemp (optfilename);
  optfd = mkstemp (optfilename);
  getcwd (optfilefullname, 256, 1); /* VMS style cwd.  */
  getcwd (optfilefullname, 256, 1); /* VMS style cwd.  */
  strcat (optfilefullname, optfilename);
  strcat (optfilefullname, optfilename);
  strcat (optfilefullname, ".");
  strcat (optfilefullname, ".");
  optfile = fdopen (optfd, "w");
  optfile = fdopen (optfd, "w");
 
 
  /* Write out the IDENTIFICATION argument first so that it can be overridden
  /* Write out the IDENTIFICATION argument first so that it can be overridden
     by an options file.  */
     by an options file.  */
  for (i = 1; i < argc; i++)
  for (i = 1; i < argc; i++)
    {
    {
      int arg_len = strlen (argv[i]);
      int arg_len = strlen (argv[i]);
 
 
      if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)
      if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)
        {
        {
          /* Comes from command line. If present will always appear before
          /* Comes from command line. If present will always appear before
             IDENTIFICATION=... and will override.  */
             IDENTIFICATION=... and will override.  */
 
 
          if (!ident)
          if (!ident)
            ident = 1;
            ident = 1;
        }
        }
      else if (arg_len > 15
      else if (arg_len > 15
               && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)
               && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)
        {
        {
          /* Comes from pragma Ident ().  */
          /* Comes from pragma Ident ().  */
 
 
          if (!ident)
          if (!ident)
            {
            {
              fprintf (optfile, "case_sensitive=yes\n");
              fprintf (optfile, "case_sensitive=yes\n");
              fprintf (optfile, "IDENTIFICATION=\"%15.15s\"\n", &argv[i][15]);
              fprintf (optfile, "IDENTIFICATION=\"%15.15s\"\n", &argv[i][15]);
              fprintf (optfile, "case_sensitive=NO\n");
              fprintf (optfile, "case_sensitive=NO\n");
              ident = 1;
              ident = 1;
            }
            }
        }
        }
    }
    }
 
 
  for (i = 1; i < argc; i++)
  for (i = 1; i < argc; i++)
    {
    {
      int arg_len = strlen (argv[i]);
      int arg_len = strlen (argv[i]);
 
 
      if (strcmp (argv[i], "-o") == 0)
      if (strcmp (argv[i], "-o") == 0)
        i++;
        i++;
      else if (arg_len > 2 && strncmp (argv[i], "-l", 2) == 0)
      else if (arg_len > 2 && strncmp (argv[i], "-l", 2) == 0)
        {
        {
          const char *libname = expand_lib (&argv[i][2]);
          const char *libname = expand_lib (&argv[i][2]);
          const char *ext;
          const char *ext;
          int len;
          int len;
 
 
          if ((len = strlen (libname)) > 0)
          if ((len = strlen (libname)) > 0)
            {
            {
              char buff [256];
              char buff [256];
 
 
              if (len > 4 && strcasecmp (&libname [len-4], ".exe") == 0)
              if (len > 4 && strcasecmp (&libname [len-4], ".exe") == 0)
                ext = "/shareable";
                ext = "/shareable";
              else
              else
                ext = "/library";
                ext = "/library";
 
 
              if (libname[0] == '[')
              if (libname[0] == '[')
                sprintf (buff, "%s%s", cwdev, libname);
                sprintf (buff, "%s%s", cwdev, libname);
              else
              else
                sprintf (buff, "%s", libname);
                sprintf (buff, "%s", libname);
 
 
              fprintf (optfile, "%s%s\n", buff, ext);
              fprintf (optfile, "%s%s\n", buff, ext);
            }
            }
        }
        }
 
 
      else if (strcmp (argv[i], "-v" ) == 0
      else if (strcmp (argv[i], "-v" ) == 0
               || strncmp (argv[i], "-g", 2 ) == 0
               || strncmp (argv[i], "-g", 2 ) == 0
               || strcmp (argv[i], "-static" ) == 0
               || strcmp (argv[i], "-static" ) == 0
               || strcmp (argv[i], "-map" ) == 0
               || strcmp (argv[i], "-map" ) == 0
               || strcmp (argv[i], "-save-temps") == 0
               || strcmp (argv[i], "-save-temps") == 0
               || strcmp (argv[i], "--noinhibit-exec") == 0
               || strcmp (argv[i], "--noinhibit-exec") == 0
               || (arg_len > 2 && strncmp (argv[i], "-L", 2) == 0)
               || (arg_len > 2 && strncmp (argv[i], "-L", 2) == 0)
               || (arg_len >= 6 && strncmp (argv[i], "-share", 6) == 0))
               || (arg_len >= 6 && strncmp (argv[i], "-share", 6) == 0))
        ;
        ;
      else if (arg_len > 1 && argv[i][0] == '@')
      else if (arg_len > 1 && argv[i][0] == '@')
        {
        {
          FILE *atfile;
          FILE *atfile;
          char *ptr, *ptr1;
          char *ptr, *ptr1;
          struct stat statbuf;
          struct stat statbuf;
          char *buff;
          char *buff;
          int len;
          int len;
 
 
          if (stat (&argv[i][1], &statbuf))
          if (stat (&argv[i][1], &statbuf))
            {
            {
              fprintf (stderr, "Couldn't open linker response file: %s\n",
              fprintf (stderr, "Couldn't open linker response file: %s\n",
                       &argv[i][1]);
                       &argv[i][1]);
              exit (1);
              exit (1);
            }
            }
 
 
          buff = xmalloc (statbuf.st_size + 1);
          buff = xmalloc (statbuf.st_size + 1);
          atfile = fopen (&argv[i][1], "r");
          atfile = fopen (&argv[i][1], "r");
          fgets (buff, statbuf.st_size + 1, atfile);
          fgets (buff, statbuf.st_size + 1, atfile);
          fclose (atfile);
          fclose (atfile);
 
 
          len = strlen (buff);
          len = strlen (buff);
          if (buff [len - 1] == '\n')
          if (buff [len - 1] == '\n')
            {
            {
              buff [len - 1] = 0;
              buff [len - 1] = 0;
              len--;
              len--;
            }
            }
 
 
          ptr = buff;
          ptr = buff;
 
 
          do
          do
          {
          {
             ptr1 = strchr (ptr, ' ');
             ptr1 = strchr (ptr, ' ');
             if (ptr1)
             if (ptr1)
               *ptr1 = 0;
               *ptr1 = 0;
             ptr = to_host_file_spec (ptr);
             ptr = to_host_file_spec (ptr);
             if (ptr[0] == '[')
             if (ptr[0] == '[')
               fprintf (optfile, "%s%s\n", cwdev, ptr);
               fprintf (optfile, "%s%s\n", cwdev, ptr);
             else
             else
               fprintf (optfile, "%s\n", ptr);
               fprintf (optfile, "%s\n", ptr);
             ptr = ptr1 + 1;
             ptr = ptr1 + 1;
          } while (ptr1);
          } while (ptr1);
        }
        }
 
 
      /* Unix style file specs and VMS style switches look alike, so assume an
      /* Unix style file specs and VMS style switches look alike, so assume an
         arg consisting of one and only one slash, and that being first, is
         arg consisting of one and only one slash, and that being first, is
         really a switch.  */
         really a switch.  */
      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
        addarg (argv[i]);
        addarg (argv[i]);
      else if (arg_len > 4
      else if (arg_len > 4
               && strncasecmp (&argv[i][arg_len-4], ".OPT", 4) == 0)
               && strncasecmp (&argv[i][arg_len-4], ".OPT", 4) == 0)
        {
        {
          FILE *optfile1;
          FILE *optfile1;
          char buff [256];
          char buff [256];
 
 
          optfile1 = fopen (argv[i], "r");
          optfile1 = fopen (argv[i], "r");
          while (fgets (buff, 256, optfile1))
          while (fgets (buff, 256, optfile1))
            fputs (buff, optfile);
            fputs (buff, optfile);
 
 
          fclose (optfile1);
          fclose (optfile1);
        }
        }
      else if (arg_len > 7 && strncasecmp (argv[i], "GSMATCH", 7) == 0)
      else if (arg_len > 7 && strncasecmp (argv[i], "GSMATCH", 7) == 0)
        fprintf (optfile, "%s\n", argv[i]);
        fprintf (optfile, "%s\n", argv[i]);
      else if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)
      else if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)
        {
        {
          /* Comes from command line and will override pragma.  */
          /* Comes from command line and will override pragma.  */
          fprintf (optfile, "case_sensitive=yes\n");
          fprintf (optfile, "case_sensitive=yes\n");
          fprintf (optfile, "IDENT=\"%15.15s\"\n", &argv[i][6]);
          fprintf (optfile, "IDENT=\"%15.15s\"\n", &argv[i][6]);
          fprintf (optfile, "case_sensitive=NO\n");
          fprintf (optfile, "case_sensitive=NO\n");
          ident = 1;
          ident = 1;
        }
        }
      else if (arg_len > 15
      else if (arg_len > 15
               && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)
               && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)
        ;
        ;
      else
      else
        {
        {
          /* Assume filename arg.  */
          /* Assume filename arg.  */
          const char *addswitch = "";
          const char *addswitch = "";
          char buff [256];
          char buff [256];
          int buff_len;
          int buff_len;
          int is_cld = 0;
          int is_cld = 0;
 
 
          argv[i] = to_host_file_spec (argv[i]);
          argv[i] = to_host_file_spec (argv[i]);
          arg_len = strlen (argv[i]);
          arg_len = strlen (argv[i]);
 
 
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".exe") == 0)
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".exe") == 0)
            addswitch = "/shareable";
            addswitch = "/shareable";
 
 
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".cld") == 0)
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".cld") == 0)
            {
            {
              addswitch = "/shareable";
              addswitch = "/shareable";
              is_cld = 1;
              is_cld = 1;
            }
            }
 
 
          if (arg_len > 2 && strcasecmp (&argv[i][arg_len-2], ".a") == 0)
          if (arg_len > 2 && strcasecmp (&argv[i][arg_len-2], ".a") == 0)
            addswitch = "/lib";
            addswitch = "/lib";
 
 
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".olb") == 0)
          if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".olb") == 0)
            addswitch = "/lib";
            addswitch = "/lib";
 
 
          if (argv[i][0] == '[')
          if (argv[i][0] == '[')
            sprintf (buff, "%s%s%s\n", cwdev, argv[i], addswitch);
            sprintf (buff, "%s%s%s\n", cwdev, argv[i], addswitch);
          else if (strchr (argv[i], ':'))
          else if (strchr (argv[i], ':'))
            sprintf (buff, "%s%s\n", argv[i], addswitch);
            sprintf (buff, "%s%s\n", argv[i], addswitch);
          else
          else
            sprintf (buff, "%s%s%s\n", cwd, argv[i], addswitch);
            sprintf (buff, "%s%s%s\n", cwd, argv[i], addswitch);
 
 
          buff_len = strlen (buff);
          buff_len = strlen (buff);
 
 
          if (buff_len >= 15
          if (buff_len >= 15
              && strcasecmp (&buff[buff_len - 15], "vms-dwarf2eh.o\n") == 0)
              && strcasecmp (&buff[buff_len - 15], "vms-dwarf2eh.o\n") == 0)
            vmsdwarf2ehspec = xstrdup (buff);
            vmsdwarf2ehspec = xstrdup (buff);
          else if (buff_len >= 13
          else if (buff_len >= 13
              && strcasecmp (&buff[buff_len - 13],"vms-dwarf2.o\n") == 0)
              && strcasecmp (&buff[buff_len - 13],"vms-dwarf2.o\n") == 0)
            vmsdwarf2spec = xstrdup (buff);
            vmsdwarf2spec = xstrdup (buff);
          else if (is_cld)
          else if (is_cld)
            {
            {
              addarg (buff);
              addarg (buff);
              addarg (",");
              addarg (",");
            }
            }
          else
          else
            fprintf (optfile, buff);
            fprintf (optfile, buff);
        }
        }
    }
    }
 
 
#if 0
#if 0
  if (share)
  if (share)
    fprintf (optfile, "symbol_vector=(main=procedure)\n");
    fprintf (optfile, "symbol_vector=(main=procedure)\n");
#endif
#endif
 
 
  if (vmsdwarf2ehspec)
  if (vmsdwarf2ehspec)
    {
    {
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "cluster=DWARF2eh,,,%s", vmsdwarf2ehspec);
      fprintf (optfile, "cluster=DWARF2eh,,,%s", vmsdwarf2ehspec);
      fprintf (optfile, "collect=DWARF2eh,eh_frame\n");
      fprintf (optfile, "collect=DWARF2eh,eh_frame\n");
      fprintf (optfile, "case_sensitive=NO\n");
      fprintf (optfile, "case_sensitive=NO\n");
    }
    }
 
 
  if (debug && vmsdwarf2spec)
  if (debug && vmsdwarf2spec)
    {
    {
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "cluster=DWARF2debug,,,%s", vmsdwarf2spec);
      fprintf (optfile, "cluster=DWARF2debug,,,%s", vmsdwarf2spec);
      fprintf (optfile, "collect=DWARF2debug,debug_abbrev,debug_aranges,-\n");
      fprintf (optfile, "collect=DWARF2debug,debug_abbrev,debug_aranges,-\n");
      fprintf (optfile, " debug_frame,debug_info,debug_line,debug_loc,-\n");
      fprintf (optfile, " debug_frame,debug_info,debug_line,debug_loc,-\n");
      fprintf (optfile, " debug_macinfo,debug_pubnames,debug_str,-\n");
      fprintf (optfile, " debug_macinfo,debug_pubnames,debug_str,-\n");
      fprintf (optfile, " debug_zzzzzz\n");
      fprintf (optfile, " debug_zzzzzz\n");
      fprintf (optfile, "case_sensitive=NO\n");
      fprintf (optfile, "case_sensitive=NO\n");
    }
    }
 
 
  if (debug && share)
  if (debug && share)
    {
    {
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "case_sensitive=yes\n");
      fprintf (optfile, "symbol_vector=(-\n");
      fprintf (optfile, "symbol_vector=(-\n");
      fprintf (optfile,
      fprintf (optfile,
               "%s$DWARF2.DEBUG_ABBREV/$dwarf2.debug_abbrev=DATA,-\n",
               "%s$DWARF2.DEBUG_ABBREV/$dwarf2.debug_abbrev=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile,
      fprintf (optfile,
               "%s$DWARF2.DEBUG_ARANGES/$dwarf2.debug_aranges=DATA,-\n",
               "%s$DWARF2.DEBUG_ARANGES/$dwarf2.debug_aranges=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_FRAME/$dwarf2.debug_frame=DATA,-\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_FRAME/$dwarf2.debug_frame=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_INFO/$dwarf2.debug_info=DATA,-\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_INFO/$dwarf2.debug_info=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_LINE/$dwarf2.debug_line=DATA,-\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_LINE/$dwarf2.debug_line=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_LOC/$dwarf2.debug_loc=DATA,-\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_LOC/$dwarf2.debug_loc=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile,
      fprintf (optfile,
               "%s$DWARF2.DEBUG_MACINFO/$dwarf2.debug_macinfo=DATA,-\n",
               "%s$DWARF2.DEBUG_MACINFO/$dwarf2.debug_macinfo=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile,
      fprintf (optfile,
               "%s$DWARF2.DEBUG_PUBNAMES/$dwarf2.debug_pubnames=DATA,-\n",
               "%s$DWARF2.DEBUG_PUBNAMES/$dwarf2.debug_pubnames=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_STR/$dwarf2.debug_str=DATA,-\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_STR/$dwarf2.debug_str=DATA,-\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "%s$DWARF2.DEBUG_ZZZZZZ/$dwarf2.debug_zzzzzz=DATA)\n",
      fprintf (optfile, "%s$DWARF2.DEBUG_ZZZZZZ/$dwarf2.debug_zzzzzz=DATA)\n",
               sharefilename);
               sharefilename);
      fprintf (optfile, "case_sensitive=NO\n");
      fprintf (optfile, "case_sensitive=NO\n");
    }
    }
 
 
  fclose (optfile);
  fclose (optfile);
  addarg (optfilefullname);
  addarg (optfilefullname);
  addarg ("/opt");
  addarg ("/opt");
 
 
  addarg (NULL);
  addarg (NULL);
 
 
  if (verbose)
  if (verbose)
    {
    {
      int i;
      int i;
 
 
      for (i = 0; i < link_arg_index; i++)
      for (i = 0; i < link_arg_index; i++)
        printf ("%s ", link_args [i]);
        printf ("%s ", link_args [i]);
      putchar ('\n');
      putchar ('\n');
    }
    }
 
 
  {
  {
    int i;
    int i;
    int len = 0;
    int len = 0;
 
 
    for (i = 0; link_args[i]; i++)
    for (i = 0; link_args[i]; i++)
      len = len + strlen (link_args[i]) + 1;
      len = len + strlen (link_args[i]) + 1;
 
 
    {
    {
      char *allargs = (char *) alloca (len + 1);
      char *allargs = (char *) alloca (len + 1);
      Descr cmd;
      Descr cmd;
      int status;
      int status;
      int status1 = 1;
      int status1 = 1;
 
 
      for (i = 0; i < len + 1; i++)
      for (i = 0; i < len + 1; i++)
        allargs [i] = 0;
        allargs [i] = 0;
 
 
      for (i = 0; link_args [i]; i++)
      for (i = 0; link_args [i]; i++)
        {
        {
          strcat (allargs, link_args [i]);
          strcat (allargs, link_args [i]);
          strcat (allargs, " ");
          strcat (allargs, " ");
        }
        }
 
 
      cmd.adr = allargs;
      cmd.adr = allargs;
      cmd.len = len;
      cmd.len = len;
      cmd.mbz = 0;
      cmd.mbz = 0;
 
 
      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);
      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);
      if ((i & 1) != 1)
      if ((i & 1) != 1)
        {
        {
          LIB$SIGNAL (i);
          LIB$SIGNAL (i);
          exit (1);
          exit (1);
        }
        }
 
 
      if (debug && !share)
      if (debug && !share)
        {
        {
          strcpy (allargs, "@gnu:[bin]set_exe ");
          strcpy (allargs, "@gnu:[bin]set_exe ");
          strcat (allargs, exefilename);
          strcat (allargs, exefilename);
          strcat (allargs, " /nodebug /silent");
          strcat (allargs, " /nodebug /silent");
          len = strlen (allargs);
          len = strlen (allargs);
          cmd.adr = allargs;
          cmd.adr = allargs;
          cmd.len = len;
          cmd.len = len;
          cmd.mbz = 0;
          cmd.mbz = 0;
 
 
          if (verbose)
          if (verbose)
            printf (allargs);
            printf (allargs);
 
 
          i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status1);
          i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status1);
 
 
          if ((i & 1) != 1)
          if ((i & 1) != 1)
            {
            {
              LIB$SIGNAL (i);
              LIB$SIGNAL (i);
              exit (1);
              exit (1);
            }
            }
        }
        }
 
 
      if (!save_temps)
      if (!save_temps)
        remove (optfilefullname);
        remove (optfilefullname);
 
 
      if ((status & 1) == 1 && (status1 & 1) == 1)
      if ((status & 1) == 1 && (status1 & 1) == 1)
        exit (0);
        exit (0);
 
 
      if (exefilename && inhibit_exec == 1)
      if (exefilename && inhibit_exec == 1)
        remove (exefilename);
        remove (exefilename);
 
 
      exit (1);
      exit (1);
    }
    }
  }
  }
}
}
 
 
static char new_host_filespec [255];
static char new_host_filespec [255];
static char filename_buff [256];
static char filename_buff [256];
 
 
static int
static int
translate_unix (char *name, int type ATTRIBUTE_UNUSED)
translate_unix (char *name, int type ATTRIBUTE_UNUSED)
{
{
  strcpy (filename_buff, name);
  strcpy (filename_buff, name);
  return 0;
  return 0;
}
}
 
 
static char *
static char *
to_host_file_spec (char *filespec)
to_host_file_spec (char *filespec)
{
{
  strcpy (new_host_filespec, "");
  strcpy (new_host_filespec, "");
  if (strchr (filespec, ']') || strchr (filespec, ':'))
  if (strchr (filespec, ']') || strchr (filespec, ':'))
    strcpy (new_host_filespec, filespec);
    strcpy (new_host_filespec, filespec);
  else
  else
    {
    {
      decc$to_vms (filespec, translate_unix, 1, 1);
      decc$to_vms (filespec, translate_unix, 1, 1);
      strcpy (new_host_filespec, filename_buff);
      strcpy (new_host_filespec, filename_buff);
    }
    }
 
 
  return new_host_filespec;
  return new_host_filespec;
}
}
 
 

powered by: WebSVN 2.1.0

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