"Fossies" - the Fresh Open Source Software Archive

Member "s-nail-14.9.10/make-config.sh" (25 Mar 2018, 86126 Bytes) of package /linux/misc/s-nail-14.9.10.tar.xz:


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 "make-config.sh": 14.9.9_vs_14.9.10.

    1 #!/bin/sh -
    2 #@ Please see INSTALL and make.rc instead.
    3 
    4 LC_ALL=C
    5 export LC_ALL
    6 
    7 # For heaven's sake auto-redirect on SunOS/Solaris
    8 if [ "x${SHELL}" = x ] || [ "${SHELL}" = /bin/sh ] && \
    9       [ -f /usr/xpg4/bin/sh ] && [ -x /usr/xpg4/bin/sh ]; then
   10    SHELL=/usr/xpg4/bin/sh
   11    export SHELL
   12    exec /usr/xpg4/bin/sh "${0}" "${@}"
   13 fi
   14 [ -n "${SHELL}" ] || SHELL=/bin/sh
   15 export SHELL
   16 
   17 # The feature set, to be kept in sync with make.rc
   18 # If no documentation given, the option is used as such; if doc is a hyphen,
   19 # entry is suppressed when configuration overview is printed, and also in the
   20 # *features* string: most likely for obsolete features etc.
   21 XOPTIONS="\
   22    ICONV='Character set conversion using iconv(3)' \
   23    SOCKETS='Network support' \
   24       SSL='SSL/TLS (OpenSSL / LibreSSL)' \
   25          SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
   26       SMTP='Simple Mail Transfer Protocol client' \
   27       POP3='Post Office Protocol Version 3 client' \
   28       IMAP='IMAP v4r1 client' \
   29       GSSAPI='Generic Security Service authentication' \
   30       NETRC='.netrc file support' \
   31       AGENT='-' \
   32       MD5='MD5 message digest (APOP, CRAM-MD5)' \
   33    IDNA='Internationalized Domain Names for Applications (encode only)' \
   34    IMAP_SEARCH='IMAP-style search expressions' \
   35    REGEX='Regular expressions' \
   36    MLE='Mailx Line Editor' \
   37       HISTORY='Line editor history management' \
   38       KEY_BINDINGS='Configurable key bindings' \
   39    TERMCAP='Terminal capability queries (termcap(5))' \
   40       TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
   41    ERRORS='Log message ring' \
   42    SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
   43    SPAM_SPAMD='-' \
   44    SPAM_FILTER='Freely configurable *spam-filter-..*s' \
   45    DOCSTRINGS='Command documentation help strings' \
   46    UISTRINGS='User interface and error message strings' \
   47    QUOTE_FOLD='Extended *quote-fold*ing' \
   48    FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
   49    COLOUR='Coloured message display' \
   50    DOTLOCK='Dotlock files and privilege-separated dotlock program' \
   51 "
   52 
   53 # Options which are automatically deduced from host environment, i.e., these
   54 # need special treatment all around here to warp from/to OPT_ stuff
   55 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
   56 XOPTIONS_DETECT="\
   57    LOCALES='Locale support - printable characters etc. depend on environment' \
   58    MULTIBYTE_CHARSETS='Multibyte character sets' \
   59    TERMINAL_CHARSET='Automatic detection of terminal character set' \
   60    WIDE_GLYPHS='Wide glyph support' \
   61 "
   62 
   63 # Rather special options, for custom building, or which always exist.
   64 # Mostly for generating the visual overview and the *features* string
   65 XOPTIONS_XTRA="\
   66    MIME='Multipurpose Internet Mail Extensions' \
   67    SMIME='S/MIME message signing, verification, en- and decryption' \
   68    CROSS_BUILD='Cross-compilation: trust any detected environment' \
   69    DEBUG='Debug enabled binary, not for end-users: THANKS!' \
   70    DEVEL='Computers do not blunder' \
   71 "
   72 
   73 # To avoid too many recompilations we use a two-stage "configuration changed"
   74 # detection, the first uses mk-config.lst, which only goes for actual user
   75 # config settings etc. the second uses mk-config.h, which thus includes the
   76 # things we have truly detected.  This does not work well for multiple choice
   77 # values of which only one will be really used, so those user wishes may not be
   78 # placed in the header, only the really detected one (but that has to!).
   79 # Used for grep(1), for portability assume fixed matching only.
   80 H_BLACKLIST='-e VAL_RANDOM -e VAL_IDNA'
   81 
   82 # The problem is that we don't have any tools we can use right now, so
   83 # encapsulate stuff in functions which get called in right order later on
   84 
   85 option_reset() {
   86    set -- ${OPTIONS}
   87    for i
   88    do
   89       eval OPT_${i}=0
   90    done
   91 }
   92 
   93 option_maximal() {
   94    set -- ${OPTIONS}
   95    for i
   96    do
   97       eval OPT_${i}=1
   98    done
   99    OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
  100 }
  101 
  102 option_setup() {
  103    option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
  104    option_parse OPTIONS "${XOPTIONS}"
  105    option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
  106    OPT_MIME=1
  107 
  108    # Predefined CONFIG= urations take precedence over anything else
  109    if [ -n "${CONFIG}" ]; then
  110       option_reset
  111       case "${CONFIG}" in
  112       [nN][uU][lL][lL])
  113          ;;
  114       [nN][uU][lL][lL][iI])
  115          OPT_ICONV=require
  116          OPT_UISTRINGS=1
  117          ;;
  118       [mM][iI][nN][iI][mM][aA][lL])
  119          OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
  120          OPT_COLOUR=1
  121          OPT_DOCSTRINGS=1
  122          OPT_UISTRINGS=1
  123          OPT_ERRORS=1
  124          OPT_IDNA=1
  125          OPT_MLE=1
  126             OPT_HISTORY=1 OPT_KEY_BINDINGS=1
  127          OPT_SPAM_FILTER=1
  128          ;;
  129       [nN][eE][tT][sS][eE][nN][dD])
  130          OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
  131          OPT_SOCKETS=require
  132             OPT_SSL=require
  133             OPT_SMTP=require
  134             OPT_GSSAPI=1 OPT_NETRC=1
  135                OPT_AGENT=1
  136          OPT_COLOUR=1
  137          OPT_DOCSTRINGS=1
  138          OPT_UISTRINGS=1
  139          OPT_ERRORS=1
  140          OPT_IDNA=1
  141          OPT_MLE=1
  142             OPT_HISTORY=1 OPT_KEY_BINDINGS=1
  143          OPT_SPAM_FILTER=1
  144          ;;
  145       [mM][aA][xX][iI][mM][aA][lL])
  146          option_maximal
  147          ;;
  148       [dD][eE][vV][eE][lL])
  149          option_maximal
  150          OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
  151          ;;
  152       [oO][dD][eE][vV][eE][lL])
  153          option_maximal
  154          OPT_DEVEL=1
  155          ;;
  156       *)
  157          echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
  158          echo >&2 '   NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
  159          exit 1
  160          ;;
  161       esac
  162       msg_nonl "CONFIG=${CONFIG} ... "
  163    fi
  164 }
  165 
  166 # Inter-relationships XXX sort this!
  167 option_update() {
  168    if feat_no SSL; then
  169       OPT_SSL_ALL_ALGORITHMS=0
  170    fi
  171 
  172    if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
  173       OPT_SOCKETS=0
  174    fi
  175    if feat_no SOCKETS; then
  176       if feat_require SMTP; then
  177          msg 'ERROR: need SOCKETS for required feature SMTP'
  178          config_exit 13
  179       fi
  180       if feat_require POP3; then
  181          msg 'ERROR: need SOCKETS for required feature POP3'
  182          config_exit 13
  183       fi
  184       if feat_require IMAP; then
  185          msg 'ERROR: need SOCKETS for required feature IMAP'
  186          config_exit 13
  187       fi
  188       OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
  189       OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
  190       OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
  191    fi
  192    if feat_no SMTP && feat_no IMAP; then
  193       OPT_GSSAPI=0
  194    fi
  195 
  196    if feat_no ICONV; then
  197       if feat_yes IMAP; then
  198          if feat_yes ALWAYS_UNICODE_LOCALE; then
  199             msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
  200          elif feat_require IMAP; then
  201             msg 'ERROR: need ICONV for required feature IMAP'
  202             config_exit 13
  203          else
  204             msg 'ERROR: disabling IMAP due to missing ICONV'
  205             OPT_IMAP=0
  206          fi
  207       fi
  208 
  209       if feat_yes IDNA; then
  210          if feat_require IDNA; then
  211             msg 'ERROR: need ICONV for required feature IDNA'
  212             config_exit 13
  213          fi
  214          msg 'ERROR: disabling IDNA due to missing ICONV'
  215          OPT_IDNA=0
  216       fi
  217    fi
  218 
  219    if feat_no MLE; then
  220       OPT_HISTORY=0 OPT_KEY_BINDINGS=0
  221    fi
  222 
  223    # If we don't need MD5 leave it alone
  224    if feat_no SOCKETS; then
  225       OPT_MD5=0
  226    fi
  227 
  228    if feat_no TERMCAP; then
  229       OPT_TERMCAP_VIA_TERMINFO=0
  230    fi
  231 
  232    if feat_yes DEVEL; then
  233       OPT_DEBUG=1
  234    fi
  235 }
  236 
  237 rc=./make.rc
  238 lst=./mk-config.lst
  239 ev=./mk-config.ev
  240 h=./mk-config.h h_name=mk-config.h
  241 mk=./mk-config.mk
  242 
  243 newlst=./mk-nconfig.lst
  244 newmk=./mk-nconfig.mk
  245 oldmk=./mk-oconfig.mk
  246 newev=./mk-nconfig.ev
  247 newh=./mk-nconfig.h
  248 oldh=./mk-oconfig.h
  249 tmp0=___tmp
  250 tmp=./${tmp0}1$$
  251 tmp2=./${tmp0}2$$
  252 
  253 ##  --  >8  - << OPTIONS | OS/CC >> -  8<  --  ##
  254 
  255 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
  256 # via path_check() later on once possible
  257 
  258 # TODO cc_maxopt is brute simple, we should compile test program and dig real
  259 # compiler versions for known compilers, then be more specific
  260 [ -n "${cc_maxopt}" ] || cc_maxopt=100
  261 #cc_force_no_stackprot=
  262 #ld_need_R_flags=
  263 #ld_no_bind_now=
  264 #ld_rpath_not_runpath=
  265 
  266 _CFLAGS= _LDFLAGS=
  267 
  268 os_early_setup() {
  269    [ -n "${OS}" ] && [ -n "${OSENV}" ] && [ -n "${OSFULLSPEC}" ] ||
  270       thecmd_testandset_fail uname uname
  271 
  272    # We don't "have any utility": only path adjustments and such in here!
  273    [ -n "${OS}" ] || OS=`${uname} -s`
  274    export OS
  275 
  276    if [ ${OS} = SunOS ]; then
  277       msg 'SunOS / Solaris?  Applying some "early setup" rules ...'
  278       _os_early_setup_sunos
  279    fi
  280 }
  281 
  282 _os_early_setup_sunos() {
  283    # According to standards(5), this is what we need to do
  284    if [ -d /usr/xpg4 ]; then :; else
  285       msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment!  Sorry.'
  286       config_exit 1
  287    fi
  288    PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
  289    [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
  290    export PATH
  291 }
  292 
  293 os_setup() {
  294    # OSENV ends up in *build-osenv*
  295    # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
  296    # etc.), it is not baked into the binary
  297    OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
  298    [ -n "${OSENV}" ] || OSENV=`${uname} -sm`
  299    [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
  300    msg 'Operating system is %s' ${OS}
  301 
  302    if [ ${OS} = darwin ]; then
  303       msg ' . have special Darwin environmental addons...'
  304       LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
  305    elif [ ${OS} = sunos ]; then
  306       msg ' . have special SunOS / Solaris "setup" rules ...'
  307       _os_setup_sunos
  308    elif [ ${OS} = unixware ]; then
  309       if feat_yes AUTOCC && acmd_set CC cc; then
  310          msg ' . have special UnixWare environmental rules ...'
  311          feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
  312 
  313          CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
  314          LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
  315          export CC CFLAGS LDFLAGS
  316          OPT_AUTOCC=0 ld_need_R_flags=-R
  317       fi
  318    elif [ -n "${VERBOSE}" ]; then
  319       msg ' . no special treatment for this system necessary or known'
  320    fi
  321 
  322    # Sledgehammer: better set _GNU_SOURCE
  323    # And in general: oh, boy!
  324    OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
  325    #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
  326    #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
  327    #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
  328 
  329    # On pkgsrc(7) systems automatically add /usr/pkg/*
  330    if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
  331       msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
  332       C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
  333       LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
  334       ld_rpath_not_runpath=1
  335    fi
  336 }
  337 
  338 _os_setup_sunos() {
  339    C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
  340    LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
  341 
  342    # Include packages
  343    if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
  344       msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
  345       C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
  346       LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
  347       ld_no_bind_now=1 ld_rpath_not_runpath=1
  348    fi
  349    if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
  350       msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
  351       C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
  352       LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
  353       ld_no_bind_now=1 ld_rpath_not_runpath=1
  354    fi
  355 
  356    OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
  357    #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
  358 
  359    [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
  360    if [ -x "${cksum}" ]; then :; else
  361       msg 'ERROR: Not an executable program: %s' "${cksum}"
  362       msg 'ERROR:   We need a CRC-32 cksum(1), as specified in POSIX.'
  363       msg 'ERROR:   However, we do so only for tests.'
  364       msg 'ERROR:   If that is ok, set "cksum=/usr/bin/true", then rerun'
  365       config_exit 1
  366    fi
  367 
  368    if feat_yes AUTOCC; then
  369       if acmd_set CC cc; then
  370          feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
  371 
  372          CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
  373          LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
  374          export CC CFLAGS LDFLAGS
  375          OPT_AUTOCC=0 ld_need_R_flags=-R
  376       else
  377          cc_maxopt=2 cc_force_no_stackprot=1
  378       fi
  379    fi
  380 }
  381 
  382 # Check out compiler ($CC) and -flags ($CFLAGS)
  383 cc_setup() {
  384    # Even though it belongs into cc_flags we will try to compile and link
  385    # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
  386    # EXTRA_CFLAGS/EXTRA_LDFLAGS
  387    if feat_no AUTOCC; then
  388       _cc_default
  389       # Ensure those don't do any harm
  390       EXTRA_CFLAGS= EXTRA_LDFLAGS=
  391       export EXTRA_CFLAGS EXTRA_LDFLAGS
  392       return
  393    else
  394       CFLAGS= LDFLAGS=
  395       export CFLAGS LDFLAGS
  396    fi
  397 
  398    [ -n "${CC}" ] && { _cc_default; return; }
  399 
  400    msg_nonl 'Searching for a usable C compiler .. $CC='
  401    if acmd_set CC clang || acmd_set CC gcc ||
  402          acmd_set CC tcc || acmd_set CC pcc ||
  403          acmd_set CC c89 || acmd_set CC c99; then
  404       :
  405    else
  406       msg 'boing booom tschak'
  407       msg 'ERROR: I cannot find a compiler!'
  408       msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
  409       msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
  410       config_exit 1
  411    fi
  412    msg '%s' "${CC}"
  413    export CC
  414 }
  415 
  416 _cc_default() {
  417    if [ -z "${CC}" ]; then
  418       msg 'To go on like you have chosen, please set $CC, rerun.'
  419       config_exit 1
  420    fi
  421 
  422    if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
  423       :
  424    else
  425       msg 'Using C compiler ${CC}=%s' "${CC}"
  426    fi
  427 }
  428 
  429 cc_flags() {
  430    if feat_yes AUTOCC; then
  431       if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
  432          cc_check_silent=1
  433          msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
  434             "${CC}"
  435       else
  436          cc_check_silent=
  437          msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
  438       fi
  439 
  440       i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
  441       if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
  442          msg ' . have special tcc(1) environmental rules ...'
  443          _cc_flags_tcc
  444       else
  445          # As of pcc CVS 2016-04-02, stack protection support is announced but
  446          # will break if used on Linux
  447          if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
  448             cc_force_no_stackprot=1
  449          fi
  450          _cc_flags_generic
  451       fi
  452 
  453       feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
  454       CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
  455       LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
  456    else
  457       if feat_no DEBUG; then
  458          CFLAGS="-DNDEBUG ${CFLAGS}"
  459       fi
  460    fi
  461    export CFLAGS LDFLAGS
  462 }
  463 
  464 _cc_flags_tcc() {
  465    __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
  466    _CFLAGS= _LDFLAGS=
  467 
  468    cc_check -W
  469    cc_check -Wall
  470    cc_check -Wextra
  471    cc_check -pedantic
  472 
  473    if feat_yes DEBUG; then
  474       # May have problems to find libtcc cc_check -b
  475       cc_check -g
  476    fi
  477 
  478    if ld_check -Wl,-rpath =./ no; then
  479       ld_need_R_flags=-Wl,-rpath=
  480       if [ -z "${ld_rpath_not_runpath}" ]; then
  481          ld_check -Wl,--enable-new-dtags
  482       else
  483          msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
  484       fi
  485       ld_runtime_flags # update!
  486    fi
  487 
  488    _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
  489    unset __cflags __ldflags
  490 }
  491 
  492 _cc_flags_generic() {
  493    __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
  494    _CFLAGS= _LDFLAGS=
  495    feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
  496 
  497    # E.g., valgrind does not work well with high optimization
  498    if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
  499          feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
  500       msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
  501       cc_maxopt=1
  502    fi
  503    # Check -g first since some others may rely upon -g / optim. level
  504    if feat_yes DEBUG; then
  505       cc_check -O
  506       cc_check -g
  507    elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
  508       :
  509    elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
  510       :
  511    elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
  512       :
  513    else
  514       cc_check -O
  515    fi
  516 
  517    if feat_yes AMALGAMATION; then
  518       cc_check -pipe
  519    fi
  520 
  521    #if feat_yes DEVEL && cc_check -Weverything; then
  522    #   :
  523    #else
  524       cc_check -W
  525       cc_check -Wall
  526       cc_check -Wextra
  527       cc_check -Wbad-function-cast
  528       cc_check -Wcast-align
  529       cc_check -Wcast-qual
  530       cc_check -Winit-self
  531       cc_check -Wmissing-prototypes
  532       cc_check -Wshadow
  533       cc_check -Wunused
  534       cc_check -Wwrite-strings
  535       cc_check -Wno-long-long
  536    #fi
  537    cc_check -pedantic
  538 
  539    if feat_yes AMALGAMATION && feat_no DEVEL; then
  540       cc_check -Wno-unused-function
  541    fi
  542    feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
  543 
  544    cc_check -fno-unwind-tables
  545    cc_check -fno-asynchronous-unwind-tables
  546    cc_check -fstrict-aliasing
  547    if cc_check -fstrict-overflow && feat_yes DEVEL; then
  548       cc_check -Wstrict-overflow=5
  549    fi
  550 
  551    if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
  552       if [ -z "${cc_force_no_stackprot}" ]; then
  553          if cc_check -fstack-protector-strong ||
  554                cc_check -fstack-protector-all; then
  555             cc_check -D_FORTIFY_SOURCE=2
  556          fi
  557       else
  558          msg ' ! Not checking for -fstack-protector compiler option,'
  559          msg ' ! since that caused errors in a "similar" configuration.'
  560          msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
  561       fi
  562    fi
  563 
  564    # LD (+ dependend CC)
  565 
  566    if feat_yes ASAN_ADDRESS; then
  567       _ccfg=${_CFLAGS}
  568       if cc_check -fsanitize=address &&
  569             ld_check -fsanitize=address; then
  570          :
  571       else
  572          feat_bail_required ASAN_ADDRESS
  573          _CFLAGS=${_ccfg}
  574       fi
  575    fi
  576 
  577    if feat_yes ASAN_MEMORY; then
  578       _ccfg=${_CFLAGS}
  579       if cc_check -fsanitize=memory &&
  580             ld_check -fsanitize=memory &&
  581             cc_check -fsanitize-memory-track-origins=2 &&
  582             ld_check -fsanitize-memory-track-origins=2; then
  583          :
  584       else
  585          feat_bail_required ASAN_MEMORY
  586          _CFLAGS=${_ccfg}
  587       fi
  588    fi
  589 
  590    ld_check -Wl,-z,relro
  591    if [ -z "${ld_no_bind_now}" ]; then
  592       ld_check -Wl,-z,now
  593    else
  594       msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
  595    fi
  596    ld_check -Wl,-z,noexecstack
  597    if ld_check -Wl,-rpath =./ no; then
  598       ld_need_R_flags=-Wl,-rpath=
  599       # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
  600       if [ -z "${ld_rpath_not_runpath}" ]; then
  601          ld_check -Wl,--enable-new-dtags
  602       else
  603          msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
  604       fi
  605       ld_runtime_flags # update!
  606    elif ld_check -Wl,-R ./ no; then
  607       ld_need_R_flags=-Wl,-R
  608       if [ -z "${ld_rpath_not_runpath}" ]; then
  609          ld_check -Wl,--enable-new-dtags
  610       else
  611          msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
  612       fi
  613       ld_runtime_flags # update!
  614    fi
  615 
  616    # Address randomization
  617    _ccfg=${_CFLAGS}
  618    if cc_check -fPIE || cc_check -fpie; then
  619       ld_check -pie || _CFLAGS=${_ccfg}
  620    fi
  621    unset _ccfg
  622 
  623    _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
  624    unset __cflags __ldflags
  625 }
  626 
  627 ##  --  >8  - <<OS/CC | SUPPORT FUNS>> -  8<  --  ##
  628 
  629 ## Notes:
  630 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
  631 ##   redirection, so use "printf '' >" instead
  632 
  633 ## Very first: we undergo several states regarding I/O redirection etc.,
  634 ## but need to deal with option updates from within all.  Since all the
  635 ## option stuff should be above the scissor line, define utility functions
  636 ## and redefine them as necessary.
  637 ## And, since we have those functions, simply use them for whatever
  638 
  639 t1=ten10one1ten10one1
  640 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
  641       [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
  642       ) > /dev/null 2>&1; then
  643    good_shell=1
  644 else
  645    unset good_shell
  646 fi
  647 unset t1
  648 
  649 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
  650 
  651 config_exit() {
  652    exit ${1}
  653 }
  654 
  655 # which(1) not standardized, command(1) -v may return non-executable: unroll!
  656 acmd_test() { __acmd "${1}" 1 0 0; }
  657 acmd_test_fail() { __acmd "${1}" 1 1 0; }
  658 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
  659 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
  660 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
  661 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
  662 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
  663 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
  664 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
  665 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
  666 __acmd() {
  667    pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
  668 
  669    if [ "${dotest}" -ne 0 ]; then
  670       eval dotest=\$${varname}
  671       if [ -n "${dotest}" ]; then
  672          [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
  673             msg ' . ${%s} ... %s' "${pname}" "${dotest}"
  674          return 0
  675       fi
  676    fi
  677 
  678    oifs=${IFS} IFS=:
  679    [ -n "${noglob_shell}" ] && set -o noglob
  680    set -- ${PATH}
  681    [ -n "${noglob_shell}" ] && set +o noglob
  682    IFS=${oifs}
  683    for path
  684    do
  685       if [ -z "${path}" ] || [ "${path}" = . ]; then
  686          if [ -d "${PWD}" ]; then
  687             path=${PWD}
  688          else
  689             path=.
  690          fi
  691       fi
  692       if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
  693          [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
  694             msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
  695          [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
  696          return 0
  697       fi
  698    done
  699 
  700    # We may have no builtin string functions, we yet have no programs we can
  701    # use, try to access once from the root, assuming it is an absolute path if
  702    # that finds the executable
  703    if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
  704      [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
  705             msg ' . ${%s} ... %s' "${pname}" "${pname}"
  706       [ -n "${varname}" ] && eval ${varname}="${pname}"
  707       return 0
  708    fi
  709 
  710    [ ${dofail} -eq 0 ] && return 1
  711    msg 'ERROR: no trace of utility '"${pname}"
  712    exit 1
  713 }
  714 
  715 msg() {
  716    fmt=${1}
  717    shift
  718    printf >&2 -- "${fmt}\\n" "${@}"
  719 }
  720 
  721 msg_nonl() {
  722    fmt=${1}
  723    shift
  724    printf >&2 -- "${fmt}" "${@}"
  725 }
  726 
  727 # Our feature check environment
  728 feat_val_no() {
  729    [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
  730    [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
  731 }
  732 
  733 feat_val_yes() {
  734    [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
  735    [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
  736          [ "x${1}" = xrequire ]
  737 }
  738 
  739 feat_val_require() {
  740    [ "x${1}" = xrequire ]
  741 }
  742 
  743 _feat_check() {
  744    eval i=\$OPT_${1}
  745    i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
  746    if feat_val_no "${i}"; then
  747       return 1
  748    elif feat_val_yes "${i}"; then
  749       return 0
  750    else
  751       msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
  752          "${1}" "${i}"
  753       config_exit 11
  754    fi
  755 }
  756 
  757 feat_yes() {
  758    _feat_check ${1}
  759 }
  760 
  761 feat_no() {
  762    _feat_check ${1} && return 1
  763    return 0
  764 }
  765 
  766 feat_require() {
  767    eval i=\$OPT_${1}
  768    i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
  769    [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
  770 }
  771 
  772 feat_bail_required() {
  773    if feat_require ${1}; then
  774       msg 'ERROR: feature OPT_%s is required but not available' "${1}"
  775       config_exit 13
  776    fi
  777    feat_is_unsupported "${1}"
  778 }
  779 
  780 feat_is_disabled() {
  781    [ ${#} -eq 1 ] && msg ' .  (disabled: OPT_%s)' "${1}"
  782    echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
  783 }
  784 
  785 feat_is_unsupported() {
  786    msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
  787    echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
  788    eval OPT_${1}=0
  789    option_update # XXX this is rather useless here (dependency chain..)
  790 }
  791 
  792 feat_def() {
  793    if feat_yes ${1}; then
  794       echo '#define HAVE_'${1}'' >> ${h}
  795       return 0
  796    else
  797       feat_is_disabled "${@}"
  798       return 1
  799    fi
  800 }
  801 
  802 option_parse() {
  803    # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
  804    # options, without documentation, to $1
  805    j=\'
  806    i="`${awk} -v input=\"${2}\" '
  807       BEGIN{
  808          for(i = 0;;){
  809             voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
  810             if(voff == 0)
  811                break
  812             v = substr(input, voff, RLENGTH)
  813             input = substr(input, voff + RLENGTH)
  814             doff = index(v, "=")
  815             if(doff > 0){
  816                d = substr(v, doff + 2, length(v) - doff - 1)
  817                v = substr(v, 1, doff - 1)
  818             }
  819             print v
  820          }
  821       }
  822       '`"
  823    eval ${1}=\"${i}\"
  824 }
  825 
  826 option_doc_of() {
  827    # Return the "documentation string" for option $1, itself if none such
  828    j=\'
  829    ${awk} -v want="${1}" \
  830       -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
  831    BEGIN{
  832       for(;;){
  833          voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
  834          if(voff == 0)
  835             break
  836          v = substr(input, voff, RLENGTH)
  837          input = substr(input, voff + RLENGTH)
  838          doff = index(v, "=")
  839          if(doff > 0){
  840             d = substr(v, doff + 2, length(v) - doff - 1)
  841             v = substr(v, 1, doff - 1)
  842          }else
  843             d = v
  844          if(v == want){
  845             if(d != "-")
  846                print d
  847             exit
  848          }
  849       }
  850    }
  851    '
  852 }
  853 
  854 option_join_rc() {
  855    # Join the values from make.rc into what currently is defined, not
  856    # overwriting yet existing settings
  857    ${rm} -f ${tmp}
  858    # We want read(1) to perform reverse solidus escaping in order to be able to
  859    # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
  860    # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
  861    < ${rc} ${awk} 'BEGIN{line = ""}{
  862       gsub(/^[[:space:]]+/, "", $0)
  863       gsub(/[[:space:]]+$/, "", $0)
  864       if(gsub(/\\$/, "", $0)){
  865          line = line $0
  866          next
  867       }else
  868          line = line $0
  869       if(index(line, "#") == 1){
  870          line = ""
  871       }else if(length(line)){
  872          print line
  873          line = ""
  874       }
  875    }' |
  876    while read line; do
  877       if [ -n "${good_shell}" ]; then
  878          i=${line%%=*}
  879       else
  880          i=`${awk} -v LINE="${line}" 'BEGIN{
  881             gsub(/=.*$/, "", LINE)
  882             print LINE
  883          }'`
  884       fi
  885       if [ "${i}" = "${line}" ]; then
  886          msg 'ERROR: invalid syntax in: %s' "${line}"
  887          continue
  888       fi
  889 
  890       eval j="\$${i}" jx="\${${i}+x}"
  891       if [ -n "${j}" ] || [ "${jx}" = x ]; then
  892          : # Yet present
  893       else
  894          j=`${awk} -v LINE="${line}" 'BEGIN{
  895             gsub(/^[^=]*=/, "", LINE)
  896             gsub(/^\"*/, "", LINE)
  897             gsub(/\"*$/, "", LINE)
  898             print LINE
  899          }'`
  900       fi
  901       [ "${i}" = "DESTDIR" ] && continue
  902       echo "${i}=\"${j}\""
  903    done > ${tmp}
  904    # Reread the mixed version right now
  905    . ./${tmp}
  906 }
  907 
  908 option_evaluate() {
  909    # Expand the option values, which may contain shell snippets
  910    ${rm} -f ${newlst} ${newmk} ${newh}
  911    exec 5<&0 6>&1 <${tmp} >${newlst}
  912    while read line; do
  913       z=
  914       if [ -n "${good_shell}" ]; then
  915          i=${line%%=*}
  916          [ "${i}" != "${i#OPT_}" ] && z=1
  917       else
  918          i=`${awk} -v LINE="${line}" 'BEGIN{
  919             gsub(/=.*$/, "", LINE);\
  920             print LINE
  921          }'`
  922          if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
  923             z=1
  924          fi
  925       fi
  926 
  927       eval j=\$${i}
  928       if [ -n "${z}" ]; then
  929          j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
  930          if [ -z "${j}" ] || feat_val_no "${j}"; then
  931             j=0
  932             printf "   /* #undef ${i} */\n" >> ${newh}
  933          elif feat_val_yes "${j}"; then
  934             if feat_val_require "${j}"; then
  935                j=require
  936             else
  937                j=1
  938             fi
  939             printf "   /* #define ${i} */\n" >> ${newh}
  940          else
  941             msg 'ERROR: cannot parse <%s>' "${line}"
  942             config_exit 1
  943          fi
  944       elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
  945          :
  946       else
  947          printf "#define ${i} \"${j}\"\n" >> ${newh}
  948       fi
  949       printf "${i} = ${j}\n" >> ${newmk}
  950       printf "${i}=${j}\n"
  951       eval "${i}=\"${j}\""
  952    done
  953    exec 0<&5 1>&6 5<&- 6<&-
  954 }
  955 
  956 val_allof() {
  957    eval __expo__=\$${1}
  958    ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
  959       BEGIN{
  960          i = split(HEAP, ha)
  961          if((j = split(USER, ua)) == 0)
  962             exit
  963          for(; j != 0; --j){
  964             us = tolower(ua[j])
  965             if(us == "all" || us == "any")
  966                continue
  967             ok = 0
  968             for(ii = i; ii != 0; --ii)
  969                if(tolower(ha[ii]) == us){
  970                   ok = 1
  971                   break
  972                }
  973             if(!ok)
  974                exit 1
  975          }
  976       }
  977    '
  978    __rv__=${?}
  979    [ ${__rv__} -ne 0 ] && return ${__rv__}
  980 
  981     if ${awk} -v USER="${__expo__}" '
  982             BEGIN{
  983                if((j = split(USER, ua)) == 0)
  984                   exit
  985                for(; j != 0; --j){
  986                   us = tolower(ua[j])
  987                   if(us == "all" || us == "any")
  988                      exit 0
  989                }
  990                exit 1
  991             }
  992          '; then
  993       eval "${1}"=\"${2}\"
  994    fi
  995    return 0
  996 }
  997 
  998 path_check() {
  999    # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
 1000    varname=${1} addflag=${2} flagvarname=${3}
 1001    j=${IFS}
 1002    IFS=:
 1003    [ -n "${noglob_shell}" ] && set -o noglob
 1004    eval "set -- \$${1}"
 1005    [ -n "${noglob_shell}" ] && set +o noglob
 1006    IFS=${j}
 1007    j= k= y= z=
 1008    for i
 1009    do
 1010       [ -z "${i}" ] && continue
 1011       [ -d "${i}" ] || continue
 1012       if [ -n "${j}" ]; then
 1013          if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
 1014             :
 1015          else
 1016             y="${y} :${i}:"
 1017             j="${j}:${i}"
 1018             # But do not link any fakeroot path into our binaries!
 1019             if [ -n "${addflag}" ]; then
 1020                case "${i}" in *fakeroot*) continue;; esac
 1021                k="${k} ${addflag}${i}"
 1022             fi
 1023          fi
 1024       else
 1025          y=" :${i}:"
 1026          j="${i}"
 1027          # But do not link any fakeroot path into our binaries!
 1028          if [ -n "${addflag}" ]; then
 1029             case "${i}" in *fakeroot*) continue;; esac
 1030             k="${k} ${addflag}${i}"
 1031          fi
 1032       fi
 1033    done
 1034    eval "${varname}=\"${j}\""
 1035    [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
 1036    unset varname
 1037 }
 1038 
 1039 ld_runtime_flags() {
 1040    if [ -n "${ld_need_R_flags}" ]; then
 1041       i=${IFS}
 1042       IFS=:
 1043       set -- ${LD_LIBRARY_PATH}
 1044       IFS=${i}
 1045       for i
 1046       do
 1047          # But do not link any fakeroot path into our binaries!
 1048          case "${i}" in *fakeroot*) continue;; esac
 1049          LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
 1050          _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
 1051       done
 1052       export LDFLAGS
 1053    fi
 1054    # Disable it for a possible second run.
 1055    ld_need_R_flags=
 1056 }
 1057 
 1058 cc_check() {
 1059    [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
 1060    if "${CC}" ${INCS} \
 1061          ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
 1062          -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
 1063       _CFLAGS="${_CFLAGS} ${1}"
 1064       [ -n "${cc_check_silent}" ] || msg 'yes'
 1065       return 0
 1066    fi
 1067    [ -n "${cc_check_silent}" ] || msg 'no'
 1068    return 1
 1069 }
 1070 
 1071 ld_check() {
 1072    # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
 1073    [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
 1074    if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
 1075          -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
 1076       [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
 1077       [ -n "${cc_check_silent}" ] || msg 'yes'
 1078       return 0
 1079    fi
 1080    [ -n "${cc_check_silent}" ] || msg 'no'
 1081    return 1
 1082 }
 1083 
 1084 dump_test_program=1
 1085 _check_preface() {
 1086    variable=$1 topic=$2 define=$3
 1087 
 1088    echo '**********'
 1089    msg_nonl ' . %s ... ' "${topic}"
 1090    #echo "/* checked ${topic} */" >> ${h}
 1091    ${rm} -f ${tmp} ${tmp}.o
 1092    if [ "${dump_test_program}" = 1 ]; then
 1093       echo '*** test program is'
 1094       { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
 1095    else
 1096       { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
 1097    fi
 1098    #echo '*** the preprocessor generates'
 1099    #${make} -f ${makefile} ${tmp}.x
 1100    #${cat} ${tmp}.x
 1101    echo '*** tests results'
 1102 }
 1103 
 1104 without_check() {
 1105    yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
 1106 
 1107    echo '**********'
 1108    msg_nonl ' . %s ... ' "${topic}"
 1109 
 1110    echo '*** enforced unchecked results are'
 1111    if feat_val_yes ${yesno}; then
 1112       if [ -n "${incs}" ] || [ -n "${libs}" ]; then
 1113          echo "*** adding INCS<${incs}> LIBS<${libs}>"
 1114          LIBS="${LIBS} ${libs}"
 1115          echo "${libs}" >> ${lib}
 1116          INCS="${INCS} ${incs}"
 1117          echo "${incs}" >> ${inc}
 1118       fi
 1119       msg 'yes (deduced)'
 1120       echo "${define}" >> ${h}
 1121       eval have_${variable}=yes
 1122       return 0
 1123    else
 1124       #echo "/* ${define} */" >> ${h}
 1125       msg 'no (deduced)'
 1126       eval unset have_${variable}
 1127       return 1
 1128    fi
 1129 }
 1130 
 1131 compile_check() {
 1132    variable=$1 topic=$2 define=$3
 1133 
 1134    _check_preface "${variable}" "${topic}" "${define}"
 1135 
 1136    if ${make} -f ${makefile} XINCS="${INCS}" \
 1137             CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
 1138             ./${tmp}.o &&
 1139          [ -f ./${tmp}.o ]; then
 1140       msg 'yes'
 1141       echo "${define}" >> ${h}
 1142       eval have_${variable}=yes
 1143       return 0
 1144    else
 1145       #echo "/* ${define} */" >> ${h}
 1146       msg 'no'
 1147       eval unset have_${variable}
 1148       return 1
 1149    fi
 1150 }
 1151 
 1152 _link_mayrun() {
 1153    run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
 1154 
 1155    _check_preface "${variable}" "${topic}" "${define}"
 1156 
 1157    if feat_yes CROSS_BUILD; then
 1158       if [ ${run} = 1 ]; then
 1159          run=0
 1160       fi
 1161    fi
 1162 
 1163    if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
 1164             CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
 1165             XLIBS="${LIBS} ${libs}" \
 1166             ./${tmp} &&
 1167          [ -f ./${tmp} ] &&
 1168          { [ ${run} -eq 0 ] || ./${tmp}; }; then
 1169       echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
 1170       msg 'yes'
 1171       echo "${define}" >> ${h}
 1172       LIBS="${LIBS} ${libs}"
 1173       echo "${libs}" >> ${lib}
 1174       INCS="${INCS} ${incs}"
 1175       echo "${incs}" >> ${inc}
 1176       eval have_${variable}=yes
 1177       return 0
 1178    else
 1179       msg 'no'
 1180       #echo "/* ${define} */" >> ${h}
 1181       eval unset have_${variable}
 1182       return 1
 1183    fi
 1184 }
 1185 
 1186 link_check() {
 1187    _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
 1188 }
 1189 
 1190 run_check() {
 1191    _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
 1192 }
 1193 
 1194 xrun_check() {
 1195    _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
 1196 }
 1197 
 1198 squeeze_em() {
 1199    < "${1}" > "${2}" ${awk} \
 1200    'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
 1201 }
 1202 
 1203 ##  --  >8  - <<SUPPORT FUNS | RUNNING>> -  8<  --  ##
 1204 
 1205 # First of all, create new configuration and check whether it changed
 1206 
 1207 # Very easy checks for the operating system in order to be able to adjust paths
 1208 # or similar very basic things which we need to be able to go at all
 1209 os_early_setup
 1210 
 1211 # Check those tools right now that we need before including $rc
 1212 msg 'Checking for basic utility set'
 1213 thecmd_testandset_fail awk awk
 1214 thecmd_testandset_fail rm rm
 1215 thecmd_testandset_fail tr tr
 1216 
 1217 # Initialize the option set
 1218 msg_nonl 'Setting up configuration options ... '
 1219 option_setup
 1220 msg 'done'
 1221 
 1222 # Include $rc, but only take from it what wasn't overwritten by the user from
 1223 # within the command line or from a chosen fixed CONFIG=
 1224 # Note we leave alone the values
 1225 trap "exit 1" HUP INT TERM
 1226 trap "${rm} -f ${tmp}" EXIT
 1227 
 1228 msg_nonl 'Joining in %s ... ' ${rc}
 1229 option_join_rc
 1230 msg 'done'
 1231 
 1232 # We need to know about that now, in order to provide utility overwrites etc.
 1233 os_setup
 1234 
 1235 msg 'Checking for remaining set of utilities'
 1236 thecmd_testandset_fail grep grep
 1237 
 1238 # Before we step ahead with the other utilities perform a path cleanup first.
 1239 path_check PATH
 1240 
 1241 # awk(1) above
 1242 thecmd_testandset_fail basename basename
 1243 thecmd_testandset_fail cat cat
 1244 thecmd_testandset_fail chmod chmod
 1245 thecmd_testandset_fail cp cp
 1246 thecmd_testandset_fail cmp cmp
 1247 # grep(1) above
 1248 thecmd_testandset_fail mkdir mkdir
 1249 thecmd_testandset_fail mv mv
 1250 # rm(1) above
 1251 thecmd_testandset_fail sed sed
 1252 thecmd_testandset_fail sort sort
 1253 thecmd_testandset_fail tee tee
 1254 __PATH=${PATH}
 1255 thecmd_testandset chown chown ||
 1256    PATH="/sbin:${PATH}" thecmd_set chown chown ||
 1257    PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
 1258 PATH=${__PATH}
 1259 thecmd_testandset_fail MAKE make
 1260 make=${MAKE}
 1261 export MAKE
 1262 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
 1263 
 1264 # For ./cc-test.sh only
 1265 thecmd_testandset_fail cksum cksum
 1266 
 1267 # Update OPT_ options now, in order to get possible inter-dependencies right
 1268 option_update
 1269 
 1270 # (No functions since some shells loose non-exported variables in traps)
 1271 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
 1272 trap "trap \"\" HUP INT TERM EXIT;\
 1273    ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
 1274       ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
 1275 
 1276 # Our configuration options may at this point still contain shell snippets,
 1277 # we need to evaluate them in order to get them expanded, and we need those
 1278 # evaluated values not only in our new configuration file, but also at hand..
 1279 msg_nonl 'Evaluating all configuration items ... '
 1280 option_evaluate
 1281 msg 'done'
 1282 
 1283 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
 1284 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
 1285 
 1286 # The problem now is that the test should be able to run in the users linker
 1287 # and path environment, so we need to place the test: rule first, before
 1288 # injecting the relevant make variables.  Set up necessary environment
 1289 if [ -z "${VERBOSE}" ]; then
 1290    printf -- "ECHO_CC = @echo '  'CC \$(@);\n" >> ${newmk}
 1291    printf -- "ECHO_LINK = @echo '  'LINK \$(@);\n" >> ${newmk}
 1292    printf -- "ECHO_GEN = @echo '  'GEN \$(@);\n" >> ${newmk}
 1293    printf -- "ECHO_TEST = @\n" >> ${newmk}
 1294    printf -- "ECHO_CMD = @echo '  CMD';\n" >> ${newmk}
 1295    printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
 1296    printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
 1297 fi
 1298 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
 1299    "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
 1300 
 1301 # Add the known utility and some other variables
 1302 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
 1303 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
 1304 if feat_yes DOTLOCK; then
 1305    printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
 1306 else
 1307    printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
 1308 fi
 1309 
 1310 for i in \
 1311       SRCDIR \
 1312       awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
 1313       MAKE MAKEFLAGS make SHELL strip \
 1314       cksum; do
 1315    eval j=\$${i}
 1316    printf "${i} = ${j}\n" >> ${newmk}
 1317    printf "${i}=${j}\n" >> ${newlst}
 1318    printf "${i}=\"${j}\";export ${i}; " >> ${newev}
 1319 done
 1320 # Note that makefile reads and eval'uates one line of this file, whereas other
 1321 # consumers source it via .(1)
 1322 printf "\n" >> ${newev}
 1323 
 1324 # Build a basic set of INCS and LIBS according to user environment.
 1325 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
 1326 path_check C_INCLUDE_PATH -I _INCS
 1327 INCS="${INCS} ${_INCS}"
 1328 path_check LD_LIBRARY_PATH -L _LIBS
 1329 LIBS="${LIBS} ${_LIBS}"
 1330 unset _INCS _LIBS
 1331 export C_INCLUDE_PATH LD_LIBRARY_PATH
 1332 
 1333 # Some environments need runtime path flags to be able to go at all
 1334 ld_runtime_flags
 1335 
 1336 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
 1337 
 1338 cc_setup
 1339 
 1340 ${cat} > ${tmp}.c << \!
 1341 #include <stdio.h>
 1342 #include <string.h>
 1343 static void doit(char const *s);
 1344 int
 1345 main(int argc, char **argv){
 1346    (void)argc;
 1347    (void)argv;
 1348    doit("Hello world");
 1349    return 0;
 1350 }
 1351 static void
 1352 doit(char const *s){
 1353    char buf[12];
 1354    memcpy(buf, s, strlen(s) +1);
 1355    puts(s);
 1356 }
 1357 !
 1358 
 1359 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
 1360       -o ${tmp2} ${tmp}.c ${LIBS}; then
 1361    :
 1362 else
 1363    msg 'ERROR: i cannot compile a "Hello world" via'
 1364    msg '   %s' \
 1365    "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
 1366    msg 'ERROR:   Please read INSTALL, rerun'
 1367    config_exit 1
 1368 fi
 1369 
 1370 # This may also update ld_runtime_flags() (again)
 1371 cc_flags
 1372 
 1373 for i in \
 1374       INCS LIBS \
 1375       ; do
 1376    eval j=\$${i}
 1377    printf -- "${i}=${j}\n" >> ${newlst}
 1378 done
 1379 for i in \
 1380       CC \
 1381       CFLAGS \
 1382       LDFLAGS \
 1383       PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
 1384       OSFULLSPEC \
 1385       ; do
 1386    eval j=\$${i}
 1387    if [ -n "${j}" ]; then
 1388        printf -- "${i} = ${j}\n" >> ${newmk}
 1389        printf -- "${i}=${j}\n" >> ${newlst}
 1390    fi
 1391 done
 1392 
 1393 # Now finally check whether we already have a configuration and if so, whether
 1394 # all those parameters are still the same.. or something has actually changed
 1395 config_updated=
 1396 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
 1397    echo 'Configuration is up-to-date'
 1398    exit 0
 1399 elif [ -f ${lst} ]; then
 1400    config_updated=1
 1401    echo 'Configuration has been updated..'
 1402 else
 1403    echo 'Shiny configuration..'
 1404 fi
 1405 
 1406 # Time to redefine helper 1
 1407 config_exit() {
 1408    ${rm} -f ${lst} ${h} ${mk}
 1409    exit ${1}
 1410 }
 1411 
 1412 ${mv} -f ${newlst} ${lst}
 1413 ${mv} -f ${newev} ${ev}
 1414 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
 1415 ${mv} -f ${newh} ${h}
 1416 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
 1417 ${mv} -f ${newmk} ${mk}
 1418 
 1419 ## Compile and link checking
 1420 
 1421 tmp3=./${tmp0}3$$
 1422 log=./mk-config.log
 1423 lib=./mk-config.lib
 1424 inc=./mk-config.inc
 1425 makefile=./${tmp0}.mk
 1426 
 1427 # (No function since some shells loose non-exported variables in traps)
 1428 trap "trap \"\" HUP INT TERM;\
 1429    ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
 1430       HUP INT TERM
 1431 trap "trap \"\" HUP INT TERM EXIT;\
 1432    ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
 1433 
 1434 # Time to redefine helper 2
 1435 msg() {
 1436    fmt=${1}
 1437    shift
 1438    printf "*** ${fmt}\\n" "${@}"
 1439    printf -- "${fmt}\\n" "${@}" >&5
 1440 }
 1441 msg_nonl() {
 1442    fmt=${1}
 1443    shift
 1444    printf "*** ${fmt}\\n" "${@}"
 1445    printf -- "${fmt}" "${@}" >&5
 1446 }
 1447 
 1448 # !!
 1449 exec 5>&2 > ${log} 2>&1
 1450 
 1451 echo "${LIBS}" > ${lib}
 1452 echo "${INCS}" > ${inc}
 1453 ${cat} > ${makefile} << \!
 1454 .SUFFIXES: .o .c .x .y
 1455 .c.o:
 1456     $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
 1457 .c.x:
 1458     $(CC) -I./ $(XINCS) -E $(<) > $(@)
 1459 .c:
 1460     $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
 1461 !
 1462 
 1463 ## Generics
 1464 
 1465 # May be multiline..
 1466 echo >> ${h}
 1467 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
 1468 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
 1469 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
 1470 
 1471 # Generate n_err_number OS mappings
 1472 dump_test_program=0
 1473 (
 1474    feat_yes DEVEL && NV= || NV=noverbose
 1475    SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
 1476       ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
 1477 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
 1478 dump_test_program=1
 1479 
 1480 feat_def ALWAYS_UNICODE_LOCALE
 1481 feat_def AMALGAMATION 0
 1482 feat_def CROSS_BUILD
 1483 feat_def DOCSTRINGS
 1484 feat_def UISTRINGS
 1485 feat_def ERRORS
 1486 
 1487 feat_def ASAN_ADDRESS 0
 1488 feat_def ASAN_MEMORY 0
 1489 feat_def DEBUG 0
 1490 feat_def DEVEL 0
 1491 feat_def NYD2 0
 1492 feat_def NOMEMDBG 0
 1493 
 1494 if xrun_check inline 'inline functions' \
 1495    '#define HAVE_INLINE
 1496    #define n_INLINE static inline' << \!
 1497 static inline int ilf(int i){return ++i;}
 1498 int main(void){return ilf(-1);}
 1499 !
 1500 then
 1501    :
 1502 elif xrun_check inline 'inline functions (via __inline)' \
 1503    '#define HAVE_INLINE
 1504    #define n_INLINE static __inline' << \!
 1505 static __inline int ilf(int i){return ++i;}
 1506 int main(void){return ilf(-1);}
 1507 !
 1508 then
 1509    :
 1510 fi
 1511 
 1512 ## Test for "basic" system-calls / functionality that is used by all parts
 1513 ## of our program.  Once this is done fork away BASE_LIBS and other BASE_*
 1514 ## macros to be used by only the subprograms (potentially).
 1515 
 1516 if run_check clock_gettime 'clock_gettime(2)' \
 1517    '#define HAVE_CLOCK_GETTIME' << \!
 1518 #include <time.h>
 1519 # include <errno.h>
 1520 int main(void){
 1521    struct timespec ts;
 1522 
 1523    if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
 1524       return 0;
 1525    return 1;
 1526 }
 1527 !
 1528 then
 1529    :
 1530 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
 1531    '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
 1532 #include <time.h>
 1533 # include <errno.h>
 1534 int main(void){
 1535    struct timespec ts;
 1536 
 1537    if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
 1538       return 0;
 1539    return 1;
 1540 }
 1541 !
 1542 then
 1543    :
 1544 elif run_check gettimeofday 'gettimeofday(2)' \
 1545    '#define HAVE_GETTIMEOFDAY' << \!
 1546 #include <stdio.h> /* For C89 NULL */
 1547 #include <sys/time.h>
 1548 # include <errno.h>
 1549 int main(void){
 1550    struct timeval tv;
 1551 
 1552    if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
 1553       return 0;
 1554    return 1;
 1555 }
 1556 !
 1557 then
 1558    :
 1559 else
 1560    have_no_subsecond_time=1
 1561 fi
 1562 
 1563 if run_check nanosleep 'nanosleep(2)' \
 1564    '#define HAVE_NANOSLEEP' << \!
 1565 #include <time.h>
 1566 # include <errno.h>
 1567 int main(void){
 1568    struct timespec ts;
 1569 
 1570    ts.tv_sec = 1;
 1571    ts.tv_nsec = 100000;
 1572    if(!nanosleep(&ts, NULL) || errno != ENOSYS)
 1573       return 0;
 1574    return 1;
 1575 }
 1576 !
 1577 then
 1578    :
 1579 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
 1580    '#define HAVE_NANOSLEEP' '-lrt' << \!
 1581 #include <time.h>
 1582 # include <errno.h>
 1583 int main(void){
 1584    struct timespec ts;
 1585 
 1586    ts.tv_sec = 1;
 1587    ts.tv_nsec = 100000;
 1588    if(!nanosleep(&ts, NULL) || errno != ENOSYS)
 1589       return 0;
 1590    return 1;
 1591 }
 1592 !
 1593 then
 1594    :
 1595 # link_check is enough for this, that function is so old, trust the proto
 1596 elif link_check sleep 'sleep(3)' \
 1597    '#define HAVE_SLEEP' << \!
 1598 #include <unistd.h>
 1599 # include <errno.h>
 1600 int main(void){
 1601    if(!sleep(1) || errno != ENOSYS)
 1602       return 0;
 1603    return 1;
 1604 }
 1605 !
 1606 then
 1607    :
 1608 else
 1609    msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
 1610    config_exit 1
 1611 fi
 1612 
 1613 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
 1614 #include <pwd.h>
 1615 #include <unistd.h>
 1616 # include <errno.h>
 1617 int main(void){
 1618    struct passwd *pw;
 1619    gid_t gid;
 1620    uid_t uid;
 1621 
 1622    if((gid = getgid()) != 0)
 1623       gid = getegid();
 1624    if((uid = getuid()) != 0)
 1625       uid = geteuid();
 1626    if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
 1627       return 1;
 1628    if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
 1629       return 1;
 1630    return 0;
 1631 }
 1632 !
 1633 then
 1634    :
 1635 else
 1636    msg 'ERROR: we require user and group info / database searches.'
 1637    msg 'That much Unix we indulge ourselfs.'
 1638    config_exit 1
 1639 fi
 1640 
 1641 if link_check ftruncate 'ftruncate(2)' \
 1642    '#define HAVE_FTRUNCATE' << \!
 1643 #include <unistd.h>
 1644 #include <sys/types.h>
 1645 int main(void){
 1646    return (ftruncate(0, 0) != 0);
 1647 }
 1648 !
 1649 then
 1650    :
 1651 else
 1652    # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
 1653    msg 'ERROR: we require the ftruncate(2) system call.'
 1654    config_exit 1
 1655 fi
 1656 
 1657 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
 1658 #include <signal.h>
 1659 # include <errno.h>
 1660 int main(void){
 1661    struct sigaction nact, oact;
 1662 
 1663    nact.sa_handler = SIG_DFL;
 1664    sigemptyset(&nact.sa_mask);
 1665    nact.sa_flags = SA_RESTART;
 1666    return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
 1667 }
 1668 !
 1669 then
 1670    :
 1671 else
 1672    msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
 1673    config_exit 1
 1674 fi
 1675 
 1676 if link_check snprintf 'snprintf(3)' << \!
 1677 #include <stdio.h>
 1678 int main(void){
 1679    char b[20];
 1680 
 1681    snprintf(b, sizeof b, "%s", "string");
 1682    return 0;
 1683 }
 1684 !
 1685 then
 1686    :
 1687 else
 1688    msg 'ERROR: we require the snprintf(3) function.'
 1689    config_exit 1
 1690 fi
 1691 
 1692 if link_check environ 'environ(3)' << \!
 1693 #include <stdio.h> /* For C89 NULL */
 1694 int main(void){
 1695    extern char **environ;
 1696 
 1697    return environ[0] == NULL;
 1698 }
 1699 !
 1700 then
 1701    :
 1702 else
 1703    msg 'ERROR: we require the environ(3) array for subprocess control.'
 1704    config_exit 1
 1705 fi
 1706 
 1707 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
 1708 #include <stdlib.h>
 1709 int main(void){
 1710    setenv("s-mailx", "i want to see it cute!", 1);
 1711    unsetenv("s-mailx");
 1712    return 0;
 1713 }
 1714 !
 1715 then
 1716    :
 1717 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
 1718 #include <stdlib.h>
 1719 int main(void){
 1720    putenv("s-mailx=i want to see it cute!");
 1721    return 0;
 1722 }
 1723 !
 1724 then
 1725    :
 1726 else
 1727    msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
 1728    config_exit 1
 1729 fi
 1730 
 1731 if link_check termios 'termios.h and tc*(3) family' << \!
 1732 #include <termios.h>
 1733 int main(void){
 1734    struct termios tios;
 1735 
 1736    tcgetattr(0, &tios);
 1737    tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
 1738    return 0;
 1739 }
 1740 !
 1741 then
 1742    :
 1743 else
 1744    msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
 1745    msg 'That much Unix we indulge ourselfs.'
 1746    config_exit 1
 1747 fi
 1748 
 1749 ## optional stuff
 1750 
 1751 if link_check vsnprintf 'vsnprintf(3)' << \!
 1752 #include <stdarg.h>
 1753 #include <stdio.h>
 1754 static void dome(char *buf, size_t blen, ...){
 1755    va_list ap;
 1756 
 1757    va_start(ap, blen);
 1758    vsnprintf(buf, blen, "%s", ap);
 1759    va_end(ap);
 1760 }
 1761 int main(void){
 1762    char b[20];
 1763 
 1764    dome(b, sizeof b, "string");
 1765    return 0;
 1766 }
 1767 !
 1768 then
 1769    :
 1770 else
 1771    feat_bail_required ERRORS
 1772 fi
 1773 
 1774 if [ "${have_vsnprintf}" = yes ]; then
 1775    __va_copy() {
 1776       link_check va_copy "va_copy(3) (as ${2})" \
 1777          "#define HAVE_N_VA_COPY
 1778 #define n_va_copy ${2}" <<_EOT
 1779 #include <stdarg.h>
 1780 #include <stdio.h>
 1781 #if ${1}
 1782 # if defined __va_copy && !defined va_copy
 1783 #  define va_copy __va_copy
 1784 # endif
 1785 #endif
 1786 static void dome2(char *buf, size_t blen, va_list src){
 1787    va_list ap;
 1788 
 1789    va_copy(ap, src);
 1790    vsnprintf(buf, blen, "%s", ap);
 1791    va_end(ap);
 1792 }
 1793 static void dome(char *buf, size_t blen, ...){
 1794    va_list ap;
 1795 
 1796    va_start(ap, blen);
 1797    dome2(buf, blen, ap);
 1798    va_end(ap);
 1799 }
 1800 int main(void){
 1801    char b[20];
 1802 
 1803    dome(b, sizeof b, "string");
 1804    return 0;
 1805 }
 1806 _EOT
 1807    }
 1808    __va_copy 0 va_copy || __va_copy 1 __va_copy
 1809 fi
 1810 
 1811 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
 1812 #include <unistd.h>
 1813 #include <errno.h>
 1814 int main(void){
 1815    int rv = 0;
 1816 
 1817    errno = 0;
 1818    rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
 1819    errno = 0;
 1820    rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
 1821 
 1822    /* Only link check */
 1823    fpathconf(0, _PC_NAME_MAX);
 1824 
 1825    return rv;
 1826 }
 1827 !
 1828 
 1829 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
 1830 #include <fcntl.h>
 1831 #include <unistd.h>
 1832 # include <errno.h>
 1833 int main(void){
 1834    int fds[2];
 1835 
 1836    if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
 1837       return 0;
 1838    return 1;
 1839 }
 1840 !
 1841 
 1842 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
 1843 #include <termios.h>
 1844 int main(void){
 1845    struct winsize ws;
 1846 
 1847    tcgetwinsize(0, &ws);
 1848    return 0;
 1849 }
 1850 !
 1851 
 1852 # We use this only then for now (need NOW+1)
 1853 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
 1854 #include <fcntl.h> /* For AT_* */
 1855 #include <sys/stat.h>
 1856 # include <errno.h>
 1857 int main(void){
 1858    struct timespec ts[2];
 1859 
 1860    ts[0].tv_nsec = UTIME_NOW;
 1861    ts[1].tv_nsec = UTIME_OMIT;
 1862    if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
 1863       return 0;
 1864    return 1;
 1865 }
 1866 !
 1867 
 1868 ##
 1869 
 1870 # The random check has been moved to below SSL detection due to multiple choice
 1871 # selection for PRG sources
 1872 
 1873 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
 1874 #include <stdio.h>
 1875 int main(void){
 1876    putc_unlocked('@', stdout);
 1877    return 0;
 1878 }
 1879 !
 1880 
 1881 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
 1882 #include <unistd.h>
 1883 int main(void){
 1884    fchdir(0);
 1885    return 0;
 1886 }
 1887 !
 1888 
 1889 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
 1890 #include <stdlib.h>
 1891 int main(void){
 1892    char x_buf[4096], *x = realpath(".", x_buf);
 1893 
 1894    return (x != NULL) ? 0 : 1;
 1895 }
 1896 !
 1897 then
 1898    if run_check realpath_malloc 'realpath(3) takes NULL' \
 1899          '#define HAVE_REALPATH_NULL' << \!
 1900 #include <stdlib.h>
 1901 int main(void){
 1902    char *x = realpath(".", NULL);
 1903 
 1904    if(x != NULL)
 1905       free(x);
 1906    return (x != NULL) ? 0 : 1;
 1907 }
 1908 !
 1909    then
 1910       :
 1911    fi
 1912 fi
 1913 
 1914 ##
 1915 ## optional and selectable
 1916 ##
 1917 
 1918 if feat_yes DOTLOCK; then
 1919    if run_check readlink 'readlink(2)' << \!
 1920 #include <unistd.h>
 1921 # include <errno.h>
 1922 int main(void){
 1923    char buf[128];
 1924 
 1925    if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
 1926       return 0;
 1927    return 1;
 1928 }
 1929 !
 1930    then
 1931       :
 1932    else
 1933       feat_bail_required DOTLOCK
 1934    fi
 1935 fi
 1936 
 1937 if feat_yes DOTLOCK; then
 1938    if run_check fchown 'fchown(2)' << \!
 1939 #include <unistd.h>
 1940 # include <errno.h>
 1941 int main(void){
 1942    if(!fchown(0, 0, 0) || errno != ENOSYS)
 1943       return 0;
 1944    return 1;
 1945 }
 1946 !
 1947    then
 1948       :
 1949    else
 1950       feat_bail_required DOTLOCK
 1951    fi
 1952 fi
 1953 
 1954 if feat_yes DOTLOCK; then
 1955    if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
 1956          '#define HAVE_PRCTL_DUMPABLE' << \!
 1957 #include <sys/prctl.h>
 1958 # include <errno.h>
 1959 int main(void){
 1960    if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
 1961       return 0;
 1962    return 1;
 1963 }
 1964 !
 1965    then
 1966       :
 1967    elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
 1968          '#define HAVE_PTRACE_DENY' << \!
 1969 #include <sys/ptrace.h>
 1970 # include <errno.h>
 1971 int main(void){
 1972    if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
 1973       return 0;
 1974    return 1;
 1975 }
 1976 !
 1977    then
 1978       :
 1979    elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
 1980          '#define HAVE_SETPFLAGS_PROTECT' << \!
 1981 #include <priv.h>
 1982 # include <errno.h>
 1983 int main(void){
 1984    if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
 1985       return 0;
 1986    return 1;
 1987 }
 1988 !
 1989    then
 1990       :
 1991    fi
 1992 fi
 1993 
 1994 ## Now it is the time to fork away the BASE_ series
 1995 
 1996 ${rm} -f ${tmp}
 1997 squeeze_em ${inc} ${tmp}
 1998 ${mv} ${tmp} ${inc}
 1999 squeeze_em ${lib} ${tmp}
 2000 ${mv} ${tmp} ${lib}
 2001 
 2002 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
 2003 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
 2004 
 2005 ## The remains are expected to be used only by the main MUA binary!
 2006 
 2007 OPT_LOCALES=0
 2008 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
 2009 #include <locale.h>
 2010 int main(void){
 2011    setlocale(LC_ALL, "");
 2012    return 0;
 2013 }
 2014 !
 2015 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
 2016 
 2017 OPT_MULTIBYTE_CHARSETS=0
 2018 OPT_WIDE_GLYPHS=0
 2019 OPT_TERMINAL_CHARSET=0
 2020 if [ -n "${have_setlocale}" ]; then
 2021    link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
 2022       '#define HAVE_C90AMEND1' << \!
 2023 #include <limits.h>
 2024 #include <stdlib.h>
 2025 #include <wchar.h>
 2026 #include <wctype.h>
 2027 int main(void){
 2028    char mbb[MB_LEN_MAX + 1];
 2029    wchar_t wc;
 2030 
 2031    iswprint(L'c');
 2032    towupper(L'c');
 2033    mbtowc(&wc, "x", 1);
 2034    mbrtowc(&wc, "x", 1, NULL);
 2035    wctomb(mbb, wc);
 2036    return (mblen("\0", 1) == 0);
 2037 }
 2038 !
 2039    [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
 2040 
 2041    if [ -n "${have_c90amend1}" ]; then
 2042       link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
 2043 #include <wchar.h>
 2044 int main(void){
 2045    wcwidth(L'c');
 2046    return 0;
 2047 }
 2048 !
 2049       [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
 2050    fi
 2051 
 2052    link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
 2053 #include <langinfo.h>
 2054 #include <stdlib.h>
 2055 int main(void){
 2056    nl_langinfo(DAY_1);
 2057    return (nl_langinfo(CODESET) == NULL);
 2058 }
 2059 !
 2060    [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
 2061 fi # have_setlocale
 2062 
 2063 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
 2064 #include <fnmatch.h>
 2065 int main(void){
 2066    return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
 2067 }
 2068 !
 2069 
 2070 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
 2071 #include <dirent.h>
 2072 int main(void){
 2073    struct dirent de;
 2074    return !(de.d_type == DT_UNKNOWN ||
 2075       de.d_type == DT_DIR || de.d_type == DT_LNK);
 2076 }
 2077 !
 2078 
 2079 ## optional and selectable
 2080 
 2081 if feat_yes ICONV; then
 2082    # To be able to create tests we need to figure out which replacement
 2083    # sequence the iconv(3) implementation creates
 2084    ${cat} > ${tmp2}.c << \!
 2085 #include <stdio.h> /* For C89 NULL */
 2086 #include <string.h>
 2087 #include <iconv.h>
 2088 int main(void){
 2089    char inb[16], oub[16], *inbp, *oubp;
 2090    iconv_t id;
 2091    size_t inl, oul;
 2092 
 2093    memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
 2094    inl = sizeof("\342\200\223") -1;
 2095    oul = sizeof oub;
 2096    oubp = oub;
 2097 
 2098    if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
 2099      return 1;
 2100    if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
 2101       return 1;
 2102    iconv_close(id);
 2103 
 2104    *oubp = '\0';
 2105    oul = (size_t)(oubp - oub);
 2106    if(oul == 0)
 2107       return 1;
 2108    /* Character-wise replacement? */
 2109    if(oul == 1){
 2110       if(oub[0] == '?')
 2111          return 2;
 2112       if(oub[0] == '*')
 2113          return 3;
 2114       return 1;
 2115    }
 2116    /* Byte-wise replacement? */
 2117    if(oul == sizeof("\342\200\223") -1){
 2118       if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
 2119          return 12;
 2120       if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
 2121          return 13;
 2122       return 1;
 2123    }
 2124    return 0;
 2125 }
 2126 !
 2127    < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
 2128          '#define HAVE_ICONV' ||
 2129       < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
 2130          '#define HAVE_ICONV' '-liconv' ||
 2131       feat_bail_required ICONV
 2132 
 2133    if feat_no CROSS_BUILD; then
 2134       { ./${tmp}; } >/dev/null 2>&1
 2135       case ${?} in
 2136       2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
 2137       3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
 2138       12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
 2139       13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
 2140       *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
 2141       esac
 2142    fi
 2143 else
 2144    feat_is_disabled ICONV
 2145 fi # feat_yes ICONV
 2146 
 2147 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
 2148    ${cat} > ${tmp2}.c << \!
 2149 #include <sys/types.h>
 2150 #include <sys/socket.h>
 2151 #include <sys/un.h>
 2152 # include <errno.h>
 2153 int main(void){
 2154    struct sockaddr_un soun;
 2155 
 2156    if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
 2157       return 1;
 2158    if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
 2159       return 1;
 2160    if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
 2161       return 1;
 2162    return 0;
 2163 }
 2164 !
 2165 
 2166    < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
 2167          '#define HAVE_UNIX_SOCKETS' ||
 2168       < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
 2169          '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
 2170       < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
 2171          '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
 2172 fi
 2173 
 2174 if feat_yes SOCKETS; then
 2175    ${cat} > ${tmp2}.c << \!
 2176 #include <sys/types.h>
 2177 #include <sys/socket.h>
 2178 #include <netinet/in.h>
 2179 # include <errno.h>
 2180 int main(void){
 2181    struct sockaddr s;
 2182 
 2183    if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
 2184       return 1;
 2185    if(connect(0, &s, 0) == -1 && errno == ENOSYS)
 2186       return 1;
 2187    return 0;
 2188 }
 2189 !
 2190 
 2191    < ${tmp2}.c run_check sockets 'sockets' \
 2192          '#define HAVE_SOCKETS' ||
 2193       < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
 2194          '#define HAVE_SOCKETS' '-lnsl' ||
 2195       < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
 2196          '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
 2197       feat_bail_required SOCKETS
 2198 else
 2199    feat_is_disabled SOCKETS
 2200 fi # feat_yes SOCKETS
 2201 
 2202 if feat_yes SOCKETS; then
 2203    link_check getaddrinfo 'getaddrinfo(3)' \
 2204       '#define HAVE_GETADDRINFO' << \!
 2205 #include <sys/types.h>
 2206 #include <sys/socket.h>
 2207 #include <stdio.h>
 2208 #include <netdb.h>
 2209 int main(void){
 2210    struct addrinfo a, *ap;
 2211    int lrv;
 2212 
 2213    switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
 2214    case EAI_NONAME:
 2215    case EAI_SERVICE:
 2216    default:
 2217       fprintf(stderr, "%s\n", gai_strerror(lrv));
 2218    case 0:
 2219       break;
 2220    }
 2221    return 0;
 2222 }
 2223 !
 2224 fi
 2225 
 2226 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
 2227    compile_check arpa_inet_h '<arpa/inet.h>' \
 2228       '#define HAVE_ARPA_INET_H' << \!
 2229 #include <sys/types.h>
 2230 #include <sys/socket.h>
 2231 #include <netdb.h>
 2232 #include <netinet/in.h>
 2233 #include <arpa/inet.h>
 2234 !
 2235 
 2236    ${cat} > ${tmp2}.c << \!
 2237 #include <sys/types.h>
 2238 #include <sys/socket.h>
 2239 #include <stdio.h>
 2240 #include <string.h>
 2241 #include <netdb.h>
 2242 #include <netinet/in.h>
 2243 #ifdef HAVE_ARPA_INET_H
 2244 #include <arpa/inet.h>
 2245 #endif
 2246 int main(void){
 2247    struct sockaddr_in servaddr;
 2248    unsigned short portno;
 2249    struct servent *ep;
 2250    struct hostent *hp;
 2251    struct in_addr **pptr;
 2252 
 2253    portno = 0;
 2254    if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
 2255       portno = (unsigned short)ep->s_port;
 2256 
 2257    if((hp = gethostbyname("POPPY-HOST")) != NULL){
 2258       pptr = (struct in_addr**)hp->h_addr_list;
 2259       if(hp->h_addrtype != AF_INET)
 2260          fprintf(stderr, "au\n");
 2261    }else{
 2262       switch(h_errno){
 2263       case HOST_NOT_FOUND:
 2264       case TRY_AGAIN:
 2265       case NO_RECOVERY:
 2266       case NO_DATA:
 2267          break;
 2268       default:
 2269          fprintf(stderr, "au\n");
 2270          break;
 2271       }
 2272    }
 2273 
 2274    memset(&servaddr, 0, sizeof servaddr);
 2275    servaddr.sin_family = AF_INET;
 2276    servaddr.sin_port = htons(portno);
 2277    memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
 2278    fprintf(stderr, "Would connect to %s:%d ...\n",
 2279       inet_ntoa(**pptr), (int)portno);
 2280    return 0;
 2281 }
 2282 !
 2283 
 2284    < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
 2285       < ${tmp2}.c link_check gethostbyname \
 2286          'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
 2287       < ${tmp2}.c link_check gethostbyname \
 2288          'get(serv|host)byname(3) (via -lsocket -nsl)' \
 2289          '' '-lsocket -lnsl' ||
 2290       feat_bail_required SOCKETS
 2291 fi
 2292 
 2293 feat_yes SOCKETS &&
 2294 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
 2295 #include <sys/socket.h>
 2296 #include <stdlib.h>
 2297 # include <errno.h>
 2298 int main(void){
 2299    int sockfd = 3;
 2300 
 2301    if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
 2302          errno == ENOSYS)
 2303       return 1;
 2304    return 0;
 2305 }
 2306 !
 2307 
 2308 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
 2309 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
 2310 #include <sys/socket.h>
 2311 #include <stdlib.h>
 2312 int main(void){
 2313    struct timeval tv;
 2314    int sockfd = 3;
 2315 
 2316    tv.tv_sec = 42;
 2317    tv.tv_usec = 21;
 2318    setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
 2319    setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
 2320    return 0;
 2321 }
 2322 !
 2323 
 2324 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
 2325 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
 2326 #include <sys/socket.h>
 2327 #include <stdlib.h>
 2328 int main(void){
 2329    struct linger li;
 2330    int sockfd = 3;
 2331 
 2332    li.l_onoff = 1;
 2333    li.l_linger = 42;
 2334    setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
 2335    return 0;
 2336 }
 2337 !
 2338 
 2339 VAL_SSL_FEATURES=
 2340 if feat_yes SSL; then # {{{
 2341    # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
 2342    # instead of keeping it at the one that corresponds to the OpenSSL at fork
 2343    # time: we need to test it first in order to get things right
 2344    if compile_check _xssl 'TLS/SSL (LibreSSL)' \
 2345       '#define HAVE_SSL
 2346       #define HAVE_XSSL
 2347       #define HAVE_XSSL_RESSL
 2348       #define HAVE_XSSL_OPENSSL 0' << \!
 2349 #include <openssl/opensslv.h>
 2350 #ifdef LIBRESSL_VERSION_NUMBER
 2351 #else
 2352 # error nope
 2353 #endif
 2354 !
 2355    then
 2356       ossl_v1_1=
 2357       VAL_SSL_FEATURES=libressl
 2358    # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
 2359    elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
 2360       '#define HAVE_SSL
 2361       #define HAVE_XSSL
 2362       #define HAVE_XSSL_OPENSSL 0x10100' << \!
 2363 #include <openssl/opensslv.h>
 2364 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
 2365 #else
 2366 # error nope
 2367 #endif
 2368 !
 2369    then
 2370       ossl_v1_1=1
 2371       VAL_SSL_FEATURES=libssl-0x10100
 2372    elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
 2373       '#define HAVE_SSL
 2374       #define HAVE_XSSL
 2375       #define HAVE_XSSL_OPENSSL 0x10000' << \!
 2376 #include <openssl/opensslv.h>
 2377 #ifdef OPENSSL_VERSION_NUMBER
 2378 #else
 2379 # error nope
 2380 #endif
 2381 !
 2382    then
 2383       ossl_v1_1=
 2384       VAL_SSL_FEATURES=libssl-0x10000
 2385    else
 2386       feat_bail_required SSL
 2387    fi # }}}
 2388 
 2389    if feat_yes SSL; then # {{{
 2390       if [ -n "${ossl_v1_1}" ]; then
 2391          without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
 2392             '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
 2393             '-lssl -lcrypto'
 2394       elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
 2395             '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
 2396             '-lssl -lcrypto' << \!
 2397 #include <openssl/ssl.h>
 2398 #include <openssl/err.h>
 2399 #include <openssl/x509v3.h>
 2400 #include <openssl/x509.h>
 2401 #include <openssl/rand.h>
 2402 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
 2403 # error We need TLSv1.
 2404 #endif
 2405 int main(void){
 2406    SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
 2407 
 2408    SSL_CTX_free(ctx);
 2409    PEM_read_PrivateKey(0, 0, 0, 0);
 2410    return 0;
 2411 }
 2412 !
 2413       then
 2414          :
 2415       elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
 2416             '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
 2417             '-lssl -lcrypto' << \!
 2418 #include <openssl/ssl.h>
 2419 #include <openssl/err.h>
 2420 #include <openssl/x509v3.h>
 2421 #include <openssl/x509.h>
 2422 #include <openssl/rand.h>
 2423 #if defined OPENSSL_NO_SSL3 &&\
 2424       defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
 2425 # error We need one of SSLv3 and TLSv1.
 2426 #endif
 2427 int main(void){
 2428    SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
 2429 
 2430    SSL_CTX_free(ctx);
 2431    PEM_read_PrivateKey(0, 0, 0, 0);
 2432    return 0;
 2433 }
 2434 !
 2435       then
 2436          :
 2437       else
 2438          feat_bail_required SSL
 2439       fi
 2440    fi # }}}
 2441 
 2442    if feat_yes SSL; then # {{{
 2443       if feat_yes SSL_ALL_ALGORITHMS; then
 2444          if [ -n "${ossl_v1_1}" ]; then
 2445             without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
 2446                '#define HAVE_SSL_ALL_ALGORITHMS'
 2447          elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
 2448             '#define HAVE_SSL_ALL_ALGORITHMS' << \!
 2449 #include <openssl/evp.h>
 2450 int main(void){
 2451    OpenSSL_add_all_algorithms();
 2452    EVP_get_cipherbyname("two cents i never exist");
 2453    EVP_cleanup();
 2454    return 0;
 2455 }
 2456 !
 2457          then
 2458             :
 2459          else
 2460             feat_bail_required SSL_ALL_ALGORITHMS
 2461          fi
 2462       elif [ -n "${ossl_v1_1}" ]; then
 2463          without_check yes ssl_all_algo \
 2464             'TLS/SSL all-algorithms (always available in v1.1.0+)' \
 2465             '#define HAVE_SSL_ALL_ALGORITHMS'
 2466       fi
 2467 
 2468       if [ -n "${ossl_v1_1}" ]; then
 2469          without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
 2470             '#define HAVE_XSSL_STACK_OF'
 2471       elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
 2472             '#define HAVE_XSSL_STACK_OF' << \!
 2473 #include <stdio.h> /* For C89 NULL */
 2474 #include <openssl/ssl.h>
 2475 #include <openssl/err.h>
 2476 #include <openssl/x509v3.h>
 2477 #include <openssl/x509.h>
 2478 #include <openssl/rand.h>
 2479 int main(void){
 2480    STACK_OF(GENERAL_NAME) *gens = NULL;
 2481 
 2482    printf("%p", gens); /* to use it */
 2483    return 0;
 2484 }
 2485 !
 2486       then
 2487          :
 2488       fi
 2489 
 2490       if [ -n "${ossl_v1_1}" ]; then
 2491          without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
 2492             '#define HAVE_XSSL_CONFIG'
 2493          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
 2494       elif link_check xssl_conf \
 2495             'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
 2496             '#define HAVE_XSSL_CONFIG' << \!
 2497 #include <stdio.h> /* For C89 NULL */
 2498 #include <openssl/conf.h>
 2499 int main(void){
 2500    CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
 2501    CONF_modules_free();
 2502    return 0;
 2503 }
 2504 !
 2505       then
 2506          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
 2507       else
 2508          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
 2509       fi
 2510 
 2511       if [ -n "${ossl_v1_1}" ]; then
 2512          without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
 2513             '#define HAVE_XSSL_CONF_CTX'
 2514          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
 2515       elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
 2516          '#define HAVE_XSSL_CONF_CTX' << \!
 2517 #include <openssl/ssl.h>
 2518 #include <openssl/err.h>
 2519 int main(void){
 2520    SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
 2521    SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
 2522 
 2523    SSL_CONF_CTX_set_flags(cctx,
 2524       SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
 2525       SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
 2526    SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
 2527    SSL_CONF_cmd(cctx, "Protocol", "ALL");
 2528    SSL_CONF_CTX_finish(cctx);
 2529    SSL_CONF_CTX_free(cctx);
 2530    SSL_CTX_free(ctx);
 2531    return 0;
 2532 }
 2533 !
 2534       then
 2535          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
 2536       else
 2537          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
 2538       fi
 2539 
 2540       if [ -n "${ossl_v1_1}" ]; then
 2541          without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
 2542             '#define HAVE_XSSL_CTX_CONFIG'
 2543          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
 2544       elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
 2545             link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
 2546                '#define HAVE_XSSL_CTX_CONFIG' << \!
 2547 #include <stdio.h> /* For C89 NULL */
 2548 #include <openssl/ssl.h>
 2549 int main(void){
 2550    SSL_CTX_config(NULL, "SOMEVAL");
 2551    return 0;
 2552 }
 2553 !
 2554       then
 2555          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
 2556       else
 2557          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
 2558       fi
 2559 
 2560       if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
 2561          without_check yes xssl_set_maxmin_proto \
 2562             'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
 2563             '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
 2564          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
 2565       elif link_check xssl_set_maxmin_proto \
 2566          'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
 2567          '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
 2568 #include <stdio.h> /* For C89 NULL */
 2569 #include <openssl/ssl.h>
 2570 int main(void){
 2571    SSL_CTX_set_min_proto_version(NULL, 0);
 2572    SSL_CTX_set_max_proto_version(NULL, 10);
 2573    return 0;
 2574 }
 2575 !
 2576       then
 2577          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
 2578       else
 2579          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
 2580       fi
 2581 
 2582       if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
 2583             '#define HAVE_XSSL_RAND_EGD' << \!
 2584 #include <openssl/rand.h>
 2585 int main(void){
 2586    return RAND_egd("some.where") > 0;
 2587 }
 2588 !
 2589       then
 2590          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
 2591       else
 2592          VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
 2593       fi
 2594    fi # feat_yes SSL }}}
 2595 
 2596    if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
 2597       run_check ssl_md5 'MD5 digest in the used crypto library' \
 2598             '#define HAVE_XSSL_MD5' << \!
 2599 #include <stdlib.h>
 2600 #include <string.h>
 2601 #include <openssl/md5.h>
 2602 int main(void){
 2603    char const dat[] = "abrakadabrafidibus";
 2604    char dig[16], hex[16 * 2];
 2605    MD5_CTX ctx;
 2606    size_t i, j;
 2607 
 2608    memset(dig, 0, sizeof(dig));
 2609    memset(hex, 0, sizeof(hex));
 2610    MD5_Init(&ctx);
 2611    MD5_Update(&ctx, dat, sizeof(dat) - 1);
 2612    MD5_Final(dig, &ctx);
 2613 
 2614 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
 2615    for(i = 0; i < sizeof(hex) / 2; i++){
 2616       j = i << 1;
 2617       hex[j] = hexchar((dig[i] & 0xf0) >> 4);
 2618       hex[++j] = hexchar(dig[i] & 0x0f);
 2619    }
 2620    return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
 2621 }
 2622 !
 2623    fi # }}}
 2624 
 2625    if feat_yes SSL; then
 2626       feat_def SSL_ALL_ALGORITHMS
 2627    else
 2628       feat_bail_required SSL_ALL_ALGORITHMS
 2629    fi
 2630 else
 2631    feat_is_disabled SSL
 2632    feat_is_disabled SSL_ALL_ALGORITHMS
 2633 fi # }}} feat_yes SSL
 2634 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
 2635 
 2636 if [ "${have_xssl}" = yes ]; then
 2637    OPT_SMIME=1
 2638 else
 2639    OPT_SMIME=0
 2640 fi
 2641 feat_def SMIME
 2642 
 2643 # VAL_RANDOM {{{
 2644 if val_allof VAL_RANDOM \
 2645       "arc4 ssl libgetrandom sysgetrandom urandom builtin error"; then
 2646    :
 2647 else
 2648    msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
 2649    config_exit 1
 2650 fi
 2651 
 2652 val_random_arc4() {
 2653    link_check arc4random 'VAL_RANDOM: arc4random(3)' \
 2654       '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
 2655 #include <stdlib.h>
 2656 int main(void){
 2657    arc4random();
 2658    return 0;
 2659 }
 2660 !
 2661 }
 2662 
 2663 val_random_ssl() {
 2664    if feat_yes SSL; then
 2665       msg ' . VAL_RANDOM: ssl ... yes'
 2666       echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
 2667       return 0
 2668    else
 2669       msg ' . VAL_RANDOM: ssl ... no'
 2670       return 1
 2671    fi
 2672 }
 2673 
 2674 val_random_libgetrandom() {
 2675    link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
 2676       '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
 2677       #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
 2678       #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
 2679 #include <sys/random.h>
 2680 int main(void){
 2681    char buf[256];
 2682    getrandom(buf, sizeof buf, 0);
 2683    return 0;
 2684 }
 2685 !
 2686 }
 2687 
 2688 val_random_sysgetrandom() {
 2689    link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
 2690       '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
 2691       #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
 2692       #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
 2693 #include <sys/syscall.h>
 2694 int main(void){
 2695    char buf[256];
 2696    syscall(SYS_getrandom, buf, sizeof buf, 0);
 2697    return 0;
 2698 }
 2699 !
 2700 }
 2701 
 2702 val_random_urandom() {
 2703    msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
 2704    if feat_yes CROSS_BUILD; then
 2705       msg 'yes (unchecked)'
 2706       echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
 2707    elif [ -f /dev/urandom ]; then
 2708       msg yes
 2709       echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
 2710    else
 2711       msg no
 2712       return 1
 2713    fi
 2714    return 0
 2715 }
 2716 
 2717 val_random_builtin() {
 2718    msg_nonl ' . VAL_RANDOM: builtin ... '
 2719    if [ -n "${have_no_subsecond_time}" ]; then
 2720       msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
 2721          'one of clock_gettime(2) and gettimeofday(2) is required.'
 2722       config_exit 1
 2723    else
 2724       msg yes
 2725       echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
 2726    fi
 2727 }
 2728 
 2729 val_random_error() {
 2730    msg 'ERROR: VAL_RANDOM search reached "error" entry'
 2731    config_exit 42
 2732 }
 2733 
 2734 oifs=${IFS}
 2735 unset IFS
 2736 VAL_RANDOM="${VAL_RANDOM} error"
 2737 set -- ${VAL_RANDOM}
 2738 IFS=${oifs}
 2739 for randfun
 2740 do
 2741    eval val_random_$randfun && break
 2742 done
 2743 # }}} VAL_RANDOM
 2744 
 2745 feat_def SMTP
 2746 feat_def POP3
 2747 feat_def IMAP
 2748 
 2749 if feat_yes GSSAPI; then
 2750    ${cat} > ${tmp2}.c << \!
 2751 #include <gssapi/gssapi.h>
 2752 int main(void){
 2753    gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
 2754    gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
 2755    return 0;
 2756 }
 2757 !
 2758    ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
 2759 
 2760    if acmd_set i krb5-config; then
 2761       GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
 2762       GSS_INCS="`CFLAGS= ${i} --cflags`"
 2763       i='GSS-API via krb5-config(1)'
 2764    else
 2765       GSS_LIBS='-lgssapi'
 2766       GSS_INCS=
 2767       i='GSS-API in gssapi/gssapi.h, libgssapi'
 2768    fi
 2769    if < ${tmp2}.c link_check gss \
 2770          "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
 2771       < ${tmp3}.c link_check gss \
 2772          'GSS-API in gssapi.h, libgssapi' \
 2773          '#define HAVE_GSSAPI
 2774          #define GSSAPI_REG_INCLUDE' \
 2775          '-lgssapi' ||\
 2776       < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
 2777          '#define HAVE_GSSAPI' \
 2778          '-lgssapi_krb5' ||\
 2779       < ${tmp3}.c link_check gss \
 2780          'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
 2781          '#define HAVE_GSSAPI
 2782          #define GSS_REG_INCLUDE' \
 2783          '-lgssapi -lkrb5 -lcrypto' \
 2784          '-I/usr/include/kerberosV' ||\
 2785       < ${tmp2}.c link_check gss 'GSS-API in libgss' \
 2786          '#define HAVE_GSSAPI' \
 2787          '-lgss' ||\
 2788       link_check gss 'GSS-API in libgssapi_krb5, old-style' \
 2789          '#define HAVE_GSSAPI
 2790          #define GSSAPI_OLD_STYLE' \
 2791          '-lgssapi_krb5' << \!
 2792 #include <gssapi/gssapi.h>
 2793 #include <gssapi/gssapi_generic.h>
 2794 int main(void){
 2795    gss_import_name(0, 0, gss_nt_service_name, 0);
 2796    gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
 2797    return 0;
 2798 }
 2799 !
 2800    then
 2801       :
 2802    else
 2803       feat_bail_required GSSAPI
 2804    fi
 2805 else
 2806    feat_is_disabled GSSAPI
 2807 fi # feat_yes GSSAPI
 2808 
 2809 feat_def NETRC
 2810 feat_def AGENT
 2811 
 2812 if feat_yes IDNA; then # {{{
 2813    if val_allof VAL_IDNA "idnkit idn2 idn"; then
 2814       :
 2815    else
 2816       msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
 2817       config_exit 1
 2818    fi
 2819 
 2820    val_idna_idn2() {
 2821       link_check idna 'OPT_IDNA: GNU Libidn2' \
 2822          '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
 2823 #include <idn2.h>
 2824 int main(void){
 2825    char *idna_utf8, *idna_lc;
 2826 
 2827    if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
 2828          IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
 2829       return 1;
 2830    if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
 2831       return 1;
 2832    idn2_free(idna_lc);
 2833    idn2_free(idna_utf8);
 2834    return 0;
 2835 }
 2836 !
 2837    }
 2838 
 2839    val_idna_idn() {
 2840       link_check idna 'OPT_IDNA: GNU Libidn' \
 2841          '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
 2842 #include <idna.h>
 2843 #include <idn-free.h>
 2844 #include <stringprep.h> /* XXX we actually use our own iconv instead */
 2845 int main(void){
 2846    char *utf8, *idna_ascii, *idna_utf8;
 2847 
 2848    utf8 = stringprep_locale_to_utf8("does.this.work");
 2849    if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
 2850          != IDNA_SUCCESS)
 2851       return 1;
 2852    idn_free(idna_ascii);
 2853    /* (Rather link check only here) */
 2854    idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
 2855    return 0;
 2856 }
 2857 !
 2858    }
 2859 
 2860    val_idna_idnkit() {
 2861       link_check idna 'OPT_IDNA: idnkit' \
 2862          '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
 2863 #include <stdio.h>
 2864 #include <idn/api.h>
 2865 #include <idn/result.h>
 2866 int main(void){
 2867    idn_result_t r;
 2868    char ace_name[256];
 2869    char local_name[256];
 2870 
 2871    r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
 2872          sizeof(ace_name));
 2873    if (r != idn_success) {
 2874       fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
 2875       return 1;
 2876    }
 2877    r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
 2878    if (r != idn_success) {
 2879       fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
 2880       return 1;
 2881    }
 2882    return 0;
 2883 }
 2884 !
 2885    }
 2886 
 2887    val_idna_bye() {
 2888       feat_bail_required IDNA
 2889    }
 2890 
 2891    oifs=${IFS}
 2892    unset IFS
 2893    VAL_IDNA="${VAL_IDNA} bye"
 2894    set -- ${VAL_IDNA}
 2895    IFS=${oifs}
 2896    for randfun
 2897    do
 2898       eval val_idna_$randfun && break
 2899    done
 2900 else
 2901    feat_is_disabled IDNA
 2902 fi # }}} IDNA
 2903 
 2904 feat_def IMAP_SEARCH
 2905 
 2906 if feat_yes REGEX; then
 2907    if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
 2908 #include <regex.h>
 2909 #include <stdlib.h>
 2910 int main(void){
 2911    size_t xret;
 2912    int status;
 2913    regex_t re;
 2914 
 2915    status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
 2916    xret = regerror(status, &re, NULL, 0);
 2917    status = regexec(&re, "plan9", 0,NULL, 0);
 2918    regfree(&re);
 2919    return !(status == REG_NOMATCH);
 2920 }
 2921 !
 2922    then
 2923       :
 2924    else
 2925       feat_bail_required REGEX
 2926    fi
 2927 else
 2928    feat_is_disabled REGEX
 2929 fi
 2930 
 2931 if feat_yes MLE; then
 2932    if [ -n "${have_c90amend1}" ]; then
 2933       have_mle=1
 2934       echo '#define HAVE_MLE' >> ${h}
 2935    else
 2936       feat_bail_required MLE
 2937    fi
 2938 else
 2939    feat_is_disabled MLE
 2940 fi
 2941 
 2942 # Generic have-a-line-editor switch for those who need it below
 2943 if [ -n "${have_mle}" ]; then
 2944    have_cle=1
 2945 fi
 2946 
 2947 if feat_yes HISTORY; then
 2948    if [ -n "${have_cle}" ]; then
 2949       echo '#define HAVE_HISTORY' >> ${h}
 2950    else
 2951       feat_is_unsupported HISTORY
 2952    fi
 2953 else
 2954    feat_is_disabled HISTORY
 2955 fi
 2956 
 2957 if feat_yes KEY_BINDINGS; then
 2958    if [ -n "${have_mle}" ]; then
 2959       echo '#define HAVE_KEY_BINDINGS' >> ${h}
 2960    else
 2961       feat_is_unsupported KEY_BINDINGS
 2962    fi
 2963 else
 2964    feat_is_disabled KEY_BINDINGS
 2965 fi
 2966 
 2967 if feat_yes TERMCAP; then
 2968    __termcaplib() {
 2969       link_check termcap "termcap(5) (via ${4})" \
 2970          "#define HAVE_TERMCAP${3}" "${1}" << _EOT
 2971 #include <stdio.h>
 2972 #include <stdlib.h>
 2973 ${2}
 2974 #include <term.h>
 2975 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
 2976 static int my_putc(int c){return putchar(c);}
 2977 int main(void){
 2978    char buf[1024+512], cmdbuf[2048], *cpb, *r1;
 2979    int r2 = OK, r3 = ERR;
 2980 
 2981    tgetent(buf, getenv("TERM"));
 2982    cpb = cmdbuf;
 2983    r1 = tgetstr(UNCONST("cm"), &cpb);
 2984    tgoto(r1, 1, 1);
 2985    r2 = tgetnum(UNCONST("Co"));
 2986    r3 = tgetflag(UNCONST("ut"));
 2987    tputs("cr", 1, &my_putc);
 2988    return (r1 == NULL || r2 == -1 || r3 == 0);
 2989 }
 2990 _EOT
 2991    }
 2992 
 2993    __terminfolib() {
 2994       link_check terminfo "terminfo(5) (via ${2})" \
 2995          '#define HAVE_TERMCAP
 2996          #define HAVE_TERMCAP_CURSES
 2997          #define HAVE_TERMINFO' "${1}" << _EOT
 2998 #include <stdio.h>
 2999 #include <curses.h>
 3000 #include <term.h>
 3001 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
 3002 static int my_putc(int c){return putchar(c);}
 3003 int main(void){
 3004    int er, r0, r1, r2;
 3005    char *r3, *tp;
 3006 
 3007    er = OK;
 3008    r0 = setupterm(NULL, 1, &er);
 3009    r1 = tigetflag(UNCONST("bce"));
 3010    r2 = tigetnum(UNCONST("colors"));
 3011    r3 = tigetstr(UNCONST("cr"));
 3012    tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
 3013    tputs(tp, 1, &my_putc);
 3014    return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
 3015       r3 == (char*)-1 || r3 == NULL);
 3016 }
 3017 _EOT
 3018    }
 3019 
 3020    if feat_yes TERMCAP_VIA_TERMINFO; then
 3021       __terminfolib -ltinfo -ltinfo ||
 3022          __terminfolib -lcurses -lcurses ||
 3023          __terminfolib -lcursesw -lcursesw ||
 3024          feat_bail_required TERMCAP_VIA_TERMINFO
 3025    fi
 3026 
 3027    if [ -z "${have_terminfo}" ]; then
 3028       __termcaplib -ltermcap '' '' '-ltermcap' ||
 3029          __termcaplib -ltermcap '#include <curses.h>' '
 3030             #define HAVE_TERMCAP_CURSES' \
 3031             'curses.h / -ltermcap' ||
 3032          __termcaplib -lcurses '#include <curses.h>' '
 3033             #define HAVE_TERMCAP_CURSES' \
 3034             'curses.h / -lcurses' ||
 3035          __termcaplib -lcursesw '#include <curses.h>' '
 3036             #define HAVE_TERMCAP_CURSES' \
 3037             'curses.h / -lcursesw' ||
 3038          feat_bail_required TERMCAP
 3039 
 3040       if [ -n "${have_termcap}" ]; then
 3041          run_check tgetent_null \
 3042             "tgetent(3) of termcap(5) takes NULL buffer" \
 3043             "#define HAVE_TGETENT_NULL_BUF" << _EOT
 3044 #include <stdio.h> /* For C89 NULL */
 3045 #include <stdlib.h>
 3046 #ifdef HAVE_TERMCAP_CURSES
 3047 # include <curses.h>
 3048 #endif
 3049 #include <term.h>
 3050 int main(void){
 3051    tgetent(NULL, getenv("TERM"));
 3052    return 0;
 3053 }
 3054 _EOT
 3055       fi
 3056    fi
 3057 else
 3058    feat_is_disabled TERMCAP
 3059    feat_is_disabled TERMCAP_VIA_TERMINFO
 3060 fi
 3061 
 3062 if feat_def SPAM_SPAMC; then
 3063    if acmd_set i spamc; then
 3064       echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
 3065    fi
 3066 fi
 3067 
 3068 if feat_yes SPAM_SPAMD; then
 3069    if [ -n "${have_af_unix}" ]; then
 3070       echo '#define HAVE_SPAM_SPAMD' >> ${h}
 3071    else
 3072       feat_bail_required SPAM_SPAMD
 3073    fi
 3074 else
 3075    feat_is_disabled SPAM_SPAMD
 3076 fi
 3077 
 3078 feat_def SPAM_FILTER
 3079 
 3080 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
 3081    echo '#define HAVE_SPAM' >> ${h}
 3082 else
 3083    echo '/* HAVE_SPAM */' >> ${h}
 3084 fi
 3085 
 3086 if feat_yes QUOTE_FOLD; then
 3087    if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
 3088       echo '#define HAVE_QUOTE_FOLD' >> ${h}
 3089    else
 3090       feat_bail_required QUOTE_FOLD
 3091    fi
 3092 else
 3093    feat_is_disabled QUOTE_FOLD
 3094 fi
 3095 
 3096 feat_def FILTER_HTML_TAGSOUP
 3097 feat_def COLOUR
 3098 feat_def DOTLOCK
 3099 feat_def MD5
 3100 
 3101 ## Summarizing
 3102 
 3103 ${rm} -f ${tmp}
 3104 squeeze_em ${inc} ${tmp}
 3105 ${mv} ${tmp} ${inc}
 3106 squeeze_em ${lib} ${tmp}
 3107 ${mv} ${tmp} ${lib}
 3108 
 3109 # mk-config.h
 3110 ${mv} ${h} ${tmp}
 3111 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
 3112 ${cat} ${tmp} >> ${h}
 3113 printf '\n' >> ${h}
 3114 # We need these for correct "second stage configuration changed" detection */
 3115 echo "/* `${cat} ${lib}` */" >> ${h}
 3116 echo "/* `${cat} ${inc}` */" >> ${h}
 3117 printf '\n' >> ${h}
 3118 
 3119 # Throw away all temporaries
 3120 ${rm} -rf ${tmp0}.* ${tmp0}*
 3121 
 3122 # Create the string that is used by *features* and `version'.
 3123 # Take this nice opportunity and generate a visual listing of included and
 3124 # non-included features for the person who runs the configuration
 3125 echo 'The following features are included (+) or not (-):' > ${tmp}
 3126 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
 3127 printf '/* The "feature string" */\n' >> ${h}
 3128 # Because + is expanded by *folder* if first in "echo $features", put something
 3129 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
 3130 sep=
 3131 for opt
 3132 do
 3133    sdoc=`option_doc_of ${opt}`
 3134    [ -z "${sdoc}" ] && continue
 3135    sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
 3136    feat_yes ${opt} && sign=+ || sign=-
 3137    printf -- "${sep}${sign}${sopt}" >> ${h}
 3138    sep=','
 3139    printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
 3140 done
 3141 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
 3142 #exec 5>&1 >>${h}
 3143 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
 3144 #   -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
 3145 printf '"\n' >> ${h}
 3146 
 3147 # Create the real mk-config.mk
 3148 # Note we cannout use explicit ./ filename prefix for source and object
 3149 # pathnames because of a bug in bmake(1)
 3150 srclist= objlist=
 3151 if feat_no AMALGAMATION; then
 3152    for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
 3153       i=`basename "${i}" .c`
 3154       if [ "${i}" = privsep ]; then
 3155          continue
 3156       fi
 3157       objlist="${objlist} ${i}.o"
 3158       srclist="${srclist} \$(SRCDIR)${i}.c"
 3159       printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
 3160          "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
 3161    done
 3162    printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
 3163 else
 3164    printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
 3165       "main.o" "main.c" >> ${mk}
 3166    srclist=main.c objlist=main.o
 3167    printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
 3168 
 3169    printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
 3170    printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
 3171    printf '# undef n_MK_CONFIG_H\n' >> ${h}
 3172    printf '# define n_MK_CONFIG_H 2\n' >> ${h}
 3173    for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
 3174       i=`basename "${i}"`
 3175       if [ "${i}" = main.c ] ||
 3176             [ "${i}" = privsep.c ]; then
 3177          continue
 3178       fi
 3179       printf '$(SRCDIR)%s ' "${i}" >> ${mk}
 3180       printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
 3181    done
 3182    echo >> ${mk}
 3183 fi
 3184 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
 3185 
 3186 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
 3187 
 3188 echo "LIBS = `${cat} ${lib}`" >> ${mk}
 3189 echo "INCS = `${cat} ${inc}`" >> ${mk}
 3190 echo >> ${mk}
 3191 ${cat} "${SRCDIR}"make-config.in >> ${mk}
 3192 
 3193 ## Finished!
 3194 
 3195 # We have completed the new configuration header.  Check whether *really*
 3196 # Do the "second stage configuration changed" detection, exit if nothing to do
 3197 if [ -f ${oldh} ]; then
 3198    if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
 3199       ${mv} -f ${oldh} ${h}
 3200       msg 'Effective configuration is up-to-date'
 3201       exit 0
 3202    fi
 3203    config_updated=1
 3204    ${rm} -f ${oldh}
 3205    msg 'Effective configuration has been updated..'
 3206 fi
 3207 
 3208 if [ -n "${config_updated}" ]; then
 3209    msg 'Wiping away old objects and such'
 3210    ( eval "${MAKE} -f ${oldmk} clean" )
 3211 fi
 3212 
 3213 msg ''
 3214 while read l; do msg "${l}"; done < ${tmp}
 3215 
 3216 msg 'Setup:'
 3217 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
 3218 msg ' . bindir: %s' "${VAL_BINDIR}"
 3219 if feat_yes DOTLOCK; then
 3220    msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
 3221 fi
 3222 msg ' . mandir: %s' "${VAL_MANDIR}"
 3223 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
 3224 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
 3225 
 3226 msg ''
 3227 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
 3228    exit 0
 3229 fi
 3230 msg 'Remarks:'
 3231 if [ -z "${have_fnmatch}" ]; then
 3232    msg ' . The function fnmatch(3) could not be found.'
 3233    msg '   Filename patterns like wildcard are not supported on your system'
 3234 fi
 3235 if [ -z "${have_fchdir}" ]; then
 3236    msg ' . The function fchdir(2) could not be found.'
 3237    msg '   We will use chdir(2) instead.'
 3238    msg '   This is a problem only if the current working directory is changed'
 3239    msg '   while this program is inside of it'
 3240 fi
 3241 msg ''
 3242 
 3243 # s-it-mode