More or less completely rewrite mime_enc.c..
[s-mailx.git] / mk-conf.sh
blob079d5cb910d61089e1521ba472810c925a09036f
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: most likely for
10 # 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 compile_check() {
884 variable=$1 topic=$2 define=$3
886 _check_preface "${variable}" "${topic}" "${define}"
888 if ${make} -f ${makefile} XINCS="${INCS}" \
889 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
890 ./${tmp}.o &&
891 [ -f ./${tmp}.o ]; then
892 msg 'yes'
893 echo "${define}" >> ${h}
894 eval have_${variable}=yes
895 return 0
896 else
897 echo "/* ${define} */" >> ${h}
898 msg 'no'
899 eval unset have_${variable}
900 return 1
904 _link_mayrun() {
905 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
907 _check_preface "${variable}" "${topic}" "${define}"
909 feat_yes CROSS_BUILD && run=0
911 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
912 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
913 XLIBS="${LIBS} ${libs}" \
914 ./${tmp} &&
915 [ -f ./${tmp} ] &&
916 { [ ${run} -eq 0 ] || ./${tmp}; }; then
917 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
918 msg 'yes'
919 echo "${define}" >> ${h}
920 LIBS="${LIBS} ${libs}"
921 echo "${libs}" >> ${lib}
922 INCS="${INCS} ${incs}"
923 echo "${incs}" >> ${inc}
924 eval have_${variable}=yes
925 return 0
926 else
927 msg 'no'
928 echo "/* ${define} */" >> ${h}
929 eval unset have_${variable}
930 return 1
934 link_check() {
935 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
938 run_check() {
939 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
942 feat_def() {
943 if feat_yes ${1}; then
944 echo '#define HAVE_'${1}'' >> ${h}
945 else
946 echo '/* OPT_'${1}'=0 */' >> ${h}
950 squeeze_em() {
951 < "${1}" > "${2}" ${awk} \
952 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
955 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
957 # First of all, create new configuration and check whether it changed
959 # Very easy checks for the operating system in order to be able to adjust paths
960 # or similar very basic things which we need to be able to go at all
961 os_early_setup
963 # Check those tools right now that we need before including $rc
964 msg 'Checking for basic utility set'
965 check_tool awk "${awk:-`command -v awk`}"
966 check_tool rm "${rm:-`command -v rm`}"
967 check_tool tr "${tr:-`command -v tr`}"
969 # Initialize the option set
970 msg_nonl 'Setting up configuration options ... '
971 option_setup
972 msg 'done'
974 # Include $rc, but only take from it what wasn't overwritten by the user from
975 # within the command line or from a chosen fixed CONFIG=
976 # Note we leave alone the values
977 trap "exit 1" HUP INT TERM
978 trap "${rm} -f ${tmp}" EXIT
980 msg_nonl 'Joining in %s ... ' ${rc}
981 option_join_rc
982 msg 'done'
984 # We need to know about that now, in order to provide utility overwrites etc.
985 os_setup
987 msg 'Checking for remaining set of utilities'
988 check_tool grep "${grep:-`command -v grep`}"
990 # Before we step ahead with the other utilities perform a path cleanup first.
991 path_check PATH
993 # awk(1) above
994 check_tool cat "${cat:-`command -v cat`}"
995 check_tool chmod "${chmod:-`command -v chmod`}"
996 check_tool cp "${cp:-`command -v cp`}"
997 check_tool cmp "${cmp:-`command -v cmp`}"
998 # grep(1) above
999 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1000 check_tool mv "${mv:-`command -v mv`}"
1001 # rm(1) above
1002 check_tool sed "${sed:-`command -v sed`}"
1003 check_tool sort "${sort:-`command -v sort`}"
1004 check_tool tee "${tee:-`command -v tee`}"
1006 check_tool chown "${chown:-`command -v chown`}" 1 ||
1007 check_tool chown "/sbin/chown" 1 ||
1008 check_tool chown "/usr/sbin/chown"
1010 check_tool make "${MAKE:-`command -v make`}"
1011 MAKE=${make}
1012 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1013 HAVE_STRIP=1 || HAVE_STRIP=0
1015 # For ./cc-test.sh only
1016 check_tool cksum "${cksum:-`command -v cksum`}"
1018 # Update OPT_ options now, in order to get possible inter-dependencies right
1019 option_update
1021 # (No functions since some shells loose non-exported variables in traps)
1022 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1023 trap "trap \"\" HUP INT TERM EXIT;\
1024 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1026 # Our configuration options may at this point still contain shell snippets,
1027 # we need to evaluate them in order to get them expanded, and we need those
1028 # evaluated values not only in our new configuration file, but also at hand..
1029 msg_nonl 'Evaluating all configuration items ... '
1030 option_evaluate
1031 msg 'done'
1033 # Add the known utility and some other variables
1034 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_NAIL}\"\n" >> ${newh}
1035 printf "VAL_UAGENT = ${VAL_SID}${VAL_NAIL}\n" >> ${newmk}
1037 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_NAIL}-privsep\"\n" >> ${newh}
1038 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1039 if feat_yes DOTLOCK; then
1040 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1041 else
1042 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1045 for i in \
1046 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1047 MAKE MAKEFLAGS make SHELL strip \
1048 cksum; do
1049 eval j=\$${i}
1050 printf "${i} = ${j}\n" >> ${newmk}
1051 printf "${i}=${j}\n" >> ${newlst}
1052 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1053 done
1054 printf "\n" >> ${newev}
1056 # Build a basic set of INCS and LIBS according to user environment.
1057 path_check C_INCLUDE_PATH -I _INCS
1058 INCS="${INCS} ${_INCS}"
1059 path_check LD_LIBRARY_PATH -L _LIBS
1060 LIBS="${LIBS} ${_LIBS}"
1061 unset _INCS _LIBS
1062 export C_INCLUDE_PATH LD_LIBRARY_PATH
1064 # Some environments need runtime path flags to be able to go at all
1065 ld_runtime_flags
1067 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1069 cc_setup
1071 ${cat} > ${tmp}.c << \!
1072 #include <stdio.h>
1073 #include <string.h>
1074 static void doit(char const *s);
1076 main(int argc, char **argv){
1077 (void)argc;
1078 (void)argv;
1079 doit("Hello world");
1080 return 0;
1082 static void
1083 doit(char const *s){
1084 char buf[12];
1085 memcpy(buf, s, strlen(s) +1);
1086 puts(s);
1090 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1091 -o ${tmp2} ${tmp}.c ${LIBS}; then
1093 else
1094 msg 'ERROR: i cannot compile a "Hello world" via'
1095 msg ' %s' \
1096 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1097 msg 'ERROR: Please read INSTALL, rerun'
1098 config_exit 1
1101 # This may also update ld_runtime_flags() (again)
1102 cc_flags
1104 for i in \
1105 INCS LIBS \
1106 ; do
1107 eval j=\$${i}
1108 printf -- "${i}=${j}\n" >> ${newlst}
1109 done
1110 for i in \
1111 CC \
1112 CFLAGS \
1113 LDFLAGS \
1114 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1115 OSFULLSPEC \
1116 ; do
1117 eval j=\$${i}
1118 printf -- "${i} = ${j}\n" >> ${newmk}
1119 printf -- "${i}=${j}\n" >> ${newlst}
1120 done
1122 # Now finally check whether we already have a configuration and if so, whether
1123 # all those parameters are still the same.. or something has actually changed
1124 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1125 echo 'Configuration is up-to-date'
1126 exit 0
1127 elif [ -f ${lst} ]; then
1128 echo 'Configuration has been updated..'
1129 ( eval "${MAKE} -f ./mk.mk clean" )
1130 echo
1131 else
1132 echo 'Shiny configuration..'
1135 # Time to redefine helper 1
1136 config_exit() {
1137 ${rm} -f ${lst} ${h} ${mk}
1138 exit ${1}
1141 ${mv} -f ${newlst} ${lst}
1142 ${mv} -f ${newev} ${ev}
1143 ${mv} -f ${newh} ${h}
1144 ${mv} -f ${newmk} ${mk}
1146 if [ -z "${VERBOSE}" ]; then
1147 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1148 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1149 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1150 printf -- "ECHO_TEST = @\n" >> ${mk}
1151 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1152 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1153 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1156 ## Compile and link checking
1158 tmp3=./${tmp0}3$$
1159 log=./config.log
1160 lib=./config.lib
1161 inc=./config.inc
1162 makefile=./config.mk
1164 # (No function since some shells loose non-exported variables in traps)
1165 trap "trap \"\" HUP INT TERM;\
1166 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1167 trap "trap \"\" HUP INT TERM EXIT;\
1168 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
1170 # Time to redefine helper 2
1171 msg() {
1172 fmt=${1}
1173 shift
1174 printf "*** ${fmt}\\n" "${@}"
1175 printf -- "${fmt}\\n" "${@}" >&5
1177 msg_nonl() {
1178 fmt=${1}
1179 shift
1180 printf "*** ${fmt}\\n" "${@}"
1181 printf -- "${fmt}" "${@}" >&5
1184 # !!
1185 exec 5>&2 > ${log} 2>&1
1187 echo "${LIBS}" > ${lib}
1188 echo "${INCS}" > ${inc}
1189 ${cat} > ${makefile} << \!
1190 .SUFFIXES: .o .c .x .y
1191 .c.o:
1192 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1193 .c.x:
1194 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1196 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1199 ## Generics
1201 # May be multiline..
1202 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1204 feat_def ALWAYS_UNICODE_LOCALE
1205 feat_def AMALGAMATION
1206 feat_def CROSS_BUILD
1207 feat_def DEBUG
1208 feat_def DEVEL
1209 feat_def DOCSTRINGS
1210 feat_def ERRORS
1211 feat_def NYD2
1212 feat_def NOMEMDBG
1214 if run_check inline 'inline functions' \
1215 '#define HAVE_INLINE
1216 #define n_INLINE static inline' << \!
1217 static inline int ilf(int i){return ++i;}
1218 int main(void){return ilf(-1);}
1220 then
1222 elif run_check inline 'inline functions (via __inline)' \
1223 '#define HAVE_INLINE
1224 #define n_INLINE static __inline' << \!
1225 static __inline int ilf(int i){return ++i;}
1226 int main(void){return ilf(-1);}
1228 then
1232 if run_check endian 'Little endian byteorder' \
1233 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1234 int main(void){
1235 enum {vBig = 1, vLittle = 0};
1236 union {unsigned short bom; unsigned char buf[2];} u;
1237 u.bom = 0xFEFF;
1238 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1241 then
1245 ## Test for "basic" system-calls / functionality that is used by all parts
1246 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1247 ## macros to be used by only the subprograms (potentially).
1249 if run_check clock_gettime 'clock_gettime(2)' \
1250 '#define HAVE_CLOCK_GETTIME' << \!
1251 #include <time.h>
1252 # include <errno.h>
1253 int main(void){
1254 struct timespec ts;
1256 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1257 return 0;
1258 return 1;
1261 then
1263 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1264 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1265 #include <time.h>
1266 # include <errno.h>
1267 int main(void){
1268 struct timespec ts;
1270 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1271 return 0;
1272 return 1;
1275 then
1277 elif run_check gettimeofday 'gettimeofday(2)' \
1278 '#define HAVE_GETTIMEOFDAY' << \!
1279 #include <stdio.h> /* For C89 NULL */
1280 #include <sys/time.h>
1281 # include <errno.h>
1282 int main(void){
1283 struct timeval tv;
1285 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1286 return 0;
1287 return 1;
1290 then
1292 else
1293 have_no_subsecond_time=1
1296 if run_check nanosleep 'nanosleep(2)' \
1297 '#define HAVE_NANOSLEEP' << \!
1298 #include <time.h>
1299 # include <errno.h>
1300 int main(void){
1301 struct timespec ts;
1303 ts.tv_sec = 1;
1304 ts.tv_nsec = 100000;
1305 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1306 return 0;
1307 return 1;
1310 then
1312 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1313 '#define HAVE_NANOSLEEP' '-lrt' << \!
1314 #include <time.h>
1315 # include <errno.h>
1316 int main(void){
1317 struct timespec ts;
1319 ts.tv_sec = 1;
1320 ts.tv_nsec = 100000;
1321 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1322 return 0;
1323 return 1;
1326 then
1328 # link_check is enough for this, that function is so old, trust the proto
1329 elif link_check sleep 'sleep(3)' \
1330 '#define HAVE_SLEEP' << \!
1331 #include <unistd.h>
1332 # include <errno.h>
1333 int main(void){
1334 if(!sleep(1) || errno != ENOSYS)
1335 return 0;
1336 return 1;
1339 then
1341 else
1342 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1343 config_exit 1
1346 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1347 #include <pwd.h>
1348 #include <unistd.h>
1349 # include <errno.h>
1350 int main(void){
1351 struct passwd *pw;
1352 gid_t gid;
1353 uid_t uid;
1355 if((gid = getgid()) != 0)
1356 gid = getegid();
1357 if((uid = getuid()) != 0)
1358 uid = geteuid();
1359 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1360 return 1;
1361 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1362 return 1;
1363 return 0;
1366 then
1368 else
1369 msg 'ERROR: we require user and group info / database searches.'
1370 msg 'That much Unix we indulge ourselfs.'
1371 config_exit 1
1374 if link_check ftruncate 'ftruncate(2)' \
1375 '#define HAVE_FTRUNCATE' << \!
1376 #include <unistd.h>
1377 #include <sys/types.h>
1378 int main(void){
1379 return (ftruncate(0, 0) != 0);
1382 then
1384 else
1385 msg 'ERROR: we require the ftruncate(2) system call.'
1386 config_exit 1
1389 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1390 #include <signal.h>
1391 # include <errno.h>
1392 int main(void){
1393 struct sigaction nact, oact;
1395 nact.sa_handler = SIG_DFL;
1396 sigemptyset(&nact.sa_mask);
1397 nact.sa_flags = SA_RESTART;
1398 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1401 then
1403 else
1404 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1405 config_exit 1
1408 if link_check snprintf 'snprintf(3)' << \!
1409 #include <stdio.h>
1410 int main(void){
1411 char b[20];
1413 snprintf(b, sizeof b, "%s", "string");
1414 return 0;
1417 then
1419 else
1420 msg 'ERROR: we require the snprintf(3) function.'
1421 config_exit 1
1424 if link_check environ 'environ(3)' << \!
1425 #include <stdio.h> /* For C89 NULL */
1426 int main(void){
1427 extern char **environ;
1429 return environ[0] == NULL;
1432 then
1434 else
1435 msg 'ERROR: we require the environ(3) array for subprocess control.'
1436 config_exit 1
1439 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1440 #include <stdlib.h>
1441 int main(void){
1442 setenv("s-mailx", "i want to see it cute!", 1);
1443 unsetenv("s-mailx");
1444 return 0;
1447 then
1449 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1450 #include <stdlib.h>
1451 int main(void){
1452 putenv("s-mailx=i want to see it cute!");
1453 return 0;
1456 then
1458 else
1459 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1460 config_exit 1
1463 if link_check termios 'termios.h and tc*(3) family' << \!
1464 #include <termios.h>
1465 int main(void){
1466 struct termios tios;
1468 tcgetattr(0, &tios);
1469 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1470 return 0;
1473 then
1475 else
1476 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1477 msg 'That much Unix we indulge ourselfs.'
1478 config_exit 1
1481 ## optional stuff
1483 if link_check vsnprintf 'vsnprintf(3)' << \!
1484 #include <stdarg.h>
1485 #include <stdio.h>
1486 static void dome(char *buf, size_t blen, ...){
1487 va_list ap;
1489 va_start(ap, blen);
1490 vsnprintf(buf, blen, "%s", ap);
1491 va_end(ap);
1493 int main(void){
1494 char b[20];
1496 dome(b, sizeof b, "string");
1497 return 0;
1500 then
1502 else
1503 feat_bail_required ERRORS
1506 if [ "${have_vsnprintf}" = yes ]; then
1507 __va_copy() {
1508 link_check va_copy "va_copy(3) (as ${2})" \
1509 "#define HAVE_N_VA_COPY
1510 #define n_va_copy ${2}" <<_EOT
1511 #include <stdarg.h>
1512 #include <stdio.h>
1513 #if ${1}
1514 # if defined __va_copy && !defined va_copy
1515 # define va_copy __va_copy
1516 # endif
1517 #endif
1518 static void dome2(char *buf, size_t blen, va_list src){
1519 va_list ap;
1521 va_copy(ap, src);
1522 vsnprintf(buf, blen, "%s", ap);
1523 va_end(ap);
1525 static void dome(char *buf, size_t blen, ...){
1526 va_list ap;
1528 va_start(ap, blen);
1529 dome2(buf, blen, ap);
1530 va_end(ap);
1532 int main(void){
1533 char b[20];
1535 dome(b, sizeof b, "string");
1536 return 0;
1538 _EOT
1540 __va_copy 0 va_copy || __va_copy 1 __va_copy
1543 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1544 #include <unistd.h>
1545 #include <errno.h>
1546 int main(void){
1547 int rv = 0;
1549 errno = 0;
1550 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1551 errno = 0;
1552 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1554 /* Only link check */
1555 fpathconf(0, _PC_NAME_MAX);
1557 return rv;
1561 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1562 #include <fcntl.h>
1563 #include <unistd.h>
1564 # include <errno.h>
1565 int main(void){
1566 int fds[2];
1568 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1569 return 0;
1570 return 1;
1574 # We use this only then for now (need NOW+1)
1575 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1576 #include <fcntl.h> /* For AT_* */
1577 #include <sys/stat.h>
1578 # include <errno.h>
1579 int main(void){
1580 struct timespec ts[2];
1582 ts[0].tv_nsec = UTIME_NOW;
1583 ts[1].tv_nsec = UTIME_OMIT;
1584 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1585 return 0;
1586 return 1;
1592 # XXX Add POSIX check once standardized
1593 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1594 #include <stdlib.h>
1595 int main(void){
1596 arc4random();
1597 return 0;
1600 then
1602 elif [ -n "${have_no_subsecond_time}" ]; then
1603 msg 'ERROR: %s %s' 'without a native random' \
1604 'one of clock_gettime(2) and gettimeofday(2) is required.'
1605 config_exit 1
1608 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1609 #include <stdio.h>
1610 int main(void){
1611 putc_unlocked('@', stdout);
1612 return 0;
1616 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1617 #include <unistd.h>
1618 int main(void){
1619 fchdir(0);
1620 return 0;
1624 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1625 #include <stdlib.h>
1626 int main(void){
1627 char x_buf[4096], *x = realpath(".", x_buf);
1629 return (x != NULL) ? 0 : 1;
1632 then
1633 if run_check realpath_malloc 'realpath(3) takes NULL' \
1634 '#define HAVE_REALPATH_NULL' << \!
1635 #include <stdlib.h>
1636 int main(void){
1637 char *x = realpath(".", NULL);
1639 if(x != NULL)
1640 free(x);
1641 return (x != NULL) ? 0 : 1;
1644 then
1649 ## optional and selectable
1651 if feat_yes DOTLOCK; then
1652 if run_check readlink 'readlink(2)' << \!
1653 #include <unistd.h>
1654 # include <errno.h>
1655 int main(void){
1656 char buf[128];
1658 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1659 return 0;
1660 return 1;
1663 then
1665 else
1666 feat_bail_required DOTLOCK
1670 if feat_yes DOTLOCK; then
1671 if run_check fchown 'fchown(2)' << \!
1672 #include <unistd.h>
1673 # include <errno.h>
1674 int main(void){
1675 if(!fchown(0, 0, 0) || errno != ENOSYS)
1676 return 0;
1677 return 1;
1680 then
1682 else
1683 feat_bail_required DOTLOCK
1687 ## Now it is the time to fork away the BASE_ series
1689 ${rm} -f ${tmp}
1690 squeeze_em ${inc} ${tmp}
1691 ${mv} ${tmp} ${inc}
1692 squeeze_em ${lib} ${tmp}
1693 ${mv} ${tmp} ${lib}
1695 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1696 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1698 ## The remains are expected to be used only by the main MUA binary!
1700 OPT_LOCALES=0
1701 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1702 #include <locale.h>
1703 int main(void){
1704 setlocale(LC_ALL, "");
1705 return 0;
1708 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1710 OPT_MULTIBYTE_CHARSETS=0
1711 OPT_WIDE_GLYPHS=0
1712 OPT_TERMINAL_CHARSET=0
1713 if [ -n "${have_setlocale}" ]; then
1714 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1715 '#define HAVE_C90AMEND1' << \!
1716 #include <limits.h>
1717 #include <stdlib.h>
1718 #include <wchar.h>
1719 #include <wctype.h>
1720 int main(void){
1721 char mbb[MB_LEN_MAX + 1];
1722 wchar_t wc;
1724 iswprint(L'c');
1725 towupper(L'c');
1726 mbtowc(&wc, "x", 1);
1727 mbrtowc(&wc, "x", 1, NULL);
1728 wctomb(mbb, wc);
1729 return (mblen("\0", 1) == 0);
1732 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1734 if [ -n "${have_c90amend1}" ]; then
1735 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1736 #include <wchar.h>
1737 int main(void){
1738 wcwidth(L'c');
1739 return 0;
1742 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1745 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1746 #include <langinfo.h>
1747 #include <stdlib.h>
1748 int main(void){
1749 nl_langinfo(DAY_1);
1750 return (nl_langinfo(CODESET) == NULL);
1753 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1754 fi # have_setlocale
1756 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1757 #include <fnmatch.h>
1758 int main(void){
1759 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1763 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1764 #include <dirent.h>
1765 int main(void){
1766 struct dirent de;
1767 return !(de.d_type == DT_UNKNOWN ||
1768 de.d_type == DT_DIR || de.d_type == DT_LNK);
1772 ## optional and selectable
1774 if feat_yes ICONV; then
1775 ${cat} > ${tmp2}.c << \!
1776 #include <stdio.h> /* For C89 NULL */
1777 #include <iconv.h>
1778 int main(void){
1779 iconv_t id;
1781 id = iconv_open("foo", "bar");
1782 iconv(id, NULL, NULL, NULL, NULL);
1783 iconv_close(id);
1784 return 0;
1787 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1788 '#define HAVE_ICONV' ||
1789 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1790 '#define HAVE_ICONV' '-liconv' ||
1791 feat_bail_required ICONV
1792 else
1793 echo '/* OPT_ICONV=0 */' >> ${h}
1794 fi # feat_yes ICONV
1796 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1797 ${cat} > ${tmp2}.c << \!
1798 #include <sys/types.h>
1799 #include <sys/socket.h>
1800 #include <sys/un.h>
1801 # include <errno.h>
1802 int main(void){
1803 struct sockaddr_un soun;
1805 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1806 return 1;
1807 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1808 return 1;
1809 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1810 return 1;
1811 return 0;
1815 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1816 '#define HAVE_UNIX_SOCKETS' ||
1817 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1818 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1819 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1820 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1823 if feat_yes SOCKETS; then
1824 ${cat} > ${tmp2}.c << \!
1825 #include "config.h"
1826 #include <sys/types.h>
1827 #include <sys/socket.h>
1828 #include <netinet/in.h>
1829 # include <errno.h>
1830 int main(void){
1831 struct sockaddr s;
1833 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1834 return 1;
1835 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1836 return 1;
1837 return 0;
1841 < ${tmp2}.c run_check sockets 'sockets' \
1842 '#define HAVE_SOCKETS' ||
1843 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1844 '#define HAVE_SOCKETS' '-lnsl' ||
1845 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1846 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1847 feat_bail_required SOCKETS
1848 else
1849 echo '/* OPT_SOCKETS=0 */' >> ${h}
1850 fi # feat_yes SOCKETS
1852 if feat_yes SOCKETS; then
1853 link_check getaddrinfo 'getaddrinfo(3)' \
1854 '#define HAVE_GETADDRINFO' << \!
1855 #include "config.h"
1856 #include <sys/types.h>
1857 #include <sys/socket.h>
1858 #include <stdio.h>
1859 #include <netdb.h>
1860 int main(void){
1861 struct addrinfo a, *ap;
1862 int lrv;
1864 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1865 case EAI_NONAME:
1866 case EAI_SERVICE:
1867 default:
1868 fprintf(stderr, "%s\n", gai_strerror(lrv));
1869 case 0:
1870 break;
1872 return 0;
1877 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1878 compile_check arpa_inet_h '<arpa/inet.h>' \
1879 '#define HAVE_ARPA_INET_H' << \!
1880 #include "config.h"
1881 #include <sys/types.h>
1882 #include <sys/socket.h>
1883 #include <netdb.h>
1884 #include <netinet/in.h>
1885 #include <arpa/inet.h>
1888 ${cat} > ${tmp2}.c << \!
1889 #include "config.h"
1890 #include <sys/types.h>
1891 #include <sys/socket.h>
1892 #include <stdio.h>
1893 #include <string.h>
1894 #include <netdb.h>
1895 #include <netinet/in.h>
1896 #ifdef HAVE_ARPA_INET_H
1897 #include <arpa/inet.h>
1898 #endif
1899 int main(void){
1900 struct sockaddr_in servaddr;
1901 unsigned short portno;
1902 struct servent *ep;
1903 struct hostent *hp;
1904 struct in_addr **pptr;
1906 portno = 0;
1907 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1908 portno = (unsigned short)ep->s_port;
1910 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1911 pptr = (struct in_addr**)hp->h_addr_list;
1912 if(hp->h_addrtype != AF_INET)
1913 fprintf(stderr, "au\n");
1914 }else{
1915 switch(h_errno){
1916 case HOST_NOT_FOUND:
1917 case TRY_AGAIN:
1918 case NO_RECOVERY:
1919 case NO_DATA:
1920 break;
1921 default:
1922 fprintf(stderr, "au\n");
1923 break;
1927 memset(&servaddr, 0, sizeof servaddr);
1928 servaddr.sin_family = AF_INET;
1929 servaddr.sin_port = htons(portno);
1930 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1931 fprintf(stderr, "Would connect to %s:%d ...\n",
1932 inet_ntoa(**pptr), (int)portno);
1933 return 0;
1937 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1938 < ${tmp2}.c link_check gethostbyname \
1939 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1940 < ${tmp2}.c link_check gethostbyname \
1941 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1942 '' '-lsocket -lnsl' ||
1943 feat_bail_required SOCKETS
1946 feat_yes SOCKETS &&
1947 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1948 #include <sys/socket.h>
1949 #include <stdlib.h>
1950 # include <errno.h>
1951 int main(void){
1952 int sockfd = 3;
1954 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1955 errno == ENOSYS)
1956 return 1;
1957 return 0;
1961 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1962 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1963 #include <sys/socket.h>
1964 #include <stdlib.h>
1965 int main(void){
1966 struct timeval tv;
1967 int sockfd = 3;
1969 tv.tv_sec = 42;
1970 tv.tv_usec = 21;
1971 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1972 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1973 return 0;
1977 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1978 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1979 #include <sys/socket.h>
1980 #include <stdlib.h>
1981 int main(void){
1982 struct linger li;
1983 int sockfd = 3;
1985 li.l_onoff = 1;
1986 li.l_linger = 42;
1987 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1988 return 0;
1992 if feat_yes SSL; then
1993 if link_check ssl_tls 'TLS/SSL (new style *_client_method(3ssl))' \
1994 '#define HAVE_SSL
1995 #define HAVE_SSL_TLS 10100' '-lssl -lcrypto' << \!
1996 #include <openssl/ssl.h>
1997 #include <openssl/err.h>
1998 #include <openssl/x509v3.h>
1999 #include <openssl/x509.h>
2000 #include <openssl/rand.h>
2001 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2002 # error We need TLSv1.
2003 #endif
2004 int main(void){
2005 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2007 SSL_CTX_free(ctx);
2008 PEM_read_PrivateKey(0, 0, 0, 0);
2009 return 0;
2012 then
2014 elif link_check ssl_tls 'TLS/SSL (old style *_client_method(3ssl))' \
2015 '#define HAVE_SSL
2016 #define HAVE_SSL_TLS 10000' '-lssl -lcrypto' << \!
2017 #include <openssl/ssl.h>
2018 #include <openssl/err.h>
2019 #include <openssl/x509v3.h>
2020 #include <openssl/x509.h>
2021 #include <openssl/rand.h>
2022 #if defined OPENSSL_NO_SSL3 &&\
2023 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2024 # error We need one of SSLv3 and TLSv1.
2025 #endif
2026 int main(void){
2027 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2029 SSL_CTX_free(ctx);
2030 PEM_read_PrivateKey(0, 0, 0, 0);
2031 return 0;
2034 then
2036 else
2037 feat_bail_required SSL
2040 if [ "${have_ssl_tls}" = 'yes' ]; then
2041 compile_check ssl_tls_stack_of 'TLS/SSL STACK_OF()' \
2042 '#define HAVE_SSL_TLS_STACK_OF' << \!
2043 #include <stdio.h> /* For C89 NULL */
2044 #include <openssl/ssl.h>
2045 #include <openssl/err.h>
2046 #include <openssl/x509v3.h>
2047 #include <openssl/x509.h>
2048 #include <openssl/rand.h>
2049 int main(void){
2050 STACK_OF(GENERAL_NAME) *gens = NULL;
2052 printf("%p", gens); /* to use it */
2053 return 0;
2057 link_check ssl_tls_conf 'OpenSSL_modules_load_file() support' \
2058 '#define HAVE_SSL_TLS_CONFIG' << \!
2059 #include <stdio.h> /* For C89 NULL */
2060 #include <openssl/conf.h>
2061 int main(void){
2062 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2063 CONF_modules_free();
2064 return 0;
2068 link_check ssl_tls_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2069 '#define HAVE_SSL_TLS_CONF_CTX' << \!
2070 #include "config.h"
2071 #include <openssl/ssl.h>
2072 #include <openssl/err.h>
2073 int main(void){
2074 #if HAVE_SSL_TLS < 10100
2075 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2076 #else
2077 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2078 #endif
2079 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2081 SSL_CONF_CTX_set_flags(cctx,
2082 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2083 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2084 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2085 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2086 SSL_CONF_CTX_finish(cctx);
2087 SSL_CONF_CTX_free(cctx);
2088 SSL_CTX_free(ctx);
2089 return 0;
2093 link_check ssl_tls_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2094 '#define HAVE_SSL_TLS_RAND_EGD' << \!
2095 #include <openssl/rand.h>
2096 int main(void){
2097 return RAND_egd("some.where") > 0;
2101 if feat_yes SSL_ALL_ALGORITHMS; then
2102 if link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2103 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2104 #include <openssl/evp.h>
2105 int main(void){
2106 OpenSSL_add_all_algorithms();
2107 EVP_get_cipherbyname("two cents i never exist");
2108 EVP_cleanup();
2109 return 0;
2112 then
2114 else
2115 feat_bail_required SSL_ALL_ALGORITHMS
2117 fi # SSL_ALL_ALGORITHMS
2119 if feat_yes MD5 && feat_no NOEXTMD5; then
2120 run_check ssl_md5 'MD5 digest in the used crypto library' \
2121 '#define HAVE_SSL_MD5' << \!
2122 #include <stdlib.h>
2123 #include <string.h>
2124 #include <openssl/md5.h>
2125 int main(void){
2126 char const dat[] = "abrakadabrafidibus";
2127 char dig[16], hex[16 * 2];
2128 MD5_CTX ctx;
2129 size_t i, j;
2131 memset(dig, 0, sizeof(dig));
2132 memset(hex, 0, sizeof(hex));
2133 MD5_Init(&ctx);
2134 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2135 MD5_Final(dig, &ctx);
2137 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2138 for(i = 0; i < sizeof(hex) / 2; i++){
2139 j = i << 1;
2140 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2141 hex[++j] = hexchar(dig[i] & 0x0f);
2143 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2146 fi # feat_yes MD5 && feat_no NOEXTMD5
2148 else
2149 echo '/* OPT_SSL=0 */' >> ${h}
2150 fi # feat_yes SSL
2152 if [ "${have_ssl_tls}" = 'yes' ]; then
2153 OPT_SMIME=1
2154 else
2155 OPT_SMIME=1
2158 if feat_yes SMTP; then
2159 echo '#define HAVE_SMTP' >> ${h}
2160 else
2161 echo '/* OPT_SMTP=0 */' >> ${h}
2164 if feat_yes POP3; then
2165 echo '#define HAVE_POP3' >> ${h}
2166 else
2167 echo '/* OPT_POP3=0 */' >> ${h}
2170 if feat_yes GSSAPI; then
2171 ${cat} > ${tmp2}.c << \!
2172 #include <gssapi/gssapi.h>
2173 int main(void){
2174 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2175 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2176 return 0;
2179 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2181 if command -v krb5-config >/dev/null 2>&1; then
2182 i=`command -v krb5-config`
2183 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2184 GSS_INCS="`CFLAGS= ${i} --cflags`"
2185 i='GSS-API via krb5-config(1)'
2186 else
2187 GSS_LIBS='-lgssapi'
2188 GSS_INCS=
2189 i='GSS-API in gssapi/gssapi.h, libgssapi'
2191 if < ${tmp2}.c link_check gss \
2192 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2193 < ${tmp3}.c link_check gss \
2194 'GSS-API in gssapi.h, libgssapi' \
2195 '#define HAVE_GSSAPI
2196 #define GSSAPI_REG_INCLUDE' \
2197 '-lgssapi' ||\
2198 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2199 '#define HAVE_GSSAPI' \
2200 '-lgssapi_krb5' ||\
2201 < ${tmp3}.c link_check gss \
2202 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2203 '#define HAVE_GSSAPI
2204 #define GSS_REG_INCLUDE' \
2205 '-lgssapi -lkrb5 -lcrypto' \
2206 '-I/usr/include/kerberosV' ||\
2207 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2208 '#define HAVE_GSSAPI' \
2209 '-lgss' ||\
2210 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2211 '#define HAVE_GSSAPI
2212 #define GSSAPI_OLD_STYLE' \
2213 '-lgssapi_krb5' << \!
2214 #include <gssapi/gssapi.h>
2215 #include <gssapi/gssapi_generic.h>
2216 int main(void){
2217 gss_import_name(0, 0, gss_nt_service_name, 0);
2218 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2219 return 0;
2222 then
2224 else
2225 feat_bail_required GSSAPI
2227 else
2228 echo '/* OPT_GSSAPI=0 */' >> ${h}
2229 fi # feat_yes GSSAPI
2231 if feat_yes NETRC; then
2232 echo '#define HAVE_NETRC' >> ${h}
2233 else
2234 echo '/* OPT_NETRC=0 */' >> ${h}
2237 if feat_yes AGENT; then
2238 echo '#define HAVE_AGENT' >> ${h}
2239 else
2240 echo '/* OPT_AGENT=0 */' >> ${h}
2243 if feat_yes IDNA; then
2244 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2245 '-lidn' << \!
2246 #include <idna.h>
2247 #include <idn-free.h>
2248 #include <stringprep.h>
2249 int main(void){
2250 char *utf8, *idna_ascii, *idna_utf8;
2252 utf8 = stringprep_locale_to_utf8("does.this.work");
2253 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2254 != IDNA_SUCCESS)
2255 return 1;
2256 idn_free(idna_ascii);
2257 /* (Rather link check only here) */
2258 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2259 return 0;
2262 then
2264 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2265 '-lidnkit' << \!
2266 #include <stdio.h>
2267 #include <idn/api.h>
2268 #include <idn/result.h>
2269 int main(void){
2270 idn_result_t r;
2271 char ace_name[256];
2272 char local_name[256];
2274 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2275 sizeof(ace_name));
2276 if (r != idn_success) {
2277 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2278 return 1;
2280 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2281 if (r != idn_success) {
2282 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2283 return 1;
2285 return 0;
2288 then
2290 else
2291 feat_bail_required IDNA
2294 if [ -n "${have_idna}" ]; then
2295 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2296 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2298 else
2299 echo '/* OPT_IDNA=0 */' >> ${h}
2302 if feat_yes IMAP_SEARCH; then
2303 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2304 else
2305 echo '/* OPT_IMAP_SEARCH=0 */' >> ${h}
2308 if feat_yes REGEX; then
2309 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2310 #include <regex.h>
2311 #include <stdlib.h>
2312 int main(void){
2313 int status;
2314 regex_t re;
2316 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2317 return 1;
2318 status = regexec(&re, "plan9", 0,NULL, 0);
2319 regfree(&re);
2320 return !(status == REG_NOMATCH);
2323 then
2325 else
2326 feat_bail_required REGEX
2328 else
2329 echo '/* OPT_REGEX=0 */' >> ${h}
2332 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2333 have_mle=1
2334 echo '#define HAVE_MLE' >> ${h}
2335 else
2336 feat_bail_required MLE
2337 echo '/* OPT_MLE=0 */' >> ${h}
2340 # Generic have-a-line-editor switch for those who need it below
2341 if [ -n "${have_mle}" ]; then
2342 have_cle=1
2345 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2346 echo '#define HAVE_HISTORY' >> ${h}
2347 else
2348 echo '/* OPT_HISTORY=0 */' >> ${h}
2351 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2352 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2353 else
2354 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2357 if feat_yes TERMCAP; then
2358 __termcaplib() {
2359 link_check termcap "termcap(5) (via ${4})" \
2360 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2361 #include <stdio.h>
2362 #include <stdlib.h>
2363 ${2}
2364 #include <term.h>
2365 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2366 static int my_putc(int c){return putchar(c);}
2367 int main(void){
2368 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2369 int r2 = OK, r3 = ERR;
2371 tgetent(buf, getenv("TERM"));
2372 cpb = cmdbuf;
2373 r1 = tgetstr(UNCONST("cm"), &cpb);
2374 tgoto(r1, 1, 1);
2375 r2 = tgetnum(UNCONST("Co"));
2376 r3 = tgetflag(UNCONST("ut"));
2377 tputs("cr", 1, &my_putc);
2378 return (r1 == NULL || r2 == -1 || r3 == 0);
2380 _EOT
2383 __terminfolib() {
2384 link_check terminfo "terminfo(5) (via ${2})" \
2385 '#define HAVE_TERMCAP
2386 #define HAVE_TERMCAP_CURSES
2387 #define HAVE_TERMINFO' "${1}" << _EOT
2388 #include <stdio.h>
2389 #include <curses.h>
2390 #include <term.h>
2391 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2392 static int my_putc(int c){return putchar(c);}
2393 int main(void){
2394 int er, r0, r1, r2;
2395 char *r3, *tp;
2397 er = OK;
2398 r0 = setupterm(NULL, 1, &er);
2399 r1 = tigetflag(UNCONST("bce"));
2400 r2 = tigetnum(UNCONST("colors"));
2401 r3 = tigetstr(UNCONST("cr"));
2402 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2403 tputs(tp, 1, &my_putc);
2404 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2405 r3 == (char*)-1 || r3 == NULL);
2407 _EOT
2410 if feat_yes TERMCAP_VIA_TERMINFO; then
2411 __terminfolib -ltinfo -ltinfo ||
2412 __terminfolib -lcurses -lcurses ||
2413 __terminfolib -lcursesw -lcursesw ||
2414 feat_bail_required TERMCAP_VIA_TERMINFO
2417 if [ -z "${have_terminfo}" ]; then
2418 __termcaplib -ltermcap '' '' '-ltermcap' ||
2419 __termcaplib -ltermcap '#include <curses.h>' '
2420 #define HAVE_TERMCAP_CURSES' \
2421 'curses.h / -ltermcap' ||
2422 __termcaplib -lcurses '#include <curses.h>' '
2423 #define HAVE_TERMCAP_CURSES' \
2424 'curses.h / -lcurses' ||
2425 __termcaplib -lcursesw '#include <curses.h>' '
2426 #define HAVE_TERMCAP_CURSES' \
2427 'curses.h / -lcursesw' ||
2428 feat_bail_required TERMCAP
2430 if [ -n "${have_termcap}" ]; then
2431 run_check tgetent_null \
2432 "tgetent(3) of termcap(5) takes NULL buffer" \
2433 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2434 #include <stdio.h> /* For C89 NULL */
2435 #include <stdlib.h>
2436 #ifdef HAVE_TERMCAP_CURSES
2437 # include <curses.h>
2438 #endif
2439 #include <term.h>
2440 int main(void){
2441 tgetent(NULL, getenv("TERM"));
2442 return 0;
2444 _EOT
2447 else
2448 echo '/* OPT_TERMCAP=0 */' >> ${h}
2449 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2452 if feat_yes SPAM_SPAMC; then
2453 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2454 if command -v spamc >/dev/null 2>&1; then
2455 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2457 else
2458 echo '/* OPT_SPAM_SPAMC=0 */' >> ${h}
2461 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2462 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2463 else
2464 feat_bail_required SPAM_SPAMD
2465 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2468 feat_def SPAM_FILTER
2470 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2471 echo '#define HAVE_SPAM' >> ${h}
2472 else
2473 echo '/* HAVE_SPAM */' >> ${h}
2476 if feat_yes QUOTE_FOLD &&\
2477 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2478 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2479 else
2480 feat_bail_required QUOTE_FOLD
2481 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2484 feat_def FILTER_HTML_TAGSOUP
2485 feat_def COLOUR
2486 feat_def DOTLOCK
2487 feat_def MD5
2488 feat_def NOMEMDBG
2490 ## Summarizing
2492 ${rm} -f ${tmp}
2493 squeeze_em ${inc} ${tmp}
2494 ${mv} ${tmp} ${inc}
2495 squeeze_em ${lib} ${tmp}
2496 ${mv} ${tmp} ${lib}
2498 # config.h
2499 ${mv} ${h} ${tmp}
2500 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2501 ${cat} ${tmp} >> ${h}
2502 ${rm} -f ${tmp}
2503 printf '\n' >> ${h}
2505 # Create the real mk.mk
2506 # Note we cannout use explicit ./ filename prefix for source and object
2507 # pathnames because of a bug in bmake(1)
2508 ${rm} -rf ${tmp0}.* ${tmp0}*
2509 printf 'OBJ_SRC = ' >> ${mk}
2510 if feat_no AMALGAMATION; then
2511 for i in `printf '%s\n' *.c | ${sort}`; do
2512 if [ "${i}" = privsep.c ]; then
2513 continue
2515 printf "${i} " >> ${mk}
2516 done
2517 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2518 else
2519 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2521 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2522 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2523 printf '# undef _CONFIG_H\n' >> ${h}
2524 printf '# define _CONFIG_H 2\n' >> ${h}
2525 for i in `printf '%s\n' *.c | ${sort}`; do
2526 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2527 [ "${i}" = privsep.c ]; then
2528 continue
2530 printf "${i} " >> ${mk}
2531 printf "# include \"${i}\"\n" >> ${h}
2532 done
2533 echo >> ${mk}
2534 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2535 echo '#else' >> ${h}
2538 # Finally, create the string that is used by *features* and `version'.
2539 # Take this nice opportunity and generate a visual listing of included and
2540 # non-included features for the person who runs the configuration
2541 msg '\nThe following features are included (+) or not (-):'
2542 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2543 printf '/* The "feature string" */\n' >> ${h}
2544 # Because + is expanded by *folder* if first in "echo $features", put something
2545 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2546 sep=
2547 for opt
2549 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2550 feat_yes ${opt} && sign=+ || sign=-
2551 printf -- "${sep}${sign}${sopt}" >> ${h}
2552 sep=','
2553 i=`option_doc_of ${opt}`
2554 [ -z "${i}" ] && continue
2555 msg " %s %s: %s" ${sign} ${sopt} "${i}"
2556 done
2557 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2558 #exec 5>&1 >>${h}
2559 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2560 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2562 printf '"\n#endif /* n_CONFIG_H */\n' >> ${h}
2564 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2565 echo "INCS = `${cat} ${inc}`" >> ${mk}
2566 echo >> ${mk}
2567 ${cat} ./mk-mk.in >> ${mk}
2569 ## Finished!
2571 msg '\nSetup:'
2572 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2573 msg ' . bindir: %s' "${VAL_BINDIR}"
2574 if feat_yes DOTLOCK; then
2575 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2577 msg ' . mandir: %s' "${VAL_MANDIR}"
2578 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2579 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2580 msg ''
2582 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2583 exit 0
2585 msg 'Remarks:'
2586 if [ -z "${have_fnmatch}" ]; then
2587 msg ' . The function fnmatch(3) could not be found.'
2588 msg ' Filename patterns like wildcard are not supported on your system'
2590 if [ -z "${have_fchdir}" ]; then
2591 msg ' . The function fchdir(2) could not be found.'
2592 msg ' We will use chdir(2) instead.'
2593 msg ' This is a problem only if the current working directory is changed'
2594 msg ' while this program is inside of it'
2596 msg ''
2598 # s-it-mode