diff options
| author | ruki <[email protected]> | 2015-06-17 10:00:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-17 10:00:20 +0800 |
| commit | 95798306093295a45c8f8671ca2f18edb16f796e (patch) | |
| tree | 50fb9cda7beb32f206d0984561d1678a58c165db /xmake/scripts | |
| parent | 12fca34edc350acfa1688bccb3a9e954b71283b0 (diff) | |
check c and c++ types
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_create.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/action/_debug.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/action/_install.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/action/_man.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 99 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 60 | ||||
| -rw-r--r-- | xmake/scripts/tools/crun.lua | 60 |
7 files changed, 129 insertions, 98 deletions
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua index 59aac8a55..17f569bd6 100644 --- a/xmake/scripts/action/_create.lua +++ b/xmake/scripts/action/_create.lua @@ -31,6 +31,8 @@ local platform = require("platform/platform") -- done the given config function _create.done() + -- TODO + print("not implement!") -- ok return true diff --git a/xmake/scripts/action/_debug.lua b/xmake/scripts/action/_debug.lua index 141d92fa4..859191c26 100644 --- a/xmake/scripts/action/_debug.lua +++ b/xmake/scripts/action/_debug.lua @@ -31,6 +31,8 @@ local platform = require("platform/platform") -- done the given config function _debug.done() + -- TODO + print("not implement!") -- ok return true diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua index af7edc104..049251d40 100644 --- a/xmake/scripts/action/_install.lua +++ b/xmake/scripts/action/_install.lua @@ -31,6 +31,8 @@ local platform = require("platform/platform") -- done the given config function _install.done() + -- TODO + print("not implement!") -- ok return true diff --git a/xmake/scripts/action/_man.lua b/xmake/scripts/action/_man.lua index bd8df690b..25fa3340a 100644 --- a/xmake/scripts/action/_man.lua +++ b/xmake/scripts/action/_man.lua @@ -31,6 +31,8 @@ local platform = require("platform/platform") -- done the given config function _man.done() + -- TODO + print("not implement!") -- ok return true diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 0b7c5115d..3bb42cb81 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -387,6 +387,33 @@ function compiler._kind(srcfile) return kind end +-- make the compile command for option +function compiler._make_for_option(module, opt, srcfile, objfile, logfile) + + -- check + assert(module and opt) + + -- the flag names + local flagnames = compiler._flagnames(module._KIND) + assert(flagnames) + + -- add flags from the compiler + local flags = {} + compiler._addflags_from_compiler(module, flags, flagnames) + + -- add flags from the platform + compiler._addflags_from_platform(module, flags, flagnames) + + -- add flags from the option + compiler._addflags_from_option(module, flags, flagnames, opt) + + -- add flags from the configure + compiler._addflags_from_config(module, flags, flagnames) + + -- execute the compile command + return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim(), logfile) +end + -- get the compiler from the given source file function compiler.get(srcfile) @@ -470,25 +497,8 @@ function compiler.check_include(opt, include, srcpath, objpath) local module = compiler.get(srcpath) if not module then return end - -- the flag names - local flagnames = compiler._flagnames(module._KIND) - assert(flagnames) - - -- add flags from the compiler - local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) - - -- add flags from the platform - compiler._addflags_from_platform(module, flags, flagnames) - - -- add flags from the option - compiler._addflags_from_option(module, flags, flagnames, opt) - - -- add flags from the configure - compiler._addflags_from_config(module, flags, flagnames) - -- execute the compile command - return module:main(module:command_compile(srcpath, objpath, table.concat(flags, " "):trim(), xmake._NULDEV)) + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) end -- check function for the project option @@ -531,25 +541,52 @@ function compiler.check_function(opt, interface, srcpath, objpath) -- exit this file srcfile:close() - -- the flag names - local flagnames = compiler._flagnames(module._KIND) - assert(flagnames) + -- execute the compile command + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) +end - -- add flags from the compiler - local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) +-- check typedef for the project option +function compiler.check_typedef(opt, typedef, srcpath, objpath) - -- add flags from the platform - compiler._addflags_from_platform(module, flags, flagnames) + -- check + assert(opt and typedef) - -- add flags from the option - compiler._addflags_from_option(module, flags, flagnames, opt) + -- open the checking source file + local srcfile = io.openmk(srcpath) + if not srcfile then return end - -- add flags from the configure - compiler._addflags_from_config(module, flags, flagnames) + -- get the compiler + local module = compiler.get(srcpath) + if not module then return end + + -- make includes + local includes = nil + 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 + srcfile:write(string.format("#include <%s>\n", include)) + end + srcfile:write("\n") + end + + -- make the main function header + srcfile:write("int main(int argc, char** argv)\n") + srcfile:write("{\n") + + -- make interfaces + srcfile:write(string.format(" typedef %s __type_xxx;\n\n", typedef)) + + -- make the main function tailer + srcfile:write(" return 0;\n") + srcfile:write("}\n") + + -- exit this file + srcfile:close() -- execute the compile command - return module:main(module:command_compile(srcpath, objpath, table.concat(flags, " "):trim(), xmake._NULDEV)) + return module:main(compiler._make_for_option(module, opt, srcpath, objpath, xmake._NULDEV)) end -- return module: compiler diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 9f6aaef38..41b754a45 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -644,6 +644,46 @@ function project._make_option_for_checking_cxxfuncs(opt, cxxfuncs, cxxfile, obje return true end +-- make option for checking ctypes +function project._make_option_for_checking_ctypes(opt, ctypes, cfile, objectfile, targetfile) + + -- done + for _, ctype in ipairs(utils.wrap(ctypes)) do + + -- check type + local ok = compiler.check_typedef(opt, ctype, cfile, objectfile) + + -- trace + utils.verbose("checking for the c type %s ... %s", ctype, utils.ifelse(ok, "ok", "no")) + + -- failed + if not ok then return false end + end + + -- ok + return true +end + +-- make option for checking cxxtypes +function project._make_option_for_checking_cxxtypes(opt, cxxtypes, cxxfile, objectfile, targetfile) + + -- done + for _, cxxtype in ipairs(utils.wrap(cxxtypes)) do + + -- check type + local ok = compiler.check_typedef(opt, cxxtype, cxxfile, objectfile) + + -- trace + utils.verbose("checking for the c++ type %s ... %s", cxxtype, utils.ifelse(ok, "ok", "no")) + + -- failed + if not ok then return false end + end + + -- ok + return true +end + -- make option function project._make_option(name, opt, cfile, cxxfile, objectfile, targetfile) @@ -664,24 +704,28 @@ function project._make_option(name, opt, cfile, cxxfile, objectfile, targetfile) end -- check links - if opt.links then - if not project._make_option_for_checking_links(opt, opt.links, cfile, objectfile, targetfile) then return end - end + if opt.links and not project._make_option_for_checking_links(opt, opt.links, cfile, objectfile, targetfile) then return end + + -- check ctypes + if opt.ctypes and not project._make_option_for_checking_ctypes(opt, opt.ctypes, cfile, objectfile, targetfile) then return end + + -- check cxxtypes + if opt.cxxtypes and not project._make_option_for_checking_cxxtypes(opt, opt.cxxtypes, cxxfile, objectfile, targetfile) then return end -- check includes and functions if opt.cincludes or opt.cxxincludes then -- check cincludes - if not project._make_option_for_checking_cincludes(opt, opt.cincludes, cfile, objectfile) then return end + if opt.cincludes and not project._make_option_for_checking_cincludes(opt, opt.cincludes, cfile, objectfile) then return end -- check cxxincludes - if not project._make_option_for_checking_cxxincludes(opt, opt.cxxincludes, cxxfile, objectfile) then return end + if opt.cxxincludes and not project._make_option_for_checking_cxxincludes(opt, opt.cxxincludes, cxxfile, objectfile) then return end -- check cfuncs - if not project._make_option_for_checking_cfuncs(opt, opt.cfuncs, cfile, objectfile, targetfile) then return end + if opt.cfuncs and not project._make_option_for_checking_cfuncs(opt, opt.cfuncs, cfile, objectfile, targetfile) then return end -- check cxxfuncs - if not project._make_option_for_checking_cxxfuncs(opt, opt.cxxfuncs, cxxfile, objectfile, targetfile) then return end + if opt.cxxfuncs and not project._make_option_for_checking_cxxfuncs(opt, opt.cxxfuncs, cxxfile, objectfile, targetfile) then return end end @@ -800,6 +844,8 @@ function project._load_options(file) , "cxxincludes" , "cfuncs" , "cxxfuncs" + , "ctypes" + , "cxxtypes" , "cflags" , "cxflags" , "cxxflags" diff --git a/xmake/scripts/tools/crun.lua b/xmake/scripts/tools/crun.lua deleted file mode 100644 index f8897cede..000000000 --- a/xmake/scripts/tools/crun.lua +++ /dev/null @@ -1,60 +0,0 @@ ---!The Automatic Cross-platform Build Tool --- --- XMake is free software; you can redistribute it and/or modify --- it under the terms of the GNU Lesser General Public License as published by --- the Free Software Foundation; either version 2.1 of the License, or --- (at your option) any later version. --- --- XMake is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Lesser General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public License --- along with XMake; --- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file crun.lua --- - --- define module: crun -local crun = crun or {} - --- load modules -local io = require("base/io") -local os = require("base/os") - --- the main function -function crun.main(self, ...) - - -- run all command files - local ok = -1 - for _, v in ipairs(...) do - - -- open file - local file = io.open(v, "r") - if file then - - -- read command - local cmd = file:read("*all") - if cmd and #cmd ~= 0 then - ok = os.execute(cmd) - end - - -- exit file - file:close() - - -- ok? - if ok ~= 0 then break end - end - end - - -- ok? - return ok -end - --- return module: crun -return crun |
