- elf2flt_progname = argv0;
- for (ptr = elf2flt_progname + len; ptr != elf2flt_progname; ptr--)
- if (IS_DIR_SEPARATOR(ptr[-1])) {
- tooldir = tmp = xmalloc(len);
- memcpy(tmp, argv0, len);
- tmp[ptr - elf2flt_progname - 1] = 0;
- elf2flt_progname = ptr;
- /* The standard binutils tool layout has:
-
- bin/<TARGET_ALIAS>-foo
- lib/
- <TARGET_ALIAS>/bin/foo
- <TARGET_ALIAS>/lib
-
- It's <TARGET_ALIAS>/ that we want here: files in lib/ are for
- the host while those in <TARGET_ALIAS>/lib are for the target. */
- if (streqn(elf2flt_progname, TARGET_ALIAS)) {
- tmp = concat(tooldir, "/../" TARGET_ALIAS "/bin", NULL);
- if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode))
- tooldir = tmp;
- }
- break;
+ elf2flt_progname = lbasename(argv0);
+
+ /* The standard binutils tool layout has:
+
+ bin/<TARGET_ALIAS>-foo
+ lib/
+ <TARGET_ALIAS>/bin/foo
+ <TARGET_ALIAS>/lib
+
+ It's <TARGET_ALIAS>/ that we want here: files in lib/ are for
+ the host while those in <TARGET_ALIAS>/lib are for the target.
+ Make bindir point to the bin dir for bin/<TARGET_ALIAS>-foo.
+ Make tooldir point to the bin dir for <TARGET_ALIAS>/bin/foo. */
+ if (streqn(elf2flt_progname, TARGET_ALIAS)) {
+ tmp = concat(argv0_dir, "../" TARGET_ALIAS "/bin", NULL);
+ if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) {
+ tooldir = concat(tmp, "/", NULL);
+ }
+ } else {
+ tmp = concat(argv0_dir, "../../bin", NULL);
+ if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) {
+ bindir = concat(tmp, "/", NULL);