--- gcc/cp/g++.c 2018/04/24 18:20:22 1.1 +++ gcc/cp/g++.c 2018/04/24 18:27:23 1.1.1.2 @@ -1,5 +1,5 @@ /* G++ preliminary semantic processing for the compiler driver. - Copyright (C) 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. Contributed by Brendan Kehoe (brendan@cygnus.com). This file is part of GNU CC. @@ -16,7 +16,8 @@ GNU General Public License for more deta You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* This program is a wrapper to the main `gcc' driver. For GNU C++, we need to do two special things: a) append `-lg++' in situations @@ -39,7 +40,11 @@ the Free Software Foundation, 675 Mass A #endif #include #include +#if !defined(_WIN32) #include /* May get R_OK, etc. on some systems. */ +#else +#include +#endif #include /* Defined to the name of the compiler; if using a cross compiler, the @@ -54,6 +59,10 @@ the Free Software Foundation, 675 Mass A /* This bit is set if they did `-lm' or `-lmath'. */ #define MATHLIB (1<<2) +#ifndef MATH_LIBRARY +#define MATH_LIBRARY "-lm" +#endif + /* On MSDOS, write temp files in current dir because there's no place else we can expect to use. */ #ifdef __MSDOS__ @@ -84,15 +93,41 @@ extern int errno; #endif extern int sys_nerr; -#if defined(bsd4_4) || defined(__NetBSD__) +#ifndef HAVE_STRERROR +#if defined(bsd4_4) extern const char *const sys_errlist[]; #else extern char *sys_errlist[]; #endif +#else +extern char *strerror(); +#endif /* Name with which this program was invoked. */ static char *programname; +char * +my_strerror(e) + int e; +{ + +#ifdef HAVE_STRERROR + return strerror(e); + +#else + + static char buffer[30]; + if (!e) + return ""; + + if (e > 0 && e < sys_nerr) + return sys_errlist[e]; + + sprintf (buffer, "Unknown error %d", e); + return buffer; +#endif +} + #ifdef HAVE_VPRINTF /* Output an error message and exit */ @@ -207,13 +242,7 @@ static void pfatal_with_name (name) char *name; { - char *s; - - if (errno < sys_nerr) - s = concat ("%s: ", sys_errlist[errno], ""); - else - s = "cannot open %s"; - fatal (s, name); + fatal (concat ("%s: ", my_strerror (errno), ""), name); } #ifdef __MSDOS__ @@ -283,7 +312,7 @@ perror_exec (name) if (errno < sys_nerr) s = concat ("installation problem, cannot exec %s: ", - sys_errlist[errno], ""); + my_strerror( errno ), ""); else s = "installation problem, cannot exec %s"; error (s, name); @@ -340,9 +369,9 @@ main (argc, argv) register char *p; int verbose = 0; - /* This will be NULL if we encounter a situation where we should not - link in libg++. */ - char *library = "-lg++"; + /* This will be 0 if we encounter a situation where we should not + link in libstdc++, or 2 if we should link in libg++ as well. */ + int library = 1; /* Used to track options that take arguments, so we don't go wrapping those with -xc++/-xnone. */ @@ -361,18 +390,26 @@ main (argc, argv) int saw_speclang = 0; /* Non-zero if we saw `-lm' or `-lmath' on the command line. */ - int saw_math = 0; + char *saw_math = 0; - /* The number of arguments being added to what's in argv. By - default it's one new argument (adding `-lg++'). We use this - to track the number of times we've inserted -xc++/-xnone as well. */ - int added = 1; + /* The number of arguments being added to what's in argv, other than + libraries. We use this to track the number of times we've inserted + -xc++/-xnone. */ + int added = 0; /* An array used to flag each argument that needs a bit set for LANGSPEC or MATHLIB. */ int *args; p = argv[0] + strlen (argv[0]); + + /* If we're called as g++ (or i386-aout-g++), link in libg++ as well. */ + + if (strcmp (p - 3, "g++") == 0) + { + library = 2; + } + while (p != argv[0] && p[-1] != '/') --p; programname = p; @@ -411,10 +448,9 @@ main (argc, argv) if (argv[i][0] == '-') { - if (strcmp (argv[i], "-nostdlib") == 0) + if (library != 0 && strcmp (argv[i], "-nostdlib") == 0) { - added--; - library = NULL; + library = 0; } else if (strcmp (argv[i], "-lm") == 0 || strcmp (argv[i], "-lmath") == 0) @@ -426,8 +462,7 @@ main (argc, argv) { /* If they only gave us `-v', don't try to link in libg++. */ - added--; - library = NULL; + library = 0; } } else if (strncmp (argv[i], "-x", 2) == 0) @@ -436,14 +471,13 @@ main (argc, argv) && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL) || strcmp (argv[i], "-Tdata") == 0)) quote = argv[i]; - else if (library != NULL && ((argv[i][2] == '\0' + else if (library != 0 && ((argv[i][2] == '\0' && (char *) strchr ("cSEM", argv[i][1]) != NULL) || strcmp (argv[i], "-MM") == 0)) { /* Don't specify libraries if we won't link, since that would cause a warning. */ - added--; - library = NULL; + library = 0; } else /* Pass other options through. */ @@ -475,9 +509,9 @@ main (argc, argv) if (quote) fatal ("argument to `%s' missing\n", quote); - if (added) + if (added || library) { - arglist = (char **) malloc ((argc + added + 1) * sizeof (char *)); + arglist = (char **) malloc ((argc + added + 4) * sizeof (char *)); for (i = 1, j = 1; i < argc; i++, j++) { @@ -487,9 +521,8 @@ main (argc, argv) itself uses those math routines. */ if (!saw_math && (args[i] & MATHLIB) && library) { - saw_math = 1; - arglist[j] = library; - arglist[++j] = argv[i]; + --j; + saw_math = argv[i]; } /* Wrap foo.c and foo.i files in a language specification to @@ -507,8 +540,14 @@ main (argc, argv) } /* Add `-lg++' if we haven't already done so. */ - if (library && !saw_math) - arglist[j++] = library; + if (library == 2) + arglist[j++] = "-lg++"; + if (library) + arglist[j++] = "-lstdc++"; + if (saw_math) + arglist[j++] = saw_math; + else if (library) + arglist[j++] = MATH_LIBRARY; arglist[j] = NULL; } @@ -527,15 +566,15 @@ main (argc, argv) fprintf (stderr, " %s", arglist[i]); fprintf (stderr, "\n"); } -#ifndef OS2 +#if !defined(OS2) && !defined (_WIN32) #ifdef __MSDOS__ run_dos (gcc, arglist); #else /* !__MSDOS__ */ if (execvp (gcc, arglist) < 0) pfatal_with_name (gcc); #endif /* __MSDOS__ */ -#else /* OS2 */ - if (spawnvp (gcc, arglist) < 0) +#else /* OS2 or _WIN32 */ + if (spawnvp (1, gcc, arglist) < 0) pfatal_with_name (gcc); #endif