"Fossies" - the Fresh Open Source Software Archive

Member "s-nail-14.9.7/make-config.sh" (16 Feb 2018, 80122 Bytes) of package /linux/misc/s-nail-14.9.7.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.6_vs_14.9.7.

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