Turn NCL into M(ailx) L(ine) E(ditor)..
[s-mailx.git] / mk-conf.sh
blob573e848bd480fd301f1e520688d081813154f729
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
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_MLE=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
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_MLE=1
39 WANT_HISTORY=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_MLE=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_MLE=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; 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 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
129 WANT_SMTP=0 WANT_POP3=0
130 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
132 if feat_no SMTP; then
133 WANT_GSSAPI=0
136 if feat_no READLINE && feat_no MLE; then
137 WANT_HISTORY=0
140 # If we don't need MD5 leave it alone
141 if feat_no SOCKETS; then
142 WANT_MD5=0
145 if feat_yes DEVEL; then
146 WANT_DEBUG=1
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 # TODO cc_maxopt is brute simple, we should compile test program and dig real
157 # compiler versions for known compilers, then be more specific
158 cc_maxopt=100
159 _CFLAGS= _LDFLAGS=
161 os_early_setup() {
162 i="${OS:-`uname -s`}"
164 if [ ${i} = SunOS ]; then
165 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
166 _os_early_setup_sunos
170 os_setup() {
171 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
172 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
173 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
174 msg 'Operating system is "%s"' ${OS}
176 if [ ${OS} = sunos ]; then
177 msg ' . have special SunOS / Solaris "setup" rules ...'
178 _os_setup_sunos
179 elif [ ${OS} = unixware ]; then
180 msg ' . have special UnixWare environmental rules ...'
181 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
182 CC=cc
183 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
185 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
186 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
187 export CC CFLAGS LDFLAGS
188 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
190 elif [ -n "${VERBOSE}" ]; then
191 msg ' . no special treatment for this system necessary or known'
194 # Sledgehammer: better set _GNU_SOURCE
195 # And in general: oh, boy!
196 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
197 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
198 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
199 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
201 # On pkgsrc(7) systems automatically add /usr/pkg/*
202 if [ -d /usr/pkg ]; then
203 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
204 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
208 _os_early_setup_sunos() {
209 # According to standards(5), this is what we need to do
210 if [ -d /usr/xpg4 ]; then :; else
211 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
212 config_exit 1
214 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
215 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
216 export PATH
219 _os_setup_sunos() {
220 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
221 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
223 # Include packages
224 if [ -d /opt/csw ]; then
225 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
226 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
229 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
230 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
232 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
233 if [ -x "${cksum}" ]; then :; else
234 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
235 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
236 msg 'ERROR: However, we do so only for tests.'
237 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
238 config_exit 1
241 if feat_yes AUTOCC; then
242 if command -v cc >/dev/null 2>&1; then
243 CC=cc
244 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
246 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
247 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
248 export CC CFLAGS LDFLAGS
249 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
250 else
251 # Assume gcc(1)
252 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
257 # Check out compiler ($CC) and -flags ($CFLAGS)
258 cc_setup() {
259 # Even though it belongs into cc_flags we will try to compile and link
260 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
261 # ADDCFLAGS/ADDLDFLAGS
262 if feat_no AUTOCC; then
263 _cc_default
264 # Ensure those don't do any harm
265 ADDCFLAGS= ADDLDFLAGS=
266 export ADDCFLAGS ADDLDFLAGS
267 return
268 else
269 CFLAGS= LDFLAGS=
270 export CFLAGS LDFLAGS
273 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
275 printf >&2 'Searching for a usable C compiler .. $CC='
276 if { i="`command -v clang`"; }; then
277 CC=${i}
278 elif { i="`command -v gcc`"; }; then
279 CC=${i}
280 elif { i="`command -v c99`"; }; then
281 CC=${i}
282 elif { i="`command -v tcc`"; }; then
283 CC=${i}
284 elif { i="`command -v pcc`"; }; then
285 CC=${i}
286 else
287 if [ "${CC}" = cc ]; then
289 elif { i="`command -v c89`"; }; then
290 CC=${i}
291 else
292 printf >&2 'boing booom tschak\n'
293 msg 'ERROR: I cannot find a compiler!'
294 msg ' Neither of clang(1), gcc(1), tcc(1), c89(1) and c99(1).'
295 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
296 config_exit 1
299 printf >&2 -- '"%s"\n' "${CC}"
300 export CC
303 _cc_default() {
304 if [ -z "${CC}" ]; then
305 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
306 config_exit 1
309 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
311 else
312 msg 'Using C compiler $CC="%s"' "${CC}"
316 cc_flags() {
317 if feat_yes AUTOCC; then
318 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
319 cc_check_silent=1
320 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
321 else
322 cc_check_silent=
323 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
326 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
327 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
328 msg ' . have special tcc(1) environmental rules ...'
329 _cc_flags_tcc
330 else
331 # As of pcc CVS 2016-04-02, stack protection support is announced but
332 # will break if used on Linux
333 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
334 force_no_stackprot=1
336 _cc_flags_generic
339 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
340 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
341 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
342 else
343 if feat_no DEBUG; then
344 CFLAGS="-DNDEBUG ${CFLAGS}"
347 msg ''
348 export CFLAGS LDFLAGS
351 _cc_flags_tcc() {
352 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
353 _CFLAGS= _LDFLAGS=
355 cc_check -Wall
356 cc_check -Wextra
357 cc_check -pedantic
359 if feat_yes DEBUG; then
360 # May have problems to find libtcc cc_check -b
361 cc_check -g
364 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
365 unset __cflags __ldflags
368 _cc_flags_generic() {
369 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
370 _CFLAGS= _LDFLAGS=
371 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
373 # Check -g first since some others may rely upon -g / optim. level
374 if feat_yes DEBUG; then
375 cc_check -O
376 cc_check -g
377 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
379 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
381 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
383 else
384 cc_check -O
387 if feat_yes DEVEL && cc_check -Weverything; then
389 else
390 cc_check -Wall
391 cc_check -Wextra
392 cc_check -Wbad-function-cast
393 cc_check -Wcast-align
394 cc_check -Wcast-qual
395 cc_check -Winit-self
396 cc_check -Wmissing-prototypes
397 cc_check -Wshadow
398 cc_check -Wunused
399 cc_check -Wwrite-strings
400 cc_check -Wno-long-long
402 cc_check -pedantic
404 if feat_yes AMALGAMATION && feat_no DEVEL; then
405 cc_check -Wno-unused-function
407 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
409 cc_check -fno-unwind-tables
410 cc_check -fno-asynchronous-unwind-tables
411 cc_check -fstrict-aliasing
412 if cc_check -fstrict-overflow && feat_yes DEVEL; then
413 cc_check -Wstrict-overflow=5
416 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
417 if [ -z "${force_no_stackprot}" ]; then
418 if cc_check -fstack-protector-strong ||
419 cc_check -fstack-protector-all; then
420 cc_check -D_FORTIFY_SOURCE=2
422 else
423 msg 'Not checking for -fstack-protector compiler option,'
424 msg 'since that caused errors in a "similar" configuration.'
425 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
429 if feat_yes AMALGAMATION; then
430 cc_check -pipe
433 # LD (+ dependend CC)
435 if feat_yes DEVEL; then
436 _ccfg=${_CFLAGS}
437 # -fsanitize=address
438 #if cc_check -fsanitize=memory &&
439 # ld_check -fsanitize=memory &&
440 # cc_check -fsanitize-memory-track-origins=2 &&
441 # ld_check -fsanitize-memory-track-origins=2; then
443 #else
444 # _CFLAGS=${_ccfg}
448 ld_check -Wl,-z,relro
449 ld_check -Wl,-z,now
450 ld_check -Wl,-z,noexecstack
452 # Address randomization
453 _ccfg=${_CFLAGS}
454 if cc_check -fPIE || cc_check -fpie; then
455 ld_check -pie || _CFLAGS=${_ccfg}
457 unset _ccfg
459 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
460 unset __cflags __ldflags
463 ## -- >8 -- 8< -- ##
465 ## Notes:
466 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
467 ## redirection, so use "printf '' >" instead
469 ## Very first: we undergo several states regarding I/O redirection etc.,
470 ## but need to deal with option updates from within all. Since all the
471 ## option stuff should be above the scissor line, define utility functions
472 ## and redefine them as necessary.
473 ## And, since we have those functions, simply use them for whatever
475 config_exit() {
476 exit ${1}
479 msg() {
480 fmt=${1}
481 shift
482 printf >&2 -- "${fmt}\\n" "${@}"
485 ## First of all, create new configuration and check wether it changed
487 rc=./make.rc
488 lst=./config.lst
489 h=./config.h h_name=config.h
490 mk=./mk.mk
492 newlst=./config.lst-new
493 newmk=./config.mk-new
494 newh=./config.h-new
495 tmp0=___tmp
496 tmp=./${tmp0}1$$
497 tmp2=./${tmp0}2$$
499 t1=ten10one1ten10one1
500 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
501 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
502 ) > /dev/null 2>&1; then
503 good_shell=1
504 else
505 unset good_shell
507 unset t1
509 # We need some standard utilities
510 unset -f command
511 check_tool() {
512 n=${1} i=${2} opt=${3:-0}
513 # Evaluate, just in case user comes in with shell snippets (..well..)
514 eval i="${i}"
515 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
516 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
517 eval ${n}=${i}
518 return 0
520 if [ ${opt} -eq 0 ]; then
521 msg 'ERROR: no trace of utility "%s"' "${n}"
522 config_exit 1
524 return 1
527 # Very easy checks for the operating system in order to be able to adjust paths
528 # or similar very basic things which we need to be able to go at all
529 os_early_setup
531 # Check those tools right now that we need before including $rc
532 msg 'Checking for basic utility set'
533 check_tool awk "${awk:-`command -v awk`}"
534 check_tool rm "${rm:-`command -v rm`}"
535 check_tool tr "${tr:-`command -v tr`}"
537 # Our feature check environment
538 feat_val_no() {
539 [ "x${1}" = x0 ] ||
540 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
543 feat_val_yes() {
544 [ "x${1}" = x1 ] ||
545 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
546 [ "x${1}" = xrequire ]
549 feat_val_require() {
550 [ "x${1}" = xrequire ]
553 _feat_check() {
554 eval i=\$WANT_${1}
555 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
556 if feat_val_no "${i}"; then
557 return 1
558 elif feat_val_yes "${i}"; then
559 return 0
560 else
561 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
562 "${1}" "${i}"
563 config_exit 11
567 feat_yes() {
568 _feat_check ${1}
571 feat_no() {
572 _feat_check ${1} && return 1
573 return 0
576 feat_require() {
577 eval i=\$WANT_${1}
578 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
579 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
582 feat_bail_required() {
583 if feat_require ${1}; then
584 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
585 config_exit 13
587 eval WANT_${1}=0
588 option_update # XXX this is rather useless here (dependency chain..)
591 # Include $rc, but only take from it what wasn't overwritten by the user from
592 # within the command line or from a chosen fixed CONFIG=
593 # Note we leave alone the values
594 trap "exit 1" HUP INT TERM
595 trap "${rm} -f ${tmp}" EXIT
597 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
598 ${rm} -f ${tmp}
599 # We want read(1) to perform backslash escaping in order to be able to use
600 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
601 # VMs (see [fa2e248]), Aharon Robbins suggested the following
602 < ${rc} ${awk} 'BEGIN{line = ""}{
603 gsub(/^[[:space:]]+/, "", $0)
604 gsub(/[[:space:]]+$/, "", $0)
605 if(gsub(/\\$/, "", $0)){
606 line = line $0
607 next
608 }else
609 line = line $0
610 if(index(line, "#") == 1){
611 line = ""
612 }else if(length(line)){
613 print line
614 line = ""
616 }' |
617 while read line; do
618 if [ -n "${good_shell}" ]; then
619 i=${line%%=*}
620 else
621 i=`${awk} -v LINE="${line}" 'BEGIN{
622 gsub(/=.*$/, "", LINE)
623 print LINE
626 if [ "${i}" = "${line}" ]; then
627 msg 'ERROR: invalid syntax in "%s"' "${line}"
628 continue
631 eval j="\$${i}" jx="\${${i}+x}"
632 if [ -n "${j}" ] || [ "${jx}" = x ]; then
633 : # Yet present
634 else
635 j=`${awk} -v LINE="${line}" 'BEGIN{
636 gsub(/^[^=]*=/, "", LINE)
637 gsub(/^\"*/, "", LINE)
638 gsub(/\"*$/, "", LINE)
639 print LINE
642 echo "${i}=\"${j}\""
643 done > ${tmp}
644 # Reread the mixed version right now
645 . ./${tmp}
646 printf >&2 'done\n'
648 # We need to know about that now, in order to provide utility overwrites etc.
649 os_setup
651 msg 'Checking for remaining set of utilities'
652 check_tool grep "${grep:-`command -v grep`}"
654 # Before we step ahead with the other utilities perform a path cleanup first.
655 # We need this function also for C_INCLUDE_PATH and LD_LIBRARY_PATH
656 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
657 path_check() {
658 varname=${1} addflag=${2} flagvarname=${3}
659 j=${IFS}
660 IFS=:
661 eval "set -- \$${1}"
662 IFS=${j}
663 j= k= y= z=
664 for i
666 [ -z "${i}" ] && continue
667 [ -d "${i}" ] || continue
668 if [ -n "${j}" ]; then
669 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
671 else
672 y="${y} :${i}:"
673 j="${j}:${i}"
674 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
676 else
677 y=" :${i}:"
678 j="${i}"
679 [ -n "${addflag}" ] && k="${addflag}${i}"
681 done
682 eval "${varname}=\"${j}\""
683 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
684 unset varname
687 path_check PATH
689 # awk(1) above
690 check_tool cat "${cat:-`command -v cat`}"
691 check_tool chmod "${chmod:-`command -v chmod`}"
692 check_tool cp "${cp:-`command -v cp`}"
693 check_tool cmp "${cmp:-`command -v cmp`}"
694 # grep(1) above
695 check_tool mkdir "${mkdir:-`command -v mkdir`}"
696 check_tool mv "${mv:-`command -v mv`}"
697 # rm(1) above
698 check_tool sed "${sed:-`command -v sed`}"
699 check_tool sort "${sort:-`command -v sort`}"
700 check_tool tee "${tee:-`command -v tee`}"
702 check_tool chown "${chown:-`command -v chown`}" 1 ||
703 check_tool chown "/sbin/chown" 1 ||
704 check_tool chown "/usr/sbin/chown"
706 check_tool make "${MAKE:-`command -v make`}"
707 MAKE=${make}
708 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
709 HAVE_STRIP=1 || HAVE_STRIP=0
711 # For ./cc-test.sh only
712 check_tool cksum "${cksum:-`command -v cksum`}"
714 # Update WANT_ options now, in order to get possible inter-dependencies right
715 option_update
717 # (No functions since some shells loose non-exported variables in traps)
718 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
719 trap "trap \"\" HUP INT TERM EXIT;\
720 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newh}" EXIT
722 # Our configuration options may at this point still contain shell snippets,
723 # we need to evaluate them in order to get them expanded, and we need those
724 # evaluated values not only in our new configuration file, but also at hand..
725 printf >&2 'Evaluating all configuration items ... '
726 ${rm} -f ${newlst} ${newmk} ${newh}
727 exec 5<&0 6>&1 <${tmp} >${newlst}
728 while read line; do
730 if [ -n "${good_shell}" ]; then
731 i=${line%%=*}
732 [ "${i}" != "${i#WANT_}" ] && z=1
733 else
734 i=`${awk} -v LINE="${line}" 'BEGIN{
735 gsub(/=.*$/, "", LINE);\
736 print LINE
738 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
743 eval j=\$${i}
744 if [ -n "${z}" ]; then
745 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
746 if [ -z "${j}" ] || feat_val_no "${j}"; then
748 printf "/*#define ${i}*/\n" >> ${newh}
749 elif feat_val_yes "${j}"; then
750 if feat_val_require "${j}"; then
751 j=require
752 else
755 printf "#define ${i}\n" >> ${newh}
756 else
757 msg 'ERROR: cannot parse <%s>' "${line}"
758 config_exit 1
760 else
761 printf "#define ${i} \"${j}\"\n" >> ${newh}
763 printf "${i} = ${j}\n" >> ${newmk}
764 printf "${i}=${j}\n"
765 eval "${i}=\"${j}\""
766 done
767 exec 0<&5 1>&6 5<&- 6<&-
768 printf >&2 'done\n'
770 # Add the known utility and some other variables
771 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
772 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
774 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
775 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
776 if feat_yes DOTLOCK; then
777 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
778 else
779 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
782 for i in \
783 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
784 MAKE make strip \
785 cksum; do
786 eval j=\$${i}
787 printf "${i} = ${j}\n" >> ${newmk}
788 printf "${i}=${j}\n" >> ${newlst}
789 done
791 # Build a basic set of INCS and LIBS according to user environment.
792 path_check C_INCLUDE_PATH -I _INCS
793 INCS="${INCS} ${_INCS}"
794 path_check LD_LIBRARY_PATH -L _LIBS
795 LIBS="${LIBS} ${_LIBS}"
796 unset _INCS _LIBS
797 export C_INCLUDE_PATH LD_LIBRARY_PATH
799 if [ -n "${need_R_ldflags}" ]; then
800 i=${IFS}
801 IFS=:
802 set -- ${LD_LIBRARY_PATH}
803 IFS=${i}
804 for i
806 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
807 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
808 done
809 export LDFLAGS
812 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
814 cc_setup
816 ${cat} > ${tmp}.c << \!
817 #include <stdio.h>
818 #include <string.h>
819 static void doit(char const *s);
821 main(int argc, char **argv){
822 (void)argc;
823 (void)argv;
824 doit("Hello world");
825 return 0;
827 static void
828 doit(char const *s){
829 char buf[12];
830 strcpy(buf, s);
831 puts(s);
835 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
836 -o ${tmp2} ${tmp}.c ${LIBS}; then
838 else
839 msg 'ERROR: i cannot compile a "Hello world" via'
840 msg ' %s' \
841 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
842 msg 'ERROR: Please read INSTALL, rerun'
843 config_exit 1
846 cc_check() {
847 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
848 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
849 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
850 _CFLAGS="${_CFLAGS} ${1}"
851 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
852 return 0
854 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
855 return 1
858 ld_check() {
859 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
860 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1} ${ADDLDFLAGS} \
861 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
862 _LDFLAGS="${_LDFLAGS} ${1}"
863 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
864 return 0
866 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
867 return 1
870 cc_flags
872 for i in \
873 INCS LIBS \
874 ; do
875 eval j=\$${i}
876 printf -- "${i}=${j}\n" >> ${newlst}
877 done
878 for i in \
879 CC \
880 CFLAGS \
881 LDFLAGS \
882 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
883 OSFULLSPEC \
884 ; do
885 eval j=\$${i}
886 printf -- "${i} = ${j}\n" >> ${newmk}
887 printf -- "${i}=${j}\n" >> ${newlst}
888 done
890 # Now finally check wether we already have a configuration and if so, wether
891 # all those parameters are still the same.. or something has actually changed
892 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
893 echo 'Configuration is up-to-date'
894 exit 0
895 elif [ -f ${lst} ]; then
896 echo 'Configuration has been updated..'
897 ( eval "${MAKE} -f ./mk.mk clean" )
898 echo
899 else
900 echo 'Shiny configuration..'
903 # Time to redefine helper 1
904 config_exit() {
905 ${rm} -f ${lst} ${h} ${mk}
906 exit ${1}
909 ${mv} -f ${newlst} ${lst}
910 ${mv} -f ${newh} ${h}
911 ${mv} -f ${newmk} ${mk}
913 ## Compile and link checking
915 tmp3=./${tmp0}3$$
916 log=./config.log
917 lib=./config.lib
918 inc=./config.inc
919 makefile=./config.mk
921 # (No function since some shells loose non-exported variables in traps)
922 trap "trap \"\" HUP INT TERM;\
923 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
924 trap "trap \"\" HUP INT TERM EXIT;\
925 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
927 # Time to redefine helper 2
928 msg() {
929 fmt=${1}
930 shift
931 printf "*** ${fmt}\\n" "${@}"
932 printf -- "${fmt}\\n" "${@}" >&5
934 msg_nonl() {
935 fmt=${1}
936 shift
937 printf "*** ${fmt}\\n" "${@}"
938 printf -- "${fmt}" "${@}" >&5
941 exec 5>&2 > ${log} 2>&1
943 echo "${LIBS}" > ${lib}
944 echo "${INCS}" > ${inc}
945 ${cat} > ${makefile} << \!
946 .SUFFIXES: .o .c .x .y
947 .c.o:
948 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
949 .c.x:
950 $(CC) -I./ $(XINCS) -E $< >$@
952 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
953 .y: ;
956 _check_preface() {
957 variable=$1 topic=$2 define=$3
959 echo '**********'
960 msg_nonl ' . %s ... ' "${topic}"
961 echo "/* checked ${topic} */" >> ${h}
962 ${rm} -f ${tmp} ${tmp}.o
963 echo '*** test program is'
964 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
965 #echo '*** the preprocessor generates'
966 #${make} -f ${makefile} ${tmp}.x
967 #${cat} ${tmp}.x
968 echo '*** results are'
971 compile_check() {
972 variable=$1 topic=$2 define=$3
974 _check_preface "${variable}" "${topic}" "${define}"
976 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
977 [ -f ./${tmp}.o ]; then
978 msg 'yes'
979 echo "${define}" >> ${h}
980 eval have_${variable}=yes
981 return 0
982 else
983 echo "/* ${define} */" >> ${h}
984 msg 'no'
985 eval unset have_${variable}
986 return 1
990 _link_mayrun() {
991 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
993 _check_preface "${variable}" "${topic}" "${define}"
995 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
996 XLIBS="${LIBS} ${libs}" ./${tmp} &&
997 [ -f ./${tmp} ] &&
998 { [ ${run} -eq 0 ] || ./${tmp}; }; then
999 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1000 msg 'yes'
1001 echo "${define}" >> ${h}
1002 LIBS="${LIBS} ${libs}"
1003 echo "${libs}" >> ${lib}
1004 INCS="${INCS} ${incs}"
1005 echo "${incs}" >> ${inc}
1006 eval have_${variable}=yes
1007 return 0
1008 else
1009 msg 'no'
1010 echo "/* ${define} */" >> ${h}
1011 eval unset have_${variable}
1012 return 1
1016 link_check() {
1017 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1020 run_check() {
1021 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1026 # May be multiline..
1027 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1029 if run_check inline '"inline" functions' \
1030 '#define HAVE_INLINE
1031 #define n_INLINE static inline' << \!
1032 static inline int ilf(int i){return ++i;}
1033 int main(void){return ilf(-1);}
1035 then
1037 elif run_check inline '"__inline" functions' \
1038 '#define HAVE_INLINE
1039 #define n_INLINE static __inline' << \!
1040 static __inline int ilf(int i){return ++i;}
1041 int main(void){return ilf(-1);}
1043 then
1047 if run_check endian 'Little endian byteorder' \
1048 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1049 int main(void){
1050 enum {vBig = 1, vLittle = 0};
1051 union {unsigned short bom; unsigned char buf[2];} u;
1052 u.bom = 0xFEFF;
1053 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1056 then
1062 if run_check clock_gettime 'clock_gettime(2)' \
1063 '#define HAVE_CLOCK_GETTIME' << \!
1064 #include <time.h>
1065 # include <errno.h>
1066 int main(void){
1067 struct timespec ts;
1069 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1070 return 0;
1071 return 1;
1074 then
1076 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1077 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1078 #include <time.h>
1079 # include <errno.h>
1080 int main(void){
1081 struct timespec ts;
1083 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1084 return 0;
1085 return 1;
1088 then
1090 elif run_check gettimeofday 'gettimeofday(2)' \
1091 '#define HAVE_GETTIMEOFDAY' << \!
1092 #include <stdio.h> /* For C89 NULL */
1093 #include <sys/time.h>
1094 # include <errno.h>
1095 int main(void){
1096 struct timeval tv;
1098 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1099 return 0;
1100 return 1;
1103 then
1105 else
1106 have_no_subsecond_time=1
1109 if run_check nanosleep 'nanosleep(2)' \
1110 '#define HAVE_NANOSLEEP' << \!
1111 #include <time.h>
1112 # include <errno.h>
1113 int main(void){
1114 struct timespec ts;
1116 ts.tv_sec = 1;
1117 ts.tv_nsec = 100000;
1118 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1119 return 0;
1120 return 1;
1123 then
1125 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1126 '#define HAVE_NANOSLEEP' '-lrt' << \!
1127 #include <time.h>
1128 # include <errno.h>
1129 int main(void){
1130 struct timespec ts;
1132 ts.tv_sec = 1;
1133 ts.tv_nsec = 100000;
1134 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1135 return 0;
1136 return 1;
1139 then
1141 # link_check is enough for this, that function is so old, trust the proto
1142 elif link_check sleep 'sleep(3)' \
1143 '#define HAVE_SLEEP' << \!
1144 #include <unistd.h>
1145 # include <errno.h>
1146 int main(void){
1147 if(!sleep(1) || errno != ENOSYS)
1148 return 0;
1149 return 1;
1152 then
1154 else
1155 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1156 config_exit 1
1159 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1160 #include <pwd.h>
1161 #include <unistd.h>
1162 # include <errno.h>
1163 int main(void){
1164 struct passwd *pw;
1165 gid_t gid;
1166 uid_t uid;
1168 if((gid = getgid()) != 0)
1169 gid = getegid();
1170 if((uid = getuid()) != 0)
1171 uid = geteuid();
1172 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1173 return 1;
1174 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1175 return 1;
1176 return 0;
1179 then
1181 else
1182 msg 'ERROR: we require user and group info / database searches.'
1183 msg 'That much Unix we indulge ourselfs.'
1184 config_exit 1
1187 if link_check snprintf 'v?snprintf(3)' << \!
1188 #include <stdarg.h>
1189 #include <stdio.h>
1190 static void dome(char *buf, ...){
1191 va_list ap;
1193 va_start(ap, buf);
1194 vsnprintf(buf, 20, "%s", ap);
1195 va_end(ap);
1196 return;
1198 int main(void){
1199 char b[20];
1201 snprintf(b, sizeof b, "%s", "string");
1202 dome(b, "string");
1203 return 0;
1206 then
1208 else
1209 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1210 config_exit 1
1213 if link_check environ 'environ(3)' << \!
1214 #include <stdio.h> /* For C89 NULL */
1215 int main(void){
1216 extern char **environ;
1218 return environ[0] == NULL;
1221 then
1223 else
1224 msg 'ERROR: we require the environ(3) array for subprocess control.'
1225 config_exit 1
1228 if link_check termios 'termios.h and tc*(3) family' << \!
1229 #include <termios.h>
1230 int main(void){
1231 struct termios tios;
1233 tcgetattr(0, &tios);
1234 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1235 return 0;
1238 then
1240 else
1241 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1242 msg 'That much Unix we indulge ourselfs.'
1243 config_exit 1
1248 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1249 #include <unistd.h>
1250 #include <errno.h>
1251 int main(void){
1252 int rv = 0;
1254 errno = 0;
1255 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1256 errno = 0;
1257 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1259 /* Only link check */
1260 fpathconf(0, _PC_NAME_MAX);
1262 return rv;
1266 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1267 #include <fcntl.h>
1268 #include <unistd.h>
1269 # include <errno.h>
1270 int main(void){
1271 int fds[2];
1273 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1274 return 0;
1275 return 1;
1279 # We use this only then for now (need NOW+1)
1280 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1281 #include <fcntl.h> /* For AT_* */
1282 #include <sys/stat.h>
1283 # include <errno.h>
1284 int main(void){
1285 struct timespec ts[2];
1287 ts[0].tv_nsec = UTIME_NOW;
1288 ts[1].tv_nsec = UTIME_OMIT;
1289 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1290 return 0;
1291 return 1;
1297 # XXX Add POSIX check once standardized
1298 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1299 #include <stdlib.h>
1300 int main(void){
1301 arc4random();
1302 return 0;
1305 then
1307 elif [ -n "${have_no_subsecond_time}" ]; then
1308 msg 'ERROR: %s %s' 'without a native random' \
1309 'one of clock_gettime(2) and gettimeofday(2) is required.'
1310 config_exit 1
1313 link_check setenv 'setenv(3)/unsetenv(3)' '#define HAVE_SETENV' << \!
1314 #include <stdlib.h>
1315 int main(void){
1316 setenv("s-nail", "to be made nifty!", 1);
1317 unsetenv("s-nail");
1318 return 0;
1322 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1323 #include <stdio.h>
1324 int main(void){
1325 putc_unlocked('@', stdout);
1326 return 0;
1330 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1331 #include <unistd.h>
1332 int main(void){
1333 fchdir(0);
1334 return 0;
1338 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1339 #include <locale.h>
1340 int main(void){
1341 setlocale(LC_ALL, "");
1342 return 0;
1346 if [ "${have_setlocale}" = yes ]; then
1347 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1348 '#define HAVE_C90AMEND1' << \!
1349 #include <limits.h>
1350 #include <stdlib.h>
1351 #include <wchar.h>
1352 #include <wctype.h>
1353 int main(void){
1354 char mbb[MB_LEN_MAX + 1];
1355 wchar_t wc;
1357 iswprint(L'c');
1358 towupper(L'c');
1359 mbtowc(&wc, "x", 1);
1360 mbrtowc(&wc, "x", 1, NULL);
1361 wctomb(mbb, wc);
1362 return (mblen("\0", 1) == 0);
1366 if [ "${have_c90amend1}" = yes ]; then
1367 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1368 #include <wchar.h>
1369 int main(void){
1370 wcwidth(L'c');
1371 return 0;
1376 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1377 #include <langinfo.h>
1378 #include <stdlib.h>
1379 int main(void){
1380 nl_langinfo(DAY_1);
1381 return (nl_langinfo(CODESET) == NULL);
1384 fi # have_setlocale
1386 run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1387 #include <stdlib.h>
1388 int main(void){
1389 #if 1 /* TODO for now we use realpath(3) without NULL as 2nd arg! */
1390 /* (And note that on Linux tcc(1) otherwise didn't detect once tested! */
1391 char x_buf[4096], *x = realpath(".", x_buf);
1393 return (x != NULL) ? 0 : 1;
1394 #else
1395 char *x = realpath(".", NULL), *y = realpath("/", NULL);
1397 return (x != NULL && y != NULL) ? 0 : 1;
1398 #endif
1402 link_check wordexp 'wordexp(3)' '#define HAVE_WORDEXP' << \!
1403 #include <stdio.h> /* For C89 NULL */
1404 #include <wordexp.h>
1405 int main(void){
1406 wordexp(NULL, NULL, 0);
1407 return 0;
1413 if feat_yes DEBUG; then
1414 echo '#define HAVE_DEBUG' >> ${h}
1417 if feat_yes AMALGAMATION; then
1418 echo '#define HAVE_AMALGAMATION' >> ${h}
1421 if feat_no NOALLOCA; then
1422 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1423 # versions of alloca(3) since modern compilers just can't be trusted
1424 # not to overoptimize and silently break some code
1425 run_check alloca '__builtin_alloca()' \
1426 '#define HAVE_ALLOCA __builtin_alloca' << \!
1427 #include <stdio.h> /* For C89 NULL */
1428 int main(void){
1429 void *vp = __builtin_alloca(1);
1431 return (vp != NULL);
1436 if feat_yes DEVEL; then
1437 echo '#define HAVE_DEVEL' >> ${h}
1440 if feat_yes NYD2; then
1441 echo '#define HAVE_NYD2' >> ${h}
1446 if feat_yes DOTLOCK; then
1447 if run_check readlink 'readlink(2)' << \!
1448 #include <unistd.h>
1449 # include <errno.h>
1450 int main(void){
1451 char buf[128];
1453 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1454 return 0;
1455 return 1;
1458 then
1460 else
1461 feat_bail_required DOTLOCK
1465 if feat_yes DOTLOCK; then
1466 if run_check fchown 'fchown(2)' << \!
1467 #include <unistd.h>
1468 # include <errno.h>
1469 int main(void){
1470 if(!fchown(0, 0, 0) || errno != ENOSYS)
1471 return 0;
1472 return 1;
1475 then
1477 else
1478 feat_bail_required DOTLOCK
1484 if feat_yes ICONV; then
1485 ${cat} > ${tmp2}.c << \!
1486 #include <stdio.h> /* For C89 NULL */
1487 #include <iconv.h>
1488 int main(void){
1489 iconv_t id;
1491 id = iconv_open("foo", "bar");
1492 iconv(id, NULL, NULL, NULL, NULL);
1493 iconv_close(id);
1494 return 0;
1497 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1498 '#define HAVE_ICONV' ||
1499 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1500 '#define HAVE_ICONV' '-liconv' ||
1501 feat_bail_required ICONV
1502 else
1503 echo '/* WANT_ICONV=0 */' >> ${h}
1504 fi # feat_yes ICONV
1506 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1507 ${cat} > ${tmp2}.c << \!
1508 #include <sys/types.h>
1509 #include <sys/socket.h>
1510 #include <sys/un.h>
1511 # include <errno.h>
1512 int main(void){
1513 struct sockaddr_un soun;
1515 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1516 return 1;
1517 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1518 return 1;
1519 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1520 return 1;
1521 return 0;
1525 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1526 '#define HAVE_UNIX_SOCKETS' ||
1527 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1528 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1529 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1530 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1533 if feat_yes SOCKETS; then
1534 ${cat} > ${tmp2}.c << \!
1535 #include "config.h"
1536 #include <sys/types.h>
1537 #include <sys/socket.h>
1538 #include <netinet/in.h>
1539 # include <errno.h>
1540 int main(void){
1541 struct sockaddr s;
1543 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1544 return 1;
1545 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1546 return 1;
1547 return 0;
1551 < ${tmp2}.c run_check sockets 'sockets' \
1552 '#define HAVE_SOCKETS' ||
1553 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1554 '#define HAVE_SOCKETS' '-lnsl' ||
1555 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1556 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1557 feat_bail_required SOCKETS
1558 else
1559 echo '/* WANT_SOCKETS=0 */' >> ${h}
1560 fi # feat_yes SOCKETS
1562 if feat_yes SOCKETS; then
1563 link_check getaddrinfo 'getaddrinfo(3)' \
1564 '#define HAVE_GETADDRINFO' << \!
1565 #include "config.h"
1566 #include <sys/types.h>
1567 #include <sys/socket.h>
1568 #include <stdio.h>
1569 #include <netdb.h>
1570 int main(void){
1571 struct addrinfo a, *ap;
1572 int lrv;
1574 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1575 case EAI_NONAME:
1576 case EAI_SERVICE:
1577 default:
1578 fprintf(stderr, "%s\n", gai_strerror(lrv));
1579 case 0:
1580 break;
1582 return 0;
1587 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1588 compile_check arpa_inet_h '<arpa/inet.h>' \
1589 '#define HAVE_ARPA_INET_H' << \!
1590 #include "config.h"
1591 #include <sys/types.h>
1592 #include <sys/socket.h>
1593 #include <netdb.h>
1594 #include <netinet/in.h>
1595 #include <arpa/inet.h>
1598 ${cat} > ${tmp2}.c << \!
1599 #include "config.h"
1600 #include <sys/types.h>
1601 #include <sys/socket.h>
1602 #include <stdio.h>
1603 #include <string.h>
1604 #include <netdb.h>
1605 #include <netinet/in.h>
1606 #ifdef HAVE_ARPA_INET_H
1607 #include <arpa/inet.h>
1608 #endif
1609 int main(void){
1610 struct sockaddr_in servaddr;
1611 unsigned short portno;
1612 struct servent *ep;
1613 struct hostent *hp;
1614 struct in_addr **pptr;
1616 portno = 0;
1617 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1618 portno = (unsigned short)ep->s_port;
1620 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1621 pptr = (struct in_addr**)hp->h_addr_list;
1622 if(hp->h_addrtype != AF_INET)
1623 fprintf(stderr, "au\n");
1624 }else{
1625 switch(h_errno){
1626 case HOST_NOT_FOUND:
1627 case TRY_AGAIN:
1628 case NO_RECOVERY:
1629 case NO_DATA:
1630 break;
1631 default:
1632 fprintf(stderr, "au\n");
1633 break;
1637 memset(&servaddr, 0, sizeof servaddr);
1638 servaddr.sin_family = AF_INET;
1639 servaddr.sin_port = htons(portno);
1640 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1641 fprintf(stderr, "Would connect to %s:%d ...\n",
1642 inet_ntoa(**pptr), (int)portno);
1643 return 0;
1647 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1648 < ${tmp2}.c link_check gethostbyname \
1649 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1650 < ${tmp2}.c link_check gethostbyname \
1651 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1652 '' '-lsocket -lnsl' ||
1653 feat_bail_required SOCKETS
1656 feat_yes SOCKETS &&
1657 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1658 #include <sys/socket.h>
1659 #include <stdlib.h>
1660 # include <errno.h>
1661 int main(void){
1662 int sockfd = 3;
1664 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1665 errno == ENOSYS)
1666 return 1;
1667 return 0;
1671 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1672 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1673 #include <sys/socket.h>
1674 #include <stdlib.h>
1675 int main(void){
1676 struct timeval tv;
1677 int sockfd = 3;
1679 tv.tv_sec = 42;
1680 tv.tv_usec = 21;
1681 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1682 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1683 return 0;
1687 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1688 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1689 #include <sys/socket.h>
1690 #include <stdlib.h>
1691 int main(void){
1692 struct linger li;
1693 int sockfd = 3;
1695 li.l_onoff = 1;
1696 li.l_linger = 42;
1697 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1698 return 0;
1702 if feat_yes SSL; then
1703 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1704 '#define HAVE_SSL
1705 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1706 #include <openssl/ssl.h>
1707 #include <openssl/err.h>
1708 #include <openssl/x509v3.h>
1709 #include <openssl/x509.h>
1710 #include <openssl/rand.h>
1711 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1712 # error We need TLSv1.
1713 #endif
1714 int main(void){
1715 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1717 SSL_CTX_free(ctx);
1718 PEM_read_PrivateKey(0, 0, 0, 0);
1719 return 0;
1722 then
1724 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1725 '#define HAVE_SSL
1726 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1727 #include <openssl/ssl.h>
1728 #include <openssl/err.h>
1729 #include <openssl/x509v3.h>
1730 #include <openssl/x509.h>
1731 #include <openssl/rand.h>
1732 #if defined OPENSSL_NO_SSL3 &&\
1733 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1734 # error We need one of SSLv3 and TLSv1.
1735 #endif
1736 int main(void){
1737 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1739 SSL_CTX_free(ctx);
1740 PEM_read_PrivateKey(0, 0, 0, 0);
1741 return 0;
1744 then
1746 else
1747 feat_bail_required SSL
1750 if [ "${have_openssl}" = 'yes' ]; then
1751 compile_check stack_of 'OpenSSL STACK_OF()' \
1752 '#define HAVE_OPENSSL_STACK_OF' << \!
1753 #include <stdio.h> /* For C89 NULL */
1754 #include <openssl/ssl.h>
1755 #include <openssl/err.h>
1756 #include <openssl/x509v3.h>
1757 #include <openssl/x509.h>
1758 #include <openssl/rand.h>
1759 int main(void){
1760 STACK_OF(GENERAL_NAME) *gens = NULL;
1762 printf("%p", gens); /* to use it */
1763 return 0;
1767 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1768 '#define HAVE_OPENSSL_CONFIG' << \!
1769 #include <stdio.h> /* For C89 NULL */
1770 #include <openssl/conf.h>
1771 int main(void){
1772 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1773 CONF_modules_free();
1774 return 0;
1778 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1779 '#define HAVE_OPENSSL_CONF_CTX' << \!
1780 #include "config.h"
1781 #include <openssl/ssl.h>
1782 #include <openssl/err.h>
1783 int main(void){
1784 #if HAVE_OPENSSL < 10100
1785 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1786 #else
1787 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1788 #endif
1789 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1791 SSL_CONF_CTX_set_flags(cctx,
1792 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1793 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1794 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1795 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1796 SSL_CONF_CTX_finish(cctx);
1797 SSL_CONF_CTX_free(cctx);
1798 SSL_CTX_free(ctx);
1799 return 0;
1803 link_check rand_egd 'OpenSSL RAND_egd()' \
1804 '#define HAVE_OPENSSL_RAND_EGD' << \!
1805 #include <openssl/rand.h>
1806 int main(void){
1807 return RAND_egd("some.where") > 0;
1811 if feat_yes SSL_ALL_ALGORITHMS; then
1812 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1813 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1814 #include <openssl/evp.h>
1815 int main(void){
1816 OpenSSL_add_all_algorithms();
1817 EVP_get_cipherbyname("two cents i never exist");
1818 EVP_cleanup();
1819 return 0;
1822 then
1824 else
1825 feat_bail_required SSL_ALL_ALGORITHMS
1827 fi # SSL_ALL_ALGORITHMS
1829 if feat_yes MD5 && feat_no NOEXTMD5; then
1830 run_check openssl_md5 'MD5 digest in OpenSSL' \
1831 '#define HAVE_OPENSSL_MD5' << \!
1832 #include <stdlib.h>
1833 #include <string.h>
1834 #include <openssl/md5.h>
1835 int main(void){
1836 char const dat[] = "abrakadabrafidibus";
1837 char dig[16], hex[16 * 2];
1838 MD5_CTX ctx;
1839 size_t i, j;
1841 memset(dig, 0, sizeof(dig));
1842 memset(hex, 0, sizeof(hex));
1843 MD5_Init(&ctx);
1844 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1845 MD5_Final(dig, &ctx);
1847 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1848 for(i = 0; i < sizeof(hex) / 2; i++){
1849 j = i << 1;
1850 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1851 hex[++j] = hexchar(dig[i] & 0x0f);
1853 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1856 fi # feat_yes MD5 && feat_no NOEXTMD5
1858 else
1859 echo '/* WANT_SSL=0 */' >> ${h}
1860 fi # feat_yes SSL
1862 if feat_yes SMTP; then
1863 echo '#define HAVE_SMTP' >> ${h}
1864 else
1865 echo '/* WANT_SMTP=0 */' >> ${h}
1868 if feat_yes POP3; then
1869 echo '#define HAVE_POP3' >> ${h}
1870 else
1871 echo '/* WANT_POP3=0 */' >> ${h}
1874 if feat_yes GSSAPI; then
1875 ${cat} > ${tmp2}.c << \!
1876 #include <gssapi/gssapi.h>
1877 int main(void){
1878 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1879 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1880 return 0;
1883 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1885 if command -v krb5-config >/dev/null 2>&1; then
1886 i=`command -v krb5-config`
1887 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1888 GSS_INCS="`CFLAGS= ${i} --cflags`"
1889 i='GSS-API via krb5-config(1)'
1890 else
1891 GSS_LIBS='-lgssapi'
1892 GSS_INCS=
1893 i='GSS-API in gssapi/gssapi.h, libgssapi'
1895 if < ${tmp2}.c link_check gss \
1896 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1897 < ${tmp3}.c link_check gss \
1898 'GSS-API in gssapi.h, libgssapi' \
1899 '#define HAVE_GSSAPI
1900 #define GSSAPI_REG_INCLUDE' \
1901 '-lgssapi' ||\
1902 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1903 '#define HAVE_GSSAPI' \
1904 '-lgssapi_krb5' ||\
1905 < ${tmp3}.c link_check gss \
1906 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1907 '#define HAVE_GSSAPI
1908 #define GSS_REG_INCLUDE' \
1909 '-lgssapi -lkrb5 -lcrypto' \
1910 '-I/usr/include/kerberosV' ||\
1911 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1912 '#define HAVE_GSSAPI' \
1913 '-lgss' ||\
1914 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1915 '#define HAVE_GSSAPI
1916 #define GSSAPI_OLD_STYLE' \
1917 '-lgssapi_krb5' << \!
1918 #include <gssapi/gssapi.h>
1919 #include <gssapi/gssapi_generic.h>
1920 int main(void){
1921 gss_import_name(0, 0, gss_nt_service_name, 0);
1922 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1923 return 0;
1926 then
1928 else
1929 feat_bail_required GSSAPI
1931 else
1932 echo '/* WANT_GSSAPI=0 */' >> ${h}
1933 fi # feat_yes GSSAPI
1935 if feat_yes NETRC; then
1936 echo '#define HAVE_NETRC' >> ${h}
1937 else
1938 echo '/* WANT_NETRC=0 */' >> ${h}
1941 if feat_yes AGENT; then
1942 echo '#define HAVE_AGENT' >> ${h}
1943 else
1944 echo '/* WANT_AGENT=0 */' >> ${h}
1947 if feat_yes IDNA; then
1948 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
1949 '-lidn' << \!
1950 #include <idna.h>
1951 #include <idn-free.h>
1952 #include <stringprep.h>
1953 int main(void){
1954 char *utf8, *idna_ascii, *idna_utf8;
1956 utf8 = stringprep_locale_to_utf8("does.this.work");
1957 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
1958 != IDNA_SUCCESS)
1959 return 1;
1960 idn_free(idna_ascii);
1961 /* (Rather link check only here) */
1962 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
1963 return 0;
1966 then
1968 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
1969 '-lidnkit' << \!
1970 #include <stdio.h>
1971 #include <idn/api.h>
1972 #include <idn/result.h>
1973 int main(void){
1974 idn_result_t r;
1975 char ace_name[256];
1976 char local_name[256];
1978 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
1979 sizeof(ace_name));
1980 if (r != idn_success) {
1981 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
1982 return 1;
1984 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
1985 if (r != idn_success) {
1986 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
1987 return 1;
1989 return 0;
1992 then
1994 else
1995 feat_bail_required IDNA
1998 if [ -n "${have_idna}" ]; then
1999 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2000 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2002 else
2003 echo '/* WANT_IDNA=0 */' >> ${h}
2006 if feat_yes IMAP_SEARCH; then
2007 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2008 else
2009 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
2012 if feat_yes REGEX; then
2013 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2014 #include <regex.h>
2015 #include <stdlib.h>
2016 int main(void){
2017 int status;
2018 regex_t re;
2020 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2021 return 1;
2022 status = regexec(&re, "plan9", 0,NULL, 0);
2023 regfree(&re);
2024 return !(status == REG_NOMATCH);
2027 then
2029 else
2030 feat_bail_required REGEX
2032 else
2033 echo '/* WANT_REGEX=0 */' >> ${h}
2036 if feat_yes READLINE; then
2037 __edrdlib() {
2038 link_check readline "for readline(3) (${1})" \
2039 '#define HAVE_READLINE' "${1}" << \!
2040 #include <stdio.h>
2041 #include <readline/history.h>
2042 #include <readline/readline.h>
2043 int main(void){
2044 char *rl;
2045 HISTORY_STATE *hs;
2046 HIST_ENTRY **he;
2047 int i;
2049 using_history();
2050 read_history("");
2051 stifle_history(242);
2052 rl = readline("Enter a line:");
2053 if (rl && *rl)
2054 add_history(rl);
2055 write_history("");
2056 rl_extend_line_buffer(10);
2057 rl_point = rl_end = 10;
2058 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2059 rl_forced_update_display();
2060 clear_history();
2061 hs = history_get_history_state();
2062 i = hs->length;
2063 he = history_list();
2064 if (i > 0)
2065 rl = he[0]->line;
2066 rl_free_line_state();
2067 rl_cleanup_after_signal();
2068 rl_reset_after_signal();
2069 return 0;
2074 __edrdlib -lreadline ||
2075 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2078 if feat_yes MLE && [ -z "${have_readline}" ] &&
2079 [ -n "${have_c90amend1}" ]; then
2080 have_mle=1
2081 echo '#define HAVE_MLE' >> ${h}
2082 else
2083 feat_bail_required MLE
2084 echo '/* WANT_{READLINE,MLE}=0 */' >> ${h}
2087 # Generic have-a-line-editor switch for those who need it below
2088 if [ -n "${have_mle}" ] ||
2089 [ -n "${have_readline}" ]; then
2090 have_cle=1
2093 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2094 echo '#define HAVE_HISTORY' >> ${h}
2095 else
2096 echo '/* WANT_HISTORY=0 */' >> ${h}
2099 if feat_yes TERMCAP; then
2100 __termlib() {
2101 link_check termcap "for termcap(3) (via ${4})" \
2102 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2103 #include <stdio.h>
2104 #include <stdlib.h>
2105 #include <string.h>
2106 ${2}
2107 #include <term.h>
2108 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2109 static int my_putc(int c){return putchar(c);}
2110 int main(void){
2111 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2112 int r2 = OK, r3 = ERR;
2114 tgetent(buf, getenv("TERM"));
2115 cpb = cmdbuf;
2116 r1 = tgetstr(UNCONST("cm"), &cpb);
2117 tgoto(r1, 1, 1);
2118 r2 = tgetnum(UNCONST("Co"));
2119 r3 = tgetflag(UNCONST("ut"));
2120 tputs("cr", 1, &my_putc);
2121 return (r1 == NULL || r2 == -1 || r3 == 0);
2123 _EOT
2126 __termlib -ltermcap '' '' termcap ||
2127 __termlib -ltermcap '#include <curses.h>' '
2128 #define HAVE_TERMCAP_CURSES' \
2129 'curses.h / -ltermcap' ||
2130 __termlib -lcurses '#include <curses.h>' '
2131 #define HAVE_TERMCAP_CURSES' \
2132 'curses.h / -lcurses' ||
2133 feat_bail_required TERMCAP
2134 else
2135 echo '/* WANT_TERMCAP=0 */' >> ${h}
2138 if feat_yes ERRORS; then
2139 echo '#define HAVE_ERRORS' >> ${h}
2140 else
2141 echo '/* WANT_ERRORS=0 */' >> ${h}
2146 if feat_yes SPAM_SPAMC; then
2147 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2148 if command -v spamc >/dev/null 2>&1; then
2149 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2151 else
2152 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2155 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2156 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2157 else
2158 feat_bail_required SPAM_SPAMD
2159 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2162 if feat_yes SPAM_FILTER; then
2163 echo '#define HAVE_SPAM_FILTER' >> ${h}
2164 else
2165 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
2168 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2169 echo '#define HAVE_SPAM' >> ${h}
2170 else
2171 echo '/* HAVE_SPAM */' >> ${h}
2174 if feat_yes DOCSTRINGS; then
2175 echo '#define HAVE_DOCSTRINGS' >> ${h}
2176 else
2177 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
2180 if feat_yes QUOTE_FOLD &&\
2181 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2182 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2183 else
2184 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2187 if feat_yes FILTER_HTML_TAGSOUP; then
2188 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2189 else
2190 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2193 if feat_yes COLOUR; then
2194 echo '#define HAVE_COLOUR' >> ${h}
2195 else
2196 echo '/* WANT_COLOUR=0 */' >> ${h}
2199 if feat_yes DOTLOCK; then
2200 echo '#define HAVE_DOTLOCK' >> ${h}
2201 else
2202 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2205 if feat_yes MD5; then
2206 echo '#define HAVE_MD5' >> ${h}
2207 else
2208 echo '/* WANT_MD5=0 */' >> ${h}
2211 ## Summarizing
2213 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2214 squeeze_em() {
2215 < "${1}" > "${2}" ${awk} \
2216 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2218 ${rm} -f ${tmp}
2219 squeeze_em ${inc} ${tmp}
2220 ${mv} ${tmp} ${inc}
2221 squeeze_em ${lib} ${tmp}
2222 ${mv} ${tmp} ${lib}
2224 # config.h
2225 ${mv} ${h} ${tmp}
2226 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2227 ${cat} ${tmp} >> ${h}
2228 ${rm} -f ${tmp}
2230 printf '\n/* The "feature string" */\n' >> ${h}
2231 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2232 printf 'static char const _features[] = "MIME"\n' >> ${h}
2233 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2234 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2235 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2236 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2237 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2238 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2239 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2240 >> ${h}
2241 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2242 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2243 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2244 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2245 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2246 printf '# ifdef HAVE_AGENT\n ",AGENT"\n# endif\n' >> ${h}
2247 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2248 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2249 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2250 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2251 printf '# ifdef HAVE_MLE\n ",MLE"\n# endif\n' >> ${h}
2252 printf '# ifdef HAVE_WCWIDTH\n " (WIDE GLYPHS)"\n# endif\n' >> ${h}
2253 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2254 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2255 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2256 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2257 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2258 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2259 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2260 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2261 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2262 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2263 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2264 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2265 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2267 # Create the real mk.mk
2268 # Note we cannout use explicit ./ filename prefix for source and object
2269 # pathnames because of a bug in bmake(1)
2270 ${rm} -rf ${tmp0}.* ${tmp0}*
2271 printf 'OBJ_SRC = ' >> ${mk}
2272 if feat_no AMALGAMATION; then
2273 for i in `printf '%s\n' *.c | ${sort}`; do
2274 if [ "${i}" = privsep.c ]; then
2275 continue
2277 printf "${i} " >> ${mk}
2278 done
2279 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2280 else
2281 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2283 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2284 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2285 printf '# undef _CONFIG_H\n' >> ${h}
2286 printf '# define _CONFIG_H 2\n' >> ${h}
2287 for i in `printf '%s\n' *.c | ${sort}`; do
2288 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2289 [ "${i}" = privsep.c ]; then
2290 continue
2292 printf "${i} " >> ${mk}
2293 printf "# include \"${i}\"\n" >> ${h}
2294 done
2295 echo >> ${mk}
2296 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2297 echo '#else' >> ${h}
2300 printf '#endif /* n_CONFIG_H */\n' >> ${h}
2302 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2303 echo "INCS = `${cat} ${inc}`" >> ${mk}
2304 echo >> ${mk}
2305 ${cat} ./mk-mk.in >> ${mk}
2307 ## Finished!
2309 ${cat} > ${tmp2}.c << \!
2310 #include "config.h"
2312 :The following optional features are enabled:
2313 #ifdef HAVE_SETLOCALE
2314 : + Locale support: Printable characters depend on the environment
2315 # ifdef HAVE_C90AMEND1
2316 : + Multibyte character support
2317 # endif
2318 # ifdef HAVE_NL_LANGINFO
2319 : + Automatic detection of terminal character set
2320 # endif
2321 #endif
2322 #ifdef HAVE_ICONV
2323 : + Character set conversion using iconv()
2324 #endif
2325 #ifdef HAVE_SOCKETS
2326 : + Network support
2327 #endif
2328 #ifdef HAVE_SSL
2329 # ifdef HAVE_OPENSSL
2330 : + S/MIME and SSL/TLS (OpenSSL)
2331 # endif
2332 # ifdef HAVE_SSL_ALL_ALGORITHMS
2333 : + + Support for more ("all") digest and cipher algorithms
2334 # endif
2335 #endif
2336 #ifdef HAVE_SMTP
2337 : + SMTP protocol
2338 #endif
2339 #ifdef HAVE_POP3
2340 : + POP3 protocol
2341 #endif
2342 #ifdef HAVE_GSSAPI
2343 : + GSS-API authentication
2344 #endif
2345 #ifdef HAVE_MD5
2346 : + MD5 message digest (APOP, CRAM-MD5)
2347 #endif
2348 #ifdef HAVE_NETRC
2349 : + .netrc file support
2350 #endif
2351 #ifdef HAVE_AGENT
2352 : + Password query through agent
2353 #endif
2354 #ifdef HAVE_IDNA
2355 : + IDNA (internationalized domain names for applications) support
2356 #endif
2357 #ifdef HAVE_IMAP_SEARCH
2358 : + IMAP-style search expressions
2359 #endif
2360 #ifdef HAVE_REGEX
2361 : + Regular expression support (searches, conditional expressions etc.)
2362 #endif
2363 #if defined HAVE_READLINE || defined HAVE_MLE
2364 # ifdef HAVE_READLINE
2365 : + Command line editing via readline(3)
2366 # else
2367 # ifdef HAVE_WCWIDTH
2368 : + Command line editing via M(ailx)-L(ine)-E(ditor) (wide glyph support)
2369 # else
2370 : + Command line editing via M(ailx)-L(ine)-E(ditor) (no wide glyph support)
2371 # endif
2372 # endif
2373 # ifdef HAVE_HISTORY
2374 : + + History management
2375 # endif
2376 #endif
2377 #ifdef HAVE_TERMCAP
2378 : + Terminal capability queries
2379 #endif
2380 #ifdef HAVE_SPAM
2381 : + Spam management
2382 # ifdef HAVE_SPAM_SPAMC
2383 : + + Via spamc(1) (of spamassassin(1))
2384 # endif
2385 # ifdef HAVE_SPAM_SPAMD
2386 : + + Directly via spamd(1) (of spamassassin(1))
2387 # endif
2388 # ifdef HAVE_SPAM_FILTER
2389 : + + Via freely configurable *spam-filter-XY*s
2390 # endif
2391 #endif
2392 #ifdef HAVE_DOCSTRINGS
2393 : + Documentation summary strings
2394 #endif
2395 #ifdef HAVE_QUOTE_FOLD
2396 : + Extended *quote-fold*ing
2397 #endif
2398 #ifdef HAVE_FILTER_HTML_TAGSOUP
2399 : + Builtin HTML-to-text filter (for display purposes, primitive)
2400 #endif
2401 #ifdef HAVE_COLOUR
2402 : + Coloured message display (simple)
2403 #endif
2404 #ifdef HAVE_DOTLOCK
2405 : + Dotlock files and privilege-separated file dotlock program
2406 #endif
2408 :The following optional features are disabled:
2409 #ifndef HAVE_SETLOCALE
2410 : - Locale support: Only ASCII characters are recognized
2411 #endif
2412 # ifndef HAVE_C90AMEND1
2413 : - Multibyte character support
2414 # endif
2415 # ifndef HAVE_NL_LANGINFO
2416 : - Automatic detection of terminal character set
2417 # endif
2418 #ifndef HAVE_ICONV
2419 : - Character set conversion using iconv()
2420 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2421 #endif
2422 #ifndef HAVE_SOCKETS
2423 : - Network support
2424 #endif
2425 #ifndef HAVE_SSL
2426 : - S/MIME and SSL/TLS
2427 #else
2428 # ifndef HAVE_SSL_ALL_ALGORITHMS
2429 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2430 # endif
2431 #endif
2432 #ifndef HAVE_SMTP
2433 : - SMTP protocol
2434 #endif
2435 #ifndef HAVE_POP3
2436 : - POP3 protocol
2437 #endif
2438 #ifndef HAVE_GSSAPI
2439 : - GSS-API authentication
2440 #endif
2441 #ifndef HAVE_MD5
2442 : - MD5 message digest (APOP, CRAM-MD5)
2443 #endif
2444 #ifndef HAVE_NETRC
2445 : - .netrc file support
2446 #endif
2447 #ifndef HAVE_AGENT
2448 : - Password query through agent
2449 #endif
2450 #ifndef HAVE_IDNA
2451 : - IDNA (internationalized domain names for applications) support
2452 #endif
2453 #ifndef HAVE_IMAP_SEARCH
2454 : - IMAP-style search expressions
2455 #endif
2456 #ifndef HAVE_REGEX
2457 : - Regular expression support
2458 #endif
2459 #if !defined HAVE_READLINE && !defined HAVE_MLE
2460 : - Command line editing and history
2461 #endif
2462 #ifndef HAVE_TERMCAP
2463 : - Terminal capability queries
2464 #endif
2465 #ifndef HAVE_SPAM
2466 : - Spam management
2467 #endif
2468 #ifndef HAVE_DOCSTRINGS
2469 : - Documentation summary strings
2470 #endif
2471 #ifndef HAVE_QUOTE_FOLD
2472 : - Extended *quote-fold*ing
2473 #endif
2474 #ifndef HAVE_FILTER_HTML_TAGSOUP
2475 : - Builtin HTML-to-text filter (for display purposes, primitive)
2476 #endif
2477 #ifndef HAVE_COLOUR
2478 : - Coloured message display (simple)
2479 #endif
2480 #ifndef HAVE_DOTLOCK
2481 : - Dotlock files and privilege-separated file dotlock program
2482 #endif
2484 #if !defined HAVE_WORDEXP || !defined HAVE_FCHDIR ||\
2485 defined HAVE_DEBUG || defined HAVE_DEVEL
2486 :Remarks:
2487 # ifndef HAVE_WORDEXP
2488 : . WARNING: the function wordexp(3) could not be found.
2489 : _ This means that echo(1) will be used via the sh(1)ell in order
2490 : _ to expand shell meta characters in filenames, which is a potential
2491 : _ security hole. Consider to either upgrade your system or set the
2492 : _ *SHELL* variable to some safe(r) wrapper script.
2493 : _ P.S.: the codebase is in transition away from wordexp(3) to some
2494 : _ safe (restricted) internal mechanism, see "COMMANDS" manual, read
2495 : _ about shell word expression in its introduction for more on that.
2496 # endif
2497 # ifndef HAVE_FCHDIR
2498 : . The function fchdir(2) could not be found. We will use chdir(2)
2499 : _ instead. This is not a problem unless the current working
2500 : _ directory is changed while this program is inside of it.
2501 # endif
2502 # ifdef HAVE_DEBUG
2503 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2504 # endif
2505 # ifdef HAVE_DEVEL
2506 : . Computers do not blunder.
2507 # endif
2509 #endif /* Remarks */
2510 :Setup:
2511 : . System-wide resource file: SYSCONFDIR/SYSCONFRC
2512 : . bindir: BINDIR
2513 #ifdef HAVE_DOTLOCK
2514 : . libexecdir: LIBEXECDIR
2515 #endif
2516 : . mandir: MANDIR
2517 : . sendmail(1): SENDMAIL (argv[0] = SENDMAIL_PROGNAME)
2518 : . Mail spool directory: MAILSPOOL
2522 ${make} -f ${makefile} ${tmp2}.x
2523 < ${tmp2}.x ${sed} -e '/^[^:]/d; /^$/d; s/^://' |
2524 while read l; do
2525 msg "${l}"
2526 done
2528 # s-it-mode