summaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c407
1 files changed, 12 insertions, 395 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index b459a928e34..83bfbb9ee6b 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -30,44 +30,6 @@ 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". */
-/* A Short Introduction to Adding a Command-Line Option.
-
- Before adding a command-line option, consider if it is really
- necessary. Each additional command-line option adds complexity and
- is difficult to remove in subsequent versions.
-
- In the following, consider adding the command-line argument
- `--bar'.
-
- 1. Each command-line option is specified in the specs file. The
- notation is described below in the comment entitled "The Specs
- Language". Read it.
-
- 2. In this file, add an entry to "option_map" equating the long
- `--' argument version and any shorter, single letter version. Read
- the comments in the declaration of "struct option_map" for an
- explanation. Do not omit the first `-'.
-
- 3. Look in the "specs" file to determine which program or option
- list should be given the argument, e.g., "cc1_options". Add the
- appropriate syntax for the shorter option version to the
- corresponding "const char *" entry in this file. Omit the first
- `-' from the option. For example, use `-bar', rather than `--bar'.
-
- 4. If the argument takes an argument, e.g., `--baz argument1',
- modify either DEFAULT_SWITCH_TAKES_ARG or
- DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h. Omit the first `-'
- from `--baz'.
-
- 5. Document the option in this file's display_help(). If the
- option is passed to a subprogram, modify its corresponding
- function, e.g., cppinit.c:print_help() or toplev.c:display_help(),
- instead.
-
- 6. Compile and test. Make sure that your new specs file is being
- read. For example, use a debugger to investigate the value of
- "specs_file" in main(). */
-
#include "config.h"
#include "system.h"
#include "coretypes.h"
@@ -263,7 +225,6 @@ static void add_prefix (struct path_prefix *, const char *, const char *,
int, int, int);
static void add_sysrooted_prefix (struct path_prefix *, const char *,
const char *, int, int, int);
-static void translate_options (int *, const char *const **);
static char *skip_whitespace (char *);
static void delete_if_ordinary (const char *);
static void delete_temp_files (void);
@@ -802,9 +763,10 @@ static const char *cc1_options =
%{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
%{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
%{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
- %{Qn:-fno-ident} %{--help:--help}\
- %{--target-help:--target-help}\
- %{--help=*:--help=%(VALUE)}\
+ %{Qn:-fno-ident} %{-help:--help}\
+ %{-target-help:--target-help}\
+ %{-version:--version}\
+ %{-help=*:--help=%*}\
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
%{fsyntax-only:-o %j} %{-param*}\
%{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
@@ -1042,341 +1004,6 @@ static char **assembler_options;
static int n_preprocessor_options;
static char **preprocessor_options;
-/* Define how to map long options into short ones. */
-
-/* This structure describes one mapping. */
-struct option_map
-{
- /* The long option's name. */
- const char *const name;
- /* The equivalent short option. */
- const char *const equivalent;
- /* Argument info. A string of flag chars; NULL equals no options.
- a => argument required.
- o => argument optional.
- j => join argument to equivalent, making one word.
- * => require other text after NAME as an argument. */
- const char *const arg_info;
-};
-
-/* This is the table of mappings. Mappings are tried sequentially
- for each option encountered; the first one that matches, wins. */
-
-static const struct option_map option_map[] =
- {
- {"--all-warnings", "-Wall", 0},
- {"--ansi", "-ansi", 0},
- {"--assemble", "-S", 0},
- {"--assert", "-A", "a"},
- {"--classpath", "-fclasspath=", "aj"},
- {"--bootclasspath", "-fbootclasspath=", "aj"},
- {"--CLASSPATH", "-fclasspath=", "aj"},
- {"--comments", "-C", 0},
- {"--comments-in-macros", "-CC", 0},
- {"--compile", "-c", 0},
- {"--debug", "-g", "oj"},
- {"--define-macro", "-D", "aj"},
- {"--dependencies", "-M", 0},
- {"--dump", "-d", "aj"},
- {"--dumpbase", "-dumpbase", "a"},
- {"--dumpdir", "-dumpdir", "a"},
- {"--encoding", "-fencoding=", "aj"},
- {"--entry", "-e", 0},
- {"--extra-warnings", "-W", 0},
- {"--extdirs", "-fextdirs=", "aj"},
- {"--for-assembler", "-Wa", "a"},
- {"--for-linker", "-Xlinker", "a"},
- {"--force-link", "-u", "a"},
- {"--coverage", "-coverage", 0},
- {"--imacros", "-imacros", "a"},
- {"--include", "-include", "a"},
- {"--include-barrier", "-I-", 0},
- {"--include-directory", "-I", "aj"},
- {"--include-directory-after", "-idirafter", "a"},
- {"--include-prefix", "-iprefix", "a"},
- {"--include-with-prefix", "-iwithprefix", "a"},
- {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
- {"--include-with-prefix-after", "-iwithprefix", "a"},
- {"--language", "-x", "a"},
- {"--library-directory", "-L", "a"},
- {"--machine", "-m", "aj"},
- {"--machine-", "-m", "*j"},
- {"--no-canonical-prefixes", "-no-canonical-prefixes", 0},
- {"--no-integrated-cpp", "-no-integrated-cpp", 0},
- {"--no-line-commands", "-P", 0},
- {"--no-precompiled-includes", "-noprecomp", 0},
- {"--no-standard-includes", "-nostdinc", 0},
- {"--no-standard-libraries", "-nostdlib", 0},
- {"--no-warnings", "-w", 0},
- {"--optimize", "-O", "oj"},
- {"--output", "-o", "a"},
- {"--output-class-directory", "-foutput-class-dir=", "ja"},
- {"--param", "--param", "a"},
- {"--pass-exit-codes", "-pass-exit-codes", 0},
- {"--pedantic", "-pedantic", 0},
- {"--pedantic-errors", "-pedantic-errors", 0},
- {"--pie", "-pie", 0},
- {"--pipe", "-pipe", 0},
- {"--prefix", "-B", "a"},
- {"--preprocess", "-E", 0},
- {"--print-search-dirs", "-print-search-dirs", 0},
- {"--print-file-name", "-print-file-name=", "aj"},
- {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
- {"--print-missing-file-dependencies", "-MG", 0},
- {"--print-multi-lib", "-print-multi-lib", 0},
- {"--print-multi-directory", "-print-multi-directory", 0},
- {"--print-multi-os-directory", "-print-multi-os-directory", 0},
- {"--print-prog-name", "-print-prog-name=", "aj"},
- {"--print-sysroot", "-print-sysroot", 0},
- {"--print-sysroot-headers-suffix", "-print-sysroot-headers-suffix", 0},
- {"--profile", "-p", 0},
- {"--resource", "-fcompile-resource=", "aj"},
- {"--save-temps", "-save-temps", 0},
- {"--shared", "-shared", 0},
- {"--specs", "-specs=", "aj"},
- {"--static", "-static", 0},
- {"--std", "-std=", "aj"},
- {"--symbolic", "-symbolic", 0},
- {"--sysroot", "--sysroot=", "aj"},
- {"--time", "-time", 0},
- {"--trace-includes", "-H", 0},
- {"--traditional", "-traditional", 0},
- {"--traditional-cpp", "-traditional-cpp", 0},
- {"--trigraphs", "-trigraphs", 0},
- {"--undefine-macro", "-U", "aj"},
- {"--user-dependencies", "-MM", 0},
- {"--verbose", "-v", 0},
- {"--warn-", "-W", "*j"},
- {"--write-dependencies", "-MD", 0},
- {"--write-user-dependencies", "-MMD", 0},
- {"--", "-f", "*j"}
- };
-
-
-#ifdef TARGET_OPTION_TRANSLATE_TABLE
-static const struct {
- const char *const option_found;
- const char *const replacements;
-} target_option_translations[] =
-{
- TARGET_OPTION_TRANSLATE_TABLE,
- { 0, 0 }
-};
-#endif
-
-/* Translate the options described by *ARGCP and *ARGVP.
- Make a new vector and store it back in *ARGVP,
- and store its length in *ARGCP. */
-
-static void
-translate_options (int *argcp, const char *const **argvp)
-{
- int i;
- int argc = *argcp;
- const char *const *argv = *argvp;
- int newvsize = (argc + 2) * 2 * sizeof (const char *);
- const char **newv = XNEWVAR (const char *, newvsize);
- int newindex = 0;
-
- i = 0;
- newv[newindex++] = argv[i++];
-
- while (i < argc)
- {
-#ifdef TARGET_OPTION_TRANSLATE_TABLE
- int tott_idx;
-
- for (tott_idx = 0;
- target_option_translations[tott_idx].option_found;
- tott_idx++)
- {
- if (strcmp (target_option_translations[tott_idx].option_found,
- argv[i]) == 0)
- {
- int spaces = 1;
- const char *sp;
- char *np;
-
- for (sp = target_option_translations[tott_idx].replacements;
- *sp; sp++)
- {
- if (*sp == ' ')
- spaces ++;
- }
-
- newvsize += spaces * sizeof (const char *);
- newv = XRESIZEVAR (const char *, newv, newvsize);
-
- sp = target_option_translations[tott_idx].replacements;
- np = xstrdup (sp);
-
- while (1)
- {
- while (*np == ' ')
- np++;
- if (*np == 0)
- break;
- newv[newindex++] = np;
- while (*np != ' ' && *np)
- np++;
- if (*np == 0)
- break;
- *np++ = 0;
- }
-
- i ++;
- break;
- }
- }
- if (target_option_translations[tott_idx].option_found)
- continue;
-#endif
-
- /* Translate -- options. */
- if (argv[i][0] == '-' && argv[i][1] == '-')
- {
- size_t j;
- /* Find a mapping that applies to this option. */
- for (j = 0; j < ARRAY_SIZE (option_map); j++)
- {
- size_t optlen = strlen (option_map[j].name);
- size_t arglen = strlen (argv[i]);
- size_t complen = arglen > optlen ? optlen : arglen;
- const char *arginfo = option_map[j].arg_info;
-
- if (arginfo == 0)
- arginfo = "";
-
- if (!strncmp (argv[i], option_map[j].name, complen))
- {
- const char *arg = 0;
-
- if (arglen < optlen)
- {
- size_t k;
- for (k = j + 1; k < ARRAY_SIZE (option_map); k++)
- if (strlen (option_map[k].name) >= arglen
- && !strncmp (argv[i], option_map[k].name, arglen))
- {
- error ("ambiguous abbreviation %s", argv[i]);
- break;
- }
-
- if (k != ARRAY_SIZE (option_map))
- break;
- }
-
- if (arglen > optlen)
- {
- /* If the option has an argument, accept that. */
- if (argv[i][optlen] == '=')
- arg = argv[i] + optlen + 1;
-
- /* If this mapping requires extra text at end of name,
- accept that as "argument". */
- else if (strchr (arginfo, '*') != 0)
- arg = argv[i] + optlen;
-
- /* Otherwise, extra text at end means mismatch.
- Try other mappings. */
- else
- continue;
- }
-
- else if (strchr (arginfo, '*') != 0)
- {
- error ("incomplete %qs option", option_map[j].name);
- break;
- }
-
- /* Handle arguments. */
- if (strchr (arginfo, 'a') != 0)
- {
- if (arg == 0)
- {
- if (i + 1 == argc)
- {
- error ("missing argument to %qs option",
- option_map[j].name);
- break;
- }
-
- arg = argv[++i];
- }
- }
- else if (strchr (arginfo, '*') != 0)
- ;
- else if (strchr (arginfo, 'o') == 0)
- {
- if (arg != 0)
- error ("extraneous argument to %qs option",
- option_map[j].name);
- arg = 0;
- }
-
- /* Store the translation as one argv elt or as two. */
- if (arg != 0 && strchr (arginfo, 'j') != 0)
- newv[newindex++] = concat (option_map[j].equivalent, arg,
- NULL);
- else if (arg != 0)
- {
- newv[newindex++] = option_map[j].equivalent;
- newv[newindex++] = arg;
- }
- else
- newv[newindex++] = option_map[j].equivalent;
-
- break;
- }
- }
- i++;
- }
-
- /* Handle old-fashioned options--just copy them through,
- with their arguments. */
- else if (argv[i][0] == '-')
- {
- const char *p = argv[i] + 1;
- int c = *p;
- int nskip = 1;
-
- if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
- nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
- else if (WORD_SWITCH_TAKES_ARG (p))
- nskip += WORD_SWITCH_TAKES_ARG (p);
- else if ((c == 'B' || c == 'b' || c == 'x')
- && p[1] == 0)
- nskip += 1;
- else if (! strcmp (p, "Xlinker"))
- nskip += 1;
- else if (! strcmp (p, "Xpreprocessor"))
- nskip += 1;
- else if (! strcmp (p, "Xassembler"))
- nskip += 1;
-
- /* Watch out for an option at the end of the command line that
- is missing arguments, and avoid skipping past the end of the
- command line. */
- if (nskip + i > argc)
- nskip = argc - i;
-
- while (nskip > 0)
- {
- newv[newindex++] = argv[i++];
- nskip--;
- }
- }
- else
- /* Ordinary operands. */
- newv[newindex++] = argv[i++];
- }
-
- newv[newindex] = 0;
-
- *argvp = newv;
- *argcp = newindex;
-}
-
static char *
skip_whitespace (char *p)
{
@@ -3546,8 +3173,7 @@ driver_handle_option (const struct cl_decoded_option *decoded,
printf ("%s\n", spec_machine);
exit (0);
- case OPT_fversion:
- /* translate_options () has turned --version into -fversion. */
+ case OPT__version:
print_version = 1;
/* CPP driver cannot obtain switch from cc1_options. */
@@ -3557,8 +3183,7 @@ driver_handle_option (const struct cl_decoded_option *decoded,
add_linker_option ("--version", strlen ("--version"));
break;
- case OPT_fhelp:
- /* translate_options () has turned --help into -fhelp. */
+ case OPT__help:
print_help_list = 1;
/* CPP driver cannot obtain switch from cc1_options. */
@@ -3568,13 +3193,11 @@ driver_handle_option (const struct cl_decoded_option *decoded,
add_linker_option ("--help", 6);
break;
- case OPT_fhelp_:
- /* translate_options () has turned --help into -fhelp. */
+ case OPT__help_:
print_subprocess_help = 2;
break;
- case OPT_ftarget_help:
- /* translate_options() has turned --target-help into -ftarget-help. */
+ case OPT__target_help:
print_subprocess_help = 1;
/* CPP driver cannot obtain switch from cc1_options. */
@@ -3885,7 +3508,6 @@ driver_handle_option (const struct cl_decoded_option *decoded,
static void
process_command (int argc, const char **argv)
{
- int i;
const char *temp;
char *temp1;
const char *tooldir_prefix;
@@ -3914,18 +3536,16 @@ process_command (int argc, const char **argv)
}
}
- /* Convert new-style -- options to old-style. */
- translate_options (&argc,
- CONST_CAST2 (const char *const **, const char ***,
- &argv));
+ decode_cmdline_options_to_array (argc, argv, CL_DRIVER,
+ &decoded_options, &decoded_options_count);
/* Handle any -no-canonical-prefixes flag early, to assign the function
that builds relative prefixes. This function creates default search
paths that are needed later in normal option handling. */
- for (i = 1; i < argc; i++)
+ for (j = 1; j < decoded_options_count; j++)
{
- if (! strcmp (argv[i], "-no-canonical-prefixes"))
+ if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
{
get_relative_prefix = make_relative_prefix_ignore_links;
break;
@@ -3974,9 +3594,6 @@ process_command (int argc, const char **argv)
is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
or an automatically created GCC_EXEC_PREFIX from argv[0]. */
- decode_cmdline_options_to_array (argc, argv, CL_DRIVER,
- &decoded_options, &decoded_options_count);
-
/* Do language-specific adjustment/addition of flags. */
lang_specific_driver (&decoded_options, &decoded_options_count,
&added_libraries);