diff --git a/configure b/configure index 659c17f60de0bb9654df95aae4a1ba9f1f969678..ea4876c96478c25423a998a2ccbd21f455f67710 100755 --- a/configure +++ b/configure @@ -10379,6 +10379,67 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for struct option" >&5 +echo $ECHO_N "checking for struct option... $ECHO_C" >&6 +if test "${ac_cv_type_struct_option+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +#ifdef HAVE_GETOPT_H +include <getopt.h> +#endif + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +if ((struct option *) 0) + return 0; +if (sizeof (struct option)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_struct_option=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_type_struct_option=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_struct_option" >&5 +echo "${ECHO_T}$ac_cv_type_struct_option" >&6 +if test $ac_cv_type_struct_option = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_OPTION 1 +_ACEOF + + +fi + + if test "$with_zlib" = yes; then # Check that <zlib.h> defines z_streamp (versions before about 1.0.4 # did not). While we could work around the lack of z_streamp, it @@ -11760,8 +11821,7 @@ fi - -for ac_func in crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul +for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -11926,6 +11986,91 @@ else LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext" fi +# similarly, use system's getopt_long() only if system provides struct option. +if test x"$ac_cv_type_struct_option" = xyes ; then + +for ac_func in getopt_long +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. */ +#include <assert.h> +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +char (*f) (); + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +f = $ac_func; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + LIBOBJS="$LIBOBJS $ac_func.$ac_objext" +fi +done + + +else + LIBOBJS="$LIBOBJS getopt_long.$ac_objext" +fi + # BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos # We override the previous test that said fseeko/ftello didn't exist # OS tests are also done in include/c.h and port/fseeko.c diff --git a/configure.in b/configure.in index 0273e4246c7fcc13014f4dec39e99a8240908e56..19056138843f379ff6dbab9a5893a8f3514509be 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -dnl $Header: /cvsroot/pgsql/configure.in,v 1.277 2003/08/04 22:30:30 pgsql Exp $ +dnl $Header: /cvsroot/pgsql/configure.in,v 1.278 2003/08/07 21:11:57 tgl Exp $ dnl dnl Developers, please strive to achieve this order: dnl @@ -780,6 +780,11 @@ AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [], #include <sys/socket.h> #include <sys/ucred.h>]) +AC_CHECK_TYPES([struct option], [], [], +[#ifdef HAVE_GETOPT_H +include <getopt.h> +#endif]) + if test "$with_zlib" = yes; then # Check that <zlib.h> defines z_streamp (versions before about 1.0.4 # did not). While we could work around the lack of z_streamp, it @@ -875,7 +880,7 @@ else AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break]) fi -AC_REPLACE_FUNCS([crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul]) +AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul]) # system's version of getaddrinfo(), if any, may be used only if we found # a definition for struct addrinfo; see notes in src/include/getaddrinfo.h @@ -885,6 +890,13 @@ else AC_LIBOBJ(getaddrinfo) fi +# similarly, use system's getopt_long() only if system provides struct option. +if test x"$ac_cv_type_struct_option" = xyes ; then + AC_REPLACE_FUNCS([getopt_long]) +else + AC_LIBOBJ(getopt_long) +fi + # BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos # We override the previous test that said fseeko/ftello didn't exist # OS tests are also done in include/c.h and port/fseeko.c diff --git a/contrib/pg_autovacuum/pg_autovacuum.h b/contrib/pg_autovacuum/pg_autovacuum.h index fbdaf699122ac7e4873f4f04d8cf70afa855265f..0fe49159ddc951e1bfa8a5d1d6fccf2b8d45ee09 100644 --- a/contrib/pg_autovacuum/pg_autovacuum.h +++ b/contrib/pg_autovacuum/pg_autovacuum.h @@ -6,7 +6,7 @@ #include "postgres_fe.h" #include <unistd.h> -#ifdef __GLIBC__ +#ifdef HAVE_GETOPT_H #include <getopt.h> #endif #include <time.h> diff --git a/contrib/pg_dumplo/main.c b/contrib/pg_dumplo/main.c index 09a71a586dcdfed31790ee66745c7fecf9e8e325..1e892f01051120324d939eaaaf311fc7b6e96fd8 100644 --- a/contrib/pg_dumplo/main.c +++ b/contrib/pg_dumplo/main.c @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.17 2003/08/04 00:43:11 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.18 2003/08/07 21:11:57 tgl Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -11,9 +11,6 @@ #include <errno.h> #include <unistd.h> -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif #include "libpq-fe.h" #include "libpq/libpq-fs.h" @@ -24,8 +21,9 @@ #include "strdup.h" #endif -#ifndef HAVE_GETOPT_LONG #include "getopt_long.h" + +#ifndef HAVE_OPTRESET int optreset; #endif diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index fb21d04cd69e924420f502f7d7c06979d20bcfe8..a6ecda10d6057d2ad840d2bb20d9b2089b52b585 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.342 2003/08/04 02:40:09 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.343 2003/08/07 21:11:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,9 +29,6 @@ #ifdef ENABLE_NLS #include <locale.h> #endif -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif #ifdef HAVE_TERMIOS_H #include <termios.h> #endif @@ -40,8 +37,9 @@ #include "strdup.h" #endif -#ifndef HAVE_GETOPT_LONG #include "getopt_long.h" + +#ifndef HAVE_OPTRESET int optreset; #endif diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 9be39ecb759c783bc177fc6dd66f50a8e63c44e8..8c83254c817421ec98f76732880e978f3a8e825b 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.26 2003/08/04 02:40:09 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.27 2003/08/07 21:11:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,16 +17,14 @@ #ifdef ENABLE_NLS #include <locale.h> #endif -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif #ifndef HAVE_STRDUP #include "strdup.h" #endif #include <errno.h> -#ifndef HAVE_GETOPT_LONG #include "getopt_long.h" + +#ifndef HAVE_OPTRESET int optreset; #endif diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 0598c9c45109c408c2db74fccfecba778bda4d89..f9217f2c0996655d4e4a0fd1e4f211898a5f3344 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -34,7 +34,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.49 2003/08/04 00:43:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.50 2003/08/07 21:11:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -55,12 +55,9 @@ #include <unistd.h> -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif - -#ifndef HAVE_GETOPT_LONG #include "getopt_long.h" + +#ifndef HAVE_OPTRESET int optreset; #endif diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 7dbe42d5a81483c8560a866e231901884a9b78ad..afee6d62a537ccf2bb77c3a09321bbe2d4bf1b62 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.78 2003/08/04 23:59:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.79 2003/08/07 21:11:58 tgl Exp $ */ #include "postgres_fe.h" @@ -17,12 +17,9 @@ #include <win32.h> #endif /* WIN32 */ -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif - -#ifndef HAVE_GETOPT_LONG #include "getopt_long.h" + +#ifndef HAVE_OPTRESET int optreset; #endif diff --git a/src/bin/scripts/common.h b/src/bin/scripts/common.h index 8a6431e724504622aa12ba25d852f1a9a1074e8c..f8cba29eb335bb2fcc584a29e490377bfd29757e 100644 --- a/src/bin/scripts/common.h +++ b/src/bin/scripts/common.h @@ -1,15 +1,8 @@ #include "postgres_fe.h" -#ifdef HAVE_GETOPT_H -#include <getopt.h> -#endif - -#ifndef HAVE_GETOPT_LONG -#include "getopt_long.h" -#endif - #include "libpq-fe.h" #include "pqexpbuffer.h" +#include "getopt_long.h" #ifndef HAVE_OPTRESET int optreset; diff --git a/src/include/getopt_long.h b/src/include/getopt_long.h index 3651cdeee92b2ec42585d1338f89992a4759ddb8..9b155b25dadb845a5cfd140a1eb482e8fb7774dd 100644 --- a/src/include/getopt_long.h +++ b/src/include/getopt_long.h @@ -2,11 +2,16 @@ * Portions Copyright (c) 1987, 1993, 1994 * The Regents of the University of California. All rights reserved. * - * Portions Copyright (c) 2003 - * PostgreSQL Global Development Group + * Portions Copyright (c) 2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/include/getopt_long.h,v 1.2 2003/08/04 00:43:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/include/getopt_long.h,v 1.3 2003/08/07 21:11:58 tgl Exp $ */ +#ifndef GETOPT_LONG_H +#define GETOPT_LONG_H + +#ifdef HAVE_GETOPT_H +#include <getopt.h> +#endif /* These are picked up from the system's getopt() facility. */ extern int opterr; @@ -17,6 +22,8 @@ extern char *optarg; /* Some systems have this, otherwise you need to define it somewhere. */ extern int optreset; +#ifndef HAVE_STRUCT_OPTION + struct option { const char *name; @@ -28,6 +35,14 @@ struct option #define no_argument 0 #define required_argument 1 -int getopt_long(int argc, char *const argv[], +#endif + +#ifndef HAVE_GETOPT_LONG + +extern int getopt_long(int argc, char *const argv[], const char *optstring, const struct option * longopts, int *longindex); + +#endif + +#endif /* GETOPT_LONG_H */ diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index e89cdb8730a519d447198fa7ada214a5f8d0edc9..379f0f4f991be74f3a989bf30de112e795469dec 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -417,6 +417,9 @@ /* Define to 1 if the system has the type `struct fcred'. */ #undef HAVE_STRUCT_FCRED +/* Define to 1 if the system has the type `struct option'. */ +#undef HAVE_STRUCT_OPTION + /* Define to 1 if `sa_len' is member of `struct sockaddr'. */ #undef HAVE_STRUCT_SOCKADDR_SA_LEN