|
| 1 | +class LibpqAT16 < Formula |
| 2 | + desc "Postgres C API library" |
| 3 | + homepage "https://www.postgresql.org/docs/16/libpq.html" |
| 4 | + url "https://ftp.postgresql.org/pub/source/v16.9/postgresql-16.9.tar.bz2" |
| 5 | + sha256 "07c00fb824df0a0c295f249f44691b86e3266753b380c96f633c3311e10bd005" |
| 6 | + license "PostgreSQL" |
| 7 | + |
| 8 | + livecheck do |
| 9 | + url "https://ftp.postgresql.org/pub/source/" |
| 10 | + regex(%r{href=["']?v?(16(?:\.\d+)+)/?["' >]}i) |
| 11 | + end |
| 12 | + |
| 13 | + keg_only :versioned_formula |
| 14 | + |
| 15 | + # https://endoflife.date/postgresql |
| 16 | + deprecate! date: "2028-11-09", because: :unmaintained, replacement_formula: "libpq" |
| 17 | + |
| 18 | + depends_on "pkgconf" => :build |
| 19 | + depends_on "icu4c@77" |
| 20 | + # GSSAPI provided by Kerberos.framework crashes when forked. |
| 21 | + # See https://github.com/Homebrew/homebrew-core/issues/47494. |
| 22 | + depends_on "krb5" |
| 23 | + depends_on "openssl@3" |
| 24 | + |
| 25 | + uses_from_macos "zlib" |
| 26 | + |
| 27 | + on_linux do |
| 28 | + depends_on "readline" |
| 29 | + end |
| 30 | + |
| 31 | + def install |
| 32 | + system "./configure", "--disable-debug", |
| 33 | + "--prefix=#{prefix}", |
| 34 | + "--with-gssapi", |
| 35 | + "--with-openssl", |
| 36 | + "--libdir=#{opt_lib}", |
| 37 | + "--includedir=#{opt_include}" |
| 38 | + dirs = %W[ |
| 39 | + libdir=#{lib} |
| 40 | + includedir=#{include} |
| 41 | + pkgincludedir=#{include}/postgresql |
| 42 | + includedir_server=#{include}/postgresql/server |
| 43 | + includedir_internal=#{include}/postgresql/internal |
| 44 | + ] |
| 45 | + system "make" |
| 46 | + system "make", "-C", "src/bin", "install", *dirs |
| 47 | + system "make", "-C", "src/include", "install", *dirs |
| 48 | + system "make", "-C", "src/interfaces", "install", *dirs |
| 49 | + system "make", "-C", "src/common", "install", *dirs |
| 50 | + system "make", "-C", "src/port", "install", *dirs |
| 51 | + system "make", "-C", "doc", "install", *dirs |
| 52 | + end |
| 53 | + |
| 54 | + test do |
| 55 | + (testpath/"libpq.c").write <<~EOS |
| 56 | + #include <stdlib.h> |
| 57 | + #include <stdio.h> |
| 58 | + #include <libpq-fe.h> |
| 59 | +
|
| 60 | + int main() |
| 61 | + { |
| 62 | + const char *conninfo; |
| 63 | + PGconn *conn; |
| 64 | +
|
| 65 | + conninfo = "dbname = postgres"; |
| 66 | +
|
| 67 | + conn = PQconnectdb(conninfo); |
| 68 | +
|
| 69 | + if (PQstatus(conn) != CONNECTION_OK) // This should always fail |
| 70 | + { |
| 71 | + printf("Connection to database attempted and failed"); |
| 72 | + PQfinish(conn); |
| 73 | + exit(0); |
| 74 | + } |
| 75 | +
|
| 76 | + return 0; |
| 77 | + } |
| 78 | + EOS |
| 79 | + system ENV.cc, "libpq.c", "-L#{lib}", "-I#{include}", "-lpq", "-o", "libpqtest" |
| 80 | + assert_equal "Connection to database attempted and failed", shell_output("./libpqtest") |
| 81 | + end |
| 82 | +end |
0 commit comments