Builtin variables and shell
原文链接 https://waruqi.github.io/2016/07/18/builtinvar-and-shell/
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。
xmake provides the grammar: $(varname)
for supporting builtin variable.
.e.g
add_cxflags("-I$(buildir)")
It will translate this variable to the real value when building.
-I$(buildir) => -I./build
We can also use these variables in the custom scripts.
target("test")
after_build(target)
print("build ok for $(plat)!")
end
And the output result is
build ok for macosx!
xmake will get values of these valriables from the cached configure after running xmake config --plat=macosx ...
Also we have some variables which are not in the configure file.
.e.g
print("$(os)")
print("$(host)")
print("$(tmpdir)")
print("$(curdir)")
we can uses these variable for writing xmake.lua
more easily.
.e.g
os.cp("$(projectdir)/file", "$(tmpdir)")
vs
-- import project module
import("core.project.project")
-- copy file
os.cp(path.join(project.directory(), "file"), os.tmpdir())
xmake can also run native shell for calling some third-party tools.
.e.g
target("test")
set_kind("binary")
if is_plat("linux") then
add_ldflags("$(shell pkg-config --libs sqlite3)")
end
Or
target("test")
set_kind("binary")
if is_plat("linux") then
add_linkdir("$(shell find ./ -name lib)")
end
But often, we do not need to do this. The Lua srcipt has been very powerful : )