Blob Blame History Raw
#!/bin/sh

#
# Sccsid @(#)makeconfig	1.44 (gritter) 5/26/09
#

tmp=___build$$
tmp2=___tmp$$
out=config.h
log=config.log
lib=LIBS

make="${MAKE-make}"

exec 5>&2 >$log 2>&1

rm -f $out $lib
echo "\
/*
 * Auto-generated by $0.
 * Changes are lost when $0 is run again.
 */
" >$out
echo "
# Auto-generated by $0.
# Changes are lost when $0 is run again.
#
# need one non-empty line
 
# to make grep happy
">$lib

trap "rm -f $out $lib; exit" 1 2 15
trap "rm -f $tmp.? $tmp $tmp2.? $tmp2" 0

msg() {
	fmt=$1
	shift
	printf "*** $fmt\\n" "$@"
	printf "$fmt" "$@" >&5
}

compile_check() {
	variable=$1
	topic=$2
	define=$3

	echo '************************************************************'
	msg "checking $topic ... "
	echo "/* checked $topic */" >>$out
	rm -f $tmp.o
	echo '*** test program is'
	tee $tmp.c
	#echo '*** the preprocessor generates'
	#$make $tmp.x
	#cat $tmp.x
	echo '*** results are'
	if $make $tmp.o && test -f $tmp.o
	then
		msg "okay\\n"
		echo "$define" >>$out
		eval have_$variable=yes
		return 0
	else
		echo "/* $define */" >>$out
		msg "no\\n"
		eval unset have_$variable
		return 1
	fi
}

link_check() {
	variable=$1
	topic=$2
	define=$3
	libs=$4

	echo '************************************************************'
	msg "checking $topic ... "
	echo "/* checked $topic */" >>$out
	cp $lib $tmp2
	rm -f $tmp $tmp.o
	echo '*** test program is'
	tee $tmp.c
	#echo '*** the preprocessor generates'
	#$make $tmp.x
	#cat $tmp.x
	echo '*** results are'
	if $make $tmp LIBS="$LIBS $libs" && test -f $tmp
	then
		msg "okay\\n"
		echo "$define" >>$out
		echo "$libs" >$lib
		cat $tmp2 >>$lib
		eval have_$variable=yes
		return 0
	else
		msg "no\\n"
		echo "/* $define */" >>$out
		eval unset have_$variable
		return 1
	fi
}

link_check hello 'if a hello world program can be built' <<\! || { \
    echo 'This problem is most certainly not specific to this software.' >&5; \
    echo "Read the file '$log' and check your compiler installation." >&5; \
    rm $out; exit 1; \
}
#include <stdio.h>

int main(int argc, char *argv[])
{
	puts("hello world");
	return 0;
}
!

compile_check alloca_h 'for <alloca.h>' '#define HAVE_ALLOCA_H' <<\!
#include <alloca.h>
!

link_check alloca 'for alloca()' '#define HAVE_ALLOCA' <<\!
#include "rcv.h"
int main(void)
{
	alloca(1);
	return 0;
}
!

compile_check ssize_t 'for ssize_t' '#define HAVE_SSIZE_T' <<\!
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
	ssize_t	i = 3;
	write(1, "foo", i);
	return 0;
}
!

link_check snprintf 'for snprintf()' '#define HAVE_SNPRINTF' <<\!
#include <stdio.h>
int main(void)
{
	char	b[20];
	snprintf(b, sizeof b, "%s", "string");
	return 0;
}
!

link_check fchdir 'for fchdir()' '#define HAVE_FCHDIR' <<\!
#include <unistd.h>
int main(void)
{
	fchdir(0);
	return 0;
}
!

link_check mmap 'for mmap()' '#define HAVE_MMAP' <<\!
#include <sys/types.h>
#include <sys/mman.h>
int main(void)
{
	mmap(0, 0, 0, 0, 0, 0);
	return 0;
}
!

link_check mremap 'for mremap()' '#define HAVE_MREMAP' <<\!
#include <sys/types.h>
#include <sys/mman.h>
int main(void)
{
	mremap(0, 0, 0, MREMAP_MAYMOVE);
	return 0;
}
!

cat >$tmp2.c <<\!
#include <iconv.h>
int main(void)
{
	iconv_t	id;

	id = iconv_open("foo", "bar");
	return 0;
}
!
<$tmp2.c link_check iconv 'for iconv functionality' '#define HAVE_ICONV' ||
	<$tmp2.c link_check iconv 'for iconv functionality in libiconv' \
		'#define HAVE_ICONV' '-liconv'

link_check wctype 'for wctype functionality' '#define HAVE_WCTYPE_H' <<\!
#include <wctype.h>
int main(void)
{
	iswprint(L'c');
	towupper(L'c');
	return 0;
}
!

link_check wcwidth 'for wcwidth() ' '#define HAVE_WCWIDTH' <<\!
#include <wchar.h>
int main(void)
{
	wcwidth(L'c');
	return 0;
}
!

link_check mbtowc 'for mbtowc()' '#define HAVE_MBTOWC' <<\!
#include <stdlib.h>
int main(void)
{
	wchar_t	wc;
	mbtowc(&wc, "x", 1);
	return 0;
}
!

link_check setlocale 'for setlocale()' '#define HAVE_SETLOCALE' <<\!
#include <locale.h>
int main(void)
{
	setlocale(LC_ALL, "");
	return 0;
}
!

link_check nl_langinfo 'for nl_langinfo()' '#define HAVE_NL_LANGINFO' <<\!
#include <langinfo.h>
int main(void)
{
	nl_langinfo(DAY_1);
	return 0;
}
!

link_check mkstemp 'for mkstemp()' '#define HAVE_MKSTEMP' <<\!
#include <stdlib.h>
int main(void)
{
	mkstemp("x");
	return 0;
}
!

link_check fpathconf 'for fpathconf()' '#define HAVE_FPATHCONF' <<\!
#include <unistd.h>
int main(void)
{
	fpathconf(0, _PC_PATH_MAX);
	return 0;
}
!

link_check wordexp 'for wordexp()' '#define HAVE_WORDEXP' <<\!
#include <wordexp.h>
int main(void)
{
	wordexp((char *)0, (wordexp_t *)0, 0);
	return 0;
}
!

compile_check arpa_inet_h 'for <arpa/inet.h>' '#define HAVE_ARPA_INET_H' <<\!
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
!

cat >$tmp2.c <<\!
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#ifdef	HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif	/* HAVE_ARPA_INET_H */

int main(void)
{
	struct sockaddr	s;
	socket(AF_INET, SOCK_STREAM, 0);
	connect(0, &s, 0);
	gethostbyname("foo");
	return 0;
}
!

<$tmp2.c link_check sockets 'for socket functionality in libc' \
		'#define HAVE_SOCKETS' ||
	<$tmp2.c link_check sockets 'for socket functionality in libnsl' \
			'#define HAVE_SOCKETS' '-lnsl' ||
		<$tmp2.c link_check sockets \
			'for socket functionality in libsocket and libnsl' \
			'#define HAVE_SOCKETS' '-lsocket -lnsl'

#link_check ipv6 'for IPv6 functionality' '#define HAVE_IPv6_FUNCS' <<\!
##include "config.h"
##include <sys/types.h>
##include <sys/socket.h>
##include <netdb.h>
##include <netinet/in.h>
##ifdef	HAVE_ARPA_INET_H
##include <arpa/inet.h>
##endif	/* HAVE_ARPA_INET_H */
#
#int main(void)
#{
#	struct addrinfo	a, *ap;
#	getaddrinfo("foo", "0", &a, &ap);
#	return 0;
#}
#!

link_check nss 'for Network Security Services (NSS)' '#define USE_SSL
#define USE_NSS' '-lsmime3 -lnss3 -lssl3 -lnspr4 -lplc4' <<\! || \
		link_check openssl 'for sufficiently recent OpenSSL' \
			'#define USE_SSL
#define USE_OPENSSL' '-lssl -lcrypto' <<\%
#include <nss.h>
#include <ssl.h>
#include <prinit.h>
#include <prmem.h>
#include <pk11func.h>
#include <prtypes.h>
#include <prerror.h>
#include <secerr.h>
#include <smime.h>
#include <ciferfam.h>
#include <private/pprio.h>

int main(void)
{
	PR_ImportTCPSocket(0);
	NSS_CMSSignerInfo_AddSMIMECaps(0);
	return 0;
}
!
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/x509v3.h>
#include <openssl/x509.h>
#include <openssl/rand.h>

int main(void)
{
	SSLv23_client_method();
	PEM_read_PrivateKey(0, 0, 0, 0);
	return 0;
}
%
if test x$have_nss = xyes
then
	compile_check genname_h 'for genname.h' '#define HAVE_GENNAME_H' <<\!
#include <genname.h>
!
	compile_check xconst_h 'for xconst.h' '#define HAVE_XCONST_H' <<\!
#include <xconst.h>
!
	compile_check CERTAltNameEncodedContext \
		'for CERTAltNameEncodedContext type' \
		'#define HAVE_CERTAltNameEncodedContext' <<\!
#include "config.h"
#include <nss.h>
#include <ssl.h>
#include <prinit.h>
#include <prmem.h>
#include <pk11func.h>
#include <prtypes.h>
#include <prerror.h>
#include <secerr.h>
#include <smime.h>
#include <ciferfam.h>
#ifdef HAVE_XCONST_H
#include <xconst.h>
#endif
#ifdef HAVE_GENNAME_H
#include <genname.h>
#endif
#include <private/pprio.h>

CERTAltNameEncodedContext	foo;
!
fi

if test x$have_openssl = xyes
then
	compile_check stack_of 'for STACK_OF()' '#define HAVE_STACK_OF' <<\!
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/x509v3.h>
#include <openssl/x509.h>
#include <openssl/rand.h>

int main(void)
{
	STACK_OF(GENERAL_NAME)	*gens = NULL;
	printf("%p", gens);	/* to make it used */
	SSLv23_client_method();
	PEM_read_PrivateKey(0, 0, 0, 0);
	return 0;
}
!
fi

cat >$tmp2.c <<\!
#include <gssapi/gssapi.h>

int main(void)
{
	gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
	gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
	return 0;
}
!

<$tmp2.c link_check gssapi 'for GSSAPI in libgss' \
		'#define USE_GSSAPI' '-lgss' ||
	<$tmp2.c link_check gssapi 'for GSSAPI in libgssapi_krb5' \
			'#define USE_GSSAPI' '-lgssapi_krb5' ||
		link_check gssapi 'for GSSAPI in libgssapi_krb5, old-style' \
				'#define USE_GSSAPI
#define GSSAPI_OLD_STYLE' '-lgssapi_krb5' <<\! || \
			link_check gssapi 'for GSSAPI in libgssapi' \
				'#define USE_GSSAPI
#define	GSSAPI_REG_INCLUDE' '-lgssapi' <<\%
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_generic.h>

int main(void)
{
	gss_import_name(0, 0, gss_nt_service_name, 0);
	gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
	return 0;
}
!
#include <gssapi.h>

int main(void)
{
	gss_import_name(0, 0, GSS_C_NT_HOSTBASED_SERVICE, 0);
	gss_init_sec_context(0,0,0,0,0,0,0,0,0,0,0,0,0);
	return 0;
}
%

cat >$tmp2.c <<\!
#include "config.h"
#ifdef HAVE_NL_LANGINFO
#include <langinfo.h>
#endif
:
:The following optional features are enabled:
#ifdef	HAVE_SETLOCALE
: + Locale support: Printable characters depend on the environment
#if defined (HAVE_MBTOWC) && defined (HAVE_WCTYPE_H)
: + Multibyte character support
#endif
#endif	/* HAVE_SETLOCALE */
#ifdef	HAVE_ICONV
: + Character set conversion using iconv()
#endif
#if defined (HAVE_SETLOCALE) && defined (HAVE_NL_LANGINFO) && defined (CODESET)
: + Automatic detection of terminal character set
#endif
#ifdef	HAVE_SOCKETS
: + Networking support (IMAP, POP3, and SMTP)
#endif
#ifdef	USE_GSSAPI
: + IMAP GSSAPI authentication
#endif
#if defined (USE_NSS)
: + S/MIME and SSL/TLS using Network Security Services (NSS)
#endif
#if defined (USE_OPENSSL)
: + S/MIME and SSL/TLS using OpenSSL
#endif
:
:The following optional features are disabled:
#ifndef	HAVE_SETLOCALE
: - Locale support: Only ASCII characters are recognized
#endif
#if !defined (HAVE_SETLOCALE) || !defined (HAVE_MBTOWC) || \
	!defined (HAVE_WCTYPE_H)
: - Multibyte character support
#endif
#ifndef	HAVE_ICONV
: - Character set conversion using iconv()
#endif
#if !defined (HAVE_SETLOCALE) || !defined (HAVE_NL_LANGINFO) || \
	!defined (CODESET)
: - Automatic detection of terminal character set
#endif
#ifndef	HAVE_SOCKETS
: - Networking support (IMAP, POP3, and SMTP)
#endif
#ifndef	USE_GSSAPI
: - IMAP GSSAPI authentication
#endif
#ifndef	USE_SSL
: - SSL/TLS (network transport authentication and encryption)
#endif
:
:Remarks:
#ifndef	HAVE_SNPRINTF
: * The function snprintf() could not be found. mailx will be compiled to use
: sprintf() instead. This might overflow buffers if input values are larger
: than expected. Use the resulting binary with care or update your system
: environment and start the configuration process again.
#endif
#ifndef	HAVE_FCHDIR
: * The function fchdir() could not be found. mailx will be compiled to use
: chdir() instead. This is not a problem unless the current working
: directory of mailx is moved while the IMAP cache is used.
#endif
:
!

(hash cc) && cc -E $tmp2.c | sed '/^[^:]/d; /^$/d; s/^://' >&5

exit 0