collect(): ~[FfMmUu]: should default to the "dot" (Andrew Gee)
[s-mailx.git] / make-config.sh
bloba7661802e2b21033118ce63a2e3dbb03bf19bbf8
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='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 UISTRINGS='User interface and error message strings' \
47 QUOTE_FOLD='Extended *quote-fold*ing' \
48 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
49 COLOUR='Coloured message display' \
50 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
53 # Options which are automatically deduced from host environment, i.e., these
54 # need special treatment all around here to warp from/to OPT_ stuff
55 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
56 XOPTIONS_DETECT="\
57 LOCALES='Locale support - printable characters etc. depend on environment' \
58 MULTIBYTE_CHARSETS='Multibyte character sets' \
59 TERMINAL_CHARSET='Automatic detection of terminal character set' \
60 WIDE_GLYPHS='Wide glyph support' \
63 # Rather special options, for custom building, or which always exist.
64 # Mostly for generating the visual overview and the *features* string
65 XOPTIONS_XTRA="\
66 MIME='Multipurpose Internet Mail Extensions' \
67 SMIME='S/MIME message signing, verification, en- and decryption' \
68 CROSS_BUILD='Cross-compilation: trust any detected environment' \
69 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
70 DEVEL='Computers do not blunder' \
73 # To avoid too many recompilations we use a two-stage "configuration changed"
74 # detection, the first uses mk-config.lst, which only goes for actual user
75 # config settings etc. the second uses mk-config.h, which thus includes the
76 # things we have truly detected. This does not work well for multiple choice
77 # values of which only one will be really used, so those user wishes may not be
78 # placed in the header, only the really detected one (but that has to!).
79 # Used for grep(1), for portability assume fixed matching only.
80 H_BLACKLIST='-e VAL_RANDOM -e VAL_IDNA'
82 # The problem is that we don't have any tools we can use right now, so
83 # encapsulate stuff in functions which get called in right order later on
85 option_reset() {
86 set -- ${OPTIONS}
87 for i
89 eval OPT_${i}=0
90 done
93 option_maximal() {
94 set -- ${OPTIONS}
95 for i
97 eval OPT_${i}=1
98 done
99 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
102 option_setup() {
103 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
104 option_parse OPTIONS "${XOPTIONS}"
105 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
106 OPT_MIME=1
108 # Predefined CONFIG= urations take precedence over anything else
109 if [ -n "${CONFIG}" ]; then
110 option_reset
111 case "${CONFIG}" in
112 [nN][uU][lL][lL])
114 [nN][uU][lL][lL][iI])
115 OPT_ICONV=require
116 OPT_UISTRINGS=1
118 [mM][iI][nN][iI][mM][aA][lL])
119 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
120 OPT_COLOUR=1
121 OPT_DOCSTRINGS=1
122 OPT_UISTRINGS=1
123 OPT_ERRORS=1
124 OPT_IDNA=1
125 OPT_MLE=1
126 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
127 OPT_SPAM_FILTER=1
129 [nN][eE][tT][sS][eE][nN][dD])
130 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
131 OPT_SOCKETS=require
132 OPT_SSL=require
133 OPT_SMTP=require
134 OPT_GSSAPI=1 OPT_NETRC=1
135 OPT_AGENT=1
136 OPT_COLOUR=1
137 OPT_DOCSTRINGS=1
138 OPT_UISTRINGS=1
139 OPT_ERRORS=1
140 OPT_IDNA=1
141 OPT_MLE=1
142 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
143 OPT_SPAM_FILTER=1
145 [mM][aA][xX][iI][mM][aA][lL])
146 option_maximal
148 [dD][eE][vV][eE][lL])
149 option_maximal
150 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
152 [oO][dD][eE][vV][eE][lL])
153 option_maximal
154 OPT_DEVEL=1
157 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
158 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
159 exit 1
161 esac
162 msg_nonl "CONFIG=${CONFIG} ... "
166 # Inter-relationships XXX sort this!
167 option_update() {
168 if feat_no SSL; then
169 OPT_SSL_ALL_ALGORITHMS=0
172 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
173 OPT_SOCKETS=0
175 if feat_no SOCKETS; then
176 if feat_require SMTP; then
177 msg 'ERROR: need SOCKETS for required feature SMTP'
178 config_exit 13
180 if feat_require POP3; then
181 msg 'ERROR: need SOCKETS for required feature POP3'
182 config_exit 13
184 if feat_require IMAP; then
185 msg 'ERROR: need SOCKETS for required feature IMAP'
186 config_exit 13
188 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
189 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
190 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
192 if feat_no SMTP && feat_no IMAP; then
193 OPT_GSSAPI=0
196 if feat_no ICONV; then
197 if feat_yes IMAP; then
198 if feat_yes ALWAYS_UNICODE_LOCALE; then
199 msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
200 elif feat_require IMAP; then
201 msg 'ERROR: need ICONV for required feature IMAP'
202 config_exit 13
203 else
204 msg 'ERROR: disabling IMAP due to missing ICONV'
205 OPT_IMAP=0
209 if feat_yes IDNA; then
210 if feat_require IDNA; then
211 msg 'ERROR: need ICONV for required feature IDNA'
212 config_exit 13
214 msg 'ERROR: disabling IDNA due to missing ICONV'
215 OPT_IDNA=0
219 if feat_no MLE; then
220 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
223 # If we don't need MD5 leave it alone
224 if feat_no SOCKETS; then
225 OPT_MD5=0
228 if feat_no TERMCAP; then
229 OPT_TERMCAP_VIA_TERMINFO=0
232 if feat_yes DEVEL; then
233 OPT_DEBUG=1
237 rc=./make.rc
238 lst=./mk-config.lst
239 ev=./mk-config.ev
240 h=./mk-config.h h_name=mk-config.h
241 mk=./mk-config.mk
243 newlst=./mk-nconfig.lst
244 newmk=./mk-nconfig.mk
245 oldmk=./mk-oconfig.mk
246 newev=./mk-nconfig.ev
247 newh=./mk-nconfig.h
248 oldh=./mk-oconfig.h
249 tmp0=___tmp
250 tmp=./${tmp0}1$$
251 tmp2=./${tmp0}2$$
253 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
255 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
256 # via path_check() later on once possible
258 # TODO cc_maxopt is brute simple, we should compile test program and dig real
259 # compiler versions for known compilers, then be more specific
260 [ -n "${cc_maxopt}" ] || cc_maxopt=100
261 #cc_force_no_stackprot=
262 #ld_need_R_flags=
263 #ld_no_bind_now=
264 #ld_rpath_not_runpath=
266 _CFLAGS= _LDFLAGS=
268 os_early_setup() {
269 [ -n "${OS}" ] && [ -n "${OSENV}" ] && [ -n "${OSFULLSPEC}" ] ||
270 thecmd_testandset_fail uname uname
272 # We don't "have any utility": only path adjustments and such in here!
273 [ -n "${OS}" ] || OS=`${uname} -s`
274 export OS
276 if [ ${OS} = SunOS ]; then
277 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
278 _os_early_setup_sunos
282 _os_early_setup_sunos() {
283 # According to standards(5), this is what we need to do
284 if [ -d /usr/xpg4 ]; then :; else
285 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
286 config_exit 1
288 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
289 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
290 export PATH
293 os_setup() {
294 # OSENV ends up in *build-osenv*
295 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
296 # etc.), it is not baked into the binary
297 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
298 [ -n "${OSENV}" ] || OSENV=`${uname} -sm`
299 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
300 msg 'Operating system is %s' ${OS}
302 if [ ${OS} = darwin ]; then
303 msg ' . have special Darwin environmental addons...'
304 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
305 elif [ ${OS} = sunos ]; then
306 msg ' . have special SunOS / Solaris "setup" rules ...'
307 _os_setup_sunos
308 elif [ ${OS} = unixware ]; then
309 if feat_yes AUTOCC && acmd_set CC cc; then
310 msg ' . have special UnixWare environmental rules ...'
311 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
313 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
314 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
315 export CC CFLAGS LDFLAGS
316 OPT_AUTOCC=0 ld_need_R_flags=-R
318 elif [ -n "${VERBOSE}" ]; then
319 msg ' . no special treatment for this system necessary or known'
322 # Sledgehammer: better set _GNU_SOURCE
323 # And in general: oh, boy!
324 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
325 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
326 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
327 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
329 # On pkgsrc(7) systems automatically add /usr/pkg/*
330 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
331 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
332 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
333 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
334 ld_rpath_not_runpath=1
338 _os_setup_sunos() {
339 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
340 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
342 # Include packages
343 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
344 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
345 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
346 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
347 ld_no_bind_now=1 ld_rpath_not_runpath=1
349 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
350 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
351 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
352 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
353 ld_no_bind_now=1 ld_rpath_not_runpath=1
356 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
357 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
359 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
360 if [ -x "${cksum}" ]; then :; else
361 msg 'ERROR: Not an executable program: %s' "${cksum}"
362 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
363 msg 'ERROR: However, we do so only for tests.'
364 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
365 config_exit 1
368 if feat_yes AUTOCC; then
369 if acmd_set CC cc; then
370 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
372 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
373 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
374 export CC CFLAGS LDFLAGS
375 OPT_AUTOCC=0 ld_need_R_flags=-R
376 else
377 cc_maxopt=2 cc_force_no_stackprot=1
382 # Check out compiler ($CC) and -flags ($CFLAGS)
383 cc_setup() {
384 # Even though it belongs into cc_flags we will try to compile and link
385 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
386 # EXTRA_CFLAGS/EXTRA_LDFLAGS
387 if feat_no AUTOCC; then
388 _cc_default
389 # Ensure those don't do any harm
390 EXTRA_CFLAGS= EXTRA_LDFLAGS=
391 export EXTRA_CFLAGS EXTRA_LDFLAGS
392 return
393 else
394 CFLAGS= LDFLAGS=
395 export CFLAGS LDFLAGS
398 [ -n "${CC}" ] && { _cc_default; return; }
400 msg_nonl 'Searching for a usable C compiler .. $CC='
401 if acmd_set CC clang || acmd_set CC gcc ||
402 acmd_set CC tcc || acmd_set CC pcc ||
403 acmd_set CC c89 || acmd_set CC c99; then
405 else
406 msg 'boing booom tschak'
407 msg 'ERROR: I cannot find a compiler!'
408 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
409 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
410 config_exit 1
412 msg '%s' "${CC}"
413 export CC
416 _cc_default() {
417 if [ -z "${CC}" ]; then
418 msg 'To go on like you have chosen, please set $CC, rerun.'
419 config_exit 1
422 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
424 else
425 msg 'Using C compiler ${CC}=%s' "${CC}"
429 cc_flags() {
430 if feat_yes AUTOCC; then
431 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
432 cc_check_silent=1
433 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
434 "${CC}"
435 else
436 cc_check_silent=
437 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
440 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
441 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
442 msg ' . have special tcc(1) environmental rules ...'
443 _cc_flags_tcc
444 else
445 # As of pcc CVS 2016-04-02, stack protection support is announced but
446 # will break if used on Linux
447 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
448 cc_force_no_stackprot=1
450 _cc_flags_generic
453 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
454 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
455 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
456 else
457 if feat_no DEBUG; then
458 CFLAGS="-DNDEBUG ${CFLAGS}"
461 export CFLAGS LDFLAGS
464 _cc_flags_tcc() {
465 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
466 _CFLAGS= _LDFLAGS=
468 cc_check -W
469 cc_check -Wall
470 cc_check -Wextra
471 cc_check -pedantic
473 if feat_yes DEBUG; then
474 # May have problems to find libtcc cc_check -b
475 cc_check -g
478 if ld_check -Wl,-rpath =./ no; then
479 ld_need_R_flags=-Wl,-rpath=
480 if [ -z "${ld_rpath_not_runpath}" ]; then
481 ld_check -Wl,--enable-new-dtags
482 else
483 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
485 ld_runtime_flags # update!
488 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
489 unset __cflags __ldflags
492 _cc_flags_generic() {
493 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
494 _CFLAGS= _LDFLAGS=
495 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
497 # E.g., valgrind does not work well with high optimization
498 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
499 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
500 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
501 cc_maxopt=1
503 # Check -g first since some others may rely upon -g / optim. level
504 if feat_yes DEBUG; then
505 cc_check -O
506 cc_check -g
507 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
509 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
511 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
513 else
514 cc_check -O
517 if feat_yes AMALGAMATION; then
518 cc_check -pipe
521 #if feat_yes DEVEL && cc_check -Weverything; then
523 #else
524 cc_check -W
525 cc_check -Wall
526 cc_check -Wextra
527 cc_check -Wbad-function-cast
528 cc_check -Wcast-align
529 cc_check -Wcast-qual
530 cc_check -Winit-self
531 cc_check -Wmissing-prototypes
532 cc_check -Wshadow
533 cc_check -Wunused
534 cc_check -Wwrite-strings
535 cc_check -Wno-long-long
537 cc_check -pedantic
539 if feat_yes AMALGAMATION && feat_no DEVEL; then
540 cc_check -Wno-unused-function
542 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
544 cc_check -fno-unwind-tables
545 cc_check -fno-asynchronous-unwind-tables
546 cc_check -fstrict-aliasing
547 if cc_check -fstrict-overflow && feat_yes DEVEL; then
548 cc_check -Wstrict-overflow=5
551 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
552 if [ -z "${cc_force_no_stackprot}" ]; then
553 if cc_check -fstack-protector-strong ||
554 cc_check -fstack-protector-all; then
555 cc_check -D_FORTIFY_SOURCE=2
557 else
558 msg ' ! Not checking for -fstack-protector compiler option,'
559 msg ' ! since that caused errors in a "similar" configuration.'
560 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
564 # LD (+ dependend CC)
566 if feat_yes ASAN_ADDRESS; then
567 _ccfg=${_CFLAGS}
568 if cc_check -fsanitize=address &&
569 ld_check -fsanitize=address; then
571 else
572 feat_bail_required ASAN_ADDRESS
573 _CFLAGS=${_ccfg}
577 if feat_yes ASAN_MEMORY; then
578 _ccfg=${_CFLAGS}
579 if cc_check -fsanitize=memory &&
580 ld_check -fsanitize=memory &&
581 cc_check -fsanitize-memory-track-origins=2 &&
582 ld_check -fsanitize-memory-track-origins=2; then
584 else
585 feat_bail_required ASAN_MEMORY
586 _CFLAGS=${_ccfg}
590 ld_check -Wl,-z,relro
591 if [ -z "${ld_no_bind_now}" ]; then
592 ld_check -Wl,-z,now
593 else
594 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
596 ld_check -Wl,-z,noexecstack
597 if ld_check -Wl,-rpath =./ no; then
598 ld_need_R_flags=-Wl,-rpath=
599 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
600 if [ -z "${ld_rpath_not_runpath}" ]; then
601 ld_check -Wl,--enable-new-dtags
602 else
603 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
605 ld_runtime_flags # update!
606 elif ld_check -Wl,-R ./ no; then
607 ld_need_R_flags=-Wl,-R
608 if [ -z "${ld_rpath_not_runpath}" ]; then
609 ld_check -Wl,--enable-new-dtags
610 else
611 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
613 ld_runtime_flags # update!
616 # Address randomization
617 _ccfg=${_CFLAGS}
618 if cc_check -fPIE || cc_check -fpie; then
619 ld_check -pie || _CFLAGS=${_ccfg}
621 unset _ccfg
623 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
624 unset __cflags __ldflags
627 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
629 ## Notes:
630 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
631 ## redirection, so use "printf '' >" instead
633 ## Very first: we undergo several states regarding I/O redirection etc.,
634 ## but need to deal with option updates from within all. Since all the
635 ## option stuff should be above the scissor line, define utility functions
636 ## and redefine them as necessary.
637 ## And, since we have those functions, simply use them for whatever
639 t1=ten10one1ten10one1
640 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
641 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
642 ) > /dev/null 2>&1; then
643 good_shell=1
644 else
645 unset good_shell
647 unset t1
649 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
651 config_exit() {
652 exit ${1}
655 # which(1) not standardized, command(1) -v may return non-executable: unroll!
656 acmd_test() { __acmd "${1}" 1 0 0; }
657 acmd_test_fail() { __acmd "${1}" 1 1 0; }
658 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
659 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
660 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
661 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
662 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
663 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
664 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
665 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
666 __acmd() {
667 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
669 if [ "${dotest}" -ne 0 ]; then
670 eval dotest=\$${varname}
671 if [ -n "${dotest}" ]; then
672 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
673 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
674 return 0
678 oifs=${IFS} IFS=:
679 [ -n "${noglob_shell}" ] && set -o noglob
680 set -- ${PATH}
681 [ -n "${noglob_shell}" ] && set +o noglob
682 IFS=${oifs}
683 for path
685 if [ -z "${path}" ] || [ "${path}" = . ]; then
686 if [ -d "${PWD}" ]; then
687 path=${PWD}
688 else
689 path=.
692 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
693 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
694 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
695 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
696 return 0
698 done
700 # We may have no builtin string functions, we yet have no programs we can
701 # use, try to access once from the root, assuming it is an absolute path if
702 # that finds the executable
703 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
704 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
705 msg ' . ${%s} ... %s' "${pname}" "${pname}"
706 [ -n "${varname}" ] && eval ${varname}="${pname}"
707 return 0
710 [ ${dofail} -eq 0 ] && return 1
711 msg 'ERROR: no trace of utility '"${pname}"
712 exit 1
715 msg() {
716 fmt=${1}
717 shift
718 printf >&2 -- "${fmt}\\n" "${@}"
721 msg_nonl() {
722 fmt=${1}
723 shift
724 printf >&2 -- "${fmt}" "${@}"
727 # Our feature check environment
728 feat_val_no() {
729 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
730 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
733 feat_val_yes() {
734 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
735 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
736 [ "x${1}" = xrequire ]
739 feat_val_require() {
740 [ "x${1}" = xrequire ]
743 _feat_check() {
744 eval i=\$OPT_${1}
745 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
746 if feat_val_no "${i}"; then
747 return 1
748 elif feat_val_yes "${i}"; then
749 return 0
750 else
751 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
752 "${1}" "${i}"
753 config_exit 11
757 feat_yes() {
758 _feat_check ${1}
761 feat_no() {
762 _feat_check ${1} && return 1
763 return 0
766 feat_require() {
767 eval i=\$OPT_${1}
768 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
769 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
772 feat_bail_required() {
773 if feat_require ${1}; then
774 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
775 config_exit 13
777 feat_is_unsupported "${1}"
780 feat_is_disabled() {
781 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
782 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
785 feat_is_unsupported() {
786 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
787 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
788 eval OPT_${1}=0
789 option_update # XXX this is rather useless here (dependency chain..)
792 feat_def() {
793 if feat_yes ${1}; then
794 msg ' . %s ... yes' "${1}"
795 echo '#define HAVE_'${1}'' >> ${h}
796 return 0
797 else
798 feat_is_disabled "${@}"
799 return 1
803 option_parse() {
804 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
805 # options, without documentation, to $1
806 j=\'
807 i="`${awk} -v input=\"${2}\" '
808 BEGIN{
809 for(i = 0;;){
810 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
811 if(voff == 0)
812 break
813 v = substr(input, voff, RLENGTH)
814 input = substr(input, voff + RLENGTH)
815 doff = index(v, "=")
816 if(doff > 0){
817 d = substr(v, doff + 2, length(v) - doff - 1)
818 v = substr(v, 1, doff - 1)
820 print v
824 eval ${1}=\"${i}\"
827 option_doc_of() {
828 # Return the "documentation string" for option $1, itself if none such
829 j=\'
830 ${awk} -v want="${1}" \
831 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
832 BEGIN{
833 for(;;){
834 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
835 if(voff == 0)
836 break
837 v = substr(input, voff, RLENGTH)
838 input = substr(input, voff + RLENGTH)
839 doff = index(v, "=")
840 if(doff > 0){
841 d = substr(v, doff + 2, length(v) - doff - 1)
842 v = substr(v, 1, doff - 1)
843 }else
844 d = v
845 if(v == want){
846 if(d != "-")
847 print d
848 exit
855 option_join_rc() {
856 # Join the values from make.rc into what currently is defined, not
857 # overwriting yet existing settings
858 ${rm} -f ${tmp}
859 # We want read(1) to perform reverse solidus escaping in order to be able to
860 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
861 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
862 < ${rc} ${awk} 'BEGIN{line = ""}{
863 gsub(/^[[:space:]]+/, "", $0)
864 gsub(/[[:space:]]+$/, "", $0)
865 if(gsub(/\\$/, "", $0)){
866 line = line $0
867 next
868 }else
869 line = line $0
870 if(index(line, "#") == 1){
871 line = ""
872 }else if(length(line)){
873 print line
874 line = ""
876 }' |
877 while read line; do
878 if [ -n "${good_shell}" ]; then
879 i=${line%%=*}
880 else
881 i=`${awk} -v LINE="${line}" 'BEGIN{
882 gsub(/=.*$/, "", LINE)
883 print LINE
886 if [ "${i}" = "${line}" ]; then
887 msg 'ERROR: invalid syntax in: %s' "${line}"
888 continue
891 eval j="\$${i}" jx="\${${i}+x}"
892 if [ -n "${j}" ] || [ "${jx}" = x ]; then
893 : # Yet present
894 else
895 j=`${awk} -v LINE="${line}" 'BEGIN{
896 gsub(/^[^=]*=/, "", LINE)
897 gsub(/^\"*/, "", LINE)
898 gsub(/\"*$/, "", LINE)
899 print LINE
902 [ "${i}" = "DESTDIR" ] && continue
903 echo "${i}=\"${j}\""
904 done > ${tmp}
905 # Reread the mixed version right now
906 . ./${tmp}
909 option_evaluate() {
910 # Expand the option values, which may contain shell snippets
911 ${rm} -f ${newlst} ${newmk} ${newh}
912 exec 5<&0 6>&1 <${tmp} >${newlst}
913 while read line; do
915 if [ -n "${good_shell}" ]; then
916 i=${line%%=*}
917 [ "${i}" != "${i#OPT_}" ] && z=1
918 else
919 i=`${awk} -v LINE="${line}" 'BEGIN{
920 gsub(/=.*$/, "", LINE);\
921 print LINE
923 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
928 eval j=\$${i}
929 if [ -n "${z}" ]; then
930 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
931 if [ -z "${j}" ] || feat_val_no "${j}"; then
933 printf " /* #undef ${i} */\n" >> ${newh}
934 elif feat_val_yes "${j}"; then
935 if feat_val_require "${j}"; then
936 j=require
937 else
940 printf " /* #define ${i} */\n" >> ${newh}
941 else
942 msg 'ERROR: cannot parse <%s>' "${line}"
943 config_exit 1
945 elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
947 else
948 printf "#define ${i} \"${j}\"\n" >> ${newh}
950 printf "${i} = ${j}\n" >> ${newmk}
951 printf "${i}=${j}\n"
952 eval "${i}=\"${j}\""
953 done
954 exec 0<&5 1>&6 5<&- 6<&-
957 val_allof() {
958 eval __expo__=\$${1}
959 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
960 BEGIN{
961 i = split(HEAP, ha, /[, ]/)
962 if((j = split(USER, ua, /[, ]/)) == 0)
963 exit
964 for(; j != 0; --j){
965 us = tolower(ua[j])
966 if(us == "all" || us == "any")
967 continue
968 ok = 0
969 for(ii = i; ii != 0; --ii)
970 if(tolower(ha[ii]) == us){
971 ok = 1
972 break
974 if(!ok)
975 exit 1
979 __rv__=${?}
980 [ ${__rv__} -ne 0 ] && return ${__rv__}
982 if ${awk} -v USER="${__expo__}" '
983 BEGIN{
984 if((j = split(USER, ua, /[, ]/)) == 0)
985 exit
986 for(; j != 0; --j){
987 us = tolower(ua[j])
988 if(us == "all" || us == "any")
989 exit 0
991 exit 1
993 '; then
994 eval "${1}"=\"${2}\"
995 else
996 # Enfore lowercase also in otherwise unchanged user value..
997 eval "${1}"=\""`echo ${__expo__} | ${tr} '[A-Z]_' '[a-z]-'`"\"
999 return 0
1002 path_check() {
1003 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
1004 varname=${1} addflag=${2} flagvarname=${3}
1005 j=${IFS}
1006 IFS=:
1007 [ -n "${noglob_shell}" ] && set -o noglob
1008 eval "set -- \$${1}"
1009 [ -n "${noglob_shell}" ] && set +o noglob
1010 IFS=${j}
1011 j= k= y= z=
1012 for i
1014 [ -z "${i}" ] && continue
1015 [ -d "${i}" ] || continue
1016 if [ -n "${j}" ]; then
1017 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1019 else
1020 y="${y} :${i}:"
1021 j="${j}:${i}"
1022 # But do not link any fakeroot path into our binaries!
1023 if [ -n "${addflag}" ]; then
1024 case "${i}" in *fakeroot*) continue;; esac
1025 k="${k} ${addflag}${i}"
1028 else
1029 y=" :${i}:"
1030 j="${i}"
1031 # But do not link any fakeroot path into our binaries!
1032 if [ -n "${addflag}" ]; then
1033 case "${i}" in *fakeroot*) continue;; esac
1034 k="${k} ${addflag}${i}"
1037 done
1038 eval "${varname}=\"${j}\""
1039 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1040 unset varname
1043 ld_runtime_flags() {
1044 if [ -n "${ld_need_R_flags}" ]; then
1045 i=${IFS}
1046 IFS=:
1047 set -- ${LD_LIBRARY_PATH}
1048 IFS=${i}
1049 for i
1051 # But do not link any fakeroot path into our binaries!
1052 case "${i}" in *fakeroot*) continue;; esac
1053 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1054 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1055 done
1056 export LDFLAGS
1058 # Disable it for a possible second run.
1059 ld_need_R_flags=
1062 cc_check() {
1063 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1064 if "${CC}" ${INCS} \
1065 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1066 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1067 _CFLAGS="${_CFLAGS} ${1}"
1068 [ -n "${cc_check_silent}" ] || msg 'yes'
1069 return 0
1071 [ -n "${cc_check_silent}" ] || msg 'no'
1072 return 1
1075 ld_check() {
1076 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1077 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1078 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1079 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1080 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1081 [ -n "${cc_check_silent}" ] || msg 'yes'
1082 return 0
1084 [ -n "${cc_check_silent}" ] || msg 'no'
1085 return 1
1088 dump_test_program=1
1089 _check_preface() {
1090 variable=$1 topic=$2 define=$3
1092 echo '**********'
1093 msg_nonl ' . %s ... ' "${topic}"
1094 #echo "/* checked ${topic} */" >> ${h}
1095 ${rm} -f ${tmp} ${tmp}.o
1096 if [ "${dump_test_program}" = 1 ]; then
1097 echo '*** test program is'
1098 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1099 else
1100 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1102 #echo '*** the preprocessor generates'
1103 #${make} -f ${makefile} ${tmp}.x
1104 #${cat} ${tmp}.x
1105 echo '*** tests results'
1108 without_check() {
1109 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1111 echo '**********'
1112 msg_nonl ' . %s ... ' "${topic}"
1114 echo '*** enforced unchecked results are'
1115 if feat_val_yes ${yesno}; then
1116 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1117 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1118 LIBS="${LIBS} ${libs}"
1119 echo "${libs}" >> ${lib}
1120 INCS="${INCS} ${incs}"
1121 echo "${incs}" >> ${inc}
1123 msg 'yes (deduced)'
1124 echo "${define}" >> ${h}
1125 eval have_${variable}=yes
1126 return 0
1127 else
1128 #echo "/* ${define} */" >> ${h}
1129 msg 'no (deduced)'
1130 eval unset have_${variable}
1131 return 1
1135 compile_check() {
1136 variable=$1 topic=$2 define=$3
1138 _check_preface "${variable}" "${topic}" "${define}"
1140 if ${make} -f ${makefile} XINCS="${INCS}" \
1141 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1142 ./${tmp}.o &&
1143 [ -f ./${tmp}.o ]; then
1144 msg 'yes'
1145 echo "${define}" >> ${h}
1146 eval have_${variable}=yes
1147 return 0
1148 else
1149 #echo "/* ${define} */" >> ${h}
1150 msg 'no'
1151 eval unset have_${variable}
1152 return 1
1156 _link_mayrun() {
1157 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1159 _check_preface "${variable}" "${topic}" "${define}"
1161 if feat_yes CROSS_BUILD; then
1162 if [ ${run} = 1 ]; then
1163 run=0
1167 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1168 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1169 XLIBS="${LIBS} ${libs}" \
1170 ./${tmp} &&
1171 [ -f ./${tmp} ] &&
1172 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1173 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1174 msg 'yes'
1175 echo "${define}" >> ${h}
1176 LIBS="${LIBS} ${libs}"
1177 echo "${libs}" >> ${lib}
1178 INCS="${INCS} ${incs}"
1179 echo "${incs}" >> ${inc}
1180 eval have_${variable}=yes
1181 return 0
1182 else
1183 msg 'no'
1184 #echo "/* ${define} */" >> ${h}
1185 eval unset have_${variable}
1186 return 1
1190 link_check() {
1191 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1194 run_check() {
1195 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1198 xrun_check() {
1199 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1202 squeeze_em() {
1203 < "${1}" > "${2}" ${awk} \
1204 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1207 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1209 # First of all, create new configuration and check whether it changed
1211 # Very easy checks for the operating system in order to be able to adjust paths
1212 # or similar very basic things which we need to be able to go at all
1213 os_early_setup
1215 # Check those tools right now that we need before including $rc
1216 msg 'Checking for basic utility set'
1217 thecmd_testandset_fail awk awk
1218 thecmd_testandset_fail rm rm
1219 thecmd_testandset_fail tr tr
1221 # Initialize the option set
1222 msg_nonl 'Setting up configuration options ... '
1223 option_setup
1224 msg 'done'
1226 # We need to know about that now, in order to provide utility overwrites etc.
1227 # Also make.rc may want $OS and such.
1228 os_setup
1230 # Include $rc, but only take from it what wasn't overwritten by the user from
1231 # within the command line or from a chosen fixed CONFIG=
1232 # Note we leave alone the values
1233 trap "exit 1" HUP INT TERM
1234 trap "${rm} -f ${tmp}" EXIT
1236 msg_nonl 'Joining in %s ... ' ${rc}
1237 option_join_rc
1238 msg 'done'
1240 msg 'Checking for remaining set of utilities'
1241 thecmd_testandset_fail grep grep
1243 # Before we step ahead with the other utilities perform a path cleanup first.
1244 path_check PATH
1246 # awk(1) above
1247 thecmd_testandset_fail basename basename
1248 thecmd_testandset_fail cat cat
1249 thecmd_testandset_fail chmod chmod
1250 thecmd_testandset_fail cp cp
1251 thecmd_testandset_fail cmp cmp
1252 # grep(1) above
1253 thecmd_testandset_fail mkdir mkdir
1254 thecmd_testandset_fail mv mv
1255 # rm(1) above
1256 thecmd_testandset_fail sed sed
1257 thecmd_testandset_fail sort sort
1258 thecmd_testandset_fail tee tee
1259 __PATH=${PATH}
1260 thecmd_testandset chown chown ||
1261 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1262 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1263 PATH=${__PATH}
1264 thecmd_testandset_fail MAKE make
1265 make=${MAKE}
1266 export MAKE
1267 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1269 # For ./cc-test.sh only
1270 thecmd_testandset_fail cksum cksum
1272 # Update OPT_ options now, in order to get possible inter-dependencies right
1273 option_update
1275 # (No functions since some shells loose non-exported variables in traps)
1276 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1277 trap "trap \"\" HUP INT TERM EXIT;\
1278 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1279 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1281 # Our configuration options may at this point still contain shell snippets,
1282 # we need to evaluate them in order to get them expanded, and we need those
1283 # evaluated values not only in our new configuration file, but also at hand..
1284 msg_nonl 'Evaluating all configuration items ... '
1285 option_evaluate
1286 msg 'done'
1288 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1289 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1291 # The problem now is that the test should be able to run in the users linker
1292 # and path environment, so we need to place the test: rule first, before
1293 # injecting the relevant make variables. Set up necessary environment
1294 if [ -z "${VERBOSE}" ]; then
1295 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1296 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1297 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1298 printf -- "ECHO_TEST = @\n" >> ${newmk}
1299 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1300 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1301 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1303 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1304 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1306 # Add the known utility and some other variables
1307 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1308 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1309 if feat_yes DOTLOCK; then
1310 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1311 else
1312 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1315 for i in \
1316 SRCDIR \
1317 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1318 MAKE MAKEFLAGS make SHELL strip \
1319 cksum; do
1320 eval j=\$${i}
1321 printf "${i} = ${j}\n" >> ${newmk}
1322 printf "${i}=${j}\n" >> ${newlst}
1323 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1324 done
1325 # Note that makefile reads and eval'uates one line of this file, whereas other
1326 # consumers source it via .(1)
1327 printf "\n" >> ${newev}
1329 # Build a basic set of INCS and LIBS according to user environment.
1330 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1331 path_check C_INCLUDE_PATH -I _INCS
1332 INCS="${INCS} ${_INCS}"
1333 path_check LD_LIBRARY_PATH -L _LIBS
1334 LIBS="${LIBS} ${_LIBS}"
1335 unset _INCS _LIBS
1336 export C_INCLUDE_PATH LD_LIBRARY_PATH
1338 # Some environments need runtime path flags to be able to go at all
1339 ld_runtime_flags
1341 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1343 cc_setup
1345 ${cat} > ${tmp}.c << \!
1346 #include <stdio.h>
1347 #include <string.h>
1348 static void doit(char const *s);
1350 main(int argc, char **argv){
1351 (void)argc;
1352 (void)argv;
1353 doit("Hello world");
1354 return 0;
1356 static void
1357 doit(char const *s){
1358 char buf[12];
1359 memcpy(buf, s, strlen(s) +1);
1360 puts(s);
1364 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1365 -o ${tmp2} ${tmp}.c ${LIBS}; then
1367 else
1368 msg 'ERROR: i cannot compile a "Hello world" via'
1369 msg ' %s' \
1370 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1371 msg 'ERROR: Please read INSTALL, rerun'
1372 config_exit 1
1375 # This may also update ld_runtime_flags() (again)
1376 cc_flags
1378 for i in \
1379 INCS LIBS \
1380 ; do
1381 eval j=\$${i}
1382 printf -- "${i}=${j}\n" >> ${newlst}
1383 done
1384 for i in \
1385 CC \
1386 CFLAGS \
1387 LDFLAGS \
1388 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1389 OSFULLSPEC \
1390 ; do
1391 eval j=\$${i}
1392 if [ -n "${j}" ]; then
1393 printf -- "${i} = ${j}\n" >> ${newmk}
1394 printf -- "${i}=${j}\n" >> ${newlst}
1396 done
1398 # Now finally check whether we already have a configuration and if so, whether
1399 # all those parameters are still the same.. or something has actually changed
1400 config_updated=
1401 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1402 echo 'Configuration is up-to-date'
1403 exit 0
1404 elif [ -f ${lst} ]; then
1405 config_updated=1
1406 echo 'Configuration has been updated..'
1407 else
1408 echo 'Shiny configuration..'
1411 # Time to redefine helper 1
1412 config_exit() {
1413 ${rm} -f ${lst} ${h} ${mk}
1414 exit ${1}
1417 ${mv} -f ${newlst} ${lst}
1418 ${mv} -f ${newev} ${ev}
1419 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1420 ${mv} -f ${newh} ${h}
1421 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1422 ${mv} -f ${newmk} ${mk}
1424 ## Compile and link checking
1426 tmp3=./${tmp0}3$$
1427 log=./mk-config.log
1428 lib=./mk-config.lib
1429 inc=./mk-config.inc
1430 makefile=./${tmp0}.mk
1432 # (No function since some shells loose non-exported variables in traps)
1433 trap "trap \"\" HUP INT TERM;\
1434 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1435 HUP INT TERM
1436 trap "trap \"\" HUP INT TERM EXIT;\
1437 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1439 # Time to redefine helper 2
1440 msg() {
1441 fmt=${1}
1442 shift
1443 printf "*** ${fmt}\\n" "${@}"
1444 printf -- "${fmt}\\n" "${@}" >&5
1446 msg_nonl() {
1447 fmt=${1}
1448 shift
1449 printf "*** ${fmt}\\n" "${@}"
1450 printf -- "${fmt}" "${@}" >&5
1453 # !!
1454 exec 5>&2 > ${log} 2>&1
1456 echo "${LIBS}" > ${lib}
1457 echo "${INCS}" > ${inc}
1458 ${cat} > ${makefile} << \!
1459 .SUFFIXES: .o .c .x .y
1460 .c.o:
1461 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1462 .c.x:
1463 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1465 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1468 ## Generics
1470 # May be multiline..
1471 echo >> ${h}
1472 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1473 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1474 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1476 # Generate n_err_number OS mappings
1477 dump_test_program=0
1479 feat_yes DEVEL && NV= || NV=noverbose
1480 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1481 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1482 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1483 dump_test_program=1
1485 feat_def ALWAYS_UNICODE_LOCALE
1486 feat_def AMALGAMATION 0
1487 feat_def CROSS_BUILD
1488 feat_def DOCSTRINGS
1489 feat_def UISTRINGS
1490 feat_def ERRORS
1492 feat_def ASAN_ADDRESS 0
1493 feat_def ASAN_MEMORY 0
1494 feat_def DEBUG 0
1495 feat_def DEVEL 0
1496 feat_def NYD2 0
1497 feat_def NOMEMDBG 0
1499 if xrun_check inline 'inline functions' \
1500 '#define HAVE_INLINE
1501 #define n_INLINE static inline' << \!
1502 static inline int ilf(int i){return ++i;}
1503 int main(void){return ilf(-1);}
1505 then
1507 elif xrun_check inline 'inline functions (via __inline)' \
1508 '#define HAVE_INLINE
1509 #define n_INLINE static __inline' << \!
1510 static __inline int ilf(int i){return ++i;}
1511 int main(void){return ilf(-1);}
1513 then
1517 ## Test for "basic" system-calls / functionality that is used by all parts
1518 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1519 ## macros to be used by only the subprograms (potentially).
1521 if run_check clock_gettime 'clock_gettime(2)' \
1522 '#define HAVE_CLOCK_GETTIME' << \!
1523 #include <time.h>
1524 # include <errno.h>
1525 int main(void){
1526 struct timespec ts;
1528 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1529 return 0;
1530 return 1;
1533 then
1535 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1536 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1537 #include <time.h>
1538 # include <errno.h>
1539 int main(void){
1540 struct timespec ts;
1542 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1543 return 0;
1544 return 1;
1547 then
1549 elif run_check gettimeofday 'gettimeofday(2)' \
1550 '#define HAVE_GETTIMEOFDAY' << \!
1551 #include <stdio.h> /* For C89 NULL */
1552 #include <sys/time.h>
1553 # include <errno.h>
1554 int main(void){
1555 struct timeval tv;
1557 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1558 return 0;
1559 return 1;
1562 then
1564 else
1565 have_no_subsecond_time=1
1568 if run_check nanosleep 'nanosleep(2)' \
1569 '#define HAVE_NANOSLEEP' << \!
1570 #include <time.h>
1571 # include <errno.h>
1572 int main(void){
1573 struct timespec ts;
1575 ts.tv_sec = 1;
1576 ts.tv_nsec = 100000;
1577 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1578 return 0;
1579 return 1;
1582 then
1584 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1585 '#define HAVE_NANOSLEEP' '-lrt' << \!
1586 #include <time.h>
1587 # include <errno.h>
1588 int main(void){
1589 struct timespec ts;
1591 ts.tv_sec = 1;
1592 ts.tv_nsec = 100000;
1593 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1594 return 0;
1595 return 1;
1598 then
1600 # link_check is enough for this, that function is so old, trust the proto
1601 elif link_check sleep 'sleep(3)' \
1602 '#define HAVE_SLEEP' << \!
1603 #include <unistd.h>
1604 # include <errno.h>
1605 int main(void){
1606 if(!sleep(1) || errno != ENOSYS)
1607 return 0;
1608 return 1;
1611 then
1613 else
1614 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1615 config_exit 1
1618 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1619 #include <pwd.h>
1620 #include <unistd.h>
1621 # include <errno.h>
1622 int main(void){
1623 struct passwd *pw;
1624 gid_t gid;
1625 uid_t uid;
1627 if((gid = getgid()) != 0)
1628 gid = getegid();
1629 if((uid = getuid()) != 0)
1630 uid = geteuid();
1631 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1632 return 1;
1633 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1634 return 1;
1635 return 0;
1638 then
1640 else
1641 msg 'ERROR: we require user and group info / database searches.'
1642 msg 'That much Unix we indulge ourselfs.'
1643 config_exit 1
1646 if link_check ftruncate 'ftruncate(2)' \
1647 '#define HAVE_FTRUNCATE' << \!
1648 #include <unistd.h>
1649 #include <sys/types.h>
1650 int main(void){
1651 return (ftruncate(0, 0) != 0);
1654 then
1656 else
1657 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1658 msg 'ERROR: we require the ftruncate(2) system call.'
1659 config_exit 1
1662 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1663 #include <signal.h>
1664 # include <errno.h>
1665 int main(void){
1666 struct sigaction nact, oact;
1668 nact.sa_handler = SIG_DFL;
1669 sigemptyset(&nact.sa_mask);
1670 nact.sa_flags = SA_RESTART;
1671 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1674 then
1676 else
1677 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1678 config_exit 1
1681 if link_check snprintf 'snprintf(3)' << \!
1682 #include <stdio.h>
1683 int main(void){
1684 char b[20];
1686 snprintf(b, sizeof b, "%s", "string");
1687 return 0;
1690 then
1692 else
1693 msg 'ERROR: we require the snprintf(3) function.'
1694 config_exit 1
1697 if link_check environ 'environ(3)' << \!
1698 #include <stdio.h> /* For C89 NULL */
1699 int main(void){
1700 extern char **environ;
1702 return environ[0] == NULL;
1705 then
1707 else
1708 msg 'ERROR: we require the environ(3) array for subprocess control.'
1709 config_exit 1
1712 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1713 #include <stdlib.h>
1714 int main(void){
1715 setenv("s-mailx", "i want to see it cute!", 1);
1716 unsetenv("s-mailx");
1717 return 0;
1720 then
1722 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1723 #include <stdlib.h>
1724 int main(void){
1725 putenv("s-mailx=i want to see it cute!");
1726 return 0;
1729 then
1731 else
1732 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1733 config_exit 1
1736 if link_check termios 'termios.h and tc*(3) family' << \!
1737 #include <termios.h>
1738 int main(void){
1739 struct termios tios;
1741 tcgetattr(0, &tios);
1742 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1743 return 0;
1746 then
1748 else
1749 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1750 msg 'That much Unix we indulge ourselfs.'
1751 config_exit 1
1754 ## optional stuff
1756 if link_check vsnprintf 'vsnprintf(3)' << \!
1757 #include <stdarg.h>
1758 #include <stdio.h>
1759 static void dome(char *buf, size_t blen, ...){
1760 va_list ap;
1762 va_start(ap, blen);
1763 vsnprintf(buf, blen, "%s", ap);
1764 va_end(ap);
1766 int main(void){
1767 char b[20];
1769 dome(b, sizeof b, "string");
1770 return 0;
1773 then
1775 else
1776 feat_bail_required ERRORS
1779 if [ "${have_vsnprintf}" = yes ]; then
1780 __va_copy() {
1781 link_check va_copy "va_copy(3) (as ${2})" \
1782 "#define HAVE_N_VA_COPY
1783 #define n_va_copy ${2}" <<_EOT
1784 #include <stdarg.h>
1785 #include <stdio.h>
1786 #if ${1}
1787 # if defined __va_copy && !defined va_copy
1788 # define va_copy __va_copy
1789 # endif
1790 #endif
1791 static void dome2(char *buf, size_t blen, va_list src){
1792 va_list ap;
1794 va_copy(ap, src);
1795 vsnprintf(buf, blen, "%s", ap);
1796 va_end(ap);
1798 static void dome(char *buf, size_t blen, ...){
1799 va_list ap;
1801 va_start(ap, blen);
1802 dome2(buf, blen, ap);
1803 va_end(ap);
1805 int main(void){
1806 char b[20];
1808 dome(b, sizeof b, "string");
1809 return 0;
1811 _EOT
1813 __va_copy 0 va_copy || __va_copy 1 __va_copy
1816 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1817 #include <unistd.h>
1818 #include <errno.h>
1819 int main(void){
1820 int rv = 0;
1822 errno = 0;
1823 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1824 errno = 0;
1825 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1827 /* Only link check */
1828 fpathconf(0, _PC_NAME_MAX);
1830 return rv;
1834 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1835 #include <fcntl.h>
1836 #include <unistd.h>
1837 # include <errno.h>
1838 int main(void){
1839 int fds[2];
1841 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1842 return 0;
1843 return 1;
1847 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1848 #include <termios.h>
1849 int main(void){
1850 struct winsize ws;
1852 tcgetwinsize(0, &ws);
1853 return 0;
1857 # We use this only then for now (need NOW+1)
1858 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1859 #include <fcntl.h> /* For AT_* */
1860 #include <sys/stat.h>
1861 # include <errno.h>
1862 int main(void){
1863 struct timespec ts[2];
1865 ts[0].tv_nsec = UTIME_NOW;
1866 ts[1].tv_nsec = UTIME_OMIT;
1867 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1868 return 0;
1869 return 1;
1875 # The random check has been moved to below SSL detection due to multiple choice
1876 # selection for PRG sources
1878 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1879 #include <stdio.h>
1880 int main(void){
1881 putc_unlocked('@', stdout);
1882 return 0;
1886 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1887 #include <unistd.h>
1888 int main(void){
1889 fchdir(0);
1890 return 0;
1894 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1895 #include <stdlib.h>
1896 int main(void){
1897 char x_buf[4096], *x = realpath(".", x_buf);
1899 return (x != NULL) ? 0 : 1;
1902 then
1903 if run_check realpath_malloc 'realpath(3) takes NULL' \
1904 '#define HAVE_REALPATH_NULL' << \!
1905 #include <stdlib.h>
1906 int main(void){
1907 char *x = realpath(".", NULL);
1909 if(x != NULL)
1910 free(x);
1911 return (x != NULL) ? 0 : 1;
1914 then
1920 ## optional and selectable
1923 if feat_yes DOTLOCK; then
1924 if run_check readlink 'readlink(2)' << \!
1925 #include <unistd.h>
1926 # include <errno.h>
1927 int main(void){
1928 char buf[128];
1930 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1931 return 0;
1932 return 1;
1935 then
1937 else
1938 feat_bail_required DOTLOCK
1942 if feat_yes DOTLOCK; then
1943 if run_check fchown 'fchown(2)' << \!
1944 #include <unistd.h>
1945 # include <errno.h>
1946 int main(void){
1947 if(!fchown(0, 0, 0) || errno != ENOSYS)
1948 return 0;
1949 return 1;
1952 then
1954 else
1955 feat_bail_required DOTLOCK
1959 if feat_yes DOTLOCK; then
1960 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1961 '#define HAVE_PRCTL_DUMPABLE' << \!
1962 #include <sys/prctl.h>
1963 # include <errno.h>
1964 int main(void){
1965 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1966 return 0;
1967 return 1;
1970 then
1972 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1973 '#define HAVE_PTRACE_DENY' << \!
1974 #include <sys/ptrace.h>
1975 # include <errno.h>
1976 int main(void){
1977 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1978 return 0;
1979 return 1;
1982 then
1984 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1985 '#define HAVE_SETPFLAGS_PROTECT' << \!
1986 #include <priv.h>
1987 # include <errno.h>
1988 int main(void){
1989 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1990 return 0;
1991 return 1;
1994 then
1999 ## Now it is the time to fork away the BASE_ series
2001 ${rm} -f ${tmp}
2002 squeeze_em ${inc} ${tmp}
2003 ${mv} ${tmp} ${inc}
2004 squeeze_em ${lib} ${tmp}
2005 ${mv} ${tmp} ${lib}
2007 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2008 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2010 ## The remains are expected to be used only by the main MUA binary!
2012 OPT_LOCALES=0
2013 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2014 #include <locale.h>
2015 int main(void){
2016 setlocale(LC_ALL, "");
2017 return 0;
2020 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2022 OPT_MULTIBYTE_CHARSETS=0
2023 OPT_WIDE_GLYPHS=0
2024 OPT_TERMINAL_CHARSET=0
2025 if [ -n "${have_setlocale}" ]; then
2026 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2027 '#define HAVE_C90AMEND1' << \!
2028 #include <limits.h>
2029 #include <stdlib.h>
2030 #include <wchar.h>
2031 #include <wctype.h>
2032 int main(void){
2033 char mbb[MB_LEN_MAX + 1];
2034 wchar_t wc;
2036 iswprint(L'c');
2037 towupper(L'c');
2038 mbtowc(&wc, "x", 1);
2039 mbrtowc(&wc, "x", 1, NULL);
2040 wctomb(mbb, wc);
2041 return (mblen("\0", 1) == 0);
2044 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2046 if [ -n "${have_c90amend1}" ]; then
2047 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2048 #include <wchar.h>
2049 int main(void){
2050 wcwidth(L'c');
2051 return 0;
2054 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2057 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2058 #include <langinfo.h>
2059 #include <stdlib.h>
2060 int main(void){
2061 nl_langinfo(DAY_1);
2062 return (nl_langinfo(CODESET) == NULL);
2065 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2066 fi # have_setlocale
2068 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2069 #include <fnmatch.h>
2070 int main(void){
2071 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2075 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2076 #include <dirent.h>
2077 int main(void){
2078 struct dirent de;
2079 return !(de.d_type == DT_UNKNOWN ||
2080 de.d_type == DT_DIR || de.d_type == DT_LNK);
2084 ## optional and selectable
2086 if feat_yes ICONV; then
2087 # To be able to create tests we need to figure out which replacement
2088 # sequence the iconv(3) implementation creates
2089 ${cat} > ${tmp2}.c << \!
2090 #include <stdio.h> /* For C89 NULL */
2091 #include <string.h>
2092 #include <iconv.h>
2093 int main(void){
2094 char inb[16], oub[16], *inbp, *oubp;
2095 iconv_t id;
2096 size_t inl, oul;
2098 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2099 inl = sizeof("\342\200\223") -1;
2100 oul = sizeof oub;
2101 oubp = oub;
2103 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2104 return 1;
2105 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2106 return 1;
2107 iconv_close(id);
2109 *oubp = '\0';
2110 oul = (size_t)(oubp - oub);
2111 if(oul == 0)
2112 return 1;
2113 /* Character-wise replacement? */
2114 if(oul == 1){
2115 if(oub[0] == '?')
2116 return 2;
2117 if(oub[0] == '*')
2118 return 3;
2119 return 1;
2121 /* Byte-wise replacement? */
2122 if(oul == sizeof("\342\200\223") -1){
2123 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2124 return 12;
2125 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2126 return 13;
2127 return 1;
2129 return 0;
2132 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2133 '#define HAVE_ICONV' ||
2134 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2135 '#define HAVE_ICONV' '-liconv' ||
2136 feat_bail_required ICONV
2138 if feat_no CROSS_BUILD; then
2139 { ./${tmp}; } >/dev/null 2>&1
2140 case ${?} in
2141 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2142 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2143 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2144 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2145 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2146 esac
2148 else
2149 feat_is_disabled ICONV
2150 fi # feat_yes ICONV
2152 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2153 ${cat} > ${tmp2}.c << \!
2154 #include <sys/types.h>
2155 #include <sys/socket.h>
2156 #include <sys/un.h>
2157 # include <errno.h>
2158 int main(void){
2159 struct sockaddr_un soun;
2161 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2162 return 1;
2163 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2164 return 1;
2165 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2166 return 1;
2167 return 0;
2171 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2172 '#define HAVE_UNIX_SOCKETS' ||
2173 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2174 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2175 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2176 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2179 if feat_yes SOCKETS; then
2180 ${cat} > ${tmp2}.c << \!
2181 #include <sys/types.h>
2182 #include <sys/socket.h>
2183 #include <netinet/in.h>
2184 # include <errno.h>
2185 int main(void){
2186 struct sockaddr s;
2188 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2189 return 1;
2190 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2191 return 1;
2192 return 0;
2196 < ${tmp2}.c run_check sockets 'sockets' \
2197 '#define HAVE_SOCKETS' ||
2198 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2199 '#define HAVE_SOCKETS' '-lnsl' ||
2200 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2201 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2202 feat_bail_required SOCKETS
2203 else
2204 feat_is_disabled SOCKETS
2205 fi # feat_yes SOCKETS
2207 if feat_yes SOCKETS; then
2208 link_check getaddrinfo 'getaddrinfo(3)' \
2209 '#define HAVE_GETADDRINFO' << \!
2210 #include <sys/types.h>
2211 #include <sys/socket.h>
2212 #include <stdio.h>
2213 #include <netdb.h>
2214 int main(void){
2215 struct addrinfo a, *ap;
2216 int lrv;
2218 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2219 case EAI_NONAME:
2220 case EAI_SERVICE:
2221 default:
2222 fprintf(stderr, "%s\n", gai_strerror(lrv));
2223 case 0:
2224 break;
2226 return 0;
2231 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2232 compile_check arpa_inet_h '<arpa/inet.h>' \
2233 '#define HAVE_ARPA_INET_H' << \!
2234 #include <sys/types.h>
2235 #include <sys/socket.h>
2236 #include <netdb.h>
2237 #include <netinet/in.h>
2238 #include <arpa/inet.h>
2241 ${cat} > ${tmp2}.c << \!
2242 #include <sys/types.h>
2243 #include <sys/socket.h>
2244 #include <stdio.h>
2245 #include <string.h>
2246 #include <netdb.h>
2247 #include <netinet/in.h>
2248 #ifdef HAVE_ARPA_INET_H
2249 #include <arpa/inet.h>
2250 #endif
2251 int main(void){
2252 struct sockaddr_in servaddr;
2253 unsigned short portno;
2254 struct servent *ep;
2255 struct hostent *hp;
2256 struct in_addr **pptr;
2258 portno = 0;
2259 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2260 portno = (unsigned short)ep->s_port;
2262 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2263 pptr = (struct in_addr**)hp->h_addr_list;
2264 if(hp->h_addrtype != AF_INET)
2265 fprintf(stderr, "au\n");
2266 }else{
2267 switch(h_errno){
2268 case HOST_NOT_FOUND:
2269 case TRY_AGAIN:
2270 case NO_RECOVERY:
2271 case NO_DATA:
2272 break;
2273 default:
2274 fprintf(stderr, "au\n");
2275 break;
2279 memset(&servaddr, 0, sizeof servaddr);
2280 servaddr.sin_family = AF_INET;
2281 servaddr.sin_port = htons(portno);
2282 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2283 fprintf(stderr, "Would connect to %s:%d ...\n",
2284 inet_ntoa(**pptr), (int)portno);
2285 return 0;
2289 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2290 < ${tmp2}.c link_check gethostbyname \
2291 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2292 < ${tmp2}.c link_check gethostbyname \
2293 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2294 '' '-lsocket -lnsl' ||
2295 feat_bail_required SOCKETS
2298 feat_yes SOCKETS &&
2299 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2300 #include <sys/socket.h>
2301 #include <stdlib.h>
2302 # include <errno.h>
2303 int main(void){
2304 int sockfd = 3;
2306 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2307 errno == ENOSYS)
2308 return 1;
2309 return 0;
2313 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2314 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2315 #include <sys/socket.h>
2316 #include <stdlib.h>
2317 int main(void){
2318 struct timeval tv;
2319 int sockfd = 3;
2321 tv.tv_sec = 42;
2322 tv.tv_usec = 21;
2323 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2324 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2325 return 0;
2329 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2330 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2331 #include <sys/socket.h>
2332 #include <stdlib.h>
2333 int main(void){
2334 struct linger li;
2335 int sockfd = 3;
2337 li.l_onoff = 1;
2338 li.l_linger = 42;
2339 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2340 return 0;
2344 VAL_SSL_FEATURES=
2345 if feat_yes SSL; then # {{{
2346 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2347 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2348 # time: we need to test it first in order to get things right
2349 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2350 '#define HAVE_SSL
2351 #define HAVE_XSSL
2352 #define HAVE_XSSL_RESSL
2353 #define HAVE_XSSL_OPENSSL 0' << \!
2354 #include <openssl/opensslv.h>
2355 #ifdef LIBRESSL_VERSION_NUMBER
2356 #else
2357 # error nope
2358 #endif
2360 then
2361 ossl_v1_1=
2362 VAL_SSL_FEATURES=libressl
2363 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2364 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2365 '#define HAVE_SSL
2366 #define HAVE_XSSL
2367 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2368 #include <openssl/opensslv.h>
2369 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2370 #else
2371 # error nope
2372 #endif
2374 then
2375 ossl_v1_1=1
2376 VAL_SSL_FEATURES=libssl-0x10100
2377 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2378 '#define HAVE_SSL
2379 #define HAVE_XSSL
2380 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2381 #include <openssl/opensslv.h>
2382 #ifdef OPENSSL_VERSION_NUMBER
2383 #else
2384 # error nope
2385 #endif
2387 then
2388 ossl_v1_1=
2389 VAL_SSL_FEATURES=libssl-0x10000
2390 else
2391 feat_bail_required SSL
2392 fi # }}}
2394 if feat_yes SSL; then # {{{
2395 if [ -n "${ossl_v1_1}" ]; then
2396 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2397 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2398 '-lssl -lcrypto'
2399 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2400 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2401 '-lssl -lcrypto' << \!
2402 #include <openssl/ssl.h>
2403 #include <openssl/err.h>
2404 #include <openssl/x509v3.h>
2405 #include <openssl/x509.h>
2406 #include <openssl/rand.h>
2407 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2408 # error We need TLSv1.
2409 #endif
2410 int main(void){
2411 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2413 SSL_CTX_free(ctx);
2414 PEM_read_PrivateKey(0, 0, 0, 0);
2415 return 0;
2418 then
2420 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2421 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2422 '-lssl -lcrypto' << \!
2423 #include <openssl/ssl.h>
2424 #include <openssl/err.h>
2425 #include <openssl/x509v3.h>
2426 #include <openssl/x509.h>
2427 #include <openssl/rand.h>
2428 #if defined OPENSSL_NO_SSL3 &&\
2429 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2430 # error We need one of SSLv3 and TLSv1.
2431 #endif
2432 int main(void){
2433 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2435 SSL_CTX_free(ctx);
2436 PEM_read_PrivateKey(0, 0, 0, 0);
2437 return 0;
2440 then
2442 else
2443 feat_bail_required SSL
2445 fi # }}}
2447 if feat_yes SSL; then # {{{
2448 if feat_yes SSL_ALL_ALGORITHMS; then
2449 if [ -n "${ossl_v1_1}" ]; then
2450 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2451 '#define HAVE_SSL_ALL_ALGORITHMS'
2452 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2453 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2454 #include <openssl/evp.h>
2455 int main(void){
2456 OpenSSL_add_all_algorithms();
2457 EVP_get_cipherbyname("two cents i never exist");
2458 EVP_cleanup();
2459 return 0;
2462 then
2464 else
2465 feat_bail_required SSL_ALL_ALGORITHMS
2467 elif [ -n "${ossl_v1_1}" ]; then
2468 without_check yes ssl_all_algo \
2469 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2470 '#define HAVE_SSL_ALL_ALGORITHMS'
2473 if [ -n "${ossl_v1_1}" ]; then
2474 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2475 '#define HAVE_XSSL_STACK_OF'
2476 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2477 '#define HAVE_XSSL_STACK_OF' << \!
2478 #include <stdio.h> /* For C89 NULL */
2479 #include <openssl/ssl.h>
2480 #include <openssl/err.h>
2481 #include <openssl/x509v3.h>
2482 #include <openssl/x509.h>
2483 #include <openssl/rand.h>
2484 int main(void){
2485 STACK_OF(GENERAL_NAME) *gens = NULL;
2487 printf("%p", gens); /* to use it */
2488 return 0;
2491 then
2495 if [ -n "${ossl_v1_1}" ]; then
2496 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2497 '#define HAVE_XSSL_CONFIG'
2498 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2499 elif link_check xssl_conf \
2500 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2501 '#define HAVE_XSSL_CONFIG' << \!
2502 #include <stdio.h> /* For C89 NULL */
2503 #include <openssl/conf.h>
2504 int main(void){
2505 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2506 CONF_modules_free();
2507 return 0;
2510 then
2511 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2512 else
2513 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2516 if [ -n "${ossl_v1_1}" ]; then
2517 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2518 '#define HAVE_XSSL_CONF_CTX'
2519 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2520 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2521 '#define HAVE_XSSL_CONF_CTX' << \!
2522 #include <openssl/ssl.h>
2523 #include <openssl/err.h>
2524 int main(void){
2525 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2526 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2528 SSL_CONF_CTX_set_flags(cctx,
2529 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2530 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2531 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2532 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2533 SSL_CONF_CTX_finish(cctx);
2534 SSL_CONF_CTX_free(cctx);
2535 SSL_CTX_free(ctx);
2536 return 0;
2539 then
2540 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2541 else
2542 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2545 if [ -n "${ossl_v1_1}" ]; then
2546 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2547 '#define HAVE_XSSL_CTX_CONFIG'
2548 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2549 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2550 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2551 '#define HAVE_XSSL_CTX_CONFIG' << \!
2552 #include <stdio.h> /* For C89 NULL */
2553 #include <openssl/ssl.h>
2554 int main(void){
2555 SSL_CTX_config(NULL, "SOMEVAL");
2556 return 0;
2559 then
2560 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2561 else
2562 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2565 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2566 without_check yes xssl_set_maxmin_proto \
2567 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2568 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2569 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2570 elif link_check xssl_set_maxmin_proto \
2571 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2572 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2573 #include <stdio.h> /* For C89 NULL */
2574 #include <openssl/ssl.h>
2575 int main(void){
2576 SSL_CTX_set_min_proto_version(NULL, 0);
2577 SSL_CTX_set_max_proto_version(NULL, 10);
2578 return 0;
2581 then
2582 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2583 else
2584 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2587 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2588 '#define HAVE_XSSL_RAND_EGD' << \!
2589 #include <openssl/rand.h>
2590 int main(void){
2591 return RAND_egd("some.where") > 0;
2594 then
2595 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2596 else
2597 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2599 fi # feat_yes SSL }}}
2601 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2602 run_check ssl_md5 'MD5 digest in the used crypto library' \
2603 '#define HAVE_XSSL_MD5' << \!
2604 #include <stdlib.h>
2605 #include <string.h>
2606 #include <openssl/md5.h>
2607 int main(void){
2608 char const dat[] = "abrakadabrafidibus";
2609 char dig[16], hex[16 * 2];
2610 MD5_CTX ctx;
2611 size_t i, j;
2613 memset(dig, 0, sizeof(dig));
2614 memset(hex, 0, sizeof(hex));
2615 MD5_Init(&ctx);
2616 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2617 MD5_Final(dig, &ctx);
2619 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2620 for(i = 0; i < sizeof(hex) / 2; i++){
2621 j = i << 1;
2622 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2623 hex[++j] = hexchar(dig[i] & 0x0f);
2625 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2628 fi # }}}
2630 if feat_yes SSL; then
2631 feat_def SSL_ALL_ALGORITHMS
2632 else
2633 feat_bail_required SSL_ALL_ALGORITHMS
2635 else
2636 feat_is_disabled SSL
2637 feat_is_disabled SSL_ALL_ALGORITHMS
2638 fi # }}} feat_yes SSL
2639 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2641 if [ "${have_xssl}" = yes ]; then
2642 OPT_SMIME=1
2643 else
2644 OPT_SMIME=0
2646 feat_def SMIME
2648 # VAL_RANDOM {{{
2649 if val_allof VAL_RANDOM \
2650 "arc4,ssl,libgetrandom,sysgetrandom,urandom,builtin,error"; then
2652 else
2653 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2654 config_exit 1
2657 val_random_arc4() {
2658 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2659 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2660 #include <stdlib.h>
2661 int main(void){
2662 arc4random();
2663 return 0;
2668 val_random_ssl() {
2669 if feat_yes SSL; then
2670 msg ' . VAL_RANDOM: ssl ... yes'
2671 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2672 return 0
2673 else
2674 msg ' . VAL_RANDOM: ssl ... no'
2675 return 1
2679 val_random_libgetrandom() {
2680 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2681 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2682 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2683 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2684 #include <sys/random.h>
2685 int main(void){
2686 char buf[256];
2687 getrandom(buf, sizeof buf, 0);
2688 return 0;
2693 val_random_sysgetrandom() {
2694 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2695 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2696 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2697 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2698 #include <sys/syscall.h>
2699 int main(void){
2700 char buf[256];
2701 syscall(SYS_getrandom, buf, sizeof buf, 0);
2702 return 0;
2707 val_random_urandom() {
2708 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2709 if feat_yes CROSS_BUILD; then
2710 msg 'yes (unchecked)'
2711 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2712 elif [ -f /dev/urandom ]; then
2713 msg yes
2714 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2715 else
2716 msg no
2717 return 1
2719 return 0
2722 val_random_builtin() {
2723 msg_nonl ' . VAL_RANDOM: builtin ... '
2724 if [ -n "${have_no_subsecond_time}" ]; then
2725 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2726 'one of clock_gettime(2) and gettimeofday(2) is required.'
2727 config_exit 1
2728 else
2729 msg yes
2730 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2734 val_random_error() {
2735 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2736 config_exit 42
2739 oifs=${IFS}
2740 IFS=", "
2741 VAL_RANDOM="${VAL_RANDOM},error"
2742 set -- ${VAL_RANDOM}
2743 IFS=${oifs}
2744 for randfun
2746 eval val_random_$randfun && break
2747 done
2748 # }}} VAL_RANDOM
2750 feat_def SMTP
2751 feat_def POP3
2752 feat_def IMAP
2754 if feat_yes GSSAPI; then
2755 ${cat} > ${tmp2}.c << \!
2756 #include <gssapi/gssapi.h>
2757 int main(void){
2758 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2759 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2760 return 0;
2763 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2765 if acmd_set i krb5-config; then
2766 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2767 GSS_INCS="`CFLAGS= ${i} --cflags`"
2768 i='GSS-API via krb5-config(1)'
2769 else
2770 GSS_LIBS='-lgssapi'
2771 GSS_INCS=
2772 i='GSS-API in gssapi/gssapi.h, libgssapi'
2774 if < ${tmp2}.c link_check gss \
2775 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2776 < ${tmp3}.c link_check gss \
2777 'GSS-API in gssapi.h, libgssapi' \
2778 '#define HAVE_GSSAPI
2779 #define GSSAPI_REG_INCLUDE' \
2780 '-lgssapi' ||\
2781 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2782 '#define HAVE_GSSAPI' \
2783 '-lgssapi_krb5' ||\
2784 < ${tmp3}.c link_check gss \
2785 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2786 '#define HAVE_GSSAPI
2787 #define GSS_REG_INCLUDE' \
2788 '-lgssapi -lkrb5 -lcrypto' \
2789 '-I/usr/include/kerberosV' ||\
2790 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2791 '#define HAVE_GSSAPI' \
2792 '-lgss' ||\
2793 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2794 '#define HAVE_GSSAPI
2795 #define GSSAPI_OLD_STYLE' \
2796 '-lgssapi_krb5' << \!
2797 #include <gssapi/gssapi.h>
2798 #include <gssapi/gssapi_generic.h>
2799 int main(void){
2800 gss_import_name(0, 0, gss_nt_service_name, 0);
2801 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2802 return 0;
2805 then
2807 else
2808 feat_bail_required GSSAPI
2810 else
2811 feat_is_disabled GSSAPI
2812 fi # feat_yes GSSAPI
2814 feat_def NETRC
2815 feat_def AGENT
2817 if feat_yes IDNA; then # {{{
2818 if val_allof VAL_IDNA "idnkit,idn2,idn"; then
2820 else
2821 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2822 config_exit 1
2825 val_idna_idn2() {
2826 link_check idna 'OPT_IDNA: GNU Libidn2' \
2827 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2828 #include <idn2.h>
2829 int main(void){
2830 char *idna_utf8, *idna_lc;
2832 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2833 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2834 return 1;
2835 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2836 return 1;
2837 idn2_free(idna_lc);
2838 idn2_free(idna_utf8);
2839 return 0;
2844 val_idna_idn() {
2845 link_check idna 'OPT_IDNA: GNU Libidn' \
2846 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2847 #include <idna.h>
2848 #include <idn-free.h>
2849 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2850 int main(void){
2851 char *utf8, *idna_ascii, *idna_utf8;
2853 utf8 = stringprep_locale_to_utf8("does.this.work");
2854 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2855 != IDNA_SUCCESS)
2856 return 1;
2857 idn_free(idna_ascii);
2858 /* (Rather link check only here) */
2859 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2860 return 0;
2865 val_idna_idnkit() {
2866 link_check idna 'OPT_IDNA: idnkit' \
2867 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2868 #include <stdio.h>
2869 #include <idn/api.h>
2870 #include <idn/result.h>
2871 int main(void){
2872 idn_result_t r;
2873 char ace_name[256];
2874 char local_name[256];
2876 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2877 sizeof(ace_name));
2878 if (r != idn_success) {
2879 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2880 return 1;
2882 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2883 if (r != idn_success) {
2884 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2885 return 1;
2887 return 0;
2892 val_idna_bye() {
2893 feat_bail_required IDNA
2896 oifs=${IFS}
2897 IFS=", "
2898 VAL_IDNA="${VAL_IDNA},bye"
2899 set -- ${VAL_IDNA}
2900 IFS=${oifs}
2901 for randfun
2903 eval val_idna_$randfun && break
2904 done
2905 else
2906 feat_is_disabled IDNA
2907 fi # }}} IDNA
2909 feat_def IMAP_SEARCH
2911 if feat_yes REGEX; then
2912 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2913 #include <regex.h>
2914 #include <stdlib.h>
2915 int main(void){
2916 size_t xret;
2917 int status;
2918 regex_t re;
2920 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2921 xret = regerror(status, &re, NULL, 0);
2922 status = regexec(&re, "plan9", 0,NULL, 0);
2923 regfree(&re);
2924 return !(status == REG_NOMATCH);
2927 then
2929 else
2930 feat_bail_required REGEX
2932 else
2933 feat_is_disabled REGEX
2936 if feat_yes MLE; then
2937 if [ -n "${have_c90amend1}" ]; then
2938 have_mle=1
2939 echo '#define HAVE_MLE' >> ${h}
2940 else
2941 feat_bail_required MLE
2943 else
2944 feat_is_disabled MLE
2947 # Generic have-a-line-editor switch for those who need it below
2948 if [ -n "${have_mle}" ]; then
2949 have_cle=1
2952 if feat_yes HISTORY; then
2953 if [ -n "${have_cle}" ]; then
2954 echo '#define HAVE_HISTORY' >> ${h}
2955 else
2956 feat_is_unsupported HISTORY
2958 else
2959 feat_is_disabled HISTORY
2962 if feat_yes KEY_BINDINGS; then
2963 if [ -n "${have_mle}" ]; then
2964 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2965 else
2966 feat_is_unsupported KEY_BINDINGS
2968 else
2969 feat_is_disabled KEY_BINDINGS
2972 if feat_yes TERMCAP; then
2973 __termcaplib() {
2974 link_check termcap "termcap(5) (via ${4})" \
2975 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2976 #include <stdio.h>
2977 #include <stdlib.h>
2978 ${2}
2979 #include <term.h>
2980 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2981 static int my_putc(int c){return putchar(c);}
2982 int main(void){
2983 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2984 int r2 = OK, r3 = ERR;
2986 tgetent(buf, getenv("TERM"));
2987 cpb = cmdbuf;
2988 r1 = tgetstr(UNCONST("cm"), &cpb);
2989 tgoto(r1, 1, 1);
2990 r2 = tgetnum(UNCONST("Co"));
2991 r3 = tgetflag(UNCONST("ut"));
2992 tputs("cr", 1, &my_putc);
2993 return (r1 == NULL || r2 == -1 || r3 == 0);
2995 _EOT
2998 __terminfolib() {
2999 link_check terminfo "terminfo(5) (via ${2})" \
3000 '#define HAVE_TERMCAP
3001 #define HAVE_TERMCAP_CURSES
3002 #define HAVE_TERMINFO' "${1}" << _EOT
3003 #include <stdio.h>
3004 #include <curses.h>
3005 #include <term.h>
3006 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3007 static int my_putc(int c){return putchar(c);}
3008 int main(void){
3009 int er, r0, r1, r2;
3010 char *r3, *tp;
3012 er = OK;
3013 r0 = setupterm(NULL, 1, &er);
3014 r1 = tigetflag(UNCONST("bce"));
3015 r2 = tigetnum(UNCONST("colors"));
3016 r3 = tigetstr(UNCONST("cr"));
3017 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3018 tputs(tp, 1, &my_putc);
3019 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3020 r3 == (char*)-1 || r3 == NULL);
3022 _EOT
3025 if feat_yes TERMCAP_VIA_TERMINFO; then
3026 __terminfolib -ltinfo -ltinfo ||
3027 __terminfolib -lcurses -lcurses ||
3028 __terminfolib -lcursesw -lcursesw ||
3029 feat_bail_required TERMCAP_VIA_TERMINFO
3032 if [ -z "${have_terminfo}" ]; then
3033 __termcaplib -ltermcap '' '' '-ltermcap' ||
3034 __termcaplib -ltermcap '#include <curses.h>' '
3035 #define HAVE_TERMCAP_CURSES' \
3036 'curses.h / -ltermcap' ||
3037 __termcaplib -lcurses '#include <curses.h>' '
3038 #define HAVE_TERMCAP_CURSES' \
3039 'curses.h / -lcurses' ||
3040 __termcaplib -lcursesw '#include <curses.h>' '
3041 #define HAVE_TERMCAP_CURSES' \
3042 'curses.h / -lcursesw' ||
3043 feat_bail_required TERMCAP
3045 if [ -n "${have_termcap}" ]; then
3046 run_check tgetent_null \
3047 "tgetent(3) of termcap(5) takes NULL buffer" \
3048 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3049 #include <stdio.h> /* For C89 NULL */
3050 #include <stdlib.h>
3051 #ifdef HAVE_TERMCAP_CURSES
3052 # include <curses.h>
3053 #endif
3054 #include <term.h>
3055 int main(void){
3056 tgetent(NULL, getenv("TERM"));
3057 return 0;
3059 _EOT
3062 else
3063 feat_is_disabled TERMCAP
3064 feat_is_disabled TERMCAP_VIA_TERMINFO
3067 if feat_def SPAM_SPAMC; then
3068 if acmd_set i spamc; then
3069 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3073 if feat_yes SPAM_SPAMD; then
3074 if [ -n "${have_af_unix}" ]; then
3075 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3076 else
3077 feat_bail_required SPAM_SPAMD
3079 else
3080 feat_is_disabled SPAM_SPAMD
3083 feat_def SPAM_FILTER
3085 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3086 echo '#define HAVE_SPAM' >> ${h}
3087 else
3088 echo '/* HAVE_SPAM */' >> ${h}
3091 if feat_yes QUOTE_FOLD; then
3092 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3093 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3094 else
3095 feat_bail_required QUOTE_FOLD
3097 else
3098 feat_is_disabled QUOTE_FOLD
3101 feat_def FILTER_HTML_TAGSOUP
3102 feat_def COLOUR
3103 feat_def DOTLOCK
3104 feat_def MD5
3106 ## Summarizing
3108 ${rm} -f ${tmp}
3109 squeeze_em ${inc} ${tmp}
3110 ${mv} ${tmp} ${inc}
3111 squeeze_em ${lib} ${tmp}
3112 ${mv} ${tmp} ${lib}
3114 # mk-config.h
3115 ${mv} ${h} ${tmp}
3116 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3117 ${cat} ${tmp} >> ${h}
3118 printf '\n' >> ${h}
3119 # We need these for correct "second stage configuration changed" detection */
3120 echo "/* `${cat} ${lib}` */" >> ${h}
3121 echo "/* `${cat} ${inc}` */" >> ${h}
3122 printf '\n' >> ${h}
3124 # Throw away all temporaries
3125 ${rm} -rf ${tmp0}.* ${tmp0}*
3127 # Create the string that is used by *features* and `version'.
3128 # Take this nice opportunity and generate a visual listing of included and
3129 # non-included features for the person who runs the configuration
3130 echo 'The following features are included (+) or not (-):' > ${tmp}
3131 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3132 printf '/* The "feature string" */\n' >> ${h}
3133 # Because + is expanded by *folder* if first in "echo $features", put something
3134 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3135 sep=
3136 for opt
3138 sdoc=`option_doc_of ${opt}`
3139 [ -z "${sdoc}" ] && continue
3140 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3141 feat_yes ${opt} && sign=+ || sign=-
3142 printf -- "${sep}${sign}${sopt}" >> ${h}
3143 sep=','
3144 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3145 done
3146 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3147 #exec 5>&1 >>${h}
3148 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3149 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3150 printf '"\n' >> ${h}
3152 # Create the real mk-config.mk
3153 # Note we cannout use explicit ./ filename prefix for source and object
3154 # pathnames because of a bug in bmake(1)
3155 srclist= objlist=
3156 if feat_no AMALGAMATION; then
3157 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3158 i=`basename "${i}" .c`
3159 if [ "${i}" = privsep ]; then
3160 continue
3162 objlist="${objlist} ${i}.o"
3163 srclist="${srclist} \$(SRCDIR)${i}.c"
3164 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3165 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3166 done
3167 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3168 else
3169 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3170 "main.o" "main.c" >> ${mk}
3171 srclist=main.c objlist=main.o
3172 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3174 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3175 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3176 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3177 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3178 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3179 i=`basename "${i}"`
3180 if [ "${i}" = main.c ] ||
3181 [ "${i}" = privsep.c ]; then
3182 continue
3184 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3185 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3186 done
3187 echo >> ${mk}
3189 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3191 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3193 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3194 echo "INCS = `${cat} ${inc}`" >> ${mk}
3195 echo >> ${mk}
3196 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3198 ## Finished!
3200 # We have completed the new configuration header. Check whether *really*
3201 # Do the "second stage configuration changed" detection, exit if nothing to do
3202 if [ -f ${oldh} ]; then
3203 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3204 ${mv} -f ${oldh} ${h}
3205 msg 'Effective configuration is up-to-date'
3206 exit 0
3208 config_updated=1
3209 ${rm} -f ${oldh}
3210 msg 'Effective configuration has been updated..'
3213 if [ -n "${config_updated}" ]; then
3214 msg 'Wiping away old objects and such'
3215 ( eval "${MAKE} -f ${oldmk} clean" )
3218 msg ''
3219 while read l; do msg "${l}"; done < ${tmp}
3221 msg 'Setup:'
3222 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3223 msg ' . bindir: %s' "${VAL_BINDIR}"
3224 if feat_yes DOTLOCK; then
3225 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3227 msg ' . mandir: %s' "${VAL_MANDIR}"
3228 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3229 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3231 msg ''
3232 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3233 exit 0
3235 msg 'Remarks:'
3236 if [ -z "${have_fnmatch}" ]; then
3237 msg ' . The function fnmatch(3) could not be found.'
3238 msg ' Filename patterns like wildcard are not supported on your system'
3240 if [ -z "${have_fchdir}" ]; then
3241 msg ' . The function fchdir(2) could not be found.'
3242 msg ' We will use chdir(2) instead.'
3243 msg ' This is a problem only if the current working directory is changed'
3244 msg ' while this program is inside of it'
3246 msg ''
3248 # s-it-mode