summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-07-14 10:30:00 +0800
committerruki <[email protected]>2015-07-14 10:30:00 +0800
commitb08c998ba48775ed029fea31fed7963944b03dae (patch)
treeefdcf8ebea307f01b7cfe10f67c4771e6a2e0e35
parent441be85afd1b39ded4584d502c434c17d27ad93e (diff)
add uninstall for macosx and linux
-rw-r--r--xmake/scripts/action/_install.lua2
-rw-r--r--xmake/scripts/action/_uninstall.lua160
-rw-r--r--xmake/scripts/base/install.lua18
-rw-r--r--xmake/scripts/base/uninstall.lua104
-rw-r--r--xmake/scripts/platform/linux/install.lua14
-rw-r--r--xmake/scripts/platform/linux/uninstall.lua134
-rw-r--r--xmake/scripts/platform/macosx/install.lua14
-rw-r--r--xmake/scripts/platform/macosx/uninstall.lua134
8 files changed, 577 insertions, 3 deletions
diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua
index b7e392bb3..300f02f8d 100644
--- a/xmake/scripts/action/_install.lua
+++ b/xmake/scripts/action/_install.lua
@@ -119,7 +119,7 @@ function _install.done()
target.outputdir = options.installdir
end
- -- done package
+ -- done install
if not install.done(configs) then
-- errors
utils.error("install: failed!")
diff --git a/xmake/scripts/action/_uninstall.lua b/xmake/scripts/action/_uninstall.lua
new file mode 100644
index 000000000..8f82907d6
--- /dev/null
+++ b/xmake/scripts/action/_uninstall.lua
@@ -0,0 +1,160 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _uninstall.lua
+--
+
+-- define module: _uninstall
+local _uninstall = _uninstall or {}
+
+-- load modules
+local utils = require("base/utils")
+local config = require("base/config")
+local global = require("base/global")
+local install = require("base/install")
+local uninstall = require("base/uninstall")
+local package = require("base/package")
+local project = require("base/project")
+local platform = require("platform/platform")
+
+-- need access to the given file?
+function _uninstall.need(name)
+
+ -- no accessors
+ return false
+end
+
+-- package target
+function _uninstall._package(target_name)
+
+ -- get the target name
+ if not target_name or target_name == "all" then
+ target_name = ""
+ end
+
+ -- package it
+ if os.execute(string.format("xmake p -P %s -f %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, target_name)) ~= 0 then
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+
+-- done
+function _uninstall.done()
+
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
+ -- trace
+ print("uninstall: ...")
+
+ -- load the global configure first
+ global.load()
+
+ -- enter the project directory
+ if not os.cd(xmake._PROJECT_DIR) then
+ -- errors
+ utils.error("not found project: %s!", xmake._PROJECT_DIR)
+ return false
+ end
+
+ -- load the install configure
+ local configs, errors = install.load()
+ if not configs then
+ -- errors
+ utils.error(errors)
+ return false
+ end
+
+ -- reload configure
+ local errors = config.reload()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+
+ -- make the platform configure
+ if not platform.make() then
+ utils.error("make platform configure: %s failed!", config.get("plat"))
+ return false
+ end
+
+ -- reload project
+ local errors = project.reload()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+
+ -- done uninstall
+ if not uninstall.done(configs) then
+ -- errors
+ utils.error("uninstall: failed!")
+ return false
+ end
+
+ -- trace
+ print("uninstall: ok!")
+
+ -- ok
+ return true
+end
+
+-- the menu
+function _uninstall.menu()
+
+ return {
+ -- xmake u
+ shortname = 'u'
+
+ -- usage
+ , usage = "xmake uninstall|u [options] [target]"
+
+ -- description
+ , description = "Uninstall the project binary files."
+
+ -- options
+ , options =
+ {
+ {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." }
+ , {'P', "project", "kv", nil, "Change to the given project directory."
+ , "Search priority:"
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
+
+ , {}
+ , {'v', "verbose", "k", nil, "Print lots of verbose information." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
+
+ , {}
+ , {nil, "target", "v", "all", "Install the given target." }
+ }
+ }
+end
+
+-- return module: _uninstall
+return _uninstall
diff --git a/xmake/scripts/base/install.lua b/xmake/scripts/base/install.lua
index 4f4eef18f..9fc41a14a 100644
--- a/xmake/scripts/base/install.lua
+++ b/xmake/scripts/base/install.lua
@@ -103,6 +103,13 @@ function install._done(target)
return true
end
+-- get the configure file
+function install._file()
+
+ -- get it
+ return config.directory() .. "/install.conf"
+end
+
-- done install from the configure
function install.done(configs)
@@ -121,8 +128,15 @@ function install.done(configs)
end
- -- ok
- return true
+ -- save to the configure file
+ return io.save(install._file(), configs)
+end
+
+-- load the install configure
+function install.load()
+
+ -- load it
+ return io.load(install._file())
end
-- return module: install
diff --git a/xmake/scripts/base/uninstall.lua b/xmake/scripts/base/uninstall.lua
new file mode 100644
index 000000000..304b73c92
--- /dev/null
+++ b/xmake/scripts/base/uninstall.lua
@@ -0,0 +1,104 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file uninstall.lua
+--
+
+-- define module: uninstall
+local uninstall = uninstall or {}
+
+-- load modules
+local os = require("base/os")
+local io = require("base/io")
+local rule = require("base/rule")
+local path = require("base/path")
+local utils = require("base/utils")
+local config = require("base/config")
+local platform = require("platform/platform")
+
+-- uninstall target from the platform script
+function uninstall._done_from_platform(target)
+
+ -- check
+ assert(target)
+
+ -- the platform uninstall script file
+ local uninstallscript = nil
+ local scriptfile = platform.directory() .. "/uninstall.lua"
+ if os.isfile(scriptfile) then
+
+ -- load the uninstall script
+ local script, errors = loadfile(scriptfile)
+ if script then
+ uninstallscript = script()
+ if type(uninstallscript) == "table" and uninstallscript.main then
+ uninstallscript = uninstallscript.main
+ end
+ else
+ utils.error(errors)
+ end
+ end
+
+ -- uninstall it
+ if type(uninstallscript) == "function" then
+ return uninstallscript(target)
+ end
+
+ -- continue
+ return 0
+end
+
+-- uninstall target from the given target configure
+function uninstall._done(target)
+
+ -- check
+ assert(target)
+
+ -- uninstall it from the platform script
+ local ok = uninstall._done_from_platform(target)
+ if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end
+
+ -- ok
+ return true
+end
+
+-- done uninstall from the configure
+function uninstall.done(configs)
+
+ -- check
+ assert(configs)
+
+ -- uninstall targets
+ for _, target in pairs(configs) do
+
+ -- uninstall it
+ if not uninstall._done(target) then
+ -- errors
+ utils.error("uninstall %s failed!", target.name)
+ return false
+ end
+
+ end
+
+ -- ok
+ return true
+end
+
+-- return module: uninstall
+return uninstall
diff --git a/xmake/scripts/platform/linux/install.lua b/xmake/scripts/platform/linux/install.lua
index f5aee6ffe..870cf5040 100644
--- a/xmake/scripts/platform/linux/install.lua
+++ b/xmake/scripts/platform/linux/install.lua
@@ -80,6 +80,9 @@ function install._done_library(target)
utils.error(errors)
return -1
end
+
+ -- update the config.h
+ info.config_h = string.format("%s/%s/%s", includedir, target.name, path.filename(info.config_h))
end
-- copy headers
@@ -99,8 +102,15 @@ function install._done_library(target)
i = i + 1
end
end
+
+ -- update the headers
+ target.headers = dstheaders
end
+ -- update the target directory and file
+ info.targetdir = librarydir
+ info.targetfile = path.filename(info.targetfile)
+
-- ok
return 1
end
@@ -138,6 +148,10 @@ function install._done_binary(target)
return -1
end
+ -- update the target directory and file
+ info.targetdir = binarydir
+ info.targetfile = path.filename(info.targetfile)
+
-- ok
return 1
end
diff --git a/xmake/scripts/platform/linux/uninstall.lua b/xmake/scripts/platform/linux/uninstall.lua
new file mode 100644
index 000000000..468692620
--- /dev/null
+++ b/xmake/scripts/platform/linux/uninstall.lua
@@ -0,0 +1,134 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file uninstall.lua
+--
+
+-- define module: uninstall
+local uninstall = uninstall or {}
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local rule = require("base/rule")
+local utils = require("base/utils")
+local string = require("base/string")
+local platform = require("platform/platform")
+
+-- uninstall target for the library file
+function uninstall._done_library(target)
+
+ -- check
+ assert(target and target.name and target.archs)
+
+ -- get target info
+ local info = target.archs[xmake._ARCH] or target.archs["x86_64"] or target.archs["i386"]
+ if not info then return -1 end
+
+ -- check
+ assert(info.targetdir and info.targetfile)
+
+ -- remove the target file
+ local targetfile = info.targetdir .. "/" .. info.targetfile
+ if os.isfile(targetfile) then
+ local ok, errors = os.rm(targetfile)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+
+ -- remove config.h
+ if info.config_h and os.isfile(info.config_h) then
+ local ok, errors = os.rm(info.config_h)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+
+ -- remove headers
+ if target.headers then
+ for _, header in ipairs(target.headers) do
+ if os.isfile(header) then
+ local ok, errors = os.rm(header)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+ end
+ end
+
+ -- ok
+ return 1
+end
+
+-- uninstall target for the binary file
+function uninstall._done_binary(target)
+
+ -- check
+ assert(target and target.archs)
+
+ -- get target info
+ local info = target.archs[xmake._ARCH] or target.archs["x86_64"] or target.archs["i386"]
+ if not info then return -1 end
+
+ -- check
+ assert(info.targetdir and info.targetfile)
+
+ -- the target file
+ local targetfile = info.targetdir .. "/" .. info.targetfile
+ if not os.isfile(targetfile) then return 1 end
+
+ -- remove the target file
+ local ok, errors = os.rm(targetfile)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+
+ -- ok
+ return 1
+end
+
+-- uninstall target
+function uninstall.main(target)
+
+ -- check
+ assert(target and target.kind)
+
+ -- the uninstall scripts
+ local uninstallscripts =
+ {
+ static = uninstall._done_library
+ , shared = uninstall._done_library
+ , binary = uninstall._done_binary
+ }
+
+ -- uninstall it
+ local uninstallscript = uninstallscripts[target.kind]
+ if uninstallscript then return uninstallscript(target) end
+
+ -- continue
+ return 0
+end
+
+-- return module: uninstall
+return uninstall
diff --git a/xmake/scripts/platform/macosx/install.lua b/xmake/scripts/platform/macosx/install.lua
index f5aee6ffe..870cf5040 100644
--- a/xmake/scripts/platform/macosx/install.lua
+++ b/xmake/scripts/platform/macosx/install.lua
@@ -80,6 +80,9 @@ function install._done_library(target)
utils.error(errors)
return -1
end
+
+ -- update the config.h
+ info.config_h = string.format("%s/%s/%s", includedir, target.name, path.filename(info.config_h))
end
-- copy headers
@@ -99,8 +102,15 @@ function install._done_library(target)
i = i + 1
end
end
+
+ -- update the headers
+ target.headers = dstheaders
end
+ -- update the target directory and file
+ info.targetdir = librarydir
+ info.targetfile = path.filename(info.targetfile)
+
-- ok
return 1
end
@@ -138,6 +148,10 @@ function install._done_binary(target)
return -1
end
+ -- update the target directory and file
+ info.targetdir = binarydir
+ info.targetfile = path.filename(info.targetfile)
+
-- ok
return 1
end
diff --git a/xmake/scripts/platform/macosx/uninstall.lua b/xmake/scripts/platform/macosx/uninstall.lua
new file mode 100644
index 000000000..468692620
--- /dev/null
+++ b/xmake/scripts/platform/macosx/uninstall.lua
@@ -0,0 +1,134 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file uninstall.lua
+--
+
+-- define module: uninstall
+local uninstall = uninstall or {}
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local rule = require("base/rule")
+local utils = require("base/utils")
+local string = require("base/string")
+local platform = require("platform/platform")
+
+-- uninstall target for the library file
+function uninstall._done_library(target)
+
+ -- check
+ assert(target and target.name and target.archs)
+
+ -- get target info
+ local info = target.archs[xmake._ARCH] or target.archs["x86_64"] or target.archs["i386"]
+ if not info then return -1 end
+
+ -- check
+ assert(info.targetdir and info.targetfile)
+
+ -- remove the target file
+ local targetfile = info.targetdir .. "/" .. info.targetfile
+ if os.isfile(targetfile) then
+ local ok, errors = os.rm(targetfile)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+
+ -- remove config.h
+ if info.config_h and os.isfile(info.config_h) then
+ local ok, errors = os.rm(info.config_h)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+
+ -- remove headers
+ if target.headers then
+ for _, header in ipairs(target.headers) do
+ if os.isfile(header) then
+ local ok, errors = os.rm(header)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+ end
+ end
+ end
+
+ -- ok
+ return 1
+end
+
+-- uninstall target for the binary file
+function uninstall._done_binary(target)
+
+ -- check
+ assert(target and target.archs)
+
+ -- get target info
+ local info = target.archs[xmake._ARCH] or target.archs["x86_64"] or target.archs["i386"]
+ if not info then return -1 end
+
+ -- check
+ assert(info.targetdir and info.targetfile)
+
+ -- the target file
+ local targetfile = info.targetdir .. "/" .. info.targetfile
+ if not os.isfile(targetfile) then return 1 end
+
+ -- remove the target file
+ local ok, errors = os.rm(targetfile)
+ if not ok then
+ utils.error(errors)
+ return -1
+ end
+
+ -- ok
+ return 1
+end
+
+-- uninstall target
+function uninstall.main(target)
+
+ -- check
+ assert(target and target.kind)
+
+ -- the uninstall scripts
+ local uninstallscripts =
+ {
+ static = uninstall._done_library
+ , shared = uninstall._done_library
+ , binary = uninstall._done_binary
+ }
+
+ -- uninstall it
+ local uninstallscript = uninstallscripts[target.kind]
+ if uninstallscript then return uninstallscript(target) end
+
+ -- continue
+ return 0
+end
+
+-- return module: uninstall
+return uninstall