1##############################################################################
2#               configure.ac
3#
4# Process this file with autoconf to produce the configure script.
5#
6# from Persistence of Vision(tm) Ray Tracer version 3.6.
7# Copyright 1991-2003 Persistence of Vision Team
8# Copyright 2003-2004 Persistence of Vision Raytracer Pty. Ltd.
9#---------------------------------------------------------------------------
10# NOTICE: This source code file is provided so that users may experiment
11# with enhancements to POV-Ray and to port the software to platforms other
12# than those supported by the POV-Ray developers. There are strict rules
13# regarding how you are permitted to use this file. These rules are contained
14# in the distribution and derivative versions licenses which should have been
15# provided with this file.
16#
17# These licences may be found online, linked from the end-user license
18# agreement that is located at http://www.povray.org/povlegal.html
19#---------------------------------------------------------------------------
20# This program is based on the popular DKB raytracer version 2.12.
21# DKBTrace was originally written by David K. Buck.
22# DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
23#---------------------------------------------------------------------------
24# $File: //depot/povray/3.6-release/unix/configure.ac $
25# $Revision: #7 $
26# $Change: 3032 $
27# $DateTime: 2004/08/02 18:43:41 $
28# $Author: chrisc $
29# $Log$
30##############################################################################
31
32# configure.ac for the source distribution of POV-Ray 3.6 for UNIX
33# Written by Nicolas Calimet <pov4grasp@free.fr>
34
35# This 'configure.ac' file is a full rewrite of the former 'configure.in'
36# prepared by Mark Gordon and distributed with the official POV-Ray 3.5
37# for Unix/Linux.  The hope is that the 'configure' script derived from
38# 'configure.ac' will work on most *nix architectures (and not only Linux).
39# 'configure.ac' comes with a set of supporting files that are needed to
40# generate a fresh 'configure'.  In particular, the 'acinclude.m4' file
41# defines all POV_* macros used throughout the present file.
42#
43# New features (among others):
44# * The supporting libraries (Zlib, PNG, JPEG, and TIFF) are included in
45#   the compilation process when they are either not found on the system
46#   or too old.  Otherwise the POV-Ray executable is linked against the
47#   shared libraries available on the system.  Full static linking is also
48#   possible through the --disable-shared option.
49# * Compilation flags (mostly for code optimization) are tested at
50#   configure time.  For now those flags are essentially oriented towards
51#   the GNU gcc compiler, but further tweaking might come along with
52#   experience in other compilers (e.g. Intel C/C++).
53# * It is no longer required to hand-edit the source/optout.h file to update
54#   the "Compiled by..." heading message.  Instead, configure uses the
55#   COMPILED_BY environment variable (required).
56
57
58# Required autoconf version.
59AC_PREREQ(2.57)
60
61# Inits.
62# Cannot use a variable to define the POV-Ray version string.
63AC_INIT([POV-Ray], [3.6.1], [pov4grasp@free.fr], [povray])
64VERSION_BASE=3.6
65AC_SUBST([VERSION_BASE])
66AC_DEFINE_UNQUOTED([VERSION_BASE],
67  ["$VERSION_BASE"],
68  [Base version number of package]
69)
70AC_CONFIG_AUX_DIR([config])
71AC_CONFIG_HEADERS([conf.h])
72AC_CONFIG_SRCDIR([unix/unix.cpp])
73
74# Required versions of the supporting libraries.
75# Must be declared after AC_INIT.
76required_libz_version="1.2.1"
77required_libpng_version="1.2.5"
78required_libjpeg_version="6b"
79required_libtiff_version="3.6.1"
80
81# Supported options.
82POV_ARG_ENABLE([--enable-watch-cursor],
83  [enable a watch cursor over the display while rendering (X Window only)]
84)
85POV_ARG_ENABLE([--enable-strip],
86  [enable stripping all symbols from the object files (smaller binary)]
87)
88POV_ARG_ENABLE([--enable-debug],
89  [enable compiler debugging mode]
90)
91POV_ARG_ENABLE([--enable-profile],
92  [enable program execution profiling]
93)
94POV_ARG_ENABLE([--disable-optimiz],
95  [disable all compiler optimizations]
96)
97POV_ARG_ENABLE([--disable-pipe],
98  [disable usage of pipes during compilation (use temporary files instead)]
99)
100POV_ARG_ENABLE([--disable-shared],
101  [disable linking with shared libraries (build static binary)]
102)
103POV_ARG_ENABLE([--disable-lib-checks],
104  [disable checking for supporting image libraries (force compiling)]
105)
106POV_ARG_ENABLE([--disable-vsnprintf-check],
107  [disable checking for the C99 vsnprintf() function (systems without this functions will fail compiling the program)]
108)
109# cannot use $PACKAGE_NAME instead of litteral POV-Ray
110POV_ARG_ENABLE([--disable-io-restrictions],
111  [disable POV-Ray's mechanism for control of I/O operations]
112)
113
114POV_ARG_WITH([--without-cygwin-dll],
115  [don't link with the Cygwin DLL (MinGW required)]
116)
117POV_ARG_WITH([--with-svga],
118  [use the SVGA library (Linux only)]
119)
120
121AC_ARG_VAR([COMPILED_BY],
122  [customize the "unofficial version" message which defaults to user@machine]
123)
124AC_ARG_VAR([C99_COMPATIBLE_RADIOSITY],
125  [adapt radiosity code to non-IEEE 754 floating point, requires ISO C99 compiler and library (see source/octree.cpp for details)]
126)
127
128
129###############################################################################
130
131
132# Remove povray.ini unconditionally.
133rm -f ./povray.ini
134
135
136# Instruction message.
137if test -z "$COMPILED_BY"; then
138  echo "
139Welcome to the $PACKAGE_NAME $PACKAGE_VERSION configure script.
140
141This script will prepare the source distribution of $PACKAGE_NAME $PACKAGE_VERSION for Unix
142for compilation on this machine.  Compiling the program yourself means
143that the POV-Ray Team(tm) is not responsible for supporting this
144version, no matter if it is the unmodified official POV-Ray source code
145or a customized version.  Refer to the POV-Ray source license conditions
146that come with this package.
147
148In order to start configuration, you have to provide a valid contact
149information that will be included in the executable and displayed
150whenever POV-Ray (or a modified version of it) is started.  In case
151you intend to distribute this binary, this information will help users
152to contact the appropriate maintainers.  To start configuring $PACKAGE_NAME
153type in the following command with your own contact information:
154
155./configure COMPILED_BY=\"your name <email@address>\"
156
157Please consult the INSTALL file for additional configuration and
158installation instructions.
159"
160  exit 1
161fi
162
163
164# Don't use 'echo' (not saved into config.log / doesn't honor --silent).
165# Don't use AC_MSG_NOTICE which prints things first.
166AC_MSG_RESULT([
167===============================================================================
168Configure $PACKAGE_NAME version $PACKAGE_VERSION
169===============================================================================
170
171This is an unofficial version compiled by:
172 $COMPILED_BY
173The POV-Ray Team(tm) is not responsible for supporting this version.])
174
175AC_DEFINE_UNQUOTED([DISTRIBUTION_MESSAGE_2],
176  [" $COMPILED_BY"],
177  [Who compiled this binary.]
178)
179
180
181###############################################################################
182
183AC_MSG_RESULT([
184Environment
185-----------])
186
187AC_CANONICAL_BUILD
188AC_CANONICAL_HOST
189
190AM_INIT_AUTOMAKE([1.7 dist-bzip2])
191AM_MAINTAINER_MODE
192
193POV_CHECK_PATH(C_INCLUDE_PATH, ".",
194  [pov_warn_path="$pov_warn_path C_INCLUDE_PATH"]
195)
196POV_CHECK_PATH(CPLUS_INCLUDE_PATH, ".",
197  [pov_warn_path="$pov_warn_path CPLUS_INCLUDE_PATH"]
198)
199
200
201###############################################################################
202
203AC_MSG_RESULT([
204Programs
205--------])
206
207# Check for C++ compiler and version.
208# Inits compiler flags to avoid defaults such as '-g -O2'.
209CXXFLAGS="$CXXFLAGS"
210POV_PROG_CXX_VERSION
211AC_DEFINE_UNQUOTED([COMPILER_VER],
212  [" ($pov_prog_cxx_version @ $host)"],
213  [Compiler version.]
214)
215
216# Check for C compiler for CFLAGS passed to supporting libraries.
217# Inits compiler flags to avoid defaults such as '-g -O2'.
218CFLAGS="$CFLAGS"
219AC_PROG_CC
220AC_PROG_CPP
221
222# Not necessary when AM_MAINTAINER_MODE is called above.
223###AC_PROG_MAKE_SET
224
225AC_PROG_RANLIB
226
227
228###############################################################################
229
230AC_MSG_RESULT([
231Language constructs and functions
232---------------------------------])
233
234AC_LANG(C++)
235
236# Don't link with the cygwin DLL.
237# Must be placed before any other header or function checks.
238AC_MSG_CHECKING([whether to link with cygwin DLL])
239if test x"$with_cygwin_dll" = x"no"; then
240  AC_MSG_RESULT([no])
241  case "$host" in
242    *cygwin*)
243      pov_flags="-mno-cygwin"
244      pov_cygwin_save_cxxflags="$CXXFLAGS"
245      pov_cygwin_save_cflags="$CFLAGS"
246      POV_PROG_CXX_FLAGS([$pov_flags],
247        [
248          POV_PROG_CC_FLAGS([$pov_flags],
249            [
250              AC_CHECK_LIB([mingw32], [main],
251                [
252                  LDFLAGS="$LDFLAGS $pov_flags"
253                  # -D__CYGWIN is required for tiffio.h (incl. in tiff_pov.cpp)
254                  CPPFLAGS="$CPPFLAGS -D__CYGWIN $pov_flags"
255                ],
256                [with_cygwin_dll="yes"]
257              )
258            ],
259            [with_cygwin_dll="yes"]
260          )
261        ],
262        [with_cygwin_dll="yes"]
263      )
264      if test x"$with_cygwin_dll" != x"no"; then
265        AC_MSG_WARN([Cannot link without Cygwin DLL])
266        CXXFLAGS="$pov_cygwin_save_cxxflags"
267        CFLAGS="$pov_cygwin_save_cflags"
268      fi
269    ;;
270  esac
271else
272  case "$host" in
273    *cygwin*)
274      AC_MSG_RESULT([yes])
275    ;;
276    *)
277      AC_MSG_RESULT([no])
278    ;;
279  esac
280fi
281
282# Compiling on the mingw32 platform (e.g. using MSYS) also requires
283# the -D__CYGWIN flag for tiff_pov.cpp
284case "$host" in
285  *mingw32*)  CPPFLAGS="$CPPFLAGS -D__CYGWIN";;
286esac
287
288
289# Language constructs.
290
291AC_HEADER_TIME
292AC_CHECK_HEADERS([limits.h sys/time.h unistd.h])
293
294AC_TYPE_SIZE_T
295AC_STRUCT_TM
296
297AC_CHECK_SIZEOF([int])
298AC_CHECK_SIZEOF([long int])	# check for 64 bit support
299AC_CHECK_SIZEOF([size_t])       # check for 64 bit support
300AC_CHECK_SIZEOF([float])
301
302
303# Checks for functions.
304
305# the test for memcmp does not work well with C++
306AC_LANG_PUSH(C)
307AC_FUNC_MEMCMP
308AC_LANG_POP(C)
309
310AC_TYPE_SIGNAL
311#AC_FUNC_STRFTIME
312#AC_FUNC_VPRINTF
313
314# vsnprintf <stdarg.h> (C99)
315if test x"$enable_vsnprintf_check" != x"no"; then
316  AC_CHECK_FUNC([vsnprintf],
317    [],
318    [AC_MSG_ERROR([
319*** This system does not provide the C99 vsnprintf() function which
320*** is required to compile $PACKAGE_NAME.  You should consider updating
321*** your C library as it is too old.  Alternatively you might install
322*** a specific library implementing the (v)snprintf family of functions.
323*** Searching the web should give you appropriate pointers.
324***
325*** In case you want to try compiling $PACKAGE_NAME while your system lacks
326*** this function (meaning that compilation *will* fail unless you provide
327*** a replacement function), try the --disable-vsnprintf-check option.
328])
329    ]
330  )
331fi
332
333# getcwd or its equivalent with getenv <unistd.h>
334AC_LANG_PUSH(C)
335AC_CHECK_FUNCS([getcwd],
336  [],
337  [
338    AC_MSG_CHECKING([for working getenv("PWD")])
339    AC_RUN_IFELSE(
340      [
341        AC_LANG_SOURCE(
342[#include <stdlib.h>
343int main(void) { return (getenv("PWD") == NULL); }]
344        )
345      ],
346      [AC_MSG_RESULT([yes])],
347      [
348        AC_MSG_RESULT([no])
349        AC_MSG_NOTICE([I/O restriction code will be disabled])
350        enable_io_restrictions="no"
351      ],
352      [
353        AC_MSG_RESULT([cross-compiling])
354        AC_MSG_NOTICE([I/O restriction code will be disabled])
355        enable_io_restrictions="no"
356      ]
357    )
358  ]
359)
360AC_LANG_POP(C)
361
362# readlink <unistd.h>
363if test x"$enable_io_restrictions" != x"no"; then
364  AC_CHECK_FUNCS([readlink],
365    [],
366    [
367      AC_MSG_NOTICE([I/O restriction code will be disabled])
368      enable_io_restrictions="no"
369    ]
370  )
371fi
372
373# gettimeofday <sys/time.h>
374AC_CHECK_FUNCS([gettimeofday],
375  [AC_DEFINE([PRECISION_TIMER_AVAILABLE], [1], [Precision timer.])],
376  [AC_DEFINE([PRECISION_TIMER_AVAILABLE], [0], [Precision timer.])]
377)
378
379
380###############################################################################
381
382AC_MSG_RESULT([
383Libraries
384---------])
385
386# Link with static library, update LDFLAGS.
387AC_MSG_CHECKING([whether to enable static linking])
388if test x"$enable_shared" = x"no"; then
389  AC_MSG_RESULT([yes])
390  POV_PROG_CXX_STATIC
391else
392  AC_MSG_RESULT([no])
393fi
394
395
396# libm
397AC_CHECK_LIB([m], [sin])
398
399
400# asinh and friends (requires libm)
401AC_CHECK_FUNCS([asinh],
402  [],
403  [AC_DEFINE([NEED_INVHYP], [], [Inverse hyperbolic functions.])]
404)
405
406
407# support for non-ieee compilers (requires libm)
408if test "$C99_COMPATIBLE_RADIOSITY" \
409|| test x"$ac_cv_sizeof_int" != x"4" \
410|| test x"$ac_cv_sizeof_float" != x"4"; then
411  AC_CHECK_FUNCS([copysign],
412    [],
413    [AC_MSG_ERROR([
414*** Cannot find the 'copysign' function required for non-ieee platform
415])]
416  )
417  if test -z "$C99_COMPATIBLE_RADIOSITY"; then  # auto-detection
418    AC_CHECK_FUNCS([ilogbf],
419      [AC_DEFINE([C99_COMPATIBLE_RADIOSITY], [2], [See source/octree.cpp for details.])],
420      [AC_CHECK_FUNCS([ilogb],
421         [AC_DEFINE([C99_COMPATIBLE_RADIOSITY], [4], [See source/octree.cpp for details.])],
422         [AC_CHECK_FUNCS([logbf],
423            [AC_DEFINE([C99_COMPATIBLE_RADIOSITY], [1], [See source/octree.cpp for details.])],
424            [AC_CHECK_FUNCS([logb],
425               [AC_DEFINE([C99_COMPATIBLE_RADIOSITY], [3], [See source/octree.cpp for details.])],
426               [AC_MSG_ERROR([
427*** Cannot find a 'logb' or equivalent function required for non-ieee platform
428])]
429             )]
430          )]
431       )]
432    )
433  else  # check value of C99_COMPATIBLE_RADIOSITY and function presence
434    case "$C99_COMPATIBLE_RADIOSITY" in
435      1) AC_CHECK_FUNCS([logbf],  [], [AC_MSG_ERROR([logbf not found])]) ;;
436      2) AC_CHECK_FUNCS([ilogbf], [], [AC_MSG_ERROR([ilogbf not found])]) ;;
437      3) AC_CHECK_FUNCS([logb],   [], [AC_MSG_ERROR([logb not found])]) ;;
438      4) AC_CHECK_FUNCS([ilogb],  [], [AC_MSG_ERROR([ilogb not found])]) ;;
439      *) AC_MSG_ERROR([Unsupported C99_COMPATIBLE_RADIOSITY value]) ;;
440    esac
441    AC_DEFINE_UNQUOTED([C99_COMPATIBLE_RADIOSITY],
442      [$C99_COMPATIBLE_RADIOSITY],
443      [See source/octree.cpp for details.]
444    )
445  fi
446fi
447
448
449# Let's try to use the -v compiler flag for better debugging.
450# Backup compiler flags first.
451pov_lib_save_cflags="$CFLAGS"
452if ! test `$CC -v < /dev/null 2> /dev/null`; then
453  CFLAGS="$CFLAGS -v"
454fi
455pov_lib_save_cxxflags="$CXXFLAGS"
456if ! test `$CXX -v < /dev/null 2> /dev/null`; then
457  CXXFLAGS="$CXXFLAGS -v"
458fi
459
460
461# don't even look for libvga/libX11 under Cygwin/MinGW
462if test x"$with_cygwin_dll" = x"no"; then
463
464  AC_MSG_NOTICE([X Window display will be disabled])
465  AC_MSG_NOTICE([SVGAlib display will be disabled])
466  AC_DEFINE([X_DISPLAY_MISSING], [], [Don't use the X Window System.])
467  pov_xwin_msg="disabled"
468  pov_svga_msg="disabled"
469
470else
471
472  # libvga and libvgagl
473  pov_svga_msg="disabled"
474  if test x"$with_svga" != x"no"; then
475    AC_CHECK_LIB([vga], [vga_init],
476      [AC_CHECK_LIB([vgagl], [gl_setcontextvga], [pov_svga_msg="enabled"], [], [-lvga])]
477    )
478    if test x"$pov_svga_msg" = x"disabled"; then
479      AC_MSG_NOTICE([SVGAlib display will be disabled])
480    fi
481  fi
482
483  # libX11
484  # Some systems seem to have libz in the X11 paths, so let's
485  # check for libX11 first.
486
487  # IRIX cannot find X headers/libraries, so set defaults.
488  case "$host" in
489    *irix*)
490      if test x"${x_includes}" = x"NONE"; then
491        x_includes="/usr/include"
492      fi
493      if test x"$x_libraries" = x"NONE"; then
494        x_libraries=""
495	# IRIX ld32/64 have weird use of -L flags (they exclude default paths)
496        # Add the content of LD_LIBRARY*_PATHS before system path
497        # Note that the first path is intentionnaly not prefixed with -L
498        if test x"$ac_cv_sizeof_long_int" = x"4"; then
499          if test "$LD_LIBRARYN32_PATH"; then
500            x_libraries=`echo $LD_LIBRARYN32_PATH | sed s,:," -L",g`
501          fi
502          x_libraries="$x_libraries -L/usr/lib32"
503        else
504          if test "$LD_LIBRARY64_PATH"; then
505            x_libraries=`echo $LD_LIBRARY64_PATH | sed s,:," -L",g`
506          fi
507          x_libraries="$x_libraries -L/usr/lib64"
508        fi
509      fi
510    ;;
511  esac
512
513  pov_xwin_msg="disabled"
514  AC_PATH_XTRA
515  if test x"$have_x" = x"yes"; then
516    AC_CHECK_LIB([X11], [XFlush],
517      [
518        # X_CFLAGS should actually be X_CPPFLAGS since it only adds -Idir
519        CPPFLAGS="$X_CFLAGS $CPPFLAGS"
520        LDFLAGS="$X_LIBS $LDFLAGS"
521        LIBS="$X_EXTRA_LIBS $X_PRE_LIBS -lX11 $LIBS"
522        pov_xwin_msg="enabled"
523      ],
524      [
525        AC_MSG_NOTICE([X Window display will be disabled])
526        AC_DEFINE([X_DISPLAY_MISSING],[1])
527      ],
528      [-L$x_libraries -lX11]
529    )
530  else
531    AC_MSG_NOTICE([X Window display will be disabled])
532  fi
533
534  if test x"$pov_xwin_msg" = x"enabled"; then
535    # Color icon and X Window cursor.
536    AC_CHECK_LIB([Xpm], [XpmCreatePixmapFromData])
537    AC_MSG_CHECKING([whether to enable the watch cursor])
538    if test x"$enable_watch_cursor" = x"yes"; then
539      AC_MSG_RESULT([yes])
540      AC_CHECK_FUNC([XCreateFontCursor],
541        [AC_DEFINE([USE_CURSOR], [], [Use a watch cursor while rendering.])],
542        [AC_MSG_NOTICE([watch cursor will be disabled])]
543      )
544    else
545      AC_MSG_RESULT([no])
546    fi
547  fi
548
549  ### Note from Warp <warp@tag.povray.org> :
550  # Using "-static" for static linking in Solaris causes a linkage error.
551  # For some reason the X libraries in Solaris are not designed for static
552  # linking. [...] So at least for Solaris the '-static' flag should
553  # definitely be turned off by default.
554  if test "$pov_cv_prog_cc_static" \
555  && test x"$ac_cv_lib_X11_XFlush" = x"yes"; then
556    case "$host" in
557      sparc-*)
558        AC_MSG_WARN([Using $pov_cv_prog_cc_static might cause a linkage error])
559      ;;
560    esac
561  fi
562
563fi  # with_cygwin_dll
564
565
566AC_MSG_CHECKING([for installed supporting libraries])
567if test x"$enable_lib_checks" != x"no"; then
568  AC_MSG_RESULT([yes])
569else
570  AC_MSG_RESULT([no, build them all])
571fi
572
573
574# Force the C compiler for testing the supporting libraries.
575# This may prevent build failure on some systems.
576AC_LANG_PUSH(C)
577
578
579# libz
580if test x"$enable_lib_checks" != x"no"; then
581  POV_CHECK_LIB([z], [$required_libz_version], [z],
582    [zlibVersion], [zlib.h], [zlibVersion()]
583  )
584fi
585if test x"$pov_check_lib" != x"ok"; then
586  if test x"$enable_lib_checks" != x"no"; then
587    AC_MSG_NOTICE([zlib will be built and statically linked to $PACKAGE_NAME])
588  fi
589  AC_CONFIG_SUBDIRS([libraries/zlib])
590  if test "$ac_cv_search_zlibVersion"; then
591    LIBS=`echo $LIBS | sed s,$ac_cv_search_zlibVersion,,g`
592  fi
593  INCZ="-I\$(top_srcdir)/libraries/zlib"
594  LIBZ="../libraries/zlib/libz.a"
595  export INCZ		# tell libpng and libtiff to use the provided zlib.
596fi
597AC_SUBST([INCZ])
598AC_SUBST([LIBZ])
599
600
601# libpng, depends on libz
602# if libz needs to be compiled, force compiling libpng as well
603if test x"$pov_check_lib" = x"ok"; then
604  if test x"$enable_lib_checks" != x"no"; then
605    # check libpng and update ${pov_check_lib}
606    POV_CHECK_LIB([png], [$required_libpng_version], [png12 png],
607      [png_get_libpng_ver], [png.h], [png_get_libpng_ver(NULL)]
608    )
609  fi
610elif test x"$enable_lib_checks" != x"no"; then
611  AC_MSG_CHECKING([for libpng])
612  AC_MSG_RESULT([forced by libz])
613fi
614if test x"$pov_check_lib" != x"ok"; then
615  if test x"$enable_lib_checks" != x"no"; then
616    AC_MSG_NOTICE([libpng will be built and statically linked to $PACKAGE_NAME])
617  fi
618  AC_CONFIG_SUBDIRS([libraries/png])
619  if test "$ac_cv_search_png_get_libpng_ver"; then
620    LIBS=`echo $LIBS | sed s,$ac_cv_search_png_get_libpng_ver,,g`
621  fi
622  INCPNG="-I\$(top_srcdir)/libraries/png"
623  LIBPNG="../libraries/png/libpng.a"
624fi
625AC_SUBST([INCPNG])
626AC_SUBST([LIBPNG])
627
628
629# libjpeg
630# always build it under cygwin which may use a custom jpeglib.h file
631case "$host" in
632  *cygwin*)
633    AC_MSG_CHECKING([for libjpeg])
634    AC_MSG_RESULT([forced by cygwin])
635  ;;
636
637  *)
638  if test x"$enable_lib_checks" != x"no"; then
639    POV_CHECK_LIBJPEG([$required_libjpeg_version])
640  fi
641  ;;
642esac
643if test x"$pov_check_libjpeg" != x"ok"; then
644  if test x"$enable_lib_checks" != x"no"; then
645    AC_MSG_NOTICE([libjpeg will be built and statically linked to $PACKAGE_NAME])
646  fi
647  AC_CONFIG_SUBDIRS([libraries/jpeg])
648  if test "$ac_cv_search_jpeg_std_error"; then
649    LIBS=`echo $LIBS | sed s,$ac_cv_search_jpeg_std_error,,g`
650  fi
651  INCJPEG="-I\$(top_srcdir)/libraries/jpeg"
652  LIBJPEG="../libraries/jpeg/libjpeg.a"
653  export INCJPEG	# tell libtiff to use the provided jpeg library.
654else
655  # create jversion.h in builddir
656  if ! test -d "./source"; then
657    mkdir ./source
658  fi
659  echo "#define JVERSION \"${pov_check_libjpeg_version}\"" > ./source/jversion.h
660fi
661AC_SUBST([INCJPEG])
662AC_SUBST([LIBJPEG])
663
664
665# libtiff, depends on libz and libjpeg
666if test -z "$INCZ"  &&  test -z "$INCJPEG"; then
667  if test x"$enable_lib_checks" != x"no"; then
668    POV_CHECK_LIBTIFF([$required_libtiff_version])
669  fi
670elif test x"$enable_lib_checks" != x"no"; then
671  AC_MSG_CHECKING([for libtiff])
672  if test "$INCZ"; then
673    AC_MSG_RESULT([forced by libz])
674  else
675    AC_MSG_RESULT([forced by libjpeg])
676  fi
677fi
678if test x"$pov_check_libtiff" != x"ok"; then
679  if test x"$enable_lib_checks" != x"no"; then
680    AC_MSG_NOTICE([libtiff will be built and statically linked to $PACKAGE_NAME])
681  fi
682  AC_CONFIG_SUBDIRS([libraries/tiff])
683  if test "$ac_cv_search_TIFFGetVersion"; then
684    LIBS=`echo $LIBS | sed s,$ac_cv_search_TIFFGetVersion,,g`
685  fi
686  INCTIFF="-I\$(top_srcdir)/libraries/tiff/libtiff -I\$(top_builddir)/libraries/tiff/libtiff"
687  LIBTIFF="../libraries/tiff/libtiff/libtiff.a"
688fi
689AC_SUBST([INCTIFF])
690AC_SUBST([LIBTIFF])
691
692
693# Revert to previous compiler (C++).
694AC_LANG_POP(C)
695
696
697# Restore initial compiler flags.
698CFLAGS="$pov_lib_save_cflags"
699CXXFLAGS="$pov_lib_save_cxxflags"
700
701
702###############################################################################
703
704AC_MSG_RESULT([
705Compiling
706---------])
707
708# Start with no flags at all, so back them up first.
709pov_comp_save_cflags="$CFLAGS"
710pov_comp_save_cxxflags="$CXXFLAGS"
711CFLAGS=
712CXXFLAGS=
713
714
715# Use pipes for communication between compilation stages.
716AC_MSG_CHECKING([whether to enable pipes for communications])
717if test x"$enable_pipe" = x"no"; then
718  AC_MSG_RESULT([no])
719else
720  AC_MSG_RESULT([yes])
721  pov_flags="-pipe"
722  POV_PROG_CXX_FLAGS([$pov_flags],
723    [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
724  )
725fi
726
727
728# Language.
729
730# don't use -ansi since it can make compilation fail (e.g. on cygwin).
731#POV_PROG_CXX_FLAGS([-ansi], [], [POV_PROG_CXX_FLAGS([-Aa])])
732
733# -w would prevent all warning messages, even if -W... is given later on.
734# we don't want to clutter the compiling with lots of warnings.
735#POV_PROG_CXX_FLAGS([-W])
736#POV_PROG_CXX_FLAGS([-Wall], [], [POV_PROG_CXX_FLAGS([-fullwarn])])
737POV_PROG_CXX_FLAGS([-Wno-multichar])
738
739
740# I/O restrictions.
741AC_MSG_CHECKING([whether to enable I/O restrictions])
742if test x"$enable_io_restrictions" = x"no"; then
743  AC_MSG_RESULT([no])
744  AC_DEFINE([IO_RESTRICTIONS_DISABLED], [1], [I/O restrictions.])
745else
746  AC_MSG_RESULT([yes])
747  AC_DEFINE([IO_RESTRICTIONS_DISABLED], [0], [I/O restrictions.])
748fi
749
750
751# Compile with debugging code.
752
753AC_MSG_CHECKING([whether to enable debugging])
754
755if test x"$enable_debug" = x"yes"; then
756  AC_MSG_RESULT([yes])
757  pov_flags="-g"
758  POV_PROG_CXX_FLAGS([$pov_flags],
759    [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
760    [AC_MSG_WARN([Cannot set debugging mode])]
761  )
762  AC_DEFINE([MEM_STATS], [2], [Memory statistics.])
763  AC_DEFINE([MEM_TRACE], [],  [Memory tracing.])
764  AC_DEFINE([MEM_GUARD], [],  [Memory guard.])
765  AC_DEFINE([MEM_TAG],   [],  [Memory tag.])
766else
767  AC_MSG_RESULT([no])
768  AC_DEFINE([MEM_STATS], [1], [Memory statistics.])
769fi
770
771
772# Compile for profiling.
773
774AC_MSG_CHECKING([whether to enable profiling])
775
776if test x"$enable_profile" = x"yes"; then
777  AC_MSG_RESULT([yes])
778  if test -z "$pov_cv_prog_cxx_flags_g"; then
779    pov_flags="-g"
780    POV_PROG_CXX_FLAGS([$pov_flags],
781      [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
782      [AC_MSG_WARN([Cannot set debugging mode])]
783    )
784  fi
785  pov_flags="-pg"
786  POV_PROG_CXX_FLAGS([$pov_flags],
787    [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
788    [AC_MSG_WARN([Cannot set profiling mode])]
789  )
790else
791  AC_MSG_RESULT([no])
792fi
793
794
795# Strip object files.
796
797AC_MSG_CHECKING([whether to enable stripping])
798
799if test x"$enable_strip" = x"yes"; then
800  if test x"$enable_debug" = x"yes" || test x"$enable_profile" = x"yes"; then
801    AC_MSG_RESULT([no, debugging/profiling mode is on])
802  else
803    AC_MSG_RESULT([yes])
804    pov_flags="-s"
805    POV_PROG_CXX_FLAGS([$pov_flags],
806      [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
807      [AC_MSG_WARN([Cannot set stripping mode])]
808    )
809  fi
810else
811  AC_MSG_RESULT([no])
812fi
813
814
815# Compile with optimizations.
816
817AC_MSG_CHECKING([whether to enable optimizations])
818
819if test x"$enable_optimiz" != x"no"; then
820
821  AC_MSG_RESULT([yes])
822
823  # don't try -fast (makes ICC fail when linking due to implied -ipo flag).
824  pov_flags="-O3"
825  POV_PROG_CXX_FLAGS([$pov_flags],
826    [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
827    [
828      pov_flags="-O2"
829      POV_PROG_CXX_FLAGS([$pov_flags],
830        [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
831        [
832          pov_flags="-O"
833          POV_PROG_CXX_FLAGS([$pov_flags],
834            [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
835          )
836        ]
837      )
838    ]
839  )
840
841  # gcc-specific flags.
842  if test x"$CXX" = x"g++"; then
843    if test x"$pov_cv_prog_cxx_flags_O" = x"yes"; then  # -O was set
844      for pov_flags in "-fexpensive-optimizations" "-finline-functions" "-foptimize-sibling-calls"; do
845        POV_PROG_CXX_FLAGS([$pov_flags],
846          [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
847        )
848      done
849    elif test x"$pov_cv_prog_cxx_flags_O2" = x"yes"; then  # -O2 was set
850      pov_flags="-finline-functions"
851      POV_PROG_CXX_FLAGS([$pov_flags],
852        [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
853      )
854    fi
855  # icc-specific flags.
856  elif test x"$CXX" = x"icc"; then
857    pov_flags="-ip"
858    POV_PROG_CXX_FLAGS([$pov_flags],
859      [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
860    )
861  fi
862
863  # Arch-specific tuning, alphabetically ordered for conveniency.
864  case "$host" in
865
866    alphaev*6*)
867      ### Suggested by Christopher Endsley <endsley@yokuts.csustan.edu> .
868      for pov_flags in "-mcpu=ev56" "-mno-soft-float"; do
869        POV_PROG_CXX_FLAGS([$pov_flags],
870          [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
871        )
872      done
873      ;;
874
875    i?86-* | k?-* | *86*64*)
876      if test x"$cross_compiling" != x"yes"; then
877        # head is used to handle SMP/HT systems
878        # check whether 'head -n 1' is supported; otherwise use older 'head -1'
879        if test -z "`head -n 1 /dev/null 2>&1`"; then
880          head_1='head -n 1'
881        else
882          head_1='head -1'
883        fi
884
885        if test -r /proc/cpuinfo ; then  # Linux
886          pov_cpuinfo=/proc/cpuinfo
887        elif test -r /compat/linux/proc/cpuinfo ; then # FreeBSD using linprocfs
888          pov_cpuinfo=/compat/linux/proc/cpuinfo
889        elif test "`dmesg 2> /dev/null`"; then  # FreeBSD 4.9 at least
890          pov_modelname=`dmesg | grep CPU | $head_1 | cut -d: -f2 | tr A-Z a-z`
891          pov_cpuflags=`dmesg | grep Features | $head_1 | cut -d'<' -f2 | sed 's/[,>]/ /g' | tr A-Z a-z`
892          pov_vendorid=`dmesg | grep Origin | $head_1 | cut -d'"' -f2`
893        fi
894      fi
895
896      if test "$pov_cpuinfo"; then
897        pov_modelname=`cat $pov_cpuinfo | grep 'model name' | $head_1 | cut -d: -f2 | tr A-Z a-z`
898        pov_cpuflags=`cat $pov_cpuinfo | grep flags | $head_1 | cut -d: -f2`
899        pov_cpuflags=`echo $pov_cpuflags`  # remove leading/trailing blanks
900        pov_vendorid=`cat $pov_cpuinfo | grep vendor_id | $head_1 | cut -d: -f2`
901        pov_vendorid=`echo $pov_vendorid`
902      fi
903
904      # log values
905      AC_TRY_COMMAND([echo pov_cpuinfo   = $pov_cpuinfo   > /dev/null])
906      AC_TRY_COMMAND([echo pov_modelname = $pov_modelname > /dev/null])
907      AC_TRY_COMMAND([echo pov_vendorid  = $pov_vendorid  > /dev/null])
908      AC_TRY_COMMAND([echo pov_cpuflags  = $pov_cpuflags  > /dev/null])
909
910      for flag in $pov_cpuflags ; do
911        case "$flag" in
912          sse)
913            pov_flags="-m$flag"
914            POV_PROG_CXX_FLAGS([$pov_flags],
915              [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
916            )
917            pov_flags="-mfpmath=$flag"
918            POV_PROG_CXX_FLAGS([$pov_flags],
919              [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
920            )
921            ;;
922          sse?)  # sse2, sse3
923            pov_flags="-m$flag"
924            POV_PROG_CXX_FLAGS([$pov_flags],
925              [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
926            )
927            ;;
928        esac
929      done
930
931      if test -z "$pov_arch"; then
932        case "$host" in
933          i486-*)         pov_arch="i486";;
934          i586-*)         pov_arch="pentium";;  # for GCC / ICC
935          i686-*|i386-*)  # FreeBSD seems to only report i386
936            pov_cpu=${pov_modelname:-`uname -p 2> /dev/null`}
937            case "$pov_cpu" in
938              # Intel
939              *pentium*4*|*xeon*)  pov_arch="pentium4";;  # for GCC / ICC
940              *pentium*mmx*)       pov_arch="pentium";;   # catch this first
941              *pentium*m*)
942                if test x"$CXX" = x"icc"; then
943                  pov_arch="pentium4"
944                else
945                  pov_arch="pentium-m"
946                fi
947                ;;
948              *pentium*iii*|*celeron*)  # assume all celerons belong here
949                if test x"$CXX" = x"icc"; then
950                  pov_arch="pentiumiii"
951                else
952                  pov_arch="pentium3"
953                fi
954                ;;
955              *pentium*ii*)
956                if test x"$CXX" = x"icc"; then
957                  pov_arch="pentiumii"
958                else
959                  pov_arch="pentium2"
960                fi
961                ;;
962              *pentium*pro*)       pov_arch="pentiumpro";;  # for GCC / ICC
963              *pentium*)           pov_arch="pentium";;     # for GCC / ICC
964              # AMD
965              *athlon*xp*)         pov_arch="athlon-xp";;
966              *athlon*mp*)         pov_arch="athlon-mp";;
967              *athlon*|*duron*)    pov_arch="athlon";;
968              # others
969              *)                   pov_arch="i686";;  # don't support true i386
970            esac
971            pov_arch_fallback="i686"
972            ;;
973          k6-*)           pov_arch="k6"; pov_arch_fallback="i686";;
974          k7-*)           pov_arch="k7"; pov_arch_fallback="i686";;
975          k8-*|x86_64-*)  pov_arch="k8"; pov_arch_fallback="i686";;
976          *)              pov_arch="unknown";;
977        esac
978      fi
979      if test x"$pov_arch" != x"unknown"; then
980        POV_PROG_CXX_FLAGS([-march=$pov_arch -mtune=$pov_arch],
981          [
982            if test "$subdirs"; then
983              {
984                POV_PROG_CC_FLAGS([-march=$pov_arch -mtune=$pov_arch],
985                  [],
986                  [POV_PROG_CC_FLAGS([-march=$pov_arch -mcpu=$pov_arch])]
987                )
988              }
989            fi
990          ],
991          [
992            POV_PROG_CXX_FLAGS([-march=$pov_arch -mcpu=$pov_arch],
993              [
994                if test "$subdirs"; then
995                  { POV_PROG_CC_FLAGS([-march=$pov_arch -mcpu=$pov_arch]) }
996                fi
997              ],
998              [
999                POV_PROG_CXX_FLAGS([-march=$pov_arch],
1000                  [
1001                    if test "$subdirs"; then
1002                      { POV_PROG_CC_FLAGS([-march=$pov_arch]) }
1003                    fi
1004                  ],
1005                  [
1006                    if test "$pov_arch_fallback"; then
1007                      {
1008                        POV_PROG_CXX_FLAGS([-march=$pov_arch_fallback],
1009                          [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_arch_fallback]) }; fi]
1010                        )
1011                      }
1012                    fi
1013                  ]
1014                )
1015              ]
1016            )
1017          ]
1018        )
1019      fi
1020
1021      # gcc says -malign-double makes no sense in the 64bit mode and reject it
1022      for pov_flags in "-malign-double" "-minline-all-stringops"; do
1023        POV_PROG_CXX_FLAGS([$pov_flags],
1024          [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
1025        )
1026      done
1027      ;;
1028
1029    *irix*)
1030      pov_flags="-mips4"
1031      POV_PROG_CXX_FLAGS([$pov_flags],
1032        [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi],
1033        [
1034          pov_flags="-mips2"
1035          POV_PROG_CXX_FLAGS([$pov_flags],
1036            [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
1037          )
1038        ]
1039      )
1040      ;;
1041
1042    powerpc*)
1043      ### Suggested by Thorsten Froehlich <thorsten@trf.de> :
1044      # Note that the different parameters for mcpu and mtune are intentional:
1045      # The PPC 7450 processor has a much longer pipeline and thus scheduling
1046      # for that pipeline always yields good results even on processors with
1047      # a shorter pipeline.  On the other hand, most PowerPC processors only
1048      # support the instructions also found in the PPC 750 processor (aka G3).
1049      # That is why it is selected in the mcpu parameter.  Using 7450 (aka G4+)
1050      # in mcpu would make the code incompatible with anything prior to the
1051      # PPC 7400 (aka G4).  To be precise, the vector instructions are new
1052      # in the four digit model number PowerPC processors (aka G4), but gcc
1053      # cannot (as of February 2003) use them automatically anyway! [trf]
1054      for pov_flags in "-mpowerpc" "-mcpu=750 -mtune=7450" "-mmultiple" "-mstring" "-mfused-madd"; do
1055        POV_PROG_CXX_FLAGS([$pov_flags],
1056          [if test "$subdirs"; then { POV_PROG_CC_FLAGS([$pov_flags]) }; fi]
1057        )
1058      done
1059      ;;
1060
1061    sparc-*)
1062      # Commented out for now.
1063      #POV_PROG_CXX_FLAGS([-march=ultrasparc])
1064      #POV_PROG_CXX_FLAGS([-mvis])
1065      ;;
1066
1067  esac
1068
1069else
1070
1071  AC_MSG_RESULT([no])
1072
1073fi
1074
1075
1076# Add flags specified at the command line.
1077CXXFLAGS="$CXXFLAGS $pov_comp_save_cxxflags"
1078
1079# Flags for supporting libraries.
1080CFLAGS="$CFLAGS $pov_comp_save_cflags"
1081export CFLAGS CPPFLAGS LDFLAGS
1082
1083
1084###############################################################################
1085
1086AC_MSG_RESULT([
1087Makefiles
1088---------])
1089
1090# Supporting libraries to be included in the compilation/linking process.
1091AC_SUBST([POVLIBS])
1092if test "$LIBZ"; then
1093  POVLIBS="zlib"
1094fi
1095if test "$LIBPNG"; then
1096  POVLIBS="$POVLIBS png"
1097fi
1098if test "$LIBJPEG"; then
1099  POVLIBS="$POVLIBS jpeg"
1100fi
1101# Does not compile all in tiff/ but only the library itself.
1102# This is required to avoid errors due to some dependencies in tiff/tools .
1103if test "$LIBTIFF"; then
1104  POVLIBS="$POVLIBS tiff/port tiff/libtiff"
1105fi
1106
1107# For 'make distclean' to clean also the supporting libraries.
1108# It is different from POVLIBS since tiff/libtiff has no distclean target.
1109POVLIBSCLEAN=`echo $POVLIBS | sed -e 's,tiff/port,,g' -e 's,/libtiff,,g'`
1110AC_SUBST([POVLIBSCLEAN])
1111
1112AC_CONFIG_FILES([\
1113  Makefile \
1114  libraries/Makefile \
1115  source/base/Makefile \
1116  source/frontend/Makefile \
1117  source/Makefile \
1118  unix/Makefile \
1119])
1120
1121
1122###############################################################################
1123
1124if test "$subdirs"; then
1125  AC_CONFIG_COMMANDS([config.log],
1126    [AC_MSG_RESULT([
1127Supporting libraries
1128--------------------])]
1129  )
1130fi
1131AC_OUTPUT
1132
1133
1134###############################################################################
1135
1136if test x"$enable_io_restrictions" = x"no"; then
1137  pov_io_msg="disabled"
1138else
1139  pov_io_msg="enabled"
1140fi
1141AC_MSG_RESULT([
1142===============================================================================
1143$PACKAGE_NAME $PACKAGE_VERSION has been configured with the following features:
1144  I/O restrictions: ${pov_io_msg}
1145  X Window display: ${pov_xwin_msg}
1146  SVGAlib display : ${pov_svga_msg}
1147
1148Type 'make' to build, and 'make install' to install all files in the hierarchy
1149${prefix}])
1150
1151if test "$pov_warn_path"; then
1152  echo "
1153WARNING: configure has detected that the list of search paths specified
1154by the following environment variables
1155 $pov_warn_path
1156erroneously contain the \".\" directory, which may cause a build failure.
1157In order to build POV-Ray successfully, the package has been configured
1158with all \".\" directory entries removed from the variables above.  You're
1159strongly advised to correct your configuration accordingly."
1160fi
1161
1162AC_MSG_RESULT(
1163[===============================================================================
1164])
1165