From 9f884b96f747c4ede28f8139874b972947aed126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sat, 9 Jul 2022 17:33:13 +0300 Subject: [PATCH] build libnss_turbo.so.2.0.0 --- build.zig | 35 +++++++++++++++++++++++++++++++++++ src/libnss.zig | 36 ++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/build.zig b/build.zig index c849e83..8458e57 100644 --- a/build.zig +++ b/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = std.builtin; const zbs = std.build; pub fn build(b: *zbs.Builder) void { @@ -42,6 +43,24 @@ pub fn build(b: *zbs.Builder) void { cmph.addIncludeDir("deps/cmph/src"); cmph.addIncludeDir("include/deps/cmph"); + const bdz = b.addStaticLibrary("bdz", null); + bdz.setTarget(target); + bdz.setBuildMode(mode); + bdz.linkLibC(); + bdz.addCSourceFiles(&.{ + "deps/cmph/src/bdz.c", + "deps/cmph/src/bdz_ph.c", + "deps/cmph/src/hash.c", + "deps/cmph/src/jenkins_hash.c", + }, &.{ + "-W", + "-Wno-unused-function", + //"-DDEBUG", + }); + bdz.omit_frame_pointer = true; + bdz.addIncludeDir("deps/cmph/src"); + bdz.addIncludeDir("include/deps/cmph"); + { const exe = b.addExecutable("turbo-unix2db", "src/unix2db.zig"); exe.setTarget(target); @@ -57,6 +76,22 @@ pub fn build(b: *zbs.Builder) void { exe.install(); } + { + const so = b.addSharedLibrary("nss_turbo", "src/libnss.zig", .{ + .versioned = builtin.Version{ + .major = 2, + .minor = 0, + .patch = 0, + }, + }); + so.linkLibC(); + so.linkLibrary(bdz); + so.addIncludeDir("deps/cmph/src"); + so.setTarget(target); + so.setBuildMode(mode); + so.install(); + } + { const src_test = b.addTest("src/test_all.zig"); addCmphDeps(src_test, cmph); diff --git a/src/libnss.zig b/src/libnss.zig index 77aa448..2d42c18 100644 --- a/src/libnss.zig +++ b/src/libnss.zig @@ -28,7 +28,7 @@ const ENV_OMIT_MEMBERS = "TURBONSS_OMIT_MEMBERS"; export var turbonss_db_path: [:0]const u8 = "/etc/turbonss/db.turbo"; -pub var log_level: std.log.Level = .err; +//pub var log_level: std.log.Level = .err; // State is a type of the global variable holding the process state: // the DB handle and all the iterators. @@ -52,23 +52,23 @@ var global_init = once(init); // assigns State from environment variables et al fn init() void { - if (os.getenvZ(ENV_LOGLEVEL)) |env| { - const got = mem.sliceTo(env, 0); - if (mem.eql(u8, got, "0")) { - log_level = .err; - } else if (mem.eql(u8, got, "1")) { - log_level = .warn; - } else if (mem.eql(u8, got, "2")) { - log_level = .info; - } else if (mem.eql(u8, got, "3")) { - log_level = .debug; - } else { - std.debug.print( - "warning: unrecognized {s}={s}. Expected between 0 and 3\n", - .{ ENV_LOGLEVEL, got }, - ); - } - } + //if (os.getenvZ(ENV_LOGLEVEL)) |env| { + // const got = mem.sliceTo(env, 0); + // if (mem.eql(u8, got, "0")) { + // log_level = .err; + // } else if (mem.eql(u8, got, "1")) { + // log_level = .warn; + // } else if (mem.eql(u8, got, "2")) { + // log_level = .info; + // } else if (mem.eql(u8, got, "3")) { + // log_level = .debug; + // } else { + // std.debug.print( + // "warning: unrecognized {s}={s}. Expected between 0 and 3\n", + // .{ ENV_LOGLEVEL, got }, + // ); + // } + //} const omit_members = blk: { if (os.getenvZ(ENV_OMIT_MEMBERS)) |env| {