class PostgresqlAT15 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v15.15/postgresql-15.15.tar.bz2" sha256 "5753aaeb8b09cbf61016f78aa69bf5cbdf01b43263f010cbf168c82896213aaa" license "PostgreSQL" livecheck do url "https://ftp.postgresql.org/pub/source/" regex(%r{href=["']?v?(15(?:\.\d+)+)/?["' >]}i) end bottle do sha256 arm64_tahoe: "d39744f4067f6c1fb6df8e90bd82d852e8e113df54305b0cf32e74a255e1a8c2" sha256 arm64_sequoia: "b4d12037958c9a66e0ae235c6003bdcd5ec47e508b217708ec0c651e8cd06bb8" sha256 arm64_sonoma: "92eaebef7a06b4cd33cdf7f8007b95efdbefe39850917bc31e3ee20d8d51efbb" sha256 sonoma: "90b48106e669b4520e95d743fd84120c0c41680a8c525320ac071241341053d0" sha256 arm64_linux: "f8e00336e15115ac8892d33a1580a709e82c663d2e4fc1fc5e2c6fa080ca34a4" sha256 x86_64_linux: "c74441fad366d2ad5cbac33e79ef019effd401f7dc92341f948e8c2de45b0545" end keg_only :versioned_formula # https://www.postgresql.org/support/versioning/ deprecate! date: "2027-11-11", 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 if OS.mac? ENV.prepend "LDFLAGS", "-L#{Formula["gettext"].opt_lib}" ENV.prepend "CPPFLAGS", "-I#{Formula["gettext"].opt_include}" end args = std_configure_args + %W[ --datadir=#{opt_pkgshare} --libdir=#{opt_lib} --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 --with-extra-version=\ (#{tap.user}) ] 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 # 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" return unless OS.linux? inreplace lib/"postgresql/pgxs/src/Makefile.global", "LD = #{Superenv.shims_path}/ld", "LD = #{HOMEBREW_PREFIX}/bin/ld" 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