changeset 440:fda62f676ed4

Allow specifying exact filenames for -l in lwlink Allow prefixing a library name with a colon (":") to instruct lwlink to search for a file with exactly the specified name in the library path. There is no change for existing behaviour if there is no colon prefix. Thus: -lfoo -> looks for "libfoo.a" -l:foo -> looks for exactly "foo"
author William Astle <lost@l-w.ca>
date Mon, 27 Nov 2017 22:21:42 -0700
parents ff4b6095ee72
children b138b4005125
files docs/manual.docbook.sgml lwlink/readfiles.c
diffstat 2 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/docs/manual.docbook.sgml	Tue Aug 15 20:49:58 2017 -0600
+++ b/docs/manual.docbook.sgml	Mon Nov 27 22:21:42 2017 -0700
@@ -2233,8 +2233,9 @@
 <term><option>-l LIBSPEC</option></term>
 <listitem>
 <para>
-Load a library using the library search path. LIBSPEC will have "lib" prepended
-and ".a" appended.
+Load a library using the library search path. If LIBSPEC is prefixed with a
+colon (":"), then LIBSPEC is the precise filename to be searched for in the
+library path. Otherwise, LIBSPEC will have "lib" prepended and ".a" appended.
 </para>
 </listitem>
 </varlistentry>
--- a/lwlink/readfiles.c	Tue Aug 15 20:49:58 2017 -0600
+++ b/lwlink/readfiles.c	Mon Nov 27 22:21:42 2017 -0700
@@ -70,25 +70,37 @@
 		if (inputfiles[i] -> islib)
 		{
 			char *tf;
+			char *sfn;
 			int s;
 			int j;
 			
 			f = NULL;
 			
+			if (inputfiles[i] -> filename[0] == ':')
+			{
+				// : suppresses the libfoo.a behaviour
+				sfn = lw_strdup(inputfiles[i] -> filename + 1);
+			}
+			else
+			{
+				sfn = lw_alloc(strlen(inputfiles[i] -> filename) + 6);
+				sprintf(sfn, "lib%s.a", inputfiles[i] -> filename);
+			}
+			
 			for (j = 0; j < nlibdirs; j++)
 			{
 				if (libdirs[j][0] == '=')
 				{
 					// handle sysroot
-					s = strlen(libdirs[j]) + 7 + strlen(sysroot) + strlen(inputfiles[i] -> filename);
+					s = strlen(libdirs[j]) + 2 + strlen(sysroot) + strlen(sfn);
 					tf = lw_alloc(s + 1);
-					sprintf(tf, "%s/%s/lib%s.a", sysroot, libdirs[j] + 1, inputfiles[i] -> filename);
+					sprintf(tf, "%s/%s/%s", sysroot, libdirs[j] + 1, sfn);
 				}
 				else
 				{
-					s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename);
+					s = strlen(libdirs[j]) + 1 + strlen(sfn);
 					tf = lw_alloc(s + 1);
-					sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename);
+					sprintf(tf, "%s/%s", libdirs[j], sfn);
 				}
 				f = fopen(tf, "rb");
 				if (!f)
@@ -99,6 +111,7 @@
 				free(tf);
 				break;
 			}
+			free(sfn);
 			if (!f)
 			{
 				fprintf(stderr, "Can't open library: -l%s\n", inputfiles[i] -> filename);