make-config.sh: actually get IMAP <> ICONV dependency right!
[s-mailx.git] / make-config.sh
blob93d9e99587d3102d253a499f4a8ccd32e5a8ab6f
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 if feat_require IMAP; then
183 msg 'ERROR: need ICONV for required feature IMAP'
184 config_exit 13
186 msg 'ERROR: disabling IMAP due to missing ICONV'
187 OPT_IMAP=0
190 if feat_no MLE; then
191 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
194 # If we don't need MD5 leave it alone
195 if feat_no SOCKETS; then
196 OPT_MD5=0
199 if feat_no TERMCAP; then
200 OPT_TERMCAP_VIA_TERMINFO=0
203 if feat_yes DEVEL; then
204 OPT_DEBUG=1
208 rc=./make.rc
209 lst=./mk-config.lst
210 ev=./mk-config.ev
211 h=./mk-config.h h_name=mk-config.h
212 mk=./mk-config.mk
214 newlst=./mk-nconfig.lst
215 newmk=./mk-nconfig.mk
216 newev=./mk-nconfig.ev
217 newh=./mk-nconfig.h
218 tmp0=___tmp
219 tmp=./${tmp0}1$$
220 tmp2=./${tmp0}2$$
222 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
224 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
225 # via path_check() later on once possible
227 # TODO cc_maxopt is brute simple, we should compile test program and dig real
228 # compiler versions for known compilers, then be more specific
229 cc_maxopt=100
230 _CFLAGS= _LDFLAGS=
232 os_early_setup() {
233 # We don't "have any utility": only path adjustments and such in here!
234 i="${OS:-`uname -s`}"
236 if [ ${i} = SunOS ]; then
237 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
238 _os_early_setup_sunos
242 _os_early_setup_sunos() {
243 # According to standards(5), this is what we need to do
244 if [ -d /usr/xpg4 ]; then :; else
245 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
246 config_exit 1
248 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
249 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
250 export PATH
253 os_setup() {
254 # OSENV ends up in *build-osenv*
255 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
256 : ${OS:=`uname -s | ${tr} '[A-Z]' '[a-z]'`}
257 : ${OSENV:=`uname -srm`}
258 : ${OSFULLSPEC:=`uname -a`}
259 msg 'Operating system is %s' ${OS}
261 if [ ${OS} = sunos ]; then
262 msg ' . have special SunOS / Solaris "setup" rules ...'
263 _os_setup_sunos
264 elif [ ${OS} = unixware ]; then
265 msg ' . have special UnixWare environmental rules ...'
266 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
267 CC=cc
268 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
270 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
271 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
272 export CC CFLAGS LDFLAGS
273 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
275 elif [ -n "${VERBOSE}" ]; then
276 msg ' . no special treatment for this system necessary or known'
279 # Sledgehammer: better set _GNU_SOURCE
280 # And in general: oh, boy!
281 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
282 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
283 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
284 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
286 # On pkgsrc(7) systems automatically add /usr/pkg/*
287 if [ -d /usr/pkg ]; then
288 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
289 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
293 _os_setup_sunos() {
294 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
295 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
297 # Include packages
298 if [ -d /opt/csw ]; then
299 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
300 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
303 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
304 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
306 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
307 if [ -x "${cksum}" ]; then :; else
308 msg 'ERROR: Not an executable program: %s' "${cksum}"
309 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
310 msg 'ERROR: However, we do so only for tests.'
311 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
312 config_exit 1
315 if feat_yes AUTOCC; then
316 if command -v cc >/dev/null 2>&1; then
317 CC=cc
318 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
320 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
321 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
322 export CC CFLAGS LDFLAGS
323 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
324 else
325 # Assume gcc(1), which supports -R for compat
326 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
331 # Check out compiler ($CC) and -flags ($CFLAGS)
332 cc_setup() {
333 # Even though it belongs into cc_flags we will try to compile and link
334 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
335 # EXTRA_CFLAGS/EXTRA_LDFLAGS
336 if feat_no AUTOCC; then
337 _cc_default
338 # Ensure those don't do any harm
339 EXTRA_CFLAGS= EXTRA_LDFLAGS=
340 export EXTRA_CFLAGS EXTRA_LDFLAGS
341 return
342 else
343 CFLAGS= LDFLAGS=
344 export CFLAGS LDFLAGS
347 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
349 msg_nonl 'Searching for a usable C compiler .. $CC='
350 if { i="`command -v clang`"; }; then
351 CC=${i}
352 elif { i="`command -v gcc`"; }; then
353 CC=${i}
354 elif { i="`command -v c99`"; }; then
355 CC=${i}
356 elif { i="`command -v tcc`"; }; then
357 CC=${i}
358 elif { i="`command -v pcc`"; }; then
359 CC=${i}
360 else
361 if [ "${CC}" = cc ]; then
363 elif { i="`command -v c89`"; }; then
364 CC=${i}
365 else
366 msg 'boing booom tschak'
367 msg 'ERROR: I cannot find a compiler!'
368 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
369 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
370 config_exit 1
373 msg '%s' "${CC}"
374 export CC
377 _cc_default() {
378 if [ -z "${CC}" ]; then
379 msg 'To go on like you have chosen, please set $CC, rerun.'
380 config_exit 1
383 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
385 else
386 msg 'Using C compiler ${CC}=%s' "${CC}"
390 cc_flags() {
391 if feat_yes AUTOCC; then
392 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
393 cc_check_silent=1
394 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
395 "${CC}"
396 else
397 cc_check_silent=
398 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
401 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
402 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
403 msg ' . have special tcc(1) environmental rules ...'
404 _cc_flags_tcc
405 else
406 # As of pcc CVS 2016-04-02, stack protection support is announced but
407 # will break if used on Linux
408 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
409 force_no_stackprot=1
411 _cc_flags_generic
414 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
415 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
416 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
417 else
418 if feat_no DEBUG; then
419 CFLAGS="-DNDEBUG ${CFLAGS}"
422 msg ''
423 export CFLAGS LDFLAGS
426 _cc_flags_tcc() {
427 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
428 _CFLAGS= _LDFLAGS=
430 cc_check -Wall
431 cc_check -Wextra
432 cc_check -pedantic
434 if feat_yes DEBUG; then
435 # May have problems to find libtcc cc_check -b
436 cc_check -g
439 if ld_check -Wl,-rpath =./ no; then
440 need_R_ldflags=-Wl,-rpath=
441 ld_check -Wl,--enable-new-dtags
442 ld_runtime_flags # update!
445 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
446 unset __cflags __ldflags
449 _cc_flags_generic() {
450 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
451 _CFLAGS= _LDFLAGS=
452 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
454 # Check -g first since some others may rely upon -g / optim. level
455 if feat_yes DEBUG; then
456 cc_check -O
457 cc_check -g
458 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
460 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
462 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
464 else
465 cc_check -O
468 if feat_yes AMALGAMATION; then
469 cc_check -pipe
472 #if feat_yes DEVEL && cc_check -Weverything; then
474 #else
475 cc_check -Wall
476 cc_check -Wextra
477 cc_check -Wbad-function-cast
478 cc_check -Wcast-align
479 cc_check -Wcast-qual
480 cc_check -Winit-self
481 cc_check -Wmissing-prototypes
482 cc_check -Wshadow
483 cc_check -Wunused
484 cc_check -Wwrite-strings
485 cc_check -Wno-long-long
487 cc_check -pedantic
489 if feat_yes AMALGAMATION && feat_no DEVEL; then
490 cc_check -Wno-unused-function
492 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
494 cc_check -fno-unwind-tables
495 cc_check -fno-asynchronous-unwind-tables
496 cc_check -fstrict-aliasing
497 if cc_check -fstrict-overflow && feat_yes DEVEL; then
498 cc_check -Wstrict-overflow=5
501 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
502 if [ -z "${force_no_stackprot}" ]; then
503 if cc_check -fstack-protector-strong ||
504 cc_check -fstack-protector-all; then
505 cc_check -D_FORTIFY_SOURCE=2
507 else
508 msg 'Not checking for -fstack-protector compiler option,'
509 msg 'since that caused errors in a "similar" configuration.'
510 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
514 # LD (+ dependend CC)
516 if feat_yes ASAN_ADDRESS; then
517 _ccfg=${_CFLAGS}
518 if cc_check -fsanitize=address &&
519 ld_check -fsanitize=address; then
521 else
522 feat_bail_required ASAN_ADDRESS
523 _CFLAGS=${_ccfg}
527 if feat_yes ASAN_MEMORY; then
528 _ccfg=${_CFLAGS}
529 if cc_check -fsanitize=memory &&
530 ld_check -fsanitize=memory &&
531 cc_check -fsanitize-memory-track-origins=2 &&
532 ld_check -fsanitize-memory-track-origins=2; then
534 else
535 feat_bail_required ASAN_MEMORY
536 _CFLAGS=${_ccfg}
540 ld_check -Wl,-z,relro
541 ld_check -Wl,-z,now
542 ld_check -Wl,-z,noexecstack
543 if ld_check -Wl,-rpath =./ no; then
544 need_R_ldflags=-Wl,-rpath=
545 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
546 ld_check -Wl,--enable-new-dtags
547 ld_runtime_flags # update!
548 elif ld_check -Wl,-R ./ no; then
549 need_R_ldflags=-Wl,-R
550 ld_check -Wl,--enable-new-dtags
551 ld_runtime_flags # update!
554 # Address randomization
555 _ccfg=${_CFLAGS}
556 if cc_check -fPIE || cc_check -fpie; then
557 ld_check -pie || _CFLAGS=${_ccfg}
559 unset _ccfg
561 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
562 unset __cflags __ldflags
565 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
567 ## Notes:
568 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
569 ## redirection, so use "printf '' >" instead
571 ## Very first: we undergo several states regarding I/O redirection etc.,
572 ## but need to deal with option updates from within all. Since all the
573 ## option stuff should be above the scissor line, define utility functions
574 ## and redefine them as necessary.
575 ## And, since we have those functions, simply use them for whatever
577 config_exit() {
578 exit ${1}
581 msg() {
582 fmt=${1}
583 shift
584 printf >&2 -- "${fmt}\\n" "${@}"
587 msg_nonl() {
588 fmt=${1}
589 shift
590 printf >&2 -- "${fmt}" "${@}"
593 t1=ten10one1ten10one1
594 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
595 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
596 ) > /dev/null 2>&1; then
597 good_shell=1
598 else
599 unset good_shell
601 unset t1
603 # We need some standard utilities
604 unset -f command
605 check_tool() {
606 n=${1} i=${2} opt=${3:-0}
607 # Evaluate, just in case user comes in with shell snippets (..well..)
608 eval i="${i}"
609 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
610 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
611 eval ${n}=${i}
612 return 0
614 if [ ${opt} -eq 0 ]; then
615 msg 'ERROR: no trace of utility %s' "${n}"
616 config_exit 1
618 return 1
621 # Our feature check environment
622 feat_val_no() {
623 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
624 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
627 feat_val_yes() {
628 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
629 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
630 [ "x${1}" = xrequire ]
633 feat_val_require() {
634 [ "x${1}" = xrequire ]
637 _feat_check() {
638 eval i=\$OPT_${1}
639 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
640 if feat_val_no "${i}"; then
641 return 1
642 elif feat_val_yes "${i}"; then
643 return 0
644 else
645 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
646 "${1}" "${i}"
647 config_exit 11
651 feat_yes() {
652 _feat_check ${1}
655 feat_no() {
656 _feat_check ${1} && return 1
657 return 0
660 feat_require() {
661 eval i=\$OPT_${1}
662 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
663 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
666 feat_bail_required() {
667 if feat_require ${1}; then
668 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
669 config_exit 13
671 eval OPT_${1}=0
672 option_update # XXX this is rather useless here (dependency chain..)
675 option_parse() {
676 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
677 # options, without documentation, to $1
678 j=\'
679 i="`${awk} -v input=\"${2}\" '
680 BEGIN{
681 for(i = 0;;){
682 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
683 if(voff == 0)
684 break
685 v = substr(input, voff, RLENGTH)
686 input = substr(input, voff + RLENGTH)
687 doff = index(v, "=")
688 if(doff > 0){
689 d = substr(v, doff + 2, length(v) - doff - 1)
690 v = substr(v, 1, doff - 1)
692 print v
696 eval ${1}=\"${i}\"
699 option_doc_of() {
700 # Return the "documentation string" for option $1, itself if none such
701 j=\'
702 ${awk} -v want="${1}" \
703 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
704 BEGIN{
705 for(;;){
706 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
707 if(voff == 0)
708 break
709 v = substr(input, voff, RLENGTH)
710 input = substr(input, voff + RLENGTH)
711 doff = index(v, "=")
712 if(doff > 0){
713 d = substr(v, doff + 2, length(v) - doff - 1)
714 v = substr(v, 1, doff - 1)
715 }else
716 d = v
717 if(v == want){
718 if(d != "-")
719 print d
720 exit
727 option_join_rc() {
728 # Join the values from make.rc into what currently is defined, not
729 # overwriting yet existing settings
730 ${rm} -f ${tmp}
731 # We want read(1) to perform reverse solidus escaping in order to be able to
732 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
733 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
734 < ${rc} ${awk} 'BEGIN{line = ""}{
735 gsub(/^[[:space:]]+/, "", $0)
736 gsub(/[[:space:]]+$/, "", $0)
737 if(gsub(/\\$/, "", $0)){
738 line = line $0
739 next
740 }else
741 line = line $0
742 if(index(line, "#") == 1){
743 line = ""
744 }else if(length(line)){
745 print line
746 line = ""
748 }' |
749 while read line; do
750 if [ -n "${good_shell}" ]; then
751 i=${line%%=*}
752 else
753 i=`${awk} -v LINE="${line}" 'BEGIN{
754 gsub(/=.*$/, "", LINE)
755 print LINE
758 if [ "${i}" = "${line}" ]; then
759 msg 'ERROR: invalid syntax in: %s' "${line}"
760 continue
763 eval j="\$${i}" jx="\${${i}+x}"
764 if [ -n "${j}" ] || [ "${jx}" = x ]; then
765 : # Yet present
766 else
767 j=`${awk} -v LINE="${line}" 'BEGIN{
768 gsub(/^[^=]*=/, "", LINE)
769 gsub(/^\"*/, "", LINE)
770 gsub(/\"*$/, "", LINE)
771 print LINE
774 [ "${i}" = "DESTDIR" ] && continue
775 echo "${i}=\"${j}\""
776 done > ${tmp}
777 # Reread the mixed version right now
778 . ./${tmp}
781 option_evaluate() {
782 # Expand the option values, which may contain shell snippets
783 ${rm} -f ${newlst} ${newmk} ${newh}
784 exec 5<&0 6>&1 <${tmp} >${newlst}
785 while read line; do
787 if [ -n "${good_shell}" ]; then
788 i=${line%%=*}
789 [ "${i}" != "${i#OPT_}" ] && z=1
790 else
791 i=`${awk} -v LINE="${line}" 'BEGIN{
792 gsub(/=.*$/, "", LINE);\
793 print LINE
795 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
800 eval j=\$${i}
801 if [ -n "${z}" ]; then
802 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
803 if [ -z "${j}" ] || feat_val_no "${j}"; then
805 printf " /* #undef ${i} */\n" >> ${newh}
806 elif feat_val_yes "${j}"; then
807 if feat_val_require "${j}"; then
808 j=require
809 else
812 printf " /* #define ${i} */\n" >> ${newh}
813 else
814 msg 'ERROR: cannot parse <%s>' "${line}"
815 config_exit 1
817 else
818 printf "#define ${i} \"${j}\"\n" >> ${newh}
820 printf "${i} = ${j}\n" >> ${newmk}
821 printf "${i}=${j}\n"
822 eval "${i}=\"${j}\""
823 done
824 exec 0<&5 1>&6 5<&- 6<&-
827 path_check() {
828 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
829 varname=${1} addflag=${2} flagvarname=${3}
830 j=${IFS}
831 IFS=:
832 eval "set -- \$${1}"
833 IFS=${j}
834 j= k= y= z=
835 for i
837 [ -z "${i}" ] && continue
838 [ -d "${i}" ] || continue
839 # Skip any fakeroot packager environment
840 case "${i}" in *fakeroot*) continue;; esac
841 if [ -n "${j}" ]; then
842 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
844 else
845 y="${y} :${i}:"
846 j="${j}:${i}"
847 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
849 else
850 y=" :${i}:"
851 j="${i}"
852 [ -n "${addflag}" ] && k="${addflag}${i}"
854 done
855 eval "${varname}=\"${j}\""
856 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
857 unset varname
860 ld_runtime_flags() {
861 if [ -n "${need_R_ldflags}" ]; then
862 i=${IFS}
863 IFS=:
864 set -- ${LD_LIBRARY_PATH}
865 IFS=${i}
866 for i
868 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
869 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
870 done
871 export LDFLAGS
873 # Disable it for a possible second run.
874 need_R_ldflags=
877 cc_check() {
878 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
879 if "${CC}" ${INCS} \
880 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
881 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
882 _CFLAGS="${_CFLAGS} ${1}"
883 [ -n "${cc_check_silent}" ] || msg 'yes'
884 return 0
886 [ -n "${cc_check_silent}" ] || msg 'no'
887 return 1
890 ld_check() {
891 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
892 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
893 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
894 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
895 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
896 [ -n "${cc_check_silent}" ] || msg 'yes'
897 return 0
899 [ -n "${cc_check_silent}" ] || msg 'no'
900 return 1
903 _check_preface() {
904 variable=$1 topic=$2 define=$3
906 echo '**********'
907 msg_nonl ' . %s ... ' "${topic}"
908 echo "/* checked ${topic} */" >> ${h}
909 ${rm} -f ${tmp} ${tmp}.o
910 echo '*** test program is'
911 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
912 #echo '*** the preprocessor generates'
913 #${make} -f ${makefile} ${tmp}.x
914 #${cat} ${tmp}.x
915 echo '*** results are'
918 without_check() {
919 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
921 echo '**********'
922 msg_nonl ' . %s ... ' "${topic}"
924 echo '*** enforced unchecked results are'
925 if feat_val_yes ${yesno}; then
926 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
927 echo "*** adding INCS<${incs}> LIBS<${libs}>"
928 LIBS="${LIBS} ${libs}"
929 echo "${libs}" >> ${lib}
930 INCS="${INCS} ${incs}"
931 echo "${incs}" >> ${inc}
933 msg 'yes (deduced)'
934 echo "${define}" >> ${h}
935 eval have_${variable}=yes
936 return 0
937 else
938 echo "/* ${define} */" >> ${h}
939 msg 'no (deduced)'
940 eval unset have_${variable}
941 return 1
945 compile_check() {
946 variable=$1 topic=$2 define=$3
948 _check_preface "${variable}" "${topic}" "${define}"
950 if ${make} -f ${makefile} XINCS="${INCS}" \
951 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
952 ./${tmp}.o &&
953 [ -f ./${tmp}.o ]; then
954 msg 'yes'
955 echo "${define}" >> ${h}
956 eval have_${variable}=yes
957 return 0
958 else
959 echo "/* ${define} */" >> ${h}
960 msg 'no'
961 eval unset have_${variable}
962 return 1
966 _link_mayrun() {
967 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
969 _check_preface "${variable}" "${topic}" "${define}"
971 if feat_yes CROSS_BUILD; then
972 if [ ${run} = 1 ]; then
973 run=0
977 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
978 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
979 XLIBS="${LIBS} ${libs}" \
980 ./${tmp} &&
981 [ -f ./${tmp} ] &&
982 { [ ${run} -eq 0 ] || ./${tmp}; }; then
983 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
984 msg 'yes'
985 echo "${define}" >> ${h}
986 LIBS="${LIBS} ${libs}"
987 echo "${libs}" >> ${lib}
988 INCS="${INCS} ${incs}"
989 echo "${incs}" >> ${inc}
990 eval have_${variable}=yes
991 return 0
992 else
993 msg 'no'
994 echo "/* ${define} */" >> ${h}
995 eval unset have_${variable}
996 return 1
1000 link_check() {
1001 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1004 run_check() {
1005 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1008 xrun_check() {
1009 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1012 feat_def() {
1013 if feat_yes ${1}; then
1014 echo '#define HAVE_'${1}'' >> ${h}
1015 return 0
1016 else
1017 echo '/* OPT_'${1}'=0 */' >> ${h}
1018 return 1
1022 squeeze_em() {
1023 < "${1}" > "${2}" ${awk} \
1024 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1027 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1029 # First of all, create new configuration and check whether it changed
1031 # Very easy checks for the operating system in order to be able to adjust paths
1032 # or similar very basic things which we need to be able to go at all
1033 os_early_setup
1035 # Check those tools right now that we need before including $rc
1036 msg 'Checking for basic utility set'
1037 check_tool awk "${awk:-`command -v awk`}"
1038 check_tool rm "${rm:-`command -v rm`}"
1039 check_tool tr "${tr:-`command -v tr`}"
1041 # Initialize the option set
1042 msg_nonl 'Setting up configuration options ... '
1043 option_setup
1044 msg 'done'
1046 # Include $rc, but only take from it what wasn't overwritten by the user from
1047 # within the command line or from a chosen fixed CONFIG=
1048 # Note we leave alone the values
1049 trap "exit 1" HUP INT TERM
1050 trap "${rm} -f ${tmp}" EXIT
1052 msg_nonl 'Joining in %s ... ' ${rc}
1053 option_join_rc
1054 msg 'done'
1056 # We need to know about that now, in order to provide utility overwrites etc.
1057 os_setup
1059 msg 'Checking for remaining set of utilities'
1060 check_tool grep "${grep:-`command -v grep`}"
1062 # Before we step ahead with the other utilities perform a path cleanup first.
1063 path_check PATH
1065 # awk(1) above
1066 check_tool cat "${cat:-`command -v cat`}"
1067 check_tool chmod "${chmod:-`command -v chmod`}"
1068 check_tool cp "${cp:-`command -v cp`}"
1069 check_tool cmp "${cmp:-`command -v cmp`}"
1070 # grep(1) above
1071 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1072 check_tool mv "${mv:-`command -v mv`}"
1073 # rm(1) above
1074 check_tool sed "${sed:-`command -v sed`}"
1075 check_tool sort "${sort:-`command -v sort`}"
1076 check_tool tee "${tee:-`command -v tee`}"
1078 check_tool chown "${chown:-`command -v chown`}" 1 ||
1079 check_tool chown "/sbin/chown" 1 ||
1080 check_tool chown "/usr/sbin/chown"
1082 check_tool make "${MAKE:-`command -v make`}"
1083 MAKE=${make}
1084 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1085 HAVE_STRIP=1 || HAVE_STRIP=0
1087 # For ./cc-test.sh only
1088 check_tool cksum "${cksum:-`command -v cksum`}"
1090 # Update OPT_ options now, in order to get possible inter-dependencies right
1091 option_update
1093 # (No functions since some shells loose non-exported variables in traps)
1094 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1095 trap "trap \"\" HUP INT TERM EXIT;\
1096 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1098 # Our configuration options may at this point still contain shell snippets,
1099 # we need to evaluate them in order to get them expanded, and we need those
1100 # evaluated values not only in our new configuration file, but also at hand..
1101 msg_nonl 'Evaluating all configuration items ... '
1102 option_evaluate
1103 msg 'done'
1105 # Add the known utility and some other variables
1106 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1107 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1109 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1110 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1111 if feat_yes DOTLOCK; then
1112 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1113 else
1114 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1117 for i in \
1118 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1119 MAKE MAKEFLAGS make SHELL strip \
1120 cksum; do
1121 eval j=\$${i}
1122 printf "${i} = ${j}\n" >> ${newmk}
1123 printf "${i}=${j}\n" >> ${newlst}
1124 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1125 done
1126 printf "\n" >> ${newev}
1128 # Build a basic set of INCS and LIBS according to user environment.
1129 path_check C_INCLUDE_PATH -I _INCS
1130 INCS="${INCS} ${_INCS}"
1131 path_check LD_LIBRARY_PATH -L _LIBS
1132 LIBS="${LIBS} ${_LIBS}"
1133 unset _INCS _LIBS
1134 export C_INCLUDE_PATH LD_LIBRARY_PATH
1136 # Some environments need runtime path flags to be able to go at all
1137 ld_runtime_flags
1139 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1141 cc_setup
1143 ${cat} > ${tmp}.c << \!
1144 #include <stdio.h>
1145 #include <string.h>
1146 static void doit(char const *s);
1148 main(int argc, char **argv){
1149 (void)argc;
1150 (void)argv;
1151 doit("Hello world");
1152 return 0;
1154 static void
1155 doit(char const *s){
1156 char buf[12];
1157 memcpy(buf, s, strlen(s) +1);
1158 puts(s);
1162 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1163 -o ${tmp2} ${tmp}.c ${LIBS}; then
1165 else
1166 msg 'ERROR: i cannot compile a "Hello world" via'
1167 msg ' %s' \
1168 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1169 msg 'ERROR: Please read INSTALL, rerun'
1170 config_exit 1
1173 # This may also update ld_runtime_flags() (again)
1174 cc_flags
1176 for i in \
1177 INCS LIBS \
1178 ; do
1179 eval j=\$${i}
1180 printf -- "${i}=${j}\n" >> ${newlst}
1181 done
1182 for i in \
1183 CC \
1184 CFLAGS \
1185 LDFLAGS \
1186 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1187 OSFULLSPEC \
1188 ; do
1189 eval j=\$${i}
1190 printf -- "${i} = ${j}\n" >> ${newmk}
1191 printf -- "${i}=${j}\n" >> ${newlst}
1192 done
1194 # Now finally check whether we already have a configuration and if so, whether
1195 # all those parameters are still the same.. or something has actually changed
1196 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1197 echo 'Configuration is up-to-date'
1198 exit 0
1199 elif [ -f ${lst} ]; then
1200 echo 'Configuration has been updated..'
1201 ( eval "${MAKE} -f ./mk-config.mk clean" )
1202 echo
1203 else
1204 echo 'Shiny configuration..'
1207 # Time to redefine helper 1
1208 config_exit() {
1209 ${rm} -f ${lst} ${h} ${mk}
1210 exit ${1}
1213 ${mv} -f ${newlst} ${lst}
1214 ${mv} -f ${newev} ${ev}
1215 ${mv} -f ${newh} ${h}
1216 ${mv} -f ${newmk} ${mk}
1218 if [ -z "${VERBOSE}" ]; then
1219 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1220 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1221 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1222 printf -- "ECHO_TEST = @\n" >> ${mk}
1223 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1224 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1225 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1228 ## Compile and link checking
1230 tmp3=./${tmp0}3$$
1231 log=./mk-config.log
1232 lib=./mk-config.lib
1233 inc=./mk-config.inc
1234 makefile=./${tmp0}.mk
1236 # (No function since some shells loose non-exported variables in traps)
1237 trap "trap \"\" HUP INT TERM;\
1238 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1239 trap "trap \"\" HUP INT TERM EXIT;\
1240 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1242 # Time to redefine helper 2
1243 msg() {
1244 fmt=${1}
1245 shift
1246 printf "*** ${fmt}\\n" "${@}"
1247 printf -- "${fmt}\\n" "${@}" >&5
1249 msg_nonl() {
1250 fmt=${1}
1251 shift
1252 printf "*** ${fmt}\\n" "${@}"
1253 printf -- "${fmt}" "${@}" >&5
1256 # !!
1257 exec 5>&2 > ${log} 2>&1
1259 echo "${LIBS}" > ${lib}
1260 echo "${INCS}" > ${inc}
1261 ${cat} > ${makefile} << \!
1262 .SUFFIXES: .o .c .x .y
1263 .c.o:
1264 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1265 .c.x:
1266 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1268 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1271 ## Generics
1273 # May be multiline..
1274 echo >> ${h}
1275 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1276 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1277 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1279 # Generate n_err_number OS mappings
1281 feat_yes DEVEL && NV= || NV=noverbose
1282 TARGET="${h}" awk="${awk}" ./make-errors.sh ${NV} config
1284 xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1286 feat_def ALWAYS_UNICODE_LOCALE
1287 feat_def AMALGAMATION
1288 feat_def CROSS_BUILD
1289 feat_def DOCSTRINGS
1290 feat_def ERRORS
1292 feat_def ASAN_ADDRESS
1293 feat_def ASAN_MEMORY
1294 feat_def DEBUG
1295 feat_def DEVEL
1296 feat_def NYD2
1297 feat_def NOMEMDBG
1299 if xrun_check inline 'inline functions' \
1300 '#define HAVE_INLINE
1301 #define n_INLINE static inline' << \!
1302 static inline int ilf(int i){return ++i;}
1303 int main(void){return ilf(-1);}
1305 then
1307 elif xrun_check inline 'inline functions (via __inline)' \
1308 '#define HAVE_INLINE
1309 #define n_INLINE static __inline' << \!
1310 static __inline int ilf(int i){return ++i;}
1311 int main(void){return ilf(-1);}
1313 then
1317 ## Test for "basic" system-calls / functionality that is used by all parts
1318 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1319 ## macros to be used by only the subprograms (potentially).
1321 if run_check clock_gettime 'clock_gettime(2)' \
1322 '#define HAVE_CLOCK_GETTIME' << \!
1323 #include <time.h>
1324 # include <errno.h>
1325 int main(void){
1326 struct timespec ts;
1328 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1329 return 0;
1330 return 1;
1333 then
1335 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1336 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1337 #include <time.h>
1338 # include <errno.h>
1339 int main(void){
1340 struct timespec ts;
1342 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1343 return 0;
1344 return 1;
1347 then
1349 elif run_check gettimeofday 'gettimeofday(2)' \
1350 '#define HAVE_GETTIMEOFDAY' << \!
1351 #include <stdio.h> /* For C89 NULL */
1352 #include <sys/time.h>
1353 # include <errno.h>
1354 int main(void){
1355 struct timeval tv;
1357 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1358 return 0;
1359 return 1;
1362 then
1364 else
1365 have_no_subsecond_time=1
1368 if run_check nanosleep 'nanosleep(2)' \
1369 '#define HAVE_NANOSLEEP' << \!
1370 #include <time.h>
1371 # include <errno.h>
1372 int main(void){
1373 struct timespec ts;
1375 ts.tv_sec = 1;
1376 ts.tv_nsec = 100000;
1377 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1378 return 0;
1379 return 1;
1382 then
1384 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1385 '#define HAVE_NANOSLEEP' '-lrt' << \!
1386 #include <time.h>
1387 # include <errno.h>
1388 int main(void){
1389 struct timespec ts;
1391 ts.tv_sec = 1;
1392 ts.tv_nsec = 100000;
1393 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1394 return 0;
1395 return 1;
1398 then
1400 # link_check is enough for this, that function is so old, trust the proto
1401 elif link_check sleep 'sleep(3)' \
1402 '#define HAVE_SLEEP' << \!
1403 #include <unistd.h>
1404 # include <errno.h>
1405 int main(void){
1406 if(!sleep(1) || errno != ENOSYS)
1407 return 0;
1408 return 1;
1411 then
1413 else
1414 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1415 config_exit 1
1418 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1419 #include <pwd.h>
1420 #include <unistd.h>
1421 # include <errno.h>
1422 int main(void){
1423 struct passwd *pw;
1424 gid_t gid;
1425 uid_t uid;
1427 if((gid = getgid()) != 0)
1428 gid = getegid();
1429 if((uid = getuid()) != 0)
1430 uid = geteuid();
1431 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1432 return 1;
1433 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1434 return 1;
1435 return 0;
1438 then
1440 else
1441 msg 'ERROR: we require user and group info / database searches.'
1442 msg 'That much Unix we indulge ourselfs.'
1443 config_exit 1
1446 if link_check ftruncate 'ftruncate(2)' \
1447 '#define HAVE_FTRUNCATE' << \!
1448 #include <unistd.h>
1449 #include <sys/types.h>
1450 int main(void){
1451 return (ftruncate(0, 0) != 0);
1454 then
1456 else
1457 msg 'ERROR: we require the ftruncate(2) system call.'
1458 config_exit 1
1461 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1462 #include <signal.h>
1463 # include <errno.h>
1464 int main(void){
1465 struct sigaction nact, oact;
1467 nact.sa_handler = SIG_DFL;
1468 sigemptyset(&nact.sa_mask);
1469 nact.sa_flags = SA_RESTART;
1470 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1473 then
1475 else
1476 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1477 config_exit 1
1480 if link_check snprintf 'snprintf(3)' << \!
1481 #include <stdio.h>
1482 int main(void){
1483 char b[20];
1485 snprintf(b, sizeof b, "%s", "string");
1486 return 0;
1489 then
1491 else
1492 msg 'ERROR: we require the snprintf(3) function.'
1493 config_exit 1
1496 if link_check environ 'environ(3)' << \!
1497 #include <stdio.h> /* For C89 NULL */
1498 int main(void){
1499 extern char **environ;
1501 return environ[0] == NULL;
1504 then
1506 else
1507 msg 'ERROR: we require the environ(3) array for subprocess control.'
1508 config_exit 1
1511 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1512 #include <stdlib.h>
1513 int main(void){
1514 setenv("s-mailx", "i want to see it cute!", 1);
1515 unsetenv("s-mailx");
1516 return 0;
1519 then
1521 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1522 #include <stdlib.h>
1523 int main(void){
1524 putenv("s-mailx=i want to see it cute!");
1525 return 0;
1528 then
1530 else
1531 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1532 config_exit 1
1535 if link_check termios 'termios.h and tc*(3) family' << \!
1536 #include <termios.h>
1537 int main(void){
1538 struct termios tios;
1540 tcgetattr(0, &tios);
1541 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1542 return 0;
1545 then
1547 else
1548 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1549 msg 'That much Unix we indulge ourselfs.'
1550 config_exit 1
1553 ## optional stuff
1555 if link_check vsnprintf 'vsnprintf(3)' << \!
1556 #include <stdarg.h>
1557 #include <stdio.h>
1558 static void dome(char *buf, size_t blen, ...){
1559 va_list ap;
1561 va_start(ap, blen);
1562 vsnprintf(buf, blen, "%s", ap);
1563 va_end(ap);
1565 int main(void){
1566 char b[20];
1568 dome(b, sizeof b, "string");
1569 return 0;
1572 then
1574 else
1575 feat_bail_required ERRORS
1578 if [ "${have_vsnprintf}" = yes ]; then
1579 __va_copy() {
1580 link_check va_copy "va_copy(3) (as ${2})" \
1581 "#define HAVE_N_VA_COPY
1582 #define n_va_copy ${2}" <<_EOT
1583 #include <stdarg.h>
1584 #include <stdio.h>
1585 #if ${1}
1586 # if defined __va_copy && !defined va_copy
1587 # define va_copy __va_copy
1588 # endif
1589 #endif
1590 static void dome2(char *buf, size_t blen, va_list src){
1591 va_list ap;
1593 va_copy(ap, src);
1594 vsnprintf(buf, blen, "%s", ap);
1595 va_end(ap);
1597 static void dome(char *buf, size_t blen, ...){
1598 va_list ap;
1600 va_start(ap, blen);
1601 dome2(buf, blen, ap);
1602 va_end(ap);
1604 int main(void){
1605 char b[20];
1607 dome(b, sizeof b, "string");
1608 return 0;
1610 _EOT
1612 __va_copy 0 va_copy || __va_copy 1 __va_copy
1615 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1616 #include <unistd.h>
1617 #include <errno.h>
1618 int main(void){
1619 int rv = 0;
1621 errno = 0;
1622 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1623 errno = 0;
1624 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1626 /* Only link check */
1627 fpathconf(0, _PC_NAME_MAX);
1629 return rv;
1633 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1634 #include <fcntl.h>
1635 #include <unistd.h>
1636 # include <errno.h>
1637 int main(void){
1638 int fds[2];
1640 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1641 return 0;
1642 return 1;
1646 # We use this only then for now (need NOW+1)
1647 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1648 #include <fcntl.h> /* For AT_* */
1649 #include <sys/stat.h>
1650 # include <errno.h>
1651 int main(void){
1652 struct timespec ts[2];
1654 ts[0].tv_nsec = UTIME_NOW;
1655 ts[1].tv_nsec = UTIME_OMIT;
1656 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1657 return 0;
1658 return 1;
1664 # XXX Add POSIX check once standardized
1665 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1666 #include <stdlib.h>
1667 int main(void){
1668 arc4random();
1669 return 0;
1672 then
1674 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1675 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1676 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1677 #include <sys/random.h>
1678 int main(void){
1679 char buf[256];
1680 getrandom(buf, sizeof buf, 0);
1681 return 0;
1684 then
1686 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1687 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1688 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1689 #include <sys/syscall.h>
1690 int main(void){
1691 char buf[256];
1692 syscall(SYS_getrandom, buf, sizeof buf, 0);
1693 return 0;
1696 then
1698 elif [ -n "${have_no_subsecond_time}" ]; then
1699 msg 'ERROR: %s %s' 'without a native random' \
1700 'one of clock_gettime(2) and gettimeofday(2) is required.'
1701 config_exit 1
1705 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1706 #include <stdio.h>
1707 int main(void){
1708 putc_unlocked('@', stdout);
1709 return 0;
1713 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1714 #include <unistd.h>
1715 int main(void){
1716 fchdir(0);
1717 return 0;
1721 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1722 #include <stdlib.h>
1723 int main(void){
1724 char x_buf[4096], *x = realpath(".", x_buf);
1726 return (x != NULL) ? 0 : 1;
1729 then
1730 if run_check realpath_malloc 'realpath(3) takes NULL' \
1731 '#define HAVE_REALPATH_NULL' << \!
1732 #include <stdlib.h>
1733 int main(void){
1734 char *x = realpath(".", NULL);
1736 if(x != NULL)
1737 free(x);
1738 return (x != NULL) ? 0 : 1;
1741 then
1746 ## optional and selectable
1748 if feat_yes DOTLOCK; then
1749 if run_check readlink 'readlink(2)' << \!
1750 #include <unistd.h>
1751 # include <errno.h>
1752 int main(void){
1753 char buf[128];
1755 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1756 return 0;
1757 return 1;
1760 then
1762 else
1763 feat_bail_required DOTLOCK
1767 if feat_yes DOTLOCK; then
1768 if run_check fchown 'fchown(2)' << \!
1769 #include <unistd.h>
1770 # include <errno.h>
1771 int main(void){
1772 if(!fchown(0, 0, 0) || errno != ENOSYS)
1773 return 0;
1774 return 1;
1777 then
1779 else
1780 feat_bail_required DOTLOCK
1784 ## Now it is the time to fork away the BASE_ series
1786 ${rm} -f ${tmp}
1787 squeeze_em ${inc} ${tmp}
1788 ${mv} ${tmp} ${inc}
1789 squeeze_em ${lib} ${tmp}
1790 ${mv} ${tmp} ${lib}
1792 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1793 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1795 ## The remains are expected to be used only by the main MUA binary!
1797 OPT_LOCALES=0
1798 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1799 #include <locale.h>
1800 int main(void){
1801 setlocale(LC_ALL, "");
1802 return 0;
1805 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1807 OPT_MULTIBYTE_CHARSETS=0
1808 OPT_WIDE_GLYPHS=0
1809 OPT_TERMINAL_CHARSET=0
1810 if [ -n "${have_setlocale}" ]; then
1811 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1812 '#define HAVE_C90AMEND1' << \!
1813 #include <limits.h>
1814 #include <stdlib.h>
1815 #include <wchar.h>
1816 #include <wctype.h>
1817 int main(void){
1818 char mbb[MB_LEN_MAX + 1];
1819 wchar_t wc;
1821 iswprint(L'c');
1822 towupper(L'c');
1823 mbtowc(&wc, "x", 1);
1824 mbrtowc(&wc, "x", 1, NULL);
1825 wctomb(mbb, wc);
1826 return (mblen("\0", 1) == 0);
1829 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1831 if [ -n "${have_c90amend1}" ]; then
1832 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1833 #include <wchar.h>
1834 int main(void){
1835 wcwidth(L'c');
1836 return 0;
1839 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1842 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1843 #include <langinfo.h>
1844 #include <stdlib.h>
1845 int main(void){
1846 nl_langinfo(DAY_1);
1847 return (nl_langinfo(CODESET) == NULL);
1850 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1851 fi # have_setlocale
1853 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1854 #include <fnmatch.h>
1855 int main(void){
1856 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1860 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1861 #include <dirent.h>
1862 int main(void){
1863 struct dirent de;
1864 return !(de.d_type == DT_UNKNOWN ||
1865 de.d_type == DT_DIR || de.d_type == DT_LNK);
1869 ## optional and selectable
1871 if feat_yes ICONV; then
1872 ${cat} > ${tmp2}.c << \!
1873 #include <stdio.h> /* For C89 NULL */
1874 #include <iconv.h>
1875 int main(void){
1876 iconv_t id;
1878 id = iconv_open("foo", "bar");
1879 iconv(id, NULL, NULL, NULL, NULL);
1880 iconv_close(id);
1881 return 0;
1884 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1885 '#define HAVE_ICONV' ||
1886 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1887 '#define HAVE_ICONV' '-liconv' ||
1888 feat_bail_required ICONV
1889 else
1890 echo '/* OPT_ICONV=0 */' >> ${h}
1891 fi # feat_yes ICONV
1893 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1894 ${cat} > ${tmp2}.c << \!
1895 #include <sys/types.h>
1896 #include <sys/socket.h>
1897 #include <sys/un.h>
1898 # include <errno.h>
1899 int main(void){
1900 struct sockaddr_un soun;
1902 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1903 return 1;
1904 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1905 return 1;
1906 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1907 return 1;
1908 return 0;
1912 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1913 '#define HAVE_UNIX_SOCKETS' ||
1914 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1915 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1916 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1917 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1920 if feat_yes SOCKETS; then
1921 ${cat} > ${tmp2}.c << \!
1922 #include <sys/types.h>
1923 #include <sys/socket.h>
1924 #include <netinet/in.h>
1925 # include <errno.h>
1926 int main(void){
1927 struct sockaddr s;
1929 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1930 return 1;
1931 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1932 return 1;
1933 return 0;
1937 < ${tmp2}.c run_check sockets 'sockets' \
1938 '#define HAVE_SOCKETS' ||
1939 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1940 '#define HAVE_SOCKETS' '-lnsl' ||
1941 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1942 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1943 feat_bail_required SOCKETS
1944 else
1945 echo '/* OPT_SOCKETS=0 */' >> ${h}
1946 fi # feat_yes SOCKETS
1948 if feat_yes SOCKETS; then
1949 link_check getaddrinfo 'getaddrinfo(3)' \
1950 '#define HAVE_GETADDRINFO' << \!
1951 #include <sys/types.h>
1952 #include <sys/socket.h>
1953 #include <stdio.h>
1954 #include <netdb.h>
1955 int main(void){
1956 struct addrinfo a, *ap;
1957 int lrv;
1959 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1960 case EAI_NONAME:
1961 case EAI_SERVICE:
1962 default:
1963 fprintf(stderr, "%s\n", gai_strerror(lrv));
1964 case 0:
1965 break;
1967 return 0;
1972 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1973 compile_check arpa_inet_h '<arpa/inet.h>' \
1974 '#define HAVE_ARPA_INET_H' << \!
1975 #include <sys/types.h>
1976 #include <sys/socket.h>
1977 #include <netdb.h>
1978 #include <netinet/in.h>
1979 #include <arpa/inet.h>
1982 ${cat} > ${tmp2}.c << \!
1983 #include <sys/types.h>
1984 #include <sys/socket.h>
1985 #include <stdio.h>
1986 #include <string.h>
1987 #include <netdb.h>
1988 #include <netinet/in.h>
1989 #ifdef HAVE_ARPA_INET_H
1990 #include <arpa/inet.h>
1991 #endif
1992 int main(void){
1993 struct sockaddr_in servaddr;
1994 unsigned short portno;
1995 struct servent *ep;
1996 struct hostent *hp;
1997 struct in_addr **pptr;
1999 portno = 0;
2000 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2001 portno = (unsigned short)ep->s_port;
2003 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2004 pptr = (struct in_addr**)hp->h_addr_list;
2005 if(hp->h_addrtype != AF_INET)
2006 fprintf(stderr, "au\n");
2007 }else{
2008 switch(h_errno){
2009 case HOST_NOT_FOUND:
2010 case TRY_AGAIN:
2011 case NO_RECOVERY:
2012 case NO_DATA:
2013 break;
2014 default:
2015 fprintf(stderr, "au\n");
2016 break;
2020 memset(&servaddr, 0, sizeof servaddr);
2021 servaddr.sin_family = AF_INET;
2022 servaddr.sin_port = htons(portno);
2023 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2024 fprintf(stderr, "Would connect to %s:%d ...\n",
2025 inet_ntoa(**pptr), (int)portno);
2026 return 0;
2030 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2031 < ${tmp2}.c link_check gethostbyname \
2032 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2033 < ${tmp2}.c link_check gethostbyname \
2034 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2035 '' '-lsocket -lnsl' ||
2036 feat_bail_required SOCKETS
2039 feat_yes SOCKETS &&
2040 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2041 #include <sys/socket.h>
2042 #include <stdlib.h>
2043 # include <errno.h>
2044 int main(void){
2045 int sockfd = 3;
2047 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2048 errno == ENOSYS)
2049 return 1;
2050 return 0;
2054 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2055 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2056 #include <sys/socket.h>
2057 #include <stdlib.h>
2058 int main(void){
2059 struct timeval tv;
2060 int sockfd = 3;
2062 tv.tv_sec = 42;
2063 tv.tv_usec = 21;
2064 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2065 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2066 return 0;
2070 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2071 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2072 #include <sys/socket.h>
2073 #include <stdlib.h>
2074 int main(void){
2075 struct linger li;
2076 int sockfd = 3;
2078 li.l_onoff = 1;
2079 li.l_linger = 42;
2080 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2081 return 0;
2085 if feat_yes SSL; then # {{{
2086 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2087 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2088 # time: we need to test it first in order to get things right
2089 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2090 '#define HAVE_SSL
2091 #define HAVE_XSSL
2092 #define HAVE_XSSL_RESSL
2093 #define HAVE_XSSL_OPENSSL 0' << \!
2094 #include <openssl/opensslv.h>
2095 #ifdef LIBRESSL_VERSION_NUMBER
2096 #else
2097 # error nope
2098 #endif
2100 then
2101 ossl_v1_1=
2102 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2103 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2104 '#define HAVE_SSL
2105 #define HAVE_XSSL
2106 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2107 #include <openssl/opensslv.h>
2108 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2109 #else
2110 # error nope
2111 #endif
2113 then
2114 ossl_v1_1=1
2115 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2116 '#define HAVE_SSL
2117 #define HAVE_XSSL
2118 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2119 #include <openssl/opensslv.h>
2120 #ifdef OPENSSL_VERSION_NUMBER
2121 #else
2122 # error nope
2123 #endif
2125 then
2126 ossl_v1_1=
2127 else
2128 feat_bail_required SSL
2129 fi # }}}
2131 if feat_yes SSL; then # {{{
2132 if [ -n "${ossl_v1_1}" ]; then
2133 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2134 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2135 '-lssl -lcrypto'
2136 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2137 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2138 '-lssl -lcrypto' << \!
2139 #include <openssl/ssl.h>
2140 #include <openssl/err.h>
2141 #include <openssl/x509v3.h>
2142 #include <openssl/x509.h>
2143 #include <openssl/rand.h>
2144 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2145 # error We need TLSv1.
2146 #endif
2147 int main(void){
2148 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2150 SSL_CTX_free(ctx);
2151 PEM_read_PrivateKey(0, 0, 0, 0);
2152 return 0;
2155 then
2157 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2158 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2159 '-lssl -lcrypto' << \!
2160 #include <openssl/ssl.h>
2161 #include <openssl/err.h>
2162 #include <openssl/x509v3.h>
2163 #include <openssl/x509.h>
2164 #include <openssl/rand.h>
2165 #if defined OPENSSL_NO_SSL3 &&\
2166 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2167 # error We need one of SSLv3 and TLSv1.
2168 #endif
2169 int main(void){
2170 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2172 SSL_CTX_free(ctx);
2173 PEM_read_PrivateKey(0, 0, 0, 0);
2174 return 0;
2177 then
2179 else
2180 feat_bail_required SSL
2182 fi # }}}
2184 if feat_yes SSL; then # {{{
2185 if [ -n "${ossl_v1_1}" ]; then
2186 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2187 '#define HAVE_XSSL_STACK_OF'
2188 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2189 '#define HAVE_XSSL_STACK_OF' << \!
2190 #include <stdio.h> /* For C89 NULL */
2191 #include <openssl/ssl.h>
2192 #include <openssl/err.h>
2193 #include <openssl/x509v3.h>
2194 #include <openssl/x509.h>
2195 #include <openssl/rand.h>
2196 int main(void){
2197 STACK_OF(GENERAL_NAME) *gens = NULL;
2199 printf("%p", gens); /* to use it */
2200 return 0;
2203 then
2207 if [ -n "${ossl_v1_1}" ]; then
2208 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2209 '#define HAVE_XSSL_CONFIG'
2210 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2211 '#define HAVE_XSSL_CONFIG' << \!
2212 #include <stdio.h> /* For C89 NULL */
2213 #include <openssl/conf.h>
2214 int main(void){
2215 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2216 CONF_modules_free();
2217 return 0;
2220 then
2224 if [ -n "${ossl_v1_1}" ]; then
2225 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2226 '#define HAVE_XSSL_CONF_CTX'
2227 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2228 '#define HAVE_XSSL_CONF_CTX' << \!
2229 #include <openssl/ssl.h>
2230 #include <openssl/err.h>
2231 int main(void){
2232 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2233 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2235 SSL_CONF_CTX_set_flags(cctx,
2236 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2237 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2238 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2239 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2240 SSL_CONF_CTX_finish(cctx);
2241 SSL_CONF_CTX_free(cctx);
2242 SSL_CTX_free(ctx);
2243 return 0;
2246 then
2250 if [ -n "${ossl_v1_1}" ]; then
2251 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2252 '#define HAVE_XSSL_RAND_EGD'
2253 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2254 '#define HAVE_XSSL_RAND_EGD' << \!
2255 #include <openssl/rand.h>
2256 int main(void){
2257 return RAND_egd("some.where") > 0;
2260 then
2264 if feat_yes SSL_ALL_ALGORITHMS; then
2265 if [ -n "${ossl_v1_1}" ]; then
2266 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2267 '#define HAVE_SSL_ALL_ALGORITHMS'
2268 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2269 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2270 #include <openssl/evp.h>
2271 int main(void){
2272 OpenSSL_add_all_algorithms();
2273 EVP_get_cipherbyname("two cents i never exist");
2274 EVP_cleanup();
2275 return 0;
2278 then
2280 else
2281 feat_bail_required SSL_ALL_ALGORITHMS
2284 fi # feat_yes SSL }}}
2286 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2287 run_check ssl_md5 'MD5 digest in the used crypto library' \
2288 '#define HAVE_XSSL_MD5' << \!
2289 #include <stdlib.h>
2290 #include <string.h>
2291 #include <openssl/md5.h>
2292 int main(void){
2293 char const dat[] = "abrakadabrafidibus";
2294 char dig[16], hex[16 * 2];
2295 MD5_CTX ctx;
2296 size_t i, j;
2298 memset(dig, 0, sizeof(dig));
2299 memset(hex, 0, sizeof(hex));
2300 MD5_Init(&ctx);
2301 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2302 MD5_Final(dig, &ctx);
2304 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2305 for(i = 0; i < sizeof(hex) / 2; i++){
2306 j = i << 1;
2307 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2308 hex[++j] = hexchar(dig[i] & 0x0f);
2310 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2313 fi # }}}
2314 else
2315 echo '/* OPT_SSL=0 */' >> ${h}
2316 fi # }}} feat_yes SSL
2318 if [ "${have_xssl}" = yes ]; then
2319 OPT_SMIME=1
2320 else
2321 OPT_SMIME=0
2323 feat_def SMIME
2325 feat_def SMTP
2326 feat_def POP3
2327 feat_def IMAP
2329 if feat_yes GSSAPI; then
2330 ${cat} > ${tmp2}.c << \!
2331 #include <gssapi/gssapi.h>
2332 int main(void){
2333 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2334 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2335 return 0;
2338 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2340 if command -v krb5-config >/dev/null 2>&1; then
2341 i=`command -v krb5-config`
2342 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2343 GSS_INCS="`CFLAGS= ${i} --cflags`"
2344 i='GSS-API via krb5-config(1)'
2345 else
2346 GSS_LIBS='-lgssapi'
2347 GSS_INCS=
2348 i='GSS-API in gssapi/gssapi.h, libgssapi'
2350 if < ${tmp2}.c link_check gss \
2351 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2352 < ${tmp3}.c link_check gss \
2353 'GSS-API in gssapi.h, libgssapi' \
2354 '#define HAVE_GSSAPI
2355 #define GSSAPI_REG_INCLUDE' \
2356 '-lgssapi' ||\
2357 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2358 '#define HAVE_GSSAPI' \
2359 '-lgssapi_krb5' ||\
2360 < ${tmp3}.c link_check gss \
2361 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2362 '#define HAVE_GSSAPI
2363 #define GSS_REG_INCLUDE' \
2364 '-lgssapi -lkrb5 -lcrypto' \
2365 '-I/usr/include/kerberosV' ||\
2366 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2367 '#define HAVE_GSSAPI' \
2368 '-lgss' ||\
2369 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2370 '#define HAVE_GSSAPI
2371 #define GSSAPI_OLD_STYLE' \
2372 '-lgssapi_krb5' << \!
2373 #include <gssapi/gssapi.h>
2374 #include <gssapi/gssapi_generic.h>
2375 int main(void){
2376 gss_import_name(0, 0, gss_nt_service_name, 0);
2377 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2378 return 0;
2381 then
2383 else
2384 feat_bail_required GSSAPI
2386 else
2387 echo '/* OPT_GSSAPI=0 */' >> ${h}
2388 fi # feat_yes GSSAPI
2390 feat_def NETRC
2391 feat_def AGENT
2393 if feat_yes IDNA; then
2394 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2395 '-lidn' << \!
2396 #include <idna.h>
2397 #include <idn-free.h>
2398 #include <stringprep.h>
2399 int main(void){
2400 char *utf8, *idna_ascii, *idna_utf8;
2402 utf8 = stringprep_locale_to_utf8("does.this.work");
2403 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2404 != IDNA_SUCCESS)
2405 return 1;
2406 idn_free(idna_ascii);
2407 /* (Rather link check only here) */
2408 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2409 return 0;
2412 then
2414 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2415 '-lidnkit' << \!
2416 #include <stdio.h>
2417 #include <idn/api.h>
2418 #include <idn/result.h>
2419 int main(void){
2420 idn_result_t r;
2421 char ace_name[256];
2422 char local_name[256];
2424 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2425 sizeof(ace_name));
2426 if (r != idn_success) {
2427 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2428 return 1;
2430 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2431 if (r != idn_success) {
2432 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2433 return 1;
2435 return 0;
2438 then
2440 else
2441 feat_bail_required IDNA
2444 if [ -n "${have_idna}" ]; then
2445 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2446 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2448 else
2449 echo '/* OPT_IDNA=0 */' >> ${h}
2452 feat_def IMAP_SEARCH
2454 if feat_yes REGEX; then
2455 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2456 #include <regex.h>
2457 #include <stdlib.h>
2458 int main(void){
2459 size_t xret;
2460 int status;
2461 regex_t re;
2463 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2464 xret = regerror(status, &re, NULL, 0);
2465 status = regexec(&re, "plan9", 0,NULL, 0);
2466 regfree(&re);
2467 return !(status == REG_NOMATCH);
2470 then
2472 else
2473 feat_bail_required REGEX
2475 else
2476 echo '/* OPT_REGEX=0 */' >> ${h}
2479 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2480 have_mle=1
2481 echo '#define HAVE_MLE' >> ${h}
2482 else
2483 feat_bail_required MLE
2484 echo '/* OPT_MLE=0 */' >> ${h}
2487 # Generic have-a-line-editor switch for those who need it below
2488 if [ -n "${have_mle}" ]; then
2489 have_cle=1
2492 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2493 echo '#define HAVE_HISTORY' >> ${h}
2494 else
2495 echo '/* OPT_HISTORY=0 */' >> ${h}
2498 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2499 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2500 else
2501 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2504 if feat_yes TERMCAP; then
2505 __termcaplib() {
2506 link_check termcap "termcap(5) (via ${4})" \
2507 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2508 #include <stdio.h>
2509 #include <stdlib.h>
2510 ${2}
2511 #include <term.h>
2512 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2513 static int my_putc(int c){return putchar(c);}
2514 int main(void){
2515 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2516 int r2 = OK, r3 = ERR;
2518 tgetent(buf, getenv("TERM"));
2519 cpb = cmdbuf;
2520 r1 = tgetstr(UNCONST("cm"), &cpb);
2521 tgoto(r1, 1, 1);
2522 r2 = tgetnum(UNCONST("Co"));
2523 r3 = tgetflag(UNCONST("ut"));
2524 tputs("cr", 1, &my_putc);
2525 return (r1 == NULL || r2 == -1 || r3 == 0);
2527 _EOT
2530 __terminfolib() {
2531 link_check terminfo "terminfo(5) (via ${2})" \
2532 '#define HAVE_TERMCAP
2533 #define HAVE_TERMCAP_CURSES
2534 #define HAVE_TERMINFO' "${1}" << _EOT
2535 #include <stdio.h>
2536 #include <curses.h>
2537 #include <term.h>
2538 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2539 static int my_putc(int c){return putchar(c);}
2540 int main(void){
2541 int er, r0, r1, r2;
2542 char *r3, *tp;
2544 er = OK;
2545 r0 = setupterm(NULL, 1, &er);
2546 r1 = tigetflag(UNCONST("bce"));
2547 r2 = tigetnum(UNCONST("colors"));
2548 r3 = tigetstr(UNCONST("cr"));
2549 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2550 tputs(tp, 1, &my_putc);
2551 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2552 r3 == (char*)-1 || r3 == NULL);
2554 _EOT
2557 if feat_yes TERMCAP_VIA_TERMINFO; then
2558 __terminfolib -ltinfo -ltinfo ||
2559 __terminfolib -lcurses -lcurses ||
2560 __terminfolib -lcursesw -lcursesw ||
2561 feat_bail_required TERMCAP_VIA_TERMINFO
2564 if [ -z "${have_terminfo}" ]; then
2565 __termcaplib -ltermcap '' '' '-ltermcap' ||
2566 __termcaplib -ltermcap '#include <curses.h>' '
2567 #define HAVE_TERMCAP_CURSES' \
2568 'curses.h / -ltermcap' ||
2569 __termcaplib -lcurses '#include <curses.h>' '
2570 #define HAVE_TERMCAP_CURSES' \
2571 'curses.h / -lcurses' ||
2572 __termcaplib -lcursesw '#include <curses.h>' '
2573 #define HAVE_TERMCAP_CURSES' \
2574 'curses.h / -lcursesw' ||
2575 feat_bail_required TERMCAP
2577 if [ -n "${have_termcap}" ]; then
2578 run_check tgetent_null \
2579 "tgetent(3) of termcap(5) takes NULL buffer" \
2580 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2581 #include <stdio.h> /* For C89 NULL */
2582 #include <stdlib.h>
2583 #ifdef HAVE_TERMCAP_CURSES
2584 # include <curses.h>
2585 #endif
2586 #include <term.h>
2587 int main(void){
2588 tgetent(NULL, getenv("TERM"));
2589 return 0;
2591 _EOT
2594 else
2595 echo '/* OPT_TERMCAP=0 */' >> ${h}
2596 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2599 if feat_def SPAM_SPAMC; then
2600 if command -v spamc >/dev/null 2>&1; then
2601 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2605 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2606 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2607 else
2608 feat_bail_required SPAM_SPAMD
2609 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2612 feat_def SPAM_FILTER
2614 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2615 echo '#define HAVE_SPAM' >> ${h}
2616 else
2617 echo '/* HAVE_SPAM */' >> ${h}
2620 if feat_yes QUOTE_FOLD &&\
2621 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2622 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2623 else
2624 feat_bail_required QUOTE_FOLD
2625 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2628 feat_def FILTER_HTML_TAGSOUP
2629 feat_def COLOUR
2630 feat_def DOTLOCK
2631 feat_def MD5
2632 feat_def NOMEMDBG
2634 ## Summarizing
2636 ${rm} -f ${tmp}
2637 squeeze_em ${inc} ${tmp}
2638 ${mv} ${tmp} ${inc}
2639 squeeze_em ${lib} ${tmp}
2640 ${mv} ${tmp} ${lib}
2642 # mk-config.h
2643 ${mv} ${h} ${tmp}
2644 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2645 ${cat} ${tmp} >> ${h}
2646 ${rm} -f ${tmp}
2647 printf '\n' >> ${h}
2649 # Create the real mk-config.mk
2650 # Note we cannout use explicit ./ filename prefix for source and object
2651 # pathnames because of a bug in bmake(1)
2652 ${rm} -rf ${tmp0}.* ${tmp0}*
2653 printf 'OBJ_SRC = ' >> ${mk}
2654 if feat_no AMALGAMATION; then
2655 for i in `printf '%s\n' *.c | ${sort}`; do
2656 if [ "${i}" = privsep.c ]; then
2657 continue
2659 printf "${i} " >> ${mk}
2660 done
2661 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2662 else
2663 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2665 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2666 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2667 printf '# undef _CONFIG_H\n' >> ${h}
2668 printf '# define _CONFIG_H 2\n' >> ${h}
2669 for i in `printf '%s\n' *.c | ${sort}`; do
2670 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2671 [ "${i}" = privsep.c ]; then
2672 continue
2674 printf "${i} " >> ${mk}
2675 printf "# include \"${i}\"\n" >> ${h}
2676 done
2677 echo >> ${mk}
2678 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2679 echo '#else' >> ${h}
2682 # Finally, create the string that is used by *features* and `version'.
2683 # Take this nice opportunity and generate a visual listing of included and
2684 # non-included features for the person who runs the configuration
2685 msg '\nThe following features are included (+) or not (-):'
2686 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2687 printf '/* The "feature string" */\n' >> ${h}
2688 # Because + is expanded by *folder* if first in "echo $features", put something
2689 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2690 sep=
2691 for opt
2693 sdoc=`option_doc_of ${opt}`
2694 [ -z "${sdoc}" ] && continue
2695 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2696 feat_yes ${opt} && sign=+ || sign=-
2697 printf -- "${sep}${sign}${sopt}" >> ${h}
2698 sep=','
2699 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2700 done
2701 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2702 #exec 5>&1 >>${h}
2703 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2704 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2706 printf '"\n#endif /* n_MK_CONFIG_H */\n' >> ${h}
2708 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2709 echo "INCS = `${cat} ${inc}`" >> ${mk}
2710 echo >> ${mk}
2711 ${cat} ./make-config.in >> ${mk}
2713 ## Finished!
2715 msg '\nSetup:'
2716 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2717 msg ' . bindir: %s' "${VAL_BINDIR}"
2718 if feat_yes DOTLOCK; then
2719 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2721 msg ' . mandir: %s' "${VAL_MANDIR}"
2722 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2723 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2724 msg ''
2726 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2727 exit 0
2729 msg 'Remarks:'
2730 if [ -z "${have_fnmatch}" ]; then
2731 msg ' . The function fnmatch(3) could not be found.'
2732 msg ' Filename patterns like wildcard are not supported on your system'
2734 if [ -z "${have_fchdir}" ]; then
2735 msg ' . The function fchdir(2) could not be found.'
2736 msg ' We will use chdir(2) instead.'
2737 msg ' This is a problem only if the current working directory is changed'
2738 msg ' while this program is inside of it'
2740 msg ''
2742 # s-it-mode