summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-12 15:51:18 +0800
committerruki <[email protected]>2015-06-12 15:51:18 +0800
commit7693b33a4e39c66fa52af65c57c6f0ddaaf56bca (patch)
treec47556bf502843f4b9bcb72e4eae3eb3bc17f058 /xmake/scripts
parenteb0e6fe79d8e49d82bb600529028fcf28767a2d8 (diff)
output headers
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/makefile.lua13
-rw-r--r--xmake/scripts/base/rule.lua48
2 files changed, 61 insertions, 0 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 4a91c0b3d..12eb23765 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -119,6 +119,9 @@ function makefile._make_target(file, name, target)
local objfiles = rule.objectfiles(name, target, srcfiles)
assert(srcfiles and objfiles)
+ -- get source and destinate header files
+ local srcheaders, dstheaders = rule.headerfiles(target)
+
-- get target file
local targetfile = rule.targetfile(name, target)
assert(targetfile)
@@ -159,6 +162,16 @@ function makefile._make_target(file, name, target)
file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end)))
file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile)))
file:write(string.format("\t@%s > %s 2>&1\n", cmd, makefile._LOGFILE))
+ if srcheaders then
+ local i = 1
+ for _, srcheader in ipairs(srcheaders) do
+ local dstheader = dstheaders[i]
+ if dstheader then
+ file:write(string.format("\t@xmake l cp %s %s\n", srcheader, dstheader))
+ end
+ i = i + 1
+ end
+ end
-- make tail
file:write("\n")
diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua
index 321ceb8c6..0be7aaaab 100644
--- a/xmake/scripts/base/rule.lua
+++ b/xmake/scripts/base/rule.lua
@@ -26,6 +26,7 @@ local rule = rule or {}
-- load modules
local os = require("base/os")
local path = require("base/path")
+local table = require("base/table")
local utils = require("base/utils")
local config = require("base/config")
local platform = require("platform/platform")
@@ -186,5 +187,52 @@ function rule.sourcefiles(target)
return sourcefiles
end
+-- get the header files from the given target
+function rule.headerfiles(target)
+
+ -- check
+ assert(target)
+
+ -- no headers?
+ local headers = target.headers
+ if not headers then return end
+
+ -- get the headerdir
+ local headerdir = target.headerdir or config.get("buildir")
+ assert(headerdir)
+
+ -- get the source pathes and destinate pathes
+ local srcheaders = {}
+ local dstheaders = {}
+ for _, header in ipairs(utils.wrap(headers)) do
+
+ -- get the root directory
+ local rootdir = header:gsub("%(.*%)", "")
+
+ -- remove '(' and ')'
+ local srcpathes = header:gsub("[%(%)]", "")
+ if srcpathes then
+
+ -- get the source pathes
+ srcpathes = os.match(srcpathes)
+ if srcpathes then
+
+ -- add the source headers
+ table.join2(srcheaders, srcpathes)
+
+ -- add the destinate headers
+ local i = 1
+ for _, srcpath in ipairs(srcpathes) do
+ dstheaders[i] = path.absolute(path.relative(srcpath, rootdir), headerdir)
+ i = i + 1
+ end
+ end
+ end
+ end
+
+ -- ok?
+ return srcheaders, dstheaders
+end
+
-- return module: rule
return rule