zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d5d5fd928c79df6e4060c7ad84068fcee28c2391 (tree)
parent c098a8f5223855b410895b5396948e3e2b3aacba
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sat,  7 May 2016 01:58:18 -0700

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

Diffstat:
Msrc/buffer.hpp | 23+++++++++++++++++++++--
Msrc/link.cpp | 9++++++++-
2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/buffer.hpp b/src/buffer.hpp @@ -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_mem(Buf *buf, const char *mem, int mem_len) { + if (buf_len(buf) < mem_len) { + return false; + } + return memcmp(buf_ptr(buf), mem, mem_len) == 0; +} + static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) { - if (buf_len(buf) < buf_len(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 buf_eql_mem(sub, buf_ptr(buf), buf_len(sub)); + 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); diff --git a/src/link.cpp b/src/link.cpp @@ -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)); }