diff options
| author | ruki <[email protected]> | 2015-05-19 15:35:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-19 15:35:49 +0800 |
| commit | 75bdd1517bc093774855c23a286e97113896f5f0 (patch) | |
| tree | 4dd3eded914ea143c39fb05480babc5b603123da /xmake/scripts | |
| parent | f9214c5e20b64d662af20b83da5889e6675dea95 (diff) | |
make object deps for makefile
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 75 | ||||
| -rw-r--r-- | xmake/scripts/platform/_macosx.lua | 21 | ||||
| -rw-r--r-- | xmake/scripts/platform/platform.lua | 20 |
3 files changed, 90 insertions, 26 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 80ef7aa45..a54f74199 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -26,11 +26,77 @@ local makefile = makefile or {} -- load modules local io = require("base/io") local os = require("base/os") +local path = require("base/path") local utils = require("base/utils") local config = require("base/config") local project = require("base/project") local platform = require("platform/platform") +-- get the source files from the given target +function makefile._srcfiles(target) + + -- check + assert(target) + + -- no files? + if not target.files then + return nil + end + + -- wrap files first + local target_files = utils.wrap(target.files) + + -- match files + local i = 1 + local srcfiles = {} + for _, target_file in ipairs(target_files) do + + -- match source files + local files = os.match(target_file) + + -- process source files + for _, file in ipairs(files) do + + -- save it + srcfiles[i] = file + i = i + 1 + + end + end + + -- ok? + return srcfiles +end + +-- get object files for the given source files +function makefile._objfiles(srcfiles) + + -- check + assert(srcfiles) + + -- the platform configs + local configs = platform._CONFIGS + assert(configs and configs.format) + + -- the object file format + local format = configs.format.object + assert(format) + + -- make object files + local i = 1 + local objfiles = {} + for _, srcfile in ipairs(srcfiles) do + + -- save it + objfiles[i] = path.directory(srcfile) .. "/" .. format[1] .. path.basename(srcfile) .. format[2] + i = i + 1 + + end + + -- ok? + return objfiles +end + -- make the given target to the makefile function makefile._make_target(file, name, target) @@ -49,9 +115,12 @@ function makefile._make_target(file, name, target) end -- make dependence for object - local srcfiles = os.match(target.files) - for _, srcfile in ipairs(srcfiles) do - file:write(" " .. srcfile) + local srcfiles = makefile._srcfiles(target) + if srcfiles then + local objfiles = makefile._objfiles(srcfiles) + for _, objfile in ipairs(objfiles) do + file:write(" " .. path.translate(objfile)) + end end -- make dependence end diff --git a/xmake/scripts/platform/_macosx.lua b/xmake/scripts/platform/_macosx.lua index 428d2ae02..3a3879730 100644 --- a/xmake/scripts/platform/_macosx.lua +++ b/xmake/scripts/platform/_macosx.lua @@ -24,23 +24,16 @@ local _macosx = _macosx or {} -- init _macosx -function _macosx.init() +function _macosx.init(configs) - -- init configs - local configs = {} - - -- init the target file suffix name - configs.suffix = {} - configs.suffix.static = ".a" - configs.suffix.object = ".o" - configs.suffix.shared = ".dylib" - - -- init the target file prefix name - configs.prefix = {} - configs.prefix.static = "lib" + -- init the file name format + configs.format = {} + configs.format.static = {"lib", ".a"} + configs.format.object = {"", ".o"} + configs.format.shared = {"", ".dylib"} -- ok - return configs + return true end diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua index 47ccb4914..6ee8de802 100644 --- a/xmake/scripts/platform/platform.lua +++ b/xmake/scripts/platform/platform.lua @@ -30,26 +30,28 @@ local config = require("base/config") -- init platform function platform.init() - -- have been existed? - if platform._CONFIGS then - return platform._CONFIGS - end + -- init platform configs + platform._CONFIGS = platform._CONFIGS or {} + local configs = platform._CONFIGS -- get target local target = config.target() assert(target) + -- init configs + configs.plat = target.plat + configs.host = target.host + configs.arch = target.arch + configs.mode = target.mode + -- load platform local p = require("platform/_" .. target.plat) if not p then - return nil + return false end -- init platform - platform._CONFIGS = p.init() - - -- ok? - return platform._CONFIGS + return p.init(configs) end -- dump configs |
