summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-05-10 22:53:49 +0800
committerruki <[email protected]>2019-05-10 11:22:55 +0800
commit13e02d0fa943dfd9ea3a0f4c2184a3df46058a20 (patch)
tree9be65f482df4d26dc16606ef19a80f0b10511a5a
parent6f3d4c780f2bb0f7334f808f70189e98d0d9e49c (diff)
improve package:script()
-rw-r--r--xmake/core/package/package.lua32
-rw-r--r--xmake/core/project/rule.lua35
-rw-r--r--xmake/core/project/target.lua35
-rw-r--r--xmake/modules/package/tools/meson.lua124
-rw-r--r--xmake/repository/packages/7/7z/xmake.lua4
-rw-r--r--xmake/repository/packages/g/git/xmake.lua6
6 files changed, 179 insertions, 57 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 9ddef427d..799776582 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -671,45 +671,29 @@ function _instance:script(name, generic)
local plat = self:plat() or ""
local arch = self:arch() or ""
- -- match script for special plat and arch
- local pattern = plat .. '|' .. arch
+ -- match pattern
+ --
+ -- `@macosx,linux`
+ -- `android@macosx,linux`
+ -- `android|armv7-a@macosx,linux`
+ --
for _pattern, _script in pairs(script) do
local hosts = {}
local hosts_spec = false
_pattern = _pattern:gsub("@(.+)", function (v)
- -- get and remove hosts for `android|armv7-a@macosx,linux`
for _, host in ipairs(v:split(',')) do
hosts[host] = true
hosts_spec = true
end
return ""
end)
- if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') and (not hosts_spec or hosts[os.host()]) then
+ if not _pattern:startswith("__") and (not hosts_spec or hosts[os.host()])
+ and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
result = _script
break
end
end
- -- match script for special plat
- if result == nil then
- for _pattern, _script in pairs(script) do
- local hosts = {}
- local hosts_spec = false
- _pattern = _pattern:gsub("@(.+)", function (v)
- -- get and remove hosts for `android@macosx,linux`
- for _, host in ipairs(v:split(',')) do
- hosts[host] = true
- hosts_spec = true
- end
- return ""
- end)
- if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') and (not hosts_spec or hosts[os.host()]) then
- result = _script
- break
- end
- end
- end
-
-- get generic script
result = result or script["__generic__"] or generic
end
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua
index aa72b5c11..8bf3b3f3e 100644
--- a/xmake/core/project/rule.lua
+++ b/xmake/core/project/rule.lua
@@ -240,26 +240,33 @@ function rule:script(name, generic)
result = script
elseif type(script) == "table" then
- -- match script for special plat and arch
- local plat = (config.get("plat") or "")
- local pattern = plat .. '|' .. (config.get("arch") or "")
+ -- get plat and arch
+ local plat = config.get("plat") or ""
+ local arch = config.get("arch") or ""
+
+ -- match pattern
+ --
+ -- `@macosx,linux`
+ -- `android@macosx,linux`
+ -- `android|armv7-a@macosx,linux`
+ --
for _pattern, _script in pairs(script) do
- if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') then
+ local hosts = {}
+ local hosts_spec = false
+ _pattern = _pattern:gsub("@(.+)", function (v)
+ for _, host in ipairs(v:split(',')) do
+ hosts[host] = true
+ hosts_spec = true
+ end
+ return ""
+ end)
+ if not _pattern:startswith("__") and (not hosts_spec or hosts[os.host()])
+ and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
result = _script
break
end
end
- -- match script for special plat
- if result == nil then
- for _pattern, _script in pairs(script) do
- if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') then
- result = _script
- break
- end
- end
- end
-
-- get generic script
result = result or script["__generic__"] or generic
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index cebbfec7d..86b86fe70 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1332,26 +1332,33 @@ function _instance:script(name, generic)
result = script
elseif type(script) == "table" then
- -- match script for special plat and arch
- local plat = (config.get("plat") or "")
- local pattern = plat .. '|' .. (config.get("arch") or "")
+ -- get plat and arch
+ local plat = config.get("plat") or ""
+ local arch = config.get("arch") or ""
+
+ -- match pattern
+ --
+ -- `@macosx,linux`
+ -- `android@macosx,linux`
+ -- `android|armv7-a@macosx,linux`
+ --
for _pattern, _script in pairs(script) do
- if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') then
+ local hosts = {}
+ local hosts_spec = false
+ _pattern = _pattern:gsub("@(.+)", function (v)
+ for _, host in ipairs(v:split(',')) do
+ hosts[host] = true
+ hosts_spec = true
+ end
+ return ""
+ end)
+ if not _pattern:startswith("__") and (not hosts_spec or hosts[os.host()])
+ and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
result = _script
break
end
end
- -- match script for special plat
- if result == nil then
- for _pattern, _script in pairs(script) do
- if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') then
- result = _script
- break
- end
- end
- end
-
-- get generic script
result = result or script["__generic__"] or generic
end
diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua
new file mode 100644
index 000000000..f977475ab
--- /dev/null
+++ b/xmake/modules/package/tools/meson.lua
@@ -0,0 +1,124 @@
+--!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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file meson.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.config")
+
+-- get build directory
+function _get_buildir()
+ _g.buildir = _g.buildir or "build_" .. hash.uuid():split('%-')[1]
+ return _g.buildir
+end
+
+-- get configs
+function _get_configs(package, configs)
+
+ -- add prefix
+ local configs = configs or {}
+ table.insert(configs, "--prefix=" .. package:installdir())
+
+ -- add build directory
+ table.insert(configs, _get_buildir())
+ return configs
+end
+
+-- get the build environments
+function buildenvs(package)
+ local envs = {}
+ if package:is_plat(os.host()) then
+ local cflags = table.join(table.wrap(package:config("cxflags")), package:config("cflags"))
+ local cxxflags = table.join(table.wrap(package:config("cxflags")), package:config("cxxflags"))
+ envs.CFLAGS = table.concat(cflags, ' ')
+ envs.CXXFLAGS = table.concat(cxxflags, ' ')
+ envs.ASFLAGS = table.concat(table.wrap(package:config("asflags")), ' ')
+ else
+ local cflags = table.join(table.wrap(package:build_getenv("cxflags")), package:build_getenv("cflags"))
+ local cxxflags = table.join(table.wrap(package:build_getenv("cxflags")), package:build_getenv("cxxflags"))
+ envs.CC = package:build_getenv("cc")
+ envs.AS = package:build_getenv("as")
+ envs.AR = package:build_getenv("ar")
+ envs.LD = package:build_getenv("ld")
+ envs.LDSHARED = package:build_getenv("sh")
+ envs.CPP = package:build_getenv("cpp")
+ envs.RANLIB = package:build_getenv("ranlib")
+ envs.CFLAGS = table.concat(cflags, ' ')
+ envs.CXXFLAGS = table.concat(cxxflags, ' ')
+ envs.ASFLAGS = table.concat(table.wrap(package:build_getenv("asflags")), ' ')
+ envs.ARFLAGS = table.concat(table.wrap(package:build_getenv("arflags")), ' ')
+ envs.LDFLAGS = table.concat(table.wrap(package:build_getenv("ldflags")), ' ')
+ envs.SHFLAGS = table.concat(table.wrap(package:build_getenv("shflags")), ' ')
+ end
+ local ACLOCAL_PATH = {}
+ local PKG_CONFIG_PATH = {}
+ for _, dep in ipairs(package:orderdeps()) do
+ local pkgconfig = path.join(dep:installdir(), "lib", "pkgconfig")
+ if os.isdir(pkgconfig) then
+ table.insert(PKG_CONFIG_PATH, pkgconfig)
+ end
+ local aclocal = path.join(dep:installdir(), "share", "aclocal")
+ if os.isdir(aclocal) then
+ table.insert(ACLOCAL_PATH, aclocal)
+ end
+ end
+ envs.ACLOCAL_PATH = table.concat(ACLOCAL_PATH, path.envsep())
+ envs.PKG_CONFIG_PATH = table.concat(PKG_CONFIG_PATH, path.envsep())
+ return envs
+end
+
+-- generate build files for ninja
+function generate(package, configs, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- pass configurations
+ local argv = {}
+ for name, value in pairs(_get_configs(package, configs)) do
+ value = tostring(value):trim()
+ if value ~= "" then
+ if type(name) == "number" then
+ table.insert(argv, value)
+ else
+ table.insert(argv, "--" .. name .. "=" .. value)
+ end
+ end
+ end
+
+ -- do configure
+ os.vrunv("meson", argv, {envs = opt.envs or buildenvs(package)})
+end
+
+-- install package
+function install(package, configs, opt)
+
+ -- generate build files
+ generate(package, configs, opt)
+
+ -- do build and install
+ local buildir = _get_buildir()
+ if option.get("verbose") or option.get("diagnosis") then
+ os.vrunv("ninja", {"-v", "-C", buildir})
+ os.vrunv("ninja", {"install", "-v", "-C", buildir})
+ else
+ os.vrunv("ninja", {"-C", buildir})
+ os.vrunv("ninja", {"install", "-C", buildir})
+ end
+end
diff --git a/xmake/repository/packages/7/7z/xmake.lua b/xmake/repository/packages/7/7z/xmake.lua
index 5ddbeed72..6cf58320e 100644
--- a/xmake/repository/packages/7/7z/xmake.lua
+++ b/xmake/repository/packages/7/7z/xmake.lua
@@ -26,12 +26,12 @@ package("7z")
add_versions("gitlab:16.02", "93c6a14efb6dc9ee2fbb8c8fd4b5f319537c98182f8810f3b25cfa6363d9905b")
end
- on_install("macosx", "linux", function (package)
+ on_install("@macosx", "@linux", function (package)
os.vrun("make 7z")
os.cp("bin", package:installdir())
end)
- on_install("windows", function (package)
+ on_install("@windows", function (package)
os.cp("*", package:installdir("bin"))
end)
diff --git a/xmake/repository/packages/g/git/xmake.lua b/xmake/repository/packages/g/git/xmake.lua
index f14d0c71b..739f5dd13 100644
--- a/xmake/repository/packages/g/git/xmake.lua
+++ b/xmake/repository/packages/g/git/xmake.lua
@@ -26,16 +26,16 @@ package("git")
end
end
- on_load("windows", function (package)
+ on_load("@windows", function (package)
package:addenv("PATH", path.join("share", "MinGit", "mingw32", "bin"))
package:addenv("PATH", path.join("share", "MinGit", "cmd"))
end)
- on_install("macosx", "linux", function (package)
+ on_install("@macosx", "@linux", function (package)
import("package.manager.install_package")("git")
end)
- on_install("windows", function (package)
+ on_install("@windows", function (package)
os.cp("*", package:installdir("share/MinGit"))
end)