diff options
| author | ruki <[email protected]> | 2025-10-28 10:40:15 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-28 10:40:15 +0800 |
| commit | 62493ad179e9b9b981045a7ecc3f82f24403ef8a (patch) | |
| tree | b961c1f56c823cd8d3d964d4be065f825dfa7801 | |
| parent | 961a7f0fe0c630ddc6e56ab192e3035c9479f0fa (diff) | |
| parent | 8b6bbe7302caa5d4aa78c5b6dec1b76659493bac (diff) | |
Merge pull request #6963 from Redbeanw44602/fix/cross-compile-with-libtool
Add libtool patch for cross compile.
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 97 | ||||
| -rw-r--r-- | xmake/scripts/patches/libtool/2.4.3.patch | 40 | ||||
| -rw-r--r-- | xmake/scripts/patches/libtool/2.4.4.patch | 40 | ||||
| -rw-r--r-- | xmake/scripts/patches/libtool/2.4.7.patch | 40 | ||||
| -rw-r--r-- | xmake/scripts/patches/libtool/2.5.0.patch | 40 | ||||
| -rw-r--r-- | xmake/scripts/patches/libtool/2.6.0.patch | 31 |
6 files changed, 288 insertions, 0 deletions
diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 56168fd6b..120467b7d 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -20,10 +20,12 @@ -- imports import("core.base.option") +import("core.base.semver") import("core.project.config") import("core.tool.toolchain") import("core.cache.memcache") import("lib.detect.find_tool") +import("devel.git") import("private.utils.toolchain", {alias = "toolchain_utils"}) -- translate paths @@ -276,6 +278,99 @@ function _get_ldflags_from_packagedeps(package, opt) return result end +-- @see https://github.com/xmake-io/xmake/pull/6963 +function _apply_libtool_patch_for_cross(package, opt) + if not package:is_cross() or not os.isfile("libtool") then + return + end + + -- this patch is only needed for clang-based toolchains + if not package:has_tool("cxx", "clang", "clangxx", "zig_cc") then + return + end + + -- detect the version of generated libtool script + local libtool = io.readfile("libtool") + local libtool_version = libtool:match("macro_version=(%d+%.%d+%.%d+)") + if option.get("verbose") then + if libtool_version then + cprint("${dim}> checking for generated libtool version ... ${color.success} %s", libtool_version) + else + wprint("generated libtool version cannot be detected, the patch for cross-compilation cannot be applied.") + end + end + if libtool_version then + libtool_version = semver.new(libtool_version) + else + return + end + + if not libtool_version:at("2.4.3", "2.6.0") then + return + end + + -- load and parse patch list + local patch_dir = path.join(os.programdir(), "scripts", "patches", "libtool") + local loaded_patch_versions = {} + for _, patch_file in ipairs(os.files(path.join(patch_dir, "*.patch"))) do + local patch_version = path.filename(patch_file):rtrim(".patch") + table.insert(loaded_patch_versions, semver.new(patch_version)) + end + table.sort(loaded_patch_versions) + + -- select the suitable patch + local suitable_patch_versions = {} + local last_patch_version = nil + for _, patch_version in ipairs(loaded_patch_versions) do + if last_patch_version then + if libtool_version:at(last_patch_version, patch_version) then + -- some distributions (such as archlinux) may package the dev + -- version of libtool, in which case the next version of the + -- patch may be applicable. + table.insert(suitable_patch_versions, last_patch_version) + table.insert(suitable_patch_versions, patch_version) + break + end + else + if #loaded_patch_versions == 1 then + if libtool_version:ge(patch_version) then + table.insert(suitable_patch_versions, patch_version) + end + end + end + last_patch_version = patch_version + end + + -- try to apply the suitable patch + local succeed = false + for _, patch_version in ipairs(suitable_patch_versions) do + if option.get("verbose") then + cprint("${dim}> try applying the patch ... ${color.success} >= %s", patch_version) + end + local patch_file = path.join(patch_dir, patch_version:shortstr() .. ".patch") + local result = try { + function () + os.cp("libtool", "__xmake_patched_libtool") + git.apply(patch_file) + os.mv("__xmake_patched_libtool", "libtool") + return true + end + } + if result then + succeed = true + break + end + end + + if option.get("verbose") then + if succeed then + cprint("${dim}> libtool patch for cross-compilation applied successfully") + else + wprint("unable to apply libtool cross-compilation patches, your build files were not modified.") + end + end +end + -- get the build environments function buildenvs(package, opt) opt = opt or {} @@ -584,6 +679,8 @@ function configure(package, configs, opt) -- do configure os.vrunv("./configure", argv, {shell = true, envs = envs}) + + _apply_libtool_patch_for_cross(package, opt) end -- do make diff --git a/xmake/scripts/patches/libtool/2.4.3.patch b/xmake/scripts/patches/libtool/2.4.3.patch new file mode 100644 index 000000000..3283ea39a --- /dev/null +++ b/xmake/scripts/patches/libtool/2.4.3.patch @@ -0,0 +1,40 @@ +--- a/__xmake_patched_libtool ++++ b/__xmake_patched_libtool +@@ -4921,6 +4921,13 @@ func_mode_link () + func_append finalize_command " $wl$qarg" + continue + ;; ++ target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev= ++ continue ++ ;; + *) + eval "$prev=\"\$arg\"" + prev= +@@ -5318,7 +5325,7 @@ func_mode_link () + # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -stdlib=* select c++ std lib with clang + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ +- -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ ++ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*|--target=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result +@@ -5328,6 +5335,14 @@ func_mode_link () + continue + ;; + ++ -target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev=target ++ continue ++ ;; ++ + # Some other compiler flag. + -* | +*) + func_quote_for_eval "$arg" diff --git a/xmake/scripts/patches/libtool/2.4.4.patch b/xmake/scripts/patches/libtool/2.4.4.patch new file mode 100644 index 000000000..d4f72dd33 --- /dev/null +++ b/xmake/scripts/patches/libtool/2.4.4.patch @@ -0,0 +1,40 @@ +--- a/__xmake_patched_libtool ++++ b/__xmake_patched_libtool +@@ -4921,6 +4921,13 @@ func_mode_link () + func_append finalize_command " $wl$qarg" + continue + ;; ++ target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev= ++ continue ++ ;; + *) + eval "$prev=\"\$arg\"" + prev= +@@ -5318,7 +5325,7 @@ func_mode_link () + # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -stdlib=* select c++ std lib with clang + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ +- -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ ++ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*|--target=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result +@@ -5328,6 +5335,14 @@ func_mode_link () + continue + ;; + ++ -target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev=target ++ continue ++ ;; ++ + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options diff --git a/xmake/scripts/patches/libtool/2.4.7.patch b/xmake/scripts/patches/libtool/2.4.7.patch new file mode 100644 index 000000000..c95c4f6d3 --- /dev/null +++ b/xmake/scripts/patches/libtool/2.4.7.patch @@ -0,0 +1,40 @@ +--- a/__xmake_patched_libtool ++++ b/__xmake_patched_libtool +@@ -4921,6 +4921,13 @@ func_mode_link () + func_append finalize_command " $wl$qarg" + continue + ;; ++ target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev= ++ continue ++ ;; + *) + eval "$prev=\"\$arg\"" + prev= +@@ -5318,7 +5325,7 @@ func_mode_link () + # -fuse-ld=* Linker select flags for GCC + # -Wa,* Pass flags directly to the assembler + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ +- -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ ++ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*|--target=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ + -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*) + func_quote_arg pretty "$arg" +@@ -5328,6 +5335,14 @@ func_mode_link () + continue + ;; + ++ -target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev=target ++ continue ++ ;; ++ + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options diff --git a/xmake/scripts/patches/libtool/2.5.0.patch b/xmake/scripts/patches/libtool/2.5.0.patch new file mode 100644 index 000000000..076c8d907 --- /dev/null +++ b/xmake/scripts/patches/libtool/2.5.0.patch @@ -0,0 +1,40 @@ +--- a/__xmake_patched_libtool ++++ b/__xmake_patched_libtool +@@ -4921,6 +4921,13 @@ func_mode_link () + func_append finalize_command " $wl$qarg" + continue + ;; ++ target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev= ++ continue ++ ;; + *) + eval "$prev=\"\$arg\"" + prev= +@@ -5318,7 +5325,7 @@ func_mode_link () + # -Wa,* Pass flags directly to the assembler + # -Werror, -Werror=* Report (specified) warnings as errors + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ +- -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ ++ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*|--target=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \ + -stdlib=*|-rtlib=*|--unwindlib=*| \ + -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \ +@@ -5328,6 +5335,14 @@ func_mode_link () + continue + ;; + ++ -target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev=target ++ continue ++ ;; ++ + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options diff --git a/xmake/scripts/patches/libtool/2.6.0.patch b/xmake/scripts/patches/libtool/2.6.0.patch new file mode 100644 index 000000000..3c2aa17e6 --- /dev/null +++ b/xmake/scripts/patches/libtool/2.6.0.patch @@ -0,0 +1,31 @@ +--- a/__xmake_patched_libtool ++++ b/__xmake_patched_libtool +@@ -4921,6 +4921,13 @@ func_mode_link () + func_append finalize_command " $wl$qarg" + continue + ;; ++ target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev= ++ continue ++ ;; + *) + eval "$prev=\"\$arg\"" + prev= +@@ -5328,6 +5335,14 @@ func_mode_link () + continue + ;; + ++ -target) ++ func_append compile_command " $arg" ++ func_append finalize_command " $arg" ++ func_append compiler_flags " $arg" ++ prev=target ++ continue ++ ;; ++ + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options |
