Fix mis-deparsing of ORDER BY lists when there is a name conflict.
[pgsql.git] / config / programs.m4
blob490ec9fe9f5d8e1a113bab039f86e5161eda7553
1 # config/programs.m4
4 # PGAC_PATH_PROGS
5 # ---------------
6 # This wrapper for AC_PATH_PROGS behaves like that macro except when
7 # VARIABLE is already set; in that case we just accept the value verbatim.
8 # (AC_PATH_PROGS would accept it only if it looks like an absolute path.)
9 # A desirable future improvement would be to convert a non-absolute-path
10 # input into absolute form.
11 AC_DEFUN([PGAC_PATH_PROGS],
12 [if test -z "$$1"; then
13   AC_PATH_PROGS($@)
14 else
15   # Report the value of $1 in configure's output in all cases.
16   AC_MSG_CHECKING([for $1])
17   AC_MSG_RESULT([$$1])
22 # PGAC_PATH_BISON
23 # ---------------
24 # Look for Bison, set the output variable BISON to its path if found.
25 # Reject versions before 2.3 (the earliest version in the buildfarm
26 # as of 2022). Note we do not accept other implementations of yacc.
28 AC_DEFUN([PGAC_PATH_BISON],
29 [PGAC_PATH_PROGS(BISON, bison)
31 if test "$BISON"; then
32   pgac_bison_version=`$BISON --version 2>/dev/null | sed q`
33   AC_MSG_NOTICE([using $pgac_bison_version])
34   if echo "$pgac_bison_version" | $AWK '{ if ([$]4 < 2.3) exit 0; else exit 1;}'
35   then
36     AC_MSG_ERROR([
37 *** The installed version of Bison, $BISON, is too old to use with PostgreSQL.
38 *** Bison version 2.3 or later is required, but this is $pgac_bison_version.])
39   fi
40   # Bison >=3.0 issues warnings about %name-prefix="base_yy", instead
41   # of the now preferred %name-prefix "base_yy", but the latter
42   # doesn't work with Bison 2.3 or less.  So for now we silence the
43   # deprecation warnings.
44   if echo "$pgac_bison_version" | $AWK '{ if ([$]4 >= 3) exit 0; else exit 1;}'
45   then
46     BISONFLAGS="$BISONFLAGS -Wno-deprecated"
47   fi
50 if test -z "$BISON"; then
51   AC_MSG_ERROR([bison not found])
53 dnl We don't need AC_SUBST(BISON) because PGAC_PATH_PROGS did it
54 AC_SUBST(BISONFLAGS)
55 ])# PGAC_PATH_BISON
59 # PGAC_PATH_FLEX
60 # --------------
61 # Look for Flex, set the output variable FLEX to its path if found.
62 # Reject versions before 2.5.35 (the earliest version in the buildfarm
63 # as of 2022). Also find Flex if its installed under `lex', but do not
64 # accept other Lex programs.
66 AC_DEFUN([PGAC_PATH_FLEX],
67 [AC_CACHE_CHECK([for flex], pgac_cv_path_flex,
68 [# Let the user override the test
69 if test -n "$FLEX"; then
70   pgac_cv_path_flex=$FLEX
71 else
72   pgac_save_IFS=$IFS
73   IFS=$PATH_SEPARATOR
74   for pgac_dir in $PATH; do
75     IFS=$pgac_save_IFS
76     if test -z "$pgac_dir" || test x"$pgac_dir" = x"."; then
77       pgac_dir=`pwd`
78     fi
79     for pgac_prog in flex lex; do
80       pgac_candidate="$pgac_dir/$pgac_prog"
81       if test -f "$pgac_candidate" \
82         && $pgac_candidate --version </dev/null >/dev/null 2>&1
83       then
84         echo '%%'  > conftest.l
85         if $pgac_candidate -t conftest.l 2>/dev/null | grep FLEX_SCANNER >/dev/null 2>&1; then
86           pgac_flex_version=`$pgac_candidate --version 2>/dev/null`
87           if echo "$pgac_flex_version" | sed ['s/[.a-z]/ /g'] | $AWK '{ if ([$]1 == 2 && ([$]2 > 5 || ([$]2 == 5 && [$]3 >= 35))) exit 0; else exit 1;}'
88           then
89             pgac_cv_path_flex=$pgac_candidate
90             break 2
91           else
92             AC_MSG_ERROR([
93 *** The installed version of Flex, $pgac_candidate, is too old to use with PostgreSQL.
94 *** Flex version 2.5.35 or later is required, but this is $pgac_flex_version.])
95           fi
96         fi
97       fi
98     done
99   done
100   rm -f conftest.l lex.yy.c
101   : ${pgac_cv_path_flex=no}
103 ])[]dnl AC_CACHE_CHECK
105 if test x"$pgac_cv_path_flex" = x"no"; then
106   AC_MSG_ERROR([flex not found])
107 else
108   FLEX=$pgac_cv_path_flex
109   pgac_flex_version=`$FLEX --version 2>/dev/null`
110   AC_MSG_NOTICE([using $pgac_flex_version])
113 AC_SUBST(FLEX)
114 AC_SUBST(FLEXFLAGS)
115 ])# PGAC_PATH_FLEX
119 # PGAC_LDAP_SAFE
120 # --------------
121 # PostgreSQL sometimes loads libldap_r and plain libldap into the same
122 # process.  Check for OpenLDAP versions known not to tolerate doing so; assume
123 # non-OpenLDAP implementations are safe.  The dblink test suite exercises the
124 # hazardous interaction directly.
126 AC_DEFUN([PGAC_LDAP_SAFE],
127 [AC_CACHE_CHECK([for compatible LDAP implementation], [pgac_cv_ldap_safe],
128 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
129 [#include <ldap.h>
130 #if !defined(LDAP_VENDOR_VERSION) || \
131      (defined(LDAP_API_FEATURE_X_OPENLDAP) && \
132       LDAP_VENDOR_VERSION >= 20424 && LDAP_VENDOR_VERSION <= 20431)
133 choke me
134 #endif], [])],
135 [pgac_cv_ldap_safe=yes],
136 [pgac_cv_ldap_safe=no])])
138 if test "$pgac_cv_ldap_safe" != yes; then
139   AC_MSG_WARN([
140 *** With OpenLDAP versions 2.4.24 through 2.4.31, inclusive, each backend
141 *** process that loads libpq (via WAL receiver, dblink, or postgres_fdw) and
142 *** also uses LDAP will crash on exit.])
143 fi])
147 # PGAC_CHECK_READLINE
148 # -------------------
149 # Check for the readline library and dependent libraries, either
150 # termcap or curses.  Also try libedit, since NetBSD's is compatible.
151 # Add the required flags to LIBS, define HAVE_LIBREADLINE.
153 AC_DEFUN([PGAC_CHECK_READLINE],
154 [AC_REQUIRE([AC_CANONICAL_HOST])
156 AC_CACHE_CHECK([for library containing readline], [pgac_cv_check_readline],
157 [pgac_cv_check_readline=no
158 pgac_save_LIBS=$LIBS
159 if test x"$with_libedit_preferred" != x"yes"
160 then    READLINE_ORDER="-lreadline -ledit"
161 else    READLINE_ORDER="-ledit -lreadline"
163 for pgac_rllib in $READLINE_ORDER ; do
164   for pgac_lib in "" " -ltermcap" " -lncurses" " -lcurses" ; do
165     LIBS="${pgac_rllib}${pgac_lib} $pgac_save_LIBS"
166     AC_TRY_LINK_FUNC([readline], [[
167       # Older NetBSD and OpenBSD have a broken linker that does not
168       # recognize dependent libraries; assume curses is needed if we didn't
169       # find any dependency.
170       case $host_os in
171         netbsd* | openbsd*)
172           if test x"$pgac_lib" = x"" ; then
173             pgac_lib=" -lcurses"
174           fi ;;
175       esac
177       pgac_cv_check_readline="${pgac_rllib}${pgac_lib}"
178       break
179     ]])
180   done
181   if test "$pgac_cv_check_readline" != no ; then
182     break
183   fi
184 done
185 LIBS=$pgac_save_LIBS
186 ])[]dnl AC_CACHE_CHECK
188 if test "$pgac_cv_check_readline" != no ; then
189   LIBS="$pgac_cv_check_readline $LIBS"
190   AC_DEFINE(HAVE_LIBREADLINE, 1, [Define if you have a function readline library])
193 ])# PGAC_CHECK_READLINE
197 # PGAC_READLINE_VARIABLES
198 # -----------------------
199 # Some Readline versions lack rl_completion_suppress_quote.
200 # Libedit lacks rl_filename_quote_characters and rl_filename_quoting_function
202 AC_DEFUN([PGAC_READLINE_VARIABLES],
203 [AC_CACHE_CHECK([for rl_completion_suppress_quote], pgac_cv_var_rl_completion_suppress_quote,
204 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
205 #if defined(HAVE_READLINE_READLINE_H)
206 #include <readline/readline.h>
207 #elif defined(HAVE_EDITLINE_READLINE_H)
208 #include <editline/readline.h>
209 #elif defined(HAVE_READLINE_H)
210 #include <readline.h>
211 #endif
213 [rl_completion_suppress_quote = 1;])],
214 [pgac_cv_var_rl_completion_suppress_quote=yes],
215 [pgac_cv_var_rl_completion_suppress_quote=no])])
216 if test x"$pgac_cv_var_rl_completion_suppress_quote" = x"yes"; then
217 AC_DEFINE(HAVE_RL_COMPLETION_SUPPRESS_QUOTE, 1,
218           [Define to 1 if you have the global variable 'rl_completion_suppress_quote'.])
220 AC_CACHE_CHECK([for rl_filename_quote_characters], pgac_cv_var_rl_filename_quote_characters,
221 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
222 #if defined(HAVE_READLINE_READLINE_H)
223 #include <readline/readline.h>
224 #elif defined(HAVE_EDITLINE_READLINE_H)
225 #include <editline/readline.h>
226 #elif defined(HAVE_READLINE_H)
227 #include <readline.h>
228 #endif
230 [rl_filename_quote_characters = "x";])],
231 [pgac_cv_var_rl_filename_quote_characters=yes],
232 [pgac_cv_var_rl_filename_quote_characters=no])])
233 if test x"$pgac_cv_var_rl_filename_quote_characters" = x"yes"; then
234 AC_DEFINE(HAVE_RL_FILENAME_QUOTE_CHARACTERS, 1,
235           [Define to 1 if you have the global variable 'rl_filename_quote_characters'.])
237 AC_CACHE_CHECK([for rl_filename_quoting_function], pgac_cv_var_rl_filename_quoting_function,
238 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
239 #if defined(HAVE_READLINE_READLINE_H)
240 #include <readline/readline.h>
241 #elif defined(HAVE_EDITLINE_READLINE_H)
242 #include <editline/readline.h>
243 #elif defined(HAVE_READLINE_H)
244 #include <readline.h>
245 #endif
247 [rl_filename_quoting_function = 0;])],
248 [pgac_cv_var_rl_filename_quoting_function=yes],
249 [pgac_cv_var_rl_filename_quoting_function=no])])
250 if test x"$pgac_cv_var_rl_filename_quoting_function" = x"yes"; then
251 AC_DEFINE(HAVE_RL_FILENAME_QUOTING_FUNCTION, 1,
252           [Define to 1 if you have the global variable 'rl_filename_quoting_function'.])
254 ])# PGAC_READLINE_VARIABLES
258 # PGAC_CHECK_GETTEXT
259 # ------------------
260 # We check for bind_textdomain_codeset() not just gettext().  GNU gettext
261 # before 0.10.36 does not have that function, and is generally too incomplete
262 # to be usable.
264 AC_DEFUN([PGAC_CHECK_GETTEXT],
266   AC_SEARCH_LIBS(bind_textdomain_codeset, intl, [],
267                  [AC_MSG_ERROR([a gettext implementation is required for NLS])])
268   AC_CHECK_HEADER([libintl.h], [],
269                   [AC_MSG_ERROR([header file <libintl.h> is required for NLS])])
270   PGAC_PATH_PROGS(MSGFMT, msgfmt)
271   AC_ARG_VAR(MSGFMT, [msgfmt program for NLS])dnl
272   if test -z "$MSGFMT"; then
273     AC_MSG_ERROR([msgfmt is required for NLS])
274   fi
275   AC_CACHE_CHECK([for msgfmt flags], pgac_cv_msgfmt_flags,
276 [if test x"$MSGFMT" != x"" && "$MSGFMT" --version 2>&1 | grep "GNU" >/dev/null; then
277     pgac_cv_msgfmt_flags=-c
278 fi])
279   AC_SUBST(MSGFMT_FLAGS, $pgac_cv_msgfmt_flags)
280   PGAC_PATH_PROGS(MSGMERGE, msgmerge)
281   PGAC_PATH_PROGS(XGETTEXT, xgettext)
282 ])# PGAC_CHECK_GETTEXT
286 # PGAC_CHECK_STRIP
287 # ----------------
288 # Check for a 'strip' program, and figure out if that program can
289 # strip libraries.
291 AC_DEFUN([PGAC_CHECK_STRIP],
293   AC_CHECK_TOOL(STRIP, strip, :)
295   AC_MSG_CHECKING([whether it is possible to strip libraries])
296   if test x"$STRIP" != x"" && "$STRIP" -V 2>&1 | grep "GNU strip" >/dev/null; then
297     STRIP_STATIC_LIB="$STRIP --strip-unneeded"
298     STRIP_SHARED_LIB="$STRIP --strip-unneeded"
299     AC_MSG_RESULT(yes)
300   else
301     case $host_os in
302       darwin*)
303         STRIP="$STRIP -x"
304         STRIP_STATIC_LIB=$STRIP
305         STRIP_SHARED_LIB=$STRIP
306         AC_MSG_RESULT(yes)
307         ;;
308       *)
309         STRIP_STATIC_LIB=:
310         STRIP_SHARED_LIB=:
311         AC_MSG_RESULT(no)
312         ;;
313     esac
314   fi
315   AC_SUBST(STRIP_STATIC_LIB)
316   AC_SUBST(STRIP_SHARED_LIB)
317 ])# PGAC_CHECK_STRIP