|
| 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 | + * accomodate 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-2003, PostgreSQL Global Development Group |
| 19 | + * |
| 20 | + * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.1 2004/08/01 13:54:05 momjian Exp $ |
| 21 | + * |
| 22 | + *------------------------------------------------------------------------- |
| 23 | + */ |
| 24 | + |
| 25 | +#include"postgres.h" |
| 26 | +#include"port.h" |
| 27 | +#include<stdio.h> |
| 28 | + |
| 29 | +#define_(x) gettext((x)) |
| 30 | + |
| 31 | +char*progname; |
| 32 | + |
| 33 | +staticvoid |
| 34 | +help() |
| 35 | +{ |
| 36 | +printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"),progname); |
| 37 | +printf(_("Usage:\n")); |
| 38 | +printf(_(" %s OPTION...\n\n"),progname); |
| 39 | +printf(_("Options:\n")); |
| 40 | +printf(_(" --bindir show location of user executables\n")); |
| 41 | +printf(_(" --includedir show location of C header files of the client\n")); |
| 42 | +printf(_(" interfaces\n")); |
| 43 | +printf(_(" --includedir-server show location of C header files for the server\n")); |
| 44 | +printf(_(" --libdir show location of object code libraries\n")); |
| 45 | +printf(_(" --pkglibdir show location of dynamically loadable modules\n")); |
| 46 | +printf(_(" --configure show options given to 'configure' script when\n")); |
| 47 | +printf(_(" PostgreSQL was built\n")); |
| 48 | +printf(_(" --version show the PostgreSQL version, then exit\n")); |
| 49 | +printf(_(" --help show this help, then exit\n\n")); |
| 50 | +printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n")); |
| 51 | +} |
| 52 | + |
| 53 | +staticvoid |
| 54 | +advice() |
| 55 | +{ |
| 56 | +fprintf(stderr,_("\nTry \"%s --help\" for more information\n"),progname); |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +int |
| 61 | +main (intargc,char**argv) |
| 62 | +{ |
| 63 | +inti; |
| 64 | +intret; |
| 65 | +charmypath[MAXPGPATH]; |
| 66 | +charotherpath[MAXPGPATH]; |
| 67 | + |
| 68 | +progname= (char*)get_progname(argv[0]); |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +if (argc<2) |
| 73 | +{ |
| 74 | +fprintf(stderr,_("%s: argument required\n"),progname); |
| 75 | +advice(); |
| 76 | +exit(1); |
| 77 | +} |
| 78 | + |
| 79 | +for (i=1;i<argc;i++) |
| 80 | +{ |
| 81 | +if (strcmp(argv[i],"--bindir")==0|| |
| 82 | +strcmp(argv[i],"--includedir")==0|| |
| 83 | +strcmp(argv[i],"--includedir-server")==0|| |
| 84 | +strcmp(argv[i],"--libdir")==0|| |
| 85 | +strcmp(argv[i],"--pkglibdir")==0|| |
| 86 | +strcmp(argv[i],"--configure")==0 |
| 87 | +) |
| 88 | +{ |
| 89 | +/* come back to these later */ |
| 90 | + |
| 91 | +continue; |
| 92 | +} |
| 93 | + |
| 94 | +if (strcmp(argv[i],"--version")==0) |
| 95 | +{ |
| 96 | +printf("PostgreSQL "PG_VERSION"\n"); |
| 97 | +exit(0); |
| 98 | +} |
| 99 | +if (strcmp(argv[i],"--help")==0||strcmp(argv[i],"-?")==0) |
| 100 | +{ |
| 101 | +help(); |
| 102 | +exit(0); |
| 103 | +} |
| 104 | +fprintf(stderr,_("%s: invalid argument: %s\n"),progname,argv[i]); |
| 105 | +advice(); |
| 106 | +exit(1); |
| 107 | +} |
| 108 | + |
| 109 | +ret=find_my_exec(argv[0],mypath); |
| 110 | + |
| 111 | +if (ret) |
| 112 | +{ |
| 113 | +fprintf(stderr,"%s: could not locate my own executable\n",progname); |
| 114 | +exit(1); |
| 115 | +} |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +for (i=1;i<argc;i++) |
| 120 | +{ |
| 121 | +if (strcmp(argv[i],"--configure")==0) |
| 122 | +{ |
| 123 | +/* the VAL_CONFIGURE macro must be defined by the Makefile */ |
| 124 | + |
| 125 | +printf("%s\n",VAL_CONFIGURE); |
| 126 | +continue; |
| 127 | +} |
| 128 | + |
| 129 | +if (strcmp(argv[i],"--bindir")==0) |
| 130 | +{ |
| 131 | +/* assume we are located in the bindir */ |
| 132 | + |
| 133 | +char*lastsep; |
| 134 | +strcpy(otherpath,mypath); |
| 135 | +lastsep=strrchr(otherpath,'/'); |
| 136 | +if (lastsep) |
| 137 | +*lastsep='\0'; |
| 138 | +} |
| 139 | +elseif (strcmp(argv[i],"--includedir")==0) |
| 140 | +get_include_path(mypath,otherpath); |
| 141 | +elseif (strcmp(argv[i],"--includedir-server")==0) |
| 142 | +get_includeserver_path(mypath,otherpath); |
| 143 | +elseif (strcmp(argv[i],"--libdir")==0) |
| 144 | +get_lib_path(mypath,otherpath); |
| 145 | +elseif (strcmp(argv[i],"--pkglibdir")==0) |
| 146 | +get_pkglib_path(mypath,otherpath); |
| 147 | + |
| 148 | +printf("%s\n",otherpath); |
| 149 | + |
| 150 | + |
| 151 | +} |
| 152 | + |
| 153 | +return0; |
| 154 | +} |