diff options
| author | ruki <[email protected]> | 2015-06-11 16:58:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-11 16:58:01 +0800 |
| commit | 882430fde4f0066e9adbbb664b98612fa4cf3bc1 (patch) | |
| tree | f5eeeb2961d22bfd68a80d95404e07396791336e /xmake/scripts/base | |
| parent | 76fd1ccaf43262df8fae3d9d3bfba1c2f0e04ca5 (diff) | |
add self for tools
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 84 | ||||
| -rw-r--r-- | xmake/scripts/base/linker.lua | 26 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 2 |
3 files changed, 62 insertions, 50 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 23796d403..50bf38c5c 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -47,7 +47,13 @@ function compiler._mapflag(module, flag) -- find and replace it using pattern for k, v in pairs(module.mapflags) do - local flag_mapped, count = flag:gsub(k, v) + local flag_mapped, count = flag:gsub(k, function (w) + if type(v) == "function" then + return v(module, w) + else + return v + end + end) if flag_mapped and count ~= 0 then return utils.ifelse(#flag_mapped ~= 0, flag_mapped, nil) end @@ -126,8 +132,8 @@ function compiler._flagnames(name) return flagnames end --- get the compiler name from the source file type -function compiler._name(srcfile) +-- get the compiler kind from the source file type +function compiler._kind(srcfile) -- get the source file type local filetype = path.extension(srcfile) @@ -138,30 +144,30 @@ function compiler._name(srcfile) -- get the lower file type filetype = filetype:lower() - -- get the compiler name - local name = nil - if filetype == ".c" then name = "cc" - elseif filetype == ".cpp" or filetype == ".cc" then name = "cxx" - elseif filetype == ".m" then name = "mm" - elseif filetype == ".mm" then name = "mxx" - elseif filetype == ".s" or filetype == ".asm" then name = "as" + -- get the compiler kind + local kind = nil + if filetype == ".c" then kind = "cc" + elseif filetype == ".cpp" or filetype == ".cc" then kind = "cxx" + elseif filetype == ".m" then kind = "mm" + elseif filetype == ".mm" then kind = "mxx" + elseif filetype == ".s" or filetype == ".asm" then kind = "as" end -- ok - return name + return kind end -- get the compiler from the given source file function compiler.get(srcfile) - -- get the compiler name - local name = compiler._name(srcfile) - if not name then + -- get the compiler kind + local kind = compiler._kind(srcfile) + if not kind then return end -- get compiler from the source file type - local module = tools.get(name) + local module = tools.get(kind) if module then -- invalid compiler @@ -169,8 +175,8 @@ function compiler.get(srcfile) return end - -- save name - module._NAME = name + -- save kind + module._KIND = kind end -- ok? @@ -184,7 +190,7 @@ function compiler.make(module, target, srcfile, objfile) assert(module and target) -- the flag names - local flagnames = compiler._flagnames(module._NAME) + local flagnames = compiler._flagnames(module._KIND) assert(flagnames) -- append the common flags from the current compiler @@ -247,21 +253,21 @@ function compiler.make(module, target, srcfile, objfile) -- append the includedirs flags from the current project if module.flag_includedir then for _, includedir in ipairs(utils.wrap(target.includedirs)) do - table.join2(flags, module.flag_includedir(includedir)) + table.join2(flags, module:flag_includedir(includedir)) end end -- append the defines flags from the current project if module.flag_define then for _, define in ipairs(utils.wrap(target.defines)) do - table.join2(flags, module.flag_define(define)) + table.join2(flags, module:flag_define(define)) end end -- append the undefines flags from the current project if module.flag_undefine then for _, undefine in ipairs(utils.wrap(target.undefines)) do - table.join2(flags, module.flag_undefine(undefine)) + table.join2(flags, module:flag_undefine(undefine)) end end @@ -282,7 +288,7 @@ function compiler.make(module, target, srcfile, objfile) -- append the includedirs flags from the option if module.flag_includedir then for _, includedir in ipairs(utils.wrap(opt.includedirs)) do - table.join2(flags, module.flag_includedir(includedir)) + table.join2(flags, module:flag_includedir(includedir)) end end @@ -294,7 +300,7 @@ function compiler.make(module, target, srcfile, objfile) if opt.defines_if_ok then table.join2(defines, opt.defines_if_ok) end for _, define in ipairs(defines) do - table.join2(flags, module.flag_define(define)) + table.join2(flags, module:flag_define(define)) end end @@ -306,7 +312,7 @@ function compiler.make(module, target, srcfile, objfile) if opt.undefines_if_ok then table.join2(undefines, opt.undefines_if_ok) end for _, undefine in ipairs(undefines) do - table.join2(flags, module.flag_undefine(undefine)) + table.join2(flags, module:flag_undefine(undefine)) end end end @@ -319,7 +325,7 @@ function compiler.make(module, target, srcfile, objfile) end -- make the compile command - return module.command_compile(srcfile, objfile, table.concat(flags, " "):trim()) + return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim()) end -- check include for the project option @@ -351,7 +357,7 @@ function compiler.check_include(opt, include, srcpath, objpath) if not module then return end -- the flag names - local flagnames = compiler._flagnames(module._NAME) + local flagnames = compiler._flagnames(module._KIND) assert(flagnames) -- append the common flags @@ -369,7 +375,7 @@ function compiler.check_include(opt, include, srcpath, objpath) if opt.defines and module.flag_define then local defines = utils.wrap(opt.defines) for _, define in ipairs(defines) do - table.join2(flags, module.flag_define(define)) + table.join2(flags, module:flag_define(define)) end end @@ -377,23 +383,23 @@ function compiler.check_include(opt, include, srcpath, objpath) if opt.undefines and module.flag_undefine then local undefines = utils.wrap(opt.undefines) for _, undefine in ipairs(undefines) do - table.join2(flags, module.flag_undefine(undefine)) + table.join2(flags, module:flag_undefine(undefine)) end end -- append the includedirs flags if opt.includedirs and module.flag_includedir then for _, includedir in ipairs(utils.wrap(opt.includedirs)) do - table.join2(flags, module.flag_includedir(includedir)) + table.join2(flags, module:flag_includedir(includedir)) end end -- make the compile command - local cmd = string.format("%s > %s 2>&1", module.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) + local cmd = string.format("%s > %s 2>&1", module:command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) if not cmd then return end -- execute the compile command - return module.main(cmd) + return module:main(cmd) end -- check function for the project option @@ -412,8 +418,8 @@ function compiler.check_function(opt, interface, srcpath, objpath) -- make includes local includes = nil - if module._NAME == "cc" then includes = opt.cincludes - elseif module._NAME == "cxx" then includes = opt.cxxincludes + if module._KIND == "cc" then includes = opt.cincludes + elseif module._KIND == "cxx" then includes = opt.cxxincludes end if includes then for _, include in ipairs(utils.wrap(includes)) do @@ -437,7 +443,7 @@ function compiler.check_function(opt, interface, srcpath, objpath) srcfile:close() -- the flag names - local flagnames = compiler._flagnames(module._NAME) + local flagnames = compiler._flagnames(module._KIND) assert(flagnames) -- append the common flags @@ -455,7 +461,7 @@ function compiler.check_function(opt, interface, srcpath, objpath) if opt.defines and module.flag_define then local defines = utils.wrap(opt.defines) for _, define in ipairs(defines) do - table.join2(flags, module.flag_define(define)) + table.join2(flags, module:flag_define(define)) end end @@ -463,23 +469,23 @@ function compiler.check_function(opt, interface, srcpath, objpath) if opt.undefines and module.flag_undefine then local undefines = utils.wrap(opt.undefines) for _, undefine in ipairs(undefines) do - table.join2(flags, module.flag_undefine(undefine)) + table.join2(flags, module:flag_undefine(undefine)) end end -- append the includedirs flags if opt.includedirs and module.flag_includedir then for _, includedir in ipairs(utils.wrap(opt.includedirs)) do - table.join2(flags, module.flag_includedir(includedir)) + table.join2(flags, module:flag_includedir(includedir)) end end -- make the compile command - local cmd = string.format("%s > %s 2>&1", module.command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) + local cmd = string.format("%s > %s 2>&1", module:command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) if not cmd then return end -- execute the compile command - return module.main(cmd) + return module:main(cmd) end -- return module: compiler diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua index befab7b7c..0019ca6b9 100644 --- a/xmake/scripts/base/linker.lua +++ b/xmake/scripts/base/linker.lua @@ -44,7 +44,13 @@ function linker._mapflag(module, flag) -- find and replace it using pattern for k, v in pairs(module.mapflags) do - local flag_mapped, count = flag:gsub(k, v) + local flag_mapped, count = flag:gsub(k, function (w) + if type(v) == "function" then + return v(module, w) + else + return v + end + end) if flag_mapped and count ~= 0 then return utils.ifelse(#flag_mapped ~= 0, flag_mapped, nil) end @@ -156,14 +162,14 @@ function linker.make(module, target, objfiles, targetfile) -- append the linkdirs flags from the current project if module.flag_linkdir then for _, linkdir in ipairs(utils.wrap(target.linkdirs)) do - table.join2(flags, module.flag_linkdir(linkdir)) + table.join2(flags, module:flag_linkdir(linkdir)) end end -- append the links flags from the current project if module.flag_link then for _, link in ipairs(utils.wrap(target.links)) do - table.join2(flags, module.flag_link(link)) + table.join2(flags, module:flag_link(link)) end end @@ -182,14 +188,14 @@ function linker.make(module, target, objfiles, targetfile) -- append the linkdirs flags from the option if module.flag_linkdir then for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do - table.join2(flags, module.flag_linkdir(linkdir)) + table.join2(flags, module:flag_linkdir(linkdir)) end end -- append the links flags from the option if module.flag_link then for _, link in ipairs(utils.wrap(opt.links)) do - table.join2(flags, module.flag_link(link)) + table.join2(flags, module:flag_link(link)) end end end @@ -204,7 +210,7 @@ function linker.make(module, target, objfiles, targetfile) })) -- make the link command - return module.command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim()) + return module:command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim()) end -- check link for the project option @@ -227,21 +233,21 @@ function linker.check_links(opt, links, objectfile, targetfile) -- append the linkdirs flags if opt.linkdirs and module.flag_linkdir then for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do - table.join2(flags, module.flag_linkdir(linkdir)) + table.join2(flags, module:flag_linkdir(linkdir)) end end -- append the links flags for _, link in ipairs(utils.wrap(links)) do - table.join2(flags, module.flag_link(link)) + table.join2(flags, module:flag_link(link)) end -- make the compile command - local cmd = string.format("%s > %s 2>&1", module.command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV) + local cmd = string.format("%s > %s 2>&1", module:command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV) if not cmd then return end -- execute the link command - return module.main(cmd) + return module:main(cmd) end -- return module: linker diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 6ad63490b..ba939790a 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -273,7 +273,7 @@ function makefile.build(target) end -- done make - return make.main(buildir .. "/makefile", target) + return make:main(buildir .. "/makefile", target) end -- return module: makefile |
