pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo Moya <rodrigo@gnome-db.org>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: Roberto Costa <rob.costa@libero.it>
Cc: PostgreSQL interfaces mailing list <pgsql-interfaces@postgresql.org>
Subject: Re: Automatic detection of PostgreSQL version
Date: 12 Mar 2003 13:51:44 +0100
Message-ID: <1047473504.1016.28.camel@azkoyen.gnome-db.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0303120121460.1617-100000@peter.localdomain>
References: <Pine.LNX.4.44.0303120121460.1617-100000@peter.localdomain>

On Wed, 2003-03-12 at 01:35, Peter Eisentraut wrote:
> Roberto Costa writes:
> 
> > What I'm currently doing is searching typical include directories (like
> > /usr/include, /usr/local/share/include, ...) for the presence of a
> > directory named postgresql or pgsql that contains config.h or
> > pg_config.h (used since PostgreSQL 7.2, if I'm not wrong). When such a
> > file is found, I grep it for a line that starts with "#define
> > PG_VERSION" and I expect the version follow and be in the form "x.y.z".
> > This works for the latest PostgreSQL versions that I could test,
> > however I don't know whether this check may work with earlier ones. In
> > reality I even ignore if this kind of check is the best way to get what
> > I want.
> 
> All of that seems highly unusual.  configure scripts are supposed to check
> for alternative features in libraries, not search the entire file system
> for the "best" library.  I suggest you just include the libpq++ header
> file in your code and be done with it.  If it's missing the user will get
> an error from the compiler and will know what to do.  
>
well, many power users will know what to do, but a lot other users will
not. So I guess a configure check and --with/--without arguments might
be the correct way to do it. I myself have the following in my
configure.in:

dnl Test for PostgreSQL
try_postgres=true
AC_ARG_WITH(postgres,
[  --with-postgres=<directory>  use postgres backend in <directory>],[
if test $withval = no
then
        try_postgres=false
elif test $withval = yes
then
        dir="/usr/local"
else
        dir=$withval
fi
])
postgresdir=""
if test $try_postgres = true
then
        AC_MSG_CHECKING(for Postgres files)
        for d in $dir /usr /usr/local/postgres /opt/postgres
/opt/packages/postgres /disk/postgres /usr/local/pgsql
        do
                if test -f $d/lib/libpq.so
                then
                        AC_MSG_RESULT(found Postgres in $d)
                        postgresdir=$d
                        break
                fi
        done
        if test x$postgresdir = x
        then
                AC_MSG_WARN(Postgres backend not used)
        else
                if test -f ${postgresdir}/include/libpq-fe.h
                then
                        POSTGRES_CFLAGS=-I${postgresdir}/include
                elif test -f ${postgresdir}/include/pgsql/libpq-fe.h
                then
                        POSTGRES_CFLAGS=-I${postgresdir}/include/pgsql
                elif test -f
${postgresdir}/include/postgresql/libpq-fe.h
                then
                       
POSTGRES_CFLAGS=-I${postgresdir}/include/postgresql
                else
                        AC_MSG_WARN(Postgres include files not found,
backend not used)
                        postgresdir=""
                fi
                POSTGRES_LIBS="-L${postgresdir}/lib -lpq"
                AC_DEFINE(HAVE_POSTGRES)
        fi
fi
                                                                                
AM_CONDITIONAL(POSTGRES, test x$postgresdir != x)

thus, you can have your user specify which version of postgres she wants
to compile against, by just using a --with-postgres=/dir/to/use

cheers




view thread (5+ messages)  latest in thread

Message-ID: <1047473504.1016.28.camel@azkoyen.gnome-db.org>
Permalink:  ../1047473504.1016.28.camel@azkoyen.gnome-db.org/
Also on:    postgresql.org/message-id/1047473504.1016.28.camel@azkoyen.gnome-db.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: rodrigo@gnome-db.org, peter_e@gmx.net, rob.costa@libero.it
  Subject: Re: Automatic detection of PostgreSQL version
  In-Reply-To: <1047473504.1016.28.camel@azkoyen.gnome-db.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox