summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-12-07 10:24:42 +0800
committerruki <[email protected]>2015-12-07 10:24:42 +0800
commitcbd6458e80f4335ddc62cb236731b258b1ba66ed (patch)
tree97b53b7b519595cb94a42f4aff8c2dbbbb3949b5
parentaaa157e94ea35a19f023483baffcff1b72e96a77 (diff)
add packages and console_tbox template
-rw-r--r--xmake/scripts/_xmake_main.lua1
-rw-r--r--xmake/scripts/action/_create.lua4
-rw-r--r--xmake/templates/c++/console_tbox/_template.lua63
-rw-r--r--xmake/templates/c++/console_tbox/project/src/main.cpp20
-rw-r--r--xmake/templates/c++/console_tbox/project/src/xmake.lua22
-rw-r--r--xmake/templates/c++/console_tbox/project/xmake.lua111
-rw-r--r--xmake/templates/c/console_tbox/_template.lua63
-rw-r--r--xmake/templates/c/console_tbox/project/src/main.c20
-rw-r--r--xmake/templates/c/console_tbox/project/src/xmake.lua22
-rw-r--r--xmake/templates/c/console_tbox/project/xmake.lua111
10 files changed, 435 insertions, 2 deletions
diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua
index c8ca48589..50f0d313c 100644
--- a/xmake/scripts/_xmake_main.lua
+++ b/xmake/scripts/_xmake_main.lua
@@ -30,6 +30,7 @@ xmake._VERSION = _VERSION
xmake._PROGRAM_DIR = _PROGRAM_DIR
xmake._PROJECT_DIR = _PROJECT_DIR
xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts"
+xmake._PACKAGES_DIR = _PROGRAM_DIR .. "/packages"
xmake._TEMPLATES_DIR = _PROGRAM_DIR .. "/templates"
xmake._PROJECT_FILE = "xmake.lua"
xmake._OPTIONS = {}
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua
index 7f91039ad..1a18c79b6 100644
--- a/xmake/scripts/action/_create.lua
+++ b/xmake/scripts/action/_create.lua
@@ -42,7 +42,7 @@ function _create.done()
assert(options)
-- the target name
- local targetname = options.target or path.basename(xmake._PROJECT_DIR) or "demo"
+ local targetname = options.target or options.name or path.basename(xmake._PROJECT_DIR) or "demo"
-- trace
utils.printf("create %s ...", targetname)
@@ -99,7 +99,7 @@ function _create.done()
end
-- done the template files
- if not module.done(targetname, xmake._PROJECT_DIR) then
+ if not module.done(targetname, xmake._PROJECT_DIR, xmake._PACKAGES_DIR) then
utils.error("update the template failed!")
return false
end
diff --git a/xmake/templates/c++/console_tbox/_template.lua b/xmake/templates/c++/console_tbox/_template.lua
new file mode 100644
index 000000000..5cda384bc
--- /dev/null
+++ b/xmake/templates/c++/console_tbox/_template.lua
@@ -0,0 +1,63 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _template.lua
+--
+
+-- define module: _template
+local _template = _template or {}
+
+-- load modules
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+
+-- init the template description
+_template.description = "The Console Program (tbox)"
+
+-- done the template file
+function _template.done(targetname, projectdir, packagesdir)
+
+ -- check
+ assert(targetname and projectdir and packagesdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/src/xmake.lua", "%[targetname%]", targetname)
+
+ -- copy the tbox.pkg
+ if not os.cp(packagesdir .. "/tbox.pkg/", projectdir .. "/pkg/tbox.pkg") then
+ -- errors
+ utils.error("copy tbox.pkg failed!")
+ return false
+ end
+
+ -- copy the base.pkg
+ if not os.cp(packagesdir .. "/base.pkg/", projectdir .. "/pkg/base.pkg") then
+ -- errors
+ utils.error("copy base.pkg failed!")
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
diff --git a/xmake/templates/c++/console_tbox/project/src/main.cpp b/xmake/templates/c++/console_tbox/project/src/main.cpp
new file mode 100644
index 000000000..80d02e35e
--- /dev/null
+++ b/xmake/templates/c++/console_tbox/project/src/main.cpp
@@ -0,0 +1,20 @@
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "tbox/tbox.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * main
+ */
+tb_int_t main(tb_int_t argc, tb_char_t** argv)
+{
+ // init tbox
+ if (!tb_init(tb_null, tb_null, tb_null, 0)) return -1;
+
+ // trace
+ tb_trace_i("hello tbox!");
+
+ // exit tbox
+ tb_exit();
+ return 0;
+}
diff --git a/xmake/templates/c++/console_tbox/project/src/xmake.lua b/xmake/templates/c++/console_tbox/project/src/xmake.lua
new file mode 100644
index 000000000..f42ad3a71
--- /dev/null
+++ b/xmake/templates/c++/console_tbox/project/src/xmake.lua
@@ -0,0 +1,22 @@
+-- add target
+add_target("[targetname]")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add defines
+ add_defines("__tb_prefix__=\"[targetname]\"")
+
+ -- set the auto-generated config.h
+ set_config_h("$(buildir)/[targetname].config.h")
+ set_config_h_prefix("CONFIG")
+
+ -- set the object files directory
+ set_objectdir("$(buildir)/.objs")
+
+ -- add packages
+ add_options("tbox", "base")
+
+ -- add files
+ add_files("*.cpp")
+
diff --git a/xmake/templates/c++/console_tbox/project/xmake.lua b/xmake/templates/c++/console_tbox/project/xmake.lua
new file mode 100644
index 000000000..9a7c001e5
--- /dev/null
+++ b/xmake/templates/c++/console_tbox/project/xmake.lua
@@ -0,0 +1,111 @@
+-- version
+set_version("1.0.0")
+
+-- set warning all as error
+set_warnings("all", "error")
+
+-- set language: c99, c++11
+set_languages("c99", "cxx11")
+
+-- disable some compiler errors
+add_cxflags("-Wno-error=deprecated-declarations")
+add_mxflags("-Wno-error=deprecated-declarations")
+
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+
+ -- add defines for debug
+ add_defines("__tb_debug__")
+
+ -- attempt to enable some checkers for pc
+ if archs("i386", "x86_64") then
+ add_cxflags("-fsanitize=address", "-ftrapv")
+ add_mxflags("-fsanitize=address", "-ftrapv")
+ add_ldflags("-fsanitize=address")
+ end
+end
+
+-- the release or profile modes
+if modes("release", "profile") then
+
+ -- the release mode
+ if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- strip all symbols
+ set_strip("all")
+
+ -- fomit the frame pointer
+ add_cxflags("-fomit-frame-pointer")
+ add_mxflags("-fomit-frame-pointer")
+
+ -- the profile mode
+ else
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ end
+
+ -- for pc
+ if archs("i386", "x86_64") then
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- for embed
+ else
+ -- enable smallest optimization
+ set_optimize("smallest")
+ end
+
+ -- attempt to add vector extensions
+ add_vectorexts("sse2", "sse3", "ssse3", "mmx")
+end
+
+-- for embed
+if not archs("i386", "x86_64") then
+
+ -- add defines for small
+ add_defines("__tb_small__")
+
+ -- add defines to config.h
+ add_defines_h("$(prefix)_SMALL")
+end
+
+-- for the windows platform (msvc)
+if plats("windows") then
+
+ -- the release mode
+ if modes("release") then
+
+ -- link libcmt.lib
+ add_cxflags("-MT")
+
+ -- the debug mode
+ elseif modes("debug") then
+
+ -- enable some checkers
+ add_cxflags("-Gs", "-RTC1")
+
+ -- link libcmtd.lib
+ add_cxflags("-MTd")
+ end
+
+ -- no msvcrt.lib
+ add_ldflags("-nodefaultlib:\"msvcrt.lib\"")
+end
+
+-- add packages
+add_pkgdirs("pkg")
+
+-- add projects
+add_subdirs("src")
diff --git a/xmake/templates/c/console_tbox/_template.lua b/xmake/templates/c/console_tbox/_template.lua
new file mode 100644
index 000000000..5cda384bc
--- /dev/null
+++ b/xmake/templates/c/console_tbox/_template.lua
@@ -0,0 +1,63 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _template.lua
+--
+
+-- define module: _template
+local _template = _template or {}
+
+-- load modules
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+
+-- init the template description
+_template.description = "The Console Program (tbox)"
+
+-- done the template file
+function _template.done(targetname, projectdir, packagesdir)
+
+ -- check
+ assert(targetname and projectdir and packagesdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/src/xmake.lua", "%[targetname%]", targetname)
+
+ -- copy the tbox.pkg
+ if not os.cp(packagesdir .. "/tbox.pkg/", projectdir .. "/pkg/tbox.pkg") then
+ -- errors
+ utils.error("copy tbox.pkg failed!")
+ return false
+ end
+
+ -- copy the base.pkg
+ if not os.cp(packagesdir .. "/base.pkg/", projectdir .. "/pkg/base.pkg") then
+ -- errors
+ utils.error("copy base.pkg failed!")
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
diff --git a/xmake/templates/c/console_tbox/project/src/main.c b/xmake/templates/c/console_tbox/project/src/main.c
new file mode 100644
index 000000000..80d02e35e
--- /dev/null
+++ b/xmake/templates/c/console_tbox/project/src/main.c
@@ -0,0 +1,20 @@
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "tbox/tbox.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * main
+ */
+tb_int_t main(tb_int_t argc, tb_char_t** argv)
+{
+ // init tbox
+ if (!tb_init(tb_null, tb_null, tb_null, 0)) return -1;
+
+ // trace
+ tb_trace_i("hello tbox!");
+
+ // exit tbox
+ tb_exit();
+ return 0;
+}
diff --git a/xmake/templates/c/console_tbox/project/src/xmake.lua b/xmake/templates/c/console_tbox/project/src/xmake.lua
new file mode 100644
index 000000000..3f6e5b51c
--- /dev/null
+++ b/xmake/templates/c/console_tbox/project/src/xmake.lua
@@ -0,0 +1,22 @@
+-- add target
+add_target("[targetname]")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add defines
+ add_defines("__tb_prefix__=\"[targetname]\"")
+
+ -- set the auto-generated config.h
+ set_config_h("$(buildir)/[targetname].config.h")
+ set_config_h_prefix("CONFIG")
+
+ -- set the object files directory
+ set_objectdir("$(buildir)/.objs")
+
+ -- add packages
+ add_options("tbox", "base")
+
+ -- add files
+ add_files("*.c")
+
diff --git a/xmake/templates/c/console_tbox/project/xmake.lua b/xmake/templates/c/console_tbox/project/xmake.lua
new file mode 100644
index 000000000..9a7c001e5
--- /dev/null
+++ b/xmake/templates/c/console_tbox/project/xmake.lua
@@ -0,0 +1,111 @@
+-- version
+set_version("1.0.0")
+
+-- set warning all as error
+set_warnings("all", "error")
+
+-- set language: c99, c++11
+set_languages("c99", "cxx11")
+
+-- disable some compiler errors
+add_cxflags("-Wno-error=deprecated-declarations")
+add_mxflags("-Wno-error=deprecated-declarations")
+
+-- the debug mode
+if modes("debug") then
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ -- disable optimization
+ set_optimize("none")
+
+ -- add defines for debug
+ add_defines("__tb_debug__")
+
+ -- attempt to enable some checkers for pc
+ if archs("i386", "x86_64") then
+ add_cxflags("-fsanitize=address", "-ftrapv")
+ add_mxflags("-fsanitize=address", "-ftrapv")
+ add_ldflags("-fsanitize=address")
+ end
+end
+
+-- the release or profile modes
+if modes("release", "profile") then
+
+ -- the release mode
+ if modes("release") then
+
+ -- set the symbols visibility: hidden
+ set_symbols("hidden")
+
+ -- strip all symbols
+ set_strip("all")
+
+ -- fomit the frame pointer
+ add_cxflags("-fomit-frame-pointer")
+ add_mxflags("-fomit-frame-pointer")
+
+ -- the profile mode
+ else
+
+ -- enable the debug symbols
+ set_symbols("debug")
+
+ end
+
+ -- for pc
+ if archs("i386", "x86_64") then
+
+ -- enable fastest optimization
+ set_optimize("fastest")
+
+ -- for embed
+ else
+ -- enable smallest optimization
+ set_optimize("smallest")
+ end
+
+ -- attempt to add vector extensions
+ add_vectorexts("sse2", "sse3", "ssse3", "mmx")
+end
+
+-- for embed
+if not archs("i386", "x86_64") then
+
+ -- add defines for small
+ add_defines("__tb_small__")
+
+ -- add defines to config.h
+ add_defines_h("$(prefix)_SMALL")
+end
+
+-- for the windows platform (msvc)
+if plats("windows") then
+
+ -- the release mode
+ if modes("release") then
+
+ -- link libcmt.lib
+ add_cxflags("-MT")
+
+ -- the debug mode
+ elseif modes("debug") then
+
+ -- enable some checkers
+ add_cxflags("-Gs", "-RTC1")
+
+ -- link libcmtd.lib
+ add_cxflags("-MTd")
+ end
+
+ -- no msvcrt.lib
+ add_ldflags("-nodefaultlib:\"msvcrt.lib\"")
+end
+
+-- add packages
+add_pkgdirs("pkg")
+
+-- add projects
+add_subdirs("src")