#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "gcc.h"
#ifndef SWITCH_TAKES_ARG
#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
#endif
#ifndef WORD_SWITCH_TAKES_ARG
#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
#endif
static const char *const known_suffixes[] =
{
".c", ".C", ".S", ".m",
".cc", ".cxx", ".cpp", ".cp", ".c++",
NULL
};
void
lang_specific_driver (int *in_argc, const char *const **in_argv,
int *in_added_libraries ATTRIBUTE_UNUSED)
{
int argc = *in_argc;
const char *const *argv = *in_argv;
int read_stdin = 1;
int need_E = 1;
int seen_input = 0;
int lang_c_here = 0;
int lang_S_here = 0;
int o_here = 0;
int need_fixups = 1;
int i, j, quote = 0;
const char **new_argv;
int new_argc;
extern int is_cpp_driver;
is_cpp_driver = 1;
for (i = 1; i < argc; i++)
{
if (quote == 1)
{
quote = 0;
continue;
}
if (argv[i][0] == '-')
{
if (argv[i][1] == '\0')
read_stdin = 0;
else if (argv[i][2] == '\0')
{
if (argv[i][1] == 'E')
need_E = 0;
else if (argv[i][1] == 'S' || argv[i][1] == 'c')
{
fatal ("\"%s\" is not a valid option to the preprocessor",
argv[i]);
return;
}
else if (argv[i][1] == 'x')
{
need_fixups = 0;
quote = 1;
}
else if (SWITCH_TAKES_ARG (argv[i][1]))
quote = 1;
}
else if (argv[i][1] == 'x')
need_fixups = 0;
else if (WORD_SWITCH_TAKES_ARG (&argv[i][1]))
quote = 1;
}
else
{
seen_input++;
if (seen_input == 3)
{
fatal ("too many input files");
return;
}
else if (seen_input == 2)
{
o_here = i;
}
else
{
read_stdin = 0;
if (need_fixups)
{
int l = strlen (argv[i]);
int known = 0;
const char *const *suff;
for (suff = known_suffixes; *suff; suff++)
if (!strcmp (*suff, &argv[i][l - strlen(*suff)]))
{
known = 1;
break;
}
if (! known)
{
if (!strcmp (".s", &argv[i][l - 2]))
lang_S_here = i;
else
lang_c_here = i;
}
}
}
}
}
new_argc = argc + need_E + read_stdin
+ !!o_here + !!lang_c_here + !!lang_S_here;
if (new_argc == argc)
return;
new_argv = XNEWVEC (const char *, new_argc + 1);
new_argv[0] = argv[0];
j = 1;
if (need_E)
new_argv[j++] = "-E";
for (i = 1; i < argc; i++, j++)
{
if (i == lang_c_here)
new_argv[j++] = "-xc";
else if (i == lang_S_here)
new_argv[j++] = "-xassembler-with-cpp";
else if (i == o_here)
new_argv[j++] = "-o";
new_argv[j] = argv[i];
}
if (read_stdin)
new_argv[j++] = "-";
new_argv[j] = NULL;
*in_argc = new_argc;
*in_argv = new_argv;
}
int lang_specific_pre_link (void)
{
return 0;
}
int lang_specific_extra_outfiles = 0;