summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-11 23:01:24 +0800
committerruki <[email protected]>2025-12-12 09:00:43 +0800
commitc8d424baeb7b93e2a1e900b271bcc09144fdce94 (patch)
tree6e506e2e9d264376b33258e97bf3f9e4440a80bf /xmake/modules
parent1c5e66f354ca526214845fa190f7d18a4960d89b (diff)
improve binutils and add cli modules
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/cli/binutils/bin2c.lua42
-rw-r--r--xmake/modules/cli/binutils/bin2obj.lua47
-rw-r--r--xmake/modules/utils/binary/bin2c.lua22
-rw-r--r--xmake/modules/utils/binary/bin2obj.lua27
-rw-r--r--xmake/modules/utils/binary/extractlib.lua19
5 files changed, 92 insertions, 65 deletions
diff --git a/xmake/modules/cli/binutils/bin2c.lua b/xmake/modules/cli/binutils/bin2c.lua
new file mode 100644
index 000000000..f2b03acdf
--- /dev/null
+++ b/xmake/modules/cli/binutils/bin2c.lua
@@ -0,0 +1,42 @@
+--!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, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file bin2c.lua
+--
+
+-- imports
+import("core.base.option")
+import("utils.binary.bin2c")
+
+local options = {
+ {'w', "linewidth", "kv", nil, "Set the line width"},
+ {nil, "nozeroend", "k", false, "Disable to patch zero terminating character"},
+ {'i', "binarypath", "kv", nil, "Set the binary file path."},
+ {'o', "outputpath", "kv", nil, "Set the output file path."}
+}
+
+function main(...)
+
+ -- parse arguments
+ local argv = {...}
+ local opt = option.parse(argv, options, "Print c/c++ code files from the given binary file."
+ , ""
+ , "Usage: xmake l cli.binutils.bin2c [options]")
+
+ -- do bin2c
+ bin2c.main(opt.binarypath, opt.outputpath, opt)
+end
diff --git a/xmake/modules/cli/binutils/bin2obj.lua b/xmake/modules/cli/binutils/bin2obj.lua
new file mode 100644
index 000000000..33eb0511e
--- /dev/null
+++ b/xmake/modules/cli/binutils/bin2obj.lua
@@ -0,0 +1,47 @@
+--!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, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file bin2obj.lua
+--
+
+-- imports
+import("core.base.option")
+import("utils.binary.bin2obj")
+
+local options = {
+ {'i', "binarypath", "kv", nil, "Set the binary file path."},
+ {'o', "outputpath", "kv", nil, "Set the output object file path."},
+ {'f', "format", "kv", nil, "Set the object file format (coff, elf, macho)."},
+ {nil, "symbol_prefix", "kv", nil, "Set the symbol prefix (default: _binary_)."},
+ {'a', "arch", "kv", nil, "Set the target architecture."},
+ {'p', "plat", "kv", nil, "Set the target platform (macosx, iphoneos, etc.)."},
+ {nil, "target_minver", "kv", nil, "Set the target minimum version (e.g., 10.0, 18.2)."},
+ {nil, "xcode_sdkver", "kv", nil, "Set the Xcode SDK version (e.g., 10.0, 18.2)."},
+ {nil, "zeroend", "k", nil, "Append a null terminator ('\\0') at the end of data."}
+}
+
+function main(...)
+
+ -- parse arguments
+ local argv = {...}
+ local opt = option.parse(argv, options, "Convert binary file to object file for direct linking."
+ , ""
+ , "Usage: xmake l cli.binutils.bin2obj [options]")
+
+ -- do bin2obj
+ bin2obj.main(opt.binarypath, opt.outputpath, opt)
+end
diff --git a/xmake/modules/utils/binary/bin2c.lua b/xmake/modules/utils/binary/bin2c.lua
index 34d9c4e02..7bbc797a4 100644
--- a/xmake/modules/utils/binary/bin2c.lua
+++ b/xmake/modules/utils/binary/bin2c.lua
@@ -20,16 +20,8 @@
-- imports
import("core.base.bytes")
-import("core.base.option")
import("core.base.binutils")
-local options = {
- {'w', "linewidth", "kv", nil, "Set the line width"},
- {nil, "nozeroend", "k", false, "Disable to patch zero terminating character"},
- {'i', "binarypath", "kv", nil, "Set the binary file path."},
- {'o', "outputpath", "kv", nil, "Set the output file path."}
-}
-
function _do_dump(binarydata, outputfile, opt)
local i = 0
local n = 147
@@ -71,7 +63,7 @@ function _do_dump(binarydata, outputfile, opt)
end
end
-function _do_bin2c(binarypath, outputpath, opt)
+function main(binarypath, outputpath, opt)
-- init source directory and options
opt = opt or {}
@@ -117,15 +109,3 @@ function _do_bin2c(binarypath, outputpath, opt)
cprint("${bright}%s generated!", outputpath)
end
-function main(...)
-
- -- parse arguments
- local argv = {...}
- local opt = option.parse(argv, options, "Print c/c++ code files from the given binary file."
- , ""
- , "Usage: xmake l utils.binary.bin2c [options]")
-
- -- do bin2c
- _do_bin2c(opt.binarypath, opt.outputpath, opt)
-end
-
diff --git a/xmake/modules/utils/binary/bin2obj.lua b/xmake/modules/utils/binary/bin2obj.lua
index 95e705ca6..13ff633e1 100644
--- a/xmake/modules/utils/binary/bin2obj.lua
+++ b/xmake/modules/utils/binary/bin2obj.lua
@@ -19,22 +19,9 @@
--
-- imports
-import("core.base.option")
import("core.base.binutils")
-local options = {
- {'i', "binarypath", "kv", nil, "Set the binary file path."},
- {'o', "outputpath", "kv", nil, "Set the output object file path."},
- {'f', "format", "kv", nil, "Set the object file format (coff, elf, macho)."},
- {nil, "symbol_prefix", "kv", nil, "Set the symbol prefix (default: _binary_)."},
- {'a', "arch", "kv", nil, "Set the target architecture."},
- {'p', "plat", "kv", nil, "Set the target platform (macosx, iphoneos, etc.)."},
- {nil, "target_minver", "kv", nil, "Set the target minimum version (e.g., 10.0, 18.2)."},
- {nil, "xcode_sdkver", "kv", nil, "Set the Xcode SDK version (e.g., 10.0, 18.2)."},
- {nil, "zeroend", "k", nil, "Append a null terminator ('\\0') at the end of data."}
-}
-
-function _do_bin2obj(binarypath, outputpath, opt)
+function main(binarypath, outputpath, opt)
-- init source directory and options
opt = opt or {}
binarypath = path.absolute(binarypath)
@@ -66,15 +53,3 @@ function _do_bin2obj(binarypath, outputpath, opt)
cprint("${bright}%s generated!", outputpath)
end
-function main(...)
-
- -- parse arguments
- local argv = {...}
- local opt = option.parse(argv, options, "Convert binary file to object file for direct linking."
- , ""
- , "Usage: xmake l utils.binary.bin2obj [options]")
-
- -- do bin2obj
- _do_bin2obj(opt.binarypath, opt.outputpath, opt)
-end
-
diff --git a/xmake/modules/utils/binary/extractlib.lua b/xmake/modules/utils/binary/extractlib.lua
index d707ac22f..9097db73a 100644
--- a/xmake/modules/utils/binary/extractlib.lua
+++ b/xmake/modules/utils/binary/extractlib.lua
@@ -19,15 +19,9 @@
--
-- imports
-import("core.base.option")
import("core.base.binutils")
-local options = {
- {'i', "libraryfile", "kv", nil, "Set the static library file path (.a or .lib)."},
- {'o', "outputdir", "kv", nil, "Set the output directory to extract object files."}
-}
-
-function _do_extractlib(libraryfile, outputdir)
+function main(libraryfile, outputdir)
-- init paths
libraryfile = path.absolute(libraryfile)
outputdir = path.absolute(outputdir)
@@ -48,14 +42,3 @@ function _do_extractlib(libraryfile, outputdir)
cprint("${bright}extraction completed!")
end
-function main(...)
- -- parse arguments
- local argv = {...}
- local opt = option.parse(argv, options, "Extract object files from static library (AR or MSVC lib format)."
- , ""
- , "Usage: xmake l utils.binary.extractlib [options]")
-
- -- do extractlib
- _do_extractlib(opt.libraryfile, opt.outputdir)
-end
-