PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_config.c
Go to the documentation of this file.
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 * accommodate 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-2026, PostgreSQL Global Development Group
19 *
20 * src/bin/pg_config/pg_config.c
21 *
22 *-------------------------------------------------------------------------
23 */
24
25#include "postgres_fe.h"
26
27#include "common/config_info.h"
28
29static const char *progname;
30
31/*
32 * Table of known information items
33 *
34 * Be careful to keep this in sync with the help() display.
35 */
36typedef struct
37{
38 const char *switchname;
39 const char *configname;
40} InfoItem;
41
42static const InfoItem info_items[] = {
43 {"--bindir", "BINDIR"},
44 {"--docdir", "DOCDIR"},
45 {"--htmldir", "HTMLDIR"},
46 {"--includedir", "INCLUDEDIR"},
47 {"--pkgincludedir", "PKGINCLUDEDIR"},
48 {"--includedir-server", "INCLUDEDIR-SERVER"},
49 {"--libdir", "LIBDIR"},
50 {"--pkglibdir", "PKGLIBDIR"},
51 {"--localedir", "LOCALEDIR"},
52 {"--mandir", "MANDIR"},
53 {"--sharedir", "SHAREDIR"},
54 {"--sysconfdir", "SYSCONFDIR"},
55 {"--pgxs", "PGXS"},
56 {"--configure", "CONFIGURE"},
57 {"--cc", "CC"},
58 {"--cppflags", "CPPFLAGS"},
59 {"--cflags", "CFLAGS"},
60 {"--cflags_sl", "CFLAGS_SL"},
61 {"--ldflags", "LDFLAGS"},
62 {"--ldflags_ex", "LDFLAGS_EX"},
63 {"--ldflags_sl", "LDFLAGS_SL"},
64 {"--libs", "LIBS"},
65 {"--version", "VERSION"},
66 {NULL, NULL}
67};
68
69
70static void
71help(void)
72{
73 printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
74 printf(_("Usage:\n"));
75 printf(_(" %s [OPTION]...\n\n"), progname);
76 printf(_("Options:\n"));
77 printf(_(" --bindir show location of user executables\n"));
78 printf(_(" --docdir show location of documentation files\n"));
79 printf(_(" --htmldir show location of HTML documentation files\n"));
80 printf(_(" --includedir show location of C header files of the client\n"
81 " interfaces\n"));
82 printf(_(" --pkgincludedir show location of other C header files\n"));
83 printf(_(" --includedir-server show location of C header files for the server\n"));
84 printf(_(" --libdir show location of object code libraries\n"));
85 printf(_(" --pkglibdir show location of dynamically loadable modules\n"));
86 printf(_(" --localedir show location of locale support files\n"));
87 printf(_(" --mandir show location of manual pages\n"));
88 printf(_(" --sharedir show location of architecture-independent support files\n"));
89 printf(_(" --sysconfdir show location of system-wide configuration files\n"));
90 printf(_(" --pgxs show location of extension makefile\n"));
91 printf(_(" --configure show options given to \"configure\" script when\n"
92 " PostgreSQL was built\n"));
93 printf(_(" --cc show CC value used when PostgreSQL was built\n"));
94 printf(_(" --cppflags show CPPFLAGS value used when PostgreSQL was built\n"));
95 printf(_(" --cflags show CFLAGS value used when PostgreSQL was built\n"));
96 printf(_(" --cflags_sl show CFLAGS_SL value used when PostgreSQL was built\n"));
97 printf(_(" --ldflags show LDFLAGS value used when PostgreSQL was built\n"));
98 printf(_(" --ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built\n"));
99 printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n"));
100 printf(_(" --libs show LIBS value used when PostgreSQL was built\n"));
101 printf(_(" --version show the PostgreSQL version\n"));
102 printf(_(" -?, --help show this help, then exit\n"));
103 printf(_("\nWith no arguments, all known items are shown.\n\n"));
104 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
105 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
106}
107
108static void
110{
111 fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
112}
113
114static void
115show_item(const char *configname,
117 size_t configdata_len)
118{
119 for (size_t i = 0; i < configdata_len; i++)
120 {
121 if (strcmp(configname, configdata[i].name) == 0)
122 printf("%s\n", configdata[i].setting);
123 }
124}
125
126int
127main(int argc, char **argv)
128{
130 size_t configdata_len;
132
133 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
134
135 progname = get_progname(argv[0]);
136
137 /* check for --help */
138 for (int i = 1; i < argc; i++)
139 {
140 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
141 {
142 help();
143 exit(0);
144 }
145 }
146
147 if (find_my_exec(argv[0], my_exec_path) < 0)
148 {
149 fprintf(stderr, _("%s: could not find own program executable\n"), progname);
150 exit(1);
151 }
152
154 /* no arguments -> print everything */
155 if (argc < 2)
156 {
157 for (size_t i = 0; i < configdata_len; i++)
158 printf("%s = %s\n", configdata[i].name, configdata[i].setting);
159 exit(0);
160 }
161
162 /* otherwise print requested items */
163 for (int i = 1; i < argc; i++)
164 {
165 int j;
166
167 for (j = 0; info_items[j].switchname != NULL; j++)
168 {
169 if (strcmp(argv[i], info_items[j].switchname) == 0)
170 {
171 show_item(info_items[j].configname,
173 break;
174 }
175 }
176 if (info_items[j].switchname == NULL)
177 {
178 fprintf(stderr, _("%s: invalid argument: %s\n"),
179 progname, argv[i]);
180 advice();
181 exit(1);
182 }
183 }
184
185 return 0;
186}
static void advice(void)
Definition pg_config.c:109
static const InfoItem info_items[]
Definition pg_config.c:42
static void help(void)
Definition pg_config.c:71
static const char * progname
Definition pg_config.c:29
static void show_item(const char *configname, ConfigData *configdata, size_t configdata_len)
Definition pg_config.c:115
#define PG_TEXTDOMAIN(domain)
Definition c.h:1343
int find_my_exec(const char *argv0, char *retpath)
Definition exec.c:161
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition exec.c:430
int main(void)
ConfigData * get_configdata(const char *my_exec_path, size_t *configdata_len)
Definition config_info.c:33
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
#define _(x)
Definition elog.c:96
char my_exec_path[MAXPGPATH]
Definition globals.c:83
int j
Definition isn.c:78
int i
Definition isn.c:77
#define MAXPGPATH
const char * get_progname(const char *argv0)
Definition path.c:669
#define printf(...)
Definition port.h:267
static int fb(int x)
const char * configname
Definition pg_config.c:39
const char * switchname
Definition pg_config.c:38
const char * name