summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-21 21:44:40 +0800
committerruki <[email protected]>2015-06-21 21:44:40 +0800
commit6faa822ae876cd75a0ad936e9af863f559e9d8e8 (patch)
tree11443cf8cb6e8632ab4022476d51b5fc9216aec2
parenta3f92451ca522092bd12e0c64a73b1154993253d (diff)
add static and shared library templates
-rw-r--r--xmake/scripts/action/_create.lua5
-rw-r--r--xmake/scripts/base/option.lua7
-rw-r--r--xmake/templates/c++/shared_library/_template.lua49
-rw-r--r--xmake/templates/c++/shared_library/project/src/interface.cpp6
-rw-r--r--xmake/templates/c++/shared_library/project/src/interface.h17
-rw-r--r--xmake/templates/c++/shared_library/project/xmake.lua32
-rw-r--r--xmake/templates/c++/static_library/_template.lua49
-rw-r--r--xmake/templates/c++/static_library/project/src/interface.cpp6
-rw-r--r--xmake/templates/c++/static_library/project/src/interface.h16
-rw-r--r--xmake/templates/c++/static_library/project/src/test.cpp10
-rw-r--r--xmake/templates/c++/static_library/project/xmake.lua50
-rw-r--r--xmake/templates/c/shared_library/_template.lua49
-rw-r--r--xmake/templates/c/shared_library/project/src/interface.c6
-rw-r--r--xmake/templates/c/shared_library/project/src/interface.h10
-rw-r--r--xmake/templates/c/shared_library/project/xmake.lua32
-rw-r--r--xmake/templates/c/static_library/_template.lua49
-rw-r--r--xmake/templates/c/static_library/project/src/interface.c6
-rw-r--r--xmake/templates/c/static_library/project/src/interface.h8
-rw-r--r--xmake/templates/c/static_library/project/src/test.c8
-rw-r--r--xmake/templates/c/static_library/project/xmake.lua50
20 files changed, 460 insertions, 5 deletions
diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua
index a49dd4915..5b79301db 100644
--- a/xmake/scripts/action/_create.lua
+++ b/xmake/scripts/action/_create.lua
@@ -115,11 +115,8 @@ end
function _create.menu()
return {
- -- xmake p
- shortname = 'p'
-
-- usage
- , usage = "xmake create|p [options] [target]"
+ usage = "xmake create [options] [target]"
-- description
, description = "Create a new project."
diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua
index 8ad3613c2..96062b4f8 100644
--- a/xmake/scripts/base/option.lua
+++ b/xmake/scripts/base/option.lua
@@ -555,7 +555,12 @@ function option.print_main()
local action_menu = menu[action]
-- init the action info
- local action_info = " " .. utils.ifelse(action_menu and action_menu.shortname, action_menu.shortname .. ", ", " ")
+ local action_info = " "
+ if action_menu and action_menu.shortname then
+ action_info = action_info .. action_menu.shortname .. ", "
+ else
+ action_info = action_info .. " "
+ end
-- append the action
action_info = action_info .. action
diff --git a/xmake/templates/c++/shared_library/_template.lua b/xmake/templates/c++/shared_library/_template.lua
new file mode 100644
index 000000000..7496c94f5
--- /dev/null
+++ b/xmake/templates/c++/shared_library/_template.lua
@@ -0,0 +1,49 @@
+--!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"
+
+-- done the template file
+function _template.done(targetname, projectdir)
+
+ -- check
+ assert(targetname and projectdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/xmake.lua", "%[targetname%]", targetname)
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
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..99b4d38db
--- /dev/null
+++ b/xmake/templates/c++/shared_library/project/src/interface.h
@@ -0,0 +1,17 @@
+#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++/shared_library/project/xmake.lua b/xmake/templates/c++/shared_library/project/xmake.lua
new file mode 100644
index 000000000..2f6742621
--- /dev/null
+++ b/xmake/templates/c++/shared_library/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("shared")
+
+ -- add files
+ add_files("src/*.cpp")
+
diff --git a/xmake/templates/c++/static_library/_template.lua b/xmake/templates/c++/static_library/_template.lua
new file mode 100644
index 000000000..0c9e9e91a
--- /dev/null
+++ b/xmake/templates/c++/static_library/_template.lua
@@ -0,0 +1,49 @@
+--!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"
+
+-- done the template file
+function _template.done(targetname, projectdir)
+
+ -- check
+ assert(targetname and projectdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/xmake.lua", "%[targetname%]", targetname)
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
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/shared_library/_template.lua b/xmake/templates/c/shared_library/_template.lua
new file mode 100644
index 000000000..7496c94f5
--- /dev/null
+++ b/xmake/templates/c/shared_library/_template.lua
@@ -0,0 +1,49 @@
+--!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"
+
+-- done the template file
+function _template.done(targetname, projectdir)
+
+ -- check
+ assert(targetname and projectdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/xmake.lua", "%[targetname%]", targetname)
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
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..0289cd562
--- /dev/null
+++ b/xmake/templates/c/shared_library/project/src/interface.h
@@ -0,0 +1,10 @@
+/*! 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/shared_library/project/xmake.lua b/xmake/templates/c/shared_library/project/xmake.lua
new file mode 100644
index 000000000..07451d4bb
--- /dev/null
+++ b/xmake/templates/c/shared_library/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("shared")
+
+ -- add files
+ add_files("src/*.c")
+
diff --git a/xmake/templates/c/static_library/_template.lua b/xmake/templates/c/static_library/_template.lua
new file mode 100644
index 000000000..0c9e9e91a
--- /dev/null
+++ b/xmake/templates/c/static_library/_template.lua
@@ -0,0 +1,49 @@
+--!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"
+
+-- done the template file
+function _template.done(targetname, projectdir)
+
+ -- check
+ assert(targetname and projectdir)
+
+ -- replace the target name
+ io.gsub(projectdir .. "/xmake.lua", "%[targetname%]", targetname)
+
+ -- ok
+ return true
+end
+
+-- return module: _template
+return _template
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)")
+