n_idna_to_ascii(): add support for idnkit 2.3
[s-mailx.git] / make-config.sh
bloba6c54922bbdfcfaccaac10fc48f13f750d9a8bdf
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 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 # The problem is that we don't have any tools we can use right now, so
74 # encapsulate stuff in functions which get called in right order later on
76 option_reset() {
77 set -- ${OPTIONS}
78 for i
80 eval OPT_${i}=0
81 done
84 option_maximal() {
85 set -- ${OPTIONS}
86 for i
88 eval OPT_${i}=1
89 done
90 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
93 option_setup() {
94 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
95 option_parse OPTIONS "${XOPTIONS}"
96 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
97 OPT_MIME=1
99 # Predefined CONFIG= urations take precedence over anything else
100 if [ -n "${CONFIG}" ]; then
101 option_reset
102 case "${CONFIG}" in
103 [nN][uU][lL][lL])
105 [nN][uU][lL][lL][iI])
106 OPT_ICONV=require
107 OPT_UISTRINGS=1
109 [mM][iI][nN][iI][mM][aA][lL])
110 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
111 OPT_COLOUR=1
112 OPT_DOCSTRINGS=1
113 OPT_UISTRINGS=1
114 OPT_ERRORS=1
115 OPT_IDNA=1
116 OPT_MLE=1
117 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
118 OPT_SPAM_FILTER=1
120 [nN][eE][tT][sS][eE][nN][dD])
121 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
122 OPT_SOCKETS=require
123 OPT_SSL=require
124 OPT_SMTP=require
125 OPT_GSSAPI=1 OPT_NETRC=1
126 OPT_AGENT=1
127 OPT_COLOUR=1
128 OPT_DOCSTRINGS=1
129 OPT_UISTRINGS=1
130 OPT_ERRORS=1
131 OPT_IDNA=1
132 OPT_MLE=1
133 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
134 OPT_SPAM_FILTER=1
136 [mM][aA][xX][iI][mM][aA][lL])
137 option_maximal
139 [dD][eE][vV][eE][lL])
140 option_maximal
141 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
143 [oO][dD][eE][vV][eE][lL])
144 option_maximal
145 OPT_DEVEL=1
148 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
149 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
150 exit 1
152 esac
153 msg_nonl "CONFIG=${CONFIG} ... "
157 # Inter-relationships XXX sort this!
158 option_update() {
159 if feat_no SSL; then
160 OPT_SSL_ALL_ALGORITHMS=0
163 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
164 OPT_SOCKETS=0
166 if feat_no SOCKETS; then
167 if feat_require SMTP; then
168 msg 'ERROR: need SOCKETS for required feature SMTP'
169 config_exit 13
171 if feat_require POP3; then
172 msg 'ERROR: need SOCKETS for required feature POP3'
173 config_exit 13
175 if feat_require IMAP; then
176 msg 'ERROR: need SOCKETS for required feature IMAP'
177 config_exit 13
179 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
180 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
181 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
183 if feat_no SMTP && feat_no IMAP; then
184 OPT_GSSAPI=0
187 if feat_no ICONV; then
188 if feat_yes IMAP; then
189 if feat_yes ALWAYS_UNICODE_LOCALE; then
190 msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
191 elif feat_require IMAP; then
192 msg 'ERROR: need ICONV for required feature IMAP'
193 config_exit 13
194 else
195 msg 'ERROR: disabling IMAP due to missing ICONV'
196 OPT_IMAP=0
200 if feat_yes IDNA; then
201 if feat_require IDNA; then
202 msg 'ERROR: need ICONV for required feature IDNA'
203 config_exit 13
205 msg 'ERROR: disabling IDNA due to missing ICONV'
206 OPT_IDNA=0
210 if feat_no MLE; then
211 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
214 # If we don't need MD5 leave it alone
215 if feat_no SOCKETS; then
216 OPT_MD5=0
219 if feat_no TERMCAP; then
220 OPT_TERMCAP_VIA_TERMINFO=0
223 if feat_yes DEVEL; then
224 OPT_DEBUG=1
228 rc=./make.rc
229 lst=./mk-config.lst
230 ev=./mk-config.ev
231 h=./mk-config.h h_name=mk-config.h
232 mk=./mk-config.mk
234 newlst=./mk-nconfig.lst
235 newmk=./mk-nconfig.mk
236 newev=./mk-nconfig.ev
237 newh=./mk-nconfig.h
238 tmp0=___tmp
239 tmp=./${tmp0}1$$
240 tmp2=./${tmp0}2$$
242 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
244 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
245 # via path_check() later on once possible
247 # TODO cc_maxopt is brute simple, we should compile test program and dig real
248 # compiler versions for known compilers, then be more specific
249 [ -n "${cc_maxopt}" ] || cc_maxopt=100
250 #cc_force_no_stackprot=
251 #ld_need_R_flags=
252 #ld_no_bind_now=
253 #ld_rpath_not_runpath=
255 _CFLAGS= _LDFLAGS=
257 os_early_setup() {
258 [ -n "${OS}" ] && [ -n "${OSENV}" ] && [ -n "${OSFULLSPEC}" ] ||
259 thecmd_testandset_fail uname uname
261 # We don't "have any utility": only path adjustments and such in here!
262 [ -n "${OS}" ] || OS=`${uname} -s`
263 export OS
265 if [ ${OS} = SunOS ]; then
266 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
267 _os_early_setup_sunos
271 _os_early_setup_sunos() {
272 # According to standards(5), this is what we need to do
273 if [ -d /usr/xpg4 ]; then :; else
274 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
275 config_exit 1
277 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
278 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
279 export PATH
282 os_setup() {
283 # OSENV ends up in *build-osenv*
284 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
285 # etc.), it is not baked into the binary
286 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
287 [ -n "${OSENV}" ] || OSENV=`${uname} -sm`
288 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
289 msg 'Operating system is %s' ${OS}
291 if [ ${OS} = darwin ]; then
292 msg ' . have special Darwin environmental addons...'
293 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
294 elif [ ${OS} = sunos ]; then
295 msg ' . have special SunOS / Solaris "setup" rules ...'
296 _os_setup_sunos
297 elif [ ${OS} = unixware ]; then
298 if feat_yes AUTOCC && acmd_set CC cc; then
299 msg ' . have special UnixWare environmental rules ...'
300 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
302 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
303 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
304 export CC CFLAGS LDFLAGS
305 OPT_AUTOCC=0 ld_need_R_flags=-R
307 elif [ -n "${VERBOSE}" ]; then
308 msg ' . no special treatment for this system necessary or known'
311 # Sledgehammer: better set _GNU_SOURCE
312 # And in general: oh, boy!
313 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
314 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
315 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
316 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
318 # On pkgsrc(7) systems automatically add /usr/pkg/*
319 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
320 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
321 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
322 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
323 ld_rpath_not_runpath=1
327 _os_setup_sunos() {
328 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
329 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
331 # Include packages
332 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
333 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
334 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
335 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
336 ld_no_bind_now=1 ld_rpath_not_runpath=1
338 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
339 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
340 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
341 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
342 ld_no_bind_now=1 ld_rpath_not_runpath=1
345 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
346 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
348 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
349 if [ -x "${cksum}" ]; then :; else
350 msg 'ERROR: Not an executable program: %s' "${cksum}"
351 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
352 msg 'ERROR: However, we do so only for tests.'
353 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
354 config_exit 1
357 if feat_yes AUTOCC; then
358 if acmd_set CC cc; then
359 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
361 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
362 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
363 export CC CFLAGS LDFLAGS
364 OPT_AUTOCC=0 ld_need_R_flags=-R
365 else
366 cc_maxopt=2 cc_force_no_stackprot=1
371 # Check out compiler ($CC) and -flags ($CFLAGS)
372 cc_setup() {
373 # Even though it belongs into cc_flags we will try to compile and link
374 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
375 # EXTRA_CFLAGS/EXTRA_LDFLAGS
376 if feat_no AUTOCC; then
377 _cc_default
378 # Ensure those don't do any harm
379 EXTRA_CFLAGS= EXTRA_LDFLAGS=
380 export EXTRA_CFLAGS EXTRA_LDFLAGS
381 return
382 else
383 CFLAGS= LDFLAGS=
384 export CFLAGS LDFLAGS
387 [ -n "${CC}" ] && { _cc_default; return; }
389 msg_nonl 'Searching for a usable C compiler .. $CC='
390 if acmd_set CC clang || acmd_set CC gcc ||
391 acmd_set CC tcc || acmd_set CC pcc ||
392 acmd_set CC c89 || acmd_set CC c99; then
394 else
395 msg 'boing booom tschak'
396 msg 'ERROR: I cannot find a compiler!'
397 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
398 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
399 config_exit 1
401 msg '%s' "${CC}"
402 export CC
405 _cc_default() {
406 if [ -z "${CC}" ]; then
407 msg 'To go on like you have chosen, please set $CC, rerun.'
408 config_exit 1
411 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
413 else
414 msg 'Using C compiler ${CC}=%s' "${CC}"
418 cc_flags() {
419 if feat_yes AUTOCC; then
420 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
421 cc_check_silent=1
422 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
423 "${CC}"
424 else
425 cc_check_silent=
426 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
429 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
430 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
431 msg ' . have special tcc(1) environmental rules ...'
432 _cc_flags_tcc
433 else
434 # As of pcc CVS 2016-04-02, stack protection support is announced but
435 # will break if used on Linux
436 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
437 cc_force_no_stackprot=1
439 _cc_flags_generic
442 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
443 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
444 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
445 else
446 if feat_no DEBUG; then
447 CFLAGS="-DNDEBUG ${CFLAGS}"
450 msg ''
451 export CFLAGS LDFLAGS
454 _cc_flags_tcc() {
455 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
456 _CFLAGS= _LDFLAGS=
458 cc_check -Wall
459 cc_check -Wextra
460 cc_check -pedantic
462 if feat_yes DEBUG; then
463 # May have problems to find libtcc cc_check -b
464 cc_check -g
467 if ld_check -Wl,-rpath =./ no; then
468 ld_need_R_flags=-Wl,-rpath=
469 if [ -z "${ld_rpath_not_runpath}" ]; then
470 ld_check -Wl,--enable-new-dtags
471 else
472 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
474 ld_runtime_flags # update!
477 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
478 unset __cflags __ldflags
481 _cc_flags_generic() {
482 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
483 _CFLAGS= _LDFLAGS=
484 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
486 # E.g., valgrind does not work well with high optimization
487 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
488 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
489 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
490 cc_maxopt=1
492 # Check -g first since some others may rely upon -g / optim. level
493 if feat_yes DEBUG; then
494 cc_check -O
495 cc_check -g
496 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
498 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
500 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
502 else
503 cc_check -O
506 if feat_yes AMALGAMATION; then
507 cc_check -pipe
510 #if feat_yes DEVEL && cc_check -Weverything; then
512 #else
513 cc_check -Wall
514 cc_check -Wextra
515 cc_check -Wbad-function-cast
516 cc_check -Wcast-align
517 cc_check -Wcast-qual
518 cc_check -Winit-self
519 cc_check -Wmissing-prototypes
520 cc_check -Wshadow
521 cc_check -Wunused
522 cc_check -Wwrite-strings
523 cc_check -Wno-long-long
525 cc_check -pedantic
527 if feat_yes AMALGAMATION && feat_no DEVEL; then
528 cc_check -Wno-unused-function
530 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
532 cc_check -fno-unwind-tables
533 cc_check -fno-asynchronous-unwind-tables
534 cc_check -fstrict-aliasing
535 if cc_check -fstrict-overflow && feat_yes DEVEL; then
536 cc_check -Wstrict-overflow=5
539 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
540 if [ -z "${cc_force_no_stackprot}" ]; then
541 if cc_check -fstack-protector-strong ||
542 cc_check -fstack-protector-all; then
543 cc_check -D_FORTIFY_SOURCE=2
545 else
546 msg ' ! Not checking for -fstack-protector compiler option,'
547 msg ' ! since that caused errors in a "similar" configuration.'
548 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
552 # LD (+ dependend CC)
554 if feat_yes ASAN_ADDRESS; then
555 _ccfg=${_CFLAGS}
556 if cc_check -fsanitize=address &&
557 ld_check -fsanitize=address; then
559 else
560 feat_bail_required ASAN_ADDRESS
561 _CFLAGS=${_ccfg}
565 if feat_yes ASAN_MEMORY; then
566 _ccfg=${_CFLAGS}
567 if cc_check -fsanitize=memory &&
568 ld_check -fsanitize=memory &&
569 cc_check -fsanitize-memory-track-origins=2 &&
570 ld_check -fsanitize-memory-track-origins=2; then
572 else
573 feat_bail_required ASAN_MEMORY
574 _CFLAGS=${_ccfg}
578 ld_check -Wl,-z,relro
579 if [ -z "${ld_no_bind_now}" ]; then
580 ld_check -Wl,-z,now
581 else
582 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
584 ld_check -Wl,-z,noexecstack
585 if ld_check -Wl,-rpath =./ no; then
586 ld_need_R_flags=-Wl,-rpath=
587 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
588 if [ -z "${ld_rpath_not_runpath}" ]; then
589 ld_check -Wl,--enable-new-dtags
590 else
591 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
593 ld_runtime_flags # update!
594 elif ld_check -Wl,-R ./ no; then
595 ld_need_R_flags=-Wl,-R
596 if [ -z "${ld_rpath_not_runpath}" ]; then
597 ld_check -Wl,--enable-new-dtags
598 else
599 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
601 ld_runtime_flags # update!
604 # Address randomization
605 _ccfg=${_CFLAGS}
606 if cc_check -fPIE || cc_check -fpie; then
607 ld_check -pie || _CFLAGS=${_ccfg}
609 unset _ccfg
611 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
612 unset __cflags __ldflags
615 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
617 ## Notes:
618 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
619 ## redirection, so use "printf '' >" instead
621 ## Very first: we undergo several states regarding I/O redirection etc.,
622 ## but need to deal with option updates from within all. Since all the
623 ## option stuff should be above the scissor line, define utility functions
624 ## and redefine them as necessary.
625 ## And, since we have those functions, simply use them for whatever
627 t1=ten10one1ten10one1
628 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
629 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
630 ) > /dev/null 2>&1; then
631 good_shell=1
632 else
633 unset good_shell
635 unset t1
637 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
639 config_exit() {
640 exit ${1}
643 # which(1) not standardized, command(1) -v may return non-executable: unroll!
644 acmd_test() { __acmd "${1}" 1 0 0; }
645 acmd_test_fail() { __acmd "${1}" 1 1 0; }
646 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
647 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
648 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
649 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
650 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
651 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
652 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
653 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
654 __acmd() {
655 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
657 if [ "${dotest}" -ne 0 ]; then
658 eval dotest=\$${varname}
659 if [ -n "${dotest}" ]; then
660 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
661 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
662 return 0
666 oifs=${IFS} IFS=:
667 [ -n "${noglob_shell}" ] && set -o noglob
668 set -- ${PATH}
669 [ -n "${noglob_shell}" ] && set +o noglob
670 IFS=${oifs}
671 for path
673 if [ -z "${path}" ] || [ "${path}" = . ]; then
674 if [ -d "${PWD}" ]; then
675 path=${PWD}
676 else
677 path=.
680 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
681 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
682 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
683 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
684 return 0
686 done
688 # We may have no builtin string functions, we yet have no programs we can
689 # use, try to access once from the root, assuming it is an absolute path if
690 # that finds the executable
691 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
692 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
693 msg ' . ${%s} ... %s' "${pname}" "${pname}"
694 [ -n "${varname}" ] && eval ${varname}="${pname}"
695 return 0
698 [ ${dofail} -eq 0 ] && return 1
699 msg 'ERROR: no trace of utility '"${pname}"
700 exit 1
703 msg() {
704 fmt=${1}
705 shift
706 printf >&2 -- "${fmt}\\n" "${@}"
709 msg_nonl() {
710 fmt=${1}
711 shift
712 printf >&2 -- "${fmt}" "${@}"
715 # Our feature check environment
716 feat_val_no() {
717 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
718 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
721 feat_val_yes() {
722 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
723 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
724 [ "x${1}" = xrequire ]
727 feat_val_require() {
728 [ "x${1}" = xrequire ]
731 _feat_check() {
732 eval i=\$OPT_${1}
733 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
734 if feat_val_no "${i}"; then
735 return 1
736 elif feat_val_yes "${i}"; then
737 return 0
738 else
739 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
740 "${1}" "${i}"
741 config_exit 11
745 feat_yes() {
746 _feat_check ${1}
749 feat_no() {
750 _feat_check ${1} && return 1
751 return 0
754 feat_require() {
755 eval i=\$OPT_${1}
756 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
757 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
760 feat_bail_required() {
761 if feat_require ${1}; then
762 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
763 config_exit 13
765 feat_is_unsupported "${1}"
768 feat_is_disabled() {
769 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
770 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
773 feat_is_unsupported() {
774 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
775 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
776 eval OPT_${1}=0
777 option_update # XXX this is rather useless here (dependency chain..)
780 feat_def() {
781 if feat_yes ${1}; then
782 echo '#define HAVE_'${1}'' >> ${h}
783 return 0
784 else
785 feat_is_disabled "${@}"
786 return 1
790 option_parse() {
791 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
792 # options, without documentation, to $1
793 j=\'
794 i="`${awk} -v input=\"${2}\" '
795 BEGIN{
796 for(i = 0;;){
797 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
798 if(voff == 0)
799 break
800 v = substr(input, voff, RLENGTH)
801 input = substr(input, voff + RLENGTH)
802 doff = index(v, "=")
803 if(doff > 0){
804 d = substr(v, doff + 2, length(v) - doff - 1)
805 v = substr(v, 1, doff - 1)
807 print v
811 eval ${1}=\"${i}\"
814 option_doc_of() {
815 # Return the "documentation string" for option $1, itself if none such
816 j=\'
817 ${awk} -v want="${1}" \
818 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
819 BEGIN{
820 for(;;){
821 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
822 if(voff == 0)
823 break
824 v = substr(input, voff, RLENGTH)
825 input = substr(input, voff + RLENGTH)
826 doff = index(v, "=")
827 if(doff > 0){
828 d = substr(v, doff + 2, length(v) - doff - 1)
829 v = substr(v, 1, doff - 1)
830 }else
831 d = v
832 if(v == want){
833 if(d != "-")
834 print d
835 exit
842 option_join_rc() {
843 # Join the values from make.rc into what currently is defined, not
844 # overwriting yet existing settings
845 ${rm} -f ${tmp}
846 # We want read(1) to perform reverse solidus escaping in order to be able to
847 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
848 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
849 < ${rc} ${awk} 'BEGIN{line = ""}{
850 gsub(/^[[:space:]]+/, "", $0)
851 gsub(/[[:space:]]+$/, "", $0)
852 if(gsub(/\\$/, "", $0)){
853 line = line $0
854 next
855 }else
856 line = line $0
857 if(index(line, "#") == 1){
858 line = ""
859 }else if(length(line)){
860 print line
861 line = ""
863 }' |
864 while read line; do
865 if [ -n "${good_shell}" ]; then
866 i=${line%%=*}
867 else
868 i=`${awk} -v LINE="${line}" 'BEGIN{
869 gsub(/=.*$/, "", LINE)
870 print LINE
873 if [ "${i}" = "${line}" ]; then
874 msg 'ERROR: invalid syntax in: %s' "${line}"
875 continue
878 eval j="\$${i}" jx="\${${i}+x}"
879 if [ -n "${j}" ] || [ "${jx}" = x ]; then
880 : # Yet present
881 else
882 j=`${awk} -v LINE="${line}" 'BEGIN{
883 gsub(/^[^=]*=/, "", LINE)
884 gsub(/^\"*/, "", LINE)
885 gsub(/\"*$/, "", LINE)
886 print LINE
889 [ "${i}" = "DESTDIR" ] && continue
890 echo "${i}=\"${j}\""
891 done > ${tmp}
892 # Reread the mixed version right now
893 . ./${tmp}
896 option_evaluate() {
897 # Expand the option values, which may contain shell snippets
898 ${rm} -f ${newlst} ${newmk} ${newh}
899 exec 5<&0 6>&1 <${tmp} >${newlst}
900 while read line; do
902 if [ -n "${good_shell}" ]; then
903 i=${line%%=*}
904 [ "${i}" != "${i#OPT_}" ] && z=1
905 else
906 i=`${awk} -v LINE="${line}" 'BEGIN{
907 gsub(/=.*$/, "", LINE);\
908 print LINE
910 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
915 eval j=\$${i}
916 if [ -n "${z}" ]; then
917 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
918 if [ -z "${j}" ] || feat_val_no "${j}"; then
920 printf " /* #undef ${i} */\n" >> ${newh}
921 elif feat_val_yes "${j}"; then
922 if feat_val_require "${j}"; then
923 j=require
924 else
927 printf " /* #define ${i} */\n" >> ${newh}
928 else
929 msg 'ERROR: cannot parse <%s>' "${line}"
930 config_exit 1
932 else
933 printf "#define ${i} \"${j}\"\n" >> ${newh}
935 printf "${i} = ${j}\n" >> ${newmk}
936 printf "${i}=${j}\n"
937 eval "${i}=\"${j}\""
938 done
939 exec 0<&5 1>&6 5<&- 6<&-
942 val_allof() {
943 eval __expo__=\$${1}
944 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
945 BEGIN{
946 i = split(HEAP, ha)
947 if((j = split(USER, ua)) == 0)
948 exit
949 for(; j != 0; --j){
950 us = tolower(ua[j])
951 if(us == "all" || us == "any")
952 continue
953 ok = 0
954 for(ii = i; ii != 0; --ii)
955 if(tolower(ha[ii]) == us){
956 ok = 1
957 break
959 if(!ok)
960 exit 1
964 __rv__=${?}
965 [ ${__rv__} -ne 0 ] && return ${__rv__}
967 if ${awk} -v USER="${__expo__}" '
968 BEGIN{
969 if((j = split(USER, ua)) == 0)
970 exit
971 for(; j != 0; --j){
972 us = tolower(ua[j])
973 if(us == "all" || us == "any")
974 exit 0
976 exit 1
978 '; then
979 eval "${1}"=\"${2}\"
981 return 0
984 path_check() {
985 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
986 varname=${1} addflag=${2} flagvarname=${3}
987 j=${IFS}
988 IFS=:
989 [ -n "${noglob_shell}" ] && set -o noglob
990 eval "set -- \$${1}"
991 [ -n "${noglob_shell}" ] && set +o noglob
992 IFS=${j}
993 j= k= y= z=
994 for i
996 [ -z "${i}" ] && continue
997 [ -d "${i}" ] || continue
998 if [ -n "${j}" ]; then
999 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1001 else
1002 y="${y} :${i}:"
1003 j="${j}:${i}"
1004 # But do not link any fakeroot path into our binaries!
1005 if [ -n "${addflag}" ]; then
1006 case "${i}" in *fakeroot*) continue;; esac
1007 k="${k} ${addflag}${i}"
1010 else
1011 y=" :${i}:"
1012 j="${i}"
1013 # But do not link any fakeroot path into our binaries!
1014 if [ -n "${addflag}" ]; then
1015 case "${i}" in *fakeroot*) continue;; esac
1016 k="${k} ${addflag}${i}"
1019 done
1020 eval "${varname}=\"${j}\""
1021 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1022 unset varname
1025 ld_runtime_flags() {
1026 if [ -n "${ld_need_R_flags}" ]; then
1027 i=${IFS}
1028 IFS=:
1029 set -- ${LD_LIBRARY_PATH}
1030 IFS=${i}
1031 for i
1033 # But do not link any fakeroot path into our binaries!
1034 case "${i}" in *fakeroot*) continue;; esac
1035 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1036 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1037 done
1038 export LDFLAGS
1040 # Disable it for a possible second run.
1041 ld_need_R_flags=
1044 cc_check() {
1045 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1046 if "${CC}" ${INCS} \
1047 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1048 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1049 _CFLAGS="${_CFLAGS} ${1}"
1050 [ -n "${cc_check_silent}" ] || msg 'yes'
1051 return 0
1053 [ -n "${cc_check_silent}" ] || msg 'no'
1054 return 1
1057 ld_check() {
1058 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1059 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1060 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1061 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1062 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1063 [ -n "${cc_check_silent}" ] || msg 'yes'
1064 return 0
1066 [ -n "${cc_check_silent}" ] || msg 'no'
1067 return 1
1070 dump_test_program=1
1071 _check_preface() {
1072 variable=$1 topic=$2 define=$3
1074 echo '**********'
1075 msg_nonl ' . %s ... ' "${topic}"
1076 echo "/* checked ${topic} */" >> ${h}
1077 ${rm} -f ${tmp} ${tmp}.o
1078 if [ "${dump_test_program}" = 1 ]; then
1079 echo '*** test program is'
1080 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1081 else
1082 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1084 #echo '*** the preprocessor generates'
1085 #${make} -f ${makefile} ${tmp}.x
1086 #${cat} ${tmp}.x
1087 echo '*** tests results'
1090 without_check() {
1091 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1093 echo '**********'
1094 msg_nonl ' . %s ... ' "${topic}"
1096 echo '*** enforced unchecked results are'
1097 if feat_val_yes ${yesno}; then
1098 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1099 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1100 LIBS="${LIBS} ${libs}"
1101 echo "${libs}" >> ${lib}
1102 INCS="${INCS} ${incs}"
1103 echo "${incs}" >> ${inc}
1105 msg 'yes (deduced)'
1106 echo "${define}" >> ${h}
1107 eval have_${variable}=yes
1108 return 0
1109 else
1110 echo "/* ${define} */" >> ${h}
1111 msg 'no (deduced)'
1112 eval unset have_${variable}
1113 return 1
1117 compile_check() {
1118 variable=$1 topic=$2 define=$3
1120 _check_preface "${variable}" "${topic}" "${define}"
1122 if ${make} -f ${makefile} XINCS="${INCS}" \
1123 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1124 ./${tmp}.o &&
1125 [ -f ./${tmp}.o ]; then
1126 msg 'yes'
1127 echo "${define}" >> ${h}
1128 eval have_${variable}=yes
1129 return 0
1130 else
1131 echo "/* ${define} */" >> ${h}
1132 msg 'no'
1133 eval unset have_${variable}
1134 return 1
1138 _link_mayrun() {
1139 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1141 _check_preface "${variable}" "${topic}" "${define}"
1143 if feat_yes CROSS_BUILD; then
1144 if [ ${run} = 1 ]; then
1145 run=0
1149 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1150 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1151 XLIBS="${LIBS} ${libs}" \
1152 ./${tmp} &&
1153 [ -f ./${tmp} ] &&
1154 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1155 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1156 msg 'yes'
1157 echo "${define}" >> ${h}
1158 LIBS="${LIBS} ${libs}"
1159 echo "${libs}" >> ${lib}
1160 INCS="${INCS} ${incs}"
1161 echo "${incs}" >> ${inc}
1162 eval have_${variable}=yes
1163 return 0
1164 else
1165 msg 'no'
1166 echo "/* ${define} */" >> ${h}
1167 eval unset have_${variable}
1168 return 1
1172 link_check() {
1173 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1176 run_check() {
1177 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1180 xrun_check() {
1181 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1184 squeeze_em() {
1185 < "${1}" > "${2}" ${awk} \
1186 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1189 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1191 # First of all, create new configuration and check whether it changed
1193 # Very easy checks for the operating system in order to be able to adjust paths
1194 # or similar very basic things which we need to be able to go at all
1195 os_early_setup
1197 # Check those tools right now that we need before including $rc
1198 msg 'Checking for basic utility set'
1199 thecmd_testandset_fail awk awk
1200 thecmd_testandset_fail rm rm
1201 thecmd_testandset_fail tr tr
1203 # Initialize the option set
1204 msg_nonl 'Setting up configuration options ... '
1205 option_setup
1206 msg 'done'
1208 # Include $rc, but only take from it what wasn't overwritten by the user from
1209 # within the command line or from a chosen fixed CONFIG=
1210 # Note we leave alone the values
1211 trap "exit 1" HUP INT TERM
1212 trap "${rm} -f ${tmp}" EXIT
1214 msg_nonl 'Joining in %s ... ' ${rc}
1215 option_join_rc
1216 msg 'done'
1218 # We need to know about that now, in order to provide utility overwrites etc.
1219 os_setup
1221 msg 'Checking for remaining set of utilities'
1222 thecmd_testandset_fail grep grep
1224 # Before we step ahead with the other utilities perform a path cleanup first.
1225 path_check PATH
1227 # awk(1) above
1228 thecmd_testandset_fail basename basename
1229 thecmd_testandset_fail cat cat
1230 thecmd_testandset_fail chmod chmod
1231 thecmd_testandset_fail cp cp
1232 thecmd_testandset_fail cmp cmp
1233 # grep(1) above
1234 thecmd_testandset_fail mkdir mkdir
1235 thecmd_testandset_fail mv mv
1236 # rm(1) above
1237 thecmd_testandset_fail sed sed
1238 thecmd_testandset_fail sort sort
1239 thecmd_testandset_fail tee tee
1240 __PATH=${PATH}
1241 thecmd_testandset chown chown ||
1242 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1243 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1244 PATH=${__PATH}
1245 thecmd_testandset_fail MAKE make
1246 make=${MAKE}
1247 export MAKE
1248 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1250 # For ./cc-test.sh only
1251 thecmd_testandset_fail cksum cksum
1253 # Update OPT_ options now, in order to get possible inter-dependencies right
1254 option_update
1256 # (No functions since some shells loose non-exported variables in traps)
1257 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1258 trap "trap \"\" HUP INT TERM EXIT;\
1259 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1261 # Our configuration options may at this point still contain shell snippets,
1262 # we need to evaluate them in order to get them expanded, and we need those
1263 # evaluated values not only in our new configuration file, but also at hand..
1264 msg_nonl 'Evaluating all configuration items ... '
1265 option_evaluate
1266 msg 'done'
1268 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1269 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1271 # The problem now is that the test should be able to run in the users linker
1272 # and path environment, so we need to place the test: rule first, before
1273 # injecting the relevant make variables. Set up necessary environment
1274 if [ -z "${VERBOSE}" ]; then
1275 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1276 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1277 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1278 printf -- "ECHO_TEST = @\n" >> ${newmk}
1279 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1280 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1281 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1283 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1284 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1286 # Add the known utility and some other variables
1287 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1288 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1289 if feat_yes DOTLOCK; then
1290 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1291 else
1292 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1295 for i in \
1296 SRCDIR \
1297 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1298 MAKE MAKEFLAGS make SHELL strip \
1299 cksum; do
1300 eval j=\$${i}
1301 printf "${i} = ${j}\n" >> ${newmk}
1302 printf "${i}=${j}\n" >> ${newlst}
1303 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1304 done
1305 # Note that makefile reads and eval'uates one line of this file, whereas other
1306 # consumers source it via .(1)
1307 printf "\n" >> ${newev}
1309 # Build a basic set of INCS and LIBS according to user environment.
1310 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1311 path_check C_INCLUDE_PATH -I _INCS
1312 INCS="${INCS} ${_INCS}"
1313 path_check LD_LIBRARY_PATH -L _LIBS
1314 LIBS="${LIBS} ${_LIBS}"
1315 unset _INCS _LIBS
1316 export C_INCLUDE_PATH LD_LIBRARY_PATH
1318 # Some environments need runtime path flags to be able to go at all
1319 ld_runtime_flags
1321 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1323 cc_setup
1325 ${cat} > ${tmp}.c << \!
1326 #include <stdio.h>
1327 #include <string.h>
1328 static void doit(char const *s);
1330 main(int argc, char **argv){
1331 (void)argc;
1332 (void)argv;
1333 doit("Hello world");
1334 return 0;
1336 static void
1337 doit(char const *s){
1338 char buf[12];
1339 memcpy(buf, s, strlen(s) +1);
1340 puts(s);
1344 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1345 -o ${tmp2} ${tmp}.c ${LIBS}; then
1347 else
1348 msg 'ERROR: i cannot compile a "Hello world" via'
1349 msg ' %s' \
1350 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1351 msg 'ERROR: Please read INSTALL, rerun'
1352 config_exit 1
1355 # This may also update ld_runtime_flags() (again)
1356 cc_flags
1358 for i in \
1359 INCS LIBS \
1360 ; do
1361 eval j=\$${i}
1362 printf -- "${i}=${j}\n" >> ${newlst}
1363 done
1364 for i in \
1365 CC \
1366 CFLAGS \
1367 LDFLAGS \
1368 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1369 OSFULLSPEC \
1370 ; do
1371 eval j=\$${i}
1372 if [ -n "${j}" ]; then
1373 printf -- "${i} = ${j}\n" >> ${newmk}
1374 printf -- "${i}=${j}\n" >> ${newlst}
1376 done
1378 # Now finally check whether we already have a configuration and if so, whether
1379 # all those parameters are still the same.. or something has actually changed
1380 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1381 echo 'Configuration is up-to-date'
1382 exit 0
1383 elif [ -f ${lst} ]; then
1384 echo 'Configuration has been updated..'
1385 ( eval "${MAKE} -f ./mk-config.mk clean" )
1386 echo
1387 else
1388 echo 'Shiny configuration..'
1391 # Time to redefine helper 1
1392 config_exit() {
1393 ${rm} -f ${lst} ${h} ${mk}
1394 exit ${1}
1397 ${mv} -f ${newlst} ${lst}
1398 ${mv} -f ${newev} ${ev}
1399 ${mv} -f ${newh} ${h}
1400 ${mv} -f ${newmk} ${mk}
1402 ## Compile and link checking
1404 tmp3=./${tmp0}3$$
1405 log=./mk-config.log
1406 lib=./mk-config.lib
1407 inc=./mk-config.inc
1408 makefile=./${tmp0}.mk
1410 # (No function since some shells loose non-exported variables in traps)
1411 trap "trap \"\" HUP INT TERM;\
1412 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1413 trap "trap \"\" HUP INT TERM EXIT;\
1414 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1416 # Time to redefine helper 2
1417 msg() {
1418 fmt=${1}
1419 shift
1420 printf "*** ${fmt}\\n" "${@}"
1421 printf -- "${fmt}\\n" "${@}" >&5
1423 msg_nonl() {
1424 fmt=${1}
1425 shift
1426 printf "*** ${fmt}\\n" "${@}"
1427 printf -- "${fmt}" "${@}" >&5
1430 # !!
1431 exec 5>&2 > ${log} 2>&1
1433 echo "${LIBS}" > ${lib}
1434 echo "${INCS}" > ${inc}
1435 ${cat} > ${makefile} << \!
1436 .SUFFIXES: .o .c .x .y
1437 .c.o:
1438 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1439 .c.x:
1440 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1442 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1445 ## Generics
1447 # May be multiline..
1448 echo >> ${h}
1449 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1450 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1451 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1453 # Generate n_err_number OS mappings
1454 dump_test_program=0
1456 feat_yes DEVEL && NV= || NV=noverbose
1457 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1458 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1459 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1460 dump_test_program=1
1462 feat_def ALWAYS_UNICODE_LOCALE
1463 feat_def AMALGAMATION 0
1464 feat_def CROSS_BUILD
1465 feat_def DOCSTRINGS
1466 feat_def UISTRINGS
1467 feat_def ERRORS
1469 feat_def ASAN_ADDRESS 0
1470 feat_def ASAN_MEMORY 0
1471 feat_def DEBUG 0
1472 feat_def DEVEL 0
1473 feat_def NYD2 0
1474 feat_def NOMEMDBG 0
1476 if xrun_check inline 'inline functions' \
1477 '#define HAVE_INLINE
1478 #define n_INLINE static inline' << \!
1479 static inline int ilf(int i){return ++i;}
1480 int main(void){return ilf(-1);}
1482 then
1484 elif xrun_check inline 'inline functions (via __inline)' \
1485 '#define HAVE_INLINE
1486 #define n_INLINE static __inline' << \!
1487 static __inline int ilf(int i){return ++i;}
1488 int main(void){return ilf(-1);}
1490 then
1494 ## Test for "basic" system-calls / functionality that is used by all parts
1495 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1496 ## macros to be used by only the subprograms (potentially).
1498 if run_check clock_gettime 'clock_gettime(2)' \
1499 '#define HAVE_CLOCK_GETTIME' << \!
1500 #include <time.h>
1501 # include <errno.h>
1502 int main(void){
1503 struct timespec ts;
1505 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1506 return 0;
1507 return 1;
1510 then
1512 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1513 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1514 #include <time.h>
1515 # include <errno.h>
1516 int main(void){
1517 struct timespec ts;
1519 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1520 return 0;
1521 return 1;
1524 then
1526 elif run_check gettimeofday 'gettimeofday(2)' \
1527 '#define HAVE_GETTIMEOFDAY' << \!
1528 #include <stdio.h> /* For C89 NULL */
1529 #include <sys/time.h>
1530 # include <errno.h>
1531 int main(void){
1532 struct timeval tv;
1534 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1535 return 0;
1536 return 1;
1539 then
1541 else
1542 have_no_subsecond_time=1
1545 if run_check nanosleep 'nanosleep(2)' \
1546 '#define HAVE_NANOSLEEP' << \!
1547 #include <time.h>
1548 # include <errno.h>
1549 int main(void){
1550 struct timespec ts;
1552 ts.tv_sec = 1;
1553 ts.tv_nsec = 100000;
1554 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1555 return 0;
1556 return 1;
1559 then
1561 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1562 '#define HAVE_NANOSLEEP' '-lrt' << \!
1563 #include <time.h>
1564 # include <errno.h>
1565 int main(void){
1566 struct timespec ts;
1568 ts.tv_sec = 1;
1569 ts.tv_nsec = 100000;
1570 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1571 return 0;
1572 return 1;
1575 then
1577 # link_check is enough for this, that function is so old, trust the proto
1578 elif link_check sleep 'sleep(3)' \
1579 '#define HAVE_SLEEP' << \!
1580 #include <unistd.h>
1581 # include <errno.h>
1582 int main(void){
1583 if(!sleep(1) || errno != ENOSYS)
1584 return 0;
1585 return 1;
1588 then
1590 else
1591 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1592 config_exit 1
1595 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1596 #include <pwd.h>
1597 #include <unistd.h>
1598 # include <errno.h>
1599 int main(void){
1600 struct passwd *pw;
1601 gid_t gid;
1602 uid_t uid;
1604 if((gid = getgid()) != 0)
1605 gid = getegid();
1606 if((uid = getuid()) != 0)
1607 uid = geteuid();
1608 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1609 return 1;
1610 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1611 return 1;
1612 return 0;
1615 then
1617 else
1618 msg 'ERROR: we require user and group info / database searches.'
1619 msg 'That much Unix we indulge ourselfs.'
1620 config_exit 1
1623 if link_check ftruncate 'ftruncate(2)' \
1624 '#define HAVE_FTRUNCATE' << \!
1625 #include <unistd.h>
1626 #include <sys/types.h>
1627 int main(void){
1628 return (ftruncate(0, 0) != 0);
1631 then
1633 else
1634 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1635 msg 'ERROR: we require the ftruncate(2) system call.'
1636 config_exit 1
1639 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1640 #include <signal.h>
1641 # include <errno.h>
1642 int main(void){
1643 struct sigaction nact, oact;
1645 nact.sa_handler = SIG_DFL;
1646 sigemptyset(&nact.sa_mask);
1647 nact.sa_flags = SA_RESTART;
1648 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1651 then
1653 else
1654 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1655 config_exit 1
1658 if link_check snprintf 'snprintf(3)' << \!
1659 #include <stdio.h>
1660 int main(void){
1661 char b[20];
1663 snprintf(b, sizeof b, "%s", "string");
1664 return 0;
1667 then
1669 else
1670 msg 'ERROR: we require the snprintf(3) function.'
1671 config_exit 1
1674 if link_check environ 'environ(3)' << \!
1675 #include <stdio.h> /* For C89 NULL */
1676 int main(void){
1677 extern char **environ;
1679 return environ[0] == NULL;
1682 then
1684 else
1685 msg 'ERROR: we require the environ(3) array for subprocess control.'
1686 config_exit 1
1689 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1690 #include <stdlib.h>
1691 int main(void){
1692 setenv("s-mailx", "i want to see it cute!", 1);
1693 unsetenv("s-mailx");
1694 return 0;
1697 then
1699 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1700 #include <stdlib.h>
1701 int main(void){
1702 putenv("s-mailx=i want to see it cute!");
1703 return 0;
1706 then
1708 else
1709 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1710 config_exit 1
1713 if link_check termios 'termios.h and tc*(3) family' << \!
1714 #include <termios.h>
1715 int main(void){
1716 struct termios tios;
1718 tcgetattr(0, &tios);
1719 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1720 return 0;
1723 then
1725 else
1726 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1727 msg 'That much Unix we indulge ourselfs.'
1728 config_exit 1
1731 ## optional stuff
1733 if link_check vsnprintf 'vsnprintf(3)' << \!
1734 #include <stdarg.h>
1735 #include <stdio.h>
1736 static void dome(char *buf, size_t blen, ...){
1737 va_list ap;
1739 va_start(ap, blen);
1740 vsnprintf(buf, blen, "%s", ap);
1741 va_end(ap);
1743 int main(void){
1744 char b[20];
1746 dome(b, sizeof b, "string");
1747 return 0;
1750 then
1752 else
1753 feat_bail_required ERRORS
1756 if [ "${have_vsnprintf}" = yes ]; then
1757 __va_copy() {
1758 link_check va_copy "va_copy(3) (as ${2})" \
1759 "#define HAVE_N_VA_COPY
1760 #define n_va_copy ${2}" <<_EOT
1761 #include <stdarg.h>
1762 #include <stdio.h>
1763 #if ${1}
1764 # if defined __va_copy && !defined va_copy
1765 # define va_copy __va_copy
1766 # endif
1767 #endif
1768 static void dome2(char *buf, size_t blen, va_list src){
1769 va_list ap;
1771 va_copy(ap, src);
1772 vsnprintf(buf, blen, "%s", ap);
1773 va_end(ap);
1775 static void dome(char *buf, size_t blen, ...){
1776 va_list ap;
1778 va_start(ap, blen);
1779 dome2(buf, blen, ap);
1780 va_end(ap);
1782 int main(void){
1783 char b[20];
1785 dome(b, sizeof b, "string");
1786 return 0;
1788 _EOT
1790 __va_copy 0 va_copy || __va_copy 1 __va_copy
1793 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1794 #include <unistd.h>
1795 #include <errno.h>
1796 int main(void){
1797 int rv = 0;
1799 errno = 0;
1800 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1801 errno = 0;
1802 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1804 /* Only link check */
1805 fpathconf(0, _PC_NAME_MAX);
1807 return rv;
1811 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1812 #include <fcntl.h>
1813 #include <unistd.h>
1814 # include <errno.h>
1815 int main(void){
1816 int fds[2];
1818 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1819 return 0;
1820 return 1;
1824 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1825 #include <termios.h>
1826 int main(void){
1827 struct winsize ws;
1829 tcgetwinsize(0, &ws);
1830 return 0;
1834 # We use this only then for now (need NOW+1)
1835 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1836 #include <fcntl.h> /* For AT_* */
1837 #include <sys/stat.h>
1838 # include <errno.h>
1839 int main(void){
1840 struct timespec ts[2];
1842 ts[0].tv_nsec = UTIME_NOW;
1843 ts[1].tv_nsec = UTIME_OMIT;
1844 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1845 return 0;
1846 return 1;
1852 # The random check has been moved to below SSL detection due to multiple choice
1853 # selection for PRG sources
1855 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1856 #include <stdio.h>
1857 int main(void){
1858 putc_unlocked('@', stdout);
1859 return 0;
1863 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1864 #include <unistd.h>
1865 int main(void){
1866 fchdir(0);
1867 return 0;
1871 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1872 #include <stdlib.h>
1873 int main(void){
1874 char x_buf[4096], *x = realpath(".", x_buf);
1876 return (x != NULL) ? 0 : 1;
1879 then
1880 if run_check realpath_malloc 'realpath(3) takes NULL' \
1881 '#define HAVE_REALPATH_NULL' << \!
1882 #include <stdlib.h>
1883 int main(void){
1884 char *x = realpath(".", NULL);
1886 if(x != NULL)
1887 free(x);
1888 return (x != NULL) ? 0 : 1;
1891 then
1897 ## optional and selectable
1900 if feat_yes DOTLOCK; then
1901 if run_check readlink 'readlink(2)' << \!
1902 #include <unistd.h>
1903 # include <errno.h>
1904 int main(void){
1905 char buf[128];
1907 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1908 return 0;
1909 return 1;
1912 then
1914 else
1915 feat_bail_required DOTLOCK
1919 if feat_yes DOTLOCK; then
1920 if run_check fchown 'fchown(2)' << \!
1921 #include <unistd.h>
1922 # include <errno.h>
1923 int main(void){
1924 if(!fchown(0, 0, 0) || errno != ENOSYS)
1925 return 0;
1926 return 1;
1929 then
1931 else
1932 feat_bail_required DOTLOCK
1936 if feat_yes DOTLOCK; then
1937 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1938 '#define HAVE_PRCTL_DUMPABLE' << \!
1939 #include <sys/prctl.h>
1940 # include <errno.h>
1941 int main(void){
1942 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1943 return 0;
1944 return 1;
1947 then
1949 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1950 '#define HAVE_PTRACE_DENY' << \!
1951 #include <sys/ptrace.h>
1952 # include <errno.h>
1953 int main(void){
1954 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1955 return 0;
1956 return 1;
1959 then
1961 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1962 '#define HAVE_SETPFLAGS_PROTECT' << \!
1963 #include <priv.h>
1964 # include <errno.h>
1965 int main(void){
1966 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1967 return 0;
1968 return 1;
1971 then
1976 ## Now it is the time to fork away the BASE_ series
1978 ${rm} -f ${tmp}
1979 squeeze_em ${inc} ${tmp}
1980 ${mv} ${tmp} ${inc}
1981 squeeze_em ${lib} ${tmp}
1982 ${mv} ${tmp} ${lib}
1984 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1985 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1987 ## The remains are expected to be used only by the main MUA binary!
1989 OPT_LOCALES=0
1990 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1991 #include <locale.h>
1992 int main(void){
1993 setlocale(LC_ALL, "");
1994 return 0;
1997 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1999 OPT_MULTIBYTE_CHARSETS=0
2000 OPT_WIDE_GLYPHS=0
2001 OPT_TERMINAL_CHARSET=0
2002 if [ -n "${have_setlocale}" ]; then
2003 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2004 '#define HAVE_C90AMEND1' << \!
2005 #include <limits.h>
2006 #include <stdlib.h>
2007 #include <wchar.h>
2008 #include <wctype.h>
2009 int main(void){
2010 char mbb[MB_LEN_MAX + 1];
2011 wchar_t wc;
2013 iswprint(L'c');
2014 towupper(L'c');
2015 mbtowc(&wc, "x", 1);
2016 mbrtowc(&wc, "x", 1, NULL);
2017 wctomb(mbb, wc);
2018 return (mblen("\0", 1) == 0);
2021 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2023 if [ -n "${have_c90amend1}" ]; then
2024 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2025 #include <wchar.h>
2026 int main(void){
2027 wcwidth(L'c');
2028 return 0;
2031 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2034 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2035 #include <langinfo.h>
2036 #include <stdlib.h>
2037 int main(void){
2038 nl_langinfo(DAY_1);
2039 return (nl_langinfo(CODESET) == NULL);
2042 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2043 fi # have_setlocale
2045 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2046 #include <fnmatch.h>
2047 int main(void){
2048 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2052 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2053 #include <dirent.h>
2054 int main(void){
2055 struct dirent de;
2056 return !(de.d_type == DT_UNKNOWN ||
2057 de.d_type == DT_DIR || de.d_type == DT_LNK);
2061 ## optional and selectable
2063 if feat_yes ICONV; then
2064 # To be able to create tests we need to figure out which replacement
2065 # sequence the iconv(3) implementation creates
2066 ${cat} > ${tmp2}.c << \!
2067 #include <stdio.h> /* For C89 NULL */
2068 #include <string.h>
2069 #include <iconv.h>
2070 int main(void){
2071 char inb[16], oub[16], *inbp, *oubp;
2072 iconv_t id;
2073 size_t inl, oul;
2075 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2076 inl = sizeof("\342\200\223") -1;
2077 oul = sizeof oub;
2078 oubp = oub;
2080 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2081 return 1;
2082 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2083 return 1;
2084 iconv_close(id);
2086 *oubp = '\0';
2087 oul = (size_t)(oubp - oub);
2088 if(oul == 0)
2089 return 1;
2090 /* Character-wise replacement? */
2091 if(oul == 1){
2092 if(oub[0] == '?')
2093 return 2;
2094 if(oub[0] == '*')
2095 return 3;
2096 return 1;
2098 /* Byte-wise replacement? */
2099 if(oul == sizeof("\342\200\223") -1){
2100 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2101 return 12;
2102 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2103 return 13;
2104 return 1;
2106 return 0;
2109 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2110 '#define HAVE_ICONV' ||
2111 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2112 '#define HAVE_ICONV' '-liconv' ||
2113 feat_bail_required ICONV
2115 if feat_no CROSS_BUILD; then
2116 { ./${tmp}; } >/dev/null 2>&1
2117 case ${?} in
2118 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2119 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2120 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2121 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2122 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2123 esac
2125 else
2126 feat_is_disabled ICONV
2127 fi # feat_yes ICONV
2129 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2130 ${cat} > ${tmp2}.c << \!
2131 #include <sys/types.h>
2132 #include <sys/socket.h>
2133 #include <sys/un.h>
2134 # include <errno.h>
2135 int main(void){
2136 struct sockaddr_un soun;
2138 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2139 return 1;
2140 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2141 return 1;
2142 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2143 return 1;
2144 return 0;
2148 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2149 '#define HAVE_UNIX_SOCKETS' ||
2150 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2151 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2152 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2153 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2156 if feat_yes SOCKETS; then
2157 ${cat} > ${tmp2}.c << \!
2158 #include <sys/types.h>
2159 #include <sys/socket.h>
2160 #include <netinet/in.h>
2161 # include <errno.h>
2162 int main(void){
2163 struct sockaddr s;
2165 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2166 return 1;
2167 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2168 return 1;
2169 return 0;
2173 < ${tmp2}.c run_check sockets 'sockets' \
2174 '#define HAVE_SOCKETS' ||
2175 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2176 '#define HAVE_SOCKETS' '-lnsl' ||
2177 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2178 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2179 feat_bail_required SOCKETS
2180 else
2181 feat_is_disabled SOCKETS
2182 fi # feat_yes SOCKETS
2184 if feat_yes SOCKETS; then
2185 link_check getaddrinfo 'getaddrinfo(3)' \
2186 '#define HAVE_GETADDRINFO' << \!
2187 #include <sys/types.h>
2188 #include <sys/socket.h>
2189 #include <stdio.h>
2190 #include <netdb.h>
2191 int main(void){
2192 struct addrinfo a, *ap;
2193 int lrv;
2195 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2196 case EAI_NONAME:
2197 case EAI_SERVICE:
2198 default:
2199 fprintf(stderr, "%s\n", gai_strerror(lrv));
2200 case 0:
2201 break;
2203 return 0;
2208 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2209 compile_check arpa_inet_h '<arpa/inet.h>' \
2210 '#define HAVE_ARPA_INET_H' << \!
2211 #include <sys/types.h>
2212 #include <sys/socket.h>
2213 #include <netdb.h>
2214 #include <netinet/in.h>
2215 #include <arpa/inet.h>
2218 ${cat} > ${tmp2}.c << \!
2219 #include <sys/types.h>
2220 #include <sys/socket.h>
2221 #include <stdio.h>
2222 #include <string.h>
2223 #include <netdb.h>
2224 #include <netinet/in.h>
2225 #ifdef HAVE_ARPA_INET_H
2226 #include <arpa/inet.h>
2227 #endif
2228 int main(void){
2229 struct sockaddr_in servaddr;
2230 unsigned short portno;
2231 struct servent *ep;
2232 struct hostent *hp;
2233 struct in_addr **pptr;
2235 portno = 0;
2236 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2237 portno = (unsigned short)ep->s_port;
2239 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2240 pptr = (struct in_addr**)hp->h_addr_list;
2241 if(hp->h_addrtype != AF_INET)
2242 fprintf(stderr, "au\n");
2243 }else{
2244 switch(h_errno){
2245 case HOST_NOT_FOUND:
2246 case TRY_AGAIN:
2247 case NO_RECOVERY:
2248 case NO_DATA:
2249 break;
2250 default:
2251 fprintf(stderr, "au\n");
2252 break;
2256 memset(&servaddr, 0, sizeof servaddr);
2257 servaddr.sin_family = AF_INET;
2258 servaddr.sin_port = htons(portno);
2259 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2260 fprintf(stderr, "Would connect to %s:%d ...\n",
2261 inet_ntoa(**pptr), (int)portno);
2262 return 0;
2266 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2267 < ${tmp2}.c link_check gethostbyname \
2268 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2269 < ${tmp2}.c link_check gethostbyname \
2270 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2271 '' '-lsocket -lnsl' ||
2272 feat_bail_required SOCKETS
2275 feat_yes SOCKETS &&
2276 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2277 #include <sys/socket.h>
2278 #include <stdlib.h>
2279 # include <errno.h>
2280 int main(void){
2281 int sockfd = 3;
2283 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2284 errno == ENOSYS)
2285 return 1;
2286 return 0;
2290 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2291 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2292 #include <sys/socket.h>
2293 #include <stdlib.h>
2294 int main(void){
2295 struct timeval tv;
2296 int sockfd = 3;
2298 tv.tv_sec = 42;
2299 tv.tv_usec = 21;
2300 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2301 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2302 return 0;
2306 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2307 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2308 #include <sys/socket.h>
2309 #include <stdlib.h>
2310 int main(void){
2311 struct linger li;
2312 int sockfd = 3;
2314 li.l_onoff = 1;
2315 li.l_linger = 42;
2316 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2317 return 0;
2321 VAL_SSL_FEATURES=
2322 if feat_yes SSL; then # {{{
2323 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2324 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2325 # time: we need to test it first in order to get things right
2326 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2327 '#define HAVE_SSL
2328 #define HAVE_XSSL
2329 #define HAVE_XSSL_RESSL
2330 #define HAVE_XSSL_OPENSSL 0' << \!
2331 #include <openssl/opensslv.h>
2332 #ifdef LIBRESSL_VERSION_NUMBER
2333 #else
2334 # error nope
2335 #endif
2337 then
2338 ossl_v1_1=
2339 VAL_SSL_FEATURES=libressl
2340 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2341 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2342 '#define HAVE_SSL
2343 #define HAVE_XSSL
2344 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2345 #include <openssl/opensslv.h>
2346 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2347 #else
2348 # error nope
2349 #endif
2351 then
2352 ossl_v1_1=1
2353 VAL_SSL_FEATURES=libssl-0x10100
2354 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2355 '#define HAVE_SSL
2356 #define HAVE_XSSL
2357 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2358 #include <openssl/opensslv.h>
2359 #ifdef OPENSSL_VERSION_NUMBER
2360 #else
2361 # error nope
2362 #endif
2364 then
2365 ossl_v1_1=
2366 VAL_SSL_FEATURES=libssl-0x10000
2367 else
2368 feat_bail_required SSL
2369 fi # }}}
2371 if feat_yes SSL; then # {{{
2372 if [ -n "${ossl_v1_1}" ]; then
2373 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2374 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2375 '-lssl -lcrypto'
2376 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2377 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2378 '-lssl -lcrypto' << \!
2379 #include <openssl/ssl.h>
2380 #include <openssl/err.h>
2381 #include <openssl/x509v3.h>
2382 #include <openssl/x509.h>
2383 #include <openssl/rand.h>
2384 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2385 # error We need TLSv1.
2386 #endif
2387 int main(void){
2388 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2390 SSL_CTX_free(ctx);
2391 PEM_read_PrivateKey(0, 0, 0, 0);
2392 return 0;
2395 then
2397 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2398 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2399 '-lssl -lcrypto' << \!
2400 #include <openssl/ssl.h>
2401 #include <openssl/err.h>
2402 #include <openssl/x509v3.h>
2403 #include <openssl/x509.h>
2404 #include <openssl/rand.h>
2405 #if defined OPENSSL_NO_SSL3 &&\
2406 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2407 # error We need one of SSLv3 and TLSv1.
2408 #endif
2409 int main(void){
2410 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2412 SSL_CTX_free(ctx);
2413 PEM_read_PrivateKey(0, 0, 0, 0);
2414 return 0;
2417 then
2419 else
2420 feat_bail_required SSL
2422 fi # }}}
2424 if feat_yes SSL; then # {{{
2425 if feat_yes SSL_ALL_ALGORITHMS; then
2426 if [ -n "${ossl_v1_1}" ]; then
2427 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2428 '#define HAVE_SSL_ALL_ALGORITHMS'
2429 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2430 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2431 #include <openssl/evp.h>
2432 int main(void){
2433 OpenSSL_add_all_algorithms();
2434 EVP_get_cipherbyname("two cents i never exist");
2435 EVP_cleanup();
2436 return 0;
2439 then
2441 else
2442 feat_bail_required SSL_ALL_ALGORITHMS
2444 elif [ -n "${ossl_v1_1}" ]; then
2445 without_check yes ssl_all_algo \
2446 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2447 '#define HAVE_SSL_ALL_ALGORITHMS'
2450 if [ -n "${ossl_v1_1}" ]; then
2451 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2452 '#define HAVE_XSSL_STACK_OF'
2453 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2454 '#define HAVE_XSSL_STACK_OF' << \!
2455 #include <stdio.h> /* For C89 NULL */
2456 #include <openssl/ssl.h>
2457 #include <openssl/err.h>
2458 #include <openssl/x509v3.h>
2459 #include <openssl/x509.h>
2460 #include <openssl/rand.h>
2461 int main(void){
2462 STACK_OF(GENERAL_NAME) *gens = NULL;
2464 printf("%p", gens); /* to use it */
2465 return 0;
2468 then
2472 if [ -n "${ossl_v1_1}" ]; then
2473 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2474 '#define HAVE_XSSL_CONFIG'
2475 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2476 elif link_check xssl_conf \
2477 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2478 '#define HAVE_XSSL_CONFIG' << \!
2479 #include <stdio.h> /* For C89 NULL */
2480 #include <openssl/conf.h>
2481 int main(void){
2482 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2483 CONF_modules_free();
2484 return 0;
2487 then
2488 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2489 else
2490 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2493 if [ -n "${ossl_v1_1}" ]; then
2494 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2495 '#define HAVE_XSSL_CONF_CTX'
2496 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2497 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2498 '#define HAVE_XSSL_CONF_CTX' << \!
2499 #include <openssl/ssl.h>
2500 #include <openssl/err.h>
2501 int main(void){
2502 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2503 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2505 SSL_CONF_CTX_set_flags(cctx,
2506 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2507 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2508 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2509 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2510 SSL_CONF_CTX_finish(cctx);
2511 SSL_CONF_CTX_free(cctx);
2512 SSL_CTX_free(ctx);
2513 return 0;
2516 then
2517 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2518 else
2519 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2522 if [ -n "${ossl_v1_1}" ]; then
2523 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2524 '#define HAVE_XSSL_CTX_CONFIG'
2525 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2526 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2527 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2528 '#define HAVE_XSSL_CTX_CONFIG' << \!
2529 #include <stdio.h> /* For C89 NULL */
2530 #include <openssl/ssl.h>
2531 int main(void){
2532 SSL_CTX_config(NULL, "SOMEVAL");
2533 return 0;
2536 then
2537 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2538 else
2539 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2542 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2543 without_check yes xssl_set_maxmin_proto \
2544 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2545 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2546 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2547 elif link_check xssl_set_maxmin_proto \
2548 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2549 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2550 #include <stdio.h> /* For C89 NULL */
2551 #include <openssl/ssl.h>
2552 int main(void){
2553 SSL_CTX_set_min_proto_version(NULL, 0);
2554 SSL_CTX_set_max_proto_version(NULL, 10);
2555 return 0;
2558 then
2559 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2560 else
2561 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2564 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2565 '#define HAVE_XSSL_RAND_EGD' << \!
2566 #include <openssl/rand.h>
2567 int main(void){
2568 return RAND_egd("some.where") > 0;
2571 then
2572 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2573 else
2574 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2576 fi # feat_yes SSL }}}
2578 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2579 run_check ssl_md5 'MD5 digest in the used crypto library' \
2580 '#define HAVE_XSSL_MD5' << \!
2581 #include <stdlib.h>
2582 #include <string.h>
2583 #include <openssl/md5.h>
2584 int main(void){
2585 char const dat[] = "abrakadabrafidibus";
2586 char dig[16], hex[16 * 2];
2587 MD5_CTX ctx;
2588 size_t i, j;
2590 memset(dig, 0, sizeof(dig));
2591 memset(hex, 0, sizeof(hex));
2592 MD5_Init(&ctx);
2593 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2594 MD5_Final(dig, &ctx);
2596 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2597 for(i = 0; i < sizeof(hex) / 2; i++){
2598 j = i << 1;
2599 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2600 hex[++j] = hexchar(dig[i] & 0x0f);
2602 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2605 fi # }}}
2607 if feat_yes SSL; then
2608 feat_def SSL_ALL_ALGORITHMS
2609 else
2610 feat_bail_required SSL_ALL_ALGORITHMS
2612 else
2613 feat_is_disabled SSL
2614 feat_is_disabled SSL_ALL_ALGORITHMS
2615 fi # }}} feat_yes SSL
2616 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2618 if [ "${have_xssl}" = yes ]; then
2619 OPT_SMIME=1
2620 else
2621 OPT_SMIME=0
2623 feat_def SMIME
2625 # VAL_RANDOM {{{
2626 if val_allof VAL_RANDOM \
2627 "arc4 ssl libgetrandom sysgetrandom urandom builtin error"; then
2629 else
2630 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2631 config_exit 1
2634 val_random_arc4() {
2635 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2636 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2637 #include <stdlib.h>
2638 int main(void){
2639 arc4random();
2640 return 0;
2645 val_random_ssl() {
2646 if feat_yes SSL; then
2647 msg ' . VAL_RANDOM: ssl ... yes'
2648 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2649 return 0
2650 else
2651 msg ' . VAL_RANDOM: ssl ... no'
2652 return 1
2656 val_random_libgetrandom() {
2657 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2658 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2659 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2660 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2661 #include <sys/random.h>
2662 int main(void){
2663 char buf[256];
2664 getrandom(buf, sizeof buf, 0);
2665 return 0;
2670 val_random_sysgetrandom() {
2671 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2672 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2673 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2674 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2675 #include <sys/syscall.h>
2676 int main(void){
2677 char buf[256];
2678 syscall(SYS_getrandom, buf, sizeof buf, 0);
2679 return 0;
2684 val_random_urandom() {
2685 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2686 if feat_yes CROSS_BUILD; then
2687 msg 'yes (unchecked)'
2688 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2689 elif [ -f /dev/urandom ]; then
2690 msg yes
2691 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2692 else
2693 msg no
2694 return 1
2696 return 0
2699 val_random_builtin() {
2700 msg_nonl ' . VAL_RANDOM: builtin ... '
2701 if [ -n "${have_no_subsecond_time}" ]; then
2702 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2703 'one of clock_gettime(2) and gettimeofday(2) is required.'
2704 config_exit 1
2705 else
2706 msg yes
2707 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2711 val_random_error() {
2712 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2713 config_exit 42
2716 oifs=${IFS}
2717 unset IFS
2718 VAL_RANDOM="${VAL_RANDOM} error"
2719 set -- ${VAL_RANDOM}
2720 IFS=${oifs}
2721 for randfun
2723 eval val_random_$randfun && break
2724 done
2725 # }}} VAL_RANDOM
2727 feat_def SMTP
2728 feat_def POP3
2729 feat_def IMAP
2731 if feat_yes GSSAPI; then
2732 ${cat} > ${tmp2}.c << \!
2733 #include <gssapi/gssapi.h>
2734 int main(void){
2735 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2736 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2737 return 0;
2740 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2742 if acmd_set i krb5-config; then
2743 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2744 GSS_INCS="`CFLAGS= ${i} --cflags`"
2745 i='GSS-API via krb5-config(1)'
2746 else
2747 GSS_LIBS='-lgssapi'
2748 GSS_INCS=
2749 i='GSS-API in gssapi/gssapi.h, libgssapi'
2751 if < ${tmp2}.c link_check gss \
2752 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2753 < ${tmp3}.c link_check gss \
2754 'GSS-API in gssapi.h, libgssapi' \
2755 '#define HAVE_GSSAPI
2756 #define GSSAPI_REG_INCLUDE' \
2757 '-lgssapi' ||\
2758 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2759 '#define HAVE_GSSAPI' \
2760 '-lgssapi_krb5' ||\
2761 < ${tmp3}.c link_check gss \
2762 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2763 '#define HAVE_GSSAPI
2764 #define GSS_REG_INCLUDE' \
2765 '-lgssapi -lkrb5 -lcrypto' \
2766 '-I/usr/include/kerberosV' ||\
2767 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2768 '#define HAVE_GSSAPI' \
2769 '-lgss' ||\
2770 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2771 '#define HAVE_GSSAPI
2772 #define GSSAPI_OLD_STYLE' \
2773 '-lgssapi_krb5' << \!
2774 #include <gssapi/gssapi.h>
2775 #include <gssapi/gssapi_generic.h>
2776 int main(void){
2777 gss_import_name(0, 0, gss_nt_service_name, 0);
2778 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2779 return 0;
2782 then
2784 else
2785 feat_bail_required GSSAPI
2787 else
2788 feat_is_disabled GSSAPI
2789 fi # feat_yes GSSAPI
2791 feat_def NETRC
2792 feat_def AGENT
2794 if feat_yes IDNA; then # {{{
2795 if val_allof VAL_IDNA "idnkit idn2 idn"; then
2797 else
2798 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2799 config_exit 1
2802 val_idna_idn2() {
2803 link_check idna 'OPT_IDNA: GNU Libidn2' \
2804 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2805 #include <idn2.h>
2806 int main(void){
2807 char *idna_utf8, *idna_lc;
2809 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2810 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2811 return 1;
2812 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2813 return 1;
2814 idn2_free(idna_lc);
2815 idn2_free(idna_utf8);
2816 return 0;
2821 val_idna_idn() {
2822 link_check idna 'OPT_IDNA: GNU Libidn' \
2823 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2824 #include <idna.h>
2825 #include <idn-free.h>
2826 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2827 int main(void){
2828 char *utf8, *idna_ascii, *idna_utf8;
2830 utf8 = stringprep_locale_to_utf8("does.this.work");
2831 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2832 != IDNA_SUCCESS)
2833 return 1;
2834 idn_free(idna_ascii);
2835 /* (Rather link check only here) */
2836 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2837 return 0;
2842 val_idna_idnkit() {
2843 link_check idna 'OPT_IDNA: idnkit' \
2844 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2845 #include <stdio.h>
2846 #include <idn/api.h>
2847 #include <idn/result.h>
2848 int main(void){
2849 idn_result_t r;
2850 char ace_name[256];
2851 char local_name[256];
2853 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2854 sizeof(ace_name));
2855 if (r != idn_success) {
2856 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2857 return 1;
2859 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2860 if (r != idn_success) {
2861 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2862 return 1;
2864 return 0;
2869 val_idna_bye() {
2870 feat_bail_required IDNA
2873 oifs=${IFS}
2874 unset IFS
2875 VAL_IDNA="${VAL_IDNA} bye"
2876 set -- ${VAL_IDNA}
2877 IFS=${oifs}
2878 for randfun
2880 eval val_idna_$randfun && break
2881 done
2882 else
2883 feat_is_disabled IDNA
2884 fi # }}} IDNA
2886 feat_def IMAP_SEARCH
2888 if feat_yes REGEX; then
2889 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2890 #include <regex.h>
2891 #include <stdlib.h>
2892 int main(void){
2893 size_t xret;
2894 int status;
2895 regex_t re;
2897 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2898 xret = regerror(status, &re, NULL, 0);
2899 status = regexec(&re, "plan9", 0,NULL, 0);
2900 regfree(&re);
2901 return !(status == REG_NOMATCH);
2904 then
2906 else
2907 feat_bail_required REGEX
2909 else
2910 feat_is_disabled REGEX
2913 if feat_yes MLE; then
2914 if [ -n "${have_c90amend1}" ]; then
2915 have_mle=1
2916 echo '#define HAVE_MLE' >> ${h}
2917 else
2918 feat_bail_required MLE
2920 else
2921 feat_is_disabled MLE
2924 # Generic have-a-line-editor switch for those who need it below
2925 if [ -n "${have_mle}" ]; then
2926 have_cle=1
2929 if feat_yes HISTORY; then
2930 if [ -n "${have_cle}" ]; then
2931 echo '#define HAVE_HISTORY' >> ${h}
2932 else
2933 feat_is_unsupported HISTORY
2935 else
2936 feat_is_disabled HISTORY
2939 if feat_yes KEY_BINDINGS; then
2940 if [ -n "${have_mle}" ]; then
2941 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2942 else
2943 feat_is_unsupported KEY_BINDINGS
2945 else
2946 feat_is_disabled KEY_BINDINGS
2949 if feat_yes TERMCAP; then
2950 __termcaplib() {
2951 link_check termcap "termcap(5) (via ${4})" \
2952 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2953 #include <stdio.h>
2954 #include <stdlib.h>
2955 ${2}
2956 #include <term.h>
2957 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2958 static int my_putc(int c){return putchar(c);}
2959 int main(void){
2960 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2961 int r2 = OK, r3 = ERR;
2963 tgetent(buf, getenv("TERM"));
2964 cpb = cmdbuf;
2965 r1 = tgetstr(UNCONST("cm"), &cpb);
2966 tgoto(r1, 1, 1);
2967 r2 = tgetnum(UNCONST("Co"));
2968 r3 = tgetflag(UNCONST("ut"));
2969 tputs("cr", 1, &my_putc);
2970 return (r1 == NULL || r2 == -1 || r3 == 0);
2972 _EOT
2975 __terminfolib() {
2976 link_check terminfo "terminfo(5) (via ${2})" \
2977 '#define HAVE_TERMCAP
2978 #define HAVE_TERMCAP_CURSES
2979 #define HAVE_TERMINFO' "${1}" << _EOT
2980 #include <stdio.h>
2981 #include <curses.h>
2982 #include <term.h>
2983 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2984 static int my_putc(int c){return putchar(c);}
2985 int main(void){
2986 int er, r0, r1, r2;
2987 char *r3, *tp;
2989 er = OK;
2990 r0 = setupterm(NULL, 1, &er);
2991 r1 = tigetflag(UNCONST("bce"));
2992 r2 = tigetnum(UNCONST("colors"));
2993 r3 = tigetstr(UNCONST("cr"));
2994 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2995 tputs(tp, 1, &my_putc);
2996 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2997 r3 == (char*)-1 || r3 == NULL);
2999 _EOT
3002 if feat_yes TERMCAP_VIA_TERMINFO; then
3003 __terminfolib -ltinfo -ltinfo ||
3004 __terminfolib -lcurses -lcurses ||
3005 __terminfolib -lcursesw -lcursesw ||
3006 feat_bail_required TERMCAP_VIA_TERMINFO
3009 if [ -z "${have_terminfo}" ]; then
3010 __termcaplib -ltermcap '' '' '-ltermcap' ||
3011 __termcaplib -ltermcap '#include <curses.h>' '
3012 #define HAVE_TERMCAP_CURSES' \
3013 'curses.h / -ltermcap' ||
3014 __termcaplib -lcurses '#include <curses.h>' '
3015 #define HAVE_TERMCAP_CURSES' \
3016 'curses.h / -lcurses' ||
3017 __termcaplib -lcursesw '#include <curses.h>' '
3018 #define HAVE_TERMCAP_CURSES' \
3019 'curses.h / -lcursesw' ||
3020 feat_bail_required TERMCAP
3022 if [ -n "${have_termcap}" ]; then
3023 run_check tgetent_null \
3024 "tgetent(3) of termcap(5) takes NULL buffer" \
3025 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3026 #include <stdio.h> /* For C89 NULL */
3027 #include <stdlib.h>
3028 #ifdef HAVE_TERMCAP_CURSES
3029 # include <curses.h>
3030 #endif
3031 #include <term.h>
3032 int main(void){
3033 tgetent(NULL, getenv("TERM"));
3034 return 0;
3036 _EOT
3039 else
3040 feat_is_disabled TERMCAP
3041 feat_is_disabled TERMCAP_VIA_TERMINFO
3044 if feat_def SPAM_SPAMC; then
3045 if acmd_set i spamc; then
3046 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3050 if feat_yes SPAM_SPAMD; then
3051 if [ -n "${have_af_unix}" ]; then
3052 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3053 else
3054 feat_bail_required SPAM_SPAMD
3056 else
3057 feat_is_disabled SPAM_SPAMD
3060 feat_def SPAM_FILTER
3062 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3063 echo '#define HAVE_SPAM' >> ${h}
3064 else
3065 echo '/* HAVE_SPAM */' >> ${h}
3068 if feat_yes QUOTE_FOLD; then
3069 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3070 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3071 else
3072 feat_bail_required QUOTE_FOLD
3074 else
3075 feat_is_disabled QUOTE_FOLD
3078 feat_def FILTER_HTML_TAGSOUP
3079 feat_def COLOUR
3080 feat_def DOTLOCK
3081 feat_def MD5
3083 ## Summarizing
3085 ${rm} -f ${tmp}
3086 squeeze_em ${inc} ${tmp}
3087 ${mv} ${tmp} ${inc}
3088 squeeze_em ${lib} ${tmp}
3089 ${mv} ${tmp} ${lib}
3091 # mk-config.h
3092 ${mv} ${h} ${tmp}
3093 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3094 ${cat} ${tmp} >> ${h}
3095 ${rm} -f ${tmp}
3096 printf '\n' >> ${h}
3098 # Create the string that is used by *features* and `version'.
3099 # Take this nice opportunity and generate a visual listing of included and
3100 # non-included features for the person who runs the configuration
3101 msg '\nThe following features are included (+) or not (-):'
3102 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3103 printf '/* The "feature string" */\n' >> ${h}
3104 # Because + is expanded by *folder* if first in "echo $features", put something
3105 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3106 sep=
3107 for opt
3109 sdoc=`option_doc_of ${opt}`
3110 [ -z "${sdoc}" ] && continue
3111 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3112 feat_yes ${opt} && sign=+ || sign=-
3113 printf -- "${sep}${sign}${sopt}" >> ${h}
3114 sep=','
3115 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
3116 done
3117 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3118 #exec 5>&1 >>${h}
3119 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3120 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3121 printf '"\n' >> ${h}
3123 # Create the real mk-config.mk
3124 # Note we cannout use explicit ./ filename prefix for source and object
3125 # pathnames because of a bug in bmake(1)
3126 ${rm} -rf ${tmp0}.* ${tmp0}*
3127 srclist= objlist=
3128 if feat_no AMALGAMATION; then
3129 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3130 i=`basename "${i}" .c`
3131 if [ "${i}" = privsep ]; then
3132 continue
3134 objlist="${objlist} ${i}.o"
3135 srclist="${srclist} \$(SRCDIR)${i}.c"
3136 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3137 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3138 done
3139 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3140 else
3141 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3142 "main.o" "main.c" >> ${mk}
3143 srclist=main.c objlist=main.o
3144 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3146 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3147 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3148 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3149 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3150 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3151 i=`basename "${i}"`
3152 if [ "${i}" = main.c ] ||
3153 [ "${i}" = privsep.c ]; then
3154 continue
3156 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3157 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3158 done
3159 echo >> ${mk}
3161 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3163 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3165 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3166 echo "INCS = `${cat} ${inc}`" >> ${mk}
3167 echo >> ${mk}
3168 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3170 ## Finished!
3172 msg '\nSetup:'
3173 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3174 msg ' . bindir: %s' "${VAL_BINDIR}"
3175 if feat_yes DOTLOCK; then
3176 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3178 msg ' . mandir: %s' "${VAL_MANDIR}"
3179 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3180 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3181 msg ''
3183 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3184 exit 0
3186 msg 'Remarks:'
3187 if [ -z "${have_fnmatch}" ]; then
3188 msg ' . The function fnmatch(3) could not be found.'
3189 msg ' Filename patterns like wildcard are not supported on your system'
3191 if [ -z "${have_fchdir}" ]; then
3192 msg ' . The function fchdir(2) could not be found.'
3193 msg ' We will use chdir(2) instead.'
3194 msg ' This is a problem only if the current working directory is changed'
3195 msg ' while this program is inside of it'
3197 msg ''
3199 # s-it-mode