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 XXX sort this!
156 OPT_SSL_ALL_ALGORITHMS
=0
159 if feat_no SMTP
&& feat_no POP3
&& feat_no IMAP
; then
162 if feat_no SOCKETS
; then
163 if feat_require SMTP
; then
164 msg
'ERROR: need SOCKETS for required feature SMTP'
167 if feat_require POP3
; then
168 msg
'ERROR: need SOCKETS for required feature POP3'
171 if feat_require IMAP
; then
172 msg
'ERROR: need SOCKETS for required feature IMAP'
175 OPT_SSL
=0 OPT_SSL_ALL_ALGORITHMS
=0
176 OPT_SMTP
=0 OPT_POP3
=0 OPT_IMAP
=0
177 OPT_GSSAPI
=0 OPT_NETRC
=0 OPT_AGENT
=0
179 if feat_no SMTP
&& feat_no IMAP
; then
183 if feat_no ICONV
; then
184 if feat_yes IMAP
; then
185 if feat_require IMAP
; then
186 msg
'ERROR: need ICONV for required feature IMAP'
189 msg
'ERROR: disabling IMAP due to missing ICONV'
193 if feat_yes IDNA
; then
194 if feat_require IDNA
; then
195 msg
'ERROR: need ICONV for required feature IDNA'
198 msg
'ERROR: disabling IDNA due to missing ICONV'
204 OPT_HISTORY
=0 OPT_KEY_BINDINGS
=0
207 # If we don't need MD5 leave it alone
208 if feat_no SOCKETS
; then
212 if feat_no TERMCAP
; then
213 OPT_TERMCAP_VIA_TERMINFO
=0
216 if feat_yes DEVEL
; then
224 h
=.
/mk-config.h h_name
=mk-config.h
227 newlst
=.
/mk-nconfig.lst
228 newmk
=.
/mk-nconfig.mk
229 newev
=.
/mk-nconfig.ev
235 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
237 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
238 # via path_check() later on once possible
240 # TODO cc_maxopt is brute simple, we should compile test program and dig real
241 # compiler versions for known compilers, then be more specific
242 [ -n "${cc_maxopt}" ] || cc_maxopt
=100
246 # We don't "have any utility": only path adjustments and such in here!
247 [ -n "${OS}" ] || OS
=`uname -s`
250 if [ ${OS} = SunOS
]; then
251 msg
'SunOS / Solaris? Applying some "early setup" rules ...'
252 _os_early_setup_sunos
256 _os_early_setup_sunos
() {
257 # According to standards(5), this is what we need to do
258 if [ -d /usr
/xpg4
]; then :; else
259 msg
'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
262 PATH
="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
263 [ -d /usr
/xpg6
] && PATH
="/usr/xpg6/bin:${PATH}"
268 # OSENV ends up in *build-osenv*
269 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
270 OS
=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
271 [ -n "${OSENV}" ] || OSENV
=`uname -srm`
272 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC
=`uname -a`
273 msg
'Operating system is %s' ${OS}
275 if [ ${OS} = darwin
]; then
276 msg
' . have special Darwin environmental addons...'
277 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
278 elif [ ${OS} = sunos
]; then
279 msg
' . have special SunOS / Solaris "setup" rules ...'
281 elif [ ${OS} = unixware
]; then
282 if feat_yes AUTOCC
&& acmd_set CC cc
; then
283 msg
' . have special UnixWare environmental rules ...'
284 feat_yes DEBUG
&& _CFLAGS
='-v -Xa -g' || _CFLAGS
='-Xa -O'
286 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
287 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
288 export CC CFLAGS LDFLAGS
289 OPT_AUTOCC
=0 had_want_autocc
=1 need_R_ldflags
=-R
291 elif [ -n "${VERBOSE}" ]; then
292 msg
' . no special treatment for this system necessary or known'
295 # Sledgehammer: better set _GNU_SOURCE
296 # And in general: oh, boy!
297 OS_DEFINES
="${OS_DEFINES}#define _GNU_SOURCE\n"
298 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
299 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
300 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
302 # On pkgsrc(7) systems automatically add /usr/pkg/*
303 if [ -d /usr
/pkg
]; then
304 C_INCLUDE_PATH
=/usr
/pkg
/include
:${C_INCLUDE_PATH}
305 LD_LIBRARY_PATH
=/usr
/pkg
/lib
:${LD_LIBRARY_PATH}
310 C_INCLUDE_PATH
=/usr
/xpg
4/include
:${C_INCLUDE_PATH}
311 LD_LIBRARY_PATH
=/usr
/xpg
4/lib
:${LD_LIBRARY_PATH}
314 if [ -d /opt
/csw
]; then
315 C_INCLUDE_PATH
=/opt
/csw
/include
:${C_INCLUDE_PATH}
316 LD_LIBRARY_PATH
=/opt
/csw
/lib
:${LD_LIBRARY_PATH}
319 OS_DEFINES
="${OS_DEFINES}#define __EXTENSIONS__\n"
320 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
322 [ -n "${cksum}" ] ||
cksum=/opt
/csw
/gnu
/cksum
323 if [ -x "${cksum}" ]; then :; else
324 msg
'ERROR: Not an executable program: %s' "${cksum}"
325 msg
'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
326 msg
'ERROR: However, we do so only for tests.'
327 msg
'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
331 if feat_yes AUTOCC
; then
332 if acmd_set CC cc
; then
333 feat_yes DEBUG
&& _CFLAGS
="-v -Xa -g" || _CFLAGS
="-Xa -O"
335 CFLAGS
="${_CFLAGS} ${EXTRA_CFLAGS}"
336 LDFLAGS
="${_LDFLAGS} ${EXTRA_LDFLAGS}"
337 export CC CFLAGS LDFLAGS
338 OPT_AUTOCC
=0 had_want_autocc
=1 need_R_ldflags
=-R
340 cc_maxopt
=2 #force_no_stackprot=1
345 # Check out compiler ($CC) and -flags ($CFLAGS)
347 # Even though it belongs into cc_flags we will try to compile and link
348 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
349 # EXTRA_CFLAGS/EXTRA_LDFLAGS
350 if feat_no AUTOCC
; then
352 # Ensure those don't do any harm
353 EXTRA_CFLAGS
= EXTRA_LDFLAGS
=
354 export EXTRA_CFLAGS EXTRA_LDFLAGS
358 export CFLAGS LDFLAGS
361 [ -n "${CC}" ] && { _cc_default
; return; }
363 msg_nonl
'Searching for a usable C compiler .. $CC='
364 if acmd_set CC clang || acmd_set CC gcc ||
365 acmd_set CC tcc || acmd_set CC pcc ||
366 acmd_set CC c89 || acmd_set CC c99
; then
369 msg
'boing booom tschak'
370 msg
'ERROR: I cannot find a compiler!'
371 msg
' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
372 msg
' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
380 if [ -z "${CC}" ]; then
381 msg
'To go on like you have chosen, please set $CC, rerun.'
385 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG
; then
388 msg
'Using C compiler ${CC}=%s' "${CC}"
393 if feat_yes AUTOCC
; then
394 if [ -f ${lst} ] && feat_no DEBUG
&& [ -z "${VERBOSE}" ]; then
396 msg
'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
400 msg
'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
403 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
404 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
405 msg ' . have special tcc(1) environmental rules ...'
408 # As of pcc CVS 2016-04-02, stack protection support is announced but
409 # will break if used on Linux
410 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
416 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
417 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
418 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
420 if feat_no DEBUG; then
421 CFLAGS="-DNDEBUG ${CFLAGS}"
425 export CFLAGS LDFLAGS
429 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
436 if feat_yes DEBUG; then
437 # May have problems to find libtcc cc_check -b
441 if ld_check -Wl,-rpath =./ no; then
442 need_R_ldflags=-Wl,-rpath=
443 ld_check -Wl,--enable-new-dtags
444 ld_runtime_flags # update!
447 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
448 unset __cflags __ldflags
451 _cc_flags_generic() {
452 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
454 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
456 # E.g., valgrind does not work well with high optimization
457 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
458 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
459 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
462 # Check -g first since some others may rely upon -g / optim. level
463 if feat_yes DEBUG; then
466 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
468 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
470 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
476 if feat_yes AMALGAMATION; then
480 #if feat_yes DEVEL && cc_check -Weverything; then
485 cc_check -Wbad-function-cast
486 cc_check -Wcast-align
489 cc_check -Wmissing-prototypes
492 cc_check -Wwrite-strings
493 cc_check -Wno-long-long
497 if feat_yes AMALGAMATION && feat_no DEVEL; then
498 cc_check -Wno-unused-function
500 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
502 cc_check -fno-unwind-tables
503 cc_check -fno-asynchronous-unwind-tables
504 cc_check -fstrict-aliasing
505 if cc_check -fstrict-overflow && feat_yes DEVEL; then
506 cc_check -Wstrict-overflow=5
509 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
510 if [ -z "${force_no_stackprot}" ]; then
511 if cc_check -fstack-protector-strong ||
512 cc_check -fstack-protector-all; then
513 cc_check -D_FORTIFY_SOURCE=2
516 msg 'Not checking for -fstack-protector compiler option,'
517 msg 'since that caused errors in a "similar" configuration.'
518 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
522 # LD (+ dependend CC)
524 if feat_yes ASAN_ADDRESS; then
526 if cc_check -fsanitize=address &&
527 ld_check -fsanitize=address; then
530 feat_bail_required ASAN_ADDRESS
535 if feat_yes ASAN_MEMORY; then
537 if cc_check -fsanitize=memory &&
538 ld_check -fsanitize=memory &&
539 cc_check -fsanitize-memory-track-origins=2 &&
540 ld_check -fsanitize-memory-track-origins=2; then
543 feat_bail_required ASAN_MEMORY
548 ld_check -Wl,-z,relro
550 ld_check -Wl,-z,noexecstack
551 if ld_check -Wl,-rpath =./ no; then
552 need_R_ldflags=-Wl,-rpath=
553 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
554 ld_check -Wl,--enable-new-dtags
555 ld_runtime_flags # update!
556 elif ld_check -Wl,-R ./ no; then
557 need_R_ldflags=-Wl,-R
558 ld_check -Wl,--enable-new-dtags
559 ld_runtime_flags # update!
562 # Address randomization
564 if cc_check -fPIE || cc_check -fpie; then
565 ld_check -pie || _CFLAGS=${_ccfg}
569 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
570 unset __cflags __ldflags
573 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
576 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
577 ## redirection, so use "printf '' >" instead
579 ## Very first: we undergo several states regarding I/O redirection etc.,
580 ## but need to deal with option updates from within all. Since all the
581 ## option stuff should be above the scissor line, define utility functions
582 ## and redefine them as necessary.
583 ## And, since we have those functions, simply use them for whatever
585 t1=ten10one1ten10one1
586 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
587 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
588 ) > /dev/null 2>&1; then
595 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
601 # which(1) not standardized, command(1) -v may return non-executable: unroll!
602 acmd_test() { __acmd "${1}" 1 0 0; }
603 acmd_test_fail() { __acmd "${1}" 1 1 0; }
604 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
605 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
606 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
607 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
608 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
609 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
610 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
611 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
613 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
615 if [ "${dotest}" -ne 0 ]; then
616 eval dotest=\$${varname}
617 if [ -n "${dotest}" ]; then
618 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
619 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
625 [ -n "${noglob_shell}" ] && set -o noglob
627 [ -n "${noglob_shell}" ] && set +o noglob
631 if [ -z "${path}" ] || [ "${path}" = . ]; then
632 if [ -d "${PWD}" ]; then
638 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
639 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
640 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
641 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
646 # We may have no builtin string functions, we yet have no programs we can
647 # use, try to access once from the root, assuming it is an absolute path if
648 # that finds the executable
649 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
650 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
651 msg ' . ${%s} ... %s' "${pname}" "${pname}"
652 [ -n "${varname}" ] && eval ${varname}="${pname}"
656 [ ${dofail} -eq 0 ] && return 1
657 msg 'ERROR: no trace of utility '"${pname}"
664 printf >&2 -- "${fmt}\\n" "${@}"
670 printf >&2 -- "${fmt}" "${@}"
673 # Our feature check environment
675 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
676 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
680 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
681 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
682 [ "x${1}" = xrequire ]
686 [ "x${1}" = xrequire ]
691 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
692 if feat_val_no "${i}"; then
694 elif feat_val_yes "${i}"; then
697 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
708 _feat_check ${1} && return 1
714 i="`echo ${i} |
${tr} '[A-Z]' '[a-z]'`"
715 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
718 feat_bail_required() {
719 if feat_require ${1}; then
720 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
724 option_update # XXX this is rather useless here (dependency chain..)
728 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
729 # options, without documentation, to $1
731 i="`${awk} -v input
=\"${2}\" '
734 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
737 v = substr(input, voff, RLENGTH)
738 input = substr(input, voff + RLENGTH)
741 d = substr(v, doff + 2, length(v) - doff - 1)
742 v = substr(v, 1, doff - 1)
752 # Return the "documentation string" for option $1, itself if none such
754 ${awk} -v want="${1}" \
755 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
758 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
761 v = substr(input, voff, RLENGTH)
762 input = substr(input, voff + RLENGTH)
765 d = substr(v, doff + 2, length(v) - doff - 1)
766 v = substr(v, 1, doff - 1)
780 # Join the values from make.rc into what currently is defined, not
781 # overwriting yet existing settings
783 # We want read(1) to perform reverse solidus escaping in order to be able to
784 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
785 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
786 < ${rc} ${awk} 'BEGIN{line = ""}{
787 gsub(/^[[:space:]]+/, "", $0)
788 gsub(/[[:space:]]+$/, "", $0)
789 if(gsub(/\\$/, "", $0)){
794 if(index(line, "#") == 1){
796 }else if(length(line)){
802 if [ -n "${good_shell}" ]; then
805 i=`${awk} -v LINE
="${line}" 'BEGIN{
806 gsub(/=.*$/, "", LINE)
810 if [ "${i}" = "${line}" ]; then
811 msg 'ERROR: invalid syntax in: %s' "${line}"
815 eval j="\$${i}" jx="\${${i}+x}"
816 if [ -n "${j}" ] || [ "${jx}" = x ]; then
819 j=`${awk} -v LINE
="${line}" 'BEGIN{
820 gsub(/^[^=]*=/, "", LINE)
821 gsub(/^\"*/, "", LINE)
822 gsub(/\"*$/, "", LINE)
826 [ "${i}" = "DESTDIR" ] && continue
829 # Reread the mixed version right now
834 # Expand the option values, which may contain shell snippets
835 ${rm} -f ${newlst} ${newmk} ${newh}
836 exec 5<&0 6>&1 <${tmp} >${newlst}
839 if [ -n "${good_shell}" ]; then
841 [ "${i}" != "${i#OPT_}" ] && z=1
843 i=`${awk} -v LINE
="${line}" 'BEGIN{
844 gsub(/=.*$/, "", LINE);\
847 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
853 if [ -n "${z}" ]; then
854 j="`echo ${j} |
${tr} '[A-Z]' '[a-z]'`"
855 if [ -z "${j}" ] || feat_val_no "${j}"; then
857 printf " /* #undef ${i} */\n" >> ${newh}
858 elif feat_val_yes "${j}"; then
859 if feat_val_require "${j}"; then
864 printf " /* #define ${i} */\n" >> ${newh}
866 msg 'ERROR: cannot parse <%s>' "${line}"
870 printf "#define ${i} \"${j}\"\n" >> ${newh}
872 printf "${i} = ${j}\n" >> ${newmk}
876 exec 0<&5 1>&6 5<&- 6<&-
880 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
881 varname=${1} addflag=${2} flagvarname=${3}
884 [ -n "${noglob_shell}" ] && set -o noglob
886 [ -n "${noglob_shell}" ] && set +o noglob
891 [ -z "${i}" ] && continue
892 [ -d "${i}" ] || continue
893 if [ -n "${j}" ]; then
894 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
899 # But do not link any fakeroot path into our binaries!
900 if [ -n "${addflag}" ]; then
901 case "${i}" in *fakeroot*) continue;; esac
902 k="${k} ${addflag}${i}"
908 # But do not link any fakeroot path into our binaries!
909 if [ -n "${addflag}" ]; then
910 case "${i}" in *fakeroot*) continue;; esac
911 k="${k} ${addflag}${i}"
915 eval "${varname}=\"${j}\""
916 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
921 if [ -n "${need_R_ldflags}" ]; then
924 set -- ${LD_LIBRARY_PATH}
928 # But do not link any fakeroot path into our binaries!
929 case "${i}" in *fakeroot*) continue;; esac
930 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
931 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
935 # Disable it for a possible second run.
940 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
942 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
943 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
944 _CFLAGS="${_CFLAGS} ${1}"
945 [ -n "${cc_check_silent}" ] || msg 'yes'
948 [ -n "${cc_check_silent}" ] || msg 'no'
953 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
954 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
955 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
956 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
957 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
958 [ -n "${cc_check_silent}" ] || msg 'yes'
961 [ -n "${cc_check_silent}" ] || msg 'no'
967 variable=$1 topic=$2 define=$3
970 msg_nonl ' . %s ... ' "${topic}"
971 echo "/* checked ${topic} */" >> ${h}
972 ${rm} -f ${tmp} ${tmp}.o
973 if [ "${dump_test_program}" = 1 ]; then
974 echo '*** test program is'
975 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
977 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
979 #echo '*** the preprocessor generates'
980 #${make} -f ${makefile} ${tmp}.x
982 echo '*** tests results'
986 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
989 msg_nonl ' . %s ... ' "${topic}"
991 echo '*** enforced unchecked results are'
992 if feat_val_yes ${yesno}; then
993 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
994 echo "*** adding INCS<${incs}> LIBS<${libs}>"
995 LIBS="${LIBS} ${libs}"
996 echo "${libs}" >> ${lib}
997 INCS="${INCS} ${incs}"
998 echo "${incs}" >> ${inc}
1001 echo "${define}" >> ${h}
1002 eval have_${variable}=yes
1005 echo "/* ${define} */" >> ${h}
1007 eval unset have_${variable}
1013 variable=$1 topic=$2 define=$3
1015 _check_preface "${variable}" "${topic}" "${define}"
1017 if ${make} -f ${makefile} XINCS="${INCS}" \
1018 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1020 [ -f ./${tmp}.o ]; then
1022 echo "${define}" >> ${h}
1023 eval have_${variable}=yes
1026 echo "/* ${define} */" >> ${h}
1028 eval unset have_${variable}
1034 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1036 _check_preface "${variable}" "${topic}" "${define}"
1038 if feat_yes CROSS_BUILD; then
1039 if [ ${run} = 1 ]; then
1044 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1045 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1046 XLIBS="${LIBS} ${libs}" \
1049 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1050 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1052 echo "${define}" >> ${h}
1053 LIBS="${LIBS} ${libs}"
1054 echo "${libs}" >> ${lib}
1055 INCS="${INCS} ${incs}"
1056 echo "${incs}" >> ${inc}
1057 eval have_${variable}=yes
1061 echo "/* ${define} */" >> ${h}
1062 eval unset have_${variable}
1068 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1072 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1076 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1080 if feat_yes ${1}; then
1081 echo '#define HAVE_'${1}'' >> ${h}
1084 echo '/* OPT_'${1}'=0 */' >> ${h}
1090 < "${1}" > "${2}" ${awk} \
1091 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1094 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1096 # First of all, create new configuration and check whether it changed
1098 # Very easy checks for the operating system in order to be able to adjust paths
1099 # or similar very basic things which we need to be able to go at all
1102 # Check those tools right now that we need before including $rc
1103 msg 'Checking for basic utility set'
1104 thecmd_testandset_fail awk awk
1105 thecmd_testandset_fail rm rm
1106 thecmd_testandset_fail tr tr
1108 # Initialize the option set
1109 msg_nonl 'Setting up configuration options ... '
1113 # Include $rc, but only take from it what wasn't overwritten by the user from
1114 # within the command line or from a chosen fixed CONFIG=
1115 # Note we leave alone the values
1116 trap "exit 1" HUP INT TERM
1117 trap "${rm} -f ${tmp}" EXIT
1119 msg_nonl 'Joining in %s ... ' ${rc}
1123 # We need to know about that now, in order to provide utility overwrites etc.
1126 msg 'Checking for remaining set of utilities'
1127 thecmd_testandset_fail grep grep
1129 # Before we step ahead with the other utilities perform a path cleanup first.
1133 thecmd_testandset_fail basename basename
1134 thecmd_testandset_fail cat cat
1135 thecmd_testandset_fail chmod chmod
1136 thecmd_testandset_fail cp cp
1137 thecmd_testandset_fail cmp cmp
1139 thecmd_testandset_fail mkdir mkdir
1140 thecmd_testandset_fail mv mv
1142 thecmd_testandset_fail sed sed
1143 thecmd_testandset_fail sort sort
1144 thecmd_testandset_fail tee tee
1146 thecmd_testandset chown chown ||
1147 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1148 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1150 thecmd_testandset_fail MAKE make
1153 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1155 # For ./cc-test.sh only
1156 thecmd_testandset_fail cksum cksum
1158 # Update OPT_ options now, in order to get possible inter-dependencies right
1161 # (No functions since some shells loose non-exported variables in traps)
1162 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1163 trap "trap \"\" HUP INT TERM EXIT;\
1164 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1166 # Our configuration options may at this point still contain shell snippets,
1167 # we need to evaluate them in order to get them expanded, and we need those
1168 # evaluated values not only in our new configuration file, but also at hand..
1169 msg_nonl 'Evaluating all configuration items ... '
1173 # Add the known utility and some other variables
1174 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1175 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1177 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1178 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1179 if feat_yes DOTLOCK; then
1180 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1182 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1187 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1188 MAKE MAKEFLAGS make SHELL strip \
1191 printf "${i} = ${j}\n" >> ${newmk}
1192 printf "${i}=${j}\n" >> ${newlst}
1193 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1195 printf "\n" >> ${newev}
1197 # Build a basic set of INCS and LIBS according to user environment.
1198 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1199 path_check C_INCLUDE_PATH -I _INCS
1200 INCS="${INCS} ${_INCS}"
1201 path_check LD_LIBRARY_PATH -L _LIBS
1202 LIBS="${LIBS} ${_LIBS}"
1204 export C_INCLUDE_PATH LD_LIBRARY_PATH
1206 # Some environments need runtime path flags to be able to go at all
1209 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1213 ${cat} > ${tmp}.c << \!
1216 static void doit(char const *s);
1218 main(int argc, char **argv){
1221 doit("Hello world");
1225 doit(char const *s){
1227 memcpy(buf, s, strlen(s) +1);
1232 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1233 -o ${tmp2} ${tmp}.c ${LIBS}; then
1236 msg 'ERROR: i cannot compile a "Hello world" via'
1238 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1239 msg 'ERROR: Please read INSTALL, rerun'
1243 # This may also update ld_runtime_flags() (again)
1250 printf -- "${i}=${j}\n" >> ${newlst}
1256 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1260 printf -- "${i} = ${j}\n" >> ${newmk}
1261 printf -- "${i}=${j}\n" >> ${newlst}
1264 # Now finally check whether we already have a configuration and if so, whether
1265 # all those parameters are still the same.. or something has actually changed
1266 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1267 echo 'Configuration is up-to-date'
1269 elif [ -f ${lst} ]; then
1270 echo 'Configuration has been updated..'
1271 ( eval "${MAKE} -f ./mk-config.mk clean" )
1274 echo 'Shiny configuration..'
1277 # Time to redefine helper 1
1279 ${rm} -f ${lst} ${h} ${mk}
1283 ${mv} -f ${newlst} ${lst}
1284 ${mv} -f ${newev} ${ev}
1285 ${mv} -f ${newh} ${h}
1286 ${mv} -f ${newmk} ${mk}
1288 if [ -z "${VERBOSE}" ]; then
1289 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1290 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1291 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1292 printf -- "ECHO_TEST = @\n" >> ${mk}
1293 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1294 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1295 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1298 ## Compile and link checking
1304 makefile=./${tmp0}.mk
1306 # (No function since some shells loose non-exported variables in traps)
1307 trap "trap \"\" HUP INT TERM;\
1308 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1309 trap "trap \"\" HUP INT TERM EXIT;\
1310 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1312 # Time to redefine helper 2
1316 printf "*** ${fmt}\\n" "${@}"
1317 printf -- "${fmt}\\n" "${@}" >&5
1322 printf "*** ${fmt}\\n" "${@}"
1323 printf -- "${fmt}" "${@}" >&5
1327 exec 5>&2 > ${log} 2>&1
1329 echo "${LIBS}" > ${lib}
1330 echo "${INCS}" > ${inc}
1331 ${cat} > ${makefile} << \!
1332 .SUFFIXES: .o .c .x .y
1334 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1336 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1338 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1343 # May be multiline..
1345 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1346 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1347 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1349 # Generate n_err_number OS mappings
1352 feat_yes DEVEL && NV= || NV=noverbose
1353 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1354 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1355 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1358 feat_def ALWAYS_UNICODE_LOCALE
1359 feat_def AMALGAMATION
1360 feat_def CROSS_BUILD
1364 feat_def ASAN_ADDRESS
1365 feat_def ASAN_MEMORY
1371 if xrun_check inline 'inline functions' \
1372 '#define HAVE_INLINE
1373 #define n_INLINE static inline' << \!
1374 static inline int ilf(int i){return ++i;}
1375 int main(void){return ilf(-1);}
1379 elif xrun_check inline 'inline functions (via __inline)' \
1380 '#define HAVE_INLINE
1381 #define n_INLINE static __inline' << \!
1382 static __inline int ilf(int i){return ++i;}
1383 int main(void){return ilf(-1);}
1389 ## Test for "basic" system-calls / functionality that is used by all parts
1390 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1391 ## macros to be used by only the subprograms (potentially).
1393 if run_check clock_gettime 'clock_gettime(2)' \
1394 '#define HAVE_CLOCK_GETTIME' << \!
1400 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1407 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1408 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1414 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1421 elif run_check gettimeofday 'gettimeofday(2)' \
1422 '#define HAVE_GETTIMEOFDAY' << \!
1423 #include <stdio.h> /* For C89 NULL */
1424 #include <sys/time.h>
1429 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1437 have_no_subsecond_time=1
1440 if run_check nanosleep 'nanosleep(2)' \
1441 '#define HAVE_NANOSLEEP' << \!
1448 ts.tv_nsec = 100000;
1449 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1456 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1457 '#define HAVE_NANOSLEEP' '-lrt' << \!
1464 ts.tv_nsec = 100000;
1465 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1472 # link_check is enough for this, that function is so old, trust the proto
1473 elif link_check sleep 'sleep(3)' \
1474 '#define HAVE_SLEEP' << \!
1478 if(!sleep(1) || errno != ENOSYS)
1486 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1490 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1499 if((gid = getgid()) != 0)
1501 if((uid = getuid()) != 0)
1503 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1505 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1513 msg 'ERROR: we require user and group info / database searches.'
1514 msg 'That much Unix we indulge ourselfs.'
1518 if link_check ftruncate 'ftruncate(2)' \
1519 '#define HAVE_FTRUNCATE' << \!
1521 #include <sys/types.h>
1523 return (ftruncate(0, 0) != 0);
1529 msg 'ERROR: we require the ftruncate(2) system call.'
1533 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1537 struct sigaction nact, oact;
1539 nact.sa_handler = SIG_DFL;
1540 sigemptyset(&nact.sa_mask);
1541 nact.sa_flags = SA_RESTART;
1542 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1548 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1552 if link_check snprintf 'snprintf(3)' << \!
1557 snprintf(b, sizeof b, "%s", "string");
1564 msg 'ERROR: we require the snprintf(3) function.'
1568 if link_check environ 'environ(3)' << \!
1569 #include <stdio.h> /* For C89 NULL */
1571 extern char **environ;
1573 return environ[0] == NULL;
1579 msg 'ERROR: we require the environ(3) array for subprocess control.'
1583 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1586 setenv("s-mailx", "i want to see it cute!", 1);
1587 unsetenv("s-mailx");
1593 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1596 putenv("s-mailx=i want to see it cute!");
1603 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1607 if link_check termios 'termios.h and tc*(3) family' << \!
1608 #include <termios.h>
1610 struct termios tios;
1612 tcgetattr(0, &tios);
1613 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1620 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1621 msg 'That much Unix we indulge ourselfs.'
1627 if link_check vsnprintf 'vsnprintf(3)' << \!
1630 static void dome(char *buf, size_t blen, ...){
1634 vsnprintf(buf, blen, "%s", ap);
1640 dome(b, sizeof b, "string");
1647 feat_bail_required ERRORS
1650 if [ "${have_vsnprintf}" = yes ]; then
1652 link_check va_copy "va_copy(3) (as ${2})" \
1653 "#define HAVE_N_VA_COPY
1654 #define n_va_copy ${2}" <<_EOT
1658 # if defined __va_copy && !defined va_copy
1659 # define va_copy __va_copy
1662 static void dome2(char *buf, size_t blen, va_list src){
1666 vsnprintf(buf, blen, "%s", ap);
1669 static void dome(char *buf, size_t blen, ...){
1673 dome2(buf, blen, ap);
1679 dome(b, sizeof b, "string");
1684 __va_copy 0 va_copy || __va_copy 1 __va_copy
1687 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1694 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1696 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1698 /* Only link check */
1699 fpathconf(0, _PC_NAME_MAX);
1705 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1712 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1718 # We use this only then for now (need NOW+1)
1719 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1720 #include <fcntl.h> /* For AT_* */
1721 #include <sys/stat.h>
1724 struct timespec ts[2];
1726 ts[0].tv_nsec = UTIME_NOW;
1727 ts[1].tv_nsec = UTIME_OMIT;
1728 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1736 # XXX Add POSIX check once standardized
1737 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1746 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1747 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1748 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1749 #include <sys/random.h>
1752 getrandom(buf, sizeof buf, 0);
1758 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1759 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1760 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1761 #include <sys/syscall.h>
1764 syscall(SYS_getrandom, buf, sizeof buf, 0);
1770 elif [ -n "${have_no_subsecond_time}" ]; then
1771 msg 'ERROR: %s %s' 'without a native random' \
1772 'one of clock_gettime(2) and gettimeofday(2) is required.'
1777 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1780 putc_unlocked('@', stdout);
1785 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1793 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1796 char x_buf[4096], *x = realpath(".", x_buf);
1798 return (x != NULL) ? 0 : 1;
1802 if run_check realpath_malloc 'realpath(3) takes NULL' \
1803 '#define HAVE_REALPATH_NULL' << \!
1806 char *x = realpath(".", NULL);
1810 return (x != NULL) ? 0 : 1;
1818 ## optional and selectable
1820 if feat_yes DOTLOCK; then
1821 if run_check readlink 'readlink(2)' << \!
1827 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1835 feat_bail_required DOTLOCK
1839 if feat_yes DOTLOCK; then
1840 if run_check fchown 'fchown(2)' << \!
1844 if(!fchown(0, 0, 0) || errno != ENOSYS)
1852 feat_bail_required DOTLOCK
1856 ## Now it is the time to fork away the BASE_ series
1859 squeeze_em ${inc} ${tmp}
1861 squeeze_em ${lib} ${tmp}
1864 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1865 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1867 ## The remains are expected to be used only by the main MUA binary!
1870 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1873 setlocale(LC_ALL, "");
1877 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1879 OPT_MULTIBYTE_CHARSETS=0
1881 OPT_TERMINAL_CHARSET=0
1882 if [ -n "${have_setlocale}" ]; then
1883 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1884 '#define HAVE_C90AMEND1' << \!
1890 char mbb[MB_LEN_MAX + 1];
1895 mbtowc(&wc, "x
", 1);
1896 mbrtowc(&wc, "x
", 1, NULL);
1898 return (mblen("\
0", 1) == 0);
1901 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1903 if [ -n "${have_c90amend1}" ]; then
1904 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1911 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1914 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1915 #include <langinfo.h>
1919 return (nl_langinfo(CODESET) == NULL);
1922 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1925 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1926 #include <fnmatch.h>
1928 return (fnmatch("*", ".
", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1932 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1936 return !(de.d_type == DT_UNKNOWN ||
1937 de.d_type == DT_DIR || de.d_type == DT_LNK);
1941 ## optional and selectable
1943 if feat_yes ICONV; then
1944 ${cat} > ${tmp2}.c << \!
1945 #include <stdio.h> /* For C89 NULL */
1950 id = iconv_open("foo
", "bar
");
1951 iconv(id, NULL, NULL, NULL, NULL);
1956 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1957 '#define HAVE_ICONV' ||
1958 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1959 '#define HAVE_ICONV' '-liconv' ||
1960 feat_bail_required ICONV
1962 echo '/* OPT_ICONV=0 */' >> ${h}
1965 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1966 ${cat} > ${tmp2}.c << \!
1967 #include <sys/types.h>
1968 #include <sys/socket.h>
1972 struct sockaddr_un soun;
1974 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1976 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1978 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1984 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1985 '#define HAVE_UNIX_SOCKETS' ||
1986 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1987 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1988 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1989 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1992 if feat_yes SOCKETS; then
1993 ${cat} > ${tmp2}.c << \!
1994 #include <sys/types.h>
1995 #include <sys/socket.h>
1996 #include <netinet/in.h>
2001 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2003 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2009 < ${tmp2}.c run_check sockets 'sockets' \
2010 '#define HAVE_SOCKETS' ||
2011 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2012 '#define HAVE_SOCKETS' '-lnsl' ||
2013 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2014 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2015 feat_bail_required SOCKETS
2017 echo '/* OPT_SOCKETS=0 */' >> ${h}
2018 fi # feat_yes SOCKETS
2020 if feat_yes SOCKETS; then
2021 link_check getaddrinfo 'getaddrinfo(3)' \
2022 '#define HAVE_GETADDRINFO' << \!
2023 #include <sys/types.h>
2024 #include <sys/socket.h>
2028 struct addrinfo a, *ap;
2031 switch((lrv = getaddrinfo("foo
", "0", &a, &ap))){
2035 fprintf(stderr, "%s
\n", gai_strerror(lrv));
2044 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2045 compile_check arpa_inet_h '<arpa/inet.h>' \
2046 '#define HAVE_ARPA_INET_H' << \!
2047 #include <sys/types.h>
2048 #include <sys/socket.h>
2050 #include <netinet/in.h>
2051 #include <arpa/inet.h>
2054 ${cat} > ${tmp2}.c << \!
2055 #include <sys/types.h>
2056 #include <sys/socket.h>
2060 #include <netinet/in.h>
2061 #ifdef HAVE_ARPA_INET_H
2062 #include <arpa/inet.h>
2065 struct sockaddr_in servaddr;
2066 unsigned short portno;
2069 struct in_addr **pptr;
2072 if((ep = getservbyname("POPPY-PORT
", "tcp
")) != NULL)
2073 portno = (unsigned short)ep->s_port;
2075 if((hp = gethostbyname("POPPY-HOST
")) != NULL){
2076 pptr = (struct in_addr**)hp->h_addr_list;
2077 if(hp->h_addrtype != AF_INET)
2078 fprintf(stderr, "au
\n");
2081 case HOST_NOT_FOUND:
2087 fprintf(stderr, "au
\n");
2092 memset(&servaddr, 0, sizeof servaddr);
2093 servaddr.sin_family = AF_INET;
2094 servaddr.sin_port = htons(portno);
2095 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2096 fprintf(stderr, "Would connect to
%s
:%d ...
\n",
2097 inet_ntoa(**pptr), (int)portno);
2102 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2103 < ${tmp2}.c link_check gethostbyname \
2104 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2105 < ${tmp2}.c link_check gethostbyname \
2106 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2107 '' '-lsocket -lnsl' ||
2108 feat_bail_required SOCKETS
2112 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2113 #include <sys/socket.h>
2119 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2126 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2127 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2128 #include <sys/socket.h>
2136 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2137 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2142 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2143 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2144 #include <sys/socket.h>
2152 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2158 if feat_yes SSL; then # {{{
2159 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2160 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2161 # time: we need to test it first in order to get things right
2162 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2165 #define HAVE_XSSL_RESSL
2166 #define HAVE_XSSL_OPENSSL 0' << \!
2167 #include <openssl/opensslv.h>
2168 #ifdef LIBRESSL_VERSION_NUMBER
2175 VAL_SSL_FEATURES=libressl
2176 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2177 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2180 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2181 #include <openssl/opensslv.h>
2182 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2189 VAL_SSL_FEATURES=libssl-0x10100
2190 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2193 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2194 #include <openssl/opensslv.h>
2195 #ifdef OPENSSL_VERSION_NUMBER
2202 VAL_SSL_FEATURES=libssl-0x10000
2204 feat_bail_required SSL
2207 if feat_yes SSL; then # {{{
2208 if [ -n "${ossl_v1_1}" ]; then
2209 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2210 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2212 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2213 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2214 '-lssl -lcrypto' << \!
2215 #include <openssl/ssl.h>
2216 #include <openssl/err.h>
2217 #include <openssl/x509v3.h>
2218 #include <openssl/x509.h>
2219 #include <openssl/rand.h>
2220 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2221 # error We need TLSv1.
2224 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2227 PEM_read_PrivateKey(0, 0, 0, 0);
2233 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2234 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2235 '-lssl -lcrypto' << \!
2236 #include <openssl/ssl.h>
2237 #include <openssl/err.h>
2238 #include <openssl/x509v3.h>
2239 #include <openssl/x509.h>
2240 #include <openssl/rand.h>
2241 #if defined OPENSSL_NO_SSL3 &&\
2242 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2243 # error We need one of SSLv3 and TLSv1.
2246 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2249 PEM_read_PrivateKey(0, 0, 0, 0);
2256 feat_bail_required SSL
2260 if feat_yes SSL; then # {{{
2261 if feat_yes SSL_ALL_ALGORITHMS; then
2262 if [ -n "${ossl_v1_1}" ]; then
2263 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2264 '#define HAVE_SSL_ALL_ALGORITHMS'
2265 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2266 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2267 #include <openssl/evp.h>
2269 OpenSSL_add_all_algorithms();
2270 EVP_get_cipherbyname("two cents i never exist
");
2278 feat_bail_required SSL_ALL_ALGORITHMS
2280 elif [ -n "${ossl_v1_1}" ]; then
2281 without_check yes ssl_all_algo \
2282 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2283 '#define HAVE_SSL_ALL_ALGORITHMS'
2286 if [ -n "${ossl_v1_1}" ]; then
2287 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2288 '#define HAVE_XSSL_STACK_OF'
2289 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2290 '#define HAVE_XSSL_STACK_OF' << \!
2291 #include <stdio.h> /* For C89 NULL */
2292 #include <openssl/ssl.h>
2293 #include <openssl/err.h>
2294 #include <openssl/x509v3.h>
2295 #include <openssl/x509.h>
2296 #include <openssl/rand.h>
2298 STACK_OF(GENERAL_NAME) *gens = NULL;
2300 printf("%p
", gens); /* to use it */
2308 if [ -n "${ossl_v1_1}" ]; then
2309 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2310 '#define HAVE_XSSL_CONFIG'
2311 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2312 elif link_check xssl_conf \
2313 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2314 '#define HAVE_XSSL_CONFIG' << \!
2315 #include <stdio.h> /* For C89 NULL */
2316 #include <openssl/conf.h>
2318 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2319 CONF_modules_free();
2324 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file
"
2326 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2329 if [ -n "${ossl_v1_1}" ]; then
2330 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2331 '#define HAVE_XSSL_CONF_CTX'
2332 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2333 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2334 '#define HAVE_XSSL_CONF_CTX' << \!
2335 #include <openssl/ssl.h>
2336 #include <openssl/err.h>
2338 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2339 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2341 SSL_CONF_CTX_set_flags(cctx,
2342 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2343 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2344 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2345 SSL_CONF_cmd(cctx, "Protocol
", "ALL
");
2346 SSL_CONF_CTX_finish(cctx);
2347 SSL_CONF_CTX_free(cctx);
2353 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx
"
2355 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2358 if [ -n "${ossl_v1_1}" ]; then
2359 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2360 '#define HAVE_XSSL_CTX_CONFIG'
2361 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2362 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2363 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2364 '#define HAVE_XSSL_CTX_CONFIG' << \!
2365 #include <stdio.h> /* For C89 NULL */
2366 #include <openssl/ssl.h>
2368 SSL_CTX_config(NULL, "SOMEVAL
");
2373 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config
"
2375 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2378 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2379 without_check yes xssl_set_maxmin_proto \
2380 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2381 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2382 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2383 elif link_check xssl_set_maxmin_proto \
2384 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2385 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2386 #include <stdio.h> /* For C89 NULL */
2387 #include <openssl/ssl.h>
2389 SSL_CTX_set_min_proto_version(NULL, 0);
2390 SSL_CTX_set_max_proto_version(NULL, 10);
2395 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto
"
2397 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2400 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2401 '#define HAVE_XSSL_RAND_EGD' << \!
2402 #include <openssl/rand.h>
2404 return RAND_egd("some.where
") > 0;
2408 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd
"
2410 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2412 fi # feat_yes SSL }}}
2414 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2415 run_check ssl_md5 'MD5 digest in the used crypto library' \
2416 '#define HAVE_XSSL_MD5' << \!
2419 #include <openssl/md5.h>
2421 char const dat[] = "abrakadabrafidibus
";
2422 char dig[16], hex[16 * 2];
2426 memset(dig, 0, sizeof(dig));
2427 memset(hex, 0, sizeof(hex));
2429 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2430 MD5_Final(dig, &ctx);
2432 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2433 for(i = 0; i < sizeof(hex) / 2; i++){
2435 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2436 hex[++j] = hexchar(dig[i] & 0x0f);
2438 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326
", hex, sizeof(hex));
2443 echo '/* OPT_SSL=0 */' >> ${h}
2444 fi # }}} feat_yes SSL
2445 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2447 if [ "${have_xssl}" = yes ]; then
2458 if feat_yes GSSAPI
; then
2459 ${cat} > ${tmp2}.c
<< \
!
2460 #include <gssapi/gssapi.h>
2462 gss_import_name
(0, 0, GSS_C_NT_HOSTBASED_SERVICE
, 0);
2463 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2467 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2469 if acmd_set i krb5-config
; then
2470 GSS_LIBS
="`CFLAGS= ${i} --libs gssapi`"
2471 GSS_INCS
="`CFLAGS= ${i} --cflags`"
2472 i
='GSS-API via krb5-config(1)'
2476 i
='GSS-API in gssapi/gssapi.h, libgssapi'
2478 if < ${tmp2}.c link_check gss \
2479 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2480 < ${tmp3}.c link_check gss \
2481 'GSS-API in gssapi.h, libgssapi' \
2482 '#define HAVE_GSSAPI
2483 #define GSSAPI_REG_INCLUDE' \
2485 < ${tmp2}.c link_check gss
'GSS-API in libgssapi_krb5' \
2486 '#define HAVE_GSSAPI' \
2488 < ${tmp3}.c link_check gss \
2489 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2490 '#define HAVE_GSSAPI
2491 #define GSS_REG_INCLUDE' \
2492 '-lgssapi -lkrb5 -lcrypto' \
2493 '-I/usr/include/kerberosV' ||\
2494 < ${tmp2}.c link_check gss
'GSS-API in libgss' \
2495 '#define HAVE_GSSAPI' \
2497 link_check gss
'GSS-API in libgssapi_krb5, old-style' \
2498 '#define HAVE_GSSAPI
2499 #define GSSAPI_OLD_STYLE' \
2500 '-lgssapi_krb5' << \
!
2501 #include <gssapi/gssapi.h>
2502 #include <gssapi/gssapi_generic.h>
2504 gss_import_name
(0, 0, gss_nt_service_name
, 0);
2505 gss_init_sec_context
(0,0,0,0,0,0,0,0,0,0,0,0,0);
2512 feat_bail_required GSSAPI
2515 echo '/* OPT_GSSAPI=0 */' >> ${h}
2516 fi # feat_yes GSSAPI
2521 if feat_yes IDNA
; then
2522 if link_check idna
'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2525 #include <idn-free.h>
2526 #include <stringprep.h>
2528 char
*utf8
, *idna_ascii
, *idna_utf8
;
2530 utf8
= stringprep_locale_to_utf8
("does.this.work");
2531 if (idna_to_ascii_8z
(utf8
, &idna_ascii
, IDNA_USE_STD3_ASCII_RULES
)
2534 idn_free
(idna_ascii
);
2535 /* (Rather link check only here
) */
2536 idna_utf8
= stringprep_convert
(idna_ascii
, "UTF-8", "de_DE");
2542 elif link_check idna
'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2545 #include <idn/api.h>
2546 #include <idn/result.h>
2550 char local_name
[256];
2552 r
= idn_encodename
(IDN_ENCODE_APP
, "does.this.work", ace_name
,
2554 if (r
!= idn_success
) {
2555 fprintf
(stderr
, "idn_encodename failed: %s\n", idn_result_tostring
(r
));
2558 r
= idn_decodename
(IDN_DECODE_APP
, ace_name
, local_name
, sizeof
(local_name
));
2559 if (r
!= idn_success
) {
2560 fprintf
(stderr
, "idn_decodename failed: %s\n", idn_result_tostring
(r
));
2569 feat_bail_required IDNA
2572 if [ -n "${have_idna}" ]; then
2573 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2574 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2577 echo '/* OPT_IDNA=0 */' >> ${h}
2580 feat_def IMAP_SEARCH
2582 if feat_yes REGEX
; then
2583 if link_check regex
'regular expressions' '#define HAVE_REGEX' << \
!
2591 status
= regcomp
(&re
, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB
);
2592 xret
= regerror
(status
, &re
, NULL
, 0);
2593 status
= regexec
(&re
, "plan9", 0,NULL
, 0);
2595 return !(status
== REG_NOMATCH
);
2601 feat_bail_required REGEX
2604 echo '/* OPT_REGEX=0 */' >> ${h}
2607 if feat_yes MLE
&& [ -n "${have_c90amend1}" ]; then
2609 echo '#define HAVE_MLE' >> ${h}
2611 feat_bail_required MLE
2612 echo '/* OPT_MLE=0 */' >> ${h}
2615 # Generic have-a-line-editor switch for those who need it below
2616 if [ -n "${have_mle}" ]; then
2620 if [ -n "${have_cle}" ] && feat_yes HISTORY
; then
2621 echo '#define HAVE_HISTORY' >> ${h}
2623 echo '/* OPT_HISTORY=0 */' >> ${h}
2626 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS
; then
2627 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2629 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2632 if feat_yes TERMCAP
; then
2634 link_check termcap
"termcap(5) (via ${4})" \
2635 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2640 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2641 static int my_putc(int c){return putchar(c);}
2643 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2644 int r2 = OK, r3 = ERR;
2646 tgetent(buf, getenv("TERM"));
2648 r1 = tgetstr(UNCONST("cm"), &cpb);
2650 r2 = tgetnum(UNCONST("Co"));
2651 r3 = tgetflag(UNCONST("ut"));
2652 tputs("cr", 1, &my_putc);
2653 return (r1 == NULL || r2 == -1 || r3 == 0);
2659 link_check terminfo
"terminfo(5) (via ${2})" \
2660 '#define HAVE_TERMCAP
2661 #define HAVE_TERMCAP_CURSES
2662 #define HAVE_TERMINFO' "${1}" << _EOT
2666 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2667 static int my_putc(int c){return putchar(c);}
2673 r0 = setupterm(NULL, 1, &er);
2674 r1 = tigetflag(UNCONST("bce"));
2675 r2 = tigetnum(UNCONST("colors"));
2676 r3 = tigetstr(UNCONST("cr"));
2677 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2678 tputs(tp, 1, &my_putc);
2679 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2680 r3 == (char*)-1 || r3 == NULL);
2685 if feat_yes TERMCAP_VIA_TERMINFO
; then
2686 __terminfolib
-ltinfo -ltinfo ||
2687 __terminfolib
-lcurses -lcurses ||
2688 __terminfolib
-lcursesw -lcursesw ||
2689 feat_bail_required TERMCAP_VIA_TERMINFO
2692 if [ -z "${have_terminfo}" ]; then
2693 __termcaplib
-ltermcap '' '' '-ltermcap' ||
2694 __termcaplib
-ltermcap '#include <curses.h>' '
2695 #define HAVE_TERMCAP_CURSES' \
2696 'curses.h / -ltermcap' ||
2697 __termcaplib
-lcurses '#include <curses.h>' '
2698 #define HAVE_TERMCAP_CURSES' \
2699 'curses.h / -lcurses' ||
2700 __termcaplib
-lcursesw '#include <curses.h>' '
2701 #define HAVE_TERMCAP_CURSES' \
2702 'curses.h / -lcursesw' ||
2703 feat_bail_required TERMCAP
2705 if [ -n "${have_termcap}" ]; then
2706 run_check tgetent_null \
2707 "tgetent(3) of termcap(5) takes NULL buffer" \
2708 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2709 #include <stdio.h> /* For C89 NULL */
2711 #ifdef HAVE_TERMCAP_CURSES
2712 # include <curses.h>
2716 tgetent(NULL, getenv("TERM"));
2723 echo '/* OPT_TERMCAP=0 */' >> ${h}
2724 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2727 if feat_def SPAM_SPAMC
; then
2728 if acmd_set i spamc
; then
2729 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2733 if feat_yes SPAM_SPAMD
&& [ -n "${have_af_unix}" ]; then
2734 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2736 feat_bail_required SPAM_SPAMD
2737 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2740 feat_def SPAM_FILTER
2742 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER
; then
2743 echo '#define HAVE_SPAM' >> ${h}
2745 echo '/* HAVE_SPAM */' >> ${h}
2748 if feat_yes QUOTE_FOLD
&&\
2749 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2750 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2752 feat_bail_required QUOTE_FOLD
2753 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2756 feat_def FILTER_HTML_TAGSOUP
2765 squeeze_em
${inc} ${tmp}
2767 squeeze_em
${lib} ${tmp}
2772 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2773 ${cat} ${tmp} >> ${h}
2777 # Create the string that is used by *features* and `version'.
2778 # Take this nice opportunity and generate a visual listing of included and
2779 # non-included features for the person who runs the configuration
2780 msg
'\nThe following features are included (+) or not (-):'
2781 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2782 printf '/* The "feature string" */\n' >> ${h}
2783 # Because + is expanded by *folder* if first in "echo $features", put something
2784 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2788 sdoc
=`option_doc_of ${opt}`
2789 [ -z "${sdoc}" ] && continue
2790 sopt
="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2791 feat_yes
${opt} && sign
=+ || sign
=-
2792 printf -- "${sep}${sign}${sopt}" >> ${h}
2794 msg " %s
%s
: %s
" ${sign} ${sopt} "${sdoc}"
2796 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2798 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2799 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2800 printf '"\n' >> ${h}
2802 # Create the real mk-config.mk
2803 # Note we cannout use explicit ./ filename prefix for source and object
2804 # pathnames because of a bug in bmake(1)
2805 ${rm} -rf ${tmp0}.* ${tmp0}*
2807 if feat_no AMALGAMATION
; then
2808 for i
in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2809 i
=`basename "${i}" .c`
2810 if [ "${i}" = privsep
]; then
2813 objlist
="${objlist} ${i}.o"
2814 srclist
="${srclist} \$(SRCDIR)${i}.c"
2815 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2816 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2818 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2820 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2821 "main.o
" "main.c
" >> ${mk}
2822 srclist=main.c objlist=main.o
2823 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2825 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2826 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2827 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2828 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2829 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2831 if [ "${i}" = main.c ] ||
2832 [ "${i}" = privsep.c ]; then
2835 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2836 printf '# include "%s
%s
"\n' "${SRCDIR}" "${i}" >> ${h}
2840 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2842 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2844 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2845 echo "INCS
= `${cat} ${inc}`" >> ${mk}
2847 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2852 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2853 msg ' . bindir: %s' "${VAL_BINDIR}"
2854 if feat_yes DOTLOCK; then
2855 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2857 msg ' . mandir: %s' "${VAL_MANDIR}"
2858 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2859 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2862 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2866 if [ -z "${have_fnmatch}" ]; then
2867 msg ' . The function fnmatch(3) could not be found.'
2868 msg ' Filename patterns like wildcard are not supported on your system'
2870 if [ -z "${have_fchdir}" ]; then
2871 msg ' . The function fchdir(2) could not be found.'
2872 msg ' We will use chdir(2) instead.'
2873 msg ' This is a problem only if the current working directory is changed'
2874 msg ' while this program is inside of it'