From e1c814493e1b884b4e35a0ff337ed5742ea96caf Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 25 Jan 2016 21:19:13 +0800 Subject: rename action filename --- xmake/core/action/_build.lua | 120 ------------- xmake/core/action/_clean.lua | 106 ------------ xmake/core/action/_config.lua | 215 ----------------------- xmake/core/action/_create.lua | 123 ------------- xmake/core/action/_debug.lua | 89 ---------- xmake/core/action/_global.lua | 104 ----------- xmake/core/action/_install.lua | 224 ------------------------ xmake/core/action/_lua.lua | 168 ------------------ xmake/core/action/_man.lua | 89 ---------- xmake/core/action/_package.lua | 365 --------------------------------------- xmake/core/action/_run.lua | 179 ------------------- xmake/core/action/_uninstall.lua | 160 ----------------- xmake/core/action/action.lua | 190 -------------------- xmake/core/action/build.lua | 120 +++++++++++++ xmake/core/action/clean.lua | 106 ++++++++++++ xmake/core/action/config.lua | 215 +++++++++++++++++++++++ xmake/core/action/create.lua | 123 +++++++++++++ xmake/core/action/debug.lua | 89 ++++++++++ xmake/core/action/global.lua | 104 +++++++++++ xmake/core/action/install.lua | 224 ++++++++++++++++++++++++ xmake/core/action/lua.lua | 168 ++++++++++++++++++ xmake/core/action/man.lua | 89 ++++++++++ xmake/core/action/package.lua | 365 +++++++++++++++++++++++++++++++++++++++ xmake/core/action/run.lua | 179 +++++++++++++++++++ xmake/core/action/uninstall.lua | 160 +++++++++++++++++ xmake/core/base/action.lua | 190 ++++++++++++++++++++ xmake/core/base/main.lua | 2 +- 27 files changed, 2133 insertions(+), 2133 deletions(-) delete mode 100644 xmake/core/action/_build.lua delete mode 100644 xmake/core/action/_clean.lua delete mode 100644 xmake/core/action/_config.lua delete mode 100644 xmake/core/action/_create.lua delete mode 100644 xmake/core/action/_debug.lua delete mode 100644 xmake/core/action/_global.lua delete mode 100644 xmake/core/action/_install.lua delete mode 100644 xmake/core/action/_lua.lua delete mode 100644 xmake/core/action/_man.lua delete mode 100644 xmake/core/action/_package.lua delete mode 100644 xmake/core/action/_run.lua delete mode 100644 xmake/core/action/_uninstall.lua delete mode 100644 xmake/core/action/action.lua create mode 100644 xmake/core/action/build.lua create mode 100644 xmake/core/action/clean.lua create mode 100644 xmake/core/action/config.lua create mode 100644 xmake/core/action/create.lua create mode 100644 xmake/core/action/debug.lua create mode 100644 xmake/core/action/global.lua create mode 100644 xmake/core/action/install.lua create mode 100644 xmake/core/action/lua.lua create mode 100644 xmake/core/action/man.lua create mode 100644 xmake/core/action/package.lua create mode 100644 xmake/core/action/run.lua create mode 100644 xmake/core/action/uninstall.lua create mode 100644 xmake/core/base/action.lua diff --git a/xmake/core/action/_build.lua b/xmake/core/action/_build.lua deleted file mode 100644 index bf660eab5..000000000 --- a/xmake/core/action/_build.lua +++ /dev/null @@ -1,120 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _build.lua --- - --- define module: _build -local _build = _build or {} - --- load modules -local rule = require("base/rule") -local utils = require("base/utils") -local clean = require("base/clean") -local config = require("base/config") -local project = require("base/project") -local makefile = require("base/makefile") - --- need access to the given file? -function _build.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { config = true, global = true, project = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _build.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- the target name - local target_name = options.target - - -- check target - if not project.checktarget(target_name) then - return false - end - - -- rebuild it? - if options.rebuild or config.get("__rebuild") then - clean.remove(target_name, "build") - -- update it? - elseif options.update then - clean.remove(target_name, "targets") - end - - -- clear rebuild mark and save configure to file - if config.get("__rebuild") then - - -- clear it - config.set("__rebuild", nil) - - -- save the configure - if not config.save() then - -- error - utils.error("update configure failed!") - end - end - - -- check makefile - if not os.isfile(rule.makefile()) then - - -- make the configure file for the given target - if not project.makeconf(options.target) then - -- error - utils.error("make configure failed!") - return false - end - - -- make makefile - if not makefile.make() then - -- error - utils.error("make makefile failed!") - return false - end - end - - -- build target for makefile - if not makefile.build(target_name) then - -- error - print("") - if options.verbose then - io.cat(rule.logfile()) - else - io.tail(rule.logfile(), 32) - end - utils.error("build target: %s failed!\n", target_name) - return false - end - - -- ok - print("build ok!") - return true -end - --- return module: _build -return _build diff --git a/xmake/core/action/_clean.lua b/xmake/core/action/_clean.lua deleted file mode 100644 index 71ed1280b..000000000 --- a/xmake/core/action/_clean.lua +++ /dev/null @@ -1,106 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _clean.lua --- - --- define module: _clean -local _clean = _clean or {} - --- load modules -local clean = require("base/clean") -local config = require("base/config") -local project = require("base/project") -local utils = require("base/utils") -local platform = require("base/platform") - --- need access to the given file? -function _clean.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { global = true, config = true, project = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _clean.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- check target - if not project.checktarget(options.target) then - return false - end - - -- clean the current target - if not clean.remove(options.target, utils.ifelse(options.all, "all", "build")) then - return false - end - - -- trace - print("clean ok!") - - -- ok - return true -end - --- the menu -function _clean.menu() - - return { - -- xmake c - shortname = 'c' - - -- usage - , usage = "xmake clean|c [options] [target]" - - -- description - , description = "Remove all binary and temporary 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" } - , {} - , {'a', "all", "k", nil, "Clean all auto-generated files by xmake." } - , {} - , {'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", "Clean for the given target." } - } - } -end - --- return module: _clean -return _clean diff --git a/xmake/core/action/_config.lua b/xmake/core/action/_config.lua deleted file mode 100644 index 9cf0af08e..000000000 --- a/xmake/core/action/_config.lua +++ /dev/null @@ -1,215 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _config.lua --- - --- define module: _config -local _config = _config or {} - --- load modules -local utils = require("base/utils") -local config = require("base/config") -local project = require("base/project") -local makefile = require("base/makefile") -local platform = require("base/platform") - --- need access to the given file? -function _config.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { config = true, global = true, project = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _config.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- check target - if not project.checktarget(options.target) then - return false - end - - -- trace - print("configure ...") - - -- save the configure - if not config.save() then - -- error - utils.error("save configure failed!") - return false - end - - -- make the configure file for the given target - if not project.makeconf(options.target) then - -- error - utils.error("make configure failed!") - return false - end - - -- make makefile - if not makefile.make() then - -- error - utils.error("make makefile failed!") - return false - end - - -- dump configure - config.dump() - - -- trace - print("configure ok!") - - -- ok - return true -end - --- the menu -function _config.menu() - - return { - -- xmake f - shortname = 'f' - - -- usage - , usage = "xmake config|f [options] [target]" - - -- description - , description = "Configure the project." - - -- options - , options = - { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } - - , {} - , {'p', "plat", "kv", xmake._HOST, "Compile for the given platform." - , function () - local descriptions = {} - local plats = platform.plats() - if plats then - for i, plat in ipairs(plats) do - descriptions[i] = " - " .. plat - end - end - return descriptions - end } - , {'a', "arch", "kv", "auto", "Compile for the given architecture." - , function () - local descriptions = {} - local plats = platform.plats() - if plats then - for i, plat in ipairs(plats) do - descriptions[i] = " - " .. plat .. ":" - local archs = platform.archs(plat) - if archs then - for _, arch in ipairs(archs) do - descriptions[i] = descriptions[i] .. " " .. arch - end - end - end - end - return descriptions - end } - , {'m', "mode", "kv", "release", "Compile for the given mode." - , " - debug" - , " - release" - , " - profile" } - , {'k', "kind", "kv", "static", "Compile for the given target kind." - , " - static" - , " - shared" - , " - binary" } - , {nil, "host", "kv", xmake._HOST, "The current host environment." } - - -- the options for project - , function () return project.menu() end - - , {} - , {nil, "make", "kv", "auto", "Set the make path." } - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } - - , {} - , {nil, "cross", "kv", nil, "The cross toolchains prefix" - , ".e.g" - , " - i386-mingw32-" - , " - arm-linux-androideabi-" } - , {nil, "toolchains", "kv", nil, "The cross toolchains directory" } - - , {} - , {nil, "cc", "kv", nil, "The C Compiler" } - , {nil, "cxx", "kv", nil, "The C++ Compiler" } - , {nil, "cflags", "kv", nil, "The C Compiler Flags" } - , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } - , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } - - , {} - , {nil, "as", "kv", nil, "The Assembler" } - , {nil, "asflags", "kv", nil, "The Assembler Flags" } - - , {} - , {nil, "sc", "kv", nil, "The Swift Compiler" } - , {nil, "scflags", "kv", nil, "The Swift Compiler Flags" } - - , {} - , {nil, "ld", "kv", nil, "The Linker" } - , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } - - , {} - , {nil, "ar", "kv", nil, "The Static Library Linker" } - , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } - - , {} - , {nil, "sh", "kv", nil, "The Shared Library Linker" } - , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } - - -- the options for all platforms - , function () return platform.menu("config") end - - , {} - , {'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" } - , {'o', "buildir", "kv", "build", "Set the build 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", "Configure for the given target." } - } - } -end - --- return module: _config -return _config diff --git a/xmake/core/action/_create.lua b/xmake/core/action/_create.lua deleted file mode 100644 index 39c3ba83a..000000000 --- a/xmake/core/action/_create.lua +++ /dev/null @@ -1,123 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _create.lua --- - --- define module: _create -local _create = _create or {} - --- load modules -local path = require("base/path") -local utils = require("base/utils") -local template = require("base/template") - --- need access to the given file? -function _create.need(name) - - -- no accessors - return false -end - --- done -function _create.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- the target name - local targetname = options.target or options.name or path.basename(xmake._PROJECT_DIR) or "demo" - - -- trace - utils.printf("create %s ...", targetname) - - -- create project from template - local ok, errors = template.create(options.language, options.template, targetname) - if not ok then - utils.error(errors) - return false - end - - -- trace - utils.printf("create %s ok!", targetname) - - -- ok - return true -end - --- the menu -function _create.menu() - - return { - -- usage - usage = "xmake create [options] [target]" - - -- description - , description = "Create a new project." - - -- options - , options = - { - {'n', "name", "kv", nil, "The project name." } - , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } - , {'P', "project", "kv", nil, "Create from the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - , {'l', "language", "kv", "c", "The project language" - , function () - local descriptions = {} - local languages = template.languages() - for _, language in ipairs(languages) do - table.insert(descriptions, " - " .. language) - end - return descriptions - end } - , {'t', "template", "kv", "1", "Select the project template id of the given language." - , function () - local descriptions = {} - local languages = template.languages() - for _, language in ipairs(languages) do - table.insert(descriptions, string.format(" - language: %s", language)) - local templates = template.loadall(language) - if templates then - for i, template in ipairs(templates) do - table.insert(descriptions, string.format(" %d. %s", i, utils.ifelse(template.description, template.description, "The Unknown Project"))) - end - end - end - return descriptions - end } - - , {} - , {'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", nil, "Create the given target." - , "Uses the project name as target if not exists." } - } - } -end - --- return module: _create -return _create diff --git a/xmake/core/action/_debug.lua b/xmake/core/action/_debug.lua deleted file mode 100644 index aba8d363e..000000000 --- a/xmake/core/action/_debug.lua +++ /dev/null @@ -1,89 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _debug.lua --- - --- define module: _debug -local _debug = _debug or {} - --- load modules -local utils = require("base/utils") -local config = require("base/config") -local platform = require("base/platform") - --- need access to the given file? -function _debug.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { config = true, global = true, project = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _debug.done() - - -- TODO - print("not implement!") - - -- ok - return true -end - --- the menu -function _debug.menu() - - return { - -- xmake d - shortname = 'd' - - -- usage - , usage = "xmake debug|d [options] [target]" - - -- description - , description = "Debug target." - - -- options - , options = - { - {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } - , {'P', "project", "kv", nil, "Create from 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", nil, "Debug a given target" } - } - } -end - --- return module: _debug -return _debug diff --git a/xmake/core/action/_global.lua b/xmake/core/action/_global.lua deleted file mode 100644 index 2ccf85901..000000000 --- a/xmake/core/action/_global.lua +++ /dev/null @@ -1,104 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _global.lua --- - --- define module: _global -local _global = _global or {} - --- load modules -local utils = require("base/utils") -local global = require("base/global") -local platform = require("base/platform") - --- need access to the given file? -function _global.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { global = true } - - -- need it? - return accessors[name] -end - --- done -function _global.done() - - -- probe the global platform configure - if not platform.probe(true) then - return false - end - - -- clear up the global configure - global.clearup() - - -- save the global configure - if not global.save() then - -- error - utils.error("save configure failed!") - return false - end - - -- dump global - global.dump() - - -- ok - print("configure ok!") - return true -end - --- the menu -function _global.menu() - - return { - -- xmake g - shortname = 'g' - - -- usage - , usage = "xmake global|g [options] [target]" - - -- description - , description = "Configure the global options for xmake." - - -- options - , options = - { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } - , {nil, "make", "kv", "auto", "Set the make path." } - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } - - , {} - -- the options for all platforms - , function () return platform.menu("global") end - - , {} - , {'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." } - } - } -end - --- return module: _global -return _global diff --git a/xmake/core/action/_install.lua b/xmake/core/action/_install.lua deleted file mode 100644 index 788584fdd..000000000 --- a/xmake/core/action/_install.lua +++ /dev/null @@ -1,224 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _install.lua --- - --- define module: _install -local _install = _install or {} - --- load modules -local utils = require("base/utils") -local config = require("base/config") -local global = require("base/global") -local install = require("base/install") -local package = require("base/package") -local project = require("base/project") -local platform = require("base/platform") - --- need access to the given file? -function _install.need(name) - - -- no accessors - return false -end - --- make configure for the given target -function _install._makeconf(configs, target_name, target) - - -- check - assert(configs and target_name and target) - - -- init configs for targets - configs[target_name] = configs[target_name] or {} - local configs_target = configs[target_name] - - -- save the install script - local installscript = target.installscript - if type(installscript) == "string" and os.isfile(installscript) then - local script, errors = loadfile(installscript) - if script then - installscript = script() - if type(installscript) == "table" and installscript.main then - installscript = installscript.main - end - else - utils.error(errors) - return false - end - end - if target.installscript and type(installscript) ~= "function" then - utils.error("invalid install script!") - return false - end - configs_target.installscript = installscript - - -- ok - return true -end - --- package target -function _install._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 _install.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- trace - print("install: ...") - - -- 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 - - -- package the given target first - if not _install._package(options.target) then - -- errors - utils.error("package: failed!") - return false - end - - -- load the package configure - local configs, errors = package.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 - - -- update the outputdir - for _, target in pairs(configs) do - target.outputdir = options.installdir - end - - -- the targets - local targets = project.targets() - assert(targets) - - -- make configure for the given target - if target_name and target_name ~= "all" then - if not _install._makeconf(configs, target_name, targets[target_name]) then - utils.error("make target configure: %s failed!", target_name) - return false - end - else - for target_name, target in pairs(targets) do - if not _install._makeconf(configs, target_name, target) then - utils.error("make target configure: %s failed!", target_name) - return false - end - end - end - - -- done install - if not install.done(configs) then - -- errors - utils.error("install: failed!") - return false - end - - -- trace - print("install: ok!") - - -- ok - return true -end - --- the menu -function _install.menu() - - return { - -- xmake i - shortname = 'i' - - -- usage - , usage = "xmake install|i [options] [target]" - - -- description - , description = "Package and install 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" } - , {'o', "installdir", "kv", nil, "Set the install 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: _install -return _install diff --git a/xmake/core/action/_lua.lua b/xmake/core/action/_lua.lua deleted file mode 100644 index 0ca841b83..000000000 --- a/xmake/core/action/_lua.lua +++ /dev/null @@ -1,168 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _lua.lua --- - --- define module: _lua -local _lua = _lua or {} - --- load modules -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local config = require("base/config") -local string = require("base/string") -local tools = require("tools/tools") -local platform = require("base/platform") - --- need access to the given file? -function _lua.need(name) - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- do not load config if be not given -f or -P options - if options.file == nil and options.project == nil then - return false - end - - -- patch target for loading config ok - options.target = "all" - - -- the accessors - local accessors = { config = true, global = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _lua.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- no script? - if not options.script then - return false - end - - -- the arguments - local arguments = options.arguments or {} - if type(arguments) ~= "table" then - arguments = {} - end - - -- is string script? - if options.string then - - -- trace - utils.verbose("script: %s", options.script) - - -- load and run string - local script = loadstring(options.script) - if script then - return script(arguments) - end - else - -- attempt to load script from the given file if exists - local file = options.script - if not path.is_absolute(file) then - file = path.absolute(file) - end - - -- attempt to load script from the tools directory - if not os.isfile(file) then - file = tools.find(options.script, xmake._CORE_DIR .. "/tools") - end - - -- load and run the script file - if os.isfile(file) then - - -- load script - local script = loadfile(file) - if script then - - -- load module - local module = script() - if module then - - -- init module - if module.init then - module:init(options.script) - end - - -- done module - return module:main(arguments) - end - end - end - end - - -- failed - utils.error("cannot run this script: %s", options.script) - return false -end - --- the menu -function _lua.menu() - - return { - -- xmake l - shortname = 'l' - - -- usage - , usage = "xmake lua|l [options] [script] [arguments]" - - -- description - , description = "Run the lua script." - - -- options - , options = - { - {'f', "file", "kv", nil, "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" } - - , {} - , {'s', "string", "k", nil, "Run the lua string script." } - - , {} - , {'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, "script", "v", nil, "Run the given lua script." - , " - The script name from the xmake tool directory" - , " - The script file" - , " - The script string" } - , {nil, "arguments", "vs", nil, "The script arguments" } - } - } -end - --- return module: _lua -return _lua diff --git a/xmake/core/action/_man.lua b/xmake/core/action/_man.lua deleted file mode 100644 index 14a2b1e5a..000000000 --- a/xmake/core/action/_man.lua +++ /dev/null @@ -1,89 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _man.lua --- - --- define module: _man -local _man = _man or {} - --- load modules -local utils = require("base/utils") -local config = require("base/config") -local platform = require("base/platform") - --- need access to the given file? -function _man.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { config = true, global = true, project = true } - - -- need it? - return accessors[name] -end - --- done -function _man.done() - - -- TODO - print("not implement!") - - -- ok - return true -end - --- the menu -function _man.menu() - - return { - -- xmake m - shortname = 'm' - - -- usage - , usage = "xmake man|m [options] [target]" - - -- description - , description = "Create a project man." - - -- options - , options = - { - {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } - , {'P', "project", "kv", nil, "Create from 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", "Create man for the given target" } - } - } -end - --- return module: _man -return _man diff --git a/xmake/core/action/_package.lua b/xmake/core/action/_package.lua deleted file mode 100644 index d55af5ada..000000000 --- a/xmake/core/action/_package.lua +++ /dev/null @@ -1,365 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _package.lua --- - --- define module: _package -local _package = _package or {} - --- load modules -local rule = require("base/rule") -local path = require("base/path") -local utils = require("base/utils") -local config = require("base/config") -local global = require("base/global") -local string = require("base/string") -local project = require("base/project") -local package = require("base/package") -local platform = require("base/platform") - --- need access to the given file? -function _package.need(name) - - -- no accessors - return false -end - --- configure target for the given architecture -function _package._config(arch, target_name) - - -- need not configure it - if not arch then return true end - - -- done the command - return os.execute(string.format("xmake f -P %s -f %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, arch, target_name)) == 0; -end - --- build target for the given architecture -function _package._build(arch, target_name) - - -- get the target name - if not target_name or target_name == "all" then - target_name = "" - end - - -- configure it first - if not _package._config(arch, target_name) then return false end - - -- build it - if os.execute(string.format("xmake -P %s %s", xmake._PROJECT_DIR, target_name)) ~= 0 then - -- errors - utils.error("build failed!") - return false - end - - -- ok - return true -end - --- backup the target files -function _package._backup(rootdir, filepath) - - -- the relative file path - if filepath and path.is_absolute(filepath) then - filepath = path.relative(filepath, xmake._PROJECT_DIR) - end - - -- not exists? return it directly - if not filepath or not os.isfile(filepath) then return end - - -- the backup file - local backupfile = string.format("%s/%s", rootdir, filepath) - - -- backup it - local ok, errors = os.cp(filepath, backupfile) - if not ok then - -- errors - utils.error(errors) - return - end - - -- ok - return filepath -end - --- make configure for the given target -function _package._makeconf(target_name, target) - - -- check - assert(target_name and target) - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- the configs - local configs = _package._CONFIGS - assert(configs) - - -- the architecture - local arch = config.get("arch") - if not arch then return false end - - -- init configs for targets - configs[target_name] = configs[target_name] or {} - local configs_target = configs[target_name] - - -- init configs for architectures - configs_target.archs = configs_target.archs or {} - - -- init configs for architecture - configs_target.archs[arch] = configs_target.archs[arch] or {} - local configs_arch = configs_target.archs[arch] - - -- save name - configs_target.name = target_name - - -- save kind - configs_target.kind = target.kind - - -- save the output directory - configs_target.outputdir = options.outputdir or config.get("buildir") - - -- save the header files - configs_target.headers = target.headers - - -- save the target directory - configs_arch.targetdir = rule.backupdir(target_name, arch) - - -- save the config file - configs_arch.config_h = _package._backup(configs_arch.targetdir, rule.config_h(target)) - - -- save the target file - configs_arch.targetfile = _package._backup(configs_arch.targetdir, rule.targetfile(target_name, target)) - - -- save the package script - local packagescript = target.packagescript - if type(packagescript) == "string" and os.isfile(packagescript) then - local script, errors = loadfile(packagescript) - if script then - packagescript = script() - if type(packagescript) == "table" and packagescript.main then - packagescript = packagescript.main - end - else - utils.error(errors) - return false - end - end - if target.packagescript and type(packagescript) ~= "function" then - utils.error("invalid package script!") - return false - end - configs_target.packagescript = packagescript - - -- ok - return true -end - --- load configure for the given target -function _package._loadconf(target_name) - - -- 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 - - -- the targets - local targets = project.targets() - assert(targets) - - -- make configure for the given target - if target_name and target_name ~= "all" then - if not _package._makeconf(target_name, targets[target_name]) then - utils.error("make target configure: %s failed!", target_name) - return false - end - else - for target_name, target in pairs(targets) do - if not _package._makeconf(target_name, target) then - utils.error("make target configure: %s failed!", target_name) - return false - end - end - end - - -- ok - return true -end - --- build target for all architectures -function _package._build_all(archs, target_name) - - -- exists the given architectures? - if archs then - - -- split all architectures - archs = archs:split(",") - if not archs then return false end - - -- build for all architectures - for _, arch in ipairs(archs) do - - -- trim it - arch = arch:trim() - - -- build it - if not _package._build(arch, target_name) then return false end - - -- load configure - if not _package._loadconf(target_name) then return false end - - end - - -- build for single architecture - else - - -- build it - if not _package._build(nil, target_name) then return false end - - -- load configure - if not _package._loadconf(target_name) then return false end - - end - - -- ok - return true -end - --- done -function _package.done() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- trace - print("package: ...") - - -- init configs - _package._CONFIGS = _package._CONFIGS or {} - local configs = _package._CONFIGS - - -- 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 - - -- build the given target first for all architectures - if not _package._build_all(options.archs, options.target) then - -- errors - utils.error("build package failed!") - return false - end - - -- done package - if not package.done(configs) then - -- errors - utils.error("package: failed!") - return false - end - - -- trace - print("package: ok!") - - -- ok - return true -end - --- the menu -function _package.menu() - - return { - -- xmake p - shortname = 'p' - - -- usage - , usage = "xmake package|p [options] [target]" - - -- description - , description = "Package target." - - -- options - , options = - { - {'a', "archs", "kv", nil, "Package multiple given architectures." - , " .e.g --archs=\"armv7, arm64\" or -a i386" - , "" - , function () - local descriptions = {} - local plats = platform.plats() - if plats then - for i, plat in ipairs(plats) do - descriptions[i] = " - " .. plat .. ":" - local archs = platform.archs(plat) - if archs then - for _, arch in ipairs(archs) do - descriptions[i] = descriptions[i] .. " " .. arch - end - end - end - end - return descriptions - end } - - , {} - , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } - , {'P', "project", "kv", nil, "Create from the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - , {'o', "outputdir", "kv", nil, "Set the output 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", "Package a given target" } - } - } -end - --- return module: _package -return _package diff --git a/xmake/core/action/_run.lua b/xmake/core/action/_run.lua deleted file mode 100644 index 31a73dbc8..000000000 --- a/xmake/core/action/_run.lua +++ /dev/null @@ -1,179 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _run.lua --- - --- define module: _run -local _run = _run or {} - --- load modules -local rule = require("base/rule") -local path = require("base/path") -local utils = require("base/utils") -local config = require("base/config") -local project = require("base/project") -local platform = require("base/platform") - --- need access to the given file? -function _run.need(name) - - -- check - assert(name) - - -- the accessors - local accessors = { config = true, global = true, project = true, platform = true } - - -- need it? - return accessors[name] -end - --- done -function _run.done() - - -- the options - local options = xmake._OPTIONS - assert(options and xmake._PROJECT_DIR) - - -- the target name - local name = options.target - if not name then - -- error - utils.error("no runable target!") - return false - end - - -- the arguments - local arguments = options.arguments or {} - if type(arguments) ~= "table" then - arguments = {} - end - - -- the targets - local targets = project.targets() - if not targets or not targets[name] then - -- error - utils.error("not found target: %s!", name) - return false - end - - -- the target - local target = targets[name] - - -- the target file - local targetfile = rule.targetfile(name, target) - if targetfile and not path.is_absolute(targetfile) then - targetfile = path.absolute(targetfile, xmake._PROJECT_DIR) - end - - -- load the run script - local runscript = target.runscript - if type(runscript) == "string" and os.isfile(runscript) then - local script, errors = loadfile(runscript) - if script then - runscript = script() - if type(runscript) == "table" and runscript.main then - runscript = runscript.main - end - else - utils.error(errors) - return false - end - end - - -- run script - if runscript ~= nil then - if type(runscript) == "function" then - - -- make passed target - local target_passed = {} - target_passed.name = name - target_passed.arguments = arguments - target_passed.targetfile = targetfile - - -- run it - local ok = runscript(target_passed) - if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end - else - utils.error("invalid run script!") - return false - end - end - - -- not executale? - if not target.kind or type(target.kind) ~= "string" or target.kind ~= "binary" then - -- error - utils.error("the target %s is not executale!", name) - return false - end - - -- check the target file - if not targetfile and not os.isfile(targetfile) then - -- error - utils.error("not found target file: %s!", targetfile) - return false - end - - -- done - local ok = os.execute(string.format("%s %s", targetfile, table.concat(arguments, " "))) - - -- ok? - return utils.ifelse(ok == 0, true, false) -end - --- the menu -function _run.menu() - - return { - -- xmake r - shortname = 'r' - - -- usage - , usage = "xmake run|r [options] [target] [arguments]" - - -- description - , description = "Run the project target." - - -- options - , options = - { - {'d', "debug", "k", nil, "Run and debug the given target." } - , {nil, "debugger", "kv", "auto", "Set the debugger path." } - - , {} - , {'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", nil, "Run the given target." } - , {nil, "arguments", "vs", nil, "The target arguments" } - } - } -end - --- return module: _run -return _run diff --git a/xmake/core/action/_uninstall.lua b/xmake/core/action/_uninstall.lua deleted file mode 100644 index 93c944b3e..000000000 --- a/xmake/core/action/_uninstall.lua +++ /dev/null @@ -1,160 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- 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("base/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/core/action/action.lua b/xmake/core/action/action.lua deleted file mode 100644 index deeacab57..000000000 --- a/xmake/core/action/action.lua +++ /dev/null @@ -1,190 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file action.lua --- - --- define module: action -local action = action or {} - --- load modules -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local global = require("base/global") -local config = require("base/config") -local project = require("base/project") -local platform = require("base/platform") - --- load the given action -function action._load(name) - - -- load the given action - return require("action/_" .. name) -end - --- load the project file -function action._load_project() - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- enter the project directory - if not os.cd(xmake._PROJECT_DIR) then - -- error - return string.format("not found project: %s!", xmake._PROJECT_DIR) - end - - -- check the project file - if not os.isfile(xmake._PROJECT_FILE) then - return string.format("not found the project file: %s", xmake._PROJECT_FILE) - end - - -- init the build directory - if options.buildir and path.is_absolute(options.buildir) then - options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR) - end - - -- xmake config or marked as "reconfig"? - if options._ACTION == "config" or config._RECONFIG then - - -- probe the current project - project.probe() - - -- clear up the configure - config.clearup() - - end - - -- load the project - return project.load() -end - --- done the given action -function action.done(name) - - -- the options - local options = xmake._OPTIONS - assert(options) - - -- load the given action - local _action = action._load(name) - if not _action then return false end - - -- load the global configure first - if _action.need("global") then global.load() end - - -- load the project configure - if _action.need("config") then - local errors = config.load() - if errors then - -- error - utils.error(errors) - return false - end - end - - -- probe the platform - if _action.need("platform") and (options._ACTION == "config" or config._RECONFIG) then - if not platform.probe(false) then - return false - end - end - - -- merge the default options - for k, v in pairs(options._DEFAULTS) do - if nil == options[k] then options[k] = v end - end - - -- make the platform configure - if _action.need("platform") and not platform.make() then - utils.error("make platform configure: %s failed!", config.get("plat")) - return false - end - - -- load the project file - if _action.need("project") then - local errors = action._load_project() - if errors then - -- error - utils.error(errors) - return false - end - end - - -- reconfig it first if marked as "reconfig" - if _action.need("config") and config._RECONFIG then - - -- config it - local _action_config = action._load("config") - if not _action_config or not _action_config.done() then - -- error - utils.error("reconfig failed for the changed host!") - return false - end - end - - -- done the given action - return _action.done() -end - --- list the all actions -function action.list() - - -- find all action scripts - local list = {} - local files = os.match(xmake._CORE_DIR .. "/action/_*.lua") - if files then - for _, file in ipairs(files) do - local name = path.basename(file) - if name and name ~= "_build" then - table.insert(list, name:sub(2)) - end - end - end - - -- ok? - return list -end - --- get the all action menus -function action.menu() - - -- get all actions - local menus = {} - local actions = action.list() - for _, name in ipairs(actions) do - - -- load action - local a = action._load(name) - if a and a.menu then - local m = a.menu() - if m then - menus[name] = m - end - end - end - - -- ok? - return menus -end - --- return module: action -return action diff --git a/xmake/core/action/build.lua b/xmake/core/action/build.lua new file mode 100644 index 000000000..ee2ddc259 --- /dev/null +++ b/xmake/core/action/build.lua @@ -0,0 +1,120 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_build.lua +-- + +-- define module: action_build +local action_build = action_build or {} + +-- load modules +local rule = require("base/rule") +local utils = require("base/utils") +local clean = require("base/clean") +local config = require("base/config") +local project = require("base/project") +local makefile = require("base/makefile") + +-- need access to the given file? +function action_build.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { config = true, global = true, project = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_build.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- the target name + local target_name = options.target + + -- check target + if not project.checktarget(target_name) then + return false + end + + -- rebuild it? + if options.rebuild or config.get("__rebuild") then + clean.remove(target_name, "build") + -- update it? + elseif options.update then + clean.remove(target_name, "targets") + end + + -- clear rebuild mark and save configure to file + if config.get("__rebuild") then + + -- clear it + config.set("__rebuild", nil) + + -- save the configure + if not config.save() then + -- error + utils.error("update configure failed!") + end + end + + -- check makefile + if not os.isfile(rule.makefile()) then + + -- make the configure file for the given target + if not project.makeconf(options.target) then + -- error + utils.error("make configure failed!") + return false + end + + -- make makefile + if not makefile.make() then + -- error + utils.error("make makefile failed!") + return false + end + end + + -- build target for makefile + if not makefile.build(target_name) then + -- error + print("") + if options.verbose then + io.cat(rule.logfile()) + else + io.tail(rule.logfile(), 32) + end + utils.error("build target: %s failed!\n", target_name) + return false + end + + -- ok + print("build ok!") + return true +end + +-- return module: action_build +return action_build diff --git a/xmake/core/action/clean.lua b/xmake/core/action/clean.lua new file mode 100644 index 000000000..2cb2c840d --- /dev/null +++ b/xmake/core/action/clean.lua @@ -0,0 +1,106 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_clean.lua +-- + +-- define module: action_clean +local action_clean = action_clean or {} + +-- load modules +local clean = require("base/clean") +local config = require("base/config") +local project = require("base/project") +local utils = require("base/utils") +local platform = require("base/platform") + +-- need access to the given file? +function action_clean.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { global = true, config = true, project = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_clean.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- check target + if not project.checktarget(options.target) then + return false + end + + -- clean the current target + if not clean.remove(options.target, utils.ifelse(options.all, "all", "build")) then + return false + end + + -- trace + print("clean ok!") + + -- ok + return true +end + +-- the menu +function action_clean.menu() + + return { + -- xmake c + shortname = 'c' + + -- usage + , usage = "xmake clean|c [options] [target]" + + -- description + , description = "Remove all binary and temporary 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" } + , {} + , {'a', "all", "k", nil, "Clean all auto-generated files by xmake." } + , {} + , {'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", "Clean for the given target." } + } + } +end + +-- return module: action_clean +return action_clean diff --git a/xmake/core/action/config.lua b/xmake/core/action/config.lua new file mode 100644 index 000000000..65cbb4b6a --- /dev/null +++ b/xmake/core/action/config.lua @@ -0,0 +1,215 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file config.lua +-- + +-- define module: action_config +local action_config = action_config or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") +local project = require("base/project") +local makefile = require("base/makefile") +local platform = require("base/platform") + +-- need access to the given file? +function action_config.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { config = true, global = true, project = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_config.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- check target + if not project.checktarget(options.target) then + return false + end + + -- trace + print("configure ...") + + -- save the configure + if not config.save() then + -- error + utils.error("save configure failed!") + return false + end + + -- make the configure file for the given target + if not project.makeconf(options.target) then + -- error + utils.error("make configure failed!") + return false + end + + -- make makefile + if not makefile.make() then + -- error + utils.error("make makefile failed!") + return false + end + + -- dump configure + config.dump() + + -- trace + print("configure ok!") + + -- ok + return true +end + +-- the menu +function action_config.menu() + + return { + -- xmake f + shortname = 'f' + + -- usage + , usage = "xmake config|f [options] [target]" + + -- description + , description = "Configure the project." + + -- options + , options = + { + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + + , {} + , {'p', "plat", "kv", xmake._HOST, "Compile for the given platform." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat + end + end + return descriptions + end } + , {'a', "arch", "kv", "auto", "Compile for the given architecture." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat .. ":" + local archs = platform.archs(plat) + if archs then + for _, arch in ipairs(archs) do + descriptions[i] = descriptions[i] .. " " .. arch + end + end + end + end + return descriptions + end } + , {'m', "mode", "kv", "release", "Compile for the given mode." + , " - debug" + , " - release" + , " - profile" } + , {'k', "kind", "kv", "static", "Compile for the given target kind." + , " - static" + , " - shared" + , " - binary" } + , {nil, "host", "kv", xmake._HOST, "The current host environment." } + + -- the options for project + , function () return project.menu() end + + , {} + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } + + , {} + , {nil, "cross", "kv", nil, "The cross toolchains prefix" + , ".e.g" + , " - i386-mingw32-" + , " - arm-linux-androideabi-" } + , {nil, "toolchains", "kv", nil, "The cross toolchains directory" } + + , {} + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cxx", "kv", nil, "The C++ Compiler" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } + + , {} + , {nil, "as", "kv", nil, "The Assembler" } + , {nil, "asflags", "kv", nil, "The Assembler Flags" } + + , {} + , {nil, "sc", "kv", nil, "The Swift Compiler" } + , {nil, "scflags", "kv", nil, "The Swift Compiler Flags" } + + , {} + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + + , {} + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + + , {} + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + -- the options for all platforms + , function () return platform.menu("config") end + + , {} + , {'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" } + , {'o', "buildir", "kv", "build", "Set the build 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", "Configure for the given target." } + } + } +end + +-- return module: action_config +return action_config diff --git a/xmake/core/action/create.lua b/xmake/core/action/create.lua new file mode 100644 index 000000000..a19404653 --- /dev/null +++ b/xmake/core/action/create.lua @@ -0,0 +1,123 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_create.lua +-- + +-- define module: action_create +local action_create = action_create or {} + +-- load modules +local path = require("base/path") +local utils = require("base/utils") +local template = require("base/template") + +-- need access to the given file? +function action_create.need(name) + + -- no accessors + return false +end + +-- done +function action_create.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- the target name + local targetname = options.target or options.name or path.basename(xmake._PROJECT_DIR) or "demo" + + -- trace + utils.printf("create %s ...", targetname) + + -- create project from template + local ok, errors = template.create(options.language, options.template, targetname) + if not ok then + utils.error(errors) + return false + end + + -- trace + utils.printf("create %s ok!", targetname) + + -- ok + return true +end + +-- the menu +function action_create.menu() + + return { + -- usage + usage = "xmake create [options] [target]" + + -- description + , description = "Create a new project." + + -- options + , options = + { + {'n', "name", "kv", nil, "The project name." } + , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + , {'P', "project", "kv", nil, "Create from the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {'l', "language", "kv", "c", "The project language" + , function () + local descriptions = {} + local languages = template.languages() + for _, language in ipairs(languages) do + table.insert(descriptions, " - " .. language) + end + return descriptions + end } + , {'t', "template", "kv", "1", "Select the project template id of the given language." + , function () + local descriptions = {} + local languages = template.languages() + for _, language in ipairs(languages) do + table.insert(descriptions, string.format(" - language: %s", language)) + local templates = template.loadall(language) + if templates then + for i, template in ipairs(templates) do + table.insert(descriptions, string.format(" %d. %s", i, utils.ifelse(template.description, template.description, "The Unknown Project"))) + end + end + end + return descriptions + end } + + , {} + , {'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", nil, "Create the given target." + , "Uses the project name as target if not exists." } + } + } +end + +-- return module: action_create +return action_create diff --git a/xmake/core/action/debug.lua b/xmake/core/action/debug.lua new file mode 100644 index 000000000..c5d657196 --- /dev/null +++ b/xmake/core/action/debug.lua @@ -0,0 +1,89 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_debug.lua +-- + +-- define module: action_debug +local action_debug = action_debug or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") +local platform = require("base/platform") + +-- need access to the given file? +function action_debug.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { config = true, global = true, project = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_debug.done() + + -- TODO + print("not implement!") + + -- ok + return true +end + +-- the menu +function action_debug.menu() + + return { + -- xmake d + shortname = 'd' + + -- usage + , usage = "xmake debug|d [options] [target]" + + -- description + , description = "Debug target." + + -- options + , options = + { + {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + , {'P', "project", "kv", nil, "Create from 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", nil, "Debug a given target" } + } + } +end + +-- return module: action_debug +return action_debug diff --git a/xmake/core/action/global.lua b/xmake/core/action/global.lua new file mode 100644 index 000000000..31b4ca47f --- /dev/null +++ b/xmake/core/action/global.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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_global.lua +-- + +-- define module: action_global +local action_global = action_global or {} + +-- load modules +local utils = require("base/utils") +local global = require("base/global") +local platform = require("base/platform") + +-- need access to the given file? +function action_global.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { global = true } + + -- need it? + return accessors[name] +end + +-- done +function action_global.done() + + -- probe the global platform configure + if not platform.probe(true) then + return false + end + + -- clear up the global configure + global.clearup() + + -- save the global configure + if not global.save() then + -- error + utils.error("save configure failed!") + return false + end + + -- dump global + global.dump() + + -- ok + print("configure ok!") + return true +end + +-- the menu +function action_global.menu() + + return { + -- xmake g + shortname = 'g' + + -- usage + , usage = "xmake global|g [options] [target]" + + -- description + , description = "Configure the global options for xmake." + + -- options + , options = + { + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." + , " --ccache=[y|n]" } + + , {} + -- the options for all platforms + , function () return platform.menu("global") end + + , {} + , {'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." } + } + } +end + +-- return module: action_global +return action_global diff --git a/xmake/core/action/install.lua b/xmake/core/action/install.lua new file mode 100644 index 000000000..b56514513 --- /dev/null +++ b/xmake/core/action/install.lua @@ -0,0 +1,224 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_install.lua +-- + +-- define module: action_install +local action_install = action_install or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") +local global = require("base/global") +local install = require("base/install") +local package = require("base/package") +local project = require("base/project") +local platform = require("base/platform") + +-- need access to the given file? +function action_install.need(name) + + -- no accessors + return false +end + +-- make configure for the given target +function action_install._makeconf(configs, target_name, target) + + -- check + assert(configs and target_name and target) + + -- init configs for targets + configs[target_name] = configs[target_name] or {} + local configs_target = configs[target_name] + + -- save the install script + local installscript = target.installscript + if type(installscript) == "string" and os.isfile(installscript) then + local script, errors = loadfile(installscript) + if script then + installscript = script() + if type(installscript) == "table" and installscript.main then + installscript = installscript.main + end + else + utils.error(errors) + return false + end + end + if target.installscript and type(installscript) ~= "function" then + utils.error("invalid install script!") + return false + end + configs_target.installscript = installscript + + -- ok + return true +end + +-- package target +function action_install._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 action_install.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- trace + print("install: ...") + + -- 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 + + -- package the given target first + if not action_install._package(options.target) then + -- errors + utils.error("package: failed!") + return false + end + + -- load the package configure + local configs, errors = package.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 + + -- update the outputdir + for _, target in pairs(configs) do + target.outputdir = options.installdir + end + + -- the targets + local targets = project.targets() + assert(targets) + + -- make configure for the given target + if target_name and target_name ~= "all" then + if not action_install._makeconf(configs, target_name, targets[target_name]) then + utils.error("make target configure: %s failed!", target_name) + return false + end + else + for target_name, target in pairs(targets) do + if not action_install._makeconf(configs, target_name, target) then + utils.error("make target configure: %s failed!", target_name) + return false + end + end + end + + -- done install + if not install.done(configs) then + -- errors + utils.error("install: failed!") + return false + end + + -- trace + print("install: ok!") + + -- ok + return true +end + +-- the menu +function action_install.menu() + + return { + -- xmake i + shortname = 'i' + + -- usage + , usage = "xmake install|i [options] [target]" + + -- description + , description = "Package and install 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" } + , {'o', "installdir", "kv", nil, "Set the install 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: action_install +return action_install diff --git a/xmake/core/action/lua.lua b/xmake/core/action/lua.lua new file mode 100644 index 000000000..c5a6ce1d5 --- /dev/null +++ b/xmake/core/action/lua.lua @@ -0,0 +1,168 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_lua.lua +-- + +-- define module: action_lua +local action_lua = action_lua or {} + +-- load modules +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local config = require("base/config") +local string = require("base/string") +local tools = require("tools/tools") +local platform = require("base/platform") + +-- need access to the given file? +function action_lua.need(name) + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- do not load config if be not given -f or -P options + if options.file == nil and options.project == nil then + return false + end + + -- patch target for loading config ok + options.target = "all" + + -- the accessors + local accessors = { config = true, global = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_lua.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- no script? + if not options.script then + return false + end + + -- the arguments + local arguments = options.arguments or {} + if type(arguments) ~= "table" then + arguments = {} + end + + -- is string script? + if options.string then + + -- trace + utils.verbose("script: %s", options.script) + + -- load and run string + local script = loadstring(options.script) + if script then + return script(arguments) + end + else + -- attempt to load script from the given file if exists + local file = options.script + if not path.is_absolute(file) then + file = path.absolute(file) + end + + -- attempt to load script from the tools directory + if not os.isfile(file) then + file = tools.find(options.script, xmake._CORE_DIR .. "/tools") + end + + -- load and run the script file + if os.isfile(file) then + + -- load script + local script = loadfile(file) + if script then + + -- load module + local module = script() + if module then + + -- init module + if module.init then + module:init(options.script) + end + + -- done module + return module:main(arguments) + end + end + end + end + + -- failed + utils.error("cannot run this script: %s", options.script) + return false +end + +-- the menu +function action_lua.menu() + + return { + -- xmake l + shortname = 'l' + + -- usage + , usage = "xmake lua|l [options] [script] [arguments]" + + -- description + , description = "Run the lua script." + + -- options + , options = + { + {'f', "file", "kv", nil, "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" } + + , {} + , {'s', "string", "k", nil, "Run the lua string script." } + + , {} + , {'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, "script", "v", nil, "Run the given lua script." + , " - The script name from the xmake tool directory" + , " - The script file" + , " - The script string" } + , {nil, "arguments", "vs", nil, "The script arguments" } + } + } +end + +-- return module: action_lua +return action_lua diff --git a/xmake/core/action/man.lua b/xmake/core/action/man.lua new file mode 100644 index 000000000..1ba0aeeef --- /dev/null +++ b/xmake/core/action/man.lua @@ -0,0 +1,89 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_man.lua +-- + +-- define module: action_man +local action_man = action_man or {} + +-- load modules +local utils = require("base/utils") +local config = require("base/config") +local platform = require("base/platform") + +-- need access to the given file? +function action_man.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { config = true, global = true, project = true } + + -- need it? + return accessors[name] +end + +-- done +function action_man.done() + + -- TODO + print("not implement!") + + -- ok + return true +end + +-- the menu +function action_man.menu() + + return { + -- xmake m + shortname = 'm' + + -- usage + , usage = "xmake man|m [options] [target]" + + -- description + , description = "Create a project man." + + -- options + , options = + { + {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + , {'P', "project", "kv", nil, "Create from 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", "Create man for the given target" } + } + } +end + +-- return module: action_man +return action_man diff --git a/xmake/core/action/package.lua b/xmake/core/action/package.lua new file mode 100644 index 000000000..7b809af56 --- /dev/null +++ b/xmake/core/action/package.lua @@ -0,0 +1,365 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_package.lua +-- + +-- define module: action_package +local action_package = action_package or {} + +-- load modules +local rule = require("base/rule") +local path = require("base/path") +local utils = require("base/utils") +local config = require("base/config") +local global = require("base/global") +local string = require("base/string") +local project = require("base/project") +local package = require("base/package") +local platform = require("base/platform") + +-- need access to the given file? +function action_package.need(name) + + -- no accessors + return false +end + +-- configure target for the given architecture +function action_package._config(arch, target_name) + + -- need not configure it + if not arch then return true end + + -- done the command + return os.execute(string.format("xmake f -P %s -f %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, arch, target_name)) == 0; +end + +-- build target for the given architecture +function action_package._build(arch, target_name) + + -- get the target name + if not target_name or target_name == "all" then + target_name = "" + end + + -- configure it first + if not action_package._config(arch, target_name) then return false end + + -- build it + if os.execute(string.format("xmake -P %s %s", xmake._PROJECT_DIR, target_name)) ~= 0 then + -- errors + utils.error("build failed!") + return false + end + + -- ok + return true +end + +-- backup the target files +function action_package._backup(rootdir, filepath) + + -- the relative file path + if filepath and path.is_absolute(filepath) then + filepath = path.relative(filepath, xmake._PROJECT_DIR) + end + + -- not exists? return it directly + if not filepath or not os.isfile(filepath) then return end + + -- the backup file + local backupfile = string.format("%s/%s", rootdir, filepath) + + -- backup it + local ok, errors = os.cp(filepath, backupfile) + if not ok then + -- errors + utils.error(errors) + return + end + + -- ok + return filepath +end + +-- make configure for the given target +function action_package._makeconf(target_name, target) + + -- check + assert(target_name and target) + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- the configs + local configs = action_package._CONFIGS + assert(configs) + + -- the architecture + local arch = config.get("arch") + if not arch then return false end + + -- init configs for targets + configs[target_name] = configs[target_name] or {} + local configs_target = configs[target_name] + + -- init configs for architectures + configs_target.archs = configs_target.archs or {} + + -- init configs for architecture + configs_target.archs[arch] = configs_target.archs[arch] or {} + local configs_arch = configs_target.archs[arch] + + -- save name + configs_target.name = target_name + + -- save kind + configs_target.kind = target.kind + + -- save the output directory + configs_target.outputdir = options.outputdir or config.get("buildir") + + -- save the header files + configs_target.headers = target.headers + + -- save the target directory + configs_arch.targetdir = rule.backupdir(target_name, arch) + + -- save the config file + configs_arch.config_h = action_package._backup(configs_arch.targetdir, rule.config_h(target)) + + -- save the target file + configs_arch.targetfile = action_package._backup(configs_arch.targetdir, rule.targetfile(target_name, target)) + + -- save the package script + local packagescript = target.packagescript + if type(packagescript) == "string" and os.isfile(packagescript) then + local script, errors = loadfile(packagescript) + if script then + packagescript = script() + if type(packagescript) == "table" and packagescript.main then + packagescript = packagescript.main + end + else + utils.error(errors) + return false + end + end + if target.packagescript and type(packagescript) ~= "function" then + utils.error("invalid package script!") + return false + end + configs_target.packagescript = packagescript + + -- ok + return true +end + +-- load configure for the given target +function action_package._loadconf(target_name) + + -- 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 + + -- the targets + local targets = project.targets() + assert(targets) + + -- make configure for the given target + if target_name and target_name ~= "all" then + if not action_package._makeconf(target_name, targets[target_name]) then + utils.error("make target configure: %s failed!", target_name) + return false + end + else + for target_name, target in pairs(targets) do + if not action_package._makeconf(target_name, target) then + utils.error("make target configure: %s failed!", target_name) + return false + end + end + end + + -- ok + return true +end + +-- build target for all architectures +function action_package._build_all(archs, target_name) + + -- exists the given architectures? + if archs then + + -- split all architectures + archs = archs:split(",") + if not archs then return false end + + -- build for all architectures + for _, arch in ipairs(archs) do + + -- trim it + arch = arch:trim() + + -- build it + if not action_package._build(arch, target_name) then return false end + + -- load configure + if not action_package._loadconf(target_name) then return false end + + end + + -- build for single architecture + else + + -- build it + if not action_package._build(nil, target_name) then return false end + + -- load configure + if not action_package._loadconf(target_name) then return false end + + end + + -- ok + return true +end + +-- done +function action_package.done() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- trace + print("package: ...") + + -- init configs + action_package._CONFIGS = action_package._CONFIGS or {} + local configs = action_package._CONFIGS + + -- 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 + + -- build the given target first for all architectures + if not action_package._build_all(options.archs, options.target) then + -- errors + utils.error("build package failed!") + return false + end + + -- done package + if not package.done(configs) then + -- errors + utils.error("package: failed!") + return false + end + + -- trace + print("package: ok!") + + -- ok + return true +end + +-- the menu +function action_package.menu() + + return { + -- xmake p + shortname = 'p' + + -- usage + , usage = "xmake package|p [options] [target]" + + -- description + , description = "Package target." + + -- options + , options = + { + {'a', "archs", "kv", nil, "Package multiple given architectures." + , " .e.g --archs=\"armv7, arm64\" or -a i386" + , "" + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat .. ":" + local archs = platform.archs(plat) + if archs then + for _, arch in ipairs(archs) do + descriptions[i] = descriptions[i] .. " " .. arch + end + end + end + end + return descriptions + end } + + , {} + , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + , {'P', "project", "kv", nil, "Create from the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {'o', "outputdir", "kv", nil, "Set the output 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", "Package a given target" } + } + } +end + +-- return module: action_package +return action_package diff --git a/xmake/core/action/run.lua b/xmake/core/action/run.lua new file mode 100644 index 000000000..3a3a351b7 --- /dev/null +++ b/xmake/core/action/run.lua @@ -0,0 +1,179 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_run.lua +-- + +-- define module: action_run +local action_run = action_run or {} + +-- load modules +local rule = require("base/rule") +local path = require("base/path") +local utils = require("base/utils") +local config = require("base/config") +local project = require("base/project") +local platform = require("base/platform") + +-- need access to the given file? +function action_run.need(name) + + -- check + assert(name) + + -- the accessors + local accessors = { config = true, global = true, project = true, platform = true } + + -- need it? + return accessors[name] +end + +-- done +function action_run.done() + + -- the options + local options = xmake._OPTIONS + assert(options and xmake._PROJECT_DIR) + + -- the target name + local name = options.target + if not name then + -- error + utils.error("no runable target!") + return false + end + + -- the arguments + local arguments = options.arguments or {} + if type(arguments) ~= "table" then + arguments = {} + end + + -- the targets + local targets = project.targets() + if not targets or not targets[name] then + -- error + utils.error("not found target: %s!", name) + return false + end + + -- the target + local target = targets[name] + + -- the target file + local targetfile = rule.targetfile(name, target) + if targetfile and not path.is_absolute(targetfile) then + targetfile = path.absolute(targetfile, xmake._PROJECT_DIR) + end + + -- load the run script + local runscript = target.runscript + if type(runscript) == "string" and os.isfile(runscript) then + local script, errors = loadfile(runscript) + if script then + runscript = script() + if type(runscript) == "table" and runscript.main then + runscript = runscript.main + end + else + utils.error(errors) + return false + end + end + + -- run script + if runscript ~= nil then + if type(runscript) == "function" then + + -- make passed target + local target_passed = {} + target_passed.name = name + target_passed.arguments = arguments + target_passed.targetfile = targetfile + + -- run it + local ok = runscript(target_passed) + if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end + else + utils.error("invalid run script!") + return false + end + end + + -- not executale? + if not target.kind or type(target.kind) ~= "string" or target.kind ~= "binary" then + -- error + utils.error("the target %s is not executale!", name) + return false + end + + -- check the target file + if not targetfile and not os.isfile(targetfile) then + -- error + utils.error("not found target file: %s!", targetfile) + return false + end + + -- done + local ok = os.execute(string.format("%s %s", targetfile, table.concat(arguments, " "))) + + -- ok? + return utils.ifelse(ok == 0, true, false) +end + +-- the menu +function action_run.menu() + + return { + -- xmake r + shortname = 'r' + + -- usage + , usage = "xmake run|r [options] [target] [arguments]" + + -- description + , description = "Run the project target." + + -- options + , options = + { + {'d', "debug", "k", nil, "Run and debug the given target." } + , {nil, "debugger", "kv", "auto", "Set the debugger path." } + + , {} + , {'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", nil, "Run the given target." } + , {nil, "arguments", "vs", nil, "The target arguments" } + } + } +end + +-- return module: action_run +return action_run diff --git a/xmake/core/action/uninstall.lua b/xmake/core/action/uninstall.lua new file mode 100644 index 000000000..ebb72109c --- /dev/null +++ b/xmake/core/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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action_uninstall.lua +-- + +-- define module: action_uninstall +local action_uninstall = action_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("base/platform") + +-- need access to the given file? +function action_uninstall.need(name) + + -- no accessors + return false +end + +-- package target +function action_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 action_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 action_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: action_uninstall +return action_uninstall diff --git a/xmake/core/base/action.lua b/xmake/core/base/action.lua new file mode 100644 index 000000000..2cb7c71cf --- /dev/null +++ b/xmake/core/base/action.lua @@ -0,0 +1,190 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file action.lua +-- + +-- define module: action +local action = action or {} + +-- load modules +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local global = require("base/global") +local config = require("base/config") +local project = require("base/project") +local platform = require("base/platform") + +-- load the given action +function action._load(name) + + -- load the given action + return require("action/" .. name) +end + +-- load the project file +function action._load_project() + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- enter the project directory + if not os.cd(xmake._PROJECT_DIR) then + -- error + return string.format("not found project: %s!", xmake._PROJECT_DIR) + end + + -- check the project file + if not os.isfile(xmake._PROJECT_FILE) then + return string.format("not found the project file: %s", xmake._PROJECT_FILE) + end + + -- init the build directory + if options.buildir and path.is_absolute(options.buildir) then + options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR) + end + + -- xmake config or marked as "reconfig"? + if options._ACTION == "config" or config._RECONFIG then + + -- probe the current project + project.probe() + + -- clear up the configure + config.clearup() + + end + + -- load the project + return project.load() +end + +-- done the given action +function action.done(name) + + -- the options + local options = xmake._OPTIONS + assert(options) + + -- load the given action + local _action = action._load(name) + if not _action then return false end + + -- load the global configure first + if _action.need("global") then global.load() end + + -- load the project configure + if _action.need("config") then + local errors = config.load() + if errors then + -- error + utils.error(errors) + return false + end + end + + -- probe the platform + if _action.need("platform") and (options._ACTION == "config" or config._RECONFIG) then + if not platform.probe(false) then + return false + end + end + + -- merge the default options + for k, v in pairs(options._DEFAULTS) do + if nil == options[k] then options[k] = v end + end + + -- make the platform configure + if _action.need("platform") and not platform.make() then + utils.error("make platform configure: %s failed!", config.get("plat")) + return false + end + + -- load the project file + if _action.need("project") then + local errors = action._load_project() + if errors then + -- error + utils.error(errors) + return false + end + end + + -- reconfig it first if marked as "reconfig" + if _action.need("config") and config._RECONFIG then + + -- config it + local _action_config = action._load("config") + if not _action_config or not _action_config.done() then + -- error + utils.error("reconfig failed for the changed host!") + return false + end + end + + -- done the given action + return _action.done() +end + +-- list the all actions +function action.list() + + -- find all action scripts + local list = {} + local files = os.match(xmake._CORE_DIR .. "/action/*.lua") + if files then + for _, file in ipairs(files) do + local name = path.basename(file) + if name and name ~= "build" then + table.insert(list, name) + end + end + end + + -- ok? + return list +end + +-- get the all action menus +function action.menu() + + -- get all actions + local menus = {} + local actions = action.list() + for _, name in ipairs(actions) do + + -- load action + local a = action._load(name) + if a and a.menu then + local m = a.menu() + if m then + menus[name] = m + end + end + end + + -- ok? + return menus +end + +-- return module: action +return action diff --git a/xmake/core/base/main.lua b/xmake/core/base/main.lua index 470815701..ad521700b 100644 --- a/xmake/core/base/main.lua +++ b/xmake/core/base/main.lua @@ -28,7 +28,7 @@ local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local option = require("base/option") -local action = require("action/action") +local action = require("base/action") -- init the option menu local menu = -- cgit v1.3.1