Many: truly support out-of-tree compilation
[s-mailx.git] / make-config.sh
blob6276fdc721f9df96a798be3c2bf0e94186305fe5
1 #!/bin/sh -
2 #@ Please see INSTALL and make.rc instead.
4 LC_ALL=C
5 export LC_ALL
7 [ -n "${SHELL}" ] || SHELL=/bin/sh
8 export SHELL
10 # The feature set, to be kept in sync with make.rc
11 # If no documentation given, the option is used as such; if doc is a hyphen,
12 # entry is suppressed when configuration overview is printed, and also in the
13 # *features* string: most likely for obsolete features etc.
14 XOPTIONS="\
15 ICONV='Character set conversion using iconv(3)' \
16 SOCKETS='Network support' \
17 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
18 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
19 SMTP='Simple Mail Transfer Protocol client' \
20 POP3='Post Office Protocol Version 3 client' \
21 IMAP='IMAP v4r1 client' \
22 GSSAPI='Generic Security Service authentication' \
23 NETRC='.netrc file support' \
24 AGENT='-' \
25 MD5='MD5 message digest (APOP, CRAM-MD5)' \
26 IDNA='Internationalized Domain Names for Applications (encode only)' \
27 IMAP_SEARCH='IMAP-style search expressions' \
28 REGEX='Regular expressions' \
29 MLE='Mailx Line Editor' \
30 HISTORY='Line editor history management' \
31 KEY_BINDINGS='Configurable key bindings' \
32 TERMCAP='Terminal capability queries (termcap(5))' \
33 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
34 ERRORS='Error log message ring' \
35 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
36 SPAM_SPAMD='-' \
37 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
38 DOCSTRINGS='Command documentation help strings' \
39 QUOTE_FOLD='Extended *quote-fold*ing' \
40 FILTER_HTML_TAGSOUP='Simple built-in HTML-to-text display filter' \
41 COLOUR='Coloured message display' \
42 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
45 # Options which are automatically deduced from host environment, i.e., these
46 # need special treatment all around here to warp from/to OPT_ stuff
47 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
48 XOPTIONS_DETECT="\
49 LOCALES='Locale support - printable characters etc. depend on environment' \
50 MULTIBYTE_CHARSETS='Multibyte character sets' \
51 TERMINAL_CHARSET='Automatic detection of terminal character set' \
52 WIDE_GLYPHS='Wide glyph support' \
55 # Rather special options, for custom building, or which always exist.
56 # Mostly for generating the visual overview and the *features* string
57 XOPTIONS_XTRA="\
58 MIME='Multipurpose Internet Mail Extensions' \
59 SMIME='S/MIME message signing, verification, en- and decryption' \
60 CROSS_BUILD='Cross-compilation: trust any detected environment' \
61 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
62 DEVEL='Computers do not blunder' \
65 # The problem is that we don't have any tools we can use right now, so
66 # encapsulate stuff in functions which get called in right order later on
68 option_reset() {
69 set -- ${OPTIONS}
70 for i
72 eval OPT_${i}=0
73 done
76 option_maximal() {
77 set -- ${OPTIONS}
78 for i
80 eval OPT_${i}=1
81 done
82 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
85 option_setup() {
86 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
87 option_parse OPTIONS "${XOPTIONS}"
88 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
89 OPT_MIME=1
91 # Predefined CONFIG= urations take precedence over anything else
92 if [ -n "${CONFIG}" ]; then
93 option_reset
94 case "${CONFIG}" in
95 [nN][uU][lL][lL])
97 [nN][uU][lL][lL][iI])
98 OPT_ICONV=require
100 [mM][iI][nN][iI][mM][aA][lL])
101 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
102 OPT_COLOUR=1
103 OPT_DOCSTRINGS=1
104 OPT_ERRORS=1
105 OPT_IDNA=1
106 OPT_MLE=1
107 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
108 OPT_SPAM_FILTER=1
110 [nN][eE][tT][sS][eE][nN][dD])
111 OPT_DOTLOCK=require OPT_ICONV=require OPT_REGEX=require
112 OPT_SOCKETS=require
113 OPT_SSL=require
114 OPT_SMTP=require
115 OPT_GSSAPI=1 OPT_NETRC=1
116 OPT_AGENT=1
117 OPT_COLOUR=1
118 OPT_DOCSTRINGS=1
119 OPT_ERRORS=1
120 OPT_IDNA=1
121 OPT_MLE=1
122 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
123 OPT_SPAM_FILTER=1
125 [mM][aA][xX][iI][mM][aA][lL])
126 option_maximal
128 [dD][eE][vV][eE][lL])
129 option_maximal
130 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
132 [oO][dD][eE][vV][eE][lL])
133 option_maximal
134 OPT_DEVEL=1
137 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
138 echo >&2 ' NULL, NULLI, MINIMAL, NETSEND, MAXIMAL'
139 exit 1
141 esac
142 msg_nonl "CONFIG=${CONFIG} ... "
146 # Inter-relationships
147 option_update() {
148 if feat_no SMTP && feat_no POP3 && feat_no IMAP; then
149 OPT_SOCKETS=0
151 if feat_no SOCKETS; then
152 if feat_require SMTP; then
153 msg 'ERROR: need SOCKETS for required feature SMTP'
154 config_exit 13
156 if feat_require POP3; then
157 msg 'ERROR: need SOCKETS for required feature POP3'
158 config_exit 13
160 if feat_require IMAP; then
161 msg 'ERROR: need SOCKETS for required feature IMAP'
162 config_exit 13
164 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
165 OPT_SMTP=0 OPT_POP3=0 OPT_IMAP=0
166 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
168 if feat_no SMTP && feat_no IMAP; then
169 OPT_GSSAPI=0
172 if feat_no ICONV; then
173 if feat_yes IMAP; then
174 if feat_require IMAP; then
175 msg 'ERROR: need ICONV for required feature IMAP'
176 config_exit 13
178 msg 'ERROR: disabling IMAP due to missing ICONV'
179 OPT_IMAP=0
182 if feat_yes IDNA; then
183 if feat_require IDNA; then
184 msg 'ERROR: need ICONV for required feature IDNA'
185 config_exit 13
187 msg 'ERROR: disabling IDNA due to missing ICONV'
188 OPT_IDNA=0
192 if feat_no MLE; then
193 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
196 # If we don't need MD5 leave it alone
197 if feat_no SOCKETS; then
198 OPT_MD5=0
201 if feat_no TERMCAP; then
202 OPT_TERMCAP_VIA_TERMINFO=0
205 if feat_yes DEVEL; then
206 OPT_DEBUG=1
210 rc=./make.rc
211 lst=./mk-config.lst
212 ev=./mk-config.ev
213 h=./mk-config.h h_name=mk-config.h
214 mk=./mk-config.mk
216 newlst=./mk-nconfig.lst
217 newmk=./mk-nconfig.mk
218 newev=./mk-nconfig.ev
219 newh=./mk-nconfig.h
220 tmp0=___tmp
221 tmp=./${tmp0}1$$
222 tmp2=./${tmp0}2$$
224 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
226 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
227 # via path_check() later on once possible
229 # TODO cc_maxopt is brute simple, we should compile test program and dig real
230 # compiler versions for known compilers, then be more specific
231 [ -n "${cc_maxopt}" ] || cc_maxopt=100
232 _CFLAGS= _LDFLAGS=
234 os_early_setup() {
235 # We don't "have any utility": only path adjustments and such in here!
236 [ -n "${OS}" ] || OS=`uname -s`
237 export OS
239 if [ ${OS} = SunOS ]; then
240 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
241 _os_early_setup_sunos
245 _os_early_setup_sunos() {
246 # According to standards(5), this is what we need to do
247 if [ -d /usr/xpg4 ]; then :; else
248 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
249 config_exit 1
251 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
252 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
253 export PATH
256 os_setup() {
257 # OSENV ends up in *build-osenv*
258 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
259 OS=`echo ${OS} | ${tr} '[A-Z]' '[a-z]'`
260 [ -n "${OSENV}" ] || OSENV=`uname -srm`
261 [ -n "${OSFULLSPEC}" ] || OSFULLSPEC=`uname -a`
262 msg 'Operating system is %s' ${OS}
264 if [ ${OS} = darwin ]; then
265 msg ' . have special Darwin environmental addons...'
266 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${DYLD_LIBRARY_PATH}
267 elif [ ${OS} = sunos ]; then
268 msg ' . have special SunOS / Solaris "setup" rules ...'
269 _os_setup_sunos
270 elif [ ${OS} = unixware ]; then
271 if feat_yes AUTOCC && acmd_set CC cc; then
272 msg ' . have special UnixWare environmental rules ...'
273 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
275 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
276 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
277 export CC CFLAGS LDFLAGS
278 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
280 elif [ -n "${VERBOSE}" ]; then
281 msg ' . no special treatment for this system necessary or known'
284 # Sledgehammer: better set _GNU_SOURCE
285 # And in general: oh, boy!
286 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
287 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
288 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
289 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
291 # On pkgsrc(7) systems automatically add /usr/pkg/*
292 if [ -d /usr/pkg ]; then
293 C_INCLUDE_PATH=/usr/pkg/include:${C_INCLUDE_PATH}
294 LD_LIBRARY_PATH=/usr/pkg/lib:${LD_LIBRARY_PATH}
298 _os_setup_sunos() {
299 C_INCLUDE_PATH=/usr/xpg4/include:${C_INCLUDE_PATH}
300 LD_LIBRARY_PATH=/usr/xpg4/lib:${LD_LIBRARY_PATH}
302 # Include packages
303 if [ -d /opt/csw ]; then
304 C_INCLUDE_PATH=/opt/csw/include:${C_INCLUDE_PATH}
305 LD_LIBRARY_PATH=/opt/csw/lib:${LD_LIBRARY_PATH}
308 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
309 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
311 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
312 if [ -x "${cksum}" ]; then :; else
313 msg 'ERROR: Not an executable program: %s' "${cksum}"
314 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
315 msg 'ERROR: However, we do so only for tests.'
316 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
317 config_exit 1
320 if feat_yes AUTOCC; then
321 if acmd_set CC cc; then
322 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
324 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
325 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
326 export CC CFLAGS LDFLAGS
327 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
328 else
329 # Assume gcc(1), which supports -R for compat
330 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
335 # Check out compiler ($CC) and -flags ($CFLAGS)
336 cc_setup() {
337 # Even though it belongs into cc_flags we will try to compile and link
338 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
339 # EXTRA_CFLAGS/EXTRA_LDFLAGS
340 if feat_no AUTOCC; then
341 _cc_default
342 # Ensure those don't do any harm
343 EXTRA_CFLAGS= EXTRA_LDFLAGS=
344 export EXTRA_CFLAGS EXTRA_LDFLAGS
345 return
346 else
347 CFLAGS= LDFLAGS=
348 export CFLAGS LDFLAGS
351 [ -n "${CC}" ] && { _cc_default; return; }
353 msg_nonl 'Searching for a usable C compiler .. $CC='
354 if acmd_set CC clang || acmd_set CC gcc ||
355 acmd_set CC tcc || acmd_set CC pcc ||
356 acmd_set CC c89 || acmd_set CC c99; then
358 else
359 msg 'boing booom tschak'
360 msg 'ERROR: I cannot find a compiler!'
361 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
362 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
363 config_exit 1
365 msg '%s' "${CC}"
366 export CC
369 _cc_default() {
370 if [ -z "${CC}" ]; then
371 msg 'To go on like you have chosen, please set $CC, rerun.'
372 config_exit 1
375 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
377 else
378 msg 'Using C compiler ${CC}=%s' "${CC}"
382 cc_flags() {
383 if feat_yes AUTOCC; then
384 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
385 cc_check_silent=1
386 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
387 "${CC}"
388 else
389 cc_check_silent=
390 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
393 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
394 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
395 msg ' . have special tcc(1) environmental rules ...'
396 _cc_flags_tcc
397 else
398 # As of pcc CVS 2016-04-02, stack protection support is announced but
399 # will break if used on Linux
400 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
401 force_no_stackprot=1
403 _cc_flags_generic
406 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
407 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
408 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
409 else
410 if feat_no DEBUG; then
411 CFLAGS="-DNDEBUG ${CFLAGS}"
414 msg ''
415 export CFLAGS LDFLAGS
418 _cc_flags_tcc() {
419 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
420 _CFLAGS= _LDFLAGS=
422 cc_check -Wall
423 cc_check -Wextra
424 cc_check -pedantic
426 if feat_yes DEBUG; then
427 # May have problems to find libtcc cc_check -b
428 cc_check -g
431 if ld_check -Wl,-rpath =./ no; then
432 need_R_ldflags=-Wl,-rpath=
433 ld_check -Wl,--enable-new-dtags
434 ld_runtime_flags # update!
437 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
438 unset __cflags __ldflags
441 _cc_flags_generic() {
442 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
443 _CFLAGS= _LDFLAGS=
444 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
446 # E.g., valgrind does not work well with high optimization
447 if [ ${cc_maxopt} -gt 1 ] && feat_yes NOMEMDBG &&
448 feat_no ASAN_ADDRESS && feat_no ASAN_MEMORY; then
449 msg 'OP_NOMEMDBG, setting cc_maxopt=1 (-O1)'
450 cc_maxopt=1
452 # Check -g first since some others may rely upon -g / optim. level
453 if feat_yes DEBUG; then
454 cc_check -O
455 cc_check -g
456 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
458 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
460 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
462 else
463 cc_check -O
466 if feat_yes AMALGAMATION; then
467 cc_check -pipe
470 #if feat_yes DEVEL && cc_check -Weverything; then
472 #else
473 cc_check -Wall
474 cc_check -Wextra
475 cc_check -Wbad-function-cast
476 cc_check -Wcast-align
477 cc_check -Wcast-qual
478 cc_check -Winit-self
479 cc_check -Wmissing-prototypes
480 cc_check -Wshadow
481 cc_check -Wunused
482 cc_check -Wwrite-strings
483 cc_check -Wno-long-long
485 cc_check -pedantic
487 if feat_yes AMALGAMATION && feat_no DEVEL; then
488 cc_check -Wno-unused-function
490 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
492 cc_check -fno-unwind-tables
493 cc_check -fno-asynchronous-unwind-tables
494 cc_check -fstrict-aliasing
495 if cc_check -fstrict-overflow && feat_yes DEVEL; then
496 cc_check -Wstrict-overflow=5
499 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
500 if [ -z "${force_no_stackprot}" ]; then
501 if cc_check -fstack-protector-strong ||
502 cc_check -fstack-protector-all; then
503 cc_check -D_FORTIFY_SOURCE=2
505 else
506 msg 'Not checking for -fstack-protector compiler option,'
507 msg 'since that caused errors in a "similar" configuration.'
508 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
512 # LD (+ dependend CC)
514 if feat_yes ASAN_ADDRESS; then
515 _ccfg=${_CFLAGS}
516 if cc_check -fsanitize=address &&
517 ld_check -fsanitize=address; then
519 else
520 feat_bail_required ASAN_ADDRESS
521 _CFLAGS=${_ccfg}
525 if feat_yes ASAN_MEMORY; then
526 _ccfg=${_CFLAGS}
527 if cc_check -fsanitize=memory &&
528 ld_check -fsanitize=memory &&
529 cc_check -fsanitize-memory-track-origins=2 &&
530 ld_check -fsanitize-memory-track-origins=2; then
532 else
533 feat_bail_required ASAN_MEMORY
534 _CFLAGS=${_ccfg}
538 ld_check -Wl,-z,relro
539 ld_check -Wl,-z,now
540 ld_check -Wl,-z,noexecstack
541 if ld_check -Wl,-rpath =./ no; then
542 need_R_ldflags=-Wl,-rpath=
543 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
544 ld_check -Wl,--enable-new-dtags
545 ld_runtime_flags # update!
546 elif ld_check -Wl,-R ./ no; then
547 need_R_ldflags=-Wl,-R
548 ld_check -Wl,--enable-new-dtags
549 ld_runtime_flags # update!
552 # Address randomization
553 _ccfg=${_CFLAGS}
554 if cc_check -fPIE || cc_check -fpie; then
555 ld_check -pie || _CFLAGS=${_ccfg}
557 unset _ccfg
559 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
560 unset __cflags __ldflags
563 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
565 ## Notes:
566 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
567 ## redirection, so use "printf '' >" instead
569 ## Very first: we undergo several states regarding I/O redirection etc.,
570 ## but need to deal with option updates from within all. Since all the
571 ## option stuff should be above the scissor line, define utility functions
572 ## and redefine them as necessary.
573 ## And, since we have those functions, simply use them for whatever
575 t1=ten10one1ten10one1
576 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
577 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
578 ) > /dev/null 2>&1; then
579 good_shell=1
580 else
581 unset good_shell
583 unset t1
585 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
587 config_exit() {
588 exit ${1}
591 # which(1) not standardized, command(1) -v may return non-executable: unroll!
592 acmd_test() { __acmd "${1}" 1 0 0; }
593 acmd_test_fail() { __acmd "${1}" 1 1 0; }
594 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
595 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
596 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
597 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
598 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
599 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
600 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
601 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
602 __acmd() {
603 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
605 if [ "${dotest}" -ne 0 ]; then
606 eval dotest=\$${varname}
607 if [ -n "${dotest}" ]; then
608 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
609 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
610 return 0
614 oifs=${IFS} IFS=:
615 [ -n "${noglob_shell}" ] && set -o noglob
616 set -- ${PATH}
617 [ -n "${noglob_shell}" ] && set +o noglob
618 IFS=${oifs}
619 for path
621 if [ -z "${path}" ] || [ "${path}" = . ]; then
622 if [ -d "${PWD}" ]; then
623 path=${PWD}
624 else
625 path=.
628 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
629 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
630 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
631 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
632 return 0
634 done
636 # We may have no builtin string functions, we yet have no programs we can
637 # use, try to access once from the root, assuming it is an absolute path if
638 # that finds the executable
639 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
640 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
641 msg ' . ${%s} ... %s' "${pname}" "${pname}"
642 [ -n "${varname}" ] && eval ${varname}="${pname}"
643 return 0
646 [ ${dofail} -eq 0 ] && return 1
647 msg 'ERROR: no trace of utility '"${pname}"
648 exit 1
651 msg() {
652 fmt=${1}
653 shift
654 printf >&2 -- "${fmt}\\n" "${@}"
657 msg_nonl() {
658 fmt=${1}
659 shift
660 printf >&2 -- "${fmt}" "${@}"
663 # Our feature check environment
664 feat_val_no() {
665 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
666 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
669 feat_val_yes() {
670 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
671 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
672 [ "x${1}" = xrequire ]
675 feat_val_require() {
676 [ "x${1}" = xrequire ]
679 _feat_check() {
680 eval i=\$OPT_${1}
681 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
682 if feat_val_no "${i}"; then
683 return 1
684 elif feat_val_yes "${i}"; then
685 return 0
686 else
687 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
688 "${1}" "${i}"
689 config_exit 11
693 feat_yes() {
694 _feat_check ${1}
697 feat_no() {
698 _feat_check ${1} && return 1
699 return 0
702 feat_require() {
703 eval i=\$OPT_${1}
704 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
705 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
708 feat_bail_required() {
709 if feat_require ${1}; then
710 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
711 config_exit 13
713 eval OPT_${1}=0
714 option_update # XXX this is rather useless here (dependency chain..)
717 option_parse() {
718 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
719 # options, without documentation, to $1
720 j=\'
721 i="`${awk} -v input=\"${2}\" '
722 BEGIN{
723 for(i = 0;;){
724 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
725 if(voff == 0)
726 break
727 v = substr(input, voff, RLENGTH)
728 input = substr(input, voff + RLENGTH)
729 doff = index(v, "=")
730 if(doff > 0){
731 d = substr(v, doff + 2, length(v) - doff - 1)
732 v = substr(v, 1, doff - 1)
734 print v
738 eval ${1}=\"${i}\"
741 option_doc_of() {
742 # Return the "documentation string" for option $1, itself if none such
743 j=\'
744 ${awk} -v want="${1}" \
745 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
746 BEGIN{
747 for(;;){
748 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
749 if(voff == 0)
750 break
751 v = substr(input, voff, RLENGTH)
752 input = substr(input, voff + RLENGTH)
753 doff = index(v, "=")
754 if(doff > 0){
755 d = substr(v, doff + 2, length(v) - doff - 1)
756 v = substr(v, 1, doff - 1)
757 }else
758 d = v
759 if(v == want){
760 if(d != "-")
761 print d
762 exit
769 option_join_rc() {
770 # Join the values from make.rc into what currently is defined, not
771 # overwriting yet existing settings
772 ${rm} -f ${tmp}
773 # We want read(1) to perform reverse solidus escaping in order to be able to
774 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
775 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
776 < ${rc} ${awk} 'BEGIN{line = ""}{
777 gsub(/^[[:space:]]+/, "", $0)
778 gsub(/[[:space:]]+$/, "", $0)
779 if(gsub(/\\$/, "", $0)){
780 line = line $0
781 next
782 }else
783 line = line $0
784 if(index(line, "#") == 1){
785 line = ""
786 }else if(length(line)){
787 print line
788 line = ""
790 }' |
791 while read line; do
792 if [ -n "${good_shell}" ]; then
793 i=${line%%=*}
794 else
795 i=`${awk} -v LINE="${line}" 'BEGIN{
796 gsub(/=.*$/, "", LINE)
797 print LINE
800 if [ "${i}" = "${line}" ]; then
801 msg 'ERROR: invalid syntax in: %s' "${line}"
802 continue
805 eval j="\$${i}" jx="\${${i}+x}"
806 if [ -n "${j}" ] || [ "${jx}" = x ]; then
807 : # Yet present
808 else
809 j=`${awk} -v LINE="${line}" 'BEGIN{
810 gsub(/^[^=]*=/, "", LINE)
811 gsub(/^\"*/, "", LINE)
812 gsub(/\"*$/, "", LINE)
813 print LINE
816 [ "${i}" = "DESTDIR" ] && continue
817 echo "${i}=\"${j}\""
818 done > ${tmp}
819 # Reread the mixed version right now
820 . ./${tmp}
823 option_evaluate() {
824 # Expand the option values, which may contain shell snippets
825 ${rm} -f ${newlst} ${newmk} ${newh}
826 exec 5<&0 6>&1 <${tmp} >${newlst}
827 while read line; do
829 if [ -n "${good_shell}" ]; then
830 i=${line%%=*}
831 [ "${i}" != "${i#OPT_}" ] && z=1
832 else
833 i=`${awk} -v LINE="${line}" 'BEGIN{
834 gsub(/=.*$/, "", LINE);\
835 print LINE
837 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
842 eval j=\$${i}
843 if [ -n "${z}" ]; then
844 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
845 if [ -z "${j}" ] || feat_val_no "${j}"; then
847 printf " /* #undef ${i} */\n" >> ${newh}
848 elif feat_val_yes "${j}"; then
849 if feat_val_require "${j}"; then
850 j=require
851 else
854 printf " /* #define ${i} */\n" >> ${newh}
855 else
856 msg 'ERROR: cannot parse <%s>' "${line}"
857 config_exit 1
859 else
860 printf "#define ${i} \"${j}\"\n" >> ${newh}
862 printf "${i} = ${j}\n" >> ${newmk}
863 printf "${i}=${j}\n"
864 eval "${i}=\"${j}\""
865 done
866 exec 0<&5 1>&6 5<&- 6<&-
869 path_check() {
870 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
871 varname=${1} addflag=${2} flagvarname=${3}
872 j=${IFS}
873 IFS=:
874 [ -n "${noglob_shell}" ] && set -o noglob
875 eval "set -- \$${1}"
876 [ -n "${noglob_shell}" ] && set +o noglob
877 IFS=${j}
878 j= k= y= z=
879 for i
881 [ -z "${i}" ] && continue
882 [ -d "${i}" ] || continue
883 if [ -n "${j}" ]; then
884 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
886 else
887 y="${y} :${i}:"
888 j="${j}:${i}"
889 # But do not link any fakeroot path into our binaries!
890 if [ -n "${addflag}" ]; then
891 case "${i}" in *fakeroot*) continue;; esac
892 k="${k} ${addflag}${i}"
895 else
896 y=" :${i}:"
897 j="${i}"
898 # But do not link any fakeroot path into our binaries!
899 if [ -n "${addflag}" ]; then
900 case "${i}" in *fakeroot*) continue;; esac
901 k="${k} ${addflag}${i}"
904 done
905 eval "${varname}=\"${j}\""
906 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
907 unset varname
910 ld_runtime_flags() {
911 if [ -n "${need_R_ldflags}" ]; then
912 i=${IFS}
913 IFS=:
914 set -- ${LD_LIBRARY_PATH}
915 IFS=${i}
916 for i
918 # But do not link any fakeroot path into our binaries!
919 case "${i}" in *fakeroot*) continue;; esac
920 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
921 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
922 done
923 export LDFLAGS
925 # Disable it for a possible second run.
926 need_R_ldflags=
929 cc_check() {
930 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
931 if "${CC}" ${INCS} \
932 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
933 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
934 _CFLAGS="${_CFLAGS} ${1}"
935 [ -n "${cc_check_silent}" ] || msg 'yes'
936 return 0
938 [ -n "${cc_check_silent}" ] || msg 'no'
939 return 1
942 ld_check() {
943 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
944 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
945 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
946 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
947 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
948 [ -n "${cc_check_silent}" ] || msg 'yes'
949 return 0
951 [ -n "${cc_check_silent}" ] || msg 'no'
952 return 1
955 dump_test_program=1
956 _check_preface() {
957 variable=$1 topic=$2 define=$3
959 echo '**********'
960 msg_nonl ' . %s ... ' "${topic}"
961 echo "/* checked ${topic} */" >> ${h}
962 ${rm} -f ${tmp} ${tmp}.o
963 if [ "${dump_test_program}" = 1 ]; then
964 echo '*** test program is'
965 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
966 else
967 { echo '#include <'"${h_name}"'>'; cat; } > ${tmp}.c
969 #echo '*** the preprocessor generates'
970 #${make} -f ${makefile} ${tmp}.x
971 #${cat} ${tmp}.x
972 echo '*** tests results'
975 without_check() {
976 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
978 echo '**********'
979 msg_nonl ' . %s ... ' "${topic}"
981 echo '*** enforced unchecked results are'
982 if feat_val_yes ${yesno}; then
983 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
984 echo "*** adding INCS<${incs}> LIBS<${libs}>"
985 LIBS="${LIBS} ${libs}"
986 echo "${libs}" >> ${lib}
987 INCS="${INCS} ${incs}"
988 echo "${incs}" >> ${inc}
990 msg 'yes (deduced)'
991 echo "${define}" >> ${h}
992 eval have_${variable}=yes
993 return 0
994 else
995 echo "/* ${define} */" >> ${h}
996 msg 'no (deduced)'
997 eval unset have_${variable}
998 return 1
1002 compile_check() {
1003 variable=$1 topic=$2 define=$3
1005 _check_preface "${variable}" "${topic}" "${define}"
1007 if ${make} -f ${makefile} XINCS="${INCS}" \
1008 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1009 ./${tmp}.o &&
1010 [ -f ./${tmp}.o ]; then
1011 msg 'yes'
1012 echo "${define}" >> ${h}
1013 eval have_${variable}=yes
1014 return 0
1015 else
1016 echo "/* ${define} */" >> ${h}
1017 msg 'no'
1018 eval unset have_${variable}
1019 return 1
1023 _link_mayrun() {
1024 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
1026 _check_preface "${variable}" "${topic}" "${define}"
1028 if feat_yes CROSS_BUILD; then
1029 if [ ${run} = 1 ]; then
1030 run=0
1034 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
1035 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
1036 XLIBS="${LIBS} ${libs}" \
1037 ./${tmp} &&
1038 [ -f ./${tmp} ] &&
1039 { [ ${run} -eq 0 ] || ./${tmp}; }; then
1040 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
1041 msg 'yes'
1042 echo "${define}" >> ${h}
1043 LIBS="${LIBS} ${libs}"
1044 echo "${libs}" >> ${lib}
1045 INCS="${INCS} ${incs}"
1046 echo "${incs}" >> ${inc}
1047 eval have_${variable}=yes
1048 return 0
1049 else
1050 msg 'no'
1051 echo "/* ${define} */" >> ${h}
1052 eval unset have_${variable}
1053 return 1
1057 link_check() {
1058 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
1061 run_check() {
1062 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
1065 xrun_check() {
1066 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
1069 feat_def() {
1070 if feat_yes ${1}; then
1071 echo '#define HAVE_'${1}'' >> ${h}
1072 return 0
1073 else
1074 echo '/* OPT_'${1}'=0 */' >> ${h}
1075 return 1
1079 squeeze_em() {
1080 < "${1}" > "${2}" ${awk} \
1081 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1084 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
1086 # First of all, create new configuration and check whether it changed
1088 # Very easy checks for the operating system in order to be able to adjust paths
1089 # or similar very basic things which we need to be able to go at all
1090 os_early_setup
1092 # Check those tools right now that we need before including $rc
1093 msg 'Checking for basic utility set'
1094 thecmd_testandset_fail awk awk
1095 thecmd_testandset_fail rm rm
1096 thecmd_testandset_fail tr tr
1098 # Initialize the option set
1099 msg_nonl 'Setting up configuration options ... '
1100 option_setup
1101 msg 'done'
1103 # Include $rc, but only take from it what wasn't overwritten by the user from
1104 # within the command line or from a chosen fixed CONFIG=
1105 # Note we leave alone the values
1106 trap "exit 1" HUP INT TERM
1107 trap "${rm} -f ${tmp}" EXIT
1109 msg_nonl 'Joining in %s ... ' ${rc}
1110 option_join_rc
1111 msg 'done'
1113 # We need to know about that now, in order to provide utility overwrites etc.
1114 os_setup
1116 msg 'Checking for remaining set of utilities'
1117 thecmd_testandset_fail grep grep
1119 # Before we step ahead with the other utilities perform a path cleanup first.
1120 path_check PATH
1122 # awk(1) above
1123 thecmd_testandset_fail basename basename
1124 thecmd_testandset_fail cat cat
1125 thecmd_testandset_fail chmod chmod
1126 thecmd_testandset_fail cp cp
1127 thecmd_testandset_fail cmp cmp
1128 # grep(1) above
1129 thecmd_testandset_fail mkdir mkdir
1130 thecmd_testandset_fail mv mv
1131 # rm(1) above
1132 thecmd_testandset_fail sed sed
1133 thecmd_testandset_fail sort sort
1134 thecmd_testandset_fail tee tee
1135 __PATH=${PATH}
1136 thecmd_testandset chown chown ||
1137 PATH="/sbin:${PATH}" thecmd_set chown chown ||
1138 PATH="/usr/sbin:${PATH}" thecmd_set_fail chown chown
1139 PATH=${__PATH}
1140 thecmd_testandset_fail make make
1141 MAKE=${make}
1142 export MAKE
1143 thecmd_testandset strip strip && HAVE_STRIP=1 || HAVE_STRIP=0
1145 # For ./cc-test.sh only
1146 thecmd_testandset_fail cksum cksum
1148 # Update OPT_ options now, in order to get possible inter-dependencies right
1149 option_update
1151 # (No functions since some shells loose non-exported variables in traps)
1152 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1153 trap "trap \"\" HUP INT TERM EXIT;\
1154 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1156 # Our configuration options may at this point still contain shell snippets,
1157 # we need to evaluate them in order to get them expanded, and we need those
1158 # evaluated values not only in our new configuration file, but also at hand..
1159 msg_nonl 'Evaluating all configuration items ... '
1160 option_evaluate
1161 msg 'done'
1163 # Add the known utility and some other variables
1164 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1165 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1167 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1168 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1169 if feat_yes DOTLOCK; then
1170 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1171 else
1172 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1175 for i in \
1176 SRCDIR \
1177 awk basename cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1178 MAKE MAKEFLAGS make SHELL strip \
1179 cksum; do
1180 eval j=\$${i}
1181 printf "${i} = ${j}\n" >> ${newmk}
1182 printf "${i}=${j}\n" >> ${newlst}
1183 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1184 done
1185 printf "\n" >> ${newev}
1187 # Build a basic set of INCS and LIBS according to user environment.
1188 C_INCLUDE_PATH="${CWDDIR}:${SRCDIR}:${C_INCLUDE_PATH}"
1189 path_check C_INCLUDE_PATH -I _INCS
1190 INCS="${INCS} ${_INCS}"
1191 path_check LD_LIBRARY_PATH -L _LIBS
1192 LIBS="${LIBS} ${_LIBS}"
1193 unset _INCS _LIBS
1194 export C_INCLUDE_PATH LD_LIBRARY_PATH
1196 # Some environments need runtime path flags to be able to go at all
1197 ld_runtime_flags
1199 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1201 cc_setup
1203 ${cat} > ${tmp}.c << \!
1204 #include <stdio.h>
1205 #include <string.h>
1206 static void doit(char const *s);
1208 main(int argc, char **argv){
1209 (void)argc;
1210 (void)argv;
1211 doit("Hello world");
1212 return 0;
1214 static void
1215 doit(char const *s){
1216 char buf[12];
1217 memcpy(buf, s, strlen(s) +1);
1218 puts(s);
1222 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1223 -o ${tmp2} ${tmp}.c ${LIBS}; then
1225 else
1226 msg 'ERROR: i cannot compile a "Hello world" via'
1227 msg ' %s' \
1228 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1229 msg 'ERROR: Please read INSTALL, rerun'
1230 config_exit 1
1233 # This may also update ld_runtime_flags() (again)
1234 cc_flags
1236 for i in \
1237 INCS LIBS \
1238 ; do
1239 eval j=\$${i}
1240 printf -- "${i}=${j}\n" >> ${newlst}
1241 done
1242 for i in \
1243 CC \
1244 CFLAGS \
1245 LDFLAGS \
1246 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1247 OSFULLSPEC \
1248 ; do
1249 eval j=\$${i}
1250 printf -- "${i} = ${j}\n" >> ${newmk}
1251 printf -- "${i}=${j}\n" >> ${newlst}
1252 done
1254 # Now finally check whether we already have a configuration and if so, whether
1255 # all those parameters are still the same.. or something has actually changed
1256 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1257 echo 'Configuration is up-to-date'
1258 exit 0
1259 elif [ -f ${lst} ]; then
1260 echo 'Configuration has been updated..'
1261 ( eval "${MAKE} -f ./mk-config.mk clean" )
1262 echo
1263 else
1264 echo 'Shiny configuration..'
1267 # Time to redefine helper 1
1268 config_exit() {
1269 ${rm} -f ${lst} ${h} ${mk}
1270 exit ${1}
1273 ${mv} -f ${newlst} ${lst}
1274 ${mv} -f ${newev} ${ev}
1275 ${mv} -f ${newh} ${h}
1276 ${mv} -f ${newmk} ${mk}
1278 if [ -z "${VERBOSE}" ]; then
1279 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1280 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1281 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1282 printf -- "ECHO_TEST = @\n" >> ${mk}
1283 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1284 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1285 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1288 ## Compile and link checking
1290 tmp3=./${tmp0}3$$
1291 log=./mk-config.log
1292 lib=./mk-config.lib
1293 inc=./mk-config.inc
1294 makefile=./${tmp0}.mk
1296 # (No function since some shells loose non-exported variables in traps)
1297 trap "trap \"\" HUP INT TERM;\
1298 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1299 trap "trap \"\" HUP INT TERM EXIT;\
1300 ${rm} -rf ${tmp0}.* ${tmp0}*" EXIT
1302 # Time to redefine helper 2
1303 msg() {
1304 fmt=${1}
1305 shift
1306 printf "*** ${fmt}\\n" "${@}"
1307 printf -- "${fmt}\\n" "${@}" >&5
1309 msg_nonl() {
1310 fmt=${1}
1311 shift
1312 printf "*** ${fmt}\\n" "${@}"
1313 printf -- "${fmt}" "${@}" >&5
1316 # !!
1317 exec 5>&2 > ${log} 2>&1
1319 echo "${LIBS}" > ${lib}
1320 echo "${INCS}" > ${inc}
1321 ${cat} > ${makefile} << \!
1322 .SUFFIXES: .o .c .x .y
1323 .c.o:
1324 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1325 .c.x:
1326 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1328 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1331 ## Generics
1333 # May be multiline..
1334 echo >> ${h}
1335 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1336 echo '#define VAL_BUILD_OS "'"${OS}"'"' >> ${h}
1337 echo '#define VAL_BUILD_OSENV "'"${OSENV}"'"' >> ${h}
1339 # Generate n_err_number OS mappings
1340 dump_test_program=0
1342 feat_yes DEVEL && NV= || NV=noverbose
1343 SRCDIR="${SRCDIR}" TARGET="${h}" awk="${awk}" \
1344 ${SHELL} "${SRCDIR}"make-errors.sh ${NV} config
1345 ) | xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1346 dump_test_program=1
1348 feat_def ALWAYS_UNICODE_LOCALE
1349 feat_def AMALGAMATION
1350 feat_def CROSS_BUILD
1351 feat_def DOCSTRINGS
1352 feat_def ERRORS
1354 feat_def ASAN_ADDRESS
1355 feat_def ASAN_MEMORY
1356 feat_def DEBUG
1357 feat_def DEVEL
1358 feat_def NYD2
1359 feat_def NOMEMDBG
1361 if xrun_check inline 'inline functions' \
1362 '#define HAVE_INLINE
1363 #define n_INLINE static inline' << \!
1364 static inline int ilf(int i){return ++i;}
1365 int main(void){return ilf(-1);}
1367 then
1369 elif xrun_check inline 'inline functions (via __inline)' \
1370 '#define HAVE_INLINE
1371 #define n_INLINE static __inline' << \!
1372 static __inline int ilf(int i){return ++i;}
1373 int main(void){return ilf(-1);}
1375 then
1379 ## Test for "basic" system-calls / functionality that is used by all parts
1380 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1381 ## macros to be used by only the subprograms (potentially).
1383 if run_check clock_gettime 'clock_gettime(2)' \
1384 '#define HAVE_CLOCK_GETTIME' << \!
1385 #include <time.h>
1386 # include <errno.h>
1387 int main(void){
1388 struct timespec ts;
1390 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1391 return 0;
1392 return 1;
1395 then
1397 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1398 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1399 #include <time.h>
1400 # include <errno.h>
1401 int main(void){
1402 struct timespec ts;
1404 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1405 return 0;
1406 return 1;
1409 then
1411 elif run_check gettimeofday 'gettimeofday(2)' \
1412 '#define HAVE_GETTIMEOFDAY' << \!
1413 #include <stdio.h> /* For C89 NULL */
1414 #include <sys/time.h>
1415 # include <errno.h>
1416 int main(void){
1417 struct timeval tv;
1419 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1420 return 0;
1421 return 1;
1424 then
1426 else
1427 have_no_subsecond_time=1
1430 if run_check nanosleep 'nanosleep(2)' \
1431 '#define HAVE_NANOSLEEP' << \!
1432 #include <time.h>
1433 # include <errno.h>
1434 int main(void){
1435 struct timespec ts;
1437 ts.tv_sec = 1;
1438 ts.tv_nsec = 100000;
1439 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1440 return 0;
1441 return 1;
1444 then
1446 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1447 '#define HAVE_NANOSLEEP' '-lrt' << \!
1448 #include <time.h>
1449 # include <errno.h>
1450 int main(void){
1451 struct timespec ts;
1453 ts.tv_sec = 1;
1454 ts.tv_nsec = 100000;
1455 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1456 return 0;
1457 return 1;
1460 then
1462 # link_check is enough for this, that function is so old, trust the proto
1463 elif link_check sleep 'sleep(3)' \
1464 '#define HAVE_SLEEP' << \!
1465 #include <unistd.h>
1466 # include <errno.h>
1467 int main(void){
1468 if(!sleep(1) || errno != ENOSYS)
1469 return 0;
1470 return 1;
1473 then
1475 else
1476 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1477 config_exit 1
1480 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1481 #include <pwd.h>
1482 #include <unistd.h>
1483 # include <errno.h>
1484 int main(void){
1485 struct passwd *pw;
1486 gid_t gid;
1487 uid_t uid;
1489 if((gid = getgid()) != 0)
1490 gid = getegid();
1491 if((uid = getuid()) != 0)
1492 uid = geteuid();
1493 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1494 return 1;
1495 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1496 return 1;
1497 return 0;
1500 then
1502 else
1503 msg 'ERROR: we require user and group info / database searches.'
1504 msg 'That much Unix we indulge ourselfs.'
1505 config_exit 1
1508 if link_check ftruncate 'ftruncate(2)' \
1509 '#define HAVE_FTRUNCATE' << \!
1510 #include <unistd.h>
1511 #include <sys/types.h>
1512 int main(void){
1513 return (ftruncate(0, 0) != 0);
1516 then
1518 else
1519 msg 'ERROR: we require the ftruncate(2) system call.'
1520 config_exit 1
1523 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1524 #include <signal.h>
1525 # include <errno.h>
1526 int main(void){
1527 struct sigaction nact, oact;
1529 nact.sa_handler = SIG_DFL;
1530 sigemptyset(&nact.sa_mask);
1531 nact.sa_flags = SA_RESTART;
1532 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1535 then
1537 else
1538 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1539 config_exit 1
1542 if link_check snprintf 'snprintf(3)' << \!
1543 #include <stdio.h>
1544 int main(void){
1545 char b[20];
1547 snprintf(b, sizeof b, "%s", "string");
1548 return 0;
1551 then
1553 else
1554 msg 'ERROR: we require the snprintf(3) function.'
1555 config_exit 1
1558 if link_check environ 'environ(3)' << \!
1559 #include <stdio.h> /* For C89 NULL */
1560 int main(void){
1561 extern char **environ;
1563 return environ[0] == NULL;
1566 then
1568 else
1569 msg 'ERROR: we require the environ(3) array for subprocess control.'
1570 config_exit 1
1573 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1574 #include <stdlib.h>
1575 int main(void){
1576 setenv("s-mailx", "i want to see it cute!", 1);
1577 unsetenv("s-mailx");
1578 return 0;
1581 then
1583 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1584 #include <stdlib.h>
1585 int main(void){
1586 putenv("s-mailx=i want to see it cute!");
1587 return 0;
1590 then
1592 else
1593 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1594 config_exit 1
1597 if link_check termios 'termios.h and tc*(3) family' << \!
1598 #include <termios.h>
1599 int main(void){
1600 struct termios tios;
1602 tcgetattr(0, &tios);
1603 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1604 return 0;
1607 then
1609 else
1610 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1611 msg 'That much Unix we indulge ourselfs.'
1612 config_exit 1
1615 ## optional stuff
1617 if link_check vsnprintf 'vsnprintf(3)' << \!
1618 #include <stdarg.h>
1619 #include <stdio.h>
1620 static void dome(char *buf, size_t blen, ...){
1621 va_list ap;
1623 va_start(ap, blen);
1624 vsnprintf(buf, blen, "%s", ap);
1625 va_end(ap);
1627 int main(void){
1628 char b[20];
1630 dome(b, sizeof b, "string");
1631 return 0;
1634 then
1636 else
1637 feat_bail_required ERRORS
1640 if [ "${have_vsnprintf}" = yes ]; then
1641 __va_copy() {
1642 link_check va_copy "va_copy(3) (as ${2})" \
1643 "#define HAVE_N_VA_COPY
1644 #define n_va_copy ${2}" <<_EOT
1645 #include <stdarg.h>
1646 #include <stdio.h>
1647 #if ${1}
1648 # if defined __va_copy && !defined va_copy
1649 # define va_copy __va_copy
1650 # endif
1651 #endif
1652 static void dome2(char *buf, size_t blen, va_list src){
1653 va_list ap;
1655 va_copy(ap, src);
1656 vsnprintf(buf, blen, "%s", ap);
1657 va_end(ap);
1659 static void dome(char *buf, size_t blen, ...){
1660 va_list ap;
1662 va_start(ap, blen);
1663 dome2(buf, blen, ap);
1664 va_end(ap);
1666 int main(void){
1667 char b[20];
1669 dome(b, sizeof b, "string");
1670 return 0;
1672 _EOT
1674 __va_copy 0 va_copy || __va_copy 1 __va_copy
1677 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1678 #include <unistd.h>
1679 #include <errno.h>
1680 int main(void){
1681 int rv = 0;
1683 errno = 0;
1684 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1685 errno = 0;
1686 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1688 /* Only link check */
1689 fpathconf(0, _PC_NAME_MAX);
1691 return rv;
1695 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1696 #include <fcntl.h>
1697 #include <unistd.h>
1698 # include <errno.h>
1699 int main(void){
1700 int fds[2];
1702 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1703 return 0;
1704 return 1;
1708 # We use this only then for now (need NOW+1)
1709 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1710 #include <fcntl.h> /* For AT_* */
1711 #include <sys/stat.h>
1712 # include <errno.h>
1713 int main(void){
1714 struct timespec ts[2];
1716 ts[0].tv_nsec = UTIME_NOW;
1717 ts[1].tv_nsec = UTIME_OMIT;
1718 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1719 return 0;
1720 return 1;
1726 # XXX Add POSIX check once standardized
1727 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1728 #include <stdlib.h>
1729 int main(void){
1730 arc4random();
1731 return 0;
1734 then
1736 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1737 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1738 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1739 #include <sys/random.h>
1740 int main(void){
1741 char buf[256];
1742 getrandom(buf, sizeof buf, 0);
1743 return 0;
1746 then
1748 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1749 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1750 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1751 #include <sys/syscall.h>
1752 int main(void){
1753 char buf[256];
1754 syscall(SYS_getrandom, buf, sizeof buf, 0);
1755 return 0;
1758 then
1760 elif [ -n "${have_no_subsecond_time}" ]; then
1761 msg 'ERROR: %s %s' 'without a native random' \
1762 'one of clock_gettime(2) and gettimeofday(2) is required.'
1763 config_exit 1
1767 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1768 #include <stdio.h>
1769 int main(void){
1770 putc_unlocked('@', stdout);
1771 return 0;
1775 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1776 #include <unistd.h>
1777 int main(void){
1778 fchdir(0);
1779 return 0;
1783 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1784 #include <stdlib.h>
1785 int main(void){
1786 char x_buf[4096], *x = realpath(".", x_buf);
1788 return (x != NULL) ? 0 : 1;
1791 then
1792 if run_check realpath_malloc 'realpath(3) takes NULL' \
1793 '#define HAVE_REALPATH_NULL' << \!
1794 #include <stdlib.h>
1795 int main(void){
1796 char *x = realpath(".", NULL);
1798 if(x != NULL)
1799 free(x);
1800 return (x != NULL) ? 0 : 1;
1803 then
1808 ## optional and selectable
1810 if feat_yes DOTLOCK; then
1811 if run_check readlink 'readlink(2)' << \!
1812 #include <unistd.h>
1813 # include <errno.h>
1814 int main(void){
1815 char buf[128];
1817 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1818 return 0;
1819 return 1;
1822 then
1824 else
1825 feat_bail_required DOTLOCK
1829 if feat_yes DOTLOCK; then
1830 if run_check fchown 'fchown(2)' << \!
1831 #include <unistd.h>
1832 # include <errno.h>
1833 int main(void){
1834 if(!fchown(0, 0, 0) || errno != ENOSYS)
1835 return 0;
1836 return 1;
1839 then
1841 else
1842 feat_bail_required DOTLOCK
1846 ## Now it is the time to fork away the BASE_ series
1848 ${rm} -f ${tmp}
1849 squeeze_em ${inc} ${tmp}
1850 ${mv} ${tmp} ${inc}
1851 squeeze_em ${lib} ${tmp}
1852 ${mv} ${tmp} ${lib}
1854 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1855 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1857 ## The remains are expected to be used only by the main MUA binary!
1859 OPT_LOCALES=0
1860 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1861 #include <locale.h>
1862 int main(void){
1863 setlocale(LC_ALL, "");
1864 return 0;
1867 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1869 OPT_MULTIBYTE_CHARSETS=0
1870 OPT_WIDE_GLYPHS=0
1871 OPT_TERMINAL_CHARSET=0
1872 if [ -n "${have_setlocale}" ]; then
1873 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1874 '#define HAVE_C90AMEND1' << \!
1875 #include <limits.h>
1876 #include <stdlib.h>
1877 #include <wchar.h>
1878 #include <wctype.h>
1879 int main(void){
1880 char mbb[MB_LEN_MAX + 1];
1881 wchar_t wc;
1883 iswprint(L'c');
1884 towupper(L'c');
1885 mbtowc(&wc, "x", 1);
1886 mbrtowc(&wc, "x", 1, NULL);
1887 wctomb(mbb, wc);
1888 return (mblen("\0", 1) == 0);
1891 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1893 if [ -n "${have_c90amend1}" ]; then
1894 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1895 #include <wchar.h>
1896 int main(void){
1897 wcwidth(L'c');
1898 return 0;
1901 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1904 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1905 #include <langinfo.h>
1906 #include <stdlib.h>
1907 int main(void){
1908 nl_langinfo(DAY_1);
1909 return (nl_langinfo(CODESET) == NULL);
1912 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1913 fi # have_setlocale
1915 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1916 #include <fnmatch.h>
1917 int main(void){
1918 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1922 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1923 #include <dirent.h>
1924 int main(void){
1925 struct dirent de;
1926 return !(de.d_type == DT_UNKNOWN ||
1927 de.d_type == DT_DIR || de.d_type == DT_LNK);
1931 ## optional and selectable
1933 if feat_yes ICONV; then
1934 ${cat} > ${tmp2}.c << \!
1935 #include <stdio.h> /* For C89 NULL */
1936 #include <iconv.h>
1937 int main(void){
1938 iconv_t id;
1940 id = iconv_open("foo", "bar");
1941 iconv(id, NULL, NULL, NULL, NULL);
1942 iconv_close(id);
1943 return 0;
1946 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1947 '#define HAVE_ICONV' ||
1948 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1949 '#define HAVE_ICONV' '-liconv' ||
1950 feat_bail_required ICONV
1951 else
1952 echo '/* OPT_ICONV=0 */' >> ${h}
1953 fi # feat_yes ICONV
1955 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1956 ${cat} > ${tmp2}.c << \!
1957 #include <sys/types.h>
1958 #include <sys/socket.h>
1959 #include <sys/un.h>
1960 # include <errno.h>
1961 int main(void){
1962 struct sockaddr_un soun;
1964 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1965 return 1;
1966 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1967 return 1;
1968 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1969 return 1;
1970 return 0;
1974 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1975 '#define HAVE_UNIX_SOCKETS' ||
1976 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1977 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1978 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1979 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1982 if feat_yes SOCKETS; then
1983 ${cat} > ${tmp2}.c << \!
1984 #include <sys/types.h>
1985 #include <sys/socket.h>
1986 #include <netinet/in.h>
1987 # include <errno.h>
1988 int main(void){
1989 struct sockaddr s;
1991 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1992 return 1;
1993 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1994 return 1;
1995 return 0;
1999 < ${tmp2}.c run_check sockets 'sockets' \
2000 '#define HAVE_SOCKETS' ||
2001 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
2002 '#define HAVE_SOCKETS' '-lnsl' ||
2003 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
2004 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
2005 feat_bail_required SOCKETS
2006 else
2007 echo '/* OPT_SOCKETS=0 */' >> ${h}
2008 fi # feat_yes SOCKETS
2010 if feat_yes SOCKETS; then
2011 link_check getaddrinfo 'getaddrinfo(3)' \
2012 '#define HAVE_GETADDRINFO' << \!
2013 #include <sys/types.h>
2014 #include <sys/socket.h>
2015 #include <stdio.h>
2016 #include <netdb.h>
2017 int main(void){
2018 struct addrinfo a, *ap;
2019 int lrv;
2021 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
2022 case EAI_NONAME:
2023 case EAI_SERVICE:
2024 default:
2025 fprintf(stderr, "%s\n", gai_strerror(lrv));
2026 case 0:
2027 break;
2029 return 0;
2034 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
2035 compile_check arpa_inet_h '<arpa/inet.h>' \
2036 '#define HAVE_ARPA_INET_H' << \!
2037 #include <sys/types.h>
2038 #include <sys/socket.h>
2039 #include <netdb.h>
2040 #include <netinet/in.h>
2041 #include <arpa/inet.h>
2044 ${cat} > ${tmp2}.c << \!
2045 #include <sys/types.h>
2046 #include <sys/socket.h>
2047 #include <stdio.h>
2048 #include <string.h>
2049 #include <netdb.h>
2050 #include <netinet/in.h>
2051 #ifdef HAVE_ARPA_INET_H
2052 #include <arpa/inet.h>
2053 #endif
2054 int main(void){
2055 struct sockaddr_in servaddr;
2056 unsigned short portno;
2057 struct servent *ep;
2058 struct hostent *hp;
2059 struct in_addr **pptr;
2061 portno = 0;
2062 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
2063 portno = (unsigned short)ep->s_port;
2065 if((hp = gethostbyname("POPPY-HOST")) != NULL){
2066 pptr = (struct in_addr**)hp->h_addr_list;
2067 if(hp->h_addrtype != AF_INET)
2068 fprintf(stderr, "au\n");
2069 }else{
2070 switch(h_errno){
2071 case HOST_NOT_FOUND:
2072 case TRY_AGAIN:
2073 case NO_RECOVERY:
2074 case NO_DATA:
2075 break;
2076 default:
2077 fprintf(stderr, "au\n");
2078 break;
2082 memset(&servaddr, 0, sizeof servaddr);
2083 servaddr.sin_family = AF_INET;
2084 servaddr.sin_port = htons(portno);
2085 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
2086 fprintf(stderr, "Would connect to %s:%d ...\n",
2087 inet_ntoa(**pptr), (int)portno);
2088 return 0;
2092 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
2093 < ${tmp2}.c link_check gethostbyname \
2094 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
2095 < ${tmp2}.c link_check gethostbyname \
2096 'get(serv|host)byname(3) (via -lsocket -nsl)' \
2097 '' '-lsocket -lnsl' ||
2098 feat_bail_required SOCKETS
2101 feat_yes SOCKETS &&
2102 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2103 #include <sys/socket.h>
2104 #include <stdlib.h>
2105 # include <errno.h>
2106 int main(void){
2107 int sockfd = 3;
2109 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2110 errno == ENOSYS)
2111 return 1;
2112 return 0;
2116 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2117 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2118 #include <sys/socket.h>
2119 #include <stdlib.h>
2120 int main(void){
2121 struct timeval tv;
2122 int sockfd = 3;
2124 tv.tv_sec = 42;
2125 tv.tv_usec = 21;
2126 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2127 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2128 return 0;
2132 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2133 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2134 #include <sys/socket.h>
2135 #include <stdlib.h>
2136 int main(void){
2137 struct linger li;
2138 int sockfd = 3;
2140 li.l_onoff = 1;
2141 li.l_linger = 42;
2142 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2143 return 0;
2147 if feat_yes SSL; then # {{{
2148 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2149 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2150 # time: we need to test it first in order to get things right
2151 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2152 '#define HAVE_SSL
2153 #define HAVE_XSSL
2154 #define HAVE_XSSL_RESSL
2155 #define HAVE_XSSL_OPENSSL 0' << \!
2156 #include <openssl/opensslv.h>
2157 #ifdef LIBRESSL_VERSION_NUMBER
2158 #else
2159 # error nope
2160 #endif
2162 then
2163 ossl_v1_1=
2164 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2165 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2166 '#define HAVE_SSL
2167 #define HAVE_XSSL
2168 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2169 #include <openssl/opensslv.h>
2170 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2171 #else
2172 # error nope
2173 #endif
2175 then
2176 ossl_v1_1=1
2177 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2178 '#define HAVE_SSL
2179 #define HAVE_XSSL
2180 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2181 #include <openssl/opensslv.h>
2182 #ifdef OPENSSL_VERSION_NUMBER
2183 #else
2184 # error nope
2185 #endif
2187 then
2188 ossl_v1_1=
2189 else
2190 feat_bail_required SSL
2191 fi # }}}
2193 if feat_yes SSL; then # {{{
2194 if [ -n "${ossl_v1_1}" ]; then
2195 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2196 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2197 '-lssl -lcrypto'
2198 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2199 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2200 '-lssl -lcrypto' << \!
2201 #include <openssl/ssl.h>
2202 #include <openssl/err.h>
2203 #include <openssl/x509v3.h>
2204 #include <openssl/x509.h>
2205 #include <openssl/rand.h>
2206 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2207 # error We need TLSv1.
2208 #endif
2209 int main(void){
2210 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2212 SSL_CTX_free(ctx);
2213 PEM_read_PrivateKey(0, 0, 0, 0);
2214 return 0;
2217 then
2219 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2220 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2221 '-lssl -lcrypto' << \!
2222 #include <openssl/ssl.h>
2223 #include <openssl/err.h>
2224 #include <openssl/x509v3.h>
2225 #include <openssl/x509.h>
2226 #include <openssl/rand.h>
2227 #if defined OPENSSL_NO_SSL3 &&\
2228 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2229 # error We need one of SSLv3 and TLSv1.
2230 #endif
2231 int main(void){
2232 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2234 SSL_CTX_free(ctx);
2235 PEM_read_PrivateKey(0, 0, 0, 0);
2236 return 0;
2239 then
2241 else
2242 feat_bail_required SSL
2244 fi # }}}
2246 if feat_yes SSL; then # {{{
2247 if [ -n "${ossl_v1_1}" ]; then
2248 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2249 '#define HAVE_XSSL_STACK_OF'
2250 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2251 '#define HAVE_XSSL_STACK_OF' << \!
2252 #include <stdio.h> /* For C89 NULL */
2253 #include <openssl/ssl.h>
2254 #include <openssl/err.h>
2255 #include <openssl/x509v3.h>
2256 #include <openssl/x509.h>
2257 #include <openssl/rand.h>
2258 int main(void){
2259 STACK_OF(GENERAL_NAME) *gens = NULL;
2261 printf("%p", gens); /* to use it */
2262 return 0;
2265 then
2269 if [ -n "${ossl_v1_1}" ]; then
2270 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2271 '#define HAVE_XSSL_CONFIG'
2272 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2273 '#define HAVE_XSSL_CONFIG' << \!
2274 #include <stdio.h> /* For C89 NULL */
2275 #include <openssl/conf.h>
2276 int main(void){
2277 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2278 CONF_modules_free();
2279 return 0;
2282 then
2286 if [ -n "${ossl_v1_1}" ]; then
2287 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2288 '#define HAVE_XSSL_CONF_CTX'
2289 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2290 '#define HAVE_XSSL_CONF_CTX' << \!
2291 #include <openssl/ssl.h>
2292 #include <openssl/err.h>
2293 int main(void){
2294 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2295 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2297 SSL_CONF_CTX_set_flags(cctx,
2298 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2299 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2300 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2301 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2302 SSL_CONF_CTX_finish(cctx);
2303 SSL_CONF_CTX_free(cctx);
2304 SSL_CTX_free(ctx);
2305 return 0;
2308 then
2312 if [ -n "${ossl_v1_1}" ]; then
2313 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2314 '#define HAVE_XSSL_RAND_EGD'
2315 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2316 '#define HAVE_XSSL_RAND_EGD' << \!
2317 #include <openssl/rand.h>
2318 int main(void){
2319 return RAND_egd("some.where") > 0;
2322 then
2326 if feat_yes SSL_ALL_ALGORITHMS; then
2327 if [ -n "${ossl_v1_1}" ]; then
2328 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2329 '#define HAVE_SSL_ALL_ALGORITHMS'
2330 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2331 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2332 #include <openssl/evp.h>
2333 int main(void){
2334 OpenSSL_add_all_algorithms();
2335 EVP_get_cipherbyname("two cents i never exist");
2336 EVP_cleanup();
2337 return 0;
2340 then
2342 else
2343 feat_bail_required SSL_ALL_ALGORITHMS
2346 fi # feat_yes SSL }}}
2348 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2349 run_check ssl_md5 'MD5 digest in the used crypto library' \
2350 '#define HAVE_XSSL_MD5' << \!
2351 #include <stdlib.h>
2352 #include <string.h>
2353 #include <openssl/md5.h>
2354 int main(void){
2355 char const dat[] = "abrakadabrafidibus";
2356 char dig[16], hex[16 * 2];
2357 MD5_CTX ctx;
2358 size_t i, j;
2360 memset(dig, 0, sizeof(dig));
2361 memset(hex, 0, sizeof(hex));
2362 MD5_Init(&ctx);
2363 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2364 MD5_Final(dig, &ctx);
2366 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2367 for(i = 0; i < sizeof(hex) / 2; i++){
2368 j = i << 1;
2369 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2370 hex[++j] = hexchar(dig[i] & 0x0f);
2372 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2375 fi # }}}
2376 else
2377 echo '/* OPT_SSL=0 */' >> ${h}
2378 fi # }}} feat_yes SSL
2380 if [ "${have_xssl}" = yes ]; then
2381 OPT_SMIME=1
2382 else
2383 OPT_SMIME=0
2385 feat_def SMIME
2387 feat_def SMTP
2388 feat_def POP3
2389 feat_def IMAP
2391 if feat_yes GSSAPI; then
2392 ${cat} > ${tmp2}.c << \!
2393 #include <gssapi/gssapi.h>
2394 int main(void){
2395 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2396 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2397 return 0;
2400 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2402 if acmd_set i krb5-config; then
2403 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2404 GSS_INCS="`CFLAGS= ${i} --cflags`"
2405 i='GSS-API via krb5-config(1)'
2406 else
2407 GSS_LIBS='-lgssapi'
2408 GSS_INCS=
2409 i='GSS-API in gssapi/gssapi.h, libgssapi'
2411 if < ${tmp2}.c link_check gss \
2412 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2413 < ${tmp3}.c link_check gss \
2414 'GSS-API in gssapi.h, libgssapi' \
2415 '#define HAVE_GSSAPI
2416 #define GSSAPI_REG_INCLUDE' \
2417 '-lgssapi' ||\
2418 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2419 '#define HAVE_GSSAPI' \
2420 '-lgssapi_krb5' ||\
2421 < ${tmp3}.c link_check gss \
2422 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2423 '#define HAVE_GSSAPI
2424 #define GSS_REG_INCLUDE' \
2425 '-lgssapi -lkrb5 -lcrypto' \
2426 '-I/usr/include/kerberosV' ||\
2427 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2428 '#define HAVE_GSSAPI' \
2429 '-lgss' ||\
2430 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2431 '#define HAVE_GSSAPI
2432 #define GSSAPI_OLD_STYLE' \
2433 '-lgssapi_krb5' << \!
2434 #include <gssapi/gssapi.h>
2435 #include <gssapi/gssapi_generic.h>
2436 int main(void){
2437 gss_import_name(0, 0, gss_nt_service_name, 0);
2438 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2439 return 0;
2442 then
2444 else
2445 feat_bail_required GSSAPI
2447 else
2448 echo '/* OPT_GSSAPI=0 */' >> ${h}
2449 fi # feat_yes GSSAPI
2451 feat_def NETRC
2452 feat_def AGENT
2454 if feat_yes IDNA; then
2455 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2456 '-lidn' << \!
2457 #include <idna.h>
2458 #include <idn-free.h>
2459 #include <stringprep.h>
2460 int main(void){
2461 char *utf8, *idna_ascii, *idna_utf8;
2463 utf8 = stringprep_locale_to_utf8("does.this.work");
2464 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2465 != IDNA_SUCCESS)
2466 return 1;
2467 idn_free(idna_ascii);
2468 /* (Rather link check only here) */
2469 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2470 return 0;
2473 then
2475 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2476 '-lidnkit' << \!
2477 #include <stdio.h>
2478 #include <idn/api.h>
2479 #include <idn/result.h>
2480 int main(void){
2481 idn_result_t r;
2482 char ace_name[256];
2483 char local_name[256];
2485 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2486 sizeof(ace_name));
2487 if (r != idn_success) {
2488 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2489 return 1;
2491 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2492 if (r != idn_success) {
2493 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2494 return 1;
2496 return 0;
2499 then
2501 else
2502 feat_bail_required IDNA
2505 if [ -n "${have_idna}" ]; then
2506 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2507 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2509 else
2510 echo '/* OPT_IDNA=0 */' >> ${h}
2513 feat_def IMAP_SEARCH
2515 if feat_yes REGEX; then
2516 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2517 #include <regex.h>
2518 #include <stdlib.h>
2519 int main(void){
2520 size_t xret;
2521 int status;
2522 regex_t re;
2524 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2525 xret = regerror(status, &re, NULL, 0);
2526 status = regexec(&re, "plan9", 0,NULL, 0);
2527 regfree(&re);
2528 return !(status == REG_NOMATCH);
2531 then
2533 else
2534 feat_bail_required REGEX
2536 else
2537 echo '/* OPT_REGEX=0 */' >> ${h}
2540 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2541 have_mle=1
2542 echo '#define HAVE_MLE' >> ${h}
2543 else
2544 feat_bail_required MLE
2545 echo '/* OPT_MLE=0 */' >> ${h}
2548 # Generic have-a-line-editor switch for those who need it below
2549 if [ -n "${have_mle}" ]; then
2550 have_cle=1
2553 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2554 echo '#define HAVE_HISTORY' >> ${h}
2555 else
2556 echo '/* OPT_HISTORY=0 */' >> ${h}
2559 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2560 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2561 else
2562 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2565 if feat_yes TERMCAP; then
2566 __termcaplib() {
2567 link_check termcap "termcap(5) (via ${4})" \
2568 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2569 #include <stdio.h>
2570 #include <stdlib.h>
2571 ${2}
2572 #include <term.h>
2573 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2574 static int my_putc(int c){return putchar(c);}
2575 int main(void){
2576 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2577 int r2 = OK, r3 = ERR;
2579 tgetent(buf, getenv("TERM"));
2580 cpb = cmdbuf;
2581 r1 = tgetstr(UNCONST("cm"), &cpb);
2582 tgoto(r1, 1, 1);
2583 r2 = tgetnum(UNCONST("Co"));
2584 r3 = tgetflag(UNCONST("ut"));
2585 tputs("cr", 1, &my_putc);
2586 return (r1 == NULL || r2 == -1 || r3 == 0);
2588 _EOT
2591 __terminfolib() {
2592 link_check terminfo "terminfo(5) (via ${2})" \
2593 '#define HAVE_TERMCAP
2594 #define HAVE_TERMCAP_CURSES
2595 #define HAVE_TERMINFO' "${1}" << _EOT
2596 #include <stdio.h>
2597 #include <curses.h>
2598 #include <term.h>
2599 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2600 static int my_putc(int c){return putchar(c);}
2601 int main(void){
2602 int er, r0, r1, r2;
2603 char *r3, *tp;
2605 er = OK;
2606 r0 = setupterm(NULL, 1, &er);
2607 r1 = tigetflag(UNCONST("bce"));
2608 r2 = tigetnum(UNCONST("colors"));
2609 r3 = tigetstr(UNCONST("cr"));
2610 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2611 tputs(tp, 1, &my_putc);
2612 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2613 r3 == (char*)-1 || r3 == NULL);
2615 _EOT
2618 if feat_yes TERMCAP_VIA_TERMINFO; then
2619 __terminfolib -ltinfo -ltinfo ||
2620 __terminfolib -lcurses -lcurses ||
2621 __terminfolib -lcursesw -lcursesw ||
2622 feat_bail_required TERMCAP_VIA_TERMINFO
2625 if [ -z "${have_terminfo}" ]; then
2626 __termcaplib -ltermcap '' '' '-ltermcap' ||
2627 __termcaplib -ltermcap '#include <curses.h>' '
2628 #define HAVE_TERMCAP_CURSES' \
2629 'curses.h / -ltermcap' ||
2630 __termcaplib -lcurses '#include <curses.h>' '
2631 #define HAVE_TERMCAP_CURSES' \
2632 'curses.h / -lcurses' ||
2633 __termcaplib -lcursesw '#include <curses.h>' '
2634 #define HAVE_TERMCAP_CURSES' \
2635 'curses.h / -lcursesw' ||
2636 feat_bail_required TERMCAP
2638 if [ -n "${have_termcap}" ]; then
2639 run_check tgetent_null \
2640 "tgetent(3) of termcap(5) takes NULL buffer" \
2641 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2642 #include <stdio.h> /* For C89 NULL */
2643 #include <stdlib.h>
2644 #ifdef HAVE_TERMCAP_CURSES
2645 # include <curses.h>
2646 #endif
2647 #include <term.h>
2648 int main(void){
2649 tgetent(NULL, getenv("TERM"));
2650 return 0;
2652 _EOT
2655 else
2656 echo '/* OPT_TERMCAP=0 */' >> ${h}
2657 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2660 if feat_def SPAM_SPAMC; then
2661 if acmd_set i spamc; then
2662 echo "#define SPAM_SPAMC_PATH \"${i}\"" >> ${h}
2666 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2667 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2668 else
2669 feat_bail_required SPAM_SPAMD
2670 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2673 feat_def SPAM_FILTER
2675 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2676 echo '#define HAVE_SPAM' >> ${h}
2677 else
2678 echo '/* HAVE_SPAM */' >> ${h}
2681 if feat_yes QUOTE_FOLD &&\
2682 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2683 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2684 else
2685 feat_bail_required QUOTE_FOLD
2686 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2689 feat_def FILTER_HTML_TAGSOUP
2690 feat_def COLOUR
2691 feat_def DOTLOCK
2692 feat_def MD5
2693 feat_def NOMEMDBG
2695 ## Summarizing
2697 ${rm} -f ${tmp}
2698 squeeze_em ${inc} ${tmp}
2699 ${mv} ${tmp} ${inc}
2700 squeeze_em ${lib} ${tmp}
2701 ${mv} ${tmp} ${lib}
2703 # mk-config.h
2704 ${mv} ${h} ${tmp}
2705 printf '#ifndef n_MK_CONFIG_H\n# define n_MK_CONFIG_H 1\n' > ${h}
2706 ${cat} ${tmp} >> ${h}
2707 ${rm} -f ${tmp}
2708 printf '\n' >> ${h}
2710 # Create the string that is used by *features* and `version'.
2711 # Take this nice opportunity and generate a visual listing of included and
2712 # non-included features for the person who runs the configuration
2713 msg '\nThe following features are included (+) or not (-):'
2714 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2715 printf '/* The "feature string" */\n' >> ${h}
2716 # Because + is expanded by *folder* if first in "echo $features", put something
2717 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2718 sep=
2719 for opt
2721 sdoc=`option_doc_of ${opt}`
2722 [ -z "${sdoc}" ] && continue
2723 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2724 feat_yes ${opt} && sign=+ || sign=-
2725 printf -- "${sep}${sign}${sopt}" >> ${h}
2726 sep=','
2727 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2728 done
2729 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2730 #exec 5>&1 >>${h}
2731 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2732 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2733 printf '"\n' >> ${h}
2735 # Create the real mk-config.mk
2736 # Note we cannout use explicit ./ filename prefix for source and object
2737 # pathnames because of a bug in bmake(1)
2738 ${rm} -rf ${tmp0}.* ${tmp0}*
2739 srclist= objlist=
2740 if feat_no AMALGAMATION; then
2741 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2742 i=`basename "${i}" .c`
2743 if [ "${i}" = privsep ]; then
2744 continue
2746 objlist="${objlist} ${i}.o"
2747 srclist="${srclist} \$(SRCDIR)${i}.c"
2748 printf '%s: %s\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c %s\n' \
2749 "${i}.o" "\$(SRCDIR)${i}.c" "\$(SRCDIR)${i}.c" >> ${mk}
2750 done
2751 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2752 else
2753 printf '%s:\n\t$(ECHO_CC)$(CC) $(CFLAGS) $(INCS) -c $(SRCDIR)%s\n' \
2754 "main.o" "main.c" >> ${mk}
2755 srclist=main.c objlist=main.o
2756 printf '\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2758 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2759 printf '#elif n_MK_CONFIG_H + 0 == 1\n' >> ${h}
2760 printf '# undef n_MK_CONFIG_H\n' >> ${h}
2761 printf '# define n_MK_CONFIG_H 2\n' >> ${h}
2762 for i in `printf '%s\n' "${SRCDIR}"*.c | ${sort}`; do
2763 i=`basename "${i}"`
2764 if [ "${i}" = main.c ] ||
2765 [ "${i}" = privsep.c ]; then
2766 continue
2768 printf '$(SRCDIR)%s ' "${i}" >> ${mk}
2769 printf '# include "%s%s"\n' "${SRCDIR}" "${i}" >> ${h}
2770 done
2771 echo >> ${mk}
2773 printf 'OBJ_SRC = %s\nOBJ = %s\n' "${srclist}" "${objlist}" >> "${mk}"
2775 printf '#endif /* n_MK_CONFIG_H */\n' >> ${h}
2777 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2778 echo "INCS = `${cat} ${inc}`" >> ${mk}
2779 echo >> ${mk}
2780 ${cat} "${SRCDIR}"make-config.in >> ${mk}
2782 ## Finished!
2784 msg '\nSetup:'
2785 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2786 msg ' . bindir: %s' "${VAL_BINDIR}"
2787 if feat_yes DOTLOCK; then
2788 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2790 msg ' . mandir: %s' "${VAL_MANDIR}"
2791 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2792 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2793 msg ''
2795 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2796 exit 0
2798 msg 'Remarks:'
2799 if [ -z "${have_fnmatch}" ]; then
2800 msg ' . The function fnmatch(3) could not be found.'
2801 msg ' Filename patterns like wildcard are not supported on your system'
2803 if [ -z "${have_fchdir}" ]; then
2804 msg ' . The function fchdir(2) could not be found.'
2805 msg ' We will use chdir(2) instead.'
2806 msg ' This is a problem only if the current working directory is changed'
2807 msg ' while this program is inside of it'
2809 msg ''
2811 # s-it-mode