1 /*-------------------------------------------------------------------------
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
22 *-------------------------------------------------------------------------
25 #include "postgres_fe.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:
40 cleanup_path(char *path
)
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
51 GetShortPathName(path
, path
, MAXPGPATH
- 1);
53 /* Replace '\' with '/' */
54 for (ptr
= path
; *ptr
; ptr
++)
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.
77 /* assume we are located in the bindir */
79 lastsep
= strrchr(path
, '/');
95 get_doc_path(mypath
, path
);
101 show_htmldir(bool all
)
103 char path
[MAXPGPATH
];
106 printf("HTMLDIR = ");
107 get_html_path(mypath
, path
);
109 printf("%s\n", path
);
113 show_includedir(bool all
)
115 char path
[MAXPGPATH
];
118 printf("INCLUDEDIR = ");
119 get_include_path(mypath
, path
);
121 printf("%s\n", path
);
125 show_pkgincludedir(bool all
)
127 char path
[MAXPGPATH
];
130 printf("PKGINCLUDEDIR = ");
131 get_pkginclude_path(mypath
, path
);
133 printf("%s\n", path
);
137 show_includedir_server(bool all
)
139 char path
[MAXPGPATH
];
142 printf("INCLUDEDIR-SERVER = ");
143 get_includeserver_path(mypath
, path
);
145 printf("%s\n", path
);
149 show_libdir(bool all
)
151 char path
[MAXPGPATH
];
155 get_lib_path(mypath
, path
);
157 printf("%s\n", path
);
161 show_pkglibdir(bool all
)
163 char path
[MAXPGPATH
];
166 printf("PKGLIBDIR = ");
167 get_pkglib_path(mypath
, path
);
169 printf("%s\n", path
);
173 show_localedir(bool all
)
175 char path
[MAXPGPATH
];
178 printf("LOCALEDIR = ");
179 get_locale_path(mypath
, path
);
181 printf("%s\n", path
);
185 show_mandir(bool all
)
187 char path
[MAXPGPATH
];
191 get_man_path(mypath
, path
);
193 printf("%s\n", path
);
197 show_sharedir(bool all
)
199 char path
[MAXPGPATH
];
202 printf("SHAREDIR = ");
203 get_share_path(mypath
, path
);
205 printf("%s\n", path
);
209 show_sysconfdir(bool all
)
211 char path
[MAXPGPATH
];
214 printf("SYSCONFDIR = ");
215 get_etc_path(mypath
, path
);
217 printf("%s\n", path
);
223 char path
[MAXPGPATH
];
227 get_pkglib_path(mypath
, path
);
228 strlcat(path
, "/pgxs/src/makefiles/pgxs.mk", sizeof(path
));
230 printf("%s\n", path
);
234 show_configure(bool all
)
238 printf("CONFIGURE = ");
239 printf("%s\n", VAL_CONFIGURE
);
243 fprintf(stderr
, _("not recorded\n"));
255 printf("%s\n", VAL_CC
);
259 fprintf(stderr
, _("not recorded\n"));
266 show_cppflags(bool all
)
270 printf("CPPFLAGS = ");
271 printf("%s\n", VAL_CPPFLAGS
);
275 fprintf(stderr
, _("not recorded\n"));
282 show_cflags(bool all
)
287 printf("%s\n", VAL_CFLAGS
);
291 fprintf(stderr
, _("not recorded\n"));
298 show_cflags_sl(bool all
)
302 printf("CFLAGS_SL = ");
303 printf("%s\n", VAL_CFLAGS_SL
);
307 fprintf(stderr
, _("not recorded\n"));
314 show_ldflags(bool all
)
318 printf("LDFLAGS = ");
319 printf("%s\n", VAL_LDFLAGS
);
323 fprintf(stderr
, _("not recorded\n"));
330 show_ldflags_sl(bool all
)
332 #ifdef VAL_LDFLAGS_SL
334 printf("LDFLAGS_SL = ");
335 printf("%s\n", VAL_LDFLAGS_SL
);
339 fprintf(stderr
, _("not recorded\n"));
351 printf("%s\n", VAL_LIBS
);
355 fprintf(stderr
, _("not recorded\n"));
362 show_version(bool 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.
377 const char *switchname
;
378 void (*show_func
) (bool all
);
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
},
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
},
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"
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"));
447 fprintf(stderr
, _("Try \"%s --help\" for more information.\n"), progname
);
455 for (i
= 0; info_items
[i
].switchname
!= NULL
; i
++)
457 (*info_items
[i
].show_func
) (true);
462 main(int argc
, char **argv
)
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)
482 ret
= find_my_exec(argv
[0], mypath
);
486 fprintf(stderr
, _("%s: could not find own program executable\n"), progname
);
490 /* no arguments -> print everything */
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);
507 if (info_items
[j
].switchname
== NULL
)
509 fprintf(stderr
, _("%s: invalid argument: %s\n"),