1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(smain.c)
3AM_CONFIG_HEADER(config.h)
4
5dnl QScheme version has to be modified here
6AM_INIT_AUTOMAKE(qscheme,0.5.1)
7
8dnl Checks for programs.
9AC_PROG_CC
10AC_PROG_LN_S
11AC_PROG_MAKE_SET
12AC_PROG_INSTALL
13AC_PROG_RANLIB
14
15dnl Check for perl5, warn if not here
16AC_PATH_PROG(PERL,perl,no)
17if test "$PERL" = "no" ; then
18	AC_MSG_WARN(Qscheme needs perl5 to rebuild sgtk interface from scratch)
19fi
20
21dnl Check stack direction
22AC_MSG_CHECKING([for stack growing direction])
23stackdir=down
24AC_TRY_RUN([void *start;
25	void check_stack() { char mark; exit(start < (void*)&mark); }
26	int main() { char mark; start = (void*)&mark; check_stack(); }
27	],
28	AC_DEFINE(STACK_GROWS_DOWN, 1, [Stack goes from high to low addresses])
29	AC_MSG_RESULT(down),
30
31	AC_DEFINE(STACK_GROWS_UP,	1, [Stack goes from low to high addresses])
32	AC_MSG_RESULT(up),
33
34	AC_MSG_ERROR(no cross compilation support))
35
36dnl Check for computed gotoes
37AC_MSG_CHECKING(for computed gotos)
38AC_TRY_RUN([
39	int main() {	void *p = &&lab;  goto *p; lab: return(0); }
40	],AC_DEFINE(HAVE_CGOTO,1,compiler supports computed gotos)
41	  AC_MSG_RESULT(yes),
42	AC_MSG_RESULT(no),
43	AC_MSG_ERROR(no cross compilation support))
44
45dnl Check for __FUNCTION__
46AC_MSG_CHECKING(for __FUNCTION__ string)
47AC_TRY_RUN([int strlen();
48	int main() { int x=strlen(__FUNCTION__); return(x == 0); } ],
49	AC_DEFINE(HAVE_FUNC_STR,1,compiler has __FUNCTION__ string)
50	AC_MSG_RESULT(yes),
51	AC_MSG_RESULT(no),
52	AC_MSG_ERROR(no cross compilation support))
53
54dnl Checks for libraries.
55AC_CHECK_LIB(dl,dlopen,,AC_MSG_ERROR(needs libdl))
56AC_CHECK_LIB(m,atan,,AC_MSG_ERROR(needs libm))
57AC_CHECK_LIB(pthread,pthread_create)
58
59dnl AC_CHECK_LIB(avcall,__builtin_avcall,,AC_MSG_ERROR(needs libavcall))
60dnl AC_CHECK_LIB(pcre,pcre_compile,,AC_MSG_ERROR(needs libpcre))
61
62dnl Checks for header files.
63AC_HEADER_STDC
64AC_HEADER_SYS_WAIT
65AC_CHECK_HEADERS(fcntl.h limits.h unistd.h)
66
67dnl AC_CHECK_HEADER(avcall.h,,needs avcall.h)
68dnl AC_CHECK_HEADER(pcre.h,,needs pcre.h)
69
70
71dnl Checks for typedefs, structures, and compiler characteristics.
72AC_C_CONST
73AC_C_INLINE
74
75dnl Checks for library functions.
76AC_FUNC_ALLOCA
77AC_FUNC_MEMCMP
78AC_CHECK_FUNCS(socket strdup strerror strstr strtol)
79
80
81dnl specify library pathes
82dnl ================================
83dnl    --x-libraries=DIR       X library files are in DIR
84
85
86dnl ================================
87dnl Check for pcre
88dnl ================================
89
90AC_ARG_WITH(pcre_dir,
91	[  --with-pcre-dir=DIR     dir containing libpcre.a ])
92AC_ARG_WITH(pcre_inc,
93	[  --with-pcre-inc=DIR     dir containing pcre.h ])
94
95old_cflags="$CFLAGS" ; old_ldflags="$LDFLAGS" ; old_libs="$LIBS"
96
97if test "$with_pcre_dir" != "" ;then
98	PCRE_DIR="$with_pcre_dir" ; LDFLAGS="-L$with_pcre_dir $LDFLAGS"
99fi
100if test "$with_pcre_inc" != "" ; then
101	PCRE_INC="$with_pcre_inc" ;	CFLAGS="-I$with_pcre_inc $CFLAGS"
102fi
103LIBS="-lpcre $LIBS"
104AC_MSG_CHECKING(for libpcre)
105AC_TRY_LINK([
106#include <stdio.h>
107#include <pcre.h>
108],[
109	pcre *pattern;
110	char *error;
111	int errptr;
112	pattern = pcre_compile("abcd",0,&error,&errptr,NULL);
113],,AC_MSG_ERROR(cannot link with pcre))
114
115CFLAGS="$old_cflags" ; LDFLAGS="$old_ldflags" ; LIBS="$old_libs"
116
117if test "$PCRE_DIR" = "" ; then
118	PCRE_LIB="-lpcre"
119else
120	PCRE_LIB="$PCRE_DIR/libpcre.a"
121fi
122
123test "$PCRE_INC" = "" && PCRE_INC="."
124
125AC_SUBST(PCRE_LIB)
126AC_SUBST(PCRE_INC)
127AC_SUBST(PCRE_DIR)
128AC_MSG_RESULT(yes)
129
130
131dnl ================================
132dnl Test for avcall
133dnl ================================
134
135AC_ARG_WITH(avcall_dir,
136	[  --with-avcall-lib=DIR   dir containing libavcall.a ])
137AC_ARG_WITH(avcall_inc,
138	[  --with-avcall-inc=DIR   dir containing avcall.h ])
139
140old_cflags="$CFLAGS"; old_ldflags="$LDFLAGS"; old_libs="$LIBS"
141
142if test "$with_avcall_dir" != "" ;then
143	AVCALL_DIR="$with_avcall_dir" ; LDFLAGS="-L$with_avcall_dir $LDFLAGS"
144fi
145if test "$with_avcall_inc" != "" ; then
146	AVCALL_INC="$with_avcall_inc" ; CFLAGS="-I$with_avcall_inc $CFLAGS"
147fi
148LIBS="-lavcall $LIBS"
149
150AC_MSG_CHECKING(for libavcall)
151AC_TRY_LINK([
152#include <stdio.h>
153#include <avcall.h>
154],[
155	av_alist alist;
156	int c;
157	av_start_int(alist,&fgetc,&c);
158],,AC_MSG_ERROR(cannot link with avcall))
159
160CFLAGS="$old_cflags" ; LDFLAGS="$old_ldflags" ; LIBS="$old_libs"
161
162if test "$AVCALL_DIR" = "" ; then
163	AVCALL_LIB="-lavcall"
164else
165	AVCALL_LIB="$AVCALL_DIR/libavcall.a"
166fi
167
168AC_SUBST(AVCALL_LIB)
169AC_SUBST(AVCALL_INC)
170AC_SUBST(AVCALL_DIR)
171AC_MSG_RESULT(yes)
172
173
174dnl ================================
175dnl Test for gmp
176dnl ================================
177
178AC_ARG_WITH(gmp_dir,
179	[  --with-gmp-lib=DIR      dir containing libgmp.a ])
180AC_ARG_WITH(gmp_inc,
181	[  --with-gmp-inc=DIR      dir containing gmp.h ])
182
183old_cflags="$CFLAGS" ; old_ldflags="$LDFLAGS" ; old_libs="$LIBS"
184
185if test "$with_gmp_dir" != "" ;then
186	GMP_DIR="$with_gmp_dir" ; LDFLAGS="-L$with_gmp_dir $LDFLAGS"
187fi
188if test "$with_gmp_inc" != "" ; then
189	GMP_INC="$with_gmp_inc" ; CFLAGS="-I$with_gmp_inc $CFLAGS"
190fi
191LIBS="-lgmp $LIBS"
192
193AC_MSG_CHECKING(for libgmp)
194AC_TRY_LINK([
195#include <gmp.h>
196],[
197	mpz_t i;
198	mpz_init(i);
199	mpz_clear(i);
200],,AC_MSG_ERROR(cannot link with gmp))
201
202CFLAGS="$old_cflags" ; LDFLAGS="$old_ldflags" ; LIBS="$old_libs"
203
204if test "$GMP_DIR" = "" ; then
205	GMP_LIB="-lgmp"
206else
207	GMP_LIB="$GMP_DIR/libgmp.a"
208fi
209
210test "$GMP_INC" = "" && GMP_INC="."
211
212AC_SUBST(GMP_LIB)
213AC_SUBST(GMP_INC)
214AC_SUBST(GMP_DIR)
215AC_MSG_RESULT(yes)
216
217dnl Threading options
218AC_ARG_ENABLE(threads,
219	[  --enable-threads      compile suppport for threading (default yes) ],
220	:,enableval=yes)
221
222if test "x$enableval" = xyes; then
223	if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then
224		AC_DEFINE(SCM_WITH_THREADS, 1, [support for multi threading])
225		AC_DEFINE(_REENTRANT,1, [use threading])
226		AC_DEFINE(_GNU_SOURCE,1, [use gnu source])
227	else
228		AC_MSG_ERROR(threading requires POSIX threads library)
229	fi
230fi
231
232dnl export the default lib path, based on datadir
233if test $prefix = NONE ; then
234	SCM_DEFAULT_LIB_PATH=$ac_default_prefix/share/$PACKAGE/$VERSION
235else
236	eval SCM_DEFAULT_LIB_PATH=$datadir/$PACKAGE/$VERSION
237fi
238
239AC_DEFINE_UNQUOTED(SCM_DEFAULT_LIB_PATH,
240		  "$SCM_DEFAULT_LIB_PATH",
241		  [the default path where to search for libs])
242
243AC_OUTPUT(Makefile tst/Makefile doc/Makefile sgtk/Makefile)
244