Thread: pg_config

pg_config

From
Andrew Dunstan
Date:


Peter Eisentraut wrote:

>Andrew Dunstan wrote:
>
>
>>To that extent is it not broken by relocated installations that we
>>have now made some provision for?
>>
>>
>
>Well, then it should be fixed to take relocated installations into
>account.
>
>Relocatable installations are by nature a pretty broken feature.  When
>you use pg_config to locate, say, libpq, then compile your third-party
>package, and then move libpq somewhere else, nothing can save you
>(except moving libpq back).  At least on Unix, relocatable
>installations are a walking cane when you need parallel installations
>for upgrades, but they'll never work reliably in general.
>
>
>

Of course, if you rely on pg_config and then move the installation you
will put a very large hole in your foot. But we can't make things
totally idiot-proof - they will just build a better idiot.

Here is an attempt to do the Right Thing (tm) in C.

cheers

andrew
Index: Makefile
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_config/Makefile,v
retrieving revision 1.6
diff -c -r1.6 Makefile
*** Makefile    29 Nov 2003 19:52:04 -0000    1.6
--- Makefile    20 Jul 2004 20:05:12 -0000
***************
*** 4,24 ****
  top_builddir = ../../..
  include $(top_builddir)/src/Makefile.global

! all: pg_config

! pg_config: pg_config.sh $(top_builddir)/src/Makefile.global Makefile
!     sed -e 's,@bindir@,$(bindir),g' \
!         -e 's,@includedir@,$(includedir),g' \
!         -e 's,@includedir_server@,$(includedir_server),g' \
!         -e 's,@libdir@,$(libdir),g' \
!         -e 's,@pkglibdir@,$(pkglibdir),g' \
!         -e "s|@configure@|$(configure_args)|g" \
!         -e 's,@version@,$(VERSION),g' \
!       $< >$@
!     chmod a+x $@

  install: all installdirs
!     $(INSTALL_SCRIPT) pg_config $(DESTDIR)$(bindir)/pg_config

  installdirs:
      $(mkinstalldirs) $(DESTDIR)$(bindir)
--- 4,23 ----
  top_builddir = ../../..
  include $(top_builddir)/src/Makefile.global

! OBJS=   pg_config.o exec.o

! override CPPFLAGS :=  -DFRONTEND -I$(libpq_srcdir) -DVAL_CONFIGURE="\"$(configure_args)\"" $(CPPFLAGS)
!
! all: submake-libpgport pg_config
!
! exec.c: % : $(top_srcdir)/src/port/%
!     rm -f $@ && $(LN_S) $< .
!
! pg_config: $(OBJS)
!     $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $@$(X)

  install: all installdirs
!     $(INSTALL_SCRIPT) pg_config((X) $(DESTDIR)$(bindir)/pg_config$(X)

  installdirs:
      $(mkinstalldirs) $(DESTDIR)$(bindir)
***************
*** 27,30 ****
      rm -f $(DESTDIR)$(bindir)/pg_config

  clean distclean maintainer-clean:
!     rm -f pg_config
--- 26,29 ----
      rm -f $(DESTDIR)$(bindir)/pg_config

  clean distclean maintainer-clean:
!     rm -f pg_config$(X) $(OBJS)
/*-------------------------------------------------------------------------
 *
 * pg_config.c
 *
 * This program reports various pieces of information about the
 * installed version of PostgreSQL.  Packages that interface to
 * PostgreSQL can use it to configure their build.
 *
 * This is a C implementation of the previous shell script written by
 * Peter Eisentraut <peter_e@gmx.net>, with adjustments made to
 * accomodate the possibility that the installation has been relocated from
 * the place originally configured.
 *
 * author of C translation: Andrew Dunstan     mailto:andrew@dunslane.net
 *
 * This code is released under the terms of the PostgreSQL License.
 *
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
 *
 * $PostgreSQL:$
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"
#include "port.h"
#include <stdio.h>

#define _(x) gettext((x))

char * progname;

static void
help()
{
    printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"),progname);
    printf(_("Usage:\n"));
    printf(_("  %s OPTION...\n\n"),progname);
    printf(_("Options:\n"));
    printf(_("  --bindir              show location of user executables\n"));
    printf(_("  --includedir          show location of C header files of the client\n"));
    printf(_("                        interfaces\n"));
    printf(_("  --includedir-server   show location of C header files for the server\n"));
    printf(_("  --libdir              show location of object code libraries\n"));
    printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
    printf(_("  --configure           show options given to 'configure' script when\n"));
    printf(_("                        PostgreSQL was built\n"));
    printf(_("  --version             show the PostgreSQL version, then exit\n"));
    printf(_("  --help                show this help, then exit\n\n"));
    printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
}

static void
advice()
{
    fprintf(stderr,_("\nTry \"%s --help\" for more information\n"),progname);
}


int
main (int argc, char ** argv)
{
    int i;
    int ret;
    char mypath[MAXPGPATH];
    char otherpath[MAXPGPATH];

    progname = (char *)get_progname(argv[0]);



    if (argc < 2)
    {
        fprintf(stderr,_("%s: argument required\n"),progname);
        advice();
        exit(1);
    }

    for (i=1; i < argc; i++)
    {
        if (strcmp(argv[i],"--bindir") == 0 ||
            strcmp(argv[i],"--includedir") == 0 ||
            strcmp(argv[i],"--includedir-server") == 0 ||
            strcmp(argv[i],"--libdir") == 0 ||
            strcmp(argv[i],"--pkglibdir") == 0 ||
            strcmp(argv[i],"--configure") == 0
            )
        {
            /* come back to these later */

            continue;
        }

        if (strcmp(argv[i],"--version") == 0)
        {
            printf("PostgreSQL " PG_VERSION "\n");
            exit(0);
        }
        if (strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-?") == 0)
        {
            help();
            exit(0);
        }
        fprintf(stderr,_("%s: invalid argument: %s\n"),progname,argv[i]);
        advice();
        exit(1);
    }

    ret = find_my_exec(argv[0],mypath);

    if (ret)
    {
        fprintf(stderr,"%s: could not locate my own executable\n",progname);
        exit(1);
    }



    for (i=1; i < argc; i++)
    {
        if (strcmp(argv[i],"--configure") == 0)
        {
            /* the VAL_CONFIGURE macro must be defined by the Makefile */

            printf("%s\n",VAL_CONFIGURE);
            continue;
        }

        if (strcmp(argv[i],"--bindir") == 0)
        {
            /* assume we are located in the bindir */

            char * lastsep;
            strcpy(otherpath,mypath);
            lastsep = strrchr(otherpath,'/');
            if (lastsep)
                *lastsep = '\0';
        }
        else if (strcmp(argv[i],"--includedir") == 0)
            get_include_path(mypath,otherpath);
        else if (strcmp(argv[i],"--includedir-server") ==0)
            get_pkginclude_path(mypath,otherpath);
        else if (strcmp(argv[i],"--libdir") == 0)
            get_include_path(mypath,otherpath);
        else if (strcmp(argv[i],"--pkglibdir") == 0)
            get_pkglib_path(mypath,otherpath);

        printf("%s\n",otherpath);


    }

    return 0;
}

Re: pg_config

From
Andrew Dunstan
Date:
There are a couple of things that need adjustment:

1. typo in the makefile - ((X) should be $(X)
2. these cases need to be fixed:

        else if (strcmp(argv[i],"--includedir-server") ==0)
            get_pkginclude_path(mypath,otherpath);
        else if (strcmp(argv[i],"--libdir") == 0)
            get_include_path(mypath,otherpath);

We might actually need one or two functions in port/path.c to handle them.

cheers

andrew



Bruce Momjian wrote:

>Your patch has been added to the PostgreSQL unapplied patches list at:
>
>    http://momjian.postgresql.org/cgi-bin/pgpatches
>
>It will be applied as soon as one of the PostgreSQL committers reviews
>and approves it.
>
>
>
>

Re: pg_config

From
Bruce Momjian
Date:
Andrew Dunstan wrote:
>
> There are a couple of things that need adjustment:
>
> 1. typo in the makefile - ((X) should be $(X)

OK.

> 2. these cases need to be fixed:
>
>         else if (strcmp(argv[i],"--includedir-server") ==0)
>             get_pkginclude_path(mypath,otherpath);
>         else if (strcmp(argv[i],"--libdir") == 0)
>             get_include_path(mypath,otherpath);
>
> We might actually need one or two functions in port/path.c to handle them.

What is the problem here?  Why do we need additional port/path
functions?  I see libdir is mismatched with include_path.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: pg_config

From
Andrew Dunstan
Date:

Bruce Momjian wrote:

>Andrew Dunstan wrote:
>
>
>>2. these cases need to be fixed:
>>
>>        else if (strcmp(argv[i],"--includedir-server") ==0)
>>            get_pkginclude_path(mypath,otherpath);
>>        else if (strcmp(argv[i],"--libdir") == 0)
>>            get_include_path(mypath,otherpath);
>>
>>We might actually need one or two functions in port/path.c to handle them.
>>
>>
>
>What is the problem here?  Why do we need additional port/path
>functions?  I see libdir is mismatched with include_path.
>
>

I don't see a function there to report the libdir at all (only
pkglibdir), and for includedir-server we would need either to append
"/server" or to have a function in path.c that reported it for us correctly.

cheers

andrew

Re: pg_config

From
Peter Eisentraut
Date:
Andrew Dunstan wrote:
> I don't see a function there to report the libdir at all (only
> pkglibdir), and for includedir-server we would need either to append
> "/server" or to have a function in path.c that reported it for us
> correctly.

These paths can all be more or less independently (or at least
unpredictably) different, so you apparently need to treat each of them
individually.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: pg_config

From
Bruce Momjian
Date:
Would someone address this and make a new patch?  The files are in the
patch queue.  Thanks.

---------------------------------------------------------------------------

Peter Eisentraut wrote:
> Andrew Dunstan wrote:
> > I don't see a function there to report the libdir at all (only
> > pkglibdir), and for includedir-server we would need either to append
> > "/server" or to have a function in path.c that reported it for us
> > correctly.
>
> These paths can all be more or less independently (or at least
> unpredictably) different, so you apparently need to treat each of them
> individually.
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: pg_config

From
Bruce Momjian
Date:

Patch applied.  Thanks.

I made all the changes you suggested and the additions to path.c for the
new parameters.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
>
> There are a couple of things that need adjustment:
>
> 1. typo in the makefile - ((X) should be $(X)
> 2. these cases need to be fixed:
>
>         else if (strcmp(argv[i],"--includedir-server") ==0)
>             get_pkginclude_path(mypath,otherpath);
>         else if (strcmp(argv[i],"--libdir") == 0)
>             get_include_path(mypath,otherpath);
>
> We might actually need one or two functions in port/path.c to handle them.
>
> cheers
>
> andrew
>
>
>
> Bruce Momjian wrote:
>
> >Your patch has been added to the PostgreSQL unapplied patches list at:
> >
> >    http://momjian.postgresql.org/cgi-bin/pgpatches
> >
> >It will be applied as soon as one of the PostgreSQL committers reviews
> >and approves it.
> >
> >
> >
> >
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: pg_config

From
Peter Eisentraut
Date:
Bruce Momjian wrote:
> Patch applied.  Thanks.
>
> I made all the changes you suggested and the additions to path.c for
> the new parameters.

I think you forgot to commit the new source files.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: pg_config

From
Bruce Momjian
Date:
Oops, sorry, done.

---------------------------------------------------------------------------

Peter Eisentraut wrote:
> Bruce Momjian wrote:
> > Patch applied.  Thanks.
> >
> > I made all the changes you suggested and the additions to path.c for
> > the new parameters.
>
> I think you forgot to commit the new source files.
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: pg_config

From
Peter Eisentraut
Date:
Bruce Momjian wrote:
> Oops, sorry, done.

The --pgxs option seems to have gotten lost in the conversion.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: pg_config

From
Andrew Dunstan
Date:

Peter Eisentraut wrote:

>Bruce Momjian wrote:
>
>
>>Oops, sorry, done.
>>
>>
>
>The --pgxs option seems to have gotten lost in the conversion.
>
>
>

It wasn't there when I did the conversion. Usual problem of duelling
patches. Can you fix it, or do you need me to send in a patch?

cheers

andrew

Re: pg_config

From
Bruce Momjian
Date:
OK, addition made, and I added documentation for -pgxs.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
>
>
> Peter Eisentraut wrote:
>
> >Bruce Momjian wrote:
> >
> >
> >>Oops, sorry, done.
> >>
> >>
> >
> >The --pgxs option seems to have gotten lost in the conversion.
> >
> >
> >
>
> It wasn't there when I did the conversion. Usual problem of duelling
> patches. Can you fix it, or do you need me to send in a patch?
>
> cheers
>
> andrew
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/ref/pg_config-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/pg_config-ref.sgml,v
retrieving revision 1.17
diff -c -c -r1.17 pg_config-ref.sgml
*** doc/src/sgml/ref/pg_config-ref.sgml    29 Nov 2003 19:51:39 -0000    1.17
--- doc/src/sgml/ref/pg_config-ref.sgml    2 Aug 2004 12:31:43 -0000
***************
*** 25,30 ****
--- 25,31 ----
      <arg>--includedir-server</arg>
      <arg>--libdir</arg>
      <arg>--pkglibdir</arg>
+     <arg>--pgxs</arg>
      <arg>--configure</arg>
      <arg>--version</arg>
     </group>
***************
*** 101,106 ****
--- 102,116 ----
      </varlistentry>

      <varlistentry>
+      <term><option>--pgxs</option></>
+      <listitem>
+       <para>
+        Print the location of extension makefiles.
+      </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>--configure</option></>
       <listitem>
        <para>
Index: src/bin/pg_config/pg_config.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_config/pg_config.c,v
retrieving revision 1.2
diff -c -c -r1.2 pg_config.c
*** src/bin/pg_config/pg_config.c    1 Aug 2004 14:01:36 -0000    1.2
--- src/bin/pg_config/pg_config.c    2 Aug 2004 12:31:48 -0000
***************
*** 43,48 ****
--- 43,49 ----
      printf(_("  --includedir-server   show location of C header files for the server\n"));
      printf(_("  --libdir              show location of object code libraries\n"));
      printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
+     printf(_("  --pgxs                show location of extension makefile\n"));
      printf(_("  --configure           show options given to 'configure' script when\n"));
      printf(_("                        PostgreSQL was built\n"));
      printf(_("  --version             show the PostgreSQL version, then exit\n"));
***************
*** 81,86 ****
--- 82,88 ----
              strcmp(argv[i],"--includedir-server") == 0 ||
              strcmp(argv[i],"--libdir") == 0 ||
              strcmp(argv[i],"--pkglibdir") == 0 ||
+             strcmp(argv[i],"--pgxs") == 0 ||
              strcmp(argv[i],"--configure") == 0)
          {
              /* come back to these later */
***************
*** 136,141 ****
--- 138,148 ----
              get_lib_path(mypath,otherpath);
          else if (strcmp(argv[i],"--pkglibdir") == 0)
              get_pkglib_path(mypath,otherpath);
+         else if (strcmp(argv[i],"--pgxs") == 0)
+         {
+             get_pkglib_path(mypath,otherpath);
+             strncat(otherpath, "/pgxs", MAXPGPATH-1);
+         }

          printf("%s\n",otherpath);
      }