diff options
| author | ruki <[email protected]> | 2020-09-24 00:33:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-09-24 00:33:54 +0800 |
| commit | 87119fd4fa17d754c8cc867caa9b60e4a8836c82 (patch) | |
| tree | dfd962c4c5fe762478c9c161fa73571bad7a0a60 | |
| parent | 8184f42f9b96b5c0fdedc7b1161dfc43d9659dd2 (diff) | |
improve install action
| -rw-r--r-- | xmake/actions/install/install.lua | 117 | ||||
| -rw-r--r-- | xmake/actions/install/install/unix.lua | 60 | ||||
| -rw-r--r-- | xmake/actions/install/install/windows.lua | 90 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 20 |
4 files changed, 181 insertions, 106 deletions
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index 798d4136f..b27d68de7 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -39,82 +39,6 @@ function _install_files(target) end end --- install binary -function _install_binary(target) - - -- is phony target? - if target:isphony() then - return - end - - -- the binary directory - local binarydir = path.join(target:installdir(), "bin") - - -- make the binary directory - os.mkdir(binarydir) - - -- copy the target file - os.vcp(target:targetfile(), binarydir) - - -- copy the dependent shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/961 - for _, dep in ipairs(target:orderdeps()) do - if dep:targetkind() == "shared" and is_plat("windows", "mingw") then - local depfile = dep:targetfile() - if os.isfile(depfile) then - os.vcp(depfile, binarydir) - end - end - end -end - --- install library -function _install_library(target) - - -- is phony target? - if target:isphony() then - return - end - - -- the library directory - local librarydir = path.join(target:installdir(), "lib") - - -- the include directory - local includedir = path.join(target:installdir(), "include") - - -- make the library directory - os.mkdir(librarydir) - - -- make the include directory - os.mkdir(includedir) - - -- copy the target file - os.vcp(target:targetfile(), librarydir) - - -- copy *.lib for shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/714 - if target:targetkind() == "shared" and is_plat("windows", "mingw") then - local targetfile = target:targetfile() - local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") - if os.isfile(targetfile_lib) then - os.vcp(targetfile_lib, librarydir) - end - end - - -- copy headers to the include directory - local srcheaders, dstheaders = target:headerfiles(includedir) - if srcheaders and dstheaders then - local i = 1 - for _, srcheader in ipairs(srcheaders) do - local dstheader = dstheaders[i] - if dstheader then - os.vcp(srcheader, dstheader) - end - i = i + 1 - end - end -end - -- do install target function _do_install_target(target) @@ -127,18 +51,13 @@ function _do_install_target(target) -- trace print("installing to %s ..", installdir) - -- the scripts - local scripts = - { - binary = _install_binary - , static = _install_library - , shared = _install_library - } - -- call script - local script = scripts[target:targetkind()] - if script then - script(target) + if not target:isphony() then + local install_style = target:is_plat("windows", "mingw") and "windows" or "unix" + local script = import("install." .. install_style, {anonymous = true})["install_" .. target:targetkind()] + if script then + script(target) + end end -- install other files @@ -148,11 +67,6 @@ end -- on install target function _on_install_target(target) - -- has been disabled? - if target:get("enabled") == false then - return - end - -- trace print("installing %s ..", target:name()) @@ -174,6 +88,11 @@ end -- install the given target function _install_target(target) + -- has been disabled? + if target:get("enabled") == false then + return + end + -- enter project directory local oldir = os.cd(project.directory()) @@ -189,13 +108,6 @@ function _install_target(target) { target:script("install_before") , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- install rules for _, r in ipairs(target:orderules()) do local before_install = r:script("install_before") if before_install then @@ -205,13 +117,6 @@ function _install_target(target) end , target:script("install", _on_install_target) , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- install rules for _, r in ipairs(target:orderules()) do local after_install = r:script("install_after") if after_install then diff --git a/xmake/actions/install/install/unix.lua b/xmake/actions/install/install/unix.lua new file mode 100644 index 000000000..93651b979 --- /dev/null +++ b/xmake/actions/install/install/unix.lua @@ -0,0 +1,60 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file unix.lua +-- + +-- install library +function _install_library(target) + + -- install libraries + local librarydir = path.join(target:installdir(), "lib") + os.mkdir(librarydir) + os.vcp(target:targetfile(), librarydir) + + -- install headers + local includedir = path.join(target:installdir(), "include") + os.mkdir(includedir) + local srcheaders, dstheaders = target:headerfiles(includedir) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end +end + +-- install binary +function install_binary(target) + local binarydir = path.join(target:installdir(), "bin") + os.mkdir(binarydir) + os.vcp(target:targetfile(), binarydir) +end + +-- install shared library +function install_shared(target) + _install_library(target) +end + +-- install static library +function install_shared(target) + _install_library(target) +end diff --git a/xmake/actions/install/install/windows.lua b/xmake/actions/install/install/windows.lua new file mode 100644 index 000000000..ab215bb1b --- /dev/null +++ b/xmake/actions/install/install/windows.lua @@ -0,0 +1,90 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file windows.lua +-- + +-- install headers +function _install_headers(target) + local includedir = path.join(target:installdir(), "include") + os.mkdir(includedir) + local srcheaders, dstheaders = target:headerfiles(includedir) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end +end + +-- install binary +function install_binary(target) + + -- install binary + local binarydir = path.join(target:installdir(), "bin") + os.mkdir(binarydir) + os.vcp(target:targetfile(), binarydir) + + -- install the dependent shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/961 + for _, dep in ipairs(target:orderdeps()) do + if dep:targetkind() == "shared" and target:is_plat("windows", "mingw") then + local depfile = dep:targetfile() + if os.isfile(depfile) then + os.vcp(depfile, binarydir) + end + end + end +end + +-- install shared library +function install_shared(target) + + -- install dll library to the binary directory + local binarydir = path.join(target:installdir(), "bin") + os.mkdir(binarydir) + os.vcp(target:targetfile(), binarydir) + + -- install *.lib for shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/714 + local targetfile = target:targetfile() + local librarydir = path.join(target:installdir(), "lib") + local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") + if os.isfile(targetfile_lib) then + os.mkdir(librarydir) + os.vcp(targetfile_lib, librarydir) + end + + -- install headers + _install_headers(target) +end + +-- install static library +function install_static(target) + + -- install library + local librarydir = path.join(target:installdir(), "lib") + os.mkdir(librarydir) + os.vcp(target:targetfile(), librarydir) + + -- install headers + _install_headers(target) +end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 8bb538ddb..cc5c86496 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -454,6 +454,26 @@ function _instance:arch() return self:get("arch") or config.get("arch") or os.arch() end +-- the current target is belong to the given platforms? +function _instance:is_plat(...) + local plat = self:plat() + for _, v in ipairs(table.join(...)) do + if v and plat == v then + return true + end + end +end + +-- the current target is belong to the given architectures? +function _instance:is_arch(...) + local arch = self:arch() + for _, v in ipairs(table.join(...)) do + if v and arch:find("^" .. v:gsub("%-", "%%-") .. "$") then + return true + end + end +end + -- get the platform instance function _instance:platform() local platform_inst = self._PLATFORM |
