diff options
| author | ruki <[email protected]> | 2016-01-25 09:47:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:25 +0800 |
| commit | 80f231295375a965495885e015963ad563d2935a (patch) | |
| tree | 26925828acbe4c5981dbf074b47f8a6d9586ae34 | |
| parent | b8b1b5129ddcc0154e701dbac023f19ae1a3bf8c (diff) | |
update templates
69 files changed, 2054 insertions, 1 deletions
diff --git a/xmake/core/base/template.lua b/xmake/core/base/template.lua index 2dc7135fa..ab2f400dc 100644 --- a/xmake/core/base/template.lua +++ b/xmake/core/base/template.lua @@ -52,7 +52,9 @@ function template._interpreter() interp:api_register_add_values(nil, nil, "macrofiles") -- register api: add_keyvalues() for root - interp:api_register_add_keyvalues(nil, nil, "macros") + interp:api_register_add_keyvalues(nil, nil, "macros" + , "copydirs" + , "movedirs") -- save interpreter template._INTERPRETER = interp @@ -61,6 +63,42 @@ function template._interpreter() return interp end +-- copy directories +function template._copydirs(copydirs) + + -- check + assert(copydirs) + + -- copy them + for srcdir, dstdir in pairs(copydirs) do + local ok, errors = os.cp(srcdir, dstdir) + if not ok then + return false, errors + end + end + + -- ok + return true +end + +-- move directories +function template._movedirs(movedirs) + + -- check + assert(movedirs) + + -- copy them + for srcdir, dstdir in pairs(movedirs) do + local ok, errors = os.mv(srcdir, dstdir) + if not ok then + return false, errors + end + end + + -- ok + return true +end + -- replace macros function template._replace(macros, macrofiles) @@ -172,6 +210,9 @@ function template.create(language, templateid, targetname) -- replace targetname if variable == "targetname" then variable = targetname + -- replace packagesdir + elseif variable == "packagesdir" then + variable = xmake._PACKAGES_DIR end -- ok? @@ -215,6 +256,22 @@ function template.create(language, templateid, targetname) return false, string.format("can not enter %s!", xmake._PROJECT_DIR) end + -- copy directories + if module.copydirs then + ok, errors = template._copydirs(module.copydirs) + if not ok then + return false, errors + end + end + + -- move directories + if module.movedirs then + ok, errors = template._movedirs(module.movedirs) + if not ok then + return false, errors + end + end + -- replace macros if module.macros and module.macrofiles then ok, errors = template._replace(module.macros, module.macrofiles) diff --git a/xmake/templates/c++/console/project/src/main.cpp b/xmake/templates/c++/console/project/src/main.cpp new file mode 100644 index 000000000..db2361659 --- /dev/null +++ b/xmake/templates/c++/console/project/src/main.cpp @@ -0,0 +1,9 @@ +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/xmake/templates/c++/console/project/xmake.lua b/xmake/templates/c++/console/project/xmake.lua new file mode 100644 index 000000000..30aca7364 --- /dev/null +++ b/xmake/templates/c++/console/project/xmake.lua @@ -0,0 +1,32 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.c") + diff --git a/xmake/templates/c++/console/template.lua b/xmake/templates/c++/console/template.lua new file mode 100644 index 000000000..09412f86d --- /dev/null +++ b/xmake/templates/c++/console/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Console Program") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") 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..ad676ef58 --- /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)) 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..602566ca6 --- /dev/null +++ b/xmake/templates/c++/console_tbox/template.lua @@ -0,0 +1,15 @@ +-- set description +set_description("The Console Program (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("src/xmake.lua") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") diff --git a/xmake/templates/c++/shared_library/project/src/interface.cpp b/xmake/templates/c++/shared_library/project/src/interface.cpp new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/xmake/templates/c++/shared_library/project/src/interface.cpp @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/xmake/templates/c++/shared_library/project/src/interface.h b/xmake/templates/c++/shared_library/project/src/interface.h new file mode 100644 index 000000000..ef24ba3ce --- /dev/null +++ b/xmake/templates/c++/shared_library/project/src/interface.h @@ -0,0 +1,24 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) +# define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +# define __export __attribute__((visibility("default"))) +#else +# define __export +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +__export int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/c++/shared_library/project/src/test.cpp b/xmake/templates/c++/shared_library/project/src/test.cpp new file mode 100644 index 000000000..72e03272b --- /dev/null +++ b/xmake/templates/c++/shared_library/project/src/test.cpp @@ -0,0 +1,10 @@ +#include "interface.h" +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "add(1, 2) = " << add(1, 2) << endl; + return 0; +} diff --git a/xmake/templates/c++/shared_library/project/xmake.lua b/xmake/templates/c++/shared_library/project/xmake.lua new file mode 100644 index 000000000..b776097d8 --- /dev/null +++ b/xmake/templates/c++/shared_library/project/xmake.lua @@ -0,0 +1,50 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("shared") + + -- add files + add_files("src/interface.cpp") + +-- add target +add_target("test") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add files + add_files("src/test.cpp") + + -- add links + add_links("[targetname]") + + -- add link directory + add_linkdirs("$(buildir)") + diff --git a/xmake/templates/c++/shared_library/template.lua b/xmake/templates/c++/shared_library/template.lua new file mode 100644 index 000000000..87e2f7183 --- /dev/null +++ b/xmake/templates/c++/shared_library/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Shared Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") 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..818ff6919 --- /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)) 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/src/_library/interface.cpp b/xmake/templates/c++/shared_library_tbox/project/src/_library/interface.cpp new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/_library/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/_library/interface.h b/xmake/templates/c++/shared_library_tbox/project/src/_library/interface.h new file mode 100644 index 000000000..513cce181 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/_library/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/_library/xmake.lua b/xmake/templates/c++/shared_library_tbox/project/src/_library/xmake.lua new file mode 100644 index 000000000..f22611058 --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/project/src/_library/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/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++/shared_library_tbox/template.lua b/xmake/templates/c++/shared_library_tbox/template.lua new file mode 100644 index 000000000..b2fcede6d --- /dev/null +++ b/xmake/templates/c++/shared_library_tbox/template.lua @@ -0,0 +1,22 @@ +-- set description +set_description("The Shared Library (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") +add_macrofiles("src/$(targetname)_demo/main.c") +add_macrofiles("src/$(targetname)_demo/xmake.lua") +add_macrofiles("src/$(targetname)/xmake.lua") + +-- add move directories +add_movedirs("src/_library", "src/$(targetname)") +add_movedirs("src/_demo", "src/$(targetname)_demo") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") diff --git a/xmake/templates/c++/static_library/project/src/interface.cpp b/xmake/templates/c++/static_library/project/src/interface.cpp new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/xmake/templates/c++/static_library/project/src/interface.cpp @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/xmake/templates/c++/static_library/project/src/interface.h b/xmake/templates/c++/static_library/project/src/interface.h new file mode 100644 index 000000000..4a41e9597 --- /dev/null +++ b/xmake/templates/c++/static_library/project/src/interface.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/c++/static_library/project/src/test.cpp b/xmake/templates/c++/static_library/project/src/test.cpp new file mode 100644 index 000000000..72e03272b --- /dev/null +++ b/xmake/templates/c++/static_library/project/src/test.cpp @@ -0,0 +1,10 @@ +#include "interface.h" +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "add(1, 2) = " << add(1, 2) << endl; + return 0; +} diff --git a/xmake/templates/c++/static_library/project/xmake.lua b/xmake/templates/c++/static_library/project/xmake.lua new file mode 100644 index 000000000..56774575e --- /dev/null +++ b/xmake/templates/c++/static_library/project/xmake.lua @@ -0,0 +1,50 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("static") + + -- add files + add_files("src/interface.cpp") + +-- add target +add_target("test") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add files + add_files("src/test.cpp") + + -- add links + add_links("[targetname]") + + -- add link directory + add_linkdirs("$(buildir)") + diff --git a/xmake/templates/c++/static_library/template.lua b/xmake/templates/c++/static_library/template.lua new file mode 100644 index 000000000..fdc5ae91c --- /dev/null +++ b/xmake/templates/c++/static_library/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Static Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") 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..818ff6919 --- /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)) 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/src/_library/interface.cpp b/xmake/templates/c++/static_library_tbox/project/src/_library/interface.cpp new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/_library/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/_library/interface.h b/xmake/templates/c++/static_library_tbox/project/src/_library/interface.h new file mode 100644 index 000000000..c8c62ac70 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/_library/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/_library/xmake.lua b/xmake/templates/c++/static_library_tbox/project/src/_library/xmake.lua new file mode 100644 index 000000000..206605202 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/project/src/_library/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/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++/static_library_tbox/template.lua b/xmake/templates/c++/static_library_tbox/template.lua new file mode 100644 index 000000000..926e78a47 --- /dev/null +++ b/xmake/templates/c++/static_library_tbox/template.lua @@ -0,0 +1,22 @@ +-- set description +set_description("The Static Library (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") +add_macrofiles("src/$(targetname)_demo/main.c") +add_macrofiles("src/$(targetname)_demo/xmake.lua") +add_macrofiles("src/$(targetname)/xmake.lua") + +-- add move directories +add_movedirs("src/_library", "src/$(targetname)") +add_movedirs("src/_demo", "src/$(targetname)_demo") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") 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..ad676ef58 --- /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)) 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") diff --git a/xmake/templates/c/console_tbox/template.lua b/xmake/templates/c/console_tbox/template.lua new file mode 100644 index 000000000..602566ca6 --- /dev/null +++ b/xmake/templates/c/console_tbox/template.lua @@ -0,0 +1,15 @@ +-- set description +set_description("The Console Program (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("src/xmake.lua") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") diff --git a/xmake/templates/c/shared_library/project/src/interface.c b/xmake/templates/c/shared_library/project/src/interface.c new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/xmake/templates/c/shared_library/project/src/interface.c @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/xmake/templates/c/shared_library/project/src/interface.h b/xmake/templates/c/shared_library/project/src/interface.h new file mode 100644 index 000000000..7a3eb570a --- /dev/null +++ b/xmake/templates/c/shared_library/project/src/interface.h @@ -0,0 +1,18 @@ +#if defined(_WIN32) +# define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +# define __export __attribute__((visibility("default"))) +#else +# define __export +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +__export int add(int a, int b); + + diff --git a/xmake/templates/c/shared_library/project/src/test.c b/xmake/templates/c/shared_library/project/src/test.c new file mode 100644 index 000000000..9505a2f75 --- /dev/null +++ b/xmake/templates/c/shared_library/project/src/test.c @@ -0,0 +1,8 @@ +#include "interface.h" +#include <stdio.h> + +int main(int argc, char** argv) +{ + printf("add(1, 2) = %d\n", add(1, 2)); + return 0; +} diff --git a/xmake/templates/c/shared_library/project/xmake.lua b/xmake/templates/c/shared_library/project/xmake.lua new file mode 100644 index 000000000..f6d15d851 --- /dev/null +++ b/xmake/templates/c/shared_library/project/xmake.lua @@ -0,0 +1,50 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("shared") + + -- add files + add_files("src/interface.c") + +-- add target +add_target("test") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add files + add_files("src/test.c") + + -- add links + add_links("[targetname]") + + -- add link directory + add_linkdirs("$(buildir)") + diff --git a/xmake/templates/c/shared_library/template.lua b/xmake/templates/c/shared_library/template.lua new file mode 100644 index 000000000..87e2f7183 --- /dev/null +++ b/xmake/templates/c/shared_library/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Shared Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") 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..818ff6919 --- /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)) 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/src/_library/interface.c b/xmake/templates/c/shared_library_tbox/project/src/_library/interface.c new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/_library/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/_library/interface.h b/xmake/templates/c/shared_library_tbox/project/src/_library/interface.h new file mode 100644 index 000000000..513cce181 --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/_library/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/_library/xmake.lua b/xmake/templates/c/shared_library_tbox/project/src/_library/xmake.lua new file mode 100644 index 000000000..6f67ab2fe --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/project/src/_library/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/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/shared_library_tbox/template.lua b/xmake/templates/c/shared_library_tbox/template.lua new file mode 100644 index 000000000..b2fcede6d --- /dev/null +++ b/xmake/templates/c/shared_library_tbox/template.lua @@ -0,0 +1,22 @@ +-- set description +set_description("The Shared Library (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") +add_macrofiles("src/$(targetname)_demo/main.c") +add_macrofiles("src/$(targetname)_demo/xmake.lua") +add_macrofiles("src/$(targetname)/xmake.lua") + +-- add move directories +add_movedirs("src/_library", "src/$(targetname)") +add_movedirs("src/_demo", "src/$(targetname)_demo") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") diff --git a/xmake/templates/c/static_library/project/src/interface.c b/xmake/templates/c/static_library/project/src/interface.c new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/xmake/templates/c/static_library/project/src/interface.c @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/xmake/templates/c/static_library/project/src/interface.h b/xmake/templates/c/static_library/project/src/interface.h new file mode 100644 index 000000000..10ec0f856 --- /dev/null +++ b/xmake/templates/c/static_library/project/src/interface.h @@ -0,0 +1,8 @@ +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); diff --git a/xmake/templates/c/static_library/project/src/test.c b/xmake/templates/c/static_library/project/src/test.c new file mode 100644 index 000000000..9505a2f75 --- /dev/null +++ b/xmake/templates/c/static_library/project/src/test.c @@ -0,0 +1,8 @@ +#include "interface.h" +#include <stdio.h> + +int main(int argc, char** argv) +{ + printf("add(1, 2) = %d\n", add(1, 2)); + return 0; +} diff --git a/xmake/templates/c/static_library/project/xmake.lua b/xmake/templates/c/static_library/project/xmake.lua new file mode 100644 index 000000000..148b7b268 --- /dev/null +++ b/xmake/templates/c/static_library/project/xmake.lua @@ -0,0 +1,50 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("static") + + -- add files + add_files("src/interface.c") + +-- add target +add_target("test") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add files + add_files("src/test.c") + + -- add links + add_links("[targetname]") + + -- add link directory + add_linkdirs("$(buildir)") + diff --git a/xmake/templates/c/static_library/template.lua b/xmake/templates/c/static_library/template.lua new file mode 100644 index 000000000..fdc5ae91c --- /dev/null +++ b/xmake/templates/c/static_library/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Static Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") 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..818ff6919 --- /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)) 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/src/_library/interface.c b/xmake/templates/c/static_library_tbox/project/src/_library/interface.c new file mode 100644 index 000000000..a0ccb007b --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/_library/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/_library/interface.h b/xmake/templates/c/static_library_tbox/project/src/_library/interface.h new file mode 100644 index 000000000..c8c62ac70 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/_library/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/_library/xmake.lua b/xmake/templates/c/static_library_tbox/project/src/_library/xmake.lua new file mode 100644 index 000000000..6c4ffbd5d --- /dev/null +++ b/xmake/templates/c/static_library_tbox/project/src/_library/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/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/static_library_tbox/template.lua b/xmake/templates/c/static_library_tbox/template.lua new file mode 100644 index 000000000..926e78a47 --- /dev/null +++ b/xmake/templates/c/static_library_tbox/template.lua @@ -0,0 +1,22 @@ +-- set description +set_description("The Static Library (tbox)") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") +add_macrofiles("src/$(targetname)_demo/main.c") +add_macrofiles("src/$(targetname)_demo/xmake.lua") +add_macrofiles("src/$(targetname)/xmake.lua") + +-- add move directories +add_movedirs("src/_library", "src/$(targetname)") +add_movedirs("src/_demo", "src/$(targetname)_demo") + +-- add copy directories +add_copydirs("$(packagesdir)/tbox.pkg", "pkg/tbox.pkg") +add_copydirs("$(packagesdir)/base.pkg", "pkg/base.pkg") diff --git a/xmake/templates/objc++/console/project/src/main.mm b/xmake/templates/objc++/console/project/src/main.mm new file mode 100644 index 000000000..61a3f5875 --- /dev/null +++ b/xmake/templates/objc++/console/project/src/main.mm @@ -0,0 +1,10 @@ +#import <Foundation/Foundation.h> + +int main(int argc, char** argv) +{ + @autoreleasepool + { + NSLog(@"hello world!"); + } + return 0; +} diff --git a/xmake/templates/objc++/console/project/xmake.lua b/xmake/templates/objc++/console/project/xmake.lua new file mode 100644 index 000000000..b051ac9df --- /dev/null +++ b/xmake/templates/objc++/console/project/xmake.lua @@ -0,0 +1,43 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- for macosx or ios +if os("macosx", "ios") then + + -- add framework + add_mxflags("-framework Foundation", "-framework CoreFoundation") + add_ldflags("-framework Foundation", "-framework CoreFoundation") + + -- enable arc? + add_mxflags("-fobjc-arc") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.mm") + diff --git a/xmake/templates/objc++/console/template.lua b/xmake/templates/objc++/console/template.lua new file mode 100644 index 000000000..09412f86d --- /dev/null +++ b/xmake/templates/objc++/console/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Console Program") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") diff --git a/xmake/templates/objc/console/project/src/main.m b/xmake/templates/objc/console/project/src/main.m new file mode 100644 index 000000000..61a3f5875 --- /dev/null +++ b/xmake/templates/objc/console/project/src/main.m @@ -0,0 +1,10 @@ +#import <Foundation/Foundation.h> + +int main(int argc, char** argv) +{ + @autoreleasepool + { + NSLog(@"hello world!"); + } + return 0; +} diff --git a/xmake/templates/objc/console/project/xmake.lua b/xmake/templates/objc/console/project/xmake.lua new file mode 100644 index 000000000..5e08682d5 --- /dev/null +++ b/xmake/templates/objc/console/project/xmake.lua @@ -0,0 +1,43 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- for macosx or ios +if os("macosx", "ios") then + + -- add framework + add_mxflags("-framework Foundation", "-framework CoreFoundation") + add_ldflags("-framework Foundation", "-framework CoreFoundation") + + -- enable arc? + add_mxflags("-fobjc-arc") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.m") + diff --git a/xmake/templates/objc/console/template.lua b/xmake/templates/objc/console/template.lua new file mode 100644 index 000000000..09412f86d --- /dev/null +++ b/xmake/templates/objc/console/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Console Program") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") diff --git a/xmake/templates/swift/console/project/src/main.swift b/xmake/templates/swift/console/project/src/main.swift new file mode 100644 index 000000000..ee21045f4 --- /dev/null +++ b/xmake/templates/swift/console/project/src/main.swift @@ -0,0 +1,3 @@ +import Foundation + +print("hello world!") diff --git a/xmake/templates/swift/console/project/xmake.lua b/xmake/templates/swift/console/project/xmake.lua new file mode 100644 index 000000000..f4aef294d --- /dev/null +++ b/xmake/templates/swift/console/project/xmake.lua @@ -0,0 +1,32 @@ +-- the debug mode +if modes("debug") then + + -- enable the debug symbols + set_symbols("debug") + + -- disable optimization + set_optimize("none") +end + +-- the release mode +if modes("release") then + + -- set the symbols visibility: hidden + set_symbols("hidden") + + -- enable fastest optimization + set_optimize("fastest") + + -- strip all symbols + set_strip("all") +end + +-- add target +add_target("[targetname]") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.swift") + diff --git a/xmake/templates/swift/console/template.lua b/xmake/templates/swift/console/template.lua new file mode 100644 index 000000000..09412f86d --- /dev/null +++ b/xmake/templates/swift/console/template.lua @@ -0,0 +1,11 @@ +-- set description +set_description("The Console Program") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") |
