Commit 48ff801b by Richard Kenner

Don't include sys/file.h for winnt; use process.h instead.

(concat): Now just concats two things; all callers changed.
(concat[346]): New functions.
(dir_separator_str): New variable.
(exec_prefixes, startfile_prefixes, include_prefixes): Renamed from same names
without plural; all users changed.
(find_a_file, process_command, do_spec_1): Use DIR_SEPARATOR.
(find_file, is_directory, main): Likewise.
(lookup_compiler): If OS/2, do case-independent search.
(fix_argv): New function on winnt.
(FIX_ARGV): New macro for some systems; use instead of argv.

From-SVN: r8184
parent 7cc322e3
...@@ -34,9 +34,14 @@ compilation is specified by a string called a "spec". */ ...@@ -34,9 +34,14 @@ compilation is specified by a string called a "spec". */
#include <ctype.h> #include <ctype.h>
#include <signal.h> #include <signal.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/file.h> /* May get R_OK, etc. on some systems. */
#include <errno.h> #include <errno.h>
#ifndef WINNT
#include <sys/file.h> /* May get R_OK, etc. on some systems. */
#else
#include <process.h>
#endif
#include "config.h" #include "config.h"
#include "obstack.h" #include "obstack.h"
#ifdef __STDC__ #ifdef __STDC__
...@@ -126,6 +131,12 @@ compilation is specified by a string called a "spec". */ ...@@ -126,6 +131,12 @@ compilation is specified by a string called a "spec". */
#define PATH_SEPARATOR ':' #define PATH_SEPARATOR ':'
#endif #endif
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
static char dir_separator_str[] = {DIR_SEPARATOR, 0};
#define obstack_chunk_alloc xmalloc #define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free #define obstack_chunk_free free
...@@ -234,7 +245,11 @@ static void choose_temp_base PROTO((void)); ...@@ -234,7 +245,11 @@ static void choose_temp_base PROTO((void));
static int check_live_switch PROTO((int, int)); static int check_live_switch PROTO((int, int));
static char *handle_braces PROTO((char *)); static char *handle_braces PROTO((char *));
static char *save_string PROTO((char *, int)); static char *save_string PROTO((char *, int));
static char *concat PROTO((char *, char *, char *)); static char *concat PROTO((char *, char *));
static char *concat3 PROTO((char *, char *, char *));
static char *concat4 PROTO((char *, char *, char *, char *));
static char *concat6 PROTO((char *, char *, char *, char *, char *, \
char *));
static int do_spec PROTO((char *)); static int do_spec PROTO((char *));
static int do_spec_1 PROTO((char *, int, char *)); static int do_spec_1 PROTO((char *, int, char *));
static char *find_file PROTO((char *)); static char *find_file PROTO((char *));
...@@ -325,7 +340,7 @@ or with constant text in a single argument. ...@@ -325,7 +340,7 @@ or with constant text in a single argument.
%A process ASM_FINAL_SPEC as a spec. A capital A is actually %A process ASM_FINAL_SPEC as a spec. A capital A is actually
used here. This can be used to run a post-processor after the used here. This can be used to run a post-processor after the
assembler has done it's job. assembler has done it's job.
%D Dump out a -L option for each directory in startfile_prefix. %D Dump out a -L option for each directory in startfile_prefixes.
If multilib_dir is set, extra entries are generated with it affixed. If multilib_dir is set, extra entries are generated with it affixed.
%l process LINK_SPEC as a spec. %l process LINK_SPEC as a spec.
%L process LIB_SPEC as a spec. %L process LIB_SPEC as a spec.
...@@ -937,8 +952,7 @@ translate_options (argcp, argvp) ...@@ -937,8 +952,7 @@ translate_options (argcp, argvp)
/* Store the translation as one argv elt or as two. */ /* Store the translation as one argv elt or as two. */
if (arg != 0 && index (arginfo, 'j') != 0) if (arg != 0 && index (arginfo, 'j') != 0)
newv[newindex++] = concat (option_map[j].equivalent, newv[newindex++] = concat (option_map[j].equivalent, arg);
arg, "");
else if (arg != 0) else if (arg != 0)
{ {
newv[newindex++] = option_map[j].equivalent; newv[newindex++] = option_map[j].equivalent;
...@@ -1178,7 +1192,7 @@ set_spec (name, spec) ...@@ -1178,7 +1192,7 @@ set_spec (name, spec)
old_spec = sl->spec; old_spec = sl->spec;
if (name && spec[0] == '+' && isspace (spec[1])) if (name && spec[0] == '+' && isspace (spec[1]))
sl->spec = concat (old_spec, spec + 1, ""); sl->spec = concat (old_spec, spec + 1);
else else
sl->spec = save_string (spec, strlen (spec)); sl->spec = save_string (spec, strlen (spec));
...@@ -1273,15 +1287,15 @@ struct path_prefix ...@@ -1273,15 +1287,15 @@ struct path_prefix
/* List of prefixes to try when looking for executables. */ /* List of prefixes to try when looking for executables. */
static struct path_prefix exec_prefix = { 0, 0, "exec" }; static struct path_prefix exec_prefixes = { 0, 0, "exec" };
/* List of prefixes to try when looking for startup (crt0) files. */ /* List of prefixes to try when looking for startup (crt0) files. */
static struct path_prefix startfile_prefix = { 0, 0, "startfile" }; static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
/* List of prefixes to try when looking for include files. */ /* List of prefixes to try when looking for include files. */
static struct path_prefix include_prefix = { 0, 0, "include" }; static struct path_prefix include_prefixes = { 0, 0, "include" };
/* Suffix to attach to directories searched for commands. /* Suffix to attach to directories searched for commands.
This looks like `MACHINE/VERSION/'. */ This looks like `MACHINE/VERSION/'. */
...@@ -1531,18 +1545,21 @@ choose_temp_base () ...@@ -1531,18 +1545,21 @@ choose_temp_base ()
base = choose_temp_base_try (P_tmpdir, base); base = choose_temp_base_try (P_tmpdir, base);
#endif #endif
base = choose_temp_base_try ("/usr/tmp", base); base = choose_temp_base_try (concat4 (dir_separator_str, "usr",
base = choose_temp_base_try ("/tmp", base); dir_separator_str, "tmp"),
base);
base = choose_temp_base_try (concat (dir_separator_str, "tmp"), base);
/* If all else fails, use the current directory! */ /* If all else fails, use the current directory! */
if (base == (char *)0) if (base == (char *)0) base = concat(".", dir_separator_str);
base = "./";
len = strlen (base); len = strlen (base);
temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1); temp_filename = xmalloc (len + strlen (concat (dir_separator_str,
"ccXXXXXX")) + 1);
strcpy (temp_filename, base); strcpy (temp_filename, base);
if (len > 0 && temp_filename[len-1] != '/') if (len > 0 && temp_filename[len-1] != '/'
temp_filename[len++] = '/'; && temp_filename[len-1] != DIR_SEPARATOR)
temp_filename[len++] = DIR_SEPARATOR;
strcpy (temp_filename + len, "ccXXXXXX"); strcpy (temp_filename + len, "ccXXXXXX");
mktemp (temp_filename); mktemp (temp_filename);
...@@ -1686,7 +1703,7 @@ find_a_file (pprefix, name, mode) ...@@ -1686,7 +1703,7 @@ find_a_file (pprefix, name, mode)
/* Determine the filename to execute (special case for absolute paths). */ /* Determine the filename to execute (special case for absolute paths). */
if (*name == '/') if (*name == '/' || *name == DIR_SEPARATOR)
{ {
if (access (name, mode)) if (access (name, mode))
{ {
...@@ -1906,7 +1923,6 @@ static int last_pipe_input; ...@@ -1906,7 +1923,6 @@ static int last_pipe_input;
NOT_LAST is nonzero if this is not the last subcommand NOT_LAST is nonzero if this is not the last subcommand
(i.e. its output should be piped to the next one.) */ (i.e. its output should be piped to the next one.) */
#ifndef OS2
#ifdef __MSDOS__ #ifdef __MSDOS__
#include <process.h> #include <process.h>
...@@ -1958,7 +1974,9 @@ pexecute (search_flag, program, argv, not_last) ...@@ -1958,7 +1974,9 @@ pexecute (search_flag, program, argv, not_last)
return i << 8; return i << 8;
} }
#else /* not __MSDOS__ */ #endif
#if !defined(__MSDOS__) && !defined(OS2) && !defined(WINNT)
static int static int
pexecute (search_flag, program, argv, not_last) pexecute (search_flag, program, argv, not_last)
...@@ -2048,8 +2066,54 @@ pexecute (search_flag, program, argv, not_last) ...@@ -2048,8 +2066,54 @@ pexecute (search_flag, program, argv, not_last)
} }
} }
#endif /* not __MSDOS__ */ #endif /* not __MSDOS__ and not OS2 */
#else /* not OS2 */
#if defined(OS2) || defined(WINNT)
#ifdef WINNT
char **
fix_argv (argvec)
char **argvec
{
int i;
for (i = 1; argvec[i] != 0; i++)
{
int len, j;
char *temp, *newtemp;
temp = argvec[i];
len = strlen (temp);
for (j = 0; j < len; j++)
{
if (temp[j] == '"')
{
newtemp = xmalloc (len + 2);
strncpy (newtemp, temp, j);
newtemp [j] = '\\';
strncpy (&newtemp [j+1], &temp [j], len-j);
newtemp [len+1] = 0;
free (temp);
temp = newtemp;
len++;
j++;
}
}
argvec[i] = temp;
}
return argvec;
}
#define FIX_ARGV(a) fix_argv(a)
#else
#define FIX_ARGV(a) a
#endif /* OS2 or WINNT */
static int static int
pexecute (search_flag, program, argv, not_last) pexecute (search_flag, program, argv, not_last)
...@@ -2058,9 +2122,10 @@ pexecute (search_flag, program, argv, not_last) ...@@ -2058,9 +2122,10 @@ pexecute (search_flag, program, argv, not_last)
char *argv[]; char *argv[];
int not_last; int not_last;
{ {
return (search_flag ? spawnv : spawnvp) (1, program, argv); return (search_flag ? spawnv : spawnvp) (1, program, FIX_ARGV (argv));
} }
#endif /* not OS2 */ #endif /* OS2 or WINNT */
/* Execute the command specified by the arguments on the current line of spec. /* Execute the command specified by the arguments on the current line of spec.
When using pipes, this includes several piped-together commands When using pipes, this includes several piped-together commands
...@@ -2098,7 +2163,7 @@ execute () ...@@ -2098,7 +2163,7 @@ execute ()
commands[0].prog = argbuf[0]; /* first command. */ commands[0].prog = argbuf[0]; /* first command. */
commands[0].argv = &argbuf[0]; commands[0].argv = &argbuf[0];
string = find_a_file (&exec_prefix, commands[0].prog, X_OK); string = find_a_file (&exec_prefixes, commands[0].prog, X_OK);
if (string) if (string)
commands[0].argv[0] = string; commands[0].argv[0] = string;
...@@ -2111,7 +2176,7 @@ execute () ...@@ -2111,7 +2176,7 @@ execute ()
argbuf[i] = 0; /* termination of command args. */ argbuf[i] = 0; /* termination of command args. */
commands[n_commands].prog = argbuf[i + 1]; commands[n_commands].prog = argbuf[i + 1];
commands[n_commands].argv = &argbuf[i + 1]; commands[n_commands].argv = &argbuf[i + 1];
string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK); string = find_a_file (&exec_prefixes, commands[n_commands].prog, X_OK);
if (string) if (string)
commands[n_commands].argv[0] = string; commands[n_commands].argv[0] = string;
n_commands++; n_commands++;
...@@ -2181,8 +2246,12 @@ execute () ...@@ -2181,8 +2246,12 @@ execute ()
#ifdef __MSDOS__ #ifdef __MSDOS__
status = pid = commands[i].pid; status = pid = commands[i].pid;
#else #else
#ifdef WINNT
pid = cwait (&status, commands[i].pid, WAIT_CHILD);
#else
pid = wait (&status); pid = wait (&status);
#endif #endif
#endif
if (pid < 0) if (pid < 0)
abort (); abort ();
...@@ -2280,8 +2349,8 @@ process_command (argc, argv) ...@@ -2280,8 +2349,8 @@ process_command (argc, argv)
if (gcc_exec_prefix) if (gcc_exec_prefix)
{ {
add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR); add_prefix (&exec_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, gcc_exec_prefix, 0, 0, NULL_PTR);
} }
/* COMPILER_PATH and LIBRARY_PATH have values /* COMPILER_PATH and LIBRARY_PATH have values
...@@ -2300,17 +2369,15 @@ process_command (argc, argv) ...@@ -2300,17 +2369,15 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
strcpy (nstore, "./"); nstore[endp-startp] = DIR_SEPARATOR;
}
else if (endp[-1] != '/')
{
nstore[endp-startp] = '/';
nstore[endp-startp+1] = 0; nstore[endp-startp+1] = 0;
} }
else else
nstore[endp-startp] = 0; nstore[endp-startp] = 0;
add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR); add_prefix (&exec_prefixes, nstore, 0, 0, NULL_PTR);
if (*endp == 0) if (*endp == 0)
break; break;
endp = startp = endp + 1; endp = startp = endp + 1;
...@@ -2333,17 +2400,15 @@ process_command (argc, argv) ...@@ -2333,17 +2400,15 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
strcpy (nstore, "./"); nstore[endp-startp] = DIR_SEPARATOR;
}
else if (endp[-1] != '/')
{
nstore[endp-startp] = '/';
nstore[endp-startp+1] = 0; nstore[endp-startp+1] = 0;
} }
else else
nstore[endp-startp] = 0; nstore[endp-startp] = 0;
add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
if (*endp == 0) if (*endp == 0)
break; break;
endp = startp = endp + 1; endp = startp = endp + 1;
...@@ -2367,17 +2432,15 @@ process_command (argc, argv) ...@@ -2367,17 +2432,15 @@ process_command (argc, argv)
{ {
strncpy (nstore, startp, endp-startp); strncpy (nstore, startp, endp-startp);
if (endp == startp) if (endp == startp)
strcpy (nstore, concat (".", dir_separator_str));
else if (endp[-1] != '/' && endp[-1] != DIR_SEPARATOR)
{ {
strcpy (nstore, "./"); nstore[endp-startp] = DIR_SEPARATOR;
}
else if (endp[-1] != '/')
{
nstore[endp-startp] = '/';
nstore[endp-startp+1] = 0; nstore[endp-startp+1] = 0;
} }
else else
nstore[endp-startp] = 0; nstore[endp-startp] = 0;
add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, nstore, 0, 0, NULL_PTR);
if (*endp == 0) if (*endp == 0)
break; break;
endp = startp = endp + 1; endp = startp = endp + 1;
...@@ -2572,22 +2635,26 @@ process_command (argc, argv) ...@@ -2572,22 +2635,26 @@ process_command (argc, argv)
value = argv[++i]; value = argv[++i];
else else
value = p + 1; value = p + 1;
add_prefix (&exec_prefix, value, 1, 0, temp); add_prefix (&exec_prefixes, value, 1, 0, temp);
add_prefix (&startfile_prefix, value, 1, 0, temp); add_prefix (&startfile_prefixes, value, 1, 0, temp);
add_prefix (&include_prefix, concat (value, "include", ""), add_prefix (&include_prefixes, concat (value, "include", ""),
1, 0, 0); 1, 0, 0);
/* As a kludge, if the arg is "[foo/]stageN/", just add /* As a kludge, if the arg is "[foo/]stageN/", just add
"[foo/]include" to the include prefix. */ "[foo/]include" to the include prefix. */
{ {
int len = strlen (value); int len = strlen (value);
if ((len == 7 || (len > 7 && value[len - 8] == '/')) if ((len == 7
|| (len > 7
&& (value[len - 8] == '/'
|| value[len - 8] == DIR_SEPARATOR)))
&& strncmp (value + len - 7, "stage", 5) == 0 && strncmp (value + len - 7, "stage", 5) == 0
&& isdigit (value[len - 2]) && isdigit (value[len - 2])
&& value[len - 1] == '/') && (value[len - 1] == '/'
|| value[len - 1] == DIR_SEPARATOR))
{ {
if (len == 7) if (len == 7)
add_prefix (&include_prefix, "include", 1, 0, 0); add_prefix (&include_prefixes, "include", 1, 0, 0);
else else
{ {
char *string = xmalloc (len + 1); char *string = xmalloc (len + 1);
...@@ -2645,44 +2712,52 @@ process_command (argc, argv) ...@@ -2645,44 +2712,52 @@ process_command (argc, argv)
(such as cpp) rather than those of the host system. */ (such as cpp) rather than those of the host system. */
/* Use 2 as fourth arg meaning try just the machine as a suffix, /* Use 2 as fourth arg meaning try just the machine as a suffix,
as well as trying the machine and the version. */ as well as trying the machine and the version. */
add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR); #ifndef OS2
add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR); add_prefix (&exec_prefixes, standard_exec_prefix, 0, 2, NULL_PTR);
add_prefix (&exec_prefixes, standard_exec_prefix_1, 0, 2, NULL_PTR);
#endif
add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR); add_prefix (&startfile_prefixes, standard_exec_prefix, 0, 1, NULL_PTR);
add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR); add_prefix (&startfile_prefixes, standard_exec_prefix_1, 0, 1, NULL_PTR);
tooldir_prefix = concat (tooldir_base_prefix, spec_machine, "/"); tooldir_prefix = concat3 (tooldir_base_prefix, spec_machine,
dir_separator_str);
/* If tooldir is relative, base it on exec_prefix. A relative /* If tooldir is relative, base it on exec_prefixes. A relative
tooldir lets us move the installed tree as a unit. tooldir lets us move the installed tree as a unit.
If GCC_EXEC_PREFIX is defined, then we want to add two relative If GCC_EXEC_PREFIX is defined, then we want to add two relative
directories, so that we can search both the user specified directory directories, so that we can search both the user specified directory
and the standard place. */ and the standard place. */
if (*tooldir_prefix != '/') if (*tooldir_prefix != '/' && *tooldir_prefix != DIR_SEPARATOR)
{ {
if (gcc_exec_prefix) if (gcc_exec_prefix)
{ {
char *gcc_exec_tooldir_prefix char *gcc_exec_tooldir_prefix
= concat (concat (gcc_exec_prefix, spec_machine, "/"), = concat6 (gcc_exec_prefix, spec_machine, dir_separator_str,
concat (spec_version, "/", tooldir_prefix), spec_version, dir_separator_str, tooldir_prefix);
"");
add_prefix (&exec_prefix, concat (gcc_exec_tooldir_prefix, "bin", "/"), add_prefix (&exec_prefixes,
concat3 (gcc_exec_tooldir_prefix, "bin",
dir_separator_str),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefix, concat (gcc_exec_tooldir_prefix, "lib", "/"), add_prefix (&startfile_prefixes,
concat3 (gcc_exec_tooldir_prefix, "lib",
dir_separator_str),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
} }
tooldir_prefix = concat (concat (standard_exec_prefix, spec_machine, "/"), tooldir_prefix = concat6 (standard_exec_prefix, spec_machine,
concat (spec_version, "/", tooldir_prefix), dir_separator_str, spec_version,
""); dir_separator_str, tooldir_prefix);
} }
add_prefix (&exec_prefix, concat (tooldir_prefix, "bin", "/"), add_prefix (&exec_prefixes,
concat3 (tooldir_prefix, "bin", dir_separator_str),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefix, concat (tooldir_prefix, "lib", "/"), add_prefix (&startfile_prefixes,
concat3 (tooldir_prefix, "lib", dir_separator_str),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
/* More prefixes are enabled in main, after we read the specs file /* More prefixes are enabled in main, after we read the specs file
...@@ -2837,9 +2912,9 @@ process_command (argc, argv) ...@@ -2837,9 +2912,9 @@ process_command (argc, argv)
+ strlen (spec_machine) + 3); + strlen (spec_machine) + 3);
strcpy (temp, gcc_exec_prefix); strcpy (temp, gcc_exec_prefix);
strcat (temp, spec_machine); strcat (temp, spec_machine);
strcat (temp, "/"); strcat (temp, dir_separator_str);
strcat (temp, spec_version); strcat (temp, spec_version);
strcat (temp, "/"); strcat (temp, dir_separator_str);
gcc_exec_prefix = temp; gcc_exec_prefix = temp;
} }
} }
...@@ -3051,7 +3126,7 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3051,7 +3126,7 @@ do_spec_1 (spec, inswitch, soft_matched_part)
that we search for startfiles. */ that we search for startfiles. */
case 'D': case 'D':
{ {
struct prefix_list *pl = startfile_prefix.plist; struct prefix_list *pl = startfile_prefixes.plist;
int bufsize = 100; int bufsize = 100;
char *buffer = (char *) xmalloc (bufsize); char *buffer = (char *) xmalloc (bufsize);
int idx; int idx;
...@@ -3064,7 +3139,7 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3064,7 +3139,7 @@ do_spec_1 (spec, inswitch, soft_matched_part)
/* Relative directories always come from -B, /* Relative directories always come from -B,
and it is better not to use them for searching and it is better not to use them for searching
at run time. In particular, stage1 loses */ at run time. In particular, stage1 loses */
if (pl->prefix[0] != '/') if (pl->prefix[0] != '/' && pl->prefix[0] != DIR_SEPARATOR)
continue; continue;
#endif #endif
/* Try subdirectory if there is one. */ /* Try subdirectory if there is one. */
...@@ -3121,7 +3196,8 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3121,7 +3196,8 @@ do_spec_1 (spec, inswitch, soft_matched_part)
buffer = (char *) xrealloc (buffer, bufsize); buffer = (char *) xrealloc (buffer, bufsize);
strcpy (buffer, machine_suffix); strcpy (buffer, machine_suffix);
idx = strlen (buffer); idx = strlen (buffer);
if (buffer[idx - 1] == '/') if (buffer[idx - 1] == '/'
|| buffer[idx - 1] == DIR_SEPARATOR)
buffer[idx - 1] = 0; buffer[idx - 1] = 0;
do_spec_1 (buffer, 1, NULL_PTR); do_spec_1 (buffer, 1, NULL_PTR);
/* Make this a separate argument. */ /* Make this a separate argument. */
...@@ -3142,7 +3218,8 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3142,7 +3218,8 @@ do_spec_1 (spec, inswitch, soft_matched_part)
buffer = (char *) xrealloc (buffer, bufsize); buffer = (char *) xrealloc (buffer, bufsize);
strcpy (buffer, pl->prefix); strcpy (buffer, pl->prefix);
idx = strlen (buffer); idx = strlen (buffer);
if (buffer[idx - 1] == '/') if (buffer[idx - 1] == '/'
|| buffer[idx - 1] == DIR_SEPARATOR)
buffer[idx - 1] = 0; buffer[idx - 1] = 0;
do_spec_1 (buffer, 1, NULL_PTR); do_spec_1 (buffer, 1, NULL_PTR);
/* Make this a separate argument. */ /* Make this a separate argument. */
...@@ -3240,7 +3317,7 @@ do_spec_1 (spec, inswitch, soft_matched_part) ...@@ -3240,7 +3317,7 @@ do_spec_1 (spec, inswitch, soft_matched_part)
case 'I': case 'I':
{ {
struct prefix_list *pl = include_prefix.plist; struct prefix_list *pl = include_prefixes.plist;
if (gcc_exec_prefix) if (gcc_exec_prefix)
{ {
...@@ -4020,10 +4097,10 @@ find_file (name) ...@@ -4020,10 +4097,10 @@ find_file (name)
try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2); try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
strcpy (try, multilib_dir); strcpy (try, multilib_dir);
strcat (try, "/"); strcat (try, dir_separator_str);
strcat (try, name); strcat (try, name);
newname = find_a_file (&startfile_prefix, try, R_OK); newname = find_a_file (&startfile_prefixes, try, R_OK);
/* If we don't find it in the multi library dir, then fall /* If we don't find it in the multi library dir, then fall
through and look for it in the normal places. */ through and look for it in the normal places. */
...@@ -4031,7 +4108,7 @@ find_file (name) ...@@ -4031,7 +4108,7 @@ find_file (name)
return newname; return newname;
} }
newname = find_a_file (&startfile_prefix, name, R_OK); newname = find_a_file (&startfile_prefixes, name, R_OK);
return newname ? newname : name; return newname ? newname : name;
} }
...@@ -4063,15 +4140,20 @@ is_directory (path1, path2, linker) ...@@ -4063,15 +4140,20 @@ is_directory (path1, path2, linker)
bcopy (path1, path, len1); bcopy (path1, path, len1);
bcopy (path2, path + len1, len2); bcopy (path2, path + len1, len2);
cp = path + len1 + len2; cp = path + len1 + len2;
if (cp[-1] != '/') if (cp[-1] != '/' && cp[-1] != DIR_SEPARATOR)
*cp++ = '/'; *cp++ = DIR_SEPARATOR;
*cp++ = '.'; *cp++ = '.';
*cp = '\0'; *cp = '\0';
/* Exclude directories that the linker is known to search. */ /* Exclude directories that the linker is known to search. */
if (linker if (linker
&& ((cp - path == 6 && strcmp (path, "/lib/.") == 0) && ((cp - path == 6
|| (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0))) && strcmp (path, concat4 (dir_separator_str, "lib",
dir_separator_str, ".")) == 0)
|| (cp - path == 10
&& strcmp (path, concat6 (dir_separator_str, "usr",
dir_separator_str, "lib",
dir_separator_str, ".")) == 0)))
return 0; return 0;
return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode)); return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
...@@ -4105,7 +4187,7 @@ main (argc, argv) ...@@ -4105,7 +4187,7 @@ main (argc, argv)
char *p; char *p;
p = argv[0] + strlen (argv[0]); p = argv[0] + strlen (argv[0]);
while (p != argv[0] && p[-1] != '/') --p; while (p != argv[0] && p[-1] != '/' && p[-1] != DIR_SEPARATOR) --p;
programname = p; programname = p;
if (signal (SIGINT, SIG_IGN) != SIG_IGN) if (signal (SIGINT, SIG_IGN) != SIG_IGN)
...@@ -4154,10 +4236,11 @@ main (argc, argv) ...@@ -4154,10 +4236,11 @@ main (argc, argv)
/* Read specs from a file if there is one. */ /* Read specs from a file if there is one. */
machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", "")); machine_suffix = concat4 (spec_machine, dir_separator_str,
just_machine_suffix = concat (spec_machine, "/", ""); spec_version, dir_separator_str);
just_machine_suffix = concat (spec_machine, dir_separator_str);
specs_file = find_a_file (&startfile_prefix, "specs", R_OK); specs_file = find_a_file (&startfile_prefixes, "specs", R_OK);
/* Read the specs file unless it is a default one. */ /* Read the specs file unless it is a default one. */
if (specs_file != 0 && strcmp (specs_file, "specs")) if (specs_file != 0 && strcmp (specs_file, "specs"))
read_specs (specs_file); read_specs (specs_file);
...@@ -4169,46 +4252,45 @@ main (argc, argv) ...@@ -4169,46 +4252,45 @@ main (argc, argv)
if (!cross_compile) if (!cross_compile)
{ {
#ifdef MD_EXEC_PREFIX #ifdef MD_EXEC_PREFIX
add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR); add_prefix (&exec_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, md_exec_prefix, 0, 0, NULL_PTR);
#endif #endif
#ifdef MD_STARTFILE_PREFIX #ifdef MD_STARTFILE_PREFIX
add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, md_startfile_prefix, 0, 0, NULL_PTR);
#endif #endif
#ifdef MD_STARTFILE_PREFIX_1 #ifdef MD_STARTFILE_PREFIX_1
add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR); add_prefix (&startfile_prefixes, md_startfile_prefix_1, 0, 0, NULL_PTR);
#endif #endif
/* If standard_startfile_prefix is relative, base it on /* If standard_startfile_prefix is relative, base it on
standard_exec_prefix. This lets us move the installed tree standard_exec_prefix. This lets us move the installed tree
as a unit. If GCC_EXEC_PREFIX is defined, base as a unit. If GCC_EXEC_PREFIX is defined, base
standard_startfile_prefix on that as well. */ standard_startfile_prefix on that as well. */
if (*standard_startfile_prefix == '/') if (*standard_startfile_prefix == '/'
add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0, || *standard_startfile_prefix == DIR_SEPARATOR)
add_prefix (&startfile_prefixes, standard_startfile_prefix, 0, 0,
NULL_PTR); NULL_PTR);
else else
{ {
if (gcc_exec_prefix) if (gcc_exec_prefix)
add_prefix (&startfile_prefix, add_prefix (&startfile_prefixes,
concat (gcc_exec_prefix, concat (gcc_exec_prefix, standard_startfile_prefix),
standard_startfile_prefix,
""),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
add_prefix (&startfile_prefix, add_prefix (&startfile_prefixes,
concat (standard_exec_prefix, concat3 (standard_exec_prefix,
machine_suffix, machine_suffix,
standard_startfile_prefix), standard_startfile_prefix),
0, 0, NULL_PTR); 0, 0, NULL_PTR);
} }
add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0, add_prefix (&startfile_prefixes, standard_startfile_prefix_1, 0, 0,
NULL_PTR); NULL_PTR);
add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0, add_prefix (&startfile_prefixes, standard_startfile_prefix_2, 0, 0,
NULL_PTR); NULL_PTR);
#if 0 /* Can cause surprises, and one can use -B./ instead. */ #if 0 /* Can cause surprises, and one can use -B./ instead. */
add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR); add_prefix (&startfile_prefixes, "./", 0, 1, NULL_PTR);
#endif #endif
} }
...@@ -4237,7 +4319,7 @@ main (argc, argv) ...@@ -4237,7 +4319,7 @@ main (argc, argv)
if (print_prog_name) if (print_prog_name)
{ {
char *newname = find_a_file (&exec_prefix, print_prog_name, X_OK); char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
printf ("%s\n", (newname ? newname : print_prog_name)); printf ("%s\n", (newname ? newname : print_prog_name));
exit (0); exit (0);
} }
...@@ -4307,7 +4389,7 @@ main (argc, argv) ...@@ -4307,7 +4389,7 @@ main (argc, argv)
input_basename = input_filename; input_basename = input_filename;
for (p = input_filename; *p; p++) for (p = input_filename; *p; p++)
if (*p == '/') if (*p == '/' || *p == DIR_SEPARATOR)
input_basename = p + 1; input_basename = p + 1;
/* Find a suffix starting with the last period, /* Find a suffix starting with the last period,
...@@ -4372,8 +4454,8 @@ main (argc, argv) ...@@ -4372,8 +4454,8 @@ main (argc, argv)
/* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
for collect. */ for collect. */
putenv_from_prefixes (&exec_prefix, "COMPILER_PATH="); putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH=");
putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH="); putenv_from_prefixes (&startfile_prefixes, "LIBRARY_PATH=");
/* Build COLLECT_GCC_OPTIONS to have all of the options specified to /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
the compiler. */ the compiler. */
...@@ -4408,8 +4490,8 @@ main (argc, argv) ...@@ -4408,8 +4490,8 @@ main (argc, argv)
} }
/* Warn if a -B option was specified but the prefix was never used. */ /* Warn if a -B option was specified but the prefix was never used. */
unused_prefix_warnings (&exec_prefix); unused_prefix_warnings (&exec_prefixes);
unused_prefix_warnings (&startfile_prefix); unused_prefix_warnings (&startfile_prefixes);
/* If options said don't run linker, /* If options said don't run linker,
complain about input files to be given to the linker. */ complain about input files to be given to the linker. */
...@@ -4466,8 +4548,16 @@ lookup_compiler (name, length, language) ...@@ -4466,8 +4548,16 @@ lookup_compiler (name, length, language)
|| ||
(strlen (cp->suffix) < length (strlen (cp->suffix) < length
/* See if the suffix matches the end of NAME. */ /* See if the suffix matches the end of NAME. */
#ifdef OS2
&& (!strcmp (cp->suffix,
name + length - strlen (cp->suffix))
|| !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
&& !strcasecmp (cp->suffix,
name + length - strlen (cp->suffix)))))
#else
&& !strcmp (cp->suffix, && !strcmp (cp->suffix,
name + length - strlen (cp->suffix)))) name + length - strlen (cp->suffix))))
#endif
{ {
if (cp->spec[0][0] == '@') if (cp->spec[0][0] == '@')
{ {
...@@ -4512,24 +4602,45 @@ xrealloc (ptr, size) ...@@ -4512,24 +4602,45 @@ xrealloc (ptr, size)
return value; return value;
} }
/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ /* Return a newly-allocated string whose contents concatenate those of s1, s2 */
static char * static char *
concat (s1, s2, s3) concat (s1, s2)
char *s1, *s2, *s3; char *s1, *s2;
{ {
int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); int len1 = strlen (s1);
char *result = xmalloc (len1 + len2 + len3 + 1); int len2 = strlen (s2);
char *result = xmalloc (len1 + len2 + 1);
strcpy (result, s1); strcpy (result, s1);
strcpy (result + len1, s2); strcpy (result + len1, s2);
strcpy (result + len1 + len2, s3); *(result + len1 + len2) = 0;
*(result + len1 + len2 + len3) = 0;
return result; return result;
} }
static char * static char *
concat3 (s1, s2, s3)
char *s1, *s2, *s3;
{
return concat (concat (s1, s2), s3);
}
static char *
concat4 (s1, s2, s3, s4)
char *s1, *s2, *s3, *s4;
{
return concat (concat (s1, s2), concat (s3, s4));
}
static char *
concat6 (s1, s2, s3, s4, s5, s6)
char *s1, *s2, *s3, *s4, *s5, *s6;
{
return concat3 (concat (s1, s2), concat (s3, s4), concat (s5, s6));
}
static char *
save_string (s, len) save_string (s, len)
char *s; char *s;
int len; int len;
...@@ -4548,7 +4659,7 @@ pfatal_with_name (name) ...@@ -4548,7 +4659,7 @@ pfatal_with_name (name)
char *s; char *s;
if (errno < sys_nerr) if (errno < sys_nerr)
s = concat ("%s: ", sys_errlist[errno], ""); s = concat ("%s: ", sys_errlist[errno]);
else else
s = "cannot open %s"; s = "cannot open %s";
fatal (s, name); fatal (s, name);
...@@ -4561,7 +4672,7 @@ perror_with_name (name) ...@@ -4561,7 +4672,7 @@ perror_with_name (name)
char *s; char *s;
if (errno < sys_nerr) if (errno < sys_nerr)
s = concat ("%s: ", sys_errlist[errno], ""); s = concat ("%s: ", sys_errlist[errno]);
else else
s = "cannot open %s"; s = "cannot open %s";
error (s, name); error (s, name);
...@@ -4574,8 +4685,7 @@ perror_exec (name) ...@@ -4574,8 +4685,7 @@ perror_exec (name)
char *s; char *s;
if (errno < sys_nerr) if (errno < sys_nerr)
s = concat ("installation problem, cannot exec %s: ", s = concat ("installation problem, cannot exec %s: ", sys_errlist[errno]);
sys_errlist[errno], "");
else else
s = "installation problem, cannot exec %s"; s = "installation problem, cannot exec %s";
error (s, name); error (s, name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment