homebrew-core/Formula/libpq.rb

83 lines
2.5 KiB
Ruby

class Libpq < Formula
desc "Postgres C API library"
homepage "https://www.postgresql.org/docs/12/libpq.html"
url "https://ftp.postgresql.org/pub/source/v12.4/postgresql-12.4.tar.bz2"
sha256 "bee93fbe2c32f59419cb162bcc0145c58da9a8644ee154a30b9a5ce47de606cc"
license "PostgreSQL"
livecheck do
url "https://ftp.postgresql.org/pub/source/?C=M&O=A"
regex(%r{href=.*?v?(\d+(?:\.\d+)+)/?["' >]}i)
end
bottle do
sha256 "dae00b7442212f928e157405e8899c7fa912bb445bfeed07f52c1de94b04b2a2" => :catalina
sha256 "79ec27aa6f8a41e00effcdaca158db7f18ed0f49958578a2ec4bdc09fec28f0b" => :mojave
sha256 "01f54e1c777c2b5a7d2e40c41ecdce5a8829a61112df16b406017b2822f36187" => :high_sierra
end
keg_only "conflicts with postgres formula"
# GSSAPI provided by Kerberos.framework crashes when forked.
# See https://github.com/Homebrew/homebrew-core/issues/47494.
depends_on "krb5"
depends_on "openssl@1.1"
on_linux do
depends_on "readline"
end
def install
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 <<~EOS
#include <stdlib.h>
#include <stdio.h>
#include <libpq-fe.h>
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;
}
EOS
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