summaryrefslogtreecommitdiff
path: root/gcc/gcc-ar.c
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2012-11-27 16:55:47 +0000
committerMeador Inge <meadori@gcc.gnu.org>2012-11-27 16:55:47 +0000
commitc2a73de27f10388dcb8e457f7ccbeec798350492 (patch)
treeb327f0c1eba3f0941ca3e99f9c8e852a2b117082 /gcc/gcc-ar.c
parent3a50da342e585096bfdfc07ce8d8d49e9a6f227e (diff)
collect2.c (main): Call find_file_set_debug.
2012-11-27 Meador Inge <meadori@codesourcery.com> * collect2.c (main): Call find_file_set_debug. (find_a_find, add_prefix, prefix_from_env, prefix_from_string): Factor out into ... * file-find.c (New file): ... here and ... * file-find.h (New file): ... here. * gcc-ar.c (standard_exec_prefix): New variable. (standard_libexec_prefix): Ditto. (tooldir_base_prefix) Ditto. (self_exec_prefix): Ditto. (self_libexec_prefix): Ditto. (self_tooldir_prefix): Ditto. (target_version): Ditto. (path): Ditto. (target_path): Ditto. (setup_prefixes): New function. (main): Rework how wrapped programs are found. * Makefile.in (OBJS-libcommon-target): Add file-find.o. (AR_OBJS): New variable. (gcc-ar$(exeext)): Add dependency on $(AR_OBJS). (gcc-nm$(exeext)): Ditto. (gcc-ranlib(exeext)): Ditto. (COLLECT2_OBJS): Add file-find.o. (collect2.o): Add file-find.h prerequisite. (file-find.o): New rule. From-SVN: r193859
Diffstat (limited to 'gcc/gcc-ar.c')
-rw-r--r--gcc/gcc-ar.c147
1 files changed, 117 insertions, 30 deletions
diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index 5f78378dea8..c614566bb7c 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -21,21 +21,110 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "libiberty.h"
+#include "file-find.h"
#ifndef PERSONALITY
#error "Please set personality"
#endif
+/* The exec prefix as derived at compile-time from --prefix. */
+
+static const char standard_exec_prefix[] = STANDARD_EXEC_PREFIX;
+
+/* The libexec prefix as derived at compile-time from --prefix. */
+
static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
+
+/* The bindir prefix as derived at compile-time from --prefix. */
+
static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
-static const char *const target_machine = TARGET_MACHINE;
+
+/* A relative path to be used in finding the location of tools
+ relative to this program. */
+
+static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
+
+/* The exec prefix as relocated from the location of this program. */
+
+static const char *self_exec_prefix;
+
+/* The libexec prefix as relocated from the location of this program. */
+
+static const char *self_libexec_prefix;
+
+/* The tools prefix as relocated from the location of this program. */
+
+static const char *self_tooldir_prefix;
+
+/* The name of the machine that is being targeted. */
+
+static const char *const target_machine = DEFAULT_TARGET_MACHINE;
+
+/* The target version. */
+
+static const char *const target_version = DEFAULT_TARGET_VERSION;
+
+/* The collection of target specific path prefixes. */
+
+static struct path_prefix target_path;
+
+/* The collection path prefixes. */
+
+static struct path_prefix path;
+
+/* The directory separator. */
static const char dir_separator[] = { DIR_SEPARATOR, 0 };
+static void
+setup_prefixes (const char *exec_path)
+{
+ const char *self;
+
+ self = getenv ("GCC_EXEC_PREFIX");
+ if (!self)
+ self = exec_path;
+ else
+ self = concat (self, "gcc-" PERSONALITY, NULL);
+
+ /* Relocate the exec prefix. */
+ self_exec_prefix = make_relative_prefix (self,
+ standard_bin_prefix,
+ standard_exec_prefix);
+ if (self_exec_prefix == NULL)
+ self_exec_prefix = standard_exec_prefix;
+
+ /* Relocate libexec prefix. */
+ self_libexec_prefix = make_relative_prefix (self,
+ standard_bin_prefix,
+ standard_libexec_prefix);
+ if (self_libexec_prefix == NULL)
+ self_libexec_prefix = standard_libexec_prefix;
+
+
+ /* Build the relative path to the target-specific tool directory. */
+ self_tooldir_prefix = concat (tooldir_base_prefix, target_machine,
+ dir_separator, NULL);
+ self_tooldir_prefix = concat (self_exec_prefix, target_machine,
+ dir_separator, target_version, dir_separator,
+ self_tooldir_prefix, NULL);
+
+ /* Add the target-specific tool bin prefix. */
+ prefix_from_string (concat (self_tooldir_prefix, "bin", NULL), &target_path);
+
+ /* Add the target-specific libexec prefix. */
+ self_libexec_prefix = concat (self_libexec_prefix, target_machine,
+ dir_separator, target_version,
+ dir_separator, NULL);
+ prefix_from_string (self_libexec_prefix, &target_path);
+
+ /* Add path as a last resort. */
+ prefix_from_env ("PATH", &path);
+}
+
int
main(int ac, char **av)
{
- const char *nprefix;
const char *exe_name;
char *plugin;
int k, status, err;
@@ -44,39 +133,37 @@ main(int ac, char **av)
bool is_ar = !strcmp (PERSONALITY, "ar");
int exit_code = FATAL_EXIT_CODE;
- exe_name = PERSONALITY;
-#ifdef CROSS_DIRECTORY_STRUCTURE
- exe_name = concat (target_machine, "-", exe_name, NULL);
-#endif
+ setup_prefixes (av[0]);
- /* Find plugin */
- /* XXX implement more magic from gcc.c? */
- nprefix = getenv ("GCC_EXEC_PREFIX");
- if (!nprefix)
- nprefix = av[0];
- else
- nprefix = concat (nprefix, "gcc-" PERSONALITY, NULL);
-
- nprefix = make_relative_prefix (nprefix,
- standard_bin_prefix,
- standard_libexec_prefix);
- if (nprefix == NULL)
- nprefix = standard_libexec_prefix;
-
- plugin = concat (nprefix,
- dir_separator,
- DEFAULT_TARGET_MACHINE,
- dir_separator,
- DEFAULT_TARGET_VERSION,
- dir_separator,
- LTOPLUGINSONAME,
- NULL);
- if (access (plugin, R_OK))
+ /* Find the GCC LTO plugin */
+ plugin = find_a_file (&target_path, LTOPLUGINSONAME);
+ if (!plugin)
{
- fprintf (stderr, "%s: Cannot find plugin %s\n", av[0], plugin);
+ fprintf (stderr, "%s: Cannot find plugin '%s'\n", av[0], LTOPLUGINSONAME);
exit (1);
}
+ /* Find the wrapped binutils program. */
+ exe_name = find_a_file (&target_path, PERSONALITY);
+ if (!exe_name)
+ {
+#ifdef CROSS_DIRECTORY_STRUCTURE
+ const char *cross_exe_name;
+
+ cross_exe_name = concat (target_machine, "-", PERSONALITY, NULL);
+ exe_name = find_a_file (&path, cross_exe_name);
+ if (!exe_name)
+ {
+ fprintf (stderr, "%s: Cannot find binary '%s'\n", av[0],
+ cross_exe_name);
+ exit (1);
+ }
+#else
+ fprintf (stderr, "%s: Cannot find binary '%s'\n", av[0], PERSONALITY);
+ exit (1);
+#endif
+ }
+
/* Create new command line with plugin */
nargv = XCNEWVEC (const char *, ac + 4);
nargv[0] = exe_name;