FIX, uh!, ah!, command escape WS prefix + ignerr handling..
[s-mailx.git] / make-config.sh
blobbbc93c12c6b76b9b5b7a37255992b210d7b3bcf1
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 GSSAPI='Generic Security Service authentication' \
19 NETRC='.netrc file support' \
20 AGENT='-' \
21 MD5='MD5 message digest (APOP, CRAM-MD5)' \
22 IDNA='Internationalized Domain Names for Applications (encode only)' \
23 IMAP_SEARCH='IMAP-style search expressions' \
24 REGEX='Regular expressions' \
25 MLE='Mailx Line Editor' \
26 HISTORY='Line editor history management' \
27 KEY_BINDINGS='Configurable key bindings' \
28 TERMCAP='Terminal capability queries (termcap(5))' \
29 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
30 ERRORS='Error log message ring' \
31 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
32 SPAM_SPAMD='-' \
33 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
34 DOCSTRINGS='Command documentation help strings' \
35 QUOTE_FOLD='Extended *quote-fold*ing' \
36 FILTER_HTML_TAGSOUP='Simple builtin HTML-to-text display filter' \
37 COLOUR='Coloured message display' \
38 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
41 # Options which are automatically deduced from host environment, i.e., these
42 # need special treatment all around here to warp from/to OPT_ stuff
43 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
44 XOPTIONS_DETECT="\
45 LOCALES='Locale support - printable characters etc. depend on environment' \
46 MULTIBYTE_CHARSETS='Multibyte character sets' \
47 TERMINAL_CHARSET='Automatic detection of terminal character set' \
48 WIDE_GLYPHS='Wide glyph support' \
51 # Rather special options, for custom building, or which always exist.
52 # Mostly for generating the visual overview and the *features* string
53 XOPTIONS_XTRA="\
54 MIME='Multipurpose Internet Mail Extensions' \
55 SMIME='S/MIME message signing, verification, en- and decryption' \
56 CROSS_BUILD='Cross-compilation: trust any detected environment' \
57 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
58 DEVEL='Computers do not blunder' \
61 # The problem is that we don't have any tools we can use right now, so
62 # encapsulate stuff in functions which get called in right order later on
64 option_reset() {
65 set -- ${OPTIONS}
66 for i
68 eval OPT_${i}=0
69 done
72 option_maximal() {
73 set -- ${OPTIONS}
74 for i
76 eval OPT_${i}=1
77 done
78 OPT_ICONV=require
79 OPT_REGEX=require
80 OPT_DOTLOCK=require
83 option_setup() {
84 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
85 option_parse OPTIONS "${XOPTIONS}"
86 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
87 OPT_MIME=1
89 # Predefined CONFIG= urations take precedence over anything else
90 if [ -n "${CONFIG}" ]; then
91 case "${CONFIG}" in
92 [nN][uU][lL][lL])
93 option_reset
95 [nN][uU][lL][lL][iI])
96 option_reset
97 OPT_ICONV=require
99 [mM][iI][nN][iI][mM][aA][lL])
100 option_reset
101 OPT_ICONV=1
102 OPT_REGEX=1
103 OPT_DOTLOCK=require
105 [mM][eE][dD][iI][uU][mM])
106 option_reset
107 OPT_ICONV=require
108 OPT_IDNA=1
109 OPT_REGEX=1
110 OPT_MLE=1
111 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
112 OPT_ERRORS=1
113 OPT_SPAM_FILTER=1
114 OPT_DOCSTRINGS=1
115 OPT_COLOUR=1
116 OPT_DOTLOCK=require
118 [nN][eE][tT][sS][eE][nN][dD])
119 option_reset
120 OPT_ICONV=require
121 OPT_SOCKETS=1
122 OPT_SSL=require
123 OPT_SMTP=require
124 OPT_GSSAPI=1 OPT_NETRC=1 OPT_AGENT=1
125 OPT_IDNA=1
126 OPT_REGEX=1
127 OPT_MLE=1
128 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
129 OPT_DOCSTRINGS=1
130 OPT_COLOUR=1
131 OPT_DOTLOCK=require
133 [mM][aA][xX][iI][mM][aA][lL])
134 option_reset
135 option_maximal
137 [dD][eE][vV][eE][lL])
138 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
139 option_maximal
141 [oO][dD][eE][vV][eE][lL])
142 OPT_DEVEL=1
143 option_maximal
146 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
147 echo >&2 ' NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
148 exit 1
150 esac
154 # Inter-relationships
155 option_update() {
156 if feat_no SMTP && feat_no POP3; then
157 OPT_SOCKETS=0
159 if feat_no SOCKETS; then
160 if feat_require SMTP; then
161 msg 'ERROR: need SOCKETS for required feature SMTP'
162 config_exit 13
164 if feat_require POP3; then
165 msg 'ERROR: need SOCKETS for required feature POP3'
166 config_exit 13
168 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
169 OPT_SMTP=0 OPT_POP3=0
170 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
172 if feat_no SMTP; then
173 OPT_GSSAPI=0
176 if feat_no MLE; then
177 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
180 # If we don't need MD5 leave it alone
181 if feat_no SOCKETS; then
182 OPT_MD5=0
185 if feat_no TERMCAP; then
186 OPT_TERMCAP_VIA_TERMINFO=0
189 if feat_yes DEVEL; then
190 OPT_DEBUG=1
194 rc=./make.rc
195 lst=./mk-config.lst
196 ev=./mk-config.ev
197 h=./mk-config.h h_name=mk-config.h
198 mk=./mk-config.mk
200 newlst=./mk-nconfig.lst
201 newmk=./mk-nconfig.mk
202 newev=./mk-nconfig.ev
203 newh=./mk-nconfig.h
204 tmp0=___tmp
205 tmp=./${tmp0}1$$
206 tmp2=./${tmp0}2$$
208 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
210 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
211 # via path_check() later on once possible
213 # TODO cc_maxopt is brute simple, we should compile test program and dig real
214 # compiler versions for known compilers, then be more specific
215 cc_maxopt=100
216 _CFLAGS= _LDFLAGS=
218 os_early_setup() {
219 # We don't "have any utility": only path adjustments and such in here!
220 i="${OS:-`uname -s`}"
222 if [ ${i} = SunOS ]; then
223 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
224 _os_early_setup_sunos
228 _os_early_setup_sunos() {
229 # According to standards(5), this is what we need to do
230 if [ -d /usr/xpg4 ]; then :; else
231 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
232 config_exit 1
234 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
235 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
236 export PATH
239 os_setup() {
240 # OSENV ends up in *build-osenv*
241 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
242 : ${OS:=`uname -s | ${tr} '[A-Z]' '[a-z]'`}
243 : ${OSENV:=`uname -srm`}
244 : ${OSFULLSPEC:=`uname -a`}
245 msg 'Operating system is %s' ${OS}
247 if [ ${OS} = sunos ]; then
248 msg ' . have special SunOS / Solaris "setup" rules ...'
249 _os_setup_sunos
250 elif [ ${OS} = unixware ]; then
251 msg ' . have special UnixWare environmental rules ...'
252 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
253 CC=cc
254 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
256 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
257 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
258 export CC CFLAGS LDFLAGS
259 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
261 elif [ -n "${VERBOSE}" ]; then
262 msg ' . no special treatment for this system necessary or known'
265 # Sledgehammer: better set _GNU_SOURCE
266 # And in general: oh, boy!
267 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
268 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
269 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
270 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
272 # On pkgsrc(7) systems automatically add /usr/pkg/*
273 if [ -d /usr/pkg ]; then
274 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
275 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
279 _os_setup_sunos() {
280 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
281 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
283 # Include packages
284 if [ -d /opt/csw ]; then
285 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
286 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
289 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
290 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
292 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
293 if [ -x "${cksum}" ]; then :; else
294 msg 'ERROR: Not an executable program: %s' "${cksum}"
295 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
296 msg 'ERROR: However, we do so only for tests.'
297 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
298 config_exit 1
301 if feat_yes AUTOCC; then
302 if command -v cc >/dev/null 2>&1; then
303 CC=cc
304 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
306 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
307 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
308 export CC CFLAGS LDFLAGS
309 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
310 else
311 # Assume gcc(1), which supports -R for compat
312 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
317 # Check out compiler ($CC) and -flags ($CFLAGS)
318 cc_setup() {
319 # Even though it belongs into cc_flags we will try to compile and link
320 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
321 # EXTRA_CFLAGS/EXTRA_LDFLAGS
322 if feat_no AUTOCC; then
323 _cc_default
324 # Ensure those don't do any harm
325 EXTRA_CFLAGS= EXTRA_LDFLAGS=
326 export EXTRA_CFLAGS EXTRA_LDFLAGS
327 return
328 else
329 CFLAGS= LDFLAGS=
330 export CFLAGS LDFLAGS
333 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
335 msg_nonl 'Searching for a usable C compiler .. $CC='
336 if { i="`command -v clang`"; }; then
337 CC=${i}
338 elif { i="`command -v gcc`"; }; then
339 CC=${i}
340 elif { i="`command -v c99`"; }; then
341 CC=${i}
342 elif { i="`command -v tcc`"; }; then
343 CC=${i}
344 elif { i="`command -v pcc`"; }; then
345 CC=${i}
346 else
347 if [ "${CC}" = cc ]; then
349 elif { i="`command -v c89`"; }; then
350 CC=${i}
351 else
352 msg 'boing booom tschak'
353 msg 'ERROR: I cannot find a compiler!'
354 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
355 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
356 config_exit 1
359 msg '%s' "${CC}"
360 export CC
363 _cc_default() {
364 if [ -z "${CC}" ]; then
365 msg 'To go on like you have chosen, please set $CC, rerun.'
366 config_exit 1
369 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
371 else
372 msg 'Using C compiler ${CC}=%s' "${CC}"
376 cc_flags() {
377 if feat_yes AUTOCC; then
378 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
379 cc_check_silent=1
380 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
381 "${CC}"
382 else
383 cc_check_silent=
384 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
387 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
388 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
389 msg ' . have special tcc(1) environmental rules ...'
390 _cc_flags_tcc
391 else
392 # As of pcc CVS 2016-04-02, stack protection support is announced but
393 # will break if used on Linux
394 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
395 force_no_stackprot=1
397 _cc_flags_generic
400 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
401 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
402 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
403 else
404 if feat_no DEBUG; then
405 CFLAGS="-DNDEBUG ${CFLAGS}"
408 msg ''
409 export CFLAGS LDFLAGS
412 _cc_flags_tcc() {
413 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
414 _CFLAGS= _LDFLAGS=
416 cc_check -Wall
417 cc_check -Wextra
418 cc_check -pedantic
420 if feat_yes DEBUG; then
421 # May have problems to find libtcc cc_check -b
422 cc_check -g
425 if ld_check -Wl,-rpath =./ no; then
426 need_R_ldflags=-Wl,-rpath=
427 ld_check -Wl,--enable-new-dtags
428 ld_runtime_flags # update!
431 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
432 unset __cflags __ldflags
435 _cc_flags_generic() {
436 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
437 _CFLAGS= _LDFLAGS=
438 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
440 # Check -g first since some others may rely upon -g / optim. level
441 if feat_yes DEBUG; then
442 cc_check -O
443 cc_check -g
444 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
446 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
448 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
450 else
451 cc_check -O
454 if feat_yes AMALGAMATION; then
455 cc_check -pipe
458 #if feat_yes DEVEL && cc_check -Weverything; then
460 #else
461 cc_check -Wall
462 cc_check -Wextra
463 cc_check -Wbad-function-cast
464 cc_check -Wcast-align
465 cc_check -Wcast-qual
466 cc_check -Winit-self
467 cc_check -Wmissing-prototypes
468 cc_check -Wshadow
469 cc_check -Wunused
470 cc_check -Wwrite-strings
471 cc_check -Wno-long-long
473 cc_check -pedantic
475 if feat_yes AMALGAMATION && feat_no DEVEL; then
476 cc_check -Wno-unused-function
478 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
480 cc_check -fno-unwind-tables
481 cc_check -fno-asynchronous-unwind-tables
482 cc_check -fstrict-aliasing
483 if cc_check -fstrict-overflow && feat_yes DEVEL; then
484 cc_check -Wstrict-overflow=5
487 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
488 if [ -z "${force_no_stackprot}" ]; then
489 if cc_check -fstack-protector-strong ||
490 cc_check -fstack-protector-all; then
491 cc_check -D_FORTIFY_SOURCE=2
493 else
494 msg 'Not checking for -fstack-protector compiler option,'
495 msg 'since that caused errors in a "similar" configuration.'
496 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
500 # LD (+ dependend CC)
502 if feat_yes ASAN_ADDRESS; then
503 _ccfg=${_CFLAGS}
504 if cc_check -fsanitize=address &&
505 ld_check -fsanitize=address; then
507 else
508 feat_bail_required ASAN_ADDRESS
509 _CFLAGS=${_ccfg}
513 if feat_yes ASAN_MEMORY; then
514 _ccfg=${_CFLAGS}
515 if cc_check -fsanitize=memory &&
516 ld_check -fsanitize=memory &&
517 cc_check -fsanitize-memory-track-origins=2 &&
518 ld_check -fsanitize-memory-track-origins=2; then
520 else
521 feat_bail_required ASAN_MEMORY
522 _CFLAGS=${_ccfg}
526 ld_check -Wl,-z,relro
527 ld_check -Wl,-z,now
528 ld_check -Wl,-z,noexecstack
529 if ld_check -Wl,-rpath =./ no; then
530 need_R_ldflags=-Wl,-rpath=
531 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
532 ld_check -Wl,--enable-new-dtags
533 ld_runtime_flags # update!
534 elif ld_check -Wl,-R ./ no; then
535 need_R_ldflags=-Wl,-R
536 ld_check -Wl,--enable-new-dtags
537 ld_runtime_flags # update!
540 # Address randomization
541 _ccfg=${_CFLAGS}
542 if cc_check -fPIE || cc_check -fpie; then
543 ld_check -pie || _CFLAGS=${_ccfg}
545 unset _ccfg
547 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
548 unset __cflags __ldflags
551 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
553 ## Notes:
554 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
555 ## redirection, so use "printf '' >" instead
557 ## Very first: we undergo several states regarding I/O redirection etc.,
558 ## but need to deal with option updates from within all. Since all the
559 ## option stuff should be above the scissor line, define utility functions
560 ## and redefine them as necessary.
561 ## And, since we have those functions, simply use them for whatever
563 config_exit() {
564 exit ${1}
567 msg() {
568 fmt=${1}
569 shift
570 printf >&2 -- "${fmt}\\n" "${@}"
573 msg_nonl() {
574 fmt=${1}
575 shift
576 printf >&2 -- "${fmt}" "${@}"
579 t1=ten10one1ten10one1
580 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
581 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
582 ) > /dev/null 2>&1; then
583 good_shell=1
584 else
585 unset good_shell
587 unset t1
589 # We need some standard utilities
590 unset -f command
591 check_tool() {
592 n=${1} i=${2} opt=${3:-0}
593 # Evaluate, just in case user comes in with shell snippets (..well..)
594 eval i="${i}"
595 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
596 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
597 eval ${n}=${i}
598 return 0
600 if [ ${opt} -eq 0 ]; then
601 msg 'ERROR: no trace of utility %s' "${n}"
602 config_exit 1
604 return 1
607 # Our feature check environment
608 feat_val_no() {
609 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
610 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
613 feat_val_yes() {
614 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
615 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
616 [ "x${1}" = xrequire ]
619 feat_val_require() {
620 [ "x${1}" = xrequire ]
623 _feat_check() {
624 eval i=\$OPT_${1}
625 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
626 if feat_val_no "${i}"; then
627 return 1
628 elif feat_val_yes "${i}"; then
629 return 0
630 else
631 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
632 "${1}" "${i}"
633 config_exit 11
637 feat_yes() {
638 _feat_check ${1}
641 feat_no() {
642 _feat_check ${1} && return 1
643 return 0
646 feat_require() {
647 eval i=\$OPT_${1}
648 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
649 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
652 feat_bail_required() {
653 if feat_require ${1}; then
654 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
655 config_exit 13
657 eval OPT_${1}=0
658 option_update # XXX this is rather useless here (dependency chain..)
661 option_parse() {
662 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
663 # options, without documentation, to $1
664 j=\'
665 i="`${awk} -v input=\"${2}\" '
666 BEGIN{
667 for(i = 0;;){
668 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
669 if(voff == 0)
670 break
671 v = substr(input, voff, RLENGTH)
672 input = substr(input, voff + RLENGTH)
673 doff = index(v, "=")
674 if(doff > 0){
675 d = substr(v, doff + 2, length(v) - doff - 1)
676 v = substr(v, 1, doff - 1)
678 print v
682 eval ${1}=\"${i}\"
685 option_doc_of() {
686 # Return the "documentation string" for option $1, itself if none such
687 j=\'
688 ${awk} -v want="${1}" \
689 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
690 BEGIN{
691 for(;;){
692 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
693 if(voff == 0)
694 break
695 v = substr(input, voff, RLENGTH)
696 input = substr(input, voff + RLENGTH)
697 doff = index(v, "=")
698 if(doff > 0){
699 d = substr(v, doff + 2, length(v) - doff - 1)
700 v = substr(v, 1, doff - 1)
701 }else
702 d = v
703 if(v == want){
704 if(d != "-")
705 print d
706 exit
713 option_join_rc() {
714 # Join the values from make.rc into what currently is defined, not
715 # overwriting yet existing settings
716 ${rm} -f ${tmp}
717 # We want read(1) to perform reverse solidus escaping in order to be able to
718 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
719 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
720 < ${rc} ${awk} 'BEGIN{line = ""}{
721 gsub(/^[[:space:]]+/, "", $0)
722 gsub(/[[:space:]]+$/, "", $0)
723 if(gsub(/\\$/, "", $0)){
724 line = line $0
725 next
726 }else
727 line = line $0
728 if(index(line, "#") == 1){
729 line = ""
730 }else if(length(line)){
731 print line
732 line = ""
734 }' |
735 while read line; do
736 if [ -n "${good_shell}" ]; then
737 i=${line%%=*}
738 else
739 i=`${awk} -v LINE="${line}" 'BEGIN{
740 gsub(/=.*$/, "", LINE)
741 print LINE
744 if [ "${i}" = "${line}" ]; then
745 msg 'ERROR: invalid syntax in: %s' "${line}"
746 continue
749 eval j="\$${i}" jx="\${${i}+x}"
750 if [ -n "${j}" ] || [ "${jx}" = x ]; then
751 : # Yet present
752 else
753 j=`${awk} -v LINE="${line}" 'BEGIN{
754 gsub(/^[^=]*=/, "", LINE)
755 gsub(/^\"*/, "", LINE)
756 gsub(/\"*$/, "", LINE)
757 print LINE
760 [ "${i}" = "DESTDIR" ] && continue
761 echo "${i}=\"${j}\""
762 done > ${tmp}
763 # Reread the mixed version right now
764 . ./${tmp}
767 option_evaluate() {
768 # Expand the option values, which may contain shell snippets
769 ${rm} -f ${newlst} ${newmk} ${newh}
770 exec 5<&0 6>&1 <${tmp} >${newlst}
771 while read line; do
773 if [ -n "${good_shell}" ]; then
774 i=${line%%=*}
775 [ "${i}" != "${i#OPT_}" ] && z=1
776 else
777 i=`${awk} -v LINE="${line}" 'BEGIN{
778 gsub(/=.*$/, "", LINE);\
779 print LINE
781 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
786 eval j=\$${i}
787 if [ -n "${z}" ]; then
788 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
789 if [ -z "${j}" ] || feat_val_no "${j}"; then
791 printf " /* #undef ${i} */\n" >> ${newh}
792 elif feat_val_yes "${j}"; then
793 if feat_val_require "${j}"; then
794 j=require
795 else
798 printf " /* #define ${i} */\n" >> ${newh}
799 else
800 msg 'ERROR: cannot parse <%s>' "${line}"
801 config_exit 1
803 else
804 printf "#define ${i} \"${j}\"\n" >> ${newh}
806 printf "${i} = ${j}\n" >> ${newmk}
807 printf "${i}=${j}\n"
808 eval "${i}=\"${j}\""
809 done
810 exec 0<&5 1>&6 5<&- 6<&-
813 path_check() {
814 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
815 varname=${1} addflag=${2} flagvarname=${3}
816 j=${IFS}
817 IFS=:
818 eval "set -- \$${1}"
819 IFS=${j}
820 j= k= y= z=
821 for i
823 [ -z "${i}" ] && continue
824 [ -d "${i}" ] || continue
825 # Skip any fakeroot packager environment
826 case "${i}" in *fakeroot*) continue;; esac
827 if [ -n "${j}" ]; then
828 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
830 else
831 y="${y} :${i}:"
832 j="${j}:${i}"
833 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
835 else
836 y=" :${i}:"
837 j="${i}"
838 [ -n "${addflag}" ] && k="${addflag}${i}"
840 done
841 eval "${varname}=\"${j}\""
842 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
843 unset varname
846 ld_runtime_flags() {
847 if [ -n "${need_R_ldflags}" ]; then
848 i=${IFS}
849 IFS=:
850 set -- ${LD_LIBRARY_PATH}
851 IFS=${i}
852 for i
854 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
855 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
856 done
857 export LDFLAGS
859 # Disable it for a possible second run.
860 need_R_ldflags=
863 cc_check() {
864 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
865 if "${CC}" ${INCS} \
866 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
867 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
868 _CFLAGS="${_CFLAGS} ${1}"
869 [ -n "${cc_check_silent}" ] || msg 'yes'
870 return 0
872 [ -n "${cc_check_silent}" ] || msg 'no'
873 return 1
876 ld_check() {
877 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
878 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
879 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
880 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
881 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
882 [ -n "${cc_check_silent}" ] || msg 'yes'
883 return 0
885 [ -n "${cc_check_silent}" ] || msg 'no'
886 return 1
889 _check_preface() {
890 variable=$1 topic=$2 define=$3
892 echo '**********'
893 msg_nonl ' . %s ... ' "${topic}"
894 echo "/* checked ${topic} */" >> ${h}
895 ${rm} -f ${tmp} ${tmp}.o
896 echo '*** test program is'
897 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
898 #echo '*** the preprocessor generates'
899 #${make} -f ${makefile} ${tmp}.x
900 #${cat} ${tmp}.x
901 echo '*** results are'
904 without_check() {
905 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
907 echo '**********'
908 msg_nonl ' . %s ... ' "${topic}"
910 echo '*** enforced unchecked results are'
911 if feat_val_yes ${yesno}; then
912 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
913 echo "*** adding INCS<${incs}> LIBS<${libs}>"
914 LIBS="${LIBS} ${libs}"
915 echo "${libs}" >> ${lib}
916 INCS="${INCS} ${incs}"
917 echo "${incs}" >> ${inc}
919 msg 'yes (deduced)'
920 echo "${define}" >> ${h}
921 eval have_${variable}=yes
922 return 0
923 else
924 echo "/* ${define} */" >> ${h}
925 msg 'no (deduced)'
926 eval unset have_${variable}
927 return 1
931 compile_check() {
932 variable=$1 topic=$2 define=$3
934 _check_preface "${variable}" "${topic}" "${define}"
936 if ${make} -f ${makefile} XINCS="${INCS}" \
937 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
938 ./${tmp}.o &&
939 [ -f ./${tmp}.o ]; then
940 msg 'yes'
941 echo "${define}" >> ${h}
942 eval have_${variable}=yes
943 return 0
944 else
945 echo "/* ${define} */" >> ${h}
946 msg 'no'
947 eval unset have_${variable}
948 return 1
952 _link_mayrun() {
953 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
955 _check_preface "${variable}" "${topic}" "${define}"
957 if feat_yes CROSS_BUILD; then
958 if [ ${run} = 1 ]; then
959 run=0
963 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
964 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
965 XLIBS="${LIBS} ${libs}" \
966 ./${tmp} &&
967 [ -f ./${tmp} ] &&
968 { [ ${run} -eq 0 ] || ./${tmp}; }; then
969 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
970 msg 'yes'
971 echo "${define}" >> ${h}
972 LIBS="${LIBS} ${libs}"
973 echo "${libs}" >> ${lib}
974 INCS="${INCS} ${incs}"
975 echo "${incs}" >> ${inc}
976 eval have_${variable}=yes
977 return 0
978 else
979 msg 'no'
980 echo "/* ${define} */" >> ${h}
981 eval unset have_${variable}
982 return 1
986 link_check() {
987 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
990 run_check() {
991 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
994 xrun_check() {
995 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
998 feat_def() {
999 if feat_yes ${1}; then
1000 echo '#define HAVE_'${1}'' >> ${h}
1001 return 0
1002 else
1003 echo '/* OPT_'${1}'=0 */' >> ${h}
1004 return 1
1008 squeeze_em() {
1009 < "${1}" > "${2}" ${awk} \
1010 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1013 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1015 # First of all, create new configuration and check whether it changed
1017 # Very easy checks for the operating system in order to be able to adjust paths
1018 # or similar very basic things which we need to be able to go at all
1019 os_early_setup
1021 # Check those tools right now that we need before including $rc
1022 msg 'Checking for basic utility set'
1023 check_tool awk "${awk:-`command -v awk`}"
1024 check_tool rm "${rm:-`command -v rm`}"
1025 check_tool tr "${tr:-`command -v tr`}"
1027 # Initialize the option set
1028 msg_nonl 'Setting up configuration options ... '
1029 option_setup
1030 msg 'done'
1032 # Include $rc, but only take from it what wasn't overwritten by the user from
1033 # within the command line or from a chosen fixed CONFIG=
1034 # Note we leave alone the values
1035 trap "exit 1" HUP INT TERM
1036 trap "${rm} -f ${tmp}" EXIT
1038 msg_nonl 'Joining in %s ... ' ${rc}
1039 option_join_rc
1040 msg 'done'
1042 # We need to know about that now, in order to provide utility overwrites etc.
1043 os_setup
1045 msg 'Checking for remaining set of utilities'
1046 check_tool grep "${grep:-`command -v grep`}"
1048 # Before we step ahead with the other utilities perform a path cleanup first.
1049 path_check PATH
1051 # awk(1) above
1052 check_tool cat "${cat:-`command -v cat`}"
1053 check_tool chmod "${chmod:-`command -v chmod`}"
1054 check_tool cp "${cp:-`command -v cp`}"
1055 check_tool cmp "${cmp:-`command -v cmp`}"
1056 # grep(1) above
1057 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1058 check_tool mv "${mv:-`command -v mv`}"
1059 # rm(1) above
1060 check_tool sed "${sed:-`command -v sed`}"
1061 check_tool sort "${sort:-`command -v sort`}"
1062 check_tool tee "${tee:-`command -v tee`}"
1064 check_tool chown "${chown:-`command -v chown`}" 1 ||
1065 check_tool chown "/sbin/chown" 1 ||
1066 check_tool chown "/usr/sbin/chown"
1068 check_tool make "${MAKE:-`command -v make`}"
1069 MAKE=${make}
1070 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1071 HAVE_STRIP=1 || HAVE_STRIP=0
1073 # For ./cc-test.sh only
1074 check_tool cksum "${cksum:-`command -v cksum`}"
1076 # Update OPT_ options now, in order to get possible inter-dependencies right
1077 option_update
1079 # (No functions since some shells loose non-exported variables in traps)
1080 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1081 trap "trap \"\" HUP INT TERM EXIT;\
1082 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1084 # Our configuration options may at this point still contain shell snippets,
1085 # we need to evaluate them in order to get them expanded, and we need those
1086 # evaluated values not only in our new configuration file, but also at hand..
1087 msg_nonl 'Evaluating all configuration items ... '
1088 option_evaluate
1089 msg 'done'
1091 # Add the known utility and some other variables
1092 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1093 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1095 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1096 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1097 if feat_yes DOTLOCK; then
1098 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1099 else
1100 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1103 for i in \
1104 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1105 MAKE MAKEFLAGS make SHELL strip \
1106 cksum; do
1107 eval j=\$${i}
1108 printf "${i} = ${j}\n" >> ${newmk}
1109 printf "${i}=${j}\n" >> ${newlst}
1110 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1111 done
1112 printf "\n" >> ${newev}
1114 # Build a basic set of INCS and LIBS according to user environment.
1115 path_check C_INCLUDE_PATH -I _INCS
1116 INCS="${INCS} ${_INCS}"
1117 path_check LD_LIBRARY_PATH -L _LIBS
1118 LIBS="${LIBS} ${_LIBS}"
1119 unset _INCS _LIBS
1120 export C_INCLUDE_PATH LD_LIBRARY_PATH
1122 # Some environments need runtime path flags to be able to go at all
1123 ld_runtime_flags
1125 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1127 cc_setup
1129 ${cat} > ${tmp}.c << \!
1130 #include <stdio.h>
1131 #include <string.h>
1132 static void doit(char const *s);
1134 main(int argc, char **argv){
1135 (void)argc;
1136 (void)argv;
1137 doit("Hello world");
1138 return 0;
1140 static void
1141 doit(char const *s){
1142 char buf[12];
1143 memcpy(buf, s, strlen(s) +1);
1144 puts(s);
1148 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1149 -o ${tmp2} ${tmp}.c ${LIBS}; then
1151 else
1152 msg 'ERROR: i cannot compile a "Hello world" via'
1153 msg ' %s' \
1154 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1155 msg 'ERROR: Please read INSTALL, rerun'
1156 config_exit 1
1159 # This may also update ld_runtime_flags() (again)
1160 cc_flags
1162 for i in \
1163 INCS LIBS \
1164 ; do
1165 eval j=\$${i}
1166 printf -- "${i}=${j}\n" >> ${newlst}
1167 done
1168 for i in \
1169 CC \
1170 CFLAGS \
1171 LDFLAGS \
1172 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1173 OSFULLSPEC \
1174 ; do
1175 eval j=\$${i}
1176 printf -- "${i} = ${j}\n" >> ${newmk}
1177 printf -- "${i}=${j}\n" >> ${newlst}
1178 done
1180 # Now finally check whether we already have a configuration and if so, whether
1181 # all those parameters are still the same.. or something has actually changed
1182 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1183 echo 'Configuration is up-to-date'
1184 exit 0
1185 elif [ -f ${lst} ]; then
1186 echo 'Configuration has been updated..'
1187 ( eval "${MAKE} -f ./mk-config.mk clean" )
1188 echo
1189 else
1190 echo 'Shiny configuration..'
1193 # Time to redefine helper 1
1194 config_exit() {
1195 ${rm} -f ${lst} ${h} ${mk}
1196 exit ${1}
1199 ${mv} -f ${newlst} ${lst}
1200 ${mv} -f ${newev} ${ev}
1201 ${mv} -f ${newh} ${h}
1202 ${mv} -f ${newmk} ${mk}
1204 if [ -z "${VERBOSE}" ]; then
1205 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1206 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1207 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1208 printf -- "ECHO_TEST = @\n" >> ${mk}
1209 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1210 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1211 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1214 ## Compile and link checking
1216 tmp3=./${tmp0}3$$
1217 log=./mk-config.log
1218 lib=./mk-config.lib
1219 inc=./mk-config.inc
1220 makefile=./${tmp0}.mk
1222 # (No function since some shells loose non-exported variables in traps)
1223 trap "trap \"\" HUP INT TERM;\
1224 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1225 trap "trap \"\" HUP INT TERM EXIT;\
1226 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1228 # Time to redefine helper 2
1229 msg() {
1230 fmt=${1}
1231 shift
1232 printf "*** ${fmt}\\n" "${@}"
1233 printf -- "${fmt}\\n" "${@}" >&5
1235 msg_nonl() {
1236 fmt=${1}
1237 shift
1238 printf "*** ${fmt}\\n" "${@}"
1239 printf -- "${fmt}" "${@}" >&5
1242 # !!
1243 exec 5>&2 > ${log} 2>&1
1245 echo "${LIBS}" > ${lib}
1246 echo "${INCS}" > ${inc}
1247 ${cat} > ${makefile} << \!
1248 .SUFFIXES: .o .c .x .y
1249 .c.o:
1250 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1251 .c.x:
1252 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1254 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1257 ## Generics
1259 # May be multiline..
1260 echo >> ${h}
1261 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1262 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1263 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1265 # Generate n_err_number OS mappings
1267 feat_yes DEVEL && NV= || NV=noverbose
1268 TARGET="${h}" awk="${awk}" ./make-errors.sh ${NV} config
1270 xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1272 feat_def ALWAYS_UNICODE_LOCALE
1273 feat_def AMALGAMATION
1274 feat_def CROSS_BUILD
1275 feat_def DOCSTRINGS
1276 feat_def ERRORS
1278 feat_def ASAN_ADDRESS
1279 feat_def ASAN_MEMORY
1280 feat_def DEBUG
1281 feat_def DEVEL
1282 feat_def NYD2
1283 feat_def NOMEMDBG
1285 if xrun_check inline 'inline functions' \
1286 '#define HAVE_INLINE
1287 #define n_INLINE static inline' << \!
1288 static inline int ilf(int i){return ++i;}
1289 int main(void){return ilf(-1);}
1291 then
1293 elif xrun_check inline 'inline functions (via __inline)' \
1294 '#define HAVE_INLINE
1295 #define n_INLINE static __inline' << \!
1296 static __inline int ilf(int i){return ++i;}
1297 int main(void){return ilf(-1);}
1299 then
1303 ## Test for "basic" system-calls / functionality that is used by all parts
1304 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1305 ## macros to be used by only the subprograms (potentially).
1307 if run_check clock_gettime 'clock_gettime(2)' \
1308 '#define HAVE_CLOCK_GETTIME' << \!
1309 #include <time.h>
1310 # include <errno.h>
1311 int main(void){
1312 struct timespec ts;
1314 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1315 return 0;
1316 return 1;
1319 then
1321 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1322 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
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 gettimeofday 'gettimeofday(2)' \
1336 '#define HAVE_GETTIMEOFDAY' << \!
1337 #include <stdio.h> /* For C89 NULL */
1338 #include <sys/time.h>
1339 # include <errno.h>
1340 int main(void){
1341 struct timeval tv;
1343 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1344 return 0;
1345 return 1;
1348 then
1350 else
1351 have_no_subsecond_time=1
1354 if run_check nanosleep 'nanosleep(2)' \
1355 '#define HAVE_NANOSLEEP' << \!
1356 #include <time.h>
1357 # include <errno.h>
1358 int main(void){
1359 struct timespec ts;
1361 ts.tv_sec = 1;
1362 ts.tv_nsec = 100000;
1363 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1364 return 0;
1365 return 1;
1368 then
1370 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1371 '#define HAVE_NANOSLEEP' '-lrt' << \!
1372 #include <time.h>
1373 # include <errno.h>
1374 int main(void){
1375 struct timespec ts;
1377 ts.tv_sec = 1;
1378 ts.tv_nsec = 100000;
1379 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1380 return 0;
1381 return 1;
1384 then
1386 # link_check is enough for this, that function is so old, trust the proto
1387 elif link_check sleep 'sleep(3)' \
1388 '#define HAVE_SLEEP' << \!
1389 #include <unistd.h>
1390 # include <errno.h>
1391 int main(void){
1392 if(!sleep(1) || errno != ENOSYS)
1393 return 0;
1394 return 1;
1397 then
1399 else
1400 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1401 config_exit 1
1404 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1405 #include <pwd.h>
1406 #include <unistd.h>
1407 # include <errno.h>
1408 int main(void){
1409 struct passwd *pw;
1410 gid_t gid;
1411 uid_t uid;
1413 if((gid = getgid()) != 0)
1414 gid = getegid();
1415 if((uid = getuid()) != 0)
1416 uid = geteuid();
1417 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1418 return 1;
1419 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1420 return 1;
1421 return 0;
1424 then
1426 else
1427 msg 'ERROR: we require user and group info / database searches.'
1428 msg 'That much Unix we indulge ourselfs.'
1429 config_exit 1
1432 if link_check ftruncate 'ftruncate(2)' \
1433 '#define HAVE_FTRUNCATE' << \!
1434 #include <unistd.h>
1435 #include <sys/types.h>
1436 int main(void){
1437 return (ftruncate(0, 0) != 0);
1440 then
1442 else
1443 msg 'ERROR: we require the ftruncate(2) system call.'
1444 config_exit 1
1447 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1448 #include <signal.h>
1449 # include <errno.h>
1450 int main(void){
1451 struct sigaction nact, oact;
1453 nact.sa_handler = SIG_DFL;
1454 sigemptyset(&nact.sa_mask);
1455 nact.sa_flags = SA_RESTART;
1456 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1459 then
1461 else
1462 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1463 config_exit 1
1466 if link_check snprintf 'snprintf(3)' << \!
1467 #include <stdio.h>
1468 int main(void){
1469 char b[20];
1471 snprintf(b, sizeof b, "%s", "string");
1472 return 0;
1475 then
1477 else
1478 msg 'ERROR: we require the snprintf(3) function.'
1479 config_exit 1
1482 if link_check environ 'environ(3)' << \!
1483 #include <stdio.h> /* For C89 NULL */
1484 int main(void){
1485 extern char **environ;
1487 return environ[0] == NULL;
1490 then
1492 else
1493 msg 'ERROR: we require the environ(3) array for subprocess control.'
1494 config_exit 1
1497 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1498 #include <stdlib.h>
1499 int main(void){
1500 setenv("s-mailx", "i want to see it cute!", 1);
1501 unsetenv("s-mailx");
1502 return 0;
1505 then
1507 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1508 #include <stdlib.h>
1509 int main(void){
1510 putenv("s-mailx=i want to see it cute!");
1511 return 0;
1514 then
1516 else
1517 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1518 config_exit 1
1521 if link_check termios 'termios.h and tc*(3) family' << \!
1522 #include <termios.h>
1523 int main(void){
1524 struct termios tios;
1526 tcgetattr(0, &tios);
1527 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1528 return 0;
1531 then
1533 else
1534 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1535 msg 'That much Unix we indulge ourselfs.'
1536 config_exit 1
1539 ## optional stuff
1541 if link_check vsnprintf 'vsnprintf(3)' << \!
1542 #include <stdarg.h>
1543 #include <stdio.h>
1544 static void dome(char *buf, size_t blen, ...){
1545 va_list ap;
1547 va_start(ap, blen);
1548 vsnprintf(buf, blen, "%s", ap);
1549 va_end(ap);
1551 int main(void){
1552 char b[20];
1554 dome(b, sizeof b, "string");
1555 return 0;
1558 then
1560 else
1561 feat_bail_required ERRORS
1564 if [ "${have_vsnprintf}" = yes ]; then
1565 __va_copy() {
1566 link_check va_copy "va_copy(3) (as ${2})" \
1567 "#define HAVE_N_VA_COPY
1568 #define n_va_copy ${2}" <<_EOT
1569 #include <stdarg.h>
1570 #include <stdio.h>
1571 #if ${1}
1572 # if defined __va_copy && !defined va_copy
1573 # define va_copy __va_copy
1574 # endif
1575 #endif
1576 static void dome2(char *buf, size_t blen, va_list src){
1577 va_list ap;
1579 va_copy(ap, src);
1580 vsnprintf(buf, blen, "%s", ap);
1581 va_end(ap);
1583 static void dome(char *buf, size_t blen, ...){
1584 va_list ap;
1586 va_start(ap, blen);
1587 dome2(buf, blen, ap);
1588 va_end(ap);
1590 int main(void){
1591 char b[20];
1593 dome(b, sizeof b, "string");
1594 return 0;
1596 _EOT
1598 __va_copy 0 va_copy || __va_copy 1 __va_copy
1601 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1602 #include <unistd.h>
1603 #include <errno.h>
1604 int main(void){
1605 int rv = 0;
1607 errno = 0;
1608 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1609 errno = 0;
1610 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1612 /* Only link check */
1613 fpathconf(0, _PC_NAME_MAX);
1615 return rv;
1619 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1620 #include <fcntl.h>
1621 #include <unistd.h>
1622 # include <errno.h>
1623 int main(void){
1624 int fds[2];
1626 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1627 return 0;
1628 return 1;
1632 # We use this only then for now (need NOW+1)
1633 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1634 #include <fcntl.h> /* For AT_* */
1635 #include <sys/stat.h>
1636 # include <errno.h>
1637 int main(void){
1638 struct timespec ts[2];
1640 ts[0].tv_nsec = UTIME_NOW;
1641 ts[1].tv_nsec = UTIME_OMIT;
1642 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1643 return 0;
1644 return 1;
1650 # XXX Add POSIX check once standardized
1651 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1652 #include <stdlib.h>
1653 int main(void){
1654 arc4random();
1655 return 0;
1658 then
1660 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1661 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1662 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1663 #include <sys/random.h>
1664 int main(void){
1665 char buf[256];
1666 getrandom(buf, sizeof buf, 0);
1667 return 0;
1670 then
1672 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1673 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1674 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1675 #include <sys/syscall.h>
1676 int main(void){
1677 char buf[256];
1678 syscall(SYS_getrandom, buf, sizeof buf, 0);
1679 return 0;
1682 then
1684 elif [ -n "${have_no_subsecond_time}" ]; then
1685 msg 'ERROR: %s %s' 'without a native random' \
1686 'one of clock_gettime(2) and gettimeofday(2) is required.'
1687 config_exit 1
1691 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1692 #include <stdio.h>
1693 int main(void){
1694 putc_unlocked('@', stdout);
1695 return 0;
1699 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1700 #include <unistd.h>
1701 int main(void){
1702 fchdir(0);
1703 return 0;
1707 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1708 #include <stdlib.h>
1709 int main(void){
1710 char x_buf[4096], *x = realpath(".", x_buf);
1712 return (x != NULL) ? 0 : 1;
1715 then
1716 if run_check realpath_malloc 'realpath(3) takes NULL' \
1717 '#define HAVE_REALPATH_NULL' << \!
1718 #include <stdlib.h>
1719 int main(void){
1720 char *x = realpath(".", NULL);
1722 if(x != NULL)
1723 free(x);
1724 return (x != NULL) ? 0 : 1;
1727 then
1732 ## optional and selectable
1734 if feat_yes DOTLOCK; then
1735 if run_check readlink 'readlink(2)' << \!
1736 #include <unistd.h>
1737 # include <errno.h>
1738 int main(void){
1739 char buf[128];
1741 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1742 return 0;
1743 return 1;
1746 then
1748 else
1749 feat_bail_required DOTLOCK
1753 if feat_yes DOTLOCK; then
1754 if run_check fchown 'fchown(2)' << \!
1755 #include <unistd.h>
1756 # include <errno.h>
1757 int main(void){
1758 if(!fchown(0, 0, 0) || errno != ENOSYS)
1759 return 0;
1760 return 1;
1763 then
1765 else
1766 feat_bail_required DOTLOCK
1770 ## Now it is the time to fork away the BASE_ series
1772 ${rm} -f ${tmp}
1773 squeeze_em ${inc} ${tmp}
1774 ${mv} ${tmp} ${inc}
1775 squeeze_em ${lib} ${tmp}
1776 ${mv} ${tmp} ${lib}
1778 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1779 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1781 ## The remains are expected to be used only by the main MUA binary!
1783 OPT_LOCALES=0
1784 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1785 #include <locale.h>
1786 int main(void){
1787 setlocale(LC_ALL, "");
1788 return 0;
1791 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1793 OPT_MULTIBYTE_CHARSETS=0
1794 OPT_WIDE_GLYPHS=0
1795 OPT_TERMINAL_CHARSET=0
1796 if [ -n "${have_setlocale}" ]; then
1797 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1798 '#define HAVE_C90AMEND1' << \!
1799 #include <limits.h>
1800 #include <stdlib.h>
1801 #include <wchar.h>
1802 #include <wctype.h>
1803 int main(void){
1804 char mbb[MB_LEN_MAX + 1];
1805 wchar_t wc;
1807 iswprint(L'c');
1808 towupper(L'c');
1809 mbtowc(&wc, "x", 1);
1810 mbrtowc(&wc, "x", 1, NULL);
1811 wctomb(mbb, wc);
1812 return (mblen("\0", 1) == 0);
1815 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1817 if [ -n "${have_c90amend1}" ]; then
1818 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1819 #include <wchar.h>
1820 int main(void){
1821 wcwidth(L'c');
1822 return 0;
1825 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1828 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1829 #include <langinfo.h>
1830 #include <stdlib.h>
1831 int main(void){
1832 nl_langinfo(DAY_1);
1833 return (nl_langinfo(CODESET) == NULL);
1836 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1837 fi # have_setlocale
1839 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1840 #include <fnmatch.h>
1841 int main(void){
1842 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1846 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1847 #include <dirent.h>
1848 int main(void){
1849 struct dirent de;
1850 return !(de.d_type == DT_UNKNOWN ||
1851 de.d_type == DT_DIR || de.d_type == DT_LNK);
1855 ## optional and selectable
1857 if feat_yes ICONV; then
1858 ${cat} > ${tmp2}.c << \!
1859 #include <stdio.h> /* For C89 NULL */
1860 #include <iconv.h>
1861 int main(void){
1862 iconv_t id;
1864 id = iconv_open("foo", "bar");
1865 iconv(id, NULL, NULL, NULL, NULL);
1866 iconv_close(id);
1867 return 0;
1870 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1871 '#define HAVE_ICONV' ||
1872 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1873 '#define HAVE_ICONV' '-liconv' ||
1874 feat_bail_required ICONV
1875 else
1876 echo '/* OPT_ICONV=0 */' >> ${h}
1877 fi # feat_yes ICONV
1879 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1880 ${cat} > ${tmp2}.c << \!
1881 #include <sys/types.h>
1882 #include <sys/socket.h>
1883 #include <sys/un.h>
1884 # include <errno.h>
1885 int main(void){
1886 struct sockaddr_un soun;
1888 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1889 return 1;
1890 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1891 return 1;
1892 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1893 return 1;
1894 return 0;
1898 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1899 '#define HAVE_UNIX_SOCKETS' ||
1900 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1901 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1902 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1903 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1906 if feat_yes SOCKETS; then
1907 ${cat} > ${tmp2}.c << \!
1908 #include <sys/types.h>
1909 #include <sys/socket.h>
1910 #include <netinet/in.h>
1911 # include <errno.h>
1912 int main(void){
1913 struct sockaddr s;
1915 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1916 return 1;
1917 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1918 return 1;
1919 return 0;
1923 < ${tmp2}.c run_check sockets 'sockets' \
1924 '#define HAVE_SOCKETS' ||
1925 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1926 '#define HAVE_SOCKETS' '-lnsl' ||
1927 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1928 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1929 feat_bail_required SOCKETS
1930 else
1931 echo '/* OPT_SOCKETS=0 */' >> ${h}
1932 fi # feat_yes SOCKETS
1934 if feat_yes SOCKETS; then
1935 link_check getaddrinfo 'getaddrinfo(3)' \
1936 '#define HAVE_GETADDRINFO' << \!
1937 #include <sys/types.h>
1938 #include <sys/socket.h>
1939 #include <stdio.h>
1940 #include <netdb.h>
1941 int main(void){
1942 struct addrinfo a, *ap;
1943 int lrv;
1945 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1946 case EAI_NONAME:
1947 case EAI_SERVICE:
1948 default:
1949 fprintf(stderr, "%s\n", gai_strerror(lrv));
1950 case 0:
1951 break;
1953 return 0;
1958 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1959 compile_check arpa_inet_h '<arpa/inet.h>' \
1960 '#define HAVE_ARPA_INET_H' << \!
1961 #include <sys/types.h>
1962 #include <sys/socket.h>
1963 #include <netdb.h>
1964 #include <netinet/in.h>
1965 #include <arpa/inet.h>
1968 ${cat} > ${tmp2}.c << \!
1969 #include <sys/types.h>
1970 #include <sys/socket.h>
1971 #include <stdio.h>
1972 #include <string.h>
1973 #include <netdb.h>
1974 #include <netinet/in.h>
1975 #ifdef HAVE_ARPA_INET_H
1976 #include <arpa/inet.h>
1977 #endif
1978 int main(void){
1979 struct sockaddr_in servaddr;
1980 unsigned short portno;
1981 struct servent *ep;
1982 struct hostent *hp;
1983 struct in_addr **pptr;
1985 portno = 0;
1986 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1987 portno = (unsigned short)ep->s_port;
1989 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1990 pptr = (struct in_addr**)hp->h_addr_list;
1991 if(hp->h_addrtype != AF_INET)
1992 fprintf(stderr, "au\n");
1993 }else{
1994 switch(h_errno){
1995 case HOST_NOT_FOUND:
1996 case TRY_AGAIN:
1997 case NO_RECOVERY:
1998 case NO_DATA:
1999 break;
2000 default:
2001 fprintf(stderr, "au\n");
2002 break;
2006 memset(&servaddr, 0, sizeof servaddr);
2007 servaddr.sin_family = AF_INET;
2008 servaddr.sin_port = htons(portno);
2009 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2010 fprintf(stderr, "Would connect to %s:%d ...\n",
2011 inet_ntoa(**pptr), (int)portno);
2012 return 0;
2016 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2017 < ${tmp2}.c link_check gethostbyname \
2018 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2019 < ${tmp2}.c link_check gethostbyname \
2020 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2021 '' '-lsocket -lnsl' ||
2022 feat_bail_required SOCKETS
2025 feat_yes SOCKETS &&
2026 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2027 #include <sys/socket.h>
2028 #include <stdlib.h>
2029 # include <errno.h>
2030 int main(void){
2031 int sockfd = 3;
2033 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2034 errno == ENOSYS)
2035 return 1;
2036 return 0;
2040 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2041 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2042 #include <sys/socket.h>
2043 #include <stdlib.h>
2044 int main(void){
2045 struct timeval tv;
2046 int sockfd = 3;
2048 tv.tv_sec = 42;
2049 tv.tv_usec = 21;
2050 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2051 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2052 return 0;
2056 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2057 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2058 #include <sys/socket.h>
2059 #include <stdlib.h>
2060 int main(void){
2061 struct linger li;
2062 int sockfd = 3;
2064 li.l_onoff = 1;
2065 li.l_linger = 42;
2066 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2067 return 0;
2071 if feat_yes SSL; then # {{{
2072 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2073 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2074 # time: we need to test it first in order to get things right
2075 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2076 '#define HAVE_SSL
2077 #define HAVE_XSSL
2078 #define HAVE_XSSL_RESSL
2079 #define HAVE_XSSL_OPENSSL 0' << \!
2080 #include <openssl/opensslv.h>
2081 #ifdef LIBRESSL_VERSION_NUMBER
2082 #else
2083 # error nope
2084 #endif
2086 then
2087 ossl_v1_1=
2088 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2089 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2090 '#define HAVE_SSL
2091 #define HAVE_XSSL
2092 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2093 #include <openssl/opensslv.h>
2094 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2095 #else
2096 # error nope
2097 #endif
2099 then
2100 ossl_v1_1=1
2101 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2102 '#define HAVE_SSL
2103 #define HAVE_XSSL
2104 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2105 #include <openssl/opensslv.h>
2106 #ifdef OPENSSL_VERSION_NUMBER
2107 #else
2108 # error nope
2109 #endif
2111 then
2112 ossl_v1_1=
2113 else
2114 feat_bail_required SSL
2115 fi # }}}
2117 if feat_yes SSL; then # {{{
2118 if [ -n "${ossl_v1_1}" ]; then
2119 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2120 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2121 '-lssl -lcrypto'
2122 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2123 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2124 '-lssl -lcrypto' << \!
2125 #include <openssl/ssl.h>
2126 #include <openssl/err.h>
2127 #include <openssl/x509v3.h>
2128 #include <openssl/x509.h>
2129 #include <openssl/rand.h>
2130 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2131 # error We need TLSv1.
2132 #endif
2133 int main(void){
2134 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2136 SSL_CTX_free(ctx);
2137 PEM_read_PrivateKey(0, 0, 0, 0);
2138 return 0;
2141 then
2143 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2144 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2145 '-lssl -lcrypto' << \!
2146 #include <openssl/ssl.h>
2147 #include <openssl/err.h>
2148 #include <openssl/x509v3.h>
2149 #include <openssl/x509.h>
2150 #include <openssl/rand.h>
2151 #if defined OPENSSL_NO_SSL3 &&\
2152 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2153 # error We need one of SSLv3 and TLSv1.
2154 #endif
2155 int main(void){
2156 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2158 SSL_CTX_free(ctx);
2159 PEM_read_PrivateKey(0, 0, 0, 0);
2160 return 0;
2163 then
2165 else
2166 feat_bail_required SSL
2168 fi # }}}
2170 if feat_yes SSL; then # {{{
2171 if [ -n "${ossl_v1_1}" ]; then
2172 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2173 '#define HAVE_XSSL_STACK_OF'
2174 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2175 '#define HAVE_XSSL_STACK_OF' << \!
2176 #include <stdio.h> /* For C89 NULL */
2177 #include <openssl/ssl.h>
2178 #include <openssl/err.h>
2179 #include <openssl/x509v3.h>
2180 #include <openssl/x509.h>
2181 #include <openssl/rand.h>
2182 int main(void){
2183 STACK_OF(GENERAL_NAME) *gens = NULL;
2185 printf("%p", gens); /* to use it */
2186 return 0;
2189 then
2193 if [ -n "${ossl_v1_1}" ]; then
2194 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2195 '#define HAVE_XSSL_CONFIG'
2196 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2197 '#define HAVE_XSSL_CONFIG' << \!
2198 #include <stdio.h> /* For C89 NULL */
2199 #include <openssl/conf.h>
2200 int main(void){
2201 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2202 CONF_modules_free();
2203 return 0;
2206 then
2210 if [ -n "${ossl_v1_1}" ]; then
2211 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2212 '#define HAVE_XSSL_CONF_CTX'
2213 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2214 '#define HAVE_XSSL_CONF_CTX' << \!
2215 #include <openssl/ssl.h>
2216 #include <openssl/err.h>
2217 int main(void){
2218 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2219 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2221 SSL_CONF_CTX_set_flags(cctx,
2222 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2223 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2224 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2225 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2226 SSL_CONF_CTX_finish(cctx);
2227 SSL_CONF_CTX_free(cctx);
2228 SSL_CTX_free(ctx);
2229 return 0;
2232 then
2236 if [ -n "${ossl_v1_1}" ]; then
2237 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2238 '#define HAVE_XSSL_RAND_EGD'
2239 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2240 '#define HAVE_XSSL_RAND_EGD' << \!
2241 #include <openssl/rand.h>
2242 int main(void){
2243 return RAND_egd("some.where") > 0;
2246 then
2250 if feat_yes SSL_ALL_ALGORITHMS; then
2251 if [ -n "${ossl_v1_1}" ]; then
2252 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2253 '#define HAVE_SSL_ALL_ALGORITHMS'
2254 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2255 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2256 #include <openssl/evp.h>
2257 int main(void){
2258 OpenSSL_add_all_algorithms();
2259 EVP_get_cipherbyname("two cents i never exist");
2260 EVP_cleanup();
2261 return 0;
2264 then
2266 else
2267 feat_bail_required SSL_ALL_ALGORITHMS
2270 fi # feat_yes SSL }}}
2272 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2273 run_check ssl_md5 'MD5 digest in the used crypto library' \
2274 '#define HAVE_XSSL_MD5' << \!
2275 #include <stdlib.h>
2276 #include <string.h>
2277 #include <openssl/md5.h>
2278 int main(void){
2279 char const dat[] = "abrakadabrafidibus";
2280 char dig[16], hex[16 * 2];
2281 MD5_CTX ctx;
2282 size_t i, j;
2284 memset(dig, 0, sizeof(dig));
2285 memset(hex, 0, sizeof(hex));
2286 MD5_Init(&ctx);
2287 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2288 MD5_Final(dig, &ctx);
2290 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2291 for(i = 0; i < sizeof(hex) / 2; i++){
2292 j = i << 1;
2293 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2294 hex[++j] = hexchar(dig[i] & 0x0f);
2296 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2299 fi # }}}
2300 else
2301 echo '/* OPT_SSL=0 */' >> ${h}
2302 fi # }}} feat_yes SSL
2304 if [ "${have_xssl}" = yes ]; then
2305 OPT_SMIME=1
2306 else
2307 OPT_SMIME=0
2309 feat_def SMIME
2311 feat_def SMTP
2312 feat_def POP3
2314 if feat_yes GSSAPI; then
2315 ${cat} > ${tmp2}.c << \!
2316 #include <gssapi/gssapi.h>
2317 int main(void){
2318 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2319 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2320 return 0;
2323 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2325 if command -v krb5-config >/dev/null 2>&1; then
2326 i=`command -v krb5-config`
2327 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2328 GSS_INCS="`CFLAGS= ${i} --cflags`"
2329 i='GSS-API via krb5-config(1)'
2330 else
2331 GSS_LIBS='-lgssapi'
2332 GSS_INCS=
2333 i='GSS-API in gssapi/gssapi.h, libgssapi'
2335 if < ${tmp2}.c link_check gss \
2336 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2337 < ${tmp3}.c link_check gss \
2338 'GSS-API in gssapi.h, libgssapi' \
2339 '#define HAVE_GSSAPI
2340 #define GSSAPI_REG_INCLUDE' \
2341 '-lgssapi' ||\
2342 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2343 '#define HAVE_GSSAPI' \
2344 '-lgssapi_krb5' ||\
2345 < ${tmp3}.c link_check gss \
2346 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2347 '#define HAVE_GSSAPI
2348 #define GSS_REG_INCLUDE' \
2349 '-lgssapi -lkrb5 -lcrypto' \
2350 '-I/usr/include/kerberosV' ||\
2351 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2352 '#define HAVE_GSSAPI' \
2353 '-lgss' ||\
2354 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2355 '#define HAVE_GSSAPI
2356 #define GSSAPI_OLD_STYLE' \
2357 '-lgssapi_krb5' << \!
2358 #include <gssapi/gssapi.h>
2359 #include <gssapi/gssapi_generic.h>
2360 int main(void){
2361 gss_import_name(0, 0, gss_nt_service_name, 0);
2362 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2363 return 0;
2366 then
2368 else
2369 feat_bail_required GSSAPI
2371 else
2372 echo '/* OPT_GSSAPI=0 */' >> ${h}
2373 fi # feat_yes GSSAPI
2375 feat_def NETRC
2376 feat_def AGENT
2378 if feat_yes IDNA; then
2379 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2380 '-lidn' << \!
2381 #include <idna.h>
2382 #include <idn-free.h>
2383 #include <stringprep.h>
2384 int main(void){
2385 char *utf8, *idna_ascii, *idna_utf8;
2387 utf8 = stringprep_locale_to_utf8("does.this.work");
2388 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2389 != IDNA_SUCCESS)
2390 return 1;
2391 idn_free(idna_ascii);
2392 /* (Rather link check only here) */
2393 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2394 return 0;
2397 then
2399 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2400 '-lidnkit' << \!
2401 #include <stdio.h>
2402 #include <idn/api.h>
2403 #include <idn/result.h>
2404 int main(void){
2405 idn_result_t r;
2406 char ace_name[256];
2407 char local_name[256];
2409 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2410 sizeof(ace_name));
2411 if (r != idn_success) {
2412 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2413 return 1;
2415 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2416 if (r != idn_success) {
2417 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2418 return 1;
2420 return 0;
2423 then
2425 else
2426 feat_bail_required IDNA
2429 if [ -n "${have_idna}" ]; then
2430 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2431 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2433 else
2434 echo '/* OPT_IDNA=0 */' >> ${h}
2437 feat_def IMAP_SEARCH
2439 if feat_yes REGEX; then
2440 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2441 #include <regex.h>
2442 #include <stdlib.h>
2443 int main(void){
2444 size_t xret;
2445 int status;
2446 regex_t re;
2448 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2449 xret = regerror(status, &re, NULL, 0);
2450 status = regexec(&re, "plan9", 0,NULL, 0);
2451 regfree(&re);
2452 return !(status == REG_NOMATCH);
2455 then
2457 else
2458 feat_bail_required REGEX
2460 else
2461 echo '/* OPT_REGEX=0 */' >> ${h}
2464 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2465 have_mle=1
2466 echo '#define HAVE_MLE' >> ${h}
2467 else
2468 feat_bail_required MLE
2469 echo '/* OPT_MLE=0 */' >> ${h}
2472 # Generic have-a-line-editor switch for those who need it below
2473 if [ -n "${have_mle}" ]; then
2474 have_cle=1
2477 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2478 echo '#define HAVE_HISTORY' >> ${h}
2479 else
2480 echo '/* OPT_HISTORY=0 */' >> ${h}
2483 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2484 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2485 else
2486 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2489 if feat_yes TERMCAP; then
2490 __termcaplib() {
2491 link_check termcap "termcap(5) (via ${4})" \
2492 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2493 #include <stdio.h>
2494 #include <stdlib.h>
2495 ${2}
2496 #include <term.h>
2497 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2498 static int my_putc(int c){return putchar(c);}
2499 int main(void){
2500 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2501 int r2 = OK, r3 = ERR;
2503 tgetent(buf, getenv("TERM"));
2504 cpb = cmdbuf;
2505 r1 = tgetstr(UNCONST("cm"), &cpb);
2506 tgoto(r1, 1, 1);
2507 r2 = tgetnum(UNCONST("Co"));
2508 r3 = tgetflag(UNCONST("ut"));
2509 tputs("cr", 1, &my_putc);
2510 return (r1 == NULL || r2 == -1 || r3 == 0);
2512 _EOT
2515 __terminfolib() {
2516 link_check terminfo "terminfo(5) (via ${2})" \
2517 '#define HAVE_TERMCAP
2518 #define HAVE_TERMCAP_CURSES
2519 #define HAVE_TERMINFO' "${1}" << _EOT
2520 #include <stdio.h>
2521 #include <curses.h>
2522 #include <term.h>
2523 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2524 static int my_putc(int c){return putchar(c);}
2525 int main(void){
2526 int er, r0, r1, r2;
2527 char *r3, *tp;
2529 er = OK;
2530 r0 = setupterm(NULL, 1, &er);
2531 r1 = tigetflag(UNCONST("bce"));
2532 r2 = tigetnum(UNCONST("colors"));
2533 r3 = tigetstr(UNCONST("cr"));
2534 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2535 tputs(tp, 1, &my_putc);
2536 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2537 r3 == (char*)-1 || r3 == NULL);
2539 _EOT
2542 if feat_yes TERMCAP_VIA_TERMINFO; then
2543 __terminfolib -ltinfo -ltinfo ||
2544 __terminfolib -lcurses -lcurses ||
2545 __terminfolib -lcursesw -lcursesw ||
2546 feat_bail_required TERMCAP_VIA_TERMINFO
2549 if [ -z "${have_terminfo}" ]; then
2550 __termcaplib -ltermcap '' '' '-ltermcap' ||
2551 __termcaplib -ltermcap '#include <curses.h>' '
2552 #define HAVE_TERMCAP_CURSES' \
2553 'curses.h / -ltermcap' ||
2554 __termcaplib -lcurses '#include <curses.h>' '
2555 #define HAVE_TERMCAP_CURSES' \
2556 'curses.h / -lcurses' ||
2557 __termcaplib -lcursesw '#include <curses.h>' '
2558 #define HAVE_TERMCAP_CURSES' \
2559 'curses.h / -lcursesw' ||
2560 feat_bail_required TERMCAP
2562 if [ -n "${have_termcap}" ]; then
2563 run_check tgetent_null \
2564 "tgetent(3) of termcap(5) takes NULL buffer" \
2565 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2566 #include <stdio.h> /* For C89 NULL */
2567 #include <stdlib.h>
2568 #ifdef HAVE_TERMCAP_CURSES
2569 # include <curses.h>
2570 #endif
2571 #include <term.h>
2572 int main(void){
2573 tgetent(NULL, getenv("TERM"));
2574 return 0;
2576 _EOT
2579 else
2580 echo '/* OPT_TERMCAP=0 */' >> ${h}
2581 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2584 if feat_def SPAM_SPAMC; then
2585 if command -v spamc >/dev/null 2>&1; then
2586 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2590 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2591 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2592 else
2593 feat_bail_required SPAM_SPAMD
2594 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2597 feat_def SPAM_FILTER
2599 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2600 echo '#define HAVE_SPAM' >> ${h}
2601 else
2602 echo '/* HAVE_SPAM */' >> ${h}
2605 if feat_yes QUOTE_FOLD &&\
2606 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2607 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2608 else
2609 feat_bail_required QUOTE_FOLD
2610 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2613 feat_def FILTER_HTML_TAGSOUP
2614 feat_def COLOUR
2615 feat_def DOTLOCK
2616 feat_def MD5
2617 feat_def NOMEMDBG
2619 ## Summarizing
2621 ${rm} -f ${tmp}
2622 squeeze_em ${inc} ${tmp}
2623 ${mv} ${tmp} ${inc}
2624 squeeze_em ${lib} ${tmp}
2625 ${mv} ${tmp} ${lib}
2627 # mk-config.h
2628 ${mv} ${h} ${tmp}
2629 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2630 ${cat} ${tmp} >> ${h}
2631 ${rm} -f ${tmp}
2632 printf '\n' >> ${h}
2634 # Create the real mk-config.mk
2635 # Note we cannout use explicit ./ filename prefix for source and object
2636 # pathnames because of a bug in bmake(1)
2637 ${rm} -rf ${tmp0}.* ${tmp0}*
2638 printf 'OBJ_SRC = ' >> ${mk}
2639 if feat_no AMALGAMATION; then
2640 for i in `printf '%s\n' *.c | ${sort}`; do
2641 if [ "${i}" = privsep.c ]; then
2642 continue
2644 printf "${i} " >> ${mk}
2645 done
2646 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2647 else
2648 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2650 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2651 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2652 printf '# undef _CONFIG_H\n' >> ${h}
2653 printf '# define _CONFIG_H 2\n' >> ${h}
2654 for i in `printf '%s\n' *.c | ${sort}`; do
2655 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2656 [ "${i}" = privsep.c ]; then
2657 continue
2659 printf "${i} " >> ${mk}
2660 printf "# include \"${i}\"\n" >> ${h}
2661 done
2662 echo >> ${mk}
2663 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2664 echo '#else' >> ${h}
2667 # Finally, create the string that is used by *features* and `version'.
2668 # Take this nice opportunity and generate a visual listing of included and
2669 # non-included features for the person who runs the configuration
2670 msg '\nThe following features are included (+) or not (-):'
2671 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2672 printf '/* The "feature string" */\n' >> ${h}
2673 # Because + is expanded by *folder* if first in "echo $features", put something
2674 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2675 sep=
2676 for opt
2678 sdoc=`option_doc_of ${opt}`
2679 [ -z "${sdoc}" ] && continue
2680 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2681 feat_yes ${opt} && sign=+ || sign=-
2682 printf -- "${sep}${sign}${sopt}" >> ${h}
2683 sep=','
2684 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2685 done
2686 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2687 #exec 5>&1 >>${h}
2688 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2689 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2691 printf '"\n#endif /* n_MK_CONFIG_H */\n' >> ${h}
2693 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2694 echo "INCS = `${cat} ${inc}`" >> ${mk}
2695 echo >> ${mk}
2696 ${cat} ./make-config.in >> ${mk}
2698 ## Finished!
2700 msg '\nSetup:'
2701 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2702 msg ' . bindir: %s' "${VAL_BINDIR}"
2703 if feat_yes DOTLOCK; then
2704 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2706 msg ' . mandir: %s' "${VAL_MANDIR}"
2707 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2708 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2709 msg ''
2711 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2712 exit 0
2714 msg 'Remarks:'
2715 if [ -z "${have_fnmatch}" ]; then
2716 msg ' . The function fnmatch(3) could not be found.'
2717 msg ' Filename patterns like wildcard are not supported on your system'
2719 if [ -z "${have_fchdir}" ]; then
2720 msg ' . The function fchdir(2) could not be found.'
2721 msg ' We will use chdir(2) instead.'
2722 msg ' This is a problem only if the current working directory is changed'
2723 msg ' while this program is inside of it'
2725 msg ''
2727 # s-it-mode