conf.rc,mk-conf.sh+: NetBSD sh(1) can't 'command -pv' (Ypnose)
[s-mailx.git] / mk-conf.sh
blobd011ccf73d74e76ee585e8650128370e3d2ea6b8
1 #!/bin/sh -
2 #@ Please see `INSTALL' and `conf.rc' instead.
4 LC_ALL=C
5 export LC_ALL
7 # Predefined CONFIG= urations take precedence over anything else
8 if [ -n "${CONFIG}" ]; then
9 case ${CONFIG} in
10 MINIMAL)
11 WANT_SOCKETS=0
12 WANT_IDNA=0
13 WANT_READLINE=0 WANT_EDITLINE=0 WANT_NCL=0
14 WANT_REGEX=0
15 WANT_SPAM=0
16 WANT_DOCSTRINGS=0
17 WANT_QUOTE_FOLD=0
18 WANT_COLOUR=0
20 MEDIUM)
21 WANT_SOCKETS=0
22 WANT_IDNA=0
23 WANT_READLINE=0 WANT_EDITLINE=0
24 WANT_REGEX=0
25 WANT_SPAM=0
26 WANT_QUOTE_FOLD=0
27 WANT_COLOUR=0
29 NETSEND)
30 WANT_IMAP=0
31 WANT_POP3=0
32 WANT_READLINE=0 WANT_EDITLINE=0
33 WANT_REGEX=0
34 WANT_SPAM=0
35 WANT_QUOTE_FOLD=0
36 WANT_COLOUR=0
39 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
40 echo >&2 'Possible values: MINIMAL, MEDIUM, NETSEND'
41 exit 1
42 esac
45 # Inter-relationships
46 option_update() {
47 if nwantfeat SOCKETS; then
48 WANT_IPV6=0 WANT_SSL=0
49 WANT_IMAP=0 WANT_GSSAPI=0 WANT_POP3=0 WANT_SMTP=0
51 if nwantfeat IMAP && nwantfeat POP3 && nwantfeat SMTP; then
52 WANT_SOCKETS=0 WANT_IPV6=0 WANT_SSL=0
54 if nwantfeat IMAP; then
55 WANT_GSSAPI=0
57 # If we don't need MD5 except for producing boundary and message-id strings,
58 # leave it off, plain old srand(3) should be enough for that purpose.
59 if nwantfeat SOCKETS; then
60 WANT_MD5=0
62 if wantfeat DEBUG; then
63 WANT_NOALLOCA=1
67 # Check out compiler ($CC) and -flags ($CFLAGS)
68 compiler_flags() {
69 i=`uname -s`
70 _CFLAGS=
72 # $CC is overwritten when empty or a default "cc", even without WANT_AUTOCC
73 if [ -z "${CC}" ] || [ "${CC}" = cc ]; then
74 _CFLAGS=
75 if { CC="`command -v clang`"; }; then
77 elif { CC="`command -v gcc`"; }; then
79 elif { CC="`command -v c89`"; }; then
80 [ "${i}" = UnixWare ] && _CFLAGS='-v -O'
81 elif { CC="`command -v c99`"; }; then
83 else
84 echo >&2 'ERROR'
85 echo >&2 ' I cannot find a compiler!'
86 echo >&2 ' Neither of clang(1), gcc(1), c89(1) and c99(1).'
87 echo >&2 ' Please set the CC environment variable, maybe CFLAGS also.'
88 exit 1
91 export CC
93 ccver=`${CC} --version 2>/dev/null`
94 stackprot=no
95 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e gcc -e clang; then
96 #if echo "${i}" | ${grep} -q -i -e gcc -e 'clang version 1'; then
97 stackprot=yes
98 _CFLAGS='-std=c89 -O2'
99 _CFLAGS="${_CFLAGS} -Wall -Wextra -pedantic"
100 _CFLAGS="${_CFLAGS} -fno-unwind-tables -fno-asynchronous-unwind-tables"
101 _CFLAGS="${_CFLAGS} -fstrict-aliasing"
102 _CFLAGS="${_CFLAGS} -Wbad-function-cast -Wcast-align -Wcast-qual"
103 _CFLAGS="${_CFLAGS} -Winit-self -Wshadow -Wunused -Wwrite-strings"
104 if { i=$ccver; echo "${i}"; } | ${grep} -q -e 'clang version 1'; then
106 else
107 _CFLAGS="${_CFLAGS} -fstrict-overflow -Wstrict-overflow=5"
108 if wantfeat AMALGAMATION && nwantfeat DEBUG; then
109 _CFLAGS="${_CFLAGS} -Wno-unused-function"
111 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
112 _CFLAGS="${_CFLAGS} -Wno-unused-result" # TODO handle the right way
115 _CFLAGS="${_CFLAGS} -Wno-long-long" # ISO C89 has no 'long long'...
116 # elif { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
117 # stackprot=yes
118 # _CFLAGS='-std=c89 -O3 -g -Weverything -Wno-long-long'
119 elif [ -z "${_CFLAGS}" ]; then
120 _CFLAGS=-O1
123 if nwantfeat DEBUG; then
124 _CFLAGS="${_CFLAGS} -DNDEBUG"
125 else
126 _CFLAGS="${_CFLAGS} -g";
127 if [ "${stackprot}" = yes ]; then
128 _CFLAGS="${_CFLAGS} -fstack-protector-all "
129 _CFLAGS="${_CFLAGS} -Wstack-protector -D_FORTIFY_SOURCE=2"
132 _CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
133 _LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}" # XXX -Wl,--sort-common,[-O1]
134 export _CFLAGS _LDFLAGS
136 # $CFLAGS and $LDFLAGS are only overwritten if explicitly wanted
137 if wantfeat AUTOCC; then
138 CFLAGS=$_CFLAGS
139 LDFLAGS=$_LDFLAGS
140 export CFLAGS LDFLAGS
144 ## -- >8 -- 8< -- ##
146 ## Notes:
147 ## - Heirloom sh(1) (and same origin) have problems with ': >' redirection,
148 ## so use "printf '' >" instead
149 ## - Heirloom sh(1) and maybe more execute loops with redirection in a subshell
150 ## (but don't export eval's from within), therefore we need to (re)include
151 ## variable assignments at toplevel instead (via reading temporary files)
153 ## First of all, create new configuration and check wether it changed ##
155 conf=./conf.rc
156 lst=./config.lst
157 h=./config.h
158 mk=./mk.mk
160 newlst=./config.lst-new
161 newmk=./config.mk-new
162 newh=./config.h-new
163 tmp0=___tmp
164 tmp=./${tmp0}1$$
166 # We need some standard utilities
167 unset -f command
168 check_tool() {
169 n=$1 i=$2 opt=${3:-0}
170 if type "${i}" >/dev/null 2>&1; then
171 eval ${n}=${i}
172 return 1
174 if [ ${opt} -eq 0 ]; then
175 echo >&2 "ERROR: no trace of the utility \`${n}'"
176 exit 1
178 return 0
181 # Check those tools right now that we need before including ${conf}
182 check_tool rm "${rm:-`command -v rm`}"
183 check_tool sed "${sed:-`command -v sed`}"
185 # Only incorporate what wasn't overwritten from command line / CONFIG
186 trap "${rm} -f ${tmp}; exit" 1 2 15
187 trap "${rm} -f ${tmp}" 0
188 ${rm} -f ${tmp}
190 < ${conf} ${sed} -e '/^[ \t]*#/d' -e '/^$/d' -e 's/[ \t]*$//' |
191 while read line; do
192 i=`echo ${line} | ${sed} -e 's/=.*$//'`
193 eval j=\$${i} jx=\${${i}+x}
194 if [ -n "${j}" ] || [ "${jx}" = x ]; then
195 line="${i}=\"${j}\""
197 echo ${line}
198 done > ${tmp}
199 . ./${tmp}
201 check_tool awk "${awk:-`command -v awk`}"
202 check_tool cat "${cat:-`command -v cat`}"
203 check_tool chmod "${chmod:-`command -v chmod`}"
204 check_tool cp "${cp:-`command -v cp`}"
205 check_tool cmp "${cmp:-`command -v cmp`}"
206 check_tool grep "${grep:-`command -v grep`}"
207 check_tool mkdir "${mkdir:-`command -v mkdir`}"
208 check_tool mv "${mv:-`command -v mv`}"
209 # rm(1), sed(1) above
210 check_tool tee "${tee:-`command -v tee`}"
212 check_tool make "${MAKE:-`command -v make`}"
213 check_tool strip "${STRIP:-`command -v strip`}" 1
214 HAVE_STRIP=${?}
216 wantfeat() {
217 eval i=\$WANT_${1}
218 [ "${i}" = "1" ]
220 nwantfeat() {
221 eval i=\$WANT_${1}
222 [ "${i}" != "1" ]
225 option_update
227 # (No function since some shells loose non-exported variables in traps)
228 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}; exit" 1 2 15
229 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}" 0
230 ${rm} -f ${newlst} ${newmk} ${newh}
232 # (Could: use FD redirection, add eval(1) and don't re-'. ./${newlst}')
233 while read line; do
234 i=`echo ${line} | ${sed} -e 's/=.*$//'`
235 eval j=\$${i}
236 if [ -z "${j}" ] || [ "${j}" = 0 ]; then
237 printf "/*#define ${i}*/\n" >> ${newh}
238 elif [ "${j}" = 1 ]; then
239 printf "#define ${i}\n" >> ${newh}
240 else
241 printf "#define ${i} \"${j}\"\n" >> ${newh}
243 printf "${i} = ${j}\n" >> ${newmk}
244 printf "${i}=\"${j}\"\n"
245 done < ${tmp} > ${newlst}
246 . ./${newlst}
248 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
249 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
251 compiler_flags
253 printf "CC = ${CC}\n" >> ${newmk}
254 printf "_CFLAGS = ${_CFLAGS}\nCFLAGS = ${CFLAGS}\n" >> ${newmk}
255 printf "_LDFLAGS = ${_LDFLAGS}\nLDFLAGS = ${LDFLAGS}\n" >> ${newmk}
256 printf "AWK = ${awk}\nCMP = ${cmp}\nCHMOD = ${chmod}\nCP = ${cp}\n" >> ${newmk}
257 printf "MKDIR = ${mkdir}\nRM = ${rm}\nSED = ${sed}\n" >> ${newmk}
258 printf "STRIP = ${strip}\nHAVE_STRIP = ${HAVE_STRIP}\n" >> ${newmk}
259 # (We include the cc(1)/ld(1) environment only for update detection..)
260 printf "CC=\"${CC}\"\n" >> ${newlst}
261 printf "_CFLAGS=\"${_CFLAGS}\"\nCFLAGS=\"${CFLAGS}\"\n" >> ${newlst}
262 printf "_LDFLAGS=\"${_LDFLAGS}\"\nLDFLAGS=\"${LDFLAGS}\"\n" >> ${newlst}
263 printf "AWK=${awk}\nCMP=${cmp}\nCHMOD=${chmod}\nCP=${cp}\n" >> ${newlst}
264 printf "MKDIR=${mkdir}\nRM=${rm}\nSED=${sed}\n" >> ${newlst}
265 printf "STRIP=${strip}\nHAVE_STRIP=${HAVE_STRIP}\n" >> ${newlst}
267 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
268 exit 0
270 [ -f ${lst} ] && echo 'configuration updated..' || echo 'shiny configuration..'
272 ${mv} -f ${newlst} ${lst}
273 ${mv} -f ${newh} ${h}
274 ${mv} -f ${newmk} ${mk}
276 ## Compile and link checking ##
278 tmp2=./${tmp0}2$$
279 tmp3=./${tmp0}3$$
280 log=./config.log
281 lib=./config.lib
282 inc=./config.inc
283 src=./config.c
284 makefile=./config.mk
286 # (No function since some shells loose non-exported variables in traps)
287 trap "${rm} -f ${lst} ${h} ${mk} ${lib} ${inc} ${src} ${makefile}; exit" 1 2 15
288 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" 0
290 exec 5>&2 > ${log} 2>&1
291 printf '' > ${lib}
292 printf '' > ${inc}
293 # ${src} is only created if WANT_AMALGAMATION
294 ${rm} -f ${src}
295 ${cat} > ${makefile} << \!
296 .SUFFIXES: .o .c .x .y
297 .c.o:
298 $(CC) $(XINCS) -c $<
299 .c.x:
300 $(CC) $(XINCS) -E $< >$@
302 $(CC) $(XINCS) -o $@ $< $(XLIBS)
303 .y: ;
306 msg() {
307 fmt=$1
309 shift
310 printf "*** ${fmt}\\n" "${@}"
311 printf "${fmt}" "${@}" >&5
314 _check_preface() {
315 variable=$1 topic=$2 define=$3
317 echo '**********'
318 msg "checking ${topic} ... "
319 echo "/* checked ${topic} */" >> ${h}
320 ${rm} -f ${tmp} ${tmp}.o
321 echo '*** test program is'
322 ${tee} ${tmp}.c
323 #echo '*** the preprocessor generates'
324 #${make} -f ${makefile} ${tmp}.x
325 #${cat} ${tmp}.x
326 echo '*** results are'
329 compile_check() {
330 variable=$1 topic=$2 define=$3
332 _check_preface "${variable}" "${topic}" "${define}"
334 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
335 [ -f ./${tmp}.o ]; then
336 msg "yes\\n"
337 echo "${define}" >> ${h}
338 eval have_${variable}=yes
339 return 0
340 else
341 echo "/* ${define} */" >> ${h}
342 msg "no\\n"
343 eval unset have_${variable}
344 return 1
348 _link_mayrun() {
349 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
351 _check_preface "${variable}" "${topic}" "${define}"
353 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
354 XLIBS="${LIBS} ${libs}" ./${tmp} &&
355 [ -f ./${tmp} ] &&
356 { [ ${run} -eq 0 ] || ./${tmp}; }; then
357 echo "*** adding INCS<${incs}> LIBS<${libs}>"
358 msg "yes\\n"
359 echo "${define}" >> ${h}
360 LIBS="${LIBS} ${libs}"
361 echo "${libs}" >> ${lib}
362 INCS="${INCS} ${incs}"
363 echo "${incs}" >> ${inc}
364 eval have_${variable}=yes
365 return 0
366 else
367 msg "no\\n"
368 echo "/* ${define} */" >> ${h}
369 eval unset have_${variable}
370 return 1
374 link_check() {
375 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
378 run_check() {
379 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
382 # Build a basic set of INCS and LIBS according to user environment.
383 # On pkgsrc(7) systems automatically add /usr/pkg/*
384 if [ -n "${C_INCLUDE_PATH}" ]; then
385 i=${IFS}
386 IFS=:
387 set -- ${C_INCLUDE_PATH}
388 IFS=${i}
389 # for i; do -- new in POSIX Issue 7 + TC1
390 for i
392 [ "${i}" = '/usr/pkg/include' ] && continue
393 INCS="${INCS} -I${i}"
394 done
396 [ -d /usr/pkg/include ] && INCS="${INCS} -I/usr/pkg/include"
397 echo "${INCS}" >> ${inc}
399 if [ -n "${LD_LIBRARY_PATH}" ]; then
400 i=${IFS}
401 IFS=:
402 set -- ${LD_LIBRARY_PATH}
403 IFS=${i}
404 # for i; do -- new in POSIX Issue 7 + TC1
405 for i
407 [ "${i}" = '/usr/pkg/lib' ] && continue
408 LIBS="${LIBS} -L${i}"
409 done
411 [ -d /usr/pkg/lib ] && LIBS="${LIBS} -L/usr/pkg/lib"
412 echo "${LIBS}" >> ${lib}
416 # Better set _GNU_SOURCE (if we are on Linux only?); 'surprised it did without
417 echo '#define _GNU_SOURCE' >> ${h}
419 link_check hello 'if a hello world program can be built' << \! || {\
420 echo >&5 'This oooops is most certainly not related to me.';\
421 echo >&5 "Read the file ${log} and check your compiler environment.";\
422 ${rm} -f ${lst} ${h} ${mk};\
423 exit 1;\
425 #include <stdio.h>
427 int main(int argc, char *argv[])
429 (void)argc;
430 (void)argv;
431 puts("hello world");
432 return 0;
436 link_check termios 'for termios.h and tc*() family' << \! || {\
437 echo >&5 'We require termios.h and the tc*() family of functions.';\
438 echo >&5 "That much Unix we indulge ourselfs.";\
439 ${rm} -f ${lst} ${h} ${mk};\
440 exit 1;\
442 #include <termios.h>
443 int main(void)
445 struct termios tios;
446 tcgetattr(0, &tios);
447 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
448 return 0;
452 link_check setenv 'for setenv()/unsetenv()' '#define HAVE_SETENV' << \!
453 #include <stdlib.h>
454 int main(void)
456 setenv("s-nail", "to be made nifty!", 1);
457 unsetenv("s-nail");
458 return 0;
462 link_check snprintf 'for snprintf()' '#define HAVE_SNPRINTF' << \!
463 #include <stdio.h>
464 int main(void)
466 char b[20];
467 snprintf(b, sizeof b, "%s", "string");
468 return 0;
472 link_check putc_unlocked 'for putc_unlocked()' '#define HAVE_PUTC_UNLOCKED' <<\!
473 #include <stdio.h>
474 int main(void)
476 putc_unlocked('@', stdout);
477 return 0;
481 link_check fchdir 'for fchdir()' '#define HAVE_FCHDIR' << \!
482 #include <unistd.h>
483 int main(void)
485 fchdir(0);
486 return 0;
490 link_check mmap 'for mmap()' '#define HAVE_MMAP' << \!
491 #include <sys/types.h>
492 #include <sys/mman.h>
493 int main(void)
495 mmap(0, 0, 0, 0, 0, 0);
496 return 0;
500 link_check mremap 'for mremap()' '#define HAVE_MREMAP' << \!
501 #include <sys/types.h>
502 #include <sys/mman.h>
503 int main(void)
505 mremap(0, 0, 0, MREMAP_MAYMOVE);
506 return 0;
510 link_check setlocale 'for setlocale()' '#define HAVE_SETLOCALE' << \!
511 #include <locale.h>
512 int main(void)
514 setlocale(LC_ALL, "");
515 return 0;
519 if [ "${have_setlocale}" = yes ]; then
520 link_check c90amend1 'for ISO/IEC 9899:1990/Amendment 1:1995' \
521 '#define HAVE_C90AMEND1' << \!
522 #include <limits.h>
523 #include <stdlib.h>
524 #include <wchar.h>
525 #include <wctype.h>
526 int main(void)
528 char mbb[MB_LEN_MAX + 1];
529 wchar_t wc;
530 iswprint(L'c');
531 towupper(L'c');
532 mbtowc(&wc, "x", 1);
533 mbrtowc(&wc, "x", 1, NULL);
534 (void)wctomb(mbb, wc);
535 return (mblen("\0", 1) == 0);
539 if [ "${have_c90amend1}" = yes ]; then
540 link_check wcwidth 'for wcwidth()' '#define HAVE_WCWIDTH' << \!
541 #include <wchar.h>
542 int main(void)
544 wcwidth(L'c');
545 return 0;
550 link_check nl_langinfo 'for nl_langinfo()' '#define HAVE_NL_LANGINFO' << \!
551 #include <langinfo.h>
552 #include <stdlib.h>
553 int main(void)
555 nl_langinfo(DAY_1);
556 return (nl_langinfo(CODESET) == NULL);
559 fi # have_setlocale
561 link_check mkstemp 'for mkstemp()' '#define HAVE_MKSTEMP' << \!
562 #include <stdlib.h>
563 int main(void)
565 mkstemp("x");
566 return 0;
570 # Note: run_check, thus we also get only the desired implementation...
571 run_check realpath 'for realpath()' '#define HAVE_REALPATH' << \!
572 #include <stdlib.h>
573 int main(void)
575 char *x = realpath(".", NULL), *y = realpath("/", NULL);
576 return (x != NULL && y != NULL) ? 0 : 1;
580 link_check wordexp 'for wordexp()' '#define HAVE_WORDEXP' << \!
581 #include <wordexp.h>
582 int main(void)
584 wordexp((char *)0, (wordexp_t *)0, 0);
585 return 0;
591 if wantfeat DEBUG; then
592 echo '#define HAVE_DEBUG' >> ${h}
595 if wantfeat AMALGAMATION; then
596 echo '#define HAVE_AMALGAMATION' >> ${h}
599 if nwantfeat NOALLOCA; then
600 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
601 # versions of alloca(3) since modern compilers just can't be trusted
602 # not to overoptimize and silently break some code
603 link_check alloca 'for __builtin_alloca()' \
604 '#define HAVE_ALLOCA __builtin_alloca' << \!
605 int main(void)
607 void *vp = __builtin_alloca(1);
608 return (!! vp);
613 if nwantfeat NOGETOPT; then
614 link_check getopt 'for getopt()' '#define HAVE_GETOPT' << \!
615 #include <unistd.h>
616 int main(int argc, char **argv)
618 #if defined __GLIBC__ || defined __linux__
619 Argument and option reordering is not a desired feature.
620 #else
621 getopt(argc, argv, "oPt");
622 #endif
623 return (((long)optarg + optind) & 0x7F);
630 if wantfeat ICONV; then
631 ${cat} > ${tmp2}.c << \!
632 #include <iconv.h>
633 int main(void)
635 iconv_t id;
637 id = iconv_open("foo", "bar");
638 return 0;
641 < ${tmp2}.c link_check iconv 'for iconv functionality' \
642 '#define HAVE_ICONV' ||
643 < ${tmp2}.c link_check iconv \
644 'for iconv functionality in libiconv' \
645 '#define HAVE_ICONV' '-liconv'
646 else
647 echo '/* WANT_ICONV=0 */' >> ${h}
648 fi # wantfeat ICONV
650 if wantfeat SOCKETS; then
651 compile_check arpa_inet_h 'for <arpa/inet.h>' \
652 '#define HAVE_ARPA_INET_H' << \!
653 #include "config.h"
654 #include <sys/types.h>
655 #include <sys/socket.h>
656 #include <netdb.h>
657 #include <netinet/in.h>
658 #include <arpa/inet.h>
661 ${cat} > ${tmp2}.c << \!
662 #include "config.h"
663 #include <sys/types.h>
664 #include <sys/socket.h>
665 #include <netdb.h>
666 #include <netinet/in.h>
667 #ifdef HAVE_ARPA_INET_H
668 #include <arpa/inet.h>
669 #endif
671 int main(void)
673 struct sockaddr s;
674 socket(AF_INET, SOCK_STREAM, 0);
675 connect(0, &s, 0);
676 gethostbyname("foo");
677 return 0;
681 < ${tmp2}.c link_check sockets 'for sockets in libc' \
682 '#define HAVE_SOCKETS' ||
683 < ${tmp2}.c link_check sockets 'for sockets in libnsl' \
684 '#define HAVE_SOCKETS' '-lnsl' ||
685 < ${tmp2}.c link_check sockets \
686 'for sockets in libsocket and libnsl' \
687 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
688 WANT_SOCKETS=0
690 # XXX Shouldn't it be a hard error if there is no socket support, then?
691 option_update
692 else
693 echo '/* WANT_SOCKETS=0 */' >> ${h}
694 fi # wantfeat SOCKETS
696 wantfeat SOCKETS &&
697 link_check setsockopt 'for setsockopt()' '#define HAVE_SETSOCKOPT' << \!
698 #include <sys/socket.h>
699 #include <stdlib.h>
700 int main(void)
702 int sockfd = 3;
703 setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0);
704 return 0;
708 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
709 link_check so_sndtimeo 'for SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
710 #include <sys/socket.h>
711 #include <stdlib.h>
712 int main(void)
714 struct timeval tv;
715 int sockfd = 3;
716 tv.tv_sec = 42;
717 tv.tv_usec = 21;
718 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
719 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
720 return 0;
724 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
725 link_check so_linger 'for SO_LINGER' '#define HAVE_SO_LINGER' << \!
726 #include <sys/socket.h>
727 #include <stdlib.h>
728 int main(void)
730 struct linger li;
731 int sockfd = 3;
732 li.l_onoff = 1;
733 li.l_linger = 42;
734 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
735 return 0;
739 if wantfeat IPV6; then
740 link_check ipv6 'for IPv6 functionality' '#define HAVE_IPV6' << \!
741 #include "config.h"
742 #include <sys/types.h>
743 #include <sys/socket.h>
744 #include <netdb.h>
745 #include <netinet/in.h>
746 #ifdef HAVE_ARPA_INET_H
747 #include <arpa/inet.h>
748 #endif
750 int main(void)
752 struct addrinfo a, *ap;
753 getaddrinfo("foo", "0", &a, &ap);
754 return 0;
757 else
758 echo '/* WANT_IPV6=0 */' >> ${h}
759 fi # wantfeat IPV6
761 if wantfeat IMAP; then
762 echo '#define HAVE_IMAP' >> ${h}
763 else
764 echo '/* WANT_IMAP=0 */' >> ${h}
767 if wantfeat POP3; then
768 echo '#define HAVE_POP3' >> ${h}
769 else
770 echo '/* WANT_POP3=0 */' >> ${h}
773 if wantfeat SMTP; then
774 echo '#define HAVE_SMTP' >> ${h}
775 else
776 echo '/* WANT_SMTP=0 */' >> ${h}
779 if wantfeat SSL; then
780 link_check openssl 'for sufficiently recent OpenSSL' \
781 '#define HAVE_SSL
782 #define HAVE_OPENSSL' '-lssl -lcrypto' << \!
783 #include <openssl/ssl.h>
784 #include <openssl/err.h>
785 #include <openssl/x509v3.h>
786 #include <openssl/x509.h>
787 #include <openssl/rand.h>
789 #if defined OPENSSL_NO_SSL2 && defined OPENSSL_NO_SSL3 &&\
790 defined OPENSSL_NO_TLS1
791 # error We need one of (SSLv2 and) SSLv3 and TLS1.
792 #endif
794 int main(void)
796 SSLv23_client_method();
797 #ifndef OPENSSL_NO_SSL3
798 SSLv3_client_method();
799 #endif
800 #ifndef OPENSSL_NO_TLS1
801 TLSv1_client_method();
802 # ifdef TLS1_1_VERSION
803 TLSv1_1_client_method();
804 # endif
805 # ifdef TLS1_2_VERSION
806 TLSv1_2_client_method();
807 # endif
808 #endif
809 PEM_read_PrivateKey(0, 0, 0, 0);
810 return 0;
814 if [ "${have_openssl}" = 'yes' ]; then
815 compile_check stack_of 'for OpenSSL STACK_OF()' \
816 '#define HAVE_STACK_OF' << \!
817 #include <openssl/ssl.h>
818 #include <openssl/err.h>
819 #include <openssl/x509v3.h>
820 #include <openssl/x509.h>
821 #include <openssl/rand.h>
823 int main(void)
825 STACK_OF(GENERAL_NAME) *gens = NULL;
826 printf("%p", gens); /* to make it used */
827 return 0;
831 run_check openssl_md5 'for MD5 digest in OpenSSL' \
832 '#define HAVE_OPENSSL_MD5' << \!
833 #include <string.h>
834 #include <openssl/md5.h>
836 int main(void)
838 char const dat[] = "abrakadabrafidibus";
839 char dig[16], hex[16 * 2];
840 MD5_CTX ctx;
841 size_t i, j;
843 memset(dig, 0, sizeof(dig));
844 memset(hex, 0, sizeof(hex));
845 MD5_Init(&ctx);
846 MD5_Update(&ctx, dat, sizeof(dat) - 1);
847 MD5_Final(dig, &ctx);
849 #define hexchar(n) ((n)>9 ? (n)-10+'a' : (n)+'0')
850 for (i = 0; i < sizeof(hex) / 2; i++) {
851 j = i << 1;
852 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
853 hex[++j] = hexchar(dig[i] & 0x0f);
855 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
860 else
861 echo '/* WANT_SSL=0 */' >> ${h}
862 fi # wantfeat SSL
864 if wantfeat GSSAPI; then
865 ${cat} > ${tmp2}.c << \!
866 #include <gssapi/gssapi.h>
868 int main(void)
870 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
871 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
872 return 0;
875 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
877 if command -v krb5-config >/dev/null 2>&1; then
878 i=`command -v krb5-config`
879 GSSAPI_LIBS="`CFLAGS= ${i} --libs gssapi`"
880 GSSAPI_INCS="`CFLAGS= ${i} --cflags`"
881 i='for GSSAPI via krb5-config(1)'
882 else
883 GSSAPI_LIBS='-lgssapi'
884 GSSAPI_INCS=
885 i='for GSSAPI in gssapi/gssapi.h, libgssapi'
887 < ${tmp2}.c link_check gssapi \
888 "${i}" '#define HAVE_GSSAPI' \
889 "${GSSAPI_LIBS}" "${GSSAPI_INCS}" ||\
890 < ${tmp3}.c link_check gssapi \
891 'for GSSAPI in gssapi.h, libgssapi' \
892 '#define HAVE_GSSAPI
893 #define GSSAPI_REG_INCLUDE' \
894 '-lgssapi' ||\
895 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgssapi_krb5' \
896 '#define HAVE_GSSAPI' \
897 '-lgssapi_krb5' ||\
898 < ${tmp3}.c link_check gssapi \
899 'for GSSAPI in libgssapi, OpenBSD-style (pre 5.3)' \
900 '#define HAVE_GSSAPI
901 #define GSSAPI_REG_INCLUDE' \
902 '-lgssapi -lkrb5 -lcrypto' \
903 '-I/usr/include/kerberosV' ||\
904 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgss' \
905 '#define HAVE_GSSAPI' \
906 '-lgss' ||\
907 link_check gssapi 'for GSSAPI in libgssapi_krb5, old-style' \
908 '#define HAVE_GSSAPI
909 #define GSSAPI_OLD_STYLE' \
910 '-lgssapi_krb5' << \!
911 #include <gssapi/gssapi.h>
912 #include <gssapi/gssapi_generic.h>
914 int main(void)
916 gss_import_name(0, 0, gss_nt_service_name, 0);
917 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
918 return 0;
921 else
922 echo '/* WANT_GSSAPI=0 */' >> ${h}
923 fi # wantfeat GSSAPI
925 if wantfeat IDNA; then
926 link_check idna 'for GNU Libidn' '#define HAVE_IDNA' '-lidn' << \!
927 #include <idna.h>
928 #include <stringprep.h>
929 int main(void)
931 char *utf8, *idna_ascii, *idna_utf8;
932 utf8 = stringprep_locale_to_utf8("does.this.work");
933 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
934 != IDNA_SUCCESS)
935 return 1;
936 /* (Rather link check only here) */
937 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
938 return 0;
941 else
942 echo '/* WANT_IDNA=0 */' >> ${h}
945 if wantfeat REGEX; then
946 link_check regex 'for regular expressions' '#define HAVE_REGEX' << \!
947 #include <regex.h>
948 #include <stdlib.h>
949 int main(void)
951 int status;
952 regex_t re;
953 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
954 return 1;
955 status = regexec(&re, "plan9", 0,NULL, 0);
956 regfree(&re);
957 return !(status == REG_NOMATCH);
960 else
961 echo '/* WANT_REGEX=0 */' >> ${h}
964 if wantfeat READLINE; then
965 __edrdlib() {
966 link_check readline "for readline(3) (${1})" \
967 '#define HAVE_READLINE' "${1}" << \!
968 #include <stdio.h>
969 #include <readline/history.h>
970 #include <readline/readline.h>
971 int main(void)
973 char *rl;
974 using_history();
975 read_history("");
976 stifle_history(242);
977 rl = readline("Enter a line:");
978 if (rl && *rl)
979 add_history(rl);
980 write_history("");
981 rl_extend_line_buffer(10);
982 rl_point = rl_end = 10;
983 rl_pre_input_hook = (rl_hook_func_t*)NULL;
984 rl_forced_update_display();
986 rl_free_line_state();
987 rl_cleanup_after_signal();
988 rl_reset_after_signal();
989 return 0;
994 __edrdlib -lreadline ||
995 __edrdlib '-lreadline -ltermcap'
996 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
999 if wantfeat EDITLINE && [ -z "${have_readline}" ]; then
1000 __edlib() {
1001 link_check editline "for editline(3) (${1})" \
1002 '#define HAVE_EDITLINE' "${1}" << \!
1003 #include <histedit.h>
1004 static char * getprompt(void) { return (char*)"ok"; }
1005 int main(void)
1007 HistEvent he;
1008 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
1009 History *el_hcom = history_init();
1010 history(el_hcom, &he, H_SETSIZE, 242);
1011 el_set(el_el, EL_SIGNAL, 0);
1012 el_set(el_el, EL_TERMINAL, NULL);
1013 el_set(el_el, EL_HIST, &history, el_hcom);
1014 el_set(el_el, EL_EDITOR, "emacs");
1015 el_set(el_el, EL_PROMPT, &getprompt);
1016 el_source(el_el, NULL);
1017 el_end(el_el);
1018 /* TODO add loader and addfn checks */
1019 history_end(el_hcom);
1020 return 0;
1025 __edlib -ledit ||
1026 __edlib '-ledit -ltermcap'
1027 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
1030 if wantfeat NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
1031 [ -n "${have_c90amend1}" ]; then
1032 have_ncl=1
1033 echo '#define HAVE_NCL' >> ${h}
1034 else
1035 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
1038 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
1039 [ -n "${have_readline}" ]; then
1040 have_cle=1
1043 if [ -n "${have_cle}" ] && wantfeat TABEXPAND; then
1044 echo '#define HAVE_TABEXPAND' >> ${h}
1045 else
1046 echo '/* WANT_TABEXPAND=0 */' >> ${h}
1049 if [ -n "${have_cle}" ] && wantfeat HISTORY; then
1050 echo '#define HAVE_HISTORY' >> ${h}
1051 else
1052 echo '/* WANT_HISTORY=0 */' >> ${h}
1055 if wantfeat SPAM; then
1056 echo '#define HAVE_SPAM' >> ${h}
1057 if command -v spamc >/dev/null 2>&1; then
1058 echo "#define SPAMC_PATH \"`command -v spamc`\"" >> ${h}
1060 else
1061 echo '/* WANT_SPAM=0 */' >> ${h}
1064 if wantfeat DOCSTRINGS; then
1065 echo '#define HAVE_DOCSTRINGS' >> ${h}
1066 else
1067 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
1070 if wantfeat QUOTE_FOLD &&\
1071 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
1072 echo '#define HAVE_QUOTE_FOLD' >> ${h}
1073 else
1074 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
1077 if wantfeat COLOUR; then
1078 echo '#define HAVE_COLOUR' >> ${h}
1079 else
1080 echo '/* WANT_COLOUR=0 */' >> ${h}
1083 if wantfeat MD5; then
1084 echo '#define HAVE_MD5' >> ${h}
1085 else
1086 echo '/* WANT_MD5=0 */' >> ${h}
1089 ## Summarizing ##
1091 # Since we cat(1) the content of those to cc/"ld", convert them to single line
1092 squeeze_em() {
1093 < "${1}" > "${2}" ${awk} \
1094 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1096 ${rm} -f ${tmp}
1097 squeeze_em ${inc} ${tmp}
1098 ${mv} ${tmp} ${inc}
1099 squeeze_em ${lib} ${tmp}
1100 ${mv} ${tmp} ${lib}
1102 # config.h
1103 ${mv} ${h} ${tmp}
1104 printf '#ifndef _CONFIG_H\n# define _CONFIG_H\n' > ${h}
1105 ${cat} ${tmp} >> ${h}
1107 printf '\n/* The "feature string", for "simplicity" and lex.c */\n' >> ${h}
1108 printf '#ifdef _MAIN_SOURCE\n' >> ${h}
1109 printf '# ifdef HAVE_AMALGAMATION\nstatic\n# endif\n' >> ${h}
1110 printf 'char const features[] = "MIME"\n' >> ${h}
1111 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
1112 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
1113 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
1114 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
1115 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
1116 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
1117 printf '# ifdef HAVE_IPV6\n ",IPv6"\n# endif\n' >> ${h}
1118 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TSL"\n# endif\n' >> ${h}
1119 printf '# ifdef HAVE_IMAP\n ",IMAP"\n# endif\n' >> ${h}
1120 printf '# ifdef HAVE_GSSAPI\n ",GSSAPI"\n# endif\n' >> ${h}
1121 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
1122 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
1123 printf '# ifdef HAVE_SPAM\n ",SPAM"\n# endif\n' >> ${h}
1124 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
1125 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
1126 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
1127 printf '# ifdef HAVE_EDITLINE\n ",EDITLINE"\n# endif\n' >> ${h}
1128 printf '# ifdef HAVE_NCL\n ",NCL"\n# endif\n' >> ${h}
1129 printf '# ifdef HAVE_TABEXPAND\n ",TABEXPAND"\n# endif\n' >> ${h}
1130 printf '# ifdef HAVE_HISTORY\n ",HISTORY MANAGEMENT"\n# endif\n' >> ${h}
1131 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
1132 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
1133 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
1134 printf ';\n#endif /* _MAIN_SOURCE */\n' >> ${h}
1136 printf '#endif /* _CONFIG_H */\n' >> ${h}
1137 ${rm} -f ${tmp}
1139 # Create the real mk.mk
1140 ${rm} -rf ${tmp0}.* ${tmp0}*
1141 printf 'OBJ_SRC = ' >> ${mk}
1142 if nwantfeat AMALGAMATION; then
1143 echo *.c >> ${mk}
1144 echo 'OBJ_DEP =' >> ${mk}
1145 else
1146 j=`echo "${src}" | sed 's/^.\///'`
1147 echo "${j}" >> ${mk}
1148 printf 'OBJ_DEP = main.c ' >> ${mk}
1149 printf '#define _MAIN_SOURCE\n' >> ${src}
1150 printf '#include "nail.h"\n#include "main.c"\n' >> ${src}
1151 for i in *.c; do
1152 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ]; then
1153 continue
1155 printf "${i} " >> ${mk}
1156 printf "#include \"${i}\"\n" >> ${src}
1157 done
1158 echo >> ${mk}
1161 echo "LIBS = `${cat} ${lib}`" >> ${mk}
1162 echo "INCLUDES = `${cat} ${inc}`" >> ${mk}
1163 echo >> ${mk}
1164 ${cat} ./mk-mk.in >> ${mk}
1166 ## Finished! ##
1168 ${cat} > ${tmp2}.c << \!
1169 #include "config.h"
1170 #ifdef HAVE_NL_LANGINFO
1171 # include <langinfo.h>
1172 #endif
1174 :The following optional features are enabled:
1175 #ifdef HAVE_ICONV
1176 : + Character set conversion using iconv()
1177 #endif
1178 #ifdef HAVE_SETLOCALE
1179 : + Locale support: Printable characters depend on the environment
1180 # ifdef HAVE_C90AMEND1
1181 : + Multibyte character support
1182 # endif
1183 # ifdef HAVE_NL_LANGINFO
1184 : + Automatic detection of terminal character set
1185 # endif
1186 #endif
1187 #ifdef HAVE_SOCKETS
1188 : + Network support
1189 #endif
1190 #ifdef HAVE_IPV6
1191 : + Support for Internet Protocol v6 (IPv6)
1192 #endif
1193 #ifdef HAVE_SSL
1194 # ifdef HAVE_OPENSSL
1195 : + S/MIME and SSL/TLS using OpenSSL
1196 # endif
1197 #endif
1198 #ifdef HAVE_IMAP
1199 : + IMAP protocol
1200 #endif
1201 #ifdef HAVE_GSSAPI
1202 : + IMAP GSSAPI authentication
1203 #endif
1204 #ifdef HAVE_POP3
1205 : + POP3 protocol
1206 #endif
1207 #ifdef HAVE_SMTP
1208 : + SMTP protocol
1209 #endif
1210 #ifdef HAVE_SPAM
1211 : + Interaction with spam filters
1212 #endif
1213 #ifdef HAVE_IDNA
1214 : + IDNA (internationalized domain names for applications) support
1215 #endif
1216 #ifdef HAVE_REGEX
1217 : + Regular expression searches
1218 #endif
1219 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
1220 : + Command line editing
1221 # ifdef HAVE_TABEXPAND
1222 : + + Tabulator expansion
1223 # endif
1224 # ifdef HAVE_HISTORY
1225 : + + History management
1226 # endif
1227 #endif
1228 #ifdef HAVE_QUOTE_FOLD
1229 : + Extended *quote-fold*ing
1230 #endif
1231 #ifdef HAVE_COLOUR
1232 : + Coloured message display (simple)
1233 #endif
1235 :The following optional features are disabled:
1236 #ifndef HAVE_ICONV
1237 : - Character set conversion using iconv()
1238 #endif
1239 #ifndef HAVE_SETLOCALE
1240 : - Locale support: Only ASCII characters are recognized
1241 #endif
1242 # ifndef HAVE_C90AMEND1
1243 : - Multibyte character support
1244 # endif
1245 # ifndef HAVE_NL_LANGINFO
1246 : - Automatic detection of terminal character set
1247 # endif
1248 #ifndef HAVE_SOCKETS
1249 : - Network support
1250 #endif
1251 #ifndef HAVE_IPV6
1252 : - Support for Internet Protocol v6 (IPv6)
1253 #endif
1254 #if !defined HAVE_SSL
1255 : - SSL/TLS (network transport authentication and encryption)
1256 #endif
1257 #ifndef HAVE_IMAP
1258 : - IMAP protocol
1259 #endif
1260 #ifndef HAVE_GSSAPI
1261 : - IMAP GSSAPI authentication
1262 #endif
1263 #ifndef HAVE_POP3
1264 : - POP3 protocol
1265 #endif
1266 #ifndef HAVE_SMTP
1267 : - SMTP protocol
1268 #endif
1269 #ifndef HAVE_SPAM
1270 : - Interaction with spam filters
1271 #endif
1272 #ifndef HAVE_IDNA
1273 : - IDNA (internationalized domain names for applications) support
1274 #endif
1275 #ifndef HAVE_REGEX
1276 : - Regular expression searches
1277 #endif
1278 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
1279 : - Command line editing and history
1280 #endif
1281 #ifndef HAVE_QUOTE_FOLD
1282 : - Extended *quote-fold*ing
1283 #endif
1284 #ifndef HAVE_COLOUR
1285 : - Coloured message display (simple)
1286 #endif
1288 :Remarks:
1289 #ifndef HAVE_SNPRINTF
1290 : . The function snprintf() could not be found. mailx will be compiled to use
1291 : sprintf() instead. This might overflow buffers if input values are larger
1292 : than expected. Use the resulting binary with care or update your system
1293 : environment and start the configuration process again.
1294 #endif
1295 #ifndef HAVE_FCHDIR
1296 : . The function fchdir() could not be found. mailx will be compiled to use
1297 : chdir() instead. This is not a problem unless the current working
1298 : directory of mailx is moved while the IMAP cache is used.
1299 #endif
1300 #ifndef HAVE_GETOPT
1301 : . Using a minimal builtin POSIX-like getopt()
1302 #endif
1303 #ifdef HAVE_DEBUG
1304 : . Debug enabled binary: not meant to be used by end-users: THANKS!
1305 #endif
1309 ${make} -f ${makefile} ${tmp2}.x
1310 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
1312 # vim:set fenc=utf-8:s-it-mode