diff --git a/packages/g/gmp/patches/6.3.0/gmp-gcc-15.patch b/packages/g/gmp/patches/6.3.0/c23.patch similarity index 54% rename from packages/g/gmp/patches/6.3.0/gmp-gcc-15.patch rename to packages/g/gmp/patches/6.3.0/c23.patch index ba67e810319..40631a9c6f6 100644 --- a/packages/g/gmp/patches/6.3.0/gmp-gcc-15.patch +++ b/packages/g/gmp/patches/6.3.0/c23.patch @@ -1,12 +1,13 @@ ---- configure -+++ configure -@@ -6568,7 +6568,7 @@ - +diff --git a/configure b/configure +index 3782fa43..79aeac9e 100644 +--- a/configure ++++ b/configure +@@ -6568,7 +6568,7 @@ if test "$gmp_prog_cc_works" = yes; then + #if defined (__GNUC__) && ! defined (__cplusplus) typedef unsigned long long t1;typedef t1*t2; -void g(){} -+void g(int a,t1 const* b,t1 c,t2 d,t1 const* e,int f){} ++void g(int,t1 const*,t1,t2,t1 const*,int){} void h(){} static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0) {t1 c,x,r;int i;if(v0){c=1;for(i=1;i yasm, arm64 -> clang + if package:is_arch("x64", "x86") then + package:add("deps", "yasm") + end + + package:add("defines", "__GMP_WITHIN_CONFIGURE") + if package:is_arch("x64", "arm64") then + package:add("defines", "_LONG_LONG_LIMB") -- mp_limb_t type + end + -- if package:config("shared") then + -- package:add("defines", "__GMP_LIBGMP_DLL") + -- end + end + end) + + on_install("!wasm and (!android or android@!windows)", function (package) + import("package.tools.autoconf") + import("lib.detect.find_tool") - on_install("@!windows and !wasm", function (package) + -- ref https://github.com/microsoft/vcpkg/blob/4ed84798137bcf664989fa432d41d278d7ad3b25/ports/gmp/subdirs.patch + io.replace("Makefile.am", + "SUBDIRS = tests mpn mpz mpq mpf printf scanf rand cxx demos tune doc", + "SUBDIRS = mpn mpz mpq mpf printf scanf rand cxx tune", {plain = true}) if is_host("windows") then io.replace("configure", "LIBTOOL='$(SHELL) $(top_builddir)/libtool'", "LIBTOOL='\"$(SHELL)\" $(top_builddir)/libtool'", {plain = true}) end + if package:is_plat("windows") then + local obj_file_suffix = package:has_tool("cxx", "cl") and ".obj" or ".o" + io.replace("configure", "$CCAS $CFLAGS $CPPFLAGS", "$CCAS $CCASFLAGS -o conftest" .. obj_file_suffix, {plain = true}) + -- Remove error flags for asm build + io.replace("mpn/Makefile.in", "$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASMFLAGS)", "$(AM_CFLAGS) ${CCASFLAGS}", {plain = true}) + if package:has_tool("ld", "link") then + -- `lib /out: xxx` -> `lib /out:xxx` + io.replace("configure", "$AR $AR_FLAGS ", "$AR $AR_FLAGS", {plain = true}) + end + if package:config("shared") then + -- error: duplicate symbol: __gmpn_add + io.replace("gmp-h.in", "#define __GMP_EXTERN_INLINE __inline", "#define __GMP_EXTERN_INLINE static __inline", {plain = true}) + -- export symbol macro + io.replace("gmp-h.in", "#define __GMP_LIBGMP_DLL @LIBGMP_DLL@", "#define __GMP_LIBGMP_DLL 1", {plain = true}) + end + end + local configs = {} table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no")) table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes")) - if package:debug() then + table.insert(configs, "--enable-cxx=" .. (package:config("cpp_api") and "yes" or "no")) + table.insert(configs, "--enable-assembly=" .. (package:config("assembly") and "yes" or "no")) + table.insert(configs, "--enable-fat=" .. (package:config("fat") and "yes" or "no")) + if package:is_debug() then table.insert(configs, "--enable-debug") end - if package:config("pic") ~= false then + if not package:is_plat("windows") and package:config("pic") ~= false then table.insert(configs, "--with-pic") end + + local opt = {} if package:is_plat("macosx") and package:is_arch("arm64") and os.arch() == "x86_64" then - import("package.tools.autoconf") table.insert(configs, "--build=x86_64-apple-darwin") table.insert(configs, "--host=arm64-apple-darwin") - local envs = autoconf.buildenvs(package, {cflags = "--target=arm64-apple-darwin"}) - envs.CC = package:build_getenv("cc") .. " -arch arm64" -- for linker flags - autoconf.install(package, configs, {envs = envs}) + opt.envs = autoconf.buildenvs(package, {cflags = "--target=arm64-apple-darwin"}) + opt.envs.CC = package:build_getenv("cc") .. " -arch arm64" -- for linker flags + elseif package:is_plat("windows") then + local msvc = package:toolchain("msvc") or package:toolchain("clang") or package:toolchain("clang-cl") + assert(msvc:check(), "msvs not found!") + -- buildenvs maybe missing deps bin dir + opt.envs = os.joinenvs(os.joinenvs(msvc:runenvs()), autoconf.buildenvs(package)) + if package:has_tool("cxx", "cl") then + opt.envs.CC = "cl -nologo" + opt.envs.CXX = "cl -nologo" + opt.envs.AR = "lib -nologo" + opt.envs.LD = "link -nologo" + opt.envs.NM = "dumpbin -nologo -symbols" + opt.envs.AR_FLAGS = "-out:" -- override `cq` flag + table.insert(configs, "gmp_cv_asm_w32=.word") -- fix detect + elseif package:has_tool("cxx", "clang") then + local suffix = opt.envs.CC:split("-") + if #suffix > 1 then + suffix = "-" .. suffix[#suffix] + else + suffix = "" + end + opt.envs.NM = "llvm-nm" .. suffix + opt.envs.LDFLAGS = opt.envs.LDFLAGS:gsub("-nostdlib", "") + if package:is_cross() then + -- require -fuse-ld=lld-link + opt.envs.CFLAGS = opt.envs.CFLAGS .. " " .. opt.envs.LDFLAGS + opt.envs.CXXFLAGS = opt.envs.CXXFLAGS .. " " .. opt.envs.LDFLAGS + end + end + -- Maybe missing ucrt flags + opt.envs.CFLAGS = opt.envs.CFLAGS .. " " .. opt.envs.CXXFLAGS + -- Fix mp_limb_t + -- msvc sizeof long == 4 unmatch gcc sizeof long == 8 + if package:is_arch("x64", "arm64") then + opt.envs.CFLAGS = opt.envs.CFLAGS .. " -D_LONG_LONG_LIMB" + opt.envs.CXXFLAGS = opt.envs.CXXFLAGS .. " -D_LONG_LONG_LIMB" + end + + local clang_archs = { + ["x86"] = "i686", + ["x64"] = "x86_64", + ["arm64"] = "aarch64", + } + local target = clang_archs[package:arch()] .. "-windows-msvc" + if package:is_arch("x64", "x86") then + local yasm_machine = { + ["x86"] = "x86", + ["x64"] = "amd64", + } + local yasm_format = { + ["x86"] = "win32", + ["x64"] = "win64", + } + opt.envs.CCAS = "yasm" + opt.envs.CCASFLAGS = format("-a x86 -m %s -p gas -r raw -f %s -g null -X gnu", yasm_machine[package:arch()], yasm_format[package:arch()]) + elseif package:is_arch("arm64") then + if package:has_tool("cxx", "clang") then + opt.envs.CCAS = opt.envs.CC + else + local llvm_nm = assert(find_tool("llvm-nm"), "windows arm64 require llvm-nm to detect") + local clang = assert(find_tool("clang"), "windows arm64 require clang to build asm") + opt.envs.CCAS = path.unix(clang.program) + opt.envs.NM = path.unix(llvm_nm.program) + end + opt.envs.CCASFLAGS = table.concat({"--target=" .. target, "-c"}, " ") + end + table.insert(configs, "--host=" .. target) + end + -- Can't generate correct gmp.lib with lib.exe + if package:is_plat("windows") then + autoconf.build(package, configs, opt) + + io.writefile("xmake.lua", [[ + option("cpp_api", {default = false}) + add_rules("mode.debug", "mode.release") + target("gmp") + set_kind("$(kind)") + add_rules("c++") + add_files("**.obj|gen-*.obj|cxx/*.obj", "**.o|gen-*.o|cxx/*.o") + remove_files("dummy.obj") -- I don't know why, it only happen on ci + add_headerfiles("gmp.h") + if has_config("cpp_api") then + target("gmpxx") + set_kind("$(kind)") + add_rules("c++") + add_files("cxx/*.obj", "cxx/*.o") + add_headerfiles("gmpxx.h") + add_deps("gmp") + end + ]]) + import("package.tools.xmake").install(package, {cpp_api = package:config("cpp_api")}) else - import("package.tools.autoconf").install(package, configs) + autoconf.install(package, configs, opt) end end)