Tweak previous, it added a bad memory access
[s-mailx.git] / mk-conf.sh
blob96db15845fd36ed271a101ff7708cc193e5dcae4
1 #!/bin/sh -
2 #@ Please see INSTALL and make.rc instead.
4 LC_ALL=C
5 export LC_ALL
7 # The feature set, to be kept in sync with make.rc
8 # If no documentation given, the option is used as such; if doc is a hyphen,
9 # entry is suppressed when configuration overview is printed, and also in the
10 # *features* string: most likely for obsolete features etc.
11 XOPTIONS="\
12 ICONV='Character set conversion using iconv(3)' \
13 SOCKETS='Network support' \
14 SSL='SSL/TLS (OpenSSL / LibreSSL)' \
15 SSL_ALL_ALGORITHMS='Support of all digest and cipher algorithms' \
16 SMTP='Simple Mail Transfer Protocol client' \
17 POP3='Post Office Protocol Version 3 client' \
18 GSSAPI='Generic Security Service authentication' \
19 NETRC='.netrc file support' \
20 AGENT='-' \
21 MD5='MD5 message digest (APOP, CRAM-MD5)' \
22 IDNA='Internationalized Domain Names for Applications (encode only)' \
23 IMAP_SEARCH='IMAP-style search expressions' \
24 REGEX='Regular expressions' \
25 MLE='Mailx Line Editor' \
26 HISTORY='Line editor history management' \
27 KEY_BINDINGS='Configurable key bindings' \
28 TERMCAP='Terminal capability queries (termcap(5))' \
29 TERMCAP_VIA_TERMINFO='Terminal capability queries use terminfo(5)' \
30 ERRORS='Error log message ring' \
31 SPAM_SPAMC='Spam management via spamc(1) of spamassassin(1)' \
32 SPAM_SPAMD='-' \
33 SPAM_FILTER='Freely configurable *spam-filter-..*s' \
34 DOCSTRINGS='Command documentation help strings' \
35 QUOTE_FOLD='Extended *quote-fold*ing' \
36 FILTER_HTML_TAGSOUP='Simple builtin HTML-to-text display filter' \
37 COLOUR='Coloured message display' \
38 DOTLOCK='Dotlock files and privilege-separated dotlock program' \
41 # Options which are automatically deduced from host environment, i.e., these
42 # need special treatment all around here to warp from/to OPT_ stuff
43 # setlocale, C90AMEND1, NL_LANGINFO, wcwidth
44 XOPTIONS_DETECT="\
45 LOCALES='Locale support - printable characters etc. depend on environment' \
46 MULTIBYTE_CHARSETS='Multibyte character sets' \
47 TERMINAL_CHARSET='Automatic detection of terminal character set' \
48 WIDE_GLYPHS='Wide glyph support' \
51 # Rather special options, for custom building, or which always exist.
52 # Mostly for generating the visual overview and the *features* string
53 XOPTIONS_XTRA="\
54 MIME='Multipurpose Internet Mail Extensions' \
55 SMIME='S/MIME message signing, verification, en- and decryption' \
56 CROSS_BUILD='Cross-compilation: trust any detected environment' \
57 DEBUG='Debug enabled binary, not for end-users: THANKS!' \
58 DEVEL='Computers do not blunder' \
61 # The problem is that we don't have any tools we can use right now, so
62 # encapsulate stuff in functions which get called in right order later on
64 option_reset() {
65 set -- ${OPTIONS}
66 for i
68 eval OPT_${i}=0
69 done
72 option_maximal() {
73 set -- ${OPTIONS}
74 for i
76 eval OPT_${i}=1
77 done
78 OPT_ICONV=require
79 OPT_REGEX=require
80 OPT_DOTLOCK=require
83 option_setup() {
84 option_parse OPTIONS_DETECT "${XOPTIONS_DETECT}"
85 option_parse OPTIONS "${XOPTIONS}"
86 option_parse OPTIONS_XTRA "${XOPTIONS_XTRA}"
87 OPT_MIME=1
89 # Predefined CONFIG= urations take precedence over anything else
90 if [ -n "${CONFIG}" ]; then
91 case "${CONFIG}" in
92 [nN][uU][lL][lL])
93 option_reset
95 [nN][uU][lL][lL][iI])
96 option_reset
97 OPT_ICONV=require
99 [mM][iI][nN][iI][mM][aA][lL])
100 option_reset
101 OPT_ICONV=1
102 OPT_REGEX=1
103 OPT_DOTLOCK=require
105 [mM][eE][dD][iI][uU][mM])
106 option_reset
107 OPT_ICONV=require
108 OPT_IDNA=1
109 OPT_REGEX=1
110 OPT_MLE=1
111 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
112 OPT_ERRORS=1
113 OPT_SPAM_FILTER=1
114 OPT_DOCSTRINGS=1
115 OPT_COLOUR=1
116 OPT_DOTLOCK=require
118 [nN][eE][tT][sS][eE][nN][dD])
119 option_reset
120 OPT_ICONV=require
121 OPT_SOCKETS=1
122 OPT_SSL=require
123 OPT_SMTP=require
124 OPT_GSSAPI=1 OPT_NETRC=1 OPT_AGENT=1
125 OPT_IDNA=1
126 OPT_REGEX=1
127 OPT_MLE=1
128 OPT_HISTORY=1 OPT_KEY_BINDINGS=1
129 OPT_DOCSTRINGS=1
130 OPT_COLOUR=1
131 OPT_DOTLOCK=require
133 [mM][aA][xX][iI][mM][aA][lL])
134 option_reset
135 option_maximal
137 [dD][eE][vV][eE][lL])
138 OPT_DEVEL=1 OPT_DEBUG=1 OPT_NYD2=1
139 option_maximal
141 [oO][dD][eE][vV][eE][lL])
142 OPT_DEVEL=1
143 option_maximal
146 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
147 echo >&2 ' NULL, NULLI, MINIMAL, MEDIUM, NETSEND, MAXIMAL'
148 exit 1
150 esac
154 # Inter-relationships
155 option_update() {
156 if feat_no SMTP && feat_no POP3; then
157 OPT_SOCKETS=0
159 if feat_no SOCKETS; then
160 if feat_require SMTP; then
161 msg 'ERROR: need SOCKETS for required feature SMTP'
162 config_exit 13
164 if feat_require POP3; then
165 msg 'ERROR: need SOCKETS for required feature POP3'
166 config_exit 13
168 OPT_SSL=0 OPT_SSL_ALL_ALGORITHMS=0
169 OPT_SMTP=0 OPT_POP3=0
170 OPT_GSSAPI=0 OPT_NETRC=0 OPT_AGENT=0
172 if feat_no SMTP; then
173 OPT_GSSAPI=0
176 if feat_no MLE; then
177 OPT_HISTORY=0 OPT_KEY_BINDINGS=0
180 # If we don't need MD5 leave it alone
181 if feat_no SOCKETS; then
182 OPT_MD5=0
185 if feat_yes DEVEL; then
186 OPT_DEBUG=1
190 rc=./make.rc
191 lst=./config.lst
192 ev=./config.ev
193 h=./config.h h_name=config.h
194 mk=./mk.mk
196 newlst=./config.lst-new
197 newmk=./config.mk-new
198 newev=./config.ev-new
199 newh=./config.h-new
200 tmp0=___tmp
201 tmp=./${tmp0}1$$
202 tmp2=./${tmp0}2$$
204 ## -- >8 - << OPTIONS | OS/CC >> - 8< -- ##
206 # Note that potential duplicates in PATH, C_INCLUDE_PATH etc. will be cleaned
207 # via path_check() later on once possible
209 # TODO cc_maxopt is brute simple, we should compile test program and dig real
210 # compiler versions for known compilers, then be more specific
211 cc_maxopt=100
212 _CFLAGS= _LDFLAGS=
214 os_early_setup() {
215 # We don't "have any utility": only path adjustments and such in here!
216 i="${OS:-`uname -s`}"
218 if [ ${i} = SunOS ]; then
219 msg 'SunOS / Solaris? Applying some "early setup" rules ...'
220 _os_early_setup_sunos
224 _os_early_setup_sunos() {
225 # According to standards(5), this is what we need to do
226 if [ -d /usr/xpg4 ]; then :; else
227 msg 'ERROR: On SunOS / Solaris we need /usr/xpg4 environment! Sorry.'
228 config_exit 1
230 PATH="/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:${PATH}"
231 [ -d /usr/xpg6 ] && PATH="/usr/xpg6/bin:${PATH}"
232 export PATH
235 os_setup() {
236 # OSFULLSPEC is used to recognize changes (i.e., machine type, updates etc.)
237 OSFULLSPEC="${OS:-`uname -a | ${tr} '[A-Z]' '[a-z]'`}"
238 OS="${OS:-`uname -s | ${tr} '[A-Z]' '[a-z]'`}"
239 msg 'Operating system is %s' ${OS}
241 if [ ${OS} = sunos ]; then
242 msg ' . have special SunOS / Solaris "setup" rules ...'
243 _os_setup_sunos
244 elif [ ${OS} = unixware ]; then
245 msg ' . have special UnixWare environmental rules ...'
246 if feat_yes AUTOCC && command -v cc >/dev/null 2>&1; then
247 CC=cc
248 feat_yes DEBUG && _CFLAGS='-v -Xa -g' || _CFLAGS='-Xa -O'
250 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
251 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
252 export CC CFLAGS LDFLAGS
253 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
255 elif [ -n "${VERBOSE}" ]; then
256 msg ' . no special treatment for this system necessary or known'
259 # Sledgehammer: better set _GNU_SOURCE
260 # And in general: oh, boy!
261 OS_DEFINES="${OS_DEFINES}#define _GNU_SOURCE\n"
262 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200809L\n"
263 #OS_DEFINES="${OS_DEFINES}#define _XOPEN_SOURCE 700\n"
264 #[ ${OS} = darwin ] && OS_DEFINES="${OS_DEFINES}#define _DARWIN_C_SOURCE\n"
266 # On pkgsrc(7) systems automatically add /usr/pkg/*
267 if [ -d /usr/pkg ]; then
268 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/usr/pkg/include"
269 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/pkg/lib"
273 _os_setup_sunos() {
274 C_INCLUDE_PATH="/usr/xpg4/include:${C_INCLUDE_PATH}"
275 LD_LIBRARY_PATH="/usr/xpg4/lib:${LD_LIBRARY_PATH}"
277 # Include packages
278 if [ -d /opt/csw ]; then
279 C_INCLUDE_PATH="${C_INCLUDE_PATH}:/opt/csw/include"
280 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/csw/lib"
283 OS_DEFINES="${OS_DEFINES}#define __EXTENSIONS__\n"
284 #OS_DEFINES="${OS_DEFINES}#define _POSIX_C_SOURCE 200112L\n"
286 [ -n "${cksum}" ] || cksum=/opt/csw/gnu/cksum
287 if [ -x "${cksum}" ]; then :; else
288 msg 'ERROR: Not an executable program: %s' "${cksum}"
289 msg 'ERROR: We need a CRC-32 cksum(1), as specified in POSIX.'
290 msg 'ERROR: However, we do so only for tests.'
291 msg 'ERROR: If that is ok, set "cksum=/usr/bin/true", then rerun'
292 config_exit 1
295 if feat_yes AUTOCC; then
296 if command -v cc >/dev/null 2>&1; then
297 CC=cc
298 feat_yes DEBUG && _CFLAGS="-v -Xa -g" || _CFLAGS="-Xa -O"
300 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
301 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
302 export CC CFLAGS LDFLAGS
303 OPT_AUTOCC=0 had_want_autocc=1 need_R_ldflags=-R
304 else
305 # Assume gcc(1), which supports -R for compat
306 cc_maxopt=2 force_no_stackprot=1 need_R_ldflags=-Wl,-R
311 # Check out compiler ($CC) and -flags ($CFLAGS)
312 cc_setup() {
313 # Even though it belongs into cc_flags we will try to compile and link
314 # something, so ensure we have a clean state regarding CFLAGS/LDFLAGS or
315 # EXTRA_CFLAGS/EXTRA_LDFLAGS
316 if feat_no AUTOCC; then
317 _cc_default
318 # Ensure those don't do any harm
319 EXTRA_CFLAGS= EXTRA_LDFLAGS=
320 export EXTRA_CFLAGS EXTRA_LDFLAGS
321 return
322 else
323 CFLAGS= LDFLAGS=
324 export CFLAGS LDFLAGS
327 [ -n "${CC}" ] && [ "${CC}" != cc ] && { _cc_default; return; }
329 msg_nonl 'Searching for a usable C compiler .. $CC='
330 if { i="`command -v clang`"; }; then
331 CC=${i}
332 elif { i="`command -v gcc`"; }; then
333 CC=${i}
334 elif { i="`command -v c99`"; }; then
335 CC=${i}
336 elif { i="`command -v tcc`"; }; then
337 CC=${i}
338 elif { i="`command -v pcc`"; }; then
339 CC=${i}
340 else
341 if [ "${CC}" = cc ]; then
343 elif { i="`command -v c89`"; }; then
344 CC=${i}
345 else
346 msg 'boing booom tschak'
347 msg 'ERROR: I cannot find a compiler!'
348 msg ' Neither of clang(1), gcc(1), tcc(1), pcc(1), c89(1) and c99(1).'
349 msg ' Please set ${CC} environment variable, maybe ${CFLAGS}, rerun.'
350 config_exit 1
353 msg '%s' "${CC}"
354 export CC
357 _cc_default() {
358 if [ -z "${CC}" ]; then
359 msg 'To go on like you have chosen, please set $CC, rerun.'
360 config_exit 1
363 if [ -z "${VERBOSE}" ] && [ -f ${lst} ] && feat_no DEBUG; then
365 else
366 msg 'Using C compiler ${CC}=%s' "${CC}"
370 cc_flags() {
371 if feat_yes AUTOCC; then
372 if [ -f ${lst} ] && feat_no DEBUG && [ -z "${VERBOSE}" ]; then
373 cc_check_silent=1
374 msg 'Detecting ${CFLAGS}/${LDFLAGS} for ${CC}=%s, just a second..' \
375 "${CC}"
376 else
377 cc_check_silent=
378 msg 'Testing usable ${CFLAGS}/${LDFLAGS} for ${CC}=%s' "${CC}"
381 i=`echo "${CC}" | ${awk} 'BEGIN{FS="/"}{print $NF}'`
382 if { echo "${i}" | ${grep} tcc; } >/dev/null 2>&1; then
383 msg ' . have special tcc(1) environmental rules ...'
384 _cc_flags_tcc
385 else
386 # As of pcc CVS 2016-04-02, stack protection support is announced but
387 # will break if used on Linux
388 if { echo "${i}" | ${grep} pcc; } >/dev/null 2>&1; then
389 force_no_stackprot=1
391 _cc_flags_generic
394 feat_no DEBUG && _CFLAGS="-DNDEBUG ${_CFLAGS}"
395 CFLAGS="${_CFLAGS} ${EXTRA_CFLAGS}"
396 LDFLAGS="${_LDFLAGS} ${EXTRA_LDFLAGS}"
397 else
398 if feat_no DEBUG; then
399 CFLAGS="-DNDEBUG ${CFLAGS}"
402 msg ''
403 export CFLAGS LDFLAGS
406 _cc_flags_tcc() {
407 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
408 _CFLAGS= _LDFLAGS=
410 cc_check -Wall
411 cc_check -Wextra
412 cc_check -pedantic
414 if feat_yes DEBUG; then
415 # May have problems to find libtcc cc_check -b
416 cc_check -g
419 if ld_check -Wl,-rpath =./ no; then
420 need_R_ldflags=-Wl,-rpath=
421 ld_check -Wl,--enable-new-dtags
422 ld_runtime_flags # update!
425 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
426 unset __cflags __ldflags
429 _cc_flags_generic() {
430 __cflags=${_CFLAGS} __ldflags=${_LDFLAGS}
431 _CFLAGS= _LDFLAGS=
432 feat_yes DEVEL && cc_check -std=c89 || cc_check -std=c99
434 # Check -g first since some others may rely upon -g / optim. level
435 if feat_yes DEBUG; then
436 cc_check -O
437 cc_check -g
438 elif [ ${cc_maxopt} -gt 2 ] && cc_check -O3; then
440 elif [ ${cc_maxopt} -gt 1 ] && cc_check -O2; then
442 elif [ ${cc_maxopt} -gt 0 ] && cc_check -O1; then
444 else
445 cc_check -O
448 #if feat_yes DEVEL && cc_check -Weverything; then
450 #else
451 cc_check -Wall
452 cc_check -Wextra
453 cc_check -Wbad-function-cast
454 cc_check -Wcast-align
455 cc_check -Wcast-qual
456 cc_check -Winit-self
457 cc_check -Wmissing-prototypes
458 cc_check -Wshadow
459 cc_check -Wunused
460 cc_check -Wwrite-strings
461 cc_check -Wno-long-long
463 cc_check -pedantic
465 if feat_yes AMALGAMATION && feat_no DEVEL; then
466 cc_check -Wno-unused-function
468 feat_no DEVEL && cc_check -Wno-unused-result # XXX do right way (pragma too)
470 cc_check -fno-unwind-tables
471 cc_check -fno-asynchronous-unwind-tables
472 cc_check -fstrict-aliasing
473 if cc_check -fstrict-overflow && feat_yes DEVEL; then
474 cc_check -Wstrict-overflow=5
477 if feat_yes DEBUG || feat_yes FORCED_STACKPROT; then
478 if [ -z "${force_no_stackprot}" ]; then
479 if cc_check -fstack-protector-strong ||
480 cc_check -fstack-protector-all; then
481 cc_check -D_FORTIFY_SOURCE=2
483 else
484 msg 'Not checking for -fstack-protector compiler option,'
485 msg 'since that caused errors in a "similar" configuration.'
486 msg 'You may turn off OPT_AUTOCC and use your own settings, rerun'
490 if feat_yes AMALGAMATION; then
491 cc_check -pipe
494 # LD (+ dependend CC)
496 if feat_yes DEVEL; then
497 _ccfg=${_CFLAGS}
498 # -fsanitize=address
499 #if cc_check -fsanitize=memory &&
500 # ld_check -fsanitize=memory &&
501 # cc_check -fsanitize-memory-track-origins=2 &&
502 # ld_check -fsanitize-memory-track-origins=2; then
504 #else
505 # _CFLAGS=${_ccfg}
509 ld_check -Wl,-z,relro
510 ld_check -Wl,-z,now
511 ld_check -Wl,-z,noexecstack
512 if ld_check -Wl,-rpath =./ no; then
513 need_R_ldflags=-Wl,-rpath=
514 # Choose DT_RUNPATH (after $LD_LIBRARY_PATH) over DT_RPATH (before)
515 ld_check -Wl,--enable-new-dtags
516 ld_runtime_flags # update!
517 elif ld_check -Wl,-R ./ no; then
518 need_R_ldflags=-Wl,-R
519 ld_check -Wl,--enable-new-dtags
520 ld_runtime_flags # update!
523 # Address randomization
524 _ccfg=${_CFLAGS}
525 if cc_check -fPIE || cc_check -fpie; then
526 ld_check -pie || _CFLAGS=${_ccfg}
528 unset _ccfg
530 _CFLAGS="${_CFLAGS} ${__cflags}" _LDFLAGS="${_LDFLAGS} ${__ldflags}"
531 unset __cflags __ldflags
534 ## -- >8 - <<OS/CC | SUPPORT FUNS>> - 8< -- ##
536 ## Notes:
537 ## - Heirloom sh(1) (and same origin) have _sometimes_ problems with ': >'
538 ## redirection, so use "printf '' >" instead
540 ## Very first: we undergo several states regarding I/O redirection etc.,
541 ## but need to deal with option updates from within all. Since all the
542 ## option stuff should be above the scissor line, define utility functions
543 ## and redefine them as necessary.
544 ## And, since we have those functions, simply use them for whatever
546 config_exit() {
547 exit ${1}
550 msg() {
551 fmt=${1}
552 shift
553 printf >&2 -- "${fmt}\\n" "${@}"
556 msg_nonl() {
557 fmt=${1}
558 shift
559 printf >&2 -- "${fmt}" "${@}"
562 t1=ten10one1ten10one1
563 if ( [ ${t1##*ten10} = one1 ] && [ ${t1#*ten10} = one1ten10one1 ] &&
564 [ ${t1%%one1*} = ten10 ] && [ ${t1%one1*} = ten10one1ten10 ]
565 ) > /dev/null 2>&1; then
566 good_shell=1
567 else
568 unset good_shell
570 unset t1
572 # We need some standard utilities
573 unset -f command
574 check_tool() {
575 n=${1} i=${2} opt=${3:-0}
576 # Evaluate, just in case user comes in with shell snippets (..well..)
577 eval i="${i}"
578 if type "${i}" >/dev/null 2>&1; then # XXX why have i type not command -v?
579 [ -n "${VERBOSE}" ] && msg ' . ${%s} ... %s' "${n}" "${i}"
580 eval ${n}=${i}
581 return 0
583 if [ ${opt} -eq 0 ]; then
584 msg 'ERROR: no trace of utility %s' "${n}"
585 config_exit 1
587 return 1
590 # Our feature check environment
591 feat_val_no() {
592 [ "x${1}" = x0 ] || [ "x${1}" = xn ] ||
593 [ "x${1}" = xfalse ] || [ "x${1}" = xno ] || [ "x${1}" = xoff ]
596 feat_val_yes() {
597 [ "x${1}" = x1 ] || [ "x${1}" = xy ] ||
598 [ "x${1}" = xtrue ] || [ "x${1}" = xyes ] || [ "x${1}" = xon ] ||
599 [ "x${1}" = xrequire ]
602 feat_val_require() {
603 [ "x${1}" = xrequire ]
606 _feat_check() {
607 eval i=\$OPT_${1}
608 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
609 if feat_val_no "${i}"; then
610 return 1
611 elif feat_val_yes "${i}"; then
612 return 0
613 else
614 msg "ERROR: %s: 0/n/false/no/off or 1/y/true/yes/on/require, got: %s" \
615 "${1}" "${i}"
616 config_exit 11
620 feat_yes() {
621 _feat_check ${1}
624 feat_no() {
625 _feat_check ${1} && return 1
626 return 0
629 feat_require() {
630 eval i=\$OPT_${1}
631 i="`echo ${i} | ${tr} '[A-Z]' '[a-z]'`"
632 [ "x${i}" = xrequire ] || [ "x${i}" = xrequired ]
635 feat_bail_required() {
636 if feat_require ${1}; then
637 msg 'ERROR: feature OPT_%s is required but not available' "${1}"
638 config_exit 13
640 eval OPT_${1}=0
641 option_update # XXX this is rather useless here (dependency chain..)
644 option_parse() {
645 # Parse one of our XOPTIONS* in $2 and assign the sh(1) compatible list of
646 # options, without documentation, to $1
647 j=\'
648 i="`${awk} -v input=\"${2}\" '
649 BEGIN{
650 for(i = 0;;){
651 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
652 if(voff == 0)
653 break
654 v = substr(input, voff, RLENGTH)
655 input = substr(input, voff + RLENGTH)
656 doff = index(v, "=")
657 if(doff > 0){
658 d = substr(v, doff + 2, length(v) - doff - 1)
659 v = substr(v, 1, doff - 1)
661 print v
665 eval ${1}=\"${i}\"
668 option_doc_of() {
669 # Return the "documentation string" for option $1, itself if none such
670 j=\'
671 ${awk} -v want="${1}" \
672 -v input="${XOPTIONS_DETECT}${XOPTIONS}${XOPTIONS_XTRA}" '
673 BEGIN{
674 for(;;){
675 voff = match(input, /[[:alnum:]_]+(='${j}'[^'${j}']+)?/)
676 if(voff == 0)
677 break
678 v = substr(input, voff, RLENGTH)
679 input = substr(input, voff + RLENGTH)
680 doff = index(v, "=")
681 if(doff > 0){
682 d = substr(v, doff + 2, length(v) - doff - 1)
683 v = substr(v, 1, doff - 1)
684 }else
685 d = v
686 if(v == want){
687 if(d != "-")
688 print d
689 exit
696 option_join_rc() {
697 # Join the values from make.rc into what currently is defined, not
698 # overwriting yet existing settings
699 ${rm} -f ${tmp}
700 # We want read(1) to perform reverse solidus escaping in order to be able to
701 # use multiline values in make.rc; the resulting sh(1)/sed(1) code was very
702 # slow in VMs (see [fa2e248]), Aharon Robbins suggested the following
703 < ${rc} ${awk} 'BEGIN{line = ""}{
704 gsub(/^[[:space:]]+/, "", $0)
705 gsub(/[[:space:]]+$/, "", $0)
706 if(gsub(/\\$/, "", $0)){
707 line = line $0
708 next
709 }else
710 line = line $0
711 if(index(line, "#") == 1){
712 line = ""
713 }else if(length(line)){
714 print line
715 line = ""
717 }' |
718 while read line; do
719 if [ -n "${good_shell}" ]; then
720 i=${line%%=*}
721 else
722 i=`${awk} -v LINE="${line}" 'BEGIN{
723 gsub(/=.*$/, "", LINE)
724 print LINE
727 if [ "${i}" = "${line}" ]; then
728 msg 'ERROR: invalid syntax in: %s' "${line}"
729 continue
732 eval j="\$${i}" jx="\${${i}+x}"
733 if [ -n "${j}" ] || [ "${jx}" = x ]; then
734 : # Yet present
735 else
736 j=`${awk} -v LINE="${line}" 'BEGIN{
737 gsub(/^[^=]*=/, "", LINE)
738 gsub(/^\"*/, "", LINE)
739 gsub(/\"*$/, "", LINE)
740 print LINE
743 [ "${i}" = "DESTDIR" ] && continue
744 echo "${i}=\"${j}\""
745 done > ${tmp}
746 # Reread the mixed version right now
747 . ./${tmp}
750 option_evaluate() {
751 # Expand the option values, which may contain shell snippets
752 ${rm} -f ${newlst} ${newmk} ${newh}
753 exec 5<&0 6>&1 <${tmp} >${newlst}
754 while read line; do
756 if [ -n "${good_shell}" ]; then
757 i=${line%%=*}
758 [ "${i}" != "${i#OPT_}" ] && z=1
759 else
760 i=`${awk} -v LINE="${line}" 'BEGIN{
761 gsub(/=.*$/, "", LINE);\
762 print LINE
764 if echo "${i}" | ${grep} '^OPT_' >/dev/null 2>&1; then
769 eval j=\$${i}
770 if [ -n "${z}" ]; then
771 j="`echo ${j} | ${tr} '[A-Z]' '[a-z]'`"
772 if [ -z "${j}" ] || feat_val_no "${j}"; then
774 printf " /* #undef ${i} */\n" >> ${newh}
775 elif feat_val_yes "${j}"; then
776 if feat_val_require "${j}"; then
777 j=require
778 else
781 printf " /* #define ${i} */\n" >> ${newh}
782 else
783 msg 'ERROR: cannot parse <%s>' "${line}"
784 config_exit 1
786 else
787 printf "#define ${i} \"${j}\"\n" >> ${newh}
789 printf "${i} = ${j}\n" >> ${newmk}
790 printf "${i}=${j}\n"
791 eval "${i}=\"${j}\""
792 done
793 exec 0<&5 1>&6 5<&- 6<&-
796 path_check() {
797 # "path_check VARNAME" or "path_check VARNAME FLAG VARNAME"
798 varname=${1} addflag=${2} flagvarname=${3}
799 j=${IFS}
800 IFS=:
801 eval "set -- \$${1}"
802 IFS=${j}
803 j= k= y= z=
804 for i
806 [ -z "${i}" ] && continue
807 [ -d "${i}" ] || continue
808 # Skip any fakeroot packager environment
809 case "${i}" in *fakeroot*) continue;; esac
810 if [ -n "${j}" ]; then
811 if { z=${y}; echo "${z}"; } | ${grep} ":${i}:" >/dev/null 2>&1; then
813 else
814 y="${y} :${i}:"
815 j="${j}:${i}"
816 [ -n "${addflag}" ] && k="${k} ${addflag}${i}"
818 else
819 y=" :${i}:"
820 j="${i}"
821 [ -n "${addflag}" ] && k="${addflag}${i}"
823 done
824 eval "${varname}=\"${j}\""
825 [ -n "${addflag}" ] && eval "${flagvarname}=\"${k}\""
826 unset varname
829 ld_runtime_flags() {
830 if [ -n "${need_R_ldflags}" ]; then
831 i=${IFS}
832 IFS=:
833 set -- ${LD_LIBRARY_PATH}
834 IFS=${i}
835 for i
837 LDFLAGS="${LDFLAGS} ${need_R_ldflags}${i}"
838 _LDFLAGS="${_LDFLAGS} ${need_R_ldflags}${i}"
839 done
840 export LDFLAGS
842 # Disable it for a possible second run.
843 need_R_ldflags=
846 cc_check() {
847 [ -n "${cc_check_silent}" ] || msg_nonl ' . CC %s .. ' "${1}"
848 if "${CC}" ${INCS} \
849 ${_CFLAGS} ${1} ${EXTRA_CFLAGS} ${_LDFLAGS} ${EXTRA_LDFLAGS} \
850 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
851 _CFLAGS="${_CFLAGS} ${1}"
852 [ -n "${cc_check_silent}" ] || msg 'yes'
853 return 0
855 [ -n "${cc_check_silent}" ] || msg 'no'
856 return 1
859 ld_check() {
860 # $1=option [$2=option argument] [$3=if set, shall NOT be added to _LDFLAGS]
861 [ -n "${cc_check_silent}" ] || msg_nonl ' . LD %s .. ' "${1}"
862 if "${CC}" ${INCS} ${_CFLAGS} ${_LDFLAGS} ${1}${2} ${EXTRA_LDFLAGS} \
863 -o ${tmp2} ${tmp}.c ${LIBS} >/dev/null 2>&1; then
864 [ -n "${3}" ] || _LDFLAGS="${_LDFLAGS} ${1}"
865 [ -n "${cc_check_silent}" ] || msg 'yes'
866 return 0
868 [ -n "${cc_check_silent}" ] || msg 'no'
869 return 1
872 _check_preface() {
873 variable=$1 topic=$2 define=$3
875 echo '**********'
876 msg_nonl ' . %s ... ' "${topic}"
877 echo "/* checked ${topic} */" >> ${h}
878 ${rm} -f ${tmp} ${tmp}.o
879 echo '*** test program is'
880 { echo '#include <'"${h_name}"'>'; cat; } | ${tee} ${tmp}.c
881 #echo '*** the preprocessor generates'
882 #${make} -f ${makefile} ${tmp}.x
883 #${cat} ${tmp}.x
884 echo '*** results are'
887 without_check() {
888 yesno=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
890 echo '**********'
891 msg_nonl ' . %s ... ' "${topic}"
893 echo '*** enforced unchecked results are'
894 if feat_val_yes ${yesno}; then
895 if [ -n "${incs}" ] || [ -n "${libs}" ]; then
896 echo "*** adding INCS<${incs}> LIBS<${libs}>"
897 LIBS="${LIBS} ${libs}"
898 echo "${libs}" >> ${lib}
899 INCS="${INCS} ${incs}"
900 echo "${incs}" >> ${inc}
902 msg 'yes (deduced)'
903 echo "${define}" >> ${h}
904 eval have_${variable}=yes
905 return 0
906 else
907 echo "/* ${define} */" >> ${h}
908 msg 'no (deduced)'
909 eval unset have_${variable}
910 return 1
914 compile_check() {
915 variable=$1 topic=$2 define=$3
917 _check_preface "${variable}" "${topic}" "${define}"
919 if ${make} -f ${makefile} XINCS="${INCS}" \
920 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
921 ./${tmp}.o &&
922 [ -f ./${tmp}.o ]; then
923 msg 'yes'
924 echo "${define}" >> ${h}
925 eval have_${variable}=yes
926 return 0
927 else
928 echo "/* ${define} */" >> ${h}
929 msg 'no'
930 eval unset have_${variable}
931 return 1
935 _link_mayrun() {
936 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
938 _check_preface "${variable}" "${topic}" "${define}"
940 if feat_yes CROSS_BUILD; then
941 if [ ${run} = 1 ]; then
942 run=0
946 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
947 CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
948 XLIBS="${LIBS} ${libs}" \
949 ./${tmp} &&
950 [ -f ./${tmp} ] &&
951 { [ ${run} -eq 0 ] || ./${tmp}; }; then
952 echo "*** adding INCS<${incs}> LIBS<${libs}>; executed: ${run}"
953 msg 'yes'
954 echo "${define}" >> ${h}
955 LIBS="${LIBS} ${libs}"
956 echo "${libs}" >> ${lib}
957 INCS="${INCS} ${incs}"
958 echo "${incs}" >> ${inc}
959 eval have_${variable}=yes
960 return 0
961 else
962 msg 'no'
963 echo "/* ${define} */" >> ${h}
964 eval unset have_${variable}
965 return 1
969 link_check() {
970 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
973 run_check() {
974 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
977 xrun_check() {
978 _link_mayrun 2 "${1}" "${2}" "${3}" "${4}" "${5}"
981 feat_def() {
982 if feat_yes ${1}; then
983 echo '#define HAVE_'${1}'' >> ${h}
984 return 0
985 else
986 echo '/* OPT_'${1}'=0 */' >> ${h}
987 return 1
991 squeeze_em() {
992 < "${1}" > "${2}" ${awk} \
993 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
996 ## -- >8 - <<SUPPORT FUNS | RUNNING>> - 8< -- ##
998 # First of all, create new configuration and check whether it changed
1000 # Very easy checks for the operating system in order to be able to adjust paths
1001 # or similar very basic things which we need to be able to go at all
1002 os_early_setup
1004 # Check those tools right now that we need before including $rc
1005 msg 'Checking for basic utility set'
1006 check_tool awk "${awk:-`command -v awk`}"
1007 check_tool rm "${rm:-`command -v rm`}"
1008 check_tool tr "${tr:-`command -v tr`}"
1010 # Initialize the option set
1011 msg_nonl 'Setting up configuration options ... '
1012 option_setup
1013 msg 'done'
1015 # Include $rc, but only take from it what wasn't overwritten by the user from
1016 # within the command line or from a chosen fixed CONFIG=
1017 # Note we leave alone the values
1018 trap "exit 1" HUP INT TERM
1019 trap "${rm} -f ${tmp}" EXIT
1021 msg_nonl 'Joining in %s ... ' ${rc}
1022 option_join_rc
1023 msg 'done'
1025 # We need to know about that now, in order to provide utility overwrites etc.
1026 os_setup
1028 msg 'Checking for remaining set of utilities'
1029 check_tool grep "${grep:-`command -v grep`}"
1031 # Before we step ahead with the other utilities perform a path cleanup first.
1032 path_check PATH
1034 # awk(1) above
1035 check_tool cat "${cat:-`command -v cat`}"
1036 check_tool chmod "${chmod:-`command -v chmod`}"
1037 check_tool cp "${cp:-`command -v cp`}"
1038 check_tool cmp "${cmp:-`command -v cmp`}"
1039 # grep(1) above
1040 check_tool mkdir "${mkdir:-`command -v mkdir`}"
1041 check_tool mv "${mv:-`command -v mv`}"
1042 # rm(1) above
1043 check_tool sed "${sed:-`command -v sed`}"
1044 check_tool sort "${sort:-`command -v sort`}"
1045 check_tool tee "${tee:-`command -v tee`}"
1047 check_tool chown "${chown:-`command -v chown`}" 1 ||
1048 check_tool chown "/sbin/chown" 1 ||
1049 check_tool chown "/usr/sbin/chown"
1051 check_tool make "${MAKE:-`command -v make`}"
1052 MAKE=${make}
1053 check_tool strip "${STRIP:-`command -v strip`}" 1 &&
1054 HAVE_STRIP=1 || HAVE_STRIP=0
1056 # For ./cc-test.sh only
1057 check_tool cksum "${cksum:-`command -v cksum`}"
1059 # Update OPT_ options now, in order to get possible inter-dependencies right
1060 option_update
1062 # (No functions since some shells loose non-exported variables in traps)
1063 trap "trap \"\" HUP INT TERM; exit 1" HUP INT TERM
1064 trap "trap \"\" HUP INT TERM EXIT;\
1065 ${rm} -rf ${newlst} ${tmp0}.* ${tmp0}* ${newmk} ${newev} ${newh}" EXIT
1067 # Our configuration options may at this point still contain shell snippets,
1068 # we need to evaluate them in order to get them expanded, and we need those
1069 # evaluated values not only in our new configuration file, but also at hand..
1070 msg_nonl 'Evaluating all configuration items ... '
1071 option_evaluate
1072 msg 'done'
1074 # Add the known utility and some other variables
1075 printf "#define VAL_UAGENT \"${VAL_SID}${VAL_MAILX}\"\n" >> ${newh}
1076 printf "VAL_UAGENT = ${VAL_SID}${VAL_MAILX}\n" >> ${newmk}
1078 printf "#define VAL_PRIVSEP \"${VAL_SID}${VAL_MAILX}-privsep\"\n" >> ${newh}
1079 printf "VAL_PRIVSEP = \$(VAL_UAGENT)-privsep\n" >> ${newmk}
1080 if feat_yes DOTLOCK; then
1081 printf "OPTIONAL_PRIVSEP = \$(VAL_PRIVSEP)\n" >> ${newmk}
1082 else
1083 printf "OPTIONAL_PRIVSEP =\n" >> ${newmk}
1086 for i in \
1087 awk cat chmod chown cp cmp grep mkdir mv rm sed sort tee tr \
1088 MAKE MAKEFLAGS make SHELL strip \
1089 cksum; do
1090 eval j=\$${i}
1091 printf "${i} = ${j}\n" >> ${newmk}
1092 printf "${i}=${j}\n" >> ${newlst}
1093 printf "${i}=\"${j}\";export ${i}; " >> ${newev}
1094 done
1095 printf "\n" >> ${newev}
1097 # Build a basic set of INCS and LIBS according to user environment.
1098 path_check C_INCLUDE_PATH -I _INCS
1099 INCS="${INCS} ${_INCS}"
1100 path_check LD_LIBRARY_PATH -L _LIBS
1101 LIBS="${LIBS} ${_LIBS}"
1102 unset _INCS _LIBS
1103 export C_INCLUDE_PATH LD_LIBRARY_PATH
1105 # Some environments need runtime path flags to be able to go at all
1106 ld_runtime_flags
1108 ## Detect CC, whether we can use it, and possibly which CFLAGS we can use
1110 cc_setup
1112 ${cat} > ${tmp}.c << \!
1113 #include <stdio.h>
1114 #include <string.h>
1115 static void doit(char const *s);
1117 main(int argc, char **argv){
1118 (void)argc;
1119 (void)argv;
1120 doit("Hello world");
1121 return 0;
1123 static void
1124 doit(char const *s){
1125 char buf[12];
1126 memcpy(buf, s, strlen(s) +1);
1127 puts(s);
1131 if "${CC}" ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} \
1132 -o ${tmp2} ${tmp}.c ${LIBS}; then
1134 else
1135 msg 'ERROR: i cannot compile a "Hello world" via'
1136 msg ' %s' \
1137 "${CC} ${INCS} ${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS} ${EXTRA_LDFLAGS} ${LIBS}"
1138 msg 'ERROR: Please read INSTALL, rerun'
1139 config_exit 1
1142 # This may also update ld_runtime_flags() (again)
1143 cc_flags
1145 for i in \
1146 INCS LIBS \
1147 ; do
1148 eval j=\$${i}
1149 printf -- "${i}=${j}\n" >> ${newlst}
1150 done
1151 for i in \
1152 CC \
1153 CFLAGS \
1154 LDFLAGS \
1155 PATH C_INCLUDE_PATH LD_LIBRARY_PATH \
1156 OSFULLSPEC \
1157 ; do
1158 eval j=\$${i}
1159 printf -- "${i} = ${j}\n" >> ${newmk}
1160 printf -- "${i}=${j}\n" >> ${newlst}
1161 done
1163 # Now finally check whether we already have a configuration and if so, whether
1164 # all those parameters are still the same.. or something has actually changed
1165 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
1166 echo 'Configuration is up-to-date'
1167 exit 0
1168 elif [ -f ${lst} ]; then
1169 echo 'Configuration has been updated..'
1170 ( eval "${MAKE} -f ./mk.mk clean" )
1171 echo
1172 else
1173 echo 'Shiny configuration..'
1176 # Time to redefine helper 1
1177 config_exit() {
1178 ${rm} -f ${lst} ${h} ${mk}
1179 exit ${1}
1182 ${mv} -f ${newlst} ${lst}
1183 ${mv} -f ${newev} ${ev}
1184 ${mv} -f ${newh} ${h}
1185 ${mv} -f ${newmk} ${mk}
1187 if [ -z "${VERBOSE}" ]; then
1188 printf -- "ECHO_CC = @echo ' 'CC \$(@);\n" >> ${mk}
1189 printf -- "ECHO_LINK = @echo ' 'LINK \$(@);\n" >> ${mk}
1190 printf -- "ECHO_GEN = @echo ' 'GEN \$(@);\n" >> ${mk}
1191 printf -- "ECHO_TEST = @\n" >> ${mk}
1192 printf -- "ECHO_CMD = @echo ' CMD';\n" >> ${mk}
1193 printf -- "ECHO_BLOCK_BEGIN = @( \n" >> ${mk}
1194 printf -- "ECHO_BLOCK_END = ) >/dev/null\n" >> ${mk}
1197 ## Compile and link checking
1199 tmp3=./${tmp0}3$$
1200 log=./config.log
1201 lib=./config.lib
1202 inc=./config.inc
1203 makefile=./config.mk
1205 # (No function since some shells loose non-exported variables in traps)
1206 trap "trap \"\" HUP INT TERM;\
1207 ${rm} -f ${lst} ${h} ${mk} ${lib} ${inc}; exit 1" HUP INT TERM
1208 trap "trap \"\" HUP INT TERM EXIT;\
1209 ${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" EXIT
1211 # Time to redefine helper 2
1212 msg() {
1213 fmt=${1}
1214 shift
1215 printf "*** ${fmt}\\n" "${@}"
1216 printf -- "${fmt}\\n" "${@}" >&5
1218 msg_nonl() {
1219 fmt=${1}
1220 shift
1221 printf "*** ${fmt}\\n" "${@}"
1222 printf -- "${fmt}" "${@}" >&5
1225 # !!
1226 exec 5>&2 > ${log} 2>&1
1228 echo "${LIBS}" > ${lib}
1229 echo "${INCS}" > ${inc}
1230 ${cat} > ${makefile} << \!
1231 .SUFFIXES: .o .c .x .y
1232 .c.o:
1233 $(CC) -I./ $(XINCS) $(CFLAGS) -c $(<)
1234 .c.x:
1235 $(CC) -I./ $(XINCS) -E $(<) > $(@)
1237 $(CC) -I./ $(XINCS) $(CFLAGS) $(LDFLAGS) -o $(@) $(<) $(XLIBS)
1240 ## Generics
1242 # May be multiline..
1243 echo >> ${h}
1244 [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h}
1246 # Generate n_err_number OS mappings
1248 feat_yes DEVEL && NV= || NV=noverbose
1249 TARGET="${h}" awk="${awk}" ./mk-errors.sh ${NV} config
1251 xrun_check oserrno 'OS error mapping table generated' || config_exit 1
1253 feat_def ALWAYS_UNICODE_LOCALE
1254 feat_def AMALGAMATION
1255 feat_def CROSS_BUILD
1256 feat_def DEBUG
1257 feat_def DEVEL
1258 feat_def DOCSTRINGS
1259 feat_def ERRORS
1260 feat_def NYD2
1261 feat_def NOMEMDBG
1263 if xrun_check inline 'inline functions' \
1264 '#define HAVE_INLINE
1265 #define n_INLINE static inline' << \!
1266 static inline int ilf(int i){return ++i;}
1267 int main(void){return ilf(-1);}
1269 then
1271 elif xrun_check inline 'inline functions (via __inline)' \
1272 '#define HAVE_INLINE
1273 #define n_INLINE static __inline' << \!
1274 static __inline int ilf(int i){return ++i;}
1275 int main(void){return ilf(-1);}
1277 then
1281 ## Test for "basic" system-calls / functionality that is used by all parts
1282 ## of our program. Once this is done fork away BASE_LIBS and other BASE_*
1283 ## macros to be used by only the subprograms (potentially).
1285 if run_check clock_gettime 'clock_gettime(2)' \
1286 '#define HAVE_CLOCK_GETTIME' << \!
1287 #include <time.h>
1288 # include <errno.h>
1289 int main(void){
1290 struct timespec ts;
1292 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1293 return 0;
1294 return 1;
1297 then
1299 elif run_check clock_gettime 'clock_gettime(2) (via -lrt)' \
1300 '#define HAVE_CLOCK_GETTIME' '-lrt' << \!
1301 #include <time.h>
1302 # include <errno.h>
1303 int main(void){
1304 struct timespec ts;
1306 if(!clock_gettime(CLOCK_REALTIME, &ts) || errno != ENOSYS)
1307 return 0;
1308 return 1;
1311 then
1313 elif run_check gettimeofday 'gettimeofday(2)' \
1314 '#define HAVE_GETTIMEOFDAY' << \!
1315 #include <stdio.h> /* For C89 NULL */
1316 #include <sys/time.h>
1317 # include <errno.h>
1318 int main(void){
1319 struct timeval tv;
1321 if(!gettimeofday(&tv, NULL) || errno != ENOSYS)
1322 return 0;
1323 return 1;
1326 then
1328 else
1329 have_no_subsecond_time=1
1332 if run_check nanosleep 'nanosleep(2)' \
1333 '#define HAVE_NANOSLEEP' << \!
1334 #include <time.h>
1335 # include <errno.h>
1336 int main(void){
1337 struct timespec ts;
1339 ts.tv_sec = 1;
1340 ts.tv_nsec = 100000;
1341 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1342 return 0;
1343 return 1;
1346 then
1348 elif run_check nanosleep 'nanosleep(2) (via -lrt)' \
1349 '#define HAVE_NANOSLEEP' '-lrt' << \!
1350 #include <time.h>
1351 # include <errno.h>
1352 int main(void){
1353 struct timespec ts;
1355 ts.tv_sec = 1;
1356 ts.tv_nsec = 100000;
1357 if(!nanosleep(&ts, NULL) || errno != ENOSYS)
1358 return 0;
1359 return 1;
1362 then
1364 # link_check is enough for this, that function is so old, trust the proto
1365 elif link_check sleep 'sleep(3)' \
1366 '#define HAVE_SLEEP' << \!
1367 #include <unistd.h>
1368 # include <errno.h>
1369 int main(void){
1370 if(!sleep(1) || errno != ENOSYS)
1371 return 0;
1372 return 1;
1375 then
1377 else
1378 msg 'ERROR: we require one of nanosleep(2) and sleep(3).'
1379 config_exit 1
1382 if run_check userdb 'gete?[gu]id(2), getpwuid(3), getpwnam(3)' << \!
1383 #include <pwd.h>
1384 #include <unistd.h>
1385 # include <errno.h>
1386 int main(void){
1387 struct passwd *pw;
1388 gid_t gid;
1389 uid_t uid;
1391 if((gid = getgid()) != 0)
1392 gid = getegid();
1393 if((uid = getuid()) != 0)
1394 uid = geteuid();
1395 if((pw = getpwuid(uid)) == NULL && errno == ENOSYS)
1396 return 1;
1397 if((pw = getpwnam("root")) == NULL && errno == ENOSYS)
1398 return 1;
1399 return 0;
1402 then
1404 else
1405 msg 'ERROR: we require user and group info / database searches.'
1406 msg 'That much Unix we indulge ourselfs.'
1407 config_exit 1
1410 if link_check ftruncate 'ftruncate(2)' \
1411 '#define HAVE_FTRUNCATE' << \!
1412 #include <unistd.h>
1413 #include <sys/types.h>
1414 int main(void){
1415 return (ftruncate(0, 0) != 0);
1418 then
1420 else
1421 msg 'ERROR: we require the ftruncate(2) system call.'
1422 config_exit 1
1425 if run_check sa_restart 'SA_RESTART (for sigaction(2))' << \!
1426 #include <signal.h>
1427 # include <errno.h>
1428 int main(void){
1429 struct sigaction nact, oact;
1431 nact.sa_handler = SIG_DFL;
1432 sigemptyset(&nact.sa_mask);
1433 nact.sa_flags = SA_RESTART;
1434 return !(!sigaction(SIGCHLD, &nact, &oact) || errno != ENOSYS);
1437 then
1439 else
1440 msg 'ERROR: we (yet) require the SA_RESTART flag for sigaction(2).'
1441 config_exit 1
1444 if link_check snprintf 'snprintf(3)' << \!
1445 #include <stdio.h>
1446 int main(void){
1447 char b[20];
1449 snprintf(b, sizeof b, "%s", "string");
1450 return 0;
1453 then
1455 else
1456 msg 'ERROR: we require the snprintf(3) function.'
1457 config_exit 1
1460 if link_check environ 'environ(3)' << \!
1461 #include <stdio.h> /* For C89 NULL */
1462 int main(void){
1463 extern char **environ;
1465 return environ[0] == NULL;
1468 then
1470 else
1471 msg 'ERROR: we require the environ(3) array for subprocess control.'
1472 config_exit 1
1475 if link_check setenv '(un)?setenv(3)' '#define HAVE_SETENV' << \!
1476 #include <stdlib.h>
1477 int main(void){
1478 setenv("s-mailx", "i want to see it cute!", 1);
1479 unsetenv("s-mailx");
1480 return 0;
1483 then
1485 elif link_check setenv 'putenv(3)' '#define HAVE_PUTENV' << \!
1486 #include <stdlib.h>
1487 int main(void){
1488 putenv("s-mailx=i want to see it cute!");
1489 return 0;
1492 then
1494 else
1495 msg 'ERROR: we require either the setenv(3) or putenv(3) functions.'
1496 config_exit 1
1499 if link_check termios 'termios.h and tc*(3) family' << \!
1500 #include <termios.h>
1501 int main(void){
1502 struct termios tios;
1504 tcgetattr(0, &tios);
1505 tcsetattr(0, TCSANOW | TCSADRAIN | TCSAFLUSH, &tios);
1506 return 0;
1509 then
1511 else
1512 msg 'ERROR: we require termios.h and the tc*() family of functions.'
1513 msg 'That much Unix we indulge ourselfs.'
1514 config_exit 1
1517 ## optional stuff
1519 if link_check vsnprintf 'vsnprintf(3)' << \!
1520 #include <stdarg.h>
1521 #include <stdio.h>
1522 static void dome(char *buf, size_t blen, ...){
1523 va_list ap;
1525 va_start(ap, blen);
1526 vsnprintf(buf, blen, "%s", ap);
1527 va_end(ap);
1529 int main(void){
1530 char b[20];
1532 dome(b, sizeof b, "string");
1533 return 0;
1536 then
1538 else
1539 feat_bail_required ERRORS
1542 if [ "${have_vsnprintf}" = yes ]; then
1543 __va_copy() {
1544 link_check va_copy "va_copy(3) (as ${2})" \
1545 "#define HAVE_N_VA_COPY
1546 #define n_va_copy ${2}" <<_EOT
1547 #include <stdarg.h>
1548 #include <stdio.h>
1549 #if ${1}
1550 # if defined __va_copy && !defined va_copy
1551 # define va_copy __va_copy
1552 # endif
1553 #endif
1554 static void dome2(char *buf, size_t blen, va_list src){
1555 va_list ap;
1557 va_copy(ap, src);
1558 vsnprintf(buf, blen, "%s", ap);
1559 va_end(ap);
1561 static void dome(char *buf, size_t blen, ...){
1562 va_list ap;
1564 va_start(ap, blen);
1565 dome2(buf, blen, ap);
1566 va_end(ap);
1568 int main(void){
1569 char b[20];
1571 dome(b, sizeof b, "string");
1572 return 0;
1574 _EOT
1576 __va_copy 0 va_copy || __va_copy 1 __va_copy
1579 run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \!
1580 #include <unistd.h>
1581 #include <errno.h>
1582 int main(void){
1583 int rv = 0;
1585 errno = 0;
1586 rv |= !(pathconf(".", _PC_NAME_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1587 errno = 0;
1588 rv |= !(pathconf(".", _PC_PATH_MAX) >= 0 || errno == 0 || errno != ENOSYS);
1590 /* Only link check */
1591 fpathconf(0, _PC_NAME_MAX);
1593 return rv;
1597 run_check pipe2 'pipe2(2)' '#define HAVE_PIPE2' << \!
1598 #include <fcntl.h>
1599 #include <unistd.h>
1600 # include <errno.h>
1601 int main(void){
1602 int fds[2];
1604 if(!pipe2(fds, O_CLOEXEC) || errno != ENOSYS)
1605 return 0;
1606 return 1;
1610 # We use this only then for now (need NOW+1)
1611 run_check utimensat 'utimensat(2)' '#define HAVE_UTIMENSAT' << \!
1612 #include <fcntl.h> /* For AT_* */
1613 #include <sys/stat.h>
1614 # include <errno.h>
1615 int main(void){
1616 struct timespec ts[2];
1618 ts[0].tv_nsec = UTIME_NOW;
1619 ts[1].tv_nsec = UTIME_OMIT;
1620 if(!utimensat(AT_FDCWD, "", ts, 0) || errno != ENOSYS)
1621 return 0;
1622 return 1;
1628 # XXX Add POSIX check once standardized
1629 if link_check posix_random 'arc4random(3)' '#define HAVE_POSIX_RANDOM 0' << \!
1630 #include <stdlib.h>
1631 int main(void){
1632 arc4random();
1633 return 0;
1636 then
1638 elif link_check getrandom 'getrandom(2) (in sys/random.h)' \
1639 '#define HAVE_GETRANDOM(B,S) getrandom(B, S, 0)
1640 #define HAVE_GETRANDOM_HEADER <sys/random.h>' <<\!
1641 #include <sys/random.h>
1642 int main(void){
1643 char buf[256];
1644 getrandom(buf, sizeof buf, 0);
1645 return 0;
1648 then
1650 elif link_check getrandom 'getrandom(2) (via syscall(2))' \
1651 '#define HAVE_GETRANDOM(B,S) syscall(SYS_getrandom, B, S, 0)
1652 #define HAVE_GETRANDOM_HEADER <sys/syscall.h>' <<\!
1653 #include <sys/syscall.h>
1654 int main(void){
1655 char buf[256];
1656 syscall(SYS_getrandom, buf, sizeof buf, 0);
1657 return 0;
1660 then
1662 elif [ -n "${have_no_subsecond_time}" ]; then
1663 msg 'ERROR: %s %s' 'without a native random' \
1664 'one of clock_gettime(2) and gettimeofday(2) is required.'
1665 config_exit 1
1669 link_check putc_unlocked 'putc_unlocked(3)' '#define HAVE_PUTC_UNLOCKED' <<\!
1670 #include <stdio.h>
1671 int main(void){
1672 putc_unlocked('@', stdout);
1673 return 0;
1677 link_check fchdir 'fchdir(3)' '#define HAVE_FCHDIR' << \!
1678 #include <unistd.h>
1679 int main(void){
1680 fchdir(0);
1681 return 0;
1685 if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \!
1686 #include <stdlib.h>
1687 int main(void){
1688 char x_buf[4096], *x = realpath(".", x_buf);
1690 return (x != NULL) ? 0 : 1;
1693 then
1694 if run_check realpath_malloc 'realpath(3) takes NULL' \
1695 '#define HAVE_REALPATH_NULL' << \!
1696 #include <stdlib.h>
1697 int main(void){
1698 char *x = realpath(".", NULL);
1700 if(x != NULL)
1701 free(x);
1702 return (x != NULL) ? 0 : 1;
1705 then
1710 ## optional and selectable
1712 if feat_yes DOTLOCK; then
1713 if run_check readlink 'readlink(2)' << \!
1714 #include <unistd.h>
1715 # include <errno.h>
1716 int main(void){
1717 char buf[128];
1719 if(!readlink("here", buf, sizeof buf) || errno != ENOSYS)
1720 return 0;
1721 return 1;
1724 then
1726 else
1727 feat_bail_required DOTLOCK
1731 if feat_yes DOTLOCK; then
1732 if run_check fchown 'fchown(2)' << \!
1733 #include <unistd.h>
1734 # include <errno.h>
1735 int main(void){
1736 if(!fchown(0, 0, 0) || errno != ENOSYS)
1737 return 0;
1738 return 1;
1741 then
1743 else
1744 feat_bail_required DOTLOCK
1748 ## Now it is the time to fork away the BASE_ series
1750 ${rm} -f ${tmp}
1751 squeeze_em ${inc} ${tmp}
1752 ${mv} ${tmp} ${inc}
1753 squeeze_em ${lib} ${tmp}
1754 ${mv} ${tmp} ${lib}
1756 echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk}
1757 echo "BASE_INCS = `${cat} ${inc}`" >> ${mk}
1759 ## The remains are expected to be used only by the main MUA binary!
1761 OPT_LOCALES=0
1762 link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \!
1763 #include <locale.h>
1764 int main(void){
1765 setlocale(LC_ALL, "");
1766 return 0;
1769 [ -n "${have_setlocale}" ] && OPT_LOCALES=1
1771 OPT_MULTIBYTE_CHARSETS=0
1772 OPT_WIDE_GLYPHS=0
1773 OPT_TERMINAL_CHARSET=0
1774 if [ -n "${have_setlocale}" ]; then
1775 link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \
1776 '#define HAVE_C90AMEND1' << \!
1777 #include <limits.h>
1778 #include <stdlib.h>
1779 #include <wchar.h>
1780 #include <wctype.h>
1781 int main(void){
1782 char mbb[MB_LEN_MAX + 1];
1783 wchar_t wc;
1785 iswprint(L'c');
1786 towupper(L'c');
1787 mbtowc(&wc, "x", 1);
1788 mbrtowc(&wc, "x", 1, NULL);
1789 wctomb(mbb, wc);
1790 return (mblen("\0", 1) == 0);
1793 [ -n "${have_c90amend1}" ] && OPT_MULTIBYTE_CHARSETS=1
1795 if [ -n "${have_c90amend1}" ]; then
1796 link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \!
1797 #include <wchar.h>
1798 int main(void){
1799 wcwidth(L'c');
1800 return 0;
1803 [ -n "${have_wcwidth}" ] && OPT_WIDE_GLYPHS=1
1806 link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \!
1807 #include <langinfo.h>
1808 #include <stdlib.h>
1809 int main(void){
1810 nl_langinfo(DAY_1);
1811 return (nl_langinfo(CODESET) == NULL);
1814 [ -n "${have_nl_langinfo}" ] && OPT_TERMINAL_CHARSET=1
1815 fi # have_setlocale
1817 link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \!
1818 #include <fnmatch.h>
1819 int main(void){
1820 return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH);
1824 link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \!
1825 #include <dirent.h>
1826 int main(void){
1827 struct dirent de;
1828 return !(de.d_type == DT_UNKNOWN ||
1829 de.d_type == DT_DIR || de.d_type == DT_LNK);
1833 ## optional and selectable
1835 if feat_yes ICONV; then
1836 ${cat} > ${tmp2}.c << \!
1837 #include <stdio.h> /* For C89 NULL */
1838 #include <iconv.h>
1839 int main(void){
1840 iconv_t id;
1842 id = iconv_open("foo", "bar");
1843 iconv(id, NULL, NULL, NULL, NULL);
1844 iconv_close(id);
1845 return 0;
1848 < ${tmp2}.c link_check iconv 'iconv(3) functionality' \
1849 '#define HAVE_ICONV' ||
1850 < ${tmp2}.c link_check iconv 'iconv(3) functionality (via -liconv)' \
1851 '#define HAVE_ICONV' '-liconv' ||
1852 feat_bail_required ICONV
1853 else
1854 echo '/* OPT_ICONV=0 */' >> ${h}
1855 fi # feat_yes ICONV
1857 if feat_yes SOCKETS || feat_yes SPAM_SPAMD; then
1858 ${cat} > ${tmp2}.c << \!
1859 #include <sys/types.h>
1860 #include <sys/socket.h>
1861 #include <sys/un.h>
1862 # include <errno.h>
1863 int main(void){
1864 struct sockaddr_un soun;
1866 if(socket(AF_UNIX, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1867 return 1;
1868 if(connect(0, (struct sockaddr*)&soun, 0) == -1 && errno == ENOSYS)
1869 return 1;
1870 if(shutdown(0, SHUT_RD | SHUT_WR | SHUT_RDWR) == -1 && errno == ENOSYS)
1871 return 1;
1872 return 0;
1876 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets' \
1877 '#define HAVE_UNIX_SOCKETS' ||
1878 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lnsl)' \
1879 '#define HAVE_UNIX_SOCKETS' '-lnsl' ||
1880 < ${tmp2}.c run_check af_unix 'AF_UNIX sockets (via -lsocket -lnsl)' \
1881 '#define HAVE_UNIX_SOCKETS' '-lsocket -lnsl'
1884 if feat_yes SOCKETS; then
1885 ${cat} > ${tmp2}.c << \!
1886 #include <sys/types.h>
1887 #include <sys/socket.h>
1888 #include <netinet/in.h>
1889 # include <errno.h>
1890 int main(void){
1891 struct sockaddr s;
1893 if(socket(AF_INET, SOCK_STREAM, 0) == -1 && errno == ENOSYS)
1894 return 1;
1895 if(connect(0, &s, 0) == -1 && errno == ENOSYS)
1896 return 1;
1897 return 0;
1901 < ${tmp2}.c run_check sockets 'sockets' \
1902 '#define HAVE_SOCKETS' ||
1903 < ${tmp2}.c run_check sockets 'sockets (via -lnsl)' \
1904 '#define HAVE_SOCKETS' '-lnsl' ||
1905 < ${tmp2}.c run_check sockets 'sockets (via -lsocket -lnsl)' \
1906 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
1907 feat_bail_required SOCKETS
1908 else
1909 echo '/* OPT_SOCKETS=0 */' >> ${h}
1910 fi # feat_yes SOCKETS
1912 if feat_yes SOCKETS; then
1913 link_check getaddrinfo 'getaddrinfo(3)' \
1914 '#define HAVE_GETADDRINFO' << \!
1915 #include <sys/types.h>
1916 #include <sys/socket.h>
1917 #include <stdio.h>
1918 #include <netdb.h>
1919 int main(void){
1920 struct addrinfo a, *ap;
1921 int lrv;
1923 switch((lrv = getaddrinfo("foo", "0", &a, &ap))){
1924 case EAI_NONAME:
1925 case EAI_SERVICE:
1926 default:
1927 fprintf(stderr, "%s\n", gai_strerror(lrv));
1928 case 0:
1929 break;
1931 return 0;
1936 if feat_yes SOCKETS && [ -z "${have_getaddrinfo}" ]; then
1937 compile_check arpa_inet_h '<arpa/inet.h>' \
1938 '#define HAVE_ARPA_INET_H' << \!
1939 #include <sys/types.h>
1940 #include <sys/socket.h>
1941 #include <netdb.h>
1942 #include <netinet/in.h>
1943 #include <arpa/inet.h>
1946 ${cat} > ${tmp2}.c << \!
1947 #include <sys/types.h>
1948 #include <sys/socket.h>
1949 #include <stdio.h>
1950 #include <string.h>
1951 #include <netdb.h>
1952 #include <netinet/in.h>
1953 #ifdef HAVE_ARPA_INET_H
1954 #include <arpa/inet.h>
1955 #endif
1956 int main(void){
1957 struct sockaddr_in servaddr;
1958 unsigned short portno;
1959 struct servent *ep;
1960 struct hostent *hp;
1961 struct in_addr **pptr;
1963 portno = 0;
1964 if((ep = getservbyname("POPPY-PORT", "tcp")) != NULL)
1965 portno = (unsigned short)ep->s_port;
1967 if((hp = gethostbyname("POPPY-HOST")) != NULL){
1968 pptr = (struct in_addr**)hp->h_addr_list;
1969 if(hp->h_addrtype != AF_INET)
1970 fprintf(stderr, "au\n");
1971 }else{
1972 switch(h_errno){
1973 case HOST_NOT_FOUND:
1974 case TRY_AGAIN:
1975 case NO_RECOVERY:
1976 case NO_DATA:
1977 break;
1978 default:
1979 fprintf(stderr, "au\n");
1980 break;
1984 memset(&servaddr, 0, sizeof servaddr);
1985 servaddr.sin_family = AF_INET;
1986 servaddr.sin_port = htons(portno);
1987 memcpy(&servaddr.sin_addr, *pptr, sizeof(struct in_addr));
1988 fprintf(stderr, "Would connect to %s:%d ...\n",
1989 inet_ntoa(**pptr), (int)portno);
1990 return 0;
1994 < ${tmp2}.c link_check gethostbyname 'get(serv|host)byname(3)' ||
1995 < ${tmp2}.c link_check gethostbyname \
1996 'get(serv|host)byname(3) (via -nsl)' '' '-lnsl' ||
1997 < ${tmp2}.c link_check gethostbyname \
1998 'get(serv|host)byname(3) (via -lsocket -nsl)' \
1999 '' '-lsocket -lnsl' ||
2000 feat_bail_required SOCKETS
2003 feat_yes SOCKETS &&
2004 run_check setsockopt 'setsockopt(2)' '#define HAVE_SETSOCKOPT' << \!
2005 #include <sys/socket.h>
2006 #include <stdlib.h>
2007 # include <errno.h>
2008 int main(void){
2009 int sockfd = 3;
2011 if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == -1 &&
2012 errno == ENOSYS)
2013 return 1;
2014 return 0;
2018 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2019 link_check so_sndtimeo 'SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
2020 #include <sys/socket.h>
2021 #include <stdlib.h>
2022 int main(void){
2023 struct timeval tv;
2024 int sockfd = 3;
2026 tv.tv_sec = 42;
2027 tv.tv_usec = 21;
2028 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
2029 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
2030 return 0;
2034 feat_yes SOCKETS && [ -n "${have_setsockopt}" ] &&
2035 link_check so_linger 'SO_LINGER' '#define HAVE_SO_LINGER' << \!
2036 #include <sys/socket.h>
2037 #include <stdlib.h>
2038 int main(void){
2039 struct linger li;
2040 int sockfd = 3;
2042 li.l_onoff = 1;
2043 li.l_linger = 42;
2044 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
2045 return 0;
2049 if feat_yes SSL; then # {{{
2050 # {{{ LibreSSL decided to define OPENSSL_VERSION_NUMBER with a useless value
2051 # instead of keeping it at the one that corresponds to the OpenSSL at fork
2052 # time: we need to test it first in order to get things right
2053 if compile_check _xssl 'TLS/SSL (LibreSSL)' \
2054 '#define HAVE_SSL
2055 #define HAVE_XSSL
2056 #define HAVE_XSSL_RESSL
2057 #define HAVE_XSSL_OPENSSL 0' << \!
2058 #include <openssl/opensslv.h>
2059 #ifdef LIBRESSL_VERSION_NUMBER
2060 #else
2061 # error nope
2062 #endif
2064 then
2065 ossl_v1_1=
2066 # TODO OPENSSL_IS_BORINGSSL, but never tried that one!
2067 elif compile_check _xssl 'TLS/SSL (OpenSSL >= v1.1.0)' \
2068 '#define HAVE_SSL
2069 #define HAVE_XSSL
2070 #define HAVE_XSSL_OPENSSL 0x10100' << \!
2071 #include <openssl/opensslv.h>
2072 #if OPENSSL_VERSION_NUMBER + 0 >= 0x10100000L
2073 #else
2074 # error nope
2075 #endif
2077 then
2078 ossl_v1_1=1
2079 elif compile_check _xssl 'TLS/SSL (OpenSSL)' \
2080 '#define HAVE_SSL
2081 #define HAVE_XSSL
2082 #define HAVE_XSSL_OPENSSL 0x10000' << \!
2083 #include <openssl/opensslv.h>
2084 #ifdef OPENSSL_VERSION_NUMBER
2085 #else
2086 # error nope
2087 #endif
2089 then
2090 ossl_v1_1=
2091 else
2092 feat_bail_required SSL
2093 fi # }}}
2095 if feat_yes SSL; then # {{{
2096 if [ -n "${ossl_v1_1}" ]; then
2097 without_check yes xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2098 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2099 '-lssl -lcrypto'
2100 elif link_check xssl 'TLS/SSL (new style *_client_method(3ssl))' \
2101 '#define n_XSSL_CLIENT_METHOD TLS_client_method' \
2102 '-lssl -lcrypto' << \!
2103 #include <openssl/ssl.h>
2104 #include <openssl/err.h>
2105 #include <openssl/x509v3.h>
2106 #include <openssl/x509.h>
2107 #include <openssl/rand.h>
2108 #ifdef OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2109 # error We need TLSv1.
2110 #endif
2111 int main(void){
2112 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
2114 SSL_CTX_free(ctx);
2115 PEM_read_PrivateKey(0, 0, 0, 0);
2116 return 0;
2119 then
2121 elif link_check xssl 'TLS/SSL (old style *_client_method(3ssl))' \
2122 '#define n_XSSL_CLIENT_METHOD SSLv23_client_method' \
2123 '-lssl -lcrypto' << \!
2124 #include <openssl/ssl.h>
2125 #include <openssl/err.h>
2126 #include <openssl/x509v3.h>
2127 #include <openssl/x509.h>
2128 #include <openssl/rand.h>
2129 #if defined OPENSSL_NO_SSL3 &&\
2130 defined OPENSSL_NO_TLS1 /* TODO only deduced from OPENSSL_NO_SSL[23]! */
2131 # error We need one of SSLv3 and TLSv1.
2132 #endif
2133 int main(void){
2134 SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
2136 SSL_CTX_free(ctx);
2137 PEM_read_PrivateKey(0, 0, 0, 0);
2138 return 0;
2141 then
2143 else
2144 feat_bail_required SSL
2146 fi # }}}
2148 if feat_yes SSL; then # {{{
2149 if [ -n "${ossl_v1_1}" ]; then
2150 without_check yes xssl_stack_of 'TLS/SSL STACK_OF()' \
2151 '#define HAVE_XSSL_STACK_OF'
2152 elif compile_check xssl_stack_of 'TLS/SSL STACK_OF()' \
2153 '#define HAVE_XSSL_STACK_OF' << \!
2154 #include <stdio.h> /* For C89 NULL */
2155 #include <openssl/ssl.h>
2156 #include <openssl/err.h>
2157 #include <openssl/x509v3.h>
2158 #include <openssl/x509.h>
2159 #include <openssl/rand.h>
2160 int main(void){
2161 STACK_OF(GENERAL_NAME) *gens = NULL;
2163 printf("%p", gens); /* to use it */
2164 return 0;
2167 then
2171 if [ -n "${ossl_v1_1}" ]; then
2172 without_check yes xssl_conf 'TLS/SSL OpenSSL_modules_load_file()' \
2173 '#define HAVE_XSSL_CONFIG'
2174 elif link_check xssl_conf 'TLS/SSL OpenSSL_modules_load_file() support' \
2175 '#define HAVE_XSSL_CONFIG' << \!
2176 #include <stdio.h> /* For C89 NULL */
2177 #include <openssl/conf.h>
2178 int main(void){
2179 CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_IGNORE_MISSING_FILE);
2180 CONF_modules_free();
2181 return 0;
2184 then
2188 if [ -n "${ossl_v1_1}" ]; then
2189 without_check yes xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2190 '#define HAVE_XSSL_CONF_CTX'
2191 elif link_check xssl_conf_ctx 'TLS/SSL SSL_CONF_CTX support' \
2192 '#define HAVE_XSSL_CONF_CTX' << \!
2193 #include <openssl/ssl.h>
2194 #include <openssl/err.h>
2195 int main(void){
2196 SSL_CTX *ctx = SSL_CTX_new(n_XSSL_CLIENT_METHOD());
2197 SSL_CONF_CTX *cctx = SSL_CONF_CTX_new();
2199 SSL_CONF_CTX_set_flags(cctx,
2200 SSL_CONF_FLAG_FILE | SSL_CONF_FLAG_CLIENT |
2201 SSL_CONF_FLAG_CERTIFICATE | SSL_CONF_FLAG_SHOW_ERRORS);
2202 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
2203 SSL_CONF_cmd(cctx, "Protocol", "ALL");
2204 SSL_CONF_CTX_finish(cctx);
2205 SSL_CONF_CTX_free(cctx);
2206 SSL_CTX_free(ctx);
2207 return 0;
2210 then
2214 if [ -n "${ossl_v1_1}" ]; then
2215 without_check no xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2216 '#define HAVE_XSSL_RAND_EGD'
2217 elif link_check xssl_rand_egd 'TLS/SSL RAND_egd(3ssl)' \
2218 '#define HAVE_XSSL_RAND_EGD' << \!
2219 #include <openssl/rand.h>
2220 int main(void){
2221 return RAND_egd("some.where") > 0;
2224 then
2228 if feat_yes SSL_ALL_ALGORITHMS; then
2229 if [ -n "${ossl_v1_1}" ]; then
2230 without_check yes ssl_all_algo 'TLS/SSL all-algorithms support' \
2231 '#define HAVE_SSL_ALL_ALGORITHMS'
2232 elif link_check ssl_all_algo 'TLS/SSL all-algorithms support' \
2233 '#define HAVE_SSL_ALL_ALGORITHMS' << \!
2234 #include <openssl/evp.h>
2235 int main(void){
2236 OpenSSL_add_all_algorithms();
2237 EVP_get_cipherbyname("two cents i never exist");
2238 EVP_cleanup();
2239 return 0;
2242 then
2244 else
2245 feat_bail_required SSL_ALL_ALGORITHMS
2248 fi # feat_yes SSL }}}
2250 if feat_yes SSL && feat_yes MD5 && feat_no NOEXTMD5; then # {{{
2251 run_check ssl_md5 'MD5 digest in the used crypto library' \
2252 '#define HAVE_XSSL_MD5' << \!
2253 #include <stdlib.h>
2254 #include <string.h>
2255 #include <openssl/md5.h>
2256 int main(void){
2257 char const dat[] = "abrakadabrafidibus";
2258 char dig[16], hex[16 * 2];
2259 MD5_CTX ctx;
2260 size_t i, j;
2262 memset(dig, 0, sizeof(dig));
2263 memset(hex, 0, sizeof(hex));
2264 MD5_Init(&ctx);
2265 MD5_Update(&ctx, dat, sizeof(dat) - 1);
2266 MD5_Final(dig, &ctx);
2268 #define hexchar(n) ((n) > 9 ? (n) - 10 + 'a' : (n) + '0')
2269 for(i = 0; i < sizeof(hex) / 2; i++){
2270 j = i << 1;
2271 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
2272 hex[++j] = hexchar(dig[i] & 0x0f);
2274 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
2277 fi # }}}
2278 else
2279 echo '/* OPT_SSL=0 */' >> ${h}
2280 fi # }}} feat_yes SSL
2282 if [ "${have_xssl}" = yes ]; then
2283 OPT_SMIME=1
2284 else
2285 OPT_SMIME=0
2287 feat_def SMIME
2289 feat_def SMTP
2290 feat_def POP3
2292 if feat_yes GSSAPI; then
2293 ${cat} > ${tmp2}.c << \!
2294 #include <gssapi/gssapi.h>
2295 int main(void){
2296 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
2297 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2298 return 0;
2301 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
2303 if command -v krb5-config >/dev/null 2>&1; then
2304 i=`command -v krb5-config`
2305 GSS_LIBS="`CFLAGS= ${i} --libs gssapi`"
2306 GSS_INCS="`CFLAGS= ${i} --cflags`"
2307 i='GSS-API via krb5-config(1)'
2308 else
2309 GSS_LIBS='-lgssapi'
2310 GSS_INCS=
2311 i='GSS-API in gssapi/gssapi.h, libgssapi'
2313 if < ${tmp2}.c link_check gss \
2314 "${i}" '#define HAVE_GSSAPI' "${GSS_LIBS}" "${GSS_INCS}" ||\
2315 < ${tmp3}.c link_check gss \
2316 'GSS-API in gssapi.h, libgssapi' \
2317 '#define HAVE_GSSAPI
2318 #define GSSAPI_REG_INCLUDE' \
2319 '-lgssapi' ||\
2320 < ${tmp2}.c link_check gss 'GSS-API in libgssapi_krb5' \
2321 '#define HAVE_GSSAPI' \
2322 '-lgssapi_krb5' ||\
2323 < ${tmp3}.c link_check gss \
2324 'GSS-API in libgssapi, OpenBSD-style (pre 5.3)' \
2325 '#define HAVE_GSSAPI
2326 #define GSS_REG_INCLUDE' \
2327 '-lgssapi -lkrb5 -lcrypto' \
2328 '-I/usr/include/kerberosV' ||\
2329 < ${tmp2}.c link_check gss 'GSS-API in libgss' \
2330 '#define HAVE_GSSAPI' \
2331 '-lgss' ||\
2332 link_check gss 'GSS-API in libgssapi_krb5, old-style' \
2333 '#define HAVE_GSSAPI
2334 #define GSSAPI_OLD_STYLE' \
2335 '-lgssapi_krb5' << \!
2336 #include <gssapi/gssapi.h>
2337 #include <gssapi/gssapi_generic.h>
2338 int main(void){
2339 gss_import_name(0, 0, gss_nt_service_name, 0);
2340 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
2341 return 0;
2344 then
2346 else
2347 feat_bail_required GSSAPI
2349 else
2350 echo '/* OPT_GSSAPI=0 */' >> ${h}
2351 fi # feat_yes GSSAPI
2353 feat_def NETRC
2354 feat_def AGENT
2356 if feat_yes IDNA; then
2357 if link_check idna 'GNU Libidn' '#define HAVE_IDNA HAVE_IDNA_LIBIDNA' \
2358 '-lidn' << \!
2359 #include <idna.h>
2360 #include <idn-free.h>
2361 #include <stringprep.h>
2362 int main(void){
2363 char *utf8, *idna_ascii, *idna_utf8;
2365 utf8 = stringprep_locale_to_utf8("does.this.work");
2366 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
2367 != IDNA_SUCCESS)
2368 return 1;
2369 idn_free(idna_ascii);
2370 /* (Rather link check only here) */
2371 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
2372 return 0;
2375 then
2377 elif link_check idna 'idnkit' '#define HAVE_IDNA HAVE_IDNA_IDNKIT' \
2378 '-lidnkit' << \!
2379 #include <stdio.h>
2380 #include <idn/api.h>
2381 #include <idn/result.h>
2382 int main(void){
2383 idn_result_t r;
2384 char ace_name[256];
2385 char local_name[256];
2387 r = idn_encodename(IDN_ENCODE_APP, "does.this.work", ace_name,
2388 sizeof(ace_name));
2389 if (r != idn_success) {
2390 fprintf(stderr, "idn_encodename failed: %s\n", idn_result_tostring(r));
2391 return 1;
2393 r = idn_decodename(IDN_DECODE_APP, ace_name, local_name, sizeof(local_name));
2394 if (r != idn_success) {
2395 fprintf(stderr, "idn_decodename failed: %s\n", idn_result_tostring(r));
2396 return 1;
2398 return 0;
2401 then
2403 else
2404 feat_bail_required IDNA
2407 if [ -n "${have_idna}" ]; then
2408 echo '#define HAVE_IDNA_LIBIDNA 0' >> ${h}
2409 echo '#define HAVE_IDNA_IDNKIT 1' >> ${h}
2411 else
2412 echo '/* OPT_IDNA=0 */' >> ${h}
2415 feat_def IMAP_SEARCH
2417 if feat_yes REGEX; then
2418 if link_check regex 'regular expressions' '#define HAVE_REGEX' << \!
2419 #include <regex.h>
2420 #include <stdlib.h>
2421 int main(void){
2422 size_t xret;
2423 int status;
2424 regex_t re;
2426 status = regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB);
2427 xret = regerror(status, &re, NULL, 0);
2428 status = regexec(&re, "plan9", 0,NULL, 0);
2429 regfree(&re);
2430 return !(status == REG_NOMATCH);
2433 then
2435 else
2436 feat_bail_required REGEX
2438 else
2439 echo '/* OPT_REGEX=0 */' >> ${h}
2442 if feat_yes MLE && [ -n "${have_c90amend1}" ]; then
2443 have_mle=1
2444 echo '#define HAVE_MLE' >> ${h}
2445 else
2446 feat_bail_required MLE
2447 echo '/* OPT_MLE=0 */' >> ${h}
2450 # Generic have-a-line-editor switch for those who need it below
2451 if [ -n "${have_mle}" ]; then
2452 have_cle=1
2455 if [ -n "${have_cle}" ] && feat_yes HISTORY; then
2456 echo '#define HAVE_HISTORY' >> ${h}
2457 else
2458 echo '/* OPT_HISTORY=0 */' >> ${h}
2461 if [ -n "${have_mle}" ] && feat_yes KEY_BINDINGS; then
2462 echo '#define HAVE_KEY_BINDINGS' >> ${h}
2463 else
2464 echo '/* OPT_KEY_BINDINGS=0 */' >> ${h}
2467 if feat_yes TERMCAP; then
2468 __termcaplib() {
2469 link_check termcap "termcap(5) (via ${4})" \
2470 "#define HAVE_TERMCAP${3}" "${1}" << _EOT
2471 #include <stdio.h>
2472 #include <stdlib.h>
2473 ${2}
2474 #include <term.h>
2475 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2476 static int my_putc(int c){return putchar(c);}
2477 int main(void){
2478 char buf[1024+512], cmdbuf[2048], *cpb, *r1;
2479 int r2 = OK, r3 = ERR;
2481 tgetent(buf, getenv("TERM"));
2482 cpb = cmdbuf;
2483 r1 = tgetstr(UNCONST("cm"), &cpb);
2484 tgoto(r1, 1, 1);
2485 r2 = tgetnum(UNCONST("Co"));
2486 r3 = tgetflag(UNCONST("ut"));
2487 tputs("cr", 1, &my_putc);
2488 return (r1 == NULL || r2 == -1 || r3 == 0);
2490 _EOT
2493 __terminfolib() {
2494 link_check terminfo "terminfo(5) (via ${2})" \
2495 '#define HAVE_TERMCAP
2496 #define HAVE_TERMCAP_CURSES
2497 #define HAVE_TERMINFO' "${1}" << _EOT
2498 #include <stdio.h>
2499 #include <curses.h>
2500 #include <term.h>
2501 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
2502 static int my_putc(int c){return putchar(c);}
2503 int main(void){
2504 int er, r0, r1, r2;
2505 char *r3, *tp;
2507 er = OK;
2508 r0 = setupterm(NULL, 1, &er);
2509 r1 = tigetflag(UNCONST("bce"));
2510 r2 = tigetnum(UNCONST("colors"));
2511 r3 = tigetstr(UNCONST("cr"));
2512 tp = tparm(r3, NULL, NULL, 0,0,0,0,0,0,0);
2513 tputs(tp, 1, &my_putc);
2514 return (r0 == ERR || r1 == -1 || r2 == -2 || r2 == -1 ||
2515 r3 == (char*)-1 || r3 == NULL);
2517 _EOT
2520 if feat_yes TERMCAP_VIA_TERMINFO; then
2521 __terminfolib -ltinfo -ltinfo ||
2522 __terminfolib -lcurses -lcurses ||
2523 __terminfolib -lcursesw -lcursesw ||
2524 feat_bail_required TERMCAP_VIA_TERMINFO
2527 if [ -z "${have_terminfo}" ]; then
2528 __termcaplib -ltermcap '' '' '-ltermcap' ||
2529 __termcaplib -ltermcap '#include <curses.h>' '
2530 #define HAVE_TERMCAP_CURSES' \
2531 'curses.h / -ltermcap' ||
2532 __termcaplib -lcurses '#include <curses.h>' '
2533 #define HAVE_TERMCAP_CURSES' \
2534 'curses.h / -lcurses' ||
2535 __termcaplib -lcursesw '#include <curses.h>' '
2536 #define HAVE_TERMCAP_CURSES' \
2537 'curses.h / -lcursesw' ||
2538 feat_bail_required TERMCAP
2540 if [ -n "${have_termcap}" ]; then
2541 run_check tgetent_null \
2542 "tgetent(3) of termcap(5) takes NULL buffer" \
2543 "#define HAVE_TGETENT_NULL_BUF" << _EOT
2544 #include <stdio.h> /* For C89 NULL */
2545 #include <stdlib.h>
2546 #ifdef HAVE_TERMCAP_CURSES
2547 # include <curses.h>
2548 #endif
2549 #include <term.h>
2550 int main(void){
2551 tgetent(NULL, getenv("TERM"));
2552 return 0;
2554 _EOT
2557 else
2558 echo '/* OPT_TERMCAP=0 */' >> ${h}
2559 echo '/* OPT_TERMCAP_VIA_TERMINFO=0 */' >> ${h}
2562 if feat_def SPAM_SPAMC; then
2563 if command -v spamc >/dev/null 2>&1; then
2564 echo "#define SPAM_SPAMC_PATH \"`command -v spamc`\"" >> ${h}
2568 if feat_yes SPAM_SPAMD && [ -n "${have_af_unix}" ]; then
2569 echo '#define HAVE_SPAM_SPAMD' >> ${h}
2570 else
2571 feat_bail_required SPAM_SPAMD
2572 echo '/* OPT_SPAM_SPAMD=0 */' >> ${h}
2575 feat_def SPAM_FILTER
2577 if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then
2578 echo '#define HAVE_SPAM' >> ${h}
2579 else
2580 echo '/* HAVE_SPAM */' >> ${h}
2583 if feat_yes QUOTE_FOLD &&\
2584 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
2585 echo '#define HAVE_QUOTE_FOLD' >> ${h}
2586 else
2587 feat_bail_required QUOTE_FOLD
2588 echo '/* OPT_QUOTE_FOLD=0 */' >> ${h}
2591 feat_def FILTER_HTML_TAGSOUP
2592 feat_def COLOUR
2593 feat_def DOTLOCK
2594 feat_def MD5
2595 feat_def NOMEMDBG
2597 ## Summarizing
2599 ${rm} -f ${tmp}
2600 squeeze_em ${inc} ${tmp}
2601 ${mv} ${tmp} ${inc}
2602 squeeze_em ${lib} ${tmp}
2603 ${mv} ${tmp} ${lib}
2605 # config.h
2606 ${mv} ${h} ${tmp}
2607 printf '#ifndef n_CONFIG_H\n# define n_CONFIG_H 1\n' > ${h}
2608 ${cat} ${tmp} >> ${h}
2609 ${rm} -f ${tmp}
2610 printf '\n' >> ${h}
2612 # Create the real mk.mk
2613 # Note we cannout use explicit ./ filename prefix for source and object
2614 # pathnames because of a bug in bmake(1)
2615 ${rm} -rf ${tmp0}.* ${tmp0}*
2616 printf 'OBJ_SRC = ' >> ${mk}
2617 if feat_no AMALGAMATION; then
2618 for i in `printf '%s\n' *.c | ${sort}`; do
2619 if [ "${i}" = privsep.c ]; then
2620 continue
2622 printf "${i} " >> ${mk}
2623 done
2624 printf '\nAMALGAM_TARGET =\nAMALGAM_DEP =\n' >> ${mk}
2625 else
2626 printf 'main.c\nAMALGAM_TARGET = main.o\nAMALGAM_DEP = ' >> ${mk}
2628 printf '\n/* HAVE_AMALGAMATION: include sources */\n' >> ${h}
2629 printf '#elif _CONFIG_H + 0 == 1\n' >> ${h}
2630 printf '# undef _CONFIG_H\n' >> ${h}
2631 printf '# define _CONFIG_H 2\n' >> ${h}
2632 for i in `printf '%s\n' *.c | ${sort}`; do
2633 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ] || \
2634 [ "${i}" = privsep.c ]; then
2635 continue
2637 printf "${i} " >> ${mk}
2638 printf "# include \"${i}\"\n" >> ${h}
2639 done
2640 echo >> ${mk}
2641 # tcc(1) fails on 2015-11-13 unless this #else clause existed
2642 echo '#else' >> ${h}
2645 # Finally, create the string that is used by *features* and `version'.
2646 # Take this nice opportunity and generate a visual listing of included and
2647 # non-included features for the person who runs the configuration
2648 msg '\nThe following features are included (+) or not (-):'
2649 set -- ${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}
2650 printf '/* The "feature string" */\n' >> ${h}
2651 # Because + is expanded by *folder* if first in "echo $features", put something
2652 printf '#define VAL_FEATURES_CNT '${#}'\n#define VAL_FEATURES "#' >> ${h}
2653 sep=
2654 for opt
2656 sdoc=`option_doc_of ${opt}`
2657 [ -z "${sdoc}" ] && continue
2658 sopt="`echo ${opt} | ${tr} '[A-Z]_' '[a-z]-'`"
2659 feat_yes ${opt} && sign=+ || sign=-
2660 printf -- "${sep}${sign}${sopt}" >> ${h}
2661 sep=','
2662 msg " %s %s: %s" ${sign} ${sopt} "${sdoc}"
2663 done
2664 # TODO instead of using sh+tr+awk+printf, use awk, drop option_doc_of, inc here
2665 #exec 5>&1 >>${h}
2666 #${awk} -v opts="${OPTIONS_DETECT} ${OPTIONS} ${OPTIONS_XTRA}" \
2667 # -v xopts="${XOPTIONS_DETECT} ${XOPTIONS} ${XOPTIONS_XTRA}" \
2669 printf '"\n#endif /* n_CONFIG_H */\n' >> ${h}
2671 echo "LIBS = `${cat} ${lib}`" >> ${mk}
2672 echo "INCS = `${cat} ${inc}`" >> ${mk}
2673 echo >> ${mk}
2674 ${cat} ./mk-mk.in >> ${mk}
2676 ## Finished!
2678 msg '\nSetup:'
2679 msg ' . System-wide resource file: %s/%s' "${VAL_SYSCONFDIR}" "${VAL_SYSCONFRC}"
2680 msg ' . bindir: %s' "${VAL_BINDIR}"
2681 if feat_yes DOTLOCK; then
2682 msg ' . libexecdir: %s' "${VAL_LIBEXECDIR}"
2684 msg ' . mandir: %s' "${VAL_MANDIR}"
2685 msg ' . M(ail)T(ransfer)A(gent): %s (argv0 %s)' "${VAL_MTA}" "${VAL_MTA_ARGV0}"
2686 msg ' . $MAIL spool directory: %s' "${VAL_MAIL}"
2687 msg ''
2689 if [ -n "${have_fnmatch}" ] && [ -n "${have_fchdir}" ]; then
2690 exit 0
2692 msg 'Remarks:'
2693 if [ -z "${have_fnmatch}" ]; then
2694 msg ' . The function fnmatch(3) could not be found.'
2695 msg ' Filename patterns like wildcard are not supported on your system'
2697 if [ -z "${have_fchdir}" ]; then
2698 msg ' . The function fchdir(2) could not be found.'
2699 msg ' We will use chdir(2) instead.'
2700 msg ' This is a problem only if the current working directory is changed'
2701 msg ' while this program is inside of it'
2703 msg ''
2705 # s-it-mode