class PostgresqlAT12 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2" sha256 "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b" license "PostgreSQL" revision 2 bottle do sha256 arm64_tahoe: "7eebc44b6f6fdd3655951ab6b671c3fcafd134dba397657e444fdf8deeca66bf" sha256 arm64_sequoia: "a298c1ffaca071ca5c61293b253109bd6f9145e3992c8fdb1814b8efeae18a65" sha256 arm64_sonoma: "c01dcad85dd0159afdb19a31bc0ef7311a17743290151fea742763e59fa418f5" sha256 sonoma: "127c10f4b874c14e5ebdec658b592e8e4cca59d206c474d518a9ee055cc11b3e" sha256 arm64_linux: "e111736fed680690c6f4a8702a946588045db4c52ac0c284d3b238a03efca183" sha256 x86_64_linux: "43dee3defb61a85fa962fa71f6a3d09ebf49128ed46a8575a828141b817dff19" end keg_only :versioned_formula # https://www.postgresql.org/support/versioning/ deprecate! date: "2024-11-14", because: :unsupported disable! date: "2025-11-14", because: :unsupported depends_on "pkgconf" => :build depends_on "icu4c@77" # 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=C", "-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=C -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", 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