Currently, we don't build pl/python when building PostgreSQL, even
though pl/python ships with PostgreSQL.  One reason for this may be that
because python is threaded and PostgreSQL is not, pl/python does not
work by default.  However, using LD_PRELOAD to load pthreads when
starting PostgreSQL works around that issue.  This is the same
workaround required by pl/v8, so assuming we are OK doing that for
pl/v8, I assume that it is fine to take the same approach with
pl/python.

This diff adds another subpackage for pl/python.  For some reason I
cannot diagnose, this seems to cause a race condition causing the build
system to attempt to rebuild the documentation, so I have added a work
around for that.

Briefly tested on i386, also compiles on amd64. This shouldn't cause any
additional dependencies, as PostgreSQL already required python to build
(transitively through libxml at least).  This should probably at least
be compile tested on other shared arches to ensure that it doesn't break
the building of PostgreSQL on them (unlikely but possible).  Worst case
scenario if that happens is a psuedo flavor used by default on those
arches that doesn't build pl/python.

Thoughts/OKs?

Thanks,
Jeremy

Index: Makefile
===================================================================
RCS file: /cvs/ports/databases/postgresql/Makefile,v
retrieving revision 1.168
diff -u -p -r1.168 Makefile
--- Makefile    24 Sep 2012 19:57:02 -0000      1.168
+++ Makefile    9 Oct 2012 17:49:12 -0000
@@ -4,6 +4,7 @@ COMMENT-main=   PostgreSQL RDBMS (client)
 COMMENT-server=        PostgreSQL RDBMS (server)
 COMMENT-docs=  PostgreSQL RDBMS documentation
 COMMENT-contrib=PostgreSQL RDBMS contributions
+COMMENT-plpython=Python procedural language for PostgreSQL
 
 VERSION=       9.2.1
 DISTNAME=      postgresql-${VERSION}
@@ -11,6 +12,7 @@ PKGNAME-main= postgresql-client-${VERSIO
 PKGNAME-server=        postgresql-server-${VERSION}
 PKGNAME-docs=  postgresql-docs-${VERSION}
 PKGNAME-contrib=postgresql-contrib-${VERSION}
+PKGNAME-plpython=postgresql-plpython-${VERSION}
 
 CATEGORIES=    databases
 SHARED_LIBS=   ecpg            7.4 \
@@ -33,7 +35,7 @@ MASTER_SITES=         ftp://ftp5.us.postgresql.
        ftp://ftp5.es.postgresql.org/mirror/postgresql/source/v${VERSION}/ \
        ftp://ftp.postgresql.org/pub/source/v${VERSION}/
 
-MULTI_PACKAGES=        -docs -main -server -contrib
+MULTI_PACKAGES=        -docs -main -server -contrib -plpython
 
 # The -client SUBPACKAGE should build and run fine on static arches,
 # but the server requires loadable library support. Until we figure
@@ -49,9 +51,13 @@ USE_GMAKE=   Yes
 USE_GROFF =    Yes
 CONFIGURE_STYLE=gnu
 
+MODULES=       lang/python
+
 INCLUDES=      ${LOCALBASE}/include /usr/include/kerberosV
+CONFIGURE_ENV= ac_cv_path_PYTHON=${MODPY_BIN}
 CONFIGURE_ARGS=        --disable-rpath --with-openssl=/usr \
                --with-perl \
+               --with-python \
                --enable-integer-datetimes \
                --includedir="${PREFIX}/include/postgresql" \
                --datadir="${PREFIX}/share/postgresql" \
@@ -92,6 +98,9 @@ LIB_DEPENDS-contrib= databases/postgresq
                     devel/uuid
 WANTLIB-contrib =      ${WANTLIB-main} pq>=4 uuid
 
+LIB_DEPENDS-plpython=  ${MODPY_LIB_DEPENDS}
+WANTLIB-plpython =     c m pthread util ${MODPY_WANTLIB}
+
 WANTLIB-docs=
 PKG_ARCH-docs= *
 
@@ -120,6 +129,11 @@ NO_REGRESS=        Yes
 DOCS=  ${WRKSRC}/COPYRIGHT ${WRKSRC}/HISTORY \
        ${WRKSRC}/INSTALL ${WRKSRC}/README \
        ${WRKSRC}/doc/TODO
+
+# Work around Makefile issue where it attempts to rebuild
+# the documentation even if it is not necessary.
+pre-build:
+       touch ${WRKSRC}/doc/src/sgml/*-stamp
 
 post-install:
        ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/postgresql
Index: patches/patch-configure
===================================================================
RCS file: patches/patch-configure
diff -N patches/patch-configure
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-configure     9 Oct 2012 17:44:51 -0000
@@ -0,0 +1,21 @@
+$OpenBSD$
+
+Remove configure check, since the pl/python does work if you
+LD_PRELOAD libpthread when starting PostgreSQL.
+
+--- configure.orig     Wed Sep 19 23:47:58 2012
++++ configure  Tue Oct  9 18:32:29 2012
+@@ -7381,13 +7381,6 @@ pythreads=`${PYTHON} -c "import sys; print(int('thread
+ if test "$pythreads" = "1"; then
+   { $as_echo "$as_me:$LINENO: result: yes" >&5
+ $as_echo "yes" >&6; }
+-  case $host_os in
+-  openbsd*)
+-    { { $as_echo "$as_me:$LINENO: error: threaded Python not supported on 
this platform" >&5
+-$as_echo "$as_me: error: threaded Python not supported on this platform" >&2;}
+-   { (exit 1); exit 1; }; }
+-    ;;
+-  esac
+ else
+   { $as_echo "$as_me:$LINENO: result: no" >&5
+ $as_echo "no" >&6; }
Index: pkg/DESCR-plpython
===================================================================
RCS file: pkg/DESCR-plpython
diff -N pkg/DESCR-plpython
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pkg/DESCR-plpython  9 Oct 2012 17:31:56 -0000
@@ -0,0 +1,2 @@
+The PL/Python procedural language allows PostgreSQL functions to be
+written in the Python language.
Index: pkg/MESSAGE-plpython
===================================================================
RCS file: pkg/MESSAGE-plpython
diff -N pkg/MESSAGE-plpython
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pkg/MESSAGE-plpython        9 Oct 2012 17:33:20 -0000
@@ -0,0 +1,9 @@
+pl/python requires pthreads in order to work.  OpenBSD does not allow
+shared objects that link to pthreads to be opened via dlopen if the
+executable program does not link to pthreads.  So to use pl/python, you
+must ensure that PostgreSQL links to libpthread.  The easiest way to do
+this is adding the following login class to login.conf:
+
+postgresql:\
+        :setenv=LD_PRELOAD=libpthread.so:\
+        :tc=daemon: 
Index: pkg/PLIST-plpython
===================================================================
RCS file: pkg/PLIST-plpython
diff -N pkg/PLIST-plpython
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pkg/PLIST-plpython  9 Oct 2012 17:30:53 -0000
@@ -0,0 +1,8 @@
+@comment $OpenBSD$
+lib/postgresql/plpython2.so
+share/postgresql/extension/plpython2u.control
+share/postgresql/extension/plpython2u--1.0.sql
+share/postgresql/extension/plpython2u--unpackaged--1.0.sql
+share/postgresql/extension/plpythonu.control
+share/postgresql/extension/plpythonu--1.0.sql
+share/postgresql/extension/plpythonu--unpackaged--1.0.sql

Reply via email to