summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-09-21 16:02:01 +0800
committerGitHub <[email protected]>2024-09-21 16:02:01 +0800
commitf56adb75cd226f28d4d92196fcd502d52e251fa4 (patch)
treea6aa5a98fc17549fe9384d9e8f26394105bda01c
parent9563841bfc304874cc9d308b1e29bd6cde76631a (diff)
parentf92bdc11978e585ae349432e3c519861b803f604 (diff)
Merge pull request #5634 from A2va/install-opt
Allows installdir, bindir and libdir to be configured via opt arguments
-rw-r--r--xmake/modules/target/action/install/main.lua31
-rw-r--r--xmake/modules/target/action/uninstall/main.lua32
2 files changed, 47 insertions, 16 deletions
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua
index b1ae56a4d..9b70a9096 100644
--- a/xmake/modules/target/action/install/main.lua
+++ b/xmake/modules/target/action/install/main.lua
@@ -25,6 +25,22 @@ import("core.project.project")
import("utils.binary.deplibs", {alias = "get_depend_libraries"})
import("utils.binary.rpath", {alias = "rpath_utils"})
+function _get_target_libdir(target, opt)
+ if not opt.installdir then
+ return target:libdir()
+ end
+ assert(opt.libdir, "opt.libdir is missing")
+ return path.join(opt.installdir, opt.libdir)
+end
+
+function _get_target_bindir(target, opt)
+ if not opt.installdir then
+ return target:bindir()
+ end
+ assert(opt.bindir, "opt.bindir is missing")
+ return path.join(opt.installdir, opt.bindir)
+end
+
-- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ...
-- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732
function _get_target_package_deplibs(target, depends, libfiles, binaryfile)
@@ -123,7 +139,7 @@ end
-- install shared libraries
function _install_shared_libraries(target, opt)
- local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
+ local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
-- get all dependent shared libraries
local libfiles = {}
@@ -158,7 +174,7 @@ function _update_install_rpath(target, opt)
if target:is_plat("windows", "mingw") then
return
end
- local bindir = target:bindir()
+ local bindir = _get_target_bindir(target, opt)
local targetfile = path.join(bindir, target:filename())
if target:policy("install.rpath") then
local result, sources = target:get_from("rpathdirs", "*")
@@ -179,7 +195,7 @@ end
-- install binary
function _install_binary(target, opt)
- local bindir = target:bindir()
+ local bindir = _get_target_bindir(target, opt)
os.mkdir(bindir)
os.vcp(target:targetfile(), bindir)
os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile())))
@@ -189,7 +205,7 @@ end
-- install shared library
function _install_shared(target, opt)
- local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
+ local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
os.mkdir(bindir)
local targetfile = target:targetfile()
@@ -197,7 +213,7 @@ function _install_shared(target, opt)
-- install *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/714
os.vcp(target:targetfile(), bindir)
- local libdir = target:libdir()
+ local libdir = _get_target_libdir(target, opt)
local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib"))
if os.isfile(targetfile_lib) then
os.mkdir(libdir)
@@ -215,7 +231,7 @@ end
-- install static library
function _install_static(target, opt)
- local libdir = target:libdir()
+ local libdir = _get_target_libdir(target, opt)
os.mkdir(libdir)
os.vcp(target:targetfile(), libdir)
os.trycp(target:symbolfile(), path.join(libdir, path.filename(target:symbolfile())))
@@ -233,7 +249,8 @@ function _install_moduleonly(target, opt)
end
function main(target, opt)
- local installdir = target:installdir()
+ opt = opt or {}
+ local installdir = opt.installdir or target:installdir()
if not installdir then
wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.")
return
diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua
index 912e5140f..e36d5617a 100644
--- a/xmake/modules/target/action/uninstall/main.lua
+++ b/xmake/modules/target/action/uninstall/main.lua
@@ -25,6 +25,22 @@ import("core.project.project")
import("utils.binary.deplibs", {alias = "get_depend_libraries"})
import("private.action.clean.remove_files")
+function _get_target_libdir(target, opt)
+ if not opt.installdir then
+ return target:libdir()
+ end
+ assert(opt.libdir, "opt.libdir is missing")
+ return path.join(opt.installdir, opt.libdir)
+end
+
+function _get_target_bindir(target, opt)
+ if not opt.installdir then
+ return target:bindir()
+ end
+ assert(opt.bindir, "opt.bindir is missing")
+ return path.join(opt.installdir, opt.bindir)
+end
+
-- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ...
-- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732
function _get_target_package_deplibs(target, depends, libfiles, binaryfile)
@@ -50,7 +66,6 @@ function _get_target_package_libfiles(target, opt)
return {}
end
local libfiles = {}
- local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
for _, pkg in ipairs(target:orderpkgs(opt)) do
if pkg:enabled() and pkg:get("libfiles") then
for _, libfile in ipairs(table.wrap(pkg:get("libfiles"))) do
@@ -114,8 +129,7 @@ end
-- uninstall shared libraries
function _uninstall_shared_libraries(target, opt)
- local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
-
+ local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
-- get all dependent shared libraries
local libfiles = {}
for _, dep in ipairs(target:orderdeps()) do
@@ -142,7 +156,7 @@ end
-- uninstall binary
function _uninstall_binary(target, opt)
- local bindir = target:bindir()
+ local bindir = _get_target_bindir(target, opt)
remove_files(path.join(bindir, path.filename(target:targetfile())), {emptydir = true})
remove_files(path.join(bindir, path.filename(target:symbolfile())), {emptydir = true})
_uninstall_shared_libraries(target, opt)
@@ -150,12 +164,11 @@ end
-- uninstall shared library
function _uninstall_shared(target, opt)
- local bindir = target:is_plat("windows", "mingw") and target:bindir() or target:libdir()
-
+ local bindir = target:is_plat("windows", "mingw") and _get_target_bindir(target, opt) or _get_target_libdir(target, opt)
if target:is_plat("windows", "mingw") then
-- uninstall *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/714
- local libdir = target:libdir()
+ local libdir = _get_target_libdir(target, opt)
local targetfile = target:targetfile()
remove_files(path.join(bindir, path.filename(targetfile)), {emptydir = true})
remove_files(path.join(libdir, path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")), {emptydir = true})
@@ -171,7 +184,7 @@ end
-- uninstall static library
function _uninstall_static(target, opt)
- local libdir = target:libdir()
+ local libdir = _get_target_libdir(target, opt)
remove_files(path.join(libdir, path.filename(target:targetfile())), {emptydir = true})
remove_files(path.join(libdir, path.filename(target:symbolfile())), {emptydir = true})
_uninstall_headers(target, opt)
@@ -188,7 +201,8 @@ function _uninstall_moduleonly(target, opt)
end
function main(target, opt)
- local installdir = target:installdir()
+ opt = opt or {}
+ local installdir = opt.installdir or target:installdir()
if not installdir then
wprint("please use `xmake install -o installdir` or `set_installdir` to set install directory.")
return