Don't use colours but for IS_TTY_SESSION() (TTYOUT not enough)
[s-mailx.git] / mk-conf.sh
blob0e745d0de0053aa478edbb1e2733d1c8cd235ee1
1 #!/bin/sh -
2 #@ Please see `INSTALL' and `make.rc' instead.
4 LC_ALL=C
5 export LC_ALL
7 option_reset() {
8 WANT_ICONV=0
9 WANT_SOCKETS=0
10 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
11 WANT_SMTP=0 WANT_POP3=0 WANT_IMAP=0
12 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
13 #WANT_MD5=0
14 WANT_IDNA=0
15 WANT_IMAP_SEARCH=0
16 WANT_REGEX=0
17 WANT_READLINE=0 WANT_EDITLINE=0 WANT_NCL=0
18 WANT_TERMCAP=0
19 WANT_ERRORS=0
20 WANT_SPAM_SPAMC=0 WANT_SPAM_SPAMD=0 WANT_SPAM_FILTER=0
21 WANT_DOCSTRINGS=0
22 WANT_QUOTE_FOLD=0
23 WANT_FILTER_HTML_TAGSOUP=0
24 WANT_COLOUR=0
25 WANT_DOTLOCK=0
28 option_maximal() {
29 WANT_ICONV=require
30 WANT_SOCKETS=1
31 WANT_SSL=1 WANT_ALL_SSL_ALGORITHMS=1
32 WANT_SMTP=1 WANT_POP3=1 WANT_IMAP=1
33 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
34 #WANT_MD5=1
35 WANT_IDNA=1
36 WANT_IMAP_SEARCH=1
37 WANT_REGEX=require
38 WANT_NCL=require
39 WANT_HISTORY=1 WANT_TABEXPAND=1
40 WANT_TERMCAP=1
41 WANT_ERRORS=1
42 WANT_SPAM_SPAMC=1 WANT_SPAM_SPAMD=1 WANT_SPAM_FILTER=1
43 WANT_DOCSTRINGS=1
44 WANT_QUOTE_FOLD=1
45 WANT_FILTER_HTML_TAGSOUP=1
46 WANT_COLOUR=1
47 WANT_DOTLOCK=require
50 # Predefined CONFIG= urations take precedence over anything else
51 if [ -n "${CONFIG}" ]; then
52 case "${CONFIG}" in
53 [nN][uU][lL][lL])
54 option_reset
56 [nN][uU][lL][lL][iI])
57 option_reset
58 WANT_ICONV=require
60 [mM][iI][nN][iI][mM][aA][lL])
61 option_reset
62 WANT_ICONV=1
63 WANT_REGEX=1
64 WANT_DOTLOCK=require
66 [mM][eE][dD][iI][uU][mM])
67 option_reset
68 WANT_ICONV=require
69 WANT_IDNA=1
70 WANT_REGEX=1
71 WANT_NCL=1
72 WANT_HISTORY=1
73 WANT_ERRORS=1
74 WANT_SPAM_FILTER=1
75 WANT_DOCSTRINGS=1
76 WANT_COLOUR=1
77 WANT_DOTLOCK=require
79 [nN][eE][tT][sS][eE][nN][dD])
80 option_reset
81 WANT_ICONV=require
82 WANT_SOCKETS=1
83 WANT_SSL=require
84 WANT_SMTP=require
85 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
86 WANT_IDNA=1
87 WANT_REGEX=1
88 WANT_NCL=1
89 WANT_HISTORY=1
90 WANT_DOCSTRINGS=1
91 WANT_COLOUR=1
92 WANT_DOTLOCK=require
94 [mM][aA][xX][iI][mM][aA][lL])
95 option_reset
96 option_maximal
98 [dD][eE][vV][eE][lL])
99 WANT_DEVEL=1 WANT_DEBUG=1 WANT_NYD2=1
100 option_maximal
102 [oO][dD][eE][vV][eE][lL])
103 WANT_DEVEL=1
104 option_maximal
107 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
108 echo >&2 'Possible values: NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
109 exit 1
111 esac
114 # Inter-relationships
115 option_update() {
116 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
117 WANT_SOCKETS=0
119 if feat_no SOCKETS; then
120 if feat_require SMTP; then
121 msg 'ERROR: need SOCKETS for required feature SMTP'
122 config_exit 13
124 if feat_require POP3; then
125 msg 'ERROR: need SOCKETS for required feature POP3'
126 config_exit 13
128 if feat_require IMAP; then
129 msg "ERROR: need SOCKETS for required feature IMAP\\n"
130 config_exit 13
132 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
133 WANT_SMTP=0 WANT_POP3=0 WANT_IMAP=0
134 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
136 if feat_no SMTP && feat_no IMAP; then
137 WANT_GSSAPI=0
140 if feat_no READLINE && feat_no EDITLINE && feat_no NCL; then
141 WANT_HISTORY=0 WANT_TABEXPAND=0
144 # If we don't need MD5 leave it alone
145 if feat_no SOCKETS; then
146 WANT_MD5=0
148 if feat_yes DEBUG; then
149 WANT_NOALLOCA=1 WANT_DEVEL=1
153 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
154 # via path_check() later on once possible
156 os_setup() {
157 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
158 msg 'Operating system is "%s"' ${OS}
160 if [ ${OS} = sunos ]; then
161 msg ' . have special SunOS / Solaris environmental rules, dealing with it'
162 _os_setup_sunos
163 elif [ ${OS} = unixware ]; then
164 msg ' . have special UnixWare environmental rules, dealing with it'
165 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
166 CC=cc
167 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
169 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
170 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
171 export CC CFLAGS LDFLAGS
172 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
174 elif [ -n "${VERBOSE}" ]; then
175 msg ' . no special treatment for this system necessary or known'
178 # Sledgehammer: better set _GNU_SOURCE
179 # And in general: oh, boy!
180 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
181 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
182 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
183 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
185 # On pkgsrc(7) systems automatically add /usr/pkg/*
186 if [ -d /usr/pkg ]; then
187 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
188 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
192 _os_setup_sunos() {
193 # According to standards(5), this is what we need to do
194 if [ -d /usr/xpg4 ]; then :; else
195 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
196 config_exit 1
198 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
199 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
200 export PATH
202 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
203 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
205 # Include packages
206 if [ -d /opt/csw ]; then
207 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
208 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
211 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
212 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
214 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
215 if [ -x "${cksum}" ]; then :; else
216 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
217 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
218 msg 'ERROR: However, we do so only for tests.'
219 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
220 config_exit 1
223 if feat_yes AUTOCC; then
224 if command -v cc >/dev/null 2>&1; then
225 CC=cc
226 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
228 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
229 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
230 export CC CFLAGS LDFLAGS
231 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
232 else
233 # Assume gcc(1)
234 force_no_stackprot=1 need_R_ldflags=-Wl,-R
239 # Check out compiler ($CC) and -flags ($CFLAGS)
240 cc_setup() {
241 # Even though it belongs into cc_flags we will try to compile and link
242 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
243 # ADDCFLAGS/ADDLDFLAGS
244 if feat_no AUTOCC; then
245 _cc_default
246 # Ensure those don't do any harm
247 ADDCFLAGS= ADDLDFLAGS=
248 export ADDCFLAGS ADDLDFLAGS
249 return
250 else
251 CFLAGS= LDFLAGS=
252 export CFLAGS LDFLAGS
254 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
256 printf >&2 'Searching for a usable C compiler .. $CC='
257 if { i="`command -v clang`"; }; then
258 CC=${i}
259 elif { i="`command -v gcc`"; }; then
260 CC=${i}
261 elif { i="`command -v c99`"; }; then
262 CC=${i}
263 else
264 if [ "${CC}" = cc ]; then
266 elif { i="`command -v c89`"; }; then
267 CC=${i}
268 else
269 printf >&2 'boing booom tschak\n'
270 msg 'ERROR: I cannot find a compiler!'
271 msg ' Neither of clang(1), gcc(1), c89(1) and c99(1).'
272 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
273 config_exit 1
276 printf >&2 '"%s"\n' "${CC}"
277 export CC
280 _cc_default() {
281 if [ -z "${CC}" ]; then
282 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
283 config_exit 1
286 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
288 else
289 msg 'Using C compiler $CC="%s"' "${CC}"
293 cc_flags() {
294 if feat_yes AUTOCC; then
295 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
296 cc_check_silent=1
297 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
298 else
299 cc_check_silent=
300 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
303 _cc_flags_generic
305 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
306 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
307 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
308 else
309 if feat_no DEBUG; then
310 CFLAGS="-DNDEBUG ${CFLAGS}"
313 msg ''
314 export CFLAGS LDFLAGS
317 _cc_flags_generic() {
318 _CFLAGS= _LDFLAGS=
319 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
321 cc_check -Wall
322 cc_check -Wextra
323 cc_check -pedantic
325 cc_check -Wbad-function-cast
326 cc_check -Wcast-align
327 cc_check -Wcast-qual
328 cc_check -Winit-self
329 cc_check -Wmissing-prototypes
330 cc_check -Wshadow
331 cc_check -Wunused
332 cc_check -Wwrite-strings
333 cc_check -Wno-long-long
335 if feat_yes AMALGAMATION && feat_no DEVEL; then
336 cc_check -Wno-unused-function
338 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
340 cc_check -fno-unwind-tables
341 cc_check -fno-asynchronous-unwind-tables
342 cc_check -fstrict-aliasing
343 if cc_check -fstrict-overflow && feat_yes DEVEL; then
344 cc_check -Wstrict-overflow=5
347 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
348 if [ -z "${force_no_stackprot}" ]; then
349 if cc_check -fstack-protector-strong ||
350 cc_check -fstack-protector-all; then
351 cc_check -D_FORTIFY_SOURCE=2
353 else
354 msg 'Not checking for -fstack-protector compiler option,'
355 msg 'since that caused linker errors in a "similar" configuration.'
356 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
360 if feat_yes AMALGAMATION; then
361 cc_check -pipe
363 if feat_yes DEBUG; then
364 cc_check -O
365 cc_check -g
366 elif cc_check -O3; then
368 elif cc_check -O2; then
370 elif cc_check -O1; then
372 else
373 cc_check -O
376 ld_check -Wl,-z,relro
377 ld_check -Wl,-z,now
378 ld_check -Wl,-z,noexecstack
380 # Address randomization
381 _ccfg=${_CFLAGS}
382 if cc_check -fPIE || cc_check -fpie; then
383 ld_check -pie || _CFLAGS=${_ccfg}
385 unset _ccfg
388 ## -- >8 -- 8< -- ##
390 ## Notes:
391 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
392 ## redirection, so use "printf '' >" instead
394 ## Very first: we undergo several states regarding I/O redirection etc.,
395 ## but need to deal with option updates from within all. Since all the
396 ## option stuff should be above the scissor line, define utility functions
397 ## and redefine them as necessary.
398 ## And, since we have those functions, simply use them for whatever
400 config_exit() {
401 exit ${1}
404 msg() {
405 fmt=${1}
406 shift
407 printf >&2 "${fmt}\\n" "${@}"
410 ## First of all, create new configuration and check wether it changed
412 rc=./make.rc
413 lst=./config.lst
414 h=./config.h h_name=config.h
415 mk=./mk.mk
417 newlst=./config.lst-new
418 newmk=./config.mk-new
419 newh=./config.h-new
420 tmp0=___tmp
421 tmp=./${tmp0}1$$
422 tmp2=./${tmp0}2$$
424 # We need some standard utilities
425 unset -f command
426 check_tool() {
427 n=${1} i=${2} opt=${3:-0}
428 # Evaluate, just in case user comes in with shell snippets (..well..)
429 eval i="${i}"
430 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
431 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
432 eval ${n}=${i}
433 return 0
435 if [ ${opt} -eq 0 ]; then
436 msg 'ERROR: no trace of utility "%s"' "${n}"
437 config_exit 1
439 return 1
442 # Check those tools right now that we need before including $rc
443 msg 'Checking for basic utility set'
444 check_tool rm "${rm:-`command -v rm`}"
445 check_tool sed "${sed:-`command -v sed`}"
446 check_tool tr "${tr:-`command -v tr`}"
448 # Our feature check environment
449 feat_val_no() {
450 [ "x${1}" = x0 ] ||
451 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
454 feat_val_yes() {
455 [ "x${1}" = x1 ] ||
456 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
457 [ "x${1}" = xrequire ]
460 feat_val_require() {
461 [ "x${1}" = xrequire ]
464 _feat_check() {
465 eval i=\$WANT_${1}
466 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
467 if feat_val_no "${i}"; then
468 return 1
469 elif feat_val_yes "${i}"; then
470 return 0
471 else
472 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
473 "${1}" "${i}"
474 config_exit 11
478 feat_yes() {
479 _feat_check ${1}
482 feat_no() {
483 _feat_check ${1} && return 1
484 return 0
487 feat_require() {
488 eval i=\$WANT_${1}
489 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
490 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
493 feat_bail_required() {
494 if feat_require ${1}; then
495 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
496 config_exit 13
498 eval WANT_${1}=0
499 option_update # XXX this is rather useless here (dependency chain..)
502 # Include $rc, but only take from it what wasn't overwritten by the user from
503 # within the command line or from a chosen fixed CONFIG=
504 # Note we leave alone the values
505 trap "${rm} -f ${tmp}; exit" 1 2 15
506 trap "${rm} -f ${tmp}" 0
508 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
509 ${rm} -f ${tmp}
510 # We want read(1) to perform backslash escaping in order to be able to use
511 # multiline values in make.rc
512 while read line; do
513 # This should be [[:space:]] but needs -E; so test SPC/HT
514 line="`echo ${line} |\
515 ${sed} -e '/^[ ]*#/d' -e '/^$/d' -e 's/[ ]*$//'`"
516 [ -z "${line}" ] && continue
517 i="`echo ${line} | ${sed} -e 's/=.*$//'`"
518 eval j="\$${i}" jx="\${${i}+x}"
519 if [ -n "${j}" ] || [ "${jx}" = x ]; then
520 : # Yet present
521 else
522 j="`echo ${line} | ${sed} -e 's/^[^=]*=//' -e 's/^\"*//' -e 's/\"*$//'`"
524 echo "${i}=\"${j}\""
525 done < ${rc} > ${tmp}
526 # Reread the mixed version right now
527 . ./${tmp}
528 printf >&2 'done\n'
530 # We need to know about that now, in order to provide utility overwrites etc.
531 os_setup
533 msg 'Checking for remaining set of utilities'
534 check_tool grep "${grep:-`command -v grep`}"
536 # Before we step ahead with the other utilities perform a path cleanup first.
537 # We need this function also for C_INCLUDE_PATH and LD_LIBRARY_PATH
538 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
539 path_check() {
540 varname=${1} addflag=${2} flagvarname=${3}
541 j=${IFS}
542 IFS=:
543 eval "set -- \$${1}"
544 IFS=${j}
545 j= k= y= z=
546 for i
548 [ -z "${i}" ] && continue
549 [ -d "${i}" ] || continue
550 if [ -n "${j}" ]; then
551 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
553 else
554 y="${y} :${i}:"
555 j="${j}:${i}"
556 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
558 else
559 y=" :${i}:"
560 j="${i}"
561 [ -n "${addflag}" ] && k="${addflag}${i}"
563 done
564 eval "${varname}=\"${j}\""
565 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
566 unset varname
569 path_check PATH
571 check_tool awk "${awk:-`command -v awk`}"
572 check_tool cat "${cat:-`command -v cat`}"
573 check_tool chmod "${chmod:-`command -v chmod`}"
574 check_tool cp "${cp:-`command -v cp`}"
575 check_tool cmp "${cmp:-`command -v cmp`}"
576 check_tool mkdir "${mkdir:-`command -v mkdir`}"
577 check_tool mv "${mv:-`command -v mv`}"
578 # rm(1), sed(1) above
579 check_tool tee "${tee:-`command -v tee`}"
581 check_tool chown "${chown:-`command -v chown`}" 1 ||
582 check_tool chown "/sbin/chown" 1 ||
583 check_tool chown "/usr/sbin/chown"
585 check_tool make "${MAKE:-`command -v make`}"
586 MAKE=${make}
587 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
588 HAVE_STRIP=1 || HAVE_STRIP=0
590 # For ./cc-test.sh only
591 check_tool cksum "${cksum:-`command -v cksum`}"
593 # Update WANT_ options now, in order to get possible inter-dependencies right
594 option_update
596 # (No functions since some shells loose non-exported variables in traps)
597 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${newlst} ${newmk} ${newh}; exit" 1 2 15
598 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${newlst} ${newmk} ${newh}" 0
600 # Our configuration options may at this point still contain shell snippets,
601 # we need to evaluate them in order to get them expanded, and we need those
602 # evaluated values not only in our new configuration file, but also at hand..
603 printf >&2 'Evaluating all configuration items ... '
604 ${rm} -f ${newlst} ${newmk} ${newh}
605 exec 5<&0 6>&1 <${tmp} >${newlst}
606 while read line; do
607 i=`echo ${line} | ${sed} -e 's/=.*$//'`
608 eval j=\$${i}
609 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
610 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
611 if [ -z "${j}" ] || feat_val_no "${j}"; then
613 printf "/*#define ${i}*/\n" >> ${newh}
614 elif feat_val_yes "${j}"; then
615 if feat_val_require "${j}"; then
616 j=require
617 else
620 printf "#define ${i}\n" >> ${newh}
621 else
622 msg 'ERROR: cannot parse <%s>' "${line}"
623 config_exit 1
625 else
626 printf "#define ${i} \"${j}\"\n" >> ${newh}
628 printf "${i} = ${j}\n" >> ${newmk}
629 printf "${i}=${j}\n"
630 eval "${i}=\"${j}\""
631 done
632 exec 0<&5 1>&6 5<&- 6<&-
633 printf >&2 'done\n'
635 # Add the known utility and some other variables
636 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
637 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
639 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
640 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
641 if feat_yes DOTLOCK; then
642 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
643 else
644 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
647 for i in \
648 awk cat chmod chown cp cmp grep mkdir mv rm sed tee tr \
649 MAKE make strip \
650 cksum; do
651 eval j=\$${i}
652 printf "${i} = ${j}\n" >> ${newmk}
653 printf "${i}=${j}\n" >> ${newlst}
654 done
656 # Build a basic set of INCS and LIBS according to user environment.
657 path_check C_INCLUDE_PATH -I _INCS
658 INCS="${INCS} ${_INCS}"
659 path_check LD_LIBRARY_PATH -L _LIBS
660 LIBS="${LIBS} ${_LIBS}"
661 unset _INCS _LIBS
662 export C_INCLUDE_PATH LD_LIBRARY_PATH
664 if [ -n "${need_R_ldflags}" ]; then
665 i=${IFS}
666 IFS=:
667 set -- ${LD_LIBRARY_PATH}
668 IFS=${i}
669 for i
671 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
672 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
673 done
674 export LDFLAGS
677 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
679 cc_setup
681 ${cat} > ${tmp}.c << \!
682 #include <stdio.h>
683 int main(int argc, char **argv)
685 (void)argc;
686 (void)argv;
687 puts("Hello world");
688 return 0;
692 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
693 -o ${tmp2} ${tmp}.c ${LIBS}; then
695 else
696 msg 'ERROR: i cannot compile a "Hello world" via'
697 msg ' %s' \
698 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
699 msg 'ERROR: Please read INSTALL, rerun'
700 config_exit 1
703 cc_check() {
704 [ -n "${cc_check_silent}" ] || printf >&2 ' . %s .. ' "${1}"
705 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
706 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
707 _CFLAGS="${_CFLAGS} ${1}"
708 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
709 return 0
711 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
712 return 1
715 ld_check() {
716 [ -n "${cc_check_silent}" ] || printf >&2 ' . %s .. ' "${1}"
717 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1} ${ADDLDFLAGS} \
718 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
719 _LDFLAGS="${_LDFLAGS} ${1}"
720 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
721 return 0
723 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
724 return 1
727 cc_flags
729 for i in \
730 INCS LIBS \
731 ; do
732 eval j=\$${i}
733 printf "${i}=${j}\n" >> ${newlst}
734 done
735 for i in \
736 CC \
737 CFLAGS \
738 LDFLAGS \
739 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
740 ; do
741 eval j=\$${i}
742 printf "${i} = ${j}\n" >> ${newmk}
743 printf "${i}=${j}\n" >> ${newlst}
744 done
746 # Now finally check wether we already have a configuration and if so, wether
747 # all those parameters are still the same.. or something has actually changed
748 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
749 echo 'Configuration is up-to-date'
750 exit 0
751 elif [ -f ${lst} ]; then
752 echo 'Configuration has been updated..'
753 ( eval "${MAKE} -f ./mk.mk clean" )
754 echo
755 else
756 echo 'Shiny configuration..'
759 # Time to redefine helper 1
760 config_exit() {
761 ${rm} -f ${lst} ${h} ${mk}
762 exit ${1}
765 ${mv} -f ${newlst} ${lst}
766 ${mv} -f ${newh} ${h}
767 ${mv} -f ${newmk} ${mk}
769 ## Compile and link checking
771 tmp3=./${tmp0}3$$
772 log=./config.log
773 lib=./config.lib
774 inc=./config.inc
775 makefile=./config.mk
777 # (No function since some shells loose non-exported variables in traps)
778 trap "${rm} -f ${lst} ${h} ${mk} ${lib} ${inc} ${makefile}; exit" 1 2 15
779 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" 0
781 # Time to redefine helper 2
782 msg() {
783 fmt=${1}
784 shift
785 printf "*** ${fmt}\\n" "${@}"
786 printf "${fmt}\\n" "${@}" >&5
788 msg_nonl() {
789 fmt=${1}
790 shift
791 printf "*** ${fmt}\\n" "${@}"
792 printf "${fmt}" "${@}" >&5
795 exec 5>&2 > ${log} 2>&1
797 echo "${LIBS}" > ${lib}
798 echo "${INCS}" > ${inc}
799 ${cat} > ${makefile} << \!
800 .SUFFIXES: .o .c .x .y
801 .c.o:
802 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
803 .c.x:
804 $(CC) -I./ $(XINCS) -E $< >$@
806 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
807 .y: ;
810 _check_preface() {
811 variable=$1 topic=$2 define=$3
813 echo '**********'
814 msg_nonl ' . %s ... ' "${topic}"
815 echo "/* checked ${topic} */" >> ${h}
816 ${rm} -f ${tmp} ${tmp}.o
817 echo '*** test program is'
818 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
819 #echo '*** the preprocessor generates'
820 #${make} -f ${makefile} ${tmp}.x
821 #${cat} ${tmp}.x
822 echo '*** results are'
825 compile_check() {
826 variable=$1 topic=$2 define=$3
828 _check_preface "${variable}" "${topic}" "${define}"
830 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
831 [ -f ./${tmp}.o ]; then
832 msg 'yes'
833 echo "${define}" >> ${h}
834 eval have_${variable}=yes
835 return 0
836 else
837 echo "/* ${define} */" >> ${h}
838 msg 'no'
839 eval unset have_${variable}
840 return 1
844 _link_mayrun() {
845 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
847 _check_preface "${variable}" "${topic}" "${define}"
849 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
850 XLIBS="${LIBS} ${libs}" ./${tmp} &&
851 [ -f ./${tmp} ] &&
852 { [ ${run} -eq 0 ] || ./${tmp}; }; then
853 echo "*** adding INCS<${incs}> LIBS<${libs}>"
854 msg 'yes'
855 echo "${define}" >> ${h}
856 LIBS="${LIBS} ${libs}"
857 echo "${libs}" >> ${lib}
858 INCS="${INCS} ${incs}"
859 echo "${incs}" >> ${inc}
860 eval have_${variable}=yes
861 return 0
862 else
863 msg 'no'
864 echo "/* ${define} */" >> ${h}
865 eval unset have_${variable}
866 return 1
870 link_check() {
871 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
874 run_check() {
875 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
880 # May be multiline..
881 [ -n "${OS_DEFINES}" ] && printf "${OS_DEFINES}" >> ${h}
883 if link_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
884 #include <pwd.h>
885 #include <unistd.h>
886 int main(void)
888 struct passwd *pw;
889 gid_t gid;
890 uid_t uid;
892 if ((gid = getgid()) != 1)
893 gid = getegid();
894 if ((uid = getuid()) != 1)
895 uid = geteuid();
896 if ((pw = getpwuid(uid)) == NULL)
897 pw = getpwnam("root");
898 return 0;
901 then
903 else
904 msg 'ERROR: we require user and group info / database searches.'
905 msg 'That much Unix we indulge ourselfs.'
906 config_exit 1
909 if link_check termios 'termios.h and tc*(3) family' << \!
910 #include <termios.h>
911 int main(void)
913 struct termios tios;
914 tcgetattr(0, &tios);
915 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
916 return 0;
919 then
921 else
922 msg 'ERROR: we require termios.h and the tc*() family of functions.'
923 msg 'That much Unix we indulge ourselfs.'
924 config_exit 1
927 if link_check snprintf 'v?snprintf(3)' << \!
928 #include <stdarg.h>
929 #include <stdio.h>
930 static void dome(char *buf, ...)
932 va_list ap;
933 va_start(ap, buf);
934 vsnprintf(buf, 20, "%s", ap);
935 va_end(ap);
936 return;
938 int main(void)
940 char b[20];
941 snprintf(b, sizeof b, "%s", "string");
942 dome(b, "string");
943 return 0;
946 then
948 else
949 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
950 config_exit 1
953 # XXX Move to below later when the time stuff is regulary needed.
954 # XXX Add POSIX check once standardized
955 link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
956 #include <stdlib.h>
957 int main(void)
959 arc4random();
960 return 0;
964 # XXX Not indented for that - drop cond. when time stuff is regulary needed.
965 if [ -z "${have_posix_random}" ]; then
966 if link_check clock_gettime 'clock_gettime(2)' \
967 '#define HAVE_CLOCK_GETTIME' << \!
968 #include <time.h>
969 int main(void)
971 struct timespec ts;
972 clock_gettime(CLOCK_REALTIME, &ts);
973 return 0;
976 then
978 elif link_check clock_gettime 'clock_gettime(2) (via -lrt)' \
979 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
980 #include <time.h>
981 int main(void)
983 struct timespec ts;
984 clock_gettime(CLOCK_REALTIME, &ts);
985 return 0;
988 then
990 elif link_check gettimeofday 'gettimeofday(2)' \
991 '#define HAVE_GETTIMEOFDAY' << \!
992 #include <stdio.h> /* For C89 NULL */
993 #include <sys/time.h>
994 int main(void)
996 struct timeval tv;
997 gettimeofday(&tv, NULL);
998 return 0;
1001 then
1003 else
1004 msg 'ERROR: one of clock_gettime(2) and gettimeofday(2) is required.'
1005 config_exit 1
1007 fi # -z ${have_posix_random}
1009 link_check pathconf 'pathconf(2)' '#define HAVE_PATHCONF' << \!
1010 #include <unistd.h>
1011 int main(void)
1013 pathconf(".", _PC_NAME_MAX);
1014 pathconf(".", _PC_PATH_MAX);
1015 return 0;
1019 link_check setenv 'setenv(3)/unsetenv(3)' '#define HAVE_SETENV' << \!
1020 #include <stdlib.h>
1021 int main(void)
1023 setenv("s-nail", "to be made nifty!", 1);
1024 unsetenv("s-nail");
1025 return 0;
1029 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1030 #include <stdio.h>
1031 int main(void)
1033 putc_unlocked('@', stdout);
1034 return 0;
1038 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1039 #include <unistd.h>
1040 int main(void)
1042 fchdir(0);
1043 return 0;
1047 link_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1048 #include <fcntl.h>
1049 #include <unistd.h>
1050 int main(void)
1052 int fds[2];
1053 pipe2(fds, O_CLOEXEC);
1054 return 0;
1058 link_check mmap 'mmap(2)' '#define HAVE_MMAP' << \!
1059 #include <sys/types.h>
1060 #include <sys/mman.h>
1061 int main(void)
1063 mmap(0, 0, 0, 0, 0, 0);
1064 return 0;
1068 link_check mremap 'mremap(2)' '#define HAVE_MREMAP' << \!
1069 #include <sys/types.h>
1070 #include <sys/mman.h>
1071 int main(void)
1073 mremap(0, 0, 0, MREMAP_MAYMOVE);
1074 return 0;
1078 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1079 #include <locale.h>
1080 int main(void)
1082 setlocale(LC_ALL, "");
1083 return 0;
1087 if [ "${have_setlocale}" = yes ]; then
1088 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1089 '#define HAVE_C90AMEND1' << \!
1090 #include <limits.h>
1091 #include <stdlib.h>
1092 #include <wchar.h>
1093 #include <wctype.h>
1094 int main(void)
1096 char mbb[MB_LEN_MAX + 1];
1097 wchar_t wc;
1098 iswprint(L'c');
1099 towupper(L'c');
1100 mbtowc(&wc, "x", 1);
1101 mbrtowc(&wc, "x", 1, NULL);
1102 wctomb(mbb, wc);
1103 return (mblen("\0", 1) == 0);
1107 if [ "${have_c90amend1}" = yes ]; then
1108 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1109 #include <wchar.h>
1110 int main(void)
1112 wcwidth(L'c');
1113 return 0;
1118 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1119 #include <langinfo.h>
1120 #include <stdlib.h>
1121 int main(void)
1123 nl_langinfo(DAY_1);
1124 return (nl_langinfo(CODESET) == NULL);
1127 fi # have_setlocale
1129 # Note: run_check, thus we also get only the desired implementation...
1130 run_check realpath 'realpath()' '#define HAVE_REALPATH' << \!
1131 #include <stdlib.h>
1132 int main(void)
1134 char *x = realpath(".", NULL), *y = realpath("/", NULL);
1135 return (x != NULL && y != NULL) ? 0 : 1;
1139 link_check wordexp 'wordexp(3)' '#define HAVE_WORDEXP' << \!
1140 #include <wordexp.h>
1141 int main(void)
1143 wordexp((char*)0, (wordexp_t*)0, 0);
1144 return 0;
1150 if feat_yes DEBUG; then
1151 echo '#define HAVE_DEBUG' >> ${h}
1154 if feat_yes AMALGAMATION; then
1155 echo '#define HAVE_AMALGAMATION' >> ${h}
1158 if feat_no NOALLOCA; then
1159 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1160 # versions of alloca(3) since modern compilers just can't be trusted
1161 # not to overoptimize and silently break some code
1162 link_check alloca '__builtin_alloca()' \
1163 '#define HAVE_ALLOCA __builtin_alloca' << \!
1164 #include <stdio.h> /* For C89 NULL */
1165 int main(void)
1167 void *vp = __builtin_alloca(1);
1168 return (vp != NULL);
1173 if feat_yes DEVEL; then
1174 echo '#define HAVE_DEVEL' >> ${h}
1177 if feat_yes NYD2; then
1178 echo '#define HAVE_NYD2' >> ${h}
1183 if feat_yes DOTLOCK; then
1184 if link_check readlink 'readlink(2)' << \!
1185 #include <unistd.h>
1186 int main(void)
1188 char buf[128];
1189 readlink("here", buf, sizeof buf);
1190 return 0;
1193 then
1195 else
1196 feat_bail_required DOTLOCK
1200 if feat_yes DOTLOCK; then
1201 if link_check fchown 'fchown(2)' << \!
1202 #include <unistd.h>
1203 int main(void)
1205 fchown(0, 0, 0);
1206 return 0;
1209 then
1211 else
1212 feat_bail_required DOTLOCK
1218 if feat_yes ICONV; then
1219 ${cat} > ${tmp2}.c << \!
1220 #include <iconv.h>
1221 int main(void)
1223 iconv_t id;
1225 id = iconv_open("foo", "bar");
1226 return 0;
1229 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1230 '#define HAVE_ICONV' ||
1231 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1232 '#define HAVE_ICONV' '-liconv' ||
1233 feat_bail_required ICONV
1234 else
1235 echo '/* WANT_ICONV=0 */' >> ${h}
1236 fi # feat_yes ICONV
1238 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1239 ${cat} > ${tmp2}.c << \!
1240 #include <sys/types.h>
1241 #include <sys/socket.h>
1242 #include <sys/un.h>
1243 int main(void)
1245 struct sockaddr_un soun;
1246 socket(AF_UNIX, SOCK_STREAM, 0);
1247 connect(0, (struct sockaddr*)&soun, 0);
1248 shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR);
1249 return 0;
1253 < ${tmp2}.c link_check af_unix 'AF_UNIX sockets' \
1254 '#define HAVE_UNIX_SOCKETS' ||
1255 < ${tmp2}.c link_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1256 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1257 < ${tmp2}.c link_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1258 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1261 if feat_yes SOCKETS; then
1262 ${cat} > ${tmp2}.c << \!
1263 #include "config.h"
1264 #include <sys/types.h>
1265 #include <sys/socket.h>
1266 #include <netinet/in.h>
1268 int main(void)
1270 struct sockaddr s;
1271 socket(AF_INET, SOCK_STREAM, 0);
1272 connect(0, &s, 0);
1273 return 0;
1277 < ${tmp2}.c link_check sockets 'sockets' \
1278 '#define HAVE_SOCKETS' ||
1279 < ${tmp2}.c link_check sockets 'sockets (via -lnsl)' \
1280 '#define HAVE_SOCKETS' '-lnsl' ||
1281 < ${tmp2}.c link_check sockets 'sockets (via -lsocket -lnsl)' \
1282 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1283 feat_bail_required SOCKETS
1284 else
1285 echo '/* WANT_SOCKETS=0 */' >> ${h}
1286 fi # feat_yes SOCKETS
1288 if feat_yes SOCKETS; then
1289 link_check getaddrinfo 'getaddrinfo(3)' \
1290 '#define HAVE_GETADDRINFO' << \!
1291 #include "config.h"
1292 #include <sys/types.h>
1293 #include <sys/socket.h>
1294 #include <stdio.h>
1295 #include <netdb.h>
1297 int main(void)
1299 struct addrinfo a, *ap;
1300 int lrv;
1301 switch ((lrv = getaddrinfo("foo", "0", &a, &ap))) {
1302 case EAI_NONAME:
1303 case EAI_SERVICE:
1304 default:
1305 fprintf(stderr, "%s\n", gai_strerror(lrv));
1306 case 0:
1307 break;
1309 return 0;
1314 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1315 compile_check arpa_inet_h '<arpa/inet.h>' \
1316 '#define HAVE_ARPA_INET_H' << \!
1317 #include "config.h"
1318 #include <sys/types.h>
1319 #include <sys/socket.h>
1320 #include <netdb.h>
1321 #include <netinet/in.h>
1322 #include <arpa/inet.h>
1325 ${cat} > ${tmp2}.c << \!
1326 #include "config.h"
1327 #include <sys/types.h>
1328 #include <sys/socket.h>
1329 #include <stdio.h>
1330 #include <string.h>
1331 #include <netdb.h>
1332 #include <netinet/in.h>
1333 #ifdef HAVE_ARPA_INET_H
1334 #include <arpa/inet.h>
1335 #endif
1337 int main(void)
1339 struct sockaddr_in servaddr;
1340 unsigned short portno;
1341 struct servent *ep;
1342 struct hostent *hp;
1343 struct in_addr **pptr;
1345 portno = 0;
1346 if ((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1347 portno = (unsigned short)ep->s_port;
1349 if ((hp = gethostbyname("POPPY-HOST")) != NULL) {
1350 pptr = (struct in_addr**)hp->h_addr_list;
1351 if (hp->h_addrtype != AF_INET)
1352 fprintf(stderr, "au\n");
1353 } else {
1354 switch (h_errno) {
1355 case HOST_NOT_FOUND:
1356 case TRY_AGAIN:
1357 case NO_RECOVERY:
1358 case NO_DATA:
1359 break;
1360 default:
1361 fprintf(stderr, "au\n");
1362 break;
1366 memset(&servaddr, 0, sizeof servaddr);
1367 servaddr.sin_family = AF_INET;
1368 servaddr.sin_port = htons(portno);
1369 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1370 fprintf(stderr, "Would connect to %s:%d ...\n",
1371 inet_ntoa(**pptr), (int)portno);
1372 return 0;
1376 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1377 < ${tmp2}.c link_check gethostbyname \
1378 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1379 < ${tmp2}.c link_check gethostbyname \
1380 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1381 '' '-lsocket -lnsl' ||
1382 feat_bail_required SOCKETS
1385 feat_yes SOCKETS &&
1386 link_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1387 #include <sys/socket.h>
1388 #include <stdlib.h>
1389 int main(void)
1391 int sockfd = 3;
1392 setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0);
1393 return 0;
1397 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1398 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1399 #include <sys/socket.h>
1400 #include <stdlib.h>
1401 int main(void)
1403 struct timeval tv;
1404 int sockfd = 3;
1405 tv.tv_sec = 42;
1406 tv.tv_usec = 21;
1407 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1408 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1409 return 0;
1413 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1414 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1415 #include <sys/socket.h>
1416 #include <stdlib.h>
1417 int main(void)
1419 struct linger li;
1420 int sockfd = 3;
1421 li.l_onoff = 1;
1422 li.l_linger = 42;
1423 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1424 return 0;
1428 if feat_yes SSL; then
1429 if link_check openssl 'OpenSSL 1.1.0 and above' \
1430 '#define HAVE_SSL
1431 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1432 #include <openssl/ssl.h>
1433 #include <openssl/err.h>
1434 #include <openssl/x509v3.h>
1435 #include <openssl/x509.h>
1436 #include <openssl/rand.h>
1438 #ifdef OPENSSL_NO_TLS1
1439 # error We need TLSv1.
1440 #endif
1442 int main(void)
1444 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1445 SSL_CTX_free(ctx);
1446 PEM_read_PrivateKey(0, 0, 0, 0);
1447 return 0;
1450 then
1452 elif link_check openssl 'OpenSSL' \
1453 '#define HAVE_SSL
1454 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1455 #include <openssl/ssl.h>
1456 #include <openssl/err.h>
1457 #include <openssl/x509v3.h>
1458 #include <openssl/x509.h>
1459 #include <openssl/rand.h>
1461 #if defined OPENSSL_NO_SSL3 && defined OPENSSL_NO_TLS1
1462 # error We need one of SSLv3 and TLSv1.
1463 #endif
1465 int main(void)
1467 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1468 SSL_CTX_free(ctx);
1469 PEM_read_PrivateKey(0, 0, 0, 0);
1470 return 0;
1473 then
1475 else
1476 feat_bail_required SSL
1479 if [ "${have_openssl}" = 'yes' ]; then
1480 compile_check stack_of 'OpenSSL STACK_OF()' \
1481 '#define HAVE_OPENSSL_STACK_OF' << \!
1482 #include <stdio.h> /* For C89 NULL */
1483 #include <openssl/ssl.h>
1484 #include <openssl/err.h>
1485 #include <openssl/x509v3.h>
1486 #include <openssl/x509.h>
1487 #include <openssl/rand.h>
1489 int main(void)
1491 STACK_OF(GENERAL_NAME) *gens = NULL;
1492 printf("%p", gens); /* to make it used */
1493 return 0;
1497 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1498 '#define HAVE_OPENSSL_CONFIG' << \!
1499 #include <stdio.h> /* For C89 NULL */
1500 #include <openssl/conf.h>
1502 int main(void)
1504 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1505 CONF_modules_free();
1506 return 0;
1510 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1511 '#define HAVE_OPENSSL_CONF_CTX' << \!
1512 #include "config.h"
1513 #include <openssl/ssl.h>
1514 #include <openssl/err.h>
1516 int main(void)
1518 #if HAVE_OPENSSL < 10100
1519 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1520 #else
1521 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1522 #endif
1523 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1524 SSL_CONF_CTX_set_flags(cctx,
1525 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1526 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1527 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1528 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1529 SSL_CONF_CTX_finish(cctx);
1530 SSL_CONF_CTX_free(cctx);
1531 SSL_CTX_free(ctx);
1532 return 0;
1536 link_check rand_egd 'OpenSSL RAND_egd()' \
1537 '#define HAVE_OPENSSL_RAND_EGD' << \!
1538 #include <openssl/rand.h>
1540 int main(void)
1542 return RAND_egd("some.where") > 0;
1546 if feat_yes SSL_ALL_ALGORITHMS; then
1547 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1548 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1549 #include <openssl/evp.h>
1551 int main(void)
1553 OpenSSL_add_all_algorithms();
1554 EVP_get_cipherbyname("two cents i never exist");
1555 EVP_cleanup();
1556 return 0;
1559 then
1561 else
1562 feat_bail_required SSL_ALL_ALGORITHMS
1564 fi # SSL_ALL_ALGORITHMS
1566 if feat_yes MD5 && feat_no NOEXTMD5; then
1567 run_check openssl_md5 'MD5 digest in OpenSSL' \
1568 '#define HAVE_OPENSSL_MD5' << \!
1569 #include <stdlib.h>
1570 #include <string.h>
1571 #include <openssl/md5.h>
1573 int main(void)
1575 char const dat[] = "abrakadabrafidibus";
1576 char dig[16], hex[16 * 2];
1577 MD5_CTX ctx;
1578 size_t i, j;
1580 memset(dig, 0, sizeof(dig));
1581 memset(hex, 0, sizeof(hex));
1582 MD5_Init(&ctx);
1583 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1584 MD5_Final(dig, &ctx);
1586 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1587 for (i = 0; i < sizeof(hex) / 2; i++) {
1588 j = i << 1;
1589 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1590 hex[++j] = hexchar(dig[i] & 0x0f);
1592 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1595 fi # feat_yes MD5 && feat_no NOEXTMD5
1597 if feat_yes DEVEL; then
1598 link_check ossl_memhooks 'OpenSSL memory hooks' \
1599 '#define HAVE_OPENSSL_MEMHOOKS' << \!
1600 #include <stdio.h> /* For C89 NULL */
1601 #include <openssl/crypto.h>
1603 int main(void)
1605 CRYPTO_set_mem_ex_functions(NULL, NULL, NULL);
1606 CRYPTO_set_mem_functions(NULL, NULL, NULL);
1607 return 0;
1612 else
1613 echo '/* WANT_SSL=0 */' >> ${h}
1614 fi # feat_yes SSL
1616 if feat_yes SMTP; then
1617 echo '#define HAVE_SMTP' >> ${h}
1618 else
1619 echo '/* WANT_SMTP=0 */' >> ${h}
1622 if feat_yes POP3; then
1623 echo '#define HAVE_POP3' >> ${h}
1624 else
1625 echo '/* WANT_POP3=0 */' >> ${h}
1628 if feat_yes IMAP; then
1629 echo '#define HAVE_IMAP' >> ${h}
1630 else
1631 echo '/* WANT_IMAP=0 */' >> ${h}
1634 if feat_yes GSSAPI; then
1635 ${cat} > ${tmp2}.c << \!
1636 #include <gssapi/gssapi.h>
1638 int main(void)
1640 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1641 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1642 return 0;
1645 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1647 if command -v krb5-config >/dev/null 2>&1; then
1648 i=`command -v krb5-config`
1649 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1650 GSS_INCS="`CFLAGS= ${i} --cflags`"
1651 i='GSS-API via krb5-config(1)'
1652 else
1653 GSS_LIBS='-lgssapi'
1654 GSS_INCS=
1655 i='GSS-API in gssapi/gssapi.h, libgssapi'
1657 if < ${tmp2}.c link_check gss \
1658 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1659 < ${tmp3}.c link_check gss \
1660 'GSS-API in gssapi.h, libgssapi' \
1661 '#define HAVE_GSSAPI
1662 #define GSSAPI_REG_INCLUDE' \
1663 '-lgssapi' ||\
1664 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1665 '#define HAVE_GSSAPI' \
1666 '-lgssapi_krb5' ||\
1667 < ${tmp3}.c link_check gss \
1668 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1669 '#define HAVE_GSSAPI
1670 #define GSS_REG_INCLUDE' \
1671 '-lgssapi -lkrb5 -lcrypto' \
1672 '-I/usr/include/kerberosV' ||\
1673 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1674 '#define HAVE_GSSAPI' \
1675 '-lgss' ||\
1676 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1677 '#define HAVE_GSSAPI
1678 #define GSSAPI_OLD_STYLE' \
1679 '-lgssapi_krb5' << \!
1680 #include <gssapi/gssapi.h>
1681 #include <gssapi/gssapi_generic.h>
1683 int main(void)
1685 gss_import_name(0, 0, gss_nt_service_name, 0);
1686 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1687 return 0;
1690 then
1692 else
1693 feat_bail_required GSSAPI
1695 else
1696 echo '/* WANT_GSSAPI=0 */' >> ${h}
1697 fi # feat_yes GSSAPI
1699 if feat_yes NETRC; then
1700 echo '#define HAVE_NETRC' >> ${h}
1701 else
1702 echo '/* WANT_NETRC=0 */' >> ${h}
1705 if feat_yes AGENT; then
1706 echo '#define HAVE_AGENT' >> ${h}
1707 else
1708 echo '/* WANT_AGENT=0 */' >> ${h}
1711 if feat_yes IDNA; then
1712 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
1713 '-lidn' << \!
1714 #include <idna.h>
1715 #include <idn-free.h>
1716 #include <stringprep.h>
1717 int main(void)
1719 char *utf8, *idna_ascii, *idna_utf8;
1720 utf8 = stringprep_locale_to_utf8("does.this.work");
1721 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
1722 != IDNA_SUCCESS)
1723 return 1;
1724 idn_free(idna_ascii);
1725 /* (Rather link check only here) */
1726 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
1727 return 0;
1730 then
1732 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
1733 '-lidnkit' << \!
1734 #include <stdio.h>
1735 #include <idn/api.h>
1736 #include <idn/result.h>
1737 int main(void)
1739 idn_result_t r;
1740 char ace_name[256];
1741 char local_name[256];
1743 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
1744 sizeof(ace_name));
1745 if (r != idn_success) {
1746 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
1747 return 1;
1749 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
1750 if (r != idn_success) {
1751 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
1752 return 1;
1754 return 0;
1757 then
1759 else
1760 feat_bail_required IDNA
1763 if [ -n "${have_idna}" ]; then
1764 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
1765 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
1767 else
1768 echo '/* WANT_IDNA=0 */' >> ${h}
1771 if feat_yes IMAP_SEARCH; then
1772 echo '#define HAVE_IMAP_SEARCH' >> ${h}
1773 else
1774 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
1777 if feat_yes REGEX; then
1778 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
1779 #include <regex.h>
1780 #include <stdlib.h>
1781 int main(void)
1783 int status;
1784 regex_t re;
1785 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
1786 return 1;
1787 status = regexec(&re, "plan9", 0,NULL, 0);
1788 regfree(&re);
1789 return !(status == REG_NOMATCH);
1792 then
1794 else
1795 feat_bail_required REGEX
1797 else
1798 echo '/* WANT_REGEX=0 */' >> ${h}
1801 if feat_yes READLINE; then
1802 __edrdlib() {
1803 link_check readline "for readline(3) (${1})" \
1804 '#define HAVE_READLINE' "${1}" << \!
1805 #include <stdio.h>
1806 #include <readline/history.h>
1807 #include <readline/readline.h>
1808 int main(void)
1810 char *rl;
1811 HISTORY_STATE *hs;
1812 HIST_ENTRY **he;
1813 int i;
1814 using_history();
1815 read_history("");
1816 stifle_history(242);
1817 rl = readline("Enter a line:");
1818 if (rl && *rl)
1819 add_history(rl);
1820 write_history("");
1821 rl_extend_line_buffer(10);
1822 rl_point = rl_end = 10;
1823 rl_pre_input_hook = (rl_hook_func_t*)NULL;
1824 rl_forced_update_display();
1825 clear_history();
1826 hs = history_get_history_state();
1827 i = hs->length;
1828 he = history_list();
1829 if (i > 0)
1830 rl = he[0]->line;
1831 rl_free_line_state();
1832 rl_cleanup_after_signal();
1833 rl_reset_after_signal();
1834 return 0;
1839 __edrdlib -lreadline ||
1840 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
1841 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
1844 if feat_yes EDITLINE && [ -z "${have_readline}" ]; then
1845 __edlib() {
1846 link_check editline "for editline(3) (${1})" \
1847 '#define HAVE_EDITLINE' "${1}" << \!
1848 #include <stdio.h> /* For C89 NULL */
1849 #include <histedit.h>
1850 static char * getprompt(void) { return (char*)"ok"; }
1851 int main(void)
1853 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
1854 HistEvent he;
1855 History *el_hcom = history_init();
1856 history(el_hcom, &he, H_SETSIZE, 242);
1857 el_set(el_el, EL_SIGNAL, 0);
1858 el_set(el_el, EL_TERMINAL, NULL);
1859 el_set(el_el, EL_HIST, &history, el_hcom);
1860 el_set(el_el, EL_EDITOR, "emacs");
1861 el_set(el_el, EL_PROMPT, &getprompt);
1862 el_source(el_el, NULL);
1863 history(el_hcom, &he, H_GETSIZE);
1864 history(el_hcom, &he, H_CLEAR);
1865 el_end(el_el);
1866 /* TODO add loader and addfn checks */
1867 history_end(el_hcom);
1868 return 0;
1873 __edlib -ledit ||
1874 __edlib '-ledit -ltermcap' || feat_bail_required EDITLINE
1875 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
1878 if feat_yes NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
1879 [ -n "${have_c90amend1}" ]; then
1880 have_ncl=1
1881 echo '#define HAVE_NCL' >> ${h}
1882 else
1883 feat_bail_required NCL
1884 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
1887 # Generic have-a-command-line-editor switch for those who need it below
1888 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
1889 [ -n "${have_readline}" ]; then
1890 have_cle=1
1893 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
1894 echo '#define HAVE_HISTORY' >> ${h}
1895 else
1896 echo '/* WANT_HISTORY=0 */' >> ${h}
1899 if [ -n "${have_cle}" ] && feat_yes TABEXPAND; then
1900 echo '#define HAVE_TABEXPAND' >> ${h}
1901 else
1902 echo '/* WANT_TABEXPAND=0 */' >> ${h}
1905 if feat_yes TERMCAP; then
1906 __termlib() {
1907 link_check termcap "for termcap(3) (via ${4})" \
1908 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
1909 #include <stdio.h>
1910 #include <stdlib.h>
1911 #include <string.h>
1912 ${2}
1913 #include <term.h>
1914 #define PTR2SIZE(X) ((unsigned long)(X))
1915 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
1916 static char *_termcap_buffer, *_termcap_ti, *_termcap_te;
1917 int main(void)
1919 char buf[1024+512], cmdbuf[2048], *cpb, *cpti, *cpte, *cp;
1920 tgetent(buf, getenv("TERM"));
1921 cpb = cmdbuf;
1922 cpti = cpb;
1923 if ((cp = tgetstr(UNCONST("ti"), &cpb)) == NULL)
1924 goto jleave;
1925 cpte = cpb;
1926 if ((cp = tgetstr(UNCONST("te"), &cpb)) == NULL)
1927 goto jleave;
1928 _termcap_buffer = malloc(PTR2SIZE(cpb - cmdbuf));
1929 memcpy(_termcap_buffer, cmdbuf, PTR2SIZE(cpb - cmdbuf));
1930 _termcap_ti = _termcap_buffer + PTR2SIZE(cpti - cmdbuf);
1931 _termcap_te = _termcap_ti + PTR2SIZE(cpte - cpti);
1932 tputs(_termcap_ti, 1, &putchar);
1933 tputs(_termcap_te, 1, &putchar);
1934 jleave:
1935 return (cp == NULL);
1937 _EOT
1940 __termlib -ltermcap '' '' termcap ||
1941 __termlib -ltermcap '#include <curses.h>' '
1942 #define HAVE_TERMCAP_CURSES' \
1943 'curses.h / -ltermcap' ||
1944 __termlib -lcurses '#include <curses.h>' '
1945 #define HAVE_TERMCAP_CURSES' \
1946 'curses.h / -lcurses' ||
1947 feat_bail_required TERMCAP
1948 else
1949 echo '/* WANT_TERMCAP=0 */' >> ${h}
1952 if feat_yes ERRORS; then
1953 echo '#define HAVE_ERRORS' >> ${h}
1954 else
1955 echo '/* WANT_ERRORS=0 */' >> ${h}
1960 if feat_yes SPAM_SPAMC; then
1961 echo '#define HAVE_SPAM_SPAMC' >> ${h}
1962 if command -v spamc >/dev/null 2>&1; then
1963 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
1965 else
1966 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
1969 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
1970 echo '#define HAVE_SPAM_SPAMD' >> ${h}
1971 else
1972 feat_bail_required SPAM_SPAMD
1973 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
1976 if feat_yes SPAM_FILTER; then
1977 echo '#define HAVE_SPAM_FILTER' >> ${h}
1978 else
1979 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
1982 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
1983 echo '#define HAVE_SPAM' >> ${h}
1984 else
1985 echo '/* HAVE_SPAM */' >> ${h}
1988 if feat_yes DOCSTRINGS; then
1989 echo '#define HAVE_DOCSTRINGS' >> ${h}
1990 else
1991 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
1994 if feat_yes QUOTE_FOLD &&\
1995 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
1996 echo '#define HAVE_QUOTE_FOLD' >> ${h}
1997 else
1998 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2001 if feat_yes FILTER_HTML_TAGSOUP; then
2002 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2003 else
2004 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2007 if feat_yes COLOUR; then
2008 echo '#define HAVE_COLOUR' >> ${h}
2009 else
2010 echo '/* WANT_COLOUR=0 */' >> ${h}
2013 if feat_yes DOTLOCK; then
2014 echo '#define HAVE_DOTLOCK' >> ${h}
2015 else
2016 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2019 if feat_yes MD5; then
2020 echo '#define HAVE_MD5' >> ${h}
2021 else
2022 echo '/* WANT_MD5=0 */' >> ${h}
2025 ## Summarizing
2027 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2028 squeeze_em() {
2029 < "${1}" > "${2}" ${awk} \
2030 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2032 ${rm} -f ${tmp}
2033 squeeze_em ${inc} ${tmp}
2034 ${mv} ${tmp} ${inc}
2035 squeeze_em ${lib} ${tmp}
2036 ${mv} ${tmp} ${lib}
2038 # config.h
2039 ${mv} ${h} ${tmp}
2040 printf '#ifndef _CONFIG_H\n# define _CONFIG_H 1\n' > ${h}
2041 ${cat} ${tmp} >> ${h}
2042 ${rm} -f ${tmp}
2044 printf '\n/* The "feature string" */\n' >> ${h}
2045 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2046 printf 'static char const _features[] = "MIME"\n' >> ${h}
2047 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2048 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2049 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2050 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2051 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2052 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2053 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2054 >> ${h}
2055 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2056 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2057 printf '# ifdef HAVE_IMAP\n ",IMAP"\n# endif\n' >> ${h}
2058 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2059 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2060 printf '# ifdef HAVE_AGENT\n ",AGENT"\n# endif\n' >> ${h}
2061 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2062 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2063 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2064 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2065 printf '# ifdef HAVE_EDITLINE\n ",EDITLINE"\n# endif\n' >> ${h}
2066 printf '# ifdef HAVE_NCL\n ",NCL"\n# endif\n' >> ${h}
2067 printf '# ifdef HAVE_TABEXPAND\n ",TABEXPAND"\n# endif\n' >> ${h}
2068 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2069 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2070 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2071 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2072 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2073 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2074 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2075 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2076 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2077 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2078 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2079 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2080 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2082 # Create the real mk.mk
2083 ${rm} -rf ${tmp0}.* ${tmp0}*
2084 printf 'OBJ_SRC = ' >> ${mk}
2085 if feat_no AMALGAMATION; then
2086 for i in *.c; do
2087 if [ "${i}" = privsep.c ]; then
2088 continue
2090 printf "${i} " >> ${mk}
2091 done
2092 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2093 else
2094 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2096 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2097 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2098 printf '# undef _CONFIG_H\n' >> ${h}
2099 printf '# define _CONFIG_H 2\n' >> ${h}
2100 for i in *.c; do
2101 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2102 [ "${i}" = privsep.c ]; then
2103 continue
2105 printf "${i} " >> ${mk}
2106 printf "# include \"${i}\"\n" >> ${h}
2107 done
2108 echo >> ${mk}
2111 printf '#endif /* _CONFIG_H */\n' >> ${h}
2113 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2114 echo "INCS = `${cat} ${inc}`" >> ${mk}
2115 echo >> ${mk}
2116 ${cat} ./mk-mk.in >> ${mk}
2118 ## Finished!
2120 ${cat} > ${tmp2}.c << \!
2121 #include "config.h"
2123 :The following optional features are enabled:
2124 #ifdef HAVE_SETLOCALE
2125 : + Locale support: Printable characters depend on the environment
2126 # ifdef HAVE_C90AMEND1
2127 : + Multibyte character support
2128 # endif
2129 # ifdef HAVE_NL_LANGINFO
2130 : + Automatic detection of terminal character set
2131 # endif
2132 #endif
2133 #ifdef HAVE_ICONV
2134 : + Character set conversion using iconv()
2135 #endif
2136 #ifdef HAVE_SOCKETS
2137 : + Network support
2138 #endif
2139 #ifdef HAVE_SSL
2140 # ifdef HAVE_OPENSSL
2141 : + S/MIME and SSL/TLS (OpenSSL)
2142 # endif
2143 # ifdef HAVE_SSL_ALL_ALGORITHMS
2144 : + + Support for more ("all") digest and cipher algorithms
2145 # endif
2146 #endif
2147 #ifdef HAVE_SMTP
2148 : + SMTP protocol
2149 #endif
2150 #ifdef HAVE_POP3
2151 : + POP3 protocol
2152 #endif
2153 #ifdef HAVE_IMAP
2154 : + IMAP protocol
2155 #endif
2156 #ifdef HAVE_GSSAPI
2157 : + GSS-API authentication
2158 #endif
2159 #ifdef HAVE_NETRC
2160 : + .netrc file support
2161 #endif
2162 #ifdef HAVE_AGENT
2163 : + Password query through agent
2164 #endif
2165 #ifdef HAVE_IDNA
2166 : + IDNA (internationalized domain names for applications) support
2167 #endif
2168 #ifdef HAVE_IMAP_SEARCH
2169 : + IMAP-style search expressions
2170 #endif
2171 #ifdef HAVE_REGEX
2172 : + Regular expression support (searches, conditional expressions etc.)
2173 #endif
2174 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
2175 : + Command line editing
2176 # ifdef HAVE_TABEXPAND
2177 : + + Tabulator expansion
2178 # endif
2179 # ifdef HAVE_HISTORY
2180 : + + History management
2181 # endif
2182 #endif
2183 #ifdef HAVE_TERMCAP
2184 : + Terminal capability queries
2185 #endif
2186 #ifdef HAVE_SPAM
2187 : + Spam management
2188 # ifdef HAVE_SPAM_SPAMC
2189 : + + Via spamc(1) (of spamassassin(1))
2190 # endif
2191 # ifdef HAVE_SPAM_SPAMD
2192 : + + Directly via spamd(1) (of spamassassin(1))
2193 # endif
2194 # ifdef HAVE_SPAM_FILTER
2195 : + + Via freely configurable *spam-filter-XY*s
2196 # endif
2197 #endif
2198 #ifdef HAVE_DOCSTRINGS
2199 : + Documentation summary strings
2200 #endif
2201 #ifdef HAVE_QUOTE_FOLD
2202 : + Extended *quote-fold*ing
2203 #endif
2204 #ifdef HAVE_FILTER_HTML_TAGSOUP
2205 : + Builtin HTML-to-text filter (for display purposes, primitive)
2206 #endif
2207 #ifdef HAVE_COLOUR
2208 : + Coloured message display (simple)
2209 #endif
2210 #ifdef HAVE_DOTLOCK
2211 : + Dotlock files and privilege-separated file dotlock program
2212 #endif
2214 :The following optional features are disabled:
2215 #ifndef HAVE_SETLOCALE
2216 : - Locale support: Only ASCII characters are recognized
2217 #endif
2218 # ifndef HAVE_C90AMEND1
2219 : - Multibyte character support
2220 # endif
2221 # ifndef HAVE_NL_LANGINFO
2222 : - Automatic detection of terminal character set
2223 # endif
2224 #ifndef HAVE_ICONV
2225 : - Character set conversion using iconv()
2226 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2227 #endif
2228 #ifndef HAVE_SOCKETS
2229 : - Network support
2230 #endif
2231 #ifndef HAVE_SSL
2232 : - S/MIME and SSL/TLS
2233 #else
2234 # ifndef HAVE_SSL_ALL_ALGORITHMS
2235 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2236 # endif
2237 #endif
2238 #ifndef HAVE_SMTP
2239 : - SMTP protocol
2240 #endif
2241 #ifndef HAVE_POP3
2242 : - POP3 protocol
2243 #endif
2244 #ifndef HAVE_IMAP
2245 : - IMAP protocol
2246 #endif
2247 #ifndef HAVE_GSSAPI
2248 : - GSS-API authentication
2249 #endif
2250 #ifndef HAVE_NETRC
2251 : - .netrc file support
2252 #endif
2253 #ifndef HAVE_AGENT
2254 : - Password query through agent
2255 #endif
2256 #ifndef HAVE_IDNA
2257 : - IDNA (internationalized domain names for applications) support
2258 #endif
2259 #ifndef HAVE_IMAP_SEARCH
2260 : - IMAP-style search expressions
2261 #endif
2262 #ifndef HAVE_REGEX
2263 : - Regular expression support
2264 #endif
2265 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2266 : - Command line editing and history
2267 #endif
2268 #ifndef HAVE_TERMCAP
2269 : - Terminal capability queries
2270 #endif
2271 #ifndef HAVE_SPAM
2272 : - Spam management
2273 #endif
2274 #ifndef HAVE_DOCSTRINGS
2275 : - Documentation summary strings
2276 #endif
2277 #ifndef HAVE_QUOTE_FOLD
2278 : - Extended *quote-fold*ing
2279 #endif
2280 #ifndef HAVE_FILTER_HTML_TAGSOUP
2281 : - Builtin HTML-to-text filter (for display purposes, primitive)
2282 #endif
2283 #ifndef HAVE_COLOUR
2284 : - Coloured message display (simple)
2285 #endif
2286 #ifndef HAVE_DOTLOCK
2287 : - Dotlock files and privilege-separated file dotlock program
2288 #endif
2290 #if !defined HAVE_WORDEXP || !defined HAVE_FCHDIR ||\
2291 defined HAVE_DEBUG || defined HAVE_DEVEL
2292 :Remarks:
2293 # ifndef HAVE_WORDEXP
2294 : . WARNING: the function wordexp(3) could not be found.
2295 : _ This means that echo(1) will be used via the sh(1)ell in order
2296 : _ to expand shell meta characters in filenames, which is a potential
2297 : _ security hole. Consider to either upgrade your system or set the
2298 : _ *SHELL* variable to some safe(r) wrapper script.
2299 : _ P.S.: the codebase is in transition away from wordexp(3) to some
2300 : _ safe (restricted) internal mechanism, see "COMMANDS" manual, read
2301 : _ about shell word expression in its introduction for more on that.
2302 # endif
2303 # ifndef HAVE_FCHDIR
2304 : . The function fchdir(2) could not be found. We will use chdir(2)
2305 : _ instead. This is not a problem unless the current working
2306 : _ directory of mailx is moved while the IMAP cache is used.
2307 # endif
2308 # ifdef HAVE_DEBUG
2309 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2310 # endif
2311 # ifdef HAVE_DEVEL
2312 : . Computers do not blunder.
2313 # endif
2315 #endif /* Remarks */
2316 :Setup:
2317 : . System-wide resource file: SYSCONFRC
2318 : . bindir: BINDIR
2319 #ifdef HAVE_DOTLOCK
2320 : . libexecdir: LIBEXECDIR
2321 #endif
2322 : . mandir: MANDIR
2323 : . sendmail(1): SENDMAIL (argv[0] = SENDMAIL_PROGNAME)
2324 : . $MAILSPOOL: MAILSPOOL
2328 ${make} -f ${makefile} ${tmp2}.x
2329 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
2331 # s-it-mode