summaryrefslogtreecommitdiff
path: root/xmake/rules
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-07 23:51:40 +0800
committerruki <[email protected]>2022-02-07 23:51:40 +0800
commit4ec0ff6570e24ed3e2434cc9f81c728fd002f20c (patch)
tree959d09f1a9635dd066c61a3ed2dab93495805bc8 /xmake/rules
parentc88d9afcb3e929d6c0a4f3644399ac3df572829f (diff)
update changelog
Diffstat (limited to 'xmake/rules')
-rw-r--r--xmake/rules/asm/xmake.lua7
-rw-r--r--xmake/rules/c++/xmake.lua4
-rw-r--r--xmake/rules/dlang/xmake.lua4
-rw-r--r--xmake/rules/linker/link_scripts/xmake.lua49
-rw-r--r--xmake/rules/linker/version_scripts/xmake.lua50
-rw-r--r--xmake/rules/platform/windows/def/xmake.lua15
-rw-r--r--xmake/rules/platform/windows/manifest/xmake.lua15
7 files changed, 132 insertions, 12 deletions
diff --git a/xmake/rules/asm/xmake.lua b/xmake/rules/asm/xmake.lua
index 153bc4802..d916af720 100644
--- a/xmake/rules/asm/xmake.lua
+++ b/xmake/rules/asm/xmake.lua
@@ -38,3 +38,10 @@ rule("asm")
-- we attempt to extract symbols to the independent file and
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
+
+ -- add platform rules
+ add_deps("platform.windows")
+
+ -- add linker rules
+ add_deps("linker.link_scripts", "linker.version_scripts")
+
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 14dc961d3..77223d0df 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -64,3 +64,7 @@ rule("c++")
-- add platform rules
add_deps("platform.windows")
+
+ -- add linker rules
+ add_deps("linker.link_scripts", "linker.version_scripts")
+
diff --git a/xmake/rules/dlang/xmake.lua b/xmake/rules/dlang/xmake.lua
index 0b4a5ff07..748026e85 100644
--- a/xmake/rules/dlang/xmake.lua
+++ b/xmake/rules/dlang/xmake.lua
@@ -38,3 +38,7 @@ rule("dlang")
-- we attempt to extract symbols to the independent file and
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
+
+ -- add linker rules
+ add_deps("linker.version_scripts")
+
diff --git a/xmake/rules/linker/link_scripts/xmake.lua b/xmake/rules/linker/link_scripts/xmake.lua
new file mode 100644
index 000000000..fdd714988
--- /dev/null
+++ b/xmake/rules/linker/link_scripts/xmake.lua
@@ -0,0 +1,49 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+rule("linker.link_scripts")
+ set_extensions(".ld", ".lds")
+ on_config(function (target)
+ if not target:is_binary() and not target:is_shared() then
+ return
+ end
+ local scriptfile
+ local sourcebatch = target:sourcebatches()["linker.link_scripts"]
+ if sourcebatch then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ scriptfile = sourcefile
+ break
+ end
+ end
+ if not scriptfile then
+ return
+ end
+ -- @note apple's linker does not support it
+ if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
+ return
+ end
+ if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or
+ target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
+ target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true})
+ elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then
+ target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true})
+ end
+ end)
+
diff --git a/xmake/rules/linker/version_scripts/xmake.lua b/xmake/rules/linker/version_scripts/xmake.lua
new file mode 100644
index 000000000..3f5a901b1
--- /dev/null
+++ b/xmake/rules/linker/version_scripts/xmake.lua
@@ -0,0 +1,50 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+rule("linker.version_scripts")
+ set_extensions(".ver", ".map")
+ on_config(function (target)
+ if not target:is_binary() and not target:is_shared() then
+ return
+ end
+ local scriptfile
+ local sourcebatch = target:sourcebatches()["linker.version_scripts"]
+ if sourcebatch then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ scriptfile = sourcefile
+ break
+ end
+ end
+ if not scriptfile then
+ return
+ end
+ -- @note apple's linker does not support it
+ if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
+ return
+ end
+ if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or
+ target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
+ target:add(target:is_shared() and "shflags" or "ldflags", "-Wl,--version-script=" .. scriptfile, {force = true})
+ elseif target:has_tool("ld", "dmd") or target:has_tool("sh", "dmd") then
+ target:add(target:is_shared() and "shflags" or "ldflags", "-L--version-script=" .. scriptfile, {force = true})
+ elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then
+ target:add(target:is_shared() and "shflags" or "ldflags", "--version-script=" .. scriptfile, {force = true})
+ end
+ end)
diff --git a/xmake/rules/platform/windows/def/xmake.lua b/xmake/rules/platform/windows/def/xmake.lua
index 7919553de..545d61fd1 100644
--- a/xmake/rules/platform/windows/def/xmake.lua
+++ b/xmake/rules/platform/windows/def/xmake.lua
@@ -22,12 +22,15 @@
rule("platform.windows.def")
set_extensions(".def")
on_config("windows", function (target)
- if target:has_tool("ld", "link") then
- for _, sourcebatch in pairs(target:sourcebatches()) do
- if sourcebatch.rulename == "platform.windows.def" then
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- target:add("shflags", "/def:" .. path.translate(sourcefile), {force = true})
- end
+ if not target:is_shared() then
+ return
+ end
+ if target:has_tool("sh", "link") then
+ local sourcebatch = target:sourcebatches()["platform.windows.def"]
+ if sourcebatch then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ target:add("shflags", "/def:" .. path.translate(sourcefile), {force = true})
+ break;
end
end
end
diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua
index fbcfe36d4..e791d9398 100644
--- a/xmake/rules/platform/windows/manifest/xmake.lua
+++ b/xmake/rules/platform/windows/manifest/xmake.lua
@@ -23,14 +23,17 @@
rule("platform.windows.manifest")
set_extensions(".manifest")
on_config("windows", function (target)
+ if not target:is_binary() then
+ return
+ end
if target:has_tool("ld", "link") then
local manifest = false
- for _, sourcebatch in pairs(target:sourcebatches()) do
- if sourcebatch.rulename == "platform.windows.manifest" then
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- target:add("ldflags", "/ManifestInput:" .. path.translate(sourcefile), {force = true})
- manifest = true
- end
+ local sourcebatch = target:sourcebatches()["platform.windows.manifest"]
+ if sourcebatch then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ target:add("ldflags", "/ManifestInput:" .. path.translate(sourcefile), {force = true})
+ manifest = true
+ break
end
end
if manifest then