mk-conf.sh, mk-mk.in: tiny steps
[s-mailx.git] / mk-conf.sh
blob1b7c5fc77056cd5e83af3f4bec053919783f7621
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} ${EXTRA_CFLAGS}"
187 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
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} ${EXTRA_CFLAGS}"
248 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
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 # EXTRA_CFLAGS/EXTRA_LDFLAGS
263 if feat_no AUTOCC; then
264 _cc_default
265 # Ensure those don't do any harm
266 EXTRA_CFLAGS= EXTRA_LDFLAGS=
267 export EXTRA_CFLAGS EXTRA_LDFLAGS
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}, 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..' \
322 "${CC}"
323 else
324 cc_check_silent=
325 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
328 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
329 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
330 msg ' . have special tcc(1) environmental rules ...'
331 _cc_flags_tcc
332 else
333 # As of pcc CVS 2016-04-02, stack protection support is announced but
334 # will break if used on Linux
335 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
336 force_no_stackprot=1
338 _cc_flags_generic
341 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
342 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
343 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
344 else
345 if feat_no DEBUG; then
346 CFLAGS="-DNDEBUG ${CFLAGS}"
349 msg ''
350 export CFLAGS LDFLAGS
353 _cc_flags_tcc() {
354 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
355 _CFLAGS= _LDFLAGS=
357 cc_check -Wall
358 cc_check -Wextra
359 cc_check -pedantic
361 if feat_yes DEBUG; then
362 # May have problems to find libtcc cc_check -b
363 cc_check -g
366 if ld_check -Wl,-rpath =./ no; then
367 need_R_ldflags=-Wl,-rpath=
368 ld_runtime_flags # update!
371 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
372 unset __cflags __ldflags
375 _cc_flags_generic() {
376 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
377 _CFLAGS= _LDFLAGS=
378 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
380 # Check -g first since some others may rely upon -g / optim. level
381 if feat_yes DEBUG; then
382 cc_check -O
383 cc_check -g
384 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
386 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
388 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
390 else
391 cc_check -O
394 if feat_yes DEVEL && cc_check -Weverything; then
396 else
397 cc_check -Wall
398 cc_check -Wextra
399 cc_check -Wbad-function-cast
400 cc_check -Wcast-align
401 cc_check -Wcast-qual
402 cc_check -Winit-self
403 cc_check -Wmissing-prototypes
404 cc_check -Wshadow
405 cc_check -Wunused
406 cc_check -Wwrite-strings
407 cc_check -Wno-long-long
409 cc_check -pedantic
411 if feat_yes AMALGAMATION && feat_no DEVEL; then
412 cc_check -Wno-unused-function
414 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
416 cc_check -fno-unwind-tables
417 cc_check -fno-asynchronous-unwind-tables
418 cc_check -fstrict-aliasing
419 if cc_check -fstrict-overflow && feat_yes DEVEL; then
420 cc_check -Wstrict-overflow=5
423 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
424 if [ -z "${force_no_stackprot}" ]; then
425 if cc_check -fstack-protector-strong ||
426 cc_check -fstack-protector-all; then
427 cc_check -D_FORTIFY_SOURCE=2
429 else
430 msg 'Not checking for -fstack-protector compiler option,'
431 msg 'since that caused errors in a "similar" configuration.'
432 msg 'You may turn off WANT_AUTOCC and use your own settings, rerun'
436 if feat_yes AMALGAMATION; then
437 cc_check -pipe
440 # LD (+ dependend CC)
442 if feat_yes DEVEL; then
443 _ccfg=${_CFLAGS}
444 # -fsanitize=address
445 #if cc_check -fsanitize=memory &&
446 # ld_check -fsanitize=memory &&
447 # cc_check -fsanitize-memory-track-origins=2 &&
448 # ld_check -fsanitize-memory-track-origins=2; then
450 #else
451 # _CFLAGS=${_ccfg}
455 ld_check -Wl,-z,relro
456 ld_check -Wl,-z,now
457 ld_check -Wl,-z,noexecstack
458 if ld_check -Wl,-rpath =./ no; then
459 need_R_ldflags=-Wl,-rpath=
460 ld_runtime_flags # update!
461 elif ld_check -Wl,-R ./ no; then
462 need_R_ldflags=-Wl,-R
463 ld_runtime_flags # update!
466 # Address randomization
467 _ccfg=${_CFLAGS}
468 if cc_check -fPIE || cc_check -fpie; then
469 ld_check -pie || _CFLAGS=${_ccfg}
471 unset _ccfg
473 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
474 unset __cflags __ldflags
477 ## -- >8 -- 8< -- ##
479 ## Notes:
480 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
481 ## redirection, so use "printf '' >" instead
483 ## Very first: we undergo several states regarding I/O redirection etc.,
484 ## but need to deal with option updates from within all. Since all the
485 ## option stuff should be above the scissor line, define utility functions
486 ## and redefine them as necessary.
487 ## And, since we have those functions, simply use them for whatever
489 config_exit() {
490 exit ${1}
493 msg() {
494 fmt=${1}
495 shift
496 printf >&2 -- "${fmt}\\n" "${@}"
499 ## First of all, create new configuration and check wether it changed
501 rc=./make.rc
502 lst=./config.lst
503 ev=./config.ev
504 h=./config.h h_name=config.h
505 mk=./mk.mk
507 newlst=./config.lst-new
508 newmk=./config.mk-new
509 newev=./config.ev-new
510 newh=./config.h-new
511 tmp0=___tmp
512 tmp=./${tmp0}1$$
513 tmp2=./${tmp0}2$$
515 t1=ten10one1ten10one1
516 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
517 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
518 ) > /dev/null 2>&1; then
519 good_shell=1
520 else
521 unset good_shell
523 unset t1
525 # We need some standard utilities
526 unset -f command
527 check_tool() {
528 n=${1} i=${2} opt=${3:-0}
529 # Evaluate, just in case user comes in with shell snippets (..well..)
530 eval i="${i}"
531 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
532 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
533 eval ${n}=${i}
534 return 0
536 if [ ${opt} -eq 0 ]; then
537 msg 'ERROR: no trace of utility "%s"' "${n}"
538 config_exit 1
540 return 1
543 # Very easy checks for the operating system in order to be able to adjust paths
544 # or similar very basic things which we need to be able to go at all
545 os_early_setup
547 # Check those tools right now that we need before including $rc
548 msg 'Checking for basic utility set'
549 check_tool awk "${awk:-`command -v awk`}"
550 check_tool rm "${rm:-`command -v rm`}"
551 check_tool tr "${tr:-`command -v tr`}"
553 # Our feature check environment
554 feat_val_no() {
555 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
556 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
559 feat_val_yes() {
560 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
561 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
562 [ "x${1}" = xrequire ]
565 feat_val_require() {
566 [ "x${1}" = xrequire ]
569 _feat_check() {
570 eval i=\$WANT_${1}
571 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
572 if feat_val_no "${i}"; then
573 return 1
574 elif feat_val_yes "${i}"; then
575 return 0
576 else
577 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
578 "${1}" "${i}"
579 config_exit 11
583 feat_yes() {
584 _feat_check ${1}
587 feat_no() {
588 _feat_check ${1} && return 1
589 return 0
592 feat_require() {
593 eval i=\$WANT_${1}
594 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
595 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
598 feat_bail_required() {
599 if feat_require ${1}; then
600 msg 'ERROR: feature WANT_%s is required but not available' "${1}"
601 config_exit 13
603 eval WANT_${1}=0
604 option_update # XXX this is rather useless here (dependency chain..)
607 path_check() {
608 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
609 varname=${1} addflag=${2} flagvarname=${3}
610 j=${IFS}
611 IFS=:
612 eval "set -- \$${1}"
613 IFS=${j}
614 j= k= y= z=
615 for i
617 [ -z "${i}" ] && continue
618 [ -d "${i}" ] || continue
619 if [ -n "${j}" ]; then
620 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
622 else
623 y="${y} :${i}:"
624 j="${j}:${i}"
625 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
627 else
628 y=" :${i}:"
629 j="${i}"
630 [ -n "${addflag}" ] && k="${addflag}${i}"
632 done
633 eval "${varname}=\"${j}\""
634 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
635 unset varname
638 ld_runtime_flags() {
639 if [ -n "${need_R_ldflags}" ]; then
640 i=${IFS}
641 IFS=:
642 set -- ${LD_LIBRARY_PATH}
643 IFS=${i}
644 for i
646 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
647 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
648 done
649 export LDFLAGS
651 # Disable it for a possible second run.
652 need_R_ldflags=
655 cc_check() {
656 [ -n "${cc_check_silent}" ] || printf >&2 ' . CC %s .. ' "${1}"
657 if "${CC}" ${INCS} \
658 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
659 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
660 _CFLAGS="${_CFLAGS} ${1}"
661 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
662 return 0
664 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
665 return 1
668 ld_check() {
669 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
670 [ -n "${cc_check_silent}" ] || printf >&2 ' . LD %s .. ' "${1}"
671 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
672 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
673 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
674 [ -n "${cc_check_silent}" ] || printf >&2 'yes\n'
675 return 0
677 [ -n "${cc_check_silent}" ] || printf >&2 'no\n'
678 return 1
681 # Include $rc, but only take from it what wasn't overwritten by the user from
682 # within the command line or from a chosen fixed CONFIG=
683 # Note we leave alone the values
684 trap "exit 1" HUP INT TERM
685 trap "${rm} -f ${tmp}" EXIT
687 printf >&2 'Reading and preparing configuration from "%s" ... ' ${rc}
688 ${rm} -f ${tmp}
689 # We want read(1) to perform backslash escaping in order to be able to use
690 # multiline values in make.rc; the resulting sh(1)/sed(1) code was very slow in
691 # VMs (see [fa2e248]), Aharon Robbins suggested the following
692 < ${rc} ${awk} 'BEGIN{line = ""}{
693 gsub(/^[[:space:]]+/, "", $0)
694 gsub(/[[:space:]]+$/, "", $0)
695 if(gsub(/\\$/, "", $0)){
696 line = line $0
697 next
698 }else
699 line = line $0
700 if(index(line, "#") == 1){
701 line = ""
702 }else if(length(line)){
703 print line
704 line = ""
706 }' |
707 while read line; do
708 if [ -n "${good_shell}" ]; then
709 i=${line%%=*}
710 else
711 i=`${awk} -v LINE="${line}" 'BEGIN{
712 gsub(/=.*$/, "", LINE)
713 print LINE
716 if [ "${i}" = "${line}" ]; then
717 msg 'ERROR: invalid syntax in "%s"' "${line}"
718 continue
721 eval j="\$${i}" jx="\${${i}+x}"
722 if [ -n "${j}" ] || [ "${jx}" = x ]; then
723 : # Yet present
724 else
725 j=`${awk} -v LINE="${line}" 'BEGIN{
726 gsub(/^[^=]*=/, "", LINE)
727 gsub(/^\"*/, "", LINE)
728 gsub(/\"*$/, "", LINE)
729 print LINE
732 [ "${i}" = "DESTDIR" ] && continue
733 echo "${i}=\"${j}\""
734 done > ${tmp}
735 # Reread the mixed version right now
736 . ./${tmp}
737 printf >&2 'done\n'
739 # We need to know about that now, in order to provide utility overwrites etc.
740 os_setup
742 msg 'Checking for remaining set of utilities'
743 check_tool grep "${grep:-`command -v grep`}"
745 # Before we step ahead with the other utilities perform a path cleanup first.
746 path_check PATH
748 # awk(1) above
749 check_tool cat "${cat:-`command -v cat`}"
750 check_tool chmod "${chmod:-`command -v chmod`}"
751 check_tool cp "${cp:-`command -v cp`}"
752 check_tool cmp "${cmp:-`command -v cmp`}"
753 # grep(1) above
754 check_tool mkdir "${mkdir:-`command -v mkdir`}"
755 check_tool mv "${mv:-`command -v mv`}"
756 # rm(1) above
757 check_tool sed "${sed:-`command -v sed`}"
758 check_tool sort "${sort:-`command -v sort`}"
759 check_tool tee "${tee:-`command -v tee`}"
761 check_tool chown "${chown:-`command -v chown`}" 1 ||
762 check_tool chown "/sbin/chown" 1 ||
763 check_tool chown "/usr/sbin/chown"
765 check_tool make "${MAKE:-`command -v make`}"
766 MAKE=${make}
767 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
768 HAVE_STRIP=1 || HAVE_STRIP=0
770 # For ./cc-test.sh only
771 check_tool cksum "${cksum:-`command -v cksum`}"
773 # Update WANT_ options now, in order to get possible inter-dependencies right
774 option_update
776 # (No functions since some shells loose non-exported variables in traps)
777 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
778 trap "trap \"\" HUP INT TERM EXIT;\
779 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
781 # Our configuration options may at this point still contain shell snippets,
782 # we need to evaluate them in order to get them expanded, and we need those
783 # evaluated values not only in our new configuration file, but also at hand..
784 printf >&2 'Evaluating all configuration items ... '
785 ${rm} -f ${newlst} ${newmk} ${newh}
786 exec 5<&0 6>&1 <${tmp} >${newlst}
787 while read line; do
789 if [ -n "${good_shell}" ]; then
790 i=${line%%=*}
791 [ "${i}" != "${i#WANT_}" ] && z=1
792 else
793 i=`${awk} -v LINE="${line}" 'BEGIN{
794 gsub(/=.*$/, "", LINE);\
795 print LINE
797 if echo "${i}" | ${grep} '^WANT_' >/dev/null 2>&1; then
802 eval j=\$${i}
803 if [ -n "${z}" ]; then
804 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
805 if [ -z "${j}" ] || feat_val_no "${j}"; then
807 printf "/*#define ${i}*/\n" >> ${newh}
808 elif feat_val_yes "${j}"; then
809 if feat_val_require "${j}"; then
810 j=require
811 else
814 printf "#define ${i}\n" >> ${newh}
815 else
816 msg 'ERROR: cannot parse <%s>' "${line}"
817 config_exit 1
819 else
820 printf "#define ${i} \"${j}\"\n" >> ${newh}
822 printf "${i} = ${j}\n" >> ${newmk}
823 printf "${i}=${j}\n"
824 eval "${i}=\"${j}\""
825 done
826 exec 0<&5 1>&6 5<&- 6<&-
827 printf >&2 'done\n'
829 # Add the known utility and some other variables
830 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
831 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
833 printf "#define PRIVSEP \"${SID}${NAIL}-privsep\"\n" >> ${newh}
834 printf "PRIVSEP = \$(UAGENT)-privsep\n" >> ${newmk}
835 if feat_yes DOTLOCK; then
836 printf "OPTIONAL_PRIVSEP = \$(PRIVSEP)\n" >> ${newmk}
837 else
838 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
841 for i in \
842 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
843 MAKE MAKEFLAGS make SHELL strip \
844 cksum; do
845 eval j=\$${i}
846 printf "${i} = ${j}\n" >> ${newmk}
847 printf "${i}=${j}\n" >> ${newlst}
848 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
849 done
850 printf "\n" >> ${newev}
852 # Build a basic set of INCS and LIBS according to user environment.
853 path_check C_INCLUDE_PATH -I _INCS
854 INCS="${INCS} ${_INCS}"
855 path_check LD_LIBRARY_PATH -L _LIBS
856 LIBS="${LIBS} ${_LIBS}"
857 unset _INCS _LIBS
858 export C_INCLUDE_PATH LD_LIBRARY_PATH
860 # Some environments need runtime path flags to be able to go at all
861 ld_runtime_flags
863 ## Detect CC, wether we can use it, and possibly which CFLAGS we can use
865 cc_setup
867 ${cat} > ${tmp}.c << \!
868 #include <stdio.h>
869 #include <string.h>
870 static void doit(char const *s);
872 main(int argc, char **argv){
873 (void)argc;
874 (void)argv;
875 doit("Hello world");
876 return 0;
878 static void
879 doit(char const *s){
880 char buf[12];
881 memcpy(buf, s, strlen(s) +1);
882 puts(s);
886 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
887 -o ${tmp2} ${tmp}.c ${LIBS}; then
889 else
890 msg 'ERROR: i cannot compile a "Hello world" via'
891 msg ' %s' \
892 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
893 msg 'ERROR: Please read INSTALL, rerun'
894 config_exit 1
897 # This may also update ld_runtime_flags() (again)
898 cc_flags
900 for i in \
901 INCS LIBS \
902 ; do
903 eval j=\$${i}
904 printf -- "${i}=${j}\n" >> ${newlst}
905 done
906 for i in \
907 CC \
908 CFLAGS \
909 LDFLAGS \
910 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
911 OSFULLSPEC \
912 ; do
913 eval j=\$${i}
914 printf -- "${i} = ${j}\n" >> ${newmk}
915 printf -- "${i}=${j}\n" >> ${newlst}
916 done
918 # Now finally check wether we already have a configuration and if so, wether
919 # all those parameters are still the same.. or something has actually changed
920 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
921 echo 'Configuration is up-to-date'
922 exit 0
923 elif [ -f ${lst} ]; then
924 echo 'Configuration has been updated..'
925 ( eval "${MAKE} -f ./mk.mk clean" )
926 echo
927 else
928 echo 'Shiny configuration..'
931 # Time to redefine helper 1
932 config_exit() {
933 ${rm} -f ${lst} ${h} ${mk}
934 exit ${1}
937 ${mv} -f ${newlst} ${lst}
938 ${mv} -f ${newev} ${ev}
939 ${mv} -f ${newh} ${h}
940 ${mv} -f ${newmk} ${mk}
942 if [ -z "${VERBOSE}" ]; then
943 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
944 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
945 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
946 printf -- "ECHO_TEST = @\n" >> ${mk}
947 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
948 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
949 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
952 ## Compile and link checking
954 tmp3=./${tmp0}3$$
955 log=./config.log
956 lib=./config.lib
957 inc=./config.inc
958 makefile=./config.mk
960 # (No function since some shells loose non-exported variables in traps)
961 trap "trap \"\" HUP INT TERM;\
962 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
963 trap "trap \"\" HUP INT TERM EXIT;\
964 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
966 # Time to redefine helper 2
967 msg() {
968 fmt=${1}
969 shift
970 printf "*** ${fmt}\\n" "${@}"
971 printf -- "${fmt}\\n" "${@}" >&5
973 msg_nonl() {
974 fmt=${1}
975 shift
976 printf "*** ${fmt}\\n" "${@}"
977 printf -- "${fmt}" "${@}" >&5
980 exec 5>&2 > ${log} 2>&1
982 echo "${LIBS}" > ${lib}
983 echo "${INCS}" > ${inc}
984 ${cat} > ${makefile} << \!
985 .SUFFIXES: .o .c .x .y
986 .c.o:
987 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
988 .c.x:
989 $(CC) -I./ $(XINCS) -E $(<) > $(@)
991 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
994 _check_preface() {
995 variable=$1 topic=$2 define=$3
997 echo '**********'
998 msg_nonl ' . %s ... ' "${topic}"
999 echo "/* checked ${topic} */" >> ${h}
1000 ${rm} -f ${tmp} ${tmp}.o
1001 echo '*** test program is'
1002 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1003 #echo '*** the preprocessor generates'
1004 #${make} -f ${makefile} ${tmp}.x
1005 #${cat} ${tmp}.x
1006 echo '*** results are'
1009 compile_check() {
1010 variable=$1 topic=$2 define=$3
1012 _check_preface "${variable}" "${topic}" "${define}"
1014 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
1015 [ -f ./${tmp}.o ]; then
1016 msg 'yes'
1017 echo "${define}" >> ${h}
1018 eval have_${variable}=yes
1019 return 0
1020 else
1021 echo "/* ${define} */" >> ${h}
1022 msg 'no'
1023 eval unset have_${variable}
1024 return 1
1028 _link_mayrun() {
1029 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1031 _check_preface "${variable}" "${topic}" "${define}"
1033 feat_yes CROSS_BUILD && run=0
1035 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1036 XLIBS="${LIBS} ${libs}" ./${tmp} &&
1037 [ -f ./${tmp} ] &&
1038 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1039 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1040 msg 'yes'
1041 echo "${define}" >> ${h}
1042 LIBS="${LIBS} ${libs}"
1043 echo "${libs}" >> ${lib}
1044 INCS="${INCS} ${incs}"
1045 echo "${incs}" >> ${inc}
1046 eval have_${variable}=yes
1047 return 0
1048 else
1049 msg 'no'
1050 echo "/* ${define} */" >> ${h}
1051 eval unset have_${variable}
1052 return 1
1056 link_check() {
1057 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1060 run_check() {
1061 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1064 feat_def() {
1065 if feat_yes ${1}; then
1066 echo '#define HAVE_'${1}'' >> ${h}
1067 else
1068 echo '/* WANT_'${1}'=0 */' >> ${h}
1072 squeeze_em() {
1073 < "${1}" > "${2}" ${awk} \
1074 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1077 ## Generics
1079 # May be multiline..
1080 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1082 feat_def AMALGAMATION
1083 feat_def CROSS_BUILD
1084 feat_def DEBUG
1085 feat_def DEVEL
1086 feat_def DOCSTRINGS
1087 feat_def ERRORS
1088 feat_def NYD2
1090 if run_check inline '"inline" functions' \
1091 '#define HAVE_INLINE
1092 #define n_INLINE static inline' << \!
1093 static inline int ilf(int i){return ++i;}
1094 int main(void){return ilf(-1);}
1096 then
1098 elif run_check inline '"__inline" functions' \
1099 '#define HAVE_INLINE
1100 #define n_INLINE static __inline' << \!
1101 static __inline int ilf(int i){return ++i;}
1102 int main(void){return ilf(-1);}
1104 then
1108 if run_check endian 'Little endian byteorder' \
1109 '#define HAVE_BYTE_ORDER_LITTLE' << \!
1110 int main(void){
1111 enum {vBig = 1, vLittle = 0};
1112 union {unsigned short bom; unsigned char buf[2];} u;
1113 u.bom = 0xFEFF;
1114 return((u.buf[1] == 0xFE) ? vLittle : vBig);
1117 then
1121 ## Test for "basic" system-calls / functionality that is used by all parts
1122 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1123 ## macros to be used by only the subprograms (potentially).
1125 if run_check clock_gettime 'clock_gettime(2)' \
1126 '#define HAVE_CLOCK_GETTIME' << \!
1127 #include <time.h>
1128 # include <errno.h>
1129 int main(void){
1130 struct timespec ts;
1132 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1133 return 0;
1134 return 1;
1137 then
1139 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1140 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1141 #include <time.h>
1142 # include <errno.h>
1143 int main(void){
1144 struct timespec ts;
1146 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1147 return 0;
1148 return 1;
1151 then
1153 elif run_check gettimeofday 'gettimeofday(2)' \
1154 '#define HAVE_GETTIMEOFDAY' << \!
1155 #include <stdio.h> /* For C89 NULL */
1156 #include <sys/time.h>
1157 # include <errno.h>
1158 int main(void){
1159 struct timeval tv;
1161 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1162 return 0;
1163 return 1;
1166 then
1168 else
1169 have_no_subsecond_time=1
1172 if run_check nanosleep 'nanosleep(2)' \
1173 '#define HAVE_NANOSLEEP' << \!
1174 #include <time.h>
1175 # include <errno.h>
1176 int main(void){
1177 struct timespec ts;
1179 ts.tv_sec = 1;
1180 ts.tv_nsec = 100000;
1181 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1182 return 0;
1183 return 1;
1186 then
1188 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1189 '#define HAVE_NANOSLEEP' '-lrt' << \!
1190 #include <time.h>
1191 # include <errno.h>
1192 int main(void){
1193 struct timespec ts;
1195 ts.tv_sec = 1;
1196 ts.tv_nsec = 100000;
1197 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1198 return 0;
1199 return 1;
1202 then
1204 # link_check is enough for this, that function is so old, trust the proto
1205 elif link_check sleep 'sleep(3)' \
1206 '#define HAVE_SLEEP' << \!
1207 #include <unistd.h>
1208 # include <errno.h>
1209 int main(void){
1210 if(!sleep(1) || errno != ENOSYS)
1211 return 0;
1212 return 1;
1215 then
1217 else
1218 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1219 config_exit 1
1222 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1223 #include <pwd.h>
1224 #include <unistd.h>
1225 # include <errno.h>
1226 int main(void){
1227 struct passwd *pw;
1228 gid_t gid;
1229 uid_t uid;
1231 if((gid = getgid()) != 0)
1232 gid = getegid();
1233 if((uid = getuid()) != 0)
1234 uid = geteuid();
1235 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1236 return 1;
1237 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1238 return 1;
1239 return 0;
1242 then
1244 else
1245 msg 'ERROR: we require user and group info / database searches.'
1246 msg 'That much Unix we indulge ourselfs.'
1247 config_exit 1
1250 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1251 #include <signal.h>
1252 # include <errno.h>
1253 int main(void){
1254 struct sigaction nact, oact;
1256 nact.sa_handler = SIG_DFL;
1257 sigemptyset(&nact.sa_mask);
1258 nact.sa_flags = SA_RESTART;
1259 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1262 then
1264 else
1265 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1266 config_exit 1
1269 if link_check snprintf 'v?snprintf(3)' << \!
1270 #include <stdarg.h>
1271 #include <stdio.h>
1272 static void dome(char *buf, ...){
1273 va_list ap;
1275 va_start(ap, buf);
1276 vsnprintf(buf, 20, "%s", ap);
1277 va_end(ap);
1278 return;
1280 int main(void){
1281 char b[20];
1283 snprintf(b, sizeof b, "%s", "string");
1284 dome(b, "string");
1285 return 0;
1288 then
1290 else
1291 msg 'ERROR: we require the snprintf(3) and vsnprintf(3) functions.'
1292 config_exit 1
1295 if link_check environ 'environ(3)' << \!
1296 #include <stdio.h> /* For C89 NULL */
1297 int main(void){
1298 extern char **environ;
1300 return environ[0] == NULL;
1303 then
1305 else
1306 msg 'ERROR: we require the environ(3) array for subprocess control.'
1307 config_exit 1
1310 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1311 #include <stdlib.h>
1312 int main(void){
1313 setenv("s-mailx", "i want to see it cute!", 1);
1314 unsetenv("s-mailx");
1315 return 0;
1318 then
1320 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1321 #include <stdlib.h>
1322 int main(void){
1323 putenv("s-mailx=i want to see it cute!");
1324 return 0;
1327 then
1329 else
1330 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1331 config_exit 1
1334 if link_check termios 'termios.h and tc*(3) family' << \!
1335 #include <termios.h>
1336 int main(void){
1337 struct termios tios;
1339 tcgetattr(0, &tios);
1340 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
1341 return 0;
1344 then
1346 else
1347 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1348 msg 'That much Unix we indulge ourselfs.'
1349 config_exit 1
1352 ## optional stuff
1354 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1355 #include <unistd.h>
1356 #include <errno.h>
1357 int main(void){
1358 int rv = 0;
1360 errno = 0;
1361 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1362 errno = 0;
1363 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1365 /* Only link check */
1366 fpathconf(0, _PC_NAME_MAX);
1368 return rv;
1372 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1373 #include <fcntl.h>
1374 #include <unistd.h>
1375 # include <errno.h>
1376 int main(void){
1377 int fds[2];
1379 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1380 return 0;
1381 return 1;
1385 # We use this only then for now (need NOW+1)
1386 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1387 #include <fcntl.h> /* For AT_* */
1388 #include <sys/stat.h>
1389 # include <errno.h>
1390 int main(void){
1391 struct timespec ts[2];
1393 ts[0].tv_nsec = UTIME_NOW;
1394 ts[1].tv_nsec = UTIME_OMIT;
1395 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1396 return 0;
1397 return 1;
1403 # XXX Add POSIX check once standardized
1404 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1405 #include <stdlib.h>
1406 int main(void){
1407 arc4random();
1408 return 0;
1411 then
1413 elif [ -n "${have_no_subsecond_time}" ]; then
1414 msg 'ERROR: %s %s' 'without a native random' \
1415 'one of clock_gettime(2) and gettimeofday(2) is required.'
1416 config_exit 1
1419 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1420 #include <stdio.h>
1421 int main(void){
1422 putc_unlocked('@', stdout);
1423 return 0;
1427 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1428 #include <unistd.h>
1429 int main(void){
1430 fchdir(0);
1431 return 0;
1435 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1436 #include <stdlib.h>
1437 int main(void){
1438 char x_buf[4096], *x = realpath(".", x_buf);
1440 return (x != NULL) ? 0 : 1;
1443 then
1444 if run_check realpath_malloc 'realpath(3) takes NULL' \
1445 '#define HAVE_REALPATH_NULL' << \!
1446 #include <stdlib.h>
1447 int main(void){
1448 char *x = realpath(".", NULL);
1450 if(x != NULL)
1451 free(x);
1452 return (x != NULL) ? 0 : 1;
1455 then
1460 ## optional and selectable
1462 if feat_no NOALLOCA; then
1463 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
1464 # versions of alloca(3) since modern compilers just can't be trusted
1465 # not to overoptimize and silently break some code
1466 run_check alloca '__builtin_alloca()' \
1467 '#define HAVE_ALLOCA __builtin_alloca' << \!
1468 #include <stdio.h> /* For C89 NULL */
1469 int main(void){
1470 void *vp = __builtin_alloca(1);
1472 return (vp != NULL);
1477 if feat_yes DOTLOCK; then
1478 if run_check readlink 'readlink(2)' << \!
1479 #include <unistd.h>
1480 # include <errno.h>
1481 int main(void){
1482 char buf[128];
1484 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1485 return 0;
1486 return 1;
1489 then
1491 else
1492 feat_bail_required DOTLOCK
1496 if feat_yes DOTLOCK; then
1497 if run_check fchown 'fchown(2)' << \!
1498 #include <unistd.h>
1499 # include <errno.h>
1500 int main(void){
1501 if(!fchown(0, 0, 0) || errno != ENOSYS)
1502 return 0;
1503 return 1;
1506 then
1508 else
1509 feat_bail_required DOTLOCK
1513 ## Now it is the time to fork away the BASE_ series
1515 ${rm} -f ${tmp}
1516 squeeze_em ${inc} ${tmp}
1517 ${mv} ${tmp} ${inc}
1518 squeeze_em ${lib} ${tmp}
1519 ${mv} ${tmp} ${lib}
1521 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1522 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1524 ## The remains are expected to be used only by the main MUA binary!
1526 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1527 #include <locale.h>
1528 int main(void){
1529 setlocale(LC_ALL, "");
1530 return 0;
1534 if [ "${have_setlocale}" = yes ]; then
1535 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1536 '#define HAVE_C90AMEND1' << \!
1537 #include <limits.h>
1538 #include <stdlib.h>
1539 #include <wchar.h>
1540 #include <wctype.h>
1541 int main(void){
1542 char mbb[MB_LEN_MAX + 1];
1543 wchar_t wc;
1545 iswprint(L'c');
1546 towupper(L'c');
1547 mbtowc(&wc, "x", 1);
1548 mbrtowc(&wc, "x", 1, NULL);
1549 wctomb(mbb, wc);
1550 return (mblen("\0", 1) == 0);
1554 if [ "${have_c90amend1}" = yes ]; then
1555 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1556 #include <wchar.h>
1557 int main(void){
1558 wcwidth(L'c');
1559 return 0;
1564 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1565 #include <langinfo.h>
1566 #include <stdlib.h>
1567 int main(void){
1568 nl_langinfo(DAY_1);
1569 return (nl_langinfo(CODESET) == NULL);
1572 fi # have_setlocale
1574 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1575 #include <fnmatch.h>
1576 int main(void){
1577 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1581 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1582 #include <dirent.h>
1583 int main(void){
1584 struct dirent de;
1585 return !(de.d_type == DT_UNKNOWN ||
1586 de.d_type == DT_DIR || de.d_type == DT_LNK);
1590 ## optional and selectable
1592 if feat_yes ICONV; then
1593 ${cat} > ${tmp2}.c << \!
1594 #include <stdio.h> /* For C89 NULL */
1595 #include <iconv.h>
1596 int main(void){
1597 iconv_t id;
1599 id = iconv_open("foo", "bar");
1600 iconv(id, NULL, NULL, NULL, NULL);
1601 iconv_close(id);
1602 return 0;
1605 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1606 '#define HAVE_ICONV' ||
1607 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1608 '#define HAVE_ICONV' '-liconv' ||
1609 feat_bail_required ICONV
1610 else
1611 echo '/* WANT_ICONV=0 */' >> ${h}
1612 fi # feat_yes ICONV
1614 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1615 ${cat} > ${tmp2}.c << \!
1616 #include <sys/types.h>
1617 #include <sys/socket.h>
1618 #include <sys/un.h>
1619 # include <errno.h>
1620 int main(void){
1621 struct sockaddr_un soun;
1623 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1624 return 1;
1625 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1626 return 1;
1627 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1628 return 1;
1629 return 0;
1633 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1634 '#define HAVE_UNIX_SOCKETS' ||
1635 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1636 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1637 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1638 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1641 if feat_yes SOCKETS; then
1642 ${cat} > ${tmp2}.c << \!
1643 #include "config.h"
1644 #include <sys/types.h>
1645 #include <sys/socket.h>
1646 #include <netinet/in.h>
1647 # include <errno.h>
1648 int main(void){
1649 struct sockaddr s;
1651 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1652 return 1;
1653 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1654 return 1;
1655 return 0;
1659 < ${tmp2}.c run_check sockets 'sockets' \
1660 '#define HAVE_SOCKETS' ||
1661 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1662 '#define HAVE_SOCKETS' '-lnsl' ||
1663 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1664 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1665 feat_bail_required SOCKETS
1666 else
1667 echo '/* WANT_SOCKETS=0 */' >> ${h}
1668 fi # feat_yes SOCKETS
1670 if feat_yes SOCKETS; then
1671 link_check getaddrinfo 'getaddrinfo(3)' \
1672 '#define HAVE_GETADDRINFO' << \!
1673 #include "config.h"
1674 #include <sys/types.h>
1675 #include <sys/socket.h>
1676 #include <stdio.h>
1677 #include <netdb.h>
1678 int main(void){
1679 struct addrinfo a, *ap;
1680 int lrv;
1682 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1683 case EAI_NONAME:
1684 case EAI_SERVICE:
1685 default:
1686 fprintf(stderr, "%s\n", gai_strerror(lrv));
1687 case 0:
1688 break;
1690 return 0;
1695 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1696 compile_check arpa_inet_h '<arpa/inet.h>' \
1697 '#define HAVE_ARPA_INET_H' << \!
1698 #include "config.h"
1699 #include <sys/types.h>
1700 #include <sys/socket.h>
1701 #include <netdb.h>
1702 #include <netinet/in.h>
1703 #include <arpa/inet.h>
1706 ${cat} > ${tmp2}.c << \!
1707 #include "config.h"
1708 #include <sys/types.h>
1709 #include <sys/socket.h>
1710 #include <stdio.h>
1711 #include <string.h>
1712 #include <netdb.h>
1713 #include <netinet/in.h>
1714 #ifdef HAVE_ARPA_INET_H
1715 #include <arpa/inet.h>
1716 #endif
1717 int main(void){
1718 struct sockaddr_in servaddr;
1719 unsigned short portno;
1720 struct servent *ep;
1721 struct hostent *hp;
1722 struct in_addr **pptr;
1724 portno = 0;
1725 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1726 portno = (unsigned short)ep->s_port;
1728 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1729 pptr = (struct in_addr**)hp->h_addr_list;
1730 if(hp->h_addrtype != AF_INET)
1731 fprintf(stderr, "au\n");
1732 }else{
1733 switch(h_errno){
1734 case HOST_NOT_FOUND:
1735 case TRY_AGAIN:
1736 case NO_RECOVERY:
1737 case NO_DATA:
1738 break;
1739 default:
1740 fprintf(stderr, "au\n");
1741 break;
1745 memset(&servaddr, 0, sizeof servaddr);
1746 servaddr.sin_family = AF_INET;
1747 servaddr.sin_port = htons(portno);
1748 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1749 fprintf(stderr, "Would connect to %s:%d ...\n",
1750 inet_ntoa(**pptr), (int)portno);
1751 return 0;
1755 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1756 < ${tmp2}.c link_check gethostbyname \
1757 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1758 < ${tmp2}.c link_check gethostbyname \
1759 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1760 '' '-lsocket -lnsl' ||
1761 feat_bail_required SOCKETS
1764 feat_yes SOCKETS &&
1765 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
1766 #include <sys/socket.h>
1767 #include <stdlib.h>
1768 # include <errno.h>
1769 int main(void){
1770 int sockfd = 3;
1772 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
1773 errno == ENOSYS)
1774 return 1;
1775 return 0;
1779 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1780 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
1781 #include <sys/socket.h>
1782 #include <stdlib.h>
1783 int main(void){
1784 struct timeval tv;
1785 int sockfd = 3;
1787 tv.tv_sec = 42;
1788 tv.tv_usec = 21;
1789 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
1790 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
1791 return 0;
1795 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
1796 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
1797 #include <sys/socket.h>
1798 #include <stdlib.h>
1799 int main(void){
1800 struct linger li;
1801 int sockfd = 3;
1803 li.l_onoff = 1;
1804 li.l_linger = 42;
1805 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
1806 return 0;
1810 if feat_yes SSL; then
1811 if link_check openssl 'OpenSSL (new style *_client_method(3ssl))' \
1812 '#define HAVE_SSL
1813 #define HAVE_OPENSSL 10100' '-lssl -lcrypto' << \!
1814 #include <openssl/ssl.h>
1815 #include <openssl/err.h>
1816 #include <openssl/x509v3.h>
1817 #include <openssl/x509.h>
1818 #include <openssl/rand.h>
1819 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1820 # error We need TLSv1.
1821 #endif
1822 int main(void){
1823 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1825 SSL_CTX_free(ctx);
1826 PEM_read_PrivateKey(0, 0, 0, 0);
1827 return 0;
1830 then
1832 elif link_check openssl 'OpenSSL (old style *_client_method(3ssl))' \
1833 '#define HAVE_SSL
1834 #define HAVE_OPENSSL 10000' '-lssl -lcrypto' << \!
1835 #include <openssl/ssl.h>
1836 #include <openssl/err.h>
1837 #include <openssl/x509v3.h>
1838 #include <openssl/x509.h>
1839 #include <openssl/rand.h>
1840 #if defined OPENSSL_NO_SSL3 &&\
1841 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
1842 # error We need one of SSLv3 and TLSv1.
1843 #endif
1844 int main(void){
1845 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1847 SSL_CTX_free(ctx);
1848 PEM_read_PrivateKey(0, 0, 0, 0);
1849 return 0;
1852 then
1854 else
1855 feat_bail_required SSL
1858 if [ "${have_openssl}" = 'yes' ]; then
1859 compile_check stack_of 'OpenSSL STACK_OF()' \
1860 '#define HAVE_OPENSSL_STACK_OF' << \!
1861 #include <stdio.h> /* For C89 NULL */
1862 #include <openssl/ssl.h>
1863 #include <openssl/err.h>
1864 #include <openssl/x509v3.h>
1865 #include <openssl/x509.h>
1866 #include <openssl/rand.h>
1867 int main(void){
1868 STACK_OF(GENERAL_NAME) *gens = NULL;
1870 printf("%p", gens); /* to use it */
1871 return 0;
1875 link_check ossl_conf 'OpenSSL_modules_load_file() support' \
1876 '#define HAVE_OPENSSL_CONFIG' << \!
1877 #include <stdio.h> /* For C89 NULL */
1878 #include <openssl/conf.h>
1879 int main(void){
1880 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
1881 CONF_modules_free();
1882 return 0;
1886 link_check ossl_conf_ctx 'OpenSSL SSL_CONF_CTX support' \
1887 '#define HAVE_OPENSSL_CONF_CTX' << \!
1888 #include "config.h"
1889 #include <openssl/ssl.h>
1890 #include <openssl/err.h>
1891 int main(void){
1892 #if HAVE_OPENSSL < 10100
1893 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
1894 #else
1895 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
1896 #endif
1897 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
1899 SSL_CONF_CTX_set_flags(cctx,
1900 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
1901 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
1902 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
1903 SSL_CONF_cmd(cctx, "Protocol", "ALL");
1904 SSL_CONF_CTX_finish(cctx);
1905 SSL_CONF_CTX_free(cctx);
1906 SSL_CTX_free(ctx);
1907 return 0;
1911 link_check rand_egd 'OpenSSL RAND_egd(3ssl)' \
1912 '#define HAVE_OPENSSL_RAND_EGD' << \!
1913 #include <openssl/rand.h>
1914 int main(void){
1915 return RAND_egd("some.where") > 0;
1919 if feat_yes SSL_ALL_ALGORITHMS; then
1920 if link_check ssl_all_algo 'OpenSSL all-algorithms support' \
1921 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
1922 #include <openssl/evp.h>
1923 int main(void){
1924 OpenSSL_add_all_algorithms();
1925 EVP_get_cipherbyname("two cents i never exist");
1926 EVP_cleanup();
1927 return 0;
1930 then
1932 else
1933 feat_bail_required SSL_ALL_ALGORITHMS
1935 fi # SSL_ALL_ALGORITHMS
1937 if feat_yes MD5 && feat_no NOEXTMD5; then
1938 run_check openssl_md5 'MD5 digest in OpenSSL' \
1939 '#define HAVE_OPENSSL_MD5' << \!
1940 #include <stdlib.h>
1941 #include <string.h>
1942 #include <openssl/md5.h>
1943 int main(void){
1944 char const dat[] = "abrakadabrafidibus";
1945 char dig[16], hex[16 * 2];
1946 MD5_CTX ctx;
1947 size_t i, j;
1949 memset(dig, 0, sizeof(dig));
1950 memset(hex, 0, sizeof(hex));
1951 MD5_Init(&ctx);
1952 MD5_Update(&ctx, dat, sizeof(dat) - 1);
1953 MD5_Final(dig, &ctx);
1955 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
1956 for(i = 0; i < sizeof(hex) / 2; i++){
1957 j = i << 1;
1958 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
1959 hex[++j] = hexchar(dig[i] & 0x0f);
1961 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
1964 fi # feat_yes MD5 && feat_no NOEXTMD5
1966 else
1967 echo '/* WANT_SSL=0 */' >> ${h}
1968 fi # feat_yes SSL
1970 if feat_yes SMTP; then
1971 echo '#define HAVE_SMTP' >> ${h}
1972 else
1973 echo '/* WANT_SMTP=0 */' >> ${h}
1976 if feat_yes POP3; then
1977 echo '#define HAVE_POP3' >> ${h}
1978 else
1979 echo '/* WANT_POP3=0 */' >> ${h}
1982 if feat_yes GSSAPI; then
1983 ${cat} > ${tmp2}.c << \!
1984 #include <gssapi/gssapi.h>
1985 int main(void){
1986 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
1987 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
1988 return 0;
1991 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
1993 if command -v krb5-config >/dev/null 2>&1; then
1994 i=`command -v krb5-config`
1995 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
1996 GSS_INCS="`CFLAGS= ${i} --cflags`"
1997 i='GSS-API via krb5-config(1)'
1998 else
1999 GSS_LIBS='-lgssapi'
2000 GSS_INCS=
2001 i='GSS-API in gssapi/gssapi.h, libgssapi'
2003 if < ${tmp2}.c link_check gss \
2004 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2005 < ${tmp3}.c link_check gss \
2006 'GSS-API in gssapi.h, libgssapi' \
2007 '#define HAVE_GSSAPI
2008 #define GSSAPI_REG_INCLUDE' \
2009 '-lgssapi' ||\
2010 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2011 '#define HAVE_GSSAPI' \
2012 '-lgssapi_krb5' ||\
2013 < ${tmp3}.c link_check gss \
2014 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2015 '#define HAVE_GSSAPI
2016 #define GSS_REG_INCLUDE' \
2017 '-lgssapi -lkrb5 -lcrypto' \
2018 '-I/usr/include/kerberosV' ||\
2019 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2020 '#define HAVE_GSSAPI' \
2021 '-lgss' ||\
2022 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2023 '#define HAVE_GSSAPI
2024 #define GSSAPI_OLD_STYLE' \
2025 '-lgssapi_krb5' << \!
2026 #include <gssapi/gssapi.h>
2027 #include <gssapi/gssapi_generic.h>
2028 int main(void){
2029 gss_import_name(0, 0, gss_nt_service_name, 0);
2030 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2031 return 0;
2034 then
2036 else
2037 feat_bail_required GSSAPI
2039 else
2040 echo '/* WANT_GSSAPI=0 */' >> ${h}
2041 fi # feat_yes GSSAPI
2043 if feat_yes NETRC; then
2044 echo '#define HAVE_NETRC' >> ${h}
2045 else
2046 echo '/* WANT_NETRC=0 */' >> ${h}
2049 if feat_yes AGENT; then
2050 echo '#define HAVE_AGENT' >> ${h}
2051 else
2052 echo '/* WANT_AGENT=0 */' >> ${h}
2055 if feat_yes IDNA; then
2056 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2057 '-lidn' << \!
2058 #include <idna.h>
2059 #include <idn-free.h>
2060 #include <stringprep.h>
2061 int main(void){
2062 char *utf8, *idna_ascii, *idna_utf8;
2064 utf8 = stringprep_locale_to_utf8("does.this.work");
2065 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2066 != IDNA_SUCCESS)
2067 return 1;
2068 idn_free(idna_ascii);
2069 /* (Rather link check only here) */
2070 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2071 return 0;
2074 then
2076 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2077 '-lidnkit' << \!
2078 #include <stdio.h>
2079 #include <idn/api.h>
2080 #include <idn/result.h>
2081 int main(void){
2082 idn_result_t r;
2083 char ace_name[256];
2084 char local_name[256];
2086 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2087 sizeof(ace_name));
2088 if (r != idn_success) {
2089 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2090 return 1;
2092 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2093 if (r != idn_success) {
2094 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2095 return 1;
2097 return 0;
2100 then
2102 else
2103 feat_bail_required IDNA
2106 if [ -n "${have_idna}" ]; then
2107 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2108 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2110 else
2111 echo '/* WANT_IDNA=0 */' >> ${h}
2114 if feat_yes IMAP_SEARCH; then
2115 echo '#define HAVE_IMAP_SEARCH' >> ${h}
2116 else
2117 echo '/* WANT_IMAP_SEARCH=0 */' >> ${h}
2120 if feat_yes REGEX; then
2121 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2122 #include <regex.h>
2123 #include <stdlib.h>
2124 int main(void){
2125 int status;
2126 regex_t re;
2128 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
2129 return 1;
2130 status = regexec(&re, "plan9", 0,NULL, 0);
2131 regfree(&re);
2132 return !(status == REG_NOMATCH);
2135 then
2137 else
2138 feat_bail_required REGEX
2140 else
2141 echo '/* WANT_REGEX=0 */' >> ${h}
2144 if feat_yes READLINE; then
2145 __edrdlib() {
2146 link_check readline "for readline(3) (${1})" \
2147 '#define HAVE_READLINE' "${1}" << \!
2148 #include <stdio.h>
2149 #include <readline/history.h>
2150 #include <readline/readline.h>
2151 int main(void){
2152 char *rl;
2153 HISTORY_STATE *hs;
2154 HIST_ENTRY **he;
2155 int i;
2157 using_history();
2158 read_history("");
2159 stifle_history(242);
2160 rl = readline("Enter a line:");
2161 if (rl && *rl)
2162 add_history(rl);
2163 write_history("");
2164 rl_extend_line_buffer(10);
2165 rl_point = rl_end = 10;
2166 rl_pre_input_hook = (rl_hook_func_t*)NULL;
2167 rl_forced_update_display();
2168 clear_history();
2169 hs = history_get_history_state();
2170 i = hs->length;
2171 he = history_list();
2172 if (i > 0)
2173 rl = he[0]->line;
2174 rl_free_line_state();
2175 rl_cleanup_after_signal();
2176 rl_reset_after_signal();
2177 return 0;
2182 __edrdlib -lreadline ||
2183 __edrdlib '-lreadline -ltermcap' || feat_bail_required READLINE
2186 if feat_yes MLE && [ -z "${have_readline}" ] &&
2187 [ -n "${have_c90amend1}" ]; then
2188 have_mle=1
2189 echo '#define HAVE_MLE' >> ${h}
2190 else
2191 feat_bail_required MLE
2192 echo '/* WANT_{READLINE,MLE}=0 */' >> ${h}
2195 # Generic have-a-line-editor switch for those who need it below
2196 if [ -n "${have_mle}" ] ||
2197 [ -n "${have_readline}" ]; then
2198 have_cle=1
2201 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2202 echo '#define HAVE_HISTORY' >> ${h}
2203 else
2204 echo '/* WANT_HISTORY=0 */' >> ${h}
2207 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2208 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2209 else
2210 echo '/* WANT_KEY_BINDINGS=0 */' >> ${h}
2213 if feat_yes TERMCAP; then
2214 __termcaplib() {
2215 link_check termcap "termcap(5) (via ${4})" \
2216 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2217 #include <stdio.h>
2218 #include <stdlib.h>
2219 ${2}
2220 #include <term.h>
2221 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2222 static int my_putc(int c){return putchar(c);}
2223 int main(void){
2224 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2225 int r2 = OK, r3 = ERR;
2227 tgetent(buf, getenv("TERM"));
2228 cpb = cmdbuf;
2229 r1 = tgetstr(UNCONST("cm"), &cpb);
2230 tgoto(r1, 1, 1);
2231 r2 = tgetnum(UNCONST("Co"));
2232 r3 = tgetflag(UNCONST("ut"));
2233 tputs("cr", 1, &my_putc);
2234 return (r1 == NULL || r2 == -1 || r3 == 0);
2236 _EOT
2239 __terminfolib() {
2240 link_check terminfo "terminfo(5) (via ${2})" \
2241 '#define HAVE_TERMCAP
2242 #define HAVE_TERMCAP_CURSES
2243 #define HAVE_TERMINFO' "${1}" << _EOT
2244 #include <stdio.h>
2245 #include <curses.h>
2246 #include <term.h>
2247 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2248 static int my_putc(int c){return putchar(c);}
2249 int main(void){
2250 int er, r0, r1, r2;
2251 char *r3, *tp;
2253 er = OK;
2254 r0 = setupterm(NULL, 1, &er);
2255 r1 = tigetflag(UNCONST("bce"));
2256 r2 = tigetnum(UNCONST("colors"));
2257 r3 = tigetstr(UNCONST("cr"));
2258 tp = tparm(r3, NULL);
2259 tputs(tp, 1, &my_putc);
2260 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2261 r3 == (char*)-1 || r3 == NULL);
2263 _EOT
2266 if feat_yes TERMCAP_PREFER_TERMINFO; then
2267 __terminfolib -ltinfo -ltinfo ||
2268 __terminfolib -lcurses -lcurses ||
2269 __terminfolib -lcursesw -lcursesw ||
2270 feat_bail_required TERMCAP_PREFER_TERMINFO
2273 if [ -z "${have_terminfo}" ]; then
2274 __termcaplib -ltermcap '' '' '-ltermcap' ||
2275 __termcaplib -ltermcap '#include <curses.h>' '
2276 #define HAVE_TERMCAP_CURSES' \
2277 'curses.h / -ltermcap' ||
2278 __termcaplib -lcurses '#include <curses.h>' '
2279 #define HAVE_TERMCAP_CURSES' \
2280 'curses.h / -lcurses' ||
2281 __termcaplib -lcursesw '#include <curses.h>' '
2282 #define HAVE_TERMCAP_CURSES' \
2283 'curses.h / -lcursesw' ||
2284 feat_bail_required TERMCAP
2286 if [ -n "${have_termcap}" ]; then
2287 run_check tgetent_null \
2288 "tgetent(3) of termcap(5) takes NULL buffer" \
2289 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2290 #include <stdio.h> /* For C89 NULL */
2291 #include <stdlib.h>
2292 #ifdef HAVE_TERMCAP_CURSES
2293 # include <curses.h>
2294 #endif
2295 #include <term.h>
2296 int main(void){
2297 tgetent(NULL, getenv("TERM"));
2298 return 0;
2300 _EOT
2303 else
2304 echo '/* WANT_TERMCAP=0 */' >> ${h}
2305 echo '/* WANT_TERMCAP_PREFER_TERMINFO=0 */' >> ${h}
2308 if feat_yes SPAM_SPAMC; then
2309 echo '#define HAVE_SPAM_SPAMC' >> ${h}
2310 if command -v spamc >/dev/null 2>&1; then
2311 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2313 else
2314 echo '/* WANT_SPAM_SPAMC=0 */' >> ${h}
2317 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2318 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2319 else
2320 feat_bail_required SPAM_SPAMD
2321 echo '/* WANT_SPAM_SPAMD=0 */' >> ${h}
2324 feat_def SPAM_FILTER
2326 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2327 echo '#define HAVE_SPAM' >> ${h}
2328 else
2329 echo '/* HAVE_SPAM */' >> ${h}
2332 if feat_yes QUOTE_FOLD &&\
2333 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2334 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2335 else
2336 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
2339 feat_def FILTER_HTML_TAGSOUP
2340 feat_def COLOUR
2341 feat_def DOTLOCK
2342 feat_def MD5
2343 feat_def NOMEMDBG
2345 ## Summarizing
2347 ${rm} -f ${tmp}
2348 squeeze_em ${inc} ${tmp}
2349 ${mv} ${tmp} ${inc}
2350 squeeze_em ${lib} ${tmp}
2351 ${mv} ${tmp} ${lib}
2353 # config.h
2354 ${mv} ${h} ${tmp}
2355 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2356 ${cat} ${tmp} >> ${h}
2357 ${rm} -f ${tmp}
2359 printf '\n/* The "feature string" */\n' >> ${h}
2360 printf '# if defined _ACCMACVAR_SOURCE || defined HAVE_AMALGAMATION\n' >> ${h}
2361 printf 'static char const _features[] = "MIME"\n' >> ${h}
2362 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
2363 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
2364 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
2365 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
2366 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
2367 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TLS"\n# endif\n' >> ${h}
2368 printf '# ifdef HAVE_SSL_ALL_ALGORITHMS\n ",SSL-ALL-ALGORITHMS"\n# endif\n'\
2369 >> ${h}
2370 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
2371 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
2372 printf '# ifdef HAVE_GSSAPI\n ",GSS-API"\n# endif\n' >> ${h}
2373 printf '# ifdef HAVE_MD5\n ",MD5 [APOP,CRAM-MD5]"\n# endif\n' >> ${h}
2374 printf '# ifdef HAVE_NETRC\n ",NETRC"\n# endif\n' >> ${h}
2375 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
2376 printf '# ifdef HAVE_IMAP_SEARCH\n ",IMAP-SEARCH"\n# endif\n' >> ${h}
2377 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
2378 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
2379 printf '# ifdef HAVE_MLE\n ",MLE"\n# endif\n' >> ${h}
2380 printf '# ifdef HAVE_WCWIDTH\n " (WIDE GLYPHS)"\n# endif\n' >> ${h}
2381 printf '# ifdef HAVE_HISTORY\n ",HISTORY"\n# endif\n' >> ${h}
2382 printf '# ifdef HAVE_KEY_BINDINGS\n ",KEY-BINDINGS"\n# endif\n' >> ${h}
2383 printf '# ifdef HAVE_TERMCAP\n ",TERMCAP"\n# endif\n' >> ${h}
2384 printf '# ifdef HAVE_TERMINFO\n " (terminfo(5))"\n# endif\n' >> ${h}
2385 printf '# ifdef HAVE_SPAM_SPAMC\n ",SPAMC"\n# endif\n' >> ${h}
2386 printf '# ifdef HAVE_SPAM_SPAMD\n ",SPAMD"\n# endif\n' >> ${h}
2387 printf '# ifdef HAVE_SPAM_FILTER\n ",SPAMFILTER"\n# endif\n' >> ${h}
2388 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
2389 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
2390 printf '# ifdef HAVE_FILTER_HTML_TAGSOUP\n ",HTML-FILTER"\n# endif\n' >> ${h}
2391 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
2392 printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h}
2393 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
2394 printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h}
2395 printf '# ifdef HAVE_CROSS_BUILD\n ",CROSS-BUILD"\n# endif\n' >> ${h}
2396 printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h}
2398 # Create the real mk.mk
2399 # Note we cannout use explicit ./ filename prefix for source and object
2400 # pathnames because of a bug in bmake(1)
2401 ${rm} -rf ${tmp0}.* ${tmp0}*
2402 printf 'OBJ_SRC = ' >> ${mk}
2403 if feat_no AMALGAMATION; then
2404 for i in `printf '%s\n' *.c | ${sort}`; do
2405 if [ "${i}" = privsep.c ]; then
2406 continue
2408 printf "${i} " >> ${mk}
2409 done
2410 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2411 else
2412 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2414 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2415 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2416 printf '# undef _CONFIG_H\n' >> ${h}
2417 printf '# define _CONFIG_H 2\n' >> ${h}
2418 for i in `printf '%s\n' *.c | ${sort}`; do
2419 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2420 [ "${i}" = privsep.c ]; then
2421 continue
2423 printf "${i} " >> ${mk}
2424 printf "# include \"${i}\"\n" >> ${h}
2425 done
2426 echo >> ${mk}
2427 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2428 echo '#else' >> ${h}
2431 printf '#endif /* n_CONFIG_H */\n' >> ${h}
2433 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2434 echo "INCS = `${cat} ${inc}`" >> ${mk}
2435 echo >> ${mk}
2436 ${cat} ./mk-mk.in >> ${mk}
2438 ## Finished!
2440 ${cat} > ${tmp2}.c << \!
2441 #include "config.h"
2443 :The following optional features are enabled:
2444 #ifdef HAVE_SETLOCALE
2445 : + Locale support: Printable characters depend on the environment
2446 # ifdef HAVE_C90AMEND1
2447 : + Multibyte character support
2448 # endif
2449 # ifdef HAVE_NL_LANGINFO
2450 : + Automatic detection of terminal character set
2451 # endif
2452 #endif
2453 #ifdef HAVE_ICONV
2454 : + Character set conversion using iconv()
2455 #endif
2456 #ifdef HAVE_SOCKETS
2457 : + Network support
2458 #endif
2459 #ifdef HAVE_SSL
2460 # ifdef HAVE_OPENSSL
2461 : + S/MIME and SSL/TLS (OpenSSL)
2462 # endif
2463 # ifdef HAVE_SSL_ALL_ALGORITHMS
2464 : + + Support for more ("all") digest and cipher algorithms
2465 # endif
2466 #endif
2467 #ifdef HAVE_SMTP
2468 : + SMTP protocol
2469 #endif
2470 #ifdef HAVE_POP3
2471 : + POP3 protocol
2472 #endif
2473 #ifdef HAVE_GSSAPI
2474 : + GSS-API authentication
2475 #endif
2476 #ifdef HAVE_MD5
2477 : + MD5 message digest (APOP, CRAM-MD5)
2478 #endif
2479 #ifdef HAVE_NETRC
2480 : + .netrc file support
2481 #endif
2482 #ifdef HAVE_IDNA
2483 : + IDNA (internationalized domain names for applications) support
2484 #endif
2485 #ifdef HAVE_IMAP_SEARCH
2486 : + IMAP-style search expressions
2487 #endif
2488 #ifdef HAVE_REGEX
2489 : + Regular expression support (searches, conditional expressions etc.)
2490 #endif
2491 #if defined HAVE_READLINE || defined HAVE_MLE
2492 # ifdef HAVE_READLINE
2493 : + Command line editing via readline(3)
2494 # else
2495 # ifdef HAVE_WCWIDTH
2496 : + Command line editing via M(ailx)-L(ine)-E(ditor) (wide glyph support)
2497 # else
2498 : + Command line editing via M(ailx)-L(ine)-E(ditor) (no wide glyph support)
2499 # endif
2500 # endif
2501 # ifdef HAVE_HISTORY
2502 : + + History management
2503 # endif
2504 # ifdef HAVE_KEY_BINDINGS
2505 : + + Configurable key bindings
2506 # endif
2507 #endif
2508 #ifdef HAVE_TERMCAP
2509 # ifdef HAVE_TERMINFO
2510 : + Terminal capability queries (terminfo(5))
2511 # else
2512 : + Terminal capability queries (termcap(5))
2513 # endif
2514 #endif
2515 #ifdef HAVE_SPAM
2516 : + Spam management
2517 # ifdef HAVE_SPAM_SPAMC
2518 : + + Via spamc(1) (of spamassassin(1))
2519 # endif
2520 # ifdef HAVE_SPAM_SPAMD
2521 : + + Directly via spamd(1) (of spamassassin(1))
2522 # endif
2523 # ifdef HAVE_SPAM_FILTER
2524 : + + Via freely configurable *spam-filter-XY*s
2525 # endif
2526 #endif
2527 #ifdef HAVE_DOCSTRINGS
2528 : + Documentation summary strings
2529 #endif
2530 #ifdef HAVE_QUOTE_FOLD
2531 : + Extended *quote-fold*ing
2532 #endif
2533 #ifdef HAVE_FILTER_HTML_TAGSOUP
2534 : + Builtin HTML-to-text filter (for display purposes, primitive)
2535 #endif
2536 #ifdef HAVE_COLOUR
2537 : + Coloured message display (simple)
2538 #endif
2539 #ifdef HAVE_DOTLOCK
2540 : + Dotlock files and privilege-separated file dotlock program
2541 #endif
2543 :The following optional features are disabled:
2544 #ifndef HAVE_SETLOCALE
2545 : - Locale support: Only ASCII characters are recognized
2546 #endif
2547 # ifndef HAVE_C90AMEND1
2548 : - Multibyte character support
2549 # endif
2550 # ifndef HAVE_NL_LANGINFO
2551 : - Automatic detection of terminal character set
2552 # endif
2553 #ifndef HAVE_ICONV
2554 : - Character set conversion using iconv()
2555 : _ (Ooooh, no iconv(3), NO character set conversion possible! Really...)
2556 #endif
2557 #ifndef HAVE_SOCKETS
2558 : - Network support
2559 #endif
2560 #ifndef HAVE_SSL
2561 : - S/MIME and SSL/TLS
2562 #else
2563 # ifndef HAVE_SSL_ALL_ALGORITHMS
2564 : - Support for more S/MIME and SSL/TLS digest and cipher algorithms
2565 # endif
2566 #endif
2567 #ifndef HAVE_SMTP
2568 : - SMTP protocol
2569 #endif
2570 #ifndef HAVE_POP3
2571 : - POP3 protocol
2572 #endif
2573 #ifndef HAVE_GSSAPI
2574 : - GSS-API authentication
2575 #endif
2576 #ifndef HAVE_MD5
2577 : - MD5 message digest (APOP, CRAM-MD5)
2578 #endif
2579 #ifndef HAVE_NETRC
2580 : - .netrc file support
2581 #endif
2582 #ifndef HAVE_IDNA
2583 : - IDNA (internationalized domain names for applications) support
2584 #endif
2585 #ifndef HAVE_IMAP_SEARCH
2586 : - IMAP-style search expressions
2587 #endif
2588 #ifndef HAVE_REGEX
2589 : - Regular expression support
2590 #endif
2591 #if !defined HAVE_READLINE && !defined HAVE_MLE
2592 : - Command line editing and history
2593 #else
2594 # ifndef HAVE_HISTORY
2595 : + (Command line editing) - History management
2596 # endif
2597 # ifndef HAVE_KEY_BINDINGS
2598 : + (Command line editing) - Configurable key bindings
2599 # endif
2600 #endif
2601 #ifndef HAVE_TERMCAP
2602 : - Terminal capability queries
2603 #endif
2604 #ifndef HAVE_SPAM
2605 : - Spam management
2606 #endif
2607 #ifndef HAVE_DOCSTRINGS
2608 : - Documentation summary strings
2609 #endif
2610 #ifndef HAVE_QUOTE_FOLD
2611 : - Extended *quote-fold*ing
2612 #endif
2613 #ifndef HAVE_FILTER_HTML_TAGSOUP
2614 : - Builtin HTML-to-text filter (for display purposes, primitive)
2615 #endif
2616 #ifndef HAVE_COLOUR
2617 : - Coloured message display (simple)
2618 #endif
2619 #ifndef HAVE_DOTLOCK
2620 : - Dotlock files and privilege-separated file dotlock program
2621 #endif
2623 #if !defined HAVE_FNMATCH || !defined HAVE_FCHDIR ||\
2624 defined HAVE_DEBUG || defined HAVE_DEVEL
2625 :Remarks:
2626 # ifndef HAVE_FNMATCH
2627 : . The function fnmatch(3) could not be found.
2628 : _ Filename patterns like wildcard are not supported on your system.
2629 # endif
2630 # ifndef HAVE_FCHDIR
2631 : . The function fchdir(2) could not be found. We will use chdir(2)
2632 : _ instead. This is not a problem unless the current working
2633 : _ directory is changed while this program is inside of it.
2634 # endif
2635 # ifdef HAVE_DEBUG
2636 : . Debug enabled binary: not meant to be used by end-users: THANKS!
2637 # endif
2638 # ifdef HAVE_DEVEL
2639 : . Computers do not blunder.
2640 # endif
2642 #endif /* Remarks */
2643 :Setup:
2644 : . System-wide resource file: SYSCONFDIR/SYSCONFRC
2645 : . bindir: BINDIR
2646 #ifdef HAVE_DOTLOCK
2647 : . libexecdir: LIBEXECDIR
2648 #endif
2649 : . mandir: MANDIR
2650 : . sendmail(1): VAL_SENDMAIL (argv[0] = VAL_SENDMAIL_PROGNAME)
2651 : . Mail spool directory: MAILSPOOL
2655 ${make} -f ${makefile} ${tmp2}.x
2656 < ${tmp2}.x ${sed} -e '/^[^:]/d; /^$/d; s/^://' |
2657 while read l; do
2658 msg "${l}"
2659 done
2661 # s-it-mode