configure.ac revision 22e8ddc74843b82606c1f0934ec1d4fad2ffc853
1dnl Process this file with autoconf to create configure.
2
3AC_PREREQ([2.59])
4
5dnl Versioning - scrape the version from configs/default
6m4_define([mesa_version],
7    [m4_esyscmd([${MAKE-make} -s -f bin/version.mk version | tr -d '\n'])])
8m4_ifval(mesa_version,,
9    [m4_fatal([Failed to get the Mesa version from `make -f bin/version.mk version`])])
10
11dnl Tell the user about autoconf.html in the --help output
12m4_divert_once([HELP_END], [
13See docs/autoconf.html for more details on the options for Mesa.])
14
15AC_INIT([Mesa],[mesa_version],
16    [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa])
17AC_CONFIG_AUX_DIR([bin])
18AC_CANONICAL_HOST
19
20dnl Versions for external dependencies
21LIBDRM_REQUIRED=2.4.15
22LIBDRM_RADEON_REQUIRED=2.4.17
23DRI2PROTO_REQUIRED=2.1
24GLPROTO_REQUIRED=1.4.11
25LIBDRM_XORG_REQUIRED=2.4.17
26LIBKMS_XORG_REQUIRED=1.0.0
27
28dnl Check for progs
29AC_PROG_CPP
30AC_PROG_CC
31AC_PROG_CXX
32AC_CHECK_PROGS([MAKE], [gmake make])
33AC_PATH_PROG([MKDEP], [makedepend])
34AC_PATH_PROG([SED], [sed])
35
36dnl Our fallback install-sh is a symlink to minstall. Use the existing
37dnl configuration in that case.
38AC_PROG_INSTALL
39test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)'
40
41dnl We need a POSIX shell for parts of the build. Assume we have one
42dnl in most cases.
43case "$host_os" in
44solaris*)
45    # Solaris /bin/sh is too old/non-POSIX compliant
46    AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh])
47    SHELL="$POSIX_SHELL"
48    ;;
49esac
50
51dnl If we're using GCC, make sure that it is at least version 3.3.0.  Older
52dnl versions are explictly not supported.
53if test "x$GCC" = xyes; then
54    AC_MSG_CHECKING([whether gcc version is sufficient])
55    major=0
56    minor=0
57
58    GCC_VERSION=`$CC -dumpversion`
59    if test $? -eq 0; then
60        major=`echo $GCC_VERSION | cut -d. -f1`
61        minor=`echo $GCC_VERSION | cut -d. -f1`
62    fi
63
64    if test $major -lt 3 -o $major -eq 3 -a $minor -lt 3 ; then
65        AC_MSG_RESULT([no])
66        AC_MSG_ERROR([If using GCC, version 3.3.0 or later is required.])
67    else
68        AC_MSG_RESULT([yes])
69    fi
70fi
71
72
73MKDEP_OPTIONS=-fdepend
74dnl Ask gcc where it's keeping its secret headers
75if test "x$GCC" = xyes; then
76    for dir in include include-fixed; do
77        GCC_INCLUDES=`$CC -print-file-name=$dir`
78        if test "x$GCC_INCLUDES" != x && \
79           test "$GCC_INCLUDES" != "$dir" && \
80           test -d "$GCC_INCLUDES"; then
81            MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES"
82        fi
83    done
84fi
85AC_SUBST([MKDEP_OPTIONS])
86
87dnl Make sure the pkg-config macros are defined
88m4_ifndef([PKG_PROG_PKG_CONFIG],
89    [m4_fatal([Could not locate the pkg-config autoconf macros.
90  These are usually located in /usr/share/aclocal/pkg.m4. If your macros
91  are in a different location, try setting the environment variable
92  ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])])
93PKG_PROG_PKG_CONFIG()
94
95dnl LIB_DIR - library basename
96LIB_DIR=`echo $libdir | $SED 's%.*/%%'`
97AC_SUBST([LIB_DIR])
98
99dnl Cache LDFLAGS so we can add EXTRA_LIB_PATH and restore it later
100_SAVE_LDFLAGS="$LDFLAGS"
101AC_ARG_VAR([EXTRA_LIB_PATH],[Extra -L paths for the linker])
102AC_SUBST([EXTRA_LIB_PATH])
103
104dnl Cache CPPFLAGS so we can add *_INCLUDES and restore it later
105_SAVE_CPPFLAGS="$CPPFLAGS"
106AC_ARG_VAR([X11_INCLUDES],[Extra -I paths for X11 headers])
107AC_SUBST([X11_INCLUDES])
108
109dnl Compiler macros
110DEFINES=""
111AC_SUBST([DEFINES])
112case "$host_os" in
113linux*|*-gnu*|gnu*)
114    DEFINES="$DEFINES -D_GNU_SOURCE -DPTHREADS"
115    ;;
116solaris*)
117    DEFINES="$DEFINES -DPTHREADS -DSVR4"
118    ;;
119cygwin*)
120    DEFINES="$DEFINES -DPTHREADS"
121    ;;
122esac
123
124dnl Add flags for gcc and g++
125if test "x$GCC" = xyes; then
126    CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -std=c99 -ffast-math"
127
128    # Enable -fvisibility=hidden if using a gcc that supports it
129    save_CFLAGS="$CFLAGS"
130    AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden])
131    CFLAGS="$CFLAGS -fvisibility=hidden"
132    AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
133		   [CFLAGS="$save_CFLAGS" ; AC_MSG_RESULT([no])]);
134
135    # Work around aliasing bugs - developers should comment this out
136    CFLAGS="$CFLAGS -fno-strict-aliasing"
137fi
138if test "x$GXX" = xyes; then
139    CXXFLAGS="$CXXFLAGS -Wall"
140
141    # Work around aliasing bugs - developers should comment this out
142    CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
143fi
144
145dnl These should be unnecessary, but let the user set them if they want
146AC_ARG_VAR([OPT_FLAGS], [Additional optimization flags for the compiler.
147    Default is to use CFLAGS.])
148AC_ARG_VAR([ARCH_FLAGS], [Additional architecture specific flags for the
149    compiler. Default is to use CFLAGS.])
150AC_SUBST([OPT_FLAGS])
151AC_SUBST([ARCH_FLAGS])
152
153dnl
154dnl Hacks to enable 32 or 64 bit build
155dnl
156AC_ARG_ENABLE([32-bit],
157    [AS_HELP_STRING([--enable-32-bit],
158        [build 32-bit libraries @<:@default=auto@:>@])],
159    [enable_32bit="$enableval"],
160    [enable_32bit=auto]
161)
162if test "x$enable_32bit" = xyes; then
163    if test "x$GCC" = xyes; then
164        CFLAGS="$CFLAGS -m32"
165        ARCH_FLAGS="$ARCH_FLAGS -m32"
166    fi
167    if test "x$GXX" = xyes; then
168        CXXFLAGS="$CXXFLAGS -m32"
169    fi
170fi
171AC_ARG_ENABLE([64-bit],
172    [AS_HELP_STRING([--enable-64-bit],
173        [build 64-bit libraries @<:@default=auto@:>@])],
174    [enable_64bit="$enableval"],
175    [enable_64bit=auto]
176)
177if test "x$enable_64bit" = xyes; then
178    if test "x$GCC" = xyes; then
179        CFLAGS="$CFLAGS -m64"
180    fi
181    if test "x$GXX" = xyes; then
182        CXXFLAGS="$CXXFLAGS -m64"
183    fi
184fi
185
186dnl
187dnl shared/static libraries, mimic libtool options
188dnl
189AC_ARG_ENABLE([static],
190    [AS_HELP_STRING([--enable-static],
191        [build static libraries @<:@default=disabled@:>@])],
192    [enable_static="$enableval"],
193    [enable_static=no]
194)
195case "x$enable_static" in
196xyes|xno ) ;;
197x ) enable_static=no ;;
198* )
199    AC_MSG_ERROR([Static library option '$enable_static' is not a valid])
200    ;;
201esac
202AC_ARG_ENABLE([shared],
203    [AS_HELP_STRING([--disable-shared],
204        [build shared libraries @<:@default=enabled@:>@])],
205    [enable_shared="$enableval"],
206    [enable_shared=yes]
207)
208case "x$enable_shared" in
209xyes|xno ) ;;
210x ) enable_shared=yes ;;
211* )
212    AC_MSG_ERROR([Shared library option '$enable_shared' is not a valid])
213    ;;
214esac
215
216dnl Can't have static and shared libraries, default to static if user
217dnl explicitly requested. If both disabled, set to static since shared
218dnl was explicitly requirested.
219case "x$enable_static$enable_shared" in
220xyesyes )
221    AC_MSG_WARN([Can't build static and shared libraries, disabling shared])
222    enable_shared=no
223    ;;
224xnono )
225    AC_MSG_WARN([Can't disable both static and shared libraries, enabling static])
226    enable_static=yes
227    ;;
228esac
229
230dnl
231dnl mklib options
232dnl
233AC_ARG_VAR([MKLIB_OPTIONS],[Options for the Mesa library script, mklib])
234if test "$enable_static" = yes; then
235    MKLIB_OPTIONS="$MKLIB_OPTIONS -static"
236fi
237AC_SUBST([MKLIB_OPTIONS])
238
239dnl
240dnl other compiler options
241dnl
242AC_ARG_ENABLE([debug],
243    [AS_HELP_STRING([--enable-debug],
244        [use debug compiler flags and macros @<:@default=disabled@:>@])],
245    [enable_debug="$enableval"],
246    [enable_debug=no]
247)
248if test "x$enable_debug" = xyes; then
249    DEFINES="$DEFINES -DDEBUG"
250    if test "x$GCC" = xyes; then
251        CFLAGS="$CFLAGS -g"
252    fi
253    if test "x$GXX" = xyes; then
254        CXXFLAGS="$CXXFLAGS -g"
255    fi
256fi
257
258dnl
259dnl library names
260dnl
261if test "$enable_static" = yes; then
262    LIB_EXTENSION='a'
263else
264    case "$host_os" in
265    darwin* )
266        LIB_EXTENSION='dylib' ;;
267    cygwin* )
268        LIB_EXTENSION='dll' ;;
269    aix* )
270        LIB_EXTENSION='a' ;;
271    * )
272        LIB_EXTENSION='so' ;;
273    esac
274fi
275
276GL_LIB_NAME='lib$(GL_LIB).'${LIB_EXTENSION}
277GLU_LIB_NAME='lib$(GLU_LIB).'${LIB_EXTENSION}
278GLUT_LIB_NAME='lib$(GLUT_LIB).'${LIB_EXTENSION}
279GLW_LIB_NAME='lib$(GLW_LIB).'${LIB_EXTENSION}
280OSMESA_LIB_NAME='lib$(OSMESA_LIB).'${LIB_EXTENSION}
281EGL_LIB_NAME='lib$(EGL_LIB).'${LIB_EXTENSION}
282
283GL_LIB_GLOB='lib$(GL_LIB).*'${LIB_EXTENSION}'*'
284GLU_LIB_GLOB='lib$(GLU_LIB).*'${LIB_EXTENSION}'*'
285GLUT_LIB_GLOB='lib$(GLUT_LIB).*'${LIB_EXTENSION}'*'
286GLW_LIB_GLOB='lib$(GLW_LIB).*'${LIB_EXTENSION}'*'
287OSMESA_LIB_GLOB='lib$(OSMESA_LIB).*'${LIB_EXTENSION}'*'
288EGL_LIB_GLOB='lib$(EGL_LIB).*'${LIB_EXTENSION}'*'
289
290AC_SUBST([GL_LIB_NAME])
291AC_SUBST([GLU_LIB_NAME])
292AC_SUBST([GLUT_LIB_NAME])
293AC_SUBST([GLW_LIB_NAME])
294AC_SUBST([OSMESA_LIB_NAME])
295AC_SUBST([EGL_LIB_NAME])
296
297AC_SUBST([GL_LIB_GLOB])
298AC_SUBST([GLU_LIB_GLOB])
299AC_SUBST([GLUT_LIB_GLOB])
300AC_SUBST([GLW_LIB_GLOB])
301AC_SUBST([OSMESA_LIB_GLOB])
302AC_SUBST([EGL_LIB_GLOB])
303
304dnl
305dnl Arch/platform-specific settings
306dnl
307AC_ARG_ENABLE([asm],
308    [AS_HELP_STRING([--disable-asm],
309        [disable assembly usage @<:@default=enabled on supported plaforms@:>@])],
310    [enable_asm="$enableval"],
311    [enable_asm=yes]
312)
313asm_arch=""
314ASM_FLAGS=""
315MESA_ASM_SOURCES=""
316GLAPI_ASM_SOURCES=""
317AC_MSG_CHECKING([whether to enable assembly])
318test "x$enable_asm" = xno && AC_MSG_RESULT([no])
319# disable if cross compiling on x86/x86_64 since we must run gen_matypes
320if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then
321    case "$host_cpu" in
322    i?86 | x86_64)
323        enable_asm=no
324        AC_MSG_RESULT([no, cross compiling])
325        ;;
326    esac
327fi
328# check for supported arches
329if test "x$enable_asm" = xyes; then
330    case "$host_cpu" in
331    i?86)
332        case "$host_os" in
333        linux* | *freebsd* | dragonfly*)
334            test "x$enable_64bit" = xyes && asm_arch=x86_64 || asm_arch=x86
335            ;;
336        esac
337        ;;
338    x86_64)
339        case "$host_os" in
340        linux* | *freebsd* | dragonfly*)
341            test "x$enable_32bit" = xyes && asm_arch=x86 || asm_arch=x86_64
342            ;;
343        esac
344        ;;
345    powerpc)
346        case "$host_os" in
347        linux*)
348            asm_arch=ppc
349            ;;
350        esac
351        ;;
352    sparc*)
353        case "$host_os" in
354        linux*)
355            asm_arch=sparc
356            ;;
357        esac
358        ;;
359    esac
360
361    case "$asm_arch" in
362    x86)
363        ASM_FLAGS="-DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM"
364        MESA_ASM_SOURCES='$(X86_SOURCES)'
365        GLAPI_ASM_SOURCES='$(X86_API)'
366        AC_MSG_RESULT([yes, x86])
367        ;;
368    x86_64)
369        ASM_FLAGS="-DUSE_X86_64_ASM"
370        MESA_ASM_SOURCES='$(X86-64_SOURCES)'
371        GLAPI_ASM_SOURCES='$(X86-64_API)'
372        AC_MSG_RESULT([yes, x86_64])
373        ;;
374    ppc)
375        ASM_FLAGS="-DUSE_PPC_ASM -DUSE_VMX_ASM"
376        MESA_ASM_SOURCES='$(PPC_SOURCES)'
377        AC_MSG_RESULT([yes, ppc])
378        ;;
379    sparc)
380        ASM_FLAGS="-DUSE_SPARC_ASM"
381        MESA_ASM_SOURCES='$(SPARC_SOURCES)'
382        GLAPI_ASM_SOURCES='$(SPARC_API)'
383        AC_MSG_RESULT([yes, sparc])
384        ;;
385    *)
386        AC_MSG_RESULT([no, platform not supported])
387        ;;
388    esac
389fi
390AC_SUBST([ASM_FLAGS])
391AC_SUBST([MESA_ASM_SOURCES])
392AC_SUBST([GLAPI_ASM_SOURCES])
393
394dnl PIC code macro
395MESA_PIC_FLAGS
396
397dnl Check to see if dlopen is in default libraries (like Solaris, which
398dnl has it in libc), or if libdl is needed to get it.
399AC_CHECK_FUNC([dlopen], [],
400    [AC_CHECK_LIB([dl], [dlopen], [DLOPEN_LIBS="-ldl"])])
401
402dnl See if posix_memalign is available
403AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"])
404
405dnl SELinux awareness.
406AC_ARG_ENABLE([selinux],
407    [AS_HELP_STRING([--enable-selinux],
408        [Build SELinux-aware Mesa @<:@default=disabled@:>@])],
409    [MESA_SELINUX="$enableval"],
410    [MESA_SELINUX=no])
411if test "x$enable_selinux" = "xyes"; then
412    AC_CHECK_HEADER([selinux/selinux.h],[],
413                    [AC_MSG_ERROR([SELinux headers not found])])
414    AC_CHECK_LIB([selinux],[is_selinux_enabled],[],
415                 [AC_MSG_ERROR([SELinux library not found])])
416    SELINUX_LIBS="-lselinux"
417    DEFINES="$DEFINES -DMESA_SELINUX"
418fi
419
420dnl
421dnl Driver configuration. Options are xlib, dri and osmesa right now.
422dnl More later: fbdev, ...
423dnl
424default_driver="xlib"
425
426case "$host_os" in
427linux*)
428    case "$host_cpu" in
429    i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
430    esac
431    ;;
432*freebsd* | dragonfly*)
433    case "$host_cpu" in
434    i*86|x86_64|powerpc*|sparc*) default_driver="dri";;
435    esac
436    ;;
437esac
438
439AC_ARG_WITH([driver],
440    [AS_HELP_STRING([--with-driver=DRIVER],
441        [driver for Mesa: xlib,dri,osmesa @<:@default=dri when available, or xlib@:>@])],
442    [mesa_driver="$withval"],
443    [mesa_driver="$default_driver"])
444dnl Check for valid option
445case "x$mesa_driver" in
446xxlib|xdri|xosmesa)
447    ;;
448*)
449    AC_MSG_ERROR([Driver '$mesa_driver' is not a valid option])
450    ;;
451esac
452
453dnl
454dnl Driver specific build directories
455dnl
456
457dnl this variable will be prepended to SRC_DIRS and is not exported
458CORE_DIRS="glsl mesa"
459
460SRC_DIRS="glew"
461GLU_DIRS="sgi"
462GALLIUM_DIRS="auxiliary drivers state_trackers"
463GALLIUM_TARGET_DIRS=""
464GALLIUM_WINSYS_DIRS="sw"
465GALLIUM_DRIVERS_DIRS="softpipe failover trace identity"
466GALLIUM_STATE_TRACKERS_DIRS=""
467
468case "$mesa_driver" in
469xlib)
470    DRIVER_DIRS="x11"
471    GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib"
472    GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib"
473    ;;
474dri)
475    SRC_DIRS="$SRC_DIRS glx"
476    DRIVER_DIRS="dri"
477    GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri sw/drm"
478    ;;
479osmesa)
480    DRIVER_DIRS="osmesa"
481    ;;
482esac
483AC_SUBST([SRC_DIRS])
484AC_SUBST([GLU_DIRS])
485AC_SUBST([DRIVER_DIRS])
486AC_SUBST([GALLIUM_DIRS])
487AC_SUBST([GALLIUM_TARGET_DIRS])
488AC_SUBST([GALLIUM_WINSYS_DIRS])
489AC_SUBST([GALLIUM_DRIVERS_DIRS])
490AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
491AC_SUBST([MESA_LLVM])
492
493dnl
494dnl User supplied program configuration
495dnl
496if test -d "$srcdir/progs/demos"; then
497    default_demos=yes
498else
499    default_demos=no
500fi
501AC_ARG_WITH([demos],
502    [AS_HELP_STRING([--with-demos@<:@=DIRS...@:>@],
503        [optional comma delimited demo directories to build
504        @<:@default=auto if source available@:>@])],
505    [with_demos="$withval"],
506    [with_demos="$default_demos"])
507if test "x$with_demos" = x; then
508    with_demos=no
509fi
510
511dnl If $with_demos is yes, directories will be added as libs available
512PROGRAM_DIRS=""
513case "$with_demos" in
514no) ;;
515yes)
516    # If the driver isn't osmesa, we have libGL and can build xdemos
517    if test "$mesa_driver" != osmesa; then
518        PROGRAM_DIRS="xdemos"
519    fi
520    ;;
521*)
522    # verify the requested demos directories exist
523    demos=`IFS=,; echo $with_demos`
524    for demo in $demos; do
525        test -d "$srcdir/progs/$demo" || \
526            AC_MSG_ERROR([Program directory '$demo' doesn't exist])
527    done
528    PROGRAM_DIRS="$demos"
529    ;;
530esac
531
532dnl
533dnl Find out if X is available. The variable have_x is set if libX11 is
534dnl found to mimic AC_PATH_XTRA.
535dnl
536if test -n "$PKG_CONFIG"; then
537    AC_MSG_CHECKING([pkg-config files for X11 are available])
538    PKG_CHECK_EXISTS([x11],[
539        x11_pkgconfig=yes
540        have_x=yes
541        ],[
542        x11_pkgconfig=no
543    ])
544    AC_MSG_RESULT([$x11_pkgconfig])
545else
546    x11_pkgconfig=no
547fi
548dnl Use the autoconf macro if no pkg-config files
549if test "$x11_pkgconfig" = yes; then
550    PKG_CHECK_MODULES([X11], [x11])
551else
552    AC_PATH_XTRA
553    test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS"
554    test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11"
555    AC_SUBST([X11_CFLAGS])
556    AC_SUBST([X11_LIBS])
557fi
558
559dnl Try to tell the user that the --x-* options are only used when
560dnl pkg-config is not available. This must be right after AC_PATH_XTRA.
561m4_divert_once([HELP_BEGIN],
562[These options are only used when the X libraries cannot be found by the
563pkg-config utility.])
564
565dnl We need X for xlib and dri, so bomb now if it's not found
566case "$mesa_driver" in
567xlib|dri)
568    if test "$no_x" = yes; then
569        AC_MSG_ERROR([X11 development libraries needed for $mesa_driver driver])
570    fi
571    ;;
572esac
573
574dnl XCB - this is only used for GLX right now
575AC_ARG_ENABLE([xcb],
576    [AS_HELP_STRING([--enable-xcb],
577        [use XCB for GLX @<:@default=disabled@:>@])],
578    [enable_xcb="$enableval"],
579    [enable_xcb=no])
580if test "x$enable_xcb" = xyes; then
581    DEFINES="$DEFINES -DUSE_XCB"
582else
583    enable_xcb=no
584fi
585
586dnl
587dnl libGL configuration per driver
588dnl
589case "$mesa_driver" in
590xlib)
591    if test "$x11_pkgconfig" = yes; then
592        PKG_CHECK_MODULES([XLIBGL], [x11 xext])
593        GL_PC_REQ_PRIV="x11 xext"
594        X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS"
595        GL_LIB_DEPS="$XLIBGL_LIBS"
596    else
597        # should check these...
598        X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
599        GL_LIB_DEPS="$X_LIBS -lX11 -lXext"
600        GL_PC_LIB_PRIV="$GL_LIB_DEPS"
601        GL_PC_CFLAGS="$X11_INCLUDES"
602    fi
603    GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm -lpthread"
604    GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm -lpthread"
605
606    # if static, move the external libraries to the programs
607    # and empty the libraries for libGL
608    if test "$enable_static" = yes; then
609        APP_LIB_DEPS="$APP_LIB_DEPS $GL_LIB_DEPS"
610        GL_LIB_DEPS=""
611    fi
612    ;;
613dri)
614    # DRI must be shared, I think
615    if test "$enable_static" = yes; then
616        AC_MSG_ERROR([Can't use static libraries for DRI drivers])
617    fi
618
619    # Check for libdrm
620    PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED])
621    PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
622    PKG_CHECK_MODULES([GLPROTO], [glproto >= $GLPROTO_REQUIRED])
623    GL_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED glproto >= $GLPROTO_REQUIRED"
624    DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED"
625
626    # find the DRI deps for libGL
627    if test "$x11_pkgconfig" = yes; then
628        # add xcb modules if necessary
629        dri_modules="x11 xext xxf86vm xdamage xfixes"
630        if test "$enable_xcb" = yes; then
631            dri_modules="$dri_modules x11-xcb xcb-glx"
632        fi
633
634        PKG_CHECK_MODULES([DRIGL], [$dri_modules])
635        GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
636        X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
637        GL_LIB_DEPS="$DRIGL_LIBS"
638    else
639        # should check these...
640        X11_INCLUDES="$X11_INCLUDES $X_CFLAGS"
641        GL_LIB_DEPS="$X_LIBS -lX11 -lXext -lXxf86vm -lXdamage -lXfixes"
642        GL_PC_LIB_PRIV="$GL_LIB_DEPS"
643        GL_PC_CFLAGS="$X11_INCLUDES"
644
645        # XCB can only be used from pkg-config
646        if test "$enable_xcb" = yes; then
647            PKG_CHECK_MODULES([XCB],[x11-xcb xcb-glx])
648            GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV x11-xcb xcb-glx"
649            X11_INCLUDES="$X11_INCLUDES $XCB_CFLAGS"
650            GL_LIB_DEPS="$GL_LIB_DEPS $XCB_LIBS"
651        fi
652    fi
653
654    # need DRM libs, -lpthread, etc.
655    GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS"
656    GL_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS"
657    ;;
658osmesa)
659    # No libGL for osmesa
660    GL_LIB_DEPS=""
661    ;;
662esac
663AC_SUBST([GL_LIB_DEPS])
664AC_SUBST([GL_PC_REQ_PRIV])
665AC_SUBST([GL_PC_LIB_PRIV])
666AC_SUBST([GL_PC_CFLAGS])
667AC_SUBST([DRI_PC_REQ_PRIV])
668
669dnl
670dnl More X11 setup
671dnl
672if test "$mesa_driver" = xlib; then
673    DEFINES="$DEFINES -DUSE_XSHM"
674fi
675
676dnl
677dnl More DRI setup
678dnl
679AC_ARG_ENABLE([glx-tls],
680    [AS_HELP_STRING([--enable-glx-tls],
681        [enable TLS support in GLX @<:@default=disabled@:>@])],
682    [GLX_USE_TLS="$enableval"],
683    [GLX_USE_TLS=no])
684dnl Directory for DRI drivers
685AC_ARG_WITH([dri-driverdir],
686    [AS_HELP_STRING([--with-dri-driverdir=DIR],
687        [directory for the DRI drivers @<:@${libdir}/dri@:>@])],
688    [DRI_DRIVER_INSTALL_DIR="$withval"],
689    [DRI_DRIVER_INSTALL_DIR='${libdir}/dri'])
690AC_SUBST([DRI_DRIVER_INSTALL_DIR])
691dnl Extra search path for DRI drivers
692AC_ARG_WITH([dri-searchpath],
693    [AS_HELP_STRING([--with-dri-searchpath=DIRS...],
694        [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])],
695    [DRI_DRIVER_SEARCH_DIR="$withval"],
696    [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}'])
697AC_SUBST([DRI_DRIVER_SEARCH_DIR])
698dnl Direct rendering or just indirect rendering
699AC_ARG_ENABLE([driglx-direct],
700    [AS_HELP_STRING([--disable-driglx-direct],
701        [enable direct rendering in GLX for DRI @<:@default=enabled@:>@])],
702    [driglx_direct="$enableval"],
703    [driglx_direct="yes"])
704dnl Which drivers to build - default is chosen by platform
705AC_ARG_WITH([dri-drivers],
706    [AS_HELP_STRING([--with-dri-drivers@<:@=DIRS...@:>@],
707        [comma delimited DRI drivers list, e.g.
708        "swrast,i965,radeon" @<:@default=auto@:>@])],
709    [with_dri_drivers="$withval"],
710    [with_dri_drivers=yes])
711if test "x$with_dri_drivers" = x; then
712    with_dri_drivers=no
713fi
714
715dnl If $with_dri_drivers is yes, directories will be added through
716dnl platform checks
717DRI_DIRS=""
718case "$with_dri_drivers" in
719no) ;;
720yes)
721    DRI_DIRS="yes"
722    ;;
723*)
724    # verify the requested driver directories exist
725    dri_drivers=`IFS=', '; echo $with_dri_drivers`
726    for driver in $dri_drivers; do
727        test -d "$srcdir/src/mesa/drivers/dri/$driver" || \
728            AC_MSG_ERROR([DRI driver directory '$driver' doesn't exist])
729    done
730    DRI_DIRS="$dri_drivers"
731    ;;
732esac
733
734dnl Set DRI_DIRS, DEFINES and LIB_DEPS
735if test "$mesa_driver" = dri; then
736    # Use TLS in GLX?
737    if test "x$GLX_USE_TLS" = xyes; then
738        DEFINES="$DEFINES -DGLX_USE_TLS -DPTHREADS"
739    fi
740
741    # Platform specific settings and drivers to build
742    case "$host_os" in
743    linux*)
744        DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
745        if test "x$driglx_direct" = xyes; then
746            DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
747        fi
748        DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
749
750        case "$host_cpu" in
751        x86_64)
752            # sis is missing because they have not be converted to use
753            # the new interface.  i810 are missing because there is no
754            # x86-64 system where they could *ever* be used.
755            if test "x$DRI_DIRS" = "xyes"; then
756                DRI_DIRS="i915 i965 mach64 mga r128 r200 r300 r600 radeon \
757                    savage tdfx unichrome swrast"
758            fi
759            ;;
760        powerpc*)
761            # Build only the drivers for cards that exist on PowerPC.
762            # At some point MGA will be added, but not yet.
763            if test "x$DRI_DIRS" = "xyes"; then
764                DRI_DIRS="mach64 r128 r200 r300 r600 radeon tdfx swrast"
765            fi
766            ;;
767        sparc*)
768            # Build only the drivers for cards that exist on sparc`
769            if test "x$DRI_DIRS" = "xyes"; then
770                DRI_DIRS="mach64 r128 r200 r300 r600 radeon swrast"
771            fi
772            ;;
773        esac
774        ;;
775    freebsd* | dragonfly*)
776        DEFINES="$DEFINES -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1"
777        DEFINES="$DEFINES -DIN_DRI_DRIVER -DHAVE_ALIAS"
778        DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
779        if test "x$driglx_direct" = xyes; then
780            DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
781        fi
782        if test "x$GXX" = xyes; then
783            CXXFLAGS="$CXXFLAGS -ansi -pedantic"
784        fi
785
786        if test "x$DRI_DIRS" = "xyes"; then
787            DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon tdfx \
788                unichrome savage sis swrast"
789        fi
790        ;;
791    gnu*)
792        DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
793        DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS"
794	;;
795    solaris*)
796        DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER"
797        DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
798        if test "x$driglx_direct" = xyes; then
799            DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
800        fi
801        ;;
802    esac
803
804    # default drivers
805    if test "x$DRI_DIRS" = "xyes"; then
806        DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon \
807            savage sis tdfx unichrome swrast"
808    fi
809
810    DRI_DIRS=`echo "$DRI_DIRS" | $SED 's/  */ /g'`
811
812    # Check for expat
813    EXPAT_INCLUDES=""
814    EXPAT_LIB=-lexpat
815    AC_ARG_WITH([expat],
816        [AS_HELP_STRING([--with-expat=DIR],
817            [expat install directory])],[
818        EXPAT_INCLUDES="-I$withval/include"
819        CPPFLAGS="$CPPFLAGS $EXPAT_INCLUDES"
820        LDFLAGS="$LDFLAGS -L$withval/$LIB_DIR"
821        EXPAT_LIB="-L$withval/$LIB_DIR -lexpat"
822        ])
823    AC_CHECK_HEADER([expat.h],[],[AC_MSG_ERROR([Expat required for DRI.])])
824    AC_CHECK_LIB([expat],[XML_ParserCreate],[],
825        [AC_MSG_ERROR([Expat required for DRI.])])
826
827    # put all the necessary libs together
828    DRI_LIB_DEPS="$SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS"
829fi
830AC_SUBST([DRI_DIRS])
831AC_SUBST([EXPAT_INCLUDES])
832AC_SUBST([DRI_LIB_DEPS])
833
834case $DRI_DIRS in
835*i915*|*i965*)
836    PKG_CHECK_MODULES([INTEL], [libdrm_intel >= 2.4.19])
837    ;;
838esac
839
840case $DRI_DIRS in
841*radeon*|*r200*|*r300*|*r600*)
842    PKG_CHECK_MODULES([LIBDRM_RADEON],
843		      [libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED],
844		      HAVE_LIBDRM_RADEON=yes,
845		      HAVE_LIBDRM_RADEON=no)
846
847    if test "$HAVE_LIBDRM_RADEON" = yes; then
848	RADEON_CFLAGS="-DHAVE_LIBDRM_RADEON=1 $LIBDRM_RADEON_CFLAGS"
849	RADEON_LDFLAGS=$LIBDRM_RADEON_LIBS
850    fi
851    ;;
852esac
853AC_SUBST([RADEON_CFLAGS])
854AC_SUBST([RADEON_LDFLAGS])
855
856
857dnl
858dnl OSMesa configuration
859dnl
860if test "$mesa_driver" = xlib; then
861    default_gl_osmesa=yes
862else
863    default_gl_osmesa=no
864fi
865AC_ARG_ENABLE([gl-osmesa],
866    [AS_HELP_STRING([--enable-gl-osmesa],
867        [enable OSMesa on libGL @<:@default=enabled for xlib driver@:>@])],
868    [gl_osmesa="$enableval"],
869    [gl_osmesa="$default_gl_osmesa"])
870if test "x$gl_osmesa" = xyes; then
871    if test "$mesa_driver" = osmesa; then
872        AC_MSG_ERROR([libGL is not available for OSMesa driver])
873    else
874        DRIVER_DIRS="$DRIVER_DIRS osmesa"
875    fi
876fi
877
878dnl Configure the channel bits for OSMesa (libOSMesa, libOSMesa16, ...)
879AC_ARG_WITH([osmesa-bits],
880    [AS_HELP_STRING([--with-osmesa-bits=BITS],
881        [OSMesa channel bits and library name: 8, 16, 32 @<:@default=8@:>@])],
882    [osmesa_bits="$withval"],
883    [osmesa_bits=8])
884if test "$mesa_driver" != osmesa && test "x$osmesa_bits" != x8; then
885    AC_MSG_WARN([Ignoring OSMesa channel bits for non-OSMesa driver])
886    osmesa_bits=8
887fi
888case "x$osmesa_bits" in
889x8)
890    OSMESA_LIB=OSMesa
891    ;;
892x16|x32)
893    OSMESA_LIB="OSMesa$osmesa_bits"
894    DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31"
895    ;;
896*)
897    AC_MSG_ERROR([OSMesa bits '$osmesa_bits' is not a valid option])
898    ;;
899esac
900AC_SUBST([OSMESA_LIB])
901
902case "$mesa_driver" in
903osmesa)
904    # only link libraries with osmesa if shared
905    if test "$enable_static" = no; then
906        OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
907    else
908        OSMESA_LIB_DEPS=""
909    fi
910    OSMESA_MESA_DEPS=""
911    OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
912    ;;
913*)
914    # Link OSMesa to libGL otherwise
915    OSMESA_LIB_DEPS=""
916    # only link libraries with osmesa if shared
917    if test "$enable_static" = no; then
918        OSMESA_MESA_DEPS='-l$(GL_LIB)'
919    else
920        OSMESA_MESA_DEPS=""
921    fi
922    OSMESA_PC_REQ="gl"
923    ;;
924esac
925OSMESA_PC_LIB_PRIV="$OSMESA_PC_LIB_PRIV"
926AC_SUBST([OSMESA_LIB_DEPS])
927AC_SUBST([OSMESA_MESA_DEPS])
928AC_SUBST([OSMESA_PC_REQ])
929AC_SUBST([OSMESA_PC_LIB_PRIV])
930
931dnl
932dnl EGL configuration
933dnl
934AC_ARG_ENABLE([egl],
935    [AS_HELP_STRING([--disable-egl],
936        [disable EGL library @<:@default=enabled@:>@])],
937    [enable_egl="$enableval"],
938    [enable_egl=yes])
939if test "x$enable_egl" = xyes; then
940    SRC_DIRS="$SRC_DIRS egl"
941    EGL_LIB_DEPS="$DLOPEN_LIBS -lpthread"
942    EGL_DRIVERS_DIRS=""
943    if test "$enable_static" != yes; then
944        # build egl_glx when libGL is built
945        if test "$mesa_driver" != osmesa; then
946            EGL_DRIVERS_DIRS="glx"
947        fi
948
949        # build egl_dri2 when xcb-dri2 is available
950        PKG_CHECK_MODULES([EGL_DRI2], [x11-xcb xcb-dri2 xcb-xfixes libdrm],
951			  [have_xcb_dri2=yes],[have_xcb_dri2=no])
952        if test "$have_xcb_dri2" = yes; then
953            EGL_DRIVERS_DIRS="$EGL_DRIVERS_DIRS dri2"
954        fi
955    fi
956
957    if test "$with_demos" = yes; then
958        PROGRAM_DIRS="$PROGRAM_DIRS egl/opengl"
959    fi
960fi
961AC_SUBST([EGL_LIB_DEPS])
962AC_SUBST([EGL_DRIVERS_DIRS])
963
964dnl
965dnl GLU configuration
966dnl
967AC_ARG_ENABLE([glu],
968    [AS_HELP_STRING([--disable-glu],
969        [enable OpenGL Utility library @<:@default=enabled@:>@])],
970    [enable_glu="$enableval"],
971    [enable_glu=yes])
972if test "x$enable_glu" = xyes; then
973    SRC_DIRS="$SRC_DIRS glu"
974
975    case "$mesa_driver" in
976    osmesa)
977        # If GLU is available and we have libOSMesa (not 16 or 32),
978        # we can build the osdemos
979        if test "$with_demos" = yes && test "$osmesa_bits" = 8; then
980            PROGRAM_DIRS="$PROGRAM_DIRS osdemos"
981        fi
982
983        # Link libGLU to libOSMesa instead of libGL
984        GLU_LIB_DEPS=""
985        GLU_PC_REQ="osmesa"
986        if test "$enable_static" = no; then
987            GLU_MESA_DEPS='-l$(OSMESA_LIB)'
988        else
989            GLU_MESA_DEPS=""
990        fi
991        ;;
992    *)
993        # If static, empty GLU_LIB_DEPS and add libs for programs to link
994        GLU_PC_REQ="gl"
995        GLU_PC_LIB_PRIV="-lm"
996        if test "$enable_static" = no; then
997            GLU_LIB_DEPS="-lm"
998            GLU_MESA_DEPS='-l$(GL_LIB)'
999        else
1000            GLU_LIB_DEPS=""
1001            GLU_MESA_DEPS=""
1002            APP_LIB_DEPS="$APP_LIB_DEPS -lstdc++"
1003        fi
1004        ;;
1005    esac
1006fi
1007if test "$enable_static" = no; then
1008    GLU_LIB_DEPS="$GLU_LIB_DEPS $OS_CPLUSPLUS_LIBS"
1009fi
1010GLU_PC_LIB_PRIV="$GLU_PC_LIB_PRIV $OS_CPLUSPLUS_LIBS"
1011AC_SUBST([GLU_LIB_DEPS])
1012AC_SUBST([GLU_MESA_DEPS])
1013AC_SUBST([GLU_PC_REQ])
1014AC_SUBST([GLU_PC_REQ_PRIV])
1015AC_SUBST([GLU_PC_LIB_PRIV])
1016AC_SUBST([GLU_PC_CFLAGS])
1017
1018dnl
1019dnl GLw configuration
1020dnl
1021AC_ARG_ENABLE([glw],
1022    [AS_HELP_STRING([--disable-glw],
1023        [enable Xt/Motif widget library @<:@default=enabled@:>@])],
1024    [enable_glw="$enableval"],
1025    [enable_glw=yes])
1026dnl Don't build GLw on osmesa
1027if test "x$enable_glw" = xyes && test "$mesa_driver" = osmesa; then
1028    AC_MSG_WARN([Disabling GLw since the driver is OSMesa])
1029    enable_glw=no
1030fi
1031AC_ARG_ENABLE([motif],
1032    [AS_HELP_STRING([--enable-motif],
1033        [use Motif widgets in GLw @<:@default=disabled@:>@])],
1034    [enable_motif="$enableval"],
1035    [enable_motif=no])
1036
1037if test "x$enable_glw" = xyes; then
1038    SRC_DIRS="$SRC_DIRS glw"
1039    if test "$x11_pkgconfig" = yes; then
1040        PKG_CHECK_MODULES([GLW],[x11 xt])
1041        GLW_PC_REQ_PRIV="x11 xt"
1042        GLW_LIB_DEPS="$GLW_LIBS"
1043    else
1044        # should check these...
1045        GLW_LIB_DEPS="$X_LIBS -lXt -lX11"
1046        GLW_PC_LIB_PRIV="$GLW_LIB_DEPS"
1047        GLW_PC_CFLAGS="$X11_INCLUDES"
1048    fi
1049
1050    GLW_SOURCES="GLwDrawA.c"
1051    MOTIF_CFLAGS=
1052    if test "x$enable_motif" = xyes; then
1053        GLW_SOURCES="$GLW_SOURCES GLwMDrawA.c"
1054        AC_PATH_PROG([MOTIF_CONFIG], [motif-config], [no])
1055        if test "x$MOTIF_CONFIG" != xno; then
1056            MOTIF_CFLAGS=`$MOTIF_CONFIG --cflags`
1057            MOTIF_LIBS=`$MOTIF_CONFIG --libs`
1058        else
1059            AC_CHECK_HEADER([Xm/PrimitiveP.h], [],
1060                [AC_MSG_ERROR([Can't locate Motif headers])])
1061            AC_CHECK_LIB([Xm], [XmGetPixmap], [MOTIF_LIBS="-lXm"],
1062                [AC_MSG_ERROR([Can't locate Motif Xm library])])
1063        fi
1064        # MOTIF_LIBS is prepended to GLW_LIB_DEPS since Xm needs Xt/X11
1065        GLW_LIB_DEPS="$MOTIF_LIBS $GLW_LIB_DEPS"
1066        GLW_PC_LIB_PRIV="$MOTIF_LIBS $GLW_PC_LIB_PRIV"
1067        GLW_PC_CFLAGS="$MOTIF_CFLAGS $GLW_PC_CFLAGS"
1068    fi
1069
1070    # If static, empty GLW_LIB_DEPS and add libs for programs to link
1071    GLW_PC_LIB_PRIV="$GLW_PC_LIB_PRIV"
1072    if test "$enable_static" = no; then
1073        GLW_MESA_DEPS='-l$(GL_LIB)'
1074        GLW_LIB_DEPS="$GLW_LIB_DEPS"
1075    else
1076        APP_LIB_DEPS="$APP_LIB_DEPS $GLW_LIB_DEPS"
1077        GLW_LIB_DEPS=""
1078        GLW_MESA_DEPS=""
1079    fi
1080fi
1081AC_SUBST([GLW_LIB_DEPS])
1082AC_SUBST([GLW_MESA_DEPS])
1083AC_SUBST([GLW_SOURCES])
1084AC_SUBST([MOTIF_CFLAGS])
1085AC_SUBST([GLW_PC_REQ_PRIV])
1086AC_SUBST([GLW_PC_LIB_PRIV])
1087AC_SUBST([GLW_PC_CFLAGS])
1088
1089dnl
1090dnl GLUT configuration
1091dnl
1092if test -f "$srcdir/include/GL/glut.h"; then
1093    default_glut=yes
1094else
1095    default_glut=no
1096fi
1097AC_ARG_ENABLE([glut],
1098    [AS_HELP_STRING([--disable-glut],
1099        [enable GLUT library @<:@default=enabled if source available@:>@])],
1100    [enable_glut="$enableval"],
1101    [enable_glut="$default_glut"])
1102
1103dnl Can't build glut if GLU not available
1104if test "x$enable_glu$enable_glut" = xnoyes; then
1105    AC_MSG_WARN([Disabling glut since GLU is disabled])
1106    enable_glut=no
1107fi
1108dnl Don't build glut on osmesa
1109if test "x$enable_glut" = xyes && test "$mesa_driver" = osmesa; then
1110    AC_MSG_WARN([Disabling glut since the driver is OSMesa])
1111    enable_glut=no
1112fi
1113
1114if test "x$enable_glut" = xyes; then
1115    SRC_DIRS="$SRC_DIRS glut/glx"
1116    GLUT_CFLAGS=""
1117    if test "x$GCC" = xyes; then
1118        GLUT_CFLAGS="-fexceptions"
1119    fi
1120    if test "$x11_pkgconfig" = yes; then
1121        PKG_CHECK_MODULES([GLUT],[x11 xmu xi])
1122        GLUT_PC_REQ_PRIV="x11 xmu xi"
1123        GLUT_LIB_DEPS="$GLUT_LIBS"
1124    else
1125        # should check these...
1126        GLUT_LIB_DEPS="$X_LIBS -lX11 -lXmu -lXi"
1127        GLUT_PC_LIB_PRIV="$GLUT_LIB_DEPS"
1128        GLUT_PC_CFLAGS="$X11_INCLUDES"
1129    fi
1130    GLUT_LIB_DEPS="$GLUT_LIB_DEPS -lm"
1131    GLUT_PC_LIB_PRIV="$GLUT_PC_LIB_PRIV -lm"
1132
1133    # If glut is available, we can build most programs
1134    if test "$with_demos" = yes; then
1135        PROGRAM_DIRS="$PROGRAM_DIRS demos redbook samples glsl"
1136    fi
1137
1138    # If static, empty GLUT_LIB_DEPS and add libs for programs to link
1139    if test "$enable_static" = no; then
1140        GLUT_MESA_DEPS='-l$(GLU_LIB) -l$(GL_LIB)'
1141    else
1142        APP_LIB_DEPS="$APP_LIB_DEPS $GLUT_LIB_DEPS"
1143        GLUT_LIB_DEPS=""
1144        GLUT_MESA_DEPS=""
1145    fi
1146fi
1147AC_SUBST([GLUT_LIB_DEPS])
1148AC_SUBST([GLUT_MESA_DEPS])
1149AC_SUBST([GLUT_CFLAGS])
1150AC_SUBST([GLUT_PC_REQ_PRIV])
1151AC_SUBST([GLUT_PC_LIB_PRIV])
1152AC_SUBST([GLUT_PC_CFLAGS])
1153
1154dnl
1155dnl Program library dependencies
1156dnl    Only libm is added here if necessary as the libraries should
1157dnl    be pulled in by the linker
1158dnl
1159if test "x$APP_LIB_DEPS" = x; then
1160    case "$host_os" in
1161    solaris*)
1162        APP_LIB_DEPS="-lX11 -lsocket -lnsl -lm"
1163        ;;
1164    cygwin*)
1165        APP_LIB_DEPS="-lX11"
1166        ;;
1167    *)
1168        APP_LIB_DEPS="-lm"
1169        ;;
1170    esac
1171fi
1172AC_SUBST([APP_LIB_DEPS])
1173AC_SUBST([PROGRAM_DIRS])
1174
1175dnl
1176dnl Gallium configuration
1177dnl
1178AC_ARG_ENABLE([gallium],
1179    [AS_HELP_STRING([--disable-gallium],
1180        [build gallium @<:@default=enabled@:>@])],
1181    [enable_gallium="$enableval"],
1182    [enable_gallium=yes])
1183if test "x$enable_gallium" = xyes; then
1184    SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
1185    AC_CHECK_HEADER([udis86.h], [HAS_UDIS86="yes"],
1186                [HAS_UDIS86="no"])
1187    AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [no])
1188fi
1189
1190AC_SUBST([LLVM_CFLAGS])
1191AC_SUBST([LLVM_LIBS])
1192AC_SUBST([LLVM_LDFLAGS])
1193AC_SUBST([LLVM_VERSION])
1194
1195dnl
1196dnl Gallium state trackers configuration
1197dnl
1198AC_ARG_WITH([state-trackers],
1199    [AS_HELP_STRING([--with-state-trackers@<:@=DIRS...@:>@],
1200        [comma delimited state_trackers list, e.g.
1201        "egl,glx" @<:@default=auto@:>@])],
1202    [with_state_trackers="$withval"],
1203    [with_state_trackers=yes])
1204
1205case "$with_state_trackers" in
1206no)
1207    GALLIUM_STATE_TRACKERS_DIRS=""
1208    ;;
1209yes)
1210    # look at what else is built
1211    case "$mesa_driver" in
1212    xlib)
1213        GALLIUM_STATE_TRACKERS_DIRS=glx
1214        ;;
1215    dri)
1216        GALLIUM_STATE_TRACKERS_DIRS="dri"
1217        HAVE_ST_DRI="yes"
1218        if test "x$enable_egl" = xyes; then
1219            GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
1220            HAVE_ST_EGL="yes"
1221        fi
1222        # Have only tested st/xorg on 1.6.0 servers
1223        PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED],
1224            HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
1225            HAVE_ST_XORG="no")
1226        ;;
1227    esac
1228    ;;
1229*)
1230    # verify the requested state tracker exist
1231    state_trackers=`IFS=', '; echo $with_state_trackers`
1232    for tracker in $state_trackers; do
1233        test -d "$srcdir/src/gallium/state_trackers/$tracker" || \
1234            AC_MSG_ERROR([state tracker '$tracker' doesn't exist])
1235
1236        case "$tracker" in
1237        dri)
1238            if test "x$mesa_driver" != xdri; then
1239                AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri])
1240            fi
1241            HAVE_ST_DRI="yes"
1242            ;;
1243        egl)
1244            if test "x$enable_egl" != xyes; then
1245                AC_MSG_ERROR([cannot build egl state tracker without EGL library])
1246            fi
1247            HAVE_ST_EGL="yes"
1248            ;;
1249        xorg)
1250            PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED])
1251            PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED])
1252            HAVE_ST_XORG="yes"
1253            ;;
1254        es)
1255            # mesa/es is required to build es state tracker
1256            CORE_DIRS="$CORE_DIRS mesa/es"
1257            ;;
1258        esac
1259    done
1260    GALLIUM_STATE_TRACKERS_DIRS="$state_trackers"
1261    ;;
1262esac
1263
1264if test "x$HAVE_ST_XORG" = xyes; then
1265    PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
1266        HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71",
1267        HAVE_XEXTPROTO_71="no")
1268fi
1269
1270AC_ARG_WITH([egl-displays],
1271    [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@],
1272        [comma delimited native displays libEGL supports, e.g.
1273        "x11,kms" @<:@default=auto@:>@])],
1274    [with_egl_displays="$withval"],
1275    [with_egl_displays=yes])
1276
1277EGL_DISPLAYS=""
1278case "$with_egl_displays" in
1279yes)
1280    if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then
1281        EGL_DISPLAYS="x11"
1282    fi
1283    ;;
1284*)
1285    if test "x$enable_egl" != xyes; then
1286        AC_MSG_ERROR([cannot build egl state tracker without EGL library])
1287    fi
1288    # verify the requested driver directories exist
1289    egl_displays=`IFS=', '; echo $with_egl_displays`
1290    for dpy in $egl_displays; do
1291        test -d "$srcdir/src/gallium/state_trackers/egl/$dpy" || \
1292            AC_MSG_ERROR([EGL display '$dpy' does't exist])
1293    done
1294    EGL_DISPLAYS="$egl_displays"
1295    ;;
1296esac
1297AC_SUBST([EGL_DISPLAYS])
1298
1299AC_ARG_WITH([egl-driver-dir],
1300    [AS_HELP_STRING([--with-egl-driver-dir=DIR],
1301                    [directory for EGL drivers [[default=${libdir}/egl]]])],
1302    [EGL_DRIVER_INSTALL_DIR="$withval"],
1303    [EGL_DRIVER_INSTALL_DIR='${libdir}/egl'])
1304AC_SUBST([EGL_DRIVER_INSTALL_DIR])
1305
1306AC_ARG_WITH([xorg-driver-dir],
1307    [AS_HELP_STRING([--with-xorg-driver-dir=DIR],
1308                    [Default xorg driver directory[[default=${libdir}/xorg/modules/drivers]]])],
1309    [XORG_DRIVER_INSTALL_DIR="$withval"],
1310    [XORG_DRIVER_INSTALL_DIR="${libdir}/xorg/modules/drivers"])
1311AC_SUBST([XORG_DRIVER_INSTALL_DIR])
1312
1313AC_ARG_WITH([max-width],
1314    [AS_HELP_STRING([--with-max-width=N],
1315                    [Maximum framebuffer width (4096)])],
1316    [DEFINES="${DEFINES} -DMAX_WIDTH=${withval}";
1317     AS_IF([test "${withval}" -gt "4096"],
1318           [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
1319)
1320AC_ARG_WITH([max-height],
1321    [AS_HELP_STRING([--with-max-height=N],
1322                    [Maximum framebuffer height (4096)])],
1323    [DEFINES="${DEFINES} -DMAX_HEIGHT=${withval}";
1324     AS_IF([test "${withval}" -gt "4096"],
1325           [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
1326)
1327
1328dnl
1329dnl Gallium LLVM
1330dnl
1331AC_ARG_ENABLE([gallium-llvm],
1332    [AS_HELP_STRING([--enable-gallium-llvm],
1333        [build gallium LLVM support @<:@default=disabled@:>@])],
1334    [enable_gallium_llvm="$enableval"],
1335    [enable_gallium_llvm=auto])
1336if test "x$enable_gallium_llvm" = xyes; then
1337    if test "x$LLVM_CONFIG" != xno; then
1338	LLVM_VERSION=`$LLVM_CONFIG --version`
1339	LLVM_CFLAGS=`$LLVM_CONFIG --cflags`
1340	LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++"
1341
1342	if test "x$HAS_UDIS86" != xno; then
1343	    LLVM_LIBS="$LLVM_LIBS -ludis86"
1344	    DEFINES="$DEFINES -DHAVE_UDIS86"
1345	fi
1346	LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
1347	GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe"
1348	DEFINES="$DEFINES -DMESA_LLVM -D__STDC_CONSTANT_MACROS"
1349	MESA_LLVM=1
1350    else
1351	MESA_LLVM=0
1352    fi
1353else
1354    MESA_LLVM=0
1355fi
1356
1357dnl
1358dnl Gallium helper functions
1359dnl
1360gallium_check_st() {
1361    if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_EGL" = xyes || test "x$HAVE_ST_XORG" = xyes; then
1362         GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
1363    fi
1364    if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
1365         GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2"
1366    fi
1367    if test "x$HAVE_ST_EGL" = xyes && test "x$3" != x; then
1368         GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3"
1369    fi
1370    if test "x$HAVE_ST_XORG" = xyes && test "x$4" != x; then
1371         GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $4"
1372    fi
1373}
1374
1375
1376dnl
1377dnl Gallium SVGA configuration
1378dnl
1379AC_ARG_ENABLE([gallium-svga],
1380    [AS_HELP_STRING([--enable-gallium-svga],
1381        [build gallium SVGA @<:@default=disabled@:>@])],
1382    [enable_gallium_svga="$enableval"],
1383    [enable_gallium_svga=auto])
1384if test "x$enable_gallium_svga" = xyes; then
1385    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
1386    gallium_check_st "svga/drm" "dri-vmwgfx" "egl-vmwgfx" "xorg-vmwgfx"
1387elif test "x$enable_gallium_svga" = xauto; then
1388    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
1389fi
1390
1391dnl
1392dnl Gallium Intel configuration
1393dnl
1394AC_ARG_ENABLE([gallium-intel],
1395    [AS_HELP_STRING([--enable-gallium-intel],
1396        [build gallium intel @<:@default=disabled@:>@])],
1397    [enable_gallium_intel="$enableval"],
1398    [enable_gallium_intel=auto])
1399if test "x$enable_gallium_intel" = xyes; then
1400    GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
1401    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
1402    gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965"
1403elif test "x$enable_gallium_intel" = xauto; then
1404    GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
1405    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
1406fi
1407
1408dnl
1409dnl Gallium Radeon configuration
1410dnl
1411AC_ARG_ENABLE([gallium-radeon],
1412    [AS_HELP_STRING([--enable-gallium-radeon],
1413        [build gallium radeon @<:@default=disabled@:>@])],
1414    [enable_gallium_radeon="$enableval"],
1415    [enable_gallium_radeon=auto])
1416if test "x$enable_gallium_radeon" = xyes; then
1417    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
1418    gallium_check_st "radeon/drm" "dri-radeong" "egl-radeon" "xorg-radeon"
1419elif test "x$enable_gallium_radeon" = xauto; then
1420    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
1421fi
1422
1423dnl
1424dnl Gallium Nouveau configuration
1425dnl
1426AC_ARG_ENABLE([gallium-nouveau],
1427    [AS_HELP_STRING([--enable-gallium-nouveau],
1428        [build gallium nouveau @<:@default=disabled@:>@])],
1429    [enable_gallium_nouveau="$enableval"],
1430    [enable_gallium_nouveau=no])
1431if test "x$enable_gallium_nouveau" = xyes; then
1432    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50"
1433    gallium_check_st "nouveau/drm" "dri-nouveau" "egl-nouveau" "xorg-nouveau"
1434fi
1435
1436dnl
1437dnl Gallium swrast configuration
1438dnl
1439AC_ARG_ENABLE([gallium-swrast],
1440    [AS_HELP_STRING([--enable-gallium-swrast],
1441        [build gallium swrast @<:@default=auto@:>@])],
1442    [enable_gallium_swrast="$enableval"],
1443    [enable_gallium_swrast=auto])
1444if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then
1445    if test "x$HAVE_ST_DRI" = xyes; then
1446        GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast"
1447    fi
1448    if test "x$HAVE_ST_EGL" = xyes; then
1449        GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast"
1450    fi
1451fi
1452
1453dnl prepend CORE_DIRS to SRC_DIRS
1454SRC_DIRS="$CORE_DIRS $SRC_DIRS"
1455
1456dnl Restore LDFLAGS and CPPFLAGS
1457LDFLAGS="$_SAVE_LDFLAGS"
1458CPPFLAGS="$_SAVE_CPPFLAGS"
1459
1460dnl Substitute the config
1461AC_CONFIG_FILES([configs/autoconf])
1462
1463dnl Replace the configs/current symlink
1464AC_CONFIG_COMMANDS([configs],[
1465if test -f configs/current || test -L configs/current; then
1466    rm -f configs/current
1467fi
1468ln -s autoconf configs/current
1469])
1470
1471AC_OUTPUT
1472
1473dnl
1474dnl Output some configuration info for the user
1475dnl
1476echo ""
1477echo "        prefix:          $prefix"
1478echo "        exec_prefix:     $exec_prefix"
1479echo "        libdir:          $libdir"
1480echo "        includedir:      $includedir"
1481
1482dnl Driver info
1483echo ""
1484echo "        Driver:          $mesa_driver"
1485if echo "$DRIVER_DIRS" | grep 'osmesa' >/dev/null 2>&1; then
1486    echo "        OSMesa:          lib$OSMESA_LIB"
1487else
1488    echo "        OSMesa:          no"
1489fi
1490if test "$mesa_driver" = dri; then
1491    # cleanup the drivers var
1492    dri_dirs=`echo $DRI_DIRS | $SED 's/^ *//;s/  */ /;s/ *$//'`
1493if test "x$DRI_DIRS" = x; then
1494    echo "        DRI drivers:     no"
1495else
1496    echo "        DRI drivers:     $dri_dirs"
1497fi
1498    echo "        DRI driver dir:  $DRI_DRIVER_INSTALL_DIR"
1499fi
1500echo "        Use XCB:         $enable_xcb"
1501
1502echo ""
1503if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
1504    echo "        Gallium:         yes"
1505    echo "        Gallium dirs:    $GALLIUM_DIRS"
1506    echo "        Target dirs:     $GALLIUM_TARGET_DIRS"
1507    echo "        Winsys dirs:     $GALLIUM_WINSYS_DIRS"
1508    echo "        Driver dirs:     $GALLIUM_DRIVERS_DIRS"
1509    echo "        Trackers dirs:   $GALLIUM_STATE_TRACKERS_DIRS"
1510else
1511    echo "        Gallium:         no"
1512fi
1513
1514dnl Libraries
1515echo ""
1516echo "        Shared libs:     $enable_shared"
1517echo "        Static libs:     $enable_static"
1518if test "$enable_egl" = yes; then
1519    echo "        EGL:             $EGL_DRIVERS_DIRS"
1520else
1521    echo "        EGL:             no"
1522fi
1523echo "        GLU:             $enable_glu"
1524echo "        GLw:             $enable_glw (Motif: $enable_motif)"
1525echo "        glut:            $enable_glut"
1526
1527dnl Programs
1528# cleanup the programs var for display
1529program_dirs=`echo $PROGRAM_DIRS | $SED 's/^ *//;s/  */ /;s/ *$//'`
1530if test "x$program_dirs" = x; then
1531    echo "        Demos:           no"
1532else
1533    echo "        Demos:           $program_dirs"
1534fi
1535
1536dnl Compiler options
1537# cleanup the CFLAGS/CXXFLAGS/DEFINES vars
1538cflags=`echo $CFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
1539    $SED 's/^ *//;s/  */ /;s/ *$//'`
1540cxxflags=`echo $CXXFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \
1541    $SED 's/^ *//;s/  */ /;s/ *$//'`
1542defines=`echo $DEFINES $ASM_FLAGS | $SED 's/^ *//;s/  */ /;s/ *$//'`
1543echo ""
1544echo "        CFLAGS:          $cflags"
1545echo "        CXXFLAGS:        $cxxflags"
1546echo "        Macros:          $defines"
1547
1548echo ""
1549echo "        Run '${MAKE-make}' to build Mesa"
1550echo ""
1551