nail.1: drop `(un)?setenv' and *bsdset*; add `environ'
[s-mailx.git] / mk-conf.sh
blob9cb3c7591877e2b884161351581bbfa6f2cfa4cc
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_HISTORY=0 WANT_KEY_BINDINGS=0
19 WANT_TERMCAP=0 WANT_TERMCAP_PREFER_TERMINFO=0
20 WANT_ERRORS=0
21 WANT_SPAM_SPAMC=0 WANT_SPAM_SPAMD=0 WANT_SPAM_FILTER=0
22 WANT_DOCSTRINGS=0
23 WANT_QUOTE_FOLD=0
24 WANT_FILTER_HTML_TAGSOUP=0
25 WANT_COLOUR=0
26 WANT_DOTLOCK=0
29 option_maximal() {
30 WANT_ICONV=require
31 WANT_SOCKETS=1
32 WANT_SSL=1 WANT_ALL_SSL_ALGORITHMS=1
33 WANT_SMTP=1 WANT_POP3=1
34 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
35 #WANT_MD5=1
36 WANT_IDNA=1
37 WANT_IMAP_SEARCH=1
38 WANT_REGEX=require
39 WANT_MLE=1
40 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
41 WANT_TERMCAP=1 WANT_TERMCAP_PREFER_TERMINFO=1
42 WANT_ERRORS=1
43 WANT_SPAM_SPAMC=1 WANT_SPAM_SPAMD=1 WANT_SPAM_FILTER=1
44 WANT_DOCSTRINGS=1
45 WANT_QUOTE_FOLD=1
46 WANT_FILTER_HTML_TAGSOUP=1
47 WANT_COLOUR=1
48 WANT_DOTLOCK=require
51 # Predefined CONFIG= urations take precedence over anything else
52 if [ -n "${CONFIG}" ]; then
53 case "${CONFIG}" in
54 [nN][uU][lL][lL])
55 option_reset
57 [nN][uU][lL][lL][iI])
58 option_reset
59 WANT_ICONV=require
61 [mM][iI][nN][iI][mM][aA][lL])
62 option_reset
63 WANT_ICONV=1
64 WANT_REGEX=1
65 WANT_DOTLOCK=require
67 [mM][eE][dD][iI][uU][mM])
68 option_reset
69 WANT_ICONV=require
70 WANT_IDNA=1
71 WANT_REGEX=1
72 WANT_MLE=1
73 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
74 WANT_ERRORS=1
75 WANT_SPAM_FILTER=1
76 WANT_DOCSTRINGS=1
77 WANT_COLOUR=1
78 WANT_DOTLOCK=require
80 [nN][eE][tT][sS][eE][nN][dD])
81 option_reset
82 WANT_ICONV=require
83 WANT_SOCKETS=1
84 WANT_SSL=require
85 WANT_SMTP=require
86 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
87 WANT_IDNA=1
88 WANT_REGEX=1
89 WANT_MLE=1
90 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
91 WANT_DOCSTRINGS=1
92 WANT_COLOUR=1
93 WANT_DOTLOCK=require
95 [mM][aA][xX][iI][mM][aA][lL])
96 option_reset
97 option_maximal
99 [dD][eE][vV][eE][lL])
100 WANT_DEVEL=1 WANT_DEBUG=1 WANT_NYD2=1
101 option_maximal
103 [oO][dD][eE][vV][eE][lL])
104 WANT_DEVEL=1
105 option_maximal
108 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
109 echo >&2 'Possible values: NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
110 exit 1
112 esac
115 # Inter-relationships
116 option_update() {
117 if feat_no SMTP && feat_no POP3; then
118 WANT_SOCKETS=0
120 if feat_no SOCKETS; then
121 if feat_require SMTP; then
122 msg 'ERROR: need SOCKETS for required feature SMTP'
123 config_exit 13
125 if feat_require POP3; then
126 msg 'ERROR: need SOCKETS for required feature POP3'
127 config_exit 13
129 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
130 WANT_SMTP=0 WANT_POP3=0
131 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
133 if feat_no SMTP; then
134 WANT_GSSAPI=0
137 if feat_no READLINE && feat_no MLE; then
138 WANT_HISTORY=0 WANT_KEY_BINDINGS=0
141 # If we don't need MD5 leave it alone
142 if feat_no SOCKETS; then
143 WANT_MD5=0
146 if feat_yes DEVEL; then
147 WANT_DEBUG=1
149 if feat_yes DEBUG; then
150 WANT_NOALLOCA=1 WANT_DEVEL=1
154 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
155 # via path_check() later on once possible
157 # TODO cc_maxopt is brute simple, we should compile test program and dig real
158 # compiler versions for known compilers, then be more specific
159 cc_maxopt=100
160 _CFLAGS= _LDFLAGS=
162 os_early_setup() {
163 i="${OS:-`uname -s`}"
165 if [ ${i} = SunOS ]; then
166 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
167 _os_early_setup_sunos
171 os_setup() {
172 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
173 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
174 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
175 msg 'Operating system is "%s"' ${OS}
177 if [ ${OS} = sunos ]; then
178 msg ' . have special SunOS / Solaris "setup" rules ...'
179 _os_setup_sunos
180 elif [ ${OS} = unixware ]; then
181 msg ' . have special UnixWare environmental rules ...'
182 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
183 CC=cc
184 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
186 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
187 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
188 export CC CFLAGS LDFLAGS
189 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
191 elif [ -n "${VERBOSE}" ]; then
192 msg ' . no special treatment for this system necessary or known'
195 # Sledgehammer: better set _GNU_SOURCE
196 # And in general: oh, boy!
197 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
198 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
199 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
200 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
202 # On pkgsrc(7) systems automatically add /usr/pkg/*
203 if [ -d /usr/pkg ]; then
204 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
205 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
209 _os_early_setup_sunos() {
210 # According to standards(5), this is what we need to do
211 if [ -d /usr/xpg4 ]; then :; else
212 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
213 config_exit 1
215 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
216 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
217 export PATH
220 _os_setup_sunos() {
221 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
222 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
224 # Include packages
225 if [ -d /opt/csw ]; then
226 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
227 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
230 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
231 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
233 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
234 if [ -x "${cksum}" ]; then :; else
235 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
236 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
237 msg 'ERROR: However, we do so only for tests.'
238 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
239 config_exit 1
242 if feat_yes AUTOCC; then
243 if command -v cc >/dev/null 2>&1; then
244 CC=cc
245 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
247 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
248 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
249 export CC CFLAGS LDFLAGS
250 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
251 else
252 # Assume gcc(1)
253 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
258 # Check out compiler ($CC) and -flags ($CFLAGS)
259 cc_setup() {
260 # Even though it belongs into cc_flags we will try to compile and link
261 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
262 # ADDCFLAGS/ADDLDFLAGS
263 if feat_no AUTOCC; then
264 _cc_default
265 # Ensure those don't do any harm
266 ADDCFLAGS= ADDLDFLAGS=
267 export ADDCFLAGS ADDLDFLAGS
268 return
269 else
270 CFLAGS= LDFLAGS=
271 export CFLAGS LDFLAGS
274 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
276 printf >&2 'Searching for a usable C compiler .. $CC='
277 if { i="`command -v clang`"; }; then
278 CC=${i}
279 elif { i="`command -v gcc`"; }; then
280 CC=${i}
281 elif { i="`command -v c99`"; }; then
282 CC=${i}
283 elif { i="`command -v tcc`"; }; then
284 CC=${i}
285 elif { i="`command -v pcc`"; }; then
286 CC=${i}
287 else
288 if [ "${CC}" = cc ]; then
290 elif { i="`command -v c89`"; }; then
291 CC=${i}
292 else
293 printf >&2 'boing booom tschak\n'
294 msg 'ERROR: I cannot find a compiler!'
295 msg ' Neither of clang(1), gcc(1), tcc(1), c89(1) and c99(1).'
296 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
297 config_exit 1
300 printf >&2 -- '"%s"\n' "${CC}"
301 export CC
304 _cc_default() {
305 if [ -z "${CC}" ]; then
306 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
307 config_exit 1
310 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
312 else
313 msg 'Using C compiler $CC="%s"' "${CC}"
317 cc_flags() {
318 if feat_yes AUTOCC; then
319 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
320 cc_check_silent=1
321 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
322 else
323 cc_check_silent=
324 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
327 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
328 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
329 msg ' . have special tcc(1) environmental rules ...'
330 _cc_flags_tcc
331 else
332 # As of pcc CVS 2016-04-02, stack protection support is announced but
333 # will break if used on Linux
334 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
335 force_no_stackprot=1
337 _cc_flags_generic
340 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
341 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
342 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
343 else
344 if feat_no DEBUG; then
345 CFLAGS="-DNDEBUG ${CFLAGS}"
348 msg ''
349 export CFLAGS LDFLAGS
352 _cc_flags_tcc() {
353 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
354 _CFLAGS= _LDFLAGS=
356 cc_check -Wall
357 cc_check -Wextra
358 cc_check -pedantic
360 if feat_yes DEBUG; then
361 # May have problems to find libtcc cc_check -b
362 cc_check -g
365 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
366 unset __cflags __ldflags
369 _cc_flags_generic() {
370 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
371 _CFLAGS= _LDFLAGS=
372 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
374 # Check -g first since some others may rely upon -g / optim. level
375 if feat_yes DEBUG; then
376 cc_check -O
377 cc_check -g
378 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
380 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
382 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
384 else
385 cc_check -O
388 if feat_yes DEVEL && cc_check -Weverything; then
390 else
391 cc_check -Wall
392 cc_check -Wextra
393 cc_check -Wbad-function-cast
394 cc_check -Wcast-align
395 cc_check -Wcast-qual
396 cc_check -Winit-self
397 cc_check -Wmissing-prototypes
398 cc_check -Wshadow
399 cc_check -Wunused
400 cc_check -Wwrite-strings
401 cc_check -Wno-long-long
403 cc_check -pedantic
405 if feat_yes AMALGAMATION && feat_no DEVEL; then
406 cc_check -Wno-unused-function
408 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
410 cc_check -fno-unwind-tables
411 cc_check -fno-asynchronous-unwind-tables
412 cc_check -fstrict-aliasing
413 if cc_check -fstrict-overflow && feat_yes DEVEL; then
414 cc_check -Wstrict-overflow=5
417 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
418 if [ -z "${force_no_stackprot}" ]; then
419 if cc_check -fstack-protector-strong ||
420 cc_check -fstack-protector-all; then
421 cc_check -D_FORTIFY_SOURCE=2
423 else
424 msg 'Not checking for -fstack-protector compiler option,'
425 msg 'since that caused errors in a "similar" configuration.'
426 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
430 if feat_yes AMALGAMATION; then
431 cc_check -pipe
434 # LD (+ dependend CC)
436 if feat_yes DEVEL; then
437 _ccfg=${_CFLAGS}
438 # -fsanitize=address
439 #if cc_check -fsanitize=memory &&
440 # ld_check -fsanitize=memory &&
441 # cc_check -fsanitize-memory-track-origins=2 &&
442 # ld_check -fsanitize-memory-track-origins=2; then
444 #else
445 # _CFLAGS=${_ccfg}
449 ld_check -Wl,-z,relro
450 ld_check -Wl,-z,now
451 ld_check -Wl,-z,noexecstack
453 # Address randomization
454 _ccfg=${_CFLAGS}
455 if cc_check -fPIE || cc_check -fpie; then
456 ld_check -pie || _CFLAGS=${_ccfg}
458 unset _ccfg
460 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
461 unset __cflags __ldflags
464 ## -- >8 -- 8< -- ##
466 ## Notes:
467 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
468 ## redirection, so use "printf '' >" instead
470 ## Very first: we undergo several states regarding I/O redirection etc.,
471 ## but need to deal with option updates from within all. Since all the
472 ## option stuff should be above the scissor line, define utility functions
473 ## and redefine them as necessary.
474 ## And, since we have those functions, simply use them for whatever
476 config_exit() {
477 exit ${1}
480 msg() {
481 fmt=${1}
482 shift
483 printf >&2 -- "${fmt}\\n" "${@}"
486 ## First of all, create new configuration and check wether it changed
488 rc=./make.rc
489 lst=./config.lst
490 h=./config.h h_name=config.h
491 mk=./mk.mk
493 newlst=./config.lst-new
494 newmk=./config.mk-new
495 newh=./config.h-new
496 tmp0=___tmp
497 tmp=./${tmp0}1$$
498 tmp2=./${tmp0}2$$
500 t1=ten10one1ten10one1
501 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
502 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
503 ) > /dev/null 2>&1; then
504 good_shell=1
505 else
506 unset good_shell
508 unset t1
510 # We need some standard utilities
511 unset -f command
512 check_tool() {
513 n=${1} i=${2} opt=${3:-0}
514 # Evaluate, just in case user comes in with shell snippets (..well..)
515 eval i="${i}"
516 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
517 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
518 eval ${n}=${i}
519 return 0
521 if [ ${opt} -eq 0 ]; then
522 msg 'ERROR: no trace of utility "%s"' "${n}"
523 config_exit 1
525 return 1
528 # Very easy checks for the operating system in order to be able to adjust paths
529 # or similar very basic things which we need to be able to go at all
530 os_early_setup
532 # Check those tools right now that we need before including $rc
533 msg 'Checking for basic utility set'
534 check_tool awk "${awk:-`command -v awk`}"
535 check_tool rm "${rm:-`command -v rm`}"
536 check_tool tr "${tr:-`command -v tr`}"
538 # Our feature check environment
539 feat_val_no() {
540 [ "x${1}" = x0 ] ||
541 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
544 feat_val_yes() {
545 [ "x${1}" = x1 ] ||
546 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
547 [ "x${1}" = xrequire ]
550 feat_val_require() {
551 [ "x${1}" = xrequire ]
554 _feat_check() {
555 eval i=\$WANT_${1}
556 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
557 if feat_val_no "${i}"; then
558 return 1
559 elif feat_val_yes "${i}"; then
560 return 0
561 else
562 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
563 "${1}" "${i}"
564 config_exit 11
568 feat_yes() {
569 _feat_check ${1}
572 feat_no() {
573 _feat_check ${1} && return 1
574 return 0
577 feat_require() {
578 eval i=\$WANT_${1}
579 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
580 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
583 feat_bail_required() {
584 if feat_require ${1}; then
585 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
586 config_exit 13
588 eval WANT_${1}=0
589 option_update # XXX this is rather useless here (dependency chain..)
592 # Include $rc, but only take from it what wasn't overwritten by the user from
593 # within the command line or from a chosen fixed CONFIG=
594 # Note we leave alone the values
595 trap "exit 1" HUP INT TERM
596 trap "${rm} -f ${tmp}" EXIT
598 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
599 ${rm} -f ${tmp}
600 # We want read(1) to perform backslash escaping in order to be able to use
601 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
602 # VMs (see [fa2e248]), Aharon Robbins suggested the following
603 < ${rc} ${awk} 'BEGIN{line = ""}{
604 gsub(/^[[:space:]]+/, "", $0)
605 gsub(/[[:space:]]+$/, "", $0)
606 if(gsub(/\\$/, "", $0)){
607 line = line $0
608 next
609 }else
610 line = line $0
611 if(index(line, "#") == 1){
612 line = ""
613 }else if(length(line)){
614 print line
615 line = ""
617 }' |
618 while read line; do
619 if [ -n "${good_shell}" ]; then
620 i=${line%%=*}
621 else
622 i=`${awk} -v LINE="${line}" 'BEGIN{
623 gsub(/=.*$/, "", LINE)
624 print LINE
627 if [ "${i}" = "${line}" ]; then
628 msg 'ERROR: invalid syntax in "%s"' "${line}"
629 continue
632 eval j="\$${i}" jx="\${${i}+x}"
633 if [ -n "${j}" ] || [ "${jx}" = x ]; then
634 : # Yet present
635 else
636 j=`${awk} -v LINE="${line}" 'BEGIN{
637 gsub(/^[^=]*=/, "", LINE)
638 gsub(/^\"*/, "", LINE)
639 gsub(/\"*$/, "", LINE)
640 print LINE
643 echo "${i}=\"${j}\""
644 done > ${tmp}
645 # Reread the mixed version right now
646 . ./${tmp}
647 printf >&2 'done\n'
649 # We need to know about that now, in order to provide utility overwrites etc.
650 os_setup
652 msg 'Checking for remaining set of utilities'
653 check_tool grep "${grep:-`command -v grep`}"
655 # Before we step ahead with the other utilities perform a path cleanup first.
656 # We need this function also for C_INCLUDE_PATH and LD_LIBRARY_PATH
657 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
658 path_check() {
659 varname=${1} addflag=${2} flagvarname=${3}
660 j=${IFS}
661 IFS=:
662 eval "set -- \$${1}"
663 IFS=${j}
664 j= k= y= z=
665 for i
667 [ -z "${i}" ] && continue
668 [ -d "${i}" ] || continue
669 if [ -n "${j}" ]; then
670 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
672 else
673 y="${y} :${i}:"
674 j="${j}:${i}"
675 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
677 else
678 y=" :${i}:"
679 j="${i}"
680 [ -n "${addflag}" ] && k="${addflag}${i}"
682 done
683 eval "${varname}=\"${j}\""
684 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
685 unset varname
688 path_check PATH
690 # awk(1) above
691 check_tool cat "${cat:-`command -v cat`}"
692 check_tool chmod "${chmod:-`command -v chmod`}"
693 check_tool cp "${cp:-`command -v cp`}"
694 check_tool cmp "${cmp:-`command -v cmp`}"
695 # grep(1) above
696 check_tool mkdir "${mkdir:-`command -v mkdir`}"
697 check_tool mv "${mv:-`command -v mv`}"
698 # rm(1) above
699 check_tool sed "${sed:-`command -v sed`}"
700 check_tool sort "${sort:-`command -v sort`}"
701 check_tool tee "${tee:-`command -v tee`}"
703 check_tool chown "${chown:-`command -v chown`}" 1 ||
704 check_tool chown "/sbin/chown" 1 ||
705 check_tool chown "/usr/sbin/chown"
707 check_tool make "${MAKE:-`command -v make`}"
708 MAKE=${make}
709 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
710 HAVE_STRIP=1 || HAVE_STRIP=0
712 # For ./cc-test.sh only
713 check_tool cksum "${cksum:-`command -v cksum`}"
715 # Update WANT_ options now, in order to get possible inter-dependencies right
716 option_update
718 # (No functions since some shells loose non-exported variables in traps)
719 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
720 trap "trap \"\" HUP INT TERM EXIT;\
721 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newh}" EXIT
723 # Our configuration options may at this point still contain shell snippets,
724 # we need to evaluate them in order to get them expanded, and we need those
725 # evaluated values not only in our new configuration file, but also at hand..
726 printf >&2 'Evaluating all configuration items ... '
727 ${rm} -f ${newlst} ${newmk} ${newh}
728 exec 5<&0 6>&1 <${tmp} >${newlst}
729 while read line; do
731 if [ -n "${good_shell}" ]; then
732 i=${line%%=*}
733 [ "${i}" != "${i#WANT_}" ] && z=1
734 else
735 i=`${awk} -v LINE="${line}" 'BEGIN{
736 gsub(/=.*$/, "", LINE);\
737 print LINE
739 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
744 eval j=\$${i}
745 if [ -n "${z}" ]; then
746 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
747 if [ -z "${j}" ] || feat_val_no "${j}"; then
749 printf "/*#define ${i}*/\n" >> ${newh}
750 elif feat_val_yes "${j}"; then
751 if feat_val_require "${j}"; then
752 j=require
753 else
756 printf "#define ${i}\n" >> ${newh}
757 else
758 msg 'ERROR: cannot parse <%s>' "${line}"
759 config_exit 1
761 else
762 printf "#define ${i} \"${j}\"\n" >> ${newh}
764 printf "${i} = ${j}\n" >> ${newmk}
765 printf "${i}=${j}\n"
766 eval "${i}=\"${j}\""
767 done
768 exec 0<&5 1>&6 5<&- 6<&-
769 printf >&2 'done\n'
771 # Add the known utility and some other variables
772 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
773 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
775 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
776 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
777 if feat_yes DOTLOCK; then
778 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
779 else
780 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
783 for i in \
784 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
785 MAKE make strip \
786 cksum; do
787 eval j=\$${i}
788 printf "${i} = ${j}\n" >> ${newmk}
789 printf "${i}=${j}\n" >> ${newlst}
790 done
792 # Build a basic set of INCS and LIBS according to user environment.
793 path_check C_INCLUDE_PATH -I _INCS
794 INCS="${INCS} ${_INCS}"
795 path_check LD_LIBRARY_PATH -L _LIBS
796 LIBS="${LIBS} ${_LIBS}"
797 unset _INCS _LIBS
798 export C_INCLUDE_PATH LD_LIBRARY_PATH
800 if [ -n "${need_R_ldflags}" ]; then
801 i=${IFS}
802 IFS=:
803 set -- ${LD_LIBRARY_PATH}
804 IFS=${i}
805 for i
807 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
808 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
809 done
810 export LDFLAGS
813 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
815 cc_setup
817 ${cat} > ${tmp}.c << \!
818 #include <stdio.h>
819 #include <string.h>
820 static void doit(char const *s);
822 main(int argc, char **argv){
823 (void)argc;
824 (void)argv;
825 doit("Hello world");
826 return 0;
828 static void
829 doit(char const *s){
830 char buf[12];
831 strcpy(buf, s);
832 puts(s);
836 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
837 -o ${tmp2} ${tmp}.c ${LIBS}; then
839 else
840 msg 'ERROR: i cannot compile a "Hello world" via'
841 msg ' %s' \
842 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
843 msg 'ERROR: Please read INSTALL, rerun'
844 config_exit 1
847 cc_check() {
848 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
849 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
850 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
851 _CFLAGS="${_CFLAGS} ${1}"
852 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
853 return 0
855 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
856 return 1
859 ld_check() {
860 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
861 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1} ${ADDLDFLAGS} \
862 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
863 _LDFLAGS="${_LDFLAGS} ${1}"
864 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
865 return 0
867 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
868 return 1
871 cc_flags
873 for i in \
874 INCS LIBS \
875 ; do
876 eval j=\$${i}
877 printf -- "${i}=${j}\n" >> ${newlst}
878 done
879 for i in \
880 CC \
881 CFLAGS \
882 LDFLAGS \
883 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
884 OSFULLSPEC \
885 ; do
886 eval j=\$${i}
887 printf -- "${i} = ${j}\n" >> ${newmk}
888 printf -- "${i}=${j}\n" >> ${newlst}
889 done
891 # Now finally check wether we already have a configuration and if so, wether
892 # all those parameters are still the same.. or something has actually changed
893 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
894 echo 'Configuration is up-to-date'
895 exit 0
896 elif [ -f ${lst} ]; then
897 echo 'Configuration has been updated..'
898 ( eval "${MAKE} -f ./mk.mk clean" )
899 echo
900 else
901 echo 'Shiny configuration..'
904 # Time to redefine helper 1
905 config_exit() {
906 ${rm} -f ${lst} ${h} ${mk}
907 exit ${1}
910 ${mv} -f ${newlst} ${lst}
911 ${mv} -f ${newh} ${h}
912 ${mv} -f ${newmk} ${mk}
914 ## Compile and link checking
916 tmp3=./${tmp0}3$$
917 log=./config.log
918 lib=./config.lib
919 inc=./config.inc
920 makefile=./config.mk
922 # (No function since some shells loose non-exported variables in traps)
923 trap "trap \"\" HUP INT TERM;\
924 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
925 trap "trap \"\" HUP INT TERM EXIT;\
926 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
928 # Time to redefine helper 2
929 msg() {
930 fmt=${1}
931 shift
932 printf "*** ${fmt}\\n" "${@}"
933 printf -- "${fmt}\\n" "${@}" >&5
935 msg_nonl() {
936 fmt=${1}
937 shift
938 printf "*** ${fmt}\\n" "${@}"
939 printf -- "${fmt}" "${@}" >&5
942 exec 5>&2 > ${log} 2>&1
944 echo "${LIBS}" > ${lib}
945 echo "${INCS}" > ${inc}
946 ${cat} > ${makefile} << \!
947 .SUFFIXES: .o .c .x .y
948 .c.o:
949 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
950 .c.x:
951 $(CC) -I./ $(XINCS) -E $< >$@
953 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
954 .y: ;
957 _check_preface() {
958 variable=$1 topic=$2 define=$3
960 echo '**********'
961 msg_nonl ' . %s ... ' "${topic}"
962 echo "/* checked ${topic} */" >> ${h}
963 ${rm} -f ${tmp} ${tmp}.o
964 echo '*** test program is'
965 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
966 #echo '*** the preprocessor generates'
967 #${make} -f ${makefile} ${tmp}.x
968 #${cat} ${tmp}.x
969 echo '*** results are'
972 compile_check() {
973 variable=$1 topic=$2 define=$3
975 _check_preface "${variable}" "${topic}" "${define}"
977 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
978 [ -f ./${tmp}.o ]; then
979 msg 'yes'
980 echo "${define}" >> ${h}
981 eval have_${variable}=yes
982 return 0
983 else
984 echo "/* ${define} */" >> ${h}
985 msg 'no'
986 eval unset have_${variable}
987 return 1
991 _link_mayrun() {
992 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
994 _check_preface "${variable}" "${topic}" "${define}"
996 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
997 XLIBS="${LIBS} ${libs}" ./${tmp} &&
998 [ -f ./${tmp} ] &&
999 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1000 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1001 msg 'yes'
1002 echo "${define}" >> ${h}
1003 LIBS="${LIBS} ${libs}"
1004 echo "${libs}" >> ${lib}
1005 INCS="${INCS} ${incs}"
1006 echo "${incs}" >> ${inc}
1007 eval have_${variable}=yes
1008 return 0
1009 else
1010 msg 'no'
1011 echo "/* ${define} */" >> ${h}
1012 eval unset have_${variable}
1013 return 1
1017 link_check() {
1018 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1021 run_check() {
1022 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1027 # May be multiline..
1028 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1030 if run_check inline '"inline" functions' \
1031 '#define HAVE_INLINE
1032 #define n_INLINE static inline' << \!
1033 static inline int ilf(int i){return ++i;}
1034 int main(void){return ilf(-1);}
1036 then
1038 elif run_check inline '"__inline" functions' \
1039 '#define HAVE_INLINE
1040 #define n_INLINE static __inline' << \!
1041 static __inline int ilf(int i){return ++i;}
1042 int main(void){return ilf(-1);}
1044 then
1048 if run_check endian 'Little endian byteorder' \
1049 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1050 int main(void){
1051 enum {vBig = 1, vLittle = 0};
1052 union {unsigned short bom; unsigned char buf[2];} u;
1053 u.bom = 0xFEFF;
1054 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1057 then
1063 if run_check clock_gettime 'clock_gettime(2)' \
1064 '#define HAVE_CLOCK_GETTIME' << \!
1065 #include <time.h>
1066 # include <errno.h>
1067 int main(void){
1068 struct timespec ts;
1070 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1071 return 0;
1072 return 1;
1075 then
1077 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1078 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1079 #include <time.h>
1080 # include <errno.h>
1081 int main(void){
1082 struct timespec ts;
1084 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1085 return 0;
1086 return 1;
1089 then
1091 elif run_check gettimeofday 'gettimeofday(2)' \
1092 '#define HAVE_GETTIMEOFDAY' << \!
1093 #include <stdio.h> /* For C89 NULL */
1094 #include <sys/time.h>
1095 # include <errno.h>
1096 int main(void){
1097 struct timeval tv;
1099 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1100 return 0;
1101 return 1;
1104 then
1106 else
1107 have_no_subsecond_time=1
1110 if run_check nanosleep 'nanosleep(2)' \
1111 '#define HAVE_NANOSLEEP' << \!
1112 #include <time.h>
1113 # include <errno.h>
1114 int main(void){
1115 struct timespec ts;
1117 ts.tv_sec = 1;
1118 ts.tv_nsec = 100000;
1119 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1120 return 0;
1121 return 1;
1124 then
1126 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1127 '#define HAVE_NANOSLEEP' '-lrt' << \!
1128 #include <time.h>
1129 # include <errno.h>
1130 int main(void){
1131 struct timespec ts;
1133 ts.tv_sec = 1;
1134 ts.tv_nsec = 100000;
1135 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1136 return 0;
1137 return 1;
1140 then
1142 # link_check is enough for this, that function is so old, trust the proto
1143 elif link_check sleep 'sleep(3)' \
1144 '#define HAVE_SLEEP' << \!
1145 #include <unistd.h>
1146 # include <errno.h>
1147 int main(void){
1148 if(!sleep(1) || errno != ENOSYS)
1149 return 0;
1150 return 1;
1153 then
1155 else
1156 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1157 config_exit 1
1160 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1161 #include <pwd.h>
1162 #include <unistd.h>
1163 # include <errno.h>
1164 int main(void){
1165 struct passwd *pw;
1166 gid_t gid;
1167 uid_t uid;
1169 if((gid = getgid()) != 0)
1170 gid = getegid();
1171 if((uid = getuid()) != 0)
1172 uid = geteuid();
1173 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1174 return 1;
1175 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1176 return 1;
1177 return 0;
1180 then
1182 else
1183 msg 'ERROR: we require user and group info / database searches.'
1184 msg 'That much Unix we indulge ourselfs.'
1185 config_exit 1
1188 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1189 #include <signal.h>
1190 # include <errno.h>
1191 int main(void){
1192 struct sigaction nact, oact;
1194 nact.sa_handler = SIG_DFL;
1195 sigemptyset(&nact.sa_mask);
1196 nact.sa_flags = SA_RESTART;
1197 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1200 then
1202 else
1203 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1204 config_exit 1
1207 if link_check snprintf 'v?snprintf(3)' << \!
1208 #include <stdarg.h>
1209 #include <stdio.h>
1210 static void dome(char *buf, ...){
1211 va_list ap;
1213 va_start(ap, buf);
1214 vsnprintf(buf, 20, "%s", ap);
1215 va_end(ap);
1216 return;
1218 int main(void){
1219 char b[20];
1221 snprintf(b, sizeof b, "%s", "string");
1222 dome(b, "string");
1223 return 0;
1226 then
1228 else
1229 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1230 config_exit 1
1233 if link_check environ 'environ(3)' << \!
1234 #include <stdio.h> /* For C89 NULL */
1235 int main(void){
1236 extern char **environ;
1238 return environ[0] == NULL;
1241 then
1243 else
1244 msg 'ERROR: we require the environ(3) array for subprocess control.'
1245 config_exit 1
1248 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1249 #include <stdlib.h>
1250 int main(void){
1251 setenv("s-mailx", "i want to see it cute!", 1);
1252 unsetenv("s-mailx");
1253 return 0;
1256 then
1258 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1259 #include <stdlib.h>
1260 int main(void){
1261 putenv("s-mailx=i want to see it cute!");
1262 return 0;
1265 then
1267 else
1268 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1269 config_exit 1
1272 if link_check termios 'termios.h and tc*(3) family' << \!
1273 #include <termios.h>
1274 int main(void){
1275 struct termios tios;
1277 tcgetattr(0, &tios);
1278 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1279 return 0;
1282 then
1284 else
1285 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1286 msg 'That much Unix we indulge ourselfs.'
1287 config_exit 1
1292 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1293 #include <unistd.h>
1294 #include <errno.h>
1295 int main(void){
1296 int rv = 0;
1298 errno = 0;
1299 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1300 errno = 0;
1301 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1303 /* Only link check */
1304 fpathconf(0, _PC_NAME_MAX);
1306 return rv;
1310 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1311 #include <fcntl.h>
1312 #include <unistd.h>
1313 # include <errno.h>
1314 int main(void){
1315 int fds[2];
1317 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1318 return 0;
1319 return 1;
1323 # We use this only then for now (need NOW+1)
1324 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1325 #include <fcntl.h> /* For AT_* */
1326 #include <sys/stat.h>
1327 # include <errno.h>
1328 int main(void){
1329 struct timespec ts[2];
1331 ts[0].tv_nsec = UTIME_NOW;
1332 ts[1].tv_nsec = UTIME_OMIT;
1333 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1334 return 0;
1335 return 1;
1341 # XXX Add POSIX check once standardized
1342 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1343 #include <stdlib.h>
1344 int main(void){
1345 arc4random();
1346 return 0;
1349 then
1351 elif [ -n "${have_no_subsecond_time}" ]; then
1352 msg 'ERROR: %s %s' 'without a native random' \
1353 'one of clock_gettime(2) and gettimeofday(2) is required.'
1354 config_exit 1
1357 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1358 #include <stdio.h>
1359 int main(void){
1360 putc_unlocked('@', stdout);
1361 return 0;
1365 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1366 #include <unistd.h>
1367 int main(void){
1368 fchdir(0);
1369 return 0;
1373 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1374 #include <locale.h>
1375 int main(void){
1376 setlocale(LC_ALL, "");
1377 return 0;
1381 if [ "${have_setlocale}" = yes ]; then
1382 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1383 '#define HAVE_C90AMEND1' << \!
1384 #include <limits.h>
1385 #include <stdlib.h>
1386 #include <wchar.h>
1387 #include <wctype.h>
1388 int main(void){
1389 char mbb[MB_LEN_MAX + 1];
1390 wchar_t wc;
1392 iswprint(L'c');
1393 towupper(L'c');
1394 mbtowc(&wc, "x", 1);
1395 mbrtowc(&wc, "x", 1, NULL);
1396 wctomb(mbb, wc);
1397 return (mblen("\0", 1) == 0);
1401 if [ "${have_c90amend1}" = yes ]; then
1402 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1403 #include <wchar.h>
1404 int main(void){
1405 wcwidth(L'c');
1406 return 0;
1411 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1412 #include <langinfo.h>
1413 #include <stdlib.h>
1414 int main(void){
1415 nl_langinfo(DAY_1);
1416 return (nl_langinfo(CODESET) == NULL);
1419 fi # have_setlocale
1421 run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1422 #include <stdlib.h>
1423 int main(void){
1424 #if 1 /* TODO for now we use realpath(3) without NULL as 2nd arg! */
1425 /* (And note that on Linux tcc(1) otherwise didn't detect once tested! */
1426 char x_buf[4096], *x = realpath(".", x_buf);
1428 return (x != NULL) ? 0 : 1;
1429 #else
1430 char *x = realpath(".", NULL), *y = realpath("/", NULL);
1432 return (x != NULL && y != NULL) ? 0 : 1;
1433 #endif
1437 link_check wordexp 'wordexp(3)' '#define HAVE_WORDEXP' << \!
1438 #include <stdio.h> /* For C89 NULL */
1439 #include <wordexp.h>
1440 int main(void){
1441 wordexp(NULL, NULL, 0);
1442 return 0;
1448 if feat_yes DEBUG; then
1449 echo '#define HAVE_DEBUG' >> ${h}
1452 if feat_yes AMALGAMATION; then
1453 echo '#define HAVE_AMALGAMATION' >> ${h}
1456 if feat_no NOALLOCA; then
1457 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1458 # versions of alloca(3) since modern compilers just can't be trusted
1459 # not to overoptimize and silently break some code
1460 run_check alloca '__builtin_alloca()' \
1461 '#define HAVE_ALLOCA __builtin_alloca' << \!
1462 #include <stdio.h> /* For C89 NULL */
1463 int main(void){
1464 void *vp = __builtin_alloca(1);
1466 return (vp != NULL);
1471 if feat_yes DEVEL; then
1472 echo '#define HAVE_DEVEL' >> ${h}
1475 if feat_yes NYD2; then
1476 echo '#define HAVE_NYD2' >> ${h}
1481 if feat_yes DOTLOCK; then
1482 if run_check readlink 'readlink(2)' << \!
1483 #include <unistd.h>
1484 # include <errno.h>
1485 int main(void){
1486 char buf[128];
1488 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1489 return 0;
1490 return 1;
1493 then
1495 else
1496 feat_bail_required DOTLOCK
1500 if feat_yes DOTLOCK; then
1501 if run_check fchown 'fchown(2)' << \!
1502 #include <unistd.h>
1503 # include <errno.h>
1504 int main(void){
1505 if(!fchown(0, 0, 0) || errno != ENOSYS)
1506 return 0;
1507 return 1;
1510 then
1512 else
1513 feat_bail_required DOTLOCK
1519 if feat_yes ICONV; then
1520 ${cat} > ${tmp2}.c << \!
1521 #include <stdio.h> /* For C89 NULL */
1522 #include <iconv.h>
1523 int main(void){
1524 iconv_t id;
1526 id = iconv_open("foo", "bar");
1527 iconv(id, NULL, NULL, NULL, NULL);
1528 iconv_close(id);
1529 return 0;
1532 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1533 '#define HAVE_ICONV' ||
1534 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1535 '#define HAVE_ICONV' '-liconv' ||
1536 feat_bail_required ICONV
1537 else
1538 echo '/* WANT_ICONV=0 */' >> ${h}
1539 fi # feat_yes ICONV
1541 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1542 ${cat} > ${tmp2}.c << \!
1543 #include <sys/types.h>
1544 #include <sys/socket.h>
1545 #include <sys/un.h>
1546 # include <errno.h>
1547 int main(void){
1548 struct sockaddr_un soun;
1550 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1551 return 1;
1552 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1553 return 1;
1554 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1555 return 1;
1556 return 0;
1560 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1561 '#define HAVE_UNIX_SOCKETS' ||
1562 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1563 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1564 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1565 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1568 if feat_yes SOCKETS; then
1569 ${cat} > ${tmp2}.c << \!
1570 #include "config.h"
1571 #include <sys/types.h>
1572 #include <sys/socket.h>
1573 #include <netinet/in.h>
1574 # include <errno.h>
1575 int main(void){
1576 struct sockaddr s;
1578 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1579 return 1;
1580 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1581 return 1;
1582 return 0;
1586 < ${tmp2}.c run_check sockets 'sockets' \
1587 '#define HAVE_SOCKETS' ||
1588 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1589 '#define HAVE_SOCKETS' '-lnsl' ||
1590 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1591 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1592 feat_bail_required SOCKETS
1593 else
1594 echo '/* WANT_SOCKETS=0 */' >> ${h}
1595 fi # feat_yes SOCKETS
1597 if feat_yes SOCKETS; then
1598 link_check getaddrinfo 'getaddrinfo(3)' \
1599 '#define HAVE_GETADDRINFO' << \!
1600 #include "config.h"
1601 #include <sys/types.h>
1602 #include <sys/socket.h>
1603 #include <stdio.h>
1604 #include <netdb.h>
1605 int main(void){
1606 struct addrinfo a, *ap;
1607 int lrv;
1609 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1610 case EAI_NONAME:
1611 case EAI_SERVICE:
1612 default:
1613 fprintf(stderr, "%s\n", gai_strerror(lrv));
1614 case 0:
1615 break;
1617 return 0;
1622 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1623 compile_check arpa_inet_h '<arpa/inet.h>' \
1624 '#define HAVE_ARPA_INET_H' << \!
1625 #include "config.h"
1626 #include <sys/types.h>
1627 #include <sys/socket.h>
1628 #include <netdb.h>
1629 #include <netinet/in.h>
1630 #include <arpa/inet.h>
1633 ${cat} > ${tmp2}.c << \!
1634 #include "config.h"
1635 #include <sys/types.h>
1636 #include <sys/socket.h>
1637 #include <stdio.h>
1638 #include <string.h>
1639 #include <netdb.h>
1640 #include <netinet/in.h>
1641 #ifdef HAVE_ARPA_INET_H
1642 #include <arpa/inet.h>
1643 #endif
1644 int main(void){
1645 struct sockaddr_in servaddr;
1646 unsigned short portno;
1647 struct servent *ep;
1648 struct hostent *hp;
1649 struct in_addr **pptr;
1651 portno = 0;
1652 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1653 portno = (unsigned short)ep->s_port;
1655 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1656 pptr = (struct in_addr**)hp->h_addr_list;
1657 if(hp->h_addrtype != AF_INET)
1658 fprintf(stderr, "au\n");
1659 }else{
1660 switch(h_errno){
1661 case HOST_NOT_FOUND:
1662 case TRY_AGAIN:
1663 case NO_RECOVERY:
1664 case NO_DATA:
1665 break;
1666 default:
1667 fprintf(stderr, "au\n");
1668 break;
1672 memset(&servaddr, 0, sizeof servaddr);
1673 servaddr.sin_family = AF_INET;
1674 servaddr.sin_port = htons(portno);
1675 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1676 fprintf(stderr, "Would connect to %s:%d ...\n",
1677 inet_ntoa(**pptr), (int)portno);
1678 return 0;
1682 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1683 < ${tmp2}.c link_check gethostbyname \
1684 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1685 < ${tmp2}.c link_check gethostbyname \
1686 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1687 '' '-lsocket -lnsl' ||
1688 feat_bail_required SOCKETS
1691 feat_yes SOCKETS &&
1692 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1693 #include <sys/socket.h>
1694 #include <stdlib.h>
1695 # include <errno.h>
1696 int main(void){
1697 int sockfd = 3;
1699 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1700 errno == ENOSYS)
1701 return 1;
1702 return 0;
1706 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1707 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1708 #include <sys/socket.h>
1709 #include <stdlib.h>
1710 int main(void){
1711 struct timeval tv;
1712 int sockfd = 3;
1714 tv.tv_sec = 42;
1715 tv.tv_usec = 21;
1716 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1717 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1718 return 0;
1722 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1723 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1724 #include <sys/socket.h>
1725 #include <stdlib.h>
1726 int main(void){
1727 struct linger li;
1728 int sockfd = 3;
1730 li.l_onoff = 1;
1731 li.l_linger = 42;
1732 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1733 return 0;
1737 if feat_yes SSL; then
1738 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1739 '#define HAVE_SSL
1740 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1741 #include <openssl/ssl.h>
1742 #include <openssl/err.h>
1743 #include <openssl/x509v3.h>
1744 #include <openssl/x509.h>
1745 #include <openssl/rand.h>
1746 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1747 # error We need TLSv1.
1748 #endif
1749 int main(void){
1750 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1752 SSL_CTX_free(ctx);
1753 PEM_read_PrivateKey(0, 0, 0, 0);
1754 return 0;
1757 then
1759 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1760 '#define HAVE_SSL
1761 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1762 #include <openssl/ssl.h>
1763 #include <openssl/err.h>
1764 #include <openssl/x509v3.h>
1765 #include <openssl/x509.h>
1766 #include <openssl/rand.h>
1767 #if defined OPENSSL_NO_SSL3 &&\
1768 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1769 # error We need one of SSLv3 and TLSv1.
1770 #endif
1771 int main(void){
1772 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1774 SSL_CTX_free(ctx);
1775 PEM_read_PrivateKey(0, 0, 0, 0);
1776 return 0;
1779 then
1781 else
1782 feat_bail_required SSL
1785 if [ "${have_openssl}" = 'yes' ]; then
1786 compile_check stack_of 'OpenSSL STACK_OF()' \
1787 '#define HAVE_OPENSSL_STACK_OF' << \!
1788 #include <stdio.h> /* For C89 NULL */
1789 #include <openssl/ssl.h>
1790 #include <openssl/err.h>
1791 #include <openssl/x509v3.h>
1792 #include <openssl/x509.h>
1793 #include <openssl/rand.h>
1794 int main(void){
1795 STACK_OF(GENERAL_NAME) *gens = NULL;
1797 printf("%p", gens); /* to use it */
1798 return 0;
1802 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1803 '#define HAVE_OPENSSL_CONFIG' << \!
1804 #include <stdio.h> /* For C89 NULL */
1805 #include <openssl/conf.h>
1806 int main(void){
1807 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1808 CONF_modules_free();
1809 return 0;
1813 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1814 '#define HAVE_OPENSSL_CONF_CTX' << \!
1815 #include "config.h"
1816 #include <openssl/ssl.h>
1817 #include <openssl/err.h>
1818 int main(void){
1819 #if HAVE_OPENSSL < 10100
1820 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1821 #else
1822 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1823 #endif
1824 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1826 SSL_CONF_CTX_set_flags(cctx,
1827 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1828 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1829 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1830 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1831 SSL_CONF_CTX_finish(cctx);
1832 SSL_CONF_CTX_free(cctx);
1833 SSL_CTX_free(ctx);
1834 return 0;
1838 link_check rand_egd 'OpenSSL RAND_egd(3ssl)' \
1839 '#define HAVE_OPENSSL_RAND_EGD' << \!
1840 #include <openssl/rand.h>
1841 int main(void){
1842 return RAND_egd("some.where") > 0;
1846 if feat_yes SSL_ALL_ALGORITHMS; then
1847 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1848 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1849 #include <openssl/evp.h>
1850 int main(void){
1851 OpenSSL_add_all_algorithms();
1852 EVP_get_cipherbyname("two cents i never exist");
1853 EVP_cleanup();
1854 return 0;
1857 then
1859 else
1860 feat_bail_required SSL_ALL_ALGORITHMS
1862 fi # SSL_ALL_ALGORITHMS
1864 if feat_yes MD5 && feat_no NOEXTMD5; then
1865 run_check openssl_md5 'MD5 digest in OpenSSL' \
1866 '#define HAVE_OPENSSL_MD5' << \!
1867 #include <stdlib.h>
1868 #include <string.h>
1869 #include <openssl/md5.h>
1870 int main(void){
1871 char const dat[] = "abrakadabrafidibus";
1872 char dig[16], hex[16 * 2];
1873 MD5_CTX ctx;
1874 size_t i, j;
1876 memset(dig, 0, sizeof(dig));
1877 memset(hex, 0, sizeof(hex));
1878 MD5_Init(&ctx);
1879 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1880 MD5_Final(dig, &ctx);
1882 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1883 for(i = 0; i < sizeof(hex) / 2; i++){
1884 j = i << 1;
1885 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1886 hex[++j] = hexchar(dig[i] & 0x0f);
1888 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1891 fi # feat_yes MD5 && feat_no NOEXTMD5
1893 else
1894 echo '/* WANT_SSL=0 */' >> ${h}
1895 fi # feat_yes SSL
1897 if feat_yes SMTP; then
1898 echo '#define HAVE_SMTP' >> ${h}
1899 else
1900 echo '/* WANT_SMTP=0 */' >> ${h}
1903 if feat_yes POP3; then
1904 echo '#define HAVE_POP3' >> ${h}
1905 else
1906 echo '/* WANT_POP3=0 */' >> ${h}
1909 if feat_yes GSSAPI; then
1910 ${cat} > ${tmp2}.c << \!
1911 #include <gssapi/gssapi.h>
1912 int main(void){
1913 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1914 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1915 return 0;
1918 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1920 if command -v krb5-config >/dev/null 2>&1; then
1921 i=`command -v krb5-config`
1922 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1923 GSS_INCS="`CFLAGS= ${i} --cflags`"
1924 i='GSS-API via krb5-config(1)'
1925 else
1926 GSS_LIBS='-lgssapi'
1927 GSS_INCS=
1928 i='GSS-API in gssapi/gssapi.h, libgssapi'
1930 if < ${tmp2}.c link_check gss \
1931 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1932 < ${tmp3}.c link_check gss \
1933 'GSS-API in gssapi.h, libgssapi' \
1934 '#define HAVE_GSSAPI
1935 #define GSSAPI_REG_INCLUDE' \
1936 '-lgssapi' ||\
1937 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1938 '#define HAVE_GSSAPI' \
1939 '-lgssapi_krb5' ||\
1940 < ${tmp3}.c link_check gss \
1941 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1942 '#define HAVE_GSSAPI
1943 #define GSS_REG_INCLUDE' \
1944 '-lgssapi -lkrb5 -lcrypto' \
1945 '-I/usr/include/kerberosV' ||\
1946 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1947 '#define HAVE_GSSAPI' \
1948 '-lgss' ||\
1949 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1950 '#define HAVE_GSSAPI
1951 #define GSSAPI_OLD_STYLE' \
1952 '-lgssapi_krb5' << \!
1953 #include <gssapi/gssapi.h>
1954 #include <gssapi/gssapi_generic.h>
1955 int main(void){
1956 gss_import_name(0, 0, gss_nt_service_name, 0);
1957 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1958 return 0;
1961 then
1963 else
1964 feat_bail_required GSSAPI
1966 else
1967 echo '/* WANT_GSSAPI=0 */' >> ${h}
1968 fi # feat_yes GSSAPI
1970 if feat_yes NETRC; then
1971 echo '#define HAVE_NETRC' >> ${h}
1972 else
1973 echo '/* WANT_NETRC=0 */' >> ${h}
1976 if feat_yes AGENT; then
1977 echo '#define HAVE_AGENT' >> ${h}
1978 else
1979 echo '/* WANT_AGENT=0 */' >> ${h}
1982 if feat_yes IDNA; then
1983 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
1984 '-lidn' << \!
1985 #include <idna.h>
1986 #include <idn-free.h>
1987 #include <stringprep.h>
1988 int main(void){
1989 char *utf8, *idna_ascii, *idna_utf8;
1991 utf8 = stringprep_locale_to_utf8("does.this.work");
1992 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
1993 != IDNA_SUCCESS)
1994 return 1;
1995 idn_free(idna_ascii);
1996 /* (Rather link check only here) */
1997 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
1998 return 0;
2001 then
2003 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2004 '-lidnkit' << \!
2005 #include <stdio.h>
2006 #include <idn/api.h>
2007 #include <idn/result.h>
2008 int main(void){
2009 idn_result_t r;
2010 char ace_name[256];
2011 char local_name[256];
2013 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2014 sizeof(ace_name));
2015 if (r != idn_success) {
2016 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2017 return 1;
2019 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2020 if (r != idn_success) {
2021 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2022 return 1;
2024 return 0;
2027 then
2029 else
2030 feat_bail_required IDNA
2033 if [ -n "${have_idna}" ]; then
2034 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2035 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2037 else
2038 echo '/* WANT_IDNA=0 */' >> ${h}
2041 if feat_yes IMAP_SEARCH; then
2042 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2043 else
2044 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
2047 if feat_yes REGEX; then
2048 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2049 #include <regex.h>
2050 #include <stdlib.h>
2051 int main(void){
2052 int status;
2053 regex_t re;
2055 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2056 return 1;
2057 status = regexec(&re, "plan9", 0,NULL, 0);
2058 regfree(&re);
2059 return !(status == REG_NOMATCH);
2062 then
2064 else
2065 feat_bail_required REGEX
2067 else
2068 echo '/* WANT_REGEX=0 */' >> ${h}
2071 if feat_yes READLINE; then
2072 __edrdlib() {
2073 link_check readline "for readline(3) (${1})" \
2074 '#define HAVE_READLINE' "${1}" << \!
2075 #include <stdio.h>
2076 #include <readline/history.h>
2077 #include <readline/readline.h>
2078 int main(void){
2079 char *rl;
2080 HISTORY_STATE *hs;
2081 HIST_ENTRY **he;
2082 int i;
2084 using_history();
2085 read_history("");
2086 stifle_history(242);
2087 rl = readline("Enter a line:");
2088 if (rl && *rl)
2089 add_history(rl);
2090 write_history("");
2091 rl_extend_line_buffer(10);
2092 rl_point = rl_end = 10;
2093 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2094 rl_forced_update_display();
2095 clear_history();
2096 hs = history_get_history_state();
2097 i = hs->length;
2098 he = history_list();
2099 if (i > 0)
2100 rl = he[0]->line;
2101 rl_free_line_state();
2102 rl_cleanup_after_signal();
2103 rl_reset_after_signal();
2104 return 0;
2109 __edrdlib -lreadline ||
2110 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2113 if feat_yes MLE && [ -z "${have_readline}" ] &&
2114 [ -n "${have_c90amend1}" ]; then
2115 have_mle=1
2116 echo '#define HAVE_MLE' >> ${h}
2117 else
2118 feat_bail_required MLE
2119 echo '/* WANT_{READLINE,MLE}=0 */' >> ${h}
2122 # Generic have-a-line-editor switch for those who need it below
2123 if [ -n "${have_mle}" ] ||
2124 [ -n "${have_readline}" ]; then
2125 have_cle=1
2128 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2129 echo '#define HAVE_HISTORY' >> ${h}
2130 else
2131 echo '/* WANT_HISTORY=0 */' >> ${h}
2134 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2135 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2136 else
2137 echo '/* WANT_KEY_BINDINGS=0 */' >> ${h}
2140 if feat_yes TERMCAP; then
2141 __termcaplib() {
2142 link_check termcap "termcap(5) (via ${4})" \
2143 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2144 #include <stdio.h>
2145 #include <stdlib.h>
2146 ${2}
2147 #include <term.h>
2148 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2149 static int my_putc(int c){return putchar(c);}
2150 int main(void){
2151 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2152 int r2 = OK, r3 = ERR;
2154 tgetent(buf, getenv("TERM"));
2155 cpb = cmdbuf;
2156 r1 = tgetstr(UNCONST("cm"), &cpb);
2157 tgoto(r1, 1, 1);
2158 r2 = tgetnum(UNCONST("Co"));
2159 r3 = tgetflag(UNCONST("ut"));
2160 tputs("cr", 1, &my_putc);
2161 return (r1 == NULL || r2 == -1 || r3 == 0);
2163 _EOT
2166 __terminfolib() {
2167 link_check terminfo "terminfo(5) (via ${2})" \
2168 '#define HAVE_TERMCAP
2169 #define HAVE_TERMCAP_CURSES
2170 #define HAVE_TERMINFO' "${1}" << _EOT
2171 #include <stdio.h>
2172 #include <curses.h>
2173 #include <term.h>
2174 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2175 static int my_putc(int c){return putchar(c);}
2176 int main(void){
2177 int er, r0, r1, r2;
2178 char *r3, *tp;
2180 er = OK;
2181 r0 = setupterm(NULL, 1, &er);
2182 r1 = tigetflag(UNCONST("bce"));
2183 r2 = tigetnum(UNCONST("colors"));
2184 r3 = tigetstr(UNCONST("cr"));
2185 tp = tparm(r3, NULL);
2186 tputs(tp, 1, &my_putc);
2187 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2188 r3 == (char*)-1 || r3 == NULL);
2190 _EOT
2193 if feat_yes TERMCAP_PREFER_TERMINFO; then
2194 __terminfolib -ltinfo -ltinfo ||
2195 __terminfolib -lcurses -lcurses ||
2196 __terminfolib -lcursesw -lcursesw ||
2197 feat_bail_required TERMCAP_PREFER_TERMINFO
2200 if [ -z "${have_terminfo}" ]; then
2201 __termcaplib -ltermcap '' '' '-ltermcap' ||
2202 __termcaplib -ltermcap '#include <curses.h>' '
2203 #define HAVE_TERMCAP_CURSES' \
2204 'curses.h / -ltermcap' ||
2205 __termcaplib -lcurses '#include <curses.h>' '
2206 #define HAVE_TERMCAP_CURSES' \
2207 'curses.h / -lcurses' ||
2208 __termcaplib -lcursesw '#include <curses.h>' '
2209 #define HAVE_TERMCAP_CURSES' \
2210 'curses.h / -lcursesw' ||
2211 feat_bail_required TERMCAP
2213 if [ -n "${have_termcap}" ]; then
2214 run_check tgetent_null \
2215 "tgetent(3) of termcap(5) takes NULL buffer" \
2216 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2217 #include <stdio.h> /* For C89 NULL */
2218 #include <stdlib.h>
2219 #ifdef HAVE_TERMCAP_CURSES
2220 # include <curses.h>
2221 #endif
2222 #include <term.h>
2223 int main(void){
2224 tgetent(NULL, getenv("TERM"));
2225 return 0;
2227 _EOT
2230 else
2231 echo '/* WANT_TERMCAP=0 */' >> ${h}
2232 echo '/* WANT_TERMCAP_PREFER_TERMINFO=0 */' >> ${h}
2235 if feat_yes ERRORS; then
2236 echo '#define HAVE_ERRORS' >> ${h}
2237 else
2238 echo '/* WANT_ERRORS=0 */' >> ${h}
2243 if feat_yes SPAM_SPAMC; then
2244 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2245 if command -v spamc >/dev/null 2>&1; then
2246 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2248 else
2249 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2252 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2253 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2254 else
2255 feat_bail_required SPAM_SPAMD
2256 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2259 if feat_yes SPAM_FILTER; then
2260 echo '#define HAVE_SPAM_FILTER' >> ${h}
2261 else
2262 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
2265 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2266 echo '#define HAVE_SPAM' >> ${h}
2267 else
2268 echo '/* HAVE_SPAM */' >> ${h}
2271 if feat_yes DOCSTRINGS; then
2272 echo '#define HAVE_DOCSTRINGS' >> ${h}
2273 else
2274 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
2277 if feat_yes QUOTE_FOLD &&\
2278 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2279 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2280 else
2281 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2284 if feat_yes FILTER_HTML_TAGSOUP; then
2285 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2286 else
2287 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2290 if feat_yes COLOUR; then
2291 echo '#define HAVE_COLOUR' >> ${h}
2292 else
2293 echo '/* WANT_COLOUR=0 */' >> ${h}
2296 if feat_yes DOTLOCK; then
2297 echo '#define HAVE_DOTLOCK' >> ${h}
2298 else
2299 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2302 if feat_yes MD5; then
2303 echo '#define HAVE_MD5' >> ${h}
2304 else
2305 echo '/* WANT_MD5=0 */' >> ${h}
2308 if feat_yes NOMEMDBG; then
2309 echo '#define HAVE_NOMEMDBG' >> ${h}
2310 else
2311 echo '/* WANT_NOMEMDBG=0 */' >> ${h}
2314 ## Summarizing
2316 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2317 squeeze_em() {
2318 < "${1}" > "${2}" ${awk} \
2319 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2321 ${rm} -f ${tmp}
2322 squeeze_em ${inc} ${tmp}
2323 ${mv} ${tmp} ${inc}
2324 squeeze_em ${lib} ${tmp}
2325 ${mv} ${tmp} ${lib}
2327 # config.h
2328 ${mv} ${h} ${tmp}
2329 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2330 ${cat} ${tmp} >> ${h}
2331 ${rm} -f ${tmp}
2333 printf '\n/* The "feature string" */\n' >> ${h}
2334 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2335 printf 'static char const _features[] = "MIME"\n' >> ${h}
2336 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2337 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2338 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2339 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2340 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2341 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2342 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2343 >> ${h}
2344 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2345 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2346 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2347 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2348 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2349 printf '# ifdef HAVE_AGENT\n ",AGENT"\n# endif\n' >> ${h}
2350 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2351 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2352 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2353 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2354 printf '# ifdef HAVE_MLE\n ",MLE"\n# endif\n' >> ${h}
2355 printf '# ifdef HAVE_WCWIDTH\n " (WIDE GLYPHS)"\n# endif\n' >> ${h}
2356 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2357 printf '# ifdef HAVE_KEY_BINDINGS\n ",KEY-BINDINGS"\n# endif\n' >> ${h}
2358 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2359 printf '# ifdef HAVE_TERMINFO\n " (terminfo(5))"\n# endif\n' >> ${h}
2360 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2361 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2362 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2363 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2364 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2365 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2366 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2367 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2368 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2369 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2370 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2372 # Create the real mk.mk
2373 # Note we cannout use explicit ./ filename prefix for source and object
2374 # pathnames because of a bug in bmake(1)
2375 ${rm} -rf ${tmp0}.* ${tmp0}*
2376 printf 'OBJ_SRC = ' >> ${mk}
2377 if feat_no AMALGAMATION; then
2378 for i in `printf '%s\n' *.c | ${sort}`; do
2379 if [ "${i}" = privsep.c ]; then
2380 continue
2382 printf "${i} " >> ${mk}
2383 done
2384 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2385 else
2386 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2388 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2389 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2390 printf '# undef _CONFIG_H\n' >> ${h}
2391 printf '# define _CONFIG_H 2\n' >> ${h}
2392 for i in `printf '%s\n' *.c | ${sort}`; do
2393 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2394 [ "${i}" = privsep.c ]; then
2395 continue
2397 printf "${i} " >> ${mk}
2398 printf "# include \"${i}\"\n" >> ${h}
2399 done
2400 echo >> ${mk}
2401 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2402 echo '#else' >> ${h}
2405 printf '#endif /* n_CONFIG_H */\n' >> ${h}
2407 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2408 echo "INCS = `${cat} ${inc}`" >> ${mk}
2409 echo >> ${mk}
2410 ${cat} ./mk-mk.in >> ${mk}
2412 ## Finished!
2414 ${cat} > ${tmp2}.c << \!
2415 #include "config.h"
2417 :The following optional features are enabled:
2418 #ifdef HAVE_SETLOCALE
2419 : + Locale support: Printable characters depend on the environment
2420 # ifdef HAVE_C90AMEND1
2421 : + Multibyte character support
2422 # endif
2423 # ifdef HAVE_NL_LANGINFO
2424 : + Automatic detection of terminal character set
2425 # endif
2426 #endif
2427 #ifdef HAVE_ICONV
2428 : + Character set conversion using iconv()
2429 #endif
2430 #ifdef HAVE_SOCKETS
2431 : + Network support
2432 #endif
2433 #ifdef HAVE_SSL
2434 # ifdef HAVE_OPENSSL
2435 : + S/MIME and SSL/TLS (OpenSSL)
2436 # endif
2437 # ifdef HAVE_SSL_ALL_ALGORITHMS
2438 : + + Support for more ("all") digest and cipher algorithms
2439 # endif
2440 #endif
2441 #ifdef HAVE_SMTP
2442 : + SMTP protocol
2443 #endif
2444 #ifdef HAVE_POP3
2445 : + POP3 protocol
2446 #endif
2447 #ifdef HAVE_GSSAPI
2448 : + GSS-API authentication
2449 #endif
2450 #ifdef HAVE_MD5
2451 : + MD5 message digest (APOP, CRAM-MD5)
2452 #endif
2453 #ifdef HAVE_NETRC
2454 : + .netrc file support
2455 #endif
2456 #ifdef HAVE_AGENT
2457 : + Password query through agent
2458 #endif
2459 #ifdef HAVE_IDNA
2460 : + IDNA (internationalized domain names for applications) support
2461 #endif
2462 #ifdef HAVE_IMAP_SEARCH
2463 : + IMAP-style search expressions
2464 #endif
2465 #ifdef HAVE_REGEX
2466 : + Regular expression support (searches, conditional expressions etc.)
2467 #endif
2468 #if defined HAVE_READLINE || defined HAVE_MLE
2469 # ifdef HAVE_READLINE
2470 : + Command line editing via readline(3)
2471 # else
2472 # ifdef HAVE_WCWIDTH
2473 : + Command line editing via M(ailx)-L(ine)-E(ditor) (wide glyph support)
2474 # else
2475 : + Command line editing via M(ailx)-L(ine)-E(ditor) (no wide glyph support)
2476 # endif
2477 # endif
2478 # ifdef HAVE_HISTORY
2479 : + + History management
2480 # endif
2481 # ifdef HAVE_KEY_BINDINGS
2482 : + + Configurable key bindings
2483 # endif
2484 #endif
2485 #ifdef HAVE_TERMCAP
2486 # ifdef HAVE_TERMINFO
2487 : + Terminal capability queries (terminfo(5))
2488 # else
2489 : + Terminal capability queries (termcap(5))
2490 # endif
2491 #endif
2492 #ifdef HAVE_SPAM
2493 : + Spam management
2494 # ifdef HAVE_SPAM_SPAMC
2495 : + + Via spamc(1) (of spamassassin(1))
2496 # endif
2497 # ifdef HAVE_SPAM_SPAMD
2498 : + + Directly via spamd(1) (of spamassassin(1))
2499 # endif
2500 # ifdef HAVE_SPAM_FILTER
2501 : + + Via freely configurable *spam-filter-XY*s
2502 # endif
2503 #endif
2504 #ifdef HAVE_DOCSTRINGS
2505 : + Documentation summary strings
2506 #endif
2507 #ifdef HAVE_QUOTE_FOLD
2508 : + Extended *quote-fold*ing
2509 #endif
2510 #ifdef HAVE_FILTER_HTML_TAGSOUP
2511 : + Builtin HTML-to-text filter (for display purposes, primitive)
2512 #endif
2513 #ifdef HAVE_COLOUR
2514 : + Coloured message display (simple)
2515 #endif
2516 #ifdef HAVE_DOTLOCK
2517 : + Dotlock files and privilege-separated file dotlock program
2518 #endif
2520 :The following optional features are disabled:
2521 #ifndef HAVE_SETLOCALE
2522 : - Locale support: Only ASCII characters are recognized
2523 #endif
2524 # ifndef HAVE_C90AMEND1
2525 : - Multibyte character support
2526 # endif
2527 # ifndef HAVE_NL_LANGINFO
2528 : - Automatic detection of terminal character set
2529 # endif
2530 #ifndef HAVE_ICONV
2531 : - Character set conversion using iconv()
2532 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2533 #endif
2534 #ifndef HAVE_SOCKETS
2535 : - Network support
2536 #endif
2537 #ifndef HAVE_SSL
2538 : - S/MIME and SSL/TLS
2539 #else
2540 # ifndef HAVE_SSL_ALL_ALGORITHMS
2541 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2542 # endif
2543 #endif
2544 #ifndef HAVE_SMTP
2545 : - SMTP protocol
2546 #endif
2547 #ifndef HAVE_POP3
2548 : - POP3 protocol
2549 #endif
2550 #ifndef HAVE_GSSAPI
2551 : - GSS-API authentication
2552 #endif
2553 #ifndef HAVE_MD5
2554 : - MD5 message digest (APOP, CRAM-MD5)
2555 #endif
2556 #ifndef HAVE_NETRC
2557 : - .netrc file support
2558 #endif
2559 #ifndef HAVE_AGENT
2560 : - Password query through agent
2561 #endif
2562 #ifndef HAVE_IDNA
2563 : - IDNA (internationalized domain names for applications) support
2564 #endif
2565 #ifndef HAVE_IMAP_SEARCH
2566 : - IMAP-style search expressions
2567 #endif
2568 #ifndef HAVE_REGEX
2569 : - Regular expression support
2570 #endif
2571 #if !defined HAVE_READLINE && !defined HAVE_MLE
2572 : - Command line editing and history
2573 #else
2574 # ifndef HAVE_HISTORY
2575 : + (Command line editing) - History management
2576 # endif
2577 # ifndef HAVE_KEY_BINDINGS
2578 : + (Command line editing) - Configurable key bindings
2579 # endif
2580 #endif
2581 #ifndef HAVE_TERMCAP
2582 : - Terminal capability queries
2583 #endif
2584 #ifndef HAVE_SPAM
2585 : - Spam management
2586 #endif
2587 #ifndef HAVE_DOCSTRINGS
2588 : - Documentation summary strings
2589 #endif
2590 #ifndef HAVE_QUOTE_FOLD
2591 : - Extended *quote-fold*ing
2592 #endif
2593 #ifndef HAVE_FILTER_HTML_TAGSOUP
2594 : - Builtin HTML-to-text filter (for display purposes, primitive)
2595 #endif
2596 #ifndef HAVE_COLOUR
2597 : - Coloured message display (simple)
2598 #endif
2599 #ifndef HAVE_DOTLOCK
2600 : - Dotlock files and privilege-separated file dotlock program
2601 #endif
2603 #if !defined HAVE_WORDEXP || !defined HAVE_FCHDIR ||\
2604 defined HAVE_DEBUG || defined HAVE_DEVEL
2605 :Remarks:
2606 # ifndef HAVE_WORDEXP
2607 : . WARNING: the function wordexp(3) could not be found.
2608 : _ This means that echo(1) will be used via the sh(1)ell in order
2609 : _ to expand shell meta characters in filenames, which is a potential
2610 : _ security hole. Consider to either upgrade your system or set the
2611 : _ *SHELL* variable to some safe(r) wrapper script.
2612 : _ P.S.: the codebase is in transition away from wordexp(3) to some
2613 : _ safe (restricted) internal mechanism, see "COMMANDS" manual, read
2614 : _ about shell word expression in its introduction for more on that.
2615 # endif
2616 # ifndef HAVE_FCHDIR
2617 : . The function fchdir(2) could not be found. We will use chdir(2)
2618 : _ instead. This is not a problem unless the current working
2619 : _ directory is changed while this program is inside of it.
2620 # endif
2621 # ifdef HAVE_DEBUG
2622 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2623 # endif
2624 # ifdef HAVE_DEVEL
2625 : . Computers do not blunder.
2626 # endif
2628 #endif /* Remarks */
2629 :Setup:
2630 : . System-wide resource file: SYSCONFDIR/SYSCONFRC
2631 : . bindir: BINDIR
2632 #ifdef HAVE_DOTLOCK
2633 : . libexecdir: LIBEXECDIR
2634 #endif
2635 : . mandir: MANDIR
2636 : . sendmail(1): VAL_SENDMAIL (argv[0] = VAL_SENDMAIL_PROGNAME)
2637 : . Mail spool directory: MAILSPOOL
2641 ${make} -f ${makefile} ${tmp2}.x
2642 < ${tmp2}.x ${sed} -e '/^[^:]/d; /^$/d; s/^://' |
2643 while read l; do
2644 msg "${l}"
2645 done
2647 # s-it-mode