diff options
| author | ruki <[email protected]> | 2026-03-02 23:52:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-02 23:52:25 +0800 |
| commit | b01dcb775c98cc48abe65a91ef9bf093be875682 (patch) | |
| tree | aef3e65981edc5506f9d20197be0892ce2957ba1 /xmake/templates/c/module | |
| parent | 3c1e3d746b7cc0a1a5dec9448a72a13bfe30f246 (diff) | |
improve template dirs
Diffstat (limited to 'xmake/templates/c/module')
12 files changed, 122 insertions, 0 deletions
diff --git a/xmake/templates/c/module/binary/.gitignore b/xmake/templates/c/module/binary/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c/module/binary/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c/module/binary/modules/binary/bar/.gitignore b/xmake/templates/c/module/binary/modules/binary/bar/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c/module/binary/modules/binary/bar/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c/module/binary/modules/binary/bar/src/add.c b/xmake/templates/c/module/binary/modules/binary/bar/src/add.c new file mode 100644 index 000000000..93fdf0ad8 --- /dev/null +++ b/xmake/templates/c/module/binary/modules/binary/bar/src/add.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a + b); + return 0; +} diff --git a/xmake/templates/c/module/binary/modules/binary/bar/src/sub.c b/xmake/templates/c/module/binary/modules/binary/bar/src/sub.c new file mode 100644 index 000000000..ae7b6d1f2 --- /dev/null +++ b/xmake/templates/c/module/binary/modules/binary/bar/src/sub.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a - b); + return 0; +} diff --git a/xmake/templates/c/module/binary/modules/binary/bar/xmake.lua b/xmake/templates/c/module/binary/modules/binary/bar/xmake.lua new file mode 100644 index 000000000..d4983d741 --- /dev/null +++ b/xmake/templates/c/module/binary/modules/binary/bar/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("add") + add_rules("module.binary") + add_files("src/add.c") + +target("sub") + add_rules("module.binary") + add_files("src/sub.c") + diff --git a/xmake/templates/c/module/binary/src/main.c b/xmake/templates/c/module/binary/src/main.c new file mode 100644 index 000000000..ccf4b2a77 --- /dev/null +++ b/xmake/templates/c/module/binary/src/main.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char **argv) { + printf("hello world!\n"); + return 0; +} diff --git a/xmake/templates/c/module/binary/xmake.lua b/xmake/templates/c/module/binary/xmake.lua new file mode 100644 index 000000000..7df556cb8 --- /dev/null +++ b/xmake/templates/c/module/binary/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.c") + on_config(function (target) + import("binary.bar") + print("binary: 1 + 1 = %s", bar.add(1, 1)) + print("binary: 1 - 1 = %s", bar.sub(1, 1)) + end) + +${FAQ} + diff --git a/xmake/templates/c/module/shared/.gitignore b/xmake/templates/c/module/shared/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c/module/shared/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c/module/shared/modules/shared/foo/src/foo.c b/xmake/templates/c/module/shared/modules/shared/foo/src/foo.c new file mode 100644 index 000000000..adde214ca --- /dev/null +++ b/xmake/templates/c/module/shared/modules/shared/foo/src/foo.c @@ -0,0 +1,22 @@ +#include <xmi.h> + +static int add(lua_State *lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a + b); + return 1; +} + +static int sub(lua_State *lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a - b); + return 1; +} + +int luaopen(foo, lua_State *lua) { + static const luaL_Reg funcs[] = { { "add", add }, { "sub", sub }, { NULL, NULL } }; + lua_newtable(lua); + luaL_setfuncs(lua, funcs, 0); + return 1; +} diff --git a/xmake/templates/c/module/shared/modules/shared/foo/xmake.lua b/xmake/templates/c/module/shared/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..035573d9f --- /dev/null +++ b/xmake/templates/c/module/shared/modules/shared/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + add_rules("module.shared") + add_files("src/foo.c") + diff --git a/xmake/templates/c/module/shared/src/main.c b/xmake/templates/c/module/shared/src/main.c new file mode 100644 index 000000000..ccf4b2a77 --- /dev/null +++ b/xmake/templates/c/module/shared/src/main.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char **argv) { + printf("hello world!\n"); + return 0; +} diff --git a/xmake/templates/c/module/shared/xmake.lua b/xmake/templates/c/module/shared/xmake.lua new file mode 100644 index 000000000..4b92b0b9e --- /dev/null +++ b/xmake/templates/c/module/shared/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.c") + on_config(function (target) + import("shared.foo") + print("shared: 1 + 1 = %s", foo.add(1, 1)) + print("shared: 1 - 1 = %s", foo.sub(1, 1)) + end) + +${FAQ} + |
