Drop requirement of BYTE_ORDER knowledge ++ for OPT_CROSS_BUILD..
[s-mailx.git] / mk-conf.sh
blob238afeb81917a92c4b3724e011db968adbf3669c
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_yes DEVEL; then
186 OPT_DEBUG=1
190 rc=./make.rc
191 lst=./config.lst
192 ev=./config.ev
193 h=./config.h h_name=config.h
194 mk=./mk.mk
196 newlst=./config.lst-new
197 newmk=./config.mk-new
198 newev=./config.ev-new
199 newh=./config.h-new
200 tmp0=___tmp
201 tmp=./${tmp0}1$$
202 tmp2=./${tmp0}2$$
204 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
206 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
207 # via path_check() later on once possible
209 # TODO cc_maxopt is brute simple, we should compile test program and dig real
210 # compiler versions for known compilers, then be more specific
211 cc_maxopt=100
212 _CFLAGS= _LDFLAGS=
214 os_early_setup() {
215 # We don't "have any utility": only path adjustments and such in here!
216 i="${OS:-`uname -s`}"
218 if [ ${i} = SunOS ]; then
219 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
220 _os_early_setup_sunos
224 _os_early_setup_sunos() {
225 # According to standards(5), this is what we need to do
226 if [ -d /usr/xpg4 ]; then :; else
227 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
228 config_exit 1
230 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
231 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
232 export PATH
235 os_setup() {
236 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
237 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
238 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
239 msg 'Operating system is %s' ${OS}
241 if [ ${OS} = sunos ]; then
242 msg ' . have special SunOS / Solaris "setup" rules ...'
243 _os_setup_sunos
244 elif [ ${OS} = unixware ]; then
245 msg ' . have special UnixWare environmental rules ...'
246 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
247 CC=cc
248 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
250 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
251 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
252 export CC CFLAGS LDFLAGS
253 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
255 elif [ -n "${VERBOSE}" ]; then
256 msg ' . no special treatment for this system necessary or known'
259 # Sledgehammer: better set _GNU_SOURCE
260 # And in general: oh, boy!
261 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
262 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
263 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
264 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
266 # On pkgsrc(7) systems automatically add /usr/pkg/*
267 if [ -d /usr/pkg ]; then
268 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
269 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
273 _os_setup_sunos() {
274 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
275 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
277 # Include packages
278 if [ -d /opt/csw ]; then
279 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
280 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
283 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
284 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
286 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
287 if [ -x "${cksum}" ]; then :; else
288 msg 'ERROR: Not an executable program: %s' "${cksum}"
289 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
290 msg 'ERROR: However, we do so only for tests.'
291 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
292 config_exit 1
295 if feat_yes AUTOCC; then
296 if command -v cc >/dev/null 2>&1; then
297 CC=cc
298 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
300 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
301 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
302 export CC CFLAGS LDFLAGS
303 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
304 else
305 # Assume gcc(1), which supports -R for compat
306 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
311 # Check out compiler ($CC) and -flags ($CFLAGS)
312 cc_setup() {
313 # Even though it belongs into cc_flags we will try to compile and link
314 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
315 # EXTRA_CFLAGS/EXTRA_LDFLAGS
316 if feat_no AUTOCC; then
317 _cc_default
318 # Ensure those don't do any harm
319 EXTRA_CFLAGS= EXTRA_LDFLAGS=
320 export EXTRA_CFLAGS EXTRA_LDFLAGS
321 return
322 else
323 CFLAGS= LDFLAGS=
324 export CFLAGS LDFLAGS
327 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
329 msg_nonl 'Searching for a usable C compiler .. $CC='
330 if { i="`command -v clang`"; }; then
331 CC=${i}
332 elif { i="`command -v gcc`"; }; then
333 CC=${i}
334 elif { i="`command -v c99`"; }; then
335 CC=${i}
336 elif { i="`command -v tcc`"; }; then
337 CC=${i}
338 elif { i="`command -v pcc`"; }; then
339 CC=${i}
340 else
341 if [ "${CC}" = cc ]; then
343 elif { i="`command -v c89`"; }; then
344 CC=${i}
345 else
346 msg 'boing booom tschak'
347 msg 'ERROR: I cannot find a compiler!'
348 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
349 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
350 config_exit 1
353 msg '%s' "${CC}"
354 export CC
357 _cc_default() {
358 if [ -z "${CC}" ]; then
359 msg 'To go on like you have chosen, please set $CC, rerun.'
360 config_exit 1
363 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
365 else
366 msg 'Using C compiler ${CC}=%s' "${CC}"
370 cc_flags() {
371 if feat_yes AUTOCC; then
372 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
373 cc_check_silent=1
374 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
375 "${CC}"
376 else
377 cc_check_silent=
378 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
381 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
382 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
383 msg ' . have special tcc(1) environmental rules ...'
384 _cc_flags_tcc
385 else
386 # As of pcc CVS 2016-04-02, stack protection support is announced but
387 # will break if used on Linux
388 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
389 force_no_stackprot=1
391 _cc_flags_generic
394 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
395 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
396 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
397 else
398 if feat_no DEBUG; then
399 CFLAGS="-DNDEBUG ${CFLAGS}"
402 msg ''
403 export CFLAGS LDFLAGS
406 _cc_flags_tcc() {
407 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
408 _CFLAGS= _LDFLAGS=
410 cc_check -Wall
411 cc_check -Wextra
412 cc_check -pedantic
414 if feat_yes DEBUG; then
415 # May have problems to find libtcc cc_check -b
416 cc_check -g
419 if ld_check -Wl,-rpath =./ no; then
420 need_R_ldflags=-Wl,-rpath=
421 ld_runtime_flags # update!
424 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
425 unset __cflags __ldflags
428 _cc_flags_generic() {
429 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
430 _CFLAGS= _LDFLAGS=
431 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
433 # Check -g first since some others may rely upon -g / optim. level
434 if feat_yes DEBUG; then
435 cc_check -O
436 cc_check -g
437 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
439 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
441 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
443 else
444 cc_check -O
447 if feat_yes DEVEL && cc_check -Weverything; then
449 else
450 cc_check -Wall
451 cc_check -Wextra
452 cc_check -Wbad-function-cast
453 cc_check -Wcast-align
454 cc_check -Wcast-qual
455 cc_check -Winit-self
456 cc_check -Wmissing-prototypes
457 cc_check -Wshadow
458 cc_check -Wunused
459 cc_check -Wwrite-strings
460 cc_check -Wno-long-long
462 cc_check -pedantic
464 if feat_yes AMALGAMATION && feat_no DEVEL; then
465 cc_check -Wno-unused-function
467 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
469 cc_check -fno-unwind-tables
470 cc_check -fno-asynchronous-unwind-tables
471 cc_check -fstrict-aliasing
472 if cc_check -fstrict-overflow && feat_yes DEVEL; then
473 cc_check -Wstrict-overflow=5
476 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
477 if [ -z "${force_no_stackprot}" ]; then
478 if cc_check -fstack-protector-strong ||
479 cc_check -fstack-protector-all; then
480 cc_check -D_FORTIFY_SOURCE=2
482 else
483 msg 'Not checking for -fstack-protector compiler option,'
484 msg 'since that caused errors in a "similar" configuration.'
485 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
489 if feat_yes AMALGAMATION; then
490 cc_check -pipe
493 # LD (+ dependend CC)
495 if feat_yes DEVEL; then
496 _ccfg=${_CFLAGS}
497 # -fsanitize=address
498 #if cc_check -fsanitize=memory &&
499 # ld_check -fsanitize=memory &&
500 # cc_check -fsanitize-memory-track-origins=2 &&
501 # ld_check -fsanitize-memory-track-origins=2; then
503 #else
504 # _CFLAGS=${_ccfg}
508 ld_check -Wl,-z,relro
509 ld_check -Wl,-z,now
510 ld_check -Wl,-z,noexecstack
511 if ld_check -Wl,-rpath =./ no; then
512 need_R_ldflags=-Wl,-rpath=
513 ld_runtime_flags # update!
514 elif ld_check -Wl,-R ./ no; then
515 need_R_ldflags=-Wl,-R
516 ld_runtime_flags # update!
519 # Address randomization
520 _ccfg=${_CFLAGS}
521 if cc_check -fPIE || cc_check -fpie; then
522 ld_check -pie || _CFLAGS=${_ccfg}
524 unset _ccfg
526 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
527 unset __cflags __ldflags
530 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
532 ## Notes:
533 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
534 ## redirection, so use "printf '' >" instead
536 ## Very first: we undergo several states regarding I/O redirection etc.,
537 ## but need to deal with option updates from within all. Since all the
538 ## option stuff should be above the scissor line, define utility functions
539 ## and redefine them as necessary.
540 ## And, since we have those functions, simply use them for whatever
542 config_exit() {
543 exit ${1}
546 msg() {
547 fmt=${1}
548 shift
549 printf >&2 -- "${fmt}\\n" "${@}"
552 msg_nonl() {
553 fmt=${1}
554 shift
555 printf >&2 -- "${fmt}" "${@}"
558 t1=ten10one1ten10one1
559 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
560 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
561 ) > /dev/null 2>&1; then
562 good_shell=1
563 else
564 unset good_shell
566 unset t1
568 # We need some standard utilities
569 unset -f command
570 check_tool() {
571 n=${1} i=${2} opt=${3:-0}
572 # Evaluate, just in case user comes in with shell snippets (..well..)
573 eval i="${i}"
574 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
575 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
576 eval ${n}=${i}
577 return 0
579 if [ ${opt} -eq 0 ]; then
580 msg 'ERROR: no trace of utility %s' "${n}"
581 config_exit 1
583 return 1
586 # Our feature check environment
587 feat_val_no() {
588 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
589 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
592 feat_val_yes() {
593 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
594 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
595 [ "x${1}" = xrequire ]
598 feat_val_require() {
599 [ "x${1}" = xrequire ]
602 _feat_check() {
603 eval i=\$OPT_${1}
604 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
605 if feat_val_no "${i}"; then
606 return 1
607 elif feat_val_yes "${i}"; then
608 return 0
609 else
610 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
611 "${1}" "${i}"
612 config_exit 11
616 feat_yes() {
617 _feat_check ${1}
620 feat_no() {
621 _feat_check ${1} && return 1
622 return 0
625 feat_require() {
626 eval i=\$OPT_${1}
627 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
628 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
631 feat_bail_required() {
632 if feat_require ${1}; then
633 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
634 config_exit 13
636 eval OPT_${1}=0
637 option_update # XXX this is rather useless here (dependency chain..)
640 option_parse() {
641 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
642 # options, without documentation, to $1
643 j=\'
644 i="`${awk} -v input=\"${2}\" '
645 BEGIN{
646 for(i = 0;;){
647 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
648 if(voff == 0)
649 break
650 v = substr(input, voff, RLENGTH)
651 input = substr(input, voff + RLENGTH)
652 doff = index(v, "=")
653 if(doff > 0){
654 d = substr(v, doff + 2, length(v) - doff - 1)
655 v = substr(v, 1, doff - 1)
657 print v
661 eval ${1}=\"${i}\"
664 option_doc_of() {
665 # Return the "documentation string" for option $1, itself if none such
666 j=\'
667 ${awk} -v want="${1}" \
668 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
669 BEGIN{
670 for(;;){
671 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
672 if(voff == 0)
673 break
674 v = substr(input, voff, RLENGTH)
675 input = substr(input, voff + RLENGTH)
676 doff = index(v, "=")
677 if(doff > 0){
678 d = substr(v, doff + 2, length(v) - doff - 1)
679 v = substr(v, 1, doff - 1)
680 }else
681 d = v
682 if(v == want){
683 if(d != "-")
684 print d
685 exit
692 option_join_rc() {
693 # Join the values from make.rc into what currently is defined, not
694 # overwriting yet existing settings
695 ${rm} -f ${tmp}
696 # We want read(1) to perform backslash escaping in order to be able to use
697 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow
698 # in VMs (see [fa2e248]), Aharon Robbins suggested the following
699 < ${rc} ${awk} 'BEGIN{line = ""}{
700 gsub(/^[[:space:]]+/, "", $0)
701 gsub(/[[:space:]]+$/, "", $0)
702 if(gsub(/\\$/, "", $0)){
703 line = line $0
704 next
705 }else
706 line = line $0
707 if(index(line, "#") == 1){
708 line = ""
709 }else if(length(line)){
710 print line
711 line = ""
713 }' |
714 while read line; do
715 if [ -n "${good_shell}" ]; then
716 i=${line%%=*}
717 else
718 i=`${awk} -v LINE="${line}" 'BEGIN{
719 gsub(/=.*$/, "", LINE)
720 print LINE
723 if [ "${i}" = "${line}" ]; then
724 msg 'ERROR: invalid syntax in: %s' "${line}"
725 continue
728 eval j="\$${i}" jx="\${${i}+x}"
729 if [ -n "${j}" ] || [ "${jx}" = x ]; then
730 : # Yet present
731 else
732 j=`${awk} -v LINE="${line}" 'BEGIN{
733 gsub(/^[^=]*=/, "", LINE)
734 gsub(/^\"*/, "", LINE)
735 gsub(/\"*$/, "", LINE)
736 print LINE
739 [ "${i}" = "DESTDIR" ] && continue
740 echo "${i}=\"${j}\""
741 done > ${tmp}
742 # Reread the mixed version right now
743 . ./${tmp}
746 option_evaluate() {
747 # Expand the option values, which may contain shell snippets
748 ${rm} -f ${newlst} ${newmk} ${newh}
749 exec 5<&0 6>&1 <${tmp} >${newlst}
750 while read line; do
752 if [ -n "${good_shell}" ]; then
753 i=${line%%=*}
754 [ "${i}" != "${i#OPT_}" ] && z=1
755 else
756 i=`${awk} -v LINE="${line}" 'BEGIN{
757 gsub(/=.*$/, "", LINE);\
758 print LINE
760 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
765 eval j=\$${i}
766 if [ -n "${z}" ]; then
767 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
768 if [ -z "${j}" ] || feat_val_no "${j}"; then
770 printf " /* #undef ${i} */\n" >> ${newh}
771 elif feat_val_yes "${j}"; then
772 if feat_val_require "${j}"; then
773 j=require
774 else
777 printf " /* #define ${i} */\n" >> ${newh}
778 else
779 msg 'ERROR: cannot parse <%s>' "${line}"
780 config_exit 1
782 else
783 printf "#define ${i} \"${j}\"\n" >> ${newh}
785 printf "${i} = ${j}\n" >> ${newmk}
786 printf "${i}=${j}\n"
787 eval "${i}=\"${j}\""
788 done
789 exec 0<&5 1>&6 5<&- 6<&-
792 path_check() {
793 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
794 varname=${1} addflag=${2} flagvarname=${3}
795 j=${IFS}
796 IFS=:
797 eval "set -- \$${1}"
798 IFS=${j}
799 j= k= y= z=
800 for i
802 [ -z "${i}" ] && continue
803 [ -d "${i}" ] || continue
804 # Skip any fakeroot packager environment
805 case "${i}" in *fakeroot*) continue;; esac
806 if [ -n "${j}" ]; then
807 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
809 else
810 y="${y} :${i}:"
811 j="${j}:${i}"
812 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
814 else
815 y=" :${i}:"
816 j="${i}"
817 [ -n "${addflag}" ] && k="${addflag}${i}"
819 done
820 eval "${varname}=\"${j}\""
821 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
822 unset varname
825 ld_runtime_flags() {
826 if [ -n "${need_R_ldflags}" ]; then
827 i=${IFS}
828 IFS=:
829 set -- ${LD_LIBRARY_PATH}
830 IFS=${i}
831 for i
833 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
834 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
835 done
836 export LDFLAGS
838 # Disable it for a possible second run.
839 need_R_ldflags=
842 cc_check() {
843 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
844 if "${CC}" ${INCS} \
845 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
846 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
847 _CFLAGS="${_CFLAGS} ${1}"
848 [ -n "${cc_check_silent}" ] || msg 'yes'
849 return 0
851 [ -n "${cc_check_silent}" ] || msg 'no'
852 return 1
855 ld_check() {
856 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
857 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
858 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
859 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
860 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
861 [ -n "${cc_check_silent}" ] || msg 'yes'
862 return 0
864 [ -n "${cc_check_silent}" ] || msg 'no'
865 return 1
868 _check_preface() {
869 variable=$1 topic=$2 define=$3
871 echo '**********'
872 msg_nonl ' . %s ... ' "${topic}"
873 echo "/* checked ${topic} */" >> ${h}
874 ${rm} -f ${tmp} ${tmp}.o
875 echo '*** test program is'
876 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
877 #echo '*** the preprocessor generates'
878 #${make} -f ${makefile} ${tmp}.x
879 #${cat} ${tmp}.x
880 echo '*** results are'
883 without_check() {
884 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
886 echo '**********'
887 msg_nonl ' . %s ... ' "${topic}"
889 echo '*** enforced unchecked results are'
890 if feat_val_yes ${yesno}; then
891 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
892 echo "*** adding INCS<${incs}> LIBS<${libs}>"
893 LIBS="${LIBS} ${libs}"
894 echo "${libs}" >> ${lib}
895 INCS="${INCS} ${incs}"
896 echo "${incs}" >> ${inc}
898 msg 'yes (deduced)'
899 echo "${define}" >> ${h}
900 eval have_${variable}=yes
901 return 0
902 else
903 echo "/* ${define} */" >> ${h}
904 msg 'no (deduced)'
905 eval unset have_${variable}
906 return 1
910 compile_check() {
911 variable=$1 topic=$2 define=$3
913 _check_preface "${variable}" "${topic}" "${define}"
915 if ${make} -f ${makefile} XINCS="${INCS}" \
916 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
917 ./${tmp}.o &&
918 [ -f ./${tmp}.o ]; then
919 msg 'yes'
920 echo "${define}" >> ${h}
921 eval have_${variable}=yes
922 return 0
923 else
924 echo "/* ${define} */" >> ${h}
925 msg 'no'
926 eval unset have_${variable}
927 return 1
931 _link_mayrun() {
932 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
934 _check_preface "${variable}" "${topic}" "${define}"
936 if feat_yes CROSS_BUILD; then
937 if [ ${run} = 1 ]; then
938 run=0
942 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
943 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
944 XLIBS="${LIBS} ${libs}" \
945 ./${tmp} &&
946 [ -f ./${tmp} ] &&
947 { [ ${run} -eq 0 ] || ./${tmp}; }; then
948 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
949 msg 'yes'
950 echo "${define}" >> ${h}
951 LIBS="${LIBS} ${libs}"
952 echo "${libs}" >> ${lib}
953 INCS="${INCS} ${incs}"
954 echo "${incs}" >> ${inc}
955 eval have_${variable}=yes
956 return 0
957 else
958 msg 'no'
959 echo "/* ${define} */" >> ${h}
960 eval unset have_${variable}
961 return 1
965 link_check() {
966 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
969 run_check() {
970 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
973 xrun_check() {
974 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
977 feat_def() {
978 if feat_yes ${1}; then
979 echo '#define HAVE_'${1}'' >> ${h}
980 else
981 echo '/* OPT_'${1}'=0 */' >> ${h}
985 squeeze_em() {
986 < "${1}" > "${2}" ${awk} \
987 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
990 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
992 # First of all, create new configuration and check whether it changed
994 # Very easy checks for the operating system in order to be able to adjust paths
995 # or similar very basic things which we need to be able to go at all
996 os_early_setup
998 # Check those tools right now that we need before including $rc
999 msg 'Checking for basic utility set'
1000 check_tool awk "${awk:-`command -v awk`}"
1001 check_tool rm "${rm:-`command -v rm`}"
1002 check_tool tr "${tr:-`command -v tr`}"
1004 # Initialize the option set
1005 msg_nonl 'Setting up configuration options ... '
1006 option_setup
1007 msg 'done'
1009 # Include $rc, but only take from it what wasn't overwritten by the user from
1010 # within the command line or from a chosen fixed CONFIG=
1011 # Note we leave alone the values
1012 trap "exit 1" HUP INT TERM
1013 trap "${rm} -f ${tmp}" EXIT
1015 msg_nonl 'Joining in %s ... ' ${rc}
1016 option_join_rc
1017 msg 'done'
1019 # We need to know about that now, in order to provide utility overwrites etc.
1020 os_setup
1022 msg 'Checking for remaining set of utilities'
1023 check_tool grep "${grep:-`command -v grep`}"
1025 # Before we step ahead with the other utilities perform a path cleanup first.
1026 path_check PATH
1028 # awk(1) above
1029 check_tool cat "${cat:-`command -v cat`}"
1030 check_tool chmod "${chmod:-`command -v chmod`}"
1031 check_tool cp "${cp:-`command -v cp`}"
1032 check_tool cmp "${cmp:-`command -v cmp`}"
1033 # grep(1) above
1034 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1035 check_tool mv "${mv:-`command -v mv`}"
1036 # rm(1) above
1037 check_tool sed "${sed:-`command -v sed`}"
1038 check_tool sort "${sort:-`command -v sort`}"
1039 check_tool tee "${tee:-`command -v tee`}"
1041 check_tool chown "${chown:-`command -v chown`}" 1 ||
1042 check_tool chown "/sbin/chown" 1 ||
1043 check_tool chown "/usr/sbin/chown"
1045 check_tool make "${MAKE:-`command -v make`}"
1046 MAKE=${make}
1047 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1048 HAVE_STRIP=1 || HAVE_STRIP=0
1050 # For ./cc-test.sh only
1051 check_tool cksum "${cksum:-`command -v cksum`}"
1053 # Update OPT_ options now, in order to get possible inter-dependencies right
1054 option_update
1056 # (No functions since some shells loose non-exported variables in traps)
1057 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1058 trap "trap \"\" HUP INT TERM EXIT;\
1059 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1061 # Our configuration options may at this point still contain shell snippets,
1062 # we need to evaluate them in order to get them expanded, and we need those
1063 # evaluated values not only in our new configuration file, but also at hand..
1064 msg_nonl 'Evaluating all configuration items ... '
1065 option_evaluate
1066 msg 'done'
1068 # Add the known utility and some other variables
1069 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_NAIL}\"\n" >> ${newh}
1070 printf "VAL_UAGENT = ${VAL_SID}${VAL_NAIL}\n" >> ${newmk}
1072 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_NAIL}-privsep\"\n" >> ${newh}
1073 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1074 if feat_yes DOTLOCK; then
1075 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1076 else
1077 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1080 for i in \
1081 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1082 MAKE MAKEFLAGS make SHELL strip \
1083 cksum; do
1084 eval j=\$${i}
1085 printf "${i} = ${j}\n" >> ${newmk}
1086 printf "${i}=${j}\n" >> ${newlst}
1087 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1088 done
1089 printf "\n" >> ${newev}
1091 # Build a basic set of INCS and LIBS according to user environment.
1092 path_check C_INCLUDE_PATH -I _INCS
1093 INCS="${INCS} ${_INCS}"
1094 path_check LD_LIBRARY_PATH -L _LIBS
1095 LIBS="${LIBS} ${_LIBS}"
1096 unset _INCS _LIBS
1097 export C_INCLUDE_PATH LD_LIBRARY_PATH
1099 # Some environments need runtime path flags to be able to go at all
1100 ld_runtime_flags
1102 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1104 cc_setup
1106 ${cat} > ${tmp}.c << \!
1107 #include <stdio.h>
1108 #include <string.h>
1109 static void doit(char const *s);
1111 main(int argc, char **argv){
1112 (void)argc;
1113 (void)argv;
1114 doit("Hello world");
1115 return 0;
1117 static void
1118 doit(char const *s){
1119 char buf[12];
1120 memcpy(buf, s, strlen(s) +1);
1121 puts(s);
1125 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1126 -o ${tmp2} ${tmp}.c ${LIBS}; then
1128 else
1129 msg 'ERROR: i cannot compile a "Hello world" via'
1130 msg ' %s' \
1131 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1132 msg 'ERROR: Please read INSTALL, rerun'
1133 config_exit 1
1136 # This may also update ld_runtime_flags() (again)
1137 cc_flags
1139 for i in \
1140 INCS LIBS \
1141 ; do
1142 eval j=\$${i}
1143 printf -- "${i}=${j}\n" >> ${newlst}
1144 done
1145 for i in \
1146 CC \
1147 CFLAGS \
1148 LDFLAGS \
1149 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1150 OSFULLSPEC \
1151 ; do
1152 eval j=\$${i}
1153 printf -- "${i} = ${j}\n" >> ${newmk}
1154 printf -- "${i}=${j}\n" >> ${newlst}
1155 done
1157 # Now finally check whether we already have a configuration and if so, whether
1158 # all those parameters are still the same.. or something has actually changed
1159 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1160 echo 'Configuration is up-to-date'
1161 exit 0
1162 elif [ -f ${lst} ]; then
1163 echo 'Configuration has been updated..'
1164 ( eval "${MAKE} -f ./mk.mk clean" )
1165 echo
1166 else
1167 echo 'Shiny configuration..'
1170 # Time to redefine helper 1
1171 config_exit() {
1172 ${rm} -f ${lst} ${h} ${mk}
1173 exit ${1}
1176 ${mv} -f ${newlst} ${lst}
1177 ${mv} -f ${newev} ${ev}
1178 ${mv} -f ${newh} ${h}
1179 ${mv} -f ${newmk} ${mk}
1181 if [ -z "${VERBOSE}" ]; then
1182 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1183 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1184 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1185 printf -- "ECHO_TEST = @\n" >> ${mk}
1186 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1187 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1188 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1191 ## Compile and link checking
1193 tmp3=./${tmp0}3$$
1194 log=./config.log
1195 lib=./config.lib
1196 inc=./config.inc
1197 makefile=./config.mk
1199 # (No function since some shells loose non-exported variables in traps)
1200 trap "trap \"\" HUP INT TERM;\
1201 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1202 trap "trap \"\" HUP INT TERM EXIT;\
1203 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
1205 # Time to redefine helper 2
1206 msg() {
1207 fmt=${1}
1208 shift
1209 printf "*** ${fmt}\\n" "${@}"
1210 printf -- "${fmt}\\n" "${@}" >&5
1212 msg_nonl() {
1213 fmt=${1}
1214 shift
1215 printf "*** ${fmt}\\n" "${@}"
1216 printf -- "${fmt}" "${@}" >&5
1219 # !!
1220 exec 5>&2 > ${log} 2>&1
1222 echo "${LIBS}" > ${lib}
1223 echo "${INCS}" > ${inc}
1224 ${cat} > ${makefile} << \!
1225 .SUFFIXES: .o .c .x .y
1226 .c.o:
1227 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1228 .c.x:
1229 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1231 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1234 ## Generics
1236 # May be multiline..
1237 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1239 feat_def ALWAYS_UNICODE_LOCALE
1240 feat_def AMALGAMATION
1241 feat_def CROSS_BUILD
1242 feat_def DEBUG
1243 feat_def DEVEL
1244 feat_def DOCSTRINGS
1245 feat_def ERRORS
1246 feat_def NYD2
1247 feat_def NOMEMDBG
1249 if xrun_check inline 'inline functions' \
1250 '#define HAVE_INLINE
1251 #define n_INLINE static inline' << \!
1252 static inline int ilf(int i){return ++i;}
1253 int main(void){return ilf(-1);}
1255 then
1257 elif xrun_check inline 'inline functions (via __inline)' \
1258 '#define HAVE_INLINE
1259 #define n_INLINE static __inline' << \!
1260 static __inline int ilf(int i){return ++i;}
1261 int main(void){return ilf(-1);}
1263 then
1267 ## Test for "basic" system-calls / functionality that is used by all parts
1268 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1269 ## macros to be used by only the subprograms (potentially).
1271 if run_check clock_gettime 'clock_gettime(2)' \
1272 '#define HAVE_CLOCK_GETTIME' << \!
1273 #include <time.h>
1274 # include <errno.h>
1275 int main(void){
1276 struct timespec ts;
1278 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1279 return 0;
1280 return 1;
1283 then
1285 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1286 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1287 #include <time.h>
1288 # include <errno.h>
1289 int main(void){
1290 struct timespec ts;
1292 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1293 return 0;
1294 return 1;
1297 then
1299 elif run_check gettimeofday 'gettimeofday(2)' \
1300 '#define HAVE_GETTIMEOFDAY' << \!
1301 #include <stdio.h> /* For C89 NULL */
1302 #include <sys/time.h>
1303 # include <errno.h>
1304 int main(void){
1305 struct timeval tv;
1307 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1308 return 0;
1309 return 1;
1312 then
1314 else
1315 have_no_subsecond_time=1
1318 if run_check nanosleep 'nanosleep(2)' \
1319 '#define HAVE_NANOSLEEP' << \!
1320 #include <time.h>
1321 # include <errno.h>
1322 int main(void){
1323 struct timespec ts;
1325 ts.tv_sec = 1;
1326 ts.tv_nsec = 100000;
1327 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1328 return 0;
1329 return 1;
1332 then
1334 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1335 '#define HAVE_NANOSLEEP' '-lrt' << \!
1336 #include <time.h>
1337 # include <errno.h>
1338 int main(void){
1339 struct timespec ts;
1341 ts.tv_sec = 1;
1342 ts.tv_nsec = 100000;
1343 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1344 return 0;
1345 return 1;
1348 then
1350 # link_check is enough for this, that function is so old, trust the proto
1351 elif link_check sleep 'sleep(3)' \
1352 '#define HAVE_SLEEP' << \!
1353 #include <unistd.h>
1354 # include <errno.h>
1355 int main(void){
1356 if(!sleep(1) || errno != ENOSYS)
1357 return 0;
1358 return 1;
1361 then
1363 else
1364 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1365 config_exit 1
1368 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1369 #include <pwd.h>
1370 #include <unistd.h>
1371 # include <errno.h>
1372 int main(void){
1373 struct passwd *pw;
1374 gid_t gid;
1375 uid_t uid;
1377 if((gid = getgid()) != 0)
1378 gid = getegid();
1379 if((uid = getuid()) != 0)
1380 uid = geteuid();
1381 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1382 return 1;
1383 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1384 return 1;
1385 return 0;
1388 then
1390 else
1391 msg 'ERROR: we require user and group info / database searches.'
1392 msg 'That much Unix we indulge ourselfs.'
1393 config_exit 1
1396 if link_check ftruncate 'ftruncate(2)' \
1397 '#define HAVE_FTRUNCATE' << \!
1398 #include <unistd.h>
1399 #include <sys/types.h>
1400 int main(void){
1401 return (ftruncate(0, 0) != 0);
1404 then
1406 else
1407 msg 'ERROR: we require the ftruncate(2) system call.'
1408 config_exit 1
1411 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1412 #include <signal.h>
1413 # include <errno.h>
1414 int main(void){
1415 struct sigaction nact, oact;
1417 nact.sa_handler = SIG_DFL;
1418 sigemptyset(&nact.sa_mask);
1419 nact.sa_flags = SA_RESTART;
1420 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1423 then
1425 else
1426 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1427 config_exit 1
1430 if link_check snprintf 'snprintf(3)' << \!
1431 #include <stdio.h>
1432 int main(void){
1433 char b[20];
1435 snprintf(b, sizeof b, "%s", "string");
1436 return 0;
1439 then
1441 else
1442 msg 'ERROR: we require the snprintf(3) function.'
1443 config_exit 1
1446 if link_check environ 'environ(3)' << \!
1447 #include <stdio.h> /* For C89 NULL */
1448 int main(void){
1449 extern char **environ;
1451 return environ[0] == NULL;
1454 then
1456 else
1457 msg 'ERROR: we require the environ(3) array for subprocess control.'
1458 config_exit 1
1461 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1462 #include <stdlib.h>
1463 int main(void){
1464 setenv("s-mailx", "i want to see it cute!", 1);
1465 unsetenv("s-mailx");
1466 return 0;
1469 then
1471 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1472 #include <stdlib.h>
1473 int main(void){
1474 putenv("s-mailx=i want to see it cute!");
1475 return 0;
1478 then
1480 else
1481 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1482 config_exit 1
1485 if link_check termios 'termios.h and tc*(3) family' << \!
1486 #include <termios.h>
1487 int main(void){
1488 struct termios tios;
1490 tcgetattr(0, &tios);
1491 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1492 return 0;
1495 then
1497 else
1498 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1499 msg 'That much Unix we indulge ourselfs.'
1500 config_exit 1
1503 ## optional stuff
1505 if link_check vsnprintf 'vsnprintf(3)' << \!
1506 #include <stdarg.h>
1507 #include <stdio.h>
1508 static void dome(char *buf, size_t blen, ...){
1509 va_list ap;
1511 va_start(ap, blen);
1512 vsnprintf(buf, blen, "%s", ap);
1513 va_end(ap);
1515 int main(void){
1516 char b[20];
1518 dome(b, sizeof b, "string");
1519 return 0;
1522 then
1524 else
1525 feat_bail_required ERRORS
1528 if [ "${have_vsnprintf}" = yes ]; then
1529 __va_copy() {
1530 link_check va_copy "va_copy(3) (as ${2})" \
1531 "#define HAVE_N_VA_COPY
1532 #define n_va_copy ${2}" <<_EOT
1533 #include <stdarg.h>
1534 #include <stdio.h>
1535 #if ${1}
1536 # if defined __va_copy && !defined va_copy
1537 # define va_copy __va_copy
1538 # endif
1539 #endif
1540 static void dome2(char *buf, size_t blen, va_list src){
1541 va_list ap;
1543 va_copy(ap, src);
1544 vsnprintf(buf, blen, "%s", ap);
1545 va_end(ap);
1547 static void dome(char *buf, size_t blen, ...){
1548 va_list ap;
1550 va_start(ap, blen);
1551 dome2(buf, blen, ap);
1552 va_end(ap);
1554 int main(void){
1555 char b[20];
1557 dome(b, sizeof b, "string");
1558 return 0;
1560 _EOT
1562 __va_copy 0 va_copy || __va_copy 1 __va_copy
1565 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1566 #include <unistd.h>
1567 #include <errno.h>
1568 int main(void){
1569 int rv = 0;
1571 errno = 0;
1572 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1573 errno = 0;
1574 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1576 /* Only link check */
1577 fpathconf(0, _PC_NAME_MAX);
1579 return rv;
1583 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1584 #include <fcntl.h>
1585 #include <unistd.h>
1586 # include <errno.h>
1587 int main(void){
1588 int fds[2];
1590 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1591 return 0;
1592 return 1;
1596 # We use this only then for now (need NOW+1)
1597 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1598 #include <fcntl.h> /* For AT_* */
1599 #include <sys/stat.h>
1600 # include <errno.h>
1601 int main(void){
1602 struct timespec ts[2];
1604 ts[0].tv_nsec = UTIME_NOW;
1605 ts[1].tv_nsec = UTIME_OMIT;
1606 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1607 return 0;
1608 return 1;
1614 # XXX Add POSIX check once standardized
1615 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1616 #include <stdlib.h>
1617 int main(void){
1618 arc4random();
1619 return 0;
1622 then
1624 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1625 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1626 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1627 #include <sys/random.h>
1628 int main(void){
1629 char buf[256];
1630 getrandom(buf, sizeof buf, 0);
1631 return 0;
1634 then
1636 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1637 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1638 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1639 #include <sys/syscall.h>
1640 int main(void){
1641 char buf[256];
1642 syscall(SYS_getrandom, buf, sizeof buf, 0);
1643 return 0;
1646 then
1648 elif [ -n "${have_no_subsecond_time}" ]; then
1649 msg 'ERROR: %s %s' 'without a native random' \
1650 'one of clock_gettime(2) and gettimeofday(2) is required.'
1651 config_exit 1
1655 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1656 #include <stdio.h>
1657 int main(void){
1658 putc_unlocked('@', stdout);
1659 return 0;
1663 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1664 #include <unistd.h>
1665 int main(void){
1666 fchdir(0);
1667 return 0;
1671 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1672 #include <stdlib.h>
1673 int main(void){
1674 char x_buf[4096], *x = realpath(".", x_buf);
1676 return (x != NULL) ? 0 : 1;
1679 then
1680 if run_check realpath_malloc 'realpath(3) takes NULL' \
1681 '#define HAVE_REALPATH_NULL' << \!
1682 #include <stdlib.h>
1683 int main(void){
1684 char *x = realpath(".", NULL);
1686 if(x != NULL)
1687 free(x);
1688 return (x != NULL) ? 0 : 1;
1691 then
1696 ## optional and selectable
1698 if feat_yes DOTLOCK; then
1699 if run_check readlink 'readlink(2)' << \!
1700 #include <unistd.h>
1701 # include <errno.h>
1702 int main(void){
1703 char buf[128];
1705 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1706 return 0;
1707 return 1;
1710 then
1712 else
1713 feat_bail_required DOTLOCK
1717 if feat_yes DOTLOCK; then
1718 if run_check fchown 'fchown(2)' << \!
1719 #include <unistd.h>
1720 # include <errno.h>
1721 int main(void){
1722 if(!fchown(0, 0, 0) || errno != ENOSYS)
1723 return 0;
1724 return 1;
1727 then
1729 else
1730 feat_bail_required DOTLOCK
1734 ## Now it is the time to fork away the BASE_ series
1736 ${rm} -f ${tmp}
1737 squeeze_em ${inc} ${tmp}
1738 ${mv} ${tmp} ${inc}
1739 squeeze_em ${lib} ${tmp}
1740 ${mv} ${tmp} ${lib}
1742 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1743 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1745 ## The remains are expected to be used only by the main MUA binary!
1747 OPT_LOCALES=0
1748 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1749 #include <locale.h>
1750 int main(void){
1751 setlocale(LC_ALL, "");
1752 return 0;
1755 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1757 OPT_MULTIBYTE_CHARSETS=0
1758 OPT_WIDE_GLYPHS=0
1759 OPT_TERMINAL_CHARSET=0
1760 if [ -n "${have_setlocale}" ]; then
1761 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1762 '#define HAVE_C90AMEND1' << \!
1763 #include <limits.h>
1764 #include <stdlib.h>
1765 #include <wchar.h>
1766 #include <wctype.h>
1767 int main(void){
1768 char mbb[MB_LEN_MAX + 1];
1769 wchar_t wc;
1771 iswprint(L'c');
1772 towupper(L'c');
1773 mbtowc(&wc, "x", 1);
1774 mbrtowc(&wc, "x", 1, NULL);
1775 wctomb(mbb, wc);
1776 return (mblen("\0", 1) == 0);
1779 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1781 if [ -n "${have_c90amend1}" ]; then
1782 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1783 #include <wchar.h>
1784 int main(void){
1785 wcwidth(L'c');
1786 return 0;
1789 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1792 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1793 #include <langinfo.h>
1794 #include <stdlib.h>
1795 int main(void){
1796 nl_langinfo(DAY_1);
1797 return (nl_langinfo(CODESET) == NULL);
1800 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1801 fi # have_setlocale
1803 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1804 #include <fnmatch.h>
1805 int main(void){
1806 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1810 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1811 #include <dirent.h>
1812 int main(void){
1813 struct dirent de;
1814 return !(de.d_type == DT_UNKNOWN ||
1815 de.d_type == DT_DIR || de.d_type == DT_LNK);
1819 ## optional and selectable
1821 if feat_yes ICONV; then
1822 ${cat} > ${tmp2}.c << \!
1823 #include <stdio.h> /* For C89 NULL */
1824 #include <iconv.h>
1825 int main(void){
1826 iconv_t id;
1828 id = iconv_open("foo", "bar");
1829 iconv(id, NULL, NULL, NULL, NULL);
1830 iconv_close(id);
1831 return 0;
1834 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1835 '#define HAVE_ICONV' ||
1836 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1837 '#define HAVE_ICONV' '-liconv' ||
1838 feat_bail_required ICONV
1839 else
1840 echo '/* OPT_ICONV=0 */' >> ${h}
1841 fi # feat_yes ICONV
1843 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1844 ${cat} > ${tmp2}.c << \!
1845 #include <sys/types.h>
1846 #include <sys/socket.h>
1847 #include <sys/un.h>
1848 # include <errno.h>
1849 int main(void){
1850 struct sockaddr_un soun;
1852 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1853 return 1;
1854 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1855 return 1;
1856 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1857 return 1;
1858 return 0;
1862 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1863 '#define HAVE_UNIX_SOCKETS' ||
1864 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1865 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1866 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1867 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1870 if feat_yes SOCKETS; then
1871 ${cat} > ${tmp2}.c << \!
1872 #include "config.h"
1873 #include <sys/types.h>
1874 #include <sys/socket.h>
1875 #include <netinet/in.h>
1876 # include <errno.h>
1877 int main(void){
1878 struct sockaddr s;
1880 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1881 return 1;
1882 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1883 return 1;
1884 return 0;
1888 < ${tmp2}.c run_check sockets 'sockets' \
1889 '#define HAVE_SOCKETS' ||
1890 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1891 '#define HAVE_SOCKETS' '-lnsl' ||
1892 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1893 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1894 feat_bail_required SOCKETS
1895 else
1896 echo '/* OPT_SOCKETS=0 */' >> ${h}
1897 fi # feat_yes SOCKETS
1899 if feat_yes SOCKETS; then
1900 link_check getaddrinfo 'getaddrinfo(3)' \
1901 '#define HAVE_GETADDRINFO' << \!
1902 #include "config.h"
1903 #include <sys/types.h>
1904 #include <sys/socket.h>
1905 #include <stdio.h>
1906 #include <netdb.h>
1907 int main(void){
1908 struct addrinfo a, *ap;
1909 int lrv;
1911 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1912 case EAI_NONAME:
1913 case EAI_SERVICE:
1914 default:
1915 fprintf(stderr, "%s\n", gai_strerror(lrv));
1916 case 0:
1917 break;
1919 return 0;
1924 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1925 compile_check arpa_inet_h '<arpa/inet.h>' \
1926 '#define HAVE_ARPA_INET_H' << \!
1927 #include "config.h"
1928 #include <sys/types.h>
1929 #include <sys/socket.h>
1930 #include <netdb.h>
1931 #include <netinet/in.h>
1932 #include <arpa/inet.h>
1935 ${cat} > ${tmp2}.c << \!
1936 #include "config.h"
1937 #include <sys/types.h>
1938 #include <sys/socket.h>
1939 #include <stdio.h>
1940 #include <string.h>
1941 #include <netdb.h>
1942 #include <netinet/in.h>
1943 #ifdef HAVE_ARPA_INET_H
1944 #include <arpa/inet.h>
1945 #endif
1946 int main(void){
1947 struct sockaddr_in servaddr;
1948 unsigned short portno;
1949 struct servent *ep;
1950 struct hostent *hp;
1951 struct in_addr **pptr;
1953 portno = 0;
1954 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1955 portno = (unsigned short)ep->s_port;
1957 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1958 pptr = (struct in_addr**)hp->h_addr_list;
1959 if(hp->h_addrtype != AF_INET)
1960 fprintf(stderr, "au\n");
1961 }else{
1962 switch(h_errno){
1963 case HOST_NOT_FOUND:
1964 case TRY_AGAIN:
1965 case NO_RECOVERY:
1966 case NO_DATA:
1967 break;
1968 default:
1969 fprintf(stderr, "au\n");
1970 break;
1974 memset(&servaddr, 0, sizeof servaddr);
1975 servaddr.sin_family = AF_INET;
1976 servaddr.sin_port = htons(portno);
1977 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1978 fprintf(stderr, "Would connect to %s:%d ...\n",
1979 inet_ntoa(**pptr), (int)portno);
1980 return 0;
1984 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1985 < ${tmp2}.c link_check gethostbyname \
1986 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1987 < ${tmp2}.c link_check gethostbyname \
1988 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1989 '' '-lsocket -lnsl' ||
1990 feat_bail_required SOCKETS
1993 feat_yes SOCKETS &&
1994 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1995 #include <sys/socket.h>
1996 #include <stdlib.h>
1997 # include <errno.h>
1998 int main(void){
1999 int sockfd = 3;
2001 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2002 errno == ENOSYS)
2003 return 1;
2004 return 0;
2008 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2009 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2010 #include <sys/socket.h>
2011 #include <stdlib.h>
2012 int main(void){
2013 struct timeval tv;
2014 int sockfd = 3;
2016 tv.tv_sec = 42;
2017 tv.tv_usec = 21;
2018 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2019 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2020 return 0;
2024 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2025 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2026 #include <sys/socket.h>
2027 #include <stdlib.h>
2028 int main(void){
2029 struct linger li;
2030 int sockfd = 3;
2032 li.l_onoff = 1;
2033 li.l_linger = 42;
2034 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2035 return 0;
2039 if feat_yes SSL; then # {{{
2040 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2041 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2042 # time: we need to test it first in order to get things right
2043 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2044 '#define HAVE_SSL
2045 #define HAVE_XSSL
2046 #define HAVE_XSSL_RESSL
2047 #define HAVE_XSSL_OPENSSL 0' << \!
2048 #include <openssl/opensslv.h>
2049 #ifdef LIBRESSL_VERSION_NUMBER
2050 #else
2051 # error nope
2052 #endif
2054 then
2055 ossl_v1_1=
2056 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2057 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2058 '#define HAVE_SSL
2059 #define HAVE_XSSL
2060 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2061 #include <openssl/opensslv.h>
2062 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2063 #else
2064 # error nope
2065 #endif
2067 then
2068 ossl_v1_1=1
2069 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2070 '#define HAVE_SSL
2071 #define HAVE_XSSL
2072 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2073 #include <openssl/opensslv.h>
2074 #ifdef OPENSSL_VERSION_NUMBER
2075 #else
2076 # error nope
2077 #endif
2079 then
2080 ossl_v1_1=
2081 else
2082 feat_bail_required SSL
2083 fi # }}}
2085 if feat_yes SSL; then # {{{
2086 if [ -n "${ossl_v1_1}" ]; then
2087 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2088 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2089 '-lssl -lcrypto'
2090 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2091 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2092 '-lssl -lcrypto' << \!
2093 #include <openssl/ssl.h>
2094 #include <openssl/err.h>
2095 #include <openssl/x509v3.h>
2096 #include <openssl/x509.h>
2097 #include <openssl/rand.h>
2098 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2099 # error We need TLSv1.
2100 #endif
2101 int main(void){
2102 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2104 SSL_CTX_free(ctx);
2105 PEM_read_PrivateKey(0, 0, 0, 0);
2106 return 0;
2109 then
2111 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2112 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2113 '-lssl -lcrypto' << \!
2114 #include <openssl/ssl.h>
2115 #include <openssl/err.h>
2116 #include <openssl/x509v3.h>
2117 #include <openssl/x509.h>
2118 #include <openssl/rand.h>
2119 #if defined OPENSSL_NO_SSL3 &&\
2120 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2121 # error We need one of SSLv3 and TLSv1.
2122 #endif
2123 int main(void){
2124 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2126 SSL_CTX_free(ctx);
2127 PEM_read_PrivateKey(0, 0, 0, 0);
2128 return 0;
2131 then
2133 else
2134 feat_bail_required SSL
2136 fi # }}}
2138 if feat_yes SSL; then # {{{
2139 if [ -n "${ossl_v1_1}" ]; then
2140 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2141 '#define HAVE_XSSL_STACK_OF'
2142 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2143 '#define HAVE_XSSL_STACK_OF' << \!
2144 #include <stdio.h> /* For C89 NULL */
2145 #include <openssl/ssl.h>
2146 #include <openssl/err.h>
2147 #include <openssl/x509v3.h>
2148 #include <openssl/x509.h>
2149 #include <openssl/rand.h>
2150 int main(void){
2151 STACK_OF(GENERAL_NAME) *gens = NULL;
2153 printf("%p", gens); /* to use it */
2154 return 0;
2157 then
2161 if [ -n "${ossl_v1_1}" ]; then
2162 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2163 '#define HAVE_XSSL_CONFIG'
2164 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2165 '#define HAVE_XSSL_CONFIG' << \!
2166 #include <stdio.h> /* For C89 NULL */
2167 #include <openssl/conf.h>
2168 int main(void){
2169 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2170 CONF_modules_free();
2171 return 0;
2174 then
2178 if [ -n "${ossl_v1_1}" ]; then
2179 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2180 '#define HAVE_XSSL_CONF_CTX'
2181 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2182 '#define HAVE_XSSL_CONF_CTX' << \!
2183 #include "config.h"
2184 #include <openssl/ssl.h>
2185 #include <openssl/err.h>
2186 int main(void){
2187 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2188 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2190 SSL_CONF_CTX_set_flags(cctx,
2191 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2192 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2193 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2194 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2195 SSL_CONF_CTX_finish(cctx);
2196 SSL_CONF_CTX_free(cctx);
2197 SSL_CTX_free(ctx);
2198 return 0;
2201 then
2205 if [ -n "${ossl_v1_1}" ]; then
2206 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2207 '#define HAVE_XSSL_RAND_EGD'
2208 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2209 '#define HAVE_XSSL_RAND_EGD' << \!
2210 #include <openssl/rand.h>
2211 int main(void){
2212 return RAND_egd("some.where") > 0;
2215 then
2219 if feat_yes SSL_ALL_ALGORITHMS; then
2220 if [ -n "${ossl_v1_1}" ]; then
2221 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2222 '#define HAVE_SSL_ALL_ALGORITHMS'
2223 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2224 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2225 #include <openssl/evp.h>
2226 int main(void){
2227 OpenSSL_add_all_algorithms();
2228 EVP_get_cipherbyname("two cents i never exist");
2229 EVP_cleanup();
2230 return 0;
2233 then
2235 else
2236 feat_bail_required SSL_ALL_ALGORITHMS
2239 fi # feat_yes SSL }}}
2241 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2242 run_check ssl_md5 'MD5 digest in the used crypto library' \
2243 '#define HAVE_XSSL_MD5' << \!
2244 #include <stdlib.h>
2245 #include <string.h>
2246 #include <openssl/md5.h>
2247 int main(void){
2248 char const dat[] = "abrakadabrafidibus";
2249 char dig[16], hex[16 * 2];
2250 MD5_CTX ctx;
2251 size_t i, j;
2253 memset(dig, 0, sizeof(dig));
2254 memset(hex, 0, sizeof(hex));
2255 MD5_Init(&ctx);
2256 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2257 MD5_Final(dig, &ctx);
2259 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2260 for(i = 0; i < sizeof(hex) / 2; i++){
2261 j = i << 1;
2262 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2263 hex[++j] = hexchar(dig[i] & 0x0f);
2265 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2268 fi # }}}
2269 else
2270 echo '/* OPT_SSL=0 */' >> ${h}
2271 fi # }}} feat_yes SSL
2273 if [ "${have_xssl}" = yes ]; then
2274 OPT_SMIME=1
2275 else
2276 OPT_SMIME=0
2279 if feat_yes SMTP; then
2280 echo '#define HAVE_SMTP' >> ${h}
2281 else
2282 echo '/* OPT_SMTP=0 */' >> ${h}
2285 if feat_yes POP3; then
2286 echo '#define HAVE_POP3' >> ${h}
2287 else
2288 echo '/* OPT_POP3=0 */' >> ${h}
2291 if feat_yes GSSAPI; then
2292 ${cat} > ${tmp2}.c << \!
2293 #include <gssapi/gssapi.h>
2294 int main(void){
2295 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2296 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2297 return 0;
2300 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2302 if command -v krb5-config >/dev/null 2>&1; then
2303 i=`command -v krb5-config`
2304 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2305 GSS_INCS="`CFLAGS= ${i} --cflags`"
2306 i='GSS-API via krb5-config(1)'
2307 else
2308 GSS_LIBS='-lgssapi'
2309 GSS_INCS=
2310 i='GSS-API in gssapi/gssapi.h, libgssapi'
2312 if < ${tmp2}.c link_check gss \
2313 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2314 < ${tmp3}.c link_check gss \
2315 'GSS-API in gssapi.h, libgssapi' \
2316 '#define HAVE_GSSAPI
2317 #define GSSAPI_REG_INCLUDE' \
2318 '-lgssapi' ||\
2319 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2320 '#define HAVE_GSSAPI' \
2321 '-lgssapi_krb5' ||\
2322 < ${tmp3}.c link_check gss \
2323 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2324 '#define HAVE_GSSAPI
2325 #define GSS_REG_INCLUDE' \
2326 '-lgssapi -lkrb5 -lcrypto' \
2327 '-I/usr/include/kerberosV' ||\
2328 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2329 '#define HAVE_GSSAPI' \
2330 '-lgss' ||\
2331 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2332 '#define HAVE_GSSAPI
2333 #define GSSAPI_OLD_STYLE' \
2334 '-lgssapi_krb5' << \!
2335 #include <gssapi/gssapi.h>
2336 #include <gssapi/gssapi_generic.h>
2337 int main(void){
2338 gss_import_name(0, 0, gss_nt_service_name, 0);
2339 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2340 return 0;
2343 then
2345 else
2346 feat_bail_required GSSAPI
2348 else
2349 echo '/* OPT_GSSAPI=0 */' >> ${h}
2350 fi # feat_yes GSSAPI
2352 if feat_yes NETRC; then
2353 echo '#define HAVE_NETRC' >> ${h}
2354 else
2355 echo '/* OPT_NETRC=0 */' >> ${h}
2358 if feat_yes AGENT; then
2359 echo '#define HAVE_AGENT' >> ${h}
2360 else
2361 echo '/* OPT_AGENT=0 */' >> ${h}
2364 if feat_yes IDNA; then
2365 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2366 '-lidn' << \!
2367 #include <idna.h>
2368 #include <idn-free.h>
2369 #include <stringprep.h>
2370 int main(void){
2371 char *utf8, *idna_ascii, *idna_utf8;
2373 utf8 = stringprep_locale_to_utf8("does.this.work");
2374 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2375 != IDNA_SUCCESS)
2376 return 1;
2377 idn_free(idna_ascii);
2378 /* (Rather link check only here) */
2379 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2380 return 0;
2383 then
2385 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2386 '-lidnkit' << \!
2387 #include <stdio.h>
2388 #include <idn/api.h>
2389 #include <idn/result.h>
2390 int main(void){
2391 idn_result_t r;
2392 char ace_name[256];
2393 char local_name[256];
2395 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2396 sizeof(ace_name));
2397 if (r != idn_success) {
2398 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2399 return 1;
2401 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2402 if (r != idn_success) {
2403 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2404 return 1;
2406 return 0;
2409 then
2411 else
2412 feat_bail_required IDNA
2415 if [ -n "${have_idna}" ]; then
2416 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2417 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2419 else
2420 echo '/* OPT_IDNA=0 */' >> ${h}
2423 if feat_yes IMAP_SEARCH; then
2424 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2425 else
2426 echo '/* OPT_IMAP_SEARCH=0 */' >> ${h}
2429 if feat_yes REGEX; then
2430 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2431 #include <regex.h>
2432 #include <stdlib.h>
2433 int main(void){
2434 size_t xret;
2435 int status;
2436 regex_t re;
2438 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2439 xret = regerror(status, &re, NULL, 0);
2440 status = regexec(&re, "plan9", 0,NULL, 0);
2441 regfree(&re);
2442 return !(status == REG_NOMATCH);
2445 then
2447 else
2448 feat_bail_required REGEX
2450 else
2451 echo '/* OPT_REGEX=0 */' >> ${h}
2454 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2455 have_mle=1
2456 echo '#define HAVE_MLE' >> ${h}
2457 else
2458 feat_bail_required MLE
2459 echo '/* OPT_MLE=0 */' >> ${h}
2462 # Generic have-a-line-editor switch for those who need it below
2463 if [ -n "${have_mle}" ]; then
2464 have_cle=1
2467 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2468 echo '#define HAVE_HISTORY' >> ${h}
2469 else
2470 echo '/* OPT_HISTORY=0 */' >> ${h}
2473 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2474 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2475 else
2476 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2479 if feat_yes TERMCAP; then
2480 __termcaplib() {
2481 link_check termcap "termcap(5) (via ${4})" \
2482 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2483 #include <stdio.h>
2484 #include <stdlib.h>
2485 ${2}
2486 #include <term.h>
2487 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2488 static int my_putc(int c){return putchar(c);}
2489 int main(void){
2490 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2491 int r2 = OK, r3 = ERR;
2493 tgetent(buf, getenv("TERM"));
2494 cpb = cmdbuf;
2495 r1 = tgetstr(UNCONST("cm"), &cpb);
2496 tgoto(r1, 1, 1);
2497 r2 = tgetnum(UNCONST("Co"));
2498 r3 = tgetflag(UNCONST("ut"));
2499 tputs("cr", 1, &my_putc);
2500 return (r1 == NULL || r2 == -1 || r3 == 0);
2502 _EOT
2505 __terminfolib() {
2506 link_check terminfo "terminfo(5) (via ${2})" \
2507 '#define HAVE_TERMCAP
2508 #define HAVE_TERMCAP_CURSES
2509 #define HAVE_TERMINFO' "${1}" << _EOT
2510 #include <stdio.h>
2511 #include <curses.h>
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 int er, r0, r1, r2;
2517 char *r3, *tp;
2519 er = OK;
2520 r0 = setupterm(NULL, 1, &er);
2521 r1 = tigetflag(UNCONST("bce"));
2522 r2 = tigetnum(UNCONST("colors"));
2523 r3 = tigetstr(UNCONST("cr"));
2524 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2525 tputs(tp, 1, &my_putc);
2526 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2527 r3 == (char*)-1 || r3 == NULL);
2529 _EOT
2532 if feat_yes TERMCAP_VIA_TERMINFO; then
2533 __terminfolib -ltinfo -ltinfo ||
2534 __terminfolib -lcurses -lcurses ||
2535 __terminfolib -lcursesw -lcursesw ||
2536 feat_bail_required TERMCAP_VIA_TERMINFO
2539 if [ -z "${have_terminfo}" ]; then
2540 __termcaplib -ltermcap '' '' '-ltermcap' ||
2541 __termcaplib -ltermcap '#include <curses.h>' '
2542 #define HAVE_TERMCAP_CURSES' \
2543 'curses.h / -ltermcap' ||
2544 __termcaplib -lcurses '#include <curses.h>' '
2545 #define HAVE_TERMCAP_CURSES' \
2546 'curses.h / -lcurses' ||
2547 __termcaplib -lcursesw '#include <curses.h>' '
2548 #define HAVE_TERMCAP_CURSES' \
2549 'curses.h / -lcursesw' ||
2550 feat_bail_required TERMCAP
2552 if [ -n "${have_termcap}" ]; then
2553 run_check tgetent_null \
2554 "tgetent(3) of termcap(5) takes NULL buffer" \
2555 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2556 #include <stdio.h> /* For C89 NULL */
2557 #include <stdlib.h>
2558 #ifdef HAVE_TERMCAP_CURSES
2559 # include <curses.h>
2560 #endif
2561 #include <term.h>
2562 int main(void){
2563 tgetent(NULL, getenv("TERM"));
2564 return 0;
2566 _EOT
2569 else
2570 echo '/* OPT_TERMCAP=0 */' >> ${h}
2571 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2574 if feat_yes SPAM_SPAMC; then
2575 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2576 if command -v spamc >/dev/null 2>&1; then
2577 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2579 else
2580 echo '/* OPT_SPAM_SPAMC=0 */' >> ${h}
2583 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2584 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2585 else
2586 feat_bail_required SPAM_SPAMD
2587 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2590 feat_def SPAM_FILTER
2592 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2593 echo '#define HAVE_SPAM' >> ${h}
2594 else
2595 echo '/* HAVE_SPAM */' >> ${h}
2598 if feat_yes QUOTE_FOLD &&\
2599 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2600 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2601 else
2602 feat_bail_required QUOTE_FOLD
2603 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2606 feat_def FILTER_HTML_TAGSOUP
2607 feat_def COLOUR
2608 feat_def DOTLOCK
2609 feat_def MD5
2610 feat_def NOMEMDBG
2612 ## Summarizing
2614 ${rm} -f ${tmp}
2615 squeeze_em ${inc} ${tmp}
2616 ${mv} ${tmp} ${inc}
2617 squeeze_em ${lib} ${tmp}
2618 ${mv} ${tmp} ${lib}
2620 # config.h
2621 ${mv} ${h} ${tmp}
2622 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2623 ${cat} ${tmp} >> ${h}
2624 ${rm} -f ${tmp}
2625 printf '\n' >> ${h}
2627 # Create the real mk.mk
2628 # Note we cannout use explicit ./ filename prefix for source and object
2629 # pathnames because of a bug in bmake(1)
2630 ${rm} -rf ${tmp0}.* ${tmp0}*
2631 printf 'OBJ_SRC = ' >> ${mk}
2632 if feat_no AMALGAMATION; then
2633 for i in `printf '%s\n' *.c | ${sort}`; do
2634 if [ "${i}" = privsep.c ]; then
2635 continue
2637 printf "${i} " >> ${mk}
2638 done
2639 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2640 else
2641 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2643 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2644 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2645 printf '# undef _CONFIG_H\n' >> ${h}
2646 printf '# define _CONFIG_H 2\n' >> ${h}
2647 for i in `printf '%s\n' *.c | ${sort}`; do
2648 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2649 [ "${i}" = privsep.c ]; then
2650 continue
2652 printf "${i} " >> ${mk}
2653 printf "# include \"${i}\"\n" >> ${h}
2654 done
2655 echo >> ${mk}
2656 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2657 echo '#else' >> ${h}
2660 # Finally, create the string that is used by *features* and `version'.
2661 # Take this nice opportunity and generate a visual listing of included and
2662 # non-included features for the person who runs the configuration
2663 msg '\nThe following features are included (+) or not (-):'
2664 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2665 printf '/* The "feature string" */\n' >> ${h}
2666 # Because + is expanded by *folder* if first in "echo $features", put something
2667 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2668 sep=
2669 for opt
2671 sdoc=`option_doc_of ${opt}`
2672 [ -z "${sdoc}" ] && continue
2673 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2674 feat_yes ${opt} && sign=+ || sign=-
2675 printf -- "${sep}${sign}${sopt}" >> ${h}
2676 sep=','
2677 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2678 done
2679 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2680 #exec 5>&1 >>${h}
2681 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2682 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2684 printf '"\n#endif /* n_CONFIG_H */\n' >> ${h}
2686 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2687 echo "INCS = `${cat} ${inc}`" >> ${mk}
2688 echo >> ${mk}
2689 ${cat} ./mk-mk.in >> ${mk}
2691 ## Finished!
2693 msg '\nSetup:'
2694 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2695 msg ' . bindir: %s' "${VAL_BINDIR}"
2696 if feat_yes DOTLOCK; then
2697 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2699 msg ' . mandir: %s' "${VAL_MANDIR}"
2700 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2701 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2702 msg ''
2704 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2705 exit 0
2707 msg 'Remarks:'
2708 if [ -z "${have_fnmatch}" ]; then
2709 msg ' . The function fnmatch(3) could not be found.'
2710 msg ' Filename patterns like wildcard are not supported on your system'
2712 if [ -z "${have_fchdir}" ]; then
2713 msg ' . The function fchdir(2) could not be found.'
2714 msg ' We will use chdir(2) instead.'
2715 msg ' This is a problem only if the current working directory is changed'
2716 msg ' while this program is inside of it'
2718 msg ''
2720 # s-it-mode