summaryrefslogtreecommitdiff
path: root/xmake/modules/package/tools/make.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/modules/package/tools/make.lua')
-rw-r--r--xmake/modules/package/tools/make.lua61
1 files changed, 43 insertions, 18 deletions
diff --git a/xmake/modules/package/tools/make.lua b/xmake/modules/package/tools/make.lua
index b236b9da6..27e73b412 100644
--- a/xmake/modules/package/tools/make.lua
+++ b/xmake/modules/package/tools/make.lua
@@ -21,6 +21,15 @@
-- imports
import("core.base.option")
import("core.project.config")
+import("lib.detect.find_tool")
+
+-- translate bin path
+function _translate_bin_path(bin_path)
+ if is_host("windows") and bin_path then
+ return bin_path:gsub("\\", "/") .. ".exe"
+ end
+ return bin_path
+end
-- get the build environments
function buildenvs(package)
@@ -43,13 +52,14 @@ function buildenvs(package)
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.CC = _translate_bin_path(package:build_getenv("cc"))
+ envs.CXX = _translate_bin_path(package:build_getenv("cxx"))
+ envs.AS = _translate_bin_path(package:build_getenv("as"))
+ envs.AR = _translate_bin_path(package:build_getenv("ar"))
+ envs.LD = _translate_bin_path(package:build_getenv("ld"))
+ envs.LDSHARED = _translate_bin_path(package:build_getenv("sh"))
+ envs.CPP = _translate_bin_path(package:build_getenv("cpp"))
+ envs.RANLIB = _translate_bin_path(package:build_getenv("ranlib"))
envs.CFLAGS = table.concat(cflags, ' ')
envs.CXXFLAGS = table.concat(cxxflags, ' ')
envs.ASFLAGS = table.concat(table.wrap(package:build_getenv("asflags")), ' ')
@@ -75,9 +85,32 @@ function buildenvs(package)
end
envs.ACLOCAL_PATH = path.joinenv(ACLOCAL_PATH)
envs.PKG_CONFIG_PATH = path.joinenv(PKG_CONFIG_PATH)
+ -- some Makefile use ComSpec to detect Windows (e.g. Makefiles generated by Premake) and require this env
+ if is_subhost("windows") then
+ envs.ComSpec = os.getenv("ComSpec")
+ end
+
return envs
end
+-- do make
+function make(package, argv, opt)
+ opt = opt or {}
+ local program
+ local runenvs = opt.envs or buildenvs(package)
+ if package:is_plat("mingw") and is_subhost("windows") then
+ local mingw = assert(package:build_getenv("mingw") or package:build_getenv("sdk"), "mingw not found!")
+ program = path.join(mingw, "bin", "mingw32-make.exe")
+ else
+ local tool = find_tool("make", {envs = runenvs})
+ if tool then
+ program = tool.program
+ end
+ end
+ assert(program, "make not found!")
+ os.vrunv(program, argv, {envs = runenvs, curdir = opt.curdir})
+end
+
-- build package
function build(package, configs, opt)
@@ -85,7 +118,7 @@ function build(package, configs, opt)
opt = opt or {}
-- pass configurations
- local njob = opt.jobs or option.get("jobs") or tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2))
+ local njob = opt.jobs or option.get("jobs") or tostring(os.default_njob())
local argv = {"-j" .. njob}
if option.get("verbose") then
table.insert(argv, "VERBOSE=1")
@@ -102,11 +135,7 @@ function build(package, configs, opt)
end
-- do build
- if is_host("bsd") then
- os.vrunv("gmake", argv, {envs = opt.envs or buildenvs(package)})
- else
- os.vrunv("make", argv, {envs = opt.envs or buildenvs(package)})
- end
+ make(package, argv, opt)
end
-- install package
@@ -121,9 +150,5 @@ function install(package, configs, opt)
if option.get("verbose") then
table.insert(argv, "VERBOSE=1")
end
- if is_host("bsd") then
- os.vrunv("gmake", argv, {envs = opt.envs or buildenvs(package)})
- else
- os.vrunv("make", argv, {envs = opt.envs or buildenvs(package)})
- end
+ make(package, argv, opt)
end