mk-conf.sh: do not use strcpy(), avoid linker warning (sigh)
[s-mailx.git] / mk-conf.sh
blob239c750ac0e36958460c529ebd8dfe5b57d1578d
1 #!/bin/sh -
2 #@ Please see `INSTALL' and `make.rc' instead.
4 LC_ALL=C
5 export LC_ALL
7 option_reset() {
8 WANT_ICONV=0
9 WANT_SOCKETS=0
10 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
11 WANT_SMTP=0 WANT_POP3=0
12 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
13 #WANT_MD5=0
14 WANT_IDNA=0
15 WANT_IMAP_SEARCH=0
16 WANT_REGEX=0
17 WANT_READLINE=0 WANT_MLE=0
18 WANT_HISTORY=0 WANT_KEY_BINDINGS=0
19 WANT_TERMCAP=0 WANT_TERMCAP_PREFER_TERMINFO=0
20 WANT_ERRORS=0
21 WANT_SPAM_SPAMC=0 WANT_SPAM_SPAMD=0 WANT_SPAM_FILTER=0
22 WANT_DOCSTRINGS=0
23 WANT_QUOTE_FOLD=0
24 WANT_FILTER_HTML_TAGSOUP=0
25 WANT_COLOUR=0
26 WANT_DOTLOCK=0
29 option_maximal() {
30 WANT_ICONV=require
31 WANT_SOCKETS=1
32 WANT_SSL=1 WANT_ALL_SSL_ALGORITHMS=1
33 WANT_SMTP=1 WANT_POP3=1
34 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
35 #WANT_MD5=1
36 WANT_IDNA=1
37 WANT_IMAP_SEARCH=1
38 WANT_REGEX=require
39 WANT_MLE=1
40 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
41 WANT_TERMCAP=1 WANT_TERMCAP_PREFER_TERMINFO=1
42 WANT_ERRORS=1
43 WANT_SPAM_SPAMC=1 WANT_SPAM_SPAMD=1 WANT_SPAM_FILTER=1
44 WANT_DOCSTRINGS=1
45 WANT_QUOTE_FOLD=1
46 WANT_FILTER_HTML_TAGSOUP=1
47 WANT_COLOUR=1
48 WANT_DOTLOCK=require
51 # Predefined CONFIG= urations take precedence over anything else
52 if [ -n "${CONFIG}" ]; then
53 case "${CONFIG}" in
54 [nN][uU][lL][lL])
55 option_reset
57 [nN][uU][lL][lL][iI])
58 option_reset
59 WANT_ICONV=require
61 [mM][iI][nN][iI][mM][aA][lL])
62 option_reset
63 WANT_ICONV=1
64 WANT_REGEX=1
65 WANT_DOTLOCK=require
67 [mM][eE][dD][iI][uU][mM])
68 option_reset
69 WANT_ICONV=require
70 WANT_IDNA=1
71 WANT_REGEX=1
72 WANT_MLE=1
73 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
74 WANT_ERRORS=1
75 WANT_SPAM_FILTER=1
76 WANT_DOCSTRINGS=1
77 WANT_COLOUR=1
78 WANT_DOTLOCK=require
80 [nN][eE][tT][sS][eE][nN][dD])
81 option_reset
82 WANT_ICONV=require
83 WANT_SOCKETS=1
84 WANT_SSL=require
85 WANT_SMTP=require
86 WANT_GSSAPI=1 WANT_NETRC=1 WANT_AGENT=1
87 WANT_IDNA=1
88 WANT_REGEX=1
89 WANT_MLE=1
90 WANT_HISTORY=1 WANT_KEY_BINDINGS=1
91 WANT_DOCSTRINGS=1
92 WANT_COLOUR=1
93 WANT_DOTLOCK=require
95 [mM][aA][xX][iI][mM][aA][lL])
96 option_reset
97 option_maximal
99 [dD][eE][vV][eE][lL])
100 WANT_DEVEL=1 WANT_DEBUG=1 WANT_NYD2=1
101 option_maximal
103 [oO][dD][eE][vV][eE][lL])
104 WANT_DEVEL=1
105 option_maximal
108 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
109 echo >&2 'Possible values: NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
110 exit 1
112 esac
115 # Inter-relationships
116 option_update() {
117 if feat_no SMTP && feat_no POP3; then
118 WANT_SOCKETS=0
120 if feat_no SOCKETS; then
121 if feat_require SMTP; then
122 msg 'ERROR: need SOCKETS for required feature SMTP'
123 config_exit 13
125 if feat_require POP3; then
126 msg 'ERROR: need SOCKETS for required feature POP3'
127 config_exit 13
129 WANT_SSL=0 WANT_ALL_SSL_ALGORITHMS=0
130 WANT_SMTP=0 WANT_POP3=0
131 WANT_GSSAPI=0 WANT_NETRC=0 WANT_AGENT=0
133 if feat_no SMTP; then
134 WANT_GSSAPI=0
137 if feat_no READLINE && feat_no MLE; then
138 WANT_HISTORY=0 WANT_KEY_BINDINGS=0
141 # If we don't need MD5 leave it alone
142 if feat_no SOCKETS; then
143 WANT_MD5=0
146 if feat_yes DEVEL; then
147 WANT_DEBUG=1
149 if feat_yes DEBUG; then
150 WANT_NOALLOCA=1 WANT_DEVEL=1
154 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
155 # via path_check() later on once possible
157 # TODO cc_maxopt is brute simple, we should compile test program and dig real
158 # compiler versions for known compilers, then be more specific
159 cc_maxopt=100
160 _CFLAGS= _LDFLAGS=
162 os_early_setup() {
163 i="${OS:-`uname -s`}"
165 if [ ${i} = SunOS ]; then
166 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
167 _os_early_setup_sunos
171 os_setup() {
172 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
173 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
174 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
175 msg 'Operating system is "%s"' ${OS}
177 if [ ${OS} = sunos ]; then
178 msg ' . have special SunOS / Solaris "setup" rules ...'
179 _os_setup_sunos
180 elif [ ${OS} = unixware ]; then
181 msg ' . have special UnixWare environmental rules ...'
182 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
183 CC=cc
184 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
186 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
187 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
188 export CC CFLAGS LDFLAGS
189 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
191 elif [ -n "${VERBOSE}" ]; then
192 msg ' . no special treatment for this system necessary or known'
195 # Sledgehammer: better set _GNU_SOURCE
196 # And in general: oh, boy!
197 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
198 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
199 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
200 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
202 # On pkgsrc(7) systems automatically add /usr/pkg/*
203 if [ -d /usr/pkg ]; then
204 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
205 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
209 _os_early_setup_sunos() {
210 # According to standards(5), this is what we need to do
211 if [ -d /usr/xpg4 ]; then :; else
212 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
213 config_exit 1
215 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
216 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
217 export PATH
220 _os_setup_sunos() {
221 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
222 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
224 # Include packages
225 if [ -d /opt/csw ]; then
226 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
227 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
230 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
231 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
233 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
234 if [ -x "${cksum}" ]; then :; else
235 msg 'ERROR: Not an executable program: "%s"' "${cksum}"
236 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
237 msg 'ERROR: However, we do so only for tests.'
238 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
239 config_exit 1
242 if feat_yes AUTOCC; then
243 if command -v cc >/dev/null 2>&1; then
244 CC=cc
245 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
247 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
248 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
249 export CC CFLAGS LDFLAGS
250 WANT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
251 else
252 # Assume gcc(1), which supports -R for compat
253 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
258 # Check out compiler ($CC) and -flags ($CFLAGS)
259 cc_setup() {
260 # Even though it belongs into cc_flags we will try to compile and link
261 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
262 # ADDCFLAGS/ADDLDFLAGS
263 if feat_no AUTOCC; then
264 _cc_default
265 # Ensure those don't do any harm
266 ADDCFLAGS= ADDLDFLAGS=
267 export ADDCFLAGS ADDLDFLAGS
268 return
269 else
270 CFLAGS= LDFLAGS=
271 export CFLAGS LDFLAGS
274 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
276 printf >&2 'Searching for a usable C compiler .. $CC='
277 if { i="`command -v clang`"; }; then
278 CC=${i}
279 elif { i="`command -v gcc`"; }; then
280 CC=${i}
281 elif { i="`command -v c99`"; }; then
282 CC=${i}
283 elif { i="`command -v tcc`"; }; then
284 CC=${i}
285 elif { i="`command -v pcc`"; }; then
286 CC=${i}
287 else
288 if [ "${CC}" = cc ]; then
290 elif { i="`command -v c89`"; }; then
291 CC=${i}
292 else
293 printf >&2 'boing booom tschak\n'
294 msg 'ERROR: I cannot find a compiler!'
295 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
296 msg ' Please set $CC environment variable, maybe $CFLAGS also, rerun.'
297 config_exit 1
300 printf >&2 -- '"%s"\n' "${CC}"
301 export CC
304 _cc_default() {
305 if [ -z "${CC}" ]; then
306 printf >&2 'To go on like you have chosen, please set $CC, rerun.'
307 config_exit 1
310 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
312 else
313 msg 'Using C compiler $CC="%s"' "${CC}"
317 cc_flags() {
318 if feat_yes AUTOCC; then
319 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
320 cc_check_silent=1
321 msg 'Detecting $CFLAGS/$LDFLAGS for $CC="%s", just a second..' "${CC}"
322 else
323 cc_check_silent=
324 msg 'Testing usable $CFLAGS/$LDFLAGS for $CC="%s"' "${CC}"
327 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
328 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
329 msg ' . have special tcc(1) environmental rules ...'
330 _cc_flags_tcc
331 else
332 # As of pcc CVS 2016-04-02, stack protection support is announced but
333 # will break if used on Linux
334 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
335 force_no_stackprot=1
337 _cc_flags_generic
340 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
341 CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
342 LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}"
343 else
344 if feat_no DEBUG; then
345 CFLAGS="-DNDEBUG ${CFLAGS}"
348 msg ''
349 export CFLAGS LDFLAGS
352 _cc_flags_tcc() {
353 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
354 _CFLAGS= _LDFLAGS=
356 cc_check -Wall
357 cc_check -Wextra
358 cc_check -pedantic
360 if feat_yes DEBUG; then
361 # May have problems to find libtcc cc_check -b
362 cc_check -g
365 if ld_check -Wl,-rpath =./ no; then
366 need_R_ldflags=-Wl,-rpath=
367 ld_runtime_flags # update!
370 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
371 unset __cflags __ldflags
374 _cc_flags_generic() {
375 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
376 _CFLAGS= _LDFLAGS=
377 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
379 # Check -g first since some others may rely upon -g / optim. level
380 if feat_yes DEBUG; then
381 cc_check -O
382 cc_check -g
383 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
385 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
387 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
389 else
390 cc_check -O
393 if feat_yes DEVEL && cc_check -Weverything; then
395 else
396 cc_check -Wall
397 cc_check -Wextra
398 cc_check -Wbad-function-cast
399 cc_check -Wcast-align
400 cc_check -Wcast-qual
401 cc_check -Winit-self
402 cc_check -Wmissing-prototypes
403 cc_check -Wshadow
404 cc_check -Wunused
405 cc_check -Wwrite-strings
406 cc_check -Wno-long-long
408 cc_check -pedantic
410 if feat_yes AMALGAMATION && feat_no DEVEL; then
411 cc_check -Wno-unused-function
413 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
415 cc_check -fno-unwind-tables
416 cc_check -fno-asynchronous-unwind-tables
417 cc_check -fstrict-aliasing
418 if cc_check -fstrict-overflow && feat_yes DEVEL; then
419 cc_check -Wstrict-overflow=5
422 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
423 if [ -z "${force_no_stackprot}" ]; then
424 if cc_check -fstack-protector-strong ||
425 cc_check -fstack-protector-all; then
426 cc_check -D_FORTIFY_SOURCE=2
428 else
429 msg 'Not checking for -fstack-protector compiler option,'
430 msg 'since that caused errors in a "similar" configuration.'
431 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
435 if feat_yes AMALGAMATION; then
436 cc_check -pipe
439 # LD (+ dependend CC)
441 if feat_yes DEVEL; then
442 _ccfg=${_CFLAGS}
443 # -fsanitize=address
444 #if cc_check -fsanitize=memory &&
445 # ld_check -fsanitize=memory &&
446 # cc_check -fsanitize-memory-track-origins=2 &&
447 # ld_check -fsanitize-memory-track-origins=2; then
449 #else
450 # _CFLAGS=${_ccfg}
454 ld_check -Wl,-z,relro
455 ld_check -Wl,-z,now
456 ld_check -Wl,-z,noexecstack
457 if ld_check -Wl,-rpath =./ no; then
458 need_R_ldflags=-Wl,-rpath=
459 ld_runtime_flags # update!
460 elif ld_check -Wl,-R ./ no; then
461 need_R_ldflags=-Wl,-R
462 ld_runtime_flags # update!
465 # Address randomization
466 _ccfg=${_CFLAGS}
467 if cc_check -fPIE || cc_check -fpie; then
468 ld_check -pie || _CFLAGS=${_ccfg}
470 unset _ccfg
472 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
473 unset __cflags __ldflags
476 ## -- >8 -- 8< -- ##
478 ## Notes:
479 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
480 ## redirection, so use "printf '' >" instead
482 ## Very first: we undergo several states regarding I/O redirection etc.,
483 ## but need to deal with option updates from within all. Since all the
484 ## option stuff should be above the scissor line, define utility functions
485 ## and redefine them as necessary.
486 ## And, since we have those functions, simply use them for whatever
488 config_exit() {
489 exit ${1}
492 msg() {
493 fmt=${1}
494 shift
495 printf >&2 -- "${fmt}\\n" "${@}"
498 ## First of all, create new configuration and check wether it changed
500 rc=./make.rc
501 lst=./config.lst
502 h=./config.h h_name=config.h
503 mk=./mk.mk
505 newlst=./config.lst-new
506 newmk=./config.mk-new
507 newh=./config.h-new
508 tmp0=___tmp
509 tmp=./${tmp0}1$$
510 tmp2=./${tmp0}2$$
512 t1=ten10one1ten10one1
513 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
514 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
515 ) > /dev/null 2>&1; then
516 good_shell=1
517 else
518 unset good_shell
520 unset t1
522 # We need some standard utilities
523 unset -f command
524 check_tool() {
525 n=${1} i=${2} opt=${3:-0}
526 # Evaluate, just in case user comes in with shell snippets (..well..)
527 eval i="${i}"
528 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
529 [ -n "${VERBOSE}" ] && msg ' . $%s ... "%s"' "${n}" "${i}"
530 eval ${n}=${i}
531 return 0
533 if [ ${opt} -eq 0 ]; then
534 msg 'ERROR: no trace of utility "%s"' "${n}"
535 config_exit 1
537 return 1
540 # Very easy checks for the operating system in order to be able to adjust paths
541 # or similar very basic things which we need to be able to go at all
542 os_early_setup
544 # Check those tools right now that we need before including $rc
545 msg 'Checking for basic utility set'
546 check_tool awk "${awk:-`command -v awk`}"
547 check_tool rm "${rm:-`command -v rm`}"
548 check_tool tr "${tr:-`command -v tr`}"
550 # Our feature check environment
551 feat_val_no() {
552 [ "x${1}" = x0 ] ||
553 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
556 feat_val_yes() {
557 [ "x${1}" = x1 ] ||
558 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
559 [ "x${1}" = xrequire ]
562 feat_val_require() {
563 [ "x${1}" = xrequire ]
566 _feat_check() {
567 eval i=\$WANT_${1}
568 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
569 if feat_val_no "${i}"; then
570 return 1
571 elif feat_val_yes "${i}"; then
572 return 0
573 else
574 msg "ERROR: %s: any of 0/false/no/off or 1/true/yes/on/require, got: %s" \
575 "${1}" "${i}"
576 config_exit 11
580 feat_yes() {
581 _feat_check ${1}
584 feat_no() {
585 _feat_check ${1} && return 1
586 return 0
589 feat_require() {
590 eval i=\$WANT_${1}
591 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
592 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
595 feat_bail_required() {
596 if feat_require ${1}; then
597 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
598 config_exit 13
600 eval WANT_${1}=0
601 option_update # XXX this is rather useless here (dependency chain..)
604 path_check() {
605 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
606 varname=${1} addflag=${2} flagvarname=${3}
607 j=${IFS}
608 IFS=:
609 eval "set -- \$${1}"
610 IFS=${j}
611 j= k= y= z=
612 for i
614 [ -z "${i}" ] && continue
615 [ -d "${i}" ] || continue
616 if [ -n "${j}" ]; then
617 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
619 else
620 y="${y} :${i}:"
621 j="${j}:${i}"
622 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
624 else
625 y=" :${i}:"
626 j="${i}"
627 [ -n "${addflag}" ] && k="${addflag}${i}"
629 done
630 eval "${varname}=\"${j}\""
631 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
632 unset varname
635 ld_runtime_flags() {
636 if [ -n "${need_R_ldflags}" ]; then
637 i=${IFS}
638 IFS=:
639 set -- ${LD_LIBRARY_PATH}
640 IFS=${i}
641 for i
643 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
644 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
645 done
646 export LDFLAGS
648 # Disable it for a possible second run.
649 need_R_ldflags=
652 cc_check() {
653 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
654 if "${CC}" ${INCS} ${_CFLAGS} ${1} ${ADDCFLAGS} ${_LDFLAGS} ${ADDLDFLAGS} \
655 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
656 _CFLAGS="${_CFLAGS} ${1}"
657 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
658 return 0
660 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
661 return 1
664 ld_check() {
665 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
666 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
667 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${ADDLDFLAGS} \
668 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
669 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
670 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
671 return 0
673 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
674 return 1
677 # Include $rc, but only take from it what wasn't overwritten by the user from
678 # within the command line or from a chosen fixed CONFIG=
679 # Note we leave alone the values
680 trap "exit 1" HUP INT TERM
681 trap "${rm} -f ${tmp}" EXIT
683 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
684 ${rm} -f ${tmp}
685 # We want read(1) to perform backslash escaping in order to be able to use
686 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
687 # VMs (see [fa2e248]), Aharon Robbins suggested the following
688 < ${rc} ${awk} 'BEGIN{line = ""}{
689 gsub(/^[[:space:]]+/, "", $0)
690 gsub(/[[:space:]]+$/, "", $0)
691 if(gsub(/\\$/, "", $0)){
692 line = line $0
693 next
694 }else
695 line = line $0
696 if(index(line, "#") == 1){
697 line = ""
698 }else if(length(line)){
699 print line
700 line = ""
702 }' |
703 while read line; do
704 if [ -n "${good_shell}" ]; then
705 i=${line%%=*}
706 else
707 i=`${awk} -v LINE="${line}" 'BEGIN{
708 gsub(/=.*$/, "", LINE)
709 print LINE
712 if [ "${i}" = "${line}" ]; then
713 msg 'ERROR: invalid syntax in "%s"' "${line}"
714 continue
717 eval j="\$${i}" jx="\${${i}+x}"
718 if [ -n "${j}" ] || [ "${jx}" = x ]; then
719 : # Yet present
720 else
721 j=`${awk} -v LINE="${line}" 'BEGIN{
722 gsub(/^[^=]*=/, "", LINE)
723 gsub(/^\"*/, "", LINE)
724 gsub(/\"*$/, "", LINE)
725 print LINE
728 [ "${i}" = "DESTDIR" ] && continue
729 echo "${i}=\"${j}\""
730 done > ${tmp}
731 # Reread the mixed version right now
732 . ./${tmp}
733 printf >&2 'done\n'
735 # We need to know about that now, in order to provide utility overwrites etc.
736 os_setup
738 msg 'Checking for remaining set of utilities'
739 check_tool grep "${grep:-`command -v grep`}"
741 # Before we step ahead with the other utilities perform a path cleanup first.
742 path_check PATH
744 # awk(1) above
745 check_tool cat "${cat:-`command -v cat`}"
746 check_tool chmod "${chmod:-`command -v chmod`}"
747 check_tool cp "${cp:-`command -v cp`}"
748 check_tool cmp "${cmp:-`command -v cmp`}"
749 # grep(1) above
750 check_tool mkdir "${mkdir:-`command -v mkdir`}"
751 check_tool mv "${mv:-`command -v mv`}"
752 # rm(1) above
753 check_tool sed "${sed:-`command -v sed`}"
754 check_tool sort "${sort:-`command -v sort`}"
755 check_tool tee "${tee:-`command -v tee`}"
757 check_tool chown "${chown:-`command -v chown`}" 1 ||
758 check_tool chown "/sbin/chown" 1 ||
759 check_tool chown "/usr/sbin/chown"
761 check_tool make "${MAKE:-`command -v make`}"
762 MAKE=${make}
763 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
764 HAVE_STRIP=1 || HAVE_STRIP=0
766 # For ./cc-test.sh only
767 check_tool cksum "${cksum:-`command -v cksum`}"
769 # Update WANT_ options now, in order to get possible inter-dependencies right
770 option_update
772 # (No functions since some shells loose non-exported variables in traps)
773 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
774 trap "trap \"\" HUP INT TERM EXIT;\
775 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newh}" EXIT
777 # Our configuration options may at this point still contain shell snippets,
778 # we need to evaluate them in order to get them expanded, and we need those
779 # evaluated values not only in our new configuration file, but also at hand..
780 printf >&2 'Evaluating all configuration items ... '
781 ${rm} -f ${newlst} ${newmk} ${newh}
782 exec 5<&0 6>&1 <${tmp} >${newlst}
783 while read line; do
785 if [ -n "${good_shell}" ]; then
786 i=${line%%=*}
787 [ "${i}" != "${i#WANT_}" ] && z=1
788 else
789 i=`${awk} -v LINE="${line}" 'BEGIN{
790 gsub(/=.*$/, "", LINE);\
791 print LINE
793 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
798 eval j=\$${i}
799 if [ -n "${z}" ]; then
800 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
801 if [ -z "${j}" ] || feat_val_no "${j}"; then
803 printf "/*#define ${i}*/\n" >> ${newh}
804 elif feat_val_yes "${j}"; then
805 if feat_val_require "${j}"; then
806 j=require
807 else
810 printf "#define ${i}\n" >> ${newh}
811 else
812 msg 'ERROR: cannot parse <%s>' "${line}"
813 config_exit 1
815 else
816 printf "#define ${i} \"${j}\"\n" >> ${newh}
818 printf "${i} = ${j}\n" >> ${newmk}
819 printf "${i}=${j}\n"
820 eval "${i}=\"${j}\""
821 done
822 exec 0<&5 1>&6 5<&- 6<&-
823 printf >&2 'done\n'
825 # Add the known utility and some other variables
826 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
827 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
829 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
830 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
831 if feat_yes DOTLOCK; then
832 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
833 else
834 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
837 for i in \
838 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
839 MAKE make strip \
840 cksum; do
841 eval j=\$${i}
842 printf "${i} = ${j}\n" >> ${newmk}
843 printf "${i}=${j}\n" >> ${newlst}
844 done
846 # Build a basic set of INCS and LIBS according to user environment.
847 path_check C_INCLUDE_PATH -I _INCS
848 INCS="${INCS} ${_INCS}"
849 path_check LD_LIBRARY_PATH -L _LIBS
850 LIBS="${LIBS} ${_LIBS}"
851 unset _INCS _LIBS
852 export C_INCLUDE_PATH LD_LIBRARY_PATH
854 # Some environments need runtime path flags to be able to go at all
855 ld_runtime_flags
857 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
859 cc_setup
861 ${cat} > ${tmp}.c << \!
862 #include <stdio.h>
863 #include <string.h>
864 static void doit(char const *s);
866 main(int argc, char **argv){
867 (void)argc;
868 (void)argv;
869 doit("Hello world");
870 return 0;
872 static void
873 doit(char const *s){
874 char buf[12];
875 memcpy(buf, s, strlen(s) +1);
876 puts(s);
880 if "${CC}" ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} \
881 -o ${tmp2} ${tmp}.c ${LIBS}; then
883 else
884 msg 'ERROR: i cannot compile a "Hello world" via'
885 msg ' %s' \
886 "${CC} ${INCS} ${CFLAGS} ${ADDCFLAGS} ${LDFLAGS} ${ADDLDFLAGS} ${LIBS}"
887 msg 'ERROR: Please read INSTALL, rerun'
888 config_exit 1
891 # This may also update ld_runtime_flags() (again)
892 cc_flags
894 for i in \
895 INCS LIBS \
896 ; do
897 eval j=\$${i}
898 printf -- "${i}=${j}\n" >> ${newlst}
899 done
900 for i in \
901 CC \
902 CFLAGS \
903 LDFLAGS \
904 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
905 OSFULLSPEC \
906 ; do
907 eval j=\$${i}
908 printf -- "${i} = ${j}\n" >> ${newmk}
909 printf -- "${i}=${j}\n" >> ${newlst}
910 done
912 # Now finally check wether we already have a configuration and if so, wether
913 # all those parameters are still the same.. or something has actually changed
914 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
915 echo 'Configuration is up-to-date'
916 exit 0
917 elif [ -f ${lst} ]; then
918 echo 'Configuration has been updated..'
919 ( eval "${MAKE} -f ./mk.mk clean" )
920 echo
921 else
922 echo 'Shiny configuration..'
925 # Time to redefine helper 1
926 config_exit() {
927 ${rm} -f ${lst} ${h} ${mk}
928 exit ${1}
931 ${mv} -f ${newlst} ${lst}
932 ${mv} -f ${newh} ${h}
933 ${mv} -f ${newmk} ${mk}
935 ## Compile and link checking
937 tmp3=./${tmp0}3$$
938 log=./config.log
939 lib=./config.lib
940 inc=./config.inc
941 makefile=./config.mk
943 # (No function since some shells loose non-exported variables in traps)
944 trap "trap \"\" HUP INT TERM;\
945 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
946 trap "trap \"\" HUP INT TERM EXIT;\
947 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
949 # Time to redefine helper 2
950 msg() {
951 fmt=${1}
952 shift
953 printf "*** ${fmt}\\n" "${@}"
954 printf -- "${fmt}\\n" "${@}" >&5
956 msg_nonl() {
957 fmt=${1}
958 shift
959 printf "*** ${fmt}\\n" "${@}"
960 printf -- "${fmt}" "${@}" >&5
963 exec 5>&2 > ${log} 2>&1
965 echo "${LIBS}" > ${lib}
966 echo "${INCS}" > ${inc}
967 ${cat} > ${makefile} << \!
968 .SUFFIXES: .o .c .x .y
969 .c.o:
970 $(CC) -I./ $(XINCS) $(CFLAGS) -c $<
971 .c.x:
972 $(CC) -I./ $(XINCS) -E $< >$@
974 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(XLIBS)
975 .y: ;
978 _check_preface() {
979 variable=$1 topic=$2 define=$3
981 echo '**********'
982 msg_nonl ' . %s ... ' "${topic}"
983 echo "/* checked ${topic} */" >> ${h}
984 ${rm} -f ${tmp} ${tmp}.o
985 echo '*** test program is'
986 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
987 #echo '*** the preprocessor generates'
988 #${make} -f ${makefile} ${tmp}.x
989 #${cat} ${tmp}.x
990 echo '*** results are'
993 compile_check() {
994 variable=$1 topic=$2 define=$3
996 _check_preface "${variable}" "${topic}" "${define}"
998 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
999 [ -f ./${tmp}.o ]; then
1000 msg 'yes'
1001 echo "${define}" >> ${h}
1002 eval have_${variable}=yes
1003 return 0
1004 else
1005 echo "/* ${define} */" >> ${h}
1006 msg 'no'
1007 eval unset have_${variable}
1008 return 1
1012 _link_mayrun() {
1013 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1015 _check_preface "${variable}" "${topic}" "${define}"
1017 feat_yes CROSS_BUILD && run=0
1019 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1020 XLIBS="${LIBS} ${libs}" ./${tmp} &&
1021 [ -f ./${tmp} ] &&
1022 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1023 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1024 msg 'yes'
1025 echo "${define}" >> ${h}
1026 LIBS="${LIBS} ${libs}"
1027 echo "${libs}" >> ${lib}
1028 INCS="${INCS} ${incs}"
1029 echo "${incs}" >> ${inc}
1030 eval have_${variable}=yes
1031 return 0
1032 else
1033 msg 'no'
1034 echo "/* ${define} */" >> ${h}
1035 eval unset have_${variable}
1036 return 1
1040 link_check() {
1041 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1044 run_check() {
1045 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1050 # May be multiline..
1051 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1052 feat_yes CROSS_BUILD && msg ' . CROSS_BUILD enabled, not _running_ tests'
1054 if run_check inline '"inline" functions' \
1055 '#define HAVE_INLINE
1056 #define n_INLINE static inline' << \!
1057 static inline int ilf(int i){return ++i;}
1058 int main(void){return ilf(-1);}
1060 then
1062 elif run_check inline '"__inline" functions' \
1063 '#define HAVE_INLINE
1064 #define n_INLINE static __inline' << \!
1065 static __inline int ilf(int i){return ++i;}
1066 int main(void){return ilf(-1);}
1068 then
1072 if run_check endian 'Little endian byteorder' \
1073 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1074 int main(void){
1075 enum {vBig = 1, vLittle = 0};
1076 union {unsigned short bom; unsigned char buf[2];} u;
1077 u.bom = 0xFEFF;
1078 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1081 then
1087 if run_check clock_gettime 'clock_gettime(2)' \
1088 '#define HAVE_CLOCK_GETTIME' << \!
1089 #include <time.h>
1090 # include <errno.h>
1091 int main(void){
1092 struct timespec ts;
1094 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1095 return 0;
1096 return 1;
1099 then
1101 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1102 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1103 #include <time.h>
1104 # include <errno.h>
1105 int main(void){
1106 struct timespec ts;
1108 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1109 return 0;
1110 return 1;
1113 then
1115 elif run_check gettimeofday 'gettimeofday(2)' \
1116 '#define HAVE_GETTIMEOFDAY' << \!
1117 #include <stdio.h> /* For C89 NULL */
1118 #include <sys/time.h>
1119 # include <errno.h>
1120 int main(void){
1121 struct timeval tv;
1123 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1124 return 0;
1125 return 1;
1128 then
1130 else
1131 have_no_subsecond_time=1
1134 if run_check nanosleep 'nanosleep(2)' \
1135 '#define HAVE_NANOSLEEP' << \!
1136 #include <time.h>
1137 # include <errno.h>
1138 int main(void){
1139 struct timespec ts;
1141 ts.tv_sec = 1;
1142 ts.tv_nsec = 100000;
1143 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1144 return 0;
1145 return 1;
1148 then
1150 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1151 '#define HAVE_NANOSLEEP' '-lrt' << \!
1152 #include <time.h>
1153 # include <errno.h>
1154 int main(void){
1155 struct timespec ts;
1157 ts.tv_sec = 1;
1158 ts.tv_nsec = 100000;
1159 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1160 return 0;
1161 return 1;
1164 then
1166 # link_check is enough for this, that function is so old, trust the proto
1167 elif link_check sleep 'sleep(3)' \
1168 '#define HAVE_SLEEP' << \!
1169 #include <unistd.h>
1170 # include <errno.h>
1171 int main(void){
1172 if(!sleep(1) || errno != ENOSYS)
1173 return 0;
1174 return 1;
1177 then
1179 else
1180 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1181 config_exit 1
1184 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1185 #include <pwd.h>
1186 #include <unistd.h>
1187 # include <errno.h>
1188 int main(void){
1189 struct passwd *pw;
1190 gid_t gid;
1191 uid_t uid;
1193 if((gid = getgid()) != 0)
1194 gid = getegid();
1195 if((uid = getuid()) != 0)
1196 uid = geteuid();
1197 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1198 return 1;
1199 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1200 return 1;
1201 return 0;
1204 then
1206 else
1207 msg 'ERROR: we require user and group info / database searches.'
1208 msg 'That much Unix we indulge ourselfs.'
1209 config_exit 1
1212 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1213 #include <signal.h>
1214 # include <errno.h>
1215 int main(void){
1216 struct sigaction nact, oact;
1218 nact.sa_handler = SIG_DFL;
1219 sigemptyset(&nact.sa_mask);
1220 nact.sa_flags = SA_RESTART;
1221 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1224 then
1226 else
1227 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1228 config_exit 1
1231 if link_check snprintf 'v?snprintf(3)' << \!
1232 #include <stdarg.h>
1233 #include <stdio.h>
1234 static void dome(char *buf, ...){
1235 va_list ap;
1237 va_start(ap, buf);
1238 vsnprintf(buf, 20, "%s", ap);
1239 va_end(ap);
1240 return;
1242 int main(void){
1243 char b[20];
1245 snprintf(b, sizeof b, "%s", "string");
1246 dome(b, "string");
1247 return 0;
1250 then
1252 else
1253 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1254 config_exit 1
1257 if link_check environ 'environ(3)' << \!
1258 #include <stdio.h> /* For C89 NULL */
1259 int main(void){
1260 extern char **environ;
1262 return environ[0] == NULL;
1265 then
1267 else
1268 msg 'ERROR: we require the environ(3) array for subprocess control.'
1269 config_exit 1
1272 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1273 #include <stdlib.h>
1274 int main(void){
1275 setenv("s-mailx", "i want to see it cute!", 1);
1276 unsetenv("s-mailx");
1277 return 0;
1280 then
1282 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1283 #include <stdlib.h>
1284 int main(void){
1285 putenv("s-mailx=i want to see it cute!");
1286 return 0;
1289 then
1291 else
1292 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1293 config_exit 1
1296 if link_check termios 'termios.h and tc*(3) family' << \!
1297 #include <termios.h>
1298 int main(void){
1299 struct termios tios;
1301 tcgetattr(0, &tios);
1302 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1303 return 0;
1306 then
1308 else
1309 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1310 msg 'That much Unix we indulge ourselfs.'
1311 config_exit 1
1316 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1317 #include <unistd.h>
1318 #include <errno.h>
1319 int main(void){
1320 int rv = 0;
1322 errno = 0;
1323 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1324 errno = 0;
1325 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1327 /* Only link check */
1328 fpathconf(0, _PC_NAME_MAX);
1330 return rv;
1334 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1335 #include <fcntl.h>
1336 #include <unistd.h>
1337 # include <errno.h>
1338 int main(void){
1339 int fds[2];
1341 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1342 return 0;
1343 return 1;
1347 # We use this only then for now (need NOW+1)
1348 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1349 #include <fcntl.h> /* For AT_* */
1350 #include <sys/stat.h>
1351 # include <errno.h>
1352 int main(void){
1353 struct timespec ts[2];
1355 ts[0].tv_nsec = UTIME_NOW;
1356 ts[1].tv_nsec = UTIME_OMIT;
1357 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1358 return 0;
1359 return 1;
1365 # XXX Add POSIX check once standardized
1366 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1367 #include <stdlib.h>
1368 int main(void){
1369 arc4random();
1370 return 0;
1373 then
1375 elif [ -n "${have_no_subsecond_time}" ]; then
1376 msg 'ERROR: %s %s' 'without a native random' \
1377 'one of clock_gettime(2) and gettimeofday(2) is required.'
1378 config_exit 1
1381 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1382 #include <stdio.h>
1383 int main(void){
1384 putc_unlocked('@', stdout);
1385 return 0;
1389 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1390 #include <unistd.h>
1391 int main(void){
1392 fchdir(0);
1393 return 0;
1397 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1398 #include <locale.h>
1399 int main(void){
1400 setlocale(LC_ALL, "");
1401 return 0;
1405 if [ "${have_setlocale}" = yes ]; then
1406 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1407 '#define HAVE_C90AMEND1' << \!
1408 #include <limits.h>
1409 #include <stdlib.h>
1410 #include <wchar.h>
1411 #include <wctype.h>
1412 int main(void){
1413 char mbb[MB_LEN_MAX + 1];
1414 wchar_t wc;
1416 iswprint(L'c');
1417 towupper(L'c');
1418 mbtowc(&wc, "x", 1);
1419 mbrtowc(&wc, "x", 1, NULL);
1420 wctomb(mbb, wc);
1421 return (mblen("\0", 1) == 0);
1425 if [ "${have_c90amend1}" = yes ]; then
1426 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1427 #include <wchar.h>
1428 int main(void){
1429 wcwidth(L'c');
1430 return 0;
1435 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1436 #include <langinfo.h>
1437 #include <stdlib.h>
1438 int main(void){
1439 nl_langinfo(DAY_1);
1440 return (nl_langinfo(CODESET) == NULL);
1443 fi # have_setlocale
1445 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1446 #include <stdlib.h>
1447 int main(void){
1448 char x_buf[4096], *x = realpath(".", x_buf);
1450 return (x != NULL) ? 0 : 1;
1453 then
1454 if run_check realpath_malloc 'realpath(3) takes NULL' \
1455 '#define HAVE_REALPATH_NULL' << \!
1456 #include <stdlib.h>
1457 int main(void){
1458 char *x = realpath(".", NULL);
1460 if(x != NULL)
1461 free(x);
1462 return (x != NULL) ? 0 : 1;
1465 then
1470 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1471 #include <fnmatch.h>
1472 int main(void){
1473 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1477 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1478 #include <dirent.h>
1479 int main(void){
1480 struct dirent de;
1481 return !(de.d_type == DT_UNKNOWN ||
1482 de.d_type == DT_DIR || de.d_type == DT_LNK);
1488 if feat_yes DEBUG; then
1489 echo '#define HAVE_DEBUG' >> ${h}
1492 if feat_yes AMALGAMATION; then
1493 echo '#define HAVE_AMALGAMATION' >> ${h}
1496 if feat_no NOALLOCA; then
1497 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1498 # versions of alloca(3) since modern compilers just can't be trusted
1499 # not to overoptimize and silently break some code
1500 run_check alloca '__builtin_alloca()' \
1501 '#define HAVE_ALLOCA __builtin_alloca' << \!
1502 #include <stdio.h> /* For C89 NULL */
1503 int main(void){
1504 void *vp = __builtin_alloca(1);
1506 return (vp != NULL);
1511 if feat_yes DEVEL; then
1512 echo '#define HAVE_DEVEL' >> ${h}
1515 if feat_yes NYD2; then
1516 echo '#define HAVE_NYD2' >> ${h}
1521 if feat_yes DOTLOCK; then
1522 if run_check readlink 'readlink(2)' << \!
1523 #include <unistd.h>
1524 # include <errno.h>
1525 int main(void){
1526 char buf[128];
1528 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1529 return 0;
1530 return 1;
1533 then
1535 else
1536 feat_bail_required DOTLOCK
1540 if feat_yes DOTLOCK; then
1541 if run_check fchown 'fchown(2)' << \!
1542 #include <unistd.h>
1543 # include <errno.h>
1544 int main(void){
1545 if(!fchown(0, 0, 0) || errno != ENOSYS)
1546 return 0;
1547 return 1;
1550 then
1552 else
1553 feat_bail_required DOTLOCK
1559 if feat_yes ICONV; then
1560 ${cat} > ${tmp2}.c << \!
1561 #include <stdio.h> /* For C89 NULL */
1562 #include <iconv.h>
1563 int main(void){
1564 iconv_t id;
1566 id = iconv_open("foo", "bar");
1567 iconv(id, NULL, NULL, NULL, NULL);
1568 iconv_close(id);
1569 return 0;
1572 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1573 '#define HAVE_ICONV' ||
1574 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1575 '#define HAVE_ICONV' '-liconv' ||
1576 feat_bail_required ICONV
1577 else
1578 echo '/* WANT_ICONV=0 */' >> ${h}
1579 fi # feat_yes ICONV
1581 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1582 ${cat} > ${tmp2}.c << \!
1583 #include <sys/types.h>
1584 #include <sys/socket.h>
1585 #include <sys/un.h>
1586 # include <errno.h>
1587 int main(void){
1588 struct sockaddr_un soun;
1590 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1591 return 1;
1592 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1593 return 1;
1594 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1595 return 1;
1596 return 0;
1600 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1601 '#define HAVE_UNIX_SOCKETS' ||
1602 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1603 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1604 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1605 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1608 if feat_yes SOCKETS; then
1609 ${cat} > ${tmp2}.c << \!
1610 #include "config.h"
1611 #include <sys/types.h>
1612 #include <sys/socket.h>
1613 #include <netinet/in.h>
1614 # include <errno.h>
1615 int main(void){
1616 struct sockaddr s;
1618 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1619 return 1;
1620 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1621 return 1;
1622 return 0;
1626 < ${tmp2}.c run_check sockets 'sockets' \
1627 '#define HAVE_SOCKETS' ||
1628 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1629 '#define HAVE_SOCKETS' '-lnsl' ||
1630 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1631 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1632 feat_bail_required SOCKETS
1633 else
1634 echo '/* WANT_SOCKETS=0 */' >> ${h}
1635 fi # feat_yes SOCKETS
1637 if feat_yes SOCKETS; then
1638 link_check getaddrinfo 'getaddrinfo(3)' \
1639 '#define HAVE_GETADDRINFO' << \!
1640 #include "config.h"
1641 #include <sys/types.h>
1642 #include <sys/socket.h>
1643 #include <stdio.h>
1644 #include <netdb.h>
1645 int main(void){
1646 struct addrinfo a, *ap;
1647 int lrv;
1649 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1650 case EAI_NONAME:
1651 case EAI_SERVICE:
1652 default:
1653 fprintf(stderr, "%s\n", gai_strerror(lrv));
1654 case 0:
1655 break;
1657 return 0;
1662 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1663 compile_check arpa_inet_h '<arpa/inet.h>' \
1664 '#define HAVE_ARPA_INET_H' << \!
1665 #include "config.h"
1666 #include <sys/types.h>
1667 #include <sys/socket.h>
1668 #include <netdb.h>
1669 #include <netinet/in.h>
1670 #include <arpa/inet.h>
1673 ${cat} > ${tmp2}.c << \!
1674 #include "config.h"
1675 #include <sys/types.h>
1676 #include <sys/socket.h>
1677 #include <stdio.h>
1678 #include <string.h>
1679 #include <netdb.h>
1680 #include <netinet/in.h>
1681 #ifdef HAVE_ARPA_INET_H
1682 #include <arpa/inet.h>
1683 #endif
1684 int main(void){
1685 struct sockaddr_in servaddr;
1686 unsigned short portno;
1687 struct servent *ep;
1688 struct hostent *hp;
1689 struct in_addr **pptr;
1691 portno = 0;
1692 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1693 portno = (unsigned short)ep->s_port;
1695 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1696 pptr = (struct in_addr**)hp->h_addr_list;
1697 if(hp->h_addrtype != AF_INET)
1698 fprintf(stderr, "au\n");
1699 }else{
1700 switch(h_errno){
1701 case HOST_NOT_FOUND:
1702 case TRY_AGAIN:
1703 case NO_RECOVERY:
1704 case NO_DATA:
1705 break;
1706 default:
1707 fprintf(stderr, "au\n");
1708 break;
1712 memset(&servaddr, 0, sizeof servaddr);
1713 servaddr.sin_family = AF_INET;
1714 servaddr.sin_port = htons(portno);
1715 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1716 fprintf(stderr, "Would connect to %s:%d ...\n",
1717 inet_ntoa(**pptr), (int)portno);
1718 return 0;
1722 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1723 < ${tmp2}.c link_check gethostbyname \
1724 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1725 < ${tmp2}.c link_check gethostbyname \
1726 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1727 '' '-lsocket -lnsl' ||
1728 feat_bail_required SOCKETS
1731 feat_yes SOCKETS &&
1732 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1733 #include <sys/socket.h>
1734 #include <stdlib.h>
1735 # include <errno.h>
1736 int main(void){
1737 int sockfd = 3;
1739 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1740 errno == ENOSYS)
1741 return 1;
1742 return 0;
1746 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1747 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1748 #include <sys/socket.h>
1749 #include <stdlib.h>
1750 int main(void){
1751 struct timeval tv;
1752 int sockfd = 3;
1754 tv.tv_sec = 42;
1755 tv.tv_usec = 21;
1756 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1757 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1758 return 0;
1762 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1763 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1764 #include <sys/socket.h>
1765 #include <stdlib.h>
1766 int main(void){
1767 struct linger li;
1768 int sockfd = 3;
1770 li.l_onoff = 1;
1771 li.l_linger = 42;
1772 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1773 return 0;
1777 if feat_yes SSL; then
1778 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1779 '#define HAVE_SSL
1780 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1781 #include <openssl/ssl.h>
1782 #include <openssl/err.h>
1783 #include <openssl/x509v3.h>
1784 #include <openssl/x509.h>
1785 #include <openssl/rand.h>
1786 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1787 # error We need TLSv1.
1788 #endif
1789 int main(void){
1790 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1792 SSL_CTX_free(ctx);
1793 PEM_read_PrivateKey(0, 0, 0, 0);
1794 return 0;
1797 then
1799 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1800 '#define HAVE_SSL
1801 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1802 #include <openssl/ssl.h>
1803 #include <openssl/err.h>
1804 #include <openssl/x509v3.h>
1805 #include <openssl/x509.h>
1806 #include <openssl/rand.h>
1807 #if defined OPENSSL_NO_SSL3 &&\
1808 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1809 # error We need one of SSLv3 and TLSv1.
1810 #endif
1811 int main(void){
1812 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1814 SSL_CTX_free(ctx);
1815 PEM_read_PrivateKey(0, 0, 0, 0);
1816 return 0;
1819 then
1821 else
1822 feat_bail_required SSL
1825 if [ "${have_openssl}" = 'yes' ]; then
1826 compile_check stack_of 'OpenSSL STACK_OF()' \
1827 '#define HAVE_OPENSSL_STACK_OF' << \!
1828 #include <stdio.h> /* For C89 NULL */
1829 #include <openssl/ssl.h>
1830 #include <openssl/err.h>
1831 #include <openssl/x509v3.h>
1832 #include <openssl/x509.h>
1833 #include <openssl/rand.h>
1834 int main(void){
1835 STACK_OF(GENERAL_NAME) *gens = NULL;
1837 printf("%p", gens); /* to use it */
1838 return 0;
1842 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1843 '#define HAVE_OPENSSL_CONFIG' << \!
1844 #include <stdio.h> /* For C89 NULL */
1845 #include <openssl/conf.h>
1846 int main(void){
1847 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1848 CONF_modules_free();
1849 return 0;
1853 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1854 '#define HAVE_OPENSSL_CONF_CTX' << \!
1855 #include "config.h"
1856 #include <openssl/ssl.h>
1857 #include <openssl/err.h>
1858 int main(void){
1859 #if HAVE_OPENSSL < 10100
1860 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1861 #else
1862 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1863 #endif
1864 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1866 SSL_CONF_CTX_set_flags(cctx,
1867 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1868 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1869 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1870 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1871 SSL_CONF_CTX_finish(cctx);
1872 SSL_CONF_CTX_free(cctx);
1873 SSL_CTX_free(ctx);
1874 return 0;
1878 link_check rand_egd 'OpenSSL RAND_egd(3ssl)' \
1879 '#define HAVE_OPENSSL_RAND_EGD' << \!
1880 #include <openssl/rand.h>
1881 int main(void){
1882 return RAND_egd("some.where") > 0;
1886 if feat_yes SSL_ALL_ALGORITHMS; then
1887 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1888 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1889 #include <openssl/evp.h>
1890 int main(void){
1891 OpenSSL_add_all_algorithms();
1892 EVP_get_cipherbyname("two cents i never exist");
1893 EVP_cleanup();
1894 return 0;
1897 then
1899 else
1900 feat_bail_required SSL_ALL_ALGORITHMS
1902 fi # SSL_ALL_ALGORITHMS
1904 if feat_yes MD5 && feat_no NOEXTMD5; then
1905 run_check openssl_md5 'MD5 digest in OpenSSL' \
1906 '#define HAVE_OPENSSL_MD5' << \!
1907 #include <stdlib.h>
1908 #include <string.h>
1909 #include <openssl/md5.h>
1910 int main(void){
1911 char const dat[] = "abrakadabrafidibus";
1912 char dig[16], hex[16 * 2];
1913 MD5_CTX ctx;
1914 size_t i, j;
1916 memset(dig, 0, sizeof(dig));
1917 memset(hex, 0, sizeof(hex));
1918 MD5_Init(&ctx);
1919 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1920 MD5_Final(dig, &ctx);
1922 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1923 for(i = 0; i < sizeof(hex) / 2; i++){
1924 j = i << 1;
1925 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1926 hex[++j] = hexchar(dig[i] & 0x0f);
1928 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1931 fi # feat_yes MD5 && feat_no NOEXTMD5
1933 else
1934 echo '/* WANT_SSL=0 */' >> ${h}
1935 fi # feat_yes SSL
1937 if feat_yes SMTP; then
1938 echo '#define HAVE_SMTP' >> ${h}
1939 else
1940 echo '/* WANT_SMTP=0 */' >> ${h}
1943 if feat_yes POP3; then
1944 echo '#define HAVE_POP3' >> ${h}
1945 else
1946 echo '/* WANT_POP3=0 */' >> ${h}
1949 if feat_yes GSSAPI; then
1950 ${cat} > ${tmp2}.c << \!
1951 #include <gssapi/gssapi.h>
1952 int main(void){
1953 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1954 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1955 return 0;
1958 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1960 if command -v krb5-config >/dev/null 2>&1; then
1961 i=`command -v krb5-config`
1962 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1963 GSS_INCS="`CFLAGS= ${i} --cflags`"
1964 i='GSS-API via krb5-config(1)'
1965 else
1966 GSS_LIBS='-lgssapi'
1967 GSS_INCS=
1968 i='GSS-API in gssapi/gssapi.h, libgssapi'
1970 if < ${tmp2}.c link_check gss \
1971 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
1972 < ${tmp3}.c link_check gss \
1973 'GSS-API in gssapi.h, libgssapi' \
1974 '#define HAVE_GSSAPI
1975 #define GSSAPI_REG_INCLUDE' \
1976 '-lgssapi' ||\
1977 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
1978 '#define HAVE_GSSAPI' \
1979 '-lgssapi_krb5' ||\
1980 < ${tmp3}.c link_check gss \
1981 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
1982 '#define HAVE_GSSAPI
1983 #define GSS_REG_INCLUDE' \
1984 '-lgssapi -lkrb5 -lcrypto' \
1985 '-I/usr/include/kerberosV' ||\
1986 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
1987 '#define HAVE_GSSAPI' \
1988 '-lgss' ||\
1989 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
1990 '#define HAVE_GSSAPI
1991 #define GSSAPI_OLD_STYLE' \
1992 '-lgssapi_krb5' << \!
1993 #include <gssapi/gssapi.h>
1994 #include <gssapi/gssapi_generic.h>
1995 int main(void){
1996 gss_import_name(0, 0, gss_nt_service_name, 0);
1997 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1998 return 0;
2001 then
2003 else
2004 feat_bail_required GSSAPI
2006 else
2007 echo '/* WANT_GSSAPI=0 */' >> ${h}
2008 fi # feat_yes GSSAPI
2010 if feat_yes NETRC; then
2011 echo '#define HAVE_NETRC' >> ${h}
2012 else
2013 echo '/* WANT_NETRC=0 */' >> ${h}
2016 if feat_yes AGENT; then
2017 echo '#define HAVE_AGENT' >> ${h}
2018 else
2019 echo '/* WANT_AGENT=0 */' >> ${h}
2022 if feat_yes IDNA; then
2023 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2024 '-lidn' << \!
2025 #include <idna.h>
2026 #include <idn-free.h>
2027 #include <stringprep.h>
2028 int main(void){
2029 char *utf8, *idna_ascii, *idna_utf8;
2031 utf8 = stringprep_locale_to_utf8("does.this.work");
2032 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2033 != IDNA_SUCCESS)
2034 return 1;
2035 idn_free(idna_ascii);
2036 /* (Rather link check only here) */
2037 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2038 return 0;
2041 then
2043 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2044 '-lidnkit' << \!
2045 #include <stdio.h>
2046 #include <idn/api.h>
2047 #include <idn/result.h>
2048 int main(void){
2049 idn_result_t r;
2050 char ace_name[256];
2051 char local_name[256];
2053 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2054 sizeof(ace_name));
2055 if (r != idn_success) {
2056 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2057 return 1;
2059 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2060 if (r != idn_success) {
2061 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2062 return 1;
2064 return 0;
2067 then
2069 else
2070 feat_bail_required IDNA
2073 if [ -n "${have_idna}" ]; then
2074 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2075 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2077 else
2078 echo '/* WANT_IDNA=0 */' >> ${h}
2081 if feat_yes IMAP_SEARCH; then
2082 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2083 else
2084 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
2087 if feat_yes REGEX; then
2088 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2089 #include <regex.h>
2090 #include <stdlib.h>
2091 int main(void){
2092 int status;
2093 regex_t re;
2095 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2096 return 1;
2097 status = regexec(&re, "plan9", 0,NULL, 0);
2098 regfree(&re);
2099 return !(status == REG_NOMATCH);
2102 then
2104 else
2105 feat_bail_required REGEX
2107 else
2108 echo '/* WANT_REGEX=0 */' >> ${h}
2111 if feat_yes READLINE; then
2112 __edrdlib() {
2113 link_check readline "for readline(3) (${1})" \
2114 '#define HAVE_READLINE' "${1}" << \!
2115 #include <stdio.h>
2116 #include <readline/history.h>
2117 #include <readline/readline.h>
2118 int main(void){
2119 char *rl;
2120 HISTORY_STATE *hs;
2121 HIST_ENTRY **he;
2122 int i;
2124 using_history();
2125 read_history("");
2126 stifle_history(242);
2127 rl = readline("Enter a line:");
2128 if (rl && *rl)
2129 add_history(rl);
2130 write_history("");
2131 rl_extend_line_buffer(10);
2132 rl_point = rl_end = 10;
2133 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2134 rl_forced_update_display();
2135 clear_history();
2136 hs = history_get_history_state();
2137 i = hs->length;
2138 he = history_list();
2139 if (i > 0)
2140 rl = he[0]->line;
2141 rl_free_line_state();
2142 rl_cleanup_after_signal();
2143 rl_reset_after_signal();
2144 return 0;
2149 __edrdlib -lreadline ||
2150 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2153 if feat_yes MLE && [ -z "${have_readline}" ] &&
2154 [ -n "${have_c90amend1}" ]; then
2155 have_mle=1
2156 echo '#define HAVE_MLE' >> ${h}
2157 else
2158 feat_bail_required MLE
2159 echo '/* WANT_{READLINE,MLE}=0 */' >> ${h}
2162 # Generic have-a-line-editor switch for those who need it below
2163 if [ -n "${have_mle}" ] ||
2164 [ -n "${have_readline}" ]; then
2165 have_cle=1
2168 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2169 echo '#define HAVE_HISTORY' >> ${h}
2170 else
2171 echo '/* WANT_HISTORY=0 */' >> ${h}
2174 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2175 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2176 else
2177 echo '/* WANT_KEY_BINDINGS=0 */' >> ${h}
2180 if feat_yes TERMCAP; then
2181 __termcaplib() {
2182 link_check termcap "termcap(5) (via ${4})" \
2183 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2184 #include <stdio.h>
2185 #include <stdlib.h>
2186 ${2}
2187 #include <term.h>
2188 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2189 static int my_putc(int c){return putchar(c);}
2190 int main(void){
2191 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2192 int r2 = OK, r3 = ERR;
2194 tgetent(buf, getenv("TERM"));
2195 cpb = cmdbuf;
2196 r1 = tgetstr(UNCONST("cm"), &cpb);
2197 tgoto(r1, 1, 1);
2198 r2 = tgetnum(UNCONST("Co"));
2199 r3 = tgetflag(UNCONST("ut"));
2200 tputs("cr", 1, &my_putc);
2201 return (r1 == NULL || r2 == -1 || r3 == 0);
2203 _EOT
2206 __terminfolib() {
2207 link_check terminfo "terminfo(5) (via ${2})" \
2208 '#define HAVE_TERMCAP
2209 #define HAVE_TERMCAP_CURSES
2210 #define HAVE_TERMINFO' "${1}" << _EOT
2211 #include <stdio.h>
2212 #include <curses.h>
2213 #include <term.h>
2214 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2215 static int my_putc(int c){return putchar(c);}
2216 int main(void){
2217 int er, r0, r1, r2;
2218 char *r3, *tp;
2220 er = OK;
2221 r0 = setupterm(NULL, 1, &er);
2222 r1 = tigetflag(UNCONST("bce"));
2223 r2 = tigetnum(UNCONST("colors"));
2224 r3 = tigetstr(UNCONST("cr"));
2225 tp = tparm(r3, NULL);
2226 tputs(tp, 1, &my_putc);
2227 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2228 r3 == (char*)-1 || r3 == NULL);
2230 _EOT
2233 if feat_yes TERMCAP_PREFER_TERMINFO; then
2234 __terminfolib -ltinfo -ltinfo ||
2235 __terminfolib -lcurses -lcurses ||
2236 __terminfolib -lcursesw -lcursesw ||
2237 feat_bail_required TERMCAP_PREFER_TERMINFO
2240 if [ -z "${have_terminfo}" ]; then
2241 __termcaplib -ltermcap '' '' '-ltermcap' ||
2242 __termcaplib -ltermcap '#include <curses.h>' '
2243 #define HAVE_TERMCAP_CURSES' \
2244 'curses.h / -ltermcap' ||
2245 __termcaplib -lcurses '#include <curses.h>' '
2246 #define HAVE_TERMCAP_CURSES' \
2247 'curses.h / -lcurses' ||
2248 __termcaplib -lcursesw '#include <curses.h>' '
2249 #define HAVE_TERMCAP_CURSES' \
2250 'curses.h / -lcursesw' ||
2251 feat_bail_required TERMCAP
2253 if [ -n "${have_termcap}" ]; then
2254 run_check tgetent_null \
2255 "tgetent(3) of termcap(5) takes NULL buffer" \
2256 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2257 #include <stdio.h> /* For C89 NULL */
2258 #include <stdlib.h>
2259 #ifdef HAVE_TERMCAP_CURSES
2260 # include <curses.h>
2261 #endif
2262 #include <term.h>
2263 int main(void){
2264 tgetent(NULL, getenv("TERM"));
2265 return 0;
2267 _EOT
2270 else
2271 echo '/* WANT_TERMCAP=0 */' >> ${h}
2272 echo '/* WANT_TERMCAP_PREFER_TERMINFO=0 */' >> ${h}
2275 if feat_yes ERRORS; then
2276 echo '#define HAVE_ERRORS' >> ${h}
2277 else
2278 echo '/* WANT_ERRORS=0 */' >> ${h}
2283 if feat_yes SPAM_SPAMC; then
2284 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2285 if command -v spamc >/dev/null 2>&1; then
2286 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2288 else
2289 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2292 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2293 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2294 else
2295 feat_bail_required SPAM_SPAMD
2296 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2299 if feat_yes SPAM_FILTER; then
2300 echo '#define HAVE_SPAM_FILTER' >> ${h}
2301 else
2302 echo '/* WANT_SPAM_FILTER=0 */' >> ${h}
2305 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2306 echo '#define HAVE_SPAM' >> ${h}
2307 else
2308 echo '/* HAVE_SPAM */' >> ${h}
2311 if feat_yes DOCSTRINGS; then
2312 echo '#define HAVE_DOCSTRINGS' >> ${h}
2313 else
2314 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
2317 if feat_yes QUOTE_FOLD &&\
2318 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2319 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2320 else
2321 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2324 if feat_yes FILTER_HTML_TAGSOUP; then
2325 echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h}
2326 else
2327 echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h}
2330 if feat_yes COLOUR; then
2331 echo '#define HAVE_COLOUR' >> ${h}
2332 else
2333 echo '/* WANT_COLOUR=0 */' >> ${h}
2336 if feat_yes DOTLOCK; then
2337 echo '#define HAVE_DOTLOCK' >> ${h}
2338 else
2339 echo '/* WANT_DOTLOCK=0 */' >> ${h}
2342 if feat_yes MD5; then
2343 echo '#define HAVE_MD5' >> ${h}
2344 else
2345 echo '/* WANT_MD5=0 */' >> ${h}
2348 if feat_yes NOMEMDBG; then
2349 echo '#define HAVE_NOMEMDBG' >> ${h}
2350 else
2351 echo '/* WANT_NOMEMDBG=0 */' >> ${h}
2354 ## Summarizing
2356 # Since we cat(1) the content of those to cc/"ld", convert them to single line
2357 squeeze_em() {
2358 < "${1}" > "${2}" ${awk} \
2359 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
2361 ${rm} -f ${tmp}
2362 squeeze_em ${inc} ${tmp}
2363 ${mv} ${tmp} ${inc}
2364 squeeze_em ${lib} ${tmp}
2365 ${mv} ${tmp} ${lib}
2367 # config.h
2368 ${mv} ${h} ${tmp}
2369 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2370 ${cat} ${tmp} >> ${h}
2371 ${rm} -f ${tmp}
2373 printf '\n/* The "feature string" */\n' >> ${h}
2374 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2375 printf 'static char const _features[] = "MIME"\n' >> ${h}
2376 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2377 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2378 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2379 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2380 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2381 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2382 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2383 >> ${h}
2384 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2385 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2386 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2387 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2388 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2389 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2390 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2391 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2392 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2393 printf '# ifdef HAVE_MLE\n ",MLE"\n# endif\n' >> ${h}
2394 printf '# ifdef HAVE_WCWIDTH\n " (WIDE GLYPHS)"\n# endif\n' >> ${h}
2395 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2396 printf '# ifdef HAVE_KEY_BINDINGS\n ",KEY-BINDINGS"\n# endif\n' >> ${h}
2397 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2398 printf '# ifdef HAVE_TERMINFO\n " (terminfo(5))"\n# endif\n' >> ${h}
2399 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2400 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2401 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2402 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2403 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2404 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2405 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2406 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2407 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2408 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2409 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2411 # Create the real mk.mk
2412 # Note we cannout use explicit ./ filename prefix for source and object
2413 # pathnames because of a bug in bmake(1)
2414 ${rm} -rf ${tmp0}.* ${tmp0}*
2415 printf 'OBJ_SRC = ' >> ${mk}
2416 if feat_no AMALGAMATION; then
2417 for i in `printf '%s\n' *.c | ${sort}`; do
2418 if [ "${i}" = privsep.c ]; then
2419 continue
2421 printf "${i} " >> ${mk}
2422 done
2423 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2424 else
2425 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2427 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2428 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2429 printf '# undef _CONFIG_H\n' >> ${h}
2430 printf '# define _CONFIG_H 2\n' >> ${h}
2431 for i in `printf '%s\n' *.c | ${sort}`; do
2432 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2433 [ "${i}" = privsep.c ]; then
2434 continue
2436 printf "${i} " >> ${mk}
2437 printf "# include \"${i}\"\n" >> ${h}
2438 done
2439 echo >> ${mk}
2440 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2441 echo '#else' >> ${h}
2444 printf '#endif /* n_CONFIG_H */\n' >> ${h}
2446 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2447 echo "INCS = `${cat} ${inc}`" >> ${mk}
2448 echo >> ${mk}
2449 ${cat} ./mk-mk.in >> ${mk}
2451 ## Finished!
2453 ${cat} > ${tmp2}.c << \!
2454 #include "config.h"
2456 :The following optional features are enabled:
2457 #ifdef HAVE_SETLOCALE
2458 : + Locale support: Printable characters depend on the environment
2459 # ifdef HAVE_C90AMEND1
2460 : + Multibyte character support
2461 # endif
2462 # ifdef HAVE_NL_LANGINFO
2463 : + Automatic detection of terminal character set
2464 # endif
2465 #endif
2466 #ifdef HAVE_ICONV
2467 : + Character set conversion using iconv()
2468 #endif
2469 #ifdef HAVE_SOCKETS
2470 : + Network support
2471 #endif
2472 #ifdef HAVE_SSL
2473 # ifdef HAVE_OPENSSL
2474 : + S/MIME and SSL/TLS (OpenSSL)
2475 # endif
2476 # ifdef HAVE_SSL_ALL_ALGORITHMS
2477 : + + Support for more ("all") digest and cipher algorithms
2478 # endif
2479 #endif
2480 #ifdef HAVE_SMTP
2481 : + SMTP protocol
2482 #endif
2483 #ifdef HAVE_POP3
2484 : + POP3 protocol
2485 #endif
2486 #ifdef HAVE_GSSAPI
2487 : + GSS-API authentication
2488 #endif
2489 #ifdef HAVE_MD5
2490 : + MD5 message digest (APOP, CRAM-MD5)
2491 #endif
2492 #ifdef HAVE_NETRC
2493 : + .netrc file support
2494 #endif
2495 #ifdef HAVE_IDNA
2496 : + IDNA (internationalized domain names for applications) support
2497 #endif
2498 #ifdef HAVE_IMAP_SEARCH
2499 : + IMAP-style search expressions
2500 #endif
2501 #ifdef HAVE_REGEX
2502 : + Regular expression support (searches, conditional expressions etc.)
2503 #endif
2504 #if defined HAVE_READLINE || defined HAVE_MLE
2505 # ifdef HAVE_READLINE
2506 : + Command line editing via readline(3)
2507 # else
2508 # ifdef HAVE_WCWIDTH
2509 : + Command line editing via M(ailx)-L(ine)-E(ditor) (wide glyph support)
2510 # else
2511 : + Command line editing via M(ailx)-L(ine)-E(ditor) (no wide glyph support)
2512 # endif
2513 # endif
2514 # ifdef HAVE_HISTORY
2515 : + + History management
2516 # endif
2517 # ifdef HAVE_KEY_BINDINGS
2518 : + + Configurable key bindings
2519 # endif
2520 #endif
2521 #ifdef HAVE_TERMCAP
2522 # ifdef HAVE_TERMINFO
2523 : + Terminal capability queries (terminfo(5))
2524 # else
2525 : + Terminal capability queries (termcap(5))
2526 # endif
2527 #endif
2528 #ifdef HAVE_SPAM
2529 : + Spam management
2530 # ifdef HAVE_SPAM_SPAMC
2531 : + + Via spamc(1) (of spamassassin(1))
2532 # endif
2533 # ifdef HAVE_SPAM_SPAMD
2534 : + + Directly via spamd(1) (of spamassassin(1))
2535 # endif
2536 # ifdef HAVE_SPAM_FILTER
2537 : + + Via freely configurable *spam-filter-XY*s
2538 # endif
2539 #endif
2540 #ifdef HAVE_DOCSTRINGS
2541 : + Documentation summary strings
2542 #endif
2543 #ifdef HAVE_QUOTE_FOLD
2544 : + Extended *quote-fold*ing
2545 #endif
2546 #ifdef HAVE_FILTER_HTML_TAGSOUP
2547 : + Builtin HTML-to-text filter (for display purposes, primitive)
2548 #endif
2549 #ifdef HAVE_COLOUR
2550 : + Coloured message display (simple)
2551 #endif
2552 #ifdef HAVE_DOTLOCK
2553 : + Dotlock files and privilege-separated file dotlock program
2554 #endif
2556 :The following optional features are disabled:
2557 #ifndef HAVE_SETLOCALE
2558 : - Locale support: Only ASCII characters are recognized
2559 #endif
2560 # ifndef HAVE_C90AMEND1
2561 : - Multibyte character support
2562 # endif
2563 # ifndef HAVE_NL_LANGINFO
2564 : - Automatic detection of terminal character set
2565 # endif
2566 #ifndef HAVE_ICONV
2567 : - Character set conversion using iconv()
2568 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2569 #endif
2570 #ifndef HAVE_SOCKETS
2571 : - Network support
2572 #endif
2573 #ifndef HAVE_SSL
2574 : - S/MIME and SSL/TLS
2575 #else
2576 # ifndef HAVE_SSL_ALL_ALGORITHMS
2577 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2578 # endif
2579 #endif
2580 #ifndef HAVE_SMTP
2581 : - SMTP protocol
2582 #endif
2583 #ifndef HAVE_POP3
2584 : - POP3 protocol
2585 #endif
2586 #ifndef HAVE_GSSAPI
2587 : - GSS-API authentication
2588 #endif
2589 #ifndef HAVE_MD5
2590 : - MD5 message digest (APOP, CRAM-MD5)
2591 #endif
2592 #ifndef HAVE_NETRC
2593 : - .netrc file support
2594 #endif
2595 #ifndef HAVE_IDNA
2596 : - IDNA (internationalized domain names for applications) support
2597 #endif
2598 #ifndef HAVE_IMAP_SEARCH
2599 : - IMAP-style search expressions
2600 #endif
2601 #ifndef HAVE_REGEX
2602 : - Regular expression support
2603 #endif
2604 #if !defined HAVE_READLINE && !defined HAVE_MLE
2605 : - Command line editing and history
2606 #else
2607 # ifndef HAVE_HISTORY
2608 : + (Command line editing) - History management
2609 # endif
2610 # ifndef HAVE_KEY_BINDINGS
2611 : + (Command line editing) - Configurable key bindings
2612 # endif
2613 #endif
2614 #ifndef HAVE_TERMCAP
2615 : - Terminal capability queries
2616 #endif
2617 #ifndef HAVE_SPAM
2618 : - Spam management
2619 #endif
2620 #ifndef HAVE_DOCSTRINGS
2621 : - Documentation summary strings
2622 #endif
2623 #ifndef HAVE_QUOTE_FOLD
2624 : - Extended *quote-fold*ing
2625 #endif
2626 #ifndef HAVE_FILTER_HTML_TAGSOUP
2627 : - Builtin HTML-to-text filter (for display purposes, primitive)
2628 #endif
2629 #ifndef HAVE_COLOUR
2630 : - Coloured message display (simple)
2631 #endif
2632 #ifndef HAVE_DOTLOCK
2633 : - Dotlock files and privilege-separated file dotlock program
2634 #endif
2636 #if !defined HAVE_FNMATCH || !defined HAVE_FCHDIR ||\
2637 defined HAVE_DEBUG || defined HAVE_DEVEL
2638 :Remarks:
2639 # ifndef HAVE_FNMATCH
2640 : . The function fnmatch(3) could not be found.
2641 : _ Filename patterns like wildcard are not supported on your system.
2642 # endif
2643 # ifndef HAVE_FCHDIR
2644 : . The function fchdir(2) could not be found. We will use chdir(2)
2645 : _ instead. This is not a problem unless the current working
2646 : _ directory is changed while this program is inside of it.
2647 # endif
2648 # ifdef HAVE_DEBUG
2649 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2650 # endif
2651 # ifdef HAVE_DEVEL
2652 : . Computers do not blunder.
2653 # endif
2655 #endif /* Remarks */
2656 :Setup:
2657 : . System-wide resource file: SYSCONFDIR/SYSCONFRC
2658 : . bindir: BINDIR
2659 #ifdef HAVE_DOTLOCK
2660 : . libexecdir: LIBEXECDIR
2661 #endif
2662 : . mandir: MANDIR
2663 : . sendmail(1): VAL_SENDMAIL (argv[0] = VAL_SENDMAIL_PROGNAME)
2664 : . Mail spool directory: MAILSPOOL
2668 ${make} -f ${makefile} ${tmp2}.x
2669 < ${tmp2}.x ${sed} -e '/^[^:]/d; /^$/d; s/^://' |
2670 while read l; do
2671 msg "${l}"
2672 done
2674 # s-it-mode