diff options
| author | ruki <[email protected]> | 2021-07-28 22:36:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-07-28 22:36:39 +0800 |
| commit | 6ce79433b71434680d166710e403360998b8a44f (patch) | |
| tree | 1a47e754bbca5772ba6dd1b86386ece188e271d7 | |
| parent | 111499e18c11b613e710159c0a27e5f0e4e0d913 (diff) | |
add vala language
| -rw-r--r-- | tests/projects/vala/sdl/src/main.vala (renamed from tests/projects/vala/sdl/main.vala) | 0 | ||||
| -rw-r--r-- | tests/projects/vala/sdl/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/languages/vala/api.lua | 74 | ||||
| -rw-r--r-- | xmake/languages/vala/check_main.lua | 40 | ||||
| -rw-r--r-- | xmake/languages/vala/load.lua | 34 | ||||
| -rw-r--r-- | xmake/languages/vala/xmake.lua | 116 | ||||
| -rw-r--r-- | xmake/rules/vala/xmake.lua | 28 |
7 files changed, 297 insertions, 0 deletions
diff --git a/tests/projects/vala/sdl/main.vala b/tests/projects/vala/sdl/src/main.vala index c8aa2588b..c8aa2588b 100644 --- a/tests/projects/vala/sdl/main.vala +++ b/tests/projects/vala/sdl/src/main.vala diff --git a/tests/projects/vala/sdl/xmake.lua b/tests/projects/vala/sdl/xmake.lua new file mode 100644 index 000000000..7f7266724 --- /dev/null +++ b/tests/projects/vala/sdl/xmake.lua @@ -0,0 +1,5 @@ +add_rules("mode.release", "mode.debug") + +target("test") + set_kind("binary") + add_files("src/*.vala") diff --git a/xmake/languages/vala/api.lua b/xmake/languages/vala/api.lua new file mode 100644 index 000000000..3501a2e9d --- /dev/null +++ b/xmake/languages/vala/api.lua @@ -0,0 +1,74 @@ +--!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/vala/check_main.lua b/xmake/languages/vala/check_main.lua new file mode 100644 index 000000000..b2251f190 --- /dev/null +++ b/xmake/languages/vala/check_main.lua @@ -0,0 +1,40 @@ +--!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 check_main.lua +-- + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.readfile(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("/%*.-%*/", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find "public static int main (string[] args) {" + if sourcecode:find("public%s+static%s+int%s+main%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/vala/load.lua b/xmake/languages/vala/load.lua new file mode 100644 index 000000000..fd547b488 --- /dev/null +++ b/xmake/languages/vala/load.lua @@ -0,0 +1,34 @@ +--!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 load.lua +-- + +-- imports +import("api") + +-- load it +function main() + + -- init apis + _g.apis = api.apis() + + -- ok + return _g +end + + diff --git a/xmake/languages/vala/xmake.lua b/xmake/languages/vala/xmake.lua new file mode 100644 index 000000000..09f6a7f6b --- /dev/null +++ b/xmake/languages/vala/xmake.lua @@ -0,0 +1,116 @@ +--!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 +-- + +-- define language +language("vala") + + -- set source file kinds + set_sourcekinds {va = ".vala"} + + -- set source file flags + set_sourceflags {va = "vaflags"} + + -- set target kinds + set_targetkinds {binary = "vald", static = "vaar", shared = "vash"} + + -- set target flags + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + + -- set language kinds + set_langkinds {vala = "va"} + + -- set mixing kinds + set_mixingkinds("va", "cc", "cxx", "as") + + -- add rules + add_rules("vala") + + -- on load + on_load("load") + + -- on check_main + on_check_main("check_main") + + -- set name flags + set_nameflags + { + object = + { + "target.symbols" + , "target.warnings" + , "target.optimize:check" + , "target.vectorexts:check" + } + , binary = + { + "config.linkdirs" + , "target.linkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "config.links" + , "target.links" + , "toolchain.links" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , shared = + { + "config.linkdirs" + , "target.linkdirs" + , "target.strip" + , "target.symbols" + , "toolchain.linkdirs" + , "config.links" + , "target.links" + , "toolchain.links" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , static = + { + "target.strip" + , "target.symbols" + } + } + + -- set menu + set_menu { + config = + { + {category = "Cross Complation Configuration/Compiler Configuration" } + , {nil, "va", "kv", nil, "The Vala Compiler" } + + , {category = "Cross Complation Configuration/Linker Configuration" } + , {nil, "vald", "kv", nil, "The Vala Linker" } + , {nil, "vaar", "kv", nil, "The Vala Static Library Archiver" } + , {nil, "vash", "kv", nil, "The Vala Shared Library Linker" } + + , {category = "Cross Complation Configuration/Builtin Flags Configuration" } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "syslinks", "kv", nil, "The System Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + } + } + diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua new file mode 100644 index 000000000..11b002a02 --- /dev/null +++ b/xmake/rules/vala/xmake.lua @@ -0,0 +1,28 @@ +--!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") + before_buildcmd_files(function (target, batchcmds, sourcebatch, opt) + import("lib.detect.find_tool") + local valac = assert(find_tool("valac"), "valac not found!") + print(sourcebatch) + end) + |
