diff options
| author | ruki <[email protected]> | 2017-01-06 00:21:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:09 +0800 |
| commit | f9a475276634d38ce2603f09352bc8551027bdb4 (patch) | |
| tree | 823e915a30089f8376bd348c1318329f00104674 | |
| parent | c5da1a805ce1226b261150278e040a14322790e1 (diff) | |
add targetkinds for language
| -rwxr-xr-x | xmake/actions/config/scanner.lua | 25 | ||||
| -rw-r--r-- | xmake/core/language/language.lua | 8 | ||||
| -rwxr-xr-x | xmake/languages/c++/xmake.lua | 3 | ||||
| -rwxr-xr-x | xmake/languages/golang/xmake.lua | 3 | ||||
| -rwxr-xr-x | xmake/languages/objc++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/swift/check_main.lua | 38 | ||||
| -rwxr-xr-x | xmake/languages/swift/xmake.lua | 5 |
7 files changed, 42 insertions, 43 deletions
diff --git a/xmake/actions/config/scanner.lua b/xmake/actions/config/scanner.lua index 9e605501f..7f60b9f33 100755 --- a/xmake/actions/config/scanner.lua +++ b/xmake/actions/config/scanner.lua @@ -32,6 +32,7 @@ function make() cprint("${yellow}xmake.lua not found, scanning files ..") -- scan source files for the current directory + local targetkinds = {} local sourcefiles = {} local sourcefiles_main = {} for _, sourcekind in ipairs(language.sourcekinds()) do @@ -43,12 +44,21 @@ function make() local check_main = instance:get("check_main") -- scan source files + local filecount = 0 for _, sourcefile in ipairs(os.files("*" .. sourcekind)) do if check_main and check_main(sourcefile) then table.insert(sourcefiles_main, sourcefile) else table.insert(sourcefiles, sourcefile) end + filecount = filecount + 1 + end + + -- add targetkinds + if filecount > 0 then + for _, targetkind in ipairs(instance:targetkinds()) do + targetkinds[targetkind] = true + end end end sourcefiles = table.unique(sourcefiles) @@ -71,18 +81,27 @@ function make() -- get target name local targetname = path.basename(os.curdir()) - -- define static target + -- define static/binary target if #sourcefiles > 0 then + -- get targetkind + local targetkind = nil + if targetkinds["static"] then + targetkind = "static" + elseif targetkinds["binary"] then + targetkind = "binary" + end + assert(targetkind, "unknown target kind!") + -- trace - cprint("target(${magenta}%s${clear}): static", targetname) + cprint("target(${magenta}%s${clear}): %s", targetname, targetkind) -- add target file:print("-- define target") file:print("target(\"%s\")", targetname) file:print("") file:print(" -- set kind") - file:print(" set_kind(\"static\")") + file:print(" set_kind(\"%s\")", targetkind) file:print("") file:print(" -- add files") for _, sourcefile in ipairs(sourcefiles) do diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 8f0ca1860..0bb6921a1 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -85,6 +85,13 @@ function _instance:sourcekinds() return self._INFO.sourcekinds end +-- get the language targetkinds +function _instance:targetkinds() + + -- get it + return self._INFO.targetkinds +end + -- the directory of language function language._directory() @@ -111,6 +118,7 @@ function language._interpreter() { -- language.set_xxx "language.set_sourcekinds" + , "language.set_targetkinds" } , script = { diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 5aa8395bf..4e43aba25 100755 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -26,6 +26,9 @@ language("c++") -- set source file kinds set_sourcekinds(".c", ".cc", ".cpp") + -- set target kinds + set_targetkinds("binary", "static", "shared") + -- on load on_load("load") diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index 8016bed17..946594e71 100755 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -26,6 +26,9 @@ language("golang") -- set source file kinds set_sourcekinds(".go") + -- set target kinds + set_targetkinds("binary", "static", "shared") + -- on load on_load("load") diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index ecb39bae4..99cb0d5ad 100755 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -26,6 +26,9 @@ language("objc++") -- set source file kinds set_sourcekinds(".m", ".mm") + -- set target kinds + set_targetkinds("binary", "static", "shared") + -- on load on_load("load") diff --git a/xmake/languages/swift/check_main.lua b/xmake/languages/swift/check_main.lua deleted file mode 100644 index fd2bc3fa3..000000000 --- a/xmake/languages/swift/check_main.lua +++ /dev/null @@ -1,38 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file check_main.lua --- - --- check it -function main(sourcefile) - - -- load source code - local sourcecode = io.read(sourcefile) - - -- find func main() { - if sourcecode:find("func%s+main%s*%(.*%)") then - return true - end - - -- no main function - return false -end - - diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index 941967c6c..3ee02263a 100755 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -26,11 +26,12 @@ language("swift") -- set source file kinds set_sourcekinds(".swift") + -- set target kinds + set_targetkinds("binary") + -- on load on_load("load") - -- on check_main - on_check_main("check_main") |
