~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/bin/pg_config/pg_config.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * pg_config.c
 
4
 *
 
5
 * This program reports various pieces of information about the
 
6
 * installed version of PostgreSQL.  Packages that interface to
 
7
 * PostgreSQL can use it to configure their build.
 
8
 *
 
9
 * This is a C implementation of the previous shell script written by
 
10
 * Peter Eisentraut <peter_e@gmx.net>, with adjustments made to
 
11
 * accomodate the possibility that the installation has been relocated from
 
12
 * the place originally configured.
 
13
 *
 
14
 * author of C translation: Andrew Dunstan         mailto:andrew@dunslane.net
 
15
 *
 
16
 * This code is released under the terms of the PostgreSQL License.
 
17
 *
 
18
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
19
 *
 
20
 * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.10 2004-12-31 22:03:03 pgsql Exp $
 
21
 *
 
22
 *-------------------------------------------------------------------------
 
23
 */
 
24
 
 
25
#include "postgres.h"
 
26
#include "port.h"
 
27
#include <stdio.h>
 
28
 
 
29
#define _(x) gettext((x))
 
30
 
 
31
static const char *progname;
 
32
 
 
33
static void
 
34
help(void)
 
35
{
 
36
        printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
 
37
        printf(_("Usage:\n"));
 
38
        printf(_("  %s OPTION...\n\n"), progname);
 
39
        printf(_("Options:\n"));
 
40
        printf(_("  --bindir              show location of user executables\n"));
 
41
        printf(_("  --includedir          show location of C header files of the client\n"
 
42
                 "                        interfaces\n"));
 
43
        printf(_("  --includedir-server   show location of C header files for the server\n"));
 
44
        printf(_("  --libdir              show location of object code libraries\n"));
 
45
        printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
 
46
        printf(_("  --pgxs                show location of extension makefile\n"));
 
47
        printf(_("  --configure           show options given to \"configure\" script when\n"
 
48
                         "                        PostgreSQL was built\n"));
 
49
        printf(_("  --version             show the PostgreSQL version, then exit\n"));
 
50
        printf(_("  --help                show this help, then exit\n\n"));
 
51
        printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
 
52
}
 
53
 
 
54
static void
 
55
advice(void)
 
56
{
 
57
        fprintf(stderr, _("\nTry \"%s --help\" for more information\n"), progname);
 
58
}
 
59
 
 
60
 
 
61
int
 
62
main(int argc, char **argv)
 
63
{
 
64
        int                     i;
 
65
        int                     ret;
 
66
        char            mypath[MAXPGPATH];
 
67
        char            otherpath[MAXPGPATH];
 
68
 
 
69
        set_pglocale_pgservice(argv[0], "pg_config");
 
70
 
 
71
        progname = get_progname(argv[0]);
 
72
 
 
73
        if (argc < 2)
 
74
        {
 
75
                fprintf(stderr, _("%s: argument required\n"), progname);
 
76
                advice();
 
77
                exit(1);
 
78
        }
 
79
 
 
80
        for (i = 1; i < argc; i++)
 
81
        {
 
82
                if (strcmp(argv[i], "--bindir") == 0 ||
 
83
                        strcmp(argv[i], "--includedir") == 0 ||
 
84
                        strcmp(argv[i], "--includedir-server") == 0 ||
 
85
                        strcmp(argv[i], "--libdir") == 0 ||
 
86
                        strcmp(argv[i], "--pkglibdir") == 0 ||
 
87
                        strcmp(argv[i], "--pgxs") == 0 ||
 
88
                        strcmp(argv[i], "--configure") == 0)
 
89
                {
 
90
                        /* come back to these later */
 
91
                        continue;
 
92
                }
 
93
 
 
94
                if (strcmp(argv[i], "--version") == 0)
 
95
                {
 
96
                        printf("PostgreSQL " PG_VERSION "\n");
 
97
                        exit(0);
 
98
                }
 
99
                if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
 
100
                {
 
101
                        help();
 
102
                        exit(0);
 
103
                }
 
104
                fprintf(stderr, _("%s: invalid argument: %s\n"), progname, argv[i]);
 
105
                advice();
 
106
                exit(1);
 
107
        }
 
108
 
 
109
        ret = find_my_exec(argv[0], mypath);
 
110
 
 
111
        if (ret)
 
112
        {
 
113
                fprintf(stderr, _("%s: could not find own executable\n"), progname);
 
114
                exit(1);
 
115
        }
 
116
 
 
117
        for (i = 1; i < argc; i++)
 
118
        {
 
119
                if (strcmp(argv[i], "--configure") == 0)
 
120
                {
 
121
                        /* the VAL_CONFIGURE macro must be defined by the Makefile */
 
122
                        printf("%s\n", VAL_CONFIGURE);
 
123
                        continue;
 
124
                }
 
125
 
 
126
                if (strcmp(argv[i], "--bindir") == 0)
 
127
                {
 
128
                        /* assume we are located in the bindir */
 
129
                        char       *lastsep;
 
130
 
 
131
                        strcpy(otherpath, mypath);
 
132
                        lastsep = strrchr(otherpath, '/');
 
133
                        if (lastsep)
 
134
                                *lastsep = '\0';
 
135
                }
 
136
                else if (strcmp(argv[i], "--includedir") == 0)
 
137
                        get_include_path(mypath, otherpath);
 
138
                else if (strcmp(argv[i], "--includedir-server") == 0)
 
139
                        get_includeserver_path(mypath, otherpath);
 
140
                else if (strcmp(argv[i], "--libdir") == 0)
 
141
                        get_lib_path(mypath, otherpath);
 
142
                else if (strcmp(argv[i], "--pkglibdir") == 0)
 
143
                        get_pkglib_path(mypath, otherpath);
 
144
                else if (strcmp(argv[i], "--pgxs") == 0)
 
145
                {
 
146
                        get_pkglib_path(mypath, otherpath);
 
147
                        strncat(otherpath, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1);
 
148
                }
 
149
 
 
150
                printf("%s\n", otherpath);
 
151
        }
 
152
 
 
153
        return 0;
 
154
}