1dnl -*- sh -*-
2dnl the "configure" script is made from this by running GNU "autoconf"
3dnl
4dnl Configuration script for the Fast Light Tool Kit (FLTK).
5dnl
6dnl Copyright 1998-2021 by Bill Spitzak and others.
7dnl
8dnl This library is free software. Distribution and use rights are outlined in
9dnl the file "COPYING" which should have been included with this file.  If this
10dnl file is missing or damaged, see the license at:
11dnl
12dnl     https://www.fltk.org/COPYING.php
13dnl
14dnl Please see the following page on how to report bugs and issues:
15dnl
16dnl      https://www.fltk.org/bugs.php
17dnl
18
19dnl We need at least autoconf 2.50...
20AC_PREREQ([2.50])
21
22dnl Required file in package...
23AC_INIT
24AC_CONFIG_SRCDIR([src/Fl.cxx])
25
26AC_CANONICAL_HOST
27
28dnl Do not automatically add "-g" to compiler options...
29dnl This must be _before_ "Find compiler commands..."
30ARCHFLAGS="${ARCHFLAGS:=}"
31CFLAGS="${CFLAGS:=}"
32CPPFLAGS="${CPPFLAGS:=}"
33CXXFLAGS="${CXXFLAGS:=}"
34DSOFLAGS="${DSOFLAGS:=}"
35LDFLAGS="${LDFLAGS:=}"
36OPTIM="${OPTIM:=}"
37
38dnl Find compiler commands...
39AC_PROG_CC
40AC_PROG_CXX
41
42dnl So --with-archflags option is used during "checking size of long"
43case $host_os in
44    darwin*)
45	if test "x$with_archflags" != x ; then
46	    CFLAGS="$CFLAGS $with_archflags"
47	fi
48	;;
49esac
50
51dnl FLTK library versions...
52FLTK_VERSION_MAJOR=1
53FLTK_VERSION_MINOR=3
54FLTK_VERSION_PATCH=8
55FL_DSO_VERSION=${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}
56FL_ABI_VERSION=${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}.0
57FLTK_VERSION=${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}.${FLTK_VERSION_PATCH}
58
59AC_SUBST(FLTK_VERSION_MAJOR)
60AC_SUBST(FLTK_VERSION_MINOR)
61AC_SUBST(FLTK_VERSION_PATCH)
62AC_SUBST(FL_DSO_VERSION)
63AC_SUBST(FL_ABI_VERSION)
64AC_SUBST(FLTK_VERSION)
65
66AC_SUBST(ARCHFLAGS)
67AC_SUBST(OPTIM)
68
69dnl FLTK build options to be used in Makefiles (defined in makeinclude)
70USEMMFILES="No"
71
72dnl OS-specific pre-tests...
73dnl host_os_gui equals $host_os unless we target Cygwin or Darwin in combination with X11.
74host_os_gui=$host_os
75case $host_os in
76    cygwin*)
77	# Handle Cygwin option *first*, before all other tests.
78	AC_ARG_ENABLE(cygwin, [  --enable-cygwin         use the Cygwin libraries [[default=no]]])
79	AC_ARG_ENABLE(x11,    [  --enable-x11            with Cygwin or Mac OS, use X11 [[default=no]]])
80	if test x$enable_cygwin = xyes; then
81	    # we target Cygwin in combination with X11
82	    if test x$enable_x11 = xyes; then
83		host_os_gui="X11$host_os"
84	    fi
85	fi
86	;;
87    darwin*)
88	if test x$enable_x11 = xyes; then
89		host_os_gui="X11"
90		OPTIM="-U__APPLE__ -mmacosx-version-min=10.9 -D_LIBCPP_HAS_THREAD_API_PTHREAD $OPTIM"
91	fi
92	;;
93   *)
94   ;;
95esac
96
97dnl Define the libraries and link options we will need.
98LINKFLTK="../lib/libfltk.a"
99LINKFLTKFORMS="../lib/libfltk_forms.a"
100LINKFLTKGL="../lib/libfltk_gl.a"
101LINKFLTKIMG="../lib/libfltk_images.a"
102GLDEMOS="gldemos"
103
104LIBEXT=".a"
105LIBNAME="../lib/libfltk.a"
106FLLIBNAME="../lib/libfltk_forms.a"
107GLLIBNAME="../lib/libfltk_gl.a"
108IMGLIBNAME="../lib/libfltk_images.a"
109CAIROLIBNAME="../lib/libfltk_cairo.a"
110
111LIBBASENAME="libfltk.a"
112FLLIBBASENAME="libfltk_forms.a"
113GLLIBBASENAME="libfltk_gl.a"
114IMGLIBBASENAME="libfltk_images.a"
115CAIROLIBBASENAME="libfltk_cairo.a"
116
117dnl Check for Cairo library unless disabled...
118CAIRODIR=""
119CAIROFLAGS=""
120LINKFLTKCAIRO=""
121FLTKCAIROOPTION=""
122CAIROLIBS=""
123
124AC_ARG_ENABLE(cairoext,[  --enable-cairoext       use fltk code instrumentation for cairo extended use [[default=no]]])
125AC_ARG_ENABLE(cairo,   [  --enable-cairo          use lib Cairo [[default=no]]])
126
127if test x$enable_cairoext = xyes; then
128	  AC_DEFINE(FLTK_USE_CAIRO)
129	  AC_DEFINE(FLTK_HAVE_CAIRO)
130	  dnl FIXME This part should be fixed so configure do not depend on
131	  dnl we do not rely on pkg-config .
132	  CAIRODIR="cairo"
133	  CAIROFLAGS="`pkg-config --cflags cairo`"
134	  CAIROLIBS="-lcairo -lpixman-1"
135	  CXXFLAGS="$CAIROFLAGS $CXXFLAGS"
136	  LINKFLTKCAIRO="../lib/libfltk_cairo.a"
137	  FLTKCAIROOPTION="-L ../cairo -lfltk_cairo$SHAREDSUFFIX"
138	  LIBS="$CAIROLIBS $LIBS"
139	  dnl $LINKFLTKCAIRO
140	  LINKFLTK+=" $LINKFLTKCAIRO"
141else
142    if test x$enable_cairo = xyes; then
143	  AC_DEFINE(FLTK_HAVE_CAIRO)
144	  dnl FIXME This part should be fixed so configure do not depend on
145	  dnl we do not rely on pkg-config .
146	  CAIRODIR="cairo"
147	  CAIROFLAGS="`pkg-config --cflags cairo`"
148	  CAIROLIBS="-lcairo -lpixman-1"
149	  CXXFLAGS="$CAIROFLAGS $CXXFLAGS"
150	  LINKFLTKCAIRO="../lib/libfltk_cairo.a"
151	  FLTKCAIROOPTION="-L ../cairo -lfltk_cairo$SHAREDSUFFIX"
152    fi
153fi
154
155AC_SUBST(CAIRODIR)
156AC_SUBST(CAIROFLAGS)
157AC_SUBST(CAIROLIBS)
158AC_SUBST(LINKFLTKCAIRO)
159AC_SUBST(FLTKCAIROOPTION)
160
161AC_SUBST(FLLIBNAME)
162AC_SUBST(GLDEMOS)
163AC_SUBST(GLLIBNAME)
164AC_SUBST(IMGLIBNAME)
165AC_SUBST(CAIROLIBNAME)
166AC_SUBST(LIBEXT)
167AC_SUBST(LIBNAME)
168AC_SUBST(LINKFLTK)
169AC_SUBST(LINKFLTKFORMS)
170AC_SUBST(LINKFLTKGL)
171AC_SUBST(LINKFLTKIMG)
172
173AC_SUBST(LIBBASENAME)
174AC_SUBST(FLLIBBASENAME)
175AC_SUBST(GLLIBBASENAME)
176AC_SUBST(IMGLIBBASENAME)
177AC_SUBST(CAIROLIBBASENAME)
178
179has_abiversion=""
180AC_ARG_WITH(abiversion,
181[  --with-abiversion       Build with FL_ABI_VERSION, e.g. 10304 for FLTK 1.3.4])
182has_abiversion="$with_abiversion"
183if test "$has_abiversion" = "yes" ; then
184 has_abiversion=""
185else
186 if test "$has_abiversion" = "no" ; then
187  has_abiversion=""
188 fi
189fi
190if test ! "$has_abiversion" = "" ; then
191 AC_DEFINE_UNQUOTED(FL_ABI_VERSION, [$has_abiversion], [define to FL_ABI_VERSION])
192fi
193
194dnl Handle compile-time options...
195AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging [[default=no]]])
196if test x$enable_debug = xyes; then
197    DEBUGFLAG="-g "
198else
199    DEBUGFLAG=""
200fi
201
202AC_ARG_ENABLE(cp936, [  --enable-cp936          turn on CP936 [[default=no]]])
203if test x$enable_cp936 = xyes; then
204    CFLAGS="$CFLAGS -DCP936"
205fi
206
207AC_ARG_ENABLE(gl, [  --enable-gl             turn on OpenGL support [[default=yes]]])
208
209AC_ARG_ENABLE(shared, [  --enable-shared         turn on shared libraries [[default=no]]])
210if test x$enable_shared = xyes; then
211    PICFLAG=1
212    SHAREDSUFFIX=""
213    FLUID="fluid-shared"
214
215    case $host_os in
216	darwin*)
217	    DSONAME="libfltk.$FL_DSO_VERSION.dylib"
218	    FLDSONAME="libfltk_forms.$FL_DSO_VERSION.dylib"
219	    GLDSONAME="libfltk_gl.$FL_DSO_VERSION.dylib"
220	    IMGDSONAME="libfltk_images.$FL_DSO_VERSION.dylib"
221	    CAIRODSONAME="libfltk_cairo.$FL_DSO_VERSION.dylib"
222	    DSOCOMMAND="\$(CXX) \$(ARCHFLAGS) \$(DSOFLAGS) -dynamiclib -lc -o"
223	    ;;
224
225	solaris*)
226	    DSONAME="libfltk.so.$FL_DSO_VERSION"
227	    FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
228	    GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
229	    IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
230	    CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
231	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -h \$@ \$(LDLIBS) -G $DEBUGFLAG -o"
232	    if test "x$libdir" != "x/usr/lib"; then
233		    DSOLINK="-R$libdir"
234	    fi
235	    ;;
236	hpux*)
237	    DSONAME="libfltk.sl.$FL_DSO_VERSION"
238	    FLDSONAME="libfltk_forms.sl.$FL_DSO_VERSION"
239	    GLDSONAME="libfltk_gl.sl.$FL_DSO_VERSION"
240	    IMGDSONAME="libfltk_images.sl.$FL_DSO_VERSION"
241	    CAIRODSONAME="libfltk_cairo.sl.$FL_DSO_VERSION"
242	    DSOCOMMAND="ld \$(DSOFLAGS) -b -z +h \$@ $DEBUGFLAG -o"
243	    if test "x$libdir" != "x/usr/lib"; then
244		    DSOLINK="-Wl,-rpath,$libdir"
245	    fi
246	    ;;
247	irix*)
248	    DSONAME="libfltk.so.$FL_DSO_VERSION"
249	    FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
250	    GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
251	    IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
252	    CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
253	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@,-set_version,sgi1.1 \$(LDLIBS) -shared $DEBUGFLAG -o"
254	    if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib32" -a "x$libdir" != "x/usr/lib64"; then
255		    DSOLINK="-Wl,-rpath,$libdir"
256	    fi
257	    ;;
258	osf*)
259	    DSONAME="libfltk.so.$FL_DSO_VERSION"
260	    FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
261	    GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
262	    IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
263	    CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
264	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared $DEBUGFLAG -o"
265	    if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib32"; then
266		    DSOLINK="-Wl,-rpath,$libdir"
267	    fi
268	    ;;
269	linux* | *bsd*)
270	    DSONAME="libfltk.so.$FL_DSO_VERSION"
271	    FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
272	    GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
273	    IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
274	    CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
275	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared -fPIC $DEBUGFLAG -o"
276
277	    # See if the compiler supports -fvisibility...
278	    AC_CACHE_CHECK([if the compiler supports -fvisibility],
279		ac_cv_cxx_fvisibility, [
280		    OLDCXXFLAGS="$CXXFLAGS"
281		    CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
282		    AC_LANG_PUSH([C++])
283		    AC_COMPILE_IFELSE(
284			[AC_LANG_PROGRAM([[]], [[]])],
285			[ac_cv_cxx_fvisibility=yes],
286			[ac_cv_cxx_fvisibility=no])
287		    CXXFLAGS="$OLDCXXFLAGS"
288		    AC_LANG_POP([])
289	    ])
290	    if test x"$ac_cv_cxx_fvisibility" = xyes; then
291		OPTIM="$OPTIM -fvisibility=hidden"
292	    fi
293
294	    # See if the compiler supports -fvisibility-inlines-hidden...
295	    AC_CACHE_CHECK([if the compiler supports -fvisibility-inlines-hidden],
296		ac_cv_cxx_fvisibility_inlines, [
297		    OLDCXXFLAGS="$CXXFLAGS"
298		    CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden"
299		    AC_LANG_PUSH([C++])
300		    AC_COMPILE_IFELSE(
301			[AC_LANG_PROGRAM([[]], [[]])],
302			[ac_cv_cxx_fvisibility_inlines=yes],
303			[ac_cv_cxx_fvisibility_inlines=no])
304		    CXXFLAGS="$OLDCXXFLAGS"
305		    AC_LANG_POP([])
306	    ])
307	    if test x"$ac_cv_cxx_fvisibility_inlines" = xyes; then
308		CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden"
309	    fi
310
311	    if test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib64"; then
312		    DSOLINK="-Wl,-rpath,$libdir"
313	    fi
314	    ;;
315	aix*)
316	    DSONAME="libfltk_s.a"
317	    FLDSONAME="libfltk_forms_s.a"
318	    GLDSONAME="libfltk_gl_s.a"
319	    IMGDSONAME="libfltk_images_s.a"
320	    CAIRODSONAME="libfltk_cairo_s.a"
321	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-bexpall,-bM:SRE,-bnoentry -o"
322	    SHAREDSUFFIX="_s"
323	    ;;
324	cygwin* | mingw*)
325	    PICFLAG=0
326	    if test x$enable_cygwin != xyes; then
327		DSONAME="mgwfltknox-$FL_DSO_VERSION.dll"
328		FLDSONAME="mgwfltknox_forms-$FL_DSO_VERSION.dll"
329		GLDSONAME="mgwfltknox_gl-$FL_DSO_VERSION.dll"
330		IMGDSONAME="mgwfltknox_images-$FL_DSO_VERSION.dll"
331		CAIRODSONAME="mgwfltknox_cairo-$FL_DSO_VERSION.dll"
332	    else
333		if test x$enable_x11 = xyes; then
334		    DSONAME="cygfltk-$FL_DSO_VERSION.dll"
335		    FLDSONAME="cygfltk_forms-$FL_DSO_VERSION.dll"
336		    GLDSONAME="cygfltk_gl-$FL_DSO_VERSION.dll"
337		    IMGDSONAME="cygfltk_images-$FL_DSO_VERSION.dll"
338		    CAIRODSONAME="cygfltk_cairo-$FL_DSO_VERSION.dll"
339		else
340		    DSONAME="cygfltknox-$FL_DSO_VERSION.dll"
341		    FLDSONAME="cygfltknox_forms-$FL_DSO_VERSION.dll"
342		    GLDSONAME="cygfltknox_gl-$FL_DSO_VERSION.dll"
343		    IMGDSONAME="cygfltknox_images-$FL_DSO_VERSION.dll"
344		    CAIRODSONAME="cygfltknox_cairo-$FL_DSO_VERSION.dll"
345		fi
346	    fi
347	    #-----------------------------------------------------------
348	    # -Wl,--enable-runtime-pseudo-reloc: See str 1585
349	    # appears to be necessary for older binutils versions < 2.16
350	    #-----------------------------------------------------------
351	    LDFLAGS="$LDFLAGS -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc"
352	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -shared \
353		-Wl,--whole-archive -Wl,--export-all-symbols \
354		-Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-import \
355		-Wl,--enable-auto-image-base -o \$@"
356	    ;;
357	*)
358	    AC_MSG_WARN([Shared libraries may not be supported. Trying -shared option with compiler.])
359	    DSONAME="libfltk.so.$FL_DSO_VERSION"
360	    FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
361	    GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
362	    IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
363	    CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
364	    DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared $DEBUGFLAG -o"
365	    ;;
366    esac
367
368    LINKSHARED="-L../src $FLTKCAIROOPTION -lfltk_images$SHAREDSUFFIX -lfltk_forms$SHAREDSUFFIX -lfltk$SHAREDSUFFIX"
369else
370    DSOCOMMAND="echo"
371    DSOLINK=""
372    DSONAME=""
373    FLDSONAME=""
374    GLDSONAME=""
375    IMGDSONAME=""
376    CAIRODSONAME=""
377    PICFLAG=0
378    SHAREDSUFFIX=""
379    FLUID="fluid"
380    LINKSHARED="$LINKFLTKCAIRO ../lib/libfltk_images.a ../lib/libfltk_forms.a ../lib/libfltk.a"
381fi
382
383dnl Define the fluid executable used when building the test programs.
384dnl In a native build we use the fluid executable created during the build,
385dnl in a cross-compilation we use `fluid' which must exist on the build system
386dnl and must be in the PATH, i.e. executable as 'fluid' (w/o $EXEEXT).
387if test "$fltk_cross_compiling" = "yes"; then
388  FLUID_BUILD="fluid"
389else
390  FLUID_BUILD="../fluid/fluid$EXEEXT"
391fi
392
393AC_SUBST(DSOCOMMAND)
394AC_SUBST(DSOFLAGS)
395AC_SUBST(DSOLINK)
396AC_SUBST(DSONAME)
397AC_SUBST(FLDSONAME)
398AC_SUBST(GLDSONAME)
399AC_SUBST(IMGDSONAME)
400AC_SUBST(CAIRODSONAME)
401AC_SUBST(SHAREDSUFFIX)
402AC_SUBST(LINKSHARED)
403AC_SUBST(FLUID)
404AC_SUBST(FLUID_BUILD)
405
406AC_ARG_ENABLE(threads, [  --enable-threads        enable multi-threading support [[default=yes]]])
407
408AC_ARG_WITH(optim, [  --with-optim="flags"    use custom optimization flags])
409
410AC_ARG_WITH(archflags, [  --with-archflags="flags"
411			  use custom architecture flags
412			  (possible Mac OS X values include -arch i386, -arch x86_64, -arch ppc)],
413    ARCHFLAGS="$withval")
414
415dnl Find commands...
416AC_PROG_INSTALL
417case $host_os in
418    osf*)
419	INSTALL="`pwd`/install-sh -c"
420	;;
421esac
422if test "$INSTALL" = "$ac_install_sh"; then
423    # Use full path to install-sh script...
424    INSTALL="`pwd`/install-sh -c"
425fi
426AC_PATH_PROG(NROFF,nroff)
427if test "x$NROFF" = "x:"; then
428    # Try groff instead of nroff...
429    AC_PATH_PROG(GROFF,groff)
430    if test "x$GROFF" = "x:"; then
431	NROFF="echo"
432    else
433	NROFF="$GROFF -T ascii"
434    fi
435fi
436AC_PATH_PROG(DOXYDOC,doxygen)
437
438dnl How do we make libraries?
439AC_PROG_RANLIB
440AC_PATH_TOOL(AR, ar)
441
442if test "x$AR" = "x:"; then
443    AC_MSG_ERROR([Configure could not find the library archiver, aborting.])
444fi
445
446if test "x$RANLIB" != "x:"; then
447    LIBCOMMAND="$AR cr"
448else
449    LIBCOMMAND="$AR crs"
450fi
451
452AC_SUBST(LIBCOMMAND)
453
454dnl how to compile (Windows) resource files
455dnl this will only be used to compile resources for Windows .exe files
456AC_PATH_TOOL(RC,windres)
457
458dnl Architecture checks...
459AC_CHECK_SIZEOF(short, 2)
460AC_CHECK_SIZEOF(int, 4)
461AC_CHECK_SIZEOF(long, 4)
462if test $ac_cv_sizeof_short -eq 2; then
463    AC_DEFINE(U16,unsigned short)
464fi
465if test $ac_cv_sizeof_int -eq 4; then
466    AC_DEFINE(U32,unsigned)
467else
468    if test $ac_cv_sizeof_long -eq 4; then
469	AC_DEFINE(U32,unsigned long)
470    fi
471fi
472case $host_os in
473    darwin*)
474	;;
475    *)
476	AC_C_BIGENDIAN
477
478	if test $ac_cv_sizeof_int -eq 8; then
479		AC_DEFINE(U64,unsigned)
480	else
481		if test $ac_cv_sizeof_long -eq 8; then
482			AC_DEFINE(U64,unsigned long)
483		fi
484	fi
485	;;
486esac
487
488dnl Does the C++ compiler support the bool type?
489AC_CACHE_CHECK(whether the compiler recognizes bool as a built-in type,
490    ac_cv_cxx_bool,[
491	AC_LANG_PUSH([C++])
492	AC_COMPILE_IFELSE(
493	    [AC_LANG_PROGRAM([[
494		int f(int  x){return 1;}
495		int f(char x){return 1;}
496		int f(bool x){return 1;}
497	      ]], [[
498		bool b = true;
499		return f(b);
500	    ]])],
501	    [ac_cv_cxx_bool=yes],
502	    [ac_cv_cxx_bool=no])
503	AC_LANG_POP([])
504    ])
505
506if test "$ac_cv_cxx_bool" != yes; then
507    CXXFLAGS="-Dbool=char -Dfalse=0 -Dtrue=1 $CXXFLAGS"
508fi
509
510dnl Standard headers and functions...
511AC_HEADER_DIRENT
512AC_CHECK_HEADERS([sys/select.h sys/stdtypes.h])
513
514dnl Do we have the POSIX compatible scandir() prototype?
515AC_CACHE_CHECK([whether we have the POSIX compatible scandir() prototype],
516    ac_cv_cxx_scandir_posix,[
517	AC_LANG_PUSH([C++])
518	AC_COMPILE_IFELSE(
519	    [AC_LANG_PROGRAM(
520		[[#include <dirent.h>
521		  int func (const char *d, dirent ***list, void *sort) {
522		    int n = scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort);
523		    return n;
524		  }
525		]], [[
526		]])],
527	    [ac_cv_cxx_scandir_posix=yes],
528	    [ac_cv_cxx_scandir_posix=no])
529	AC_LANG_POP([])
530    ])
531
532dnl Define both HAVE_SCANDIR... macros, if the POSIX compatible function is
533dnl available. Otherwise: check, whether any scandir prototype is available,
534dnl but dont use it on SunOS and QNX because of an incompatibility in pre-Y2K
535dnl SunOS scandir versions. We assume, though, that the POSIX compatible
536dnl version on newer SunOS/Solaris versions works as expected.
537if test "$ac_cv_cxx_scandir_posix" = yes; then
538    AC_DEFINE(HAVE_SCANDIR)
539    AC_DEFINE(HAVE_SCANDIR_POSIX)
540else
541    AC_CHECK_FUNC(scandir,[
542	case $host_os in
543	    solaris* | *qnx*)
544		AC_MSG_WARN([Not using $host_os scandir emulation function.])
545		;;
546	    *)
547		AC_DEFINE(HAVE_SCANDIR)
548		;;
549	esac])
550fi
551
552AC_CHECK_FUNC(vsnprintf,[
553    case $host_os in
554	hpux1020)
555	    AC_MSG_WARN([Not using built-in vsnprintf function because you are running HP-UX 10.20.])
556	    ;;
557	osf4)
558	    AC_MSG_WARN([Not using built-in vsnprintf function because you are running Tru64 4.0.])
559	    ;;
560	*)
561	    AC_DEFINE(HAVE_VSNPRINTF)
562	    ;;
563    esac])
564AC_CHECK_FUNC(snprintf,[
565    case $host_os in
566	hpux1020)
567	    AC_MSG_WARN([Not using built-in snprintf function because you are running HP-UX 10.20.])
568	    ;;
569	osf4)
570	    AC_MSG_WARN([Not using built-in snprintf function because you are running Tru64 4.0.])
571	    ;;
572	*)
573	    AC_DEFINE(HAVE_SNPRINTF)
574	    ;;
575    esac])
576AC_CHECK_HEADERS(strings.h)
577AC_CHECK_FUNCS(strcasecmp strlcat strlcpy)
578
579AC_CHECK_HEADERS(locale.h)
580AC_CHECK_FUNCS(localeconv)
581
582dnl FLTK library uses math library functions...
583AC_SEARCH_LIBS(pow, m)
584
585dnl Check for largefile support...
586AC_SYS_LARGEFILE
587
588dnl Define largefile options as needed...
589LARGEFILE=""
590if test x$enable_largefile != xno; then
591	LARGEFILE="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
592
593	if test x$ac_cv_sys_large_files = x1; then
594		LARGEFILE="$LARGEFILE -D_LARGE_FILES"
595	fi
596
597	if test x$ac_cv_sys_file_offset_bits = x64; then
598		LARGEFILE="$LARGEFILE -D_FILE_OFFSET_BITS=64"
599	fi
600fi
601AC_SUBST(LARGEFILE)
602
603dnl Check for "long long" support...
604AC_CACHE_CHECK(for long long int, ac_cv_c_long_long,
605	[if test "$GCC" = yes; then
606		ac_cv_c_long_long=yes
607	else
608		AC_COMPILE_IFELSE(
609		    [AC_LANG_PROGRAM([[]],
610			[[long long int i;]])],
611		    [ac_cv_c_long_long=yes],
612		    [ac_cv_c_long_long=no])
613	fi])
614
615if test $ac_cv_c_long_long = yes; then
616	AC_DEFINE(HAVE_LONG_LONG)
617fi
618
619dnl Check for dlopen/dlsym...
620AC_SEARCH_LIBS(dlsym, dl, AC_DEFINE(HAVE_DLSYM))
621AC_CHECK_HEADER(dlfcn.h, AC_DEFINE(HAVE_DLFCN_H))
622
623dnl Check for audio libraries...
624AUDIOLIBS=""
625
626case $host_os in
627    cygwin* | mingw*)
628	dnl Cygwin environment...
629	AUDIOLIBS="-lwinmm"
630	;;
631
632    darwin*)
633	AUDIOLIBS="-framework CoreAudio"
634	;;
635
636    *)
637	AC_CHECK_HEADER(alsa/asoundlib.h,
638	    AC_DEFINE(HAVE_ALSA_ASOUNDLIB_H)
639	    AUDIOLIBS="-lasound")
640	;;
641esac
642
643AC_SUBST(AUDIOLIBS)
644
645dnl Check for image libraries...
646SAVELIBS="$LIBS"
647IMAGELIBS=""
648STATICIMAGELIBS=""
649
650AC_SUBST(IMAGELIBS)
651AC_SUBST(STATICIMAGELIBS)
652
653# Handle the JPEG lib linking mode (use fltk local or system lib)
654# If --enable-(resp. --disable-)localjpeg parameter is not set by user
655# Then we check the JPEG lib usability, with result in sysjpeglib_ok variable
656AC_ARG_ENABLE(localjpeg, [  --enable-localjpeg      use local JPEG library [[default=auto]]])
657# Check for System lib use if automatic mode or --disable-localjpeg is requested
658sysjpeglib_ok=no
659sysjpeginc_ok=no
660if test x$enable_localjpeg != xyes; then
661    AC_CHECK_LIB(jpeg,jpeg_CreateCompress,
662	[AC_CHECK_HEADER(jpeglib.h,
663	    sysjpeginc_ok=yes)
664	    if test x$sysjpeginc_ok = xyes; then
665		sysjpeglib_ok=yes
666	    fi])
667fi
668# Now set the jpeg lib and include flags according to the requested mode and availability
669if test x$enable_localjpeg = xyes -o x$sysjpeglib_ok = xno; then
670    JPEGINC="-I../jpeg"
671    JPEG="jpeg"
672    IMAGELIBS="-lfltk_jpeg $IMAGELIBS"
673    STATICIMAGELIBS="\$libdir/libfltk_jpeg.a $STATICIMAGELIBS"
674    AC_DEFINE(HAVE_LIBJPEG)
675    #ac_cv_lib_jpeg_jpeg_CreateCompress=no # from ima: should not be necessary
676    # Finally, warn user if system lib was requested but not found
677    if test x$enable_localjpeg = xno; then
678	AC_MSG_WARN([Cannot find system jpeg lib or header: choosing the local lib mode.])
679    fi
680else
681    JPEGINC=""
682    JPEG=""
683    IMAGELIBS="-ljpeg $IMAGELIBS"
684    STATICIMAGELIBS="-ljpeg $STATICIMAGELIBS"
685    AC_DEFINE(HAVE_LIBJPEG)
686fi
687
688# Handle the ZLIB lib linking mode (use fltk local or system lib)
689# If --enable-(resp. --disable-)localzlib parameter is not set by user
690# Then we check the ZLIB lib usability, with result in syszlib_ok variable
691AC_ARG_ENABLE(localzlib, [  --enable-localzlib      use local ZLIB library [[default=auto]]])
692# Check for System lib use if automatic mode or --disable-localzlib is requested
693syszlib_ok=no
694syszinc_ok=no
695if test x$enable_localzlib != xyes; then
696    AC_CHECK_LIB(z,gzgets,
697	[AC_CHECK_HEADER(zlib.h,
698		syszinc_ok=yes)
699	if test x$syszinc_ok = xyes; then
700	    syszlib_ok=yes
701	fi])
702fi
703# Now set the Z lib and include flags according to the requested mode and availability
704if test x$enable_localzlib = xyes -o x$syszlib_ok = xno ; then
705    ZLIBINC="-I../zlib"
706    ZLIB="zlib"
707    LIBS="-lfltk_z $LIBS"
708    IMAGELIBS="-lfltk_z $IMAGELIBS"
709    STATICIMAGELIBS="\$libdir/libfltk_z.a $STATICIMAGELIBS"
710    AC_DEFINE(HAVE_LIBZ)
711    ac_cv_lib_z_gzgets=no # fc: is still necessary ?
712    # Finally, warn user if system lib was requested but not found
713    if test x$enable_localzlib = xno; then
714	AC_MSG_WARN([Cannot find system z lib or header: choosing the local lib mode.])
715    fi
716else
717    ZLIBINC=""
718    ZLIB=""
719    LIBS="-lz $LIBS"
720    IMAGELIBS="-lz $IMAGELIBS"
721    STATICIMAGELIBS="-lz $STATICIMAGELIBS"
722    AC_DEFINE(HAVE_LIBZ)
723fi
724
725# Handle the PNG lib linking mode (use fltk local or system lib)
726# If --enable-(resp. --disable-)localpng parameter is not set by user
727# Then we check the png lib usability with result in syspng_lib variable
728AC_ARG_ENABLE(localpng, [  --enable-localpng       use local PNG library  [[default=auto]]])
729
730# Now check if system lib is usable, we check Lib AND include availability with inc variant,
731# but only, if the builtin lib is not requested
732syspnglib_ok=no
733syspnginc_ok=no
734if test x$enable_localpng != xyes; then
735  AC_CHECK_LIB(png, png_read_info,
736    [AC_CHECK_HEADER(png.h,
737	AC_DEFINE(HAVE_PNG_H)
738	syspnginc_ok=yes)
739    AC_CHECK_HEADER(libpng/png.h,
740	AC_DEFINE(HAVE_LIBPNG_PNG_H)
741	syspnginc_ok=yes)
742    if test x$syspnginc_ok = xyes; then
743	syspnglib_ok=yes
744    fi])
745fi
746
747# The following is executed if the lib was not found usable or if local lib is required explicitly
748if test x$enable_localpng = xyes -o x$syspnglib_ok = xno ; then
749    PNGINC="-I../png"
750    PNG="png"
751    IMAGELIBS="-lfltk_png $IMAGELIBS"
752    STATICIMAGELIBS="\$libdir/libfltk_png.a $STATICIMAGELIBS"
753    AC_DEFINE(HAVE_LIBPNG)
754    AC_DEFINE(HAVE_PNG_H)
755    AC_DEFINE(HAVE_PNG_GET_VALID)
756    AC_DEFINE(HAVE_PNG_SET_TRNS_TO_ALPHA)
757    # Finally, warn user if system lib was requested but not found
758    if test x$enable_localpng = xno; then
759	AC_MSG_WARN([Cannot find system png lib or header: choosing the local lib mode.])
760    fi
761else
762    PNGINC=""
763    PNG=""
764    IMAGELIBS="-lpng $IMAGELIBS"
765    STATICIMAGELIBS="-lpng $STATICIMAGELIBS"
766    AC_DEFINE(HAVE_LIBPNG)
767    AC_CHECK_LIB(png,png_get_valid, AC_DEFINE(HAVE_PNG_GET_VALID))
768    AC_CHECK_LIB(png,png_set_tRNS_to_alpha, AC_DEFINE(HAVE_PNG_SET_TRNS_TO_ALPHA))
769fi
770
771AC_SUBST(JPEG)
772AC_SUBST(JPEGINC)
773AC_SUBST(PNG)
774AC_SUBST(PNGINC)
775AC_SUBST(ZLIB)
776AC_SUBST(ZLIBINC)
777
778dnl Restore original LIBS settings...
779LIBS="$SAVELIBS"
780
781dnl See if we need a .exe extension on executables...
782AC_EXEEXT
783
784dnl Check for pthreads for multi-threaded apps...
785have_pthread=no
786PTHREAD_FLAGS=""
787
788dnl Test whether we want to check for pthreads. We must not do it on Windows
789dnl unless we run under Cygwin with --enable-cygwin, since we always use
790dnl native threads on Windows (even if libpthread is available)
791check_pthread=yes
792case $host_os in
793    mingw*)
794	check_pthread=no
795	;;
796    cygwin*)
797	if test "x$enable_cygwin" != xyes; then
798	    check_pthread=no
799	fi
800	;;
801    *)
802	;;
803esac
804
805if test "x$enable_threads" != xno -a x$check_pthread = xyes; then
806    AC_CHECK_HEADERS(pthread.h)
807
808    if test x$ac_cv_header_pthread_h = xyes; then
809	dnl Check various threading options for the platforms we support
810	for flag in -lpthreads -lpthread -pthread; do
811	    AC_MSG_CHECKING([for pthread_create using $flag])
812	    SAVELIBS="$LIBS"
813	    LIBS="$flag $LIBS"
814	    AC_LINK_IFELSE(
815		[AC_LANG_PROGRAM(
816		    [[#include <pthread.h>]],
817		    [[pthread_create(0, 0, 0, 0);]])],
818		[have_pthread=yes],
819		[LIBS="$SAVELIBS"])
820	    AC_MSG_RESULT([$have_pthread])
821
822	    if test $have_pthread = yes; then
823		AC_DEFINE(HAVE_PTHREAD)
824		PTHREAD_FLAGS="-D_THREAD_SAFE -D_REENTRANT"
825
826		# Solaris requires -D_POSIX_PTHREAD_SEMANTICS to
827		# be POSIX-compliant... :(
828		case $host_os in
829		    solaris*)
830			PTHREAD_FLAGS="$PTHREAD_FLAGS -D_POSIX_PTHREAD_SEMANTICS"
831			;;
832		esac
833		break
834	    fi
835	done
836    fi
837fi
838
839AC_SUBST(PTHREAD_FLAGS)
840
841dnl Define OS-specific stuff...
842HLINKS=
843OSX_ONLY=:
844THREADS=
845
846AC_ARG_WITH(links, [  --with-links            make header links for common misspellings [[default=no]]])
847
848INSTALL_DESKTOP=""
849UNINSTALL_DESKTOP=""
850
851case $host_os_gui in
852    cygwin* | mingw*)
853	dnl Cygwin environment, using windows GDI ...
854	# Recent versions of Cygwin are seriously broken and the size
855	# checks don't work because the shell puts out \r\n instead of
856	# \n.  Here we just force U32 to be defined to "unsigned"...
857	AC_DEFINE(U32,unsigned)
858	CFLAGS="-mwindows -DWIN32 -DUSE_OPENGL32 $CFLAGS"
859	CXXFLAGS="-mwindows -DWIN32 -DUSE_OPENGL32 $CXXFLAGS"
860	LDFLAGS="-mwindows $LDFLAGS"
861	DSOFLAGS="-mwindows $DSOFLAGS"
862	LIBS="$LIBS -lole32 -luuid -lcomctl32"
863	if test "x$with_optim" = x; then
864	    dnl Avoid -Os optimization on Cygwin/MinGW
865	    with_optim="-O3"
866	fi
867
868	if test x$enable_gl != xno; then
869	    AC_CHECK_HEADER(GL/gl.h,
870		AC_DEFINE(HAVE_GL)
871		GLLIBS="-lopengl32")
872	    AC_CHECK_HEADER(GL/glu.h,
873		AC_DEFINE(HAVE_GL_GLU_H)
874		GLLIBS="-lglu32 $GLLIBS")
875	else
876	    LINKFLTKGL=""
877	    GLLIBNAME=""
878	    GLDSONAME=""
879	    GLDEMOS=""
880	fi
881
882	if test "x$enable_threads" != xno; then
883	    if test x$have_pthread = xyes; then
884		AC_DEFINE(HAVE_PTHREAD)
885	    fi
886	fi
887
888	THREADS="threads$EXEEXT"
889
890	# Don't make symlinks since Windows is not case sensitive.
891	if test "x$with_links" != xyes; then
892		HLINKS="#"
893	fi
894	;;
895
896    darwin*)
897	AC_DEFINE(__APPLE_QUARTZ__)
898
899	USEMMFILES="Yes"
900
901	# MacOS X uses Cocoa for graphics.
902	LIBS="$LIBS -framework Cocoa"
903
904	if test x$have_pthread = xyes; then
905	    AC_DEFINE(HAVE_PTHREAD)
906	    THREADS="threads$EXEEXT"
907	fi
908
909	if test x$enable_gl != xno; then
910	    AC_DEFINE(HAVE_GL)
911	    AC_DEFINE(HAVE_GL_GLU_H)
912	    GLLIBS="-framework OpenGL"
913	else
914	    LINKFLTKGL=""
915	    GLLIBNAME=""
916	    GLDSONAME=""
917	    GLDEMOS=""
918	fi
919
920	# Don't make symlinks because HFS+ is not case sensitive...
921	if test "x$with_links" != xyes; then
922		HLINKS="#"
923	fi
924
925	# Some steps are only done for OS X package management
926	OSX_ONLY=
927
928	# Install/Uninstall FLUID application
929	INSTALL_DESKTOP="install-osx"
930	UNINSTALL_DESKTOP="uninstall-osx"
931	;;
932
933    *)
934	# All others are UNIX/X11...
935	# This includes Cygwin target combined with X11
936	if test x$have_pthread = xyes; then
937	    AC_DEFINE(HAVE_PTHREAD)
938	    THREADS="threads$EXEEXT"
939	fi
940
941	dnl Check for X11...
942	AC_PATH_XTRA
943
944	if test x$no_x = xyes; then
945	    AC_MSG_ERROR([Configure could not find required X11 libraries, aborting.])
946	fi
947
948	if test "x$X_PRE_LIBS" != x; then
949	    AC_MSG_WARN([Ignoring libraries "$X_PRE_LIBS" requested by configure.])
950	fi
951
952	LIBS="$LIBS -lX11 $X_EXTRA_LIBS"
953	CFLAGS="$CFLAGS $X_CFLAGS"
954	CXXFLAGS="$CXXFLAGS $X_CFLAGS"
955	LDFLAGS="$X_LIBS $LDFLAGS"
956	DSOFLAGS="$X_LIBS $DSOFLAGS"
957	AC_DEFINE(USE_X11)
958	if test "x$x_includes" != x; then
959	    ac_cpp="$ac_cpp -I$x_includes"
960	fi
961
962	dnl Check for OpenGL unless disabled...
963	GLLIBS=
964
965	if test x$enable_gl != xno; then
966	    AC_SEARCH_LIBS(dlopen, dl)
967	    AC_CHECK_HEADER(GL/gl.h,
968		AC_CHECK_LIB(GL, glXMakeCurrent,
969		    [AC_DEFINE(HAVE_GL)
970		     GLLIBS="-lGL"],
971		    AC_CHECK_LIB(MesaGL, glXMakeCurrent,
972			[AC_DEFINE(HAVE_GL)
973			 GLLIBS="-lMesaGL"],,
974			[-lm]),
975		    [-lm])
976		AC_CHECK_LIB(GL, glXGetProcAddressARB,
977		    AC_DEFINE(HAVE_GLXGETPROCADDRESSARB),, [-lm])
978	    )
979	    AC_CHECK_HEADER(GL/glu.h,
980		AC_DEFINE(HAVE_GL_GLU_H)
981		if test x$ac_cv_lib_GL_glXMakeCurrent = xyes; then
982		    GLLIBS="-lGLU $GLLIBS"
983		fi
984		if test x$ac_cv_lib_MesaGL_glXMakeCurrent = xyes; then
985		    GLLIBS="-lMesaGLU $GLLIBS"
986		fi
987	    )
988
989	    if test x$ac_cv_lib_GL_glXMakeCurrent != xyes -a x$ac_cv_lib_MesaGL_glXMakeCurrent != xyes; then
990		LINKFLTKGL=""
991		GLLIBNAME=""
992		GLDSONAME=""
993		GLDEMOS=""
994	    fi
995	else
996	    LINKFLTKGL=""
997	    GLLIBNAME=""
998	    GLDSONAME=""
999	    GLDEMOS=""
1000	fi
1001
1002	dnl Check for Xinerama support unless disabled...
1003	AC_ARG_ENABLE(xinerama, [  --enable-xinerama       turn on Xinerama support [[default=yes]]])
1004
1005	xinerama_found=no
1006	if test x$enable_xinerama != xno; then
1007	    AC_CHECK_LIB(Xinerama, XineramaIsActive,
1008		[AC_DEFINE(HAVE_XINERAMA)
1009		 LIBS="-lXinerama $LIBS"
1010		 xinerama_found=yes])
1011	fi
1012
1013	dnl Check for the Xft library unless disabled...
1014	AC_ARG_ENABLE(xft, [  --enable-xft            turn on Xft support [[default=yes]]])
1015
1016	xft_found=no
1017	if test x$enable_xft != xno; then
1018            # Try pkg-config first (freetype2 deprecated freetype-config from some version on)
1019            AC_PATH_PROG(PKGCONFIG, pkg-config)
1020            FT_FLAGS=""
1021            if test "x$PKGCONFIG" != x; then
1022                FT_FLAGS="`$PKGCONFIG --cflags xft`"
1023                if test "x$FT_FLAGS" = x; then
1024                    FT_FLAGS="`$PKGCONFIG --cflags freetype2`"
1025                fi
1026            fi
1027            # if that failed, try freetype-config
1028            if test "x$FT_FLAGS" = x; then
1029                AC_PATH_PROG(FTCONFIG, freetype-config)
1030                if test "x$FTCONFIG" != x; then
1031                    FT_FLAGS="`$FTCONFIG --cflags`"
1032                else
1033                    # abort if both methods failed
1034                    AC_MSG_NOTICE([please install pkg-config or use 'configure --disable-xft'.])
1035                    AC_MSG_ERROR([Aborting.])
1036                fi
1037            fi
1038            CPPFLAGS="$FT_FLAGS $CPPFLAGS"
1039            CXXFLAGS="$FT_FLAGS $CXXFLAGS"
1040            CFLAGS="$FT_FLAGS $CFLAGS"
1041
1042            AC_CHECK_LIB(fontconfig, FcPatternCreate)
1043            AC_CHECK_HEADER(X11/Xft/Xft.h,
1044		    AC_CHECK_LIB(Xft, XftDrawCreate,
1045			[AC_DEFINE(USE_XFT)
1046			 LIBS="-lXft $LIBS"
1047			 xft_found=yes] ))
1048	fi
1049
1050	dnl Issue a warning message if Xft was not found, abort configure
1051	dnl if Xft was requested explicitly (but not found)
1052	if test x$enable_xft != xno -a x$xft_found != xyes; then
1053	    AC_MSG_WARN([could not find the required Xft headers and/or libraries.])
1054	    AC_MSG_NOTICE([please install Xft headers and libraries or use 'configure --disable-xft'.])
1055	    if test x$enable_xft = xyes; then
1056		AC_MSG_ERROR([Aborting.])
1057	    fi
1058	fi
1059
1060	dnl Check for the Xdbe extension unless disabled...
1061	AC_ARG_ENABLE(xdbe, [  --enable-xdbe           turn on Xdbe support [[default=yes]]])
1062
1063	xdbe_found=no
1064	if test x$enable_xdbe != xno; then
1065	    AC_CHECK_HEADER(
1066		[X11/extensions/Xdbe.h],
1067		[AC_CHECK_LIB(Xext, XdbeQueryExtension,
1068		    [AC_DEFINE(HAVE_XDBE)
1069		     LIBS="-lXext $LIBS"
1070		     xdbe_found=yes])],
1071		[],
1072		[#include <X11/Xlib.h>])
1073	fi
1074
1075	dnl Check for the Xfixes extension unless disabled...
1076	AC_ARG_ENABLE(xfixes, [  --enable-xfixes         turn on Xfixes support [[default=yes]]])
1077
1078	xfixes_found=no
1079	if test x$enable_xfixes != xno; then
1080	    AC_CHECK_HEADER(
1081		[X11/extensions/Xfixes.h],
1082		[AC_CHECK_LIB(Xfixes, XFixesQueryExtension,
1083		    [AC_DEFINE(HAVE_XFIXES)
1084		     LIBS="-lXfixes $LIBS"
1085		     xfixes_found=yes])],
1086		[],
1087		[#include <X11/Xlib.h>])
1088	fi
1089
1090	dnl Check for the Xcursor library unless disabled...
1091	AC_ARG_ENABLE(xcursor, [  --enable-xcursor        turn on Xcursor support [[default=yes]]])
1092
1093	xcursor_found=no
1094	if test x$enable_xcursor != xno; then
1095	    AC_CHECK_HEADER(
1096		[X11/Xcursor/Xcursor.h],
1097		[AC_CHECK_LIB(Xcursor, XcursorImageCreate,
1098		    [AC_DEFINE(HAVE_XCURSOR)
1099		     LIBS="-lXcursor $LIBS"
1100		     xcursor_found=yes])],
1101		[],
1102		[#include <X11/Xlib.h>])
1103	fi
1104
1105	dnl Check for the Xrender library unless disabled...
1106	AC_ARG_ENABLE(xrender, [  --enable-xrender        turn on Xrender support [[default=yes]]])
1107
1108	xrender_found=no
1109	if test x$enable_xrender != xno; then
1110	    AC_CHECK_HEADER(
1111		[X11/extensions/Xrender.h],
1112		[AC_CHECK_LIB(Xrender, XRenderQueryVersion,
1113		    [AC_DEFINE(HAVE_XRENDER)
1114		     LIBS="-lXrender $LIBS"
1115		     xrender_found=yes])],
1116		[],
1117		[#include <X11/Xlib.h>])
1118	fi
1119
1120	dnl Check for the X11/Xregion.h header file...
1121	AC_CHECK_HEADER(X11/Xregion.h, AC_DEFINE(HAVE_X11_XREGION_H),,
1122	    [#include <X11/Xlib.h>])
1123
1124	dnl Check for overlay visuals...
1125	AC_PATH_PROG(XPROP, xprop)
1126	AC_CACHE_CHECK(for X overlay visuals, ac_cv_have_overlay,
1127	    if test "x$XPROP" != x; then
1128		if $XPROP -root 2>/dev/null | grep -c "SERVER_OVERLAY_VISUALS" >/dev/null; then
1129		    ac_cv_have_overlay=yes
1130		else
1131		    ac_cv_have_overlay=no
1132		fi
1133	    else
1134		ac_cv_have_overlay=no
1135	    fi)
1136
1137	if test x$ac_cv_have_overlay = xyes; then
1138	    AC_DEFINE(HAVE_OVERLAY)
1139	fi
1140
1141	# Make symlinks since UNIX/Linux is case sensitive,
1142	# but Cygwin in general not.
1143	case $host_os in
1144	    cygwin*)
1145		HLINKS="#"
1146	    ;;
1147	    *)
1148	    ;;
1149	esac
1150	# Make symlinks since UNIX/Linux is case sensitive,
1151	# but only if explicitly configured (default=no)
1152	if test "x$with_links" != xyes; then
1153		HLINKS="#"
1154	fi
1155
1156	# Install/Uninstall FLUID application support files
1157	INSTALL_DESKTOP="install-linux"
1158	UNINSTALL_DESKTOP="uninstall-linux"
1159	;;
1160esac
1161
1162AC_SUBST(GLDEMOS)
1163AC_SUBST(GLLIBS)
1164AC_SUBST(HLINKS)
1165AC_SUBST(OSX_ONLY)
1166AC_SUBST(THREADS)
1167
1168AC_SUBST(INSTALL_DESKTOP)
1169AC_SUBST(UNINSTALL_DESKTOP)
1170
1171AC_SUBST(USEMMFILES)
1172
1173dnl Figure out the appropriate formatted man page extension...
1174case "$host_os" in
1175    *bsd* | darwin*)
1176	# *BSD
1177	CAT1EXT=0
1178	CAT3EXT=0
1179	CAT6EXT=0
1180	;;
1181    irix*)
1182	# SGI IRIX
1183	CAT1EXT=z
1184	CAT3EXT=z
1185	CAT6EXT=z
1186	;;
1187    *)
1188	# All others
1189	CAT1EXT=1
1190	CAT3EXT=3
1191	CAT6EXT=6
1192	;;
1193esac
1194
1195AC_SUBST(CAT1EXT)
1196AC_SUBST(CAT3EXT)
1197AC_SUBST(CAT6EXT)
1198
1199dnl Fix "mandir" variable...
1200if test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"; then
1201    case "$host_os" in
1202	*bsd* | darwin* | linux*)
1203	    # *BSD, Darwin, and Linux
1204	    mandir="\${prefix}/share/man"
1205	    ;;
1206	irix*)
1207	    # SGI IRIX
1208	    mandir="\${prefix}/share/catman"
1209	    ;;
1210    esac
1211fi
1212
1213dnl Fix "libdir" variable...
1214if test "$prefix" = NONE; then
1215    prefix=/usr/local
1216fi
1217
1218if test "$exec_prefix" = NONE; then
1219    exec_prefix="\${prefix}"
1220fi
1221
1222case $host_os in
1223    irix[1-5]*)
1224	;;
1225    irix*)
1226	if test "$libdir" = "\${exec_prefix}/lib" -a "$exec_prefix" = "\${prefix}" -a "$prefix" = "/usr"; then
1227	    libdir="/usr/lib32"
1228	fi
1229	;;
1230esac
1231
1232dnl Define the command used to update the dependencies (this option
1233dnl mainly for FLTK core developers - not necessary for users)
1234MAKEDEPEND="\$(CXX) -M"
1235AC_SUBST(MAKEDEPEND)
1236
1237dnl Add warnings to compiler switches:
1238dnl do this last so messing with switches does not break tests
1239
1240if test -n "$GCC"; then
1241    # Show all standard warnings + unused variables, conversion errors,
1242    # and inlining problems when compiling...
1243    OPTIM="-Wall -Wunused -Wno-format-y2k $OPTIM"
1244
1245    # The following additional warnings are useful for tracking down problems...
1246    #OPTIM="-Wshadow -Wconversion $OPTIM"
1247
1248    # We know that Carbon is deprecated on OS X 10.4. To avoid hundreds of warnings
1249    # we will temporarily disable 'deprecated' warnings on OS X.
1250    case $host_os in
1251	darwin[1-7])
1252	    ;;
1253	darwin*)
1254	    OPTIM="-Wno-deprecated-declarations $OPTIM"
1255	    ;;
1256    esac
1257
1258    # Set the default compiler optimizations...
1259    if test -z "$DEBUGFLAG"; then
1260	#
1261	# Note: Can't use -fomit-frame-pointer - prevents tools like
1262	#       libsafe from working!
1263	#
1264	#       Don't use -fforce-mem, -fforce-addr, or -fcaller-saves.
1265	#       They all seem to make either no difference or enlarge
1266	#       the code by a few hundred bytes.
1267	#
1268	#       "-Os" seems to be the best compromise between speed and
1269	#       code size.  "-O3" and higher seem to make no effective
1270	#       difference in the speed of the code, but does bloat the
1271	#       library 10+%.
1272	#
1273
1274	if test "x$with_optim" != x; then
1275	    OPTIM="$with_optim $OPTIM"
1276	else
1277	    OPTIM="-Os $OPTIM"
1278	fi
1279    fi
1280
1281    # Generate position-independent code when needed...
1282    if test $PICFLAG = 1; then
1283	OPTIM="$OPTIM -fPIC"
1284    fi
1285
1286    # See if GCC supports -fno-exceptions...
1287    AC_MSG_CHECKING([if GCC supports -fno-exceptions])
1288    OLDCFLAGS="$CFLAGS"
1289    CFLAGS="$CFLAGS -fno-exceptions"
1290    AC_COMPILE_IFELSE(
1291	[AC_LANG_PROGRAM([[]], [[]])],
1292	[OPTIM="$OPTIM -fno-exceptions"
1293	 AC_MSG_RESULT(yes)],
1294	[AC_MSG_RESULT(no)])
1295    CFLAGS="$OLDCFLAGS"
1296
1297    # See if GCC supports -fno-strict-aliasing...
1298    AC_MSG_CHECKING([if GCC supports -fno-strict-aliasing])
1299    OLDCFLAGS="$CFLAGS"
1300    CFLAGS="$CFLAGS -fno-strict-aliasing"
1301    AC_COMPILE_IFELSE(
1302	[AC_LANG_PROGRAM([[]], [[]])],
1303	[OPTIM="$OPTIM -fno-strict-aliasing"
1304	 AC_MSG_RESULT(yes)],
1305	[AC_MSG_RESULT(no)])
1306    CFLAGS="$OLDCFLAGS"
1307
1308dnl Make sure that shared libraries don't have undefined references
1309    # See if ld supports -no-undefined...
1310    AC_MSG_CHECKING([if ld supports -no-undefined])
1311    OLDLDFLAGS="$LDFLAGS"
1312    LDFLAGS="$LDFLAGS -Wl,-no-undefined"
1313    AC_LINK_IFELSE(
1314	[AC_LANG_PROGRAM([[]], [[]])],
1315	[DSOFLAGS="$DSOFLAGS -Wl,-no-undefined"
1316	 AC_MSG_RESULT(yes)],
1317	[AC_MSG_RESULT(no)])
1318    LDFLAGS="$OLDLDFLAGS"
1319
1320    # See if ld supports -Bsymbolic-functions...
1321    AC_MSG_CHECKING([if ld supports -Bsymbolic-functions])
1322    OLDLDFLAGS="$LDFLAGS"
1323    LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"
1324    AC_LINK_IFELSE(
1325	[AC_LANG_PROGRAM([[]], [[]])],
1326	[DSOFLAGS="$DSOFLAGS -Wl,-Bsymbolic-functions"
1327	 AC_MSG_RESULT(yes)],
1328	[AC_MSG_RESULT(no)])
1329    LDFLAGS="$OLDLDFLAGS"
1330
1331    # See if toolchain supports a sectioned build...
1332    AC_MSG_CHECKING([if toolchain supports sections])
1333    OLDLDFLAGS="$LDFLAGS"
1334    OLDCFLAGS="$CFLAGS"
1335    LDFLAGS="$LDFLAGS -Wl,-gc-sections"
1336    CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
1337    AC_LINK_IFELSE(
1338	[AC_LANG_PROGRAM([[]], [[]])],
1339	[DSOFLAGS="$DSOFLAGS -Wl,-gc-sections"
1340	 OPTIM="$OPTIM -ffunction-sections -fdata-sections"
1341	 AC_MSG_RESULT(yes)],
1342	[AC_MSG_RESULT(no)])
1343    LDFLAGS="$OLDLDFLAGS"
1344    CFLAGS="$OLDCFLAGS"
1345
1346    # See if we are running Solaris; if so, try the -fpermissive option...
1347    # This option is required on some versions of Solaris to work around
1348    # bugs in the X headers up through Solaris 7.
1349    #
1350    # Unlike the other compiler/optimization settings, this one is placed
1351    # in CFLAGS and CXXFLAGS so that fltk-config will provide the option
1352    # to clients - otherwise client apps will not compile properly...
1353    case $host_os in
1354	solaris*)
1355	    AC_MSG_CHECKING([if GCC supports -fpermissive])
1356
1357	    OLDCFLAGS="$CFLAGS"
1358	    CFLAGS="$CFLAGS -fpermissive"
1359	    AC_COMPILE_IFELSE(
1360		[AC_LANG_PROGRAM([[]], [[]])],
1361		[CXXFLAGS="$CXXFLAGS -fpermissive"
1362		 AC_MSG_RESULT(yes)],
1363		[CFLAGS="$OLDCFLAGS"
1364		 AC_MSG_RESULT(no)])
1365	    ;;
1366    esac
1367else
1368    case "$host_os" in
1369	irix*)
1370	    # Running some flavor of IRIX; see which version and
1371	    # set things up according...
1372	    if test "$uversion" -ge 62; then
1373		# We are running IRIX 6.2 or higher; uncomment the following
1374		# lines if you don't have IDO 7.2 or higher:
1375		#
1376		#     CXX="CC -n32 -mips3"
1377		#     CC="cc -n32 -mips3"
1378		#     LD="ld -n32 -mips3"
1379		#     MAKEDEPEND="CC -M"
1380
1381		if test "x`grep abi=n32 /etc/compiler.defaults`" = x; then
1382			AC_MSG_WARN([FOR BEST RESULTS BEFORE COMPILING: setenv SGI_ABI "-n32 -mips3"])
1383		fi
1384
1385		OPTIM="-fullwarn $OPTIM"
1386	    fi
1387	    if test -z "$DEBUGFLAG"; then
1388		if test "x$with_optim" != x; then
1389		    OPTIM="$with_optim $OPTIM"
1390		else
1391		    OPTIM="-O2 $OPTIM"
1392		    if test $uversion -gt 62; then
1393			OPTIM="-OPT:Olimit=4000 $OPTIM"
1394		    fi
1395		fi
1396	    fi
1397	    ;;
1398	hpux*)
1399	    # Running HP-UX; these options should work for the HP compilers.
1400	    if test -z "$DEBUGFLAG"; then
1401		if test "x$with_optim" != x; then
1402		    OPTIM="$with_optim $OPTIM"
1403		else
1404		    OPTIM="+O2 $OPTIM"
1405		fi
1406	    fi
1407
1408	    if test $PICFLAG = 1; then
1409		OPTIM="+z $OPTIM"
1410	    fi
1411
1412	    CXXFLAGS="$CXXFLAGS +W336,501,736,740,749,829"
1413	    ;;
1414	OSF1*)
1415	    # Running Digital/Tru64 UNIX; these options should work for the
1416	    # Digital/Compaq/NewHP compilers.
1417	    if test -z "$DEBUGFLAG"; then
1418		if test "x$with_optim" != x; then
1419		    OPTIM="$with_optim $OPTIM"
1420		else
1421		    OPTIM="-O2 $OPTIM"
1422		fi
1423	    fi
1424	    ;;
1425	solaris*)
1426	    # Solaris
1427	    if test -z "$DEBUGFLAG"; then
1428		if test "x$with_optim" != x; then
1429		    OPTIM="$with_optim $OPTIM"
1430		else
1431		    OPTIM="-xO3 $OPTIM"
1432		fi
1433	    fi
1434
1435	    if test $PICFLAG = 1; then
1436		OPTIM="-KPIC $OPTIM"
1437	    fi
1438	    ;;
1439	aix*)
1440	    if test -z "$DEBUGFLAG"; then
1441		if test "x$with_optim" != x; then
1442		    OPTIM="$with_optim $OPTIM"
1443		else
1444		    OPTIM="-O2 $OPTIM"
1445		fi
1446	    fi
1447
1448	    AC_MSG_WARN([The AIX C and C++ compilers are known not to correctly compile the FLTK library.])
1449	    ;;
1450	*)
1451	    # Running some other operating system; inform the user they
1452	    # should contribute the necessary options via the STR form..
1453	    AC_MSG_WARN([Building FLTK with default compiler optimizations])
1454	    AC_MSG_WARN([Send the FLTK developers your uname and compiler options via http://www.fltk.org/str.php])
1455	    ;;
1456    esac
1457fi
1458
1459OPTIM="$DEBUGFLAG $OPTIM"
1460
1461dnl Take archflags away from CFLAGS (makefiles use ARCHFLAGS explicitly)
1462case $host_os in
1463    darwin*)
1464	if test "x$with_archflags" != x ; then
1465	    CFLAGS="`echo $CFLAGS | sed -e "s/$with_archflags//g"`"
1466	fi
1467	;;
1468esac
1469
1470dnl Define the FLTK documentation directory...
1471case $host_os in
1472  mingw*)
1473     # Determine the path where MSys has /usr installed
1474	msyspath=`mount | grep '\/usr ' | cut -d ' ' -f -1 | sed -e 's/\\\/\// g'`
1475     # Then substitute that in the WIN32 path instead of /usr
1476	AC_DEFINE_UNQUOTED(FLTK_DOCDIR, "$msyspath/local/share/doc/fltk")
1477    ;;
1478  *)
1479    if test x$prefix = xNONE; then
1480	AC_DEFINE_UNQUOTED(FLTK_DOCDIR, "/usr/local/share/doc/fltk")
1481    else
1482	AC_DEFINE_UNQUOTED(FLTK_DOCDIR, "$prefix/share/doc/fltk")
1483    fi
1484    ;;
1485esac
1486
1487dnl Define the FLTK data directory...
1488if test x$prefix = xNONE; then
1489    AC_DEFINE_UNQUOTED(FLTK_DATADIR, "/usr/local/share/fltk")
1490else
1491    AC_DEFINE_UNQUOTED(FLTK_DATADIR, "$prefix/share/fltk")
1492fi
1493
1494dnl Summarize results of configure tests...
1495echo ""
1496echo "Configuration Summary"
1497echo "-------------------------------------------------------------------------"
1498
1499case $host_os_gui in
1500    cygwin* | mingw*)
1501	graphics="GDI"
1502	;;
1503    darwin*)
1504	graphics="Quartz"
1505	;;
1506    *)
1507	graphics="X11"
1508	if test x$xft_found = xyes; then
1509	    graphics="$graphics + Xft"
1510	fi
1511	if test x$xdbe_found = xyes; then
1512	    graphics="$graphics + Xdbe"
1513	fi
1514	if test x$xfixes_found = xyes; then
1515	    graphics="$graphics + Xfixes"
1516	fi
1517	if test x$xinerama_found = xyes; then
1518	    graphics="$graphics + Xinerama"
1519	fi
1520	if test x$xcursor_found = xyes; then
1521	    graphics="$graphics + Xcursor"
1522	fi
1523	if test x$xrender_found = xyes; then
1524	    graphics="$graphics + Xrender"
1525	fi
1526	;;
1527esac
1528
1529echo "    Directories: prefix=$prefix"
1530echo "                 bindir=$bindir"
1531echo "                 datadir=$datadir"
1532echo "                 datarootdir=$datarootdir"
1533echo "                 exec_prefix=$exec_prefix"
1534echo "                 includedir=$includedir"
1535echo "                 libdir=$libdir"
1536echo "                 mandir=$mandir"
1537case $host_os in
1538  mingw*)
1539    echo "                 MSys docpath=$msyspath/local/share/doc/fltk"
1540  ;;
1541esac
1542echo "       Graphics: $graphics"
1543
1544if test x$JPEG = x; then
1545    echo "Image Libraries: JPEG=System"
1546else
1547    echo "Image Libraries: JPEG=Builtin"
1548fi
1549if test x$PNG = x; then
1550    echo "                 PNG=System"
1551else
1552    echo "                 PNG=Builtin"
1553fi
1554if test x$ZLIB = x; then
1555    echo "                 ZLIB=System"
1556else
1557    echo "                 ZLIB=Builtin"
1558fi
1559if test x$enable_cairo = xyes; then
1560    echo "                 CAIRO=lib"
1561fi
1562if test x$enable_cairoext = xyes; then
1563    echo "                 CAIRO=internal_use"
1564fi
1565
1566if test x$enable_largefile != xno; then
1567    echo "    Large Files: YES"
1568else
1569    echo "    Large Files: NO"
1570fi
1571
1572if test x$GLDEMOS = x; then
1573    echo "         OpenGL: NO"
1574else
1575    echo "         OpenGL: YES"
1576fi
1577
1578if test x$THREADS = x; then
1579    echo "        Threads: NO"
1580else
1581    echo "        Threads: YES"
1582fi
1583
1584dnl Set empty BINARY_DIR variable for fltk-config.in (CMake compatibility)
1585BINARY_DIR=
1586AC_SUBST(BINARY_DIR)
1587
1588dnl Write all of the files...
1589AC_CONFIG_HEADER(config.h:configh.in)
1590AC_CONFIG_HEADER(FL/abi-version.h:abi-version.in)
1591AC_CONFIG_FILES([makeinclude fltk.list fltk-config fltk.spec FL/Makefile])
1592AC_OUTPUT
1593
1594dnl Make sure the fltk-config script is executable...
1595chmod +x fltk-config
1596
1597dnl
1598dnl End of "$Id$".
1599dnl
1600