n_getdeadletter(): CID 1376996 !
[s-mailx.git] / make-config.sh
blob2e25f611046630c3318d45b04236fda7ec421ef8
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
152 msg_nonl "CONFIG=${CONFIG} ... "
156 # Inter-relationships
157 option_update() {
158 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
159 OPT_SOCKETS=0
161 if feat_no SOCKETS; then
162 if feat_require SMTP; then
163 msg 'ERROR: need SOCKETS for required feature SMTP'
164 config_exit 13
166 if feat_require POP3; then
167 msg 'ERROR: need SOCKETS for required feature POP3'
168 config_exit 13
170 if feat_require IMAP; then
171 msg 'ERROR: need SOCKETS for required feature IMAP'
172 config_exit 13
174 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
175 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
176 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
178 if feat_no SMTP && feat_no IMAP; then
179 OPT_GSSAPI=0
182 if feat_no ICONV; then
183 if feat_require IMAP; then
184 msg 'ERROR: need ICONV for required feature IMAP'
185 config_exit 13
187 msg 'ERROR: disabling IMAP due to missing ICONV'
188 OPT_IMAP=0
191 if feat_no MLE; then
192 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
195 # If we don't need MD5 leave it alone
196 if feat_no SOCKETS; then
197 OPT_MD5=0
200 if feat_no TERMCAP; then
201 OPT_TERMCAP_VIA_TERMINFO=0
204 if feat_yes DEVEL; then
205 OPT_DEBUG=1
209 rc=./make.rc
210 lst=./mk-config.lst
211 ev=./mk-config.ev
212 h=./mk-config.h h_name=mk-config.h
213 mk=./mk-config.mk
215 newlst=./mk-nconfig.lst
216 newmk=./mk-nconfig.mk
217 newev=./mk-nconfig.ev
218 newh=./mk-nconfig.h
219 tmp0=___tmp
220 tmp=./${tmp0}1$$
221 tmp2=./${tmp0}2$$
223 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
225 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
226 # via path_check() later on once possible
228 # TODO cc_maxopt is brute simple, we should compile test program and dig real
229 # compiler versions for known compilers, then be more specific
230 cc_maxopt=100
231 _CFLAGS= _LDFLAGS=
233 os_early_setup() {
234 # We don't "have any utility": only path adjustments and such in here!
235 i="${OS:-`uname -s`}"
237 if [ ${i} = SunOS ]; then
238 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
239 _os_early_setup_sunos
243 _os_early_setup_sunos() {
244 # According to standards(5), this is what we need to do
245 if [ -d /usr/xpg4 ]; then :; else
246 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
247 config_exit 1
249 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
250 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
251 export PATH
254 os_setup() {
255 # OSENV ends up in *build-osenv*
256 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
257 : ${OS:=`uname -s | ${tr} '[A-Z]' '[a-z]'`}
258 : ${OSENV:=`uname -srm`}
259 : ${OSFULLSPEC:=`uname -a`}
260 msg 'Operating system is %s' ${OS}
262 if [ ${OS} = sunos ]; then
263 msg ' . have special SunOS / Solaris "setup" rules ...'
264 _os_setup_sunos
265 elif [ ${OS} = unixware ]; then
266 msg ' . have special UnixWare environmental rules ...'
267 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
268 CC=cc
269 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
271 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
272 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
273 export CC CFLAGS LDFLAGS
274 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
276 elif [ -n "${VERBOSE}" ]; then
277 msg ' . no special treatment for this system necessary or known'
280 # Sledgehammer: better set _GNU_SOURCE
281 # And in general: oh, boy!
282 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
283 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
284 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
285 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
287 # On pkgsrc(7) systems automatically add /usr/pkg/*
288 if [ -d /usr/pkg ]; then
289 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
290 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
294 _os_setup_sunos() {
295 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
296 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
298 # Include packages
299 if [ -d /opt/csw ]; then
300 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
301 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
304 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
305 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
307 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
308 if [ -x "${cksum}" ]; then :; else
309 msg 'ERROR: Not an executable program: %s' "${cksum}"
310 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
311 msg 'ERROR: However, we do so only for tests.'
312 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
313 config_exit 1
316 if feat_yes AUTOCC; then
317 if command -v cc >/dev/null 2>&1; then
318 CC=cc
319 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
321 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
322 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
323 export CC CFLAGS LDFLAGS
324 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
325 else
326 # Assume gcc(1), which supports -R for compat
327 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
332 # Check out compiler ($CC) and -flags ($CFLAGS)
333 cc_setup() {
334 # Even though it belongs into cc_flags we will try to compile and link
335 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
336 # EXTRA_CFLAGS/EXTRA_LDFLAGS
337 if feat_no AUTOCC; then
338 _cc_default
339 # Ensure those don't do any harm
340 EXTRA_CFLAGS= EXTRA_LDFLAGS=
341 export EXTRA_CFLAGS EXTRA_LDFLAGS
342 return
343 else
344 CFLAGS= LDFLAGS=
345 export CFLAGS LDFLAGS
348 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
350 msg_nonl 'Searching for a usable C compiler .. $CC='
351 if { i="`command -v clang`"; }; then
352 CC=${i}
353 elif { i="`command -v gcc`"; }; then
354 CC=${i}
355 elif { i="`command -v c99`"; }; then
356 CC=${i}
357 elif { i="`command -v tcc`"; }; then
358 CC=${i}
359 elif { i="`command -v pcc`"; }; then
360 CC=${i}
361 else
362 if [ "${CC}" = cc ]; then
364 elif { i="`command -v c89`"; }; then
365 CC=${i}
366 else
367 msg 'boing booom tschak'
368 msg 'ERROR: I cannot find a compiler!'
369 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
370 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
371 config_exit 1
374 msg '%s' "${CC}"
375 export CC
378 _cc_default() {
379 if [ -z "${CC}" ]; then
380 msg 'To go on like you have chosen, please set $CC, rerun.'
381 config_exit 1
384 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
386 else
387 msg 'Using C compiler ${CC}=%s' "${CC}"
391 cc_flags() {
392 if feat_yes AUTOCC; then
393 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
394 cc_check_silent=1
395 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
396 "${CC}"
397 else
398 cc_check_silent=
399 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
402 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
403 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
404 msg ' . have special tcc(1) environmental rules ...'
405 _cc_flags_tcc
406 else
407 # As of pcc CVS 2016-04-02, stack protection support is announced but
408 # will break if used on Linux
409 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
410 force_no_stackprot=1
412 _cc_flags_generic
415 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
416 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
417 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
418 else
419 if feat_no DEBUG; then
420 CFLAGS="-DNDEBUG ${CFLAGS}"
423 msg ''
424 export CFLAGS LDFLAGS
427 _cc_flags_tcc() {
428 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
429 _CFLAGS= _LDFLAGS=
431 cc_check -Wall
432 cc_check -Wextra
433 cc_check -pedantic
435 if feat_yes DEBUG; then
436 # May have problems to find libtcc cc_check -b
437 cc_check -g
440 if ld_check -Wl,-rpath =./ no; then
441 need_R_ldflags=-Wl,-rpath=
442 ld_check -Wl,--enable-new-dtags
443 ld_runtime_flags # update!
446 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
447 unset __cflags __ldflags
450 _cc_flags_generic() {
451 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
452 _CFLAGS= _LDFLAGS=
453 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
455 # Check -g first since some others may rely upon -g / optim. level
456 if feat_yes DEBUG; then
457 cc_check -O
458 cc_check -g
459 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
461 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
463 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
465 else
466 cc_check -O
469 if feat_yes AMALGAMATION; then
470 cc_check -pipe
473 #if feat_yes DEVEL && cc_check -Weverything; then
475 #else
476 cc_check -Wall
477 cc_check -Wextra
478 cc_check -Wbad-function-cast
479 cc_check -Wcast-align
480 cc_check -Wcast-qual
481 cc_check -Winit-self
482 cc_check -Wmissing-prototypes
483 cc_check -Wshadow
484 cc_check -Wunused
485 cc_check -Wwrite-strings
486 cc_check -Wno-long-long
488 cc_check -pedantic
490 if feat_yes AMALGAMATION && feat_no DEVEL; then
491 cc_check -Wno-unused-function
493 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
495 cc_check -fno-unwind-tables
496 cc_check -fno-asynchronous-unwind-tables
497 cc_check -fstrict-aliasing
498 if cc_check -fstrict-overflow && feat_yes DEVEL; then
499 cc_check -Wstrict-overflow=5
502 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
503 if [ -z "${force_no_stackprot}" ]; then
504 if cc_check -fstack-protector-strong ||
505 cc_check -fstack-protector-all; then
506 cc_check -D_FORTIFY_SOURCE=2
508 else
509 msg 'Not checking for -fstack-protector compiler option,'
510 msg 'since that caused errors in a "similar" configuration.'
511 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
515 # LD (+ dependend CC)
517 if feat_yes ASAN_ADDRESS; then
518 _ccfg=${_CFLAGS}
519 if cc_check -fsanitize=address &&
520 ld_check -fsanitize=address; then
522 else
523 feat_bail_required ASAN_ADDRESS
524 _CFLAGS=${_ccfg}
528 if feat_yes ASAN_MEMORY; then
529 _ccfg=${_CFLAGS}
530 if cc_check -fsanitize=memory &&
531 ld_check -fsanitize=memory &&
532 cc_check -fsanitize-memory-track-origins=2 &&
533 ld_check -fsanitize-memory-track-origins=2; then
535 else
536 feat_bail_required ASAN_MEMORY
537 _CFLAGS=${_ccfg}
541 ld_check -Wl,-z,relro
542 ld_check -Wl,-z,now
543 ld_check -Wl,-z,noexecstack
544 if ld_check -Wl,-rpath =./ no; then
545 need_R_ldflags=-Wl,-rpath=
546 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
547 ld_check -Wl,--enable-new-dtags
548 ld_runtime_flags # update!
549 elif ld_check -Wl,-R ./ no; then
550 need_R_ldflags=-Wl,-R
551 ld_check -Wl,--enable-new-dtags
552 ld_runtime_flags # update!
555 # Address randomization
556 _ccfg=${_CFLAGS}
557 if cc_check -fPIE || cc_check -fpie; then
558 ld_check -pie || _CFLAGS=${_ccfg}
560 unset _ccfg
562 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
563 unset __cflags __ldflags
566 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
568 ## Notes:
569 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
570 ## redirection, so use "printf '' >" instead
572 ## Very first: we undergo several states regarding I/O redirection etc.,
573 ## but need to deal with option updates from within all. Since all the
574 ## option stuff should be above the scissor line, define utility functions
575 ## and redefine them as necessary.
576 ## And, since we have those functions, simply use them for whatever
578 config_exit() {
579 exit ${1}
582 msg() {
583 fmt=${1}
584 shift
585 printf >&2 -- "${fmt}\\n" "${@}"
588 msg_nonl() {
589 fmt=${1}
590 shift
591 printf >&2 -- "${fmt}" "${@}"
594 t1=ten10one1ten10one1
595 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
596 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
597 ) > /dev/null 2>&1; then
598 good_shell=1
599 else
600 unset good_shell
602 unset t1
604 # We need some standard utilities
605 unset -f command
606 check_tool() {
607 n=${1} i=${2} opt=${3:-0}
608 # Evaluate, just in case user comes in with shell snippets (..well..)
609 eval i="${i}"
610 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
611 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
612 eval ${n}=${i}
613 return 0
615 if [ ${opt} -eq 0 ]; then
616 msg 'ERROR: no trace of utility %s' "${n}"
617 config_exit 1
619 return 1
622 # Our feature check environment
623 feat_val_no() {
624 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
625 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
628 feat_val_yes() {
629 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
630 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
631 [ "x${1}" = xrequire ]
634 feat_val_require() {
635 [ "x${1}" = xrequire ]
638 _feat_check() {
639 eval i=\$OPT_${1}
640 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
641 if feat_val_no "${i}"; then
642 return 1
643 elif feat_val_yes "${i}"; then
644 return 0
645 else
646 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
647 "${1}" "${i}"
648 config_exit 11
652 feat_yes() {
653 _feat_check ${1}
656 feat_no() {
657 _feat_check ${1} && return 1
658 return 0
661 feat_require() {
662 eval i=\$OPT_${1}
663 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
664 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
667 feat_bail_required() {
668 if feat_require ${1}; then
669 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
670 config_exit 13
672 eval OPT_${1}=0
673 option_update # XXX this is rather useless here (dependency chain..)
676 option_parse() {
677 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
678 # options, without documentation, to $1
679 j=\'
680 i="`${awk} -v input=\"${2}\" '
681 BEGIN{
682 for(i = 0;;){
683 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
684 if(voff == 0)
685 break
686 v = substr(input, voff, RLENGTH)
687 input = substr(input, voff + RLENGTH)
688 doff = index(v, "=")
689 if(doff > 0){
690 d = substr(v, doff + 2, length(v) - doff - 1)
691 v = substr(v, 1, doff - 1)
693 print v
697 eval ${1}=\"${i}\"
700 option_doc_of() {
701 # Return the "documentation string" for option $1, itself if none such
702 j=\'
703 ${awk} -v want="${1}" \
704 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
705 BEGIN{
706 for(;;){
707 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
708 if(voff == 0)
709 break
710 v = substr(input, voff, RLENGTH)
711 input = substr(input, voff + RLENGTH)
712 doff = index(v, "=")
713 if(doff > 0){
714 d = substr(v, doff + 2, length(v) - doff - 1)
715 v = substr(v, 1, doff - 1)
716 }else
717 d = v
718 if(v == want){
719 if(d != "-")
720 print d
721 exit
728 option_join_rc() {
729 # Join the values from make.rc into what currently is defined, not
730 # overwriting yet existing settings
731 ${rm} -f ${tmp}
732 # We want read(1) to perform reverse solidus escaping in order to be able to
733 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
734 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
735 < ${rc} ${awk} 'BEGIN{line = ""}{
736 gsub(/^[[:space:]]+/, "", $0)
737 gsub(/[[:space:]]+$/, "", $0)
738 if(gsub(/\\$/, "", $0)){
739 line = line $0
740 next
741 }else
742 line = line $0
743 if(index(line, "#") == 1){
744 line = ""
745 }else if(length(line)){
746 print line
747 line = ""
749 }' |
750 while read line; do
751 if [ -n "${good_shell}" ]; then
752 i=${line%%=*}
753 else
754 i=`${awk} -v LINE="${line}" 'BEGIN{
755 gsub(/=.*$/, "", LINE)
756 print LINE
759 if [ "${i}" = "${line}" ]; then
760 msg 'ERROR: invalid syntax in: %s' "${line}"
761 continue
764 eval j="\$${i}" jx="\${${i}+x}"
765 if [ -n "${j}" ] || [ "${jx}" = x ]; then
766 : # Yet present
767 else
768 j=`${awk} -v LINE="${line}" 'BEGIN{
769 gsub(/^[^=]*=/, "", LINE)
770 gsub(/^\"*/, "", LINE)
771 gsub(/\"*$/, "", LINE)
772 print LINE
775 [ "${i}" = "DESTDIR" ] && continue
776 echo "${i}=\"${j}\""
777 done > ${tmp}
778 # Reread the mixed version right now
779 . ./${tmp}
782 option_evaluate() {
783 # Expand the option values, which may contain shell snippets
784 ${rm} -f ${newlst} ${newmk} ${newh}
785 exec 5<&0 6>&1 <${tmp} >${newlst}
786 while read line; do
788 if [ -n "${good_shell}" ]; then
789 i=${line%%=*}
790 [ "${i}" != "${i#OPT_}" ] && z=1
791 else
792 i=`${awk} -v LINE="${line}" 'BEGIN{
793 gsub(/=.*$/, "", LINE);\
794 print LINE
796 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
801 eval j=\$${i}
802 if [ -n "${z}" ]; then
803 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
804 if [ -z "${j}" ] || feat_val_no "${j}"; then
806 printf " /* #undef ${i} */\n" >> ${newh}
807 elif feat_val_yes "${j}"; then
808 if feat_val_require "${j}"; then
809 j=require
810 else
813 printf " /* #define ${i} */\n" >> ${newh}
814 else
815 msg 'ERROR: cannot parse <%s>' "${line}"
816 config_exit 1
818 else
819 printf "#define ${i} \"${j}\"\n" >> ${newh}
821 printf "${i} = ${j}\n" >> ${newmk}
822 printf "${i}=${j}\n"
823 eval "${i}=\"${j}\""
824 done
825 exec 0<&5 1>&6 5<&- 6<&-
828 path_check() {
829 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
830 varname=${1} addflag=${2} flagvarname=${3}
831 j=${IFS}
832 IFS=:
833 eval "set -- \$${1}"
834 IFS=${j}
835 j= k= y= z=
836 for i
838 [ -z "${i}" ] && continue
839 [ -d "${i}" ] || continue
840 # Skip any fakeroot packager environment
841 case "${i}" in *fakeroot*) continue;; esac
842 if [ -n "${j}" ]; then
843 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
845 else
846 y="${y} :${i}:"
847 j="${j}:${i}"
848 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
850 else
851 y=" :${i}:"
852 j="${i}"
853 [ -n "${addflag}" ] && k="${addflag}${i}"
855 done
856 eval "${varname}=\"${j}\""
857 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
858 unset varname
861 ld_runtime_flags() {
862 if [ -n "${need_R_ldflags}" ]; then
863 i=${IFS}
864 IFS=:
865 set -- ${LD_LIBRARY_PATH}
866 IFS=${i}
867 for i
869 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
870 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
871 done
872 export LDFLAGS
874 # Disable it for a possible second run.
875 need_R_ldflags=
878 cc_check() {
879 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
880 if "${CC}" ${INCS} \
881 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
882 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
883 _CFLAGS="${_CFLAGS} ${1}"
884 [ -n "${cc_check_silent}" ] || msg 'yes'
885 return 0
887 [ -n "${cc_check_silent}" ] || msg 'no'
888 return 1
891 ld_check() {
892 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
893 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
894 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
895 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
896 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
897 [ -n "${cc_check_silent}" ] || msg 'yes'
898 return 0
900 [ -n "${cc_check_silent}" ] || msg 'no'
901 return 1
904 _check_preface() {
905 variable=$1 topic=$2 define=$3
907 echo '**********'
908 msg_nonl ' . %s ... ' "${topic}"
909 echo "/* checked ${topic} */" >> ${h}
910 ${rm} -f ${tmp} ${tmp}.o
911 echo '*** test program is'
912 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
913 #echo '*** the preprocessor generates'
914 #${make} -f ${makefile} ${tmp}.x
915 #${cat} ${tmp}.x
916 echo '*** results are'
919 without_check() {
920 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
922 echo '**********'
923 msg_nonl ' . %s ... ' "${topic}"
925 echo '*** enforced unchecked results are'
926 if feat_val_yes ${yesno}; then
927 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
928 echo "*** adding INCS<${incs}> LIBS<${libs}>"
929 LIBS="${LIBS} ${libs}"
930 echo "${libs}" >> ${lib}
931 INCS="${INCS} ${incs}"
932 echo "${incs}" >> ${inc}
934 msg 'yes (deduced)'
935 echo "${define}" >> ${h}
936 eval have_${variable}=yes
937 return 0
938 else
939 echo "/* ${define} */" >> ${h}
940 msg 'no (deduced)'
941 eval unset have_${variable}
942 return 1
946 compile_check() {
947 variable=$1 topic=$2 define=$3
949 _check_preface "${variable}" "${topic}" "${define}"
951 if ${make} -f ${makefile} XINCS="${INCS}" \
952 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
953 ./${tmp}.o &&
954 [ -f ./${tmp}.o ]; then
955 msg 'yes'
956 echo "${define}" >> ${h}
957 eval have_${variable}=yes
958 return 0
959 else
960 echo "/* ${define} */" >> ${h}
961 msg 'no'
962 eval unset have_${variable}
963 return 1
967 _link_mayrun() {
968 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
970 _check_preface "${variable}" "${topic}" "${define}"
972 if feat_yes CROSS_BUILD; then
973 if [ ${run} = 1 ]; then
974 run=0
978 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
979 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
980 XLIBS="${LIBS} ${libs}" \
981 ./${tmp} &&
982 [ -f ./${tmp} ] &&
983 { [ ${run} -eq 0 ] || ./${tmp}; }; then
984 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
985 msg 'yes'
986 echo "${define}" >> ${h}
987 LIBS="${LIBS} ${libs}"
988 echo "${libs}" >> ${lib}
989 INCS="${INCS} ${incs}"
990 echo "${incs}" >> ${inc}
991 eval have_${variable}=yes
992 return 0
993 else
994 msg 'no'
995 echo "/* ${define} */" >> ${h}
996 eval unset have_${variable}
997 return 1
1001 link_check() {
1002 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1005 run_check() {
1006 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1009 xrun_check() {
1010 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1013 feat_def() {
1014 if feat_yes ${1}; then
1015 echo '#define HAVE_'${1}'' >> ${h}
1016 return 0
1017 else
1018 echo '/* OPT_'${1}'=0 */' >> ${h}
1019 return 1
1023 squeeze_em() {
1024 < "${1}" > "${2}" ${awk} \
1025 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1028 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1030 # First of all, create new configuration and check whether it changed
1032 # Very easy checks for the operating system in order to be able to adjust paths
1033 # or similar very basic things which we need to be able to go at all
1034 os_early_setup
1036 # Check those tools right now that we need before including $rc
1037 msg 'Checking for basic utility set'
1038 check_tool awk "${awk:-`command -v awk`}"
1039 check_tool rm "${rm:-`command -v rm`}"
1040 check_tool tr "${tr:-`command -v tr`}"
1042 # Initialize the option set
1043 msg_nonl 'Setting up configuration options ... '
1044 option_setup
1045 msg 'done'
1047 # Include $rc, but only take from it what wasn't overwritten by the user from
1048 # within the command line or from a chosen fixed CONFIG=
1049 # Note we leave alone the values
1050 trap "exit 1" HUP INT TERM
1051 trap "${rm} -f ${tmp}" EXIT
1053 msg_nonl 'Joining in %s ... ' ${rc}
1054 option_join_rc
1055 msg 'done'
1057 # We need to know about that now, in order to provide utility overwrites etc.
1058 os_setup
1060 msg 'Checking for remaining set of utilities'
1061 check_tool grep "${grep:-`command -v grep`}"
1063 # Before we step ahead with the other utilities perform a path cleanup first.
1064 path_check PATH
1066 # awk(1) above
1067 check_tool cat "${cat:-`command -v cat`}"
1068 check_tool chmod "${chmod:-`command -v chmod`}"
1069 check_tool cp "${cp:-`command -v cp`}"
1070 check_tool cmp "${cmp:-`command -v cmp`}"
1071 # grep(1) above
1072 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1073 check_tool mv "${mv:-`command -v mv`}"
1074 # rm(1) above
1075 check_tool sed "${sed:-`command -v sed`}"
1076 check_tool sort "${sort:-`command -v sort`}"
1077 check_tool tee "${tee:-`command -v tee`}"
1079 check_tool chown "${chown:-`command -v chown`}" 1 ||
1080 check_tool chown "/sbin/chown" 1 ||
1081 check_tool chown "/usr/sbin/chown"
1083 check_tool make "${MAKE:-`command -v make`}"
1084 MAKE=${make}
1085 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1086 HAVE_STRIP=1 || HAVE_STRIP=0
1088 # For ./cc-test.sh only
1089 check_tool cksum "${cksum:-`command -v cksum`}"
1091 # Update OPT_ options now, in order to get possible inter-dependencies right
1092 option_update
1094 # (No functions since some shells loose non-exported variables in traps)
1095 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1096 trap "trap \"\" HUP INT TERM EXIT;\
1097 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1099 # Our configuration options may at this point still contain shell snippets,
1100 # we need to evaluate them in order to get them expanded, and we need those
1101 # evaluated values not only in our new configuration file, but also at hand..
1102 msg_nonl 'Evaluating all configuration items ... '
1103 option_evaluate
1104 msg 'done'
1106 # Add the known utility and some other variables
1107 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1108 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1110 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1111 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1112 if feat_yes DOTLOCK; then
1113 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1114 else
1115 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1118 for i in \
1119 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1120 MAKE MAKEFLAGS make SHELL strip \
1121 cksum; do
1122 eval j=\$${i}
1123 printf "${i} = ${j}\n" >> ${newmk}
1124 printf "${i}=${j}\n" >> ${newlst}
1125 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1126 done
1127 printf "\n" >> ${newev}
1129 # Build a basic set of INCS and LIBS according to user environment.
1130 path_check C_INCLUDE_PATH -I _INCS
1131 INCS="${INCS} ${_INCS}"
1132 path_check LD_LIBRARY_PATH -L _LIBS
1133 LIBS="${LIBS} ${_LIBS}"
1134 unset _INCS _LIBS
1135 export C_INCLUDE_PATH LD_LIBRARY_PATH
1137 # Some environments need runtime path flags to be able to go at all
1138 ld_runtime_flags
1140 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1142 cc_setup
1144 ${cat} > ${tmp}.c << \!
1145 #include <stdio.h>
1146 #include <string.h>
1147 static void doit(char const *s);
1149 main(int argc, char **argv){
1150 (void)argc;
1151 (void)argv;
1152 doit("Hello world");
1153 return 0;
1155 static void
1156 doit(char const *s){
1157 char buf[12];
1158 memcpy(buf, s, strlen(s) +1);
1159 puts(s);
1163 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1164 -o ${tmp2} ${tmp}.c ${LIBS}; then
1166 else
1167 msg 'ERROR: i cannot compile a "Hello world" via'
1168 msg ' %s' \
1169 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1170 msg 'ERROR: Please read INSTALL, rerun'
1171 config_exit 1
1174 # This may also update ld_runtime_flags() (again)
1175 cc_flags
1177 for i in \
1178 INCS LIBS \
1179 ; do
1180 eval j=\$${i}
1181 printf -- "${i}=${j}\n" >> ${newlst}
1182 done
1183 for i in \
1184 CC \
1185 CFLAGS \
1186 LDFLAGS \
1187 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1188 OSFULLSPEC \
1189 ; do
1190 eval j=\$${i}
1191 printf -- "${i} = ${j}\n" >> ${newmk}
1192 printf -- "${i}=${j}\n" >> ${newlst}
1193 done
1195 # Now finally check whether we already have a configuration and if so, whether
1196 # all those parameters are still the same.. or something has actually changed
1197 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1198 echo 'Configuration is up-to-date'
1199 exit 0
1200 elif [ -f ${lst} ]; then
1201 echo 'Configuration has been updated..'
1202 ( eval "${MAKE} -f ./mk-config.mk clean" )
1203 echo
1204 else
1205 echo 'Shiny configuration..'
1208 # Time to redefine helper 1
1209 config_exit() {
1210 ${rm} -f ${lst} ${h} ${mk}
1211 exit ${1}
1214 ${mv} -f ${newlst} ${lst}
1215 ${mv} -f ${newev} ${ev}
1216 ${mv} -f ${newh} ${h}
1217 ${mv} -f ${newmk} ${mk}
1219 if [ -z "${VERBOSE}" ]; then
1220 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1221 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1222 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1223 printf -- "ECHO_TEST = @\n" >> ${mk}
1224 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1225 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1226 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1229 ## Compile and link checking
1231 tmp3=./${tmp0}3$$
1232 log=./mk-config.log
1233 lib=./mk-config.lib
1234 inc=./mk-config.inc
1235 makefile=./${tmp0}.mk
1237 # (No function since some shells loose non-exported variables in traps)
1238 trap "trap \"\" HUP INT TERM;\
1239 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1240 trap "trap \"\" HUP INT TERM EXIT;\
1241 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1243 # Time to redefine helper 2
1244 msg() {
1245 fmt=${1}
1246 shift
1247 printf "*** ${fmt}\\n" "${@}"
1248 printf -- "${fmt}\\n" "${@}" >&5
1250 msg_nonl() {
1251 fmt=${1}
1252 shift
1253 printf "*** ${fmt}\\n" "${@}"
1254 printf -- "${fmt}" "${@}" >&5
1257 # !!
1258 exec 5>&2 > ${log} 2>&1
1260 echo "${LIBS}" > ${lib}
1261 echo "${INCS}" > ${inc}
1262 ${cat} > ${makefile} << \!
1263 .SUFFIXES: .o .c .x .y
1264 .c.o:
1265 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1266 .c.x:
1267 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1269 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1272 ## Generics
1274 # May be multiline..
1275 echo >> ${h}
1276 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1277 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1278 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1280 # Generate n_err_number OS mappings
1282 feat_yes DEVEL && NV= || NV=noverbose
1283 TARGET="${h}" awk="${awk}" ./make-errors.sh ${NV} config
1285 xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1287 feat_def ALWAYS_UNICODE_LOCALE
1288 feat_def AMALGAMATION
1289 feat_def CROSS_BUILD
1290 feat_def DOCSTRINGS
1291 feat_def ERRORS
1293 feat_def ASAN_ADDRESS
1294 feat_def ASAN_MEMORY
1295 feat_def DEBUG
1296 feat_def DEVEL
1297 feat_def NYD2
1298 feat_def NOMEMDBG
1300 if xrun_check inline 'inline functions' \
1301 '#define HAVE_INLINE
1302 #define n_INLINE static inline' << \!
1303 static inline int ilf(int i){return ++i;}
1304 int main(void){return ilf(-1);}
1306 then
1308 elif xrun_check inline 'inline functions (via __inline)' \
1309 '#define HAVE_INLINE
1310 #define n_INLINE static __inline' << \!
1311 static __inline int ilf(int i){return ++i;}
1312 int main(void){return ilf(-1);}
1314 then
1318 ## Test for "basic" system-calls / functionality that is used by all parts
1319 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1320 ## macros to be used by only the subprograms (potentially).
1322 if run_check clock_gettime 'clock_gettime(2)' \
1323 '#define HAVE_CLOCK_GETTIME' << \!
1324 #include <time.h>
1325 # include <errno.h>
1326 int main(void){
1327 struct timespec ts;
1329 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1330 return 0;
1331 return 1;
1334 then
1336 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1337 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1338 #include <time.h>
1339 # include <errno.h>
1340 int main(void){
1341 struct timespec ts;
1343 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1344 return 0;
1345 return 1;
1348 then
1350 elif run_check gettimeofday 'gettimeofday(2)' \
1351 '#define HAVE_GETTIMEOFDAY' << \!
1352 #include <stdio.h> /* For C89 NULL */
1353 #include <sys/time.h>
1354 # include <errno.h>
1355 int main(void){
1356 struct timeval tv;
1358 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1359 return 0;
1360 return 1;
1363 then
1365 else
1366 have_no_subsecond_time=1
1369 if run_check nanosleep 'nanosleep(2)' \
1370 '#define HAVE_NANOSLEEP' << \!
1371 #include <time.h>
1372 # include <errno.h>
1373 int main(void){
1374 struct timespec ts;
1376 ts.tv_sec = 1;
1377 ts.tv_nsec = 100000;
1378 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1379 return 0;
1380 return 1;
1383 then
1385 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1386 '#define HAVE_NANOSLEEP' '-lrt' << \!
1387 #include <time.h>
1388 # include <errno.h>
1389 int main(void){
1390 struct timespec ts;
1392 ts.tv_sec = 1;
1393 ts.tv_nsec = 100000;
1394 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1395 return 0;
1396 return 1;
1399 then
1401 # link_check is enough for this, that function is so old, trust the proto
1402 elif link_check sleep 'sleep(3)' \
1403 '#define HAVE_SLEEP' << \!
1404 #include <unistd.h>
1405 # include <errno.h>
1406 int main(void){
1407 if(!sleep(1) || errno != ENOSYS)
1408 return 0;
1409 return 1;
1412 then
1414 else
1415 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1416 config_exit 1
1419 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1420 #include <pwd.h>
1421 #include <unistd.h>
1422 # include <errno.h>
1423 int main(void){
1424 struct passwd *pw;
1425 gid_t gid;
1426 uid_t uid;
1428 if((gid = getgid()) != 0)
1429 gid = getegid();
1430 if((uid = getuid()) != 0)
1431 uid = geteuid();
1432 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1433 return 1;
1434 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1435 return 1;
1436 return 0;
1439 then
1441 else
1442 msg 'ERROR: we require user and group info / database searches.'
1443 msg 'That much Unix we indulge ourselfs.'
1444 config_exit 1
1447 if link_check ftruncate 'ftruncate(2)' \
1448 '#define HAVE_FTRUNCATE' << \!
1449 #include <unistd.h>
1450 #include <sys/types.h>
1451 int main(void){
1452 return (ftruncate(0, 0) != 0);
1455 then
1457 else
1458 msg 'ERROR: we require the ftruncate(2) system call.'
1459 config_exit 1
1462 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1463 #include <signal.h>
1464 # include <errno.h>
1465 int main(void){
1466 struct sigaction nact, oact;
1468 nact.sa_handler = SIG_DFL;
1469 sigemptyset(&nact.sa_mask);
1470 nact.sa_flags = SA_RESTART;
1471 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1474 then
1476 else
1477 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1478 config_exit 1
1481 if link_check snprintf 'snprintf(3)' << \!
1482 #include <stdio.h>
1483 int main(void){
1484 char b[20];
1486 snprintf(b, sizeof b, "%s", "string");
1487 return 0;
1490 then
1492 else
1493 msg 'ERROR: we require the snprintf(3) function.'
1494 config_exit 1
1497 if link_check environ 'environ(3)' << \!
1498 #include <stdio.h> /* For C89 NULL */
1499 int main(void){
1500 extern char **environ;
1502 return environ[0] == NULL;
1505 then
1507 else
1508 msg 'ERROR: we require the environ(3) array for subprocess control.'
1509 config_exit 1
1512 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1513 #include <stdlib.h>
1514 int main(void){
1515 setenv("s-mailx", "i want to see it cute!", 1);
1516 unsetenv("s-mailx");
1517 return 0;
1520 then
1522 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1523 #include <stdlib.h>
1524 int main(void){
1525 putenv("s-mailx=i want to see it cute!");
1526 return 0;
1529 then
1531 else
1532 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1533 config_exit 1
1536 if link_check termios 'termios.h and tc*(3) family' << \!
1537 #include <termios.h>
1538 int main(void){
1539 struct termios tios;
1541 tcgetattr(0, &tios);
1542 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1543 return 0;
1546 then
1548 else
1549 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1550 msg 'That much Unix we indulge ourselfs.'
1551 config_exit 1
1554 ## optional stuff
1556 if link_check vsnprintf 'vsnprintf(3)' << \!
1557 #include <stdarg.h>
1558 #include <stdio.h>
1559 static void dome(char *buf, size_t blen, ...){
1560 va_list ap;
1562 va_start(ap, blen);
1563 vsnprintf(buf, blen, "%s", ap);
1564 va_end(ap);
1566 int main(void){
1567 char b[20];
1569 dome(b, sizeof b, "string");
1570 return 0;
1573 then
1575 else
1576 feat_bail_required ERRORS
1579 if [ "${have_vsnprintf}" = yes ]; then
1580 __va_copy() {
1581 link_check va_copy "va_copy(3) (as ${2})" \
1582 "#define HAVE_N_VA_COPY
1583 #define n_va_copy ${2}" <<_EOT
1584 #include <stdarg.h>
1585 #include <stdio.h>
1586 #if ${1}
1587 # if defined __va_copy && !defined va_copy
1588 # define va_copy __va_copy
1589 # endif
1590 #endif
1591 static void dome2(char *buf, size_t blen, va_list src){
1592 va_list ap;
1594 va_copy(ap, src);
1595 vsnprintf(buf, blen, "%s", ap);
1596 va_end(ap);
1598 static void dome(char *buf, size_t blen, ...){
1599 va_list ap;
1601 va_start(ap, blen);
1602 dome2(buf, blen, ap);
1603 va_end(ap);
1605 int main(void){
1606 char b[20];
1608 dome(b, sizeof b, "string");
1609 return 0;
1611 _EOT
1613 __va_copy 0 va_copy || __va_copy 1 __va_copy
1616 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1617 #include <unistd.h>
1618 #include <errno.h>
1619 int main(void){
1620 int rv = 0;
1622 errno = 0;
1623 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1624 errno = 0;
1625 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1627 /* Only link check */
1628 fpathconf(0, _PC_NAME_MAX);
1630 return rv;
1634 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1635 #include <fcntl.h>
1636 #include <unistd.h>
1637 # include <errno.h>
1638 int main(void){
1639 int fds[2];
1641 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1642 return 0;
1643 return 1;
1647 # We use this only then for now (need NOW+1)
1648 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1649 #include <fcntl.h> /* For AT_* */
1650 #include <sys/stat.h>
1651 # include <errno.h>
1652 int main(void){
1653 struct timespec ts[2];
1655 ts[0].tv_nsec = UTIME_NOW;
1656 ts[1].tv_nsec = UTIME_OMIT;
1657 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1658 return 0;
1659 return 1;
1665 # XXX Add POSIX check once standardized
1666 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1667 #include <stdlib.h>
1668 int main(void){
1669 arc4random();
1670 return 0;
1673 then
1675 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1676 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1677 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1678 #include <sys/random.h>
1679 int main(void){
1680 char buf[256];
1681 getrandom(buf, sizeof buf, 0);
1682 return 0;
1685 then
1687 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1688 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1689 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1690 #include <sys/syscall.h>
1691 int main(void){
1692 char buf[256];
1693 syscall(SYS_getrandom, buf, sizeof buf, 0);
1694 return 0;
1697 then
1699 elif [ -n "${have_no_subsecond_time}" ]; then
1700 msg 'ERROR: %s %s' 'without a native random' \
1701 'one of clock_gettime(2) and gettimeofday(2) is required.'
1702 config_exit 1
1706 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1707 #include <stdio.h>
1708 int main(void){
1709 putc_unlocked('@', stdout);
1710 return 0;
1714 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1715 #include <unistd.h>
1716 int main(void){
1717 fchdir(0);
1718 return 0;
1722 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1723 #include <stdlib.h>
1724 int main(void){
1725 char x_buf[4096], *x = realpath(".", x_buf);
1727 return (x != NULL) ? 0 : 1;
1730 then
1731 if run_check realpath_malloc 'realpath(3) takes NULL' \
1732 '#define HAVE_REALPATH_NULL' << \!
1733 #include <stdlib.h>
1734 int main(void){
1735 char *x = realpath(".", NULL);
1737 if(x != NULL)
1738 free(x);
1739 return (x != NULL) ? 0 : 1;
1742 then
1747 ## optional and selectable
1749 if feat_yes DOTLOCK; then
1750 if run_check readlink 'readlink(2)' << \!
1751 #include <unistd.h>
1752 # include <errno.h>
1753 int main(void){
1754 char buf[128];
1756 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1757 return 0;
1758 return 1;
1761 then
1763 else
1764 feat_bail_required DOTLOCK
1768 if feat_yes DOTLOCK; then
1769 if run_check fchown 'fchown(2)' << \!
1770 #include <unistd.h>
1771 # include <errno.h>
1772 int main(void){
1773 if(!fchown(0, 0, 0) || errno != ENOSYS)
1774 return 0;
1775 return 1;
1778 then
1780 else
1781 feat_bail_required DOTLOCK
1785 ## Now it is the time to fork away the BASE_ series
1787 ${rm} -f ${tmp}
1788 squeeze_em ${inc} ${tmp}
1789 ${mv} ${tmp} ${inc}
1790 squeeze_em ${lib} ${tmp}
1791 ${mv} ${tmp} ${lib}
1793 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1794 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1796 ## The remains are expected to be used only by the main MUA binary!
1798 OPT_LOCALES=0
1799 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1800 #include <locale.h>
1801 int main(void){
1802 setlocale(LC_ALL, "");
1803 return 0;
1806 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1808 OPT_MULTIBYTE_CHARSETS=0
1809 OPT_WIDE_GLYPHS=0
1810 OPT_TERMINAL_CHARSET=0
1811 if [ -n "${have_setlocale}" ]; then
1812 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1813 '#define HAVE_C90AMEND1' << \!
1814 #include <limits.h>
1815 #include <stdlib.h>
1816 #include <wchar.h>
1817 #include <wctype.h>
1818 int main(void){
1819 char mbb[MB_LEN_MAX + 1];
1820 wchar_t wc;
1822 iswprint(L'c');
1823 towupper(L'c');
1824 mbtowc(&wc, "x", 1);
1825 mbrtowc(&wc, "x", 1, NULL);
1826 wctomb(mbb, wc);
1827 return (mblen("\0", 1) == 0);
1830 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1832 if [ -n "${have_c90amend1}" ]; then
1833 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1834 #include <wchar.h>
1835 int main(void){
1836 wcwidth(L'c');
1837 return 0;
1840 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1843 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1844 #include <langinfo.h>
1845 #include <stdlib.h>
1846 int main(void){
1847 nl_langinfo(DAY_1);
1848 return (nl_langinfo(CODESET) == NULL);
1851 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1852 fi # have_setlocale
1854 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1855 #include <fnmatch.h>
1856 int main(void){
1857 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1861 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1862 #include <dirent.h>
1863 int main(void){
1864 struct dirent de;
1865 return !(de.d_type == DT_UNKNOWN ||
1866 de.d_type == DT_DIR || de.d_type == DT_LNK);
1870 ## optional and selectable
1872 if feat_yes ICONV; then
1873 ${cat} > ${tmp2}.c << \!
1874 #include <stdio.h> /* For C89 NULL */
1875 #include <iconv.h>
1876 int main(void){
1877 iconv_t id;
1879 id = iconv_open("foo", "bar");
1880 iconv(id, NULL, NULL, NULL, NULL);
1881 iconv_close(id);
1882 return 0;
1885 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1886 '#define HAVE_ICONV' ||
1887 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1888 '#define HAVE_ICONV' '-liconv' ||
1889 feat_bail_required ICONV
1890 else
1891 echo '/* OPT_ICONV=0 */' >> ${h}
1892 fi # feat_yes ICONV
1894 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1895 ${cat} > ${tmp2}.c << \!
1896 #include <sys/types.h>
1897 #include <sys/socket.h>
1898 #include <sys/un.h>
1899 # include <errno.h>
1900 int main(void){
1901 struct sockaddr_un soun;
1903 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1904 return 1;
1905 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1906 return 1;
1907 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1908 return 1;
1909 return 0;
1913 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1914 '#define HAVE_UNIX_SOCKETS' ||
1915 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1916 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1917 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1918 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1921 if feat_yes SOCKETS; then
1922 ${cat} > ${tmp2}.c << \!
1923 #include <sys/types.h>
1924 #include <sys/socket.h>
1925 #include <netinet/in.h>
1926 # include <errno.h>
1927 int main(void){
1928 struct sockaddr s;
1930 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1931 return 1;
1932 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1933 return 1;
1934 return 0;
1938 < ${tmp2}.c run_check sockets 'sockets' \
1939 '#define HAVE_SOCKETS' ||
1940 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1941 '#define HAVE_SOCKETS' '-lnsl' ||
1942 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1943 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1944 feat_bail_required SOCKETS
1945 else
1946 echo '/* OPT_SOCKETS=0 */' >> ${h}
1947 fi # feat_yes SOCKETS
1949 if feat_yes SOCKETS; then
1950 link_check getaddrinfo 'getaddrinfo(3)' \
1951 '#define HAVE_GETADDRINFO' << \!
1952 #include <sys/types.h>
1953 #include <sys/socket.h>
1954 #include <stdio.h>
1955 #include <netdb.h>
1956 int main(void){
1957 struct addrinfo a, *ap;
1958 int lrv;
1960 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1961 case EAI_NONAME:
1962 case EAI_SERVICE:
1963 default:
1964 fprintf(stderr, "%s\n", gai_strerror(lrv));
1965 case 0:
1966 break;
1968 return 0;
1973 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1974 compile_check arpa_inet_h '<arpa/inet.h>' \
1975 '#define HAVE_ARPA_INET_H' << \!
1976 #include <sys/types.h>
1977 #include <sys/socket.h>
1978 #include <netdb.h>
1979 #include <netinet/in.h>
1980 #include <arpa/inet.h>
1983 ${cat} > ${tmp2}.c << \!
1984 #include <sys/types.h>
1985 #include <sys/socket.h>
1986 #include <stdio.h>
1987 #include <string.h>
1988 #include <netdb.h>
1989 #include <netinet/in.h>
1990 #ifdef HAVE_ARPA_INET_H
1991 #include <arpa/inet.h>
1992 #endif
1993 int main(void){
1994 struct sockaddr_in servaddr;
1995 unsigned short portno;
1996 struct servent *ep;
1997 struct hostent *hp;
1998 struct in_addr **pptr;
2000 portno = 0;
2001 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2002 portno = (unsigned short)ep->s_port;
2004 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2005 pptr = (struct in_addr**)hp->h_addr_list;
2006 if(hp->h_addrtype != AF_INET)
2007 fprintf(stderr, "au\n");
2008 }else{
2009 switch(h_errno){
2010 case HOST_NOT_FOUND:
2011 case TRY_AGAIN:
2012 case NO_RECOVERY:
2013 case NO_DATA:
2014 break;
2015 default:
2016 fprintf(stderr, "au\n");
2017 break;
2021 memset(&servaddr, 0, sizeof servaddr);
2022 servaddr.sin_family = AF_INET;
2023 servaddr.sin_port = htons(portno);
2024 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2025 fprintf(stderr, "Would connect to %s:%d ...\n",
2026 inet_ntoa(**pptr), (int)portno);
2027 return 0;
2031 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2032 < ${tmp2}.c link_check gethostbyname \
2033 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2034 < ${tmp2}.c link_check gethostbyname \
2035 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2036 '' '-lsocket -lnsl' ||
2037 feat_bail_required SOCKETS
2040 feat_yes SOCKETS &&
2041 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2042 #include <sys/socket.h>
2043 #include <stdlib.h>
2044 # include <errno.h>
2045 int main(void){
2046 int sockfd = 3;
2048 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2049 errno == ENOSYS)
2050 return 1;
2051 return 0;
2055 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2056 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2057 #include <sys/socket.h>
2058 #include <stdlib.h>
2059 int main(void){
2060 struct timeval tv;
2061 int sockfd = 3;
2063 tv.tv_sec = 42;
2064 tv.tv_usec = 21;
2065 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2066 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2067 return 0;
2071 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2072 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2073 #include <sys/socket.h>
2074 #include <stdlib.h>
2075 int main(void){
2076 struct linger li;
2077 int sockfd = 3;
2079 li.l_onoff = 1;
2080 li.l_linger = 42;
2081 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2082 return 0;
2086 if feat_yes SSL; then # {{{
2087 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2088 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2089 # time: we need to test it first in order to get things right
2090 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2091 '#define HAVE_SSL
2092 #define HAVE_XSSL
2093 #define HAVE_XSSL_RESSL
2094 #define HAVE_XSSL_OPENSSL 0' << \!
2095 #include <openssl/opensslv.h>
2096 #ifdef LIBRESSL_VERSION_NUMBER
2097 #else
2098 # error nope
2099 #endif
2101 then
2102 ossl_v1_1=
2103 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2104 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2105 '#define HAVE_SSL
2106 #define HAVE_XSSL
2107 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2108 #include <openssl/opensslv.h>
2109 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2110 #else
2111 # error nope
2112 #endif
2114 then
2115 ossl_v1_1=1
2116 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2117 '#define HAVE_SSL
2118 #define HAVE_XSSL
2119 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2120 #include <openssl/opensslv.h>
2121 #ifdef OPENSSL_VERSION_NUMBER
2122 #else
2123 # error nope
2124 #endif
2126 then
2127 ossl_v1_1=
2128 else
2129 feat_bail_required SSL
2130 fi # }}}
2132 if feat_yes SSL; then # {{{
2133 if [ -n "${ossl_v1_1}" ]; then
2134 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2135 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2136 '-lssl -lcrypto'
2137 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2138 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2139 '-lssl -lcrypto' << \!
2140 #include <openssl/ssl.h>
2141 #include <openssl/err.h>
2142 #include <openssl/x509v3.h>
2143 #include <openssl/x509.h>
2144 #include <openssl/rand.h>
2145 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2146 # error We need TLSv1.
2147 #endif
2148 int main(void){
2149 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2151 SSL_CTX_free(ctx);
2152 PEM_read_PrivateKey(0, 0, 0, 0);
2153 return 0;
2156 then
2158 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2159 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2160 '-lssl -lcrypto' << \!
2161 #include <openssl/ssl.h>
2162 #include <openssl/err.h>
2163 #include <openssl/x509v3.h>
2164 #include <openssl/x509.h>
2165 #include <openssl/rand.h>
2166 #if defined OPENSSL_NO_SSL3 &&\
2167 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2168 # error We need one of SSLv3 and TLSv1.
2169 #endif
2170 int main(void){
2171 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2173 SSL_CTX_free(ctx);
2174 PEM_read_PrivateKey(0, 0, 0, 0);
2175 return 0;
2178 then
2180 else
2181 feat_bail_required SSL
2183 fi # }}}
2185 if feat_yes SSL; then # {{{
2186 if [ -n "${ossl_v1_1}" ]; then
2187 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2188 '#define HAVE_XSSL_STACK_OF'
2189 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2190 '#define HAVE_XSSL_STACK_OF' << \!
2191 #include <stdio.h> /* For C89 NULL */
2192 #include <openssl/ssl.h>
2193 #include <openssl/err.h>
2194 #include <openssl/x509v3.h>
2195 #include <openssl/x509.h>
2196 #include <openssl/rand.h>
2197 int main(void){
2198 STACK_OF(GENERAL_NAME) *gens = NULL;
2200 printf("%p", gens); /* to use it */
2201 return 0;
2204 then
2208 if [ -n "${ossl_v1_1}" ]; then
2209 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2210 '#define HAVE_XSSL_CONFIG'
2211 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2212 '#define HAVE_XSSL_CONFIG' << \!
2213 #include <stdio.h> /* For C89 NULL */
2214 #include <openssl/conf.h>
2215 int main(void){
2216 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2217 CONF_modules_free();
2218 return 0;
2221 then
2225 if [ -n "${ossl_v1_1}" ]; then
2226 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2227 '#define HAVE_XSSL_CONF_CTX'
2228 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2229 '#define HAVE_XSSL_CONF_CTX' << \!
2230 #include <openssl/ssl.h>
2231 #include <openssl/err.h>
2232 int main(void){
2233 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2234 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2236 SSL_CONF_CTX_set_flags(cctx,
2237 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2238 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2239 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2240 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2241 SSL_CONF_CTX_finish(cctx);
2242 SSL_CONF_CTX_free(cctx);
2243 SSL_CTX_free(ctx);
2244 return 0;
2247 then
2251 if [ -n "${ossl_v1_1}" ]; then
2252 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2253 '#define HAVE_XSSL_RAND_EGD'
2254 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2255 '#define HAVE_XSSL_RAND_EGD' << \!
2256 #include <openssl/rand.h>
2257 int main(void){
2258 return RAND_egd("some.where") > 0;
2261 then
2265 if feat_yes SSL_ALL_ALGORITHMS; then
2266 if [ -n "${ossl_v1_1}" ]; then
2267 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2268 '#define HAVE_SSL_ALL_ALGORITHMS'
2269 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2270 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2271 #include <openssl/evp.h>
2272 int main(void){
2273 OpenSSL_add_all_algorithms();
2274 EVP_get_cipherbyname("two cents i never exist");
2275 EVP_cleanup();
2276 return 0;
2279 then
2281 else
2282 feat_bail_required SSL_ALL_ALGORITHMS
2285 fi # feat_yes SSL }}}
2287 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2288 run_check ssl_md5 'MD5 digest in the used crypto library' \
2289 '#define HAVE_XSSL_MD5' << \!
2290 #include <stdlib.h>
2291 #include <string.h>
2292 #include <openssl/md5.h>
2293 int main(void){
2294 char const dat[] = "abrakadabrafidibus";
2295 char dig[16], hex[16 * 2];
2296 MD5_CTX ctx;
2297 size_t i, j;
2299 memset(dig, 0, sizeof(dig));
2300 memset(hex, 0, sizeof(hex));
2301 MD5_Init(&ctx);
2302 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2303 MD5_Final(dig, &ctx);
2305 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2306 for(i = 0; i < sizeof(hex) / 2; i++){
2307 j = i << 1;
2308 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2309 hex[++j] = hexchar(dig[i] & 0x0f);
2311 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2314 fi # }}}
2315 else
2316 echo '/* OPT_SSL=0 */' >> ${h}
2317 fi # }}} feat_yes SSL
2319 if [ "${have_xssl}" = yes ]; then
2320 OPT_SMIME=1
2321 else
2322 OPT_SMIME=0
2324 feat_def SMIME
2326 feat_def SMTP
2327 feat_def POP3
2328 feat_def IMAP
2330 if feat_yes GSSAPI; then
2331 ${cat} > ${tmp2}.c << \!
2332 #include <gssapi/gssapi.h>
2333 int main(void){
2334 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2335 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2336 return 0;
2339 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2341 if command -v krb5-config >/dev/null 2>&1; then
2342 i=`command -v krb5-config`
2343 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2344 GSS_INCS="`CFLAGS= ${i} --cflags`"
2345 i='GSS-API via krb5-config(1)'
2346 else
2347 GSS_LIBS='-lgssapi'
2348 GSS_INCS=
2349 i='GSS-API in gssapi/gssapi.h, libgssapi'
2351 if < ${tmp2}.c link_check gss \
2352 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2353 < ${tmp3}.c link_check gss \
2354 'GSS-API in gssapi.h, libgssapi' \
2355 '#define HAVE_GSSAPI
2356 #define GSSAPI_REG_INCLUDE' \
2357 '-lgssapi' ||\
2358 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2359 '#define HAVE_GSSAPI' \
2360 '-lgssapi_krb5' ||\
2361 < ${tmp3}.c link_check gss \
2362 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2363 '#define HAVE_GSSAPI
2364 #define GSS_REG_INCLUDE' \
2365 '-lgssapi -lkrb5 -lcrypto' \
2366 '-I/usr/include/kerberosV' ||\
2367 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2368 '#define HAVE_GSSAPI' \
2369 '-lgss' ||\
2370 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2371 '#define HAVE_GSSAPI
2372 #define GSSAPI_OLD_STYLE' \
2373 '-lgssapi_krb5' << \!
2374 #include <gssapi/gssapi.h>
2375 #include <gssapi/gssapi_generic.h>
2376 int main(void){
2377 gss_import_name(0, 0, gss_nt_service_name, 0);
2378 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2379 return 0;
2382 then
2384 else
2385 feat_bail_required GSSAPI
2387 else
2388 echo '/* OPT_GSSAPI=0 */' >> ${h}
2389 fi # feat_yes GSSAPI
2391 feat_def NETRC
2392 feat_def AGENT
2394 if feat_yes IDNA; then
2395 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2396 '-lidn' << \!
2397 #include <idna.h>
2398 #include <idn-free.h>
2399 #include <stringprep.h>
2400 int main(void){
2401 char *utf8, *idna_ascii, *idna_utf8;
2403 utf8 = stringprep_locale_to_utf8("does.this.work");
2404 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2405 != IDNA_SUCCESS)
2406 return 1;
2407 idn_free(idna_ascii);
2408 /* (Rather link check only here) */
2409 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2410 return 0;
2413 then
2415 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2416 '-lidnkit' << \!
2417 #include <stdio.h>
2418 #include <idn/api.h>
2419 #include <idn/result.h>
2420 int main(void){
2421 idn_result_t r;
2422 char ace_name[256];
2423 char local_name[256];
2425 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2426 sizeof(ace_name));
2427 if (r != idn_success) {
2428 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2429 return 1;
2431 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2432 if (r != idn_success) {
2433 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2434 return 1;
2436 return 0;
2439 then
2441 else
2442 feat_bail_required IDNA
2445 if [ -n "${have_idna}" ]; then
2446 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2447 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2449 else
2450 echo '/* OPT_IDNA=0 */' >> ${h}
2453 feat_def IMAP_SEARCH
2455 if feat_yes REGEX; then
2456 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2457 #include <regex.h>
2458 #include <stdlib.h>
2459 int main(void){
2460 size_t xret;
2461 int status;
2462 regex_t re;
2464 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2465 xret = regerror(status, &re, NULL, 0);
2466 status = regexec(&re, "plan9", 0,NULL, 0);
2467 regfree(&re);
2468 return !(status == REG_NOMATCH);
2471 then
2473 else
2474 feat_bail_required REGEX
2476 else
2477 echo '/* OPT_REGEX=0 */' >> ${h}
2480 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2481 have_mle=1
2482 echo '#define HAVE_MLE' >> ${h}
2483 else
2484 feat_bail_required MLE
2485 echo '/* OPT_MLE=0 */' >> ${h}
2488 # Generic have-a-line-editor switch for those who need it below
2489 if [ -n "${have_mle}" ]; then
2490 have_cle=1
2493 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2494 echo '#define HAVE_HISTORY' >> ${h}
2495 else
2496 echo '/* OPT_HISTORY=0 */' >> ${h}
2499 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2500 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2501 else
2502 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2505 if feat_yes TERMCAP; then
2506 __termcaplib() {
2507 link_check termcap "termcap(5) (via ${4})" \
2508 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2509 #include <stdio.h>
2510 #include <stdlib.h>
2511 ${2}
2512 #include <term.h>
2513 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2514 static int my_putc(int c){return putchar(c);}
2515 int main(void){
2516 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2517 int r2 = OK, r3 = ERR;
2519 tgetent(buf, getenv("TERM"));
2520 cpb = cmdbuf;
2521 r1 = tgetstr(UNCONST("cm"), &cpb);
2522 tgoto(r1, 1, 1);
2523 r2 = tgetnum(UNCONST("Co"));
2524 r3 = tgetflag(UNCONST("ut"));
2525 tputs("cr", 1, &my_putc);
2526 return (r1 == NULL || r2 == -1 || r3 == 0);
2528 _EOT
2531 __terminfolib() {
2532 link_check terminfo "terminfo(5) (via ${2})" \
2533 '#define HAVE_TERMCAP
2534 #define HAVE_TERMCAP_CURSES
2535 #define HAVE_TERMINFO' "${1}" << _EOT
2536 #include <stdio.h>
2537 #include <curses.h>
2538 #include <term.h>
2539 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2540 static int my_putc(int c){return putchar(c);}
2541 int main(void){
2542 int er, r0, r1, r2;
2543 char *r3, *tp;
2545 er = OK;
2546 r0 = setupterm(NULL, 1, &er);
2547 r1 = tigetflag(UNCONST("bce"));
2548 r2 = tigetnum(UNCONST("colors"));
2549 r3 = tigetstr(UNCONST("cr"));
2550 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2551 tputs(tp, 1, &my_putc);
2552 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2553 r3 == (char*)-1 || r3 == NULL);
2555 _EOT
2558 if feat_yes TERMCAP_VIA_TERMINFO; then
2559 __terminfolib -ltinfo -ltinfo ||
2560 __terminfolib -lcurses -lcurses ||
2561 __terminfolib -lcursesw -lcursesw ||
2562 feat_bail_required TERMCAP_VIA_TERMINFO
2565 if [ -z "${have_terminfo}" ]; then
2566 __termcaplib -ltermcap '' '' '-ltermcap' ||
2567 __termcaplib -ltermcap '#include <curses.h>' '
2568 #define HAVE_TERMCAP_CURSES' \
2569 'curses.h / -ltermcap' ||
2570 __termcaplib -lcurses '#include <curses.h>' '
2571 #define HAVE_TERMCAP_CURSES' \
2572 'curses.h / -lcurses' ||
2573 __termcaplib -lcursesw '#include <curses.h>' '
2574 #define HAVE_TERMCAP_CURSES' \
2575 'curses.h / -lcursesw' ||
2576 feat_bail_required TERMCAP
2578 if [ -n "${have_termcap}" ]; then
2579 run_check tgetent_null \
2580 "tgetent(3) of termcap(5) takes NULL buffer" \
2581 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2582 #include <stdio.h> /* For C89 NULL */
2583 #include <stdlib.h>
2584 #ifdef HAVE_TERMCAP_CURSES
2585 # include <curses.h>
2586 #endif
2587 #include <term.h>
2588 int main(void){
2589 tgetent(NULL, getenv("TERM"));
2590 return 0;
2592 _EOT
2595 else
2596 echo '/* OPT_TERMCAP=0 */' >> ${h}
2597 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2600 if feat_def SPAM_SPAMC; then
2601 if command -v spamc >/dev/null 2>&1; then
2602 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2606 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2607 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2608 else
2609 feat_bail_required SPAM_SPAMD
2610 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2613 feat_def SPAM_FILTER
2615 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2616 echo '#define HAVE_SPAM' >> ${h}
2617 else
2618 echo '/* HAVE_SPAM */' >> ${h}
2621 if feat_yes QUOTE_FOLD &&\
2622 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2623 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2624 else
2625 feat_bail_required QUOTE_FOLD
2626 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2629 feat_def FILTER_HTML_TAGSOUP
2630 feat_def COLOUR
2631 feat_def DOTLOCK
2632 feat_def MD5
2633 feat_def NOMEMDBG
2635 ## Summarizing
2637 ${rm} -f ${tmp}
2638 squeeze_em ${inc} ${tmp}
2639 ${mv} ${tmp} ${inc}
2640 squeeze_em ${lib} ${tmp}
2641 ${mv} ${tmp} ${lib}
2643 # mk-config.h
2644 ${mv} ${h} ${tmp}
2645 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2646 ${cat} ${tmp} >> ${h}
2647 ${rm} -f ${tmp}
2648 printf '\n' >> ${h}
2650 # Create the real mk-config.mk
2651 # Note we cannout use explicit ./ filename prefix for source and object
2652 # pathnames because of a bug in bmake(1)
2653 ${rm} -rf ${tmp0}.* ${tmp0}*
2654 printf 'OBJ_SRC = ' >> ${mk}
2655 if feat_no AMALGAMATION; then
2656 for i in `printf '%s\n' *.c | ${sort}`; do
2657 if [ "${i}" = privsep.c ]; then
2658 continue
2660 printf "${i} " >> ${mk}
2661 done
2662 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2663 else
2664 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2666 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2667 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2668 printf '# undef _CONFIG_H\n' >> ${h}
2669 printf '# define _CONFIG_H 2\n' >> ${h}
2670 for i in `printf '%s\n' *.c | ${sort}`; do
2671 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2672 [ "${i}" = privsep.c ]; then
2673 continue
2675 printf "${i} " >> ${mk}
2676 printf "# include \"${i}\"\n" >> ${h}
2677 done
2678 echo >> ${mk}
2679 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2680 echo '#else' >> ${h}
2683 # Finally, create the string that is used by *features* and `version'.
2684 # Take this nice opportunity and generate a visual listing of included and
2685 # non-included features for the person who runs the configuration
2686 msg '\nThe following features are included (+) or not (-):'
2687 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2688 printf '/* The "feature string" */\n' >> ${h}
2689 # Because + is expanded by *folder* if first in "echo $features", put something
2690 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2691 sep=
2692 for opt
2694 sdoc=`option_doc_of ${opt}`
2695 [ -z "${sdoc}" ] && continue
2696 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2697 feat_yes ${opt} && sign=+ || sign=-
2698 printf -- "${sep}${sign}${sopt}" >> ${h}
2699 sep=','
2700 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2701 done
2702 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2703 #exec 5>&1 >>${h}
2704 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2705 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2707 printf '"\n#endif /* n_MK_CONFIG_H */\n' >> ${h}
2709 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2710 echo "INCS = `${cat} ${inc}`" >> ${mk}
2711 echo >> ${mk}
2712 ${cat} ./make-config.in >> ${mk}
2714 ## Finished!
2716 msg '\nSetup:'
2717 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2718 msg ' . bindir: %s' "${VAL_BINDIR}"
2719 if feat_yes DOTLOCK; then
2720 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2722 msg ' . mandir: %s' "${VAL_MANDIR}"
2723 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2724 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2725 msg ''
2727 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2728 exit 0
2730 msg 'Remarks:'
2731 if [ -z "${have_fnmatch}" ]; then
2732 msg ' . The function fnmatch(3) could not be found.'
2733 msg ' Filename patterns like wildcard are not supported on your system'
2735 if [ -z "${have_fchdir}" ]; then
2736 msg ' . The function fchdir(2) could not be found.'
2737 msg ' We will use chdir(2) instead.'
2738 msg ' This is a problem only if the current working directory is changed'
2739 msg ' while this program is inside of it'
2741 msg ''
2743 # s-it-mode