Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions | Variables

pg_config.c File Reference

#include "postgres_fe.h"
#include "port.h"
Include dependency graph for pg_config.c:

Go to the source code of this file.

Data Structures

struct  InfoItem

Functions

static void cleanup_path (char *path)
static void show_bindir (bool all)
static void show_docdir (bool all)
static void show_htmldir (bool all)
static void show_includedir (bool all)
static void show_pkgincludedir (bool all)
static void show_includedir_server (bool all)
static void show_libdir (bool all)
static void show_pkglibdir (bool all)
static void show_localedir (bool all)
static void show_mandir (bool all)
static void show_sharedir (bool all)
static void show_sysconfdir (bool all)
static void show_pgxs (bool all)
static void show_configure (bool all)
static void show_cc (bool all)
static void show_cppflags (bool all)
static void show_cflags (bool all)
static void show_cflags_sl (bool all)
static void show_ldflags (bool all)
static void show_ldflags_ex (bool all)
static void show_ldflags_sl (bool all)
static void show_libs (bool all)
static void show_version (bool all)
static void help (void)
static void advice (void)
static void show_all (void)
int main (int argc, char **argv)

Variables

static const char * progname
static char mypath [MAXPGPATH]
static const InfoItem info_items []

Function Documentation

static void advice ( void   )  [static]

Definition at line 463 of file pg_config.c.

References _, and progname.

Referenced by main().

{
    fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
}

static void cleanup_path ( char *  path  )  [static]

Definition at line 40 of file pg_config.c.

References MAXPGPATH.

Referenced by show_bindir(), show_docdir(), show_htmldir(), show_includedir(), show_includedir_server(), show_libdir(), show_localedir(), show_mandir(), show_pgxs(), show_pkgincludedir(), show_pkglibdir(), show_sharedir(), and show_sysconfdir().

{
#ifdef WIN32
    char       *ptr;

    /*
     * GetShortPathName() will fail if the path does not exist, or short names
     * are disabled on this file system.  In both cases, we just return the
     * original path.  This is particularly useful for --sysconfdir, which
     * might not exist.
     */
    GetShortPathName(path, path, MAXPGPATH - 1);

    /* Replace '\' with '/' */
    for (ptr = path; *ptr; ptr++)
    {
        if (*ptr == '\\')
            *ptr = '/';
    }
#endif
}

static void help ( void   )  [static]

Definition at line 426 of file pg_config.c.

References _, and progname.

Referenced by main().

{
    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(_("  --docdir              show location of documentation files\n"));
    printf(_("  --htmldir             show location of HTML documentation files\n"));
    printf(_("  --includedir          show location of C header files of the client\n"
             "                        interfaces\n"));
    printf(_("  --pkgincludedir       show location of other C header files\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(_("  --localedir           show location of locale support files\n"));
    printf(_("  --mandir              show location of manual pages\n"));
    printf(_("  --sharedir            show location of architecture-independent support files\n"));
    printf(_("  --sysconfdir          show location of system-wide configuration files\n"));
    printf(_("  --pgxs                show location of extension makefile\n"));
    printf(_("  --configure           show options given to \"configure\" script when\n"
             "                        PostgreSQL was built\n"));
    printf(_("  --cc                  show CC value used when PostgreSQL was built\n"));
    printf(_("  --cppflags            show CPPFLAGS value used when PostgreSQL was built\n"));
    printf(_("  --cflags              show CFLAGS value used when PostgreSQL was built\n"));
    printf(_("  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built\n"));
    printf(_("  --ldflags             show LDFLAGS value used when PostgreSQL was built\n"));
    printf(_("  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built\n"));
    printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
    printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
    printf(_("  --version             show the PostgreSQL version\n"));
    printf(_("  -?, --help            show this help, then exit\n"));
    printf(_("\nWith no arguments, all known items are shown.\n\n"));
    printf(_("Report bugs to <[email protected]>.\n"));
}

int main ( int  argc,
char **  argv 
)

Definition at line 480 of file pg_config.c.

References _, advice(), find_my_exec(), get_progname(), help(), i, mypath, NULL, PG_TEXTDOMAIN, progname, set_pglocale_pgservice(), show_all(), InfoItem::show_func, and InfoItem::switchname.

{
    int         i;
    int         j;
    int         ret;

    set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));

    progname = get_progname(argv[0]);

    /* check for --help */
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
        {
            help();
            exit(0);
        }
    }

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

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

    /* no arguments -> print everything */
    if (argc < 2)
    {
        show_all();
        exit(0);
    }

    for (i = 1; i < argc; i++)
    {
        for (j = 0; info_items[j].switchname != NULL; j++)
        {
            if (strcmp(argv[i], info_items[j].switchname) == 0)
            {
                (*info_items[j].show_func) (false);
                break;
            }
        }
        if (info_items[j].switchname == NULL)
        {
            fprintf(stderr, _("%s: invalid argument: %s\n"),
                    progname, argv[i]);
            advice();
            exit(1);
        }
    }

    return 0;
}

static void show_all ( void   )  [static]

Definition at line 469 of file pg_config.c.

References i, InfoItem::show_func, and InfoItem::switchname.

Referenced by main().

{
    int         i;

    for (i = 0; info_items[i].switchname != NULL; i++)
    {
        (*info_items[i].show_func) (true);
    }
}

static void show_bindir ( bool  all  )  [static]

Definition at line 70 of file pg_config.c.

References cleanup_path(), and mypath.

{
    char        path[MAXPGPATH];
    char       *lastsep;

    if (all)
        printf("BINDIR = ");
    /* assume we are located in the bindir */
    strcpy(path, mypath);
    lastsep = strrchr(path, '/');

    if (lastsep)
        *lastsep = '\0';

    cleanup_path(path);
    printf("%s\n", path);
}

static void show_cc ( bool  all  )  [static]

Definition at line 250 of file pg_config.c.

References _.

{
#ifdef VAL_CC
    if (all)
        printf("CC = ");
    printf("%s\n", VAL_CC);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_cflags ( bool  all  )  [static]

Definition at line 282 of file pg_config.c.

References _.

{
#ifdef VAL_CFLAGS
    if (all)
        printf("CFLAGS = ");
    printf("%s\n", VAL_CFLAGS);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_cflags_sl ( bool  all  )  [static]

Definition at line 298 of file pg_config.c.

References _.

{
#ifdef VAL_CFLAGS_SL
    if (all)
        printf("CFLAGS_SL = ");
    printf("%s\n", VAL_CFLAGS_SL);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_configure ( bool  all  )  [static]

Definition at line 234 of file pg_config.c.

References _.

{
#ifdef VAL_CONFIGURE
    if (all)
        printf("CONFIGURE = ");
    printf("%s\n", VAL_CONFIGURE);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_cppflags ( bool  all  )  [static]

Definition at line 266 of file pg_config.c.

References _.

{
#ifdef VAL_CPPFLAGS
    if (all)
        printf("CPPFLAGS = ");
    printf("%s\n", VAL_CPPFLAGS);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_docdir ( bool  all  )  [static]

Definition at line 89 of file pg_config.c.

References cleanup_path(), get_doc_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("DOCDIR = ");
    get_doc_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_htmldir ( bool  all  )  [static]

Definition at line 101 of file pg_config.c.

References cleanup_path(), get_html_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("HTMLDIR = ");
    get_html_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_includedir ( bool  all  )  [static]

Definition at line 113 of file pg_config.c.

References cleanup_path(), get_include_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("INCLUDEDIR = ");
    get_include_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_includedir_server ( bool  all  )  [static]

Definition at line 137 of file pg_config.c.

References cleanup_path(), get_includeserver_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("INCLUDEDIR-SERVER = ");
    get_includeserver_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_ldflags ( bool  all  )  [static]

Definition at line 314 of file pg_config.c.

References _.

{
#ifdef VAL_LDFLAGS
    if (all)
        printf("LDFLAGS = ");
    printf("%s\n", VAL_LDFLAGS);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_ldflags_ex ( bool  all  )  [static]

Definition at line 330 of file pg_config.c.

References _.

{
#ifdef VAL_LDFLAGS_EX
    if (all)
        printf("LDFLAGS_EX = ");
    printf("%s\n", VAL_LDFLAGS_EX);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_ldflags_sl ( bool  all  )  [static]

Definition at line 346 of file pg_config.c.

References _.

{
#ifdef VAL_LDFLAGS_SL
    if (all)
        printf("LDFLAGS_SL = ");
    printf("%s\n", VAL_LDFLAGS_SL);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_libdir ( bool  all  )  [static]

Definition at line 149 of file pg_config.c.

References cleanup_path(), get_lib_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("LIBDIR = ");
    get_lib_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_libs ( bool  all  )  [static]

Definition at line 362 of file pg_config.c.

References _.

{
#ifdef VAL_LIBS
    if (all)
        printf("LIBS = ");
    printf("%s\n", VAL_LIBS);
#else
    if (!all)
    {
        fprintf(stderr, _("not recorded\n"));
        exit(1);
    }
#endif
}

static void show_localedir ( bool  all  )  [static]

Definition at line 173 of file pg_config.c.

References cleanup_path(), get_locale_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("LOCALEDIR = ");
    get_locale_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_mandir ( bool  all  )  [static]

Definition at line 185 of file pg_config.c.

References cleanup_path(), get_man_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("MANDIR = ");
    get_man_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_pgxs ( bool  all  )  [static]

Definition at line 221 of file pg_config.c.

References cleanup_path(), get_pkglib_path(), mypath, and strlcat().

{
    char        path[MAXPGPATH];

    if (all)
        printf("PGXS = ");
    get_pkglib_path(mypath, path);
    strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_pkgincludedir ( bool  all  )  [static]

Definition at line 125 of file pg_config.c.

References cleanup_path(), get_pkginclude_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("PKGINCLUDEDIR = ");
    get_pkginclude_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_pkglibdir ( bool  all  )  [static]

Definition at line 161 of file pg_config.c.

References cleanup_path(), get_pkglib_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("PKGLIBDIR = ");
    get_pkglib_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_sharedir ( bool  all  )  [static]

Definition at line 197 of file pg_config.c.

References cleanup_path(), get_share_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("SHAREDIR = ");
    get_share_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_sysconfdir ( bool  all  )  [static]

Definition at line 209 of file pg_config.c.

References cleanup_path(), get_etc_path(), and mypath.

{
    char        path[MAXPGPATH];

    if (all)
        printf("SYSCONFDIR = ");
    get_etc_path(mypath, path);
    cleanup_path(path);
    printf("%s\n", path);
}

static void show_version ( bool  all  )  [static]

Definition at line 378 of file pg_config.c.

{
    if (all)
        printf("VERSION = ");
    printf("PostgreSQL " PG_VERSION "\n");
}


Variable Documentation

const InfoItem info_items[] [static]
Initial value:
 {
    {"--bindir", show_bindir},
    {"--docdir", show_docdir},
    {"--htmldir", show_htmldir},
    {"--includedir", show_includedir},
    {"--pkgincludedir", show_pkgincludedir},
    {"--includedir-server", show_includedir_server},
    {"--libdir", show_libdir},
    {"--pkglibdir", show_pkglibdir},
    {"--localedir", show_localedir},
    {"--mandir", show_mandir},
    {"--sharedir", show_sharedir},
    {"--sysconfdir", show_sysconfdir},
    {"--pgxs", show_pgxs},
    {"--configure", show_configure},
    {"--cc", show_cc},
    {"--cppflags", show_cppflags},
    {"--cflags", show_cflags},
    {"--cflags_sl", show_cflags_sl},
    {"--ldflags", show_ldflags},
    {"--ldflags_ex", show_ldflags_ex},
    {"--ldflags_sl", show_ldflags_sl},
    {"--libs", show_libs},
    {"--version", show_version},
    {NULL, NULL}
}

Definition at line 397 of file pg_config.c.

char mypath[MAXPGPATH] [static]
const char* progname [static]

Definition at line 29 of file pg_config.c.