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 QUOTE_FOLD='Extended *quote-fold*ing' \
47 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
48 COLOUR='Coloured message display' \
49 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
52 # Options which are automatically deduced from host environment, i.e., these
53 # need special treatment all around here to warp from/to OPT_ stuff
54 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
56 LOCALES='Locale support - printable characters etc. depend on environment' \
57 MULTIBYTE_CHARSETS='Multibyte character sets' \
58 TERMINAL_CHARSET='Automatic detection of terminal character set' \
59 WIDE_GLYPHS='Wide glyph support' \
62 # Rather special options, for custom building, or which always exist.
63 # Mostly for generating the visual overview and the *features* string
65 MIME='Multipurpose Internet Mail Extensions' \
66 SMIME='S/MIME message signing, verification, en- and decryption' \
67 CROSS_BUILD='Cross-compilation: trust any detected environment' \
68 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
69 DEVEL='Computers do not blunder' \
72 # The problem is that we don't have any tools we can use right now, so
73 # encapsulate stuff in functions which get called in right order later on
89 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
93 option_parse OPTIONS_DETECT
"${XOPTIONS_DETECT}"
94 option_parse OPTIONS
"${XOPTIONS}"
95 option_parse OPTIONS_XTRA
"${XOPTIONS_XTRA}"
98 # Predefined CONFIG= urations take precedence over anything else
99 if [ -n "${CONFIG}" ]; then
104 [nN
][uU
][lL
][lL
][iI
])
107 [mM
][iI
][nN
][iI
][mM
][aA
][lL
])
108 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
114 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
117 [nN
][eE
][tT
][sS
][eE
][nN
][dD
])
118 OPT_DOTLOCK
=require OPT_ICONV
=require OPT_REGEX
=require
122 OPT_GSSAPI
=1 OPT_NETRC
=1
129 OPT_HISTORY
=1 OPT_KEY_BINDINGS
=1
132 [mM
][aA
][xX
][iI
][mM
][aA
][lL
])
135 [dD
][eE
][vV
][eE
][lL
])
137 OPT_DEVEL
=1 OPT_DEBUG
=1 OPT_NYD2
=1
139 [oO
][dD
][eE
][vV
][eE
][lL
])
144 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
145 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
149 msg_nonl
"CONFIG=${CONFIG} ... "
153 # Inter-relationships
155 if feat_no SMTP
&& feat_no POP3
&& feat_no IMAP
; then
158 if feat_no SOCKETS
; then
159 if feat_require SMTP
; then
160 msg
'ERROR: need SOCKETS for required feature SMTP'
163 if feat_require POP3
; then
164 msg
'ERROR: need SOCKETS for required feature POP3'
167 if feat_require IMAP
; then
168 msg
'ERROR: need SOCKETS for required feature IMAP'
171 OPT_SSL
=0 OPT_SSL_ALL_ALGORITHMS
=0
172 OPT_SMTP
=0 OPT_POP3
=0 OPT_IMAP
=0
173 OPT_GSSAPI
=0 OPT_NETRC
=0 OPT_AGENT
=0
175 if feat_no SMTP
&& feat_no IMAP
; then
179 if feat_no ICONV
; then
180 if feat_yes IMAP
; then
181 if feat_require IMAP
; then
182 msg
'ERROR: need ICONV for required feature IMAP'
185 msg
'ERROR: disabling IMAP due to missing ICONV'
189 if feat_yes IDNA
; then
190 if feat_require IDNA
; then
191 msg
'ERROR: need ICONV for required feature IDNA'
194 msg
'ERROR: disabling IDNA due to missing ICONV'
200 OPT_HISTORY
=0 OPT_KEY_BINDINGS
=0
203 # If we don't need MD5 leave it alone
204 if feat_no SOCKETS
; then
208 if feat_no TERMCAP
; then
209 OPT_TERMCAP_VIA_TERMINFO
=0
212 if feat_yes DEVEL
; then
220 h
=.
/mk-config.h h_name
=mk-config.h
223 newlst
=.
/mk-nconfig.lst
224 newmk
=.
/mk-nconfig.mk
225 newev
=.
/mk-nconfig.ev
231 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
233 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
234 # via path_check() later on once possible
236 # TODO cc_maxopt is brute simple, we should compile test program and dig real
237 # compiler versions for known compilers, then be more specific
238 [ -n "${cc_maxopt}" ] || cc_maxopt
=100
242 # We don't "have any utility": only path adjustments and such in here!
243 [ -n "${OS}" ] || OS
=`uname -s`
246 if [ ${OS} = SunOS
]; then
247 msg
'SunOS / Solaris? Applying some "early setup" rules ...'
248 _os_early_setup_sunos
252 _os_early_setup_sunos
() {
253 # According to standards(5), this is what we need to do
254 if [ -d /usr
/xpg4
]; then :; else
255 msg
'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
258 PATH
="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
259 [ -d /usr
/xpg6
] && PATH
="/usr/xpg6/bin:${PATH}"
264 # OSENV ends up in *build-osenv*
265 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
266 OS
=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
267 [ -n "${OSENV}" ] || OSENV
=`uname -srm`
268 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC
=`uname -a`
269 msg
'Operating system is %s' ${OS}
271 if [ ${OS} = darwin
]; then
272 msg
' . have special Darwin environmental addons...'
273 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
274 elif [ ${OS} = sunos
]; then
275 msg
' . have special SunOS / Solaris "setup" rules ...'
277 elif [ ${OS} = unixware
]; then
278 if feat_yes AUTOCC
&& acmd_set CC cc
; then
279 msg
' . have special UnixWare environmental rules ...'
280 feat_yes DEBUG
&& _CFLAGS
='-v -Xa -g' || _CFLAGS
='-Xa -O'
282 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
283 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
284 export CC CFLAGS LDFLAGS
285 OPT_AUTOCC
=0 had_want_autocc
=1 need_R_ldflags
=-R
287 elif [ -n "${VERBOSE}" ]; then
288 msg
' . no special treatment for this system necessary or known'
291 # Sledgehammer: better set _GNU_SOURCE
292 # And in general: oh, boy!
293 OS_DEFINES
="${OS_DEFINES}#define _GNU_SOURCE\n"
294 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
295 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
296 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
298 # On pkgsrc(7) systems automatically add /usr/pkg/*
299 if [ -d /usr
/pkg
]; then
300 C_INCLUDE_PATH
=/usr
/pkg
/include
:${C_INCLUDE_PATH}
301 LD_LIBRARY_PATH
=/usr
/pkg
/lib
:${LD_LIBRARY_PATH}
306 C_INCLUDE_PATH
=/usr
/xpg
4/include
:${C_INCLUDE_PATH}
307 LD_LIBRARY_PATH
=/usr
/xpg
4/lib
:${LD_LIBRARY_PATH}
310 if [ -d /opt
/csw
]; then
311 C_INCLUDE_PATH
=/opt
/csw
/include
:${C_INCLUDE_PATH}
312 LD_LIBRARY_PATH
=/opt
/csw
/lib
:${LD_LIBRARY_PATH}
315 OS_DEFINES
="${OS_DEFINES}#define __EXTENSIONS__\n"
316 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
318 [ -n "${cksum}" ] ||
cksum=/opt
/csw
/gnu
/cksum
319 if [ -x "${cksum}" ]; then :; else
320 msg
'ERROR: Not an executable program: %s' "${cksum}"
321 msg
'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
322 msg
'ERROR: However, we do so only for tests.'
323 msg
'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
327 if feat_yes AUTOCC
; then
328 if acmd_set CC cc
; then
329 feat_yes DEBUG
&& _CFLAGS
="-v -Xa -g" || _CFLAGS
="-Xa -O"
331 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
332 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
333 export CC CFLAGS LDFLAGS
334 OPT_AUTOCC
=0 had_want_autocc
=1 need_R_ldflags
=-R
336 # Assume gcc(1), which supports -R for compat
337 cc_maxopt
=2 force_no_stackprot
=1 need_R_ldflags
=-Wl,-R
342 # Check out compiler ($CC) and -flags ($CFLAGS)
344 # Even though it belongs into cc_flags we will try to compile and link
345 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
346 # EXTRA_CFLAGS/EXTRA_LDFLAGS
347 if feat_no AUTOCC
; then
349 # Ensure those don't do any harm
350 EXTRA_CFLAGS
= EXTRA_LDFLAGS
=
351 export EXTRA_CFLAGS EXTRA_LDFLAGS
355 export CFLAGS LDFLAGS
358 [ -n "${CC}" ] && { _cc_default
; return; }
360 msg_nonl
'Searching for a usable C compiler .. $CC='
361 if acmd_set CC clang || acmd_set CC gcc ||
362 acmd_set CC tcc || acmd_set CC pcc ||
363 acmd_set CC c89 || acmd_set CC c99
; then
366 msg
'boing booom tschak'
367 msg
'ERROR: I cannot find a compiler!'
368 msg
' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
369 msg
' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
377 if [ -z "${CC}" ]; then
378 msg
'To go on like you have chosen, please set $CC, rerun.'
382 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG
; then
385 msg
'Using C compiler ${CC}=%s' "${CC}"
390 if feat_yes AUTOCC
; then
391 if [ -f ${lst} ] && feat_no DEBUG
&& [ -z "${VERBOSE}" ]; then
393 msg
'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
397 msg
'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
400 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
401 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
402 msg ' . have special tcc(1) environmental rules ...'
405 # As of pcc CVS 2016-04-02, stack protection support is announced but
406 # will break if used on Linux
407 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
413 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
414 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
415 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
417 if feat_no DEBUG; then
418 CFLAGS="-DNDEBUG ${CFLAGS}"
422 export CFLAGS LDFLAGS
426 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
433 if feat_yes DEBUG; then
434 # May have problems to find libtcc cc_check -b
438 if ld_check -Wl,-rpath =./ no; then
439 need_R_ldflags=-Wl,-rpath=
440 ld_check -Wl,--enable-new-dtags
441 ld_runtime_flags # update!
444 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
445 unset __cflags __ldflags
448 _cc_flags_generic() {
449 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
451 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
453 # E.g., valgrind does not work well with high optimization
454 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
455 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
456 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
459 # Check -g first since some others may rely upon -g / optim. level
460 if feat_yes DEBUG; then
463 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
465 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
467 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
473 if feat_yes AMALGAMATION; then
477 #if feat_yes DEVEL && cc_check -Weverything; then
482 cc_check -Wbad-function-cast
483 cc_check -Wcast-align
486 cc_check -Wmissing-prototypes
489 cc_check -Wwrite-strings
490 cc_check -Wno-long-long
494 if feat_yes AMALGAMATION && feat_no DEVEL; then
495 cc_check -Wno-unused-function
497 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
499 cc_check -fno-unwind-tables
500 cc_check -fno-asynchronous-unwind-tables
501 cc_check -fstrict-aliasing
502 if cc_check -fstrict-overflow && feat_yes DEVEL; then
503 cc_check -Wstrict-overflow=5
506 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
507 if [ -z "${force_no_stackprot}" ]; then
508 if cc_check -fstack-protector-strong ||
509 cc_check -fstack-protector-all; then
510 cc_check -D_FORTIFY_SOURCE=2
513 msg 'Not checking for -fstack-protector compiler option,'
514 msg 'since that caused errors in a "similar" configuration.'
515 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
519 # LD (+ dependend CC)
521 if feat_yes ASAN_ADDRESS; then
523 if cc_check -fsanitize=address &&
524 ld_check -fsanitize=address; then
527 feat_bail_required ASAN_ADDRESS
532 if feat_yes ASAN_MEMORY; then
534 if cc_check -fsanitize=memory &&
535 ld_check -fsanitize=memory &&
536 cc_check -fsanitize-memory-track-origins=2 &&
537 ld_check -fsanitize-memory-track-origins=2; then
540 feat_bail_required ASAN_MEMORY
545 ld_check -Wl,-z,relro
547 ld_check -Wl,-z,noexecstack
548 if ld_check -Wl,-rpath =./ no; then
549 need_R_ldflags=-Wl,-rpath=
550 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
551 ld_check -Wl,--enable-new-dtags
552 ld_runtime_flags # update!
553 elif ld_check -Wl,-R ./ no; then
554 need_R_ldflags=-Wl,-R
555 ld_check -Wl,--enable-new-dtags
556 ld_runtime_flags # update!
559 # Address randomization
561 if cc_check -fPIE || cc_check -fpie; then
562 ld_check -pie || _CFLAGS=${_ccfg}
566 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
567 unset __cflags __ldflags
570 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
573 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
574 ## redirection, so use "printf '' >" instead
576 ## Very first: we undergo several states regarding I/O redirection etc.,
577 ## but need to deal with option updates from within all. Since all the
578 ## option stuff should be above the scissor line, define utility functions
579 ## and redefine them as necessary.
580 ## And, since we have those functions, simply use them for whatever
582 t1=ten10one1ten10one1
583 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
584 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
585 ) > /dev/null 2>&1; then
592 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
598 # which(1) not standardized, command(1) -v may return non-executable: unroll!
599 acmd_test() { __acmd "${1}" 1 0 0; }
600 acmd_test_fail() { __acmd "${1}" 1 1 0; }
601 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
602 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
603 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
604 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
605 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
606 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
607 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
608 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
610 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
612 if [ "${dotest}" -ne 0 ]; then
613 eval dotest=\$${varname}
614 if [ -n "${dotest}" ]; then
615 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
616 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
622 [ -n "${noglob_shell}" ] && set -o noglob
624 [ -n "${noglob_shell}" ] && set +o noglob
628 if [ -z "${path}" ] || [ "${path}" = . ]; then
629 if [ -d "${PWD}" ]; then
635 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
636 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
637 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
638 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
643 # We may have no builtin string functions, we yet have no programs we can
644 # use, try to access once from the root, assuming it is an absolute path if
645 # that finds the executable
646 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
647 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
648 msg ' . ${%s} ... %s' "${pname}" "${pname}"
649 [ -n "${varname}" ] && eval ${varname}="${pname}"
653 [ ${dofail} -eq 0 ] && return 1
654 msg 'ERROR: no trace of utility '"${pname}"
661 printf >&2 -- "${fmt}\\n" "${@}"
667 printf >&2 -- "${fmt}" "${@}"
670 # Our feature check environment
672 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
673 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
677 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
678 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
679 [ "x${1}" = xrequire ]
683 [ "x${1}" = xrequire ]
688 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
689 if feat_val_no "${i}"; then
691 elif feat_val_yes "${i}"; then
694 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
705 _feat_check ${1} && return 1
711 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
712 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
715 feat_bail_required() {
716 if feat_require ${1}; then
717 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
721 option_update # XXX this is rather useless here (dependency chain..)
725 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
726 # options, without documentation, to $1
728 i="`${awk} -v input
=\"${2}\" '
731 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
734 v = substr(input, voff, RLENGTH)
735 input = substr(input, voff + RLENGTH)
738 d = substr(v, doff + 2, length(v) - doff - 1)
739 v = substr(v, 1, doff - 1)
749 # Return the "documentation string" for option $1, itself if none such
751 ${awk} -v want="${1}" \
752 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
755 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
758 v = substr(input, voff, RLENGTH)
759 input = substr(input, voff + RLENGTH)
762 d = substr(v, doff + 2, length(v) - doff - 1)
763 v = substr(v, 1, doff - 1)
777 # Join the values from make.rc into what currently is defined, not
778 # overwriting yet existing settings
780 # We want read(1) to perform reverse solidus escaping in order to be able to
781 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
782 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
783 < ${rc} ${awk} 'BEGIN{line = ""}{
784 gsub(/^[[:space:]]+/, "", $0)
785 gsub(/[[:space:]]+$/, "", $0)
786 if(gsub(/\\$/, "", $0)){
791 if(index(line, "#") == 1){
793 }else if(length(line)){
799 if [ -n "${good_shell}" ]; then
802 i=`${awk} -v LINE
="${line}" 'BEGIN{
803 gsub(/=.*$/, "", LINE)
807 if [ "${i}" = "${line}" ]; then
808 msg 'ERROR: invalid syntax in: %s' "${line}"
812 eval j="\$${i}" jx="\${${i}+x}"
813 if [ -n "${j}" ] || [ "${jx}" = x ]; then
816 j=`${awk} -v LINE
="${line}" 'BEGIN{
817 gsub(/^[^=]*=/, "", LINE)
818 gsub(/^\"*/, "", LINE)
819 gsub(/\"*$/, "", LINE)
823 [ "${i}" = "DESTDIR" ] && continue
826 # Reread the mixed version right now
831 # Expand the option values, which may contain shell snippets
832 ${rm} -f ${newlst} ${newmk} ${newh}
833 exec 5<&0 6>&1 <${tmp} >${newlst}
836 if [ -n "${good_shell}" ]; then
838 [ "${i}" != "${i#OPT_}" ] && z=1
840 i=`${awk} -v LINE
="${line}" 'BEGIN{
841 gsub(/=.*$/, "", LINE);\
844 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
850 if [ -n "${z}" ]; then
851 j="`echo ${j} |
${tr} '[A-Z]' '[a-z]'`"
852 if [ -z "${j}" ] || feat_val_no "${j}"; then
854 printf " /* #undef ${i} */\n" >> ${newh}
855 elif feat_val_yes "${j}"; then
856 if feat_val_require "${j}"; then
861 printf " /* #define ${i} */\n" >> ${newh}
863 msg 'ERROR: cannot parse <%s>' "${line}"
867 printf "#define ${i} \"${j}\"\n" >> ${newh}
869 printf "${i} = ${j}\n" >> ${newmk}
873 exec 0<&5 1>&6 5<&- 6<&-
877 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
878 varname=${1} addflag=${2} flagvarname=${3}
881 [ -n "${noglob_shell}" ] && set -o noglob
883 [ -n "${noglob_shell}" ] && set +o noglob
888 [ -z "${i}" ] && continue
889 [ -d "${i}" ] || continue
890 if [ -n "${j}" ]; then
891 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
896 # But do not link any fakeroot path into our binaries!
897 if [ -n "${addflag}" ]; then
898 case "${i}" in *fakeroot*) continue;; esac
899 k="${k} ${addflag}${i}"
905 # But do not link any fakeroot path into our binaries!
906 if [ -n "${addflag}" ]; then
907 case "${i}" in *fakeroot*) continue;; esac
908 k="${k} ${addflag}${i}"
912 eval "${varname}=\"${j}\""
913 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
918 if [ -n "${need_R_ldflags}" ]; then
921 set -- ${LD_LIBRARY_PATH}
925 # But do not link any fakeroot path into our binaries!
926 case "${i}" in *fakeroot*) continue;; esac
927 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
928 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
932 # Disable it for a possible second run.
937 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
939 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
940 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
941 _CFLAGS="${_CFLAGS} ${1}"
942 [ -n "${cc_check_silent}" ] || msg 'yes'
945 [ -n "${cc_check_silent}" ] || msg 'no'
950 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
951 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
952 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
953 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
954 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
955 [ -n "${cc_check_silent}" ] || msg 'yes'
958 [ -n "${cc_check_silent}" ] || msg 'no'
964 variable=$1 topic=$2 define=$3
967 msg_nonl ' . %s ... ' "${topic}"
968 echo "/* checked ${topic} */" >> ${h}
969 ${rm} -f ${tmp} ${tmp}.o
970 if [ "${dump_test_program}" = 1 ]; then
971 echo '*** test program is'
972 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
974 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
976 #echo '*** the preprocessor generates'
977 #${make} -f ${makefile} ${tmp}.x
979 echo '*** tests results'
983 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
986 msg_nonl ' . %s ... ' "${topic}"
988 echo '*** enforced unchecked results are'
989 if feat_val_yes ${yesno}; then
990 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
991 echo "*** adding INCS<${incs}> LIBS<${libs}>"
992 LIBS="${LIBS} ${libs}"
993 echo "${libs}" >> ${lib}
994 INCS="${INCS} ${incs}"
995 echo "${incs}" >> ${inc}
998 echo "${define}" >> ${h}
999 eval have_${variable}=yes
1002 echo "/* ${define} */" >> ${h}
1004 eval unset have_${variable}
1010 variable=$1 topic=$2 define=$3
1012 _check_preface "${variable}" "${topic}" "${define}"
1014 if ${make} -f ${makefile} XINCS="${INCS}" \
1015 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1017 [ -f ./${tmp}.o ]; then
1019 echo "${define}" >> ${h}
1020 eval have_${variable}=yes
1023 echo "/* ${define} */" >> ${h}
1025 eval unset have_${variable}
1031 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1033 _check_preface "${variable}" "${topic}" "${define}"
1035 if feat_yes CROSS_BUILD; then
1036 if [ ${run} = 1 ]; then
1041 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1042 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1043 XLIBS="${LIBS} ${libs}" \
1046 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1047 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1049 echo "${define}" >> ${h}
1050 LIBS="${LIBS} ${libs}"
1051 echo "${libs}" >> ${lib}
1052 INCS="${INCS} ${incs}"
1053 echo "${incs}" >> ${inc}
1054 eval have_${variable}=yes
1058 echo "/* ${define} */" >> ${h}
1059 eval unset have_${variable}
1065 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1069 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1073 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1077 if feat_yes ${1}; then
1078 echo '#define HAVE_'${1}'' >> ${h}
1081 echo '/* OPT_'${1}'=0 */' >> ${h}
1087 < "${1}" > "${2}" ${awk} \
1088 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1091 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1093 # First of all, create new configuration and check whether it changed
1095 # Very easy checks for the operating system in order to be able to adjust paths
1096 # or similar very basic things which we need to be able to go at all
1099 # Check those tools right now that we need before including $rc
1100 msg 'Checking for basic utility set'
1101 thecmd_testandset_fail awk awk
1102 thecmd_testandset_fail rm rm
1103 thecmd_testandset_fail tr tr
1105 # Initialize the option set
1106 msg_nonl 'Setting up configuration options ... '
1110 # Include $rc, but only take from it what wasn't overwritten by the user from
1111 # within the command line or from a chosen fixed CONFIG=
1112 # Note we leave alone the values
1113 trap "exit 1" HUP INT TERM
1114 trap "${rm} -f ${tmp}" EXIT
1116 msg_nonl 'Joining in %s ... ' ${rc}
1120 # We need to know about that now, in order to provide utility overwrites etc.
1123 msg 'Checking for remaining set of utilities'
1124 thecmd_testandset_fail grep grep
1126 # Before we step ahead with the other utilities perform a path cleanup first.
1130 thecmd_testandset_fail basename basename
1131 thecmd_testandset_fail cat cat
1132 thecmd_testandset_fail chmod chmod
1133 thecmd_testandset_fail cp cp
1134 thecmd_testandset_fail cmp cmp
1136 thecmd_testandset_fail mkdir mkdir
1137 thecmd_testandset_fail mv mv
1139 thecmd_testandset_fail sed sed
1140 thecmd_testandset_fail sort sort
1141 thecmd_testandset_fail tee tee
1143 thecmd_testandset chown chown ||
1144 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1145 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1147 thecmd_testandset_fail make make
1150 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1152 # For ./cc-test.sh only
1153 thecmd_testandset_fail cksum cksum
1155 # Update OPT_ options now, in order to get possible inter-dependencies right
1158 # (No functions since some shells loose non-exported variables in traps)
1159 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1160 trap "trap \"\" HUP INT TERM EXIT;\
1161 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1163 # Our configuration options may at this point still contain shell snippets,
1164 # we need to evaluate them in order to get them expanded, and we need those
1165 # evaluated values not only in our new configuration file, but also at hand..
1166 msg_nonl 'Evaluating all configuration items ... '
1170 # Add the known utility and some other variables
1171 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1172 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1174 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1175 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1176 if feat_yes DOTLOCK; then
1177 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1179 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1184 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1185 MAKE MAKEFLAGS make SHELL strip \
1188 printf "${i} = ${j}\n" >> ${newmk}
1189 printf "${i}=${j}\n" >> ${newlst}
1190 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1192 printf "\n" >> ${newev}
1194 # Build a basic set of INCS and LIBS according to user environment.
1195 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1196 path_check C_INCLUDE_PATH -I _INCS
1197 INCS="${INCS} ${_INCS}"
1198 path_check LD_LIBRARY_PATH -L _LIBS
1199 LIBS="${LIBS} ${_LIBS}"
1201 export C_INCLUDE_PATH LD_LIBRARY_PATH
1203 # Some environments need runtime path flags to be able to go at all
1206 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1210 ${cat} > ${tmp}.c << \!
1213 static void doit(char const *s);
1215 main(int argc, char **argv){
1218 doit("Hello world");
1222 doit(char const *s){
1224 memcpy(buf, s, strlen(s) +1);
1229 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1230 -o ${tmp2} ${tmp}.c ${LIBS}; then
1233 msg 'ERROR: i cannot compile a "Hello world" via'
1235 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1236 msg 'ERROR: Please read INSTALL, rerun'
1240 # This may also update ld_runtime_flags() (again)
1247 printf -- "${i}=${j}\n" >> ${newlst}
1253 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1257 printf -- "${i} = ${j}\n" >> ${newmk}
1258 printf -- "${i}=${j}\n" >> ${newlst}
1261 # Now finally check whether we already have a configuration and if so, whether
1262 # all those parameters are still the same.. or something has actually changed
1263 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1264 echo 'Configuration is up-to-date'
1266 elif [ -f ${lst} ]; then
1267 echo 'Configuration has been updated..'
1268 ( eval "${MAKE} -f ./mk-config.mk clean" )
1271 echo 'Shiny configuration..'
1274 # Time to redefine helper 1
1276 ${rm} -f ${lst} ${h} ${mk}
1280 ${mv} -f ${newlst} ${lst}
1281 ${mv} -f ${newev} ${ev}
1282 ${mv} -f ${newh} ${h}
1283 ${mv} -f ${newmk} ${mk}
1285 if [ -z "${VERBOSE}" ]; then
1286 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1287 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1288 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1289 printf -- "ECHO_TEST = @\n" >> ${mk}
1290 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1291 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1292 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1295 ## Compile and link checking
1301 makefile=./${tmp0}.mk
1303 # (No function since some shells loose non-exported variables in traps)
1304 trap "trap \"\" HUP INT TERM;\
1305 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1306 trap "trap \"\" HUP INT TERM EXIT;\
1307 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1309 # Time to redefine helper 2
1313 printf "*** ${fmt}\\n" "${@}"
1314 printf -- "${fmt}\\n" "${@}" >&5
1319 printf "*** ${fmt}\\n" "${@}"
1320 printf -- "${fmt}" "${@}" >&5
1324 exec 5>&2 > ${log} 2>&1
1326 echo "${LIBS}" > ${lib}
1327 echo "${INCS}" > ${inc}
1328 ${cat} > ${makefile} << \!
1329 .SUFFIXES: .o .c .x .y
1331 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1333 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1335 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1340 # May be multiline..
1342 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1343 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1344 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1346 # Generate n_err_number OS mappings
1349 feat_yes DEVEL && NV= || NV=noverbose
1350 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1351 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1352 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1355 feat_def ALWAYS_UNICODE_LOCALE
1356 feat_def AMALGAMATION
1357 feat_def CROSS_BUILD
1361 feat_def ASAN_ADDRESS
1362 feat_def ASAN_MEMORY
1368 if xrun_check inline 'inline functions' \
1369 '#define HAVE_INLINE
1370 #define n_INLINE static inline' << \!
1371 static inline int ilf(int i){return ++i;}
1372 int main(void){return ilf(-1);}
1376 elif xrun_check inline 'inline functions (via __inline)' \
1377 '#define HAVE_INLINE
1378 #define n_INLINE static __inline' << \!
1379 static __inline int ilf(int i){return ++i;}
1380 int main(void){return ilf(-1);}
1386 ## Test for "basic" system-calls / functionality that is used by all parts
1387 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1388 ## macros to be used by only the subprograms (potentially).
1390 if run_check clock_gettime 'clock_gettime(2)' \
1391 '#define HAVE_CLOCK_GETTIME' << \!
1397 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1404 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1405 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1411 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1418 elif run_check gettimeofday 'gettimeofday(2)' \
1419 '#define HAVE_GETTIMEOFDAY' << \!
1420 #include <stdio.h> /* For C89 NULL */
1421 #include <sys/time.h>
1426 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1434 have_no_subsecond_time=1
1437 if run_check nanosleep 'nanosleep(2)' \
1438 '#define HAVE_NANOSLEEP' << \!
1445 ts.tv_nsec = 100000;
1446 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1453 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1454 '#define HAVE_NANOSLEEP' '-lrt' << \!
1461 ts.tv_nsec = 100000;
1462 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1469 # link_check is enough for this, that function is so old, trust the proto
1470 elif link_check sleep 'sleep(3)' \
1471 '#define HAVE_SLEEP' << \!
1475 if(!sleep(1) || errno != ENOSYS)
1483 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1487 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1496 if((gid = getgid()) != 0)
1498 if((uid = getuid()) != 0)
1500 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1502 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1510 msg 'ERROR: we require user and group info / database searches.'
1511 msg 'That much Unix we indulge ourselfs.'
1515 if link_check ftruncate 'ftruncate(2)' \
1516 '#define HAVE_FTRUNCATE' << \!
1518 #include <sys/types.h>
1520 return (ftruncate(0, 0) != 0);
1526 msg 'ERROR: we require the ftruncate(2) system call.'
1530 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1534 struct sigaction nact, oact;
1536 nact.sa_handler = SIG_DFL;
1537 sigemptyset(&nact.sa_mask);
1538 nact.sa_flags = SA_RESTART;
1539 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1545 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1549 if link_check snprintf 'snprintf(3)' << \!
1554 snprintf(b, sizeof b, "%s", "string");
1561 msg 'ERROR: we require the snprintf(3) function.'
1565 if link_check environ 'environ(3)' << \!
1566 #include <stdio.h> /* For C89 NULL */
1568 extern char **environ;
1570 return environ[0] == NULL;
1576 msg 'ERROR: we require the environ(3) array for subprocess control.'
1580 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1583 setenv("s-mailx", "i want to see it cute!", 1);
1584 unsetenv("s-mailx");
1590 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1593 putenv("s-mailx=i want to see it cute!");
1600 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1604 if link_check termios 'termios.h and tc*(3) family' << \!
1605 #include <termios.h>
1607 struct termios tios;
1609 tcgetattr(0, &tios);
1610 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1617 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1618 msg 'That much Unix we indulge ourselfs.'
1624 if link_check vsnprintf 'vsnprintf(3)' << \!
1627 static void dome(char *buf, size_t blen, ...){
1631 vsnprintf(buf, blen, "%s", ap);
1637 dome(b, sizeof b, "string");
1644 feat_bail_required ERRORS
1647 if [ "${have_vsnprintf}" = yes ]; then
1649 link_check va_copy "va_copy(3) (as ${2})" \
1650 "#define HAVE_N_VA_COPY
1651 #define n_va_copy ${2}" <<_EOT
1655 # if defined __va_copy && !defined va_copy
1656 # define va_copy __va_copy
1659 static void dome2(char *buf, size_t blen, va_list src){
1663 vsnprintf(buf, blen, "%s", ap);
1666 static void dome(char *buf, size_t blen, ...){
1670 dome2(buf, blen, ap);
1676 dome(b, sizeof b, "string");
1681 __va_copy 0 va_copy || __va_copy 1 __va_copy
1684 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1691 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1693 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1695 /* Only link check */
1696 fpathconf(0, _PC_NAME_MAX);
1702 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1709 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1715 # We use this only then for now (need NOW+1)
1716 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1717 #include <fcntl.h> /* For AT_* */
1718 #include <sys/stat.h>
1721 struct timespec ts[2];
1723 ts[0].tv_nsec = UTIME_NOW;
1724 ts[1].tv_nsec = UTIME_OMIT;
1725 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1733 # XXX Add POSIX check once standardized
1734 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1743 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1744 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1745 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1746 #include <sys/random.h>
1749 getrandom(buf, sizeof buf, 0);
1755 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1756 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1757 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1758 #include <sys/syscall.h>
1761 syscall(SYS_getrandom, buf, sizeof buf, 0);
1767 elif [ -n "${have_no_subsecond_time}" ]; then
1768 msg 'ERROR: %s %s' 'without a native random' \
1769 'one of clock_gettime(2) and gettimeofday(2) is required.'
1774 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1777 putc_unlocked('@', stdout);
1782 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1790 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1793 char x_buf[4096], *x = realpath(".", x_buf);
1795 return (x != NULL) ? 0 : 1;
1799 if run_check realpath_malloc 'realpath(3) takes NULL' \
1800 '#define HAVE_REALPATH_NULL' << \!
1803 char *x = realpath(".", NULL);
1807 return (x != NULL) ? 0 : 1;
1815 ## optional and selectable
1817 if feat_yes DOTLOCK; then
1818 if run_check readlink 'readlink(2)' << \!
1824 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1832 feat_bail_required DOTLOCK
1836 if feat_yes DOTLOCK; then
1837 if run_check fchown 'fchown(2)' << \!
1841 if(!fchown(0, 0, 0) || errno != ENOSYS)
1849 feat_bail_required DOTLOCK
1853 ## Now it is the time to fork away the BASE_ series
1856 squeeze_em ${inc} ${tmp}
1858 squeeze_em ${lib} ${tmp}
1861 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1862 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1864 ## The remains are expected to be used only by the main MUA binary!
1867 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1870 setlocale(LC_ALL, "");
1874 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1876 OPT_MULTIBYTE_CHARSETS=0
1878 OPT_TERMINAL_CHARSET=0
1879 if [ -n "${have_setlocale}" ]; then
1880 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1881 '#define HAVE_C90AMEND1' << \!
1887 char mbb[MB_LEN_MAX + 1];
1892 mbtowc(&wc, "x
", 1);
1893 mbrtowc(&wc, "x
", 1, NULL);
1895 return (mblen("\
0", 1) == 0);
1898 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1900 if [ -n "${have_c90amend1}" ]; then
1901 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1908 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1911 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1912 #include <langinfo.h>
1916 return (nl_langinfo(CODESET) == NULL);
1919 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1922 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1923 #include <fnmatch.h>
1925 return (fnmatch("*", ".
", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1929 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1933 return !(de.d_type == DT_UNKNOWN ||
1934 de.d_type == DT_DIR || de.d_type == DT_LNK);
1938 ## optional and selectable
1940 if feat_yes ICONV; then
1941 ${cat} > ${tmp2}.c << \!
1942 #include <stdio.h> /* For C89 NULL */
1947 id = iconv_open("foo
", "bar
");
1948 iconv(id, NULL, NULL, NULL, NULL);
1953 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1954 '#define HAVE_ICONV' ||
1955 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1956 '#define HAVE_ICONV' '-liconv' ||
1957 feat_bail_required ICONV
1959 echo '/* OPT_ICONV=0 */' >> ${h}
1962 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1963 ${cat} > ${tmp2}.c << \!
1964 #include <sys/types.h>
1965 #include <sys/socket.h>
1969 struct sockaddr_un soun;
1971 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1973 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1975 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1981 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1982 '#define HAVE_UNIX_SOCKETS' ||
1983 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1984 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1985 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1986 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1989 if feat_yes SOCKETS; then
1990 ${cat} > ${tmp2}.c << \!
1991 #include <sys/types.h>
1992 #include <sys/socket.h>
1993 #include <netinet/in.h>
1998 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2000 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2006 < ${tmp2}.c run_check sockets 'sockets' \
2007 '#define HAVE_SOCKETS' ||
2008 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2009 '#define HAVE_SOCKETS' '-lnsl' ||
2010 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2011 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2012 feat_bail_required SOCKETS
2014 echo '/* OPT_SOCKETS=0 */' >> ${h}
2015 fi # feat_yes SOCKETS
2017 if feat_yes SOCKETS; then
2018 link_check getaddrinfo 'getaddrinfo(3)' \
2019 '#define HAVE_GETADDRINFO' << \!
2020 #include <sys/types.h>
2021 #include <sys/socket.h>
2025 struct addrinfo a, *ap;
2028 switch((lrv = getaddrinfo("foo
", "0", &a, &ap))){
2032 fprintf(stderr, "%s
\n", gai_strerror(lrv));
2041 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2042 compile_check arpa_inet_h '<arpa/inet.h>' \
2043 '#define HAVE_ARPA_INET_H' << \!
2044 #include <sys/types.h>
2045 #include <sys/socket.h>
2047 #include <netinet/in.h>
2048 #include <arpa/inet.h>
2051 ${cat} > ${tmp2}.c << \!
2052 #include <sys/types.h>
2053 #include <sys/socket.h>
2057 #include <netinet/in.h>
2058 #ifdef HAVE_ARPA_INET_H
2059 #include <arpa/inet.h>
2062 struct sockaddr_in servaddr;
2063 unsigned short portno;
2066 struct in_addr **pptr;
2069 if((ep = getservbyname("POPPY-PORT
", "tcp
")) != NULL)
2070 portno = (unsigned short)ep->s_port;
2072 if((hp = gethostbyname("POPPY-HOST
")) != NULL){
2073 pptr = (struct in_addr**)hp->h_addr_list;
2074 if(hp->h_addrtype != AF_INET)
2075 fprintf(stderr, "au
\n");
2078 case HOST_NOT_FOUND:
2084 fprintf(stderr, "au
\n");
2089 memset(&servaddr, 0, sizeof servaddr);
2090 servaddr.sin_family = AF_INET;
2091 servaddr.sin_port = htons(portno);
2092 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2093 fprintf(stderr, "Would connect to
%s
:%d ...
\n",
2094 inet_ntoa(**pptr), (int)portno);
2099 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2100 < ${tmp2}.c link_check gethostbyname \
2101 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2102 < ${tmp2}.c link_check gethostbyname \
2103 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2104 '' '-lsocket -lnsl' ||
2105 feat_bail_required SOCKETS
2109 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2110 #include <sys/socket.h>
2116 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2123 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2124 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2125 #include <sys/socket.h>
2133 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2134 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2139 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2140 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2141 #include <sys/socket.h>
2149 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2155 if feat_yes SSL; then # {{{
2156 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2157 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2158 # time: we need to test it first in order to get things right
2159 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2162 #define HAVE_XSSL_RESSL
2163 #define HAVE_XSSL_OPENSSL 0' << \!
2164 #include <openssl/opensslv.h>
2165 #ifdef LIBRESSL_VERSION_NUMBER
2172 VAL_SSL_FEATURES=libressl
2173 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2174 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2177 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2178 #include <openssl/opensslv.h>
2179 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2186 VAL_SSL_FEATURES=libssl-0x10100
2187 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2190 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2191 #include <openssl/opensslv.h>
2192 #ifdef OPENSSL_VERSION_NUMBER
2199 VAL_SSL_FEATURES=libssl-0x10000
2201 feat_bail_required SSL
2204 if feat_yes SSL; then # {{{
2205 if [ -n "${ossl_v1_1}" ]; then
2206 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2207 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2209 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2210 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2211 '-lssl -lcrypto' << \!
2212 #include <openssl/ssl.h>
2213 #include <openssl/err.h>
2214 #include <openssl/x509v3.h>
2215 #include <openssl/x509.h>
2216 #include <openssl/rand.h>
2217 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2218 # error We need TLSv1.
2221 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2224 PEM_read_PrivateKey(0, 0, 0, 0);
2230 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2231 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2232 '-lssl -lcrypto' << \!
2233 #include <openssl/ssl.h>
2234 #include <openssl/err.h>
2235 #include <openssl/x509v3.h>
2236 #include <openssl/x509.h>
2237 #include <openssl/rand.h>
2238 #if defined OPENSSL_NO_SSL3 &&\
2239 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2240 # error We need one of SSLv3 and TLSv1.
2243 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2246 PEM_read_PrivateKey(0, 0, 0, 0);
2253 feat_bail_required SSL
2257 if feat_yes SSL; then # {{{
2258 if feat_yes SSL_ALL_ALGORITHMS; then
2259 if [ -n "${ossl_v1_1}" ]; then
2260 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2261 '#define HAVE_SSL_ALL_ALGORITHMS'
2262 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2263 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2264 #include <openssl/evp.h>
2266 OpenSSL_add_all_algorithms();
2267 EVP_get_cipherbyname("two cents i never exist
");
2275 feat_bail_required SSL_ALL_ALGORITHMS
2277 elif [ -n "${ossl_v1_1}" ]; then
2278 without_check yes ssl_all_algo \
2279 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2280 '#define HAVE_SSL_ALL_ALGORITHMS'
2283 if [ -n "${ossl_v1_1}" ]; then
2284 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2285 '#define HAVE_XSSL_STACK_OF'
2286 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2287 '#define HAVE_XSSL_STACK_OF' << \!
2288 #include <stdio.h> /* For C89 NULL */
2289 #include <openssl/ssl.h>
2290 #include <openssl/err.h>
2291 #include <openssl/x509v3.h>
2292 #include <openssl/x509.h>
2293 #include <openssl/rand.h>
2295 STACK_OF(GENERAL_NAME) *gens = NULL;
2297 printf("%p
", gens); /* to use it */
2305 if [ -n "${ossl_v1_1}" ]; then
2306 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2307 '#define HAVE_XSSL_CONFIG'
2308 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2309 elif link_check xssl_conf \
2310 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2311 '#define HAVE_XSSL_CONFIG' << \!
2312 #include <stdio.h> /* For C89 NULL */
2313 #include <openssl/conf.h>
2315 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2316 CONF_modules_free();
2321 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2323 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2326 if [ -n "${ossl_v1_1}" ]; then
2327 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2328 '#define HAVE_XSSL_CONF_CTX'
2329 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2330 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2331 '#define HAVE_XSSL_CONF_CTX' << \!
2332 #include <openssl/ssl.h>
2333 #include <openssl/err.h>
2335 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2336 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2338 SSL_CONF_CTX_set_flags(cctx,
2339 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2340 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2341 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2342 SSL_CONF_cmd(cctx, "Protocol
", "ALL
");
2343 SSL_CONF_CTX_finish(cctx);
2344 SSL_CONF_CTX_free(cctx);
2350 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2352 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2355 if [ -n "${ossl_v1_1}" ]; then
2356 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2357 '#define HAVE_XSSL_CTX_CONFIG'
2358 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2359 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2360 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2361 '#define HAVE_XSSL_CTX_CONFIG' << \!
2362 #include <stdio.h> /* For C89 NULL */
2363 #include <openssl/ssl.h>
2365 SSL_CTX_config(NULL, "SOMEVAL
");
2370 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2372 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2375 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2376 without_check yes xssl_set_maxmin_proto \
2377 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2378 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2379 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2380 elif link_check xssl_set_maxmin_proto \
2381 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2382 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2383 #include <stdio.h> /* For C89 NULL */
2384 #include <openssl/ssl.h>
2386 SSL_CTX_set_min_proto_version(NULL, 0);
2387 SSL_CTX_set_max_proto_version(NULL, 10);
2392 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2394 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2397 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2398 '#define HAVE_XSSL_RAND_EGD' << \!
2399 #include <openssl/rand.h>
2401 return RAND_egd("some.where
") > 0;
2405 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd
"
2407 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2409 fi # feat_yes SSL }}}
2411 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2412 run_check ssl_md5 'MD5 digest in the used crypto library' \
2413 '#define HAVE_XSSL_MD5' << \!
2416 #include <openssl/md5.h>
2418 char const dat[] = "abrakadabrafidibus
";
2419 char dig[16], hex[16 * 2];
2423 memset(dig, 0, sizeof(dig));
2424 memset(hex, 0, sizeof(hex));
2426 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2427 MD5_Final(dig, &ctx);
2429 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2430 for(i = 0; i < sizeof(hex) / 2; i++){
2432 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2433 hex[++j] = hexchar(dig[i] & 0x0f);
2435 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326
", hex, sizeof(hex));
2440 echo '/* OPT_SSL=0 */' >> ${h}
2441 fi # }}} feat_yes SSL
2442 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2444 if [ "${have_xssl}" = yes ]; then
2455 if feat_yes GSSAPI
; then
2456 ${cat} > ${tmp2}.c
<< \
!
2457 #include <gssapi/gssapi.h>
2459 gss_import_name
(0, 0, GSS_C_NT_HOSTBASED_SERVICE
, 0);
2460 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2464 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2466 if acmd_set i krb5-config
; then
2467 GSS_LIBS
="`CFLAGS= ${i} --libs gssapi`"
2468 GSS_INCS
="`CFLAGS= ${i} --cflags`"
2469 i
='GSS-API via krb5-config(1)'
2473 i
='GSS-API in gssapi/gssapi.h, libgssapi'
2475 if < ${tmp2}.c link_check gss \
2476 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2477 < ${tmp3}.c link_check gss \
2478 'GSS-API in gssapi.h, libgssapi' \
2479 '#define HAVE_GSSAPI
2480 #define GSSAPI_REG_INCLUDE' \
2482 < ${tmp2}.c link_check gss
'GSS-API in libgssapi_krb5' \
2483 '#define HAVE_GSSAPI' \
2485 < ${tmp3}.c link_check gss \
2486 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2487 '#define HAVE_GSSAPI
2488 #define GSS_REG_INCLUDE' \
2489 '-lgssapi -lkrb5 -lcrypto' \
2490 '-I/usr/include/kerberosV' ||\
2491 < ${tmp2}.c link_check gss
'GSS-API in libgss' \
2492 '#define HAVE_GSSAPI' \
2494 link_check gss
'GSS-API in libgssapi_krb5, old-style' \
2495 '#define HAVE_GSSAPI
2496 #define GSSAPI_OLD_STYLE' \
2497 '-lgssapi_krb5' << \
!
2498 #include <gssapi/gssapi.h>
2499 #include <gssapi/gssapi_generic.h>
2501 gss_import_name
(0, 0, gss_nt_service_name
, 0);
2502 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2509 feat_bail_required GSSAPI
2512 echo '/* OPT_GSSAPI=0 */' >> ${h}
2513 fi # feat_yes GSSAPI
2518 if feat_yes IDNA
; then
2519 if link_check idna
'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2522 #include <idn-free.h>
2523 #include <stringprep.h>
2525 char
*utf8
, *idna_ascii
, *idna_utf8
;
2527 utf8
= stringprep_locale_to_utf8
("does.this.work");
2528 if (idna_to_ascii_8z
(utf8
, &idna_ascii
, IDNA_USE_STD3_ASCII_RULES
)
2531 idn_free
(idna_ascii
);
2532 /* (Rather link check only here
) */
2533 idna_utf8
= stringprep_convert
(idna_ascii
, "UTF-8", "de_DE");
2539 elif link_check idna
'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2542 #include <idn/api.h>
2543 #include <idn/result.h>
2547 char local_name
[256];
2549 r
= idn_encodename
(IDN_ENCODE_APP
, "does.this.work", ace_name
,
2551 if (r
!= idn_success
) {
2552 fprintf
(stderr
, "idn_encodename failed: %s\n", idn_result_tostring
(r
));
2555 r
= idn_decodename
(IDN_DECODE_APP
, ace_name
, local_name
, sizeof
(local_name
));
2556 if (r
!= idn_success
) {
2557 fprintf
(stderr
, "idn_decodename failed: %s\n", idn_result_tostring
(r
));
2566 feat_bail_required IDNA
2569 if [ -n "${have_idna}" ]; then
2570 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2571 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2574 echo '/* OPT_IDNA=0 */' >> ${h}
2577 feat_def IMAP_SEARCH
2579 if feat_yes REGEX
; then
2580 if link_check regex
'regular expressions' '#define HAVE_REGEX' << \
!
2588 status
= regcomp
(&re
, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB
);
2589 xret
= regerror
(status
, &re
, NULL
, 0);
2590 status
= regexec
(&re
, "plan9", 0,NULL
, 0);
2592 return !(status
== REG_NOMATCH
);
2598 feat_bail_required REGEX
2601 echo '/* OPT_REGEX=0 */' >> ${h}
2604 if feat_yes MLE
&& [ -n "${have_c90amend1}" ]; then
2606 echo '#define HAVE_MLE' >> ${h}
2608 feat_bail_required MLE
2609 echo '/* OPT_MLE=0 */' >> ${h}
2612 # Generic have-a-line-editor switch for those who need it below
2613 if [ -n "${have_mle}" ]; then
2617 if [ -n "${have_cle}" ] && feat_yes HISTORY
; then
2618 echo '#define HAVE_HISTORY' >> ${h}
2620 echo '/* OPT_HISTORY=0 */' >> ${h}
2623 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS
; then
2624 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2626 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2629 if feat_yes TERMCAP
; then
2631 link_check termcap
"termcap(5) (via ${4})" \
2632 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2637 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2638 static int my_putc(int c){return putchar(c);}
2640 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2641 int r2 = OK, r3 = ERR;
2643 tgetent(buf, getenv("TERM"));
2645 r1 = tgetstr(UNCONST("cm"), &cpb);
2647 r2 = tgetnum(UNCONST("Co"));
2648 r3 = tgetflag(UNCONST("ut"));
2649 tputs("cr", 1, &my_putc);
2650 return (r1 == NULL || r2 == -1 || r3 == 0);
2656 link_check terminfo
"terminfo(5) (via ${2})" \
2657 '#define HAVE_TERMCAP
2658 #define HAVE_TERMCAP_CURSES
2659 #define HAVE_TERMINFO' "${1}" << _EOT
2663 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2664 static int my_putc(int c){return putchar(c);}
2670 r0 = setupterm(NULL, 1, &er);
2671 r1 = tigetflag(UNCONST("bce"));
2672 r2 = tigetnum(UNCONST("colors"));
2673 r3 = tigetstr(UNCONST("cr"));
2674 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2675 tputs(tp, 1, &my_putc);
2676 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2677 r3 == (char*)-1 || r3 == NULL);
2682 if feat_yes TERMCAP_VIA_TERMINFO
; then
2683 __terminfolib
-ltinfo -ltinfo ||
2684 __terminfolib
-lcurses -lcurses ||
2685 __terminfolib
-lcursesw -lcursesw ||
2686 feat_bail_required TERMCAP_VIA_TERMINFO
2689 if [ -z "${have_terminfo}" ]; then
2690 __termcaplib
-ltermcap '' '' '-ltermcap' ||
2691 __termcaplib
-ltermcap '#include <curses.h>' '
2692 #define HAVE_TERMCAP_CURSES' \
2693 'curses.h / -ltermcap' ||
2694 __termcaplib
-lcurses '#include <curses.h>' '
2695 #define HAVE_TERMCAP_CURSES' \
2696 'curses.h / -lcurses' ||
2697 __termcaplib
-lcursesw '#include <curses.h>' '
2698 #define HAVE_TERMCAP_CURSES' \
2699 'curses.h / -lcursesw' ||
2700 feat_bail_required TERMCAP
2702 if [ -n "${have_termcap}" ]; then
2703 run_check tgetent_null \
2704 "tgetent(3) of termcap(5) takes NULL buffer" \
2705 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2706 #include <stdio.h> /* For C89 NULL */
2708 #ifdef HAVE_TERMCAP_CURSES
2709 # include <curses.h>
2713 tgetent(NULL, getenv("TERM"));
2720 echo '/* OPT_TERMCAP=0 */' >> ${h}
2721 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2724 if feat_def SPAM_SPAMC
; then
2725 if acmd_set i spamc
; then
2726 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2730 if feat_yes SPAM_SPAMD
&& [ -n "${have_af_unix}" ]; then
2731 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2733 feat_bail_required SPAM_SPAMD
2734 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2737 feat_def SPAM_FILTER
2739 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER
; then
2740 echo '#define HAVE_SPAM' >> ${h}
2742 echo '/* HAVE_SPAM */' >> ${h}
2745 if feat_yes QUOTE_FOLD
&&\
2746 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2747 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2749 feat_bail_required QUOTE_FOLD
2750 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2753 feat_def FILTER_HTML_TAGSOUP
2762 squeeze_em
${inc} ${tmp}
2764 squeeze_em
${lib} ${tmp}
2769 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2770 ${cat} ${tmp} >> ${h}
2774 # Create the string that is used by *features* and `version'.
2775 # Take this nice opportunity and generate a visual listing of included and
2776 # non-included features for the person who runs the configuration
2777 msg
'\nThe following features are included (+) or not (-):'
2778 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2779 printf '/* The "feature string" */\n' >> ${h}
2780 # Because + is expanded by *folder* if first in "echo $features", put something
2781 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2785 sdoc
=`option_doc_of ${opt}`
2786 [ -z "${sdoc}" ] && continue
2787 sopt
="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2788 feat_yes
${opt} && sign
=+ || sign
=-
2789 printf -- "${sep}${sign}${sopt}" >> ${h}
2791 msg " %s
%s
: %s
" ${sign} ${sopt} "${sdoc}"
2793 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2795 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2796 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2797 printf '"\n' >> ${h}
2799 # Create the real mk-config.mk
2800 # Note we cannout use explicit ./ filename prefix for source and object
2801 # pathnames because of a bug in bmake(1)
2802 ${rm} -rf ${tmp0}.* ${tmp0}*
2804 if feat_no AMALGAMATION
; then
2805 for i
in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2806 i
=`basename "${i}" .c`
2807 if [ "${i}" = privsep
]; then
2810 objlist
="${objlist} ${i}.o"
2811 srclist
="${srclist} \$(SRCDIR)${i}.c"
2812 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2813 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2815 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2817 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2818 "main.o
" "main.c
" >> ${mk}
2819 srclist=main.c objlist=main.o
2820 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2822 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2823 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2824 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2825 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2826 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2828 if [ "${i}" = main.c ] ||
2829 [ "${i}" = privsep.c ]; then
2832 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2833 printf '# include "%s
%s
"\n' "${SRCDIR}" "${i}" >> ${h}
2837 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2839 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2841 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2842 echo "INCS
= `${cat} ${inc}`" >> ${mk}
2844 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2849 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2850 msg ' . bindir: %s' "${VAL_BINDIR}"
2851 if feat_yes DOTLOCK; then
2852 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2854 msg ' . mandir: %s' "${VAL_MANDIR}"
2855 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2856 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2859 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2863 if [ -z "${have_fnmatch}" ]; then
2864 msg ' . The function fnmatch(3) could not be found.'
2865 msg ' Filename patterns like wildcard are not supported on your system'
2867 if [ -z "${have_fchdir}" ]; then
2868 msg ' . The function fchdir(2) could not be found.'
2869 msg ' We will use chdir(2) instead.'
2870 msg ' This is a problem only if the current working directory is changed'
2871 msg ' while this program is inside of it'