00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "postgres_fe.h"
00026
00027 #include "port.h"
00028
00029 static const char *progname;
00030 static char mypath[MAXPGPATH];
00031
00032
00033
00034
00035
00036
00037
00038
00039 static void
00040 cleanup_path(char *path)
00041 {
00042 #ifdef WIN32
00043 char *ptr;
00044
00045
00046
00047
00048
00049
00050
00051 GetShortPathName(path, path, MAXPGPATH - 1);
00052
00053
00054 for (ptr = path; *ptr; ptr++)
00055 {
00056 if (*ptr == '\\')
00057 *ptr = '/';
00058 }
00059 #endif
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 static void
00070 show_bindir(bool all)
00071 {
00072 char path[MAXPGPATH];
00073 char *lastsep;
00074
00075 if (all)
00076 printf("BINDIR = ");
00077
00078 strcpy(path, mypath);
00079 lastsep = strrchr(path, '/');
00080
00081 if (lastsep)
00082 *lastsep = '\0';
00083
00084 cleanup_path(path);
00085 printf("%s\n", path);
00086 }
00087
00088 static void
00089 show_docdir(bool all)
00090 {
00091 char path[MAXPGPATH];
00092
00093 if (all)
00094 printf("DOCDIR = ");
00095 get_doc_path(mypath, path);
00096 cleanup_path(path);
00097 printf("%s\n", path);
00098 }
00099
00100 static void
00101 show_htmldir(bool all)
00102 {
00103 char path[MAXPGPATH];
00104
00105 if (all)
00106 printf("HTMLDIR = ");
00107 get_html_path(mypath, path);
00108 cleanup_path(path);
00109 printf("%s\n", path);
00110 }
00111
00112 static void
00113 show_includedir(bool all)
00114 {
00115 char path[MAXPGPATH];
00116
00117 if (all)
00118 printf("INCLUDEDIR = ");
00119 get_include_path(mypath, path);
00120 cleanup_path(path);
00121 printf("%s\n", path);
00122 }
00123
00124 static void
00125 show_pkgincludedir(bool all)
00126 {
00127 char path[MAXPGPATH];
00128
00129 if (all)
00130 printf("PKGINCLUDEDIR = ");
00131 get_pkginclude_path(mypath, path);
00132 cleanup_path(path);
00133 printf("%s\n", path);
00134 }
00135
00136 static void
00137 show_includedir_server(bool all)
00138 {
00139 char path[MAXPGPATH];
00140
00141 if (all)
00142 printf("INCLUDEDIR-SERVER = ");
00143 get_includeserver_path(mypath, path);
00144 cleanup_path(path);
00145 printf("%s\n", path);
00146 }
00147
00148 static void
00149 show_libdir(bool all)
00150 {
00151 char path[MAXPGPATH];
00152
00153 if (all)
00154 printf("LIBDIR = ");
00155 get_lib_path(mypath, path);
00156 cleanup_path(path);
00157 printf("%s\n", path);
00158 }
00159
00160 static void
00161 show_pkglibdir(bool all)
00162 {
00163 char path[MAXPGPATH];
00164
00165 if (all)
00166 printf("PKGLIBDIR = ");
00167 get_pkglib_path(mypath, path);
00168 cleanup_path(path);
00169 printf("%s\n", path);
00170 }
00171
00172 static void
00173 show_localedir(bool all)
00174 {
00175 char path[MAXPGPATH];
00176
00177 if (all)
00178 printf("LOCALEDIR = ");
00179 get_locale_path(mypath, path);
00180 cleanup_path(path);
00181 printf("%s\n", path);
00182 }
00183
00184 static void
00185 show_mandir(bool all)
00186 {
00187 char path[MAXPGPATH];
00188
00189 if (all)
00190 printf("MANDIR = ");
00191 get_man_path(mypath, path);
00192 cleanup_path(path);
00193 printf("%s\n", path);
00194 }
00195
00196 static void
00197 show_sharedir(bool all)
00198 {
00199 char path[MAXPGPATH];
00200
00201 if (all)
00202 printf("SHAREDIR = ");
00203 get_share_path(mypath, path);
00204 cleanup_path(path);
00205 printf("%s\n", path);
00206 }
00207
00208 static void
00209 show_sysconfdir(bool all)
00210 {
00211 char path[MAXPGPATH];
00212
00213 if (all)
00214 printf("SYSCONFDIR = ");
00215 get_etc_path(mypath, path);
00216 cleanup_path(path);
00217 printf("%s\n", path);
00218 }
00219
00220 static void
00221 show_pgxs(bool all)
00222 {
00223 char path[MAXPGPATH];
00224
00225 if (all)
00226 printf("PGXS = ");
00227 get_pkglib_path(mypath, path);
00228 strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
00229 cleanup_path(path);
00230 printf("%s\n", path);
00231 }
00232
00233 static void
00234 show_configure(bool all)
00235 {
00236 #ifdef VAL_CONFIGURE
00237 if (all)
00238 printf("CONFIGURE = ");
00239 printf("%s\n", VAL_CONFIGURE);
00240 #else
00241 if (!all)
00242 {
00243 fprintf(stderr, _("not recorded\n"));
00244 exit(1);
00245 }
00246 #endif
00247 }
00248
00249 static void
00250 show_cc(bool all)
00251 {
00252 #ifdef VAL_CC
00253 if (all)
00254 printf("CC = ");
00255 printf("%s\n", VAL_CC);
00256 #else
00257 if (!all)
00258 {
00259 fprintf(stderr, _("not recorded\n"));
00260 exit(1);
00261 }
00262 #endif
00263 }
00264
00265 static void
00266 show_cppflags(bool all)
00267 {
00268 #ifdef VAL_CPPFLAGS
00269 if (all)
00270 printf("CPPFLAGS = ");
00271 printf("%s\n", VAL_CPPFLAGS);
00272 #else
00273 if (!all)
00274 {
00275 fprintf(stderr, _("not recorded\n"));
00276 exit(1);
00277 }
00278 #endif
00279 }
00280
00281 static void
00282 show_cflags(bool all)
00283 {
00284 #ifdef VAL_CFLAGS
00285 if (all)
00286 printf("CFLAGS = ");
00287 printf("%s\n", VAL_CFLAGS);
00288 #else
00289 if (!all)
00290 {
00291 fprintf(stderr, _("not recorded\n"));
00292 exit(1);
00293 }
00294 #endif
00295 }
00296
00297 static void
00298 show_cflags_sl(bool all)
00299 {
00300 #ifdef VAL_CFLAGS_SL
00301 if (all)
00302 printf("CFLAGS_SL = ");
00303 printf("%s\n", VAL_CFLAGS_SL);
00304 #else
00305 if (!all)
00306 {
00307 fprintf(stderr, _("not recorded\n"));
00308 exit(1);
00309 }
00310 #endif
00311 }
00312
00313 static void
00314 show_ldflags(bool all)
00315 {
00316 #ifdef VAL_LDFLAGS
00317 if (all)
00318 printf("LDFLAGS = ");
00319 printf("%s\n", VAL_LDFLAGS);
00320 #else
00321 if (!all)
00322 {
00323 fprintf(stderr, _("not recorded\n"));
00324 exit(1);
00325 }
00326 #endif
00327 }
00328
00329 static void
00330 show_ldflags_ex(bool all)
00331 {
00332 #ifdef VAL_LDFLAGS_EX
00333 if (all)
00334 printf("LDFLAGS_EX = ");
00335 printf("%s\n", VAL_LDFLAGS_EX);
00336 #else
00337 if (!all)
00338 {
00339 fprintf(stderr, _("not recorded\n"));
00340 exit(1);
00341 }
00342 #endif
00343 }
00344
00345 static void
00346 show_ldflags_sl(bool all)
00347 {
00348 #ifdef VAL_LDFLAGS_SL
00349 if (all)
00350 printf("LDFLAGS_SL = ");
00351 printf("%s\n", VAL_LDFLAGS_SL);
00352 #else
00353 if (!all)
00354 {
00355 fprintf(stderr, _("not recorded\n"));
00356 exit(1);
00357 }
00358 #endif
00359 }
00360
00361 static void
00362 show_libs(bool all)
00363 {
00364 #ifdef VAL_LIBS
00365 if (all)
00366 printf("LIBS = ");
00367 printf("%s\n", VAL_LIBS);
00368 #else
00369 if (!all)
00370 {
00371 fprintf(stderr, _("not recorded\n"));
00372 exit(1);
00373 }
00374 #endif
00375 }
00376
00377 static void
00378 show_version(bool all)
00379 {
00380 if (all)
00381 printf("VERSION = ");
00382 printf("PostgreSQL " PG_VERSION "\n");
00383 }
00384
00385
00386
00387
00388
00389
00390
00391 typedef struct
00392 {
00393 const char *switchname;
00394 void (*show_func) (bool all);
00395 } InfoItem;
00396
00397 static const InfoItem info_items[] = {
00398 {"--bindir", show_bindir},
00399 {"--docdir", show_docdir},
00400 {"--htmldir", show_htmldir},
00401 {"--includedir", show_includedir},
00402 {"--pkgincludedir", show_pkgincludedir},
00403 {"--includedir-server", show_includedir_server},
00404 {"--libdir", show_libdir},
00405 {"--pkglibdir", show_pkglibdir},
00406 {"--localedir", show_localedir},
00407 {"--mandir", show_mandir},
00408 {"--sharedir", show_sharedir},
00409 {"--sysconfdir", show_sysconfdir},
00410 {"--pgxs", show_pgxs},
00411 {"--configure", show_configure},
00412 {"--cc", show_cc},
00413 {"--cppflags", show_cppflags},
00414 {"--cflags", show_cflags},
00415 {"--cflags_sl", show_cflags_sl},
00416 {"--ldflags", show_ldflags},
00417 {"--ldflags_ex", show_ldflags_ex},
00418 {"--ldflags_sl", show_ldflags_sl},
00419 {"--libs", show_libs},
00420 {"--version", show_version},
00421 {NULL, NULL}
00422 };
00423
00424
00425 static void
00426 help(void)
00427 {
00428 printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
00429 printf(_("Usage:\n"));
00430 printf(_(" %s [OPTION]...\n\n"), progname);
00431 printf(_("Options:\n"));
00432 printf(_(" --bindir show location of user executables\n"));
00433 printf(_(" --docdir show location of documentation files\n"));
00434 printf(_(" --htmldir show location of HTML documentation files\n"));
00435 printf(_(" --includedir show location of C header files of the client\n"
00436 " interfaces\n"));
00437 printf(_(" --pkgincludedir show location of other C header files\n"));
00438 printf(_(" --includedir-server show location of C header files for the server\n"));
00439 printf(_(" --libdir show location of object code libraries\n"));
00440 printf(_(" --pkglibdir show location of dynamically loadable modules\n"));
00441 printf(_(" --localedir show location of locale support files\n"));
00442 printf(_(" --mandir show location of manual pages\n"));
00443 printf(_(" --sharedir show location of architecture-independent support files\n"));
00444 printf(_(" --sysconfdir show location of system-wide configuration files\n"));
00445 printf(_(" --pgxs show location of extension makefile\n"));
00446 printf(_(" --configure show options given to \"configure\" script when\n"
00447 " PostgreSQL was built\n"));
00448 printf(_(" --cc show CC value used when PostgreSQL was built\n"));
00449 printf(_(" --cppflags show CPPFLAGS value used when PostgreSQL was built\n"));
00450 printf(_(" --cflags show CFLAGS value used when PostgreSQL was built\n"));
00451 printf(_(" --cflags_sl show CFLAGS_SL value used when PostgreSQL was built\n"));
00452 printf(_(" --ldflags show LDFLAGS value used when PostgreSQL was built\n"));
00453 printf(_(" --ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built\n"));
00454 printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n"));
00455 printf(_(" --libs show LIBS value used when PostgreSQL was built\n"));
00456 printf(_(" --version show the PostgreSQL version\n"));
00457 printf(_(" -?, --help show this help, then exit\n"));
00458 printf(_("\nWith no arguments, all known items are shown.\n\n"));
00459 printf(_("Report bugs to <[email protected]>.\n"));
00460 }
00461
00462 static void
00463 advice(void)
00464 {
00465 fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
00466 }
00467
00468 static void
00469 show_all(void)
00470 {
00471 int i;
00472
00473 for (i = 0; info_items[i].switchname != NULL; i++)
00474 {
00475 (*info_items[i].show_func) (true);
00476 }
00477 }
00478
00479 int
00480 main(int argc, char **argv)
00481 {
00482 int i;
00483 int j;
00484 int ret;
00485
00486 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config"));
00487
00488 progname = get_progname(argv[0]);
00489
00490
00491 for (i = 1; i < argc; i++)
00492 {
00493 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0)
00494 {
00495 help();
00496 exit(0);
00497 }
00498 }
00499
00500 ret = find_my_exec(argv[0], mypath);
00501
00502 if (ret)
00503 {
00504 fprintf(stderr, _("%s: could not find own program executable\n"), progname);
00505 exit(1);
00506 }
00507
00508
00509 if (argc < 2)
00510 {
00511 show_all();
00512 exit(0);
00513 }
00514
00515 for (i = 1; i < argc; i++)
00516 {
00517 for (j = 0; info_items[j].switchname != NULL; j++)
00518 {
00519 if (strcmp(argv[i], info_items[j].switchname) == 0)
00520 {
00521 (*info_items[j].show_func) (false);
00522 break;
00523 }
00524 }
00525 if (info_items[j].switchname == NULL)
00526 {
00527 fprintf(stderr, _("%s: invalid argument: %s\n"),
00528 progname, argv[i]);
00529 advice();
00530 exit(1);
00531 }
00532 }
00533
00534 return 0;
00535 }