Add is_mlist_mp() and :Ll colon modifiers, and use "Ll" for *headline*'s %T
[s-mailx.git] / make-config.sh
blob3c3a16fb1809fd28fdc2431e9bb888b123c7d7f4
1 #!/bin/sh -
2 #@ Please see INSTALL and make.rc instead.
4 LC_ALL=C
5 export LC_ALL
7 # For heaven's sake auto-redirect on SunOS/Solaris
8 if [ "x${SHELL}" = x ] || [ "${SHELL}" = /bin/sh ] && \
9 [ -f /usr/xpg4/bin/sh ] && [ -x /usr/xpg4/bin/sh ]; then
10 SHELL=/usr/xpg4/bin/sh
11 export SHELL
12 exec /usr/xpg4/bin/sh "${0}" "${@}"
14 [ -n "${SHELL}" ] || SHELL=/bin/sh
15 export SHELL
17 # The feature set, to be kept in sync with make.rc
18 # If no documentation given, the option is used as such; if doc is a hyphen,
19 # entry is suppressed when configuration overview is printed, and also in the
20 # *features* string: most likely for obsolete features etc.
21 XOPTIONS="\
22 ICONV='Character set conversion using iconv(3)' \
23 SOCKETS='Network support' \
24 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
25 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
26 SMTP='Simple Mail Transfer Protocol client' \
27 POP3='Post Office Protocol Version 3 client' \
28 IMAP='IMAP v4r1 client' \
29 GSSAPI='Generic Security Service authentication' \
30 NETRC='.netrc file support' \
31 AGENT='-' \
32 MD5='MD5 message digest (APOP, CRAM-MD5)' \
33 IDNA='Internationalized Domain Names for Applications (encode only)' \
34 IMAP_SEARCH='IMAP-style search expressions' \
35 REGEX='Regular expressions' \
36 MLE='Mailx Line Editor' \
37 HISTORY='Line editor history management' \
38 KEY_BINDINGS='Configurable key bindings' \
39 TERMCAP='Terminal capability queries (termcap(5))' \
40 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
41 ERRORS='Error log message ring' \
42 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
43 SPAM_SPAMD='-' \
44 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
45 DOCSTRINGS='Command documentation help strings' \
46 QUOTE_FOLD='Extended *quote-fold*ing' \
47 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
48 COLOUR='Coloured message display' \
49 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
52 # Options which are automatically deduced from host environment, i.e., these
53 # need special treatment all around here to warp from/to OPT_ stuff
54 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
55 XOPTIONS_DETECT="\
56 LOCALES='Locale support - printable characters etc. depend on environment' \
57 MULTIBYTE_CHARSETS='Multibyte character sets' \
58 TERMINAL_CHARSET='Automatic detection of terminal character set' \
59 WIDE_GLYPHS='Wide glyph support' \
62 # Rather special options, for custom building, or which always exist.
63 # Mostly for generating the visual overview and the *features* string
64 XOPTIONS_XTRA="\
65 MIME='Multipurpose Internet Mail Extensions' \
66 SMIME='S/MIME message signing, verification, en- and decryption' \
67 CROSS_BUILD='Cross-compilation: trust any detected environment' \
68 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
69 DEVEL='Computers do not blunder' \
72 # The problem is that we don't have any tools we can use right now, so
73 # encapsulate stuff in functions which get called in right order later on
75 option_reset() {
76 set -- ${OPTIONS}
77 for i
79 eval OPT_${i}=0
80 done
83 option_maximal() {
84 set -- ${OPTIONS}
85 for i
87 eval OPT_${i}=1
88 done
89 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
92 option_setup() {
93 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
94 option_parse OPTIONS "${XOPTIONS}"
95 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
96 OPT_MIME=1
98 # Predefined CONFIG= urations take precedence over anything else
99 if [ -n "${CONFIG}" ]; then
100 option_reset
101 case "${CONFIG}" in
102 [nN][uU][lL][lL])
104 [nN][uU][lL][lL][iI])
105 OPT_ICONV=require
107 [mM][iI][nN][iI][mM][aA][lL])
108 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
109 OPT_COLOUR=1
110 OPT_DOCSTRINGS=1
111 OPT_ERRORS=1
112 OPT_IDNA=1
113 OPT_MLE=1
114 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
115 OPT_SPAM_FILTER=1
117 [nN][eE][tT][sS][eE][nN][dD])
118 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
119 OPT_SOCKETS=require
120 OPT_SSL=require
121 OPT_SMTP=require
122 OPT_GSSAPI=1 OPT_NETRC=1
123 OPT_AGENT=1
124 OPT_COLOUR=1
125 OPT_DOCSTRINGS=1
126 OPT_ERRORS=1
127 OPT_IDNA=1
128 OPT_MLE=1
129 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
130 OPT_SPAM_FILTER=1
132 [mM][aA][xX][iI][mM][aA][lL])
133 option_maximal
135 [dD][eE][vV][eE][lL])
136 option_maximal
137 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
139 [oO][dD][eE][vV][eE][lL])
140 option_maximal
141 OPT_DEVEL=1
144 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
145 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
146 exit 1
148 esac
149 msg_nonl "CONFIG=${CONFIG} ... "
153 # Inter-relationships XXX sort this!
154 option_update() {
155 if feat_no SSL; then
156 OPT_SSL_ALL_ALGORITHMS=0
159 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
160 OPT_SOCKETS=0
162 if feat_no SOCKETS; then
163 if feat_require SMTP; then
164 msg 'ERROR: need SOCKETS for required feature SMTP'
165 config_exit 13
167 if feat_require POP3; then
168 msg 'ERROR: need SOCKETS for required feature POP3'
169 config_exit 13
171 if feat_require IMAP; then
172 msg 'ERROR: need SOCKETS for required feature IMAP'
173 config_exit 13
175 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
176 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
177 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
179 if feat_no SMTP && feat_no IMAP; then
180 OPT_GSSAPI=0
183 if feat_no ICONV; then
184 if feat_yes IMAP; then
185 if feat_require IMAP; then
186 msg 'ERROR: need ICONV for required feature IMAP'
187 config_exit 13
189 msg 'ERROR: disabling IMAP due to missing ICONV'
190 OPT_IMAP=0
193 if feat_yes IDNA; then
194 if feat_require IDNA; then
195 msg 'ERROR: need ICONV for required feature IDNA'
196 config_exit 13
198 msg 'ERROR: disabling IDNA due to missing ICONV'
199 OPT_IDNA=0
203 if feat_no MLE; then
204 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
207 # If we don't need MD5 leave it alone
208 if feat_no SOCKETS; then
209 OPT_MD5=0
212 if feat_no TERMCAP; then
213 OPT_TERMCAP_VIA_TERMINFO=0
216 if feat_yes DEVEL; then
217 OPT_DEBUG=1
221 rc=./make.rc
222 lst=./mk-config.lst
223 ev=./mk-config.ev
224 h=./mk-config.h h_name=mk-config.h
225 mk=./mk-config.mk
227 newlst=./mk-nconfig.lst
228 newmk=./mk-nconfig.mk
229 newev=./mk-nconfig.ev
230 newh=./mk-nconfig.h
231 tmp0=___tmp
232 tmp=./${tmp0}1$$
233 tmp2=./${tmp0}2$$
235 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
237 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
238 # via path_check() later on once possible
240 # TODO cc_maxopt is brute simple, we should compile test program and dig real
241 # compiler versions for known compilers, then be more specific
242 [ -n "${cc_maxopt}" ] || cc_maxopt=100
243 _CFLAGS= _LDFLAGS=
245 os_early_setup() {
246 # We don't "have any utility": only path adjustments and such in here!
247 [ -n "${OS}" ] || OS=`uname -s`
248 export OS
250 if [ ${OS} = SunOS ]; then
251 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
252 _os_early_setup_sunos
256 _os_early_setup_sunos() {
257 # According to standards(5), this is what we need to do
258 if [ -d /usr/xpg4 ]; then :; else
259 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
260 config_exit 1
262 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
263 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
264 export PATH
267 os_setup() {
268 # OSENV ends up in *build-osenv*
269 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
270 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
271 [ -n "${OSENV}" ] || OSENV=`uname -srm`
272 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`uname -a`
273 msg 'Operating system is %s' ${OS}
275 if [ ${OS} = darwin ]; then
276 msg ' . have special Darwin environmental addons...'
277 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
278 elif [ ${OS} = sunos ]; then
279 msg ' . have special SunOS / Solaris "setup" rules ...'
280 _os_setup_sunos
281 elif [ ${OS} = unixware ]; then
282 if feat_yes AUTOCC && acmd_set CC cc; then
283 msg ' . have special UnixWare environmental rules ...'
284 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
286 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
287 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
288 export CC CFLAGS LDFLAGS
289 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
291 elif [ -n "${VERBOSE}" ]; then
292 msg ' . no special treatment for this system necessary or known'
295 # Sledgehammer: better set _GNU_SOURCE
296 # And in general: oh, boy!
297 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
298 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
299 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
300 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
302 # On pkgsrc(7) systems automatically add /usr/pkg/*
303 if [ -d /usr/pkg ]; then
304 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
305 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
309 _os_setup_sunos() {
310 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
311 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
313 # Include packages
314 if [ -d /opt/csw ]; then
315 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
316 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
319 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
320 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
322 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
323 if [ -x "${cksum}" ]; then :; else
324 msg 'ERROR: Not an executable program: %s' "${cksum}"
325 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
326 msg 'ERROR: However, we do so only for tests.'
327 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
328 config_exit 1
331 if feat_yes AUTOCC; then
332 if acmd_set CC cc; then
333 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
335 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
336 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
337 export CC CFLAGS LDFLAGS
338 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
339 else
340 cc_maxopt=2 #force_no_stackprot=1
345 # Check out compiler ($CC) and -flags ($CFLAGS)
346 cc_setup() {
347 # Even though it belongs into cc_flags we will try to compile and link
348 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
349 # EXTRA_CFLAGS/EXTRA_LDFLAGS
350 if feat_no AUTOCC; then
351 _cc_default
352 # Ensure those don't do any harm
353 EXTRA_CFLAGS= EXTRA_LDFLAGS=
354 export EXTRA_CFLAGS EXTRA_LDFLAGS
355 return
356 else
357 CFLAGS= LDFLAGS=
358 export CFLAGS LDFLAGS
361 [ -n "${CC}" ] && { _cc_default; return; }
363 msg_nonl 'Searching for a usable C compiler .. $CC='
364 if acmd_set CC clang || acmd_set CC gcc ||
365 acmd_set CC tcc || acmd_set CC pcc ||
366 acmd_set CC c89 || acmd_set CC c99; then
368 else
369 msg 'boing booom tschak'
370 msg 'ERROR: I cannot find a compiler!'
371 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
372 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
373 config_exit 1
375 msg '%s' "${CC}"
376 export CC
379 _cc_default() {
380 if [ -z "${CC}" ]; then
381 msg 'To go on like you have chosen, please set $CC, rerun.'
382 config_exit 1
385 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
387 else
388 msg 'Using C compiler ${CC}=%s' "${CC}"
392 cc_flags() {
393 if feat_yes AUTOCC; then
394 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
395 cc_check_silent=1
396 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
397 "${CC}"
398 else
399 cc_check_silent=
400 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
403 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
404 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
405 msg ' . have special tcc(1) environmental rules ...'
406 _cc_flags_tcc
407 else
408 # As of pcc CVS 2016-04-02, stack protection support is announced but
409 # will break if used on Linux
410 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
411 force_no_stackprot=1
413 _cc_flags_generic
416 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
417 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
418 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
419 else
420 if feat_no DEBUG; then
421 CFLAGS="-DNDEBUG ${CFLAGS}"
424 msg ''
425 export CFLAGS LDFLAGS
428 _cc_flags_tcc() {
429 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
430 _CFLAGS= _LDFLAGS=
432 cc_check -Wall
433 cc_check -Wextra
434 cc_check -pedantic
436 if feat_yes DEBUG; then
437 # May have problems to find libtcc cc_check -b
438 cc_check -g
441 if ld_check -Wl,-rpath =./ no; then
442 need_R_ldflags=-Wl,-rpath=
443 ld_check -Wl,--enable-new-dtags
444 ld_runtime_flags # update!
447 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
448 unset __cflags __ldflags
451 _cc_flags_generic() {
452 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
453 _CFLAGS= _LDFLAGS=
454 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
456 # E.g., valgrind does not work well with high optimization
457 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
458 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
459 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
460 cc_maxopt=1
462 # Check -g first since some others may rely upon -g / optim. level
463 if feat_yes DEBUG; then
464 cc_check -O
465 cc_check -g
466 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
468 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
470 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
472 else
473 cc_check -O
476 if feat_yes AMALGAMATION; then
477 cc_check -pipe
480 #if feat_yes DEVEL && cc_check -Weverything; then
482 #else
483 cc_check -Wall
484 cc_check -Wextra
485 cc_check -Wbad-function-cast
486 cc_check -Wcast-align
487 cc_check -Wcast-qual
488 cc_check -Winit-self
489 cc_check -Wmissing-prototypes
490 cc_check -Wshadow
491 cc_check -Wunused
492 cc_check -Wwrite-strings
493 cc_check -Wno-long-long
495 cc_check -pedantic
497 if feat_yes AMALGAMATION && feat_no DEVEL; then
498 cc_check -Wno-unused-function
500 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
502 cc_check -fno-unwind-tables
503 cc_check -fno-asynchronous-unwind-tables
504 cc_check -fstrict-aliasing
505 if cc_check -fstrict-overflow && feat_yes DEVEL; then
506 cc_check -Wstrict-overflow=5
509 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
510 if [ -z "${force_no_stackprot}" ]; then
511 if cc_check -fstack-protector-strong ||
512 cc_check -fstack-protector-all; then
513 cc_check -D_FORTIFY_SOURCE=2
515 else
516 msg 'Not checking for -fstack-protector compiler option,'
517 msg 'since that caused errors in a "similar" configuration.'
518 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
522 # LD (+ dependend CC)
524 if feat_yes ASAN_ADDRESS; then
525 _ccfg=${_CFLAGS}
526 if cc_check -fsanitize=address &&
527 ld_check -fsanitize=address; then
529 else
530 feat_bail_required ASAN_ADDRESS
531 _CFLAGS=${_ccfg}
535 if feat_yes ASAN_MEMORY; then
536 _ccfg=${_CFLAGS}
537 if cc_check -fsanitize=memory &&
538 ld_check -fsanitize=memory &&
539 cc_check -fsanitize-memory-track-origins=2 &&
540 ld_check -fsanitize-memory-track-origins=2; then
542 else
543 feat_bail_required ASAN_MEMORY
544 _CFLAGS=${_ccfg}
548 ld_check -Wl,-z,relro
549 ld_check -Wl,-z,now
550 ld_check -Wl,-z,noexecstack
551 if ld_check -Wl,-rpath =./ no; then
552 need_R_ldflags=-Wl,-rpath=
553 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
554 ld_check -Wl,--enable-new-dtags
555 ld_runtime_flags # update!
556 elif ld_check -Wl,-R ./ no; then
557 need_R_ldflags=-Wl,-R
558 ld_check -Wl,--enable-new-dtags
559 ld_runtime_flags # update!
562 # Address randomization
563 _ccfg=${_CFLAGS}
564 if cc_check -fPIE || cc_check -fpie; then
565 ld_check -pie || _CFLAGS=${_ccfg}
567 unset _ccfg
569 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
570 unset __cflags __ldflags
573 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
575 ## Notes:
576 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
577 ## redirection, so use "printf '' >" instead
579 ## Very first: we undergo several states regarding I/O redirection etc.,
580 ## but need to deal with option updates from within all. Since all the
581 ## option stuff should be above the scissor line, define utility functions
582 ## and redefine them as necessary.
583 ## And, since we have those functions, simply use them for whatever
585 t1=ten10one1ten10one1
586 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
587 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
588 ) > /dev/null 2>&1; then
589 good_shell=1
590 else
591 unset good_shell
593 unset t1
595 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
597 config_exit() {
598 exit ${1}
601 # which(1) not standardized, command(1) -v may return non-executable: unroll!
602 acmd_test() { __acmd "${1}" 1 0 0; }
603 acmd_test_fail() { __acmd "${1}" 1 1 0; }
604 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
605 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
606 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
607 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
608 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
609 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
610 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
611 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
612 __acmd() {
613 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
615 if [ "${dotest}" -ne 0 ]; then
616 eval dotest=\$${varname}
617 if [ -n "${dotest}" ]; then
618 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
619 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
620 return 0
624 oifs=${IFS} IFS=:
625 [ -n "${noglob_shell}" ] && set -o noglob
626 set -- ${PATH}
627 [ -n "${noglob_shell}" ] && set +o noglob
628 IFS=${oifs}
629 for path
631 if [ -z "${path}" ] || [ "${path}" = . ]; then
632 if [ -d "${PWD}" ]; then
633 path=${PWD}
634 else
635 path=.
638 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
639 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
640 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
641 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
642 return 0
644 done
646 # We may have no builtin string functions, we yet have no programs we can
647 # use, try to access once from the root, assuming it is an absolute path if
648 # that finds the executable
649 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
650 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
651 msg ' . ${%s} ... %s' "${pname}" "${pname}"
652 [ -n "${varname}" ] && eval ${varname}="${pname}"
653 return 0
656 [ ${dofail} -eq 0 ] && return 1
657 msg 'ERROR: no trace of utility '"${pname}"
658 exit 1
661 msg() {
662 fmt=${1}
663 shift
664 printf >&2 -- "${fmt}\\n" "${@}"
667 msg_nonl() {
668 fmt=${1}
669 shift
670 printf >&2 -- "${fmt}" "${@}"
673 # Our feature check environment
674 feat_val_no() {
675 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
676 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
679 feat_val_yes() {
680 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
681 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
682 [ "x${1}" = xrequire ]
685 feat_val_require() {
686 [ "x${1}" = xrequire ]
689 _feat_check() {
690 eval i=\$OPT_${1}
691 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
692 if feat_val_no "${i}"; then
693 return 1
694 elif feat_val_yes "${i}"; then
695 return 0
696 else
697 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
698 "${1}" "${i}"
699 config_exit 11
703 feat_yes() {
704 _feat_check ${1}
707 feat_no() {
708 _feat_check ${1} && return 1
709 return 0
712 feat_require() {
713 eval i=\$OPT_${1}
714 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
715 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
718 feat_bail_required() {
719 if feat_require ${1}; then
720 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
721 config_exit 13
723 eval OPT_${1}=0
724 option_update # XXX this is rather useless here (dependency chain..)
727 option_parse() {
728 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
729 # options, without documentation, to $1
730 j=\'
731 i="`${awk} -v input=\"${2}\" '
732 BEGIN{
733 for(i = 0;;){
734 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
735 if(voff == 0)
736 break
737 v = substr(input, voff, RLENGTH)
738 input = substr(input, voff + RLENGTH)
739 doff = index(v, "=")
740 if(doff > 0){
741 d = substr(v, doff + 2, length(v) - doff - 1)
742 v = substr(v, 1, doff - 1)
744 print v
748 eval ${1}=\"${i}\"
751 option_doc_of() {
752 # Return the "documentation string" for option $1, itself if none such
753 j=\'
754 ${awk} -v want="${1}" \
755 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
756 BEGIN{
757 for(;;){
758 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
759 if(voff == 0)
760 break
761 v = substr(input, voff, RLENGTH)
762 input = substr(input, voff + RLENGTH)
763 doff = index(v, "=")
764 if(doff > 0){
765 d = substr(v, doff + 2, length(v) - doff - 1)
766 v = substr(v, 1, doff - 1)
767 }else
768 d = v
769 if(v == want){
770 if(d != "-")
771 print d
772 exit
779 option_join_rc() {
780 # Join the values from make.rc into what currently is defined, not
781 # overwriting yet existing settings
782 ${rm} -f ${tmp}
783 # We want read(1) to perform reverse solidus escaping in order to be able to
784 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
785 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
786 < ${rc} ${awk} 'BEGIN{line = ""}{
787 gsub(/^[[:space:]]+/, "", $0)
788 gsub(/[[:space:]]+$/, "", $0)
789 if(gsub(/\\$/, "", $0)){
790 line = line $0
791 next
792 }else
793 line = line $0
794 if(index(line, "#") == 1){
795 line = ""
796 }else if(length(line)){
797 print line
798 line = ""
800 }' |
801 while read line; do
802 if [ -n "${good_shell}" ]; then
803 i=${line%%=*}
804 else
805 i=`${awk} -v LINE="${line}" 'BEGIN{
806 gsub(/=.*$/, "", LINE)
807 print LINE
810 if [ "${i}" = "${line}" ]; then
811 msg 'ERROR: invalid syntax in: %s' "${line}"
812 continue
815 eval j="\$${i}" jx="\${${i}+x}"
816 if [ -n "${j}" ] || [ "${jx}" = x ]; then
817 : # Yet present
818 else
819 j=`${awk} -v LINE="${line}" 'BEGIN{
820 gsub(/^[^=]*=/, "", LINE)
821 gsub(/^\"*/, "", LINE)
822 gsub(/\"*$/, "", LINE)
823 print LINE
826 [ "${i}" = "DESTDIR" ] && continue
827 echo "${i}=\"${j}\""
828 done > ${tmp}
829 # Reread the mixed version right now
830 . ./${tmp}
833 option_evaluate() {
834 # Expand the option values, which may contain shell snippets
835 ${rm} -f ${newlst} ${newmk} ${newh}
836 exec 5<&0 6>&1 <${tmp} >${newlst}
837 while read line; do
839 if [ -n "${good_shell}" ]; then
840 i=${line%%=*}
841 [ "${i}" != "${i#OPT_}" ] && z=1
842 else
843 i=`${awk} -v LINE="${line}" 'BEGIN{
844 gsub(/=.*$/, "", LINE);\
845 print LINE
847 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
852 eval j=\$${i}
853 if [ -n "${z}" ]; then
854 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
855 if [ -z "${j}" ] || feat_val_no "${j}"; then
857 printf " /* #undef ${i} */\n" >> ${newh}
858 elif feat_val_yes "${j}"; then
859 if feat_val_require "${j}"; then
860 j=require
861 else
864 printf " /* #define ${i} */\n" >> ${newh}
865 else
866 msg 'ERROR: cannot parse <%s>' "${line}"
867 config_exit 1
869 else
870 printf "#define ${i} \"${j}\"\n" >> ${newh}
872 printf "${i} = ${j}\n" >> ${newmk}
873 printf "${i}=${j}\n"
874 eval "${i}=\"${j}\""
875 done
876 exec 0<&5 1>&6 5<&- 6<&-
879 path_check() {
880 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
881 varname=${1} addflag=${2} flagvarname=${3}
882 j=${IFS}
883 IFS=:
884 [ -n "${noglob_shell}" ] && set -o noglob
885 eval "set -- \$${1}"
886 [ -n "${noglob_shell}" ] && set +o noglob
887 IFS=${j}
888 j= k= y= z=
889 for i
891 [ -z "${i}" ] && continue
892 [ -d "${i}" ] || continue
893 if [ -n "${j}" ]; then
894 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
896 else
897 y="${y} :${i}:"
898 j="${j}:${i}"
899 # But do not link any fakeroot path into our binaries!
900 if [ -n "${addflag}" ]; then
901 case "${i}" in *fakeroot*) continue;; esac
902 k="${k} ${addflag}${i}"
905 else
906 y=" :${i}:"
907 j="${i}"
908 # But do not link any fakeroot path into our binaries!
909 if [ -n "${addflag}" ]; then
910 case "${i}" in *fakeroot*) continue;; esac
911 k="${k} ${addflag}${i}"
914 done
915 eval "${varname}=\"${j}\""
916 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
917 unset varname
920 ld_runtime_flags() {
921 if [ -n "${need_R_ldflags}" ]; then
922 i=${IFS}
923 IFS=:
924 set -- ${LD_LIBRARY_PATH}
925 IFS=${i}
926 for i
928 # But do not link any fakeroot path into our binaries!
929 case "${i}" in *fakeroot*) continue;; esac
930 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
931 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
932 done
933 export LDFLAGS
935 # Disable it for a possible second run.
936 need_R_ldflags=
939 cc_check() {
940 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
941 if "${CC}" ${INCS} \
942 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
943 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
944 _CFLAGS="${_CFLAGS} ${1}"
945 [ -n "${cc_check_silent}" ] || msg 'yes'
946 return 0
948 [ -n "${cc_check_silent}" ] || msg 'no'
949 return 1
952 ld_check() {
953 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
954 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
955 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
956 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
957 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
958 [ -n "${cc_check_silent}" ] || msg 'yes'
959 return 0
961 [ -n "${cc_check_silent}" ] || msg 'no'
962 return 1
965 dump_test_program=1
966 _check_preface() {
967 variable=$1 topic=$2 define=$3
969 echo '**********'
970 msg_nonl ' . %s ... ' "${topic}"
971 echo "/* checked ${topic} */" >> ${h}
972 ${rm} -f ${tmp} ${tmp}.o
973 if [ "${dump_test_program}" = 1 ]; then
974 echo '*** test program is'
975 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
976 else
977 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
979 #echo '*** the preprocessor generates'
980 #${make} -f ${makefile} ${tmp}.x
981 #${cat} ${tmp}.x
982 echo '*** tests results'
985 without_check() {
986 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
988 echo '**********'
989 msg_nonl ' . %s ... ' "${topic}"
991 echo '*** enforced unchecked results are'
992 if feat_val_yes ${yesno}; then
993 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
994 echo "*** adding INCS<${incs}> LIBS<${libs}>"
995 LIBS="${LIBS} ${libs}"
996 echo "${libs}" >> ${lib}
997 INCS="${INCS} ${incs}"
998 echo "${incs}" >> ${inc}
1000 msg 'yes (deduced)'
1001 echo "${define}" >> ${h}
1002 eval have_${variable}=yes
1003 return 0
1004 else
1005 echo "/* ${define} */" >> ${h}
1006 msg 'no (deduced)'
1007 eval unset have_${variable}
1008 return 1
1012 compile_check() {
1013 variable=$1 topic=$2 define=$3
1015 _check_preface "${variable}" "${topic}" "${define}"
1017 if ${make} -f ${makefile} XINCS="${INCS}" \
1018 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1019 ./${tmp}.o &&
1020 [ -f ./${tmp}.o ]; then
1021 msg 'yes'
1022 echo "${define}" >> ${h}
1023 eval have_${variable}=yes
1024 return 0
1025 else
1026 echo "/* ${define} */" >> ${h}
1027 msg 'no'
1028 eval unset have_${variable}
1029 return 1
1033 _link_mayrun() {
1034 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1036 _check_preface "${variable}" "${topic}" "${define}"
1038 if feat_yes CROSS_BUILD; then
1039 if [ ${run} = 1 ]; then
1040 run=0
1044 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1045 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1046 XLIBS="${LIBS} ${libs}" \
1047 ./${tmp} &&
1048 [ -f ./${tmp} ] &&
1049 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1050 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1051 msg 'yes'
1052 echo "${define}" >> ${h}
1053 LIBS="${LIBS} ${libs}"
1054 echo "${libs}" >> ${lib}
1055 INCS="${INCS} ${incs}"
1056 echo "${incs}" >> ${inc}
1057 eval have_${variable}=yes
1058 return 0
1059 else
1060 msg 'no'
1061 echo "/* ${define} */" >> ${h}
1062 eval unset have_${variable}
1063 return 1
1067 link_check() {
1068 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1071 run_check() {
1072 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1075 xrun_check() {
1076 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1079 feat_def() {
1080 if feat_yes ${1}; then
1081 echo '#define HAVE_'${1}'' >> ${h}
1082 return 0
1083 else
1084 echo '/* OPT_'${1}'=0 */' >> ${h}
1085 return 1
1089 squeeze_em() {
1090 < "${1}" > "${2}" ${awk} \
1091 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1094 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1096 # First of all, create new configuration and check whether it changed
1098 # Very easy checks for the operating system in order to be able to adjust paths
1099 # or similar very basic things which we need to be able to go at all
1100 os_early_setup
1102 # Check those tools right now that we need before including $rc
1103 msg 'Checking for basic utility set'
1104 thecmd_testandset_fail awk awk
1105 thecmd_testandset_fail rm rm
1106 thecmd_testandset_fail tr tr
1108 # Initialize the option set
1109 msg_nonl 'Setting up configuration options ... '
1110 option_setup
1111 msg 'done'
1113 # Include $rc, but only take from it what wasn't overwritten by the user from
1114 # within the command line or from a chosen fixed CONFIG=
1115 # Note we leave alone the values
1116 trap "exit 1" HUP INT TERM
1117 trap "${rm} -f ${tmp}" EXIT
1119 msg_nonl 'Joining in %s ... ' ${rc}
1120 option_join_rc
1121 msg 'done'
1123 # We need to know about that now, in order to provide utility overwrites etc.
1124 os_setup
1126 msg 'Checking for remaining set of utilities'
1127 thecmd_testandset_fail grep grep
1129 # Before we step ahead with the other utilities perform a path cleanup first.
1130 path_check PATH
1132 # awk(1) above
1133 thecmd_testandset_fail basename basename
1134 thecmd_testandset_fail cat cat
1135 thecmd_testandset_fail chmod chmod
1136 thecmd_testandset_fail cp cp
1137 thecmd_testandset_fail cmp cmp
1138 # grep(1) above
1139 thecmd_testandset_fail mkdir mkdir
1140 thecmd_testandset_fail mv mv
1141 # rm(1) above
1142 thecmd_testandset_fail sed sed
1143 thecmd_testandset_fail sort sort
1144 thecmd_testandset_fail tee tee
1145 __PATH=${PATH}
1146 thecmd_testandset chown chown ||
1147 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1148 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1149 PATH=${__PATH}
1150 thecmd_testandset_fail MAKE make
1151 make=${MAKE}
1152 export MAKE
1153 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1155 # For ./cc-test.sh only
1156 thecmd_testandset_fail cksum cksum
1158 # Update OPT_ options now, in order to get possible inter-dependencies right
1159 option_update
1161 # (No functions since some shells loose non-exported variables in traps)
1162 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1163 trap "trap \"\" HUP INT TERM EXIT;\
1164 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1166 # Our configuration options may at this point still contain shell snippets,
1167 # we need to evaluate them in order to get them expanded, and we need those
1168 # evaluated values not only in our new configuration file, but also at hand..
1169 msg_nonl 'Evaluating all configuration items ... '
1170 option_evaluate
1171 msg 'done'
1173 # Add the known utility and some other variables
1174 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1175 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1177 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1178 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1179 if feat_yes DOTLOCK; then
1180 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1181 else
1182 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1185 for i in \
1186 SRCDIR \
1187 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1188 MAKE MAKEFLAGS make SHELL strip \
1189 cksum; do
1190 eval j=\$${i}
1191 printf "${i} = ${j}\n" >> ${newmk}
1192 printf "${i}=${j}\n" >> ${newlst}
1193 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1194 done
1195 printf "\n" >> ${newev}
1197 # Build a basic set of INCS and LIBS according to user environment.
1198 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1199 path_check C_INCLUDE_PATH -I _INCS
1200 INCS="${INCS} ${_INCS}"
1201 path_check LD_LIBRARY_PATH -L _LIBS
1202 LIBS="${LIBS} ${_LIBS}"
1203 unset _INCS _LIBS
1204 export C_INCLUDE_PATH LD_LIBRARY_PATH
1206 # Some environments need runtime path flags to be able to go at all
1207 ld_runtime_flags
1209 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1211 cc_setup
1213 ${cat} > ${tmp}.c << \!
1214 #include <stdio.h>
1215 #include <string.h>
1216 static void doit(char const *s);
1218 main(int argc, char **argv){
1219 (void)argc;
1220 (void)argv;
1221 doit("Hello world");
1222 return 0;
1224 static void
1225 doit(char const *s){
1226 char buf[12];
1227 memcpy(buf, s, strlen(s) +1);
1228 puts(s);
1232 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1233 -o ${tmp2} ${tmp}.c ${LIBS}; then
1235 else
1236 msg 'ERROR: i cannot compile a "Hello world" via'
1237 msg ' %s' \
1238 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1239 msg 'ERROR: Please read INSTALL, rerun'
1240 config_exit 1
1243 # This may also update ld_runtime_flags() (again)
1244 cc_flags
1246 for i in \
1247 INCS LIBS \
1248 ; do
1249 eval j=\$${i}
1250 printf -- "${i}=${j}\n" >> ${newlst}
1251 done
1252 for i in \
1253 CC \
1254 CFLAGS \
1255 LDFLAGS \
1256 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1257 OSFULLSPEC \
1258 ; do
1259 eval j=\$${i}
1260 printf -- "${i} = ${j}\n" >> ${newmk}
1261 printf -- "${i}=${j}\n" >> ${newlst}
1262 done
1264 # Now finally check whether we already have a configuration and if so, whether
1265 # all those parameters are still the same.. or something has actually changed
1266 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1267 echo 'Configuration is up-to-date'
1268 exit 0
1269 elif [ -f ${lst} ]; then
1270 echo 'Configuration has been updated..'
1271 ( eval "${MAKE} -f ./mk-config.mk clean" )
1272 echo
1273 else
1274 echo 'Shiny configuration..'
1277 # Time to redefine helper 1
1278 config_exit() {
1279 ${rm} -f ${lst} ${h} ${mk}
1280 exit ${1}
1283 ${mv} -f ${newlst} ${lst}
1284 ${mv} -f ${newev} ${ev}
1285 ${mv} -f ${newh} ${h}
1286 ${mv} -f ${newmk} ${mk}
1288 if [ -z "${VERBOSE}" ]; then
1289 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1290 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1291 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1292 printf -- "ECHO_TEST = @\n" >> ${mk}
1293 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1294 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1295 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1298 ## Compile and link checking
1300 tmp3=./${tmp0}3$$
1301 log=./mk-config.log
1302 lib=./mk-config.lib
1303 inc=./mk-config.inc
1304 makefile=./${tmp0}.mk
1306 # (No function since some shells loose non-exported variables in traps)
1307 trap "trap \"\" HUP INT TERM;\
1308 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1309 trap "trap \"\" HUP INT TERM EXIT;\
1310 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1312 # Time to redefine helper 2
1313 msg() {
1314 fmt=${1}
1315 shift
1316 printf "*** ${fmt}\\n" "${@}"
1317 printf -- "${fmt}\\n" "${@}" >&5
1319 msg_nonl() {
1320 fmt=${1}
1321 shift
1322 printf "*** ${fmt}\\n" "${@}"
1323 printf -- "${fmt}" "${@}" >&5
1326 # !!
1327 exec 5>&2 > ${log} 2>&1
1329 echo "${LIBS}" > ${lib}
1330 echo "${INCS}" > ${inc}
1331 ${cat} > ${makefile} << \!
1332 .SUFFIXES: .o .c .x .y
1333 .c.o:
1334 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1335 .c.x:
1336 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1338 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1341 ## Generics
1343 # May be multiline..
1344 echo >> ${h}
1345 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1346 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1347 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1349 # Generate n_err_number OS mappings
1350 dump_test_program=0
1352 feat_yes DEVEL && NV= || NV=noverbose
1353 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1354 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1355 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1356 dump_test_program=1
1358 feat_def ALWAYS_UNICODE_LOCALE
1359 feat_def AMALGAMATION
1360 feat_def CROSS_BUILD
1361 feat_def DOCSTRINGS
1362 feat_def ERRORS
1364 feat_def ASAN_ADDRESS
1365 feat_def ASAN_MEMORY
1366 feat_def DEBUG
1367 feat_def DEVEL
1368 feat_def NYD2
1369 feat_def NOMEMDBG
1371 if xrun_check inline 'inline functions' \
1372 '#define HAVE_INLINE
1373 #define n_INLINE static inline' << \!
1374 static inline int ilf(int i){return ++i;}
1375 int main(void){return ilf(-1);}
1377 then
1379 elif xrun_check inline 'inline functions (via __inline)' \
1380 '#define HAVE_INLINE
1381 #define n_INLINE static __inline' << \!
1382 static __inline int ilf(int i){return ++i;}
1383 int main(void){return ilf(-1);}
1385 then
1389 ## Test for "basic" system-calls / functionality that is used by all parts
1390 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1391 ## macros to be used by only the subprograms (potentially).
1393 if run_check clock_gettime 'clock_gettime(2)' \
1394 '#define HAVE_CLOCK_GETTIME' << \!
1395 #include <time.h>
1396 # include <errno.h>
1397 int main(void){
1398 struct timespec ts;
1400 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1401 return 0;
1402 return 1;
1405 then
1407 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1408 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1409 #include <time.h>
1410 # include <errno.h>
1411 int main(void){
1412 struct timespec ts;
1414 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1415 return 0;
1416 return 1;
1419 then
1421 elif run_check gettimeofday 'gettimeofday(2)' \
1422 '#define HAVE_GETTIMEOFDAY' << \!
1423 #include <stdio.h> /* For C89 NULL */
1424 #include <sys/time.h>
1425 # include <errno.h>
1426 int main(void){
1427 struct timeval tv;
1429 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1430 return 0;
1431 return 1;
1434 then
1436 else
1437 have_no_subsecond_time=1
1440 if run_check nanosleep 'nanosleep(2)' \
1441 '#define HAVE_NANOSLEEP' << \!
1442 #include <time.h>
1443 # include <errno.h>
1444 int main(void){
1445 struct timespec ts;
1447 ts.tv_sec = 1;
1448 ts.tv_nsec = 100000;
1449 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1450 return 0;
1451 return 1;
1454 then
1456 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1457 '#define HAVE_NANOSLEEP' '-lrt' << \!
1458 #include <time.h>
1459 # include <errno.h>
1460 int main(void){
1461 struct timespec ts;
1463 ts.tv_sec = 1;
1464 ts.tv_nsec = 100000;
1465 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1466 return 0;
1467 return 1;
1470 then
1472 # link_check is enough for this, that function is so old, trust the proto
1473 elif link_check sleep 'sleep(3)' \
1474 '#define HAVE_SLEEP' << \!
1475 #include <unistd.h>
1476 # include <errno.h>
1477 int main(void){
1478 if(!sleep(1) || errno != ENOSYS)
1479 return 0;
1480 return 1;
1483 then
1485 else
1486 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1487 config_exit 1
1490 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1491 #include <pwd.h>
1492 #include <unistd.h>
1493 # include <errno.h>
1494 int main(void){
1495 struct passwd *pw;
1496 gid_t gid;
1497 uid_t uid;
1499 if((gid = getgid()) != 0)
1500 gid = getegid();
1501 if((uid = getuid()) != 0)
1502 uid = geteuid();
1503 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1504 return 1;
1505 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1506 return 1;
1507 return 0;
1510 then
1512 else
1513 msg 'ERROR: we require user and group info / database searches.'
1514 msg 'That much Unix we indulge ourselfs.'
1515 config_exit 1
1518 if link_check ftruncate 'ftruncate(2)' \
1519 '#define HAVE_FTRUNCATE' << \!
1520 #include <unistd.h>
1521 #include <sys/types.h>
1522 int main(void){
1523 return (ftruncate(0, 0) != 0);
1526 then
1528 else
1529 msg 'ERROR: we require the ftruncate(2) system call.'
1530 config_exit 1
1533 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1534 #include <signal.h>
1535 # include <errno.h>
1536 int main(void){
1537 struct sigaction nact, oact;
1539 nact.sa_handler = SIG_DFL;
1540 sigemptyset(&nact.sa_mask);
1541 nact.sa_flags = SA_RESTART;
1542 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1545 then
1547 else
1548 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1549 config_exit 1
1552 if link_check snprintf 'snprintf(3)' << \!
1553 #include <stdio.h>
1554 int main(void){
1555 char b[20];
1557 snprintf(b, sizeof b, "%s", "string");
1558 return 0;
1561 then
1563 else
1564 msg 'ERROR: we require the snprintf(3) function.'
1565 config_exit 1
1568 if link_check environ 'environ(3)' << \!
1569 #include <stdio.h> /* For C89 NULL */
1570 int main(void){
1571 extern char **environ;
1573 return environ[0] == NULL;
1576 then
1578 else
1579 msg 'ERROR: we require the environ(3) array for subprocess control.'
1580 config_exit 1
1583 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1584 #include <stdlib.h>
1585 int main(void){
1586 setenv("s-mailx", "i want to see it cute!", 1);
1587 unsetenv("s-mailx");
1588 return 0;
1591 then
1593 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1594 #include <stdlib.h>
1595 int main(void){
1596 putenv("s-mailx=i want to see it cute!");
1597 return 0;
1600 then
1602 else
1603 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1604 config_exit 1
1607 if link_check termios 'termios.h and tc*(3) family' << \!
1608 #include <termios.h>
1609 int main(void){
1610 struct termios tios;
1612 tcgetattr(0, &tios);
1613 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1614 return 0;
1617 then
1619 else
1620 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1621 msg 'That much Unix we indulge ourselfs.'
1622 config_exit 1
1625 ## optional stuff
1627 if link_check vsnprintf 'vsnprintf(3)' << \!
1628 #include <stdarg.h>
1629 #include <stdio.h>
1630 static void dome(char *buf, size_t blen, ...){
1631 va_list ap;
1633 va_start(ap, blen);
1634 vsnprintf(buf, blen, "%s", ap);
1635 va_end(ap);
1637 int main(void){
1638 char b[20];
1640 dome(b, sizeof b, "string");
1641 return 0;
1644 then
1646 else
1647 feat_bail_required ERRORS
1650 if [ "${have_vsnprintf}" = yes ]; then
1651 __va_copy() {
1652 link_check va_copy "va_copy(3) (as ${2})" \
1653 "#define HAVE_N_VA_COPY
1654 #define n_va_copy ${2}" <<_EOT
1655 #include <stdarg.h>
1656 #include <stdio.h>
1657 #if ${1}
1658 # if defined __va_copy && !defined va_copy
1659 # define va_copy __va_copy
1660 # endif
1661 #endif
1662 static void dome2(char *buf, size_t blen, va_list src){
1663 va_list ap;
1665 va_copy(ap, src);
1666 vsnprintf(buf, blen, "%s", ap);
1667 va_end(ap);
1669 static void dome(char *buf, size_t blen, ...){
1670 va_list ap;
1672 va_start(ap, blen);
1673 dome2(buf, blen, ap);
1674 va_end(ap);
1676 int main(void){
1677 char b[20];
1679 dome(b, sizeof b, "string");
1680 return 0;
1682 _EOT
1684 __va_copy 0 va_copy || __va_copy 1 __va_copy
1687 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1688 #include <unistd.h>
1689 #include <errno.h>
1690 int main(void){
1691 int rv = 0;
1693 errno = 0;
1694 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1695 errno = 0;
1696 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1698 /* Only link check */
1699 fpathconf(0, _PC_NAME_MAX);
1701 return rv;
1705 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1706 #include <fcntl.h>
1707 #include <unistd.h>
1708 # include <errno.h>
1709 int main(void){
1710 int fds[2];
1712 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1713 return 0;
1714 return 1;
1718 # We use this only then for now (need NOW+1)
1719 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1720 #include <fcntl.h> /* For AT_* */
1721 #include <sys/stat.h>
1722 # include <errno.h>
1723 int main(void){
1724 struct timespec ts[2];
1726 ts[0].tv_nsec = UTIME_NOW;
1727 ts[1].tv_nsec = UTIME_OMIT;
1728 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1729 return 0;
1730 return 1;
1736 # XXX Add POSIX check once standardized
1737 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1738 #include <stdlib.h>
1739 int main(void){
1740 arc4random();
1741 return 0;
1744 then
1746 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1747 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1748 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1749 #include <sys/random.h>
1750 int main(void){
1751 char buf[256];
1752 getrandom(buf, sizeof buf, 0);
1753 return 0;
1756 then
1758 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1759 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1760 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1761 #include <sys/syscall.h>
1762 int main(void){
1763 char buf[256];
1764 syscall(SYS_getrandom, buf, sizeof buf, 0);
1765 return 0;
1768 then
1770 elif [ -n "${have_no_subsecond_time}" ]; then
1771 msg 'ERROR: %s %s' 'without a native random' \
1772 'one of clock_gettime(2) and gettimeofday(2) is required.'
1773 config_exit 1
1777 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1778 #include <stdio.h>
1779 int main(void){
1780 putc_unlocked('@', stdout);
1781 return 0;
1785 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1786 #include <unistd.h>
1787 int main(void){
1788 fchdir(0);
1789 return 0;
1793 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1794 #include <stdlib.h>
1795 int main(void){
1796 char x_buf[4096], *x = realpath(".", x_buf);
1798 return (x != NULL) ? 0 : 1;
1801 then
1802 if run_check realpath_malloc 'realpath(3) takes NULL' \
1803 '#define HAVE_REALPATH_NULL' << \!
1804 #include <stdlib.h>
1805 int main(void){
1806 char *x = realpath(".", NULL);
1808 if(x != NULL)
1809 free(x);
1810 return (x != NULL) ? 0 : 1;
1813 then
1818 ## optional and selectable
1820 if feat_yes DOTLOCK; then
1821 if run_check readlink 'readlink(2)' << \!
1822 #include <unistd.h>
1823 # include <errno.h>
1824 int main(void){
1825 char buf[128];
1827 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1828 return 0;
1829 return 1;
1832 then
1834 else
1835 feat_bail_required DOTLOCK
1839 if feat_yes DOTLOCK; then
1840 if run_check fchown 'fchown(2)' << \!
1841 #include <unistd.h>
1842 # include <errno.h>
1843 int main(void){
1844 if(!fchown(0, 0, 0) || errno != ENOSYS)
1845 return 0;
1846 return 1;
1849 then
1851 else
1852 feat_bail_required DOTLOCK
1856 ## Now it is the time to fork away the BASE_ series
1858 ${rm} -f ${tmp}
1859 squeeze_em ${inc} ${tmp}
1860 ${mv} ${tmp} ${inc}
1861 squeeze_em ${lib} ${tmp}
1862 ${mv} ${tmp} ${lib}
1864 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1865 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1867 ## The remains are expected to be used only by the main MUA binary!
1869 OPT_LOCALES=0
1870 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1871 #include <locale.h>
1872 int main(void){
1873 setlocale(LC_ALL, "");
1874 return 0;
1877 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1879 OPT_MULTIBYTE_CHARSETS=0
1880 OPT_WIDE_GLYPHS=0
1881 OPT_TERMINAL_CHARSET=0
1882 if [ -n "${have_setlocale}" ]; then
1883 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1884 '#define HAVE_C90AMEND1' << \!
1885 #include <limits.h>
1886 #include <stdlib.h>
1887 #include <wchar.h>
1888 #include <wctype.h>
1889 int main(void){
1890 char mbb[MB_LEN_MAX + 1];
1891 wchar_t wc;
1893 iswprint(L'c');
1894 towupper(L'c');
1895 mbtowc(&wc, "x", 1);
1896 mbrtowc(&wc, "x", 1, NULL);
1897 wctomb(mbb, wc);
1898 return (mblen("\0", 1) == 0);
1901 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1903 if [ -n "${have_c90amend1}" ]; then
1904 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1905 #include <wchar.h>
1906 int main(void){
1907 wcwidth(L'c');
1908 return 0;
1911 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1914 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1915 #include <langinfo.h>
1916 #include <stdlib.h>
1917 int main(void){
1918 nl_langinfo(DAY_1);
1919 return (nl_langinfo(CODESET) == NULL);
1922 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1923 fi # have_setlocale
1925 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1926 #include <fnmatch.h>
1927 int main(void){
1928 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1932 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1933 #include <dirent.h>
1934 int main(void){
1935 struct dirent de;
1936 return !(de.d_type == DT_UNKNOWN ||
1937 de.d_type == DT_DIR || de.d_type == DT_LNK);
1941 ## optional and selectable
1943 if feat_yes ICONV; then
1944 ${cat} > ${tmp2}.c << \!
1945 #include <stdio.h> /* For C89 NULL */
1946 #include <iconv.h>
1947 int main(void){
1948 iconv_t id;
1950 id = iconv_open("foo", "bar");
1951 iconv(id, NULL, NULL, NULL, NULL);
1952 iconv_close(id);
1953 return 0;
1956 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1957 '#define HAVE_ICONV' ||
1958 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1959 '#define HAVE_ICONV' '-liconv' ||
1960 feat_bail_required ICONV
1961 else
1962 echo '/* OPT_ICONV=0 */' >> ${h}
1963 fi # feat_yes ICONV
1965 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1966 ${cat} > ${tmp2}.c << \!
1967 #include <sys/types.h>
1968 #include <sys/socket.h>
1969 #include <sys/un.h>
1970 # include <errno.h>
1971 int main(void){
1972 struct sockaddr_un soun;
1974 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1975 return 1;
1976 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1977 return 1;
1978 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1979 return 1;
1980 return 0;
1984 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1985 '#define HAVE_UNIX_SOCKETS' ||
1986 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1987 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1988 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1989 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1992 if feat_yes SOCKETS; then
1993 ${cat} > ${tmp2}.c << \!
1994 #include <sys/types.h>
1995 #include <sys/socket.h>
1996 #include <netinet/in.h>
1997 # include <errno.h>
1998 int main(void){
1999 struct sockaddr s;
2001 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2002 return 1;
2003 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2004 return 1;
2005 return 0;
2009 < ${tmp2}.c run_check sockets 'sockets' \
2010 '#define HAVE_SOCKETS' ||
2011 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2012 '#define HAVE_SOCKETS' '-lnsl' ||
2013 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2014 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2015 feat_bail_required SOCKETS
2016 else
2017 echo '/* OPT_SOCKETS=0 */' >> ${h}
2018 fi # feat_yes SOCKETS
2020 if feat_yes SOCKETS; then
2021 link_check getaddrinfo 'getaddrinfo(3)' \
2022 '#define HAVE_GETADDRINFO' << \!
2023 #include <sys/types.h>
2024 #include <sys/socket.h>
2025 #include <stdio.h>
2026 #include <netdb.h>
2027 int main(void){
2028 struct addrinfo a, *ap;
2029 int lrv;
2031 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2032 case EAI_NONAME:
2033 case EAI_SERVICE:
2034 default:
2035 fprintf(stderr, "%s\n", gai_strerror(lrv));
2036 case 0:
2037 break;
2039 return 0;
2044 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2045 compile_check arpa_inet_h '<arpa/inet.h>' \
2046 '#define HAVE_ARPA_INET_H' << \!
2047 #include <sys/types.h>
2048 #include <sys/socket.h>
2049 #include <netdb.h>
2050 #include <netinet/in.h>
2051 #include <arpa/inet.h>
2054 ${cat} > ${tmp2}.c << \!
2055 #include <sys/types.h>
2056 #include <sys/socket.h>
2057 #include <stdio.h>
2058 #include <string.h>
2059 #include <netdb.h>
2060 #include <netinet/in.h>
2061 #ifdef HAVE_ARPA_INET_H
2062 #include <arpa/inet.h>
2063 #endif
2064 int main(void){
2065 struct sockaddr_in servaddr;
2066 unsigned short portno;
2067 struct servent *ep;
2068 struct hostent *hp;
2069 struct in_addr **pptr;
2071 portno = 0;
2072 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2073 portno = (unsigned short)ep->s_port;
2075 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2076 pptr = (struct in_addr**)hp->h_addr_list;
2077 if(hp->h_addrtype != AF_INET)
2078 fprintf(stderr, "au\n");
2079 }else{
2080 switch(h_errno){
2081 case HOST_NOT_FOUND:
2082 case TRY_AGAIN:
2083 case NO_RECOVERY:
2084 case NO_DATA:
2085 break;
2086 default:
2087 fprintf(stderr, "au\n");
2088 break;
2092 memset(&servaddr, 0, sizeof servaddr);
2093 servaddr.sin_family = AF_INET;
2094 servaddr.sin_port = htons(portno);
2095 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2096 fprintf(stderr, "Would connect to %s:%d ...\n",
2097 inet_ntoa(**pptr), (int)portno);
2098 return 0;
2102 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2103 < ${tmp2}.c link_check gethostbyname \
2104 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2105 < ${tmp2}.c link_check gethostbyname \
2106 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2107 '' '-lsocket -lnsl' ||
2108 feat_bail_required SOCKETS
2111 feat_yes SOCKETS &&
2112 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2113 #include <sys/socket.h>
2114 #include <stdlib.h>
2115 # include <errno.h>
2116 int main(void){
2117 int sockfd = 3;
2119 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2120 errno == ENOSYS)
2121 return 1;
2122 return 0;
2126 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2127 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2128 #include <sys/socket.h>
2129 #include <stdlib.h>
2130 int main(void){
2131 struct timeval tv;
2132 int sockfd = 3;
2134 tv.tv_sec = 42;
2135 tv.tv_usec = 21;
2136 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2137 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2138 return 0;
2142 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2143 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2144 #include <sys/socket.h>
2145 #include <stdlib.h>
2146 int main(void){
2147 struct linger li;
2148 int sockfd = 3;
2150 li.l_onoff = 1;
2151 li.l_linger = 42;
2152 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2153 return 0;
2157 VAL_SSL_FEATURES=
2158 if feat_yes SSL; then # {{{
2159 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2160 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2161 # time: we need to test it first in order to get things right
2162 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2163 '#define HAVE_SSL
2164 #define HAVE_XSSL
2165 #define HAVE_XSSL_RESSL
2166 #define HAVE_XSSL_OPENSSL 0' << \!
2167 #include <openssl/opensslv.h>
2168 #ifdef LIBRESSL_VERSION_NUMBER
2169 #else
2170 # error nope
2171 #endif
2173 then
2174 ossl_v1_1=
2175 VAL_SSL_FEATURES=libressl
2176 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2177 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2178 '#define HAVE_SSL
2179 #define HAVE_XSSL
2180 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2181 #include <openssl/opensslv.h>
2182 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2183 #else
2184 # error nope
2185 #endif
2187 then
2188 ossl_v1_1=1
2189 VAL_SSL_FEATURES=libssl-0x10100
2190 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2191 '#define HAVE_SSL
2192 #define HAVE_XSSL
2193 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2194 #include <openssl/opensslv.h>
2195 #ifdef OPENSSL_VERSION_NUMBER
2196 #else
2197 # error nope
2198 #endif
2200 then
2201 ossl_v1_1=
2202 VAL_SSL_FEATURES=libssl-0x10000
2203 else
2204 feat_bail_required SSL
2205 fi # }}}
2207 if feat_yes SSL; then # {{{
2208 if [ -n "${ossl_v1_1}" ]; then
2209 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2210 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2211 '-lssl -lcrypto'
2212 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2213 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2214 '-lssl -lcrypto' << \!
2215 #include <openssl/ssl.h>
2216 #include <openssl/err.h>
2217 #include <openssl/x509v3.h>
2218 #include <openssl/x509.h>
2219 #include <openssl/rand.h>
2220 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2221 # error We need TLSv1.
2222 #endif
2223 int main(void){
2224 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2226 SSL_CTX_free(ctx);
2227 PEM_read_PrivateKey(0, 0, 0, 0);
2228 return 0;
2231 then
2233 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2234 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2235 '-lssl -lcrypto' << \!
2236 #include <openssl/ssl.h>
2237 #include <openssl/err.h>
2238 #include <openssl/x509v3.h>
2239 #include <openssl/x509.h>
2240 #include <openssl/rand.h>
2241 #if defined OPENSSL_NO_SSL3 &&\
2242 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2243 # error We need one of SSLv3 and TLSv1.
2244 #endif
2245 int main(void){
2246 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2248 SSL_CTX_free(ctx);
2249 PEM_read_PrivateKey(0, 0, 0, 0);
2250 return 0;
2253 then
2255 else
2256 feat_bail_required SSL
2258 fi # }}}
2260 if feat_yes SSL; then # {{{
2261 if feat_yes SSL_ALL_ALGORITHMS; then
2262 if [ -n "${ossl_v1_1}" ]; then
2263 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2264 '#define HAVE_SSL_ALL_ALGORITHMS'
2265 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2266 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2267 #include <openssl/evp.h>
2268 int main(void){
2269 OpenSSL_add_all_algorithms();
2270 EVP_get_cipherbyname("two cents i never exist");
2271 EVP_cleanup();
2272 return 0;
2275 then
2277 else
2278 feat_bail_required SSL_ALL_ALGORITHMS
2280 elif [ -n "${ossl_v1_1}" ]; then
2281 without_check yes ssl_all_algo \
2282 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2283 '#define HAVE_SSL_ALL_ALGORITHMS'
2286 if [ -n "${ossl_v1_1}" ]; then
2287 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2288 '#define HAVE_XSSL_STACK_OF'
2289 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2290 '#define HAVE_XSSL_STACK_OF' << \!
2291 #include <stdio.h> /* For C89 NULL */
2292 #include <openssl/ssl.h>
2293 #include <openssl/err.h>
2294 #include <openssl/x509v3.h>
2295 #include <openssl/x509.h>
2296 #include <openssl/rand.h>
2297 int main(void){
2298 STACK_OF(GENERAL_NAME) *gens = NULL;
2300 printf("%p", gens); /* to use it */
2301 return 0;
2304 then
2308 if [ -n "${ossl_v1_1}" ]; then
2309 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2310 '#define HAVE_XSSL_CONFIG'
2311 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2312 elif link_check xssl_conf \
2313 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2314 '#define HAVE_XSSL_CONFIG' << \!
2315 #include <stdio.h> /* For C89 NULL */
2316 #include <openssl/conf.h>
2317 int main(void){
2318 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2319 CONF_modules_free();
2320 return 0;
2323 then
2324 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2325 else
2326 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2329 if [ -n "${ossl_v1_1}" ]; then
2330 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2331 '#define HAVE_XSSL_CONF_CTX'
2332 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2333 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2334 '#define HAVE_XSSL_CONF_CTX' << \!
2335 #include <openssl/ssl.h>
2336 #include <openssl/err.h>
2337 int main(void){
2338 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2339 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2341 SSL_CONF_CTX_set_flags(cctx,
2342 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2343 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2344 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2345 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2346 SSL_CONF_CTX_finish(cctx);
2347 SSL_CONF_CTX_free(cctx);
2348 SSL_CTX_free(ctx);
2349 return 0;
2352 then
2353 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2354 else
2355 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2358 if [ -n "${ossl_v1_1}" ]; then
2359 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2360 '#define HAVE_XSSL_CTX_CONFIG'
2361 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2362 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2363 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2364 '#define HAVE_XSSL_CTX_CONFIG' << \!
2365 #include <stdio.h> /* For C89 NULL */
2366 #include <openssl/ssl.h>
2367 int main(void){
2368 SSL_CTX_config(NULL, "SOMEVAL");
2369 return 0;
2372 then
2373 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2374 else
2375 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2378 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2379 without_check yes xssl_set_maxmin_proto \
2380 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2381 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2382 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2383 elif link_check xssl_set_maxmin_proto \
2384 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2385 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2386 #include <stdio.h> /* For C89 NULL */
2387 #include <openssl/ssl.h>
2388 int main(void){
2389 SSL_CTX_set_min_proto_version(NULL, 0);
2390 SSL_CTX_set_max_proto_version(NULL, 10);
2391 return 0;
2394 then
2395 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2396 else
2397 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2400 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2401 '#define HAVE_XSSL_RAND_EGD' << \!
2402 #include <openssl/rand.h>
2403 int main(void){
2404 return RAND_egd("some.where") > 0;
2407 then
2408 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2409 else
2410 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2412 fi # feat_yes SSL }}}
2414 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2415 run_check ssl_md5 'MD5 digest in the used crypto library' \
2416 '#define HAVE_XSSL_MD5' << \!
2417 #include <stdlib.h>
2418 #include <string.h>
2419 #include <openssl/md5.h>
2420 int main(void){
2421 char const dat[] = "abrakadabrafidibus";
2422 char dig[16], hex[16 * 2];
2423 MD5_CTX ctx;
2424 size_t i, j;
2426 memset(dig, 0, sizeof(dig));
2427 memset(hex, 0, sizeof(hex));
2428 MD5_Init(&ctx);
2429 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2430 MD5_Final(dig, &ctx);
2432 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2433 for(i = 0; i < sizeof(hex) / 2; i++){
2434 j = i << 1;
2435 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2436 hex[++j] = hexchar(dig[i] & 0x0f);
2438 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2441 fi # }}}
2442 else
2443 echo '/* OPT_SSL=0 */' >> ${h}
2444 fi # }}} feat_yes SSL
2445 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2447 if [ "${have_xssl}" = yes ]; then
2448 OPT_SMIME=1
2449 else
2450 OPT_SMIME=0
2452 feat_def SMIME
2454 feat_def SMTP
2455 feat_def POP3
2456 feat_def IMAP
2458 if feat_yes GSSAPI; then
2459 ${cat} > ${tmp2}.c << \!
2460 #include <gssapi/gssapi.h>
2461 int main(void){
2462 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2463 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2464 return 0;
2467 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2469 if acmd_set i krb5-config; then
2470 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2471 GSS_INCS="`CFLAGS= ${i} --cflags`"
2472 i='GSS-API via krb5-config(1)'
2473 else
2474 GSS_LIBS='-lgssapi'
2475 GSS_INCS=
2476 i='GSS-API in gssapi/gssapi.h, libgssapi'
2478 if < ${tmp2}.c link_check gss \
2479 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2480 < ${tmp3}.c link_check gss \
2481 'GSS-API in gssapi.h, libgssapi' \
2482 '#define HAVE_GSSAPI
2483 #define GSSAPI_REG_INCLUDE' \
2484 '-lgssapi' ||\
2485 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2486 '#define HAVE_GSSAPI' \
2487 '-lgssapi_krb5' ||\
2488 < ${tmp3}.c link_check gss \
2489 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2490 '#define HAVE_GSSAPI
2491 #define GSS_REG_INCLUDE' \
2492 '-lgssapi -lkrb5 -lcrypto' \
2493 '-I/usr/include/kerberosV' ||\
2494 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2495 '#define HAVE_GSSAPI' \
2496 '-lgss' ||\
2497 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2498 '#define HAVE_GSSAPI
2499 #define GSSAPI_OLD_STYLE' \
2500 '-lgssapi_krb5' << \!
2501 #include <gssapi/gssapi.h>
2502 #include <gssapi/gssapi_generic.h>
2503 int main(void){
2504 gss_import_name(0, 0, gss_nt_service_name, 0);
2505 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2506 return 0;
2509 then
2511 else
2512 feat_bail_required GSSAPI
2514 else
2515 echo '/* OPT_GSSAPI=0 */' >> ${h}
2516 fi # feat_yes GSSAPI
2518 feat_def NETRC
2519 feat_def AGENT
2521 if feat_yes IDNA; then
2522 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2523 '-lidn' << \!
2524 #include <idna.h>
2525 #include <idn-free.h>
2526 #include <stringprep.h>
2527 int main(void){
2528 char *utf8, *idna_ascii, *idna_utf8;
2530 utf8 = stringprep_locale_to_utf8("does.this.work");
2531 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2532 != IDNA_SUCCESS)
2533 return 1;
2534 idn_free(idna_ascii);
2535 /* (Rather link check only here) */
2536 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2537 return 0;
2540 then
2542 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2543 '-lidnkit' << \!
2544 #include <stdio.h>
2545 #include <idn/api.h>
2546 #include <idn/result.h>
2547 int main(void){
2548 idn_result_t r;
2549 char ace_name[256];
2550 char local_name[256];
2552 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2553 sizeof(ace_name));
2554 if (r != idn_success) {
2555 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2556 return 1;
2558 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2559 if (r != idn_success) {
2560 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2561 return 1;
2563 return 0;
2566 then
2568 else
2569 feat_bail_required IDNA
2572 if [ -n "${have_idna}" ]; then
2573 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2574 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2576 else
2577 echo '/* OPT_IDNA=0 */' >> ${h}
2580 feat_def IMAP_SEARCH
2582 if feat_yes REGEX; then
2583 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2584 #include <regex.h>
2585 #include <stdlib.h>
2586 int main(void){
2587 size_t xret;
2588 int status;
2589 regex_t re;
2591 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2592 xret = regerror(status, &re, NULL, 0);
2593 status = regexec(&re, "plan9", 0,NULL, 0);
2594 regfree(&re);
2595 return !(status == REG_NOMATCH);
2598 then
2600 else
2601 feat_bail_required REGEX
2603 else
2604 echo '/* OPT_REGEX=0 */' >> ${h}
2607 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2608 have_mle=1
2609 echo '#define HAVE_MLE' >> ${h}
2610 else
2611 feat_bail_required MLE
2612 echo '/* OPT_MLE=0 */' >> ${h}
2615 # Generic have-a-line-editor switch for those who need it below
2616 if [ -n "${have_mle}" ]; then
2617 have_cle=1
2620 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2621 echo '#define HAVE_HISTORY' >> ${h}
2622 else
2623 echo '/* OPT_HISTORY=0 */' >> ${h}
2626 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2627 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2628 else
2629 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2632 if feat_yes TERMCAP; then
2633 __termcaplib() {
2634 link_check termcap "termcap(5) (via ${4})" \
2635 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2636 #include <stdio.h>
2637 #include <stdlib.h>
2638 ${2}
2639 #include <term.h>
2640 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2641 static int my_putc(int c){return putchar(c);}
2642 int main(void){
2643 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2644 int r2 = OK, r3 = ERR;
2646 tgetent(buf, getenv("TERM"));
2647 cpb = cmdbuf;
2648 r1 = tgetstr(UNCONST("cm"), &cpb);
2649 tgoto(r1, 1, 1);
2650 r2 = tgetnum(UNCONST("Co"));
2651 r3 = tgetflag(UNCONST("ut"));
2652 tputs("cr", 1, &my_putc);
2653 return (r1 == NULL || r2 == -1 || r3 == 0);
2655 _EOT
2658 __terminfolib() {
2659 link_check terminfo "terminfo(5) (via ${2})" \
2660 '#define HAVE_TERMCAP
2661 #define HAVE_TERMCAP_CURSES
2662 #define HAVE_TERMINFO' "${1}" << _EOT
2663 #include <stdio.h>
2664 #include <curses.h>
2665 #include <term.h>
2666 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2667 static int my_putc(int c){return putchar(c);}
2668 int main(void){
2669 int er, r0, r1, r2;
2670 char *r3, *tp;
2672 er = OK;
2673 r0 = setupterm(NULL, 1, &er);
2674 r1 = tigetflag(UNCONST("bce"));
2675 r2 = tigetnum(UNCONST("colors"));
2676 r3 = tigetstr(UNCONST("cr"));
2677 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2678 tputs(tp, 1, &my_putc);
2679 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2680 r3 == (char*)-1 || r3 == NULL);
2682 _EOT
2685 if feat_yes TERMCAP_VIA_TERMINFO; then
2686 __terminfolib -ltinfo -ltinfo ||
2687 __terminfolib -lcurses -lcurses ||
2688 __terminfolib -lcursesw -lcursesw ||
2689 feat_bail_required TERMCAP_VIA_TERMINFO
2692 if [ -z "${have_terminfo}" ]; then
2693 __termcaplib -ltermcap '' '' '-ltermcap' ||
2694 __termcaplib -ltermcap '#include <curses.h>' '
2695 #define HAVE_TERMCAP_CURSES' \
2696 'curses.h / -ltermcap' ||
2697 __termcaplib -lcurses '#include <curses.h>' '
2698 #define HAVE_TERMCAP_CURSES' \
2699 'curses.h / -lcurses' ||
2700 __termcaplib -lcursesw '#include <curses.h>' '
2701 #define HAVE_TERMCAP_CURSES' \
2702 'curses.h / -lcursesw' ||
2703 feat_bail_required TERMCAP
2705 if [ -n "${have_termcap}" ]; then
2706 run_check tgetent_null \
2707 "tgetent(3) of termcap(5) takes NULL buffer" \
2708 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2709 #include <stdio.h> /* For C89 NULL */
2710 #include <stdlib.h>
2711 #ifdef HAVE_TERMCAP_CURSES
2712 # include <curses.h>
2713 #endif
2714 #include <term.h>
2715 int main(void){
2716 tgetent(NULL, getenv("TERM"));
2717 return 0;
2719 _EOT
2722 else
2723 echo '/* OPT_TERMCAP=0 */' >> ${h}
2724 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2727 if feat_def SPAM_SPAMC; then
2728 if acmd_set i spamc; then
2729 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2733 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2734 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2735 else
2736 feat_bail_required SPAM_SPAMD
2737 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2740 feat_def SPAM_FILTER
2742 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2743 echo '#define HAVE_SPAM' >> ${h}
2744 else
2745 echo '/* HAVE_SPAM */' >> ${h}
2748 if feat_yes QUOTE_FOLD &&\
2749 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2750 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2751 else
2752 feat_bail_required QUOTE_FOLD
2753 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2756 feat_def FILTER_HTML_TAGSOUP
2757 feat_def COLOUR
2758 feat_def DOTLOCK
2759 feat_def MD5
2760 feat_def NOMEMDBG
2762 ## Summarizing
2764 ${rm} -f ${tmp}
2765 squeeze_em ${inc} ${tmp}
2766 ${mv} ${tmp} ${inc}
2767 squeeze_em ${lib} ${tmp}
2768 ${mv} ${tmp} ${lib}
2770 # mk-config.h
2771 ${mv} ${h} ${tmp}
2772 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2773 ${cat} ${tmp} >> ${h}
2774 ${rm} -f ${tmp}
2775 printf '\n' >> ${h}
2777 # Create the string that is used by *features* and `version'.
2778 # Take this nice opportunity and generate a visual listing of included and
2779 # non-included features for the person who runs the configuration
2780 msg '\nThe following features are included (+) or not (-):'
2781 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2782 printf '/* The "feature string" */\n' >> ${h}
2783 # Because + is expanded by *folder* if first in "echo $features", put something
2784 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2785 sep=
2786 for opt
2788 sdoc=`option_doc_of ${opt}`
2789 [ -z "${sdoc}" ] && continue
2790 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2791 feat_yes ${opt} && sign=+ || sign=-
2792 printf -- "${sep}${sign}${sopt}" >> ${h}
2793 sep=','
2794 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2795 done
2796 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2797 #exec 5>&1 >>${h}
2798 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2799 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2800 printf '"\n' >> ${h}
2802 # Create the real mk-config.mk
2803 # Note we cannout use explicit ./ filename prefix for source and object
2804 # pathnames because of a bug in bmake(1)
2805 ${rm} -rf ${tmp0}.* ${tmp0}*
2806 srclist= objlist=
2807 if feat_no AMALGAMATION; then
2808 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2809 i=`basename "${i}" .c`
2810 if [ "${i}" = privsep ]; then
2811 continue
2813 objlist="${objlist} ${i}.o"
2814 srclist="${srclist} \$(SRCDIR)${i}.c"
2815 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2816 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2817 done
2818 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2819 else
2820 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2821 "main.o" "main.c" >> ${mk}
2822 srclist=main.c objlist=main.o
2823 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2825 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2826 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2827 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2828 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2829 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2830 i=`basename "${i}"`
2831 if [ "${i}" = main.c ] ||
2832 [ "${i}" = privsep.c ]; then
2833 continue
2835 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2836 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
2837 done
2838 echo >> ${mk}
2840 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2842 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2844 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2845 echo "INCS = `${cat} ${inc}`" >> ${mk}
2846 echo >> ${mk}
2847 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2849 ## Finished!
2851 msg '\nSetup:'
2852 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2853 msg ' . bindir: %s' "${VAL_BINDIR}"
2854 if feat_yes DOTLOCK; then
2855 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2857 msg ' . mandir: %s' "${VAL_MANDIR}"
2858 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2859 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2860 msg ''
2862 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2863 exit 0
2865 msg 'Remarks:'
2866 if [ -z "${have_fnmatch}" ]; then
2867 msg ' . The function fnmatch(3) could not be found.'
2868 msg ' Filename patterns like wildcard are not supported on your system'
2870 if [ -z "${have_fchdir}" ]; then
2871 msg ' . The function fchdir(2) could not be found.'
2872 msg ' We will use chdir(2) instead.'
2873 msg ' This is a problem only if the current working directory is changed'
2874 msg ' while this program is inside of it'
2876 msg ''
2878 # s-it-mode