NEWS: update for s-nail-14_5_2-sort.patch
[s-mailx.git] / mk-conf.sh
blob20e8710ba9308314f7903bbf422356b8ae3d54ed
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 optim= dbgoptim=
74 if [ -z "${CC}" ] || [ "${CC}" = cc ]; then
75 _CFLAGS=
76 if { CC="`command -v clang`"; }; then
78 elif { CC="`command -v gcc`"; }; then
80 elif { CC="`command -v c89`"; }; then
81 [ "${i}" = UnixWare ] && _CFLAGS=-v optim=-O dbgoptim=
82 elif { CC="`command -v c99`"; }; then
84 else
85 echo >&2 'ERROR'
86 echo >&2 ' I cannot find a compiler!'
87 echo >&2 ' Neither of clang(1), gcc(1), c89(1) and c99(1).'
88 echo >&2 ' Please set the CC environment variable, maybe CFLAGS also.'
89 exit 1
92 export CC
94 ccver=`${CC} --version 2>/dev/null`
95 stackprot=no
96 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e gcc -e clang; then
97 #if echo "${i}" | ${grep} -q -i -e gcc -e 'clang version 1'; then
98 optim=-O2 dbgoptim=-O
99 stackprot=yes
100 _CFLAGS='-std=c89'
101 _CFLAGS="${_CFLAGS} -Wall -Wextra -pedantic"
102 _CFLAGS="${_CFLAGS} -fno-unwind-tables -fno-asynchronous-unwind-tables"
103 _CFLAGS="${_CFLAGS} -fstrict-aliasing"
104 _CFLAGS="${_CFLAGS} -Wbad-function-cast -Wcast-align -Wcast-qual"
105 _CFLAGS="${_CFLAGS} -Winit-self -Wshadow -Wunused -Wwrite-strings"
106 if { i=$ccver; echo "${i}"; } | ${grep} -q -e 'clang version 1'; then
108 else
109 _CFLAGS="${_CFLAGS} -fstrict-overflow -Wstrict-overflow=5"
110 if wantfeat AMALGAMATION && nwantfeat DEBUG; then
111 _CFLAGS="${_CFLAGS} -Wno-unused-function"
113 if { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
114 _CFLAGS="${_CFLAGS} -Wno-unused-result" # TODO handle the right way
117 _CFLAGS="${_CFLAGS} -Wno-long-long" # ISO C89 has no 'long long'...
118 # elif { i=$ccver; echo "${i}"; } | ${grep} -q -i -e clang; then
119 # stackprot=yes
120 # optim=-O3 dbgoptim=-O
121 # _CFLAGS='-std=c89 -g -Weverything -Wno-long-long'
122 elif [ -z "${optim}" ]; then
123 optim=-O1 dbgoptim=-O
126 if nwantfeat DEBUG; then
127 _CFLAGS="${optim} -DNDEBUG ${_CFLAGS}"
128 else
129 _CFLAGS="${dbgoptim} -g ${_CFLAGS}";
130 if [ "${stackprot}" = yes ]; then
131 _CFLAGS="${_CFLAGS} -fstack-protector-all "
132 _CFLAGS="${_CFLAGS} -Wstack-protector -D_FORTIFY_SOURCE=2"
135 _CFLAGS="${_CFLAGS} ${ADDCFLAGS}"
136 _LDFLAGS="${_LDFLAGS} ${ADDLDFLAGS}" # XXX -Wl,--sort-common,[-O1]
137 export _CFLAGS _LDFLAGS
139 # $CFLAGS and $LDFLAGS are only overwritten if explicitly wanted
140 if wantfeat AUTOCC; then
141 CFLAGS=$_CFLAGS
142 LDFLAGS=$_LDFLAGS
143 export CFLAGS LDFLAGS
147 ## -- >8 -- 8< -- ##
149 ## Notes:
150 ## - Heirloom sh(1) (and same origin) have problems with ': >' redirection,
151 ## so use "printf '' >" instead
152 ## - Heirloom sh(1) and maybe more execute loops with redirection in a subshell
153 ## (but don't export eval's from within), therefore we need to (re)include
154 ## variable assignments at toplevel instead (via reading temporary files)
156 ## First of all, create new configuration and check wether it changed ##
158 conf=./conf.rc
159 lst=./config.lst
160 h=./config.h
161 mk=./mk.mk
163 newlst=./config.lst-new
164 newmk=./config.mk-new
165 newh=./config.h-new
166 tmp0=___tmp
167 tmp=./${tmp0}1$$
169 # We need some standard utilities
170 unset -f command
171 check_tool() {
172 n=$1 i=$2 opt=${3:-0}
173 if type "${i}" >/dev/null 2>&1; then
174 eval ${n}=${i}
175 return 1
177 if [ ${opt} -eq 0 ]; then
178 echo >&2 "ERROR: no trace of the utility \`${n}'"
179 exit 1
181 return 0
184 # Check those tools right now that we need before including ${conf}
185 check_tool rm "${rm:-`command -v rm`}"
186 check_tool sed "${sed:-`command -v sed`}"
188 # Only incorporate what wasn't overwritten from command line / CONFIG
189 trap "${rm} -f ${tmp}; exit" 1 2 15
190 trap "${rm} -f ${tmp}" 0
191 ${rm} -f ${tmp}
193 < ${conf} ${sed} -e '/^[ \t]*#/d' -e '/^$/d' -e 's/[ \t]*$//' |
194 while read line; do
195 i=`echo ${line} | ${sed} -e 's/=.*$//'`
196 eval j=\$${i} jx=\${${i}+x}
197 if [ -n "${j}" ] || [ "${jx}" = x ]; then
198 line="${i}=\"${j}\""
200 echo ${line}
201 done > ${tmp}
202 . ./${tmp}
204 check_tool awk "${awk:-`command -v awk`}"
205 check_tool cat "${cat:-`command -v cat`}"
206 check_tool chmod "${chmod:-`command -v chmod`}"
207 check_tool cp "${cp:-`command -v cp`}"
208 check_tool cmp "${cmp:-`command -v cmp`}"
209 check_tool grep "${grep:-`command -v grep`}"
210 check_tool mkdir "${mkdir:-`command -v mkdir`}"
211 check_tool mv "${mv:-`command -v mv`}"
212 # rm(1), sed(1) above
213 check_tool tee "${tee:-`command -v tee`}"
215 check_tool make "${MAKE:-`command -v make`}"
216 check_tool strip "${STRIP:-`command -v strip`}" 1
217 HAVE_STRIP=${?}
219 wantfeat() {
220 eval i=\$WANT_${1}
221 [ "${i}" = "1" ]
223 nwantfeat() {
224 eval i=\$WANT_${1}
225 [ "${i}" != "1" ]
228 option_update
230 # (No function since some shells loose non-exported variables in traps)
231 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}; exit" 1 2 15
232 trap "${rm} -f ${tmp} ${newlst} ${newmk} ${newh}" 0
233 ${rm} -f ${newlst} ${newmk} ${newh}
235 # (Could: use FD redirection, add eval(1) and don't re-'. ./${newlst}')
236 while read line; do
237 i=`echo ${line} | ${sed} -e 's/=.*$//'`
238 eval j=\$${i}
239 if [ -z "${j}" ] || [ "${j}" = 0 ]; then
240 printf "/*#define ${i}*/\n" >> ${newh}
241 elif [ "${j}" = 1 ]; then
242 printf "#define ${i}\n" >> ${newh}
243 else
244 printf "#define ${i} \"${j}\"\n" >> ${newh}
246 printf "${i} = ${j}\n" >> ${newmk}
247 printf "${i}=\"${j}\"\n"
248 done < ${tmp} > ${newlst}
249 . ./${newlst}
251 printf "#define UAGENT \"${SID}${NAIL}\"\n" >> ${newh}
252 printf "UAGENT = ${SID}${NAIL}\n" >> ${newmk}
254 compiler_flags
256 printf "CC = ${CC}\n" >> ${newmk}
257 printf "_CFLAGS = ${_CFLAGS}\nCFLAGS = ${CFLAGS}\n" >> ${newmk}
258 printf "_LDFLAGS = ${_LDFLAGS}\nLDFLAGS = ${LDFLAGS}\n" >> ${newmk}
259 printf "AWK = ${awk}\nCMP = ${cmp}\nCHMOD = ${chmod}\nCP = ${cp}\n" >> ${newmk}
260 printf "GREP = ${grep}\nMKDIR = ${mkdir}\nRM = ${rm}\nSED = ${sed}\n" \
261 >> ${newmk}
262 printf "STRIP = ${strip}\nHAVE_STRIP = ${HAVE_STRIP}\n" >> ${newmk}
263 # (We include the cc(1)/ld(1) environment only for update detection..)
264 printf "CC=\"${CC}\"\n" >> ${newlst}
265 printf "_CFLAGS=\"${_CFLAGS}\"\nCFLAGS=\"${CFLAGS}\"\n" >> ${newlst}
266 printf "_LDFLAGS=\"${_LDFLAGS}\"\nLDFLAGS=\"${LDFLAGS}\"\n" >> ${newlst}
267 printf "AWK=${awk}\nCMP=${cmp}\nCHMOD=${chmod}\nCP=${cp}\n" >> ${newlst}
268 printf "GREP=${grep}\nMKDIR=${mkdir}\nRM=${rm}\nSED=${sed}\n" >> ${newlst}
269 printf "STRIP=${strip}\nHAVE_STRIP=${HAVE_STRIP}\n" >> ${newlst}
271 if [ -f ${lst} ] && ${cmp} ${newlst} ${lst} >/dev/null 2>&1; then
272 exit 0
274 [ -f ${lst} ] && echo 'configuration updated..' || echo 'shiny configuration..'
276 ${mv} -f ${newlst} ${lst}
277 ${mv} -f ${newh} ${h}
278 ${mv} -f ${newmk} ${mk}
280 ## Compile and link checking ##
282 tmp2=./${tmp0}2$$
283 tmp3=./${tmp0}3$$
284 log=./config.log
285 lib=./config.lib
286 inc=./config.inc
287 src=./config.c
288 makefile=./config.mk
290 # (No function since some shells loose non-exported variables in traps)
291 trap "${rm} -f ${lst} ${h} ${mk} ${lib} ${inc} ${src} ${makefile}; exit" 1 2 15
292 trap "${rm} -rf ${tmp0}.* ${tmp0}* ${makefile}" 0
294 exec 5>&2 > ${log} 2>&1
295 printf '' > ${lib}
296 printf '' > ${inc}
297 # ${src} is only created if WANT_AMALGAMATION
298 ${rm} -f ${src}
299 ${cat} > ${makefile} << \!
300 .SUFFIXES: .o .c .x .y
301 .c.o:
302 $(CC) $(XINCS) -c $<
303 .c.x:
304 $(CC) $(XINCS) -E $< >$@
306 $(CC) $(XINCS) -o $@ $< $(XLIBS)
307 .y: ;
310 msg() {
311 fmt=$1
313 shift
314 printf "*** ${fmt}\\n" "${@}"
315 printf "${fmt}" "${@}" >&5
318 _check_preface() {
319 variable=$1 topic=$2 define=$3
321 echo '**********'
322 msg "checking ${topic} ... "
323 echo "/* checked ${topic} */" >> ${h}
324 ${rm} -f ${tmp} ${tmp}.o
325 echo '*** test program is'
326 ${tee} ${tmp}.c
327 #echo '*** the preprocessor generates'
328 #${make} -f ${makefile} ${tmp}.x
329 #${cat} ${tmp}.x
330 echo '*** results are'
333 compile_check() {
334 variable=$1 topic=$2 define=$3
336 _check_preface "${variable}" "${topic}" "${define}"
338 if ${make} -f ${makefile} XINCS="${INCS}" ./${tmp}.o &&
339 [ -f ./${tmp}.o ]; then
340 msg "yes\\n"
341 echo "${define}" >> ${h}
342 eval have_${variable}=yes
343 return 0
344 else
345 echo "/* ${define} */" >> ${h}
346 msg "no\\n"
347 eval unset have_${variable}
348 return 1
352 _link_mayrun() {
353 run=$1 variable=$2 topic=$3 define=$4 libs=$5 incs=$6
355 _check_preface "${variable}" "${topic}" "${define}"
357 if ${make} -f ${makefile} XINCS="${INCS} ${incs}" \
358 XLIBS="${LIBS} ${libs}" ./${tmp} &&
359 [ -f ./${tmp} ] &&
360 { [ ${run} -eq 0 ] || ./${tmp}; }; then
361 echo "*** adding INCS<${incs}> LIBS<${libs}>"
362 msg "yes\\n"
363 echo "${define}" >> ${h}
364 LIBS="${LIBS} ${libs}"
365 echo "${libs}" >> ${lib}
366 INCS="${INCS} ${incs}"
367 echo "${incs}" >> ${inc}
368 eval have_${variable}=yes
369 return 0
370 else
371 msg "no\\n"
372 echo "/* ${define} */" >> ${h}
373 eval unset have_${variable}
374 return 1
378 link_check() {
379 _link_mayrun 0 "${1}" "${2}" "${3}" "${4}" "${5}"
382 run_check() {
383 _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}"
386 # Build a basic set of INCS and LIBS according to user environment.
387 # On pkgsrc(7) systems automatically add /usr/pkg/*
388 if [ -n "${C_INCLUDE_PATH}" ]; then
389 i=${IFS}
390 IFS=:
391 set -- ${C_INCLUDE_PATH}
392 IFS=${i}
393 # for i; do -- new in POSIX Issue 7 + TC1
394 for i
396 [ "${i}" = '/usr/pkg/include' ] && continue
397 INCS="${INCS} -I${i}"
398 done
400 [ -d /usr/pkg/include ] && INCS="${INCS} -I/usr/pkg/include"
401 echo "${INCS}" >> ${inc}
403 if [ -n "${LD_LIBRARY_PATH}" ]; then
404 i=${IFS}
405 IFS=:
406 set -- ${LD_LIBRARY_PATH}
407 IFS=${i}
408 # for i; do -- new in POSIX Issue 7 + TC1
409 for i
411 [ "${i}" = '/usr/pkg/lib' ] && continue
412 LIBS="${LIBS} -L${i}"
413 done
415 [ -d /usr/pkg/lib ] && LIBS="${LIBS} -L/usr/pkg/lib"
416 echo "${LIBS}" >> ${lib}
420 # Better set _GNU_SOURCE (if we are on Linux only?); 'surprised it did without
421 echo '#define _GNU_SOURCE' >> ${h}
423 link_check hello 'if a hello world program can be built' << \! || {\
424 echo >&5 'This oooops is most certainly not related to me.';\
425 echo >&5 "Read the file ${log} and check your compiler environment.";\
426 ${rm} -f ${lst} ${h} ${mk};\
427 exit 1;\
429 #include <stdio.h>
431 int main(int argc, char *argv[])
433 (void)argc;
434 (void)argv;
435 puts("hello world");
436 return 0;
440 link_check termios 'for termios.h and tc*() family' << \! || {\
441 echo >&5 'We require termios.h and the tc*() family of functions.';\
442 echo >&5 "That much Unix we indulge ourselfs.";\
443 ${rm} -f ${lst} ${h} ${mk};\
444 exit 1;\
446 #include <termios.h>
447 int main(void)
449 struct termios tios;
450 tcgetattr(0, &tios);
451 tcsetattr(0, TCSADRAIN | TCSAFLUSH, &tios);
452 return 0;
456 link_check setenv 'for setenv()/unsetenv()' '#define HAVE_SETENV' << \!
457 #include <stdlib.h>
458 int main(void)
460 setenv("s-nail", "to be made nifty!", 1);
461 unsetenv("s-nail");
462 return 0;
466 link_check snprintf 'for snprintf()' '#define HAVE_SNPRINTF' << \!
467 #include <stdio.h>
468 int main(void)
470 char b[20];
471 snprintf(b, sizeof b, "%s", "string");
472 return 0;
476 link_check putc_unlocked 'for putc_unlocked()' '#define HAVE_PUTC_UNLOCKED' <<\!
477 #include <stdio.h>
478 int main(void)
480 putc_unlocked('@', stdout);
481 return 0;
485 link_check fchdir 'for fchdir()' '#define HAVE_FCHDIR' << \!
486 #include <unistd.h>
487 int main(void)
489 fchdir(0);
490 return 0;
494 link_check mmap 'for mmap()' '#define HAVE_MMAP' << \!
495 #include <sys/types.h>
496 #include <sys/mman.h>
497 int main(void)
499 mmap(0, 0, 0, 0, 0, 0);
500 return 0;
504 link_check mremap 'for mremap()' '#define HAVE_MREMAP' << \!
505 #include <sys/types.h>
506 #include <sys/mman.h>
507 int main(void)
509 mremap(0, 0, 0, MREMAP_MAYMOVE);
510 return 0;
514 link_check setlocale 'for setlocale()' '#define HAVE_SETLOCALE' << \!
515 #include <locale.h>
516 int main(void)
518 setlocale(LC_ALL, "");
519 return 0;
523 if [ "${have_setlocale}" = yes ]; then
524 link_check c90amend1 'for ISO/IEC 9899:1990/Amendment 1:1995' \
525 '#define HAVE_C90AMEND1' << \!
526 #include <limits.h>
527 #include <stdlib.h>
528 #include <wchar.h>
529 #include <wctype.h>
530 int main(void)
532 char mbb[MB_LEN_MAX + 1];
533 wchar_t wc;
534 iswprint(L'c');
535 towupper(L'c');
536 mbtowc(&wc, "x", 1);
537 mbrtowc(&wc, "x", 1, NULL);
538 (void)wctomb(mbb, wc);
539 return (mblen("\0", 1) == 0);
543 if [ "${have_c90amend1}" = yes ]; then
544 link_check wcwidth 'for wcwidth()' '#define HAVE_WCWIDTH' << \!
545 #include <wchar.h>
546 int main(void)
548 wcwidth(L'c');
549 return 0;
554 link_check nl_langinfo 'for nl_langinfo()' '#define HAVE_NL_LANGINFO' << \!
555 #include <langinfo.h>
556 #include <stdlib.h>
557 int main(void)
559 nl_langinfo(DAY_1);
560 return (nl_langinfo(CODESET) == NULL);
563 fi # have_setlocale
565 link_check mkstemp 'for mkstemp()' '#define HAVE_MKSTEMP' << \!
566 #include <stdlib.h>
567 int main(void)
569 mkstemp("x");
570 return 0;
574 # Note: run_check, thus we also get only the desired implementation...
575 run_check realpath 'for realpath()' '#define HAVE_REALPATH' << \!
576 #include <stdlib.h>
577 int main(void)
579 char *x = realpath(".", NULL), *y = realpath("/", NULL);
580 return (x != NULL && y != NULL) ? 0 : 1;
584 link_check wordexp 'for wordexp()' '#define HAVE_WORDEXP' << \!
585 #include <wordexp.h>
586 int main(void)
588 wordexp((char *)0, (wordexp_t *)0, 0);
589 return 0;
595 if wantfeat DEBUG; then
596 echo '#define HAVE_DEBUG' >> ${h}
599 if wantfeat AMALGAMATION; then
600 echo '#define HAVE_AMALGAMATION' >> ${h}
603 if nwantfeat NOALLOCA; then
604 # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin
605 # versions of alloca(3) since modern compilers just can't be trusted
606 # not to overoptimize and silently break some code
607 link_check alloca 'for __builtin_alloca()' \
608 '#define HAVE_ALLOCA __builtin_alloca' << \!
609 int main(void)
611 void *vp = __builtin_alloca(1);
612 return (!! vp);
617 if nwantfeat NOGETOPT; then
618 link_check getopt 'for getopt()' '#define HAVE_GETOPT' << \!
619 #include <unistd.h>
620 int main(int argc, char **argv)
622 #if defined __GLIBC__ || defined __linux__
623 Argument and option reordering is not a desired feature.
624 #else
625 getopt(argc, argv, "oPt");
626 #endif
627 return (((long)optarg + optind) & 0x7F);
634 if wantfeat ICONV; then
635 ${cat} > ${tmp2}.c << \!
636 #include <iconv.h>
637 int main(void)
639 iconv_t id;
641 id = iconv_open("foo", "bar");
642 return 0;
645 < ${tmp2}.c link_check iconv 'for iconv functionality' \
646 '#define HAVE_ICONV' ||
647 < ${tmp2}.c link_check iconv \
648 'for iconv functionality in libiconv' \
649 '#define HAVE_ICONV' '-liconv'
650 else
651 echo '/* WANT_ICONV=0 */' >> ${h}
652 fi # wantfeat ICONV
654 if wantfeat SOCKETS; then
655 compile_check arpa_inet_h 'for <arpa/inet.h>' \
656 '#define HAVE_ARPA_INET_H' << \!
657 #include "config.h"
658 #include <sys/types.h>
659 #include <sys/socket.h>
660 #include <netdb.h>
661 #include <netinet/in.h>
662 #include <arpa/inet.h>
665 ${cat} > ${tmp2}.c << \!
666 #include "config.h"
667 #include <sys/types.h>
668 #include <sys/socket.h>
669 #include <netdb.h>
670 #include <netinet/in.h>
671 #ifdef HAVE_ARPA_INET_H
672 #include <arpa/inet.h>
673 #endif
675 int main(void)
677 struct sockaddr s;
678 socket(AF_INET, SOCK_STREAM, 0);
679 connect(0, &s, 0);
680 gethostbyname("foo");
681 return 0;
685 < ${tmp2}.c link_check sockets 'for sockets in libc' \
686 '#define HAVE_SOCKETS' ||
687 < ${tmp2}.c link_check sockets 'for sockets in libnsl' \
688 '#define HAVE_SOCKETS' '-lnsl' ||
689 < ${tmp2}.c link_check sockets \
690 'for sockets in libsocket and libnsl' \
691 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
692 WANT_SOCKETS=0
694 # XXX Shouldn't it be a hard error if there is no socket support, then?
695 option_update
696 else
697 echo '/* WANT_SOCKETS=0 */' >> ${h}
698 fi # wantfeat SOCKETS
700 wantfeat SOCKETS &&
701 link_check setsockopt 'for setsockopt()' '#define HAVE_SETSOCKOPT' << \!
702 #include <sys/socket.h>
703 #include <stdlib.h>
704 int main(void)
706 int sockfd = 3;
707 setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0);
708 return 0;
712 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
713 link_check so_sndtimeo 'for SO_SNDTIMEO' '#define HAVE_SO_SNDTIMEO' << \!
714 #include <sys/socket.h>
715 #include <stdlib.h>
716 int main(void)
718 struct timeval tv;
719 int sockfd = 3;
720 tv.tv_sec = 42;
721 tv.tv_usec = 21;
722 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
723 setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
724 return 0;
728 wantfeat SOCKETS && [ -n "${have_setsockopt}" ] &&
729 link_check so_linger 'for SO_LINGER' '#define HAVE_SO_LINGER' << \!
730 #include <sys/socket.h>
731 #include <stdlib.h>
732 int main(void)
734 struct linger li;
735 int sockfd = 3;
736 li.l_onoff = 1;
737 li.l_linger = 42;
738 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &li, sizeof li);
739 return 0;
743 if wantfeat IPV6; then
744 link_check ipv6 'for IPv6 functionality' '#define HAVE_IPV6' << \!
745 #include "config.h"
746 #include <sys/types.h>
747 #include <sys/socket.h>
748 #include <netdb.h>
749 #include <netinet/in.h>
750 #ifdef HAVE_ARPA_INET_H
751 #include <arpa/inet.h>
752 #endif
754 int main(void)
756 struct addrinfo a, *ap;
757 getaddrinfo("foo", "0", &a, &ap);
758 return 0;
761 else
762 echo '/* WANT_IPV6=0 */' >> ${h}
763 fi # wantfeat IPV6
765 if wantfeat IMAP; then
766 echo '#define HAVE_IMAP' >> ${h}
767 else
768 echo '/* WANT_IMAP=0 */' >> ${h}
771 if wantfeat POP3; then
772 echo '#define HAVE_POP3' >> ${h}
773 else
774 echo '/* WANT_POP3=0 */' >> ${h}
777 if wantfeat SMTP; then
778 echo '#define HAVE_SMTP' >> ${h}
779 else
780 echo '/* WANT_SMTP=0 */' >> ${h}
783 if wantfeat SSL; then
784 link_check openssl 'for sufficiently recent OpenSSL' \
785 '#define HAVE_SSL
786 #define HAVE_OPENSSL' '-lssl -lcrypto' << \!
787 #include <openssl/ssl.h>
788 #include <openssl/err.h>
789 #include <openssl/x509v3.h>
790 #include <openssl/x509.h>
791 #include <openssl/rand.h>
793 #if defined OPENSSL_NO_SSL2 && defined OPENSSL_NO_SSL3 &&\
794 defined OPENSSL_NO_TLS1
795 # error We need one of (SSLv2 and) SSLv3 and TLS1.
796 #endif
798 int main(void)
800 SSLv23_client_method();
801 #ifndef OPENSSL_NO_SSL3
802 SSLv3_client_method();
803 #endif
804 #ifndef OPENSSL_NO_TLS1
805 TLSv1_client_method();
806 # ifdef TLS1_1_VERSION
807 TLSv1_1_client_method();
808 # endif
809 # ifdef TLS1_2_VERSION
810 TLSv1_2_client_method();
811 # endif
812 #endif
813 PEM_read_PrivateKey(0, 0, 0, 0);
814 return 0;
818 if [ "${have_openssl}" = 'yes' ]; then
819 compile_check stack_of 'for OpenSSL STACK_OF()' \
820 '#define HAVE_STACK_OF' << \!
821 #include <openssl/ssl.h>
822 #include <openssl/err.h>
823 #include <openssl/x509v3.h>
824 #include <openssl/x509.h>
825 #include <openssl/rand.h>
827 int main(void)
829 STACK_OF(GENERAL_NAME) *gens = NULL;
830 printf("%p", gens); /* to make it used */
831 return 0;
835 run_check openssl_md5 'for MD5 digest in OpenSSL' \
836 '#define HAVE_OPENSSL_MD5' << \!
837 #include <string.h>
838 #include <openssl/md5.h>
840 int main(void)
842 char const dat[] = "abrakadabrafidibus";
843 char dig[16], hex[16 * 2];
844 MD5_CTX ctx;
845 size_t i, j;
847 memset(dig, 0, sizeof(dig));
848 memset(hex, 0, sizeof(hex));
849 MD5_Init(&ctx);
850 MD5_Update(&ctx, dat, sizeof(dat) - 1);
851 MD5_Final(dig, &ctx);
853 #define hexchar(n) ((n)>9 ? (n)-10+'a' : (n)+'0')
854 for (i = 0; i < sizeof(hex) / 2; i++) {
855 j = i << 1;
856 hex[j] = hexchar((dig[i] & 0xf0) >> 4);
857 hex[++j] = hexchar(dig[i] & 0x0f);
859 return !!memcmp("6d7d0a3d949da2e96f2aa010f65d8326", hex, sizeof(hex));
864 else
865 echo '/* WANT_SSL=0 */' >> ${h}
866 fi # wantfeat SSL
868 if wantfeat GSSAPI; then
869 ${cat} > ${tmp2}.c << \!
870 #include <gssapi/gssapi.h>
872 int main(void)
874 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
875 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
876 return 0;
879 ${sed} -e '1s/gssapi\///' < ${tmp2}.c > ${tmp3}.c
881 if command -v krb5-config >/dev/null 2>&1; then
882 i=`command -v krb5-config`
883 GSSAPI_LIBS="`CFLAGS= ${i} --libs gssapi`"
884 GSSAPI_INCS="`CFLAGS= ${i} --cflags`"
885 i='for GSSAPI via krb5-config(1)'
886 else
887 GSSAPI_LIBS='-lgssapi'
888 GSSAPI_INCS=
889 i='for GSSAPI in gssapi/gssapi.h, libgssapi'
891 < ${tmp2}.c link_check gssapi \
892 "${i}" '#define HAVE_GSSAPI' \
893 "${GSSAPI_LIBS}" "${GSSAPI_INCS}" ||\
894 < ${tmp3}.c link_check gssapi \
895 'for GSSAPI in gssapi.h, libgssapi' \
896 '#define HAVE_GSSAPI
897 #define GSSAPI_REG_INCLUDE' \
898 '-lgssapi' ||\
899 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgssapi_krb5' \
900 '#define HAVE_GSSAPI' \
901 '-lgssapi_krb5' ||\
902 < ${tmp3}.c link_check gssapi \
903 'for GSSAPI in libgssapi, OpenBSD-style (pre 5.3)' \
904 '#define HAVE_GSSAPI
905 #define GSSAPI_REG_INCLUDE' \
906 '-lgssapi -lkrb5 -lcrypto' \
907 '-I/usr/include/kerberosV' ||\
908 < ${tmp2}.c link_check gssapi 'for GSSAPI in libgss' \
909 '#define HAVE_GSSAPI' \
910 '-lgss' ||\
911 link_check gssapi 'for GSSAPI in libgssapi_krb5, old-style' \
912 '#define HAVE_GSSAPI
913 #define GSSAPI_OLD_STYLE' \
914 '-lgssapi_krb5' << \!
915 #include <gssapi/gssapi.h>
916 #include <gssapi/gssapi_generic.h>
918 int main(void)
920 gss_import_name(0, 0, gss_nt_service_name, 0);
921 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
922 return 0;
925 else
926 echo '/* WANT_GSSAPI=0 */' >> ${h}
927 fi # wantfeat GSSAPI
929 if wantfeat IDNA; then
930 link_check idna 'for GNU Libidn' '#define HAVE_IDNA' '-lidn' << \!
931 #include <idna.h>
932 #include <stringprep.h>
933 int main(void)
935 char *utf8, *idna_ascii, *idna_utf8;
936 utf8 = stringprep_locale_to_utf8("does.this.work");
937 if (idna_to_ascii_8z(utf8, &idna_ascii, IDNA_USE_STD3_ASCII_RULES)
938 != IDNA_SUCCESS)
939 return 1;
940 /* (Rather link check only here) */
941 idna_utf8 = stringprep_convert(idna_ascii, "UTF-8", "de_DE");
942 return 0;
945 else
946 echo '/* WANT_IDNA=0 */' >> ${h}
949 if wantfeat REGEX; then
950 link_check regex 'for regular expressions' '#define HAVE_REGEX' << \!
951 #include <regex.h>
952 #include <stdlib.h>
953 int main(void)
955 int status;
956 regex_t re;
957 if (regcomp(&re, ".*bsd", REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
958 return 1;
959 status = regexec(&re, "plan9", 0,NULL, 0);
960 regfree(&re);
961 return !(status == REG_NOMATCH);
964 else
965 echo '/* WANT_REGEX=0 */' >> ${h}
968 if wantfeat READLINE; then
969 __edrdlib() {
970 link_check readline "for readline(3) (${1})" \
971 '#define HAVE_READLINE' "${1}" << \!
972 #include <stdio.h>
973 #include <readline/history.h>
974 #include <readline/readline.h>
975 int main(void)
977 char *rl;
978 HISTORY_STATE *hs;
979 HIST_ENTRY **he;
980 int i;
981 using_history();
982 read_history("");
983 stifle_history(242);
984 rl = readline("Enter a line:");
985 if (rl && *rl)
986 add_history(rl);
987 write_history("");
988 rl_extend_line_buffer(10);
989 rl_point = rl_end = 10;
990 rl_pre_input_hook = (rl_hook_func_t*)NULL;
991 rl_forced_update_display();
992 clear_history();
993 hs = history_get_history_state();
994 i = hs->length;
995 he = history_list();
996 if (i > 0)
997 rl = he[0]->line;
998 rl_free_line_state();
999 rl_cleanup_after_signal();
1000 rl_reset_after_signal();
1001 return 0;
1006 __edrdlib -lreadline ||
1007 __edrdlib '-lreadline -ltermcap'
1008 [ -n "${have_readline}" ] && WANT_TABEXPAND=1
1011 if wantfeat EDITLINE && [ -z "${have_readline}" ]; then
1012 __edlib() {
1013 link_check editline "for editline(3) (${1})" \
1014 '#define HAVE_EDITLINE' "${1}" << \!
1015 #include <histedit.h>
1016 static char * getprompt(void) { return (char*)"ok"; }
1017 int main(void)
1019 EditLine *el_el = el_init("TEST", stdin, stdout, stderr);
1020 HistEvent he;
1021 History *el_hcom = history_init();
1022 history(el_hcom, &he, H_SETSIZE, 242);
1023 el_set(el_el, EL_SIGNAL, 0);
1024 el_set(el_el, EL_TERMINAL, NULL);
1025 el_set(el_el, EL_HIST, &history, el_hcom);
1026 el_set(el_el, EL_EDITOR, "emacs");
1027 el_set(el_el, EL_PROMPT, &getprompt);
1028 el_source(el_el, NULL);
1029 history(el_hcom, &he, H_GETSIZE);
1030 history(el_hcom, &he, H_CLEAR);
1031 el_end(el_el);
1032 /* TODO add loader and addfn checks */
1033 history_end(el_hcom);
1034 return 0;
1039 __edlib -ledit ||
1040 __edlib '-ledit -ltermcap'
1041 [ -n "${have_editline}" ] && WANT_TABEXPAND=0
1044 if wantfeat NCL && [ -z "${have_editline}" ] && [ -z "${have_readline}" ] &&\
1045 [ -n "${have_c90amend1}" ]; then
1046 have_ncl=1
1047 echo '#define HAVE_NCL' >> ${h}
1048 else
1049 echo '/* WANT_{READLINE,EDITLINE,NCL}=0 */' >> ${h}
1052 # Generic have-a-command-line-editor switch for those who need it below
1053 if [ -n "${have_ncl}" ] || [ -n "${have_editline}" ] ||\
1054 [ -n "${have_readline}" ]; then
1055 have_cle=1
1058 if [ -n "${have_cle}" ] && wantfeat TABEXPAND; then
1059 echo '#define HAVE_TABEXPAND' >> ${h}
1060 else
1061 echo '/* WANT_TABEXPAND=0 */' >> ${h}
1064 if [ -n "${have_cle}" ] && wantfeat HISTORY; then
1065 echo '#define HAVE_HISTORY' >> ${h}
1066 else
1067 echo '/* WANT_HISTORY=0 */' >> ${h}
1070 if wantfeat SPAM; then
1071 echo '#define HAVE_SPAM' >> ${h}
1072 if command -v spamc >/dev/null 2>&1; then
1073 echo "#define SPAMC_PATH \"`command -v spamc`\"" >> ${h}
1075 else
1076 echo '/* WANT_SPAM=0 */' >> ${h}
1079 if wantfeat DOCSTRINGS; then
1080 echo '#define HAVE_DOCSTRINGS' >> ${h}
1081 else
1082 echo '/* WANT_DOCSTRINGS=0 */' >> ${h}
1085 if wantfeat QUOTE_FOLD &&\
1086 [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then
1087 echo '#define HAVE_QUOTE_FOLD' >> ${h}
1088 else
1089 echo '/* WANT_QUOTE_FOLD=0 */' >> ${h}
1092 if wantfeat COLOUR; then
1093 echo '#define HAVE_COLOUR' >> ${h}
1094 else
1095 echo '/* WANT_COLOUR=0 */' >> ${h}
1098 if wantfeat MD5; then
1099 echo '#define HAVE_MD5' >> ${h}
1100 else
1101 echo '/* WANT_MD5=0 */' >> ${h}
1104 ## Summarizing ##
1106 # Since we cat(1) the content of those to cc/"ld", convert them to single line
1107 squeeze_em() {
1108 < "${1}" > "${2}" ${awk} \
1109 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
1111 ${rm} -f ${tmp}
1112 squeeze_em ${inc} ${tmp}
1113 ${mv} ${tmp} ${inc}
1114 squeeze_em ${lib} ${tmp}
1115 ${mv} ${tmp} ${lib}
1117 # config.h
1118 ${mv} ${h} ${tmp}
1119 printf '#ifndef _CONFIG_H\n# define _CONFIG_H\n' > ${h}
1120 ${cat} ${tmp} >> ${h}
1122 printf '\n/* The "feature string", for "simplicity" and lex.c */\n' >> ${h}
1123 printf '#ifdef _MAIN_SOURCE\n' >> ${h}
1124 printf '# ifdef HAVE_AMALGAMATION\nstatic\n# endif\n' >> ${h}
1125 printf 'char const features[] = "MIME"\n' >> ${h}
1126 printf '# ifdef HAVE_DOCSTRINGS\n ",DOCSTRINGS"\n# endif\n' >> ${h}
1127 printf '# ifdef HAVE_ICONV\n ",ICONV"\n# endif\n' >> ${h}
1128 printf '# ifdef HAVE_SETLOCALE\n ",LOCALES"\n# endif\n' >> ${h}
1129 printf '# ifdef HAVE_C90AMEND1\n ",MULTIBYTE CHARSETS"\n# endif\n' >> ${h}
1130 printf '# ifdef HAVE_NL_LANGINFO\n ",TERMINAL CHARSET"\n# endif\n' >> ${h}
1131 printf '# ifdef HAVE_SOCKETS\n ",NETWORK"\n# endif\n' >> ${h}
1132 printf '# ifdef HAVE_IPV6\n ",IPv6"\n# endif\n' >> ${h}
1133 printf '# ifdef HAVE_SSL\n ",S/MIME,SSL/TSL"\n# endif\n' >> ${h}
1134 printf '# ifdef HAVE_IMAP\n ",IMAP"\n# endif\n' >> ${h}
1135 printf '# ifdef HAVE_GSSAPI\n ",GSSAPI"\n# endif\n' >> ${h}
1136 printf '# ifdef HAVE_POP3\n ",POP3"\n# endif\n' >> ${h}
1137 printf '# ifdef HAVE_SMTP\n ",SMTP"\n# endif\n' >> ${h}
1138 printf '# ifdef HAVE_SPAM\n ",SPAM"\n# endif\n' >> ${h}
1139 printf '# ifdef HAVE_IDNA\n ",IDNA"\n# endif\n' >> ${h}
1140 printf '# ifdef HAVE_REGEX\n ",REGEX"\n# endif\n' >> ${h}
1141 printf '# ifdef HAVE_READLINE\n ",READLINE"\n# endif\n' >> ${h}
1142 printf '# ifdef HAVE_EDITLINE\n ",EDITLINE"\n# endif\n' >> ${h}
1143 printf '# ifdef HAVE_NCL\n ",NCL"\n# endif\n' >> ${h}
1144 printf '# ifdef HAVE_TABEXPAND\n ",TABEXPAND"\n# endif\n' >> ${h}
1145 printf '# ifdef HAVE_HISTORY\n ",HISTORY MANAGEMENT"\n# endif\n' >> ${h}
1146 printf '# ifdef HAVE_QUOTE_FOLD\n ",QUOTE-FOLD"\n# endif\n' >> ${h}
1147 printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h}
1148 printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h}
1149 printf ';\n#endif /* _MAIN_SOURCE */\n' >> ${h}
1151 printf '#endif /* _CONFIG_H */\n' >> ${h}
1152 ${rm} -f ${tmp}
1154 # Create the real mk.mk
1155 ${rm} -rf ${tmp0}.* ${tmp0}*
1156 printf 'OBJ_SRC = ' >> ${mk}
1157 if nwantfeat AMALGAMATION; then
1158 echo *.c >> ${mk}
1159 echo 'OBJ_DEP =' >> ${mk}
1160 else
1161 j=`echo "${src}" | sed 's/^.\///'`
1162 echo "${j}" >> ${mk}
1163 printf 'OBJ_DEP = main.c ' >> ${mk}
1164 printf '#define _MAIN_SOURCE\n' >> ${src}
1165 printf '#include "nail.h"\n#include "main.c"\n' >> ${src}
1166 for i in *.c; do
1167 if [ "${i}" = "${j}" ] || [ "${i}" = main.c ]; then
1168 continue
1170 printf "${i} " >> ${mk}
1171 printf "#include \"${i}\"\n" >> ${src}
1172 done
1173 echo >> ${mk}
1176 echo "LIBS = `${cat} ${lib}`" >> ${mk}
1177 echo "INCLUDES = `${cat} ${inc}`" >> ${mk}
1178 echo >> ${mk}
1179 ${cat} ./mk-mk.in >> ${mk}
1181 ## Finished! ##
1183 ${cat} > ${tmp2}.c << \!
1184 #include "config.h"
1185 #ifdef HAVE_NL_LANGINFO
1186 # include <langinfo.h>
1187 #endif
1189 :The following optional features are enabled:
1190 #ifdef HAVE_ICONV
1191 : + Character set conversion using iconv()
1192 #endif
1193 #ifdef HAVE_SETLOCALE
1194 : + Locale support: Printable characters depend on the environment
1195 # ifdef HAVE_C90AMEND1
1196 : + Multibyte character support
1197 # endif
1198 # ifdef HAVE_NL_LANGINFO
1199 : + Automatic detection of terminal character set
1200 # endif
1201 #endif
1202 #ifdef HAVE_SOCKETS
1203 : + Network support
1204 #endif
1205 #ifdef HAVE_IPV6
1206 : + Support for Internet Protocol v6 (IPv6)
1207 #endif
1208 #ifdef HAVE_SSL
1209 # ifdef HAVE_OPENSSL
1210 : + S/MIME and SSL/TLS using OpenSSL
1211 # endif
1212 #endif
1213 #ifdef HAVE_IMAP
1214 : + IMAP protocol
1215 #endif
1216 #ifdef HAVE_GSSAPI
1217 : + IMAP GSSAPI authentication
1218 #endif
1219 #ifdef HAVE_POP3
1220 : + POP3 protocol
1221 #endif
1222 #ifdef HAVE_SMTP
1223 : + SMTP protocol
1224 #endif
1225 #ifdef HAVE_SPAM
1226 : + Interaction with spam filters
1227 #endif
1228 #ifdef HAVE_IDNA
1229 : + IDNA (internationalized domain names for applications) support
1230 #endif
1231 #ifdef HAVE_REGEX
1232 : + Regular expression searches
1233 #endif
1234 #if defined HAVE_READLINE || defined HAVE_EDITLINE || defined HAVE_NCL
1235 : + Command line editing
1236 # ifdef HAVE_TABEXPAND
1237 : + + Tabulator expansion
1238 # endif
1239 # ifdef HAVE_HISTORY
1240 : + + History management
1241 # endif
1242 #endif
1243 #ifdef HAVE_QUOTE_FOLD
1244 : + Extended *quote-fold*ing
1245 #endif
1246 #ifdef HAVE_COLOUR
1247 : + Coloured message display (simple)
1248 #endif
1250 :The following optional features are disabled:
1251 #ifndef HAVE_ICONV
1252 : - Character set conversion using iconv()
1253 #endif
1254 #ifndef HAVE_SETLOCALE
1255 : - Locale support: Only ASCII characters are recognized
1256 #endif
1257 # ifndef HAVE_C90AMEND1
1258 : - Multibyte character support
1259 # endif
1260 # ifndef HAVE_NL_LANGINFO
1261 : - Automatic detection of terminal character set
1262 # endif
1263 #ifndef HAVE_SOCKETS
1264 : - Network support
1265 #endif
1266 #ifndef HAVE_IPV6
1267 : - Support for Internet Protocol v6 (IPv6)
1268 #endif
1269 #if !defined HAVE_SSL
1270 : - SSL/TLS (network transport authentication and encryption)
1271 #endif
1272 #ifndef HAVE_IMAP
1273 : - IMAP protocol
1274 #endif
1275 #ifndef HAVE_GSSAPI
1276 : - IMAP GSSAPI authentication
1277 #endif
1278 #ifndef HAVE_POP3
1279 : - POP3 protocol
1280 #endif
1281 #ifndef HAVE_SMTP
1282 : - SMTP protocol
1283 #endif
1284 #ifndef HAVE_SPAM
1285 : - Interaction with spam filters
1286 #endif
1287 #ifndef HAVE_IDNA
1288 : - IDNA (internationalized domain names for applications) support
1289 #endif
1290 #ifndef HAVE_REGEX
1291 : - Regular expression searches
1292 #endif
1293 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
1294 : - Command line editing and history
1295 #endif
1296 #ifndef HAVE_QUOTE_FOLD
1297 : - Extended *quote-fold*ing
1298 #endif
1299 #ifndef HAVE_COLOUR
1300 : - Coloured message display (simple)
1301 #endif
1303 :Remarks:
1304 #ifndef HAVE_SNPRINTF
1305 : . The function snprintf() could not be found. mailx will be compiled to use
1306 : sprintf() instead. This might overflow buffers if input values are larger
1307 : than expected. Use the resulting binary with care or update your system
1308 : environment and start the configuration process again.
1309 #endif
1310 #ifndef HAVE_FCHDIR
1311 : . The function fchdir() could not be found. mailx will be compiled to use
1312 : chdir() instead. This is not a problem unless the current working
1313 : directory of mailx is moved while the IMAP cache is used.
1314 #endif
1315 #ifndef HAVE_GETOPT
1316 : . Using a minimal builtin POSIX-like getopt()
1317 #endif
1318 #ifdef HAVE_DEBUG
1319 : . Debug enabled binary: not meant to be used by end-users: THANKS!
1320 #endif
1324 ${make} -f ${makefile} ${tmp2}.x
1325 < ${tmp2}.x >&5 ${sed} -e '/^[^:]/d; /^$/d; s/^://'
1327 # vim:set fenc=utf-8:s-it-mode