gcc/gcc.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) Index: gcc41/gcc/gcc.c =================================================================== --- gcc41.orig/gcc/gcc.c +++ gcc41/gcc/gcc.c @@ -334,6 +334,7 @@ static void display_help (void); static void add_preprocessor_option (const char *, int); static void add_assembler_option (const char *, int); static void add_linker_option (const char *, int); +static void hijack_cflags (int *, const char ***); static void process_command (int, const char **); static int execute (void); static void alloc_args (void); @@ -3143,6 +3144,76 @@ add_linker_option (const char *option, i linker_options [n_linker_options - 1] = save_string (option, len); } +static const char ** +split_string (char *s, const char **vp, int *k, int sz) +{ + int j = 0; + while (s [j]) + { + vp [*k] = &s [j]; + while (s [j] && s [j] != ' ') + j ++; + if (s [j]) + { + s [j] = '\0'; + j ++; + while (s [j] && s [j] == ' ') + j ++; + } + (*k) ++; + if ((*k) >= sz) + { + sz += sz; + vp = xrealloc (vp, sz * sizeof (char *)); + } + } + vp [*k] = 0; + return vp; +} + +static void +hijack_cflags (int *argcp, const char ***argvp) +{ + char *s, *t, **sp; + const char **vp; + int ssz, vsz, nsp, nvp, j, q, skip; + + s = getenv ("GCC_HIDDEN_CFLAGS"); + t = getenv ("GCC_STRIP_CFLAGS"); + if (s && s [0]) + { + ssz = 4; + sp = xcalloc (ssz, sizeof (char *)); + nsp = 0; + if (t && t [0]) + sp = (char **) split_string (t, (const char **) sp, &nsp, ssz); + else + sp [0] = 0; + vsz = *argcp + 4; + vp = xcalloc (vsz, sizeof (char *)); + nvp = q = 0; + skip = 0; + while (q < *argcp) + { + for (j = 0; j < nsp; j ++) + { + if (!strcmp ((*argvp) [q], sp [j])) + skip = 1; + } + if (!skip) + { + vp [nvp] = (*argvp) [q]; + nvp ++; + } + skip = 0; + q ++; + } + vp = split_string (s, vp, &nvp, vsz); + *argcp = nvp; + *argvp = vp; + } +} + /* Create the vector `switches' and its contents. Store its length in `n_switches'. */ @@ -6125,6 +6196,7 @@ main (int argc, const char **argv) Make a table of specified input files (infiles, n_infiles). Decode switches that are handled locally. */ + hijack_cflags (&argc, &argv); process_command (argc, argv); /* Initialize the vector of specs to just the default.