diff options
| author | ruki <[email protected]> | 2021-09-04 23:43:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-04 23:43:32 +0800 |
| commit | b54c309384c334c265072e15a23692e52f11b0b7 (patch) | |
| tree | d78d70c0f2ba313943babc1717e8b3b5a75a07a4 | |
| parent | feefe1dce66ea47e4a968887fbcb81cb0f9caf33 (diff) | |
improve merge lib for ar
| -rw-r--r-- | tests/projects/other/merge_archive2/src/main.c | 17 | ||||
| -rw-r--r-- | tests/projects/other/merge_archive2/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/utils/archive/merge_staticlib.lua | 12 | ||||
| -rw-r--r-- | xmake/rules/utils/merge_archive/xmake.lua | 3 |
4 files changed, 33 insertions, 2 deletions
diff --git a/tests/projects/other/merge_archive2/src/main.c b/tests/projects/other/merge_archive2/src/main.c new file mode 100644 index 000000000..927c9173e --- /dev/null +++ b/tests/projects/other/merge_archive2/src/main.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +int add(int a, int b); +int sub(int a, int b); +int mul(int a, int b); +int subdir_add(int a, int b); +int subdir_sub(int a, int b); + +int main(int argc, char** argv) +{ + printf("%d\n", add(1, 1)); + printf("%d\n", sub(1, 1)); + printf("%d\n", mul(1, 1)); + printf("%d\n", subdir_add(1, 1)); + printf("%d\n", subdir_sub(1, 1)); + return 0; +} diff --git a/tests/projects/other/merge_archive2/xmake.lua b/tests/projects/other/merge_archive2/xmake.lua index eb23dd859..be1f45de0 100644 --- a/tests/projects/other/merge_archive2/xmake.lua +++ b/tests/projects/other/merge_archive2/xmake.lua @@ -16,3 +16,6 @@ target("mul") add_files("src/mul.c") set_policy("build.merge_archive", true) +target("test") + add_deps("mul") + add_files("src/main.c") diff --git a/xmake/modules/utils/archive/merge_staticlib.lua b/xmake/modules/utils/archive/merge_staticlib.lua index b5adbd98f..cbafa4bdb 100644 --- a/xmake/modules/utils/archive/merge_staticlib.lua +++ b/xmake/modules/utils/archive/merge_staticlib.lua @@ -27,7 +27,17 @@ function _merge_for_ar(target, program, outputfile, libraryfiles, opt) if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then os.vrunv("libtool", table.join("-static", "-o", outputfile, libraryfiles)) else - os.vrunv(program, table.join("crsT", outputfile, libraryfiles)) + local tmpfile = os.tmpfile() + local mrifile = io.open(tmpfile, "w") + mrifile:print("create %s", outputfile) + for _, libraryfile in ipairs(libraryfiles) do + mrifile:print("addlib %s", libraryfile) + end + mrifile:print("save") + mrifile:print("end") + mrifile:close() + os.vrunv(program, {"-M"}, {stdin = tmpfile}) + os.rm(tmpfile) end end diff --git a/xmake/rules/utils/merge_archive/xmake.lua b/xmake/rules/utils/merge_archive/xmake.lua index 63c947d08..62e3900ff 100644 --- a/xmake/rules/utils/merge_archive/xmake.lua +++ b/xmake/rules/utils/merge_archive/xmake.lua @@ -40,7 +40,8 @@ rule("utils.merge.archive") if #libraryfiles > 0 then local tmpfile = os.tmpfile() .. path.extension(target:targetfile()) merge_staticlib(target, tmpfile, libraryfiles) - os.mv(tmpfile, target:targetfile()) + os.cp(tmpfile, target:targetfile()) + os.rm(tmpfile) end end, {dependfile = target:dependfile(target:targetfile() .. ".merge_archive"), files = libraryfiles}) end |
