link: don't put -l in front of .a or .so files

master
Andrew Kelley 2016-05-07 01:58:18 -07:00
parent c098a8f522
commit d5d5fd928c
2 changed files with 30 additions and 4 deletions

View File

@ -140,11 +140,30 @@ static inline bool buf_eql_str(Buf *buf, const char *str) {
return buf_eql_mem(buf, str, strlen(str));
}
static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) {
if (buf_len(buf) < buf_len(sub)) {
static inline bool buf_starts_with_mem(Buf *buf, const char *mem, int mem_len) {
if (buf_len(buf) < mem_len) {
return false;
}
return buf_eql_mem(sub, buf_ptr(buf), buf_len(sub));
return memcmp(buf_ptr(buf), mem, mem_len) == 0;
}
static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) {
return buf_starts_with_mem(buf, buf_ptr(sub), buf_len(sub));
}
static inline bool buf_starts_with_str(Buf *buf, const char *str) {
return buf_starts_with_mem(buf, str, strlen(str));
}
static inline bool buf_ends_with_mem(Buf *buf, const char *mem, int mem_len) {
if (buf_len(buf) < mem_len) {
return false;
}
return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0;
}
static inline bool buf_ends_with_str(Buf *buf, const char *str) {
return buf_ends_with_mem(buf, str, strlen(str));
}
bool buf_eql_buf(Buf *buf, Buf *other);

View File

@ -238,7 +238,14 @@ static void construct_linker_job_linux(LinkJob *lj) {
for (int i = 0; i < g->link_libs.length; i += 1) {
Buf *link_lib = g->link_libs.at(i);
Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
Buf *arg;
if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") ||
buf_ends_with_str(link_lib, ".so"))
{
arg = link_lib;
} else {
arg = buf_sprintf("-l%s", buf_ptr(link_lib));
}
lj->args.append(buf_ptr(arg));
}