Skip to content

Commit

Permalink
improve nmake
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Apr 10, 2024
1 parent 86075cd commit 7e7b37e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
2 changes: 0 additions & 2 deletions xmake/modules/package/tools/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ end

-- build package
function build(package, configs, opt)

-- init options
opt = opt or {}

-- pass configurations
Expand Down
45 changes: 22 additions & 23 deletions xmake/modules/package/tools/nmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import("lib.detect.find_tool")

-- get msvc
function _get_msvc(package)
local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
assert(msvc:check(), "vs not found!") -- we need check vs envs if it has been not checked yet
local msvc = package:toolchain("msvc")
assert(msvc:check(), "vs not found!") -- we need to check vs envs if it has been not checked yet
return msvc
end

Expand All @@ -36,10 +36,21 @@ function buildenvs(package, opt)
return os.joinenvs(_get_msvc(package):runenvs())
end

-- do make
function make(package, argv, opt)
opt = opt or {}
local program
local runenvs = opt.envs or buildenvs(package)
local tool = find_tool("nmake", {envs = runenvs})
if tool then
program = tool.program
end
assert(program, "nmake not found!")
os.vrunv(program, argv or {}, {envs = runenvs, curdir = opt.curdir})
end

-- build package
function build(package, configs, opt)

-- pass configurations
opt = opt or {}
local argv = {}
if option.get("verbose") then
Expand All @@ -57,33 +68,21 @@ function build(package, configs, opt)
end

-- do build
local runenvs = opt.envs or buildenvs(package, opt)
local nmake = find_tool("nmake", {envs = runenvs})
os.vrunv(nmake.program, argv, {envs = runenvs})
make(package, argv, opt)
end

-- install package
function install(package, configs, opt)

-- pass configurations
-- do build
opt = opt or {}
build(package, configs, opt)

-- do install
local argv = {"install"}
if option.get("verbose") then
table.insert(argv, "VERBOSE=1")
table.insert(argv, "V=1")
end
for name, value in pairs(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 install
local runenvs = opt.envs or buildenvs(package, opt)
local nmake = find_tool("nmake", {envs = runenvs})
os.vrunv(nmake.program, argv, {envs = runenvs})
make(package, argv, opt)
end

0 comments on commit 7e7b37e

Please sign in to comment.