diff options
| author | ruki <[email protected]> | 2020-07-09 22:06:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-07-09 06:36:19 +0800 |
| commit | 57c15ee42343b7ca4c9b5b860aff9a27b266ae3d (patch) | |
| tree | 50ef27e845e86b8e4dcc5154f7aa54f149a3deb6 /xmake/modules/core/tools/zig.lua | |
| parent | 519535ca82c093b011ccec2ba4c8378c117f72c0 (diff) | |
improve zig
Diffstat (limited to 'xmake/modules/core/tools/zig.lua')
| -rw-r--r-- | xmake/modules/core/tools/zig.lua | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/zig.lua b/xmake/modules/core/tools/zig.lua index 1b41bff17..6e6969dbb 100644 --- a/xmake/modules/core/tools/zig.lua +++ b/xmake/modules/core/tools/zig.lua @@ -22,12 +22,83 @@ import("core.base.option") import("core.project.config") import("core.project.project") +import("core.project.target") -- init it function init(self) -- init shflags - self:set("zcshflags", "-dynamic") + self:set("zcshflags", "-dynamic", "-fPIC") + + -- init zcflags for the kind: shared + self:set("shared.zcflags", "-fPIC") +end + +-- make the strip flag +function nf_strip(self, level) + local maps = + { + debug = "--strip" + , all = "--strip" + } + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + none = "-O0" + , fast = "--release-safe" + , aggressive = "--release-fast" + , fastest = "--release-fast" + , smallest = "--release-small" + , aggressive = "--release-fast" + } + return maps[level] +end + +-- make the link flag +function nf_link(self, lib) + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L" .. os.args(dir) +end + +-- make the framework flag +function nf_framework(self, framework) + return "-framework " .. framework +end + +-- make the frameworkdir flag +function nf_frameworkdir(self, frameworkdir) + return "-F " .. os.args(path.translate(frameworkdir)) +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir) + dir = path.translate(dir) + if is_plat("macosx") then + return "-rpath " .. os.args(dir:gsub("%$ORIGIN", "@loader_path")) + else + return "-rpath " .. os.args(dir:gsub("@[%w_]+", function (name) + local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} + return maps[name] + end)) + end end -- make the link arguments list @@ -40,7 +111,8 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags) else raise("unknown target kind(%s)!", targetkind) end - table.join2(argv, flags, "--output-dir", path.directory(targetfile), "--name", path.basename(targetfile), "--object", objectfiles) + local name = targetkind == "binary" and path.basename(targetfile) or target.linkname(path.filename(targetfile)) + table.join2(argv, flags, "--output-dir", path.directory(targetfile), "--name", name, "--object", objectfiles) return self:program(), argv end |
