nail.1: variable chains: base name namespace is "reserved"
[s-mailx.git] / make-config.sh
blob6d340c4e1ed4076dfdb39389b046688f5bf1c495
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 #cc_force_no_stackprot=
244 #ld_need_R_flags=
245 #ld_no_bind_now=
246 #ld_rpath_not_runpath=
248 _CFLAGS= _LDFLAGS=
250 os_early_setup() {
251 # We don't "have any utility": only path adjustments and such in here!
252 [ -n "${OS}" ] || OS=`uname -s`
253 export OS
255 if [ ${OS} = SunOS ]; then
256 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
257 _os_early_setup_sunos
261 _os_early_setup_sunos() {
262 # According to standards(5), this is what we need to do
263 if [ -d /usr/xpg4 ]; then :; else
264 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
265 config_exit 1
267 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
268 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
269 export PATH
272 os_setup() {
273 # OSENV ends up in *build-osenv*
274 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
275 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
276 [ -n "${OSENV}" ] || OSENV=`uname -srm`
277 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`uname -a`
278 msg 'Operating system is %s' ${OS}
280 if [ ${OS} = darwin ]; then
281 msg ' . have special Darwin environmental addons...'
282 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
283 elif [ ${OS} = sunos ]; then
284 msg ' . have special SunOS / Solaris "setup" rules ...'
285 _os_setup_sunos
286 elif [ ${OS} = unixware ]; then
287 if feat_yes AUTOCC && acmd_set CC cc; then
288 msg ' . have special UnixWare environmental rules ...'
289 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
291 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
292 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
293 export CC CFLAGS LDFLAGS
294 OPT_AUTOCC=0 ld_need_R_flags=-R
296 elif [ -n "${VERBOSE}" ]; then
297 msg ' . no special treatment for this system necessary or known'
300 # Sledgehammer: better set _GNU_SOURCE
301 # And in general: oh, boy!
302 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
303 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
304 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
305 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
307 # On pkgsrc(7) systems automatically add /usr/pkg/*
308 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
309 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
310 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
311 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
312 ld_rpath_not_runpath=1
316 _os_setup_sunos() {
317 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
318 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
320 # Include packages
321 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
322 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
323 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
324 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
325 ld_no_bind_now=1 ld_rpath_not_runpath=1
327 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
328 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
329 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
330 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
331 ld_no_bind_now=1 ld_rpath_not_runpath=1
334 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
335 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
337 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
338 if [ -x "${cksum}" ]; then :; else
339 msg 'ERROR: Not an executable program: %s' "${cksum}"
340 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
341 msg 'ERROR: However, we do so only for tests.'
342 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
343 config_exit 1
346 if feat_yes AUTOCC; then
347 if acmd_set CC cc; then
348 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
350 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
351 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
352 export CC CFLAGS LDFLAGS
353 OPT_AUTOCC=0 ld_need_R_flags=-R
354 else
355 cc_maxopt=2 cc_force_no_stackprot=1
360 # Check out compiler ($CC) and -flags ($CFLAGS)
361 cc_setup() {
362 # Even though it belongs into cc_flags we will try to compile and link
363 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
364 # EXTRA_CFLAGS/EXTRA_LDFLAGS
365 if feat_no AUTOCC; then
366 _cc_default
367 # Ensure those don't do any harm
368 EXTRA_CFLAGS= EXTRA_LDFLAGS=
369 export EXTRA_CFLAGS EXTRA_LDFLAGS
370 return
371 else
372 CFLAGS= LDFLAGS=
373 export CFLAGS LDFLAGS
376 [ -n "${CC}" ] && { _cc_default; return; }
378 msg_nonl 'Searching for a usable C compiler .. $CC='
379 if acmd_set CC clang || acmd_set CC gcc ||
380 acmd_set CC tcc || acmd_set CC pcc ||
381 acmd_set CC c89 || acmd_set CC c99; then
383 else
384 msg 'boing booom tschak'
385 msg 'ERROR: I cannot find a compiler!'
386 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
387 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
388 config_exit 1
390 msg '%s' "${CC}"
391 export CC
394 _cc_default() {
395 if [ -z "${CC}" ]; then
396 msg 'To go on like you have chosen, please set $CC, rerun.'
397 config_exit 1
400 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
402 else
403 msg 'Using C compiler ${CC}=%s' "${CC}"
407 cc_flags() {
408 if feat_yes AUTOCC; then
409 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
410 cc_check_silent=1
411 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
412 "${CC}"
413 else
414 cc_check_silent=
415 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
418 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
419 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
420 msg ' . have special tcc(1) environmental rules ...'
421 _cc_flags_tcc
422 else
423 # As of pcc CVS 2016-04-02, stack protection support is announced but
424 # will break if used on Linux
425 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
426 cc_force_no_stackprot=1
428 _cc_flags_generic
431 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
432 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
433 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
434 else
435 if feat_no DEBUG; then
436 CFLAGS="-DNDEBUG ${CFLAGS}"
439 msg ''
440 export CFLAGS LDFLAGS
443 _cc_flags_tcc() {
444 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
445 _CFLAGS= _LDFLAGS=
447 cc_check -Wall
448 cc_check -Wextra
449 cc_check -pedantic
451 if feat_yes DEBUG; then
452 # May have problems to find libtcc cc_check -b
453 cc_check -g
456 if ld_check -Wl,-rpath =./ no; then
457 ld_need_R_flags=-Wl,-rpath=
458 if [ -z "${ld_rpath_not_runpath}" ]; then
459 ld_check -Wl,--enable-new-dtags
460 else
461 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
463 ld_runtime_flags # update!
466 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
467 unset __cflags __ldflags
470 _cc_flags_generic() {
471 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
472 _CFLAGS= _LDFLAGS=
473 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
475 # E.g., valgrind does not work well with high optimization
476 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
477 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
478 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
479 cc_maxopt=1
481 # Check -g first since some others may rely upon -g / optim. level
482 if feat_yes DEBUG; then
483 cc_check -O
484 cc_check -g
485 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
487 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
489 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
491 else
492 cc_check -O
495 if feat_yes AMALGAMATION; then
496 cc_check -pipe
499 #if feat_yes DEVEL && cc_check -Weverything; then
501 #else
502 cc_check -Wall
503 cc_check -Wextra
504 cc_check -Wbad-function-cast
505 cc_check -Wcast-align
506 cc_check -Wcast-qual
507 cc_check -Winit-self
508 cc_check -Wmissing-prototypes
509 cc_check -Wshadow
510 cc_check -Wunused
511 cc_check -Wwrite-strings
512 cc_check -Wno-long-long
514 cc_check -pedantic
516 if feat_yes AMALGAMATION && feat_no DEVEL; then
517 cc_check -Wno-unused-function
519 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
521 cc_check -fno-unwind-tables
522 cc_check -fno-asynchronous-unwind-tables
523 cc_check -fstrict-aliasing
524 if cc_check -fstrict-overflow && feat_yes DEVEL; then
525 cc_check -Wstrict-overflow=5
528 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
529 if [ -z "${cc_force_no_stackprot}" ]; then
530 if cc_check -fstack-protector-strong ||
531 cc_check -fstack-protector-all; then
532 cc_check -D_FORTIFY_SOURCE=2
534 else
535 msg ' ! Not checking for -fstack-protector compiler option,'
536 msg ' ! since that caused errors in a "similar" configuration.'
537 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
541 # LD (+ dependend CC)
543 if feat_yes ASAN_ADDRESS; then
544 _ccfg=${_CFLAGS}
545 if cc_check -fsanitize=address &&
546 ld_check -fsanitize=address; then
548 else
549 feat_bail_required ASAN_ADDRESS
550 _CFLAGS=${_ccfg}
554 if feat_yes ASAN_MEMORY; then
555 _ccfg=${_CFLAGS}
556 if cc_check -fsanitize=memory &&
557 ld_check -fsanitize=memory &&
558 cc_check -fsanitize-memory-track-origins=2 &&
559 ld_check -fsanitize-memory-track-origins=2; then
561 else
562 feat_bail_required ASAN_MEMORY
563 _CFLAGS=${_ccfg}
567 ld_check -Wl,-z,relro
568 if [ -z "${ld_no_bind_now}" ]; then
569 ld_check -Wl,-z,now
570 else
571 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
573 ld_check -Wl,-z,noexecstack
574 if ld_check -Wl,-rpath =./ no; then
575 ld_need_R_flags=-Wl,-rpath=
576 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
577 if [ -z "${ld_rpath_not_runpath}" ]; then
578 ld_check -Wl,--enable-new-dtags
579 else
580 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
582 ld_runtime_flags # update!
583 elif ld_check -Wl,-R ./ no; then
584 ld_need_R_flags=-Wl,-R
585 if [ -z "${ld_rpath_not_runpath}" ]; then
586 ld_check -Wl,--enable-new-dtags
587 else
588 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
590 ld_runtime_flags # update!
593 # Address randomization
594 _ccfg=${_CFLAGS}
595 if cc_check -fPIE || cc_check -fpie; then
596 ld_check -pie || _CFLAGS=${_ccfg}
598 unset _ccfg
600 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
601 unset __cflags __ldflags
604 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
606 ## Notes:
607 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
608 ## redirection, so use "printf '' >" instead
610 ## Very first: we undergo several states regarding I/O redirection etc.,
611 ## but need to deal with option updates from within all. Since all the
612 ## option stuff should be above the scissor line, define utility functions
613 ## and redefine them as necessary.
614 ## And, since we have those functions, simply use them for whatever
616 t1=ten10one1ten10one1
617 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
618 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
619 ) > /dev/null 2>&1; then
620 good_shell=1
621 else
622 unset good_shell
624 unset t1
626 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
628 config_exit() {
629 exit ${1}
632 # which(1) not standardized, command(1) -v may return non-executable: unroll!
633 acmd_test() { __acmd "${1}" 1 0 0; }
634 acmd_test_fail() { __acmd "${1}" 1 1 0; }
635 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
636 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
637 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
638 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
639 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
640 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
641 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
642 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
643 __acmd() {
644 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
646 if [ "${dotest}" -ne 0 ]; then
647 eval dotest=\$${varname}
648 if [ -n "${dotest}" ]; then
649 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
650 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
651 return 0
655 oifs=${IFS} IFS=:
656 [ -n "${noglob_shell}" ] && set -o noglob
657 set -- ${PATH}
658 [ -n "${noglob_shell}" ] && set +o noglob
659 IFS=${oifs}
660 for path
662 if [ -z "${path}" ] || [ "${path}" = . ]; then
663 if [ -d "${PWD}" ]; then
664 path=${PWD}
665 else
666 path=.
669 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
670 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
671 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
672 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
673 return 0
675 done
677 # We may have no builtin string functions, we yet have no programs we can
678 # use, try to access once from the root, assuming it is an absolute path if
679 # that finds the executable
680 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
681 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
682 msg ' . ${%s} ... %s' "${pname}" "${pname}"
683 [ -n "${varname}" ] && eval ${varname}="${pname}"
684 return 0
687 [ ${dofail} -eq 0 ] && return 1
688 msg 'ERROR: no trace of utility '"${pname}"
689 exit 1
692 msg() {
693 fmt=${1}
694 shift
695 printf >&2 -- "${fmt}\\n" "${@}"
698 msg_nonl() {
699 fmt=${1}
700 shift
701 printf >&2 -- "${fmt}" "${@}"
704 # Our feature check environment
705 feat_val_no() {
706 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
707 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
710 feat_val_yes() {
711 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
712 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
713 [ "x${1}" = xrequire ]
716 feat_val_require() {
717 [ "x${1}" = xrequire ]
720 _feat_check() {
721 eval i=\$OPT_${1}
722 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
723 if feat_val_no "${i}"; then
724 return 1
725 elif feat_val_yes "${i}"; then
726 return 0
727 else
728 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
729 "${1}" "${i}"
730 config_exit 11
734 feat_yes() {
735 _feat_check ${1}
738 feat_no() {
739 _feat_check ${1} && return 1
740 return 0
743 feat_require() {
744 eval i=\$OPT_${1}
745 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
746 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
749 feat_bail_required() {
750 if feat_require ${1}; then
751 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
752 config_exit 13
754 eval OPT_${1}=0
755 option_update # XXX this is rather useless here (dependency chain..)
758 option_parse() {
759 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
760 # options, without documentation, to $1
761 j=\'
762 i="`${awk} -v input=\"${2}\" '
763 BEGIN{
764 for(i = 0;;){
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)
775 print v
779 eval ${1}=\"${i}\"
782 option_doc_of() {
783 # Return the "documentation string" for option $1, itself if none such
784 j=\'
785 ${awk} -v want="${1}" \
786 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
787 BEGIN{
788 for(;;){
789 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
790 if(voff == 0)
791 break
792 v = substr(input, voff, RLENGTH)
793 input = substr(input, voff + RLENGTH)
794 doff = index(v, "=")
795 if(doff > 0){
796 d = substr(v, doff + 2, length(v) - doff - 1)
797 v = substr(v, 1, doff - 1)
798 }else
799 d = v
800 if(v == want){
801 if(d != "-")
802 print d
803 exit
810 option_join_rc() {
811 # Join the values from make.rc into what currently is defined, not
812 # overwriting yet existing settings
813 ${rm} -f ${tmp}
814 # We want read(1) to perform reverse solidus escaping in order to be able to
815 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
816 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
817 < ${rc} ${awk} 'BEGIN{line = ""}{
818 gsub(/^[[:space:]]+/, "", $0)
819 gsub(/[[:space:]]+$/, "", $0)
820 if(gsub(/\\$/, "", $0)){
821 line = line $0
822 next
823 }else
824 line = line $0
825 if(index(line, "#") == 1){
826 line = ""
827 }else if(length(line)){
828 print line
829 line = ""
831 }' |
832 while read line; do
833 if [ -n "${good_shell}" ]; then
834 i=${line%%=*}
835 else
836 i=`${awk} -v LINE="${line}" 'BEGIN{
837 gsub(/=.*$/, "", LINE)
838 print LINE
841 if [ "${i}" = "${line}" ]; then
842 msg 'ERROR: invalid syntax in: %s' "${line}"
843 continue
846 eval j="\$${i}" jx="\${${i}+x}"
847 if [ -n "${j}" ] || [ "${jx}" = x ]; then
848 : # Yet present
849 else
850 j=`${awk} -v LINE="${line}" 'BEGIN{
851 gsub(/^[^=]*=/, "", LINE)
852 gsub(/^\"*/, "", LINE)
853 gsub(/\"*$/, "", LINE)
854 print LINE
857 [ "${i}" = "DESTDIR" ] && continue
858 echo "${i}=\"${j}\""
859 done > ${tmp}
860 # Reread the mixed version right now
861 . ./${tmp}
864 option_evaluate() {
865 # Expand the option values, which may contain shell snippets
866 ${rm} -f ${newlst} ${newmk} ${newh}
867 exec 5<&0 6>&1 <${tmp} >${newlst}
868 while read line; do
870 if [ -n "${good_shell}" ]; then
871 i=${line%%=*}
872 [ "${i}" != "${i#OPT_}" ] && z=1
873 else
874 i=`${awk} -v LINE="${line}" 'BEGIN{
875 gsub(/=.*$/, "", LINE);\
876 print LINE
878 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
883 eval j=\$${i}
884 if [ -n "${z}" ]; then
885 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
886 if [ -z "${j}" ] || feat_val_no "${j}"; then
888 printf " /* #undef ${i} */\n" >> ${newh}
889 elif feat_val_yes "${j}"; then
890 if feat_val_require "${j}"; then
891 j=require
892 else
895 printf " /* #define ${i} */\n" >> ${newh}
896 else
897 msg 'ERROR: cannot parse <%s>' "${line}"
898 config_exit 1
900 else
901 printf "#define ${i} \"${j}\"\n" >> ${newh}
903 printf "${i} = ${j}\n" >> ${newmk}
904 printf "${i}=${j}\n"
905 eval "${i}=\"${j}\""
906 done
907 exec 0<&5 1>&6 5<&- 6<&-
910 path_check() {
911 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
912 varname=${1} addflag=${2} flagvarname=${3}
913 j=${IFS}
914 IFS=:
915 [ -n "${noglob_shell}" ] && set -o noglob
916 eval "set -- \$${1}"
917 [ -n "${noglob_shell}" ] && set +o noglob
918 IFS=${j}
919 j= k= y= z=
920 for i
922 [ -z "${i}" ] && continue
923 [ -d "${i}" ] || continue
924 if [ -n "${j}" ]; then
925 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
927 else
928 y="${y} :${i}:"
929 j="${j}:${i}"
930 # But do not link any fakeroot path into our binaries!
931 if [ -n "${addflag}" ]; then
932 case "${i}" in *fakeroot*) continue;; esac
933 k="${k} ${addflag}${i}"
936 else
937 y=" :${i}:"
938 j="${i}"
939 # But do not link any fakeroot path into our binaries!
940 if [ -n "${addflag}" ]; then
941 case "${i}" in *fakeroot*) continue;; esac
942 k="${k} ${addflag}${i}"
945 done
946 eval "${varname}=\"${j}\""
947 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
948 unset varname
951 ld_runtime_flags() {
952 if [ -n "${ld_need_R_flags}" ]; then
953 i=${IFS}
954 IFS=:
955 set -- ${LD_LIBRARY_PATH}
956 IFS=${i}
957 for i
959 # But do not link any fakeroot path into our binaries!
960 case "${i}" in *fakeroot*) continue;; esac
961 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
962 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
963 done
964 export LDFLAGS
966 # Disable it for a possible second run.
967 ld_need_R_flags=
970 cc_check() {
971 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
972 if "${CC}" ${INCS} \
973 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
974 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
975 _CFLAGS="${_CFLAGS} ${1}"
976 [ -n "${cc_check_silent}" ] || msg 'yes'
977 return 0
979 [ -n "${cc_check_silent}" ] || msg 'no'
980 return 1
983 ld_check() {
984 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
985 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
986 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
987 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
988 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
989 [ -n "${cc_check_silent}" ] || msg 'yes'
990 return 0
992 [ -n "${cc_check_silent}" ] || msg 'no'
993 return 1
996 dump_test_program=1
997 _check_preface() {
998 variable=$1 topic=$2 define=$3
1000 echo '**********'
1001 msg_nonl ' . %s ... ' "${topic}"
1002 echo "/* checked ${topic} */" >> ${h}
1003 ${rm} -f ${tmp} ${tmp}.o
1004 if [ "${dump_test_program}" = 1 ]; then
1005 echo '*** test program is'
1006 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1007 else
1008 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1010 #echo '*** the preprocessor generates'
1011 #${make} -f ${makefile} ${tmp}.x
1012 #${cat} ${tmp}.x
1013 echo '*** tests results'
1016 without_check() {
1017 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1019 echo '**********'
1020 msg_nonl ' . %s ... ' "${topic}"
1022 echo '*** enforced unchecked results are'
1023 if feat_val_yes ${yesno}; then
1024 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1025 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1026 LIBS="${LIBS} ${libs}"
1027 echo "${libs}" >> ${lib}
1028 INCS="${INCS} ${incs}"
1029 echo "${incs}" >> ${inc}
1031 msg 'yes (deduced)'
1032 echo "${define}" >> ${h}
1033 eval have_${variable}=yes
1034 return 0
1035 else
1036 echo "/* ${define} */" >> ${h}
1037 msg 'no (deduced)'
1038 eval unset have_${variable}
1039 return 1
1043 compile_check() {
1044 variable=$1 topic=$2 define=$3
1046 _check_preface "${variable}" "${topic}" "${define}"
1048 if ${make} -f ${makefile} XINCS="${INCS}" \
1049 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1050 ./${tmp}.o &&
1051 [ -f ./${tmp}.o ]; then
1052 msg 'yes'
1053 echo "${define}" >> ${h}
1054 eval have_${variable}=yes
1055 return 0
1056 else
1057 echo "/* ${define} */" >> ${h}
1058 msg 'no'
1059 eval unset have_${variable}
1060 return 1
1064 _link_mayrun() {
1065 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1067 _check_preface "${variable}" "${topic}" "${define}"
1069 if feat_yes CROSS_BUILD; then
1070 if [ ${run} = 1 ]; then
1071 run=0
1075 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1076 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1077 XLIBS="${LIBS} ${libs}" \
1078 ./${tmp} &&
1079 [ -f ./${tmp} ] &&
1080 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1081 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1082 msg 'yes'
1083 echo "${define}" >> ${h}
1084 LIBS="${LIBS} ${libs}"
1085 echo "${libs}" >> ${lib}
1086 INCS="${INCS} ${incs}"
1087 echo "${incs}" >> ${inc}
1088 eval have_${variable}=yes
1089 return 0
1090 else
1091 msg 'no'
1092 echo "/* ${define} */" >> ${h}
1093 eval unset have_${variable}
1094 return 1
1098 link_check() {
1099 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1102 run_check() {
1103 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1106 xrun_check() {
1107 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1110 feat_def() {
1111 if feat_yes ${1}; then
1112 echo '#define HAVE_'${1}'' >> ${h}
1113 return 0
1114 else
1115 echo '/* OPT_'${1}'=0 */' >> ${h}
1116 return 1
1120 squeeze_em() {
1121 < "${1}" > "${2}" ${awk} \
1122 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1125 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1127 # First of all, create new configuration and check whether it changed
1129 # Very easy checks for the operating system in order to be able to adjust paths
1130 # or similar very basic things which we need to be able to go at all
1131 os_early_setup
1133 # Check those tools right now that we need before including $rc
1134 msg 'Checking for basic utility set'
1135 thecmd_testandset_fail awk awk
1136 thecmd_testandset_fail rm rm
1137 thecmd_testandset_fail tr tr
1139 # Initialize the option set
1140 msg_nonl 'Setting up configuration options ... '
1141 option_setup
1142 msg 'done'
1144 # Include $rc, but only take from it what wasn't overwritten by the user from
1145 # within the command line or from a chosen fixed CONFIG=
1146 # Note we leave alone the values
1147 trap "exit 1" HUP INT TERM
1148 trap "${rm} -f ${tmp}" EXIT
1150 msg_nonl 'Joining in %s ... ' ${rc}
1151 option_join_rc
1152 msg 'done'
1154 # We need to know about that now, in order to provide utility overwrites etc.
1155 os_setup
1157 msg 'Checking for remaining set of utilities'
1158 thecmd_testandset_fail grep grep
1160 # Before we step ahead with the other utilities perform a path cleanup first.
1161 path_check PATH
1163 # awk(1) above
1164 thecmd_testandset_fail basename basename
1165 thecmd_testandset_fail cat cat
1166 thecmd_testandset_fail chmod chmod
1167 thecmd_testandset_fail cp cp
1168 thecmd_testandset_fail cmp cmp
1169 # grep(1) above
1170 thecmd_testandset_fail mkdir mkdir
1171 thecmd_testandset_fail mv mv
1172 # rm(1) above
1173 thecmd_testandset_fail sed sed
1174 thecmd_testandset_fail sort sort
1175 thecmd_testandset_fail tee tee
1176 __PATH=${PATH}
1177 thecmd_testandset chown chown ||
1178 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1179 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1180 PATH=${__PATH}
1181 thecmd_testandset_fail MAKE make
1182 make=${MAKE}
1183 export MAKE
1184 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1186 # For ./cc-test.sh only
1187 thecmd_testandset_fail cksum cksum
1189 # Update OPT_ options now, in order to get possible inter-dependencies right
1190 option_update
1192 # (No functions since some shells loose non-exported variables in traps)
1193 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1194 trap "trap \"\" HUP INT TERM EXIT;\
1195 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1197 # Our configuration options may at this point still contain shell snippets,
1198 # we need to evaluate them in order to get them expanded, and we need those
1199 # evaluated values not only in our new configuration file, but also at hand..
1200 msg_nonl 'Evaluating all configuration items ... '
1201 option_evaluate
1202 msg 'done'
1204 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1205 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1207 # The problem now is that the test should be able to run in the users linker
1208 # and path environment, so we need to place the test: rule first, before
1209 # injecting the relevant make variables. Set up necessary environment
1210 if [ -z "${VERBOSE}" ]; then
1211 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1212 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1213 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1214 printf -- "ECHO_TEST = @\n" >> ${newmk}
1215 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1216 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1217 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1219 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1220 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1222 # Add the known utility and some other variables
1223 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1224 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1225 if feat_yes DOTLOCK; then
1226 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1227 else
1228 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1231 for i in \
1232 SRCDIR \
1233 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1234 MAKE MAKEFLAGS make SHELL strip \
1235 cksum; do
1236 eval j=\$${i}
1237 printf "${i} = ${j}\n" >> ${newmk}
1238 printf "${i}=${j}\n" >> ${newlst}
1239 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1240 done
1241 printf "\n" >> ${newev}
1243 # Build a basic set of INCS and LIBS according to user environment.
1244 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1245 path_check C_INCLUDE_PATH -I _INCS
1246 INCS="${INCS} ${_INCS}"
1247 path_check LD_LIBRARY_PATH -L _LIBS
1248 LIBS="${LIBS} ${_LIBS}"
1249 unset _INCS _LIBS
1250 export C_INCLUDE_PATH LD_LIBRARY_PATH
1252 # Some environments need runtime path flags to be able to go at all
1253 ld_runtime_flags
1255 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1257 cc_setup
1259 ${cat} > ${tmp}.c << \!
1260 #include <stdio.h>
1261 #include <string.h>
1262 static void doit(char const *s);
1264 main(int argc, char **argv){
1265 (void)argc;
1266 (void)argv;
1267 doit("Hello world");
1268 return 0;
1270 static void
1271 doit(char const *s){
1272 char buf[12];
1273 memcpy(buf, s, strlen(s) +1);
1274 puts(s);
1278 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1279 -o ${tmp2} ${tmp}.c ${LIBS}; then
1281 else
1282 msg 'ERROR: i cannot compile a "Hello world" via'
1283 msg ' %s' \
1284 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1285 msg 'ERROR: Please read INSTALL, rerun'
1286 config_exit 1
1289 # This may also update ld_runtime_flags() (again)
1290 cc_flags
1292 for i in \
1293 INCS LIBS \
1294 ; do
1295 eval j=\$${i}
1296 printf -- "${i}=${j}\n" >> ${newlst}
1297 done
1298 for i in \
1299 CC \
1300 CFLAGS \
1301 LDFLAGS \
1302 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1303 OSFULLSPEC \
1304 ; do
1305 eval j=\$${i}
1306 printf -- "${i} = ${j}\n" >> ${newmk}
1307 printf -- "${i}=${j}\n" >> ${newlst}
1308 done
1310 # Now finally check whether we already have a configuration and if so, whether
1311 # all those parameters are still the same.. or something has actually changed
1312 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1313 echo 'Configuration is up-to-date'
1314 exit 0
1315 elif [ -f ${lst} ]; then
1316 echo 'Configuration has been updated..'
1317 ( eval "${MAKE} -f ./mk-config.mk clean" )
1318 echo
1319 else
1320 echo 'Shiny configuration..'
1323 # Time to redefine helper 1
1324 config_exit() {
1325 ${rm} -f ${lst} ${h} ${mk}
1326 exit ${1}
1329 ${mv} -f ${newlst} ${lst}
1330 ${mv} -f ${newev} ${ev}
1331 ${mv} -f ${newh} ${h}
1332 ${mv} -f ${newmk} ${mk}
1334 ## Compile and link checking
1336 tmp3=./${tmp0}3$$
1337 log=./mk-config.log
1338 lib=./mk-config.lib
1339 inc=./mk-config.inc
1340 makefile=./${tmp0}.mk
1342 # (No function since some shells loose non-exported variables in traps)
1343 trap "trap \"\" HUP INT TERM;\
1344 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1345 trap "trap \"\" HUP INT TERM EXIT;\
1346 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1348 # Time to redefine helper 2
1349 msg() {
1350 fmt=${1}
1351 shift
1352 printf "*** ${fmt}\\n" "${@}"
1353 printf -- "${fmt}\\n" "${@}" >&5
1355 msg_nonl() {
1356 fmt=${1}
1357 shift
1358 printf "*** ${fmt}\\n" "${@}"
1359 printf -- "${fmt}" "${@}" >&5
1362 # !!
1363 exec 5>&2 > ${log} 2>&1
1365 echo "${LIBS}" > ${lib}
1366 echo "${INCS}" > ${inc}
1367 ${cat} > ${makefile} << \!
1368 .SUFFIXES: .o .c .x .y
1369 .c.o:
1370 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1371 .c.x:
1372 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1374 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1377 ## Generics
1379 # May be multiline..
1380 echo >> ${h}
1381 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1382 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1383 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1385 # Generate n_err_number OS mappings
1386 dump_test_program=0
1388 feat_yes DEVEL && NV= || NV=noverbose
1389 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1390 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1391 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1392 dump_test_program=1
1394 feat_def ALWAYS_UNICODE_LOCALE
1395 feat_def AMALGAMATION
1396 feat_def CROSS_BUILD
1397 feat_def DOCSTRINGS
1398 feat_def ERRORS
1400 feat_def ASAN_ADDRESS
1401 feat_def ASAN_MEMORY
1402 feat_def DEBUG
1403 feat_def DEVEL
1404 feat_def NYD2
1405 feat_def NOMEMDBG
1407 if xrun_check inline 'inline functions' \
1408 '#define HAVE_INLINE
1409 #define n_INLINE static inline' << \!
1410 static inline int ilf(int i){return ++i;}
1411 int main(void){return ilf(-1);}
1413 then
1415 elif xrun_check inline 'inline functions (via __inline)' \
1416 '#define HAVE_INLINE
1417 #define n_INLINE static __inline' << \!
1418 static __inline int ilf(int i){return ++i;}
1419 int main(void){return ilf(-1);}
1421 then
1425 ## Test for "basic" system-calls / functionality that is used by all parts
1426 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1427 ## macros to be used by only the subprograms (potentially).
1429 if run_check clock_gettime 'clock_gettime(2)' \
1430 '#define HAVE_CLOCK_GETTIME' << \!
1431 #include <time.h>
1432 # include <errno.h>
1433 int main(void){
1434 struct timespec ts;
1436 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1437 return 0;
1438 return 1;
1441 then
1443 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1444 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1445 #include <time.h>
1446 # include <errno.h>
1447 int main(void){
1448 struct timespec ts;
1450 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1451 return 0;
1452 return 1;
1455 then
1457 elif run_check gettimeofday 'gettimeofday(2)' \
1458 '#define HAVE_GETTIMEOFDAY' << \!
1459 #include <stdio.h> /* For C89 NULL */
1460 #include <sys/time.h>
1461 # include <errno.h>
1462 int main(void){
1463 struct timeval tv;
1465 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1466 return 0;
1467 return 1;
1470 then
1472 else
1473 have_no_subsecond_time=1
1476 if run_check nanosleep 'nanosleep(2)' \
1477 '#define HAVE_NANOSLEEP' << \!
1478 #include <time.h>
1479 # include <errno.h>
1480 int main(void){
1481 struct timespec ts;
1483 ts.tv_sec = 1;
1484 ts.tv_nsec = 100000;
1485 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1486 return 0;
1487 return 1;
1490 then
1492 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1493 '#define HAVE_NANOSLEEP' '-lrt' << \!
1494 #include <time.h>
1495 # include <errno.h>
1496 int main(void){
1497 struct timespec ts;
1499 ts.tv_sec = 1;
1500 ts.tv_nsec = 100000;
1501 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1502 return 0;
1503 return 1;
1506 then
1508 # link_check is enough for this, that function is so old, trust the proto
1509 elif link_check sleep 'sleep(3)' \
1510 '#define HAVE_SLEEP' << \!
1511 #include <unistd.h>
1512 # include <errno.h>
1513 int main(void){
1514 if(!sleep(1) || errno != ENOSYS)
1515 return 0;
1516 return 1;
1519 then
1521 else
1522 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1523 config_exit 1
1526 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1527 #include <pwd.h>
1528 #include <unistd.h>
1529 # include <errno.h>
1530 int main(void){
1531 struct passwd *pw;
1532 gid_t gid;
1533 uid_t uid;
1535 if((gid = getgid()) != 0)
1536 gid = getegid();
1537 if((uid = getuid()) != 0)
1538 uid = geteuid();
1539 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1540 return 1;
1541 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1542 return 1;
1543 return 0;
1546 then
1548 else
1549 msg 'ERROR: we require user and group info / database searches.'
1550 msg 'That much Unix we indulge ourselfs.'
1551 config_exit 1
1554 if link_check ftruncate 'ftruncate(2)' \
1555 '#define HAVE_FTRUNCATE' << \!
1556 #include <unistd.h>
1557 #include <sys/types.h>
1558 int main(void){
1559 return (ftruncate(0, 0) != 0);
1562 then
1564 else
1565 msg 'ERROR: we require the ftruncate(2) system call.'
1566 config_exit 1
1569 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1570 #include <signal.h>
1571 # include <errno.h>
1572 int main(void){
1573 struct sigaction nact, oact;
1575 nact.sa_handler = SIG_DFL;
1576 sigemptyset(&nact.sa_mask);
1577 nact.sa_flags = SA_RESTART;
1578 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1581 then
1583 else
1584 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1585 config_exit 1
1588 if link_check snprintf 'snprintf(3)' << \!
1589 #include <stdio.h>
1590 int main(void){
1591 char b[20];
1593 snprintf(b, sizeof b, "%s", "string");
1594 return 0;
1597 then
1599 else
1600 msg 'ERROR: we require the snprintf(3) function.'
1601 config_exit 1
1604 if link_check environ 'environ(3)' << \!
1605 #include <stdio.h> /* For C89 NULL */
1606 int main(void){
1607 extern char **environ;
1609 return environ[0] == NULL;
1612 then
1614 else
1615 msg 'ERROR: we require the environ(3) array for subprocess control.'
1616 config_exit 1
1619 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1620 #include <stdlib.h>
1621 int main(void){
1622 setenv("s-mailx", "i want to see it cute!", 1);
1623 unsetenv("s-mailx");
1624 return 0;
1627 then
1629 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1630 #include <stdlib.h>
1631 int main(void){
1632 putenv("s-mailx=i want to see it cute!");
1633 return 0;
1636 then
1638 else
1639 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1640 config_exit 1
1643 if link_check termios 'termios.h and tc*(3) family' << \!
1644 #include <termios.h>
1645 int main(void){
1646 struct termios tios;
1648 tcgetattr(0, &tios);
1649 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1650 return 0;
1653 then
1655 else
1656 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1657 msg 'That much Unix we indulge ourselfs.'
1658 config_exit 1
1661 ## optional stuff
1663 if link_check vsnprintf 'vsnprintf(3)' << \!
1664 #include <stdarg.h>
1665 #include <stdio.h>
1666 static void dome(char *buf, size_t blen, ...){
1667 va_list ap;
1669 va_start(ap, blen);
1670 vsnprintf(buf, blen, "%s", ap);
1671 va_end(ap);
1673 int main(void){
1674 char b[20];
1676 dome(b, sizeof b, "string");
1677 return 0;
1680 then
1682 else
1683 feat_bail_required ERRORS
1686 if [ "${have_vsnprintf}" = yes ]; then
1687 __va_copy() {
1688 link_check va_copy "va_copy(3) (as ${2})" \
1689 "#define HAVE_N_VA_COPY
1690 #define n_va_copy ${2}" <<_EOT
1691 #include <stdarg.h>
1692 #include <stdio.h>
1693 #if ${1}
1694 # if defined __va_copy && !defined va_copy
1695 # define va_copy __va_copy
1696 # endif
1697 #endif
1698 static void dome2(char *buf, size_t blen, va_list src){
1699 va_list ap;
1701 va_copy(ap, src);
1702 vsnprintf(buf, blen, "%s", ap);
1703 va_end(ap);
1705 static void dome(char *buf, size_t blen, ...){
1706 va_list ap;
1708 va_start(ap, blen);
1709 dome2(buf, blen, ap);
1710 va_end(ap);
1712 int main(void){
1713 char b[20];
1715 dome(b, sizeof b, "string");
1716 return 0;
1718 _EOT
1720 __va_copy 0 va_copy || __va_copy 1 __va_copy
1723 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1724 #include <unistd.h>
1725 #include <errno.h>
1726 int main(void){
1727 int rv = 0;
1729 errno = 0;
1730 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1731 errno = 0;
1732 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1734 /* Only link check */
1735 fpathconf(0, _PC_NAME_MAX);
1737 return rv;
1741 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1742 #include <fcntl.h>
1743 #include <unistd.h>
1744 # include <errno.h>
1745 int main(void){
1746 int fds[2];
1748 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1749 return 0;
1750 return 1;
1754 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1755 #include <termios.h>
1756 int main(void){
1757 struct winsize ws;
1759 tcgetwinsize(0, &ws);
1760 return 0;
1764 # We use this only then for now (need NOW+1)
1765 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1766 #include <fcntl.h> /* For AT_* */
1767 #include <sys/stat.h>
1768 # include <errno.h>
1769 int main(void){
1770 struct timespec ts[2];
1772 ts[0].tv_nsec = UTIME_NOW;
1773 ts[1].tv_nsec = UTIME_OMIT;
1774 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1775 return 0;
1776 return 1;
1782 # XXX Add POSIX check once standardized
1783 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1784 #include <stdlib.h>
1785 int main(void){
1786 arc4random();
1787 return 0;
1790 then
1792 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1793 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1794 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1795 #include <sys/random.h>
1796 int main(void){
1797 char buf[256];
1798 getrandom(buf, sizeof buf, 0);
1799 return 0;
1802 then
1804 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1805 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1806 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1807 #include <sys/syscall.h>
1808 int main(void){
1809 char buf[256];
1810 syscall(SYS_getrandom, buf, sizeof buf, 0);
1811 return 0;
1814 then
1816 elif [ -n "${have_no_subsecond_time}" ]; then
1817 msg 'ERROR: %s %s' 'without a native random' \
1818 'one of clock_gettime(2) and gettimeofday(2) is required.'
1819 config_exit 1
1823 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1824 #include <stdio.h>
1825 int main(void){
1826 putc_unlocked('@', stdout);
1827 return 0;
1831 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1832 #include <unistd.h>
1833 int main(void){
1834 fchdir(0);
1835 return 0;
1839 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1840 #include <stdlib.h>
1841 int main(void){
1842 char x_buf[4096], *x = realpath(".", x_buf);
1844 return (x != NULL) ? 0 : 1;
1847 then
1848 if run_check realpath_malloc 'realpath(3) takes NULL' \
1849 '#define HAVE_REALPATH_NULL' << \!
1850 #include <stdlib.h>
1851 int main(void){
1852 char *x = realpath(".", NULL);
1854 if(x != NULL)
1855 free(x);
1856 return (x != NULL) ? 0 : 1;
1859 then
1864 ## optional and selectable
1866 if feat_yes DOTLOCK; then
1867 if run_check readlink 'readlink(2)' << \!
1868 #include <unistd.h>
1869 # include <errno.h>
1870 int main(void){
1871 char buf[128];
1873 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1874 return 0;
1875 return 1;
1878 then
1880 else
1881 feat_bail_required DOTLOCK
1885 if feat_yes DOTLOCK; then
1886 if run_check fchown 'fchown(2)' << \!
1887 #include <unistd.h>
1888 # include <errno.h>
1889 int main(void){
1890 if(!fchown(0, 0, 0) || errno != ENOSYS)
1891 return 0;
1892 return 1;
1895 then
1897 else
1898 feat_bail_required DOTLOCK
1902 ## Now it is the time to fork away the BASE_ series
1904 ${rm} -f ${tmp}
1905 squeeze_em ${inc} ${tmp}
1906 ${mv} ${tmp} ${inc}
1907 squeeze_em ${lib} ${tmp}
1908 ${mv} ${tmp} ${lib}
1910 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1911 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1913 ## The remains are expected to be used only by the main MUA binary!
1915 OPT_LOCALES=0
1916 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1917 #include <locale.h>
1918 int main(void){
1919 setlocale(LC_ALL, "");
1920 return 0;
1923 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1925 OPT_MULTIBYTE_CHARSETS=0
1926 OPT_WIDE_GLYPHS=0
1927 OPT_TERMINAL_CHARSET=0
1928 if [ -n "${have_setlocale}" ]; then
1929 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1930 '#define HAVE_C90AMEND1' << \!
1931 #include <limits.h>
1932 #include <stdlib.h>
1933 #include <wchar.h>
1934 #include <wctype.h>
1935 int main(void){
1936 char mbb[MB_LEN_MAX + 1];
1937 wchar_t wc;
1939 iswprint(L'c');
1940 towupper(L'c');
1941 mbtowc(&wc, "x", 1);
1942 mbrtowc(&wc, "x", 1, NULL);
1943 wctomb(mbb, wc);
1944 return (mblen("\0", 1) == 0);
1947 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1949 if [ -n "${have_c90amend1}" ]; then
1950 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1951 #include <wchar.h>
1952 int main(void){
1953 wcwidth(L'c');
1954 return 0;
1957 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1960 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1961 #include <langinfo.h>
1962 #include <stdlib.h>
1963 int main(void){
1964 nl_langinfo(DAY_1);
1965 return (nl_langinfo(CODESET) == NULL);
1968 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1969 fi # have_setlocale
1971 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1972 #include <fnmatch.h>
1973 int main(void){
1974 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1978 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1979 #include <dirent.h>
1980 int main(void){
1981 struct dirent de;
1982 return !(de.d_type == DT_UNKNOWN ||
1983 de.d_type == DT_DIR || de.d_type == DT_LNK);
1987 ## optional and selectable
1989 if feat_yes ICONV; then
1990 ${cat} > ${tmp2}.c << \!
1991 #include <stdio.h> /* For C89 NULL */
1992 #include <iconv.h>
1993 int main(void){
1994 iconv_t id;
1996 id = iconv_open("foo", "bar");
1997 iconv(id, NULL, NULL, NULL, NULL);
1998 iconv_close(id);
1999 return 0;
2002 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2003 '#define HAVE_ICONV' ||
2004 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2005 '#define HAVE_ICONV' '-liconv' ||
2006 feat_bail_required ICONV
2007 else
2008 echo '/* OPT_ICONV=0 */' >> ${h}
2009 fi # feat_yes ICONV
2011 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2012 ${cat} > ${tmp2}.c << \!
2013 #include <sys/types.h>
2014 #include <sys/socket.h>
2015 #include <sys/un.h>
2016 # include <errno.h>
2017 int main(void){
2018 struct sockaddr_un soun;
2020 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2021 return 1;
2022 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2023 return 1;
2024 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2025 return 1;
2026 return 0;
2030 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2031 '#define HAVE_UNIX_SOCKETS' ||
2032 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2033 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2034 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2035 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2038 if feat_yes SOCKETS; then
2039 ${cat} > ${tmp2}.c << \!
2040 #include <sys/types.h>
2041 #include <sys/socket.h>
2042 #include <netinet/in.h>
2043 # include <errno.h>
2044 int main(void){
2045 struct sockaddr s;
2047 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2048 return 1;
2049 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2050 return 1;
2051 return 0;
2055 < ${tmp2}.c run_check sockets 'sockets' \
2056 '#define HAVE_SOCKETS' ||
2057 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2058 '#define HAVE_SOCKETS' '-lnsl' ||
2059 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2060 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2061 feat_bail_required SOCKETS
2062 else
2063 echo '/* OPT_SOCKETS=0 */' >> ${h}
2064 fi # feat_yes SOCKETS
2066 if feat_yes SOCKETS; then
2067 link_check getaddrinfo 'getaddrinfo(3)' \
2068 '#define HAVE_GETADDRINFO' << \!
2069 #include <sys/types.h>
2070 #include <sys/socket.h>
2071 #include <stdio.h>
2072 #include <netdb.h>
2073 int main(void){
2074 struct addrinfo a, *ap;
2075 int lrv;
2077 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2078 case EAI_NONAME:
2079 case EAI_SERVICE:
2080 default:
2081 fprintf(stderr, "%s\n", gai_strerror(lrv));
2082 case 0:
2083 break;
2085 return 0;
2090 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2091 compile_check arpa_inet_h '<arpa/inet.h>' \
2092 '#define HAVE_ARPA_INET_H' << \!
2093 #include <sys/types.h>
2094 #include <sys/socket.h>
2095 #include <netdb.h>
2096 #include <netinet/in.h>
2097 #include <arpa/inet.h>
2100 ${cat} > ${tmp2}.c << \!
2101 #include <sys/types.h>
2102 #include <sys/socket.h>
2103 #include <stdio.h>
2104 #include <string.h>
2105 #include <netdb.h>
2106 #include <netinet/in.h>
2107 #ifdef HAVE_ARPA_INET_H
2108 #include <arpa/inet.h>
2109 #endif
2110 int main(void){
2111 struct sockaddr_in servaddr;
2112 unsigned short portno;
2113 struct servent *ep;
2114 struct hostent *hp;
2115 struct in_addr **pptr;
2117 portno = 0;
2118 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2119 portno = (unsigned short)ep->s_port;
2121 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2122 pptr = (struct in_addr**)hp->h_addr_list;
2123 if(hp->h_addrtype != AF_INET)
2124 fprintf(stderr, "au\n");
2125 }else{
2126 switch(h_errno){
2127 case HOST_NOT_FOUND:
2128 case TRY_AGAIN:
2129 case NO_RECOVERY:
2130 case NO_DATA:
2131 break;
2132 default:
2133 fprintf(stderr, "au\n");
2134 break;
2138 memset(&servaddr, 0, sizeof servaddr);
2139 servaddr.sin_family = AF_INET;
2140 servaddr.sin_port = htons(portno);
2141 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2142 fprintf(stderr, "Would connect to %s:%d ...\n",
2143 inet_ntoa(**pptr), (int)portno);
2144 return 0;
2148 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2149 < ${tmp2}.c link_check gethostbyname \
2150 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2151 < ${tmp2}.c link_check gethostbyname \
2152 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2153 '' '-lsocket -lnsl' ||
2154 feat_bail_required SOCKETS
2157 feat_yes SOCKETS &&
2158 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2159 #include <sys/socket.h>
2160 #include <stdlib.h>
2161 # include <errno.h>
2162 int main(void){
2163 int sockfd = 3;
2165 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2166 errno == ENOSYS)
2167 return 1;
2168 return 0;
2172 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2173 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2174 #include <sys/socket.h>
2175 #include <stdlib.h>
2176 int main(void){
2177 struct timeval tv;
2178 int sockfd = 3;
2180 tv.tv_sec = 42;
2181 tv.tv_usec = 21;
2182 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2183 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2184 return 0;
2188 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2189 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2190 #include <sys/socket.h>
2191 #include <stdlib.h>
2192 int main(void){
2193 struct linger li;
2194 int sockfd = 3;
2196 li.l_onoff = 1;
2197 li.l_linger = 42;
2198 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2199 return 0;
2203 VAL_SSL_FEATURES=
2204 if feat_yes SSL; then # {{{
2205 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2206 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2207 # time: we need to test it first in order to get things right
2208 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2209 '#define HAVE_SSL
2210 #define HAVE_XSSL
2211 #define HAVE_XSSL_RESSL
2212 #define HAVE_XSSL_OPENSSL 0' << \!
2213 #include <openssl/opensslv.h>
2214 #ifdef LIBRESSL_VERSION_NUMBER
2215 #else
2216 # error nope
2217 #endif
2219 then
2220 ossl_v1_1=
2221 VAL_SSL_FEATURES=libressl
2222 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2223 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2224 '#define HAVE_SSL
2225 #define HAVE_XSSL
2226 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2227 #include <openssl/opensslv.h>
2228 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2229 #else
2230 # error nope
2231 #endif
2233 then
2234 ossl_v1_1=1
2235 VAL_SSL_FEATURES=libssl-0x10100
2236 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2237 '#define HAVE_SSL
2238 #define HAVE_XSSL
2239 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2240 #include <openssl/opensslv.h>
2241 #ifdef OPENSSL_VERSION_NUMBER
2242 #else
2243 # error nope
2244 #endif
2246 then
2247 ossl_v1_1=
2248 VAL_SSL_FEATURES=libssl-0x10000
2249 else
2250 feat_bail_required SSL
2251 fi # }}}
2253 if feat_yes SSL; then # {{{
2254 if [ -n "${ossl_v1_1}" ]; then
2255 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2256 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2257 '-lssl -lcrypto'
2258 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2259 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2260 '-lssl -lcrypto' << \!
2261 #include <openssl/ssl.h>
2262 #include <openssl/err.h>
2263 #include <openssl/x509v3.h>
2264 #include <openssl/x509.h>
2265 #include <openssl/rand.h>
2266 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2267 # error We need TLSv1.
2268 #endif
2269 int main(void){
2270 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2272 SSL_CTX_free(ctx);
2273 PEM_read_PrivateKey(0, 0, 0, 0);
2274 return 0;
2277 then
2279 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2280 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2281 '-lssl -lcrypto' << \!
2282 #include <openssl/ssl.h>
2283 #include <openssl/err.h>
2284 #include <openssl/x509v3.h>
2285 #include <openssl/x509.h>
2286 #include <openssl/rand.h>
2287 #if defined OPENSSL_NO_SSL3 &&\
2288 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2289 # error We need one of SSLv3 and TLSv1.
2290 #endif
2291 int main(void){
2292 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2294 SSL_CTX_free(ctx);
2295 PEM_read_PrivateKey(0, 0, 0, 0);
2296 return 0;
2299 then
2301 else
2302 feat_bail_required SSL
2304 fi # }}}
2306 if feat_yes SSL; then # {{{
2307 if feat_yes SSL_ALL_ALGORITHMS; then
2308 if [ -n "${ossl_v1_1}" ]; then
2309 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2310 '#define HAVE_SSL_ALL_ALGORITHMS'
2311 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2312 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2313 #include <openssl/evp.h>
2314 int main(void){
2315 OpenSSL_add_all_algorithms();
2316 EVP_get_cipherbyname("two cents i never exist");
2317 EVP_cleanup();
2318 return 0;
2321 then
2323 else
2324 feat_bail_required SSL_ALL_ALGORITHMS
2326 elif [ -n "${ossl_v1_1}" ]; then
2327 without_check yes ssl_all_algo \
2328 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2329 '#define HAVE_SSL_ALL_ALGORITHMS'
2332 if [ -n "${ossl_v1_1}" ]; then
2333 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2334 '#define HAVE_XSSL_STACK_OF'
2335 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2336 '#define HAVE_XSSL_STACK_OF' << \!
2337 #include <stdio.h> /* For C89 NULL */
2338 #include <openssl/ssl.h>
2339 #include <openssl/err.h>
2340 #include <openssl/x509v3.h>
2341 #include <openssl/x509.h>
2342 #include <openssl/rand.h>
2343 int main(void){
2344 STACK_OF(GENERAL_NAME) *gens = NULL;
2346 printf("%p", gens); /* to use it */
2347 return 0;
2350 then
2354 if [ -n "${ossl_v1_1}" ]; then
2355 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2356 '#define HAVE_XSSL_CONFIG'
2357 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2358 elif link_check xssl_conf \
2359 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2360 '#define HAVE_XSSL_CONFIG' << \!
2361 #include <stdio.h> /* For C89 NULL */
2362 #include <openssl/conf.h>
2363 int main(void){
2364 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2365 CONF_modules_free();
2366 return 0;
2369 then
2370 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2371 else
2372 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2375 if [ -n "${ossl_v1_1}" ]; then
2376 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2377 '#define HAVE_XSSL_CONF_CTX'
2378 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2379 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2380 '#define HAVE_XSSL_CONF_CTX' << \!
2381 #include <openssl/ssl.h>
2382 #include <openssl/err.h>
2383 int main(void){
2384 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2385 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2387 SSL_CONF_CTX_set_flags(cctx,
2388 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2389 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2390 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2391 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2392 SSL_CONF_CTX_finish(cctx);
2393 SSL_CONF_CTX_free(cctx);
2394 SSL_CTX_free(ctx);
2395 return 0;
2398 then
2399 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2400 else
2401 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2404 if [ -n "${ossl_v1_1}" ]; then
2405 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2406 '#define HAVE_XSSL_CTX_CONFIG'
2407 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2408 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2409 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2410 '#define HAVE_XSSL_CTX_CONFIG' << \!
2411 #include <stdio.h> /* For C89 NULL */
2412 #include <openssl/ssl.h>
2413 int main(void){
2414 SSL_CTX_config(NULL, "SOMEVAL");
2415 return 0;
2418 then
2419 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2420 else
2421 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2424 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2425 without_check yes xssl_set_maxmin_proto \
2426 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2427 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2428 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2429 elif link_check xssl_set_maxmin_proto \
2430 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2431 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2432 #include <stdio.h> /* For C89 NULL */
2433 #include <openssl/ssl.h>
2434 int main(void){
2435 SSL_CTX_set_min_proto_version(NULL, 0);
2436 SSL_CTX_set_max_proto_version(NULL, 10);
2437 return 0;
2440 then
2441 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2442 else
2443 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2446 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2447 '#define HAVE_XSSL_RAND_EGD' << \!
2448 #include <openssl/rand.h>
2449 int main(void){
2450 return RAND_egd("some.where") > 0;
2453 then
2454 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2455 else
2456 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2458 fi # feat_yes SSL }}}
2460 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2461 run_check ssl_md5 'MD5 digest in the used crypto library' \
2462 '#define HAVE_XSSL_MD5' << \!
2463 #include <stdlib.h>
2464 #include <string.h>
2465 #include <openssl/md5.h>
2466 int main(void){
2467 char const dat[] = "abrakadabrafidibus";
2468 char dig[16], hex[16 * 2];
2469 MD5_CTX ctx;
2470 size_t i, j;
2472 memset(dig, 0, sizeof(dig));
2473 memset(hex, 0, sizeof(hex));
2474 MD5_Init(&ctx);
2475 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2476 MD5_Final(dig, &ctx);
2478 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2479 for(i = 0; i < sizeof(hex) / 2; i++){
2480 j = i << 1;
2481 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2482 hex[++j] = hexchar(dig[i] & 0x0f);
2484 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2487 fi # }}}
2488 else
2489 echo '/* OPT_SSL=0 */' >> ${h}
2490 fi # }}} feat_yes SSL
2491 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2493 if [ "${have_xssl}" = yes ]; then
2494 OPT_SMIME=1
2495 else
2496 OPT_SMIME=0
2498 feat_def SMIME
2500 feat_def SMTP
2501 feat_def POP3
2502 feat_def IMAP
2504 if feat_yes GSSAPI; then
2505 ${cat} > ${tmp2}.c << \!
2506 #include <gssapi/gssapi.h>
2507 int main(void){
2508 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2509 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2510 return 0;
2513 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2515 if acmd_set i krb5-config; then
2516 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2517 GSS_INCS="`CFLAGS= ${i} --cflags`"
2518 i='GSS-API via krb5-config(1)'
2519 else
2520 GSS_LIBS='-lgssapi'
2521 GSS_INCS=
2522 i='GSS-API in gssapi/gssapi.h, libgssapi'
2524 if < ${tmp2}.c link_check gss \
2525 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2526 < ${tmp3}.c link_check gss \
2527 'GSS-API in gssapi.h, libgssapi' \
2528 '#define HAVE_GSSAPI
2529 #define GSSAPI_REG_INCLUDE' \
2530 '-lgssapi' ||\
2531 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2532 '#define HAVE_GSSAPI' \
2533 '-lgssapi_krb5' ||\
2534 < ${tmp3}.c link_check gss \
2535 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2536 '#define HAVE_GSSAPI
2537 #define GSS_REG_INCLUDE' \
2538 '-lgssapi -lkrb5 -lcrypto' \
2539 '-I/usr/include/kerberosV' ||\
2540 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2541 '#define HAVE_GSSAPI' \
2542 '-lgss' ||\
2543 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2544 '#define HAVE_GSSAPI
2545 #define GSSAPI_OLD_STYLE' \
2546 '-lgssapi_krb5' << \!
2547 #include <gssapi/gssapi.h>
2548 #include <gssapi/gssapi_generic.h>
2549 int main(void){
2550 gss_import_name(0, 0, gss_nt_service_name, 0);
2551 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2552 return 0;
2555 then
2557 else
2558 feat_bail_required GSSAPI
2560 else
2561 echo '/* OPT_GSSAPI=0 */' >> ${h}
2562 fi # feat_yes GSSAPI
2564 feat_def NETRC
2565 feat_def AGENT
2567 if feat_yes IDNA; then
2568 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2569 '-lidn' << \!
2570 #include <idna.h>
2571 #include <idn-free.h>
2572 #include <stringprep.h>
2573 int main(void){
2574 char *utf8, *idna_ascii, *idna_utf8;
2576 utf8 = stringprep_locale_to_utf8("does.this.work");
2577 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2578 != IDNA_SUCCESS)
2579 return 1;
2580 idn_free(idna_ascii);
2581 /* (Rather link check only here) */
2582 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2583 return 0;
2586 then
2588 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2589 '-lidnkit' << \!
2590 #include <stdio.h>
2591 #include <idn/api.h>
2592 #include <idn/result.h>
2593 int main(void){
2594 idn_result_t r;
2595 char ace_name[256];
2596 char local_name[256];
2598 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2599 sizeof(ace_name));
2600 if (r != idn_success) {
2601 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2602 return 1;
2604 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2605 if (r != idn_success) {
2606 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2607 return 1;
2609 return 0;
2612 then
2614 else
2615 feat_bail_required IDNA
2618 if [ -n "${have_idna}" ]; then
2619 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2620 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2622 else
2623 echo '/* OPT_IDNA=0 */' >> ${h}
2626 feat_def IMAP_SEARCH
2628 if feat_yes REGEX; then
2629 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2630 #include <regex.h>
2631 #include <stdlib.h>
2632 int main(void){
2633 size_t xret;
2634 int status;
2635 regex_t re;
2637 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2638 xret = regerror(status, &re, NULL, 0);
2639 status = regexec(&re, "plan9", 0,NULL, 0);
2640 regfree(&re);
2641 return !(status == REG_NOMATCH);
2644 then
2646 else
2647 feat_bail_required REGEX
2649 else
2650 echo '/* OPT_REGEX=0 */' >> ${h}
2653 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2654 have_mle=1
2655 echo '#define HAVE_MLE' >> ${h}
2656 else
2657 feat_bail_required MLE
2658 echo '/* OPT_MLE=0 */' >> ${h}
2661 # Generic have-a-line-editor switch for those who need it below
2662 if [ -n "${have_mle}" ]; then
2663 have_cle=1
2666 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2667 echo '#define HAVE_HISTORY' >> ${h}
2668 else
2669 echo '/* OPT_HISTORY=0 */' >> ${h}
2672 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2673 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2674 else
2675 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2678 if feat_yes TERMCAP; then
2679 __termcaplib() {
2680 link_check termcap "termcap(5) (via ${4})" \
2681 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2682 #include <stdio.h>
2683 #include <stdlib.h>
2684 ${2}
2685 #include <term.h>
2686 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2687 static int my_putc(int c){return putchar(c);}
2688 int main(void){
2689 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2690 int r2 = OK, r3 = ERR;
2692 tgetent(buf, getenv("TERM"));
2693 cpb = cmdbuf;
2694 r1 = tgetstr(UNCONST("cm"), &cpb);
2695 tgoto(r1, 1, 1);
2696 r2 = tgetnum(UNCONST("Co"));
2697 r3 = tgetflag(UNCONST("ut"));
2698 tputs("cr", 1, &my_putc);
2699 return (r1 == NULL || r2 == -1 || r3 == 0);
2701 _EOT
2704 __terminfolib() {
2705 link_check terminfo "terminfo(5) (via ${2})" \
2706 '#define HAVE_TERMCAP
2707 #define HAVE_TERMCAP_CURSES
2708 #define HAVE_TERMINFO' "${1}" << _EOT
2709 #include <stdio.h>
2710 #include <curses.h>
2711 #include <term.h>
2712 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2713 static int my_putc(int c){return putchar(c);}
2714 int main(void){
2715 int er, r0, r1, r2;
2716 char *r3, *tp;
2718 er = OK;
2719 r0 = setupterm(NULL, 1, &er);
2720 r1 = tigetflag(UNCONST("bce"));
2721 r2 = tigetnum(UNCONST("colors"));
2722 r3 = tigetstr(UNCONST("cr"));
2723 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2724 tputs(tp, 1, &my_putc);
2725 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2726 r3 == (char*)-1 || r3 == NULL);
2728 _EOT
2731 if feat_yes TERMCAP_VIA_TERMINFO; then
2732 __terminfolib -ltinfo -ltinfo ||
2733 __terminfolib -lcurses -lcurses ||
2734 __terminfolib -lcursesw -lcursesw ||
2735 feat_bail_required TERMCAP_VIA_TERMINFO
2738 if [ -z "${have_terminfo}" ]; then
2739 __termcaplib -ltermcap '' '' '-ltermcap' ||
2740 __termcaplib -ltermcap '#include <curses.h>' '
2741 #define HAVE_TERMCAP_CURSES' \
2742 'curses.h / -ltermcap' ||
2743 __termcaplib -lcurses '#include <curses.h>' '
2744 #define HAVE_TERMCAP_CURSES' \
2745 'curses.h / -lcurses' ||
2746 __termcaplib -lcursesw '#include <curses.h>' '
2747 #define HAVE_TERMCAP_CURSES' \
2748 'curses.h / -lcursesw' ||
2749 feat_bail_required TERMCAP
2751 if [ -n "${have_termcap}" ]; then
2752 run_check tgetent_null \
2753 "tgetent(3) of termcap(5) takes NULL buffer" \
2754 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2755 #include <stdio.h> /* For C89 NULL */
2756 #include <stdlib.h>
2757 #ifdef HAVE_TERMCAP_CURSES
2758 # include <curses.h>
2759 #endif
2760 #include <term.h>
2761 int main(void){
2762 tgetent(NULL, getenv("TERM"));
2763 return 0;
2765 _EOT
2768 else
2769 echo '/* OPT_TERMCAP=0 */' >> ${h}
2770 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2773 if feat_def SPAM_SPAMC; then
2774 if acmd_set i spamc; then
2775 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2779 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2780 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2781 else
2782 feat_bail_required SPAM_SPAMD
2783 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2786 feat_def SPAM_FILTER
2788 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2789 echo '#define HAVE_SPAM' >> ${h}
2790 else
2791 echo '/* HAVE_SPAM */' >> ${h}
2794 if feat_yes QUOTE_FOLD &&\
2795 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2796 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2797 else
2798 feat_bail_required QUOTE_FOLD
2799 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2802 feat_def FILTER_HTML_TAGSOUP
2803 feat_def COLOUR
2804 feat_def DOTLOCK
2805 feat_def MD5
2807 ## Summarizing
2809 ${rm} -f ${tmp}
2810 squeeze_em ${inc} ${tmp}
2811 ${mv} ${tmp} ${inc}
2812 squeeze_em ${lib} ${tmp}
2813 ${mv} ${tmp} ${lib}
2815 # mk-config.h
2816 ${mv} ${h} ${tmp}
2817 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2818 ${cat} ${tmp} >> ${h}
2819 ${rm} -f ${tmp}
2820 printf '\n' >> ${h}
2822 # Create the string that is used by *features* and `version'.
2823 # Take this nice opportunity and generate a visual listing of included and
2824 # non-included features for the person who runs the configuration
2825 msg '\nThe following features are included (+) or not (-):'
2826 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2827 printf '/* The "feature string" */\n' >> ${h}
2828 # Because + is expanded by *folder* if first in "echo $features", put something
2829 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2830 sep=
2831 for opt
2833 sdoc=`option_doc_of ${opt}`
2834 [ -z "${sdoc}" ] && continue
2835 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2836 feat_yes ${opt} && sign=+ || sign=-
2837 printf -- "${sep}${sign}${sopt}" >> ${h}
2838 sep=','
2839 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2840 done
2841 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2842 #exec 5>&1 >>${h}
2843 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2844 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2845 printf '"\n' >> ${h}
2847 # Create the real mk-config.mk
2848 # Note we cannout use explicit ./ filename prefix for source and object
2849 # pathnames because of a bug in bmake(1)
2850 ${rm} -rf ${tmp0}.* ${tmp0}*
2851 srclist= objlist=
2852 if feat_no AMALGAMATION; then
2853 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2854 i=`basename "${i}" .c`
2855 if [ "${i}" = privsep ]; then
2856 continue
2858 objlist="${objlist} ${i}.o"
2859 srclist="${srclist} \$(SRCDIR)${i}.c"
2860 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2861 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2862 done
2863 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2864 else
2865 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2866 "main.o" "main.c" >> ${mk}
2867 srclist=main.c objlist=main.o
2868 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2870 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2871 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2872 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2873 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2874 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2875 i=`basename "${i}"`
2876 if [ "${i}" = main.c ] ||
2877 [ "${i}" = privsep.c ]; then
2878 continue
2880 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2881 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
2882 done
2883 echo >> ${mk}
2885 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2887 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2889 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2890 echo "INCS = `${cat} ${inc}`" >> ${mk}
2891 echo >> ${mk}
2892 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2894 ## Finished!
2896 msg '\nSetup:'
2897 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2898 msg ' . bindir: %s' "${VAL_BINDIR}"
2899 if feat_yes DOTLOCK; then
2900 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2902 msg ' . mandir: %s' "${VAL_MANDIR}"
2903 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2904 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2905 msg ''
2907 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2908 exit 0
2910 msg 'Remarks:'
2911 if [ -z "${have_fnmatch}" ]; then
2912 msg ' . The function fnmatch(3) could not be found.'
2913 msg ' Filename patterns like wildcard are not supported on your system'
2915 if [ -z "${have_fchdir}" ]; then
2916 msg ' . The function fchdir(2) could not be found.'
2917 msg ' We will use chdir(2) instead.'
2918 msg ' This is a problem only if the current working directory is changed'
2919 msg ' while this program is inside of it'
2921 msg ''
2923 # s-it-mode