Force a checkpoint in CREATE DATABASE before starting to copy the files,
[PostgreSQL.git] / src / bin / pg_config / pg_config.c
blobd9807308ac1b2db91ac946b602e61bc880b7456f
1 /*-------------------------------------------------------------------------
3 * pg_config.c
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.
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.
14 * author of C translation: Andrew Dunstan mailto:andrew@dunslane.net
16 * This code is released under the terms of the PostgreSQL License.
18 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
20 * $PostgreSQL$
22 *-------------------------------------------------------------------------
25 #include "postgres_fe.h"
27 #include "port.h"
29 static const char *progname;
30 static char mypath[MAXPGPATH];
34 * This function cleans up the paths for use with either cmd.exe or Msys
35 * on Windows. We need them to use filenames without spaces, for which a
36 * short filename is the safest equivalent, eg:
37 * C:/Progra~1/
39 static void
40 cleanup_path(char *path)
42 #ifdef WIN32
43 char *ptr;
46 * GetShortPathName() will fail if the path does not exist, or short names
47 * are disabled on this file system. In both cases, we just return the
48 * original path. This is particularly useful for --sysconfdir, which
49 * might not exist.
51 GetShortPathName(path, path, MAXPGPATH - 1);
53 /* Replace '\' with '/' */
54 for (ptr = path; *ptr; ptr++)
56 if (*ptr == '\\')
57 *ptr = '/';
59 #endif
64 * For each piece of information known to pg_config, we define a subroutine
65 * to print it. This is probably overkill, but it avoids code duplication
66 * and accidentally omitting items from the "all" display.
69 static void
70 show_bindir(bool all)
72 char path[MAXPGPATH];
73 char *lastsep;
75 if (all)
76 printf("BINDIR = ");
77 /* assume we are located in the bindir */
78 strcpy(path, mypath);
79 lastsep = strrchr(path, '/');
81 if (lastsep)
82 *lastsep = '\0';
84 cleanup_path(path);
85 printf("%s\n", path);
88 static void
89 show_docdir(bool all)
91 char path[MAXPGPATH];
93 if (all)
94 printf("DOCDIR = ");
95 get_doc_path(mypath, path);
96 cleanup_path(path);
97 printf("%s\n", path);
100 static void
101 show_htmldir(bool all)
103 char path[MAXPGPATH];
105 if (all)
106 printf("HTMLDIR = ");
107 get_html_path(mypath, path);
108 cleanup_path(path);
109 printf("%s\n", path);
112 static void
113 show_includedir(bool all)
115 char path[MAXPGPATH];
117 if (all)
118 printf("INCLUDEDIR = ");
119 get_include_path(mypath, path);
120 cleanup_path(path);
121 printf("%s\n", path);
124 static void
125 show_pkgincludedir(bool all)
127 char path[MAXPGPATH];
129 if (all)
130 printf("PKGINCLUDEDIR = ");
131 get_pkginclude_path(mypath, path);
132 cleanup_path(path);
133 printf("%s\n", path);
136 static void
137 show_includedir_server(bool all)
139 char path[MAXPGPATH];
141 if (all)
142 printf("INCLUDEDIR-SERVER = ");
143 get_includeserver_path(mypath, path);
144 cleanup_path(path);
145 printf("%s\n", path);
148 static void
149 show_libdir(bool all)
151 char path[MAXPGPATH];
153 if (all)
154 printf("LIBDIR = ");
155 get_lib_path(mypath, path);
156 cleanup_path(path);
157 printf("%s\n", path);
160 static void
161 show_pkglibdir(bool all)
163 char path[MAXPGPATH];
165 if (all)
166 printf("PKGLIBDIR = ");
167 get_pkglib_path(mypath, path);
168 cleanup_path(path);
169 printf("%s\n", path);
172 static void
173 show_localedir(bool all)
175 char path[MAXPGPATH];
177 if (all)
178 printf("LOCALEDIR = ");
179 get_locale_path(mypath, path);
180 cleanup_path(path);
181 printf("%s\n", path);
184 static void
185 show_mandir(bool all)
187 char path[MAXPGPATH];
189 if (all)
190 printf("MANDIR = ");
191 get_man_path(mypath, path);
192 cleanup_path(path);
193 printf("%s\n", path);
196 static void
197 show_sharedir(bool all)
199 char path[MAXPGPATH];
201 if (all)
202 printf("SHAREDIR = ");
203 get_share_path(mypath, path);
204 cleanup_path(path);
205 printf("%s\n", path);
208 static void
209 show_sysconfdir(bool all)
211 char path[MAXPGPATH];
213 if (all)
214 printf("SYSCONFDIR = ");
215 get_etc_path(mypath, path);
216 cleanup_path(path);
217 printf("%s\n", path);
220 static void
221 show_pgxs(bool all)
223 char path[MAXPGPATH];
225 if (all)
226 printf("PGXS = ");
227 get_pkglib_path(mypath, path);
228 strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
229 cleanup_path(path);
230 printf("%s\n", path);
233 static void
234 show_configure(bool all)
236 #ifdef VAL_CONFIGURE
237 if (all)
238 printf("CONFIGURE = ");
239 printf("%s\n", VAL_CONFIGURE);
240 #else
241 if (!all)
243 fprintf(stderr, _("not recorded\n"));
244 exit(1);
246 #endif
249 static void
250 show_cc(bool all)
252 #ifdef VAL_CC
253 if (all)
254 printf("CC = ");
255 printf("%s\n", VAL_CC);
256 #else
257 if (!all)
259 fprintf(stderr, _("not recorded\n"));
260 exit(1);
262 #endif
265 static void
266 show_cppflags(bool all)
268 #ifdef VAL_CPPFLAGS
269 if (all)
270 printf("CPPFLAGS = ");
271 printf("%s\n", VAL_CPPFLAGS);
272 #else
273 if (!all)
275 fprintf(stderr, _("not recorded\n"));
276 exit(1);
278 #endif
281 static void
282 show_cflags(bool all)
284 #ifdef VAL_CFLAGS
285 if (all)
286 printf("CFLAGS = ");
287 printf("%s\n", VAL_CFLAGS);
288 #else
289 if (!all)
291 fprintf(stderr, _("not recorded\n"));
292 exit(1);
294 #endif
297 static void
298 show_cflags_sl(bool all)
300 #ifdef VAL_CFLAGS_SL
301 if (all)
302 printf("CFLAGS_SL = ");
303 printf("%s\n", VAL_CFLAGS_SL);
304 #else
305 if (!all)
307 fprintf(stderr, _("not recorded\n"));
308 exit(1);
310 #endif
313 static void
314 show_ldflags(bool all)
316 #ifdef VAL_LDFLAGS
317 if (all)
318 printf("LDFLAGS = ");
319 printf("%s\n", VAL_LDFLAGS);
320 #else
321 if (!all)
323 fprintf(stderr, _("not recorded\n"));
324 exit(1);
326 #endif
329 static void
330 show_ldflags_sl(bool all)
332 #ifdef VAL_LDFLAGS_SL
333 if (all)
334 printf("LDFLAGS_SL = ");
335 printf("%s\n", VAL_LDFLAGS_SL);
336 #else
337 if (!all)
339 fprintf(stderr, _("not recorded\n"));
340 exit(1);
342 #endif
345 static void
346 show_libs(bool all)
348 #ifdef VAL_LIBS
349 if (all)
350 printf("LIBS = ");
351 printf("%s\n", VAL_LIBS);
352 #else
353 if (!all)
355 fprintf(stderr, _("not recorded\n"));
356 exit(1);
358 #endif
361 static void
362 show_version(bool all)
364 if (all)
365 printf("VERSION = ");
366 printf("PostgreSQL " PG_VERSION "\n");
371 * Table of known information items
373 * Be careful to keep this in sync with the help() display.
375 typedef struct
377 const char *switchname;
378 void (*show_func) (bool all);
379 } InfoItem;
381 static const InfoItem info_items[] = {
382 {"--bindir", show_bindir},
383 {"--docdir", show_docdir},
384 {"--htmldir", show_htmldir},
385 {"--includedir", show_includedir},
386 {"--pkgincludedir", show_pkgincludedir},
387 {"--includedir-server", show_includedir_server},
388 {"--libdir", show_libdir},
389 {"--pkglibdir", show_pkglibdir},
390 {"--localedir", show_localedir},
391 {"--mandir", show_mandir},
392 {"--sharedir", show_sharedir},
393 {"--sysconfdir", show_sysconfdir},
394 {"--pgxs", show_pgxs},
395 {"--configure", show_configure},
396 {"--cc", show_cc},
397 {"--cppflags", show_cppflags},
398 {"--cflags", show_cflags},
399 {"--cflags_sl", show_cflags_sl},
400 {"--ldflags", show_ldflags},
401 {"--ldflags_sl", show_ldflags_sl},
402 {"--libs", show_libs},
403 {"--version", show_version},
404 {NULL, NULL}
408 static void
409 help(void)
411 printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
412 printf(_("Usage:\n"));
413 printf(_(" %s [ OPTION ... ]\n\n"), progname);
414 printf(_("Options:\n"));
415 printf(_(" --bindir show location of user executables\n"));
416 printf(_(" --docdir show location of documentation files\n"));
417 printf(_(" --htmldir show location of HTML documentation files\n"));
418 printf(_(" --includedir show location of C header files of the client\n"
419 " interfaces\n"));
420 printf(_(" --pkgincludedir show location of other C header files\n"));
421 printf(_(" --includedir-server show location of C header files for the server\n"));
422 printf(_(" --libdir show location of object code libraries\n"));
423 printf(_(" --pkglibdir show location of dynamically loadable modules\n"));
424 printf(_(" --localedir show location of locale support files\n"));
425 printf(_(" --mandir show location of manual pages\n"));
426 printf(_(" --sharedir show location of architecture-independent support files\n"));
427 printf(_(" --sysconfdir show location of system-wide configuration files\n"));
428 printf(_(" --pgxs show location of extension makefile\n"));
429 printf(_(" --configure show options given to \"configure\" script when\n"
430 " PostgreSQL was built\n"));
431 printf(_(" --cc show CC value used when PostgreSQL was built\n"));
432 printf(_(" --cppflags show CPPFLAGS value used when PostgreSQL was built\n"));
433 printf(_(" --cflags show CFLAGS value used when PostgreSQL was built\n"));
434 printf(_(" --cflags_sl show CFLAGS_SL value used when PostgreSQL was built\n"));
435 printf(_(" --ldflags show LDFLAGS value used when PostgreSQL was built\n"));
436 printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n"));
437 printf(_(" --libs show LIBS value used when PostgreSQL was built\n"));
438 printf(_(" --version show the PostgreSQL version\n"));
439 printf(_(" --help show this help, then exit\n"));
440 printf(_("\nWith no arguments, all known items are shown.\n\n"));
441 printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
444 static void
445 advice(void)
447 fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
450 static void
451 show_all(void)
453 int i;
455 for (i = 0; info_items[i].switchname != NULL; i++)
457 (*info_items[i].show_func) (true);
462 main(int argc, char **argv)
464 int i;
465 int j;
466 int ret;
468 set_pglocale_pgservice(argv[0], "pg_config");
470 progname = get_progname(argv[0]);
472 /* check for --help */
473 for (i = 1; i < argc; i++)
475 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
477 help();
478 exit(0);
482 ret = find_my_exec(argv[0], mypath);
484 if (ret)
486 fprintf(stderr, _("%s: could not find own program executable\n"), progname);
487 exit(1);
490 /* no arguments -> print everything */
491 if (argc < 2)
493 show_all();
494 exit(0);
497 for (i = 1; i < argc; i++)
499 for (j = 0; info_items[j].switchname != NULL; j++)
501 if (strcmp(argv[i], info_items[j].switchname) == 0)
503 (*info_items[j].show_func) (false);
504 break;
507 if (info_items[j].switchname == NULL)
509 fprintf(stderr, _("%s: invalid argument: %s\n"),
510 progname, argv[i]);
511 advice();
512 exit(1);
516 return 0;