make-config.sh: change a message for easier devel greps
[s-mailx.git] / make-config.sh
blob4303b7d7c9cebb4a6173d99d52e3dd8147994386
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 -Wall
469 cc_check -Wextra
470 cc_check -pedantic
472 if feat_yes DEBUG; then
473 # May have problems to find libtcc cc_check -b
474 cc_check -g
477 if ld_check -Wl,-rpath =./ no; then
478 ld_need_R_flags=-Wl,-rpath=
479 if [ -z "${ld_rpath_not_runpath}" ]; then
480 ld_check -Wl,--enable-new-dtags
481 else
482 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
484 ld_runtime_flags # update!
487 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
488 unset __cflags __ldflags
491 _cc_flags_generic() {
492 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
493 _CFLAGS= _LDFLAGS=
494 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
496 # E.g., valgrind does not work well with high optimization
497 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
498 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
499 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
500 cc_maxopt=1
502 # Check -g first since some others may rely upon -g / optim. level
503 if feat_yes DEBUG; then
504 cc_check -O
505 cc_check -g
506 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
508 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
510 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
512 else
513 cc_check -O
516 if feat_yes AMALGAMATION; then
517 cc_check -pipe
520 #if feat_yes DEVEL && cc_check -Weverything; then
522 #else
523 cc_check -Wall
524 cc_check -Wextra
525 cc_check -Wbad-function-cast
526 cc_check -Wcast-align
527 cc_check -Wcast-qual
528 cc_check -Winit-self
529 cc_check -Wmissing-prototypes
530 cc_check -Wshadow
531 cc_check -Wunused
532 cc_check -Wwrite-strings
533 cc_check -Wno-long-long
535 cc_check -pedantic
537 if feat_yes AMALGAMATION && feat_no DEVEL; then
538 cc_check -Wno-unused-function
540 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
542 cc_check -fno-unwind-tables
543 cc_check -fno-asynchronous-unwind-tables
544 cc_check -fstrict-aliasing
545 if cc_check -fstrict-overflow && feat_yes DEVEL; then
546 cc_check -Wstrict-overflow=5
549 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
550 if [ -z "${cc_force_no_stackprot}" ]; then
551 if cc_check -fstack-protector-strong ||
552 cc_check -fstack-protector-all; then
553 cc_check -D_FORTIFY_SOURCE=2
555 else
556 msg ' ! Not checking for -fstack-protector compiler option,'
557 msg ' ! since that caused errors in a "similar" configuration.'
558 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
562 # LD (+ dependend CC)
564 if feat_yes ASAN_ADDRESS; then
565 _ccfg=${_CFLAGS}
566 if cc_check -fsanitize=address &&
567 ld_check -fsanitize=address; then
569 else
570 feat_bail_required ASAN_ADDRESS
571 _CFLAGS=${_ccfg}
575 if feat_yes ASAN_MEMORY; then
576 _ccfg=${_CFLAGS}
577 if cc_check -fsanitize=memory &&
578 ld_check -fsanitize=memory &&
579 cc_check -fsanitize-memory-track-origins=2 &&
580 ld_check -fsanitize-memory-track-origins=2; then
582 else
583 feat_bail_required ASAN_MEMORY
584 _CFLAGS=${_ccfg}
588 ld_check -Wl,-z,relro
589 if [ -z "${ld_no_bind_now}" ]; then
590 ld_check -Wl,-z,now
591 else
592 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
594 ld_check -Wl,-z,noexecstack
595 if ld_check -Wl,-rpath =./ no; then
596 ld_need_R_flags=-Wl,-rpath=
597 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
598 if [ -z "${ld_rpath_not_runpath}" ]; then
599 ld_check -Wl,--enable-new-dtags
600 else
601 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
603 ld_runtime_flags # update!
604 elif ld_check -Wl,-R ./ no; then
605 ld_need_R_flags=-Wl,-R
606 if [ -z "${ld_rpath_not_runpath}" ]; then
607 ld_check -Wl,--enable-new-dtags
608 else
609 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
611 ld_runtime_flags # update!
614 # Address randomization
615 _ccfg=${_CFLAGS}
616 if cc_check -fPIE || cc_check -fpie; then
617 ld_check -pie || _CFLAGS=${_ccfg}
619 unset _ccfg
621 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
622 unset __cflags __ldflags
625 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
627 ## Notes:
628 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
629 ## redirection, so use "printf '' >" instead
631 ## Very first: we undergo several states regarding I/O redirection etc.,
632 ## but need to deal with option updates from within all. Since all the
633 ## option stuff should be above the scissor line, define utility functions
634 ## and redefine them as necessary.
635 ## And, since we have those functions, simply use them for whatever
637 t1=ten10one1ten10one1
638 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
639 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
640 ) > /dev/null 2>&1; then
641 good_shell=1
642 else
643 unset good_shell
645 unset t1
647 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
649 config_exit() {
650 exit ${1}
653 # which(1) not standardized, command(1) -v may return non-executable: unroll!
654 acmd_test() { __acmd "${1}" 1 0 0; }
655 acmd_test_fail() { __acmd "${1}" 1 1 0; }
656 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
657 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
658 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
659 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
660 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
661 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
662 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
663 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
664 __acmd() {
665 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
667 if [ "${dotest}" -ne 0 ]; then
668 eval dotest=\$${varname}
669 if [ -n "${dotest}" ]; then
670 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
671 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
672 return 0
676 oifs=${IFS} IFS=:
677 [ -n "${noglob_shell}" ] && set -o noglob
678 set -- ${PATH}
679 [ -n "${noglob_shell}" ] && set +o noglob
680 IFS=${oifs}
681 for path
683 if [ -z "${path}" ] || [ "${path}" = . ]; then
684 if [ -d "${PWD}" ]; then
685 path=${PWD}
686 else
687 path=.
690 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
691 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
692 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
693 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
694 return 0
696 done
698 # We may have no builtin string functions, we yet have no programs we can
699 # use, try to access once from the root, assuming it is an absolute path if
700 # that finds the executable
701 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
702 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
703 msg ' . ${%s} ... %s' "${pname}" "${pname}"
704 [ -n "${varname}" ] && eval ${varname}="${pname}"
705 return 0
708 [ ${dofail} -eq 0 ] && return 1
709 msg 'ERROR: no trace of utility '"${pname}"
710 exit 1
713 msg() {
714 fmt=${1}
715 shift
716 printf >&2 -- "${fmt}\\n" "${@}"
719 msg_nonl() {
720 fmt=${1}
721 shift
722 printf >&2 -- "${fmt}" "${@}"
725 # Our feature check environment
726 feat_val_no() {
727 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
728 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
731 feat_val_yes() {
732 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
733 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
734 [ "x${1}" = xrequire ]
737 feat_val_require() {
738 [ "x${1}" = xrequire ]
741 _feat_check() {
742 eval i=\$OPT_${1}
743 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
744 if feat_val_no "${i}"; then
745 return 1
746 elif feat_val_yes "${i}"; then
747 return 0
748 else
749 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
750 "${1}" "${i}"
751 config_exit 11
755 feat_yes() {
756 _feat_check ${1}
759 feat_no() {
760 _feat_check ${1} && return 1
761 return 0
764 feat_require() {
765 eval i=\$OPT_${1}
766 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
767 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
770 feat_bail_required() {
771 if feat_require ${1}; then
772 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
773 config_exit 13
775 feat_is_unsupported "${1}"
778 feat_is_disabled() {
779 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
780 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
783 feat_is_unsupported() {
784 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
785 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
786 eval OPT_${1}=0
787 option_update # XXX this is rather useless here (dependency chain..)
790 feat_def() {
791 if feat_yes ${1}; then
792 echo '#define HAVE_'${1}'' >> ${h}
793 return 0
794 else
795 feat_is_disabled "${@}"
796 return 1
800 option_parse() {
801 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
802 # options, without documentation, to $1
803 j=\'
804 i="`${awk} -v input=\"${2}\" '
805 BEGIN{
806 for(i = 0;;){
807 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
808 if(voff == 0)
809 break
810 v = substr(input, voff, RLENGTH)
811 input = substr(input, voff + RLENGTH)
812 doff = index(v, "=")
813 if(doff > 0){
814 d = substr(v, doff + 2, length(v) - doff - 1)
815 v = substr(v, 1, doff - 1)
817 print v
821 eval ${1}=\"${i}\"
824 option_doc_of() {
825 # Return the "documentation string" for option $1, itself if none such
826 j=\'
827 ${awk} -v want="${1}" \
828 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
829 BEGIN{
830 for(;;){
831 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
832 if(voff == 0)
833 break
834 v = substr(input, voff, RLENGTH)
835 input = substr(input, voff + RLENGTH)
836 doff = index(v, "=")
837 if(doff > 0){
838 d = substr(v, doff + 2, length(v) - doff - 1)
839 v = substr(v, 1, doff - 1)
840 }else
841 d = v
842 if(v == want){
843 if(d != "-")
844 print d
845 exit
852 option_join_rc() {
853 # Join the values from make.rc into what currently is defined, not
854 # overwriting yet existing settings
855 ${rm} -f ${tmp}
856 # We want read(1) to perform reverse solidus escaping in order to be able to
857 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
858 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
859 < ${rc} ${awk} 'BEGIN{line = ""}{
860 gsub(/^[[:space:]]+/, "", $0)
861 gsub(/[[:space:]]+$/, "", $0)
862 if(gsub(/\\$/, "", $0)){
863 line = line $0
864 next
865 }else
866 line = line $0
867 if(index(line, "#") == 1){
868 line = ""
869 }else if(length(line)){
870 print line
871 line = ""
873 }' |
874 while read line; do
875 if [ -n "${good_shell}" ]; then
876 i=${line%%=*}
877 else
878 i=`${awk} -v LINE="${line}" 'BEGIN{
879 gsub(/=.*$/, "", LINE)
880 print LINE
883 if [ "${i}" = "${line}" ]; then
884 msg 'ERROR: invalid syntax in: %s' "${line}"
885 continue
888 eval j="\$${i}" jx="\${${i}+x}"
889 if [ -n "${j}" ] || [ "${jx}" = x ]; then
890 : # Yet present
891 else
892 j=`${awk} -v LINE="${line}" 'BEGIN{
893 gsub(/^[^=]*=/, "", LINE)
894 gsub(/^\"*/, "", LINE)
895 gsub(/\"*$/, "", LINE)
896 print LINE
899 [ "${i}" = "DESTDIR" ] && continue
900 echo "${i}=\"${j}\""
901 done > ${tmp}
902 # Reread the mixed version right now
903 . ./${tmp}
906 option_evaluate() {
907 # Expand the option values, which may contain shell snippets
908 ${rm} -f ${newlst} ${newmk} ${newh}
909 exec 5<&0 6>&1 <${tmp} >${newlst}
910 while read line; do
912 if [ -n "${good_shell}" ]; then
913 i=${line%%=*}
914 [ "${i}" != "${i#OPT_}" ] && z=1
915 else
916 i=`${awk} -v LINE="${line}" 'BEGIN{
917 gsub(/=.*$/, "", LINE);\
918 print LINE
920 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
925 eval j=\$${i}
926 if [ -n "${z}" ]; then
927 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
928 if [ -z "${j}" ] || feat_val_no "${j}"; then
930 printf " /* #undef ${i} */\n" >> ${newh}
931 elif feat_val_yes "${j}"; then
932 if feat_val_require "${j}"; then
933 j=require
934 else
937 printf " /* #define ${i} */\n" >> ${newh}
938 else
939 msg 'ERROR: cannot parse <%s>' "${line}"
940 config_exit 1
942 elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
944 else
945 printf "#define ${i} \"${j}\"\n" >> ${newh}
947 printf "${i} = ${j}\n" >> ${newmk}
948 printf "${i}=${j}\n"
949 eval "${i}=\"${j}\""
950 done
951 exec 0<&5 1>&6 5<&- 6<&-
954 val_allof() {
955 eval __expo__=\$${1}
956 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
957 BEGIN{
958 i = split(HEAP, ha)
959 if((j = split(USER, ua)) == 0)
960 exit
961 for(; j != 0; --j){
962 us = tolower(ua[j])
963 if(us == "all" || us == "any")
964 continue
965 ok = 0
966 for(ii = i; ii != 0; --ii)
967 if(tolower(ha[ii]) == us){
968 ok = 1
969 break
971 if(!ok)
972 exit 1
976 __rv__=${?}
977 [ ${__rv__} -ne 0 ] && return ${__rv__}
979 if ${awk} -v USER="${__expo__}" '
980 BEGIN{
981 if((j = split(USER, ua)) == 0)
982 exit
983 for(; j != 0; --j){
984 us = tolower(ua[j])
985 if(us == "all" || us == "any")
986 exit 0
988 exit 1
990 '; then
991 eval "${1}"=\"${2}\"
993 return 0
996 path_check() {
997 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
998 varname=${1} addflag=${2} flagvarname=${3}
999 j=${IFS}
1000 IFS=:
1001 [ -n "${noglob_shell}" ] && set -o noglob
1002 eval "set -- \$${1}"
1003 [ -n "${noglob_shell}" ] && set +o noglob
1004 IFS=${j}
1005 j= k= y= z=
1006 for i
1008 [ -z "${i}" ] && continue
1009 [ -d "${i}" ] || continue
1010 if [ -n "${j}" ]; then
1011 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1013 else
1014 y="${y} :${i}:"
1015 j="${j}:${i}"
1016 # But do not link any fakeroot path into our binaries!
1017 if [ -n "${addflag}" ]; then
1018 case "${i}" in *fakeroot*) continue;; esac
1019 k="${k} ${addflag}${i}"
1022 else
1023 y=" :${i}:"
1024 j="${i}"
1025 # But do not link any fakeroot path into our binaries!
1026 if [ -n "${addflag}" ]; then
1027 case "${i}" in *fakeroot*) continue;; esac
1028 k="${k} ${addflag}${i}"
1031 done
1032 eval "${varname}=\"${j}\""
1033 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1034 unset varname
1037 ld_runtime_flags() {
1038 if [ -n "${ld_need_R_flags}" ]; then
1039 i=${IFS}
1040 IFS=:
1041 set -- ${LD_LIBRARY_PATH}
1042 IFS=${i}
1043 for i
1045 # But do not link any fakeroot path into our binaries!
1046 case "${i}" in *fakeroot*) continue;; esac
1047 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1048 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1049 done
1050 export LDFLAGS
1052 # Disable it for a possible second run.
1053 ld_need_R_flags=
1056 cc_check() {
1057 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1058 if "${CC}" ${INCS} \
1059 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1060 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1061 _CFLAGS="${_CFLAGS} ${1}"
1062 [ -n "${cc_check_silent}" ] || msg 'yes'
1063 return 0
1065 [ -n "${cc_check_silent}" ] || msg 'no'
1066 return 1
1069 ld_check() {
1070 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1071 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1072 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1073 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1074 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1075 [ -n "${cc_check_silent}" ] || msg 'yes'
1076 return 0
1078 [ -n "${cc_check_silent}" ] || msg 'no'
1079 return 1
1082 dump_test_program=1
1083 _check_preface() {
1084 variable=$1 topic=$2 define=$3
1086 echo '**********'
1087 msg_nonl ' . %s ... ' "${topic}"
1088 #echo "/* checked ${topic} */" >> ${h}
1089 ${rm} -f ${tmp} ${tmp}.o
1090 if [ "${dump_test_program}" = 1 ]; then
1091 echo '*** test program is'
1092 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1093 else
1094 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1096 #echo '*** the preprocessor generates'
1097 #${make} -f ${makefile} ${tmp}.x
1098 #${cat} ${tmp}.x
1099 echo '*** tests results'
1102 without_check() {
1103 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1105 echo '**********'
1106 msg_nonl ' . %s ... ' "${topic}"
1108 echo '*** enforced unchecked results are'
1109 if feat_val_yes ${yesno}; then
1110 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1111 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1112 LIBS="${LIBS} ${libs}"
1113 echo "${libs}" >> ${lib}
1114 INCS="${INCS} ${incs}"
1115 echo "${incs}" >> ${inc}
1117 msg 'yes (deduced)'
1118 echo "${define}" >> ${h}
1119 eval have_${variable}=yes
1120 return 0
1121 else
1122 #echo "/* ${define} */" >> ${h}
1123 msg 'no (deduced)'
1124 eval unset have_${variable}
1125 return 1
1129 compile_check() {
1130 variable=$1 topic=$2 define=$3
1132 _check_preface "${variable}" "${topic}" "${define}"
1134 if ${make} -f ${makefile} XINCS="${INCS}" \
1135 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1136 ./${tmp}.o &&
1137 [ -f ./${tmp}.o ]; then
1138 msg 'yes'
1139 echo "${define}" >> ${h}
1140 eval have_${variable}=yes
1141 return 0
1142 else
1143 #echo "/* ${define} */" >> ${h}
1144 msg 'no'
1145 eval unset have_${variable}
1146 return 1
1150 _link_mayrun() {
1151 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1153 _check_preface "${variable}" "${topic}" "${define}"
1155 if feat_yes CROSS_BUILD; then
1156 if [ ${run} = 1 ]; then
1157 run=0
1161 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1162 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1163 XLIBS="${LIBS} ${libs}" \
1164 ./${tmp} &&
1165 [ -f ./${tmp} ] &&
1166 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1167 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1168 msg 'yes'
1169 echo "${define}" >> ${h}
1170 LIBS="${LIBS} ${libs}"
1171 echo "${libs}" >> ${lib}
1172 INCS="${INCS} ${incs}"
1173 echo "${incs}" >> ${inc}
1174 eval have_${variable}=yes
1175 return 0
1176 else
1177 msg 'no'
1178 #echo "/* ${define} */" >> ${h}
1179 eval unset have_${variable}
1180 return 1
1184 link_check() {
1185 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1188 run_check() {
1189 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1192 xrun_check() {
1193 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1196 squeeze_em() {
1197 < "${1}" > "${2}" ${awk} \
1198 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1201 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1203 # First of all, create new configuration and check whether it changed
1205 # Very easy checks for the operating system in order to be able to adjust paths
1206 # or similar very basic things which we need to be able to go at all
1207 os_early_setup
1209 # Check those tools right now that we need before including $rc
1210 msg 'Checking for basic utility set'
1211 thecmd_testandset_fail awk awk
1212 thecmd_testandset_fail rm rm
1213 thecmd_testandset_fail tr tr
1215 # Initialize the option set
1216 msg_nonl 'Setting up configuration options ... '
1217 option_setup
1218 msg 'done'
1220 # Include $rc, but only take from it what wasn't overwritten by the user from
1221 # within the command line or from a chosen fixed CONFIG=
1222 # Note we leave alone the values
1223 trap "exit 1" HUP INT TERM
1224 trap "${rm} -f ${tmp}" EXIT
1226 msg_nonl 'Joining in %s ... ' ${rc}
1227 option_join_rc
1228 msg 'done'
1230 # We need to know about that now, in order to provide utility overwrites etc.
1231 os_setup
1233 msg 'Checking for remaining set of utilities'
1234 thecmd_testandset_fail grep grep
1236 # Before we step ahead with the other utilities perform a path cleanup first.
1237 path_check PATH
1239 # awk(1) above
1240 thecmd_testandset_fail basename basename
1241 thecmd_testandset_fail cat cat
1242 thecmd_testandset_fail chmod chmod
1243 thecmd_testandset_fail cp cp
1244 thecmd_testandset_fail cmp cmp
1245 # grep(1) above
1246 thecmd_testandset_fail mkdir mkdir
1247 thecmd_testandset_fail mv mv
1248 # rm(1) above
1249 thecmd_testandset_fail sed sed
1250 thecmd_testandset_fail sort sort
1251 thecmd_testandset_fail tee tee
1252 __PATH=${PATH}
1253 thecmd_testandset chown chown ||
1254 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1255 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1256 PATH=${__PATH}
1257 thecmd_testandset_fail MAKE make
1258 make=${MAKE}
1259 export MAKE
1260 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1262 # For ./cc-test.sh only
1263 thecmd_testandset_fail cksum cksum
1265 # Update OPT_ options now, in order to get possible inter-dependencies right
1266 option_update
1268 # (No functions since some shells loose non-exported variables in traps)
1269 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1270 trap "trap \"\" HUP INT TERM EXIT;\
1271 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1272 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1274 # Our configuration options may at this point still contain shell snippets,
1275 # we need to evaluate them in order to get them expanded, and we need those
1276 # evaluated values not only in our new configuration file, but also at hand..
1277 msg_nonl 'Evaluating all configuration items ... '
1278 option_evaluate
1279 msg 'done'
1281 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1282 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1284 # The problem now is that the test should be able to run in the users linker
1285 # and path environment, so we need to place the test: rule first, before
1286 # injecting the relevant make variables. Set up necessary environment
1287 if [ -z "${VERBOSE}" ]; then
1288 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1289 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1290 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1291 printf -- "ECHO_TEST = @\n" >> ${newmk}
1292 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1293 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1294 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1296 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1297 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1299 # Add the known utility and some other variables
1300 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1301 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1302 if feat_yes DOTLOCK; then
1303 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1304 else
1305 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1308 for i in \
1309 SRCDIR \
1310 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1311 MAKE MAKEFLAGS make SHELL strip \
1312 cksum; do
1313 eval j=\$${i}
1314 printf "${i} = ${j}\n" >> ${newmk}
1315 printf "${i}=${j}\n" >> ${newlst}
1316 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1317 done
1318 # Note that makefile reads and eval'uates one line of this file, whereas other
1319 # consumers source it via .(1)
1320 printf "\n" >> ${newev}
1322 # Build a basic set of INCS and LIBS according to user environment.
1323 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1324 path_check C_INCLUDE_PATH -I _INCS
1325 INCS="${INCS} ${_INCS}"
1326 path_check LD_LIBRARY_PATH -L _LIBS
1327 LIBS="${LIBS} ${_LIBS}"
1328 unset _INCS _LIBS
1329 export C_INCLUDE_PATH LD_LIBRARY_PATH
1331 # Some environments need runtime path flags to be able to go at all
1332 ld_runtime_flags
1334 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1336 cc_setup
1338 ${cat} > ${tmp}.c << \!
1339 #include <stdio.h>
1340 #include <string.h>
1341 static void doit(char const *s);
1343 main(int argc, char **argv){
1344 (void)argc;
1345 (void)argv;
1346 doit("Hello world");
1347 return 0;
1349 static void
1350 doit(char const *s){
1351 char buf[12];
1352 memcpy(buf, s, strlen(s) +1);
1353 puts(s);
1357 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1358 -o ${tmp2} ${tmp}.c ${LIBS}; then
1360 else
1361 msg 'ERROR: i cannot compile a "Hello world" via'
1362 msg ' %s' \
1363 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1364 msg 'ERROR: Please read INSTALL, rerun'
1365 config_exit 1
1368 # This may also update ld_runtime_flags() (again)
1369 cc_flags
1371 for i in \
1372 INCS LIBS \
1373 ; do
1374 eval j=\$${i}
1375 printf -- "${i}=${j}\n" >> ${newlst}
1376 done
1377 for i in \
1378 CC \
1379 CFLAGS \
1380 LDFLAGS \
1381 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1382 OSFULLSPEC \
1383 ; do
1384 eval j=\$${i}
1385 if [ -n "${j}" ]; then
1386 printf -- "${i} = ${j}\n" >> ${newmk}
1387 printf -- "${i}=${j}\n" >> ${newlst}
1389 done
1391 # Now finally check whether we already have a configuration and if so, whether
1392 # all those parameters are still the same.. or something has actually changed
1393 config_updated=
1394 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1395 echo 'Configuration is up-to-date'
1396 exit 0
1397 elif [ -f ${lst} ]; then
1398 config_updated=1
1399 echo 'Configuration has been updated..'
1400 else
1401 echo 'Shiny configuration..'
1404 # Time to redefine helper 1
1405 config_exit() {
1406 ${rm} -f ${lst} ${h} ${mk}
1407 exit ${1}
1410 ${mv} -f ${newlst} ${lst}
1411 ${mv} -f ${newev} ${ev}
1412 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1413 ${mv} -f ${newh} ${h}
1414 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1415 ${mv} -f ${newmk} ${mk}
1417 ## Compile and link checking
1419 tmp3=./${tmp0}3$$
1420 log=./mk-config.log
1421 lib=./mk-config.lib
1422 inc=./mk-config.inc
1423 makefile=./${tmp0}.mk
1425 # (No function since some shells loose non-exported variables in traps)
1426 trap "trap \"\" HUP INT TERM;\
1427 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1428 HUP INT TERM
1429 trap "trap \"\" HUP INT TERM EXIT;\
1430 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1432 # Time to redefine helper 2
1433 msg() {
1434 fmt=${1}
1435 shift
1436 printf "*** ${fmt}\\n" "${@}"
1437 printf -- "${fmt}\\n" "${@}" >&5
1439 msg_nonl() {
1440 fmt=${1}
1441 shift
1442 printf "*** ${fmt}\\n" "${@}"
1443 printf -- "${fmt}" "${@}" >&5
1446 # !!
1447 exec 5>&2 > ${log} 2>&1
1449 echo "${LIBS}" > ${lib}
1450 echo "${INCS}" > ${inc}
1451 ${cat} > ${makefile} << \!
1452 .SUFFIXES: .o .c .x .y
1453 .c.o:
1454 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1455 .c.x:
1456 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1458 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1461 ## Generics
1463 # May be multiline..
1464 echo >> ${h}
1465 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1466 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1467 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1469 # Generate n_err_number OS mappings
1470 dump_test_program=0
1472 feat_yes DEVEL && NV= || NV=noverbose
1473 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1474 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1475 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1476 dump_test_program=1
1478 feat_def ALWAYS_UNICODE_LOCALE
1479 feat_def AMALGAMATION 0
1480 feat_def CROSS_BUILD
1481 feat_def DOCSTRINGS
1482 feat_def UISTRINGS
1483 feat_def ERRORS
1485 feat_def ASAN_ADDRESS 0
1486 feat_def ASAN_MEMORY 0
1487 feat_def DEBUG 0
1488 feat_def DEVEL 0
1489 feat_def NYD2 0
1490 feat_def NOMEMDBG 0
1492 if xrun_check inline 'inline functions' \
1493 '#define HAVE_INLINE
1494 #define n_INLINE static inline' << \!
1495 static inline int ilf(int i){return ++i;}
1496 int main(void){return ilf(-1);}
1498 then
1500 elif xrun_check inline 'inline functions (via __inline)' \
1501 '#define HAVE_INLINE
1502 #define n_INLINE static __inline' << \!
1503 static __inline int ilf(int i){return ++i;}
1504 int main(void){return ilf(-1);}
1506 then
1510 ## Test for "basic" system-calls / functionality that is used by all parts
1511 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1512 ## macros to be used by only the subprograms (potentially).
1514 if run_check clock_gettime 'clock_gettime(2)' \
1515 '#define HAVE_CLOCK_GETTIME' << \!
1516 #include <time.h>
1517 # include <errno.h>
1518 int main(void){
1519 struct timespec ts;
1521 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1522 return 0;
1523 return 1;
1526 then
1528 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1529 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1530 #include <time.h>
1531 # include <errno.h>
1532 int main(void){
1533 struct timespec ts;
1535 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1536 return 0;
1537 return 1;
1540 then
1542 elif run_check gettimeofday 'gettimeofday(2)' \
1543 '#define HAVE_GETTIMEOFDAY' << \!
1544 #include <stdio.h> /* For C89 NULL */
1545 #include <sys/time.h>
1546 # include <errno.h>
1547 int main(void){
1548 struct timeval tv;
1550 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1551 return 0;
1552 return 1;
1555 then
1557 else
1558 have_no_subsecond_time=1
1561 if run_check nanosleep 'nanosleep(2)' \
1562 '#define HAVE_NANOSLEEP' << \!
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 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1578 '#define HAVE_NANOSLEEP' '-lrt' << \!
1579 #include <time.h>
1580 # include <errno.h>
1581 int main(void){
1582 struct timespec ts;
1584 ts.tv_sec = 1;
1585 ts.tv_nsec = 100000;
1586 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1587 return 0;
1588 return 1;
1591 then
1593 # link_check is enough for this, that function is so old, trust the proto
1594 elif link_check sleep 'sleep(3)' \
1595 '#define HAVE_SLEEP' << \!
1596 #include <unistd.h>
1597 # include <errno.h>
1598 int main(void){
1599 if(!sleep(1) || errno != ENOSYS)
1600 return 0;
1601 return 1;
1604 then
1606 else
1607 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1608 config_exit 1
1611 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1612 #include <pwd.h>
1613 #include <unistd.h>
1614 # include <errno.h>
1615 int main(void){
1616 struct passwd *pw;
1617 gid_t gid;
1618 uid_t uid;
1620 if((gid = getgid()) != 0)
1621 gid = getegid();
1622 if((uid = getuid()) != 0)
1623 uid = geteuid();
1624 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1625 return 1;
1626 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1627 return 1;
1628 return 0;
1631 then
1633 else
1634 msg 'ERROR: we require user and group info / database searches.'
1635 msg 'That much Unix we indulge ourselfs.'
1636 config_exit 1
1639 if link_check ftruncate 'ftruncate(2)' \
1640 '#define HAVE_FTRUNCATE' << \!
1641 #include <unistd.h>
1642 #include <sys/types.h>
1643 int main(void){
1644 return (ftruncate(0, 0) != 0);
1647 then
1649 else
1650 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1651 msg 'ERROR: we require the ftruncate(2) system call.'
1652 config_exit 1
1655 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1656 #include <signal.h>
1657 # include <errno.h>
1658 int main(void){
1659 struct sigaction nact, oact;
1661 nact.sa_handler = SIG_DFL;
1662 sigemptyset(&nact.sa_mask);
1663 nact.sa_flags = SA_RESTART;
1664 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1667 then
1669 else
1670 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1671 config_exit 1
1674 if link_check snprintf 'snprintf(3)' << \!
1675 #include <stdio.h>
1676 int main(void){
1677 char b[20];
1679 snprintf(b, sizeof b, "%s", "string");
1680 return 0;
1683 then
1685 else
1686 msg 'ERROR: we require the snprintf(3) function.'
1687 config_exit 1
1690 if link_check environ 'environ(3)' << \!
1691 #include <stdio.h> /* For C89 NULL */
1692 int main(void){
1693 extern char **environ;
1695 return environ[0] == NULL;
1698 then
1700 else
1701 msg 'ERROR: we require the environ(3) array for subprocess control.'
1702 config_exit 1
1705 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1706 #include <stdlib.h>
1707 int main(void){
1708 setenv("s-mailx", "i want to see it cute!", 1);
1709 unsetenv("s-mailx");
1710 return 0;
1713 then
1715 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1716 #include <stdlib.h>
1717 int main(void){
1718 putenv("s-mailx=i want to see it cute!");
1719 return 0;
1722 then
1724 else
1725 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1726 config_exit 1
1729 if link_check termios 'termios.h and tc*(3) family' << \!
1730 #include <termios.h>
1731 int main(void){
1732 struct termios tios;
1734 tcgetattr(0, &tios);
1735 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1736 return 0;
1739 then
1741 else
1742 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1743 msg 'That much Unix we indulge ourselfs.'
1744 config_exit 1
1747 ## optional stuff
1749 if link_check vsnprintf 'vsnprintf(3)' << \!
1750 #include <stdarg.h>
1751 #include <stdio.h>
1752 static void dome(char *buf, size_t blen, ...){
1753 va_list ap;
1755 va_start(ap, blen);
1756 vsnprintf(buf, blen, "%s", ap);
1757 va_end(ap);
1759 int main(void){
1760 char b[20];
1762 dome(b, sizeof b, "string");
1763 return 0;
1766 then
1768 else
1769 feat_bail_required ERRORS
1772 if [ "${have_vsnprintf}" = yes ]; then
1773 __va_copy() {
1774 link_check va_copy "va_copy(3) (as ${2})" \
1775 "#define HAVE_N_VA_COPY
1776 #define n_va_copy ${2}" <<_EOT
1777 #include <stdarg.h>
1778 #include <stdio.h>
1779 #if ${1}
1780 # if defined __va_copy && !defined va_copy
1781 # define va_copy __va_copy
1782 # endif
1783 #endif
1784 static void dome2(char *buf, size_t blen, va_list src){
1785 va_list ap;
1787 va_copy(ap, src);
1788 vsnprintf(buf, blen, "%s", ap);
1789 va_end(ap);
1791 static void dome(char *buf, size_t blen, ...){
1792 va_list ap;
1794 va_start(ap, blen);
1795 dome2(buf, blen, ap);
1796 va_end(ap);
1798 int main(void){
1799 char b[20];
1801 dome(b, sizeof b, "string");
1802 return 0;
1804 _EOT
1806 __va_copy 0 va_copy || __va_copy 1 __va_copy
1809 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1810 #include <unistd.h>
1811 #include <errno.h>
1812 int main(void){
1813 int rv = 0;
1815 errno = 0;
1816 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1817 errno = 0;
1818 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1820 /* Only link check */
1821 fpathconf(0, _PC_NAME_MAX);
1823 return rv;
1827 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1828 #include <fcntl.h>
1829 #include <unistd.h>
1830 # include <errno.h>
1831 int main(void){
1832 int fds[2];
1834 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1835 return 0;
1836 return 1;
1840 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1841 #include <termios.h>
1842 int main(void){
1843 struct winsize ws;
1845 tcgetwinsize(0, &ws);
1846 return 0;
1850 # We use this only then for now (need NOW+1)
1851 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1852 #include <fcntl.h> /* For AT_* */
1853 #include <sys/stat.h>
1854 # include <errno.h>
1855 int main(void){
1856 struct timespec ts[2];
1858 ts[0].tv_nsec = UTIME_NOW;
1859 ts[1].tv_nsec = UTIME_OMIT;
1860 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1861 return 0;
1862 return 1;
1868 # The random check has been moved to below SSL detection due to multiple choice
1869 # selection for PRG sources
1871 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1872 #include <stdio.h>
1873 int main(void){
1874 putc_unlocked('@', stdout);
1875 return 0;
1879 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1880 #include <unistd.h>
1881 int main(void){
1882 fchdir(0);
1883 return 0;
1887 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1888 #include <stdlib.h>
1889 int main(void){
1890 char x_buf[4096], *x = realpath(".", x_buf);
1892 return (x != NULL) ? 0 : 1;
1895 then
1896 if run_check realpath_malloc 'realpath(3) takes NULL' \
1897 '#define HAVE_REALPATH_NULL' << \!
1898 #include <stdlib.h>
1899 int main(void){
1900 char *x = realpath(".", NULL);
1902 if(x != NULL)
1903 free(x);
1904 return (x != NULL) ? 0 : 1;
1907 then
1913 ## optional and selectable
1916 if feat_yes DOTLOCK; then
1917 if run_check readlink 'readlink(2)' << \!
1918 #include <unistd.h>
1919 # include <errno.h>
1920 int main(void){
1921 char buf[128];
1923 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1924 return 0;
1925 return 1;
1928 then
1930 else
1931 feat_bail_required DOTLOCK
1935 if feat_yes DOTLOCK; then
1936 if run_check fchown 'fchown(2)' << \!
1937 #include <unistd.h>
1938 # include <errno.h>
1939 int main(void){
1940 if(!fchown(0, 0, 0) || errno != ENOSYS)
1941 return 0;
1942 return 1;
1945 then
1947 else
1948 feat_bail_required DOTLOCK
1952 if feat_yes DOTLOCK; then
1953 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1954 '#define HAVE_PRCTL_DUMPABLE' << \!
1955 #include <sys/prctl.h>
1956 # include <errno.h>
1957 int main(void){
1958 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1959 return 0;
1960 return 1;
1963 then
1965 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1966 '#define HAVE_PTRACE_DENY' << \!
1967 #include <sys/ptrace.h>
1968 # include <errno.h>
1969 int main(void){
1970 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1971 return 0;
1972 return 1;
1975 then
1977 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1978 '#define HAVE_SETPFLAGS_PROTECT' << \!
1979 #include <priv.h>
1980 # include <errno.h>
1981 int main(void){
1982 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1983 return 0;
1984 return 1;
1987 then
1992 ## Now it is the time to fork away the BASE_ series
1994 ${rm} -f ${tmp}
1995 squeeze_em ${inc} ${tmp}
1996 ${mv} ${tmp} ${inc}
1997 squeeze_em ${lib} ${tmp}
1998 ${mv} ${tmp} ${lib}
2000 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2001 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2003 ## The remains are expected to be used only by the main MUA binary!
2005 OPT_LOCALES=0
2006 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2007 #include <locale.h>
2008 int main(void){
2009 setlocale(LC_ALL, "");
2010 return 0;
2013 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2015 OPT_MULTIBYTE_CHARSETS=0
2016 OPT_WIDE_GLYPHS=0
2017 OPT_TERMINAL_CHARSET=0
2018 if [ -n "${have_setlocale}" ]; then
2019 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2020 '#define HAVE_C90AMEND1' << \!
2021 #include <limits.h>
2022 #include <stdlib.h>
2023 #include <wchar.h>
2024 #include <wctype.h>
2025 int main(void){
2026 char mbb[MB_LEN_MAX + 1];
2027 wchar_t wc;
2029 iswprint(L'c');
2030 towupper(L'c');
2031 mbtowc(&wc, "x", 1);
2032 mbrtowc(&wc, "x", 1, NULL);
2033 wctomb(mbb, wc);
2034 return (mblen("\0", 1) == 0);
2037 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2039 if [ -n "${have_c90amend1}" ]; then
2040 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2041 #include <wchar.h>
2042 int main(void){
2043 wcwidth(L'c');
2044 return 0;
2047 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2050 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2051 #include <langinfo.h>
2052 #include <stdlib.h>
2053 int main(void){
2054 nl_langinfo(DAY_1);
2055 return (nl_langinfo(CODESET) == NULL);
2058 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2059 fi # have_setlocale
2061 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2062 #include <fnmatch.h>
2063 int main(void){
2064 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2068 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2069 #include <dirent.h>
2070 int main(void){
2071 struct dirent de;
2072 return !(de.d_type == DT_UNKNOWN ||
2073 de.d_type == DT_DIR || de.d_type == DT_LNK);
2077 ## optional and selectable
2079 if feat_yes ICONV; then
2080 # To be able to create tests we need to figure out which replacement
2081 # sequence the iconv(3) implementation creates
2082 ${cat} > ${tmp2}.c << \!
2083 #include <stdio.h> /* For C89 NULL */
2084 #include <string.h>
2085 #include <iconv.h>
2086 int main(void){
2087 char inb[16], oub[16], *inbp, *oubp;
2088 iconv_t id;
2089 size_t inl, oul;
2091 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2092 inl = sizeof("\342\200\223") -1;
2093 oul = sizeof oub;
2094 oubp = oub;
2096 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2097 return 1;
2098 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2099 return 1;
2100 iconv_close(id);
2102 *oubp = '\0';
2103 oul = (size_t)(oubp - oub);
2104 if(oul == 0)
2105 return 1;
2106 /* Character-wise replacement? */
2107 if(oul == 1){
2108 if(oub[0] == '?')
2109 return 2;
2110 if(oub[0] == '*')
2111 return 3;
2112 return 1;
2114 /* Byte-wise replacement? */
2115 if(oul == sizeof("\342\200\223") -1){
2116 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2117 return 12;
2118 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2119 return 13;
2120 return 1;
2122 return 0;
2125 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2126 '#define HAVE_ICONV' ||
2127 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2128 '#define HAVE_ICONV' '-liconv' ||
2129 feat_bail_required ICONV
2131 if feat_no CROSS_BUILD; then
2132 { ./${tmp}; } >/dev/null 2>&1
2133 case ${?} in
2134 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2135 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2136 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2137 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2138 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2139 esac
2141 else
2142 feat_is_disabled ICONV
2143 fi # feat_yes ICONV
2145 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2146 ${cat} > ${tmp2}.c << \!
2147 #include <sys/types.h>
2148 #include <sys/socket.h>
2149 #include <sys/un.h>
2150 # include <errno.h>
2151 int main(void){
2152 struct sockaddr_un soun;
2154 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2155 return 1;
2156 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2157 return 1;
2158 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2159 return 1;
2160 return 0;
2164 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2165 '#define HAVE_UNIX_SOCKETS' ||
2166 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2167 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2168 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2169 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2172 if feat_yes SOCKETS; then
2173 ${cat} > ${tmp2}.c << \!
2174 #include <sys/types.h>
2175 #include <sys/socket.h>
2176 #include <netinet/in.h>
2177 # include <errno.h>
2178 int main(void){
2179 struct sockaddr s;
2181 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2182 return 1;
2183 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2184 return 1;
2185 return 0;
2189 < ${tmp2}.c run_check sockets 'sockets' \
2190 '#define HAVE_SOCKETS' ||
2191 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2192 '#define HAVE_SOCKETS' '-lnsl' ||
2193 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2194 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2195 feat_bail_required SOCKETS
2196 else
2197 feat_is_disabled SOCKETS
2198 fi # feat_yes SOCKETS
2200 if feat_yes SOCKETS; then
2201 link_check getaddrinfo 'getaddrinfo(3)' \
2202 '#define HAVE_GETADDRINFO' << \!
2203 #include <sys/types.h>
2204 #include <sys/socket.h>
2205 #include <stdio.h>
2206 #include <netdb.h>
2207 int main(void){
2208 struct addrinfo a, *ap;
2209 int lrv;
2211 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2212 case EAI_NONAME:
2213 case EAI_SERVICE:
2214 default:
2215 fprintf(stderr, "%s\n", gai_strerror(lrv));
2216 case 0:
2217 break;
2219 return 0;
2224 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2225 compile_check arpa_inet_h '<arpa/inet.h>' \
2226 '#define HAVE_ARPA_INET_H' << \!
2227 #include <sys/types.h>
2228 #include <sys/socket.h>
2229 #include <netdb.h>
2230 #include <netinet/in.h>
2231 #include <arpa/inet.h>
2234 ${cat} > ${tmp2}.c << \!
2235 #include <sys/types.h>
2236 #include <sys/socket.h>
2237 #include <stdio.h>
2238 #include <string.h>
2239 #include <netdb.h>
2240 #include <netinet/in.h>
2241 #ifdef HAVE_ARPA_INET_H
2242 #include <arpa/inet.h>
2243 #endif
2244 int main(void){
2245 struct sockaddr_in servaddr;
2246 unsigned short portno;
2247 struct servent *ep;
2248 struct hostent *hp;
2249 struct in_addr **pptr;
2251 portno = 0;
2252 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2253 portno = (unsigned short)ep->s_port;
2255 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2256 pptr = (struct in_addr**)hp->h_addr_list;
2257 if(hp->h_addrtype != AF_INET)
2258 fprintf(stderr, "au\n");
2259 }else{
2260 switch(h_errno){
2261 case HOST_NOT_FOUND:
2262 case TRY_AGAIN:
2263 case NO_RECOVERY:
2264 case NO_DATA:
2265 break;
2266 default:
2267 fprintf(stderr, "au\n");
2268 break;
2272 memset(&servaddr, 0, sizeof servaddr);
2273 servaddr.sin_family = AF_INET;
2274 servaddr.sin_port = htons(portno);
2275 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2276 fprintf(stderr, "Would connect to %s:%d ...\n",
2277 inet_ntoa(**pptr), (int)portno);
2278 return 0;
2282 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2283 < ${tmp2}.c link_check gethostbyname \
2284 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2285 < ${tmp2}.c link_check gethostbyname \
2286 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2287 '' '-lsocket -lnsl' ||
2288 feat_bail_required SOCKETS
2291 feat_yes SOCKETS &&
2292 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2293 #include <sys/socket.h>
2294 #include <stdlib.h>
2295 # include <errno.h>
2296 int main(void){
2297 int sockfd = 3;
2299 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2300 errno == ENOSYS)
2301 return 1;
2302 return 0;
2306 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2307 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2308 #include <sys/socket.h>
2309 #include <stdlib.h>
2310 int main(void){
2311 struct timeval tv;
2312 int sockfd = 3;
2314 tv.tv_sec = 42;
2315 tv.tv_usec = 21;
2316 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2317 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2318 return 0;
2322 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2323 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2324 #include <sys/socket.h>
2325 #include <stdlib.h>
2326 int main(void){
2327 struct linger li;
2328 int sockfd = 3;
2330 li.l_onoff = 1;
2331 li.l_linger = 42;
2332 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2333 return 0;
2337 VAL_SSL_FEATURES=
2338 if feat_yes SSL; then # {{{
2339 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2340 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2341 # time: we need to test it first in order to get things right
2342 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2343 '#define HAVE_SSL
2344 #define HAVE_XSSL
2345 #define HAVE_XSSL_RESSL
2346 #define HAVE_XSSL_OPENSSL 0' << \!
2347 #include <openssl/opensslv.h>
2348 #ifdef LIBRESSL_VERSION_NUMBER
2349 #else
2350 # error nope
2351 #endif
2353 then
2354 ossl_v1_1=
2355 VAL_SSL_FEATURES=libressl
2356 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2357 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2358 '#define HAVE_SSL
2359 #define HAVE_XSSL
2360 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2361 #include <openssl/opensslv.h>
2362 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2363 #else
2364 # error nope
2365 #endif
2367 then
2368 ossl_v1_1=1
2369 VAL_SSL_FEATURES=libssl-0x10100
2370 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2371 '#define HAVE_SSL
2372 #define HAVE_XSSL
2373 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2374 #include <openssl/opensslv.h>
2375 #ifdef OPENSSL_VERSION_NUMBER
2376 #else
2377 # error nope
2378 #endif
2380 then
2381 ossl_v1_1=
2382 VAL_SSL_FEATURES=libssl-0x10000
2383 else
2384 feat_bail_required SSL
2385 fi # }}}
2387 if feat_yes SSL; then # {{{
2388 if [ -n "${ossl_v1_1}" ]; then
2389 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2390 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2391 '-lssl -lcrypto'
2392 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2393 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2394 '-lssl -lcrypto' << \!
2395 #include <openssl/ssl.h>
2396 #include <openssl/err.h>
2397 #include <openssl/x509v3.h>
2398 #include <openssl/x509.h>
2399 #include <openssl/rand.h>
2400 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2401 # error We need TLSv1.
2402 #endif
2403 int main(void){
2404 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2406 SSL_CTX_free(ctx);
2407 PEM_read_PrivateKey(0, 0, 0, 0);
2408 return 0;
2411 then
2413 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2414 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2415 '-lssl -lcrypto' << \!
2416 #include <openssl/ssl.h>
2417 #include <openssl/err.h>
2418 #include <openssl/x509v3.h>
2419 #include <openssl/x509.h>
2420 #include <openssl/rand.h>
2421 #if defined OPENSSL_NO_SSL3 &&\
2422 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2423 # error We need one of SSLv3 and TLSv1.
2424 #endif
2425 int main(void){
2426 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2428 SSL_CTX_free(ctx);
2429 PEM_read_PrivateKey(0, 0, 0, 0);
2430 return 0;
2433 then
2435 else
2436 feat_bail_required SSL
2438 fi # }}}
2440 if feat_yes SSL; then # {{{
2441 if feat_yes SSL_ALL_ALGORITHMS; then
2442 if [ -n "${ossl_v1_1}" ]; then
2443 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2444 '#define HAVE_SSL_ALL_ALGORITHMS'
2445 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2446 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2447 #include <openssl/evp.h>
2448 int main(void){
2449 OpenSSL_add_all_algorithms();
2450 EVP_get_cipherbyname("two cents i never exist");
2451 EVP_cleanup();
2452 return 0;
2455 then
2457 else
2458 feat_bail_required SSL_ALL_ALGORITHMS
2460 elif [ -n "${ossl_v1_1}" ]; then
2461 without_check yes ssl_all_algo \
2462 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2463 '#define HAVE_SSL_ALL_ALGORITHMS'
2466 if [ -n "${ossl_v1_1}" ]; then
2467 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2468 '#define HAVE_XSSL_STACK_OF'
2469 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2470 '#define HAVE_XSSL_STACK_OF' << \!
2471 #include <stdio.h> /* For C89 NULL */
2472 #include <openssl/ssl.h>
2473 #include <openssl/err.h>
2474 #include <openssl/x509v3.h>
2475 #include <openssl/x509.h>
2476 #include <openssl/rand.h>
2477 int main(void){
2478 STACK_OF(GENERAL_NAME) *gens = NULL;
2480 printf("%p", gens); /* to use it */
2481 return 0;
2484 then
2488 if [ -n "${ossl_v1_1}" ]; then
2489 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2490 '#define HAVE_XSSL_CONFIG'
2491 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2492 elif link_check xssl_conf \
2493 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2494 '#define HAVE_XSSL_CONFIG' << \!
2495 #include <stdio.h> /* For C89 NULL */
2496 #include <openssl/conf.h>
2497 int main(void){
2498 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2499 CONF_modules_free();
2500 return 0;
2503 then
2504 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2505 else
2506 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2509 if [ -n "${ossl_v1_1}" ]; then
2510 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2511 '#define HAVE_XSSL_CONF_CTX'
2512 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2513 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2514 '#define HAVE_XSSL_CONF_CTX' << \!
2515 #include <openssl/ssl.h>
2516 #include <openssl/err.h>
2517 int main(void){
2518 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2519 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2521 SSL_CONF_CTX_set_flags(cctx,
2522 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2523 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2524 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2525 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2526 SSL_CONF_CTX_finish(cctx);
2527 SSL_CONF_CTX_free(cctx);
2528 SSL_CTX_free(ctx);
2529 return 0;
2532 then
2533 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2534 else
2535 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2538 if [ -n "${ossl_v1_1}" ]; then
2539 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2540 '#define HAVE_XSSL_CTX_CONFIG'
2541 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2542 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2543 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2544 '#define HAVE_XSSL_CTX_CONFIG' << \!
2545 #include <stdio.h> /* For C89 NULL */
2546 #include <openssl/ssl.h>
2547 int main(void){
2548 SSL_CTX_config(NULL, "SOMEVAL");
2549 return 0;
2552 then
2553 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2554 else
2555 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2558 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2559 without_check yes xssl_set_maxmin_proto \
2560 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2561 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2562 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2563 elif link_check xssl_set_maxmin_proto \
2564 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2565 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2566 #include <stdio.h> /* For C89 NULL */
2567 #include <openssl/ssl.h>
2568 int main(void){
2569 SSL_CTX_set_min_proto_version(NULL, 0);
2570 SSL_CTX_set_max_proto_version(NULL, 10);
2571 return 0;
2574 then
2575 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2576 else
2577 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2580 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2581 '#define HAVE_XSSL_RAND_EGD' << \!
2582 #include <openssl/rand.h>
2583 int main(void){
2584 return RAND_egd("some.where") > 0;
2587 then
2588 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2589 else
2590 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2592 fi # feat_yes SSL }}}
2594 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2595 run_check ssl_md5 'MD5 digest in the used crypto library' \
2596 '#define HAVE_XSSL_MD5' << \!
2597 #include <stdlib.h>
2598 #include <string.h>
2599 #include <openssl/md5.h>
2600 int main(void){
2601 char const dat[] = "abrakadabrafidibus";
2602 char dig[16], hex[16 * 2];
2603 MD5_CTX ctx;
2604 size_t i, j;
2606 memset(dig, 0, sizeof(dig));
2607 memset(hex, 0, sizeof(hex));
2608 MD5_Init(&ctx);
2609 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2610 MD5_Final(dig, &ctx);
2612 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2613 for(i = 0; i < sizeof(hex) / 2; i++){
2614 j = i << 1;
2615 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2616 hex[++j] = hexchar(dig[i] & 0x0f);
2618 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2621 fi # }}}
2623 if feat_yes SSL; then
2624 feat_def SSL_ALL_ALGORITHMS
2625 else
2626 feat_bail_required SSL_ALL_ALGORITHMS
2628 else
2629 feat_is_disabled SSL
2630 feat_is_disabled SSL_ALL_ALGORITHMS
2631 fi # }}} feat_yes SSL
2632 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2634 if [ "${have_xssl}" = yes ]; then
2635 OPT_SMIME=1
2636 else
2637 OPT_SMIME=0
2639 feat_def SMIME
2641 # VAL_RANDOM {{{
2642 if val_allof VAL_RANDOM \
2643 "arc4 ssl libgetrandom sysgetrandom urandom builtin error"; then
2645 else
2646 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2647 config_exit 1
2650 val_random_arc4() {
2651 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2652 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2653 #include <stdlib.h>
2654 int main(void){
2655 arc4random();
2656 return 0;
2661 val_random_ssl() {
2662 if feat_yes SSL; then
2663 msg ' . VAL_RANDOM: ssl ... yes'
2664 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2665 return 0
2666 else
2667 msg ' . VAL_RANDOM: ssl ... no'
2668 return 1
2672 val_random_libgetrandom() {
2673 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2674 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2675 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2676 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2677 #include <sys/random.h>
2678 int main(void){
2679 char buf[256];
2680 getrandom(buf, sizeof buf, 0);
2681 return 0;
2686 val_random_sysgetrandom() {
2687 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2688 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2689 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2690 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2691 #include <sys/syscall.h>
2692 int main(void){
2693 char buf[256];
2694 syscall(SYS_getrandom, buf, sizeof buf, 0);
2695 return 0;
2700 val_random_urandom() {
2701 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2702 if feat_yes CROSS_BUILD; then
2703 msg 'yes (unchecked)'
2704 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2705 elif [ -f /dev/urandom ]; then
2706 msg yes
2707 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2708 else
2709 msg no
2710 return 1
2712 return 0
2715 val_random_builtin() {
2716 msg_nonl ' . VAL_RANDOM: builtin ... '
2717 if [ -n "${have_no_subsecond_time}" ]; then
2718 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2719 'one of clock_gettime(2) and gettimeofday(2) is required.'
2720 config_exit 1
2721 else
2722 msg yes
2723 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2727 val_random_error() {
2728 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2729 config_exit 42
2732 oifs=${IFS}
2733 unset IFS
2734 VAL_RANDOM="${VAL_RANDOM} error"
2735 set -- ${VAL_RANDOM}
2736 IFS=${oifs}
2737 for randfun
2739 eval val_random_$randfun && break
2740 done
2741 # }}} VAL_RANDOM
2743 feat_def SMTP
2744 feat_def POP3
2745 feat_def IMAP
2747 if feat_yes GSSAPI; then
2748 ${cat} > ${tmp2}.c << \!
2749 #include <gssapi/gssapi.h>
2750 int main(void){
2751 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2752 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2753 return 0;
2756 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2758 if acmd_set i krb5-config; then
2759 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2760 GSS_INCS="`CFLAGS= ${i} --cflags`"
2761 i='GSS-API via krb5-config(1)'
2762 else
2763 GSS_LIBS='-lgssapi'
2764 GSS_INCS=
2765 i='GSS-API in gssapi/gssapi.h, libgssapi'
2767 if < ${tmp2}.c link_check gss \
2768 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2769 < ${tmp3}.c link_check gss \
2770 'GSS-API in gssapi.h, libgssapi' \
2771 '#define HAVE_GSSAPI
2772 #define GSSAPI_REG_INCLUDE' \
2773 '-lgssapi' ||\
2774 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2775 '#define HAVE_GSSAPI' \
2776 '-lgssapi_krb5' ||\
2777 < ${tmp3}.c link_check gss \
2778 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2779 '#define HAVE_GSSAPI
2780 #define GSS_REG_INCLUDE' \
2781 '-lgssapi -lkrb5 -lcrypto' \
2782 '-I/usr/include/kerberosV' ||\
2783 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2784 '#define HAVE_GSSAPI' \
2785 '-lgss' ||\
2786 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2787 '#define HAVE_GSSAPI
2788 #define GSSAPI_OLD_STYLE' \
2789 '-lgssapi_krb5' << \!
2790 #include <gssapi/gssapi.h>
2791 #include <gssapi/gssapi_generic.h>
2792 int main(void){
2793 gss_import_name(0, 0, gss_nt_service_name, 0);
2794 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2795 return 0;
2798 then
2800 else
2801 feat_bail_required GSSAPI
2803 else
2804 feat_is_disabled GSSAPI
2805 fi # feat_yes GSSAPI
2807 feat_def NETRC
2808 feat_def AGENT
2810 if feat_yes IDNA; then # {{{
2811 if val_allof VAL_IDNA "idnkit idn2 idn"; then
2813 else
2814 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2815 config_exit 1
2818 val_idna_idn2() {
2819 link_check idna 'OPT_IDNA: GNU Libidn2' \
2820 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2821 #include <idn2.h>
2822 int main(void){
2823 char *idna_utf8, *idna_lc;
2825 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2826 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2827 return 1;
2828 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2829 return 1;
2830 idn2_free(idna_lc);
2831 idn2_free(idna_utf8);
2832 return 0;
2837 val_idna_idn() {
2838 link_check idna 'OPT_IDNA: GNU Libidn' \
2839 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2840 #include <idna.h>
2841 #include <idn-free.h>
2842 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2843 int main(void){
2844 char *utf8, *idna_ascii, *idna_utf8;
2846 utf8 = stringprep_locale_to_utf8("does.this.work");
2847 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2848 != IDNA_SUCCESS)
2849 return 1;
2850 idn_free(idna_ascii);
2851 /* (Rather link check only here) */
2852 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2853 return 0;
2858 val_idna_idnkit() {
2859 link_check idna 'OPT_IDNA: idnkit' \
2860 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2861 #include <stdio.h>
2862 #include <idn/api.h>
2863 #include <idn/result.h>
2864 int main(void){
2865 idn_result_t r;
2866 char ace_name[256];
2867 char local_name[256];
2869 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2870 sizeof(ace_name));
2871 if (r != idn_success) {
2872 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2873 return 1;
2875 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2876 if (r != idn_success) {
2877 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2878 return 1;
2880 return 0;
2885 val_idna_bye() {
2886 feat_bail_required IDNA
2889 oifs=${IFS}
2890 unset IFS
2891 VAL_IDNA="${VAL_IDNA} bye"
2892 set -- ${VAL_IDNA}
2893 IFS=${oifs}
2894 for randfun
2896 eval val_idna_$randfun && break
2897 done
2898 else
2899 feat_is_disabled IDNA
2900 fi # }}} IDNA
2902 feat_def IMAP_SEARCH
2904 if feat_yes REGEX; then
2905 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2906 #include <regex.h>
2907 #include <stdlib.h>
2908 int main(void){
2909 size_t xret;
2910 int status;
2911 regex_t re;
2913 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2914 xret = regerror(status, &re, NULL, 0);
2915 status = regexec(&re, "plan9", 0,NULL, 0);
2916 regfree(&re);
2917 return !(status == REG_NOMATCH);
2920 then
2922 else
2923 feat_bail_required REGEX
2925 else
2926 feat_is_disabled REGEX
2929 if feat_yes MLE; then
2930 if [ -n "${have_c90amend1}" ]; then
2931 have_mle=1
2932 echo '#define HAVE_MLE' >> ${h}
2933 else
2934 feat_bail_required MLE
2936 else
2937 feat_is_disabled MLE
2940 # Generic have-a-line-editor switch for those who need it below
2941 if [ -n "${have_mle}" ]; then
2942 have_cle=1
2945 if feat_yes HISTORY; then
2946 if [ -n "${have_cle}" ]; then
2947 echo '#define HAVE_HISTORY' >> ${h}
2948 else
2949 feat_is_unsupported HISTORY
2951 else
2952 feat_is_disabled HISTORY
2955 if feat_yes KEY_BINDINGS; then
2956 if [ -n "${have_mle}" ]; then
2957 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2958 else
2959 feat_is_unsupported KEY_BINDINGS
2961 else
2962 feat_is_disabled KEY_BINDINGS
2965 if feat_yes TERMCAP; then
2966 __termcaplib() {
2967 link_check termcap "termcap(5) (via ${4})" \
2968 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2969 #include <stdio.h>
2970 #include <stdlib.h>
2971 ${2}
2972 #include <term.h>
2973 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2974 static int my_putc(int c){return putchar(c);}
2975 int main(void){
2976 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2977 int r2 = OK, r3 = ERR;
2979 tgetent(buf, getenv("TERM"));
2980 cpb = cmdbuf;
2981 r1 = tgetstr(UNCONST("cm"), &cpb);
2982 tgoto(r1, 1, 1);
2983 r2 = tgetnum(UNCONST("Co"));
2984 r3 = tgetflag(UNCONST("ut"));
2985 tputs("cr", 1, &my_putc);
2986 return (r1 == NULL || r2 == -1 || r3 == 0);
2988 _EOT
2991 __terminfolib() {
2992 link_check terminfo "terminfo(5) (via ${2})" \
2993 '#define HAVE_TERMCAP
2994 #define HAVE_TERMCAP_CURSES
2995 #define HAVE_TERMINFO' "${1}" << _EOT
2996 #include <stdio.h>
2997 #include <curses.h>
2998 #include <term.h>
2999 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3000 static int my_putc(int c){return putchar(c);}
3001 int main(void){
3002 int er, r0, r1, r2;
3003 char *r3, *tp;
3005 er = OK;
3006 r0 = setupterm(NULL, 1, &er);
3007 r1 = tigetflag(UNCONST("bce"));
3008 r2 = tigetnum(UNCONST("colors"));
3009 r3 = tigetstr(UNCONST("cr"));
3010 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3011 tputs(tp, 1, &my_putc);
3012 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3013 r3 == (char*)-1 || r3 == NULL);
3015 _EOT
3018 if feat_yes TERMCAP_VIA_TERMINFO; then
3019 __terminfolib -ltinfo -ltinfo ||
3020 __terminfolib -lcurses -lcurses ||
3021 __terminfolib -lcursesw -lcursesw ||
3022 feat_bail_required TERMCAP_VIA_TERMINFO
3025 if [ -z "${have_terminfo}" ]; then
3026 __termcaplib -ltermcap '' '' '-ltermcap' ||
3027 __termcaplib -ltermcap '#include <curses.h>' '
3028 #define HAVE_TERMCAP_CURSES' \
3029 'curses.h / -ltermcap' ||
3030 __termcaplib -lcurses '#include <curses.h>' '
3031 #define HAVE_TERMCAP_CURSES' \
3032 'curses.h / -lcurses' ||
3033 __termcaplib -lcursesw '#include <curses.h>' '
3034 #define HAVE_TERMCAP_CURSES' \
3035 'curses.h / -lcursesw' ||
3036 feat_bail_required TERMCAP
3038 if [ -n "${have_termcap}" ]; then
3039 run_check tgetent_null \
3040 "tgetent(3) of termcap(5) takes NULL buffer" \
3041 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3042 #include <stdio.h> /* For C89 NULL */
3043 #include <stdlib.h>
3044 #ifdef HAVE_TERMCAP_CURSES
3045 # include <curses.h>
3046 #endif
3047 #include <term.h>
3048 int main(void){
3049 tgetent(NULL, getenv("TERM"));
3050 return 0;
3052 _EOT
3055 else
3056 feat_is_disabled TERMCAP
3057 feat_is_disabled TERMCAP_VIA_TERMINFO
3060 if feat_def SPAM_SPAMC; then
3061 if acmd_set i spamc; then
3062 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3066 if feat_yes SPAM_SPAMD; then
3067 if [ -n "${have_af_unix}" ]; then
3068 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3069 else
3070 feat_bail_required SPAM_SPAMD
3072 else
3073 feat_is_disabled SPAM_SPAMD
3076 feat_def SPAM_FILTER
3078 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3079 echo '#define HAVE_SPAM' >> ${h}
3080 else
3081 echo '/* HAVE_SPAM */' >> ${h}
3084 if feat_yes QUOTE_FOLD; then
3085 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3086 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3087 else
3088 feat_bail_required QUOTE_FOLD
3090 else
3091 feat_is_disabled QUOTE_FOLD
3094 feat_def FILTER_HTML_TAGSOUP
3095 feat_def COLOUR
3096 feat_def DOTLOCK
3097 feat_def MD5
3099 ## Summarizing
3101 ${rm} -f ${tmp}
3102 squeeze_em ${inc} ${tmp}
3103 ${mv} ${tmp} ${inc}
3104 squeeze_em ${lib} ${tmp}
3105 ${mv} ${tmp} ${lib}
3107 # mk-config.h
3108 ${mv} ${h} ${tmp}
3109 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3110 ${cat} ${tmp} >> ${h}
3111 printf '\n' >> ${h}
3112 # We need these for correct "second stage configuration changed" detection */
3113 echo "/* `${cat} ${lib}` */" >> ${h}
3114 echo "/* `${cat} ${inc}` */" >> ${h}
3115 printf '\n' >> ${h}
3117 # Throw away all temporaries
3118 ${rm} -rf ${tmp0}.* ${tmp0}*
3120 # Create the string that is used by *features* and `version'.
3121 # Take this nice opportunity and generate a visual listing of included and
3122 # non-included features for the person who runs the configuration
3123 echo 'The following features are included (+) or not (-):' > ${tmp}
3124 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3125 printf '/* The "feature string" */\n' >> ${h}
3126 # Because + is expanded by *folder* if first in "echo $features", put something
3127 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3128 sep=
3129 for opt
3131 sdoc=`option_doc_of ${opt}`
3132 [ -z "${sdoc}" ] && continue
3133 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3134 feat_yes ${opt} && sign=+ || sign=-
3135 printf -- "${sep}${sign}${sopt}" >> ${h}
3136 sep=','
3137 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3138 done
3139 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3140 #exec 5>&1 >>${h}
3141 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3142 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3143 printf '"\n' >> ${h}
3145 # Create the real mk-config.mk
3146 # Note we cannout use explicit ./ filename prefix for source and object
3147 # pathnames because of a bug in bmake(1)
3148 srclist= objlist=
3149 if feat_no AMALGAMATION; then
3150 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3151 i=`basename "${i}" .c`
3152 if [ "${i}" = privsep ]; then
3153 continue
3155 objlist="${objlist} ${i}.o"
3156 srclist="${srclist} \$(SRCDIR)${i}.c"
3157 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3158 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3159 done
3160 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3161 else
3162 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3163 "main.o" "main.c" >> ${mk}
3164 srclist=main.c objlist=main.o
3165 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3167 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3168 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3169 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3170 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3171 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3172 i=`basename "${i}"`
3173 if [ "${i}" = main.c ] ||
3174 [ "${i}" = privsep.c ]; then
3175 continue
3177 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3178 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3179 done
3180 echo >> ${mk}
3182 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3184 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3186 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3187 echo "INCS = `${cat} ${inc}`" >> ${mk}
3188 echo >> ${mk}
3189 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3191 ## Finished!
3193 # We have completed the new configuration header. Check whether *really*
3194 # Do the "second stage configuration changed" detection, exit if nothing to do
3195 if [ -f ${oldh} ]; then
3196 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3197 ${mv} -f ${oldh} ${h}
3198 msg 'Effective configuration is up-to-date'
3199 exit 0
3201 config_updated=1
3202 ${rm} -f ${oldh}
3203 msg 'Effective configuration has been updated..'
3206 if [ -n "${config_updated}" ]; then
3207 msg 'Wiping away old objects and such'
3208 ( eval "${MAKE} -f ${oldmk} clean" )
3211 msg ''
3212 while read l; do msg "${l}"; done < ${tmp}
3214 msg 'Setup:'
3215 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3216 msg ' . bindir: %s' "${VAL_BINDIR}"
3217 if feat_yes DOTLOCK; then
3218 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3220 msg ' . mandir: %s' "${VAL_MANDIR}"
3221 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3222 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3224 msg ''
3225 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3226 exit 0
3228 msg 'Remarks:'
3229 if [ -z "${have_fnmatch}" ]; then
3230 msg ' . The function fnmatch(3) could not be found.'
3231 msg ' Filename patterns like wildcard are not supported on your system'
3233 if [ -z "${have_fchdir}" ]; then
3234 msg ' . The function fchdir(2) could not be found.'
3235 msg ' We will use chdir(2) instead.'
3236 msg ' This is a problem only if the current working directory is changed'
3237 msg ' while this program is inside of it'
3239 msg ''
3241 # s-it-mode