klib: add package (#5560)

* klib: add package

* improve non-x86 arch build
pull/5569/head
star9029 1 month ago committed by GitHub
parent 60e50e957b
commit 3468d1d2ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      packages/k/klib/port/rand48.c
  2. 8
      packages/k/klib/port/unistd.h
  3. 52
      packages/k/klib/port/xmake.lua
  4. 53
      packages/k/klib/xmake.lua

@ -0,0 +1,9 @@
#include <stdlib.h>
double drand48(void) {
return rand() / (RAND_MAX + 1.0);
}
void srand48(long int seedval) {
srand(seedval);
}

@ -0,0 +1,8 @@
#pragma once
#ifdef _MSC_VER
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#else
typedef int ssize_t;
#endif

@ -0,0 +1,52 @@
option("url", {default = false})
option("thread", {default = false})
option("open", {default = false})
add_rules("mode.release", "mode.debug")
add_requires("zlib")
if has_config("url") then
add_requires("libcurl")
add_packages("libcurl")
end
if has_config("thread") then
add_syslinks("pthread")
end
target("klib")
set_kind("$(kind)")
add_files("kmath.c", {defines = "M_SQRT2=1.41421356237309504880"})
add_files("*.c|rand48.c|kurl.c|kthread.c|kopen.c|ksw.c")
add_includedirs(os.projectdir())
add_packages("zlib")
if is_plat("windows") and is_kind("shared") then
add_rules("utils.symbols.export_all")
end
if is_plat("windows", "mingw") then
add_syslinks("ws2_32")
end
add_headerfiles("*.h|unistd.h|kurl.h|kthread.h|kopen.h|ksw.h")
if has_config("url") then
add_files("kurl.c")
add_headerfiles("kurl.h")
end
if has_config("thread") then
add_files("kthread.c")
add_headerfiles("kthread.h")
end
if has_config("open") then
add_files("kopen.c")
add_headerfiles("kopen.h")
end
if is_arch("x64", "x86", "x86_64") then
add_files("ksw.c")
add_headerfiles("ksw.h")
end

@ -0,0 +1,53 @@
package("klib")
set_homepage("http://attractivechaos.github.io/klib/")
set_description("A standalone and lightweight C library")
set_license("MIT")
add_urls("https://github.com/attractivechaos/klib.git")
add_versions("2024.06.03", "29445495262cf34f4c3b82d3917ac83f3e1f3f58")
add_configs("url", {description = "Enable FILE-like interfaces to libcurl.", default = false, type = "boolean"})
add_configs("thread", {description = "Enable simple multi-threading models.", default = false, type = "boolean"})
add_configs("open", {description = "Enable smart stream opening.", default = false, type = "boolean"})
if is_plat("windows", "mingw") then
add_syslinks("ws2_32")
end
add_deps("zlib")
on_load(function (package)
if package:config("url") then
package:add("deps", "libcurl")
end
if package:config("thread") then
package:add("syslinks", "pthread")
end
end)
on_install(function (package)
io.replace("bgzf.c", "fp->uncompressed_block + input_length", "(char*)fp->uncompressed_block + input_length", {plain = true})
io.replace("bgzf.c", "fp->compressed_block + 18", "(char*)fp->compressed_block + 18", {plain = true})
io.replace("knetfile.c", "buf + l", "(char*)buf + l", {plain = true})
if package:is_plat("windows", "mingw") then
io.replace("khmm.c", "// new/delete hmm_par_t", [[#include "rand48.c"]], {plain = true})
end
local configs = {
url = package:config("url"),
thread = package:config("thread"),
open = package:config("open"),
}
if package:is_plat("windows", "mingw") then
os.cp(path.join(package:scriptdir(), "port", "rand48.c"), "rand48.c")
if package:is_plat("windows") then
os.cp(path.join(package:scriptdir(), "port", "unistd.h"), "unistd.h")
end
end
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
assert(package:has_cfuncs("kmalloc", {includes = "kalloc.h"}))
end)
Loading…
Cancel
Save