1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/*-------------------------------------------------------------------------
*
* 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
* accommodate 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-2022, PostgreSQL Global Development Group
*
* src/bin/pg_config/pg_config.c
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "common/config_info.h"
#include "port.h"
static const char *progname;
/*
* Table of known information items
*
* Be careful to keep this in sync with the help() display.
*/
typedef struct
{
const char *switchname;
const char *configname;
} InfoItem;
static const InfoItem info_items[] = {
{"--bindir", "BINDIR"},
{"--docdir", "DOCDIR"},
{"--htmldir", "HTMLDIR"},
{"--includedir", "INCLUDEDIR"},
{"--pkgincludedir", "PKGINCLUDEDIR"},
{"--includedir-server", "INCLUDEDIR-SERVER"},
{"--libdir", "LIBDIR"},
{"--pkglibdir", "PKGLIBDIR"},
{"--localedir", "LOCALEDIR"},
{"--mandir", "MANDIR"},
{"--sharedir", "SHAREDIR"},
{"--sysconfdir", "SYSCONFDIR"},
{"--pgxs", "PGXS"},
{"--configure", "CONFIGURE"},
{"--cc", "CC"},
{"--cppflags", "CPPFLAGS"},
{"--cflags", "CFLAGS"},
{"--cflags_sl", "CFLAGS_SL"},
{"--ldflags", "LDFLAGS"},
{"--ldflags_ex", "LDFLAGS_EX"},
{"--ldflags_sl", "LDFLAGS_SL"},
{"--libs", "LIBS"},
{"--version", "VERSION"},
{NULL, NULL}
};
static void
help(void)
{
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 <%s>.\n"), PACKAGE_BUGREPORT);
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
static void
advice(void)
{
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
}
static void
show_item(const char *configname,
ConfigData *configdata,
size_t configdata_len)
{
int i;
for (i = 0; i < configdata_len; i++)
{
if (strcmp(configname, configdata[i].name) == 0)
printf("%s\n", configdata[i].setting);
}
}
int
main(int argc, char **argv)
{
ConfigData *configdata;
size_t configdata_len;
char my_exec_path[MAXPGPATH];
int i;
int j;
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);
}
}
if (find_my_exec(argv[0], my_exec_path) < 0)
{
fprintf(stderr, _("%s: could not find own program executable\n"), progname);
exit(1);
}
configdata = get_configdata(my_exec_path, &configdata_len);
/* no arguments -> print everything */
if (argc < 2)
{
for (i = 0; i < configdata_len; i++)
printf("%s = %s\n", configdata[i].name, configdata[i].setting);
exit(0);
}
/* otherwise print requested items */
for (i = 1; i < argc; i++)
{
for (j = 0; info_items[j].switchname != NULL; j++)
{
if (strcmp(argv[i], info_items[j].switchname) == 0)
{
show_item(info_items[j].configname,
configdata, configdata_len);
break;
}
}
if (info_items[j].switchname == NULL)
{
fprintf(stderr, _("%s: invalid argument: %s\n"),
progname, argv[i]);
advice();
exit(1);
}
}
return 0;
}
|