FIX: really_rewind() for pre POSIX Issue 7
[s-mailx.git] / mk-conf.sh
blobd3d2fd3d1c67a3a27946c9cb37086f40aefc1733
1 #!/bin/sh -
2 #@ Please see `INSTALL' and `make.rc' instead.
4 LC_ALL=C
5 export LC_ALL
7 option_reset() {
8 WANT_ICONV=0
9 WANT_SOCKETS=0
10 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
11 WANT_SMTP=0 WANT_POP3=0 WANT_IMAP=0
12 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
13 #WANT_MD5=0
14 WANT_IDNA=0
15 WANT_IMAP_SEARCH=0
16 WANT_REGEX=0
17 WANT_READLINE=0 WANT_EDITLINE=0 WANT_NCL=0
18 WANT_TERMCAP=0
19 WANT_ERRORS=0
20 WANT_SPAM_SPAMC=0 WANT_SPAM_SPAMD=0 WANT_SPAM_FILTER=0
21 WANT_DOCSTRINGS=0
22 WANT_QUOTE_FOLD=0
23 WANT_FILTER_HTML_TAGSOUP=0
24 WANT_COLOUR=0
25 WANT_DOTLOCK=0
28 option_maximal() {
29 WANT_ICONV=require
30 WANT_SOCKETS=1
31 WANT_SSL=1 WANT_ALL_SSL_ALGORITHMS=1
32 WANT_SMTP=1 WANT_POP3=1 WANT_IMAP=1
33 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
34 #WANT_MD5=1
35 WANT_IDNA=1
36 WANT_IMAP_SEARCH=1
37 WANT_REGEX=require
38 WANT_NCL=1
39 WANT_HISTORY=1 WANT_TABEXPAND=1
40 WANT_TERMCAP=1
41 WANT_ERRORS=1
42 WANT_SPAM_SPAMC=1 WANT_SPAM_SPAMD=1 WANT_SPAM_FILTER=1
43 WANT_DOCSTRINGS=1
44 WANT_QUOTE_FOLD=1
45 WANT_FILTER_HTML_TAGSOUP=1
46 WANT_COLOUR=1
47 WANT_DOTLOCK=require
50 # Predefined CONFIG= urations take precedence over anything else
51 if [ -n "${CONFIG}" ]; then
52 case "${CONFIG}" in
53 [nN][uU][lL][lL])
54 option_reset
56 [nN][uU][lL][lL][iI])
57 option_reset
58 WANT_ICONV=require
60 [mM][iI][nN][iI][mM][aA][lL])
61 option_reset
62 WANT_ICONV=1
63 WANT_REGEX=1
64 WANT_DOTLOCK=require
66 [mM][eE][dD][iI][uU][mM])
67 option_reset
68 WANT_ICONV=require
69 WANT_IDNA=1
70 WANT_REGEX=1
71 WANT_NCL=1
72 WANT_HISTORY=1
73 WANT_ERRORS=1
74 WANT_SPAM_FILTER=1
75 WANT_DOCSTRINGS=1
76 WANT_COLOUR=1
77 WANT_DOTLOCK=require
79 [nN][eE][tT][sS][eE][nN][dD])
80 option_reset
81 WANT_ICONV=require
82 WANT_SOCKETS=1
83 WANT_SSL=require
84 WANT_SMTP=require
85 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
86 WANT_IDNA=1
87 WANT_REGEX=1
88 WANT_NCL=1
89 WANT_HISTORY=1
90 WANT_DOCSTRINGS=1
91 WANT_COLOUR=1
92 WANT_DOTLOCK=require
94 [mM][aA][xX][iI][mM][aA][lL])
95 option_reset
96 option_maximal
98 [dD][eE][vV][eE][lL])
99 WANT_DEVEL=1 WANT_DEBUG=1 WANT_NYD2=1
100 option_maximal
102 [oO][dD][eE][vV][eE][lL])
103 WANT_DEVEL=1
104 option_maximal
107 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
108 echo >&2 'Possible values: NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
109 exit 1
111 esac
114 # Inter-relationships
115 option_update() {
116 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
117 WANT_SOCKETS=0
119 if feat_no SOCKETS; then
120 if feat_require SMTP; then
121 msg 'ERROR: need SOCKETS for required feature SMTP'
122 config_exit 13
124 if feat_require POP3; then
125 msg 'ERROR: need SOCKETS for required feature POP3'
126 config_exit 13
128 if feat_require IMAP; then
129 msg "ERROR: need SOCKETS for required feature IMAP\\n"
130 config_exit 13
132 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
133 WANT_SMTP=0 WANT_POP3=0 WANT_IMAP=0
134 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
136 if feat_no SMTP && feat_no IMAP; then
137 WANT_GSSAPI=0
140 if feat_no READLINE && feat_no EDITLINE && feat_no NCL; then
141 WANT_HISTORY=0 WANT_TABEXPAND=0
144 # If we don't need MD5 leave it alone
145 if feat_no SOCKETS; then
146 WANT_MD5=0
149 if feat_yes DEVEL; then
150 WANT_DEBUG=1
152 if feat_yes DEBUG; then
153 WANT_NOALLOCA=1 WANT_DEVEL=1
157 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
158 # via path_check() later on once possible
160 # TODO cc_maxopt is brute simple, we should compile test program and dig real
161 # compiler versions for known compilers, then be more specific
162 cc_maxopt=100
163 _CFLAGS= _LDFLAGS=
165 os_early_setup() {
166 i="${OS:-`uname -s`}"
168 if [ ${i} = SunOS ]; then
169 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
170 _os_early_setup_sunos
174 os_setup() {
175 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
176 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
177 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
178 msg 'Operating system is "%s"' ${OS}
180 if [ ${OS} = sunos ]; then
181 msg ' . have special SunOS / Solaris "setup" rules ...'
182 _os_setup_sunos
183 elif [ ${OS} = unixware ]; then
184 msg ' . have special UnixWare environmental rules ...'
185 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
186 CC=cc
187 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
189 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
190 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
191 export CC CFLAGS LDFLAGS
192 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
194 elif [ -n "${VERBOSE}" ]; then
195 msg ' . no special treatment for this system necessary or known'
198 # Sledgehammer: better set _GNU_SOURCE
199 # And in general: oh, boy!
200 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
201 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
202 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
203 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
205 # On pkgsrc(7) systems automatically add /usr/pkg/*
206 if [ -d /usr/pkg ]; then
207 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
208 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
212 _os_early_setup_sunos() {
213 # According to standards(5), this is what we need to do
214 if [ -d /usr/xpg4 ]; then :; else
215 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
216 config_exit 1
218 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
219 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
220 export PATH
223 _os_setup_sunos() {
224 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
225 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
227 # Include packages
228 if [ -d /opt/csw ]; then
229 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
230 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
233 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
234 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
236 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
237 if [ -x "${cksum}" ]; then :; else
238 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
239 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
240 msg 'ERROR: However, we do so only for tests.'
241 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
242 config_exit 1
245 if feat_yes AUTOCC; then
246 if command -v cc >/dev/null 2>&1; then
247 CC=cc
248 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
250 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
251 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
252 export CC CFLAGS LDFLAGS
253 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
254 else
255 # Assume gcc(1)
256 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
261 # Check out compiler ($CC) and -flags ($CFLAGS)
262 cc_setup() {
263 # Even though it belongs into cc_flags we will try to compile and link
264 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
265 # ADDCFLAGS/ADDLDFLAGS
266 if feat_no AUTOCC; then
267 _cc_default
268 # Ensure those don't do any harm
269 ADDCFLAGS= ADDLDFLAGS=
270 export ADDCFLAGS ADDLDFLAGS
271 return
272 else
273 CFLAGS= LDFLAGS=
274 export CFLAGS LDFLAGS
277 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
279 printf >&2 'Searching for a usable C compiler .. $CC='
280 if { i="`command -v clang`"; }; then
281 CC=${i}
282 elif { i="`command -v gcc`"; }; then
283 CC=${i}
284 elif { i="`command -v c99`"; }; then
285 CC=${i}
286 elif { i="`command -v tcc`"; }; then
287 CC=${i}
288 elif { i="`command -v pcc`"; }; then
289 CC=${i}
290 else
291 if [ "${CC}" = cc ]; then
293 elif { i="`command -v c89`"; }; then
294 CC=${i}
295 else
296 printf >&2 'boing booom tschak\n'
297 msg 'ERROR: I cannot find a compiler!'
298 msg ' Neither of clang(1), gcc(1), tcc(1), c89(1) and c99(1).'
299 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
300 config_exit 1
303 printf >&2 -- '"%s"\n' "${CC}"
304 export CC
307 _cc_default() {
308 if [ -z "${CC}" ]; then
309 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
310 config_exit 1
313 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
315 else
316 msg 'Using C compiler $CC="%s"' "${CC}"
320 cc_flags() {
321 if feat_yes AUTOCC; then
322 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
323 cc_check_silent=1
324 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
325 else
326 cc_check_silent=
327 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
330 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
331 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
332 msg ' . have special tcc(1) environmental rules ...'
333 _cc_flags_tcc
334 else
335 # As of pcc CVS 2016-04-02, stack protection support is announced but
336 # will break if used on Linux
337 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
338 force_no_stackprot=1
340 _cc_flags_generic
343 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
344 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
345 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
346 else
347 if feat_no DEBUG; then
348 CFLAGS="-DNDEBUG ${CFLAGS}"
351 msg ''
352 export CFLAGS LDFLAGS
355 _cc_flags_tcc() {
356 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
357 _CFLAGS= _LDFLAGS=
359 cc_check -Wall
360 cc_check -Wextra
361 cc_check -pedantic
363 if feat_yes DEBUG; then
364 # May have problems to find libtcc cc_check -b
365 cc_check -g
368 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
369 unset __cflags __ldflags
372 _cc_flags_generic() {
373 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
374 _CFLAGS= _LDFLAGS=
375 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
377 # Check -g first since some others may rely upon -g / optim. level
378 if feat_yes DEBUG; then
379 cc_check -O
380 cc_check -g
381 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
383 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
385 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
387 else
388 cc_check -O
391 if feat_yes DEVEL && cc_check -Weverything; then
393 else
394 cc_check -Wall
395 cc_check -Wextra
396 cc_check -Wbad-function-cast
397 cc_check -Wcast-align
398 cc_check -Wcast-qual
399 cc_check -Winit-self
400 cc_check -Wmissing-prototypes
401 cc_check -Wshadow
402 cc_check -Wunused
403 cc_check -Wwrite-strings
404 cc_check -Wno-long-long
406 cc_check -pedantic
408 if feat_yes AMALGAMATION && feat_no DEVEL; then
409 cc_check -Wno-unused-function
411 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
413 cc_check -fno-unwind-tables
414 cc_check -fno-asynchronous-unwind-tables
415 cc_check -fstrict-aliasing
416 if cc_check -fstrict-overflow && feat_yes DEVEL; then
417 cc_check -Wstrict-overflow=5
420 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
421 if [ -z "${force_no_stackprot}" ]; then
422 if cc_check -fstack-protector-strong ||
423 cc_check -fstack-protector-all; then
424 cc_check -D_FORTIFY_SOURCE=2
426 else
427 msg 'Not checking for -fstack-protector compiler option,'
428 msg 'since that caused errors in a "similar" configuration.'
429 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
433 if feat_yes AMALGAMATION; then
434 cc_check -pipe
437 # LD (+ dependend CC)
439 if feat_yes DEVEL; then
440 _ccfg=${_CFLAGS}
441 # -fsanitize=address
442 #if cc_check -fsanitize=memory &&
443 # ld_check -fsanitize=memory &&
444 # cc_check -fsanitize-memory-track-origins=2 &&
445 # ld_check -fsanitize-memory-track-origins=2; then
447 #else
448 # _CFLAGS=${_ccfg}
452 ld_check -Wl,-z,relro
453 ld_check -Wl,-z,now
454 ld_check -Wl,-z,noexecstack
456 # Address randomization
457 _ccfg=${_CFLAGS}
458 if cc_check -fPIE || cc_check -fpie; then
459 ld_check -pie || _CFLAGS=${_ccfg}
461 unset _ccfg
463 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
464 unset __cflags __ldflags
467 ## -- >8 -- 8< -- ##
469 ## Notes:
470 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
471 ## redirection, so use "printf '' >" instead
473 ## Very first: we undergo several states regarding I/O redirection etc.,
474 ## but need to deal with option updates from within all. Since all the
475 ## option stuff should be above the scissor line, define utility functions
476 ## and redefine them as necessary.
477 ## And, since we have those functions, simply use them for whatever
479 config_exit() {
480 exit ${1}
483 msg() {
484 fmt=${1}
485 shift
486 printf >&2 -- "${fmt}\\n" "${@}"
489 ## First of all, create new configuration and check wether it changed
491 rc=./make.rc
492 lst=./config.lst
493 h=./config.h h_name=config.h
494 mk=./mk.mk
496 newlst=./config.lst-new
497 newmk=./config.mk-new
498 newh=./config.h-new
499 tmp0=___tmp
500 tmp=./${tmp0}1$$
501 tmp2=./${tmp0}2$$
503 t1=ten10one1ten10one1
504 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
505 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
506 ) > /dev/null 2>&1; then
507 good_shell=1
508 else
509 unset good_shell
511 unset t1
513 # We need some standard utilities
514 unset -f command
515 check_tool() {
516 n=${1} i=${2} opt=${3:-0}
517 # Evaluate, just in case user comes in with shell snippets (..well..)
518 eval i="${i}"
519 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
520 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
521 eval ${n}=${i}
522 return 0
524 if [ ${opt} -eq 0 ]; then
525 msg 'ERROR: no trace of utility "%s"' "${n}"
526 config_exit 1
528 return 1
531 # Very easy checks for the operating system in order to be able to adjust paths
532 # or similar very basic things which we need to be able to go at all
533 os_early_setup
535 # Check those tools right now that we need before including $rc
536 msg 'Checking for basic utility set'
537 check_tool awk "${awk:-`command -v awk`}"
538 check_tool rm "${rm:-`command -v rm`}"
539 check_tool tr "${tr:-`command -v tr`}"
541 # Our feature check environment
542 feat_val_no() {
543 [ "x${1}" = x0 ] ||
544 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
547 feat_val_yes() {
548 [ "x${1}" = x1 ] ||
549 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
550 [ "x${1}" = xrequire ]
553 feat_val_require() {
554 [ "x${1}" = xrequire ]
557 _feat_check() {
558 eval i=\$WANT_${1}
559 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
560 if feat_val_no "${i}"; then
561 return 1
562 elif feat_val_yes "${i}"; then
563 return 0
564 else
565 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
566 "${1}" "${i}"
567 config_exit 11
571 feat_yes() {
572 _feat_check ${1}
575 feat_no() {
576 _feat_check ${1} && return 1
577 return 0
580 feat_require() {
581 eval i=\$WANT_${1}
582 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
583 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
586 feat_bail_required() {
587 if feat_require ${1}; then
588 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
589 config_exit 13
591 eval WANT_${1}=0
592 option_update # XXX this is rather useless here (dependency chain..)
595 # Include $rc, but only take from it what wasn't overwritten by the user from
596 # within the command line or from a chosen fixed CONFIG=
597 # Note we leave alone the values
598 trap "exit 1" HUP INT TERM
599 trap "${rm} -f ${tmp}" EXIT
601 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
602 ${rm} -f ${tmp}
603 # We want read(1) to perform backslash escaping in order to be able to use
604 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
605 # VMs (see [fa2e248]), Aharon Robbins suggested the following
606 < ${rc} ${awk} 'BEGIN{line = ""}{
607 gsub(/^[[:space:]]+/, "", $0)
608 gsub(/[[:space:]]+$/, "", $0)
609 if(gsub(/\\$/, "", $0)){
610 line = line $0
611 next
612 }else
613 line = line $0
614 if(index(line, "#") == 1){
615 line = ""
616 }else if(length(line)){
617 print line
618 line = ""
620 }' |
621 while read line; do
622 if [ -n "${good_shell}" ]; then
623 i=${line%%=*}
624 else
625 i=`${awk} -v LINE="${line}" 'BEGIN{
626 gsub(/=.*$/, "", LINE)
627 print LINE
630 if [ "${i}" = "${line}" ]; then
631 msg 'ERROR: invalid syntax in "%s"' "${line}"
632 continue
635 eval j="\$${i}" jx="\${${i}+x}"
636 if [ -n "${j}" ] || [ "${jx}" = x ]; then
637 : # Yet present
638 else
639 j=`${awk} -v LINE="${line}" 'BEGIN{
640 gsub(/^[^=]*=/, "", LINE)
641 gsub(/^\"*/, "", LINE)
642 gsub(/\"*$/, "", LINE)
643 print LINE
646 echo "${i}=\"${j}\""
647 done > ${tmp}
648 # Reread the mixed version right now
649 . ./${tmp}
650 printf >&2 'done\n'
652 # We need to know about that now, in order to provide utility overwrites etc.
653 os_setup
655 msg 'Checking for remaining set of utilities'
656 check_tool grep "${grep:-`command -v grep`}"
658 # Before we step ahead with the other utilities perform a path cleanup first.
659 # We need this function also for C_INCLUDE_PATH and LD_LIBRARY_PATH
660 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
661 path_check() {
662 varname=${1} addflag=${2} flagvarname=${3}
663 j=${IFS}
664 IFS=:
665 eval "set -- \$${1}"
666 IFS=${j}
667 j= k= y= z=
668 for i
670 [ -z "${i}" ] && continue
671 [ -d "${i}" ] || continue
672 if [ -n "${j}" ]; then
673 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
675 else
676 y="${y} :${i}:"
677 j="${j}:${i}"
678 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
680 else
681 y=" :${i}:"
682 j="${i}"
683 [ -n "${addflag}" ] && k="${addflag}${i}"
685 done
686 eval "${varname}=\"${j}\""
687 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
688 unset varname
691 path_check PATH
693 # awk(1) above
694 check_tool cat "${cat:-`command -v cat`}"
695 check_tool chmod "${chmod:-`command -v chmod`}"
696 check_tool cp "${cp:-`command -v cp`}"
697 check_tool cmp "${cmp:-`command -v cmp`}"
698 # grep(1) above
699 check_tool mkdir "${mkdir:-`command -v mkdir`}"
700 check_tool mv "${mv:-`command -v mv`}"
701 # rm(1) above
702 check_tool sed "${sed:-`command -v sed`}"
703 check_tool sort "${sort:-`command -v sort`}"
704 check_tool tee "${tee:-`command -v tee`}"
706 check_tool chown "${chown:-`command -v chown`}" 1 ||
707 check_tool chown "/sbin/chown" 1 ||
708 check_tool chown "/usr/sbin/chown"
710 check_tool make "${MAKE:-`command -v make`}"
711 MAKE=${make}
712 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
713 HAVE_STRIP=1 || HAVE_STRIP=0
715 # For ./cc-test.sh only
716 check_tool cksum "${cksum:-`command -v cksum`}"
718 # Update WANT_ options now, in order to get possible inter-dependencies right
719 option_update
721 # (No functions since some shells loose non-exported variables in traps)
722 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
723 trap "trap \"\" HUP INT TERM EXIT;\
724 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newh}" EXIT
726 # Our configuration options may at this point still contain shell snippets,
727 # we need to evaluate them in order to get them expanded, and we need those
728 # evaluated values not only in our new configuration file, but also at hand..
729 printf >&2 'Evaluating all configuration items ... '
730 ${rm} -f ${newlst} ${newmk} ${newh}
731 exec 5<&0 6>&1 <${tmp} >${newlst}
732 while read line; do
734 if [ -n "${good_shell}" ]; then
735 i=${line%%=*}
736 [ "${i}" != "${i#WANT_}" ] && z=1
737 else
738 i=`${awk} -v LINE="${line}" 'BEGIN{
739 gsub(/=.*$/, "", LINE);\
740 print LINE
742 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
747 eval j=\$${i}
748 if [ -n "${z}" ]; then
749 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
750 if [ -z "${j}" ] || feat_val_no "${j}"; then
752 printf "/*#define ${i}*/\n" >> ${newh}
753 elif feat_val_yes "${j}"; then
754 if feat_val_require "${j}"; then
755 j=require
756 else
759 printf "#define ${i}\n" >> ${newh}
760 else
761 msg 'ERROR: cannot parse <%s>' "${line}"
762 config_exit 1
764 else
765 printf "#define ${i} \"${j}\"\n" >> ${newh}
767 printf "${i} = ${j}\n" >> ${newmk}
768 printf "${i}=${j}\n"
769 eval "${i}=\"${j}\""
770 done
771 exec 0<&5 1>&6 5<&- 6<&-
772 printf >&2 'done\n'
774 # Add the known utility and some other variables
775 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
776 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
778 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
779 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
780 if feat_yes DOTLOCK; then
781 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
782 else
783 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
786 for i in \
787 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
788 MAKE make strip \
789 cksum; do
790 eval j=\$${i}
791 printf "${i} = ${j}\n" >> ${newmk}
792 printf "${i}=${j}\n" >> ${newlst}
793 done
795 # Build a basic set of INCS and LIBS according to user environment.
796 path_check C_INCLUDE_PATH -I _INCS
797 INCS="${INCS} ${_INCS}"
798 path_check LD_LIBRARY_PATH -L _LIBS
799 LIBS="${LIBS} ${_LIBS}"
800 unset _INCS _LIBS
801 export C_INCLUDE_PATH LD_LIBRARY_PATH
803 if [ -n "${need_R_ldflags}" ]; then
804 i=${IFS}
805 IFS=:
806 set -- ${LD_LIBRARY_PATH}
807 IFS=${i}
808 for i
810 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
811 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
812 done
813 export LDFLAGS
816 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
818 cc_setup
820 ${cat} > ${tmp}.c << \!
821 #include <stdio.h>
822 #include <string.h>
823 static void doit(char const *s);
825 main(int argc, char **argv){
826 (void)argc;
827 (void)argv;
828 doit("Hello world");
829 return 0;
831 static void
832 doit(char const *s){
833 char buf[12];
834 strcpy(buf, s);
835 puts(s);
839 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
840 -o ${tmp2} ${tmp}.c ${LIBS}; then
842 else
843 msg 'ERROR: i cannot compile a "Hello world" via'
844 msg ' %s' \
845 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
846 msg 'ERROR: Please read INSTALL, rerun'
847 config_exit 1
850 cc_check() {
851 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
852 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
853 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
854 _CFLAGS="${_CFLAGS} ${1}"
855 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
856 return 0
858 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
859 return 1
862 ld_check() {
863 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
864 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1} ${ADDLDFLAGS} \
865 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
866 _LDFLAGS="${_LDFLAGS} ${1}"
867 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
868 return 0
870 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
871 return 1
874 cc_flags
876 for i in \
877 INCS LIBS \
878 ; do
879 eval j=\$${i}
880 printf -- "${i}=${j}\n" >> ${newlst}
881 done
882 for i in \
883 CC \
884 CFLAGS \
885 LDFLAGS \
886 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
887 OSFULLSPEC \
888 ; do
889 eval j=\$${i}
890 printf -- "${i} = ${j}\n" >> ${newmk}
891 printf -- "${i}=${j}\n" >> ${newlst}
892 done
894 # Now finally check wether we already have a configuration and if so, wether
895 # all those parameters are still the same.. or something has actually changed
896 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
897 echo 'Configuration is up-to-date'
898 exit 0
899 elif [ -f ${lst} ]; then
900 echo 'Configuration has been updated..'
901 ( eval "${MAKE} -f ./mk.mk clean" )
902 echo
903 else
904 echo 'Shiny configuration..'
907 # Time to redefine helper 1
908 config_exit() {
909 ${rm} -f ${lst} ${h} ${mk}
910 exit ${1}
913 ${mv} -f ${newlst} ${lst}
914 ${mv} -f ${newh} ${h}
915 ${mv} -f ${newmk} ${mk}
917 ## Compile and link checking
919 tmp3=./${tmp0}3$$
920 log=./config.log
921 lib=./config.lib
922 inc=./config.inc
923 makefile=./config.mk
925 # (No function since some shells loose non-exported variables in traps)
926 trap "trap \"\" HUP INT TERM;\
927 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
928 trap "trap \"\" HUP INT TERM EXIT;\
929 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
931 # Time to redefine helper 2
932 msg() {
933 fmt=${1}
934 shift
935 printf "*** ${fmt}\\n" "${@}"
936 printf -- "${fmt}\\n" "${@}" >&5
938 msg_nonl() {
939 fmt=${1}
940 shift
941 printf "*** ${fmt}\\n" "${@}"
942 printf -- "${fmt}" "${@}" >&5
945 exec 5>&2 > ${log} 2>&1
947 echo "${LIBS}" > ${lib}
948 echo "${INCS}" > ${inc}
949 ${cat} > ${makefile} << \!
950 .SUFFIXES: .o .c .x .y
951 .c.o:
952 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
953 .c.x:
954 $(CC) -I./ $(XINCS) -E $< >$@
956 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
957 .y: ;
960 _check_preface() {
961 variable=$1 topic=$2 define=$3
963 echo '**********'
964 msg_nonl ' . %s ... ' "${topic}"
965 echo "/* checked ${topic} */" >> ${h}
966 ${rm} -f ${tmp} ${tmp}.o
967 echo '*** test program is'
968 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
969 #echo '*** the preprocessor generates'
970 #${make} -f ${makefile} ${tmp}.x
971 #${cat} ${tmp}.x
972 echo '*** results are'
975 compile_check() {
976 variable=$1 topic=$2 define=$3
978 _check_preface "${variable}" "${topic}" "${define}"
980 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
981 [ -f ./${tmp}.o ]; then
982 msg 'yes'
983 echo "${define}" >> ${h}
984 eval have_${variable}=yes
985 return 0
986 else
987 echo "/* ${define} */" >> ${h}
988 msg 'no'
989 eval unset have_${variable}
990 return 1
994 _link_mayrun() {
995 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
997 _check_preface "${variable}" "${topic}" "${define}"
999 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1000 XLIBS="${LIBS} ${libs}" ./${tmp} &&
1001 [ -f ./${tmp} ] &&
1002 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1003 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1004 msg 'yes'
1005 echo "${define}" >> ${h}
1006 LIBS="${LIBS} ${libs}"
1007 echo "${libs}" >> ${lib}
1008 INCS="${INCS} ${incs}"
1009 echo "${incs}" >> ${inc}
1010 eval have_${variable}=yes
1011 return 0
1012 else
1013 msg 'no'
1014 echo "/* ${define} */" >> ${h}
1015 eval unset have_${variable}
1016 return 1
1020 link_check() {
1021 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1024 run_check() {
1025 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1030 # May be multiline..
1031 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1033 if run_check clock_gettime 'clock_gettime(2)' \
1034 '#define HAVE_CLOCK_GETTIME' << \!
1035 #include <time.h>
1036 # include <errno.h>
1037 int main(void){
1038 struct timespec ts;
1040 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1041 return 0;
1042 return 1;
1045 then
1047 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1048 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1049 #include <time.h>
1050 # include <errno.h>
1051 int main(void){
1052 struct timespec ts;
1054 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1055 return 0;
1056 return 1;
1059 then
1061 elif run_check gettimeofday 'gettimeofday(2)' \
1062 '#define HAVE_GETTIMEOFDAY' << \!
1063 #include <stdio.h> /* For C89 NULL */
1064 #include <sys/time.h>
1065 # include <errno.h>
1066 int main(void){
1067 struct timeval tv;
1069 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1070 return 0;
1071 return 1;
1074 then
1076 else
1077 have_no_subsecond_time=1
1080 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1081 #include <pwd.h>
1082 #include <unistd.h>
1083 # include <errno.h>
1084 int main(void){
1085 struct passwd *pw;
1086 gid_t gid;
1087 uid_t uid;
1089 if((gid = getgid()) != 0)
1090 gid = getegid();
1091 if((uid = getuid()) != 0)
1092 uid = geteuid();
1093 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1094 return 1;
1095 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1096 return 1;
1097 return 0;
1100 then
1102 else
1103 msg 'ERROR: we require user and group info / database searches.'
1104 msg 'That much Unix we indulge ourselfs.'
1105 config_exit 1
1108 if link_check snprintf 'v?snprintf(3)' << \!
1109 #include <stdarg.h>
1110 #include <stdio.h>
1111 static void dome(char *buf, ...){
1112 va_list ap;
1114 va_start(ap, buf);
1115 vsnprintf(buf, 20, "%s", ap);
1116 va_end(ap);
1117 return;
1119 int main(void){
1120 char b[20];
1122 snprintf(b, sizeof b, "%s", "string");
1123 dome(b, "string");
1124 return 0;
1127 then
1129 else
1130 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1131 config_exit 1
1134 if link_check environ 'environ(3)' << \!
1135 #include <stdio.h> /* For C89 NULL */
1136 int main(void){
1137 extern char **environ;
1139 return environ[0] == NULL;
1142 then
1144 else
1145 msg 'ERROR: we require the environ(3) array for subprocess control.'
1146 config_exit 1
1149 if link_check termios 'termios.h and tc*(3) family' << \!
1150 #include <termios.h>
1151 int main(void){
1152 struct termios tios;
1154 tcgetattr(0, &tios);
1155 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1156 return 0;
1159 then
1161 else
1162 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1163 msg 'That much Unix we indulge ourselfs.'
1164 config_exit 1
1169 link_check mmap 'mmap(2)' '#define HAVE_MMAP' << \!
1170 #include <sys/types.h>
1171 #include <sys/mman.h>
1172 int main(void)
1174 mmap(0, 0, 0, 0, 0, 0);
1175 return 0;
1179 link_check mremap 'mremap(2)' '#define HAVE_MREMAP' << \!
1180 #include <sys/types.h>
1181 #include <sys/mman.h>
1182 int main(void)
1184 mremap(0, 0, 0, MREMAP_MAYMOVE);
1185 return 0;
1189 run_check pathconf 'pathconf(2)' '#define HAVE_PATHCONF' << \!
1190 #include <unistd.h>
1191 #include <errno.h>
1192 int main(void){
1193 int rv = 0;
1195 errno = 0;
1196 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1197 errno = 0;
1198 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1199 return rv;
1203 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1204 #include <fcntl.h>
1205 #include <unistd.h>
1206 # include <errno.h>
1207 int main(void){
1208 int fds[2];
1210 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1211 return 0;
1212 return 1;
1216 # We use this only then for now (need NOW+1)
1217 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1218 #include <fcntl.h> /* For AT_* */
1219 #include <sys/stat.h>
1220 # include <errno.h>
1221 int main(void){
1222 struct timespec ts[2];
1224 ts[0].tv_nsec = UTIME_NOW;
1225 ts[1].tv_nsec = UTIME_OMIT;
1226 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1227 return 0;
1228 return 1;
1234 # XXX Add POSIX check once standardized
1235 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1236 #include <stdlib.h>
1237 int main(void){
1238 arc4random();
1239 return 0;
1242 then
1244 elif [ -n "${have_no_subsecond_time}" ]; then
1245 msg 'ERROR: %s %s' 'without a native random' \
1246 'one of clock_gettime(2) and gettimeofday(2) is required.'
1247 config_exit 1
1250 link_check setenv 'setenv(3)/unsetenv(3)' '#define HAVE_SETENV' << \!
1251 #include <stdlib.h>
1252 int main(void){
1253 setenv("s-nail", "to be made nifty!", 1);
1254 unsetenv("s-nail");
1255 return 0;
1259 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1260 #include <stdio.h>
1261 int main(void){
1262 putc_unlocked('@', stdout);
1263 return 0;
1267 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1268 #include <unistd.h>
1269 int main(void){
1270 fchdir(0);
1271 return 0;
1275 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1276 #include <locale.h>
1277 int main(void){
1278 setlocale(LC_ALL, "");
1279 return 0;
1283 if [ "${have_setlocale}" = yes ]; then
1284 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1285 '#define HAVE_C90AMEND1' << \!
1286 #include <limits.h>
1287 #include <stdlib.h>
1288 #include <wchar.h>
1289 #include <wctype.h>
1290 int main(void){
1291 char mbb[MB_LEN_MAX + 1];
1292 wchar_t wc;
1294 iswprint(L'c');
1295 towupper(L'c');
1296 mbtowc(&wc, "x", 1);
1297 mbrtowc(&wc, "x", 1, NULL);
1298 wctomb(mbb, wc);
1299 return (mblen("\0", 1) == 0);
1303 if [ "${have_c90amend1}" = yes ]; then
1304 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1305 #include <wchar.h>
1306 int main(void){
1307 wcwidth(L'c');
1308 return 0;
1313 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1314 #include <langinfo.h>
1315 #include <stdlib.h>
1316 int main(void){
1317 nl_langinfo(DAY_1);
1318 return (nl_langinfo(CODESET) == NULL);
1321 fi # have_setlocale
1323 run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1324 #include <stdlib.h>
1325 int main(void){
1326 #if 1 /* TODO for now we use realpath(3) without NULL as 2nd arg! */
1327 /* (And note that on Linux tcc(1) otherwise didn't detect once tested! */
1328 char x_buf[4096], *x = realpath(".", x_buf);
1330 return (x != NULL) ? 0 : 1;
1331 #else
1332 char *x = realpath(".", NULL), *y = realpath("/", NULL);
1334 return (x != NULL && y != NULL) ? 0 : 1;
1335 #endif
1339 link_check wordexp 'wordexp(3)' '#define HAVE_WORDEXP' << \!
1340 #include <stdio.h> /* For C89 NULL */
1341 #include <wordexp.h>
1342 int main(void){
1343 wordexp(NULL, NULL, 0);
1344 return 0;
1350 if feat_yes DEBUG; then
1351 echo '#define HAVE_DEBUG' >> ${h}
1354 if feat_yes AMALGAMATION; then
1355 echo '#define HAVE_AMALGAMATION' >> ${h}
1358 if feat_no NOALLOCA; then
1359 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1360 # versions of alloca(3) since modern compilers just can't be trusted
1361 # not to overoptimize and silently break some code
1362 run_check alloca '__builtin_alloca()' \
1363 '#define HAVE_ALLOCA __builtin_alloca' << \!
1364 #include <stdio.h> /* For C89 NULL */
1365 int main(void){
1366 void *vp = __builtin_alloca(1);
1368 return (vp != NULL);
1373 if feat_yes DEVEL; then
1374 echo '#define HAVE_DEVEL' >> ${h}
1377 if feat_yes NYD2; then
1378 echo '#define HAVE_NYD2' >> ${h}
1383 if feat_yes DOTLOCK; then
1384 if run_check readlink 'readlink(2)' << \!
1385 #include <unistd.h>
1386 # include <errno.h>
1387 int main(void){
1388 char buf[128];
1390 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1391 return 0;
1392 return 1;
1395 then
1397 else
1398 feat_bail_required DOTLOCK
1402 if feat_yes DOTLOCK; then
1403 if run_check fchown 'fchown(2)' << \!
1404 #include <unistd.h>
1405 # include <errno.h>
1406 int main(void){
1407 if(!fchown(0, 0, 0) || errno != ENOSYS)
1408 return 0;
1409 return 1;
1412 then
1414 else
1415 feat_bail_required DOTLOCK
1421 if feat_yes ICONV; then
1422 ${cat} > ${tmp2}.c << \!
1423 #include <stdio.h> /* For C89 NULL */
1424 #include <iconv.h>
1425 int main(void){
1426 iconv_t id;
1428 id = iconv_open("foo", "bar");
1429 iconv(id, NULL, NULL, NULL, NULL);
1430 iconv_close(id);
1431 return 0;
1434 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1435 '#define HAVE_ICONV' ||
1436 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1437 '#define HAVE_ICONV' '-liconv' ||
1438 feat_bail_required ICONV
1439 else
1440 echo '/* WANT_ICONV=0 */' >> ${h}
1441 fi # feat_yes ICONV
1443 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1444 ${cat} > ${tmp2}.c << \!
1445 #include <sys/types.h>
1446 #include <sys/socket.h>
1447 #include <sys/un.h>
1448 # include <errno.h>
1449 int main(void){
1450 struct sockaddr_un soun;
1452 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1453 return 1;
1454 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1455 return 1;
1456 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1457 return 1;
1458 return 0;
1462 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1463 '#define HAVE_UNIX_SOCKETS' ||
1464 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1465 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1466 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1467 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1470 if feat_yes SOCKETS; then
1471 ${cat} > ${tmp2}.c << \!
1472 #include "config.h"
1473 #include <sys/types.h>
1474 #include <sys/socket.h>
1475 #include <netinet/in.h>
1476 # include <errno.h>
1477 int main(void){
1478 struct sockaddr s;
1480 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1481 return 1;
1482 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1483 return 1;
1484 return 0;
1488 < ${tmp2}.c run_check sockets 'sockets' \
1489 '#define HAVE_SOCKETS' ||
1490 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1491 '#define HAVE_SOCKETS' '-lnsl' ||
1492 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1493 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1494 feat_bail_required SOCKETS
1495 else
1496 echo '/* WANT_SOCKETS=0 */' >> ${h}
1497 fi # feat_yes SOCKETS
1499 if feat_yes SOCKETS; then
1500 link_check getaddrinfo 'getaddrinfo(3)' \
1501 '#define HAVE_GETADDRINFO' << \!
1502 #include "config.h"
1503 #include <sys/types.h>
1504 #include <sys/socket.h>
1505 #include <stdio.h>
1506 #include <netdb.h>
1507 int main(void){
1508 struct addrinfo a, *ap;
1509 int lrv;
1511 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1512 case EAI_NONAME:
1513 case EAI_SERVICE:
1514 default:
1515 fprintf(stderr, "%s\n", gai_strerror(lrv));
1516 case 0:
1517 break;
1519 return 0;
1524 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1525 compile_check arpa_inet_h '<arpa/inet.h>' \
1526 '#define HAVE_ARPA_INET_H' << \!
1527 #include "config.h"
1528 #include <sys/types.h>
1529 #include <sys/socket.h>
1530 #include <netdb.h>
1531 #include <netinet/in.h>
1532 #include <arpa/inet.h>
1535 ${cat} > ${tmp2}.c << \!
1536 #include "config.h"
1537 #include <sys/types.h>
1538 #include <sys/socket.h>
1539 #include <stdio.h>
1540 #include <string.h>
1541 #include <netdb.h>
1542 #include <netinet/in.h>
1543 #ifdef HAVE_ARPA_INET_H
1544 #include <arpa/inet.h>
1545 #endif
1546 int main(void){
1547 struct sockaddr_in servaddr;
1548 unsigned short portno;
1549 struct servent *ep;
1550 struct hostent *hp;
1551 struct in_addr **pptr;
1553 portno = 0;
1554 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1555 portno = (unsigned short)ep->s_port;
1557 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1558 pptr = (struct in_addr**)hp->h_addr_list;
1559 if(hp->h_addrtype != AF_INET)
1560 fprintf(stderr, "au\n");
1561 }else{
1562 switch(h_errno){
1563 case HOST_NOT_FOUND:
1564 case TRY_AGAIN:
1565 case NO_RECOVERY:
1566 case NO_DATA:
1567 break;
1568 default:
1569 fprintf(stderr, "au\n");
1570 break;
1574 memset(&servaddr, 0, sizeof servaddr);
1575 servaddr.sin_family = AF_INET;
1576 servaddr.sin_port = htons(portno);
1577 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1578 fprintf(stderr, "Would connect to %s:%d ...\n",
1579 inet_ntoa(**pptr), (int)portno);
1580 return 0;
1584 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1585 < ${tmp2}.c link_check gethostbyname \
1586 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1587 < ${tmp2}.c link_check gethostbyname \
1588 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1589 '' '-lsocket -lnsl' ||
1590 feat_bail_required SOCKETS
1593 feat_yes SOCKETS &&
1594 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1595 #include <sys/socket.h>
1596 #include <stdlib.h>
1597 # include <errno.h>
1598 int main(void){
1599 int sockfd = 3;
1601 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1602 errno == ENOSYS)
1603 return 1;
1604 return 0;
1608 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1609 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1610 #include <sys/socket.h>
1611 #include <stdlib.h>
1612 int main(void){
1613 struct timeval tv;
1614 int sockfd = 3;
1616 tv.tv_sec = 42;
1617 tv.tv_usec = 21;
1618 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1619 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1620 return 0;
1624 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1625 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1626 #include <sys/socket.h>
1627 #include <stdlib.h>
1628 int main(void){
1629 struct linger li;
1630 int sockfd = 3;
1632 li.l_onoff = 1;
1633 li.l_linger = 42;
1634 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1635 return 0;
1639 if feat_yes SSL; then
1640 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1641 '#define HAVE_SSL
1642 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1643 #include <openssl/ssl.h>
1644 #include <openssl/err.h>
1645 #include <openssl/x509v3.h>
1646 #include <openssl/x509.h>
1647 #include <openssl/rand.h>
1648 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1649 # error We need TLSv1.
1650 #endif
1651 int main(void){
1652 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1654 SSL_CTX_free(ctx);
1655 PEM_read_PrivateKey(0, 0, 0, 0);
1656 return 0;
1659 then
1661 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1662 '#define HAVE_SSL
1663 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1664 #include <openssl/ssl.h>
1665 #include <openssl/err.h>
1666 #include <openssl/x509v3.h>
1667 #include <openssl/x509.h>
1668 #include <openssl/rand.h>
1669 #if defined OPENSSL_NO_SSL3 &&\
1670 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1671 # error We need one of SSLv3 and TLSv1.
1672 #endif
1673 int main(void){
1674 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1676 SSL_CTX_free(ctx);
1677 PEM_read_PrivateKey(0, 0, 0, 0);
1678 return 0;
1681 then
1683 else
1684 feat_bail_required SSL
1687 if [ "${have_openssl}" = 'yes' ]; then
1688 compile_check stack_of 'OpenSSL STACK_OF()' \
1689 '#define HAVE_OPENSSL_STACK_OF' << \!
1690 #include <stdio.h> /* For C89 NULL */
1691 #include <openssl/ssl.h>
1692 #include <openssl/err.h>
1693 #include <openssl/x509v3.h>
1694 #include <openssl/x509.h>
1695 #include <openssl/rand.h>
1696 int main(void){
1697 STACK_OF(GENERAL_NAME) *gens = NULL;
1699 printf("%p", gens); /* to use it */
1700 return 0;
1704 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1705 '#define HAVE_OPENSSL_CONFIG' << \!
1706 #include <stdio.h> /* For C89 NULL */
1707 #include <openssl/conf.h>
1708 int main(void){
1709 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1710 CONF_modules_free();
1711 return 0;
1715 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1716 '#define HAVE_OPENSSL_CONF_CTX' << \!
1717 #include "config.h"
1718 #include <openssl/ssl.h>
1719 #include <openssl/err.h>
1720 int main(void){
1721 #if HAVE_OPENSSL < 10100
1722 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1723 #else
1724 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1725 #endif
1726 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1728 SSL_CONF_CTX_set_flags(cctx,
1729 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1730 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1731 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1732 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1733 SSL_CONF_CTX_finish(cctx);
1734 SSL_CONF_CTX_free(cctx);
1735 SSL_CTX_free(ctx);
1736 return 0;
1740 link_check rand_egd 'OpenSSL RAND_egd()' \
1741 '#define HAVE_OPENSSL_RAND_EGD' << \!
1742 #include <openssl/rand.h>
1743 int main(void){
1744 return RAND_egd("some.where") > 0;
1748 if feat_yes SSL_ALL_ALGORITHMS; then
1749 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1750 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1751 #include <openssl/evp.h>
1752 int main(void){
1753 OpenSSL_add_all_algorithms();
1754 EVP_get_cipherbyname("two cents i never exist");
1755 EVP_cleanup();
1756 return 0;
1759 then
1761 else
1762 feat_bail_required SSL_ALL_ALGORITHMS
1764 fi # SSL_ALL_ALGORITHMS
1766 if feat_yes MD5 && feat_no NOEXTMD5; then
1767 run_check openssl_md5 'MD5 digest in OpenSSL' \
1768 '#define HAVE_OPENSSL_MD5' << \!
1769 #include <stdlib.h>
1770 #include <string.h>
1771 #include <openssl/md5.h>
1772 int main(void){
1773 char const dat[] = "abrakadabrafidibus";
1774 char dig[16], hex[16 * 2];
1775 MD5_CTX ctx;
1776 size_t i, j;
1778 memset(dig, 0, sizeof(dig));
1779 memset(hex, 0, sizeof(hex));
1780 MD5_Init(&ctx);
1781 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1782 MD5_Final(dig, &ctx);
1784 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1785 for(i = 0; i < sizeof(hex) / 2; i++){
1786 j = i << 1;
1787 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1788 hex[++j] = hexchar(dig[i] & 0x0f);
1790 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1793 fi # feat_yes MD5 && feat_no NOEXTMD5
1795 else
1796 echo '/* WANT_SSL=0 */' >> ${h}
1797 fi # feat_yes SSL
1799 if feat_yes SMTP; then
1800 echo '#define HAVE_SMTP' >> ${h}
1801 else
1802 echo '/* WANT_SMTP=0 */' >> ${h}
1805 if feat_yes POP3; then
1806 echo '#define HAVE_POP3' >> ${h}
1807 else
1808 echo '/* WANT_POP3=0 */' >> ${h}
1811 if feat_yes IMAP; then
1812 echo '#define HAVE_IMAP' >> ${h}
1813 else
1814 echo '/* WANT_IMAP=0 */' >> ${h}
1817 if feat_yes GSSAPI; then
1818 ${cat} > ${tmp2}.c << \!
1819 #include <gssapi/gssapi.h>
1820 int main(void){
1821 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1822 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1823 return 0;
1826 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1828 if command -v krb5-config >/dev/null 2>&1; then
1829 i=`command -v krb5-config`
1830 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1831 GSS_INCS="`CFLAGS= ${i} --cflags`"
1832 i='GSS-API via krb5-config(1)'
1833 else
1834 GSS_LIBS='-lgssapi'
1835 GSS_INCS=
1836 i='GSS-API in gssapi/gssapi.h, libgssapi'
1838 if < ${tmp2}.c link_check gss \
1839 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1840 < ${tmp3}.c link_check gss \
1841 'GSS-API in gssapi.h, libgssapi' \
1842 '#define HAVE_GSSAPI
1843 #define GSSAPI_REG_INCLUDE' \
1844 '-lgssapi' ||\
1845 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1846 '#define HAVE_GSSAPI' \
1847 '-lgssapi_krb5' ||\
1848 < ${tmp3}.c link_check gss \
1849 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1850 '#define HAVE_GSSAPI
1851 #define GSS_REG_INCLUDE' \
1852 '-lgssapi -lkrb5 -lcrypto' \
1853 '-I/usr/include/kerberosV' ||\
1854 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1855 '#define HAVE_GSSAPI' \
1856 '-lgss' ||\
1857 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1858 '#define HAVE_GSSAPI
1859 #define GSSAPI_OLD_STYLE' \
1860 '-lgssapi_krb5' << \!
1861 #include <gssapi/gssapi.h>
1862 #include <gssapi/gssapi_generic.h>
1863 int main(void){
1864 gss_import_name(0, 0, gss_nt_service_name, 0);
1865 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1866 return 0;
1869 then
1871 else
1872 feat_bail_required GSSAPI
1874 else
1875 echo '/* WANT_GSSAPI=0 */' >> ${h}
1876 fi # feat_yes GSSAPI
1878 if feat_yes NETRC; then
1879 echo '#define HAVE_NETRC' >> ${h}
1880 else
1881 echo '/* WANT_NETRC=0 */' >> ${h}
1884 if feat_yes AGENT; then
1885 echo '#define HAVE_AGENT' >> ${h}
1886 else
1887 echo '/* WANT_AGENT=0 */' >> ${h}
1890 if feat_yes IDNA; then
1891 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
1892 '-lidn' << \!
1893 #include <idna.h>
1894 #include <idn-free.h>
1895 #include <stringprep.h>
1896 int main(void){
1897 char *utf8, *idna_ascii, *idna_utf8;
1899 utf8 = stringprep_locale_to_utf8("does.this.work");
1900 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
1901 != IDNA_SUCCESS)
1902 return 1;
1903 idn_free(idna_ascii);
1904 /* (Rather link check only here) */
1905 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
1906 return 0;
1909 then
1911 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
1912 '-lidnkit' << \!
1913 #include <stdio.h>
1914 #include <idn/api.h>
1915 #include <idn/result.h>
1916 int main(void){
1917 idn_result_t r;
1918 char ace_name[256];
1919 char local_name[256];
1921 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
1922 sizeof(ace_name));
1923 if (r != idn_success) {
1924 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
1925 return 1;
1927 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
1928 if (r != idn_success) {
1929 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
1930 return 1;
1932 return 0;
1935 then
1937 else
1938 feat_bail_required IDNA
1941 if [ -n "${have_idna}" ]; then
1942 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
1943 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
1945 else
1946 echo '/* WANT_IDNA=0 */' >> ${h}
1949 if feat_yes IMAP_SEARCH; then
1950 echo '#define HAVE_IMAP_SEARCH' >> ${h}
1951 else
1952 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
1955 if feat_yes REGEX; then
1956 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
1957 #include <regex.h>
1958 #include <stdlib.h>
1959 int main(void){
1960 int status;
1961 regex_t re;
1963 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
1964 return 1;
1965 status = regexec(&re, "plan9", 0,NULL, 0);
1966 regfree(&re);
1967 return !(status == REG_NOMATCH);
1970 then
1972 else
1973 feat_bail_required REGEX
1975 else
1976 echo '/* WANT_REGEX=0 */' >> ${h}
1979 if feat_yes READLINE; then
1980 __edrdlib() {
1981 link_check readline "for readline(3) (${1})" \
1982 '#define HAVE_READLINE' "${1}" << \!
1983 #include <stdio.h>
1984 #include <readline/history.h>
1985 #include <readline/readline.h>
1986 int main(void){
1987 char *rl;
1988 HISTORY_STATE *hs;
1989 HIST_ENTRY **he;
1990 int i;
1992 using_history();
1993 read_history("");
1994 stifle_history(242);
1995 rl = readline("Enter a line:");
1996 if (rl && *rl)
1997 add_history(rl);
1998 write_history("");
1999 rl_extend_line_buffer(10);
2000 rl_point = rl_end = 10;
2001 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2002 rl_forced_update_display();
2003 clear_history();
2004 hs = history_get_history_state();
2005 i = hs->length;
2006 he = history_list();
2007 if (i > 0)
2008 rl = he[0]->line;
2009 rl_free_line_state();
2010 rl_cleanup_after_signal();
2011 rl_reset_after_signal();
2012 return 0;
2017 __edrdlib -lreadline ||
2018 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2019 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
2022 if feat_yes EDITLINE && [ -z "${have_readline}" ]; then
2023 __edlib() {
2024 link_check editline "for editline(3) (${1})" \
2025 '#define HAVE_EDITLINE' "${1}" << \!
2026 #include <stdio.h> /* For C89 NULL */
2027 #include <histedit.h>
2028 static char * getprompt(void) { return (char*)"ok"; }
2029 int main(void)
2031 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
2032 HistEvent he;
2033 History *el_hcom = history_init();
2034 history(el_hcom, &he, H_SETSIZE, 242);
2035 el_set(el_el, EL_SIGNAL, 0);
2036 el_set(el_el, EL_TERMINAL, NULL);
2037 el_set(el_el, EL_HIST, &history, el_hcom);
2038 el_set(el_el, EL_EDITOR, "emacs");
2039 el_set(el_el, EL_PROMPT, &getprompt);
2040 el_source(el_el, NULL);
2041 history(el_hcom, &he, H_GETSIZE);
2042 history(el_hcom, &he, H_CLEAR);
2043 el_end(el_el);
2044 /* TODO add loader and addfn checks */
2045 history_end(el_hcom);
2046 return 0;
2051 __edlib -ledit ||
2052 __edlib '-ledit -ltermcap' || feat_bail_required EDITLINE
2053 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
2056 if feat_yes NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
2057 [ -n "${have_c90amend1}" ]; then
2058 have_ncl=1
2059 echo '#define HAVE_NCL' >> ${h}
2060 else
2061 feat_bail_required NCL
2062 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
2065 # Generic have-a-command-line-editor switch for those who need it below
2066 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
2067 [ -n "${have_readline}" ]; then
2068 have_cle=1
2071 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2072 echo '#define HAVE_HISTORY' >> ${h}
2073 else
2074 echo '/* WANT_HISTORY=0 */' >> ${h}
2077 if [ -n "${have_cle}" ] && feat_yes TABEXPAND; then
2078 echo '#define HAVE_TABEXPAND' >> ${h}
2079 else
2080 echo '/* WANT_TABEXPAND=0 */' >> ${h}
2083 if feat_yes TERMCAP; then
2084 __termlib() {
2085 link_check termcap "for termcap(3) (via ${4})" \
2086 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2087 #include <stdio.h>
2088 #include <stdlib.h>
2089 #include <string.h>
2090 ${2}
2091 #include <term.h>
2092 #define PTR2SIZE(X) ((unsigned long)(X))
2093 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2094 static char *_termcap_buffer, *_termcap_ti, *_termcap_te;
2095 int main(void){
2096 char buf[1024+512], cmdbuf[2048], *cpb, *cpti, *cpte, *cp;
2098 tgetent(buf, getenv("TERM"));
2099 cpb = cmdbuf;
2100 cpti = cpb;
2101 if ((cp = tgetstr(UNCONST("ti"), &cpb)) == NULL)
2102 goto jleave;
2103 cpte = cpb;
2104 if ((cp = tgetstr(UNCONST("te"), &cpb)) == NULL)
2105 goto jleave;
2106 _termcap_buffer = malloc(PTR2SIZE(cpb - cmdbuf));
2107 memcpy(_termcap_buffer, cmdbuf, PTR2SIZE(cpb - cmdbuf));
2108 _termcap_ti = _termcap_buffer + PTR2SIZE(cpti - cmdbuf);
2109 _termcap_te = _termcap_ti + PTR2SIZE(cpte - cpti);
2110 tputs(_termcap_ti, 1, &putchar);
2111 tputs(_termcap_te, 1, &putchar);
2112 jleave:
2113 return (cp == NULL);
2115 _EOT
2118 __termlib -ltermcap '' '' termcap ||
2119 __termlib -ltermcap '#include <curses.h>' '
2120 #define HAVE_TERMCAP_CURSES' \
2121 'curses.h / -ltermcap' ||
2122 __termlib -lcurses '#include <curses.h>' '
2123 #define HAVE_TERMCAP_CURSES' \
2124 'curses.h / -lcurses' ||
2125 feat_bail_required TERMCAP
2126 else
2127 echo '/* WANT_TERMCAP=0 */' >> ${h}
2130 if feat_yes ERRORS; then
2131 echo '#define HAVE_ERRORS' >> ${h}
2132 else
2133 echo '/* WANT_ERRORS=0 */' >> ${h}
2138 if feat_yes SPAM_SPAMC; then
2139 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2140 if command -v spamc >/dev/null 2>&1; then
2141 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2143 else
2144 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2147 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2148 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2149 else
2150 feat_bail_required SPAM_SPAMD
2151 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2154 if feat_yes SPAM_FILTER; then
2155 echo '#define HAVE_SPAM_FILTER' >> ${h}
2156 else
2157 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
2160 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2161 echo '#define HAVE_SPAM' >> ${h}
2162 else
2163 echo '/* HAVE_SPAM */' >> ${h}
2166 if feat_yes DOCSTRINGS; then
2167 echo '#define HAVE_DOCSTRINGS' >> ${h}
2168 else
2169 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
2172 if feat_yes QUOTE_FOLD &&\
2173 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2174 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2175 else
2176 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2179 if feat_yes FILTER_HTML_TAGSOUP; then
2180 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2181 else
2182 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2185 if feat_yes COLOUR; then
2186 echo '#define HAVE_COLOUR' >> ${h}
2187 else
2188 echo '/* WANT_COLOUR=0 */' >> ${h}
2191 if feat_yes DOTLOCK; then
2192 echo '#define HAVE_DOTLOCK' >> ${h}
2193 else
2194 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2197 if feat_yes MD5; then
2198 echo '#define HAVE_MD5' >> ${h}
2199 else
2200 echo '/* WANT_MD5=0 */' >> ${h}
2203 ## Summarizing
2205 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2206 squeeze_em() {
2207 < "${1}" > "${2}" ${awk} \
2208 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2210 ${rm} -f ${tmp}
2211 squeeze_em ${inc} ${tmp}
2212 ${mv} ${tmp} ${inc}
2213 squeeze_em ${lib} ${tmp}
2214 ${mv} ${tmp} ${lib}
2216 # config.h
2217 ${mv} ${h} ${tmp}
2218 printf '#ifndef _CONFIG_H\n# define _CONFIG_H 1\n' > ${h}
2219 ${cat} ${tmp} >> ${h}
2220 ${rm} -f ${tmp}
2222 printf '\n/* The "feature string" */\n' >> ${h}
2223 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2224 printf 'static char const _features[] = "MIME"\n' >> ${h}
2225 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2226 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2227 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2228 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2229 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2230 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2231 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2232 >> ${h}
2233 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2234 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2235 printf '# ifdef HAVE_IMAP\n ",IMAP"\n# endif\n' >> ${h}
2236 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2237 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2238 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2239 printf '# ifdef HAVE_AGENT\n ",AGENT"\n# endif\n' >> ${h}
2240 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2241 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2242 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2243 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2244 printf '# ifdef HAVE_EDITLINE\n ",EDITLINE"\n# endif\n' >> ${h}
2245 printf '# ifdef HAVE_NCL\n ",NCL"\n# endif\n' >> ${h}
2246 printf '# ifdef HAVE_TABEXPAND\n ",TABEXPAND"\n# endif\n' >> ${h}
2247 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2248 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2249 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2250 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2251 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2252 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2253 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2254 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2255 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2256 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2257 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2258 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2259 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2261 # Create the real mk.mk
2262 # Note we cannout use explicit ./ filename prefix for source and object
2263 # pathnames because of a bug in bmake(1)
2264 ${rm} -rf ${tmp0}.* ${tmp0}*
2265 printf 'OBJ_SRC = ' >> ${mk}
2266 if feat_no AMALGAMATION; then
2267 for i in `printf '%s\n' *.c | ${sort}`; do
2268 if [ "${i}" = privsep.c ]; then
2269 continue
2271 printf "${i} " >> ${mk}
2272 done
2273 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2274 else
2275 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2277 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2278 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2279 printf '# undef _CONFIG_H\n' >> ${h}
2280 printf '# define _CONFIG_H 2\n' >> ${h}
2281 for i in `printf '%s\n' *.c | ${sort}`; do
2282 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2283 [ "${i}" = privsep.c ]; then
2284 continue
2286 printf "${i} " >> ${mk}
2287 printf "# include \"${i}\"\n" >> ${h}
2288 done
2289 echo >> ${mk}
2290 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2291 echo '#else' >> ${h}
2294 printf '#endif /* _CONFIG_H */\n' >> ${h}
2296 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2297 echo "INCS = `${cat} ${inc}`" >> ${mk}
2298 echo >> ${mk}
2299 ${cat} ./mk-mk.in >> ${mk}
2301 ## Finished!
2303 ${cat} > ${tmp2}.c << \!
2304 #include "config.h"
2306 :The following optional features are enabled:
2307 #ifdef HAVE_SETLOCALE
2308 : + Locale support: Printable characters depend on the environment
2309 # ifdef HAVE_C90AMEND1
2310 : + Multibyte character support
2311 # endif
2312 # ifdef HAVE_NL_LANGINFO
2313 : + Automatic detection of terminal character set
2314 # endif
2315 #endif
2316 #ifdef HAVE_ICONV
2317 : + Character set conversion using iconv()
2318 #endif
2319 #ifdef HAVE_SOCKETS
2320 : + Network support
2321 #endif
2322 #ifdef HAVE_SSL
2323 # ifdef HAVE_OPENSSL
2324 : + S/MIME and SSL/TLS (OpenSSL)
2325 # endif
2326 # ifdef HAVE_SSL_ALL_ALGORITHMS
2327 : + + Support for more ("all") digest and cipher algorithms
2328 # endif
2329 #endif
2330 #ifdef HAVE_SMTP
2331 : + SMTP protocol
2332 #endif
2333 #ifdef HAVE_POP3
2334 : + POP3 protocol
2335 #endif
2336 #ifdef HAVE_IMAP
2337 : + IMAP protocol
2338 #endif
2339 #ifdef HAVE_GSSAPI
2340 : + GSS-API authentication
2341 #endif
2342 #ifdef HAVE_MD5
2343 : + MD5 message digest (APOP, CRAM-MD5)
2344 #endif
2345 #ifdef HAVE_NETRC
2346 : + .netrc file support
2347 #endif
2348 #ifdef HAVE_AGENT
2349 : + Password query through agent
2350 #endif
2351 #ifdef HAVE_IDNA
2352 : + IDNA (internationalized domain names for applications) support
2353 #endif
2354 #ifdef HAVE_IMAP_SEARCH
2355 : + IMAP-style search expressions
2356 #endif
2357 #ifdef HAVE_REGEX
2358 : + Regular expression support (searches, conditional expressions etc.)
2359 #endif
2360 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
2361 # ifdef HAVE_READLINE
2362 : + Command line editing via readline(3)
2363 # elif defined HAVE_EDITLINE
2364 : + Command line editing via editline(3)
2365 # else
2366 : + Command line editing via N(ail) C(ommand) L(ine)
2367 # endif
2368 # ifdef HAVE_TABEXPAND
2369 : + + Tabulator expansion
2370 # endif
2371 # ifdef HAVE_HISTORY
2372 : + + History management
2373 # endif
2374 #endif
2375 #ifdef HAVE_TERMCAP
2376 : + Terminal capability queries
2377 #endif
2378 #ifdef HAVE_SPAM
2379 : + Spam management
2380 # ifdef HAVE_SPAM_SPAMC
2381 : + + Via spamc(1) (of spamassassin(1))
2382 # endif
2383 # ifdef HAVE_SPAM_SPAMD
2384 : + + Directly via spamd(1) (of spamassassin(1))
2385 # endif
2386 # ifdef HAVE_SPAM_FILTER
2387 : + + Via freely configurable *spam-filter-XY*s
2388 # endif
2389 #endif
2390 #ifdef HAVE_DOCSTRINGS
2391 : + Documentation summary strings
2392 #endif
2393 #ifdef HAVE_QUOTE_FOLD
2394 : + Extended *quote-fold*ing
2395 #endif
2396 #ifdef HAVE_FILTER_HTML_TAGSOUP
2397 : + Builtin HTML-to-text filter (for display purposes, primitive)
2398 #endif
2399 #ifdef HAVE_COLOUR
2400 : + Coloured message display (simple)
2401 #endif
2402 #ifdef HAVE_DOTLOCK
2403 : + Dotlock files and privilege-separated file dotlock program
2404 #endif
2406 :The following optional features are disabled:
2407 #ifndef HAVE_SETLOCALE
2408 : - Locale support: Only ASCII characters are recognized
2409 #endif
2410 # ifndef HAVE_C90AMEND1
2411 : - Multibyte character support
2412 # endif
2413 # ifndef HAVE_NL_LANGINFO
2414 : - Automatic detection of terminal character set
2415 # endif
2416 #ifndef HAVE_ICONV
2417 : - Character set conversion using iconv()
2418 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2419 #endif
2420 #ifndef HAVE_SOCKETS
2421 : - Network support
2422 #endif
2423 #ifndef HAVE_SSL
2424 : - S/MIME and SSL/TLS
2425 #else
2426 # ifndef HAVE_SSL_ALL_ALGORITHMS
2427 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2428 # endif
2429 #endif
2430 #ifndef HAVE_SMTP
2431 : - SMTP protocol
2432 #endif
2433 #ifndef HAVE_POP3
2434 : - POP3 protocol
2435 #endif
2436 #ifndef HAVE_IMAP
2437 : - IMAP protocol
2438 #endif
2439 #ifndef HAVE_GSSAPI
2440 : - GSS-API authentication
2441 #endif
2442 #ifndef HAVE_MD5
2443 : - MD5 message digest (APOP, CRAM-MD5)
2444 #endif
2445 #ifndef HAVE_NETRC
2446 : - .netrc file support
2447 #endif
2448 #ifndef HAVE_AGENT
2449 : - Password query through agent
2450 #endif
2451 #ifndef HAVE_IDNA
2452 : - IDNA (internationalized domain names for applications) support
2453 #endif
2454 #ifndef HAVE_IMAP_SEARCH
2455 : - IMAP-style search expressions
2456 #endif
2457 #ifndef HAVE_REGEX
2458 : - Regular expression support
2459 #endif
2460 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2461 : - Command line editing and history
2462 #endif
2463 #ifndef HAVE_TERMCAP
2464 : - Terminal capability queries
2465 #endif
2466 #ifndef HAVE_SPAM
2467 : - Spam management
2468 #endif
2469 #ifndef HAVE_DOCSTRINGS
2470 : - Documentation summary strings
2471 #endif
2472 #ifndef HAVE_QUOTE_FOLD
2473 : - Extended *quote-fold*ing
2474 #endif
2475 #ifndef HAVE_FILTER_HTML_TAGSOUP
2476 : - Builtin HTML-to-text filter (for display purposes, primitive)
2477 #endif
2478 #ifndef HAVE_COLOUR
2479 : - Coloured message display (simple)
2480 #endif
2481 #ifndef HAVE_DOTLOCK
2482 : - Dotlock files and privilege-separated file dotlock program
2483 #endif
2485 #if !defined HAVE_WORDEXP || !defined HAVE_FCHDIR ||\
2486 defined HAVE_DEBUG || defined HAVE_DEVEL
2487 :Remarks:
2488 # ifndef HAVE_WORDEXP
2489 : . WARNING: the function wordexp(3) could not be found.
2490 : _ This means that echo(1) will be used via the sh(1)ell in order
2491 : _ to expand shell meta characters in filenames, which is a potential
2492 : _ security hole. Consider to either upgrade your system or set the
2493 : _ *SHELL* variable to some safe(r) wrapper script.
2494 : _ P.S.: the codebase is in transition away from wordexp(3) to some
2495 : _ safe (restricted) internal mechanism, see "COMMANDS" manual, read
2496 : _ about shell word expression in its introduction for more on that.
2497 # endif
2498 # ifndef HAVE_FCHDIR
2499 : . The function fchdir(2) could not be found. We will use chdir(2)
2500 : _ instead. This is not a problem unless the current working
2501 : _ directory of mailx is moved while the IMAP cache is used.
2502 # endif
2503 # ifdef HAVE_DEBUG
2504 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2505 # endif
2506 # ifdef HAVE_DEVEL
2507 : . Computers do not blunder.
2508 # endif
2510 #endif /* Remarks */
2511 :Setup:
2512 : . System-wide resource file: SYSCONFRC
2513 : . bindir: BINDIR
2514 #ifdef HAVE_DOTLOCK
2515 : . libexecdir: LIBEXECDIR
2516 #endif
2517 : . mandir: MANDIR
2518 : . sendmail(1): SENDMAIL (argv[0] = SENDMAIL_PROGNAME)
2519 : . Mail spool directory: MAILSPOOL
2523 ${make} -f ${makefile} ${tmp2}.x
2524 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
2526 # s-it-mode