objformat: don't hardcode compiler versions
authorSimon Schubert <corecode@dragonflybsd.org>
Mon, 27 Jul 2009 08:53:36 +0000 (10:53 +0200)
committerSimon Schubert <corecode@dragonflybsd.org>
Mon, 27 Jul 2009 21:29:44 +0000 (23:29 +0200)
In the previous commit a fallback to the "custom" compiler driver was
introduced for unknown compilers.  The previous approach hard-coded
known compiler versions, making it more complicated to add new compilers
to base.

This commit changes slightly the behavior for the "custom" compiler
fallback:  The compiler is searched for like before the "custom" change,
and in addition, in case no compiler could be found, the search is
retried for the "custom" compiler driver.  This way we don't have to
hard-code known compiler versions, while a truely non-existing CCVER
will still be handled by the "custom" compiler driver.

usr.bin/objformat/objformat.c

index b853230..b8f1db4 100644 (file)
@@ -164,6 +164,7 @@ main(int argc, char **argv)
        if (objformat_path == NULL)
                objformat_path = OBJFORMAT_PATH_DEFAULT;
 
+again:
        path = strdup(objformat_path);
 
        if (setenv("OBJFORMAT", objformat, 1) == -1)
@@ -181,14 +182,8 @@ main(int argc, char **argv)
                        asprintf(&newcmd, "%s%s/%s/%s/%s",
                                chunk, base_path, env_value, objformat, cmd);
                } else {
-                       if (strncmp(env_value, "gcc34", 5) != 0 &&
-                           strncmp(env_value, "gcc41", 5) != 0) {
-                               asprintf(&newcmd, "%s%s/custom/%s",
-                                   chunk, base_path, cmd);
-                       } else {
-                               asprintf(&newcmd, "%s%s/%s/%s",
-                                   chunk, base_path, env_value, cmd);
-                       }
+                       asprintf(&newcmd, "%s%s/%s/%s",
+                               chunk, base_path, env_value, cmd);
                }
                if (newcmd == NULL)
                        err(1, "cannot allocate memory");
@@ -196,6 +191,17 @@ main(int argc, char **argv)
                argv[0] = newcmd;
                execv(newcmd, argv);
        }
+
+       /*
+        * Fallback:  if we're searching for a compiler, but didn't
+        * find any, try again using the custom compiler driver.
+        */
+       if (cmds && cmds->type == COMPILER &&
+           strcmp(env_value, "custom") != 0) {
+               env_value = "custom";
+               goto again;
+       }
+
        if (use_objformat) {
                err(1, "in path [%s]%s/%s/%s/%s",
                        objformat_path, base_path, env_value, objformat, cmd);