# HG changeset patch # User William Astle # Date 1511846502 25200 # Node ID fda62f676ed4f6f6c9d3786bc7b71efb2b54a5fe # Parent ff4b6095ee724f114f0bd27d2a3506ab1ecd54b8 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" diff -r ff4b6095ee72 -r fda62f676ed4 docs/manual.docbook.sgml --- 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 @@ -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. diff -r ff4b6095ee72 -r fda62f676ed4 lwlink/readfiles.c --- 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);