diff options
| author | ruki <[email protected]> | 2025-12-07 23:16:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-07 23:16:00 +0800 |
| commit | eecb6774a518fbe5df5c5820fa35bd3d8def8dd9 (patch) | |
| tree | 6e58f82c21a65a83020bbe69180fe2eedbb373b8 /xmake/rules/utils/bin2c/xmake.lua | |
| parent | 0187b34737611b7b194761ef1a241dd4ac6eee05 (diff) | |
improve bin2c
Diffstat (limited to 'xmake/rules/utils/bin2c/xmake.lua')
| -rw-r--r-- | xmake/rules/utils/bin2c/xmake.lua | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/xmake/rules/utils/bin2c/xmake.lua b/xmake/rules/utils/bin2c/xmake.lua index 7be711af1..9f6338758 100644 --- a/xmake/rules/utils/bin2c/xmake.lua +++ b/xmake/rules/utils/bin2c/xmake.lua @@ -29,32 +29,12 @@ rule("utils.bin2c") target:add("includedirs", headerdir) end) on_preparecmd_file(function (target, batchcmds, sourcefile_bin, opt) + import("rules.utils.bin2c.utils", {alias = "bin2c_utils", rootdir = os.programdir()}) - -- get header file - local headerdir = path.join(target:autogendir(), "rules", "utils", "bin2c") - local headerfile = path.join(headerdir, path.filename(sourcefile_bin) .. ".h") - target:add("includedirs", headerdir) - - -- add commands - batchcmds:show_progress(opt.progress, "${color.build.object}generating.bin2c %s", sourcefile_bin) - batchcmds:mkdir(headerdir) - local argv = {"-i", path(sourcefile_bin), "-o", path(headerfile)} - local linewidth = target:extraconf("rules", "utils.bin2c", "linewidth") - if linewidth then - table.insert(argv, "-w") - table.insert(argv, tostring(linewidth)) - end - -- get nozeroend (check file-level config first, then rule-level config) - local fileconfig = target:fileconfig(sourcefile_bin) - local nozeroend = (fileconfig and fileconfig.nozeroend) or target:extraconf("rules", "utils.bin2c", "nozeroend") or false - -- also support zeroend (inverse of nozeroend) - if fileconfig and fileconfig.zeroend ~= nil then - nozeroend = not fileconfig.zeroend - end - if nozeroend then - table.insert(argv, "--nozeroend") - end - batchcmds:vlua("utils.binary.bin2c", argv) + -- generate header file + local headerfile = bin2c_utils.generate_headerfile(target, batchcmds, sourcefile_bin, { + progress = opt.progress + }) -- add deps batchcmds:add_depfiles(sourcefile_bin) |
