n_go_input(): add TODO: does not know about shell parsing
[s-mailx.git] / make-config.sh
blobb0491b59a20005c26cba5d01da439dcb8183cd66
1 #!/bin/sh -
2 #@ Please see INSTALL and make.rc instead.
4 LC_ALL=C
5 export LC_ALL
7 # For heaven's sake auto-redirect on SunOS/Solaris
8 if [ "x${SHELL}" = x ] || [ "${SHELL}" = /bin/sh ] && \
9 [ -f /usr/xpg4/bin/sh ] && [ -x /usr/xpg4/bin/sh ]; then
10 SHELL=/usr/xpg4/bin/sh
11 export SHELL
12 exec /usr/xpg4/bin/sh "${0}" "${@}"
14 [ -n "${SHELL}" ] || SHELL=/bin/sh
15 export SHELL
17 # The feature set, to be kept in sync with make.rc
18 # If no documentation given, the option is used as such; if doc is a hyphen,
19 # entry is suppressed when configuration overview is printed, and also in the
20 # *features* string: most likely for obsolete features etc.
21 XOPTIONS="\
22 ICONV='Character set conversion using iconv(3)' \
23 SOCKETS='Network support' \
24 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
25 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
26 SMTP='Simple Mail Transfer Protocol client' \
27 POP3='Post Office Protocol Version 3 client' \
28 IMAP='IMAP v4r1 client' \
29 GSSAPI='Generic Security Service authentication' \
30 NETRC='.netrc file support' \
31 AGENT='-' \
32 MD5='MD5 message digest (APOP, CRAM-MD5)' \
33 IDNA='Internationalized Domain Names for Applications (encode only)' \
34 IMAP_SEARCH='IMAP-style search expressions' \
35 REGEX='Regular expressions' \
36 MLE='Mailx Line Editor' \
37 HISTORY='Line editor history management' \
38 KEY_BINDINGS='Configurable key bindings' \
39 TERMCAP='Terminal capability queries (termcap(5))' \
40 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
41 ERRORS='Log message ring' \
42 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
43 SPAM_SPAMD='-' \
44 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
45 DOCSTRINGS='Command documentation help strings' \
46 UISTRINGS='User interface and error message strings' \
47 QUOTE_FOLD='Extended *quote-fold*ing' \
48 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
49 COLOUR='Coloured message display' \
50 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
53 # Options which are automatically deduced from host environment, i.e., these
54 # need special treatment all around here to warp from/to OPT_ stuff
55 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
56 XOPTIONS_DETECT="\
57 LOCALES='Locale support - printable characters etc. depend on environment' \
58 MULTIBYTE_CHARSETS='Multibyte character sets' \
59 TERMINAL_CHARSET='Automatic detection of terminal character set' \
60 WIDE_GLYPHS='Wide glyph support' \
63 # Rather special options, for custom building, or which always exist.
64 # Mostly for generating the visual overview and the *features* string
65 XOPTIONS_XTRA="\
66 MIME='Multipurpose Internet Mail Extensions' \
67 SMIME='S/MIME message signing, verification, en- and decryption' \
68 CROSS_BUILD='Cross-compilation: trust any detected environment' \
69 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
70 DEVEL='Computers do not blunder' \
73 # To avoid too many recompilations we use a two-stage "configuration changed"
74 # detection, the first uses mk-config.lst, which only goes for actual user
75 # config settings etc. the second uses mk-config.h, which thus includes the
76 # things we have truly detected. This does not work well for multiple choice
77 # values of which only one will be really used, so those user wishes may not be
78 # placed in the header, only the really detected one (but that has to!).
79 # Used for grep(1), for portability assume fixed matching only.
80 H_BLACKLIST='-e VAL_RANDOM -e VAL_IDNA'
82 # The problem is that we don't have any tools we can use right now, so
83 # encapsulate stuff in functions which get called in right order later on
85 option_reset() {
86 set -- ${OPTIONS}
87 for i
89 eval OPT_${i}=0
90 done
93 option_maximal() {
94 set -- ${OPTIONS}
95 for i
97 eval OPT_${i}=1
98 done
99 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
102 option_setup() {
103 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
104 option_parse OPTIONS "${XOPTIONS}"
105 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
106 OPT_MIME=1
108 # Predefined CONFIG= urations take precedence over anything else
109 if [ -n "${CONFIG}" ]; then
110 option_reset
111 case "${CONFIG}" in
112 [nN][uU][lL][lL])
114 [nN][uU][lL][lL][iI])
115 OPT_ICONV=require
116 OPT_UISTRINGS=1
118 [mM][iI][nN][iI][mM][aA][lL])
119 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
120 OPT_COLOUR=1
121 OPT_DOCSTRINGS=1
122 OPT_UISTRINGS=1
123 OPT_ERRORS=1
124 OPT_IDNA=1
125 OPT_MLE=1
126 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
127 OPT_SPAM_FILTER=1
129 [nN][eE][tT][sS][eE][nN][dD])
130 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
131 OPT_SOCKETS=require
132 OPT_SSL=require
133 OPT_SMTP=require
134 OPT_GSSAPI=1 OPT_NETRC=1
135 OPT_AGENT=1
136 OPT_COLOUR=1
137 OPT_DOCSTRINGS=1
138 OPT_UISTRINGS=1
139 OPT_ERRORS=1
140 OPT_IDNA=1
141 OPT_MLE=1
142 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
143 OPT_SPAM_FILTER=1
145 [mM][aA][xX][iI][mM][aA][lL])
146 option_maximal
148 [dD][eE][vV][eE][lL])
149 option_maximal
150 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
152 [oO][dD][eE][vV][eE][lL])
153 option_maximal
154 OPT_DEVEL=1
157 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
158 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
159 exit 1
161 esac
162 msg_nonl "CONFIG=${CONFIG} ... "
166 # Inter-relationships XXX sort this!
167 option_update() {
168 if feat_no SSL; then
169 OPT_SSL_ALL_ALGORITHMS=0
172 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
173 OPT_SOCKETS=0
175 if feat_no SOCKETS; then
176 if feat_require SMTP; then
177 msg 'ERROR: need SOCKETS for required feature SMTP'
178 config_exit 13
180 if feat_require POP3; then
181 msg 'ERROR: need SOCKETS for required feature POP3'
182 config_exit 13
184 if feat_require IMAP; then
185 msg 'ERROR: need SOCKETS for required feature IMAP'
186 config_exit 13
188 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
189 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
190 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
192 if feat_no SMTP && feat_no IMAP; then
193 OPT_GSSAPI=0
196 if feat_no ICONV; then
197 if feat_yes IMAP; then
198 if feat_yes ALWAYS_UNICODE_LOCALE; then
199 msg 'WARN: no ICONV, keeping IMAP due to ALWAYS_UNICODE_LOCALE!'
200 elif feat_require IMAP; then
201 msg 'ERROR: need ICONV for required feature IMAP'
202 config_exit 13
203 else
204 msg 'ERROR: disabling IMAP due to missing ICONV'
205 OPT_IMAP=0
209 if feat_yes IDNA; then
210 if feat_require IDNA; then
211 msg 'ERROR: need ICONV for required feature IDNA'
212 config_exit 13
214 msg 'ERROR: disabling IDNA due to missing ICONV'
215 OPT_IDNA=0
219 if feat_no MLE; then
220 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
223 # If we don't need MD5 leave it alone
224 if feat_no SOCKETS; then
225 OPT_MD5=0
228 if feat_no TERMCAP; then
229 OPT_TERMCAP_VIA_TERMINFO=0
232 if feat_yes DEVEL; then
233 OPT_DEBUG=1
237 rc=./make.rc
238 lst=.obj/mk-config.lst
239 ev=.obj/mk-config.ev
240 h=.obj/mk-config.h h_name=mk-config.h
241 mk=.obj/mk-config.mk
243 newlst=.obj/mk-nconfig.lst
244 newmk=.obj/mk-nconfig.mk
245 oldmk=.obj/mk-oconfig.mk
246 newev=.obj/mk-nconfig.ev
247 newh=.obj/mk-nconfig.h
248 oldh=.obj/mk-oconfig.h
249 tmp0=.obj/___tmp
250 tmp=${tmp0}1$$
251 tmp2=${tmp0}2$$
253 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
255 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
256 # via path_check() later on once possible
258 COMMLINE="${*}"
260 # TODO cc_maxopt is brute simple, we should compile test program and dig real
261 # compiler versions for known compilers, then be more specific
262 [ -n "${cc_maxopt}" ] || cc_maxopt=100
263 #cc_force_no_stackprot=
264 #ld_need_R_flags=
265 #ld_no_bind_now=
266 #ld_rpath_not_runpath=
268 _CFLAGS= _LDFLAGS=
270 os_early_setup() {
271 # We don't "have any utility" (see make.rc)
272 [ -n "${OS}" ] && [ -n "${OSFULLSPEC}" ] ||
273 thecmd_testandset_fail uname uname
275 [ -n "${OS}" ] || OS=`${uname} -s`
276 export OS
278 if [ ${OS} = SunOS ]; then
279 # According to standards(5), this is what we need to do
280 if [ -d /usr/xpg4 ]; then :; else
281 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
282 config_exit 1
284 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
285 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
286 export PATH
290 os_setup() {
291 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
292 msg 'Operating system is %s' "${OS}"
294 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
295 # etc.), it is not baked into the binary
296 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
298 if [ ${OS} = darwin ]; then
299 msg ' . have special Darwin environmental addons...'
300 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
301 elif [ ${OS} = sunos ]; then
302 msg ' . have special SunOS / Solaris "setup" rules ...'
303 _os_setup_sunos
304 elif [ ${OS} = unixware ]; then
305 if feat_yes AUTOCC && acmd_set CC cc; then
306 msg ' . have special UnixWare environmental rules ...'
307 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
309 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
310 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
311 export CC CFLAGS LDFLAGS
312 OPT_AUTOCC=0 ld_need_R_flags=-R
314 elif [ -n "${VERBOSE}" ]; then
315 msg ' . no special treatment for this system necessary or known'
318 # Sledgehammer: better set _GNU_SOURCE
319 # And in general: oh, boy!
320 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
321 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
322 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
323 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
325 # On pkgsrc(7) systems automatically add /usr/pkg/*
326 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
327 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
328 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
329 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
330 ld_rpath_not_runpath=1
334 _os_setup_sunos() {
335 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
336 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
338 # Include packages
339 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
340 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
341 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
342 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
343 ld_no_bind_now=1 ld_rpath_not_runpath=1
345 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
346 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
347 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
348 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
349 ld_no_bind_now=1 ld_rpath_not_runpath=1
352 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
353 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
355 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
356 if [ -x "${cksum}" ]; then :; else
357 msg 'ERROR: Not an executable program: %s' "${cksum}"
358 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
359 msg 'ERROR: However, we do so only for tests.'
360 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
361 config_exit 1
364 if feat_yes AUTOCC; then
365 if acmd_set CC cc; then
366 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
368 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
369 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
370 export CC CFLAGS LDFLAGS
371 OPT_AUTOCC=0 ld_need_R_flags=-R
372 else
373 cc_maxopt=2 cc_force_no_stackprot=1
378 # Check out compiler ($CC) and -flags ($CFLAGS)
379 cc_setup() {
380 # Even though it belongs into cc_flags we will try to compile and link
381 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
382 # EXTRA_CFLAGS/EXTRA_LDFLAGS
383 if feat_no AUTOCC; then
384 _cc_default
385 # Ensure those don't do any harm
386 EXTRA_CFLAGS= EXTRA_LDFLAGS=
387 export EXTRA_CFLAGS EXTRA_LDFLAGS
388 return
389 else
390 CFLAGS= LDFLAGS=
391 export CFLAGS LDFLAGS
394 [ -n "${CC}" ] && { _cc_default; return; }
396 msg_nonl 'Searching for a usable C compiler .. $CC='
397 if acmd_set CC clang || acmd_set CC gcc ||
398 acmd_set CC tcc || acmd_set CC pcc ||
399 acmd_set CC c89 || acmd_set CC c99; then
401 else
402 msg 'boing booom tschak'
403 msg 'ERROR: I cannot find a compiler!'
404 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
405 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
406 config_exit 1
408 msg '%s' "${CC}"
409 export CC
412 _cc_default() {
413 if [ -z "${CC}" ]; then
414 msg 'To go on like you have chosen, please set $CC, rerun.'
415 config_exit 1
418 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
420 else
421 msg 'Using C compiler ${CC}=%s' "${CC}"
425 cc_flags() {
426 if feat_yes AUTOCC; then
427 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
428 cc_check_silent=1
429 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
430 "${CC}"
431 else
432 cc_check_silent=
433 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
436 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
437 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
438 msg ' . have special tcc(1) environmental rules ...'
439 _cc_flags_tcc
440 else
441 # As of pcc CVS 2016-04-02, stack protection support is announced but
442 # will break if used on Linux
443 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
444 cc_force_no_stackprot=1
446 _cc_flags_generic
449 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
450 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
451 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
452 else
453 if feat_no DEBUG; then
454 CFLAGS="-DNDEBUG ${CFLAGS}"
457 export CFLAGS LDFLAGS
460 _cc_flags_tcc() {
461 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
462 _CFLAGS= _LDFLAGS=
464 cc_check -W
465 cc_check -Wall
466 cc_check -Wextra
467 cc_check -pedantic
469 if feat_yes DEBUG; then
470 # May have problems to find libtcc cc_check -b
471 cc_check -g
474 if ld_check -Wl,-rpath =./ no; then
475 ld_need_R_flags=-Wl,-rpath=
476 if [ -z "${ld_rpath_not_runpath}" ]; then
477 ld_check -Wl,--enable-new-dtags
478 else
479 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
481 ld_runtime_flags # update!
484 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
485 unset __cflags __ldflags
488 _cc_flags_generic() {
489 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
490 _CFLAGS= _LDFLAGS=
491 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
493 # E.g., valgrind does not work well with high optimization
494 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
495 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
496 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
497 cc_maxopt=1
499 # Check -g first since some others may rely upon -g / optim. level
500 if feat_yes DEBUG; then
501 cc_check -O
502 cc_check -g
503 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
505 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
507 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
509 else
510 cc_check -O
513 if feat_yes AMALGAMATION; then
514 cc_check -pipe
517 #if feat_yes DEVEL && cc_check -Weverything; then
519 #else
520 cc_check -W
521 cc_check -Wall
522 cc_check -Wextra
523 cc_check -Wbad-function-cast
524 cc_check -Wcast-align
525 cc_check -Wcast-qual
526 cc_check -Winit-self
527 cc_check -Wmissing-prototypes
528 cc_check -Wshadow
529 cc_check -Wunused
530 cc_check -Wwrite-strings
531 cc_check -Wno-long-long
533 cc_check -pedantic
535 if feat_yes AMALGAMATION && feat_no DEVEL; then
536 cc_check -Wno-unused-function
538 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
540 cc_check -fno-unwind-tables
541 cc_check -fno-asynchronous-unwind-tables
542 cc_check -fstrict-aliasing
543 if cc_check -fstrict-overflow && feat_yes DEVEL; then
544 cc_check -Wstrict-overflow=5
547 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
548 if [ -z "${cc_force_no_stackprot}" ]; then
549 if cc_check -fstack-protector-strong ||
550 cc_check -fstack-protector-all; then
551 cc_check -D_FORTIFY_SOURCE=2
553 else
554 msg ' ! Not checking for -fstack-protector compiler option,'
555 msg ' ! since that caused errors in a "similar" configuration.'
556 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
560 # LD (+ dependend CC)
562 if feat_yes ASAN_ADDRESS; then
563 _ccfg=${_CFLAGS}
564 if cc_check -fsanitize=address && ld_check -fsanitize=address; then
566 else
567 feat_bail_required ASAN_ADDRESS
568 _CFLAGS=${_ccfg}
572 if feat_yes ASAN_MEMORY; then
573 _ccfg=${_CFLAGS}
574 if cc_check -fsanitize=memory && ld_check -fsanitize=memory &&
575 cc_check -fsanitize-memory-track-origins=2 &&
576 ld_check -fsanitize-memory-track-origins=2; then
578 else
579 feat_bail_required ASAN_MEMORY
580 _CFLAGS=${_ccfg}
584 if feat_yes USAN; then
585 _ccfg=${_CFLAGS}
586 if cc_check -fsanitize=undefined && ld_check -fsanitize=undefined; then
588 else
589 feat_bail_required USAN
590 _CFLAGS=${_ccfg}
594 ld_check -Wl,-z,relro
595 if [ -z "${ld_no_bind_now}" ]; then
596 ld_check -Wl,-z,now
597 else
598 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
600 ld_check -Wl,-z,noexecstack
601 ld_check -Wl,--as-needed
602 if ld_check -Wl,-rpath =./ no; then
603 ld_need_R_flags=-Wl,-rpath=
604 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
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!
611 elif ld_check -Wl,-R ./ no; then
612 ld_need_R_flags=-Wl,-R
613 if [ -z "${ld_rpath_not_runpath}" ]; then
614 ld_check -Wl,--enable-new-dtags
615 else
616 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
618 ld_runtime_flags # update!
621 # Address randomization
622 _ccfg=${_CFLAGS}
623 if cc_check -fPIE || cc_check -fpie; then
624 ld_check -pie || _CFLAGS=${_ccfg}
626 unset _ccfg
628 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
629 unset __cflags __ldflags
632 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
634 ## Notes:
635 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
636 ## redirection, so use "printf '' >" instead
638 ## Very first: we undergo several states regarding I/O redirection etc.,
639 ## but need to deal with option updates from within all. Since all the
640 ## option stuff should be above the scissor line, define utility functions
641 ## and redefine them as necessary.
642 ## And, since we have those functions, simply use them for whatever
644 t1=ten10one1ten10one1
645 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
646 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
647 ) > /dev/null 2>&1; then
648 good_shell=1
649 else
650 unset good_shell
652 unset t1
654 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
656 config_exit() {
657 exit ${1}
660 # which(1) not standardized, command(1) -v may return non-executable: unroll!
661 acmd_test() { __acmd "${1}" 1 0 0; }
662 acmd_test_fail() { __acmd "${1}" 1 1 0; }
663 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
664 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
665 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
666 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
667 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
668 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
669 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
670 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
671 __acmd() {
672 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
674 if [ "${dotest}" -ne 0 ]; then
675 eval dotest=\$${varname}
676 if [ -n "${dotest}" ]; then
677 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
678 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
679 return 0
683 oifs=${IFS} IFS=:
684 [ -n "${noglob_shell}" ] && set -o noglob
685 set -- ${PATH}
686 [ -n "${noglob_shell}" ] && set +o noglob
687 IFS=${oifs}
688 for path
690 if [ -z "${path}" ] || [ "${path}" = . ]; then
691 if [ -d "${PWD}" ]; then
692 path=${PWD}
693 else
694 path=.
697 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
698 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
699 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
700 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
701 return 0
703 done
705 # We may have no builtin string functions, we yet have no programs we can
706 # use, try to access once from the root, assuming it is an absolute path if
707 # that finds the executable
708 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
709 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
710 msg ' . ${%s} ... %s' "${pname}" "${pname}"
711 [ -n "${varname}" ] && eval ${varname}="${pname}"
712 return 0
715 [ ${dofail} -eq 0 ] && return 1
716 msg 'ERROR: no trace of utility '"${pname}"
717 exit 1
720 msg() {
721 fmt=${1}
722 shift
723 printf >&2 -- "${fmt}\\n" "${@}"
726 msg_nonl() {
727 fmt=${1}
728 shift
729 printf >&2 -- "${fmt}" "${@}"
732 # Our feature check environment
733 feat_val_no() {
734 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
735 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
738 feat_val_yes() {
739 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
740 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
741 [ "x${1}" = xrequire ]
744 feat_val_require() {
745 [ "x${1}" = xrequire ]
748 _feat_check() {
749 eval i=\$OPT_${1}
750 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
751 if feat_val_no "${i}"; then
752 return 1
753 elif feat_val_yes "${i}"; then
754 return 0
755 else
756 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
757 "${1}" "${i}"
758 config_exit 11
762 feat_yes() {
763 _feat_check ${1}
766 feat_no() {
767 _feat_check ${1} && return 1
768 return 0
771 feat_require() {
772 eval i=\$OPT_${1}
773 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
774 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
777 feat_bail_required() {
778 if feat_require ${1}; then
779 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
780 config_exit 13
782 feat_is_unsupported "${1}"
785 feat_is_disabled() {
786 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
787 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
790 feat_is_unsupported() {
791 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
792 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
793 eval OPT_${1}=0
794 option_update # XXX this is rather useless here (dependency chain..)
797 feat_def() {
798 if feat_yes ${1}; then
799 msg ' . %s ... yes' "${1}"
800 echo '#define HAVE_'${1}'' >> ${h}
801 return 0
802 else
803 feat_is_disabled "${@}"
804 return 1
808 option_parse() {
809 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
810 # options, without documentation, to $1
811 j=\'
812 i="`${awk} -v input=\"${2}\" '
813 BEGIN{
814 for(i = 0;;){
815 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
816 if(voff == 0)
817 break
818 v = substr(input, voff, RLENGTH)
819 input = substr(input, voff + RLENGTH)
820 doff = index(v, "=")
821 if(doff > 0){
822 d = substr(v, doff + 2, length(v) - doff - 1)
823 v = substr(v, 1, doff - 1)
825 print v
829 eval ${1}=\"${i}\"
832 option_doc_of() {
833 # Return the "documentation string" for option $1, itself if none such
834 j=\'
835 ${awk} -v want="${1}" \
836 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
837 BEGIN{
838 for(;;){
839 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
840 if(voff == 0)
841 break
842 v = substr(input, voff, RLENGTH)
843 input = substr(input, voff + RLENGTH)
844 doff = index(v, "=")
845 if(doff > 0){
846 d = substr(v, doff + 2, length(v) - doff - 1)
847 v = substr(v, 1, doff - 1)
848 }else
849 d = v
850 if(v == want){
851 if(d != "-")
852 print d
853 exit
860 option_join_rc() {
861 # Join the values from make.rc into what currently is defined, not
862 # overwriting yet existing settings
863 ${rm} -f ${tmp}
864 # We want read(1) to perform reverse solidus escaping in order to be able to
865 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
866 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
867 < ${rc} ${awk} 'BEGIN{line = ""}{
868 gsub(/^[[:space:]]+/, "", $0)
869 gsub(/[[:space:]]+$/, "", $0)
870 if(gsub(/\\$/, "", $0)){
871 line = line $0
872 next
873 }else
874 line = line $0
875 if(index(line, "#") == 1){
876 line = ""
877 }else if(length(line)){
878 print line
879 line = ""
881 }' |
882 while read line; do
883 if [ -n "${good_shell}" ]; then
884 i=${line%%=*}
885 else
886 i=`${awk} -v LINE="${line}" 'BEGIN{
887 gsub(/=.*$/, "", LINE)
888 print LINE
891 if [ "${i}" = "${line}" ]; then
892 msg 'ERROR: invalid syntax in: %s' "${line}"
893 continue
896 eval j="\$${i}" jx="\${${i}+x}"
897 if [ -n "${j}" ] || [ "${jx}" = x ]; then
898 : # Yet present
899 else
900 j=`${awk} -v LINE="${line}" 'BEGIN{
901 gsub(/^[^=]*=/, "", LINE)
902 gsub(/^\"*/, "", LINE)
903 gsub(/\"*$/, "", LINE)
904 print LINE
907 [ "${i}" = "DESTDIR" ] && continue
908 echo "${i}=\"${j}\""
909 done > ${tmp}
910 # Reread the mixed version right now
911 . ./${tmp}
914 option_evaluate() {
915 # Expand the option values, which may contain shell snippets
916 ${rm} -f ${newlst} ${newmk} ${newh}
917 exec 5<&0 6>&1 <${tmp} >${newlst}
918 while read line; do
920 if [ -n "${good_shell}" ]; then
921 i=${line%%=*}
922 [ "${i}" != "${i#OPT_}" ] && z=1
923 else
924 i=`${awk} -v LINE="${line}" 'BEGIN{
925 gsub(/=.*$/, "", LINE);\
926 print LINE
928 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
933 eval j=\$${i}
934 if [ -n "${z}" ]; then
935 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
936 if [ -z "${j}" ] || feat_val_no "${j}"; then
938 printf " /* #undef ${i} */\n" >> ${newh}
939 elif feat_val_yes "${j}"; then
940 if feat_val_require "${j}"; then
941 j=require
942 else
945 printf " /* #define ${i} */\n" >> ${newh}
946 else
947 msg 'ERROR: cannot parse <%s>' "${line}"
948 config_exit 1
950 elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
952 else
953 printf "#define ${i} \"${j}\"\n" >> ${newh}
955 printf "${i} = ${j}\n" >> ${newmk}
956 printf "${i}=${j}\n"
957 eval "${i}=\"${j}\""
958 done
959 exec 0<&5 1>&6 5<&- 6<&-
962 val_allof() {
963 eval __expo__=\$${1}
964 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
965 BEGIN{
966 i = split(HEAP, ha, /[, ]/)
967 if((j = split(USER, ua, /[, ]/)) == 0)
968 exit
969 for(; j != 0; --j){
970 us = tolower(ua[j])
971 if(us == "all" || us == "any")
972 continue
973 ok = 0
974 for(ii = i; ii != 0; --ii)
975 if(tolower(ha[ii]) == us){
976 ok = 1
977 break
979 if(!ok)
980 exit 1
984 __rv__=${?}
985 [ ${__rv__} -ne 0 ] && return ${__rv__}
987 if ${awk} -v USER="${__expo__}" '
988 BEGIN{
989 if((j = split(USER, ua, /[, ]/)) == 0)
990 exit
991 for(; j != 0; --j){
992 us = tolower(ua[j])
993 if(us == "all" || us == "any")
994 exit 0
996 exit 1
998 '; then
999 eval "${1}"=\"${2}\"
1000 else
1001 # Enfore lowercase also in otherwise unchanged user value..
1002 eval "${1}"=\""`echo ${__expo__} | ${tr} '[A-Z]_' '[a-z]-'`"\"
1004 return 0
1007 path_check() {
1008 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
1009 varname=${1} addflag=${2} flagvarname=${3}
1010 j=${IFS}
1011 IFS=:
1012 [ -n "${noglob_shell}" ] && set -o noglob
1013 eval "set -- \$${1}"
1014 [ -n "${noglob_shell}" ] && set +o noglob
1015 IFS=${j}
1016 j= k= y= z=
1017 for i
1019 [ -z "${i}" ] && continue
1020 [ -d "${i}" ] || continue
1021 if [ -n "${j}" ]; then
1022 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1024 else
1025 y="${y} :${i}:"
1026 j="${j}:${i}"
1027 # But do not link any fakeroot path into our binaries!
1028 if [ -n "${addflag}" ]; then
1029 case "${i}" in *fakeroot*) continue;; esac
1030 k="${k} ${addflag}${i}"
1033 else
1034 y=" :${i}:"
1035 j="${i}"
1036 # But do not link any fakeroot path into our binaries!
1037 if [ -n "${addflag}" ]; then
1038 case "${i}" in *fakeroot*) continue;; esac
1039 k="${k} ${addflag}${i}"
1042 done
1043 eval "${varname}=\"${j}\""
1044 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1045 unset varname
1048 ld_runtime_flags() {
1049 if [ -n "${ld_need_R_flags}" ]; then
1050 i=${IFS}
1051 IFS=:
1052 set -- ${LD_LIBRARY_PATH}
1053 IFS=${i}
1054 for i
1056 # But do not link any fakeroot path into our binaries!
1057 case "${i}" in *fakeroot*) continue;; esac
1058 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1059 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1060 done
1061 export LDFLAGS
1063 # Disable it for a possible second run.
1064 ld_need_R_flags=
1067 cc_check() {
1068 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1069 if ${CC} ${INCS} \
1070 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1071 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1072 _CFLAGS="${_CFLAGS} ${1}"
1073 [ -n "${cc_check_silent}" ] || msg 'yes'
1074 return 0
1076 [ -n "${cc_check_silent}" ] || msg 'no'
1077 return 1
1080 ld_check() {
1081 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1082 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1083 if ${CC} ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1084 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1085 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1086 [ -n "${cc_check_silent}" ] || msg 'yes'
1087 return 0
1089 [ -n "${cc_check_silent}" ] || msg 'no'
1090 return 1
1093 dump_test_program=1
1094 _check_preface() {
1095 variable=$1 topic=$2 define=$3
1097 echo '**********'
1098 msg_nonl ' . %s ... ' "${topic}"
1099 #echo "/* checked ${topic} */" >> ${h}
1100 ${rm} -f ${tmp} ${tmp}.o
1101 if [ "${dump_test_program}" = 1 ]; then
1102 echo '*** test program is'
1103 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1104 else
1105 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1107 #echo '*** the preprocessor generates'
1108 #${make} -f ${makefile} ${tmp}.x
1109 #${cat} ${tmp}.x
1110 echo '*** tests results'
1113 without_check() {
1114 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1116 echo '**********'
1117 msg_nonl ' . %s ... ' "${topic}"
1119 echo '*** enforced unchecked results are'
1120 if feat_val_yes ${yesno}; then
1121 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1122 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1123 LIBS="${LIBS} ${libs}"
1124 echo "${libs}" >> ${lib}
1125 INCS="${INCS} ${incs}"
1126 echo "${incs}" >> ${inc}
1128 msg 'yes (deduced)'
1129 echo "${define}" >> ${h}
1130 eval have_${variable}=yes
1131 return 0
1132 else
1133 #echo "/* ${define} */" >> ${h}
1134 msg 'no (deduced)'
1135 eval unset have_${variable}
1136 return 1
1140 compile_check() {
1141 variable=$1 topic=$2 define=$3
1143 _check_preface "${variable}" "${topic}" "${define}"
1145 if ${make} -f ${makefile} XINCS="${INCS}" \
1146 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ${tmp}.o &&
1147 [ -f ${tmp}.o ]; then
1148 msg 'yes'
1149 echo "${define}" >> ${h}
1150 eval have_${variable}=yes
1151 return 0
1152 else
1153 #echo "/* ${define} */" >> ${h}
1154 msg 'no'
1155 eval unset have_${variable}
1156 return 1
1160 _link_mayrun() {
1161 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1163 _check_preface "${variable}" "${topic}" "${define}"
1165 if feat_yes CROSS_BUILD; then
1166 if [ ${run} = 1 ]; then
1167 run=0
1171 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1172 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1173 XLIBS="${LIBS} ${libs}" ${tmp} &&
1174 [ -f ${tmp} ] && { [ ${run} -eq 0 ] || ${tmp}; }; then
1175 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1176 msg 'yes'
1177 echo "${define}" >> ${h}
1178 LIBS="${LIBS} ${libs}"
1179 echo "${libs}" >> ${lib}
1180 INCS="${INCS} ${incs}"
1181 echo "${incs}" >> ${inc}
1182 eval have_${variable}=yes
1183 return 0
1184 else
1185 msg 'no'
1186 #echo "/* ${define} */" >> ${h}
1187 eval unset have_${variable}
1188 return 1
1192 link_check() {
1193 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1196 run_check() {
1197 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1200 xrun_check() {
1201 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1204 squeeze_em() {
1205 < "${1}" > "${2}" ${awk} \
1206 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1209 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1211 # First of all, create new configuration and check whether it changed
1213 if [ -d .obj ] || mkdir .obj; then :; else
1214 msg 'ERROR: cannot create .obj build directory'
1215 exit 1
1218 # Very easy checks for the operating system in order to be able to adjust paths
1219 # or similar very basic things which we need to be able to go at all
1220 os_early_setup
1222 # Check those tools right now that we need before including $rc
1223 msg 'Checking for basic utility set'
1224 thecmd_testandset_fail awk awk
1225 thecmd_testandset_fail rm rm
1226 thecmd_testandset_fail tr tr
1228 # Initialize the option set
1229 msg_nonl 'Setting up configuration options ... '
1230 option_setup
1231 msg 'done'
1233 # Include $rc, but only take from it what wasn't overwritten by the user from
1234 # within the command line or from a chosen fixed CONFIG=
1235 # Note we leave alone the values
1236 trap "exit 1" HUP INT TERM
1237 trap "${rm} -f ${tmp}" EXIT
1239 msg_nonl 'Joining in %s ... ' ${rc}
1240 option_join_rc
1241 msg 'done'
1243 # We need to know about that now, in order to provide utility overwrites etc.
1244 os_setup
1246 msg 'Checking for remaining set of utilities'
1247 thecmd_testandset_fail grep grep
1249 # Before we step ahead with the other utilities perform a path cleanup first.
1250 path_check PATH
1252 # awk(1) above
1253 thecmd_testandset_fail basename basename
1254 thecmd_testandset_fail cat cat
1255 thecmd_testandset_fail chmod chmod
1256 thecmd_testandset_fail cp cp
1257 thecmd_testandset_fail cmp cmp
1258 # grep(1) above
1259 thecmd_testandset_fail mkdir mkdir
1260 thecmd_testandset_fail mv mv
1261 # pwd(1) is needed - either for make-emerge.sh, or for ourselves
1262 [ -n "${CWDDIR}" ] || thecmd_testandset_fail pwd pwd
1263 # rm(1) above
1264 thecmd_testandset_fail sed sed
1265 thecmd_testandset_fail sort sort
1266 thecmd_testandset_fail tee tee
1267 __PATH=${PATH}
1268 thecmd_testandset chown chown ||
1269 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1270 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1271 PATH=${__PATH}
1272 thecmd_testandset_fail MAKE make
1273 make=${MAKE}
1274 export MAKE
1275 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1277 # For ./cc-test.sh only
1278 thecmd_testandset_fail cksum cksum
1280 # Now that we have pwd(1), set our build paths unless make-emerge.sh has been
1281 # used; it would have created a makefile with the full paths, then
1282 [ -n "${CWDDIR}" ] || CWDDIR=`${pwd}`/
1283 [ -n "${SRCDIR}" ] || SRCDIR=${CWDDIR}
1285 # Update OPT_ options now, in order to get possible inter-dependencies right
1286 option_update
1288 # (No functions since some shells loose non-exported variables in traps)
1289 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1290 trap "trap \"\" HUP INT TERM EXIT;\
1291 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1292 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1294 # Our configuration options may at this point still contain shell snippets,
1295 # we need to evaluate them in order to get them expanded, and we need those
1296 # evaluated values not only in our new configuration file, but also at hand..
1297 msg_nonl 'Evaluating all configuration items ... '
1298 option_evaluate
1299 msg 'done'
1302 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1303 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1305 # The problem now is that the test should be able to run in the users linker
1306 # and path environment, so we need to place the test: rule first, before
1307 # injecting the relevant make variables. Set up necessary environment
1308 if [ -z "${VERBOSE}" ]; then
1309 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1310 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1311 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1312 printf -- "ECHO_TEST = @\n" >> ${newmk}
1313 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1314 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1315 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1317 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only %s\n' \
1318 "${SHELL}" "${SRCDIR}" "./${VAL_SID}${VAL_MAILX}" >> ${newmk}
1320 # Add the known utility and some other variables
1321 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1322 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1323 if feat_yes DOTLOCK; then
1324 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1325 else
1326 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1329 for i in \
1330 CWDDIR SRCDIR \
1331 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1332 MAKE MAKEFLAGS make SHELL strip \
1333 cksum; do
1334 eval j=\$${i}
1335 printf -- "${i} = ${j}\n" >> ${newmk}
1336 printf -- "${i}=${j}\n" >> ${newlst}
1337 printf -- "${i}=\"${j}\";export ${i}; " >> ${newev}
1338 done
1339 # Note that makefile reads and eval'uates one line of this file, whereas other
1340 # consumers source it via .(1)
1341 printf "\n" >> ${newev}
1343 # Build a basic set of INCS and LIBS according to user environment.
1344 C_INCLUDE_PATH="${CWDDIR}:${CWDDIR}.obj:${SRCDIR}:${C_INCLUDE_PATH}"
1345 path_check C_INCLUDE_PATH -I _INCS
1346 INCS="${INCS} ${_INCS}"
1347 path_check LD_LIBRARY_PATH -L _LIBS
1348 LIBS="${LIBS} ${_LIBS}"
1349 unset _INCS _LIBS
1350 export C_INCLUDE_PATH LD_LIBRARY_PATH
1352 # Some environments need runtime path flags to be able to go at all
1353 ld_runtime_flags
1355 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1357 cc_setup
1359 ${cat} > ${tmp}.c << \!
1360 #include <stdio.h>
1361 #include <string.h>
1362 static void doit(char const *s);
1364 main(int argc, char **argv){
1365 (void)argc;
1366 (void)argv;
1367 doit("Hello world");
1368 return 0;
1370 static void
1371 doit(char const *s){
1372 char buf[12];
1373 memcpy(buf, s, strlen(s) +1);
1374 puts(s);
1378 if ${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1379 -o ${tmp2} ${tmp}.c ${LIBS}; then
1381 else
1382 msg 'ERROR: i cannot compile a "Hello world" via'
1383 msg ' %s' \
1384 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1385 msg 'ERROR: Please read INSTALL, rerun'
1386 config_exit 1
1389 # This may also update ld_runtime_flags() (again)
1390 cc_flags
1392 for i in \
1393 COMMLINE \
1394 INCS LIBS \
1395 ; do
1396 eval j="\$${i}"
1397 printf -- "${i}=${j}\n" >> ${newlst}
1398 done
1399 for i in \
1400 CC \
1401 CFLAGS \
1402 LDFLAGS \
1403 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1404 OSFULLSPEC \
1405 ; do
1406 eval j=\$${i}
1407 if [ -n "${j}" ]; then
1408 printf -- "${i} = ${j}\n" >> ${newmk}
1409 printf -- "${i}=${j}\n" >> ${newlst}
1411 done
1413 # Now finally check whether we already have a configuration and if so, whether
1414 # all those parameters are still the same.. or something has actually changed
1415 config_updated=
1416 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1417 echo 'Configuration is up-to-date'
1418 exit 0
1419 elif [ -f ${lst} ]; then
1420 config_updated=1
1421 echo 'Configuration has been updated..'
1422 else
1423 echo 'Shiny configuration..'
1426 # Time to redefine helper 1
1427 config_exit() {
1428 ${rm} -f ${lst} ${h} ${mk}
1429 exit ${1}
1432 ${mv} -f ${newlst} ${lst}
1433 ${mv} -f ${newev} ${ev}
1434 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1435 ${mv} -f ${newh} ${h}
1436 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1437 ${mv} -f ${newmk} ${mk}
1439 ## Compile and link checking
1441 tmp3=${tmp0}3$$
1442 log=.obj/mk-config.log
1443 lib=.obj/mk-config.lib
1444 inc=.obj/mk-config.inc
1445 makefile=${tmp0}.mk
1447 # (No function since some shells loose non-exported variables in traps)
1448 trap "trap \"\" HUP INT TERM;\
1449 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1450 HUP INT TERM
1451 trap "trap \"\" HUP INT TERM EXIT;\
1452 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1454 # Time to redefine helper 2
1455 msg() {
1456 fmt=${1}
1457 shift
1458 printf "*** ${fmt}\\n" "${@}"
1459 printf -- "${fmt}\\n" "${@}" >&5
1461 msg_nonl() {
1462 fmt=${1}
1463 shift
1464 printf "*** ${fmt}\\n" "${@}"
1465 printf -- "${fmt}" "${@}" >&5
1468 # !!
1469 exec 5>&2 > ${log} 2>&1
1471 echo "${LIBS}" > ${lib}
1472 echo "${INCS}" > ${inc}
1473 ${cat} > ${makefile} << \!
1474 .SUFFIXES: .o .c .x .y
1475 .c.o:
1476 $(CC) -I./ $(XINCS) $(CFLAGS) -o $(@) -c $(<)
1477 .c.x:
1478 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1480 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1483 ## Generics
1485 # May be multiline..
1486 echo >> ${h}
1487 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1488 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1490 # Generate n_err_number OS mappings
1491 dump_test_program=0
1493 feat_yes DEVEL && NV= || NV=noverbose
1494 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1495 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1496 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1497 dump_test_program=1
1499 feat_def ALWAYS_UNICODE_LOCALE
1500 feat_def AMALGAMATION 0
1501 feat_def CROSS_BUILD
1502 feat_def DOCSTRINGS
1503 feat_def UISTRINGS
1504 feat_def ERRORS
1506 feat_def ASAN_ADDRESS 0
1507 feat_def ASAN_MEMORY 0
1508 feat_def DEBUG 0
1509 feat_def DEVEL 0
1510 feat_def NYD2 0
1511 feat_def NOMEMDBG 0
1513 if xrun_check inline 'inline functions' \
1514 '#define HAVE_INLINE
1515 #define n_INLINE static inline' << \!
1516 static inline int ilf(int i){return ++i;}
1517 int main(void){return ilf(-1);}
1519 then
1521 elif xrun_check inline 'inline functions (via __inline)' \
1522 '#define HAVE_INLINE
1523 #define n_INLINE static __inline' << \!
1524 static __inline int ilf(int i){return ++i;}
1525 int main(void){return ilf(-1);}
1527 then
1531 ## Test for "basic" system-calls / functionality that is used by all parts
1532 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1533 ## macros to be used by only the subprograms (potentially).
1535 if run_check clock_gettime 'clock_gettime(2)' \
1536 '#define HAVE_CLOCK_GETTIME' << \!
1537 #include <time.h>
1538 # include <errno.h>
1539 int main(void){
1540 struct timespec ts;
1542 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1543 return 0;
1544 return 1;
1547 then
1549 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1550 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1551 #include <time.h>
1552 # include <errno.h>
1553 int main(void){
1554 struct timespec ts;
1556 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1557 return 0;
1558 return 1;
1561 then
1563 elif run_check gettimeofday 'gettimeofday(2)' \
1564 '#define HAVE_GETTIMEOFDAY' << \!
1565 #include <stdio.h> /* For C89 NULL */
1566 #include <sys/time.h>
1567 # include <errno.h>
1568 int main(void){
1569 struct timeval tv;
1571 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1572 return 0;
1573 return 1;
1576 then
1578 else
1579 have_no_subsecond_time=1
1582 if run_check nanosleep 'nanosleep(2)' \
1583 '#define HAVE_NANOSLEEP' << \!
1584 #include <time.h>
1585 # include <errno.h>
1586 int main(void){
1587 struct timespec ts;
1589 ts.tv_sec = 1;
1590 ts.tv_nsec = 100000;
1591 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1592 return 0;
1593 return 1;
1596 then
1598 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1599 '#define HAVE_NANOSLEEP' '-lrt' << \!
1600 #include <time.h>
1601 # include <errno.h>
1602 int main(void){
1603 struct timespec ts;
1605 ts.tv_sec = 1;
1606 ts.tv_nsec = 100000;
1607 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1608 return 0;
1609 return 1;
1612 then
1614 # link_check is enough for this, that function is so old, trust the proto
1615 elif link_check sleep 'sleep(3)' \
1616 '#define HAVE_SLEEP' << \!
1617 #include <unistd.h>
1618 # include <errno.h>
1619 int main(void){
1620 if(!sleep(1) || errno != ENOSYS)
1621 return 0;
1622 return 1;
1625 then
1627 else
1628 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1629 config_exit 1
1632 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1633 #include <pwd.h>
1634 #include <unistd.h>
1635 # include <errno.h>
1636 int main(void){
1637 struct passwd *pw;
1638 gid_t gid;
1639 uid_t uid;
1641 if((gid = getgid()) != 0)
1642 gid = getegid();
1643 if((uid = getuid()) != 0)
1644 uid = geteuid();
1645 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1646 return 1;
1647 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1648 return 1;
1649 return 0;
1652 then
1654 else
1655 msg 'ERROR: we require user and group info / database searches.'
1656 msg 'That much Unix we indulge ourselfs.'
1657 config_exit 1
1660 if link_check ftruncate 'ftruncate(2)' \
1661 '#define HAVE_FTRUNCATE' << \!
1662 #include <unistd.h>
1663 #include <sys/types.h>
1664 int main(void){
1665 return (ftruncate(0, 0) != 0);
1668 then
1670 else
1671 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1672 msg 'ERROR: we require the ftruncate(2) system call.'
1673 config_exit 1
1676 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1677 #include <signal.h>
1678 # include <errno.h>
1679 int main(void){
1680 struct sigaction nact, oact;
1682 nact.sa_handler = SIG_DFL;
1683 sigemptyset(&nact.sa_mask);
1684 nact.sa_flags = SA_RESTART;
1685 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1688 then
1690 else
1691 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1692 config_exit 1
1695 if link_check snprintf 'snprintf(3)' << \!
1696 #include <stdio.h>
1697 int main(void){
1698 char b[20];
1700 snprintf(b, sizeof b, "%s", "string");
1701 return 0;
1704 then
1706 else
1707 msg 'ERROR: we require the snprintf(3) function.'
1708 config_exit 1
1711 if link_check environ 'environ(3)' << \!
1712 #include <stdio.h> /* For C89 NULL */
1713 int main(void){
1714 extern char **environ;
1716 return environ[0] == NULL;
1719 then
1721 else
1722 msg 'ERROR: we require the environ(3) array for subprocess control.'
1723 config_exit 1
1726 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1727 #include <stdlib.h>
1728 int main(void){
1729 setenv("s-mailx", "i want to see it cute!", 1);
1730 unsetenv("s-mailx");
1731 return 0;
1734 then
1736 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1737 #include <stdlib.h>
1738 int main(void){
1739 putenv("s-mailx=i want to see it cute!");
1740 return 0;
1743 then
1745 else
1746 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1747 config_exit 1
1750 if link_check termios 'termios.h and tc*(3) family' << \!
1751 #include <termios.h>
1752 int main(void){
1753 struct termios tios;
1755 tcgetattr(0, &tios);
1756 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1757 return 0;
1760 then
1762 else
1763 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1764 msg 'That much Unix we indulge ourselfs.'
1765 config_exit 1
1768 ## optional stuff
1770 if link_check vsnprintf 'vsnprintf(3)' << \!
1771 #include <stdarg.h>
1772 #include <stdio.h>
1773 static void dome(char *buf, size_t blen, ...){
1774 va_list ap;
1776 va_start(ap, blen);
1777 vsnprintf(buf, blen, "%s", ap);
1778 va_end(ap);
1780 int main(void){
1781 char b[20];
1783 dome(b, sizeof b, "string");
1784 return 0;
1787 then
1789 else
1790 feat_bail_required ERRORS
1793 if [ "${have_vsnprintf}" = yes ]; then
1794 __va_copy() {
1795 link_check va_copy "va_copy(3) (as ${2})" \
1796 "#define HAVE_N_VA_COPY
1797 #define n_va_copy ${2}" <<_EOT
1798 #include <stdarg.h>
1799 #include <stdio.h>
1800 #if ${1}
1801 # if defined __va_copy && !defined va_copy
1802 # define va_copy __va_copy
1803 # endif
1804 #endif
1805 static void dome2(char *buf, size_t blen, va_list src){
1806 va_list ap;
1808 va_copy(ap, src);
1809 vsnprintf(buf, blen, "%s", ap);
1810 va_end(ap);
1812 static void dome(char *buf, size_t blen, ...){
1813 va_list ap;
1815 va_start(ap, blen);
1816 dome2(buf, blen, ap);
1817 va_end(ap);
1819 int main(void){
1820 char b[20];
1822 dome(b, sizeof b, "string");
1823 return 0;
1825 _EOT
1827 __va_copy 0 va_copy || __va_copy 1 __va_copy
1830 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1831 #include <unistd.h>
1832 #include <errno.h>
1833 int main(void){
1834 int rv = 0;
1836 errno = 0;
1837 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1838 errno = 0;
1839 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1841 /* Only link check */
1842 fpathconf(0, _PC_NAME_MAX);
1844 return rv;
1848 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1849 #include <fcntl.h>
1850 #include <unistd.h>
1851 # include <errno.h>
1852 int main(void){
1853 int fds[2];
1855 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1856 return 0;
1857 return 1;
1861 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1862 #include <termios.h>
1863 int main(void){
1864 struct winsize ws;
1866 tcgetwinsize(0, &ws);
1867 return 0;
1871 # We use this only then for now (need NOW+1)
1872 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1873 #include <fcntl.h> /* For AT_* */
1874 #include <sys/stat.h>
1875 # include <errno.h>
1876 int main(void){
1877 struct timespec ts[2];
1879 ts[0].tv_nsec = UTIME_NOW;
1880 ts[1].tv_nsec = UTIME_OMIT;
1881 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1882 return 0;
1883 return 1;
1889 # The random check has been moved to below SSL detection due to multiple choice
1890 # selection for PRG sources
1892 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1893 #include <stdio.h>
1894 int main(void){
1895 putc_unlocked('@', stdout);
1896 return 0;
1900 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1901 #include <unistd.h>
1902 int main(void){
1903 fchdir(0);
1904 return 0;
1908 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1909 #include <stdlib.h>
1910 int main(void){
1911 char x_buf[4096], *x = realpath(".", x_buf);
1913 return (x != NULL) ? 0 : 1;
1916 then
1917 if run_check realpath_malloc 'realpath(3) takes NULL' \
1918 '#define HAVE_REALPATH_NULL' << \!
1919 #include <stdlib.h>
1920 int main(void){
1921 char *x = realpath(".", NULL);
1923 if(x != NULL)
1924 free(x);
1925 return (x != NULL) ? 0 : 1;
1928 then
1934 ## optional and selectable
1937 if feat_yes DOTLOCK; then
1938 if run_check readlink 'readlink(2)' << \!
1939 #include <unistd.h>
1940 # include <errno.h>
1941 int main(void){
1942 char buf[128];
1944 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1945 return 0;
1946 return 1;
1949 then
1951 else
1952 feat_bail_required DOTLOCK
1956 if feat_yes DOTLOCK; then
1957 if run_check fchown 'fchown(2)' << \!
1958 #include <unistd.h>
1959 # include <errno.h>
1960 int main(void){
1961 if(!fchown(0, 0, 0) || errno != ENOSYS)
1962 return 0;
1963 return 1;
1966 then
1968 else
1969 feat_bail_required DOTLOCK
1973 if feat_yes DOTLOCK; then
1974 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1975 '#define HAVE_PRCTL_DUMPABLE' << \!
1976 #include <sys/prctl.h>
1977 # include <errno.h>
1978 int main(void){
1979 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1980 return 0;
1981 return 1;
1984 then
1986 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1987 '#define HAVE_PTRACE_DENY' << \!
1988 #include <sys/ptrace.h>
1989 # include <errno.h>
1990 int main(void){
1991 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1992 return 0;
1993 return 1;
1996 then
1998 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
1999 '#define HAVE_SETPFLAGS_PROTECT' << \!
2000 #include <priv.h>
2001 # include <errno.h>
2002 int main(void){
2003 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
2004 return 0;
2005 return 1;
2008 then
2013 ## Now it is the time to fork away the BASE_ series
2015 ${rm} -f ${tmp}
2016 squeeze_em ${inc} ${tmp}
2017 ${mv} ${tmp} ${inc}
2018 squeeze_em ${lib} ${tmp}
2019 ${mv} ${tmp} ${lib}
2021 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2022 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2024 ## The remains are expected to be used only by the main MUA binary!
2026 OPT_LOCALES=0
2027 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2028 #include <locale.h>
2029 int main(void){
2030 setlocale(LC_ALL, "");
2031 return 0;
2034 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2036 OPT_MULTIBYTE_CHARSETS=0
2037 OPT_WIDE_GLYPHS=0
2038 OPT_TERMINAL_CHARSET=0
2039 if [ -n "${have_setlocale}" ]; then
2040 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2041 '#define HAVE_C90AMEND1' << \!
2042 #include <limits.h>
2043 #include <stdlib.h>
2044 #include <wchar.h>
2045 #include <wctype.h>
2046 int main(void){
2047 char mbb[MB_LEN_MAX + 1];
2048 wchar_t wc;
2050 iswprint(L'c');
2051 towupper(L'c');
2052 mbtowc(&wc, "x", 1);
2053 mbrtowc(&wc, "x", 1, NULL);
2054 wctomb(mbb, wc);
2055 return (mblen("\0", 1) == 0);
2058 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2060 if [ -n "${have_c90amend1}" ]; then
2061 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2062 #include <wchar.h>
2063 int main(void){
2064 wcwidth(L'c');
2065 return 0;
2068 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2071 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2072 #include <langinfo.h>
2073 #include <stdlib.h>
2074 int main(void){
2075 nl_langinfo(DAY_1);
2076 return (nl_langinfo(CODESET) == NULL);
2079 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2080 fi # have_setlocale
2082 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2083 #include <fnmatch.h>
2084 int main(void){
2085 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2089 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2090 #include <dirent.h>
2091 int main(void){
2092 struct dirent de;
2093 return !(de.d_type == DT_UNKNOWN ||
2094 de.d_type == DT_DIR || de.d_type == DT_LNK);
2098 ## optional and selectable
2100 if feat_yes ICONV; then
2101 # To be able to create tests we need to figure out which replacement
2102 # sequence the iconv(3) implementation creates
2103 ${cat} > ${tmp2}.c << \!
2104 #include <stdio.h> /* For C89 NULL */
2105 #include <string.h>
2106 #include <iconv.h>
2107 int main(void){
2108 char inb[16], oub[16], *inbp, *oubp;
2109 iconv_t id;
2110 size_t inl, oul;
2112 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2113 inl = sizeof("\342\200\223") -1;
2114 oul = sizeof oub;
2115 oubp = oub;
2117 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2118 return 1;
2119 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2120 return 1;
2121 iconv_close(id);
2123 *oubp = '\0';
2124 oul = (size_t)(oubp - oub);
2125 if(oul == 0)
2126 return 1;
2127 /* Character-wise replacement? */
2128 if(oul == 1){
2129 if(oub[0] == '?')
2130 return 2;
2131 if(oub[0] == '*')
2132 return 3;
2133 return 1;
2135 /* Byte-wise replacement? */
2136 if(oul == sizeof("\342\200\223") -1){
2137 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2138 return 12;
2139 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2140 return 13;
2141 return 1;
2143 return 0;
2146 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2147 '#define HAVE_ICONV' ||
2148 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2149 '#define HAVE_ICONV' '-liconv' ||
2150 feat_bail_required ICONV
2152 if feat_no CROSS_BUILD; then
2153 { ${tmp}; } >/dev/null 2>&1
2154 case ${?} in
2155 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2156 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2157 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2158 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2159 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2160 esac
2162 else
2163 feat_is_disabled ICONV
2164 fi # feat_yes ICONV
2166 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2167 ${cat} > ${tmp2}.c << \!
2168 #include <sys/types.h>
2169 #include <sys/socket.h>
2170 #include <sys/un.h>
2171 # include <errno.h>
2172 int main(void){
2173 struct sockaddr_un soun;
2175 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2176 return 1;
2177 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2178 return 1;
2179 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2180 return 1;
2181 return 0;
2185 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2186 '#define HAVE_UNIX_SOCKETS' ||
2187 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2188 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2189 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2190 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2193 if feat_yes SOCKETS; then
2194 ${cat} > ${tmp2}.c << \!
2195 #include <sys/types.h>
2196 #include <sys/socket.h>
2197 #include <netinet/in.h>
2198 # include <errno.h>
2199 int main(void){
2200 struct sockaddr s;
2202 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2203 return 1;
2204 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2205 return 1;
2206 return 0;
2210 < ${tmp2}.c run_check sockets 'sockets' \
2211 '#define HAVE_SOCKETS' ||
2212 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2213 '#define HAVE_SOCKETS' '-lnsl' ||
2214 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2215 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2216 feat_bail_required SOCKETS
2217 else
2218 feat_is_disabled SOCKETS
2219 fi # feat_yes SOCKETS
2221 feat_yes SOCKETS &&
2222 link_check sockopt '[gs]etsockopt(2)' '#define HAVE_SOCKOPT' << \!
2223 #include <sys/socket.h>
2224 #include <stdlib.h>
2225 # include <errno.h>
2226 int main(void){
2227 socklen_t sol;
2228 int sockfd = 3, soe;
2230 sol = sizeof soe;
2231 if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &soe, &sol) == -1 &&
2232 errno == ENOSYS)
2233 return 1;
2234 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2235 errno == ENOSYS)
2236 return 1;
2237 return 0;
2241 feat_yes SOCKETS &&
2242 link_check nonblocksock 'non-blocking sockets' \
2243 '#define HAVE_NONBLOCKSOCK' << \!
2244 #include <sys/types.h>
2245 #include <sys/select.h>
2246 #include <sys/socket.h>
2247 #include <sys/time.h>
2248 #include <arpa/inet.h>
2249 #include <netinet/in.h>
2250 #include <fcntl.h>
2251 #include <stdlib.h>
2252 #include <unistd.h>
2253 # include <errno.h>
2254 int main(void){
2255 fd_set fdset;
2256 struct timeval tv;
2257 struct sockaddr_in sin;
2258 socklen_t sol;
2259 int sofd, soe;
2261 if((sofd = socket(AF_INET, SOCK_STREAM, 0)) == -1 && errno == ENOSYS)
2262 return 1;
2263 if(fcntl(sofd, F_SETFL, O_NONBLOCK) != 0)
2264 return 1;
2266 sin.sin_family = AF_INET;
2267 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
2268 sin.sin_port = htons(80);
2269 if(connect(sofd, &sin, sizeof sin) == -1 && errno == ENOSYS)
2270 return 1;
2272 FD_ZERO(&fdset);
2273 FD_SET(sofd, &fdset);
2274 tv.tv_sec = 10;
2275 tv.tv_usec = 0;
2276 if((soe = select(sofd + 1, NULL, &fdset, NULL, &tv)) == 1){
2277 sol = sizeof soe;
2278 getsockopt(sofd, SOL_SOCKET, SO_ERROR, &soe, &sol);
2279 if(soe == 0)
2280 return 0;
2281 }else if(soe == -1 && errno == ENOSYS)
2282 return 1;
2284 close(sofd);
2285 return 0;
2289 if feat_yes SOCKETS; then
2290 link_check getaddrinfo 'getaddrinfo(3)' \
2291 '#define HAVE_GETADDRINFO' << \!
2292 #include <sys/types.h>
2293 #include <sys/socket.h>
2294 #include <stdio.h>
2295 #include <netdb.h>
2296 int main(void){
2297 struct addrinfo a, *ap;
2298 int lrv;
2300 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2301 case EAI_NONAME:
2302 case EAI_SERVICE:
2303 default:
2304 fprintf(stderr, "%s\n", gai_strerror(lrv));
2305 case 0:
2306 break;
2308 return 0;
2313 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2314 compile_check arpa_inet_h '<arpa/inet.h>' \
2315 '#define HAVE_ARPA_INET_H' << \!
2316 #include <sys/types.h>
2317 #include <sys/socket.h>
2318 #include <netdb.h>
2319 #include <netinet/in.h>
2320 #include <arpa/inet.h>
2323 ${cat} > ${tmp2}.c << \!
2324 #include <sys/types.h>
2325 #include <sys/socket.h>
2326 #include <stdio.h>
2327 #include <string.h>
2328 #include <netdb.h>
2329 #include <netinet/in.h>
2330 #ifdef HAVE_ARPA_INET_H
2331 #include <arpa/inet.h>
2332 #endif
2333 int main(void){
2334 struct sockaddr_in servaddr;
2335 unsigned short portno;
2336 struct servent *ep;
2337 struct hostent *hp;
2338 struct in_addr **pptr;
2340 portno = 0;
2341 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2342 portno = (unsigned short)ep->s_port;
2344 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2345 pptr = (struct in_addr**)hp->h_addr_list;
2346 if(hp->h_addrtype != AF_INET)
2347 fprintf(stderr, "au\n");
2348 }else{
2349 switch(h_errno){
2350 case HOST_NOT_FOUND:
2351 case TRY_AGAIN:
2352 case NO_RECOVERY:
2353 case NO_DATA:
2354 break;
2355 default:
2356 fprintf(stderr, "au\n");
2357 break;
2361 memset(&servaddr, 0, sizeof servaddr);
2362 servaddr.sin_family = AF_INET;
2363 servaddr.sin_port = htons(portno);
2364 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2365 fprintf(stderr, "Would connect to %s:%d ...\n",
2366 inet_ntoa(**pptr), (int)portno);
2367 return 0;
2371 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2372 < ${tmp2}.c link_check gethostbyname \
2373 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2374 < ${tmp2}.c link_check gethostbyname \
2375 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2376 '' '-lsocket -lnsl' ||
2377 feat_bail_required SOCKETS
2380 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2381 link_check so_xtimeo 'SO_{RCV,SND}TIMEO' '#define HAVE_SO_XTIMEO' << \!
2382 #include <sys/socket.h>
2383 #include <stdlib.h>
2384 int main(void){
2385 struct timeval tv;
2386 int sockfd = 3;
2388 tv.tv_sec = 42;
2389 tv.tv_usec = 21;
2390 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2391 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2392 return 0;
2396 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2397 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2398 #include <sys/socket.h>
2399 #include <stdlib.h>
2400 int main(void){
2401 struct linger li;
2402 int sockfd = 3;
2404 li.l_onoff = 1;
2405 li.l_linger = 42;
2406 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2407 return 0;
2411 VAL_SSL_FEATURES=
2412 if feat_yes SSL; then # {{{
2413 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2414 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2415 # time: we need to test it first in order to get things right
2416 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2417 '#define HAVE_SSL
2418 #define HAVE_XSSL
2419 #define HAVE_XSSL_RESSL
2420 #define HAVE_XSSL_OPENSSL 0' << \!
2421 #include <openssl/opensslv.h>
2422 #ifdef LIBRESSL_VERSION_NUMBER
2423 #else
2424 # error nope
2425 #endif
2427 then
2428 ossl_v1_1=
2429 VAL_SSL_FEATURES=libressl
2430 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2431 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2432 '#define HAVE_SSL
2433 #define HAVE_XSSL
2434 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2435 #include <openssl/opensslv.h>
2436 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2437 #else
2438 # error nope
2439 #endif
2441 then
2442 ossl_v1_1=1
2443 VAL_SSL_FEATURES=libssl-0x10100
2444 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2445 '#define HAVE_SSL
2446 #define HAVE_XSSL
2447 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2448 #include <openssl/opensslv.h>
2449 #ifdef OPENSSL_VERSION_NUMBER
2450 #else
2451 # error nope
2452 #endif
2454 then
2455 ossl_v1_1=
2456 VAL_SSL_FEATURES=libssl-0x10000
2457 else
2458 feat_bail_required SSL
2459 fi # }}}
2461 if feat_yes SSL; then # {{{
2462 if [ -n "${ossl_v1_1}" ]; then
2463 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2464 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2465 '-lssl -lcrypto'
2466 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2467 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2468 '-lssl -lcrypto' << \!
2469 #include <openssl/ssl.h>
2470 #include <openssl/err.h>
2471 #include <openssl/x509v3.h>
2472 #include <openssl/x509.h>
2473 #include <openssl/rand.h>
2474 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2475 # error We need TLSv1.
2476 #endif
2477 int main(void){
2478 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2480 SSL_CTX_free(ctx);
2481 PEM_read_PrivateKey(0, 0, 0, 0);
2482 return 0;
2485 then
2487 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2488 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2489 '-lssl -lcrypto' << \!
2490 #include <openssl/ssl.h>
2491 #include <openssl/err.h>
2492 #include <openssl/x509v3.h>
2493 #include <openssl/x509.h>
2494 #include <openssl/rand.h>
2495 #if defined OPENSSL_NO_SSL3 &&\
2496 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2497 # error We need one of SSLv3 and TLSv1.
2498 #endif
2499 int main(void){
2500 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2502 SSL_CTX_free(ctx);
2503 PEM_read_PrivateKey(0, 0, 0, 0);
2504 return 0;
2507 then
2509 else
2510 feat_bail_required SSL
2512 fi # }}}
2514 if feat_yes SSL; then # {{{
2515 if feat_yes SSL_ALL_ALGORITHMS; then
2516 if [ -n "${ossl_v1_1}" ]; then
2517 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2518 '#define HAVE_SSL_ALL_ALGORITHMS'
2519 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2520 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2521 #include <openssl/evp.h>
2522 int main(void){
2523 OpenSSL_add_all_algorithms();
2524 EVP_get_cipherbyname("two cents i never exist");
2525 EVP_cleanup();
2526 return 0;
2529 then
2531 else
2532 feat_bail_required SSL_ALL_ALGORITHMS
2534 elif [ -n "${ossl_v1_1}" ]; then
2535 without_check yes ssl_all_algo \
2536 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2537 '#define HAVE_SSL_ALL_ALGORITHMS'
2540 if [ -n "${ossl_v1_1}" ]; then
2541 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2542 '#define HAVE_XSSL_STACK_OF'
2543 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2544 '#define HAVE_XSSL_STACK_OF' << \!
2545 #include <stdio.h> /* For C89 NULL */
2546 #include <openssl/ssl.h>
2547 #include <openssl/err.h>
2548 #include <openssl/x509v3.h>
2549 #include <openssl/x509.h>
2550 #include <openssl/rand.h>
2551 int main(void){
2552 STACK_OF(GENERAL_NAME) *gens = NULL;
2554 printf("%p", gens); /* to use it */
2555 return 0;
2558 then
2562 if [ -n "${ossl_v1_1}" ]; then
2563 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2564 '#define HAVE_XSSL_CONFIG'
2565 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2566 elif link_check xssl_conf \
2567 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2568 '#define HAVE_XSSL_CONFIG' << \!
2569 #include <stdio.h> /* For C89 NULL */
2570 #include <openssl/conf.h>
2571 int main(void){
2572 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2573 CONF_modules_free();
2574 return 0;
2577 then
2578 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2579 else
2580 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2583 if [ -n "${ossl_v1_1}" ]; then
2584 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2585 '#define HAVE_XSSL_CONF_CTX'
2586 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2587 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2588 '#define HAVE_XSSL_CONF_CTX' << \!
2589 #include <openssl/ssl.h>
2590 #include <openssl/err.h>
2591 int main(void){
2592 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2593 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2595 SSL_CONF_CTX_set_flags(cctx,
2596 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2597 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2598 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2599 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2600 SSL_CONF_CTX_finish(cctx);
2601 SSL_CONF_CTX_free(cctx);
2602 SSL_CTX_free(ctx);
2603 return 0;
2606 then
2607 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2608 else
2609 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2612 if [ -n "${ossl_v1_1}" ]; then
2613 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2614 '#define HAVE_XSSL_CTX_CONFIG'
2615 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2616 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2617 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2618 '#define HAVE_XSSL_CTX_CONFIG' << \!
2619 #include <stdio.h> /* For C89 NULL */
2620 #include <openssl/ssl.h>
2621 int main(void){
2622 SSL_CTX_config(NULL, "SOMEVAL");
2623 return 0;
2626 then
2627 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2628 else
2629 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2632 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2633 without_check yes xssl_set_maxmin_proto \
2634 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2635 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2636 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2637 elif link_check xssl_set_maxmin_proto \
2638 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2639 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2640 #include <stdio.h> /* For C89 NULL */
2641 #include <openssl/ssl.h>
2642 int main(void){
2643 SSL_CTX_set_min_proto_version(NULL, 0);
2644 SSL_CTX_set_max_proto_version(NULL, 10);
2645 return 0;
2648 then
2649 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2650 else
2651 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2654 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2655 without_check yes xssl_set_ciphersuites \
2656 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2657 '#define HAVE_XSSL_SET_CIPHERSUITES'
2658 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-ciphersuites"
2659 elif link_check xssl_set_ciphersuites \
2660 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2661 '#define HAVE_XSSL_SET_CIPHERSUITES' << \!
2662 #include <stdio.h> /* For C89 NULL */
2663 #include <openssl/ssl.h>
2664 int main(void){
2665 SSL_CTX_set_ciphersuites(NULL, NULL);
2666 return 0;
2669 then
2670 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-ciphersuites"
2671 else
2672 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-ciphersuites"
2675 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2676 '#define HAVE_XSSL_RAND_EGD' << \!
2677 #include <openssl/rand.h>
2678 int main(void){
2679 return RAND_egd("some.where") > 0;
2682 then
2683 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2684 else
2685 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2687 fi # feat_yes SSL }}}
2689 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2690 run_check ssl_md5 'MD5 digest in the used crypto library' \
2691 '#define HAVE_XSSL_MD5' << \!
2692 #include <stdlib.h>
2693 #include <string.h>
2694 #include <openssl/md5.h>
2695 int main(void){
2696 char const dat[] = "abrakadabrafidibus";
2697 char dig[16], hex[16 * 2];
2698 MD5_CTX ctx;
2699 size_t i, j;
2701 memset(dig, 0, sizeof(dig));
2702 memset(hex, 0, sizeof(hex));
2703 MD5_Init(&ctx);
2704 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2705 MD5_Final(dig, &ctx);
2707 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2708 for(i = 0; i < sizeof(hex) / 2; i++){
2709 j = i << 1;
2710 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2711 hex[++j] = hexchar(dig[i] & 0x0f);
2713 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2716 fi # }}}
2718 if feat_yes SSL; then
2719 feat_def SSL_ALL_ALGORITHMS
2720 else
2721 feat_bail_required SSL_ALL_ALGORITHMS
2723 else
2724 feat_is_disabled SSL
2725 feat_is_disabled SSL_ALL_ALGORITHMS
2726 fi # }}} feat_yes SSL
2727 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2729 if [ "${have_xssl}" = yes ]; then
2730 OPT_SMIME=1
2731 else
2732 OPT_SMIME=0
2734 feat_def SMIME
2736 # VAL_RANDOM {{{
2737 if val_allof VAL_RANDOM \
2738 "arc4,ssl,libgetrandom,sysgetrandom,urandom,builtin,error"; then
2740 else
2741 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2742 config_exit 1
2745 val_random_arc4() {
2746 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2747 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2748 #include <stdlib.h>
2749 int main(void){
2750 arc4random();
2751 return 0;
2756 val_random_ssl() {
2757 if feat_yes SSL; then
2758 msg ' . VAL_RANDOM: ssl ... yes'
2759 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2760 return 0
2761 else
2762 msg ' . VAL_RANDOM: ssl ... no'
2763 return 1
2767 val_random_libgetrandom() {
2768 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2769 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2770 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2771 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2772 #include <sys/random.h>
2773 int main(void){
2774 char buf[256];
2775 getrandom(buf, sizeof buf, 0);
2776 return 0;
2781 val_random_sysgetrandom() {
2782 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2783 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2784 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2785 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2786 #include <sys/syscall.h>
2787 int main(void){
2788 char buf[256];
2789 syscall(SYS_getrandom, buf, sizeof buf, 0);
2790 return 0;
2795 val_random_urandom() {
2796 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2797 if feat_yes CROSS_BUILD; then
2798 msg 'yes (unchecked)'
2799 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2800 elif [ -f /dev/urandom ]; then
2801 msg yes
2802 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2803 else
2804 msg no
2805 return 1
2807 return 0
2810 val_random_builtin() {
2811 msg_nonl ' . VAL_RANDOM: builtin ... '
2812 if [ -n "${have_no_subsecond_time}" ]; then
2813 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2814 'one of clock_gettime(2) and gettimeofday(2) is required.'
2815 config_exit 1
2816 else
2817 msg yes
2818 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2822 val_random_error() {
2823 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2824 config_exit 42
2827 oifs=${IFS}
2828 IFS=", "
2829 VAL_RANDOM="${VAL_RANDOM},error"
2830 set -- ${VAL_RANDOM}
2831 IFS=${oifs}
2832 for randfun
2834 eval val_random_$randfun && break
2835 done
2836 # }}} VAL_RANDOM
2838 feat_def SMTP
2839 feat_def POP3
2840 feat_def IMAP
2842 if feat_yes GSSAPI; then
2843 ${cat} > ${tmp2}.c << \!
2844 #include <gssapi/gssapi.h>
2845 int main(void){
2846 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2847 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2848 return 0;
2851 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2853 if acmd_set i krb5-config; then
2854 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2855 GSS_INCS="`CFLAGS= ${i} --cflags`"
2856 i='GSS-API via krb5-config(1)'
2857 else
2858 GSS_LIBS='-lgssapi'
2859 GSS_INCS=
2860 i='GSS-API in gssapi/gssapi.h, libgssapi'
2862 if < ${tmp2}.c link_check gss \
2863 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2864 < ${tmp3}.c link_check gss \
2865 'GSS-API in gssapi.h, libgssapi' \
2866 '#define HAVE_GSSAPI
2867 #define GSSAPI_REG_INCLUDE' \
2868 '-lgssapi' ||\
2869 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2870 '#define HAVE_GSSAPI' \
2871 '-lgssapi_krb5' ||\
2872 < ${tmp3}.c link_check gss \
2873 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2874 '#define HAVE_GSSAPI
2875 #define GSS_REG_INCLUDE' \
2876 '-lgssapi -lkrb5 -lcrypto' \
2877 '-I/usr/include/kerberosV' ||\
2878 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2879 '#define HAVE_GSSAPI' \
2880 '-lgss' ||\
2881 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2882 '#define HAVE_GSSAPI
2883 #define GSSAPI_OLD_STYLE' \
2884 '-lgssapi_krb5' << \!
2885 #include <gssapi/gssapi.h>
2886 #include <gssapi/gssapi_generic.h>
2887 int main(void){
2888 gss_import_name(0, 0, gss_nt_service_name, 0);
2889 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2890 return 0;
2893 then
2895 else
2896 feat_bail_required GSSAPI
2898 else
2899 feat_is_disabled GSSAPI
2900 fi # feat_yes GSSAPI
2902 feat_def NETRC
2903 feat_def AGENT
2905 if feat_yes IDNA; then # {{{
2906 if val_allof VAL_IDNA "idnkit,idn2,idn"; then
2908 else
2909 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2910 config_exit 1
2913 val_idna_idn2() {
2914 link_check idna 'OPT_IDNA: GNU Libidn2' \
2915 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2916 #include <idn2.h>
2917 int main(void){
2918 char *idna_utf8, *idna_lc;
2920 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2921 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2922 return 1;
2923 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2924 return 1;
2925 idn2_free(idna_lc);
2926 idn2_free(idna_utf8);
2927 return 0;
2932 val_idna_idn() {
2933 link_check idna 'OPT_IDNA: GNU Libidn' \
2934 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2935 #include <idna.h>
2936 #include <idn-free.h>
2937 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2938 int main(void){
2939 char *utf8, *idna_ascii, *idna_utf8;
2941 utf8 = stringprep_locale_to_utf8("does.this.work");
2942 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2943 != IDNA_SUCCESS)
2944 return 1;
2945 idn_free(idna_ascii);
2946 /* (Rather link check only here) */
2947 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2948 return 0;
2953 val_idna_idnkit() {
2954 link_check idna 'OPT_IDNA: idnkit' \
2955 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2956 #include <stdio.h>
2957 #include <idn/api.h>
2958 #include <idn/result.h>
2959 int main(void){
2960 idn_result_t r;
2961 char ace_name[256];
2962 char local_name[256];
2964 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2965 sizeof(ace_name));
2966 if (r != idn_success) {
2967 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2968 return 1;
2970 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2971 if (r != idn_success) {
2972 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2973 return 1;
2975 return 0;
2980 val_idna_bye() {
2981 feat_bail_required IDNA
2984 oifs=${IFS}
2985 IFS=", "
2986 VAL_IDNA="${VAL_IDNA},bye"
2987 set -- ${VAL_IDNA}
2988 IFS=${oifs}
2989 for randfun
2991 eval val_idna_$randfun && break
2992 done
2993 else
2994 feat_is_disabled IDNA
2995 fi # }}} IDNA
2997 feat_def IMAP_SEARCH
2999 if feat_yes REGEX; then
3000 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
3001 #include <regex.h>
3002 #include <stdlib.h>
3003 int main(void){
3004 size_t xret;
3005 int status;
3006 regex_t re;
3008 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
3009 xret = regerror(status, &re, NULL, 0);
3010 status = regexec(&re, "plan9", 0,NULL, 0);
3011 regfree(&re);
3012 return !(status == REG_NOMATCH);
3015 then
3017 else
3018 feat_bail_required REGEX
3020 else
3021 feat_is_disabled REGEX
3024 if feat_yes MLE; then
3025 if [ -n "${have_c90amend1}" ]; then
3026 have_mle=1
3027 echo '#define HAVE_MLE' >> ${h}
3028 else
3029 feat_bail_required MLE
3031 else
3032 feat_is_disabled MLE
3035 # Generic have-a-line-editor switch for those who need it below
3036 if [ -n "${have_mle}" ]; then
3037 have_cle=1
3040 if feat_yes HISTORY; then
3041 if [ -n "${have_cle}" ]; then
3042 echo '#define HAVE_HISTORY' >> ${h}
3043 else
3044 feat_is_unsupported HISTORY
3046 else
3047 feat_is_disabled HISTORY
3050 if feat_yes KEY_BINDINGS; then
3051 if [ -n "${have_mle}" ]; then
3052 echo '#define HAVE_KEY_BINDINGS' >> ${h}
3053 else
3054 feat_is_unsupported KEY_BINDINGS
3056 else
3057 feat_is_disabled KEY_BINDINGS
3060 if feat_yes TERMCAP; then # {{{
3061 ADDINC=
3062 __termcaplib() {
3063 link_check termcap "termcap(5) (via ${4}${ADDINC})" \
3064 "#define HAVE_TERMCAP${3}" "${1}" "${ADDINC}" << _EOT
3065 #include <stdio.h>
3066 #include <stdlib.h>
3067 ${2}
3068 #include <term.h>
3069 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3070 static int my_putc(int c){return putchar(c);}
3071 int main(void){
3072 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
3073 int r2 = OK, r3 = ERR;
3075 tgetent(buf, getenv("TERM"));
3076 cpb = cmdbuf;
3077 r1 = tgetstr(UNCONST("cm"), &cpb);
3078 tgoto(r1, 1, 1);
3079 r2 = tgetnum(UNCONST("Co"));
3080 r3 = tgetflag(UNCONST("ut"));
3081 tputs("cr", 1, &my_putc);
3082 return (r1 == NULL || r2 == -1 || r3 == 0);
3084 _EOT
3087 __terminfolib() {
3088 link_check terminfo "terminfo(5) (via ${2}${ADDINC})" \
3089 '#define HAVE_TERMCAP
3090 #define HAVE_TERMCAP_CURSES
3091 #define HAVE_TERMINFO' "${1}" "${ADDINC}" << _EOT
3092 #include <stdio.h>
3093 #include <curses.h>
3094 #include <term.h>
3095 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3096 static int my_putc(int c){return putchar(c);}
3097 int main(void){
3098 int er, r0, r1, r2;
3099 char *r3, *tp;
3101 er = OK;
3102 r0 = setupterm(NULL, 1, &er);
3103 r1 = tigetflag(UNCONST("bce"));
3104 r2 = tigetnum(UNCONST("colors"));
3105 r3 = tigetstr(UNCONST("cr"));
3106 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3107 tputs(tp, 1, &my_putc);
3108 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3109 r3 == (char*)-1 || r3 == NULL);
3111 _EOT
3114 if feat_yes TERMCAP_VIA_TERMINFO; then
3115 ADDINC=
3116 do_me() {
3117 xbail=
3118 __terminfolib -ltinfo -ltinfo ||
3119 __terminfolib -lcurses -lcurses ||
3120 __terminfolib -lcursesw -lcursesw ||
3121 xbail=y
3123 do_me
3124 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3125 ADDINC=' -I/usr/local/include/ncurses'
3126 do_me
3128 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3129 ADDINC=' -I/usr/include/ncurses'
3130 do_me
3132 [ -n "${xbail}" ] && feat_bail_required TERMCAP_VIA_TERMINFO
3135 if [ -z "${have_terminfo}" ]; then
3136 ADDINC=
3137 do_me() {
3138 xbail=
3139 __termcaplib -ltermcap '' '' '-ltermcap' ||
3140 __termcaplib -ltermcap '#include <curses.h>' '
3141 #define HAVE_TERMCAP_CURSES' \
3142 'curses.h / -ltermcap' ||
3143 __termcaplib -lcurses '#include <curses.h>' '
3144 #define HAVE_TERMCAP_CURSES' \
3145 'curses.h / -lcurses' ||
3146 __termcaplib -lcursesw '#include <curses.h>' '
3147 #define HAVE_TERMCAP_CURSES' \
3148 'curses.h / -lcursesw' ||
3149 xbail=y
3151 do_me
3152 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3153 ADDINC=' -I/usr/local/include/ncurses'
3154 do_me
3156 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3157 ADDINC=' -I/usr/include/ncurses'
3158 do_me
3160 [ -n "${xbail}" ] && feat_bail_required TERMCAP
3162 if [ -n "${have_termcap}" ]; then
3163 run_check tgetent_null \
3164 "tgetent(3) of termcap(5) takes NULL buffer" \
3165 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3166 #include <stdio.h> /* For C89 NULL */
3167 #include <stdlib.h>
3168 #ifdef HAVE_TERMCAP_CURSES
3169 # include <curses.h>
3170 #endif
3171 #include <term.h>
3172 int main(void){
3173 tgetent(NULL, getenv("TERM"));
3174 return 0;
3176 _EOT
3179 unset ADDINC
3180 else # }}}
3181 feat_is_disabled TERMCAP
3182 feat_is_disabled TERMCAP_VIA_TERMINFO
3185 if feat_def SPAM_SPAMC; then
3186 if acmd_set i spamc; then
3187 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3191 if feat_yes SPAM_SPAMD; then
3192 if [ -n "${have_af_unix}" ]; then
3193 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3194 else
3195 feat_bail_required SPAM_SPAMD
3197 else
3198 feat_is_disabled SPAM_SPAMD
3201 feat_def SPAM_FILTER
3203 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3204 echo '#define HAVE_SPAM' >> ${h}
3205 else
3206 echo '/* HAVE_SPAM */' >> ${h}
3209 if feat_yes QUOTE_FOLD; then
3210 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3211 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3212 else
3213 feat_bail_required QUOTE_FOLD
3215 else
3216 feat_is_disabled QUOTE_FOLD
3219 feat_def FILTER_HTML_TAGSOUP
3220 feat_def COLOUR
3221 feat_def DOTLOCK
3222 feat_def MD5
3224 ## Summarizing
3226 ${rm} -f ${tmp}
3227 squeeze_em ${inc} ${tmp}
3228 ${mv} ${tmp} ${inc}
3229 squeeze_em ${lib} ${tmp}
3230 ${mv} ${tmp} ${lib}
3232 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3233 echo "INCS = `${cat} ${inc}`" >> ${mk}
3234 echo >> ${mk}
3236 # mk-config.h
3237 ${mv} ${h} ${tmp}
3238 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3239 ${cat} ${tmp} >> ${h}
3240 printf '\n' >> ${h}
3241 # Also need these for correct "second stage configuration changed" detection */
3243 if (${CC} --version) >/dev/null 2>&1; then
3244 i=`${CC} --version 2>&1 | ${awk} '
3245 BEGIN{l=""}
3246 {if(length($0)) {if(l) l = l "\\\\n"; l = l "@" $0}}
3247 END{gsub(/"/, "", l); print "\\\\n" l}
3249 elif (${CC} -v) >/dev/null 2>&1; then
3250 i=`${CC} -v 2>&1 | ${awk} '
3251 BEGIN{l=""}
3252 {if(length($0)) {if(l) l = l "\\\\n"; l = l "@" $0}}
3253 END{gsub(/"/, "", l); print "\\\\n" l}
3256 printf '#define VAL_BUILD_CC "%s %s %s%s"\n' \
3257 "${CC}" "${CFLAGS}" "" "${i}" >> ${h}
3258 printf '#define VAL_BUILD_LD "%s %s %s"\n' \
3259 "${CC}" "${LDFLAGS}" "`${cat} ${lib}`" >> ${h}
3260 printf '#define VAL_BUILD_REST "%s"\n' "${COMMLINE}" >> ${h}
3261 printf '\n' >> ${h}
3263 # Throw away all temporaries
3264 ${rm} -rf ${tmp0}.* ${tmp0}*
3266 # Create the string that is used by *features* and `version'.
3267 # Take this nice opportunity and generate a visual listing of included and
3268 # non-included features for the person who runs the configuration
3269 echo 'The following features are included (+) or not (-):' > ${tmp}
3270 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3271 printf '/* The "feature string" */\n' >> ${h}
3272 # Because + is expanded by *folder* if first in "echo $features", put something
3273 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3274 sep=
3275 for opt
3277 sdoc=`option_doc_of ${opt}`
3278 [ -z "${sdoc}" ] && continue
3279 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3280 feat_yes ${opt} && sign=+ || sign=-
3281 printf -- "${sep}${sign}${sopt}" >> ${h}
3282 sep=','
3283 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3284 done
3285 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3286 #exec 5>&1 >>${h}
3287 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3288 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3289 printf '"\n' >> ${h}
3291 # Create the real mk-config.mk
3292 # Note we cannout use explicit ./ filename prefix for source and object
3293 # pathnames because of a bug in bmake(1)
3294 srclist= objlist=
3295 if feat_no AMALGAMATION; then
3296 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3297 i=`basename "${i}" .c`
3298 if [ "${i}" = privsep ]; then
3299 continue
3301 objlist="${objlist} ${i}.o"
3302 srclist="${srclist} \$(SRCDIR)${i}.c"
3303 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3304 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3305 done
3306 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3307 else
3308 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3309 "main.o" "main.c" >> ${mk}
3310 srclist=main.c objlist=main.o
3311 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3313 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3314 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3315 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3316 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3317 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3318 i=`basename "${i}"`
3319 if [ "${i}" = main.c ] ||
3320 [ "${i}" = privsep.c ]; then
3321 continue
3323 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3324 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3325 done
3326 echo >> ${mk}
3328 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3330 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3332 echo >> ${mk}
3333 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3335 ## Finished!
3337 # We have completed the new configuration header. Check whether *really*
3338 # Do the "second stage configuration changed" detection, exit if nothing to do
3339 if [ -f ${oldh} ]; then
3340 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3341 ${mv} -f ${oldh} ${h}
3342 msg 'Effective configuration is up-to-date'
3343 exit 0
3345 config_updated=1
3346 ${rm} -f ${oldh}
3347 msg 'Effective configuration has been updated..'
3350 if [ -n "${config_updated}" ]; then
3351 msg 'Wiping away old objects and such..'
3352 ( cd .obj; oldmk=`${basename} ${oldmk}`; ${MAKE} -f ${oldmk} clean )
3355 msg ''
3356 while read l; do msg "${l}"; done < ${tmp}
3358 msg 'Setup:'
3359 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3360 msg ' . bindir: %s' "${VAL_BINDIR}"
3361 if feat_yes DOTLOCK; then
3362 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3364 msg ' . mandir: %s' "${VAL_MANDIR}"
3365 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3366 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3368 msg ''
3369 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3370 exit 0
3372 msg 'Remarks:'
3373 if [ -z "${have_fnmatch}" ]; then
3374 msg ' . The function fnmatch(3) could not be found.'
3375 msg ' Filename patterns like wildcard are not supported on your system'
3377 if [ -z "${have_fchdir}" ]; then
3378 msg ' . The function fchdir(2) could not be found.'
3379 msg ' We will use chdir(2) instead.'
3380 msg ' This is a problem only if the current working directory is changed'
3381 msg ' while this program is inside of it'
3383 msg ''
3385 # s-it-mode