CC recognizes how to compile each input file by suffixes in the file names.
Once it knows which kind of compilation to perform, the procedure for
compilation is specified by a string called a "spec". */
-\f
+
+
#include "config.h"
#include "system.h"
#include <signal.h>
-
#include "obstack.h"
#include "intl.h"
#include "prefix.h"
+#include "gcc.h"
#ifdef VMS
#define exit __posix_exit
static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
static char *build_search_list PROTO((struct path_prefix *, const char *, int));
static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
+static int access_check PROTO((const char *, int));
static char *find_a_file PROTO((struct path_prefix *, const char *, int));
static void add_prefix PROTO((struct path_prefix *, const char *,
const char *, int, int, int *));
static int check_live_switch PROTO((int, int));
static const char *handle_braces PROTO((const char *));
static char *save_string PROTO((const char *, int));
-extern int do_spec PROTO((const char *));
static int do_spec_1 PROTO((const char *, int, const char *));
static const char *find_file PROTO((const char *));
static int is_directory PROTO((const char *, const char *, int));
static void unused_prefix_warnings PROTO ((struct path_prefix *));
static void clear_args PROTO ((void));
static void fatal_error PROTO ((int));
-
-void fancy_abort PROTO((void)) ATTRIBUTE_NORETURN;
-
-/* Called before processing to change/add/remove arguments. */
-extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
- int *, char ***, int *));
-
-/* Called before linking. Returns 0 on success and -1 on failure. */
-extern int lang_specific_pre_link ();
-
-/* Number of extra output files that lang_specific_pre_link may generate. */
-extern int lang_specific_extra_outfiles;
\f
/* Specs are strings containing lines, each of which (if not blank)
is made up of a program name, and arguments separated by spaces.
#define MULTILIB_DEFAULTS { "" }
#endif
-static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
+static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
struct user_specs {
struct user_specs *next;
{"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
%{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
%{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
- %{aux-info*} %{Qn:-fno-ident}\
+ %{aux-info*} %{Qn:-fno-ident} -fpreprocessed\
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
%{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
%{!S:as %a %Y\
*argcp = newindex;
}
\f
-char *
-xstrerror(e)
- int e;
-{
-#ifdef HAVE_STRERROR
-
- return strerror(e);
-
-#else
-
- if (!e)
- return "errno = 0";
-
- if (e > 0 && e < sys_nerr)
- return sys_errlist[e];
-
- return "errno = ?";
-#endif
-}
-\f
static char *
skip_whitespace (p)
char *p;
#ifdef EXTRA_SPECS
extra_specs = (struct spec_list *)
- xmalloc (sizeof(struct spec_list) *
+ xcalloc (sizeof(struct spec_list),
(sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
- bzero ((PTR) extra_specs, sizeof(struct spec_list) *
- (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
{
{
/* Not found - make it */
sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
- sl->name = save_string (name, strlen (name));
+ sl->name = xstrdup (name);
sl->name_len = name_len;
sl->ptr_spec = &sl->ptr;
sl->alloc_p = 0;
old_spec = *(sl->ptr_spec);
*(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
? concat (old_spec, spec + 1, NULL_PTR)
- : save_string (spec, strlen (spec)));
+ : xstrdup (spec));
#ifdef DEBUG_SPECS
if (verbose_flag)
(n_compilers + 2) * sizeof (struct compiler)));
compilers[n_compilers].suffix = suffix;
- bzero ((char *) compilers[n_compilers].spec,
- sizeof compilers[n_compilers].spec);
+ memset (compilers[n_compilers].spec, 0,
+ sizeof compilers[n_compilers].spec);
compilers[n_compilers].spec[0] = spec;
n_compilers++;
- bzero ((char *) &compilers[n_compilers],
- sizeof compilers[n_compilers]);
+ memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
}
if (*suffix == 0)
int always_delete;
int fail_delete;
{
- register char *name;
- name = xmalloc (strlen (filename) + 1);
- strcpy (name, filename);
+ register char * const name = xstrdup (filename);
if (always_delete)
{
putenv (build_search_list (paths, env_var, 1));
}
\f
+/* Check whether NAME can be accessed in MODE. This is like access,
+ except that it never considers directories to be executable. */
+
+static int
+access_check (name, mode)
+ const char *name;
+ int mode;
+{
+ if (mode == X_OK)
+ {
+ struct stat st;
+
+ if (stat (name, &st) < 0
+ || S_ISDIR (st.st_mode))
+ return -1;
+ }
+
+ return access (name, mode);
+}
+
/* Search for NAME using the prefix list PREFIXES. MODE is passed to
access to check permissions.
Return 0 if not found, otherwise return its name, allocated with malloc. */
int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
#ifdef DEFAULT_ASSEMBLER
- if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
- name = DEFAULT_ASSEMBLER;
- len = strlen(name)+1;
- temp = xmalloc (len);
- strcpy (temp, name);
- return temp;
- }
+ if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
+ return xstrdup (DEFAULT_ASSEMBLER);
#endif
#ifdef DEFAULT_LINKER
- if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
- name = DEFAULT_LINKER;
- len = strlen(name)+1;
- temp = xmalloc (len);
- strcpy (temp, name);
- return temp;
- }
+ if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
+ return xstrdup (DEFAULT_LINKER);
#endif
if (machine_suffix)
strcat (temp, machine_suffix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, machine_suffix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcat (temp, just_machine_suffix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, just_machine_suffix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
/* Figure compiler version from version string. */
- compiler_version = temp1 =
- save_string (version_string, strlen (version_string));
+ compiler_version = temp1 = xstrdup (version_string);
+
for (; *temp1; ++temp1)
{
if (*temp1 == ' ')
translate_options (&argc, &argv);
/* Do language-specific adjustment/addition of flags. */
- lang_specific_driver (fatal, &argc, &argv, &added_libraries);
+ lang_specific_driver (&argc, &argv, &added_libraries);
/* Scan argv twice. Here, the first time, just count how many switches
there will be in their vector, and how many input files in theirs.
printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
- exit (0);
+ return (0);
}
if (print_file_name)
{
printf ("%s\n", find_file (print_file_name));
- exit (0);
+ return (0);
}
if (print_prog_name)
{
char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
printf ("%s\n", (newname ? newname : print_prog_name));
- exit (0);
+ return (0);
}
if (print_multi_lib)
{
print_multilib_info ();
- exit (0);
+ return (0);
}
if (print_multi_directory)
printf (".\n");
else
printf ("%s\n", multilib_dir);
- exit (0);
+ return (0);
}
if (print_help_list)
if (! verbose_flag)
{
printf ("\nFor bug reporting instructions, please see:\n");
- printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>.\n");
+ printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
- exit (0);
+ return (0);
}
/* We do not exit here. Instead we have created a fake input file
version_string, compiler_version);
if (n_infiles == 0)
- exit (0);
+ return (0);
}
if (n_infiles == added_libraries)
i = n_infiles;
i += lang_specific_extra_outfiles;
- outfiles = (const char **) xmalloc (i * sizeof (char *));
- bzero ((char *) outfiles, i * sizeof (char *));
+ outfiles = (const char **) xcalloc (i, sizeof (char *));
/* Record which files were specified explicitly as link input. */
- explicit_link_files = xmalloc (n_infiles);
- bzero (explicit_link_files, n_infiles);
+ explicit_link_files = xcalloc (1, n_infiles);
for (i = 0; (int)i < n_infiles; i++)
{
if (print_help_list)
{
printf ("\nFor bug reporting instructions, please see:\n");
- printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>\n");
+ printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>\n");
}
- exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
- /* NOTREACHED */
- return 0;
+ return (error_count > 0 ? (signal_count ? 2 : 1) : 0);
}
/* Find the proper compilation spec for the file name NAME,
language = cp->spec[0] + 1;
new = (struct compiler *) xmalloc (sizeof (struct compiler));
new->suffix = cp->suffix;
- bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
- (char *) new->spec, sizeof new->spec);
+ memcpy (new->spec,
+ lookup_compiler (NULL_PTR, 0, language)->spec,
+ sizeof new->spec);
return new;
}
return 0;
}
\f
-PTR
-xmalloc (size)
- size_t size;
-{
- register PTR value = (PTR) malloc (size);
- if (value == 0)
- fatal ("virtual memory exhausted");
- return value;
-}
-
-PTR
-xrealloc (old, size)
- PTR old;
- size_t size;
-{
- register PTR ptr;
- if (old)
- ptr = (PTR) realloc (old, size);
- else
- ptr = (PTR) malloc (size);
- if (ptr == 0)
- fatal ("virtual memory exhausted");
- return ptr;
-}
-
static char *
save_string (s, len)
const char *s;