Bump S-nail v14.9.0-pre2, 2016-10-31
[s-mailx.git] / mk-conf.sh
blobcfde9fd376c2b5c12b21510dfcd5ff6524bd12ff
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
188 if feat_yes DEBUG; then
189 OPT_NOALLOCA=1
193 rc=./make.rc
194 lst=./config.lst
195 ev=./config.ev
196 h=./config.h h_name=config.h
197 mk=./mk.mk
199 newlst=./config.lst-new
200 newmk=./config.mk-new
201 newev=./config.ev-new
202 newh=./config.h-new
203 tmp0=___tmp
204 tmp=./${tmp0}1$$
205 tmp2=./${tmp0}2$$
207 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
209 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
210 # via path_check() later on once possible
212 # TODO cc_maxopt is brute simple, we should compile test program and dig real
213 # compiler versions for known compilers, then be more specific
214 cc_maxopt=100
215 _CFLAGS= _LDFLAGS=
217 os_early_setup() {
218 # We don't "have any utility": only path adjustments and such in here!
219 i="${OS:-`uname -s`}"
221 if [ ${i} = SunOS ]; then
222 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
223 _os_early_setup_sunos
227 _os_early_setup_sunos() {
228 # According to standards(5), this is what we need to do
229 if [ -d /usr/xpg4 ]; then :; else
230 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
231 config_exit 1
233 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
234 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
235 export PATH
238 os_setup() {
239 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
240 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
241 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
242 msg 'Operating system is %s' ${OS}
244 if [ ${OS} = sunos ]; then
245 msg ' . have special SunOS / Solaris "setup" rules ...'
246 _os_setup_sunos
247 elif [ ${OS} = unixware ]; then
248 msg ' . have special UnixWare environmental rules ...'
249 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
250 CC=cc
251 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
253 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
254 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
255 export CC CFLAGS LDFLAGS
256 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
258 elif [ -n "${VERBOSE}" ]; then
259 msg ' . no special treatment for this system necessary or known'
262 # Sledgehammer: better set _GNU_SOURCE
263 # And in general: oh, boy!
264 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
265 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
266 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
267 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
269 # On pkgsrc(7) systems automatically add /usr/pkg/*
270 if [ -d /usr/pkg ]; then
271 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
272 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
276 _os_setup_sunos() {
277 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
278 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
280 # Include packages
281 if [ -d /opt/csw ]; then
282 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
283 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
286 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
287 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
289 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
290 if [ -x "${cksum}" ]; then :; else
291 msg 'ERROR: Not an executable program: %s' "${cksum}"
292 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
293 msg 'ERROR: However, we do so only for tests.'
294 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
295 config_exit 1
298 if feat_yes AUTOCC; then
299 if command -v cc >/dev/null 2>&1; then
300 CC=cc
301 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
303 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
304 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
305 export CC CFLAGS LDFLAGS
306 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
307 else
308 # Assume gcc(1), which supports -R for compat
309 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
314 # Check out compiler ($CC) and -flags ($CFLAGS)
315 cc_setup() {
316 # Even though it belongs into cc_flags we will try to compile and link
317 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
318 # EXTRA_CFLAGS/EXTRA_LDFLAGS
319 if feat_no AUTOCC; then
320 _cc_default
321 # Ensure those don't do any harm
322 EXTRA_CFLAGS= EXTRA_LDFLAGS=
323 export EXTRA_CFLAGS EXTRA_LDFLAGS
324 return
325 else
326 CFLAGS= LDFLAGS=
327 export CFLAGS LDFLAGS
330 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
332 msg_nonl 'Searching for a usable C compiler .. $CC='
333 if { i="`command -v clang`"; }; then
334 CC=${i}
335 elif { i="`command -v gcc`"; }; then
336 CC=${i}
337 elif { i="`command -v c99`"; }; then
338 CC=${i}
339 elif { i="`command -v tcc`"; }; then
340 CC=${i}
341 elif { i="`command -v pcc`"; }; then
342 CC=${i}
343 else
344 if [ "${CC}" = cc ]; then
346 elif { i="`command -v c89`"; }; then
347 CC=${i}
348 else
349 msg 'boing booom tschak'
350 msg 'ERROR: I cannot find a compiler!'
351 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
352 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
353 config_exit 1
356 msg '%s' "${CC}"
357 export CC
360 _cc_default() {
361 if [ -z "${CC}" ]; then
362 msg 'To go on like you have chosen, please set $CC, rerun.'
363 config_exit 1
366 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
368 else
369 msg 'Using C compiler ${CC}=%s' "${CC}"
373 cc_flags() {
374 if feat_yes AUTOCC; then
375 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
376 cc_check_silent=1
377 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
378 "${CC}"
379 else
380 cc_check_silent=
381 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
384 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
385 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
386 msg ' . have special tcc(1) environmental rules ...'
387 _cc_flags_tcc
388 else
389 # As of pcc CVS 2016-04-02, stack protection support is announced but
390 # will break if used on Linux
391 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
392 force_no_stackprot=1
394 _cc_flags_generic
397 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
398 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
399 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
400 else
401 if feat_no DEBUG; then
402 CFLAGS="-DNDEBUG ${CFLAGS}"
405 msg ''
406 export CFLAGS LDFLAGS
409 _cc_flags_tcc() {
410 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
411 _CFLAGS= _LDFLAGS=
413 cc_check -Wall
414 cc_check -Wextra
415 cc_check -pedantic
417 if feat_yes DEBUG; then
418 # May have problems to find libtcc cc_check -b
419 cc_check -g
422 if ld_check -Wl,-rpath =./ no; then
423 need_R_ldflags=-Wl,-rpath=
424 ld_runtime_flags # update!
427 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
428 unset __cflags __ldflags
431 _cc_flags_generic() {
432 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
433 _CFLAGS= _LDFLAGS=
434 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
436 # Check -g first since some others may rely upon -g / optim. level
437 if feat_yes DEBUG; then
438 cc_check -O
439 cc_check -g
440 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
442 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
444 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
446 else
447 cc_check -O
450 if feat_yes DEVEL && cc_check -Weverything; then
452 else
453 cc_check -Wall
454 cc_check -Wextra
455 cc_check -Wbad-function-cast
456 cc_check -Wcast-align
457 cc_check -Wcast-qual
458 cc_check -Winit-self
459 cc_check -Wmissing-prototypes
460 cc_check -Wshadow
461 cc_check -Wunused
462 cc_check -Wwrite-strings
463 cc_check -Wno-long-long
465 cc_check -pedantic
467 if feat_yes AMALGAMATION && feat_no DEVEL; then
468 cc_check -Wno-unused-function
470 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
472 cc_check -fno-unwind-tables
473 cc_check -fno-asynchronous-unwind-tables
474 cc_check -fstrict-aliasing
475 if cc_check -fstrict-overflow && feat_yes DEVEL; then
476 cc_check -Wstrict-overflow=5
479 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
480 if [ -z "${force_no_stackprot}" ]; then
481 if cc_check -fstack-protector-strong ||
482 cc_check -fstack-protector-all; then
483 cc_check -D_FORTIFY_SOURCE=2
485 else
486 msg 'Not checking for -fstack-protector compiler option,'
487 msg 'since that caused errors in a "similar" configuration.'
488 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
492 if feat_yes AMALGAMATION; then
493 cc_check -pipe
496 # LD (+ dependend CC)
498 if feat_yes DEVEL; then
499 _ccfg=${_CFLAGS}
500 # -fsanitize=address
501 #if cc_check -fsanitize=memory &&
502 # ld_check -fsanitize=memory &&
503 # cc_check -fsanitize-memory-track-origins=2 &&
504 # ld_check -fsanitize-memory-track-origins=2; then
506 #else
507 # _CFLAGS=${_ccfg}
511 ld_check -Wl,-z,relro
512 ld_check -Wl,-z,now
513 ld_check -Wl,-z,noexecstack
514 if ld_check -Wl,-rpath =./ no; then
515 need_R_ldflags=-Wl,-rpath=
516 ld_runtime_flags # update!
517 elif ld_check -Wl,-R ./ no; then
518 need_R_ldflags=-Wl,-R
519 ld_runtime_flags # update!
522 # Address randomization
523 _ccfg=${_CFLAGS}
524 if cc_check -fPIE || cc_check -fpie; then
525 ld_check -pie || _CFLAGS=${_ccfg}
527 unset _ccfg
529 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
530 unset __cflags __ldflags
533 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
535 ## Notes:
536 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
537 ## redirection, so use "printf '' >" instead
539 ## Very first: we undergo several states regarding I/O redirection etc.,
540 ## but need to deal with option updates from within all. Since all the
541 ## option stuff should be above the scissor line, define utility functions
542 ## and redefine them as necessary.
543 ## And, since we have those functions, simply use them for whatever
545 config_exit() {
546 exit ${1}
549 msg() {
550 fmt=${1}
551 shift
552 printf >&2 -- "${fmt}\\n" "${@}"
555 msg_nonl() {
556 fmt=${1}
557 shift
558 printf >&2 -- "${fmt}" "${@}"
561 t1=ten10one1ten10one1
562 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
563 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
564 ) > /dev/null 2>&1; then
565 good_shell=1
566 else
567 unset good_shell
569 unset t1
571 # We need some standard utilities
572 unset -f command
573 check_tool() {
574 n=${1} i=${2} opt=${3:-0}
575 # Evaluate, just in case user comes in with shell snippets (..well..)
576 eval i="${i}"
577 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
578 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
579 eval ${n}=${i}
580 return 0
582 if [ ${opt} -eq 0 ]; then
583 msg 'ERROR: no trace of utility %s' "${n}"
584 config_exit 1
586 return 1
589 # Our feature check environment
590 feat_val_no() {
591 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
592 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
595 feat_val_yes() {
596 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
597 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
598 [ "x${1}" = xrequire ]
601 feat_val_require() {
602 [ "x${1}" = xrequire ]
605 _feat_check() {
606 eval i=\$OPT_${1}
607 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
608 if feat_val_no "${i}"; then
609 return 1
610 elif feat_val_yes "${i}"; then
611 return 0
612 else
613 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
614 "${1}" "${i}"
615 config_exit 11
619 feat_yes() {
620 _feat_check ${1}
623 feat_no() {
624 _feat_check ${1} && return 1
625 return 0
628 feat_require() {
629 eval i=\$OPT_${1}
630 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
631 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
634 feat_bail_required() {
635 if feat_require ${1}; then
636 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
637 config_exit 13
639 eval OPT_${1}=0
640 option_update # XXX this is rather useless here (dependency chain..)
643 option_parse() {
644 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
645 # options, without documentation, to $1
646 j=\'
647 i="`${awk} -v input=\"${2}\" '
648 BEGIN{
649 for(i = 0;;){
650 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
651 if(voff == 0)
652 break
653 v = substr(input, voff, RLENGTH)
654 input = substr(input, voff + RLENGTH)
655 doff = index(v, "=")
656 if(doff > 0){
657 d = substr(v, doff + 2, length(v) - doff - 1)
658 v = substr(v, 1, doff - 1)
660 print v
664 eval ${1}=\"${i}\"
667 option_doc_of() {
668 # Return the "documentation string" for option $1, itself if none such
669 j=\'
670 ${awk} -v want="${1}" \
671 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
672 BEGIN{
673 for(;;){
674 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
675 if(voff == 0)
676 break
677 v = substr(input, voff, RLENGTH)
678 input = substr(input, voff + RLENGTH)
679 doff = index(v, "=")
680 if(doff > 0){
681 d = substr(v, doff + 2, length(v) - doff - 1)
682 v = substr(v, 1, doff - 1)
683 }else
684 d = v
685 if(v == want){
686 if(d != "-")
687 print d
688 exit
695 option_join_rc() {
696 # Join the values from make.rc into what currently is defined, not
697 # overwriting yet existing settings
698 ${rm} -f ${tmp}
699 # We want read(1) to perform backslash escaping in order to be able to use
700 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow
701 # in VMs (see [fa2e248]), Aharon Robbins suggested the following
702 < ${rc} ${awk} 'BEGIN{line = ""}{
703 gsub(/^[[:space:]]+/, "", $0)
704 gsub(/[[:space:]]+$/, "", $0)
705 if(gsub(/\\$/, "", $0)){
706 line = line $0
707 next
708 }else
709 line = line $0
710 if(index(line, "#") == 1){
711 line = ""
712 }else if(length(line)){
713 print line
714 line = ""
716 }' |
717 while read line; do
718 if [ -n "${good_shell}" ]; then
719 i=${line%%=*}
720 else
721 i=`${awk} -v LINE="${line}" 'BEGIN{
722 gsub(/=.*$/, "", LINE)
723 print LINE
726 if [ "${i}" = "${line}" ]; then
727 msg 'ERROR: invalid syntax in: %s' "${line}"
728 continue
731 eval j="\$${i}" jx="\${${i}+x}"
732 if [ -n "${j}" ] || [ "${jx}" = x ]; then
733 : # Yet present
734 else
735 j=`${awk} -v LINE="${line}" 'BEGIN{
736 gsub(/^[^=]*=/, "", LINE)
737 gsub(/^\"*/, "", LINE)
738 gsub(/\"*$/, "", LINE)
739 print LINE
742 [ "${i}" = "DESTDIR" ] && continue
743 echo "${i}=\"${j}\""
744 done > ${tmp}
745 # Reread the mixed version right now
746 . ./${tmp}
749 option_evaluate() {
750 # Expand the option values, which may contain shell snippets
751 ${rm} -f ${newlst} ${newmk} ${newh}
752 exec 5<&0 6>&1 <${tmp} >${newlst}
753 while read line; do
755 if [ -n "${good_shell}" ]; then
756 i=${line%%=*}
757 [ "${i}" != "${i#OPT_}" ] && z=1
758 else
759 i=`${awk} -v LINE="${line}" 'BEGIN{
760 gsub(/=.*$/, "", LINE);\
761 print LINE
763 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
768 eval j=\$${i}
769 if [ -n "${z}" ]; then
770 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
771 if [ -z "${j}" ] || feat_val_no "${j}"; then
773 printf " /* #undef ${i} */\n" >> ${newh}
774 elif feat_val_yes "${j}"; then
775 if feat_val_require "${j}"; then
776 j=require
777 else
780 printf " /* #define ${i} */\n" >> ${newh}
781 else
782 msg 'ERROR: cannot parse <%s>' "${line}"
783 config_exit 1
785 else
786 printf "#define ${i} \"${j}\"\n" >> ${newh}
788 printf "${i} = ${j}\n" >> ${newmk}
789 printf "${i}=${j}\n"
790 eval "${i}=\"${j}\""
791 done
792 exec 0<&5 1>&6 5<&- 6<&-
795 path_check() {
796 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
797 varname=${1} addflag=${2} flagvarname=${3}
798 j=${IFS}
799 IFS=:
800 eval "set -- \$${1}"
801 IFS=${j}
802 j= k= y= z=
803 for i
805 [ -z "${i}" ] && continue
806 [ -d "${i}" ] || continue
807 # Skip any fakeroot packager environment
808 case "${i}" in *fakeroot*) continue;; esac
809 if [ -n "${j}" ]; then
810 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
812 else
813 y="${y} :${i}:"
814 j="${j}:${i}"
815 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
817 else
818 y=" :${i}:"
819 j="${i}"
820 [ -n "${addflag}" ] && k="${addflag}${i}"
822 done
823 eval "${varname}=\"${j}\""
824 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
825 unset varname
828 ld_runtime_flags() {
829 if [ -n "${need_R_ldflags}" ]; then
830 i=${IFS}
831 IFS=:
832 set -- ${LD_LIBRARY_PATH}
833 IFS=${i}
834 for i
836 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
837 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
838 done
839 export LDFLAGS
841 # Disable it for a possible second run.
842 need_R_ldflags=
845 cc_check() {
846 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
847 if "${CC}" ${INCS} \
848 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
849 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
850 _CFLAGS="${_CFLAGS} ${1}"
851 [ -n "${cc_check_silent}" ] || msg 'yes'
852 return 0
854 [ -n "${cc_check_silent}" ] || msg 'no'
855 return 1
858 ld_check() {
859 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
860 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
861 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
862 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
863 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
864 [ -n "${cc_check_silent}" ] || msg 'yes'
865 return 0
867 [ -n "${cc_check_silent}" ] || msg 'no'
868 return 1
871 _check_preface() {
872 variable=$1 topic=$2 define=$3
874 echo '**********'
875 msg_nonl ' . %s ... ' "${topic}"
876 echo "/* checked ${topic} */" >> ${h}
877 ${rm} -f ${tmp} ${tmp}.o
878 echo '*** test program is'
879 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
880 #echo '*** the preprocessor generates'
881 #${make} -f ${makefile} ${tmp}.x
882 #${cat} ${tmp}.x
883 echo '*** results are'
886 compile_check() {
887 variable=$1 topic=$2 define=$3
889 _check_preface "${variable}" "${topic}" "${define}"
891 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
892 [ -f ./${tmp}.o ]; then
893 msg 'yes'
894 echo "${define}" >> ${h}
895 eval have_${variable}=yes
896 return 0
897 else
898 echo "/* ${define} */" >> ${h}
899 msg 'no'
900 eval unset have_${variable}
901 return 1
905 _link_mayrun() {
906 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
908 _check_preface "${variable}" "${topic}" "${define}"
910 feat_yes CROSS_BUILD && run=0
912 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
913 XLIBS="${LIBS} ${libs}" ./${tmp} &&
914 [ -f ./${tmp} ] &&
915 { [ ${run} -eq 0 ] || ./${tmp}; }; then
916 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
917 msg 'yes'
918 echo "${define}" >> ${h}
919 LIBS="${LIBS} ${libs}"
920 echo "${libs}" >> ${lib}
921 INCS="${INCS} ${incs}"
922 echo "${incs}" >> ${inc}
923 eval have_${variable}=yes
924 return 0
925 else
926 msg 'no'
927 echo "/* ${define} */" >> ${h}
928 eval unset have_${variable}
929 return 1
933 link_check() {
934 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
937 run_check() {
938 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
941 feat_def() {
942 if feat_yes ${1}; then
943 echo '#define HAVE_'${1}'' >> ${h}
944 else
945 echo '/* OPT_'${1}'=0 */' >> ${h}
949 squeeze_em() {
950 < "${1}" > "${2}" ${awk} \
951 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
954 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
956 # First of all, create new configuration and check whether it changed
958 # Very easy checks for the operating system in order to be able to adjust paths
959 # or similar very basic things which we need to be able to go at all
960 os_early_setup
962 # Check those tools right now that we need before including $rc
963 msg 'Checking for basic utility set'
964 check_tool awk "${awk:-`command -v awk`}"
965 check_tool rm "${rm:-`command -v rm`}"
966 check_tool tr "${tr:-`command -v tr`}"
968 # Initialize the option set
969 msg_nonl 'Setting up configuration options ... '
970 option_setup
971 msg 'done'
973 # Include $rc, but only take from it what wasn't overwritten by the user from
974 # within the command line or from a chosen fixed CONFIG=
975 # Note we leave alone the values
976 trap "exit 1" HUP INT TERM
977 trap "${rm} -f ${tmp}" EXIT
979 msg_nonl 'Joining in %s ... ' ${rc}
980 option_join_rc
981 msg 'done'
983 # We need to know about that now, in order to provide utility overwrites etc.
984 os_setup
986 msg 'Checking for remaining set of utilities'
987 check_tool grep "${grep:-`command -v grep`}"
989 # Before we step ahead with the other utilities perform a path cleanup first.
990 path_check PATH
992 # awk(1) above
993 check_tool cat "${cat:-`command -v cat`}"
994 check_tool chmod "${chmod:-`command -v chmod`}"
995 check_tool cp "${cp:-`command -v cp`}"
996 check_tool cmp "${cmp:-`command -v cmp`}"
997 # grep(1) above
998 check_tool mkdir "${mkdir:-`command -v mkdir`}"
999 check_tool mv "${mv:-`command -v mv`}"
1000 # rm(1) above
1001 check_tool sed "${sed:-`command -v sed`}"
1002 check_tool sort "${sort:-`command -v sort`}"
1003 check_tool tee "${tee:-`command -v tee`}"
1005 check_tool chown "${chown:-`command -v chown`}" 1 ||
1006 check_tool chown "/sbin/chown" 1 ||
1007 check_tool chown "/usr/sbin/chown"
1009 check_tool make "${MAKE:-`command -v make`}"
1010 MAKE=${make}
1011 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1012 HAVE_STRIP=1 || HAVE_STRIP=0
1014 # For ./cc-test.sh only
1015 check_tool cksum "${cksum:-`command -v cksum`}"
1017 # Update OPT_ options now, in order to get possible inter-dependencies right
1018 option_update
1020 # (No functions since some shells loose non-exported variables in traps)
1021 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1022 trap "trap \"\" HUP INT TERM EXIT;\
1023 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1025 # Our configuration options may at this point still contain shell snippets,
1026 # we need to evaluate them in order to get them expanded, and we need those
1027 # evaluated values not only in our new configuration file, but also at hand..
1028 msg_nonl 'Evaluating all configuration items ... '
1029 option_evaluate
1030 msg 'done'
1032 # Add the known utility and some other variables
1033 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_NAIL}\"\n" >> ${newh}
1034 printf "VAL_UAGENT = ${VAL_SID}${VAL_NAIL}\n" >> ${newmk}
1036 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_NAIL}-privsep\"\n" >> ${newh}
1037 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1038 if feat_yes DOTLOCK; then
1039 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1040 else
1041 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1044 for i in \
1045 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1046 MAKE MAKEFLAGS make SHELL strip \
1047 cksum; do
1048 eval j=\$${i}
1049 printf "${i} = ${j}\n" >> ${newmk}
1050 printf "${i}=${j}\n" >> ${newlst}
1051 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1052 done
1053 printf "\n" >> ${newev}
1055 # Build a basic set of INCS and LIBS according to user environment.
1056 path_check C_INCLUDE_PATH -I _INCS
1057 INCS="${INCS} ${_INCS}"
1058 path_check LD_LIBRARY_PATH -L _LIBS
1059 LIBS="${LIBS} ${_LIBS}"
1060 unset _INCS _LIBS
1061 export C_INCLUDE_PATH LD_LIBRARY_PATH
1063 # Some environments need runtime path flags to be able to go at all
1064 ld_runtime_flags
1066 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1068 cc_setup
1070 ${cat} > ${tmp}.c << \!
1071 #include <stdio.h>
1072 #include <string.h>
1073 static void doit(char const *s);
1075 main(int argc, char **argv){
1076 (void)argc;
1077 (void)argv;
1078 doit("Hello world");
1079 return 0;
1081 static void
1082 doit(char const *s){
1083 char buf[12];
1084 memcpy(buf, s, strlen(s) +1);
1085 puts(s);
1089 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1090 -o ${tmp2} ${tmp}.c ${LIBS}; then
1092 else
1093 msg 'ERROR: i cannot compile a "Hello world" via'
1094 msg ' %s' \
1095 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1096 msg 'ERROR: Please read INSTALL, rerun'
1097 config_exit 1
1100 # This may also update ld_runtime_flags() (again)
1101 cc_flags
1103 for i in \
1104 INCS LIBS \
1105 ; do
1106 eval j=\$${i}
1107 printf -- "${i}=${j}\n" >> ${newlst}
1108 done
1109 for i in \
1110 CC \
1111 CFLAGS \
1112 LDFLAGS \
1113 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1114 OSFULLSPEC \
1115 ; do
1116 eval j=\$${i}
1117 printf -- "${i} = ${j}\n" >> ${newmk}
1118 printf -- "${i}=${j}\n" >> ${newlst}
1119 done
1121 # Now finally check whether we already have a configuration and if so, whether
1122 # all those parameters are still the same.. or something has actually changed
1123 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1124 echo 'Configuration is up-to-date'
1125 exit 0
1126 elif [ -f ${lst} ]; then
1127 echo 'Configuration has been updated..'
1128 ( eval "${MAKE} -f ./mk.mk clean" )
1129 echo
1130 else
1131 echo 'Shiny configuration..'
1134 # Time to redefine helper 1
1135 config_exit() {
1136 ${rm} -f ${lst} ${h} ${mk}
1137 exit ${1}
1140 ${mv} -f ${newlst} ${lst}
1141 ${mv} -f ${newev} ${ev}
1142 ${mv} -f ${newh} ${h}
1143 ${mv} -f ${newmk} ${mk}
1145 if [ -z "${VERBOSE}" ]; then
1146 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1147 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1148 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1149 printf -- "ECHO_TEST = @\n" >> ${mk}
1150 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1151 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1152 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1155 ## Compile and link checking
1157 tmp3=./${tmp0}3$$
1158 log=./config.log
1159 lib=./config.lib
1160 inc=./config.inc
1161 makefile=./config.mk
1163 # (No function since some shells loose non-exported variables in traps)
1164 trap "trap \"\" HUP INT TERM;\
1165 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1166 trap "trap \"\" HUP INT TERM EXIT;\
1167 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
1169 # Time to redefine helper 2
1170 msg() {
1171 fmt=${1}
1172 shift
1173 printf "*** ${fmt}\\n" "${@}"
1174 printf -- "${fmt}\\n" "${@}" >&5
1176 msg_nonl() {
1177 fmt=${1}
1178 shift
1179 printf "*** ${fmt}\\n" "${@}"
1180 printf -- "${fmt}" "${@}" >&5
1183 # !!
1184 exec 5>&2 > ${log} 2>&1
1186 echo "${LIBS}" > ${lib}
1187 echo "${INCS}" > ${inc}
1188 ${cat} > ${makefile} << \!
1189 .SUFFIXES: .o .c .x .y
1190 .c.o:
1191 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1192 .c.x:
1193 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1195 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1198 ## Generics
1200 # May be multiline..
1201 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1203 feat_def ALWAYS_UNICODE_LOCALE
1204 feat_def AMALGAMATION
1205 feat_def CROSS_BUILD
1206 feat_def DEBUG
1207 feat_def DEVEL
1208 feat_def DOCSTRINGS
1209 feat_def ERRORS
1210 feat_def NYD2
1211 feat_def NOMEMDBG
1213 if run_check inline 'inline functions' \
1214 '#define HAVE_INLINE
1215 #define n_INLINE static inline' << \!
1216 static inline int ilf(int i){return ++i;}
1217 int main(void){return ilf(-1);}
1219 then
1221 elif run_check inline 'inline functions (via __inline)' \
1222 '#define HAVE_INLINE
1223 #define n_INLINE static __inline' << \!
1224 static __inline int ilf(int i){return ++i;}
1225 int main(void){return ilf(-1);}
1227 then
1231 if run_check endian 'Little endian byteorder' \
1232 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1233 int main(void){
1234 enum {vBig = 1, vLittle = 0};
1235 union {unsigned short bom; unsigned char buf[2];} u;
1236 u.bom = 0xFEFF;
1237 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1240 then
1244 ## Test for "basic" system-calls / functionality that is used by all parts
1245 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1246 ## macros to be used by only the subprograms (potentially).
1248 if run_check clock_gettime 'clock_gettime(2)' \
1249 '#define HAVE_CLOCK_GETTIME' << \!
1250 #include <time.h>
1251 # include <errno.h>
1252 int main(void){
1253 struct timespec ts;
1255 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1256 return 0;
1257 return 1;
1260 then
1262 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1263 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1264 #include <time.h>
1265 # include <errno.h>
1266 int main(void){
1267 struct timespec ts;
1269 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1270 return 0;
1271 return 1;
1274 then
1276 elif run_check gettimeofday 'gettimeofday(2)' \
1277 '#define HAVE_GETTIMEOFDAY' << \!
1278 #include <stdio.h> /* For C89 NULL */
1279 #include <sys/time.h>
1280 # include <errno.h>
1281 int main(void){
1282 struct timeval tv;
1284 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1285 return 0;
1286 return 1;
1289 then
1291 else
1292 have_no_subsecond_time=1
1295 if run_check nanosleep 'nanosleep(2)' \
1296 '#define HAVE_NANOSLEEP' << \!
1297 #include <time.h>
1298 # include <errno.h>
1299 int main(void){
1300 struct timespec ts;
1302 ts.tv_sec = 1;
1303 ts.tv_nsec = 100000;
1304 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1305 return 0;
1306 return 1;
1309 then
1311 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1312 '#define HAVE_NANOSLEEP' '-lrt' << \!
1313 #include <time.h>
1314 # include <errno.h>
1315 int main(void){
1316 struct timespec ts;
1318 ts.tv_sec = 1;
1319 ts.tv_nsec = 100000;
1320 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1321 return 0;
1322 return 1;
1325 then
1327 # link_check is enough for this, that function is so old, trust the proto
1328 elif link_check sleep 'sleep(3)' \
1329 '#define HAVE_SLEEP' << \!
1330 #include <unistd.h>
1331 # include <errno.h>
1332 int main(void){
1333 if(!sleep(1) || errno != ENOSYS)
1334 return 0;
1335 return 1;
1338 then
1340 else
1341 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1342 config_exit 1
1345 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1346 #include <pwd.h>
1347 #include <unistd.h>
1348 # include <errno.h>
1349 int main(void){
1350 struct passwd *pw;
1351 gid_t gid;
1352 uid_t uid;
1354 if((gid = getgid()) != 0)
1355 gid = getegid();
1356 if((uid = getuid()) != 0)
1357 uid = geteuid();
1358 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1359 return 1;
1360 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1361 return 1;
1362 return 0;
1365 then
1367 else
1368 msg 'ERROR: we require user and group info / database searches.'
1369 msg 'That much Unix we indulge ourselfs.'
1370 config_exit 1
1373 if link_check ftruncate 'ftruncate(2)' \
1374 '#define HAVE_FTRUNCATE' << \!
1375 #include <unistd.h>
1376 #include <sys/types.h>
1377 int main(void){
1378 return (ftruncate(0, 0) != 0);
1381 then
1383 else
1384 msg 'ERROR: we require the ftruncate(2) system call.'
1385 config_exit 1
1388 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1389 #include <signal.h>
1390 # include <errno.h>
1391 int main(void){
1392 struct sigaction nact, oact;
1394 nact.sa_handler = SIG_DFL;
1395 sigemptyset(&nact.sa_mask);
1396 nact.sa_flags = SA_RESTART;
1397 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1400 then
1402 else
1403 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1404 config_exit 1
1407 if link_check snprintf 'snprintf(3)' << \!
1408 #include <stdio.h>
1409 int main(void){
1410 char b[20];
1412 snprintf(b, sizeof b, "%s", "string");
1413 return 0;
1416 then
1418 else
1419 msg 'ERROR: we require the snprintf(3) function.'
1420 config_exit 1
1423 if link_check environ 'environ(3)' << \!
1424 #include <stdio.h> /* For C89 NULL */
1425 int main(void){
1426 extern char **environ;
1428 return environ[0] == NULL;
1431 then
1433 else
1434 msg 'ERROR: we require the environ(3) array for subprocess control.'
1435 config_exit 1
1438 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1439 #include <stdlib.h>
1440 int main(void){
1441 setenv("s-mailx", "i want to see it cute!", 1);
1442 unsetenv("s-mailx");
1443 return 0;
1446 then
1448 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1449 #include <stdlib.h>
1450 int main(void){
1451 putenv("s-mailx=i want to see it cute!");
1452 return 0;
1455 then
1457 else
1458 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1459 config_exit 1
1462 if link_check termios 'termios.h and tc*(3) family' << \!
1463 #include <termios.h>
1464 int main(void){
1465 struct termios tios;
1467 tcgetattr(0, &tios);
1468 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1469 return 0;
1472 then
1474 else
1475 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1476 msg 'That much Unix we indulge ourselfs.'
1477 config_exit 1
1480 ## optional stuff
1482 if link_check vsnprintf 'vsnprintf(3)' << \!
1483 #include <stdarg.h>
1484 #include <stdio.h>
1485 static void dome(char *buf, size_t blen, ...){
1486 va_list ap;
1488 va_start(ap, blen);
1489 vsnprintf(buf, blen, "%s", ap);
1490 va_end(ap);
1492 int main(void){
1493 char b[20];
1495 dome(b, sizeof b, "string");
1496 return 0;
1499 then
1501 else
1502 feat_bail_required ERRORS
1505 if [ "${have_vsnprintf}" = yes ]; then
1506 __va_copy() {
1507 link_check va_copy "va_copy(3) (as ${2})" \
1508 "#define HAVE_N_VA_COPY
1509 #define n_va_copy ${2}" <<_EOT
1510 #include <stdarg.h>
1511 #include <stdio.h>
1512 #if ${1}
1513 # if defined __va_copy && !defined va_copy
1514 # define va_copy __va_copy
1515 # endif
1516 #endif
1517 static void dome2(char *buf, size_t blen, va_list src){
1518 va_list ap;
1520 va_copy(ap, src);
1521 vsnprintf(buf, blen, "%s", ap);
1522 va_end(ap);
1524 static void dome(char *buf, size_t blen, ...){
1525 va_list ap;
1527 va_start(ap, blen);
1528 dome2(buf, blen, ap);
1529 va_end(ap);
1531 int main(void){
1532 char b[20];
1534 dome(b, sizeof b, "string");
1535 return 0;
1537 _EOT
1539 __va_copy 0 va_copy || __va_copy 1 __va_copy
1542 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1543 #include <unistd.h>
1544 #include <errno.h>
1545 int main(void){
1546 int rv = 0;
1548 errno = 0;
1549 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1550 errno = 0;
1551 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1553 /* Only link check */
1554 fpathconf(0, _PC_NAME_MAX);
1556 return rv;
1560 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1561 #include <fcntl.h>
1562 #include <unistd.h>
1563 # include <errno.h>
1564 int main(void){
1565 int fds[2];
1567 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1568 return 0;
1569 return 1;
1573 # We use this only then for now (need NOW+1)
1574 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1575 #include <fcntl.h> /* For AT_* */
1576 #include <sys/stat.h>
1577 # include <errno.h>
1578 int main(void){
1579 struct timespec ts[2];
1581 ts[0].tv_nsec = UTIME_NOW;
1582 ts[1].tv_nsec = UTIME_OMIT;
1583 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1584 return 0;
1585 return 1;
1591 # XXX Add POSIX check once standardized
1592 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1593 #include <stdlib.h>
1594 int main(void){
1595 arc4random();
1596 return 0;
1599 then
1601 elif [ -n "${have_no_subsecond_time}" ]; then
1602 msg 'ERROR: %s %s' 'without a native random' \
1603 'one of clock_gettime(2) and gettimeofday(2) is required.'
1604 config_exit 1
1607 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1608 #include <stdio.h>
1609 int main(void){
1610 putc_unlocked('@', stdout);
1611 return 0;
1615 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1616 #include <unistd.h>
1617 int main(void){
1618 fchdir(0);
1619 return 0;
1623 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1624 #include <stdlib.h>
1625 int main(void){
1626 char x_buf[4096], *x = realpath(".", x_buf);
1628 return (x != NULL) ? 0 : 1;
1631 then
1632 if run_check realpath_malloc 'realpath(3) takes NULL' \
1633 '#define HAVE_REALPATH_NULL' << \!
1634 #include <stdlib.h>
1635 int main(void){
1636 char *x = realpath(".", NULL);
1638 if(x != NULL)
1639 free(x);
1640 return (x != NULL) ? 0 : 1;
1643 then
1648 ## optional and selectable
1650 if feat_no NOALLOCA; then
1651 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1652 # versions of alloca(3) since modern compilers just can't be trusted
1653 # not to overoptimize and silently break some code
1654 run_check alloca '__builtin_alloca()' \
1655 '#define HAVE_ALLOCA __builtin_alloca' << \!
1656 #include <stdio.h> /* For C89 NULL */
1657 int main(void){
1658 void *vp = __builtin_alloca(1);
1660 return (vp != NULL);
1665 if feat_yes DOTLOCK; then
1666 if run_check readlink 'readlink(2)' << \!
1667 #include <unistd.h>
1668 # include <errno.h>
1669 int main(void){
1670 char buf[128];
1672 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1673 return 0;
1674 return 1;
1677 then
1679 else
1680 feat_bail_required DOTLOCK
1684 if feat_yes DOTLOCK; then
1685 if run_check fchown 'fchown(2)' << \!
1686 #include <unistd.h>
1687 # include <errno.h>
1688 int main(void){
1689 if(!fchown(0, 0, 0) || errno != ENOSYS)
1690 return 0;
1691 return 1;
1694 then
1696 else
1697 feat_bail_required DOTLOCK
1701 ## Now it is the time to fork away the BASE_ series
1703 ${rm} -f ${tmp}
1704 squeeze_em ${inc} ${tmp}
1705 ${mv} ${tmp} ${inc}
1706 squeeze_em ${lib} ${tmp}
1707 ${mv} ${tmp} ${lib}
1709 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1710 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1712 ## The remains are expected to be used only by the main MUA binary!
1714 OPT_LOCALES=0
1715 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1716 #include <locale.h>
1717 int main(void){
1718 setlocale(LC_ALL, "");
1719 return 0;
1722 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1724 OPT_MULTIBYTE_CHARSETS=0
1725 OPT_WIDE_GLYPHS=0
1726 OPT_TERMINAL_CHARSET=0
1727 if [ -n "${have_setlocale}" ]; then
1728 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1729 '#define HAVE_C90AMEND1' << \!
1730 #include <limits.h>
1731 #include <stdlib.h>
1732 #include <wchar.h>
1733 #include <wctype.h>
1734 int main(void){
1735 char mbb[MB_LEN_MAX + 1];
1736 wchar_t wc;
1738 iswprint(L'c');
1739 towupper(L'c');
1740 mbtowc(&wc, "x", 1);
1741 mbrtowc(&wc, "x", 1, NULL);
1742 wctomb(mbb, wc);
1743 return (mblen("\0", 1) == 0);
1746 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1748 if [ -n "${have_c90amend1}" ]; then
1749 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1750 #include <wchar.h>
1751 int main(void){
1752 wcwidth(L'c');
1753 return 0;
1756 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1759 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1760 #include <langinfo.h>
1761 #include <stdlib.h>
1762 int main(void){
1763 nl_langinfo(DAY_1);
1764 return (nl_langinfo(CODESET) == NULL);
1767 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1768 fi # have_setlocale
1770 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1771 #include <fnmatch.h>
1772 int main(void){
1773 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1777 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1778 #include <dirent.h>
1779 int main(void){
1780 struct dirent de;
1781 return !(de.d_type == DT_UNKNOWN ||
1782 de.d_type == DT_DIR || de.d_type == DT_LNK);
1786 ## optional and selectable
1788 if feat_yes ICONV; then
1789 ${cat} > ${tmp2}.c << \!
1790 #include <stdio.h> /* For C89 NULL */
1791 #include <iconv.h>
1792 int main(void){
1793 iconv_t id;
1795 id = iconv_open("foo", "bar");
1796 iconv(id, NULL, NULL, NULL, NULL);
1797 iconv_close(id);
1798 return 0;
1801 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1802 '#define HAVE_ICONV' ||
1803 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1804 '#define HAVE_ICONV' '-liconv' ||
1805 feat_bail_required ICONV
1806 else
1807 echo '/* OPT_ICONV=0 */' >> ${h}
1808 fi # feat_yes ICONV
1810 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1811 ${cat} > ${tmp2}.c << \!
1812 #include <sys/types.h>
1813 #include <sys/socket.h>
1814 #include <sys/un.h>
1815 # include <errno.h>
1816 int main(void){
1817 struct sockaddr_un soun;
1819 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1820 return 1;
1821 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1822 return 1;
1823 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1824 return 1;
1825 return 0;
1829 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1830 '#define HAVE_UNIX_SOCKETS' ||
1831 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1832 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1833 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1834 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1837 if feat_yes SOCKETS; then
1838 ${cat} > ${tmp2}.c << \!
1839 #include "config.h"
1840 #include <sys/types.h>
1841 #include <sys/socket.h>
1842 #include <netinet/in.h>
1843 # include <errno.h>
1844 int main(void){
1845 struct sockaddr s;
1847 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1848 return 1;
1849 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1850 return 1;
1851 return 0;
1855 < ${tmp2}.c run_check sockets 'sockets' \
1856 '#define HAVE_SOCKETS' ||
1857 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1858 '#define HAVE_SOCKETS' '-lnsl' ||
1859 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1860 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1861 feat_bail_required SOCKETS
1862 else
1863 echo '/* OPT_SOCKETS=0 */' >> ${h}
1864 fi # feat_yes SOCKETS
1866 if feat_yes SOCKETS; then
1867 link_check getaddrinfo 'getaddrinfo(3)' \
1868 '#define HAVE_GETADDRINFO' << \!
1869 #include "config.h"
1870 #include <sys/types.h>
1871 #include <sys/socket.h>
1872 #include <stdio.h>
1873 #include <netdb.h>
1874 int main(void){
1875 struct addrinfo a, *ap;
1876 int lrv;
1878 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1879 case EAI_NONAME:
1880 case EAI_SERVICE:
1881 default:
1882 fprintf(stderr, "%s\n", gai_strerror(lrv));
1883 case 0:
1884 break;
1886 return 0;
1891 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1892 compile_check arpa_inet_h '<arpa/inet.h>' \
1893 '#define HAVE_ARPA_INET_H' << \!
1894 #include "config.h"
1895 #include <sys/types.h>
1896 #include <sys/socket.h>
1897 #include <netdb.h>
1898 #include <netinet/in.h>
1899 #include <arpa/inet.h>
1902 ${cat} > ${tmp2}.c << \!
1903 #include "config.h"
1904 #include <sys/types.h>
1905 #include <sys/socket.h>
1906 #include <stdio.h>
1907 #include <string.h>
1908 #include <netdb.h>
1909 #include <netinet/in.h>
1910 #ifdef HAVE_ARPA_INET_H
1911 #include <arpa/inet.h>
1912 #endif
1913 int main(void){
1914 struct sockaddr_in servaddr;
1915 unsigned short portno;
1916 struct servent *ep;
1917 struct hostent *hp;
1918 struct in_addr **pptr;
1920 portno = 0;
1921 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1922 portno = (unsigned short)ep->s_port;
1924 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1925 pptr = (struct in_addr**)hp->h_addr_list;
1926 if(hp->h_addrtype != AF_INET)
1927 fprintf(stderr, "au\n");
1928 }else{
1929 switch(h_errno){
1930 case HOST_NOT_FOUND:
1931 case TRY_AGAIN:
1932 case NO_RECOVERY:
1933 case NO_DATA:
1934 break;
1935 default:
1936 fprintf(stderr, "au\n");
1937 break;
1941 memset(&servaddr, 0, sizeof servaddr);
1942 servaddr.sin_family = AF_INET;
1943 servaddr.sin_port = htons(portno);
1944 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1945 fprintf(stderr, "Would connect to %s:%d ...\n",
1946 inet_ntoa(**pptr), (int)portno);
1947 return 0;
1951 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1952 < ${tmp2}.c link_check gethostbyname \
1953 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1954 < ${tmp2}.c link_check gethostbyname \
1955 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1956 '' '-lsocket -lnsl' ||
1957 feat_bail_required SOCKETS
1960 feat_yes SOCKETS &&
1961 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1962 #include <sys/socket.h>
1963 #include <stdlib.h>
1964 # include <errno.h>
1965 int main(void){
1966 int sockfd = 3;
1968 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1969 errno == ENOSYS)
1970 return 1;
1971 return 0;
1975 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1976 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1977 #include <sys/socket.h>
1978 #include <stdlib.h>
1979 int main(void){
1980 struct timeval tv;
1981 int sockfd = 3;
1983 tv.tv_sec = 42;
1984 tv.tv_usec = 21;
1985 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1986 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1987 return 0;
1991 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1992 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1993 #include <sys/socket.h>
1994 #include <stdlib.h>
1995 int main(void){
1996 struct linger li;
1997 int sockfd = 3;
1999 li.l_onoff = 1;
2000 li.l_linger = 42;
2001 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2002 return 0;
2006 if feat_yes SSL; then
2007 if link_check ssl_tls 'TLS/SSL (new style *_client_method(3ssl))' \
2008 '#define HAVE_SSL
2009 #define HAVE_SSL_TLS 10100' '-lssl -lcrypto' << \!
2010 #include <openssl/ssl.h>
2011 #include <openssl/err.h>
2012 #include <openssl/x509v3.h>
2013 #include <openssl/x509.h>
2014 #include <openssl/rand.h>
2015 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2016 # error We need TLSv1.
2017 #endif
2018 int main(void){
2019 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2021 SSL_CTX_free(ctx);
2022 PEM_read_PrivateKey(0, 0, 0, 0);
2023 return 0;
2026 then
2028 elif link_check ssl_tls 'TLS/SSL (old style *_client_method(3ssl))' \
2029 '#define HAVE_SSL
2030 #define HAVE_SSL_TLS 10000' '-lssl -lcrypto' << \!
2031 #include <openssl/ssl.h>
2032 #include <openssl/err.h>
2033 #include <openssl/x509v3.h>
2034 #include <openssl/x509.h>
2035 #include <openssl/rand.h>
2036 #if defined OPENSSL_NO_SSL3 &&\
2037 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2038 # error We need one of SSLv3 and TLSv1.
2039 #endif
2040 int main(void){
2041 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2043 SSL_CTX_free(ctx);
2044 PEM_read_PrivateKey(0, 0, 0, 0);
2045 return 0;
2048 then
2050 else
2051 feat_bail_required SSL
2054 if [ "${have_ssl_tls}" = 'yes' ]; then
2055 compile_check ssl_tls_stack_of 'TLS/SSL STACK_OF()' \
2056 '#define HAVE_SSL_TLS_STACK_OF' << \!
2057 #include <stdio.h> /* For C89 NULL */
2058 #include <openssl/ssl.h>
2059 #include <openssl/err.h>
2060 #include <openssl/x509v3.h>
2061 #include <openssl/x509.h>
2062 #include <openssl/rand.h>
2063 int main(void){
2064 STACK_OF(GENERAL_NAME) *gens = NULL;
2066 printf("%p", gens); /* to use it */
2067 return 0;
2071 link_check ssl_tls_conf 'OpenSSL_modules_load_file() support' \
2072 '#define HAVE_SSL_TLS_CONFIG' << \!
2073 #include <stdio.h> /* For C89 NULL */
2074 #include <openssl/conf.h>
2075 int main(void){
2076 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2077 CONF_modules_free();
2078 return 0;
2082 link_check ssl_tls_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2083 '#define HAVE_SSL_TLS_CONF_CTX' << \!
2084 #include "config.h"
2085 #include <openssl/ssl.h>
2086 #include <openssl/err.h>
2087 int main(void){
2088 #if HAVE_SSL_TLS < 10100
2089 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2090 #else
2091 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2092 #endif
2093 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2095 SSL_CONF_CTX_set_flags(cctx,
2096 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2097 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2098 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2099 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2100 SSL_CONF_CTX_finish(cctx);
2101 SSL_CONF_CTX_free(cctx);
2102 SSL_CTX_free(ctx);
2103 return 0;
2107 link_check ssl_tls_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2108 '#define HAVE_SSL_TLS_RAND_EGD' << \!
2109 #include <openssl/rand.h>
2110 int main(void){
2111 return RAND_egd("some.where") > 0;
2115 if feat_yes SSL_ALL_ALGORITHMS; then
2116 if link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2117 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2118 #include <openssl/evp.h>
2119 int main(void){
2120 OpenSSL_add_all_algorithms();
2121 EVP_get_cipherbyname("two cents i never exist");
2122 EVP_cleanup();
2123 return 0;
2126 then
2128 else
2129 feat_bail_required SSL_ALL_ALGORITHMS
2131 fi # SSL_ALL_ALGORITHMS
2133 if feat_yes MD5 && feat_no NOEXTMD5; then
2134 run_check ssl_md5 'MD5 digest in the used crypto library' \
2135 '#define HAVE_SSL_MD5' << \!
2136 #include <stdlib.h>
2137 #include <string.h>
2138 #include <openssl/md5.h>
2139 int main(void){
2140 char const dat[] = "abrakadabrafidibus";
2141 char dig[16], hex[16 * 2];
2142 MD5_CTX ctx;
2143 size_t i, j;
2145 memset(dig, 0, sizeof(dig));
2146 memset(hex, 0, sizeof(hex));
2147 MD5_Init(&ctx);
2148 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2149 MD5_Final(dig, &ctx);
2151 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2152 for(i = 0; i < sizeof(hex) / 2; i++){
2153 j = i << 1;
2154 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2155 hex[++j] = hexchar(dig[i] & 0x0f);
2157 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2160 fi # feat_yes MD5 && feat_no NOEXTMD5
2162 else
2163 echo '/* OPT_SSL=0 */' >> ${h}
2164 fi # feat_yes SSL
2166 if [ "${have_ssl_tls}" = 'yes' ]; then
2167 OPT_SMIME=1
2168 else
2169 OPT_SMIME=1
2172 if feat_yes SMTP; then
2173 echo '#define HAVE_SMTP' >> ${h}
2174 else
2175 echo '/* OPT_SMTP=0 */' >> ${h}
2178 if feat_yes POP3; then
2179 echo '#define HAVE_POP3' >> ${h}
2180 else
2181 echo '/* OPT_POP3=0 */' >> ${h}
2184 if feat_yes GSSAPI; then
2185 ${cat} > ${tmp2}.c << \!
2186 #include <gssapi/gssapi.h>
2187 int main(void){
2188 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2189 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2190 return 0;
2193 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2195 if command -v krb5-config >/dev/null 2>&1; then
2196 i=`command -v krb5-config`
2197 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2198 GSS_INCS="`CFLAGS= ${i} --cflags`"
2199 i='GSS-API via krb5-config(1)'
2200 else
2201 GSS_LIBS='-lgssapi'
2202 GSS_INCS=
2203 i='GSS-API in gssapi/gssapi.h, libgssapi'
2205 if < ${tmp2}.c link_check gss \
2206 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2207 < ${tmp3}.c link_check gss \
2208 'GSS-API in gssapi.h, libgssapi' \
2209 '#define HAVE_GSSAPI
2210 #define GSSAPI_REG_INCLUDE' \
2211 '-lgssapi' ||\
2212 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2213 '#define HAVE_GSSAPI' \
2214 '-lgssapi_krb5' ||\
2215 < ${tmp3}.c link_check gss \
2216 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2217 '#define HAVE_GSSAPI
2218 #define GSS_REG_INCLUDE' \
2219 '-lgssapi -lkrb5 -lcrypto' \
2220 '-I/usr/include/kerberosV' ||\
2221 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2222 '#define HAVE_GSSAPI' \
2223 '-lgss' ||\
2224 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2225 '#define HAVE_GSSAPI
2226 #define GSSAPI_OLD_STYLE' \
2227 '-lgssapi_krb5' << \!
2228 #include <gssapi/gssapi.h>
2229 #include <gssapi/gssapi_generic.h>
2230 int main(void){
2231 gss_import_name(0, 0, gss_nt_service_name, 0);
2232 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2233 return 0;
2236 then
2238 else
2239 feat_bail_required GSSAPI
2241 else
2242 echo '/* OPT_GSSAPI=0 */' >> ${h}
2243 fi # feat_yes GSSAPI
2245 if feat_yes NETRC; then
2246 echo '#define HAVE_NETRC' >> ${h}
2247 else
2248 echo '/* OPT_NETRC=0 */' >> ${h}
2251 if feat_yes AGENT; then
2252 echo '#define HAVE_AGENT' >> ${h}
2253 else
2254 echo '/* OPT_AGENT=0 */' >> ${h}
2257 if feat_yes IDNA; then
2258 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2259 '-lidn' << \!
2260 #include <idna.h>
2261 #include <idn-free.h>
2262 #include <stringprep.h>
2263 int main(void){
2264 char *utf8, *idna_ascii, *idna_utf8;
2266 utf8 = stringprep_locale_to_utf8("does.this.work");
2267 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2268 != IDNA_SUCCESS)
2269 return 1;
2270 idn_free(idna_ascii);
2271 /* (Rather link check only here) */
2272 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2273 return 0;
2276 then
2278 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2279 '-lidnkit' << \!
2280 #include <stdio.h>
2281 #include <idn/api.h>
2282 #include <idn/result.h>
2283 int main(void){
2284 idn_result_t r;
2285 char ace_name[256];
2286 char local_name[256];
2288 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2289 sizeof(ace_name));
2290 if (r != idn_success) {
2291 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2292 return 1;
2294 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2295 if (r != idn_success) {
2296 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2297 return 1;
2299 return 0;
2302 then
2304 else
2305 feat_bail_required IDNA
2308 if [ -n "${have_idna}" ]; then
2309 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2310 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2312 else
2313 echo '/* OPT_IDNA=0 */' >> ${h}
2316 if feat_yes IMAP_SEARCH; then
2317 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2318 else
2319 echo '/* OPT_IMAP_SEARCH=0 */' >> ${h}
2322 if feat_yes REGEX; then
2323 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2324 #include <regex.h>
2325 #include <stdlib.h>
2326 int main(void){
2327 int status;
2328 regex_t re;
2330 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2331 return 1;
2332 status = regexec(&re, "plan9", 0,NULL, 0);
2333 regfree(&re);
2334 return !(status == REG_NOMATCH);
2337 then
2339 else
2340 feat_bail_required REGEX
2342 else
2343 echo '/* OPT_REGEX=0 */' >> ${h}
2346 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2347 have_mle=1
2348 echo '#define HAVE_MLE' >> ${h}
2349 else
2350 feat_bail_required MLE
2351 echo '/* OPT_MLE=0 */' >> ${h}
2354 # Generic have-a-line-editor switch for those who need it below
2355 if [ -n "${have_mle}" ]; then
2356 have_cle=1
2359 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2360 echo '#define HAVE_HISTORY' >> ${h}
2361 else
2362 echo '/* OPT_HISTORY=0 */' >> ${h}
2365 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2366 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2367 else
2368 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2371 if feat_yes TERMCAP; then
2372 __termcaplib() {
2373 link_check termcap "termcap(5) (via ${4})" \
2374 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2375 #include <stdio.h>
2376 #include <stdlib.h>
2377 ${2}
2378 #include <term.h>
2379 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2380 static int my_putc(int c){return putchar(c);}
2381 int main(void){
2382 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2383 int r2 = OK, r3 = ERR;
2385 tgetent(buf, getenv("TERM"));
2386 cpb = cmdbuf;
2387 r1 = tgetstr(UNCONST("cm"), &cpb);
2388 tgoto(r1, 1, 1);
2389 r2 = tgetnum(UNCONST("Co"));
2390 r3 = tgetflag(UNCONST("ut"));
2391 tputs("cr", 1, &my_putc);
2392 return (r1 == NULL || r2 == -1 || r3 == 0);
2394 _EOT
2397 __terminfolib() {
2398 link_check terminfo "terminfo(5) (via ${2})" \
2399 '#define HAVE_TERMCAP
2400 #define HAVE_TERMCAP_CURSES
2401 #define HAVE_TERMINFO' "${1}" << _EOT
2402 #include <stdio.h>
2403 #include <curses.h>
2404 #include <term.h>
2405 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2406 static int my_putc(int c){return putchar(c);}
2407 int main(void){
2408 int er, r0, r1, r2;
2409 char *r3, *tp;
2411 er = OK;
2412 r0 = setupterm(NULL, 1, &er);
2413 r1 = tigetflag(UNCONST("bce"));
2414 r2 = tigetnum(UNCONST("colors"));
2415 r3 = tigetstr(UNCONST("cr"));
2416 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2417 tputs(tp, 1, &my_putc);
2418 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2419 r3 == (char*)-1 || r3 == NULL);
2421 _EOT
2424 if feat_yes TERMCAP_VIA_TERMINFO; then
2425 __terminfolib -ltinfo -ltinfo ||
2426 __terminfolib -lcurses -lcurses ||
2427 __terminfolib -lcursesw -lcursesw ||
2428 feat_bail_required TERMCAP_VIA_TERMINFO
2431 if [ -z "${have_terminfo}" ]; then
2432 __termcaplib -ltermcap '' '' '-ltermcap' ||
2433 __termcaplib -ltermcap '#include <curses.h>' '
2434 #define HAVE_TERMCAP_CURSES' \
2435 'curses.h / -ltermcap' ||
2436 __termcaplib -lcurses '#include <curses.h>' '
2437 #define HAVE_TERMCAP_CURSES' \
2438 'curses.h / -lcurses' ||
2439 __termcaplib -lcursesw '#include <curses.h>' '
2440 #define HAVE_TERMCAP_CURSES' \
2441 'curses.h / -lcursesw' ||
2442 feat_bail_required TERMCAP
2444 if [ -n "${have_termcap}" ]; then
2445 run_check tgetent_null \
2446 "tgetent(3) of termcap(5) takes NULL buffer" \
2447 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2448 #include <stdio.h> /* For C89 NULL */
2449 #include <stdlib.h>
2450 #ifdef HAVE_TERMCAP_CURSES
2451 # include <curses.h>
2452 #endif
2453 #include <term.h>
2454 int main(void){
2455 tgetent(NULL, getenv("TERM"));
2456 return 0;
2458 _EOT
2461 else
2462 echo '/* OPT_TERMCAP=0 */' >> ${h}
2463 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2466 if feat_yes SPAM_SPAMC; then
2467 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2468 if command -v spamc >/dev/null 2>&1; then
2469 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2471 else
2472 echo '/* OPT_SPAM_SPAMC=0 */' >> ${h}
2475 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2476 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2477 else
2478 feat_bail_required SPAM_SPAMD
2479 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2482 feat_def SPAM_FILTER
2484 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2485 echo '#define HAVE_SPAM' >> ${h}
2486 else
2487 echo '/* HAVE_SPAM */' >> ${h}
2490 if feat_yes QUOTE_FOLD &&\
2491 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2492 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2493 else
2494 feat_bail_required QUOTE_FOLD
2495 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2498 feat_def FILTER_HTML_TAGSOUP
2499 feat_def COLOUR
2500 feat_def DOTLOCK
2501 feat_def MD5
2502 feat_def NOMEMDBG
2504 ## Summarizing
2506 ${rm} -f ${tmp}
2507 squeeze_em ${inc} ${tmp}
2508 ${mv} ${tmp} ${inc}
2509 squeeze_em ${lib} ${tmp}
2510 ${mv} ${tmp} ${lib}
2512 # config.h
2513 ${mv} ${h} ${tmp}
2514 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2515 ${cat} ${tmp} >> ${h}
2516 ${rm} -f ${tmp}
2517 printf '\n' >> ${h}
2519 # Create the real mk.mk
2520 # Note we cannout use explicit ./ filename prefix for source and object
2521 # pathnames because of a bug in bmake(1)
2522 ${rm} -rf ${tmp0}.* ${tmp0}*
2523 printf 'OBJ_SRC = ' >> ${mk}
2524 if feat_no AMALGAMATION; then
2525 for i in `printf '%s\n' *.c | ${sort}`; do
2526 if [ "${i}" = privsep.c ]; then
2527 continue
2529 printf "${i} " >> ${mk}
2530 done
2531 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2532 else
2533 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2535 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2536 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2537 printf '# undef _CONFIG_H\n' >> ${h}
2538 printf '# define _CONFIG_H 2\n' >> ${h}
2539 for i in `printf '%s\n' *.c | ${sort}`; do
2540 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2541 [ "${i}" = privsep.c ]; then
2542 continue
2544 printf "${i} " >> ${mk}
2545 printf "# include \"${i}\"\n" >> ${h}
2546 done
2547 echo >> ${mk}
2548 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2549 echo '#else' >> ${h}
2552 # Finally, create the string that is used by *features* and `version'.
2553 # Take this nice opportunity and generate a visual listing of included and
2554 # non-included features for the person who runs the configuration
2555 msg '\nThe following features are included (+) or not (-):'
2556 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2557 printf '/* The "feature string" */\n' >> ${h}
2558 # Because + is expanded by *folder* if first in "echo $features", put something
2559 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2560 sep=
2561 for opt
2563 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2564 feat_yes ${opt} && sign=+ || sign=-
2565 printf -- "${sep}${sign}${sopt}" >> ${h}
2566 sep=','
2567 i=`option_doc_of ${opt}`
2568 [ -z "${i}" ] && continue
2569 msg " %s %s: %s" ${sign} ${sopt} "${i}"
2570 done
2571 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2572 #exec 5>&1 >>${h}
2573 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2574 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2576 printf '"\n#endif /* n_CONFIG_H */\n' >> ${h}
2578 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2579 echo "INCS = `${cat} ${inc}`" >> ${mk}
2580 echo >> ${mk}
2581 ${cat} ./mk-mk.in >> ${mk}
2583 ## Finished!
2585 msg '\nSetup:'
2586 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2587 msg ' . bindir: %s' "${VAL_BINDIR}"
2588 if feat_yes DOTLOCK; then
2589 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2591 msg ' . mandir: %s' "${VAL_MANDIR}"
2592 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2593 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2594 msg ''
2596 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2597 exit 0
2599 msg 'Remarks:'
2600 if [ -z "${have_fnmatch}" ]; then
2601 msg ' . The function fnmatch(3) could not be found.'
2602 msg ' Filename patterns like wildcard are not supported on your system'
2604 if [ -z "${have_fchdir}" ]; then
2605 msg ' . The function fchdir(2) could not be found.'
2606 msg ' We will use chdir(2) instead.'
2607 msg ' This is a problem only if the current working directory is changed'
2608 msg ' while this program is inside of it'
2610 msg ''
2612 # s-it-mode