1#                                               -*- Autoconf -*-
2# Run autoheader and autoconf to produce a header and configure script from
3# this file.
4
5AC_PREREQ(2)
6AC_INIT([Asymptote],[2.67],[http://sourceforge.net/projects/asymptote])
7VERSION=$PACKAGE_VERSION
8AC_SUBST(VERSION)
9m4_include([ax_pthread.m4])
10
11test "$CXXFLAGS" || CXXFLAGS="-std=c++11"
12
13test "$CFLAGS" || CFLAGS="-g -O3"
14
15AC_C_BIGENDIAN
16AC_CANONICAL_HOST
17
18test "$prefix" = NONE && prefix=/usr/local
19Datadir=$datadir
20test "$Datadir" = '${datarootdir}' && Datadir=$datarootdir
21test "$Datadir" = '${prefix}/share' && Datadir=$prefix/share
22AC_SUBST(Datadir)
23
24AC_ARG_WITH(latex,
25        [AS_HELP_STRING(--with-latex=PATH,
26                        specify path to LaTeX installation)],
27                     [if test "x$withval" != "x" ; then
28                        latexdir=$withval
29                      fi
30                     ],[
31AC_CHECK_PROG(kpsewhich,kpsewhich,true)
32if test "x$kpsewhich" = "xtrue"; then
33  latexdir=`kpsewhich -expand-var='$TEXMFLOCAL'/tex/latex`
34else
35  latexdir=$prefix/share/texmf/tex/latex
36  AC_CHECK_FILE($latexdir/base/latex.ltx,,
37  [latexdir=/usr/share/texmf/tex/latex
38  AC_CHECK_FILE($latexdir/base/latex.ltx,,)])
39fi
40])
41
42AC_ARG_WITH(context,
43        [AS_HELP_STRING(--with-context=PATH,
44                        specify path to ConTeXt installation)],
45                     [if test "x$withval" != "x" ; then
46                        contextdir=$withval
47                      fi
48                     ],[
49AC_CHECK_PROG(kpsewhich,kpsewhich,true)
50if test "x$kpsewhich" = "xtrue"; then
51  contextdir=`kpsewhich -expand-var='$TEXMFLOCAL'/tex/context/third`
52else
53  contextdir=$prefix/share/texmf/tex/context/third
54fi
55])
56
57AC_CHECK_PROGS(TEXI2DVI,[texi2dvi],
58[@echo \*\*\*\*\*\*\*\*\*\* Please install texi2dvi or put http://asymptote.sourceforge.net/asymptote.pdf in the doc directory: cannot execute texi2dvi])
59
60AC_SUBST(TEXI2DVI)
61
62latexdir=$latexdir/asymptote
63contextdir=$contextdir/asymptote
64
65AC_MSG_NOTICE([Using $latexdir for LaTeX style file])
66AC_MSG_NOTICE([Using $contextdir for ConTeXT style file])
67
68AC_SUBST(latexdir)
69AC_SUBST(contextdir)
70
71docdir=$Datadir/doc/asymptote
72
73AC_ARG_WITH(docdir,
74        [AS_HELP_STRING(--with-docdir=PATH,
75alternate documentation installation directory)],
76                     [if test "x$withval" != "x" ; then
77                        docdir=$withval
78                      fi
79                     ])
80AC_SUBST(docdir)
81
82sysdir=$Datadir/asymptote
83
84AC_ARG_ENABLE(texlive-build,
85[AS_HELP_STRING(--enable-texlive-build,
86automatically determine sysdir from kpsewhich)],
87[ if test "x$enableval" = "xyes" ; then
88    sysdir=""
89  fi
90])
91
92AC_DEFINE_UNQUOTED(ASYMPTOTE_SYSDIR,"$sysdir",
93        [System directory for global .asy files])
94AC_DEFINE_UNQUOTED(ASYMPTOTE_DOCDIR,"$docdir",
95        [Directory for documentation])
96
97AC_CONFIG_SRCDIR([absyn.cc])
98
99AC_LANG([C++])
100
101# Checks for programs.
102AC_PROG_LEX
103AC_PROG_CXX
104AC_PROG_INSTALL
105AC_PROG_CC
106AC_PROG_MAKE_SET
107AC_PROG_YACC
108
109if test "$GXX" = yes ; then
110   ac_gcc_version=`echo __GNUC__ | $CC -E - | grep -v ^\#`
111   ac_clang=`echo __clang__ | $CC -E - | grep -v ^\#`
112   if test "$ac_gcc_version" -lt 4; then
113       CFLAGS=$CFLAGS" -finline-limit=400"
114   else
115     if test "$ac_clang" != 1; then
116         CFLAGS=$CFLAGS" -fno-var-tracking"
117     fi
118   fi
119fi
120
121AC_DEFUN([DEFINE],[
122Define to 1 if you have $1.
123])
124
125AC_DEFUN([DEFINE_LIB],[
126Define to 1 if you have the `$1' library (-l$1).
127])
128
129AC_CHECK_HEADER(tr1/unordered_map)
130AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
131    [#include <tr1/unordered_map>]
132    [std::tr1::unordered_map<int,int> map;]
133  )],
134  AC_DEFINE(HAVE_TR1_UNORDERED_MAP,1,
135  DEFINE([<tr1/unordered_map>])),
136  [
137  AC_CHECK_HEADER(unordered_map,AC_DEFINE(HAVE_UNORDERED_MAP,1,
138                   DEFINE([<unordered_map>])),
139  [AC_CHECK_HEADER(ext/hash_map,,OPTIONS=$OPTIONS"-DNOHASH ")])])
140
141ASYGLVERSION=1.00
142
143GCVERSION=8.0.4
144ATOMICVERSION=7.6.10
145
146GCFILE=gc-$GCVERSION
147ac_cv_use_gc="system"
148
149AC_CHECK_FILE($GCFILE.tar.gz,
150ac_cv_use_gc=$GCVERSION)
151AC_ARG_ENABLE(gc,
152        [AS_HELP_STRING(--enable-gc[[[=system]]],
153enable system Boehm garbage collector)]
154        [     [[=VERSION]]   enable local VERSION of Boehm garbage collector]
155        [     [[=PREFIX]]    use Boehm garbage collector installed in PREFIX],
156                        [
157                        if test "x$enableval" != "xyes" ; then
158                           ac_cv_use_gc=$enableval
159                        fi
160                        ])
161
162OPTIONS="-D_FILE_OFFSET_BITS=64 "
163GCLIB=
164GCPPLIB=
165INCL="-I."
166GCNAME="Boehm Garbage Collector"
167GCOPTIONS="--disable-shared"
168if test "x$ac_cv_use_gc" != "xno" ; then
169   OPTIONS=$OPTIONS"-DUSEGC "
170   case _$ac_cv_use_gc in
171   _|_system|_*[[\\/]]*)
172      if test "x$ac_cv_use_gc" = "xsystem" ; then
173         INCL="-I. -I$prefix/include/gc -I/usr/include/gc"
174         LIBS=$LIBS"-L$prefix/lib "
175      else
176         INCL="-I$ac_cv_use_gc/include/gc"
177         LIBS=$LIBS"-L$ac_cv_use_gc/lib "
178      fi
179      CPPFLAGS_SAVE=$CPPFLAGS
180      CPPFLAGS=$CPPFLAGS" $INCL"
181      AC_CHECK_HEADER(gc.h,
182        AC_CHECK_LIB([gc],[GC_malloc],[
183          LIBS=$LIBS"-lgc "
184          AC_MSG_NOTICE([enabling system $GCNAME])],[
185        GCDIR=$GCFILE
186        INCL="-I. -I\$(GC)/include"
187        GCLIB="\$(GC)/.libs/libgc.a"
188        AC_MSG_NOTICE($GCNAME library not found)]),
189      GCDIR=$GCFILE
190      GCLIB="\$(GC)/.libs/libgc.a"
191      INCL="-I. -I\$(GC)/include"
192      AC_MSG_NOTICE($GCNAME header file not found))
193      CPPFLAGS=$CPPFLAGS_SAVE
194      ;;
195   *)
196      GCVERSION=$ac_cv_use_gc
197      GCFILE=gc-$GCVERSION
198      GCDIR=$GCFILE
199      AC_MSG_NOTICE([enabling local $GCNAME $GCDIR])
200      GCLIB="\$(GC)/.libs/libgc.a"
201      INCL="-I. -I\$(GC)/include"
202      ;;
203   esac
204else
205   AC_MSG_NOTICE([disabling the $GCNAME])
206fi
207
208AC_ARG_ENABLE(gc-debug,
209[AS_HELP_STRING(--enable-gc-debug,enable (slow) garbage collector debugging)],
210[ if test "x$ac_cv_use_gc" != "xno" ; then
211    if test "x$enableval" = "xyes" ; then
212       OPTIONS=$OPTIONS"-DGC_DEBUG "
213       AC_MSG_NOTICE([*** Enabling GC debugging: remember to make clean ***])
214       AC_MSG_NOTICE([*** Set the environment variable GC_FIND_LEAK at runtime ***])
215    fi
216 fi
217])
218
219AC_ARG_ENABLE(gc-full-debug,
220[AS_HELP_STRING(--enable-gc-full-debug,enable (very slow) garbage collector backtrace)],
221[ if test "x$ac_cv_use_gc" != "xno" ; then
222    if test "x$enableval" = "xyes" ; then
223       OPTIONS=$OPTIONS"-DGC_DEBUG -DGC_BACKTRACE "
224       GCOPTIONS=$GCOPTIONS"--enable-gc-debug "
225       AC_MSG_NOTICE([*** Enabling GC backtrace debugging; remember to make gc-clean ***])
226    fi
227 fi
228])
229
230INCL=$INCL" -I/usr/include/tirpc"
231
232if test "$OSTYPE" = "msdos"; then
233CPPFLAGS=$CPPFLAGS" -D__MSDOS__ -I/usr/include/w32api -I/usr/include -DCALLBACK=__stdcall $INCL"
234else
235CPPFLAGS=$CPPFLAGS" $INCL"
236fi
237
238AC_CHECK_FUNC(getopt_long_only, AC_DEFINE(HAVE_GNU_GETOPT_H, 1,
239                           DEFINE([GNU <getopt.h>])),
240                           getopt="getopt getopt1",)
241AC_SUBST(getopt)
242AC_SUBST(GCVERSION)
243AC_SUBST(ASYGLVERSION)
244AC_SUBST(ATOMICVERSION)
245AC_SUBST(GCOPTIONS)
246AC_SUBST(GCLIB)
247AC_SUBST(GCPPLIB)
248AC_SUBST(INCL)
249AC_SUBST(OPTIONS)
250AC_SUBST(GLEW)
251
252# Checks for libraries.
253AC_SEARCH_LIBS([lgamma],[m c],,
254AC_MSG_ERROR([*** Please install libm on your system ***]))
255AC_CHECK_LIB([z], [deflate],,
256AC_MSG_ERROR([*** Please install libz or zlib-devel on your system ***]))
257AX_PTHREAD
258
259AC_ARG_ENABLE(sigsegv,
260[AS_HELP_STRING(--enable-sigsegv[[[=yes]]],enable GNU Stack Overflow Handler)])
261
262if test "x$enable_sigsegv" != "xno"; then
263  AC_CHECK_LIB([sigsegv], [stackoverflow_install_handler])
264fi
265
266AC_CHECK_LIB([rt], [sched_yield])
267
268AC_CHECK_LIB([curl],[curl_easy_init],,
269AC_MSG_NOTICE([*** Could not find libcurl: will compile without optional URL support. ***]))
270
271AC_ARG_ENABLE(readline,
272[AS_HELP_STRING(--enable-readline[[[=yes]]],enable GNU Readline Library)])
273
274AC_ARG_ENABLE(static,
275[AS_HELP_STRING(--enable-static[[[=no]]],link against static libraries)])
276
277LDSTATIC=""
278STATIC=""
279DYNAMIC=""
280if test "x$enable_static" = "xyes"; then
281  LDSTATIC="-static "
282  STATIC="-Wl,-Bstatic "
283  DYNAMIC="-Wl,-Bdynamic "
284fi
285
286AC_DEFUN([READLINE],[
287AC_MSG_NOTICE([*** Could not find GNU readline 4.3 or later: will compile without readline support ***])
288AC_CHECK_LIB([edit],[readline])
289AC_CHECK_HEADERS(editline/readline.h)
290])
291
292AC_DEFUN([CHECK_FOUND_STATIC],[
293AC_DEFINE($1,1,DEFINE_LIB($2))
294LIBS=$LIBS$STATIC"-l$2 "$DYNAMIC
295])
296
297AC_DEFUN([AC_CHECK_LIB_STATIC],[
298LDFLAGS0=$LDFLAGS
299LDFLAGS=$LDFLAGS$LDSTATIC
300AC_CHECK_LIB($1,$2,CHECK_FOUND_STATIC($3,$1),
301if test "x$enable_static" = "xyes"; then
302[
303AS_UNSET([ac_cv_lib_$1_$2])
304LDFLAGS=$LDFLAGS0
305AC_CHECK_LIB($1,$2,,$4)
306]
307else
308$4
309fi
310)
311LDFLAGS=$LDFLAGS0
312])
313
314if test "x$enable_readline" != "xno"; then
315AC_COMPILE_IFELSE([
316AC_LANG_PROGRAM([
317#include <stdio.h>
318#include <unistd.h>
319#include <readline/readline.h>
320],[
321#ifndef RL_READLINE_VERSION
322abort
323#endif
324])],
325AC_CHECK_LIB_STATIC(readline,history_list,HAVE_LIBREADLINE,READLINE),
326READLINE)
327
328AC_CHECK_LIB_STATIC(tinfo,tgetent,HAVE_LIBTINFO,AC_MSG_NOTICE([perhaps tgetent is in -lncurses]))
329
330AC_CHECK_HEADERS([ncurses/curses.h ncurses.h curses.h],[break])
331AC_CHECK_LIB_STATIC([ncurses],[setupterm],HAVE_LIBCURSES,
332                    AC_CHECK_LIB([curses],[setupterm]))
333fi
334
335AC_ARG_ENABLE(fftw,
336[AS_HELP_STRING(--enable-fftw[[[=yes]]],enable FFTW Library)])
337
338if test "x$enable_fftw" != "xno"; then
339
340AC_CHECK_HEADER(fftw3.h,
341AC_CHECK_LIB_STATIC([fftw3],[fftw_execute],HAVE_LIBFFTW3,
342           AC_MSG_NOTICE([*** Could not find libfftw3: will compile without optional fast Fourier transforms. ***])),
343     AC_MSG_NOTICE([*** Header file fftw3.h not found: will compile without optional fast Fourier transforms. ***]))
344fi
345
346# Checks for header files.
347AC_HEADER_SYS_WAIT
348AC_CHECK_HEADERS([fenv.h stddef.h libintl.h])
349AC_CHECK_HEADERS(fpu_control.h)
350AC_CHECK_FUNCS([feenableexcept])
351
352
353AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "xstream.h"])],
354                   [AC_SEARCH_LIBS([xdrstdio_create],[nsl tirpc])
355                    AC_DEFINE(HAVE_RPC_RPC_H,1,
356                   DEFINE([a working <tirpc/rpc/rpc.h> header]))],
357   AC_MSG_WARN([*** Broken rpc headers; XDR support disabled ***]))
358
359AC_ARG_ENABLE(gsl,
360[AS_HELP_STRING(--enable-gsl[[[=yes]]],enable GNU Scientific Library)])
361
362if test "x$enable_gsl" != "xno"; then
363  AC_CHECK_HEADER(gsl/gsl_sf.h,
364   AC_CHECK_LIB([gsl], gsl_sf_debye_6, [AC_DEFINE(HAVE_LIBGSL,1,
365   DEFINE_LIB[gsl]) LIBS=$LIBS"-lgsl -lgslcblas "],
366           AC_MSG_NOTICE([*** Could not find libgsl: will compile without optional special functions. ***]),[-lgslcblas]),
367     AC_MSG_NOTICE([*** Header file gsl_sf.h not found: will compile without optional special functions. ***]))
368fi
369
370AC_ARG_ENABLE(gl,
371[AS_HELP_STRING(--enable-gl[[[=yes]]],enable OpenGL Library)])
372
373AC_ARG_ENABLE(offscreen,
374[AS_HELP_STRING(--enable-offscreen[[[=no]]],use OSMesa library to implement offscreen rendering)])
375
376AC_ARG_ENABLE(OpenImageIO,
377[AS_HELP_STRING(--enable-openimageio[[[=no]]],enable experimental OpenImageIO Library)])
378
379            AC_CHECK_HEADER(glm/glm.hpp,
380                       [AC_DEFINE(HAVE_LIBGLM,1,
381                    DEFINE([the <glm/glm.hpp> header]))],AC_MSG_NOTICE([*** Could not find glm header files: will compile without WebGL or OpenGL support ***]))
382
383if test "x$enable_gl" != "xno"; then
384                    AC_CHECK_HEADERS([ncurses/curses.h ncurses.h curses.h],[break])
385if test "x$enable_openimageio" = "xyes"; then
386            AC_CHECK_HEADER([OpenEXR/ImathVec.h],
387                AC_CHECK_HEADER([OpenImageIO/imageio.h],
388                        AC_CHECK_LIB([OpenImageIO],[open])))
389fi
390
391case "$OSTYPE" in
392     msdos)
393              AC_CHECK_LIB([gccpp],[GC_throw_bad_alloc])
394              AC_CHECK_HEADER(GL/glut.h,
395                                  [AC_DEFINE(HAVE_LIBGLUT,1,
396                     DEFINE_LIB[freeglut])
397                             LIBS=$LIBS"-lfreeglut "],
398                                   AC_MSG_NOTICE([*** Could not find libfreeglut: will compile without OpenGL support ***]))
399              AC_CHECK_HEADER(GL/gl.h,
400                                  [AC_DEFINE(HAVE_LIBGL,1,
401                     DEFINE_LIB[opengl32])
402                             LIBS=$LIBS"-lopengl32 "
403                             GLEW="glew.o "],
404                                   AC_MSG_NOTICE([*** Could not find libopengl32: will compile without OpenGL support ***]))
405        ;;
406     darwin*)
407              AC_CHECK_LIB([gccpp],[GC_throw_bad_alloc])
408              AC_CHECK_HEADER(OpenGL/gl.h,
409                             [AC_DEFINE(HAVE_LIBGL,1,
410                             DEFINE([<gl.h> header]))])
411              AC_CHECK_HEADER(GLUT/glut.h, [AC_DEFINE(HAVE_LIBGLUT,1,
412                   DEFINE_LIB[GLUT])
413                           LIBS=$LIBS"-framework GLUT -framework OpenGL -framework Cocoa "
414                           GLEW="glew.o "],
415                                 AC_MSG_NOTICE([*** Could not find GLUT: will compile without OpenGLLUT support ***]))
416        ;;
417     *)
418         AC_CHECK_LIB([gccpp],[GC_throw_bad_alloc])
419          AC_CHECK_LIB([glut], [glutMainLoop],,
420                       AC_MSG_NOTICE([*** Could not find libglut: will compile without OpenGL support ***]))
421         AC_CHECK_LIB([GL], [glDepthMask],
422                                 [AC_DEFINE(HAVE_LIBGL,1,
423                             DEFINE_LIB([GL]))
424                             LIBS=$LIBS"-lGL "
425                             GLEW="glew.o "
426                             AC_CHECK_LIB([GLX],[glXGetProcAddressARB],
427                             GLEW=$GLEW"-lGLX ")],
428                                   AC_MSG_NOTICE([*** Could not find libGL: will compile without OpenGL support ***]))
429esac
430   if test "x$enable_offscreen" = "xyes"; then
431           AC_CHECK_LIB([OSMesa],OSMesaCreateContext,,
432                        AC_MSG_NOTICE([*** Could not find libOSMesa: will compile without offscreen rendering support ***]))
433   fi
434fi
435
436# Checks for typedefs, structures, and compiler characteristics.
437AC_TYPE_PID_T
438AC_TYPE_SIZE_T
439AC_CHECK_TYPES([ptrdiff_t])
440AC_CHECK_TYPES([long long])
441AC_CHECK_TYPES([long])
442AC_C_CONST
443AC_C_INLINE
444AC_TYPE_SIGNAL
445
446AC_DEFUN([ac_FUNC_STRPTIME], [
447    AC_CHECK_FUNCS(strptime)
448])
449
450# Checks for library functions.
451AC_FUNC_FORK
452AC_CHECK_FUNCS([dup2 floor memset strchr tgamma lgamma memrchr popcount])
453AC_FUNC_STRFTIME
454ac_FUNC_STRPTIME
455AC_FUNC_ERROR_AT_LINE
456AC_FUNC_FSEEKO
457
458AC_CONFIG_HEADERS(config.h)
459
460AC_CONFIG_FILES([Makefile doc/Makefile doc/png/Makefile])
461AC_OUTPUT
462
463if test "x$GCDIR" != "x" ; then
464   AC_CHECK_FILE($GCDIR.tar.gz,,[
465   echo
466   echo Please put the Boehm garbage collector tar.gz files in the asymptote directory.
467   echo FOR EXAMPLE, USE THE COMMANDS:
468   echo
469   echo wget https://github.com/ivmai/bdwgc/releases/download/v$GCVERSION/$GCFILE.tar.gz
470   echo wget http://www.ivmaisoft.com/_bin/atomic_ops/libatomic_ops-$ATOMICVERSION.tar.gz
471
472   echo
473   exit 1
474   ])
475fi
476