class PostgresqlAT95 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v9.5.24/postgresql-9.5.24.tar.bz2" sha256 "065cfd3db9f5aca84e794e73e71a797c984b2e728e760f4f4226a9162a99c22a" license "PostgreSQL" livecheck do url "https://www.postgresql.org/docs/9.5/static/release.html" regex(/Release v?(\d+(?:\.\d+)+)/i) end bottle do sha256 "b4856b072806f67090e5d09d583bc772398286adbf1de11638022efefb8d2a56" => :big_sur sha256 "0be4dafb4894658edd6f1df7f3f26e9460d123fc9e34a76b13b4605569aaadee" => :catalina sha256 "8b24d678fb18b585ba9d4034e66edd9d2658f3567762f31a594519dd84f88f7a" => :mojave end keg_only :versioned_formula depends_on "openssl@1.1" depends_on "readline" uses_from_macos "libxslt" uses_from_macos "perl" on_linux do depends_on "util-linux" end def install ENV.prepend "LDFLAGS", "-L#{Formula["openssl@1.1"].opt_lib} -L#{Formula["readline"].opt_lib}" ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@1.1"].opt_include} -I#{Formula["readline"].opt_include}" # avoid adding the SDK library directory to the linker search path ENV["XML2_CONFIG"] = "xml2-config --exec-prefix=/usr" args = %W[ --disable-debug --prefix=#{prefix} --datadir=#{pkgshare} --libdir=#{lib} --sysconfdir=#{prefix}/etc --docdir=#{doc} --enable-thread-safety --with-bonjour --with-gssapi --with-ldap --with-libxml --with-libxslt --with-openssl --with-pam --with-perl --with-tcl --with-uuid=e2fs ] # PostgreSQL by default uses xcodebuild internally to determine this, # which does not work on CLT-only installs. args << "PG_SYSROOT=#{MacOS.sdk_path}" if MacOS.sdk_root_needed? system "./configure", *args system "make" dirs = %W[datadir=#{pkgshare} libdir=#{lib} pkglibdir=#{lib}] # Temporarily disable building/installing the documentation. # Postgresql seems to "know" the build system has been altered and # tries to regenerate the documentation when using `install-world`. # This results in the build failing: # `ERROR: `osx' is missing on your system.` # Attempting to fix that by adding a dependency on `open-sp` doesn't # work and the build errors out on generating the documentation, so # for now let's simply omit it so we can package Postgresql for Mojave. if DevelopmentTools.clang_build_version >= 1000 system "make", "all" system "make", "-C", "contrib", "install", "all", *dirs system "make", "install", "all", *dirs else system "make", "install-world", *dirs end end def post_install return if ENV["CI"] (var/"log").mkpath postgresql_datadir.mkpath system "#{bin}/initdb", 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 If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/Homebrew/legacy-homebrew/issues/2510 This formula has created a default database cluster with: initdb #{postgresql_datadir} For more details, read: https://www.postgresql.org/docs/#{version.major}/app-initdb.html EOS end plist_options manual: "pg_ctl -D #{HOMEBREW_PREFIX}/var/postgresql@9.5 start" def plist <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/postgres -D #{postgresql_datadir} RunAtLoad WorkingDirectory #{HOMEBREW_PREFIX} StandardErrorPath #{postgresql_log_path} EOS end test do system "#{bin}/initdb", testpath/"test" unless ENV["CI"] assert_equal pkgshare.to_s, shell_output("#{bin}/pg_config --sharedir").chomp assert_equal lib.to_s, shell_output("#{bin}/pg_config --libdir").chomp assert_equal lib.to_s, shell_output("#{bin}/pg_config --pkglibdir").chomp end end