summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-06-30 15:00:56 +0800
committerruki <[email protected]>2016-06-30 15:00:56 +0800
commit0910e8ce0ad2bffc1e5c9b2c28ee7c845a339521 (patch)
tree74a403f404a55f94b172d6d36945a47210bd941c
parent8732e635f54ecc9bb5722112a2245d55ef4bd2ce (diff)
add installer for linux
-rw-r--r--xmake/platforms/installer.lua122
-rw-r--r--xmake/platforms/linux/installer.lua74
-rwxr-xr-xxmake/platforms/linux/xmake.lua3
-rw-r--r--xmake/platforms/macosx/installer.lua113
4 files changed, 206 insertions, 106 deletions
diff --git a/xmake/platforms/installer.lua b/xmake/platforms/installer.lua
new file mode 100644
index 000000000..1f5b1296a
--- /dev/null
+++ b/xmake/platforms/installer.lua
@@ -0,0 +1,122 @@
+--!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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file installer.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- install binary
+function install_binary_on_unix(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or "/usr/local"
+
+ -- the binary directory
+ local binarydir = path.join(outputdir, "bin")
+
+ -- make the binary directory
+ os.mkdir(binarydir)
+
+ -- copy the target file
+ os.cp(target:targetfile(), binarydir)
+end
+
+-- install library
+function install_library_on_unix(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or "/usr/local"
+
+ -- the library directory
+ local librarydir = path.join(outputdir, "lib")
+
+ -- the include directory
+ local includedir = path.join(outputdir, "include")
+
+ -- make the library directory
+ os.mkdir(librarydir)
+
+ -- make the include directory
+ os.mkdir(includedir)
+
+ -- copy the target file
+ os.cp(target:targetfile(), librarydir)
+
+ -- copy the config.h to the include directory
+ local configheader, configoutput = target:configheader(includedir)
+ if configheader and configoutput then
+ os.cp(configheader, configoutput)
+ 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.cp(srcheader, dstheader)
+ end
+ i = i + 1
+ end
+ end
+end
+
+-- uninstall binary
+function uninstall_binary_on_unix(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or "/usr/local"
+
+ -- the binary directory
+ local binarydir = path.join(outputdir, "bin")
+
+ -- remove the target file
+ os.rm(path.join(binarydir, path.filename(target:targetfile())))
+end
+
+-- uninstall library
+function uninstall_library_on_unix(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or "/usr/local"
+
+ -- the library directory
+ local librarydir = path.join(outputdir, "lib")
+
+ -- the include directory
+ local includedir = path.join(outputdir, "include")
+
+ -- remove the target file
+ os.rm(path.join(librarydir, path.filename(target:targetfile())))
+
+ -- reove the config.h from the include directory
+ local _, configoutput = target:configheader(includedir)
+ if configoutput then
+ os.rm(configoutput)
+ end
+
+ -- remove headers from the include directory
+ local _, dstheaders = target:headerfiles(includedir)
+ for _, dstheader in ipairs(dstheaders) do
+ os.rm(dstheader)
+ end
+end
diff --git a/xmake/platforms/linux/installer.lua b/xmake/platforms/linux/installer.lua
new file mode 100644
index 000000000..ba0064888
--- /dev/null
+++ b/xmake/platforms/linux/installer.lua
@@ -0,0 +1,74 @@
+--!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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file install.lua
+--
+
+-- imports
+import("core.project.config")
+import("platforms.installer", {rootdir = os.programdir()})
+
+-- install target
+function install(target)
+
+ -- check architecture
+ local arch = config.get("arch")
+ if arch ~= "i386" and arch ~= "x86_64" then
+ raise("cannot install target(%s) for arch(%s)!", target:name(), arch)
+ end
+
+ -- the scripts
+ local scripts =
+ {
+ binary = installer.install_binary_on_unix
+ , static = installer.install_library_on_unix
+ , shared = installer.install_library_on_unix
+ }
+
+ -- call script
+ local script = scripts[target:get("kind")]
+ if script then
+ script(target)
+ end
+end
+
+-- uninstall target
+function uninstall(target)
+
+ -- check architecture
+ local arch = config.get("arch")
+ if arch ~= "i386" and arch ~= "x86_64" then
+ raise("cannot uninstall target(%s) for arch(%s)!", target:name(), arch)
+ end
+
+ -- the scripts
+ local scripts =
+ {
+ binary = installer.uninstall_binary_on_unix
+ , static = installer.uninstall_library_on_unix
+ , shared = installer.uninstall_library_on_unix
+ }
+
+ -- call script
+ local script = scripts[target:get("kind")]
+ if script then
+ script(target)
+ end
+end
+
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index e6af941bd..f2c4552ca 100755
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -35,6 +35,9 @@ platform("linux")
-- set checker
set_checker("checker")
+ -- set installer
+ set_installer("installer")
+
-- set tooldirs
set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin")
diff --git a/xmake/platforms/macosx/installer.lua b/xmake/platforms/macosx/installer.lua
index 9544749d1..b47863db6 100644
--- a/xmake/platforms/macosx/installer.lua
+++ b/xmake/platforms/macosx/installer.lua
@@ -21,106 +21,7 @@
--
-- imports
-import("core.base.option")
---import("platforms.checker", {rootdir = os.programdir()})
-
--- install binary
-function _install_binary(target)
-
- -- the output directory
- local outputdir = option.get("outputdir") or "/usr/local"
-
- -- the binary directory
- local binarydir = path.join(outputdir, "bin")
-
- -- make the binary directory
- os.mkdir(binarydir)
-
- -- copy the target file
- os.cp(target:targetfile(), binarydir)
-end
-
--- install library
-function _install_library(target)
-
- -- the output directory
- local outputdir = option.get("outputdir") or "/usr/local"
-
- -- the library directory
- local librarydir = path.join(outputdir, "lib")
-
- -- the include directory
- local includedir = path.join(outputdir, "include")
-
- -- make the library directory
- os.mkdir(librarydir)
-
- -- make the include directory
- os.mkdir(includedir)
-
- -- copy the target file
- os.cp(target:targetfile(), librarydir)
-
- -- copy the config.h to the include directory
- local configheader, configoutput = target:configheader(includedir)
- if configheader and configoutput then
- os.cp(configheader, configoutput)
- 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.cp(srcheader, dstheader)
- end
- i = i + 1
- end
- end
-end
-
--- uninstall binary
-function _uninstall_binary(target)
-
- -- the output directory
- local outputdir = option.get("outputdir") or "/usr/local"
-
- -- the binary directory
- local binarydir = path.join(outputdir, "bin")
-
- -- remove the target file
- os.rm(path.join(binarydir, path.filename(target:targetfile())))
-end
-
--- uninstall library
-function _uninstall_library(target)
-
- -- the output directory
- local outputdir = option.get("outputdir") or "/usr/local"
-
- -- the library directory
- local librarydir = path.join(outputdir, "lib")
-
- -- the include directory
- local includedir = path.join(outputdir, "include")
-
- -- remove the target file
- os.rm(path.join(librarydir, path.filename(target:targetfile())))
-
- -- reove the config.h from the include directory
- local _, configoutput = target:configheader(includedir)
- if configoutput then
- os.rm(configoutput)
- end
-
- -- remove headers from the include directory
- local _, dstheaders = target:headerfiles(includedir)
- for _, dstheader in ipairs(dstheaders) do
- os.rm(dstheader)
- end
-end
+import("platforms.installer", {rootdir = os.programdir()})
-- install target
function install(target)
@@ -128,9 +29,9 @@ function install(target)
-- the scripts
local scripts =
{
- binary = _install_binary
- , static = _install_library
- , shared = _install_library
+ binary = installer.install_binary_on_unix
+ , static = installer.install_library_on_unix
+ , shared = installer.install_library_on_unix
}
-- call script
@@ -146,9 +47,9 @@ function uninstall(target)
-- the scripts
local scripts =
{
- binary = _uninstall_binary
- , static = _uninstall_library
- , shared = _uninstall_library
+ binary = installer.uninstall_binary_on_unix
+ , static = installer.uninstall_library_on_unix
+ , shared = installer.uninstall_library_on_unix
}
-- call script