class Libpq < Formula desc "Postgres C API library" homepage "https://www.postgresql.org/docs/current/libpq.html" url "https://ftp.postgresql.org/pub/source/v18.1/postgresql-18.1.tar.bz2" sha256 "ff86675c336c46e98ac991ebb306d1b67621ece1d06787beaade312c2c915d54" license "PostgreSQL" livecheck do url "https://ftp.postgresql.org/pub/source/" regex(%r{href=["']?v?(\d+(?:\.\d+)+)/?["' >]}i) end bottle do sha256 arm64_tahoe: "45aa1668f5f0ded58652306525b008cab1cd78d64b39f77975b4314724146495" sha256 arm64_sequoia: "28ad8ca6f9b262c718b4fd4486c45211cb8847f6a07031fdadee26978ed6f713" sha256 arm64_sonoma: "1e1bbad6817851a75ec790a18779b2580ab200013530683c339e271e67726478" sha256 sonoma: "5190c06e00bc0ce9ca965568925c8f235d149ff6d3b526b9e7f278e148da6e9c" sha256 arm64_linux: "f5164f475e135797456916bdcfa24b2a47cec6cde87d7900b9b59ab58cebc381" sha256 x86_64_linux: "b3f9b5ce82be0a12937af75b4bccc0500319fea0e0d06281119d6572ae8f9557" end keg_only "it conflicts with PostgreSQL" depends_on "docbook" => :build depends_on "docbook-xsl" => :build depends_on "pkgconf" => :build depends_on "icu4c@78" # GSSAPI provided by Kerberos.framework crashes when forked. # See https://github.com/Homebrew/homebrew-core/issues/47494. depends_on "krb5" depends_on "openssl@3" uses_from_macos "bison" => :build uses_from_macos "flex" => :build uses_from_macos "libxml2" => :build uses_from_macos "libxslt" => :build # for xsltproc uses_from_macos "zlib" on_linux do depends_on "readline" end def install ENV["XML_CATALOG_FILES"] = "#{etc}/xml/catalog" ENV.runtime_cpu_detection system "./configure", "--disable-debug", "--prefix=#{prefix}", "--with-gssapi", "--with-openssl", "--libdir=#{opt_lib}", "--includedir=#{opt_include}" dirs = %W[ libdir=#{lib} includedir=#{include} pkgincludedir=#{include}/postgresql includedir_server=#{include}/postgresql/server includedir_internal=#{include}/postgresql/internal ] system "make" system "make", "-C", "src/bin", "install", *dirs system "make", "-C", "src/include", "install", *dirs system "make", "-C", "src/interfaces", "install", *dirs system "make", "-C", "src/common", "install", *dirs system "make", "-C", "src/port", "install", *dirs system "make", "-C", "doc", "install", *dirs end test do (testpath/"libpq.c").write <<~C #include #include #include int main() { const char *conninfo; PGconn *conn; conninfo = "dbname = postgres"; conn = PQconnectdb(conninfo); if (PQstatus(conn) != CONNECTION_OK) // This should always fail { printf("Connection to database attempted and failed"); PQfinish(conn); exit(0); } return 0; } C system ENV.cc, "libpq.c", "-L#{lib}", "-I#{include}", "-lpq", "-o", "libpqtest" assert_equal "Connection to database attempted and failed", shell_output("./libpqtest") end end