"Fossies" - the Fresh Open Source Software Archive

Member "txr-217/configure" (10 Jun 2019, 63949 Bytes) of package /linux/misc/txr-217.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "configure": 216_vs_217.

    1 #!/bin/sh
    2 #
    3 # Copyright 2009-2019
    4 # Kaz Kylheku <kaz@kylheku.com>
    5 # Vancouver, Canada
    6 # All rights reserved.
    7 #
    8 # Redistribution and use in source and binary forms, with or without
    9 # modification, are permitted provided that the following conditions are met:
   10 #
   11 # 1. Redistributions of source code must retain the above copyright notice, this
   12 #    list of conditions and the following disclaimer.
   13 #
   14 # 2. Redistributions in binary form must reproduce the above copyright notice,
   15 #    this list of conditions and the following disclaimer in the documentation
   16 #    and/or other materials provided with the distribution.
   17 #
   18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   21 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
   22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   24 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   26 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   28 
   29 #
   30 # The #!/bin/sh might be some legacy piece of crap,
   31 # not even up to 1990 POSIX.2 spec. So the first step
   32 # is to look for a better shell in some known places
   33 # and re-execute ourselves with that interpreter.
   34 #
   35 
   36 if test x$txr_shell = x ; then
   37   for shell in /bin/bash /usr/bin/bash /usr/xpg4/bin/sh ; do
   38     if test -x $shell ; then
   39        txr_shell=$shell
   40        break
   41     fi
   42   done
   43   if test x$txr_shell = x ; then
   44     echo "No known POSIX shell found: falling back on /bin/sh, which may not work"
   45     txr_shell=/bin/sh
   46   fi
   47   export txr_shell
   48   exec $txr_shell $0 ${@+"$@"}
   49 fi
   50 
   51 set -u
   52 
   53 #
   54 # Save command line in a way that can be re-run.
   55 # This takes care of spaces, but if there are shell-meta characters
   56 # in the arguments, oops.
   57 #
   58 
   59 cmdline=
   60 for arg in "$0" ${@+"$@"} ; do
   61   [ -n "$cmdline" ] && cmdline="$cmdline "
   62   case $arg in
   63   *" "* | " "* | *" " )
   64     cmdline=$cmdline$(printf "\"%s\"" "$arg")
   65     ;;
   66   * )
   67     cmdline=$cmdline$arg
   68     ;;
   69   esac
   70 done
   71 
   72 #
   73 # Establish default values for any variables that are not specified
   74 # on the command line. The default derivations from prefix are in
   75 # Make syntax. They go verbatim into the generated config.make.
   76 # This way they can be overridden more flexibly at make time.
   77 #
   78 
   79 #
   80 # non-config
   81 #
   82 help=
   83 
   84 #
   85 # config
   86 #
   87 build_in_srcdir=
   88 prefix='/usr/local'
   89 install_prefix=
   90 bindir='bin'
   91 datadir='share/txr'
   92 mandir='share/man'
   93 make=
   94 cross=
   95 compiler_prefix=
   96 ccname='$(CC)'
   97 cc='$(cross)$(compiler_prefix)$(ccname)'
   98 intptr=
   99 exe=
  100 tool_prefix=
  101 lexname_given=
  102 lexname=
  103 lex_given=
  104 lex='$(cross)$(tool_prefix)$(lexname)'
  105 yaccname_given=
  106 yaccname='' # test tries $(YACC) first
  107 yacc='$(cross)$(tool_prefix)$(yaccname)'
  108 yacc_given=
  109 nm='$(cross)$(tool_prefix)nm'
  110 opt_flags='-O2 -fno-stack-protector'
  111 lang_flags='-ansi -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE'
  112 diag_flags='-Wall -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=strict-prototypes'
  113 debug_flags=-g
  114 debug_only_flags=-DTXR_DEBUG
  115 debug_also=
  116 inline=
  117 platform_cflags=
  118 remove_flags=
  119 lex_dbg_flags=
  120 conf_ldflags=
  121 platform_ldflags=
  122 txr_dbg_opts=--gc-debug
  123 valgrind=
  124 lit_align=
  125 extra_debugging=
  126 debug_support=y
  127 gen_gc=y
  128 have_dbl_decimal_dig=
  129 have_unistd=
  130 have_sys_types=
  131 have_sys_time=
  132 have_makedev=
  133 have_syslog=
  134 have_glob=
  135 have_ftw=
  136 have_windows_h=
  137 have_windres=
  138 have_posix_sigs=
  139 have_sockets=
  140 need_darwin_c_source=
  141 have_git=
  142 have_pwuid=
  143 have_grgid=
  144 have_alloca=
  145 have_termios=
  146 have_winsize=
  147 termios_define=
  148 have_pkgconfig=
  149 libffi_cflags=
  150 
  151 #
  152 # Parse configuration variables
  153 #
  154 while [ $# -gt 0 ] ; do
  155   case $1 in
  156   --no-* | --no_* )
  157     var=${1#--no?}
  158     val=
  159     ;;
  160   --*=* )
  161     var=${1%%=*}
  162     var=${var#--}
  163     val=${1#*=}
  164     ;;
  165   --*= )
  166     var=${1%%=*}
  167     var=${var#--}
  168     val=
  169     ;; --* )
  170     var=${1#--}
  171     val=y
  172     ;;
  173   *=* )
  174     var=${1%%=*}
  175     val=${1#*=}
  176     ;;
  177   *= )
  178     var=${1%%=*}
  179     val=
  180     ;;
  181   * )
  182     printf "$0: '$1' doesn't look like a configuration variable assignment\n"
  183     printf "$0: use --help to get help\n"
  184     exit 1
  185   esac
  186 
  187   var=$(echo "$var" | tr - _)
  188 
  189   if ! echo $var | grep -q -E '^[A-Za-z_][A-Za-z0-9_]*$' ; then
  190     printf "$0: '$var' isn't a proper configuration variable name\n"
  191     exit 1
  192   fi
  193 
  194   eval "var_exists=\${$var+y}"
  195 
  196   if [ "$var_exists" != y ] ; then
  197     printf "$0: nonexistent option: '%s'\n" "$1"
  198     exit 1
  199   fi
  200 
  201   eval "$var='$val'"
  202 
  203   eval "var_given_exists=\${${var}_given+y}"
  204 
  205   if [ "$var_given_exists" = y ] ; then
  206     eval "${var}_given=y"
  207   fi
  208 
  209   shift
  210 done
  211 
  212 #
  213 # If --help was given (or --help=<nonempty> or help=<nonempty>) then
  214 # print help and exit. The termination status is failed, to indicate
  215 # that configuration was not done.
  216 #
  217 
  218 if [ -n "$help" ] ; then
  219 cat <<!
  220 
  221 usage: $0 { variable=value }*
  222 
  223 The configure script prepares txr program for compilation and installation.
  224 To configure a program means to establish the values of make variables
  225 which influence how the software is built, where it is installed.
  226 These variables can also influence what features are present in the
  227 software, and can determine various defaults for those behaviors which are
  228 dynamically configurable when the software is run.
  229 
  230 Configuration variables are recorded in a file called config.make.
  231 This is a GNU makefile, and consequently uses the GNU make syntax. It is
  232 included in the main Makefile by an include statement.
  233 
  234 The configure script is flexible. It allows variables to be entered in any
  235 of these forms:
  236 
  237 Canonical:
  238 
  239    variable=value      Defines the given variable as having the given value.
  240    variable=           Defines the variable as having an empty value.
  241                        An empty value serves as boolean false.
  242 
  243 Long-option style:
  244 
  245    --variable=value    Same as 'variable=value', but resembles a GNU-style
  246                        long option.
  247    --variable          Same as 'variable=y'.
  248    --no-variable       Same as 'variable='.
  249 
  250 No variables are required. The configure script establishes default values
  251 for any variables which are needed by the build, but which are not specified
  252 on the command line.
  253 
  254 After running $0, check that the config.make contents are sane.
  255 
  256 The following variables are supported.  Note that make variable syntax may
  257 be used in paths. Default values are shown in [square brackets].
  258 
  259 Variables are case-sensitive, but underscores and dashes are interchangeable.
  260 
  261 prefix [$prefix]
  262 
  263   Specifies root directory where the software will ultimately be installed and
  264   run from.
  265 
  266 install-prefix [$install_prefix]
  267 
  268   Specifies an extra path prefix that will be prepended to all paths during
  269   installation, which allows the software to be installed in a temporary
  270   directory for packaging. This variable becomes the \$(DESTDIR)
  271   variable in the config.make makefile.
  272 
  273 bindir [$bindir]
  274 
  275   Specifies where the program executable will be installed, as a relative
  276   path from the prefix.
  277 
  278 datadir [$datadir]
  279 
  280   Specifies where read-only program data is to be stored, as a relative
  281   path from the prefix.
  282 
  283 mandir [$mandir]
  284 
  285   Specifies the directory where to install man pages, as a relative
  286   path from the prefix.
  287 
  288 cross [$cross]
  289 
  290   Specifies the root of a cross-compiling toolchain.
  291   This becomes the \$(cross) variable in the config.make makefile, and by
  292   default will be added as a prefix to all of the toolchain commands.
  293   It should include the trailing slash, unless the \$compiler_prefix
  294   and \$tool_prefix variables take care of this by providing a leading slash.
  295   If this variable is set, ccname should also be set; the default
  296   ccname doesn't make sense in that case.
  297 
  298 compiler-prefix [$compiler_prefix]
  299 
  300   Specifies a prefix to be added to the compiler command.
  301   This is added to the \$(cross) prefix. This can include some path name
  302   components, and a name fragment. For instance, if
  303   \$cross is "/cross/toolchain/" and \$compiler_prefix is
  304   "bin/mips-linux-" then the compiler command, unless otherwise
  305   specified, will be "/cross/toolchain/bin/mips-linux-gcc".
  306   If this variable is set, ccname should also be set; the default
  307   ccname doesn't make sense in that case.
  308 
  309 ccname [$ccname]
  310 
  311   Specifies just the name of the compiler front-end program, without the path.
  312   The following variable, cc, specifies the full name.
  313   The default value is the \$(CC) predefined make variable.
  314 
  315 cc [$cc]
  316 
  317   Specifies the name of the toolchain front-end driver command to use for
  318   compiling C sources to object files, and for linking object files to
  319   executables. This becomes the TXR_CC variable in config.make.
  320   Note that cross and compiler_prefix are empty by default and
  321   and so this expands to just ccname.
  322 
  323 intptr [$intptr]
  324 
  325   Specifies the name of the C integer type wide enough such that a pointer
  326   value can be converted to it. If this is blank, the configure script
  327   will try to auto detect it.
  328 
  329 lit-align [$lit_align]
  330 
  331   Specifies alignment for wide string literals.  This is guessed
  332   from the size of the wchar_t type. If your wchar_t type is two byte wide, but
  333   wide literals are aligned to four bytes, then you should specify this.  This
  334   will eliminate some kludges in the program. There is no easy way to check
  335   for this withut generating and running a C program, which is unfriendly
  336   for cross-compiling!
  337 
  338 inline [$inline]
  339 
  340   Specifies the syntax for defining an inline function, in such
  341   a way that the function definition can be included into multiple
  342   translation units without clashes.
  343 
  344   If blank, an attempt is made to auto-detect this which
  345   falls back on "static".
  346 
  347 tool-prefix [$tool_prefix]
  348 
  349   Specifies a prefix to be added to tool commands other than the
  350   compiler, like lex and yacc, in addition to \$cross.
  351 
  352 lexname [$lexname]
  353 
  354   Specifies just the name of the lex program without the path.
  355   The following variable, lex, specifies the full name.
  356   If blank, the choice lex program will be auto-detected.
  357 
  358 lex [$lex]
  359 
  360   Specifies the program to use for compiling lex scanners to C.
  361   This must be compatible with GNU flex, since flex extensions are used.
  362 
  363 yaccname [$yaccname]
  364 
  365   Specifies just the name of the yacc program without the path.
  366   The following variable, yacc, specifies the full name.
  367   If blank, the choice yacc program will be auto-detected.
  368 
  369 yacc [$yacc]
  370 
  371   Specifies the program to use for compiling yacc scanners to C.
  372 
  373 nm [$nm]
  374 
  375   Specifies the nm program for dumping symbols from an object file.
  376 
  377 opt-flags [$opt_flags]
  378 
  379   Specifies optimization flags to use for compiling and linking
  380   C sources. Note that these are in addition to any CFLAGS
  381   passed in the environment or on the make command line.
  382 
  383 lang-flags [$lang_flags]
  384 
  385   Specifies compiler flags which control the C language dialect and standard
  386   conformance in the language and header files. The txr program is written
  387   in C90, and requires POSIX and possibly other extensions.
  388 
  389 diag-flags [$diag_flags]
  390 
  391   Specifies compiler flags for obtaining extra diagnostics.
  392 
  393 debug-flags [$debug_flags]
  394 
  395   Specifies flags for requesting that debugging information be
  396   retained in the compile and link. These flags are applied
  397   to optimized and debugging targets.
  398 
  399 debug-only-flags [$debug_only_flags]
  400 
  401   Specifies compiler flags which only apply to debugging
  402   targets.
  403 
  404 debug-also [$debug_also]
  405 
  406   Specifies that a debugging version of TXR is to be built at the
  407   same time. This means that "make" will always update two sets
  408   of object files compiled with different optimization flags,
  409   and produce two binaries: txr and txr-dbg.
  410 
  411 platform-cflags [$platform_cflags]
  412 
  413   Specify additional compiler flags for anything else, such as CPU tuning,
  414   target ABI selection, code generation options, et cetera.
  415 
  416 platform-ldflags [$platform_ldflags]
  417 
  418   Specify additional linker flags for anything else, such as hardening,
  419   linking as needed, et cetera. Note that these are in addition to
  420   any LDFLAGS from the environment or make command line.
  421 
  422 remove-flags [$remove_flags]
  423 
  424   This is a negative otpion. Any flags mentioned in this variable
  425   will be removed from any of the other compiler flags options above.
  426   The flags may contain GNU Make patterns.
  427 
  428 lex-dbg-flags [$lex_dbg_flags]
  429 
  430   Specifies debug flags to be passed to lex, perhaps to generate a debugging
  431   scanner.
  432 
  433 txr-dbg-opts [$txr_dbg_opts]
  434 
  435   Specifies debug flags to pass to the txr program during the execution
  436   of "make tests".
  437 
  438 valgrind [$valgrind]
  439 
  440   Use --valgrind to to build txr with valgrind integration.
  441   Valgrind integration means that when the program is running under valgrind,
  442   it advises valgrind about stack memory locations accessed by the garbage
  443   collector, to suppress diagnostics about uninitialized accesses.
  444 
  445 extra-debugging [$extra_debugging]
  446 
  447   Use --extra_debugging to configure some additional debugging features,
  448   which incur a run-time penalty.
  449 
  450 gen-gc [$gen_gc]
  451 
  452   Use --no-gen-gc to disable the generational garbage collector which
  453   is now enabled by default.
  454 
  455   When disabled, the garbage collector performs a full object traversal and
  456   sweep on each garbage collection.
  457 
  458 !
  459   exit 1
  460 fi
  461 
  462 #
  463 # Variables are read, --help wasn't given, so let's configure!
  464 #
  465 
  466 
  467 txr_ver=217
  468 
  469 #
  470 # The all important banner.
  471 #
  472 
  473 if [ $txr_ver ] ; then
  474   banner_text=$(printf " Configuring txr %s " "$txr_ver")
  475 else
  476   banner_text=" Configuring txr (unknown version) "
  477 fi
  478 banner_box=$(printf "%.${#banner_text}s\n" \
  479              "-------------------------------------------")
  480 printf "+%s+\n|%s|\n+%s+\n" $banner_box "$banner_text" $banner_box
  481 
  482 #
  483 # From here on in, we bail if any command fails.
  484 #
  485 
  486 set -e
  487 
  488 printf "We are using this shell: %s\n" $txr_shell
  489 
  490 #
  491 # Check for GNU make
  492 #
  493 
  494 printf "Checking for GNU Make ... "
  495 
  496 if [ -z "$make" ] ; then
  497   for make in make gmake ; do
  498     output=$($make --version 2> /dev/null) || true
  499     set -- $output
  500 
  501     if [ $# -lt 2 ] || [ $1 != "GNU" -o $2 != "Make" ] ; then
  502       continue
  503     fi
  504     break
  505   done
  506 fi
  507 
  508 if [ -z "$make" ] ; then
  509   printf "missing\n"
  510   exit 1
  511 fi
  512 
  513 make_version=$3
  514 
  515 save_ifs=$IFS ; IFS=. ; set -- $make_version ; IFS=$save_ifs
  516 
  517 if [ $1 -lt 3 -o \( $1 -eq 3 -a $2 -lt 81 \) ] ; then
  518   printf "too old (%s found, 3.81 or newer needed)\n" $make_version
  519   exit 1
  520 else
  521   printf "yes (%s found)\n" $make_version
  522 fi
  523 
  524 #
  525 # Verify sanity of --prefix and other directories.
  526 #
  527 
  528 printf "Checking installation paths:\n"
  529 
  530 for name in bindir datadir mandir; do
  531   eval path="\$install_prefix\$prefix/\${$name}"
  532   printf "\$(install_prefix)\$(prefix)/\$%s=%s ... " $name "$path"
  533   test_access=y
  534   case "$path" in
  535   " "* | *" "* | *" " )
  536     printf "incorrect (contains spaces)\n"
  537     exit 1
  538     ;;
  539   -* )
  540     printf "incorrect (resembles a command option)\n"
  541     exit 1
  542     ;;
  543   *'$('* )
  544     # It's a make expression; can't test it
  545     test_access=
  546     ;;
  547   /* )
  548     ;;
  549   * )
  550     printf "incorrect (must be absolute path)\n"
  551     exit 1
  552     ;;
  553   esac
  554 
  555   if [ $test_access ] ; then
  556     test_prefix=$path
  557 
  558     while true ; do
  559       if [ -e $test_prefix ] ; then
  560       if [ ! -d $test_prefix ] ; then
  561         printf "incorrect ('%s' is not a directory)!\n" $test_prefix
  562         exit 1
  563       fi
  564       if [ ! -w $test_prefix ] ; then
  565         printf "okay\n  (but no write access to '%s'\n" $test_prefix
  566 
  567         printf "   so '$make install' will require root privileges)\n"
  568       else
  569         printf "okay\n"
  570       fi
  571       break
  572       fi
  573       test_prefix=$(dirname $test_prefix)
  574     done
  575   else
  576     printf "okay\n  (make variable derivation)\n"
  577   fi
  578 done
  579 
  580 #
  581 # First, we have to figure out whether we are configured straight
  582 # in the source directory, or whether we are in a separate build directory.
  583 # In the latter case, we set up a symbolic link to the Makefile.
  584 #
  585 source_dir="$(dirname $0)"
  586 
  587 #
  588 # If building in a separate directory, establish top_srcdir as
  589 # an absolute path to the source directory, with a trailing slash.
  590 # Otherwise top_srcdir is blank.
  591 #
  592 
  593 if [ "$source_dir" = "." ] ; then
  594   top_srcdir=""
  595 else
  596   top_srcdir="$(cd "$source_dir" ; pwd -P)"/
  597 fi
  598 
  599 printf "Checking source directory \"%s\" ..." "$top_srcdir"
  600 
  601 lndir()
  602 {
  603   fromdir=$1
  604   todir=${2%/}
  605   abs=${fromdir%${fromdir#/}}
  606 
  607   find "$fromdir" \( -type f -o -type d \) | while read frompath ; do
  608     topath=${frompath#$fromdir}
  609     topath=${topath#/}
  610     [ -n "$topath" ] || topath="."
  611     if [ -f "$frompath" ] ; then
  612       if [ $abs ] ; then
  613         ln -sf "$frompath" "$todir/$topath"
  614       else
  615         old_IFS=$IFS
  616         IFS=/
  617         set -- $todir/$topath
  618         IFS=$old_IFS
  619         dots=""
  620         while [ $# -gt 0 ] ; do
  621           [ $1 = "." ] || dots="$dots../"
  622           shift
  623         done
  624         rm -f "$todir/$topath"
  625         ln -sf "$dots$frompath" "$todir/$topath"
  626       fi
  627     else
  628       mkdir -p "$todir/$topath"
  629     fi
  630   done
  631 }
  632 
  633 inode()
  634 {
  635   set -- $(ls -idL "$1")
  636   printf "%s\n" "$1"
  637 }
  638 
  639 case "$top_srcdir" in
  640 " "* | *" "* | *" " )
  641   printf " bad (contains spaces)\n"
  642   exit 1
  643   ;;
  644 * )
  645   printf " okay\n"
  646   ;;
  647 esac
  648 
  649 if [ $(inode "$source_dir") != $(inode ".") ] ; then
  650   for x in Makefile ; do
  651     printf "Symlinking %s -> $source_dir/%s\n" $x $x
  652     ln -sf "$source_dir/$x" .
  653   done
  654   for x in share tests; do
  655     printf "Tree symlinking %s -> $source_dir/%s\n" $x $x
  656     lndir $source_dir/$x $x
  657   done
  658 else
  659   printf "** Note: it's recommended to build in a separate directory\n"
  660   build_in_srcdir=y
  661 fi
  662 
  663 gen_config_make()
  664 {
  665   cat > config.make <<!
  666 #
  667 # Make include file automatically generated by $0.
  668 # Changes to this file are lost when the above is re-run.
  669 #
  670 
  671 # Shell used by make for running recipes; this
  672 # is the as the shell we chose for the configure script,
  673 # derived from the txr_shell variable.
  674 SHELL := $txr_shell
  675 
  676 txr_ver := $txr_ver
  677 
  678 # absolute path to source code directory
  679 top_srcdir := $top_srcdir
  680 
  681 # build directory is top_srcdir
  682 build_in_srcdir = $build_in_srcdir
  683 
  684 # ultimate installation prefix, where the
  685 # application will be run.
  686 prefix := $prefix
  687 
  688 # packaging installation prefix, where the
  689 # application may be temporarily installed
  690 # for creating pre-compiled packages,
  691 # e.g. for an operating system distro.
  692 DESTDIR := $install_prefix
  693 
  694 # relative path from prefix to datadir
  695 bindir_rel := $bindir
  696 
  697 # executable directory
  698 bindir = \$(prefix)/\$(bindir_rel)
  699 
  700 # read-only data directory
  701 datadir = \$(prefix)/$datadir
  702 
  703 # man page directory
  704 mandir = \$(prefix)/$mandir
  705 
  706 # cross compiler toolchain root directory
  707 cross := $cross
  708 
  709 # compiler name
  710 ccname = $ccname
  711 
  712 # name of lex program
  713 lexname = $lexname
  714 
  715 # name of yacc program
  716 yaccname = $yaccname
  717 
  718 # prefix for compiler command
  719 compiler_prefix := $compiler_prefix
  720 
  721 # prefix for non-compiler toolchain commands
  722 tool_prefix := $tool_prefix
  723 
  724 # do we compile in syslog support?
  725 have_syslog := $have_syslog
  726 
  727 # do we compile in glob support?
  728 have_glob := $have_glob
  729 
  730 # do we compile in ftwsupport?
  731 have_ftw := $have_ftw
  732 
  733 # do we modern posix signal handling?
  734 have_posix_sigs := $have_posix_sigs
  735 
  736 have_sockets := $have_sockets
  737 have_termios := $have_termios
  738 termios_define := $termios_define
  739 
  740 # do we compile in debug support?
  741 debug_support := $debug_support
  742 
  743 # EXE suffix
  744 EXE := $exe
  745 
  746 have_git := $have_git
  747 
  748 add_win_res := $([ -n "$have_windows_h" -a -n "$have_windres" ] && echo "y")
  749 
  750 TXR_CC := $cc
  751 TXR_LEX := $lex
  752 TXR_YACC := $yacc
  753 TXR_NM := $nm
  754 
  755 PROG := txr
  756 
  757 OPT_FLAGS := $opt_flags
  758 LANG_FLAGS := $lang_flags
  759 DIAG_FLAGS := $diag_flags
  760 DBG_FLAGS := $debug_flags
  761 DBG_ONLY_FLAGS := $debug_only_flags
  762 BUILD_TARGETS := $(if [ $debug_also ] ; then
  763                      echo '$(PROG) $(PROG)-dbg'
  764                    else
  765                      echo '$(PROG)'; fi)
  766 PLATFORM_CFLAGS := $platform_cflags
  767 PLATFORM_LDFLAGS := $platform_ldflags
  768 CONF_LDFLAGS := $conf_ldflags
  769 REMOVE_FLAGS := $remove_flags
  770 LEX_DBG_FLAGS := $lex_dbg_flags
  771 TXR_DBG_OPTS := $txr_dbg_opts
  772 
  773 LIBFFI_CFLAGS := $libffi_cflags
  774 !
  775 }
  776 
  777 #
  778 # Before doing some other tests, we need a config.make
  779 #
  780 
  781 printf "Generating config.make ... "
  782 gen_config_make
  783 printf "\n"
  784 
  785 #
  786 # Start config.h header
  787 #
  788 
  789 cat <<! > config.h
  790 /*
  791  * Header file automatically generated by $0.
  792  * Tweaking this file may seem like a good temporary workaround
  793  * to some problem but you probably should fix the script
  794  * to do the job. In any case, be aware that you will lose your
  795  * changes if you re-run $0.
  796  */
  797 !
  798 
  799 #
  800 # Perform a configure test.
  801 # Arguments are passed through to make
  802 #
  803 conftest()
  804 {
  805   rm -f ${exe-"conftest conftest.exe"} ${exe+"conftest$exe"}
  806   $make conftest ${@+"$@"} > conftest.err 2>&1 && [ -x conftest ] 
  807 }
  808 
  809 #
  810 # Like conftest but make only .o
  811 #
  812 conftest_o()
  813 {
  814   rm -f conftest.o
  815   $make conftest.o ${@+"$@"} > conftest.err 2>&1
  816 }
  817 
  818 #
  819 # Like conftest but make conftest.syms
  820 #
  821 conftest_syms()
  822 {
  823   rm -f conftest.o conftest.syms
  824   $make conftest.syms ${@+"$@"} > conftest.err 2>&1
  825 }
  826 
  827 #
  828 # Check for git because we use it out of the Makefile
  829 # But this is pointless if we have no git repo.
  830 # "have_git" means we have a repo, and git.
  831 #
  832 if [ -d $top_srcdir.git ] ; then 
  833   printf "Checking whether we have git ... "
  834 
  835   if git --version > /dev/null 2> /dev/null ; then
  836     have_git=y
  837     printf "yes\n"
  838   else
  839     printf "missing\n"
  840   fi
  841 fi
  842 
  843 #
  844 # Check C compiler sanity
  845 #
  846 printf "Checking whether your C compiler can make a simple executable ... "
  847 
  848 cat > conftest.c <<!
  849 #include <stdio.h>
  850 int main(void)
  851 {
  852   printf("Hello, world!\n");
  853   return 0;
  854 }
  855 !
  856 
  857 if ! conftest ; then
  858   printf "failed\n"
  859   printf "Checking whether the failure is due to a requirement to use C99 ... "
  860   if conftest EXTRA_FLAGS=-std=c99 ; then
  861     printf "yes\n"
  862     lang_flags="$(echo "$lang_flags" | sed -e 's/-ansi/-std=c99/')"
  863   else
  864     printf "no\n\n"
  865     conftest && true
  866     printf "Errors from compilation: \n\n"
  867     cat conftest.err
  868     exit 1
  869   fi
  870 else
  871   printf "okay\n"
  872 fi
  873 
  874 printf "Checking whether executables have that idiotic .exe suffix ... "
  875 
  876 if ls conftest.exe > /dev/null 2>&1 ; then
  877   echo "yes"
  878   exe=.exe
  879 else
  880   echo "no"
  881 fi
  882 
  883 rm -f conftest$exe
  884 
  885 #
  886 # Check for annoying clashes from non-conforming BSD-derived systems that don't
  887 # honor Unix/POSIX feature selection macros!
  888 #
  889 
  890 printf "Checking for name clashes caused by nonconforming toolchains ... "
  891 
  892 for ident in trunc floorf random longlong_t ; do
  893   cat > conftest.c <<!
  894 #include <assert.h>
  895 #include <ctype.h>
  896 #include <dirent.h>
  897 #include <errno.h>
  898 #include <float.h>
  899 #include <limits.h>
  900 #include <math.h>
  901 #include <setjmp.h>
  902 #include <stdarg.h>
  903 #include <stddef.h>
  904 #include <stdio.h>
  905 #include <stdlib.h>
  906 #include <string.h>
  907 #include <sys/wait.h>
  908 #include <time.h>
  909 #include <unistd.h>
  910 #include <wchar.h>
  911 #include <wctype.h>
  912 
  913 struct txr_foo { int txr; } $ident;
  914 
  915 int $ident(void);
  916 
  917 int main(void) { return 0; }
  918 !
  919   if ! conftest ; then
  920     printf "#define %s txr_%s\n" $ident $ident >> config.h
  921     have_unistd=y
  922   fi
  923 done
  924 
  925 printf "done\n"
  926 
  927 #
  928 # Check for idiotic behavior: extensions in C header files controlled
  929 # by __STRICT_ANSI__ rather than things like __POSIX_SOURCE.
  930 #
  931 
  932 printf "Checking for proper support for feature-test macros ... "
  933 
  934 cat > conftest.c <<!
  935 #include <stdio.h>
  936 
  937 int main(void)
  938 {
  939    return fileno(stdin);
  940 }
  941 !
  942 if conftest EXTRA_FLAGS=-Werror ; then
  943   printf "yes\n"
  944 else
  945   printf "no\n"
  946   lang_flags="$lang_flags -U__STRICT_ANSI__"
  947   printf "Regenerating config.make ..."
  948   gen_config_make
  949   printf "done\n"
  950 fi
  951 
  952 #
  953 # Detect Apple environment. We need _DARWIN_C_SOURCE.
  954 #
  955 
  956 printf "Checking for Apple environment ... "
  957 if [ "$(make conftest.darwin)" = "yes" ] ; then
  958   printf "yes\n"
  959   need_darwin_c_source=y
  960   lang_flags="$lang_flags -D_DARWIN_C_SOURCE"
  961   printf "Regenerating config.make ..."
  962   gen_config_make
  963   printf "done\n"
  964 else
  965   printf "no\n"
  966 fi
  967 
  968 #
  969 # Detect stupid FreeBSD problem: no defined way to reveal
  970 # traditional BSD functions if Unix compliance is selected with
  971 # _XOPEN_SOURCE. Heaven help these troglodytes.
  972 #
  973 
  974 printf "Detecting what symbol reveals BSD functions ... "
  975 
  976 cat > conftest.c <<!
  977 #include <unistd.h>
  978 #include <stdlib.h>
  979 
  980 int main(int argc, char **argv)
  981 {
  982   int (*pdaemon)(int, int) = &daemon;
  983 }
  984 !
  985 
  986 if conftest ; then
  987   printf "none needed\n"
  988 else
  989   for flag in _DEFAULT_SOURCE _BSD_SOURCE __BSD_VISIBLE _GNU_SOURCE _X_OOPS; do
  990     if [ $flag = _X_OOPS ] ; then
  991       printf "failed\n"
  992       break
  993     fi
  994     
  995     if conftest EXTRA_FLAGS=-D$flag ; then
  996       printf "%s\n" $flag 
  997       lang_flags="$lang_flags -D$flag"
  998       gen_config_make
  999       break
 1000     fi
 1001   done
 1002 fi
 1003 
 1004 #
 1005 # Check for annoying warnings from ctype.h macros
 1006 #
 1007 
 1008 printf "Checking for annoying warnings from <ctype.h> macros ... "
 1009 
 1010 cat > conftest.c <<!
 1011 #include <ctype.h>
 1012 
 1013 int main(void)
 1014 {
 1015   char x = '3';
 1016   return isdigit(x);
 1017 }
 1018 !
 1019 if conftest EXTRA_FLAGS=-Werror ; then
 1020   printf "absent\n"
 1021 else
 1022   printf "present\n"
 1023   cat >> config.h <<!
 1024 $(for x in isalpha isupper islower isdigit isxdigit isalnum isspace \
 1025            ispunct isprint isgraph iscntrl isblank ; do \
 1026     printf "#undef %s\n" $x ; done)
 1027 !
 1028 fi
 1029 
 1030 #
 1031 # Check what kind of C type we have for integers wider than long,
 1032 # if any.
 1033 #
 1034 printf "Checking what C type we have for integers wider than \"long\" ... "
 1035 
 1036 longlong=
 1037 
 1038 for try_type in int64 __int64 "long long" ; do
 1039   cat > conftest.c <<!
 1040 $try_type value;
 1041 !
 1042   if conftest_o ; then
 1043     longlong=$try_type
 1044     break
 1045   fi
 1046 done
 1047 
 1048 if [ -n "$longlong" ] ; then
 1049   printf '"%s"\n' "$longlong"
 1050   printf "#define HAVE_LONGLONG_T 1\n" >> config.h
 1051   printf "typedef $longlong longlong_t;\n" >> config.h
 1052 else
 1053   printf "none\n"
 1054 fi
 1055 
 1056 printf "Checking what C type we have for unsigned integers wider than \"long\" ... "
 1057 
 1058 ulonglong=
 1059 
 1060 for try_type in uint64 __uint64 "unsigned long long" ; do
 1061   cat > conftest.c <<!
 1062 $try_type value;
 1063 !
 1064   if conftest_o; then
 1065     ulonglong=$try_type
 1066     break
 1067   fi
 1068 done
 1069 
 1070 if [ -n "$ulonglong" ] ; then
 1071   printf '"%s"\n' "$ulonglong"
 1072   printf "#define HAVE_ULONGLONG_T 1\n" >> config.h
 1073   printf "typedef $ulonglong ulonglong_t;\n" >> config.h
 1074 else
 1075   printf "none\n"
 1076 fi
 1077 
 1078 printf "Checking what C type we have for integers wider than \"long long\" ... "
 1079 
 1080 broken128=
 1081 output=$($make conftest.ccver)
 1082 set -- $output
 1083 if [ "$1" = "gcc" ] ; then
 1084   gcc_version=$3
 1085   save_ifs=$IFS ; IFS=. ; set -- $gcc_version ; IFS=$save_ifs
 1086   if [ $1 -lt 4 ] || [ $1 -eq 4 -a $2 -le 3 ] ; then
 1087     broken128=y
 1088   fi
 1089 fi
 1090 
 1091 superlong=
 1092 
 1093 if [ -z "$broken128" ] ; then
 1094   for try_type in int128 int128_t __int128 __int128_t ; do
 1095     cat > conftest.c <<!
 1096 #include "config.h"
 1097 int main(void)
 1098 {
 1099    extern longlong_t a, b;
 1100    $try_type value = ($try_type) a * ($try_type) b;
 1101    return 0;
 1102 }
 1103 longlong_t a, b;
 1104 !
 1105     if conftest_o ; then
 1106       superlong=$try_type
 1107       break
 1108     fi
 1109   done
 1110 fi
 1111 
 1112 if [ -n "$superlong" ] ; then
 1113   printf '"%s"\n' "$superlong"
 1114 else
 1115   printf "none\n"
 1116 fi
 1117 
 1118 printf "Checking what C type we have for u. integers wider than \"long long\" ... "
 1119 
 1120 superulong=
 1121 
 1122 if [ -z "$broken128" ] ; then
 1123   for try_type in uint128 uint128_t __uint128 __uint128_t 'unsigned int128'; do
 1124     cat > conftest.c <<!
 1125 #include "config.h"
 1126 int main(void)
 1127 {
 1128    extern longlong_t a, b;
 1129    $try_type value = ($try_type) a * ($try_type) b;
 1130    return 0;
 1131 }
 1132 longlong_t a, b;
 1133 !
 1134     if conftest_o ; then
 1135       superulong=$try_type
 1136       break
 1137     fi
 1138   done
 1139 fi
 1140 
 1141 if [ -n "$superulong" ] ; then
 1142   printf '"%s"\n' "$superulong"
 1143 else
 1144   printf "none\n"
 1145 fi
 1146 
 1147 if [ -n "$superlong" -a -n "$superulong" ] ; then
 1148   printf "#define HAVE_SUPERLONG_T 1\n" >> config.h
 1149   printf "typedef $superlong superlong_t;\n" >> config.h
 1150   printf "typedef $superulong superulong_t;\n" >> config.h
 1151 fi
 1152 
 1153 printf "Checking what C integer type can hold a pointer ... "
 1154 
 1155 read_syms()
 1156 {
 1157   print_into_config=${1-} 
 1158   deferred_offset=
 1159 
 1160   while read symbol type offset size ; do
 1161     size=$(( 0$size + 0 ))
 1162     offset=$(( 0$offset + 0 ))
 1163     symbol=${symbol#_}
 1164     case "$type" in
 1165     C )
 1166       size=$(( offset + 0 ))
 1167       ;;
 1168     S )
 1169       if [ -n "$deferred_offset" ] ; then
 1170         size=$(( offset - deferred_offset ))
 1171         case "$deferred_sym" in
 1172         SIZEOF* )
 1173           eval $(printf "%s=%d\n" "$deferred_sym" "$size")
 1174             if [ -n "$print_into_config" ] ; then
 1175               printf "#define %s %s\n" "$deferred_sym" "$size" >> config.h
 1176             fi
 1177           ;;
 1178         esac
 1179       fi
 1180       deferred_sym=$symbol
 1181       deferred_offset=$offset
 1182       continue
 1183       ;;
 1184     esac
 1185     case "$symbol" in
 1186     SIZEOF* )
 1187       eval $(printf "%s=%d\n" "$symbol" "$size")
 1188       if [ -n "$print_into_config" ] ; then
 1189         printf "#define %s %s\n" "$symbol" "$size" >> config.h
 1190       fi
 1191       ;;
 1192     esac
 1193   done < conftest.syms
 1194 }
 1195 
 1196 if [ -z "$intptr" ] ; then
 1197   cat > conftest.c <<!
 1198 #include <stddef.h>
 1199 #include <limits.h>
 1200 #include "config.h"
 1201 char SIZEOF_BYTE[CHAR_BIT];
 1202 #ifdef HAVE_SUPERLONG_T
 1203 char SIZEOF_SUPERLONG_T[sizeof (superlong_t)];
 1204 #endif
 1205 #ifdef HAVE_LONGLONG_T
 1206 char SIZEOF_LONGLONG_T[sizeof (longlong_t)];
 1207 #endif
 1208 char SIZEOF_PTR[sizeof (char *)];
 1209 char SIZEOF_LONG[sizeof (long)];
 1210 char SIZEOF_INT[sizeof (int)];
 1211 char SIZEOF_SHORT[sizeof (short)];
 1212 char SIZEOF_WCHAR_T[sizeof (wchar_t)];
 1213 char DUMMY;
 1214 !
 1215   if ! conftest_syms ; then
 1216     printf "failed\n\n"
 1217 
 1218     printf "Errors from compilation: \n\n"
 1219     cat conftest.err
 1220     exit 1
 1221   fi
 1222 
 1223   SIZEOF_BYTE=0
 1224   SIZEOF_PTR=0
 1225   SIZEOF_SHORT=0
 1226   SIZEOF_INT=0
 1227   SIZEOF_LONG=0
 1228   SIZEOF_LONGLONG_T=0
 1229   SIZEOF_SUPERLONG_T=0
 1230 
 1231   read_syms y
 1232 
 1233   if [ $SIZEOF_PTR -eq 0 -o $SIZEOF_BYTE -eq 0 ] ; then
 1234     printf "failed\n"
 1235     exit 1
 1236   fi
 1237 
 1238   if [ $SIZEOF_PTR -eq $SIZEOF_SHORT ] ; then
 1239     intptr="short"
 1240   elif [ $SIZEOF_PTR -eq $SIZEOF_INT ] ; then
 1241     intptr="int"
 1242   elif [ $SIZEOF_PTR -eq $SIZEOF_LONG ] ; then
 1243     intptr="long"
 1244   elif [ $SIZEOF_PTR -eq $SIZEOF_LONGLONG_T ] ; then
 1245     intptr="longlong_t"
 1246   fi
 1247 
 1248   if [ -z "$intptr" ] ; then
 1249     printf "failed\n"
 1250     exit 1
 1251   fi
 1252 fi
 1253 
 1254 printf '"%s"\n' "$intptr"
 1255 printf "typedef $intptr int_ptr_t;\n" >> config.h
 1256 printf "typedef unsigned $intptr uint_ptr_t;\n" >> config.h
 1257 intptr_max_expr="((((convert(int_ptr_t, 1) << $((SIZEOF_PTR * SIZEOF_BYTE - 2))) - 1) << 1) + 1)"
 1258 printf "#define INT_PTR_MAX %s\n" "$intptr_max_expr" >> config.h
 1259 printf "#define INT_PTR_MIN (-INT_PTR_MAX-1)\n" >> config.h
 1260 printf "#define UINT_PTR_MAX (convert(uint_ptr_t, -1))\n" >> config.h
 1261 double_intptr_max_expr="((((convert(double_intptr_t, 1) << $((2 * SIZEOF_PTR * SIZEOF_BYTE - 2))) - 1) << 1) + 1)"
 1262 printf "#define SIZEOF_DOUBLE_INTPTR (2*SIZEOF_PTR)\n" >> config.h
 1263 printf "#define DOUBLE_INTPTR_MAX %s\n" "$double_intptr_max_expr" >> config.h
 1264 printf "#define DOUBLE_INTPTR_MIN (-DOUBLE_INTPTR_MAX-1)\n" >> config.h
 1265 printf "#define DOUBLE_UINTPTR_MAX (convert(double_uintptr_t, -1))\n" >> config.h
 1266 
 1267 if [ -n "$longlong" ] && [ $SIZEOF_LONGLONG_T -eq $(( 2 * SIZEOF_PTR )) ]
 1268 then
 1269   printf "#define HAVE_DOUBLE_INTPTR_T 1\n" >> config.h
 1270   printf "typedef longlong_t double_intptr_t;\n" >> config.h
 1271   printf "typedef ulonglong_t double_uintptr_t;\n" >> config.h
 1272 elif [ -n "$superlong" ] && [ $SIZEOF_SUPERLONG_T -eq $(( 2 * SIZEOF_PTR )) ]
 1273 then
 1274   printf "#define HAVE_DOUBLE_INTPTR_T 1\n" >> config.h
 1275   printf "typedef superlong_t double_intptr_t;\n" >> config.h
 1276   printf "typedef superulong_t double_uintptr_t;\n" >> config.h
 1277 fi
 1278 
 1279 #if HAVE_LONGLONG_T && 
 1280 
 1281 #
 1282 # Alignment of wchar_t
 1283 #
 1284 # What we really want to know is the alignment of wide string literals
 1285 # like L"wide literal".
 1286 #
 1287 # We make pessimistic assumption that the size of the wchar_t type is this
 1288 # alignment.
 1289 #
 1290 # There is no easy way to get the information without running a compiled
 1291 # program.
 1292 #
 1293 
 1294 printf "Conservatively guessing the alignment of wide literals ... "
 1295 
 1296 if [ -z "$lit_align" ] ; then
 1297   if [ $SIZEOF_WCHAR_T -eq 0 ] ; then
 1298     printf "failed\n"
 1299     exit 1
 1300   fi
 1301 
 1302   if [ -n "$need_darwin_c_source" ] ; then
 1303     lit_align=2
 1304   else
 1305     lit_align=$SIZEOF_WCHAR_T
 1306   fi
 1307 fi
 1308 
 1309 printf "%d\n" "$lit_align"
 1310 printf "#define LIT_ALIGN %d\n" "$lit_align" >> config.h
 1311 
 1312 #
 1313 # Endianness.
 1314 #
 1315 
 1316 printf "Checking target machine endianness ... "
 1317 cat > conftest.c <<!
 1318 #define USPELL(C0, C1, C2, C3) \
 1319   ((unsigned) C0 << 24 | \
 1320    (unsigned) C1 << 16 | \
 1321    (unsigned) C2 << 8 | (unsigned) C3)
 1322 
 1323 unsigned x[6] = {
 1324   0,
 1325   USPELL('L', 'I', 'S', 'P'),
 1326   USPELL('U', 'N', 'I', 'X'),
 1327   USPELL('C', 'O', 'R', 'E'),
 1328   USPELL('D', 'W', 'I', 'M'),
 1329   0
 1330 };
 1331 !
 1332 
 1333 if ! conftest_o ; then
 1334   printf "failed\n";
 1335   exit 1;
 1336 else
 1337   if grep -q 'PSILXINUEROCMIWD' conftest.o ; then
 1338     printf "little\n";
 1339     printf "#define HAVE_LITTLE_ENDIAN 1\n" >> config.h
 1340   elif grep -q 'LISPUNIXCOREDWIM' conftest.o ; then
 1341     printf "big\n";
 1342     printf "#define HAVE_LITTLE_ENDIAN 0\n" >> config.h
 1343   else
 1344     printf "failed\n"
 1345     exit 1
 1346   fi
 1347 fi
 1348 
 1349 #
 1350 # Inline functions
 1351 # 
 1352 
 1353 printf "Checking how to declare inline functions ... "
 1354 
 1355 if [ -z "$inline" ] ; then
 1356   for inline in \
 1357     "inline" "static inline" "extern inline" \
 1358     "__inline__" "static __inline__" "extern __inline__" \
 1359     "static"
 1360   do
 1361     cat > conftest1.c <<!
 1362 $inline int func(void)
 1363 {
 1364   return 0;
 1365 }
 1366 
 1367 int main(void)
 1368 {
 1369   return func();
 1370 }
 1371 !
 1372     cat > conftest2.c <<!
 1373 $inline int func(void)
 1374 {
 1375   return 0;
 1376 }
 1377 !
 1378     rm -f conftest2$exe
 1379     if ! $make conftest2 > conftest.err 2>&1 || ! [ -x conftest2 ] ; then
 1380       continue
 1381     fi
 1382     break
 1383   done
 1384 fi
 1385 
 1386 printf '"%s"\n' "$inline"
 1387 printf "#define INLINE $inline\n" >> config.h
 1388 
 1389 #
 1390 # DBL_DECIMAL_DIG
 1391 #
 1392 
 1393 printf "Checking for DBL_DECIMAL_DIG ... "
 1394 
 1395 for try_sym in DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__ ; do
 1396   cat > conftest.c <<!
 1397 #include <float.h>
 1398 
 1399 #ifndef $try_sym
 1400 #error $try_sym not defined
 1401 #else
 1402 int main(void)
 1403 {
 1404   return 0;
 1405 }
 1406 #endif
 1407 !
 1408   if conftest ; then
 1409     printf "yes (%s)\n" $try_sym
 1410     printf "#define FLO_MAX_DIG $try_sym\n" >> config.h
 1411     have_dbl_decimal_dig=y
 1412   fi
 1413 done
 1414 
 1415 if ! [ $have_dbl_decimal_dig ] ; then
 1416     printf "no\n"
 1417     printf "#define FLO_MAX_DIG (DBL_DIG + 2)\n" >> config.h
 1418 fi
 1419 
 1420 #
 1421 # Rounding mode control.
 1422 #
 1423 
 1424 printf "Checking for fesetround and fegetround ... "
 1425 
 1426 cat > conftest.c <<!
 1427 #include <fenv.h>
 1428 
 1429 int main(void)
 1430 {
 1431   int mode = fegetround();
 1432   fesetround(FE_TONEAREST);
 1433   fesetround(FE_DOWNWARD);
 1434   fesetround(FE_UPWARD);
 1435   fesetround(FE_TOWARDZERO);
 1436   return 0;
 1437 }
 1438 !
 1439 if conftest ; then
 1440   printf "yes\n"
 1441   printf "#define HAVE_ROUNDING_CTL_H 1\n" >> config.h
 1442 else
 1443   printf "no\n"
 1444 fi
 1445 
 1446 printf "Checking for fpclassify ..."
 1447 
 1448 cat > conftest.c <<!
 1449 #include <math.h>
 1450 
 1451 int main(void)
 1452 {
 1453   double x = 3.14;
 1454   switch (fpclassify(x)) {
 1455   case FP_ZERO:
 1456   case FP_NORMAL:
 1457   case FP_SUBNORMAL:
 1458   case FP_INFINITE:
 1459   case FP_NAN:
 1460   default:
 1461     break;
 1462   }
 1463   return 0;
 1464 }
 1465 !
 1466 if conftest ; then
 1467   printf "yes\n"
 1468   printf "#define HAVE_FPCLASSIFY 1\n" >> config.h
 1469 else
 1470   printf "no\n"
 1471 fi
 1472 
 1473 #
 1474 # Valgrind
 1475 #
 1476 
 1477 if [ -n "$valgrind" ] ; then
 1478   printf "Checking valgrind API availability ... "
 1479 
 1480   cat > conftest.c <<!
 1481 #include <valgrind/memcheck.h>
 1482 
 1483 #ifdef VALGRIND_DO_CLIENT_REQUEST
 1484 
 1485 int main(void)
 1486 {
 1487   return 0;
 1488 }
 1489 
 1490 #else
 1491 syntax error
 1492 #endif
 1493 !
 1494   if ! conftest ; then
 1495     printf "failed\n\n"
 1496     printf "Errors from compilation: \n\n"
 1497     cat conftest.err
 1498     exit 1
 1499   fi
 1500 
 1501   printf "okay\n"
 1502   printf "#define HAVE_VALGRIND 1\n" >> config.h
 1503 fi
 1504 
 1505 #
 1506 # Lex and Yacc tests
 1507 #
 1508 
 1509 printf "Checking for lex ... "
 1510 
 1511 if [ -z "$lex_given" -a -z "$lexname_given" ] ; then
 1512   for lexname in '$(LEX)' "lex" "flex" "" ; do
 1513     rm -f lex.yy.c
 1514     if make lexname="$lexname" lex.yy.c > /dev/null 2>&1; then
 1515       break;
 1516     fi
 1517   done
 1518   if [ -z "$lexname" ] ; then
 1519     printf "not found\n"
 1520     exit 1
 1521   fi
 1522 else
 1523   rm -f lex.yy.c
 1524   if ! make lexname="$lexname" lex.yy.c > /dev/null 2>&1; then
 1525     printf "error\n\n"
 1526     printf 'values --lexname="%s" --lex="%s" are not working\n\n' "$lexname" "$lex"
 1527     printf 'A GNU Flex compatible lex is required\n\n'
 1528     exit 1
 1529   fi
 1530 fi
 1531 
 1532 rm -f lex.yy.c
 1533 
 1534 printf '"%s"\n' "$lexname"
 1535 
 1536 printf "Checking for yacc program ... "
 1537 
 1538 if [ -z "$yacc_given" -a -z "$yaccname_given" ] ; then
 1539   rm -f conftest.yacc
 1540   for yaccname in '$(YACC)' "yacc" "byacc" "bison -y" "" ; do
 1541     yaccpath=$($make yaccname="$yaccname" conftest.yacc)
 1542     if command -v $yaccpath > /dev/null ; then
 1543       break;
 1544     fi
 1545   done
 1546 
 1547   if [ -z "$yaccname" ] ; then
 1548     printf "not found\n"
 1549     exit 1
 1550   fi
 1551 
 1552   printf '"%s" (path "%s")\n' "$yaccname" "$yaccpath"
 1553 else
 1554   yaccpath=$($make conftest.yacc)
 1555   case $yaccpath in
 1556   *bison )
 1557     printf "error\n\n"
 1558     printf "GNU Bison needs -y to behave like yacc\n\n"
 1559     printf "This needs to be specified in the --yaccname or --yacc option\n\n"
 1560     exit 1
 1561     ;;
 1562   * )
 1563     if ! command -v $yaccpath > /dev/null ; then
 1564       printf "not found\n\n"
 1565       exit 1
 1566     fi
 1567     printf "given\n"
 1568     ;;
 1569   esac
 1570 fi
 1571 
 1572 #
 1573 # sys/wait.h
 1574 #
 1575 
 1576 printf "Checking whether we have <sys/wait.h> ... "
 1577 
 1578 cat > conftest.c <<!
 1579 #include <sys/wait.h>
 1580 
 1581 int main(void)
 1582 {
 1583   return 0;
 1584 }
 1585 !
 1586 if conftest ; then
 1587   printf "yes\n"
 1588   printf "#define HAVE_SYS_WAIT 1\n" >> config.h
 1589 else
 1590   printf "no\n"
 1591 fi
 1592 
 1593 #
 1594 # sys/stat.h
 1595 #
 1596 
 1597 printf "Checking whether we have <sys/stat.h> ... "
 1598 
 1599 cat > conftest.c <<!
 1600 #include <sys/stat.h>
 1601 
 1602 struct stat s;
 1603 
 1604 int main(void)
 1605 {
 1606   return 0;
 1607 }
 1608 !
 1609 if conftest ; then
 1610   printf "yes\n"
 1611   printf "#define HAVE_SYS_STAT 1\n" >> config.h
 1612 else
 1613   printf "no\n"
 1614 fi
 1615 
 1616 
 1617 #
 1618 # environ
 1619 #
 1620 
 1621 printf "Checking whether we have environ ... "
 1622 
 1623 cat > conftest.c <<!
 1624 #include <stdio.h>
 1625 
 1626 int main(void)
 1627 {
 1628   extern char **environ;
 1629   puts(environ[0]);
 1630   return 0;
 1631 }
 1632 !
 1633 if conftest ; then
 1634   printf "yes\n"
 1635   printf "#define HAVE_ENVIRON 1\n" >> config.h
 1636 else
 1637   printf "no\n"
 1638 fi
 1639 
 1640 #
 1641 # GetEnvironmentStrings
 1642 #
 1643 
 1644 printf "Checking whether we have GetEnvironmentStrings ... "
 1645 
 1646 cat > conftest.c <<!
 1647 #include <windows.h>
 1648 
 1649 int main(void)
 1650 {
 1651   WCHAR *ptr = GetEnvironmentStringsW();
 1652   return 0;
 1653 }
 1654 !
 1655 if conftest ; then
 1656   printf "yes\n"
 1657   printf "#define HAVE_GETENVIRONMENTSTRINGS 1\n" >> config.h
 1658   have_windows_h=y
 1659 else
 1660   printf "no\n"
 1661 fi
 1662 
 1663 #
 1664 # fork, pipe, exec, waitpid.
 1665 #
 1666 
 1667 printf "Checking for POSIX fork/pipe/exec/waitpid ... "
 1668 
 1669 cat > conftest.c <<!
 1670 #include "config.h"
 1671 #ifdef HAVE_SYS_WAIT
 1672 #include <sys/wait.h>
 1673 #endif
 1674 #include <sys/types.h>
 1675 #include <unistd.h>
 1676 
 1677 int main(int argc, char **argv)
 1678 {
 1679   int status, fd[2];
 1680   pid_t p = fork();
 1681   int res = pipe(fd);
 1682   (void) execvp(argv[0], argv);
 1683   (void) waitpid(p, &status, 0);
 1684   (void) res;
 1685   return 0;
 1686 }
 1687 !
 1688 
 1689 if conftest ; then
 1690   printf "yes\n"
 1691   printf "#define HAVE_FORK_STUFF 1\n" >> config.h
 1692   have_unistd=y
 1693   have_sys_types=y
 1694 else
 1695   printf "no\n"
 1696 fi
 1697 
 1698 printf "Checking for POSIX getppid ... "
 1699 
 1700 cat > conftest.c <<!
 1701 #include <sys/types.h>
 1702 #include <unistd.h>
 1703 
 1704 int main(int argc, char **argv)
 1705 {
 1706   pid_t p = getppid();
 1707   return 0;
 1708 }
 1709 !
 1710 
 1711 if conftest ; then
 1712   printf "yes\n"
 1713   printf "#define HAVE_GETPPID 1\n" >> config.h
 1714   have_unistd=y
 1715   have_sys_types=y
 1716 else
 1717   printf "no\n"
 1718 fi
 1719 
 1720 #
 1721 # fcntl
 1722 #
 1723 
 1724 printf "Checking for POSIX fcntl ... "
 1725 
 1726 cat > conftest.c <<!
 1727 #include "config.h"
 1728 #include <fcntl.h>
 1729 
 1730 int main(int argc, char **argv)
 1731 {
 1732   int err = fcntl(0, F_SETFD, FD_CLOEXEC);
 1733   return 0;
 1734 }
 1735 !
 1736 
 1737 if conftest ; then
 1738   printf "yes\n"
 1739   printf "#define HAVE_FCNTL 1\n" >> config.h
 1740 else
 1741   printf "no\n"
 1742 fi
 1743 
 1744 #
 1745 # poll
 1746 #
 1747 
 1748 printf "Checking for poll ... "
 1749 
 1750 cat > conftest.c <<!
 1751 #include <poll.h>
 1752 #include "config.h"
 1753 
 1754 int main(int argc, char **argv)
 1755 {
 1756   static struct pollfd fds[42];
 1757   nfds_t n = 42;
 1758   int err = poll(fds, 42, 1000);
 1759   return 0;
 1760 }
 1761 !
 1762 
 1763 if conftest ; then
 1764   printf "yes\n"
 1765   printf "#define HAVE_POLL 1\n" >> config.h
 1766 else
 1767   printf "no\n"
 1768 fi
 1769 
 1770 #
 1771 # Check for fields inside struct tm
 1772 #
 1773 
 1774 printf "detecting timezone fields in struct tm ... "
 1775 
 1776 for try_field in tm_gmtoff __tm_gmtoff ; do
 1777   cat > conftest.c <<!
 1778 #include <time.h>
 1779 int x = sizeof ((struct tm *) 0)->$try_field;
 1780 !
 1781   if conftest_o ; then
 1782     printf "#define HAVE_TM_GMTOFF 1\n" >> config.h
 1783     printf "#define TM_GMTOFF %s\n" $try_field >> config.h
 1784     break
 1785   fi
 1786 done
 1787 
 1788 for try_field in tm_zone __tm_zone ; do
 1789   cat > conftest.c <<!
 1790 #include <time.h>
 1791 int x = sizeof ((struct tm *) 0)->$try_field;
 1792 !
 1793   if conftest_o ; then
 1794     printf "#define HAVE_TM_ZONE 1\n" >> config.h
 1795     printf "#define TM_ZONE %s\n" $try_field >> config.h
 1796     break
 1797   fi
 1798 done
 1799 
 1800 printf "done\n"
 1801 
 1802 printf "Checking for timegm function ... "
 1803 
 1804 cat > conftest.c <<!
 1805 #include <time.h>
 1806 
 1807 int main(void)
 1808 {
 1809   time_t (*ptgm)(struct tm *) = &timegm;
 1810   return 0;
 1811 }
 1812 !
 1813 if conftest ; then
 1814   printf "yes\n"
 1815   printf "#define HAVE_TIMEGM 1\n" >> config.h
 1816 else
 1817   printf "no\n"
 1818 fi
 1819 
 1820 printf "Checking for setenv and unsetenv functions ... "
 1821 
 1822 cat > conftest.c <<!
 1823 #include <stdlib.h>
 1824 
 1825 int main(void)
 1826 {
 1827   setenv("TERM", "foo", 1);
 1828   unsetenv("TERM");
 1829   return 0;
 1830 }
 1831 !
 1832 if conftest ; then
 1833   printf "yes\n"
 1834   printf "#define HAVE_SETENV 1\n" >> config.h
 1835 else
 1836   printf "no\n"
 1837 fi
 1838 printf "Checking for tzset function ... "
 1839 
 1840 cat > conftest.c <<!
 1841 #include <time.h>
 1842 
 1843 int main(void)
 1844 {
 1845   tzset();
 1846   return 0;
 1847 }
 1848 !
 1849 if conftest ; then
 1850   printf "yes\n"
 1851   printf "#define HAVE_TZSET 1\n" >> config.h
 1852 else
 1853   printf "no\n"
 1854 fi
 1855 
 1856 printf "Checking for localtime_r and gmtime_r functions ... "
 1857 
 1858 cat > conftest.c <<!
 1859 #include <time.h>
 1860 
 1861 int main(int argc, char **argv)
 1862 {
 1863   struct tm stm;
 1864   time_t t;
 1865 
 1866   localtime_r(&t, &stm);
 1867   gmtime_r(&t, &stm);
 1868   return 0;
 1869 }
 1870 !
 1871 if conftest ; then
 1872   printf "yes\n"
 1873   printf "#define HAVE_GMTIME_R 1\n" >> config.h
 1874   have_unistd=y
 1875 else
 1876   printf "no\n"
 1877 fi
 1878 
 1879 printf "Checking for strptime function ... "
 1880 
 1881 cat > conftest.c <<!
 1882 #include <time.h>
 1883 
 1884 int main(int argc, char **argv)
 1885 {
 1886   struct tm stm = { 0 };
 1887   strptime("2016-08-20 00:00:00", "%Y-%m-%d %H:%M:%S", &stm);
 1888   return 0;
 1889 }
 1890 !
 1891 if conftest ; then
 1892   printf "yes\n"
 1893   printf "#define HAVE_STRPTIME 1\n" >> config.h
 1894 else
 1895   printf "no\n"
 1896 fi
 1897 
 1898 printf "Checking for POSIX sleep function ... "
 1899 
 1900 cat > conftest.c <<!
 1901 #include <unistd.h>
 1902 
 1903 int main(int argc, char **argv)
 1904 {
 1905   sleep(42);
 1906   return 0;
 1907 }
 1908 !
 1909 if conftest ; then
 1910   printf "yes\n"
 1911   printf "#define HAVE_POSIX_SLEEP 1\n" >> config.h
 1912   have_unistd=y
 1913 else
 1914   printf "no\n"
 1915 fi
 1916 
 1917 printf "Checking for POSIX usleep function ... "
 1918 
 1919 cat > conftest.c <<!
 1920 #include <unistd.h>
 1921 
 1922 int main(int argc, char **argv)
 1923 {
 1924   usleep(42);
 1925   return 0;
 1926 }
 1927 !
 1928 if conftest ; then
 1929   printf "yes\n"
 1930   printf "#define HAVE_POSIX_USLEEP 1\n" >> config.h
 1931   have_unistd=y
 1932 else
 1933   printf "no\n"
 1934 fi
 1935 
 1936 printf "Checking for POSIX nanosleep function ... "
 1937 
 1938 cat > conftest.c <<!
 1939 #include <time.h>
 1940 
 1941 int main(int argc, char **argv)
 1942 {
 1943   struct timespec ts;
 1944   nanosleep(&ts, &ts);
 1945   return 0;
 1946 }
 1947 !
 1948 if conftest ; then
 1949   printf "yes\n"
 1950   printf "#define HAVE_POSIX_NANOSLEEP 1\n" >> config.h
 1951   have_unistd=y
 1952 else
 1953   printf "no\n"
 1954 fi
 1955 
 1956 printf "Checking for BSD daemon function ... "
 1957 
 1958 cat > conftest.c <<!
 1959 #include <stdlib.h>
 1960 #include <unistd.h>
 1961 
 1962 int main(int argc, char **argv)
 1963 {
 1964   int (*pdaemon)(int, int) = &daemon;
 1965 }
 1966 !
 1967 if conftest ; then
 1968   printf "yes\n"
 1969   printf "#define HAVE_DAEMON 1\n" >> config.h
 1970   have_unistd=y
 1971 else
 1972   printf "no\n"
 1973 fi
 1974 
 1975 printf "Checking for isatty function ... "
 1976 
 1977 cat > conftest.c <<!
 1978 #include <unistd.h>
 1979 
 1980 int main(void)
 1981 {
 1982   isatty(0);
 1983   return 0;
 1984 }
 1985 !
 1986 if conftest ; then
 1987   printf "yes\n"
 1988   printf "#define HAVE_ISATTY 1\n" >> config.h
 1989   have_unistd=y
 1990 else
 1991   printf "no\n"
 1992 fi
 1993 
 1994 printf "Checking for syslog ... "
 1995 
 1996 cat > conftest.c <<!
 1997 #include <syslog.h>
 1998 
 1999 int main(void)
 2000 {
 2001   openlog("foo", LOG_CONS, LOG_DAEMON);
 2002   syslog(LOG_EMERG, "bar %d\n", 3);
 2003   setlogmask(0);
 2004   closelog();
 2005   return 0;
 2006 }
 2007 !
 2008 if conftest ; then
 2009   printf "yes\n"
 2010   printf "#define HAVE_SYSLOG 1\n" >> config.h
 2011   have_syslog=y
 2012 else
 2013   printf "no\n"
 2014 fi
 2015 
 2016 printf "Checking for reasonably modern POSIX signal handling ... "
 2017 
 2018 cat > conftest.c <<!
 2019 #include <signal.h>
 2020 #include <setjmp.h>
 2021 
 2022 int main(void)
 2023 {
 2024   sigjmp_buf jb;
 2025   static struct sigaction olda, newa;
 2026   static sigset_t olds, news;
 2027   sigaction(0, &newa, &olda);
 2028   sigprocmask(SIG_BLOCK, &news, &olds);
 2029   if (!sigsetjmp(jb, 1)) 
 2030     siglongjmp(jb, 1);
 2031   return 0;
 2032 }
 2033 !
 2034 if conftest ; then
 2035   printf "yes\n"
 2036   printf "#define HAVE_POSIX_SIGS 1\n" >> config.h
 2037   have_posix_sigs=y
 2038 else
 2039   printf "no\n"
 2040 fi
 2041 
 2042 printf "Checking for sigaltstack ... "
 2043 
 2044 cat > conftest.c <<!
 2045 #include <signal.h>
 2046 #include <stdlib.h>
 2047 
 2048 int main(void)
 2049 {
 2050   stack_t ss;
 2051   ss.ss_sp = malloc(SIGSTKSZ);
 2052   ss.ss_size = SIGSTKSZ;
 2053   ss.ss_flags = 0;
 2054   return sigaltstack(&ss, 0);
 2055 }
 2056 !
 2057 if conftest ; then
 2058   printf "yes\n"
 2059   printf "#define HAVE_SIGALTSTACK 1\n" >> config.h
 2060 else
 2061   printf "no\n"
 2062 fi
 2063 
 2064 printf "Checking for setitimer/getitimer ... "
 2065 
 2066 cat > conftest.c <<!
 2067 #include <sys/time.h>
 2068 
 2069 int main(void)
 2070 {
 2071   struct itimerval itv, itv2;
 2072   int err;
 2073   err = getitimer(ITIMER_REAL, &itv);
 2074   err = getitimer(ITIMER_VIRTUAL, &itv);
 2075   err = setitimer(ITIMER_VIRTUAL, &itv, &itv2);
 2076   return 0;
 2077 }
 2078 !
 2079 if conftest ; then
 2080   printf "yes\n"
 2081   printf "#define HAVE_ITIMER 1\n" >> config.h
 2082   have_sys_time=y
 2083 else
 2084   printf "no\n"
 2085 fi
 2086 
 2087 printf "Checking for makedev ... "
 2088 
 2089 for try_header in sysmacros types ; do
 2090   cat > conftest.c <<!
 2091 #include <sys/${try_header}.h>
 2092 
 2093 int main(void)
 2094 {
 2095   int d = makedev(1, 2);
 2096   int j = major(d);
 2097   int n = minor(d);
 2098   return 0;
 2099 }
 2100 !
 2101   if conftest ; then
 2102     printf "yes\n"
 2103     printf "#define HAVE_MAKEDEV 1\n" >> config.h
 2104     case $try_header in
 2105     sysmacros )
 2106       printf "#define HAVE_SYS_SYSMACROS_H 1\n" >> config.h
 2107       ;;
 2108     types )
 2109       have_sys_types=y
 2110       ;;
 2111     esac
 2112     have_makedev=y
 2113     break
 2114   fi
 2115 done
 2116 
 2117 if [ -z "$have_makedev" ] ; then
 2118   printf "no\n"
 2119 fi
 2120 
 2121 printf "Checking for link, symlink and readlink ... "
 2122 
 2123 cat > conftest.c <<!
 2124 #include <unistd.h>
 2125 
 2126 int main(void)
 2127 {
 2128   int e1 = symlink("a", "b");
 2129   int e2 = link("c", "d");
 2130   char buf[256];
 2131   ssize_t foo = readlink("e", buf, sizeof buf);
 2132   return 0;
 2133 }
 2134 !
 2135 if conftest ; then
 2136   printf "yes\n"
 2137   printf "#define HAVE_SYMLINK 1\n" >> config.h
 2138   have_unistd=y
 2139 else
 2140   printf "no\n"
 2141 fi
 2142 
 2143 printf "Checking for POSIX mkdir ... "
 2144 
 2145 cat > conftest.c <<!
 2146 #include "config.h"
 2147 #include <sys/stat.h>
 2148 #if HAVE_WINDOWS_H
 2149 #include <windows.h>
 2150 #endif
 2151 
 2152 int main(void)
 2153 {
 2154   int e = mkdir("a", 0);
 2155   return 0;
 2156 }
 2157 !
 2158 if conftest ; then
 2159   printf "yes\n"
 2160   printf "#define HAVE_MKDIR 1\n" >> config.h
 2161 else
 2162   printf "no\n"
 2163 fi
 2164 
 2165 printf "Checking for mknod ... "
 2166 
 2167 cat > conftest.c <<!
 2168 #include "config.h"
 2169 #include <unistd.h>
 2170 #if HAVE_SYS_STAT
 2171 #include <sys/stat.h>
 2172 #endif
 2173 
 2174 int main(void)
 2175 {
 2176   int e = mknod("a", 0, 0);
 2177   return 0;
 2178 }
 2179 !
 2180 if conftest ; then
 2181   printf "yes\n"
 2182   printf "#define HAVE_MKNOD 1\n" >> config.h
 2183   have_unistd=y
 2184 else
 2185   printf "no\n"
 2186 fi
 2187 
 2188 printf "Checking for chmod ... "
 2189 cat > conftest.c <<!
 2190 #include <sys/stat.h>
 2191 
 2192 int main(void)
 2193 {
 2194   int r = chmod("a", S_IWUSR);
 2195   return 0;
 2196 }
 2197 !
 2198 if conftest ; then
 2199   printf "yes\n"
 2200   printf "#define HAVE_CHMOD 1\n" >> config.h
 2201 else
 2202   printf "no\n"
 2203 fi
 2204 
 2205 printf "Checking for pipe ... "
 2206 cat > conftest.c <<!
 2207 #include <unistd.h>
 2208 
 2209 int main(void)
 2210 {
 2211   int p[2];
 2212   int r = pipe(p);
 2213   return 0;
 2214 }
 2215 !
 2216 if conftest ; then
 2217   printf "yes\n"
 2218   printf "#define HAVE_PIPE 1\n" >> config.h
 2219 else
 2220   printf "no\n"
 2221 fi
 2222 
 2223 printf "Checking for ftruncate ... "
 2224 cat > conftest.c <<!
 2225 #include <unistd.h>
 2226 
 2227 int main(void)
 2228 {
 2229   int e = ftruncate(0, 42);
 2230   return 0;
 2231 }
 2232 !
 2233 if conftest ; then
 2234   printf "yes\n"
 2235   printf "#define HAVE_FTRUNCATE 1\n" >> config.h
 2236 else
 2237   printf "no\n"
 2238 fi
 2239 
 2240 printf "Checking for _wspawnlp ... "
 2241 
 2242 cat > conftest.c <<!
 2243 #include "config.h"
 2244 #include <process.h>
 2245 #include <wchar.h>
 2246 
 2247 int main(int argc, char **argv)
 2248 {
 2249   wchar_t *wargv[] = { L"foo", L"bar", 0 };
 2250   int r = _wspawnlp(_P_WAIT, L"foo", wargv);
 2251   return 0;
 2252 }
 2253 !
 2254 if conftest ; then
 2255   printf "yes\n"
 2256   printf "#define HAVE_WSPAWN 1\n" >> config.h
 2257 else
 2258   printf "no\n"
 2259 fi
 2260 
 2261 printf "Checking for chsize ... "
 2262 cat > conftest.c <<!
 2263 #include <unistd.h>
 2264 
 2265 int main(void)
 2266 {
 2267   int e = chsize(0, 42);
 2268   return 0;
 2269 }
 2270 !
 2271 if conftest ; then
 2272   printf "yes\n"
 2273   printf "#define HAVE_CHSIZE 1\n" >> config.h
 2274 else
 2275   printf "no\n"
 2276 fi
 2277 
 2278 
 2279 printf "Checking for log2 ... "
 2280 
 2281 cat > conftest.c <<!
 2282 #include <math.h>
 2283 
 2284 int main(void)
 2285 {
 2286   double x = log2(42.0);
 2287   return 0;
 2288 }
 2289 !
 2290 if conftest ; then
 2291   printf "yes\n"
 2292   printf "#define HAVE_LOG2 1\n" >> config.h
 2293 else
 2294   printf "no\n"
 2295 fi
 2296 
 2297 printf "Checking for round ... "
 2298 cat > conftest.c <<!
 2299 #include <math.h>
 2300 
 2301 int main(void)
 2302 {
 2303   double x = round(0.5);
 2304   return 0;
 2305 }
 2306 !
 2307 if conftest ; then
 2308   printf "yes\n"
 2309   printf "#define HAVE_ROUND 1\n" >> config.h
 2310 else
 2311   printf "no\n"
 2312 fi
 2313 
 2314 
 2315 
 2316 printf "Checking for glob ... "
 2317 
 2318 cat > conftest.c <<!
 2319 #include <glob.h>
 2320 
 2321 static int errfunc(const char *path, int err)
 2322 {
 2323   return 0;
 2324 }
 2325 
 2326 int main(void)
 2327 {
 2328   glob_t gl;
 2329   int result = glob("*", GLOB_ERR, errfunc, &gl);
 2330   globfree(&gl);
 2331   return result;
 2332 }
 2333 !
 2334 if conftest ; then
 2335   printf "yes\n"
 2336   printf "#define HAVE_GLOB 1\n" >> config.h
 2337   have_glob=y
 2338 else
 2339   printf "no\n"
 2340 fi
 2341 
 2342 printf "Checking for nftw ... "
 2343 
 2344 cat > conftest.c <<!
 2345 #include <ftw.h>
 2346 #include <stdlib.h>
 2347 
 2348 static int callback(const char *fpath, const struct stat *sb,
 2349                     int tflag, struct FTW *ftwbuf)
 2350 {
 2351    switch (tflag) {
 2352    case FTW_D:
 2353    case FTW_DP:
 2354    case FTW_NS:
 2355    case FTW_SLN:
 2356      break;
 2357    }
 2358    return 0;
 2359 }
 2360 
 2361 int main(int argc, char *argv[])
 2362 {
 2363    int flags = FTW_DEPTH | FTW_PHYS;
 2364    int res = nftw(argv[1], callback, 20, flags);
 2365    return (res == -1) ? EXIT_FAILURE : 0;
 2366 }
 2367 !
 2368 
 2369 if conftest ; then
 2370   printf "yes\n"
 2371   printf "#define HAVE_FTW 1\n" >> config.h
 2372   have_ftw=y
 2373 else
 2374   printf "no\n"
 2375 fi
 2376 
 2377 printf "Checking for fnmatch ... "
 2378 
 2379 cat > conftest.c <<!
 2380 #include <fnmatch.h>
 2381 
 2382 int main(int argc, char *argv[])
 2383 {
 2384   int res = fnmatch("*.txr", "foo.txr", FNM_PATHNAME);
 2385   return 0;
 2386 }
 2387 !
 2388 
 2389 if conftest ; then
 2390   printf "yes\n"
 2391   printf "#define HAVE_FNMATCH 1\n" >> config.h
 2392   have_ftw=y
 2393 else
 2394   printf "no\n"
 2395 fi
 2396 
 2397 printf "Checking for windres ... "
 2398 
 2399 if output=$(windres -V 2> /dev/null) ; then
 2400   printf "yes\n"
 2401   have_windres=y
 2402 else
 2403   printf "no\n"
 2404 fi
 2405 
 2406 printf "Checking for POSIX geteuid function family ... "
 2407 
 2408 cat > conftest.c <<!
 2409 #include <sys/types.h>
 2410 #include <unistd.h>
 2411 
 2412 int main(int argc, char **argv)
 2413 {
 2414   uid_t u = getuid();
 2415   uid_t e = geteuid();
 2416   gid_t g = getgid();
 2417   gid_t h = getegid();
 2418   setuid(u);
 2419   seteuid(e);
 2420   setgid(g);
 2421   setegid(h);
 2422   getgroups(0, NULL);
 2423   return 0;
 2424 }
 2425 !
 2426 
 2427 if conftest ; then
 2428   printf "yes\n"
 2429   printf "#define HAVE_GETEUID 1\n" >> config.h
 2430   have_unistd=y
 2431   have_sys_types=y
 2432 else
 2433   printf "no\n"
 2434 fi
 2435 
 2436 printf "Checking for {set,get}res{uid,gid} ... "
 2437 
 2438 cat > conftest.c <<!
 2439 #include <sys/types.h>
 2440 #include <unistd.h>
 2441 
 2442 int main(int argc, char **argv)
 2443 {
 2444   uid_t ur, ue, us;
 2445   gid_t gr, ge, gs;
 2446   int gur = getresuid(&ur, &ue, &us);
 2447   int ggr = getresgid(&gr, &ge, &gs);
 2448   int sur = setresuid(0, 0, 0);
 2449   int sgr = setresgid(0, 0, 0);
 2450   return 0;
 2451 }
 2452 !
 2453 
 2454 if conftest ; then
 2455   printf "yes\n"
 2456   printf "#define HAVE_SETRESUID 1\n" >> config.h
 2457   have_unistd=y
 2458   have_sys_types=y
 2459 else
 2460   printf "no\n"
 2461 fi
 2462 
 2463 printf "Checking for setgroups ... "
 2464 
 2465 cat > conftest.c <<!
 2466 #include <sys/types.h>
 2467 #include <unistd.h>
 2468 #include <grp.h>
 2469 
 2470 int main(int argc, char **argv)
 2471 {
 2472   int res = setgroups(0, 0);
 2473   return 0;
 2474 }
 2475 !
 2476 
 2477 if conftest ; then
 2478   printf "yes\n"
 2479   printf "#define HAVE_SETGROUPS 1\n" >> config.h
 2480   have_unistd=y
 2481 elif conftest EXTRA_FLAGS=-D__EXTENSIONS__=1 ; then
 2482   printf "yes\n"
 2483   printf "#define HAVE_SETGROUPS 1\n" >> config.h
 2484   lang_flags="$lang_flags -D__EXTENSIONS__=1" # Solaris buggery
 2485   have_unistd=y
 2486   have_sys_types=y
 2487 else
 2488   printf "no\n"
 2489 fi
 2490 
 2491 printf "Checking for old school getpwent, getpwuid and getpwnam ... "
 2492 
 2493 cat > conftest.c <<!
 2494 #include <sys/types.h>
 2495 #include <pwd.h>
 2496 
 2497 int main(void)
 2498 {
 2499   struct passwd *p = getpwent();
 2500   struct passwd *q = getpwnam("root");
 2501   struct passwd *r = getpwuid(0);
 2502   setpwent();
 2503   endpwent();
 2504   return 0;
 2505 }
 2506 !
 2507 
 2508 if conftest ; then
 2509   printf "yes\n"
 2510   printf "#define HAVE_PWUID 1\n" >> config.h
 2511   have_pwuid=y
 2512   have_sys_types=y
 2513 else
 2514   printf "no\n"
 2515 fi
 2516 
 2517 if [ "$have_pwuid" ]; then
 2518   printf "Checking for getpwent_r, getpwuid_r, and getpwnam_r ... "
 2519 
 2520   cat > conftest.c <<!
 2521 #include <sys/types.h>
 2522 #include <pwd.h>
 2523 
 2524 int main(void)
 2525 {
 2526   struct passwd pw;
 2527   struct passwd *p;
 2528   char buf[1024];
 2529   int r0 = getpwent_r(&pw, buf, sizeof buf, &p);
 2530   int r1 = getpwuid_r(0, &pw, buf, sizeof buf, &p);
 2531   int r2 = getpwnam_r("root", &pw, buf, sizeof buf, &p);
 2532   return 0;
 2533 }
 2534 !
 2535 
 2536   if conftest ; then
 2537     printf "yes\n"
 2538     printf "#define HAVE_PWUID_R 1\n" >> config.h
 2539   else
 2540     printf "no\n"
 2541   fi
 2542 fi
 2543 
 2544 printf "Checking for old school getgrent, getgrgid and getgrnam ... "
 2545 
 2546 cat > conftest.c <<!
 2547 #include <sys/types.h>
 2548 #include <grp.h>
 2549 
 2550 int main(void)
 2551 {
 2552   struct group *g = getgrent();
 2553   struct group *h = getgrnam("root");
 2554   struct group *i = getgrgid(0);
 2555   setgrent();
 2556   endgrent();
 2557   return 0;
 2558 }
 2559 !
 2560 
 2561 if conftest ; then
 2562   printf "yes\n"
 2563   printf "#define HAVE_GRGID 1\n" >> config.h
 2564   have_grgid=y
 2565 else
 2566   printf "no\n"
 2567 fi
 2568 
 2569 if [ "$have_grgid" ]; then
 2570   printf "Checking for getgrgid_r and getgrnam_r ... "
 2571 
 2572   cat > conftest.c <<!
 2573 #include <sys/types.h>
 2574 #include <grp.h>
 2575 
 2576 int main(void)
 2577 {
 2578   struct group gr;
 2579   struct group *g;
 2580   char buf[1024];
 2581   int r1 = getgrgid_r(0, &gr, buf, sizeof buf, &g);
 2582   int r2 = getgrnam_r("root", &gr, buf, sizeof buf, &g);
 2583   return 0;
 2584 }
 2585 !
 2586 
 2587   if conftest ; then
 2588     printf "yes\n"
 2589     printf "#define HAVE_GRGID_R 1\n" >> config.h
 2590   else
 2591     printf "no\n"
 2592   fi
 2593 fi
 2594 
 2595 printf "Checking for crypt ... "
 2596 
 2597 cat > conftest.c <<!
 2598 #include <unistd.h>
 2599 
 2600 int main(void)
 2601 {
 2602   char *c = crypt("foo", "bar");
 2603   return 0;
 2604 }
 2605 !
 2606 
 2607 for try_lcrypt in "" "-lcrypt" "no" ; do
 2608   if [ "$try_lcrypt" = "no" ] ; then
 2609     printf "no\n"
 2610     break
 2611   fi
 2612   if conftest EXTRA_LDFLAGS=$try_lcrypt; then
 2613     printf "yes\n"
 2614     printf "#define HAVE_CRYPT 1\n" >> config.h
 2615     if [ -n "$try_lcrypt" ] ; then
 2616       conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lcrypt"
 2617     fi
 2618     break;
 2619   fi
 2620 done
 2621 
 2622 printf "Checking for alloca ... "
 2623 
 2624 for try_header in stdlib alloca malloc ; do
 2625   cat > conftest.c <<!
 2626 #include <$try_header.h>
 2627 
 2628 int main(int argc, char **argv)
 2629 {
 2630   void *bytes = alloca(42);
 2631   return 0;
 2632 }
 2633 !
 2634 
 2635   if conftest ; then
 2636     printf "yes\n"
 2637     printf "#define HAVE_ALLOCA_%s 1\n" $try_header >> config.h
 2638     have_alloca=y
 2639     break;
 2640   fi
 2641 done
 2642 
 2643 if [ -z "$have_alloca" ] ; then
 2644   printf "no\n"
 2645   printf "TXR requires the alloca function.\n"
 2646   exit 1
 2647 fi
 2648 
 2649 printf "Checking for termios ... "
 2650 
 2651 cat > conftest.c <<!
 2652 #include <termios.h>
 2653 
 2654 int main(int argc, char **argv)
 2655 {
 2656   struct termios t;
 2657   return 0;
 2658 }
 2659 !
 2660 
 2661 if conftest ; then
 2662   printf "yes\n"
 2663   printf "#define HAVE_TERMIOS 1\n" >> config.h
 2664   have_termios=y
 2665 else
 2666   printf "no\n"
 2667 fi
 2668 
 2669 printf "Checking for struct winsize ... "
 2670 
 2671 for termios_define in NOTHING __EXTENSIONS__ ; do
 2672   cat > conftest.c <<!
 2673 #define $termios_define
 2674 #include <sys/ioctl.h>
 2675 #include <termios.h>
 2676 
 2677 int main(int argc, char **argv)
 2678 {
 2679   struct winsize ws;
 2680   return 0;
 2681 }
 2682 !
 2683   if conftest ; then
 2684     printf "yes\n"
 2685     printf "#define HAVE_WINSIZE 1\n" >> config.h
 2686     have_winsize=y
 2687     break;
 2688   fi
 2689 done
 2690 
 2691 if [ -z "$have_winsize" ] ; then
 2692   printf "no\n"
 2693 fi
 2694 
 2695 printf "Checking for mkstemps ... "
 2696 
 2697 cat > conftest.c <<!
 2698 #include <stdlib.h>
 2699 
 2700 int main(int argc, char **argv)
 2701 {
 2702   char templ[] = "abcXXXXXX.xyz";
 2703   int fd = mkstemps(templ, 4);
 2704   return 0;
 2705 }
 2706 !
 2707 
 2708 if conftest ; then
 2709   printf "yes\n"
 2710   printf "#define HAVE_MKSTEMPS 1\n" >> config.h
 2711 else
 2712   printf "no\n"
 2713 fi
 2714 
 2715 #
 2716 # Low stack size on Windows fails the man or boy test case.
 2717 #
 2718 
 2719 printf "Do we need to set stack size ... "
 2720 
 2721 if uname -a | grep -q -E 'MINGW|CYGWIN' ; then
 2722   conf_ldflags="-Wl,--stack,16777216${conf_ldflags:+" $conf_ldflags"}"
 2723   printf "yes\n"
 2724 else
 2725   printf "no\n"
 2726 fi
 2727 
 2728 #
 2729 # Do we have fseeko and ftello?
 2730 #
 2731 
 2732 printf "Checking for fseeko and ftello ... "
 2733 
 2734 cat > conftest.c <<!
 2735 #include <stdio.h>
 2736 #include <sys/types.h>
 2737 
 2738 int main(int argc, char **argv)
 2739 {
 2740   int res = fseeko(stdin, 0, SEEK_CUR);
 2741   off_t pos = ftello(stdin);
 2742   return 0;
 2743 }
 2744 !
 2745 
 2746 if conftest ; then
 2747   printf "yes\n"
 2748   printf "#define HAVE_FSEEKO 1\n" >> config.h
 2749   have_sys_types=y
 2750 elif conftest EXTRA_FLAGS=-D_LARGEFILE_SOURCE ; then
 2751   printf "yes\n"
 2752   printf "#define HAVE_FSEEKO 1\n" >> config.h
 2753   lang_flags="$lang_flags -D_LARGEFILE_SOURCE"
 2754   have_sys_types=y
 2755 else
 2756   printf "no\n"
 2757 fi
 2758 
 2759 printf "Checking how to enable 64 bit file offsets ... "
 2760 
 2761 file_offset_define=none
 2762 
 2763 for try in NOTHING _LARGE_FILES=1 _FILE_OFFSET_BITS=64 ; do
 2764   cat > conftest.c <<!
 2765 #include <limits.h>
 2766 #include <sys/types.h>
 2767 char SIZEOF_BYTE[CHAR_BIT];
 2768 char SIZEOF_OFF_T[sizeof (off_t)];
 2769 char DUMMY;
 2770 !
 2771   if ! conftest_syms VERBOSE=y EXTRA_FLAGS=-D$try ; then
 2772     printf "failed\n\n"
 2773 
 2774     printf "Errors from compilation: \n\n"
 2775     cat conftest.err
 2776     exit 1
 2777   fi
 2778 
 2779   SIZEOF_BYTE=0
 2780   SIZEOF_OFF_T=0
 2781 
 2782   read_syms
 2783 
 2784   if [ $SIZEOF_OFF_T -eq 0 -o $SIZEOF_BYTE -eq 0 ] ; then
 2785     printf "failed\n"
 2786     exit 1
 2787   fi
 2788 
 2789   if [ $(( SIZEOF_BYTE * SIZEOF_OFF_T )) -eq 64 ] ; then
 2790     if [ $try = NOTHING ] ; then
 2791       printf "default\n"
 2792       file_offset_define=
 2793     else
 2794       printf -- "-D%s\n" $try
 2795       file_offset_define=$try
 2796     fi
 2797     break;
 2798   fi
 2799 done
 2800 
 2801 if [ "$file_offset_define" = none ] ; then
 2802   printf "unable\n"
 2803 elif [ -n "$file_offset_define" ] ; then
 2804   lang_flags="$lang_flags -D$file_offset_define"
 2805 fi
 2806 
 2807 printf "Checking for socket API ... "
 2808 
 2809 cat > conftest.c <<!
 2810 #include <sys/types.h>
 2811 #include <sys/socket.h>
 2812 #include <netinet/in.h>
 2813 #include <arpa/inet.h>
 2814 #include <sys/un.h>
 2815 
 2816 int main(int argc, char **argv)
 2817 {
 2818   static struct sockaddr_in in_addr;
 2819   static struct sockaddr_un un_addr;
 2820   static char buf[256];
 2821   socklen_t len;
 2822 
 2823   int s = socket(AF_INET, SOCK_STREAM, 0);
 2824   int e0 = bind(s, (struct sockaddr *) &in_addr, sizeof in_addr);
 2825   int e1 = listen(s, 42);
 2826   int e3 = connect(s, (struct sockaddr *) &un_addr, sizeof un_addr);
 2827   int e4 = send(s, buf, sizeof buf, 0);
 2828   int e5 = sendto(s, buf, sizeof buf, 0,
 2829                   (struct sockaddr *) &un_addr, sizeof un_addr);
 2830   int e6 = recv(s, buf, sizeof buf, 0);
 2831   int e7 = (len = sizeof in_addr,
 2832             recvfrom(s, buf, sizeof buf, 0,
 2833                      (struct sockaddr *) &in_addr, &len));
 2834   int e8 = shutdown(s, 0);
 2835   in_addr_t ia = inet_addr("10.0.0.1");
 2836 
 2837   return 0;
 2838 }
 2839 !
 2840 
 2841 if conftest ; then
 2842   printf "yes\n"
 2843   printf "#define HAVE_SOCKETS 1\n" >> config.h
 2844   have_sockets=y
 2845   have_sys_types=y
 2846 elif conftest EXTRA_LDFLAGS="-lsocket -lnsl" ; then
 2847   printf "yes\n"
 2848   printf "#define HAVE_SOCKETS 1\n" >> config.h
 2849   have_sockets=y
 2850   have_sys_types=y
 2851   conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lsocket -lnsl"
 2852   printf "Need libs for sockets: regenerating config.make ..."
 2853   gen_config_make
 2854   printf "done\n"
 2855 else
 2856   printf "no\n"
 2857 fi
 2858 
 2859 if [ $have_sockets ] ; then
 2860   printf "Checking whether we have <sys/select.h> ... "
 2861 
 2862   cat > conftest.c <<!
 2863 #include <sys/select.h>
 2864 
 2865 int main(int argc, char **argv)
 2866 {
 2867   fd_set rfds;
 2868   int res;
 2869   FD_ZERO(&rfds);
 2870   FD_SET(0, &rfds);
 2871   res = res = select(1, &rfds, 0, 0, 0);
 2872   return 0;
 2873 }
 2874 !
 2875   if conftest; then
 2876     printf "yes\n"
 2877     printf "#define HAVE_SYS_SELECT_H 1\n" >> config.h
 2878   else
 2879     printf "no\n"
 2880   fi
 2881 fi
 2882 
 2883 printf "Checking for getaddrinfo ... "
 2884 
 2885 cat > conftest.c <<!
 2886 #include <sys/types.h>
 2887 #include <netdb.h>
 2888 #include <stdio.h>
 2889 
 2890 int main(void)
 2891 {
 2892   struct addrinfo hints;
 2893   struct addrinfo *ptr;
 2894   int res = getaddrinfo("node", "serv", &hints, &ptr);
 2895   freeaddrinfo(ptr);
 2896   puts(gai_strerror(res));
 2897   return 0;
 2898 }
 2899 !
 2900 
 2901 if conftest ; then
 2902   printf "yes\n"
 2903   printf "#define HAVE_GETADDRINFO 1\n" >> config.h
 2904 else
 2905   printf "no\n"
 2906 fi
 2907 
 2908 printf "Checking for uname ... "
 2909 
 2910 cat > conftest.c <<!
 2911 #include <sys/utsname.h>
 2912 #include <stdio.h>
 2913 
 2914 int main(void)
 2915 {
 2916   struct utsname utn;
 2917   if (uname(&utn) == 0)
 2918     printf("%s:%s:%s:%s:%s\n", utn.sysname,
 2919            utn.nodename, utn.release, utn.version,
 2920            utn.machine);
 2921   return 0;
 2922 }
 2923 !
 2924 
 2925 if conftest ; then
 2926   printf "yes\n"
 2927   printf "#define HAVE_UNAME 1\n" >> config.h
 2928 else
 2929   printf "no\n"
 2930 fi
 2931 
 2932 printf "Checking for domainname in struct utsname ... "
 2933 
 2934 cat > conftest.c <<!
 2935 #include <sys/utsname.h>
 2936 #include <stdio.h>
 2937 
 2938 int main(void)
 2939 {
 2940   struct utsname utn;
 2941   if (uname(&utn) == 0)
 2942     printf("%s\n", utn.domainname);
 2943   return 0;
 2944 }
 2945 !
 2946 
 2947 if conftest ; then
 2948   printf "yes\n"
 2949   printf "#define HAVE_UTSNAME_DOMAINNAME 1\n" >> config.h
 2950 else
 2951   printf "no\n"
 2952 fi
 2953 
 2954 printf "Checking for dlopen ... "
 2955 
 2956 cat > conftest.c <<!
 2957 #include <dlfcn.h>
 2958 
 2959 int main(void)
 2960 {
 2961   void *lib = dlopen("foo.so", 0);
 2962   void *sym = dlsym(lib, "bar");
 2963 #if TEST_DLVSYM
 2964   void *vsym = dlvsym(lib, "bar", "1");
 2965 #endif
 2966   dlclose(lib);
 2967   return 0;
 2968 }
 2969 !
 2970 
 2971 if conftest ; then
 2972   printf "yes\n"
 2973   printf "#define HAVE_DLOPEN 1\n" >> config.h
 2974 elif conftest EXTRA_LDFLAGS=-ldl ; then
 2975   printf "yes\n"
 2976   printf "#define HAVE_DLOPEN 1\n" >> config.h
 2977   conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-ldl"
 2978 else
 2979   printf "no\n"
 2980 fi
 2981 
 2982 printf "Checking for dlvsym ... "
 2983 if conftest CONF_LDFLAGS="$conf_ldflags" EXTRA_FLAGS=-DTEST_DLVSYM=1 ; then
 2984   printf "yes\n"
 2985   printf "#define HAVE_DLVSYM 1\n" >> config.h
 2986 else
 2987   printf "no\n"
 2988 fi
 2989 
 2990 printf "Checking for pkg-config ... "
 2991 
 2992 if pkg-config --version > /dev/null 2>&1 ; then
 2993   printf "present\n"
 2994   have_pkgconfig=y
 2995 else
 2996   printf "absent\n"
 2997 fi
 2998 
 2999 printf "Checking for libffi ... "
 3000 
 3001 cat > conftest.c <<!
 3002 #include <stdio.h>
 3003 #include <ffi.h>
 3004 
 3005 int main(void)
 3006 {
 3007   ffi_cif cif;
 3008   ffi_type *args[1];
 3009   void *values[1];
 3010   char *s;
 3011   args[0] = &ffi_type_pointer;
 3012   values[0] = &s;
 3013   return ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sint, args) != FFI_OK;
 3014 }
 3015 !
 3016 
 3017 if conftest ; then
 3018   printf "yes\n"
 3019   printf "#define HAVE_LIBFFI 1\n" >> config.h
 3020 elif conftest EXTRA_LDFLAGS=-lffi ; then
 3021   printf "yes\n"
 3022   printf "#define HAVE_LIBFFI 1\n" >> config.h
 3023   conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lffi"
 3024 elif [ -n "$have_pkgconfig" ] && pkg-config --exists libffi ; then
 3025   libffi_cflags=$(pkg-config --cflags libffi)
 3026   libffi_ldflags=$(pkg-config --libs libffi)
 3027   if conftest EXTRA_FLAGS="$libffi_cflags" EXTRA_LDFLAGS="$libffi_ldflags" ; then
 3028     printf "yes\n"
 3029     printf "#define HAVE_LIBFFI 1\n" >> config.h
 3030     conf_ldflags="${conf_ldflags:+"$conf_ldflags "}$libffi_ldflags"
 3031   else
 3032     printf "no\n"
 3033     libffi_cflags=
 3034   fi
 3035 else
 3036   printf "no\n"
 3037 fi
 3038 
 3039 printf "Checking for clockid_t ... "
 3040 cat > conftest.c <<!
 3041 #include <sys/types.h>
 3042 
 3043 int main(void)
 3044 {
 3045   clockid_t cid = 0;
 3046   return 0;
 3047 }
 3048 !
 3049 
 3050 if conftest ; then
 3051   printf "yes\n"
 3052   printf "#define HAVE_CLOCKID_T 1\n" >> config.h
 3053   have_sys_types=y
 3054 else
 3055   printf "no\n"
 3056 fi
 3057 
 3058 printf "Checking for loff_t ... "
 3059 cat > conftest.c <<!
 3060 #include <sys/types.h>
 3061 
 3062 int main(void)
 3063 {
 3064   loff_t lo = 0;
 3065   return 0;
 3066 }
 3067 !
 3068 
 3069 if conftest ; then
 3070   printf "yes\n"
 3071   printf "#define HAVE_LOFF_T 1\n" >> config.h
 3072   have_sys_types=y
 3073 else
 3074   printf "no\n"
 3075 fi
 3076 
 3077 printf "Checking for realpath ... "
 3078 cat > conftest.c <<!
 3079 #include <stdlib.h>
 3080 
 3081 int main(void)
 3082 {
 3083   char *rp = realpath("/var/lib", 0);
 3084   return 0;
 3085 }
 3086 !
 3087 
 3088 if conftest ; then
 3089   printf "yes\n"
 3090   printf "#define HAVE_REALPATH 1\n" >> config.h
 3091 else
 3092   printf "no\n"
 3093 fi
 3094 
 3095 printf "Checking for getexecname ... "
 3096 cat > conftest.c <<!
 3097 #include <stdlib.h>
 3098 
 3099 int main(void)
 3100 {
 3101   const char *rp = getexecname();
 3102   return 0;
 3103 }
 3104 !
 3105 
 3106 if conftest ; then
 3107   printf "yes\n"
 3108   printf "#define HAVE_GETEXECNAME 1\n" >> config.h
 3109 else
 3110   printf "no\n"
 3111 fi
 3112 
 3113 #
 3114 # Dependent variables
 3115 #
 3116 
 3117 if [ -n "$have_unistd" ] ; then
 3118   printf "#define HAVE_UNISTD_H 1\n" >> config.h
 3119 fi
 3120 
 3121 if [ -n "$have_sys_types" ] ; then
 3122   printf "#define HAVE_SYS_TYPES_H 1\n" >> config.h
 3123 fi
 3124 
 3125 if [ -n "$have_sys_time" ] ; then
 3126   printf "#define HAVE_SYS_TIME 1\n" >> config.h
 3127 fi
 3128 
 3129 if [ -n "$have_windows_h" ] ; then
 3130   printf "#define HAVE_WINDOWS_H 1\n" >> config.h
 3131 fi
 3132 
 3133 #
 3134 # Extra debugging.
 3135 #
 3136 
 3137 if [ -n "$extra_debugging" ] ; then
 3138   printf "Configuring extra debugging, as requested ...\n"
 3139   printf "#define CONFIG_EXTRA_DEBUGGING 1\n" >> config.h
 3140 fi
 3141 
 3142 #
 3143 # Clean up
 3144 #
 3145 
 3146 $make conftest.clean
 3147 
 3148 #
 3149 # Some final blurbs into config.h
 3150 #
 3151 
 3152 [ -n "$debug_support" ] && printf "#define CONFIG_DEBUG_SUPPORT 1\n" >> config.h
 3153 [ -n "$gen_gc" ] && printf "#define CONFIG_GEN_GC 1\n" >> config.h
 3154 
 3155 #
 3156 # Regenerate config.make
 3157 #
 3158 
 3159 printf "Regenerating config.make ... "
 3160 gen_config_make
 3161 printf "done\n"
 3162 
 3163 #
 3164 # Save configuration in config.log
 3165 #
 3166 cat > config.log <<!
 3167 
 3168 Configured on $(date) using
 3169 
 3170    $cmdline
 3171 
 3172 !
 3173 #
 3174 # Parting message
 3175 #
 3176 cat <<!
 3177 
 3178 The configuration seems to have been successful. That doesn't mean it's
 3179 correct!  Please check the above output for any problems, and verify that the
 3180 contents of the generated files config.make and config.h are sane for the
 3181 target platform.
 3182 
 3183 The next step is to build the program with $make.
 3184 
 3185 If that is successful, please follow the INSTALL guide.
 3186 
 3187 Usually, most users just need to "$make tests" and "$make install",
 3188 possibly switching to superuser for "$make install" if the prefix
 3189 points to a privileged location like /usr/local/.
 3190 
 3191 !