diff options
| author | ruki <[email protected]> | 2024-07-23 12:50:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-23 12:50:50 +0800 |
| commit | d4364efee8f1906288ac5c650ae7bd101066240a (patch) | |
| tree | 72baca766710b28ca154f4b0f0983d7e9d8abc00 /xmake/core | |
| parent | 45852e6ffcd3f043d961574e72f40d287a2898ab (diff) | |
| parent | 56ca5adad669d45f400198b0c99a1d20f546970c (diff) | |
Merge pull request #5335 from xmake-io/install
Improve installation
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 63 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 16 |
4 files changed, 63 insertions, 22 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index b0545afc8..9160aa534 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -503,7 +503,7 @@ function os.rm(filepath, opt) return false, errors end if opt.emptydirs then - ok, errors = os._rm_empty_parentdirs(filepath) + ok, errors = os._rm_empty_parentdirs(_filepath) if not ok then return false, errors end diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 7299de719..2a2195cdb 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -68,6 +68,8 @@ function policy.policies() ["build.sanitizer.leak"] = {description = "Enable leak sanitizer for c/c++ building.", type = "boolean"}, -- Enable undefined sanitizer for c/c++ building. ["build.sanitizer.undefined"] = {description = "Enable undefined sanitizer for c/c++ building.", type = "boolean"}, + -- Enable build rpath + ["build.rpath"] = {description = "Enable build rpath.", default = true, type = "boolean"}, -- Enable C++ modules for C++ building, even if no .mpp is involved in the compilation ["build.c++.modules"] = {description = "Enable C++ modules for C++ building.", type = "boolean"}, -- Enable std module @@ -96,6 +98,8 @@ function policy.policies() ["windows.manifest.uac.ui"] = {description = "Enable windows manifest UAC.", type = "boolean"}, -- Automatically build before running ["run.autobuild"] = {description = "Automatically build before running.", type = "boolean"}, + -- Enable install rpath + ["install.rpath"] = {description = "Enable install rpath.", default = true, type = "boolean"}, -- Preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess ["preprocessor.linemarkers"] = {description = "Enable linemarkers for preprocessor.", default = true, type = "boolean"}, -- Preprocessor configuration for ccache/distcc, we can disable it to avoid cache object file with __DATE__, __TIME__ diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 0ed7465d4..e19ea07c5 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1623,20 +1623,56 @@ function _instance:rundir() return baseoption.get("workdir") or self:get("rundir") or path.directory(self:targetfile()) end --- get install directory -function _instance:installdir() +-- get prefix directory +function _instance:prefixdir() + return self:get("prefixdir") +end + +-- get the installed binary directory +function _instance:bindir() + local bindir = self:extraconf("prefixdir", self:prefixdir(), "bindir") + if bindir == nil then + bindir = "bin" + end + return self:installdir(bindir) +end + +-- get the installed library directory +function _instance:libdir() + local libdir = self:extraconf("prefixdir", self:prefixdir(), "libdir") + if libdir == nil then + libdir = "lib" + end + return self:installdir(libdir) +end - -- get it from the cache +-- get the installed include directory +function _instance:includedir() + local includedir = self:extraconf("prefixdir", self:prefixdir(), "includedir") + if includedir == nil then + includedir = "include" + end + return self:installdir(includedir) +end + +-- get install directory +function _instance:installdir(...) + opt = opt or {} local installdir = baseoption.get("installdir") if not installdir then - -- DESTDIR: be compatible with https://www.gnu.org/prep/standards/html_node/DESTDIR.html installdir = self:get("installdir") or os.getenv("INSTALLDIR") or os.getenv("PREFIX") or os.getenv("DESTDIR") or platform.get("installdir") if installdir then installdir = installdir:trim() end end - return installdir + if installdir then + local prefixdir = self:prefixdir() + if prefixdir then + installdir = path.join(installdir, prefixdir) + end + return path.normalize(path.join(installdir, ...)) + end end -- get package directory @@ -2000,7 +2036,7 @@ end -- get the header files function _instance:headerfiles(outputdir, opt) opt = opt or {} - local headerfiles = self:get("headerfiles") + local headerfiles = self:get("headerfiles", opt) or {} -- add_headerfiles("src/*.h", {install = false}) -- @see https://github.com/xmake-io/xmake/issues/2577 if opt.installonly then @@ -2016,13 +2052,12 @@ function _instance:headerfiles(outputdir, opt) return end - local headerdir = outputdir - if not headerdir then - if self:installdir() then - headerdir = path.join(self:installdir(), "include") + if not outputdir then + if self:includedir() then + outputdir = self:includedir() end end - return match_copyfiles(self, "headerfiles", headerdir, {copyfiles = headerfiles}) + return match_copyfiles(self, "headerfiles", outputdir, {copyfiles = headerfiles}) end -- get the configuration files @@ -2036,8 +2071,9 @@ function _instance:configfiles(outputdir) end -- get the install files -function _instance:installfiles(outputdir) - return match_copyfiles(self, "installfiles", outputdir or self:installdir()) +function _instance:installfiles(outputdir, opt) + local installfiles = self:get("installfiles", opt) or {} + return match_copyfiles(self, "installfiles", outputdir or self:installdir(), {copyfiles = installfiles}) end -- get the extra files @@ -2737,6 +2773,7 @@ function target.apis() , "target.set_runargs" , "target.set_exceptions" , "target.set_encodings" + , "target.set_prefixdir" -- target.add_xxx , "target.add_deps" , "target.add_rules" diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 9004f66ee..d626d0372 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -102,21 +102,21 @@ function sandbox_os.cp(srcpath, dstpath, opt) end -- move file or directory -function sandbox_os.mv(srcpath, dstpath) +function sandbox_os.mv(srcpath, dstpath, opt) assert(srcpath and dstpath) srcpath = tostring(srcpath) dstpath = tostring(dstpath) - local ok, errors = os.mv(vformat(srcpath), vformat(dstpath)) + local ok, errors = os.mv(vformat(srcpath), vformat(dstpath), opt) if not ok then os.raise(errors) end end -- remove files or directories -function sandbox_os.rm(filepath) +function sandbox_os.rm(filepath, opt) assert(filepath) filepath = tostring(filepath) - local ok, errors = os.rm(vformat(filepath)) + local ok, errors = os.rm(vformat(filepath), opt) if not ok then os.raise(errors) end @@ -161,12 +161,12 @@ function sandbox_os.vrm(filepath, opt) end -- link file or directory with the verbose info -function sandbox_os.vln(srcpath, dstpath) +function sandbox_os.vln(srcpath, dstpath, opt) assert(srcpath and dstpath) if option.get("verbose") then utils.cprint("${dim}> link %s to %s", srcpath, dstpath) end - return sandbox_os.ln(srcpath, dstpath) + return sandbox_os.ln(srcpath, dstpath, opt) end -- try to copy file or directory @@ -176,9 +176,9 @@ function sandbox_os.trycp(srcpath, dstpath, opt) end -- try to move file or directory -function sandbox_os.trymv(srcpath, dstpath) +function sandbox_os.trymv(srcpath, dstpath, opt) assert(srcpath and dstpath) - return os.mv(vformat(srcpath), vformat(dstpath)) + return os.mv(vformat(srcpath), vformat(dstpath), opt) end -- try to remove files or directories |
