]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Better parsing of g* Options, and only use last argument 92/head
authorNorbert Lange <nolange79@gmail.com>
Sat, 28 May 2016 13:38:10 +0000 (15:38 +0200)
committerNorbert Lange <nolange79@gmail.com>
Sun, 5 Jun 2016 21:46:13 +0000 (23:46 +0200)
Commonly some base configuration like CFLAGS="-O2 -g3 ..." will be
modified for builds by appending "-g0" to disable debug information.
This commit only en/disables options based on the last argument
that modifies debuginfo generation.

Also some more arguments are supported.

ccache.c

index 23103ee3c2457da01f3da2f82743a42754e5069a..ee1bdd8750447643afd39273fd8cf8b5cffd96c2 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -2125,6 +2125,8 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
        char **argv;
        bool result = true;
        bool found_color_diagnostics = false;
+       int deb_level = 0;
+       const char *deb_argument = NULL;
 
        expanded_args = args_copy(args);
        stripped_args = args_init(0, NULL);
@@ -2329,21 +2331,33 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                /* Debugging is handled specially, so that we know if we can strip line
                 * number info. */
                if (str_startswith(argv[i], "-g")) {
-                       generating_debuginfo = true;
-                       args_add(stripped_args, argv[i]);
-                       if (conf->unify && !str_eq(argv[i], "-g0")) {
-                               cc_log("%s used; disabling unify mode", argv[i]);
-                               conf->unify = false;
+                       const char *pLevel = argv[i] + 2;
+                       int foundlevel = -1;
+                       if (str_startswith(argv[i], "-ggdb")) {
+                               pLevel = argv[i] + 5;
+                       } else if (str_startswith(argv[i], "-gstabs")) {
+                               pLevel = argv[i] + 7;
+                       } else if (str_startswith(argv[i], "-gcoff")) {
+                               pLevel = argv[i] + 6;
+                       } else if (str_startswith(argv[i], "-gxcoff")) {
+                               pLevel = argv[i] + 7;
+                       } else if (str_startswith(argv[i], "-gvms")) {
+                               pLevel = argv[i] + 5;
                        }
-                       if (str_eq(argv[i], "-g3")) {
-                               /*
-                                * Fix for bug 7190 ("commandline macros (-D)
-                                * have non-zero lineno when using -g3").
-                                */
-                               cc_log("%s used; not compiling preprocessed code", argv[i]);
-                               conf->run_second_cpp = true;
+
+                       /* Deduce level from Argument, default is 2 */
+                       if (pLevel[0] == '\0') {
+                               foundlevel = 2;
+                       }
+                       else if (pLevel[0] >= '0' && pLevel[0] <= '9') {
+                               foundlevel = atoi(pLevel);
+                       }
+
+                       if (foundlevel >= 0) {
+                               deb_level = foundlevel;
+                               deb_argument = argv[i];
+                               continue;
                        }
-                       continue;
                }
 
                /* These options require special handling, because they
@@ -2768,6 +2782,23 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                input_file = make_relative_path(x_strdup(argv[i]));
        } /* for */
 
+       if (deb_level > 0) {
+               generating_debuginfo = true;
+               args_add(stripped_args, deb_argument);
+               if (conf->unify) {
+                       cc_log("%s used; disabling unify mode", deb_argument);
+                       conf->unify = false;
+               }
+               if (deb_level >= 3) {
+                       /*
+                        * Fix for bug 7190 ("commandline macros (-D)
+                        * have non-zero lineno when using -g3").
+                        */
+                       cc_log("%s used; not compiling preprocessed code", deb_argument);
+                       conf->run_second_cpp = true;
+               }
+       }
+
        if (found_S_opt) {
                /* Even if -gsplit-dwarf is given, the .dwo file is not generated when -S
                 * is also given.