Improve *smtp* obsoletion warning
[s-mailx.git] / make-config.sh
blob04816bd5ffe0e4ed67ba1ae01dca26baea43cfed
1 #!/bin/sh -
2 #@ Please see INSTALL and make.rc instead.
4 LC_ALL=C
5 export LC_ALL
7 # The feature set, to be kept in sync with make.rc
8 # If no documentation given, the option is used as such; if doc is a hyphen,
9 # entry is suppressed when configuration overview is printed, and also in the
10 # *features* string: most likely for obsolete features etc.
11 XOPTIONS="\
12 ICONV='Character set conversion using iconv(3)' \
13 SOCKETS='Network support' \
14 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
15 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
16 SMTP='Simple Mail Transfer Protocol client' \
17 POP3='Post Office Protocol Version 3 client' \
18 IMAP='IMAP v4r1 client' \
19 GSSAPI='Generic Security Service authentication' \
20 NETRC='.netrc file support' \
21 AGENT='-' \
22 MD5='MD5 message digest (APOP, CRAM-MD5)' \
23 IDNA='Internationalized Domain Names for Applications (encode only)' \
24 IMAP_SEARCH='IMAP-style search expressions' \
25 REGEX='Regular expressions' \
26 MLE='Mailx Line Editor' \
27 HISTORY='Line editor history management' \
28 KEY_BINDINGS='Configurable key bindings' \
29 TERMCAP='Terminal capability queries (termcap(5))' \
30 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
31 ERRORS='Error log message ring' \
32 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
33 SPAM_SPAMD='-' \
34 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
35 DOCSTRINGS='Command documentation help strings' \
36 QUOTE_FOLD='Extended *quote-fold*ing' \
37 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
38 COLOUR='Coloured message display' \
39 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
42 # Options which are automatically deduced from host environment, i.e., these
43 # need special treatment all around here to warp from/to OPT_ stuff
44 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
45 XOPTIONS_DETECT="\
46 LOCALES='Locale support - printable characters etc. depend on environment' \
47 MULTIBYTE_CHARSETS='Multibyte character sets' \
48 TERMINAL_CHARSET='Automatic detection of terminal character set' \
49 WIDE_GLYPHS='Wide glyph support' \
52 # Rather special options, for custom building, or which always exist.
53 # Mostly for generating the visual overview and the *features* string
54 XOPTIONS_XTRA="\
55 MIME='Multipurpose Internet Mail Extensions' \
56 SMIME='S/MIME message signing, verification, en- and decryption' \
57 CROSS_BUILD='Cross-compilation: trust any detected environment' \
58 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
59 DEVEL='Computers do not blunder' \
62 # The problem is that we don't have any tools we can use right now, so
63 # encapsulate stuff in functions which get called in right order later on
65 option_reset() {
66 set -- ${OPTIONS}
67 for i
69 eval OPT_${i}=0
70 done
73 option_maximal() {
74 set -- ${OPTIONS}
75 for i
77 eval OPT_${i}=1
78 done
79 OPT_ICONV=require
80 OPT_REGEX=require
81 OPT_DOTLOCK=require
84 option_setup() {
85 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
86 option_parse OPTIONS "${XOPTIONS}"
87 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
88 OPT_MIME=1
90 # Predefined CONFIG= urations take precedence over anything else
91 if [ -n "${CONFIG}" ]; then
92 case "${CONFIG}" in
93 [nN][uU][lL][lL])
94 option_reset
96 [nN][uU][lL][lL][iI])
97 option_reset
98 OPT_ICONV=require
100 [mM][iI][nN][iI][mM][aA][lL])
101 option_reset
102 OPT_ICONV=1
103 OPT_REGEX=1
104 OPT_DOTLOCK=require
106 [mM][eE][dD][iI][uU][mM])
107 option_reset
108 OPT_ICONV=require
109 OPT_IDNA=1
110 OPT_REGEX=1
111 OPT_MLE=1
112 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
113 OPT_ERRORS=1
114 OPT_SPAM_FILTER=1
115 OPT_DOCSTRINGS=1
116 OPT_COLOUR=1
117 OPT_DOTLOCK=require
119 [nN][eE][tT][sS][eE][nN][dD])
120 option_reset
121 OPT_ICONV=require
122 OPT_SOCKETS=1
123 OPT_SSL=require
124 OPT_SMTP=require
125 OPT_GSSAPI=1 OPT_NETRC=1 OPT_AGENT=1
126 OPT_IDNA=1
127 OPT_REGEX=1
128 OPT_MLE=1
129 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
130 OPT_DOCSTRINGS=1
131 OPT_COLOUR=1
132 OPT_DOTLOCK=require
134 [mM][aA][xX][iI][mM][aA][lL])
135 option_reset
136 option_maximal
138 [dD][eE][vV][eE][lL])
139 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
140 option_maximal
142 [oO][dD][eE][vV][eE][lL])
143 OPT_DEVEL=1
144 option_maximal
147 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
148 echo >&2 ' NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
149 exit 1
151 esac
155 # Inter-relationships
156 option_update() {
157 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
158 OPT_SOCKETS=0
160 if feat_no SOCKETS; then
161 if feat_require SMTP; then
162 msg 'ERROR: need SOCKETS for required feature SMTP'
163 config_exit 13
165 if feat_require POP3; then
166 msg 'ERROR: need SOCKETS for required feature POP3'
167 config_exit 13
169 if feat_require IMAP; then
170 msg 'ERROR: need SOCKETS for required feature IMAP'
171 config_exit 13
173 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
174 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
175 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
177 if feat_no SMTP && feat_no IMAP; then
178 OPT_GSSAPI=0
181 if feat_no ICONV; then
182 WANT_IMAP=0
185 if feat_no MLE; then
186 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
189 # If we don't need MD5 leave it alone
190 if feat_no SOCKETS; then
191 OPT_MD5=0
194 if feat_no TERMCAP; then
195 OPT_TERMCAP_VIA_TERMINFO=0
198 if feat_yes DEVEL; then
199 OPT_DEBUG=1
203 rc=./make.rc
204 lst=./mk-config.lst
205 ev=./mk-config.ev
206 h=./mk-config.h h_name=mk-config.h
207 mk=./mk-config.mk
209 newlst=./mk-nconfig.lst
210 newmk=./mk-nconfig.mk
211 newev=./mk-nconfig.ev
212 newh=./mk-nconfig.h
213 tmp0=___tmp
214 tmp=./${tmp0}1$$
215 tmp2=./${tmp0}2$$
217 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
219 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
220 # via path_check() later on once possible
222 # TODO cc_maxopt is brute simple, we should compile test program and dig real
223 # compiler versions for known compilers, then be more specific
224 cc_maxopt=100
225 _CFLAGS= _LDFLAGS=
227 os_early_setup() {
228 # We don't "have any utility": only path adjustments and such in here!
229 i="${OS:-`uname -s`}"
231 if [ ${i} = SunOS ]; then
232 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
233 _os_early_setup_sunos
237 _os_early_setup_sunos() {
238 # According to standards(5), this is what we need to do
239 if [ -d /usr/xpg4 ]; then :; else
240 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
241 config_exit 1
243 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
244 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
245 export PATH
248 os_setup() {
249 # OSENV ends up in *build-osenv*
250 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
251 : ${OS:=`uname -s | ${tr} '[A-Z]' '[a-z]'`}
252 : ${OSENV:=`uname -srm`}
253 : ${OSFULLSPEC:=`uname -a`}
254 msg 'Operating system is %s' ${OS}
256 if [ ${OS} = sunos ]; then
257 msg ' . have special SunOS / Solaris "setup" rules ...'
258 _os_setup_sunos
259 elif [ ${OS} = unixware ]; then
260 msg ' . have special UnixWare environmental rules ...'
261 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
262 CC=cc
263 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
265 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
266 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
267 export CC CFLAGS LDFLAGS
268 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
270 elif [ -n "${VERBOSE}" ]; then
271 msg ' . no special treatment for this system necessary or known'
274 # Sledgehammer: better set _GNU_SOURCE
275 # And in general: oh, boy!
276 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
277 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
278 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
279 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
281 # On pkgsrc(7) systems automatically add /usr/pkg/*
282 if [ -d /usr/pkg ]; then
283 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
284 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
288 _os_setup_sunos() {
289 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
290 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
292 # Include packages
293 if [ -d /opt/csw ]; then
294 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
295 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
298 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
299 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
301 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
302 if [ -x "${cksum}" ]; then :; else
303 msg 'ERROR: Not an executable program: %s' "${cksum}"
304 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
305 msg 'ERROR: However, we do so only for tests.'
306 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
307 config_exit 1
310 if feat_yes AUTOCC; then
311 if command -v cc >/dev/null 2>&1; then
312 CC=cc
313 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
315 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
316 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
317 export CC CFLAGS LDFLAGS
318 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
319 else
320 # Assume gcc(1), which supports -R for compat
321 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
326 # Check out compiler ($CC) and -flags ($CFLAGS)
327 cc_setup() {
328 # Even though it belongs into cc_flags we will try to compile and link
329 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
330 # EXTRA_CFLAGS/EXTRA_LDFLAGS
331 if feat_no AUTOCC; then
332 _cc_default
333 # Ensure those don't do any harm
334 EXTRA_CFLAGS= EXTRA_LDFLAGS=
335 export EXTRA_CFLAGS EXTRA_LDFLAGS
336 return
337 else
338 CFLAGS= LDFLAGS=
339 export CFLAGS LDFLAGS
342 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
344 msg_nonl 'Searching for a usable C compiler .. $CC='
345 if { i="`command -v clang`"; }; then
346 CC=${i}
347 elif { i="`command -v gcc`"; }; then
348 CC=${i}
349 elif { i="`command -v c99`"; }; then
350 CC=${i}
351 elif { i="`command -v tcc`"; }; then
352 CC=${i}
353 elif { i="`command -v pcc`"; }; then
354 CC=${i}
355 else
356 if [ "${CC}" = cc ]; then
358 elif { i="`command -v c89`"; }; then
359 CC=${i}
360 else
361 msg 'boing booom tschak'
362 msg 'ERROR: I cannot find a compiler!'
363 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
364 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
365 config_exit 1
368 msg '%s' "${CC}"
369 export CC
372 _cc_default() {
373 if [ -z "${CC}" ]; then
374 msg 'To go on like you have chosen, please set $CC, rerun.'
375 config_exit 1
378 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
380 else
381 msg 'Using C compiler ${CC}=%s' "${CC}"
385 cc_flags() {
386 if feat_yes AUTOCC; then
387 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
388 cc_check_silent=1
389 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
390 "${CC}"
391 else
392 cc_check_silent=
393 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
396 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
397 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
398 msg ' . have special tcc(1) environmental rules ...'
399 _cc_flags_tcc
400 else
401 # As of pcc CVS 2016-04-02, stack protection support is announced but
402 # will break if used on Linux
403 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
404 force_no_stackprot=1
406 _cc_flags_generic
409 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
410 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
411 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
412 else
413 if feat_no DEBUG; then
414 CFLAGS="-DNDEBUG ${CFLAGS}"
417 msg ''
418 export CFLAGS LDFLAGS
421 _cc_flags_tcc() {
422 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
423 _CFLAGS= _LDFLAGS=
425 cc_check -Wall
426 cc_check -Wextra
427 cc_check -pedantic
429 if feat_yes DEBUG; then
430 # May have problems to find libtcc cc_check -b
431 cc_check -g
434 if ld_check -Wl,-rpath =./ no; then
435 need_R_ldflags=-Wl,-rpath=
436 ld_check -Wl,--enable-new-dtags
437 ld_runtime_flags # update!
440 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
441 unset __cflags __ldflags
444 _cc_flags_generic() {
445 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
446 _CFLAGS= _LDFLAGS=
447 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
449 # Check -g first since some others may rely upon -g / optim. level
450 if feat_yes DEBUG; then
451 cc_check -O
452 cc_check -g
453 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
455 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
457 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
459 else
460 cc_check -O
463 if feat_yes AMALGAMATION; then
464 cc_check -pipe
467 #if feat_yes DEVEL && cc_check -Weverything; then
469 #else
470 cc_check -Wall
471 cc_check -Wextra
472 cc_check -Wbad-function-cast
473 cc_check -Wcast-align
474 cc_check -Wcast-qual
475 cc_check -Winit-self
476 cc_check -Wmissing-prototypes
477 cc_check -Wshadow
478 cc_check -Wunused
479 cc_check -Wwrite-strings
480 cc_check -Wno-long-long
482 cc_check -pedantic
484 if feat_yes AMALGAMATION && feat_no DEVEL; then
485 cc_check -Wno-unused-function
487 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
489 cc_check -fno-unwind-tables
490 cc_check -fno-asynchronous-unwind-tables
491 cc_check -fstrict-aliasing
492 if cc_check -fstrict-overflow && feat_yes DEVEL; then
493 cc_check -Wstrict-overflow=5
496 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
497 if [ -z "${force_no_stackprot}" ]; then
498 if cc_check -fstack-protector-strong ||
499 cc_check -fstack-protector-all; then
500 cc_check -D_FORTIFY_SOURCE=2
502 else
503 msg 'Not checking for -fstack-protector compiler option,'
504 msg 'since that caused errors in a "similar" configuration.'
505 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
509 # LD (+ dependend CC)
511 if feat_yes ASAN_ADDRESS; then
512 _ccfg=${_CFLAGS}
513 if cc_check -fsanitize=address &&
514 ld_check -fsanitize=address; then
516 else
517 feat_bail_required ASAN_ADDRESS
518 _CFLAGS=${_ccfg}
522 if feat_yes ASAN_MEMORY; then
523 _ccfg=${_CFLAGS}
524 if cc_check -fsanitize=memory &&
525 ld_check -fsanitize=memory &&
526 cc_check -fsanitize-memory-track-origins=2 &&
527 ld_check -fsanitize-memory-track-origins=2; then
529 else
530 feat_bail_required ASAN_MEMORY
531 _CFLAGS=${_ccfg}
535 ld_check -Wl,-z,relro
536 ld_check -Wl,-z,now
537 ld_check -Wl,-z,noexecstack
538 if ld_check -Wl,-rpath =./ no; then
539 need_R_ldflags=-Wl,-rpath=
540 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
541 ld_check -Wl,--enable-new-dtags
542 ld_runtime_flags # update!
543 elif ld_check -Wl,-R ./ no; then
544 need_R_ldflags=-Wl,-R
545 ld_check -Wl,--enable-new-dtags
546 ld_runtime_flags # update!
549 # Address randomization
550 _ccfg=${_CFLAGS}
551 if cc_check -fPIE || cc_check -fpie; then
552 ld_check -pie || _CFLAGS=${_ccfg}
554 unset _ccfg
556 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
557 unset __cflags __ldflags
560 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
562 ## Notes:
563 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
564 ## redirection, so use "printf '' >" instead
566 ## Very first: we undergo several states regarding I/O redirection etc.,
567 ## but need to deal with option updates from within all. Since all the
568 ## option stuff should be above the scissor line, define utility functions
569 ## and redefine them as necessary.
570 ## And, since we have those functions, simply use them for whatever
572 config_exit() {
573 exit ${1}
576 msg() {
577 fmt=${1}
578 shift
579 printf >&2 -- "${fmt}\\n" "${@}"
582 msg_nonl() {
583 fmt=${1}
584 shift
585 printf >&2 -- "${fmt}" "${@}"
588 t1=ten10one1ten10one1
589 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
590 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
591 ) > /dev/null 2>&1; then
592 good_shell=1
593 else
594 unset good_shell
596 unset t1
598 # We need some standard utilities
599 unset -f command
600 check_tool() {
601 n=${1} i=${2} opt=${3:-0}
602 # Evaluate, just in case user comes in with shell snippets (..well..)
603 eval i="${i}"
604 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
605 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
606 eval ${n}=${i}
607 return 0
609 if [ ${opt} -eq 0 ]; then
610 msg 'ERROR: no trace of utility %s' "${n}"
611 config_exit 1
613 return 1
616 # Our feature check environment
617 feat_val_no() {
618 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
619 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
622 feat_val_yes() {
623 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
624 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
625 [ "x${1}" = xrequire ]
628 feat_val_require() {
629 [ "x${1}" = xrequire ]
632 _feat_check() {
633 eval i=\$OPT_${1}
634 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
635 if feat_val_no "${i}"; then
636 return 1
637 elif feat_val_yes "${i}"; then
638 return 0
639 else
640 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
641 "${1}" "${i}"
642 config_exit 11
646 feat_yes() {
647 _feat_check ${1}
650 feat_no() {
651 _feat_check ${1} && return 1
652 return 0
655 feat_require() {
656 eval i=\$OPT_${1}
657 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
658 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
661 feat_bail_required() {
662 if feat_require ${1}; then
663 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
664 config_exit 13
666 eval OPT_${1}=0
667 option_update # XXX this is rather useless here (dependency chain..)
670 option_parse() {
671 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
672 # options, without documentation, to $1
673 j=\'
674 i="`${awk} -v input=\"${2}\" '
675 BEGIN{
676 for(i = 0;;){
677 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
678 if(voff == 0)
679 break
680 v = substr(input, voff, RLENGTH)
681 input = substr(input, voff + RLENGTH)
682 doff = index(v, "=")
683 if(doff > 0){
684 d = substr(v, doff + 2, length(v) - doff - 1)
685 v = substr(v, 1, doff - 1)
687 print v
691 eval ${1}=\"${i}\"
694 option_doc_of() {
695 # Return the "documentation string" for option $1, itself if none such
696 j=\'
697 ${awk} -v want="${1}" \
698 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
699 BEGIN{
700 for(;;){
701 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
702 if(voff == 0)
703 break
704 v = substr(input, voff, RLENGTH)
705 input = substr(input, voff + RLENGTH)
706 doff = index(v, "=")
707 if(doff > 0){
708 d = substr(v, doff + 2, length(v) - doff - 1)
709 v = substr(v, 1, doff - 1)
710 }else
711 d = v
712 if(v == want){
713 if(d != "-")
714 print d
715 exit
722 option_join_rc() {
723 # Join the values from make.rc into what currently is defined, not
724 # overwriting yet existing settings
725 ${rm} -f ${tmp}
726 # We want read(1) to perform reverse solidus escaping in order to be able to
727 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
728 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
729 < ${rc} ${awk} 'BEGIN{line = ""}{
730 gsub(/^[[:space:]]+/, "", $0)
731 gsub(/[[:space:]]+$/, "", $0)
732 if(gsub(/\\$/, "", $0)){
733 line = line $0
734 next
735 }else
736 line = line $0
737 if(index(line, "#") == 1){
738 line = ""
739 }else if(length(line)){
740 print line
741 line = ""
743 }' |
744 while read line; do
745 if [ -n "${good_shell}" ]; then
746 i=${line%%=*}
747 else
748 i=`${awk} -v LINE="${line}" 'BEGIN{
749 gsub(/=.*$/, "", LINE)
750 print LINE
753 if [ "${i}" = "${line}" ]; then
754 msg 'ERROR: invalid syntax in: %s' "${line}"
755 continue
758 eval j="\$${i}" jx="\${${i}+x}"
759 if [ -n "${j}" ] || [ "${jx}" = x ]; then
760 : # Yet present
761 else
762 j=`${awk} -v LINE="${line}" 'BEGIN{
763 gsub(/^[^=]*=/, "", LINE)
764 gsub(/^\"*/, "", LINE)
765 gsub(/\"*$/, "", LINE)
766 print LINE
769 [ "${i}" = "DESTDIR" ] && continue
770 echo "${i}=\"${j}\""
771 done > ${tmp}
772 # Reread the mixed version right now
773 . ./${tmp}
776 option_evaluate() {
777 # Expand the option values, which may contain shell snippets
778 ${rm} -f ${newlst} ${newmk} ${newh}
779 exec 5<&0 6>&1 <${tmp} >${newlst}
780 while read line; do
782 if [ -n "${good_shell}" ]; then
783 i=${line%%=*}
784 [ "${i}" != "${i#OPT_}" ] && z=1
785 else
786 i=`${awk} -v LINE="${line}" 'BEGIN{
787 gsub(/=.*$/, "", LINE);\
788 print LINE
790 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
795 eval j=\$${i}
796 if [ -n "${z}" ]; then
797 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
798 if [ -z "${j}" ] || feat_val_no "${j}"; then
800 printf " /* #undef ${i} */\n" >> ${newh}
801 elif feat_val_yes "${j}"; then
802 if feat_val_require "${j}"; then
803 j=require
804 else
807 printf " /* #define ${i} */\n" >> ${newh}
808 else
809 msg 'ERROR: cannot parse <%s>' "${line}"
810 config_exit 1
812 else
813 printf "#define ${i} \"${j}\"\n" >> ${newh}
815 printf "${i} = ${j}\n" >> ${newmk}
816 printf "${i}=${j}\n"
817 eval "${i}=\"${j}\""
818 done
819 exec 0<&5 1>&6 5<&- 6<&-
822 path_check() {
823 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
824 varname=${1} addflag=${2} flagvarname=${3}
825 j=${IFS}
826 IFS=:
827 eval "set -- \$${1}"
828 IFS=${j}
829 j= k= y= z=
830 for i
832 [ -z "${i}" ] && continue
833 [ -d "${i}" ] || continue
834 # Skip any fakeroot packager environment
835 case "${i}" in *fakeroot*) continue;; esac
836 if [ -n "${j}" ]; then
837 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
839 else
840 y="${y} :${i}:"
841 j="${j}:${i}"
842 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
844 else
845 y=" :${i}:"
846 j="${i}"
847 [ -n "${addflag}" ] && k="${addflag}${i}"
849 done
850 eval "${varname}=\"${j}\""
851 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
852 unset varname
855 ld_runtime_flags() {
856 if [ -n "${need_R_ldflags}" ]; then
857 i=${IFS}
858 IFS=:
859 set -- ${LD_LIBRARY_PATH}
860 IFS=${i}
861 for i
863 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
864 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
865 done
866 export LDFLAGS
868 # Disable it for a possible second run.
869 need_R_ldflags=
872 cc_check() {
873 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
874 if "${CC}" ${INCS} \
875 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
876 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
877 _CFLAGS="${_CFLAGS} ${1}"
878 [ -n "${cc_check_silent}" ] || msg 'yes'
879 return 0
881 [ -n "${cc_check_silent}" ] || msg 'no'
882 return 1
885 ld_check() {
886 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
887 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
888 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
889 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
890 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
891 [ -n "${cc_check_silent}" ] || msg 'yes'
892 return 0
894 [ -n "${cc_check_silent}" ] || msg 'no'
895 return 1
898 _check_preface() {
899 variable=$1 topic=$2 define=$3
901 echo '**********'
902 msg_nonl ' . %s ... ' "${topic}"
903 echo "/* checked ${topic} */" >> ${h}
904 ${rm} -f ${tmp} ${tmp}.o
905 echo '*** test program is'
906 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
907 #echo '*** the preprocessor generates'
908 #${make} -f ${makefile} ${tmp}.x
909 #${cat} ${tmp}.x
910 echo '*** results are'
913 without_check() {
914 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
916 echo '**********'
917 msg_nonl ' . %s ... ' "${topic}"
919 echo '*** enforced unchecked results are'
920 if feat_val_yes ${yesno}; then
921 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
922 echo "*** adding INCS<${incs}> LIBS<${libs}>"
923 LIBS="${LIBS} ${libs}"
924 echo "${libs}" >> ${lib}
925 INCS="${INCS} ${incs}"
926 echo "${incs}" >> ${inc}
928 msg 'yes (deduced)'
929 echo "${define}" >> ${h}
930 eval have_${variable}=yes
931 return 0
932 else
933 echo "/* ${define} */" >> ${h}
934 msg 'no (deduced)'
935 eval unset have_${variable}
936 return 1
940 compile_check() {
941 variable=$1 topic=$2 define=$3
943 _check_preface "${variable}" "${topic}" "${define}"
945 if ${make} -f ${makefile} XINCS="${INCS}" \
946 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
947 ./${tmp}.o &&
948 [ -f ./${tmp}.o ]; then
949 msg 'yes'
950 echo "${define}" >> ${h}
951 eval have_${variable}=yes
952 return 0
953 else
954 echo "/* ${define} */" >> ${h}
955 msg 'no'
956 eval unset have_${variable}
957 return 1
961 _link_mayrun() {
962 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
964 _check_preface "${variable}" "${topic}" "${define}"
966 if feat_yes CROSS_BUILD; then
967 if [ ${run} = 1 ]; then
968 run=0
972 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
973 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
974 XLIBS="${LIBS} ${libs}" \
975 ./${tmp} &&
976 [ -f ./${tmp} ] &&
977 { [ ${run} -eq 0 ] || ./${tmp}; }; then
978 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
979 msg 'yes'
980 echo "${define}" >> ${h}
981 LIBS="${LIBS} ${libs}"
982 echo "${libs}" >> ${lib}
983 INCS="${INCS} ${incs}"
984 echo "${incs}" >> ${inc}
985 eval have_${variable}=yes
986 return 0
987 else
988 msg 'no'
989 echo "/* ${define} */" >> ${h}
990 eval unset have_${variable}
991 return 1
995 link_check() {
996 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
999 run_check() {
1000 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1003 xrun_check() {
1004 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1007 feat_def() {
1008 if feat_yes ${1}; then
1009 echo '#define HAVE_'${1}'' >> ${h}
1010 return 0
1011 else
1012 echo '/* OPT_'${1}'=0 */' >> ${h}
1013 return 1
1017 squeeze_em() {
1018 < "${1}" > "${2}" ${awk} \
1019 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1022 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1024 # First of all, create new configuration and check whether it changed
1026 # Very easy checks for the operating system in order to be able to adjust paths
1027 # or similar very basic things which we need to be able to go at all
1028 os_early_setup
1030 # Check those tools right now that we need before including $rc
1031 msg 'Checking for basic utility set'
1032 check_tool awk "${awk:-`command -v awk`}"
1033 check_tool rm "${rm:-`command -v rm`}"
1034 check_tool tr "${tr:-`command -v tr`}"
1036 # Initialize the option set
1037 msg_nonl 'Setting up configuration options ... '
1038 option_setup
1039 msg 'done'
1041 # Include $rc, but only take from it what wasn't overwritten by the user from
1042 # within the command line or from a chosen fixed CONFIG=
1043 # Note we leave alone the values
1044 trap "exit 1" HUP INT TERM
1045 trap "${rm} -f ${tmp}" EXIT
1047 msg_nonl 'Joining in %s ... ' ${rc}
1048 option_join_rc
1049 msg 'done'
1051 # We need to know about that now, in order to provide utility overwrites etc.
1052 os_setup
1054 msg 'Checking for remaining set of utilities'
1055 check_tool grep "${grep:-`command -v grep`}"
1057 # Before we step ahead with the other utilities perform a path cleanup first.
1058 path_check PATH
1060 # awk(1) above
1061 check_tool cat "${cat:-`command -v cat`}"
1062 check_tool chmod "${chmod:-`command -v chmod`}"
1063 check_tool cp "${cp:-`command -v cp`}"
1064 check_tool cmp "${cmp:-`command -v cmp`}"
1065 # grep(1) above
1066 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1067 check_tool mv "${mv:-`command -v mv`}"
1068 # rm(1) above
1069 check_tool sed "${sed:-`command -v sed`}"
1070 check_tool sort "${sort:-`command -v sort`}"
1071 check_tool tee "${tee:-`command -v tee`}"
1073 check_tool chown "${chown:-`command -v chown`}" 1 ||
1074 check_tool chown "/sbin/chown" 1 ||
1075 check_tool chown "/usr/sbin/chown"
1077 check_tool make "${MAKE:-`command -v make`}"
1078 MAKE=${make}
1079 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1080 HAVE_STRIP=1 || HAVE_STRIP=0
1082 # For ./cc-test.sh only
1083 check_tool cksum "${cksum:-`command -v cksum`}"
1085 # Update OPT_ options now, in order to get possible inter-dependencies right
1086 option_update
1088 # (No functions since some shells loose non-exported variables in traps)
1089 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1090 trap "trap \"\" HUP INT TERM EXIT;\
1091 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1093 # Our configuration options may at this point still contain shell snippets,
1094 # we need to evaluate them in order to get them expanded, and we need those
1095 # evaluated values not only in our new configuration file, but also at hand..
1096 msg_nonl 'Evaluating all configuration items ... '
1097 option_evaluate
1098 msg 'done'
1100 # Add the known utility and some other variables
1101 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1102 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1104 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1105 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1106 if feat_yes DOTLOCK; then
1107 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1108 else
1109 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1112 for i in \
1113 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1114 MAKE MAKEFLAGS make SHELL strip \
1115 cksum; do
1116 eval j=\$${i}
1117 printf "${i} = ${j}\n" >> ${newmk}
1118 printf "${i}=${j}\n" >> ${newlst}
1119 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1120 done
1121 printf "\n" >> ${newev}
1123 # Build a basic set of INCS and LIBS according to user environment.
1124 path_check C_INCLUDE_PATH -I _INCS
1125 INCS="${INCS} ${_INCS}"
1126 path_check LD_LIBRARY_PATH -L _LIBS
1127 LIBS="${LIBS} ${_LIBS}"
1128 unset _INCS _LIBS
1129 export C_INCLUDE_PATH LD_LIBRARY_PATH
1131 # Some environments need runtime path flags to be able to go at all
1132 ld_runtime_flags
1134 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1136 cc_setup
1138 ${cat} > ${tmp}.c << \!
1139 #include <stdio.h>
1140 #include <string.h>
1141 static void doit(char const *s);
1143 main(int argc, char **argv){
1144 (void)argc;
1145 (void)argv;
1146 doit("Hello world");
1147 return 0;
1149 static void
1150 doit(char const *s){
1151 char buf[12];
1152 memcpy(buf, s, strlen(s) +1);
1153 puts(s);
1157 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1158 -o ${tmp2} ${tmp}.c ${LIBS}; then
1160 else
1161 msg 'ERROR: i cannot compile a "Hello world" via'
1162 msg ' %s' \
1163 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1164 msg 'ERROR: Please read INSTALL, rerun'
1165 config_exit 1
1168 # This may also update ld_runtime_flags() (again)
1169 cc_flags
1171 for i in \
1172 INCS LIBS \
1173 ; do
1174 eval j=\$${i}
1175 printf -- "${i}=${j}\n" >> ${newlst}
1176 done
1177 for i in \
1178 CC \
1179 CFLAGS \
1180 LDFLAGS \
1181 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1182 OSFULLSPEC \
1183 ; do
1184 eval j=\$${i}
1185 printf -- "${i} = ${j}\n" >> ${newmk}
1186 printf -- "${i}=${j}\n" >> ${newlst}
1187 done
1189 # Now finally check whether we already have a configuration and if so, whether
1190 # all those parameters are still the same.. or something has actually changed
1191 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1192 echo 'Configuration is up-to-date'
1193 exit 0
1194 elif [ -f ${lst} ]; then
1195 echo 'Configuration has been updated..'
1196 ( eval "${MAKE} -f ./mk-config.mk clean" )
1197 echo
1198 else
1199 echo 'Shiny configuration..'
1202 # Time to redefine helper 1
1203 config_exit() {
1204 ${rm} -f ${lst} ${h} ${mk}
1205 exit ${1}
1208 ${mv} -f ${newlst} ${lst}
1209 ${mv} -f ${newev} ${ev}
1210 ${mv} -f ${newh} ${h}
1211 ${mv} -f ${newmk} ${mk}
1213 if [ -z "${VERBOSE}" ]; then
1214 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1215 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1216 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1217 printf -- "ECHO_TEST = @\n" >> ${mk}
1218 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1219 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1220 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1223 ## Compile and link checking
1225 tmp3=./${tmp0}3$$
1226 log=./mk-config.log
1227 lib=./mk-config.lib
1228 inc=./mk-config.inc
1229 makefile=./${tmp0}.mk
1231 # (No function since some shells loose non-exported variables in traps)
1232 trap "trap \"\" HUP INT TERM;\
1233 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1234 trap "trap \"\" HUP INT TERM EXIT;\
1235 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1237 # Time to redefine helper 2
1238 msg() {
1239 fmt=${1}
1240 shift
1241 printf "*** ${fmt}\\n" "${@}"
1242 printf -- "${fmt}\\n" "${@}" >&5
1244 msg_nonl() {
1245 fmt=${1}
1246 shift
1247 printf "*** ${fmt}\\n" "${@}"
1248 printf -- "${fmt}" "${@}" >&5
1251 # !!
1252 exec 5>&2 > ${log} 2>&1
1254 echo "${LIBS}" > ${lib}
1255 echo "${INCS}" > ${inc}
1256 ${cat} > ${makefile} << \!
1257 .SUFFIXES: .o .c .x .y
1258 .c.o:
1259 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1260 .c.x:
1261 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1263 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1266 ## Generics
1268 # May be multiline..
1269 echo >> ${h}
1270 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1271 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1272 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1274 # Generate n_err_number OS mappings
1276 feat_yes DEVEL && NV= || NV=noverbose
1277 TARGET="${h}" awk="${awk}" ./make-errors.sh ${NV} config
1279 xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1281 feat_def ALWAYS_UNICODE_LOCALE
1282 feat_def AMALGAMATION
1283 feat_def CROSS_BUILD
1284 feat_def DOCSTRINGS
1285 feat_def ERRORS
1287 feat_def ASAN_ADDRESS
1288 feat_def ASAN_MEMORY
1289 feat_def DEBUG
1290 feat_def DEVEL
1291 feat_def NYD2
1292 feat_def NOMEMDBG
1294 if xrun_check inline 'inline functions' \
1295 '#define HAVE_INLINE
1296 #define n_INLINE static inline' << \!
1297 static inline int ilf(int i){return ++i;}
1298 int main(void){return ilf(-1);}
1300 then
1302 elif xrun_check inline 'inline functions (via __inline)' \
1303 '#define HAVE_INLINE
1304 #define n_INLINE static __inline' << \!
1305 static __inline int ilf(int i){return ++i;}
1306 int main(void){return ilf(-1);}
1308 then
1312 ## Test for "basic" system-calls / functionality that is used by all parts
1313 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1314 ## macros to be used by only the subprograms (potentially).
1316 if run_check clock_gettime 'clock_gettime(2)' \
1317 '#define HAVE_CLOCK_GETTIME' << \!
1318 #include <time.h>
1319 # include <errno.h>
1320 int main(void){
1321 struct timespec ts;
1323 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1324 return 0;
1325 return 1;
1328 then
1330 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1331 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1332 #include <time.h>
1333 # include <errno.h>
1334 int main(void){
1335 struct timespec ts;
1337 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1338 return 0;
1339 return 1;
1342 then
1344 elif run_check gettimeofday 'gettimeofday(2)' \
1345 '#define HAVE_GETTIMEOFDAY' << \!
1346 #include <stdio.h> /* For C89 NULL */
1347 #include <sys/time.h>
1348 # include <errno.h>
1349 int main(void){
1350 struct timeval tv;
1352 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1353 return 0;
1354 return 1;
1357 then
1359 else
1360 have_no_subsecond_time=1
1363 if run_check nanosleep 'nanosleep(2)' \
1364 '#define HAVE_NANOSLEEP' << \!
1365 #include <time.h>
1366 # include <errno.h>
1367 int main(void){
1368 struct timespec ts;
1370 ts.tv_sec = 1;
1371 ts.tv_nsec = 100000;
1372 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1373 return 0;
1374 return 1;
1377 then
1379 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1380 '#define HAVE_NANOSLEEP' '-lrt' << \!
1381 #include <time.h>
1382 # include <errno.h>
1383 int main(void){
1384 struct timespec ts;
1386 ts.tv_sec = 1;
1387 ts.tv_nsec = 100000;
1388 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1389 return 0;
1390 return 1;
1393 then
1395 # link_check is enough for this, that function is so old, trust the proto
1396 elif link_check sleep 'sleep(3)' \
1397 '#define HAVE_SLEEP' << \!
1398 #include <unistd.h>
1399 # include <errno.h>
1400 int main(void){
1401 if(!sleep(1) || errno != ENOSYS)
1402 return 0;
1403 return 1;
1406 then
1408 else
1409 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1410 config_exit 1
1413 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1414 #include <pwd.h>
1415 #include <unistd.h>
1416 # include <errno.h>
1417 int main(void){
1418 struct passwd *pw;
1419 gid_t gid;
1420 uid_t uid;
1422 if((gid = getgid()) != 0)
1423 gid = getegid();
1424 if((uid = getuid()) != 0)
1425 uid = geteuid();
1426 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1427 return 1;
1428 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1429 return 1;
1430 return 0;
1433 then
1435 else
1436 msg 'ERROR: we require user and group info / database searches.'
1437 msg 'That much Unix we indulge ourselfs.'
1438 config_exit 1
1441 if link_check ftruncate 'ftruncate(2)' \
1442 '#define HAVE_FTRUNCATE' << \!
1443 #include <unistd.h>
1444 #include <sys/types.h>
1445 int main(void){
1446 return (ftruncate(0, 0) != 0);
1449 then
1451 else
1452 msg 'ERROR: we require the ftruncate(2) system call.'
1453 config_exit 1
1456 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1457 #include <signal.h>
1458 # include <errno.h>
1459 int main(void){
1460 struct sigaction nact, oact;
1462 nact.sa_handler = SIG_DFL;
1463 sigemptyset(&nact.sa_mask);
1464 nact.sa_flags = SA_RESTART;
1465 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1468 then
1470 else
1471 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1472 config_exit 1
1475 if link_check snprintf 'snprintf(3)' << \!
1476 #include <stdio.h>
1477 int main(void){
1478 char b[20];
1480 snprintf(b, sizeof b, "%s", "string");
1481 return 0;
1484 then
1486 else
1487 msg 'ERROR: we require the snprintf(3) function.'
1488 config_exit 1
1491 if link_check environ 'environ(3)' << \!
1492 #include <stdio.h> /* For C89 NULL */
1493 int main(void){
1494 extern char **environ;
1496 return environ[0] == NULL;
1499 then
1501 else
1502 msg 'ERROR: we require the environ(3) array for subprocess control.'
1503 config_exit 1
1506 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1507 #include <stdlib.h>
1508 int main(void){
1509 setenv("s-mailx", "i want to see it cute!", 1);
1510 unsetenv("s-mailx");
1511 return 0;
1514 then
1516 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1517 #include <stdlib.h>
1518 int main(void){
1519 putenv("s-mailx=i want to see it cute!");
1520 return 0;
1523 then
1525 else
1526 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1527 config_exit 1
1530 if link_check termios 'termios.h and tc*(3) family' << \!
1531 #include <termios.h>
1532 int main(void){
1533 struct termios tios;
1535 tcgetattr(0, &tios);
1536 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1537 return 0;
1540 then
1542 else
1543 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1544 msg 'That much Unix we indulge ourselfs.'
1545 config_exit 1
1548 ## optional stuff
1550 if link_check vsnprintf 'vsnprintf(3)' << \!
1551 #include <stdarg.h>
1552 #include <stdio.h>
1553 static void dome(char *buf, size_t blen, ...){
1554 va_list ap;
1556 va_start(ap, blen);
1557 vsnprintf(buf, blen, "%s", ap);
1558 va_end(ap);
1560 int main(void){
1561 char b[20];
1563 dome(b, sizeof b, "string");
1564 return 0;
1567 then
1569 else
1570 feat_bail_required ERRORS
1573 if [ "${have_vsnprintf}" = yes ]; then
1574 __va_copy() {
1575 link_check va_copy "va_copy(3) (as ${2})" \
1576 "#define HAVE_N_VA_COPY
1577 #define n_va_copy ${2}" <<_EOT
1578 #include <stdarg.h>
1579 #include <stdio.h>
1580 #if ${1}
1581 # if defined __va_copy && !defined va_copy
1582 # define va_copy __va_copy
1583 # endif
1584 #endif
1585 static void dome2(char *buf, size_t blen, va_list src){
1586 va_list ap;
1588 va_copy(ap, src);
1589 vsnprintf(buf, blen, "%s", ap);
1590 va_end(ap);
1592 static void dome(char *buf, size_t blen, ...){
1593 va_list ap;
1595 va_start(ap, blen);
1596 dome2(buf, blen, ap);
1597 va_end(ap);
1599 int main(void){
1600 char b[20];
1602 dome(b, sizeof b, "string");
1603 return 0;
1605 _EOT
1607 __va_copy 0 va_copy || __va_copy 1 __va_copy
1610 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1611 #include <unistd.h>
1612 #include <errno.h>
1613 int main(void){
1614 int rv = 0;
1616 errno = 0;
1617 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1618 errno = 0;
1619 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1621 /* Only link check */
1622 fpathconf(0, _PC_NAME_MAX);
1624 return rv;
1628 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1629 #include <fcntl.h>
1630 #include <unistd.h>
1631 # include <errno.h>
1632 int main(void){
1633 int fds[2];
1635 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1636 return 0;
1637 return 1;
1641 # We use this only then for now (need NOW+1)
1642 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1643 #include <fcntl.h> /* For AT_* */
1644 #include <sys/stat.h>
1645 # include <errno.h>
1646 int main(void){
1647 struct timespec ts[2];
1649 ts[0].tv_nsec = UTIME_NOW;
1650 ts[1].tv_nsec = UTIME_OMIT;
1651 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1652 return 0;
1653 return 1;
1659 # XXX Add POSIX check once standardized
1660 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1661 #include <stdlib.h>
1662 int main(void){
1663 arc4random();
1664 return 0;
1667 then
1669 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1670 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1671 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1672 #include <sys/random.h>
1673 int main(void){
1674 char buf[256];
1675 getrandom(buf, sizeof buf, 0);
1676 return 0;
1679 then
1681 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1682 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1683 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1684 #include <sys/syscall.h>
1685 int main(void){
1686 char buf[256];
1687 syscall(SYS_getrandom, buf, sizeof buf, 0);
1688 return 0;
1691 then
1693 elif [ -n "${have_no_subsecond_time}" ]; then
1694 msg 'ERROR: %s %s' 'without a native random' \
1695 'one of clock_gettime(2) and gettimeofday(2) is required.'
1696 config_exit 1
1700 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1701 #include <stdio.h>
1702 int main(void){
1703 putc_unlocked('@', stdout);
1704 return 0;
1708 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1709 #include <unistd.h>
1710 int main(void){
1711 fchdir(0);
1712 return 0;
1716 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1717 #include <stdlib.h>
1718 int main(void){
1719 char x_buf[4096], *x = realpath(".", x_buf);
1721 return (x != NULL) ? 0 : 1;
1724 then
1725 if run_check realpath_malloc 'realpath(3) takes NULL' \
1726 '#define HAVE_REALPATH_NULL' << \!
1727 #include <stdlib.h>
1728 int main(void){
1729 char *x = realpath(".", NULL);
1731 if(x != NULL)
1732 free(x);
1733 return (x != NULL) ? 0 : 1;
1736 then
1741 ## optional and selectable
1743 if feat_yes DOTLOCK; then
1744 if run_check readlink 'readlink(2)' << \!
1745 #include <unistd.h>
1746 # include <errno.h>
1747 int main(void){
1748 char buf[128];
1750 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1751 return 0;
1752 return 1;
1755 then
1757 else
1758 feat_bail_required DOTLOCK
1762 if feat_yes DOTLOCK; then
1763 if run_check fchown 'fchown(2)' << \!
1764 #include <unistd.h>
1765 # include <errno.h>
1766 int main(void){
1767 if(!fchown(0, 0, 0) || errno != ENOSYS)
1768 return 0;
1769 return 1;
1772 then
1774 else
1775 feat_bail_required DOTLOCK
1779 ## Now it is the time to fork away the BASE_ series
1781 ${rm} -f ${tmp}
1782 squeeze_em ${inc} ${tmp}
1783 ${mv} ${tmp} ${inc}
1784 squeeze_em ${lib} ${tmp}
1785 ${mv} ${tmp} ${lib}
1787 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1788 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1790 ## The remains are expected to be used only by the main MUA binary!
1792 OPT_LOCALES=0
1793 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1794 #include <locale.h>
1795 int main(void){
1796 setlocale(LC_ALL, "");
1797 return 0;
1800 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1802 OPT_MULTIBYTE_CHARSETS=0
1803 OPT_WIDE_GLYPHS=0
1804 OPT_TERMINAL_CHARSET=0
1805 if [ -n "${have_setlocale}" ]; then
1806 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1807 '#define HAVE_C90AMEND1' << \!
1808 #include <limits.h>
1809 #include <stdlib.h>
1810 #include <wchar.h>
1811 #include <wctype.h>
1812 int main(void){
1813 char mbb[MB_LEN_MAX + 1];
1814 wchar_t wc;
1816 iswprint(L'c');
1817 towupper(L'c');
1818 mbtowc(&wc, "x", 1);
1819 mbrtowc(&wc, "x", 1, NULL);
1820 wctomb(mbb, wc);
1821 return (mblen("\0", 1) == 0);
1824 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1826 if [ -n "${have_c90amend1}" ]; then
1827 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1828 #include <wchar.h>
1829 int main(void){
1830 wcwidth(L'c');
1831 return 0;
1834 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1837 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1838 #include <langinfo.h>
1839 #include <stdlib.h>
1840 int main(void){
1841 nl_langinfo(DAY_1);
1842 return (nl_langinfo(CODESET) == NULL);
1845 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1846 fi # have_setlocale
1848 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1849 #include <fnmatch.h>
1850 int main(void){
1851 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1855 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1856 #include <dirent.h>
1857 int main(void){
1858 struct dirent de;
1859 return !(de.d_type == DT_UNKNOWN ||
1860 de.d_type == DT_DIR || de.d_type == DT_LNK);
1864 ## optional and selectable
1866 if feat_yes ICONV; then
1867 ${cat} > ${tmp2}.c << \!
1868 #include <stdio.h> /* For C89 NULL */
1869 #include <iconv.h>
1870 int main(void){
1871 iconv_t id;
1873 id = iconv_open("foo", "bar");
1874 iconv(id, NULL, NULL, NULL, NULL);
1875 iconv_close(id);
1876 return 0;
1879 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1880 '#define HAVE_ICONV' ||
1881 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1882 '#define HAVE_ICONV' '-liconv' ||
1883 feat_bail_required ICONV
1884 else
1885 echo '/* OPT_ICONV=0 */' >> ${h}
1886 fi # feat_yes ICONV
1888 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1889 ${cat} > ${tmp2}.c << \!
1890 #include <sys/types.h>
1891 #include <sys/socket.h>
1892 #include <sys/un.h>
1893 # include <errno.h>
1894 int main(void){
1895 struct sockaddr_un soun;
1897 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1898 return 1;
1899 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1900 return 1;
1901 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1902 return 1;
1903 return 0;
1907 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1908 '#define HAVE_UNIX_SOCKETS' ||
1909 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1910 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1911 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1912 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1915 if feat_yes SOCKETS; then
1916 ${cat} > ${tmp2}.c << \!
1917 #include <sys/types.h>
1918 #include <sys/socket.h>
1919 #include <netinet/in.h>
1920 # include <errno.h>
1921 int main(void){
1922 struct sockaddr s;
1924 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1925 return 1;
1926 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1927 return 1;
1928 return 0;
1932 < ${tmp2}.c run_check sockets 'sockets' \
1933 '#define HAVE_SOCKETS' ||
1934 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1935 '#define HAVE_SOCKETS' '-lnsl' ||
1936 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1937 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1938 feat_bail_required SOCKETS
1939 else
1940 echo '/* OPT_SOCKETS=0 */' >> ${h}
1941 fi # feat_yes SOCKETS
1943 if feat_yes SOCKETS; then
1944 link_check getaddrinfo 'getaddrinfo(3)' \
1945 '#define HAVE_GETADDRINFO' << \!
1946 #include <sys/types.h>
1947 #include <sys/socket.h>
1948 #include <stdio.h>
1949 #include <netdb.h>
1950 int main(void){
1951 struct addrinfo a, *ap;
1952 int lrv;
1954 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1955 case EAI_NONAME:
1956 case EAI_SERVICE:
1957 default:
1958 fprintf(stderr, "%s\n", gai_strerror(lrv));
1959 case 0:
1960 break;
1962 return 0;
1967 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1968 compile_check arpa_inet_h '<arpa/inet.h>' \
1969 '#define HAVE_ARPA_INET_H' << \!
1970 #include <sys/types.h>
1971 #include <sys/socket.h>
1972 #include <netdb.h>
1973 #include <netinet/in.h>
1974 #include <arpa/inet.h>
1977 ${cat} > ${tmp2}.c << \!
1978 #include <sys/types.h>
1979 #include <sys/socket.h>
1980 #include <stdio.h>
1981 #include <string.h>
1982 #include <netdb.h>
1983 #include <netinet/in.h>
1984 #ifdef HAVE_ARPA_INET_H
1985 #include <arpa/inet.h>
1986 #endif
1987 int main(void){
1988 struct sockaddr_in servaddr;
1989 unsigned short portno;
1990 struct servent *ep;
1991 struct hostent *hp;
1992 struct in_addr **pptr;
1994 portno = 0;
1995 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1996 portno = (unsigned short)ep->s_port;
1998 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1999 pptr = (struct in_addr**)hp->h_addr_list;
2000 if(hp->h_addrtype != AF_INET)
2001 fprintf(stderr, "au\n");
2002 }else{
2003 switch(h_errno){
2004 case HOST_NOT_FOUND:
2005 case TRY_AGAIN:
2006 case NO_RECOVERY:
2007 case NO_DATA:
2008 break;
2009 default:
2010 fprintf(stderr, "au\n");
2011 break;
2015 memset(&servaddr, 0, sizeof servaddr);
2016 servaddr.sin_family = AF_INET;
2017 servaddr.sin_port = htons(portno);
2018 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2019 fprintf(stderr, "Would connect to %s:%d ...\n",
2020 inet_ntoa(**pptr), (int)portno);
2021 return 0;
2025 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2026 < ${tmp2}.c link_check gethostbyname \
2027 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2028 < ${tmp2}.c link_check gethostbyname \
2029 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2030 '' '-lsocket -lnsl' ||
2031 feat_bail_required SOCKETS
2034 feat_yes SOCKETS &&
2035 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2036 #include <sys/socket.h>
2037 #include <stdlib.h>
2038 # include <errno.h>
2039 int main(void){
2040 int sockfd = 3;
2042 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2043 errno == ENOSYS)
2044 return 1;
2045 return 0;
2049 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2050 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2051 #include <sys/socket.h>
2052 #include <stdlib.h>
2053 int main(void){
2054 struct timeval tv;
2055 int sockfd = 3;
2057 tv.tv_sec = 42;
2058 tv.tv_usec = 21;
2059 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2060 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2061 return 0;
2065 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2066 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2067 #include <sys/socket.h>
2068 #include <stdlib.h>
2069 int main(void){
2070 struct linger li;
2071 int sockfd = 3;
2073 li.l_onoff = 1;
2074 li.l_linger = 42;
2075 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2076 return 0;
2080 if feat_yes SSL; then # {{{
2081 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2082 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2083 # time: we need to test it first in order to get things right
2084 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2085 '#define HAVE_SSL
2086 #define HAVE_XSSL
2087 #define HAVE_XSSL_RESSL
2088 #define HAVE_XSSL_OPENSSL 0' << \!
2089 #include <openssl/opensslv.h>
2090 #ifdef LIBRESSL_VERSION_NUMBER
2091 #else
2092 # error nope
2093 #endif
2095 then
2096 ossl_v1_1=
2097 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2098 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2099 '#define HAVE_SSL
2100 #define HAVE_XSSL
2101 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2102 #include <openssl/opensslv.h>
2103 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2104 #else
2105 # error nope
2106 #endif
2108 then
2109 ossl_v1_1=1
2110 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2111 '#define HAVE_SSL
2112 #define HAVE_XSSL
2113 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2114 #include <openssl/opensslv.h>
2115 #ifdef OPENSSL_VERSION_NUMBER
2116 #else
2117 # error nope
2118 #endif
2120 then
2121 ossl_v1_1=
2122 else
2123 feat_bail_required SSL
2124 fi # }}}
2126 if feat_yes SSL; then # {{{
2127 if [ -n "${ossl_v1_1}" ]; then
2128 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2129 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2130 '-lssl -lcrypto'
2131 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2132 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2133 '-lssl -lcrypto' << \!
2134 #include <openssl/ssl.h>
2135 #include <openssl/err.h>
2136 #include <openssl/x509v3.h>
2137 #include <openssl/x509.h>
2138 #include <openssl/rand.h>
2139 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2140 # error We need TLSv1.
2141 #endif
2142 int main(void){
2143 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2145 SSL_CTX_free(ctx);
2146 PEM_read_PrivateKey(0, 0, 0, 0);
2147 return 0;
2150 then
2152 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2153 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2154 '-lssl -lcrypto' << \!
2155 #include <openssl/ssl.h>
2156 #include <openssl/err.h>
2157 #include <openssl/x509v3.h>
2158 #include <openssl/x509.h>
2159 #include <openssl/rand.h>
2160 #if defined OPENSSL_NO_SSL3 &&\
2161 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2162 # error We need one of SSLv3 and TLSv1.
2163 #endif
2164 int main(void){
2165 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2167 SSL_CTX_free(ctx);
2168 PEM_read_PrivateKey(0, 0, 0, 0);
2169 return 0;
2172 then
2174 else
2175 feat_bail_required SSL
2177 fi # }}}
2179 if feat_yes SSL; then # {{{
2180 if [ -n "${ossl_v1_1}" ]; then
2181 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2182 '#define HAVE_XSSL_STACK_OF'
2183 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2184 '#define HAVE_XSSL_STACK_OF' << \!
2185 #include <stdio.h> /* For C89 NULL */
2186 #include <openssl/ssl.h>
2187 #include <openssl/err.h>
2188 #include <openssl/x509v3.h>
2189 #include <openssl/x509.h>
2190 #include <openssl/rand.h>
2191 int main(void){
2192 STACK_OF(GENERAL_NAME) *gens = NULL;
2194 printf("%p", gens); /* to use it */
2195 return 0;
2198 then
2202 if [ -n "${ossl_v1_1}" ]; then
2203 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2204 '#define HAVE_XSSL_CONFIG'
2205 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2206 '#define HAVE_XSSL_CONFIG' << \!
2207 #include <stdio.h> /* For C89 NULL */
2208 #include <openssl/conf.h>
2209 int main(void){
2210 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2211 CONF_modules_free();
2212 return 0;
2215 then
2219 if [ -n "${ossl_v1_1}" ]; then
2220 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2221 '#define HAVE_XSSL_CONF_CTX'
2222 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2223 '#define HAVE_XSSL_CONF_CTX' << \!
2224 #include <openssl/ssl.h>
2225 #include <openssl/err.h>
2226 int main(void){
2227 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2228 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2230 SSL_CONF_CTX_set_flags(cctx,
2231 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2232 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2233 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2234 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2235 SSL_CONF_CTX_finish(cctx);
2236 SSL_CONF_CTX_free(cctx);
2237 SSL_CTX_free(ctx);
2238 return 0;
2241 then
2245 if [ -n "${ossl_v1_1}" ]; then
2246 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2247 '#define HAVE_XSSL_RAND_EGD'
2248 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2249 '#define HAVE_XSSL_RAND_EGD' << \!
2250 #include <openssl/rand.h>
2251 int main(void){
2252 return RAND_egd("some.where") > 0;
2255 then
2259 if feat_yes SSL_ALL_ALGORITHMS; then
2260 if [ -n "${ossl_v1_1}" ]; then
2261 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2262 '#define HAVE_SSL_ALL_ALGORITHMS'
2263 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2264 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2265 #include <openssl/evp.h>
2266 int main(void){
2267 OpenSSL_add_all_algorithms();
2268 EVP_get_cipherbyname("two cents i never exist");
2269 EVP_cleanup();
2270 return 0;
2273 then
2275 else
2276 feat_bail_required SSL_ALL_ALGORITHMS
2279 fi # feat_yes SSL }}}
2281 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2282 run_check ssl_md5 'MD5 digest in the used crypto library' \
2283 '#define HAVE_XSSL_MD5' << \!
2284 #include <stdlib.h>
2285 #include <string.h>
2286 #include <openssl/md5.h>
2287 int main(void){
2288 char const dat[] = "abrakadabrafidibus";
2289 char dig[16], hex[16 * 2];
2290 MD5_CTX ctx;
2291 size_t i, j;
2293 memset(dig, 0, sizeof(dig));
2294 memset(hex, 0, sizeof(hex));
2295 MD5_Init(&ctx);
2296 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2297 MD5_Final(dig, &ctx);
2299 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2300 for(i = 0; i < sizeof(hex) / 2; i++){
2301 j = i << 1;
2302 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2303 hex[++j] = hexchar(dig[i] & 0x0f);
2305 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2308 fi # }}}
2309 else
2310 echo '/* OPT_SSL=0 */' >> ${h}
2311 fi # }}} feat_yes SSL
2313 if [ "${have_xssl}" = yes ]; then
2314 OPT_SMIME=1
2315 else
2316 OPT_SMIME=0
2318 feat_def SMIME
2320 feat_def SMTP
2321 feat_def POP3
2322 feat_def IMAP
2324 if feat_yes GSSAPI; then
2325 ${cat} > ${tmp2}.c << \!
2326 #include <gssapi/gssapi.h>
2327 int main(void){
2328 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2329 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2330 return 0;
2333 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2335 if command -v krb5-config >/dev/null 2>&1; then
2336 i=`command -v krb5-config`
2337 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2338 GSS_INCS="`CFLAGS= ${i} --cflags`"
2339 i='GSS-API via krb5-config(1)'
2340 else
2341 GSS_LIBS='-lgssapi'
2342 GSS_INCS=
2343 i='GSS-API in gssapi/gssapi.h, libgssapi'
2345 if < ${tmp2}.c link_check gss \
2346 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2347 < ${tmp3}.c link_check gss \
2348 'GSS-API in gssapi.h, libgssapi' \
2349 '#define HAVE_GSSAPI
2350 #define GSSAPI_REG_INCLUDE' \
2351 '-lgssapi' ||\
2352 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2353 '#define HAVE_GSSAPI' \
2354 '-lgssapi_krb5' ||\
2355 < ${tmp3}.c link_check gss \
2356 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2357 '#define HAVE_GSSAPI
2358 #define GSS_REG_INCLUDE' \
2359 '-lgssapi -lkrb5 -lcrypto' \
2360 '-I/usr/include/kerberosV' ||\
2361 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2362 '#define HAVE_GSSAPI' \
2363 '-lgss' ||\
2364 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2365 '#define HAVE_GSSAPI
2366 #define GSSAPI_OLD_STYLE' \
2367 '-lgssapi_krb5' << \!
2368 #include <gssapi/gssapi.h>
2369 #include <gssapi/gssapi_generic.h>
2370 int main(void){
2371 gss_import_name(0, 0, gss_nt_service_name, 0);
2372 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2373 return 0;
2376 then
2378 else
2379 feat_bail_required GSSAPI
2381 else
2382 echo '/* OPT_GSSAPI=0 */' >> ${h}
2383 fi # feat_yes GSSAPI
2385 feat_def NETRC
2386 feat_def AGENT
2388 if feat_yes IDNA; then
2389 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2390 '-lidn' << \!
2391 #include <idna.h>
2392 #include <idn-free.h>
2393 #include <stringprep.h>
2394 int main(void){
2395 char *utf8, *idna_ascii, *idna_utf8;
2397 utf8 = stringprep_locale_to_utf8("does.this.work");
2398 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2399 != IDNA_SUCCESS)
2400 return 1;
2401 idn_free(idna_ascii);
2402 /* (Rather link check only here) */
2403 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2404 return 0;
2407 then
2409 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2410 '-lidnkit' << \!
2411 #include <stdio.h>
2412 #include <idn/api.h>
2413 #include <idn/result.h>
2414 int main(void){
2415 idn_result_t r;
2416 char ace_name[256];
2417 char local_name[256];
2419 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2420 sizeof(ace_name));
2421 if (r != idn_success) {
2422 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2423 return 1;
2425 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2426 if (r != idn_success) {
2427 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2428 return 1;
2430 return 0;
2433 then
2435 else
2436 feat_bail_required IDNA
2439 if [ -n "${have_idna}" ]; then
2440 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2441 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2443 else
2444 echo '/* OPT_IDNA=0 */' >> ${h}
2447 feat_def IMAP_SEARCH
2449 if feat_yes REGEX; then
2450 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2451 #include <regex.h>
2452 #include <stdlib.h>
2453 int main(void){
2454 size_t xret;
2455 int status;
2456 regex_t re;
2458 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2459 xret = regerror(status, &re, NULL, 0);
2460 status = regexec(&re, "plan9", 0,NULL, 0);
2461 regfree(&re);
2462 return !(status == REG_NOMATCH);
2465 then
2467 else
2468 feat_bail_required REGEX
2470 else
2471 echo '/* OPT_REGEX=0 */' >> ${h}
2474 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2475 have_mle=1
2476 echo '#define HAVE_MLE' >> ${h}
2477 else
2478 feat_bail_required MLE
2479 echo '/* OPT_MLE=0 */' >> ${h}
2482 # Generic have-a-line-editor switch for those who need it below
2483 if [ -n "${have_mle}" ]; then
2484 have_cle=1
2487 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2488 echo '#define HAVE_HISTORY' >> ${h}
2489 else
2490 echo '/* OPT_HISTORY=0 */' >> ${h}
2493 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2494 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2495 else
2496 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2499 if feat_yes TERMCAP; then
2500 __termcaplib() {
2501 link_check termcap "termcap(5) (via ${4})" \
2502 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2503 #include <stdio.h>
2504 #include <stdlib.h>
2505 ${2}
2506 #include <term.h>
2507 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2508 static int my_putc(int c){return putchar(c);}
2509 int main(void){
2510 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2511 int r2 = OK, r3 = ERR;
2513 tgetent(buf, getenv("TERM"));
2514 cpb = cmdbuf;
2515 r1 = tgetstr(UNCONST("cm"), &cpb);
2516 tgoto(r1, 1, 1);
2517 r2 = tgetnum(UNCONST("Co"));
2518 r3 = tgetflag(UNCONST("ut"));
2519 tputs("cr", 1, &my_putc);
2520 return (r1 == NULL || r2 == -1 || r3 == 0);
2522 _EOT
2525 __terminfolib() {
2526 link_check terminfo "terminfo(5) (via ${2})" \
2527 '#define HAVE_TERMCAP
2528 #define HAVE_TERMCAP_CURSES
2529 #define HAVE_TERMINFO' "${1}" << _EOT
2530 #include <stdio.h>
2531 #include <curses.h>
2532 #include <term.h>
2533 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2534 static int my_putc(int c){return putchar(c);}
2535 int main(void){
2536 int er, r0, r1, r2;
2537 char *r3, *tp;
2539 er = OK;
2540 r0 = setupterm(NULL, 1, &er);
2541 r1 = tigetflag(UNCONST("bce"));
2542 r2 = tigetnum(UNCONST("colors"));
2543 r3 = tigetstr(UNCONST("cr"));
2544 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2545 tputs(tp, 1, &my_putc);
2546 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2547 r3 == (char*)-1 || r3 == NULL);
2549 _EOT
2552 if feat_yes TERMCAP_VIA_TERMINFO; then
2553 __terminfolib -ltinfo -ltinfo ||
2554 __terminfolib -lcurses -lcurses ||
2555 __terminfolib -lcursesw -lcursesw ||
2556 feat_bail_required TERMCAP_VIA_TERMINFO
2559 if [ -z "${have_terminfo}" ]; then
2560 __termcaplib -ltermcap '' '' '-ltermcap' ||
2561 __termcaplib -ltermcap '#include <curses.h>' '
2562 #define HAVE_TERMCAP_CURSES' \
2563 'curses.h / -ltermcap' ||
2564 __termcaplib -lcurses '#include <curses.h>' '
2565 #define HAVE_TERMCAP_CURSES' \
2566 'curses.h / -lcurses' ||
2567 __termcaplib -lcursesw '#include <curses.h>' '
2568 #define HAVE_TERMCAP_CURSES' \
2569 'curses.h / -lcursesw' ||
2570 feat_bail_required TERMCAP
2572 if [ -n "${have_termcap}" ]; then
2573 run_check tgetent_null \
2574 "tgetent(3) of termcap(5) takes NULL buffer" \
2575 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2576 #include <stdio.h> /* For C89 NULL */
2577 #include <stdlib.h>
2578 #ifdef HAVE_TERMCAP_CURSES
2579 # include <curses.h>
2580 #endif
2581 #include <term.h>
2582 int main(void){
2583 tgetent(NULL, getenv("TERM"));
2584 return 0;
2586 _EOT
2589 else
2590 echo '/* OPT_TERMCAP=0 */' >> ${h}
2591 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2594 if feat_def SPAM_SPAMC; then
2595 if command -v spamc >/dev/null 2>&1; then
2596 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2600 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2601 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2602 else
2603 feat_bail_required SPAM_SPAMD
2604 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2607 feat_def SPAM_FILTER
2609 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2610 echo '#define HAVE_SPAM' >> ${h}
2611 else
2612 echo '/* HAVE_SPAM */' >> ${h}
2615 if feat_yes QUOTE_FOLD &&\
2616 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2617 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2618 else
2619 feat_bail_required QUOTE_FOLD
2620 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2623 feat_def FILTER_HTML_TAGSOUP
2624 feat_def COLOUR
2625 feat_def DOTLOCK
2626 feat_def MD5
2627 feat_def NOMEMDBG
2629 ## Summarizing
2631 ${rm} -f ${tmp}
2632 squeeze_em ${inc} ${tmp}
2633 ${mv} ${tmp} ${inc}
2634 squeeze_em ${lib} ${tmp}
2635 ${mv} ${tmp} ${lib}
2637 # mk-config.h
2638 ${mv} ${h} ${tmp}
2639 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2640 ${cat} ${tmp} >> ${h}
2641 ${rm} -f ${tmp}
2642 printf '\n' >> ${h}
2644 # Create the real mk-config.mk
2645 # Note we cannout use explicit ./ filename prefix for source and object
2646 # pathnames because of a bug in bmake(1)
2647 ${rm} -rf ${tmp0}.* ${tmp0}*
2648 printf 'OBJ_SRC = ' >> ${mk}
2649 if feat_no AMALGAMATION; then
2650 for i in `printf '%s\n' *.c | ${sort}`; do
2651 if [ "${i}" = privsep.c ]; then
2652 continue
2654 printf "${i} " >> ${mk}
2655 done
2656 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2657 else
2658 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2660 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2661 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2662 printf '# undef _CONFIG_H\n' >> ${h}
2663 printf '# define _CONFIG_H 2\n' >> ${h}
2664 for i in `printf '%s\n' *.c | ${sort}`; do
2665 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2666 [ "${i}" = privsep.c ]; then
2667 continue
2669 printf "${i} " >> ${mk}
2670 printf "# include \"${i}\"\n" >> ${h}
2671 done
2672 echo >> ${mk}
2673 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2674 echo '#else' >> ${h}
2677 # Finally, create the string that is used by *features* and `version'.
2678 # Take this nice opportunity and generate a visual listing of included and
2679 # non-included features for the person who runs the configuration
2680 msg '\nThe following features are included (+) or not (-):'
2681 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2682 printf '/* The "feature string" */\n' >> ${h}
2683 # Because + is expanded by *folder* if first in "echo $features", put something
2684 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2685 sep=
2686 for opt
2688 sdoc=`option_doc_of ${opt}`
2689 [ -z "${sdoc}" ] && continue
2690 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2691 feat_yes ${opt} && sign=+ || sign=-
2692 printf -- "${sep}${sign}${sopt}" >> ${h}
2693 sep=','
2694 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2695 done
2696 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2697 #exec 5>&1 >>${h}
2698 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2699 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2701 printf '"\n#endif /* n_MK_CONFIG_H */\n' >> ${h}
2703 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2704 echo "INCS = `${cat} ${inc}`" >> ${mk}
2705 echo >> ${mk}
2706 ${cat} ./make-config.in >> ${mk}
2708 ## Finished!
2710 msg '\nSetup:'
2711 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2712 msg ' . bindir: %s' "${VAL_BINDIR}"
2713 if feat_yes DOTLOCK; then
2714 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2716 msg ' . mandir: %s' "${VAL_MANDIR}"
2717 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2718 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2719 msg ''
2721 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2722 exit 0
2724 msg 'Remarks:'
2725 if [ -z "${have_fnmatch}" ]; then
2726 msg ' . The function fnmatch(3) could not be found.'
2727 msg ' Filename patterns like wildcard are not supported on your system'
2729 if [ -z "${have_fchdir}" ]; then
2730 msg ' . The function fchdir(2) could not be found.'
2731 msg ' We will use chdir(2) instead.'
2732 msg ' This is a problem only if the current working directory is changed'
2733 msg ' while this program is inside of it'
2735 msg ''
2737 # s-it-mode