diff options
| author | ruki <[email protected]> | 2025-12-07 21:31:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-07 21:31:25 +0800 |
| commit | 4e4b28eb4cad79cc4df5fca887b4f4b709f2b211 (patch) | |
| tree | 8e9d3cf29071bf65d3b0a097deadabe25245cacf /xmake/core/base/binutils.lua | |
| parent | 40d790cf416c8677c51a8e969d421e85c25a019b (diff) | |
| parent | 8e3cc0092d8e356c6387aee941825cf66615541c (diff) | |
Merge pull request #7103 from xmake-io/bin2obj
Add bin2obj rule, will be faster than bin2c
Diffstat (limited to 'xmake/core/base/binutils.lua')
| -rw-r--r-- | xmake/core/base/binutils.lua | 61 |
1 files changed, 61 insertions, 0 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 + |
