make-config.in: complete path (leftover of [807f64e2], 2015-12-26!)
[s-mailx.git] / make-config.sh
blob54b13f9b31dbd5f31098d506c67393ef98a9f005
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 MAILDIR='Maildir E-mail directories' \
24 SOCKETS='Network support' \
25 TLS='Transport Layer Security (OpenSSL / LibreSSL)' \
26 TLS_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='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 UISTRINGS='User interface and error message strings' \
48 QUOTE_FOLD='Extended *quote-fold*ing' \
49 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
50 COLOUR='Coloured message display' \
51 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
54 # Options which are automatically deduced from host environment, i.e., these
55 # need special treatment all around here to warp from/to OPT_ stuff
56 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
57 XOPTIONS_DETECT="\
58 LOCALES='Locale support - printable characters etc. depend on environment' \
59 MULTIBYTE_CHARSETS='Multibyte character sets' \
60 TERMINAL_CHARSET='Automatic detection of terminal character set' \
61 WIDE_GLYPHS='Wide glyph support' \
64 # Rather special options, for custom building, or which always exist.
65 # Mostly for generating the visual overview and the *features* string
66 XOPTIONS_XTRA="\
67 MIME='Multipurpose Internet Mail Extensions' \
68 SMIME='S/MIME message signing, verification, en- and decryption' \
69 CROSS_BUILD='Cross-compilation: trust any detected environment' \
70 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
71 DEVEL='Computers do not blunder' \
74 # To avoid too many recompilations we use a two-stage "configuration changed"
75 # detection, the first uses mk-config.lst, which only goes for actual user
76 # config settings etc. the second uses mk-config.h, which thus includes the
77 # things we have truly detected. This does not work well for multiple choice
78 # values of which only one will be really used, so those user wishes may not be
79 # placed in the header, only the really detected one (but that has to!).
80 # Used for grep(1), for portability assume fixed matching only.
81 H_BLACKLIST='-e VAL_RANDOM -e VAL_IDNA'
83 # The problem is that we don't have any tools we can use right now, so
84 # encapsulate stuff in functions which get called in right order later on
86 option_reset() {
87 set -- ${OPTIONS}
88 for i
90 eval OPT_${i}=0
91 done
94 option_maximal() {
95 set -- ${OPTIONS}
96 for i
98 eval OPT_${i}=1
99 done
100 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
103 option_setup() {
104 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
105 option_parse OPTIONS "${XOPTIONS}"
106 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
107 OPT_MIME=1
109 # Predefined CONFIG= urations take precedence over anything else
110 if [ -n "${CONFIG}" ]; then
111 option_reset
112 case "${CONFIG}" in
113 [nN][uU][lL][lL])
115 [nN][uU][lL][lL][iI])
116 OPT_ICONV=require
117 OPT_UISTRINGS=1
119 [mM][iI][nN][iI][mM][aA][lL])
120 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
121 OPT_COLOUR=1
122 OPT_DOCSTRINGS=1
123 OPT_UISTRINGS=1
124 OPT_ERRORS=1
125 OPT_IDNA=1
126 OPT_MAILDIR=1
127 OPT_MLE=1
128 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
129 OPT_SPAM_FILTER=1
131 [nN][eE][tT][sS][eE][nN][dD])
132 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
133 OPT_SOCKETS=require
134 OPT_TLS=require
135 OPT_SMTP=require
136 OPT_GSSAPI=1 OPT_NETRC=1
137 OPT_AGENT=1
138 OPT_COLOUR=1
139 OPT_DOCSTRINGS=1
140 OPT_UISTRINGS=1
141 OPT_ERRORS=1
142 OPT_IDNA=1
143 OPT_MAILDIR=1
144 OPT_MLE=1
145 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
146 OPT_SPAM_FILTER=1
148 [mM][aA][xX][iI][mM][aA][lL])
149 option_maximal
151 [dD][eE][vV][eE][lL])
152 option_maximal
153 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
155 [oO][dD][eE][vV][eE][lL])
156 option_maximal
157 OPT_DEVEL=1
160 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
161 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
162 exit 1
164 esac
165 msg_nonl "CONFIG=${CONFIG} ... "
169 # Inter-relationships XXX sort this!
170 option_update() {
171 if feat_no TLS; then
172 OPT_TLS_ALL_ALGORITHMS=0
175 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
176 OPT_SOCKETS=0
178 if feat_no SOCKETS; then
179 if feat_require SMTP; then
180 msg 'ERROR: need SOCKETS for required feature SMTP'
181 config_exit 13
183 if feat_require POP3; then
184 msg 'ERROR: need SOCKETS for required feature POP3'
185 config_exit 13
187 if feat_require IMAP; then
188 msg 'ERROR: need SOCKETS for required feature IMAP'
189 config_exit 13
191 OPT_TLS=0 OPT_TLS_ALL_ALGORITHMS=0
192 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
193 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
195 if feat_no SMTP && feat_no IMAP; then
196 OPT_GSSAPI=0
199 if feat_no ICONV; then
200 if feat_yes IMAP; then
201 if feat_yes ALWAYS_UNICODE_LOCALE; then
202 msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
203 elif feat_require IMAP; then
204 msg 'ERROR: need ICONV for required feature IMAP'
205 config_exit 13
206 else
207 msg 'ERROR: disabling IMAP due to missing ICONV'
208 OPT_IMAP=0
212 if feat_yes IDNA; then
213 if feat_require IDNA; then
214 msg 'ERROR: need ICONV for required feature IDNA'
215 config_exit 13
217 msg 'ERROR: disabling IDNA due to missing ICONV'
218 OPT_IDNA=0
222 if feat_no MLE; then
223 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
226 # If we don't need MD5 leave it alone
227 if feat_no SOCKETS; then
228 OPT_MD5=0
231 if feat_no TERMCAP; then
232 OPT_TERMCAP_VIA_TERMINFO=0
235 if feat_yes DEVEL; then
236 OPT_DEBUG=1
240 rc=./make.rc
241 lst=.obj/mk-config.lst
242 ev=.obj/mk-config.ev
243 h=.obj/mk-config.h h_name=mk-config.h
244 mk=.obj/mk-config.mk
246 newlst=.obj/mk-nconfig.lst
247 newmk=.obj/mk-nconfig.mk
248 oldmk=.obj/mk-oconfig.mk
249 newev=.obj/mk-nconfig.ev
250 newh=.obj/mk-nconfig.h
251 oldh=.obj/mk-oconfig.h
252 tmp0=.obj/___tmp
253 tmp=${tmp0}1$$
254 tmp2=${tmp0}2$$
256 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
258 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
259 # via path_check() later on once possible
261 COMMLINE="${*}"
263 # TODO cc_maxopt is brute simple, we should compile test program and dig real
264 # compiler versions for known compilers, then be more specific
265 [ -n "${cc_maxopt}" ] || cc_maxopt=100
266 #cc_force_no_stackprot=
267 #ld_need_R_flags=
268 #ld_no_bind_now=
269 #ld_rpath_not_runpath=
271 _CFLAGS= _LDFLAGS=
273 os_early_setup() {
274 # We don't "have any utility" (see make.rc)
275 [ -n "${OS}" ] && [ -n "${OSFULLSPEC}" ] ||
276 thecmd_testandset_fail uname uname
278 [ -n "${OS}" ] || OS=`${uname} -s`
279 export OS
280 msg 'Operating system is %s' "${OS}"
282 if [ ${OS} = SunOS ]; then
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
294 os_setup() {
295 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
296 # etc.), it is not baked into the binary
297 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
299 if [ ${OS} = darwin ]; then
300 msg ' . have special Darwin environmental addons...'
301 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
302 elif [ ${OS} = sunos ]; then
303 msg ' . have special SunOS / Solaris "setup" rules ...'
304 _os_setup_sunos
305 elif [ ${OS} = unixware ]; then
306 if feat_yes AUTOCC && acmd_set CC cc; then
307 msg ' . have special UnixWare environmental rules ...'
308 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
310 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
311 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
312 export CC CFLAGS LDFLAGS
313 OPT_AUTOCC=0 ld_need_R_flags=-R
315 elif [ -n "${VERBOSE}" ]; then
316 msg ' . no special treatment for this system necessary or known'
319 # Sledgehammer: better set _GNU_SOURCE
320 # And in general: oh, boy!
321 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
322 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
323 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
324 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
326 # On pkgsrc(7) systems automatically add /usr/pkg/*
327 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
328 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
329 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
330 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
331 ld_rpath_not_runpath=1
335 _os_setup_sunos() {
336 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
337 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
339 # Include packages
340 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
341 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
342 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
343 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
344 ld_no_bind_now=1 ld_rpath_not_runpath=1
346 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
347 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
348 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
349 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
350 ld_no_bind_now=1 ld_rpath_not_runpath=1
353 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
354 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
356 if feat_yes AUTOCC; then
357 if acmd_set CC cc; then
358 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
360 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
361 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
362 export CC CFLAGS LDFLAGS
363 OPT_AUTOCC=0 ld_need_R_flags=-R
364 else
365 cc_maxopt=2 cc_force_no_stackprot=1
370 # Check out compiler ($CC) and -flags ($CFLAGS)
371 cc_setup() {
372 # Even though it belongs into cc_flags we will try to compile and link
373 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
374 # EXTRA_CFLAGS/EXTRA_LDFLAGS
375 if feat_no AUTOCC; then
376 _cc_default
377 # Ensure those don't do any harm
378 EXTRA_CFLAGS= EXTRA_LDFLAGS=
379 export EXTRA_CFLAGS EXTRA_LDFLAGS
380 return
381 else
382 CFLAGS= LDFLAGS=
383 export CFLAGS LDFLAGS
386 [ -n "${CC}" ] && { _cc_default; return; }
388 msg_nonl 'Searching for a usable C compiler .. $CC='
389 if acmd_set CC clang || acmd_set CC gcc ||
390 acmd_set CC tcc || acmd_set CC pcc ||
391 acmd_set CC c89 || acmd_set CC c99; then
393 else
394 msg 'boing booom tschak'
395 msg 'ERROR: I cannot find a compiler!'
396 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
397 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
398 config_exit 1
400 msg '%s' "${CC}"
401 export CC
404 _cc_default() {
405 if [ -z "${CC}" ]; then
406 msg 'To go on like you have chosen, please set $CC, rerun.'
407 config_exit 1
410 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
412 else
413 msg 'Using C compiler ${CC}=%s' "${CC}"
417 cc_flags() {
418 if feat_yes AUTOCC; then
419 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
420 cc_check_silent=1
421 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
422 "${CC}"
423 else
424 cc_check_silent=
425 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
428 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
429 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
430 msg ' . have special tcc(1) environmental rules ...'
431 _cc_flags_tcc
432 else
433 # As of pcc CVS 2016-04-02, stack protection support is announced but
434 # will break if used on Linux
435 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
436 cc_force_no_stackprot=1
438 _cc_flags_generic
441 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
442 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
443 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
444 else
445 if feat_no DEBUG; then
446 CFLAGS="-DNDEBUG ${CFLAGS}"
449 export CFLAGS LDFLAGS
452 _cc_flags_tcc() {
453 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
454 _CFLAGS= _LDFLAGS=
456 cc_check -W
457 cc_check -Wall
458 cc_check -Wextra
459 cc_check -pedantic
461 if feat_yes DEBUG; then
462 # May have problems to find libtcc cc_check -b
463 cc_check -g
466 if ld_check -Wl,-rpath =./ no; then
467 ld_need_R_flags=-Wl,-rpath=
468 if [ -z "${ld_rpath_not_runpath}" ]; then
469 ld_check -Wl,--enable-new-dtags
470 else
471 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
473 ld_runtime_flags # update!
476 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
477 unset __cflags __ldflags
480 _cc_flags_generic() {
481 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
482 _CFLAGS= _LDFLAGS=
483 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
485 # E.g., valgrind does not work well with high optimization
486 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
487 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
488 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
489 cc_maxopt=1
491 # Check -g first since some others may rely upon -g / optim. level
492 if feat_yes DEBUG; then
493 cc_check -O
494 cc_check -g
495 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
497 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
499 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
501 else
502 cc_check -O
505 if feat_yes AMALGAMATION; then
506 cc_check -pipe
509 #if feat_yes DEVEL && cc_check -Weverything; then
511 #else
512 cc_check -W
513 cc_check -Wall
514 cc_check -Wextra
515 cc_check -Wbad-function-cast
516 cc_check -Wcast-align
517 cc_check -Wcast-qual
518 cc_check -Winit-self
519 cc_check -Wmissing-prototypes
520 cc_check -Wshadow
521 cc_check -Wunused
522 cc_check -Wwrite-strings
523 cc_check -Wno-long-long
525 cc_check -pedantic
527 if feat_yes AMALGAMATION && feat_no DEVEL; then
528 cc_check -Wno-unused-function
530 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
532 cc_check -fno-unwind-tables
533 cc_check -fno-asynchronous-unwind-tables
534 cc_check -fstrict-aliasing
535 if cc_check -fstrict-overflow && feat_yes DEVEL; then
536 cc_check -Wstrict-overflow=5
539 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
540 if [ -z "${cc_force_no_stackprot}" ]; then
541 if cc_check -fstack-protector-strong ||
542 cc_check -fstack-protector-all; then
543 cc_check -D_FORTIFY_SOURCE=2
545 else
546 msg ' ! Not checking for -fstack-protector compiler option,'
547 msg ' ! since that caused errors in a "similar" configuration.'
548 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
552 # LD (+ dependend CC)
554 if feat_yes ASAN_ADDRESS; then
555 _ccfg=${_CFLAGS}
556 if cc_check -fsanitize=address && ld_check -fsanitize=address; then
558 else
559 feat_bail_required ASAN_ADDRESS
560 _CFLAGS=${_ccfg}
564 if feat_yes ASAN_MEMORY; then
565 _ccfg=${_CFLAGS}
566 if cc_check -fsanitize=memory && 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 if feat_yes USAN; then
577 _ccfg=${_CFLAGS}
578 if cc_check -fsanitize=undefined && ld_check -fsanitize=undefined; then
580 else
581 feat_bail_required USAN
582 _CFLAGS=${_ccfg}
586 ld_check -Wl,-z,relro
587 if [ -z "${ld_no_bind_now}" ]; then
588 ld_check -Wl,-z,now
589 else
590 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
592 ld_check -Wl,-z,noexecstack
593 ld_check -Wl,--as-needed
594 if ld_check -Wl,-rpath =./ no; then
595 ld_need_R_flags=-Wl,-rpath=
596 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
597 if [ -z "${ld_rpath_not_runpath}" ]; then
598 ld_check -Wl,--enable-new-dtags
599 else
600 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
602 ld_runtime_flags # update!
603 elif ld_check -Wl,-R ./ no; then
604 ld_need_R_flags=-Wl,-R
605 if [ -z "${ld_rpath_not_runpath}" ]; then
606 ld_check -Wl,--enable-new-dtags
607 else
608 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
610 ld_runtime_flags # update!
613 # Address randomization
614 _ccfg=${_CFLAGS}
615 if cc_check -fPIE || cc_check -fpie; then
616 ld_check -pie || _CFLAGS=${_ccfg}
618 unset _ccfg
620 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
621 unset __cflags __ldflags
624 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
626 ## Notes:
627 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
628 ## redirection, so use "printf '' >" instead
630 ## Very first: we undergo several states regarding I/O redirection etc.,
631 ## but need to deal with option updates from within all. Since all the
632 ## option stuff should be above the scissor line, define utility functions
633 ## and redefine them as necessary.
634 ## And, since we have those functions, simply use them for whatever
636 t1=ten10one1ten10one1
637 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
638 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
639 ) > /dev/null 2>&1; then
640 good_shell=1
641 else
642 unset good_shell
644 unset t1
646 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
648 config_exit() {
649 exit ${1}
652 # which(1) not standardized, command(1) -v may return non-executable: unroll!
653 acmd_test() { __acmd "${1}" 1 0 0; }
654 acmd_test_fail() { __acmd "${1}" 1 1 0; }
655 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
656 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
657 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
658 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
659 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
660 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
661 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
662 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
663 __acmd() {
664 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
666 if [ "${dotest}" -ne 0 ]; then
667 eval dotest=\$${varname}
668 if [ -n "${dotest}" ]; then
669 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
670 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
671 return 0
675 oifs=${IFS} IFS=:
676 [ -n "${noglob_shell}" ] && set -o noglob
677 set -- ${PATH}
678 [ -n "${noglob_shell}" ] && set +o noglob
679 IFS=${oifs}
680 for path
682 if [ -z "${path}" ] || [ "${path}" = . ]; then
683 if [ -d "${PWD}" ]; then
684 path=${PWD}
685 else
686 path=.
689 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
690 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
691 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
692 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
693 return 0
695 done
697 # We may have no builtin string functions, we yet have no programs we can
698 # use, try to access once from the root, assuming it is an absolute path if
699 # that finds the executable
700 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
701 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
702 msg ' . ${%s} ... %s' "${pname}" "${pname}"
703 [ -n "${varname}" ] && eval ${varname}="${pname}"
704 return 0
707 [ ${dofail} -eq 0 ] && return 1
708 msg 'ERROR: no trace of utility '"${pname}"
709 exit 1
712 msg() {
713 fmt=${1}
714 shift
715 printf >&2 -- "${fmt}\\n" "${@}"
718 msg_nonl() {
719 fmt=${1}
720 shift
721 printf >&2 -- "${fmt}" "${@}"
724 # Our feature check environment
725 feat_val_no() {
726 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
727 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
730 feat_val_yes() {
731 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
732 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
733 [ "x${1}" = xrequire ]
736 feat_val_require() {
737 [ "x${1}" = xrequire ]
740 _feat_check() {
741 eval i=\$OPT_${1}
742 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
743 if feat_val_no "${i}"; then
744 return 1
745 elif feat_val_yes "${i}"; then
746 return 0
747 else
748 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
749 "${1}" "${i}"
750 config_exit 11
754 feat_yes() {
755 _feat_check ${1}
758 feat_no() {
759 _feat_check ${1} && return 1
760 return 0
763 feat_require() {
764 eval i=\$OPT_${1}
765 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
766 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
769 feat_bail_required() {
770 if feat_require ${1}; then
771 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
772 config_exit 13
774 feat_is_unsupported "${1}"
777 feat_is_disabled() {
778 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
779 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
782 feat_is_unsupported() {
783 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
784 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
785 eval OPT_${1}=0
786 option_update # XXX this is rather useless here (dependency chain..)
789 feat_def() {
790 if feat_yes ${1}; then
791 msg ' . %s ... yes' "${1}"
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}\"
992 else
993 # Enfore lowercase also in otherwise unchanged user value..
994 eval "${1}"=\""`echo ${__expo__} | ${tr} '[A-Z]_' '[a-z]-'`"\"
996 return 0
999 path_check() {
1000 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
1001 varname=${1} addflag=${2} flagvarname=${3}
1002 j=${IFS}
1003 IFS=:
1004 [ -n "${noglob_shell}" ] && set -o noglob
1005 eval "set -- \$${1}"
1006 [ -n "${noglob_shell}" ] && set +o noglob
1007 IFS=${j}
1008 j= k= y= z=
1009 for i
1011 [ -z "${i}" ] && continue
1012 [ -d "${i}" ] || continue
1013 if [ -n "${j}" ]; then
1014 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1016 else
1017 y="${y} :${i}:"
1018 j="${j}:${i}"
1019 # But do not link any fakeroot path into our binaries!
1020 if [ -n "${addflag}" ]; then
1021 case "${i}" in *fakeroot*) continue;; esac
1022 k="${k} ${addflag}${i}"
1025 else
1026 y=" :${i}:"
1027 j="${i}"
1028 # But do not link any fakeroot path into our binaries!
1029 if [ -n "${addflag}" ]; then
1030 case "${i}" in *fakeroot*) continue;; esac
1031 k="${k} ${addflag}${i}"
1034 done
1035 eval "${varname}=\"${j}\""
1036 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1037 unset varname
1040 ld_runtime_flags() {
1041 if [ -n "${ld_need_R_flags}" ]; then
1042 i=${IFS}
1043 IFS=:
1044 set -- ${LD_LIBRARY_PATH}
1045 IFS=${i}
1046 for i
1048 # But do not link any fakeroot path into our binaries!
1049 case "${i}" in *fakeroot*) continue;; esac
1050 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1051 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1052 done
1053 export LDFLAGS
1055 # Disable it for a possible second run.
1056 ld_need_R_flags=
1059 cc_check() {
1060 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1061 if ${CC} ${INCS} \
1062 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1063 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1064 _CFLAGS="${_CFLAGS} ${1}"
1065 [ -n "${cc_check_silent}" ] || msg 'yes'
1066 return 0
1068 [ -n "${cc_check_silent}" ] || msg 'no'
1069 return 1
1072 ld_check() {
1073 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1074 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1075 if ${CC} ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1076 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1077 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1078 [ -n "${cc_check_silent}" ] || msg 'yes'
1079 return 0
1081 [ -n "${cc_check_silent}" ] || msg 'no'
1082 return 1
1085 dump_test_program=1
1086 _check_preface() {
1087 variable=$1 topic=$2 define=$3
1089 echo '**********'
1090 msg_nonl ' . %s ... ' "${topic}"
1091 #echo "/* checked ${topic} */" >> ${h}
1092 ${rm} -f ${tmp} ${tmp}.o
1093 if [ "${dump_test_program}" = 1 ]; then
1094 echo '*** test program is'
1095 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1096 else
1097 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1099 #echo '*** the preprocessor generates'
1100 #${make} -f ${makefile} ${tmp}.x
1101 #${cat} ${tmp}.x
1102 echo '*** tests results'
1105 without_check() {
1106 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1108 echo '**********'
1109 msg_nonl ' . %s ... ' "${topic}"
1111 echo '*** enforced unchecked results are'
1112 if feat_val_yes ${yesno}; then
1113 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1114 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1115 LIBS="${LIBS} ${libs}"
1116 echo "${libs}" >> ${lib}
1117 INCS="${INCS} ${incs}"
1118 echo "${incs}" >> ${inc}
1120 msg 'yes (deduced)'
1121 echo "${define}" >> ${h}
1122 eval have_${variable}=yes
1123 return 0
1124 else
1125 #echo "/* ${define} */" >> ${h}
1126 msg 'no (deduced)'
1127 eval unset have_${variable}
1128 return 1
1132 compile_check() {
1133 variable=$1 topic=$2 define=$3
1135 _check_preface "${variable}" "${topic}" "${define}"
1137 if ${make} -f ${makefile} XINCS="${INCS}" \
1138 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ${tmp}.o &&
1139 [ -f ${tmp}.o ]; then
1140 msg 'yes'
1141 echo "${define}" >> ${h}
1142 eval have_${variable}=yes
1143 return 0
1144 else
1145 #echo "/* ${define} */" >> ${h}
1146 msg 'no'
1147 eval unset have_${variable}
1148 return 1
1152 _link_mayrun() {
1153 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1155 _check_preface "${variable}" "${topic}" "${define}"
1157 if feat_yes CROSS_BUILD; then
1158 if [ ${run} = 1 ]; then
1159 run=0
1163 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1164 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1165 XLIBS="${LIBS} ${libs}" ${tmp} &&
1166 [ -f ${tmp} ] && { [ ${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 if [ -d .obj ] || mkdir .obj; then :; else
1206 msg 'ERROR: cannot create .obj build directory'
1207 exit 1
1210 # Very easy checks for the operating system in order to be able to adjust paths
1211 # or similar very basic things which we need to be able to go at all
1212 os_early_setup
1214 # Check those tools right now that we need before including $rc
1215 msg 'Checking for basic utility set'
1216 thecmd_testandset_fail awk awk
1217 thecmd_testandset_fail rm rm
1218 thecmd_testandset_fail tr tr
1220 # Lowercase this now in order to isolate all the remains from case matters
1221 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
1222 export OS
1224 # Initialize the option set
1225 msg_nonl 'Setting up configuration options ... '
1226 option_setup
1227 msg 'done'
1229 # Include $rc, but only take from it what wasn't overwritten by the user from
1230 # within the command line or from a chosen fixed CONFIG=
1231 # Note we leave alone the values
1232 trap "exit 1" HUP INT TERM
1233 trap "${rm} -f ${tmp}" EXIT
1235 msg_nonl 'Joining in %s ... ' ${rc}
1236 option_join_rc
1237 msg 'done'
1239 # We need to know about that now, in order to provide utility overwrites etc.
1240 os_setup
1242 msg 'Checking for remaining set of utilities'
1243 thecmd_testandset_fail grep grep
1245 # Before we step ahead with the other utilities perform a path cleanup first.
1246 path_check PATH
1248 # awk(1) above
1249 thecmd_testandset_fail basename basename
1250 thecmd_testandset_fail cat cat
1251 thecmd_testandset_fail chmod chmod
1252 thecmd_testandset_fail cp cp
1253 thecmd_testandset_fail cmp cmp
1254 # grep(1) above
1255 thecmd_testandset_fail mkdir mkdir
1256 thecmd_testandset_fail mv mv
1257 # pwd(1) is needed - either for make-emerge.sh, or for ourselves
1258 [ -n "${CWDDIR}" ] || thecmd_testandset_fail pwd pwd
1259 # rm(1) above
1260 thecmd_testandset_fail sed sed
1261 thecmd_testandset_fail sort sort
1262 thecmd_testandset_fail tee tee
1263 __PATH=${PATH}
1264 thecmd_testandset chown chown ||
1265 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1266 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1267 PATH=${__PATH}
1268 thecmd_testandset_fail MAKE make
1269 make=${MAKE}
1270 export MAKE
1271 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1273 # For ./cc-test.sh only
1274 thecmd_testandset_fail cksum cksum
1276 # Now that we have pwd(1), set our build paths unless make-emerge.sh has been
1277 # used; it would have created a makefile with the full paths, then
1278 [ -n "${CWDDIR}" ] || CWDDIR=`${pwd}`/
1279 [ -n "${SRCDIR}" ] || SRCDIR=${CWDDIR}
1281 # Update OPT_ options now, in order to get possible inter-dependencies right
1282 option_update
1284 # (No functions since some shells loose non-exported variables in traps)
1285 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1286 trap "trap \"\" HUP INT TERM EXIT;\
1287 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1288 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1290 # Our configuration options may at this point still contain shell snippets,
1291 # we need to evaluate them in order to get them expanded, and we need those
1292 # evaluated values not only in our new configuration file, but also at hand..
1293 msg_nonl 'Evaluating all configuration items ... '
1294 option_evaluate
1295 msg 'done'
1298 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1299 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1301 # The problem now is that the test should be able to run in the users linker
1302 # and path environment, so we need to place the test: rule first, before
1303 # injecting the relevant make variables. Set up necessary environment
1304 if [ -z "${VERBOSE}" ]; then
1305 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1306 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1307 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1308 printf -- "ECHO_TEST = @\n" >> ${newmk}
1309 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1310 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1311 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1313 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only %s\n' \
1314 "${SHELL}" "${SRCDIR}" "./${VAL_SID}${VAL_MAILX}" >> ${newmk}
1316 # Add the known utility and some other variables
1317 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1318 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1319 if feat_yes DOTLOCK; then
1320 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1321 else
1322 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1325 for i in \
1326 CWDDIR SRCDIR \
1327 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1328 MAKE MAKEFLAGS make SHELL strip \
1329 cksum; do
1330 eval j=\$${i}
1331 printf -- "${i} = ${j}\n" >> ${newmk}
1332 printf -- "${i}=${j}\n" >> ${newlst}
1333 printf -- "${i}=\"${j}\";export ${i}; " >> ${newev}
1334 done
1335 # Note that makefile reads and eval'uates one line of this file, whereas other
1336 # consumers source it via .(1)
1337 printf "\n" >> ${newev}
1339 # Build a basic set of INCS and LIBS according to user environment.
1340 C_INCLUDE_PATH="${CWDDIR}:${CWDDIR}.obj:${SRCDIR}:${C_INCLUDE_PATH}"
1341 path_check C_INCLUDE_PATH -I _INCS
1342 INCS="${INCS} ${_INCS}"
1343 path_check LD_LIBRARY_PATH -L _LIBS
1344 LIBS="${LIBS} ${_LIBS}"
1345 unset _INCS _LIBS
1346 export C_INCLUDE_PATH LD_LIBRARY_PATH
1348 # Some environments need runtime path flags to be able to go at all
1349 ld_runtime_flags
1351 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1353 cc_setup
1355 ${cat} > ${tmp}.c << \!
1356 #include <stdio.h>
1357 #include <string.h>
1358 static void doit(char const *s);
1360 main(int argc, char **argv){
1361 (void)argc;
1362 (void)argv;
1363 doit("Hello world");
1364 return 0;
1366 static void
1367 doit(char const *s){
1368 char buf[12];
1369 memcpy(buf, s, strlen(s) +1);
1370 puts(s);
1374 if ${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1375 -o ${tmp2} ${tmp}.c ${LIBS}; then
1377 else
1378 msg 'ERROR: i cannot compile a "Hello world" via'
1379 msg ' %s' \
1380 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1381 msg 'ERROR: Please read INSTALL, rerun'
1382 config_exit 1
1385 # This may also update ld_runtime_flags() (again)
1386 cc_flags
1388 for i in \
1389 COMMLINE \
1390 INCS LIBS \
1391 ; do
1392 eval j="\$${i}"
1393 printf -- "${i}=${j}\n" >> ${newlst}
1394 done
1395 for i in \
1396 CC \
1397 CFLAGS \
1398 LDFLAGS \
1399 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1400 OSFULLSPEC \
1401 ; do
1402 eval j=\$${i}
1403 if [ -n "${j}" ]; then
1404 printf -- "${i} = ${j}\n" >> ${newmk}
1405 printf -- "${i}=${j}\n" >> ${newlst}
1407 done
1409 # Now finally check whether we already have a configuration and if so, whether
1410 # all those parameters are still the same.. or something has actually changed
1411 config_updated=
1412 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1413 echo 'Configuration is up-to-date'
1414 exit 0
1415 elif [ -f ${lst} ]; then
1416 config_updated=1
1417 echo 'Configuration has been updated..'
1418 else
1419 echo 'Shiny configuration..'
1422 # Time to redefine helper 1
1423 config_exit() {
1424 ${rm} -f ${lst} ${h} ${mk}
1425 exit ${1}
1428 ${mv} -f ${newlst} ${lst}
1429 ${mv} -f ${newev} ${ev}
1430 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1431 ${mv} -f ${newh} ${h}
1432 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1433 ${mv} -f ${newmk} ${mk}
1435 ## Compile and link checking
1437 tmp3=${tmp0}3$$
1438 log=.obj/mk-config.log
1439 lib=.obj/mk-config.lib
1440 inc=.obj/mk-config.inc
1441 makefile=${tmp0}.mk
1443 # (No function since some shells loose non-exported variables in traps)
1444 trap "trap \"\" HUP INT TERM;\
1445 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1446 HUP INT TERM
1447 trap "trap \"\" HUP INT TERM EXIT;\
1448 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1450 # Time to redefine helper 2
1451 msg() {
1452 fmt=${1}
1453 shift
1454 printf "*** ${fmt}\\n" "${@}"
1455 printf -- "${fmt}\\n" "${@}" >&5
1457 msg_nonl() {
1458 fmt=${1}
1459 shift
1460 printf "*** ${fmt}\\n" "${@}"
1461 printf -- "${fmt}" "${@}" >&5
1464 # !!
1465 exec 5>&2 > ${log} 2>&1
1467 echo "${LIBS}" > ${lib}
1468 echo "${INCS}" > ${inc}
1469 ${cat} > ${makefile} << \!
1470 .SUFFIXES: .o .c .x .y
1471 .c.o:
1472 $(CC) -I./ $(XINCS) $(CFLAGS) -o $(@) -c $(<)
1473 .c.x:
1474 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1476 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1479 ## Generics
1481 # May be multiline..
1482 echo >> ${h}
1483 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1484 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1486 # Generate n_err_number OS mappings
1487 dump_test_program=0
1489 feat_yes DEVEL && NV= || NV=noverbose
1490 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1491 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1492 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1493 dump_test_program=1
1495 feat_def ALWAYS_UNICODE_LOCALE
1496 feat_def AMALGAMATION 0
1497 feat_def CROSS_BUILD
1498 feat_def DOCSTRINGS
1499 feat_def MAILDIR
1500 feat_def UISTRINGS
1501 feat_def ERRORS
1503 feat_def ASAN_ADDRESS 0
1504 feat_def ASAN_MEMORY 0
1505 feat_def DEBUG 0
1506 feat_def DEVEL 0
1507 feat_def NYD2 0
1508 feat_def NOMEMDBG 0
1510 if xrun_check inline 'inline functions' \
1511 '#define HAVE_INLINE
1512 #define n_INLINE static inline' << \!
1513 static inline int ilf(int i){return ++i;}
1514 int main(void){return ilf(-1);}
1516 then
1518 elif xrun_check inline 'inline functions (via __inline)' \
1519 '#define HAVE_INLINE
1520 #define n_INLINE static __inline' << \!
1521 static __inline int ilf(int i){return ++i;}
1522 int main(void){return ilf(-1);}
1524 then
1528 ## Test for "basic" system-calls / functionality that is used by all parts
1529 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1530 ## macros to be used by only the subprograms (potentially).
1532 if run_check clock_gettime 'clock_gettime(2)' \
1533 '#define HAVE_CLOCK_GETTIME' << \!
1534 #include <time.h>
1535 # include <errno.h>
1536 int main(void){
1537 struct timespec ts;
1539 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1540 return 0;
1541 return 1;
1544 then
1546 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1547 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1548 #include <time.h>
1549 # include <errno.h>
1550 int main(void){
1551 struct timespec ts;
1553 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1554 return 0;
1555 return 1;
1558 then
1560 elif run_check gettimeofday 'gettimeofday(2)' \
1561 '#define HAVE_GETTIMEOFDAY' << \!
1562 #include <stdio.h> /* For C89 NULL */
1563 #include <sys/time.h>
1564 # include <errno.h>
1565 int main(void){
1566 struct timeval tv;
1568 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1569 return 0;
1570 return 1;
1573 then
1575 else
1576 have_no_subsecond_time=1
1579 if run_check nanosleep 'nanosleep(2)' \
1580 '#define HAVE_NANOSLEEP' << \!
1581 #include <time.h>
1582 # include <errno.h>
1583 int main(void){
1584 struct timespec ts;
1586 ts.tv_sec = 1;
1587 ts.tv_nsec = 100000;
1588 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1589 return 0;
1590 return 1;
1593 then
1595 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1596 '#define HAVE_NANOSLEEP' '-lrt' << \!
1597 #include <time.h>
1598 # include <errno.h>
1599 int main(void){
1600 struct timespec ts;
1602 ts.tv_sec = 1;
1603 ts.tv_nsec = 100000;
1604 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1605 return 0;
1606 return 1;
1609 then
1611 # link_check is enough for this, that function is so old, trust the proto
1612 elif link_check sleep 'sleep(3)' \
1613 '#define HAVE_SLEEP' << \!
1614 #include <unistd.h>
1615 # include <errno.h>
1616 int main(void){
1617 if(!sleep(1) || errno != ENOSYS)
1618 return 0;
1619 return 1;
1622 then
1624 else
1625 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1626 config_exit 1
1629 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1630 #include <pwd.h>
1631 #include <unistd.h>
1632 # include <errno.h>
1633 int main(void){
1634 struct passwd *pw;
1635 gid_t gid;
1636 uid_t uid;
1638 if((gid = getgid()) != 0)
1639 gid = getegid();
1640 if((uid = getuid()) != 0)
1641 uid = geteuid();
1642 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1643 return 1;
1644 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1645 return 1;
1646 return 0;
1649 then
1651 else
1652 msg 'ERROR: we require user and group info / database searches.'
1653 msg 'That much Unix we indulge ourselfs.'
1654 config_exit 1
1657 if link_check ftruncate 'ftruncate(2)' \
1658 '#define HAVE_FTRUNCATE' << \!
1659 #include <unistd.h>
1660 #include <sys/types.h>
1661 int main(void){
1662 return (ftruncate(0, 0) != 0);
1665 then
1667 else
1668 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1669 msg 'ERROR: we require the ftruncate(2) system call.'
1670 config_exit 1
1673 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1674 #include <signal.h>
1675 # include <errno.h>
1676 int main(void){
1677 struct sigaction nact, oact;
1679 nact.sa_handler = SIG_DFL;
1680 sigemptyset(&nact.sa_mask);
1681 nact.sa_flags = SA_RESTART;
1682 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1685 then
1687 else
1688 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1689 config_exit 1
1692 if link_check snprintf 'snprintf(3)' << \!
1693 #include <stdio.h>
1694 int main(void){
1695 char b[20];
1697 snprintf(b, sizeof b, "%s", "string");
1698 return 0;
1701 then
1703 else
1704 msg 'ERROR: we require the snprintf(3) function.'
1705 config_exit 1
1708 if link_check environ 'environ(3)' << \!
1709 #include <stdio.h> /* For C89 NULL */
1710 int main(void){
1711 extern char **environ;
1713 return environ[0] == NULL;
1716 then
1718 else
1719 msg 'ERROR: we require the environ(3) array for subprocess control.'
1720 config_exit 1
1723 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1724 #include <stdlib.h>
1725 int main(void){
1726 setenv("s-mailx", "i want to see it cute!", 1);
1727 unsetenv("s-mailx");
1728 return 0;
1731 then
1733 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1734 #include <stdlib.h>
1735 int main(void){
1736 putenv("s-mailx=i want to see it cute!");
1737 return 0;
1740 then
1742 else
1743 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1744 config_exit 1
1747 if link_check termios 'termios.h and tc*(3) family' << \!
1748 #include <termios.h>
1749 int main(void){
1750 struct termios tios;
1752 tcgetattr(0, &tios);
1753 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1754 return 0;
1757 then
1759 else
1760 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1761 msg 'That much Unix we indulge ourselfs.'
1762 config_exit 1
1765 ## optional stuff
1767 if link_check vsnprintf 'vsnprintf(3)' << \!
1768 #include <stdarg.h>
1769 #include <stdio.h>
1770 static void dome(char *buf, size_t blen, ...){
1771 va_list ap;
1773 va_start(ap, blen);
1774 vsnprintf(buf, blen, "%s", ap);
1775 va_end(ap);
1777 int main(void){
1778 char b[20];
1780 dome(b, sizeof b, "string");
1781 return 0;
1784 then
1786 else
1787 feat_bail_required ERRORS
1790 if [ "${have_vsnprintf}" = yes ]; then
1791 __va_copy() {
1792 link_check va_copy "va_copy(3) (as ${2})" \
1793 "#define HAVE_N_VA_COPY
1794 #define n_va_copy ${2}" <<_EOT
1795 #include <stdarg.h>
1796 #include <stdio.h>
1797 #if ${1}
1798 # if defined __va_copy && !defined va_copy
1799 # define va_copy __va_copy
1800 # endif
1801 #endif
1802 static void dome2(char *buf, size_t blen, va_list src){
1803 va_list ap;
1805 va_copy(ap, src);
1806 vsnprintf(buf, blen, "%s", ap);
1807 va_end(ap);
1809 static void dome(char *buf, size_t blen, ...){
1810 va_list ap;
1812 va_start(ap, blen);
1813 dome2(buf, blen, ap);
1814 va_end(ap);
1816 int main(void){
1817 char b[20];
1819 dome(b, sizeof b, "string");
1820 return 0;
1822 _EOT
1824 __va_copy 0 va_copy || __va_copy 1 __va_copy
1827 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1828 #include <unistd.h>
1829 #include <errno.h>
1830 int main(void){
1831 int rv = 0;
1833 errno = 0;
1834 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1835 errno = 0;
1836 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1838 /* Only link check */
1839 fpathconf(0, _PC_NAME_MAX);
1841 return rv;
1845 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1846 #include <fcntl.h>
1847 #include <unistd.h>
1848 # include <errno.h>
1849 int main(void){
1850 int fds[2];
1852 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1853 return 0;
1854 return 1;
1858 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1859 #include <termios.h>
1860 int main(void){
1861 struct winsize ws;
1863 tcgetwinsize(0, &ws);
1864 return 0;
1868 # We use this only then for now (need NOW+1)
1869 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1870 #include <fcntl.h> /* For AT_* */
1871 #include <sys/stat.h>
1872 # include <errno.h>
1873 int main(void){
1874 struct timespec ts[2];
1876 ts[0].tv_nsec = UTIME_NOW;
1877 ts[1].tv_nsec = UTIME_OMIT;
1878 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1879 return 0;
1880 return 1;
1886 # The random check has been moved to below TLS detection due to multiple choice
1887 # selection for PRG sources
1889 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1890 #include <stdio.h>
1891 int main(void){
1892 putc_unlocked('@', stdout);
1893 return 0;
1897 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1898 #include <unistd.h>
1899 int main(void){
1900 fchdir(0);
1901 return 0;
1905 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1906 #include <stdlib.h>
1907 int main(void){
1908 char x_buf[4096], *x = realpath(".", x_buf);
1910 return (x != NULL) ? 0 : 1;
1913 then
1914 if run_check realpath_malloc 'realpath(3) takes NULL' \
1915 '#define HAVE_REALPATH_NULL' << \!
1916 #include <stdlib.h>
1917 int main(void){
1918 char *x = realpath(".", NULL);
1920 if(x != NULL)
1921 free(x);
1922 return (x != NULL) ? 0 : 1;
1925 then
1931 ## optional and selectable
1934 if feat_yes DOTLOCK; then
1935 if run_check readlink 'readlink(2)' << \!
1936 #include <unistd.h>
1937 # include <errno.h>
1938 int main(void){
1939 char buf[128];
1941 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1942 return 0;
1943 return 1;
1946 then
1948 else
1949 feat_bail_required DOTLOCK
1953 if feat_yes DOTLOCK; then
1954 if run_check fchown 'fchown(2)' << \!
1955 #include <unistd.h>
1956 # include <errno.h>
1957 int main(void){
1958 if(!fchown(0, 0, 0) || errno != ENOSYS)
1959 return 0;
1960 return 1;
1963 then
1965 else
1966 feat_bail_required DOTLOCK
1970 if feat_yes DOTLOCK; then
1971 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1972 '#define HAVE_PRCTL_DUMPABLE' << \!
1973 #include <sys/prctl.h>
1974 # include <errno.h>
1975 int main(void){
1976 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1977 return 0;
1978 return 1;
1981 then
1983 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1984 '#define HAVE_PTRACE_DENY' << \!
1985 #include <sys/ptrace.h>
1986 # include <errno.h>
1987 int main(void){
1988 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1989 return 0;
1990 return 1;
1993 then
1995 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1996 '#define HAVE_SETPFLAGS_PROTECT' << \!
1997 #include <priv.h>
1998 # include <errno.h>
1999 int main(void){
2000 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
2001 return 0;
2002 return 1;
2005 then
2010 ## Now it is the time to fork away the BASE_ series
2012 ${rm} -f ${tmp}
2013 squeeze_em ${inc} ${tmp}
2014 ${mv} ${tmp} ${inc}
2015 squeeze_em ${lib} ${tmp}
2016 ${mv} ${tmp} ${lib}
2018 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2019 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2021 ## The remains are expected to be used only by the main MUA binary!
2023 OPT_LOCALES=0
2024 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2025 #include <locale.h>
2026 int main(void){
2027 setlocale(LC_ALL, "");
2028 return 0;
2031 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2033 OPT_MULTIBYTE_CHARSETS=0
2034 OPT_WIDE_GLYPHS=0
2035 OPT_TERMINAL_CHARSET=0
2036 if [ -n "${have_setlocale}" ]; then
2037 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2038 '#define HAVE_C90AMEND1' << \!
2039 #include <limits.h>
2040 #include <stdlib.h>
2041 #include <wchar.h>
2042 #include <wctype.h>
2043 int main(void){
2044 char mbb[MB_LEN_MAX + 1];
2045 wchar_t wc;
2047 iswprint(L'c');
2048 towupper(L'c');
2049 mbtowc(&wc, "x", 1);
2050 mbrtowc(&wc, "x", 1, NULL);
2051 wctomb(mbb, wc);
2052 return (mblen("\0", 1) == 0);
2055 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2057 if [ -n "${have_c90amend1}" ]; then
2058 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2059 #include <wchar.h>
2060 int main(void){
2061 wcwidth(L'c');
2062 return 0;
2065 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2068 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2069 #include <langinfo.h>
2070 #include <stdlib.h>
2071 int main(void){
2072 nl_langinfo(DAY_1);
2073 return (nl_langinfo(CODESET) == NULL);
2076 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2077 fi # have_setlocale
2079 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2080 #include <fnmatch.h>
2081 int main(void){
2082 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2086 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2087 #include <dirent.h>
2088 int main(void){
2089 struct dirent de;
2090 return !(de.d_type == DT_UNKNOWN ||
2091 de.d_type == DT_DIR || de.d_type == DT_LNK);
2095 ## optional and selectable
2097 if feat_yes ICONV; then
2098 # To be able to create tests we need to figure out which replacement
2099 # sequence the iconv(3) implementation creates
2100 ${cat} > ${tmp2}.c << \!
2101 #include <stdio.h> /* For C89 NULL */
2102 #include <string.h>
2103 #include <iconv.h>
2104 int main(void){
2105 char inb[16], oub[16], *inbp, *oubp;
2106 iconv_t id;
2107 size_t inl, oul;
2109 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2110 inl = sizeof("\342\200\223") -1;
2111 oul = sizeof oub;
2112 oubp = oub;
2114 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2115 return 1;
2116 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2117 return 1;
2118 iconv_close(id);
2120 *oubp = '\0';
2121 oul = (size_t)(oubp - oub);
2122 if(oul == 0)
2123 return 1;
2124 /* Character-wise replacement? */
2125 if(oul == 1){
2126 if(oub[0] == '?')
2127 return 2;
2128 if(oub[0] == '*')
2129 return 3;
2130 return 1;
2132 /* Byte-wise replacement? */
2133 if(oul == sizeof("\342\200\223") -1){
2134 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2135 return 12;
2136 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2137 return 13;
2138 return 1;
2140 return 0;
2143 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2144 '#define HAVE_ICONV' ||
2145 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2146 '#define HAVE_ICONV' '-liconv' ||
2147 feat_bail_required ICONV
2149 if feat_no CROSS_BUILD; then
2150 { ${tmp}; } >/dev/null 2>&1
2151 case ${?} in
2152 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2153 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2154 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2155 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2156 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2157 esac
2159 else
2160 feat_is_disabled ICONV
2161 fi # feat_yes ICONV
2163 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2164 ${cat} > ${tmp2}.c << \!
2165 #include <sys/types.h>
2166 #include <sys/socket.h>
2167 #include <sys/un.h>
2168 # include <errno.h>
2169 int main(void){
2170 struct sockaddr_un soun;
2172 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2173 return 1;
2174 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2175 return 1;
2176 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2177 return 1;
2178 return 0;
2182 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2183 '#define HAVE_UNIX_SOCKETS' ||
2184 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2185 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2186 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2187 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2190 if feat_yes SOCKETS; then
2191 ${cat} > ${tmp2}.c << \!
2192 #include <sys/types.h>
2193 #include <sys/socket.h>
2194 #include <netinet/in.h>
2195 # include <errno.h>
2196 int main(void){
2197 struct sockaddr s;
2199 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2200 return 1;
2201 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2202 return 1;
2203 return 0;
2207 < ${tmp2}.c run_check sockets 'sockets' \
2208 '#define HAVE_SOCKETS' ||
2209 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2210 '#define HAVE_SOCKETS' '-lnsl' ||
2211 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2212 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2213 feat_bail_required SOCKETS
2214 else
2215 feat_is_disabled SOCKETS
2216 fi # feat_yes SOCKETS
2218 feat_yes SOCKETS &&
2219 link_check sockopt '[gs]etsockopt(2)' '#define HAVE_SOCKOPT' << \!
2220 #include <sys/socket.h>
2221 #include <stdlib.h>
2222 # include <errno.h>
2223 int main(void){
2224 socklen_t sol;
2225 int sockfd = 3, soe;
2227 sol = sizeof soe;
2228 if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &soe, &sol) == -1 &&
2229 errno == ENOSYS)
2230 return 1;
2231 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2232 errno == ENOSYS)
2233 return 1;
2234 return 0;
2238 feat_yes SOCKETS &&
2239 link_check nonblocksock 'non-blocking sockets' \
2240 '#define HAVE_NONBLOCKSOCK' << \!
2241 #include <sys/types.h>
2242 #include <sys/select.h>
2243 #include <sys/socket.h>
2244 #include <sys/time.h>
2245 #include <arpa/inet.h>
2246 #include <netinet/in.h>
2247 #include <fcntl.h>
2248 #include <stdlib.h>
2249 #include <unistd.h>
2250 # include <errno.h>
2251 int main(void){
2252 fd_set fdset;
2253 struct timeval tv;
2254 struct sockaddr_in sin;
2255 socklen_t sol;
2256 int sofd, soe;
2258 if((sofd = socket(AF_INET, SOCK_STREAM, 0)) == -1 && errno == ENOSYS)
2259 return 1;
2260 if(fcntl(sofd, F_SETFL, O_NONBLOCK) != 0)
2261 return 1;
2263 sin.sin_family = AF_INET;
2264 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
2265 sin.sin_port = htons(80);
2266 if(connect(sofd, &sin, sizeof sin) == -1 && errno == ENOSYS)
2267 return 1;
2269 FD_ZERO(&fdset);
2270 FD_SET(sofd, &fdset);
2271 tv.tv_sec = 10;
2272 tv.tv_usec = 0;
2273 if((soe = select(sofd + 1, NULL, &fdset, NULL, &tv)) == 1){
2274 sol = sizeof soe;
2275 getsockopt(sofd, SOL_SOCKET, SO_ERROR, &soe, &sol);
2276 if(soe == 0)
2277 return 0;
2278 }else if(soe == -1 && errno == ENOSYS)
2279 return 1;
2281 close(sofd);
2282 return 0;
2286 if feat_yes SOCKETS; then
2287 link_check getaddrinfo 'getaddrinfo(3)' \
2288 '#define HAVE_GETADDRINFO' << \!
2289 #include <sys/types.h>
2290 #include <sys/socket.h>
2291 #include <stdio.h>
2292 #include <netdb.h>
2293 int main(void){
2294 struct addrinfo a, *ap;
2295 int lrv;
2297 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2298 case EAI_NONAME:
2299 case EAI_SERVICE:
2300 default:
2301 fprintf(stderr, "%s\n", gai_strerror(lrv));
2302 case 0:
2303 break;
2305 return 0;
2310 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2311 compile_check arpa_inet_h '<arpa/inet.h>' \
2312 '#define HAVE_ARPA_INET_H' << \!
2313 #include <sys/types.h>
2314 #include <sys/socket.h>
2315 #include <netdb.h>
2316 #include <netinet/in.h>
2317 #include <arpa/inet.h>
2320 ${cat} > ${tmp2}.c << \!
2321 #include <sys/types.h>
2322 #include <sys/socket.h>
2323 #include <stdio.h>
2324 #include <string.h>
2325 #include <netdb.h>
2326 #include <netinet/in.h>
2327 #ifdef HAVE_ARPA_INET_H
2328 #include <arpa/inet.h>
2329 #endif
2330 int main(void){
2331 struct sockaddr_in servaddr;
2332 unsigned short portno;
2333 struct servent *ep;
2334 struct hostent *hp;
2335 struct in_addr **pptr;
2337 portno = 0;
2338 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2339 portno = (unsigned short)ep->s_port;
2341 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2342 pptr = (struct in_addr**)hp->h_addr_list;
2343 if(hp->h_addrtype != AF_INET)
2344 fprintf(stderr, "au\n");
2345 }else{
2346 switch(h_errno){
2347 case HOST_NOT_FOUND:
2348 case TRY_AGAIN:
2349 case NO_RECOVERY:
2350 case NO_DATA:
2351 break;
2352 default:
2353 fprintf(stderr, "au\n");
2354 break;
2358 memset(&servaddr, 0, sizeof servaddr);
2359 servaddr.sin_family = AF_INET;
2360 servaddr.sin_port = htons(portno);
2361 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2362 fprintf(stderr, "Would connect to %s:%d ...\n",
2363 inet_ntoa(**pptr), (int)portno);
2364 return 0;
2368 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2369 < ${tmp2}.c link_check gethostbyname \
2370 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2371 < ${tmp2}.c link_check gethostbyname \
2372 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2373 '' '-lsocket -lnsl' ||
2374 feat_bail_required SOCKETS
2377 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2378 link_check so_xtimeo 'SO_{RCV,SND}TIMEO' '#define HAVE_SO_XTIMEO' << \!
2379 #include <sys/socket.h>
2380 #include <stdlib.h>
2381 int main(void){
2382 struct timeval tv;
2383 int sockfd = 3;
2385 tv.tv_sec = 42;
2386 tv.tv_usec = 21;
2387 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2388 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2389 return 0;
2393 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2394 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2395 #include <sys/socket.h>
2396 #include <stdlib.h>
2397 int main(void){
2398 struct linger li;
2399 int sockfd = 3;
2401 li.l_onoff = 1;
2402 li.l_linger = 42;
2403 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2404 return 0;
2408 VAL_TLS_FEATURES=
2409 if feat_yes TLS; then # {{{
2410 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2411 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2412 # time: we need to test it first in order to get things right
2413 if compile_check _xtls 'TLS (LibreSSL)' \
2414 '#define HAVE_TLS
2415 #define HAVE_XTLS
2416 #define HAVE_XTLS_RESSL
2417 #define HAVE_XTLS_OPENSSL 0' << \!
2418 #include <openssl/opensslv.h>
2419 #ifdef LIBRESSL_VERSION_NUMBER
2420 #else
2421 # error nope
2422 #endif
2424 then
2425 ossl_v1_1=
2426 VAL_TLS_FEATURES=libressl
2427 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2428 elif compile_check _xtls 'TLS (OpenSSL >= v1.1.0)' \
2429 '#define HAVE_TLS
2430 #define HAVE_XTLS
2431 #define HAVE_XTLS_OPENSSL 0x10100' << \!
2432 #include <openssl/opensslv.h>
2433 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2434 #else
2435 # error nope
2436 #endif
2438 then
2439 ossl_v1_1=1
2440 VAL_TLS_FEATURES=libssl-0x10100
2441 elif compile_check _xtls 'TLS (OpenSSL)' \
2442 '#define HAVE_TLS
2443 #define HAVE_XTLS
2444 #define HAVE_XTLS_OPENSSL 0x10000' << \!
2445 #include <openssl/opensslv.h>
2446 #ifdef OPENSSL_VERSION_NUMBER
2447 #else
2448 # error nope
2449 #endif
2451 then
2452 ossl_v1_1=
2453 VAL_TLS_FEATURES=libssl-0x10000
2454 else
2455 feat_bail_required TLS
2456 fi # }}}
2458 if feat_yes TLS; then # {{{
2459 if [ -n "${ossl_v1_1}" ]; then
2460 without_check yes xtls 'TLS new style TLS_client_method(3ssl)' \
2461 '#define n_XTLS_CLIENT_METHOD TLS_client_method' \
2462 '-lssl -lcrypto'
2463 elif link_check xtls 'TLS new style TLS_client_method(3ssl)' \
2464 '#define n_XTLS_CLIENT_METHOD TLS_client_method' \
2465 '-lssl -lcrypto' << \!
2466 #include <openssl/ssl.h>
2467 #include <openssl/err.h>
2468 #include <openssl/x509v3.h>
2469 #include <openssl/x509.h>
2470 #include <openssl/rand.h>
2471 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2472 # error We need TLSv1.
2473 #endif
2474 int main(void){
2475 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2477 SSL_CTX_free(ctx);
2478 PEM_read_PrivateKey(0, 0, 0, 0);
2479 return 0;
2482 then
2484 elif link_check xtls 'TLS old style SSLv23_client_method(3ssl)' \
2485 '#define n_XTLS_CLIENT_METHOD SSLv23_client_method' \
2486 '-lssl -lcrypto' << \!
2487 #include <openssl/ssl.h>
2488 #include <openssl/err.h>
2489 #include <openssl/x509v3.h>
2490 #include <openssl/x509.h>
2491 #include <openssl/rand.h>
2492 #if defined OPENSSL_NO_SSL3 &&\
2493 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2494 # error We need one of SSLv3 and TLSv1.
2495 #endif
2496 int main(void){
2497 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2499 SSL_CTX_free(ctx);
2500 PEM_read_PrivateKey(0, 0, 0, 0);
2501 return 0;
2504 then
2506 else
2507 feat_bail_required TLS
2509 fi # }}}
2511 if feat_yes TLS; then # {{{
2512 if [ -n "${ossl_v1_1}" ]; then
2513 without_check yes xtls_stack_of 'TLS STACK_OF()' \
2514 '#define HAVE_XTLS_STACK_OF'
2515 elif compile_check xtls_stack_of 'TLS STACK_OF()' \
2516 '#define HAVE_XTLS_STACK_OF' << \!
2517 #include <stdio.h> /* For C89 NULL */
2518 #include <openssl/ssl.h>
2519 #include <openssl/err.h>
2520 #include <openssl/x509v3.h>
2521 #include <openssl/x509.h>
2522 #include <openssl/rand.h>
2523 int main(void){
2524 STACK_OF(GENERAL_NAME) *gens = NULL;
2526 printf("%p", gens); /* to use it */
2527 return 0;
2530 then
2534 if [ -n "${ossl_v1_1}" ]; then
2535 without_check yes xtls_conf 'TLS OpenSSL_modules_load_file(3ssl)' \
2536 '#define HAVE_XTLS_CONFIG'
2537 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+modules-load-file"
2538 elif link_check xtls_conf \
2539 'TLS OpenSSL_modules_load_file(3ssl) support' \
2540 '#define HAVE_XTLS_CONFIG' << \!
2541 #include <stdio.h> /* For C89 NULL */
2542 #include <openssl/conf.h>
2543 int main(void){
2544 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2545 CONF_modules_free();
2546 return 0;
2549 then
2550 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+modules-load-file"
2551 else
2552 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},-modules-load-file"
2555 if [ -n "${ossl_v1_1}" ]; then
2556 without_check yes xtls_conf_ctx 'TLS SSL_CONF_CTX support' \
2557 '#define HAVE_XTLS_CONF_CTX'
2558 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+conf-ctx"
2559 elif link_check xtls_conf_ctx 'TLS SSL_CONF_CTX support' \
2560 '#define HAVE_XTLS_CONF_CTX' << \!
2561 #include <openssl/ssl.h>
2562 #include <openssl/err.h>
2563 int main(void){
2564 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2565 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2567 SSL_CONF_CTX_set_flags(cctx,
2568 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2569 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2570 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2571 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2572 SSL_CONF_CTX_finish(cctx);
2573 SSL_CONF_CTX_free(cctx);
2574 SSL_CTX_free(ctx);
2575 return 0;
2578 then
2579 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+conf-ctx"
2580 else
2581 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},-conf-ctx"
2584 if [ -n "${ossl_v1_1}" ]; then
2585 without_check yes xtls_ctx_config 'TLS SSL_CTX_config(3ssl)' \
2586 '#define HAVE_XTLS_CTX_CONFIG'
2587 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-config"
2588 elif [ -n "${have_xtls_conf}" ] && [ -n "${have_xtls_conf_ctx}" ] &&
2589 link_check xtls_ctx_config 'TLS SSL_CTX_config(3ssl)' \
2590 '#define HAVE_XTLS_CTX_CONFIG' << \!
2591 #include <stdio.h> /* For C89 NULL */
2592 #include <openssl/ssl.h>
2593 int main(void){
2594 SSL_CTX_config(NULL, "SOMEVAL");
2595 return 0;
2598 then
2599 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-config"
2600 else
2601 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},-ctx-config"
2604 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xtls_conf_ctx}" ]; then
2605 without_check yes xtls_set_maxmin_proto \
2606 'TLS SSL_CTX_set_min_proto_version(3ssl)' \
2607 '#define HAVE_XTLS_SET_MIN_PROTO_VERSION'
2608 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-set-maxmin-proto"
2609 elif link_check xtls_set_maxmin_proto \
2610 'TLS SSL_CTX_set_min_proto_version(3ssl)' \
2611 '#define HAVE_XTLS_SET_MIN_PROTO_VERSION' << \!
2612 #include <stdio.h> /* For C89 NULL */
2613 #include <openssl/ssl.h>
2614 int main(void){
2615 SSL_CTX_set_min_proto_version(NULL, 0);
2616 SSL_CTX_set_max_proto_version(NULL, 10);
2617 return 0;
2620 then
2621 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-set-maxmin-proto"
2622 else
2623 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},-ctx-set-maxmin-proto"
2626 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xtls_conf_ctx}" ]; then
2627 without_check yes xtls_set_ciphersuites \
2628 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2629 '#define HAVE_XTLS_SET_CIPHERSUITES'
2630 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-set-ciphersuites"
2631 elif link_check xtls_set_ciphersuites \
2632 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2633 '#define HAVE_XTLS_SET_CIPHERSUITES' << \!
2634 #include <stdio.h> /* For C89 NULL */
2635 #include <openssl/ssl.h>
2636 int main(void){
2637 SSL_CTX_set_ciphersuites(NULL, NULL);
2638 return 0;
2641 then
2642 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},+ctx-set-ciphersuites"
2643 else
2644 VAL_TLS_FEATURES="${VAL_TLS_FEATURES},-ctx-set-ciphersuites"
2646 fi # feat_yes SSL }}}
2648 if feat_yes TLS; then # digest etc algorithms {{{
2649 if feat_yes TLS_ALL_ALGORITHMS; then
2650 if [ -n "${ossl_v1_1}" ]; then
2651 without_check yes tls_all_algo 'TLS all-algorithms support' \
2652 '#define HAVE_TLS_ALL_ALGORITHMS'
2653 elif link_check tls_all_algo 'TLS all-algorithms support' \
2654 '#define HAVE_TLS_ALL_ALGORITHMS' << \!
2655 #include <openssl/evp.h>
2656 int main(void){
2657 OpenSSL_add_all_algorithms();
2658 EVP_get_cipherbyname("two cents i never exist");
2659 EVP_cleanup();
2660 return 0;
2663 then
2665 else
2666 feat_bail_required TLS_ALL_ALGORITHMS
2668 elif [ -n "${ossl_v1_1}" ]; then
2669 without_check yes tls_all_algo \
2670 'TLS all-algorithms (always available in v1.1.0+)' \
2671 '#define HAVE_TLS_ALL_ALGORITHMS'
2674 # Blake
2675 link_check tls_blake2 'TLS: BLAKE2 digests' \
2676 '#define HAVE_XTLS_BLAKE2' << \!
2677 #include <openssl/evp.h>
2678 int main(void){
2679 EVP_blake2b512();
2680 EVP_blake2s256();
2681 return 0;
2685 # SHA-3
2686 link_check tls_sha3 'TLS: SHA-3 digests' '#define HAVE_XTLS_SHA3' << \!
2687 #include <openssl/evp.h>
2688 int main(void){
2689 EVP_sha3_512();
2690 EVP_sha3_384();
2691 EVP_sha3_256();
2692 EVP_sha3_224();
2693 return 0;
2697 if feat_yes MD5 && feat_no NOEXTMD5; then
2698 run_check tls_md5 'TLS: MD5 digest' '#define HAVE_XTLS_MD5' << \!
2699 #include <stdlib.h>
2700 #include <string.h>
2701 #include <openssl/md5.h>
2702 int main(void){
2703 char const dat[] = "abrakadabrafidibus";
2704 char dig[16], hex[16 * 2];
2705 MD5_CTX ctx;
2706 size_t i, j;
2708 memset(dig, 0, sizeof(dig));
2709 memset(hex, 0, sizeof(hex));
2710 MD5_Init(&ctx);
2711 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2712 MD5_Final(dig, &ctx);
2714 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2715 for(i = 0; i < sizeof(hex) / 2; i++){
2716 j = i << 1;
2717 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2718 hex[++j] = hexchar(dig[i] & 0x0f);
2720 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2724 fi # }}}
2726 if feat_yes TLS; then
2727 feat_def TLS_ALL_ALGORITHMS
2728 else
2729 feat_bail_required TLS_ALL_ALGORITHMS
2731 else
2732 feat_is_disabled TLS
2733 feat_is_disabled TLS_ALL_ALGORITHMS
2734 fi # }}} feat_yes TLS
2735 printf '#define VAL_TLS_FEATURES "#'"${VAL_TLS_FEATURES}"'"\n' >> ${h}
2737 if [ "${have_xtls}" = yes ]; then
2738 OPT_SMIME=1
2739 else
2740 OPT_SMIME=0
2742 feat_def SMIME
2744 # VAL_RANDOM {{{
2745 if val_allof VAL_RANDOM \
2746 "arc4,tls,libgetrandom,sysgetrandom,urandom,builtin,error"; then
2748 else
2749 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2750 config_exit 1
2753 val_random_arc4() {
2754 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2755 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2756 #include <stdlib.h>
2757 int main(void){
2758 arc4random();
2759 return 0;
2764 val_random_tls() {
2765 if feat_yes TLS; then
2766 msg ' . VAL_RANDOM: tls ... yes'
2767 echo '#define HAVE_RANDOM n_RANDOM_IMPL_TLS' >> ${h}
2768 return 0
2769 else
2770 msg ' . VAL_RANDOM: tls ... no'
2771 return 1
2775 val_random_libgetrandom() {
2776 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2777 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2778 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2779 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2780 #include <sys/random.h>
2781 int main(void){
2782 char buf[256];
2783 getrandom(buf, sizeof buf, 0);
2784 return 0;
2789 val_random_sysgetrandom() {
2790 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2791 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2792 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2793 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2794 #include <sys/syscall.h>
2795 int main(void){
2796 char buf[256];
2797 syscall(SYS_getrandom, buf, sizeof buf, 0);
2798 return 0;
2803 val_random_urandom() {
2804 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2805 if feat_yes CROSS_BUILD; then
2806 msg 'yes (unchecked)'
2807 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2808 elif [ -f /dev/urandom ]; then
2809 msg yes
2810 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2811 else
2812 msg no
2813 return 1
2815 return 0
2818 val_random_builtin() {
2819 msg_nonl ' . VAL_RANDOM: builtin ... '
2820 if [ -n "${have_no_subsecond_time}" ]; then
2821 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2822 'one of clock_gettime(2) and gettimeofday(2) is required.'
2823 config_exit 1
2824 else
2825 msg yes
2826 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2830 val_random_error() {
2831 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2832 config_exit 42
2835 oifs=${IFS}
2836 IFS=", "
2837 VAL_RANDOM="${VAL_RANDOM},error"
2838 set -- ${VAL_RANDOM}
2839 IFS=${oifs}
2840 for randfun
2842 eval val_random_$randfun && break
2843 done
2844 # }}} VAL_RANDOM
2846 feat_def SMTP
2847 feat_def POP3
2848 feat_def IMAP
2850 if feat_yes GSSAPI; then
2851 ${cat} > ${tmp2}.c << \!
2852 #include <gssapi/gssapi.h>
2853 int main(void){
2854 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2855 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2856 return 0;
2859 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2861 if acmd_set i krb5-config; then
2862 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2863 GSS_INCS="`CFLAGS= ${i} --cflags`"
2864 i='GSS-API via krb5-config(1)'
2865 else
2866 GSS_LIBS='-lgssapi'
2867 GSS_INCS=
2868 i='GSS-API in gssapi/gssapi.h, libgssapi'
2870 if < ${tmp2}.c link_check gss \
2871 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2872 < ${tmp3}.c link_check gss \
2873 'GSS-API in gssapi.h, libgssapi' \
2874 '#define HAVE_GSSAPI
2875 #define GSSAPI_REG_INCLUDE' \
2876 '-lgssapi' ||\
2877 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2878 '#define HAVE_GSSAPI' \
2879 '-lgssapi_krb5' ||\
2880 < ${tmp3}.c link_check gss \
2881 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2882 '#define HAVE_GSSAPI
2883 #define GSS_REG_INCLUDE' \
2884 '-lgssapi -lkrb5 -lcrypto' \
2885 '-I/usr/include/kerberosV' ||\
2886 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2887 '#define HAVE_GSSAPI' \
2888 '-lgss' ||\
2889 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2890 '#define HAVE_GSSAPI
2891 #define GSSAPI_OLD_STYLE' \
2892 '-lgssapi_krb5' << \!
2893 #include <gssapi/gssapi.h>
2894 #include <gssapi/gssapi_generic.h>
2895 int main(void){
2896 gss_import_name(0, 0, gss_nt_service_name, 0);
2897 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2898 return 0;
2901 then
2903 else
2904 feat_bail_required GSSAPI
2906 else
2907 feat_is_disabled GSSAPI
2908 fi # feat_yes GSSAPI
2910 feat_def NETRC
2911 feat_def AGENT
2913 if feat_yes IDNA; then # {{{
2914 if val_allof VAL_IDNA "idnkit,idn2,idn"; then
2916 else
2917 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2918 config_exit 1
2921 val_idna_idn2() {
2922 link_check idna 'OPT_IDNA: GNU Libidn2' \
2923 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2924 #include <idn2.h>
2925 int main(void){
2926 char *idna_utf8, *idna_lc;
2928 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2929 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2930 return 1;
2931 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2932 return 1;
2933 idn2_free(idna_lc);
2934 idn2_free(idna_utf8);
2935 return 0;
2940 val_idna_idn() {
2941 link_check idna 'OPT_IDNA: GNU Libidn' \
2942 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2943 #include <idna.h>
2944 #include <idn-free.h>
2945 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2946 int main(void){
2947 char *utf8, *idna_ascii, *idna_utf8;
2949 utf8 = stringprep_locale_to_utf8("does.this.work");
2950 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2951 != IDNA_SUCCESS)
2952 return 1;
2953 idn_free(idna_ascii);
2954 /* (Rather link check only here) */
2955 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2956 return 0;
2961 val_idna_idnkit() {
2962 link_check idna 'OPT_IDNA: idnkit' \
2963 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2964 #include <stdio.h>
2965 #include <idn/api.h>
2966 #include <idn/result.h>
2967 int main(void){
2968 idn_result_t r;
2969 char ace_name[256];
2970 char local_name[256];
2972 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2973 sizeof(ace_name));
2974 if (r != idn_success) {
2975 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2976 return 1;
2978 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2979 if (r != idn_success) {
2980 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2981 return 1;
2983 return 0;
2988 val_idna_bye() {
2989 feat_bail_required IDNA
2992 oifs=${IFS}
2993 IFS=", "
2994 VAL_IDNA="${VAL_IDNA},bye"
2995 set -- ${VAL_IDNA}
2996 IFS=${oifs}
2997 for randfun
2999 eval val_idna_$randfun && break
3000 done
3001 else
3002 feat_is_disabled IDNA
3003 fi # }}} IDNA
3005 feat_def IMAP_SEARCH
3007 if feat_yes REGEX; then
3008 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
3009 #include <regex.h>
3010 #include <stdlib.h>
3011 int main(void){
3012 size_t xret;
3013 int status;
3014 regex_t re;
3016 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
3017 xret = regerror(status, &re, NULL, 0);
3018 status = regexec(&re, "plan9", 0,NULL, 0);
3019 regfree(&re);
3020 return !(status == REG_NOMATCH);
3023 then
3025 else
3026 feat_bail_required REGEX
3028 else
3029 feat_is_disabled REGEX
3032 if feat_yes MLE; then
3033 if [ -n "${have_c90amend1}" ]; then
3034 have_mle=1
3035 echo '#define HAVE_MLE' >> ${h}
3036 else
3037 feat_bail_required MLE
3039 else
3040 feat_is_disabled MLE
3043 # Generic have-a-line-editor switch for those who need it below
3044 if [ -n "${have_mle}" ]; then
3045 have_cle=1
3048 if feat_yes HISTORY; then
3049 if [ -n "${have_cle}" ]; then
3050 echo '#define HAVE_HISTORY' >> ${h}
3051 else
3052 feat_is_unsupported HISTORY
3054 else
3055 feat_is_disabled HISTORY
3058 if feat_yes KEY_BINDINGS; then
3059 if [ -n "${have_mle}" ]; then
3060 echo '#define HAVE_KEY_BINDINGS' >> ${h}
3061 else
3062 feat_is_unsupported KEY_BINDINGS
3064 else
3065 feat_is_disabled KEY_BINDINGS
3068 if feat_yes TERMCAP; then # {{{
3069 ADDINC=
3070 __termcaplib() {
3071 link_check termcap "termcap(5) (via ${4}${ADDINC})" \
3072 "#define HAVE_TERMCAP${3}" "${1}" "${ADDINC}" << _EOT
3073 #include <stdio.h>
3074 #include <stdlib.h>
3075 ${2}
3076 #include <term.h>
3077 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3078 static int my_putc(int c){return putchar(c);}
3079 int main(void){
3080 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
3081 int r2 = OK, r3 = ERR;
3083 tgetent(buf, getenv("TERM"));
3084 cpb = cmdbuf;
3085 r1 = tgetstr(UNCONST("cm"), &cpb);
3086 tgoto(r1, 1, 1);
3087 r2 = tgetnum(UNCONST("Co"));
3088 r3 = tgetflag(UNCONST("ut"));
3089 tputs("cr", 1, &my_putc);
3090 return (r1 == NULL || r2 == -1 || r3 == 0);
3092 _EOT
3095 __terminfolib() {
3096 link_check terminfo "terminfo(5) (via ${2}${ADDINC})" \
3097 '#define HAVE_TERMCAP
3098 #define HAVE_TERMCAP_CURSES
3099 #define HAVE_TERMINFO' "${1}" "${ADDINC}" << _EOT
3100 #include <stdio.h>
3101 #include <curses.h>
3102 #include <term.h>
3103 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3104 static int my_putc(int c){return putchar(c);}
3105 int main(void){
3106 int er, r0, r1, r2;
3107 char *r3, *tp;
3109 er = OK;
3110 r0 = setupterm(NULL, 1, &er);
3111 r1 = tigetflag(UNCONST("bce"));
3112 r2 = tigetnum(UNCONST("colors"));
3113 r3 = tigetstr(UNCONST("cr"));
3114 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3115 tputs(tp, 1, &my_putc);
3116 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3117 r3 == (char*)-1 || r3 == NULL);
3119 _EOT
3122 if feat_yes TERMCAP_VIA_TERMINFO; then
3123 ADDINC=
3124 do_me() {
3125 xbail=
3126 __terminfolib -ltinfo -ltinfo ||
3127 __terminfolib -lcurses -lcurses ||
3128 __terminfolib -lcursesw -lcursesw ||
3129 xbail=y
3131 do_me
3132 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3133 ADDINC=' -I/usr/local/include/ncurses'
3134 do_me
3136 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3137 ADDINC=' -I/usr/include/ncurses'
3138 do_me
3140 [ -n "${xbail}" ] && feat_bail_required TERMCAP_VIA_TERMINFO
3143 if [ -z "${have_terminfo}" ]; then
3144 ADDINC=
3145 do_me() {
3146 xbail=
3147 __termcaplib -ltermcap '' '' '-ltermcap' ||
3148 __termcaplib -ltermcap '#include <curses.h>' '
3149 #define HAVE_TERMCAP_CURSES' \
3150 'curses.h / -ltermcap' ||
3151 __termcaplib -lcurses '#include <curses.h>' '
3152 #define HAVE_TERMCAP_CURSES' \
3153 'curses.h / -lcurses' ||
3154 __termcaplib -lcursesw '#include <curses.h>' '
3155 #define HAVE_TERMCAP_CURSES' \
3156 'curses.h / -lcursesw' ||
3157 xbail=y
3159 do_me
3160 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3161 ADDINC=' -I/usr/local/include/ncurses'
3162 do_me
3164 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3165 ADDINC=' -I/usr/include/ncurses'
3166 do_me
3168 [ -n "${xbail}" ] && feat_bail_required TERMCAP
3170 if [ -n "${have_termcap}" ]; then
3171 run_check tgetent_null \
3172 "tgetent(3) of termcap(5) takes NULL buffer" \
3173 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3174 #include <stdio.h> /* For C89 NULL */
3175 #include <stdlib.h>
3176 #ifdef HAVE_TERMCAP_CURSES
3177 # include <curses.h>
3178 #endif
3179 #include <term.h>
3180 int main(void){
3181 tgetent(NULL, getenv("TERM"));
3182 return 0;
3184 _EOT
3187 unset ADDINC
3188 else # }}}
3189 feat_is_disabled TERMCAP
3190 feat_is_disabled TERMCAP_VIA_TERMINFO
3193 if feat_def SPAM_SPAMC; then
3194 if acmd_set i spamc; then
3195 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3199 if feat_yes SPAM_SPAMD; then
3200 if [ -n "${have_af_unix}" ]; then
3201 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3202 else
3203 feat_bail_required SPAM_SPAMD
3205 else
3206 feat_is_disabled SPAM_SPAMD
3209 feat_def SPAM_FILTER
3211 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3212 echo '#define HAVE_SPAM' >> ${h}
3213 else
3214 echo '/* HAVE_SPAM */' >> ${h}
3217 if feat_yes QUOTE_FOLD; then
3218 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3219 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3220 else
3221 feat_bail_required QUOTE_FOLD
3223 else
3224 feat_is_disabled QUOTE_FOLD
3227 feat_def FILTER_HTML_TAGSOUP
3228 feat_def COLOUR
3229 feat_def DOTLOCK
3230 feat_def MD5
3232 ## Summarizing
3234 ${rm} -f ${tmp}
3235 squeeze_em ${inc} ${tmp}
3236 ${mv} ${tmp} ${inc}
3237 squeeze_em ${lib} ${tmp}
3238 ${mv} ${tmp} ${lib}
3240 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3241 echo "INCS = `${cat} ${inc}`" >> ${mk}
3242 echo >> ${mk}
3244 # mk-config.h
3245 ${mv} ${h} ${tmp}
3246 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3247 ${cat} ${tmp} >> ${h}
3248 printf '\n' >> ${h}
3249 # Also need these for correct "second stage configuration changed" detection */
3251 if (${CC} --version) >/dev/null 2>&1; then
3252 i=`${CC} --version 2>&1 | ${awk} '
3253 BEGIN{l=""}
3254 {if(length($0)) {if(l) l = l "\\\\n"; l = l "@" $0}}
3255 END{gsub(/"/, "", l); print "\\\\n" l}
3257 elif (${CC} -v) >/dev/null 2>&1; then
3258 i=`${CC} -v 2>&1 | ${awk} '
3259 BEGIN{l=""}
3260 {if(length($0)) {if(l) l = l "\\\\n"; l = l "@" $0}}
3261 END{gsub(/"/, "", l); print "\\\\n" l}
3264 printf '#define VAL_BUILD_CC "%s %s %s%s"\n' \
3265 "${CC}" "${CFLAGS}" "" "${i}" >> ${h}
3266 printf '#define VAL_BUILD_LD "%s %s %s"\n' \
3267 "${CC}" "${LDFLAGS}" "`${cat} ${lib}`" >> ${h}
3268 printf '#define VAL_BUILD_REST "%s"\n' "${COMMLINE}" >> ${h}
3269 printf '\n' >> ${h}
3271 # Throw away all temporaries
3272 ${rm} -rf ${tmp0}.* ${tmp0}*
3274 # Create the string that is used by *features* and `version'.
3275 # Take this nice opportunity and generate a visual listing of included and
3276 # non-included features for the person who runs the configuration
3277 echo 'The following features are included (+) or not (-):' > ${tmp}
3278 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3279 printf '/* The "feature string" */\n' >> ${h}
3280 # Because + is expanded by *folder* if first in "echo $features", put something
3281 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3282 sep=
3283 for opt
3285 sdoc=`option_doc_of ${opt}`
3286 [ -z "${sdoc}" ] && continue
3287 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3288 feat_yes ${opt} && sign=+ || sign=-
3289 printf -- "${sep}${sign}${sopt}" >> ${h}
3290 sep=','
3291 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3292 done
3293 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3294 #exec 5>&1 >>${h}
3295 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3296 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3297 printf '"\n' >> ${h}
3299 # Create the real mk-config.mk
3300 # Note we cannout use explicit ./ filename prefix for source and object
3301 # pathnames because of a bug in bmake(1)
3302 srclist= objlist=
3303 if feat_no AMALGAMATION; then
3304 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3305 i=`basename "${i}" .c`
3306 if [ "${i}" = privsep ]; then
3307 continue
3309 objlist="${objlist} ${i}.o"
3310 srclist="${srclist} \$(SRCDIR)${i}.c"
3311 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3312 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3313 done
3314 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3315 else
3316 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3317 "main.o" "main.c" >> ${mk}
3318 srclist=main.c objlist=main.o
3319 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3321 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3322 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3323 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3324 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3325 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3326 i=`basename "${i}"`
3327 if [ "${i}" = main.c ] ||
3328 [ "${i}" = privsep.c ]; then
3329 continue
3331 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3332 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3333 done
3334 echo >> ${mk}
3336 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3338 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3340 echo >> ${mk}
3341 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3343 ## Finished!
3345 # We have completed the new configuration header. Check whether *really*
3346 # Do the "second stage configuration changed" detection, exit if nothing to do
3347 if [ -f ${oldh} ]; then
3348 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3349 ${mv} -f ${oldh} ${h}
3350 msg 'Effective configuration is up-to-date'
3351 exit 0
3353 config_updated=1
3354 ${rm} -f ${oldh}
3355 msg 'Effective configuration has been updated..'
3358 if [ -n "${config_updated}" ]; then
3359 msg 'Wiping away old objects and such..'
3360 ( cd .obj; oldmk=`${basename} ${oldmk}`; ${MAKE} -f ${oldmk} clean )
3363 msg ''
3364 while read l; do msg "${l}"; done < ${tmp}
3366 msg 'Setup:'
3367 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3368 msg ' . bindir: %s' "${VAL_BINDIR}"
3369 if feat_yes DOTLOCK; then
3370 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3372 msg ' . mandir: %s' "${VAL_MANDIR}"
3373 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3374 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3376 msg ''
3377 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3378 exit 0
3380 msg 'Remarks:'
3381 if [ -z "${have_fnmatch}" ]; then
3382 msg ' . The function fnmatch(3) could not be found.'
3383 msg ' Filename patterns like wildcard are not supported on your system'
3385 if [ -z "${have_fchdir}" ]; then
3386 msg ' . The function fchdir(2) could not be found.'
3387 msg ' We will use chdir(2) instead.'
3388 msg ' This is a problem only if the current working directory is changed'
3389 msg ' while this program is inside of it'
3391 msg ''
3393 # s-it-mode