1dnl Copyright (C) 2000 Nelson H. F. Beebe
2dnl See the file ndiff.sin for a full copyright notice.
3dnl
4dnl Process this file with autoconf to produce a configure script.
5AC_INIT(ndiff.c)
6
7AC_CONFIG_HEADER(config.h:config.hin)
8
9DATE=10-Dec-2000
10AC_SUBST(DATE)
11VERSION=2.00
12VERSIONREGEXP=2[[.]]00
13AC_SUBST(VERSION)
14AC_SUBST(VERSIONREGEXP)
15
16dnl Checks for package options.
17dnl Normally, configure will choose the longest precision supported,
18dnl but the user can configure a particular choice with any of these
19dnl mutually-exclusive options:
20dnl	--with-gmp
21dnl	--with-double
22dnl	--with-long-double
23
24fp_package=
25
26AC_ARG_WITH(gmp,
27	[  --with-gmp              use GNU multiple-precision floating-point library],
28	[fp_package=gmp])
29
30AC_ARG_WITH(double,
31	[  --with-double           use double floating-point precision],
32	[fp_package=dbl])
33
34AC_ARG_WITH(long-double,
35	[  --with-long-double      use long double floating-point precision],
36	[fp_package=ldb])
37
38dnl Checks for compiler
39AC_PROG_CC
40
41dnl Checks for support programs
42AC_CHECK_PROGS(AUTOCONF,	autoconf)
43AC_CHECK_PROGS(AUTOHEADER,	autoheader)
44
45dnl These must have a full pathname, because we will embed the
46dnl definitions not only in the Makefile, but also in the installed
47dnl scripts, which must be impervious to the PATH settings of all
48dnl users.
49AC_PATH_PROGS(AWK,		[mawk nawk gawk bawk awk])
50AC_PATH_PROGS(SH,		[sh ksh bash])
51
52dnl We need to have the current directory first in the path, so that
53dnl any private script is found first (mkdir.sh handles the -p option
54dnl portably; some older mkdir commands do not support -p):
55AC_PATH_PROGS(MKDIR,		mkdir.sh mkdir,,$PWD:$PATH)
56
57AC_CHECK_PROGS(CAT,		cat)
58AC_CHECK_PROGS(CHECKNR,		[checknr echo])
59AC_CHECK_PROGS(CHECKSUM,	[checksum cat])
60AC_CHECK_PROGS(CHMOD,		chmod)
61AC_CHECK_PROGS(CMP,		cmp)
62AC_CHECK_PROGS(CP,		[scp rcp cp])
63AC_CHECK_PROGS(DEROFF,		deroff)
64AC_CHECK_PROGS(DIFF,		diff)
65AC_CHECK_PROGS(DISTILL,		[distill ps2pdf])
66AC_CHECK_PROGS(DITROFF,		[ditroff groff])
67AC_CHECK_PROGS(DW,		[dw echo])
68AC_CHECK_PROGS(ETAGS,		etags)
69AC_CHECK_PROGS(GREP,		grep)
70AC_CHECK_PROGS(GZIP,		[gzip compress])
71AC_CHECK_PROGS(ISPELL,		[ispell echo])
72AC_CHECK_PROGS(JAR,		[jar tar])
73AC_CHECK_PROGS(LN,		ln)
74AC_CHECK_PROGS(LS,		ls)
75AC_CHECK_PROGS(MAN2HTML,	man2html)
76AC_CHECK_PROGS(MV,		mv)
77AC_CHECK_PROGS(NROFF,		[nroff groff])
78AC_CHECK_PROGS(RM,		rm)
79AC_CHECK_PROGS(SED,		sed)
80AC_CHECK_PROGS(SORT,		sort)
81AC_CHECK_PROGS(SPELL,		spell)
82AC_CHECK_PROGS(TAR,		tar)
83AC_CHECK_PROGS(TGRIND,		tgrind)
84AC_CHECK_PROGS(UNZIP,		unzip)
85AC_CHECK_PROGS(ZIP,		zip)
86AC_CHECK_PROGS(ZOO,		zoo)
87
88dnl Checks for header files.
89AC_HEADER_STDC
90
91dnl Do NOT use this test for const: it gets the wrong answer for C++,
92dnl and this code is written for ANSI/ISO Standard C anyway.
93dnl AC_C_CONST
94
95AC_CHECK_HEADERS(ctype.h limits.h stddef.h stdio.h stdlib.h string.h)
96
97dnl Checks for typedefs, structures, and compiler characteristics.
98AC_TYPE_SIZE_T
99
100if test -z "$fp_package"
101then
102	AC_CACHE_CHECK([GNU multiple-precision library (gmp)],ac_cv_have_gmp,
103		OLDCFLAGS="$CFLAGS"
104		OLDLIBS=$LIBS
105		if test "x$prefix" != xNONE
106		then
107			CFLAGS="$CFLAGS -I$prefix/include"
108			LIBS="$LIBS -L$prefix/lib -lgmp"
109		else
110			CFLAGS="$CFLAGS -I$ac_default_prefix/include"
111			LIBS="$LIBS -L$ac_default_prefix/lib -lgmp"
112		fi
113		AC_TRY_LINK(
114			[#include <gmp.h>],
115			[mpf_t x; mpf_init(x);],
116			[ac_cv_have_gmp=yes],
117			[ac_cv_have_gmp=no])
118		if test "$ac_cv_have_gmp" = "yes"
119		then
120			ac_cv_c_long_double=no
121			AC_DEFINE(HAVE_GMP)
122			fp_package=gmp
123		else
124			CFLAGS=$OLDCFLAGS
125			LIBS=$OLDLIBS
126		fi
127	)
128
129	dnl The built-in test for long double fails for C++ compilers because
130	dnl of a missing exit() prototype, sigh..., so we create our own,
131	dnl using very similar code.  However, we change the < to <= in the
132	dnl return statement, so as to catch the several implementations that
133	dnl treat long double like double, so as not to confuse the user who
134	dnl believes the code has been built for quadruple precision.
135	dnl AC_C_LONG_DOUBLE
136	if test "$ac_cv_have_gmp" = "no"
137	then
138		AC_MSG_CHECKING(for long double)
139		AC_TRY_RUN(
140		    [
141			#include "confdefs.h"
142			int main()
143			{
144			    /* The Stardent Vistra knows sizeof(long double), but does not support it.  */
145			    long double foo = 0.0;
146			    /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
147			    return (sizeof(long double) <= sizeof(double));
148			}
149		    ],
150		    [ac_cv_c_long_double=yes],[ac_cv_c_long_double=no]
151		)
152		if test $ac_cv_c_long_double = yes
153		then
154		    fp_package=ldb
155		    AC_DEFINE(HAVE_LONG_DOUBLE)
156		fi
157		AC_MSG_RESULT($ac_cv_c_long_double)
158	fi
159elif test $fp_package = gmp
160then
161	AC_DEFINE(HAVE_GMP)
162elif test $fp_package = ldb
163then
164	AC_DEFINE(HAVE_LONG_DOUBLE)
165fi
166
167if test -z "$fp_package"
168then
169	fp_package=dbl
170elif test $fp_package = gmp
171then
172	LIBS="$LIBS -lgmp"
173fi
174
175CHECKOKAY=okay-$fp_package
176AC_SUBST(CHECKOKAY)
177
178dnl Remove -g from CFLAGS gratuitously inserted by configure.
179CFLAGS="`echo $CFLAGS | sed -e 's/-g //g' -e 's/ -g$//g' -e 's/^-g$//'`"
180
181dnl Remove -O2 from CFLAGS gratuitously inserted by configure.
182CFLAGS="`echo $CFLAGS | sed -e 's/-O2 //g' -e 's/ -O2$//g' -e 's/^-O2$//'`"
183
184AC_OUTPUT(Makefile ndiff.sh:ndiff.sin)
185
186dnl Make the shell scripts executable, and all generated files, non-writable
187chmod 555 ndiff.sh
188chmod 444 Makefile
189