popen.c: some cleanup, use other wait_child() from now on
[s-mailx.git] / mk-conf.sh
blob620cc12533fe0fe7d41a73e699d86a7864d4c37c
1 #!/bin/sh -
2 #@ Please see `INSTALL' and `conf.rc' instead.
4 LC_ALL=C
5 export LC_ALL
7 awk=`command -pv awk`
8 cat=`command -pv cat`
9 chmod=`command -pv chmod`
10 cp=`command -pv cp`
11 cmp=`command -pv cmp`
12 grep=`command -pv grep`
13 make="${MAKE:-`command -pv make`}"
14 mkdir=`command -pv mkdir`
15 mv=`command -pv mv`
16 rm=`command -pv rm`
17 sed=`command -pv sed`
18 tee=`command -pv tee`
20 STRIP=`command -pv strip`
21 [ ${?} -eq 0 ] && HAVE_STRIP=1 || HAVE_STRIP=0
23 # Predefined CONFIG= urations take precedence over anything else
24 if [ -n "${CONFIG}" ]; then
25 case ${CONFIG} in
26 MINIMAL)
27 WANT_SOCKETS=0
28 WANT_IDNA=0
29 WANT_READLINE=0 WANT_EDITLINE=0 WANT_NCL=0
30 WANT_QUOTE_FOLD=0
31 WANT_DOCSTRINGS=0
32 WANT_SPAM=0
34 MEDIUM)
35 WANT_SOCKETS=0
36 WANT_IDNA=0
37 WANT_READLINE=0 WANT_EDITLINE=0
38 WANT_QUOTE_FOLD=0
39 WANT_SPAM=0
41 NETSEND)
42 WANT_IMAP=0
43 WANT_POP3=0
44 WANT_READLINE=0 WANT_EDITLINE=0
45 WANT_QUOTE_FOLD=0
46 WANT_SPAM=0
49 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
50 echo >&2 'Possible values: MINIMAL, MEDIUM, NETSEND'
51 exit 1
52 esac
55 # Inter-relationships
56 option_update() {
57 if nwantfeat SOCKETS; then
58 WANT_IPV6=0 WANT_SSL=0
59 WANT_IMAP=0 WANT_GSSAPI=0 WANT_POP3=0 WANT_SMTP=0
61 if nwantfeat IMAP && nwantfeat POP3 && nwantfeat SMTP; then
62 WANT_SOCKETS=0 WANT_IPV6=0 WANT_SSL=0
64 if nwantfeat IMAP; then
65 WANT_GSSAPI=0
67 # If we don't need MD5 except for producing boundary and message-id strings,
68 # leave it off, plain old srand(3) should be enough for that purpose.
69 if nwantfeat SOCKETS; then
70 WANT_MD5=0
72 if wantfeat DEBUG; then
73 WANT_NOALLOCA=1
77 # Check out compiler ($CC) and -flags ($CFLAGS)
78 compiler_flags() {
79 i=`uname -s`
80 _CFLAGS=
81 if [ -z "${CC}" ] || [ "${CC}" = cc ]; then
82 _CFLAGS=
83 if { CC="`command -v clang`"; }; then
85 elif { CC="`command -v gcc`"; }; then
87 elif { CC="`command -v c89`"; }; then
88 [ "${i}" = UnixWare ] && _CFLAGS='-v -O'
89 elif { CC="`command -v c99`"; }; then
91 else
92 echo >&2 'ERROR'
93 echo >&2 ' I cannot find a compiler!'
94 echo >&2 ' Neither of clang(1), gcc(1), c89(1) and c99(1).'
95 echo >&2 ' Please set the CC environment variable, maybe CFLAGS also.'
96 exit 1
99 export CC
101 ccver=`${CC} --version 2>/dev/null`
102 stackprot=no
103 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e gcc -e clang; then
104 #if echo "${i}" | ${grep} -q -i -e gcc -e 'clang version 1'; then
105 stackprot=yes
106 _CFLAGS='-std=c89 -O2'
107 _CFLAGS="${_CFLAGS} -Wall -Wextra -pedantic"
108 _CFLAGS="${_CFLAGS} -fno-unwind-tables -fno-asynchronous-unwind-tables"
109 _CFLAGS="${_CFLAGS} -fstrict-aliasing"
110 _CFLAGS="${_CFLAGS} -Wbad-function-cast -Wcast-align -Wcast-qual"
111 _CFLAGS="${_CFLAGS} -Winit-self -Wshadow -Wunused -Wwrite-strings"
112 if { i=$ccver; echo "${i}"; } | ${grep} -q -e 'clang version 1'; then
114 else
115 _CFLAGS="${_CFLAGS} -fstrict-overflow -Wstrict-overflow=5"
116 if wantfeat AMALGAMATION && nwantfeat DEBUG; then
117 _CFLAGS="${_CFLAGS} -Wno-unused-function"
119 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
120 _CFLAGS="${_CFLAGS} -Wno-unused-result" # TODO handle the right way
123 _CFLAGS="${_CFLAGS} -Wno-long-long" # ISO C89 has no 'long long'...
124 # elif { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
125 # stackprot=yes
126 # _CFLAGS='-std=c89 -O3 -g -Weverything -Wno-long-long'
127 elif [ -z "${_CFLAGS}" ]; then
128 _CFLAGS=-O1
131 if nwantfeat DEBUG; then
132 _CFLAGS="${_CFLAGS} -DNDEBUG"
133 else
134 _CFLAGS="${_CFLAGS} -g";
135 if [ "${stackprot}" = yes ]; then
136 _CFLAGS="${_CFLAGS} -fstack-protector-all "
137 _CFLAGS="${_CFLAGS} -Wstack-protector -D_FORTIFY_SOURCE=2"
140 _CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
141 _LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}" # XXX -Wl,--sort-common,[-O1]
142 export _CFLAGS _LDFLAGS
144 if wantfeat AUTOCC || [ -z "${CFLAGS}" ]; then
145 CFLAGS=$_CFLAGS
146 export CFLAGS
148 if wantfeat AUTOCC || [ -z "${LDFLAGS}" ]; then
149 LDFLAGS=$_LDFLAGS
150 export LDFLAGS
154 ## -- >8 -- 8< -- ##
156 ## Notes:
157 ## - Heirloom sh(1) (and same origin) have problems with ': >' redirection,
158 ## so use "printf '' >" instead
159 ## - Heirloom sh(1) and maybe more execute loops with redirection in a subshell
160 ## (but don't export eval's from within), therefore we need to (re)include
161 ## variable assignments at toplevel instead (via reading temporary files)
163 ## First of all, create new configuration and check wether it changed ##
165 conf=./conf.rc
166 lst=./config.lst
167 h=./config.h
168 mk=./mk.mk
170 newlst=./config.lst-new
171 newmk=./config.mk-new
172 newh=./config.h-new
173 tmp0=___tmp
174 tmp=./${tmp0}1$$
176 # Only incorporate what wasn't overwritten from command line / CONFIG
177 trap "${rm} -f ${tmp}; exit" 1 2 15
178 trap "${rm} -f ${tmp}" 0
179 ${rm} -f ${tmp}
181 < ${conf} ${sed} -e '/^[ \t]*#/d' -e '/^$/d' -e 's/[ \t]*$//' |
182 while read line; do
183 i=`echo ${line} | ${sed} -e 's/=.*$//'`
184 eval j=\$${i} jx=\${${i}+x}
185 if [ -n "${j}" ] || [ "${jx}" = x ]; then
186 line="${i}=\"${j}\""
188 echo ${line}
189 done > ${tmp}
190 . ./${tmp}
192 wantfeat() {
193 eval i=\$WANT_${1}
194 [ "${i}" = "1" ]
196 nwantfeat() {
197 eval i=\$WANT_${1}
198 [ "${i}" != "1" ]
201 option_update
203 # (No function since some shells loose non-exported variables in traps)
204 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}; exit" 1 2 15
205 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}" 0
206 ${rm} -f ${newlst} ${newmk} ${newh}
208 while read line; do
209 i=`echo ${line} | ${sed} -e 's/=.*$//'`
210 eval j=\$${i}
211 if [ -z "${j}" ] || [ "${j}" = 0 ]; then
212 printf "/*#define ${i}*/\n" >> ${newh}
213 elif [ "${j}" = 1 ]; then
214 printf "#define ${i}\n" >> ${newh}
215 else
216 printf "#define ${i} \"${j}\"\n" >> ${newh}
218 printf "${i} = ${j}\n" >> ${newmk}
219 printf "${i}=\"${j}\"\n"
220 done < ${tmp} > ${newlst}
221 . ./${newlst}
223 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
224 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
226 compiler_flags
228 printf "CC = ${CC}\n" >> ${newmk}
229 printf "_CFLAGS = ${_CFLAGS}\nCFLAGS = ${CFLAGS}\n" >> ${newmk}
230 printf "_LDFLAGS = ${_LDFLAGS}\nLDFLAGS = ${LDFLAGS}\n" >> ${newmk}
231 printf "CMP=${cmp}\nCHMOD=${chmod}\nCP=${cp}\nMKDIR=${mkdir}\nRM=${rm}\n"\
232 >> ${newmk}
233 printf "STRIP=${STRIP}\nHAVE_STRIP=${HAVE_STRIP}\n" >> ${newmk}
234 # (We include the cc(1)/ld(1) environment only for update detection..)
235 printf "CC=\"${CC}\"\n" >> ${newlst}
236 printf "_CFLAGS=\"${_CFLAGS}\"\nCFLAGS=\"${CFLAGS}\"\n" >> ${newlst}
237 printf "_LDFLAGS=\"${_LDFLAGS}\"\nLDFLAGS=\"${LDFLAGS}\"\n" >> ${newlst}
238 printf "CMP=${cmp}\nCHMOD=${chmod}\nCP=${cp}\nMKDIR=${mkdir}\nRM=${rm}\n"\
239 >> ${newlst}
240 printf "STRIP=${STRIP}\nHAVE_STRIP=${HAVE_STRIP}\n" >> ${newlst}
242 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
243 exit 0
245 [ -f ${lst} ] && echo 'configuration updated..' || echo 'shiny configuration..'
247 ${mv} -f ${newlst} ${lst}
248 ${mv} -f ${newh} ${h}
249 ${mv} -f ${newmk} ${mk}
251 ## Compile and link checking ##
253 tmp2=./${tmp0}2$$
254 tmp3=./${tmp0}3$$
255 log=./config.log
256 lib=./config.lib
257 inc=./config.inc
258 src=./config.c
259 makefile=./config.mk
261 # (No function since some shells loose non-exported variables in traps)
262 trap "${rm} -f ${lst} ${h} ${mk} ${lib} ${inc} ${src} ${makefile}; exit" 1 2 15
263 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" 0
265 exec 5>&2 > ${log} 2>&1
266 printf '' > ${lib}
267 printf '' > ${inc}
268 # ${src} is only created if WANT_AMALGAMATION
269 ${rm} -f ${src}
270 ${cat} > ${makefile} << \!
271 .SUFFIXES: .o .c .x .y
272 .c.o:
273 $(CC) $(XINCS) -c $<
274 .c.x:
275 $(CC) $(XINCS) -E $< >$@
277 $(CC) $(XINCS) -o $@ $< $(XLIBS)
278 .y: ;
281 msg() {
282 fmt=$1
284 shift
285 printf "*** ${fmt}\\n" "${@}"
286 printf "${fmt}" "${@}" >&5
289 _check_preface() {
290 variable=$1 topic=$2 define=$3
292 echo '**********'
293 msg "checking ${topic} ... "
294 echo "/* checked ${topic} */" >> ${h}
295 ${rm} -f ${tmp} ${tmp}.o
296 echo '*** test program is'
297 ${tee} ${tmp}.c
298 #echo '*** the preprocessor generates'
299 #${make} -f ${makefile} ${tmp}.x
300 #${cat} ${tmp}.x
301 echo '*** results are'
304 compile_check() {
305 variable=$1 topic=$2 define=$3
307 _check_preface "${variable}" "${topic}" "${define}"
309 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
310 [ -f ./${tmp}.o ]; then
311 msg "yes\\n"
312 echo "${define}" >> ${h}
313 eval have_${variable}=yes
314 return 0
315 else
316 echo "/* ${define} */" >> ${h}
317 msg "no\\n"
318 eval unset have_${variable}
319 return 1
323 _link_mayrun() {
324 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
326 _check_preface "${variable}" "${topic}" "${define}"
328 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
329 XLIBS="${LIBS} ${libs}" ./${tmp} &&
330 [ -f ./${tmp} ] &&
331 { [ ${run} -eq 0 ] || ./${tmp}; }; then
332 echo "*** adding INCS<${incs}> LIBS<${libs}>"
333 msg "yes\\n"
334 echo "${define}" >> ${h}
335 LIBS="${LIBS} ${libs}"
336 echo "${libs}" >> ${lib}
337 INCS="${INCS} ${incs}"
338 echo "${incs}" >> ${inc}
339 eval have_${variable}=yes
340 return 0
341 else
342 msg "no\\n"
343 echo "/* ${define} */" >> ${h}
344 eval unset have_${variable}
345 return 1
349 link_check() {
350 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
353 run_check() {
354 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
357 # Build a basic set of INCS and LIBS according to user environment.
358 # On pkgsrc(7) systems automatically add /usr/pkg/*
359 if [ -n "${C_INCLUDE_PATH}" ]; then
360 i=${IFS}
361 IFS=:
362 set -- ${C_INCLUDE_PATH}
363 IFS=${i}
364 # for i; do -- new in POSIX Issue 7 + TC1
365 for i
367 [ "${i}" = '/usr/pkg/include' ] && continue
368 INCS="${INCS} -I${i}"
369 done
371 [ -d /usr/pkg/include ] && INCS="${INCS} -I/usr/pkg/include"
372 echo "${INCS}" >> ${inc}
374 if [ -n "${LD_LIBRARY_PATH}" ]; then
375 i=${IFS}
376 IFS=:
377 set -- ${LD_LIBRARY_PATH}
378 IFS=${i}
379 # for i; do -- new in POSIX Issue 7 + TC1
380 for i
382 [ "${i}" = '/usr/pkg/lib' ] && continue
383 LIBS="${LIBS} -L${i}"
384 done
386 [ -d /usr/pkg/lib ] && LIBS="${LIBS} -L/usr/pkg/lib"
387 echo "${LIBS}" >> ${lib}
391 # Better set _GNU_SOURCE (if we are on Linux only?)
392 # Fixes compilation on Slackware 14 + (with at least clang(1)).
393 # Since i've always defined this on GNU/Linux, i'm even surprised it works
394 # without!! Didn't check this yet (and TinyCore uses different environment).
395 echo '#define _GNU_SOURCE' >> ${h}
397 link_check hello 'if a hello world program can be built' << \! || {\
398 echo >&5 'This oooops is most certainly not related to me.';\
399 echo >&5 "Read the file ${log} and check your compiler environment.";\
400 ${rm} -f ${lst} ${h} ${mk};\
401 exit 1;\
403 #include <stdio.h>
405 int main(int argc, char *argv[])
407 (void)argc;
408 (void)argv;
409 puts("hello world");
410 return 0;
414 link_check termios 'for termios.h and tc*() family' << \! || {\
415 echo >&5 'We require termios.h and the tc*() family of functions.';\
416 echo >&5 "That much Unix we indulge ourselfs.";\
417 ${rm} -f ${lst} ${h} ${mk};\
418 exit 1;\
420 #include <termios.h>
421 int main(void)
423 struct termios tios;
424 tcgetattr(0, &tios);
425 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
426 return 0;
430 link_check snprintf 'for snprintf()' '#define HAVE_SNPRINTF' << \!
431 #include <stdio.h>
432 int main(void)
434 char b[20];
435 snprintf(b, sizeof b, "%s", "string");
436 return 0;
440 link_check putc_unlocked 'for putc_unlocked()' '#define HAVE_PUTC_UNLOCKED' <<\!
441 #include <stdio.h>
442 int main(void)
444 putc_unlocked('@', stdout);
445 return 0;
449 link_check fchdir 'for fchdir()' '#define HAVE_FCHDIR' << \!
450 #include <unistd.h>
451 int main(void)
453 fchdir(0);
454 return 0;
458 link_check mmap 'for mmap()' '#define HAVE_MMAP' << \!
459 #include <sys/types.h>
460 #include <sys/mman.h>
461 int main(void)
463 mmap(0, 0, 0, 0, 0, 0);
464 return 0;
468 link_check mremap 'for mremap()' '#define HAVE_MREMAP' << \!
469 #include <sys/types.h>
470 #include <sys/mman.h>
471 int main(void)
473 mremap(0, 0, 0, MREMAP_MAYMOVE);
474 return 0;
478 link_check wctype 'for wctype functionality' '#define HAVE_WCTYPE_H' << \!
479 #include <wctype.h>
480 int main(void)
482 iswprint(L'c');
483 towupper(L'c');
484 return 0;
488 link_check wcwidth 'for wcwidth() ' '#define HAVE_WCWIDTH' << \!
489 #include <wchar.h>
490 int main(void)
492 wcwidth(L'c');
493 return 0;
497 link_check mbtowc 'for mbtowc()' '#define HAVE_MBTOWC' << \!
498 #include <stdlib.h>
499 int main(void)
501 wchar_t wc;
502 mbtowc(&wc, "x", 1);
503 return 0;
507 link_check mbrtowc 'for mbrtowc()' '#define HAVE_MBRTOWC' << \!
508 #include <wchar.h>
509 int main(void)
511 wchar_t wc;
512 mbrtowc(&wc, "x", 1, NULL);
513 return 0;
517 link_check mblen 'for mblen()' '#define HAVE_MBLEN' << \!
518 #include <stdlib.h>
519 int main(void)
521 return mblen("\0", 1) == 0;
525 link_check setlocale 'for setlocale()' '#define HAVE_SETLOCALE' << \!
526 #include <locale.h>
527 int main(void)
529 setlocale(LC_ALL, "");
530 return 0;
534 link_check nl_langinfo 'for nl_langinfo()' '#define HAVE_NL_LANGINFO' << \!
535 #include <langinfo.h>
536 int main(void)
538 nl_langinfo(DAY_1);
539 return 0;
543 link_check mkstemp 'for mkstemp()' '#define HAVE_MKSTEMP' << \!
544 #include <stdlib.h>
545 int main(void)
547 mkstemp("x");
548 return 0;
552 # Note: run_check, thus we also get only the desired implementation...
553 run_check realpath 'for realpath()' '#define HAVE_REALPATH' << \!
554 #include <stdlib.h>
555 int main(void)
557 char *x = realpath(".", NULL), *y = realpath("/", NULL);
558 return (x != NULL && y != NULL) ? 0 : 1;
562 link_check wordexp 'for wordexp()' '#define HAVE_WORDEXP' << \!
563 #include <wordexp.h>
564 int main(void)
566 wordexp((char *)0, (wordexp_t *)0, 0);
567 return 0;
573 if wantfeat DEBUG; then
574 echo '#define HAVE_DEBUG' >> ${h}
577 if wantfeat AMALGAMATION; then
578 echo '#define HAVE_AMALGAMATION' >> ${h}
581 if nwantfeat NOALLOCA; then
582 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
583 # versions of alloca(3) since modern compilers just can't be trusted
584 # not to overoptimize and silently break some code
585 link_check alloca 'for __builtin_alloca()' \
586 '#define HAVE_ALLOCA __builtin_alloca' << \!
587 int main(void)
589 void *vp = __builtin_alloca(1);
590 return (!! vp);
595 if nwantfeat NOGETOPT; then
596 link_check getopt 'for getopt()' '#define HAVE_GETOPT' << \!
597 #include <unistd.h>
598 int main(int argc, char **argv)
600 #if defined __GLIBC__ || defined __linux__
601 Argument and option reordering is not a desired feature.
602 #else
603 getopt(argc, argv, "oPt");
604 #endif
605 return (((long)optarg + optind) & 0x7F);
612 if wantfeat ICONV; then
613 ${cat} > ${tmp2}.c << \!
614 #include <iconv.h>
615 int main(void)
617 iconv_t id;
619 id = iconv_open("foo", "bar");
620 return 0;
623 < ${tmp2}.c link_check iconv 'for iconv functionality' \
624 '#define HAVE_ICONV' ||
625 < ${tmp2}.c link_check iconv \
626 'for iconv functionality in libiconv' \
627 '#define HAVE_ICONV' '-liconv'
628 else
629 echo '/* WANT_ICONV=0 */' >> ${h}
630 fi # wantfeat ICONV
632 if wantfeat SOCKETS; then
633 compile_check arpa_inet_h 'for <arpa/inet.h>' \
634 '#define HAVE_ARPA_INET_H' << \!
635 #include "config.h"
636 #include <sys/types.h>
637 #include <sys/socket.h>
638 #include <netdb.h>
639 #include <netinet/in.h>
640 #include <arpa/inet.h>
643 ${cat} > ${tmp2}.c << \!
644 #include "config.h"
645 #include <sys/types.h>
646 #include <sys/socket.h>
647 #include <netdb.h>
648 #include <netinet/in.h>
649 #ifdef HAVE_ARPA_INET_H
650 #include <arpa/inet.h>
651 #endif
653 int main(void)
655 struct sockaddr s;
656 socket(AF_INET, SOCK_STREAM, 0);
657 connect(0, &s, 0);
658 gethostbyname("foo");
659 return 0;
663 < ${tmp2}.c link_check sockets 'for sockets in libc' \
664 '#define HAVE_SOCKETS' ||
665 < ${tmp2}.c link_check sockets 'for sockets in libnsl' \
666 '#define HAVE_SOCKETS' '-lnsl' ||
667 < ${tmp2}.c link_check sockets \
668 'for sockets in libsocket and libnsl' \
669 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
670 WANT_SOCKETS=0
672 # XXX Shouldn't it be a hard error if there is no socket support, then?
673 option_update
674 else
675 echo '/* WANT_SOCKETS=0 */' >> ${h}
676 fi # wantfeat SOCKETS
678 wantfeat SOCKETS &&
679 link_check setsockopt 'for setsockopt()' '#define HAVE_SETSOCKOPT' << \!
680 #include <sys/socket.h>
681 #include <stdlib.h>
682 int main(void)
684 int sockfd = 3;
685 setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0);
686 return 0;
690 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
691 link_check so_sndtimeo 'for SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
692 #include <sys/socket.h>
693 #include <stdlib.h>
694 int main(void)
696 struct timeval tv;
697 int sockfd = 3;
698 tv.tv_sec = 42;
699 tv.tv_usec = 21;
700 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
701 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
702 return 0;
706 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
707 link_check so_linger 'for SO_LINGER' '#define HAVE_SO_LINGER' << \!
708 #include <sys/socket.h>
709 #include <stdlib.h>
710 int main(void)
712 struct linger li;
713 int sockfd = 3;
714 li.l_onoff = 1;
715 li.l_linger = 42;
716 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
717 return 0;
721 if wantfeat IPV6; then
722 link_check ipv6 'for IPv6 functionality' '#define HAVE_IPV6' << \!
723 #include "config.h"
724 #include <sys/types.h>
725 #include <sys/socket.h>
726 #include <netdb.h>
727 #include <netinet/in.h>
728 #ifdef HAVE_ARPA_INET_H
729 #include <arpa/inet.h>
730 #endif
732 int main(void)
734 struct addrinfo a, *ap;
735 getaddrinfo("foo", "0", &a, &ap);
736 return 0;
739 else
740 echo '/* WANT_IPV6=0 */' >> ${h}
741 fi # wantfeat IPV6
743 if wantfeat IMAP; then
744 echo '#define HAVE_IMAP' >> ${h}
745 else
746 echo '/* WANT_IMAP=0 */' >> ${h}
749 if wantfeat POP3; then
750 echo '#define HAVE_POP3' >> ${h}
751 else
752 echo '/* WANT_POP3=0 */' >> ${h}
755 if wantfeat SMTP; then
756 echo '#define HAVE_SMTP' >> ${h}
757 else
758 echo '/* WANT_SMTP=0 */' >> ${h}
761 if wantfeat SSL; then
762 link_check openssl 'for sufficiently recent OpenSSL' \
763 '#define HAVE_SSL
764 #define HAVE_OPENSSL' '-lssl -lcrypto' << \!
765 #include <openssl/ssl.h>
766 #include <openssl/err.h>
767 #include <openssl/x509v3.h>
768 #include <openssl/x509.h>
769 #include <openssl/rand.h>
771 #if defined OPENSSL_NO_SSL2 && defined OPENSSL_NO_SSL3 &&\
772 defined OPENSSL_NO_TLS1
773 # error We need one of (SSLv2 and) SSLv3 and TLS1.
774 #endif
776 int main(void)
778 SSLv23_client_method();
779 #ifndef OPENSSL_NO_SSL3
780 SSLv3_client_method();
781 #endif
782 #ifndef OPENSSL_NO_TLS1
783 TLSv1_client_method();
784 # ifdef TLS1_1_VERSION
785 TLSv1_1_client_method();
786 # endif
787 # ifdef TLS1_2_VERSION
788 TLSv1_2_client_method();
789 # endif
790 #endif
791 PEM_read_PrivateKey(0, 0, 0, 0);
792 return 0;
796 if [ "${have_openssl}" = 'yes' ]; then
797 compile_check stack_of 'for OpenSSL STACK_OF()' \
798 '#define HAVE_STACK_OF' << \!
799 #include <openssl/ssl.h>
800 #include <openssl/err.h>
801 #include <openssl/x509v3.h>
802 #include <openssl/x509.h>
803 #include <openssl/rand.h>
805 int main(void)
807 STACK_OF(GENERAL_NAME) *gens = NULL;
808 printf("%p", gens); /* to make it used */
809 return 0;
813 run_check openssl_md5 'for MD5 digest in OpenSSL' \
814 '#define HAVE_OPENSSL_MD5' << \!
815 #include <string.h>
816 #include <openssl/md5.h>
818 int main(void)
820 char const dat[] = "abrakadabrafidibus";
821 char dig[16], hex[16 * 2];
822 MD5_CTX ctx;
823 size_t i, j;
825 memset(dig, 0, sizeof(dig));
826 memset(hex, 0, sizeof(hex));
827 MD5_Init(&ctx);
828 MD5_Update(&ctx, dat, sizeof(dat) - 1);
829 MD5_Final(dig, &ctx);
831 #define hexchar(n) ((n)>9 ? (n)-10+'a' : (n)+'0')
832 for (i = 0; i < sizeof(hex) / 2; i++) {
833 j = i << 1;
834 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
835 hex[++j] = hexchar(dig[i] & 0x0f);
837 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
842 else
843 echo '/* WANT_SSL=0 */' >> ${h}
844 fi # wantfeat SSL
846 if wantfeat GSSAPI; then
847 ${cat} > ${tmp2}.c << \!
848 #include <gssapi/gssapi.h>
850 int main(void)
852 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
853 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
854 return 0;
857 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
859 if command -v krb5-config >/dev/null 2>&1; then
860 i=`command -v krb5-config`
861 GSSAPI_LIBS="`CFLAGS= ${i} --libs gssapi`"
862 GSSAPI_INCS="`CFLAGS= ${i} --cflags`"
863 i='for GSSAPI via krb5-config(1)'
864 else
865 GSSAPI_LIBS='-lgssapi'
866 GSSAPI_INCS=
867 i='for GSSAPI in gssapi/gssapi.h, libgssapi'
869 < ${tmp2}.c link_check gssapi \
870 "${i}" '#define HAVE_GSSAPI' \
871 "${GSSAPI_LIBS}" "${GSSAPI_INCS}" ||\
872 < ${tmp3}.c link_check gssapi \
873 'for GSSAPI in gssapi.h, libgssapi' \
874 '#define HAVE_GSSAPI
875 #define GSSAPI_REG_INCLUDE' \
876 '-lgssapi' ||\
877 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgssapi_krb5' \
878 '#define HAVE_GSSAPI' \
879 '-lgssapi_krb5' ||\
880 < ${tmp3}.c link_check gssapi \
881 'for GSSAPI in libgssapi, OpenBSD-style (pre 5.3)' \
882 '#define HAVE_GSSAPI
883 #define GSSAPI_REG_INCLUDE' \
884 '-lgssapi -lkrb5 -lcrypto' \
885 '-I/usr/include/kerberosV' ||\
886 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgss' \
887 '#define HAVE_GSSAPI' \
888 '-lgss' ||\
889 link_check gssapi 'for GSSAPI in libgssapi_krb5, old-style' \
890 '#define HAVE_GSSAPI
891 #define GSSAPI_OLD_STYLE' \
892 '-lgssapi_krb5' << \!
893 #include <gssapi/gssapi.h>
894 #include <gssapi/gssapi_generic.h>
896 int main(void)
898 gss_import_name(0, 0, gss_nt_service_name, 0);
899 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
900 return 0;
903 else
904 echo '/* WANT_GSSAPI=0 */' >> ${h}
905 fi # wantfeat GSSAPI
907 if wantfeat IDNA; then
908 link_check idna 'for GNU Libidn' '#define HAVE_IDNA' '-lidn' << \!
909 #include <idna.h>
910 #include <stringprep.h>
911 int main(void)
913 char *utf8, *idna_ascii, *idna_utf8;
914 utf8 = stringprep_locale_to_utf8("does.this.work");
915 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
916 != IDNA_SUCCESS)
917 return 1;
918 /* (Rather link check only here) */
919 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
920 return 0;
923 else
924 echo '/* WANT_IDNA=0 */' >> ${h}
925 fi # wantfeat IDNA
927 if wantfeat READLINE; then
928 __edrdlib() {
929 link_check readline "for readline(3) (${1})" \
930 '#define HAVE_READLINE' "${1}" << \!
931 #include <stdio.h>
932 #include <readline/history.h>
933 #include <readline/readline.h>
934 int main(void)
936 char *rl;
937 using_history();
938 read_history("");
939 stifle_history(242);
940 rl = readline("Enter a line:");
941 if (rl && *rl)
942 add_history(rl);
943 write_history("");
944 rl_extend_line_buffer(10);
945 rl_point = rl_end = 10;
946 rl_pre_input_hook = (rl_hook_func_t*)NULL;
947 rl_forced_update_display();
949 rl_free_line_state();
950 rl_cleanup_after_signal();
951 rl_reset_after_signal();
952 return 0;
957 __edrdlib -lreadline ||
958 __edrdlib '-lreadline -ltermcap'
959 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
962 if wantfeat EDITLINE && [ -z "${have_readline}" ]; then
963 __edlib() {
964 link_check editline "for editline(3) (${1})" \
965 '#define HAVE_EDITLINE' "${1}" << \!
966 #include <histedit.h>
967 static char * getprompt(void) { return (char*)"ok"; }
968 int main(void)
970 HistEvent he;
971 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
972 History *el_hcom = history_init();
973 history(el_hcom, &he, H_SETSIZE, 242);
974 el_set(el_el, EL_SIGNAL, 0);
975 el_set(el_el, EL_TERMINAL, NULL);
976 el_set(el_el, EL_HIST, &history, el_hcom);
977 el_set(el_el, EL_EDITOR, "emacs");
978 el_set(el_el, EL_PROMPT, &getprompt);
979 el_source(el_el, NULL);
980 el_end(el_el);
981 /* TODO add loader and addfn checks */
982 history_end(el_hcom);
983 return 0;
988 __edlib -ledit ||
989 __edlib '-ledit -ltermcap'
990 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
993 if wantfeat NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
994 [ -n "${have_mbrtowc}" ] && [ -n "${have_wctype}" ]; then
995 have_ncl=1
996 echo '#define HAVE_NCL' >> ${h}
997 else
998 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
1001 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
1002 [ -n "${have_readline}" ]; then
1003 have_cle=1
1006 if [ -n "${have_cle}" ] && wantfeat TABEXPAND; then
1007 echo '#define HAVE_TABEXPAND' >> ${h}
1008 else
1009 echo '/* WANT_TABEXPAND=0 */' >> ${h}
1012 if [ -n "${have_cle}" ] && wantfeat HISTORY; then
1013 echo '#define HAVE_HISTORY' >> ${h}
1014 else
1015 echo '/* WANT_HISTORY=0 */' >> ${h}
1018 if wantfeat QUOTE_FOLD &&\
1019 [ -n "${have_mbrtowc}" ] && [ -n "${have_wcwidth}" ]; then
1020 echo '#define HAVE_QUOTE_FOLD' >> ${h}
1021 else
1022 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
1025 if wantfeat DOCSTRINGS; then
1026 echo '#define HAVE_DOCSTRINGS' >> ${h}
1027 else
1028 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
1031 if wantfeat SPAM; then
1032 echo '#define HAVE_SPAM' >> ${h}
1033 if command -v spamc >/dev/null 2>&1; then
1034 echo "#define SPAMC_PATH \"`command -v spamc`\"" >> ${h}
1036 else
1037 echo '/* WANT_SPAM=0 */' >> ${h}
1040 if wantfeat MD5; then
1041 echo '#define HAVE_MD5' >> ${h}
1042 else
1043 echo '/* WANT_MD5=0 */' >> ${h}
1046 ## Summarizing ##
1048 # Since we cat(1) the content of those to cc/"ld", convert them to single line
1049 squeeze_em() {
1050 < "${1}" > "${2}" ${awk} \
1051 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1053 ${rm} -f ${tmp}
1054 squeeze_em ${inc} ${tmp}
1055 ${mv} ${tmp} ${inc}
1056 squeeze_em ${lib} ${tmp}
1057 ${mv} ${tmp} ${lib}
1059 ${mv} ${h} ${tmp}
1060 printf '#ifndef _CONFIG_H\n# define _CONFIG_H\n' > ${h}
1061 ${cat} ${tmp} >> ${h}
1062 printf '#endif /* _CONFIG_H */\n' >> ${h}
1063 ${rm} -f ${tmp}
1065 # Create the real mk.mk
1066 ${rm} -rf ${tmp0}.* ${tmp0}*
1067 printf 'OBJ_SRC = ' >> ${mk}
1068 if nwantfeat AMALGAMATION; then
1069 echo *.c >> ${mk}
1070 echo 'OBJ_DEP =' >> ${mk}
1071 else
1072 j=`echo "${src}" | sed 's/^.\///'`
1073 echo "${j}" >> ${mk}
1074 printf 'OBJ_DEP = main.c ' >> ${mk}
1075 printf '#define _MAIN_SOURCE\n' >> ${src}
1076 printf '#include "nail.h"\n#include "main.c"\n' >> ${src}
1077 for i in *.c; do
1078 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ]; then
1079 continue
1081 printf "${i} " >> ${mk}
1082 printf "#include \"${i}\"\n" >> ${src}
1083 done
1084 echo >> ${mk}
1087 echo "LIBS = `${cat} ${lib}`" >> ${mk}
1088 echo "INCLUDES = `${cat} ${inc}`" >> ${mk}
1089 echo >> ${mk}
1090 ${cat} ./mk-mk.in >> ${mk}
1092 ## Finished! ##
1094 ${cat} > ${tmp2}.c << \!
1095 #include "config.h"
1096 #ifdef HAVE_NL_LANGINFO
1097 #include <langinfo.h>
1098 #endif
1100 :The following optional features are enabled:
1101 #ifdef HAVE_ICONV
1102 : + Character set conversion using iconv()
1103 #endif
1104 #ifdef HAVE_SETLOCALE
1105 : + Locale support: Printable characters depend on the environment
1106 # if defined HAVE_MBTOWC && defined HAVE_WCTYPE_H
1107 : + Multibyte character support
1108 # endif
1109 # if defined HAVE_NL_LANGINFO && defined CODESET
1110 : + Automatic detection of terminal character set
1111 # endif
1112 #endif
1113 #ifdef HAVE_SOCKETS
1114 : + Network support
1115 #endif
1116 #ifdef HAVE_IPV6
1117 : + Support for Internet Protocol v6 (IPv6)
1118 #endif
1119 #ifdef HAVE_OPENSSL
1120 : + S/MIME and SSL/TLS using OpenSSL
1121 #endif
1122 #ifdef HAVE_IMAP
1123 : + IMAP protocol
1124 #endif
1125 #ifdef HAVE_GSSAPI
1126 : + IMAP GSSAPI authentication
1127 #endif
1128 #ifdef HAVE_POP3
1129 : + POP3 protocol
1130 #endif
1131 #ifdef HAVE_SMTP
1132 : + SMTP protocol
1133 #endif
1134 #ifdef HAVE_SPAM
1135 : + Interaction with spam filters
1136 #endif
1137 #ifdef HAVE_IDNA
1138 : + IDNA (internationalized domain names for applications) support
1139 #endif
1140 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
1141 : + Command line editing
1142 # ifdef HAVE_TABEXPAND
1143 : + + Tabulator expansion
1144 # endif
1145 # ifdef HAVE_HISTORY
1146 : + + History management
1147 # endif
1148 #endif
1149 #ifdef HAVE_QUOTE_FOLD
1150 : + Extended *quote-fold*ing
1151 #endif
1153 :The following optional features are disabled:
1154 #ifndef HAVE_ICONV
1155 : - Character set conversion using iconv()
1156 #endif
1157 #ifndef HAVE_SETLOCALE
1158 : - Locale support: Only ASCII characters are recognized
1159 #endif
1160 #if ! defined HAVE_SETLOCALE || ! defined HAVE_MBTOWC || !defined HAVE_WCTYPE_H
1161 : - Multibyte character support
1162 #endif
1163 #if ! defined HAVE_SETLOCALE || ! defined HAVE_NL_LANGINFO || ! defined CODESET
1164 : - Automatic detection of terminal character set
1165 #endif
1166 #ifndef HAVE_SOCKETS
1167 : - Network support
1168 #endif
1169 #ifndef HAVE_IPV6
1170 : - Support for Internet Protocol v6 (IPv6)
1171 #endif
1172 #if ! defined HAVE_SSL
1173 : - SSL/TLS (network transport authentication and encryption)
1174 #endif
1175 #ifndef HAVE_IMAP
1176 : - IMAP protocol
1177 #endif
1178 #ifndef HAVE_GSSAPI
1179 : - IMAP GSSAPI authentication
1180 #endif
1181 #ifndef HAVE_POP3
1182 : - POP3 protocol
1183 #endif
1184 #ifndef HAVE_SMTP
1185 : - SMTP protocol
1186 #endif
1187 #ifndef HAVE_SPAM
1188 : - Interaction with spam filters
1189 #endif
1190 #ifndef HAVE_IDNA
1191 : - IDNA (internationalized domain names for applications) support
1192 #endif
1193 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
1194 : - Command line editing and history
1195 #endif
1196 #ifndef HAVE_QUOTE_FOLD
1197 : - Extended *quote-fold*ing
1198 #endif
1200 :Remarks:
1201 #ifndef HAVE_SNPRINTF
1202 : . The function snprintf() could not be found. mailx will be compiled to use
1203 : sprintf() instead. This might overflow buffers if input values are larger
1204 : than expected. Use the resulting binary with care or update your system
1205 : environment and start the configuration process again.
1206 #endif
1207 #ifndef HAVE_FCHDIR
1208 : . The function fchdir() could not be found. mailx will be compiled to use
1209 : chdir() instead. This is not a problem unless the current working
1210 : directory of mailx is moved while the IMAP cache is used.
1211 #endif
1212 #ifndef HAVE_GETOPT
1213 : . Using a minimal builtin POSIX-like getopt()
1214 #endif
1215 #ifdef HAVE_DEBUG
1216 : . Debug enabled binary: not meant to be used by end-users: THANKS!
1217 #endif
1221 ${make} -f ${makefile} ${tmp2}.x
1222 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
1224 # vim:set fenc=utf-8:s-it-mode