ld path fix

Peter Naulls peter at chocky.org
Tue Apr 1 06:04:24 PST 2003



This prevents specification of -ljpeg not picking up libjpeg.a just
because you happen to have jpeg.o in your build (that option is now
tried last):


Index: ld.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/riscos-aof/ld/ld.c,v
retrieving revision 1.7.2.12
diff -u -r1.7.2.12 ld.c
@@ -1607,65 +1608,79 @@
 static void parse_library (const char *library)
 {
   char file_name[200];
-  llist *list = library_path;
-  int i;
-
-  while (list)
-    {
-      /* Add 'lib' onto the front of each library name. This is what
-	 'ld' does anyway.  */
-      i = strlen (list->name);
-      strcpy (file_name, list->name);
-      if (list->name[i] != ':' && list->name[i] != '.'
-          && list->name[i] != '/')
-        strcat (file_name, "/");
+  int pass;
 
+  /* For the first pass, try all the "regular" options,
+     for the second last ditch pass, try without the lib prefix */
+  for (pass = 0; pass < 2; pass++)
+    {
+      llist *list = library_path;
+
+      while (list)
+        {
+          int namelen = strlen (list->name);
+
+          if (pass == 0)
+            {
+  
+              /* Add 'lib' onto the front of each library name. This is what
+                'ld' does anyway.  */
+              strcpy (file_name, list->name);
+              if (list->name[namelen] != ':' && list->name[namelen] != '.'
+                  && list->name[namelen] != '/')
+                strcat (file_name, "/");
+      
 #ifdef CROSS_COMPILE
-      strcat (file_name, "lib"); 
-      strcat (file_name, library); 
-      strcat (file_name, ".a"); 
-#else 
-      strcat (file_name, "a.lib"); 
-      strcat (file_name, library); 
-#endif 
-      if (check_and_add_library (file_name) == 1) 
-       return; 
- 
-      /* Couldn't find lib<name>.a so try lib<name>.o */ 
-      strcpy (file_name, list->name); 
-      if (list->name[i] != ':' && list->name[i] != '.' 
-          && list->name[i] != '/') 
-        strcat (file_name, "/"); 
-
+              strcat (file_name, "lib"); 
+              strcat (file_name, library); 
+              strcat (file_name, ".a"); 
+#else
+              strcat (file_name, "a/lib"); 
+              strcat (file_name, library); 
+#endif
+              if (check_and_add_library (file_name) == 1)
+               return;
+       
+              /* Couldn't find lib<name>.a so try lib<name>.o */ 
+              strcpy (file_name, list->name); 
+              if (list->name[namelen] != ':' && list->name[namelen] != '.'
+                  && list->name[namelen] != '/')
+                strcat (file_name, "/"); 
+      
 #ifdef CROSS_COMPILE
-      strcat (file_name, "lib");
-      strcat (file_name, library);
-      strcat (file_name, ".o");
+              strcat (file_name, "lib");
+              strcat (file_name, library);
+              strcat (file_name, ".o");
 #else
-      strcat (file_name, "o.lib");
-      strcat (file_name, library);
+              strcat (file_name, "o/lib");
+              strcat (file_name, library);
 #endif
-      if (check_and_add_library (file_name) == 1)
-	return;
+              if (check_and_add_library (file_name) == 1)
+               return;
 
-      /* If we couldn't find the library with lib on the front i.e.
-	 for the case of UnixLib then try it without.  */
-      strcpy (file_name, list->name);
-      if (list->name[i] != ':' && list->name[i] != '.'
-          && list->name[i] != '/')
-        strcat (file_name, "/");
+           }
+         else
+           {
+
+           /* If we couldn't find the library with lib on the front e.g.
+              for the case of UnixLib then try it without.  */
+           strcpy (file_name, list->name);
+           if (list->name[namelen] != ':' && list->name[namelen] != '.'
+               && list->name[namelen] != '/')
+             strcat (file_name, "/");
 
 #ifdef CROSS_COMPILE
-      strcat (file_name, library);
-      strcat (file_name, ".o");
+           strcat (file_name, library);
+           strcat (file_name, ".o");
 #else
-      strcat (file_name, "o.");
-      strcat (file_name, library);
+           strcat (file_name, "o/");
+           strcat (file_name, library);
 #endif
-      if (check_and_add_library (file_name) == 1)
-	return;
-
-      list = list->next;
+           if (check_and_add_library (file_name) == 1)
+             return;
+        }
+        list = list->next;
+      }
     }
 
   /* Check for precise filename */


-- 
------------------------------------------------------------------------
 Peter Naulls - peter at chocky.org
 Homepage                     -  http://www.chocky.org/
 RISC OS C Programming        -  http://www.riscos.info/
 Unix Programs on RISC OS     -  http://www.chocky.org/unix/
------------------------------------------------------------------------
 



More information about the gcc mailing list