Tweak (Use system getopt(3) if available.., 2012-10-05)..
[s-mailx.git] / makeconfig
blob901c1da05bbc290fae787e1dd47c670572e3dc70
1 #!/bin/sh
3 [ -z "${WANT_ASSERTS}" ] && WANT_ASSERTS=0
4 if [ -z "${CONFIG}" ]; then
5 [ -f user.conf ] && . user.conf
6 else
7 case ${CONFIG} in
8 MINIMAL)
9 WANT_JUNK=0 WANT_SOCKET=0
11 NETLESS)
12 WANT_SOCKET=0
14 NETSEND)
15 WANT_JUNK=0 WANT_IMAP=0 WANT_POP3=0
18 echo >&2 "Unknown CONFIG= setting: ${CONFIG}"
19 echo >&2 'Possible values: MINIMAL, NETLESS, NETSEND'
20 exit 1
21 esac
24 wantfeat() {
25 eval i=\$WANT_${1}
26 [ "${i}" != "0" ]
28 nwantfeat() {
29 eval i=\$WANT_${1}
30 [ "${i}" = "0" ]
33 if nwantfeat SOCKET; then
34 WANT_IPV6=0 WANT_SSL=0
35 WANT_IMAP=0 WANT_GSSAPI=0 WANT_POP3=0 WANT_SMTP=0
37 if nwantfeat IMAP && nwantfeat POP3 && nwantfeat SMTP; then
38 WANT_SOCKET=0 WANT_IPV6=0 WANT_SSL=0
39 else
40 WANT_SOCKET=1
42 if nwantfeat IMAP; then
43 WANT_GSSAPI=0
45 # If we don't need MD5 except for producing boundary and message-id strings,
46 # leave it off, plain old srand(3) should be enough for that purpose.
47 if nwantfeat SOCKET && nwantfeat JUNK; then
48 WANT_MD5=0
49 elif wantfeat JUNK; then
50 WANT_MD5=1
53 tmp=___build$$
54 tmp2=___tmp1$$
55 tmp3=___tmp2$$
56 out=config.h
57 log=config.log
58 lib=LIBS
59 inc=INCS
60 makefile=config.mk
62 make="${MAKE-make}"
64 exec 5>&2 >$log 2>&1
66 rm -f $out $lib $inc
67 echo "\
69 * Auto-generated by $0.
70 * Changes are lost when $0 is run again.
72 " > $out
73 : > $lib
74 : > $inc
75 cat > $makefile << \!
76 .SUFFIXES: .o .c .x .y
77 .c.o:
78 $(CC) $(CFLAGS) $(INCLUDES) -c $<
80 .c.x:
81 $(CC) $(CFLAGS) $(INCLUDES) -E $< >$@
83 .c:
84 $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(LIBS) -o $@
86 .y: ;
90 trap "rm -f $out $lib $inc $makefile; exit" 1 2 15
91 trap "rm -rf $tmp.*; rm -f $tmp $tmp2.? $tmp2 $tmp3.? $tmp3 $makefile" 0
93 msg() {
94 fmt=$1
95 shift
96 printf "*** $fmt\\n" "$@"
97 printf "$fmt" "$@" >&5
100 compile_check() {
101 variable=$1
102 topic=$2
103 define=$3
105 echo '************************************************************'
106 msg "checking $topic ... "
107 echo "/* checked $topic */" >>$out
108 rm -f $tmp.o
109 echo '*** test program is'
110 tee $tmp.c
111 #echo '*** the preprocessor generates'
112 #$make -f $makefile $tmp.x
113 #cat $tmp.x
114 echo '*** results are'
115 if $make -f $makefile $tmp.o && test -f $tmp.o
116 then
117 msg "okay\\n"
118 echo "$define" >>$out
119 eval have_$variable=yes
120 return 0
121 else
122 echo "/* $define */" >>$out
123 msg "no\\n"
124 eval unset have_$variable
125 return 1
129 link_check() {
130 variable=$1
131 topic=$2
132 define=$3
133 libs=$4
134 incs=$5
136 echo '************************************************************'
137 msg "checking $topic ... "
138 echo "/* checked $topic */" >>$out
139 rm -f $tmp $tmp.o
140 echo '*** test program is'
141 tee $tmp.c
142 #echo '*** the preprocessor generates'
143 #$make -f $makefile $tmp.x
144 #cat $tmp.x
145 echo '*** results are'
146 if $make -f $makefile \
147 $tmp INCLUDES="$INCLUDES $incs" LIBS="$LIBS $libs" &&
148 test -f $tmp
149 then
150 msg "okay\\n"
151 echo "$define" >> $out
152 echo "$libs" >> $lib
153 echo "$incs" >> $inc
154 eval have_$variable=yes
155 return 0
156 else
157 msg "no\\n"
158 echo "/* $define */" >>$out
159 eval unset have_$variable
160 return 1
164 link_check hello 'if a hello world program can be built' <<\! || { \
165 echo 'This problem is most certainly not specific to this software.' >&5; \
166 echo "Read the file '$log' and check your compiler installation." >&5; \
167 rm $out; exit 1; \
169 #include <stdio.h>
171 int main(int argc, char *argv[])
173 (void)argc;
174 (void)argv;
175 puts("hello world");
176 return 0;
180 compile_check alloca_h 'for <alloca.h>' '#define HAVE_ALLOCA_H' <<\!
181 #include <alloca.h>
184 link_check alloca 'for alloca()' '#define HAVE_ALLOCA' <<\!
185 #include "rcv.h"
186 int main(void)
188 alloca(1);
189 return 0;
193 compile_check ssize_t 'for ssize_t' '#define HAVE_SSIZE_T' <<\!
194 #include <sys/types.h>
195 #include <unistd.h>
196 int main(void)
198 ssize_t i = 3;
199 write(1, "foo", i);
200 return 0;
204 link_check snprintf 'for snprintf()' '#define HAVE_SNPRINTF' <<\!
205 #include <stdio.h>
206 int main(void)
208 char b[20];
209 snprintf(b, sizeof b, "%s", "string");
210 return 0;
214 link_check putc_unlocked 'for putc_unlocked()' '#define HAVE_PUTC_UNLOCKED' <<\!
215 #include <stdio.h>
216 int main(void)
218 putc_unlocked('@', stdout);
219 return 0;
223 link_check fchdir 'for fchdir()' '#define HAVE_FCHDIR' <<\!
224 #include <unistd.h>
225 int main(void)
227 fchdir(0);
228 return 0;
232 link_check mmap 'for mmap()' '#define HAVE_MMAP' <<\!
233 #include <sys/types.h>
234 #include <sys/mman.h>
235 int main(void)
237 mmap(0, 0, 0, 0, 0, 0);
238 return 0;
242 link_check mremap 'for mremap()' '#define HAVE_MREMAP' <<\!
243 #include <sys/types.h>
244 #include <sys/mman.h>
245 int main(void)
247 mremap(0, 0, 0, MREMAP_MAYMOVE);
248 return 0;
252 cat >$tmp2.c <<\!
253 #include <iconv.h>
254 int main(void)
256 iconv_t id;
258 id = iconv_open("foo", "bar");
259 return 0;
262 <$tmp2.c link_check iconv 'for iconv functionality' '#define HAVE_ICONV' ||
263 <$tmp2.c link_check iconv 'for iconv functionality in libiconv' \
264 '#define HAVE_ICONV' '-liconv'
266 link_check wctype 'for wctype functionality' '#define HAVE_WCTYPE_H' <<\!
267 #include <wctype.h>
268 int main(void)
270 iswprint(L'c');
271 towupper(L'c');
272 return 0;
276 link_check wcwidth 'for wcwidth() ' '#define HAVE_WCWIDTH' <<\!
277 #include <wchar.h>
278 int main(void)
280 wcwidth(L'c');
281 return 0;
285 link_check mbtowc 'for mbtowc()' '#define HAVE_MBTOWC' <<\!
286 #include <stdlib.h>
287 int main(void)
289 wchar_t wc;
290 mbtowc(&wc, "x", 1);
291 return 0;
295 link_check setlocale 'for setlocale()' '#define HAVE_SETLOCALE' <<\!
296 #include <locale.h>
297 int main(void)
299 setlocale(LC_ALL, "");
300 return 0;
304 link_check nl_langinfo 'for nl_langinfo()' '#define HAVE_NL_LANGINFO' <<\!
305 #include <langinfo.h>
306 int main(void)
308 nl_langinfo(DAY_1);
309 return 0;
313 link_check mkstemp 'for mkstemp()' '#define HAVE_MKSTEMP' <<\!
314 #include <stdlib.h>
315 int main(void)
317 mkstemp("x");
318 return 0;
322 link_check fpathconf 'for fpathconf()' '#define HAVE_FPATHCONF' <<\!
323 #include <unistd.h>
324 int main(void)
326 fpathconf(0, _PC_PATH_MAX);
327 return 0;
331 link_check wordexp 'for wordexp()' '#define HAVE_WORDEXP' <<\!
332 #include <wordexp.h>
333 int main(void)
335 wordexp((char *)0, (wordexp_t *)0, 0);
336 return 0;
340 link_check getopt 'for getopt()' '#define HAVE_GETOPT' << \!
341 #include <unistd.h>
342 int main(int argc, char **argv)
344 #if defined __GLIBC__ || defined __linux__
345 Argument and option reordering is not a desired feature.
346 #else
347 getopt(argc, argv, "oPt");
348 #endif
349 return (((long)optarg + optind) & 0x7F);
353 ## user.conf added later, indentation not adjusted ##
355 if wantfeat SOCKET; then
357 compile_check arpa_inet_h 'for <arpa/inet.h>' '#define HAVE_ARPA_INET_H' <<\!
358 #include "config.h"
359 #include <sys/types.h>
360 #include <sys/socket.h>
361 #include <netdb.h>
362 #include <netinet/in.h>
363 #include <arpa/inet.h>
366 cat >$tmp2.c <<\!
367 #include "config.h"
368 #include <sys/types.h>
369 #include <sys/socket.h>
370 #include <netdb.h>
371 #include <netinet/in.h>
372 #ifdef HAVE_ARPA_INET_H
373 #include <arpa/inet.h>
374 #endif /* HAVE_ARPA_INET_H */
376 int main(void)
378 struct sockaddr s;
379 socket(AF_INET, SOCK_STREAM, 0);
380 connect(0, &s, 0);
381 gethostbyname("foo");
382 return 0;
386 WANT_SOCKET=1
387 <$tmp2.c link_check sockets 'for socket functionality in libc' \
388 '#define HAVE_SOCKETS' ||
389 <$tmp2.c link_check sockets 'for socket functionality in libnsl' \
390 '#define HAVE_SOCKETS' '-lnsl' ||
391 <$tmp2.c link_check sockets \
392 'for socket functionality in libsocket and libnsl' \
393 '#define HAVE_SOCKETS' '-lsocket -lnsl' ||
394 WANT_SOCKET=0
396 # XXX Shouldn't it be a hard error if there is no socket support, then?
397 [ ${WANT_SOCKET} -eq 1 ] ||
398 WANT_IPV6=0 WANT_SSL=0 \
399 WANT_IMAP=0 WANT_GSSAPI=0 WANT_POP3=0 WANT_SMTP=0
401 fi # wantfeat SOCKET
402 if wantfeat IPV6; then
404 link_check ipv6 'for IPv6 functionality' '#define USE_IPV6' << \!
405 #include "config.h"
406 #include <sys/types.h>
407 #include <sys/socket.h>
408 #include <netdb.h>
409 #include <netinet/in.h>
410 #ifdef HAVE_ARPA_INET_H
411 #include <arpa/inet.h>
412 #endif
414 int main(void)
416 struct addrinfo a, *ap;
417 getaddrinfo("foo", "0", &a, &ap);
418 return 0;
422 fi # wantfeat IPV6
424 if wantfeat IMAP; then
425 echo "#define USE_IMAP" >> $out
426 else
427 echo "/* #define USE_IMAP */" >> $out
430 if wantfeat POP3; then
431 echo "#define USE_POP3" >>$out
432 else
433 echo "/* #define USE_POP3 */" >> $out
436 if wantfeat SMTP; then
437 echo "#define USE_SMTP" >>$out
438 else
439 echo "/* #define USE_SMTP */" >> $out
442 if wantfeat SSL; then
444 link_check nss 'for Network Security Services (NSS)' '#define USE_SSL
445 #define USE_NSS' '-lsmime3 -lnss3 -lssl3 -lnspr4 -lplc4' <<\! || \
446 link_check openssl 'for sufficiently recent OpenSSL' \
447 '#define USE_SSL
448 #define USE_OPENSSL' '-lssl -lcrypto' <<\%
449 #include <nss.h>
450 #include <ssl.h>
451 #include <prinit.h>
452 #include <prmem.h>
453 #include <pk11func.h>
454 #include <prtypes.h>
455 #include <prerror.h>
456 #include <secerr.h>
457 #include <smime.h>
458 #include <ciferfam.h>
459 #include <private/pprio.h>
461 int main(void)
463 PR_ImportTCPSocket(0);
464 NSS_CMSSignerInfo_AddSMIMECaps(0);
465 return 0;
468 #include <openssl/ssl.h>
469 #include <openssl/err.h>
470 #include <openssl/x509v3.h>
471 #include <openssl/x509.h>
472 #include <openssl/rand.h>
474 int main(void)
476 SSLv23_client_method();
477 PEM_read_PrivateKey(0, 0, 0, 0);
478 return 0;
481 if test x$have_nss = xyes
482 then
483 compile_check genname_h 'for genname.h' '#define HAVE_GENNAME_H' <<\!
484 #include <genname.h>
486 compile_check xconst_h 'for xconst.h' '#define HAVE_XCONST_H' <<\!
487 #include <xconst.h>
489 compile_check CERTAltNameEncodedContext \
490 'for CERTAltNameEncodedContext type' \
491 '#define HAVE_CERTAltNameEncodedContext' <<\!
492 #include "config.h"
493 #include <nss.h>
494 #include <ssl.h>
495 #include <prinit.h>
496 #include <prmem.h>
497 #include <pk11func.h>
498 #include <prtypes.h>
499 #include <prerror.h>
500 #include <secerr.h>
501 #include <smime.h>
502 #include <ciferfam.h>
503 #ifdef HAVE_XCONST_H
504 #include <xconst.h>
505 #endif
506 #ifdef HAVE_GENNAME_H
507 #include <genname.h>
508 #endif
509 #include <private/pprio.h>
511 CERTAltNameEncodedContext foo;
515 if test x$have_openssl = xyes
516 then
517 compile_check stack_of 'for STACK_OF()' '#define HAVE_STACK_OF' <<\!
518 #include <openssl/ssl.h>
519 #include <openssl/err.h>
520 #include <openssl/x509v3.h>
521 #include <openssl/x509.h>
522 #include <openssl/rand.h>
524 int main(void)
526 STACK_OF(GENERAL_NAME) *gens = NULL;
527 printf("%p", gens); /* to make it used */
528 SSLv23_client_method();
529 PEM_read_PrivateKey(0, 0, 0, 0);
530 return 0;
535 else
536 echo '/* Socket/SSL support not desired */' >> $out
537 fi # wantfeat SSL
538 if wantfeat GSSAPI; then
540 cat >$tmp2.c <<\!
541 #include <gssapi/gssapi.h>
543 int main(void)
545 gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
546 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
547 return 0;
551 sed -e '1s/gssapi\///' < $tmp2.c > $tmp3.c
553 <$tmp2.c link_check gssapi 'for GSSAPI in libgss' \
554 '#define USE_GSSAPI' '-lgss' ||
555 <$tmp2.c link_check gssapi 'for GSSAPI in libgssapi_krb5' \
556 '#define USE_GSSAPI' '-lgssapi_krb5' ||
557 link_check gssapi 'for GSSAPI in libgssapi_krb5, old-style' \
558 '#define USE_GSSAPI
559 #define GSSAPI_OLD_STYLE' '-lgssapi_krb5' <<\! || \
560 <$tmp3.c link_check gssapi 'for GSSAPI in libgssapi' \
561 '#define USE_GSSAPI
562 #define GSSAPI_REG_INCLUDE' '-lgssapi' || \
563 <$tmp3.c link_check gssapi \
564 'for GSSAPI in libgssapi, OpenBSD-style' \
565 '#define USE_GSSAPI
566 #define GSSAPI_REG_INCLUDE' \
567 '-lgssapi -lkrb5 -lcrypto' '-I/usr/include/kerberosV'
569 #include <gssapi/gssapi.h>
570 #include <gssapi/gssapi_generic.h>
572 int main(void)
574 gss_import_name(0, 0, gss_nt_service_name, 0);
575 gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
576 return 0;
580 else
581 echo '/* IMAP/GSSAPI support not desired */' >> $out
582 fi # wantfeat GSSAPI
584 if wantfeat JUNK; then
585 echo "#define USE_JUNK" >> $out
586 else
587 echo "/* #define USE_JUNK */" >> $out
590 if wantfeat MD5; then
591 echo "#define USE_MD5" >> $out
592 else
593 echo "/* #define USE_MD5 */" >> $out
596 if wantfeat ASSERTS; then
597 echo "#define HAVE_ASSERTS" >> $out
598 else
599 echo "/* #define HAVE_ASSERTS */" >> $out
602 # Since we cat(1) the content of those to cc/"ld", convert them to single line
603 squeeze_em() {
604 < "${1}" > "${2}" awk \
605 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}'
607 rm -f "$tmp"
608 squeeze_em "$inc" "$tmp"
609 mv "$tmp" "$inc"
610 squeeze_em "$lib" "$tmp"
611 mv "$tmp" "$lib"
613 # Finished!
614 cat > $tmp2.c << \!
615 #include "config.h"
616 #ifdef HAVE_NL_LANGINFO
617 #include <langinfo.h>
618 #endif
620 :The following optional features are enabled:
621 #ifdef HAVE_SETLOCALE
622 : + Locale support: Printable characters depend on the environment
623 #if defined (HAVE_MBTOWC) && defined (HAVE_WCTYPE_H)
624 : + Multibyte character support
625 #endif
626 #endif /* HAVE_SETLOCALE */
627 #ifdef HAVE_ICONV
628 : + Character set conversion using iconv()
629 #endif
630 #if defined (HAVE_SETLOCALE) && defined (HAVE_NL_LANGINFO) && defined (CODESET)
631 : + Automatic detection of terminal character set
632 #endif
633 #ifdef HAVE_SOCKETS
634 : + Network support
635 #endif
636 #ifdef USE_IPV6
637 : + Support for Internet Protocol v6 (IPv6)
638 #endif
639 #ifdef USE_NSS
640 : + S/MIME and SSL/TLS using Network Security Services (NSS)
641 #endif
642 #ifdef USE_OPENSSL
643 : + S/MIME and SSL/TLS using OpenSSL
644 #endif
645 #ifdef USE_IMAP
646 : + IMAP protocol
647 #endif
648 #ifdef USE_GSSAPI
649 : + IMAP GSSAPI authentication
650 #endif
651 #ifdef USE_POP3
652 : + POP3 protocol
653 #endif
654 #ifdef USE_SMTP
655 : + SMTP protocol
656 #endif
657 #ifdef USE_JUNK
658 : + Junk-mail management (Bayesian filtering)
659 #endif
660 #ifdef USE_MD5
661 : + The MD5 message digest
662 #endif
664 :The following optional features are disabled:
665 #ifndef HAVE_SETLOCALE
666 : - Locale support: Only ASCII characters are recognized
667 #endif
668 #if !defined (HAVE_SETLOCALE) || !defined (HAVE_MBTOWC) || \
669 !defined (HAVE_WCTYPE_H)
670 : - Multibyte character support
671 #endif
672 #ifndef HAVE_ICONV
673 : - Character set conversion using iconv()
674 #endif
675 #if !defined (HAVE_SETLOCALE) || !defined (HAVE_NL_LANGINFO) || \
676 !defined (CODESET)
677 : - Automatic detection of terminal character set
678 #endif
679 #ifndef HAVE_SOCKETS
680 : - Network support
681 #endif
682 #ifndef USE_IPV6
683 : - Support for Internet Protocol v6 (IPv6)
684 #endif
685 #if ! defined USE_SSL && ! defined USE_NSS
686 : - SSL/TLS (network transport authentication and encryption)
687 #endif
688 #ifndef USE_IMAP
689 : - IMAP protocol
690 #endif
691 #ifndef USE_GSSAPI
692 : - IMAP GSSAPI authentication
693 #endif
694 #ifndef USE_POP3
695 : - POP3 protocol
696 #endif
697 #ifndef USE_SMTP
698 : - SMTP protocol
699 #endif
700 #ifndef USE_JUNK
701 : - Junk-mail management (Bayesian filtering)
702 #endif
703 #ifndef USE_MD5
704 : - The MD5 message digest
705 #endif
707 :Remarks:
708 #ifndef HAVE_SNPRINTF
709 : * The function snprintf() could not be found. mailx will be compiled to use
710 : sprintf() instead. This might overflow buffers if input values are larger
711 : than expected. Use the resulting binary with care or update your system
712 : environment and start the configuration process again.
713 #endif
714 #ifndef HAVE_FCHDIR
715 : * The function fchdir() could not be found. mailx will be compiled to use
716 : chdir() instead. This is not a problem unless the current working
717 : directory of mailx is moved while the IMAP cache is used.
718 #endif
719 #ifndef HAVE_GETOPT
720 : * A (usable) getopt() functionality could not be found.
721 : A builtin version is used instead.
722 #endif
723 #ifdef HAVE_ASSERTS
724 : * WANT_ASSERTS is enabled, the program binary will contain code assertions.
725 : Such a binary is not meant to be used by end-users, but only for
726 : development purposes. Thanks!
727 #endif
731 $make -f $makefile $tmp2.x
732 < $tmp2.x >&5 sed '/^[^:]/d; /^$/d; s/^://'
734 exit 0