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" livecheck do url "https://ftp.postgresql.org/pub/source/" regex(%r{href=["']?v?(16(?:\.\d+)+)/?["' >]}i) end bottle do sha256 arm64_tahoe: "45a77587d6a1b043135652f6e016c4f5acd47f2c1d43bc6668750048bb160542" sha256 arm64_sequoia: "3a30b366f2a9c08df8b37addaebb20457320f74112e45f284f710f201261e000" sha256 arm64_sonoma: "208551c7ead5cf3f3fd083a9a03c7e9b640cc22f369cfd32deec92ca018c255f" sha256 sonoma: "959e4839458f26cf628846bc287552cab1d61163409ffa783511cc501902a20e" sha256 arm64_linux: "dbe27d036bc18547705755037cde2ce6e5a47a6cfeaf46dbddf230287e1f5806" sha256 x86_64_linux: "73f79b7c9ab845ee7714b8fd4efb9899afff4d5be88c3d46e97c3a410c06e6d4" 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