summaryrefslogtreecommitdiff
path: root/xmake/rules/utils/bin2c/xmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-05 00:29:18 +0800
committerruki <[email protected]>2021-08-05 00:29:18 +0800
commitb700ce5f896f1a3edfadafb4c188d1f147ea4ac7 (patch)
tree298f5a01927bc8ce08eb5d0911f9f11d3f330d0d /xmake/rules/utils/bin2c/xmake.lua
parent87d159290c9d9f5ad00e26640cb091f6ac068d05 (diff)
add bin2c module
Diffstat (limited to 'xmake/rules/utils/bin2c/xmake.lua')
-rw-r--r--xmake/rules/utils/bin2c/xmake.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/xmake/rules/utils/bin2c/xmake.lua b/xmake/rules/utils/bin2c/xmake.lua
new file mode 100644
index 000000000..658bf113a
--- /dev/null
+++ b/xmake/rules/utils/bin2c/xmake.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, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+rule("utils.bin2c")
+ set_extensions(".bin")
+ on_load(function (target)
+ local headerdir = path.join(target:autogendir(), "rules", "c++", "bin2c")
+ if not os.isfile(headerdir) then
+ os.mkdir(headerdir)
+ end
+ target:add("includedirs", headerdir)
+ end)
+ before_buildcmd_file(function (target, batchcmds, sourcefile_bin, opt)
+
+ -- get header file
+ local headerdir = path.join(target:autogendir(), "rules", "c++", "bin2c")
+ local headerfile = path.join(headerdir, (sourcefile_bin:gsub("%.", "_")) .. ".h")
+
+ -- add commands
+ batchcmds:show_progress(opt.progress, "${color.build.object}generating.header %s", sourcefile_bin)
+ batchcmds:mkdir(headerdir)
+ local argv = {"-i", sourcefile_bin, "-o", headerfile, "-w", "32"}
+ batchcmds:vrunv(os.programfile(), argv)
+
+ -- add deps
+ batchcmds:add_depfiles(sourcefile_bin)
+ batchcmds:set_depmtime(os.mtime(headerfile))
+ batchcmds:set_depcache(target:dependfile(headerfile))
+ end)
+