Fix (BWDIC!) `~^ header show': optionally show address type in field 1..
[s-mailx.git] / make-config.sh
blob9ce005d17992a4c92627d89d732db08d1a4b7f84
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 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
26 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
27 SMTP='Simple Mail Transfer Protocol client' \
28 POP3='Post Office Protocol Version 3 client' \
29 IMAP='IMAP v4r1 client' \
30 GSSAPI='Generic Security Service authentication' \
31 NETRC='.netrc file support' \
32 AGENT='-' \
33 MD5='MD5 message digest (APOP, CRAM-MD5)' \
34 IDNA='Internationalized Domain Names for Applications (encode only)' \
35 IMAP_SEARCH='IMAP-style search expressions' \
36 REGEX='Regular expressions' \
37 MLE='Mailx Line Editor' \
38 HISTORY='Line editor history management' \
39 KEY_BINDINGS='Configurable key bindings' \
40 TERMCAP='Terminal capability queries (termcap(5))' \
41 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
42 ERRORS='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_SSL=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 SSL; then
172 OPT_SSL_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_SSL=0 OPT_SSL_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
281 if [ ${OS} = SunOS ]; then
282 # According to standards(5), this is what we need to do
283 if [ -d /usr/xpg4 ]; then :; else
284 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
285 config_exit 1
287 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
288 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
289 export PATH
293 os_setup() {
294 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
295 msg 'Operating system is %s' "${OS}"
297 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates
298 # etc.), it is not baked into the binary
299 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`${uname} -a`
301 if [ ${OS} = darwin ]; then
302 msg ' . have special Darwin environmental addons...'
303 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
304 elif [ ${OS} = sunos ]; then
305 msg ' . have special SunOS / Solaris "setup" rules ...'
306 _os_setup_sunos
307 elif [ ${OS} = unixware ]; then
308 if feat_yes AUTOCC && acmd_set CC cc; then
309 msg ' . have special UnixWare environmental rules ...'
310 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
312 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
313 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
314 export CC CFLAGS LDFLAGS
315 OPT_AUTOCC=0 ld_need_R_flags=-R
317 elif [ -n "${VERBOSE}" ]; then
318 msg ' . no special treatment for this system necessary or known'
321 # Sledgehammer: better set _GNU_SOURCE
322 # And in general: oh, boy!
323 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
324 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
325 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
326 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
328 # On pkgsrc(7) systems automatically add /usr/pkg/*
329 if [ -d /usr/pkg ] && feat_yes USE_PKGSYS; then
330 msg ' . found pkgsrc(7), merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
331 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
332 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
333 ld_rpath_not_runpath=1
337 _os_setup_sunos() {
338 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
339 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
341 # Include packages
342 if [ -d /opt/csw ] && feat_yes USE_PKGSYS; then
343 msg ' . found OpenCSW PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
344 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
345 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
346 ld_no_bind_now=1 ld_rpath_not_runpath=1
348 if [ -d /opt/schily ] && feat_yes USE_PKGSYS; then
349 msg ' . found Schily PKGSYS, merging C_INCLUDE_PATH and LD_LIBRARY_PATH'
350 C_INCLUDE_PATH=/opt/schily/include:${C_INCLUDE_PATH}
351 LD_LIBRARY_PATH=/opt/schily/lib:${LD_LIBRARY_PATH}
352 ld_no_bind_now=1 ld_rpath_not_runpath=1
355 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
356 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
358 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
359 if [ -x "${cksum}" ]; then :; else
360 msg 'ERROR: Not an executable program: %s' "${cksum}"
361 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
362 msg 'ERROR: However, we do so only for tests.'
363 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
364 config_exit 1
367 if feat_yes AUTOCC; then
368 if acmd_set CC cc; then
369 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
371 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
372 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
373 export CC CFLAGS LDFLAGS
374 OPT_AUTOCC=0 ld_need_R_flags=-R
375 else
376 cc_maxopt=2 cc_force_no_stackprot=1
381 # Check out compiler ($CC) and -flags ($CFLAGS)
382 cc_setup() {
383 # Even though it belongs into cc_flags we will try to compile and link
384 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
385 # EXTRA_CFLAGS/EXTRA_LDFLAGS
386 if feat_no AUTOCC; then
387 _cc_default
388 # Ensure those don't do any harm
389 EXTRA_CFLAGS= EXTRA_LDFLAGS=
390 export EXTRA_CFLAGS EXTRA_LDFLAGS
391 return
392 else
393 CFLAGS= LDFLAGS=
394 export CFLAGS LDFLAGS
397 [ -n "${CC}" ] && { _cc_default; return; }
399 msg_nonl 'Searching for a usable C compiler .. $CC='
400 if acmd_set CC clang || acmd_set CC gcc ||
401 acmd_set CC tcc || acmd_set CC pcc ||
402 acmd_set CC c89 || acmd_set CC c99; then
404 else
405 msg 'boing booom tschak'
406 msg 'ERROR: I cannot find a compiler!'
407 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
408 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
409 config_exit 1
411 msg '%s' "${CC}"
412 export CC
415 _cc_default() {
416 if [ -z "${CC}" ]; then
417 msg 'To go on like you have chosen, please set $CC, rerun.'
418 config_exit 1
421 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
423 else
424 msg 'Using C compiler ${CC}=%s' "${CC}"
428 cc_flags() {
429 if feat_yes AUTOCC; then
430 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
431 cc_check_silent=1
432 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
433 "${CC}"
434 else
435 cc_check_silent=
436 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
439 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
440 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
441 msg ' . have special tcc(1) environmental rules ...'
442 _cc_flags_tcc
443 else
444 # As of pcc CVS 2016-04-02, stack protection support is announced but
445 # will break if used on Linux
446 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
447 cc_force_no_stackprot=1
449 _cc_flags_generic
452 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
453 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
454 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
455 else
456 if feat_no DEBUG; then
457 CFLAGS="-DNDEBUG ${CFLAGS}"
460 export CFLAGS LDFLAGS
463 _cc_flags_tcc() {
464 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
465 _CFLAGS= _LDFLAGS=
467 cc_check -W
468 cc_check -Wall
469 cc_check -Wextra
470 cc_check -pedantic
472 if feat_yes DEBUG; then
473 # May have problems to find libtcc cc_check -b
474 cc_check -g
477 if ld_check -Wl,-rpath =./ no; then
478 ld_need_R_flags=-Wl,-rpath=
479 if [ -z "${ld_rpath_not_runpath}" ]; then
480 ld_check -Wl,--enable-new-dtags
481 else
482 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
484 ld_runtime_flags # update!
487 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
488 unset __cflags __ldflags
491 _cc_flags_generic() {
492 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
493 _CFLAGS= _LDFLAGS=
494 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
496 # E.g., valgrind does not work well with high optimization
497 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
498 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
499 msg ' ! OPT_NOMEMDBG, setting cc_maxopt=1 (-O1)'
500 cc_maxopt=1
502 # Check -g first since some others may rely upon -g / optim. level
503 if feat_yes DEBUG; then
504 cc_check -O
505 cc_check -g
506 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
508 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
510 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
512 else
513 cc_check -O
516 if feat_yes AMALGAMATION; then
517 cc_check -pipe
520 #if feat_yes DEVEL && cc_check -Weverything; then
522 #else
523 cc_check -W
524 cc_check -Wall
525 cc_check -Wextra
526 cc_check -Wbad-function-cast
527 cc_check -Wcast-align
528 cc_check -Wcast-qual
529 cc_check -Winit-self
530 cc_check -Wmissing-prototypes
531 cc_check -Wshadow
532 cc_check -Wunused
533 cc_check -Wwrite-strings
534 cc_check -Wno-long-long
536 cc_check -pedantic
538 if feat_yes AMALGAMATION && feat_no DEVEL; then
539 cc_check -Wno-unused-function
541 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
543 cc_check -fno-unwind-tables
544 cc_check -fno-asynchronous-unwind-tables
545 cc_check -fstrict-aliasing
546 if cc_check -fstrict-overflow && feat_yes DEVEL; then
547 cc_check -Wstrict-overflow=5
550 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
551 if [ -z "${cc_force_no_stackprot}" ]; then
552 if cc_check -fstack-protector-strong ||
553 cc_check -fstack-protector-all; then
554 cc_check -D_FORTIFY_SOURCE=2
556 else
557 msg ' ! Not checking for -fstack-protector compiler option,'
558 msg ' ! since that caused errors in a "similar" configuration.'
559 msg ' ! You may turn off OPT_AUTOCC and use your own settings, rerun'
563 # LD (+ dependend CC)
565 if feat_yes ASAN_ADDRESS; then
566 _ccfg=${_CFLAGS}
567 if cc_check -fsanitize=address && ld_check -fsanitize=address; then
569 else
570 feat_bail_required ASAN_ADDRESS
571 _CFLAGS=${_ccfg}
575 if feat_yes ASAN_MEMORY; then
576 _ccfg=${_CFLAGS}
577 if cc_check -fsanitize=memory && ld_check -fsanitize=memory &&
578 cc_check -fsanitize-memory-track-origins=2 &&
579 ld_check -fsanitize-memory-track-origins=2; then
581 else
582 feat_bail_required ASAN_MEMORY
583 _CFLAGS=${_ccfg}
587 if feat_yes USAN; then
588 _ccfg=${_CFLAGS}
589 if cc_check -fsanitize=undefined && ld_check -fsanitize=undefined; then
591 else
592 feat_bail_required USAN
593 _CFLAGS=${_ccfg}
597 ld_check -Wl,-z,relro
598 if [ -z "${ld_no_bind_now}" ]; then
599 ld_check -Wl,-z,now
600 else
601 msg ' ! $LD_LIBRARY_PATH adjusted, not trying -Wl,-z,now'
603 ld_check -Wl,-z,noexecstack
604 ld_check -Wl,--as-needed
605 if ld_check -Wl,-rpath =./ no; then
606 ld_need_R_flags=-Wl,-rpath=
607 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
608 if [ -z "${ld_rpath_not_runpath}" ]; then
609 ld_check -Wl,--enable-new-dtags
610 else
611 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
613 ld_runtime_flags # update!
614 elif ld_check -Wl,-R ./ no; then
615 ld_need_R_flags=-Wl,-R
616 if [ -z "${ld_rpath_not_runpath}" ]; then
617 ld_check -Wl,--enable-new-dtags
618 else
619 msg ' ! $LD_LIBRARY_PATH adjusted, not trying --enable-new-dtags'
621 ld_runtime_flags # update!
624 # Address randomization
625 _ccfg=${_CFLAGS}
626 if cc_check -fPIE || cc_check -fpie; then
627 ld_check -pie || _CFLAGS=${_ccfg}
629 unset _ccfg
631 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
632 unset __cflags __ldflags
635 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
637 ## Notes:
638 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
639 ## redirection, so use "printf '' >" instead
641 ## Very first: we undergo several states regarding I/O redirection etc.,
642 ## but need to deal with option updates from within all. Since all the
643 ## option stuff should be above the scissor line, define utility functions
644 ## and redefine them as necessary.
645 ## And, since we have those functions, simply use them for whatever
647 t1=ten10one1ten10one1
648 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
649 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
650 ) > /dev/null 2>&1; then
651 good_shell=1
652 else
653 unset good_shell
655 unset t1
657 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
659 config_exit() {
660 exit ${1}
663 # which(1) not standardized, command(1) -v may return non-executable: unroll!
664 acmd_test() { __acmd "${1}" 1 0 0; }
665 acmd_test_fail() { __acmd "${1}" 1 1 0; }
666 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
667 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
668 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
669 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
670 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
671 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
672 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
673 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
674 __acmd() {
675 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
677 if [ "${dotest}" -ne 0 ]; then
678 eval dotest=\$${varname}
679 if [ -n "${dotest}" ]; then
680 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
681 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
682 return 0
686 oifs=${IFS} IFS=:
687 [ -n "${noglob_shell}" ] && set -o noglob
688 set -- ${PATH}
689 [ -n "${noglob_shell}" ] && set +o noglob
690 IFS=${oifs}
691 for path
693 if [ -z "${path}" ] || [ "${path}" = . ]; then
694 if [ -d "${PWD}" ]; then
695 path=${PWD}
696 else
697 path=.
700 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
701 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
702 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
703 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
704 return 0
706 done
708 # We may have no builtin string functions, we yet have no programs we can
709 # use, try to access once from the root, assuming it is an absolute path if
710 # that finds the executable
711 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
712 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
713 msg ' . ${%s} ... %s' "${pname}" "${pname}"
714 [ -n "${varname}" ] && eval ${varname}="${pname}"
715 return 0
718 [ ${dofail} -eq 0 ] && return 1
719 msg 'ERROR: no trace of utility '"${pname}"
720 exit 1
723 msg() {
724 fmt=${1}
725 shift
726 printf >&2 -- "${fmt}\\n" "${@}"
729 msg_nonl() {
730 fmt=${1}
731 shift
732 printf >&2 -- "${fmt}" "${@}"
735 # Our feature check environment
736 feat_val_no() {
737 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
738 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
741 feat_val_yes() {
742 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
743 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
744 [ "x${1}" = xrequire ]
747 feat_val_require() {
748 [ "x${1}" = xrequire ]
751 _feat_check() {
752 eval i=\$OPT_${1}
753 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
754 if feat_val_no "${i}"; then
755 return 1
756 elif feat_val_yes "${i}"; then
757 return 0
758 else
759 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
760 "${1}" "${i}"
761 config_exit 11
765 feat_yes() {
766 _feat_check ${1}
769 feat_no() {
770 _feat_check ${1} && return 1
771 return 0
774 feat_require() {
775 eval i=\$OPT_${1}
776 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
777 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
780 feat_bail_required() {
781 if feat_require ${1}; then
782 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
783 config_exit 13
785 feat_is_unsupported "${1}"
788 feat_is_disabled() {
789 [ ${#} -eq 1 ] && msg ' . (disabled: OPT_%s)' "${1}"
790 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
793 feat_is_unsupported() {
794 msg ' ! NOTICE: unsupported: OPT_%s' "${1}"
795 echo "/* OPT_${1} -> HAVE_${1} */" >> ${h}
796 eval OPT_${1}=0
797 option_update # XXX this is rather useless here (dependency chain..)
800 feat_def() {
801 if feat_yes ${1}; then
802 msg ' . %s ... yes' "${1}"
803 echo '#define HAVE_'${1}'' >> ${h}
804 return 0
805 else
806 feat_is_disabled "${@}"
807 return 1
811 option_parse() {
812 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
813 # options, without documentation, to $1
814 j=\'
815 i="`${awk} -v input=\"${2}\" '
816 BEGIN{
817 for(i = 0;;){
818 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
819 if(voff == 0)
820 break
821 v = substr(input, voff, RLENGTH)
822 input = substr(input, voff + RLENGTH)
823 doff = index(v, "=")
824 if(doff > 0){
825 d = substr(v, doff + 2, length(v) - doff - 1)
826 v = substr(v, 1, doff - 1)
828 print v
832 eval ${1}=\"${i}\"
835 option_doc_of() {
836 # Return the "documentation string" for option $1, itself if none such
837 j=\'
838 ${awk} -v want="${1}" \
839 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
840 BEGIN{
841 for(;;){
842 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
843 if(voff == 0)
844 break
845 v = substr(input, voff, RLENGTH)
846 input = substr(input, voff + RLENGTH)
847 doff = index(v, "=")
848 if(doff > 0){
849 d = substr(v, doff + 2, length(v) - doff - 1)
850 v = substr(v, 1, doff - 1)
851 }else
852 d = v
853 if(v == want){
854 if(d != "-")
855 print d
856 exit
863 option_join_rc() {
864 # Join the values from make.rc into what currently is defined, not
865 # overwriting yet existing settings
866 ${rm} -f ${tmp}
867 # We want read(1) to perform reverse solidus escaping in order to be able to
868 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
869 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
870 < ${rc} ${awk} 'BEGIN{line = ""}{
871 gsub(/^[[:space:]]+/, "", $0)
872 gsub(/[[:space:]]+$/, "", $0)
873 if(gsub(/\\$/, "", $0)){
874 line = line $0
875 next
876 }else
877 line = line $0
878 if(index(line, "#") == 1){
879 line = ""
880 }else if(length(line)){
881 print line
882 line = ""
884 }' |
885 while read line; do
886 if [ -n "${good_shell}" ]; then
887 i=${line%%=*}
888 else
889 i=`${awk} -v LINE="${line}" 'BEGIN{
890 gsub(/=.*$/, "", LINE)
891 print LINE
894 if [ "${i}" = "${line}" ]; then
895 msg 'ERROR: invalid syntax in: %s' "${line}"
896 continue
899 eval j="\$${i}" jx="\${${i}+x}"
900 if [ -n "${j}" ] || [ "${jx}" = x ]; then
901 : # Yet present
902 else
903 j=`${awk} -v LINE="${line}" 'BEGIN{
904 gsub(/^[^=]*=/, "", LINE)
905 gsub(/^\"*/, "", LINE)
906 gsub(/\"*$/, "", LINE)
907 print LINE
910 [ "${i}" = "DESTDIR" ] && continue
911 echo "${i}=\"${j}\""
912 done > ${tmp}
913 # Reread the mixed version right now
914 . ./${tmp}
917 option_evaluate() {
918 # Expand the option values, which may contain shell snippets
919 ${rm} -f ${newlst} ${newmk} ${newh}
920 exec 5<&0 6>&1 <${tmp} >${newlst}
921 while read line; do
923 if [ -n "${good_shell}" ]; then
924 i=${line%%=*}
925 [ "${i}" != "${i#OPT_}" ] && z=1
926 else
927 i=`${awk} -v LINE="${line}" 'BEGIN{
928 gsub(/=.*$/, "", LINE);\
929 print LINE
931 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
936 eval j=\$${i}
937 if [ -n "${z}" ]; then
938 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
939 if [ -z "${j}" ] || feat_val_no "${j}"; then
941 printf " /* #undef ${i} */\n" >> ${newh}
942 elif feat_val_yes "${j}"; then
943 if feat_val_require "${j}"; then
944 j=require
945 else
948 printf " /* #define ${i} */\n" >> ${newh}
949 else
950 msg 'ERROR: cannot parse <%s>' "${line}"
951 config_exit 1
953 elif { echo ${i} | ${grep} ${H_BLACKLIST} >/dev/null 2>&1; }; then
955 else
956 printf "#define ${i} \"${j}\"\n" >> ${newh}
958 printf "${i} = ${j}\n" >> ${newmk}
959 printf "${i}=${j}\n"
960 eval "${i}=\"${j}\""
961 done
962 exec 0<&5 1>&6 5<&- 6<&-
965 val_allof() {
966 eval __expo__=\$${1}
967 ${awk} -v HEAP="${2}" -v USER="${__expo__}" '
968 BEGIN{
969 i = split(HEAP, ha, /[, ]/)
970 if((j = split(USER, ua, /[, ]/)) == 0)
971 exit
972 for(; j != 0; --j){
973 us = tolower(ua[j])
974 if(us == "all" || us == "any")
975 continue
976 ok = 0
977 for(ii = i; ii != 0; --ii)
978 if(tolower(ha[ii]) == us){
979 ok = 1
980 break
982 if(!ok)
983 exit 1
987 __rv__=${?}
988 [ ${__rv__} -ne 0 ] && return ${__rv__}
990 if ${awk} -v USER="${__expo__}" '
991 BEGIN{
992 if((j = split(USER, ua, /[, ]/)) == 0)
993 exit
994 for(; j != 0; --j){
995 us = tolower(ua[j])
996 if(us == "all" || us == "any")
997 exit 0
999 exit 1
1001 '; then
1002 eval "${1}"=\"${2}\"
1003 else
1004 # Enfore lowercase also in otherwise unchanged user value..
1005 eval "${1}"=\""`echo ${__expo__} | ${tr} '[A-Z]_' '[a-z]-'`"\"
1007 return 0
1010 path_check() {
1011 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
1012 varname=${1} addflag=${2} flagvarname=${3}
1013 j=${IFS}
1014 IFS=:
1015 [ -n "${noglob_shell}" ] && set -o noglob
1016 eval "set -- \$${1}"
1017 [ -n "${noglob_shell}" ] && set +o noglob
1018 IFS=${j}
1019 j= k= y= z=
1020 for i
1022 [ -z "${i}" ] && continue
1023 [ -d "${i}" ] || continue
1024 if [ -n "${j}" ]; then
1025 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
1027 else
1028 y="${y} :${i}:"
1029 j="${j}:${i}"
1030 # But do not link any fakeroot path into our binaries!
1031 if [ -n "${addflag}" ]; then
1032 case "${i}" in *fakeroot*) continue;; esac
1033 k="${k} ${addflag}${i}"
1036 else
1037 y=" :${i}:"
1038 j="${i}"
1039 # But do not link any fakeroot path into our binaries!
1040 if [ -n "${addflag}" ]; then
1041 case "${i}" in *fakeroot*) continue;; esac
1042 k="${k} ${addflag}${i}"
1045 done
1046 eval "${varname}=\"${j}\""
1047 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
1048 unset varname
1051 ld_runtime_flags() {
1052 if [ -n "${ld_need_R_flags}" ]; then
1053 i=${IFS}
1054 IFS=:
1055 set -- ${LD_LIBRARY_PATH}
1056 IFS=${i}
1057 for i
1059 # But do not link any fakeroot path into our binaries!
1060 case "${i}" in *fakeroot*) continue;; esac
1061 LDFLAGS="${LDFLAGS} ${ld_need_R_flags}${i}"
1062 _LDFLAGS="${_LDFLAGS} ${ld_need_R_flags}${i}"
1063 done
1064 export LDFLAGS
1066 # Disable it for a possible second run.
1067 ld_need_R_flags=
1070 cc_check() {
1071 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
1072 if ${CC} ${INCS} \
1073 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
1074 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1075 _CFLAGS="${_CFLAGS} ${1}"
1076 [ -n "${cc_check_silent}" ] || msg 'yes'
1077 return 0
1079 [ -n "${cc_check_silent}" ] || msg 'no'
1080 return 1
1083 ld_check() {
1084 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
1085 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
1086 if ${CC} ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
1087 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
1088 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
1089 [ -n "${cc_check_silent}" ] || msg 'yes'
1090 return 0
1092 [ -n "${cc_check_silent}" ] || msg 'no'
1093 return 1
1096 dump_test_program=1
1097 _check_preface() {
1098 variable=$1 topic=$2 define=$3
1100 echo '**********'
1101 msg_nonl ' . %s ... ' "${topic}"
1102 #echo "/* checked ${topic} */" >> ${h}
1103 ${rm} -f ${tmp} ${tmp}.o
1104 if [ "${dump_test_program}" = 1 ]; then
1105 echo '*** test program is'
1106 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
1107 else
1108 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
1110 #echo '*** the preprocessor generates'
1111 #${make} -f ${makefile} ${tmp}.x
1112 #${cat} ${tmp}.x
1113 echo '*** tests results'
1116 without_check() {
1117 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1119 echo '**********'
1120 msg_nonl ' . %s ... ' "${topic}"
1122 echo '*** enforced unchecked results are'
1123 if feat_val_yes ${yesno}; then
1124 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
1125 echo "*** adding INCS<${incs}> LIBS<${libs}>"
1126 LIBS="${LIBS} ${libs}"
1127 echo "${libs}" >> ${lib}
1128 INCS="${INCS} ${incs}"
1129 echo "${incs}" >> ${inc}
1131 msg 'yes (deduced)'
1132 echo "${define}" >> ${h}
1133 eval have_${variable}=yes
1134 return 0
1135 else
1136 #echo "/* ${define} */" >> ${h}
1137 msg 'no (deduced)'
1138 eval unset have_${variable}
1139 return 1
1143 compile_check() {
1144 variable=$1 topic=$2 define=$3
1146 _check_preface "${variable}" "${topic}" "${define}"
1148 if ${make} -f ${makefile} XINCS="${INCS}" \
1149 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ${tmp}.o &&
1150 [ -f ${tmp}.o ]; then
1151 msg 'yes'
1152 echo "${define}" >> ${h}
1153 eval have_${variable}=yes
1154 return 0
1155 else
1156 #echo "/* ${define} */" >> ${h}
1157 msg 'no'
1158 eval unset have_${variable}
1159 return 1
1163 _link_mayrun() {
1164 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1166 _check_preface "${variable}" "${topic}" "${define}"
1168 if feat_yes CROSS_BUILD; then
1169 if [ ${run} = 1 ]; then
1170 run=0
1174 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1175 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1176 XLIBS="${LIBS} ${libs}" ${tmp} &&
1177 [ -f ${tmp} ] && { [ ${run} -eq 0 ] || ${tmp}; }; then
1178 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1179 msg 'yes'
1180 echo "${define}" >> ${h}
1181 LIBS="${LIBS} ${libs}"
1182 echo "${libs}" >> ${lib}
1183 INCS="${INCS} ${incs}"
1184 echo "${incs}" >> ${inc}
1185 eval have_${variable}=yes
1186 return 0
1187 else
1188 msg 'no'
1189 #echo "/* ${define} */" >> ${h}
1190 eval unset have_${variable}
1191 return 1
1195 link_check() {
1196 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1199 run_check() {
1200 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1203 xrun_check() {
1204 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1207 squeeze_em() {
1208 < "${1}" > "${2}" ${awk} \
1209 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1212 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1214 # First of all, create new configuration and check whether it changed
1216 if [ -d .obj ] || mkdir .obj; then :; else
1217 msg 'ERROR: cannot create .obj build directory'
1218 exit 1
1221 # Very easy checks for the operating system in order to be able to adjust paths
1222 # or similar very basic things which we need to be able to go at all
1223 os_early_setup
1225 # Check those tools right now that we need before including $rc
1226 msg 'Checking for basic utility set'
1227 thecmd_testandset_fail awk awk
1228 thecmd_testandset_fail rm rm
1229 thecmd_testandset_fail tr tr
1231 # Initialize the option set
1232 msg_nonl 'Setting up configuration options ... '
1233 option_setup
1234 msg 'done'
1236 # Include $rc, but only take from it what wasn't overwritten by the user from
1237 # within the command line or from a chosen fixed CONFIG=
1238 # Note we leave alone the values
1239 trap "exit 1" HUP INT TERM
1240 trap "${rm} -f ${tmp}" EXIT
1242 msg_nonl 'Joining in %s ... ' ${rc}
1243 option_join_rc
1244 msg 'done'
1246 # We need to know about that now, in order to provide utility overwrites etc.
1247 os_setup
1249 msg 'Checking for remaining set of utilities'
1250 thecmd_testandset_fail grep grep
1252 # Before we step ahead with the other utilities perform a path cleanup first.
1253 path_check PATH
1255 # awk(1) above
1256 thecmd_testandset_fail basename basename
1257 thecmd_testandset_fail cat cat
1258 thecmd_testandset_fail chmod chmod
1259 thecmd_testandset_fail cp cp
1260 thecmd_testandset_fail cmp cmp
1261 # grep(1) above
1262 thecmd_testandset_fail mkdir mkdir
1263 thecmd_testandset_fail mv mv
1264 # pwd(1) is needed - either for make-emerge.sh, or for ourselves
1265 [ -n "${CWDDIR}" ] || thecmd_testandset_fail pwd pwd
1266 # rm(1) above
1267 thecmd_testandset_fail sed sed
1268 thecmd_testandset_fail sort sort
1269 thecmd_testandset_fail tee tee
1270 __PATH=${PATH}
1271 thecmd_testandset chown chown ||
1272 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1273 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1274 PATH=${__PATH}
1275 thecmd_testandset_fail MAKE make
1276 make=${MAKE}
1277 export MAKE
1278 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1280 # For ./cc-test.sh only
1281 thecmd_testandset_fail cksum cksum
1283 # Now that we have pwd(1), set our build paths unless make-emerge.sh has been
1284 # used; it would have created a makefile with the full paths, then
1285 [ -n "${CWDDIR}" ] || CWDDIR=`${pwd}`/
1286 [ -n "${SRCDIR}" ] || SRCDIR=${CWDDIR}
1288 # Update OPT_ options now, in order to get possible inter-dependencies right
1289 option_update
1291 # (No functions since some shells loose non-exported variables in traps)
1292 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1293 trap "trap \"\" HUP INT TERM EXIT;\
1294 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* \
1295 ${newmk} ${oldmk} ${newev} ${newh} ${oldh}" EXIT
1297 # Our configuration options may at this point still contain shell snippets,
1298 # we need to evaluate them in order to get them expanded, and we need those
1299 # evaluated values not only in our new configuration file, but also at hand..
1300 msg_nonl 'Evaluating all configuration items ... '
1301 option_evaluate
1302 msg 'done'
1305 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1306 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1308 # The problem now is that the test should be able to run in the users linker
1309 # and path environment, so we need to place the test: rule first, before
1310 # injecting the relevant make variables. Set up necessary environment
1311 if [ -z "${VERBOSE}" ]; then
1312 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${newmk}
1313 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${newmk}
1314 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${newmk}
1315 printf -- "ECHO_TEST = @\n" >> ${newmk}
1316 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${newmk}
1317 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${newmk}
1318 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${newmk}
1320 printf 'test: all\n\t$(ECHO_TEST)%s %scc-test.sh --check-only %s\n' \
1321 "${SHELL}" "${SRCDIR}" "./${VAL_SID}${VAL_MAILX}" >> ${newmk}
1322 printf 'citest: all\n\t$(ECHO_TEST)%s %scc-test.sh --ci-test %s\n' \
1323 "${SHELL}" "${SRCDIR}" "./${VAL_SID}${VAL_MAILX}" >> ${newmk}
1325 # Add the known utility and some other variables
1326 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1327 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1328 if feat_yes DOTLOCK; then
1329 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1330 else
1331 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1334 for i in \
1335 CWDDIR SRCDIR \
1336 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1337 MAKE MAKEFLAGS make SHELL strip \
1338 cksum; do
1339 eval j=\$${i}
1340 printf -- "${i} = ${j}\n" >> ${newmk}
1341 printf -- "${i}=${j}\n" >> ${newlst}
1342 printf -- "${i}=\"${j}\";export ${i}; " >> ${newev}
1343 done
1344 # Note that makefile reads and eval'uates one line of this file, whereas other
1345 # consumers source it via .(1)
1346 printf "\n" >> ${newev}
1348 # Build a basic set of INCS and LIBS according to user environment.
1349 C_INCLUDE_PATH="${CWDDIR}:${CWDDIR}.obj:${SRCDIR}:${C_INCLUDE_PATH}"
1350 path_check C_INCLUDE_PATH -I _INCS
1351 INCS="${INCS} ${_INCS}"
1352 path_check LD_LIBRARY_PATH -L _LIBS
1353 LIBS="${LIBS} ${_LIBS}"
1354 unset _INCS _LIBS
1355 export C_INCLUDE_PATH LD_LIBRARY_PATH
1357 # Some environments need runtime path flags to be able to go at all
1358 ld_runtime_flags
1360 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1362 cc_setup
1364 ${cat} > ${tmp}.c << \!
1365 #include <stdio.h>
1366 #include <string.h>
1367 static void doit(char const *s);
1369 main(int argc, char **argv){
1370 (void)argc;
1371 (void)argv;
1372 doit("Hello world");
1373 return 0;
1375 static void
1376 doit(char const *s){
1377 char buf[12];
1378 memcpy(buf, s, strlen(s) +1);
1379 puts(s);
1383 if ${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1384 -o ${tmp2} ${tmp}.c ${LIBS}; then
1386 else
1387 msg 'ERROR: i cannot compile a "Hello world" via'
1388 msg ' %s' \
1389 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1390 msg 'ERROR: Please read INSTALL, rerun'
1391 config_exit 1
1394 # This may also update ld_runtime_flags() (again)
1395 cc_flags
1397 for i in \
1398 COMMLINE \
1399 INCS LIBS \
1400 ; do
1401 eval j="\$${i}"
1402 printf -- "${i}=${j}\n" >> ${newlst}
1403 done
1404 for i in \
1405 CC \
1406 CFLAGS \
1407 LDFLAGS \
1408 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1409 OSFULLSPEC \
1410 ; do
1411 eval j=\$${i}
1412 if [ -n "${j}" ]; then
1413 printf -- "${i} = ${j}\n" >> ${newmk}
1414 printf -- "${i}=${j}\n" >> ${newlst}
1416 done
1418 # Now finally check whether we already have a configuration and if so, whether
1419 # all those parameters are still the same.. or something has actually changed
1420 config_updated=
1421 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1422 echo 'Configuration is up-to-date'
1423 exit 0
1424 elif [ -f ${lst} ]; then
1425 config_updated=1
1426 echo 'Configuration has been updated..'
1427 else
1428 echo 'Shiny configuration..'
1431 # Time to redefine helper 1
1432 config_exit() {
1433 ${rm} -f ${lst} ${h} ${mk}
1434 exit ${1}
1437 ${mv} -f ${newlst} ${lst}
1438 ${mv} -f ${newev} ${ev}
1439 [ -f ${h} ] && ${mv} -f ${h} ${oldh}
1440 ${mv} -f ${newh} ${h}
1441 [ -f ${mk} ] && ${mv} -f ${mk} ${oldmk}
1442 ${mv} -f ${newmk} ${mk}
1444 ## Compile and link checking
1446 tmp3=${tmp0}3$$
1447 log=.obj/mk-config.log
1448 lib=.obj/mk-config.lib
1449 inc=.obj/mk-config.inc
1450 makefile=${tmp0}.mk
1452 # (No function since some shells loose non-exported variables in traps)
1453 trap "trap \"\" HUP INT TERM;\
1454 ${rm} -f ${lst} ${oldh} ${h} ${oldmk} ${mk} ${lib} ${inc}; exit 1" \
1455 HUP INT TERM
1456 trap "trap \"\" HUP INT TERM EXIT;\
1457 ${rm} -rf ${oldh} ${oldmk} ${tmp0}.* ${tmp0}*" EXIT
1459 # Time to redefine helper 2
1460 msg() {
1461 fmt=${1}
1462 shift
1463 printf "*** ${fmt}\\n" "${@}"
1464 printf -- "${fmt}\\n" "${@}" >&5
1466 msg_nonl() {
1467 fmt=${1}
1468 shift
1469 printf "*** ${fmt}\\n" "${@}"
1470 printf -- "${fmt}" "${@}" >&5
1473 # !!
1474 exec 5>&2 > ${log} 2>&1
1476 echo "${LIBS}" > ${lib}
1477 echo "${INCS}" > ${inc}
1478 ${cat} > ${makefile} << \!
1479 .SUFFIXES: .o .c .x .y
1480 .c.o:
1481 $(CC) -I./ $(XINCS) $(CFLAGS) -o $(@) -c $(<)
1482 .c.x:
1483 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1485 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1488 ## Generics
1490 # May be multiline..
1491 echo >> ${h}
1492 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1493 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1495 # Generate n_err_number OS mappings
1496 dump_test_program=0
1498 feat_yes DEVEL && NV= || NV=noverbose
1499 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1500 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1501 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1502 dump_test_program=1
1504 feat_def ALWAYS_UNICODE_LOCALE
1505 feat_def AMALGAMATION 0
1506 feat_def CROSS_BUILD
1507 feat_def DOCSTRINGS
1508 feat_def MAILDIR
1509 feat_def UISTRINGS
1510 feat_def ERRORS
1512 feat_def ASAN_ADDRESS 0
1513 feat_def ASAN_MEMORY 0
1514 feat_def DEBUG 0
1515 feat_def DEVEL 0
1516 feat_def NYD2 0
1517 feat_def NOMEMDBG 0
1519 if xrun_check inline 'inline functions' \
1520 '#define HAVE_INLINE
1521 #define n_INLINE static inline' << \!
1522 static inline int ilf(int i){return ++i;}
1523 int main(void){return ilf(-1);}
1525 then
1527 elif xrun_check inline 'inline functions (via __inline)' \
1528 '#define HAVE_INLINE
1529 #define n_INLINE static __inline' << \!
1530 static __inline int ilf(int i){return ++i;}
1531 int main(void){return ilf(-1);}
1533 then
1537 ## Test for "basic" system-calls / functionality that is used by all parts
1538 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1539 ## macros to be used by only the subprograms (potentially).
1541 if run_check clock_gettime 'clock_gettime(2)' \
1542 '#define HAVE_CLOCK_GETTIME' << \!
1543 #include <time.h>
1544 # include <errno.h>
1545 int main(void){
1546 struct timespec ts;
1548 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1549 return 0;
1550 return 1;
1553 then
1555 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1556 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1557 #include <time.h>
1558 # include <errno.h>
1559 int main(void){
1560 struct timespec ts;
1562 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1563 return 0;
1564 return 1;
1567 then
1569 elif run_check gettimeofday 'gettimeofday(2)' \
1570 '#define HAVE_GETTIMEOFDAY' << \!
1571 #include <stdio.h> /* For C89 NULL */
1572 #include <sys/time.h>
1573 # include <errno.h>
1574 int main(void){
1575 struct timeval tv;
1577 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1578 return 0;
1579 return 1;
1582 then
1584 else
1585 have_no_subsecond_time=1
1588 if run_check nanosleep 'nanosleep(2)' \
1589 '#define HAVE_NANOSLEEP' << \!
1590 #include <time.h>
1591 # include <errno.h>
1592 int main(void){
1593 struct timespec ts;
1595 ts.tv_sec = 1;
1596 ts.tv_nsec = 100000;
1597 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1598 return 0;
1599 return 1;
1602 then
1604 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1605 '#define HAVE_NANOSLEEP' '-lrt' << \!
1606 #include <time.h>
1607 # include <errno.h>
1608 int main(void){
1609 struct timespec ts;
1611 ts.tv_sec = 1;
1612 ts.tv_nsec = 100000;
1613 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1614 return 0;
1615 return 1;
1618 then
1620 # link_check is enough for this, that function is so old, trust the proto
1621 elif link_check sleep 'sleep(3)' \
1622 '#define HAVE_SLEEP' << \!
1623 #include <unistd.h>
1624 # include <errno.h>
1625 int main(void){
1626 if(!sleep(1) || errno != ENOSYS)
1627 return 0;
1628 return 1;
1631 then
1633 else
1634 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1635 config_exit 1
1638 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1639 #include <pwd.h>
1640 #include <unistd.h>
1641 # include <errno.h>
1642 int main(void){
1643 struct passwd *pw;
1644 gid_t gid;
1645 uid_t uid;
1647 if((gid = getgid()) != 0)
1648 gid = getegid();
1649 if((uid = getuid()) != 0)
1650 uid = geteuid();
1651 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1652 return 1;
1653 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1654 return 1;
1655 return 0;
1658 then
1660 else
1661 msg 'ERROR: we require user and group info / database searches.'
1662 msg 'That much Unix we indulge ourselfs.'
1663 config_exit 1
1666 if link_check ftruncate 'ftruncate(2)' \
1667 '#define HAVE_FTRUNCATE' << \!
1668 #include <unistd.h>
1669 #include <sys/types.h>
1670 int main(void){
1671 return (ftruncate(0, 0) != 0);
1674 then
1676 else
1677 # TODO support HAVE_FTRUNCATE *everywhere*, do not require this syscall!
1678 msg 'ERROR: we require the ftruncate(2) system call.'
1679 config_exit 1
1682 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1683 #include <signal.h>
1684 # include <errno.h>
1685 int main(void){
1686 struct sigaction nact, oact;
1688 nact.sa_handler = SIG_DFL;
1689 sigemptyset(&nact.sa_mask);
1690 nact.sa_flags = SA_RESTART;
1691 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1694 then
1696 else
1697 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1698 config_exit 1
1701 if link_check snprintf 'snprintf(3)' << \!
1702 #include <stdio.h>
1703 int main(void){
1704 char b[20];
1706 snprintf(b, sizeof b, "%s", "string");
1707 return 0;
1710 then
1712 else
1713 msg 'ERROR: we require the snprintf(3) function.'
1714 config_exit 1
1717 if link_check environ 'environ(3)' << \!
1718 #include <stdio.h> /* For C89 NULL */
1719 int main(void){
1720 extern char **environ;
1722 return environ[0] == NULL;
1725 then
1727 else
1728 msg 'ERROR: we require the environ(3) array for subprocess control.'
1729 config_exit 1
1732 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1733 #include <stdlib.h>
1734 int main(void){
1735 setenv("s-mailx", "i want to see it cute!", 1);
1736 unsetenv("s-mailx");
1737 return 0;
1740 then
1742 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1743 #include <stdlib.h>
1744 int main(void){
1745 putenv("s-mailx=i want to see it cute!");
1746 return 0;
1749 then
1751 else
1752 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1753 config_exit 1
1756 if link_check termios 'termios.h and tc*(3) family' << \!
1757 #include <termios.h>
1758 int main(void){
1759 struct termios tios;
1761 tcgetattr(0, &tios);
1762 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1763 return 0;
1766 then
1768 else
1769 msg 'ERROR: we require termios.h and the tc[gs]etattr() family of functions.'
1770 msg 'That much Unix we indulge ourselfs.'
1771 config_exit 1
1774 ## optional stuff
1776 if link_check vsnprintf 'vsnprintf(3)' << \!
1777 #include <stdarg.h>
1778 #include <stdio.h>
1779 static void dome(char *buf, size_t blen, ...){
1780 va_list ap;
1782 va_start(ap, blen);
1783 vsnprintf(buf, blen, "%s", ap);
1784 va_end(ap);
1786 int main(void){
1787 char b[20];
1789 dome(b, sizeof b, "string");
1790 return 0;
1793 then
1795 else
1796 feat_bail_required ERRORS
1799 if [ "${have_vsnprintf}" = yes ]; then
1800 __va_copy() {
1801 link_check va_copy "va_copy(3) (as ${2})" \
1802 "#define HAVE_N_VA_COPY
1803 #define n_va_copy ${2}" <<_EOT
1804 #include <stdarg.h>
1805 #include <stdio.h>
1806 #if ${1}
1807 # if defined __va_copy && !defined va_copy
1808 # define va_copy __va_copy
1809 # endif
1810 #endif
1811 static void dome2(char *buf, size_t blen, va_list src){
1812 va_list ap;
1814 va_copy(ap, src);
1815 vsnprintf(buf, blen, "%s", ap);
1816 va_end(ap);
1818 static void dome(char *buf, size_t blen, ...){
1819 va_list ap;
1821 va_start(ap, blen);
1822 dome2(buf, blen, ap);
1823 va_end(ap);
1825 int main(void){
1826 char b[20];
1828 dome(b, sizeof b, "string");
1829 return 0;
1831 _EOT
1833 __va_copy 0 va_copy || __va_copy 1 __va_copy
1836 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1837 #include <unistd.h>
1838 #include <errno.h>
1839 int main(void){
1840 int rv = 0;
1842 errno = 0;
1843 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1844 errno = 0;
1845 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1847 /* Only link check */
1848 fpathconf(0, _PC_NAME_MAX);
1850 return rv;
1854 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1855 #include <fcntl.h>
1856 #include <unistd.h>
1857 # include <errno.h>
1858 int main(void){
1859 int fds[2];
1861 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1862 return 0;
1863 return 1;
1867 link_check tcgetwinsize 'tcgetwinsize(3)' '#define HAVE_TCGETWINSIZE' << \!
1868 #include <termios.h>
1869 int main(void){
1870 struct winsize ws;
1872 tcgetwinsize(0, &ws);
1873 return 0;
1877 # We use this only then for now (need NOW+1)
1878 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1879 #include <fcntl.h> /* For AT_* */
1880 #include <sys/stat.h>
1881 # include <errno.h>
1882 int main(void){
1883 struct timespec ts[2];
1885 ts[0].tv_nsec = UTIME_NOW;
1886 ts[1].tv_nsec = UTIME_OMIT;
1887 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1888 return 0;
1889 return 1;
1895 # The random check has been moved to below SSL detection due to multiple choice
1896 # selection for PRG sources
1898 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1899 #include <stdio.h>
1900 int main(void){
1901 putc_unlocked('@', stdout);
1902 return 0;
1906 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1907 #include <unistd.h>
1908 int main(void){
1909 fchdir(0);
1910 return 0;
1914 if link_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1915 #include <stdlib.h>
1916 int main(void){
1917 char x_buf[4096], *x = realpath(".", x_buf);
1919 return (x != NULL) ? 0 : 1;
1922 then
1923 if run_check realpath_malloc 'realpath(3) takes NULL' \
1924 '#define HAVE_REALPATH_NULL' << \!
1925 #include <stdlib.h>
1926 int main(void){
1927 char *x = realpath(".", NULL);
1929 if(x != NULL)
1930 free(x);
1931 return (x != NULL) ? 0 : 1;
1934 then
1940 ## optional and selectable
1943 if feat_yes DOTLOCK; then
1944 if run_check readlink 'readlink(2)' << \!
1945 #include <unistd.h>
1946 # include <errno.h>
1947 int main(void){
1948 char buf[128];
1950 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1951 return 0;
1952 return 1;
1955 then
1957 else
1958 feat_bail_required DOTLOCK
1962 if feat_yes DOTLOCK; then
1963 if run_check fchown 'fchown(2)' << \!
1964 #include <unistd.h>
1965 # include <errno.h>
1966 int main(void){
1967 if(!fchown(0, 0, 0) || errno != ENOSYS)
1968 return 0;
1969 return 1;
1972 then
1974 else
1975 feat_bail_required DOTLOCK
1979 if feat_yes DOTLOCK; then
1980 if run_check prctl_dumpable 'prctl(2) + PR_SET_DUMPABLE' \
1981 '#define HAVE_PRCTL_DUMPABLE' << \!
1982 #include <sys/prctl.h>
1983 # include <errno.h>
1984 int main(void){
1985 if(!prctl(PR_SET_DUMPABLE, 0) || errno != ENOSYS)
1986 return 0;
1987 return 1;
1990 then
1992 elif run_check prtrace_deny 'ptrace(2) + PT_DENY_ATTACH' \
1993 '#define HAVE_PTRACE_DENY' << \!
1994 #include <sys/ptrace.h>
1995 # include <errno.h>
1996 int main(void){
1997 if(ptrace(PT_DENY_ATTACH, 0, 0, 0) != -1 || errno != ENOSYS)
1998 return 0;
1999 return 1;
2002 then
2004 elif run_check setpflags_protect 'setpflags(2) + __PROC_PROTECT' \
2005 '#define HAVE_SETPFLAGS_PROTECT' << \!
2006 #include <priv.h>
2007 # include <errno.h>
2008 int main(void){
2009 if(!setpflags(__PROC_PROTECT, 1) || errno != ENOSYS)
2010 return 0;
2011 return 1;
2014 then
2019 ## Now it is the time to fork away the BASE_ series
2021 ${rm} -f ${tmp}
2022 squeeze_em ${inc} ${tmp}
2023 ${mv} ${tmp} ${inc}
2024 squeeze_em ${lib} ${tmp}
2025 ${mv} ${tmp} ${lib}
2027 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
2028 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
2030 ## The remains are expected to be used only by the main MUA binary!
2032 OPT_LOCALES=0
2033 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
2034 #include <locale.h>
2035 int main(void){
2036 setlocale(LC_ALL, "");
2037 return 0;
2040 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
2042 OPT_MULTIBYTE_CHARSETS=0
2043 OPT_WIDE_GLYPHS=0
2044 OPT_TERMINAL_CHARSET=0
2045 if [ -n "${have_setlocale}" ]; then
2046 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
2047 '#define HAVE_C90AMEND1' << \!
2048 #include <limits.h>
2049 #include <stdlib.h>
2050 #include <wchar.h>
2051 #include <wctype.h>
2052 int main(void){
2053 char mbb[MB_LEN_MAX + 1];
2054 wchar_t wc;
2056 iswprint(L'c');
2057 towupper(L'c');
2058 mbtowc(&wc, "x", 1);
2059 mbrtowc(&wc, "x", 1, NULL);
2060 wctomb(mbb, wc);
2061 return (mblen("\0", 1) == 0);
2064 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
2066 if [ -n "${have_c90amend1}" ]; then
2067 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
2068 #include <wchar.h>
2069 int main(void){
2070 wcwidth(L'c');
2071 return 0;
2074 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
2077 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
2078 #include <langinfo.h>
2079 #include <stdlib.h>
2080 int main(void){
2081 nl_langinfo(DAY_1);
2082 return (nl_langinfo(CODESET) == NULL);
2085 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
2086 fi # have_setlocale
2088 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
2089 #include <fnmatch.h>
2090 int main(void){
2091 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
2095 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
2096 #include <dirent.h>
2097 int main(void){
2098 struct dirent de;
2099 return !(de.d_type == DT_UNKNOWN ||
2100 de.d_type == DT_DIR || de.d_type == DT_LNK);
2104 ## optional and selectable
2106 if feat_yes ICONV; then
2107 # To be able to create tests we need to figure out which replacement
2108 # sequence the iconv(3) implementation creates
2109 ${cat} > ${tmp2}.c << \!
2110 #include <stdio.h> /* For C89 NULL */
2111 #include <string.h>
2112 #include <iconv.h>
2113 int main(void){
2114 char inb[16], oub[16], *inbp, *oubp;
2115 iconv_t id;
2116 size_t inl, oul;
2118 memcpy(inbp = inb, "\342\200\223", sizeof("\342\200\223"));
2119 inl = sizeof("\342\200\223") -1;
2120 oul = sizeof oub;
2121 oubp = oub;
2123 if((id = iconv_open("ascii", "utf-8")) == (iconv_t)-1)
2124 return 1;
2125 if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1)
2126 return 1;
2127 iconv_close(id);
2129 *oubp = '\0';
2130 oul = (size_t)(oubp - oub);
2131 if(oul == 0)
2132 return 1;
2133 /* Character-wise replacement? */
2134 if(oul == 1){
2135 if(oub[0] == '?')
2136 return 2;
2137 if(oub[0] == '*')
2138 return 3;
2139 return 1;
2141 /* Byte-wise replacement? */
2142 if(oul == sizeof("\342\200\223") -1){
2143 if(!memcmp(oub, "???????", sizeof("\342\200\223") -1))
2144 return 12;
2145 if(!memcmp(oub, "*******", sizeof("\342\200\223") -1))
2146 return 13;
2147 return 1;
2149 return 0;
2152 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
2153 '#define HAVE_ICONV' ||
2154 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
2155 '#define HAVE_ICONV' '-liconv' ||
2156 feat_bail_required ICONV
2158 if feat_no CROSS_BUILD; then
2159 { ${tmp}; } >/dev/null 2>&1
2160 case ${?} in
2161 2) echo 'MAILX_ICONV_MODE=2;export MAILX_ICONV_MODE;' >> ${ev};;
2162 3) echo 'MAILX_ICONV_MODE=3;export MAILX_ICONV_MODE;' >> ${ev};;
2163 12) echo 'MAILX_ICONV_MODE=12;export MAILX_ICONV_MODE;' >> ${ev};;
2164 13) echo 'MAILX_ICONV_MODE=13;export MAILX_ICONV_MODE;' >> ${ev};;
2165 *) msg 'WARN: will restrict iconv(3) tests due to unknown replacement';;
2166 esac
2168 else
2169 feat_is_disabled ICONV
2170 fi # feat_yes ICONV
2172 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
2173 ${cat} > ${tmp2}.c << \!
2174 #include <sys/types.h>
2175 #include <sys/socket.h>
2176 #include <sys/un.h>
2177 # include <errno.h>
2178 int main(void){
2179 struct sockaddr_un soun;
2181 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2182 return 1;
2183 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
2184 return 1;
2185 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
2186 return 1;
2187 return 0;
2191 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
2192 '#define HAVE_UNIX_SOCKETS' ||
2193 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
2194 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
2195 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
2196 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
2199 if feat_yes SOCKETS; then
2200 ${cat} > ${tmp2}.c << \!
2201 #include <sys/types.h>
2202 #include <sys/socket.h>
2203 #include <netinet/in.h>
2204 # include <errno.h>
2205 int main(void){
2206 struct sockaddr s;
2208 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
2209 return 1;
2210 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2211 return 1;
2212 return 0;
2216 < ${tmp2}.c run_check sockets 'sockets' \
2217 '#define HAVE_SOCKETS' ||
2218 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2219 '#define HAVE_SOCKETS' '-lnsl' ||
2220 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2221 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2222 feat_bail_required SOCKETS
2223 else
2224 feat_is_disabled SOCKETS
2225 fi # feat_yes SOCKETS
2227 feat_yes SOCKETS &&
2228 link_check sockopt '[gs]etsockopt(2)' '#define HAVE_SOCKOPT' << \!
2229 #include <sys/socket.h>
2230 #include <stdlib.h>
2231 # include <errno.h>
2232 int main(void){
2233 socklen_t sol;
2234 int sockfd = 3, soe;
2236 sol = sizeof soe;
2237 if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &soe, &sol) == -1 &&
2238 errno == ENOSYS)
2239 return 1;
2240 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2241 errno == ENOSYS)
2242 return 1;
2243 return 0;
2247 feat_yes SOCKETS &&
2248 link_check nonblocksock 'non-blocking sockets' \
2249 '#define HAVE_NONBLOCKSOCK' << \!
2250 #include <sys/types.h>
2251 #include <sys/select.h>
2252 #include <sys/socket.h>
2253 #include <sys/time.h>
2254 #include <arpa/inet.h>
2255 #include <netinet/in.h>
2256 #include <fcntl.h>
2257 #include <stdlib.h>
2258 #include <unistd.h>
2259 # include <errno.h>
2260 int main(void){
2261 fd_set fdset;
2262 struct timeval tv;
2263 struct sockaddr_in sin;
2264 socklen_t sol;
2265 int sofd, soe;
2267 if((sofd = socket(AF_INET, SOCK_STREAM, 0)) == -1 && errno == ENOSYS)
2268 return 1;
2269 if(fcntl(sofd, F_SETFL, O_NONBLOCK) != 0)
2270 return 1;
2272 sin.sin_family = AF_INET;
2273 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
2274 sin.sin_port = htons(80);
2275 if(connect(sofd, &sin, sizeof sin) == -1 && errno == ENOSYS)
2276 return 1;
2278 FD_ZERO(&fdset);
2279 FD_SET(sofd, &fdset);
2280 tv.tv_sec = 10;
2281 tv.tv_usec = 0;
2282 if((soe = select(sofd + 1, NULL, &fdset, NULL, &tv)) == 1){
2283 sol = sizeof soe;
2284 getsockopt(sofd, SOL_SOCKET, SO_ERROR, &soe, &sol);
2285 if(soe == 0)
2286 return 0;
2287 }else if(soe == -1 && errno == ENOSYS)
2288 return 1;
2290 close(sofd);
2291 return 0;
2295 if feat_yes SOCKETS; then
2296 link_check getaddrinfo 'getaddrinfo(3)' \
2297 '#define HAVE_GETADDRINFO' << \!
2298 #include <sys/types.h>
2299 #include <sys/socket.h>
2300 #include <stdio.h>
2301 #include <netdb.h>
2302 int main(void){
2303 struct addrinfo a, *ap;
2304 int lrv;
2306 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2307 case EAI_NONAME:
2308 case EAI_SERVICE:
2309 default:
2310 fprintf(stderr, "%s\n", gai_strerror(lrv));
2311 case 0:
2312 break;
2314 return 0;
2319 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2320 compile_check arpa_inet_h '<arpa/inet.h>' \
2321 '#define HAVE_ARPA_INET_H' << \!
2322 #include <sys/types.h>
2323 #include <sys/socket.h>
2324 #include <netdb.h>
2325 #include <netinet/in.h>
2326 #include <arpa/inet.h>
2329 ${cat} > ${tmp2}.c << \!
2330 #include <sys/types.h>
2331 #include <sys/socket.h>
2332 #include <stdio.h>
2333 #include <string.h>
2334 #include <netdb.h>
2335 #include <netinet/in.h>
2336 #ifdef HAVE_ARPA_INET_H
2337 #include <arpa/inet.h>
2338 #endif
2339 int main(void){
2340 struct sockaddr_in servaddr;
2341 unsigned short portno;
2342 struct servent *ep;
2343 struct hostent *hp;
2344 struct in_addr **pptr;
2346 portno = 0;
2347 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2348 portno = (unsigned short)ep->s_port;
2350 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2351 pptr = (struct in_addr**)hp->h_addr_list;
2352 if(hp->h_addrtype != AF_INET)
2353 fprintf(stderr, "au\n");
2354 }else{
2355 switch(h_errno){
2356 case HOST_NOT_FOUND:
2357 case TRY_AGAIN:
2358 case NO_RECOVERY:
2359 case NO_DATA:
2360 break;
2361 default:
2362 fprintf(stderr, "au\n");
2363 break;
2367 memset(&servaddr, 0, sizeof servaddr);
2368 servaddr.sin_family = AF_INET;
2369 servaddr.sin_port = htons(portno);
2370 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2371 fprintf(stderr, "Would connect to %s:%d ...\n",
2372 inet_ntoa(**pptr), (int)portno);
2373 return 0;
2377 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2378 < ${tmp2}.c link_check gethostbyname \
2379 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2380 < ${tmp2}.c link_check gethostbyname \
2381 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2382 '' '-lsocket -lnsl' ||
2383 feat_bail_required SOCKETS
2386 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2387 link_check so_xtimeo 'SO_{RCV,SND}TIMEO' '#define HAVE_SO_XTIMEO' << \!
2388 #include <sys/socket.h>
2389 #include <stdlib.h>
2390 int main(void){
2391 struct timeval tv;
2392 int sockfd = 3;
2394 tv.tv_sec = 42;
2395 tv.tv_usec = 21;
2396 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2397 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2398 return 0;
2402 feat_yes SOCKETS && [ -n "${have_sockopt}" ] &&
2403 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2404 #include <sys/socket.h>
2405 #include <stdlib.h>
2406 int main(void){
2407 struct linger li;
2408 int sockfd = 3;
2410 li.l_onoff = 1;
2411 li.l_linger = 42;
2412 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2413 return 0;
2417 VAL_SSL_FEATURES=
2418 if feat_yes SSL; then # {{{
2419 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2420 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2421 # time: we need to test it first in order to get things right
2422 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2423 '#define HAVE_SSL
2424 #define HAVE_XSSL
2425 #define HAVE_XSSL_RESSL
2426 #define HAVE_XSSL_OPENSSL 0' << \!
2427 #include <openssl/opensslv.h>
2428 #ifdef LIBRESSL_VERSION_NUMBER
2429 #else
2430 # error nope
2431 #endif
2433 then
2434 ossl_v1_1=
2435 VAL_SSL_FEATURES=libressl
2436 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2437 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2438 '#define HAVE_SSL
2439 #define HAVE_XSSL
2440 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2441 #include <openssl/opensslv.h>
2442 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2443 #else
2444 # error nope
2445 #endif
2447 then
2448 ossl_v1_1=1
2449 VAL_SSL_FEATURES=libssl-0x10100
2450 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2451 '#define HAVE_SSL
2452 #define HAVE_XSSL
2453 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2454 #include <openssl/opensslv.h>
2455 #ifdef OPENSSL_VERSION_NUMBER
2456 #else
2457 # error nope
2458 #endif
2460 then
2461 ossl_v1_1=
2462 VAL_SSL_FEATURES=libssl-0x10000
2463 else
2464 feat_bail_required SSL
2465 fi # }}}
2467 if feat_yes SSL; then # {{{
2468 if [ -n "${ossl_v1_1}" ]; then
2469 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2470 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2471 '-lssl -lcrypto'
2472 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2473 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2474 '-lssl -lcrypto' << \!
2475 #include <openssl/ssl.h>
2476 #include <openssl/err.h>
2477 #include <openssl/x509v3.h>
2478 #include <openssl/x509.h>
2479 #include <openssl/rand.h>
2480 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2481 # error We need TLSv1.
2482 #endif
2483 int main(void){
2484 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2486 SSL_CTX_free(ctx);
2487 PEM_read_PrivateKey(0, 0, 0, 0);
2488 return 0;
2491 then
2493 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2494 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2495 '-lssl -lcrypto' << \!
2496 #include <openssl/ssl.h>
2497 #include <openssl/err.h>
2498 #include <openssl/x509v3.h>
2499 #include <openssl/x509.h>
2500 #include <openssl/rand.h>
2501 #if defined OPENSSL_NO_SSL3 &&\
2502 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2503 # error We need one of SSLv3 and TLSv1.
2504 #endif
2505 int main(void){
2506 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2508 SSL_CTX_free(ctx);
2509 PEM_read_PrivateKey(0, 0, 0, 0);
2510 return 0;
2513 then
2515 else
2516 feat_bail_required SSL
2518 fi # }}}
2520 if feat_yes SSL; then # {{{
2521 if feat_yes SSL_ALL_ALGORITHMS; then
2522 if [ -n "${ossl_v1_1}" ]; then
2523 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2524 '#define HAVE_SSL_ALL_ALGORITHMS'
2525 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2526 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2527 #include <openssl/evp.h>
2528 int main(void){
2529 OpenSSL_add_all_algorithms();
2530 EVP_get_cipherbyname("two cents i never exist");
2531 EVP_cleanup();
2532 return 0;
2535 then
2537 else
2538 feat_bail_required SSL_ALL_ALGORITHMS
2540 elif [ -n "${ossl_v1_1}" ]; then
2541 without_check yes ssl_all_algo \
2542 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2543 '#define HAVE_SSL_ALL_ALGORITHMS'
2546 if [ -n "${ossl_v1_1}" ]; then
2547 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2548 '#define HAVE_XSSL_STACK_OF'
2549 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2550 '#define HAVE_XSSL_STACK_OF' << \!
2551 #include <stdio.h> /* For C89 NULL */
2552 #include <openssl/ssl.h>
2553 #include <openssl/err.h>
2554 #include <openssl/x509v3.h>
2555 #include <openssl/x509.h>
2556 #include <openssl/rand.h>
2557 int main(void){
2558 STACK_OF(GENERAL_NAME) *gens = NULL;
2560 printf("%p", gens); /* to use it */
2561 return 0;
2564 then
2568 if [ -n "${ossl_v1_1}" ]; then
2569 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2570 '#define HAVE_XSSL_CONFIG'
2571 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2572 elif link_check xssl_conf \
2573 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2574 '#define HAVE_XSSL_CONFIG' << \!
2575 #include <stdio.h> /* For C89 NULL */
2576 #include <openssl/conf.h>
2577 int main(void){
2578 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2579 CONF_modules_free();
2580 return 0;
2583 then
2584 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2585 else
2586 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2589 if [ -n "${ossl_v1_1}" ]; then
2590 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2591 '#define HAVE_XSSL_CONF_CTX'
2592 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2593 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2594 '#define HAVE_XSSL_CONF_CTX' << \!
2595 #include <openssl/ssl.h>
2596 #include <openssl/err.h>
2597 int main(void){
2598 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2599 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2601 SSL_CONF_CTX_set_flags(cctx,
2602 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2603 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2604 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2605 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2606 SSL_CONF_CTX_finish(cctx);
2607 SSL_CONF_CTX_free(cctx);
2608 SSL_CTX_free(ctx);
2609 return 0;
2612 then
2613 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2614 else
2615 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2618 if [ -n "${ossl_v1_1}" ]; then
2619 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2620 '#define HAVE_XSSL_CTX_CONFIG'
2621 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2622 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2623 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2624 '#define HAVE_XSSL_CTX_CONFIG' << \!
2625 #include <stdio.h> /* For C89 NULL */
2626 #include <openssl/ssl.h>
2627 int main(void){
2628 SSL_CTX_config(NULL, "SOMEVAL");
2629 return 0;
2632 then
2633 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2634 else
2635 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2638 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2639 without_check yes xssl_set_maxmin_proto \
2640 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2641 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2642 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2643 elif link_check xssl_set_maxmin_proto \
2644 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2645 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2646 #include <stdio.h> /* For C89 NULL */
2647 #include <openssl/ssl.h>
2648 int main(void){
2649 SSL_CTX_set_min_proto_version(NULL, 0);
2650 SSL_CTX_set_max_proto_version(NULL, 10);
2651 return 0;
2654 then
2655 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2656 else
2657 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2660 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2661 without_check yes xssl_set_ciphersuites \
2662 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2663 '#define HAVE_XSSL_SET_CIPHERSUITES'
2664 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-ciphersuites"
2665 elif link_check xssl_set_ciphersuites \
2666 'TLSv1.3 SSL_CTX_set_ciphersuites(3ssl)' \
2667 '#define HAVE_XSSL_SET_CIPHERSUITES' << \!
2668 #include <stdio.h> /* For C89 NULL */
2669 #include <openssl/ssl.h>
2670 int main(void){
2671 SSL_CTX_set_ciphersuites(NULL, NULL);
2672 return 0;
2675 then
2676 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-ciphersuites"
2677 else
2678 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-ciphersuites"
2681 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2682 '#define HAVE_XSSL_RAND_EGD' << \!
2683 #include <openssl/rand.h>
2684 int main(void){
2685 return RAND_egd("some.where") > 0;
2688 then
2689 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2690 else
2691 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2693 fi # feat_yes SSL }}}
2695 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2696 run_check ssl_md5 'MD5 digest in the used crypto library' \
2697 '#define HAVE_XSSL_MD5' << \!
2698 #include <stdlib.h>
2699 #include <string.h>
2700 #include <openssl/md5.h>
2701 int main(void){
2702 char const dat[] = "abrakadabrafidibus";
2703 char dig[16], hex[16 * 2];
2704 MD5_CTX ctx;
2705 size_t i, j;
2707 memset(dig, 0, sizeof(dig));
2708 memset(hex, 0, sizeof(hex));
2709 MD5_Init(&ctx);
2710 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2711 MD5_Final(dig, &ctx);
2713 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2714 for(i = 0; i < sizeof(hex) / 2; i++){
2715 j = i << 1;
2716 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2717 hex[++j] = hexchar(dig[i] & 0x0f);
2719 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2722 fi # }}}
2724 if feat_yes SSL; then
2725 feat_def SSL_ALL_ALGORITHMS
2726 else
2727 feat_bail_required SSL_ALL_ALGORITHMS
2729 else
2730 feat_is_disabled SSL
2731 feat_is_disabled SSL_ALL_ALGORITHMS
2732 fi # }}} feat_yes SSL
2733 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2735 if [ "${have_xssl}" = yes ]; then
2736 OPT_SMIME=1
2737 else
2738 OPT_SMIME=0
2740 feat_def SMIME
2742 # VAL_RANDOM {{{
2743 if val_allof VAL_RANDOM \
2744 "arc4,ssl,libgetrandom,sysgetrandom,urandom,builtin,error"; then
2746 else
2747 msg 'ERROR: VAL_RANDOM with invalid entries: %s' "${VAL_RANDOM}"
2748 config_exit 1
2751 val_random_arc4() {
2752 link_check arc4random 'VAL_RANDOM: arc4random(3)' \
2753 '#define HAVE_RANDOM n_RANDOM_IMPL_ARC4' << \!
2754 #include <stdlib.h>
2755 int main(void){
2756 arc4random();
2757 return 0;
2762 val_random_ssl() {
2763 if feat_yes SSL; then
2764 msg ' . VAL_RANDOM: ssl ... yes'
2765 echo '#define HAVE_RANDOM n_RANDOM_IMPL_SSL' >> ${h}
2766 return 0
2767 else
2768 msg ' . VAL_RANDOM: ssl ... no'
2769 return 1
2773 val_random_libgetrandom() {
2774 link_check getrandom 'VAL_RANDOM: getrandom(3) (in sys/random.h)' \
2775 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2776 #define n_RANDOM_GETRANDOM_FUN(B,S) getrandom(B, S, 0)
2777 #define n_RANDOM_GETRANDOM_H <sys/random.h>' <<\!
2778 #include <sys/random.h>
2779 int main(void){
2780 char buf[256];
2781 getrandom(buf, sizeof buf, 0);
2782 return 0;
2787 val_random_sysgetrandom() {
2788 link_check getrandom 'VAL_RANDOM: getrandom(2) (via syscall(2))' \
2789 '#define HAVE_RANDOM n_RANDOM_IMPL_GETRANDOM
2790 #define n_RANDOM_GETRANDOM_FUN(B,S) syscall(SYS_getrandom, B, S, 0)
2791 #define n_RANDOM_GETRANDOM_H <sys/syscall.h>' <<\!
2792 #include <sys/syscall.h>
2793 int main(void){
2794 char buf[256];
2795 syscall(SYS_getrandom, buf, sizeof buf, 0);
2796 return 0;
2801 val_random_urandom() {
2802 msg_nonl ' . VAL_RANDOM: /dev/urandom ... '
2803 if feat_yes CROSS_BUILD; then
2804 msg 'yes (unchecked)'
2805 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2806 elif [ -f /dev/urandom ]; then
2807 msg yes
2808 echo '#define HAVE_RANDOM n_RANDOM_IMPL_URANDOM' >> ${h}
2809 else
2810 msg no
2811 return 1
2813 return 0
2816 val_random_builtin() {
2817 msg_nonl ' . VAL_RANDOM: builtin ... '
2818 if [ -n "${have_no_subsecond_time}" ]; then
2819 msg 'no\nERROR: %s %s' 'without a specialized PRG ' \
2820 'one of clock_gettime(2) and gettimeofday(2) is required.'
2821 config_exit 1
2822 else
2823 msg yes
2824 echo '#define HAVE_RANDOM n_RANDOM_IMPL_BUILTIN' >> ${h}
2828 val_random_error() {
2829 msg 'ERROR: VAL_RANDOM search reached "error" entry'
2830 config_exit 42
2833 oifs=${IFS}
2834 IFS=", "
2835 VAL_RANDOM="${VAL_RANDOM},error"
2836 set -- ${VAL_RANDOM}
2837 IFS=${oifs}
2838 for randfun
2840 eval val_random_$randfun && break
2841 done
2842 # }}} VAL_RANDOM
2844 feat_def SMTP
2845 feat_def POP3
2846 feat_def IMAP
2848 if feat_yes GSSAPI; then
2849 ${cat} > ${tmp2}.c << \!
2850 #include <gssapi/gssapi.h>
2851 int main(void){
2852 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2853 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2854 return 0;
2857 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2859 if acmd_set i krb5-config; then
2860 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2861 GSS_INCS="`CFLAGS= ${i} --cflags`"
2862 i='GSS-API via krb5-config(1)'
2863 else
2864 GSS_LIBS='-lgssapi'
2865 GSS_INCS=
2866 i='GSS-API in gssapi/gssapi.h, libgssapi'
2868 if < ${tmp2}.c link_check gss \
2869 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2870 < ${tmp3}.c link_check gss \
2871 'GSS-API in gssapi.h, libgssapi' \
2872 '#define HAVE_GSSAPI
2873 #define GSSAPI_REG_INCLUDE' \
2874 '-lgssapi' ||\
2875 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2876 '#define HAVE_GSSAPI' \
2877 '-lgssapi_krb5' ||\
2878 < ${tmp3}.c link_check gss \
2879 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2880 '#define HAVE_GSSAPI
2881 #define GSS_REG_INCLUDE' \
2882 '-lgssapi -lkrb5 -lcrypto' \
2883 '-I/usr/include/kerberosV' ||\
2884 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2885 '#define HAVE_GSSAPI' \
2886 '-lgss' ||\
2887 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2888 '#define HAVE_GSSAPI
2889 #define GSSAPI_OLD_STYLE' \
2890 '-lgssapi_krb5' << \!
2891 #include <gssapi/gssapi.h>
2892 #include <gssapi/gssapi_generic.h>
2893 int main(void){
2894 gss_import_name(0, 0, gss_nt_service_name, 0);
2895 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2896 return 0;
2899 then
2901 else
2902 feat_bail_required GSSAPI
2904 else
2905 feat_is_disabled GSSAPI
2906 fi # feat_yes GSSAPI
2908 feat_def NETRC
2909 feat_def AGENT
2911 if feat_yes IDNA; then # {{{
2912 if val_allof VAL_IDNA "idnkit,idn2,idn"; then
2914 else
2915 msg 'ERROR: VAL_IDNA with invalid entries: %s' "${VAL_IDNA}"
2916 config_exit 1
2919 val_idna_idn2() {
2920 link_check idna 'OPT_IDNA: GNU Libidn2' \
2921 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN2' '-lidn2' << \!
2922 #include <idn2.h>
2923 int main(void){
2924 char *idna_utf8, *idna_lc;
2926 if(idn2_to_ascii_8z("does.this.work", &idna_utf8,
2927 IDN2_NONTRANSITIONAL | IDN2_TRANSITIONAL) != IDN2_OK)
2928 return 1;
2929 if(idn2_to_unicode_8zlz(idna_utf8, &idna_lc, 0) != IDN2_OK)
2930 return 1;
2931 idn2_free(idna_lc);
2932 idn2_free(idna_utf8);
2933 return 0;
2938 val_idna_idn() {
2939 link_check idna 'OPT_IDNA: GNU Libidn' \
2940 '#define HAVE_IDNA n_IDNA_IMPL_LIBIDN' '-lidn' << \!
2941 #include <idna.h>
2942 #include <idn-free.h>
2943 #include <stringprep.h> /* XXX we actually use our own iconv instead */
2944 int main(void){
2945 char *utf8, *idna_ascii, *idna_utf8;
2947 utf8 = stringprep_locale_to_utf8("does.this.work");
2948 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2949 != IDNA_SUCCESS)
2950 return 1;
2951 idn_free(idna_ascii);
2952 /* (Rather link check only here) */
2953 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2954 return 0;
2959 val_idna_idnkit() {
2960 link_check idna 'OPT_IDNA: idnkit' \
2961 '#define HAVE_IDNA n_IDNA_IMPL_IDNKIT' '-lidnkit' << \!
2962 #include <stdio.h>
2963 #include <idn/api.h>
2964 #include <idn/result.h>
2965 int main(void){
2966 idn_result_t r;
2967 char ace_name[256];
2968 char local_name[256];
2970 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2971 sizeof(ace_name));
2972 if (r != idn_success) {
2973 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2974 return 1;
2976 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2977 if (r != idn_success) {
2978 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2979 return 1;
2981 return 0;
2986 val_idna_bye() {
2987 feat_bail_required IDNA
2990 oifs=${IFS}
2991 IFS=", "
2992 VAL_IDNA="${VAL_IDNA},bye"
2993 set -- ${VAL_IDNA}
2994 IFS=${oifs}
2995 for randfun
2997 eval val_idna_$randfun && break
2998 done
2999 else
3000 feat_is_disabled IDNA
3001 fi # }}} IDNA
3003 feat_def IMAP_SEARCH
3005 if feat_yes REGEX; then
3006 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
3007 #include <regex.h>
3008 #include <stdlib.h>
3009 int main(void){
3010 size_t xret;
3011 int status;
3012 regex_t re;
3014 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
3015 xret = regerror(status, &re, NULL, 0);
3016 status = regexec(&re, "plan9", 0,NULL, 0);
3017 regfree(&re);
3018 return !(status == REG_NOMATCH);
3021 then
3023 else
3024 feat_bail_required REGEX
3026 else
3027 feat_is_disabled REGEX
3030 if feat_yes MLE; then
3031 if [ -n "${have_c90amend1}" ]; then
3032 have_mle=1
3033 echo '#define HAVE_MLE' >> ${h}
3034 else
3035 feat_bail_required MLE
3037 else
3038 feat_is_disabled MLE
3041 # Generic have-a-line-editor switch for those who need it below
3042 if [ -n "${have_mle}" ]; then
3043 have_cle=1
3046 if feat_yes HISTORY; then
3047 if [ -n "${have_cle}" ]; then
3048 echo '#define HAVE_HISTORY' >> ${h}
3049 else
3050 feat_is_unsupported HISTORY
3052 else
3053 feat_is_disabled HISTORY
3056 if feat_yes KEY_BINDINGS; then
3057 if [ -n "${have_mle}" ]; then
3058 echo '#define HAVE_KEY_BINDINGS' >> ${h}
3059 else
3060 feat_is_unsupported KEY_BINDINGS
3062 else
3063 feat_is_disabled KEY_BINDINGS
3066 if feat_yes TERMCAP; then # {{{
3067 ADDINC=
3068 __termcaplib() {
3069 link_check termcap "termcap(5) (via ${4}${ADDINC})" \
3070 "#define HAVE_TERMCAP${3}" "${1}" "${ADDINC}" << _EOT
3071 #include <stdio.h>
3072 #include <stdlib.h>
3073 ${2}
3074 #include <term.h>
3075 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3076 static int my_putc(int c){return putchar(c);}
3077 int main(void){
3078 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
3079 int r2 = OK, r3 = ERR;
3081 tgetent(buf, getenv("TERM"));
3082 cpb = cmdbuf;
3083 r1 = tgetstr(UNCONST("cm"), &cpb);
3084 tgoto(r1, 1, 1);
3085 r2 = tgetnum(UNCONST("Co"));
3086 r3 = tgetflag(UNCONST("ut"));
3087 tputs("cr", 1, &my_putc);
3088 return (r1 == NULL || r2 == -1 || r3 == 0);
3090 _EOT
3093 __terminfolib() {
3094 link_check terminfo "terminfo(5) (via ${2}${ADDINC})" \
3095 '#define HAVE_TERMCAP
3096 #define HAVE_TERMCAP_CURSES
3097 #define HAVE_TERMINFO' "${1}" "${ADDINC}" << _EOT
3098 #include <stdio.h>
3099 #include <curses.h>
3100 #include <term.h>
3101 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
3102 static int my_putc(int c){return putchar(c);}
3103 int main(void){
3104 int er, r0, r1, r2;
3105 char *r3, *tp;
3107 er = OK;
3108 r0 = setupterm(NULL, 1, &er);
3109 r1 = tigetflag(UNCONST("bce"));
3110 r2 = tigetnum(UNCONST("colors"));
3111 r3 = tigetstr(UNCONST("cr"));
3112 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
3113 tputs(tp, 1, &my_putc);
3114 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
3115 r3 == (char*)-1 || r3 == NULL);
3117 _EOT
3120 if feat_yes TERMCAP_VIA_TERMINFO; then
3121 ADDINC=
3122 do_me() {
3123 xbail=
3124 __terminfolib -ltinfo -ltinfo ||
3125 __terminfolib -lcurses -lcurses ||
3126 __terminfolib -lcursesw -lcursesw ||
3127 xbail=y
3129 do_me
3130 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3131 ADDINC=' -I/usr/local/include/ncurses'
3132 do_me
3134 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3135 ADDINC=' -I/usr/include/ncurses'
3136 do_me
3138 [ -n "${xbail}" ] && feat_bail_required TERMCAP_VIA_TERMINFO
3141 if [ -z "${have_terminfo}" ]; then
3142 ADDINC=
3143 do_me() {
3144 xbail=
3145 __termcaplib -ltermcap '' '' '-ltermcap' ||
3146 __termcaplib -ltermcap '#include <curses.h>' '
3147 #define HAVE_TERMCAP_CURSES' \
3148 'curses.h / -ltermcap' ||
3149 __termcaplib -lcurses '#include <curses.h>' '
3150 #define HAVE_TERMCAP_CURSES' \
3151 'curses.h / -lcurses' ||
3152 __termcaplib -lcursesw '#include <curses.h>' '
3153 #define HAVE_TERMCAP_CURSES' \
3154 'curses.h / -lcursesw' ||
3155 xbail=y
3157 do_me
3158 if [ -n "${xbail}" ] && [ -d /usr/local/include/ncurses ]; then
3159 ADDINC=' -I/usr/local/include/ncurses'
3160 do_me
3162 if [ -n "${xbail}" ] && [ -d /usr/include/ncurses ]; then
3163 ADDINC=' -I/usr/include/ncurses'
3164 do_me
3166 [ -n "${xbail}" ] && feat_bail_required TERMCAP
3168 if [ -n "${have_termcap}" ]; then
3169 run_check tgetent_null \
3170 "tgetent(3) of termcap(5) takes NULL buffer" \
3171 "#define HAVE_TGETENT_NULL_BUF" << _EOT
3172 #include <stdio.h> /* For C89 NULL */
3173 #include <stdlib.h>
3174 #ifdef HAVE_TERMCAP_CURSES
3175 # include <curses.h>
3176 #endif
3177 #include <term.h>
3178 int main(void){
3179 tgetent(NULL, getenv("TERM"));
3180 return 0;
3182 _EOT
3185 unset ADDINC
3186 else # }}}
3187 feat_is_disabled TERMCAP
3188 feat_is_disabled TERMCAP_VIA_TERMINFO
3191 if feat_def SPAM_SPAMC; then
3192 if acmd_set i spamc; then
3193 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
3197 if feat_yes SPAM_SPAMD; then
3198 if [ -n "${have_af_unix}" ]; then
3199 echo '#define HAVE_SPAM_SPAMD' >> ${h}
3200 else
3201 feat_bail_required SPAM_SPAMD
3203 else
3204 feat_is_disabled SPAM_SPAMD
3207 feat_def SPAM_FILTER
3209 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
3210 echo '#define HAVE_SPAM' >> ${h}
3211 else
3212 echo '/* HAVE_SPAM */' >> ${h}
3215 if feat_yes QUOTE_FOLD; then
3216 if [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
3217 echo '#define HAVE_QUOTE_FOLD' >> ${h}
3218 else
3219 feat_bail_required QUOTE_FOLD
3221 else
3222 feat_is_disabled QUOTE_FOLD
3225 feat_def FILTER_HTML_TAGSOUP
3226 feat_def COLOUR
3227 feat_def DOTLOCK
3228 feat_def MD5
3230 ## Summarizing
3232 ${rm} -f ${tmp}
3233 squeeze_em ${inc} ${tmp}
3234 ${mv} ${tmp} ${inc}
3235 squeeze_em ${lib} ${tmp}
3236 ${mv} ${tmp} ${lib}
3238 echo "LIBS = `${cat} ${lib}`" >> ${mk}
3239 echo "INCS = `${cat} ${inc}`" >> ${mk}
3240 echo >> ${mk}
3242 # mk-config.h
3243 ${mv} ${h} ${tmp}
3244 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
3245 ${cat} ${tmp} >> ${h}
3246 printf '\n' >> ${h}
3247 # Also need these for correct "second stage configuration changed" detection */
3249 if (${CC} --version) >/dev/null 2>&1; then
3250 i=`${CC} --version 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}
3255 elif (${CC} -v) >/dev/null 2>&1; then
3256 i=`${CC} -v 2>&1 | ${awk} '
3257 BEGIN{l=""}
3258 {if(length($0)) {if(l) l = l "\\\\n"; l = l "@" $0}}
3259 END{gsub(/"/, "", l); print "\\\\n" l}
3262 printf '#define VAL_BUILD_CC "%s %s %s%s"\n' \
3263 "${CC}" "${CFLAGS}" "" "${i}" >> ${h}
3264 printf '#define VAL_BUILD_LD "%s %s %s"\n' \
3265 "${CC}" "${LDFLAGS}" "`${cat} ${lib}`" >> ${h}
3266 printf '#define VAL_BUILD_REST "%s"\n' "${COMMLINE}" >> ${h}
3267 printf '\n' >> ${h}
3269 # Throw away all temporaries
3270 ${rm} -rf ${tmp0}.* ${tmp0}*
3272 # Create the string that is used by *features* and `version'.
3273 # Take this nice opportunity and generate a visual listing of included and
3274 # non-included features for the person who runs the configuration
3275 echo 'The following features are included (+) or not (-):' > ${tmp}
3276 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
3277 printf '/* The "feature string" */\n' >> ${h}
3278 # Because + is expanded by *folder* if first in "echo $features", put something
3279 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
3280 sep=
3281 for opt
3283 sdoc=`option_doc_of ${opt}`
3284 [ -z "${sdoc}" ] && continue
3285 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
3286 feat_yes ${opt} && sign=+ || sign=-
3287 printf -- "${sep}${sign}${sopt}" >> ${h}
3288 sep=','
3289 printf ' %s %s: %s\n' ${sign} ${sopt} "${sdoc}" >> ${tmp}
3290 done
3291 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
3292 #exec 5>&1 >>${h}
3293 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
3294 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
3295 printf '"\n' >> ${h}
3297 # Create the real mk-config.mk
3298 # Note we cannout use explicit ./ filename prefix for source and object
3299 # pathnames because of a bug in bmake(1)
3300 srclist= objlist=
3301 if feat_no AMALGAMATION; then
3302 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3303 i=`basename "${i}" .c`
3304 if [ "${i}" = privsep ]; then
3305 continue
3307 objlist="${objlist} ${i}.o"
3308 srclist="${srclist} \$(SRCDIR)${i}.c"
3309 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
3310 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
3311 done
3312 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
3313 else
3314 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
3315 "main.o" "main.c" >> ${mk}
3316 srclist=main.c objlist=main.o
3317 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
3319 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
3320 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
3321 printf '# undef n_MK_CONFIG_H\n' >> ${h}
3322 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
3323 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
3324 i=`basename "${i}"`
3325 if [ "${i}" = main.c ] ||
3326 [ "${i}" = privsep.c ]; then
3327 continue
3329 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
3330 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
3331 done
3332 echo >> ${mk}
3334 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
3336 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
3338 echo >> ${mk}
3339 ${cat} "${SRCDIR}"make-config.in >> ${mk}
3341 ## Finished!
3343 # We have completed the new configuration header. Check whether *really*
3344 # Do the "second stage configuration changed" detection, exit if nothing to do
3345 if [ -f ${oldh} ]; then
3346 if ${cmp} ${h} ${oldh} >/dev/null 2>&1; then
3347 ${mv} -f ${oldh} ${h}
3348 msg 'Effective configuration is up-to-date'
3349 exit 0
3351 config_updated=1
3352 ${rm} -f ${oldh}
3353 msg 'Effective configuration has been updated..'
3356 if [ -n "${config_updated}" ]; then
3357 msg 'Wiping away old objects and such..'
3358 ( cd .obj; oldmk=`${basename} ${oldmk}`; ${MAKE} -f ${oldmk} clean )
3361 msg ''
3362 while read l; do msg "${l}"; done < ${tmp}
3364 msg 'Setup:'
3365 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
3366 msg ' . bindir: %s' "${VAL_BINDIR}"
3367 if feat_yes DOTLOCK; then
3368 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
3370 msg ' . mandir: %s' "${VAL_MANDIR}"
3371 msg ' . M(ail)T(ransfer)A(gent): %s (argv0: %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
3372 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
3374 msg ''
3375 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
3376 exit 0
3378 msg 'Remarks:'
3379 if [ -z "${have_fnmatch}" ]; then
3380 msg ' . The function fnmatch(3) could not be found.'
3381 msg ' Filename patterns like wildcard are not supported on your system'
3383 if [ -z "${have_fchdir}" ]; then
3384 msg ' . The function fchdir(2) could not be found.'
3385 msg ' We will use chdir(2) instead.'
3386 msg ' This is a problem only if the current working directory is changed'
3387 msg ' while this program is inside of it'
3389 msg ''
3391 # s-it-mode