class PostgresqlAT13 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2" sha256 "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6" license "PostgreSQL" bottle do sha256 arm64_tahoe: "a164abe87a5feaf5499e942d14c8412f922b5887fa6a98e4d362e51d0d26a348" sha256 arm64_sequoia: "728cf49c02c7764b2fb9e444c627806cae1dcbd155edef25645f03f455f36b32" sha256 arm64_sonoma: "1e5c8492c74ca97a02f88326e77913fce9a4801ff7c76d9e8569daca0353ea96" sha256 sonoma: "5d05cd9a57f5754507ed091634ae35aee997d977c32e9d6f78057277fd4c25c2" sha256 arm64_linux: "2656270dc4f6fb71addd4816ac396e09f6c7b3c66e5f93ec3da46972e1487066" sha256 x86_64_linux: "ae85182e2bd663d43d2637a9391d924c0d48c0e05742aecad4b2ebd1eac4f9ac" end keg_only :versioned_formula # https://www.postgresql.org/support/versioning/ disable! date: "2026-03-01", because: :unsupported 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 "openssl@3" depends_on "readline" uses_from_macos "libxml2" uses_from_macos "libxslt" uses_from_macos "openldap" uses_from_macos "perl" uses_from_macos "zlib" on_linux do depends_on "linux-pam" depends_on "util-linux" end def install ENV.runtime_cpu_detection ENV.delete "PKG_CONFIG_LIBDIR" if OS.mac? && MacOS.version == :catalina 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}" args = %W[ --disable-debug --prefix=#{prefix} --datadir=#{opt_pkgshare} --libdir=#{opt_lib} --includedir=#{opt_include} --sysconfdir=#{etc} --docdir=#{doc} --enable-thread-safety --with-gssapi --with-icu --with-ldap --with-libxml --with-libxslt --with-openssl --with-pam --with-perl --with-uuid=e2fs ] 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] 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 end end