class PostgresqlAT16 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v16.11/postgresql-16.11.tar.bz2" sha256 "6deb08c23d03d77d8f8bd1c14049eeef64aef8968fd8891df2dfc0b42f178eac" license "PostgreSQL" revision 1 livecheck do url "https://ftp.postgresql.org/pub/source/" regex(%r{href=["']?v?(16(?:\.\d+)+)/?["' >]}i) end bottle do sha256 arm64_tahoe: "b6eefb442479e59c9ed3d834071b7f8cf15f2012fd1a25efb5afaebdb82609d9" sha256 arm64_sequoia: "7d0161d142ee80fa4016f9065541a28589a220dc4f02d40dfcecfc1ef243d515" sha256 arm64_sonoma: "337e431e6c05b015f4c5a497bc8254807d102c7f9ee468d21958d55c934dc6f7" sha256 sonoma: "ed8067a9d2321a5cd5267060d40893445774b66b2ba816cc0481534cac6a773b" sha256 arm64_linux: "7d1ab5d99f598714e24459c9a470a69e1eb45d0d49bee672a437fe9ffe0b7f02" sha256 x86_64_linux: "d9864f3ed876ddb71b35befc2bc9508895aa540144abcb8c9b4663be91db9c62" end keg_only :versioned_formula # https://www.postgresql.org/support/versioning/ deprecate! date: "2028-11-09", because: :unsupported depends_on "gettext" => :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 "lz4" depends_on "openssl@3" depends_on "readline" depends_on "zstd" uses_from_macos "libxml2" uses_from_macos "libxslt" uses_from_macos "openldap" uses_from_macos "perl" uses_from_macos "zlib" on_macos do depends_on "gettext" end on_linux do depends_on "linux-pam" depends_on "util-linux" end def install ENV.runtime_cpu_detection ENV.delete "PKG_CONFIG_LIBDIR" ENV.prepend "LDFLAGS", "-L#{Formula["openssl@3"].opt_lib} -L#{Formula["readline"].opt_lib}" ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@3"].opt_include} -I#{Formula["readline"].opt_include}" # Fix 'libintl.h' file not found for extensions # Update config to fix `error: could not find function 'gss_store_cred_into' required for GSSAPI` if OS.mac? ENV.prepend "LDFLAGS", "-L#{Formula["gettext"].opt_lib} -L#{Formula["krb5"].opt_lib}" ENV.prepend "CPPFLAGS", "-I#{Formula["gettext"].opt_include} -I#{Formula["krb5"].opt_include}" end args = %W[ --datadir=#{opt_pkgshare} --includedir=#{opt_include} --sysconfdir=#{etc} --docdir=#{doc} --enable-nls --enable-thread-safety --with-gssapi --with-icu --with-ldap --with-libxml --with-libxslt --with-lz4 --with-zstd --with-openssl --with-pam --with-perl --with-uuid=e2fs ] args << "--with-extra-version= (#{tap.user})" if tap args += %w[--with-bonjour --with-tcl] if OS.mac? # PostgreSQL by default uses xcodebuild internally to determine this, # which does not work on CLT-only installs. args << "PG_SYSROOT=#{MacOS.sdk_path}" if OS.mac? system "./configure", *args, *std_configure_args(libdir: opt_lib) # Work around busted path magic in Makefile.global.in. This can't be specified # in ./configure, but needs to be set here otherwise install prefixes containing # the string "postgres" will get an incorrect pkglibdir. # See https://github.com/Homebrew/homebrew-core/issues/62930#issuecomment-709411789 system "make", "pkglibdir=#{opt_lib}/postgresql", "pkgincludedir=#{opt_include}/postgresql", "includedir_server=#{opt_include}/postgresql/server" system "make", "install-world", "datadir=#{pkgshare}", "libdir=#{lib}", "pkglibdir=#{lib}/postgresql", "includedir=#{include}", "pkgincludedir=#{include}/postgresql", "includedir_server=#{include}/postgresql/server", "includedir_internal=#{include}/postgresql/internal" end def post_install (var/"log").mkpath postgresql_datadir.mkpath # Don't initialize database, it clashes when testing other PostgreSQL versions. return if ENV["HOMEBREW_GITHUB_ACTIONS"] system bin/"initdb", "--locale=en_US.UTF-8", "-E", "UTF-8", postgresql_datadir unless pg_version_exists? end def postgresql_datadir var/name end def postgresql_log_path var/"log/#{name}.log" end def pg_version_exists? (postgresql_datadir/"PG_VERSION").exist? end def caveats <<~EOS This formula has created a default database cluster with: initdb --locale=en_US.UTF-8 -E UTF-8 #{postgresql_datadir} EOS end service do run [opt_bin/"postgres", "-D", f.postgresql_datadir] environment_variables LC_ALL: "en_US.UTF-8" keep_alive true log_path f.postgresql_log_path error_log_path f.postgresql_log_path working_dir HOMEBREW_PREFIX end test do system bin/"initdb", "--locale=en_US.UTF-8", "-E UTF-8", testpath/"test" unless ENV["HOMEBREW_GITHUB_ACTIONS"] assert_equal opt_pkgshare.to_s, shell_output("#{bin}/pg_config --sharedir").chomp assert_equal opt_lib.to_s, shell_output("#{bin}/pg_config --libdir").chomp assert_equal (opt_lib/"postgresql").to_s, shell_output("#{bin}/pg_config --pkglibdir").chomp assert_equal (opt_include/"postgresql").to_s, shell_output("#{bin}/pg_config --pkgincludedir").chomp assert_equal (opt_include/"postgresql/server").to_s, shell_output("#{bin}/pg_config --includedir-server").chomp assert_match "-I#{Formula["gettext"].opt_include}", shell_output("#{bin}/pg_config --cppflags") if OS.mac? end end