Fix not-null constraint test
[pgsql.git] / config / programs.m4
blob8a118b4e03483539b9ca4c6df49736b4a7f572ff
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_WARN([
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     BISON=""
40   fi
41   # Bison >=3.0 issues warnings about %name-prefix="base_yy", instead
42   # of the now preferred %name-prefix "base_yy", but the latter
43   # doesn't work with Bison 2.3 or less.  So for now we silence the
44   # deprecation warnings.
45   if echo "$pgac_bison_version" | $AWK '{ if ([$]4 >= 3) exit 0; else exit 1;}'
46   then
47     BISONFLAGS="$BISONFLAGS -Wno-deprecated"
48   fi
51 if test -z "$BISON"; then
52   AC_MSG_WARN([
53 *** Without Bison you will not be able to build PostgreSQL from Git nor
54 *** change any of the parser definition files.  You can obtain Bison from
55 *** a GNU mirror site.  (If you are using the official distribution of
56 *** PostgreSQL then you do not need to worry about this, because the Bison
57 *** output is pre-generated.)])
59 dnl We don't need AC_SUBST(BISON) because PGAC_PATH_PROGS did it
60 AC_SUBST(BISONFLAGS)
61 ])# PGAC_PATH_BISON
65 # PGAC_PATH_FLEX
66 # --------------
67 # Look for Flex, set the output variable FLEX to its path if found.
68 # Reject versions before 2.5.35 (the earliest version in the buildfarm
69 # as of 2022). Also find Flex if its installed under `lex', but do not
70 # accept other Lex programs.
72 AC_DEFUN([PGAC_PATH_FLEX],
73 [AC_CACHE_CHECK([for flex], pgac_cv_path_flex,
74 [# Let the user override the test
75 if test -n "$FLEX"; then
76   pgac_cv_path_flex=$FLEX
77 else
78   pgac_save_IFS=$IFS
79   IFS=$PATH_SEPARATOR
80   for pgac_dir in $PATH; do
81     IFS=$pgac_save_IFS
82     if test -z "$pgac_dir" || test x"$pgac_dir" = x"."; then
83       pgac_dir=`pwd`
84     fi
85     for pgac_prog in flex lex; do
86       pgac_candidate="$pgac_dir/$pgac_prog"
87       if test -f "$pgac_candidate" \
88         && $pgac_candidate --version </dev/null >/dev/null 2>&1
89       then
90         echo '%%'  > conftest.l
91         if $pgac_candidate -t conftest.l 2>/dev/null | grep FLEX_SCANNER >/dev/null 2>&1; then
92           pgac_flex_version=`$pgac_candidate --version 2>/dev/null`
93           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;}'
94           then
95             pgac_cv_path_flex=$pgac_candidate
96             break 2
97           else
98             AC_MSG_WARN([
99 *** The installed version of Flex, $pgac_candidate, is too old to use with PostgreSQL.
100 *** Flex version 2.5.35 or later is required, but this is $pgac_flex_version.])
101           fi
102         fi
103       fi
104     done
105   done
106   rm -f conftest.l lex.yy.c
107   : ${pgac_cv_path_flex=no}
109 ])[]dnl AC_CACHE_CHECK
111 if test x"$pgac_cv_path_flex" = x"no"; then
112   AC_MSG_WARN([
113 *** Without Flex you will not be able to build PostgreSQL from Git nor
114 *** change any of the scanner definition files.  You can obtain Flex from
115 *** a GNU mirror site.  (If you are using the official distribution of
116 *** PostgreSQL then you do not need to worry about this because the Flex
117 *** output is pre-generated.)])
119   FLEX=
120 else
121   FLEX=$pgac_cv_path_flex
122   pgac_flex_version=`$FLEX --version 2>/dev/null`
123   AC_MSG_NOTICE([using $pgac_flex_version])
126 AC_SUBST(FLEX)
127 AC_SUBST(FLEXFLAGS)
128 ])# PGAC_PATH_FLEX
132 # PGAC_LDAP_SAFE
133 # --------------
134 # PostgreSQL sometimes loads libldap_r and plain libldap into the same
135 # process.  Check for OpenLDAP versions known not to tolerate doing so; assume
136 # non-OpenLDAP implementations are safe.  The dblink test suite exercises the
137 # hazardous interaction directly.
139 AC_DEFUN([PGAC_LDAP_SAFE],
140 [AC_CACHE_CHECK([for compatible LDAP implementation], [pgac_cv_ldap_safe],
141 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
142 [#include <ldap.h>
143 #if !defined(LDAP_VENDOR_VERSION) || \
144      (defined(LDAP_API_FEATURE_X_OPENLDAP) && \
145       LDAP_VENDOR_VERSION >= 20424 && LDAP_VENDOR_VERSION <= 20431)
146 choke me
147 #endif], [])],
148 [pgac_cv_ldap_safe=yes],
149 [pgac_cv_ldap_safe=no])])
151 if test "$pgac_cv_ldap_safe" != yes; then
152   AC_MSG_WARN([
153 *** With OpenLDAP versions 2.4.24 through 2.4.31, inclusive, each backend
154 *** process that loads libpq (via WAL receiver, dblink, or postgres_fdw) and
155 *** also uses LDAP will crash on exit.])
156 fi])
160 # PGAC_CHECK_READLINE
161 # -------------------
162 # Check for the readline library and dependent libraries, either
163 # termcap or curses.  Also try libedit, since NetBSD's is compatible.
164 # Add the required flags to LIBS, define HAVE_LIBREADLINE.
166 AC_DEFUN([PGAC_CHECK_READLINE],
167 [AC_REQUIRE([AC_CANONICAL_HOST])
169 AC_CACHE_CHECK([for library containing readline], [pgac_cv_check_readline],
170 [pgac_cv_check_readline=no
171 pgac_save_LIBS=$LIBS
172 if test x"$with_libedit_preferred" != x"yes"
173 then    READLINE_ORDER="-lreadline -ledit"
174 else    READLINE_ORDER="-ledit -lreadline"
176 for pgac_rllib in $READLINE_ORDER ; do
177   for pgac_lib in "" " -ltermcap" " -lncurses" " -lcurses" ; do
178     LIBS="${pgac_rllib}${pgac_lib} $pgac_save_LIBS"
179     AC_TRY_LINK_FUNC([readline], [[
180       # Older NetBSD and OpenBSD have a broken linker that does not
181       # recognize dependent libraries; assume curses is needed if we didn't
182       # find any dependency.
183       case $host_os in
184         netbsd* | openbsd*)
185           if test x"$pgac_lib" = x"" ; then
186             pgac_lib=" -lcurses"
187           fi ;;
188       esac
190       pgac_cv_check_readline="${pgac_rllib}${pgac_lib}"
191       break
192     ]])
193   done
194   if test "$pgac_cv_check_readline" != no ; then
195     break
196   fi
197 done
198 LIBS=$pgac_save_LIBS
199 ])[]dnl AC_CACHE_CHECK
201 if test "$pgac_cv_check_readline" != no ; then
202   LIBS="$pgac_cv_check_readline $LIBS"
203   AC_DEFINE(HAVE_LIBREADLINE, 1, [Define if you have a function readline library])
206 ])# PGAC_CHECK_READLINE
210 # PGAC_READLINE_VARIABLES
211 # -----------------------
212 # Some Readline versions lack rl_completion_suppress_quote.
213 # Libedit lacks rl_filename_quote_characters and rl_filename_quoting_function
215 AC_DEFUN([PGAC_READLINE_VARIABLES],
216 [AC_CACHE_CHECK([for rl_completion_suppress_quote], pgac_cv_var_rl_completion_suppress_quote,
217 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
218 #if defined(HAVE_READLINE_READLINE_H)
219 #include <readline/readline.h>
220 #elif defined(HAVE_EDITLINE_READLINE_H)
221 #include <editline/readline.h>
222 #elif defined(HAVE_READLINE_H)
223 #include <readline.h>
224 #endif
226 [rl_completion_suppress_quote = 1;])],
227 [pgac_cv_var_rl_completion_suppress_quote=yes],
228 [pgac_cv_var_rl_completion_suppress_quote=no])])
229 if test x"$pgac_cv_var_rl_completion_suppress_quote" = x"yes"; then
230 AC_DEFINE(HAVE_RL_COMPLETION_SUPPRESS_QUOTE, 1,
231           [Define to 1 if you have the global variable 'rl_completion_suppress_quote'.])
233 AC_CACHE_CHECK([for rl_filename_quote_characters], pgac_cv_var_rl_filename_quote_characters,
234 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
235 #if defined(HAVE_READLINE_READLINE_H)
236 #include <readline/readline.h>
237 #elif defined(HAVE_EDITLINE_READLINE_H)
238 #include <editline/readline.h>
239 #elif defined(HAVE_READLINE_H)
240 #include <readline.h>
241 #endif
243 [rl_filename_quote_characters = "x";])],
244 [pgac_cv_var_rl_filename_quote_characters=yes],
245 [pgac_cv_var_rl_filename_quote_characters=no])])
246 if test x"$pgac_cv_var_rl_filename_quote_characters" = x"yes"; then
247 AC_DEFINE(HAVE_RL_FILENAME_QUOTE_CHARACTERS, 1,
248           [Define to 1 if you have the global variable 'rl_filename_quote_characters'.])
250 AC_CACHE_CHECK([for rl_filename_quoting_function], pgac_cv_var_rl_filename_quoting_function,
251 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>
252 #if defined(HAVE_READLINE_READLINE_H)
253 #include <readline/readline.h>
254 #elif defined(HAVE_EDITLINE_READLINE_H)
255 #include <editline/readline.h>
256 #elif defined(HAVE_READLINE_H)
257 #include <readline.h>
258 #endif
260 [rl_filename_quoting_function = 0;])],
261 [pgac_cv_var_rl_filename_quoting_function=yes],
262 [pgac_cv_var_rl_filename_quoting_function=no])])
263 if test x"$pgac_cv_var_rl_filename_quoting_function" = x"yes"; then
264 AC_DEFINE(HAVE_RL_FILENAME_QUOTING_FUNCTION, 1,
265           [Define to 1 if you have the global variable 'rl_filename_quoting_function'.])
267 ])# PGAC_READLINE_VARIABLES
271 # PGAC_CHECK_GETTEXT
272 # ------------------
273 # We check for bind_textdomain_codeset() not just gettext().  GNU gettext
274 # before 0.10.36 does not have that function, and is generally too incomplete
275 # to be usable.
277 AC_DEFUN([PGAC_CHECK_GETTEXT],
279   AC_SEARCH_LIBS(bind_textdomain_codeset, intl, [],
280                  [AC_MSG_ERROR([a gettext implementation is required for NLS])])
281   AC_CHECK_HEADER([libintl.h], [],
282                   [AC_MSG_ERROR([header file <libintl.h> is required for NLS])])
283   PGAC_PATH_PROGS(MSGFMT, msgfmt)
284   AC_ARG_VAR(MSGFMT, [msgfmt program for NLS])dnl
285   if test -z "$MSGFMT"; then
286     AC_MSG_ERROR([msgfmt is required for NLS])
287   fi
288   AC_CACHE_CHECK([for msgfmt flags], pgac_cv_msgfmt_flags,
289 [if test x"$MSGFMT" != x"" && "$MSGFMT" --version 2>&1 | grep "GNU" >/dev/null; then
290     pgac_cv_msgfmt_flags=-c
291 fi])
292   AC_SUBST(MSGFMT_FLAGS, $pgac_cv_msgfmt_flags)
293   PGAC_PATH_PROGS(MSGMERGE, msgmerge)
294   PGAC_PATH_PROGS(XGETTEXT, xgettext)
295 ])# PGAC_CHECK_GETTEXT
299 # PGAC_CHECK_STRIP
300 # ----------------
301 # Check for a 'strip' program, and figure out if that program can
302 # strip libraries.
304 AC_DEFUN([PGAC_CHECK_STRIP],
306   AC_CHECK_TOOL(STRIP, strip, :)
308   AC_MSG_CHECKING([whether it is possible to strip libraries])
309   if test x"$STRIP" != x"" && "$STRIP" -V 2>&1 | grep "GNU strip" >/dev/null; then
310     STRIP_STATIC_LIB="$STRIP --strip-unneeded"
311     STRIP_SHARED_LIB="$STRIP --strip-unneeded"
312     AC_MSG_RESULT(yes)
313   else
314     case $host_os in
315       darwin*)
316         STRIP="$STRIP -x"
317         STRIP_STATIC_LIB=$STRIP
318         STRIP_SHARED_LIB=$STRIP
319         AC_MSG_RESULT(yes)
320         ;;
321       *)
322         STRIP_STATIC_LIB=:
323         STRIP_SHARED_LIB=:
324         AC_MSG_RESULT(no)
325         ;;
326     esac
327   fi
328   AC_SUBST(STRIP_STATIC_LIB)
329   AC_SUBST(STRIP_SHARED_LIB)
330 ])# PGAC_CHECK_STRIP