Add support for ${BINUTILSVER} to objformat. This defaults to gcc2
authorJoerg Sonnenberger <joerg@dragonflybsd.org>
Fri, 23 Jan 2004 22:30:25 +0000 (22:30 +0000)
committerJoerg Sonnenberger <joerg@dragonflybsd.org>
Fri, 23 Jan 2004 22:30:25 +0000 (22:30 +0000)
and generates the current locations (e.g. /usr/libexec/gcc2/elf/as).
c++filt was moved into the normal compiler bindir.

gnu/usr.bin/cc/c++filt/Makefile
gnu/usr.bin/cc3/c++filt/Makefile
usr.bin/objformat/Makefile
usr.bin/objformat/objformat.c

index da7d2c5..8a0e641 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/gnu/usr.bin/cc/c++filt/Makefile,v 1.11 1999/11/04 04:45:59 obrien Exp $
-# $DragonFly: src/gnu/usr.bin/cc/c++filt/Attic/Makefile,v 1.3 2004/01/16 07:45:21 dillon Exp $
+# $DragonFly: src/gnu/usr.bin/cc/c++filt/Attic/Makefile,v 1.4 2004/01/23 22:30:24 joerg Exp $
 
 .include "../Makefile.inc"
 
@@ -7,7 +7,6 @@
 
 PROG=  c++filt
 SRCS=  cplus-dem.c getopt.c getopt1.c underscore.c
-BINDIR=        /usr/libexec/gcc2/${OBJFORMAT}
 NOMAN= 1
 
 CFLAGS+= -DMAIN -DIN_GCC -DVERSION=\"$(version)\"
index a211cf8..7d6b5be 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/gnu/usr.bin/cc/c++filt/Makefile,v 1.16 2003/07/11 05:37:23 kan Exp $
-# $DragonFly: src/gnu/usr.bin/cc3/c++filt/Attic/Makefile,v 1.2 2004/01/17 23:05:19 drhodus Exp $
+# $DragonFly: src/gnu/usr.bin/cc3/c++filt/Attic/Makefile,v 1.3 2004/01/23 22:30:25 joerg Exp $
 
 .include "../Makefile.inc"
 
@@ -7,7 +7,6 @@
 
 PROG=  c++filt
 SRCS=  cp-demangle.c cplus-dem+%DIKED.c
-BINDIR= /usr/libexec/gcc3/${OBJFORMAT}
 NOMAN= 1
 
 CFLAGS+= -DSTANDALONE_DEMANGLER -DIN_GCC -DVERSION=\"$(version)\"
index 420b1ce..923446e 100644 (file)
@@ -1,16 +1,15 @@
 # $FreeBSD: src/usr.bin/objformat/Makefile,v 1.15 1999/12/24 15:18:19 green Exp $
-# $DragonFly: src/usr.bin/objformat/Makefile,v 1.3 2004/01/16 07:45:22 dillon Exp $
+# $DragonFly: src/usr.bin/objformat/Makefile,v 1.4 2004/01/23 22:30:25 joerg Exp $
 
 PROG=          objformat
 CFLAGS+=       -Wall
 NOSHARED?=     YES
 
-# These will exec /usr/libexec/gcc2/<objformat>/<name>
+# These will exec /usr/libexec/${BINUTILSVER}/<objformat>/<name>
 #
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/addr2line
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/ar
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/as
-LINKS+=        ${BINDIR}/objformat ${BINDIR}/c++filt
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/gasp
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/gdb
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/ld
@@ -22,16 +21,16 @@ LINKS+=     ${BINDIR}/objformat ${BINDIR}/size
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/strings
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/strip
 
-
-# These will exec /usr/bin/gcc2/<name>
+# These will exec /usr/bin/${CCVER}/<name>
 #
+LINKS+=        ${BINDIR}/objformat ${BINDIR}/CC
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/cpp
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/c++
+LINKS+=        ${BINDIR}/objformat ${BINDIR}/c++filt
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/cc
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/f77
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/g++
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/gcc
 LINKS+=        ${BINDIR}/objformat ${BINDIR}/gcov
 
-
 .include <bsd.prog.mk>
index eb80e95..2e10cc5 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.bin/objformat/objformat.c,v 1.6 1998/10/24 02:01:30 jdp Exp $
- * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.4 2004/01/23 10:59:53 joerg Exp $
+ * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.5 2004/01/23 22:30:25 joerg Exp $
  */
 
 #include <err.h>
 #include <string.h>
 #include <unistd.h>
 
+#define OBJFORMAT      0
+#define COMPILER       1
+#define BINUTILS       2
+
+struct command {
+       const char *cmd;
+       int type;
+};
+
+static struct command commands[] = {
+       {"CC",          COMPILER},
+       {"c++",         COMPILER},
+       {"c++filt",     COMPILER},
+       {"cc",          COMPILER},
+       {"cpp",         COMPILER},
+       {"f77",         COMPILER},
+       {"g++",         COMPILER},
+       {"gcc",         COMPILER},
+       {"gcov",        COMPILER},
+       {"addr2line",   BINUTILS},
+       {"ar",          BINUTILS},
+       {"as",          BINUTILS},
+       {"gasp",        BINUTILS},
+       {"gdb",         BINUTILS},
+       {"ld",          BINUTILS},
+       {"nm",          BINUTILS},
+       {"objcopy",     BINUTILS},
+       {"objdump",     BINUTILS},
+       {"ranlib",      BINUTILS},
+       {"size",        BINUTILS},
+       {"strings",     BINUTILS},
+       {"strip",       BINUTILS},
+       {"objformat",   OBJFORMAT},
+       {0, 0}
+};
+
 int
 main(int argc, char **argv)
 {
+       struct command *cmds = commands;
        char objformat[32];
        char *path, *chunk;
        char *cmd, *newcmd = NULL;
        char *objformat_path;
-       char *ccver;
-       char *dirprefix;
-       char *dirpostfix;
+       const char *env_name = NULL;
+       const char *env_value;
+       const char *env_default = NULL;
+       const char *base_path = NULL;
+       int use_objformat = 0;
 
        if (getobjformat(objformat, sizeof objformat, &argc, argv) == -1)
                errx(1, "Invalid object format");
@@ -57,32 +96,40 @@ main(int argc, char **argv)
        else
                cmd = argv[0];
 
-       /*
-        * Directory prefix
-        */
-       if (strcmp(cmd, "c++") == 0 ||
-                  strcmp(cmd, "cc") == 0 ||
-                  strcmp(cmd, "cpp") == 0 ||
-                  strcmp(cmd, "f77") == 0 ||
-                  strcmp(cmd, "g++") == 0 ||
-                  strcmp(cmd, "gcc") == 0 ||
-                  strcmp(cmd, "gcov") == 0
-       ) {
-               dirprefix = "/usr/bin";
-               dirpostfix = "";
-       } else {
-               dirprefix = "/usr/libexec";
-               asprintf(&dirpostfix, "/%s", objformat);
-       }
+       for (;cmds->cmd; cmds++)
+               if (strcmp(cmd, cmds->cmd) == 0)
+               {
+                       switch (cmds->type)
+                       {
+                       case COMPILER:
+                               env_name = "CCVER";
+                               env_default = "gcc2";
+                               base_path = "/usr/bin";
+                               use_objformat = 0;
+                               break;
+                       case BINUTILS:
+                               env_name = "BINUTILSVER";
+                               env_default = "gcc2";
+                               base_path = "/usr/libexec";
+                               use_objformat = 1;
+                               break;
+                       case OBJFORMAT:
+                               break;
+                       default:
+                               err(1, "unknown command type");
+                       }
+                       break;
+               }
 
        /*
         * The objformat command itself doesn't need another exec
         */
-       if (strcmp(cmd, "objformat") == 0) {
+       if (cmds->type == OBJFORMAT) {
                if (argc != 1) {
                        fprintf(stderr, "Usage: objformat\n");
                        exit(1);
                }
+
                printf("%s\n", objformat);
                exit(0);
        }
@@ -93,9 +140,10 @@ main(int argc, char **argv)
        objformat_path = getenv("OBJFORMAT_PATH");
        if (objformat_path == NULL)
                objformat_path = "";
-       if ((ccver = getenv("CCVER")) == NULL) {
-               ccver = "gcc2";
-       }
+
+       if ((env_value = getenv(env_name)) == NULL)
+               env_value = env_default;
+
        path = strdup(objformat_path);
 
        setenv("OBJFORMAT", objformat, 1);
@@ -108,15 +156,23 @@ main(int argc, char **argv)
                        free(newcmd);
                        newcmd = NULL;
                }
-               asprintf(&newcmd, "%s%s/%s%s/%s",
-                       chunk, dirprefix, ccver, dirpostfix, cmd);
+               if (use_objformat)
+                       asprintf(&newcmd, "%s%s/%s/%s/%s",
+                               chunk, base_path, env_value, objformat, cmd);
+               else
+                       asprintf(&newcmd, "%s%s/%s/%s",
+                               chunk, base_path, env_value, cmd);
                if (newcmd == NULL)
                        err(1, "cannot allocate memory");
 
                argv[0] = newcmd;
                execv(newcmd, argv);
        }
-       err(1, "in path [%s]%s/%s%s/%s",
-               objformat_path, dirprefix, ccver, dirpostfix, cmd);
+       if (use_objformat)
+               err(1, "in path [%s]%s/%s/%s/%s",
+                       objformat_path, base_path, env_value, objformat, cmd);
+       else
+               err(1, "in path [%s]%s/%s/%s",
+                       objformat_path, base_path, env_value, cmd);
 }