summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-29 22:43:45 +0800
committerruki <[email protected]>2021-07-29 22:43:45 +0800
commite2067d1b58aeec0024ac2f52e7599a4893b15f14 (patch)
tree783e31fb7410f9e2eb17a47fbb6b7a6b1c09a74b /xmake
parent6acd768b2f692c49ddc89b5fffdfed0bf75744dc (diff)
impl vala rule
Diffstat (limited to 'xmake')
-rw-r--r--xmake/languages/vala/check_main.lua40
-rw-r--r--xmake/languages/vala/load.lua72
-rw-r--r--xmake/languages/vala/xmake.lua85
-rw-r--r--xmake/rules/lex_yacc/lex/xmake.lua4
-rw-r--r--xmake/rules/lex_yacc/yacc/xmake.lua4
-rw-r--r--xmake/rules/vala/xmake.lua33
6 files changed, 33 insertions, 205 deletions
diff --git a/xmake/languages/vala/check_main.lua b/xmake/languages/vala/check_main.lua
deleted file mode 100644
index b2251f190..000000000
--- a/xmake/languages/vala/check_main.lua
+++ /dev/null
@@ -1,40 +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 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
deleted file mode 100644
index 32ab9cae2..000000000
--- a/xmake/languages/vala/load.lua
+++ /dev/null
@@ -1,72 +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 load.lua
---
-
-function _get_apis()
- local apis = {}
- apis.values = {
- -- target.add_xxx
- "target.add_links"
- , "target.add_syslinks"
- , "target.add_vaflags"
- , "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_vaflags"
- , "option.add_ldflags"
- , "option.add_arflags"
- , "option.add_shflags"
- , "option.add_rpathdirs"
- -- package.add_xxx
- , "package.add_links"
- , "package.add_syslinks"
- , "package.add_vaflags"
- , "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_vaflags"
- , "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
-
-function main()
- return {apis = _get_apis()}
-end
-
-
diff --git a/xmake/languages/vala/xmake.lua b/xmake/languages/vala/xmake.lua
deleted file mode 100644
index 16cc226f3..000000000
--- a/xmake/languages/vala/xmake.lua
+++ /dev/null
@@ -1,85 +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 xmake.lua
---
-
-language("vala")
- add_rules("vala")
- set_sourcekinds {va = ".vala"}
- set_sourceflags {va = "vaflags"}
- set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
- set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
- set_langkinds {vala = "va"}
- set_mixingkinds("va", "cc", "cxx", "as")
-
- on_load("load")
- on_check_main("check_main")
-
- 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 {
- config = {
- {category = "Cross Complation Configuration/Compiler Configuration" }
- , {nil, "va", "kv", nil, "The Vala Compiler" }
-
- , {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/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
index 11b002a02..6de49665c 100644
--- a/xmake/rules/vala/xmake.lua
+++ b/xmake/rules/vala/xmake.lua
@@ -20,9 +20,38 @@
rule("vala")
set_extensions(".vala")
- before_buildcmd_files(function (target, batchcmds, sourcebatch, opt)
+ 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!")
- print(sourcebatch)
+
+ -- get c source file for vala
+ local sourcefile_c = path.join(target:autogendir(), "rules", "vala", path.basename(sourcefile_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)