1dnl Process this file with autoconf to produce a configure script.
2dnl configure.in
3dnl
4dnl Developers, please strive to achieve this order:
5dnl
6dnl 0. Initialization and options processing
7dnl 1. Programs
8dnl 2. Libraries
9dnl 3. Header files
10dnl 4. Types
11dnl 5. Structures
12dnl 6. Compiler characteristics
13dnl 7. Functions, global variables
14dnl 8. System services
15dnl
16dnl Read the Autoconf manual for details.
17dnl
18m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
19
20AC_INIT([PostgreSQL], [9.6.24], [pgsql-bugs@postgresql.org])
21
22m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required.
23Untested combinations of 'autoconf' and PostgreSQL versions are not
24recommended.  You can remove the check from 'configure.in' but it is then
25your responsibility whether the result works or not.])])
26AC_COPYRIGHT([Copyright (c) 1996-2016, PostgreSQL Global Development Group])
27AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c])
28AC_CONFIG_AUX_DIR(config)
29AC_PREFIX_DEFAULT(/usr/local/pgsql)
30AC_SUBST(configure_args, [$ac_configure_args])
31
32[PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\.[0-9][0-9]*\)'`]
33AC_SUBST(PG_MAJORVERSION)
34AC_DEFINE_UNQUOTED(PG_MAJORVERSION, "$PG_MAJORVERSION", [PostgreSQL major version as a string])
35
36PGAC_ARG_REQ(with, extra-version, [STRING], [append STRING to version],
37             [PG_VERSION="$PACKAGE_VERSION$withval"],
38             [PG_VERSION="$PACKAGE_VERSION"])
39AC_DEFINE_UNQUOTED(PG_VERSION, "$PG_VERSION", [PostgreSQL version as a string])
40
41AC_CANONICAL_HOST
42
43template=
44AC_MSG_CHECKING([which template to use])
45
46PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
47[
48  case $withval in
49    list)   echo; ls "$srcdir/src/template"; exit;;
50    *)      if test -f "$srcdir/src/template/$with_template" ; then
51              template=$withval
52            else
53              AC_MSG_ERROR(['$withval' is not a valid template name. Use 'list' for a list.])
54            fi;;
55  esac
56],
57[
58# --with-template not given
59
60case $host_os in
61     aix*) template=aix ;;
62  cygwin*) template=cygwin ;;
63  darwin*) template=darwin ;;
64dragonfly*) template=netbsd ;;
65 freebsd*) template=freebsd ;;
66    hpux*) template=hpux ;;
67 linux*|gnu*|k*bsd*-gnu)
68           template=linux ;;
69   mingw*) template=win32 ;;
70  netbsd*) template=netbsd ;;
71 openbsd*) template=openbsd ;;
72     sco*) template=sco ;;
73 solaris*) template=solaris ;;
74   sysv5*) template=unixware ;;
75esac
76
77  if test x"$template" = x"" ; then
78    AC_MSG_ERROR([[
79*******************************************************************
80PostgreSQL has apparently not been ported to your platform yet.
81To try a manual configuration, look into the src/template directory
82for a similar platform and use the '--with-template=' option.
83
84Please also contact <pgsql-bugs@postgresql.org> to see about
85rectifying this.  Include the above 'checking host system type...'
86line.
87*******************************************************************
88]])
89  fi
90
91])
92
93AC_MSG_RESULT([$template])
94
95PORTNAME=$template
96AC_SUBST(PORTNAME)
97
98# Initialize default assumption that we do not need separate assembly code
99# for TAS (test-and-set).  This can be overridden by the template file
100# when it's executed.
101need_tas=no
102tas_file=dummy.s
103
104
105
106##
107## Command line options
108##
109
110#
111# Add non-standard directories to the include path
112#
113PGAC_ARG_REQ(with, includes, [DIRS], [look for additional header files in DIRS])
114
115
116#
117# Add non-standard directories to the library search path
118#
119PGAC_ARG_REQ(with, libraries, [DIRS], [look for additional libraries in DIRS],
120             [LIBRARY_DIRS=$withval])
121
122PGAC_ARG_REQ(with, libs,      [DIRS], [alternative spelling of --with-libraries],
123             [LIBRARY_DIRS=$withval])
124
125
126#
127# 64-bit integer date/time storage: enabled by default.
128#
129AC_MSG_CHECKING([whether to build with 64-bit integer date/time support])
130PGAC_ARG_BOOL(enable, integer-datetimes, yes, [disable 64-bit integer date/time support],
131              [AC_DEFINE([USE_INTEGER_DATETIMES], 1,
132                         [Define to 1 if you want 64-bit integer timestamp and interval support. (--enable-integer-datetimes)])])
133AC_MSG_RESULT([$enable_integer_datetimes])
134
135
136#
137# NLS
138#
139AC_MSG_CHECKING([whether NLS is wanted])
140PGAC_ARG_OPTARG(enable, nls,
141                [LANGUAGES], [enable Native Language Support],
142                [],
143                [WANTED_LANGUAGES=$enableval],
144                [AC_DEFINE(ENABLE_NLS, 1,
145                           [Define to 1 if you want National Language Support. (--enable-nls)])])
146AC_MSG_RESULT([$enable_nls])
147AC_SUBST(enable_nls)
148AC_SUBST(WANTED_LANGUAGES)
149
150#
151# Default port number (--with-pgport), default 5432
152#
153AC_MSG_CHECKING([for default port number])
154PGAC_ARG_REQ(with, pgport, [PORTNUM], [set default port number [5432]],
155             [default_port=$withval],
156             [default_port=5432])
157AC_MSG_RESULT([$default_port])
158# Need both of these because some places want an integer and some a string
159AC_DEFINE_UNQUOTED(DEF_PGPORT, ${default_port},
160[Define to the default TCP port number on which the server listens and
161to which clients will try to connect.  This can be overridden at run-time,
162but it's convenient if your clients have the right default compiled in.
163(--with-pgport=PORTNUM)])
164AC_DEFINE_UNQUOTED(DEF_PGPORT_STR, "${default_port}",
165                   [Define to the default TCP port number as a string constant.])
166AC_SUBST(default_port)
167
168# It's worth validating port; you can get very confusing errors otherwise
169if test x"$default_port" = x""; then
170  AC_MSG_ERROR([invalid --with-pgport specification: empty string])
171elif test ! x`echo "$default_port" | sed -e 's/[[0-9]]*//'` = x""; then
172  AC_MSG_ERROR([invalid --with-pgport specification: must be a number])
173elif test ! x`echo "$default_port" | sed -e 's/^0.//'` = x"$default_port"; then
174  AC_MSG_ERROR([invalid --with-pgport specification: must not have leading 0])
175elif test "$default_port" -lt "1" -o "$default_port" -gt "65535"; then
176  AC_MSG_ERROR([invalid --with-pgport specification: must be between 1 and 65535])
177fi
178
179#
180# '-rpath'-like feature can be disabled
181#
182PGAC_ARG_BOOL(enable, rpath, yes,
183              [do not embed shared library search path in executables])
184AC_SUBST(enable_rpath)
185
186#
187# Spinlocks
188#
189PGAC_ARG_BOOL(enable, spinlocks, yes,
190              [do not use spinlocks])
191
192#
193# Atomic operations
194#
195PGAC_ARG_BOOL(enable, atomics, yes,
196              [do not use atomic operations])
197
198#
199# --enable-debug adds -g to compiler flags
200#
201PGAC_ARG_BOOL(enable, debug, no,
202              [build with debugging symbols (-g)])
203AC_SUBST(enable_debug)
204
205#
206# --enable-profiling enables gcc profiling
207#
208PGAC_ARG_BOOL(enable, profiling, no,
209              [build with profiling enabled ])
210
211#
212# --enable-coverage enables generation of code coverage metrics with gcov
213#
214PGAC_ARG_BOOL(enable, coverage, no,
215              [build with coverage testing instrumentation],
216[AC_CHECK_PROGS(GCOV, gcov)
217if test -z "$GCOV"; then
218  AC_MSG_ERROR([gcov not found])
219fi
220AC_CHECK_PROGS(LCOV, lcov)
221if test -z "$LCOV"; then
222  AC_MSG_ERROR([lcov not found])
223fi
224AC_CHECK_PROGS(GENHTML, genhtml)
225if test -z "$GENHTML"; then
226  AC_MSG_ERROR([genhtml not found])
227fi])
228AC_SUBST(enable_coverage)
229
230#
231# DTrace
232#
233PGAC_ARG_BOOL(enable, dtrace, no,
234              [build with DTrace support],
235[AC_CHECK_PROGS(DTRACE, dtrace)
236if test -z "$DTRACE"; then
237  AC_MSG_ERROR([dtrace not found])
238fi
239AC_SUBST(DTRACEFLAGS)])
240AC_SUBST(enable_dtrace)
241
242#
243# TAP tests
244#
245PGAC_ARG_BOOL(enable, tap-tests, no,
246              [enable TAP tests (requires Perl and IPC::Run)])
247AC_SUBST(enable_tap_tests)
248
249#
250# Block size
251#
252AC_MSG_CHECKING([for block size])
253PGAC_ARG_REQ(with, blocksize, [BLOCKSIZE], [set table block size in kB [8]],
254             [blocksize=$withval],
255             [blocksize=8])
256case ${blocksize} in
257  1) BLCKSZ=1024;;
258  2) BLCKSZ=2048;;
259  4) BLCKSZ=4096;;
260  8) BLCKSZ=8192;;
261 16) BLCKSZ=16384;;
262 32) BLCKSZ=32768;;
263  *) AC_MSG_ERROR([Invalid block size. Allowed values are 1,2,4,8,16,32.])
264esac
265AC_MSG_RESULT([${blocksize}kB])
266
267AC_DEFINE_UNQUOTED([BLCKSZ], ${BLCKSZ}, [
268 Size of a disk block --- this also limits the size of a tuple.  You
269 can set it bigger if you need bigger tuples (although TOAST should
270 reduce the need to have large tuples, since fields can be spread
271 across multiple tuples).
272
273 BLCKSZ must be a power of 2.  The maximum possible value of BLCKSZ
274 is currently 2^15 (32768).  This is determined by the 15-bit widths
275 of the lp_off and lp_len fields in ItemIdData (see
276 include/storage/itemid.h).
277
278 Changing BLCKSZ requires an initdb.
279])
280
281#
282# Relation segment size
283#
284AC_MSG_CHECKING([for segment size])
285PGAC_ARG_REQ(with, segsize, [SEGSIZE], [set table segment size in GB [1]],
286             [segsize=$withval],
287             [segsize=1])
288# this expression is set up to avoid unnecessary integer overflow
289# blocksize is already guaranteed to be a factor of 1024
290RELSEG_SIZE=`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024`
291test $? -eq 0 || exit 1
292AC_MSG_RESULT([${segsize}GB])
293
294AC_DEFINE_UNQUOTED([RELSEG_SIZE], ${RELSEG_SIZE}, [
295 RELSEG_SIZE is the maximum number of blocks allowed in one disk file.
296 Thus, the maximum size of a single file is RELSEG_SIZE * BLCKSZ;
297 relations bigger than that are divided into multiple files.
298
299 RELSEG_SIZE * BLCKSZ must be less than your OS' limit on file size.
300 This is often 2 GB or 4GB in a 32-bit operating system, unless you
301 have large file support enabled.  By default, we make the limit 1 GB
302 to avoid any possible integer-overflow problems within the OS.
303 A limit smaller than necessary only means we divide a large
304 relation into more chunks than necessary, so it seems best to err
305 in the direction of a small limit.
306
307 A power-of-2 value is recommended to save a few cycles in md.c,
308 but is not absolutely required.
309
310 Changing RELSEG_SIZE requires an initdb.
311])
312
313#
314# WAL block size
315#
316AC_MSG_CHECKING([for WAL block size])
317PGAC_ARG_REQ(with, wal-blocksize, [BLOCKSIZE], [set WAL block size in kB [8]],
318             [wal_blocksize=$withval],
319             [wal_blocksize=8])
320case ${wal_blocksize} in
321  1) XLOG_BLCKSZ=1024;;
322  2) XLOG_BLCKSZ=2048;;
323  4) XLOG_BLCKSZ=4096;;
324  8) XLOG_BLCKSZ=8192;;
325 16) XLOG_BLCKSZ=16384;;
326 32) XLOG_BLCKSZ=32768;;
327 64) XLOG_BLCKSZ=65536;;
328  *) AC_MSG_ERROR([Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.])
329esac
330AC_MSG_RESULT([${wal_blocksize}kB])
331
332AC_DEFINE_UNQUOTED([XLOG_BLCKSZ], ${XLOG_BLCKSZ}, [
333 Size of a WAL file block.  This need have no particular relation to BLCKSZ.
334 XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O,
335 XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O
336 buffers, else direct I/O may fail.
337
338 Changing XLOG_BLCKSZ requires an initdb.
339])
340
341#
342# WAL segment size
343#
344AC_MSG_CHECKING([for WAL segment size])
345PGAC_ARG_REQ(with, wal-segsize, [SEGSIZE], [set WAL segment size in MB [16]],
346             [wal_segsize=$withval],
347             [wal_segsize=16])
348case ${wal_segsize} in
349  1) ;;
350  2) ;;
351  4) ;;
352  8) ;;
353 16) ;;
354 32) ;;
355 64) ;;
356  *) AC_MSG_ERROR([Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.])
357esac
358AC_MSG_RESULT([${wal_segsize}MB])
359
360AC_DEFINE_UNQUOTED([XLOG_SEG_SIZE], [(${wal_segsize} * 1024 * 1024)], [
361 XLOG_SEG_SIZE is the size of a single WAL file.  This must be a power of 2
362 and larger than XLOG_BLCKSZ (preferably, a great deal larger than
363 XLOG_BLCKSZ).
364
365 Changing XLOG_SEG_SIZE requires an initdb.
366])
367
368#
369# C compiler
370#
371
372# For historical reasons you can also use --with-CC to specify the C compiler
373# to use, although the standard way to do this is to set the CC environment
374# variable.
375PGAC_ARG_REQ(with, CC, [CMD], [set compiler (deprecated)], [CC=$with_CC])
376
377case $template in
378  aix) pgac_cc_list="gcc xlc";;
379    *) pgac_cc_list="gcc cc";;
380esac
381
382AC_PROG_CC([$pgac_cc_list])
383
384# Check if it's Intel's compiler, which (usually) pretends to be gcc,
385# but has idiosyncrasies of its own.  We assume icc will define
386# __INTEL_COMPILER regardless of CFLAGS.
387AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@ifndef __INTEL_COMPILER
388choke me
389@%:@endif])], [ICC=yes], [ICC=no])
390
391# Check if it's Sun Studio compiler. We assume that
392# __SUNPRO_C will be defined for Sun Studio compilers
393AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@ifndef __SUNPRO_C
394choke me
395@%:@endif])], [SUN_STUDIO_CC=yes], [SUN_STUDIO_CC=no])
396
397AC_SUBST(SUN_STUDIO_CC)
398
399unset CFLAGS
400
401#
402# Read the template
403#
404. "$srcdir/src/template/$template" || exit
405
406# CFLAGS are selected so:
407# If the user specifies something in the environment, that is used.
408# else:  If the template file set something, that is used.
409# else:  If coverage was enabled, don't set anything.
410# else:  If the compiler is GCC, then we use -O2.
411# else:  If the compiler is something else, then we use -O, unless debugging.
412
413if test "$ac_env_CFLAGS_set" = set; then
414  CFLAGS=$ac_env_CFLAGS_value
415elif test "${CFLAGS+set}" = set; then
416  : # (keep what template set)
417elif test "$enable_coverage" = yes; then
418  : # no optimization by default
419elif test "$GCC" = yes; then
420  CFLAGS="-O2"
421else
422  # if the user selected debug mode, don't use -O
423  if test "$enable_debug" != yes; then
424    CFLAGS="-O"
425  fi
426fi
427
428# CFLAGS we determined above will be added back at the end
429user_CFLAGS=$CFLAGS
430CFLAGS=""
431
432# set CFLAGS_VECTOR from the environment, if available
433if test "$ac_env_CFLAGS_VECTOR_set" = set; then
434  CFLAGS_VECTOR=$ac_env_CFLAGS_VECTOR_value
435fi
436
437# Some versions of GCC support some additional useful warning flags.
438# Check whether they are supported, and add them to CFLAGS if so.
439# ICC pretends to be GCC but it's lying; it doesn't support these flags,
440# but has its own.  Also check other compiler-specific flags here.
441
442if test "$GCC" = yes -a "$ICC" = no; then
443  CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith"
444  # These work in some but not all gcc versions
445  PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
446  PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
447  PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
448  # This was included in -Wall/-Wformat in older GCC versions
449  PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
450  # Disable strict-aliasing rules; needed for gcc 3.3+
451  PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
452  # Disable optimizations that assume no overflow; needed for gcc 4.3+
453  PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
454  # Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
455  PGAC_PROG_CC_CFLAGS_OPT([-fexcess-precision=standard])
456  # Optimization flags for specific files that benefit from vectorization
457  PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-funroll-loops])
458  PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-ftree-vectorize])
459  # We want to suppress clang's unhelpful unused-command-line-argument warnings
460  # but gcc won't complain about unrecognized -Wno-foo switches, so we have to
461  # test for the positive form and if that works, add the negative form
462  NOT_THE_CFLAGS=""
463  PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wunused-command-line-argument])
464  if test -n "$NOT_THE_CFLAGS"; then
465    CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
466  fi
467  # Similarly disable useless truncation warnings from gcc 8+
468  NOT_THE_CFLAGS=""
469  PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wformat-truncation])
470  if test -n "$NOT_THE_CFLAGS"; then
471    CFLAGS="$CFLAGS -Wno-format-truncation"
472  fi
473  NOT_THE_CFLAGS=""
474  PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wstringop-truncation])
475  if test -n "$NOT_THE_CFLAGS"; then
476    CFLAGS="$CFLAGS -Wno-stringop-truncation"
477  fi
478elif test "$ICC" = yes; then
479  # Intel's compiler has a bug/misoptimization in checking for
480  # division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
481  PGAC_PROG_CC_CFLAGS_OPT([-mp1])
482  # Make sure strict aliasing is off (though this is said to be the default)
483  PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
484elif test "$PORTNAME" = "aix"; then
485  # AIX's xlc has to have strict aliasing turned off too
486  PGAC_PROG_CC_CFLAGS_OPT([-qnoansialias])
487  PGAC_PROG_CC_CFLAGS_OPT([-qlonglong])
488elif test "$PORTNAME" = "hpux"; then
489  # On some versions of HP-UX, libm functions do not set errno by default.
490  # Fix that by using +Olibmerrno if the compiler recognizes it.
491  PGAC_PROG_CC_CFLAGS_OPT([+Olibmerrno])
492fi
493
494AC_SUBST(CFLAGS_VECTOR)
495
496# supply -g if --enable-debug
497if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
498  CFLAGS="$CFLAGS -g"
499fi
500
501# enable code coverage if --enable-coverage
502if test "$enable_coverage" = yes; then
503  if test "$GCC" = yes; then
504    CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
505  else
506    AC_MSG_ERROR([--enable-coverage is supported only when using GCC])
507  fi
508fi
509
510# enable profiling if --enable-profiling
511if test "$enable_profiling" = yes && test "$ac_cv_prog_cc_g" = yes; then
512  if test "$GCC" = yes; then
513    AC_DEFINE([PROFILE_PID_DIR], 1,
514           [Define to 1 to allow profiling output to be saved separately for each process.])
515    CFLAGS="$CFLAGS -pg $PLATFORM_PROFILE_FLAGS"
516  else
517    AC_MSG_ERROR([--enable-profiling is supported only when using GCC])
518  fi
519fi
520
521# We already have this in Makefile.win32, but configure needs it too
522if test "$PORTNAME" = "win32"; then
523  CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
524fi
525
526# Now that we're done automatically adding stuff to CFLAGS, put back the
527# user-specified flags (if any) at the end.  This lets users override
528# the automatic additions.
529CFLAGS="$CFLAGS $user_CFLAGS"
530
531# The template file must set up CFLAGS_SL; we don't support user override
532AC_SUBST(CFLAGS_SL)
533
534# Check if the compiler still works with the final flag settings
535AC_MSG_CHECKING([whether the C compiler still works])
536AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
537  [AC_MSG_RESULT(yes)],
538  [AC_MSG_RESULT(no)
539   AC_MSG_ERROR([cannot proceed])])
540
541# Defend against gcc -ffast-math
542if test "$GCC" = yes; then
543AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@ifdef __FAST_MATH__
544choke me
545@%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
546fi
547
548# Defend against clang being used on x86-32 without SSE2 enabled.  As current
549# versions of clang do not understand -fexcess-precision=standard, the use of
550# x87 floating point operations leads to problems like isinf possibly returning
551# false for a value that is infinite when converted from the 80bit register to
552# the 8byte memory representation.
553#
554# Only perform the test if the compiler doesn't understand
555# -fexcess-precision=standard, that way a potentially fixed compiler will work
556# automatically.
557if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
558AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
559@%:@if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
560choke me
561@%:@endif
562])], [],
563[AC_MSG_ERROR([Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc.])])
564fi
565
566AC_PROG_CPP
567AC_SUBST(GCC)
568
569
570#
571# Set up TAS assembly code if needed; the template file has now had its
572# chance to request this.
573#
574AC_CONFIG_LINKS([src/backend/port/tas.s:src/backend/port/tas/${tas_file}])
575
576if test "$need_tas" = yes ; then
577  TAS=tas.o
578else
579  TAS=""
580fi
581AC_SUBST(TAS)
582
583
584#
585# Automatic dependency tracking
586#
587PGAC_ARG_BOOL(enable, depend, no, [turn on automatic dependency tracking],
588              [autodepend=yes])
589AC_SUBST(autodepend)
590
591
592#
593# Enable assert checks
594#
595PGAC_ARG_BOOL(enable, cassert, no, [enable assertion checks (for debugging)],
596              [AC_DEFINE([USE_ASSERT_CHECKING], 1,
597                         [Define to 1 to build with assertion checks. (--enable-cassert)])])
598
599
600#
601# Include directories
602#
603ac_save_IFS=$IFS
604IFS="${IFS}${PATH_SEPARATOR}"
605# SRCH_INC comes from the template file
606for dir in $with_includes $SRCH_INC; do
607  if test -d "$dir"; then
608    INCLUDES="$INCLUDES -I$dir"
609  else
610    AC_MSG_WARN([*** Include directory $dir does not exist.])
611  fi
612done
613IFS=$ac_save_IFS
614AC_SUBST(INCLUDES)
615
616
617#
618# Library directories
619#
620ac_save_IFS=$IFS
621IFS="${IFS}${PATH_SEPARATOR}"
622# LIBRARY_DIRS comes from command line, SRCH_LIB from template file.
623for dir in $LIBRARY_DIRS $SRCH_LIB; do
624  if test -d "$dir"; then
625    LIBDIRS="$LIBDIRS -L$dir"
626  else
627    AC_MSG_WARN([*** Library directory $dir does not exist.])
628  fi
629done
630IFS=$ac_save_IFS
631
632#
633# Enable thread-safe client libraries
634#
635AC_MSG_CHECKING([allow thread-safe client libraries])
636PGAC_ARG_BOOL(enable, thread-safety, yes, [disable thread-safety in client libraries])
637if test "$enable_thread_safety" = yes; then
638  AC_DEFINE([ENABLE_THREAD_SAFETY], 1,
639          [Define to 1 to build client libraries as thread-safe code. (--enable-thread-safety)])
640fi
641AC_MSG_RESULT([$enable_thread_safety])
642AC_SUBST(enable_thread_safety)
643
644#
645# Optionally build Tcl modules (PL/Tcl)
646#
647AC_MSG_CHECKING([whether to build with Tcl])
648PGAC_ARG_BOOL(with, tcl, no, [build Tcl modules (PL/Tcl)])
649AC_MSG_RESULT([$with_tcl])
650AC_SUBST([with_tcl])
651
652# We see if the path to the Tcl/Tk configuration scripts is specified.
653# This will override the use of tclsh to find the paths to search.
654
655PGAC_ARG_REQ(with, tclconfig, [DIR], [tclConfig.sh is in DIR])
656
657#
658# Optionally build Perl modules (PL/Perl)
659#
660AC_MSG_CHECKING([whether to build Perl modules])
661PGAC_ARG_BOOL(with, perl, no, [build Perl modules (PL/Perl)])
662AC_MSG_RESULT([$with_perl])
663AC_SUBST(with_perl)
664
665#
666# Optionally build Python modules (PL/Python)
667#
668AC_MSG_CHECKING([whether to build Python modules])
669PGAC_ARG_BOOL(with, python, no, [build Python modules (PL/Python)])
670AC_MSG_RESULT([$with_python])
671AC_SUBST(with_python)
672
673#
674# GSSAPI
675#
676AC_MSG_CHECKING([whether to build with GSSAPI support])
677PGAC_ARG_BOOL(with, gssapi, no, [build with GSSAPI support],
678[
679  AC_DEFINE(ENABLE_GSS, 1, [Define to build with GSSAPI support. (--with-gssapi)])
680  krb_srvtab="FILE:\$(sysconfdir)/krb5.keytab"
681])
682AC_MSG_RESULT([$with_gssapi])
683
684
685AC_SUBST(krb_srvtab)
686
687
688#
689# Kerberos configuration parameters
690#
691PGAC_ARG_REQ(with, krb-srvnam,
692             [NAME], [default service principal name in Kerberos (GSSAPI) [postgres]],
693             [],
694             [with_krb_srvnam="postgres"])
695AC_DEFINE_UNQUOTED([PG_KRB_SRVNAM], ["$with_krb_srvnam"],
696                   [Define to the name of the default PostgreSQL service principal in Kerberos (GSSAPI). (--with-krb-srvnam=NAME)])
697
698
699#
700# PAM
701#
702AC_MSG_CHECKING([whether to build with PAM support])
703PGAC_ARG_BOOL(with, pam, no,
704              [build with PAM support],
705              [AC_DEFINE([USE_PAM], 1, [Define to 1 to build with PAM support. (--with-pam)])])
706AC_MSG_RESULT([$with_pam])
707
708
709#
710# BSD AUTH
711#
712AC_MSG_CHECKING([whether to build with BSD Authentication support])
713PGAC_ARG_BOOL(with, bsd-auth, no,
714              [build with BSD Authentication support],
715              [AC_DEFINE([USE_BSD_AUTH], 1, [Define to 1 to build with BSD Authentication support. (--with-bsd-auth)])])
716AC_MSG_RESULT([$with_bsd_auth])
717
718
719#
720# LDAP
721#
722AC_MSG_CHECKING([whether to build with LDAP support])
723PGAC_ARG_BOOL(with, ldap, no,
724              [build with LDAP support],
725              [AC_DEFINE([USE_LDAP], 1, [Define to 1 to build with LDAP support. (--with-ldap)])])
726AC_MSG_RESULT([$with_ldap])
727
728
729#
730# Bonjour
731#
732AC_MSG_CHECKING([whether to build with Bonjour support])
733PGAC_ARG_BOOL(with, bonjour, no,
734              [build with Bonjour support],
735              [AC_DEFINE([USE_BONJOUR], 1, [Define to 1 to build with Bonjour support. (--with-bonjour)])])
736AC_MSG_RESULT([$with_bonjour])
737
738
739#
740# OpenSSL
741#
742AC_MSG_CHECKING([whether to build with OpenSSL support])
743PGAC_ARG_BOOL(with, openssl, no, [build with OpenSSL support],
744              [AC_DEFINE([USE_OPENSSL], 1, [Define to build with OpenSSL support. (--with-openssl)])])
745AC_MSG_RESULT([$with_openssl])
746AC_SUBST(with_openssl)
747
748#
749# SELinux
750#
751AC_MSG_CHECKING([whether to build with SELinux support])
752PGAC_ARG_BOOL(with, selinux, no, [build with SELinux support])
753AC_SUBST(with_selinux)
754AC_MSG_RESULT([$with_selinux])
755
756#
757# Systemd
758#
759AC_MSG_CHECKING([whether to build with systemd support])
760PGAC_ARG_BOOL(with, systemd, no, [build with systemd support],
761              [AC_DEFINE([USE_SYSTEMD], 1, [Define to build with systemd support. (--with-systemd)])])
762AC_SUBST(with_systemd)
763AC_MSG_RESULT([$with_systemd])
764
765#
766# Readline
767#
768PGAC_ARG_BOOL(with, readline, yes,
769              [do not use GNU Readline nor BSD Libedit for editing])
770# readline on MinGW has problems with backslashes in psql and other bugs.
771# This is particularly a problem with non-US code pages.
772# Therefore disable its use until we understand the cause. 2004-07-20
773if test "$PORTNAME" = "win32"; then
774  if test "$with_readline" = yes; then
775    AC_MSG_WARN([*** Readline does not work on MinGW --- disabling])
776    with_readline=no
777  fi
778fi
779
780
781#
782# Prefer libedit
783#
784PGAC_ARG_BOOL(with, libedit-preferred, no,
785              [prefer BSD Libedit over GNU Readline])
786
787
788#
789# UUID library
790#
791# There are at least three UUID libraries in common use: the FreeBSD/NetBSD
792# library, the e2fsprogs libuuid (now part of util-linux-ng), and the OSSP
793# UUID library.  More than one of these might be present on a given platform,
794# so we make the user say which one she wants.
795#
796PGAC_ARG_REQ(with, uuid, [LIB], [build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)])
797if test x"$with_uuid" = x"" ; then
798  with_uuid=no
799fi
800PGAC_ARG_BOOL(with, ossp-uuid, no, [obsolete spelling of --with-uuid=ossp])
801if test "$with_ossp_uuid" = yes ; then
802  with_uuid=ossp
803fi
804
805if test "$with_uuid" = bsd ; then
806  AC_DEFINE([HAVE_UUID_BSD], 1, [Define to 1 if you have BSD UUID support.])
807  UUID_EXTRA_OBJS="md5.o sha1.o"
808elif test "$with_uuid" = e2fs ; then
809  AC_DEFINE([HAVE_UUID_E2FS], 1, [Define to 1 if you have E2FS UUID support.])
810  UUID_EXTRA_OBJS="md5.o sha1.o"
811elif test "$with_uuid" = ossp ; then
812  AC_DEFINE([HAVE_UUID_OSSP], 1, [Define to 1 if you have OSSP UUID support.])
813  UUID_EXTRA_OBJS=""
814elif test "$with_uuid" = no ; then
815  UUID_EXTRA_OBJS=""
816else
817  AC_MSG_ERROR([--with-uuid must specify one of bsd, e2fs, or ossp])
818fi
819AC_SUBST(with_uuid)
820AC_SUBST(UUID_EXTRA_OBJS)
821
822
823#
824# XML
825#
826PGAC_ARG_BOOL(with, libxml, no, [build with XML support],
827              [AC_DEFINE([USE_LIBXML], 1, [Define to 1 to build with XML support. (--with-libxml)])])
828
829if test "$with_libxml" = yes ; then
830  AC_CHECK_PROGS(XML2_CONFIG, xml2-config)
831  if test -n "$XML2_CONFIG"; then
832    for pgac_option in `$XML2_CONFIG --cflags`; do
833      case $pgac_option in
834        -I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
835      esac
836    done
837    for pgac_option in `$XML2_CONFIG --libs`; do
838      case $pgac_option in
839        -L*) LDFLAGS="$LDFLAGS $pgac_option";;
840      esac
841    done
842  fi
843fi
844
845AC_SUBST(with_libxml)
846
847#
848# XSLT
849#
850PGAC_ARG_BOOL(with, libxslt, no, [use XSLT support when building contrib/xml2],
851              [AC_DEFINE([USE_LIBXSLT], 1, [Define to 1 to use XSLT support when building contrib/xml2. (--with-libxslt)])])
852
853
854AC_SUBST(with_libxslt)
855
856#
857# tzdata
858#
859PGAC_ARG_REQ(with, system-tzdata,
860             [DIR], [use system time zone data in DIR])
861AC_SUBST(with_system_tzdata)
862
863#
864# Zlib
865#
866PGAC_ARG_BOOL(with, zlib, yes,
867              [do not use Zlib])
868AC_SUBST(with_zlib)
869
870#
871# Elf
872#
873
874# Assume system is ELF if it predefines __ELF__ as 1,
875# otherwise believe host_os based default.
876case $host_os in
877    freebsd1*|freebsd2*) elf=no;;
878    freebsd3*|freebsd4*) elf=yes;;
879esac
880
881AC_EGREP_CPP(yes,
882[#if __ELF__
883  yes
884#endif
885],
886[ELF_SYS=true],
887[if test "X$elf" = "Xyes" ; then
888  ELF_SYS=true
889else
890  ELF_SYS=
891fi])
892AC_SUBST(ELF_SYS)
893
894#
895# Assignments
896#
897
898CPPFLAGS="$CPPFLAGS $INCLUDES"
899LDFLAGS="$LDFLAGS $LIBDIRS"
900
901AC_ARG_VAR(LDFLAGS_EX, [extra linker flags for linking executables only])
902AC_ARG_VAR(LDFLAGS_SL, [extra linker flags for linking shared libraries only])
903
904PGAC_PROG_LD
905AC_SUBST(LD)
906AC_SUBST(with_gnu_ld)
907case $host_os in sysv5*)
908  AC_CACHE_CHECK([whether ld -R works], [pgac_cv_prog_ld_R],
909  [
910    pgac_save_LDFLAGS=$LDFLAGS; LDFLAGS="$LDFLAGS -Wl,-R/usr/lib"
911    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
912      [pgac_cv_prog_ld_R=yes],
913      [pgac_cv_prog_ld_R=no])
914    LDFLAGS=$pgac_save_LDFLAGS
915  ])
916  ld_R_works=$pgac_cv_prog_ld_R
917  AC_SUBST(ld_R_works)
918esac
919AC_PROG_RANLIB
920PGAC_CHECK_STRIP
921AC_CHECK_TOOL(AR, ar, ar)
922if test "$PORTNAME" = "win32"; then
923  AC_CHECK_TOOL(DLLTOOL, dlltool, dlltool)
924  AC_CHECK_TOOL(DLLWRAP, dllwrap, dllwrap)
925  AC_CHECK_TOOL(WINDRES, windres, windres)
926fi
927
928AC_PROG_INSTALL
929# When Autoconf chooses install-sh as install program it tries to generate
930# a relative path to it in each makefile where it substitutes it. This clashes
931# with our Makefile.global concept. This workaround helps.
932case $INSTALL in
933  *install-sh*) install_bin='';;
934  *) install_bin=$INSTALL;;
935esac
936AC_SUBST(install_bin)
937
938AC_PATH_PROG(TAR, tar)
939AC_PROG_LN_S
940AC_PROG_AWK
941AC_PROG_MKDIR_P
942# When Autoconf chooses install-sh as mkdir -p program it tries to generate
943# a relative path to it in each makefile where it substitutes it. This clashes
944# with our Makefile.global concept. This workaround helps.
945case $MKDIR_P in
946  *install-sh*) MKDIR_P='\${SHELL} \${top_srcdir}/config/install-sh -c -d';;
947esac
948
949PGAC_PATH_BISON
950PGAC_PATH_FLEX
951
952PGAC_PATH_PERL
953if test "$with_perl" = yes; then
954  if test -z "$PERL"; then
955    AC_MSG_ERROR([Perl not found])
956  fi
957  PGAC_CHECK_PERL_CONFIGS([archlibexp,privlibexp,useshrplib])
958  if test "$perl_useshrplib" != yes && test "$perl_useshrplib" != true; then
959    AC_MSG_ERROR([cannot build PL/Perl because libperl is not a shared library
960You might have to rebuild your Perl installation.  Refer to the
961documentation for details.  Use --without-perl to disable building
962PL/Perl.])
963  fi
964  # On most platforms, archlibexp is also where the Perl include files live ...
965  perl_includespec="-I$perl_archlibexp/CORE"
966  # ... but on newer macOS versions, we must use -iwithsysroot to look
967  # under $PG_SYSROOT
968  if test \! -f "$perl_archlibexp/CORE/perl.h" ; then
969    if test -f "$PG_SYSROOT$perl_archlibexp/CORE/perl.h" ; then
970      perl_includespec="-iwithsysroot $perl_archlibexp/CORE"
971    fi
972  fi
973  AC_SUBST(perl_includespec)dnl
974  PGAC_CHECK_PERL_EMBED_CCFLAGS
975  PGAC_CHECK_PERL_EMBED_LDFLAGS
976fi
977
978if test "$with_python" = yes; then
979  PGAC_PATH_PYTHON
980  PGAC_CHECK_PYTHON_EMBED_SETUP
981
982  # We need libpython as a shared library.  With Python >=2.5, we
983  # check the Py_ENABLE_SHARED setting.  On Debian, the setting is not
984  # correct before the jessie release (http://bugs.debian.org/695979).
985  # We also want to support older Python versions.  So as a fallback
986  # we see if there is a file that is named like a shared library.
987
988  if test "$python_enable_shared" != 1; then
989    if test "$PORTNAME" = darwin; then
990      # OS X does supply a .dylib even though Py_ENABLE_SHARED does
991      # not get set.  The file detection logic below doesn't succeed
992      # on older OS X versions, so make it explicit.
993      python_enable_shared=1
994    elif test "$PORTNAME" = win32; then
995      # Windows also needs an explicit override.
996      python_enable_shared=1
997    else
998      # We don't know the platform shared library extension here yet,
999      # so we try some candidates.
1000      for dlsuffix in .so .sl; do
1001        if ls "$python_libdir"/libpython*${dlsuffix}* >/dev/null 2>&1; then
1002          python_enable_shared=1
1003          break
1004        fi
1005      done
1006    fi
1007  fi
1008
1009  if test "$python_enable_shared" != 1; then
1010    AC_MSG_ERROR([cannot build PL/Python because libpython is not a shared library
1011You might have to rebuild your Python installation.  Refer to the
1012documentation for details.  Use --without-python to disable building
1013PL/Python.])
1014  fi
1015fi
1016
1017if test "$cross_compiling" = yes && test -z "$with_system_tzdata"; then
1018  AC_PATH_PROG(ZIC, zic)
1019  if test -z "$ZIC"; then
1020    AC_MSG_ERROR([
1021When cross-compiling, either use the option --with-system-tzdata to use
1022existing time-zone data, or set the environment variable ZIC to a zic
1023program to use during the build.])
1024  fi
1025fi
1026
1027#
1028# Pthreads
1029#
1030# For each platform, we need to know about any special compile and link
1031# libraries, and whether the normal C function names are thread-safe.
1032# See the comment at the top of src/port/thread.c for more information.
1033# WIN32 doesn't need the pthread tests;  it always uses threads
1034#
1035# These tests are run before the library-tests, because linking with the
1036# other libraries can pull in the pthread functions as a side-effect.  We
1037# want to use the -pthread or similar flags directly, and not rely on
1038# the side-effects of linking with some other library.
1039#
1040# note: We have to use AS_IF here rather than plain if. The AC_CHECK_HEADER
1041# invocation below is the first one in the script, and autoconf generates
1042# additional code for that, which must not be inside the if-block. AS_IF
1043# knows how to do that.
1044AS_IF([test "$enable_thread_safety" = yes -a "$PORTNAME" != "win32"],
1045[ # then
1046AX_PTHREAD	# set thread flags
1047
1048# Some platforms use these, so just define them.  They can't hurt if they
1049# are not supported.  For example, on Solaris -D_POSIX_PTHREAD_SEMANTICS
1050# enables 5-arg getpwuid_r, among other things.
1051PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
1052
1053# Check for *_r functions
1054_CFLAGS="$CFLAGS"
1055_LIBS="$LIBS"
1056CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1057LIBS="$LIBS $PTHREAD_LIBS"
1058
1059AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([
1060pthread.h not found;  use --disable-thread-safety to disable thread safety])])
1061
1062AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
1063
1064# Do test here with the proper thread flags
1065PGAC_FUNC_STRERROR_R_INT
1066
1067CFLAGS="$_CFLAGS"
1068LIBS="$_LIBS"
1069
1070], [ # else
1071# do not use values from template file
1072PTHREAD_CFLAGS=
1073PTHREAD_LIBS=
1074]) # fi
1075
1076AC_SUBST(PTHREAD_CFLAGS)
1077AC_SUBST(PTHREAD_LIBS)
1078
1079
1080##
1081## Libraries
1082##
1083## Most libraries are included only if they demonstrably provide a function
1084## we need, but libm is an exception: always include it, because there are
1085## too many compilers that play cute optimization games that will break
1086## probes for standard functions such as pow().
1087##
1088
1089AC_CHECK_LIB(m, main)
1090AC_SEARCH_LIBS(setproctitle, util)
1091AC_SEARCH_LIBS(dlopen, dl)
1092AC_SEARCH_LIBS(socket, [socket ws2_32])
1093AC_SEARCH_LIBS(shl_load, dld)
1094# We only use libld in port/dynloader/aix.c
1095case $host_os in
1096     aix*)
1097	AC_SEARCH_LIBS(ldopen, ld)
1098	;;
1099esac
1100AC_SEARCH_LIBS(getopt_long, [getopt gnugetopt])
1101AC_SEARCH_LIBS(crypt, crypt)
1102AC_SEARCH_LIBS(shm_open, rt)
1103AC_SEARCH_LIBS(shm_unlink, rt)
1104# Solaris:
1105AC_SEARCH_LIBS(fdatasync, [rt posix4])
1106# Required for thread_test.c on Solaris
1107AC_SEARCH_LIBS(sched_yield, rt)
1108# Required for thread_test.c on Solaris 2.5:
1109# Other ports use it too (HP-UX) so test unconditionally
1110AC_SEARCH_LIBS(gethostbyname_r, nsl)
1111# Cygwin:
1112AC_SEARCH_LIBS(shmget, cygipc)
1113
1114if test "$with_readline" = yes; then
1115  PGAC_CHECK_READLINE
1116  if test x"$pgac_cv_check_readline" = x"no"; then
1117    AC_MSG_ERROR([readline library not found
1118If you have readline already installed, see config.log for details on the
1119failure.  It is possible the compiler isn't looking in the proper directory.
1120Use --without-readline to disable readline support.])
1121  fi
1122fi
1123
1124if test "$with_zlib" = yes; then
1125  AC_CHECK_LIB(z, inflate, [],
1126               [AC_MSG_ERROR([zlib library not found
1127If you have zlib already installed, see config.log for details on the
1128failure.  It is possible the compiler isn't looking in the proper directory.
1129Use --without-zlib to disable zlib support.])])
1130fi
1131
1132if test "$enable_spinlocks" = yes; then
1133  AC_DEFINE(HAVE_SPINLOCKS, 1, [Define to 1 if you have spinlocks.])
1134else
1135  AC_MSG_WARN([
1136*** Not using spinlocks will cause poor performance.])
1137fi
1138
1139if test "$enable_atomics" = yes; then
1140  AC_DEFINE(HAVE_ATOMICS, 1, [Define to 1 if you want to use atomics if available.])
1141else
1142  AC_MSG_WARN([
1143*** Not using atomic operations will cause poor performance.])
1144fi
1145
1146if test "$with_gssapi" = yes ; then
1147  if test "$PORTNAME" != "win32"; then
1148    AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
1149                   [AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
1150  else
1151    LIBS="$LIBS -lgssapi32"
1152  fi
1153fi
1154
1155if test "$with_openssl" = yes ; then
1156  dnl Order matters!
1157  if test "$PORTNAME" != "win32"; then
1158     AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])])
1159     AC_CHECK_LIB(ssl,    SSL_new, [], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])])
1160  else
1161     AC_SEARCH_LIBS(CRYPTO_new_ex_data, [eay32 crypto], [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])])
1162     AC_SEARCH_LIBS(SSL_new, [ssleay32 ssl], [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])])
1163  fi
1164  AC_CHECK_FUNCS([SSL_get_current_compression])
1165  # Functions introduced in OpenSSL 1.1.0. We used to check for
1166  # OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
1167  # defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
1168  # doesn't have these OpenSSL 1.1.0 functions. So check for individual
1169  # functions.
1170  AC_CHECK_FUNCS([OPENSSL_init_ssl BIO_get_data BIO_meth_new ASN1_STRING_get0_data RAND_OpenSSL])
1171  # OpenSSL versions before 1.1.0 required setting callback functions, for
1172  # thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
1173  # function was removed.
1174  AC_CHECK_FUNCS([CRYPTO_lock])
1175fi
1176
1177if test "$with_pam" = yes ; then
1178  AC_CHECK_LIB(pam,    pam_start, [], [AC_MSG_ERROR([library 'pam' is required for PAM])])
1179fi
1180
1181if test "$with_libxml" = yes ; then
1182  AC_CHECK_LIB(xml2, xmlSaveToBuffer, [], [AC_MSG_ERROR([library 'xml2' (version >= 2.6.23) is required for XML support])])
1183fi
1184
1185if test "$with_libxslt" = yes ; then
1186  AC_CHECK_LIB(xslt, xsltCleanupGlobals, [], [AC_MSG_ERROR([library 'xslt' is required for XSLT support])])
1187fi
1188
1189# Note: We can test for libldap_r only after we know PTHREAD_LIBS;
1190# also, on AIX, we may need to have openssl in LIBS for this step.
1191if test "$with_ldap" = yes ; then
1192  _LIBS="$LIBS"
1193  if test "$PORTNAME" != "win32"; then
1194    AC_CHECK_LIB(ldap, ldap_bind, [],
1195		 [AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1196		 [$EXTRA_LDAP_LIBS])
1197    LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
1198    if test "$enable_thread_safety" = yes; then
1199      # Use ldap_r for FE if available, else assume ldap is thread-safe.
1200      # On some platforms ldap_r fails to link without PTHREAD_LIBS.
1201      LIBS="$_LIBS"
1202      AC_CHECK_LIB(ldap_r, ldap_bind,
1203		   [LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"],
1204		   [LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"],
1205		   [$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1206    else
1207      LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
1208    fi
1209  else
1210    AC_CHECK_LIB(wldap32, ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
1211    LDAP_LIBS_FE="-lwldap32"
1212    LDAP_LIBS_BE="-lwldap32"
1213  fi
1214  LIBS="$_LIBS"
1215fi
1216AC_SUBST(LDAP_LIBS_FE)
1217AC_SUBST(LDAP_LIBS_BE)
1218
1219# for contrib/sepgsql
1220if test "$with_selinux" = yes; then
1221  AC_CHECK_LIB(selinux, security_compute_create_name, [],
1222               [AC_MSG_ERROR([library 'libselinux', version 2.1.10 or newer, is required for SELinux support])])
1223fi
1224
1225# for contrib/uuid-ossp
1226if test "$with_uuid" = bsd ; then
1227  # On BSD, the UUID functions are in libc
1228  AC_CHECK_FUNC(uuid_to_string,
1229    [UUID_LIBS=""],
1230    [AC_MSG_ERROR([BSD UUID functions are not present])])
1231elif test "$with_uuid" = e2fs ; then
1232  # On OS X, the UUID functions are in libc
1233  AC_CHECK_FUNC(uuid_generate,
1234    [UUID_LIBS=""],
1235    [AC_CHECK_LIB(uuid, uuid_generate,
1236      [UUID_LIBS="-luuid"],
1237      [AC_MSG_ERROR([library 'uuid' is required for E2FS UUID])])])
1238elif test "$with_uuid" = ossp ; then
1239  AC_CHECK_LIB(ossp-uuid, uuid_export,
1240    [UUID_LIBS="-lossp-uuid"],
1241    [AC_CHECK_LIB(uuid, uuid_export,
1242      [UUID_LIBS="-luuid"],
1243      [AC_MSG_ERROR([library 'ossp-uuid' or 'uuid' is required for OSSP UUID])])])
1244fi
1245AC_SUBST(UUID_LIBS)
1246
1247
1248##
1249## Header files
1250##
1251
1252dnl sys/socket.h is required by AC_FUNC_ACCEPT_ARGTYPES
1253AC_CHECK_HEADERS([atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h pwd.h sys/epoll.h sys/ioctl.h sys/ipc.h sys/poll.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/socket.h sys/sockio.h sys/tas.h sys/time.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h])
1254
1255# On BSD, test for net/if.h will fail unless sys/socket.h
1256# is included first.
1257AC_CHECK_HEADERS(net/if.h, [], [],
1258[AC_INCLUDES_DEFAULT
1259#ifdef HAVE_SYS_SOCKET_H
1260#include <sys/socket.h>
1261#endif
1262])
1263
1264# On OpenBSD, test for sys/ucred.h will fail unless sys/param.h
1265# is included first.
1266AC_CHECK_HEADERS(sys/ucred.h, [], [],
1267[AC_INCLUDES_DEFAULT
1268#include <sys/param.h>
1269])
1270
1271# At least on IRIX, test for netinet/tcp.h will fail unless
1272# netinet/in.h is included first.
1273AC_CHECK_HEADERS(netinet/in.h)
1274AC_CHECK_HEADERS(netinet/tcp.h, [], [],
1275[AC_INCLUDES_DEFAULT
1276#ifdef HAVE_NETINET_IN_H
1277#include <netinet/in.h>
1278#endif
1279])
1280
1281if expr x"$pgac_cv_check_readline" : 'x-lreadline' >/dev/null ; then
1282  AC_CHECK_HEADERS(readline/readline.h, [],
1283        [AC_CHECK_HEADERS(readline.h, [],
1284                [AC_MSG_ERROR([readline header not found
1285If you have readline already installed, see config.log for details on the
1286failure.  It is possible the compiler isn't looking in the proper directory.
1287Use --without-readline to disable readline support.])])])
1288  AC_CHECK_HEADERS(readline/history.h, [],
1289        [AC_CHECK_HEADERS(history.h, [],
1290                [AC_MSG_ERROR([history header not found
1291If you have readline already installed, see config.log for details on the
1292failure.  It is possible the compiler isn't looking in the proper directory.
1293Use --without-readline to disable readline support.])])])
1294fi
1295
1296if expr x"$pgac_cv_check_readline" : 'x-ledit' >/dev/null ; then
1297# Some installations of libedit usurp /usr/include/readline/, which seems
1298# bad practice, since in combined installations readline will have its headers
1299# there.  We might have to resort to AC_EGREP checks to make sure we found
1300# the proper header...
1301  AC_CHECK_HEADERS(editline/readline.h, [],
1302        [AC_CHECK_HEADERS(readline.h, [],
1303                [AC_CHECK_HEADERS(readline/readline.h, [],
1304                        [AC_MSG_ERROR([readline header not found
1305If you have libedit already installed, see config.log for details on the
1306failure.  It is possible the compiler isn't looking in the proper directory.
1307Use --without-readline to disable libedit support.])])])])
1308# Note: in a libedit installation, history.h is sometimes a dummy, and may
1309# not be there at all.  Hence, don't complain if not found.  We must check
1310# though, since in yet other versions it is an independent header.
1311  AC_CHECK_HEADERS(editline/history.h, [],
1312        [AC_CHECK_HEADERS(history.h, [],
1313                [AC_CHECK_HEADERS(readline/history.h)])])
1314fi
1315
1316if test "$with_zlib" = yes; then
1317  AC_CHECK_HEADER(zlib.h, [], [AC_MSG_ERROR([zlib header not found
1318If you have zlib already installed, see config.log for details on the
1319failure.  It is possible the compiler isn't looking in the proper directory.
1320Use --without-zlib to disable zlib support.])])
1321fi
1322
1323if test "$with_gssapi" = yes ; then
1324  AC_CHECK_HEADERS(gssapi/gssapi.h, [],
1325	[AC_CHECK_HEADERS(gssapi.h, [], [AC_MSG_ERROR([gssapi.h header file is required for GSSAPI])])])
1326fi
1327
1328if test "$with_openssl" = yes ; then
1329  AC_CHECK_HEADER(openssl/ssl.h, [], [AC_MSG_ERROR([header file <openssl/ssl.h> is required for OpenSSL])])
1330  AC_CHECK_HEADER(openssl/err.h, [], [AC_MSG_ERROR([header file <openssl/err.h> is required for OpenSSL])])
1331fi
1332
1333if test "$with_pam" = yes ; then
1334  AC_CHECK_HEADERS(security/pam_appl.h, [],
1335                   [AC_CHECK_HEADERS(pam/pam_appl.h, [],
1336                                     [AC_MSG_ERROR([header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.])])])
1337fi
1338
1339if test "$with_bsd_auth" = yes ; then
1340  AC_CHECK_HEADER(bsd_auth.h, [], [AC_MSG_ERROR([header file <bsd_auth.h> is required for BSD Authentication support])])
1341fi
1342
1343if test "$with_systemd" = yes ; then
1344  AC_CHECK_HEADER(systemd/sd-daemon.h, [], [AC_MSG_ERROR([header file <systemd/sd-daemon.h> is required for systemd support])])
1345fi
1346
1347if test "$with_libxml" = yes ; then
1348  AC_CHECK_HEADER(libxml/parser.h, [], [AC_MSG_ERROR([header file <libxml/parser.h> is required for XML support])])
1349fi
1350
1351if test "$with_libxslt" = yes ; then
1352  AC_CHECK_HEADER(libxslt/xslt.h, [], [AC_MSG_ERROR([header file <libxslt/xslt.h> is required for XSLT support])])
1353fi
1354
1355if test "$with_ldap" = yes ; then
1356  if test "$PORTNAME" != "win32"; then
1357     AC_CHECK_HEADERS(ldap.h, [],
1358                      [AC_MSG_ERROR([header file <ldap.h> is required for LDAP])])
1359     PGAC_LDAP_SAFE
1360  else
1361     AC_CHECK_HEADERS(winldap.h, [],
1362                      [AC_MSG_ERROR([header file <winldap.h> is required for LDAP])],
1363                      [AC_INCLUDES_DEFAULT
1364#include <windows.h>
1365                      ])
1366  fi
1367fi
1368
1369if test "$with_bonjour" = yes ; then
1370  AC_CHECK_HEADER(dns_sd.h, [], [AC_MSG_ERROR([header file <dns_sd.h> is required for Bonjour])])
1371dnl At some point we might add something like
1372dnl AC_SEARCH_LIBS(DNSServiceRegister, dns_sd)
1373dnl but right now, what that would mainly accomplish is to encourage
1374dnl people to try to use the avahi implementation, which does not work.
1375dnl If you want to use Apple's own Bonjour code on another platform,
1376dnl just add -ldns_sd to LIBS manually.
1377fi
1378
1379# for contrib/uuid-ossp
1380if test "$with_uuid" = bsd ; then
1381  AC_CHECK_HEADERS(uuid.h,
1382    [AC_EGREP_HEADER([uuid_to_string], uuid.h, [],
1383      [AC_MSG_ERROR([header file <uuid.h> does not match BSD UUID library])])],
1384    [AC_MSG_ERROR([header file <uuid.h> is required for BSD UUID])])
1385elif test "$with_uuid" = e2fs ; then
1386  AC_CHECK_HEADERS(uuid/uuid.h,
1387    [AC_EGREP_HEADER([uuid_generate], uuid/uuid.h, [],
1388      [AC_MSG_ERROR([header file <uuid/uuid.h> does not match E2FS UUID library])])],
1389    [AC_CHECK_HEADERS(uuid.h,
1390      [AC_EGREP_HEADER([uuid_generate], uuid.h, [],
1391        [AC_MSG_ERROR([header file <uuid.h> does not match E2FS UUID library])])],
1392      [AC_MSG_ERROR([header file <uuid/uuid.h> or <uuid.h> is required for E2FS UUID])])])
1393elif test "$with_uuid" = ossp ; then
1394  AC_CHECK_HEADERS(ossp/uuid.h,
1395    [AC_EGREP_HEADER([uuid_export], ossp/uuid.h, [],
1396      [AC_MSG_ERROR([header file <ossp/uuid.h> does not match OSSP UUID library])])],
1397    [AC_CHECK_HEADERS(uuid.h,
1398      [AC_EGREP_HEADER([uuid_export], uuid.h, [],
1399        [AC_MSG_ERROR([header file <uuid.h> does not match OSSP UUID library])])],
1400      [AC_MSG_ERROR([header file <ossp/uuid.h> or <uuid.h> is required for OSSP UUID])])])
1401fi
1402
1403if test "$PORTNAME" = "win32" ; then
1404   AC_CHECK_HEADERS(crtdefs.h)
1405fi
1406
1407##
1408## Types, structures, compiler characteristics
1409##
1410
1411m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
1412AC_C_BIGENDIAN
1413AC_C_INLINE
1414PGAC_PRINTF_ARCHETYPE
1415AC_C_FLEXIBLE_ARRAY_MEMBER
1416PGAC_C_SIGNED
1417PGAC_C_FUNCNAME_SUPPORT
1418PGAC_C_STATIC_ASSERT
1419PGAC_C_TYPES_COMPATIBLE
1420PGAC_C_BUILTIN_BSWAP32
1421PGAC_C_BUILTIN_BSWAP64
1422PGAC_C_BUILTIN_CONSTANT_P
1423PGAC_C_BUILTIN_UNREACHABLE
1424PGAC_C_VA_ARGS
1425PGAC_STRUCT_TIMEZONE
1426PGAC_UNION_SEMUN
1427PGAC_STRUCT_SOCKADDR_UN
1428PGAC_STRUCT_SOCKADDR_STORAGE
1429PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
1430PGAC_STRUCT_ADDRINFO
1431AC_TYPE_INTPTR_T
1432AC_TYPE_UINTPTR_T
1433AC_TYPE_LONG_LONG_INT
1434
1435PGAC_TYPE_LOCALE_T
1436
1437AC_CHECK_TYPES([struct cmsgcred], [], [],
1438[#include <sys/socket.h>
1439#include <sys/param.h>
1440#ifdef HAVE_SYS_UCRED_H
1441#include <sys/ucred.h>
1442#endif])
1443
1444AC_CHECK_TYPES([struct option], [], [],
1445[#ifdef HAVE_GETOPT_H
1446#include <getopt.h>
1447#endif])
1448
1449if test "$with_zlib" = yes; then
1450  # Check that <zlib.h> defines z_streamp (versions before about 1.0.4
1451  # did not).  While we could work around the lack of z_streamp, it
1452  # seems unwise to encourage people to use such old zlib versions...
1453  AC_CHECK_TYPE(z_streamp, [], [AC_MSG_ERROR([zlib version is too old
1454Use --without-zlib to disable zlib support.])],
1455                [#include <zlib.h>])
1456fi
1457
1458# On PPC, check if assembler supports LWARX instruction's mutex hint bit
1459case $host_cpu in
1460  ppc*|powerpc*)
1461    AC_MSG_CHECKING([whether assembler supports lwarx hint bit])
1462    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1463	[int a = 0; int *p = &a; int r;
1464	 __asm__ __volatile__ (" lwarx %0,0,%1,1\n" : "=&r"(r) : "r"(p));])],
1465	[pgac_cv_have_ppc_mutex_hint=yes],
1466	[pgac_cv_have_ppc_mutex_hint=no])
1467    AC_MSG_RESULT([$pgac_cv_have_ppc_mutex_hint])
1468    if test x"$pgac_cv_have_ppc_mutex_hint" = xyes ; then
1469	AC_DEFINE(HAVE_PPC_LWARX_MUTEX_HINT, 1, [Define to 1 if the assembler supports PPC's LWARX mutex hint bit.])
1470    fi
1471  ;;
1472esac
1473
1474# Check largefile support.  You might think this is a system service not a
1475# compiler characteristic, but you'd be wrong.  We must check this before
1476# probing existence of related functions such as fseeko, since the largefile
1477# defines can affect what is generated for that.
1478if test "$PORTNAME" != "win32"; then
1479   AC_SYS_LARGEFILE
1480   dnl Autoconf 2.69's AC_SYS_LARGEFILE believes it's a good idea to #define
1481   dnl _DARWIN_USE_64_BIT_INODE, but it isn't: on OS X 10.5 that activates a
1482   dnl bug that causes readdir() to sometimes return EINVAL.  On later OS X
1483   dnl versions where the feature actually works, it's on by default anyway.
1484   AH_VERBATIM([_DARWIN_USE_64_BIT_INODE],[])
1485fi
1486
1487# Check for largefile support (must be after AC_SYS_LARGEFILE)
1488AC_CHECK_SIZEOF([off_t])
1489
1490# If we don't have largefile support, can't handle segsize >= 2GB.
1491if test "$ac_cv_sizeof_off_t" -lt 8 -a "$segsize" != "1"; then
1492   AC_MSG_ERROR([Large file support is not enabled. Segment size cannot be larger than 1GB.])
1493fi
1494
1495
1496##
1497## Functions, global variables
1498##
1499
1500PGAC_VAR_INT_TIMEZONE
1501AC_FUNC_ACCEPT_ARGTYPES
1502PGAC_FUNC_GETTIMEOFDAY_1ARG
1503PGAC_FUNC_WCSTOMBS_L
1504
1505# Some versions of libedit contain strlcpy(), setproctitle(), and other
1506# symbols that that library has no business exposing to the world.  Pending
1507# acquisition of a clue by those developers, ignore libedit (including its
1508# possible alias of libreadline) while checking for everything else.
1509LIBS_including_readline="$LIBS"
1510LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1511
1512AC_CHECK_FUNCS(m4_normalize([
1513	cbrt
1514	dlopen
1515	fdatasync
1516	getifaddrs
1517	getpeerucred
1518	getrlimit
1519	mbstowcs_l
1520	memmove
1521	poll
1522	posix_fallocate
1523	pstat
1524	pthread_is_threaded_np
1525	readlink
1526	setproctitle
1527	setsid
1528	shm_open
1529	strsignal
1530	symlink
1531	sync_file_range
1532	towlower
1533	uselocale
1534	utime
1535	utimes
1536	wcstombs
1537	wcstombs_l
1538]))
1539
1540AC_REPLACE_FUNCS(fseeko)
1541case $host_os in
1542	# NetBSD uses a custom fseeko/ftello built on fsetpos/fgetpos
1543	# Mingw uses macros to access Win32 API calls
1544	netbsd*|mingw*)
1545		AC_DEFINE(HAVE_FSEEKO, 1, [Define to 1 because replacement version used.])
1546		ac_cv_func_fseeko=yes;;
1547	*)
1548		AC_FUNC_FSEEKO;;
1549esac
1550
1551# posix_fadvise() is a no-op on Solaris, so don't incur function overhead
1552# by calling it, 2009-04-02
1553# http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
1554dnl must use AS_IF here, else AC_REQUIRES inside AC_CHECK_DECLS malfunctions
1555AS_IF([test "$PORTNAME" != "solaris"], [
1556AC_CHECK_FUNCS(posix_fadvise)
1557AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
1558]) # fi
1559
1560AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
1561AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
1562# This is probably only present on Darwin, but may as well check always
1563AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
1564
1565HAVE_IPV6=no
1566AC_CHECK_TYPE([struct sockaddr_in6],
1567        [AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if you have support for IPv6.])
1568         HAVE_IPV6=yes],
1569        [],
1570[$ac_includes_default
1571#include <netinet/in.h>])
1572AC_SUBST(HAVE_IPV6)
1573
1574AC_CACHE_CHECK([for PS_STRINGS], [pgac_cv_var_PS_STRINGS],
1575[AC_LINK_IFELSE([AC_LANG_PROGRAM(
1576[#include <machine/vmparam.h>
1577#include <sys/exec.h>
1578],
1579[PS_STRINGS->ps_nargvstr = 1;
1580PS_STRINGS->ps_argvstr = "foo";])],
1581[pgac_cv_var_PS_STRINGS=yes],
1582[pgac_cv_var_PS_STRINGS=no])])
1583if test "$pgac_cv_var_PS_STRINGS" = yes ; then
1584  AC_DEFINE([HAVE_PS_STRINGS], 1, [Define to 1 if the PS_STRINGS thing exists.])
1585fi
1586
1587
1588# We use our snprintf.c emulation if either snprintf() or vsnprintf()
1589# is missing.  Yes, there are machines that have only one.  We may
1590# also decide to use snprintf.c if snprintf() is present but does not
1591# have all the features we need --- see below.
1592
1593if test "$PORTNAME" = "win32"; then
1594  # Win32 gets snprintf.c built unconditionally.
1595  #
1596  # To properly translate all NLS languages strings, we must support the
1597  # *printf() %$ format, which allows *printf() arguments to be selected
1598  # by position in the translated string.
1599  #
1600  # libintl versions < 0.13 use the native *printf() functions, and Win32
1601  # *printf() doesn't understand %$, so we must use our /port versions,
1602  # which do understand %$. libintl versions >= 0.13 include their own
1603  # *printf versions on Win32.  The libintl 0.13 release note text is:
1604  #
1605  #   C format strings with positions, as they arise when a translator
1606  #   needs to reorder a sentence, are now supported on all platforms.
1607  #   On those few platforms (NetBSD and Woe32) for which the native
1608  #   printf()/fprintf()/... functions don't support such format
1609  #   strings, replacements are provided through <libintl.h>.
1610  #
1611  # We could use libintl >= 0.13's *printf() if we were sure that we had
1612  # a litint >= 0.13 at runtime, but seeing that there is no clean way
1613  # to guarantee that, it is best to just use our own, so we are sure to
1614  # get %$ support. In include/port.h we disable the *printf() macros
1615  # that might have been defined by libintl.
1616  #
1617  # We do this unconditionally whether NLS is used or not so we are sure
1618  # that all Win32 libraries and binaries behave the same.
1619  pgac_need_repl_snprintf=yes
1620else
1621  pgac_need_repl_snprintf=no
1622  AC_CHECK_FUNCS(snprintf, [], pgac_need_repl_snprintf=yes)
1623  AC_CHECK_FUNCS(vsnprintf, [], pgac_need_repl_snprintf=yes)
1624fi
1625
1626
1627# Check whether <stdio.h> declares snprintf() and vsnprintf(); if not,
1628# include/c.h will provide declarations.  Note this is a separate test
1629# from whether the functions exist in the C library --- there are
1630# systems that have the functions but don't bother to declare them :-(
1631
1632AC_CHECK_DECLS([snprintf, vsnprintf])
1633
1634
1635dnl Cannot use AC_CHECK_FUNC because isinf may be a macro
1636AC_CACHE_CHECK([for isinf], ac_cv_func_isinf,
1637[AC_LINK_IFELSE([AC_LANG_PROGRAM([
1638#include <math.h>
1639double glob_double;
1640],
1641[return isinf(glob_double) ? 0 : 1;])],
1642[ac_cv_func_isinf=yes],
1643[ac_cv_func_isinf=no])])
1644
1645if test $ac_cv_func_isinf = yes ; then
1646  AC_DEFINE(HAVE_ISINF, 1, [Define to 1 if you have isinf().])
1647else
1648  AC_LIBOBJ(isinf)
1649  # Look for a way to implement a substitute for isinf()
1650  AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
1651fi
1652
1653AC_REPLACE_FUNCS([crypt fls getopt getrusage inet_aton mkdtemp random rint srandom strerror strlcat strlcpy strnlen])
1654
1655case $host_os in
1656
1657        # Windows uses a specialised env handler
1658        # and doesn't need a replacement getpeereid because it doesn't use
1659        # Unix sockets.
1660        mingw*)
1661                AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
1662                AC_DEFINE(HAVE_GETPEEREID, 1, [Define to 1 because function not required.])
1663                ac_cv_func_unsetenv=yes
1664                ac_cv_func_getpeereid=yes;;
1665        *)
1666                AC_REPLACE_FUNCS([unsetenv getpeereid])
1667		;;
1668esac
1669
1670# System's version of getaddrinfo(), if any, may be used only if we found
1671# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h.
1672# We use only our own getaddrinfo.c on Windows, but it's time to revisit that.
1673if test x"$ac_cv_type_struct_addrinfo" = xyes && \
1674   test "$PORTNAME" != "win32"; then
1675  AC_REPLACE_FUNCS([getaddrinfo])
1676else
1677  AC_LIBOBJ(getaddrinfo)
1678fi
1679
1680# Similarly, use system's getopt_long() only if system provides struct option.
1681if test x"$ac_cv_type_struct_option" = xyes ; then
1682  AC_REPLACE_FUNCS([getopt_long])
1683else
1684  AC_LIBOBJ(getopt_long)
1685fi
1686
1687# On OpenBSD and Solaris, getopt() doesn't do what we want for long options
1688# (i.e., allow '-' as a flag character), so use our version on those platforms.
1689if test "$PORTNAME" = "openbsd" -o "$PORTNAME" = "solaris"; then
1690  AC_LIBOBJ(getopt)
1691fi
1692
1693# mingw has adopted a GNU-centric interpretation of optind/optreset,
1694# so always use our version on Windows.
1695if test "$PORTNAME" = "win32"; then
1696  AC_LIBOBJ(getopt)
1697  AC_LIBOBJ(getopt_long)
1698fi
1699
1700# Win32 (really MinGW) support
1701if test "$PORTNAME" = "win32"; then
1702  AC_CHECK_FUNCS(_configthreadlocale)
1703  AC_REPLACE_FUNCS(gettimeofday)
1704  AC_LIBOBJ(dirmod)
1705  AC_LIBOBJ(kill)
1706  AC_LIBOBJ(open)
1707  AC_LIBOBJ(system)
1708  AC_LIBOBJ(win32env)
1709  AC_LIBOBJ(win32error)
1710  AC_LIBOBJ(win32security)
1711  AC_LIBOBJ(win32setlocale)
1712  AC_DEFINE([HAVE_SYMLINK], 1,
1713            [Define to 1 if you have the `symlink' function.])
1714  AC_CHECK_TYPES(MINIDUMP_TYPE, [pgac_minidump_type=yes], [pgac_minidump_type=no], [
1715#define WIN32_LEAN_AND_MEAN
1716#include <windows.h>
1717#include <string.h>
1718#include <dbghelp.h>])
1719fi
1720if test x"$pgac_minidump_type" = x"yes" ; then
1721  AC_SUBST(have_win32_dbghelp,yes)
1722else
1723  AC_SUBST(have_win32_dbghelp,no)
1724fi
1725
1726# Cygwin needs only a bit of that
1727if test "$PORTNAME" = "cygwin"; then
1728  AC_LIBOBJ(dirmod)
1729fi
1730
1731AC_CHECK_FUNC(syslog,
1732              [AC_CHECK_HEADER(syslog.h,
1733                               [AC_DEFINE(HAVE_SYSLOG, 1, [Define to 1 if you have the syslog interface.])])])
1734
1735AC_CACHE_CHECK([for opterr], pgac_cv_var_int_opterr,
1736[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
1737  [extern int opterr; opterr = 1;])],
1738  [pgac_cv_var_int_opterr=yes],
1739  [pgac_cv_var_int_opterr=no])])
1740if test x"$pgac_cv_var_int_opterr" = x"yes"; then
1741  AC_DEFINE(HAVE_INT_OPTERR, 1, [Define to 1 if you have the global variable 'int opterr'.])
1742fi
1743
1744AC_CACHE_CHECK([for optreset], pgac_cv_var_int_optreset,
1745[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
1746  [extern int optreset; optreset = 1;])],
1747  [pgac_cv_var_int_optreset=yes],
1748  [pgac_cv_var_int_optreset=no])])
1749if test x"$pgac_cv_var_int_optreset" = x"yes"; then
1750  AC_DEFINE(HAVE_INT_OPTRESET, 1, [Define to 1 if you have the global variable 'int optreset'.])
1751fi
1752
1753AC_CHECK_FUNCS([strtoll __strtoll strtoq], [break])
1754AC_CHECK_FUNCS([strtoull __strtoull strtouq], [break])
1755# strto[u]ll may exist but not be declared
1756AC_CHECK_DECLS([strtoll, strtoull])
1757
1758# Lastly, restore full LIBS list and check for readline/libedit symbols
1759LIBS="$LIBS_including_readline"
1760
1761if test "$with_readline" = yes; then
1762  PGAC_VAR_RL_COMPLETION_APPEND_CHARACTER
1763  AC_CHECK_FUNCS([rl_completion_matches rl_filename_completion_function rl_reset_screen_size])
1764  AC_CHECK_FUNCS([append_history history_truncate_file])
1765fi
1766
1767
1768# This test makes sure that run tests work at all.  Sometimes a shared
1769# library is found by the linker, but the runtime linker can't find it.
1770# This check should come after all modifications of compiler or linker
1771# variables, and before any other run tests.
1772AC_MSG_CHECKING([test program])
1773AC_RUN_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])],
1774[AC_MSG_RESULT(ok)],
1775[AC_MSG_RESULT(failed)
1776AC_MSG_ERROR([[
1777Could not execute a simple test program.  This may be a problem
1778related to locating shared libraries.  Check the file 'config.log'
1779for the exact reason.]])],
1780[AC_MSG_RESULT([cross-compiling])])
1781
1782# --------------------
1783# Run tests below here
1784# --------------------
1785
1786# Force use of our snprintf if system's doesn't do arg control
1787# See comment above at snprintf test for details.
1788if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
1789  PGAC_FUNC_SNPRINTF_ARG_CONTROL
1790  if test $pgac_cv_snprintf_arg_control != yes ; then
1791    pgac_need_repl_snprintf=yes
1792  fi
1793fi
1794
1795
1796dnl Check to see if we have a working 64-bit integer type.
1797dnl This breaks down into two steps:
1798dnl (1) figure out if the compiler has a 64-bit int type with working
1799dnl arithmetic, and if so
1800dnl (2) see whether snprintf() can format the type correctly.  (Currently,
1801dnl snprintf is the only library routine we really need for int8 support.)
1802dnl It's entirely possible to have a compiler that handles a 64-bit type
1803dnl when the C library doesn't; this is fairly likely when using gcc on
1804dnl an older platform, for example.
1805dnl If there is no native snprintf() or it does not handle the 64-bit type,
1806dnl we force our own version of snprintf() to be used instead.
1807dnl Note this test must be run after our initial check for snprintf/vsnprintf.
1808
1809dnl As of Postgres 8.4, we no longer support compilers without a working
1810dnl 64-bit type.  But we still handle the case of snprintf being broken.
1811
1812PGAC_TYPE_64BIT_INT([long int])
1813
1814if test x"$HAVE_LONG_INT_64" = x"yes" ; then
1815  pg_int64_type="long int"
1816else
1817  PGAC_TYPE_64BIT_INT([long long int])
1818  if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then
1819    pg_int64_type="long long int"
1820  else
1821    AC_MSG_ERROR([Cannot find a working 64-bit integer type.])
1822  fi
1823fi
1824
1825AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
1826  [Define to the name of a signed 64-bit integer type.])
1827
1828# If we found "long int" is 64 bits, assume snprintf handles it.  If
1829# we found we need to use "long long int", better check.  We cope with
1830# snprintfs that use %lld, %qd, or %I64d as the format.  If none of these
1831# work, fall back to our own snprintf emulation (which we know uses %lld).
1832
1833if test "$HAVE_LONG_LONG_INT_64" = yes ; then
1834  if test $pgac_need_repl_snprintf = no; then
1835    PGAC_FUNC_SNPRINTF_LONG_LONG_INT_MODIFIER
1836    if test "$LONG_LONG_INT_MODIFIER" = ""; then
1837      # Force usage of our own snprintf, since system snprintf is broken
1838      pgac_need_repl_snprintf=yes
1839      LONG_LONG_INT_MODIFIER='ll'
1840    fi
1841  else
1842    # Here if we previously decided we needed to use our own snprintf
1843    LONG_LONG_INT_MODIFIER='ll'
1844  fi
1845else
1846  # Here if we are not using 'long long int' at all
1847  LONG_LONG_INT_MODIFIER='l'
1848fi
1849
1850INT64_MODIFIER="\"$LONG_LONG_INT_MODIFIER\""
1851
1852AC_DEFINE_UNQUOTED(INT64_MODIFIER, $INT64_MODIFIER,
1853                   [Define to the appropriate snprintf length modifier for 64-bit ints.])
1854
1855# Also force use of our snprintf if the system's doesn't support the %z flag.
1856if test "$pgac_need_repl_snprintf" = no; then
1857  PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
1858  if test "$pgac_cv_snprintf_size_t_support" != yes; then
1859    pgac_need_repl_snprintf=yes
1860  fi
1861fi
1862
1863# Now we have checked all the reasons to replace snprintf
1864if test $pgac_need_repl_snprintf = yes; then
1865  AC_DEFINE(USE_REPL_SNPRINTF, 1, [Use replacement snprintf() functions.])
1866  AC_LIBOBJ(snprintf)
1867fi
1868
1869# Check size of void *, size_t (enables tweaks for > 32bit address space)
1870AC_CHECK_SIZEOF([void *])
1871AC_CHECK_SIZEOF([size_t])
1872AC_CHECK_SIZEOF([long])
1873
1874# Decide whether float4 is passed by value: user-selectable, enabled by default
1875AC_MSG_CHECKING([whether to build with float4 passed by value])
1876PGAC_ARG_BOOL(enable, float4-byval, yes, [disable float4 passed by value],
1877              [AC_DEFINE([USE_FLOAT4_BYVAL], 1,
1878                         [Define to 1 if you want float4 values to be passed by value. (--enable-float4-byval)])
1879               float4passbyval=true],
1880              [float4passbyval=false])
1881AC_MSG_RESULT([$enable_float4_byval])
1882AC_DEFINE_UNQUOTED([FLOAT4PASSBYVAL], [$float4passbyval], [float4 values are passed by value if 'true', by reference if 'false'])
1883
1884# Decide whether float8 is passed by value.
1885# Note: this setting also controls int8 and related types such as timestamp.
1886# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
1887# If not, trying to select it is an error.
1888AC_MSG_CHECKING([whether to build with float8 passed by value])
1889if test $ac_cv_sizeof_void_p -ge 8 ; then
1890  PGAC_ARG_BOOL(enable, float8-byval, yes, [disable float8 passed by value])
1891else
1892  PGAC_ARG_BOOL(enable, float8-byval, no, [disable float8 passed by value])
1893  if test "$enable_float8_byval" = yes ; then
1894    AC_MSG_ERROR([--enable-float8-byval is not supported on 32-bit platforms.])
1895  fi
1896fi
1897if test "$enable_float8_byval" = yes ; then
1898  AC_DEFINE([USE_FLOAT8_BYVAL], 1,
1899            [Define to 1 if you want float8, int8, etc values to be passed by value. (--enable-float8-byval)])
1900  float8passbyval=true
1901else
1902  float8passbyval=false
1903fi
1904AC_MSG_RESULT([$enable_float8_byval])
1905AC_DEFINE_UNQUOTED([FLOAT8PASSBYVAL], [$float8passbyval], [float8, int8, and related values are passed by value if 'true', by reference if 'false'])
1906
1907# Determine memory alignment requirements for the basic C data types.
1908
1909AC_CHECK_ALIGNOF(short)
1910AC_CHECK_ALIGNOF(int)
1911AC_CHECK_ALIGNOF(long)
1912if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then
1913  AC_CHECK_ALIGNOF(long long int)
1914fi
1915AC_CHECK_ALIGNOF(double)
1916
1917# Compute maximum alignment of any basic type.
1918# We assume long's alignment is at least as strong as char, short, or int;
1919# but we must check long long (if it is being used for int64) and double.
1920# Note that we intentionally do not consider any types wider than 64 bits,
1921# as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much of a penalty
1922# for disk and memory space.
1923
1924MAX_ALIGNOF=$ac_cv_alignof_long
1925if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
1926  MAX_ALIGNOF=$ac_cv_alignof_double
1927fi
1928if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $MAX_ALIGNOF -lt $ac_cv_alignof_long_long_int ; then
1929  MAX_ALIGNOF="$ac_cv_alignof_long_long_int"
1930fi
1931AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
1932
1933
1934# Some platforms predefine the types int8, int16, etc.  Only check
1935# a (hopefully) representative subset.
1936AC_CHECK_TYPES([int8, uint8, int64, uint64], [], [],
1937[#include <stdio.h>])
1938
1939# Some compilers offer a 128-bit integer scalar type.
1940PGAC_TYPE_128BIT_INT
1941
1942# Check for various atomic operations now that we have checked how to declare
1943# 64bit integers.
1944PGAC_HAVE_GCC__SYNC_CHAR_TAS
1945PGAC_HAVE_GCC__SYNC_INT32_TAS
1946PGAC_HAVE_GCC__SYNC_INT32_CAS
1947PGAC_HAVE_GCC__SYNC_INT64_CAS
1948PGAC_HAVE_GCC__ATOMIC_INT32_CAS
1949PGAC_HAVE_GCC__ATOMIC_INT64_CAS
1950
1951
1952# Check for x86 cpuid instruction
1953AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid],
1954[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cpuid.h>],
1955  [[unsigned int exx[4] = {0, 0, 0, 0};
1956  __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
1957  ]])],
1958  [pgac_cv__get_cpuid="yes"],
1959  [pgac_cv__get_cpuid="no"])])
1960if test x"$pgac_cv__get_cpuid" = x"yes"; then
1961  AC_DEFINE(HAVE__GET_CPUID, 1, [Define to 1 if you have __get_cpuid.])
1962fi
1963
1964AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid],
1965[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>],
1966  [[unsigned int exx[4] = {0, 0, 0, 0};
1967  __get_cpuid(exx[0], 1);
1968  ]])],
1969  [pgac_cv__cpuid="yes"],
1970  [pgac_cv__cpuid="no"])])
1971if test x"$pgac_cv__cpuid" = x"yes"; then
1972  AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.])
1973fi
1974
1975# Check for Intel SSE 4.2 intrinsics to do CRC calculations.
1976#
1977# First check if the _mm_crc32_u8 and _mm_crc32_u64 intrinsics can be used
1978# with the default compiler flags. If not, check if adding the -msse4.2
1979# flag helps. CFLAGS_SSE42 is set to -msse4.2 if that's required.
1980PGAC_SSE42_CRC32_INTRINSICS([])
1981if test x"$pgac_sse42_crc32_intrinsics" != x"yes"; then
1982  PGAC_SSE42_CRC32_INTRINSICS([-msse4.2])
1983fi
1984AC_SUBST(CFLAGS_SSE42)
1985
1986# Are we targeting a processor that supports SSE 4.2? gcc, clang and icc all
1987# define __SSE4_2__ in that case.
1988AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1989#ifndef __SSE4_2__
1990#error __SSE4_2__ not defined
1991#endif
1992])], [SSE4_2_TARGETED=1])
1993
1994# Select CRC-32C implementation.
1995#
1996# If we are targeting a processor that has SSE 4.2 instructions, we can use the
1997# special CRC instructions for calculating CRC-32C. If we're not targeting such
1998# a processor, but we can nevertheless produce code that uses the SSE
1999# intrinsics, perhaps with some extra CFLAGS, compile both implementations and
2000# select which one to use at runtime, depending on whether SSE 4.2 is supported
2001# by the processor we're running on.
2002#
2003# You can override this logic by setting the appropriate USE_*_CRC32 flag to 1
2004# in the template or configure command line.
2005if test x"$USE_SSE42_CRC32C" = x"" && test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"" && test x"$USE_SLICING_BY_8_CRC32C" = x""; then
2006  if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && test x"$SSE4_2_TARGETED" = x"1" ; then
2007    USE_SSE42_CRC32C=1
2008  else
2009    # the CPUID instruction is needed for the runtime check.
2010    if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && (test x"$pgac_cv__get_cpuid" = x"yes" || test x"$pgac_cv__cpuid" = x"yes"); then
2011      USE_SSE42_CRC32C_WITH_RUNTIME_CHECK=1
2012    else
2013      # fall back to slicing-by-8 algorithm which doesn't require any special
2014      # CPU support.
2015      USE_SLICING_BY_8_CRC32C=1
2016    fi
2017  fi
2018fi
2019
2020# Set PG_CRC32C_OBJS appropriately depending on the selected implementation.
2021AC_MSG_CHECKING([which CRC-32C implementation to use])
2022if test x"$USE_SSE42_CRC32C" = x"1"; then
2023  AC_DEFINE(USE_SSE42_CRC32C, 1, [Define to 1 use Intel SSE 4.2 CRC instructions.])
2024  PG_CRC32C_OBJS="pg_crc32c_sse42.o"
2025  AC_MSG_RESULT(SSE 4.2)
2026else
2027  if test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"1"; then
2028    AC_DEFINE(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK, 1, [Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check.])
2029    PG_CRC32C_OBJS="pg_crc32c_sse42.o pg_crc32c_sb8.o pg_crc32c_choose.o"
2030    AC_MSG_RESULT(SSE 4.2 with runtime check)
2031  else
2032    AC_DEFINE(USE_SLICING_BY_8_CRC32C, 1, [Define to 1 to use software CRC-32C implementation (slicing-by-8).])
2033    PG_CRC32C_OBJS="pg_crc32c_sb8.o"
2034    AC_MSG_RESULT(slicing-by-8)
2035  fi
2036fi
2037AC_SUBST(PG_CRC32C_OBJS)
2038
2039
2040# Select semaphore implementation type.
2041if test "$PORTNAME" != "win32"; then
2042  if test x"$USE_NAMED_POSIX_SEMAPHORES" = x"1" ; then
2043    AC_DEFINE(USE_NAMED_POSIX_SEMAPHORES, 1, [Define to select named POSIX semaphores.])
2044    SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
2045  else
2046    if test x"$USE_UNNAMED_POSIX_SEMAPHORES" = x"1" ; then
2047      AC_DEFINE(USE_UNNAMED_POSIX_SEMAPHORES, 1, [Define to select unnamed POSIX semaphores.])
2048      SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
2049    else
2050      AC_DEFINE(USE_SYSV_SEMAPHORES, 1, [Define to select SysV-style semaphores.])
2051      SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c"
2052    fi
2053  fi
2054else
2055  AC_DEFINE(USE_WIN32_SEMAPHORES, 1, [Define to select Win32-style semaphores.])
2056  SEMA_IMPLEMENTATION="src/backend/port/win32_sema.c"
2057fi
2058
2059
2060# Select shared-memory implementation type.
2061if test "$PORTNAME" != "win32"; then
2062  AC_DEFINE(USE_SYSV_SHARED_MEMORY, 1, [Define to select SysV-style shared memory.])
2063  SHMEM_IMPLEMENTATION="src/backend/port/sysv_shmem.c"
2064else
2065  AC_DEFINE(USE_WIN32_SHARED_MEMORY, 1, [Define to select Win32-style shared memory.])
2066  SHMEM_IMPLEMENTATION="src/backend/port/win32_shmem.c"
2067fi
2068
2069# If not set in template file, set bytes to use libc memset()
2070if test x"$MEMSET_LOOP_LIMIT" = x"" ; then
2071  MEMSET_LOOP_LIMIT=1024
2072fi
2073AC_DEFINE_UNQUOTED(MEMSET_LOOP_LIMIT, ${MEMSET_LOOP_LIMIT}, [Define bytes to use libc memset().])
2074
2075
2076if test "$enable_nls" = yes ; then
2077  PGAC_CHECK_GETTEXT
2078fi
2079
2080# Check for Tcl configuration script tclConfig.sh
2081if test "$with_tcl" = yes; then
2082    PGAC_PATH_TCLCONFIGSH([$with_tclconfig])
2083    PGAC_EVAL_TCLCONFIGSH([$TCL_CONFIG_SH],
2084                          [TCL_INCLUDE_SPEC,TCL_LIBS,TCL_LIB_SPEC,TCL_SHARED_BUILD])
2085    AC_SUBST(TCL_SHLIB_LD_LIBS)dnl don't want to double-evaluate that one
2086    if test "$TCL_SHARED_BUILD" != 1; then
2087      AC_MSG_ERROR([cannot build PL/Tcl because Tcl is not a shared library
2088Use --without-tcl to disable building PL/Tcl.])
2089    fi
2090    # now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
2091    ac_save_CPPFLAGS=$CPPFLAGS
2092    CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
2093    AC_CHECK_HEADER(tcl.h, [], [AC_MSG_ERROR([header file <tcl.h> is required for Tcl])])
2094    CPPFLAGS=$ac_save_CPPFLAGS
2095fi
2096
2097# check for <perl.h>
2098if test "$with_perl" = yes; then
2099  ac_save_CPPFLAGS=$CPPFLAGS
2100  CPPFLAGS="$CPPFLAGS $perl_includespec"
2101  AC_CHECK_HEADER(perl.h, [], [AC_MSG_ERROR([header file <perl.h> is required for Perl])],
2102                  [#include <EXTERN.h>])
2103  # While we're at it, check that we can link to libperl.
2104  # On most platforms, if perl.h is there then libperl.so will be too, but at
2105  # this writing Debian packages them separately.  There is no known reason to
2106  # waste cycles on separate probes for the Tcl or Python libraries, though.
2107  # On some Red Hat platforms, the link attempt can fail if we don't use
2108  # CFLAGS_SL while building the test program.
2109  ac_save_CFLAGS=$CFLAGS
2110  CFLAGS="$CFLAGS $CFLAGS_SL"
2111  pgac_save_LIBS=$LIBS
2112  LIBS="$perl_embed_ldflags"
2113  AC_MSG_CHECKING([for libperl])
2114  AC_LINK_IFELSE([AC_LANG_PROGRAM([
2115#include <EXTERN.h>
2116#include <perl.h>
2117],  [perl_alloc();])],
2118    [AC_MSG_RESULT(yes)],
2119    [AC_MSG_RESULT(no)
2120     AC_MSG_ERROR([libperl library is required for Perl])])
2121  LIBS=$pgac_save_LIBS
2122  CFLAGS=$ac_save_CFLAGS
2123  CPPFLAGS=$ac_save_CPPFLAGS
2124fi
2125
2126# check for <Python.h>
2127if test "$with_python" = yes; then
2128  ac_save_CPPFLAGS=$CPPFLAGS
2129  CPPFLAGS="$python_includespec $CPPFLAGS"
2130  AC_CHECK_HEADER(Python.h, [], [AC_MSG_ERROR([header file <Python.h> is required for Python])])
2131  CPPFLAGS=$ac_save_CPPFLAGS
2132fi
2133
2134#
2135# Check for DocBook and tools
2136#
2137PGAC_PROG_NSGMLS
2138PGAC_PROG_JADE
2139PGAC_CHECK_DOCBOOK(4.2)
2140PGAC_PATH_DOCBOOK_STYLESHEETS
2141PGAC_PATH_COLLATEINDEX
2142AC_CHECK_PROGS(DBTOEPUB, dbtoepub)
2143AC_CHECK_PROGS(XMLLINT, xmllint)
2144AC_CHECK_PROGS(XSLTPROC, xsltproc)
2145AC_CHECK_PROGS(OSX, [osx sgml2xml sx])
2146
2147#
2148# Check for test tools
2149#
2150if test "$enable_tap_tests" = yes; then
2151  AC_CHECK_PROGS(PROVE, prove)
2152  if test -z "$PROVE"; then
2153    AC_MSG_ERROR([prove not found])
2154  fi
2155  if test -z "$PERL"; then
2156    AC_MSG_ERROR([Perl not found])
2157  fi
2158fi
2159
2160# Thread testing
2161
2162# We have to run the thread test near the end so we have all our symbols
2163# defined.  Cross compiling throws a warning.
2164#
2165if test "$enable_thread_safety" = yes; then
2166if test "$PORTNAME" != "win32"
2167then
2168AC_MSG_CHECKING([thread safety of required library functions])
2169
2170_CFLAGS="$CFLAGS"
2171_LIBS="$LIBS"
2172CFLAGS="$CFLAGS $PTHREAD_CFLAGS -DIN_CONFIGURE"
2173LIBS="$LIBS $PTHREAD_LIBS"
2174AC_RUN_IFELSE(
2175  [AC_LANG_SOURCE([[#include "$srcdir/src/test/thread/thread_test.c"]])],
2176  [AC_MSG_RESULT(yes)],
2177  [AC_MSG_RESULT(no)
2178  AC_MSG_ERROR([thread test program failed
2179This platform is not thread-safe.  Check the file 'config.log' or compile
2180and run src/test/thread/thread_test for the exact reason.
2181Use --disable-thread-safety to disable thread safety.])],
2182  [AC_MSG_RESULT(maybe)
2183  AC_MSG_WARN([
2184*** Skipping thread test program because of cross-compile build.
2185*** Run the program in src/test/thread on the target machine.
2186])])
2187CFLAGS="$_CFLAGS"
2188LIBS="$_LIBS"
2189else
2190AC_MSG_WARN([*** skipping thread test on Win32])
2191fi
2192fi
2193
2194# If compiler will take -Wl,--as-needed (or various platform-specific
2195# spellings thereof) then add that to LDFLAGS.  This is much easier than
2196# trying to filter LIBS to the minimum for each executable.
2197# On (at least) some Red-Hat-derived systems, this switch breaks linking to
2198# libreadline; therefore we postpone testing it until we know what library
2199# dependencies readline has.  The test code will try to link with $LIBS.
2200if test "$with_readline" = yes; then
2201  link_test_func=readline
2202else
2203  link_test_func=exit
2204fi
2205
2206if test "$PORTNAME" = "darwin"; then
2207  PGAC_PROG_CC_LDFLAGS_OPT([-Wl,-dead_strip_dylibs], $link_test_func)
2208elif test "$PORTNAME" = "openbsd"; then
2209  PGAC_PROG_CC_LDFLAGS_OPT([-Wl,-Bdynamic], $link_test_func)
2210else
2211  PGAC_PROG_CC_LDFLAGS_OPT([-Wl,--as-needed], $link_test_func)
2212fi
2213
2214# Create compiler version string
2215if test x"$GCC" = x"yes" ; then
2216  cc_string=`${CC} --version | sed q`
2217  case $cc_string in [[A-Za-z]]*) ;; *) cc_string="GCC $cc_string";; esac
2218elif test x"$SUN_STUDIO_CC" = x"yes" ; then
2219  cc_string=`${CC} -V 2>&1 | sed q`
2220else
2221  cc_string=$CC
2222fi
2223
2224AC_DEFINE_UNQUOTED(PG_VERSION_STR,
2225                   ["PostgreSQL $PG_VERSION on $host, compiled by $cc_string, `expr $ac_cv_sizeof_void_p \* 8`-bit"],
2226                   [A string containing the version number, platform, and C compiler])
2227
2228# Supply a numeric version string for use by 3rd party add-ons
2229# awk -F is a regex on some platforms, and not on others, so make "." a tab
2230[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
2231tr '.' '	' |
2232$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
2233AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
2234AC_SUBST(PG_VERSION_NUM)
2235
2236# If we are inserting PG_SYSROOT into CPPFLAGS, do so symbolically not
2237# literally, so that it's possible to override it at build time using
2238# a command like "make ... PG_SYSROOT=path".  This has to be done after
2239# we've finished all configure checks that depend on CPPFLAGS.
2240# The same for LDFLAGS, too.
2241if test x"$PG_SYSROOT" != x; then
2242  CPPFLAGS=`echo "$CPPFLAGS" | sed -e "s| $PG_SYSROOT | \\\$(PG_SYSROOT) |"`
2243  LDFLAGS=`echo "$LDFLAGS" | sed -e "s| $PG_SYSROOT | \\\$(PG_SYSROOT) |"`
2244fi
2245AC_SUBST(PG_SYSROOT)
2246
2247
2248# Begin output steps
2249
2250AC_MSG_NOTICE([using compiler=$cc_string])
2251AC_MSG_NOTICE([using CFLAGS=$CFLAGS])
2252AC_MSG_NOTICE([using CPPFLAGS=$CPPFLAGS])
2253AC_MSG_NOTICE([using LDFLAGS=$LDFLAGS])
2254
2255# prepare build tree if outside source tree
2256# Note 1: test -ef might not exist, but it's more reliable than `pwd`.
2257# Note 2: /bin/pwd might be better than shell's built-in at getting
2258#         a symlink-free name.
2259if ( test "$srcdir" -ef . ) >/dev/null 2>&1 || test "`cd $srcdir && /bin/pwd`" = "`/bin/pwd`"; then
2260  vpath_build=no
2261else
2262  vpath_build=yes
2263  if test "$no_create" != yes; then
2264    _AS_ECHO_N([preparing build tree... ])
2265    pgac_abs_top_srcdir=`cd "$srcdir" && pwd`
2266    $SHELL "$ac_aux_dir/prep_buildtree" "$pgac_abs_top_srcdir" "." \
2267      || AC_MSG_ERROR(failed)
2268    AC_MSG_RESULT(done)
2269  fi
2270fi
2271AC_SUBST(vpath_build)
2272
2273
2274AC_CONFIG_FILES([GNUmakefile src/Makefile.global])
2275
2276AC_CONFIG_LINKS([
2277  src/backend/port/dynloader.c:src/backend/port/dynloader/${template}.c
2278  src/backend/port/pg_sema.c:${SEMA_IMPLEMENTATION}
2279  src/backend/port/pg_shmem.c:${SHMEM_IMPLEMENTATION}
2280  src/include/dynloader.h:src/backend/port/dynloader/${template}.h
2281  src/include/pg_config_os.h:src/include/port/${template}.h
2282  src/Makefile.port:src/makefiles/Makefile.${template}
2283])
2284
2285if test "$PORTNAME" = "win32"; then
2286AC_CONFIG_COMMANDS([check_win32_symlinks],[
2287# Links sometimes fail undetected on Mingw -
2288# so here we detect it and warn the user
2289for FILE in $CONFIG_LINKS
2290 do
2291	# test -e works for symlinks in the MinGW console
2292	test -e `expr "$FILE" : '\([[^:]]*\)'` || AC_MSG_WARN([*** link for $FILE -- please fix by hand])
2293 done
2294])
2295fi
2296
2297AC_CONFIG_HEADERS([src/include/pg_config.h],
2298[
2299# Update timestamp for pg_config.h (see Makefile.global)
2300echo >src/include/stamp-h
2301])
2302
2303AC_CONFIG_HEADERS([src/include/pg_config_ext.h],
2304[
2305# Update timestamp for pg_config_ext.h (see Makefile.global)
2306echo >src/include/stamp-ext-h
2307])
2308
2309AC_CONFIG_HEADERS([src/interfaces/ecpg/include/ecpg_config.h],
2310                  [echo >src/interfaces/ecpg/include/stamp-h])
2311
2312AC_OUTPUT
2313