Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / cross / COMMON / buwrapper.c
blobc9edd5774739bbebe5e2704f1da4b7576ab95993
1 /* $NetBSD: buwrapper.c,v 1.1 1999/01/04 22:37:30 tv Exp $ */
3 #include <err.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sysexits.h>
7 #include <unistd.h>
9 /*
10 * Wrapper for binutils programs.
12 * This frontend sets the appropriate environment variables that tell
13 * binutils programs which target will be used.
16 static const char binsubdir[] = "libexec/binutils";
18 #define PATHLEN sizeof(PREFIX) + sizeof(binsubdir) + 20
20 int main(int argc, char **argv) {
21 char path[PATHLEN], *p, *prog;
23 /* quickly find last part of path component */
24 if (p = strrchr(argv[0], '/'))
25 p++;
26 else
27 p = argv[0];
28 if (prog = strrchr(p, '-'))
29 prog++;
30 else
31 prog = p;
33 /* make program pathname */
34 snprintf(path, PATHLEN, "%s/%s/%s", PREFIX, binsubdir, prog);
36 /* set up environment */
37 setenv("GNUTARGET", GNUTARGET, 0);
38 #ifdef LDEMULATION
39 setenv("LDEMULATION", LDEMULATION, 0);
40 #endif
41 #ifdef LD_RPATH_LINK
42 setenv("LD_RPATH_LINK", LD_RPATH_LINK, 1);
43 #endif
45 /* run it! */
46 execv(path, argv);
48 /* we shouldn't get here. */
49 err(EX_OSERR, "(buwrapper): exec %s", path);