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='Error 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 # The problem is that we don't have any tools we can use right now, so
74 # encapsulate stuff in functions which get called in right order later on
90 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
94 option_parse OPTIONS_DETECT
"${XOPTIONS_DETECT}"
95 option_parse OPTIONS
"${XOPTIONS}"
96 option_parse OPTIONS_XTRA
"${XOPTIONS_XTRA}"
99 # Predefined CONFIG= urations take precedence over anything else
100 if [ -n "${CONFIG}" ]; then
105 [nN
][uU
][lL
][lL
][iI
])
109 [mM
][iI
][nN
][iI
][mM
][aA
][lL
])
110 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
117 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
120 [nN
][eE
][tT
][sS
][eE
][nN
][dD
])
121 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
125 OPT_GSSAPI
=1 OPT_NETRC
=1
133 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
136 [mM
][aA
][xX
][iI
][mM
][aA
][lL
])
139 [dD
][eE
][vV
][eE
][lL
])
141 OPT_DEVEL
=1 OPT_DEBUG
=1 OPT_NYD2
=1
143 [oO
][dD
][eE
][vV
][eE
][lL
])
148 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
149 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
153 msg_nonl
"CONFIG=${CONFIG} ... "
157 # Inter-relationships XXX sort this!
160 OPT_SSL_ALL_ALGORITHMS
=0
163 if feat_no SMTP
&& feat_no POP3
&& feat_no IMAP
; then
166 if feat_no SOCKETS
; then
167 if feat_require SMTP
; then
168 msg
'ERROR: need SOCKETS for required feature SMTP'
171 if feat_require POP3
; then
172 msg
'ERROR: need SOCKETS for required feature POP3'
175 if feat_require IMAP
; then
176 msg
'ERROR: need SOCKETS for required feature IMAP'
179 OPT_SSL
=0 OPT_SSL_ALL_ALGORITHMS
=0
180 OPT_SMTP
=0 OPT_POP3
=0 OPT_IMAP
=0
181 OPT_GSSAPI
=0 OPT_NETRC
=0 OPT_AGENT
=0
183 if feat_no SMTP
&& feat_no IMAP
; then
187 if feat_no ICONV
; then
188 if feat_yes IMAP
; then
189 if feat_yes ALWAYS_UNICODE_LOCALE
; then
190 msg
'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
191 elif feat_require IMAP
; then
192 msg
'ERROR: need ICONV for required feature IMAP'
195 msg
'ERROR: disabling IMAP due to missing ICONV'
200 if feat_yes IDNA
; then
201 if feat_require IDNA
; then
202 msg
'ERROR: need ICONV for required feature IDNA'
205 msg
'ERROR: disabling IDNA due to missing ICONV'
211 OPT_HISTORY
=0 OPT_KEY_BINDINGS
=0
214 # If we don't need MD5 leave it alone
215 if feat_no SOCKETS
; then
219 if feat_no TERMCAP
; then
220 OPT_TERMCAP_VIA_TERMINFO
=0
223 if feat_yes DEVEL
; then
231 h
=.
/mk-config.h h_name
=mk-config.h
234 newlst
=.
/mk-nconfig.lst
235 newmk
=.
/mk-nconfig.mk
236 newev
=.
/mk-nconfig.ev
242 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
244 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
245 # via path_check() later on once possible
247 # TODO cc_maxopt is brute simple, we should compile test program and dig real
248 # compiler versions for known compilers, then be more specific
249 [ -n "${cc_maxopt}" ] || cc_maxopt
=100
250 #cc_force_no_stackprot=
253 #ld_rpath_not_runpath=
258 [ -n "${OS}" ] && [ -n "${OSENV}" ] && [ -n "${OSFULLSPEC}" ] ||
259 thecmd_testandset_fail uname uname
261 # We don't "have any utility": only path adjustments and such in here!
262 [ -n "${OS}" ] || OS
=`${uname} -s`
265 if [ ${OS} = SunOS
]; then
266 msg
'SunOS / Solaris? Applying some "early setup" rules ...'
267 _os_early_setup_sunos
271 _os_early_setup_sunos
() {
272 # According to standards(5), this is what we need to do
273 if [ -d /usr
/xpg4
]; then :; else
274 msg
'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
277 PATH
="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
278 [ -d /usr
/xpg6
] && PATH
="/usr/xpg6/bin:${PATH}"
283 # OSENV ends up in *build-osenv*
284 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
285 # etc.), it is not baked into the binary
286 OS
=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
287 [ -n "${OSENV}" ] || OSENV
=`${uname} -sm`
288 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC
=`${uname} -a`
289 msg
'Operating system is %s' ${OS}
291 if [ ${OS} = darwin
]; then
292 msg
' . have special Darwin environmental addons...'
293 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
294 elif [ ${OS} = sunos
]; then
295 msg
' . have special SunOS / Solaris "setup" rules ...'
297 elif [ ${OS} = unixware
]; then
298 if feat_yes AUTOCC
&& acmd_set CC cc
; then
299 msg
' . have special UnixWare environmental rules ...'
300 feat_yes DEBUG
&& _CFLAGS
='-v -Xa -g' || _CFLAGS
='-Xa -O'
302 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
303 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
304 export CC CFLAGS LDFLAGS
305 OPT_AUTOCC
=0 ld_need_R_flags
=-R
307 elif [ -n "${VERBOSE}" ]; then
308 msg
' . no special treatment for this system necessary or known'
311 # Sledgehammer: better set _GNU_SOURCE
312 # And in general: oh, boy!
313 OS_DEFINES
="${OS_DEFINES}#define _GNU_SOURCE\n"
314 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
315 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
316 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
318 # On pkgsrc(7) systems automatically add /usr/pkg/*
319 if [ -d /usr
/pkg
] && feat_yes USE_PKGSYS
; then
320 msg
' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
321 C_INCLUDE_PATH
=/usr
/pkg
/include
:${C_INCLUDE_PATH}
322 LD_LIBRARY_PATH
=/usr
/pkg
/lib
:${LD_LIBRARY_PATH}
323 ld_rpath_not_runpath
=1
328 C_INCLUDE_PATH
=/usr
/xpg
4/include
:${C_INCLUDE_PATH}
329 LD_LIBRARY_PATH
=/usr
/xpg
4/lib
:${LD_LIBRARY_PATH}
332 if [ -d /opt
/csw
] && feat_yes USE_PKGSYS
; then
333 msg
' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
334 C_INCLUDE_PATH
=/opt
/csw
/include
:${C_INCLUDE_PATH}
335 LD_LIBRARY_PATH
=/opt
/csw
/lib
:${LD_LIBRARY_PATH}
336 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
338 if [ -d /opt
/schily
] && feat_yes USE_PKGSYS
; then
339 msg
' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
340 C_INCLUDE_PATH
=/opt
/schily
/include
:${C_INCLUDE_PATH}
341 LD_LIBRARY_PATH
=/opt
/schily
/lib
:${LD_LIBRARY_PATH}
342 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
345 OS_DEFINES
="${OS_DEFINES}#define __EXTENSIONS__\n"
346 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
348 [ -n "${cksum}" ] ||
cksum=/opt
/csw
/gnu
/cksum
349 if [ -x "${cksum}" ]; then :; else
350 msg
'ERROR: Not an executable program: %s' "${cksum}"
351 msg
'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
352 msg
'ERROR: However, we do so only for tests.'
353 msg
'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
357 if feat_yes AUTOCC
; then
358 if acmd_set CC cc
; then
359 feat_yes DEBUG
&& _CFLAGS
="-v -Xa -g" || _CFLAGS
="-Xa -O"
361 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
362 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
363 export CC CFLAGS LDFLAGS
364 OPT_AUTOCC
=0 ld_need_R_flags
=-R
366 cc_maxopt
=2 cc_force_no_stackprot
=1
371 # Check out compiler ($CC) and -flags ($CFLAGS)
373 # Even though it belongs into cc_flags we will try to compile and link
374 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
375 # EXTRA_CFLAGS/EXTRA_LDFLAGS
376 if feat_no AUTOCC
; then
378 # Ensure those don't do any harm
379 EXTRA_CFLAGS
= EXTRA_LDFLAGS
=
380 export EXTRA_CFLAGS EXTRA_LDFLAGS
384 export CFLAGS LDFLAGS
387 [ -n "${CC}" ] && { _cc_default
; return; }
389 msg_nonl
'Searching for a usable C compiler .. $CC='
390 if acmd_set CC clang || acmd_set CC gcc ||
391 acmd_set CC tcc || acmd_set CC pcc ||
392 acmd_set CC c89 || acmd_set CC c99
; then
395 msg
'boing booom tschak'
396 msg
'ERROR: I cannot find a compiler!'
397 msg
' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
398 msg
' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
406 if [ -z "${CC}" ]; then
407 msg
'To go on like you have chosen, please set $CC, rerun.'
411 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG
; then
414 msg
'Using C compiler ${CC}=%s' "${CC}"
419 if feat_yes AUTOCC
; then
420 if [ -f ${lst} ] && feat_no DEBUG
&& [ -z "${VERBOSE}" ]; then
422 msg
'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
426 msg
'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
429 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
430 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
431 msg ' . have special tcc(1) environmental rules ...'
434 # As of pcc CVS 2016-04-02, stack protection support is announced but
435 # will break if used on Linux
436 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
437 cc_force_no_stackprot=1
442 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
443 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
444 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
446 if feat_no DEBUG; then
447 CFLAGS="-DNDEBUG ${CFLAGS}"
451 export CFLAGS LDFLAGS
455 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
462 if feat_yes DEBUG; then
463 # May have problems to find libtcc cc_check -b
467 if ld_check -Wl,-rpath =./ no; then
468 ld_need_R_flags=-Wl,-rpath=
469 if [ -z "${ld_rpath_not_runpath}" ]; then
470 ld_check -Wl,--enable-new-dtags
472 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
474 ld_runtime_flags # update!
477 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
478 unset __cflags __ldflags
481 _cc_flags_generic() {
482 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
484 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
486 # E.g., valgrind does not work well with high optimization
487 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
488 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
489 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
492 # Check -g first since some others may rely upon -g / optim. level
493 if feat_yes DEBUG; then
496 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
498 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
500 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
506 if feat_yes AMALGAMATION; then
510 #if feat_yes DEVEL && cc_check -Weverything; then
515 cc_check -Wbad-function-cast
516 cc_check -Wcast-align
519 cc_check -Wmissing-prototypes
522 cc_check -Wwrite-strings
523 cc_check -Wno-long-long
527 if feat_yes AMALGAMATION && feat_no DEVEL; then
528 cc_check -Wno-unused-function
530 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
532 cc_check -fno-unwind-tables
533 cc_check -fno-asynchronous-unwind-tables
534 cc_check -fstrict-aliasing
535 if cc_check -fstrict-overflow && feat_yes DEVEL; then
536 cc_check -Wstrict-overflow=5
539 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
540 if [ -z "${cc_force_no_stackprot}" ]; then
541 if cc_check -fstack-protector-strong ||
542 cc_check -fstack-protector-all; then
543 cc_check -D_FORTIFY_SOURCE=2
546 msg ' ! Not checking for -fstack-protector compiler option,'
547 msg ' ! since that caused errors in a "similar" configuration.'
548 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
552 # LD (+ dependend CC)
554 if feat_yes ASAN_ADDRESS; then
556 if cc_check -fsanitize=address &&
557 ld_check -fsanitize=address; then
560 feat_bail_required ASAN_ADDRESS
565 if feat_yes ASAN_MEMORY; then
567 if cc_check -fsanitize=memory &&
568 ld_check -fsanitize=memory &&
569 cc_check -fsanitize-memory-track-origins=2 &&
570 ld_check -fsanitize-memory-track-origins=2; then
573 feat_bail_required ASAN_MEMORY
578 ld_check -Wl,-z,relro
579 if [ -z "${ld_no_bind_now}" ]; then
582 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
584 ld_check -Wl,-z,noexecstack
585 if ld_check -Wl,-rpath =./ no; then
586 ld_need_R_flags=-Wl,-rpath=
587 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
588 if [ -z "${ld_rpath_not_runpath}" ]; then
589 ld_check -Wl,--enable-new-dtags
591 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
593 ld_runtime_flags # update!
594 elif ld_check -Wl,-R ./ no; then
595 ld_need_R_flags=-Wl,-R
596 if [ -z "${ld_rpath_not_runpath}" ]; then
597 ld_check -Wl,--enable-new-dtags
599 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
601 ld_runtime_flags # update!
604 # Address randomization
606 if cc_check -fPIE || cc_check -fpie; then
607 ld_check -pie || _CFLAGS=${_ccfg}
611 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
612 unset __cflags __ldflags
615 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
618 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
619 ## redirection, so use "printf '' >" instead
621 ## Very first: we undergo several states regarding I/O redirection etc.,
622 ## but need to deal with option updates from within all. Since all the
623 ## option stuff should be above the scissor line, define utility functions
624 ## and redefine them as necessary.
625 ## And, since we have those functions, simply use them for whatever
627 t1=ten10one1ten10one1
628 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
629 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
630 ) > /dev/null 2>&1; then
637 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
643 # which(1) not standardized, command(1) -v may return non-executable: unroll!
644 acmd_test() { __acmd "${1}" 1 0 0; }
645 acmd_test_fail() { __acmd "${1}" 1 1 0; }
646 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
647 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
648 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
649 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
650 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
651 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
652 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
653 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
655 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
657 if [ "${dotest}" -ne 0 ]; then
658 eval dotest=\$${varname}
659 if [ -n "${dotest}" ]; then
660 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
661 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
667 [ -n "${noglob_shell}" ] && set -o noglob
669 [ -n "${noglob_shell}" ] && set +o noglob
673 if [ -z "${path}" ] || [ "${path}" = . ]; then
674 if [ -d "${PWD}" ]; then
680 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
681 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
682 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
683 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
688 # We may have no builtin string functions, we yet have no programs we can
689 # use, try to access once from the root, assuming it is an absolute path if
690 # that finds the executable
691 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
692 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
693 msg ' . ${%s} ... %s' "${pname}" "${pname}"
694 [ -n "${varname}" ] && eval ${varname}="${pname}"
698 [ ${dofail} -eq 0 ] && return 1
699 msg 'ERROR: no trace of utility '"${pname}"
706 printf >&2 -- "${fmt}\\n" "${@}"
712 printf >&2 -- "${fmt}" "${@}"
715 # Our feature check environment
717 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
718 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
722 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
723 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
724 [ "x${1}" = xrequire ]
728 [ "x${1}" = xrequire ]
733 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
734 if feat_val_no "${i}"; then
736 elif feat_val_yes "${i}"; then
739 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
750 _feat_check ${1} && return 1
756 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
757 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
760 feat_bail_required() {
761 if feat_require ${1}; then
762 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
765 feat_is_unsupported "${1}"
769 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
770 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
773 feat_is_unsupported() {
774 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
775 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
777 option_update # XXX this is rather useless here (dependency chain..)
781 if feat_yes ${1}; then
782 echo '#define HAVE_'${1}'' >> ${h}
785 feat_is_disabled "${@}"
791 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
792 # options, without documentation, to $1
794 i="`${awk} -v input
=\"${2}\" '
797 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
800 v = substr(input, voff, RLENGTH)
801 input = substr(input, voff + RLENGTH)
804 d = substr(v, doff + 2, length(v) - doff - 1)
805 v = substr(v, 1, doff - 1)
815 # Return the "documentation string" for option $1, itself if none such
817 ${awk} -v want="${1}" \
818 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
821 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
824 v = substr(input, voff, RLENGTH)
825 input = substr(input, voff + RLENGTH)
828 d = substr(v, doff + 2, length(v) - doff - 1)
829 v = substr(v, 1, doff - 1)
843 # Join the values from make.rc into what currently is defined, not
844 # overwriting yet existing settings
846 # We want read(1) to perform reverse solidus escaping in order to be able to
847 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
848 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
849 < ${rc} ${awk} 'BEGIN{line = ""}{
850 gsub(/^[[:space:]]+/, "", $0)
851 gsub(/[[:space:]]+$/, "", $0)
852 if(gsub(/\\$/, "", $0)){
857 if(index(line, "#") == 1){
859 }else if(length(line)){
865 if [ -n "${good_shell}" ]; then
868 i=`${awk} -v LINE
="${line}" 'BEGIN{
869 gsub(/=.*$/, "", LINE)
873 if [ "${i}" = "${line}" ]; then
874 msg 'ERROR: invalid syntax in: %s' "${line}"
878 eval j="\$${i}" jx="\${${i}+x}"
879 if [ -n "${j}" ] || [ "${jx}" = x ]; then
882 j=`${awk} -v LINE
="${line}" 'BEGIN{
883 gsub(/^[^=]*=/, "", LINE)
884 gsub(/^\"*/, "", LINE)
885 gsub(/\"*$/, "", LINE)
889 [ "${i}" = "DESTDIR" ] && continue
892 # Reread the mixed version right now
897 # Expand the option values, which may contain shell snippets
898 ${rm} -f ${newlst} ${newmk} ${newh}
899 exec 5<&0 6>&1 <${tmp} >${newlst}
902 if [ -n "${good_shell}" ]; then
904 [ "${i}" != "${i#OPT_}" ] && z=1
906 i=`${awk} -v LINE
="${line}" 'BEGIN{
907 gsub(/=.*$/, "", LINE);\
910 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
916 if [ -n "${z}" ]; then
917 j="`echo ${j} |
${tr} '[A-Z]' '[a-z]'`"
918 if [ -z "${j}" ] || feat_val_no "${j}"; then
920 printf " /* #undef ${i} */\n" >> ${newh}
921 elif feat_val_yes "${j}"; then
922 if feat_val_require "${j}"; then
927 printf " /* #define ${i} */\n" >> ${newh}
929 msg 'ERROR: cannot parse <%s>' "${line}"
933 printf "#define ${i} \"${j}\"\n" >> ${newh}
935 printf "${i} = ${j}\n" >> ${newmk}
939 exec 0<&5 1>&6 5<&- 6<&-
944 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
947 if((j = split(USER, ua)) == 0)
951 if(us == "all" || us == "any")
954 for(ii = i; ii != 0; --ii)
955 if(tolower(ha[ii]) == us){
965 [ ${__rv__} -ne 0 ] && return ${__rv__}
967 if ${awk} -v USER="${__expo__}" '
969 if((j = split(USER, ua)) == 0)
973 if(us == "all" || us == "any")
985 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
986 varname=${1} addflag=${2} flagvarname=${3}
989 [ -n "${noglob_shell}" ] && set -o noglob
991 [ -n "${noglob_shell}" ] && set +o noglob
996 [ -z "${i}" ] && continue
997 [ -d "${i}" ] || continue
998 if [ -n "${j}" ]; then
999 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1004 # But do not link any fakeroot path into our binaries!
1005 if [ -n "${addflag}" ]; then
1006 case "${i}" in *fakeroot*) continue;; esac
1007 k="${k} ${addflag}${i}"
1013 # But do not link any fakeroot path into our binaries!
1014 if [ -n "${addflag}" ]; then
1015 case "${i}" in *fakeroot*) continue;; esac
1016 k="${k} ${addflag}${i}"
1020 eval "${varname}=\"${j}\""
1021 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1025 ld_runtime_flags() {
1026 if [ -n "${ld_need_R_flags}" ]; then
1029 set -- ${LD_LIBRARY_PATH}
1033 # But do not link any fakeroot path into our binaries!
1034 case "${i}" in *fakeroot*) continue;; esac
1035 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1036 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1040 # Disable it for a possible second run.
1045 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1046 if "${CC}" ${INCS} \
1047 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1048 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1049 _CFLAGS="${_CFLAGS} ${1}"
1050 [ -n "${cc_check_silent}" ] || msg 'yes'
1053 [ -n "${cc_check_silent}" ] || msg 'no'
1058 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1059 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1060 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1061 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1062 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1063 [ -n "${cc_check_silent}" ] || msg 'yes'
1066 [ -n "${cc_check_silent}" ] || msg 'no'
1072 variable=$1 topic=$2 define=$3
1075 msg_nonl ' . %s ... ' "${topic}"
1076 echo "/* checked ${topic} */" >> ${h}
1077 ${rm} -f ${tmp} ${tmp}.o
1078 if [ "${dump_test_program}" = 1 ]; then
1079 echo '*** test program is'
1080 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1082 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1084 #echo '*** the preprocessor generates'
1085 #${make} -f ${makefile} ${tmp}.x
1087 echo '*** tests results'
1091 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1094 msg_nonl ' . %s ... ' "${topic}"
1096 echo '*** enforced unchecked results are'
1097 if feat_val_yes ${yesno}; then
1098 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1099 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1100 LIBS="${LIBS} ${libs}"
1101 echo "${libs}" >> ${lib}
1102 INCS="${INCS} ${incs}"
1103 echo "${incs}" >> ${inc}
1106 echo "${define}" >> ${h}
1107 eval have_${variable}=yes
1110 echo "/* ${define} */" >> ${h}
1112 eval unset have_${variable}
1118 variable=$1 topic=$2 define=$3
1120 _check_preface "${variable}" "${topic}" "${define}"
1122 if ${make} -f ${makefile} XINCS="${INCS}" \
1123 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1125 [ -f ./${tmp}.o ]; then
1127 echo "${define}" >> ${h}
1128 eval have_${variable}=yes
1131 echo "/* ${define} */" >> ${h}
1133 eval unset have_${variable}
1139 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1141 _check_preface "${variable}" "${topic}" "${define}"
1143 if feat_yes CROSS_BUILD; then
1144 if [ ${run} = 1 ]; then
1149 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1150 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1151 XLIBS="${LIBS} ${libs}" \
1154 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1155 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1157 echo "${define}" >> ${h}
1158 LIBS="${LIBS} ${libs}"
1159 echo "${libs}" >> ${lib}
1160 INCS="${INCS} ${incs}"
1161 echo "${incs}" >> ${inc}
1162 eval have_${variable}=yes
1166 echo "/* ${define} */" >> ${h}
1167 eval unset have_${variable}
1173 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1177 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1181 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1185 < "${1}" > "${2}" ${awk} \
1186 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1189 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1191 # First of all, create new configuration and check whether it changed
1193 # Very easy checks for the operating system in order to be able to adjust paths
1194 # or similar very basic things which we need to be able to go at all
1197 # Check those tools right now that we need before including $rc
1198 msg 'Checking for basic utility set'
1199 thecmd_testandset_fail awk awk
1200 thecmd_testandset_fail rm rm
1201 thecmd_testandset_fail tr tr
1203 # Initialize the option set
1204 msg_nonl 'Setting up configuration options ... '
1208 # Include $rc, but only take from it what wasn't overwritten by the user from
1209 # within the command line or from a chosen fixed CONFIG=
1210 # Note we leave alone the values
1211 trap "exit 1" HUP INT TERM
1212 trap "${rm} -f ${tmp}" EXIT
1214 msg_nonl 'Joining in %s ... ' ${rc}
1218 # We need to know about that now, in order to provide utility overwrites etc.
1221 msg 'Checking for remaining set of utilities'
1222 thecmd_testandset_fail grep grep
1224 # Before we step ahead with the other utilities perform a path cleanup first.
1228 thecmd_testandset_fail basename basename
1229 thecmd_testandset_fail cat cat
1230 thecmd_testandset_fail chmod chmod
1231 thecmd_testandset_fail cp cp
1232 thecmd_testandset_fail cmp cmp
1234 thecmd_testandset_fail mkdir mkdir
1235 thecmd_testandset_fail mv mv
1237 thecmd_testandset_fail sed sed
1238 thecmd_testandset_fail sort sort
1239 thecmd_testandset_fail tee tee
1241 thecmd_testandset chown chown ||
1242 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1243 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1245 thecmd_testandset_fail MAKE make
1248 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1250 # For ./cc-test.sh only
1251 thecmd_testandset_fail cksum cksum
1253 # Update OPT_ options now, in order to get possible inter-dependencies right
1256 # (No functions since some shells loose non-exported variables in traps)
1257 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1258 trap "trap \"\" HUP INT TERM EXIT;\
1259 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1261 # Our configuration options may at this point still contain shell snippets,
1262 # we need to evaluate them in order to get them expanded, and we need those
1263 # evaluated values not only in our new configuration file, but also at hand..
1264 msg_nonl 'Evaluating all configuration items ... '
1268 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1269 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1271 # The problem now is that the test should be able to run in the users linker
1272 # and path environment, so we need to place the test: rule first, before
1273 # injecting the relevant make variables. Set up necessary environment
1274 if [ -z "${VERBOSE}" ]; then
1275 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1276 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1277 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1278 printf -- "ECHO_TEST = @\n" >> ${newmk}
1279 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1280 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1281 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1283 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1284 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1286 # Add the known utility and some other variables
1287 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1288 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1289 if feat_yes DOTLOCK; then
1290 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1292 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1297 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1298 MAKE MAKEFLAGS make SHELL strip \
1301 printf "${i} = ${j}\n" >> ${newmk}
1302 printf "${i}=${j}\n" >> ${newlst}
1303 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1305 # Note that makefile reads and eval'uates one line of this file, whereas other
1306 # consumers source it via .(1)
1307 printf "\n" >> ${newev}
1309 # Build a basic set of INCS and LIBS according to user environment.
1310 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1311 path_check C_INCLUDE_PATH -I _INCS
1312 INCS="${INCS} ${_INCS}"
1313 path_check LD_LIBRARY_PATH -L _LIBS
1314 LIBS="${LIBS} ${_LIBS}"
1316 export C_INCLUDE_PATH LD_LIBRARY_PATH
1318 # Some environments need runtime path flags to be able to go at all
1321 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1325 ${cat} > ${tmp}.c << \!
1328 static void doit(char const *s);
1330 main(int argc, char **argv){
1333 doit("Hello world");
1337 doit(char const *s){
1339 memcpy(buf, s, strlen(s) +1);
1344 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1345 -o ${tmp2} ${tmp}.c ${LIBS}; then
1348 msg 'ERROR: i cannot compile a "Hello world" via'
1350 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1351 msg 'ERROR: Please read INSTALL, rerun'
1355 # This may also update ld_runtime_flags() (again)
1362 printf -- "${i}=${j}\n" >> ${newlst}
1368 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1372 if [ -n "${j}" ]; then
1373 printf -- "${i} = ${j}\n" >> ${newmk}
1374 printf -- "${i}=${j}\n" >> ${newlst}
1378 # Now finally check whether we already have a configuration and if so, whether
1379 # all those parameters are still the same.. or something has actually changed
1380 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1381 echo 'Configuration is up-to-date'
1383 elif [ -f ${lst} ]; then
1384 echo 'Configuration has been updated..'
1385 ( eval "${MAKE} -f ./mk-config.mk clean" )
1388 echo 'Shiny configuration..'
1391 # Time to redefine helper 1
1393 ${rm} -f ${lst} ${h} ${mk}
1397 ${mv} -f ${newlst} ${lst}
1398 ${mv} -f ${newev} ${ev}
1399 ${mv} -f ${newh} ${h}
1400 ${mv} -f ${newmk} ${mk}
1402 ## Compile and link checking
1408 makefile=./${tmp0}.mk
1410 # (No function since some shells loose non-exported variables in traps)
1411 trap "trap \"\" HUP INT TERM;\
1412 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1413 trap "trap \"\" HUP INT TERM EXIT;\
1414 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1416 # Time to redefine helper 2
1420 printf "*** ${fmt}\\n" "${@}"
1421 printf -- "${fmt}\\n" "${@}" >&5
1426 printf "*** ${fmt}\\n" "${@}"
1427 printf -- "${fmt}" "${@}" >&5
1431 exec 5>&2 > ${log} 2>&1
1433 echo "${LIBS}" > ${lib}
1434 echo "${INCS}" > ${inc}
1435 ${cat} > ${makefile} << \!
1436 .SUFFIXES: .o .c .x .y
1438 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1440 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1442 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1447 # May be multiline..
1449 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1450 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1451 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1453 # Generate n_err_number OS mappings
1456 feat_yes DEVEL && NV= || NV=noverbose
1457 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1458 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1459 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1462 feat_def ALWAYS_UNICODE_LOCALE
1463 feat_def AMALGAMATION 0
1464 feat_def CROSS_BUILD
1469 feat_def ASAN_ADDRESS 0
1470 feat_def ASAN_MEMORY 0
1476 if xrun_check inline 'inline functions' \
1477 '#define HAVE_INLINE
1478 #define n_INLINE static inline' << \!
1479 static inline int ilf(int i){return ++i;}
1480 int main(void){return ilf(-1);}
1484 elif xrun_check inline 'inline functions (via __inline)' \
1485 '#define HAVE_INLINE
1486 #define n_INLINE static __inline' << \!
1487 static __inline int ilf(int i){return ++i;}
1488 int main(void){return ilf(-1);}
1494 ## Test for "basic" system-calls / functionality that is used by all parts
1495 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1496 ## macros to be used by only the subprograms (potentially).
1498 if run_check clock_gettime 'clock_gettime(2)' \
1499 '#define HAVE_CLOCK_GETTIME' << \!
1505 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1512 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1513 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1519 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1526 elif run_check gettimeofday 'gettimeofday(2)' \
1527 '#define HAVE_GETTIMEOFDAY' << \!
1528 #include <stdio.h> /* For C89 NULL */
1529 #include <sys/time.h>
1534 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1542 have_no_subsecond_time=1
1545 if run_check nanosleep 'nanosleep(2)' \
1546 '#define HAVE_NANOSLEEP' << \!
1553 ts.tv_nsec = 100000;
1554 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1561 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1562 '#define HAVE_NANOSLEEP' '-lrt' << \!
1569 ts.tv_nsec = 100000;
1570 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1577 # link_check is enough for this, that function is so old, trust the proto
1578 elif link_check sleep 'sleep(3)' \
1579 '#define HAVE_SLEEP' << \!
1583 if(!sleep(1) || errno != ENOSYS)
1591 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1595 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1604 if((gid = getgid()) != 0)
1606 if((uid = getuid()) != 0)
1608 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1610 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1618 msg 'ERROR: we require user and group info / database searches.'
1619 msg 'That much Unix we indulge ourselfs.'
1623 if link_check ftruncate 'ftruncate(2)' \
1624 '#define HAVE_FTRUNCATE' << \!
1626 #include <sys/types.h>
1628 return (ftruncate(0, 0) != 0);
1634 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1635 msg 'ERROR: we require the ftruncate(2) system call.'
1639 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1643 struct sigaction nact, oact;
1645 nact.sa_handler = SIG_DFL;
1646 sigemptyset(&nact.sa_mask);
1647 nact.sa_flags = SA_RESTART;
1648 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1654 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1658 if link_check snprintf 'snprintf(3)' << \!
1663 snprintf(b, sizeof b, "%s", "string");
1670 msg 'ERROR: we require the snprintf(3) function.'
1674 if link_check environ 'environ(3)' << \!
1675 #include <stdio.h> /* For C89 NULL */
1677 extern char **environ;
1679 return environ[0] == NULL;
1685 msg 'ERROR: we require the environ(3) array for subprocess control.'
1689 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1692 setenv("s-mailx", "i want to see it cute!", 1);
1693 unsetenv("s-mailx");
1699 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1702 putenv("s-mailx=i want to see it cute!");
1709 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1713 if link_check termios 'termios.h and tc*(3) family' << \!
1714 #include <termios.h>
1716 struct termios tios;
1718 tcgetattr(0, &tios);
1719 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1726 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1727 msg 'That much Unix we indulge ourselfs.'
1733 if link_check vsnprintf 'vsnprintf(3)' << \!
1736 static void dome(char *buf, size_t blen, ...){
1740 vsnprintf(buf, blen, "%s", ap);
1746 dome(b, sizeof b, "string");
1753 feat_bail_required ERRORS
1756 if [ "${have_vsnprintf}" = yes ]; then
1758 link_check va_copy "va_copy(3) (as ${2})" \
1759 "#define HAVE_N_VA_COPY
1760 #define n_va_copy ${2}" <<_EOT
1764 # if defined __va_copy && !defined va_copy
1765 # define va_copy __va_copy
1768 static void dome2(char *buf, size_t blen, va_list src){
1772 vsnprintf(buf, blen, "%s", ap);
1775 static void dome(char *buf, size_t blen, ...){
1779 dome2(buf, blen, ap);
1785 dome(b, sizeof b, "string");
1790 __va_copy 0 va_copy || __va_copy 1 __va_copy
1793 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1800 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1802 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1804 /* Only link check */
1805 fpathconf(0, _PC_NAME_MAX);
1811 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1818 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1824 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1825 #include <termios.h>
1829 tcgetwinsize(0, &ws);
1834 # We use this only then for now (need NOW+1)
1835 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1836 #include <fcntl.h> /* For AT_* */
1837 #include <sys/stat.h>
1840 struct timespec ts[2];
1842 ts[0].tv_nsec = UTIME_NOW;
1843 ts[1].tv_nsec = UTIME_OMIT;
1844 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1852 # The random check has been moved to below SSL detection due to multiple choice
1853 # selection for PRG sources
1855 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1858 putc_unlocked('@', stdout);
1863 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1871 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1874 char x_buf[4096], *x = realpath(".", x_buf);
1876 return (x != NULL) ? 0 : 1;
1880 if run_check realpath_malloc 'realpath(3) takes NULL' \
1881 '#define HAVE_REALPATH_NULL' << \!
1884 char *x = realpath(".", NULL);
1888 return (x != NULL) ? 0 : 1;
1897 ## optional and selectable
1900 if feat_yes DOTLOCK; then
1901 if run_check readlink 'readlink(2)' << \!
1907 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1915 feat_bail_required DOTLOCK
1919 if feat_yes DOTLOCK; then
1920 if run_check fchown 'fchown(2)' << \!
1924 if(!fchown(0, 0, 0) || errno != ENOSYS)
1932 feat_bail_required DOTLOCK
1936 if feat_yes DOTLOCK; then
1937 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1938 '#define HAVE_PRCTL_DUMPABLE' << \!
1939 #include <sys/prctl.h>
1942 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1949 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1950 '#define HAVE_PTRACE_DENY' << \!
1951 #include <sys/ptrace.h>
1954 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1961 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1962 '#define HAVE_SETPFLAGS_PROTECT' << \!
1966 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1976 ## Now it is the time to fork away the BASE_ series
1979 squeeze_em ${inc} ${tmp}
1981 squeeze_em ${lib} ${tmp}
1984 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1985 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1987 ## The remains are expected to be used only by the main MUA binary!
1990 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1993 setlocale(LC_ALL, "");
1997 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1999 OPT_MULTIBYTE_CHARSETS=0
2001 OPT_TERMINAL_CHARSET=0
2002 if [ -n "${have_setlocale}" ]; then
2003 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2004 '#define HAVE_C90AMEND1' << \!
2010 char mbb[MB_LEN_MAX + 1];
2015 mbtowc(&wc, "x
", 1);
2016 mbrtowc(&wc, "x
", 1, NULL);
2018 return (mblen("\
0", 1) == 0);
2021 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2023 if [ -n "${have_c90amend1}" ]; then
2024 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2031 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2034 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2035 #include <langinfo.h>
2039 return (nl_langinfo(CODESET) == NULL);
2042 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2045 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2046 #include <fnmatch.h>
2048 return (fnmatch("*", ".
", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2052 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2056 return !(de.d_type == DT_UNKNOWN ||
2057 de.d_type == DT_DIR || de.d_type == DT_LNK);
2061 ## optional and selectable
2063 if feat_yes ICONV; then
2064 # To be able to create tests we need to figure out which replacement
2065 # sequence the iconv(3) implementation creates
2066 ${cat} > ${tmp2}.c << \!
2067 #include <stdio.h> /* For C89 NULL */
2071 char inb[16], oub[16], *inbp, *oubp;
2075 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2076 inl = sizeof("\342\200\223") -1;
2080 if((id = iconv_open("ascii
", "utf-8
")) == (iconv_t)-1)
2082 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2087 oul = (size_t)(oubp - oub);
2090 /* Character-wise replacement? */
2098 /* Byte-wise replacement? */
2099 if(oul == sizeof("\342\200\223") -1){
2100 if(!memcmp(oub, "???????
", sizeof("\342\200\223") -1))
2102 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2109 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2110 '#define HAVE_ICONV' ||
2111 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2112 '#define HAVE_ICONV' '-liconv' ||
2113 feat_bail_required ICONV
2115 if feat_no CROSS_BUILD; then
2116 { ./${tmp}; } >/dev/null 2>&1
2118 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2119 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2120 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2121 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2122 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2126 feat_is_disabled ICONV
2129 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2130 ${cat} > ${tmp2}.c << \!
2131 #include <sys/types.h>
2132 #include <sys/socket.h>
2136 struct sockaddr_un soun;
2138 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2140 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2142 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2148 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2149 '#define HAVE_UNIX_SOCKETS' ||
2150 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2151 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2152 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2153 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2156 if feat_yes SOCKETS; then
2157 ${cat} > ${tmp2}.c << \!
2158 #include <sys/types.h>
2159 #include <sys/socket.h>
2160 #include <netinet/in.h>
2165 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2167 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2173 < ${tmp2}.c run_check sockets 'sockets' \
2174 '#define HAVE_SOCKETS' ||
2175 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2176 '#define HAVE_SOCKETS' '-lnsl' ||
2177 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2178 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2179 feat_bail_required SOCKETS
2181 feat_is_disabled SOCKETS
2182 fi # feat_yes SOCKETS
2184 if feat_yes SOCKETS; then
2185 link_check getaddrinfo 'getaddrinfo(3)' \
2186 '#define HAVE_GETADDRINFO' << \!
2187 #include <sys/types.h>
2188 #include <sys/socket.h>
2192 struct addrinfo a, *ap;
2195 switch((lrv = getaddrinfo("foo
", "0", &a, &ap))){
2199 fprintf(stderr, "%s
\n", gai_strerror(lrv));
2208 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2209 compile_check arpa_inet_h '<arpa/inet.h>' \
2210 '#define HAVE_ARPA_INET_H' << \!
2211 #include <sys/types.h>
2212 #include <sys/socket.h>
2214 #include <netinet/in.h>
2215 #include <arpa/inet.h>
2218 ${cat} > ${tmp2}.c << \!
2219 #include <sys/types.h>
2220 #include <sys/socket.h>
2224 #include <netinet/in.h>
2225 #ifdef HAVE_ARPA_INET_H
2226 #include <arpa/inet.h>
2229 struct sockaddr_in servaddr;
2230 unsigned short portno;
2233 struct in_addr **pptr;
2236 if((ep = getservbyname("POPPY-PORT
", "tcp
")) != NULL)
2237 portno = (unsigned short)ep->s_port;
2239 if((hp = gethostbyname("POPPY-HOST
")) != NULL){
2240 pptr = (struct in_addr**)hp->h_addr_list;
2241 if(hp->h_addrtype != AF_INET)
2242 fprintf(stderr, "au
\n");
2245 case HOST_NOT_FOUND:
2251 fprintf(stderr, "au
\n");
2256 memset(&servaddr, 0, sizeof servaddr);
2257 servaddr.sin_family = AF_INET;
2258 servaddr.sin_port = htons(portno);
2259 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2260 fprintf(stderr, "Would connect to
%s
:%d ...
\n",
2261 inet_ntoa(**pptr), (int)portno);
2266 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2267 < ${tmp2}.c link_check gethostbyname \
2268 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2269 < ${tmp2}.c link_check gethostbyname \
2270 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2271 '' '-lsocket -lnsl' ||
2272 feat_bail_required SOCKETS
2276 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2277 #include <sys/socket.h>
2283 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2290 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2291 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2292 #include <sys/socket.h>
2300 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2301 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2306 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2307 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2308 #include <sys/socket.h>
2316 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2322 if feat_yes SSL; then # {{{
2323 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2324 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2325 # time: we need to test it first in order to get things right
2326 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2329 #define HAVE_XSSL_RESSL
2330 #define HAVE_XSSL_OPENSSL 0' << \!
2331 #include <openssl/opensslv.h>
2332 #ifdef LIBRESSL_VERSION_NUMBER
2339 VAL_SSL_FEATURES=libressl
2340 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2341 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2344 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2345 #include <openssl/opensslv.h>
2346 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2353 VAL_SSL_FEATURES=libssl-0x10100
2354 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2357 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2358 #include <openssl/opensslv.h>
2359 #ifdef OPENSSL_VERSION_NUMBER
2366 VAL_SSL_FEATURES=libssl-0x10000
2368 feat_bail_required SSL
2371 if feat_yes SSL; then # {{{
2372 if [ -n "${ossl_v1_1}" ]; then
2373 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2374 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2376 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2377 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2378 '-lssl -lcrypto' << \!
2379 #include <openssl/ssl.h>
2380 #include <openssl/err.h>
2381 #include <openssl/x509v3.h>
2382 #include <openssl/x509.h>
2383 #include <openssl/rand.h>
2384 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2385 # error We need TLSv1.
2388 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2391 PEM_read_PrivateKey(0, 0, 0, 0);
2397 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2398 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2399 '-lssl -lcrypto' << \!
2400 #include <openssl/ssl.h>
2401 #include <openssl/err.h>
2402 #include <openssl/x509v3.h>
2403 #include <openssl/x509.h>
2404 #include <openssl/rand.h>
2405 #if defined OPENSSL_NO_SSL3 &&\
2406 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2407 # error We need one of SSLv3 and TLSv1.
2410 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2413 PEM_read_PrivateKey(0, 0, 0, 0);
2420 feat_bail_required SSL
2424 if feat_yes SSL; then # {{{
2425 if feat_yes SSL_ALL_ALGORITHMS; then
2426 if [ -n "${ossl_v1_1}" ]; then
2427 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2428 '#define HAVE_SSL_ALL_ALGORITHMS'
2429 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2430 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2431 #include <openssl/evp.h>
2433 OpenSSL_add_all_algorithms();
2434 EVP_get_cipherbyname("two cents i never exist
");
2442 feat_bail_required SSL_ALL_ALGORITHMS
2444 elif [ -n "${ossl_v1_1}" ]; then
2445 without_check yes ssl_all_algo \
2446 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2447 '#define HAVE_SSL_ALL_ALGORITHMS'
2450 if [ -n "${ossl_v1_1}" ]; then
2451 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2452 '#define HAVE_XSSL_STACK_OF'
2453 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2454 '#define HAVE_XSSL_STACK_OF' << \!
2455 #include <stdio.h> /* For C89 NULL */
2456 #include <openssl/ssl.h>
2457 #include <openssl/err.h>
2458 #include <openssl/x509v3.h>
2459 #include <openssl/x509.h>
2460 #include <openssl/rand.h>
2462 STACK_OF(GENERAL_NAME) *gens = NULL;
2464 printf("%p
", gens); /* to use it */
2472 if [ -n "${ossl_v1_1}" ]; then
2473 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2474 '#define HAVE_XSSL_CONFIG'
2475 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2476 elif link_check xssl_conf \
2477 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2478 '#define HAVE_XSSL_CONFIG' << \!
2479 #include <stdio.h> /* For C89 NULL */
2480 #include <openssl/conf.h>
2482 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2483 CONF_modules_free();
2488 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2490 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2493 if [ -n "${ossl_v1_1}" ]; then
2494 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2495 '#define HAVE_XSSL_CONF_CTX'
2496 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2497 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2498 '#define HAVE_XSSL_CONF_CTX' << \!
2499 #include <openssl/ssl.h>
2500 #include <openssl/err.h>
2502 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2503 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2505 SSL_CONF_CTX_set_flags(cctx,
2506 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2507 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2508 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2509 SSL_CONF_cmd(cctx, "Protocol
", "ALL
");
2510 SSL_CONF_CTX_finish(cctx);
2511 SSL_CONF_CTX_free(cctx);
2517 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2519 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2522 if [ -n "${ossl_v1_1}" ]; then
2523 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2524 '#define HAVE_XSSL_CTX_CONFIG'
2525 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2526 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2527 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2528 '#define HAVE_XSSL_CTX_CONFIG' << \!
2529 #include <stdio.h> /* For C89 NULL */
2530 #include <openssl/ssl.h>
2532 SSL_CTX_config(NULL, "SOMEVAL
");
2537 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2539 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2542 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2543 without_check yes xssl_set_maxmin_proto \
2544 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2545 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2546 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2547 elif link_check xssl_set_maxmin_proto \
2548 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2549 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2550 #include <stdio.h> /* For C89 NULL */
2551 #include <openssl/ssl.h>
2553 SSL_CTX_set_min_proto_version(NULL, 0);
2554 SSL_CTX_set_max_proto_version(NULL, 10);
2559 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2561 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2564 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2565 '#define HAVE_XSSL_RAND_EGD' << \!
2566 #include <openssl/rand.h>
2568 return RAND_egd("some.where
") > 0;
2572 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd
"
2574 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2576 fi # feat_yes SSL }}}
2578 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2579 run_check ssl_md5 'MD5 digest in the used crypto library' \
2580 '#define HAVE_XSSL_MD5' << \!
2583 #include <openssl/md5.h>
2585 char const dat[] = "abrakadabrafidibus
";
2586 char dig[16], hex[16 * 2];
2590 memset(dig, 0, sizeof(dig));
2591 memset(hex, 0, sizeof(hex));
2593 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2594 MD5_Final(dig, &ctx);
2596 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2597 for(i = 0; i < sizeof(hex) / 2; i++){
2599 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2600 hex[++j] = hexchar(dig[i] & 0x0f);
2602 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326
", hex, sizeof(hex));
2607 if feat_yes SSL; then
2608 feat_def SSL_ALL_ALGORITHMS
2610 feat_bail_required SSL_ALL_ALGORITHMS
2613 feat_is_disabled SSL
2614 feat_is_disabled SSL_ALL_ALGORITHMS
2615 fi # }}} feat_yes SSL
2616 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2618 if [ "${have_xssl}" = yes ]; then
2626 if val_allof VAL_RANDOM \
2627 "arc4 ssl libgetrandom sysgetrandom urandom builtin error"; then
2630 msg
'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2635 link_check arc4random
'VAL_RANDOM: arc4random(3)' \
2636 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \
!
2646 if feat_yes SSL
; then
2647 msg
' . VAL_RANDOM: ssl ... yes'
2648 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2651 msg
' . VAL_RANDOM: ssl ... no'
2656 val_random_libgetrandom
() {
2657 link_check getrandom
'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2658 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2659 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2660 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\
!
2661 #include <sys/random.h>
2664 getrandom
(buf
, sizeof buf
, 0);
2670 val_random_sysgetrandom
() {
2671 link_check getrandom
'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2672 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2673 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2674 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\
!
2675 #include <sys/syscall.h>
2678 syscall
(SYS_getrandom
, buf
, sizeof buf
, 0);
2684 val_random_urandom
() {
2685 msg_nonl
' . VAL_RANDOM: /dev/urandom ... '
2686 if feat_yes CROSS_BUILD
; then
2687 msg
'yes (unchecked)'
2688 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2689 elif [ -f /dev
/urandom
]; then
2691 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2699 val_random_builtin
() {
2700 msg_nonl
' . VAL_RANDOM: builtin ... '
2701 if [ -n "${have_no_subsecond_time}" ]; then
2702 msg
'no\nERROR: %s %s' 'without a specialized PRG ' \
2703 'one of clock_gettime(2) and gettimeofday(2) is required.'
2707 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2711 val_random_error
() {
2712 msg
'ERROR: VAL_RANDOM search reached "error" entry'
2718 VAL_RANDOM
="${VAL_RANDOM} error"
2719 set -- ${VAL_RANDOM}
2723 eval val_random_
$randfun && break
2731 if feat_yes GSSAPI
; then
2732 ${cat} > ${tmp2}.c
<< \
!
2733 #include <gssapi/gssapi.h>
2735 gss_import_name
(0, 0, GSS_C_NT_HOSTBASED_SERVICE
, 0);
2736 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2740 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2742 if acmd_set i krb5-config
; then
2743 GSS_LIBS
="`CFLAGS= ${i} --libs gssapi`"
2744 GSS_INCS
="`CFLAGS= ${i} --cflags`"
2745 i
='GSS-API via krb5-config(1)'
2749 i
='GSS-API in gssapi/gssapi.h, libgssapi'
2751 if < ${tmp2}.c link_check gss \
2752 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2753 < ${tmp3}.c link_check gss \
2754 'GSS-API in gssapi.h, libgssapi' \
2755 '#define HAVE_GSSAPI
2756 #define GSSAPI_REG_INCLUDE' \
2758 < ${tmp2}.c link_check gss
'GSS-API in libgssapi_krb5' \
2759 '#define HAVE_GSSAPI' \
2761 < ${tmp3}.c link_check gss \
2762 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2763 '#define HAVE_GSSAPI
2764 #define GSS_REG_INCLUDE' \
2765 '-lgssapi -lkrb5 -lcrypto' \
2766 '-I/usr/include/kerberosV' ||\
2767 < ${tmp2}.c link_check gss
'GSS-API in libgss' \
2768 '#define HAVE_GSSAPI' \
2770 link_check gss
'GSS-API in libgssapi_krb5, old-style' \
2771 '#define HAVE_GSSAPI
2772 #define GSSAPI_OLD_STYLE' \
2773 '-lgssapi_krb5' << \
!
2774 #include <gssapi/gssapi.h>
2775 #include <gssapi/gssapi_generic.h>
2777 gss_import_name
(0, 0, gss_nt_service_name
, 0);
2778 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2785 feat_bail_required GSSAPI
2788 feat_is_disabled GSSAPI
2789 fi # feat_yes GSSAPI
2794 if feat_yes IDNA
; then # {{{
2795 if val_allof VAL_IDNA
"idnkit idn2 idn"; then
2798 msg
'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2803 link_check idna
'OPT_IDNA: GNU Libidn2' \
2804 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \
!
2807 char
*idna_utf8
, *idna_lc
;
2809 if(idn2_to_ascii_8z
("does.this.work", &idna_utf8
,
2810 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL
) != IDN2_OK
)
2812 if(idn2_to_unicode_8zlz
(idna_utf8
, &idna_lc
, 0) != IDN2_OK
)
2815 idn2_free
(idna_utf8
);
2822 link_check idna
'OPT_IDNA: GNU Libidn' \
2823 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \
!
2825 #include <idn-free.h>
2826 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2828 char
*utf8
, *idna_ascii
, *idna_utf8
;
2830 utf8
= stringprep_locale_to_utf8
("does.this.work");
2831 if (idna_to_ascii_8z
(utf8
, &idna_ascii
, IDNA_USE_STD3_ASCII_RULES
)
2834 idn_free
(idna_ascii
);
2835 /* (Rather link check only here
) */
2836 idna_utf8
= stringprep_convert
(idna_ascii
, "UTF-8", "de_DE");
2843 link_check idna
'OPT_IDNA: idnkit' \
2844 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \
!
2846 #include <idn/api.h>
2847 #include <idn/result.h>
2851 char local_name
[256];
2853 r
= idn_encodename
(IDN_ENCODE_APP
, "does.this.work", ace_name
,
2855 if (r
!= idn_success
) {
2856 fprintf
(stderr
, "idn_encodename failed: %s\n", idn_result_tostring
(r
));
2859 r
= idn_decodename
(IDN_DECODE_APP
, ace_name
, local_name
, sizeof
(local_name
));
2860 if (r
!= idn_success
) {
2861 fprintf
(stderr
, "idn_decodename failed: %s\n", idn_result_tostring
(r
));
2870 feat_bail_required IDNA
2875 VAL_IDNA
="${VAL_IDNA} bye"
2880 eval val_idna_
$randfun && break
2883 feat_is_disabled IDNA
2886 feat_def IMAP_SEARCH
2888 if feat_yes REGEX
; then
2889 if link_check regex
'regular expressions' '#define HAVE_REGEX' << \
!
2897 status
= regcomp
(&re
, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB
);
2898 xret
= regerror
(status
, &re
, NULL
, 0);
2899 status
= regexec
(&re
, "plan9", 0,NULL
, 0);
2901 return !(status
== REG_NOMATCH
);
2907 feat_bail_required REGEX
2910 feat_is_disabled REGEX
2913 if feat_yes MLE
; then
2914 if [ -n "${have_c90amend1}" ]; then
2916 echo '#define HAVE_MLE' >> ${h}
2918 feat_bail_required MLE
2921 feat_is_disabled MLE
2924 # Generic have-a-line-editor switch for those who need it below
2925 if [ -n "${have_mle}" ]; then
2929 if feat_yes HISTORY
; then
2930 if [ -n "${have_cle}" ]; then
2931 echo '#define HAVE_HISTORY' >> ${h}
2933 feat_is_unsupported HISTORY
2936 feat_is_disabled HISTORY
2939 if feat_yes KEY_BINDINGS
; then
2940 if [ -n "${have_mle}" ]; then
2941 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2943 feat_is_unsupported KEY_BINDINGS
2946 feat_is_disabled KEY_BINDINGS
2949 if feat_yes TERMCAP
; then
2951 link_check termcap
"termcap(5) (via ${4})" \
2952 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2957 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2958 static int my_putc(int c){return putchar(c);}
2960 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2961 int r2 = OK, r3 = ERR;
2963 tgetent(buf, getenv("TERM"));
2965 r1 = tgetstr(UNCONST("cm"), &cpb);
2967 r2 = tgetnum(UNCONST("Co"));
2968 r3 = tgetflag(UNCONST("ut"));
2969 tputs("cr", 1, &my_putc);
2970 return (r1 == NULL || r2 == -1 || r3 == 0);
2976 link_check terminfo
"terminfo(5) (via ${2})" \
2977 '#define HAVE_TERMCAP
2978 #define HAVE_TERMCAP_CURSES
2979 #define HAVE_TERMINFO' "${1}" << _EOT
2983 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2984 static int my_putc(int c){return putchar(c);}
2990 r0 = setupterm(NULL, 1, &er);
2991 r1 = tigetflag(UNCONST("bce"));
2992 r2 = tigetnum(UNCONST("colors"));
2993 r3 = tigetstr(UNCONST("cr"));
2994 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2995 tputs(tp, 1, &my_putc);
2996 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2997 r3 == (char*)-1 || r3 == NULL);
3002 if feat_yes TERMCAP_VIA_TERMINFO
; then
3003 __terminfolib
-ltinfo -ltinfo ||
3004 __terminfolib
-lcurses -lcurses ||
3005 __terminfolib
-lcursesw -lcursesw ||
3006 feat_bail_required TERMCAP_VIA_TERMINFO
3009 if [ -z "${have_terminfo}" ]; then
3010 __termcaplib
-ltermcap '' '' '-ltermcap' ||
3011 __termcaplib
-ltermcap '#include <curses.h>' '
3012 #define HAVE_TERMCAP_CURSES' \
3013 'curses.h / -ltermcap' ||
3014 __termcaplib
-lcurses '#include <curses.h>' '
3015 #define HAVE_TERMCAP_CURSES' \
3016 'curses.h / -lcurses' ||
3017 __termcaplib
-lcursesw '#include <curses.h>' '
3018 #define HAVE_TERMCAP_CURSES' \
3019 'curses.h / -lcursesw' ||
3020 feat_bail_required TERMCAP
3022 if [ -n "${have_termcap}" ]; then
3023 run_check tgetent_null \
3024 "tgetent(3) of termcap(5) takes NULL buffer" \
3025 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3026 #include <stdio.h> /* For C89 NULL */
3028 #ifdef HAVE_TERMCAP_CURSES
3029 # include <curses.h>
3033 tgetent(NULL, getenv("TERM"));
3040 feat_is_disabled TERMCAP
3041 feat_is_disabled TERMCAP_VIA_TERMINFO
3044 if feat_def SPAM_SPAMC
; then
3045 if acmd_set i spamc
; then
3046 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3050 if feat_yes SPAM_SPAMD
; then
3051 if [ -n "${have_af_unix}" ]; then
3052 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3054 feat_bail_required SPAM_SPAMD
3057 feat_is_disabled SPAM_SPAMD
3060 feat_def SPAM_FILTER
3062 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER
; then
3063 echo '#define HAVE_SPAM' >> ${h}
3065 echo '/* HAVE_SPAM */' >> ${h}
3068 if feat_yes QUOTE_FOLD
; then
3069 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3070 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3072 feat_bail_required QUOTE_FOLD
3075 feat_is_disabled QUOTE_FOLD
3078 feat_def FILTER_HTML_TAGSOUP
3086 squeeze_em
${inc} ${tmp}
3088 squeeze_em
${lib} ${tmp}
3093 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3094 ${cat} ${tmp} >> ${h}
3098 # Create the string that is used by *features* and `version'.
3099 # Take this nice opportunity and generate a visual listing of included and
3100 # non-included features for the person who runs the configuration
3101 msg
'\nThe following features are included (+) or not (-):'
3102 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3103 printf '/* The "feature string" */\n' >> ${h}
3104 # Because + is expanded by *folder* if first in "echo $features", put something
3105 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3109 sdoc
=`option_doc_of ${opt}`
3110 [ -z "${sdoc}" ] && continue
3111 sopt
="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3112 feat_yes
${opt} && sign
=+ || sign
=-
3113 printf -- "${sep}${sign}${sopt}" >> ${h}
3115 msg " %s
%s
: %s
" ${sign} ${sopt} "${sdoc}"
3117 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3119 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3120 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3121 printf '"\n' >> ${h}
3123 # Create the real mk-config.mk
3124 # Note we cannout use explicit ./ filename prefix for source and object
3125 # pathnames because of a bug in bmake(1)
3126 ${rm} -rf ${tmp0}.* ${tmp0}*
3128 if feat_no AMALGAMATION
; then
3129 for i
in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3130 i
=`basename "${i}" .c`
3131 if [ "${i}" = privsep
]; then
3134 objlist
="${objlist} ${i}.o"
3135 srclist
="${srclist} \$(SRCDIR)${i}.c"
3136 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3137 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3139 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3141 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3142 "main.o
" "main.c
" >> ${mk}
3143 srclist=main.c objlist=main.o
3144 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3146 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3147 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3148 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3149 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3150 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3152 if [ "${i}" = main.c ] ||
3153 [ "${i}" = privsep.c ]; then
3156 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3157 printf '# include "%s
%s
"\n' "${SRCDIR}" "${i}" >> ${h}
3161 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3163 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3165 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3166 echo "INCS
= `${cat} ${inc}`" >> ${mk}
3168 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3173 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3174 msg ' . bindir: %s' "${VAL_BINDIR}"
3175 if feat_yes DOTLOCK; then
3176 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3178 msg ' . mandir: %s' "${VAL_MANDIR}"
3179 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3180 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3183 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3187 if [ -z "${have_fnmatch}" ]; then
3188 msg ' . The function fnmatch(3) could not be found.'
3189 msg ' Filename patterns like wildcard are not supported on your system'
3191 if [ -z "${have_fchdir}" ]; then
3192 msg ' . The function fchdir(2) could not be found.'
3193 msg ' We will use chdir(2) instead.'
3194 msg ' This is a problem only if the current working directory is changed'
3195 msg ' while this program is inside of it'