Even less shell globbing (Ivan Tham)
[s-mailx.git] / make-config.sh
blob93fd6e37b71a9bd67d6520d10f1dd3578945e6ea
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 ] && feat_yes USE_PKGSYS; then
304 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
305 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
306 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
310 _os_setup_sunos() {
311 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
312 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
314 # Include packages
315 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
316 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
317 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
318 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
320 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
321 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
322 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
323 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
326 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
327 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
329 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
330 if [ -x "${cksum}" ]; then :; else
331 msg 'ERROR: Not an executable program: %s' "${cksum}"
332 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
333 msg 'ERROR: However, we do so only for tests.'
334 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
335 config_exit 1
338 if feat_yes AUTOCC; then
339 if acmd_set CC cc; then
340 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
342 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
343 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
344 export CC CFLAGS LDFLAGS
345 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
346 else
347 cc_maxopt=2 #force_no_stackprot=1
352 # Check out compiler ($CC) and -flags ($CFLAGS)
353 cc_setup() {
354 # Even though it belongs into cc_flags we will try to compile and link
355 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
356 # EXTRA_CFLAGS/EXTRA_LDFLAGS
357 if feat_no AUTOCC; then
358 _cc_default
359 # Ensure those don't do any harm
360 EXTRA_CFLAGS= EXTRA_LDFLAGS=
361 export EXTRA_CFLAGS EXTRA_LDFLAGS
362 return
363 else
364 CFLAGS= LDFLAGS=
365 export CFLAGS LDFLAGS
368 [ -n "${CC}" ] && { _cc_default; return; }
370 msg_nonl 'Searching for a usable C compiler .. $CC='
371 if acmd_set CC clang || acmd_set CC gcc ||
372 acmd_set CC tcc || acmd_set CC pcc ||
373 acmd_set CC c89 || acmd_set CC c99; then
375 else
376 msg 'boing booom tschak'
377 msg 'ERROR: I cannot find a compiler!'
378 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
379 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
380 config_exit 1
382 msg '%s' "${CC}"
383 export CC
386 _cc_default() {
387 if [ -z "${CC}" ]; then
388 msg 'To go on like you have chosen, please set $CC, rerun.'
389 config_exit 1
392 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
394 else
395 msg 'Using C compiler ${CC}=%s' "${CC}"
399 cc_flags() {
400 if feat_yes AUTOCC; then
401 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
402 cc_check_silent=1
403 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
404 "${CC}"
405 else
406 cc_check_silent=
407 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
410 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
411 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
412 msg ' . have special tcc(1) environmental rules ...'
413 _cc_flags_tcc
414 else
415 # As of pcc CVS 2016-04-02, stack protection support is announced but
416 # will break if used on Linux
417 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
418 force_no_stackprot=1
420 _cc_flags_generic
423 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
424 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
425 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
426 else
427 if feat_no DEBUG; then
428 CFLAGS="-DNDEBUG ${CFLAGS}"
431 msg ''
432 export CFLAGS LDFLAGS
435 _cc_flags_tcc() {
436 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
437 _CFLAGS= _LDFLAGS=
439 cc_check -Wall
440 cc_check -Wextra
441 cc_check -pedantic
443 if feat_yes DEBUG; then
444 # May have problems to find libtcc cc_check -b
445 cc_check -g
448 if ld_check -Wl,-rpath =./ no; then
449 need_R_ldflags=-Wl,-rpath=
450 ld_check -Wl,--enable-new-dtags
451 ld_runtime_flags # update!
454 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
455 unset __cflags __ldflags
458 _cc_flags_generic() {
459 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
460 _CFLAGS= _LDFLAGS=
461 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
463 # E.g., valgrind does not work well with high optimization
464 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
465 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
466 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
467 cc_maxopt=1
469 # Check -g first since some others may rely upon -g / optim. level
470 if feat_yes DEBUG; then
471 cc_check -O
472 cc_check -g
473 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
475 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
477 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
479 else
480 cc_check -O
483 if feat_yes AMALGAMATION; then
484 cc_check -pipe
487 #if feat_yes DEVEL && cc_check -Weverything; then
489 #else
490 cc_check -Wall
491 cc_check -Wextra
492 cc_check -Wbad-function-cast
493 cc_check -Wcast-align
494 cc_check -Wcast-qual
495 cc_check -Winit-self
496 cc_check -Wmissing-prototypes
497 cc_check -Wshadow
498 cc_check -Wunused
499 cc_check -Wwrite-strings
500 cc_check -Wno-long-long
502 cc_check -pedantic
504 if feat_yes AMALGAMATION && feat_no DEVEL; then
505 cc_check -Wno-unused-function
507 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
509 cc_check -fno-unwind-tables
510 cc_check -fno-asynchronous-unwind-tables
511 cc_check -fstrict-aliasing
512 if cc_check -fstrict-overflow && feat_yes DEVEL; then
513 cc_check -Wstrict-overflow=5
516 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
517 if [ -z "${force_no_stackprot}" ]; then
518 if cc_check -fstack-protector-strong ||
519 cc_check -fstack-protector-all; then
520 cc_check -D_FORTIFY_SOURCE=2
522 else
523 msg 'Not checking for -fstack-protector compiler option,'
524 msg 'since that caused errors in a "similar" configuration.'
525 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
529 # LD (+ dependend CC)
531 if feat_yes ASAN_ADDRESS; then
532 _ccfg=${_CFLAGS}
533 if cc_check -fsanitize=address &&
534 ld_check -fsanitize=address; then
536 else
537 feat_bail_required ASAN_ADDRESS
538 _CFLAGS=${_ccfg}
542 if feat_yes ASAN_MEMORY; then
543 _ccfg=${_CFLAGS}
544 if cc_check -fsanitize=memory &&
545 ld_check -fsanitize=memory &&
546 cc_check -fsanitize-memory-track-origins=2 &&
547 ld_check -fsanitize-memory-track-origins=2; then
549 else
550 feat_bail_required ASAN_MEMORY
551 _CFLAGS=${_ccfg}
555 ld_check -Wl,-z,relro
556 ld_check -Wl,-z,now
557 ld_check -Wl,-z,noexecstack
558 if ld_check -Wl,-rpath =./ no; then
559 need_R_ldflags=-Wl,-rpath=
560 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
561 ld_check -Wl,--enable-new-dtags
562 ld_runtime_flags # update!
563 elif ld_check -Wl,-R ./ no; then
564 need_R_ldflags=-Wl,-R
565 ld_check -Wl,--enable-new-dtags
566 ld_runtime_flags # update!
569 # Address randomization
570 _ccfg=${_CFLAGS}
571 if cc_check -fPIE || cc_check -fpie; then
572 ld_check -pie || _CFLAGS=${_ccfg}
574 unset _ccfg
576 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
577 unset __cflags __ldflags
580 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
582 ## Notes:
583 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
584 ## redirection, so use "printf '' >" instead
586 ## Very first: we undergo several states regarding I/O redirection etc.,
587 ## but need to deal with option updates from within all. Since all the
588 ## option stuff should be above the scissor line, define utility functions
589 ## and redefine them as necessary.
590 ## And, since we have those functions, simply use them for whatever
592 t1=ten10one1ten10one1
593 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
594 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
595 ) > /dev/null 2>&1; then
596 good_shell=1
597 else
598 unset good_shell
600 unset t1
602 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
604 config_exit() {
605 exit ${1}
608 # which(1) not standardized, command(1) -v may return non-executable: unroll!
609 acmd_test() { __acmd "${1}" 1 0 0; }
610 acmd_test_fail() { __acmd "${1}" 1 1 0; }
611 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
612 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
613 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
614 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
615 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
616 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
617 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
618 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
619 __acmd() {
620 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
622 if [ "${dotest}" -ne 0 ]; then
623 eval dotest=\$${varname}
624 if [ -n "${dotest}" ]; then
625 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
626 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
627 return 0
631 oifs=${IFS} IFS=:
632 [ -n "${noglob_shell}" ] && set -o noglob
633 set -- ${PATH}
634 [ -n "${noglob_shell}" ] && set +o noglob
635 IFS=${oifs}
636 for path
638 if [ -z "${path}" ] || [ "${path}" = . ]; then
639 if [ -d "${PWD}" ]; then
640 path=${PWD}
641 else
642 path=.
645 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
646 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
647 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
648 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
649 return 0
651 done
653 # We may have no builtin string functions, we yet have no programs we can
654 # use, try to access once from the root, assuming it is an absolute path if
655 # that finds the executable
656 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
657 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
658 msg ' . ${%s} ... %s' "${pname}" "${pname}"
659 [ -n "${varname}" ] && eval ${varname}="${pname}"
660 return 0
663 [ ${dofail} -eq 0 ] && return 1
664 msg 'ERROR: no trace of utility '"${pname}"
665 exit 1
668 msg() {
669 fmt=${1}
670 shift
671 printf >&2 -- "${fmt}\\n" "${@}"
674 msg_nonl() {
675 fmt=${1}
676 shift
677 printf >&2 -- "${fmt}" "${@}"
680 # Our feature check environment
681 feat_val_no() {
682 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
683 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
686 feat_val_yes() {
687 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
688 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
689 [ "x${1}" = xrequire ]
692 feat_val_require() {
693 [ "x${1}" = xrequire ]
696 _feat_check() {
697 eval i=\$OPT_${1}
698 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
699 if feat_val_no "${i}"; then
700 return 1
701 elif feat_val_yes "${i}"; then
702 return 0
703 else
704 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
705 "${1}" "${i}"
706 config_exit 11
710 feat_yes() {
711 _feat_check ${1}
714 feat_no() {
715 _feat_check ${1} && return 1
716 return 0
719 feat_require() {
720 eval i=\$OPT_${1}
721 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
722 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
725 feat_bail_required() {
726 if feat_require ${1}; then
727 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
728 config_exit 13
730 eval OPT_${1}=0
731 option_update # XXX this is rather useless here (dependency chain..)
734 option_parse() {
735 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
736 # options, without documentation, to $1
737 j=\'
738 i="`${awk} -v input=\"${2}\" '
739 BEGIN{
740 for(i = 0;;){
741 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
742 if(voff == 0)
743 break
744 v = substr(input, voff, RLENGTH)
745 input = substr(input, voff + RLENGTH)
746 doff = index(v, "=")
747 if(doff > 0){
748 d = substr(v, doff + 2, length(v) - doff - 1)
749 v = substr(v, 1, doff - 1)
751 print v
755 eval ${1}=\"${i}\"
758 option_doc_of() {
759 # Return the "documentation string" for option $1, itself if none such
760 j=\'
761 ${awk} -v want="${1}" \
762 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
763 BEGIN{
764 for(;;){
765 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
766 if(voff == 0)
767 break
768 v = substr(input, voff, RLENGTH)
769 input = substr(input, voff + RLENGTH)
770 doff = index(v, "=")
771 if(doff > 0){
772 d = substr(v, doff + 2, length(v) - doff - 1)
773 v = substr(v, 1, doff - 1)
774 }else
775 d = v
776 if(v == want){
777 if(d != "-")
778 print d
779 exit
786 option_join_rc() {
787 # Join the values from make.rc into what currently is defined, not
788 # overwriting yet existing settings
789 ${rm} -f ${tmp}
790 # We want read(1) to perform reverse solidus escaping in order to be able to
791 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
792 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
793 < ${rc} ${awk} 'BEGIN{line = ""}{
794 gsub(/^[[:space:]]+/, "", $0)
795 gsub(/[[:space:]]+$/, "", $0)
796 if(gsub(/\\$/, "", $0)){
797 line = line $0
798 next
799 }else
800 line = line $0
801 if(index(line, "#") == 1){
802 line = ""
803 }else if(length(line)){
804 print line
805 line = ""
807 }' |
808 while read line; do
809 if [ -n "${good_shell}" ]; then
810 i=${line%%=*}
811 else
812 i=`${awk} -v LINE="${line}" 'BEGIN{
813 gsub(/=.*$/, "", LINE)
814 print LINE
817 if [ "${i}" = "${line}" ]; then
818 msg 'ERROR: invalid syntax in: %s' "${line}"
819 continue
822 eval j="\$${i}" jx="\${${i}+x}"
823 if [ -n "${j}" ] || [ "${jx}" = x ]; then
824 : # Yet present
825 else
826 j=`${awk} -v LINE="${line}" 'BEGIN{
827 gsub(/^[^=]*=/, "", LINE)
828 gsub(/^\"*/, "", LINE)
829 gsub(/\"*$/, "", LINE)
830 print LINE
833 [ "${i}" = "DESTDIR" ] && continue
834 echo "${i}=\"${j}\""
835 done > ${tmp}
836 # Reread the mixed version right now
837 . ./${tmp}
840 option_evaluate() {
841 # Expand the option values, which may contain shell snippets
842 ${rm} -f ${newlst} ${newmk} ${newh}
843 exec 5<&0 6>&1 <${tmp} >${newlst}
844 while read line; do
846 if [ -n "${good_shell}" ]; then
847 i=${line%%=*}
848 [ "${i}" != "${i#OPT_}" ] && z=1
849 else
850 i=`${awk} -v LINE="${line}" 'BEGIN{
851 gsub(/=.*$/, "", LINE);\
852 print LINE
854 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
859 eval j=\$${i}
860 if [ -n "${z}" ]; then
861 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
862 if [ -z "${j}" ] || feat_val_no "${j}"; then
864 printf " /* #undef ${i} */\n" >> ${newh}
865 elif feat_val_yes "${j}"; then
866 if feat_val_require "${j}"; then
867 j=require
868 else
871 printf " /* #define ${i} */\n" >> ${newh}
872 else
873 msg 'ERROR: cannot parse <%s>' "${line}"
874 config_exit 1
876 else
877 printf "#define ${i} \"${j}\"\n" >> ${newh}
879 printf "${i} = ${j}\n" >> ${newmk}
880 printf "${i}=${j}\n"
881 eval "${i}=\"${j}\""
882 done
883 exec 0<&5 1>&6 5<&- 6<&-
886 path_check() {
887 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
888 varname=${1} addflag=${2} flagvarname=${3}
889 j=${IFS}
890 IFS=:
891 [ -n "${noglob_shell}" ] && set -o noglob
892 eval "set -- \$${1}"
893 [ -n "${noglob_shell}" ] && set +o noglob
894 IFS=${j}
895 j= k= y= z=
896 for i
898 [ -z "${i}" ] && continue
899 [ -d "${i}" ] || continue
900 if [ -n "${j}" ]; then
901 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
903 else
904 y="${y} :${i}:"
905 j="${j}:${i}"
906 # But do not link any fakeroot path into our binaries!
907 if [ -n "${addflag}" ]; then
908 case "${i}" in *fakeroot*) continue;; esac
909 k="${k} ${addflag}${i}"
912 else
913 y=" :${i}:"
914 j="${i}"
915 # But do not link any fakeroot path into our binaries!
916 if [ -n "${addflag}" ]; then
917 case "${i}" in *fakeroot*) continue;; esac
918 k="${k} ${addflag}${i}"
921 done
922 eval "${varname}=\"${j}\""
923 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
924 unset varname
927 ld_runtime_flags() {
928 if [ -n "${need_R_ldflags}" ]; then
929 i=${IFS}
930 IFS=:
931 set -- ${LD_LIBRARY_PATH}
932 IFS=${i}
933 for i
935 # But do not link any fakeroot path into our binaries!
936 case "${i}" in *fakeroot*) continue;; esac
937 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
938 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
939 done
940 export LDFLAGS
942 # Disable it for a possible second run.
943 need_R_ldflags=
946 cc_check() {
947 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
948 if "${CC}" ${INCS} \
949 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
950 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
951 _CFLAGS="${_CFLAGS} ${1}"
952 [ -n "${cc_check_silent}" ] || msg 'yes'
953 return 0
955 [ -n "${cc_check_silent}" ] || msg 'no'
956 return 1
959 ld_check() {
960 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
961 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
962 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
963 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
964 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
965 [ -n "${cc_check_silent}" ] || msg 'yes'
966 return 0
968 [ -n "${cc_check_silent}" ] || msg 'no'
969 return 1
972 dump_test_program=1
973 _check_preface() {
974 variable=$1 topic=$2 define=$3
976 echo '**********'
977 msg_nonl ' . %s ... ' "${topic}"
978 echo "/* checked ${topic} */" >> ${h}
979 ${rm} -f ${tmp} ${tmp}.o
980 if [ "${dump_test_program}" = 1 ]; then
981 echo '*** test program is'
982 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
983 else
984 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
986 #echo '*** the preprocessor generates'
987 #${make} -f ${makefile} ${tmp}.x
988 #${cat} ${tmp}.x
989 echo '*** tests results'
992 without_check() {
993 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
995 echo '**********'
996 msg_nonl ' . %s ... ' "${topic}"
998 echo '*** enforced unchecked results are'
999 if feat_val_yes ${yesno}; then
1000 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1001 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1002 LIBS="${LIBS} ${libs}"
1003 echo "${libs}" >> ${lib}
1004 INCS="${INCS} ${incs}"
1005 echo "${incs}" >> ${inc}
1007 msg 'yes (deduced)'
1008 echo "${define}" >> ${h}
1009 eval have_${variable}=yes
1010 return 0
1011 else
1012 echo "/* ${define} */" >> ${h}
1013 msg 'no (deduced)'
1014 eval unset have_${variable}
1015 return 1
1019 compile_check() {
1020 variable=$1 topic=$2 define=$3
1022 _check_preface "${variable}" "${topic}" "${define}"
1024 if ${make} -f ${makefile} XINCS="${INCS}" \
1025 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1026 ./${tmp}.o &&
1027 [ -f ./${tmp}.o ]; then
1028 msg 'yes'
1029 echo "${define}" >> ${h}
1030 eval have_${variable}=yes
1031 return 0
1032 else
1033 echo "/* ${define} */" >> ${h}
1034 msg 'no'
1035 eval unset have_${variable}
1036 return 1
1040 _link_mayrun() {
1041 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1043 _check_preface "${variable}" "${topic}" "${define}"
1045 if feat_yes CROSS_BUILD; then
1046 if [ ${run} = 1 ]; then
1047 run=0
1051 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1052 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1053 XLIBS="${LIBS} ${libs}" \
1054 ./${tmp} &&
1055 [ -f ./${tmp} ] &&
1056 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1057 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1058 msg 'yes'
1059 echo "${define}" >> ${h}
1060 LIBS="${LIBS} ${libs}"
1061 echo "${libs}" >> ${lib}
1062 INCS="${INCS} ${incs}"
1063 echo "${incs}" >> ${inc}
1064 eval have_${variable}=yes
1065 return 0
1066 else
1067 msg 'no'
1068 echo "/* ${define} */" >> ${h}
1069 eval unset have_${variable}
1070 return 1
1074 link_check() {
1075 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1078 run_check() {
1079 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1082 xrun_check() {
1083 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1086 feat_def() {
1087 if feat_yes ${1}; then
1088 echo '#define HAVE_'${1}'' >> ${h}
1089 return 0
1090 else
1091 echo '/* OPT_'${1}'=0 */' >> ${h}
1092 return 1
1096 squeeze_em() {
1097 < "${1}" > "${2}" ${awk} \
1098 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1101 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1103 # First of all, create new configuration and check whether it changed
1105 # Very easy checks for the operating system in order to be able to adjust paths
1106 # or similar very basic things which we need to be able to go at all
1107 os_early_setup
1109 # Check those tools right now that we need before including $rc
1110 msg 'Checking for basic utility set'
1111 thecmd_testandset_fail awk awk
1112 thecmd_testandset_fail rm rm
1113 thecmd_testandset_fail tr tr
1115 # Initialize the option set
1116 msg_nonl 'Setting up configuration options ... '
1117 option_setup
1118 msg 'done'
1120 # Include $rc, but only take from it what wasn't overwritten by the user from
1121 # within the command line or from a chosen fixed CONFIG=
1122 # Note we leave alone the values
1123 trap "exit 1" HUP INT TERM
1124 trap "${rm} -f ${tmp}" EXIT
1126 msg_nonl 'Joining in %s ... ' ${rc}
1127 option_join_rc
1128 msg 'done'
1130 # We need to know about that now, in order to provide utility overwrites etc.
1131 os_setup
1133 msg 'Checking for remaining set of utilities'
1134 thecmd_testandset_fail grep grep
1136 # Before we step ahead with the other utilities perform a path cleanup first.
1137 path_check PATH
1139 # awk(1) above
1140 thecmd_testandset_fail basename basename
1141 thecmd_testandset_fail cat cat
1142 thecmd_testandset_fail chmod chmod
1143 thecmd_testandset_fail cp cp
1144 thecmd_testandset_fail cmp cmp
1145 # grep(1) above
1146 thecmd_testandset_fail mkdir mkdir
1147 thecmd_testandset_fail mv mv
1148 # rm(1) above
1149 thecmd_testandset_fail sed sed
1150 thecmd_testandset_fail sort sort
1151 thecmd_testandset_fail tee tee
1152 __PATH=${PATH}
1153 thecmd_testandset chown chown ||
1154 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1155 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1156 PATH=${__PATH}
1157 thecmd_testandset_fail MAKE make
1158 make=${MAKE}
1159 export MAKE
1160 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1162 # For ./cc-test.sh only
1163 thecmd_testandset_fail cksum cksum
1165 # Update OPT_ options now, in order to get possible inter-dependencies right
1166 option_update
1168 # (No functions since some shells loose non-exported variables in traps)
1169 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1170 trap "trap \"\" HUP INT TERM EXIT;\
1171 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1173 # Our configuration options may at this point still contain shell snippets,
1174 # we need to evaluate them in order to get them expanded, and we need those
1175 # evaluated values not only in our new configuration file, but also at hand..
1176 msg_nonl 'Evaluating all configuration items ... '
1177 option_evaluate
1178 msg 'done'
1180 # Add the known utility and some other variables
1181 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1182 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1184 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1185 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1186 if feat_yes DOTLOCK; then
1187 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1188 else
1189 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1192 for i in \
1193 SRCDIR \
1194 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1195 MAKE MAKEFLAGS make SHELL strip \
1196 cksum; do
1197 eval j=\$${i}
1198 printf "${i} = ${j}\n" >> ${newmk}
1199 printf "${i}=${j}\n" >> ${newlst}
1200 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1201 done
1202 printf "\n" >> ${newev}
1204 # Build a basic set of INCS and LIBS according to user environment.
1205 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1206 path_check C_INCLUDE_PATH -I _INCS
1207 INCS="${INCS} ${_INCS}"
1208 path_check LD_LIBRARY_PATH -L _LIBS
1209 LIBS="${LIBS} ${_LIBS}"
1210 unset _INCS _LIBS
1211 export C_INCLUDE_PATH LD_LIBRARY_PATH
1213 # Some environments need runtime path flags to be able to go at all
1214 ld_runtime_flags
1216 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1218 cc_setup
1220 ${cat} > ${tmp}.c << \!
1221 #include <stdio.h>
1222 #include <string.h>
1223 static void doit(char const *s);
1225 main(int argc, char **argv){
1226 (void)argc;
1227 (void)argv;
1228 doit("Hello world");
1229 return 0;
1231 static void
1232 doit(char const *s){
1233 char buf[12];
1234 memcpy(buf, s, strlen(s) +1);
1235 puts(s);
1239 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1240 -o ${tmp2} ${tmp}.c ${LIBS}; then
1242 else
1243 msg 'ERROR: i cannot compile a "Hello world" via'
1244 msg ' %s' \
1245 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1246 msg 'ERROR: Please read INSTALL, rerun'
1247 config_exit 1
1250 # This may also update ld_runtime_flags() (again)
1251 cc_flags
1253 for i in \
1254 INCS LIBS \
1255 ; do
1256 eval j=\$${i}
1257 printf -- "${i}=${j}\n" >> ${newlst}
1258 done
1259 for i in \
1260 CC \
1261 CFLAGS \
1262 LDFLAGS \
1263 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1264 OSFULLSPEC \
1265 ; do
1266 eval j=\$${i}
1267 printf -- "${i} = ${j}\n" >> ${newmk}
1268 printf -- "${i}=${j}\n" >> ${newlst}
1269 done
1271 # Now finally check whether we already have a configuration and if so, whether
1272 # all those parameters are still the same.. or something has actually changed
1273 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1274 echo 'Configuration is up-to-date'
1275 exit 0
1276 elif [ -f ${lst} ]; then
1277 echo 'Configuration has been updated..'
1278 ( eval "${MAKE} -f ./mk-config.mk clean" )
1279 echo
1280 else
1281 echo 'Shiny configuration..'
1284 # Time to redefine helper 1
1285 config_exit() {
1286 ${rm} -f ${lst} ${h} ${mk}
1287 exit ${1}
1290 ${mv} -f ${newlst} ${lst}
1291 ${mv} -f ${newev} ${ev}
1292 ${mv} -f ${newh} ${h}
1293 ${mv} -f ${newmk} ${mk}
1295 if [ -z "${VERBOSE}" ]; then
1296 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1297 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1298 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1299 printf -- "ECHO_TEST = @\n" >> ${mk}
1300 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1301 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1302 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1305 ## Compile and link checking
1307 tmp3=./${tmp0}3$$
1308 log=./mk-config.log
1309 lib=./mk-config.lib
1310 inc=./mk-config.inc
1311 makefile=./${tmp0}.mk
1313 # (No function since some shells loose non-exported variables in traps)
1314 trap "trap \"\" HUP INT TERM;\
1315 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1316 trap "trap \"\" HUP INT TERM EXIT;\
1317 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1319 # Time to redefine helper 2
1320 msg() {
1321 fmt=${1}
1322 shift
1323 printf "*** ${fmt}\\n" "${@}"
1324 printf -- "${fmt}\\n" "${@}" >&5
1326 msg_nonl() {
1327 fmt=${1}
1328 shift
1329 printf "*** ${fmt}\\n" "${@}"
1330 printf -- "${fmt}" "${@}" >&5
1333 # !!
1334 exec 5>&2 > ${log} 2>&1
1336 echo "${LIBS}" > ${lib}
1337 echo "${INCS}" > ${inc}
1338 ${cat} > ${makefile} << \!
1339 .SUFFIXES: .o .c .x .y
1340 .c.o:
1341 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1342 .c.x:
1343 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1345 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1348 ## Generics
1350 # May be multiline..
1351 echo >> ${h}
1352 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1353 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1354 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1356 # Generate n_err_number OS mappings
1357 dump_test_program=0
1359 feat_yes DEVEL && NV= || NV=noverbose
1360 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1361 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1362 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1363 dump_test_program=1
1365 feat_def ALWAYS_UNICODE_LOCALE
1366 feat_def AMALGAMATION
1367 feat_def CROSS_BUILD
1368 feat_def DOCSTRINGS
1369 feat_def ERRORS
1371 feat_def ASAN_ADDRESS
1372 feat_def ASAN_MEMORY
1373 feat_def DEBUG
1374 feat_def DEVEL
1375 feat_def NYD2
1376 feat_def NOMEMDBG
1378 if xrun_check inline 'inline functions' \
1379 '#define HAVE_INLINE
1380 #define n_INLINE static inline' << \!
1381 static inline int ilf(int i){return ++i;}
1382 int main(void){return ilf(-1);}
1384 then
1386 elif xrun_check inline 'inline functions (via __inline)' \
1387 '#define HAVE_INLINE
1388 #define n_INLINE static __inline' << \!
1389 static __inline int ilf(int i){return ++i;}
1390 int main(void){return ilf(-1);}
1392 then
1396 ## Test for "basic" system-calls / functionality that is used by all parts
1397 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1398 ## macros to be used by only the subprograms (potentially).
1400 if run_check clock_gettime 'clock_gettime(2)' \
1401 '#define HAVE_CLOCK_GETTIME' << \!
1402 #include <time.h>
1403 # include <errno.h>
1404 int main(void){
1405 struct timespec ts;
1407 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1408 return 0;
1409 return 1;
1412 then
1414 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1415 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1416 #include <time.h>
1417 # include <errno.h>
1418 int main(void){
1419 struct timespec ts;
1421 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1422 return 0;
1423 return 1;
1426 then
1428 elif run_check gettimeofday 'gettimeofday(2)' \
1429 '#define HAVE_GETTIMEOFDAY' << \!
1430 #include <stdio.h> /* For C89 NULL */
1431 #include <sys/time.h>
1432 # include <errno.h>
1433 int main(void){
1434 struct timeval tv;
1436 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1437 return 0;
1438 return 1;
1441 then
1443 else
1444 have_no_subsecond_time=1
1447 if run_check nanosleep 'nanosleep(2)' \
1448 '#define HAVE_NANOSLEEP' << \!
1449 #include <time.h>
1450 # include <errno.h>
1451 int main(void){
1452 struct timespec ts;
1454 ts.tv_sec = 1;
1455 ts.tv_nsec = 100000;
1456 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1457 return 0;
1458 return 1;
1461 then
1463 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1464 '#define HAVE_NANOSLEEP' '-lrt' << \!
1465 #include <time.h>
1466 # include <errno.h>
1467 int main(void){
1468 struct timespec ts;
1470 ts.tv_sec = 1;
1471 ts.tv_nsec = 100000;
1472 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1473 return 0;
1474 return 1;
1477 then
1479 # link_check is enough for this, that function is so old, trust the proto
1480 elif link_check sleep 'sleep(3)' \
1481 '#define HAVE_SLEEP' << \!
1482 #include <unistd.h>
1483 # include <errno.h>
1484 int main(void){
1485 if(!sleep(1) || errno != ENOSYS)
1486 return 0;
1487 return 1;
1490 then
1492 else
1493 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1494 config_exit 1
1497 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1498 #include <pwd.h>
1499 #include <unistd.h>
1500 # include <errno.h>
1501 int main(void){
1502 struct passwd *pw;
1503 gid_t gid;
1504 uid_t uid;
1506 if((gid = getgid()) != 0)
1507 gid = getegid();
1508 if((uid = getuid()) != 0)
1509 uid = geteuid();
1510 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1511 return 1;
1512 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1513 return 1;
1514 return 0;
1517 then
1519 else
1520 msg 'ERROR: we require user and group info / database searches.'
1521 msg 'That much Unix we indulge ourselfs.'
1522 config_exit 1
1525 if link_check ftruncate 'ftruncate(2)' \
1526 '#define HAVE_FTRUNCATE' << \!
1527 #include <unistd.h>
1528 #include <sys/types.h>
1529 int main(void){
1530 return (ftruncate(0, 0) != 0);
1533 then
1535 else
1536 msg 'ERROR: we require the ftruncate(2) system call.'
1537 config_exit 1
1540 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1541 #include <signal.h>
1542 # include <errno.h>
1543 int main(void){
1544 struct sigaction nact, oact;
1546 nact.sa_handler = SIG_DFL;
1547 sigemptyset(&nact.sa_mask);
1548 nact.sa_flags = SA_RESTART;
1549 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1552 then
1554 else
1555 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1556 config_exit 1
1559 if link_check snprintf 'snprintf(3)' << \!
1560 #include <stdio.h>
1561 int main(void){
1562 char b[20];
1564 snprintf(b, sizeof b, "%s", "string");
1565 return 0;
1568 then
1570 else
1571 msg 'ERROR: we require the snprintf(3) function.'
1572 config_exit 1
1575 if link_check environ 'environ(3)' << \!
1576 #include <stdio.h> /* For C89 NULL */
1577 int main(void){
1578 extern char **environ;
1580 return environ[0] == NULL;
1583 then
1585 else
1586 msg 'ERROR: we require the environ(3) array for subprocess control.'
1587 config_exit 1
1590 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1591 #include <stdlib.h>
1592 int main(void){
1593 setenv("s-mailx", "i want to see it cute!", 1);
1594 unsetenv("s-mailx");
1595 return 0;
1598 then
1600 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1601 #include <stdlib.h>
1602 int main(void){
1603 putenv("s-mailx=i want to see it cute!");
1604 return 0;
1607 then
1609 else
1610 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1611 config_exit 1
1614 if link_check termios 'termios.h and tc*(3) family' << \!
1615 #include <termios.h>
1616 int main(void){
1617 struct termios tios;
1619 tcgetattr(0, &tios);
1620 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1621 return 0;
1624 then
1626 else
1627 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1628 msg 'That much Unix we indulge ourselfs.'
1629 config_exit 1
1632 ## optional stuff
1634 if link_check vsnprintf 'vsnprintf(3)' << \!
1635 #include <stdarg.h>
1636 #include <stdio.h>
1637 static void dome(char *buf, size_t blen, ...){
1638 va_list ap;
1640 va_start(ap, blen);
1641 vsnprintf(buf, blen, "%s", ap);
1642 va_end(ap);
1644 int main(void){
1645 char b[20];
1647 dome(b, sizeof b, "string");
1648 return 0;
1651 then
1653 else
1654 feat_bail_required ERRORS
1657 if [ "${have_vsnprintf}" = yes ]; then
1658 __va_copy() {
1659 link_check va_copy "va_copy(3) (as ${2})" \
1660 "#define HAVE_N_VA_COPY
1661 #define n_va_copy ${2}" <<_EOT
1662 #include <stdarg.h>
1663 #include <stdio.h>
1664 #if ${1}
1665 # if defined __va_copy && !defined va_copy
1666 # define va_copy __va_copy
1667 # endif
1668 #endif
1669 static void dome2(char *buf, size_t blen, va_list src){
1670 va_list ap;
1672 va_copy(ap, src);
1673 vsnprintf(buf, blen, "%s", ap);
1674 va_end(ap);
1676 static void dome(char *buf, size_t blen, ...){
1677 va_list ap;
1679 va_start(ap, blen);
1680 dome2(buf, blen, ap);
1681 va_end(ap);
1683 int main(void){
1684 char b[20];
1686 dome(b, sizeof b, "string");
1687 return 0;
1689 _EOT
1691 __va_copy 0 va_copy || __va_copy 1 __va_copy
1694 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1695 #include <unistd.h>
1696 #include <errno.h>
1697 int main(void){
1698 int rv = 0;
1700 errno = 0;
1701 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1702 errno = 0;
1703 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1705 /* Only link check */
1706 fpathconf(0, _PC_NAME_MAX);
1708 return rv;
1712 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1713 #include <fcntl.h>
1714 #include <unistd.h>
1715 # include <errno.h>
1716 int main(void){
1717 int fds[2];
1719 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1720 return 0;
1721 return 1;
1725 # We use this only then for now (need NOW+1)
1726 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1727 #include <fcntl.h> /* For AT_* */
1728 #include <sys/stat.h>
1729 # include <errno.h>
1730 int main(void){
1731 struct timespec ts[2];
1733 ts[0].tv_nsec = UTIME_NOW;
1734 ts[1].tv_nsec = UTIME_OMIT;
1735 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1736 return 0;
1737 return 1;
1743 # XXX Add POSIX check once standardized
1744 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1745 #include <stdlib.h>
1746 int main(void){
1747 arc4random();
1748 return 0;
1751 then
1753 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1754 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1755 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1756 #include <sys/random.h>
1757 int main(void){
1758 char buf[256];
1759 getrandom(buf, sizeof buf, 0);
1760 return 0;
1763 then
1765 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1766 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1767 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1768 #include <sys/syscall.h>
1769 int main(void){
1770 char buf[256];
1771 syscall(SYS_getrandom, buf, sizeof buf, 0);
1772 return 0;
1775 then
1777 elif [ -n "${have_no_subsecond_time}" ]; then
1778 msg 'ERROR: %s %s' 'without a native random' \
1779 'one of clock_gettime(2) and gettimeofday(2) is required.'
1780 config_exit 1
1784 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1785 #include <stdio.h>
1786 int main(void){
1787 putc_unlocked('@', stdout);
1788 return 0;
1792 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1793 #include <unistd.h>
1794 int main(void){
1795 fchdir(0);
1796 return 0;
1800 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1801 #include <stdlib.h>
1802 int main(void){
1803 char x_buf[4096], *x = realpath(".", x_buf);
1805 return (x != NULL) ? 0 : 1;
1808 then
1809 if run_check realpath_malloc 'realpath(3) takes NULL' \
1810 '#define HAVE_REALPATH_NULL' << \!
1811 #include <stdlib.h>
1812 int main(void){
1813 char *x = realpath(".", NULL);
1815 if(x != NULL)
1816 free(x);
1817 return (x != NULL) ? 0 : 1;
1820 then
1825 ## optional and selectable
1827 if feat_yes DOTLOCK; then
1828 if run_check readlink 'readlink(2)' << \!
1829 #include <unistd.h>
1830 # include <errno.h>
1831 int main(void){
1832 char buf[128];
1834 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1835 return 0;
1836 return 1;
1839 then
1841 else
1842 feat_bail_required DOTLOCK
1846 if feat_yes DOTLOCK; then
1847 if run_check fchown 'fchown(2)' << \!
1848 #include <unistd.h>
1849 # include <errno.h>
1850 int main(void){
1851 if(!fchown(0, 0, 0) || errno != ENOSYS)
1852 return 0;
1853 return 1;
1856 then
1858 else
1859 feat_bail_required DOTLOCK
1863 ## Now it is the time to fork away the BASE_ series
1865 ${rm} -f ${tmp}
1866 squeeze_em ${inc} ${tmp}
1867 ${mv} ${tmp} ${inc}
1868 squeeze_em ${lib} ${tmp}
1869 ${mv} ${tmp} ${lib}
1871 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1872 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1874 ## The remains are expected to be used only by the main MUA binary!
1876 OPT_LOCALES=0
1877 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1878 #include <locale.h>
1879 int main(void){
1880 setlocale(LC_ALL, "");
1881 return 0;
1884 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1886 OPT_MULTIBYTE_CHARSETS=0
1887 OPT_WIDE_GLYPHS=0
1888 OPT_TERMINAL_CHARSET=0
1889 if [ -n "${have_setlocale}" ]; then
1890 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1891 '#define HAVE_C90AMEND1' << \!
1892 #include <limits.h>
1893 #include <stdlib.h>
1894 #include <wchar.h>
1895 #include <wctype.h>
1896 int main(void){
1897 char mbb[MB_LEN_MAX + 1];
1898 wchar_t wc;
1900 iswprint(L'c');
1901 towupper(L'c');
1902 mbtowc(&wc, "x", 1);
1903 mbrtowc(&wc, "x", 1, NULL);
1904 wctomb(mbb, wc);
1905 return (mblen("\0", 1) == 0);
1908 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1910 if [ -n "${have_c90amend1}" ]; then
1911 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1912 #include <wchar.h>
1913 int main(void){
1914 wcwidth(L'c');
1915 return 0;
1918 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1921 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1922 #include <langinfo.h>
1923 #include <stdlib.h>
1924 int main(void){
1925 nl_langinfo(DAY_1);
1926 return (nl_langinfo(CODESET) == NULL);
1929 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1930 fi # have_setlocale
1932 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1933 #include <fnmatch.h>
1934 int main(void){
1935 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1939 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1940 #include <dirent.h>
1941 int main(void){
1942 struct dirent de;
1943 return !(de.d_type == DT_UNKNOWN ||
1944 de.d_type == DT_DIR || de.d_type == DT_LNK);
1948 ## optional and selectable
1950 if feat_yes ICONV; then
1951 ${cat} > ${tmp2}.c << \!
1952 #include <stdio.h> /* For C89 NULL */
1953 #include <iconv.h>
1954 int main(void){
1955 iconv_t id;
1957 id = iconv_open("foo", "bar");
1958 iconv(id, NULL, NULL, NULL, NULL);
1959 iconv_close(id);
1960 return 0;
1963 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1964 '#define HAVE_ICONV' ||
1965 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1966 '#define HAVE_ICONV' '-liconv' ||
1967 feat_bail_required ICONV
1968 else
1969 echo '/* OPT_ICONV=0 */' >> ${h}
1970 fi # feat_yes ICONV
1972 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1973 ${cat} > ${tmp2}.c << \!
1974 #include <sys/types.h>
1975 #include <sys/socket.h>
1976 #include <sys/un.h>
1977 # include <errno.h>
1978 int main(void){
1979 struct sockaddr_un soun;
1981 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1982 return 1;
1983 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1984 return 1;
1985 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1986 return 1;
1987 return 0;
1991 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1992 '#define HAVE_UNIX_SOCKETS' ||
1993 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1994 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1995 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1996 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1999 if feat_yes SOCKETS; then
2000 ${cat} > ${tmp2}.c << \!
2001 #include <sys/types.h>
2002 #include <sys/socket.h>
2003 #include <netinet/in.h>
2004 # include <errno.h>
2005 int main(void){
2006 struct sockaddr s;
2008 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2009 return 1;
2010 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2011 return 1;
2012 return 0;
2016 < ${tmp2}.c run_check sockets 'sockets' \
2017 '#define HAVE_SOCKETS' ||
2018 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2019 '#define HAVE_SOCKETS' '-lnsl' ||
2020 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2021 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2022 feat_bail_required SOCKETS
2023 else
2024 echo '/* OPT_SOCKETS=0 */' >> ${h}
2025 fi # feat_yes SOCKETS
2027 if feat_yes SOCKETS; then
2028 link_check getaddrinfo 'getaddrinfo(3)' \
2029 '#define HAVE_GETADDRINFO' << \!
2030 #include <sys/types.h>
2031 #include <sys/socket.h>
2032 #include <stdio.h>
2033 #include <netdb.h>
2034 int main(void){
2035 struct addrinfo a, *ap;
2036 int lrv;
2038 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2039 case EAI_NONAME:
2040 case EAI_SERVICE:
2041 default:
2042 fprintf(stderr, "%s\n", gai_strerror(lrv));
2043 case 0:
2044 break;
2046 return 0;
2051 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2052 compile_check arpa_inet_h '<arpa/inet.h>' \
2053 '#define HAVE_ARPA_INET_H' << \!
2054 #include <sys/types.h>
2055 #include <sys/socket.h>
2056 #include <netdb.h>
2057 #include <netinet/in.h>
2058 #include <arpa/inet.h>
2061 ${cat} > ${tmp2}.c << \!
2062 #include <sys/types.h>
2063 #include <sys/socket.h>
2064 #include <stdio.h>
2065 #include <string.h>
2066 #include <netdb.h>
2067 #include <netinet/in.h>
2068 #ifdef HAVE_ARPA_INET_H
2069 #include <arpa/inet.h>
2070 #endif
2071 int main(void){
2072 struct sockaddr_in servaddr;
2073 unsigned short portno;
2074 struct servent *ep;
2075 struct hostent *hp;
2076 struct in_addr **pptr;
2078 portno = 0;
2079 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2080 portno = (unsigned short)ep->s_port;
2082 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2083 pptr = (struct in_addr**)hp->h_addr_list;
2084 if(hp->h_addrtype != AF_INET)
2085 fprintf(stderr, "au\n");
2086 }else{
2087 switch(h_errno){
2088 case HOST_NOT_FOUND:
2089 case TRY_AGAIN:
2090 case NO_RECOVERY:
2091 case NO_DATA:
2092 break;
2093 default:
2094 fprintf(stderr, "au\n");
2095 break;
2099 memset(&servaddr, 0, sizeof servaddr);
2100 servaddr.sin_family = AF_INET;
2101 servaddr.sin_port = htons(portno);
2102 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2103 fprintf(stderr, "Would connect to %s:%d ...\n",
2104 inet_ntoa(**pptr), (int)portno);
2105 return 0;
2109 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2110 < ${tmp2}.c link_check gethostbyname \
2111 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2112 < ${tmp2}.c link_check gethostbyname \
2113 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2114 '' '-lsocket -lnsl' ||
2115 feat_bail_required SOCKETS
2118 feat_yes SOCKETS &&
2119 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2120 #include <sys/socket.h>
2121 #include <stdlib.h>
2122 # include <errno.h>
2123 int main(void){
2124 int sockfd = 3;
2126 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2127 errno == ENOSYS)
2128 return 1;
2129 return 0;
2133 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2134 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2135 #include <sys/socket.h>
2136 #include <stdlib.h>
2137 int main(void){
2138 struct timeval tv;
2139 int sockfd = 3;
2141 tv.tv_sec = 42;
2142 tv.tv_usec = 21;
2143 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2144 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2145 return 0;
2149 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2150 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2151 #include <sys/socket.h>
2152 #include <stdlib.h>
2153 int main(void){
2154 struct linger li;
2155 int sockfd = 3;
2157 li.l_onoff = 1;
2158 li.l_linger = 42;
2159 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2160 return 0;
2164 VAL_SSL_FEATURES=
2165 if feat_yes SSL; then # {{{
2166 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2167 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2168 # time: we need to test it first in order to get things right
2169 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2170 '#define HAVE_SSL
2171 #define HAVE_XSSL
2172 #define HAVE_XSSL_RESSL
2173 #define HAVE_XSSL_OPENSSL 0' << \!
2174 #include <openssl/opensslv.h>
2175 #ifdef LIBRESSL_VERSION_NUMBER
2176 #else
2177 # error nope
2178 #endif
2180 then
2181 ossl_v1_1=
2182 VAL_SSL_FEATURES=libressl
2183 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2184 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2185 '#define HAVE_SSL
2186 #define HAVE_XSSL
2187 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2188 #include <openssl/opensslv.h>
2189 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2190 #else
2191 # error nope
2192 #endif
2194 then
2195 ossl_v1_1=1
2196 VAL_SSL_FEATURES=libssl-0x10100
2197 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2198 '#define HAVE_SSL
2199 #define HAVE_XSSL
2200 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2201 #include <openssl/opensslv.h>
2202 #ifdef OPENSSL_VERSION_NUMBER
2203 #else
2204 # error nope
2205 #endif
2207 then
2208 ossl_v1_1=
2209 VAL_SSL_FEATURES=libssl-0x10000
2210 else
2211 feat_bail_required SSL
2212 fi # }}}
2214 if feat_yes SSL; then # {{{
2215 if [ -n "${ossl_v1_1}" ]; then
2216 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2217 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2218 '-lssl -lcrypto'
2219 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2220 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2221 '-lssl -lcrypto' << \!
2222 #include <openssl/ssl.h>
2223 #include <openssl/err.h>
2224 #include <openssl/x509v3.h>
2225 #include <openssl/x509.h>
2226 #include <openssl/rand.h>
2227 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2228 # error We need TLSv1.
2229 #endif
2230 int main(void){
2231 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2233 SSL_CTX_free(ctx);
2234 PEM_read_PrivateKey(0, 0, 0, 0);
2235 return 0;
2238 then
2240 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2241 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2242 '-lssl -lcrypto' << \!
2243 #include <openssl/ssl.h>
2244 #include <openssl/err.h>
2245 #include <openssl/x509v3.h>
2246 #include <openssl/x509.h>
2247 #include <openssl/rand.h>
2248 #if defined OPENSSL_NO_SSL3 &&\
2249 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2250 # error We need one of SSLv3 and TLSv1.
2251 #endif
2252 int main(void){
2253 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2255 SSL_CTX_free(ctx);
2256 PEM_read_PrivateKey(0, 0, 0, 0);
2257 return 0;
2260 then
2262 else
2263 feat_bail_required SSL
2265 fi # }}}
2267 if feat_yes SSL; then # {{{
2268 if feat_yes SSL_ALL_ALGORITHMS; then
2269 if [ -n "${ossl_v1_1}" ]; then
2270 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2271 '#define HAVE_SSL_ALL_ALGORITHMS'
2272 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2273 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2274 #include <openssl/evp.h>
2275 int main(void){
2276 OpenSSL_add_all_algorithms();
2277 EVP_get_cipherbyname("two cents i never exist");
2278 EVP_cleanup();
2279 return 0;
2282 then
2284 else
2285 feat_bail_required SSL_ALL_ALGORITHMS
2287 elif [ -n "${ossl_v1_1}" ]; then
2288 without_check yes ssl_all_algo \
2289 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2290 '#define HAVE_SSL_ALL_ALGORITHMS'
2293 if [ -n "${ossl_v1_1}" ]; then
2294 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2295 '#define HAVE_XSSL_STACK_OF'
2296 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2297 '#define HAVE_XSSL_STACK_OF' << \!
2298 #include <stdio.h> /* For C89 NULL */
2299 #include <openssl/ssl.h>
2300 #include <openssl/err.h>
2301 #include <openssl/x509v3.h>
2302 #include <openssl/x509.h>
2303 #include <openssl/rand.h>
2304 int main(void){
2305 STACK_OF(GENERAL_NAME) *gens = NULL;
2307 printf("%p", gens); /* to use it */
2308 return 0;
2311 then
2315 if [ -n "${ossl_v1_1}" ]; then
2316 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2317 '#define HAVE_XSSL_CONFIG'
2318 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2319 elif link_check xssl_conf \
2320 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2321 '#define HAVE_XSSL_CONFIG' << \!
2322 #include <stdio.h> /* For C89 NULL */
2323 #include <openssl/conf.h>
2324 int main(void){
2325 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2326 CONF_modules_free();
2327 return 0;
2330 then
2331 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2332 else
2333 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2336 if [ -n "${ossl_v1_1}" ]; then
2337 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2338 '#define HAVE_XSSL_CONF_CTX'
2339 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2340 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2341 '#define HAVE_XSSL_CONF_CTX' << \!
2342 #include <openssl/ssl.h>
2343 #include <openssl/err.h>
2344 int main(void){
2345 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2346 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2348 SSL_CONF_CTX_set_flags(cctx,
2349 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2350 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2351 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2352 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2353 SSL_CONF_CTX_finish(cctx);
2354 SSL_CONF_CTX_free(cctx);
2355 SSL_CTX_free(ctx);
2356 return 0;
2359 then
2360 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2361 else
2362 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2365 if [ -n "${ossl_v1_1}" ]; then
2366 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2367 '#define HAVE_XSSL_CTX_CONFIG'
2368 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2369 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2370 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2371 '#define HAVE_XSSL_CTX_CONFIG' << \!
2372 #include <stdio.h> /* For C89 NULL */
2373 #include <openssl/ssl.h>
2374 int main(void){
2375 SSL_CTX_config(NULL, "SOMEVAL");
2376 return 0;
2379 then
2380 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2381 else
2382 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2385 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2386 without_check yes xssl_set_maxmin_proto \
2387 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2388 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2389 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2390 elif link_check xssl_set_maxmin_proto \
2391 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2392 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2393 #include <stdio.h> /* For C89 NULL */
2394 #include <openssl/ssl.h>
2395 int main(void){
2396 SSL_CTX_set_min_proto_version(NULL, 0);
2397 SSL_CTX_set_max_proto_version(NULL, 10);
2398 return 0;
2401 then
2402 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2403 else
2404 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2407 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2408 '#define HAVE_XSSL_RAND_EGD' << \!
2409 #include <openssl/rand.h>
2410 int main(void){
2411 return RAND_egd("some.where") > 0;
2414 then
2415 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2416 else
2417 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2419 fi # feat_yes SSL }}}
2421 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2422 run_check ssl_md5 'MD5 digest in the used crypto library' \
2423 '#define HAVE_XSSL_MD5' << \!
2424 #include <stdlib.h>
2425 #include <string.h>
2426 #include <openssl/md5.h>
2427 int main(void){
2428 char const dat[] = "abrakadabrafidibus";
2429 char dig[16], hex[16 * 2];
2430 MD5_CTX ctx;
2431 size_t i, j;
2433 memset(dig, 0, sizeof(dig));
2434 memset(hex, 0, sizeof(hex));
2435 MD5_Init(&ctx);
2436 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2437 MD5_Final(dig, &ctx);
2439 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2440 for(i = 0; i < sizeof(hex) / 2; i++){
2441 j = i << 1;
2442 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2443 hex[++j] = hexchar(dig[i] & 0x0f);
2445 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2448 fi # }}}
2449 else
2450 echo '/* OPT_SSL=0 */' >> ${h}
2451 fi # }}} feat_yes SSL
2452 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2454 if [ "${have_xssl}" = yes ]; then
2455 OPT_SMIME=1
2456 else
2457 OPT_SMIME=0
2459 feat_def SMIME
2461 feat_def SMTP
2462 feat_def POP3
2463 feat_def IMAP
2465 if feat_yes GSSAPI; then
2466 ${cat} > ${tmp2}.c << \!
2467 #include <gssapi/gssapi.h>
2468 int main(void){
2469 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2470 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2471 return 0;
2474 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2476 if acmd_set i krb5-config; then
2477 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2478 GSS_INCS="`CFLAGS= ${i} --cflags`"
2479 i='GSS-API via krb5-config(1)'
2480 else
2481 GSS_LIBS='-lgssapi'
2482 GSS_INCS=
2483 i='GSS-API in gssapi/gssapi.h, libgssapi'
2485 if < ${tmp2}.c link_check gss \
2486 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2487 < ${tmp3}.c link_check gss \
2488 'GSS-API in gssapi.h, libgssapi' \
2489 '#define HAVE_GSSAPI
2490 #define GSSAPI_REG_INCLUDE' \
2491 '-lgssapi' ||\
2492 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2493 '#define HAVE_GSSAPI' \
2494 '-lgssapi_krb5' ||\
2495 < ${tmp3}.c link_check gss \
2496 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2497 '#define HAVE_GSSAPI
2498 #define GSS_REG_INCLUDE' \
2499 '-lgssapi -lkrb5 -lcrypto' \
2500 '-I/usr/include/kerberosV' ||\
2501 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2502 '#define HAVE_GSSAPI' \
2503 '-lgss' ||\
2504 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2505 '#define HAVE_GSSAPI
2506 #define GSSAPI_OLD_STYLE' \
2507 '-lgssapi_krb5' << \!
2508 #include <gssapi/gssapi.h>
2509 #include <gssapi/gssapi_generic.h>
2510 int main(void){
2511 gss_import_name(0, 0, gss_nt_service_name, 0);
2512 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2513 return 0;
2516 then
2518 else
2519 feat_bail_required GSSAPI
2521 else
2522 echo '/* OPT_GSSAPI=0 */' >> ${h}
2523 fi # feat_yes GSSAPI
2525 feat_def NETRC
2526 feat_def AGENT
2528 if feat_yes IDNA; then
2529 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2530 '-lidn' << \!
2531 #include <idna.h>
2532 #include <idn-free.h>
2533 #include <stringprep.h>
2534 int main(void){
2535 char *utf8, *idna_ascii, *idna_utf8;
2537 utf8 = stringprep_locale_to_utf8("does.this.work");
2538 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2539 != IDNA_SUCCESS)
2540 return 1;
2541 idn_free(idna_ascii);
2542 /* (Rather link check only here) */
2543 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2544 return 0;
2547 then
2549 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2550 '-lidnkit' << \!
2551 #include <stdio.h>
2552 #include <idn/api.h>
2553 #include <idn/result.h>
2554 int main(void){
2555 idn_result_t r;
2556 char ace_name[256];
2557 char local_name[256];
2559 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2560 sizeof(ace_name));
2561 if (r != idn_success) {
2562 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2563 return 1;
2565 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2566 if (r != idn_success) {
2567 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2568 return 1;
2570 return 0;
2573 then
2575 else
2576 feat_bail_required IDNA
2579 if [ -n "${have_idna}" ]; then
2580 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2581 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2583 else
2584 echo '/* OPT_IDNA=0 */' >> ${h}
2587 feat_def IMAP_SEARCH
2589 if feat_yes REGEX; then
2590 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2591 #include <regex.h>
2592 #include <stdlib.h>
2593 int main(void){
2594 size_t xret;
2595 int status;
2596 regex_t re;
2598 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2599 xret = regerror(status, &re, NULL, 0);
2600 status = regexec(&re, "plan9", 0,NULL, 0);
2601 regfree(&re);
2602 return !(status == REG_NOMATCH);
2605 then
2607 else
2608 feat_bail_required REGEX
2610 else
2611 echo '/* OPT_REGEX=0 */' >> ${h}
2614 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2615 have_mle=1
2616 echo '#define HAVE_MLE' >> ${h}
2617 else
2618 feat_bail_required MLE
2619 echo '/* OPT_MLE=0 */' >> ${h}
2622 # Generic have-a-line-editor switch for those who need it below
2623 if [ -n "${have_mle}" ]; then
2624 have_cle=1
2627 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2628 echo '#define HAVE_HISTORY' >> ${h}
2629 else
2630 echo '/* OPT_HISTORY=0 */' >> ${h}
2633 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2634 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2635 else
2636 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2639 if feat_yes TERMCAP; then
2640 __termcaplib() {
2641 link_check termcap "termcap(5) (via ${4})" \
2642 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2643 #include <stdio.h>
2644 #include <stdlib.h>
2645 ${2}
2646 #include <term.h>
2647 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2648 static int my_putc(int c){return putchar(c);}
2649 int main(void){
2650 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2651 int r2 = OK, r3 = ERR;
2653 tgetent(buf, getenv("TERM"));
2654 cpb = cmdbuf;
2655 r1 = tgetstr(UNCONST("cm"), &cpb);
2656 tgoto(r1, 1, 1);
2657 r2 = tgetnum(UNCONST("Co"));
2658 r3 = tgetflag(UNCONST("ut"));
2659 tputs("cr", 1, &my_putc);
2660 return (r1 == NULL || r2 == -1 || r3 == 0);
2662 _EOT
2665 __terminfolib() {
2666 link_check terminfo "terminfo(5) (via ${2})" \
2667 '#define HAVE_TERMCAP
2668 #define HAVE_TERMCAP_CURSES
2669 #define HAVE_TERMINFO' "${1}" << _EOT
2670 #include <stdio.h>
2671 #include <curses.h>
2672 #include <term.h>
2673 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2674 static int my_putc(int c){return putchar(c);}
2675 int main(void){
2676 int er, r0, r1, r2;
2677 char *r3, *tp;
2679 er = OK;
2680 r0 = setupterm(NULL, 1, &er);
2681 r1 = tigetflag(UNCONST("bce"));
2682 r2 = tigetnum(UNCONST("colors"));
2683 r3 = tigetstr(UNCONST("cr"));
2684 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2685 tputs(tp, 1, &my_putc);
2686 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2687 r3 == (char*)-1 || r3 == NULL);
2689 _EOT
2692 if feat_yes TERMCAP_VIA_TERMINFO; then
2693 __terminfolib -ltinfo -ltinfo ||
2694 __terminfolib -lcurses -lcurses ||
2695 __terminfolib -lcursesw -lcursesw ||
2696 feat_bail_required TERMCAP_VIA_TERMINFO
2699 if [ -z "${have_terminfo}" ]; then
2700 __termcaplib -ltermcap '' '' '-ltermcap' ||
2701 __termcaplib -ltermcap '#include <curses.h>' '
2702 #define HAVE_TERMCAP_CURSES' \
2703 'curses.h / -ltermcap' ||
2704 __termcaplib -lcurses '#include <curses.h>' '
2705 #define HAVE_TERMCAP_CURSES' \
2706 'curses.h / -lcurses' ||
2707 __termcaplib -lcursesw '#include <curses.h>' '
2708 #define HAVE_TERMCAP_CURSES' \
2709 'curses.h / -lcursesw' ||
2710 feat_bail_required TERMCAP
2712 if [ -n "${have_termcap}" ]; then
2713 run_check tgetent_null \
2714 "tgetent(3) of termcap(5) takes NULL buffer" \
2715 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2716 #include <stdio.h> /* For C89 NULL */
2717 #include <stdlib.h>
2718 #ifdef HAVE_TERMCAP_CURSES
2719 # include <curses.h>
2720 #endif
2721 #include <term.h>
2722 int main(void){
2723 tgetent(NULL, getenv("TERM"));
2724 return 0;
2726 _EOT
2729 else
2730 echo '/* OPT_TERMCAP=0 */' >> ${h}
2731 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2734 if feat_def SPAM_SPAMC; then
2735 if acmd_set i spamc; then
2736 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2740 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2741 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2742 else
2743 feat_bail_required SPAM_SPAMD
2744 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2747 feat_def SPAM_FILTER
2749 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2750 echo '#define HAVE_SPAM' >> ${h}
2751 else
2752 echo '/* HAVE_SPAM */' >> ${h}
2755 if feat_yes QUOTE_FOLD &&\
2756 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2757 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2758 else
2759 feat_bail_required QUOTE_FOLD
2760 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2763 feat_def FILTER_HTML_TAGSOUP
2764 feat_def COLOUR
2765 feat_def DOTLOCK
2766 feat_def MD5
2767 feat_def NOMEMDBG
2769 ## Summarizing
2771 ${rm} -f ${tmp}
2772 squeeze_em ${inc} ${tmp}
2773 ${mv} ${tmp} ${inc}
2774 squeeze_em ${lib} ${tmp}
2775 ${mv} ${tmp} ${lib}
2777 # mk-config.h
2778 ${mv} ${h} ${tmp}
2779 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2780 ${cat} ${tmp} >> ${h}
2781 ${rm} -f ${tmp}
2782 printf '\n' >> ${h}
2784 # Create the string that is used by *features* and `version'.
2785 # Take this nice opportunity and generate a visual listing of included and
2786 # non-included features for the person who runs the configuration
2787 msg '\nThe following features are included (+) or not (-):'
2788 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2789 printf '/* The "feature string" */\n' >> ${h}
2790 # Because + is expanded by *folder* if first in "echo $features", put something
2791 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2792 sep=
2793 for opt
2795 sdoc=`option_doc_of ${opt}`
2796 [ -z "${sdoc}" ] && continue
2797 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2798 feat_yes ${opt} && sign=+ || sign=-
2799 printf -- "${sep}${sign}${sopt}" >> ${h}
2800 sep=','
2801 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2802 done
2803 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2804 #exec 5>&1 >>${h}
2805 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2806 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2807 printf '"\n' >> ${h}
2809 # Create the real mk-config.mk
2810 # Note we cannout use explicit ./ filename prefix for source and object
2811 # pathnames because of a bug in bmake(1)
2812 ${rm} -rf ${tmp0}.* ${tmp0}*
2813 srclist= objlist=
2814 if feat_no AMALGAMATION; then
2815 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2816 i=`basename "${i}" .c`
2817 if [ "${i}" = privsep ]; then
2818 continue
2820 objlist="${objlist} ${i}.o"
2821 srclist="${srclist} \$(SRCDIR)${i}.c"
2822 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2823 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2824 done
2825 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2826 else
2827 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2828 "main.o" "main.c" >> ${mk}
2829 srclist=main.c objlist=main.o
2830 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2832 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2833 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2834 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2835 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2836 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2837 i=`basename "${i}"`
2838 if [ "${i}" = main.c ] ||
2839 [ "${i}" = privsep.c ]; then
2840 continue
2842 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2843 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
2844 done
2845 echo >> ${mk}
2847 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2849 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2851 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2852 echo "INCS = `${cat} ${inc}`" >> ${mk}
2853 echo >> ${mk}
2854 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2856 ## Finished!
2858 msg '\nSetup:'
2859 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2860 msg ' . bindir: %s' "${VAL_BINDIR}"
2861 if feat_yes DOTLOCK; then
2862 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2864 msg ' . mandir: %s' "${VAL_MANDIR}"
2865 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2866 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2867 msg ''
2869 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2870 exit 0
2872 msg 'Remarks:'
2873 if [ -z "${have_fnmatch}" ]; then
2874 msg ' . The function fnmatch(3) could not be found.'
2875 msg ' Filename patterns like wildcard are not supported on your system'
2877 if [ -z "${have_fchdir}" ]; then
2878 msg ' . The function fchdir(2) could not be found.'
2879 msg ' We will use chdir(2) instead.'
2880 msg ' This is a problem only if the current working directory is changed'
2881 msg ' while this program is inside of it'
2883 msg ''
2885 # s-it-mode