2 #@ Please see INSTALL and make.rc instead.
7 # For heaven's sake auto-redirect on SunOS/Solaris
8 if [ "x${SHELL}" = x
] ||
[ "${SHELL}" = /bin
/sh
] && \
9 [ -f /usr
/xpg
4/bin
/sh
] && [ -x /usr
/xpg
4/bin
/sh
]; then
10 SHELL
=/usr
/xpg
4/bin
/sh
12 exec /usr
/xpg
4/bin
/sh
"${0}" "${@}"
14 [ -n "${SHELL}" ] || SHELL
=/bin
/sh
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.
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' \
32 MD5='MD5 message digest (APOP, CRAM-MD5)' \
33 IDNA='Internationalized Domain Names for Applications (encode only)' \
34 IMAP_SEARCH='IMAP-style search expressions' \
35 REGEX='Regular expressions' \
36 MLE='Mailx Line Editor' \
37 HISTORY='Line editor history management' \
38 KEY_BINDINGS='Configurable key bindings' \
39 TERMCAP='Terminal capability queries (termcap(5))' \
40 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
41 ERRORS='Log message ring' \
42 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
44 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
45 DOCSTRINGS='Command documentation help strings' \
46 UISTRINGS='User interface and error message strings' \
47 QUOTE_FOLD='Extended *quote-fold*ing' \
48 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
49 COLOUR='Coloured message display' \
50 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
53 # Options which are automatically deduced from host environment, i.e., these
54 # need special treatment all around here to warp from/to OPT_ stuff
55 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
57 LOCALES='Locale support - printable characters etc. depend on environment' \
58 MULTIBYTE_CHARSETS='Multibyte character sets' \
59 TERMINAL_CHARSET='Automatic detection of terminal character set' \
60 WIDE_GLYPHS='Wide glyph support' \
63 # Rather special options, for custom building, or which always exist.
64 # Mostly for generating the visual overview and the *features* string
66 MIME='Multipurpose Internet Mail Extensions' \
67 SMIME='S/MIME message signing, verification, en- and decryption' \
68 CROSS_BUILD='Cross-compilation: trust any detected environment' \
69 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
70 DEVEL='Computers do not blunder' \
73 # To avoid too many recompilations we use a two-stage "configuration changed"
74 # detection, the first uses mk-config.lst, which only goes for actual user
75 # config settings etc. the second uses mk-config.h, which thus includes the
76 # things we have truly detected. This does not work well for multiple choice
77 # values of which only one will be really used, so those user wishes may not be
78 # placed in the header, only the really detected one (but that has to!).
79 # Used for grep(1), for portability assume fixed matching only.
80 H_BLACKLIST
='-e VAL_RANDOM -e VAL_IDNA'
82 # The problem is that we don't have any tools we can use right now, so
83 # encapsulate stuff in functions which get called in right order later on
99 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
103 option_parse OPTIONS_DETECT
"${XOPTIONS_DETECT}"
104 option_parse OPTIONS
"${XOPTIONS}"
105 option_parse OPTIONS_XTRA
"${XOPTIONS_XTRA}"
108 # Predefined CONFIG= urations take precedence over anything else
109 if [ -n "${CONFIG}" ]; then
114 [nN
][uU
][lL
][lL
][iI
])
118 [mM
][iI
][nN
][iI
][mM
][aA
][lL
])
119 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
126 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
129 [nN
][eE
][tT
][sS
][eE
][nN
][dD
])
130 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
134 OPT_GSSAPI
=1 OPT_NETRC
=1
142 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
145 [mM
][aA
][xX
][iI
][mM
][aA
][lL
])
148 [dD
][eE
][vV
][eE
][lL
])
150 OPT_DEVEL
=1 OPT_DEBUG
=1 OPT_NYD2
=1
152 [oO
][dD
][eE
][vV
][eE
][lL
])
157 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
158 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
162 msg_nonl
"CONFIG=${CONFIG} ... "
166 # Inter-relationships XXX sort this!
169 OPT_SSL_ALL_ALGORITHMS
=0
172 if feat_no SMTP
&& feat_no POP3
&& feat_no IMAP
; then
175 if feat_no SOCKETS
; then
176 if feat_require SMTP
; then
177 msg
'ERROR: need SOCKETS for required feature SMTP'
180 if feat_require POP3
; then
181 msg
'ERROR: need SOCKETS for required feature POP3'
184 if feat_require IMAP
; then
185 msg
'ERROR: need SOCKETS for required feature IMAP'
188 OPT_SSL
=0 OPT_SSL_ALL_ALGORITHMS
=0
189 OPT_SMTP
=0 OPT_POP3
=0 OPT_IMAP
=0
190 OPT_GSSAPI
=0 OPT_NETRC
=0 OPT_AGENT
=0
192 if feat_no SMTP
&& feat_no IMAP
; then
196 if feat_no ICONV
; then
197 if feat_yes IMAP
; then
198 if feat_yes ALWAYS_UNICODE_LOCALE
; then
199 msg
'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
200 elif feat_require IMAP
; then
201 msg
'ERROR: need ICONV for required feature IMAP'
204 msg
'ERROR: disabling IMAP due to missing ICONV'
209 if feat_yes IDNA
; then
210 if feat_require IDNA
; then
211 msg
'ERROR: need ICONV for required feature IDNA'
214 msg
'ERROR: disabling IDNA due to missing ICONV'
220 OPT_HISTORY
=0 OPT_KEY_BINDINGS
=0
223 # If we don't need MD5 leave it alone
224 if feat_no SOCKETS
; then
228 if feat_no TERMCAP
; then
229 OPT_TERMCAP_VIA_TERMINFO
=0
232 if feat_yes DEVEL
; then
240 h
=.
/mk-config.h h_name
=mk-config.h
243 newlst
=.
/mk-nconfig.lst
244 newmk
=.
/mk-nconfig.mk
245 oldmk
=.
/mk-oconfig.mk
246 newev
=.
/mk-nconfig.ev
253 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
255 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
256 # via path_check() later on once possible
258 # TODO cc_maxopt is brute simple, we should compile test program and dig real
259 # compiler versions for known compilers, then be more specific
260 [ -n "${cc_maxopt}" ] || cc_maxopt
=100
261 #cc_force_no_stackprot=
264 #ld_rpath_not_runpath=
269 [ -n "${OS}" ] && [ -n "${OSENV}" ] && [ -n "${OSFULLSPEC}" ] ||
270 thecmd_testandset_fail uname uname
272 # We don't "have any utility": only path adjustments and such in here!
273 [ -n "${OS}" ] || OS
=`${uname} -s`
276 if [ ${OS} = SunOS
]; then
277 msg
'SunOS / Solaris? Applying some "early setup" rules ...'
278 _os_early_setup_sunos
282 _os_early_setup_sunos
() {
283 # According to standards(5), this is what we need to do
284 if [ -d /usr
/xpg4
]; then :; else
285 msg
'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
288 PATH
="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
289 [ -d /usr
/xpg6
] && PATH
="/usr/xpg6/bin:${PATH}"
294 # OSENV ends up in *build-osenv*
295 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
296 # etc.), it is not baked into the binary
297 OS
=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
298 [ -n "${OSENV}" ] || OSENV
=`${uname} -sm`
299 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC
=`${uname} -a`
300 msg
'Operating system is %s' ${OS}
302 if [ ${OS} = darwin
]; then
303 msg
' . have special Darwin environmental addons...'
304 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
305 elif [ ${OS} = sunos
]; then
306 msg
' . have special SunOS / Solaris "setup" rules ...'
308 elif [ ${OS} = unixware
]; then
309 if feat_yes AUTOCC
&& acmd_set CC cc
; then
310 msg
' . have special UnixWare environmental rules ...'
311 feat_yes DEBUG
&& _CFLAGS
='-v -Xa -g' || _CFLAGS
='-Xa -O'
313 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
314 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
315 export CC CFLAGS LDFLAGS
316 OPT_AUTOCC
=0 ld_need_R_flags
=-R
318 elif [ -n "${VERBOSE}" ]; then
319 msg
' . no special treatment for this system necessary or known'
322 # Sledgehammer: better set _GNU_SOURCE
323 # And in general: oh, boy!
324 OS_DEFINES
="${OS_DEFINES}#define _GNU_SOURCE\n"
325 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
326 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
327 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
329 # On pkgsrc(7) systems automatically add /usr/pkg/*
330 if [ -d /usr
/pkg
] && feat_yes USE_PKGSYS
; then
331 msg
' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
332 C_INCLUDE_PATH
=/usr
/pkg
/include
:${C_INCLUDE_PATH}
333 LD_LIBRARY_PATH
=/usr
/pkg
/lib
:${LD_LIBRARY_PATH}
334 ld_rpath_not_runpath
=1
339 C_INCLUDE_PATH
=/usr
/xpg
4/include
:${C_INCLUDE_PATH}
340 LD_LIBRARY_PATH
=/usr
/xpg
4/lib
:${LD_LIBRARY_PATH}
343 if [ -d /opt
/csw
] && feat_yes USE_PKGSYS
; then
344 msg
' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
345 C_INCLUDE_PATH
=/opt
/csw
/include
:${C_INCLUDE_PATH}
346 LD_LIBRARY_PATH
=/opt
/csw
/lib
:${LD_LIBRARY_PATH}
347 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
349 if [ -d /opt
/schily
] && feat_yes USE_PKGSYS
; then
350 msg
' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
351 C_INCLUDE_PATH
=/opt
/schily
/include
:${C_INCLUDE_PATH}
352 LD_LIBRARY_PATH
=/opt
/schily
/lib
:${LD_LIBRARY_PATH}
353 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
356 OS_DEFINES
="${OS_DEFINES}#define __EXTENSIONS__\n"
357 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
359 [ -n "${cksum}" ] ||
cksum=/opt
/csw
/gnu
/cksum
360 if [ -x "${cksum}" ]; then :; else
361 msg
'ERROR: Not an executable program: %s' "${cksum}"
362 msg
'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
363 msg
'ERROR: However, we do so only for tests.'
364 msg
'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
368 if feat_yes AUTOCC
; then
369 if acmd_set CC cc
; then
370 feat_yes DEBUG
&& _CFLAGS
="-v -Xa -g" || _CFLAGS
="-Xa -O"
372 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
373 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
374 export CC CFLAGS LDFLAGS
375 OPT_AUTOCC
=0 ld_need_R_flags
=-R
377 cc_maxopt
=2 cc_force_no_stackprot
=1
382 # Check out compiler ($CC) and -flags ($CFLAGS)
384 # Even though it belongs into cc_flags we will try to compile and link
385 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
386 # EXTRA_CFLAGS/EXTRA_LDFLAGS
387 if feat_no AUTOCC
; then
389 # Ensure those don't do any harm
390 EXTRA_CFLAGS
= EXTRA_LDFLAGS
=
391 export EXTRA_CFLAGS EXTRA_LDFLAGS
395 export CFLAGS LDFLAGS
398 [ -n "${CC}" ] && { _cc_default
; return; }
400 msg_nonl
'Searching for a usable C compiler .. $CC='
401 if acmd_set CC clang || acmd_set CC gcc ||
402 acmd_set CC tcc || acmd_set CC pcc ||
403 acmd_set CC c89 || acmd_set CC c99
; then
406 msg
'boing booom tschak'
407 msg
'ERROR: I cannot find a compiler!'
408 msg
' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
409 msg
' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
417 if [ -z "${CC}" ]; then
418 msg
'To go on like you have chosen, please set $CC, rerun.'
422 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG
; then
425 msg
'Using C compiler ${CC}=%s' "${CC}"
430 if feat_yes AUTOCC
; then
431 if [ -f ${lst} ] && feat_no DEBUG
&& [ -z "${VERBOSE}" ]; then
433 msg
'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
437 msg
'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
440 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
441 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
442 msg ' . have special tcc(1) environmental rules ...'
445 # As of pcc CVS 2016-04-02, stack protection support is announced but
446 # will break if used on Linux
447 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
448 cc_force_no_stackprot=1
453 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
454 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
455 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
457 if feat_no DEBUG; then
458 CFLAGS="-DNDEBUG ${CFLAGS}"
461 export CFLAGS LDFLAGS
465 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
472 if feat_yes DEBUG; then
473 # May have problems to find libtcc cc_check -b
477 if ld_check -Wl,-rpath =./ no; then
478 ld_need_R_flags=-Wl,-rpath=
479 if [ -z "${ld_rpath_not_runpath}" ]; then
480 ld_check -Wl,--enable-new-dtags
482 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
484 ld_runtime_flags # update!
487 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
488 unset __cflags __ldflags
491 _cc_flags_generic() {
492 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
494 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
496 # E.g., valgrind does not work well with high optimization
497 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
498 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
499 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
502 # Check -g first since some others may rely upon -g / optim. level
503 if feat_yes DEBUG; then
506 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
508 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
510 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
516 if feat_yes AMALGAMATION; then
520 #if feat_yes DEVEL && cc_check -Weverything; then
525 cc_check -Wbad-function-cast
526 cc_check -Wcast-align
529 cc_check -Wmissing-prototypes
532 cc_check -Wwrite-strings
533 cc_check -Wno-long-long
537 if feat_yes AMALGAMATION && feat_no DEVEL; then
538 cc_check -Wno-unused-function
540 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
542 cc_check -fno-unwind-tables
543 cc_check -fno-asynchronous-unwind-tables
544 cc_check -fstrict-aliasing
545 if cc_check -fstrict-overflow && feat_yes DEVEL; then
546 cc_check -Wstrict-overflow=5
549 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
550 if [ -z "${cc_force_no_stackprot}" ]; then
551 if cc_check -fstack-protector-strong ||
552 cc_check -fstack-protector-all; then
553 cc_check -D_FORTIFY_SOURCE=2
556 msg ' ! Not checking for -fstack-protector compiler option,'
557 msg ' ! since that caused errors in a "similar" configuration.'
558 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
562 # LD (+ dependend CC)
564 if feat_yes ASAN_ADDRESS; then
566 if cc_check -fsanitize=address &&
567 ld_check -fsanitize=address; then
570 feat_bail_required ASAN_ADDRESS
575 if feat_yes ASAN_MEMORY; then
577 if cc_check -fsanitize=memory &&
578 ld_check -fsanitize=memory &&
579 cc_check -fsanitize-memory-track-origins=2 &&
580 ld_check -fsanitize-memory-track-origins=2; then
583 feat_bail_required ASAN_MEMORY
588 ld_check -Wl,-z,relro
589 if [ -z "${ld_no_bind_now}" ]; then
592 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
594 ld_check -Wl,-z,noexecstack
595 if ld_check -Wl,-rpath =./ no; then
596 ld_need_R_flags=-Wl,-rpath=
597 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
598 if [ -z "${ld_rpath_not_runpath}" ]; then
599 ld_check -Wl,--enable-new-dtags
601 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
603 ld_runtime_flags # update!
604 elif ld_check -Wl,-R ./ no; then
605 ld_need_R_flags=-Wl,-R
606 if [ -z "${ld_rpath_not_runpath}" ]; then
607 ld_check -Wl,--enable-new-dtags
609 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
611 ld_runtime_flags # update!
614 # Address randomization
616 if cc_check -fPIE || cc_check -fpie; then
617 ld_check -pie || _CFLAGS=${_ccfg}
621 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
622 unset __cflags __ldflags
625 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
628 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
629 ## redirection, so use "printf '' >" instead
631 ## Very first: we undergo several states regarding I/O redirection etc.,
632 ## but need to deal with option updates from within all. Since all the
633 ## option stuff should be above the scissor line, define utility functions
634 ## and redefine them as necessary.
635 ## And, since we have those functions, simply use them for whatever
637 t1=ten10one1ten10one1
638 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
639 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
640 ) > /dev/null 2>&1; then
647 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
653 # which(1) not standardized, command(1) -v may return non-executable: unroll!
654 acmd_test() { __acmd "${1}" 1 0 0; }
655 acmd_test_fail() { __acmd "${1}" 1 1 0; }
656 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
657 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
658 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
659 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
660 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
661 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
662 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
663 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
665 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
667 if [ "${dotest}" -ne 0 ]; then
668 eval dotest=\$${varname}
669 if [ -n "${dotest}" ]; then
670 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
671 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
677 [ -n "${noglob_shell}" ] && set -o noglob
679 [ -n "${noglob_shell}" ] && set +o noglob
683 if [ -z "${path}" ] || [ "${path}" = . ]; then
684 if [ -d "${PWD}" ]; then
690 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
691 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
692 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
693 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
698 # We may have no builtin string functions, we yet have no programs we can
699 # use, try to access once from the root, assuming it is an absolute path if
700 # that finds the executable
701 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
702 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
703 msg ' . ${%s} ... %s' "${pname}" "${pname}"
704 [ -n "${varname}" ] && eval ${varname}="${pname}"
708 [ ${dofail} -eq 0 ] && return 1
709 msg 'ERROR: no trace of utility '"${pname}"
716 printf >&2 -- "${fmt}\\n" "${@}"
722 printf >&2 -- "${fmt}" "${@}"
725 # Our feature check environment
727 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
728 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
732 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
733 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
734 [ "x${1}" = xrequire ]
738 [ "x${1}" = xrequire ]
743 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
744 if feat_val_no "${i}"; then
746 elif feat_val_yes "${i}"; then
749 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
760 _feat_check ${1} && return 1
766 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
767 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
770 feat_bail_required() {
771 if feat_require ${1}; then
772 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
775 feat_is_unsupported "${1}"
779 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
780 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
783 feat_is_unsupported() {
784 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
785 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
787 option_update # XXX this is rather useless here (dependency chain..)
791 if feat_yes ${1}; then
792 echo '#define HAVE_'${1}'' >> ${h}
795 feat_is_disabled "${@}"
801 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
802 # options, without documentation, to $1
804 i="`${awk} -v input
=\"${2}\" '
807 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
810 v = substr(input, voff, RLENGTH)
811 input = substr(input, voff + RLENGTH)
814 d = substr(v, doff + 2, length(v) - doff - 1)
815 v = substr(v, 1, doff - 1)
825 # Return the "documentation string" for option $1, itself if none such
827 ${awk} -v want="${1}" \
828 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
831 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
834 v = substr(input, voff, RLENGTH)
835 input = substr(input, voff + RLENGTH)
838 d = substr(v, doff + 2, length(v) - doff - 1)
839 v = substr(v, 1, doff - 1)
853 # Join the values from make.rc into what currently is defined, not
854 # overwriting yet existing settings
856 # We want read(1) to perform reverse solidus escaping in order to be able to
857 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
858 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
859 < ${rc} ${awk} 'BEGIN{line = ""}{
860 gsub(/^[[:space:]]+/, "", $0)
861 gsub(/[[:space:]]+$/, "", $0)
862 if(gsub(/\\$/, "", $0)){
867 if(index(line, "#") == 1){
869 }else if(length(line)){
875 if [ -n "${good_shell}" ]; then
878 i=`${awk} -v LINE
="${line}" 'BEGIN{
879 gsub(/=.*$/, "", LINE)
883 if [ "${i}" = "${line}" ]; then
884 msg 'ERROR: invalid syntax in: %s' "${line}"
888 eval j="\$${i}" jx="\${${i}+x}"
889 if [ -n "${j}" ] || [ "${jx}" = x ]; then
892 j=`${awk} -v LINE
="${line}" 'BEGIN{
893 gsub(/^[^=]*=/, "", LINE)
894 gsub(/^\"*/, "", LINE)
895 gsub(/\"*$/, "", LINE)
899 [ "${i}" = "DESTDIR" ] && continue
902 # Reread the mixed version right now
907 # Expand the option values, which may contain shell snippets
908 ${rm} -f ${newlst} ${newmk} ${newh}
909 exec 5<&0 6>&1 <${tmp} >${newlst}
912 if [ -n "${good_shell}" ]; then
914 [ "${i}" != "${i#OPT_}" ] && z=1
916 i=`${awk} -v LINE
="${line}" 'BEGIN{
917 gsub(/=.*$/, "", LINE);\
920 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
926 if [ -n "${z}" ]; then
927 j="`echo ${j} |
${tr} '[A-Z]' '[a-z]'`"
928 if [ -z "${j}" ] || feat_val_no "${j}"; then
930 printf " /* #undef ${i} */\n" >> ${newh}
931 elif feat_val_yes "${j}"; then
932 if feat_val_require "${j}"; then
937 printf " /* #define ${i} */\n" >> ${newh}
939 msg 'ERROR: cannot parse <%s>' "${line}"
942 elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
945 printf "#define ${i} \"${j}\"\n" >> ${newh}
947 printf "${i} = ${j}\n" >> ${newmk}
951 exec 0<&5 1>&6 5<&- 6<&-
956 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
959 if((j = split(USER, ua)) == 0)
963 if(us == "all" || us == "any")
966 for(ii = i; ii != 0; --ii)
967 if(tolower(ha[ii]) == us){
977 [ ${__rv__} -ne 0 ] && return ${__rv__}
979 if ${awk} -v USER="${__expo__}" '
981 if((j = split(USER, ua)) == 0)
985 if(us == "all" || us == "any")
997 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
998 varname=${1} addflag=${2} flagvarname=${3}
1001 [ -n "${noglob_shell}" ] && set -o noglob
1002 eval "set -- \$${1}"
1003 [ -n "${noglob_shell}" ] && set +o noglob
1008 [ -z "${i}" ] && continue
1009 [ -d "${i}" ] || continue
1010 if [ -n "${j}" ]; then
1011 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1016 # But do not link any fakeroot path into our binaries!
1017 if [ -n "${addflag}" ]; then
1018 case "${i}" in *fakeroot*) continue;; esac
1019 k="${k} ${addflag}${i}"
1025 # But do not link any fakeroot path into our binaries!
1026 if [ -n "${addflag}" ]; then
1027 case "${i}" in *fakeroot*) continue;; esac
1028 k="${k} ${addflag}${i}"
1032 eval "${varname}=\"${j}\""
1033 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1037 ld_runtime_flags() {
1038 if [ -n "${ld_need_R_flags}" ]; then
1041 set -- ${LD_LIBRARY_PATH}
1045 # But do not link any fakeroot path into our binaries!
1046 case "${i}" in *fakeroot*) continue;; esac
1047 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1048 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1052 # Disable it for a possible second run.
1057 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1058 if "${CC}" ${INCS} \
1059 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1060 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1061 _CFLAGS="${_CFLAGS} ${1}"
1062 [ -n "${cc_check_silent}" ] || msg 'yes'
1065 [ -n "${cc_check_silent}" ] || msg 'no'
1070 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1071 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1072 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1073 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1074 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1075 [ -n "${cc_check_silent}" ] || msg 'yes'
1078 [ -n "${cc_check_silent}" ] || msg 'no'
1084 variable=$1 topic=$2 define=$3
1087 msg_nonl ' . %s ... ' "${topic}"
1088 #echo "/* checked ${topic} */" >> ${h}
1089 ${rm} -f ${tmp} ${tmp}.o
1090 if [ "${dump_test_program}" = 1 ]; then
1091 echo '*** test program is'
1092 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1094 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1096 #echo '*** the preprocessor generates'
1097 #${make} -f ${makefile} ${tmp}.x
1099 echo '*** tests results'
1103 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1106 msg_nonl ' . %s ... ' "${topic}"
1108 echo '*** enforced unchecked results are'
1109 if feat_val_yes ${yesno}; then
1110 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1111 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1112 LIBS="${LIBS} ${libs}"
1113 echo "${libs}" >> ${lib}
1114 INCS="${INCS} ${incs}"
1115 echo "${incs}" >> ${inc}
1118 echo "${define}" >> ${h}
1119 eval have_${variable}=yes
1122 #echo "/* ${define} */" >> ${h}
1124 eval unset have_${variable}
1130 variable=$1 topic=$2 define=$3
1132 _check_preface "${variable}" "${topic}" "${define}"
1134 if ${make} -f ${makefile} XINCS="${INCS}" \
1135 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1137 [ -f ./${tmp}.o ]; then
1139 echo "${define}" >> ${h}
1140 eval have_${variable}=yes
1143 #echo "/* ${define} */" >> ${h}
1145 eval unset have_${variable}
1151 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1153 _check_preface "${variable}" "${topic}" "${define}"
1155 if feat_yes CROSS_BUILD; then
1156 if [ ${run} = 1 ]; then
1161 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1162 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1163 XLIBS="${LIBS} ${libs}" \
1166 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1167 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1169 echo "${define}" >> ${h}
1170 LIBS="${LIBS} ${libs}"
1171 echo "${libs}" >> ${lib}
1172 INCS="${INCS} ${incs}"
1173 echo "${incs}" >> ${inc}
1174 eval have_${variable}=yes
1178 #echo "/* ${define} */" >> ${h}
1179 eval unset have_${variable}
1185 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1189 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1193 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1197 < "${1}" > "${2}" ${awk} \
1198 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1201 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1203 # First of all, create new configuration and check whether it changed
1205 # Very easy checks for the operating system in order to be able to adjust paths
1206 # or similar very basic things which we need to be able to go at all
1209 # Check those tools right now that we need before including $rc
1210 msg 'Checking for basic utility set'
1211 thecmd_testandset_fail awk awk
1212 thecmd_testandset_fail rm rm
1213 thecmd_testandset_fail tr tr
1215 # Initialize the option set
1216 msg_nonl 'Setting up configuration options ... '
1220 # Include $rc, but only take from it what wasn't overwritten by the user from
1221 # within the command line or from a chosen fixed CONFIG=
1222 # Note we leave alone the values
1223 trap "exit 1" HUP INT TERM
1224 trap "${rm} -f ${tmp}" EXIT
1226 msg_nonl 'Joining in %s ... ' ${rc}
1230 # We need to know about that now, in order to provide utility overwrites etc.
1233 msg 'Checking for remaining set of utilities'
1234 thecmd_testandset_fail grep grep
1236 # Before we step ahead with the other utilities perform a path cleanup first.
1240 thecmd_testandset_fail basename basename
1241 thecmd_testandset_fail cat cat
1242 thecmd_testandset_fail chmod chmod
1243 thecmd_testandset_fail cp cp
1244 thecmd_testandset_fail cmp cmp
1246 thecmd_testandset_fail mkdir mkdir
1247 thecmd_testandset_fail mv mv
1249 thecmd_testandset_fail sed sed
1250 thecmd_testandset_fail sort sort
1251 thecmd_testandset_fail tee tee
1253 thecmd_testandset chown chown ||
1254 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1255 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1257 thecmd_testandset_fail MAKE make
1260 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1262 # For ./cc-test.sh only
1263 thecmd_testandset_fail cksum cksum
1265 # Update OPT_ options now, in order to get possible inter-dependencies right
1268 # (No functions since some shells loose non-exported variables in traps)
1269 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1270 trap "trap \"\" HUP INT TERM EXIT;\
1271 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1272 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1274 # Our configuration options may at this point still contain shell snippets,
1275 # we need to evaluate them in order to get them expanded, and we need those
1276 # evaluated values not only in our new configuration file, but also at hand..
1277 msg_nonl 'Evaluating all configuration items ... '
1281 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1282 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1284 # The problem now is that the test should be able to run in the users linker
1285 # and path environment, so we need to place the test: rule first, before
1286 # injecting the relevant make variables. Set up necessary environment
1287 if [ -z "${VERBOSE}" ]; then
1288 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1289 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1290 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1291 printf -- "ECHO_TEST = @\n" >> ${newmk}
1292 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1293 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1294 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1296 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1297 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1299 # Add the known utility and some other variables
1300 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1301 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1302 if feat_yes DOTLOCK; then
1303 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1305 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1310 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1311 MAKE MAKEFLAGS make SHELL strip \
1314 printf "${i} = ${j}\n" >> ${newmk}
1315 printf "${i}=${j}\n" >> ${newlst}
1316 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1318 # Note that makefile reads and eval'uates one line of this file, whereas other
1319 # consumers source it via .(1)
1320 printf "\n" >> ${newev}
1322 # Build a basic set of INCS and LIBS according to user environment.
1323 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1324 path_check C_INCLUDE_PATH -I _INCS
1325 INCS="${INCS} ${_INCS}"
1326 path_check LD_LIBRARY_PATH -L _LIBS
1327 LIBS="${LIBS} ${_LIBS}"
1329 export C_INCLUDE_PATH LD_LIBRARY_PATH
1331 # Some environments need runtime path flags to be able to go at all
1334 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1338 ${cat} > ${tmp}.c << \!
1341 static void doit(char const *s);
1343 main(int argc, char **argv){
1346 doit("Hello world");
1350 doit(char const *s){
1352 memcpy(buf, s, strlen(s) +1);
1357 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1358 -o ${tmp2} ${tmp}.c ${LIBS}; then
1361 msg 'ERROR: i cannot compile a "Hello world" via'
1363 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1364 msg 'ERROR: Please read INSTALL, rerun'
1368 # This may also update ld_runtime_flags() (again)
1375 printf -- "${i}=${j}\n" >> ${newlst}
1381 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1385 if [ -n "${j}" ]; then
1386 printf -- "${i} = ${j}\n" >> ${newmk}
1387 printf -- "${i}=${j}\n" >> ${newlst}
1391 # Now finally check whether we already have a configuration and if so, whether
1392 # all those parameters are still the same.. or something has actually changed
1394 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1395 echo 'Configuration is up-to-date'
1397 elif [ -f ${lst} ]; then
1399 echo 'Configuration has been updated..'
1401 echo 'Shiny configuration..'
1404 # Time to redefine helper 1
1406 ${rm} -f ${lst} ${h} ${mk}
1410 ${mv} -f ${newlst} ${lst}
1411 ${mv} -f ${newev} ${ev}
1412 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1413 ${mv} -f ${newh} ${h}
1414 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1415 ${mv} -f ${newmk} ${mk}
1417 ## Compile and link checking
1423 makefile=./${tmp0}.mk
1425 # (No function since some shells loose non-exported variables in traps)
1426 trap "trap \"\" HUP INT TERM;\
1427 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1429 trap "trap \"\" HUP INT TERM EXIT;\
1430 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1432 # Time to redefine helper 2
1436 printf "*** ${fmt}\\n" "${@}"
1437 printf -- "${fmt}\\n" "${@}" >&5
1442 printf "*** ${fmt}\\n" "${@}"
1443 printf -- "${fmt}" "${@}" >&5
1447 exec 5>&2 > ${log} 2>&1
1449 echo "${LIBS}" > ${lib}
1450 echo "${INCS}" > ${inc}
1451 ${cat} > ${makefile} << \!
1452 .SUFFIXES: .o .c .x .y
1454 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1456 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1458 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1463 # May be multiline..
1465 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1466 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1467 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1469 # Generate n_err_number OS mappings
1472 feat_yes DEVEL && NV= || NV=noverbose
1473 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1474 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1475 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1478 feat_def ALWAYS_UNICODE_LOCALE
1479 feat_def AMALGAMATION 0
1480 feat_def CROSS_BUILD
1485 feat_def ASAN_ADDRESS 0
1486 feat_def ASAN_MEMORY 0
1492 if xrun_check inline 'inline functions' \
1493 '#define HAVE_INLINE
1494 #define n_INLINE static inline' << \!
1495 static inline int ilf(int i){return ++i;}
1496 int main(void){return ilf(-1);}
1500 elif xrun_check inline 'inline functions (via __inline)' \
1501 '#define HAVE_INLINE
1502 #define n_INLINE static __inline' << \!
1503 static __inline int ilf(int i){return ++i;}
1504 int main(void){return ilf(-1);}
1510 ## Test for "basic" system-calls / functionality that is used by all parts
1511 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1512 ## macros to be used by only the subprograms (potentially).
1514 if run_check clock_gettime 'clock_gettime(2)' \
1515 '#define HAVE_CLOCK_GETTIME' << \!
1521 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1528 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1529 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1535 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1542 elif run_check gettimeofday 'gettimeofday(2)' \
1543 '#define HAVE_GETTIMEOFDAY' << \!
1544 #include <stdio.h> /* For C89 NULL */
1545 #include <sys/time.h>
1550 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1558 have_no_subsecond_time=1
1561 if run_check nanosleep 'nanosleep(2)' \
1562 '#define HAVE_NANOSLEEP' << \!
1569 ts.tv_nsec = 100000;
1570 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1577 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1578 '#define HAVE_NANOSLEEP' '-lrt' << \!
1585 ts.tv_nsec = 100000;
1586 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1593 # link_check is enough for this, that function is so old, trust the proto
1594 elif link_check sleep 'sleep(3)' \
1595 '#define HAVE_SLEEP' << \!
1599 if(!sleep(1) || errno != ENOSYS)
1607 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1611 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1620 if((gid = getgid()) != 0)
1622 if((uid = getuid()) != 0)
1624 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1626 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1634 msg 'ERROR: we require user and group info / database searches.'
1635 msg 'That much Unix we indulge ourselfs.'
1639 if link_check ftruncate 'ftruncate(2)' \
1640 '#define HAVE_FTRUNCATE' << \!
1642 #include <sys/types.h>
1644 return (ftruncate(0, 0) != 0);
1650 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1651 msg 'ERROR: we require the ftruncate(2) system call.'
1655 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1659 struct sigaction nact, oact;
1661 nact.sa_handler = SIG_DFL;
1662 sigemptyset(&nact.sa_mask);
1663 nact.sa_flags = SA_RESTART;
1664 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1670 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1674 if link_check snprintf 'snprintf(3)' << \!
1679 snprintf(b, sizeof b, "%s", "string");
1686 msg 'ERROR: we require the snprintf(3) function.'
1690 if link_check environ 'environ(3)' << \!
1691 #include <stdio.h> /* For C89 NULL */
1693 extern char **environ;
1695 return environ[0] == NULL;
1701 msg 'ERROR: we require the environ(3) array for subprocess control.'
1705 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1708 setenv("s-mailx", "i want to see it cute!", 1);
1709 unsetenv("s-mailx");
1715 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1718 putenv("s-mailx=i want to see it cute!");
1725 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1729 if link_check termios 'termios.h and tc*(3) family' << \!
1730 #include <termios.h>
1732 struct termios tios;
1734 tcgetattr(0, &tios);
1735 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1742 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1743 msg 'That much Unix we indulge ourselfs.'
1749 if link_check vsnprintf 'vsnprintf(3)' << \!
1752 static void dome(char *buf, size_t blen, ...){
1756 vsnprintf(buf, blen, "%s", ap);
1762 dome(b, sizeof b, "string");
1769 feat_bail_required ERRORS
1772 if [ "${have_vsnprintf}" = yes ]; then
1774 link_check va_copy "va_copy(3) (as ${2})" \
1775 "#define HAVE_N_VA_COPY
1776 #define n_va_copy ${2}" <<_EOT
1780 # if defined __va_copy && !defined va_copy
1781 # define va_copy __va_copy
1784 static void dome2(char *buf, size_t blen, va_list src){
1788 vsnprintf(buf, blen, "%s", ap);
1791 static void dome(char *buf, size_t blen, ...){
1795 dome2(buf, blen, ap);
1801 dome(b, sizeof b, "string");
1806 __va_copy 0 va_copy || __va_copy 1 __va_copy
1809 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1816 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1818 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1820 /* Only link check */
1821 fpathconf(0, _PC_NAME_MAX);
1827 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1834 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1840 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1841 #include <termios.h>
1845 tcgetwinsize(0, &ws);
1850 # We use this only then for now (need NOW+1)
1851 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1852 #include <fcntl.h> /* For AT_* */
1853 #include <sys/stat.h>
1856 struct timespec ts[2];
1858 ts[0].tv_nsec = UTIME_NOW;
1859 ts[1].tv_nsec = UTIME_OMIT;
1860 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1868 # The random check has been moved to below SSL detection due to multiple choice
1869 # selection for PRG sources
1871 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1874 putc_unlocked('@', stdout);
1879 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1887 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1890 char x_buf[4096], *x = realpath(".", x_buf);
1892 return (x != NULL) ? 0 : 1;
1896 if run_check realpath_malloc 'realpath(3) takes NULL' \
1897 '#define HAVE_REALPATH_NULL' << \!
1900 char *x = realpath(".", NULL);
1904 return (x != NULL) ? 0 : 1;
1913 ## optional and selectable
1916 if feat_yes DOTLOCK; then
1917 if run_check readlink 'readlink(2)' << \!
1923 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1931 feat_bail_required DOTLOCK
1935 if feat_yes DOTLOCK; then
1936 if run_check fchown 'fchown(2)' << \!
1940 if(!fchown(0, 0, 0) || errno != ENOSYS)
1948 feat_bail_required DOTLOCK
1952 if feat_yes DOTLOCK; then
1953 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1954 '#define HAVE_PRCTL_DUMPABLE' << \!
1955 #include <sys/prctl.h>
1958 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1965 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1966 '#define HAVE_PTRACE_DENY' << \!
1967 #include <sys/ptrace.h>
1970 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1977 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1978 '#define HAVE_SETPFLAGS_PROTECT' << \!
1982 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1992 ## Now it is the time to fork away the BASE_ series
1995 squeeze_em ${inc} ${tmp}
1997 squeeze_em ${lib} ${tmp}
2000 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2001 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2003 ## The remains are expected to be used only by the main MUA binary!
2006 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2009 setlocale(LC_ALL, "");
2013 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2015 OPT_MULTIBYTE_CHARSETS=0
2017 OPT_TERMINAL_CHARSET=0
2018 if [ -n "${have_setlocale}" ]; then
2019 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2020 '#define HAVE_C90AMEND1' << \!
2026 char mbb[MB_LEN_MAX + 1];
2031 mbtowc(&wc, "x
", 1);
2032 mbrtowc(&wc, "x
", 1, NULL);
2034 return (mblen("\
0", 1) == 0);
2037 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2039 if [ -n "${have_c90amend1}" ]; then
2040 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2047 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2050 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2051 #include <langinfo.h>
2055 return (nl_langinfo(CODESET) == NULL);
2058 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2061 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2062 #include <fnmatch.h>
2064 return (fnmatch("*", ".
", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2068 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2072 return !(de.d_type == DT_UNKNOWN ||
2073 de.d_type == DT_DIR || de.d_type == DT_LNK);
2077 ## optional and selectable
2079 if feat_yes ICONV; then
2080 # To be able to create tests we need to figure out which replacement
2081 # sequence the iconv(3) implementation creates
2082 ${cat} > ${tmp2}.c << \!
2083 #include <stdio.h> /* For C89 NULL */
2087 char inb[16], oub[16], *inbp, *oubp;
2091 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2092 inl = sizeof("\342\200\223") -1;
2096 if((id = iconv_open("ascii
", "utf-8
")) == (iconv_t)-1)
2098 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2103 oul = (size_t)(oubp - oub);
2106 /* Character-wise replacement? */
2114 /* Byte-wise replacement? */
2115 if(oul == sizeof("\342\200\223") -1){
2116 if(!memcmp(oub, "???????
", sizeof("\342\200\223") -1))
2118 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2125 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2126 '#define HAVE_ICONV' ||
2127 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2128 '#define HAVE_ICONV' '-liconv' ||
2129 feat_bail_required ICONV
2131 if feat_no CROSS_BUILD; then
2132 { ./${tmp}; } >/dev/null 2>&1
2134 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2135 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2136 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2137 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2138 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2142 feat_is_disabled ICONV
2145 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2146 ${cat} > ${tmp2}.c << \!
2147 #include <sys/types.h>
2148 #include <sys/socket.h>
2152 struct sockaddr_un soun;
2154 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2156 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2158 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2164 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2165 '#define HAVE_UNIX_SOCKETS' ||
2166 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2167 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2168 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2169 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2172 if feat_yes SOCKETS; then
2173 ${cat} > ${tmp2}.c << \!
2174 #include <sys/types.h>
2175 #include <sys/socket.h>
2176 #include <netinet/in.h>
2181 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2183 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2189 < ${tmp2}.c run_check sockets 'sockets' \
2190 '#define HAVE_SOCKETS' ||
2191 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2192 '#define HAVE_SOCKETS' '-lnsl' ||
2193 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2194 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2195 feat_bail_required SOCKETS
2197 feat_is_disabled SOCKETS
2198 fi # feat_yes SOCKETS
2200 if feat_yes SOCKETS; then
2201 link_check getaddrinfo 'getaddrinfo(3)' \
2202 '#define HAVE_GETADDRINFO' << \!
2203 #include <sys/types.h>
2204 #include <sys/socket.h>
2208 struct addrinfo a, *ap;
2211 switch((lrv = getaddrinfo("foo
", "0", &a, &ap))){
2215 fprintf(stderr, "%s
\n", gai_strerror(lrv));
2224 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2225 compile_check arpa_inet_h '<arpa/inet.h>' \
2226 '#define HAVE_ARPA_INET_H' << \!
2227 #include <sys/types.h>
2228 #include <sys/socket.h>
2230 #include <netinet/in.h>
2231 #include <arpa/inet.h>
2234 ${cat} > ${tmp2}.c << \!
2235 #include <sys/types.h>
2236 #include <sys/socket.h>
2240 #include <netinet/in.h>
2241 #ifdef HAVE_ARPA_INET_H
2242 #include <arpa/inet.h>
2245 struct sockaddr_in servaddr;
2246 unsigned short portno;
2249 struct in_addr **pptr;
2252 if((ep = getservbyname("POPPY-PORT
", "tcp
")) != NULL)
2253 portno = (unsigned short)ep->s_port;
2255 if((hp = gethostbyname("POPPY-HOST
")) != NULL){
2256 pptr = (struct in_addr**)hp->h_addr_list;
2257 if(hp->h_addrtype != AF_INET)
2258 fprintf(stderr, "au
\n");
2261 case HOST_NOT_FOUND:
2267 fprintf(stderr, "au
\n");
2272 memset(&servaddr, 0, sizeof servaddr);
2273 servaddr.sin_family = AF_INET;
2274 servaddr.sin_port = htons(portno);
2275 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2276 fprintf(stderr, "Would connect to
%s
:%d ...
\n",
2277 inet_ntoa(**pptr), (int)portno);
2282 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2283 < ${tmp2}.c link_check gethostbyname \
2284 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2285 < ${tmp2}.c link_check gethostbyname \
2286 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2287 '' '-lsocket -lnsl' ||
2288 feat_bail_required SOCKETS
2292 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2293 #include <sys/socket.h>
2299 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2306 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2307 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2308 #include <sys/socket.h>
2316 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2317 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2322 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2323 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2324 #include <sys/socket.h>
2332 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2338 if feat_yes SSL; then # {{{
2339 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2340 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2341 # time: we need to test it first in order to get things right
2342 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2345 #define HAVE_XSSL_RESSL
2346 #define HAVE_XSSL_OPENSSL 0' << \!
2347 #include <openssl/opensslv.h>
2348 #ifdef LIBRESSL_VERSION_NUMBER
2355 VAL_SSL_FEATURES=libressl
2356 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2357 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2360 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2361 #include <openssl/opensslv.h>
2362 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2369 VAL_SSL_FEATURES=libssl-0x10100
2370 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2373 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2374 #include <openssl/opensslv.h>
2375 #ifdef OPENSSL_VERSION_NUMBER
2382 VAL_SSL_FEATURES=libssl-0x10000
2384 feat_bail_required SSL
2387 if feat_yes SSL; then # {{{
2388 if [ -n "${ossl_v1_1}" ]; then
2389 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2390 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2392 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2393 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2394 '-lssl -lcrypto' << \!
2395 #include <openssl/ssl.h>
2396 #include <openssl/err.h>
2397 #include <openssl/x509v3.h>
2398 #include <openssl/x509.h>
2399 #include <openssl/rand.h>
2400 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2401 # error We need TLSv1.
2404 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2407 PEM_read_PrivateKey(0, 0, 0, 0);
2413 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2414 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2415 '-lssl -lcrypto' << \!
2416 #include <openssl/ssl.h>
2417 #include <openssl/err.h>
2418 #include <openssl/x509v3.h>
2419 #include <openssl/x509.h>
2420 #include <openssl/rand.h>
2421 #if defined OPENSSL_NO_SSL3 &&\
2422 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2423 # error We need one of SSLv3 and TLSv1.
2426 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2429 PEM_read_PrivateKey(0, 0, 0, 0);
2436 feat_bail_required SSL
2440 if feat_yes SSL; then # {{{
2441 if feat_yes SSL_ALL_ALGORITHMS; then
2442 if [ -n "${ossl_v1_1}" ]; then
2443 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2444 '#define HAVE_SSL_ALL_ALGORITHMS'
2445 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2446 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2447 #include <openssl/evp.h>
2449 OpenSSL_add_all_algorithms();
2450 EVP_get_cipherbyname("two cents i never exist
");
2458 feat_bail_required SSL_ALL_ALGORITHMS
2460 elif [ -n "${ossl_v1_1}" ]; then
2461 without_check yes ssl_all_algo \
2462 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2463 '#define HAVE_SSL_ALL_ALGORITHMS'
2466 if [ -n "${ossl_v1_1}" ]; then
2467 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2468 '#define HAVE_XSSL_STACK_OF'
2469 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2470 '#define HAVE_XSSL_STACK_OF' << \!
2471 #include <stdio.h> /* For C89 NULL */
2472 #include <openssl/ssl.h>
2473 #include <openssl/err.h>
2474 #include <openssl/x509v3.h>
2475 #include <openssl/x509.h>
2476 #include <openssl/rand.h>
2478 STACK_OF(GENERAL_NAME) *gens = NULL;
2480 printf("%p
", gens); /* to use it */
2488 if [ -n "${ossl_v1_1}" ]; then
2489 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2490 '#define HAVE_XSSL_CONFIG'
2491 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2492 elif link_check xssl_conf \
2493 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2494 '#define HAVE_XSSL_CONFIG' << \!
2495 #include <stdio.h> /* For C89 NULL */
2496 #include <openssl/conf.h>
2498 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2499 CONF_modules_free();
2504 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2506 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2509 if [ -n "${ossl_v1_1}" ]; then
2510 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2511 '#define HAVE_XSSL_CONF_CTX'
2512 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2513 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2514 '#define HAVE_XSSL_CONF_CTX' << \!
2515 #include <openssl/ssl.h>
2516 #include <openssl/err.h>
2518 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2519 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2521 SSL_CONF_CTX_set_flags(cctx,
2522 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2523 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2524 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2525 SSL_CONF_cmd(cctx, "Protocol
", "ALL
");
2526 SSL_CONF_CTX_finish(cctx);
2527 SSL_CONF_CTX_free(cctx);
2533 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2535 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2538 if [ -n "${ossl_v1_1}" ]; then
2539 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2540 '#define HAVE_XSSL_CTX_CONFIG'
2541 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2542 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2543 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2544 '#define HAVE_XSSL_CTX_CONFIG' << \!
2545 #include <stdio.h> /* For C89 NULL */
2546 #include <openssl/ssl.h>
2548 SSL_CTX_config(NULL, "SOMEVAL
");
2553 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2555 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2558 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2559 without_check yes xssl_set_maxmin_proto \
2560 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2561 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2562 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2563 elif link_check xssl_set_maxmin_proto \
2564 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2565 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2566 #include <stdio.h> /* For C89 NULL */
2567 #include <openssl/ssl.h>
2569 SSL_CTX_set_min_proto_version(NULL, 0);
2570 SSL_CTX_set_max_proto_version(NULL, 10);
2575 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2577 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2580 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2581 '#define HAVE_XSSL_RAND_EGD' << \!
2582 #include <openssl/rand.h>
2584 return RAND_egd("some.where
") > 0;
2588 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd
"
2590 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2592 fi # feat_yes SSL }}}
2594 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2595 run_check ssl_md5 'MD5 digest in the used crypto library' \
2596 '#define HAVE_XSSL_MD5' << \!
2599 #include <openssl/md5.h>
2601 char const dat[] = "abrakadabrafidibus
";
2602 char dig[16], hex[16 * 2];
2606 memset(dig, 0, sizeof(dig));
2607 memset(hex, 0, sizeof(hex));
2609 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2610 MD5_Final(dig, &ctx);
2612 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2613 for(i = 0; i < sizeof(hex) / 2; i++){
2615 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2616 hex[++j] = hexchar(dig[i] & 0x0f);
2618 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326
", hex, sizeof(hex));
2623 if feat_yes SSL; then
2624 feat_def SSL_ALL_ALGORITHMS
2626 feat_bail_required SSL_ALL_ALGORITHMS
2629 feat_is_disabled SSL
2630 feat_is_disabled SSL_ALL_ALGORITHMS
2631 fi # }}} feat_yes SSL
2632 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2634 if [ "${have_xssl}" = yes ]; then
2642 if val_allof VAL_RANDOM \
2643 "arc4 ssl libgetrandom sysgetrandom urandom builtin error"; then
2646 msg
'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2651 link_check arc4random
'VAL_RANDOM: arc4random(3)' \
2652 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \
!
2662 if feat_yes SSL
; then
2663 msg
' . VAL_RANDOM: ssl ... yes'
2664 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2667 msg
' . VAL_RANDOM: ssl ... no'
2672 val_random_libgetrandom
() {
2673 link_check getrandom
'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2674 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2675 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2676 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\
!
2677 #include <sys/random.h>
2680 getrandom
(buf
, sizeof buf
, 0);
2686 val_random_sysgetrandom
() {
2687 link_check getrandom
'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2688 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2689 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2690 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\
!
2691 #include <sys/syscall.h>
2694 syscall
(SYS_getrandom
, buf
, sizeof buf
, 0);
2700 val_random_urandom
() {
2701 msg_nonl
' . VAL_RANDOM: /dev/urandom ... '
2702 if feat_yes CROSS_BUILD
; then
2703 msg
'yes (unchecked)'
2704 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2705 elif [ -f /dev
/urandom
]; then
2707 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2715 val_random_builtin
() {
2716 msg_nonl
' . VAL_RANDOM: builtin ... '
2717 if [ -n "${have_no_subsecond_time}" ]; then
2718 msg
'no\nERROR: %s %s' 'without a specialized PRG ' \
2719 'one of clock_gettime(2) and gettimeofday(2) is required.'
2723 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2727 val_random_error
() {
2728 msg
'ERROR: VAL_RANDOM search reached "error" entry'
2734 VAL_RANDOM
="${VAL_RANDOM} error"
2735 set -- ${VAL_RANDOM}
2739 eval val_random_
$randfun && break
2747 if feat_yes GSSAPI
; then
2748 ${cat} > ${tmp2}.c
<< \
!
2749 #include <gssapi/gssapi.h>
2751 gss_import_name
(0, 0, GSS_C_NT_HOSTBASED_SERVICE
, 0);
2752 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2756 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2758 if acmd_set i krb5-config
; then
2759 GSS_LIBS
="`CFLAGS= ${i} --libs gssapi`"
2760 GSS_INCS
="`CFLAGS= ${i} --cflags`"
2761 i
='GSS-API via krb5-config(1)'
2765 i
='GSS-API in gssapi/gssapi.h, libgssapi'
2767 if < ${tmp2}.c link_check gss \
2768 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2769 < ${tmp3}.c link_check gss \
2770 'GSS-API in gssapi.h, libgssapi' \
2771 '#define HAVE_GSSAPI
2772 #define GSSAPI_REG_INCLUDE' \
2774 < ${tmp2}.c link_check gss
'GSS-API in libgssapi_krb5' \
2775 '#define HAVE_GSSAPI' \
2777 < ${tmp3}.c link_check gss \
2778 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2779 '#define HAVE_GSSAPI
2780 #define GSS_REG_INCLUDE' \
2781 '-lgssapi -lkrb5 -lcrypto' \
2782 '-I/usr/include/kerberosV' ||\
2783 < ${tmp2}.c link_check gss
'GSS-API in libgss' \
2784 '#define HAVE_GSSAPI' \
2786 link_check gss
'GSS-API in libgssapi_krb5, old-style' \
2787 '#define HAVE_GSSAPI
2788 #define GSSAPI_OLD_STYLE' \
2789 '-lgssapi_krb5' << \
!
2790 #include <gssapi/gssapi.h>
2791 #include <gssapi/gssapi_generic.h>
2793 gss_import_name
(0, 0, gss_nt_service_name
, 0);
2794 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2801 feat_bail_required GSSAPI
2804 feat_is_disabled GSSAPI
2805 fi # feat_yes GSSAPI
2810 if feat_yes IDNA
; then # {{{
2811 if val_allof VAL_IDNA
"idnkit idn2 idn"; then
2814 msg
'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2819 link_check idna
'OPT_IDNA: GNU Libidn2' \
2820 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \
!
2823 char
*idna_utf8
, *idna_lc
;
2825 if(idn2_to_ascii_8z
("does.this.work", &idna_utf8
,
2826 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL
) != IDN2_OK
)
2828 if(idn2_to_unicode_8zlz
(idna_utf8
, &idna_lc
, 0) != IDN2_OK
)
2831 idn2_free
(idna_utf8
);
2838 link_check idna
'OPT_IDNA: GNU Libidn' \
2839 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \
!
2841 #include <idn-free.h>
2842 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2844 char
*utf8
, *idna_ascii
, *idna_utf8
;
2846 utf8
= stringprep_locale_to_utf8
("does.this.work");
2847 if (idna_to_ascii_8z
(utf8
, &idna_ascii
, IDNA_USE_STD3_ASCII_RULES
)
2850 idn_free
(idna_ascii
);
2851 /* (Rather link check only here
) */
2852 idna_utf8
= stringprep_convert
(idna_ascii
, "UTF-8", "de_DE");
2859 link_check idna
'OPT_IDNA: idnkit' \
2860 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \
!
2862 #include <idn/api.h>
2863 #include <idn/result.h>
2867 char local_name
[256];
2869 r
= idn_encodename
(IDN_ENCODE_APP
, "does.this.work", ace_name
,
2871 if (r
!= idn_success
) {
2872 fprintf
(stderr
, "idn_encodename failed: %s\n", idn_result_tostring
(r
));
2875 r
= idn_decodename
(IDN_DECODE_APP
, ace_name
, local_name
, sizeof
(local_name
));
2876 if (r
!= idn_success
) {
2877 fprintf
(stderr
, "idn_decodename failed: %s\n", idn_result_tostring
(r
));
2886 feat_bail_required IDNA
2891 VAL_IDNA
="${VAL_IDNA} bye"
2896 eval val_idna_
$randfun && break
2899 feat_is_disabled IDNA
2902 feat_def IMAP_SEARCH
2904 if feat_yes REGEX
; then
2905 if link_check regex
'regular expressions' '#define HAVE_REGEX' << \
!
2913 status
= regcomp
(&re
, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB
);
2914 xret
= regerror
(status
, &re
, NULL
, 0);
2915 status
= regexec
(&re
, "plan9", 0,NULL
, 0);
2917 return !(status
== REG_NOMATCH
);
2923 feat_bail_required REGEX
2926 feat_is_disabled REGEX
2929 if feat_yes MLE
; then
2930 if [ -n "${have_c90amend1}" ]; then
2932 echo '#define HAVE_MLE' >> ${h}
2934 feat_bail_required MLE
2937 feat_is_disabled MLE
2940 # Generic have-a-line-editor switch for those who need it below
2941 if [ -n "${have_mle}" ]; then
2945 if feat_yes HISTORY
; then
2946 if [ -n "${have_cle}" ]; then
2947 echo '#define HAVE_HISTORY' >> ${h}
2949 feat_is_unsupported HISTORY
2952 feat_is_disabled HISTORY
2955 if feat_yes KEY_BINDINGS
; then
2956 if [ -n "${have_mle}" ]; then
2957 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2959 feat_is_unsupported KEY_BINDINGS
2962 feat_is_disabled KEY_BINDINGS
2965 if feat_yes TERMCAP
; then
2967 link_check termcap
"termcap(5) (via ${4})" \
2968 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2973 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2974 static int my_putc(int c){return putchar(c);}
2976 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2977 int r2 = OK, r3 = ERR;
2979 tgetent(buf, getenv("TERM"));
2981 r1 = tgetstr(UNCONST("cm"), &cpb);
2983 r2 = tgetnum(UNCONST("Co"));
2984 r3 = tgetflag(UNCONST("ut"));
2985 tputs("cr", 1, &my_putc);
2986 return (r1 == NULL || r2 == -1 || r3 == 0);
2992 link_check terminfo
"terminfo(5) (via ${2})" \
2993 '#define HAVE_TERMCAP
2994 #define HAVE_TERMCAP_CURSES
2995 #define HAVE_TERMINFO' "${1}" << _EOT
2999 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3000 static int my_putc(int c){return putchar(c);}
3006 r0 = setupterm(NULL, 1, &er);
3007 r1 = tigetflag(UNCONST("bce"));
3008 r2 = tigetnum(UNCONST("colors"));
3009 r3 = tigetstr(UNCONST("cr"));
3010 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3011 tputs(tp, 1, &my_putc);
3012 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3013 r3 == (char*)-1 || r3 == NULL);
3018 if feat_yes TERMCAP_VIA_TERMINFO
; then
3019 __terminfolib
-ltinfo -ltinfo ||
3020 __terminfolib
-lcurses -lcurses ||
3021 __terminfolib
-lcursesw -lcursesw ||
3022 feat_bail_required TERMCAP_VIA_TERMINFO
3025 if [ -z "${have_terminfo}" ]; then
3026 __termcaplib
-ltermcap '' '' '-ltermcap' ||
3027 __termcaplib
-ltermcap '#include <curses.h>' '
3028 #define HAVE_TERMCAP_CURSES' \
3029 'curses.h / -ltermcap' ||
3030 __termcaplib
-lcurses '#include <curses.h>' '
3031 #define HAVE_TERMCAP_CURSES' \
3032 'curses.h / -lcurses' ||
3033 __termcaplib
-lcursesw '#include <curses.h>' '
3034 #define HAVE_TERMCAP_CURSES' \
3035 'curses.h / -lcursesw' ||
3036 feat_bail_required TERMCAP
3038 if [ -n "${have_termcap}" ]; then
3039 run_check tgetent_null \
3040 "tgetent(3) of termcap(5) takes NULL buffer" \
3041 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3042 #include <stdio.h> /* For C89 NULL */
3044 #ifdef HAVE_TERMCAP_CURSES
3045 # include <curses.h>
3049 tgetent(NULL, getenv("TERM"));
3056 feat_is_disabled TERMCAP
3057 feat_is_disabled TERMCAP_VIA_TERMINFO
3060 if feat_def SPAM_SPAMC
; then
3061 if acmd_set i spamc
; then
3062 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3066 if feat_yes SPAM_SPAMD
; then
3067 if [ -n "${have_af_unix}" ]; then
3068 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3070 feat_bail_required SPAM_SPAMD
3073 feat_is_disabled SPAM_SPAMD
3076 feat_def SPAM_FILTER
3078 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER
; then
3079 echo '#define HAVE_SPAM' >> ${h}
3081 echo '/* HAVE_SPAM */' >> ${h}
3084 if feat_yes QUOTE_FOLD
; then
3085 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3086 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3088 feat_bail_required QUOTE_FOLD
3091 feat_is_disabled QUOTE_FOLD
3094 feat_def FILTER_HTML_TAGSOUP
3102 squeeze_em
${inc} ${tmp}
3104 squeeze_em
${lib} ${tmp}
3109 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3110 ${cat} ${tmp} >> ${h}
3112 # We need these for correct "second stage configuration changed" detection */
3113 echo "/* `${cat} ${lib}` */" >> ${h}
3114 echo "/* `${cat} ${inc}` */" >> ${h}
3117 # Throw away all temporaries
3118 ${rm} -rf ${tmp0}.* ${tmp0}*
3120 # Create the string that is used by *features* and `version
'.
3121 # Take this nice opportunity and generate a visual listing of included and
3122 # non-included features for the person who runs the configuration
3123 echo 'The following features are included
(+) or not
(-):' > ${tmp}
3124 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3125 printf '/* The
"feature string" */\n' >> ${h}
3126 # Because + is expanded by *folder* if first in "echo $features", put something
3127 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3131 sdoc
=`option_doc_of ${opt}`
3132 [ -z "${sdoc}" ] && continue
3133 sopt
="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3134 feat_yes
${opt} && sign
=+ || sign
=-
3135 printf -- "${sep}${sign}${sopt}" >> ${h}
3137 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3139 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3141 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3142 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3143 printf '"\n' >> ${h}
3145 # Create the real mk-config.mk
3146 # Note we cannout use explicit ./ filename prefix for source and object
3147 # pathnames because of a bug in bmake(1)
3149 if feat_no AMALGAMATION
; then
3150 for i
in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3151 i
=`basename "${i}" .c`
3152 if [ "${i}" = privsep
]; then
3155 objlist
="${objlist} ${i}.o"
3156 srclist
="${srclist} \$(SRCDIR)${i}.c"
3157 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3158 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3160 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3162 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3163 "main.o
" "main.c
" >> ${mk}
3164 srclist=main.c objlist=main.o
3165 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3167 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3168 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3169 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3170 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3171 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3173 if [ "${i}" = main.c ] ||
3174 [ "${i}" = privsep.c ]; then
3177 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3178 printf '# include "%s
%s
"\n' "${SRCDIR}" "${i}" >> ${h}
3182 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3184 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3186 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3187 echo "INCS
= `${cat} ${inc}`" >> ${mk}
3189 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3193 # We have completed the new configuration header. Check whether *really*
3194 # Do the "second stage configuration changed" detection, exit if nothing to do
3195 if [ -f ${oldh} ]; then
3196 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3197 ${mv} -f ${oldh} ${h}
3198 msg 'Effective configuration is up-to-date'
3203 msg 'Effective configuration has been updated..'
3206 if [ -n "${config_updated}" ]; then
3207 msg 'Wiping away old objects and such'
3208 ( eval "${MAKE} -f ${oldmk} clean" )
3212 while read l; do msg "${l}"; done < ${tmp}
3215 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3216 msg ' . bindir: %s' "${VAL_BINDIR}"
3217 if feat_yes DOTLOCK; then
3218 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3220 msg ' . mandir: %s' "${VAL_MANDIR}"
3221 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3222 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3225 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3229 if [ -z "${have_fnmatch}" ]; then
3230 msg ' . The function fnmatch(3) could not be found.'
3231 msg ' Filename patterns like wildcard are not supported on your system'
3233 if [ -z "${have_fchdir}" ]; then
3234 msg ' . The function fchdir(2) could not be found.'
3235 msg ' We will use chdir(2) instead.'
3236 msg ' This is a problem only if the current working directory is changed'
3237 msg ' while this program is inside of it'