summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 19:19:39 +0800
committerruki <[email protected]>2022-05-22 19:19:39 +0800
commita3d82bd43a50906804597a86a9deea950c2e5adb (patch)
tree811a5049e80812beb0f9434a3e5cf93e0adae05d
parent59b0d6109513a973815ff08a811305d70ec5fe01 (diff)
improve lex yacc rules
-rw-r--r--xmake/core/base/path.lua13
-rw-r--r--xmake/rules/asn1c/xmake.lua2
-rw-r--r--xmake/rules/lex_yacc/lex/xmake.lua2
-rw-r--r--xmake/rules/lex_yacc/yacc/xmake.lua7
4 files changed, 20 insertions, 4 deletions
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index 04c386c23..4f534bb50 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -26,6 +26,9 @@ local string = require("base/string")
local table = require("base/table")
local _instance = _instance or {}
+-- save original interfaces
+path._absolute = path._absolute or path.absolute
+
-- new a path
function _instance.new(p, transform)
local instance = table.inherit(_instance)
@@ -95,6 +98,10 @@ function _instance:directory()
return path.new(path.directory(self:str()), self._TRANSFORM)
end
+function _instance:absolute()
+ return path.new(path.absolute(self:str()), self._TRANSFORM)
+end
+
function _instance:join(...)
local items = {self:str()}
for _, item in ipairs(table.pack(...)) do
@@ -165,6 +172,12 @@ if not path.directory then
end
end
+-- get absolute path
+function path.absolute(p)
+ p = tostring(p)
+ return path._absolute(p)
+end
+
-- get the filename of the path
function path.filename(p, sep)
p = tostring(p)
diff --git a/xmake/rules/asn1c/xmake.lua b/xmake/rules/asn1c/xmake.lua
index 7efbcd040..cc1c60dd0 100644
--- a/xmake/rules/asn1c/xmake.lua
+++ b/xmake/rules/asn1c/xmake.lua
@@ -30,7 +30,7 @@ rule("asn1c")
local sourcefile_dir = path.join(target:autogendir(), "rules", "asn1c")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.asn1c %s", sourcefile_asn1)
batchcmds:mkdir(sourcefile_dir)
- batchcmds:vrunv(asn1c.program, {path.absolute(sourcefile_asn1)}, {curdir = sourcefile_dir})
+ batchcmds:vrunv(asn1c.program, {path(sourcefile_asn1):absolute()}, {curdir = sourcefile_dir})
-- compile *.c
for _, sourcefile in ipairs(os.files(path.join(sourcefile_dir, "*.c|converter-*.c"))) do
diff --git a/xmake/rules/lex_yacc/lex/xmake.lua b/xmake/rules/lex_yacc/lex/xmake.lua
index adc3c49ec..e8c30d204 100644
--- a/xmake/rules/lex_yacc/lex/xmake.lua
+++ b/xmake/rules/lex_yacc/lex/xmake.lua
@@ -38,7 +38,7 @@ rule("lex")
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.lex %s", sourcefile_lex)
batchcmds:mkdir(path.directory(sourcefile_cx))
- batchcmds:vrunv(lex.program, {"-o", sourcefile_cx, sourcefile_lex})
+ batchcmds:vrunv(lex.program, {"-o", path(sourcefile_cx), path(sourcefile_lex)})
batchcmds:compile(sourcefile_cx, objectfile)
-- add deps
diff --git a/xmake/rules/lex_yacc/yacc/xmake.lua b/xmake/rules/lex_yacc/yacc/xmake.lua
index 70514cadb..021780c5f 100644
--- a/xmake/rules/lex_yacc/yacc/xmake.lua
+++ b/xmake/rules/lex_yacc/yacc/xmake.lua
@@ -21,6 +21,10 @@
-- define rule: yacc
rule("yacc")
set_extensions(".y", ".yy")
+ on_load(function (target)
+ local sourcefile_dir = path.join(target:autogendir(), "rules", "yacc_yacc")
+ target:add("includedirs", sourcefile_dir)
+ end)
before_buildcmd_file(function (target, batchcmds, sourcefile_yacc, opt)
-- get yacc
@@ -37,12 +41,11 @@ rule("yacc")
-- add includedirs
local sourcefile_dir = path.directory(sourcefile_cx)
- target:add("includedirs", sourcefile_dir)
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.yacc %s", sourcefile_yacc)
batchcmds:mkdir(sourcefile_dir)
- batchcmds:vrunv(yacc.program, {"-d", "-o", sourcefile_cx, sourcefile_yacc})
+ batchcmds:vrunv(yacc.program, {"-d", "-o", path(sourcefile_cx), path(sourcefile_yacc)})
batchcmds:compile(sourcefile_cx, objectfile)
-- add deps