diff options
| author | ruki <[email protected]> | 2015-05-02 20:12:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-02 20:12:39 +0800 |
| commit | 6d4865a5c2c156ad812ecef9a7973c6a0375e7b4 (patch) | |
| tree | 0d4cba41d3b80c812d0f1cb64dc1045a5b96abb8 | |
| parent | 335840294ec2442d177358cc8e42c036d46401ac (diff) | |
print the menu
| -rw-r--r-- | xmake/scripts/base/main.lua | 119 | ||||
| -rw-r--r-- | xmake/scripts/base/option.lua | 205 | ||||
| -rw-r--r-- | xmake/scripts/base/utils.lua | 9 |
3 files changed, 307 insertions, 26 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 039deae88..710a521ab 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -28,17 +28,13 @@ local utils = require("base/utils") local option = require("base/option") -- init the option menu -option._MENU = +local menu = { -- title - title = "XMake" .. xmake._VERSION .. ", The Automatic Cross-platform Build Tool" + title = "XMake " .. xmake._VERSION .. ", The Automatic Cross-platform Build Tool" -- copyright -, copyright = - [[ - Copyright (C) 2015-2016 Ruki Wang, tboox.org - Copyright (C) 2005-2014 Mike Pall, luajit.org - ]] +, copyright = "Copyright (C) 2015-2016 Ruki Wang, tboox.org\nCopyright (C) 2005-2014 Mike Pall, luajit.org" -- build project: xmake , main = @@ -46,14 +42,31 @@ option._MENU = -- usage usage = "xmake [action] [options] ..." + -- description + , description = "Build the project if no given action." + + , -- actions + actions = {"create", "config", "install", "clean"} + -- options , options = { - {'p', "project", "Change to the given project directory." } - , {'f', "file", "Read a given xmake.lua file." } - , {'-', "verbose", "Print lots of verbose information." } - , {'v', "version", "Print the version number and exit." } - , {'h', "help", "Print this help message and exit." } + {'b', "build", "k", nil, "Build project. This is default building mode and optional." } + , {'u', "update", "k", nil, "Only relink and update the binary files." } + , {'r', "rebuild", "k", nil, "Rebuild the project." } + + , {} + , {nil, "verbose", "k", nil, "Print lots of verbose information." } + , {'v', "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {nil, nil, "v", nil, "Change to the given project directory." + , "Search priority:" + , " 1. the last argument of the current command: ..." + , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" + , " 3. the current directory" } } } @@ -72,6 +85,17 @@ option._MENU = -- options , options = { + {nil, "verbose", "k", nil, "Print lots of verbose information." } + , {'v', "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {nil, nil, "v", nil, "Change to the given project directory." + , "Search priority:" + , " 1. the last argument of the current command: ..." + , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" + , " 3. the current directory" } } } @@ -90,6 +114,46 @@ option._MENU = -- options , options = { + {'d', "debug", "k", nil, "Compile for the debugging mode. (default: release)" } + , {nil, "profile", "k", nil, "Compile for the profiling mode and disable the debugging mode."} + + , {} + , {nil, "output", "kv", "build", "Set the build output directory" } + , {nil, "packages", "kv", "pkg", "Set the packages directory" } + + , {} + , {nil, "cc", "kv", nil, "The c compiler" } + , {nil, "cxx", "kv", nil, "The c++ compiler" } + , {nil, "mm", "kv", nil, "The objc compiler" } + , {nil, "mxx", "kv", nil, "The objc++ compiler" } + , {nil, "ld", "kv", nil, "The linker" } + , {nil, "as", "kv", nil, "The assembler" } + , {nil, "ar", "kv", nil, "The library creator" } + + , {} + , {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, "mflags", "kv", nil, "The objc compiler flags" } + , {nil, "mxflags", "kv", nil, "The objc/c++ compiler flags" } + , {nil, "mxxflags", "kv", nil, "The objc++ compiler flags" } + , {nil, "asflags", "kv", nil, "The assembler flags" } + , {nil, "ldflags", "kv", nil, "The linker flags" } + , {nil, "arflags", "kv", nil, "The library creator flags" } + + , {} + , {nil, "verbose", "k", nil, "Print lots of verbose information." } + , {'v', "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {nil, nil, "v", nil, "Change to the given project directory." + , "Search priority:" + , " 1. the last argument of the current command: ..." + , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" + , " 3. the current directory" } + } } @@ -108,6 +172,17 @@ option._MENU = -- options , options = { + {nil, "verbose", "k", nil, "Print lots of verbose information." } + , {'v', "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {nil, nil, "v", nil, "Change to the given project directory." + , "Search priority:" + , " 1. the last argument of the current command: ..." + , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" + , " 3. the current directory" } } } @@ -121,11 +196,22 @@ option._MENU = , usage = "xmake clean|c [options] ..." -- description - , description = "Clean the project binary and temporary files." + , description = "Remove all binary and temporary files." -- options , options = { + {nil, "verbose", "k", nil, "Print lots of verbose information." } + , {'v', "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {nil, nil, "v", nil, "Change to the given project directory." + , "Search priority:" + , " 1. the last argument of the current command: ..." + , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" + , " 3. the current directory" } } } } @@ -134,12 +220,7 @@ option._MENU = function main.done() -- done option first - if not option.done(xmake._ARGV) then - - -- print the help option - option.help() - - -- failed + if not option.done(xmake._ARGV, menu) then return -1 end diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua index a4d7ce1bf..51c18d701 100644 --- a/xmake/scripts/base/option.lua +++ b/xmake/scripts/base/option.lua @@ -23,6 +23,9 @@ -- define module: option local option = {} +-- load modules +local utils = require("base/utils") + -- init _OPTIONS.metatable to always use lowercase keys local _OPTIONS_metatable = { @@ -45,10 +48,10 @@ xmake._OPTIONS = xmake._OPTIONS or {} setmetatable(xmake._OPTIONS, _OPTIONS_metatable) -- done the option -function option.done(argv) +function option.done(argv, menu) -- check - assert(option._MENU) + assert(argv and menu) -- parse _ARGV to _OPTIONS for i, arg in ipairs(argv) do @@ -76,16 +79,208 @@ function option.done(argv) end end + -- save menu + option._MENU = menu + + -- print main menu + option.print_main() + + -- print action menu: create + option.print_action("create") + option.print_action("config") + option.print_action("install") + option.print_action("clean") + -- ok return true end --- print the help option -function option.help() +-- print the main menu +function option.print_main() + + -- the menu + local menu = option._MENU + assert(menu) + + -- the main menu + local main = menu.main + assert(main) + + -- print title + if menu.title then + print(menu.title) + end + + -- print copyright + if menu.copyright then + print(menu.copyright) + end + + -- print usage + if main.usage then + print("") + print("Usage: " .. main.usage) + end + + -- print description + if main.description then + print("") + print(main.description) + end + + -- print actions + if main.actions then + + -- print header + print("") + print("Actions: ") + + -- the padding spaces + local padding = 32 + + -- print actions + for _, action in ipairs(main.actions) do + + -- the action menu + local action_menu = menu[action] + + -- init the action info + local action_info = " " .. utils.ifelse(action_menu and action_menu.shortname, action_menu.shortname .. ", ", " ") + + -- append the action + action_info = action_info .. action + + if action_menu then + -- append spaces + for i = (#action_info), padding do + action_info = action_info .. " " + end + + -- append the action description + if action_menu.description then + action_info = action_info .. action_menu.description + end + end + + -- print action info + print(action_info) + end + end + + -- print options + if main.options then + option.print_options(main.options) + end +end + +-- print the action menu +function option.print_action(action) + + -- no action? print main menu + if not action then + option.print_main() + end + + -- the menu + local menu = option._MENU + assert(menu) + + -- the action + action = menu[action] + assert(action) + + -- print usage + if action.usage then + print("Usage: " .. action.usage) + end + + -- print description + if action.description then + print("") + print(action.description) + end + + -- print options + if action.options then + option.print_options(action.options) + end +end + +-- print the options menu +function option.print_options(options) -- check - assert(option._MENU) + assert(options) + + -- print header + print("") + print("Options: ") + + -- the padding spaces + local padding = 32 + + -- print options + for _, option in ipairs(options) do + + -- init the option info + local option_info = "" + + -- append the shortname + local shortname = option[1]; + local name = option[2]; + local mode = option[3]; + if shortname then + option_info = option_info .. " -" .. shortname + if mode == "kv" then + option_info = option_info .. " " .. utils.ifelse(name, name:upper(), "XXX") + end + end + + -- append the name + if name then + option_info = option_info .. utils.ifelse(shortname, ", --", " --") .. name + if mode == "kv" then + option_info = option_info .. "=" .. name:upper() + end + elseif mode == "v" then + option_info = option_info .. " ..." + end + + -- append spaces + for i = (#option_info), padding do + option_info = option_info .. " " + end + + -- append the option description + local description = option[5]; + if description then + option_info = option_info .. description + end + -- append the default value + local default = option[4]; + if default then + option_info = option_info .. " (default: " .. default .. ")" + end + + -- print option info + print(option_info) + + -- print more description if exists + for i = 6, #option do + if option[i] then + + -- make spaces + local spaces = "" + for i = 0, padding do + spaces = spaces .. " " + end + + -- print this description + print(spaces .. option[i]) + end + end + end end -- return module: option diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua index 59769c260..1c05fd480 100644 --- a/xmake/scripts/base/utils.lua +++ b/xmake/scripts/base/utils.lua @@ -23,8 +23,8 @@ -- define module: utils local utils = {} --- the trace function -function utils.trace(msg, ...) +-- the printf function +function utils.printf(msg, ...) print(string.format(msg, ...)) end @@ -45,5 +45,10 @@ function utils.warning(msg, ...) print("warning: " .. string.format(msg, ...)) end +-- ifelse, a? b : c +function utils.ifelse(a, b, c) + if a then return b else return c end +end + -- return module: utils return utils |
