1 class Tinycdb < Formula
2 desc "Create and read constant databases"
3 homepage "https://www.corpit.ru/mjt/tinycdb.html"
4 url "https://www.corpit.ru/mjt/tinycdb/tinycdb-0.81.tar.gz"
5 sha256 "469de2d445bf54880f652f4b6dc95c7cdf6f5502c35524a45b2122d70d47ebc2"
11 regex(/href=.*?tinycdb[._-]v?(\d+(?:\.\d+)+)\.t/i)
15 sha256 cellar: :any, arm64_sequoia: "680cfcfc325b233fe7340563af3250740568b8a3689fae20f477e108ed673a8e"
16 sha256 cellar: :any, arm64_sonoma: "345b0faa2f7c6d23974d5c2428eb7961fbf0934a5064e39f1d957469c6ca491c"
17 sha256 cellar: :any, arm64_ventura: "29a4f84b5a7f2f4eeb6301260a9dd6dc063428a9550bb646b526c3cca3d96565"
18 sha256 cellar: :any, sonoma: "00517e16683f21a47b6f985fd00927be4fca3c501aa34e445008aad1f9bbf7ea"
19 sha256 cellar: :any, ventura: "c803d0c447413f5d29e43172e75c6a6ac54f6b23b2c85c469e1d0a2930932b95"
20 sha256 cellar: :any_skip_relocation, x86_64_linux: "e936f20c0ba2216f0ead62448ee2793eb96181c32bb381b9f3207e34e3ce46b5"
24 # This value is used only on macOS.
25 # If the test block fails only on Linux, then this value likely needs updating.
31 system "make", "install", "prefix=#{prefix}", "mandir=#{man}"
33 shared_flags = ["prefix=#{prefix}"]
34 shared_flags += if OS.mac?
36 SHAREDLIB=#{shared_library("$(LIBBASE)", libcdb_soversion)}
37 SOLIB=#{shared_library("$(LIBBASE)")}
38 LDFLAGS_SONAME=-Wl,-install_name,$(prefix)/
44 system "make", *shared_flags, "shared"
45 system "make", *shared_flags, "install-sharedlib"
49 (testpath/"test.c").write <<~C
62 fd = open("#{testpath}/db", O_RDWR|O_CREAT);
64 cdb_make_start(&cdbm, fd);
65 cdb_make_add(&cdbm, key, klen, val, vlen);
66 cdb_make_exists(&cdbm, key, klen);
67 cdb_make_finish(&cdbm);
71 system ENV.cc, "test.c", "-L#{lib}", "-lcdb", "-o", "test"
73 return unless OS.linux?
75 # Let's test whether our hard-coded `libcdb_soversion` is correct, since we don't override this on Linux.
76 # If this test fails, the the value in the `libcdb_soversion` needs updating.
77 versioned_libcdb_candidates = lib.glob(shared_library("libcdb", "*")).reject { |so| so.to_s.end_with?(".so") }
78 assert_equal versioned_libcdb_candidates.count, 1, "expected only one versioned `libcdb`!"
80 versioned_libcdb = versioned_libcdb_candidates.first.basename.to_s
81 soversion = versioned_libcdb[/\.(\d+)$/, 1]
82 assert_equal libcdb_soversion, soversion