diff options
| author | ruki <[email protected]> | 2016-12-20 09:16:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:08 +0800 |
| commit | f0c81e8d818b3d0d5177ac4b39ff59562f133886 (patch) | |
| tree | b687c5a34f1543492605ce7d23f6f36f5aaaedf3 | |
| parent | 42ff9b62aa8ef799d8a9cfc064a40311671bee54 (diff) | |
load language apis
| -rw-r--r-- | xmake/core/language/language.lua | 32 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 3 | ||||
| -rwxr-xr-x | xmake/languages/c++/xmake.lua | 66 | ||||
| -rwxr-xr-x | xmake/languages/c/xmake.lua | 42 | ||||
| -rwxr-xr-x | xmake/languages/golang/xmake.lua | 33 | ||||
| -rwxr-xr-x | xmake/languages/objc++/xmake.lua | 66 | ||||
| -rwxr-xr-x | xmake/languages/objc/xmake.lua | 42 | ||||
| -rwxr-xr-x | xmake/languages/swift/xmake.lua | 33 |
8 files changed, 211 insertions, 106 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 1b042d871..43b77898e 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -139,7 +139,7 @@ end function language._directory() -- the directory - return path.join(xmake._PROGRAM_DIR, "languages")) + return path.join(xmake._PROGRAM_DIR, "languages") end -- the interpreter @@ -160,6 +160,9 @@ function language._interpreter() -- register api: on_load() interp:api_register_on_script("language", "load") + -- register api: set_values() to language + interp:api_register_set_values("language", "sourcekinds") + -- save interpreter language._INTERPRETER = interp @@ -172,7 +175,7 @@ function language.load(name) -- load all languages if not name then - for _, name in ipairs(table.wrap(os.match(language._directory(), true))) do + for _, name in ipairs(table.wrap(os.match(path.join(language._directory(), "*"), true))) do local instance, errors = language.load(path.basename(name)) if not instance then return nil, errors @@ -263,5 +266,30 @@ function language.load_from_kind(kind) return result end +-- load the language apis +function language.apis() + + -- load all languages + local languages, errors = language.load() + if not languages then + return nil, errors + end + + -- merge apis for each language + local apis = {values = {}, pathes = {}} + for _, instance in pairs(languages) do + local instance_apis = instance:get("apis") + if instance_apis then + table.join2(apis.values, table.wrap(instance_apis.values)) + table.join2(apis.pathes, table.wrap(instance_apis.pathes)) + end + end + apis.values = table.unique(apis.values) + apis.pathes = table.unique(apis.pathes) + + -- ok + return apis +end + -- return module return language diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index c0d36b844..fd42e661c 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -40,6 +40,7 @@ local package = require("project/package") local deprecated_project = require("project/deprecated/project") local platform = require("platform/platform") local environment = require("platform/environment") +local language = require("language/language") -- the current os is belong to the given os? function project._api_is_os(interp, ...) @@ -298,6 +299,8 @@ function project._interpreter() -- register api: target(), option() and task() interp:api_register_scope("target", "option", "task") +-- table.dump(language.apis()) + -- register api: set_values() to target interp:api_register_set_values("target", "kind" , "config_h_prefix" diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index b11118651..20c2087bd 100755 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -24,17 +24,71 @@ language("c++") -- set source file kinds - set_sourcekinds(".cpp", ".cc") + set_sourcekinds(".c", ".cc", ".cpp") -- on load on_load(function () -- init flags - _g.cxflags = {} - _g.cxxflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} + _g.cflags = {} + _g.cxflags = {} + _g.cxxflags = {} + _g.ldflags = {} + _g.arflags = {} + _g.shflags = {} + + -- init apis + _g.api = {} + _g.api.values = + { + -- target.set_xxx + "target.set_config_h_prefix" + -- target.add_xxx + , "target.add_links" + , "target.add_cflags" + , "target.add_cxflags" + , "target.add_cxxflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_defines_h" + , "target.add_undefines_h" + -- option.add_xxx + , "option.add_cincludes" + , "option.add_cxxincludes" + , "option.add_cfuncs" + , "option.add_cxxfuncs" + , "option.add_ctypes" + , "option.add_cxxtypes" + , "option.add_links" + , "option.add_cflags" + , "option.add_cxflags" + , "option.add_cxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_defines_if_ok" + , "option.add_defines_h_if_ok" + , "option.add_undefines" + , "option.add_undefines_if_ok" + , "option.add_undefines_h_if_ok" + } + _g.api.pathes = + { + -- target.set_xxx + "target.set_headerdir" + , "target.set_config_h" + -- target.add_xxx + , "target.add_headers" + , "target.add_linkdirs" + , "target.add_includedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + } end) diff --git a/xmake/languages/c/xmake.lua b/xmake/languages/c/xmake.lua deleted file mode 100755 index 0fcf33f36..000000000 --- a/xmake/languages/c/xmake.lua +++ /dev/null @@ -1,42 +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 xmake.lua --- - --- define language -language("c") - - -- set source file kinds - set_sourcekinds(".c") - - -- on load - on_load(function () - - -- init flags - _g.cflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} - - end) - - - - diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index b52d40e0a..c1a20fff8 100755 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -30,10 +30,35 @@ language("golang") on_load(function () -- init flags - _g.goflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} + _g.goflags = {} + _g.ldflags = {} + _g.arflags = {} + _g.shflags = {} + + -- init apis + _g.apis = {} + _g.apis.values = + { + -- target.add_xxx + "target.add_links" + , "target.add_goflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + -- option.add_xxx + , "option.add_links" + , "option.add_goflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + } + _g.apis.pathes = + { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } end) diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index d1fc66182..00642035b 100755 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -24,17 +24,71 @@ language("objc++") -- set source file kinds - set_sourcekinds(".mm") + set_sourcekinds(".m", ".mm") -- on load on_load(function () -- init flags - _g.mxflags = {} - _g.mxxflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} + _g.mflags = {} + _g.mxflags = {} + _g.mxxflags = {} + _g.ldflags = {} + _g.arflags = {} + _g.shflags = {} + + -- init apis + _g.apis = {} + _g.apis.values = + { + -- target.set_xxx + "target.set_config_h_prefix" + -- target.add_xxx + , "target.add_links" + , "target.add_mflags" + , "target.add_mxflags" + , "target.add_mxxflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_defines_h" + , "target.add_undefines_h" + -- option.add_xxx + , "option.add_cincludes" + , "option.add_cxxincludes" + , "option.add_cfuncs" + , "option.add_cxxfuncs" + , "option.add_ctypes" + , "option.add_cxxtypes" + , "option.add_links" + , "option.add_mflags" + , "option.add_mxflags" + , "option.add_mxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_defines_if_ok" + , "option.add_defines_h_if_ok" + , "option.add_undefines" + , "option.add_undefines_if_ok" + , "option.add_undefines_h_if_ok" + } + _g.apis.pathes = + { + -- target.set_xxx + "target.set_headerdir" + , "target.set_config_h" + -- target.add_xxx + , "target.add_headers" + , "target.add_linkdirs" + , "target.add_includedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + } end) diff --git a/xmake/languages/objc/xmake.lua b/xmake/languages/objc/xmake.lua deleted file mode 100755 index be35c4291..000000000 --- a/xmake/languages/objc/xmake.lua +++ /dev/null @@ -1,42 +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 xmake.lua --- - --- define language -language("objc") - - -- set source file kinds - set_sourcekinds(".m") - - -- on load - on_load(function () - - -- init flags - _g.mflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} - - end) - - - - diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index 0ec937a12..255957a41 100755 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -30,10 +30,35 @@ language("swift") on_load(function () -- init flags - _g.scflags = {} - _g.ldflags = {} - _g.arflags = {} - _g.shflags = {} + _g.scflags = {} + _g.ldflags = {} + _g.arflags = {} + _g.shflags = {} + + -- init apis + _g.apis = {} + _g.apis.values = + { + -- target.add_xxx + "target.add_links" + , "target.add_scflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + -- option.add_xxx + , "option.add_links" + , "option.add_scflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + } + _g.apis.pathes = + { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } end) |
