Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glpk: improve build #5999

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions packages/g/glpk/port/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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/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", "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")
87 changes: 66 additions & 21 deletions packages/g/glpk/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,81 @@ 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("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")
end

on_install("macosx|x86_64", "linux", function (package)
add_deps("zlib")

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)
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/[email protected]/msg01020.html
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"))
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/[email protected]/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"))
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
os.cp("glpk.lib", package:installdir("lib"))
table.insert(configs, "--disable-dl")
end

os.cd("..")
os.cp("src/glpk.h", package:installdir("include"))
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)
Expand Down
Loading