Domain update
[s-mailx.git] / mk-conf.sh
blobfb16d7788824ac293f12306ce2312b2c77172546
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)' \
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 MBYTE_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 *feature* 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 OPT_DEVEL=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 i="`${awk} -v input=\"${2}\" '
647 BEGIN{
648 for(i = 0;;){
649 voff = match(input, /[[:alnum:]_]+(='"'"'[^'"'"']+)?/)
650 if(voff == 0)
651 break
652 v = substr(input, voff, RLENGTH)
653 input = substr(input, voff + RLENGTH)
654 doff = index(v, "=")
655 if(doff > 0){
656 d = substr(v, doff + 2, length(v) - doff - 1)
657 v = substr(v, 1, doff - 1)
659 print v
663 eval ${1}=\"${i}\"
666 option_doc_of() {
667 # Return the "documentation string" for option $1, itself if none such
668 ${awk} -v want="${1}" \
669 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
670 BEGIN{
671 for(;;){
672 voff = match(input, /[[:alnum:]_]+(='"'"'[^'"'"']+)?/)
673 if(voff == 0)
674 break
675 v = substr(input, voff, RLENGTH)
676 input = substr(input, voff + RLENGTH)
677 doff = index(v, "=")
678 if(doff > 0){
679 d = substr(v, doff + 2, length(v) - doff - 1)
680 v = substr(v, 1, doff - 1)
681 }else
682 d = v
683 if(v == want){
684 if(d != "-")
685 print d
686 exit
693 option_join_rc() {
694 # Join the values from make.rc into what currently is defined, not
695 # overwriting yet existing settings
696 ${rm} -f ${tmp}
697 # We want read(1) to perform backslash escaping in order to be able to use
698 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow
699 # in VMs (see [fa2e248]), Aharon Robbins suggested the following
700 < ${rc} ${awk} 'BEGIN{line = ""}{
701 gsub(/^[[:space:]]+/, "", $0)
702 gsub(/[[:space:]]+$/, "", $0)
703 if(gsub(/\\$/, "", $0)){
704 line = line $0
705 next
706 }else
707 line = line $0
708 if(index(line, "#") == 1){
709 line = ""
710 }else if(length(line)){
711 print line
712 line = ""
714 }' |
715 while read line; do
716 if [ -n "${good_shell}" ]; then
717 i=${line%%=*}
718 else
719 i=`${awk} -v LINE="${line}" 'BEGIN{
720 gsub(/=.*$/, "", LINE)
721 print LINE
724 if [ "${i}" = "${line}" ]; then
725 msg 'ERROR: invalid syntax in: %s' "${line}"
726 continue
729 eval j="\$${i}" jx="\${${i}+x}"
730 if [ -n "${j}" ] || [ "${jx}" = x ]; then
731 : # Yet present
732 else
733 j=`${awk} -v LINE="${line}" 'BEGIN{
734 gsub(/^[^=]*=/, "", LINE)
735 gsub(/^\"*/, "", LINE)
736 gsub(/\"*$/, "", LINE)
737 print LINE
740 [ "${i}" = "DESTDIR" ] && continue
741 echo "${i}=\"${j}\""
742 done > ${tmp}
743 # Reread the mixed version right now
744 . ./${tmp}
747 option_evaluate() {
748 # Expand the option values, which may contain shell snippets
749 ${rm} -f ${newlst} ${newmk} ${newh}
750 exec 5<&0 6>&1 <${tmp} >${newlst}
751 while read line; do
753 if [ -n "${good_shell}" ]; then
754 i=${line%%=*}
755 [ "${i}" != "${i#OPT_}" ] && z=1
756 else
757 i=`${awk} -v LINE="${line}" 'BEGIN{
758 gsub(/=.*$/, "", LINE);\
759 print LINE
761 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
766 eval j=\$${i}
767 if [ -n "${z}" ]; then
768 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
769 if [ -z "${j}" ] || feat_val_no "${j}"; then
771 printf " /* #undef ${i} */\n" >> ${newh}
772 elif feat_val_yes "${j}"; then
773 if feat_val_require "${j}"; then
774 j=require
775 else
778 printf " /* #define ${i} */\n" >> ${newh}
779 else
780 msg 'ERROR: cannot parse <%s>' "${line}"
781 config_exit 1
783 else
784 printf "#define ${i} \"${j}\"\n" >> ${newh}
786 printf "${i} = ${j}\n" >> ${newmk}
787 printf "${i}=${j}\n"
788 eval "${i}=\"${j}\""
789 done
790 exec 0<&5 1>&6 5<&- 6<&-
793 path_check() {
794 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
795 varname=${1} addflag=${2} flagvarname=${3}
796 j=${IFS}
797 IFS=:
798 eval "set -- \$${1}"
799 IFS=${j}
800 j= k= y= z=
801 for i
803 [ -z "${i}" ] && continue
804 [ -d "${i}" ] || continue
805 # Skip any fakeroot packager environment
806 case "${i}" in *fakeroot*) continue;; esac
807 if [ -n "${j}" ]; then
808 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
810 else
811 y="${y} :${i}:"
812 j="${j}:${i}"
813 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
815 else
816 y=" :${i}:"
817 j="${i}"
818 [ -n "${addflag}" ] && k="${addflag}${i}"
820 done
821 eval "${varname}=\"${j}\""
822 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
823 unset varname
826 ld_runtime_flags() {
827 if [ -n "${need_R_ldflags}" ]; then
828 i=${IFS}
829 IFS=:
830 set -- ${LD_LIBRARY_PATH}
831 IFS=${i}
832 for i
834 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
835 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
836 done
837 export LDFLAGS
839 # Disable it for a possible second run.
840 need_R_ldflags=
843 cc_check() {
844 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
845 if "${CC}" ${INCS} \
846 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
847 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
848 _CFLAGS="${_CFLAGS} ${1}"
849 [ -n "${cc_check_silent}" ] || msg 'yes'
850 return 0
852 [ -n "${cc_check_silent}" ] || msg 'no'
853 return 1
856 ld_check() {
857 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
858 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
859 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
860 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
861 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
862 [ -n "${cc_check_silent}" ] || msg 'yes'
863 return 0
865 [ -n "${cc_check_silent}" ] || msg 'no'
866 return 1
869 _check_preface() {
870 variable=$1 topic=$2 define=$3
872 echo '**********'
873 msg_nonl ' . %s ... ' "${topic}"
874 echo "/* checked ${topic} */" >> ${h}
875 ${rm} -f ${tmp} ${tmp}.o
876 echo '*** test program is'
877 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
878 #echo '*** the preprocessor generates'
879 #${make} -f ${makefile} ${tmp}.x
880 #${cat} ${tmp}.x
881 echo '*** results are'
884 compile_check() {
885 variable=$1 topic=$2 define=$3
887 _check_preface "${variable}" "${topic}" "${define}"
889 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
890 [ -f ./${tmp}.o ]; then
891 msg 'yes'
892 echo "${define}" >> ${h}
893 eval have_${variable}=yes
894 return 0
895 else
896 echo "/* ${define} */" >> ${h}
897 msg 'no'
898 eval unset have_${variable}
899 return 1
903 _link_mayrun() {
904 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
906 _check_preface "${variable}" "${topic}" "${define}"
908 feat_yes CROSS_BUILD && run=0
910 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
911 XLIBS="${LIBS} ${libs}" ./${tmp} &&
912 [ -f ./${tmp} ] &&
913 { [ ${run} -eq 0 ] || ./${tmp}; }; then
914 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
915 msg 'yes'
916 echo "${define}" >> ${h}
917 LIBS="${LIBS} ${libs}"
918 echo "${libs}" >> ${lib}
919 INCS="${INCS} ${incs}"
920 echo "${incs}" >> ${inc}
921 eval have_${variable}=yes
922 return 0
923 else
924 msg 'no'
925 echo "/* ${define} */" >> ${h}
926 eval unset have_${variable}
927 return 1
931 link_check() {
932 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
935 run_check() {
936 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
939 feat_def() {
940 if feat_yes ${1}; then
941 echo '#define HAVE_'${1}'' >> ${h}
942 else
943 echo '/* OPT_'${1}'=0 */' >> ${h}
947 squeeze_em() {
948 < "${1}" > "${2}" ${awk} \
949 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
952 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
954 # First of all, create new configuration and check whether it changed
956 # Very easy checks for the operating system in order to be able to adjust paths
957 # or similar very basic things which we need to be able to go at all
958 os_early_setup
960 # Check those tools right now that we need before including $rc
961 msg 'Checking for basic utility set'
962 check_tool awk "${awk:-`command -v awk`}"
963 check_tool rm "${rm:-`command -v rm`}"
964 check_tool tr "${tr:-`command -v tr`}"
966 # Initialize the option set
967 msg_nonl 'Setting up configuration options ... '
968 option_setup
969 msg 'done'
971 # Include $rc, but only take from it what wasn't overwritten by the user from
972 # within the command line or from a chosen fixed CONFIG=
973 # Note we leave alone the values
974 trap "exit 1" HUP INT TERM
975 trap "${rm} -f ${tmp}" EXIT
977 msg_nonl 'Joining in %s ... ' ${rc}
978 option_join_rc
979 msg 'done'
981 # We need to know about that now, in order to provide utility overwrites etc.
982 os_setup
984 msg 'Checking for remaining set of utilities'
985 check_tool grep "${grep:-`command -v grep`}"
987 # Before we step ahead with the other utilities perform a path cleanup first.
988 path_check PATH
990 # awk(1) above
991 check_tool cat "${cat:-`command -v cat`}"
992 check_tool chmod "${chmod:-`command -v chmod`}"
993 check_tool cp "${cp:-`command -v cp`}"
994 check_tool cmp "${cmp:-`command -v cmp`}"
995 # grep(1) above
996 check_tool mkdir "${mkdir:-`command -v mkdir`}"
997 check_tool mv "${mv:-`command -v mv`}"
998 # rm(1) above
999 check_tool sed "${sed:-`command -v sed`}"
1000 check_tool sort "${sort:-`command -v sort`}"
1001 check_tool tee "${tee:-`command -v tee`}"
1003 check_tool chown "${chown:-`command -v chown`}" 1 ||
1004 check_tool chown "/sbin/chown" 1 ||
1005 check_tool chown "/usr/sbin/chown"
1007 check_tool make "${MAKE:-`command -v make`}"
1008 MAKE=${make}
1009 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1010 HAVE_STRIP=1 || HAVE_STRIP=0
1012 # For ./cc-test.sh only
1013 check_tool cksum "${cksum:-`command -v cksum`}"
1015 # Update OPT_ options now, in order to get possible inter-dependencies right
1016 option_update
1018 # (No functions since some shells loose non-exported variables in traps)
1019 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1020 trap "trap \"\" HUP INT TERM EXIT;\
1021 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1023 # Our configuration options may at this point still contain shell snippets,
1024 # we need to evaluate them in order to get them expanded, and we need those
1025 # evaluated values not only in our new configuration file, but also at hand..
1026 msg_nonl 'Evaluating all configuration items ... '
1027 option_evaluate
1028 msg 'done'
1030 # Add the known utility and some other variables
1031 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_NAIL}\"\n" >> ${newh}
1032 printf "VAL_UAGENT = ${VAL_SID}${VAL_NAIL}\n" >> ${newmk}
1034 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_NAIL}-privsep\"\n" >> ${newh}
1035 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1036 if feat_yes DOTLOCK; then
1037 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1038 else
1039 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1042 for i in \
1043 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1044 MAKE MAKEFLAGS make SHELL strip \
1045 cksum; do
1046 eval j=\$${i}
1047 printf "${i} = ${j}\n" >> ${newmk}
1048 printf "${i}=${j}\n" >> ${newlst}
1049 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1050 done
1051 printf "\n" >> ${newev}
1053 # Build a basic set of INCS and LIBS according to user environment.
1054 path_check C_INCLUDE_PATH -I _INCS
1055 INCS="${INCS} ${_INCS}"
1056 path_check LD_LIBRARY_PATH -L _LIBS
1057 LIBS="${LIBS} ${_LIBS}"
1058 unset _INCS _LIBS
1059 export C_INCLUDE_PATH LD_LIBRARY_PATH
1061 # Some environments need runtime path flags to be able to go at all
1062 ld_runtime_flags
1064 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1066 cc_setup
1068 ${cat} > ${tmp}.c << \!
1069 #include <stdio.h>
1070 #include <string.h>
1071 static void doit(char const *s);
1073 main(int argc, char **argv){
1074 (void)argc;
1075 (void)argv;
1076 doit("Hello world");
1077 return 0;
1079 static void
1080 doit(char const *s){
1081 char buf[12];
1082 memcpy(buf, s, strlen(s) +1);
1083 puts(s);
1087 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1088 -o ${tmp2} ${tmp}.c ${LIBS}; then
1090 else
1091 msg 'ERROR: i cannot compile a "Hello world" via'
1092 msg ' %s' \
1093 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1094 msg 'ERROR: Please read INSTALL, rerun'
1095 config_exit 1
1098 # This may also update ld_runtime_flags() (again)
1099 cc_flags
1101 for i in \
1102 INCS LIBS \
1103 ; do
1104 eval j=\$${i}
1105 printf -- "${i}=${j}\n" >> ${newlst}
1106 done
1107 for i in \
1108 CC \
1109 CFLAGS \
1110 LDFLAGS \
1111 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1112 OSFULLSPEC \
1113 ; do
1114 eval j=\$${i}
1115 printf -- "${i} = ${j}\n" >> ${newmk}
1116 printf -- "${i}=${j}\n" >> ${newlst}
1117 done
1119 # Now finally check whether we already have a configuration and if so, whether
1120 # all those parameters are still the same.. or something has actually changed
1121 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1122 echo 'Configuration is up-to-date'
1123 exit 0
1124 elif [ -f ${lst} ]; then
1125 echo 'Configuration has been updated..'
1126 ( eval "${MAKE} -f ./mk.mk clean" )
1127 echo
1128 else
1129 echo 'Shiny configuration..'
1132 # Time to redefine helper 1
1133 config_exit() {
1134 ${rm} -f ${lst} ${h} ${mk}
1135 exit ${1}
1138 ${mv} -f ${newlst} ${lst}
1139 ${mv} -f ${newev} ${ev}
1140 ${mv} -f ${newh} ${h}
1141 ${mv} -f ${newmk} ${mk}
1143 if [ -z "${VERBOSE}" ]; then
1144 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1145 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1146 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1147 printf -- "ECHO_TEST = @\n" >> ${mk}
1148 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1149 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1150 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1153 ## Compile and link checking
1155 tmp3=./${tmp0}3$$
1156 log=./config.log
1157 lib=./config.lib
1158 inc=./config.inc
1159 makefile=./config.mk
1161 # (No function since some shells loose non-exported variables in traps)
1162 trap "trap \"\" HUP INT TERM;\
1163 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1164 trap "trap \"\" HUP INT TERM EXIT;\
1165 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
1167 # Time to redefine helper 2
1168 msg() {
1169 fmt=${1}
1170 shift
1171 printf "*** ${fmt}\\n" "${@}"
1172 printf -- "${fmt}\\n" "${@}" >&5
1174 msg_nonl() {
1175 fmt=${1}
1176 shift
1177 printf "*** ${fmt}\\n" "${@}"
1178 printf -- "${fmt}" "${@}" >&5
1181 # !!
1182 exec 5>&2 > ${log} 2>&1
1184 echo "${LIBS}" > ${lib}
1185 echo "${INCS}" > ${inc}
1186 ${cat} > ${makefile} << \!
1187 .SUFFIXES: .o .c .x .y
1188 .c.o:
1189 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1190 .c.x:
1191 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1193 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1196 ## Generics
1198 # May be multiline..
1199 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1201 feat_def AMALGAMATION
1202 feat_def CROSS_BUILD
1203 feat_def DEBUG
1204 feat_def DEVEL
1205 feat_def DOCSTRINGS
1206 feat_def ERRORS
1207 feat_def NYD2
1208 feat_def NOMEMDBG
1210 if run_check inline '"inline" functions' \
1211 '#define HAVE_INLINE
1212 #define n_INLINE static inline' << \!
1213 static inline int ilf(int i){return ++i;}
1214 int main(void){return ilf(-1);}
1216 then
1218 elif run_check inline '"__inline" functions' \
1219 '#define HAVE_INLINE
1220 #define n_INLINE static __inline' << \!
1221 static __inline int ilf(int i){return ++i;}
1222 int main(void){return ilf(-1);}
1224 then
1228 if run_check endian 'Little endian byteorder' \
1229 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1230 int main(void){
1231 enum {vBig = 1, vLittle = 0};
1232 union {unsigned short bom; unsigned char buf[2];} u;
1233 u.bom = 0xFEFF;
1234 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1237 then
1241 ## Test for "basic" system-calls / functionality that is used by all parts
1242 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1243 ## macros to be used by only the subprograms (potentially).
1245 if run_check clock_gettime 'clock_gettime(2)' \
1246 '#define HAVE_CLOCK_GETTIME' << \!
1247 #include <time.h>
1248 # include <errno.h>
1249 int main(void){
1250 struct timespec ts;
1252 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1253 return 0;
1254 return 1;
1257 then
1259 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1260 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1261 #include <time.h>
1262 # include <errno.h>
1263 int main(void){
1264 struct timespec ts;
1266 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1267 return 0;
1268 return 1;
1271 then
1273 elif run_check gettimeofday 'gettimeofday(2)' \
1274 '#define HAVE_GETTIMEOFDAY' << \!
1275 #include <stdio.h> /* For C89 NULL */
1276 #include <sys/time.h>
1277 # include <errno.h>
1278 int main(void){
1279 struct timeval tv;
1281 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1282 return 0;
1283 return 1;
1286 then
1288 else
1289 have_no_subsecond_time=1
1292 if run_check nanosleep 'nanosleep(2)' \
1293 '#define HAVE_NANOSLEEP' << \!
1294 #include <time.h>
1295 # include <errno.h>
1296 int main(void){
1297 struct timespec ts;
1299 ts.tv_sec = 1;
1300 ts.tv_nsec = 100000;
1301 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1302 return 0;
1303 return 1;
1306 then
1308 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1309 '#define HAVE_NANOSLEEP' '-lrt' << \!
1310 #include <time.h>
1311 # include <errno.h>
1312 int main(void){
1313 struct timespec ts;
1315 ts.tv_sec = 1;
1316 ts.tv_nsec = 100000;
1317 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1318 return 0;
1319 return 1;
1322 then
1324 # link_check is enough for this, that function is so old, trust the proto
1325 elif link_check sleep 'sleep(3)' \
1326 '#define HAVE_SLEEP' << \!
1327 #include <unistd.h>
1328 # include <errno.h>
1329 int main(void){
1330 if(!sleep(1) || errno != ENOSYS)
1331 return 0;
1332 return 1;
1335 then
1337 else
1338 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1339 config_exit 1
1342 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1343 #include <pwd.h>
1344 #include <unistd.h>
1345 # include <errno.h>
1346 int main(void){
1347 struct passwd *pw;
1348 gid_t gid;
1349 uid_t uid;
1351 if((gid = getgid()) != 0)
1352 gid = getegid();
1353 if((uid = getuid()) != 0)
1354 uid = geteuid();
1355 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1356 return 1;
1357 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1358 return 1;
1359 return 0;
1362 then
1364 else
1365 msg 'ERROR: we require user and group info / database searches.'
1366 msg 'That much Unix we indulge ourselfs.'
1367 config_exit 1
1370 if link_check ftruncate 'ftruncate(2)' \
1371 '#define HAVE_FTRUNCATE' << \!
1372 #include <unistd.h>
1373 #include <sys/types.h>
1374 int main(void){
1375 return (ftruncate(0, 0) != 0);
1378 then
1380 else
1381 msg 'ERROR: we require the ftruncate(2) system call.'
1382 config_exit 1
1385 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1386 #include <signal.h>
1387 # include <errno.h>
1388 int main(void){
1389 struct sigaction nact, oact;
1391 nact.sa_handler = SIG_DFL;
1392 sigemptyset(&nact.sa_mask);
1393 nact.sa_flags = SA_RESTART;
1394 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1397 then
1399 else
1400 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1401 config_exit 1
1404 if link_check snprintf 'snprintf(3)' << \!
1405 #include <stdio.h>
1406 int main(void){
1407 char b[20];
1409 snprintf(b, sizeof b, "%s", "string");
1410 return 0;
1413 then
1415 else
1416 msg 'ERROR: we require the snprintf(3) function.'
1417 config_exit 1
1420 if link_check environ 'environ(3)' << \!
1421 #include <stdio.h> /* For C89 NULL */
1422 int main(void){
1423 extern char **environ;
1425 return environ[0] == NULL;
1428 then
1430 else
1431 msg 'ERROR: we require the environ(3) array for subprocess control.'
1432 config_exit 1
1435 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1436 #include <stdlib.h>
1437 int main(void){
1438 setenv("s-mailx", "i want to see it cute!", 1);
1439 unsetenv("s-mailx");
1440 return 0;
1443 then
1445 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1446 #include <stdlib.h>
1447 int main(void){
1448 putenv("s-mailx=i want to see it cute!");
1449 return 0;
1452 then
1454 else
1455 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1456 config_exit 1
1459 if link_check termios 'termios.h and tc*(3) family' << \!
1460 #include <termios.h>
1461 int main(void){
1462 struct termios tios;
1464 tcgetattr(0, &tios);
1465 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1466 return 0;
1469 then
1471 else
1472 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1473 msg 'That much Unix we indulge ourselfs.'
1474 config_exit 1
1477 ## optional stuff
1479 if link_check vsnprintf 'vsnprintf(3)' << \!
1480 #include <stdarg.h>
1481 #include <stdio.h>
1482 static void dome(char *buf, size_t blen, ...){
1483 va_list ap;
1485 va_start(ap, buf);
1486 vsnprintf(buf, blen, "%s", ap);
1487 va_end(ap);
1489 int main(void){
1490 char b[20];
1492 dome(b, sizeof b, "string");
1493 return 0;
1496 then
1498 else
1499 feat_bail_required ERRORS
1502 if [ "${have_vsnprintf}" = yes ]; then
1503 link_check va_copy 'va_copy(3)' '#define HAVE_VA_COPY' << \!
1504 #include <stdarg.h>
1505 #include <stdio.h>
1506 static void dome2(char *buf, size_t blen, va_list src){
1507 va_list ap;
1509 va_copy(ap, src);
1510 vsnprintf(buf, blen, "%s", ap);
1511 va_end(ap);
1513 static void dome(char *buf, size_t blen, ...){
1514 va_list ap;
1516 va_start(ap, buf);
1517 dome2(buf, blen, ap)
1518 va_end(ap);
1520 int main(void){
1521 char b[20];
1523 dome(b, sizeof b, "string");
1524 return 0;
1529 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1530 #include <unistd.h>
1531 #include <errno.h>
1532 int main(void){
1533 int rv = 0;
1535 errno = 0;
1536 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1537 errno = 0;
1538 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1540 /* Only link check */
1541 fpathconf(0, _PC_NAME_MAX);
1543 return rv;
1547 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1548 #include <fcntl.h>
1549 #include <unistd.h>
1550 # include <errno.h>
1551 int main(void){
1552 int fds[2];
1554 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1555 return 0;
1556 return 1;
1560 # We use this only then for now (need NOW+1)
1561 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1562 #include <fcntl.h> /* For AT_* */
1563 #include <sys/stat.h>
1564 # include <errno.h>
1565 int main(void){
1566 struct timespec ts[2];
1568 ts[0].tv_nsec = UTIME_NOW;
1569 ts[1].tv_nsec = UTIME_OMIT;
1570 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1571 return 0;
1572 return 1;
1578 # XXX Add POSIX check once standardized
1579 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1580 #include <stdlib.h>
1581 int main(void){
1582 arc4random();
1583 return 0;
1586 then
1588 elif [ -n "${have_no_subsecond_time}" ]; then
1589 msg 'ERROR: %s %s' 'without a native random' \
1590 'one of clock_gettime(2) and gettimeofday(2) is required.'
1591 config_exit 1
1594 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1595 #include <stdio.h>
1596 int main(void){
1597 putc_unlocked('@', stdout);
1598 return 0;
1602 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1603 #include <unistd.h>
1604 int main(void){
1605 fchdir(0);
1606 return 0;
1610 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1611 #include <stdlib.h>
1612 int main(void){
1613 char x_buf[4096], *x = realpath(".", x_buf);
1615 return (x != NULL) ? 0 : 1;
1618 then
1619 if run_check realpath_malloc 'realpath(3) takes NULL' \
1620 '#define HAVE_REALPATH_NULL' << \!
1621 #include <stdlib.h>
1622 int main(void){
1623 char *x = realpath(".", NULL);
1625 if(x != NULL)
1626 free(x);
1627 return (x != NULL) ? 0 : 1;
1630 then
1635 ## optional and selectable
1637 if feat_no NOALLOCA; then
1638 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1639 # versions of alloca(3) since modern compilers just can't be trusted
1640 # not to overoptimize and silently break some code
1641 run_check alloca '__builtin_alloca()' \
1642 '#define HAVE_ALLOCA __builtin_alloca' << \!
1643 #include <stdio.h> /* For C89 NULL */
1644 int main(void){
1645 void *vp = __builtin_alloca(1);
1647 return (vp != NULL);
1652 if feat_yes DOTLOCK; then
1653 if run_check readlink 'readlink(2)' << \!
1654 #include <unistd.h>
1655 # include <errno.h>
1656 int main(void){
1657 char buf[128];
1659 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1660 return 0;
1661 return 1;
1664 then
1666 else
1667 feat_bail_required DOTLOCK
1671 if feat_yes DOTLOCK; then
1672 if run_check fchown 'fchown(2)' << \!
1673 #include <unistd.h>
1674 # include <errno.h>
1675 int main(void){
1676 if(!fchown(0, 0, 0) || errno != ENOSYS)
1677 return 0;
1678 return 1;
1681 then
1683 else
1684 feat_bail_required DOTLOCK
1688 ## Now it is the time to fork away the BASE_ series
1690 ${rm} -f ${tmp}
1691 squeeze_em ${inc} ${tmp}
1692 ${mv} ${tmp} ${inc}
1693 squeeze_em ${lib} ${tmp}
1694 ${mv} ${tmp} ${lib}
1696 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1697 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1699 ## The remains are expected to be used only by the main MUA binary!
1701 OPT_LOCALES=0
1702 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1703 #include <locale.h>
1704 int main(void){
1705 setlocale(LC_ALL, "");
1706 return 0;
1709 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1711 OPT_MBYTE_CHARSETS=0
1712 OPT_WIDE_GLYPHS=0
1713 OPT_TERMINAL_CHARSET=0
1714 if [ -n "${have_setlocale}" ]; then
1715 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1716 '#define HAVE_C90AMEND1' << \!
1717 #include <limits.h>
1718 #include <stdlib.h>
1719 #include <wchar.h>
1720 #include <wctype.h>
1721 int main(void){
1722 char mbb[MB_LEN_MAX + 1];
1723 wchar_t wc;
1725 iswprint(L'c');
1726 towupper(L'c');
1727 mbtowc(&wc, "x", 1);
1728 mbrtowc(&wc, "x", 1, NULL);
1729 wctomb(mbb, wc);
1730 return (mblen("\0", 1) == 0);
1733 [ -n "${have_c90amend1}" ] && OPT_MBYTE_CHARSETS=1
1735 if [ -n "${have_c90amend1}" ]; then
1736 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1737 #include <wchar.h>
1738 int main(void){
1739 wcwidth(L'c');
1740 return 0;
1743 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1746 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1747 #include <langinfo.h>
1748 #include <stdlib.h>
1749 int main(void){
1750 nl_langinfo(DAY_1);
1751 return (nl_langinfo(CODESET) == NULL);
1754 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1755 fi # have_setlocale
1757 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1758 #include <fnmatch.h>
1759 int main(void){
1760 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1764 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1765 #include <dirent.h>
1766 int main(void){
1767 struct dirent de;
1768 return !(de.d_type == DT_UNKNOWN ||
1769 de.d_type == DT_DIR || de.d_type == DT_LNK);
1773 ## optional and selectable
1775 if feat_yes ICONV; then
1776 ${cat} > ${tmp2}.c << \!
1777 #include <stdio.h> /* For C89 NULL */
1778 #include <iconv.h>
1779 int main(void){
1780 iconv_t id;
1782 id = iconv_open("foo", "bar");
1783 iconv(id, NULL, NULL, NULL, NULL);
1784 iconv_close(id);
1785 return 0;
1788 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1789 '#define HAVE_ICONV' ||
1790 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1791 '#define HAVE_ICONV' '-liconv' ||
1792 feat_bail_required ICONV
1793 else
1794 echo '/* OPT_ICONV=0 */' >> ${h}
1795 fi # feat_yes ICONV
1797 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1798 ${cat} > ${tmp2}.c << \!
1799 #include <sys/types.h>
1800 #include <sys/socket.h>
1801 #include <sys/un.h>
1802 # include <errno.h>
1803 int main(void){
1804 struct sockaddr_un soun;
1806 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1807 return 1;
1808 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1809 return 1;
1810 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1811 return 1;
1812 return 0;
1816 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1817 '#define HAVE_UNIX_SOCKETS' ||
1818 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1819 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1820 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1821 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1824 if feat_yes SOCKETS; then
1825 ${cat} > ${tmp2}.c << \!
1826 #include "config.h"
1827 #include <sys/types.h>
1828 #include <sys/socket.h>
1829 #include <netinet/in.h>
1830 # include <errno.h>
1831 int main(void){
1832 struct sockaddr s;
1834 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1835 return 1;
1836 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1837 return 1;
1838 return 0;
1842 < ${tmp2}.c run_check sockets 'sockets' \
1843 '#define HAVE_SOCKETS' ||
1844 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1845 '#define HAVE_SOCKETS' '-lnsl' ||
1846 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1847 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1848 feat_bail_required SOCKETS
1849 else
1850 echo '/* OPT_SOCKETS=0 */' >> ${h}
1851 fi # feat_yes SOCKETS
1853 if feat_yes SOCKETS; then
1854 link_check getaddrinfo 'getaddrinfo(3)' \
1855 '#define HAVE_GETADDRINFO' << \!
1856 #include "config.h"
1857 #include <sys/types.h>
1858 #include <sys/socket.h>
1859 #include <stdio.h>
1860 #include <netdb.h>
1861 int main(void){
1862 struct addrinfo a, *ap;
1863 int lrv;
1865 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1866 case EAI_NONAME:
1867 case EAI_SERVICE:
1868 default:
1869 fprintf(stderr, "%s\n", gai_strerror(lrv));
1870 case 0:
1871 break;
1873 return 0;
1878 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1879 compile_check arpa_inet_h '<arpa/inet.h>' \
1880 '#define HAVE_ARPA_INET_H' << \!
1881 #include "config.h"
1882 #include <sys/types.h>
1883 #include <sys/socket.h>
1884 #include <netdb.h>
1885 #include <netinet/in.h>
1886 #include <arpa/inet.h>
1889 ${cat} > ${tmp2}.c << \!
1890 #include "config.h"
1891 #include <sys/types.h>
1892 #include <sys/socket.h>
1893 #include <stdio.h>
1894 #include <string.h>
1895 #include <netdb.h>
1896 #include <netinet/in.h>
1897 #ifdef HAVE_ARPA_INET_H
1898 #include <arpa/inet.h>
1899 #endif
1900 int main(void){
1901 struct sockaddr_in servaddr;
1902 unsigned short portno;
1903 struct servent *ep;
1904 struct hostent *hp;
1905 struct in_addr **pptr;
1907 portno = 0;
1908 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1909 portno = (unsigned short)ep->s_port;
1911 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1912 pptr = (struct in_addr**)hp->h_addr_list;
1913 if(hp->h_addrtype != AF_INET)
1914 fprintf(stderr, "au\n");
1915 }else{
1916 switch(h_errno){
1917 case HOST_NOT_FOUND:
1918 case TRY_AGAIN:
1919 case NO_RECOVERY:
1920 case NO_DATA:
1921 break;
1922 default:
1923 fprintf(stderr, "au\n");
1924 break;
1928 memset(&servaddr, 0, sizeof servaddr);
1929 servaddr.sin_family = AF_INET;
1930 servaddr.sin_port = htons(portno);
1931 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1932 fprintf(stderr, "Would connect to %s:%d ...\n",
1933 inet_ntoa(**pptr), (int)portno);
1934 return 0;
1938 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1939 < ${tmp2}.c link_check gethostbyname \
1940 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1941 < ${tmp2}.c link_check gethostbyname \
1942 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1943 '' '-lsocket -lnsl' ||
1944 feat_bail_required SOCKETS
1947 feat_yes SOCKETS &&
1948 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1949 #include <sys/socket.h>
1950 #include <stdlib.h>
1951 # include <errno.h>
1952 int main(void){
1953 int sockfd = 3;
1955 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1956 errno == ENOSYS)
1957 return 1;
1958 return 0;
1962 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1963 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1964 #include <sys/socket.h>
1965 #include <stdlib.h>
1966 int main(void){
1967 struct timeval tv;
1968 int sockfd = 3;
1970 tv.tv_sec = 42;
1971 tv.tv_usec = 21;
1972 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1973 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1974 return 0;
1978 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1979 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1980 #include <sys/socket.h>
1981 #include <stdlib.h>
1982 int main(void){
1983 struct linger li;
1984 int sockfd = 3;
1986 li.l_onoff = 1;
1987 li.l_linger = 42;
1988 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1989 return 0;
1993 if feat_yes SSL; then
1994 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1995 '#define HAVE_SSL
1996 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1997 #include <openssl/ssl.h>
1998 #include <openssl/err.h>
1999 #include <openssl/x509v3.h>
2000 #include <openssl/x509.h>
2001 #include <openssl/rand.h>
2002 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2003 # error We need TLSv1.
2004 #endif
2005 int main(void){
2006 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2008 SSL_CTX_free(ctx);
2009 PEM_read_PrivateKey(0, 0, 0, 0);
2010 return 0;
2013 then
2015 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
2016 '#define HAVE_SSL
2017 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
2018 #include <openssl/ssl.h>
2019 #include <openssl/err.h>
2020 #include <openssl/x509v3.h>
2021 #include <openssl/x509.h>
2022 #include <openssl/rand.h>
2023 #if defined OPENSSL_NO_SSL3 &&\
2024 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2025 # error We need one of SSLv3 and TLSv1.
2026 #endif
2027 int main(void){
2028 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2030 SSL_CTX_free(ctx);
2031 PEM_read_PrivateKey(0, 0, 0, 0);
2032 return 0;
2035 then
2037 else
2038 feat_bail_required SSL
2041 if [ "${have_openssl}" = 'yes' ]; then
2042 compile_check stack_of 'OpenSSL STACK_OF()' \
2043 '#define HAVE_OPENSSL_STACK_OF' << \!
2044 #include <stdio.h> /* For C89 NULL */
2045 #include <openssl/ssl.h>
2046 #include <openssl/err.h>
2047 #include <openssl/x509v3.h>
2048 #include <openssl/x509.h>
2049 #include <openssl/rand.h>
2050 int main(void){
2051 STACK_OF(GENERAL_NAME) *gens = NULL;
2053 printf("%p", gens); /* to use it */
2054 return 0;
2058 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
2059 '#define HAVE_OPENSSL_CONFIG' << \!
2060 #include <stdio.h> /* For C89 NULL */
2061 #include <openssl/conf.h>
2062 int main(void){
2063 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2064 CONF_modules_free();
2065 return 0;
2069 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
2070 '#define HAVE_OPENSSL_CONF_CTX' << \!
2071 #include "config.h"
2072 #include <openssl/ssl.h>
2073 #include <openssl/err.h>
2074 int main(void){
2075 #if HAVE_OPENSSL < 10100
2076 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2077 #else
2078 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2079 #endif
2080 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2082 SSL_CONF_CTX_set_flags(cctx,
2083 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2084 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2085 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2086 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2087 SSL_CONF_CTX_finish(cctx);
2088 SSL_CONF_CTX_free(cctx);
2089 SSL_CTX_free(ctx);
2090 return 0;
2094 link_check rand_egd 'OpenSSL RAND_egd(3ssl)' \
2095 '#define HAVE_OPENSSL_RAND_EGD' << \!
2096 #include <openssl/rand.h>
2097 int main(void){
2098 return RAND_egd("some.where") > 0;
2102 if feat_yes SSL_ALL_ALGORITHMS; then
2103 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
2104 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2105 #include <openssl/evp.h>
2106 int main(void){
2107 OpenSSL_add_all_algorithms();
2108 EVP_get_cipherbyname("two cents i never exist");
2109 EVP_cleanup();
2110 return 0;
2113 then
2115 else
2116 feat_bail_required SSL_ALL_ALGORITHMS
2118 fi # SSL_ALL_ALGORITHMS
2120 if feat_yes MD5 && feat_no NOEXTMD5; then
2121 run_check openssl_md5 'MD5 digest in OpenSSL' \
2122 '#define HAVE_OPENSSL_MD5' << \!
2123 #include <stdlib.h>
2124 #include <string.h>
2125 #include <openssl/md5.h>
2126 int main(void){
2127 char const dat[] = "abrakadabrafidibus";
2128 char dig[16], hex[16 * 2];
2129 MD5_CTX ctx;
2130 size_t i, j;
2132 memset(dig, 0, sizeof(dig));
2133 memset(hex, 0, sizeof(hex));
2134 MD5_Init(&ctx);
2135 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2136 MD5_Final(dig, &ctx);
2138 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2139 for(i = 0; i < sizeof(hex) / 2; i++){
2140 j = i << 1;
2141 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2142 hex[++j] = hexchar(dig[i] & 0x0f);
2144 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2147 fi # feat_yes MD5 && feat_no NOEXTMD5
2149 else
2150 echo '/* OPT_SSL=0 */' >> ${h}
2151 fi # feat_yes SSL
2153 if [ "${have_openssl}" = 'yes' ]; then
2154 OPT_SMIME=1
2155 else
2156 OPT_SMIME=1
2159 if feat_yes SMTP; then
2160 echo '#define HAVE_SMTP' >> ${h}
2161 else
2162 echo '/* OPT_SMTP=0 */' >> ${h}
2165 if feat_yes POP3; then
2166 echo '#define HAVE_POP3' >> ${h}
2167 else
2168 echo '/* OPT_POP3=0 */' >> ${h}
2171 if feat_yes GSSAPI; then
2172 ${cat} > ${tmp2}.c << \!
2173 #include <gssapi/gssapi.h>
2174 int main(void){
2175 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2176 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2177 return 0;
2180 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2182 if command -v krb5-config >/dev/null 2>&1; then
2183 i=`command -v krb5-config`
2184 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2185 GSS_INCS="`CFLAGS= ${i} --cflags`"
2186 i='GSS-API via krb5-config(1)'
2187 else
2188 GSS_LIBS='-lgssapi'
2189 GSS_INCS=
2190 i='GSS-API in gssapi/gssapi.h, libgssapi'
2192 if < ${tmp2}.c link_check gss \
2193 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2194 < ${tmp3}.c link_check gss \
2195 'GSS-API in gssapi.h, libgssapi' \
2196 '#define HAVE_GSSAPI
2197 #define GSSAPI_REG_INCLUDE' \
2198 '-lgssapi' ||\
2199 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2200 '#define HAVE_GSSAPI' \
2201 '-lgssapi_krb5' ||\
2202 < ${tmp3}.c link_check gss \
2203 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2204 '#define HAVE_GSSAPI
2205 #define GSS_REG_INCLUDE' \
2206 '-lgssapi -lkrb5 -lcrypto' \
2207 '-I/usr/include/kerberosV' ||\
2208 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2209 '#define HAVE_GSSAPI' \
2210 '-lgss' ||\
2211 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2212 '#define HAVE_GSSAPI
2213 #define GSSAPI_OLD_STYLE' \
2214 '-lgssapi_krb5' << \!
2215 #include <gssapi/gssapi.h>
2216 #include <gssapi/gssapi_generic.h>
2217 int main(void){
2218 gss_import_name(0, 0, gss_nt_service_name, 0);
2219 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2220 return 0;
2223 then
2225 else
2226 feat_bail_required GSSAPI
2228 else
2229 echo '/* OPT_GSSAPI=0 */' >> ${h}
2230 fi # feat_yes GSSAPI
2232 if feat_yes NETRC; then
2233 echo '#define HAVE_NETRC' >> ${h}
2234 else
2235 echo '/* OPT_NETRC=0 */' >> ${h}
2238 if feat_yes AGENT; then
2239 echo '#define HAVE_AGENT' >> ${h}
2240 else
2241 echo '/* OPT_AGENT=0 */' >> ${h}
2244 if feat_yes IDNA; then
2245 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2246 '-lidn' << \!
2247 #include <idna.h>
2248 #include <idn-free.h>
2249 #include <stringprep.h>
2250 int main(void){
2251 char *utf8, *idna_ascii, *idna_utf8;
2253 utf8 = stringprep_locale_to_utf8("does.this.work");
2254 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2255 != IDNA_SUCCESS)
2256 return 1;
2257 idn_free(idna_ascii);
2258 /* (Rather link check only here) */
2259 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2260 return 0;
2263 then
2265 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2266 '-lidnkit' << \!
2267 #include <stdio.h>
2268 #include <idn/api.h>
2269 #include <idn/result.h>
2270 int main(void){
2271 idn_result_t r;
2272 char ace_name[256];
2273 char local_name[256];
2275 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2276 sizeof(ace_name));
2277 if (r != idn_success) {
2278 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2279 return 1;
2281 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2282 if (r != idn_success) {
2283 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2284 return 1;
2286 return 0;
2289 then
2291 else
2292 feat_bail_required IDNA
2295 if [ -n "${have_idna}" ]; then
2296 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2297 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2299 else
2300 echo '/* OPT_IDNA=0 */' >> ${h}
2303 if feat_yes IMAP_SEARCH; then
2304 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2305 else
2306 echo '/* OPT_IMAP_SEARCH=0 */' >> ${h}
2309 if feat_yes REGEX; then
2310 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2311 #include <regex.h>
2312 #include <stdlib.h>
2313 int main(void){
2314 int status;
2315 regex_t re;
2317 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2318 return 1;
2319 status = regexec(&re, "plan9", 0,NULL, 0);
2320 regfree(&re);
2321 return !(status == REG_NOMATCH);
2324 then
2326 else
2327 feat_bail_required REGEX
2329 else
2330 echo '/* OPT_REGEX=0 */' >> ${h}
2333 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2334 have_mle=1
2335 echo '#define HAVE_MLE' >> ${h}
2336 else
2337 feat_bail_required MLE
2338 echo '/* OPT_MLE=0 */' >> ${h}
2341 # Generic have-a-line-editor switch for those who need it below
2342 if [ -n "${have_mle}" ]; then
2343 have_cle=1
2346 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2347 echo '#define HAVE_HISTORY' >> ${h}
2348 else
2349 echo '/* OPT_HISTORY=0 */' >> ${h}
2352 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2353 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2354 else
2355 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2358 if feat_yes TERMCAP; then
2359 __termcaplib() {
2360 link_check termcap "termcap(5) (via ${4})" \
2361 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2362 #include <stdio.h>
2363 #include <stdlib.h>
2364 ${2}
2365 #include <term.h>
2366 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2367 static int my_putc(int c){return putchar(c);}
2368 int main(void){
2369 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2370 int r2 = OK, r3 = ERR;
2372 tgetent(buf, getenv("TERM"));
2373 cpb = cmdbuf;
2374 r1 = tgetstr(UNCONST("cm"), &cpb);
2375 tgoto(r1, 1, 1);
2376 r2 = tgetnum(UNCONST("Co"));
2377 r3 = tgetflag(UNCONST("ut"));
2378 tputs("cr", 1, &my_putc);
2379 return (r1 == NULL || r2 == -1 || r3 == 0);
2381 _EOT
2384 __terminfolib() {
2385 link_check terminfo "terminfo(5) (via ${2})" \
2386 '#define HAVE_TERMCAP
2387 #define HAVE_TERMCAP_CURSES
2388 #define HAVE_TERMINFO' "${1}" << _EOT
2389 #include <stdio.h>
2390 #include <curses.h>
2391 #include <term.h>
2392 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2393 static int my_putc(int c){return putchar(c);}
2394 int main(void){
2395 int er, r0, r1, r2;
2396 char *r3, *tp;
2398 er = OK;
2399 r0 = setupterm(NULL, 1, &er);
2400 r1 = tigetflag(UNCONST("bce"));
2401 r2 = tigetnum(UNCONST("colors"));
2402 r3 = tigetstr(UNCONST("cr"));
2403 tp = tparm(r3, NULL);
2404 tputs(tp, 1, &my_putc);
2405 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2406 r3 == (char*)-1 || r3 == NULL);
2408 _EOT
2411 if feat_yes TERMCAP_VIA_TERMINFO; then
2412 __terminfolib -ltinfo -ltinfo ||
2413 __terminfolib -lcurses -lcurses ||
2414 __terminfolib -lcursesw -lcursesw ||
2415 feat_bail_required TERMCAP_VIA_TERMINFO
2418 if [ -z "${have_terminfo}" ]; then
2419 __termcaplib -ltermcap '' '' '-ltermcap' ||
2420 __termcaplib -ltermcap '#include <curses.h>' '
2421 #define HAVE_TERMCAP_CURSES' \
2422 'curses.h / -ltermcap' ||
2423 __termcaplib -lcurses '#include <curses.h>' '
2424 #define HAVE_TERMCAP_CURSES' \
2425 'curses.h / -lcurses' ||
2426 __termcaplib -lcursesw '#include <curses.h>' '
2427 #define HAVE_TERMCAP_CURSES' \
2428 'curses.h / -lcursesw' ||
2429 feat_bail_required TERMCAP
2431 if [ -n "${have_termcap}" ]; then
2432 run_check tgetent_null \
2433 "tgetent(3) of termcap(5) takes NULL buffer" \
2434 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2435 #include <stdio.h> /* For C89 NULL */
2436 #include <stdlib.h>
2437 #ifdef HAVE_TERMCAP_CURSES
2438 # include <curses.h>
2439 #endif
2440 #include <term.h>
2441 int main(void){
2442 tgetent(NULL, getenv("TERM"));
2443 return 0;
2445 _EOT
2448 else
2449 echo '/* OPT_TERMCAP=0 */' >> ${h}
2450 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2453 if feat_yes SPAM_SPAMC; then
2454 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2455 if command -v spamc >/dev/null 2>&1; then
2456 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2458 else
2459 echo '/* OPT_SPAM_SPAMC=0 */' >> ${h}
2462 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2463 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2464 else
2465 feat_bail_required SPAM_SPAMD
2466 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2469 feat_def SPAM_FILTER
2471 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2472 echo '#define HAVE_SPAM' >> ${h}
2473 else
2474 echo '/* HAVE_SPAM */' >> ${h}
2477 if feat_yes QUOTE_FOLD &&\
2478 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2479 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2480 else
2481 feat_bail_required QUOTE_FOLD
2482 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2485 feat_def FILTER_HTML_TAGSOUP
2486 feat_def COLOUR
2487 feat_def DOTLOCK
2488 feat_def MD5
2489 feat_def NOMEMDBG
2491 ## Summarizing
2493 ${rm} -f ${tmp}
2494 squeeze_em ${inc} ${tmp}
2495 ${mv} ${tmp} ${inc}
2496 squeeze_em ${lib} ${tmp}
2497 ${mv} ${tmp} ${lib}
2499 # config.h
2500 ${mv} ${h} ${tmp}
2501 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2502 ${cat} ${tmp} >> ${h}
2503 ${rm} -f ${tmp}
2504 printf '\n' >> ${h}
2506 # Create the real mk.mk
2507 # Note we cannout use explicit ./ filename prefix for source and object
2508 # pathnames because of a bug in bmake(1)
2509 ${rm} -rf ${tmp0}.* ${tmp0}*
2510 printf 'OBJ_SRC = ' >> ${mk}
2511 if feat_no AMALGAMATION; then
2512 for i in `printf '%s\n' *.c | ${sort}`; do
2513 if [ "${i}" = privsep.c ]; then
2514 continue
2516 printf "${i} " >> ${mk}
2517 done
2518 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2519 else
2520 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2522 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2523 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2524 printf '# undef _CONFIG_H\n' >> ${h}
2525 printf '# define _CONFIG_H 2\n' >> ${h}
2526 for i in `printf '%s\n' *.c | ${sort}`; do
2527 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2528 [ "${i}" = privsep.c ]; then
2529 continue
2531 printf "${i} " >> ${mk}
2532 printf "# include \"${i}\"\n" >> ${h}
2533 done
2534 echo >> ${mk}
2535 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2536 echo '#else' >> ${h}
2539 # Finally, create the string that is used by *feature* and `version'.
2540 # Take this nice opportunity and generate a visual listing of included and
2541 # non-included features for the person who runs the configuration
2542 msg '\nThe following features are included (+) or not (-):'
2543 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2544 printf '/* The "feature string" */\n' >> ${h}
2545 # Because + is expanded by *folder* if first in "echo $features", put something
2546 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2547 sep=
2548 for opt
2550 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2551 feat_yes ${opt} && sign=+ || sign=-
2552 printf -- "${sep}${sign}${sopt}" >> ${h}
2553 sep=','
2554 i=`option_doc_of ${opt}`
2555 [ -z "${i}" ] && continue
2556 msg " %s %s: %s" ${sign} ${sopt} "${i}"
2557 done
2558 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2559 #exec 5>&1 >>${h}
2560 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2561 # -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