diff options
| author | ruki <[email protected]> | 2015-12-07 11:04:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-12-07 11:04:09 +0800 |
| commit | 9e5eecfdc1629dd3d9880fb5cb19d848b10a525b (patch) | |
| tree | ce4fc4363f2ca49b362399bf950f22ee70aee3a8 | |
| parent | cbd6458e80f4335ddc62cb236731b258b1ba66ed (diff) | |
add static and shared library template for tbox
28 files changed, 1268 insertions, 0 deletions
diff --git a/xmake/templates/c++/shared_library_tbox/_template.lua b/xmake/templates/c++/shared_library_tbox/_template.lua new file mode 100644 index 000000000..951152bc1 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/_template.lua @@ -0,0 +1,73 @@ +--!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 Shared Library (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 .. "/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/main.cpp", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/[targetname]/xmake.lua", "%[targetname%]", targetname) + + -- rename the target directory + if not os.mv(projectdir .. "/src/[targetname]", projectdir .. "/src/" .. targetname) then + -- errors + utils.error("rename the target directory failed!") + return false + end + + -- 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++/shared_library_tbox/project/src/[targetname]/interface.cpp b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/interface.cpp new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/interface.cpp @@ -0,0 +1,12 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "interface.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t add(tb_int_t a, tb_int_t b) +{ + return a + b; +} diff --git a/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/interface.h b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/interface.h new file mode 100644 index 000000000..513cce181 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/interface.h @@ -0,0 +1,30 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "config.h" +#include "tbox/tbox.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_enter__ + + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +__tb_export__ tb_int_t add(tb_int_t a, tb_int_t b); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_leave__ + +#endif diff --git a/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/xmake.lua b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/xmake.lua new file mode 100644 index 000000000..f22611058 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/[targetname]/xmake.lua @@ -0,0 +1,29 @@ +-- add target +add_target("[targetname]") + + -- set kind + set_kind("shared") + + -- 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") + + -- add the header files for installing + add_headers("../([targetname]/**.h)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- 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++/shared_library_tbox/project/src/demo/main.cpp b/xmake/templates/c++/shared_library_tbox/project/src/demo/main.cpp new file mode 100644 index 000000000..2b974bfd8 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/demo/main.cpp @@ -0,0 +1,23 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "[targetname]/interface.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!"); + + // test + tb_trace_i("add(1 + 1) = %d", add(1, 1)); + + // exit tbox + tb_exit(); + return 0; +} diff --git a/xmake/templates/c++/shared_library_tbox/project/src/demo/xmake.lua b/xmake/templates/c++/shared_library_tbox/project/src/demo/xmake.lua new file mode 100644 index 000000000..deeb9db4a --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/demo/xmake.lua @@ -0,0 +1,31 @@ +-- add target +add_target("demo") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add defines + add_defines("__tb_prefix__=\"demo\"") + + -- set the object files directory + set_objectdir("$(buildir)/.objs") + + -- add links directory + add_linkdirs("$(buildir)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- add links + add_links("[targetname]") + + -- add packages + add_options("tbox", "base") + + -- add files + add_files("*.cpp") + diff --git a/xmake/templates/c++/shared_library_tbox/project/xmake.lua b/xmake/templates/c++/shared_library_tbox/project/xmake.lua new file mode 100644 index 000000000..3509970b7 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/xmake.lua @@ -0,0 +1,119 @@ +-- 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 option: demo +add_option("demo") + set_option_enable(true) + set_option_showmenu(true) + set_option_category("option") + set_option_description("Enable or disable the demo module") + +-- add packages +add_pkgdirs("pkg") + +-- add projects +add_subdirs("src/[targetname]") +if options("demo") then add_subdirs("src/demo") end diff --git a/xmake/templates/c++/static_library_tbox/_template.lua b/xmake/templates/c++/static_library_tbox/_template.lua new file mode 100644 index 000000000..9312c2435 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/_template.lua @@ -0,0 +1,73 @@ +--!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 Static Library (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 .. "/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/main.cpp", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/[targetname]/xmake.lua", "%[targetname%]", targetname) + + -- rename the target directory + if not os.mv(projectdir .. "/src/[targetname]", projectdir .. "/src/" .. targetname) then + -- errors + utils.error("rename the target directory failed!") + return false + end + + -- 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++/static_library_tbox/project/src/[targetname]/interface.cpp b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/interface.cpp new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/interface.cpp @@ -0,0 +1,12 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "interface.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t add(tb_int_t a, tb_int_t b) +{ + return a + b; +} diff --git a/xmake/templates/c++/static_library_tbox/project/src/[targetname]/interface.h b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/interface.h new file mode 100644 index 000000000..c8c62ac70 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/interface.h @@ -0,0 +1,30 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "config.h" +#include "tbox/tbox.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_enter__ + + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +tb_int_t add(tb_int_t a, tb_int_t b); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_leave__ + +#endif diff --git a/xmake/templates/c++/static_library_tbox/project/src/[targetname]/xmake.lua b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/xmake.lua new file mode 100644 index 000000000..206605202 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/[targetname]/xmake.lua @@ -0,0 +1,29 @@ +-- add target +add_target("[targetname]") + + -- set kind + set_kind("static") + + -- 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") + + -- add the header files for installing + add_headers("../([targetname]/**.h)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- 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++/static_library_tbox/project/src/demo/main.cpp b/xmake/templates/c++/static_library_tbox/project/src/demo/main.cpp new file mode 100644 index 000000000..2b974bfd8 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/demo/main.cpp @@ -0,0 +1,23 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "[targetname]/interface.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!"); + + // test + tb_trace_i("add(1 + 1) = %d", add(1, 1)); + + // exit tbox + tb_exit(); + return 0; +} diff --git a/xmake/templates/c++/static_library_tbox/project/src/demo/xmake.lua b/xmake/templates/c++/static_library_tbox/project/src/demo/xmake.lua new file mode 100644 index 000000000..deeb9db4a --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/demo/xmake.lua @@ -0,0 +1,31 @@ +-- add target +add_target("demo") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add defines + add_defines("__tb_prefix__=\"demo\"") + + -- set the object files directory + set_objectdir("$(buildir)/.objs") + + -- add links directory + add_linkdirs("$(buildir)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- add links + add_links("[targetname]") + + -- add packages + add_options("tbox", "base") + + -- add files + add_files("*.cpp") + diff --git a/xmake/templates/c++/static_library_tbox/project/xmake.lua b/xmake/templates/c++/static_library_tbox/project/xmake.lua new file mode 100644 index 000000000..3509970b7 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/xmake.lua @@ -0,0 +1,119 @@ +-- 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 option: demo +add_option("demo") + set_option_enable(true) + set_option_showmenu(true) + set_option_category("option") + set_option_description("Enable or disable the demo module") + +-- add packages +add_pkgdirs("pkg") + +-- add projects +add_subdirs("src/[targetname]") +if options("demo") then add_subdirs("src/demo") end diff --git a/xmake/templates/c/shared_library_tbox/_template.lua b/xmake/templates/c/shared_library_tbox/_template.lua new file mode 100644 index 000000000..1df207819 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/_template.lua @@ -0,0 +1,73 @@ +--!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 Shared Library (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 .. "/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/main.c", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/[targetname]/xmake.lua", "%[targetname%]", targetname) + + -- rename the target directory + if not os.mv(projectdir .. "/src/[targetname]", projectdir .. "/src/" .. targetname) then + -- errors + utils.error("rename the target directory failed!") + return false + end + + -- 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/shared_library_tbox/project/src/[targetname]/interface.c b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/interface.c new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/interface.c @@ -0,0 +1,12 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "interface.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t add(tb_int_t a, tb_int_t b) +{ + return a + b; +} diff --git a/xmake/templates/c/shared_library_tbox/project/src/[targetname]/interface.h b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/interface.h new file mode 100644 index 000000000..513cce181 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/interface.h @@ -0,0 +1,30 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "config.h" +#include "tbox/tbox.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_enter__ + + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +__tb_export__ tb_int_t add(tb_int_t a, tb_int_t b); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_leave__ + +#endif diff --git a/xmake/templates/c/shared_library_tbox/project/src/[targetname]/xmake.lua b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/xmake.lua new file mode 100644 index 000000000..6f67ab2fe --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/[targetname]/xmake.lua @@ -0,0 +1,29 @@ +-- add target +add_target("[targetname]") + + -- set kind + set_kind("shared") + + -- 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") + + -- add the header files for installing + add_headers("../([targetname]/**.h)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- 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/shared_library_tbox/project/src/demo/main.c b/xmake/templates/c/shared_library_tbox/project/src/demo/main.c new file mode 100644 index 000000000..2b974bfd8 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/demo/main.c @@ -0,0 +1,23 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "[targetname]/interface.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!"); + + // test + tb_trace_i("add(1 + 1) = %d", add(1, 1)); + + // exit tbox + tb_exit(); + return 0; +} diff --git a/xmake/templates/c/shared_library_tbox/project/src/demo/xmake.lua b/xmake/templates/c/shared_library_tbox/project/src/demo/xmake.lua new file mode 100644 index 000000000..c750a9b70 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/demo/xmake.lua @@ -0,0 +1,31 @@ +-- add target +add_target("demo") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add defines + add_defines("__tb_prefix__=\"demo\"") + + -- set the object files directory + set_objectdir("$(buildir)/.objs") + + -- add links directory + add_linkdirs("$(buildir)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- add links + add_links("[targetname]") + + -- add packages + add_options("tbox", "base") + + -- add files + add_files("*.c") + diff --git a/xmake/templates/c/shared_library_tbox/project/xmake.lua b/xmake/templates/c/shared_library_tbox/project/xmake.lua new file mode 100644 index 000000000..3509970b7 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/xmake.lua @@ -0,0 +1,119 @@ +-- 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 option: demo +add_option("demo") + set_option_enable(true) + set_option_showmenu(true) + set_option_category("option") + set_option_description("Enable or disable the demo module") + +-- add packages +add_pkgdirs("pkg") + +-- add projects +add_subdirs("src/[targetname]") +if options("demo") then add_subdirs("src/demo") end diff --git a/xmake/templates/c/static_library_tbox/_template.lua b/xmake/templates/c/static_library_tbox/_template.lua new file mode 100644 index 000000000..18536fbc4 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/_template.lua @@ -0,0 +1,73 @@ +--!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 Static Library (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 .. "/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/main.c", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/demo/xmake.lua", "%[targetname%]", targetname) + io.gsub(projectdir .. "/src/[targetname]/xmake.lua", "%[targetname%]", targetname) + + -- rename the target directory + if not os.mv(projectdir .. "/src/[targetname]", projectdir .. "/src/" .. targetname) then + -- errors + utils.error("rename the target directory failed!") + return false + end + + -- 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/static_library_tbox/project/src/[targetname]/interface.c b/xmake/templates/c/static_library_tbox/project/src/[targetname]/interface.c new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/[targetname]/interface.c @@ -0,0 +1,12 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "interface.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t add(tb_int_t a, tb_int_t b) +{ + return a + b; +} diff --git a/xmake/templates/c/static_library_tbox/project/src/[targetname]/interface.h b/xmake/templates/c/static_library_tbox/project/src/[targetname]/interface.h new file mode 100644 index 000000000..c8c62ac70 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/[targetname]/interface.h @@ -0,0 +1,30 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "config.h" +#include "tbox/tbox.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_enter__ + + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +tb_int_t add(tb_int_t a, tb_int_t b); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_leave__ + +#endif diff --git a/xmake/templates/c/static_library_tbox/project/src/[targetname]/xmake.lua b/xmake/templates/c/static_library_tbox/project/src/[targetname]/xmake.lua new file mode 100644 index 000000000..6c4ffbd5d --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/[targetname]/xmake.lua @@ -0,0 +1,29 @@ +-- add target +add_target("[targetname]") + + -- set kind + set_kind("static") + + -- 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") + + -- add the header files for installing + add_headers("../([targetname]/**.h)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- 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/static_library_tbox/project/src/demo/main.c b/xmake/templates/c/static_library_tbox/project/src/demo/main.c new file mode 100644 index 000000000..2b974bfd8 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/demo/main.c @@ -0,0 +1,23 @@ +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "[targetname]/interface.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!"); + + // test + tb_trace_i("add(1 + 1) = %d", add(1, 1)); + + // exit tbox + tb_exit(); + return 0; +} diff --git a/xmake/templates/c/static_library_tbox/project/src/demo/xmake.lua b/xmake/templates/c/static_library_tbox/project/src/demo/xmake.lua new file mode 100644 index 000000000..c750a9b70 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/demo/xmake.lua @@ -0,0 +1,31 @@ +-- add target +add_target("demo") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add defines + add_defines("__tb_prefix__=\"demo\"") + + -- set the object files directory + set_objectdir("$(buildir)/.objs") + + -- add links directory + add_linkdirs("$(buildir)") + + -- add includes directory + add_includedirs("$(buildir)") + add_includedirs("$(buildir)/[targetname]") + + -- add links + add_links("[targetname]") + + -- add packages + add_options("tbox", "base") + + -- add files + add_files("*.c") + diff --git a/xmake/templates/c/static_library_tbox/project/xmake.lua b/xmake/templates/c/static_library_tbox/project/xmake.lua new file mode 100644 index 000000000..3509970b7 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/xmake.lua @@ -0,0 +1,119 @@ +-- 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 option: demo +add_option("demo") + set_option_enable(true) + set_option_showmenu(true) + set_option_category("option") + set_option_description("Enable or disable the demo module") + +-- add packages +add_pkgdirs("pkg") + +-- add projects +add_subdirs("src/[targetname]") +if options("demo") then add_subdirs("src/demo") end |
