diff options
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/binutils.lua | 61 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/binutils.lua | 62 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 13 |
4 files changed, 128 insertions, 16 deletions
diff --git a/xmake/core/base/binutils.lua b/xmake/core/base/binutils.lua new file mode 100644 index 000000000..b21de2276 --- /dev/null +++ b/xmake/core/base/binutils.lua @@ -0,0 +1,61 @@ +--!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 binutils.lua +-- + +-- define module +local binutils = binutils or {} + +-- save original interfaces +binutils._bin2c = binutils._bin2c or binutils.bin2c +binutils._bin2coff = binutils._bin2coff or binutils.bin2coff +binutils._bin2macho = binutils._bin2macho or binutils.bin2macho +binutils._bin2elf = binutils._bin2elf or binutils.bin2elf + +-- generate c/c++ code from the binary file +function binutils.bin2c(binaryfile, outputfile, opt) + opt = opt or {} + if binutils._bin2c then + return binutils._bin2c(binaryfile, outputfile, opt.linewidth or 32, opt.nozeroend or false) + else + -- fallback to old implementation if C implementation not available + return nil, "bin2c: C implementation not available" + end +end + +-- generate COFF object file from the binary file +function binutils.bin2coff(binaryfile, outputfile, opt) + opt = opt or {} + return binutils._bin2coff(binaryfile, outputfile, opt.symbol_prefix or "_binary_", opt.arch or "x86_64", opt.basename, opt.zeroend or false) +end + +-- generate Mach-O object file from the binary file +function binutils.bin2macho(binaryfile, outputfile, opt) + opt = opt or {} + return binutils._bin2macho(binaryfile, outputfile, opt.symbol_prefix or "_binary_", opt.plat or "macosx", opt.arch or "x86_64", opt.basename, opt.target_minver, opt.xcode_sdkver, opt.zeroend or false) +end + +-- generate ELF object file from the binary file +function binutils.bin2elf(binaryfile, outputfile, opt) + opt = opt or {} + return binutils._bin2elf(binaryfile, outputfile, opt.symbol_prefix or "_binary_", opt.arch or "x86_64", opt.basename, opt.zeroend or false) +end + +-- return module +return binutils + diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index ac9884851..ddf8c127f 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -30,8 +30,6 @@ local io = require("base/io") local dump = require("base/dump") local text = require("base/text") --- save original interfaces -utils._bin2c = utils._bin2c or utils.bin2c -- dump values function utils.dump(...) @@ -337,11 +335,5 @@ function utils.vtable(data, opt) utils.vprintf(text.table(data, opt)) end --- generate c/c++ code from the binary file -function utils.bin2c(binaryfile, outputfile, opt) - opt = opt or {} - return utils._bin2c(binaryfile, outputfile, opt.linewidth or 32, opt.nozeroend or false) -end - -- return module return utils diff --git a/xmake/core/sandbox/modules/import/core/base/binutils.lua b/xmake/core/sandbox/modules/import/core/base/binutils.lua new file mode 100644 index 000000000..38aad9b73 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/binutils.lua @@ -0,0 +1,62 @@ +--!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 binutils.lua +-- + +-- define module +local sandbox_core_base_binutils = sandbox_core_base_binutils or {} + +-- load modules +local binutils = require("base/binutils") +local raise = require("sandbox/modules/raise") + +-- generate c/c++ code from the binary file +function sandbox_core_base_binutils.bin2c(binaryfile, outputfile, opt) + local ok, errors = binutils.bin2c(binaryfile, outputfile, opt) + if not ok then + raise("bin2c: %s", errors or "unknown errors") + end +end + +-- generate COFF object file from the binary file +function sandbox_core_base_binutils.bin2coff(binaryfile, outputfile, opt) + local ok, errors = binutils.bin2coff(binaryfile, outputfile, opt) + if not ok then + raise("bin2coff: %s", errors or "unknown errors") + end +end + +-- generate Mach-O object file from the binary file +function sandbox_core_base_binutils.bin2macho(binaryfile, outputfile, opt) + local ok, errors = binutils.bin2macho(binaryfile, outputfile, opt) + if not ok then + raise("bin2macho: %s", errors or "unknown errors") + end +end + +-- generate ELF object file from the binary file +function sandbox_core_base_binutils.bin2elf(binaryfile, outputfile, opt) + local ok, errors = binutils.bin2elf(binaryfile, outputfile, opt) + if not ok then + raise("bin2elf: %s", errors or "unknown errors") + end +end + +-- return module +return sandbox_core_base_binutils + diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 88ccd6bac..df90492be 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -26,6 +26,7 @@ local colors = require("base/colors") local option = require("base/option") local log = require("base/log") local deprecated = require("base/deprecated") +local binutils = require("base/binutils") local try = require("sandbox/modules/try") local catch = require("sandbox/modules/catch") local vformat = require("sandbox/modules/vformat") @@ -148,14 +149,10 @@ function sandbox_utils.assert(value, format, ...) return value end --- generate c/c++ code from the binary file -if utils._bin2c then - function sandbox_utils.bin2c(binaryfile, outputfile, opt) - local ok, errors = utils.bin2c(binaryfile, outputfile, opt) - if not ok then - os.raise(errors) - end - end +-- generate c/c++ code from the binary file (deprecated, use binutils.bin2c instead) +function sandbox_utils.bin2c(binaryfile, outputfile, opt) + deprecated.add("binutils.bin2c", "utils.bin2c") + return binutils.bin2c(binaryfile, outputfile, opt) end -- return module |
