lpsmith / postgresql-libpq

Low-level Haskell bindings for libpq
BSD 3-Clause "New" or "Revised" License
19 stars 18 forks source link

Update postgresql-libpq.cabal #13

Closed AlexanderAA closed 10 years ago

AlexanderAA commented 10 years ago

Fix issue #12 Credit goes to the maintainer of the OpenBSD package, David Coppa. Tested on OpenBSD 5.4-release

lpsmith commented 10 years ago

Thanks, but this breaks the build on my linux box. You are going to have to hide those additional Extra-libraries behind an appropriate .cabal file conditional. Let me investigate the right syntax, which I can't quite remember off the top of my head.

lpsmith commented 10 years ago

Ok, this should almost work:

Extra-Libraries: pq
if os(openbsd)
    Extra-Libraries:  crypto ssl com_err asn1 krb5 wind roken heimbase

Try this out on your platform, and amend your pull request. I'm not sure if the name of the os is quite right; you should check the value of System.Info.os per the cabal package developer's guide.

AlexanderAA commented 10 years ago

Thanks Leon, I can confirm that the conditional works fine on OpenBSD 5.4-release and Debian "wheezy".

lpsmith commented 10 years ago

Thanks!

lpsmith commented 10 years ago

Looking at this email thread a bit more carefully, I would certainly like to use the output of pg_config to set Extra-Libraries appropriately, and I can certainly help with that as I've done a bit of Setup.hs hacking. However I guess I don't really understand the issue brought up that the order of the libraries emitted by pg_config not being quite right, and whether or not it's possible to fix that in Setup.hs in any sane way.

AlexanderAA commented 10 years ago

Thanks Leon.

I can't agree more; "os(openbsd)" conditional should certainly be replaced with something else, which tests for features, not platform. Unfortunately, I do not know how to implement that yet.

In the meantime, here is the output from pg_config on OpenBSD 5.4. It seems, that the missing libraries are listed in LDFLAGS:

$ pg_config
BINDIR = /usr/local/bin
DOCDIR = /usr/local/share/doc/postgresql
HTMLDIR = /usr/local/share/doc/postgresql
INCLUDEDIR = /usr/local/include/postgresql
PKGINCLUDEDIR = /usr/local/include/postgresql
INCLUDEDIR-SERVER = /usr/local/include/postgresql/server
LIBDIR = /usr/local/lib
PKGLIBDIR = /usr/local/lib/postgresql
LOCALEDIR = /usr/local/share/locale
MANDIR = /usr/local/man
SHAREDIR = /usr/local/share/postgresql
SYSCONFDIR = /etc/postgresql
PGXS = /usr/local/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--disable-rpath' '--with-openssl=/usr' '--with-perl' '--with-pam=no' '--enable-integer-datetimes' '--includedir=/usr/local/include/postgresql' '--datadir=/usr/local/share/postgresql' '--docdir=/usr/local/share/doc/postgresql' '--with-includes=' '--with-libraries=/usr/local/lib' '--with-system-tzdata=/usr/share/zoneinfo' '--with-openssl' '--with-ossp-uuid' '--with-libxml' '--with-krb5' '--disable-thread-safety' '--prefix=/usr/local' '--sysconfdir=/etc' '--mandir=/usr/local/man' '--infodir=/usr/local/info' '--localstatedir=/var' '--disable-silent-rules' 'CC=cc' 'CFLAGS=-O2 -pipe' 'LDFLAGS=-L/usr/local/lib -L/usr/lib -lkrb5 -lasn1 -lcrypto -lwind -lroken -lcom_err -lheimbase' 'CPPFLAGS=-I/usr/local/include -I/usr/include/kerberosV '
CC = cc
CPPFLAGS = -I/usr/local/include -I/usr/include/kerberosV -I/usr/local/include/libxml2 -I/usr/local/include
CFLAGS = -O2 -pipe -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL = -fpic -DPIC
LDFLAGS = -L/usr/local/lib -L/usr/lib -lkrb5 -lasn1 -lcrypto -lwind -lroken -lcom_err -lheimbase -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -Wl,-Bdynamic
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgport -lxml2 -lssl -lcrypto -lz -lreadline -ltermcap -lm 
VERSION = PostgreSQL 9.2.4
$ pg_config --configure
'--disable-rpath' '--with-openssl=/usr' '--with-perl' '--with-pam=no' '--enable-integer-datetimes' '--includedir=/usr/local/include/postgresql' '--datadir=/usr/local/share/postgresql' '--docdir=/usr/local/share/doc/postgresql' '--with-includes=' '--with-libraries=/usr/local/lib' '--with-system-tzdata=/usr/share/zoneinfo' '--with-openssl' '--with-ossp-uuid' '--with-libxml' '--with-krb5' '--disable-thread-safety' '--prefix=/usr/local' '--sysconfdir=/etc' '--mandir=/usr/local/man' '--infodir=/usr/local/info' '--localstatedir=/var' '--disable-silent-rules' 'CC=cc' 'CFLAGS=-O2 -pipe' 'LDFLAGS=-L/usr/local/lib -L/usr/lib -lkrb5 -lasn1 -lcrypto -lwind -lroken -lcom_err -lheimbase' 'CPPFLAGS=-I/usr/local/include -I/usr/include/kerberosV '
AlexanderAA commented 10 years ago

pg_config output, Debian "wheezy" (for comparison):

$ pg_config             
BINDIR = /usr/lib/postgresql/9.1/bin
DOCDIR = /usr/share/doc/postgresql-doc-9.1
HTMLDIR = /usr/share/doc/postgresql-doc-9.1
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/9.1/server
LIBDIR = /usr/lib
PKGLIBDIR = /usr/lib/postgresql/9.1/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/9.1/man
SHAREDIR = /usr/share/postgresql/9.1
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/9.1/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-krb5' '--with-gssapi' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' '--with-tclconfig=/usr/lib/tcl8.5' '--with-tkconfig=/usr/lib/tk8.5' '--with-includes=/usr/include/tcl8.5' 'PYTHON=/usr/bin/python' '--mandir=/usr/share/postgresql/9.1/man' '--docdir=/usr/share/doc/postgresql-doc-9.1' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/9.1' '--bindir=/usr/lib/postgresql/9.1/bin' '--libdir=/usr/lib/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-debug' '--disable-rpath' '--with-ossp-uuid' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie' 'CPPFLAGS=-D_FORTIFY_SOURCE=2 -DLINUX_OOM_ADJ=0' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now -Wl,--as-needed'
CC = gcc
CPPFLAGS = -D_FORTIFY_SOURCE=2 -DLINUX_OOM_ADJ=0 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/tcl8.5
CFLAGS = -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g
CFLAGS_SL = -fpic
LDFLAGS = -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -L/usr/lib -Wl,--as-needed
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -ledit -lcrypt -ldl -lm 
VERSION = PostgreSQL 9.1.9
$ pg_config --configure 
'--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-krb5' '--with-gssapi' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-ldap' '--with-tclconfig=/usr/lib/tcl8.5' '--with-tkconfig=/usr/lib/tk8.5' '--with-includes=/usr/include/tcl8.5' 'PYTHON=/usr/bin/python' '--mandir=/usr/share/postgresql/9.1/man' '--docdir=/usr/share/doc/postgresql-doc-9.1' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/9.1' '--bindir=/usr/lib/postgresql/9.1/bin' '--libdir=/usr/lib/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-debug' '--disable-rpath' '--with-ossp-uuid' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie' 'CPPFLAGS=-D_FORTIFY_SOURCE=2 -DLINUX_OOM_ADJ=0' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now -Wl,--as-needed'
lpsmith commented 10 years ago

Well, my recommendation for Setup.hs hacking is first to be patient, it's going to take quite a bit of effort for small but very tangible improvements in functionality. Second, install groom, and then use that to pretty-print various cabal data structures until you see the data you are looking for. Populating a field with some useless information can help you locate your goal too. From there you can deduce where to look in the cabal haddocks for further information. A few times I've had to resort to reading the cabal source as well.

It's also worth pointing out that you need Build-type: Custom in the .cabal file; Build-type: Simple tends to ignore the Setup.hs file altogether, unless you specifically run it (and don't use the cabal executable provided by the cabal-install package)

So for example, here's a simple Setup.hs that prints out the main data structures associated with a confHook:

import Distribution.Simple
import Text.Groom

main = defaultMainWithHooks simpleUserHooks {
    confHook = \pkg flags -> do
        putStr "pkg:\n\n"
        putStr (groom pkg) 
        putStr "\n\n\n\n"
        putStr "flags:\n\n"
        putStr (groom flags)
        putStr "\n\n\n\n"
        putStr "running default confHook:\n\n"
        lbi <- confHook simpleUserHooks pkg flags
        putStr "\n\n\n\n"
        putStr "lbi:\n\n"
        putStr (groom lbi)
        putStr "\n\n\n\n"
        return lbi
  }

Then just cabal configure and inspect the output; this generates a lot of output so you almost certainly want to pipe this to less -S or a file or whatever you prefer, not least so you can search for strings in the output. I suspect what you are looking for is probably in the ConfigFlags structure.

lpsmith commented 10 years ago

You might also want to figure out exactly how Cabal generates it's flags for gcc and ld, I don't know if that's particularly well documented or not (documentation is often a little sparse, sadly) or if you'll need to resort to reading the source. You might also find it helpful to ask questions on the #hackage irc channel on FreeNode.