Bump S-nail v14.9.9.ar ("Marsh tit savours first spring sun, II"), 2018-03-06
[s-mailx.git] / make-config.sh
blob5b5a2d7f3319ea325e4bb27a3c71f991857a52d5
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_RANDOM='-' \
26 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
27 SMTP='Simple Mail Transfer Protocol client' \
28 POP3='Post Office Protocol Version 3 client' \
29 IMAP='IMAP v4r1 client' \
30 GSSAPI='Generic Security Service authentication' \
31 NETRC='.netrc file support' \
32 AGENT='-' \
33 MD5='MD5 message digest (APOP, CRAM-MD5)' \
34 IDNA='Internationalized Domain Names for Applications (encode only)' \
35 IMAP_SEARCH='IMAP-style search expressions' \
36 REGEX='Regular expressions' \
37 MLE='Mailx Line Editor' \
38 HISTORY='Line editor history management' \
39 KEY_BINDINGS='Configurable key bindings' \
40 TERMCAP='Terminal capability queries (termcap(5))' \
41 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
42 ERRORS='Error log message ring' \
43 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
44 SPAM_SPAMD='-' \
45 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
46 DOCSTRINGS='Command documentation help 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
108 [mM][iI][nN][iI][mM][aA][lL])
109 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
110 OPT_COLOUR=1
111 OPT_DOCSTRINGS=1
112 OPT_ERRORS=1
113 OPT_IDNA=1
114 OPT_MLE=1
115 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
116 OPT_SPAM_FILTER=1
118 [nN][eE][tT][sS][eE][nN][dD])
119 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
120 OPT_SOCKETS=require
121 OPT_SSL=require
122 OPT_SMTP=require
123 OPT_GSSAPI=1 OPT_NETRC=1
124 OPT_AGENT=1
125 OPT_COLOUR=1
126 OPT_DOCSTRINGS=1
127 OPT_ERRORS=1
128 OPT_IDNA=1
129 OPT_MLE=1
130 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
131 OPT_SPAM_FILTER=1
133 [mM][aA][xX][iI][mM][aA][lL])
134 option_maximal
136 [dD][eE][vV][eE][lL])
137 option_maximal
138 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
140 [oO][dD][eE][vV][eE][lL])
141 option_maximal
142 OPT_DEVEL=1
145 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
146 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
147 exit 1
149 esac
150 msg_nonl "CONFIG=${CONFIG} ... "
154 # Inter-relationships XXX sort this!
155 option_update() {
156 if feat_yes NOEXTRANDOM; then
157 OPT_SSL_RANDOM=0
160 if feat_no SSL; then
161 OPT_SSL_RANDOM=0 OPT_SSL_ALL_ALGORITHMS=0
164 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
165 OPT_SOCKETS=0
167 if feat_no SOCKETS; then
168 if feat_require SMTP; then
169 msg 'ERROR: need SOCKETS for required feature SMTP'
170 config_exit 13
172 if feat_require POP3; then
173 msg 'ERROR: need SOCKETS for required feature POP3'
174 config_exit 13
176 if feat_require IMAP; then
177 msg 'ERROR: need SOCKETS for required feature IMAP'
178 config_exit 13
180 OPT_SSL=0 OPT_SSL_RANDOM=0 OPT_SSL_ALL_ALGORITHMS=0
181 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
182 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
184 if feat_no SMTP && feat_no IMAP; then
185 OPT_GSSAPI=0
188 if feat_no ICONV; then
189 if feat_yes IMAP; then
190 if feat_yes ALWAYS_UNICODE_LOCALE; then
191 msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
192 elif feat_require IMAP; then
193 msg 'ERROR: need ICONV for required feature IMAP'
194 config_exit 13
195 else
196 msg 'ERROR: disabling IMAP due to missing ICONV'
197 OPT_IMAP=0
201 if feat_yes IDNA; then
202 if feat_require IDNA; then
203 msg 'ERROR: need ICONV for required feature IDNA'
204 config_exit 13
206 msg 'ERROR: disabling IDNA due to missing ICONV'
207 OPT_IDNA=0
211 if feat_no MLE; then
212 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
215 # If we don't need MD5 leave it alone
216 if feat_no SOCKETS; then
217 OPT_MD5=0
220 if feat_no TERMCAP; then
221 OPT_TERMCAP_VIA_TERMINFO=0
224 if feat_yes DEVEL; then
225 OPT_DEBUG=1
229 rc=./make.rc
230 lst=./mk-config.lst
231 ev=./mk-config.ev
232 h=./mk-config.h h_name=mk-config.h
233 mk=./mk-config.mk
235 newlst=./mk-nconfig.lst
236 newmk=./mk-nconfig.mk
237 newev=./mk-nconfig.ev
238 newh=./mk-nconfig.h
239 tmp0=___tmp
240 tmp=./${tmp0}1$$
241 tmp2=./${tmp0}2$$
243 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
245 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
246 # via path_check() later on once possible
248 # TODO cc_maxopt is brute simple, we should compile test program and dig real
249 # compiler versions for known compilers, then be more specific
250 [ -n "${cc_maxopt}" ] || cc_maxopt=100
251 #cc_force_no_stackprot=
252 #ld_need_R_flags=
253 #ld_no_bind_now=
254 #ld_rpath_not_runpath=
256 _CFLAGS= _LDFLAGS=
258 os_early_setup() {
259 # We don't "have any utility": only path adjustments and such in here!
260 [ -n "${OS}" ] || OS=`${uname} -s`
261 export OS
263 if [ ${OS} = SunOS ]; then
264 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
265 _os_early_setup_sunos
269 _os_early_setup_sunos() {
270 # According to standards(5), this is what we need to do
271 if [ -d /usr/xpg4 ]; then :; else
272 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
273 config_exit 1
275 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
276 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
277 export PATH
280 os_setup() {
281 # OSENV ends up in *build-osenv*
282 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
283 # etc.), it is not baked into the binary
284 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
285 [ -n "${OSENV}" ] || OSENV=`${uname} -sm`
286 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
287 msg 'Operating system is %s' ${OS}
289 if [ ${OS} = darwin ]; then
290 msg ' . have special Darwin environmental addons...'
291 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
292 elif [ ${OS} = sunos ]; then
293 msg ' . have special SunOS / Solaris "setup" rules ...'
294 _os_setup_sunos
295 elif [ ${OS} = unixware ]; then
296 if feat_yes AUTOCC && acmd_set CC cc; then
297 msg ' . have special UnixWare environmental rules ...'
298 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
300 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
301 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
302 export CC CFLAGS LDFLAGS
303 OPT_AUTOCC=0 ld_need_R_flags=-R
305 elif [ -n "${VERBOSE}" ]; then
306 msg ' . no special treatment for this system necessary or known'
309 # Sledgehammer: better set _GNU_SOURCE
310 # And in general: oh, boy!
311 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
312 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
313 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
314 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
316 # On pkgsrc(7) systems automatically add /usr/pkg/*
317 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
318 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
319 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
320 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
321 ld_rpath_not_runpath=1
325 _os_setup_sunos() {
326 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
327 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
329 # Include packages
330 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
331 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
332 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
333 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
334 ld_no_bind_now=1 ld_rpath_not_runpath=1
336 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
337 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
338 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
339 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
340 ld_no_bind_now=1 ld_rpath_not_runpath=1
343 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
344 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
346 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
347 if [ -x "${cksum}" ]; then :; else
348 msg 'ERROR: Not an executable program: %s' "${cksum}"
349 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
350 msg 'ERROR: However, we do so only for tests.'
351 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
352 config_exit 1
355 if feat_yes AUTOCC; then
356 if acmd_set CC cc; then
357 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
359 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
360 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
361 export CC CFLAGS LDFLAGS
362 OPT_AUTOCC=0 ld_need_R_flags=-R
363 else
364 cc_maxopt=2 cc_force_no_stackprot=1
369 # Check out compiler ($CC) and -flags ($CFLAGS)
370 cc_setup() {
371 # Even though it belongs into cc_flags we will try to compile and link
372 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
373 # EXTRA_CFLAGS/EXTRA_LDFLAGS
374 if feat_no AUTOCC; then
375 _cc_default
376 # Ensure those don't do any harm
377 EXTRA_CFLAGS= EXTRA_LDFLAGS=
378 export EXTRA_CFLAGS EXTRA_LDFLAGS
379 return
380 else
381 CFLAGS= LDFLAGS=
382 export CFLAGS LDFLAGS
385 [ -n "${CC}" ] && { _cc_default; return; }
387 msg_nonl 'Searching for a usable C compiler .. $CC='
388 if acmd_set CC clang || acmd_set CC gcc ||
389 acmd_set CC tcc || acmd_set CC pcc ||
390 acmd_set CC c89 || acmd_set CC c99; then
392 else
393 msg 'boing booom tschak'
394 msg 'ERROR: I cannot find a compiler!'
395 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
396 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
397 config_exit 1
399 msg '%s' "${CC}"
400 export CC
403 _cc_default() {
404 if [ -z "${CC}" ]; then
405 msg 'To go on like you have chosen, please set $CC, rerun.'
406 config_exit 1
409 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
411 else
412 msg 'Using C compiler ${CC}=%s' "${CC}"
416 cc_flags() {
417 if feat_yes AUTOCC; then
418 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
419 cc_check_silent=1
420 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
421 "${CC}"
422 else
423 cc_check_silent=
424 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
427 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
428 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
429 msg ' . have special tcc(1) environmental rules ...'
430 _cc_flags_tcc
431 else
432 # As of pcc CVS 2016-04-02, stack protection support is announced but
433 # will break if used on Linux
434 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
435 cc_force_no_stackprot=1
437 _cc_flags_generic
440 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
441 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
442 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
443 else
444 if feat_no DEBUG; then
445 CFLAGS="-DNDEBUG ${CFLAGS}"
448 msg ''
449 export CFLAGS LDFLAGS
452 _cc_flags_tcc() {
453 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
454 _CFLAGS= _LDFLAGS=
456 cc_check -Wall
457 cc_check -Wextra
458 cc_check -pedantic
460 if feat_yes DEBUG; then
461 # May have problems to find libtcc cc_check -b
462 cc_check -g
465 if ld_check -Wl,-rpath =./ no; then
466 ld_need_R_flags=-Wl,-rpath=
467 if [ -z "${ld_rpath_not_runpath}" ]; then
468 ld_check -Wl,--enable-new-dtags
469 else
470 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
472 ld_runtime_flags # update!
475 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
476 unset __cflags __ldflags
479 _cc_flags_generic() {
480 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
481 _CFLAGS= _LDFLAGS=
482 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
484 # E.g., valgrind does not work well with high optimization
485 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
486 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
487 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
488 cc_maxopt=1
490 # Check -g first since some others may rely upon -g / optim. level
491 if feat_yes DEBUG; then
492 cc_check -O
493 cc_check -g
494 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
496 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
498 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
500 else
501 cc_check -O
504 if feat_yes AMALGAMATION; then
505 cc_check -pipe
508 #if feat_yes DEVEL && cc_check -Weverything; then
510 #else
511 cc_check -Wall
512 cc_check -Wextra
513 cc_check -Wbad-function-cast
514 cc_check -Wcast-align
515 cc_check -Wcast-qual
516 cc_check -Winit-self
517 cc_check -Wmissing-prototypes
518 cc_check -Wshadow
519 cc_check -Wunused
520 cc_check -Wwrite-strings
521 cc_check -Wno-long-long
523 cc_check -pedantic
525 if feat_yes AMALGAMATION && feat_no DEVEL; then
526 cc_check -Wno-unused-function
528 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
530 cc_check -fno-unwind-tables
531 cc_check -fno-asynchronous-unwind-tables
532 cc_check -fstrict-aliasing
533 if cc_check -fstrict-overflow && feat_yes DEVEL; then
534 cc_check -Wstrict-overflow=5
537 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
538 if [ -z "${cc_force_no_stackprot}" ]; then
539 if cc_check -fstack-protector-strong ||
540 cc_check -fstack-protector-all; then
541 cc_check -D_FORTIFY_SOURCE=2
543 else
544 msg ' ! Not checking for -fstack-protector compiler option,'
545 msg ' ! since that caused errors in a "similar" configuration.'
546 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
550 # LD (+ dependend CC)
552 if feat_yes ASAN_ADDRESS; then
553 _ccfg=${_CFLAGS}
554 if cc_check -fsanitize=address &&
555 ld_check -fsanitize=address; then
557 else
558 feat_bail_required ASAN_ADDRESS
559 _CFLAGS=${_ccfg}
563 if feat_yes ASAN_MEMORY; then
564 _ccfg=${_CFLAGS}
565 if cc_check -fsanitize=memory &&
566 ld_check -fsanitize=memory &&
567 cc_check -fsanitize-memory-track-origins=2 &&
568 ld_check -fsanitize-memory-track-origins=2; then
570 else
571 feat_bail_required ASAN_MEMORY
572 _CFLAGS=${_ccfg}
576 ld_check -Wl,-z,relro
577 if [ -z "${ld_no_bind_now}" ]; then
578 ld_check -Wl,-z,now
579 else
580 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
582 ld_check -Wl,-z,noexecstack
583 if ld_check -Wl,-rpath =./ no; then
584 ld_need_R_flags=-Wl,-rpath=
585 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
586 if [ -z "${ld_rpath_not_runpath}" ]; then
587 ld_check -Wl,--enable-new-dtags
588 else
589 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
591 ld_runtime_flags # update!
592 elif ld_check -Wl,-R ./ no; then
593 ld_need_R_flags=-Wl,-R
594 if [ -z "${ld_rpath_not_runpath}" ]; then
595 ld_check -Wl,--enable-new-dtags
596 else
597 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
599 ld_runtime_flags # update!
602 # Address randomization
603 _ccfg=${_CFLAGS}
604 if cc_check -fPIE || cc_check -fpie; then
605 ld_check -pie || _CFLAGS=${_ccfg}
607 unset _ccfg
609 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
610 unset __cflags __ldflags
613 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
615 ## Notes:
616 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
617 ## redirection, so use "printf '' >" instead
619 ## Very first: we undergo several states regarding I/O redirection etc.,
620 ## but need to deal with option updates from within all. Since all the
621 ## option stuff should be above the scissor line, define utility functions
622 ## and redefine them as necessary.
623 ## And, since we have those functions, simply use them for whatever
625 t1=ten10one1ten10one1
626 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
627 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
628 ) > /dev/null 2>&1; then
629 good_shell=1
630 else
631 unset good_shell
633 unset t1
635 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
637 config_exit() {
638 exit ${1}
641 # which(1) not standardized, command(1) -v may return non-executable: unroll!
642 acmd_test() { __acmd "${1}" 1 0 0; }
643 acmd_test_fail() { __acmd "${1}" 1 1 0; }
644 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
645 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
646 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
647 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
648 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
649 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
650 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
651 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
652 __acmd() {
653 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
655 if [ "${dotest}" -ne 0 ]; then
656 eval dotest=\$${varname}
657 if [ -n "${dotest}" ]; then
658 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
659 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
660 return 0
664 oifs=${IFS} IFS=:
665 [ -n "${noglob_shell}" ] && set -o noglob
666 set -- ${PATH}
667 [ -n "${noglob_shell}" ] && set +o noglob
668 IFS=${oifs}
669 for path
671 if [ -z "${path}" ] || [ "${path}" = . ]; then
672 if [ -d "${PWD}" ]; then
673 path=${PWD}
674 else
675 path=.
678 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
679 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
680 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
681 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
682 return 0
684 done
686 # We may have no builtin string functions, we yet have no programs we can
687 # use, try to access once from the root, assuming it is an absolute path if
688 # that finds the executable
689 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
690 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
691 msg ' . ${%s} ... %s' "${pname}" "${pname}"
692 [ -n "${varname}" ] && eval ${varname}="${pname}"
693 return 0
696 [ ${dofail} -eq 0 ] && return 1
697 msg 'ERROR: no trace of utility '"${pname}"
698 exit 1
701 msg() {
702 fmt=${1}
703 shift
704 printf >&2 -- "${fmt}\\n" "${@}"
707 msg_nonl() {
708 fmt=${1}
709 shift
710 printf >&2 -- "${fmt}" "${@}"
713 # Our feature check environment
714 feat_val_no() {
715 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
716 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
719 feat_val_yes() {
720 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
721 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
722 [ "x${1}" = xrequire ]
725 feat_val_require() {
726 [ "x${1}" = xrequire ]
729 _feat_check() {
730 eval i=\$OPT_${1}
731 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
732 if feat_val_no "${i}"; then
733 return 1
734 elif feat_val_yes "${i}"; then
735 return 0
736 else
737 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
738 "${1}" "${i}"
739 config_exit 11
743 feat_yes() {
744 _feat_check ${1}
747 feat_no() {
748 _feat_check ${1} && return 1
749 return 0
752 feat_require() {
753 eval i=\$OPT_${1}
754 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
755 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
758 feat_bail_required() {
759 if feat_require ${1}; then
760 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
761 config_exit 13
763 eval OPT_${1}=0
764 option_update # XXX this is rather useless here (dependency chain..)
767 option_parse() {
768 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
769 # options, without documentation, to $1
770 j=\'
771 i="`${awk} -v input=\"${2}\" '
772 BEGIN{
773 for(i = 0;;){
774 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
775 if(voff == 0)
776 break
777 v = substr(input, voff, RLENGTH)
778 input = substr(input, voff + RLENGTH)
779 doff = index(v, "=")
780 if(doff > 0){
781 d = substr(v, doff + 2, length(v) - doff - 1)
782 v = substr(v, 1, doff - 1)
784 print v
788 eval ${1}=\"${i}\"
791 option_doc_of() {
792 # Return the "documentation string" for option $1, itself if none such
793 j=\'
794 ${awk} -v want="${1}" \
795 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
796 BEGIN{
797 for(;;){
798 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
799 if(voff == 0)
800 break
801 v = substr(input, voff, RLENGTH)
802 input = substr(input, voff + RLENGTH)
803 doff = index(v, "=")
804 if(doff > 0){
805 d = substr(v, doff + 2, length(v) - doff - 1)
806 v = substr(v, 1, doff - 1)
807 }else
808 d = v
809 if(v == want){
810 if(d != "-")
811 print d
812 exit
819 option_join_rc() {
820 # Join the values from make.rc into what currently is defined, not
821 # overwriting yet existing settings
822 ${rm} -f ${tmp}
823 # We want read(1) to perform reverse solidus escaping in order to be able to
824 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
825 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
826 < ${rc} ${awk} 'BEGIN{line = ""}{
827 gsub(/^[[:space:]]+/, "", $0)
828 gsub(/[[:space:]]+$/, "", $0)
829 if(gsub(/\\$/, "", $0)){
830 line = line $0
831 next
832 }else
833 line = line $0
834 if(index(line, "#") == 1){
835 line = ""
836 }else if(length(line)){
837 print line
838 line = ""
840 }' |
841 while read line; do
842 if [ -n "${good_shell}" ]; then
843 i=${line%%=*}
844 else
845 i=`${awk} -v LINE="${line}" 'BEGIN{
846 gsub(/=.*$/, "", LINE)
847 print LINE
850 if [ "${i}" = "${line}" ]; then
851 msg 'ERROR: invalid syntax in: %s' "${line}"
852 continue
855 eval j="\$${i}" jx="\${${i}+x}"
856 if [ -n "${j}" ] || [ "${jx}" = x ]; then
857 : # Yet present
858 else
859 j=`${awk} -v LINE="${line}" 'BEGIN{
860 gsub(/^[^=]*=/, "", LINE)
861 gsub(/^\"*/, "", LINE)
862 gsub(/\"*$/, "", LINE)
863 print LINE
866 [ "${i}" = "DESTDIR" ] && continue
867 echo "${i}=\"${j}\""
868 done > ${tmp}
869 # Reread the mixed version right now
870 . ./${tmp}
873 option_evaluate() {
874 # Expand the option values, which may contain shell snippets
875 ${rm} -f ${newlst} ${newmk} ${newh}
876 exec 5<&0 6>&1 <${tmp} >${newlst}
877 while read line; do
879 if [ -n "${good_shell}" ]; then
880 i=${line%%=*}
881 [ "${i}" != "${i#OPT_}" ] && z=1
882 else
883 i=`${awk} -v LINE="${line}" 'BEGIN{
884 gsub(/=.*$/, "", LINE);\
885 print LINE
887 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
892 eval j=\$${i}
893 if [ -n "${z}" ]; then
894 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
895 if [ -z "${j}" ] || feat_val_no "${j}"; then
897 printf " /* #undef ${i} */\n" >> ${newh}
898 elif feat_val_yes "${j}"; then
899 if feat_val_require "${j}"; then
900 j=require
901 else
904 printf " /* #define ${i} */\n" >> ${newh}
905 else
906 msg 'ERROR: cannot parse <%s>' "${line}"
907 config_exit 1
909 else
910 printf "#define ${i} \"${j}\"\n" >> ${newh}
912 printf "${i} = ${j}\n" >> ${newmk}
913 printf "${i}=${j}\n"
914 eval "${i}=\"${j}\""
915 done
916 exec 0<&5 1>&6 5<&- 6<&-
919 path_check() {
920 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
921 varname=${1} addflag=${2} flagvarname=${3}
922 j=${IFS}
923 IFS=:
924 [ -n "${noglob_shell}" ] && set -o noglob
925 eval "set -- \$${1}"
926 [ -n "${noglob_shell}" ] && set +o noglob
927 IFS=${j}
928 j= k= y= z=
929 for i
931 [ -z "${i}" ] && continue
932 [ -d "${i}" ] || continue
933 if [ -n "${j}" ]; then
934 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
936 else
937 y="${y} :${i}:"
938 j="${j}:${i}"
939 # But do not link any fakeroot path into our binaries!
940 if [ -n "${addflag}" ]; then
941 case "${i}" in *fakeroot*) continue;; esac
942 k="${k} ${addflag}${i}"
945 else
946 y=" :${i}:"
947 j="${i}"
948 # But do not link any fakeroot path into our binaries!
949 if [ -n "${addflag}" ]; then
950 case "${i}" in *fakeroot*) continue;; esac
951 k="${k} ${addflag}${i}"
954 done
955 eval "${varname}=\"${j}\""
956 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
957 unset varname
960 ld_runtime_flags() {
961 if [ -n "${ld_need_R_flags}" ]; then
962 i=${IFS}
963 IFS=:
964 set -- ${LD_LIBRARY_PATH}
965 IFS=${i}
966 for i
968 # But do not link any fakeroot path into our binaries!
969 case "${i}" in *fakeroot*) continue;; esac
970 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
971 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
972 done
973 export LDFLAGS
975 # Disable it for a possible second run.
976 ld_need_R_flags=
979 cc_check() {
980 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
981 if "${CC}" ${INCS} \
982 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
983 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
984 _CFLAGS="${_CFLAGS} ${1}"
985 [ -n "${cc_check_silent}" ] || msg 'yes'
986 return 0
988 [ -n "${cc_check_silent}" ] || msg 'no'
989 return 1
992 ld_check() {
993 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
994 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
995 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
996 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
997 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
998 [ -n "${cc_check_silent}" ] || msg 'yes'
999 return 0
1001 [ -n "${cc_check_silent}" ] || msg 'no'
1002 return 1
1005 dump_test_program=1
1006 _check_preface() {
1007 variable=$1 topic=$2 define=$3
1009 echo '**********'
1010 msg_nonl ' . %s ... ' "${topic}"
1011 echo "/* checked ${topic} */" >> ${h}
1012 ${rm} -f ${tmp} ${tmp}.o
1013 if [ "${dump_test_program}" = 1 ]; then
1014 echo '*** test program is'
1015 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1016 else
1017 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1019 #echo '*** the preprocessor generates'
1020 #${make} -f ${makefile} ${tmp}.x
1021 #${cat} ${tmp}.x
1022 echo '*** tests results'
1025 without_check() {
1026 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1028 echo '**********'
1029 msg_nonl ' . %s ... ' "${topic}"
1031 echo '*** enforced unchecked results are'
1032 if feat_val_yes ${yesno}; then
1033 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1034 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1035 LIBS="${LIBS} ${libs}"
1036 echo "${libs}" >> ${lib}
1037 INCS="${INCS} ${incs}"
1038 echo "${incs}" >> ${inc}
1040 msg 'yes (deduced)'
1041 echo "${define}" >> ${h}
1042 eval have_${variable}=yes
1043 return 0
1044 else
1045 echo "/* ${define} */" >> ${h}
1046 msg 'no (deduced)'
1047 eval unset have_${variable}
1048 return 1
1052 compile_check() {
1053 variable=$1 topic=$2 define=$3
1055 _check_preface "${variable}" "${topic}" "${define}"
1057 if ${make} -f ${makefile} XINCS="${INCS}" \
1058 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1059 ./${tmp}.o &&
1060 [ -f ./${tmp}.o ]; then
1061 msg 'yes'
1062 echo "${define}" >> ${h}
1063 eval have_${variable}=yes
1064 return 0
1065 else
1066 echo "/* ${define} */" >> ${h}
1067 msg 'no'
1068 eval unset have_${variable}
1069 return 1
1073 _link_mayrun() {
1074 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1076 _check_preface "${variable}" "${topic}" "${define}"
1078 if feat_yes CROSS_BUILD; then
1079 if [ ${run} = 1 ]; then
1080 run=0
1084 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1085 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1086 XLIBS="${LIBS} ${libs}" \
1087 ./${tmp} &&
1088 [ -f ./${tmp} ] &&
1089 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1090 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1091 msg 'yes'
1092 echo "${define}" >> ${h}
1093 LIBS="${LIBS} ${libs}"
1094 echo "${libs}" >> ${lib}
1095 INCS="${INCS} ${incs}"
1096 echo "${incs}" >> ${inc}
1097 eval have_${variable}=yes
1098 return 0
1099 else
1100 msg 'no'
1101 echo "/* ${define} */" >> ${h}
1102 eval unset have_${variable}
1103 return 1
1107 link_check() {
1108 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1111 run_check() {
1112 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1115 xrun_check() {
1116 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1119 feat_def() {
1120 if feat_yes ${1}; then
1121 echo '#define HAVE_'${1}'' >> ${h}
1122 return 0
1123 else
1124 echo '/* OPT_'${1}'=0 */' >> ${h}
1125 return 1
1129 squeeze_em() {
1130 < "${1}" > "${2}" ${awk} \
1131 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1134 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1136 # First of all, create new configuration and check whether it changed
1138 # Very easy checks for the operating system in order to be able to adjust paths
1139 # or similar very basic things which we need to be able to go at all
1140 thecmd_testandset_fail uname uname
1141 os_early_setup
1143 # Check those tools right now that we need before including $rc
1144 msg 'Checking for basic utility set'
1145 thecmd_testandset_fail awk awk
1146 thecmd_testandset_fail rm rm
1147 thecmd_testandset_fail tr tr
1149 # Initialize the option set
1150 msg_nonl 'Setting up configuration options ... '
1151 option_setup
1152 msg 'done'
1154 # Include $rc, but only take from it what wasn't overwritten by the user from
1155 # within the command line or from a chosen fixed CONFIG=
1156 # Note we leave alone the values
1157 trap "exit 1" HUP INT TERM
1158 trap "${rm} -f ${tmp}" EXIT
1160 msg_nonl 'Joining in %s ... ' ${rc}
1161 option_join_rc
1162 msg 'done'
1164 # We need to know about that now, in order to provide utility overwrites etc.
1165 os_setup
1167 msg 'Checking for remaining set of utilities'
1168 thecmd_testandset_fail grep grep
1170 # Before we step ahead with the other utilities perform a path cleanup first.
1171 path_check PATH
1173 # awk(1) above
1174 thecmd_testandset_fail basename basename
1175 thecmd_testandset_fail cat cat
1176 thecmd_testandset_fail chmod chmod
1177 thecmd_testandset_fail cp cp
1178 thecmd_testandset_fail cmp cmp
1179 # grep(1) above
1180 thecmd_testandset_fail mkdir mkdir
1181 thecmd_testandset_fail mv mv
1182 # rm(1) above
1183 thecmd_testandset_fail sed sed
1184 thecmd_testandset_fail sort sort
1185 thecmd_testandset_fail tee tee
1186 __PATH=${PATH}
1187 thecmd_testandset chown chown ||
1188 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1189 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1190 PATH=${__PATH}
1191 thecmd_testandset_fail MAKE make
1192 make=${MAKE}
1193 export MAKE
1194 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1196 # For ./cc-test.sh only
1197 thecmd_testandset_fail cksum cksum
1199 # Update OPT_ options now, in order to get possible inter-dependencies right
1200 option_update
1202 # (No functions since some shells loose non-exported variables in traps)
1203 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1204 trap "trap \"\" HUP INT TERM EXIT;\
1205 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1207 # Our configuration options may at this point still contain shell snippets,
1208 # we need to evaluate them in order to get them expanded, and we need those
1209 # evaluated values not only in our new configuration file, but also at hand..
1210 msg_nonl 'Evaluating all configuration items ... '
1211 option_evaluate
1212 msg 'done'
1214 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1215 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1217 # The problem now is that the test should be able to run in the users linker
1218 # and path environment, so we need to place the test: rule first, before
1219 # injecting the relevant make variables. Set up necessary environment
1220 if [ -z "${VERBOSE}" ]; then
1221 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1222 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1223 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1224 printf -- "ECHO_TEST = @\n" >> ${newmk}
1225 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1226 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1227 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1229 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only ./%s\n' \
1230 "${SHELL}" "${SRCDIR}" "${VAL_SID}${VAL_MAILX}" >> ${newmk}
1232 # Add the known utility and some other variables
1233 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1234 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1235 if feat_yes DOTLOCK; then
1236 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1237 else
1238 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1241 for i in \
1242 SRCDIR \
1243 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1244 MAKE MAKEFLAGS make SHELL strip \
1245 cksum; do
1246 eval j=\$${i}
1247 printf "${i} = ${j}\n" >> ${newmk}
1248 printf "${i}=${j}\n" >> ${newlst}
1249 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1250 done
1251 # Note that makefile reads and eval'uates one line of this file, whereas other
1252 # consumers source it via .(1)
1253 printf "\n" >> ${newev}
1255 # Build a basic set of INCS and LIBS according to user environment.
1256 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1257 path_check C_INCLUDE_PATH -I _INCS
1258 INCS="${INCS} ${_INCS}"
1259 path_check LD_LIBRARY_PATH -L _LIBS
1260 LIBS="${LIBS} ${_LIBS}"
1261 unset _INCS _LIBS
1262 export C_INCLUDE_PATH LD_LIBRARY_PATH
1264 # Some environments need runtime path flags to be able to go at all
1265 ld_runtime_flags
1267 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1269 cc_setup
1271 ${cat} > ${tmp}.c << \!
1272 #include <stdio.h>
1273 #include <string.h>
1274 static void doit(char const *s);
1276 main(int argc, char **argv){
1277 (void)argc;
1278 (void)argv;
1279 doit("Hello world");
1280 return 0;
1282 static void
1283 doit(char const *s){
1284 char buf[12];
1285 memcpy(buf, s, strlen(s) +1);
1286 puts(s);
1290 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1291 -o ${tmp2} ${tmp}.c ${LIBS}; then
1293 else
1294 msg 'ERROR: i cannot compile a "Hello world" via'
1295 msg ' %s' \
1296 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1297 msg 'ERROR: Please read INSTALL, rerun'
1298 config_exit 1
1301 # This may also update ld_runtime_flags() (again)
1302 cc_flags
1304 for i in \
1305 INCS LIBS \
1306 ; do
1307 eval j=\$${i}
1308 printf -- "${i}=${j}\n" >> ${newlst}
1309 done
1310 for i in \
1311 CC \
1312 CFLAGS \
1313 LDFLAGS \
1314 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1315 OSFULLSPEC \
1316 ; do
1317 eval j=\$${i}
1318 if [ -n "${j}" ]; then
1319 printf -- "${i} = ${j}\n" >> ${newmk}
1320 printf -- "${i}=${j}\n" >> ${newlst}
1322 done
1324 # Now finally check whether we already have a configuration and if so, whether
1325 # all those parameters are still the same.. or something has actually changed
1326 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1327 echo 'Configuration is up-to-date'
1328 exit 0
1329 elif [ -f ${lst} ]; then
1330 echo 'Configuration has been updated..'
1331 ( eval "${MAKE} -f ./mk-config.mk clean" )
1332 echo
1333 else
1334 echo 'Shiny configuration..'
1337 # Time to redefine helper 1
1338 config_exit() {
1339 ${rm} -f ${lst} ${h} ${mk}
1340 exit ${1}
1343 ${mv} -f ${newlst} ${lst}
1344 ${mv} -f ${newev} ${ev}
1345 ${mv} -f ${newh} ${h}
1346 ${mv} -f ${newmk} ${mk}
1348 ## Compile and link checking
1350 tmp3=./${tmp0}3$$
1351 log=./mk-config.log
1352 lib=./mk-config.lib
1353 inc=./mk-config.inc
1354 makefile=./${tmp0}.mk
1356 # (No function since some shells loose non-exported variables in traps)
1357 trap "trap \"\" HUP INT TERM;\
1358 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1359 trap "trap \"\" HUP INT TERM EXIT;\
1360 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1362 # Time to redefine helper 2
1363 msg() {
1364 fmt=${1}
1365 shift
1366 printf "*** ${fmt}\\n" "${@}"
1367 printf -- "${fmt}\\n" "${@}" >&5
1369 msg_nonl() {
1370 fmt=${1}
1371 shift
1372 printf "*** ${fmt}\\n" "${@}"
1373 printf -- "${fmt}" "${@}" >&5
1376 # !!
1377 exec 5>&2 > ${log} 2>&1
1379 echo "${LIBS}" > ${lib}
1380 echo "${INCS}" > ${inc}
1381 ${cat} > ${makefile} << \!
1382 .SUFFIXES: .o .c .x .y
1383 .c.o:
1384 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1385 .c.x:
1386 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1388 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1391 ## Generics
1393 # May be multiline..
1394 echo >> ${h}
1395 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1396 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1397 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1399 # Generate n_err_number OS mappings
1400 dump_test_program=0
1402 feat_yes DEVEL && NV= || NV=noverbose
1403 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1404 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1405 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1406 dump_test_program=1
1408 feat_def ALWAYS_UNICODE_LOCALE
1409 feat_def AMALGAMATION
1410 feat_def CROSS_BUILD
1411 feat_def DOCSTRINGS
1412 feat_def ERRORS
1414 feat_def ASAN_ADDRESS
1415 feat_def ASAN_MEMORY
1416 feat_def DEBUG
1417 feat_def DEVEL
1418 feat_def NYD2
1419 feat_def NOMEMDBG
1421 if xrun_check inline 'inline functions' \
1422 '#define HAVE_INLINE
1423 #define n_INLINE static inline' << \!
1424 static inline int ilf(int i){return ++i;}
1425 int main(void){return ilf(-1);}
1427 then
1429 elif xrun_check inline 'inline functions (via __inline)' \
1430 '#define HAVE_INLINE
1431 #define n_INLINE static __inline' << \!
1432 static __inline int ilf(int i){return ++i;}
1433 int main(void){return ilf(-1);}
1435 then
1439 ## Test for "basic" system-calls / functionality that is used by all parts
1440 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1441 ## macros to be used by only the subprograms (potentially).
1443 if run_check clock_gettime 'clock_gettime(2)' \
1444 '#define HAVE_CLOCK_GETTIME' << \!
1445 #include <time.h>
1446 # include <errno.h>
1447 int main(void){
1448 struct timespec ts;
1450 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1451 return 0;
1452 return 1;
1455 then
1457 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1458 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1459 #include <time.h>
1460 # include <errno.h>
1461 int main(void){
1462 struct timespec ts;
1464 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1465 return 0;
1466 return 1;
1469 then
1471 elif run_check gettimeofday 'gettimeofday(2)' \
1472 '#define HAVE_GETTIMEOFDAY' << \!
1473 #include <stdio.h> /* For C89 NULL */
1474 #include <sys/time.h>
1475 # include <errno.h>
1476 int main(void){
1477 struct timeval tv;
1479 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1480 return 0;
1481 return 1;
1484 then
1486 else
1487 have_no_subsecond_time=1
1490 if run_check nanosleep 'nanosleep(2)' \
1491 '#define HAVE_NANOSLEEP' << \!
1492 #include <time.h>
1493 # include <errno.h>
1494 int main(void){
1495 struct timespec ts;
1497 ts.tv_sec = 1;
1498 ts.tv_nsec = 100000;
1499 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1500 return 0;
1501 return 1;
1504 then
1506 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1507 '#define HAVE_NANOSLEEP' '-lrt' << \!
1508 #include <time.h>
1509 # include <errno.h>
1510 int main(void){
1511 struct timespec ts;
1513 ts.tv_sec = 1;
1514 ts.tv_nsec = 100000;
1515 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1516 return 0;
1517 return 1;
1520 then
1522 # link_check is enough for this, that function is so old, trust the proto
1523 elif link_check sleep 'sleep(3)' \
1524 '#define HAVE_SLEEP' << \!
1525 #include <unistd.h>
1526 # include <errno.h>
1527 int main(void){
1528 if(!sleep(1) || errno != ENOSYS)
1529 return 0;
1530 return 1;
1533 then
1535 else
1536 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1537 config_exit 1
1540 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1541 #include <pwd.h>
1542 #include <unistd.h>
1543 # include <errno.h>
1544 int main(void){
1545 struct passwd *pw;
1546 gid_t gid;
1547 uid_t uid;
1549 if((gid = getgid()) != 0)
1550 gid = getegid();
1551 if((uid = getuid()) != 0)
1552 uid = geteuid();
1553 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1554 return 1;
1555 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1556 return 1;
1557 return 0;
1560 then
1562 else
1563 msg 'ERROR: we require user and group info / database searches.'
1564 msg 'That much Unix we indulge ourselfs.'
1565 config_exit 1
1568 if link_check ftruncate 'ftruncate(2)' \
1569 '#define HAVE_FTRUNCATE' << \!
1570 #include <unistd.h>
1571 #include <sys/types.h>
1572 int main(void){
1573 return (ftruncate(0, 0) != 0);
1576 then
1578 else
1579 msg 'ERROR: we require the ftruncate(2) system call.'
1580 config_exit 1
1583 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1584 #include <signal.h>
1585 # include <errno.h>
1586 int main(void){
1587 struct sigaction nact, oact;
1589 nact.sa_handler = SIG_DFL;
1590 sigemptyset(&nact.sa_mask);
1591 nact.sa_flags = SA_RESTART;
1592 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1595 then
1597 else
1598 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1599 config_exit 1
1602 if link_check snprintf 'snprintf(3)' << \!
1603 #include <stdio.h>
1604 int main(void){
1605 char b[20];
1607 snprintf(b, sizeof b, "%s", "string");
1608 return 0;
1611 then
1613 else
1614 msg 'ERROR: we require the snprintf(3) function.'
1615 config_exit 1
1618 if link_check environ 'environ(3)' << \!
1619 #include <stdio.h> /* For C89 NULL */
1620 int main(void){
1621 extern char **environ;
1623 return environ[0] == NULL;
1626 then
1628 else
1629 msg 'ERROR: we require the environ(3) array for subprocess control.'
1630 config_exit 1
1633 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1634 #include <stdlib.h>
1635 int main(void){
1636 setenv("s-mailx", "i want to see it cute!", 1);
1637 unsetenv("s-mailx");
1638 return 0;
1641 then
1643 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1644 #include <stdlib.h>
1645 int main(void){
1646 putenv("s-mailx=i want to see it cute!");
1647 return 0;
1650 then
1652 else
1653 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1654 config_exit 1
1657 if link_check termios 'termios.h and tc*(3) family' << \!
1658 #include <termios.h>
1659 int main(void){
1660 struct termios tios;
1662 tcgetattr(0, &tios);
1663 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1664 return 0;
1667 then
1669 else
1670 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1671 msg 'That much Unix we indulge ourselfs.'
1672 config_exit 1
1675 ## optional stuff
1677 if link_check vsnprintf 'vsnprintf(3)' << \!
1678 #include <stdarg.h>
1679 #include <stdio.h>
1680 static void dome(char *buf, size_t blen, ...){
1681 va_list ap;
1683 va_start(ap, blen);
1684 vsnprintf(buf, blen, "%s", ap);
1685 va_end(ap);
1687 int main(void){
1688 char b[20];
1690 dome(b, sizeof b, "string");
1691 return 0;
1694 then
1696 else
1697 feat_bail_required ERRORS
1700 if [ "${have_vsnprintf}" = yes ]; then
1701 __va_copy() {
1702 link_check va_copy "va_copy(3) (as ${2})" \
1703 "#define HAVE_N_VA_COPY
1704 #define n_va_copy ${2}" <<_EOT
1705 #include <stdarg.h>
1706 #include <stdio.h>
1707 #if ${1}
1708 # if defined __va_copy && !defined va_copy
1709 # define va_copy __va_copy
1710 # endif
1711 #endif
1712 static void dome2(char *buf, size_t blen, va_list src){
1713 va_list ap;
1715 va_copy(ap, src);
1716 vsnprintf(buf, blen, "%s", ap);
1717 va_end(ap);
1719 static void dome(char *buf, size_t blen, ...){
1720 va_list ap;
1722 va_start(ap, blen);
1723 dome2(buf, blen, ap);
1724 va_end(ap);
1726 int main(void){
1727 char b[20];
1729 dome(b, sizeof b, "string");
1730 return 0;
1732 _EOT
1734 __va_copy 0 va_copy || __va_copy 1 __va_copy
1737 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1738 #include <unistd.h>
1739 #include <errno.h>
1740 int main(void){
1741 int rv = 0;
1743 errno = 0;
1744 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1745 errno = 0;
1746 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1748 /* Only link check */
1749 fpathconf(0, _PC_NAME_MAX);
1751 return rv;
1755 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1756 #include <fcntl.h>
1757 #include <unistd.h>
1758 # include <errno.h>
1759 int main(void){
1760 int fds[2];
1762 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1763 return 0;
1764 return 1;
1768 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1769 #include <termios.h>
1770 int main(void){
1771 struct winsize ws;
1773 tcgetwinsize(0, &ws);
1774 return 0;
1778 # We use this only then for now (need NOW+1)
1779 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1780 #include <fcntl.h> /* For AT_* */
1781 #include <sys/stat.h>
1782 # include <errno.h>
1783 int main(void){
1784 struct timespec ts[2];
1786 ts[0].tv_nsec = UTIME_NOW;
1787 ts[1].tv_nsec = UTIME_OMIT;
1788 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1789 return 0;
1790 return 1;
1796 # The random check has been moved to below SSL detection due to OPT_SSL_RANDOM
1798 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1799 #include <stdio.h>
1800 int main(void){
1801 putc_unlocked('@', stdout);
1802 return 0;
1806 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1807 #include <unistd.h>
1808 int main(void){
1809 fchdir(0);
1810 return 0;
1814 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1815 #include <stdlib.h>
1816 int main(void){
1817 char x_buf[4096], *x = realpath(".", x_buf);
1819 return (x != NULL) ? 0 : 1;
1822 then
1823 if run_check realpath_malloc 'realpath(3) takes NULL' \
1824 '#define HAVE_REALPATH_NULL' << \!
1825 #include <stdlib.h>
1826 int main(void){
1827 char *x = realpath(".", NULL);
1829 if(x != NULL)
1830 free(x);
1831 return (x != NULL) ? 0 : 1;
1834 then
1839 ## optional and selectable
1841 if feat_yes DOTLOCK; then
1842 if run_check readlink 'readlink(2)' << \!
1843 #include <unistd.h>
1844 # include <errno.h>
1845 int main(void){
1846 char buf[128];
1848 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1849 return 0;
1850 return 1;
1853 then
1855 else
1856 feat_bail_required DOTLOCK
1860 if feat_yes DOTLOCK; then
1861 if run_check fchown 'fchown(2)' << \!
1862 #include <unistd.h>
1863 # include <errno.h>
1864 int main(void){
1865 if(!fchown(0, 0, 0) || errno != ENOSYS)
1866 return 0;
1867 return 1;
1870 then
1872 else
1873 feat_bail_required DOTLOCK
1877 if feat_yes DOTLOCK; then
1878 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1879 '#define HAVE_PRCTL_DUMPABLE' << \!
1880 #include <sys/prctl.h>
1881 # include <errno.h>
1882 int main(void){
1883 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1884 return 0;
1885 return 1;
1888 then
1890 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1891 '#define HAVE_PTRACE_DENY' << \!
1892 #include <sys/ptrace.h>
1893 # include <errno.h>
1894 int main(void){
1895 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1896 return 0;
1897 return 1;
1900 then
1902 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1903 '#define HAVE_SETPFLAGS_PROTECT' << \!
1904 #include <priv.h>
1905 # include <errno.h>
1906 int main(void){
1907 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
1908 return 0;
1909 return 1;
1912 then
1917 ## Now it is the time to fork away the BASE_ series
1919 ${rm} -f ${tmp}
1920 squeeze_em ${inc} ${tmp}
1921 ${mv} ${tmp} ${inc}
1922 squeeze_em ${lib} ${tmp}
1923 ${mv} ${tmp} ${lib}
1925 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1926 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1928 ## The remains are expected to be used only by the main MUA binary!
1930 OPT_LOCALES=0
1931 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1932 #include <locale.h>
1933 int main(void){
1934 setlocale(LC_ALL, "");
1935 return 0;
1938 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1940 OPT_MULTIBYTE_CHARSETS=0
1941 OPT_WIDE_GLYPHS=0
1942 OPT_TERMINAL_CHARSET=0
1943 if [ -n "${have_setlocale}" ]; then
1944 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1945 '#define HAVE_C90AMEND1' << \!
1946 #include <limits.h>
1947 #include <stdlib.h>
1948 #include <wchar.h>
1949 #include <wctype.h>
1950 int main(void){
1951 char mbb[MB_LEN_MAX + 1];
1952 wchar_t wc;
1954 iswprint(L'c');
1955 towupper(L'c');
1956 mbtowc(&wc, "x", 1);
1957 mbrtowc(&wc, "x", 1, NULL);
1958 wctomb(mbb, wc);
1959 return (mblen("\0", 1) == 0);
1962 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1964 if [ -n "${have_c90amend1}" ]; then
1965 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1966 #include <wchar.h>
1967 int main(void){
1968 wcwidth(L'c');
1969 return 0;
1972 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1975 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1976 #include <langinfo.h>
1977 #include <stdlib.h>
1978 int main(void){
1979 nl_langinfo(DAY_1);
1980 return (nl_langinfo(CODESET) == NULL);
1983 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1984 fi # have_setlocale
1986 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1987 #include <fnmatch.h>
1988 int main(void){
1989 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1993 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1994 #include <dirent.h>
1995 int main(void){
1996 struct dirent de;
1997 return !(de.d_type == DT_UNKNOWN ||
1998 de.d_type == DT_DIR || de.d_type == DT_LNK);
2002 ## optional and selectable
2004 if feat_yes ICONV; then
2005 # To be able to create tests we need to figure out which replacement
2006 # sequence the iconv(3) implementation creates
2007 ${cat} > ${tmp2}.c << \!
2008 #include <stdio.h> /* For C89 NULL */
2009 #include <string.h>
2010 #include <iconv.h>
2011 int main(void){
2012 char inb[16], oub[16], *inbp, *oubp;
2013 iconv_t id;
2014 size_t inl, oul;
2016 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2017 inl = sizeof("\342\200\223") -1;
2018 oul = sizeof oub;
2019 oubp = oub;
2021 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2022 return 1;
2023 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2024 return 1;
2025 iconv_close(id);
2027 *oubp = '\0';
2028 oul = (size_t)(oubp - oub);
2029 if(oul == 0)
2030 return 1;
2031 /* Character-wise replacement? */
2032 if(oul == 1){
2033 if(oub[0] == '?')
2034 return 2;
2035 if(oub[0] == '*')
2036 return 3;
2037 return 1;
2039 /* Byte-wise replacement? */
2040 if(oul == sizeof("\342\200\223") -1){
2041 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2042 return 12;
2043 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2044 return 13;
2045 return 1;
2047 return 0;
2050 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2051 '#define HAVE_ICONV' ||
2052 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2053 '#define HAVE_ICONV' '-liconv' ||
2054 feat_bail_required ICONV
2056 if feat_no CROSS_BUILD; then
2057 { ./${tmp}; } >/dev/null 2>&1
2058 case ${?} in
2059 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2060 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2061 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2062 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2063 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2064 esac
2066 else
2067 echo '/* OPT_ICONV=0 */' >> ${h}
2068 fi # feat_yes ICONV
2070 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2071 ${cat} > ${tmp2}.c << \!
2072 #include <sys/types.h>
2073 #include <sys/socket.h>
2074 #include <sys/un.h>
2075 # include <errno.h>
2076 int main(void){
2077 struct sockaddr_un soun;
2079 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2080 return 1;
2081 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2082 return 1;
2083 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2084 return 1;
2085 return 0;
2089 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2090 '#define HAVE_UNIX_SOCKETS' ||
2091 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2092 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2093 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2094 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2097 if feat_yes SOCKETS; then
2098 ${cat} > ${tmp2}.c << \!
2099 #include <sys/types.h>
2100 #include <sys/socket.h>
2101 #include <netinet/in.h>
2102 # include <errno.h>
2103 int main(void){
2104 struct sockaddr s;
2106 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2107 return 1;
2108 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2109 return 1;
2110 return 0;
2114 < ${tmp2}.c run_check sockets 'sockets' \
2115 '#define HAVE_SOCKETS' ||
2116 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2117 '#define HAVE_SOCKETS' '-lnsl' ||
2118 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2119 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2120 feat_bail_required SOCKETS
2121 else
2122 echo '/* OPT_SOCKETS=0 */' >> ${h}
2123 fi # feat_yes SOCKETS
2125 if feat_yes SOCKETS; then
2126 link_check getaddrinfo 'getaddrinfo(3)' \
2127 '#define HAVE_GETADDRINFO' << \!
2128 #include <sys/types.h>
2129 #include <sys/socket.h>
2130 #include <stdio.h>
2131 #include <netdb.h>
2132 int main(void){
2133 struct addrinfo a, *ap;
2134 int lrv;
2136 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2137 case EAI_NONAME:
2138 case EAI_SERVICE:
2139 default:
2140 fprintf(stderr, "%s\n", gai_strerror(lrv));
2141 case 0:
2142 break;
2144 return 0;
2149 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2150 compile_check arpa_inet_h '<arpa/inet.h>' \
2151 '#define HAVE_ARPA_INET_H' << \!
2152 #include <sys/types.h>
2153 #include <sys/socket.h>
2154 #include <netdb.h>
2155 #include <netinet/in.h>
2156 #include <arpa/inet.h>
2159 ${cat} > ${tmp2}.c << \!
2160 #include <sys/types.h>
2161 #include <sys/socket.h>
2162 #include <stdio.h>
2163 #include <string.h>
2164 #include <netdb.h>
2165 #include <netinet/in.h>
2166 #ifdef HAVE_ARPA_INET_H
2167 #include <arpa/inet.h>
2168 #endif
2169 int main(void){
2170 struct sockaddr_in servaddr;
2171 unsigned short portno;
2172 struct servent *ep;
2173 struct hostent *hp;
2174 struct in_addr **pptr;
2176 portno = 0;
2177 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2178 portno = (unsigned short)ep->s_port;
2180 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2181 pptr = (struct in_addr**)hp->h_addr_list;
2182 if(hp->h_addrtype != AF_INET)
2183 fprintf(stderr, "au\n");
2184 }else{
2185 switch(h_errno){
2186 case HOST_NOT_FOUND:
2187 case TRY_AGAIN:
2188 case NO_RECOVERY:
2189 case NO_DATA:
2190 break;
2191 default:
2192 fprintf(stderr, "au\n");
2193 break;
2197 memset(&servaddr, 0, sizeof servaddr);
2198 servaddr.sin_family = AF_INET;
2199 servaddr.sin_port = htons(portno);
2200 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2201 fprintf(stderr, "Would connect to %s:%d ...\n",
2202 inet_ntoa(**pptr), (int)portno);
2203 return 0;
2207 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2208 < ${tmp2}.c link_check gethostbyname \
2209 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2210 < ${tmp2}.c link_check gethostbyname \
2211 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2212 '' '-lsocket -lnsl' ||
2213 feat_bail_required SOCKETS
2216 feat_yes SOCKETS &&
2217 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2218 #include <sys/socket.h>
2219 #include <stdlib.h>
2220 # include <errno.h>
2221 int main(void){
2222 int sockfd = 3;
2224 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2225 errno == ENOSYS)
2226 return 1;
2227 return 0;
2231 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2232 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2233 #include <sys/socket.h>
2234 #include <stdlib.h>
2235 int main(void){
2236 struct timeval tv;
2237 int sockfd = 3;
2239 tv.tv_sec = 42;
2240 tv.tv_usec = 21;
2241 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2242 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2243 return 0;
2247 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2248 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2249 #include <sys/socket.h>
2250 #include <stdlib.h>
2251 int main(void){
2252 struct linger li;
2253 int sockfd = 3;
2255 li.l_onoff = 1;
2256 li.l_linger = 42;
2257 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2258 return 0;
2262 VAL_SSL_FEATURES=
2263 if feat_yes SSL; then # {{{
2264 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2265 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2266 # time: we need to test it first in order to get things right
2267 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2268 '#define HAVE_SSL
2269 #define HAVE_XSSL
2270 #define HAVE_XSSL_RESSL
2271 #define HAVE_XSSL_OPENSSL 0' << \!
2272 #include <openssl/opensslv.h>
2273 #ifdef LIBRESSL_VERSION_NUMBER
2274 #else
2275 # error nope
2276 #endif
2278 then
2279 ossl_v1_1=
2280 VAL_SSL_FEATURES=libressl
2281 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2282 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2283 '#define HAVE_SSL
2284 #define HAVE_XSSL
2285 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2286 #include <openssl/opensslv.h>
2287 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2288 #else
2289 # error nope
2290 #endif
2292 then
2293 ossl_v1_1=1
2294 VAL_SSL_FEATURES=libssl-0x10100
2295 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2296 '#define HAVE_SSL
2297 #define HAVE_XSSL
2298 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2299 #include <openssl/opensslv.h>
2300 #ifdef OPENSSL_VERSION_NUMBER
2301 #else
2302 # error nope
2303 #endif
2305 then
2306 ossl_v1_1=
2307 VAL_SSL_FEATURES=libssl-0x10000
2308 else
2309 feat_bail_required SSL
2310 fi # }}}
2312 if feat_yes SSL; then # {{{
2313 if [ -n "${ossl_v1_1}" ]; then
2314 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2315 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2316 '-lssl -lcrypto'
2317 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2318 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2319 '-lssl -lcrypto' << \!
2320 #include <openssl/ssl.h>
2321 #include <openssl/err.h>
2322 #include <openssl/x509v3.h>
2323 #include <openssl/x509.h>
2324 #include <openssl/rand.h>
2325 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2326 # error We need TLSv1.
2327 #endif
2328 int main(void){
2329 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2331 SSL_CTX_free(ctx);
2332 PEM_read_PrivateKey(0, 0, 0, 0);
2333 return 0;
2336 then
2338 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2339 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2340 '-lssl -lcrypto' << \!
2341 #include <openssl/ssl.h>
2342 #include <openssl/err.h>
2343 #include <openssl/x509v3.h>
2344 #include <openssl/x509.h>
2345 #include <openssl/rand.h>
2346 #if defined OPENSSL_NO_SSL3 &&\
2347 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2348 # error We need one of SSLv3 and TLSv1.
2349 #endif
2350 int main(void){
2351 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2353 SSL_CTX_free(ctx);
2354 PEM_read_PrivateKey(0, 0, 0, 0);
2355 return 0;
2358 then
2360 else
2361 feat_bail_required SSL
2363 fi # }}}
2365 if feat_yes SSL; then # {{{
2366 if feat_yes SSL_ALL_ALGORITHMS; then
2367 if [ -n "${ossl_v1_1}" ]; then
2368 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2369 '#define HAVE_SSL_ALL_ALGORITHMS'
2370 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2371 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2372 #include <openssl/evp.h>
2373 int main(void){
2374 OpenSSL_add_all_algorithms();
2375 EVP_get_cipherbyname("two cents i never exist");
2376 EVP_cleanup();
2377 return 0;
2380 then
2382 else
2383 feat_bail_required SSL_ALL_ALGORITHMS
2385 elif [ -n "${ossl_v1_1}" ]; then
2386 without_check yes ssl_all_algo \
2387 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2388 '#define HAVE_SSL_ALL_ALGORITHMS'
2391 if [ -n "${ossl_v1_1}" ]; then
2392 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2393 '#define HAVE_XSSL_STACK_OF'
2394 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2395 '#define HAVE_XSSL_STACK_OF' << \!
2396 #include <stdio.h> /* For C89 NULL */
2397 #include <openssl/ssl.h>
2398 #include <openssl/err.h>
2399 #include <openssl/x509v3.h>
2400 #include <openssl/x509.h>
2401 #include <openssl/rand.h>
2402 int main(void){
2403 STACK_OF(GENERAL_NAME) *gens = NULL;
2405 printf("%p", gens); /* to use it */
2406 return 0;
2409 then
2413 if [ -n "${ossl_v1_1}" ]; then
2414 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2415 '#define HAVE_XSSL_CONFIG'
2416 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2417 elif link_check xssl_conf \
2418 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2419 '#define HAVE_XSSL_CONFIG' << \!
2420 #include <stdio.h> /* For C89 NULL */
2421 #include <openssl/conf.h>
2422 int main(void){
2423 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2424 CONF_modules_free();
2425 return 0;
2428 then
2429 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2430 else
2431 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2434 if [ -n "${ossl_v1_1}" ]; then
2435 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2436 '#define HAVE_XSSL_CONF_CTX'
2437 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2438 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2439 '#define HAVE_XSSL_CONF_CTX' << \!
2440 #include <openssl/ssl.h>
2441 #include <openssl/err.h>
2442 int main(void){
2443 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2444 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2446 SSL_CONF_CTX_set_flags(cctx,
2447 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2448 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2449 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2450 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2451 SSL_CONF_CTX_finish(cctx);
2452 SSL_CONF_CTX_free(cctx);
2453 SSL_CTX_free(ctx);
2454 return 0;
2457 then
2458 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2459 else
2460 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2463 if [ -n "${ossl_v1_1}" ]; then
2464 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2465 '#define HAVE_XSSL_CTX_CONFIG'
2466 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2467 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2468 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2469 '#define HAVE_XSSL_CTX_CONFIG' << \!
2470 #include <stdio.h> /* For C89 NULL */
2471 #include <openssl/ssl.h>
2472 int main(void){
2473 SSL_CTX_config(NULL, "SOMEVAL");
2474 return 0;
2477 then
2478 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2479 else
2480 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2483 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2484 without_check yes xssl_set_maxmin_proto \
2485 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2486 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2487 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2488 elif link_check xssl_set_maxmin_proto \
2489 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2490 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2491 #include <stdio.h> /* For C89 NULL */
2492 #include <openssl/ssl.h>
2493 int main(void){
2494 SSL_CTX_set_min_proto_version(NULL, 0);
2495 SSL_CTX_set_max_proto_version(NULL, 10);
2496 return 0;
2499 then
2500 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2501 else
2502 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2505 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2506 '#define HAVE_XSSL_RAND_EGD' << \!
2507 #include <openssl/rand.h>
2508 int main(void){
2509 return RAND_egd("some.where") > 0;
2512 then
2513 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2514 else
2515 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2517 fi # feat_yes SSL }}}
2519 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2520 run_check ssl_md5 'MD5 digest in the used crypto library' \
2521 '#define HAVE_XSSL_MD5' << \!
2522 #include <stdlib.h>
2523 #include <string.h>
2524 #include <openssl/md5.h>
2525 int main(void){
2526 char const dat[] = "abrakadabrafidibus";
2527 char dig[16], hex[16 * 2];
2528 MD5_CTX ctx;
2529 size_t i, j;
2531 memset(dig, 0, sizeof(dig));
2532 memset(hex, 0, sizeof(hex));
2533 MD5_Init(&ctx);
2534 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2535 MD5_Final(dig, &ctx);
2537 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2538 for(i = 0; i < sizeof(hex) / 2; i++){
2539 j = i << 1;
2540 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2541 hex[++j] = hexchar(dig[i] & 0x0f);
2543 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2546 fi # }}}
2548 if feat_yes SSL; then
2549 feat_def SSL_RANDOM
2550 feat_def SSL_ALL_ALGORITHMS
2551 else
2552 feat_bail_required SSL_RANDOM
2553 feat_bail_required SSL_ALL_ALGORITHMS
2554 echo '/* OPT_SSL=0 */' >> ${h}
2555 fi # }}} feat_yes SSL
2556 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2558 if [ "${have_xssl}" = yes ]; then
2559 OPT_SMIME=1
2560 else
2561 OPT_SMIME=0
2563 feat_def SMIME
2565 # Native random check (had been delayed due to OPT_SSL_RAMDOM) {{{
2566 # XXX Add POSIX check once standardized
2567 if feat_yes NOEXTRANDOM; then
2568 echo '#define HAVE_NOEXTRANDOM' >> ${h}
2569 elif feat_yes SSL_RANDOM; then
2571 elif link_check arc4random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
2572 #include <stdlib.h>
2573 int main(void){
2574 arc4random();
2575 return 0;
2578 then
2580 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
2581 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
2582 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
2583 #include <sys/random.h>
2584 int main(void){
2585 char buf[256];
2586 getrandom(buf, sizeof buf, 0);
2587 return 0;
2590 then
2592 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
2593 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
2594 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
2595 #include <sys/syscall.h>
2596 int main(void){
2597 char buf[256];
2598 syscall(SYS_getrandom, buf, sizeof buf, 0);
2599 return 0;
2602 then
2604 elif [ -n "${have_no_subsecond_time}" ]; then
2605 msg 'ERROR: %s %s' 'without a native random' \
2606 'one of clock_gettime(2) and gettimeofday(2) is required.'
2607 config_exit 1
2608 fi # }}}
2610 feat_def SMTP
2611 feat_def POP3
2612 feat_def IMAP
2614 if feat_yes GSSAPI; then
2615 ${cat} > ${tmp2}.c << \!
2616 #include <gssapi/gssapi.h>
2617 int main(void){
2618 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2619 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2620 return 0;
2623 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2625 if acmd_set i krb5-config; then
2626 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2627 GSS_INCS="`CFLAGS= ${i} --cflags`"
2628 i='GSS-API via krb5-config(1)'
2629 else
2630 GSS_LIBS='-lgssapi'
2631 GSS_INCS=
2632 i='GSS-API in gssapi/gssapi.h, libgssapi'
2634 if < ${tmp2}.c link_check gss \
2635 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2636 < ${tmp3}.c link_check gss \
2637 'GSS-API in gssapi.h, libgssapi' \
2638 '#define HAVE_GSSAPI
2639 #define GSSAPI_REG_INCLUDE' \
2640 '-lgssapi' ||\
2641 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2642 '#define HAVE_GSSAPI' \
2643 '-lgssapi_krb5' ||\
2644 < ${tmp3}.c link_check gss \
2645 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2646 '#define HAVE_GSSAPI
2647 #define GSS_REG_INCLUDE' \
2648 '-lgssapi -lkrb5 -lcrypto' \
2649 '-I/usr/include/kerberosV' ||\
2650 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2651 '#define HAVE_GSSAPI' \
2652 '-lgss' ||\
2653 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2654 '#define HAVE_GSSAPI
2655 #define GSSAPI_OLD_STYLE' \
2656 '-lgssapi_krb5' << \!
2657 #include <gssapi/gssapi.h>
2658 #include <gssapi/gssapi_generic.h>
2659 int main(void){
2660 gss_import_name(0, 0, gss_nt_service_name, 0);
2661 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2662 return 0;
2665 then
2667 else
2668 feat_bail_required GSSAPI
2670 else
2671 echo '/* OPT_GSSAPI=0 */' >> ${h}
2672 fi # feat_yes GSSAPI
2674 feat_def NETRC
2675 feat_def AGENT
2677 if feat_yes IDNA; then
2678 if link_check idna 'Libidn2' '#define HAVE_IDNA HAVE_IDNA_LIBIDN2' \
2679 '-lidn2' << \!
2680 #include <idn2.h>
2681 int main(void){
2682 char *idna_utf8, *idna_lc;
2684 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2685 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2686 return 1;
2687 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2688 return 1;
2689 idn2_free(idna_lc);
2690 idn2_free(idna_utf8);
2691 return 0;
2694 then
2696 elif link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2697 '-lidn' << \!
2698 #include <idna.h>
2699 #include <idn-free.h>
2700 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2701 int main(void){
2702 char *utf8, *idna_ascii, *idna_utf8;
2704 utf8 = stringprep_locale_to_utf8("does.this.work");
2705 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2706 != IDNA_SUCCESS)
2707 return 1;
2708 idn_free(idna_ascii);
2709 /* (Rather link check only here) */
2710 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2711 return 0;
2714 then
2716 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2717 '-lidnkit' << \!
2718 #include <stdio.h>
2719 #include <idn/api.h>
2720 #include <idn/result.h>
2721 int main(void){
2722 idn_result_t r;
2723 char ace_name[256];
2724 char local_name[256];
2726 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2727 sizeof(ace_name));
2728 if (r != idn_success) {
2729 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2730 return 1;
2732 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2733 if (r != idn_success) {
2734 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2735 return 1;
2737 return 0;
2740 then
2742 else
2743 feat_bail_required IDNA
2746 if [ -n "${have_idna}" ]; then
2747 echo '#define HAVE_IDNA_LIBIDN2 0' >> ${h}
2748 echo '#define HAVE_IDNA_LIBIDNA 1' >> ${h}
2749 echo '#define HAVE_IDNA_IDNKIT 2' >> ${h}
2751 else
2752 echo '/* OPT_IDNA=0 */' >> ${h}
2755 feat_def IMAP_SEARCH
2757 if feat_yes REGEX; then
2758 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2759 #include <regex.h>
2760 #include <stdlib.h>
2761 int main(void){
2762 size_t xret;
2763 int status;
2764 regex_t re;
2766 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2767 xret = regerror(status, &re, NULL, 0);
2768 status = regexec(&re, "plan9", 0,NULL, 0);
2769 regfree(&re);
2770 return !(status == REG_NOMATCH);
2773 then
2775 else
2776 feat_bail_required REGEX
2778 else
2779 echo '/* OPT_REGEX=0 */' >> ${h}
2782 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2783 have_mle=1
2784 echo '#define HAVE_MLE' >> ${h}
2785 else
2786 feat_bail_required MLE
2787 echo '/* OPT_MLE=0 */' >> ${h}
2790 # Generic have-a-line-editor switch for those who need it below
2791 if [ -n "${have_mle}" ]; then
2792 have_cle=1
2795 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2796 echo '#define HAVE_HISTORY' >> ${h}
2797 else
2798 echo '/* OPT_HISTORY=0 */' >> ${h}
2801 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2802 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2803 else
2804 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2807 if feat_yes TERMCAP; then
2808 __termcaplib() {
2809 link_check termcap "termcap(5) (via ${4})" \
2810 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2811 #include <stdio.h>
2812 #include <stdlib.h>
2813 ${2}
2814 #include <term.h>
2815 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2816 static int my_putc(int c){return putchar(c);}
2817 int main(void){
2818 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2819 int r2 = OK, r3 = ERR;
2821 tgetent(buf, getenv("TERM"));
2822 cpb = cmdbuf;
2823 r1 = tgetstr(UNCONST("cm"), &cpb);
2824 tgoto(r1, 1, 1);
2825 r2 = tgetnum(UNCONST("Co"));
2826 r3 = tgetflag(UNCONST("ut"));
2827 tputs("cr", 1, &my_putc);
2828 return (r1 == NULL || r2 == -1 || r3 == 0);
2830 _EOT
2833 __terminfolib() {
2834 link_check terminfo "terminfo(5) (via ${2})" \
2835 '#define HAVE_TERMCAP
2836 #define HAVE_TERMCAP_CURSES
2837 #define HAVE_TERMINFO' "${1}" << _EOT
2838 #include <stdio.h>
2839 #include <curses.h>
2840 #include <term.h>
2841 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2842 static int my_putc(int c){return putchar(c);}
2843 int main(void){
2844 int er, r0, r1, r2;
2845 char *r3, *tp;
2847 er = OK;
2848 r0 = setupterm(NULL, 1, &er);
2849 r1 = tigetflag(UNCONST("bce"));
2850 r2 = tigetnum(UNCONST("colors"));
2851 r3 = tigetstr(UNCONST("cr"));
2852 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2853 tputs(tp, 1, &my_putc);
2854 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2855 r3 == (char*)-1 || r3 == NULL);
2857 _EOT
2860 if feat_yes TERMCAP_VIA_TERMINFO; then
2861 __terminfolib -ltinfo -ltinfo ||
2862 __terminfolib -lcurses -lcurses ||
2863 __terminfolib -lcursesw -lcursesw ||
2864 feat_bail_required TERMCAP_VIA_TERMINFO
2867 if [ -z "${have_terminfo}" ]; then
2868 __termcaplib -ltermcap '' '' '-ltermcap' ||
2869 __termcaplib -ltermcap '#include <curses.h>' '
2870 #define HAVE_TERMCAP_CURSES' \
2871 'curses.h / -ltermcap' ||
2872 __termcaplib -lcurses '#include <curses.h>' '
2873 #define HAVE_TERMCAP_CURSES' \
2874 'curses.h / -lcurses' ||
2875 __termcaplib -lcursesw '#include <curses.h>' '
2876 #define HAVE_TERMCAP_CURSES' \
2877 'curses.h / -lcursesw' ||
2878 feat_bail_required TERMCAP
2880 if [ -n "${have_termcap}" ]; then
2881 run_check tgetent_null \
2882 "tgetent(3) of termcap(5) takes NULL buffer" \
2883 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2884 #include <stdio.h> /* For C89 NULL */
2885 #include <stdlib.h>
2886 #ifdef HAVE_TERMCAP_CURSES
2887 # include <curses.h>
2888 #endif
2889 #include <term.h>
2890 int main(void){
2891 tgetent(NULL, getenv("TERM"));
2892 return 0;
2894 _EOT
2897 else
2898 echo '/* OPT_TERMCAP=0 */' >> ${h}
2899 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2902 if feat_def SPAM_SPAMC; then
2903 if acmd_set i spamc; then
2904 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2908 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2909 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2910 else
2911 feat_bail_required SPAM_SPAMD
2912 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2915 feat_def SPAM_FILTER
2917 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2918 echo '#define HAVE_SPAM' >> ${h}
2919 else
2920 echo '/* HAVE_SPAM */' >> ${h}
2923 if feat_yes QUOTE_FOLD &&\
2924 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2925 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2926 else
2927 feat_bail_required QUOTE_FOLD
2928 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2931 feat_def FILTER_HTML_TAGSOUP
2932 feat_def COLOUR
2933 feat_def DOTLOCK
2934 feat_def MD5
2936 ## Summarizing
2938 ${rm} -f ${tmp}
2939 squeeze_em ${inc} ${tmp}
2940 ${mv} ${tmp} ${inc}
2941 squeeze_em ${lib} ${tmp}
2942 ${mv} ${tmp} ${lib}
2944 # mk-config.h
2945 ${mv} ${h} ${tmp}
2946 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2947 ${cat} ${tmp} >> ${h}
2948 ${rm} -f ${tmp}
2949 printf '\n' >> ${h}
2951 # Create the string that is used by *features* and `version'.
2952 # Take this nice opportunity and generate a visual listing of included and
2953 # non-included features for the person who runs the configuration
2954 msg '\nThe following features are included (+) or not (-):'
2955 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2956 printf '/* The "feature string" */\n' >> ${h}
2957 # Because + is expanded by *folder* if first in "echo $features", put something
2958 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2959 sep=
2960 for opt
2962 sdoc=`option_doc_of ${opt}`
2963 [ -z "${sdoc}" ] && continue
2964 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2965 feat_yes ${opt} && sign=+ || sign=-
2966 printf -- "${sep}${sign}${sopt}" >> ${h}
2967 sep=','
2968 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2969 done
2970 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2971 #exec 5>&1 >>${h}
2972 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2973 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2974 printf '"\n' >> ${h}
2976 # Create the real mk-config.mk
2977 # Note we cannout use explicit ./ filename prefix for source and object
2978 # pathnames because of a bug in bmake(1)
2979 ${rm} -rf ${tmp0}.* ${tmp0}*
2980 srclist= objlist=
2981 if feat_no AMALGAMATION; then
2982 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2983 i=`basename "${i}" .c`
2984 if [ "${i}" = privsep ]; then
2985 continue
2987 objlist="${objlist} ${i}.o"
2988 srclist="${srclist} \$(SRCDIR)${i}.c"
2989 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2990 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2991 done
2992 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2993 else
2994 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2995 "main.o" "main.c" >> ${mk}
2996 srclist=main.c objlist=main.o
2997 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2999 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3000 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3001 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3002 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3003 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3004 i=`basename "${i}"`
3005 if [ "${i}" = main.c ] ||
3006 [ "${i}" = privsep.c ]; then
3007 continue
3009 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3010 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3011 done
3012 echo >> ${mk}
3014 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3016 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3018 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3019 echo "INCS = `${cat} ${inc}`" >> ${mk}
3020 echo >> ${mk}
3021 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3023 ## Finished!
3025 msg '\nSetup:'
3026 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3027 msg ' . bindir: %s' "${VAL_BINDIR}"
3028 if feat_yes DOTLOCK; then
3029 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3031 msg ' . mandir: %s' "${VAL_MANDIR}"
3032 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3033 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3034 msg ''
3036 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3037 exit 0
3039 msg 'Remarks:'
3040 if [ -z "${have_fnmatch}" ]; then
3041 msg ' . The function fnmatch(3) could not be found.'
3042 msg ' Filename patterns like wildcard are not supported on your system'
3044 if [ -z "${have_fchdir}" ]; then
3045 msg ' . The function fchdir(2) could not be found.'
3046 msg ' We will use chdir(2) instead.'
3047 msg ' This is a problem only if the current working directory is changed'
3048 msg ' while this program is inside of it'
3050 msg ''
3052 # s-it-mode