diff options
| author | ruki <[email protected]> | 2021-07-29 12:04:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-29 12:04:08 +0800 |
| commit | 9776c89aec960c73bc1fd7c47ef61a54de2ba4ef (patch) | |
| tree | 63880515f449a33b05484d67b7fbd95995458429 | |
| parent | 309343f78d84dcf654019b1b84756a659e8c2649 (diff) | |
| parent | 10a61c13f734a0a813d2e8d38eba42c823f407f0 (diff) | |
Merge pull request #1538 from xmake-io/vala
add vala language support
40 files changed, 959 insertions, 1683 deletions
diff --git a/tests/projects/vala/lua/src/main.vala b/tests/projects/vala/lua/src/main.vala new file mode 100644 index 000000000..8e8a32da0 --- /dev/null +++ b/tests/projects/vala/lua/src/main.vala @@ -0,0 +1,21 @@ +using Lua; + +static int my_func (LuaVM vm) { + stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1)); + return 1; +} + +static int main (string[] args) { + + string code = """ + print "Lua Code From Vala Code!" + my_func(33) + """; + + var vm = new LuaVM (); + vm.open_libs (); + vm.register ("my_func", my_func); + vm.do_string (code); + + return 0; +} diff --git a/tests/projects/vala/lua/xmake.lua b/tests/projects/vala/lua/xmake.lua new file mode 100644 index 000000000..df0cbeb89 --- /dev/null +++ b/tests/projects/vala/lua/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.release", "mode.debug") + +add_requires("lua", "glib") + +target("test") + set_kind("binary") + add_rules("vala") + add_files("src/*.vala") + add_packages("lua", "glib") + add_values("vala.packages", "lua") diff --git a/tests/projects/vala/sdl/main.vala b/tests/projects/vala/sdl/main.vala deleted file mode 100644 index c8aa2588b..000000000 --- a/tests/projects/vala/sdl/main.vala +++ /dev/null @@ -1,91 +0,0 @@ -using SDL; -using SDLGraphics; - -public class SDLSample : Object { - - private const int SCREEN_WIDTH = 640; - private const int SCREEN_HEIGHT = 480; - private const int SCREEN_BPP = 32; - private const int DELAY = 10; - - private unowned SDL.Screen screen; - private GLib.Rand rand; - private bool done; - - public SDLSample () { - this.rand = new GLib.Rand (); - } - - public void run () { - init_video (); - - while (!done) { - draw (); - process_events (); - SDL.Timer.delay (DELAY); - } - } - - private void init_video () { - uint32 video_flags = SurfaceFlag.DOUBLEBUF - | SurfaceFlag.HWACCEL - | SurfaceFlag.HWSURFACE; - - this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT, - SCREEN_BPP, video_flags); - if (this.screen == null) { - stderr.printf ("Could not set video mode.\n"); - } - - SDL.WindowManager.set_caption ("Vala SDL Demo", ""); - } - - private void draw () { - int16 x = (int16) rand.int_range (0, screen.w); - int16 y = (int16) rand.int_range (0, screen.h); - int16 radius = (int16) rand.int_range (0, 100); - uint32 color = rand.next_int (); - - Circle.fill_color (this.screen, x, y, radius, color); - Circle.outline_color_aa (this.screen, x, y, radius, color); - - this.screen.flip (); - } - - private void process_events () { - Event event; - while (Event.poll (out event) == 1) { - switch (event.type) { - case EventType.QUIT: - this.done = true; - break; - case EventType.KEYDOWN: - this.on_keyboard_event (event.key); - break; - } - } - } - - private void on_keyboard_event (KeyboardEvent event) { - if (is_alt_enter (event.keysym)) { - WindowManager.toggle_fullscreen (screen); - } - } - - private static bool is_alt_enter (Key key) { - return ((key.mod & KeyModifier.LALT)!=0) - && (key.sym == KeySymbol.RETURN - || key.sym == KeySymbol.KP_ENTER); - } - - public static int main (string[] args) { - SDL.init (InitFlag.VIDEO); - - var sample = new SDLSample (); - sample.run (); - - SDL.quit (); - - return 0; - } -} diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 4815d47db..0b38769da 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -247,11 +247,7 @@ function language._interpreter() , "language.set_targetflags" } } - - -- save interpreter language._INTERPRETER = interp - - -- ok? return interp end @@ -313,11 +309,7 @@ function language.load(name) if not instance then return nil, errors end - - -- save instance to the cache language._LANGUAGES[name] = instance - - -- ok return instance end @@ -347,16 +339,10 @@ function language.load_sk(sourcekind) break end end - - -- not found? if not result then return nil, string.format("unknown language sourcekind: %s", sourcekind) end - - -- cache this language language._LANGUAGES_OF_SK[sourcekind] = result - - -- ok return result end @@ -386,45 +372,37 @@ function language.load_ex(extension) break end end - - -- not found? if not result then return nil, string.format("unknown language source extension: %s", extension) end - - -- cache this language language._LANGUAGES_OF_EX[extension] = result - - -- ok return result end -- load the language apis function language.apis() - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge apis for each language - local apis = {values = {}, paths = {}, custom = {}, dictionary = {}} - for name, 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.paths, table.wrap(instance_apis.paths)) - table.join2(apis.custom, table.wrap(instance_apis.custom)) - table.join2(apis.dictionary, table.wrap(instance_apis.dictionary)) + local apis = language._APIS + if not apis then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + apis = {values = {}, paths = {}, custom = {}, dictionary = {}} + for name, 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.paths, table.wrap(instance_apis.paths)) + table.join2(apis.custom, table.wrap(instance_apis.custom)) + table.join2(apis.dictionary, table.wrap(instance_apis.dictionary)) + end end + apis.values = table.unique(apis.values) + apis.paths = table.unique(apis.paths) + apis.custom = table.unique(apis.custom) + language._APIS = apis end - apis.values = table.unique(apis.values) - apis.paths = table.unique(apis.paths) - apis.custom = table.unique(apis.custom) - - -- ok return apis end @@ -443,28 +421,18 @@ end -- } -- function language.extensions() - - -- attempt to get it from cache - if language._EXTENSIONS then - return language._EXTENSIONS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local extensions = {} - for name, instance in pairs(languages) do - table.join2(extensions, instance:extensions()) + local extensions = language._EXTENSIONS + if not extensions then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + extensions = {} + for name, instance in pairs(languages) do + table.join2(extensions, instance:extensions()) + end + language._EXTENSIONS = extensions end - - -- cache it - language._EXTENSIONS = extensions - - -- ok return extensions end @@ -482,28 +450,18 @@ end -- } -- function language.sourcekinds() - - -- attempt to get it from cache - if language._SOURCEKINDS then - return language._SOURCEKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local sourcekinds = {} - for name, instance in pairs(languages) do - table.join2(sourcekinds, instance:sourcekinds()) + local sourcekinds = language._SOURCEKINDS + if not sourcekinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + sourcekinds = {} + for name, instance in pairs(languages) do + table.join2(sourcekinds, instance:sourcekinds()) + end + language._SOURCEKINDS = sourcekinds end - - -- cache it - language._SOURCEKINDS = sourcekinds - - -- ok return sourcekinds end @@ -518,28 +476,18 @@ end -- } -- function language.sourceflags() - - -- attempt to get it from cache - if language._SOURCEFLAGS then - return language._SOURCEFLAGS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local sourceflags = {} - for name, instance in pairs(languages) do - table.join2(sourceflags, instance:sourceflags()) + local sourceflags = language._SOURCEFLAGS + if not sourceflags then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + sourceflags = {} + for name, instance in pairs(languages) do + table.join2(sourceflags, instance:sourceflags()) + end + language._SOURCEFLAGS = sourceflags end - - -- cache it - language._SOURCEFLAGS = sourceflags - - -- ok return sourceflags end @@ -560,21 +508,15 @@ function language.sourcekind_of(sourcefile) if not sourcekind then return nil, string.format("%s is unknown extension", extension) end - - -- ok return sourcekind end -- get extension of the source kind function language.extension_of(sourcekind) - - -- get extension local extension = table.wrap(language.sourcekinds()[sourcekind])[1] if not extension then return nil, string.format("%s is unknown source kind", sourcekind) end - - -- ok return extension end @@ -615,8 +557,6 @@ function language.linkerinfos_of(targetkind, sourcekinds) end end end - - -- cache it language._LINKERINFOS = linkerinfos end @@ -654,34 +594,24 @@ end -- } -- function language.targetkinds() - - -- attempt to get it from cache - if language._TARGETKINDS then - return language._TARGETKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local targetkinds = {} - for name, instance in pairs(languages) do - for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do - targetkinds[targetkind] = targetkinds[targetkind] or {} - table.insert(targetkinds[targetkind], linkerkind) + local targetkinds = language._TARGETKINDS + if not targetkinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) end + targetkinds = {} + for name, instance in pairs(languages) do + for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do + targetkinds[targetkind] = targetkinds[targetkind] or {} + table.insert(targetkinds[targetkind], linkerkind) + end + end + for targetkind, linkerkinds in pairs(targetkinds) do + targetkinds[targetkind] = table.unique(linkerkinds) + end + language._TARGETKINDS = targetkinds end - for targetkind, linkerkinds in pairs(targetkinds) do - targetkinds[targetkind] = table.unique(linkerkinds) - end - - -- cache it - language._TARGETKINDS = targetkinds - - -- ok return targetkinds end @@ -702,30 +632,19 @@ end -- } -- function language.langkinds() - - -- attempt to get it from cache - if language._LANGKINDS then - return language._LANGKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local langkinds = {} - for name, instance in pairs(languages) do - table.join2(langkinds, instance:langkinds()) + local langkinds = language._LANGKINDS + if not langkinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + langkinds = {} + for name, instance in pairs(languages) do + table.join2(langkinds, instance:langkinds()) + end + language._LANGKINDS = langkinds end - - -- cache it - language._LANGKINDS = langkinds - - -- ok return langkinds end --- return module return language diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 38d207656..30d1ad7b1 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1545,30 +1545,18 @@ end -- e.g. cc cxx mm mxx as ... -- function _instance:sourcekinds() - - -- cached? return it directly - if self._SOURCEKINDS then - return self._SOURCEKINDS - end - - -- make source kinds - local sourcekinds = {} - for _, sourcefile in pairs(self:sourcefiles()) do - - -- get source kind - local sourcekind = self:sourcekind_of(sourcefile) - if sourcekind then - table.insert(sourcekinds, sourcekind) + local sourcekinds = self._SOURCEKINDS + if not sourcekinds then + sourcekinds = {} + for _, sourcefile in pairs(self:sourcefiles()) do + local sourcekind = self:sourcekind_of(sourcefile) + if sourcekind then + table.insert(sourcekinds, sourcekind) + end end + sourcekinds = table.unique(sourcekinds) + self._SOURCEKINDS = sourcekinds end - - -- remove repeat - sourcekinds = table.unique(sourcekinds) - - -- cache it - self._SOURCEKINDS = sourcekinds - - -- ok? return sourcekinds end diff --git a/xmake/languages/asm/api.lua b/xmake/languages/asm/api.lua deleted file mode 100644 index 49bda6a36..000000000 --- a/xmake/languages/asm/api.lua +++ /dev/null @@ -1,92 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_asflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_defines" - , "target.add_undefines" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_asflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_asflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_defines" - , "package.add_undefines" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_cflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_headers" -- TODO deprecated - , "target.add_headerfiles" - , "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/asm/load.lua b/xmake/languages/asm/load.lua index fd547b488..9fe4681f4 100644 --- a/xmake/languages/asm/load.lua +++ b/xmake/languages/asm/load.lua @@ -18,17 +18,73 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_asflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_asflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_asflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_headers" -- TODO deprecated + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua index a57790027..cb9aa22f5 100644 --- a/xmake/languages/asm/xmake.lua +++ b/xmake/languages/asm/xmake.lua @@ -18,38 +18,19 @@ -- @file xmake.lua -- --- define language language("asm") - - -- set source file kinds + add_rules("asm") set_sourcekinds {as = {".s", ".asm"}} - - -- set source file flags set_sourceflags {as = "asflags"} - - -- set target kinds set_targetkinds {binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {as = "as"} - - -- set mixing kinds + set_langkinds {as = "as"} set_mixingkinds("as") - -- add rules - add_rules("asm") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -65,8 +46,7 @@ language("asm") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -78,8 +58,7 @@ language("asm") , "target.links" , "toolchain.links" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -92,14 +71,12 @@ language("asm") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/c++/api.lua b/xmake/languages/c++/api.lua deleted file mode 100644 index e33580fc4..000000000 --- a/xmake/languages/c++/api.lua +++ /dev/null @@ -1,260 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get function name and function info --- --- sigsetjmp --- sigsetjmp((void*)0, 0) --- sigsetjmp{sigsetjmp((void*)0, 0);} --- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} --- -function _funcinfo(func) - local name, code = string.match(func, "(.+){(.+)}") - if code == nil then - local pos = func:find("%(") - if pos then - name = func:sub(1, pos - 1) - code = func - else - name = func - code = string.format("volatile void* p%s = (void*)&%s;", name, name) - end - end - return name:trim(), code -end - --- TODO add c function, deprecated -function _api_add_cfunc(interp, module, alias, links, includes, func) - - -- parse the function info - local funcname, funccode = _funcinfo(func) - - -- make the option name - local name = nil - if module ~= nil then - name = format("__%s_%s", module, funcname) - else - name = format("__%s", funcname) - end - - -- uses the alias name - if alias ~= nil then - funcname = alias - end - - -- make the option define - local define = nil - if module ~= nil then - define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) - else - define = format("$(prefix)_HAVE_%s", funcname:upper()) - end - - -- save the current scope - local scope = interp:scope_save() - - -- check option - interp:api_call("option", name) - interp:api_call("set_category", "cfuncs") - interp:api_call("add_cfuncs", func) - if links then interp:api_call("add_links", links) end - if includes then interp:api_call("add_cincludes", includes) end - - -- restore the current scope - interp:scope_restore(scope) - - -- add this option - interp:api_call("add_options", name) -end - --- TODO add c functions, deprecated -function _api_add_cfuncs(interp, module, links, includes, ...) - wprint("target.add_cfuncs is deprecated, please use option.add_cfuncs()") - for _, func in ipairs({...}) do - _api_add_cfunc(interp, module, nil, links, includes, func) - end -end - --- TODO add c++ function, deprecated -function _api_add_cxxfunc(interp, module, alias, links, includes, func) - - -- parse the function info - local funcname, funccode = _funcinfo(func) - - -- make the option name - local name = nil - if module ~= nil then - name = format("__%s_%s", module, funcname) - else - name = format("__%s", funcname) - end - - -- uses the alias name - if alias ~= nil then - funcname = alias - end - - -- make the option define - local define = nil - if module ~= nil then - define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) - else - define = format("$(prefix)_HAVE_%s", funcname:upper()) - end - - -- save the current scope - local scope = interp:scope_save() - - -- check option - interp:api_call("option", name) - interp:api_call("set_category", "cxxfuncs") - interp:api_call("add_cxxfuncs", func) - if links then interp:api_call("add_links", links) end - if includes then interp:api_call("add_cxxincludes", includes) end - - -- restore the current scope - interp:scope_restore(scope) - - -- add this option - interp:api_call("add_options", name) -end - --- TODO add c++ functions, deprecated -function _api_add_cxxfuncs(interp, module, links, includes, ...) - wprint("target.add_cxxfuncs is deprecated, please use option.add_cxxfuncs()") - for _, func in ipairs({...}) do - _api_add_cxxfunc(interp, module, nil, links, includes, func) - end -end - - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "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_frameworks" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- 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_syslinks" - , "option.add_cflags" - , "option.add_cxflags" - , "option.add_cxxflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_frameworks" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_cflags" - , "package.add_cxflags" - , "package.add_cxxflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_defines" - , "package.add_undefines" - , "package.add_frameworks" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 - , "package.add_sysincludedirs" - , "package.add_frameworkdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_cflags" - , "toolchain.add_cxflags" - , "toolchain.add_cxxflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_frameworks" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - , "toolchain.add_frameworkdirs" - } - _g.paths = - { - -- target.set_xxx - "target.set_headerdir" -- TODO deprecated - , "target.set_config_header" -- TODO deprecated - , "target.set_pcheader" - , "target.set_pcxxheader" - -- target.add_xxx - , "target.add_headers" -- TODO deprecated - , "target.add_headerfiles" - , "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - , "target.add_frameworkdirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - , "option.add_frameworkdirs" - } - _g.dictionary = - { - -- option.add_xxx - "option.add_csnippets" - , "option.add_cxxsnippets" - } - _g.custom = - { - -- target.add_xxx - {"target.add_cfunc", _api_add_cfunc } - , {"target.add_cfuncs", _api_add_cfuncs } - , {"target.add_cxxfunc", _api_add_cxxfunc } - , {"target.add_cxxfuncs", _api_add_cxxfuncs } - } - - -- ok - return _g -end - - diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua index fd547b488..12fb5283b 100644 --- a/xmake/languages/c++/load.lua +++ b/xmake/languages/c++/load.lua @@ -18,17 +18,239 @@ -- @file load.lua -- --- imports -import("api") +-- get function name and function info +-- +-- sigsetjmp +-- sigsetjmp((void*)0, 0) +-- sigsetjmp{sigsetjmp((void*)0, 0);} +-- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} +-- +function _funcinfo(func) + local name, code = string.match(func, "(.+){(.+)}") + if code == nil then + local pos = func:find("%(") + if pos then + name = func:sub(1, pos - 1) + code = func + else + name = func + code = string.format("volatile void* p%s = (void*)&%s;", name, name) + end + end + return name:trim(), code +end --- load it -function main() +-- TODO add c function, deprecated +function _api_add_cfunc(interp, module, alias, links, includes, func) + + -- parse the function info + local funcname, funccode = _funcinfo(func) + + -- make the option name + local name = nil + if module ~= nil then + name = format("__%s_%s", module, funcname) + else + name = format("__%s", funcname) + end + + -- uses the alias name + if alias ~= nil then + funcname = alias + end + + -- make the option define + local define = nil + if module ~= nil then + define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) + else + define = format("$(prefix)_HAVE_%s", funcname:upper()) + end + + -- save the current scope + local scope = interp:scope_save() + + -- check option + interp:api_call("option", name) + interp:api_call("set_category", "cfuncs") + interp:api_call("add_cfuncs", func) + if links then interp:api_call("add_links", links) end + if includes then interp:api_call("add_cincludes", includes) end + + -- restore the current scope + interp:scope_restore(scope) + + -- add this option + interp:api_call("add_options", name) +end + +-- TODO add c functions, deprecated +function _api_add_cfuncs(interp, module, links, includes, ...) + wprint("target.add_cfuncs is deprecated, please use option.add_cfuncs()") + for _, func in ipairs({...}) do + _api_add_cfunc(interp, module, nil, links, includes, func) + end +end - -- init apis - _g.apis = api.apis() +-- TODO add c++ function, deprecated +function _api_add_cxxfunc(interp, module, alias, links, includes, func) - -- ok - return _g + -- parse the function info + local funcname, funccode = _funcinfo(func) + + -- make the option name + local name = nil + if module ~= nil then + name = format("__%s_%s", module, funcname) + else + name = format("__%s", funcname) + end + + -- uses the alias name + if alias ~= nil then + funcname = alias + end + + -- make the option define + local define = nil + if module ~= nil then + define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) + else + define = format("$(prefix)_HAVE_%s", funcname:upper()) + end + + -- save the current scope + local scope = interp:scope_save() + + -- check option + interp:api_call("option", name) + interp:api_call("set_category", "cxxfuncs") + interp:api_call("add_cxxfuncs", func) + if links then interp:api_call("add_links", links) end + if includes then interp:api_call("add_cxxincludes", includes) end + + -- restore the current scope + interp:scope_restore(scope) + + -- add this option + interp:api_call("add_options", name) +end + +-- TODO add c++ functions, deprecated +function _api_add_cxxfuncs(interp, module, links, includes, ...) + wprint("target.add_cxxfuncs is deprecated, please use option.add_cxxfuncs()") + for _, func in ipairs({...}) do + _api_add_cxxfunc(interp, module, nil, links, includes, func) + end +end + +-- get apis +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "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_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- 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_syslinks" + , "option.add_cflags" + , "option.add_cxflags" + , "option.add_cxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_cflags" + , "package.add_cxflags" + , "package.add_cxxflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_frameworks" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 + , "package.add_sysincludedirs" + , "package.add_frameworkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_cxflags" + , "toolchain.add_cxxflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + , "toolchain.add_frameworkdirs" + } + apis.paths = { + -- target.set_xxx + "target.set_headerdir" -- TODO deprecated + , "target.set_config_header" -- TODO deprecated + , "target.set_pcheader" + , "target.set_pcxxheader" + -- target.add_xxx + , "target.add_headers" -- TODO deprecated + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + , "option.add_frameworkdirs" + } + apis.dictionary = { + -- option.add_xxx + "option.add_csnippets" + , "option.add_cxxsnippets" + } + apis.custom = { + -- target.add_xxx + {"target.add_cfunc", _api_add_cfunc } + , {"target.add_cfuncs", _api_add_cfuncs } + , {"target.add_cxxfunc", _api_add_cxxfunc } + , {"target.add_cxxfuncs", _api_add_cxxfuncs } + } + return apis +end + +function main() + return {apis = _get_apis()} end diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 4a18dc5df..52c7baa91 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("c++") - - -- set source file kinds + add_rules("c++") set_sourcekinds {cc = ".c", cxx = {".cpp", ".cc", ".cxx"}} - - -- set source file flags set_sourceflags {cc = {"cflags", "cxflags"}, cxx = {"cxxflags", "cxflags"}} - - -- set target kinds set_targetkinds {binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {c = "cc", cxx = "cxx"} - - -- set mixing kinds + set_langkinds {c = "cc", cxx = "cxx"} set_mixingkinds("cc", "cxx", "as", "mrc") - -- add rules - add_rules("c++") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "config.frameworkdirs" , "config.frameworks" @@ -78,8 +57,7 @@ language("c++") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -101,8 +79,7 @@ language("c++") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -124,14 +101,12 @@ language("c++") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/cuda/api.lua b/xmake/languages/cuda/api.lua deleted file mode 100644 index 26f8ebf89..000000000 --- a/xmake/languages/cuda/api.lua +++ /dev/null @@ -1,79 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_cugencodes" - , "target.add_cuflags" - , "target.add_culdflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_defines" - , "target.add_undefines" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_cugencodes" - , "option.add_cuflags" - , "option.add_culdflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_cugencodes" - , "toolchain.add_cuflags" - , "toolchain.add_culdflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/cuda/load.lua b/xmake/languages/cuda/load.lua index fd547b488..6df51bc2d 100644 --- a/xmake/languages/cuda/load.lua +++ b/xmake/languages/cuda/load.lua @@ -18,17 +18,60 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_cugencodes" + , "target.add_cuflags" + , "target.add_culdflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_cugencodes" + , "option.add_cuflags" + , "option.add_culdflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cugencodes" + , "toolchain.add_cuflags" + , "toolchain.add_culdflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 1915730d0..a50935e4e 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("cuda") - - -- set source file kinds + add_rules("cuda") set_sourcekinds {cu = ".cu"} - - -- set source file flags set_sourceflags {cu = "cuflags"} - - -- set target kinds set_targetkinds {gpucode = "culd", binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {gpucode = "culdflags", binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds set_langkinds {cu = "cu"} - - -- set mixing kinds set_mixingkinds("cu", "cc", "cxx", "as") - -- add rules - add_rules("cuda") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -68,8 +47,7 @@ language("cuda") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -98,13 +76,11 @@ language("cuda") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } - , gpucode = - { + , gpucode = { "config.linkdirs" , "target.linkdirs" , "toolchain.linkdirs" @@ -117,7 +93,6 @@ language("cuda") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/dlang/api.lua b/xmake/languages/dlang/api.lua deleted file mode 100644 index e6211e677..000000000 --- a/xmake/languages/dlang/api.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_dcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_dcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_dcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_dcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/dlang/load.lua b/xmake/languages/dlang/load.lua index 97ef5346a..23653150c 100644 --- a/xmake/languages/dlang/load.lua +++ b/xmake/languages/dlang/load.lua @@ -18,13 +18,63 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_dcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_dcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_dcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_dcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - _g.apis = api.apis() - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index c9df5657b..9749c0d15 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("dlang") - - -- set source file kinds + add_rules("dlang") set_sourcekinds {dc = ".d"} - - -- set source file flags set_sourceflags {dc = "dcflags"} - - -- set target kinds set_targetkinds {binary = "dcld", static = "dcar", shared = "dcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {d = "dc"} - - -- set mixing kinds + set_langkinds {d = "dc"} set_mixingkinds("dc", "cc", "cxx", "as") - -- add rules - add_rules("dlang") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -63,8 +42,7 @@ language("dlang") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -79,8 +57,7 @@ language("dlang") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -93,14 +70,12 @@ language("dlang") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/fortran/api.lua b/xmake/languages/fortran/api.lua deleted file mode 100644 index b9724bb7e..000000000 --- a/xmake/languages/fortran/api.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_fcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_fcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_fcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_fcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/fortran/load.lua b/xmake/languages/fortran/load.lua index fd547b488..e701b198f 100644 --- a/xmake/languages/fortran/load.lua +++ b/xmake/languages/fortran/load.lua @@ -18,17 +18,63 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_fcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_fcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_fcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_fcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/fortran/xmake.lua b/xmake/languages/fortran/xmake.lua index 435b55ca2..5d73f153d 100644 --- a/xmake/languages/fortran/xmake.lua +++ b/xmake/languages/fortran/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("fortran") - - -- set source file kinds + add_rules("fortran") set_sourcekinds {fc = {".f03", ".f90", ".f95", ".for", ".f"}} - - -- set source file flags set_sourceflags {fc = "fcflags"} - - -- set target kinds set_targetkinds {binary = "fcld", static = "ar", shared = "fcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {fortran = "fc"} - - -- set mixing kinds + set_langkinds {fortran = "fc"} set_mixingkinds("fc", "cc", "cxx", "as") - -- add rules - add_rules("fortran") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -63,8 +42,7 @@ language("fortran") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -79,8 +57,7 @@ language("fortran") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -93,14 +70,12 @@ language("fortran") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/golang/api.lua b/xmake/languages/golang/api.lua deleted file mode 100644 index 730502bdf..000000000 --- a/xmake/languages/golang/api.lua +++ /dev/null @@ -1,62 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_gcflags" - , "target.add_ldflags" - , "target.add_arflags" - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_gcflags" - , "option.add_ldflags" - , "option.add_arflags" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_gcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/golang/load.lua b/xmake/languages/golang/load.lua index fd547b488..c4d3176b3 100644 --- a/xmake/languages/golang/load.lua +++ b/xmake/languages/golang/load.lua @@ -18,17 +18,43 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_gcflags" + , "target.add_ldflags" + , "target.add_arflags" + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_gcflags" + , "option.add_ldflags" + , "option.add_arflags" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_gcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index cae73ca26..213bf2b46 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("golang") - - -- set source file kinds + add_rules("go") set_sourcekinds {gc = ".go"} - - -- set source file flags set_sourceflags {gc = "gcflags"} - - -- set target kinds set_targetkinds {binary = "gcld", static = "gcar"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags"} - - -- set language kinds - set_langkinds {go = "gc"} - - -- set mixing kinds + set_langkinds {go = "gc"} set_mixingkinds("gc") - -- add rules - add_rules("go") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -67,8 +46,7 @@ language("golang") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -81,8 +59,7 @@ language("golang") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -97,7 +74,6 @@ language("golang") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/msrc/api.lua b/xmake/languages/msrc/api.lua deleted file mode 100644 index ab7ae6bad..000000000 --- a/xmake/languages/msrc/api.lua +++ /dev/null @@ -1,48 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_mrcflags" - -- option.add_xxx - , "option.add_mrcflags" - -- toolchain.add_xxx - , "toolchain.add_mrcflags" - } - _g.paths = - { - -- target.add_xxx - "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/msrc/load.lua b/xmake/languages/msrc/load.lua index fd547b488..d6e03a68b 100644 --- a/xmake/languages/msrc/load.lua +++ b/xmake/languages/msrc/load.lua @@ -18,17 +18,29 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_mrcflags" + -- option.add_xxx + , "option.add_mrcflags" + -- toolchain.add_xxx + , "toolchain.add_mrcflags" + } + apis.paths = { + -- target.add_xxx + "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua index e5becdba7..93d113d53 100644 --- a/xmake/languages/msrc/xmake.lua +++ b/xmake/languages/msrc/xmake.lua @@ -18,32 +18,17 @@ -- @file xmake.lua -- --- define language language("msrc") - - -- set source file kinds + add_rules("win.sdk.resource") set_sourcekinds {mrc = ".rc"} - - -- set source file flags set_sourceflags {mrc = "mrcflags"} - - -- set language kinds - set_langkinds {msrc = "mrc"} - - -- set mixing kinds + set_langkinds {msrc = "mrc"} set_mixingkinds("mrc") - -- add rules - add_rules("win.sdk.resource") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.defines" , "target.undefines" @@ -56,7 +41,6 @@ language("msrc") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/objc++/api.lua b/xmake/languages/objc++/api.lua deleted file mode 100644 index 8df275896..000000000 --- a/xmake/languages/objc++/api.lua +++ /dev/null @@ -1,102 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "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_frameworks" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- 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_syslinks" - , "option.add_mflags" - , "option.add_mxflags" - , "option.add_mxxflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_frameworks" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_mflags" - , "toolchain.add_mxflags" - , "toolchain.add_mxxflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_frameworks" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - , "toolchain.add_frameworkdirs" - } - _g.paths = - { - -- target.set_xxx - "target.set_headerdir" -- TODO deprecated - , "target.set_config_header" - , "target.set_pcheader" - , "target.set_pcxxheader" - -- target.add_xxx - , "target.add_headers" -- TODO deprecated - , "target.add_headerfiles" - , "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - , "target.add_frameworkdirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - , "option.add_frameworkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/objc++/load.lua b/xmake/languages/objc++/load.lua index fd547b488..85df22850 100644 --- a/xmake/languages/objc++/load.lua +++ b/xmake/languages/objc++/load.lua @@ -18,17 +18,83 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "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_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- 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_syslinks" + , "option.add_mflags" + , "option.add_mxflags" + , "option.add_mxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_mflags" + , "toolchain.add_mxflags" + , "toolchain.add_mxxflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + , "toolchain.add_frameworkdirs" + } + apis.paths = { + -- target.set_xxx + "target.set_headerdir" -- TODO deprecated + , "target.set_config_header" + , "target.set_pcheader" + , "target.set_pcxxheader" + -- target.add_xxx + , "target.add_headers" -- TODO deprecated + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + , "option.add_frameworkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/rust/api.lua b/xmake/languages/rust/api.lua deleted file mode 100644 index dbd7e6776..000000000 --- a/xmake/languages/rust/api.lua +++ /dev/null @@ -1,58 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_rcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_rcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_rcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - -- option.add_xxx - , "option.add_linkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/rust/load.lua b/xmake/languages/rust/load.lua index fd547b488..c02f50bfd 100644 --- a/xmake/languages/rust/load.lua +++ b/xmake/languages/rust/load.lua @@ -18,17 +18,39 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_rcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_rcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_rcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 9c7e94edc..dc6ae3d15 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -18,48 +18,26 @@ -- @file xmake.lua -- --- define language language("rust") - - -- set source file kinds + add_rules("rust") set_sourcekinds {rc = ".rs"} - - -- set source file flags set_sourceflags {rc = "rcflags"} - - -- set target kinds set_targetkinds {binary = "rcld", static = "rcar", shared = "rcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds set_langkinds {rust = "rc"} - - -- set mixing kinds set_mixingkinds("rc") - -- add rules - add_rules("rust") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "target.symbols" , "target.warnings" , "target.optimize:check" , "target.vectorexts:check" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -68,22 +46,19 @@ language("rust") , "toolchain.linkdirs" , "toolchain.rpathdirs" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" , "target.symbols" , "toolchain.linkdirs" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/swift/api.lua b/xmake/languages/swift/api.lua deleted file mode 100644 index 3b8dd0506..000000000 --- a/xmake/languages/swift/api.lua +++ /dev/null @@ -1,69 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_scflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_frameworks" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_scflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_frameworks" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_scflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_frameworks" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_frameworkdirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_frameworkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/swift/load.lua b/xmake/languages/swift/load.lua index fd547b488..8de44b044 100644 --- a/xmake/languages/swift/load.lua +++ b/xmake/languages/swift/load.lua @@ -18,17 +18,50 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_scflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_scflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_scflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_frameworkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index b0de2d067..ba0d6b693 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -18,38 +18,19 @@ -- @file xmake.lua -- --- define language language("swift") - - -- set source file kinds + add_rules("swift") set_sourcekinds {sc = ".swift"} - - -- set source file flags set_sourceflags {sc = "scflags"} - - -- set target kinds set_targetkinds {binary = "scld", static = "ar", shared = "scsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {swift = "sc"} - - -- set mixing kinds + set_langkinds {swift = "sc"} set_mixingkinds("sc", "mm", "mxx", "cc", "cxx") - -- add rules - add_rules("swift") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "config.frameworkdirs" , "config.Frameworks" @@ -69,8 +50,7 @@ language("swift") , "toolchain.frameworkdirs" , "toolchain.frameworks" } - , binary = - { + , binary = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -91,8 +71,7 @@ language("swift") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -111,14 +90,12 @@ language("swift") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/zig/api.lua b/xmake/languages/zig/api.lua deleted file mode 100644 index 3501a2e9d..000000000 --- a/xmake/languages/zig/api.lua +++ /dev/null @@ -1,74 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_zcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_zcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_zcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_zcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - -- option.add_xxx - , "option.add_linkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/zig/load.lua b/xmake/languages/zig/load.lua index fd547b488..418645a5e 100644 --- a/xmake/languages/zig/load.lua +++ b/xmake/languages/zig/load.lua @@ -18,17 +18,55 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_zcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_zcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_zcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_zcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/zig/xmake.lua b/xmake/languages/zig/xmake.lua index 117890613..9c85e3962 100644 --- a/xmake/languages/zig/xmake.lua +++ b/xmake/languages/zig/xmake.lua @@ -18,48 +18,26 @@ -- @file xmake.lua -- --- define language language("zig") - - -- set source file kinds + add_rules("zig") set_sourcekinds {zc = ".zig"} - - -- set source file flags set_sourceflags {zc = "zcflags"} - - -- set target kinds set_targetkinds {binary = "zcld", static = "zcar", shared = "zcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {zig = "zc"} - - -- set mixing kinds + set_langkinds {zig = "zc"} set_mixingkinds("zc", "cc", "cxx", "as") - -- add rules - add_rules("zig") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "target.symbols" , "target.warnings" , "target.optimize:check" , "target.vectorexts:check" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -74,8 +52,7 @@ language("zig") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -88,17 +65,14 @@ language("zig") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { - config = - { + config = { {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "zc", "kv", nil, "The Zig Compiler" } diff --git a/xmake/rules/lex_yacc/lex/xmake.lua b/xmake/rules/lex_yacc/lex/xmake.lua index cbdb766e4..adc3c49ec 100644 --- a/xmake/rules/lex_yacc/lex/xmake.lua +++ b/xmake/rules/lex_yacc/lex/xmake.lua @@ -23,10 +23,8 @@ rule("lex") set_extensions(".l", ".ll") on_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt) - -- imports - import("lib.detect.find_tool") - -- get lex + import("lib.detect.find_tool") local lex = assert(find_tool("flex") or find_tool("lex"), "lex not found!") -- get c/c++ source file for lex diff --git a/xmake/rules/lex_yacc/yacc/xmake.lua b/xmake/rules/lex_yacc/yacc/xmake.lua index f93db2ccb..70514cadb 100644 --- a/xmake/rules/lex_yacc/yacc/xmake.lua +++ b/xmake/rules/lex_yacc/yacc/xmake.lua @@ -23,10 +23,8 @@ rule("yacc") set_extensions(".y", ".yy") before_buildcmd_file(function (target, batchcmds, sourcefile_yacc, opt) - -- imports - import("lib.detect.find_tool") - -- get yacc + import("lib.detect.find_tool") local yacc = assert(find_tool("bison") or find_tool("yacc"), "yacc/bison not found!") -- get c/c++ source file for yacc diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua new file mode 100644 index 000000000..a2ce76937 --- /dev/null +++ b/xmake/rules/vala/xmake.lua @@ -0,0 +1,64 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("vala") + set_extensions(".vala") + on_load(function (target) + -- only vala source files? we need patch c source kind for linker + local sourcekinds = target:sourcekinds() + if #sourcekinds == 0 then + table.insert(sourcekinds, "cc") + end + end) + before_buildcmd_file(function (target, batchcmds, sourcefile_vala, opt) + + -- get valac + import("lib.detect.find_tool") + local valac = assert(find_tool("valac"), "valac not found!") + + -- get c source file for vala + local sourcefile_c = target:autogenfile((sourcefile_vala:gsub(".vala$", ".c"))) + local basedir = path.directory(sourcefile_c) + + -- add objectfile + local objectfile = target:objectfile(sourcefile_c) + table.insert(target:objectfiles(), objectfile) + + -- add commands + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.vala %s", sourcefile_vala) + batchcmds:mkdir(basedir) + local argv = {"-C", "-b", basedir} + local packages = target:values("vala.packages") + if packages then + for _, package in ipairs(packages) do + table.insert(argv, "--pkg") + table.insert(argv, package) + end + end + table.insert(argv, sourcefile_vala) + batchcmds:vrunv(valac.program, argv) + batchcmds:compile(sourcefile_c, objectfile) + + -- add deps + batchcmds:add_depfiles(sourcefile_vala) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + end) + |
