Bump S-nail v14.8.14.ar, 2016-10-20
[s-mailx.git] / mk-conf.sh
blob60166a1c0bc0398ad6dd8d6619aa917356cf9cde
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 ICONV; then
141 WANT_IMAP=0
144 if feat_no READLINE && feat_no EDITLINE && feat_no NCL; then
145 WANT_HISTORY=0 WANT_TABEXPAND=0
148 # If we don't need MD5 leave it alone
149 if feat_no SOCKETS; then
150 WANT_MD5=0
153 if feat_yes DEVEL; then
154 WANT_DEBUG=1
156 if feat_yes DEBUG; then
157 WANT_NOALLOCA=1
161 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
162 # via path_check() later on once possible
164 # TODO cc_maxopt is brute simple, we should compile test program and dig real
165 # compiler versions for known compilers, then be more specific
166 cc_maxopt=100
167 _CFLAGS= _LDFLAGS=
169 os_early_setup() {
170 i="${OS:-`uname -s`}"
172 if [ ${i} = SunOS ]; then
173 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
174 _os_early_setup_sunos
178 os_setup() {
179 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
180 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
181 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
182 msg 'Operating system is "%s"' ${OS}
184 if [ ${OS} = sunos ]; then
185 msg ' . have special SunOS / Solaris "setup" rules ...'
186 _os_setup_sunos
187 elif [ ${OS} = unixware ]; then
188 msg ' . have special UnixWare environmental rules ...'
189 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
190 CC=cc
191 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
193 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
194 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
195 export CC CFLAGS LDFLAGS
196 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
198 elif [ -n "${VERBOSE}" ]; then
199 msg ' . no special treatment for this system necessary or known'
202 # Sledgehammer: better set _GNU_SOURCE
203 # And in general: oh, boy!
204 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
205 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
206 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
207 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
209 # On pkgsrc(7) systems automatically add /usr/pkg/*
210 if [ -d /usr/pkg ]; then
211 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
212 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
216 _os_early_setup_sunos() {
217 # According to standards(5), this is what we need to do
218 if [ -d /usr/xpg4 ]; then :; else
219 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
220 config_exit 1
222 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
223 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
224 export PATH
227 _os_setup_sunos() {
228 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
229 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
231 # Include packages
232 if [ -d /opt/csw ]; then
233 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
234 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
237 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
238 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
240 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
241 if [ -x "${cksum}" ]; then :; else
242 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
243 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
244 msg 'ERROR: However, we do so only for tests.'
245 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
246 config_exit 1
249 if feat_yes AUTOCC; then
250 if command -v cc >/dev/null 2>&1; then
251 CC=cc
252 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
254 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
255 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
256 export CC CFLAGS LDFLAGS
257 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
258 else
259 # Assume gcc(1)
260 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
265 # Check out compiler ($CC) and -flags ($CFLAGS)
266 cc_setup() {
267 # Even though it belongs into cc_flags we will try to compile and link
268 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
269 # ADDCFLAGS/ADDLDFLAGS
270 if feat_no AUTOCC; then
271 _cc_default
272 # Ensure those don't do any harm
273 ADDCFLAGS= ADDLDFLAGS=
274 export ADDCFLAGS ADDLDFLAGS
275 return
276 else
277 CFLAGS= LDFLAGS=
278 export CFLAGS LDFLAGS
281 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
283 printf >&2 'Searching for a usable C compiler .. $CC='
284 if { i="`command -v clang`"; }; then
285 CC=${i}
286 elif { i="`command -v gcc`"; }; then
287 CC=${i}
288 elif { i="`command -v c99`"; }; then
289 CC=${i}
290 elif { i="`command -v tcc`"; }; then
291 CC=${i}
292 elif { i="`command -v pcc`"; }; then
293 CC=${i}
294 else
295 if [ "${CC}" = cc ]; then
297 elif { i="`command -v c89`"; }; then
298 CC=${i}
299 else
300 printf >&2 'boing booom tschak\n'
301 msg 'ERROR: I cannot find a compiler!'
302 msg ' Neither of clang(1), gcc(1), tcc(1), c89(1) and c99(1).'
303 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
304 config_exit 1
307 printf >&2 -- '"%s"\n' "${CC}"
308 export CC
311 _cc_default() {
312 if [ -z "${CC}" ]; then
313 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
314 config_exit 1
317 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
319 else
320 msg 'Using C compiler $CC="%s"' "${CC}"
324 cc_flags() {
325 if feat_yes AUTOCC; then
326 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
327 cc_check_silent=1
328 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
329 else
330 cc_check_silent=
331 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
334 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
335 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
336 msg ' . have special tcc(1) environmental rules ...'
337 _cc_flags_tcc
338 else
339 # As of pcc CVS 2016-04-02, stack protection support is announced but
340 # will break if used on Linux
341 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
342 force_no_stackprot=1
344 _cc_flags_generic
347 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
348 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
349 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
350 else
351 if feat_no DEBUG; then
352 CFLAGS="-DNDEBUG ${CFLAGS}"
355 msg ''
356 export CFLAGS LDFLAGS
359 _cc_flags_tcc() {
360 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
361 _CFLAGS= _LDFLAGS=
363 cc_check -Wall
364 cc_check -Wextra
365 cc_check -pedantic
367 if feat_yes DEBUG; then
368 # May have problems to find libtcc cc_check -b
369 cc_check -g
372 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
373 unset __cflags __ldflags
376 _cc_flags_generic() {
377 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
378 _CFLAGS= _LDFLAGS=
379 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
381 # Check -g first since some others may rely upon -g / optim. level
382 if feat_yes DEBUG; then
383 cc_check -O
384 cc_check -g
385 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
387 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
389 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
391 else
392 cc_check -O
395 if feat_yes DEVEL && cc_check -Weverything; then
397 else
398 cc_check -Wall
399 cc_check -Wextra
400 cc_check -Wbad-function-cast
401 cc_check -Wcast-align
402 cc_check -Wcast-qual
403 cc_check -Winit-self
404 cc_check -Wmissing-prototypes
405 cc_check -Wshadow
406 cc_check -Wunused
407 cc_check -Wwrite-strings
408 cc_check -Wno-long-long
410 cc_check -pedantic
412 if feat_yes AMALGAMATION && feat_no DEVEL; then
413 cc_check -Wno-unused-function
415 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
417 cc_check -fno-unwind-tables
418 cc_check -fno-asynchronous-unwind-tables
419 cc_check -fstrict-aliasing
420 if cc_check -fstrict-overflow && feat_yes DEVEL; then
421 cc_check -Wstrict-overflow=5
424 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
425 if [ -z "${force_no_stackprot}" ]; then
426 if cc_check -fstack-protector-strong ||
427 cc_check -fstack-protector-all; then
428 cc_check -D_FORTIFY_SOURCE=2
430 else
431 msg 'Not checking for -fstack-protector compiler option,'
432 msg 'since that caused errors in a "similar" configuration.'
433 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
437 if feat_yes AMALGAMATION; then
438 cc_check -pipe
441 # LD (+ dependend CC)
443 if feat_yes DEVEL; then
444 _ccfg=${_CFLAGS}
445 # -fsanitize=address
446 #if cc_check -fsanitize=memory &&
447 # ld_check -fsanitize=memory &&
448 # cc_check -fsanitize-memory-track-origins=2 &&
449 # ld_check -fsanitize-memory-track-origins=2; then
451 #else
452 # _CFLAGS=${_ccfg}
456 ld_check -Wl,-z,relro
457 ld_check -Wl,-z,now
458 ld_check -Wl,-z,noexecstack
460 # Address randomization
461 _ccfg=${_CFLAGS}
462 if cc_check -fPIE || cc_check -fpie; then
463 ld_check -pie || _CFLAGS=${_ccfg}
465 unset _ccfg
467 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
468 unset __cflags __ldflags
471 ## -- >8 -- 8< -- ##
473 ## Notes:
474 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
475 ## redirection, so use "printf '' >" instead
477 ## Very first: we undergo several states regarding I/O redirection etc.,
478 ## but need to deal with option updates from within all. Since all the
479 ## option stuff should be above the scissor line, define utility functions
480 ## and redefine them as necessary.
481 ## And, since we have those functions, simply use them for whatever
483 config_exit() {
484 exit ${1}
487 msg() {
488 fmt=${1}
489 shift
490 printf >&2 -- "${fmt}\\n" "${@}"
493 ## First of all, create new configuration and check wether it changed
495 rc=./make.rc
496 lst=./config.lst
497 h=./config.h h_name=config.h
498 mk=./mk.mk
500 newlst=./config.lst-new
501 newmk=./config.mk-new
502 newh=./config.h-new
503 tmp0=___tmp
504 tmp=./${tmp0}1$$
505 tmp2=./${tmp0}2$$
507 t1=ten10one1ten10one1
508 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
509 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
510 ) > /dev/null 2>&1; then
511 good_shell=1
512 else
513 unset good_shell
515 unset t1
517 # We need some standard utilities
518 unset -f command
519 check_tool() {
520 n=${1} i=${2} opt=${3:-0}
521 # Evaluate, just in case user comes in with shell snippets (..well..)
522 eval i="${i}"
523 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
524 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
525 eval ${n}=${i}
526 return 0
528 if [ ${opt} -eq 0 ]; then
529 msg 'ERROR: no trace of utility "%s"' "${n}"
530 config_exit 1
532 return 1
535 # Very easy checks for the operating system in order to be able to adjust paths
536 # or similar very basic things which we need to be able to go at all
537 os_early_setup
539 # Check those tools right now that we need before including $rc
540 msg 'Checking for basic utility set'
541 check_tool awk "${awk:-`command -v awk`}"
542 check_tool rm "${rm:-`command -v rm`}"
543 check_tool tr "${tr:-`command -v tr`}"
545 # Our feature check environment
546 feat_val_no() {
547 [ "x${1}" = x0 ] ||
548 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
551 feat_val_yes() {
552 [ "x${1}" = x1 ] ||
553 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
554 [ "x${1}" = xrequire ]
557 feat_val_require() {
558 [ "x${1}" = xrequire ]
561 _feat_check() {
562 eval i=\$WANT_${1}
563 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
564 if feat_val_no "${i}"; then
565 return 1
566 elif feat_val_yes "${i}"; then
567 return 0
568 else
569 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
570 "${1}" "${i}"
571 config_exit 11
575 feat_yes() {
576 _feat_check ${1}
579 feat_no() {
580 _feat_check ${1} && return 1
581 return 0
584 feat_require() {
585 eval i=\$WANT_${1}
586 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
587 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
590 feat_bail_required() {
591 if feat_require ${1}; then
592 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
593 config_exit 13
595 eval WANT_${1}=0
596 option_update # XXX this is rather useless here (dependency chain..)
599 # Include $rc, but only take from it what wasn't overwritten by the user from
600 # within the command line or from a chosen fixed CONFIG=
601 # Note we leave alone the values
602 trap "exit 1" HUP INT TERM
603 trap "${rm} -f ${tmp}" EXIT
605 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
606 ${rm} -f ${tmp}
607 # We want read(1) to perform backslash escaping in order to be able to use
608 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
609 # VMs (see [fa2e248]), Aharon Robbins suggested the following
610 < ${rc} ${awk} 'BEGIN{line = ""}{
611 gsub(/^[[:space:]]+/, "", $0)
612 gsub(/[[:space:]]+$/, "", $0)
613 if(gsub(/\\$/, "", $0)){
614 line = line $0
615 next
616 }else
617 line = line $0
618 if(index(line, "#") == 1){
619 line = ""
620 }else if(length(line)){
621 print line
622 line = ""
624 }' |
625 while read line; do
626 if [ -n "${good_shell}" ]; then
627 i=${line%%=*}
628 else
629 i=`${awk} -v LINE="${line}" 'BEGIN{
630 gsub(/=.*$/, "", LINE)
631 print LINE
634 if [ "${i}" = "${line}" ]; then
635 msg 'ERROR: invalid syntax in "%s"' "${line}"
636 continue
639 eval j="\$${i}" jx="\${${i}+x}"
640 if [ -n "${j}" ] || [ "${jx}" = x ]; then
641 : # Yet present
642 else
643 j=`${awk} -v LINE="${line}" 'BEGIN{
644 gsub(/^[^=]*=/, "", LINE)
645 gsub(/^\"*/, "", LINE)
646 gsub(/\"*$/, "", LINE)
647 print LINE
650 echo "${i}=\"${j}\""
651 done > ${tmp}
652 # Reread the mixed version right now
653 . ./${tmp}
654 printf >&2 'done\n'
656 # We need to know about that now, in order to provide utility overwrites etc.
657 os_setup
659 msg 'Checking for remaining set of utilities'
660 check_tool grep "${grep:-`command -v grep`}"
662 # Before we step ahead with the other utilities perform a path cleanup first.
663 # We need this function also for C_INCLUDE_PATH and LD_LIBRARY_PATH
664 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
665 path_check() {
666 varname=${1} addflag=${2} flagvarname=${3}
667 j=${IFS}
668 IFS=:
669 eval "set -- \$${1}"
670 IFS=${j}
671 j= k= y= z=
672 for i
674 [ -z "${i}" ] && continue
675 [ -d "${i}" ] || continue
676 if [ -n "${j}" ]; then
677 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
679 else
680 y="${y} :${i}:"
681 j="${j}:${i}"
682 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
684 else
685 y=" :${i}:"
686 j="${i}"
687 [ -n "${addflag}" ] && k="${addflag}${i}"
689 done
690 eval "${varname}=\"${j}\""
691 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
692 unset varname
695 path_check PATH
697 # awk(1) above
698 check_tool cat "${cat:-`command -v cat`}"
699 check_tool chmod "${chmod:-`command -v chmod`}"
700 check_tool cp "${cp:-`command -v cp`}"
701 check_tool cmp "${cmp:-`command -v cmp`}"
702 # grep(1) above
703 check_tool mkdir "${mkdir:-`command -v mkdir`}"
704 check_tool mv "${mv:-`command -v mv`}"
705 # rm(1) above
706 check_tool sed "${sed:-`command -v sed`}"
707 check_tool sort "${sort:-`command -v sort`}"
708 check_tool tee "${tee:-`command -v tee`}"
710 check_tool chown "${chown:-`command -v chown`}" 1 ||
711 check_tool chown "/sbin/chown" 1 ||
712 check_tool chown "/usr/sbin/chown"
714 check_tool make "${MAKE:-`command -v make`}"
715 MAKE=${make}
716 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
717 HAVE_STRIP=1 || HAVE_STRIP=0
719 # For ./cc-test.sh only
720 check_tool cksum "${cksum:-`command -v cksum`}"
722 # Update WANT_ options now, in order to get possible inter-dependencies right
723 option_update
725 # (No functions since some shells loose non-exported variables in traps)
726 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
727 trap "trap \"\" HUP INT TERM EXIT;\
728 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newh}" EXIT
730 # Our configuration options may at this point still contain shell snippets,
731 # we need to evaluate them in order to get them expanded, and we need those
732 # evaluated values not only in our new configuration file, but also at hand..
733 printf >&2 'Evaluating all configuration items ... '
734 ${rm} -f ${newlst} ${newmk} ${newh}
735 exec 5<&0 6>&1 <${tmp} >${newlst}
736 while read line; do
738 if [ -n "${good_shell}" ]; then
739 i=${line%%=*}
740 [ "${i}" != "${i#WANT_}" ] && z=1
741 else
742 i=`${awk} -v LINE="${line}" 'BEGIN{
743 gsub(/=.*$/, "", LINE);\
744 print LINE
746 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
751 eval j=\$${i}
752 if [ -n "${z}" ]; then
753 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
754 if [ -z "${j}" ] || feat_val_no "${j}"; then
756 printf "/*#define ${i}*/\n" >> ${newh}
757 elif feat_val_yes "${j}"; then
758 if feat_val_require "${j}"; then
759 j=require
760 else
763 printf "#define ${i}\n" >> ${newh}
764 else
765 msg 'ERROR: cannot parse <%s>' "${line}"
766 config_exit 1
768 else
769 printf "#define ${i} \"${j}\"\n" >> ${newh}
771 printf "${i} = ${j}\n" >> ${newmk}
772 printf "${i}=${j}\n"
773 eval "${i}=\"${j}\""
774 done
775 exec 0<&5 1>&6 5<&- 6<&-
776 printf >&2 'done\n'
778 # Add the known utility and some other variables
779 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
780 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
782 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
783 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
784 if feat_yes DOTLOCK; then
785 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
786 else
787 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
790 for i in \
791 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
792 MAKE make strip \
793 cksum; do
794 eval j=\$${i}
795 printf "${i} = ${j}\n" >> ${newmk}
796 printf "${i}=${j}\n" >> ${newlst}
797 done
799 # Build a basic set of INCS and LIBS according to user environment.
800 path_check C_INCLUDE_PATH -I _INCS
801 INCS="${INCS} ${_INCS}"
802 path_check LD_LIBRARY_PATH -L _LIBS
803 LIBS="${LIBS} ${_LIBS}"
804 unset _INCS _LIBS
805 export C_INCLUDE_PATH LD_LIBRARY_PATH
807 if [ -n "${need_R_ldflags}" ]; then
808 i=${IFS}
809 IFS=:
810 set -- ${LD_LIBRARY_PATH}
811 IFS=${i}
812 for i
814 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
815 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
816 done
817 export LDFLAGS
820 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
822 cc_setup
824 ${cat} > ${tmp}.c << \!
825 #include <stdio.h>
826 #include <string.h>
827 static void doit(char const *s);
829 main(int argc, char **argv){
830 (void)argc;
831 (void)argv;
832 doit("Hello world");
833 return 0;
835 static void
836 doit(char const *s){
837 char buf[12];
838 strcpy(buf, s);
839 puts(s);
843 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
844 -o ${tmp2} ${tmp}.c ${LIBS}; then
846 else
847 msg 'ERROR: i cannot compile a "Hello world" via'
848 msg ' %s' \
849 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
850 msg 'ERROR: Please read INSTALL, rerun'
851 config_exit 1
854 cc_check() {
855 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
856 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
857 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
858 _CFLAGS="${_CFLAGS} ${1}"
859 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
860 return 0
862 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
863 return 1
866 ld_check() {
867 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
868 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1} ${ADDLDFLAGS} \
869 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
870 _LDFLAGS="${_LDFLAGS} ${1}"
871 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
872 return 0
874 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
875 return 1
878 cc_flags
880 for i in \
881 INCS LIBS \
882 ; do
883 eval j=\$${i}
884 printf -- "${i}=${j}\n" >> ${newlst}
885 done
886 for i in \
887 CC \
888 CFLAGS \
889 LDFLAGS \
890 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
891 OSFULLSPEC \
892 ; do
893 eval j=\$${i}
894 printf -- "${i} = ${j}\n" >> ${newmk}
895 printf -- "${i}=${j}\n" >> ${newlst}
896 done
898 # Now finally check wether we already have a configuration and if so, wether
899 # all those parameters are still the same.. or something has actually changed
900 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
901 echo 'Configuration is up-to-date'
902 exit 0
903 elif [ -f ${lst} ]; then
904 echo 'Configuration has been updated..'
905 ( eval "${MAKE} -f ./mk.mk clean" )
906 echo
907 else
908 echo 'Shiny configuration..'
911 # Time to redefine helper 1
912 config_exit() {
913 ${rm} -f ${lst} ${h} ${mk}
914 exit ${1}
917 ${mv} -f ${newlst} ${lst}
918 ${mv} -f ${newh} ${h}
919 ${mv} -f ${newmk} ${mk}
921 ## Compile and link checking
923 tmp3=./${tmp0}3$$
924 log=./config.log
925 lib=./config.lib
926 inc=./config.inc
927 makefile=./config.mk
929 # (No function since some shells loose non-exported variables in traps)
930 trap "trap \"\" HUP INT TERM;\
931 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
932 trap "trap \"\" HUP INT TERM EXIT;\
933 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
935 # Time to redefine helper 2
936 msg() {
937 fmt=${1}
938 shift
939 printf "*** ${fmt}\\n" "${@}"
940 printf -- "${fmt}\\n" "${@}" >&5
942 msg_nonl() {
943 fmt=${1}
944 shift
945 printf "*** ${fmt}\\n" "${@}"
946 printf -- "${fmt}" "${@}" >&5
949 exec 5>&2 > ${log} 2>&1
951 echo "${LIBS}" > ${lib}
952 echo "${INCS}" > ${inc}
953 ${cat} > ${makefile} << \!
954 .SUFFIXES: .o .c .x .y
955 .c.o:
956 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
957 .c.x:
958 $(CC) -I./ $(XINCS) -E $< >$@
960 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
961 .y: ;
964 _check_preface() {
965 variable=$1 topic=$2 define=$3
967 echo '**********'
968 msg_nonl ' . %s ... ' "${topic}"
969 echo "/* checked ${topic} */" >> ${h}
970 ${rm} -f ${tmp} ${tmp}.o
971 echo '*** test program is'
972 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
973 #echo '*** the preprocessor generates'
974 #${make} -f ${makefile} ${tmp}.x
975 #${cat} ${tmp}.x
976 echo '*** results are'
979 compile_check() {
980 variable=$1 topic=$2 define=$3
982 _check_preface "${variable}" "${topic}" "${define}"
984 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
985 [ -f ./${tmp}.o ]; then
986 msg 'yes'
987 echo "${define}" >> ${h}
988 eval have_${variable}=yes
989 return 0
990 else
991 echo "/* ${define} */" >> ${h}
992 msg 'no'
993 eval unset have_${variable}
994 return 1
998 _link_mayrun() {
999 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1001 _check_preface "${variable}" "${topic}" "${define}"
1003 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1004 XLIBS="${LIBS} ${libs}" ./${tmp} &&
1005 [ -f ./${tmp} ] &&
1006 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1007 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1008 msg 'yes'
1009 echo "${define}" >> ${h}
1010 LIBS="${LIBS} ${libs}"
1011 echo "${libs}" >> ${lib}
1012 INCS="${INCS} ${incs}"
1013 echo "${incs}" >> ${inc}
1014 eval have_${variable}=yes
1015 return 0
1016 else
1017 msg 'no'
1018 echo "/* ${define} */" >> ${h}
1019 eval unset have_${variable}
1020 return 1
1024 link_check() {
1025 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1028 run_check() {
1029 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1034 # May be multiline..
1035 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1037 if run_check clock_gettime 'clock_gettime(2)' \
1038 '#define HAVE_CLOCK_GETTIME' << \!
1039 #include <time.h>
1040 # include <errno.h>
1041 int main(void){
1042 struct timespec ts;
1044 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1045 return 0;
1046 return 1;
1049 then
1051 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1052 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1053 #include <time.h>
1054 # include <errno.h>
1055 int main(void){
1056 struct timespec ts;
1058 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1059 return 0;
1060 return 1;
1063 then
1065 elif run_check gettimeofday 'gettimeofday(2)' \
1066 '#define HAVE_GETTIMEOFDAY' << \!
1067 #include <stdio.h> /* For C89 NULL */
1068 #include <sys/time.h>
1069 # include <errno.h>
1070 int main(void){
1071 struct timeval tv;
1073 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1074 return 0;
1075 return 1;
1078 then
1080 else
1081 have_no_subsecond_time=1
1084 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1085 #include <pwd.h>
1086 #include <unistd.h>
1087 # include <errno.h>
1088 int main(void){
1089 struct passwd *pw;
1090 gid_t gid;
1091 uid_t uid;
1093 if((gid = getgid()) != 0)
1094 gid = getegid();
1095 if((uid = getuid()) != 0)
1096 uid = geteuid();
1097 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1098 return 1;
1099 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1100 return 1;
1101 return 0;
1104 then
1106 else
1107 msg 'ERROR: we require user and group info / database searches.'
1108 msg 'That much Unix we indulge ourselfs.'
1109 config_exit 1
1112 if link_check snprintf 'v?snprintf(3)' << \!
1113 #include <stdarg.h>
1114 #include <stdio.h>
1115 static void dome(char *buf, ...){
1116 va_list ap;
1118 va_start(ap, buf);
1119 vsnprintf(buf, 20, "%s", ap);
1120 va_end(ap);
1121 return;
1123 int main(void){
1124 char b[20];
1126 snprintf(b, sizeof b, "%s", "string");
1127 dome(b, "string");
1128 return 0;
1131 then
1133 else
1134 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1135 config_exit 1
1138 if link_check environ 'environ(3)' << \!
1139 #include <stdio.h> /* For C89 NULL */
1140 int main(void){
1141 extern char **environ;
1143 return environ[0] == NULL;
1146 then
1148 else
1149 msg 'ERROR: we require the environ(3) array for subprocess control.'
1150 config_exit 1
1153 if link_check termios 'termios.h and tc*(3) family' << \!
1154 #include <termios.h>
1155 int main(void){
1156 struct termios tios;
1158 tcgetattr(0, &tios);
1159 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1160 return 0;
1163 then
1165 else
1166 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1167 msg 'That much Unix we indulge ourselfs.'
1168 config_exit 1
1173 link_check mmap 'mmap(2)' '#define HAVE_MMAP' << \!
1174 #include <sys/types.h>
1175 #include <sys/mman.h>
1176 int main(void)
1178 mmap(0, 0, 0, 0, 0, 0);
1179 return 0;
1183 link_check mremap 'mremap(2)' '#define HAVE_MREMAP' << \!
1184 #include <sys/types.h>
1185 #include <sys/mman.h>
1186 int main(void)
1188 mremap(0, 0, 0, MREMAP_MAYMOVE);
1189 return 0;
1193 run_check pathconf 'pathconf(2)' '#define HAVE_PATHCONF' << \!
1194 #include <unistd.h>
1195 #include <errno.h>
1196 int main(void){
1197 int rv = 0;
1199 errno = 0;
1200 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1201 errno = 0;
1202 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1203 return rv;
1207 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1208 #include <fcntl.h>
1209 #include <unistd.h>
1210 # include <errno.h>
1211 int main(void){
1212 int fds[2];
1214 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1215 return 0;
1216 return 1;
1220 # We use this only then for now (need NOW+1)
1221 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1222 #include <fcntl.h> /* For AT_* */
1223 #include <sys/stat.h>
1224 # include <errno.h>
1225 int main(void){
1226 struct timespec ts[2];
1228 ts[0].tv_nsec = UTIME_NOW;
1229 ts[1].tv_nsec = UTIME_OMIT;
1230 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1231 return 0;
1232 return 1;
1238 # XXX Add POSIX check once standardized
1239 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1240 #include <stdlib.h>
1241 int main(void){
1242 arc4random();
1243 return 0;
1246 then
1248 elif [ -n "${have_no_subsecond_time}" ]; then
1249 msg 'ERROR: %s %s' 'without a native random' \
1250 'one of clock_gettime(2) and gettimeofday(2) is required.'
1251 config_exit 1
1254 link_check setenv 'setenv(3)/unsetenv(3)' '#define HAVE_SETENV' << \!
1255 #include <stdlib.h>
1256 int main(void){
1257 setenv("s-nail", "to be made nifty!", 1);
1258 unsetenv("s-nail");
1259 return 0;
1263 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1264 #include <stdio.h>
1265 int main(void){
1266 putc_unlocked('@', stdout);
1267 return 0;
1271 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1272 #include <unistd.h>
1273 int main(void){
1274 fchdir(0);
1275 return 0;
1279 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1280 #include <locale.h>
1281 int main(void){
1282 setlocale(LC_ALL, "");
1283 return 0;
1287 if [ "${have_setlocale}" = yes ]; then
1288 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1289 '#define HAVE_C90AMEND1' << \!
1290 #include <limits.h>
1291 #include <stdlib.h>
1292 #include <wchar.h>
1293 #include <wctype.h>
1294 int main(void){
1295 char mbb[MB_LEN_MAX + 1];
1296 wchar_t wc;
1298 iswprint(L'c');
1299 towupper(L'c');
1300 mbtowc(&wc, "x", 1);
1301 mbrtowc(&wc, "x", 1, NULL);
1302 wctomb(mbb, wc);
1303 return (mblen("\0", 1) == 0);
1307 if [ "${have_c90amend1}" = yes ]; then
1308 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1309 #include <wchar.h>
1310 int main(void){
1311 wcwidth(L'c');
1312 return 0;
1317 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1318 #include <langinfo.h>
1319 #include <stdlib.h>
1320 int main(void){
1321 nl_langinfo(DAY_1);
1322 return (nl_langinfo(CODESET) == NULL);
1325 fi # have_setlocale
1327 run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1328 #include <stdlib.h>
1329 int main(void){
1330 #if 1 /* TODO for now we use realpath(3) without NULL as 2nd arg! */
1331 /* (And note that on Linux tcc(1) otherwise didn't detect once tested! */
1332 char x_buf[4096], *x = realpath(".", x_buf);
1334 return (x != NULL) ? 0 : 1;
1335 #else
1336 char *x = realpath(".", NULL), *y = realpath("/", NULL);
1338 return (x != NULL && y != NULL) ? 0 : 1;
1339 #endif
1343 link_check wordexp 'wordexp(3)' '#define HAVE_WORDEXP' << \!
1344 #include <stdio.h> /* For C89 NULL */
1345 #include <wordexp.h>
1346 int main(void){
1347 wordexp(NULL, NULL, 0);
1348 return 0;
1354 if feat_yes DEBUG; then
1355 echo '#define HAVE_DEBUG' >> ${h}
1358 if feat_yes AMALGAMATION; then
1359 echo '#define HAVE_AMALGAMATION' >> ${h}
1362 if feat_no NOALLOCA; then
1363 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1364 # versions of alloca(3) since modern compilers just can't be trusted
1365 # not to overoptimize and silently break some code
1366 run_check alloca '__builtin_alloca()' \
1367 '#define HAVE_ALLOCA __builtin_alloca' << \!
1368 #include <stdio.h> /* For C89 NULL */
1369 int main(void){
1370 void *vp = __builtin_alloca(1);
1372 return (vp != NULL);
1377 if feat_yes DEVEL; then
1378 echo '#define HAVE_DEVEL' >> ${h}
1381 if feat_yes NYD2; then
1382 echo '#define HAVE_NYD2' >> ${h}
1387 if feat_yes DOTLOCK; then
1388 if run_check readlink 'readlink(2)' << \!
1389 #include <unistd.h>
1390 # include <errno.h>
1391 int main(void){
1392 char buf[128];
1394 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1395 return 0;
1396 return 1;
1399 then
1401 else
1402 feat_bail_required DOTLOCK
1406 if feat_yes DOTLOCK; then
1407 if run_check fchown 'fchown(2)' << \!
1408 #include <unistd.h>
1409 # include <errno.h>
1410 int main(void){
1411 if(!fchown(0, 0, 0) || errno != ENOSYS)
1412 return 0;
1413 return 1;
1416 then
1418 else
1419 feat_bail_required DOTLOCK
1425 if feat_yes ICONV; then
1426 ${cat} > ${tmp2}.c << \!
1427 #include <stdio.h> /* For C89 NULL */
1428 #include <iconv.h>
1429 int main(void){
1430 iconv_t id;
1432 id = iconv_open("foo", "bar");
1433 iconv(id, NULL, NULL, NULL, NULL);
1434 iconv_close(id);
1435 return 0;
1438 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1439 '#define HAVE_ICONV' ||
1440 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1441 '#define HAVE_ICONV' '-liconv' ||
1442 feat_bail_required ICONV
1443 else
1444 echo '/* WANT_ICONV=0 */' >> ${h}
1445 fi # feat_yes ICONV
1447 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1448 ${cat} > ${tmp2}.c << \!
1449 #include <sys/types.h>
1450 #include <sys/socket.h>
1451 #include <sys/un.h>
1452 # include <errno.h>
1453 int main(void){
1454 struct sockaddr_un soun;
1456 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1457 return 1;
1458 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1459 return 1;
1460 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1461 return 1;
1462 return 0;
1466 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1467 '#define HAVE_UNIX_SOCKETS' ||
1468 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1469 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1470 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1471 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1474 if feat_yes SOCKETS; then
1475 ${cat} > ${tmp2}.c << \!
1476 #include "config.h"
1477 #include <sys/types.h>
1478 #include <sys/socket.h>
1479 #include <netinet/in.h>
1480 # include <errno.h>
1481 int main(void){
1482 struct sockaddr s;
1484 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1485 return 1;
1486 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1487 return 1;
1488 return 0;
1492 < ${tmp2}.c run_check sockets 'sockets' \
1493 '#define HAVE_SOCKETS' ||
1494 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1495 '#define HAVE_SOCKETS' '-lnsl' ||
1496 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1497 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1498 feat_bail_required SOCKETS
1499 else
1500 echo '/* WANT_SOCKETS=0 */' >> ${h}
1501 fi # feat_yes SOCKETS
1503 if feat_yes SOCKETS; then
1504 link_check getaddrinfo 'getaddrinfo(3)' \
1505 '#define HAVE_GETADDRINFO' << \!
1506 #include "config.h"
1507 #include <sys/types.h>
1508 #include <sys/socket.h>
1509 #include <stdio.h>
1510 #include <netdb.h>
1511 int main(void){
1512 struct addrinfo a, *ap;
1513 int lrv;
1515 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1516 case EAI_NONAME:
1517 case EAI_SERVICE:
1518 default:
1519 fprintf(stderr, "%s\n", gai_strerror(lrv));
1520 case 0:
1521 break;
1523 return 0;
1528 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1529 compile_check arpa_inet_h '<arpa/inet.h>' \
1530 '#define HAVE_ARPA_INET_H' << \!
1531 #include "config.h"
1532 #include <sys/types.h>
1533 #include <sys/socket.h>
1534 #include <netdb.h>
1535 #include <netinet/in.h>
1536 #include <arpa/inet.h>
1539 ${cat} > ${tmp2}.c << \!
1540 #include "config.h"
1541 #include <sys/types.h>
1542 #include <sys/socket.h>
1543 #include <stdio.h>
1544 #include <string.h>
1545 #include <netdb.h>
1546 #include <netinet/in.h>
1547 #ifdef HAVE_ARPA_INET_H
1548 #include <arpa/inet.h>
1549 #endif
1550 int main(void){
1551 struct sockaddr_in servaddr;
1552 unsigned short portno;
1553 struct servent *ep;
1554 struct hostent *hp;
1555 struct in_addr **pptr;
1557 portno = 0;
1558 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1559 portno = (unsigned short)ep->s_port;
1561 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1562 pptr = (struct in_addr**)hp->h_addr_list;
1563 if(hp->h_addrtype != AF_INET)
1564 fprintf(stderr, "au\n");
1565 }else{
1566 switch(h_errno){
1567 case HOST_NOT_FOUND:
1568 case TRY_AGAIN:
1569 case NO_RECOVERY:
1570 case NO_DATA:
1571 break;
1572 default:
1573 fprintf(stderr, "au\n");
1574 break;
1578 memset(&servaddr, 0, sizeof servaddr);
1579 servaddr.sin_family = AF_INET;
1580 servaddr.sin_port = htons(portno);
1581 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1582 fprintf(stderr, "Would connect to %s:%d ...\n",
1583 inet_ntoa(**pptr), (int)portno);
1584 return 0;
1588 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1589 < ${tmp2}.c link_check gethostbyname \
1590 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1591 < ${tmp2}.c link_check gethostbyname \
1592 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1593 '' '-lsocket -lnsl' ||
1594 feat_bail_required SOCKETS
1597 feat_yes SOCKETS &&
1598 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1599 #include <sys/socket.h>
1600 #include <stdlib.h>
1601 # include <errno.h>
1602 int main(void){
1603 int sockfd = 3;
1605 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1606 errno == ENOSYS)
1607 return 1;
1608 return 0;
1612 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1613 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1614 #include <sys/socket.h>
1615 #include <stdlib.h>
1616 int main(void){
1617 struct timeval tv;
1618 int sockfd = 3;
1620 tv.tv_sec = 42;
1621 tv.tv_usec = 21;
1622 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1623 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1624 return 0;
1628 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1629 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1630 #include <sys/socket.h>
1631 #include <stdlib.h>
1632 int main(void){
1633 struct linger li;
1634 int sockfd = 3;
1636 li.l_onoff = 1;
1637 li.l_linger = 42;
1638 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1639 return 0;
1643 if feat_yes SSL; then
1644 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1645 '#define HAVE_SSL
1646 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1647 #include <openssl/ssl.h>
1648 #include <openssl/err.h>
1649 #include <openssl/x509v3.h>
1650 #include <openssl/x509.h>
1651 #include <openssl/rand.h>
1652 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1653 # error We need TLSv1.
1654 #endif
1655 int main(void){
1656 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1658 SSL_CTX_free(ctx);
1659 PEM_read_PrivateKey(0, 0, 0, 0);
1660 return 0;
1663 then
1665 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1666 '#define HAVE_SSL
1667 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1668 #include <openssl/ssl.h>
1669 #include <openssl/err.h>
1670 #include <openssl/x509v3.h>
1671 #include <openssl/x509.h>
1672 #include <openssl/rand.h>
1673 #if defined OPENSSL_NO_SSL3 &&\
1674 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1675 # error We need one of SSLv3 and TLSv1.
1676 #endif
1677 int main(void){
1678 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1680 SSL_CTX_free(ctx);
1681 PEM_read_PrivateKey(0, 0, 0, 0);
1682 return 0;
1685 then
1687 else
1688 feat_bail_required SSL
1691 if [ "${have_openssl}" = 'yes' ]; then
1692 compile_check stack_of 'OpenSSL STACK_OF()' \
1693 '#define HAVE_OPENSSL_STACK_OF' << \!
1694 #include <stdio.h> /* For C89 NULL */
1695 #include <openssl/ssl.h>
1696 #include <openssl/err.h>
1697 #include <openssl/x509v3.h>
1698 #include <openssl/x509.h>
1699 #include <openssl/rand.h>
1700 int main(void){
1701 STACK_OF(GENERAL_NAME) *gens = NULL;
1703 printf("%p", gens); /* to use it */
1704 return 0;
1708 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1709 '#define HAVE_OPENSSL_CONFIG' << \!
1710 #include <stdio.h> /* For C89 NULL */
1711 #include <openssl/conf.h>
1712 int main(void){
1713 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1714 CONF_modules_free();
1715 return 0;
1719 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1720 '#define HAVE_OPENSSL_CONF_CTX' << \!
1721 #include "config.h"
1722 #include <openssl/ssl.h>
1723 #include <openssl/err.h>
1724 int main(void){
1725 #if HAVE_OPENSSL < 10100
1726 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1727 #else
1728 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1729 #endif
1730 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1732 SSL_CONF_CTX_set_flags(cctx,
1733 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1734 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1735 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1736 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1737 SSL_CONF_CTX_finish(cctx);
1738 SSL_CONF_CTX_free(cctx);
1739 SSL_CTX_free(ctx);
1740 return 0;
1744 link_check rand_egd 'OpenSSL RAND_egd()' \
1745 '#define HAVE_OPENSSL_RAND_EGD' << \!
1746 #include <openssl/rand.h>
1747 int main(void){
1748 return RAND_egd("some.where") > 0;
1752 if feat_yes SSL_ALL_ALGORITHMS; then
1753 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1754 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1755 #include <openssl/evp.h>
1756 int main(void){
1757 OpenSSL_add_all_algorithms();
1758 EVP_get_cipherbyname("two cents i never exist");
1759 EVP_cleanup();
1760 return 0;
1763 then
1765 else
1766 feat_bail_required SSL_ALL_ALGORITHMS
1768 fi # SSL_ALL_ALGORITHMS
1770 if feat_yes MD5 && feat_no NOEXTMD5; then
1771 run_check openssl_md5 'MD5 digest in OpenSSL' \
1772 '#define HAVE_OPENSSL_MD5' << \!
1773 #include <stdlib.h>
1774 #include <string.h>
1775 #include <openssl/md5.h>
1776 int main(void){
1777 char const dat[] = "abrakadabrafidibus";
1778 char dig[16], hex[16 * 2];
1779 MD5_CTX ctx;
1780 size_t i, j;
1782 memset(dig, 0, sizeof(dig));
1783 memset(hex, 0, sizeof(hex));
1784 MD5_Init(&ctx);
1785 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1786 MD5_Final(dig, &ctx);
1788 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1789 for(i = 0; i < sizeof(hex) / 2; i++){
1790 j = i << 1;
1791 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1792 hex[++j] = hexchar(dig[i] & 0x0f);
1794 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1797 fi # feat_yes MD5 && feat_no NOEXTMD5
1799 else
1800 echo '/* WANT_SSL=0 */' >> ${h}
1801 fi # feat_yes SSL
1803 if feat_yes SMTP; then
1804 echo '#define HAVE_SMTP' >> ${h}
1805 else
1806 echo '/* WANT_SMTP=0 */' >> ${h}
1809 if feat_yes POP3; then
1810 echo '#define HAVE_POP3' >> ${h}
1811 else
1812 echo '/* WANT_POP3=0 */' >> ${h}
1815 if feat_yes IMAP; then
1816 echo '#define HAVE_IMAP' >> ${h}
1817 else
1818 echo '/* WANT_IMAP=0 */' >> ${h}
1821 if feat_yes GSSAPI; then
1822 ${cat} > ${tmp2}.c << \!
1823 #include <gssapi/gssapi.h>
1824 int main(void){
1825 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1826 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1827 return 0;
1830 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1832 if command -v krb5-config >/dev/null 2>&1; then
1833 i=`command -v krb5-config`
1834 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1835 GSS_INCS="`CFLAGS= ${i} --cflags`"
1836 i='GSS-API via krb5-config(1)'
1837 else
1838 GSS_LIBS='-lgssapi'
1839 GSS_INCS=
1840 i='GSS-API in gssapi/gssapi.h, libgssapi'
1842 if < ${tmp2}.c link_check gss \
1843 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1844 < ${tmp3}.c link_check gss \
1845 'GSS-API in gssapi.h, libgssapi' \
1846 '#define HAVE_GSSAPI
1847 #define GSSAPI_REG_INCLUDE' \
1848 '-lgssapi' ||\
1849 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1850 '#define HAVE_GSSAPI' \
1851 '-lgssapi_krb5' ||\
1852 < ${tmp3}.c link_check gss \
1853 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1854 '#define HAVE_GSSAPI
1855 #define GSS_REG_INCLUDE' \
1856 '-lgssapi -lkrb5 -lcrypto' \
1857 '-I/usr/include/kerberosV' ||\
1858 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1859 '#define HAVE_GSSAPI' \
1860 '-lgss' ||\
1861 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1862 '#define HAVE_GSSAPI
1863 #define GSSAPI_OLD_STYLE' \
1864 '-lgssapi_krb5' << \!
1865 #include <gssapi/gssapi.h>
1866 #include <gssapi/gssapi_generic.h>
1867 int main(void){
1868 gss_import_name(0, 0, gss_nt_service_name, 0);
1869 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1870 return 0;
1873 then
1875 else
1876 feat_bail_required GSSAPI
1878 else
1879 echo '/* WANT_GSSAPI=0 */' >> ${h}
1880 fi # feat_yes GSSAPI
1882 if feat_yes NETRC; then
1883 echo '#define HAVE_NETRC' >> ${h}
1884 else
1885 echo '/* WANT_NETRC=0 */' >> ${h}
1888 if feat_yes AGENT; then
1889 echo '#define HAVE_AGENT' >> ${h}
1890 else
1891 echo '/* WANT_AGENT=0 */' >> ${h}
1894 if feat_yes IDNA; then
1895 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
1896 '-lidn' << \!
1897 #include <idna.h>
1898 #include <idn-free.h>
1899 #include <stringprep.h>
1900 int main(void){
1901 char *utf8, *idna_ascii, *idna_utf8;
1903 utf8 = stringprep_locale_to_utf8("does.this.work");
1904 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
1905 != IDNA_SUCCESS)
1906 return 1;
1907 idn_free(idna_ascii);
1908 /* (Rather link check only here) */
1909 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
1910 return 0;
1913 then
1915 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
1916 '-lidnkit' << \!
1917 #include <stdio.h>
1918 #include <idn/api.h>
1919 #include <idn/result.h>
1920 int main(void){
1921 idn_result_t r;
1922 char ace_name[256];
1923 char local_name[256];
1925 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
1926 sizeof(ace_name));
1927 if (r != idn_success) {
1928 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
1929 return 1;
1931 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
1932 if (r != idn_success) {
1933 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
1934 return 1;
1936 return 0;
1939 then
1941 else
1942 feat_bail_required IDNA
1945 if [ -n "${have_idna}" ]; then
1946 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
1947 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
1949 else
1950 echo '/* WANT_IDNA=0 */' >> ${h}
1953 if feat_yes IMAP_SEARCH; then
1954 echo '#define HAVE_IMAP_SEARCH' >> ${h}
1955 else
1956 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
1959 if feat_yes REGEX; then
1960 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
1961 #include <regex.h>
1962 #include <stdlib.h>
1963 int main(void){
1964 int status;
1965 regex_t re;
1967 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
1968 return 1;
1969 status = regexec(&re, "plan9", 0,NULL, 0);
1970 regfree(&re);
1971 return !(status == REG_NOMATCH);
1974 then
1976 else
1977 feat_bail_required REGEX
1979 else
1980 echo '/* WANT_REGEX=0 */' >> ${h}
1983 if feat_yes READLINE; then
1984 __edrdlib() {
1985 link_check readline "for readline(3) (${1})" \
1986 '#define HAVE_READLINE' "${1}" << \!
1987 #include <stdio.h>
1988 #include <readline/history.h>
1989 #include <readline/readline.h>
1990 int main(void){
1991 char *rl;
1992 HISTORY_STATE *hs;
1993 HIST_ENTRY **he;
1994 int i;
1996 using_history();
1997 read_history("");
1998 stifle_history(242);
1999 rl = readline("Enter a line:");
2000 if (rl && *rl)
2001 add_history(rl);
2002 write_history("");
2003 rl_extend_line_buffer(10);
2004 rl_point = rl_end = 10;
2005 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2006 rl_forced_update_display();
2007 clear_history();
2008 hs = history_get_history_state();
2009 i = hs->length;
2010 he = history_list();
2011 if (i > 0)
2012 rl = he[0]->line;
2013 rl_free_line_state();
2014 rl_cleanup_after_signal();
2015 rl_reset_after_signal();
2016 return 0;
2021 __edrdlib -lreadline ||
2022 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2023 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
2026 if feat_yes EDITLINE && [ -z "${have_readline}" ]; then
2027 __edlib() {
2028 link_check editline "for editline(3) (${1})" \
2029 '#define HAVE_EDITLINE' "${1}" << \!
2030 #include <stdio.h> /* For C89 NULL */
2031 #include <histedit.h>
2032 static char * getprompt(void) { return (char*)"ok"; }
2033 int main(void)
2035 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
2036 HistEvent he;
2037 History *el_hcom = history_init();
2038 history(el_hcom, &he, H_SETSIZE, 242);
2039 el_set(el_el, EL_SIGNAL, 0);
2040 el_set(el_el, EL_TERMINAL, NULL);
2041 el_set(el_el, EL_HIST, &history, el_hcom);
2042 el_set(el_el, EL_EDITOR, "emacs");
2043 el_set(el_el, EL_PROMPT, &getprompt);
2044 el_source(el_el, NULL);
2045 history(el_hcom, &he, H_GETSIZE);
2046 history(el_hcom, &he, H_CLEAR);
2047 el_end(el_el);
2048 /* TODO add loader and addfn checks */
2049 history_end(el_hcom);
2050 return 0;
2055 __edlib -ledit ||
2056 __edlib '-ledit -ltermcap' || feat_bail_required EDITLINE
2057 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
2060 if feat_yes NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
2061 [ -n "${have_c90amend1}" ]; then
2062 have_ncl=1
2063 echo '#define HAVE_NCL' >> ${h}
2064 else
2065 feat_bail_required NCL
2066 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
2069 # Generic have-a-command-line-editor switch for those who need it below
2070 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
2071 [ -n "${have_readline}" ]; then
2072 have_cle=1
2075 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2076 echo '#define HAVE_HISTORY' >> ${h}
2077 else
2078 echo '/* WANT_HISTORY=0 */' >> ${h}
2081 if [ -n "${have_cle}" ] && feat_yes TABEXPAND; then
2082 echo '#define HAVE_TABEXPAND' >> ${h}
2083 else
2084 echo '/* WANT_TABEXPAND=0 */' >> ${h}
2087 if feat_yes TERMCAP; then
2088 __termlib() {
2089 link_check termcap "for termcap(3) (via ${4})" \
2090 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2091 #include <stdio.h>
2092 #include <stdlib.h>
2093 #include <string.h>
2094 ${2}
2095 #include <term.h>
2096 #define PTR2SIZE(X) ((unsigned long)(X))
2097 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2098 static char *_termcap_buffer, *_termcap_ti, *_termcap_te;
2099 int main(void){
2100 char buf[1024+512], cmdbuf[2048], *cpb, *cpti, *cpte, *cp;
2102 tgetent(buf, getenv("TERM"));
2103 cpb = cmdbuf;
2104 cpti = cpb;
2105 if ((cp = tgetstr(UNCONST("ti"), &cpb)) == NULL)
2106 goto jleave;
2107 cpte = cpb;
2108 if ((cp = tgetstr(UNCONST("te"), &cpb)) == NULL)
2109 goto jleave;
2110 _termcap_buffer = malloc(PTR2SIZE(cpb - cmdbuf));
2111 memcpy(_termcap_buffer, cmdbuf, PTR2SIZE(cpb - cmdbuf));
2112 _termcap_ti = _termcap_buffer + PTR2SIZE(cpti - cmdbuf);
2113 _termcap_te = _termcap_ti + PTR2SIZE(cpte - cpti);
2114 tputs(_termcap_ti, 1, &putchar);
2115 tputs(_termcap_te, 1, &putchar);
2116 jleave:
2117 return (cp == NULL);
2119 _EOT
2122 __termlib -ltermcap '' '' termcap ||
2123 __termlib -ltermcap '#include <curses.h>' '
2124 #define HAVE_TERMCAP_CURSES' \
2125 'curses.h / -ltermcap' ||
2126 __termlib -lcurses '#include <curses.h>' '
2127 #define HAVE_TERMCAP_CURSES' \
2128 'curses.h / -lcurses' ||
2129 feat_bail_required TERMCAP
2130 else
2131 echo '/* WANT_TERMCAP=0 */' >> ${h}
2134 if feat_yes ERRORS; then
2135 echo '#define HAVE_ERRORS' >> ${h}
2136 else
2137 echo '/* WANT_ERRORS=0 */' >> ${h}
2142 if feat_yes SPAM_SPAMC; then
2143 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2144 if command -v spamc >/dev/null 2>&1; then
2145 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2147 else
2148 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2151 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2152 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2153 else
2154 feat_bail_required SPAM_SPAMD
2155 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2158 if feat_yes SPAM_FILTER; then
2159 echo '#define HAVE_SPAM_FILTER' >> ${h}
2160 else
2161 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
2164 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2165 echo '#define HAVE_SPAM' >> ${h}
2166 else
2167 echo '/* HAVE_SPAM */' >> ${h}
2170 if feat_yes DOCSTRINGS; then
2171 echo '#define HAVE_DOCSTRINGS' >> ${h}
2172 else
2173 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
2176 if feat_yes QUOTE_FOLD &&\
2177 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2178 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2179 else
2180 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2183 if feat_yes FILTER_HTML_TAGSOUP; then
2184 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2185 else
2186 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2189 if feat_yes COLOUR; then
2190 echo '#define HAVE_COLOUR' >> ${h}
2191 else
2192 echo '/* WANT_COLOUR=0 */' >> ${h}
2195 if feat_yes DOTLOCK; then
2196 echo '#define HAVE_DOTLOCK' >> ${h}
2197 else
2198 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2201 if feat_yes MD5; then
2202 echo '#define HAVE_MD5' >> ${h}
2203 else
2204 echo '/* WANT_MD5=0 */' >> ${h}
2207 ## Summarizing
2209 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2210 squeeze_em() {
2211 < "${1}" > "${2}" ${awk} \
2212 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2214 ${rm} -f ${tmp}
2215 squeeze_em ${inc} ${tmp}
2216 ${mv} ${tmp} ${inc}
2217 squeeze_em ${lib} ${tmp}
2218 ${mv} ${tmp} ${lib}
2220 # config.h
2221 ${mv} ${h} ${tmp}
2222 printf '#ifndef _CONFIG_H\n# define _CONFIG_H 1\n' > ${h}
2223 ${cat} ${tmp} >> ${h}
2224 ${rm} -f ${tmp}
2226 printf '\n/* The "feature string" */\n' >> ${h}
2227 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2228 printf 'static char const _features[] = "MIME"\n' >> ${h}
2229 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2230 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2231 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2232 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2233 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2234 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2235 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2236 >> ${h}
2237 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2238 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2239 printf '# ifdef HAVE_IMAP\n ",IMAP"\n# endif\n' >> ${h}
2240 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2241 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2242 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2243 printf '# ifdef HAVE_AGENT\n ",AGENT"\n# endif\n' >> ${h}
2244 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2245 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2246 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2247 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2248 printf '# ifdef HAVE_EDITLINE\n ",EDITLINE"\n# endif\n' >> ${h}
2249 printf '# ifdef HAVE_NCL\n ",NCL"\n# endif\n' >> ${h}
2250 printf '# ifdef HAVE_TABEXPAND\n ",TABEXPAND"\n# endif\n' >> ${h}
2251 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2252 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2253 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2254 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2255 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2256 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2257 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2258 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2259 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2260 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2261 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2262 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2263 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2265 # Create the real mk.mk
2266 # Note we cannout use explicit ./ filename prefix for source and object
2267 # pathnames because of a bug in bmake(1)
2268 ${rm} -rf ${tmp0}.* ${tmp0}*
2269 printf 'OBJ_SRC = ' >> ${mk}
2270 if feat_no AMALGAMATION; then
2271 for i in `printf '%s\n' *.c | ${sort}`; do
2272 if [ "${i}" = privsep.c ]; then
2273 continue
2275 printf "${i} " >> ${mk}
2276 done
2277 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2278 else
2279 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2281 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2282 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2283 printf '# undef _CONFIG_H\n' >> ${h}
2284 printf '# define _CONFIG_H 2\n' >> ${h}
2285 for i in `printf '%s\n' *.c | ${sort}`; do
2286 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2287 [ "${i}" = privsep.c ]; then
2288 continue
2290 printf "${i} " >> ${mk}
2291 printf "# include \"${i}\"\n" >> ${h}
2292 done
2293 echo >> ${mk}
2294 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2295 echo '#else' >> ${h}
2298 printf '#endif /* _CONFIG_H */\n' >> ${h}
2300 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2301 echo "INCS = `${cat} ${inc}`" >> ${mk}
2302 echo >> ${mk}
2303 ${cat} ./mk-mk.in >> ${mk}
2305 ## Finished!
2307 ${cat} > ${tmp2}.c << \!
2308 #include "config.h"
2310 :The following optional features are enabled:
2311 #ifdef HAVE_SETLOCALE
2312 : + Locale support: Printable characters depend on the environment
2313 # ifdef HAVE_C90AMEND1
2314 : + Multibyte character support
2315 # endif
2316 # ifdef HAVE_NL_LANGINFO
2317 : + Automatic detection of terminal character set
2318 # endif
2319 #endif
2320 #ifdef HAVE_ICONV
2321 : + Character set conversion using iconv()
2322 #endif
2323 #ifdef HAVE_SOCKETS
2324 : + Network support
2325 #endif
2326 #ifdef HAVE_SSL
2327 # ifdef HAVE_OPENSSL
2328 : + S/MIME and SSL/TLS (OpenSSL)
2329 # endif
2330 # ifdef HAVE_SSL_ALL_ALGORITHMS
2331 : + + Support for more ("all") digest and cipher algorithms
2332 # endif
2333 #endif
2334 #ifdef HAVE_SMTP
2335 : + SMTP protocol
2336 #endif
2337 #ifdef HAVE_POP3
2338 : + POP3 protocol
2339 #endif
2340 #ifdef HAVE_IMAP
2341 : + IMAP protocol
2342 #endif
2343 #ifdef HAVE_GSSAPI
2344 : + GSS-API authentication
2345 #endif
2346 #ifdef HAVE_MD5
2347 : + MD5 message digest (APOP, CRAM-MD5)
2348 #endif
2349 #ifdef HAVE_NETRC
2350 : + .netrc file support
2351 #endif
2352 #ifdef HAVE_AGENT
2353 : + Password query through agent
2354 #endif
2355 #ifdef HAVE_IDNA
2356 : + IDNA (internationalized domain names for applications) support
2357 #endif
2358 #ifdef HAVE_IMAP_SEARCH
2359 : + IMAP-style search expressions
2360 #endif
2361 #ifdef HAVE_REGEX
2362 : + Regular expression support (searches, conditional expressions etc.)
2363 #endif
2364 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
2365 # ifdef HAVE_READLINE
2366 : + Command line editing via readline(3)
2367 # elif defined HAVE_EDITLINE
2368 : + Command line editing via editline(3)
2369 # else
2370 : + Command line editing via N(ail) C(ommand) L(ine)
2371 # endif
2372 # ifdef HAVE_TABEXPAND
2373 : + + Tabulator expansion
2374 # endif
2375 # ifdef HAVE_HISTORY
2376 : + + History management
2377 # endif
2378 #endif
2379 #ifdef HAVE_TERMCAP
2380 : + Terminal capability queries
2381 #endif
2382 #ifdef HAVE_SPAM
2383 : + Spam management
2384 # ifdef HAVE_SPAM_SPAMC
2385 : + + Via spamc(1) (of spamassassin(1))
2386 # endif
2387 # ifdef HAVE_SPAM_SPAMD
2388 : + + Directly via spamd(1) (of spamassassin(1))
2389 # endif
2390 # ifdef HAVE_SPAM_FILTER
2391 : + + Via freely configurable *spam-filter-XY*s
2392 # endif
2393 #endif
2394 #ifdef HAVE_DOCSTRINGS
2395 : + Documentation summary strings
2396 #endif
2397 #ifdef HAVE_QUOTE_FOLD
2398 : + Extended *quote-fold*ing
2399 #endif
2400 #ifdef HAVE_FILTER_HTML_TAGSOUP
2401 : + Builtin HTML-to-text filter (for display purposes, primitive)
2402 #endif
2403 #ifdef HAVE_COLOUR
2404 : + Coloured message display (simple)
2405 #endif
2406 #ifdef HAVE_DOTLOCK
2407 : + Dotlock files and privilege-separated file dotlock program
2408 #endif
2410 :The following optional features are disabled:
2411 #ifndef HAVE_SETLOCALE
2412 : - Locale support: Only ASCII characters are recognized
2413 #endif
2414 # ifndef HAVE_C90AMEND1
2415 : - Multibyte character support
2416 # endif
2417 # ifndef HAVE_NL_LANGINFO
2418 : - Automatic detection of terminal character set
2419 # endif
2420 #ifndef HAVE_ICONV
2421 : - Character set conversion using iconv()
2422 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2423 #endif
2424 #ifndef HAVE_SOCKETS
2425 : - Network support
2426 #endif
2427 #ifndef HAVE_SSL
2428 : - S/MIME and SSL/TLS
2429 #else
2430 # ifndef HAVE_SSL_ALL_ALGORITHMS
2431 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2432 # endif
2433 #endif
2434 #ifndef HAVE_SMTP
2435 : - SMTP protocol
2436 #endif
2437 #ifndef HAVE_POP3
2438 : - POP3 protocol
2439 #endif
2440 #ifndef HAVE_IMAP
2441 : - IMAP protocol
2442 #endif
2443 #ifndef HAVE_GSSAPI
2444 : - GSS-API authentication
2445 #endif
2446 #ifndef HAVE_MD5
2447 : - MD5 message digest (APOP, CRAM-MD5)
2448 #endif
2449 #ifndef HAVE_NETRC
2450 : - .netrc file support
2451 #endif
2452 #ifndef HAVE_AGENT
2453 : - Password query through agent
2454 #endif
2455 #ifndef HAVE_IDNA
2456 : - IDNA (internationalized domain names for applications) support
2457 #endif
2458 #ifndef HAVE_IMAP_SEARCH
2459 : - IMAP-style search expressions
2460 #endif
2461 #ifndef HAVE_REGEX
2462 : - Regular expression support
2463 #endif
2464 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2465 : - Command line editing and history
2466 #endif
2467 #ifndef HAVE_TERMCAP
2468 : - Terminal capability queries
2469 #endif
2470 #ifndef HAVE_SPAM
2471 : - Spam management
2472 #endif
2473 #ifndef HAVE_DOCSTRINGS
2474 : - Documentation summary strings
2475 #endif
2476 #ifndef HAVE_QUOTE_FOLD
2477 : - Extended *quote-fold*ing
2478 #endif
2479 #ifndef HAVE_FILTER_HTML_TAGSOUP
2480 : - Builtin HTML-to-text filter (for display purposes, primitive)
2481 #endif
2482 #ifndef HAVE_COLOUR
2483 : - Coloured message display (simple)
2484 #endif
2485 #ifndef HAVE_DOTLOCK
2486 : - Dotlock files and privilege-separated file dotlock program
2487 #endif
2489 #if !defined HAVE_WORDEXP || !defined HAVE_FCHDIR ||\
2490 defined HAVE_DEBUG || defined HAVE_DEVEL
2491 :Remarks:
2492 # ifndef HAVE_WORDEXP
2493 : . WARNING: the function wordexp(3) could not be found.
2494 : _ This means that echo(1) will be used via the sh(1)ell in order
2495 : _ to expand shell meta characters in filenames, which is a potential
2496 : _ security hole. Consider to either upgrade your system or set the
2497 : _ *SHELL* variable to some safe(r) wrapper script.
2498 : _ P.S.: the codebase is in transition away from wordexp(3) to some
2499 : _ safe (restricted) internal mechanism, see "COMMANDS" manual, read
2500 : _ about shell word expression in its introduction for more on that.
2501 # endif
2502 # ifndef HAVE_FCHDIR
2503 : . The function fchdir(2) could not be found. We will use chdir(2)
2504 : _ instead. This is not a problem unless the current working
2505 : _ directory of mailx is moved while the IMAP cache is used.
2506 # endif
2507 # ifdef HAVE_DEBUG
2508 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2509 # endif
2510 # ifdef HAVE_DEVEL
2511 : . Computers do not blunder.
2512 # endif
2514 #endif /* Remarks */
2515 :Setup:
2516 : . System-wide resource file: SYSCONFRC
2517 : . bindir: BINDIR
2518 #ifdef HAVE_DOTLOCK
2519 : . libexecdir: LIBEXECDIR
2520 #endif
2521 : . mandir: MANDIR
2522 : . sendmail(1): SENDMAIL (argv[0] = SENDMAIL_PROGNAME)
2523 : . Mail spool directory: MAILSPOOL
2527 ${make} -f ${makefile} ${tmp2}.x
2528 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
2530 # s-it-mode