eg. -l :crti.o, with the same meaning as for other linkers (search library paths for an exact match) Also clean up some copy/pasting
Unified · Split
| @@ -1212,26 +1212,37 @@ ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename) · 1211 unmodified lines | |||
| 1212 | /* the library name is the same as the argument of the '-l' option */ | 1212 | /* the library name is the same as the argument of the '-l' option */ |
| 1213 | LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) | 1213 | LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) |
| 1214 | { | 1214 | { |
| 1215 | static const char * const libs[] = { | ||
| 1215 | #if defined TCC_TARGET_PE | 1216 | #if defined TCC_TARGET_PE |
| 1216 | static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; | 1217 | "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", |
| 1217 | const char * const *pp = s->static_link ? libs + 4 : libs; | ||
| 1218 | #elif defined TCC_TARGET_MACHO | 1218 | #elif defined TCC_TARGET_MACHO |
| 1219 | static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL }; | 1219 | "%s/lib%s.dylib", "%s/lib%s.tbd", |
| 1220 | const char * const *pp = s->static_link ? libs + 2 : libs; | ||
| 1221 | #elif defined TARGETOS_OpenBSD | 1220 | #elif defined TARGETOS_OpenBSD |
| 1222 | static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL }; | 1221 | "%s/lib%s.so.*", |
| 1223 | const char * const *pp = s->static_link ? libs + 1 : libs; | ||
| 1224 | #else | 1222 | #else |
| 1225 | static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL }; | 1223 | "%s/lib%s.so", |
| 1226 | const char * const *pp = s->static_link ? libs + 1 : libs; | ||
| 1227 | #endif | 1224 | #endif |
| 1228 | int flags = s->filetype & AFF_WHOLE_ARCHIVE; | 1225 | "%s/lib%s.a", |
| 1229 | while (*pp) { | 1226 | NULL |
| 1230 | int ret = tcc_add_library_internal(s, *pp, | 1227 | }; |
| 1231 | libraryname, flags, s->library_paths, s->nb_library_paths); | 1228 | |
| 1232 | if (ret != FILE_NOT_FOUND) | 1229 | const char * const *pp = s->static_link |
| 1233 | return ret; | 1230 | ? libs + sizeof(libs) / sizeof(*libs) - 2 |
| 1234 | ++pp; | 1231 | : libs; |
| 1232 | |||
| 1233 | /* if libraryname begins with a colon, it means search lib paths for | ||
| 1234 | exactly the following file, without lib prefix or anything */ | ||
| 1235 | if (*libraryname == ':') | ||
| 1236 | libraryname++; | ||
| 1237 | else { | ||
| 1238 | int flags = s->filetype & AFF_WHOLE_ARCHIVE; | ||
| 1239 | while (*pp) { | ||
| 1240 | int ret = tcc_add_library_internal(s, *pp, | ||
| 1241 | libraryname, flags, s->library_paths, s->nb_library_paths); | ||
| 1242 | if (ret != FILE_NOT_FOUND) | ||
| 1243 | return ret; | ||
| 1244 | ++pp; | ||
| 1245 | } | ||
| 1235 | } | 1246 | } |
| 1236 | return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR); | 1247 | return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR); |
| 1237 | } | 1248 | } |