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)' \
26 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
27 SMTP='Simple Mail Transfer Protocol client' \
28 POP3='Post Office Protocol Version 3 client' \
29 IMAP='IMAP v4r1 client' \
30 GSSAPI='Generic Security Service authentication' \
31 NETRC='.netrc file support' \
33 MD5='MD5 message digest (APOP, CRAM-MD5)' \
34 IDNA='Internationalized Domain Names for Applications (encode only)' \
35 IMAP_SEARCH='IMAP-style search expressions' \
36 REGEX='Regular expressions' \
37 MLE='Mailx Line Editor' \
38 HISTORY='Line editor history management' \
39 KEY_BINDINGS='Configurable key bindings' \
40 TERMCAP='Terminal capability queries (termcap(5))' \
41 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
42 ERRORS='Error log message ring' \
43 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
45 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
46 DOCSTRINGS='Command documentation help 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
])
108 [mM
][iI
][nN
][iI
][mM
][aA
][lL
])
109 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
115 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
118 [nN
][eE
][tT
][sS
][eE
][nN
][dD
])
119 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
123 OPT_GSSAPI
=1 OPT_NETRC
=1
130 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
133 [mM
][aA
][xX
][iI
][mM
][aA
][lL
])
136 [dD
][eE
][vV
][eE
][lL
])
138 OPT_DEVEL
=1 OPT_DEBUG
=1 OPT_NYD2
=1
140 [oO
][dD
][eE
][vV
][eE
][lL
])
145 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
146 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
150 msg_nonl
"CONFIG=${CONFIG} ... "
154 # Inter-relationships XXX sort this!
156 if feat_yes NOEXTRANDOM
; then
161 OPT_SSL_RANDOM
=0 OPT_SSL_ALL_ALGORITHMS
=0
164 if feat_no SMTP
&& feat_no POP3
&& feat_no IMAP
; then
167 if feat_no SOCKETS
; then
168 if feat_require SMTP
; then
169 msg
'ERROR: need SOCKETS for required feature SMTP'
172 if feat_require POP3
; then
173 msg
'ERROR: need SOCKETS for required feature POP3'
176 if feat_require IMAP
; then
177 msg
'ERROR: need SOCKETS for required feature IMAP'
180 OPT_SSL
=0 OPT_SSL_RANDOM
=0 OPT_SSL_ALL_ALGORITHMS
=0
181 OPT_SMTP
=0 OPT_POP3
=0 OPT_IMAP
=0
182 OPT_GSSAPI
=0 OPT_NETRC
=0 OPT_AGENT
=0
184 if feat_no SMTP
&& feat_no IMAP
; then
188 if feat_no ICONV
; then
189 if feat_yes IMAP
; then
190 if feat_yes ALWAYS_UNICODE_LOCALE
; then
191 msg
'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
192 elif feat_require IMAP
; then
193 msg
'ERROR: need ICONV for required feature IMAP'
196 msg
'ERROR: disabling IMAP due to missing ICONV'
201 if feat_yes IDNA
; then
202 if feat_require IDNA
; then
203 msg
'ERROR: need ICONV for required feature IDNA'
206 msg
'ERROR: disabling IDNA due to missing ICONV'
212 OPT_HISTORY
=0 OPT_KEY_BINDINGS
=0
215 # If we don't need MD5 leave it alone
216 if feat_no SOCKETS
; then
220 if feat_no TERMCAP
; then
221 OPT_TERMCAP_VIA_TERMINFO
=0
224 if feat_yes DEVEL
; then
232 h
=.
/mk-config.h h_name
=mk-config.h
235 newlst
=.
/mk-nconfig.lst
236 newmk
=.
/mk-nconfig.mk
237 newev
=.
/mk-nconfig.ev
243 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
245 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
246 # via path_check() later on once possible
248 # TODO cc_maxopt is brute simple, we should compile test program and dig real
249 # compiler versions for known compilers, then be more specific
250 [ -n "${cc_maxopt}" ] || cc_maxopt
=100
251 #cc_force_no_stackprot=
254 #ld_rpath_not_runpath=
259 # We don't "have any utility": only path adjustments and such in here!
260 [ -n "${OS}" ] || OS
=`${uname} -s`
263 if [ ${OS} = SunOS
]; then
264 msg
'SunOS / Solaris? Applying some "early setup" rules ...'
265 _os_early_setup_sunos
269 _os_early_setup_sunos
() {
270 # According to standards(5), this is what we need to do
271 if [ -d /usr
/xpg4
]; then :; else
272 msg
'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
275 PATH
="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
276 [ -d /usr
/xpg6
] && PATH
="/usr/xpg6/bin:${PATH}"
281 # OSENV ends up in *build-osenv*
282 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
283 # etc.), it is not baked into the binary
284 OS
=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
285 [ -n "${OSENV}" ] || OSENV
=`${uname} -sm`
286 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC
=`${uname} -a`
287 msg
'Operating system is %s' ${OS}
289 if [ ${OS} = darwin
]; then
290 msg
' . have special Darwin environmental addons...'
291 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
292 elif [ ${OS} = sunos
]; then
293 msg
' . have special SunOS / Solaris "setup" rules ...'
295 elif [ ${OS} = unixware
]; then
296 if feat_yes AUTOCC
&& acmd_set CC cc
; then
297 msg
' . have special UnixWare environmental rules ...'
298 feat_yes DEBUG
&& _CFLAGS
='-v -Xa -g' || _CFLAGS
='-Xa -O'
300 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
301 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
302 export CC CFLAGS LDFLAGS
303 OPT_AUTOCC
=0 ld_need_R_flags
=-R
305 elif [ -n "${VERBOSE}" ]; then
306 msg
' . no special treatment for this system necessary or known'
309 # Sledgehammer: better set _GNU_SOURCE
310 # And in general: oh, boy!
311 OS_DEFINES
="${OS_DEFINES}#define _GNU_SOURCE\n"
312 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
313 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
314 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
316 # On pkgsrc(7) systems automatically add /usr/pkg/*
317 if [ -d /usr
/pkg
] && feat_yes USE_PKGSYS
; then
318 msg
' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
319 C_INCLUDE_PATH
=/usr
/pkg
/include
:${C_INCLUDE_PATH}
320 LD_LIBRARY_PATH
=/usr
/pkg
/lib
:${LD_LIBRARY_PATH}
321 ld_rpath_not_runpath
=1
326 C_INCLUDE_PATH
=/usr
/xpg
4/include
:${C_INCLUDE_PATH}
327 LD_LIBRARY_PATH
=/usr
/xpg
4/lib
:${LD_LIBRARY_PATH}
330 if [ -d /opt
/csw
] && feat_yes USE_PKGSYS
; then
331 msg
' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
332 C_INCLUDE_PATH
=/opt
/csw
/include
:${C_INCLUDE_PATH}
333 LD_LIBRARY_PATH
=/opt
/csw
/lib
:${LD_LIBRARY_PATH}
334 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
336 if [ -d /opt
/schily
] && feat_yes USE_PKGSYS
; then
337 msg
' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
338 C_INCLUDE_PATH
=/opt
/schily
/include
:${C_INCLUDE_PATH}
339 LD_LIBRARY_PATH
=/opt
/schily
/lib
:${LD_LIBRARY_PATH}
340 ld_no_bind_now
=1 ld_rpath_not_runpath
=1
343 OS_DEFINES
="${OS_DEFINES}#define __EXTENSIONS__\n"
344 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
346 [ -n "${cksum}" ] ||
cksum=/opt
/csw
/gnu
/cksum
347 if [ -x "${cksum}" ]; then :; else
348 msg
'ERROR: Not an executable program: %s' "${cksum}"
349 msg
'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
350 msg
'ERROR: However, we do so only for tests.'
351 msg
'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
355 if feat_yes AUTOCC
; then
356 if acmd_set CC cc
; then
357 feat_yes DEBUG
&& _CFLAGS
="-v -Xa -g" || _CFLAGS
="-Xa -O"
359 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
360 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
361 export CC CFLAGS LDFLAGS
362 OPT_AUTOCC
=0 ld_need_R_flags
=-R
364 cc_maxopt
=2 cc_force_no_stackprot
=1
369 # Check out compiler ($CC) and -flags ($CFLAGS)
371 # Even though it belongs into cc_flags we will try to compile and link
372 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
373 # EXTRA_CFLAGS/EXTRA_LDFLAGS
374 if feat_no AUTOCC
; then
376 # Ensure those don't do any harm
377 EXTRA_CFLAGS
= EXTRA_LDFLAGS
=
378 export EXTRA_CFLAGS EXTRA_LDFLAGS
382 export CFLAGS LDFLAGS
385 [ -n "${CC}" ] && { _cc_default
; return; }
387 msg_nonl
'Searching for a usable C compiler .. $CC='
388 if acmd_set CC clang || acmd_set CC gcc ||
389 acmd_set CC tcc || acmd_set CC pcc ||
390 acmd_set CC c89 || acmd_set CC c99
; then
393 msg
'boing booom tschak'
394 msg
'ERROR: I cannot find a compiler!'
395 msg
' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
396 msg
' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
404 if [ -z "${CC}" ]; then
405 msg
'To go on like you have chosen, please set $CC, rerun.'
409 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG
; then
412 msg
'Using C compiler ${CC}=%s' "${CC}"
417 if feat_yes AUTOCC
; then
418 if [ -f ${lst} ] && feat_no DEBUG
&& [ -z "${VERBOSE}" ]; then
420 msg
'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
424 msg
'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
427 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
428 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
429 msg ' . have special tcc(1) environmental rules ...'
432 # As of pcc CVS 2016-04-02, stack protection support is announced but
433 # will break if used on Linux
434 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
435 cc_force_no_stackprot=1
440 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
441 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
442 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
444 if feat_no DEBUG; then
445 CFLAGS="-DNDEBUG ${CFLAGS}"
449 export CFLAGS LDFLAGS
453 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
460 if feat_yes DEBUG; then
461 # May have problems to find libtcc cc_check -b
465 if ld_check -Wl,-rpath =./ no; then
466 ld_need_R_flags=-Wl,-rpath=
467 if [ -z "${ld_rpath_not_runpath}" ]; then
468 ld_check -Wl,--enable-new-dtags
470 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
472 ld_runtime_flags # update!
475 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
476 unset __cflags __ldflags
479 _cc_flags_generic() {
480 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
482 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
484 # E.g., valgrind does not work well with high optimization
485 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
486 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
487 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
490 # Check -g first since some others may rely upon -g / optim. level
491 if feat_yes DEBUG; then
494 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
496 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
498 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
504 if feat_yes AMALGAMATION; then
508 #if feat_yes DEVEL && cc_check -Weverything; then
513 cc_check -Wbad-function-cast
514 cc_check -Wcast-align
517 cc_check -Wmissing-prototypes
520 cc_check -Wwrite-strings
521 cc_check -Wno-long-long
525 if feat_yes AMALGAMATION && feat_no DEVEL; then
526 cc_check -Wno-unused-function
528 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
530 cc_check -fno-unwind-tables
531 cc_check -fno-asynchronous-unwind-tables
532 cc_check -fstrict-aliasing
533 if cc_check -fstrict-overflow && feat_yes DEVEL; then
534 cc_check -Wstrict-overflow=5
537 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
538 if [ -z "${cc_force_no_stackprot}" ]; then
539 if cc_check -fstack-protector-strong ||
540 cc_check -fstack-protector-all; then
541 cc_check -D_FORTIFY_SOURCE=2
544 msg ' ! Not checking for -fstack-protector compiler option,'
545 msg ' ! since that caused errors in a "similar" configuration.'
546 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
550 # LD (+ dependend CC)
552 if feat_yes ASAN_ADDRESS; then
554 if cc_check -fsanitize=address &&
555 ld_check -fsanitize=address; then
558 feat_bail_required ASAN_ADDRESS
563 if feat_yes ASAN_MEMORY; then
565 if cc_check -fsanitize=memory &&
566 ld_check -fsanitize=memory &&
567 cc_check -fsanitize-memory-track-origins=2 &&
568 ld_check -fsanitize-memory-track-origins=2; then
571 feat_bail_required ASAN_MEMORY
576 ld_check -Wl,-z,relro
577 if [ -z "${ld_no_bind_now}" ]; then
580 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
582 ld_check -Wl,-z,noexecstack
583 if ld_check -Wl,-rpath =./ no; then
584 ld_need_R_flags=-Wl,-rpath=
585 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
586 if [ -z "${ld_rpath_not_runpath}" ]; then
587 ld_check -Wl,--enable-new-dtags
589 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
591 ld_runtime_flags # update!
592 elif ld_check -Wl,-R ./ no; then
593 ld_need_R_flags=-Wl,-R
594 if [ -z "${ld_rpath_not_runpath}" ]; then
595 ld_check -Wl,--enable-new-dtags
597 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
599 ld_runtime_flags # update!
602 # Address randomization
604 if cc_check -fPIE || cc_check -fpie; then
605 ld_check -pie || _CFLAGS=${_ccfg}
609 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
610 unset __cflags __ldflags
613 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
616 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
617 ## redirection, so use "printf '' >" instead
619 ## Very first: we undergo several states regarding I/O redirection etc.,
620 ## but need to deal with option updates from within all. Since all the
621 ## option stuff should be above the scissor line, define utility functions
622 ## and redefine them as necessary.
623 ## And, since we have those functions, simply use them for whatever
625 t1=ten10one1ten10one1
626 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
627 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
628 ) > /dev/null 2>&1; then
635 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
641 # which(1) not standardized, command(1) -v may return non-executable: unroll!
642 acmd_test() { __acmd "${1}" 1 0 0; }
643 acmd_test_fail() { __acmd "${1}" 1 1 0; }
644 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
645 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
646 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
647 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
648 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
649 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
650 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
651 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
653 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
655 if [ "${dotest}" -ne 0 ]; then
656 eval dotest=\$${varname}
657 if [ -n "${dotest}" ]; then
658 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
659 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
665 [ -n "${noglob_shell}" ] && set -o noglob
667 [ -n "${noglob_shell}" ] && set +o noglob
671 if [ -z "${path}" ] || [ "${path}" = . ]; then
672 if [ -d "${PWD}" ]; then
678 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
679 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
680 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
681 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
686 # We may have no builtin string functions, we yet have no programs we can
687 # use, try to access once from the root, assuming it is an absolute path if
688 # that finds the executable
689 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
690 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
691 msg ' . ${%s} ... %s' "${pname}" "${pname}"
692 [ -n "${varname}" ] && eval ${varname}="${pname}"
696 [ ${dofail} -eq 0 ] && return 1
697 msg 'ERROR: no trace of utility '"${pname}"
704 printf >&2 -- "${fmt}\\n" "${@}"
710 printf >&2 -- "${fmt}" "${@}"
713 # Our feature check environment
715 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
716 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
720 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
721 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
722 [ "x${1}" = xrequire ]
726 [ "x${1}" = xrequire ]
731 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
732 if feat_val_no "${i}"; then
734 elif feat_val_yes "${i}"; then
737 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
748 _feat_check ${1} && return 1
754 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
755 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
758 feat_bail_required() {
759 if feat_require ${1}; then
760 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
764 option_update # XXX this is rather useless here (dependency chain..)
768 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
769 # options, without documentation, to $1
771 i="`${awk} -v input
=\"${2}\" '
774 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
777 v = substr(input, voff, RLENGTH)
778 input = substr(input, voff + RLENGTH)
781 d = substr(v, doff + 2, length(v) - doff - 1)
782 v = substr(v, 1, doff - 1)
792 # Return the "documentation string" for option $1, itself if none such
794 ${awk} -v want="${1}" \
795 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
798 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
801 v = substr(input, voff, RLENGTH)
802 input = substr(input, voff + RLENGTH)
805 d = substr(v, doff + 2, length(v) - doff - 1)
806 v = substr(v, 1, doff - 1)
820 # Join the values from make.rc into what currently is defined, not
821 # overwriting yet existing settings
823 # We want read(1) to perform reverse solidus escaping in order to be able to
824 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
825 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
826 < ${rc} ${awk} 'BEGIN{line = ""}{
827 gsub(/^[[:space:]]+/, "", $0)
828 gsub(/[[:space:]]+$/, "", $0)
829 if(gsub(/\\$/, "", $0)){
834 if(index(line, "#") == 1){
836 }else if(length(line)){
842 if [ -n "${good_shell}" ]; then
845 i=`${awk} -v LINE
="${line}" 'BEGIN{
846 gsub(/=.*$/, "", LINE)
850 if [ "${i}" = "${line}" ]; then
851 msg 'ERROR: invalid syntax in: %s' "${line}"
855 eval j="\$${i}" jx="\${${i}+x}"
856 if [ -n "${j}" ] || [ "${jx}" = x ]; then
859 j=`${awk} -v LINE
="${line}" 'BEGIN{
860 gsub(/^[^=]*=/, "", LINE)
861 gsub(/^\"*/, "", LINE)
862 gsub(/\"*$/, "", LINE)
866 [ "${i}" = "DESTDIR" ] && continue
869 # Reread the mixed version right now
874 # Expand the option values, which may contain shell snippets
875 ${rm} -f ${newlst} ${newmk} ${newh}
876 exec 5<&0 6>&1 <${tmp} >${newlst}
879 if [ -n "${good_shell}" ]; then
881 [ "${i}" != "${i#OPT_}" ] && z=1
883 i=`${awk} -v LINE
="${line}" 'BEGIN{
884 gsub(/=.*$/, "", LINE);\
887 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
893 if [ -n "${z}" ]; then
894 j="`echo ${j} |
${tr} '[A-Z]' '[a-z]'`"
895 if [ -z "${j}" ] || feat_val_no "${j}"; then
897 printf " /* #undef ${i} */\n" >> ${newh}
898 elif feat_val_yes "${j}"; then
899 if feat_val_require "${j}"; then
904 printf " /* #define ${i} */\n" >> ${newh}
906 msg 'ERROR: cannot parse <%s>' "${line}"
910 printf "#define ${i} \"${j}\"\n" >> ${newh}
912 printf "${i} = ${j}\n" >> ${newmk}
916 exec 0<&5 1>&6 5<&- 6<&-
920 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
921 varname=${1} addflag=${2} flagvarname=${3}
924 [ -n "${noglob_shell}" ] && set -o noglob
926 [ -n "${noglob_shell}" ] && set +o noglob
931 [ -z "${i}" ] && continue
932 [ -d "${i}" ] || continue
933 if [ -n "${j}" ]; then
934 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
939 # But do not link any fakeroot path into our binaries!
940 if [ -n "${addflag}" ]; then
941 case "${i}" in *fakeroot*) continue;; esac
942 k="${k} ${addflag}${i}"
948 # But do not link any fakeroot path into our binaries!
949 if [ -n "${addflag}" ]; then
950 case "${i}" in *fakeroot*) continue;; esac
951 k="${k} ${addflag}${i}"
955 eval "${varname}=\"${j}\""
956 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
961 if [ -n "${ld_need_R_flags}" ]; then
964 set -- ${LD_LIBRARY_PATH}
968 # But do not link any fakeroot path into our binaries!
969 case "${i}" in *fakeroot*) continue;; esac
970 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
971 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
975 # Disable it for a possible second run.
980 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
982 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
983 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
984 _CFLAGS="${_CFLAGS} ${1}"
985 [ -n "${cc_check_silent}" ] || msg 'yes'
988 [ -n "${cc_check_silent}" ] || msg 'no'
993 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
994 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
995 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
996 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
997 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
998 [ -n "${cc_check_silent}" ] || msg 'yes'
1001 [ -n "${cc_check_silent}" ] || msg 'no'
1007 variable=$1 topic=$2 define=$3
1010 msg_nonl ' . %s ... ' "${topic}"
1011 echo "/* checked ${topic} */" >> ${h}
1012 ${rm} -f ${tmp} ${tmp}.o
1013 if [ "${dump_test_program}" = 1 ]; then
1014 echo '*** test program is'
1015 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1017 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1019 #echo '*** the preprocessor generates'
1020 #${make} -f ${makefile} ${tmp}.x
1022 echo '*** tests results'
1026 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1029 msg_nonl ' . %s ... ' "${topic}"
1031 echo '*** enforced unchecked results are'
1032 if feat_val_yes ${yesno}; then
1033 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1034 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1035 LIBS="${LIBS} ${libs}"
1036 echo "${libs}" >> ${lib}
1037 INCS="${INCS} ${incs}"
1038 echo "${incs}" >> ${inc}
1041 echo "${define}" >> ${h}
1042 eval have_${variable}=yes
1045 echo "/* ${define} */" >> ${h}
1047 eval unset have_${variable}
1053 variable=$1 topic=$2 define=$3
1055 _check_preface "${variable}" "${topic}" "${define}"
1057 if ${make} -f ${makefile} XINCS="${INCS}" \
1058 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1060 [ -f ./${tmp}.o ]; then
1062 echo "${define}" >> ${h}
1063 eval have_${variable}=yes
1066 echo "/* ${define} */" >> ${h}
1068 eval unset have_${variable}
1074 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1076 _check_preface "${variable}" "${topic}" "${define}"
1078 if feat_yes CROSS_BUILD; then
1079 if [ ${run} = 1 ]; then
1084 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1085 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1086 XLIBS="${LIBS} ${libs}" \
1089 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1090 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1092 echo "${define}" >> ${h}
1093 LIBS="${LIBS} ${libs}"
1094 echo "${libs}" >> ${lib}
1095 INCS="${INCS} ${incs}"
1096 echo "${incs}" >> ${inc}
1097 eval have_${variable}=yes
1101 echo "/* ${define} */" >> ${h}
1102 eval unset have_${variable}
1108 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1112 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1116 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1120 if feat_yes ${1}; then
1121 echo '#define HAVE_'${1}'' >> ${h}
1124 echo '/* OPT_'${1}'=0 */' >> ${h}
1130 < "${1}" > "${2}" ${awk} \
1131 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1134 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1136 # First of all, create new configuration and check whether it changed
1138 # Very easy checks for the operating system in order to be able to adjust paths
1139 # or similar very basic things which we need to be able to go at all
1140 thecmd_testandset_fail uname uname
1143 # Check those tools right now that we need before including $rc
1144 msg 'Checking for basic utility set'
1145 thecmd_testandset_fail awk awk
1146 thecmd_testandset_fail rm rm
1147 thecmd_testandset_fail tr tr
1149 # Initialize the option set
1150 msg_nonl 'Setting up configuration options ... '
1154 # Include $rc, but only take from it what wasn't overwritten by the user from
1155 # within the command line or from a chosen fixed CONFIG=
1156 # Note we leave alone the values
1157 trap "exit 1" HUP INT TERM
1158 trap "${rm} -f ${tmp}" EXIT
1160 msg_nonl 'Joining in %s ... ' ${rc}
1164 # We need to know about that now, in order to provide utility overwrites etc.
1167 msg 'Checking for remaining set of utilities'
1168 thecmd_testandset_fail grep grep
1170 # Before we step ahead with the other utilities perform a path cleanup first.
1174 thecmd_testandset_fail basename basename
1175 thecmd_testandset_fail cat cat
1176 thecmd_testandset_fail chmod chmod
1177 thecmd_testandset_fail cp cp
1178 thecmd_testandset_fail cmp cmp
1180 thecmd_testandset_fail mkdir mkdir
1181 thecmd_testandset_fail mv mv
1183 thecmd_testandset_fail sed sed
1184 thecmd_testandset_fail sort sort
1185 thecmd_testandset_fail tee tee
1187 thecmd_testandset chown chown ||
1188 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1189 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1191 thecmd_testandset_fail MAKE make
1194 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1196 # For ./cc-test.sh only
1197 thecmd_testandset_fail cksum cksum
1199 # Update OPT_ options now, in order to get possible inter-dependencies right
1202 # (No functions since some shells loose non-exported variables in traps)
1203 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1204 trap "trap \"\" HUP INT TERM EXIT;\
1205 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1207 # Our configuration options may at this point still contain shell snippets,
1208 # we need to evaluate them in order to get them expanded, and we need those
1209 # evaluated values not only in our new configuration file, but also at hand..
1210 msg_nonl 'Evaluating all configuration items ... '
1214 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1215 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1217 # The problem now is that the test should be able to run in the users linker
1218 # and path environment, so we need to place the test: rule first, before
1219 # injecting the relevant make variables. Set up necessary environment
1220 if [ -z "${VERBOSE}" ]; then
1221 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1222 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1223 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1224 printf -- "ECHO_TEST = @\n" >> ${newmk}
1225 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1226 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1227 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1229 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1230 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1232 # Add the known utility and some other variables
1233 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1234 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1235 if feat_yes DOTLOCK; then
1236 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1238 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1243 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1244 MAKE MAKEFLAGS make SHELL strip \
1247 printf "${i} = ${j}\n" >> ${newmk}
1248 printf "${i}=${j}\n" >> ${newlst}
1249 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1251 # Note that makefile reads and eval'uates one line of this file, whereas other
1252 # consumers source it via .(1)
1253 printf "\n" >> ${newev}
1255 # Build a basic set of INCS and LIBS according to user environment.
1256 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1257 path_check C_INCLUDE_PATH -I _INCS
1258 INCS="${INCS} ${_INCS}"
1259 path_check LD_LIBRARY_PATH -L _LIBS
1260 LIBS="${LIBS} ${_LIBS}"
1262 export C_INCLUDE_PATH LD_LIBRARY_PATH
1264 # Some environments need runtime path flags to be able to go at all
1267 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1271 ${cat} > ${tmp}.c << \!
1274 static void doit(char const *s);
1276 main(int argc, char **argv){
1279 doit("Hello world");
1283 doit(char const *s){
1285 memcpy(buf, s, strlen(s) +1);
1290 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1291 -o ${tmp2} ${tmp}.c ${LIBS}; then
1294 msg 'ERROR: i cannot compile a "Hello world" via'
1296 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1297 msg 'ERROR: Please read INSTALL, rerun'
1301 # This may also update ld_runtime_flags() (again)
1308 printf -- "${i}=${j}\n" >> ${newlst}
1314 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1318 if [ -n "${j}" ]; then
1319 printf -- "${i} = ${j}\n" >> ${newmk}
1320 printf -- "${i}=${j}\n" >> ${newlst}
1324 # Now finally check whether we already have a configuration and if so, whether
1325 # all those parameters are still the same.. or something has actually changed
1326 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1327 echo 'Configuration is up-to-date'
1329 elif [ -f ${lst} ]; then
1330 echo 'Configuration has been updated..'
1331 ( eval "${MAKE} -f ./mk-config.mk clean" )
1334 echo 'Shiny configuration..'
1337 # Time to redefine helper 1
1339 ${rm} -f ${lst} ${h} ${mk}
1343 ${mv} -f ${newlst} ${lst}
1344 ${mv} -f ${newev} ${ev}
1345 ${mv} -f ${newh} ${h}
1346 ${mv} -f ${newmk} ${mk}
1348 ## Compile and link checking
1354 makefile=./${tmp0}.mk
1356 # (No function since some shells loose non-exported variables in traps)
1357 trap "trap \"\" HUP INT TERM;\
1358 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1359 trap "trap \"\" HUP INT TERM EXIT;\
1360 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1362 # Time to redefine helper 2
1366 printf "*** ${fmt}\\n" "${@}"
1367 printf -- "${fmt}\\n" "${@}" >&5
1372 printf "*** ${fmt}\\n" "${@}"
1373 printf -- "${fmt}" "${@}" >&5
1377 exec 5>&2 > ${log} 2>&1
1379 echo "${LIBS}" > ${lib}
1380 echo "${INCS}" > ${inc}
1381 ${cat} > ${makefile} << \!
1382 .SUFFIXES: .o .c .x .y
1384 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1386 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1388 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1393 # May be multiline..
1395 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1396 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1397 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1399 # Generate n_err_number OS mappings
1402 feat_yes DEVEL && NV= || NV=noverbose
1403 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1404 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1405 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1408 feat_def ALWAYS_UNICODE_LOCALE
1409 feat_def AMALGAMATION
1410 feat_def CROSS_BUILD
1414 feat_def ASAN_ADDRESS
1415 feat_def ASAN_MEMORY
1421 if xrun_check inline 'inline functions' \
1422 '#define HAVE_INLINE
1423 #define n_INLINE static inline' << \!
1424 static inline int ilf(int i){return ++i;}
1425 int main(void){return ilf(-1);}
1429 elif xrun_check inline 'inline functions (via __inline)' \
1430 '#define HAVE_INLINE
1431 #define n_INLINE static __inline' << \!
1432 static __inline int ilf(int i){return ++i;}
1433 int main(void){return ilf(-1);}
1439 ## Test for "basic" system-calls / functionality that is used by all parts
1440 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1441 ## macros to be used by only the subprograms (potentially).
1443 if run_check clock_gettime 'clock_gettime(2)' \
1444 '#define HAVE_CLOCK_GETTIME' << \!
1450 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1457 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1458 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1464 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1471 elif run_check gettimeofday 'gettimeofday(2)' \
1472 '#define HAVE_GETTIMEOFDAY' << \!
1473 #include <stdio.h> /* For C89 NULL */
1474 #include <sys/time.h>
1479 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1487 have_no_subsecond_time=1
1490 if run_check nanosleep 'nanosleep(2)' \
1491 '#define HAVE_NANOSLEEP' << \!
1498 ts.tv_nsec = 100000;
1499 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1506 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1507 '#define HAVE_NANOSLEEP' '-lrt' << \!
1514 ts.tv_nsec = 100000;
1515 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1522 # link_check is enough for this, that function is so old, trust the proto
1523 elif link_check sleep 'sleep(3)' \
1524 '#define HAVE_SLEEP' << \!
1528 if(!sleep(1) || errno != ENOSYS)
1536 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1540 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1549 if((gid = getgid()) != 0)
1551 if((uid = getuid()) != 0)
1553 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1555 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1563 msg 'ERROR: we require user and group info / database searches.'
1564 msg 'That much Unix we indulge ourselfs.'
1568 if link_check ftruncate 'ftruncate(2)' \
1569 '#define HAVE_FTRUNCATE' << \!
1571 #include <sys/types.h>
1573 return (ftruncate(0, 0) != 0);
1579 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1580 msg 'ERROR: we require the ftruncate(2) system call.'
1584 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1588 struct sigaction nact, oact;
1590 nact.sa_handler = SIG_DFL;
1591 sigemptyset(&nact.sa_mask);
1592 nact.sa_flags = SA_RESTART;
1593 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1599 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1603 if link_check snprintf 'snprintf(3)' << \!
1608 snprintf(b, sizeof b, "%s", "string");
1615 msg 'ERROR: we require the snprintf(3) function.'
1619 if link_check environ 'environ(3)' << \!
1620 #include <stdio.h> /* For C89 NULL */
1622 extern char **environ;
1624 return environ[0] == NULL;
1630 msg 'ERROR: we require the environ(3) array for subprocess control.'
1634 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1637 setenv("s-mailx", "i want to see it cute!", 1);
1638 unsetenv("s-mailx");
1644 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1647 putenv("s-mailx=i want to see it cute!");
1654 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1658 if link_check termios 'termios.h and tc*(3) family' << \!
1659 #include <termios.h>
1661 struct termios tios;
1663 tcgetattr(0, &tios);
1664 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1671 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1672 msg 'That much Unix we indulge ourselfs.'
1678 if link_check vsnprintf 'vsnprintf(3)' << \!
1681 static void dome(char *buf, size_t blen, ...){
1685 vsnprintf(buf, blen, "%s", ap);
1691 dome(b, sizeof b, "string");
1698 feat_bail_required ERRORS
1701 if [ "${have_vsnprintf}" = yes ]; then
1703 link_check va_copy "va_copy(3) (as ${2})" \
1704 "#define HAVE_N_VA_COPY
1705 #define n_va_copy ${2}" <<_EOT
1709 # if defined __va_copy && !defined va_copy
1710 # define va_copy __va_copy
1713 static void dome2(char *buf, size_t blen, va_list src){
1717 vsnprintf(buf, blen, "%s", ap);
1720 static void dome(char *buf, size_t blen, ...){
1724 dome2(buf, blen, ap);
1730 dome(b, sizeof b, "string");
1735 __va_copy 0 va_copy || __va_copy 1 __va_copy
1738 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1745 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1747 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1749 /* Only link check */
1750 fpathconf(0, _PC_NAME_MAX);
1756 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1763 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1769 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1770 #include <termios.h>
1774 tcgetwinsize(0, &ws);
1779 # We use this only then for now (need NOW+1)
1780 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1781 #include <fcntl.h> /* For AT_* */
1782 #include <sys/stat.h>
1785 struct timespec ts[2];
1787 ts[0].tv_nsec = UTIME_NOW;
1788 ts[1].tv_nsec = UTIME_OMIT;
1789 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1797 # The random check has been moved to below SSL detection due to OPT_SSL_RANDOM
1799 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1802 putc_unlocked('@', stdout);
1807 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1815 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1818 char x_buf[4096], *x = realpath(".", x_buf);
1820 return (x != NULL) ? 0 : 1;
1824 if run_check realpath_malloc 'realpath(3) takes NULL' \
1825 '#define HAVE_REALPATH_NULL' << \!
1828 char *x = realpath(".", NULL);
1832 return (x != NULL) ? 0 : 1;
1840 ## optional and selectable
1842 if feat_yes DOTLOCK; then
1843 if run_check readlink 'readlink(2)' << \!
1849 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1857 feat_bail_required DOTLOCK
1861 if feat_yes DOTLOCK; then
1862 if run_check fchown 'fchown(2)' << \!
1866 if(!fchown(0, 0, 0) || errno != ENOSYS)
1874 feat_bail_required DOTLOCK
1878 if feat_yes DOTLOCK; then
1879 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1880 '#define HAVE_PRCTL_DUMPABLE' << \!
1881 #include <sys/prctl.h>
1884 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1891 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1892 '#define HAVE_PTRACE_DENY' << \!
1893 #include <sys/ptrace.h>
1896 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1903 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1904 '#define HAVE_SETPFLAGS_PROTECT' << \!
1908 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1918 ## Now it is the time to fork away the BASE_ series
1921 squeeze_em ${inc} ${tmp}
1923 squeeze_em ${lib} ${tmp}
1926 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1927 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1929 ## The remains are expected to be used only by the main MUA binary!
1932 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1935 setlocale(LC_ALL, "");
1939 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1941 OPT_MULTIBYTE_CHARSETS=0
1943 OPT_TERMINAL_CHARSET=0
1944 if [ -n "${have_setlocale}" ]; then
1945 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1946 '#define HAVE_C90AMEND1' << \!
1952 char mbb[MB_LEN_MAX + 1];
1957 mbtowc(&wc, "x
", 1);
1958 mbrtowc(&wc, "x
", 1, NULL);
1960 return (mblen("\
0", 1) == 0);
1963 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1965 if [ -n "${have_c90amend1}" ]; then
1966 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1973 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1976 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1977 #include <langinfo.h>
1981 return (nl_langinfo(CODESET) == NULL);
1984 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1987 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1988 #include <fnmatch.h>
1990 return (fnmatch("*", ".
", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1994 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1998 return !(de.d_type == DT_UNKNOWN ||
1999 de.d_type == DT_DIR || de.d_type == DT_LNK);
2003 ## optional and selectable
2005 if feat_yes ICONV; then
2006 # To be able to create tests we need to figure out which replacement
2007 # sequence the iconv(3) implementation creates
2008 ${cat} > ${tmp2}.c << \!
2009 #include <stdio.h> /* For C89 NULL */
2013 char inb[16], oub[16], *inbp, *oubp;
2017 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2018 inl = sizeof("\342\200\223") -1;
2022 if((id = iconv_open("ascii
", "utf-8
")) == (iconv_t)-1)
2024 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2029 oul = (size_t)(oubp - oub);
2032 /* Character-wise replacement? */
2040 /* Byte-wise replacement? */
2041 if(oul == sizeof("\342\200\223") -1){
2042 if(!memcmp(oub, "???????
", sizeof("\342\200\223") -1))
2044 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2051 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2052 '#define HAVE_ICONV' ||
2053 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2054 '#define HAVE_ICONV' '-liconv' ||
2055 feat_bail_required ICONV
2057 if feat_no CROSS_BUILD; then
2058 { ./${tmp}; } >/dev/null 2>&1
2060 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2061 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2062 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2063 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2064 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2068 echo '/* OPT_ICONV=0 */' >> ${h}
2071 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2072 ${cat} > ${tmp2}.c << \!
2073 #include <sys/types.h>
2074 #include <sys/socket.h>
2078 struct sockaddr_un soun;
2080 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2082 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2084 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2090 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2091 '#define HAVE_UNIX_SOCKETS' ||
2092 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2093 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2094 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2095 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2098 if feat_yes SOCKETS; then
2099 ${cat} > ${tmp2}.c << \!
2100 #include <sys/types.h>
2101 #include <sys/socket.h>
2102 #include <netinet/in.h>
2107 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2109 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2115 < ${tmp2}.c run_check sockets 'sockets' \
2116 '#define HAVE_SOCKETS' ||
2117 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2118 '#define HAVE_SOCKETS' '-lnsl' ||
2119 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2120 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2121 feat_bail_required SOCKETS
2123 echo '/* OPT_SOCKETS=0 */' >> ${h}
2124 fi # feat_yes SOCKETS
2126 if feat_yes SOCKETS; then
2127 link_check getaddrinfo 'getaddrinfo(3)' \
2128 '#define HAVE_GETADDRINFO' << \!
2129 #include <sys/types.h>
2130 #include <sys/socket.h>
2134 struct addrinfo a, *ap;
2137 switch((lrv = getaddrinfo("foo
", "0", &a, &ap))){
2141 fprintf(stderr, "%s
\n", gai_strerror(lrv));
2150 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2151 compile_check arpa_inet_h '<arpa/inet.h>' \
2152 '#define HAVE_ARPA_INET_H' << \!
2153 #include <sys/types.h>
2154 #include <sys/socket.h>
2156 #include <netinet/in.h>
2157 #include <arpa/inet.h>
2160 ${cat} > ${tmp2}.c << \!
2161 #include <sys/types.h>
2162 #include <sys/socket.h>
2166 #include <netinet/in.h>
2167 #ifdef HAVE_ARPA_INET_H
2168 #include <arpa/inet.h>
2171 struct sockaddr_in servaddr;
2172 unsigned short portno;
2175 struct in_addr **pptr;
2178 if((ep = getservbyname("POPPY-PORT
", "tcp
")) != NULL)
2179 portno = (unsigned short)ep->s_port;
2181 if((hp = gethostbyname("POPPY-HOST
")) != NULL){
2182 pptr = (struct in_addr**)hp->h_addr_list;
2183 if(hp->h_addrtype != AF_INET)
2184 fprintf(stderr, "au
\n");
2187 case HOST_NOT_FOUND:
2193 fprintf(stderr, "au
\n");
2198 memset(&servaddr, 0, sizeof servaddr);
2199 servaddr.sin_family = AF_INET;
2200 servaddr.sin_port = htons(portno);
2201 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2202 fprintf(stderr, "Would connect to
%s
:%d ...
\n",
2203 inet_ntoa(**pptr), (int)portno);
2208 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2209 < ${tmp2}.c link_check gethostbyname \
2210 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2211 < ${tmp2}.c link_check gethostbyname \
2212 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2213 '' '-lsocket -lnsl' ||
2214 feat_bail_required SOCKETS
2218 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2219 #include <sys/socket.h>
2225 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2232 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2233 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2234 #include <sys/socket.h>
2242 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2243 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2248 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2249 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2250 #include <sys/socket.h>
2258 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2264 if feat_yes SSL; then # {{{
2265 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2266 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2267 # time: we need to test it first in order to get things right
2268 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2271 #define HAVE_XSSL_RESSL
2272 #define HAVE_XSSL_OPENSSL 0' << \!
2273 #include <openssl/opensslv.h>
2274 #ifdef LIBRESSL_VERSION_NUMBER
2281 VAL_SSL_FEATURES=libressl
2282 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2283 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2286 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2287 #include <openssl/opensslv.h>
2288 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2295 VAL_SSL_FEATURES=libssl-0x10100
2296 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2299 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2300 #include <openssl/opensslv.h>
2301 #ifdef OPENSSL_VERSION_NUMBER
2308 VAL_SSL_FEATURES=libssl-0x10000
2310 feat_bail_required SSL
2313 if feat_yes SSL; then # {{{
2314 if [ -n "${ossl_v1_1}" ]; then
2315 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2316 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2318 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2319 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2320 '-lssl -lcrypto' << \!
2321 #include <openssl/ssl.h>
2322 #include <openssl/err.h>
2323 #include <openssl/x509v3.h>
2324 #include <openssl/x509.h>
2325 #include <openssl/rand.h>
2326 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2327 # error We need TLSv1.
2330 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2333 PEM_read_PrivateKey(0, 0, 0, 0);
2339 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2340 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2341 '-lssl -lcrypto' << \!
2342 #include <openssl/ssl.h>
2343 #include <openssl/err.h>
2344 #include <openssl/x509v3.h>
2345 #include <openssl/x509.h>
2346 #include <openssl/rand.h>
2347 #if defined OPENSSL_NO_SSL3 &&\
2348 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2349 # error We need one of SSLv3 and TLSv1.
2352 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2355 PEM_read_PrivateKey(0, 0, 0, 0);
2362 feat_bail_required SSL
2366 if feat_yes SSL; then # {{{
2367 if feat_yes SSL_ALL_ALGORITHMS; then
2368 if [ -n "${ossl_v1_1}" ]; then
2369 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2370 '#define HAVE_SSL_ALL_ALGORITHMS'
2371 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2372 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2373 #include <openssl/evp.h>
2375 OpenSSL_add_all_algorithms();
2376 EVP_get_cipherbyname("two cents i never exist
");
2384 feat_bail_required SSL_ALL_ALGORITHMS
2386 elif [ -n "${ossl_v1_1}" ]; then
2387 without_check yes ssl_all_algo \
2388 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2389 '#define HAVE_SSL_ALL_ALGORITHMS'
2392 if [ -n "${ossl_v1_1}" ]; then
2393 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2394 '#define HAVE_XSSL_STACK_OF'
2395 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2396 '#define HAVE_XSSL_STACK_OF' << \!
2397 #include <stdio.h> /* For C89 NULL */
2398 #include <openssl/ssl.h>
2399 #include <openssl/err.h>
2400 #include <openssl/x509v3.h>
2401 #include <openssl/x509.h>
2402 #include <openssl/rand.h>
2404 STACK_OF(GENERAL_NAME) *gens = NULL;
2406 printf("%p
", gens); /* to use it */
2414 if [ -n "${ossl_v1_1}" ]; then
2415 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2416 '#define HAVE_XSSL_CONFIG'
2417 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2418 elif link_check xssl_conf \
2419 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2420 '#define HAVE_XSSL_CONFIG' << \!
2421 #include <stdio.h> /* For C89 NULL */
2422 #include <openssl/conf.h>
2424 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2425 CONF_modules_free();
2430 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2432 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2435 if [ -n "${ossl_v1_1}" ]; then
2436 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2437 '#define HAVE_XSSL_CONF_CTX'
2438 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2439 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2440 '#define HAVE_XSSL_CONF_CTX' << \!
2441 #include <openssl/ssl.h>
2442 #include <openssl/err.h>
2444 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2445 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2447 SSL_CONF_CTX_set_flags(cctx,
2448 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2449 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2450 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2451 SSL_CONF_cmd(cctx, "Protocol
", "ALL
");
2452 SSL_CONF_CTX_finish(cctx);
2453 SSL_CONF_CTX_free(cctx);
2459 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2461 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2464 if [ -n "${ossl_v1_1}" ]; then
2465 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2466 '#define HAVE_XSSL_CTX_CONFIG'
2467 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2468 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2469 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2470 '#define HAVE_XSSL_CTX_CONFIG' << \!
2471 #include <stdio.h> /* For C89 NULL */
2472 #include <openssl/ssl.h>
2474 SSL_CTX_config(NULL, "SOMEVAL
");
2479 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2481 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2484 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2485 without_check yes xssl_set_maxmin_proto \
2486 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2487 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2488 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2489 elif link_check xssl_set_maxmin_proto \
2490 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2491 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2492 #include <stdio.h> /* For C89 NULL */
2493 #include <openssl/ssl.h>
2495 SSL_CTX_set_min_proto_version(NULL, 0);
2496 SSL_CTX_set_max_proto_version(NULL, 10);
2501 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2503 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2506 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2507 '#define HAVE_XSSL_RAND_EGD' << \!
2508 #include <openssl/rand.h>
2510 return RAND_egd("some.where
") > 0;
2514 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd
"
2516 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2518 fi # feat_yes SSL }}}
2520 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2521 run_check ssl_md5 'MD5 digest in the used crypto library' \
2522 '#define HAVE_XSSL_MD5' << \!
2525 #include <openssl/md5.h>
2527 char const dat[] = "abrakadabrafidibus
";
2528 char dig[16], hex[16 * 2];
2532 memset(dig, 0, sizeof(dig));
2533 memset(hex, 0, sizeof(hex));
2535 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2536 MD5_Final(dig, &ctx);
2538 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2539 for(i = 0; i < sizeof(hex) / 2; i++){
2541 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2542 hex[++j] = hexchar(dig[i] & 0x0f);
2544 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326
", hex, sizeof(hex));
2549 if feat_yes SSL; then
2551 feat_def SSL_ALL_ALGORITHMS
2553 feat_bail_required SSL_RANDOM
2554 feat_bail_required SSL_ALL_ALGORITHMS
2555 echo '/* OPT_SSL=0 */' >> ${h}
2556 fi # }}} feat_yes SSL
2557 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2559 if [ "${have_xssl}" = yes ]; then
2566 # Native random check (had been delayed due to OPT_SSL_RAMDOM) {{{
2567 # XXX Add POSIX check once standardized
2568 if feat_yes NOEXTRANDOM
; then
2569 echo '#define HAVE_NOEXTRANDOM' >> ${h}
2570 elif feat_yes SSL_RANDOM
; then
2572 elif link_check arc4random
'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \
!
2581 elif link_check getrandom
'getrandom(2) (in sys/random.h)' \
2582 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
2583 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\
!
2584 #include <sys/random.h>
2587 getrandom
(buf
, sizeof buf
, 0);
2593 elif link_check getrandom
'getrandom(2) (via syscall(2))' \
2594 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
2595 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\
!
2596 #include <sys/syscall.h>
2599 syscall
(SYS_getrandom
, buf
, sizeof buf
, 0);
2605 elif [ -n "${have_no_subsecond_time}" ]; then
2606 msg
'ERROR: %s %s' 'without a native random' \
2607 'one of clock_gettime(2) and gettimeofday(2) is required.'
2615 if feat_yes GSSAPI
; then
2616 ${cat} > ${tmp2}.c
<< \
!
2617 #include <gssapi/gssapi.h>
2619 gss_import_name
(0, 0, GSS_C_NT_HOSTBASED_SERVICE
, 0);
2620 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2624 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2626 if acmd_set i krb5-config
; then
2627 GSS_LIBS
="`CFLAGS= ${i} --libs gssapi`"
2628 GSS_INCS
="`CFLAGS= ${i} --cflags`"
2629 i
='GSS-API via krb5-config(1)'
2633 i
='GSS-API in gssapi/gssapi.h, libgssapi'
2635 if < ${tmp2}.c link_check gss \
2636 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2637 < ${tmp3}.c link_check gss \
2638 'GSS-API in gssapi.h, libgssapi' \
2639 '#define HAVE_GSSAPI
2640 #define GSSAPI_REG_INCLUDE' \
2642 < ${tmp2}.c link_check gss
'GSS-API in libgssapi_krb5' \
2643 '#define HAVE_GSSAPI' \
2645 < ${tmp3}.c link_check gss \
2646 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2647 '#define HAVE_GSSAPI
2648 #define GSS_REG_INCLUDE' \
2649 '-lgssapi -lkrb5 -lcrypto' \
2650 '-I/usr/include/kerberosV' ||\
2651 < ${tmp2}.c link_check gss
'GSS-API in libgss' \
2652 '#define HAVE_GSSAPI' \
2654 link_check gss
'GSS-API in libgssapi_krb5, old-style' \
2655 '#define HAVE_GSSAPI
2656 #define GSSAPI_OLD_STYLE' \
2657 '-lgssapi_krb5' << \
!
2658 #include <gssapi/gssapi.h>
2659 #include <gssapi/gssapi_generic.h>
2661 gss_import_name
(0, 0, gss_nt_service_name
, 0);
2662 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2669 feat_bail_required GSSAPI
2672 echo '/* OPT_GSSAPI=0 */' >> ${h}
2673 fi # feat_yes GSSAPI
2678 if feat_yes IDNA
; then
2679 if link_check idna
'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2682 #include <idn-free.h>
2683 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2685 char
*utf8
, *idna_ascii
, *idna_utf8
;
2687 utf8
= stringprep_locale_to_utf8
("does.this.work");
2688 if (idna_to_ascii_8z
(utf8
, &idna_ascii
, IDNA_USE_STD3_ASCII_RULES
)
2691 idn_free
(idna_ascii
);
2692 /* (Rather link check only here
) */
2693 idna_utf8
= stringprep_convert
(idna_ascii
, "UTF-8", "de_DE");
2699 elif link_check idna
'Libidn2' '#define HAVE_IDNA HAVE_IDNA_LIBIDN2' \
2703 char
*idna_utf8
, *idna_lc
;
2705 if(idn2_to_ascii_8z
("does.this.work", &idna_utf8
,
2706 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL
) != IDN2_OK
)
2708 if(idn2_to_unicode_8zlz
(idna_utf8
, &idna_lc
, 0) != IDN2_OK
)
2711 idn2_free
(idna_utf8
);
2717 elif link_check idna
'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2720 #include <idn/api.h>
2721 #include <idn/result.h>
2725 char local_name
[256];
2727 r
= idn_encodename
(IDN_ENCODE_APP
, "does.this.work", ace_name
,
2729 if (r
!= idn_success
) {
2730 fprintf
(stderr
, "idn_encodename failed: %s\n", idn_result_tostring
(r
));
2733 r
= idn_decodename
(IDN_DECODE_APP
, ace_name
, local_name
, sizeof
(local_name
));
2734 if (r
!= idn_success
) {
2735 fprintf
(stderr
, "idn_decodename failed: %s\n", idn_result_tostring
(r
));
2744 feat_bail_required IDNA
2747 if [ -n "${have_idna}" ]; then
2748 echo '#define HAVE_IDNA_LIBIDN2 0' >> ${h}
2749 echo '#define HAVE_IDNA_LIBIDNA 1' >> ${h}
2750 echo '#define HAVE_IDNA_IDNKIT 2' >> ${h}
2753 echo '/* OPT_IDNA=0 */' >> ${h}
2756 feat_def IMAP_SEARCH
2758 if feat_yes REGEX
; then
2759 if link_check regex
'regular expressions' '#define HAVE_REGEX' << \
!
2767 status
= regcomp
(&re
, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB
);
2768 xret
= regerror
(status
, &re
, NULL
, 0);
2769 status
= regexec
(&re
, "plan9", 0,NULL
, 0);
2771 return !(status
== REG_NOMATCH
);
2777 feat_bail_required REGEX
2780 echo '/* OPT_REGEX=0 */' >> ${h}
2783 if feat_yes MLE
&& [ -n "${have_c90amend1}" ]; then
2785 echo '#define HAVE_MLE' >> ${h}
2787 feat_bail_required MLE
2788 echo '/* OPT_MLE=0 */' >> ${h}
2791 # Generic have-a-line-editor switch for those who need it below
2792 if [ -n "${have_mle}" ]; then
2796 if [ -n "${have_cle}" ] && feat_yes HISTORY
; then
2797 echo '#define HAVE_HISTORY' >> ${h}
2799 echo '/* OPT_HISTORY=0 */' >> ${h}
2802 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS
; then
2803 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2805 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2808 if feat_yes TERMCAP
; then
2810 link_check termcap
"termcap(5) (via ${4})" \
2811 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2816 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2817 static int my_putc(int c){return putchar(c);}
2819 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2820 int r2 = OK, r3 = ERR;
2822 tgetent(buf, getenv("TERM"));
2824 r1 = tgetstr(UNCONST("cm"), &cpb);
2826 r2 = tgetnum(UNCONST("Co"));
2827 r3 = tgetflag(UNCONST("ut"));
2828 tputs("cr", 1, &my_putc);
2829 return (r1 == NULL || r2 == -1 || r3 == 0);
2835 link_check terminfo
"terminfo(5) (via ${2})" \
2836 '#define HAVE_TERMCAP
2837 #define HAVE_TERMCAP_CURSES
2838 #define HAVE_TERMINFO' "${1}" << _EOT
2842 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2843 static int my_putc(int c){return putchar(c);}
2849 r0 = setupterm(NULL, 1, &er);
2850 r1 = tigetflag(UNCONST("bce"));
2851 r2 = tigetnum(UNCONST("colors"));
2852 r3 = tigetstr(UNCONST("cr"));
2853 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2854 tputs(tp, 1, &my_putc);
2855 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2856 r3 == (char*)-1 || r3 == NULL);
2861 if feat_yes TERMCAP_VIA_TERMINFO
; then
2862 __terminfolib
-ltinfo -ltinfo ||
2863 __terminfolib
-lcurses -lcurses ||
2864 __terminfolib
-lcursesw -lcursesw ||
2865 feat_bail_required TERMCAP_VIA_TERMINFO
2868 if [ -z "${have_terminfo}" ]; then
2869 __termcaplib
-ltermcap '' '' '-ltermcap' ||
2870 __termcaplib
-ltermcap '#include <curses.h>' '
2871 #define HAVE_TERMCAP_CURSES' \
2872 'curses.h / -ltermcap' ||
2873 __termcaplib
-lcurses '#include <curses.h>' '
2874 #define HAVE_TERMCAP_CURSES' \
2875 'curses.h / -lcurses' ||
2876 __termcaplib
-lcursesw '#include <curses.h>' '
2877 #define HAVE_TERMCAP_CURSES' \
2878 'curses.h / -lcursesw' ||
2879 feat_bail_required TERMCAP
2881 if [ -n "${have_termcap}" ]; then
2882 run_check tgetent_null \
2883 "tgetent(3) of termcap(5) takes NULL buffer" \
2884 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2885 #include <stdio.h> /* For C89 NULL */
2887 #ifdef HAVE_TERMCAP_CURSES
2888 # include <curses.h>
2892 tgetent(NULL, getenv("TERM"));
2899 echo '/* OPT_TERMCAP=0 */' >> ${h}
2900 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2903 if feat_def SPAM_SPAMC
; then
2904 if acmd_set i spamc
; then
2905 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2909 if feat_yes SPAM_SPAMD
&& [ -n "${have_af_unix}" ]; then
2910 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2912 feat_bail_required SPAM_SPAMD
2913 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2916 feat_def SPAM_FILTER
2918 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER
; then
2919 echo '#define HAVE_SPAM' >> ${h}
2921 echo '/* HAVE_SPAM */' >> ${h}
2924 if feat_yes QUOTE_FOLD
&&\
2925 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2926 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2928 feat_bail_required QUOTE_FOLD
2929 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2932 feat_def FILTER_HTML_TAGSOUP
2940 squeeze_em
${inc} ${tmp}
2942 squeeze_em
${lib} ${tmp}
2947 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2948 ${cat} ${tmp} >> ${h}
2952 # Create the string that is used by *features* and `version'.
2953 # Take this nice opportunity and generate a visual listing of included and
2954 # non-included features for the person who runs the configuration
2955 msg
'\nThe following features are included (+) or not (-):'
2956 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2957 printf '/* The "feature string" */\n' >> ${h}
2958 # Because + is expanded by *folder* if first in "echo $features", put something
2959 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2963 sdoc
=`option_doc_of ${opt}`
2964 [ -z "${sdoc}" ] && continue
2965 sopt
="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2966 feat_yes
${opt} && sign
=+ || sign
=-
2967 printf -- "${sep}${sign}${sopt}" >> ${h}
2969 msg " %s
%s
: %s
" ${sign} ${sopt} "${sdoc}"
2971 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2973 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2974 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2975 printf '"\n' >> ${h}
2977 # Create the real mk-config.mk
2978 # Note we cannout use explicit ./ filename prefix for source and object
2979 # pathnames because of a bug in bmake(1)
2980 ${rm} -rf ${tmp0}.* ${tmp0}*
2982 if feat_no AMALGAMATION
; then
2983 for i
in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2984 i
=`basename "${i}" .c`
2985 if [ "${i}" = privsep
]; then
2988 objlist
="${objlist} ${i}.o"
2989 srclist
="${srclist} \$(SRCDIR)${i}.c"
2990 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2991 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2993 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2995 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2996 "main.o
" "main.c
" >> ${mk}
2997 srclist=main.c objlist=main.o
2998 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3000 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3001 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3002 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3003 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3004 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3006 if [ "${i}" = main.c ] ||
3007 [ "${i}" = privsep.c ]; then
3010 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3011 printf '# include "%s
%s
"\n' "${SRCDIR}" "${i}" >> ${h}
3015 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3017 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3019 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3020 echo "INCS
= `${cat} ${inc}`" >> ${mk}
3022 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3027 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3028 msg ' . bindir: %s' "${VAL_BINDIR}"
3029 if feat_yes DOTLOCK; then
3030 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3032 msg ' . mandir: %s' "${VAL_MANDIR}"
3033 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3034 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3037 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3041 if [ -z "${have_fnmatch}" ]; then
3042 msg ' . The function fnmatch(3) could not be found.'
3043 msg ' Filename patterns like wildcard are not supported on your system'
3045 if [ -z "${have_fchdir}" ]; then
3046 msg ' . The function fchdir(2) could not be found.'
3047 msg ' We will use chdir(2) instead.'
3048 msg ' This is a problem only if the current working directory is changed'
3049 msg ' while this program is inside of it'