Skip to content

Commit 6fbbd5d

Browse files
committed
libqalculate: add package
1 parent 9c11b99 commit 6fbbd5d

File tree

6 files changed

+205
-8
lines changed

6 files changed

+205
-8
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
add_rules("mode.debug", "mode.release")
2+
add_requires("libcurl", "gmp", "icu4c", "mpfr", "readline", "libxml2")
3+
add_packages("libcurl", "gmp", "icu4c", "mpfr", "readline", "libxml2")
4+
add_includedirs(".", "libqalculate")
5+
set_languages("c++17") -- Use C++17 to avoid template syntax issues with nested angle brackets for Apple Clang
6+
7+
includes("@builtin/check")
8+
check_cxxincludes("HAVE_UNORDERED_MAP", "unordered_map")
9+
check_cincludes("HAVE_PTHREADS", "pthread.h")
10+
check_cincludes("HAVE_STDIO_H", "stdio.h")
11+
check_cfuncs("HAVE_PIPE2", "pipe2", {includes = {"unistd.h", "fcntl.h"}})
12+
-- External dependencies
13+
-- check_cincludes("HAVE_ICONV", "iconv.h")
14+
check_cincludes("HAVE_ICU", "unicode/ucasemap.h")
15+
check_cincludes("HAVE_LIBCURL", "curl/curl.h")
16+
check_cincludes("HAVE_LIBREADLINE", {"stdio.h", "readline/readline.h"})
17+
-- Check if 'int_n_cs_precedes' is a member of 'struct lconv'
18+
-- check_csnippets("HAVE_STRUCT_LCONV_INT_N_CS_PRECEDES", [[
19+
-- #include <locale.h>
20+
-- void* test(void) {
21+
-- return &((struct lconv *)0)->int_n_cs_precedes;
22+
-- }
23+
-- ]])
24+
-- check_csnippets("HAVE_STRUCT_LCONV_INT_P_CS_PRECEDES", [[
25+
-- #include <locale.h>
26+
-- void* test(void) {
27+
-- return &((struct lconv *)0)->int_p_cs_precedes;
28+
-- }
29+
-- ]])
30+
-- -- Define "ICONV_CONST" as "const" if the declaration of iconv() needs const.
31+
-- option("iconv_not_need_const")
32+
-- add_csnippets("iconv_const", [[
33+
-- #include <iconv.h>
34+
-- #include <string.h>
35+
36+
-- #ifndef ICONV_CONST
37+
-- # define ICONV_CONST
38+
-- #endif
39+
-- int main(int argc, char **argv) {
40+
-- int result = 0;
41+
-- /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
42+
-- returns. */
43+
-- iconv_t cd_utf8_to_88591 = iconv_open("ISO8859-1", "UTF-8");
44+
-- if (cd_utf8_to_88591 != (iconv_t)(-1)) {
45+
-- static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
46+
-- char buf[10];
47+
-- ICONV_CONST char *inptr = input;
48+
-- size_t inbytesleft = strlen(input);
49+
-- char *outptr = buf;
50+
-- size_t outbytesleft = sizeof(buf);
51+
-- size_t res = iconv(cd_utf8_to_88591,
52+
-- &inptr, &inbytesleft,
53+
-- &outptr, &outbytesleft);
54+
-- if (res == 0)
55+
-- result |= 1;
56+
-- iconv_close(cd_utf8_to_88591);
57+
-- }
58+
-- return result;
59+
-- }
60+
-- ]])
61+
-- option_end()
62+
-- if get_config("iconv_not_need_const") then
63+
-- add_defines("ICONV_CONST=")
64+
-- else
65+
-- add_defines("ICONV_CONST=const")
66+
-- end
67+
68+
option("version", {default = "0.0.1"})
69+
local version = get_config("version")
70+
if version then
71+
add_defines("VERSION=\"" .. version .. "\"")
72+
end
73+
74+
target("libqalculate") -- Expect `libqalculate.pc` to be generated
75+
set_basename("qalculate")
76+
set_kind("$(kind)")
77+
add_headerfiles("(libqalculate/BuiltinFunctions.h)",
78+
"(libqalculate/Calculator.h)",
79+
"(libqalculate/DataSet.h)",
80+
"(libqalculate/ExpressionItem.h)",
81+
"(libqalculate/Function.h)",
82+
"(libqalculate/MathStructure.h)",
83+
"(libqalculate/Number.h)",
84+
"(libqalculate/Prefix.h)",
85+
"(libqalculate/QalculateDateTime.h)",
86+
"(libqalculate/Unit.h)",
87+
"(libqalculate/Variable.h)",
88+
"(libqalculate/includes.h)",
89+
"(libqalculate/qalculate.h)",
90+
"(libqalculate/util.h)")
91+
add_files("libqalculate/*.cc")
92+
93+
target("qalc")
94+
set_kind("binary")
95+
add_files("src/qalc.cc")
96+
add_deps("libqalculate")

packages/l/libqalculate/xmake.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package("libqalculate")
2+
set_homepage("https://qalculate.github.io/")
3+
set_description("Qalculate! is a multi-purpose cross-platform desktop calculator.")
4+
set_license("GPL-2.0")
5+
6+
add_urls("https://github.com/Qalculate/libqalculate/archive/refs/tags/$(version).tar.gz",
7+
"https://github.com/Qalculate/libqalculate.git")
8+
9+
add_versions("v5.5.2", "3b8f65583779fb584a0e2fa7be95bfcc8a7e71e8e4d2ba64f00856640d32b805")
10+
11+
if is_plat("linux") then
12+
add_extsources("apt::libqalculate-dev")
13+
end
14+
15+
add_deps("libcurl", "gmp", "icu4c", "mpfr", "readline", "libxml2")
16+
17+
on_install("linux", "macosx", "mingw", function (package)
18+
io.replace("libqalculate/util.cc", "PACKAGE_DATA_DIR", '"' .. package:installdir("share") .. '"', {plain = true})
19+
io.replace("libqalculate/util.cc", "PACKAGE_LOCALE_DIR", '"' .. package:installdir("share", "locale") .. '"', {plain = true})
20+
if package:is_plat("mingw") then
21+
local src_files = {"libqalculate/MathStructure-print.cc", "libqalculate/Number.cc", "src/qalc.cc"}
22+
for _, src_file in ipairs(src_files) do
23+
io.replace(src_file, "#%s*include%s*<VersionHelpers.h>", "# include <versionhelpers.h>")
24+
end
25+
end
26+
local version = try { function() return io.readfile("configure.ac"):match("AC_INIT%(([%d%.]+)") end }
27+
version = version or (package:version() and package:version_str():gsub("^v", ""))
28+
local configs = {version = version}
29+
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
30+
import("package.tools.xmake").install(package, configs)
31+
if not package:is_cross() then
32+
package:addenv("PATH", "bin")
33+
end
34+
end)
35+
36+
on_test(function (package)
37+
assert(package:check_cxxsnippets({test = [[
38+
void test() {
39+
Calculator calc;
40+
calc.calculate("1+1");
41+
}
42+
]]}, {includes = "libqalculate/Calculator.h"}))
43+
if not package:is_cross() then
44+
os.vrunv("qalc", {"-version"})
45+
end
46+
end)

packages/m/mpfr/xmake.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ package("mpfr")
1616
add_extsources("brew::mpfr")
1717
end
1818

19-
add_deps("gmp")
20-
on_install("macosx", "linux", function (package)
19+
on_load(function (package)
20+
package:add("deps", "gmp", { configs = {shared = package:config("shared")} })
21+
end)
22+
23+
on_install("@!windows and !wasm", function (package)
2124
local configs = {"--disable-dependency-tracking"}
2225
table.insert(configs, "--with-gmp=" .. package:dep("gmp"):installdir())
2326
if package:config("shared") then

packages/n/ncurses/xmake.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ package("ncurses")
2020
end
2121

2222
on_load(function (package)
23+
if package:is_cross() then
24+
package:add("deps", "ncurses~host", {kind = "binary", private = true})
25+
end
2326
if package:config("widec") then
2427
package:add("links", "ncursesw", "formw", "panelw", "menuw")
2528
package:add("includedirs", "include/ncursesw", "include")
@@ -33,19 +36,30 @@ package("ncurses")
3336
end
3437
end)
3538

36-
on_install("linux", "macosx", "bsd", "msys", function (package)
39+
on_install("linux", "macosx", "bsd", "msys", "mingw", function (package)
3740
local configs = {
3841
"--without-manpages",
3942
"--enable-sigwinch",
4043
"--with-gpm=no",
4144
"--without-tests",
4245
"--without-ada",
4346
}
47+
if package:is_cross() then
48+
local tic = package:dep("ncurses"):installdir("bin", "tic" .. (is_host("windows") and ".exe" or ""))
49+
if os.isfile(tic) then
50+
table.insert(configs, "--with-tic-path=" .. path:unix(tic))
51+
end
52+
end
53+
local cxflags = {}
54+
if package:is_plat("msys", "mingw") then
55+
table.insert(cxflags, "-D__USE_MINGW_ACCESS")
56+
table.insert(configs, "--enable-term-driver")
57+
end
4458

4559
table.insert(configs, "--with-debug=" .. (package:is_debug() and "yes" or "no"))
4660
table.insert(configs, "--with-shared=" .. (package:config("shared") and "yes" or "no"))
4761
table.insert(configs, "--enable-widec=" .. (package:config("widec") and "yes" or "no"))
48-
import("package.tools.autoconf").install(package, configs, {arflags = {"-curvU"}})
62+
import("package.tools.autoconf").install(package, configs, {arflags = {"-curvU"}, cxflags = cxflags})
4963
end)
5064

5165
on_test(function (package)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/input.c b/input.c
2+
index 6f038d4..da4da45 100644
3+
--- a/input.c
4+
+++ b/input.c
5+
@@ -818,7 +820,7 @@ rl_getc (FILE *stream)
6+
/* We know at this point that _rl_caught_signal == 0 */
7+
8+
#if defined (__MINGW32__)
9+
- if (isatty (fd)
10+
+ if (isatty (fd))
11+
return (_getch ()); /* "There is no error return." */
12+
#endif
13+
result = 0;
14+
diff --git a/rlprivate.h b/rlprivate.h
15+
index d87d07a..cb9cf17 100644
16+
--- a/rlprivate.h
17+
+++ b/rlprivate.h
18+
@@ -303,7 +303,7 @@ extern int _rl_pushed_input_available (void);
19+
20+
extern int _rl_timeout_init (void);
21+
extern int _rl_timeout_handle_sigalrm (void);
22+
-#if defined (_POSIXSELECT_H_)
23+
+#if defined (RL_TIMEOUT_USE_SELECT)
24+
/* use as a sentinel for fd_set, struct timeval, and sigset_t definitions */
25+
extern int _rl_timeout_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *, const sigset_t *);
26+
#endif

packages/r/readline/xmake.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,34 @@ package("readline")
66
add_urls("https://ftpmirror.gnu.org/readline/readline-$(version).tar.gz",
77
"https://ftp.gnu.org/gnu/readline/readline-$(version).tar.gz")
88

9+
add_versions("8.2.13", "0e5be4d2937e8bd9b7cd60d46721ce79f88a33415dd68c2d738fb5924638f656")
910
add_versions("8.2", "3feb7171f16a84ee82ca18a36d7b9be109a52c04f492a053331d7d1095007c35")
1011
add_versions("8.1", "f8ceb4ee131e3232226a17f51b164afc46cd0b9e6cef344be87c65962cb82b02")
1112

13+
-- Patch adopted from MSYS2
14+
-- add_patches("8.2.13", "patches/8.2.13/0001-sigwinch.patch", "2b30dcb0804abb6e7e4f44cd119bddef94c1b1d7ebff43dda401e710eda2fd0f")
15+
-- add_patches("8.2.13", "patches/8.2.13/0002-event-hook.patch", "5a5ab63e87a025af39b3e5101b171d16bd5d227f350f036a32193496d12bcbe2")
16+
-- add_patches("8.2.13", "patches/8.2.13/0003-fd_set.patch", "6329d02c9e151951136a31cce036f952f95f80a63d60694539839b9c706857e9")
17+
-- add_patches("8.2.13", "patches/8.2.13/0004-locale.patch", "72ed438ae142ba9d5498652dfdf4fb517265bcf9a67199b7c5b35cc24fa25b9e")
18+
19+
add_patches("8.2.13", "patches/8.2.13/mingw.patch", "3b5576e51471b248f5c89e0d4c01ac0bc443a239169fa19e25980f9a923f659a")
20+
21+
-- add_deps("patch")
1222
add_deps("ncurses")
1323

14-
on_install("linux", "macosx", function (package)
24+
on_install("linux", "macosx", "mingw", function (package)
1525
local configs = {"--with-curses"}
1626
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
1727
table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
1828
if package:is_debug() then
1929
table.insert(configs, "--enable-debug")
2030
end
21-
if package:config("pic") ~= false then
22-
table.insert(configs, "--with-pic")
31+
local cflags = {}
32+
if package:is_plat("mingw") then
33+
table.insert(cflags, "-DNEED_EXTERN_PC=1") -- Use extern PC variable from ncurses
34+
table.join2(cflags, {"-D__USE_MINGW_ALARM", "-D_POSIX"}) -- Make mingw-w64 provide a dummy alarm() function
2335
end
24-
import("package.tools.autoconf").install(package, configs)
36+
import("package.tools.autoconf").install(package, configs, {cflags = cflags})
2537
end)
2638

2739
on_test(function (package)

0 commit comments

Comments
 (0)