2
0
mirror of https://github.com/bebbo/amigaos-cross-toolchain.git synced 2025-12-08 22:38:24 +00:00
Files
amigaos-cross-toolchain6/patches/binutils-2.9.1/ld/ldfile.c.diff
2012-02-14 19:23:53 -08:00

109 lines
2.6 KiB
Diff

--- binutils-2.9.1/ld/ldfile.c 1998-05-01 08:48:48.000000000 -0700
+++ binutils-2.9.1/ld/ldfile.c 2011-05-08 20:28:36.636307945 -0700
@@ -39,6 +39,9 @@
#include <ctype.h>
+static int n_flavors, flavors_len;
+char **flavors;
+
const char *ldfile_input_filename;
boolean ldfile_assumed_script = false;
const char *ldfile_output_machine_name = "";
@@ -79,6 +82,32 @@
const char *lib, const char *suffix));
static FILE *try_open PARAMS ((const char *name, const char *exten));
+static int flavors_cmp (f1, f2)
+ const void *f1, *f2;
+{
+ return strcmp (*(char**)f1, *(char**)f2);
+}
+
+void
+sort_flavors ()
+{
+ if (n_flavors > 1)
+ qsort ((void*)flavors, n_flavors, sizeof(char**), flavors_cmp);
+}
+
+void
+ldfile_add_flavor (name)
+ char *name;
+{
+ n_flavors++;
+ if (flavors)
+ flavors = (char**) xrealloc ((PTR)flavors, n_flavors*sizeof (char*));
+ else
+ flavors = (char**) xmalloc (sizeof (char*));
+ flavors [n_flavors-1] = name;
+ flavors_len += strlen (name);
+}
+
void
ldfile_add_library_path (name, cmdline)
const char *name;
@@ -128,6 +157,7 @@
const char *suffix;
{
search_dirs_type *search;
+ char *flavor_dir = (char *) alloca (flavors_len + n_flavors + 1);
/* If this is not an archive, try to open it in the current
directory first. */
@@ -142,6 +172,7 @@
search = search->next)
{
char *string;
+ int i, count=n_flavors;
if (entry->dynamic && ! link_info.relocateable)
{
@@ -171,15 +202,40 @@
else
sprintf (string, "%s%s%s", search->name, slash, entry->filename);
- if (ldfile_try_open_bfd (string, entry))
- {
- entry->filename = string;
- return true;
+ for (count = n_flavors; count>=0; count--) {
+ *flavor_dir = '\0';
+ for (i=0; i<count; i++) {
+ strcat (flavor_dir, flavors[i]);
+ strcat (flavor_dir, slash);
}
- free (string);
+ string = (char *) xmalloc (strlen (search->name)
+ + strlen (slash)
+ + strlen (flavor_dir)
+ + strlen (lib)
+ + strlen (entry->filename)
+ + strlen (arch)
+ + strlen (suffix)
+ + 1);
+
+ if (entry->is_archive)
+ sprintf (string, "%s%s%s%s%s%s%s", search->name, slash, flavor_dir,
+ lib, entry->filename, arch, suffix);
+ else if (entry->filename[0] == '/' || entry->filename[0] == '.')
+ strcpy (string, entry->filename);
+ else
+ sprintf (string, "%s%s%s%s", search->name, slash, flavor_dir,
+ entry->filename);
+
+ if (ldfile_try_open_bfd (string, entry))
+ {
+ entry->filename = string;
+ return true;
+ }
+
+ free (string);
+ }
}
-
return false;
}