1dnl
2dnl Process this file with autoconf to produce a configure script.
3dnl
4
5AC_PREREQ([2.50])
6
7dnl VARIABLES EXPORTED
8dnl
9dnl ARCH
10dnl
11dnl DefHeapSpace= Default DB space
12dnl DefStackSpace= Default global+local
13dnl DefTrailSpace= Default trail
14dnl
15dnl  CPLINT
16dnl
17dnl CPLINT_LIBS=
18dnl CPLINT_LIBS=
19dnl CPLINT_LDFLAGS=
20dnl CPLINT_SHLIB_LD=
21dnl
22dnl  ENVIRONMENT to run YAP before Install is complete
23dnl PRE_INSTALL_ENV= prefix to run YAP after libYap.so and yap are available
24dnl    but before make install
25dnl INSTALL_ENV= prefix to run YAP while doing make install
26dnl
27dnl EXEC_SUFFIX=suffix for executable (.exe)
28dnl
29dnl INSTALL_DLLS= we can do dynamic linking
30dnl SO= suffix for loadable binary (.so,.dll,.o)
31dnl MERGE_DLL_OBJS= we need to merge several .o files into a single dll.
32dnl
33dnl CXXFLAGS= C++-flags
34dnl SHLIB_FLAGS= C-flags used to compile a file that will be loaded dynamically
35dnl DO_SECOND_LD= call a separate dll ld
36dnl YAPLIB_LD= construct libYap.DLL
37dnl SHLIB_LD= dll ld (C)
38dnl SHLIB_CXX_LD= dll ld (C++)
39dnl SHLIB_CFLAGS= cflags to use when constructing a DLL
40dnl SHLIB_CXX_CFLAGS= c++flags to use when constructing a DLL
41dnl YAPLIB_CFLAGS=flags to construct libYap
42dnl EXTRA_LIBS_FOR_DLLS= libs that are required when lding a so
43dnl EXTRA_LIBS_FOR_SWIDLLS= libs that are required when lding a SWI so
44
45
46AC_INIT(console/yap.c)
47AC_CONFIG_HEADER(config.h)
48
49dnl store the environment's compilation flags
50mycflags="$CFLAGS"
51
52AC_PROG_CC
53AC_PROG_CXX
54AC_PROG_AWK
55AC_SUBST(GCC)
56AC_SUBST(C_INTERF_FLAGS)
57AC_SUBST(C_PARSER_FLAGS)
58
59AC_ARG_ENABLE(tabling,
60	[ --enable-tabling           support tabling ],
61	tabling="$enableval", tabling=no)
62AC_ARG_ENABLE(or-parallelism,
63	[ --enable-or-parallelism    support or-parallelism as: env-copy,sba,a-cow ],
64	orparallelism="$enableval", orparallelism=no)
65AC_ARG_ENABLE(rational-trees,
66	[ --enable-rational-trees    support infinite rational trees ],
67	rationaltrees="$enableval" , rationaltrees=yes)
68AC_ARG_ENABLE(coroutining,
69	[ --enable-coroutining       support co-routining, attributed variables and constraints],
70	rationaltrees="$enableval";coroutining="$enableval", coroutining=yes)
71AC_ARG_ENABLE(depth-limit,
72	[ --enable-depth-limit       support depth-bound computation ],
73	depthlimit="$enableval", depthlimit=yes)
74AC_ARG_ENABLE(wam-profile,
75	[ --enable-wam-profile       support low level profiling of abstract machine ],
76	wamprofile="$enableval", wamprofile=no)
77AC_ARG_ENABLE(low-level-tracer,
78	[ --enable-low-level-tracer  support support for procedure-call tracing ],
79	lowleveltracer="$enableval", lowleveltracer=no)
80AC_ARG_ENABLE(threads,
81	[ --enable-threads           support system threads ],
82	threads="$enableval", threads=no)
83AC_ARG_ENABLE(pthread-locking,
84	[ --enable-pthread-locking   use pthread locking primitives for internal locking (requires threads)  ],
85	pthreadlocking="$enableval", pthreadlocking=no)
86AC_ARG_ENABLE(max-performance,
87	[ --enable-max-performance   try using the best flags for specific architecture ],
88	maxperformance="$enableval", maxperformance=no)
89AC_ARG_ENABLE(max-memory,
90	[ --enable-max-memory        try using the best flags for using the memory to the most ],
91	maxmemory="$enableval", maxmemory=yes)
92AC_ARG_ENABLE(debug-yap,
93	[ --enable-debug-yap         enable C-debugging for YAP ],
94	debugyap="$enableval", debugyap=no)
95AC_ARG_ENABLE(eam,
96	[ --enable-eam               enable EAM on YAP ],
97	eam="$enableval", eam=no)
98AC_ARG_ENABLE(cygwin,
99	[ --enable-cygwin            use cygwin library in WIN32 ],
100	cygwin="$enableval", cygwin=no)
101AC_ARG_ENABLE(dynamic_loading,
102	[ --enable-dynamic-loading   compile YAP as a DLL ],
103	dynamic_loading="$enableval", dynamic_loading=no)
104AC_ARG_ENABLE(static_compilation,
105	[ --enable-static-compilation   compile YAP statically ],
106	static_compilation="$enableval", static_compilation=no)
107AC_ARG_ENABLE(use-malloc,
108	[ --enable-use-malloc        use malloc to allocate memory ],
109	use_malloc="$enableval", use_malloc=no)
110AC_ARG_ENABLE(condor,
111	[ --enable-condor            allow YAP to be used from condor ],
112	use_condor="$enableval", use_condor=no)
113AC_ARG_ENABLE(chr,
114	[ --enable-chr            install chr library ],
115	use_chr="$enableval", use_chr=yes)
116AC_ARG_ENABLE(clpqr,
117	[ --enable-clpqr            install clpqr library ],
118	use_clpqr="$enableval", use_clpqr=yes)
119AC_ARG_ENABLE(win64,
120	[ --enable-win64            compile YAP for win64 ],
121	target_win64="$enableval", target_win64=no)
122
123AC_ARG_ENABLE(april,
124	[ --enable-april             compile Yap to support April ILP system],
125	use_april="$enableval", use_april=no)
126
127AC_ARG_ENABLE(dlcompat,
128	[ --enable-dlcompat          use dlcompat library for dynamic loading on Mac OS X],
129	use_dlcompat="$enableval", use_dlcompat=no)
130
131AC_ARG_ENABLE(cplint,
132	[ --enable-cplint[=DIR]       enable the cplint library using the cudd library in DIR/lib],
133		yap_cv_cplint=$enableval, yap_cv_cplint=no)
134
135AC_ARG_WITH(gmp,
136	[ --with-gmp[=DIR]           use GNU Multiple Precision in DIR],
137	if test "$withval" = yes; then
138		yap_cv_gmp=yes
139	elif test "$withval" = no; then
140		yap_cv_gmp=no
141	else
142		yap_cv_gmp=$with_gmp
143		LDFLAGS="$LDFLAGS -L${yap_cv_gmp}/lib"
144		LIBS="$LIBS -L${yap_cv_gmp}/lib"
145		CPPFLAGS="$CPPFLAGS -I${yap_cv_gmp}/include"
146		CFLAGS="$CFLAGS -I${yap_cv_gmp}/include"
147	fi,
148	[yap_cv_gmp=yes])
149
150dnl best test we could do.
151AC_ARG_WITH(minisat,
152	[ --enable-minisat           use minisat interface],
153	if test "$withval" = yes; then
154		yap_cv_minisat=yes
155	elif test "$withval" = no; then
156		yap_cv_minisat=no
157	else
158		yap_cv_minisat="$GXX"
159	fi,
160	[yap_cv_minisat=yes])
161
162AC_ARG_WITH(cudd,
163	[ --with-cudd[=DIR]           use CUDD package in DIR],
164	if test "$withval" = yes; then
165		yap_cv_cudd=yes
166	elif test "$withval" = no; then
167		yap_cv_cudd=no
168	elif test "$withval" = /opt/local; then
169		yap_cv_cudd=$with_cudd
170		CUDD_LDFLAGS="-L/opt/local/lib/cudd -lcudd"
171		CUDD_CPPFLAGS="-I /opt/local/include/cudd"
172	elif test "$withval" = /usr; then
173		yap_cv_cudd=$with_cudd
174		CUDD_LDFLAGS="-lcudd -lmtr -lcuddst -lcuddutil -lepd"
175		CUDD_CPPFLAGS="-I /usr/include/cudd"
176	else
177		yap_cv_cudd=$with_cudd
178		CUDD_LDFLAGS="$yap_cv_cudd/cudd/libcudd.a  $yap_cv_cudd/mtr/libmtr.a  $yap_cv_cudd/st/libst.a  $yap_cv_cudd/util/libutil.a  $yap_cv_cudd/epd/libepd.a"
179		CUDD_CPPFLAGS="-I $yap_cv_cudd/include"
180	fi,
181	[yap_cv_cudd=no])
182
183AC_ARG_ENABLE(myddas,
184v	[ --enable-myddas[[=DIR]]      enable the MYDDAS library],
185	if test "$enableval" = yes; then
186		yap_cv_myddas=/usr
187	elif test "$enableval" = no; then
188		yap_cv_myddas=no
189	else
190		yap_cv_myddas=$enable_myddas
191		LDFLAGS="$LDFLAGS -L${yap_cv_myddas}/lib "
192		CPPFLAGS="$CPPFLAGS -I${yap_cv_myddas}/include "
193	fi,
194	[yap_cv_myddas=/usr])
195
196AC_ARG_ENABLE(myddas-stats,
197	[ --enable-myddas-stats      enable the MYDDAS library statistics support],
198	if test "$yap_cv_myddas" = no; then
199		myddasstats=no
200	else
201		myddasstats="$enableval"
202	fi, myddasstats=no)
203
204AC_ARG_ENABLE(myddas-top-level,
205	[ --enable-myddas-top-level  enable the MYDDAS top-level support to MySQL],
206	if test "$yap_cv_myddas" = no; then
207	   	myddastoplevel=no
208	else
209		myddastoplevel="$enableval"
210	fi, myddastoplevel=no)
211
212AC_ARG_WITH(java,
213	[ --with-java=JAVA_HOME       use Java instalation in JAVA_HOME],
214	if test "$withval" = yes; then
215		yap_cv_java="$JAVA_HOME"
216		dynamic_loading=yes
217		maxmemory=yes
218dnl		threads=yes
219	elif test "$withval" = no; then
220		yap_cv_java=no
221	else
222		yap_cv_java=$with_java
223		dynamic_loading=yes
224		maxmemory=yes
225dnl		threads=yes
226	fi,
227	[yap_cv_java=no])
228
229AC_ARG_WITH(readline,
230	[ --with-readline[=DIR]      use GNU Readline Library in DIR],
231	if test "$withval" = yes; then
232		yap_cv_readline=yes
233	elif test "$withval" = no; then
234		yap_cv_readline=no
235	else
236		yap_cv_readline=$with_readline
237		LDFLAGS="$LDFLAGS -L${yap_cv_readline}/lib"
238		CPPFLAGS="$CPPFLAGS -I${yap_cv_readline}/include"
239	fi,
240	[yap_cv_readline=yes])
241
242AC_ARG_WITH(matlab,
243	[ --with-matlab[=DIR]      use MATLAB package in DIR],
244	if test "$withval" = yes; then
245		yap_cv_matlab=yes
246	elif test "$withval" = no; then
247		yap_cv_matlab=no
248	else
249		yap_cv_matlab=$with_matlab
250		MATLAB_INCLUDE="-I${yap_cv_matlab}/extern/include"
251	fi,
252	[yap_cv_matlab=no])
253
254AC_ARG_WITH(mpi,
255	[ --with-mpi[=DIR]           use MPI library in DIR],
256	if test "$withval" = yes; then
257		yap_cv_mpi=yes
258	elif test "$withval" = no; then
259		yap_cv_mpi=no
260	else
261		yap_cv_mpi=$with_mpi
262		LDFLAGS="$LDFLAGS -L${yap_cv_mpi}/lib"
263		CPPFLAGS="$CPPFLAGS -I${yap_cv_mpi}/include"
264	fi,
265	[yap_cv_mpi=no])
266
267
268AC_ARG_WITH(mpe,
269	[ --with-mpe[=DIR]           use MPE library in DIR],
270	if test "$withval" = yes; then
271		yap_cv_mpe=yes
272	elif test "$withval" = no; then
273		yap_cv_mpe=no
274	else
275		yap_cv_mpe=$with_mpe
276		LDFLAGS="$LDFLAGS -L${yap_cv_mpe}/lib"
277		CPPFLAGS="$CPPFLAGS -I${yap_cv_mpe}/include"
278	fi,
279	[yap_cv_mpe=no])
280
281AC_ARG_WITH(lam,
282	[ --with-lam[=DIR]           use LAM MPI library in DIR],
283	if test "$withval" = yes; then
284		yap_cv_lam=yes
285	elif test "$withval" = no; then
286		yap_cv_lam=no
287	else
288		yap_cv_lam=$with_lam
289		LDFLAGS="$LDFLAGS -L${yap_cv_lam}/lib/lam"
290		CPPFLAGS="$CPPFLAGS -I${yap_cv_lam}/include"
291	fi,
292	[yap_cv_lam=no])
293
294AC_ARG_WITH(heap-space,
295	[ --with-heap-space[=space]  default heap size in Kbytes],
296	if test "$withval" = yes; then
297		yap_cv_heap_space=0
298	elif test "$withval" = no; then
299		yap_cv_heap_space=0
300	else
301		yap_cv_heap_space=$withval
302	fi,
303	[yap_cv_heap_space=0])
304
305AC_ARG_WITH(stack-space,
306	[ --with-stack-space[=space] default stack size in Kbytes],
307	if test "$withval" = yes; then
308		yap_cv_stack_space=0
309	elif test "$withval" = no; then
310		yap_cv_stack_space=0
311	else
312		yap_cv_stack_space=$withval
313	fi,
314	[yap_cv_stack_space=0])
315
316AC_ARG_WITH(trail-space,
317	[ --with-trail-space[=space] default trail size in Kbytes],
318	if test "$withval" = yes; then
319		yap_cv_trail_space=0
320	elif test "$withval" = no; then
321		yap_cv_trail_space=0
322	else
323		yap_cv_trail_space=$withval
324	fi,
325	[yap_cv_trail_space=0])
326
327AC_ARG_WITH(max-workers,
328	[ --with-max-workers[=integer] maximum number of or-parallel processes],
329	if test "$withval" = yes; then
330	  yap_cv_max_workers="(8*SIZEOF_INT_P)"
331	elif test "$withval" = no; then
332	  yap_cv_max_workers="1"
333	else
334	  yap_cv_max_workers=$withval
335	fi,
336	[yap_cv_max_workers="(8*SIZEOF_INT_P)"])
337
338AC_ARG_WITH(max-threads,
339	[ --with-max-threads[=integer] maximum number of or-parallel processes],
340	if test "$withval" = yes; then
341	  yap_cv_max_threads="1024"
342	elif test "$withval" = no; then
343	  yap_cv_max_threads="1"
344	else
345	  yap_cv_max_threads=$withval
346	fi,
347	[yap_cv_max_threads="1024"])
348
349AC_ARG_WITH(junit, [  --with-junit=PATH	  Specify location of the junit JAR file],
350	    [case "$withval" in
351		 yes) JUNIT=/usr/share/java/junit.jar
352			;;
353		 no) JUNIT=""
354			;;
355		 *) JUNIT="$withval"
356			;;
357	     esac])
358
359AC_DEFINE(MinHeapSpace, (1000*SIZEOF_INT_P))
360AC_DEFINE(MinStackSpace,(300*SIZEOF_INT_P))
361AC_DEFINE(MinTrailSpace,( 48*SIZEOF_INT_P))
362
363AC_DEFINE_UNQUOTED(DefHeapSpace,$yap_cv_heap_space)
364AC_DEFINE_UNQUOTED(DefStackSpace,$yap_cv_stack_space)
365AC_DEFINE_UNQUOTED(DefTrailSpace,$yap_cv_trail_space)
366
367AC_SUBST(DefHeapSpace)
368AC_SUBST(DefStackSpace)
369AC_SUBST(DefTrailSpace)
370
371AC_CANONICAL_SYSTEM
372
373AC_DEFINE_UNQUOTED(HOST_ALIAS,"${target}")
374
375if test "$or-parallelism" = no
376then
377  AC_DEFINE(MAX_WORKERS,1)
378else
379  AC_DEFINE_UNQUOTED(MAX_WORKERS,$yap_cv_max_workers)
380fi
381
382if test "$threads" = no
383then
384  AC_DEFINE(MAX_THREADS,1)
385else
386 AC_DEFINE_UNQUOTED(MAX_THREADS,$yap_cv_max_threads)
387fi
388
389
390dnl condor does not like dynamic linking on Linux, DEC, and HP-UX platforms.
391if test "$yap_cv_matlab" = no
392then
393  INSTALL_MATLAB="@# "
394elif test "$yap_cv_matlab" = yes
395then
396  INSTALL_MATLAB=""
397else
398  case "$target_cpu" in
399  i*86*)
400     LDFLAGS="$LDFLAGS -L${yap_cv_matlab}/bin/glnx86"
401  ;;
402  x86*)
403     LDFLAGS="$LDFLAGS -L${yap_cv_matlab}/bin/glnxa64"
404  ;;
405  sparc*)
406     LDFLAGS="$LDFLAGS -L${yap_cv_matlab}/bin/sol2"
407  ;;
408  esac
409  INSTALL_MATLAB=""
410fi
411
412if test "$yap_cv_cudd" = no
413then
414  USE_CUDD="@# "
415else
416  USE_CUDD=""
417fi
418
419dnl condor universe does not like dynamic linking on Linux, DEC, and HP-UX platforms.
420if test "$use_condor" = yes
421then
422  static_compilation="yes"
423  use_malloc="yes"
424  CC="condor_compile $CC"
425  CXX="condor_compile $CXX"
426  dnl no readline with condor.
427  yap_cv_readline="no"
428  AC_DEFINE(SUPPORT_CONDOR, 1)
429  dnl and it disables minisat
430  yap_cv_minisat=no
431  STATIC_MODE=""
432else
433  static_compilation="no"
434  STATIC_MODE="# "
435fi
436
437if test "$yap_cv_minisat" = no
438then
439  USE_MINISAT="@# "
440elif test "$INSTALL_DLLS" = "#"
441then
442  USE_MINISAT="@# "
443else
444  USE_MINISAT=""
445fi
446
447dnl Compilation Flags
448if test "$GCC" = "yes"
449then
450     if test "$debugyap" = "yes"
451     then
452       CXXFLAGS="-O -g -Wall $CFLAGS"
453       C_INTERF_FLAGS="-O -g -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
454       CFLAGS="-O -g -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
455     else
456       CXXFLAGS="-O3 -fomit-frame-pointer -Wall $CFLAGS"
457       C_INTERF_FLAGS="-O3 -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
458       C_PARSER_FLAGS="-O3 -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
459       CFLAGS="-O3 -fomit-frame-pointer -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
460       case "`$CC --version < /dev/null`" in
461	  *3.4*) CFLAGS="-fno-gcse -fno-crossjumping $CFLAGS" ;;
462       esac
463       case "$target_cpu" in
464        i*86*)
465           CFLAGS="-DBP_FREE $CFLAGS"
466           CXXFLAGS="-DBP_FREE $CXXFLAGS"
467        ;;
468        sparc*)
469	  case "$target_os" in
470           *solaris[2-9]*)	dnl
471             CFLAGS="-mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1 $CFLAGS"
472             CXXFLAGS="-mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1 $CFPPLAGS"
473            ;;
474          esac
475        ;;
476       esac
477       if test "$tcpu"; then
478          target_cpu=$tcpu
479       fi
480       if test "$maxperformance" = "yes"
481       then
482         case "$target_cpu" in
483	  athlon)
484           CFLAGS="-march=athlon $CFLAGS"
485           CXXFLAGS="-march=athlon $CXXFLAGS"
486	  ;;
487          i686*)
488           CFLAGS="-march=i686 $CFLAGS"
489           CXXFLAGS="-march=i686 $CXXFLAGS"
490          ;;
491          i586*)
492           CFLAGS="-march=i586 $CFLAGS"
493           CXXFLAGS="-march=i586 $CXXFLAGS"
494          ;;
495          i486*)
496           CFLAGS="-march=i486 $CFLAGS"
497           CXXFLAGS="-march=i486 $CXXFLAGS"
498          ;;
499          i386*)
500           CFLAGS="-march=i386 $CFLAGS"
501           CXXFLAGS="-march=i386 $CXXFLAGS"
502          ;;
503         esac
504       fi
505   fi
506   if test "$CC" = "sslittle-na-sstrix-gcc"
507   then
508    RANLIB="sslittle-na-sstrix-ranlib"
509    AR="sslittle-na-sstrix-ar"
510    PRE_INSTALL_ENV="sim-fast"
511    INSTALL_ENV="sim-fast"
512   fi
513else
514     case "$target_cpu" in
515       i?86*)
516        if test "$CC" = "lcc"
517        then
518          CFLAGS="-A -A $CFLAGS"
519        elif test "$CC" = "cl"
520        then
521          CXXFLAGS="-/nologo $CFLAGS"
522          CFLAGS="/nologo $CFLAGS"
523          CPP="/nologo /E"
524        fi
525        ;;
526       hppa*)
527        if test "$CC" = "cc" -o $CC = c89
528         then
529           if test "$debugyap" = "yes"
530           then
531             CXXFLAGS="-Ae -g -O $CFLAGS"
532             CFLAGS="-Ae -g -O $CFLAGS"
533           else
534             CXXFLAGS="-Ae +O3 +Onolimit  $CFLAGS"
535             CFLAGS="-Ae +O3 +Onolimit $CFLAGS"
536           fi
537        fi
538dnl	LDFLAGS="+e UserCPredicate $LDFLAGS"
539        ;;
540     esac
541   C_INTERF_FLAGS="$CFLAGS"
542   C_PARSER_FLAGS="$CFLAGS"
543fi
544
545dnl Checks for programs.
546AC_PROG_LN_S
547AC_PROG_INSTALL
548AC_PROG_RANLIB
549AC_CHECK_TOOL(INDENT,indent,:)
550AC_CHECK_TOOL(AR,ar,:)
551AC_CHECK_TOOL(MPI_CC,mpicc,:)
552AC_PATH_PROG(INSTALL_INFO,install-info,true,$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin)
553AC_PATH_PROG(SHELL,sh)
554
555dnl Check for libraries.
556dnl mingw does not get along well with libm
557dnl cygnus and mingw32 also need wsock32 to use sockets.
558dnl
559if test "$target_os" = "cygwin"  -o "$target_os" = "mingw32"
560then
561  INSTALL_COMMAND=install_win32
562  if test "$cygwin" = "no" -o "$target_os" = "mingw32"
563  then
564
565    if test "$target_win64" = yes
566    then
567      AC_CHECK_LIB(ws2_32,main)
568      EXTRA_LIBS_FOR_DLLS="-lws2_32 \$(abs_top_builddir)/yap.dll"
569    elif test "$target_os" = "cygwin"
570    then
571      CC="${CC}  -mno-cygwin"
572      CXX="${CXX}  -mno-cygwin"
573      AC_CHECK_LIB(wsock32,main)
574      EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll"
575    else
576      AC_CHECK_LIB(wsock32,main)
577      EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll"
578    fi
579    AC_CHECK_LIB(psapi,main)
580    yap_cv_readline=no
581    if test "$target_win64" = yes
582	CLIB_NETLIBS="-lws2_32 -lpsapi -lgdi32"
583    then
584	CLIB_NETLIBS="-lwsock32 -lpsapi -lgdi32"
585    fi
586    if test "$prefix" = "NONE"
587    then
588      if test "$target_win64" = yes
589      then
590        prefix="\${SYSTEMDRIVE}/Yap64"
591	CLIB_NETLIBS="-lwsock32 -lpsapi -lgdi32"
592      else
593        prefix="\${SYSTEMDRIVE}/Yap"
594      fi
595    fi
596    ENABLE_WINCONSOLE=""
597  else
598    ENABLE_WINCONSOLE="#"
599    LIBS="-lcygwin"
600    EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll"
601  fi
602else
603  INSTALL_COMMAND="install_unix"
604  ENABLE_WINCONSOLE="#"
605  AC_CHECK_LIB(m,sin)
606  AC_CHECK_LIB(socket,socket)
607  dnl X/Open Networking is sometimes a separate library
608  AC_CHECK_LIB(xnet,getsockname)
609  AC_CHECK_LIB(stdc++,main)
610  AC_CHECK_LIB(nsl,main,
611	have_nsl=yes
612	,
613	have_nsl=no)
614  AC_CHECK_LIB(crypt,main)
615  AC_CHECK_LIB(nss_files,main)
616  AC_CHECK_LIB(nss_dns,main)
617  AC_CHECK_LIB(resolv,main)
618fi
619
620if test "$yap_cv_readline" != "no"
621then
622  AC_CHECK_LIB([readline], [main],[
623                AC_DEFINE([HAVE_LIBREADLINE], [1],[Define if you have libreadline])
624		LIBS="$LIBS -lreadline -lncurses"
625              ],
626              [if test "x$with_readline" != xcheck; then
627                 AC_MSG_FAILURE(
628                   [--with-readline was given, but test for readline failed])
629               fi
630              ], -lncurses)
631fi
632if test "$yap_cv_gmp" != "no"
633then
634  AC_CHECK_LIB(gmp,main)
635fi
636
637dnl if test "$yap_cv_cudd" != "no"
638dnl then
639dnl   AC_CHECK_LIB(cudd,Cudd_Init)
640dnl fi
641
642dnl check if we have zlib
643AC_CHECK_LIB(z, zlibVersion,
644	     ZLIBS="-lz"
645	     ZLIB=yes,
646	     ZLIB=no)
647if test $ZLIB = yes
648then
649  LIBS="$LIBS -lz"
650fi
651
652if test "$yap_cv_myddas" != "no"
653then
654	dnl check for mysql
655	AC_MSG_CHECKING(for main in -lmysqlclient)
656	AC_CACHE_VAL(yap_cv_mysql,[
657	AC_TRY_COMPILE(
658		#include <mysql/mysql.h>
659		#include <stdio.h>
660		,
661		MYSQL *conn;
662		conn = mysql_init(NULL);
663		,
664		yap_cv_mysql=yes,yap_cv_mysql=no)])
665	AC_MSG_RESULT($yap_cv_mysql)
666	if test "$yap_cv_mysql" = yes
667	then
668                YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL"
669		LIBS="$LIBS -L${yap_cv_myddas}/lib/mysql -lmysqlclient "
670	fi
671
672	dnl check for odbc
673	AC_MSG_CHECKING(for main in -lodbc)
674	AC_CACHE_VAL(yap_cv_odbc,[
675	AC_TRY_COMPILE(
676		#include <sql.h>
677		#include <sqlucode.h>
678		#include <stdio.h>
679		,
680		SQLHENV henv;
681  		SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
682		,
683		yap_cv_odbc=yes,yap_cv_odbc=no)])
684	AC_MSG_RESULT($yap_cv_odbc)
685	if test "$yap_cv_odbc" = yes
686	then
687		YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC"
688                case "$target_os" in
689			*darwin9*)
690			LIBS="$LIBS -lodbc -framework CoreFoundation"
691			;;
692			**)
693			LIBS="$LIBS -lodbc"
694			;;
695		esac
696	fi
697
698fi
699
700if test "$myddasstats" = "yes"
701  then
702  YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_STATS"
703fi
704
705if test "$myddastoplevel" = "yes"
706  then
707  YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL"
708fi
709
710if test "$threads" = yes
711then
712  AC_DEFINE(SUPPORT_THREADS, 1)
713  AC_CHECK_LIB(pthread,pthread_create)
714  AC_CHECK_HEADERS(pthread.h)
715  AC_CHECK_FUNCS(pthread_mutexattr_setkind_np pthread_mutexattr_settype)
716  if test "$pthreadlocking" = yes
717  then
718    AC_DEFINE(USE_PTHREAD_LOCKING, 1)
719  fi
720  use_malloc=yes
721fi
722
723if test ! -z "$GCC"; then
724    COFLAGS="${COFLAGS--O2 -cc-options,-fno-strict-aliasing}"
725    CWFLAGS="${CWFLAGS--Wall}"
726else
727    COFLAGS="${COFLAGS--O}"
728    CWFLAGS="${CWFLAGS-}"
729fi
730CMFLAGS=-fpic
731CIFLAGS=-I.
732
733if test "$use_chr" = no; then
734  ENABLE_CHR="@# "
735elif test -e "$srcdir"/packages/chr/Makefile.in; then
736  ENABLE_CHR=""
737else
738  ENABLE_CHR="@# "
739fi
740
741if test "$use_clpqr" = no; then
742  ENABLE_CLPQR="@# "
743elif test -e "$srcdir"/packages/clpqr/Makefile.in; then
744  ENABLE_CLPQR=""
745else
746  ENABLE_CLPQR="@# "
747fi
748
749dnl
750dnl java is hard
751dnl
752if test "$yap_cv_java" = no; then
753	ENABLE_JPL="@#"
754elif test -e "$srcdir"/packages/jpl/Makefile.in; then
755	ENABLE_JPL=""
756	JAVA=java
757	JAVA_HOME="$yap_cv_java"
758	case "$target_os" in
759	    *cygwin*|*mingw*)
760	       if test $threads = yes; then
761	         JAVALIBPATH="\"$JAVA_HOME\"/lib/jvm.lib -lpthread"
762               else
763	         JAVALIBPATH="\"$JAVA_HOME\"/lib/jvm.lib"
764               fi
765	       JAVAINCPATH="-I\"$JAVA_HOME\"/include -I\"$JAVA_HOME\"/include/win32"
766	       	  ;;
767	       *darwin*)
768	       LIBS="$LIBS -framework JavaVM"
769	       JAVALIBPATH="-L/System/Library/Frameworks/JavaVM.framework/Libraries -Wl,-framework,JavaVM"
770	       JAVAINCPATH="-I/System/Library/Frameworks/JavaVM.framework/Headers"
771	       	  ;;
772	       *)
773              case "$target_os" in
774	         *linux*)
775		   JAVAINCPATH="-I\"$JAVA_HOME\"/include -I\"$JAVA_HOME\"/include/linux"
776                ;;
777	         *solaris*)
778	        JAVAINCPATH="-I\"$JAVA_HOME\"/include -I\"$JAVA_HOME\"/include/solaris"
779                ;;
780              esac
781              case "$target_cpu" in
782	        i*86*)
783                JAVA_TARGET=i386
784                ;;
785                x86*)
786                JAVA_TARGET=amd64
787               ;;
788               sparc*)
789               JAVA_TARGET=sparc
790                ;;
791               esac
792	       JAVALIBPATH="-L$JAVA_HOME/jre/lib/$JAVA_TARGET -L$JAVA_HOME/jre/lib/$JAVA_TARGET/client  -L$JAVA_HOME/jre/lib/$JAVA_TARGET/server   -Wl,-R,$JAVA_HOME/jre/lib/$JAVA_TARGET -ljava -lverify -ljvm "
793	       	  ;;
794	esac
795	if test "$yap_cv_java" = ""; then
796	  JAVA=java
797          JAR=jar
798          JAVAC=javac
799          JAVADOC=javadoc
800        else
801	  JAVA="$yap_cv_java"/bin/java
802	  JAR="$yap_cv_java"/bin/jar
803	  JAVAC="$yap_cv_java"/bin/javac
804	  JAVADOC="$yap_cv_java"/bin/javadoc
805        fi
806else
807      ENABLE_JPL="@#"
808fi
809
810LAM_MPI_CC=${MPI_CC}
811MPI_OBJS=
812if test "$yap_cv_mpi" != "no"
813then
814  OLD_CC=${CC}
815  CC=${MPI_CC}
816  AC_CHECK_LIB(mpi,MPI_Init,
817		[AC_DEFINE(HAVE_LIBMPI, 1)],
818		[AC_DEFINE(HAVE_LIBMPI, 0)])
819  if test "$ac_cv_lib_mpi_MPI_Init" = yes
820  then
821	#YAPMPILIB=YapMPI.a
822	MPI_OBJS=mpi.o
823  else
824    AC_CHECK_LIB(mpich,MPI_Init,
825		[AC_DEFINE(HAVE_LIBMPICH, 1)],
826		[AC_DEFINE(HAVE_LIBMPICH, 0)])
827    if test "$ac_cv_lib_mpich_MPI_Init" = yes
828    then
829	#YAPMPILIB=YapMPI.a
830	MPI_OBJS=mpi.o
831    else
832	#YAPMPILIB=
833	MPI_CC=${CC}
834    fi
835  fi
836  CC=${OLD_CC}
837else
838#   MPI_CC=${MPI_CC}
839  MPI_CC=${CC}
840fi
841
842
843MPI_LIBS=
844if test "$yap_cv_mpi" != "no" -a "$yap_cv_mpe" != "no"
845then
846  OLD_CC=${CC}
847  CC=${MPI_CC}
848  AC_CHECK_LIB(mpe,MPE_Init_log,
849		[AC_DEFINE(HAVE_LIBMPE, 1)],
850		[AC_DEFINE(HAVE_LIBMPE, 0)])
851  if test "$ac_cv_lib_mpe_MPE_Init_log" = yes
852  then
853	MPI_LIBS="-lmpe"
854	MPI_OBJS="$MPI_OBJS mpe.o"
855  fi
856  CC=${OLD_CC}
857fi
858
859AC_PROG_CPP
860
861if test "$cross_compiling" = "yes"
862then
863  YAP_EXTRAS=
864else
865  AC_SYS_RESTARTABLE_SYSCALLS
866fi
867
868
869dnl defaults
870INSTALL_DLLS="#"
871EXTRA_OBJS=""
872SHLIB_LD="#"
873SHLIB_CXX_LD="#"
874DO_SECOND_LD="#"
875M4="m4"
876MERGE_DLL_OBJS="#"
877IN_UNIX=""
878
879dnl This has to be before $target_os
880YAPLIB="libYap.a"
881
882dnl now this is where things get nasty.
883dnl trying to get the libraries
884case "$target_os" in
885      *linux*)
886        if test "$static_compilation" = "no"
887        then
888	  AC_CHECK_LIB(dl,dlopen,
889	     have_dl=yes
890	   ,
891	     have_dl=no)
892          if test "$have_dl" = "yes"
893	  then
894	    SO="so"
895            SHLIB_LD="$CC -shared -export-dynamic"
896            SHLIB_CXX_LD="$CXX -shared -export-dynamic"
897            DO_SECOND_LD=""
898	    LIBS="$LIBS -ldl"
899	    case "$target_cpu" in
900	      alpha*)
901	        LDFLAGS="-dynamic $LDFLAGS"
902              ;;
903              *)
904	        if test "$CC" != "lcc"
905                then
906	          LDFLAGS="-rdynamic $LDFLAGS"
907                fi
908              ;;
909            esac
910          fi
911	  if test "$ac_cv_prog_gcc" = "yes"
912	  then
913	   SHLIB_CFLAGS="-shared -fPIC $CFLAGS"
914	   SHLIB_CXXFLAGS="-shared -fPIC $CXXFLAGS"
915	   INSTALL_DLLS=""
916          fi
917	  LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
918          DYNYAPLIB=libYap."$SO"
919          SONAMEFLAG="-Wl,-soname=$DYNYAPLIB"
920        fi
921        if test "$have_nsl" = yes
922	 then
923	 LIBS="$LIBS -lnsl"
924        fi
925        if test "$dynamic_loading" = "yes"
926        then
927           YAPLIB_LD="\$(CC) -shared"
928           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
929           INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
930           PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
931        else
932           YAPLIB_LD="\$(CC)"
933           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
934           INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
935           PRE_INSTALL_ENV=""
936        fi
937	;;
938      *sunos4*)
939	M4="/usr/5bin/m4"
940	LDFLAGS="$LDFLAGS -N"
941        if test "$have_nsl" = yes
942	 then
943	 LIBS="$LIBS -lnsl"
944        fi
945        SO="o"
946	INSTALL_DLLS=""
947	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
948        DYNYAPLIB=libYap."$SO"
949	SONAMEFLAG=""
950        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
951        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
952        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
953	;;
954      *hpux*)
955	#do not use the first memory quadrant
956	AC_DEFINE(FORCE_SECOND_QUADRANT)
957	M4="/usr/bin/m4"
958	if test ${use_condor} = no
959        then
960	  SHLIB_INTERFACE="load_shl.o"
961	  if test "$CC" = cc -o "$CC" = c89
962	  then
963	    #this tells ld to export all non-static symbols,
964	    #otherwise no external predicates.
965            SHLIB_LD="$CC -shared -export-dynamic"
966            SHLIB_CXX_LD="$CXX -shared -export-dynamic"
967            DO_SECOND_LD=""
968            SO="sl"
969	    SHLIB_CFLAGS="+z $CFLAGS"
970	    SHLIB_CXXFLAGS="+z $CXXFLAGS"
971	    INSTALL_DLLS=""
972	    # If the xnet library was found, turn on X/Open networking
973	    if test "$ac_cv_lib_xnet_getsockname" = yes
974	    then
975	     AC_DEFINE(_XOPEN_SOURCE)
976	     AC_DEFINE(_XOPEN_SOURCE_EXTENDED,1)
977	    fi
978	  else
979	    INSTALL_DLLS="#"
980          fi
981        fi
982	#do not use realloc() from HP-UX 10.20 together with MPI
983	if test ${target_os} = hpux10.20
984	then
985	  AC_DEFINE(MPI_AVOID_REALLOC,1)
986	fi
987	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
988        DYNYAPLIB=libYap."$SO"
989	SONAMEFLAG=""
990        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
991        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
992        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
993	;;
994      *aix*)
995	# To actually use dlls in AIX I'd need to build YAP as a DLL first.
996	# I won't bother for now.
997	#
998        # SO="a"
999        #SHLIB_LD="\$(srcdir)/../../ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
1000	#INSTALL_DLLS=""
1001	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
1002        DYNYAPLIB=libYap."$SO"
1003	SONAMEFLAG=""
1004        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,\$(LIBDIR)"
1005        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1006        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1007	;;
1008      *osf*)
1009        if ${use_condor} = no
1010        then
1011	  AC_CHECK_LIB(dl,dlopen,
1012dnl Linux has both elf and a.out, in this case we found elf
1013	     have_dl=yes
1014	   ,
1015	     have_dl=no)
1016          SO="so"
1017          SHLIB_LD="ld -shared -expect_unresolved '*'"
1018          DO_SECOND_LD=""
1019        fi
1020	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
1021        DYNYAPLIB=libYap."$SO"
1022	SONAMEFLAG=""
1023        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
1024        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1025        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1026	;;
1027      *irix6*)
1028	SHLIB_CFLAGS="$CFLAGS"
1029	SHLIB_CXXFLAGS="$CXXFLAGS"
1030	SO="so"
1031        DO_SECOND_LD=""
1032	SHLIB_LD="ld -n32 -shared -rdata_shared"
1033        SHLIB_CXX_LD="$SHLIB_LD"
1034	INSTALL_DLLS=""
1035	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
1036        DYNYAPLIB=libYap."$SO"
1037	SONAMEFLAG=""
1038        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
1039        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1040        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1041	;;
1042      *darwin*)
1043	if test ${use_dlcompat} = yes
1044	then
1045	  AC_CHECK_LIB(dl,dlopen,
1046	     have_dl=yes
1047	   ,
1048	     have_dl=no)
1049	  if test ${have_dl} = yes
1050	  then
1051	    LIBS="$LIBS -ldl"
1052	  fi
1053	fi
1054	SO="dylib"
1055        DO_SECOND_LD=""
1056        if test "$dynamic_loading" = "yes"
1057        then
1058	   SHLIB_LD="$CC  -dynamiclib"
1059           SHLIB_CXX_LD="$CXX  -dynamiclib"
1060           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap   -Wl,-install_name,\$(YAPLIBDIR)/\$@"
1061           INSTALL_ENV="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1062        else
1063	   SHLIB_LD="$CC  -dynamiclib -Wl,-undefined,dynamic_lookup"
1064           SHLIB_CXX_LD="$CXX  -dynamiclib -Wl,-undefined,dynamic_lookup"
1065           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS   -Wl,-install_name,\$(YAPLIBDIR)/\$@"
1066           INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1067        fi
1068	if test "$ac_cv_prog_gcc" = "yes"
1069	then
1070	   SHLIB_CFLAGS="-shared -fPIC $CFLAGS"
1071	   SHLIB_CXXFLAGS="-shared -fPIC $CXXFLAGS"
1072	   INSTALL_DLLS=""
1073        fi
1074        CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2"
1075        DYNYAPLIB=libYap."$SO"
1076	SONAMEFLAG=""
1077        YAPLIB_LD="$CC -dynamiclib -Wl,-install_name,$prefix/lib/libYap.$SO"
1078        PRE_INSTALL_ENV="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
1079	;;
1080      *netbsd*|*openbsd*|*freebsd*|*dragonfly*)
1081	if echo __ELF__ | ${CC:-cc} -E - | grep -q __ELF__
1082        then
1083	  #an a.out system
1084	  SHLIB_CFLAGS="$CFLAGS"
1085	  SHLIB_CXXFLAGS="$CXXFLAGS"
1086	  SO="o"
1087        else
1088	  #an elf system
1089	  LDFLAGS="-Wl,--export-dynamic $LDFLAGS"
1090	  SHLIB_CFLAGS="-fPIC $CFLAGS"
1091	  SHLIB_CXXFLAGS="-fPIC $CXXFLAGS"
1092	  SHLIB_LD="$CC -shared -export-dynamic"
1093          SHLIB_CXX_LD="$CXX -shared -export-dynamic"
1094          DO_SECOND_LD=""
1095	  SO="so"
1096	  INSTALL_DLLS=""
1097        fi
1098	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR)"
1099        DYNYAPLIB=libYap."$SO"
1100        SONAMEFLAG="-Wl,--soname=$DYNYAPLIB"
1101        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -Wl,-R,\$(YAPLIBDIR)"
1102        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1103        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1104	;;
1105      *solaris*)
1106       #an elf system
1107        LDFLAGS="-dynamic $LDFLAGS"
1108	SHLIB_CFLAGS="-fPIC $CFLAGS"
1109	SHLIB_CXXFLAGS="-fPIC $CXXFLAGS"
1110	SHLIB_LD="$CC -shared"
1111        SHLIB_CXX_LD="$CXX -shared"
1112        DO_SECOND_LD=""
1113	SO="so"
1114	INSTALL_DLLS=""
1115	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
1116        DYNYAPLIB=libYap."$SO"
1117	SONAMEFLAG="-Wl,--soname=$DYNYAPLIB"
1118        if test "$dynamic_loading" = "yes"
1119        then
1120           YAPLIB_LD="\$(CC)"
1121           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
1122           PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1123           INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1124        else
1125           EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
1126           PRE_INSTALL_ENV=""
1127           YAPLIB_LD="\$(CC) -shared"
1128           INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1129        fi
1130	;;
1131      *cyg*|*mingw*)
1132	# gcc on cygwin seems to have trouble with longjmp
1133        # and -fomit-frame-point -DBP_FREE
1134	YAPLIB="yap.dll"
1135	DYNYAPLIB="yap.dll"
1136	SONAMEFLAG=""
1137	SHLIB_CFLAGS="$CFLAGS"
1138	SHLIB_CXXFLAGS="$CXXFLAGS"
1139        if test "$target_win64" = no
1140        then
1141	  LDFLAGS="-Wl,--large-address-aware $LDFLAGS"
1142        fi
1143        SHLIB_LD="\$(CC) -shared -Wl,--export-all-symbols"
1144        SHLIB_CXX_LD="\$(CXX) -shared -Wl,--export-all-symbols"
1145	SO="dll"
1146	C_PARSER_FLAGS="$C_INTERF_FLAGS"
1147	EXEC_SUFFIX=".exe"
1148	INSTALL_DLLS=""
1149	DO_SECOND_LD=""
1150	MERGE_DLL_OBJS=""
1151        IN_UNIX="#"
1152        YAPLIB_LD="\$(CC) -shared -Wl,--export-all-symbols"
1153        PRE_INSTALL_ENV=""
1154        INSTALL_ENV=""
1155	;;
1156      *)
1157	AC_CHECK_LIB(dl,dlopen,
1158	   have_dl=yes
1159	 ,
1160	   have_dl=no)
1161        if test "$have_dl" = yes
1162	 then
1163         SO="o"
1164	 LIBS="$LIBS -ldl"
1165	 INSTALL_DLLS=""
1166	 if test "$GCC" = "yes"
1167	 then
1168	   SHLIB_CXXFLAGS="-fPIC $CXXFLAGS"
1169	 fi
1170        fi
1171        if test "$have_nsl" = yes
1172	 then
1173	 LIBS="$LIBS -lnsl"
1174        fi
1175	LDFLAGS="$LDFLAGS -L\$(abs_top_builddir) -Wl,-R,\$(LIBDIR) -Wl,-R,\$(YAPLIBDIR)"
1176        DYNYAPLIB=libYap."$SO"
1177	SONAMEFLAG=""
1178        EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)"
1179        PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)"
1180        INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
1181	;;
1182esac
1183
1184EXTRA_LIBS_FOR_SWIDLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir)/packages/PLStream -lplstream"
1185
1186
1187if test "$dynamic_loading" = "yes"
1188then
1189  YAPLIB_CFLAGS="$SHLIB_CFLAGS"
1190  YAPLIB="$DYNYAPLIB"
1191else
1192  YAPLIB_CFLAGS="$CFLAGS"
1193fi
1194
1195if test "$coroutining" = "yes"
1196  then
1197  YAP_EXTRAS="$YAP_EXTRAS -DCOROUTINING=1"
1198fi
1199
1200if test "$rationaltrees" = "yes"
1201  then
1202  YAP_EXTRAS="$YAP_EXTRAS -DRATIONAL_TREES=1"
1203fi
1204
1205if test "$rationaltrees" = "yes" -a "$coroutining" = "yes"
1206  then
1207  INSTALLCLP=""
1208  else
1209  INSTALLCLP="@#"
1210fi
1211
1212if test "$debugyap" = "yes"
1213  then
1214  YAP_EXTRAS="$YAP_EXTRAS -DDEBUG=1"
1215fi
1216
1217if test "$eam" = "yes"
1218  then
1219  YAP_EXTRAS="$YAP_EXTRAS -DBEAM"
1220fi
1221
1222if test "$wamprofile" = "yes"
1223  then
1224  YAP_EXTRAS="$YAP_EXTRAS -DANALYST=1"
1225fi
1226
1227if test "$depthlimit" = "yes"
1228  then
1229  YAP_EXTRAS="$YAP_EXTRAS -DDEPTH_LIMIT=1"
1230fi
1231
1232if test "$use_april" = "yes"
1233  then
1234   YAP_EXTRAS="$YAP_EXTRAS -DDEPTH_LIMIT=1 -DAPRIL"
1235   LDFLAGS="$LDFLAGS -L."
1236   LIBS="$LIBS -lApril"
1237fi
1238
1239if test "$lowleveltracer" = "yes"
1240  then
1241  YAP_EXTRAS="$YAP_EXTRAS -DLOW_LEVEL_TRACER=1"
1242fi
1243
1244if test "$threads" = "yes"
1245  then
1246  YAP_EXTRAS="$YAP_EXTRAS -DTHREADS=1"
1247  if test "$GCC" = "yes"
1248  then
1249    YAP_EXTRAS="$YAP_EXTRAS -D_GNU_SOURCE"
1250  fi
1251fi
1252
1253case "$orparallelism" in
1254  sba)
1255   YAP_EXTRAS="$YAP_EXTRAS -DSBA=1"
1256  ;;
1257  a-cow)
1258   YAP_EXTRAS="$YAP_EXTRAS -DACOW=1"
1259  ;;
1260  yes|env-copy)
1261   YAP_EXTRAS="$YAP_EXTRAS -DENV_COPY=1"
1262  ;;
1263esac
1264
1265if test "$cutc" = "yes"
1266  then
1267  YAP_EXTRAS="$YAP_EXTRAS -DCUT_C=1"
1268fi
1269
1270if test "$tabling" = "yes"
1271  then
1272  YAP_EXTRAS="$YAP_EXTRAS -DTABLING=1"
1273fi
1274if test ! "$yap_cv_cplint" = "no"
1275  then
1276	if test ! "$yap_cv_cplint" = "yes"
1277	then
1278		CPLINT_LDFLAGS+=" -L${yap_cv_cplint}/cudd -L${yap_cv_cplint}/mtr -L${yap_cv_cplint}/st -L${yap_cv_cplint}/util -L${yap_cv_cplint}/epd "
1279		CPLINT_CFLAGS+=" -I${yap_cv_cplint}/include"
1280		CPLINT_LIBS="-lcudd  -lmtr -lst -lepd -lutil -lm "$CPLINT_LIBS
1281	fi
1282	ENABLE_CPLINT=""
1283	if test "$target_os" = "cygwin" -o "$target_os" = "mingw32"
1284	then
1285		CPLINT_SHLIB_LD="gcc -shared ../../yap.dll"
1286		SHLIB_SUFFIX="dll"
1287	else
1288		CPLINT_SHLIB_LD=$SHLIB_LD
1289		SHLIB_SUFFIX="so"
1290	fi
1291	AC_SUBST(CPLINT_LIBS)
1292	AC_SUBST(CPLINT_CFLAGS)
1293	AC_SUBST(CPLINT_LDFLAGS)
1294	AC_SUBST(CPLINT_SHLIB_LD)
1295	AC_SUBST(SHLIB_SUFFIX)
1296else
1297	ENABLE_CPLINT="@#"
1298fi
1299AC_SUBST(ENABLE_CPLINT)
1300
1301AC_SUBST(INSTALL_ENV)
1302AC_SUBST(PRE_INSTALL_ENV)
1303
1304AC_CHECK_LIB(z, zlibVersion,
1305	     ZLIBS="-lz"
1306	     ZLIB=yes,
1307	     ZLIB=no)
1308
1309if test "$ZLIB" = yes; then
1310  ZLIB_TARGETS="zlib4pl.$SO"
1311  ZLIB_PLTARGETS='$(srcdir)/zlib.pl'
1312  ZLIB_INSTALL=install
1313else
1314  ZLIB_TARGETS=nolib
1315  ZLIB_INSTALL=nolib
1316  cat << EOF
1317##################################################################
1318# ERROR: Could not find library zlib (-lz).  Dropped library(zlib)
1319# Library zlib is available from http://www.zlib.net/
1320# Most Unix/Linux distributions are shipped with binaries.  Make
1321# sure to have the development library installed.
1322##################################################################
1323EOF
1324fi
1325
1326AC_SUBST(ZLIBS)
1327AC_SUBST(ZLIB_TARGETS)
1328AC_SUBST(ZLIB_PLTARGETS)
1329AC_SUBST(ZLIB_INSTALL)
1330
1331
1332# LAM
1333OLD_CC=${CC}
1334CC=${LAM_MPI_CC}
1335AC_CHECK_LIB([lam], [main],
1336	LAMOBJS=yap_mpi."$SO",
1337	LAMOBJS=no)
1338CC=${OLD_CC}
1339
1340dnl Checks for header files.
1341AC_HEADER_STDC
1342AC_HEADER_SYS_WAIT
1343AC_CHECK_HEADERS(arpa/inet.h alloca.h crypt.h)
1344AC_CHECK_HEADERS(ctype.h direct.h dirent.h dlfcn.h)
1345AC_CHECK_HEADERS(errno.h execinfo.h fcntl.h fenv.h)
1346AC_CHECK_HEADERS(float.h fpu_control.h ieeefp.h io.h limits.h)
1347AC_CHECK_HEADERS(locale.h malloc.h math.h memory.h)
1348AC_CHECK_HEADERS(mpe.h mpi.h)
1349AC_CHECK_HEADERS(netdb.h netinet/in.h netinet/tcp.h pwd.h regex.h)
1350AC_CHECK_HEADERS(siginfo.h signal.h stdarg.h string.h stropts.h)
1351AC_CHECK_HEADERS(sys/conf.h sys/dir.h sys/file.h)
1352AC_CHECK_HEADERS(sys/mman.h sys/ndir.h sys/param.h)
1353AC_CHECK_HEADERS(sys/resource.h sys/select.h)
1354AC_CHECK_HEADERS(sys/shm.h sys/socket.h sys/stat.h)
1355AC_CHECK_HEADERS(sys/time.h sys/times.h sys/types.h)
1356AC_CHECK_HEADERS(sys/ucontext.h sys/un.h sys/wait.h)
1357AC_CHECK_HEADERS(time.h unistd.h utime.h wctype.h winsock.h winsock2.h)
1358AC_CHECK_HEADERS(zlib.h zutil.h)
1359AC_CHECK_HEADERS(mach-o/dyld.h)
1360if test "$yap_cv_gmp" != "no"
1361then
1362  AC_CHECK_HEADERS(gmp.h)
1363fi
1364if test "$yap_cv_cudd" != "no"
1365then
1366  AC_CHECK_HEADERS(cudd.h)
1367fi
1368if test "$yap_cv_myddas" != "no"
1369then
1370  AC_CHECK_HEADERS(mysql/mysql.h)
1371fi
1372if test "$yap_cv_readline" != "no"
1373then
1374  AC_CHECK_HEADERS( readline/readline.h)
1375fi
1376AC_CHECK_HEADERS(mpe.h)
1377
1378dnl Checks for typedefs, structures, and compiler characteristics.
1379AC_C_INLINE
1380AC_STRUCT_TM
1381AC_CHECK_SIZEOF(int *,4)
1382AC_CHECK_SIZEOF(short int,2)
1383AC_CHECK_SIZEOF(int,4)
1384AC_CHECK_SIZEOF(long int,4)
1385AC_CHECK_SIZEOF(long long int,8)
1386AC_CHECK_SIZEOF(float,4)
1387AC_CHECK_SIZEOF(double,8)
1388
1389dnl check type of malloc (i.e. char *  or void *)
1390AC_MSG_CHECKING(for type of malloc)
1391AC_CACHE_VAL(yap_cv_malloct,[
1392AC_TRY_RUN(
1393	#include <stdlib.h>
1394	char *malloc(size_t);
1395	int main() {
1396	   void *p=malloc(1);
1397	   return 0;
1398	}
1399	,
1400	yap_cv_malloct=char,yap_cv_malloct=void,yap_cv_malloct=void)])
1401AC_MSG_RESULT($yap_cv_malloct *)
1402if test "$yap_cv_malloct" = void
1403then AC_DEFINE(MALLOC_T,void *)
1404else AC_DEFINE(MALLOC_T,char *)
1405fi
1406
1407
1408dnl check how to generate headers (i.e. should we use GCC inline?)
1409AC_MSG_CHECKING(for gcc inline)
1410AC_CACHE_VAL(yap_cv_gcc,[
1411AC_TRY_RUN(
1412	#undef inline
1413	inline int f(int x) {return x+1;}
1414	int main() { return 0;}
1415	,
1416	yap_cv_gcc=yes,yap_cv_gcc=no,yap_cv_gcc=yes)])
1417AC_MSG_RESULT($yap_cv_gcc)
1418if test "$yap_cv_gcc" = yes
1419then
1420M4GENHDRS=m4/gcc_genhdrs.m4
1421AC_DEFINE(HAVE_GCC,1)
1422else
1423M4GENHDRS=m4/cc_genhdrs.m4
1424AC_DEFINE(HAVE_GCC,0)
1425fi
1426AC_SUBST(M4)
1427AC_SUBST(M4GENHDRS)
1428
1429dnl SWI compatibility, I don't know why just use host...
1430changequote(,)dnl
1431if test "x$ARCH" = "x"; then
1432  case "$host" in
1433    *linux*)
1434      ARCH=`echo $host | sed 's/-.*/-linux/'`
1435      ;;
1436    *-gnu)
1437      ARCH=`echo $host | sed 's/\([^-]*\)-[^-]*-\([^-]*\)-gnu/\1-\2/'`
1438      ;;
1439    *)
1440      ARCH=`echo $host | sed 's/\([^-]*\)-[^-]*-\([^-]*\)/\1-\2/'`
1441      ;;
1442  esac
1443fi
1444changequote([,])dnl
1445AC_SUBST(ARCH)
1446
1447dnl System stuff for dynamic linking.
1448dnl
1449dnl Exports:
1450dnl
1451dnl "" if we can do dynamic linking, "#" otherwise
1452AC_SUBST(INSTALL_DLLS)
1453dnl if we need to merge several .o files into a single dll.
1454AC_SUBST(MERGE_DLL_OBJS)
1455dnl C-flags used to compile a file that will be loaded dynamically
1456AC_SUBST(CXXFLAGS)
1457AC_SUBST(SHLIB_CFLAGS)
1458AC_SUBST(SHLIB_CXXFLAGS)
1459dnl suffix for loadable binary (.so,.dll,.o)
1460AC_SUBST(SO)
1461dnl suffix for executable (.exe)
1462AC_SUBST(EXEC_SUFFIX)
1463dnl how to call the loader
1464AC_SUBST(DO_SECOND_LD)
1465AC_SUBST(SHLIB_LD)
1466AC_SUBST(SHLIB_CXX_LD)
1467AC_SUBST(YAPLIB_LD)
1468AC_SUBST(YAPLIB_CFLAGS)
1469AC_SUBST(EXTRA_LIBS_FOR_DLLS)
1470AC_SUBST(EXTRA_LIBS_FOR_SWIDLLS)
1471dnl objects in YAP library
1472AC_SUBST(YAPLIB)
1473AC_SUBST(DYNYAPLIB)
1474AC_SUBST(LDFLAGS)
1475AC_SUBST(SONAMEFLAG)
1476dnl install_info
1477AC_SUBST(INSTALL_INFO)
1478dnl let YAP_EXTRAS fall through configure, from the env into Makefile
1479AC_SUBST(YAP_EXTRAS)
1480AC_SUBST(NO_BUILTIN_REGEXP)
1481AC_SUBST(ENABLE_CHR)
1482AC_SUBST(ENABLE_CLPQR)
1483AC_SUBST(ENABLE_JPL)
1484AC_SUBST(JAVA)
1485AC_SUBST(JAVA_HOME)
1486AC_SUBST(JUNIT)
1487AC_SUBST(JAVAC)
1488AC_SUBST(JAVADOC)
1489AC_SUBST(JAR)
1490AC_SUBST(IN_UNIX)
1491AC_SUBST(YAPMPILIB)
1492AC_SUBST(LAM_MPI_CC)
1493AC_SUBST(MPI_OBJS)
1494AC_SUBST(MPI_LIBS)
1495AC_SUBST(INSTALL_COMMAND)
1496AC_SUBST(INSTALLCLP)
1497AC_SUBST(JAVALIBPATH)
1498AC_SUBST(JAVAINCPATH)
1499AC_SUBST(LAMOBJS)
1500AC_SUBST(MAX_WORKERS)
1501AC_SUBST(STATIC_MODE)
1502AC_SUBST(ENABLE_WINCONSOLE)
1503
1504AC_SUBST(USE_CUDD)
1505AC_SUBST(CUDD_LDFLAGS)
1506AC_SUBST(CUDD_CPPFLAGS)
1507AC_SUBST(USE_MINISAT)
1508AC_SUBST(INSTALL_MATLAB)
1509AC_SUBST(MATLAB_INCLUDE)
1510
1511dnl check for threaded code
1512AC_MSG_CHECKING(for gcc threaded code)
1513AC_CACHE_VAL(yap_cv_threaded_code,[
1514AC_TRY_RUN(
1515	int main() {
1516	void *t = &&l2;
1517	l1: goto *t;
1518	l2: return 0;
1519}
1520	,
1521	yap_cv_threaded_code=yes,yap_cv_threaded_code=no,yap_cv_threaded_code=yes)])
1522AC_MSG_RESULT($yap_cv_threaded_code)
1523if test "$yap_cv_threaded_code" = yes && test "$yap_cv_gcc" = yes
1524then
1525	AC_DEFINE(USE_THREADED_CODE,1)
1526	M4GENABSMI=gen_gcc.m4
1527else
1528	AC_DEFINE(USE_THREADED_CODE,0)
1529	M4GENABSMI=gen_ansi.m4
1530fi
1531
1532AC_SUBST(M4GENABSMI)
1533
1534
1535dnl check for IEEE floats
1536AC_MSG_CHECKING(for IEEE floats)
1537AC_CACHE_VAL(yap_cv_ffieee,[
1538AC_TRY_RUN(
1539	int main() {
1540	  union { float f; int i} a;
1541	  a.f = 1;
1542	  if (a.i==0x3f800000) return 0;
1543	  return 1;
1544	}
1545	,
1546	yap_cv_ffieee=yes,yap_cv_ffieee=no,yap_cv_ffieee=yes)])
1547AC_MSG_RESULT($yap_cv_ffieee)
1548if test "$yap_cv_ffieee" = yes
1549then
1550AC_DEFINE(FFIEEE,1)
1551else
1552AC_DEFINE(FFIEEE,0)
1553fi
1554
1555dnl check for sigsetjmp
1556AC_MSG_CHECKING(for sigsetjmp)
1557AC_CACHE_VAL(yap_cv_sigsetjmp,[
1558AC_TRY_COMPILE(
1559	#include <setjmp.h>
1560	,
1561	sigjmp_buf         RestartEnv;
1562
1563	siglongjmp (RestartEnv, 1);
1564	,
1565	yap_cv_sigsetjmp=yes,yap_cv_sigsetjmp=no)])
1566AC_MSG_RESULT($yap_cv_sigsetjmp)
1567if test "$yap_cv_sigsetjmp" = yes
1568then
1569AC_DEFINE(HAVE_SIGSETJMP,1)
1570else
1571AC_DEFINE(HAVE_SIGSETJMP,0)
1572fi
1573
1574dnl check for sigsegv
1575AC_MSG_CHECKING(for sigsegv)
1576AC_CACHE_VAL(yap_cv_sigsegv,[
1577AC_TRY_COMPILE(
1578	#include <signal.h>
1579	#include <stdio.h>
1580	,
1581	printf("Signal value is %d\n", SIGSEGV);
1582	,
1583	yap_cv_sigsegv=yes,yap_cv_sigsegv=no)])
1584AC_MSG_RESULT($yap_cv_sigsegv)
1585if test "$yap_cv_sigsegv" = yes
1586then
1587AC_DEFINE(HAVE_SIGSEGV,1)
1588else
1589AC_DEFINE(HAVE_SIGSEGV,0)
1590fi
1591
1592dnl check for sigsegv
1593AC_MSG_CHECKING(for sigprof)
1594AC_CACHE_VAL(yap_cv_sigprof,[
1595AC_TRY_COMPILE(
1596	#include <signal.h>
1597	#include <stdio.h>
1598	,
1599	printf("Signal value is %d\n", SIGPROF);
1600	,
1601	yap_cv_sigprof=yes,yap_cv_sigprof=no)])
1602AC_MSG_RESULT($yap_cv_sigprof)
1603if test "$yap_cv_sigsegv" = yes
1604then
1605AC_DEFINE(HAVE_SIGPROF,1)
1606else
1607AC_DEFINE(HAVE_SIGPROF,0)
1608fi
1609
1610dnl check for siginfo
1611AC_MSG_CHECKING(for siginfo)
1612AC_CACHE_VAL(yap_cv_siginfo,[
1613AC_TRY_COMPILE(
1614	#include <signal.h>
1615	#include <stdio.h>
1616	,
1617	printf("SIGINFO value is %d\n", SA_SIGINFO);
1618	,
1619	yap_cv_siginfo=yes,yap_cv_siginfo=no)])
1620AC_MSG_RESULT($yap_cv_siginfo)
1621if test "$yap_cv_siginfo" = yes
1622then
1623AC_DEFINE(HAVE_SIGINFO,1)
1624else
1625AC_DEFINE(HAVE_SIGINFO,0)
1626fi
1627
1628dnl this is copied from the Tcl code
1629dnl this code checks whether the system defines an union wait
1630AC_MSG_CHECKING([union wait])
1631AC_TRY_LINK([#include <sys/types.h>
1632#include <sys/wait.h>], [
1633union wait x;
1634wait(&x);		/* make sure we can compile wait */
1635WIFEXITED(x);		/* Generates compiler error if WIFEXITED
1636			 * uses an int. */
1637], union_wait_ok=yes, union_wait_ok=no)
1638AC_MSG_RESULT($union_wait_ok)
1639if test "$union_wait_ok" = no; then
1640    AC_DEFINE(NO_UNION_WAIT)
1641fi
1642
1643dnl check whether the system supports the environ variable
1644AC_MSG_CHECKING([environ])
1645AC_TRY_LINK([], [
1646extern char **environ;
1647], environ_ok=yes, environ_ok=no)
1648AC_MSG_RESULT($environ_ok)
1649if test "$environ_ok" = yes; then
1650    AC_DEFINE(HAVE_ENVIRON)
1651fi
1652
1653dnl Checks for library functions.
1654AC_TYPE_SIGNAL
1655AC_CHECK_FUNCS(_NSGetEnviron access acosh)
1656AC_CHECK_FUNCS(alloca asinh atanh chdir ctime dlopen dup2)
1657AC_CHECK_FUNCS(erf feclearexcept)
1658AC_CHECK_FUNCS(fesettrapenable fgetpos finite fpclass ftime getcwd getenv)
1659AC_CHECK_FUNCS(gethostbyname gethostent gethostid gethostname)
1660AC_CHECK_FUNCS(gethrtime getpagesize)
1661AC_CHECK_FUNCS(getpwnam getrlimit getrusage gettimeofday getwd)
1662AC_CHECK_FUNCS(isatty isnan isinf kill labs link lgamma)
1663AC_CHECK_FUNCS(localtime lstat mallinfo)
1664AC_CHECK_FUNCS(mbsnrtowcs)
1665AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp)
1666AC_CHECK_FUNCS(nanosleep mktime opendir)
1667AC_CHECK_FUNCS(putenv rand random readlink regexec)
1668AC_CHECK_FUNCS(rename rint rl_set_prompt sbrk select)
1669AC_CHECK_FUNCS(setbuf setitimer setsid setlinebuf sigaction)
1670AC_CHECK_FUNCS(siggetmask siginterrupt)
1671AC_CHECK_FUNCS(signal sigprocmask socket stat)
1672AC_CHECK_FUNCS(strchr strerror stricmp strncat strncpy strtod)
1673AC_CHECK_FUNCS(time times tmpnam usleep utime vsnprintf)
1674
1675AC_CHECK_FUNC(regexec, [NO_BUILTIN_REGEXP="#"], [NO_BUILTIN_REGEXP=""])
1676
1677AC_CHECK_FUNCS(NSLinkModule)
1678
1679if test "$use_condor" = "no"
1680then
1681  AC_CHECK_FUNCS(alarm mmap popen shmat sleep system ttyname waitpid)
1682fi
1683
1684if test "$target_os" != "mingw32"
1685then
1686  AC_CHECK_FUNCS(fetestexcept snprintf)
1687fi
1688
1689dnl check for mpz_xor
1690AC_MSG_CHECKING(for mpz_xor)
1691AC_CACHE_VAL(yap_cv_mpz_xor,[
1692AC_TRY_LINK(
1693	#include <gmp.h>
1694	void check(mpz_t rop,mpz_t op1,mpz_t op2) {
1695	  mpz_xor(rop,op1,op2);
1696	}
1697	,
1698	,
1699	yap_cv_mpz_xor=yes,yap_cv_mpz_xor=no)])
1700AC_MSG_RESULT($yap_cv_mpz_xor)
1701if test "$yap_cv_mpz_xor" = yes
1702then
1703AC_DEFINE(HAVE_MPZ_XOR,1)
1704else
1705AC_DEFINE(HAVE_MPZ_XOR,0)
1706fi
1707
1708if test "$use_malloc" = "yes" -a "$maxmemory" = "yes"
1709then
1710  maxmemory="no"
1711fi
1712
1713dnl On some systems doing a fflush(NULL) to flush all output streams
1714dnl has the side-effect of makeing all charactes waiting in input
1715dnl pipes disapear.
1716AC_CACHE_CHECK(
1717[if fflush(NULL) clobbers input pipes],
1718[yap_cv_broken_fflush_null],
1719[ cat >conftest.$ac_ext <<EOF
1720  #include <stdio.h>
1721  #include <stdlib.h>
1722  int main(int argc, char **argv)
1723  {
1724      char *buf;
1725      int i;
1726      char *bp;
1727      bp = buf = malloc(1024);
1728      while (1) {
1729          while ((i = getc(stdin)) != -1
1730                 && (*bp++ = i) != '\n'
1731                 && (bp - buf < 1024) )
1732    	  /* DO NOTHING */ ;
1733          *bp = '\0';
1734          fprintf(stdout, "%s", buf);
1735          fflush(NULL);
1736          if( i == EOF ) return 0;
1737          bp = buf;
1738      }
1739  }
1740EOF
1741  AC_TRY_EVAL(ac_link)
1742  if test "$?" = 0
1743  then
1744    cat conftest.$ac_ext | ./conftest$ac_exeext > conftest.out
1745    AC_TRY_COMMAND(cmp conftest.$ac_ext conftest.out)
1746    if test "$?" = 0
1747    then
1748      AC_MSG_RESULT(no)
1749      yap_cv_broken_fflush_null=no
1750    else
1751      AC_MSG_RESULT(yes)
1752      yap_cv_broken_fflush_null=yes
1753    fi
1754  else
1755    dnl This should never happen
1756    AC_MSG_RESULT(failed)
1757    yap_cv_broken_fflush_null=failed
1758  fi
1759  rm -f conftest.$ac_ext conftest.$ac_objext conftest$ac_exeext conftest.out ])
1760if test "$yap_cv_broken_fflush_null" = no
1761then
1762  AC_DEFINE(BROKEN_FFLUSH_NULL,0)
1763else
1764  dnl be conservative: if the test failed, assume fflush(NULL) is
1765  dnl not working properly
1766  AC_DEFINE(BROKEN_FFLUSH_NULL,1)
1767fi
1768
1769dnl disable smart memory management
1770if test "$use_malloc" = yes
1771then
1772AC_DEFINE(USE_SYSTEM_MALLOC,1)
1773AC_DEFINE(GC_NO_TAGS,1)
1774fi
1775
1776dnl large memory configuration, don't trust Yap allocation routines
1777if test "$maxmemory" = yes
1778then
1779AC_DEFINE(GC_NO_TAGS,1)
1780AC_DEFINE(USE_DL_MALLOC,1)
1781fi
1782
1783dnl SWI compatibility support!
1784PROLOG_SYSTEM=yap
1785IN_YAP=
1786IN_SWI="#"
1787CHR_TARGETS=chr_support."$SO"
1788
1789AC_SUBST(PROLOG_SYSTEM)
1790AC_SUBST(IN_YAP)
1791AC_SUBST(IN_SWI)
1792AC_SUBST(TARGETS)
1793AC_SUBST(PLTARGETS)
1794AC_SUBST(CHR_TARGETS)
1795
1796CLIB_TARGETS="random.$SO socket.$SO cgi.$SO memfile.$SO files.$SO mime.$SO crypt.$SO"
1797CLIB_PLTARGETS="\$(srcdir)/random.pl \$(srcdir)/socket.pl \$(srcdir)/cgi.pl \$(srcdir)/memfile.pl \$(srcdir)/filesex.pl \$(srcdir)/mime.pl \$(srcdir)/crypt.pl"
1798
1799if test "$ac_cv_func_setitimer" = "yes"; then
1800  CLIB_TARGETS="$CLIB_TARGETS time.$SO"
1801  CLIB_PLTARGETS="$CLIB_PLTARGETS \$(srcdir)/time.pl"
1802else
1803  echo "WARNING: no setitimer(); dropping time.pl from targets"
1804fi
1805
1806if test "$IN_UNIX" = ""; then
1807CLIB_TARGETS="unix.$SO $CLIB_TARGETS"
1808CLIB_PLTARGETS="\$(srcdir)/unix.pl $CLIB_PLTARGETS"
1809CLIB_NETLIBS=
1810else
1811AC_CHECK_FUNC(socket, [], [
1812             AC_CHECK_LIB(socket, socket,
1813                      [CLIB_NETLIBS="$CLIB_NETLIBS -lsocket"]
1814                      AC_DEFINE(HAVE_LIBSOCKET, 1,
1815                      "Define if you have the socket library (-lsocket)."))])
1816AC_CHECK_FUNC(gethostent, [], [
1817             AC_CHECK_LIB(nsl, gethostent,
1818                      [CLIB_NETLIBS="$CLIB_NETLIBS -lnsl"]
1819                      AC_DEFINE(HAVE_LIBNSL, 1,
1820                      "Define if you have the nsl library (-lnsl)."))])
1821fi
1822
1823AC_CHECK_LIB(pthread, pthread_create,
1824                      [CLIB_PTHREADS="-lpthread"],[CLIB_PTHREADS=""])
1825
1826oldlibs="$LIBS"
1827AC_CHECK_LIB(crypt, crypt)
1828CLIB_CRYPTLIBS="$LIBS"
1829AC_CHECK_FUNCS(crypt)
1830LIBS="$oldlibs"
1831
1832AC_SUBST(CLIB_PTHREADS)
1833AC_SUBST(CLIB_TARGETS)
1834AC_SUBST(CLIB_PLTARGETS)
1835AC_SUBST(CLIB_NETLIBS)
1836AC_SUBST(CLIB_CRYPTLIBS)
1837
1838AC_CHECK_TYPES(socklen_t, [], [],
1839[
1840#include <sys/types.h>
1841#include <sys/socket.h>
1842])
1843AC_CHECK_TYPES(ssize_t, [], [],
1844[
1845#include <sys/types.h>
1846#include <sys/socket.h>
1847])
1848
1849dnl tszet and timezone trouble
1850
1851AC_MSG_CHECKING("variable timezone in tzset")
1852AC_TRY_RUN(
1853[ #include <time.h>
1854  #include <stdlib.h>
1855  #ifdef __CYGWIN__
1856  #define timezone _timezone
1857  #endif
1858  extern long timezone;
1859
1860  main()
1861  { tzset();
1862
1863    if ( timezone > -15*3600 &&
1864	 timezone < 15*3600 &&
1865	 timezone % 60 == 0 )
1866      return 0;
1867
1868    exit(1);
1869  }
1870],
1871AC_MSG_RESULT(yes)
1872AC_DEFINE(HAVE_VAR_TIMEZONE, 1,
1873	  [Define if tzset sets timezone variable]),
1874AC_MSG_RESULT(no),
1875AC_MSG_RESULT(assuming no))
1876
1877AC_CHECK_MEMBER(struct tm.tm_gmtoff,
1878		AC_DEFINE(HAVE_STRUCT_TIME_TM_GMTOFF, [],
1879			  [Define is struct tm has tm_gmtoff]),
1880		[],
1881		[#include <time.h>])
1882
1883AC_MSG_CHECKING(_XOPEN_SOURCE)
1884AC_TRY_COMPILE(
1885[
1886#define _XOPEN_SOURCE
1887#include <unistd.h>
1888],
1889[
1890], AC_DEFINE(DEFINE_XOPEN_SOURCE, 1,
1891	     "Define if _XOPEN_SOURCE is needed")
1892   AC_MSG_RESULT(yes),
1893   AC_MSG_RESULT(no))
1894
1895if test "$with_time" = yes; then
1896  if test "$ac_cv_func_setitimer" = "yes"; then
1897    TARGETS="$TARGETS time.$SO"
1898  else
1899    echo "WARNING: no setitimer(); dropping time.pl from targets"
1900  fi
1901fi
1902
1903if test "$ac_cv_func_getrlimit" = "yes"; then
1904  TARGETS="$TARGETS rlimit.$SO"
1905else
1906  echo "WARNING: no getrlimit(); dropping rlimit.pl from targets"
1907fi
1908
1909
1910
1911mkdir -p  library/lammpi
1912mkdir -p  library/matrix
1913mkdir -p  library/matlab
1914mkdir -p  library/mpi
1915mkdir -p  library/random
1916mkdir -p  library/regex
1917mkdir -p  library/system
1918mkdir -p  library/tries
1919mkdir -p  library/rltree
1920mkdir -p  LGPL/clp
1921mkdir -p  LGPL/swi_console
1922mkdir -p  GPL
1923mkdir -p  packages/
1924mkdir -p  packages/clib
1925mkdir -p  packages/clib/sha1
1926mkdir -p  packages/clib/maildrop
1927mkdir -p  packages/clib/maildrop/rfc822
1928mkdir -p  packages/clib/maildrop/rfc2045
1929mkdir -p  packages/CLPBN
1930mkdir -p  packages/clpqr
1931mkdir -p  packages/cplint
1932mkdir -p  packages/cplint/approx
1933mkdir -p  packages/cplint/slipcase
1934mkdir -p  packages/cplint/approx/simplecuddLPADs
1935mkdir -p  packages/http
1936mkdir -p  packages/jpl
1937mkdir -p  packages/jpl/src/java
1938mkdir -p  packages/jpl/src/java/jpl
1939mkdir -p  packages/jpl/src/java/jpl/fli
1940mkdir -p  packages/jpl/src/java/jpl/test
1941mkdir -p  packages/jpl/examples
1942mkdir -p  packages/jpl/examples/java
1943mkdir -p  packages/tai
1944mkdir -p  packages/tai/libtai
1945mkdir -p  packages/PLStream
1946mkdir -p  packages/plunit
1947mkdir -p  packages/ProbLog
1948mkdir -p  packages/ProbLog/simplecudd
1949mkdir -p  packages/ProbLog/simplecudd_lfi
1950mkdir -p  packages/RDF
1951mkdir -p  packages/semweb
1952mkdir -p  packages/sgml
1953mkdir -p  packages/zlib
1954
1955AC_CONFIG_FILES([Makefile])
1956AC_CONFIG_FILES([GPL/Makefile])
1957AC_CONFIG_FILES([library/Makefile])
1958AC_CONFIG_FILES([library/lammpi/Makefile])
1959AC_CONFIG_FILES([library/matlab/Makefile])
1960AC_CONFIG_FILES([library/matrix/Makefile])
1961AC_CONFIG_FILES([library/mpi/Makefile])
1962AC_CONFIG_FILES([library/random/Makefile])
1963AC_CONFIG_FILES([library/regex/Makefile])
1964AC_CONFIG_FILES([library/rltree/Makefile])
1965AC_CONFIG_FILES([library/system/Makefile])
1966AC_CONFIG_FILES([library/tries/Makefile])
1967AC_CONFIG_FILES([LGPL/Makefile])
1968AC_CONFIG_FILES([LGPL/clp/Makefile])
1969AC_CONFIG_FILES([LGPL/swi_console/Makefile])
1970AC_CONFIG_FILES([packages/clib/Makefile])
1971AC_CONFIG_FILES([packages/clib/maildrop/rfc822/Makefile])
1972AC_CONFIG_FILES([packages/clib/maildrop/rfc2045/Makefile])
1973AC_CONFIG_FILES([packages/CLPBN/Makefile])
1974AC_CONFIG_FILES([packages/cplint/Makefile])
1975AC_CONFIG_FILES([packages/cplint/approx/simplecuddLPADs/Makefile])
1976AC_CONFIG_FILES([packages/cplint/slipcase/Makefile])
1977AC_CONFIG_FILES([packages/http/Makefile])
1978AC_CONFIG_FILES([packages/tai/Makefile])
1979AC_CONFIG_FILES([packages/tai/libtai/Makefile])
1980AC_CONFIG_FILES([packages/PLStream/Makefile])
1981AC_CONFIG_FILES([packages/plunit/Makefile])
1982AC_CONFIG_FILES([packages/ProbLog/Makefile ])
1983AC_CONFIG_FILES([packages/RDF/Makefile])
1984AC_CONFIG_FILES([packages/semweb/Makefile])
1985AC_CONFIG_FILES([packages/sgml/Makefile])
1986AC_CONFIG_FILES([packages/zlib/Makefile])
1987
1988if test "$ENABLE_CHR" = ""; then
1989AC_CONFIG_FILES([packages/chr/Makefile])
1990fi
1991
1992if test "$ENABLE_CLPQR" = ""; then
1993AC_CONFIG_FILES([packages/clpqr/Makefile])
1994fi
1995
1996if test "$ENABLE_JPL" = ""; then
1997AC_CONFIG_FILES([packages/jpl/Makefile packages/jpl/jpl_paths.yap packages/jpl/src/java/Makefile packages/pyswip/Makefile ])
1998fi
1999
2000if test "$USE_CUDD" = ""; then
2001AC_CONFIG_FILES([packages/ProbLog/simplecudd/Makefile])
2002AC_CONFIG_FILES([packages/ProbLog/simplecudd_lfi/Makefile])
2003fi
2004
2005if test "$USE_MINISAT" = ""; then
2006AC_CONFIG_FILES([packages/swi-minisat2/Makefile])
2007AC_CONFIG_FILES([packages/swi-minisat2/C/Makefile])
2008fi
2009
2010AC_OUTPUT()
2011
2012