PageRenderTime 33ms CodeModel.GetById 45ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/postgresql.rb

https://github.com/aaroncm/homebrew
Ruby | 232 lines | 169 code | 46 blank | 17 comment | 8 complexity | c9382e3a264a6a31203fc3ff07ba4441 MD5 | raw file
  1. require 'formula'
  2. class Postgresql < Formula
  3. homepage 'http://www.postgresql.org/'
  4. url 'http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.bz2'
  5. md5 'a8035688dba988b782725ac1aec60186'
  6. depends_on 'readline'
  7. depends_on 'libxml2' if MacOS.leopard? # Leopard libxml is too old
  8. depends_on 'ossp-uuid'
  9. def options
  10. [
  11. ['--32-bit', 'Build 32-bit only.'],
  12. ['--without-ossp-uuid', 'Build without OSSP uuid.'],
  13. ['--no-python', 'Build without Python support.'],
  14. ['--no-perl', 'Build without Perl support.'],
  15. ['--enable-dtrace', 'Build with DTrace support.']
  16. ]
  17. end
  18. skip_clean :all
  19. # Fix PL/Python build: https://github.com/mxcl/homebrew/issues/11162
  20. # Fix uuid-ossp build issues: http://archives.postgresql.org/pgsql-general/2012-07/msg00654.php
  21. def patches
  22. DATA
  23. end
  24. def install
  25. ENV.libxml2 if MacOS.snow_leopard?
  26. args = ["--disable-debug",
  27. "--prefix=#{prefix}",
  28. "--datadir=#{share}/#{name}",
  29. "--docdir=#{doc}",
  30. "--enable-thread-safety",
  31. "--with-bonjour",
  32. "--with-gssapi",
  33. "--with-krb5",
  34. "--with-openssl",
  35. "--with-libxml",
  36. "--with-libxslt"]
  37. args << "--with-ossp-uuid" unless ARGV.include? '--without-ossp-uuid'
  38. args << "--with-python" unless ARGV.include? '--no-python'
  39. args << "--with-perl" unless ARGV.include? '--no-perl'
  40. args << "--enable-dtrace" if ARGV.include? '--enable-dtrace'
  41. ENV.append 'CFLAGS', `uuid-config --cflags`.strip
  42. ENV.append 'LDFLAGS', `uuid-config --ldflags`.strip
  43. ENV.append 'LIBS', `uuid-config --libs`.strip
  44. if not ARGV.build_32_bit? and MacOS.prefer_64_bit? and not ARGV.include? '--no-python'
  45. args << "ARCHFLAGS='-arch x86_64'"
  46. check_python_arch
  47. end
  48. if ARGV.build_32_bit?
  49. ENV.append 'CFLAGS', '-arch i386'
  50. ENV.append 'LDFLAGS', '-arch i386'
  51. end
  52. # Fails on Core Duo with O4 and O3
  53. ENV.O2 if Hardware.intel_family == :core
  54. system "./configure", *args
  55. system "make install-world"
  56. plist_path.write startup_plist
  57. plist_path.chmod 0644
  58. end
  59. def check_python_arch
  60. # On 64-bit systems, we need to look for a 32-bit Framework Python.
  61. # The configure script prefers this Python version, and if it doesn't
  62. # have 64-bit support then linking will fail.
  63. framework_python = Pathname.new "/Library/Frameworks/Python.framework/Versions/Current/Python"
  64. return unless framework_python.exist?
  65. unless (archs_for_command framework_python).include? :x86_64
  66. opoo "Detected a framework Python that does not have 64-bit support in:"
  67. puts <<-EOS.undent
  68. #{framework_python}
  69. The configure script seems to prefer this version of Python over any others,
  70. so you may experience linker problems as described in:
  71. http://osdir.com/ml/pgsql-general/2009-09/msg00160.html
  72. To fix this issue, you may need to either delete the version of Python
  73. shown above, or move it out of the way before brewing PostgreSQL.
  74. Note that a framework Python in /Library/Frameworks/Python.framework is
  75. the "MacPython" version, and not the system-provided version which is in:
  76. /System/Library/Frameworks/Python.framework
  77. EOS
  78. end
  79. end
  80. def caveats
  81. s = <<-EOS
  82. # Build Notes
  83. If builds of PostgreSQL 9 are failing and you have version 8.x installed,
  84. you may need to remove the previous version first. See:
  85. https://github.com/mxcl/homebrew/issues/issue/2510
  86. To build plpython against a specific Python, set PYTHON prior to brewing:
  87. PYTHON=/usr/local/bin/python brew install postgresql
  88. See:
  89. http://www.postgresql.org/docs/9.1/static/install-procedure.html
  90. # Create/Upgrade a Database
  91. If this is your first install, create a database with:
  92. initdb #{var}/postgres
  93. To migrate existing data from a previous major version (pre-9.1) of PostgreSQL, see:
  94. http://www.postgresql.org/docs/9.1/static/upgrading.html
  95. # Start/Stop PostgreSQL
  96. If this is your first install, automatically load on login with:
  97. mkdir -p ~/Library/LaunchAgents
  98. cp #{plist_path} ~/Library/LaunchAgents/
  99. launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
  100. If this is an upgrade and you already have the #{plist_path.basename} loaded:
  101. launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
  102. cp #{plist_path} ~/Library/LaunchAgents/
  103. launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
  104. Or start manually with:
  105. pg_ctl -D #{var}/postgres -l #{var}/postgres/server.log start
  106. And stop with:
  107. pg_ctl -D #{var}/postgres stop -s -m fast
  108. # Loading Extensions
  109. By default, Homebrew builds all available Contrib extensions. To see a list of all
  110. available extensions, from the psql command line, run:
  111. SELECT * FROM pg_available_extensions;
  112. To load any of the extension names, navigate to the desired database and run:
  113. CREATE EXTENSION [extension name];
  114. For instance, to load the tablefunc extension in the current database, run:
  115. CREATE EXTENSION tablefunc;
  116. For more information on the CREATE EXTENSION command, see:
  117. http://www.postgresql.org/docs/9.1/static/sql-createextension.html
  118. For more information on extensions, see:
  119. http://www.postgresql.org/docs/9.1/static/contrib.html
  120. # Other
  121. Some machines may require provisioning of shared memory:
  122. http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
  123. EOS
  124. if MacOS.prefer_64_bit? then
  125. s << <<-EOS
  126. To install postgresql (and ossp-uuid) in 32-bit mode:
  127. brew install postgresql --32-bit
  128. If you want to install the postgres gem, including ARCHFLAGS is recommended:
  129. env ARCHFLAGS="-arch x86_64" gem install pg
  130. To install gems without sudo, see the Homebrew wiki.
  131. EOS
  132. end
  133. return s
  134. end
  135. def startup_plist
  136. return <<-EOPLIST
  137. <?xml version="1.0" encoding="UTF-8"?>
  138. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  139. <plist version="1.0">
  140. <dict>
  141. <key>KeepAlive</key>
  142. <true/>
  143. <key>Label</key>
  144. <string>#{plist_name}</string>
  145. <key>ProgramArguments</key>
  146. <array>
  147. <string>#{HOMEBREW_PREFIX}/bin/postgres</string>
  148. <string>-D</string>
  149. <string>#{var}/postgres</string>
  150. <string>-r</string>
  151. <string>#{var}/postgres/server.log</string>
  152. </array>
  153. <key>RunAtLoad</key>
  154. <true/>
  155. <key>UserName</key>
  156. <string>#{`whoami`.chomp}</string>
  157. <key>WorkingDirectory</key>
  158. <string>#{HOMEBREW_PREFIX}</string>
  159. <key>StandardErrorPath</key>
  160. <string>#{var}/postgres/server.log</string>
  161. </dict>
  162. </plist>
  163. EOPLIST
  164. end
  165. end
  166. __END__
  167. --- a/src/pl/plpython/Makefile 2011-09-23 08:03:52.000000000 +1000
  168. +++ b/src/pl/plpython/Makefile 2011-10-26 21:43:40.000000000 +1100
  169. @@ -24,8 +24,6 @@
  170. # Darwin (OS X) has its own ideas about how to do this.
  171. ifeq ($(PORTNAME), darwin)
  172. shared_libpython = yes
  173. -override python_libspec = -framework Python
  174. -override python_additional_libs =
  175. endif
  176. # If we don't have a shared library and the platform doesn't allow it
  177. --- a/contrib/uuid-ossp/uuid-ossp.c 2012-07-30 18:34:53.000000000 -0700
  178. +++ b/contrib/uuid-ossp/uuid-ossp.c 2012-07-30 18:35:03.000000000 -0700
  179. @@ -9,6 +9,8 @@
  180. *-------------------------------------------------------------------------
  181. */
  182. +#define _XOPEN_SOURCE
  183. +
  184. #include "postgres.h"
  185. #include "fmgr.h"
  186. #include "utils/builtins.h"