From 0d64f4f3cc21baea3aef7dc42cb486e48c92589e Mon Sep 17 00:00:00 2001 From: star9029 Date: Tue, 17 Dec 2024 20:29:49 +0800 Subject: [PATCH 1/3] glpk: improve windows build --- packages/g/glpk/port/xmake.lua | 34 ++++++++++++++++++++++++++++++++++ packages/g/glpk/xmake.lua | 33 +++++++++++++++------------------ 2 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 packages/g/glpk/port/xmake.lua diff --git a/packages/g/glpk/port/xmake.lua b/packages/g/glpk/port/xmake.lua new file mode 100644 index 00000000000..576a78d0093 --- /dev/null +++ b/packages/g/glpk/port/xmake.lua @@ -0,0 +1,34 @@ +add_rules("mode.debug", "mode.release") + +add_requires("zlib") + +target("glpk") + set_kind("$(kind)") + add_files("src/**.c|zlib/*.c") + add_includedirs( + "src", + "src/amd", + "src/api", + "src/bflib", + "src/colamd", + "src/draft", + "src/env", + "src/intopt", + "src/minisat", + "src/misc", + "src/mpl", + "src/npp", + "src/simplex" + ) + + if is_kind("shared") then + add_files("*.def") + end + + if is_plat("windows") then + add_defines("__WOE__=1") + end + + add_packages("zlib") + + add_headerfiles("src/glpk.h") diff --git a/packages/g/glpk/xmake.lua b/packages/g/glpk/xmake.lua index 73face3fbed..36921e16ebc 100644 --- a/packages/g/glpk/xmake.lua +++ b/packages/g/glpk/xmake.lua @@ -11,32 +11,29 @@ package("glpk") add_extsources("apt::libglpk-dev") end - on_install("macosx|x86_64", "linux", function (package) + add_deps("zlib") + + on_install("macosx", "linux", function (package) 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")) import("package.tools.autoconf").install(package, configs) end) - on_install("windows", function (package) - os.cd("w64") -- Makefiles are the same in w64 and w32 directory - os.cp("config_VC", "config.h") - local version = package:version() - local basename = string.format("glpk_%d_%d", version:major(), version:minor()) - -- glp_netgen_prob is not defined, but should be disabled - -- see: https://www.mail-archive.com/bug-glpk@gnu.org/msg01020.html - io.replace(basename .. ".def", "glp_netgen_prob\n", "", {plain = true}) - import("package.tools.nmake").build(package, {"/f", package:config("shared") and "makefile_VC_DLL" or "makefile_VC"}) - - if package:config("shared") then - os.cp(basename .. ".dll", package:installdir("bin")) - os.cp(basename .. ".lib", package:installdir("lib")) - else - os.cp("glpk.lib", package:installdir("lib")) + on_install(function (package) + if package:is_plat("windows") and package:config("shared") then + local def = "glpk.def" + local version = package:version() + local arch_dir = package:is_arch64() and "w64" or "w32" + local basename = format("%s/glpk_%d_%d.def", arch_dir, version:major(), version:minor()) + os.vcp(basename, def) + -- glp_netgen_prob is not defined, but should be disabled + -- see: https://www.mail-archive.com/bug-glpk@gnu.org/msg01020.html + io.replace(def, "glp_netgen_prob\n", "", {plain = true}) end - os.cd("..") - os.cp("src/glpk.h", package:installdir("include")) + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + import("package.tools.xmake").install(package, configs) end) on_test(function (package) From 1b7eb84a8e45e028649936c33018ddd536b8609c Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 18 Dec 2024 01:12:47 +0800 Subject: [PATCH 2/3] support dl & gmp --- packages/g/glpk/port/xmake.lua | 45 ++++++++++++++++++++++++++-- packages/g/glpk/xmake.lua | 55 ++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/packages/g/glpk/port/xmake.lua b/packages/g/glpk/port/xmake.lua index 576a78d0093..8286845a82e 100644 --- a/packages/g/glpk/port/xmake.lua +++ b/packages/g/glpk/port/xmake.lua @@ -1,12 +1,46 @@ +option("dl", {default = nil, type = "string", values = {"ltdl", "dlfcn"}}) +option("gmp", {default = false}) +option("mysql", {default = false}) +option("odbc", {default = false}) + add_rules("mode.debug", "mode.release") add_requires("zlib") +local dl = get_config("dl") +if dl == "ltdl" then + add_requires("libtool", {kind = "library"}) + add_packages("libtool") + add_defines("HAVE_LTDL") +elseif dl == "dlfcn" then + if is_plat("linux", "bsd") then + add_syslinks("dl") + end + add_defines("HAVE_DLFCN") +end + +if has_config("gmp") then + add_requires("gmp") + add_packages("gmp") + add_defines("HAVE_GMP") +end + +if has_config("mysql") then + add_requires("mysql") + -- TODO + -- add_defines("MYSQL_DLNAME=" .. mysql shared link name) +end + +includes("@builtin/check") + +configvar_check_cincludes("HAVE_SYS_TIME_H", "sys/time.h") +configvar_check_cfuncs("HAVE_GETTIMEOFDAY", "gettimeofday", {includes = "time.h"}) + target("glpk") set_kind("$(kind)") add_files("src/**.c|zlib/*.c") + add_includedirs("src", {public = true}) add_includedirs( - "src", "src/amd", "src/api", "src/bflib", @@ -25,10 +59,15 @@ target("glpk") add_files("*.def") end - if is_plat("windows") then - add_defines("__WOE__=1") + if is_plat("windows", "mingw", "msys") then + add_defines("__WOE__=1", "TLS=__declspec(thread)") end add_packages("zlib") add_headerfiles("src/glpk.h") + +target("glpsol") + set_kind("binary") + add_files("examples/glpsol.c") + add_deps("glpk") diff --git a/packages/g/glpk/xmake.lua b/packages/g/glpk/xmake.lua index 36921e16ebc..5abbf9183c9 100644 --- a/packages/g/glpk/xmake.lua +++ b/packages/g/glpk/xmake.lua @@ -7,17 +7,36 @@ package("glpk") add_versions("5.0", "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15") + add_configs("dl", {description = "Eenable shared library support", default = nil, type = "string", values = {"ltdl", "dlfcn"}}) + add_configs("gmp", {description = "Enable gmp support", default = false, type = "boolean"}) + add_configs("mysql", {description = "enable MathProg MySQL support", default = false, type = "boolean", readonly = true}) + add_configs("odbc", {description = "enable MathProg ODBC support", default = false, type = "boolean", readonly = true}) + if is_plat("linux") then add_extsources("apt::libglpk-dev") end add_deps("zlib") - on_install("macosx", "linux", function (package) - 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")) - import("package.tools.autoconf").install(package, configs) + on_load(function (package) + if package:config("gmp") then + package:add("deps", "gmp") + end + if package:config("mysql") then + package:add("deps", "mysql") + end + local dl = package:config("dl") + if dl == "ltdl" then + package:add("deps", "libtool", {kind = "library"}) + elseif dl == "dlfcn" then + if package:is_plat("linux", "bsd") then + package:add("syslinks", "dl") + end + -- src/env/dlsup.c will use LoadLibrary/GetProcAddress/FreeLibrary + -- if package:is_plat("windows") then + -- package:add("deps", "dlfcn-win32") + -- end + end end) on_install(function (package) @@ -32,10 +51,36 @@ package("glpk") io.replace(def, "glp_netgen_prob\n", "", {plain = true}) end + local configs = { + dl = package:config("dl"), + gmp = package:config("gmp"), + mysql = package:config("mysql"), + odbc = package:config("odbc"), + } os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") import("package.tools.xmake").install(package, configs) end) + on_install("macosx", "linux", function (package) + 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")) + table.insert(configs, "--enable-mysql=" .. (package:config("mysql") and "yes" or "no")) + table.insert(configs, "--enable-odbc=" .. (package:config("odbc") and "yes" or "no")) + local dl = package:config("dl") + if dl then + table.insert(configs, "--enable-dl=" .. dl) + else + table.insert(configs, "--disable-dl") + end + if package:config("gmp") then + table.insert(configs, "--with-gmp") + else + table.insert(configs, "--without-gmp") + end + import("package.tools.autoconf").install(package, configs) + end) + on_test(function (package) assert(package:check_cxxsnippets({test = [[ #include From 10c4435ffb058138e2a8526daa00b831f75bedbc Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 18 Dec 2024 22:53:07 +0800 Subject: [PATCH 3/3] fix wasm --- packages/g/glpk/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/g/glpk/xmake.lua b/packages/g/glpk/xmake.lua index 5abbf9183c9..052daf4f03e 100644 --- a/packages/g/glpk/xmake.lua +++ b/packages/g/glpk/xmake.lua @@ -11,6 +11,9 @@ package("glpk") add_configs("gmp", {description = "Enable gmp support", default = false, type = "boolean"}) add_configs("mysql", {description = "enable MathProg MySQL support", default = false, type = "boolean", readonly = true}) add_configs("odbc", {description = "enable MathProg ODBC support", default = false, type = "boolean", readonly = true}) + if is_plat("wasm") then + add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) + end if is_plat("linux") then add_extsources("apt::libglpk-dev")