Port to SunOS 5.9 (Aharon Robbins)
[s-mailx.git] / make-config.sh
blob094d893b69ccfa08dd2fff894c3ebbafaa83386b
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='Error 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 QUOTE_FOLD='Extended *quote-fold*ing' \
47 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
48 COLOUR='Coloured message display' \
49 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
52 # Options which are automatically deduced from host environment, i.e., these
53 # need special treatment all around here to warp from/to OPT_ stuff
54 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
55 XOPTIONS_DETECT="\
56 LOCALES='Locale support - printable characters etc. depend on environment' \
57 MULTIBYTE_CHARSETS='Multibyte character sets' \
58 TERMINAL_CHARSET='Automatic detection of terminal character set' \
59 WIDE_GLYPHS='Wide glyph support' \
62 # Rather special options, for custom building, or which always exist.
63 # Mostly for generating the visual overview and the *features* string
64 XOPTIONS_XTRA="\
65 MIME='Multipurpose Internet Mail Extensions' \
66 SMIME='S/MIME message signing, verification, en- and decryption' \
67 CROSS_BUILD='Cross-compilation: trust any detected environment' \
68 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
69 DEVEL='Computers do not blunder' \
72 # The problem is that we don't have any tools we can use right now, so
73 # encapsulate stuff in functions which get called in right order later on
75 option_reset() {
76 set -- ${OPTIONS}
77 for i
79 eval OPT_${i}=0
80 done
83 option_maximal() {
84 set -- ${OPTIONS}
85 for i
87 eval OPT_${i}=1
88 done
89 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
92 option_setup() {
93 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
94 option_parse OPTIONS "${XOPTIONS}"
95 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
96 OPT_MIME=1
98 # Predefined CONFIG= urations take precedence over anything else
99 if [ -n "${CONFIG}" ]; then
100 option_reset
101 case "${CONFIG}" in
102 [nN][uU][lL][lL])
104 [nN][uU][lL][lL][iI])
105 OPT_ICONV=require
107 [mM][iI][nN][iI][mM][aA][lL])
108 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
109 OPT_COLOUR=1
110 OPT_DOCSTRINGS=1
111 OPT_ERRORS=1
112 OPT_IDNA=1
113 OPT_MLE=1
114 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
115 OPT_SPAM_FILTER=1
117 [nN][eE][tT][sS][eE][nN][dD])
118 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
119 OPT_SOCKETS=require
120 OPT_SSL=require
121 OPT_SMTP=require
122 OPT_GSSAPI=1 OPT_NETRC=1
123 OPT_AGENT=1
124 OPT_COLOUR=1
125 OPT_DOCSTRINGS=1
126 OPT_ERRORS=1
127 OPT_IDNA=1
128 OPT_MLE=1
129 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
130 OPT_SPAM_FILTER=1
132 [mM][aA][xX][iI][mM][aA][lL])
133 option_maximal
135 [dD][eE][vV][eE][lL])
136 option_maximal
137 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
139 [oO][dD][eE][vV][eE][lL])
140 option_maximal
141 OPT_DEVEL=1
144 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
145 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
146 exit 1
148 esac
149 msg_nonl "CONFIG=${CONFIG} ... "
153 # Inter-relationships
154 option_update() {
155 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
156 OPT_SOCKETS=0
158 if feat_no SOCKETS; then
159 if feat_require SMTP; then
160 msg 'ERROR: need SOCKETS for required feature SMTP'
161 config_exit 13
163 if feat_require POP3; then
164 msg 'ERROR: need SOCKETS for required feature POP3'
165 config_exit 13
167 if feat_require IMAP; then
168 msg 'ERROR: need SOCKETS for required feature IMAP'
169 config_exit 13
171 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
172 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
173 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
175 if feat_no SMTP && feat_no IMAP; then
176 OPT_GSSAPI=0
179 if feat_no ICONV; then
180 if feat_yes IMAP; then
181 if feat_require IMAP; then
182 msg 'ERROR: need ICONV for required feature IMAP'
183 config_exit 13
185 msg 'ERROR: disabling IMAP due to missing ICONV'
186 OPT_IMAP=0
189 if feat_yes IDNA; then
190 if feat_require IDNA; then
191 msg 'ERROR: need ICONV for required feature IDNA'
192 config_exit 13
194 msg 'ERROR: disabling IDNA due to missing ICONV'
195 OPT_IDNA=0
199 if feat_no MLE; then
200 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
203 # If we don't need MD5 leave it alone
204 if feat_no SOCKETS; then
205 OPT_MD5=0
208 if feat_no TERMCAP; then
209 OPT_TERMCAP_VIA_TERMINFO=0
212 if feat_yes DEVEL; then
213 OPT_DEBUG=1
217 rc=./make.rc
218 lst=./mk-config.lst
219 ev=./mk-config.ev
220 h=./mk-config.h h_name=mk-config.h
221 mk=./mk-config.mk
223 newlst=./mk-nconfig.lst
224 newmk=./mk-nconfig.mk
225 newev=./mk-nconfig.ev
226 newh=./mk-nconfig.h
227 tmp0=___tmp
228 tmp=./${tmp0}1$$
229 tmp2=./${tmp0}2$$
231 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
233 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
234 # via path_check() later on once possible
236 # TODO cc_maxopt is brute simple, we should compile test program and dig real
237 # compiler versions for known compilers, then be more specific
238 [ -n "${cc_maxopt}" ] || cc_maxopt=100
239 _CFLAGS= _LDFLAGS=
241 os_early_setup() {
242 # We don't "have any utility": only path adjustments and such in here!
243 [ -n "${OS}" ] || OS=`uname -s`
244 export OS
246 if [ ${OS} = SunOS ]; then
247 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
248 _os_early_setup_sunos
252 _os_early_setup_sunos() {
253 # According to standards(5), this is what we need to do
254 if [ -d /usr/xpg4 ]; then :; else
255 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
256 config_exit 1
258 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
259 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
260 export PATH
263 os_setup() {
264 # OSENV ends up in *build-osenv*
265 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
266 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
267 [ -n "${OSENV}" ] || OSENV=`uname -srm`
268 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`uname -a`
269 msg 'Operating system is %s' ${OS}
271 if [ ${OS} = darwin ]; then
272 msg ' . have special Darwin environmental addons...'
273 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
274 elif [ ${OS} = sunos ]; then
275 msg ' . have special SunOS / Solaris "setup" rules ...'
276 _os_setup_sunos
277 elif [ ${OS} = unixware ]; then
278 if feat_yes AUTOCC && acmd_set CC cc; then
279 msg ' . have special UnixWare environmental rules ...'
280 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
282 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
283 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
284 export CC CFLAGS LDFLAGS
285 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
287 elif [ -n "${VERBOSE}" ]; then
288 msg ' . no special treatment for this system necessary or known'
291 # Sledgehammer: better set _GNU_SOURCE
292 # And in general: oh, boy!
293 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
294 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
295 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
296 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
298 # On pkgsrc(7) systems automatically add /usr/pkg/*
299 if [ -d /usr/pkg ]; then
300 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
301 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
305 _os_setup_sunos() {
306 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
307 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
309 # Include packages
310 if [ -d /opt/csw ]; then
311 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
312 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
315 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
316 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
318 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
319 if [ -x "${cksum}" ]; then :; else
320 msg 'ERROR: Not an executable program: %s' "${cksum}"
321 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
322 msg 'ERROR: However, we do so only for tests.'
323 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
324 config_exit 1
327 if feat_yes AUTOCC; then
328 if acmd_set CC cc; then
329 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
331 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
332 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
333 export CC CFLAGS LDFLAGS
334 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
335 else
336 # Assume gcc(1), which supports -R for compat
337 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
342 # Check out compiler ($CC) and -flags ($CFLAGS)
343 cc_setup() {
344 # Even though it belongs into cc_flags we will try to compile and link
345 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
346 # EXTRA_CFLAGS/EXTRA_LDFLAGS
347 if feat_no AUTOCC; then
348 _cc_default
349 # Ensure those don't do any harm
350 EXTRA_CFLAGS= EXTRA_LDFLAGS=
351 export EXTRA_CFLAGS EXTRA_LDFLAGS
352 return
353 else
354 CFLAGS= LDFLAGS=
355 export CFLAGS LDFLAGS
358 [ -n "${CC}" ] && { _cc_default; return; }
360 msg_nonl 'Searching for a usable C compiler .. $CC='
361 if acmd_set CC clang || acmd_set CC gcc ||
362 acmd_set CC tcc || acmd_set CC pcc ||
363 acmd_set CC c89 || acmd_set CC c99; then
365 else
366 msg 'boing booom tschak'
367 msg 'ERROR: I cannot find a compiler!'
368 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
369 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
370 config_exit 1
372 msg '%s' "${CC}"
373 export CC
376 _cc_default() {
377 if [ -z "${CC}" ]; then
378 msg 'To go on like you have chosen, please set $CC, rerun.'
379 config_exit 1
382 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
384 else
385 msg 'Using C compiler ${CC}=%s' "${CC}"
389 cc_flags() {
390 if feat_yes AUTOCC; then
391 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
392 cc_check_silent=1
393 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
394 "${CC}"
395 else
396 cc_check_silent=
397 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
400 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
401 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
402 msg ' . have special tcc(1) environmental rules ...'
403 _cc_flags_tcc
404 else
405 # As of pcc CVS 2016-04-02, stack protection support is announced but
406 # will break if used on Linux
407 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
408 force_no_stackprot=1
410 _cc_flags_generic
413 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
414 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
415 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
416 else
417 if feat_no DEBUG; then
418 CFLAGS="-DNDEBUG ${CFLAGS}"
421 msg ''
422 export CFLAGS LDFLAGS
425 _cc_flags_tcc() {
426 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
427 _CFLAGS= _LDFLAGS=
429 cc_check -Wall
430 cc_check -Wextra
431 cc_check -pedantic
433 if feat_yes DEBUG; then
434 # May have problems to find libtcc cc_check -b
435 cc_check -g
438 if ld_check -Wl,-rpath =./ no; then
439 need_R_ldflags=-Wl,-rpath=
440 ld_check -Wl,--enable-new-dtags
441 ld_runtime_flags # update!
444 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
445 unset __cflags __ldflags
448 _cc_flags_generic() {
449 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
450 _CFLAGS= _LDFLAGS=
451 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
453 # E.g., valgrind does not work well with high optimization
454 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
455 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
456 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
457 cc_maxopt=1
459 # Check -g first since some others may rely upon -g / optim. level
460 if feat_yes DEBUG; then
461 cc_check -O
462 cc_check -g
463 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
465 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
467 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
469 else
470 cc_check -O
473 if feat_yes AMALGAMATION; then
474 cc_check -pipe
477 #if feat_yes DEVEL && cc_check -Weverything; then
479 #else
480 cc_check -Wall
481 cc_check -Wextra
482 cc_check -Wbad-function-cast
483 cc_check -Wcast-align
484 cc_check -Wcast-qual
485 cc_check -Winit-self
486 cc_check -Wmissing-prototypes
487 cc_check -Wshadow
488 cc_check -Wunused
489 cc_check -Wwrite-strings
490 cc_check -Wno-long-long
492 cc_check -pedantic
494 if feat_yes AMALGAMATION && feat_no DEVEL; then
495 cc_check -Wno-unused-function
497 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
499 cc_check -fno-unwind-tables
500 cc_check -fno-asynchronous-unwind-tables
501 cc_check -fstrict-aliasing
502 if cc_check -fstrict-overflow && feat_yes DEVEL; then
503 cc_check -Wstrict-overflow=5
506 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
507 if [ -z "${force_no_stackprot}" ]; then
508 if cc_check -fstack-protector-strong ||
509 cc_check -fstack-protector-all; then
510 cc_check -D_FORTIFY_SOURCE=2
512 else
513 msg 'Not checking for -fstack-protector compiler option,'
514 msg 'since that caused errors in a "similar" configuration.'
515 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
519 # LD (+ dependend CC)
521 if feat_yes ASAN_ADDRESS; then
522 _ccfg=${_CFLAGS}
523 if cc_check -fsanitize=address &&
524 ld_check -fsanitize=address; then
526 else
527 feat_bail_required ASAN_ADDRESS
528 _CFLAGS=${_ccfg}
532 if feat_yes ASAN_MEMORY; then
533 _ccfg=${_CFLAGS}
534 if cc_check -fsanitize=memory &&
535 ld_check -fsanitize=memory &&
536 cc_check -fsanitize-memory-track-origins=2 &&
537 ld_check -fsanitize-memory-track-origins=2; then
539 else
540 feat_bail_required ASAN_MEMORY
541 _CFLAGS=${_ccfg}
545 ld_check -Wl,-z,relro
546 ld_check -Wl,-z,now
547 ld_check -Wl,-z,noexecstack
548 if ld_check -Wl,-rpath =./ no; then
549 need_R_ldflags=-Wl,-rpath=
550 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
551 ld_check -Wl,--enable-new-dtags
552 ld_runtime_flags # update!
553 elif ld_check -Wl,-R ./ no; then
554 need_R_ldflags=-Wl,-R
555 ld_check -Wl,--enable-new-dtags
556 ld_runtime_flags # update!
559 # Address randomization
560 _ccfg=${_CFLAGS}
561 if cc_check -fPIE || cc_check -fpie; then
562 ld_check -pie || _CFLAGS=${_ccfg}
564 unset _ccfg
566 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
567 unset __cflags __ldflags
570 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
572 ## Notes:
573 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
574 ## redirection, so use "printf '' >" instead
576 ## Very first: we undergo several states regarding I/O redirection etc.,
577 ## but need to deal with option updates from within all. Since all the
578 ## option stuff should be above the scissor line, define utility functions
579 ## and redefine them as necessary.
580 ## And, since we have those functions, simply use them for whatever
582 t1=ten10one1ten10one1
583 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
584 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
585 ) > /dev/null 2>&1; then
586 good_shell=1
587 else
588 unset good_shell
590 unset t1
592 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
594 config_exit() {
595 exit ${1}
598 # which(1) not standardized, command(1) -v may return non-executable: unroll!
599 acmd_test() { __acmd "${1}" 1 0 0; }
600 acmd_test_fail() { __acmd "${1}" 1 1 0; }
601 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
602 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
603 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
604 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
605 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
606 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
607 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
608 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
609 __acmd() {
610 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
612 if [ "${dotest}" -ne 0 ]; then
613 eval dotest=\$${varname}
614 if [ -n "${dotest}" ]; then
615 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
616 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
617 return 0
621 oifs=${IFS} IFS=:
622 [ -n "${noglob_shell}" ] && set -o noglob
623 set -- ${PATH}
624 [ -n "${noglob_shell}" ] && set +o noglob
625 IFS=${oifs}
626 for path
628 if [ -z "${path}" ] || [ "${path}" = . ]; then
629 if [ -d "${PWD}" ]; then
630 path=${PWD}
631 else
632 path=.
635 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
636 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
637 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
638 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
639 return 0
641 done
643 # We may have no builtin string functions, we yet have no programs we can
644 # use, try to access once from the root, assuming it is an absolute path if
645 # that finds the executable
646 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
647 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
648 msg ' . ${%s} ... %s' "${pname}" "${pname}"
649 [ -n "${varname}" ] && eval ${varname}="${pname}"
650 return 0
653 [ ${dofail} -eq 0 ] && return 1
654 msg 'ERROR: no trace of utility '"${pname}"
655 exit 1
658 msg() {
659 fmt=${1}
660 shift
661 printf >&2 -- "${fmt}\\n" "${@}"
664 msg_nonl() {
665 fmt=${1}
666 shift
667 printf >&2 -- "${fmt}" "${@}"
670 # Our feature check environment
671 feat_val_no() {
672 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
673 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
676 feat_val_yes() {
677 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
678 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
679 [ "x${1}" = xrequire ]
682 feat_val_require() {
683 [ "x${1}" = xrequire ]
686 _feat_check() {
687 eval i=\$OPT_${1}
688 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
689 if feat_val_no "${i}"; then
690 return 1
691 elif feat_val_yes "${i}"; then
692 return 0
693 else
694 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
695 "${1}" "${i}"
696 config_exit 11
700 feat_yes() {
701 _feat_check ${1}
704 feat_no() {
705 _feat_check ${1} && return 1
706 return 0
709 feat_require() {
710 eval i=\$OPT_${1}
711 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
712 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
715 feat_bail_required() {
716 if feat_require ${1}; then
717 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
718 config_exit 13
720 eval OPT_${1}=0
721 option_update # XXX this is rather useless here (dependency chain..)
724 option_parse() {
725 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
726 # options, without documentation, to $1
727 j=\'
728 i="`${awk} -v input=\"${2}\" '
729 BEGIN{
730 for(i = 0;;){
731 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
732 if(voff == 0)
733 break
734 v = substr(input, voff, RLENGTH)
735 input = substr(input, voff + RLENGTH)
736 doff = index(v, "=")
737 if(doff > 0){
738 d = substr(v, doff + 2, length(v) - doff - 1)
739 v = substr(v, 1, doff - 1)
741 print v
745 eval ${1}=\"${i}\"
748 option_doc_of() {
749 # Return the "documentation string" for option $1, itself if none such
750 j=\'
751 ${awk} -v want="${1}" \
752 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
753 BEGIN{
754 for(;;){
755 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
756 if(voff == 0)
757 break
758 v = substr(input, voff, RLENGTH)
759 input = substr(input, voff + RLENGTH)
760 doff = index(v, "=")
761 if(doff > 0){
762 d = substr(v, doff + 2, length(v) - doff - 1)
763 v = substr(v, 1, doff - 1)
764 }else
765 d = v
766 if(v == want){
767 if(d != "-")
768 print d
769 exit
776 option_join_rc() {
777 # Join the values from make.rc into what currently is defined, not
778 # overwriting yet existing settings
779 ${rm} -f ${tmp}
780 # We want read(1) to perform reverse solidus escaping in order to be able to
781 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
782 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
783 < ${rc} ${awk} 'BEGIN{line = ""}{
784 gsub(/^[[:space:]]+/, "", $0)
785 gsub(/[[:space:]]+$/, "", $0)
786 if(gsub(/\\$/, "", $0)){
787 line = line $0
788 next
789 }else
790 line = line $0
791 if(index(line, "#") == 1){
792 line = ""
793 }else if(length(line)){
794 print line
795 line = ""
797 }' |
798 while read line; do
799 if [ -n "${good_shell}" ]; then
800 i=${line%%=*}
801 else
802 i=`${awk} -v LINE="${line}" 'BEGIN{
803 gsub(/=.*$/, "", LINE)
804 print LINE
807 if [ "${i}" = "${line}" ]; then
808 msg 'ERROR: invalid syntax in: %s' "${line}"
809 continue
812 eval j="\$${i}" jx="\${${i}+x}"
813 if [ -n "${j}" ] || [ "${jx}" = x ]; then
814 : # Yet present
815 else
816 j=`${awk} -v LINE="${line}" 'BEGIN{
817 gsub(/^[^=]*=/, "", LINE)
818 gsub(/^\"*/, "", LINE)
819 gsub(/\"*$/, "", LINE)
820 print LINE
823 [ "${i}" = "DESTDIR" ] && continue
824 echo "${i}=\"${j}\""
825 done > ${tmp}
826 # Reread the mixed version right now
827 . ./${tmp}
830 option_evaluate() {
831 # Expand the option values, which may contain shell snippets
832 ${rm} -f ${newlst} ${newmk} ${newh}
833 exec 5<&0 6>&1 <${tmp} >${newlst}
834 while read line; do
836 if [ -n "${good_shell}" ]; then
837 i=${line%%=*}
838 [ "${i}" != "${i#OPT_}" ] && z=1
839 else
840 i=`${awk} -v LINE="${line}" 'BEGIN{
841 gsub(/=.*$/, "", LINE);\
842 print LINE
844 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
849 eval j=\$${i}
850 if [ -n "${z}" ]; then
851 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
852 if [ -z "${j}" ] || feat_val_no "${j}"; then
854 printf " /* #undef ${i} */\n" >> ${newh}
855 elif feat_val_yes "${j}"; then
856 if feat_val_require "${j}"; then
857 j=require
858 else
861 printf " /* #define ${i} */\n" >> ${newh}
862 else
863 msg 'ERROR: cannot parse <%s>' "${line}"
864 config_exit 1
866 else
867 printf "#define ${i} \"${j}\"\n" >> ${newh}
869 printf "${i} = ${j}\n" >> ${newmk}
870 printf "${i}=${j}\n"
871 eval "${i}=\"${j}\""
872 done
873 exec 0<&5 1>&6 5<&- 6<&-
876 path_check() {
877 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
878 varname=${1} addflag=${2} flagvarname=${3}
879 j=${IFS}
880 IFS=:
881 [ -n "${noglob_shell}" ] && set -o noglob
882 eval "set -- \$${1}"
883 [ -n "${noglob_shell}" ] && set +o noglob
884 IFS=${j}
885 j= k= y= z=
886 for i
888 [ -z "${i}" ] && continue
889 [ -d "${i}" ] || continue
890 if [ -n "${j}" ]; then
891 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
893 else
894 y="${y} :${i}:"
895 j="${j}:${i}"
896 # But do not link any fakeroot path into our binaries!
897 if [ -n "${addflag}" ]; then
898 case "${i}" in *fakeroot*) continue;; esac
899 k="${k} ${addflag}${i}"
902 else
903 y=" :${i}:"
904 j="${i}"
905 # But do not link any fakeroot path into our binaries!
906 if [ -n "${addflag}" ]; then
907 case "${i}" in *fakeroot*) continue;; esac
908 k="${k} ${addflag}${i}"
911 done
912 eval "${varname}=\"${j}\""
913 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
914 unset varname
917 ld_runtime_flags() {
918 if [ -n "${need_R_ldflags}" ]; then
919 i=${IFS}
920 IFS=:
921 set -- ${LD_LIBRARY_PATH}
922 IFS=${i}
923 for i
925 # But do not link any fakeroot path into our binaries!
926 case "${i}" in *fakeroot*) continue;; esac
927 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
928 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
929 done
930 export LDFLAGS
932 # Disable it for a possible second run.
933 need_R_ldflags=
936 cc_check() {
937 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
938 if "${CC}" ${INCS} \
939 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
940 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
941 _CFLAGS="${_CFLAGS} ${1}"
942 [ -n "${cc_check_silent}" ] || msg 'yes'
943 return 0
945 [ -n "${cc_check_silent}" ] || msg 'no'
946 return 1
949 ld_check() {
950 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
951 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
952 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
953 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
954 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
955 [ -n "${cc_check_silent}" ] || msg 'yes'
956 return 0
958 [ -n "${cc_check_silent}" ] || msg 'no'
959 return 1
962 dump_test_program=1
963 _check_preface() {
964 variable=$1 topic=$2 define=$3
966 echo '**********'
967 msg_nonl ' . %s ... ' "${topic}"
968 echo "/* checked ${topic} */" >> ${h}
969 ${rm} -f ${tmp} ${tmp}.o
970 if [ "${dump_test_program}" = 1 ]; then
971 echo '*** test program is'
972 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
973 else
974 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
976 #echo '*** the preprocessor generates'
977 #${make} -f ${makefile} ${tmp}.x
978 #${cat} ${tmp}.x
979 echo '*** tests results'
982 without_check() {
983 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
985 echo '**********'
986 msg_nonl ' . %s ... ' "${topic}"
988 echo '*** enforced unchecked results are'
989 if feat_val_yes ${yesno}; then
990 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
991 echo "*** adding INCS<${incs}> LIBS<${libs}>"
992 LIBS="${LIBS} ${libs}"
993 echo "${libs}" >> ${lib}
994 INCS="${INCS} ${incs}"
995 echo "${incs}" >> ${inc}
997 msg 'yes (deduced)'
998 echo "${define}" >> ${h}
999 eval have_${variable}=yes
1000 return 0
1001 else
1002 echo "/* ${define} */" >> ${h}
1003 msg 'no (deduced)'
1004 eval unset have_${variable}
1005 return 1
1009 compile_check() {
1010 variable=$1 topic=$2 define=$3
1012 _check_preface "${variable}" "${topic}" "${define}"
1014 if ${make} -f ${makefile} XINCS="${INCS}" \
1015 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1016 ./${tmp}.o &&
1017 [ -f ./${tmp}.o ]; then
1018 msg 'yes'
1019 echo "${define}" >> ${h}
1020 eval have_${variable}=yes
1021 return 0
1022 else
1023 echo "/* ${define} */" >> ${h}
1024 msg 'no'
1025 eval unset have_${variable}
1026 return 1
1030 _link_mayrun() {
1031 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1033 _check_preface "${variable}" "${topic}" "${define}"
1035 if feat_yes CROSS_BUILD; then
1036 if [ ${run} = 1 ]; then
1037 run=0
1041 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1042 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1043 XLIBS="${LIBS} ${libs}" \
1044 ./${tmp} &&
1045 [ -f ./${tmp} ] &&
1046 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1047 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1048 msg 'yes'
1049 echo "${define}" >> ${h}
1050 LIBS="${LIBS} ${libs}"
1051 echo "${libs}" >> ${lib}
1052 INCS="${INCS} ${incs}"
1053 echo "${incs}" >> ${inc}
1054 eval have_${variable}=yes
1055 return 0
1056 else
1057 msg 'no'
1058 echo "/* ${define} */" >> ${h}
1059 eval unset have_${variable}
1060 return 1
1064 link_check() {
1065 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1068 run_check() {
1069 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1072 xrun_check() {
1073 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1076 feat_def() {
1077 if feat_yes ${1}; then
1078 echo '#define HAVE_'${1}'' >> ${h}
1079 return 0
1080 else
1081 echo '/* OPT_'${1}'=0 */' >> ${h}
1082 return 1
1086 squeeze_em() {
1087 < "${1}" > "${2}" ${awk} \
1088 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1091 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1093 # First of all, create new configuration and check whether it changed
1095 # Very easy checks for the operating system in order to be able to adjust paths
1096 # or similar very basic things which we need to be able to go at all
1097 os_early_setup
1099 # Check those tools right now that we need before including $rc
1100 msg 'Checking for basic utility set'
1101 thecmd_testandset_fail awk awk
1102 thecmd_testandset_fail rm rm
1103 thecmd_testandset_fail tr tr
1105 # Initialize the option set
1106 msg_nonl 'Setting up configuration options ... '
1107 option_setup
1108 msg 'done'
1110 # Include $rc, but only take from it what wasn't overwritten by the user from
1111 # within the command line or from a chosen fixed CONFIG=
1112 # Note we leave alone the values
1113 trap "exit 1" HUP INT TERM
1114 trap "${rm} -f ${tmp}" EXIT
1116 msg_nonl 'Joining in %s ... ' ${rc}
1117 option_join_rc
1118 msg 'done'
1120 # We need to know about that now, in order to provide utility overwrites etc.
1121 os_setup
1123 msg 'Checking for remaining set of utilities'
1124 thecmd_testandset_fail grep grep
1126 # Before we step ahead with the other utilities perform a path cleanup first.
1127 path_check PATH
1129 # awk(1) above
1130 thecmd_testandset_fail basename basename
1131 thecmd_testandset_fail cat cat
1132 thecmd_testandset_fail chmod chmod
1133 thecmd_testandset_fail cp cp
1134 thecmd_testandset_fail cmp cmp
1135 # grep(1) above
1136 thecmd_testandset_fail mkdir mkdir
1137 thecmd_testandset_fail mv mv
1138 # rm(1) above
1139 thecmd_testandset_fail sed sed
1140 thecmd_testandset_fail sort sort
1141 thecmd_testandset_fail tee tee
1142 __PATH=${PATH}
1143 thecmd_testandset chown chown ||
1144 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1145 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1146 PATH=${__PATH}
1147 thecmd_testandset_fail make make
1148 MAKE=${make}
1149 export MAKE
1150 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1152 # For ./cc-test.sh only
1153 thecmd_testandset_fail cksum cksum
1155 # Update OPT_ options now, in order to get possible inter-dependencies right
1156 option_update
1158 # (No functions since some shells loose non-exported variables in traps)
1159 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1160 trap "trap \"\" HUP INT TERM EXIT;\
1161 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1163 # Our configuration options may at this point still contain shell snippets,
1164 # we need to evaluate them in order to get them expanded, and we need those
1165 # evaluated values not only in our new configuration file, but also at hand..
1166 msg_nonl 'Evaluating all configuration items ... '
1167 option_evaluate
1168 msg 'done'
1170 # Add the known utility and some other variables
1171 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1172 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1174 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1175 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1176 if feat_yes DOTLOCK; then
1177 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1178 else
1179 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1182 for i in \
1183 SRCDIR \
1184 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1185 MAKE MAKEFLAGS make SHELL strip \
1186 cksum; do
1187 eval j=\$${i}
1188 printf "${i} = ${j}\n" >> ${newmk}
1189 printf "${i}=${j}\n" >> ${newlst}
1190 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1191 done
1192 printf "\n" >> ${newev}
1194 # Build a basic set of INCS and LIBS according to user environment.
1195 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1196 path_check C_INCLUDE_PATH -I _INCS
1197 INCS="${INCS} ${_INCS}"
1198 path_check LD_LIBRARY_PATH -L _LIBS
1199 LIBS="${LIBS} ${_LIBS}"
1200 unset _INCS _LIBS
1201 export C_INCLUDE_PATH LD_LIBRARY_PATH
1203 # Some environments need runtime path flags to be able to go at all
1204 ld_runtime_flags
1206 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1208 cc_setup
1210 ${cat} > ${tmp}.c << \!
1211 #include <stdio.h>
1212 #include <string.h>
1213 static void doit(char const *s);
1215 main(int argc, char **argv){
1216 (void)argc;
1217 (void)argv;
1218 doit("Hello world");
1219 return 0;
1221 static void
1222 doit(char const *s){
1223 char buf[12];
1224 memcpy(buf, s, strlen(s) +1);
1225 puts(s);
1229 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1230 -o ${tmp2} ${tmp}.c ${LIBS}; then
1232 else
1233 msg 'ERROR: i cannot compile a "Hello world" via'
1234 msg ' %s' \
1235 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1236 msg 'ERROR: Please read INSTALL, rerun'
1237 config_exit 1
1240 # This may also update ld_runtime_flags() (again)
1241 cc_flags
1243 for i in \
1244 INCS LIBS \
1245 ; do
1246 eval j=\$${i}
1247 printf -- "${i}=${j}\n" >> ${newlst}
1248 done
1249 for i in \
1250 CC \
1251 CFLAGS \
1252 LDFLAGS \
1253 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1254 OSFULLSPEC \
1255 ; do
1256 eval j=\$${i}
1257 printf -- "${i} = ${j}\n" >> ${newmk}
1258 printf -- "${i}=${j}\n" >> ${newlst}
1259 done
1261 # Now finally check whether we already have a configuration and if so, whether
1262 # all those parameters are still the same.. or something has actually changed
1263 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1264 echo 'Configuration is up-to-date'
1265 exit 0
1266 elif [ -f ${lst} ]; then
1267 echo 'Configuration has been updated..'
1268 ( eval "${MAKE} -f ./mk-config.mk clean" )
1269 echo
1270 else
1271 echo 'Shiny configuration..'
1274 # Time to redefine helper 1
1275 config_exit() {
1276 ${rm} -f ${lst} ${h} ${mk}
1277 exit ${1}
1280 ${mv} -f ${newlst} ${lst}
1281 ${mv} -f ${newev} ${ev}
1282 ${mv} -f ${newh} ${h}
1283 ${mv} -f ${newmk} ${mk}
1285 if [ -z "${VERBOSE}" ]; then
1286 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1287 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1288 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1289 printf -- "ECHO_TEST = @\n" >> ${mk}
1290 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1291 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1292 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1295 ## Compile and link checking
1297 tmp3=./${tmp0}3$$
1298 log=./mk-config.log
1299 lib=./mk-config.lib
1300 inc=./mk-config.inc
1301 makefile=./${tmp0}.mk
1303 # (No function since some shells loose non-exported variables in traps)
1304 trap "trap \"\" HUP INT TERM;\
1305 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1306 trap "trap \"\" HUP INT TERM EXIT;\
1307 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1309 # Time to redefine helper 2
1310 msg() {
1311 fmt=${1}
1312 shift
1313 printf "*** ${fmt}\\n" "${@}"
1314 printf -- "${fmt}\\n" "${@}" >&5
1316 msg_nonl() {
1317 fmt=${1}
1318 shift
1319 printf "*** ${fmt}\\n" "${@}"
1320 printf -- "${fmt}" "${@}" >&5
1323 # !!
1324 exec 5>&2 > ${log} 2>&1
1326 echo "${LIBS}" > ${lib}
1327 echo "${INCS}" > ${inc}
1328 ${cat} > ${makefile} << \!
1329 .SUFFIXES: .o .c .x .y
1330 .c.o:
1331 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1332 .c.x:
1333 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1335 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1338 ## Generics
1340 # May be multiline..
1341 echo >> ${h}
1342 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1343 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1344 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1346 # Generate n_err_number OS mappings
1347 dump_test_program=0
1349 feat_yes DEVEL && NV= || NV=noverbose
1350 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1351 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1352 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1353 dump_test_program=1
1355 feat_def ALWAYS_UNICODE_LOCALE
1356 feat_def AMALGAMATION
1357 feat_def CROSS_BUILD
1358 feat_def DOCSTRINGS
1359 feat_def ERRORS
1361 feat_def ASAN_ADDRESS
1362 feat_def ASAN_MEMORY
1363 feat_def DEBUG
1364 feat_def DEVEL
1365 feat_def NYD2
1366 feat_def NOMEMDBG
1368 if xrun_check inline 'inline functions' \
1369 '#define HAVE_INLINE
1370 #define n_INLINE static inline' << \!
1371 static inline int ilf(int i){return ++i;}
1372 int main(void){return ilf(-1);}
1374 then
1376 elif xrun_check inline 'inline functions (via __inline)' \
1377 '#define HAVE_INLINE
1378 #define n_INLINE static __inline' << \!
1379 static __inline int ilf(int i){return ++i;}
1380 int main(void){return ilf(-1);}
1382 then
1386 ## Test for "basic" system-calls / functionality that is used by all parts
1387 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1388 ## macros to be used by only the subprograms (potentially).
1390 if run_check clock_gettime 'clock_gettime(2)' \
1391 '#define HAVE_CLOCK_GETTIME' << \!
1392 #include <time.h>
1393 # include <errno.h>
1394 int main(void){
1395 struct timespec ts;
1397 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1398 return 0;
1399 return 1;
1402 then
1404 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1405 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1406 #include <time.h>
1407 # include <errno.h>
1408 int main(void){
1409 struct timespec ts;
1411 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1412 return 0;
1413 return 1;
1416 then
1418 elif run_check gettimeofday 'gettimeofday(2)' \
1419 '#define HAVE_GETTIMEOFDAY' << \!
1420 #include <stdio.h> /* For C89 NULL */
1421 #include <sys/time.h>
1422 # include <errno.h>
1423 int main(void){
1424 struct timeval tv;
1426 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1427 return 0;
1428 return 1;
1431 then
1433 else
1434 have_no_subsecond_time=1
1437 if run_check nanosleep 'nanosleep(2)' \
1438 '#define HAVE_NANOSLEEP' << \!
1439 #include <time.h>
1440 # include <errno.h>
1441 int main(void){
1442 struct timespec ts;
1444 ts.tv_sec = 1;
1445 ts.tv_nsec = 100000;
1446 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1447 return 0;
1448 return 1;
1451 then
1453 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1454 '#define HAVE_NANOSLEEP' '-lrt' << \!
1455 #include <time.h>
1456 # include <errno.h>
1457 int main(void){
1458 struct timespec ts;
1460 ts.tv_sec = 1;
1461 ts.tv_nsec = 100000;
1462 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1463 return 0;
1464 return 1;
1467 then
1469 # link_check is enough for this, that function is so old, trust the proto
1470 elif link_check sleep 'sleep(3)' \
1471 '#define HAVE_SLEEP' << \!
1472 #include <unistd.h>
1473 # include <errno.h>
1474 int main(void){
1475 if(!sleep(1) || errno != ENOSYS)
1476 return 0;
1477 return 1;
1480 then
1482 else
1483 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1484 config_exit 1
1487 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1488 #include <pwd.h>
1489 #include <unistd.h>
1490 # include <errno.h>
1491 int main(void){
1492 struct passwd *pw;
1493 gid_t gid;
1494 uid_t uid;
1496 if((gid = getgid()) != 0)
1497 gid = getegid();
1498 if((uid = getuid()) != 0)
1499 uid = geteuid();
1500 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1501 return 1;
1502 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1503 return 1;
1504 return 0;
1507 then
1509 else
1510 msg 'ERROR: we require user and group info / database searches.'
1511 msg 'That much Unix we indulge ourselfs.'
1512 config_exit 1
1515 if link_check ftruncate 'ftruncate(2)' \
1516 '#define HAVE_FTRUNCATE' << \!
1517 #include <unistd.h>
1518 #include <sys/types.h>
1519 int main(void){
1520 return (ftruncate(0, 0) != 0);
1523 then
1525 else
1526 msg 'ERROR: we require the ftruncate(2) system call.'
1527 config_exit 1
1530 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1531 #include <signal.h>
1532 # include <errno.h>
1533 int main(void){
1534 struct sigaction nact, oact;
1536 nact.sa_handler = SIG_DFL;
1537 sigemptyset(&nact.sa_mask);
1538 nact.sa_flags = SA_RESTART;
1539 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1542 then
1544 else
1545 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1546 config_exit 1
1549 if link_check snprintf 'snprintf(3)' << \!
1550 #include <stdio.h>
1551 int main(void){
1552 char b[20];
1554 snprintf(b, sizeof b, "%s", "string");
1555 return 0;
1558 then
1560 else
1561 msg 'ERROR: we require the snprintf(3) function.'
1562 config_exit 1
1565 if link_check environ 'environ(3)' << \!
1566 #include <stdio.h> /* For C89 NULL */
1567 int main(void){
1568 extern char **environ;
1570 return environ[0] == NULL;
1573 then
1575 else
1576 msg 'ERROR: we require the environ(3) array for subprocess control.'
1577 config_exit 1
1580 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1581 #include <stdlib.h>
1582 int main(void){
1583 setenv("s-mailx", "i want to see it cute!", 1);
1584 unsetenv("s-mailx");
1585 return 0;
1588 then
1590 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1591 #include <stdlib.h>
1592 int main(void){
1593 putenv("s-mailx=i want to see it cute!");
1594 return 0;
1597 then
1599 else
1600 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1601 config_exit 1
1604 if link_check termios 'termios.h and tc*(3) family' << \!
1605 #include <termios.h>
1606 int main(void){
1607 struct termios tios;
1609 tcgetattr(0, &tios);
1610 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1611 return 0;
1614 then
1616 else
1617 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1618 msg 'That much Unix we indulge ourselfs.'
1619 config_exit 1
1622 ## optional stuff
1624 if link_check vsnprintf 'vsnprintf(3)' << \!
1625 #include <stdarg.h>
1626 #include <stdio.h>
1627 static void dome(char *buf, size_t blen, ...){
1628 va_list ap;
1630 va_start(ap, blen);
1631 vsnprintf(buf, blen, "%s", ap);
1632 va_end(ap);
1634 int main(void){
1635 char b[20];
1637 dome(b, sizeof b, "string");
1638 return 0;
1641 then
1643 else
1644 feat_bail_required ERRORS
1647 if [ "${have_vsnprintf}" = yes ]; then
1648 __va_copy() {
1649 link_check va_copy "va_copy(3) (as ${2})" \
1650 "#define HAVE_N_VA_COPY
1651 #define n_va_copy ${2}" <<_EOT
1652 #include <stdarg.h>
1653 #include <stdio.h>
1654 #if ${1}
1655 # if defined __va_copy && !defined va_copy
1656 # define va_copy __va_copy
1657 # endif
1658 #endif
1659 static void dome2(char *buf, size_t blen, va_list src){
1660 va_list ap;
1662 va_copy(ap, src);
1663 vsnprintf(buf, blen, "%s", ap);
1664 va_end(ap);
1666 static void dome(char *buf, size_t blen, ...){
1667 va_list ap;
1669 va_start(ap, blen);
1670 dome2(buf, blen, ap);
1671 va_end(ap);
1673 int main(void){
1674 char b[20];
1676 dome(b, sizeof b, "string");
1677 return 0;
1679 _EOT
1681 __va_copy 0 va_copy || __va_copy 1 __va_copy
1684 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1685 #include <unistd.h>
1686 #include <errno.h>
1687 int main(void){
1688 int rv = 0;
1690 errno = 0;
1691 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1692 errno = 0;
1693 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1695 /* Only link check */
1696 fpathconf(0, _PC_NAME_MAX);
1698 return rv;
1702 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1703 #include <fcntl.h>
1704 #include <unistd.h>
1705 # include <errno.h>
1706 int main(void){
1707 int fds[2];
1709 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1710 return 0;
1711 return 1;
1715 # We use this only then for now (need NOW+1)
1716 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1717 #include <fcntl.h> /* For AT_* */
1718 #include <sys/stat.h>
1719 # include <errno.h>
1720 int main(void){
1721 struct timespec ts[2];
1723 ts[0].tv_nsec = UTIME_NOW;
1724 ts[1].tv_nsec = UTIME_OMIT;
1725 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1726 return 0;
1727 return 1;
1733 # XXX Add POSIX check once standardized
1734 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1735 #include <stdlib.h>
1736 int main(void){
1737 arc4random();
1738 return 0;
1741 then
1743 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1744 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1745 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1746 #include <sys/random.h>
1747 int main(void){
1748 char buf[256];
1749 getrandom(buf, sizeof buf, 0);
1750 return 0;
1753 then
1755 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1756 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1757 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1758 #include <sys/syscall.h>
1759 int main(void){
1760 char buf[256];
1761 syscall(SYS_getrandom, buf, sizeof buf, 0);
1762 return 0;
1765 then
1767 elif [ -n "${have_no_subsecond_time}" ]; then
1768 msg 'ERROR: %s %s' 'without a native random' \
1769 'one of clock_gettime(2) and gettimeofday(2) is required.'
1770 config_exit 1
1774 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1775 #include <stdio.h>
1776 int main(void){
1777 putc_unlocked('@', stdout);
1778 return 0;
1782 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1783 #include <unistd.h>
1784 int main(void){
1785 fchdir(0);
1786 return 0;
1790 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1791 #include <stdlib.h>
1792 int main(void){
1793 char x_buf[4096], *x = realpath(".", x_buf);
1795 return (x != NULL) ? 0 : 1;
1798 then
1799 if run_check realpath_malloc 'realpath(3) takes NULL' \
1800 '#define HAVE_REALPATH_NULL' << \!
1801 #include <stdlib.h>
1802 int main(void){
1803 char *x = realpath(".", NULL);
1805 if(x != NULL)
1806 free(x);
1807 return (x != NULL) ? 0 : 1;
1810 then
1815 ## optional and selectable
1817 if feat_yes DOTLOCK; then
1818 if run_check readlink 'readlink(2)' << \!
1819 #include <unistd.h>
1820 # include <errno.h>
1821 int main(void){
1822 char buf[128];
1824 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1825 return 0;
1826 return 1;
1829 then
1831 else
1832 feat_bail_required DOTLOCK
1836 if feat_yes DOTLOCK; then
1837 if run_check fchown 'fchown(2)' << \!
1838 #include <unistd.h>
1839 # include <errno.h>
1840 int main(void){
1841 if(!fchown(0, 0, 0) || errno != ENOSYS)
1842 return 0;
1843 return 1;
1846 then
1848 else
1849 feat_bail_required DOTLOCK
1853 ## Now it is the time to fork away the BASE_ series
1855 ${rm} -f ${tmp}
1856 squeeze_em ${inc} ${tmp}
1857 ${mv} ${tmp} ${inc}
1858 squeeze_em ${lib} ${tmp}
1859 ${mv} ${tmp} ${lib}
1861 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1862 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1864 ## The remains are expected to be used only by the main MUA binary!
1866 OPT_LOCALES=0
1867 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1868 #include <locale.h>
1869 int main(void){
1870 setlocale(LC_ALL, "");
1871 return 0;
1874 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1876 OPT_MULTIBYTE_CHARSETS=0
1877 OPT_WIDE_GLYPHS=0
1878 OPT_TERMINAL_CHARSET=0
1879 if [ -n "${have_setlocale}" ]; then
1880 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1881 '#define HAVE_C90AMEND1' << \!
1882 #include <limits.h>
1883 #include <stdlib.h>
1884 #include <wchar.h>
1885 #include <wctype.h>
1886 int main(void){
1887 char mbb[MB_LEN_MAX + 1];
1888 wchar_t wc;
1890 iswprint(L'c');
1891 towupper(L'c');
1892 mbtowc(&wc, "x", 1);
1893 mbrtowc(&wc, "x", 1, NULL);
1894 wctomb(mbb, wc);
1895 return (mblen("\0", 1) == 0);
1898 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1900 if [ -n "${have_c90amend1}" ]; then
1901 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1902 #include <wchar.h>
1903 int main(void){
1904 wcwidth(L'c');
1905 return 0;
1908 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1911 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1912 #include <langinfo.h>
1913 #include <stdlib.h>
1914 int main(void){
1915 nl_langinfo(DAY_1);
1916 return (nl_langinfo(CODESET) == NULL);
1919 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1920 fi # have_setlocale
1922 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1923 #include <fnmatch.h>
1924 int main(void){
1925 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1929 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1930 #include <dirent.h>
1931 int main(void){
1932 struct dirent de;
1933 return !(de.d_type == DT_UNKNOWN ||
1934 de.d_type == DT_DIR || de.d_type == DT_LNK);
1938 ## optional and selectable
1940 if feat_yes ICONV; then
1941 ${cat} > ${tmp2}.c << \!
1942 #include <stdio.h> /* For C89 NULL */
1943 #include <iconv.h>
1944 int main(void){
1945 iconv_t id;
1947 id = iconv_open("foo", "bar");
1948 iconv(id, NULL, NULL, NULL, NULL);
1949 iconv_close(id);
1950 return 0;
1953 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1954 '#define HAVE_ICONV' ||
1955 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1956 '#define HAVE_ICONV' '-liconv' ||
1957 feat_bail_required ICONV
1958 else
1959 echo '/* OPT_ICONV=0 */' >> ${h}
1960 fi # feat_yes ICONV
1962 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1963 ${cat} > ${tmp2}.c << \!
1964 #include <sys/types.h>
1965 #include <sys/socket.h>
1966 #include <sys/un.h>
1967 # include <errno.h>
1968 int main(void){
1969 struct sockaddr_un soun;
1971 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1972 return 1;
1973 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1974 return 1;
1975 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1976 return 1;
1977 return 0;
1981 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1982 '#define HAVE_UNIX_SOCKETS' ||
1983 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1984 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1985 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1986 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1989 if feat_yes SOCKETS; then
1990 ${cat} > ${tmp2}.c << \!
1991 #include <sys/types.h>
1992 #include <sys/socket.h>
1993 #include <netinet/in.h>
1994 # include <errno.h>
1995 int main(void){
1996 struct sockaddr s;
1998 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1999 return 1;
2000 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
2001 return 1;
2002 return 0;
2006 < ${tmp2}.c run_check sockets 'sockets' \
2007 '#define HAVE_SOCKETS' ||
2008 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2009 '#define HAVE_SOCKETS' '-lnsl' ||
2010 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2011 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2012 feat_bail_required SOCKETS
2013 else
2014 echo '/* OPT_SOCKETS=0 */' >> ${h}
2015 fi # feat_yes SOCKETS
2017 if feat_yes SOCKETS; then
2018 link_check getaddrinfo 'getaddrinfo(3)' \
2019 '#define HAVE_GETADDRINFO' << \!
2020 #include <sys/types.h>
2021 #include <sys/socket.h>
2022 #include <stdio.h>
2023 #include <netdb.h>
2024 int main(void){
2025 struct addrinfo a, *ap;
2026 int lrv;
2028 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2029 case EAI_NONAME:
2030 case EAI_SERVICE:
2031 default:
2032 fprintf(stderr, "%s\n", gai_strerror(lrv));
2033 case 0:
2034 break;
2036 return 0;
2041 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2042 compile_check arpa_inet_h '<arpa/inet.h>' \
2043 '#define HAVE_ARPA_INET_H' << \!
2044 #include <sys/types.h>
2045 #include <sys/socket.h>
2046 #include <netdb.h>
2047 #include <netinet/in.h>
2048 #include <arpa/inet.h>
2051 ${cat} > ${tmp2}.c << \!
2052 #include <sys/types.h>
2053 #include <sys/socket.h>
2054 #include <stdio.h>
2055 #include <string.h>
2056 #include <netdb.h>
2057 #include <netinet/in.h>
2058 #ifdef HAVE_ARPA_INET_H
2059 #include <arpa/inet.h>
2060 #endif
2061 int main(void){
2062 struct sockaddr_in servaddr;
2063 unsigned short portno;
2064 struct servent *ep;
2065 struct hostent *hp;
2066 struct in_addr **pptr;
2068 portno = 0;
2069 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2070 portno = (unsigned short)ep->s_port;
2072 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2073 pptr = (struct in_addr**)hp->h_addr_list;
2074 if(hp->h_addrtype != AF_INET)
2075 fprintf(stderr, "au\n");
2076 }else{
2077 switch(h_errno){
2078 case HOST_NOT_FOUND:
2079 case TRY_AGAIN:
2080 case NO_RECOVERY:
2081 case NO_DATA:
2082 break;
2083 default:
2084 fprintf(stderr, "au\n");
2085 break;
2089 memset(&servaddr, 0, sizeof servaddr);
2090 servaddr.sin_family = AF_INET;
2091 servaddr.sin_port = htons(portno);
2092 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2093 fprintf(stderr, "Would connect to %s:%d ...\n",
2094 inet_ntoa(**pptr), (int)portno);
2095 return 0;
2099 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2100 < ${tmp2}.c link_check gethostbyname \
2101 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2102 < ${tmp2}.c link_check gethostbyname \
2103 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2104 '' '-lsocket -lnsl' ||
2105 feat_bail_required SOCKETS
2108 feat_yes SOCKETS &&
2109 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2110 #include <sys/socket.h>
2111 #include <stdlib.h>
2112 # include <errno.h>
2113 int main(void){
2114 int sockfd = 3;
2116 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2117 errno == ENOSYS)
2118 return 1;
2119 return 0;
2123 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2124 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2125 #include <sys/socket.h>
2126 #include <stdlib.h>
2127 int main(void){
2128 struct timeval tv;
2129 int sockfd = 3;
2131 tv.tv_sec = 42;
2132 tv.tv_usec = 21;
2133 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2134 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2135 return 0;
2139 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2140 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2141 #include <sys/socket.h>
2142 #include <stdlib.h>
2143 int main(void){
2144 struct linger li;
2145 int sockfd = 3;
2147 li.l_onoff = 1;
2148 li.l_linger = 42;
2149 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2150 return 0;
2154 VAL_SSL_FEATURES=
2155 if feat_yes SSL; then # {{{
2156 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2157 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2158 # time: we need to test it first in order to get things right
2159 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2160 '#define HAVE_SSL
2161 #define HAVE_XSSL
2162 #define HAVE_XSSL_RESSL
2163 #define HAVE_XSSL_OPENSSL 0' << \!
2164 #include <openssl/opensslv.h>
2165 #ifdef LIBRESSL_VERSION_NUMBER
2166 #else
2167 # error nope
2168 #endif
2170 then
2171 ossl_v1_1=
2172 VAL_SSL_FEATURES=libressl
2173 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2174 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2175 '#define HAVE_SSL
2176 #define HAVE_XSSL
2177 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2178 #include <openssl/opensslv.h>
2179 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2180 #else
2181 # error nope
2182 #endif
2184 then
2185 ossl_v1_1=1
2186 VAL_SSL_FEATURES=libssl-0x10100
2187 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2188 '#define HAVE_SSL
2189 #define HAVE_XSSL
2190 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2191 #include <openssl/opensslv.h>
2192 #ifdef OPENSSL_VERSION_NUMBER
2193 #else
2194 # error nope
2195 #endif
2197 then
2198 ossl_v1_1=
2199 VAL_SSL_FEATURES=libssl-0x10000
2200 else
2201 feat_bail_required SSL
2202 fi # }}}
2204 if feat_yes SSL; then # {{{
2205 if [ -n "${ossl_v1_1}" ]; then
2206 without_check yes xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2207 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2208 '-lssl -lcrypto'
2209 elif link_check xssl 'TLS/SSL new style TLS_client_method(3ssl)' \
2210 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2211 '-lssl -lcrypto' << \!
2212 #include <openssl/ssl.h>
2213 #include <openssl/err.h>
2214 #include <openssl/x509v3.h>
2215 #include <openssl/x509.h>
2216 #include <openssl/rand.h>
2217 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2218 # error We need TLSv1.
2219 #endif
2220 int main(void){
2221 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2223 SSL_CTX_free(ctx);
2224 PEM_read_PrivateKey(0, 0, 0, 0);
2225 return 0;
2228 then
2230 elif link_check xssl 'TLS/SSL old style SSLv23_client_method(3ssl)' \
2231 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2232 '-lssl -lcrypto' << \!
2233 #include <openssl/ssl.h>
2234 #include <openssl/err.h>
2235 #include <openssl/x509v3.h>
2236 #include <openssl/x509.h>
2237 #include <openssl/rand.h>
2238 #if defined OPENSSL_NO_SSL3 &&\
2239 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2240 # error We need one of SSLv3 and TLSv1.
2241 #endif
2242 int main(void){
2243 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2245 SSL_CTX_free(ctx);
2246 PEM_read_PrivateKey(0, 0, 0, 0);
2247 return 0;
2250 then
2252 else
2253 feat_bail_required SSL
2255 fi # }}}
2257 if feat_yes SSL; then # {{{
2258 if feat_yes SSL_ALL_ALGORITHMS; then
2259 if [ -n "${ossl_v1_1}" ]; then
2260 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2261 '#define HAVE_SSL_ALL_ALGORITHMS'
2262 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2263 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2264 #include <openssl/evp.h>
2265 int main(void){
2266 OpenSSL_add_all_algorithms();
2267 EVP_get_cipherbyname("two cents i never exist");
2268 EVP_cleanup();
2269 return 0;
2272 then
2274 else
2275 feat_bail_required SSL_ALL_ALGORITHMS
2277 elif [ -n "${ossl_v1_1}" ]; then
2278 without_check yes ssl_all_algo \
2279 'TLS/SSL all-algorithms (always available in v1.1.0+)' \
2280 '#define HAVE_SSL_ALL_ALGORITHMS'
2283 if [ -n "${ossl_v1_1}" ]; then
2284 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2285 '#define HAVE_XSSL_STACK_OF'
2286 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2287 '#define HAVE_XSSL_STACK_OF' << \!
2288 #include <stdio.h> /* For C89 NULL */
2289 #include <openssl/ssl.h>
2290 #include <openssl/err.h>
2291 #include <openssl/x509v3.h>
2292 #include <openssl/x509.h>
2293 #include <openssl/rand.h>
2294 int main(void){
2295 STACK_OF(GENERAL_NAME) *gens = NULL;
2297 printf("%p", gens); /* to use it */
2298 return 0;
2301 then
2305 if [ -n "${ossl_v1_1}" ]; then
2306 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file(3ssl)' \
2307 '#define HAVE_XSSL_CONFIG'
2308 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2309 elif link_check xssl_conf \
2310 'TLS/SSL OpenSSL_modules_load_file(3ssl) support' \
2311 '#define HAVE_XSSL_CONFIG' << \!
2312 #include <stdio.h> /* For C89 NULL */
2313 #include <openssl/conf.h>
2314 int main(void){
2315 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2316 CONF_modules_free();
2317 return 0;
2320 then
2321 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+modules-load-file"
2322 else
2323 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-modules-load-file"
2326 if [ -n "${ossl_v1_1}" ]; then
2327 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2328 '#define HAVE_XSSL_CONF_CTX'
2329 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2330 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2331 '#define HAVE_XSSL_CONF_CTX' << \!
2332 #include <openssl/ssl.h>
2333 #include <openssl/err.h>
2334 int main(void){
2335 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2336 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2338 SSL_CONF_CTX_set_flags(cctx,
2339 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2340 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2341 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2342 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2343 SSL_CONF_CTX_finish(cctx);
2344 SSL_CONF_CTX_free(cctx);
2345 SSL_CTX_free(ctx);
2346 return 0;
2349 then
2350 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+conf-ctx"
2351 else
2352 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-conf-ctx"
2355 if [ -n "${ossl_v1_1}" ]; then
2356 without_check yes xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2357 '#define HAVE_XSSL_CTX_CONFIG'
2358 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2359 elif [ -n "${have_xssl_conf}" ] && [ -n "${have_xssl_conf_ctx}" ] &&
2360 link_check xssl_ctx_config 'TLS/SSL SSL_CTX_config(3ssl)' \
2361 '#define HAVE_XSSL_CTX_CONFIG' << \!
2362 #include <stdio.h> /* For C89 NULL */
2363 #include <openssl/ssl.h>
2364 int main(void){
2365 SSL_CTX_config(NULL, "SOMEVAL");
2366 return 0;
2369 then
2370 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-config"
2371 else
2372 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-config"
2375 if [ -n "${ossl_v1_1}" ] && [ -n "${have_xssl_conf_ctx}" ]; then
2376 without_check yes xssl_set_maxmin_proto \
2377 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2378 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION'
2379 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2380 elif link_check xssl_set_maxmin_proto \
2381 'TLS/SSL SSL_CTX_set_min_proto_version(3ssl)' \
2382 '#define HAVE_XSSL_SET_MIN_PROTO_VERSION' << \!
2383 #include <stdio.h> /* For C89 NULL */
2384 #include <openssl/ssl.h>
2385 int main(void){
2386 SSL_CTX_set_min_proto_version(NULL, 0);
2387 SSL_CTX_set_max_proto_version(NULL, 10);
2388 return 0;
2391 then
2392 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+ctx-set-maxmin-proto"
2393 else
2394 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-ctx-set-maxmin-proto"
2397 if link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2398 '#define HAVE_XSSL_RAND_EGD' << \!
2399 #include <openssl/rand.h>
2400 int main(void){
2401 return RAND_egd("some.where") > 0;
2404 then
2405 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},+rand-egd"
2406 else
2407 VAL_SSL_FEATURES="${VAL_SSL_FEATURES},-rand-egd"
2409 fi # feat_yes SSL }}}
2411 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2412 run_check ssl_md5 'MD5 digest in the used crypto library' \
2413 '#define HAVE_XSSL_MD5' << \!
2414 #include <stdlib.h>
2415 #include <string.h>
2416 #include <openssl/md5.h>
2417 int main(void){
2418 char const dat[] = "abrakadabrafidibus";
2419 char dig[16], hex[16 * 2];
2420 MD5_CTX ctx;
2421 size_t i, j;
2423 memset(dig, 0, sizeof(dig));
2424 memset(hex, 0, sizeof(hex));
2425 MD5_Init(&ctx);
2426 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2427 MD5_Final(dig, &ctx);
2429 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2430 for(i = 0; i < sizeof(hex) / 2; i++){
2431 j = i << 1;
2432 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2433 hex[++j] = hexchar(dig[i] & 0x0f);
2435 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2438 fi # }}}
2439 else
2440 echo '/* OPT_SSL=0 */' >> ${h}
2441 fi # }}} feat_yes SSL
2442 printf '#define VAL_SSL_FEATURES "#'"${VAL_SSL_FEATURES}"'"\n' >> ${h}
2444 if [ "${have_xssl}" = yes ]; then
2445 OPT_SMIME=1
2446 else
2447 OPT_SMIME=0
2449 feat_def SMIME
2451 feat_def SMTP
2452 feat_def POP3
2453 feat_def IMAP
2455 if feat_yes GSSAPI; then
2456 ${cat} > ${tmp2}.c << \!
2457 #include <gssapi/gssapi.h>
2458 int main(void){
2459 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2460 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2461 return 0;
2464 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2466 if acmd_set i krb5-config; then
2467 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2468 GSS_INCS="`CFLAGS= ${i} --cflags`"
2469 i='GSS-API via krb5-config(1)'
2470 else
2471 GSS_LIBS='-lgssapi'
2472 GSS_INCS=
2473 i='GSS-API in gssapi/gssapi.h, libgssapi'
2475 if < ${tmp2}.c link_check gss \
2476 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2477 < ${tmp3}.c link_check gss \
2478 'GSS-API in gssapi.h, libgssapi' \
2479 '#define HAVE_GSSAPI
2480 #define GSSAPI_REG_INCLUDE' \
2481 '-lgssapi' ||\
2482 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2483 '#define HAVE_GSSAPI' \
2484 '-lgssapi_krb5' ||\
2485 < ${tmp3}.c link_check gss \
2486 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2487 '#define HAVE_GSSAPI
2488 #define GSS_REG_INCLUDE' \
2489 '-lgssapi -lkrb5 -lcrypto' \
2490 '-I/usr/include/kerberosV' ||\
2491 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2492 '#define HAVE_GSSAPI' \
2493 '-lgss' ||\
2494 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2495 '#define HAVE_GSSAPI
2496 #define GSSAPI_OLD_STYLE' \
2497 '-lgssapi_krb5' << \!
2498 #include <gssapi/gssapi.h>
2499 #include <gssapi/gssapi_generic.h>
2500 int main(void){
2501 gss_import_name(0, 0, gss_nt_service_name, 0);
2502 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2503 return 0;
2506 then
2508 else
2509 feat_bail_required GSSAPI
2511 else
2512 echo '/* OPT_GSSAPI=0 */' >> ${h}
2513 fi # feat_yes GSSAPI
2515 feat_def NETRC
2516 feat_def AGENT
2518 if feat_yes IDNA; then
2519 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2520 '-lidn' << \!
2521 #include <idna.h>
2522 #include <idn-free.h>
2523 #include <stringprep.h>
2524 int main(void){
2525 char *utf8, *idna_ascii, *idna_utf8;
2527 utf8 = stringprep_locale_to_utf8("does.this.work");
2528 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2529 != IDNA_SUCCESS)
2530 return 1;
2531 idn_free(idna_ascii);
2532 /* (Rather link check only here) */
2533 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2534 return 0;
2537 then
2539 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2540 '-lidnkit' << \!
2541 #include <stdio.h>
2542 #include <idn/api.h>
2543 #include <idn/result.h>
2544 int main(void){
2545 idn_result_t r;
2546 char ace_name[256];
2547 char local_name[256];
2549 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2550 sizeof(ace_name));
2551 if (r != idn_success) {
2552 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2553 return 1;
2555 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2556 if (r != idn_success) {
2557 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2558 return 1;
2560 return 0;
2563 then
2565 else
2566 feat_bail_required IDNA
2569 if [ -n "${have_idna}" ]; then
2570 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2571 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2573 else
2574 echo '/* OPT_IDNA=0 */' >> ${h}
2577 feat_def IMAP_SEARCH
2579 if feat_yes REGEX; then
2580 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2581 #include <regex.h>
2582 #include <stdlib.h>
2583 int main(void){
2584 size_t xret;
2585 int status;
2586 regex_t re;
2588 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2589 xret = regerror(status, &re, NULL, 0);
2590 status = regexec(&re, "plan9", 0,NULL, 0);
2591 regfree(&re);
2592 return !(status == REG_NOMATCH);
2595 then
2597 else
2598 feat_bail_required REGEX
2600 else
2601 echo '/* OPT_REGEX=0 */' >> ${h}
2604 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2605 have_mle=1
2606 echo '#define HAVE_MLE' >> ${h}
2607 else
2608 feat_bail_required MLE
2609 echo '/* OPT_MLE=0 */' >> ${h}
2612 # Generic have-a-line-editor switch for those who need it below
2613 if [ -n "${have_mle}" ]; then
2614 have_cle=1
2617 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2618 echo '#define HAVE_HISTORY' >> ${h}
2619 else
2620 echo '/* OPT_HISTORY=0 */' >> ${h}
2623 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2624 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2625 else
2626 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2629 if feat_yes TERMCAP; then
2630 __termcaplib() {
2631 link_check termcap "termcap(5) (via ${4})" \
2632 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2633 #include <stdio.h>
2634 #include <stdlib.h>
2635 ${2}
2636 #include <term.h>
2637 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2638 static int my_putc(int c){return putchar(c);}
2639 int main(void){
2640 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2641 int r2 = OK, r3 = ERR;
2643 tgetent(buf, getenv("TERM"));
2644 cpb = cmdbuf;
2645 r1 = tgetstr(UNCONST("cm"), &cpb);
2646 tgoto(r1, 1, 1);
2647 r2 = tgetnum(UNCONST("Co"));
2648 r3 = tgetflag(UNCONST("ut"));
2649 tputs("cr", 1, &my_putc);
2650 return (r1 == NULL || r2 == -1 || r3 == 0);
2652 _EOT
2655 __terminfolib() {
2656 link_check terminfo "terminfo(5) (via ${2})" \
2657 '#define HAVE_TERMCAP
2658 #define HAVE_TERMCAP_CURSES
2659 #define HAVE_TERMINFO' "${1}" << _EOT
2660 #include <stdio.h>
2661 #include <curses.h>
2662 #include <term.h>
2663 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2664 static int my_putc(int c){return putchar(c);}
2665 int main(void){
2666 int er, r0, r1, r2;
2667 char *r3, *tp;
2669 er = OK;
2670 r0 = setupterm(NULL, 1, &er);
2671 r1 = tigetflag(UNCONST("bce"));
2672 r2 = tigetnum(UNCONST("colors"));
2673 r3 = tigetstr(UNCONST("cr"));
2674 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2675 tputs(tp, 1, &my_putc);
2676 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2677 r3 == (char*)-1 || r3 == NULL);
2679 _EOT
2682 if feat_yes TERMCAP_VIA_TERMINFO; then
2683 __terminfolib -ltinfo -ltinfo ||
2684 __terminfolib -lcurses -lcurses ||
2685 __terminfolib -lcursesw -lcursesw ||
2686 feat_bail_required TERMCAP_VIA_TERMINFO
2689 if [ -z "${have_terminfo}" ]; then
2690 __termcaplib -ltermcap '' '' '-ltermcap' ||
2691 __termcaplib -ltermcap '#include <curses.h>' '
2692 #define HAVE_TERMCAP_CURSES' \
2693 'curses.h / -ltermcap' ||
2694 __termcaplib -lcurses '#include <curses.h>' '
2695 #define HAVE_TERMCAP_CURSES' \
2696 'curses.h / -lcurses' ||
2697 __termcaplib -lcursesw '#include <curses.h>' '
2698 #define HAVE_TERMCAP_CURSES' \
2699 'curses.h / -lcursesw' ||
2700 feat_bail_required TERMCAP
2702 if [ -n "${have_termcap}" ]; then
2703 run_check tgetent_null \
2704 "tgetent(3) of termcap(5) takes NULL buffer" \
2705 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2706 #include <stdio.h> /* For C89 NULL */
2707 #include <stdlib.h>
2708 #ifdef HAVE_TERMCAP_CURSES
2709 # include <curses.h>
2710 #endif
2711 #include <term.h>
2712 int main(void){
2713 tgetent(NULL, getenv("TERM"));
2714 return 0;
2716 _EOT
2719 else
2720 echo '/* OPT_TERMCAP=0 */' >> ${h}
2721 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2724 if feat_def SPAM_SPAMC; then
2725 if acmd_set i spamc; then
2726 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2730 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2731 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2732 else
2733 feat_bail_required SPAM_SPAMD
2734 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2737 feat_def SPAM_FILTER
2739 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2740 echo '#define HAVE_SPAM' >> ${h}
2741 else
2742 echo '/* HAVE_SPAM */' >> ${h}
2745 if feat_yes QUOTE_FOLD &&\
2746 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2747 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2748 else
2749 feat_bail_required QUOTE_FOLD
2750 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2753 feat_def FILTER_HTML_TAGSOUP
2754 feat_def COLOUR
2755 feat_def DOTLOCK
2756 feat_def MD5
2757 feat_def NOMEMDBG
2759 ## Summarizing
2761 ${rm} -f ${tmp}
2762 squeeze_em ${inc} ${tmp}
2763 ${mv} ${tmp} ${inc}
2764 squeeze_em ${lib} ${tmp}
2765 ${mv} ${tmp} ${lib}
2767 # mk-config.h
2768 ${mv} ${h} ${tmp}
2769 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2770 ${cat} ${tmp} >> ${h}
2771 ${rm} -f ${tmp}
2772 printf '\n' >> ${h}
2774 # Create the string that is used by *features* and `version'.
2775 # Take this nice opportunity and generate a visual listing of included and
2776 # non-included features for the person who runs the configuration
2777 msg '\nThe following features are included (+) or not (-):'
2778 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2779 printf '/* The "feature string" */\n' >> ${h}
2780 # Because + is expanded by *folder* if first in "echo $features", put something
2781 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2782 sep=
2783 for opt
2785 sdoc=`option_doc_of ${opt}`
2786 [ -z "${sdoc}" ] && continue
2787 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2788 feat_yes ${opt} && sign=+ || sign=-
2789 printf -- "${sep}${sign}${sopt}" >> ${h}
2790 sep=','
2791 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2792 done
2793 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2794 #exec 5>&1 >>${h}
2795 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2796 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2797 printf '"\n' >> ${h}
2799 # Create the real mk-config.mk
2800 # Note we cannout use explicit ./ filename prefix for source and object
2801 # pathnames because of a bug in bmake(1)
2802 ${rm} -rf ${tmp0}.* ${tmp0}*
2803 srclist= objlist=
2804 if feat_no AMALGAMATION; then
2805 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2806 i=`basename "${i}" .c`
2807 if [ "${i}" = privsep ]; then
2808 continue
2810 objlist="${objlist} ${i}.o"
2811 srclist="${srclist} \$(SRCDIR)${i}.c"
2812 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2813 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2814 done
2815 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2816 else
2817 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2818 "main.o" "main.c" >> ${mk}
2819 srclist=main.c objlist=main.o
2820 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2822 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2823 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2824 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2825 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2826 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2827 i=`basename "${i}"`
2828 if [ "${i}" = main.c ] ||
2829 [ "${i}" = privsep.c ]; then
2830 continue
2832 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2833 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
2834 done
2835 echo >> ${mk}
2837 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2839 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2841 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2842 echo "INCS = `${cat} ${inc}`" >> ${mk}
2843 echo >> ${mk}
2844 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2846 ## Finished!
2848 msg '\nSetup:'
2849 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2850 msg ' . bindir: %s' "${VAL_BINDIR}"
2851 if feat_yes DOTLOCK; then
2852 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2854 msg ' . mandir: %s' "${VAL_MANDIR}"
2855 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2856 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2857 msg ''
2859 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2860 exit 0
2862 msg 'Remarks:'
2863 if [ -z "${have_fnmatch}" ]; then
2864 msg ' . The function fnmatch(3) could not be found.'
2865 msg ' Filename patterns like wildcard are not supported on your system'
2867 if [ -z "${have_fchdir}" ]; then
2868 msg ' . The function fchdir(2) could not be found.'
2869 msg ' We will use chdir(2) instead.'
2870 msg ' This is a problem only if the current working directory is changed'
2871 msg ' while this program is inside of it'
2873 msg ''
2875 # s-it-mode