comparison lwlink/readfiles.c @ 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 221b5f58d8ad
children
comparison
equal deleted inserted replaced
439:ff4b6095ee72 440:fda62f676ed4
68 for (i = 0; i < ninputfiles; i++) 68 for (i = 0; i < ninputfiles; i++)
69 { 69 {
70 if (inputfiles[i] -> islib) 70 if (inputfiles[i] -> islib)
71 { 71 {
72 char *tf; 72 char *tf;
73 char *sfn;
73 int s; 74 int s;
74 int j; 75 int j;
75 76
76 f = NULL; 77 f = NULL;
78
79 if (inputfiles[i] -> filename[0] == ':')
80 {
81 // : suppresses the libfoo.a behaviour
82 sfn = lw_strdup(inputfiles[i] -> filename + 1);
83 }
84 else
85 {
86 sfn = lw_alloc(strlen(inputfiles[i] -> filename) + 6);
87 sprintf(sfn, "lib%s.a", inputfiles[i] -> filename);
88 }
77 89
78 for (j = 0; j < nlibdirs; j++) 90 for (j = 0; j < nlibdirs; j++)
79 { 91 {
80 if (libdirs[j][0] == '=') 92 if (libdirs[j][0] == '=')
81 { 93 {
82 // handle sysroot 94 // handle sysroot
83 s = strlen(libdirs[j]) + 7 + strlen(sysroot) + strlen(inputfiles[i] -> filename); 95 s = strlen(libdirs[j]) + 2 + strlen(sysroot) + strlen(sfn);
84 tf = lw_alloc(s + 1); 96 tf = lw_alloc(s + 1);
85 sprintf(tf, "%s/%s/lib%s.a", sysroot, libdirs[j] + 1, inputfiles[i] -> filename); 97 sprintf(tf, "%s/%s/%s", sysroot, libdirs[j] + 1, sfn);
86 } 98 }
87 else 99 else
88 { 100 {
89 s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename); 101 s = strlen(libdirs[j]) + 1 + strlen(sfn);
90 tf = lw_alloc(s + 1); 102 tf = lw_alloc(s + 1);
91 sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename); 103 sprintf(tf, "%s/%s", libdirs[j], sfn);
92 } 104 }
93 f = fopen(tf, "rb"); 105 f = fopen(tf, "rb");
94 if (!f) 106 if (!f)
95 { 107 {
96 free(tf); 108 free(tf);
97 continue; 109 continue;
98 } 110 }
99 free(tf); 111 free(tf);
100 break; 112 break;
101 } 113 }
114 free(sfn);
102 if (!f) 115 if (!f)
103 { 116 {
104 fprintf(stderr, "Can't open library: -l%s\n", inputfiles[i] -> filename); 117 fprintf(stderr, "Can't open library: -l%s\n", inputfiles[i] -> filename);
105 exit(1); 118 exit(1);
106 } 119 }