OSDN Git Service

android: vulkan/util: fix generating vk_enum_to_str.*
[android-x86/external-mesa.git] / configure.ac
1 dnl Copyright © 2011-2014 Intel Corporation
2 dnl Copyright © 2011-2014 Emil Velikov <emil.l.velikov@gmail.com>
3 dnl Copyright © 2007-2010 Dan Nicholson
4 dnl Copyright © 2010-2014 Marek Olšák <maraeo@gmail.com>
5 dnl Copyright © 2010-2014 Christian König
6 dnl Copyright © 2012-2014 Tom Stellard <tstellar@gmail.com>
7 dnl Copyright © 2009-2012 Jakob Bornecrantz
8 dnl Copyright © 2009-2014 Jon TURNEY
9 dnl Copyright © 2011-2012 Benjamin Franzke
10 dnl Copyright © 2008-2014 David Airlie
11 dnl Copyright © 2009-2013 Brian Paul
12 dnl
13 dnl Permission is hereby granted, free of charge, to any person obtaining a
14 dnl copy of this software and associated documentation files (the "Software"),
15 dnl to deal in the Software without restriction, including without limitation
16 dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 dnl and/or sell copies of the Software, and to permit persons to whom the
18 dnl Software is furnished to do so, subject to the following conditions:
19 dnl
20 dnl The above copyright notice and this permission notice (including the next
21 dnl paragraph) shall be included in all copies or substantial portions of the
22 dnl Software.
23 dnl
24 dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27 dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 dnl DEALINGS IN THE SOFTWARE.
31 dnl
32 dnl Process this file with autoconf to create configure.
33
34 AC_PREREQ([2.60])
35
36 dnl Tell the user about autoconf.html in the --help output
37 m4_divert_once([HELP_END], [
38 See docs/autoconf.html for more details on the options for Mesa.])
39
40 m4_define(MESA_VERSION, m4_normalize(m4_include(VERSION)))
41 AC_INIT([Mesa], [MESA_VERSION],
42     [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa])
43 AC_CONFIG_AUX_DIR([bin])
44 AC_CONFIG_MACRO_DIR([m4])
45 AC_CANONICAL_SYSTEM
46 AM_INIT_AUTOMAKE([foreign tar-ustar dist-xz subdir-objects])
47
48 dnl We only support native Windows builds (MinGW/MSVC) through SCons.
49 case "$host_os" in
50 mingw*)
51     AC_MSG_ERROR([MinGW build not supported through autoconf/automake, use SCons instead])
52     ;;
53 esac
54
55 # Support silent build rules, requires at least automake-1.11. Disable
56 # by either passing --disable-silent-rules to configure or passing V=1
57 # to make
58 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
59     [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
60
61 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
62
63 dnl Set internal versions
64 OSMESA_VERSION=8
65 AC_SUBST([OSMESA_VERSION])
66 OPENCL_VERSION=1
67 AC_SUBST([OPENCL_VERSION])
68
69 # The idea is that libdrm is distributed as one cohesive package, even
70 # though it is composed of multiple libraries. However some drivers
71 # may have different version requirements than others. This list
72 # codifies which drivers need which version of libdrm. Any libdrm
73 # version dependencies in non-driver-specific code should be reflected
74 # in the first entry.
75 LIBDRM_REQUIRED=2.4.75
76 LIBDRM_RADEON_REQUIRED=2.4.71
77 LIBDRM_AMDGPU_REQUIRED=2.4.95
78 LIBDRM_INTEL_REQUIRED=2.4.75
79 LIBDRM_NVVIEUX_REQUIRED=2.4.66
80 LIBDRM_NOUVEAU_REQUIRED=2.4.66
81 LIBDRM_ETNAVIV_REQUIRED=2.4.89
82 LIBDRM_VC4_REQUIRED=2.4.89
83
84 dnl Versions for external dependencies
85 DRI2PROTO_REQUIRED=2.8
86 GLPROTO_REQUIRED=1.4.14
87 LIBOMXIL_BELLAGIO_REQUIRED=0.0
88 LIBOMXIL_TIZONIA_REQUIRED=0.10.0
89 LIBVA_REQUIRED=0.39.0
90 VDPAU_REQUIRED=1.1
91 WAYLAND_REQUIRED=1.11
92 WAYLAND_EGL_BACKEND_REQUIRED=3
93 WAYLAND_PROTOCOLS_REQUIRED=1.8
94 XCB_REQUIRED=1.9.3
95 XCBDRI2_REQUIRED=1.8
96 XCBDRI3_MODIFIERS_REQUIRED=1.13
97 XCBGLX_REQUIRED=1.8.1
98 XCBPRESENT_MODIFIERS_REQUIRED=1.13
99 XDAMAGE_REQUIRED=1.1
100 XSHMFENCE_REQUIRED=1.1
101 XVMC_REQUIRED=1.0.6
102 PYTHON_MAKO_REQUIRED=0.8.0
103 LIBSENSORS_REQUIRED=4.0.0
104 ZLIB_REQUIRED=1.2.3
105
106 dnl LLVM versions
107 LLVM_REQUIRED_GALLIUM=3.3.0
108 LLVM_REQUIRED_OPENCL=3.9.0
109 LLVM_REQUIRED_R600=3.9.0
110 LLVM_REQUIRED_RADEONSI=6.0.0
111 LLVM_REQUIRED_RADV=6.0.0
112 LLVM_REQUIRED_SWR=6.0.0
113
114 dnl Check for progs
115 AC_PROG_CPP
116 AC_PROG_CC
117 AC_PROG_CXX
118 dnl add this here, so the help for this environmnet variable is close to
119 dnl other CC/CXX flags related help
120 AC_ARG_VAR([CXX11_CXXFLAGS], [Compiler flag to enable C++11 support (only needed if not
121                               enabled by default and different  from -std=c++11)])
122 AM_PROG_CC_C_O
123 AC_PROG_GREP
124 AC_PROG_NM
125 AM_PROG_AS
126 AX_CHECK_GNU_MAKE
127 AM_PATH_PYTHON([2.7],, [AM_PATH_PYTHON([3.4],, [:])])
128
129 AC_PROG_SED
130 AC_PROG_MKDIR_P
131
132 AC_SYS_LARGEFILE
133
134
135 LT_PREREQ([2.2])
136 LT_INIT([disable-static])
137
138 AC_CHECK_PROG(RM, rm, [rm -f])
139
140 AX_PROG_BISON([],
141               AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-parse.c"],
142                     [AC_MSG_ERROR([bison not found - unable to compile glcpp-parse.y])]))
143 AX_PROG_FLEX([],
144              AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-lex.c"],
145                    [AC_MSG_ERROR([flex not found - unable to compile glcpp-lex.l])]))
146
147 AC_CHECK_PROG(INDENT, indent, indent, cat)
148 if test "x$INDENT" != "xcat"; then
149     # Only GNU indent is supported
150     INDENT_VERSION=`indent --version | grep GNU`
151     if test $? -eq 0; then
152        AC_SUBST(INDENT_FLAGS, '-i4 -nut -br -brs -npcs -ce -TGLubyte -TGLbyte -TBool')
153     else
154        INDENT="cat"
155     fi
156 fi
157
158 AX_CHECK_PYTHON_MAKO_MODULE($PYTHON_MAKO_REQUIRED)
159
160 if test "$PYTHON" = ":"; then
161     if test ! -f "$srcdir/src/util/format_srgb.c"; then
162         AC_MSG_ERROR([Python not found - unable to generate sources])
163     fi
164 else
165     if test "x$acv_mako_found" = xno; then
166         if test ! -f "$srcdir/src/mesa/main/format_unpack.c"; then
167             AC_MSG_ERROR([Python mako module v$PYTHON_MAKO_REQUIRED or higher not found])
168         fi
169     fi
170 fi
171
172 AC_PROG_INSTALL
173
174 dnl We need a POSIX shell for parts of the build. Assume we have one
175 dnl in most cases.
176 case "$host_os" in
177 solaris*)
178     # Solaris /bin/sh is too old/non-POSIX compliant
179     AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh])
180     SHELL="$POSIX_SHELL"
181     ;;
182 esac
183
184 dnl clang is mostly GCC-compatible, but its version is much lower,
185 dnl so we have to check for it.
186 AC_MSG_CHECKING([if compiling with clang])
187
188 AC_COMPILE_IFELSE(
189 [AC_LANG_PROGRAM([], [[
190 #ifndef __clang__
191        not clang
192 #endif
193 ]])],
194 [acv_mesa_CLANG=yes], [acv_mesa_CLANG=no])
195
196 AC_MSG_RESULT([$acv_mesa_CLANG])
197
198 dnl If we're using GCC, make sure that it is at least version 4.2.0.  Older
199 dnl versions are explictly not supported.
200 GEN_ASM_OFFSETS=no
201 USE_GNU99=no
202 if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
203     AC_MSG_CHECKING([whether gcc version is sufficient])
204     major=0
205     minor=0
206
207     GCC_VERSION=`$CC -dumpversion`
208     if test $? -eq 0; then
209         GCC_VERSION_MAJOR=`echo $GCC_VERSION | cut -d. -f1`
210         GCC_VERSION_MINOR=`echo $GCC_VERSION | cut -d. -f2`
211     fi
212
213     if test $GCC_VERSION_MAJOR -lt 4 -o $GCC_VERSION_MAJOR -eq 4 -a $GCC_VERSION_MINOR -lt 2 ; then
214         AC_MSG_RESULT([no])
215         AC_MSG_ERROR([If using GCC, version 4.2.0 or later is required.])
216     else
217         AC_MSG_RESULT([yes])
218     fi
219
220     if test $GCC_VERSION_MAJOR -lt 4 -o $GCC_VERSION_MAJOR -eq 4 -a $GCC_VERSION_MINOR -lt 6 ; then
221         USE_GNU99=yes
222     fi
223     if test "x$cross_compiling" = xyes; then
224         GEN_ASM_OFFSETS=yes
225     fi
226 fi
227
228 dnl We don't support building Mesa with Sun C compiler
229 dnl https://bugs.freedesktop.org/show_bug.cgi?id=93189
230 AC_CHECK_DECL([__SUNPRO_C], [SUNCC=yes], [SUNCC=no])
231 if test "x$SUNCC" = xyes; then
232     AC_MSG_ERROR([Building with Sun C compiler is not supported, use GCC instead.])
233 fi
234
235 dnl Check for compiler builtins
236 AX_GCC_BUILTIN([__builtin_bswap32])
237 AX_GCC_BUILTIN([__builtin_bswap64])
238 AX_GCC_BUILTIN([__builtin_clz])
239 AX_GCC_BUILTIN([__builtin_clzll])
240 AX_GCC_BUILTIN([__builtin_ctz])
241 AX_GCC_BUILTIN([__builtin_expect])
242 AX_GCC_BUILTIN([__builtin_ffs])
243 AX_GCC_BUILTIN([__builtin_ffsll])
244 AX_GCC_BUILTIN([__builtin_popcount])
245 AX_GCC_BUILTIN([__builtin_popcountll])
246 AX_GCC_BUILTIN([__builtin_unreachable])
247
248 AX_GCC_FUNC_ATTRIBUTE([const])
249 AX_GCC_FUNC_ATTRIBUTE([flatten])
250 AX_GCC_FUNC_ATTRIBUTE([format])
251 AX_GCC_FUNC_ATTRIBUTE([malloc])
252 AX_GCC_FUNC_ATTRIBUTE([packed])
253 AX_GCC_FUNC_ATTRIBUTE([pure])
254 AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
255 AX_GCC_FUNC_ATTRIBUTE([unused])
256 AX_GCC_FUNC_ATTRIBUTE([visibility])
257 AX_GCC_FUNC_ATTRIBUTE([warn_unused_result])
258 AX_GCC_FUNC_ATTRIBUTE([weak])
259 AX_GCC_FUNC_ATTRIBUTE([alias])
260 AX_GCC_FUNC_ATTRIBUTE([noreturn])
261
262 AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
263
264 dnl Make sure the pkg-config macros are defined
265 m4_ifndef([PKG_PROG_PKG_CONFIG],
266     [m4_fatal([Could not locate the pkg-config autoconf macros.
267   These are usually located in /usr/share/aclocal/pkg.m4. If your macros
268   are in a different location, try setting the environment variable
269   ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])])
270 PKG_PROG_PKG_CONFIG()
271
272 dnl LIB_DIR - library basename
273 LIB_DIR=`echo $libdir | $SED 's%.*/%%'`
274 AC_SUBST([LIB_DIR])
275
276 dnl Cache LDFLAGS and CPPFLAGS so we can add to them and restore later
277 _SAVE_LDFLAGS="$LDFLAGS"
278 _SAVE_CPPFLAGS="$CPPFLAGS"
279
280 dnl Compiler macros
281 DEFINES="-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
282 AC_SUBST([DEFINES])
283 android=no
284 case "$host_os" in
285 *-android*)
286     android=yes
287     ;;
288 linux*|*-gnu*|gnu*|cygwin*)
289     DEFINES="$DEFINES -D_GNU_SOURCE"
290     ;;
291 solaris*)
292     DEFINES="$DEFINES -DSVR4"
293     ;;
294 esac
295
296 AM_CONDITIONAL(HAVE_ANDROID, test "x$android" = xyes)
297
298 # Toggle Werror since at some point clang started treating unknown -W
299 # flags as warnings, succeeding with the build, yet issuing an annoying
300 # warning.
301 save_CFLAGS="$CFLAGS"
302 export CFLAGS="$CFLAGS -Werror"
303
304 dnl
305 dnl Check compiler flags
306 dnl
307 AX_CHECK_COMPILE_FLAG([-Wall],                                 [CFLAGS="$CFLAGS -Wall"])
308 AX_CHECK_COMPILE_FLAG([-Werror=implicit-function-declaration], [CFLAGS="$CFLAGS -Werror=implicit-function-declaration"])
309 AX_CHECK_COMPILE_FLAG([-Werror=missing-prototypes],            [CFLAGS="$CFLAGS -Werror=missing-prototypes"])
310 AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes],                  [CFLAGS="$CFLAGS -Wmissing-prototypes"])
311 dnl Dylan Baker: gcc and clang always accepr -Wno-*, hence check for the original warning, then set the no-* flag
312 AX_CHECK_COMPILE_FLAG([-Wmissing-field-initializers],          [CFLAGS="$CFLAGS -Wno-missing-field-initializers"])
313 AX_CHECK_COMPILE_FLAG([-Wformat-truncation],                   [CFLAGS="$CFLAGS -Wno-format-truncation"])
314 AX_CHECK_COMPILE_FLAG([-fno-math-errno],                       [CFLAGS="$CFLAGS -fno-math-errno"])
315
316 AX_CHECK_COMPILE_FLAG([-fno-trapping-math],                    [CFLAGS="$CFLAGS -fno-trapping-math"])
317 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],                   [VISIBILITY_CFLAGS="-fvisibility=hidden"])
318
319 CFLAGS="$save_CFLAGS"
320
321 # Toggle Werror since at some point clang started treating unknown -W
322 # flags as warnings, succeeding with the build, yet issuing an annoying
323 # warning.
324 dnl
325 dnl Check C++ compiler flags
326 dnl
327 AC_LANG_PUSH([C++])
328 AX_CHECK_COMPILE_FLAG([-Wall],                                 [CXXFLAGS="$CXXFLAGS -Wall"])
329 AX_CHECK_COMPILE_FLAG([-fno-math-errno],                       [CXXFLAGS="$CXXFLAGS -fno-math-errno"])
330 AX_CHECK_COMPILE_FLAG([-fno-trapping-math],                    [CXXFLAGS="$CXXFLAGS -fno-trapping-math"])
331 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],                   [VISIBILITY_CXXFLAGS="-fvisibility=hidden"])
332 AX_CHECK_COMPILE_FLAG([-Wmissing-field-initializers],          [CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers"])
333 AX_CHECK_COMPILE_FLAG([-Wformat-truncation],                   [CXXFLAGS="$CXXFLAGS -Wno-format-truncation"])
334 AC_LANG_POP([C++])
335
336 # Flags to help ensure that certain portions of the code -- and only those
337 # portions -- can be built with MSVC:
338 # - src/util, src/gallium/auxiliary, rc/gallium/drivers/llvmpipe, and
339 # - non-Linux/Posix OpenGL portions needs to build on MSVC 2013 (which
340 #   supports most of C99)
341 # - the rest has no compiler compiler restrictions
342 AX_CHECK_COMPILE_FLAG([-Werror=pointer-arith],                 [MSVC2013_COMPAT_CFLAGS="$MSVC2013_COMPAT_CFLAGS -Werror=pointer-arith"])
343 AX_CHECK_COMPILE_FLAG([-Werror=vla],                           [MSVC2013_COMPAT_CFLAGS="$MSVC2013_COMPAT_CFLAGS -Werror=vla"])
344 AC_LANG_PUSH([C++])
345 AX_CHECK_COMPILE_FLAG([-Werror=pointer-arith],                 [MSVC2013_COMPAT_CXXFLAGS="$MSVC2013_COMPAT_CXXFLAGS -Werror=pointer-arith"])
346 AX_CHECK_COMPILE_FLAG([-Werror=vla],                           [MSVC2013_COMPAT_CXXFLAGS="$MSVC2013_COMPAT_CXXFLAGS -Werror=vla"])
347 AC_LANG_POP([C++])
348
349 AC_SUBST([MSVC2013_COMPAT_CFLAGS])
350 AC_SUBST([MSVC2013_COMPAT_CXXFLAGS])
351
352 if test "x$GCC" = xyes; then
353     if test "x$USE_GNU99" = xyes; then
354         CFLAGS="$CFLAGS -std=gnu99"
355     else
356         CFLAGS="$CFLAGS -std=c99"
357     fi
358 fi
359
360 dnl
361 dnl Check whether C++11 is supported, if the environment variable
362 dnl CXX11_CXXFLAGS is set it takes precedence.
363 dnl
364
365 AC_LANG_PUSH([C++])
366
367 check_cxx11_available() {
368     output_support=$1
369     AC_COMPILE_IFELSE(
370         [AC_LANG_PROGRAM([
371              #if !(__cplusplus >= 201103L)
372              #error
373              #endif
374              #include <tuple>
375         ])
376     ], [
377          AC_MSG_RESULT(yes)
378          cxx11_support=yes
379     ], AC_MSG_RESULT(no))
380     eval "$output_support=\$cxx11_support"
381 }
382
383 HAVE_CXX11=no
384 save_CXXFLAGS="$CXXFLAGS"
385
386 dnl If the user provides a flag to enable c++11, then we test only this
387 if test "x$CXX11_CXXFLAGS" != "x"; then
388    CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
389    AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
390    check_cxx11_available HAVE_CXX11
391 else
392    dnl test whether c++11 is enabled by default
393    AC_MSG_CHECKING(whether c++11 is enabled by default)
394    check_cxx11_available HAVE_CXX11
395
396    dnl C++11 not enabled by default, test whether -std=c++11 does the job
397    if test "x$HAVE_CXX11" != "xyes"; then
398        CXX11_CXXFLAGS=-std=c++11
399        CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
400        AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
401        check_cxx11_available HAVE_CXX11
402    fi
403 fi
404
405 CXXFLAGS="$save_CXXFLAGS"
406 AM_CONDITIONAL(HAVE_STD_CXX11, test "x$HAVE_CXX11" = "xyes")
407 AC_SUBST(CXX11_CXXFLAGS)
408 AC_LANG_POP([C++])
409
410 dnl even if the compiler appears to support it, using visibility attributes isn't
411 dnl going to do anything useful currently on cygwin apart from emit lots of warnings
412 case "$host_os" in
413 cygwin*)
414     VISIBILITY_CFLAGS=""
415     VISIBILITY_CXXFLAGS=""
416     ;;
417 esac
418
419 AC_SUBST([VISIBILITY_CFLAGS])
420 AC_SUBST([VISIBILITY_CXXFLAGS])
421
422 dnl For some reason, the test for -Wno-foo always succeeds with gcc, even if the
423 dnl option is not supported. Hence, check for -Wfoo instead.
424 AX_CHECK_COMPILE_FLAG([-Woverride-init],                    [WNO_OVERRIDE_INIT="$WNO_OVERRIDE_INIT -Wno-override-init"])         # gcc
425 AX_CHECK_COMPILE_FLAG([-Winitializer-overrides],            [WNO_OVERRIDE_INIT="$WNO_OVERRIDE_INIT -Wno-initializer-overrides"]) # clang
426 AC_SUBST([WNO_OVERRIDE_INIT])
427
428 dnl
429 dnl Optional flags, check for compiler support
430 dnl
431 SSE41_CFLAGS="-msse4.1"
432 dnl Code compiled by GCC with -msse* assumes a 16 byte aligned
433 dnl stack, but on x86-32 such alignment is not guaranteed.
434 case "$target_cpu" in
435 i?86)
436     SSE41_CFLAGS="$SSE41_CFLAGS -mstackrealign"
437     ;;
438 esac
439 save_CFLAGS="$CFLAGS"
440 CFLAGS="$SSE41_CFLAGS $CFLAGS"
441 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
442 #include <smmintrin.h>
443 int param;
444 int main () {
445     __m128i a = _mm_set1_epi32 (param), b = _mm_set1_epi32 (param + 1), c;
446     c = _mm_max_epu32(a, b);
447     return _mm_cvtsi128_si32(c);
448 }]])], SSE41_SUPPORTED=1)
449 CFLAGS="$save_CFLAGS"
450 if test "x$SSE41_SUPPORTED" = x1; then
451     DEFINES="$DEFINES -DUSE_SSE41"
452 fi
453 AM_CONDITIONAL([SSE41_SUPPORTED], [test x$SSE41_SUPPORTED = x1])
454 AC_SUBST([SSE41_CFLAGS], $SSE41_CFLAGS)
455
456 dnl Check for new-style atomic builtins. We first check without linking to
457 dnl -latomic.
458 AC_MSG_CHECKING(whether __atomic_load_n is supported)
459 AC_LINK_IFELSE([AC_LANG_SOURCE([[
460 #include <stdint.h>
461 int main() {
462     struct {
463         uint64_t *v;
464     } x;
465     return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
466            (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
467 }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=yes, GCC_ATOMIC_BUILTINS_SUPPORTED=no)
468
469 dnl If that didn't work, we try linking with -latomic, which is needed on some
470 dnl platforms.
471 if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != xyes; then
472    save_LDFLAGS=$LDFLAGS
473    LDFLAGS="$LDFLAGS -latomic"
474    AC_LINK_IFELSE([AC_LANG_SOURCE([[
475    #include <stdint.h>
476    int main() {
477         struct {
478             uint64_t *v;
479         } x;
480         return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
481                (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
482    }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=yes LIBATOMIC_LIBS="-latomic",
483           GCC_ATOMIC_BUILTINS_SUPPORTED=no)
484    LDFLAGS=$save_LDFLAGS
485 fi
486 AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_SUPPORTED)
487
488 if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" = xyes; then
489     DEFINES="$DEFINES -DUSE_GCC_ATOMIC_BUILTINS"
490 fi
491 AC_SUBST([LIBATOMIC_LIBS])
492
493 dnl Check if host supports 64-bit atomics
494 dnl note that lack of support usually results in link (not compile) error
495 AC_MSG_CHECKING(whether __sync_add_and_fetch_8 is supported)
496 AC_LINK_IFELSE([AC_LANG_SOURCE([[
497 #include <stdint.h>
498 uint64_t v;
499 int main() {
500     return __sync_add_and_fetch(&v, (uint64_t)1);
501 }]])], GCC_64BIT_ATOMICS_SUPPORTED=yes, GCC_64BIT_ATOMICS_SUPPORTED=no)
502 if test "x$GCC_64BIT_ATOMICS_SUPPORTED" != xyes; then
503     DEFINES="$DEFINES -DMISSING_64BIT_ATOMICS"
504 fi
505 AC_MSG_RESULT($GCC_64BIT_ATOMICS_SUPPORTED)
506
507 dnl Check for Endianness
508 AC_C_BIGENDIAN(
509    little_endian=no,
510    little_endian=yes,
511    little_endian=no,
512    little_endian=no
513 )
514
515 dnl Check for POWER8 Architecture
516 PWR8_CFLAGS="-mpower8-vector"
517 have_pwr8_intrinsics=no
518 AC_MSG_CHECKING(whether gcc supports -mpower8-vector)
519 save_CFLAGS=$CFLAGS
520 CFLAGS="$PWR8_CFLAGS $CFLAGS"
521 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
522 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
523 #error "Need GCC >= 4.8 for sane POWER8 support"
524 #endif
525 #include <altivec.h>
526 int main () {
527     vector unsigned char r;
528     vector unsigned int v = vec_splat_u32 (1);
529     r = __builtin_vec_vgbbd ((vector unsigned char) v);
530     return 0;
531 }]])], have_pwr8_intrinsics=yes)
532 CFLAGS=$save_CFLAGS
533
534 AC_ARG_ENABLE(pwr8,
535    [AS_HELP_STRING([--disable-pwr8],
536                    [disable POWER8-specific instructions])],
537    [enable_pwr8=$enableval], [enable_pwr8=auto])
538
539 if test "x$enable_pwr8" = xno ; then
540    have_pwr8_intrinsics=disabled
541 fi
542
543 if test $have_pwr8_intrinsics = yes && test $little_endian = yes ; then
544    DEFINES="$DEFINES -D_ARCH_PWR8"
545    CXXFLAGS="$CXXFLAGS $PWR8_CFLAGS"
546    CFLAGS="$CFLAGS $PWR8_CFLAGS"
547 else
548    PWR8_CFLAGS=
549 fi
550
551 AC_MSG_RESULT($have_pwr8_intrinsics)
552 if test "x$enable_pwr8" = xyes && test $have_pwr8_intrinsics = no ; then
553    AC_MSG_ERROR([POWER8 compiler support not detected])
554 fi
555
556 if test $have_pwr8_intrinsics = yes && test $little_endian = no ; then
557    AC_MSG_WARN([POWER8 optimization is enabled only on POWER8 Little-Endian])
558 fi
559
560 AC_SUBST([PWR8_CFLAGS], $PWR8_CFLAGS)
561
562 dnl Can't have static and shared libraries, default to static if user
563 dnl explicitly requested. If both disabled, set to static since shared
564 dnl was explicitly requested.
565 case "x$enable_static$enable_shared" in
566 xyesyes)
567     AC_MSG_ERROR([Cannot enable both static and shared. Building using --enable-shared is strongly recommended])
568     ;;
569 xnono)
570     AC_MSG_ERROR([Cannot disable both static and shared. Building using --enable-shared is strongly recommended])
571     ;;
572 esac
573
574 AM_CONDITIONAL(BUILD_SHARED, test "x$enable_shared" = xyes)
575
576 dnl
577 dnl other compiler options
578 dnl
579 AC_ARG_ENABLE([debug],
580     [AS_HELP_STRING([--enable-debug],
581         [use debug compiler flags and macros @<:@default=disabled@:>@])],
582     [enable_debug="$enableval"],
583     [enable_debug=no]
584 )
585
586 AC_ARG_ENABLE([profile],
587     [AS_HELP_STRING([--enable-profile],
588         [enable profiling of code @<:@default=disabled@:>@])],
589     [enable_profile="$enableval"],
590     [enable_profile=no]
591 )
592
593 AC_ARG_ENABLE([sanitize],
594     [AS_HELP_STRING([--enable-sanitize@<:@=address|undefined@:>@],
595         [enable code sanitizer @<:@default=disabled@:>@])],
596     [enable_sanitize="$enableval"],
597     [enable_sanitize=no])
598
599 if test "x$enable_profile" = xyes; then
600     DEFINES="$DEFINES -DPROFILE"
601     if test "x$GCC" = xyes; then
602         CFLAGS="$CFLAGS -fno-omit-frame-pointer"
603     fi
604     if test "x$GXX" = xyes; then
605         CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"
606     fi
607 fi
608
609 if test "x$enable_debug" = xyes; then
610     DEFINES="$DEFINES -DDEBUG"
611     if test "x$enable_profile" = xyes; then
612         AC_MSG_WARN([Debug and Profile are enabled at the same time])
613     fi
614     if test "x$GCC" = xyes; then
615         if ! echo "$CFLAGS" | grep -q -e '-g'; then
616             CFLAGS="$CFLAGS -g"
617         fi
618         if ! echo "$CFLAGS" | grep -q -e '-O'; then
619             CFLAGS="$CFLAGS -O0"
620         fi
621     fi
622     if test "x$GXX" = xyes; then
623         if ! echo "$CXXFLAGS" | grep -q -e '-g'; then
624             CXXFLAGS="$CXXFLAGS -g"
625         fi
626         if ! echo "$CXXFLAGS" | grep -q -e '-O'; then
627             CXXFLAGS="$CXXFLAGS -O0"
628         fi
629     fi
630 else
631    DEFINES="$DEFINES -DNDEBUG"
632 fi
633
634 if test "x$enable_sanitize" != xno; then
635     if test "x$enable_profile" = xyes; then
636         AC_MSG_WARN([Sanitize and Profile are enabled at the same time])
637     fi
638
639     CFLAGS="$CFLAGS -fsanitize=$enable_sanitize"
640     CXXFLAGS="$CXXFLAGS -fsanitize=$enable_sanitize"
641     LDFLAGS="$LDFLAGS -fsanitize=$enable_sanitize"
642
643     AC_LINK_IFELSE(
644         [AC_LANG_SOURCE([int main(){return 0;}])],
645         [],
646         [AC_MSG_FAILURE([sanitize flags '$enable_sanitize' not supported])])
647 fi
648
649 dnl
650 dnl Check if linker supports -Bsymbolic
651 dnl
652 save_LDFLAGS=$LDFLAGS
653 LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
654 AC_MSG_CHECKING([if ld supports -Bsymbolic])
655 AC_LINK_IFELSE(
656     [AC_LANG_SOURCE([int main() { return 0;}])],
657     [AC_MSG_RESULT([yes])
658         BSYMBOLIC="-Wl,-Bsymbolic";],
659     [AC_MSG_RESULT([no])
660         BSYMBOLIC="";])
661 LDFLAGS=$save_LDFLAGS
662
663 AC_SUBST([BSYMBOLIC])
664
665 dnl
666 dnl Check if linker supports garbage collection
667 dnl
668 save_LDFLAGS=$LDFLAGS
669 LDFLAGS="$LDFLAGS -Wl,--gc-sections"
670 AC_MSG_CHECKING([whether ld supports --gc-sections])
671 AC_LINK_IFELSE(
672     [AC_LANG_SOURCE([static char UnusedFunc() { return 5; } int main() { return 0;}])],
673     [AC_MSG_RESULT([yes])
674         GC_SECTIONS="-Wl,--gc-sections";],
675     [AC_MSG_RESULT([no])
676         GC_SECTIONS="";])
677 LDFLAGS=$save_LDFLAGS
678
679 AC_SUBST([GC_SECTIONS])
680
681 dnl
682 dnl OpenBSD does not have DT_NEEDED entries for libc by design
683 dnl so when these flags are passed to ld via libtool the checks will fail
684 dnl
685 case "$host_os" in
686 openbsd* | darwin* )
687     LD_NO_UNDEFINED="" ;;
688 *)
689     if test "x$enable_sanitize" = xno; then
690         LD_NO_UNDEFINED="-Wl,--no-undefined"
691     else
692         LD_NO_UNDEFINED=""
693     fi
694     ;;
695 esac
696
697 AC_SUBST([LD_NO_UNDEFINED])
698
699 dnl
700 dnl Check if linker supports version scripts
701 dnl
702 AC_MSG_CHECKING([if the linker supports version-scripts])
703 save_LDFLAGS=$LDFLAGS
704 LDFLAGS="$LDFLAGS -Wl,--version-script=$srcdir/build-support/conftest.map"
705 AC_LINK_IFELSE(
706     [AC_LANG_SOURCE([int main() { return 0;}])],
707     [have_ld_version_script=yes;AC_MSG_RESULT(yes)],
708     [have_ld_version_script=no; AC_MSG_RESULT(no)])
709 LDFLAGS=$save_LDFLAGS
710 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
711
712 dnl
713 dnl Check if linker supports dynamic list files
714 dnl
715 AC_MSG_CHECKING([if the linker supports --dynamic-list])
716 save_LDFLAGS=$LDFLAGS
717 LDFLAGS="$LDFLAGS -Wl,--dynamic-list=$srcdir/build-support/conftest.dyn"
718 AC_LINK_IFELSE(
719     [AC_LANG_SOURCE([int main() { return 0;}])],
720     [have_ld_dynamic_list=yes;AC_MSG_RESULT(yes)],
721     [have_ld_dynamic_list=no; AC_MSG_RESULT(no)])
722 LDFLAGS=$save_LDFLAGS
723 AM_CONDITIONAL(HAVE_LD_DYNAMIC_LIST, test "$have_ld_dynamic_list" = "yes")
724
725 dnl
726 dnl OSX linker does not support build-id
727 dnl
728 case "$host_os" in
729 darwin*)
730     LD_BUILD_ID=""
731     ;;
732 *)
733     LD_BUILD_ID="-Wl,--build-id=sha1"
734     ;;
735 esac
736 AC_SUBST([LD_BUILD_ID])
737
738 dnl
739 dnl compatibility symlinks
740 dnl
741 case "$host_os" in
742 linux* )
743     HAVE_COMPAT_SYMLINKS=yes ;;
744 * )
745     HAVE_COMPAT_SYMLINKS=no ;;
746 esac
747
748 AM_CONDITIONAL(HAVE_COMPAT_SYMLINKS, test "x$HAVE_COMPAT_SYMLINKS" = xyes)
749
750 dnl
751 dnl library names
752 dnl
753 dnl Unfortunately we need to do a few things that libtool can't help us with,
754 dnl so we need some knowledge of shared library filenames:
755 dnl
756 dnl LIB_EXT is the extension used when creating symlinks for alternate
757 dnl filenames for a shared library which will be dynamically loaded
758 dnl
759 dnl IMP_LIB_EXT is the extension used when checking for the presence of a
760 dnl the file for a shared library we wish to link with
761 dnl
762 case "$host_os" in
763 darwin* )
764     LIB_EXT='dylib'
765     IMP_LIB_EXT=$LIB_EXT
766     ;;
767 cygwin* )
768     LIB_EXT='dll'
769     IMP_LIB_EXT='dll.a'
770     ;;
771 aix* )
772     LIB_EXT='a'
773     IMP_LIB_EXT=$LIB_EXT
774     ;;
775 * )
776     LIB_EXT='so'
777     IMP_LIB_EXT=$LIB_EXT
778     ;;
779 esac
780
781 AC_SUBST([LIB_EXT])
782
783 dnl
784 dnl Arch/platform-specific settings
785 dnl
786 AC_ARG_ENABLE([asm],
787     [AS_HELP_STRING([--disable-asm],
788         [disable assembly usage @<:@default=enabled on supported platforms@:>@])],
789     [enable_asm="$enableval"],
790     [enable_asm=yes]
791 )
792 asm_arch=""
793 AC_MSG_CHECKING([whether to enable assembly])
794 test "x$enable_asm" = xno && AC_MSG_RESULT([no])
795 # disable if cross compiling on x86/x86_64 since we must run gen_matypes
796 if test "x$enable_asm" = xyes -a "x$cross_compiling" = xyes; then
797     case "$host_cpu" in
798     i?86 | x86_64 | amd64)
799         if test "x$host_cpu" != "x$target_cpu"; then
800             enable_asm=no
801             AC_MSG_RESULT([no, cross compiling])
802         fi
803         ;;
804     esac
805 fi
806 # check for supported arches
807 if test "x$enable_asm" = xyes; then
808     case "$host_cpu" in
809     i?86)
810         case "$host_os" in
811         linux* | *freebsd* | dragonfly* | *netbsd* | openbsd* | gnu*)
812             asm_arch=x86
813             ;;
814         esac
815         ;;
816     x86_64|amd64)
817         case "$host_os" in
818         linux* | *freebsd* | dragonfly* | *netbsd* | openbsd*)
819             asm_arch=x86_64
820             ;;
821         esac
822         ;;
823     sparc*)
824         case "$host_os" in
825         linux*)
826             asm_arch=sparc
827             ;;
828         esac
829         ;;
830     powerpc64le)
831         case "$host_os" in
832         linux*)
833             asm_arch=ppc64le
834             ;;
835         esac
836         ;;
837     aarch64)
838         case "$host_os" in
839         linux*)
840             asm_arch=aarch64
841             ;;
842         esac
843         ;;
844     arm)
845         case "$host_os" in
846         linux*)
847             asm_arch=arm
848             ;;
849         esac
850         ;;
851     esac
852
853     case "$asm_arch" in
854     x86)
855         DEFINES="$DEFINES -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM"
856         AC_MSG_RESULT([yes, x86])
857         ;;
858     x86_64|amd64)
859         DEFINES="$DEFINES -DUSE_X86_64_ASM"
860         AC_MSG_RESULT([yes, x86_64])
861         ;;
862     sparc)
863         DEFINES="$DEFINES -DUSE_SPARC_ASM"
864         AC_MSG_RESULT([yes, sparc])
865         ;;
866     ppc64le)
867         DEFINES="$DEFINES -DUSE_PPC64LE_ASM"
868         AC_MSG_RESULT([yes, ppc64le])
869         ;;
870     aarch64)
871         DEFINES="$DEFINES -DUSE_AARCH64_ASM"
872         AC_MSG_RESULT([yes, aarch64])
873         ;;
874     arm)
875         DEFINES="$DEFINES -DUSE_ARM_ASM"
876         AC_MSG_RESULT([yes, arm])
877         ;;
878     *)
879         AC_MSG_RESULT([no, platform not supported])
880         ;;
881     esac
882 fi
883
884 AC_HEADER_MAJOR
885 AC_CHECK_HEADER([xlocale.h], [DEFINES="$DEFINES -DHAVE_XLOCALE_H"])
886 AC_CHECK_HEADER([sys/sysctl.h], [DEFINES="$DEFINES -DHAVE_SYS_SYSCTL_H"])
887 AC_CHECK_HEADERS([endian.h])
888 AC_CHECK_HEADER([dlfcn.h], [DEFINES="$DEFINES -DHAVE_DLFCN_H"])
889 AC_CHECK_FUNC([strtof], [DEFINES="$DEFINES -DHAVE_STRTOF"])
890 AC_CHECK_FUNC([mkostemp], [DEFINES="$DEFINES -DHAVE_MKOSTEMP"])
891 AC_CHECK_FUNC([timespec_get], [DEFINES="$DEFINES -DHAVE_TIMESPEC_GET"])
892 AC_CHECK_FUNC([memfd_create], [DEFINES="$DEFINES -DHAVE_MEMFD_CREATE"])
893
894 AC_MSG_CHECKING([whether strtod has locale support])
895 AC_LINK_IFELSE([AC_LANG_SOURCE([[
896     #define _GNU_SOURCE
897     #include <stdlib.h>
898     #include <locale.h>
899     #ifdef HAVE_XLOCALE_H
900     #include <xlocale.h>
901     #endif
902     int main() {
903        locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
904        const char *s = "1.0";
905        char *end;
906        double d = strtod_l(s, end, loc);
907        float f = strtof_l(s, end, loc);
908        freelocale(loc);
909        return 0;
910     }]])],
911   [DEFINES="$DEFINES -DHAVE_STRTOD_L"];
912    AC_MSG_RESULT([yes]),
913    AC_MSG_RESULT([no]))
914
915 dnl Check to see if dlopen is in default libraries (like Solaris, which
916 dnl has it in libc), or if libdl is needed to get it.
917 AC_CHECK_FUNC([dlopen], [],
918     [AC_CHECK_LIB([dl], [dlopen],
919        [DLOPEN_LIBS="-ldl"])])
920 AC_SUBST([DLOPEN_LIBS])
921
922 dnl Check if that library also has dladdr
923 save_LIBS="$LIBS"
924 LIBS="$LIBS $DLOPEN_LIBS"
925 AC_CHECK_FUNCS([dladdr])
926 LIBS="$save_LIBS"
927
928 AC_CHECK_FUNC([dl_iterate_phdr], [DEFINES="$DEFINES -DHAVE_DL_ITERATE_PHDR"])
929
930 case "$host_os" in
931 darwin*)
932     ;;
933 *)
934     AC_CHECK_FUNCS([clock_gettime], [CLOCK_LIB=],
935                    [AC_CHECK_LIB([rt], [clock_gettime], [CLOCK_LIB=-lrt],
936                                  [AC_MSG_ERROR([Could not find clock_gettime])])])
937     AC_SUBST([CLOCK_LIB])
938     ;;
939 esac
940
941 dnl See if posix_memalign is available
942 AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"])
943
944 dnl Check for zlib
945 PKG_CHECK_MODULES([ZLIB], [zlib >= $ZLIB_REQUIRED])
946 DEFINES="$DEFINES -DHAVE_ZLIB"
947
948 dnl Check for pthreads
949 AX_PTHREAD
950 if test "x$ax_pthread_ok" = xno; then
951     AC_MSG_ERROR([Building mesa on this platform requires pthreads])
952 fi
953 dnl AX_PTHREADS leaves PTHREAD_LIBS empty for gcc and sets PTHREAD_CFLAGS
954 dnl to -pthread, which causes problems if we need -lpthread to appear in
955 dnl pkgconfig files.  Since Android doesn't have a pthread lib, this check
956 dnl is not valid for that platform.
957 if test "x$android" = xno; then
958     test -z "$PTHREAD_LIBS" && PTHREAD_LIBS="-lpthread"
959 fi
960 dnl According to the manual when using pthreads, one should add -pthread to
961 dnl both compile and link-time arguments.
962 dnl In practise that should be sufficient for all platforms, since any
963 dnl platforms build with GCC and Clang support the flag.
964 PTHREAD_LIBS="$PTHREAD_LIBS -pthread"
965
966 dnl pthread-stubs is mandatory on some BSD platforms, due to the nature of the
967 dnl project. Even then there's a notable issue as described in the project README
968 case "$host_os" in
969 linux* | cygwin* | darwin* | solaris* | *-gnu* | gnu* | openbsd*)
970     pthread_stubs_possible="no"
971     ;;
972 * )
973     pthread_stubs_possible="yes"
974     ;;
975 esac
976
977 if test "x$pthread_stubs_possible" = xyes; then
978     PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs >= 0.4)
979 fi
980
981 save_LIBS="$LIBS"
982 LIBS="$PTHREAD_LIBS"
983 AC_MSG_CHECKING(whether pthread_setaffinity_np is supported)
984 AC_LINK_IFELSE([AC_LANG_SOURCE([[
985     #define _GNU_SOURCE
986     #include <pthread.h>
987     int main() {
988        void *a = (void*) &pthread_setaffinity_np;
989        long b = (long) a;
990        return (int) b;
991     }]])],
992   [DEFINES="$DEFINES -DHAVE_PTHREAD_SETAFFINITY"];
993    AC_MSG_RESULT([yes]),
994    AC_MSG_RESULT([no]))
995 LIBS="$save_LIBS"
996
997 dnl Check for futex for fast inline simple_mtx_t.
998 AC_CHECK_HEADER([linux/futex.h], [DEFINES="$DEFINES -DHAVE_LINUX_FUTEX_H"])
999
1000 dnl SELinux awareness.
1001 AC_ARG_ENABLE([selinux],
1002     [AS_HELP_STRING([--enable-selinux],
1003         [Build SELinux-aware Mesa @<:@default=disabled@:>@])],
1004     [MESA_SELINUX="$enableval"],
1005     [MESA_SELINUX=no])
1006 if test "x$enable_selinux" = "xyes"; then
1007     PKG_CHECK_MODULES([SELINUX], [libselinux], [],
1008         [AC_CHECK_HEADER([selinux/selinux.h],[],
1009                          [AC_MSG_ERROR([SELinux headers not found])])
1010          AC_CHECK_LIB([selinux],[is_selinux_enabled],[],
1011                       [AC_MSG_ERROR([SELinux library not found])])
1012          SELINUX_LIBS="-lselinux"])
1013     DEFINES="$DEFINES -DMESA_SELINUX"
1014 fi
1015 AC_SUBST([SELINUX_CFLAGS])
1016 AC_SUBST([SELINUX_LIBS])
1017
1018 dnl
1019 dnl LLVM
1020 dnl
1021 AC_ARG_ENABLE([llvm-shared-libs],
1022     [AS_HELP_STRING([--enable-llvm-shared-libs],
1023         [link with LLVM shared libraries @<:@default=enabled@:>@])],
1024     [enable_llvm_shared_libs="$enableval"],
1025     [enable_llvm_shared_libs=yes])
1026
1027 AC_ARG_WITH([llvm-prefix],
1028     [AS_HELP_STRING([--with-llvm-prefix],
1029         [Prefix for LLVM installations in non-standard locations])],
1030     [llvm_prefix="$withval"],
1031     [llvm_prefix=''])
1032
1033 PKG_CHECK_MODULES([LIBELF], [libelf], [have_libelf=yes], [have_libelf=no])
1034 if test "x$have_libelf" = xno; then
1035    LIBELF_LIBS=''
1036    LIBELF_CFLAGS=''
1037    AC_CHECK_LIB([elf], [elf_memory], [have_libelf=yes;LIBELF_LIBS=-lelf], [have_libelf=no])
1038    AC_SUBST([LIBELF_LIBS])
1039    AC_SUBST([LIBELF_CFLAGS])
1040 fi
1041
1042 if test -z "$LLVM_CONFIG"; then
1043     if test -n "$llvm_prefix"; then
1044         AC_PATH_TOOL([LLVM_CONFIG], [llvm-config], [no], ["$llvm_prefix/bin"])
1045     else
1046         AC_PATH_TOOL([LLVM_CONFIG], [llvm-config], [no])
1047     fi
1048 fi
1049
1050 llvm_add_component() {
1051     new_llvm_component=$1
1052     driver_name=$2
1053
1054     if $LLVM_CONFIG --components | grep -iqw $new_llvm_component ; then
1055         LLVM_COMPONENTS="${LLVM_COMPONENTS} ${new_llvm_component}"
1056     else
1057         AC_MSG_ERROR([LLVM component '$new_llvm_component' not enabled in your LLVM build. Required by $driver_name.])
1058     fi
1059 }
1060
1061 llvm_add_optional_component() {
1062     new_llvm_component=$1
1063     driver_name=$2
1064
1065     if $LLVM_CONFIG --components | grep -iqw $new_llvm_component ; then
1066         LLVM_COMPONENTS="${LLVM_COMPONENTS} ${new_llvm_component}"
1067     fi
1068 }
1069
1070 llvm_add_default_components() {
1071     driver_name=$1
1072
1073     # Required default components
1074     llvm_add_component "bitwriter" $driver_name
1075     llvm_add_component "engine" $driver_name
1076     llvm_add_component "mcdisassembler" $driver_name
1077     llvm_add_component "mcjit" $driver_name
1078
1079     # Optional default components
1080     llvm_add_optional_component "inteljitevents" $driver_name
1081 }
1082
1083 llvm_add_target() {
1084     new_llvm_target=$1
1085     driver_name=$2
1086
1087     if $LLVM_CONFIG --targets-built | grep -iqw $new_llvm_target ; then
1088         llvm_add_component $new_llvm_target $driver_name
1089     else
1090         AC_MSG_ERROR([LLVM target '$new_llvm_target' not enabled in your LLVM build. Required by $driver_name.])
1091     fi
1092 }
1093
1094 # Call this inside ` ` to get the return value.
1095 # $1 is the llvm-config command with arguments.
1096 strip_unwanted_llvm_flags() {
1097     echo " `$1` " | sed -E \
1098         -e 's/[[[:space:]]]+-m[[^[:space:]]]*//g' \
1099         -e 's/[[[:space:]]]+-DNDEBUG[[[:space:]]]/ /g' \
1100         -e 's/[[[:space:]]]+-D_GNU_SOURCE[[[:space:]]]/ /g' \
1101         -e 's/[[[:space:]]]+-pedantic[[[:space:]]]/ /g' \
1102         -e 's/[[[:space:]]]+-W[[^[:space:]]]*//g' \
1103         -e 's/[[[:space:]]]+-O[[^[:space:]]]*//g' \
1104         -e 's/[[[:space:]]]+-g[[^[:space:]]]*//g' \
1105         -e 's/-fno-rtti[[[:space:]]]/-Fno-rtti /g' \
1106         -e 's/[[[:space:]]]+-f[[^[:space:]]]*//g' \
1107         -e 's/-Fno-rtti[[[:space:]]]/-fno-rtti /g' \
1108         -e 's/^[[[:space:]]]//' \
1109         -e 's/[[[:space:]]]$//'
1110 }
1111
1112 llvm_set_environment_variables() {
1113     if test "x$LLVM_CONFIG" != xno; then
1114         LLVM_VERSION=`$LLVM_CONFIG --version | egrep -o '^[[0-9.]]+'`
1115         LLVM_CPPFLAGS=`strip_unwanted_llvm_flags "$LLVM_CONFIG --cppflags"`
1116         LLVM_INCLUDEDIR=`$LLVM_CONFIG --includedir`
1117         LLVM_LIBDIR=`$LLVM_CONFIG --libdir`
1118
1119         # We need to respect LLVM_CPPFLAGS when compiling LLVM headers.
1120         save_CFLAGS="$CFLAGS"
1121         CFLAGS="$CFLAGS $LLVM_CPPFLAGS"
1122
1123         AC_COMPUTE_INT([LLVM_VERSION_MAJOR], [LLVM_VERSION_MAJOR],
1124             [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
1125         AC_COMPUTE_INT([LLVM_VERSION_MINOR], [LLVM_VERSION_MINOR],
1126             [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
1127         AC_COMPUTE_INT([LLVM_VERSION_PATCH], [LLVM_VERSION_PATCH],
1128             [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
1129
1130         CFLAGS="$save_CFLAGS"
1131
1132         # Only needed for LLVM < 3.6.0
1133         if test -z "$LLVM_VERSION_PATCH"; then
1134             LLVM_VERSION_PATCH=0
1135         fi
1136
1137         LLVM_VERSION_INT="${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MINOR}"
1138
1139         FOUND_LLVM=yes
1140     else
1141         FOUND_LLVM=no
1142         LLVM_VERSION_INT=0
1143     fi
1144 }
1145
1146 require_llvm() {
1147     if test "x$enable_llvm" != "xyes"; then
1148         AC_MSG_ERROR([--enable-llvm is required when building $1])
1149     fi
1150 }
1151
1152 llvm_require_version() {
1153     require_llvm $2
1154
1155     llvm_target_version_major=`echo $1 | cut -d. -f1 | egrep -o '^[[0-9]]+'`
1156     llvm_target_version_minor=`echo $1 | cut -d. -f2 | egrep -o '^[[0-9]]+'`
1157     llvm_target_version_patch=`echo $1 | cut -d. -f3 | egrep -o '^[[0-9]]+'`
1158
1159     if test "$LLVM_VERSION_MAJOR" -gt "$llvm_target_version_major"; then
1160         # major > required major
1161         #  --> OK
1162         return
1163     fi
1164
1165     if test "$LLVM_VERSION_MAJOR" -eq "$llvm_target_version_major"; then
1166         if test "$LLVM_VERSION_MINOR" -gt "$llvm_target_version_minor"; then
1167             # major = required major and
1168             # minor > required minor
1169             #  --> OK
1170             return
1171         else
1172             if test "$LLVM_VERSION_MINOR" -eq "$llvm_target_version_minor"; then
1173                 if test "$LLVM_VERSION_PATCH" -ge "$llvm_target_version_patch"; then
1174                     # major = required major and
1175                     # minor = required minor and
1176                     # patch >= required patch
1177                     #  --> OK
1178                     return
1179                 fi
1180             fi
1181         fi
1182     fi
1183
1184     AC_MSG_ERROR([LLVM $1 or newer is required for $2])
1185 }
1186
1187 radeon_llvm_check() {
1188     if test ${LLVM_VERSION_INT} -lt 307; then
1189         amdgpu_llvm_target_name='r600'
1190     else
1191         amdgpu_llvm_target_name='amdgpu'
1192     fi
1193
1194     llvm_require_version $*
1195
1196     llvm_add_target $amdgpu_llvm_target_name $2
1197
1198     llvm_add_default_components $2
1199     llvm_add_component "bitreader" $2
1200     llvm_add_component "ipo" $2
1201
1202     if test "x$have_libelf" != xyes; then
1203        AC_MSG_ERROR([$2 requires libelf when using llvm])
1204     fi
1205 }
1206
1207 llvm_set_environment_variables
1208
1209 AC_SUBST([LLVM_CFLAGS])
1210 AC_SUBST([LLVM_CXXFLAGS])
1211 AC_SUBST([LLVM_LIBS])
1212 AC_SUBST([LLVM_LDFLAGS])
1213 AC_SUBST([LLVM_INCLUDEDIR])
1214
1215 dnl
1216 dnl libunwind
1217 dnl
1218 PKG_CHECK_EXISTS(libunwind, [HAVE_LIBUNWIND=yes], [HAVE_LIBUNWIND=no])
1219 AC_ARG_ENABLE([libunwind],
1220     [AS_HELP_STRING([--enable-libunwind],
1221             [Use libunwind for backtracing (default: auto)])],
1222         [LIBUNWIND="$enableval"],
1223         [LIBUNWIND="$HAVE_LIBUNWIND"])
1224
1225 if test "x$LIBUNWIND" = "xyes"; then
1226     PKG_CHECK_MODULES(LIBUNWIND, libunwind)
1227     AC_DEFINE(HAVE_LIBUNWIND, 1, [Have libunwind support])
1228 fi
1229
1230
1231 dnl Options for APIs
1232 AC_ARG_ENABLE([opengl],
1233     [AS_HELP_STRING([--disable-opengl],
1234         [disable support for standard OpenGL API @<:@default=enabled@:>@])],
1235     [enable_opengl="$enableval"],
1236     [enable_opengl=yes])
1237 AC_ARG_ENABLE([gles1],
1238     [AS_HELP_STRING([--disable-gles1],
1239         [disable support for OpenGL ES 1.x API @<:@default=enabled@:>@])],
1240     [enable_gles1="$enableval"],
1241     [enable_gles1=yes])
1242 AC_ARG_ENABLE([gles2],
1243     [AS_HELP_STRING([--disable-gles2],
1244         [disable support for OpenGL ES 2.x API @<:@default=enabled@:>@])],
1245     [enable_gles2="$enableval"],
1246     [enable_gles2=yes])
1247
1248 AC_ARG_ENABLE([dri],
1249     [AS_HELP_STRING([--enable-dri],
1250         [enable DRI modules @<:@default=enabled@:>@])],
1251     [enable_dri="$enableval"],
1252     [enable_dri=yes])
1253
1254 AC_ARG_ENABLE([gallium-extra-hud],
1255     [AS_HELP_STRING([--enable-gallium-extra-hud],
1256         [enable HUD block/NIC I/O HUD stats support @<:@default=disabled@:>@])],
1257     [enable_gallium_extra_hud="$enableval"],
1258     [enable_gallium_extra_hud=no])
1259 AM_CONDITIONAL(HAVE_GALLIUM_EXTRA_HUD, test "x$enable_gallium_extra_hud" = xyes)
1260 if test "x$enable_gallium_extra_hud" = xyes ; then
1261     DEFINES="${DEFINES} -DHAVE_GALLIUM_EXTRA_HUD=1"
1262 fi
1263
1264 #TODO: no pkgconfig .pc available for libsensors.
1265 #PKG_CHECK_MODULES([LIBSENSORS], [libsensors >= $LIBSENSORS_REQUIRED], [enable_lmsensors=yes], [enable_lmsensors=no])
1266 AC_ARG_ENABLE([lmsensors],
1267     [AS_HELP_STRING([--enable-lmsensors],
1268         [enable HUD lmsensor support @<:@default=disabled@:>@])],
1269     [enable_lmsensors="$enableval"],
1270     [enable_lmsensors=no])
1271 AM_CONDITIONAL(HAVE_LIBSENSORS, test "x$enable_lmsensors" = xyes)
1272 if test "x$enable_lmsensors" = xyes ; then
1273     DEFINES="${DEFINES} -DHAVE_LIBSENSORS=1"
1274     LIBSENSORS_LIBS="-lsensors"
1275 else
1276     LIBSENSORS_LIBS=""
1277 fi
1278 AC_SUBST(LIBSENSORS_LIBS)
1279
1280 case "$host_os" in
1281 linux*)
1282     dri3_default=yes
1283     ;;
1284 *)
1285     dri3_default=no
1286     ;;
1287 esac
1288
1289 if test "x$enable_dri" = xno; then
1290     dri3_default=no
1291 fi
1292
1293 AC_ARG_ENABLE([dri3],
1294     [AS_HELP_STRING([--enable-dri3],
1295         [enable DRI3 @<:@default=auto@:>@])],
1296     [enable_dri3="$enableval"],
1297     [enable_dri3="$dri3_default"])
1298 AC_ARG_ENABLE([glx],
1299     [AS_HELP_STRING([--enable-glx@<:@=dri|xlib|gallium-xlib@:>@],
1300         [enable the GLX library and choose an implementation @<:@default=auto@:>@])],
1301     [enable_glx="$enableval"],
1302     [enable_glx=yes])
1303 AC_ARG_ENABLE([osmesa],
1304     [AS_HELP_STRING([--enable-osmesa],
1305         [enable OSMesa library @<:@default=disabled@:>@])],
1306     [enable_osmesa="$enableval"],
1307     [enable_osmesa=no])
1308 AC_ARG_ENABLE([gallium-osmesa],
1309     [AS_HELP_STRING([--enable-gallium-osmesa],
1310         [enable Gallium implementation of the OSMesa library @<:@default=disabled@:>@])],
1311     [enable_gallium_osmesa="$enableval"],
1312     [enable_gallium_osmesa=no])
1313 AC_ARG_ENABLE([egl],
1314     [AS_HELP_STRING([--disable-egl],
1315         [disable EGL library @<:@default=enabled@:>@])],
1316     [enable_egl="$enableval"],
1317     [enable_egl=yes])
1318
1319 AC_ARG_ENABLE([xa],
1320     [AS_HELP_STRING([--enable-xa],
1321         [enable build of the XA X Acceleration API @<:@default=disabled@:>@])],
1322     [enable_xa="$enableval"],
1323     [enable_xa=no])
1324 AC_ARG_ENABLE([gbm],
1325    [AS_HELP_STRING([--enable-gbm],
1326          [enable gbm library @<:@default=yes except cygwin and macOS@:>@])],
1327    [enable_gbm="$enableval"],
1328    [case "$host_os" in
1329        cygwin* | darwin*)
1330           enable_gbm=no
1331           ;;
1332        *)
1333           enable_gbm=yes
1334           ;;
1335     esac])
1336 AC_ARG_ENABLE([nine],
1337     [AS_HELP_STRING([--enable-nine],
1338         [enable build of the nine Direct3D9 API @<:@default=no@:>@])],
1339     [enable_nine="$enableval"],
1340     [enable_nine=no])
1341
1342 AC_ARG_ENABLE([xvmc],
1343    [AS_HELP_STRING([--enable-xvmc],
1344          [enable xvmc library @<:@default=auto@:>@])],
1345    [enable_xvmc="$enableval"],
1346    [enable_xvmc=auto])
1347 AC_ARG_ENABLE([vdpau],
1348    [AS_HELP_STRING([--enable-vdpau],
1349          [enable vdpau library @<:@default=auto@:>@])],
1350    [enable_vdpau="$enableval"],
1351    [enable_vdpau=auto])
1352 AC_ARG_ENABLE([omx],
1353    [AS_HELP_STRING([--enable-omx],
1354          [DEPRECATED: Use --enable-omx-bellagio or --enable-omx-tizonia instead @<:@default=auto@:>@])],
1355    [AC_MSG_ERROR([--enable-omx is deprecated. Use --enable-omx-bellagio or --enable-omx-tizonia instead.])],
1356    [])
1357 AC_ARG_ENABLE([omx-bellagio],
1358    [AS_HELP_STRING([--enable-omx-bellagio],
1359          [enable OpenMAX Bellagio library @<:@default=disabled@:>@])],
1360    [enable_omx_bellagio="$enableval"],
1361    [enable_omx_bellagio=no])
1362 AC_ARG_ENABLE([omx-tizonia],
1363    [AS_HELP_STRING([--enable-omx-tizonia],
1364          [enable OpenMAX Tizonia library @<:@default=disabled@:>@])],
1365    [enable_omx_tizonia="$enableval"],
1366    [enable_omx_tizonia=no])
1367 AC_ARG_ENABLE([va],
1368    [AS_HELP_STRING([--enable-va],
1369          [enable va library @<:@default=auto@:>@])],
1370    [enable_va="$enableval"],
1371    [enable_va=auto])
1372 AC_ARG_ENABLE([opencl],
1373    [AS_HELP_STRING([--enable-opencl],
1374          [enable OpenCL library @<:@default=disabled@:>@])],
1375    [enable_opencl="$enableval"],
1376    [enable_opencl=no])
1377 AC_ARG_ENABLE([opencl_icd],
1378    [AS_HELP_STRING([--enable-opencl-icd],
1379           [Build an OpenCL ICD library to be loaded by an ICD implementation
1380            @<:@default=enabled@:>@])],
1381     [enable_opencl_icd="$enableval"],
1382     [enable_opencl_icd=yes])
1383
1384 AC_ARG_ENABLE([gallium-tests],
1385     [AS_HELP_STRING([--enable-gallium-tests],
1386         [Enable optional Gallium tests) @<:@default=disabled@:>@])],
1387     [enable_gallium_tests="$enableval"],
1388     [enable_gallium_tests=no])
1389
1390 # Option for Gallium drivers
1391
1392 # Keep this in sync with the --with-gallium-drivers help string default value
1393 GALLIUM_DRIVERS_DEFAULT="r300,r600,svga,swrast"
1394
1395 AC_ARG_WITH([gallium-drivers],
1396     [AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
1397         [comma delimited Gallium drivers list, e.g.
1398         "i915,nouveau,r300,r600,radeonsi,freedreno,pl111,svga,swrast,swr,tegra,v3d,vc4,virgl,etnaviv,imx"
1399         @<:@default=r300,r600,svga,swrast@:>@])],
1400     [with_gallium_drivers="$withval"],
1401     [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
1402
1403 # Doing '--without-gallium-drivers' will set this variable to 'no'.  Clear it
1404 # here so that the script doesn't choke on an unknown driver name later.
1405 case "$with_gallium_drivers" in
1406     yes) with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT" ;;
1407     no) with_gallium_drivers='' ;;
1408 esac
1409
1410 if test "x$enable_opengl" = xno -a \
1411         "x$enable_gles1" = xno -a \
1412         "x$enable_gles2" = xno -a \
1413         "x$enable_nine" = xno -a \
1414         "x$enable_xa" = xno -a \
1415         "x$enable_xvmc" = xno -a \
1416         "x$enable_vdpau" = xno -a \
1417         "x$enable_omx_bellagio" = xno -a \
1418         "x$enable_omx_tizonia" = xno -a \
1419         "x$enable_va" = xno -a \
1420         "x$enable_opencl" = xno; then
1421     AC_MSG_ERROR([at least one API should be enabled])
1422 fi
1423
1424 if test "x$enable_omx_bellagio" = xyes -a \
1425         "x$enable_omx_tizonia" = xyes; then
1426    AC_MSG_ERROR([Can't enable both bellagio and tizonia at same time])
1427 fi
1428
1429 # Building OpenGL ES1 and/or ES2 without OpenGL is not supported on mesa 9.0.x
1430 if test "x$enable_opengl" = xno -a \
1431         "x$enable_gles1" = xyes; then
1432     AC_MSG_ERROR([Building OpenGL ES1 without OpenGL is not supported])
1433 fi
1434
1435 if test "x$enable_opengl" = xno -a \
1436         "x$enable_gles2" = xyes; then
1437     AC_MSG_ERROR([Building OpenGL ES2 without OpenGL is not supported])
1438 fi
1439
1440 AM_CONDITIONAL(HAVE_OPENGL, test "x$enable_opengl" = xyes)
1441 AM_CONDITIONAL(HAVE_OPENGL_ES1, test "x$enable_gles1" = xyes)
1442 AM_CONDITIONAL(HAVE_OPENGL_ES2, test "x$enable_gles2" = xyes)
1443 AM_CONDITIONAL(NEED_OPENGL_COMMON, test "x$enable_opengl" = xyes -o \
1444                                         "x$enable_gles1" = xyes -o \
1445                                         "x$enable_gles2" = xyes)
1446 AM_CONDITIONAL(NEED_KHRPLATFORM, test "x$enable_egl" = xyes -o \
1447                                       "x$enable_opengl" = xyes -o \
1448                                       "x$enable_gles1" = xyes -o \
1449                                       "x$enable_gles2" = xyes)
1450
1451 # Validate GLX options
1452 if test "x$enable_glx" = xyes; then
1453     if test "x$enable_dri" = xyes; then
1454         enable_glx=dri
1455     elif test -n "$with_gallium_drivers"; then
1456         enable_glx=gallium-xlib
1457     else
1458         enable_glx=xlib
1459     fi
1460 fi
1461 case "x$enable_glx" in
1462 xdri | xxlib | xgallium-xlib)
1463     # GLX requires OpenGL
1464     if test "x$enable_opengl" = xno; then
1465         AC_MSG_ERROR([GLX cannot be built without OpenGL])
1466     fi
1467
1468     # Check individual dependencies
1469     case "x$enable_glx" in
1470     xdri)
1471         if test "x$enable_dri" = xno; then
1472             AC_MSG_ERROR([DRI-based GLX requires DRI to be enabled])
1473         fi
1474         ;;
1475     xxlib)
1476         if test "x$enable_dri" = xyes; then
1477             AC_MSG_ERROR([Xlib-based GLX cannot be built with DRI enabled])
1478         fi
1479         ;;
1480     xgallium-xlib )
1481         if test "x$enable_dri" = xyes; then
1482             AC_MSG_ERROR([Xlib-based (Gallium) GLX cannot be built with DRI enabled])
1483         fi
1484         if test -z "$with_gallium_drivers"; then
1485             AC_MSG_ERROR([Xlib-based (Gallium) GLX cannot be built without Gallium enabled])
1486         fi
1487         ;;
1488     esac
1489     ;;
1490 xno)
1491     ;;
1492 *)
1493     AC_MSG_ERROR([Illegal value for --enable-glx: $enable_glx])
1494     ;;
1495 esac
1496
1497 AM_CONDITIONAL(HAVE_GLX, test "x$enable_glx" != xno)
1498 AM_CONDITIONAL(HAVE_DRI_GLX, test "x$enable_glx" = xdri)
1499 AM_CONDITIONAL(HAVE_XLIB_GLX, test "x$enable_glx" = xxlib)
1500 AM_CONDITIONAL(HAVE_GALLIUM_XLIB_GLX, test "x$enable_glx" = xgallium-xlib)
1501
1502 DEFAULT_GL_LIB_NAME=GL
1503
1504 dnl
1505 dnl Libglvnd configuration
1506 dnl
1507 AC_ARG_ENABLE([libglvnd],
1508     [AS_HELP_STRING([--enable-libglvnd],
1509         [Build GLX and EGL for libglvnd @<:@default=disabled@:>@])],
1510     [enable_libglvnd="$enableval"],
1511     [enable_libglvnd=no])
1512 AM_CONDITIONAL(USE_LIBGLVND, test "x$enable_libglvnd" = xyes)
1513
1514 if test "x$enable_libglvnd" = xyes ; then
1515     case "x$enable_glx" in
1516     xxlib | xgallium-xlib )
1517         AC_MSG_ERROR([cannot build libgvnd when Xlib-GLX or Gallium-Xlib-GLX is enabled])
1518         ;;
1519     esac
1520
1521     PKG_CHECK_MODULES([GLVND], libglvnd >= 0.2.0)
1522     LIBGLVND_DATADIR=`$PKG_CONFIG --variable=datadir libglvnd`
1523     AC_SUBST([LIBGLVND_DATADIR])
1524
1525     DEFINES="${DEFINES} -DUSE_LIBGLVND=1"
1526     DEFAULT_GL_LIB_NAME=GLX_mesa
1527
1528     if test "x$enable_glx" = xno -a "x$enable_egl" = xno; then
1529         AC_MSG_ERROR([cannot build libglvnd without GLX or EGL])
1530     fi
1531 fi
1532
1533 AC_ARG_WITH([gl-lib-name],
1534   [AS_HELP_STRING([--with-gl-lib-name@<:@=NAME@:>@],
1535     [specify GL library name @<:@default=GL@:>@])],
1536   [AC_MSG_ERROR([--with-gl-lib-name is no longer supported. Rename the library manually if needed.])],
1537   [])
1538 AC_ARG_WITH([osmesa-lib-name],
1539   [AS_HELP_STRING([--with-osmesa-lib-name@<:@=NAME@:>@],
1540     [specify OSMesa library name @<:@default=OSMesa@:>@])],
1541   [AC_MSG_ERROR([--with-osmesa-lib-name is no longer supported. Rename the library manually if needed.])],
1542   [])
1543 GL_LIB="$DEFAULT_GL_LIB_NAME"
1544 OSMESA_LIB=OSMesa
1545
1546 dnl
1547 dnl Mangled Mesa support
1548 dnl
1549 AC_ARG_ENABLE([mangling],
1550   [AS_HELP_STRING([--enable-mangling],
1551     [enable mangled symbols and library name @<:@default=disabled@:>@])],
1552   [enable_mangling="${enableval}"],
1553   [enable_mangling=no]
1554 )
1555 if test "x${enable_mangling}" = "xyes" ; then
1556   if test "x$enable_libglvnd" = xyes; then
1557     AC_MSG_ERROR([Conflicting options --enable-mangling and --enable-libglvnd.])
1558   fi
1559   DEFINES="${DEFINES} -DUSE_MGL_NAMESPACE"
1560   GL_LIB="Mangled${GL_LIB}"
1561   OSMESA_LIB="Mangled${OSMESA_LIB}"
1562 fi
1563 AC_SUBST([GL_LIB])
1564 AC_SUBST([OSMESA_LIB])
1565
1566 dnl HACK when building glx + glvnd we ship gl.pc, despite that glvnd should do it
1567 dnl Thus we need to use GL as a DSO name.
1568 if test "x$enable_libglvnd" = xyes -a "x$enable_glx" != xno; then
1569   GL_PKGCONF_LIB="GL"
1570 else
1571   GL_PKGCONF_LIB="$GL_LIB"
1572 fi
1573 AC_SUBST([GL_PKGCONF_LIB])
1574
1575 # Check for libdrm
1576 PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED],
1577                   [have_libdrm=yes], [have_libdrm=no])
1578 if test "x$have_libdrm" = xyes; then
1579     DEFINES="$DEFINES -DHAVE_LIBDRM"
1580 fi
1581
1582 require_libdrm() {
1583     if test "x$have_libdrm" != xyes; then
1584        AC_MSG_ERROR([$1 requires libdrm >= $LIBDRM_REQUIRED])
1585     fi
1586 }
1587
1588
1589 # Select which platform-dependent DRI code gets built
1590 case "$host_os" in
1591 darwin*)
1592     dri_platform='apple' ;;
1593 cygwin*)
1594     dri_platform='windows' ;;
1595 gnu*)
1596     dri_platform='none' ;;
1597 *)
1598     dri_platform='drm' ;;
1599 esac
1600
1601 if test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes; then
1602     have_drisw_kms='yes'
1603 fi
1604
1605 AM_CONDITIONAL(HAVE_DRICOMMON, test "x$enable_dri" = xyes )
1606 AM_CONDITIONAL(HAVE_DRISW, test "x$enable_dri" = xyes )
1607 AM_CONDITIONAL(HAVE_DRISW_KMS, test "x$have_drisw_kms" = xyes )
1608 AM_CONDITIONAL(HAVE_DRI2, test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )
1609 AM_CONDITIONAL(HAVE_DRI3, test "x$enable_dri3" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )
1610 AM_CONDITIONAL(HAVE_APPLEDRI, test "x$enable_dri" = xyes -a "x$dri_platform" = xapple )
1611 AM_CONDITIONAL(HAVE_LMSENSORS, test "x$enable_lmsensors" = xyes )
1612 AM_CONDITIONAL(HAVE_GALLIUM_EXTRA_HUD, test "x$enable_gallium_extra_hud" = xyes )
1613 AM_CONDITIONAL(HAVE_WINDOWSDRI, test "x$enable_dri" = xyes -a "x$dri_platform" = xwindows )
1614 AM_CONDITIONAL(HAVE_XLEASE, test "x$have_xlease" = xyes )
1615
1616 AC_ARG_ENABLE([shared-glapi],
1617     [AS_HELP_STRING([--enable-shared-glapi],
1618         [Enable shared glapi for OpenGL @<:@default=enabled@:>@])],
1619     [enable_shared_glapi="$enableval"],
1620     [enable_shared_glapi=yes])
1621
1622 case "x$enable_opengl$enable_gles1$enable_gles2" in
1623 x*yes*yes*)
1624     if test "x$enable_shared_glapi" = xno; then
1625         AC_MSG_ERROR([shared GLAPI required when building two or more of
1626                       the following APIs - opengl, gles1 gles2])
1627     fi
1628     ;;
1629 esac
1630
1631 AM_CONDITIONAL(HAVE_SHARED_GLAPI, test "x$enable_shared_glapi" = xyes)
1632
1633 # Build the pipe-drivers as separate libraries/modules.
1634 # Do not touch this unless you know what you are doing.
1635 # XXX: Expose via configure option ?
1636 enable_shared_pipe_drivers=no
1637
1638 dnl
1639 dnl Driver specific build directories
1640 dnl
1641
1642 if test "x$enable_gallium_osmesa" = xyes; then
1643     if ! echo "$with_gallium_drivers" | grep -q 'swrast'; then
1644         AC_MSG_ERROR([gallium_osmesa requires the gallium swrast driver])
1645     fi
1646     if test "x$enable_osmesa" = xyes; then
1647         AC_MSG_ERROR([Cannot enable both classic and Gallium OSMesa implementations])
1648     fi
1649 fi
1650
1651 require_dri_shared_libs_and_glapi() {
1652     if test "x$enable_static" = xyes; then
1653         AC_MSG_ERROR([$1 cannot be build as static library])
1654     fi
1655
1656     if test "x$enable_dri" != xyes; then
1657         # There is only a single backend which won't be build/used otherwise.
1658         # XXX: Revisit this as the egl/haiku is a thing.
1659         AC_MSG_ERROR([$1 requires --enable-dri])
1660     fi
1661
1662     if test "x$enable_shared_glapi" != xyes; then
1663         AC_MSG_ERROR([$1 requires --enable-shared-glapi])
1664     fi
1665 }
1666
1667 if test "x$enable_dri" = xyes; then
1668     require_dri_shared_libs_and_glapi "DRI"
1669
1670     # not a hard requirement as swrast does not depend on it
1671     if test "x$have_libdrm" = xyes; then
1672         DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED"
1673     fi
1674 fi
1675
1676 AC_ARG_ENABLE([driglx-direct],
1677     [AS_HELP_STRING([--disable-driglx-direct],
1678         [disable direct rendering in GLX and EGL for DRI \
1679             @<:@default=enabled@:>@])],
1680     [driglx_direct="$enableval"],
1681     [driglx_direct="yes"])
1682
1683 dnl
1684 dnl libGL configuration per driver
1685 dnl
1686 if test "x$enable_glx" != xno; then
1687     PKG_CHECK_MODULES([GLPROTO], [glproto >= $GLPROTO_REQUIRED])
1688 fi
1689 case "x$enable_glx" in
1690 xxlib | xgallium-xlib)
1691     # Xlib-based GLX
1692     dri_modules="x11 xext xcb"
1693     PKG_CHECK_MODULES([XLIBGL], [$dri_modules])
1694     GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
1695     X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS"
1696     GL_LIB_DEPS="$XLIBGL_LIBS"
1697     GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
1698     GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm $PTHREAD_LIBS"
1699     ;;
1700 xdri)
1701     # DRI-based GLX
1702
1703     require_dri_shared_libs_and_glapi "GLX"
1704
1705     # find the DRI deps for libGL
1706     dri_modules="x11 xext xdamage >= $XDAMAGE_REQUIRED xfixes x11-xcb xcb xcb-glx >= $XCBGLX_REQUIRED"
1707
1708     if test x"$driglx_direct" = xyes; then
1709         if test x"$dri_platform" = xdrm ; then
1710             DEFINES="$DEFINES -DGLX_USE_DRM"
1711             require_libdrm "Direct rendering"
1712
1713             PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
1714             GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED"
1715
1716             if test x"$enable_dri" = xyes; then
1717                dri_modules="$dri_modules xcb-dri2 >= $XCBDRI2_REQUIRED"
1718             fi
1719
1720             dri_modules="$dri_modules xxf86vm"
1721         fi
1722         if test x"$dri_platform" = xapple ; then
1723             DEFINES="$DEFINES -DGLX_USE_APPLEGL"
1724         fi
1725         if test x"$dri_platform" = xwindows ; then
1726             DEFINES="$DEFINES -DGLX_USE_WINDOWSGL"
1727         fi
1728     fi
1729
1730     PKG_CHECK_MODULES([DRIGL], [$dri_modules])
1731     GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
1732     X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
1733     GL_LIB_DEPS="$DRIGL_LIBS"
1734
1735     # need DRM libs, $PTHREAD_LIBS, etc.
1736     GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
1737     GL_PC_LIB_PRIV="-lm $PTHREAD_LIBS $DLOPEN_LIBS"
1738     ;;
1739 esac
1740
1741 GLESv1_CM_LIB_DEPS="$LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
1742 GLESv1_CM_PC_LIB_PRIV="-lm $PTHREAD_LIBS $DLOPEN_LIBS"
1743 GLESv2_LIB_DEPS="$LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
1744 GLESv2_PC_LIB_PRIV="-lm $PTHREAD_LIBS $DLOPEN_LIBS"
1745
1746 AC_SUBST([X11_INCLUDES])
1747 AC_SUBST([GL_LIB_DEPS])
1748 AC_SUBST([GL_PC_REQ_PRIV])
1749 AC_SUBST([GL_PC_LIB_PRIV])
1750 AC_SUBST([GL_PC_CFLAGS])
1751 AC_SUBST([DRI_PC_REQ_PRIV])
1752 AC_SUBST([GLESv1_CM_LIB_DEPS])
1753 AC_SUBST([GLESv1_CM_PC_LIB_PRIV])
1754 AC_SUBST([GLESv2_LIB_DEPS])
1755 AC_SUBST([GLESv2_PC_LIB_PRIV])
1756
1757 dnl
1758 dnl More GLX setup
1759 dnl
1760 case "x$enable_glx" in
1761 xxlib | xgallium-xlib)
1762     DEFINES="$DEFINES -DUSE_XSHM"
1763     ;;
1764 xdri)
1765     DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING"
1766     if test "x$driglx_direct" = xyes; then
1767         DEFINES="$DEFINES -DGLX_DIRECT_RENDERING"
1768     fi
1769     ;;
1770 esac
1771
1772 dnl
1773 dnl TLS detection
1774 dnl
1775
1776 AC_ARG_ENABLE([glx-tls],
1777     [AS_HELP_STRING([--enable-glx-tls],
1778         [enable TLS support in GLX @<:@default=enabled@:>@])],
1779     [GLX_USE_TLS="$enableval"],
1780     [GLX_USE_TLS=yes])
1781 AC_SUBST(GLX_TLS, ${GLX_USE_TLS})
1782
1783 if test "x$GLX_USE_TLS" = xyes; then
1784     DEFINES="$DEFINES -DGLX_USE_TLS"
1785 fi
1786
1787 dnl Read-only text section on x86 hardened platforms
1788 AC_ARG_ENABLE([glx-read-only-text],
1789     [AS_HELP_STRING([--enable-glx-read-only-text],
1790         [Disable writable .text section on x86 (decreases performance) @<:@default=disabled@:>@])],
1791     [enable_glx_read_only_text="$enableval"],
1792     [enable_glx_read_only_text=no])
1793 if test "x$enable_glx_read_only_text" = xyes; then
1794     DEFINES="$DEFINES -DGLX_X86_READONLY_TEXT"
1795 fi
1796
1797 dnl
1798 dnl DEPRECATED: EGL Platforms configuration
1799 dnl
1800 AC_ARG_WITH([egl-platforms],
1801     [AS_HELP_STRING([--with-egl-platforms@<:@=DIRS...@:>@],
1802         [DEPRECATED: use --with-platforms instead@<:@default=auto@:>@])],
1803     [with_egl_platforms="$withval"],
1804     [with_egl_platforms=auto])
1805
1806 if test "x$with_egl_platforms" = xauto; then
1807     with_egl_platforms="x11,surfaceless"
1808     if test "x$enable_gbm" = xyes; then
1809         with_egl_platforms="$with_egl_platforms,drm"
1810     fi
1811 else
1812     AC_MSG_WARN([--with-egl-platforms is deprecated. Use --with-platforms instead.])
1813 fi
1814
1815 dnl
1816 dnl Platforms configuration
1817 dnl
1818 AC_ARG_WITH([platforms],
1819     [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
1820         [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
1821         "x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
1822     [with_platforms="$withval"],
1823     [with_platforms=auto])
1824
1825 # Reuse the autodetection rather than duplicating it.
1826 if test "x$with_platforms" = xauto; then
1827     with_platforms=$with_egl_platforms
1828 fi
1829
1830 # Do per platform setups and checks
1831 platforms=`IFS=', '; echo $with_platforms`
1832 for plat in $platforms; do
1833     case "$plat" in
1834     wayland)
1835
1836         PKG_CHECK_MODULES([WAYLAND_CLIENT], [wayland-client >= $WAYLAND_REQUIRED])
1837         PKG_CHECK_MODULES([WAYLAND_SERVER], [wayland-server >= $WAYLAND_REQUIRED])
1838         PKG_CHECK_MODULES([WAYLAND_PROTOCOLS], [wayland-protocols >= $WAYLAND_PROTOCOLS_REQUIRED])
1839         if test "x$enable_egl" = xyes; then
1840           PKG_CHECK_MODULES([WAYLAND_EGL], [wayland-egl-backend >= $WAYLAND_EGL_BACKEND_REQUIRED])
1841         fi
1842         WAYLAND_PROTOCOLS_DATADIR=`$PKG_CONFIG --variable=pkgdatadir wayland-protocols`
1843
1844         PKG_CHECK_MODULES([WAYLAND_SCANNER], [wayland-scanner],
1845                           WAYLAND_SCANNER=`$PKG_CONFIG --variable=wayland_scanner wayland-scanner`,
1846                           WAYLAND_SCANNER='')
1847         PKG_CHECK_EXISTS([wayland-scanner >= 1.15],
1848                           AC_SUBST(SCANNER_ARG, 'private-code'),
1849                           AC_SUBST(SCANNER_ARG, 'code'))
1850
1851         if test "x$WAYLAND_SCANNER" = x; then
1852             AC_PATH_PROG([WAYLAND_SCANNER], [wayland-scanner], [:])
1853         fi
1854
1855         if test "x$WAYLAND_SCANNER" = "x:"; then
1856                 AC_MSG_ERROR([wayland-scanner is needed to compile the wayland platform])
1857         fi
1858         DEFINES="$DEFINES -DHAVE_WAYLAND_PLATFORM -DWL_HIDE_DEPRECATED"
1859         ;;
1860
1861     x11)
1862         PKG_CHECK_MODULES([XCB_DRI2], [x11-xcb xcb xcb-dri2 >= $XCBDRI2_REQUIRED xcb-xfixes])
1863         DEFINES="$DEFINES -DHAVE_X11_PLATFORM"
1864         ;;
1865
1866     drm)
1867         test "x$enable_egl" = "xyes" &&
1868         test "x$enable_gbm" = "xno" &&
1869                 AC_MSG_ERROR([EGL platform drm needs gbm])
1870         DEFINES="$DEFINES -DHAVE_DRM_PLATFORM"
1871         ;;
1872
1873     surfaceless)
1874         DEFINES="$DEFINES -DHAVE_SURFACELESS_PLATFORM"
1875         ;;
1876
1877     android)
1878         PKG_CHECK_MODULES([ANDROID], [cutils hardware sync])
1879         if test -n "$with_gallium_drivers"; then
1880             PKG_CHECK_MODULES([BACKTRACE], [backtrace])
1881         fi
1882         DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
1883         ;;
1884
1885     *)
1886         AC_MSG_ERROR([platform '$plat' does not exist])
1887         ;;
1888     esac
1889
1890     case "$plat" in
1891     wayland|drm|surfaceless)
1892         require_libdrm "Platform $plat"
1893         ;;
1894     esac
1895 done
1896 AC_SUBST([WAYLAND_PROTOCOLS_DATADIR])
1897
1898 if test "x$enable_glx" != xno; then
1899     if ! echo "$platforms" | grep -q 'x11'; then
1900         AC_MSG_ERROR([Building GLX without the x11 platform is not supported])
1901     fi
1902 fi
1903
1904 if test x"$enable_dri3" = xyes; then
1905     DEFINES="$DEFINES -DHAVE_DRI3"
1906
1907     dri3_modules="x11-xcb xcb >= $XCB_REQUIRED xcb-dri3 xcb-xfixes xcb-present xcb-sync xshmfence >= $XSHMFENCE_REQUIRED"
1908     PKG_CHECK_MODULES([XCB_DRI3], [$dri3_modules])
1909     dri3_modifier_modules="xcb-dri3 >= $XCBDRI3_MODIFIERS_REQUIRED xcb-present >= $XCBPRESENT_MODIFIERS_REQUIRED"
1910     PKG_CHECK_MODULES([XCB_DRI3_MODIFIERS], [$dri3_modifier_modules], [have_dri3_modifiers=yes], [have_dri3_modifiers=no])
1911
1912     if test "x$have_dri3_modifiers" == xyes; then
1913         DEFINES="$DEFINES -DHAVE_DRI3_MODIFIERS"
1914     fi
1915 fi
1916
1917
1918 if echo "$platforms" | grep -q 'x11' && echo "$platforms" | grep -q 'drm'; then
1919     have_xlease=yes
1920 else
1921     have_xlease=no
1922 fi
1923
1924 if test x"$have_xlease" = xyes; then
1925     randr_modules="x11-xcb xcb-randr"
1926     PKG_CHECK_MODULES([XCB_RANDR], [$randr_modules])
1927     xlib_randr_modules="xrandr"
1928     PKG_CHECK_MODULES([XLIB_RANDR], [$xlib_randr_modules])
1929 fi
1930
1931 AM_CONDITIONAL(HAVE_PLATFORM_X11, echo "$platforms" | grep -q 'x11')
1932 AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | grep -q 'wayland')
1933 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
1934 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 'surfaceless')
1935 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
1936
1937 AC_ARG_ENABLE(xlib-lease,
1938     [AS_HELP_STRING([--enable-xlib-lease]
1939                     [enable VK_acquire_xlib_display using X leases])],
1940     [enable_xlib_lease=$enableval], [enable_xlib_lease=auto])
1941 case "x$enable_xlib_lease" in
1942 xyes)
1943     ;;
1944 xno)
1945     ;;
1946 *)
1947     if echo "$platforms" | grep -q 'x11' && echo "$platforms" | grep -q 'drm'; then
1948         enable_xlib_lease=yes
1949     else
1950         enable_xlib_lease=no
1951     fi
1952 esac
1953
1954 AM_CONDITIONAL(HAVE_XLIB_LEASE, test "x$enable_xlib_lease" = xyes)
1955
1956 dnl
1957 dnl More DRI setup
1958 dnl
1959 dnl Directory for DRI drivers
1960 AC_ARG_WITH([dri-driverdir],
1961     [AS_HELP_STRING([--with-dri-driverdir=DIR],
1962         [directory for the DRI drivers @<:@${libdir}/dri@:>@])],
1963     [DRI_DRIVER_INSTALL_DIR="$withval"],
1964     [DRI_DRIVER_INSTALL_DIR='${libdir}/dri'])
1965 AC_SUBST([DRI_DRIVER_INSTALL_DIR])
1966 dnl Extra search path for DRI drivers
1967 AC_ARG_WITH([dri-searchpath],
1968     [AS_HELP_STRING([--with-dri-searchpath=DIRS...],
1969         [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])],
1970     [DRI_DRIVER_SEARCH_DIR="$withval"],
1971     [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}'])
1972 AC_SUBST([DRI_DRIVER_SEARCH_DIR])
1973 dnl Which drivers to build - default is chosen by platform
1974 AC_ARG_WITH([dri-drivers],
1975     [AS_HELP_STRING([--with-dri-drivers@<:@=DIRS...@:>@],
1976         [comma delimited classic DRI drivers list, e.g.
1977         "i915,i965,nouveau,radeon,r200,swrast" @<:@default=auto@:>@])],
1978     [with_dri_drivers="$withval"],
1979     [with_dri_drivers=auto])
1980
1981 if test "x$with_dri_drivers" = xauto; then
1982     if test "x$enable_opengl" = xyes -a "x$enable_dri" = xyes; then
1983         with_dri_drivers="yes"
1984     else
1985         with_dri_drivers="no"
1986     fi
1987 fi
1988 if test "x$with_dri_drivers" = xno; then
1989     with_dri_drivers=''
1990 fi
1991
1992 # Check for expat
1993 PKG_CHECK_MODULES([EXPAT], [expat],,
1994     [PKG_CHECK_MODULES([EXPAT], [expat21])]
1995 )
1996
1997 dnl If $with_dri_drivers is yes, drivers will be added through
1998 dnl platform checks. Set DEFINES and LIB_DEPS
1999 if test "x$enable_dri" = xyes; then
2000     # Platform specific settings and drivers to build
2001     case "$host_os" in
2002     linux*)
2003         case "$host_cpu" in
2004         powerpc* | sparc*)
2005             # Build only the drivers for cards that exist on PowerPC/sparc
2006             if test "x$with_dri_drivers" = "xyes"; then
2007                 with_dri_drivers="r200 radeon swrast"
2008             fi
2009             ;;
2010         esac
2011         ;;
2012     cygwin*)
2013         if test "x$with_dri_drivers" = "xyes"; then
2014             with_dri_drivers="swrast"
2015         fi
2016         ;;
2017     darwin*)
2018         DEFINES="$DEFINES -DBUILDING_MESA"
2019         if test "x$with_dri_drivers" = "xyes"; then
2020             with_dri_drivers="swrast"
2021         fi
2022         ;;
2023     esac
2024
2025     # default drivers
2026     if test "x$with_dri_drivers" = "xyes"; then
2027         with_dri_drivers="i915 i965 nouveau r200 radeon swrast"
2028     fi
2029
2030     # put all the necessary libs together
2031     DRI_LIB_DEPS="$DRI_LIB_DEPS $SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
2032 fi
2033
2034 AC_SUBST([DRI_LIB_DEPS])
2035
2036 DRI_DIRS=''
2037 dnl Duplicates in DRI_DIRS are removed by sorting it at the end of this block
2038 if test -n "$with_dri_drivers"; then
2039     if test "x$enable_opengl" != xyes; then
2040         AC_MSG_ERROR([--with-dri-drivers requires OpenGL])
2041     fi
2042
2043     dri_drivers=`IFS=', '; echo $with_dri_drivers`
2044     for driver in $dri_drivers; do
2045         DRI_DIRS="$DRI_DIRS $driver"
2046         case "x$driver" in
2047         xi915)
2048             require_libdrm "i915"
2049             HAVE_I915_DRI=yes
2050             PKG_CHECK_MODULES([I915], [libdrm >= $LIBDRM_INTEL_REQUIRED libdrm_intel >= $LIBDRM_INTEL_REQUIRED])
2051             ;;
2052         xi965)
2053             require_libdrm "i965"
2054             HAVE_I965_DRI=yes
2055             ;;
2056         xnouveau)
2057             require_libdrm "nouveau"
2058             HAVE_NOUVEAU_DRI=yes
2059             PKG_CHECK_MODULES([NVVIEUX], [libdrm >= $LIBDRM_NVVIEUX_REQUIRED libdrm_nouveau >= $LIBDRM_NVVIEUX_REQUIRED])
2060             ;;
2061         xradeon)
2062             require_libdrm "radeon"
2063             HAVE_RADEON_DRI=yes;
2064             PKG_CHECK_MODULES([RADEON], [libdrm >= $LIBDRM_RADEON_REQUIRED libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
2065             ;;
2066         xr200)
2067             require_libdrm "r200"
2068             HAVE_R200_DRI=yes
2069             PKG_CHECK_MODULES([RADEON], [libdrm >= $LIBDRM_RADEON_REQUIRED libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
2070             ;;
2071         xswrast)
2072             HAVE_SWRAST_DRI=yes
2073             ;;
2074         *)
2075             AC_MSG_ERROR([classic DRI driver '$driver' does not exist])
2076             ;;
2077         esac
2078     done
2079     DRI_DIRS=`echo $DRI_DIRS|tr " " "\n"|sort -u|tr "\n" " "`
2080 fi
2081
2082
2083 dnl
2084 dnl Gallium LLVM
2085 dnl Deprecated: kept for backwards compatibility
2086 dnl
2087 AC_ARG_ENABLE([gallium-llvm],
2088     [AS_HELP_STRING([--enable-gallium-llvm],
2089         [DEPRECATED: use --enable-llvm instead])],
2090     [enable_gallium_llvm="$enableval"],
2091     [enable_gallium_llvm=auto])
2092
2093 if test "x$enable_gallium_llvm" != xauto; then
2094    AC_MSG_WARN([The --enable-gallium-llvm option has been deprecated. Use --enable-llvm instead.])
2095    enable_llvm=$enable_gallium_llvm
2096 fi
2097
2098 dnl
2099 dnl LLVM
2100 dnl
2101 AC_ARG_ENABLE([llvm],
2102     [AS_HELP_STRING([--enable-llvm],
2103         [build with LLVM support @<:@default=enabled on x86/x86_64@:>@])],
2104     [enable_llvm="$enableval"],
2105     [enable_llvm=auto])
2106
2107 if test "x$enable_llvm" = xauto -a "x$FOUND_LLVM" = xyes; then
2108     if test "x$FOUND_LLVM" = xyes; then
2109         case "$host_cpu" in
2110         i*86|x86_64|amd64) enable_llvm=yes;;
2111         *) enable_llvm=no;;
2112         esac
2113     else
2114         enable_llvm=no
2115     fi
2116 fi
2117
2118 if test "x$enable_llvm" = xyes -a "x$FOUND_LLVM" = xno; then
2119     AC_MSG_ERROR([--enable-llvm selected but llvm-config is not found])
2120 fi
2121
2122 #
2123 # Vulkan driver configuration
2124 #
2125
2126 AC_ARG_WITH([vulkan-drivers],
2127     [AS_HELP_STRING([--with-vulkan-drivers@<:@=DIRS...@:>@],
2128         [comma delimited Vulkan drivers list, e.g.
2129         "intel,radeon"
2130         @<:@default=no@:>@])],
2131     [with_vulkan_drivers="$withval"],
2132     [with_vulkan_drivers="no"])
2133
2134 # Doing '--without-vulkan-drivers' will set this variable to 'no'.  Clear it
2135 # here so that the script doesn't choke on an unknown driver name later.
2136 case "x$with_vulkan_drivers" in
2137     xyes) with_vulkan_drivers="$VULKAN_DRIVERS_DEFAULT" ;;
2138     xno) with_vulkan_drivers='' ;;
2139 esac
2140
2141 AC_ARG_WITH([vulkan-icddir],
2142     [AS_HELP_STRING([--with-vulkan-icddir=DIR],
2143         [directory for the Vulkan driver icd files @<:@${datarootdir}/vulkan/icd.d@:>@])],
2144     [VULKAN_ICD_INSTALL_DIR="$withval"],
2145     [VULKAN_ICD_INSTALL_DIR='${datarootdir}/vulkan/icd.d'])
2146 AC_SUBST([VULKAN_ICD_INSTALL_DIR])
2147
2148 require_x11_dri3() {
2149     if echo "$platforms" | grep -q 'x11'; then
2150         if test "x$enable_dri3" != xyes; then
2151             AC_MSG_ERROR([$1 Vulkan driver requires DRI3 when built with X11])
2152         fi
2153     fi
2154 }
2155
2156 if test -n "$with_vulkan_drivers"; then
2157     if test "x$ac_cv_func_dl_iterate_phdr" = xno; then
2158         AC_MSG_ERROR([Vulkan drivers require the dl_iterate_phdr function])
2159     fi
2160
2161     VULKAN_DRIVERS=`IFS=', '; echo $with_vulkan_drivers`
2162     for driver in $VULKAN_DRIVERS; do
2163         case "x$driver" in
2164         xintel)
2165             require_libdrm "ANV"
2166             require_x11_dri3 "ANV"
2167             HAVE_INTEL_VULKAN=yes
2168             ;;
2169         xradeon)
2170             require_libdrm "radv"
2171             PKG_CHECK_MODULES([AMDGPU], [libdrm >= $LIBDRM_AMDGPU_REQUIRED libdrm_amdgpu >= $LIBDRM_AMDGPU_REQUIRED])
2172             radeon_llvm_check $LLVM_REQUIRED_RADV "radv"
2173             require_x11_dri3 "radv"
2174             if test "x$acv_mako_found" = xno; then
2175                 AC_MSG_ERROR([Python mako module v$PYTHON_MAKO_REQUIRED or higher not found])
2176             fi
2177             HAVE_RADEON_VULKAN=yes
2178             ;;
2179         *)
2180             AC_MSG_ERROR([Vulkan driver '$driver' does not exist])
2181             ;;
2182         esac
2183     done
2184     VULKAN_DRIVERS=`echo $VULKAN_DRIVERS|tr " " "\n"|sort -u|tr "\n" " "`
2185 fi
2186
2187
2188 DEFINES="$DEFINES -DENABLE_SHADER_CACHE"
2189 AM_CONDITIONAL(NEED_MEGADRIVER, test -n "$DRI_DIRS")
2190 AM_CONDITIONAL(NEED_LIBMESA, test "x$enable_glx" = xxlib -o \
2191                                   "x$enable_osmesa" = xyes -o \
2192                                   -n "$DRI_DIRS")
2193
2194 dnl
2195 dnl OSMesa configuration
2196 dnl
2197
2198 dnl Configure the channel bits for OSMesa (libOSMesa, libOSMesa16, ...)
2199 AC_ARG_WITH([osmesa-bits],
2200     [AS_HELP_STRING([--with-osmesa-bits=BITS],
2201         [OSMesa channel bits and library name: 8, 16, 32 @<:@default=8@:>@])],
2202     [osmesa_bits="$withval"],
2203     [osmesa_bits=8])
2204 if test "x$osmesa_bits" != x8; then
2205     if test "x$enable_dri" = xyes -o "x$enable_glx" != xno; then
2206         AC_MSG_WARN([Ignoring OSMesa channel bits because of non-OSMesa driver])
2207         osmesa_bits=8
2208     fi
2209 fi
2210 case "x$osmesa_bits" in
2211 x8)
2212     OSMESA_LIB="${OSMESA_LIB}"
2213     ;;
2214 x16|x32)
2215     OSMESA_LIB="${OSMESA_LIB}$osmesa_bits"
2216     DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31"
2217     ;;
2218 *)
2219     AC_MSG_ERROR([OSMesa bits '$osmesa_bits' is not a valid option])
2220     ;;
2221 esac
2222
2223 if test "x$enable_osmesa" = xyes -o "x$enable_gallium_osmesa" = xyes; then
2224     # only link libraries with osmesa if shared
2225     if test "$enable_static" = no; then
2226         OSMESA_LIB_DEPS="-lm $PTHREAD_LIBS $SELINUX_LIBS $DLOPEN_LIBS"
2227     else
2228         OSMESA_LIB_DEPS=""
2229     fi
2230     OSMESA_PC_LIB_PRIV="-lm $PTHREAD_LIBS $SELINUX_LIBS $DLOPEN_LIBS"
2231 fi
2232
2233 AC_SUBST([OSMESA_LIB_DEPS])
2234 AC_SUBST([OSMESA_PC_REQ])
2235 AC_SUBST([OSMESA_PC_LIB_PRIV])
2236
2237 dnl
2238 dnl gbm configuration
2239 dnl
2240 if test "x$enable_gbm" = xyes; then
2241     require_dri_shared_libs_and_glapi "gbm"
2242 fi
2243 AM_CONDITIONAL(HAVE_GBM, test "x$enable_gbm" = xyes)
2244 # FINISHME: GBM has a number of dependencies which we should add below
2245 GBM_PC_REQ_PRIV=""
2246 GBM_PC_LIB_PRIV="$DLOPEN_LIBS"
2247 AC_SUBST([GBM_PC_REQ_PRIV])
2248 AC_SUBST([GBM_PC_LIB_PRIV])
2249
2250 dnl
2251 dnl EGL configuration
2252 dnl
2253
2254 if test "x$enable_egl" = xyes; then
2255     EGL_LIB_DEPS="$DLOPEN_LIBS $SELINUX_LIBS $PTHREAD_LIBS"
2256
2257     AC_CHECK_FUNC(mincore, [DEFINES="$DEFINES -DHAVE_MINCORE"])
2258
2259     require_dri_shared_libs_and_glapi "egl"
2260 fi
2261 AM_CONDITIONAL(HAVE_EGL, test "x$enable_egl" = xyes)
2262 AC_SUBST([EGL_LIB_DEPS])
2263
2264 gallium_st="mesa"
2265
2266 dnl
2267 dnl XA configuration
2268 dnl
2269 if test "x$enable_xa" = xyes; then
2270     if test "x$with_gallium_drivers" = xswrast; then
2271        AC_MSG_ERROR([
2272           Building xa requires at least one non swrast gallium driver.
2273           If you are looking to use libxatracker.so with the VMware driver,
2274           make sure to include svga in the gallium drivers list, apart from
2275           enabling XA.
2276           Example: ./configure --enable-xa --with-gallium-drivers=svga...])
2277     fi
2278     gallium_st="$gallium_st xa"
2279 fi
2280 AM_CONDITIONAL(HAVE_ST_XA, test "x$enable_xa" = xyes)
2281
2282 if echo $platforms | grep -q "x11"; then
2283     have_xvmc_platform=yes
2284 else
2285     have_xvmc_platform=no
2286 fi
2287
2288 if echo $platforms | grep -q "x11"; then
2289     have_vdpau_platform=yes
2290 else
2291     have_vdpau_platform=no
2292 fi
2293
2294 if echo $platforms | egrep -q "x11|drm"; then
2295     have_omx_platform=yes
2296 else
2297     have_omx_platform=no
2298 fi
2299
2300 if echo $platforms | egrep -q "x11|drm|wayland"; then
2301     have_va_platform=yes
2302 else
2303     have_va_platform=no
2304 fi
2305
2306 dnl
2307 dnl Gallium G3DVL configuration
2308 dnl
2309 if test -n "$with_gallium_drivers" -a "x$with_gallium_drivers" != xswrast; then
2310     if test "x$enable_xvmc" = xauto -a "x$have_xvmc_platform" = xyes; then
2311         PKG_CHECK_EXISTS([xvmc >= $XVMC_REQUIRED], [enable_xvmc=yes], [enable_xvmc=no])
2312     fi
2313
2314     if test "x$enable_vdpau" = xauto -a "x$have_vdpau_platform" = xyes; then
2315         PKG_CHECK_EXISTS([vdpau >= $VDPAU_REQUIRED], [enable_vdpau=yes], [enable_vdpau=no])
2316     fi
2317
2318     if test "x$enable_omx_bellagio" = xauto -a "x$have_omx_platform" = xyes; then
2319         PKG_CHECK_EXISTS([libomxil-bellagio >= $LIBOMXIL_BELLAGIO_REQUIRED], [enable_omx_bellagio=yes], [enable_omx_bellagio=no])
2320     fi
2321
2322     if test "x$enable_omx_tizonia" = xauto -a "x$have_omx_platform" = xyes; then
2323        PKG_CHECK_EXISTS([libtizonia >= $LIBOMXIL_TIZONIA_REQUIRED], [enable_omx_tizonia=yes], [enable_omx_tizonia=no])
2324     fi
2325
2326     if test "x$enable_va" = xauto -a "x$have_va_platform" = xyes; then
2327         PKG_CHECK_EXISTS([libva >= $LIBVA_REQUIRED], [enable_va=yes], [enable_va=no])
2328     fi
2329 fi
2330
2331 if test "x$enable_dri" = xyes -o \
2332         "x$enable_xvmc" = xyes -o \
2333         "x$enable_vdpau" = xyes -o \
2334         "x$enable_omx_bellagio" = xyes -o \
2335         "x$enable_omx_tizonia" = xyes -o \
2336         "x$enable_va" = xyes; then
2337     need_gallium_vl=yes
2338 fi
2339 AM_CONDITIONAL(NEED_GALLIUM_VL, test "x$need_gallium_vl" = xyes)
2340
2341 if test "x$enable_xvmc" = xyes -o \
2342         "x$enable_vdpau" = xyes -o \
2343         "x$enable_omx_bellagio" = xyes -o \
2344         "x$enable_omx_tizonia" = xyes -o \
2345         "x$enable_va" = xyes; then
2346     if echo $platforms | grep -q "x11"; then
2347         PKG_CHECK_MODULES([VL], [x11-xcb xcb xcb-dri2 >= $XCBDRI2_REQUIRED])
2348     fi
2349     need_gallium_vl_winsys=yes
2350 fi
2351 AM_CONDITIONAL(NEED_GALLIUM_VL_WINSYS, test "x$need_gallium_vl_winsys" = xyes)
2352
2353 if test "x$enable_xvmc" = xyes; then
2354     if test "x$have_xvmc_platform" != xyes; then
2355         AC_MSG_ERROR([XVMC requires the x11 platforms])
2356     fi
2357     PKG_CHECK_MODULES([XVMC], [xvmc >= $XVMC_REQUIRED])
2358     gallium_st="$gallium_st xvmc"
2359 fi
2360 AM_CONDITIONAL(HAVE_ST_XVMC, test "x$enable_xvmc" = xyes)
2361
2362 if test "x$enable_vdpau" = xyes; then
2363     if test "x$have_vdpau_platform" != xyes; then
2364         AC_MSG_ERROR([VDPAU requires the x11 platforms])
2365     fi
2366     PKG_CHECK_MODULES([VDPAU], [vdpau >= $VDPAU_REQUIRED])
2367     gallium_st="$gallium_st vdpau"
2368     DEFINES="$DEFINES -DHAVE_ST_VDPAU"
2369 fi
2370 AM_CONDITIONAL(HAVE_ST_VDPAU, test "x$enable_vdpau" = xyes)
2371
2372 if test "x$enable_omx_bellagio" = xyes; then
2373     if test "x$have_omx_platform" != xyes; then
2374         AC_MSG_ERROR([OMX requires at least one of the x11 or drm platforms])
2375     fi
2376     PKG_CHECK_MODULES([OMX_BELLAGIO], [libomxil-bellagio >= $LIBOMXIL_BELLAGIO_REQUIRED])
2377     gallium_st="$gallium_st omx_bellagio"
2378     AC_DEFINE([ENABLE_ST_OMX_BELLAGIO], 1, [Use Bellagio for OMX IL])
2379 else
2380     AC_DEFINE([ENABLE_ST_OMX_BELLAGIO], 0)
2381 fi
2382 AM_CONDITIONAL(HAVE_ST_OMX_BELLAGIO, test "x$enable_omx_bellagio" = xyes)
2383
2384 if test "x$enable_omx_tizonia" = xyes; then
2385     if test "x$have_omx_platform" != xyes; then
2386         AC_MSG_ERROR([OMX requires at least one of the x11 or drm platforms])
2387     fi
2388     PKG_CHECK_MODULES([OMX_TIZONIA],
2389                       [libtizonia >= $LIBOMXIL_TIZONIA_REQUIRED
2390                        tizilheaders >= $LIBOMXIL_TIZONIA_REQUIRED
2391                        libtizplatform >= $LIBOMXIL_TIZONIA_REQUIRED])
2392     gallium_st="$gallium_st omx_tizonia"
2393     AC_DEFINE([ENABLE_ST_OMX_TIZONIA], 1, [Use Tizoina for OMX IL])
2394 else
2395     AC_DEFINE([ENABLE_ST_OMX_TIZONIA], 0)
2396 fi
2397 AM_CONDITIONAL(HAVE_ST_OMX_TIZONIA, test "x$enable_omx_tizonia" = xyes)
2398
2399 if test "x$enable_va" = xyes; then
2400     if test "x$have_va_platform" != xyes; then
2401         AC_MSG_ERROR([VA requires at least one of the x11 drm or wayland platforms])
2402     fi
2403     PKG_CHECK_MODULES([VA], [libva >= $LIBVA_REQUIRED])
2404     gallium_st="$gallium_st va"
2405 fi
2406 AM_CONDITIONAL(HAVE_ST_VA, test "x$enable_va" = xyes)
2407
2408 dnl
2409 dnl Nine Direct3D9 configuration
2410 dnl
2411 if test "x$enable_nine" = xyes; then
2412     if ! echo "$with_gallium_drivers" | grep -q 'swrast'; then
2413         AC_MSG_ERROR([nine requires the gallium swrast driver])
2414     fi
2415     if test "x$with_gallium_drivers" = xswrast; then
2416         AC_MSG_ERROR([nine requires at least one non-swrast gallium driver])
2417     fi
2418     if test $GCC_VERSION_MAJOR -lt 4 -o $GCC_VERSION_MAJOR -eq 4 -a $GCC_VERSION_MINOR -lt 6; then
2419         AC_MSG_ERROR([gcc >= 4.6 is required to build nine])
2420     fi
2421
2422     if test "x$enable_dri3" = xno; then
2423         AC_MSG_WARN([using nine together with wine requires DRI3 enabled system])
2424     fi
2425
2426     gallium_st="$gallium_st nine"
2427 fi
2428 AM_CONDITIONAL(HAVE_ST_NINE, test "x$enable_nine" = xyes)
2429
2430 dnl
2431 dnl OpenCL configuration
2432 dnl
2433
2434 AC_ARG_WITH([clang-libdir],
2435    [AS_HELP_STRING([--with-clang-libdir],
2436          [Path to Clang libraries @<:@default=llvm-config --libdir@:>@])],
2437    [CLANG_LIBDIR="$withval"],
2438    [CLANG_LIBDIR=''])
2439
2440 PKG_CHECK_EXISTS([libclc], [have_libclc=yes], [have_libclc=no])
2441
2442 if test "x$enable_opencl" = xyes; then
2443     if test -z "$with_gallium_drivers"; then
2444         AC_MSG_ERROR([cannot enable OpenCL without Gallium])
2445     fi
2446
2447     if test "x$HAVE_CXX11" != "xyes"; then
2448        AC_MSG_ERROR([clover requires c++11 support])
2449     fi
2450
2451     if test "x$have_libclc" = xno; then
2452         AC_MSG_ERROR([pkg-config cannot find libclc.pc which is required to build clover.
2453                     Make sure the directory containing libclc.pc is specified in your
2454                     PKG_CONFIG_PATH environment variable.
2455                     By default libclc.pc is installed to /usr/local/share/pkgconfig/])
2456     else
2457         LIBCLC_INCLUDEDIR=`$PKG_CONFIG --variable=includedir libclc`
2458         LIBCLC_LIBEXECDIR=`$PKG_CONFIG --variable=libexecdir libclc`
2459         AC_SUBST([LIBCLC_INCLUDEDIR])
2460         AC_SUBST([LIBCLC_LIBEXECDIR])
2461     fi
2462
2463     gallium_st="$gallium_st clover"
2464
2465     if test "x$enable_opencl_icd" = xyes; then
2466         OPENCL_LIBNAME="MesaOpenCL"
2467     else
2468         OPENCL_LIBNAME="OpenCL"
2469     fi
2470
2471     if test "x$have_libelf" != xyes; then
2472        AC_MSG_ERROR([Clover requires libelf])
2473     fi
2474
2475     if test "x${ac_cv_cxx_compiler_gnu}" = xyes; then
2476         altivec_enabled=no
2477         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2478         #if !defined(__VEC__) || !defined(__ALTIVEC__)
2479         #error "AltiVec not enabled"
2480         #endif
2481         ])], altivec_enabled=yes)
2482
2483         if test "$altivec_enabled" = yes; then
2484             CLOVER_STD_OVERRIDE="-std=gnu++11"
2485         fi
2486         AC_SUBST([CLOVER_STD_OVERRIDE])
2487     fi
2488
2489     llvm_require_version $LLVM_REQUIRED_OPENCL "opencl"
2490
2491     llvm_add_default_components "opencl"
2492     llvm_add_component "all-targets" "opencl"
2493     llvm_add_component "coverage" "opencl"
2494     llvm_add_component "linker" "opencl"
2495     llvm_add_component "instrumentation" "opencl"
2496     llvm_add_component "ipo" "opencl"
2497     llvm_add_component "irreader" "opencl"
2498     llvm_add_component "lto" "opencl"
2499     llvm_add_component "option" "opencl"
2500     llvm_add_component "objcarcopts" "opencl"
2501     llvm_add_component "profiledata" "opencl"
2502     llvm_add_optional_component "coroutines" "opencl"
2503
2504     dnl Check for Clang internal headers
2505     if test -z "$CLANG_LIBDIR"; then
2506         CLANG_LIBDIR=${LLVM_LIBDIR}
2507     fi
2508     CLANG_RESOURCE_DIR=$CLANG_LIBDIR/clang/${LLVM_VERSION}
2509     AS_IF([test ! -f "$CLANG_RESOURCE_DIR/include/stddef.h"],
2510         [AC_MSG_ERROR([Could not find clang internal header stddef.h in $CLANG_RESOURCE_DIR Use --with-clang-libdir to specify the correct path to the clang libraries.])])
2511 fi
2512 AM_CONDITIONAL(HAVE_CLOVER, test "x$enable_opencl" = xyes)
2513 AM_CONDITIONAL(HAVE_CLOVER_ICD, test "x$enable_opencl_icd" = xyes)
2514 AC_SUBST([OPENCL_LIBNAME])
2515 AC_SUBST([CLANG_RESOURCE_DIR])
2516
2517 dnl
2518 dnl Gallium configuration
2519 dnl
2520 AM_CONDITIONAL(HAVE_GALLIUM, test -n "$with_gallium_drivers")
2521
2522 # libEGL wants to default to the first platform specified in
2523 # ./configure.  parse that here.
2524 if test "x$platforms" != "x"; then
2525     FIRST_PLATFORM_CAPS=`echo $platforms | sed 's| .*||' | tr '[[a-z]]' '[[A-Z]]'`
2526     EGL_NATIVE_PLATFORM="_EGL_PLATFORM_$FIRST_PLATFORM_CAPS"
2527 else
2528     EGL_NATIVE_PLATFORM="_EGL_INVALID_PLATFORM"
2529 fi
2530
2531 AC_SUBST([EGL_NATIVE_PLATFORM])
2532 AC_SUBST([EGL_CFLAGS])
2533
2534 # If we don't have the X11 platform, set this define so we don't try to include
2535 # the X11 headers.
2536 if ! echo "$platforms" | grep -q 'x11'; then
2537     DEFINES="$DEFINES -DMESA_EGL_NO_X11_HEADERS"
2538     GL_PC_CFLAGS="$GL_PC_CFLAGS -DMESA_EGL_NO_X11_HEADERS"
2539 fi
2540
2541 dnl Directory for XVMC libs
2542 AC_ARG_WITH([xvmc-libdir],
2543     [AS_HELP_STRING([--with-xvmc-libdir=DIR],
2544         [directory for the XVMC libraries @<:@default=${libdir}@:>@])],
2545     [XVMC_LIB_INSTALL_DIR="$withval"],
2546     [XVMC_LIB_INSTALL_DIR='${libdir}'])
2547 AC_SUBST([XVMC_LIB_INSTALL_DIR])
2548
2549 dnl
2550 dnl Gallium Tests
2551 dnl
2552 AM_CONDITIONAL(HAVE_GALLIUM_TESTS, test "x$enable_gallium_tests" = xyes)
2553
2554 dnl Directory for VDPAU libs
2555 AC_ARG_WITH([vdpau-libdir],
2556     [AS_HELP_STRING([--with-vdpau-libdir=DIR],
2557         [directory for the VDPAU libraries @<:@default=${libdir}/vdpau@:>@])],
2558     [VDPAU_LIB_INSTALL_DIR="$withval"],
2559     [VDPAU_LIB_INSTALL_DIR='${libdir}/vdpau'])
2560 AC_SUBST([VDPAU_LIB_INSTALL_DIR])
2561
2562 dnl Directory for OMX_BELLAGIO libs
2563
2564 AC_ARG_WITH([omx-bellagio-libdir],
2565     [AS_HELP_STRING([--with-omx-bellagio-libdir=DIR],
2566         [directory for the OMX_BELLAGIO libraries])],
2567     [OMX_BELLAGIO_LIB_INSTALL_DIR="$withval"],
2568     [OMX_BELLAGIO_LIB_INSTALL_DIR=`$PKG_CONFIG --exists libomxil-bellagio && \
2569                                    $PKG_CONFIG --define-variable=libdir=\$libdir --variable=pluginsdir libomxil-bellagio`])
2570 AC_SUBST([OMX_BELLAGIO_LIB_INSTALL_DIR])
2571
2572 dnl Directory for OMX_TIZONIA libs
2573
2574 AC_ARG_WITH([omx-tizonia-libdir],
2575     [AS_HELP_STRING([--with-omx-tizonia-libdir=DIR],
2576         [directory for the OMX_TIZONIA libraries])],
2577     [OMX_TIZONIA_LIB_INSTALL_DIR="$withval"],
2578     [OMX_TIZONIA_LIB_INSTALL_DIR=`$PKG_CONFIG --define-variable=libdir=\$libdir --variable=pluginsdir libtizcore`])
2579 AC_SUBST([OMX_TIZONIA_LIB_INSTALL_DIR])
2580
2581 dnl Directory for VA libs
2582
2583 AC_ARG_WITH([va-libdir],
2584     [AS_HELP_STRING([--with-va-libdir=DIR],
2585         [directory for the VA libraries @<:@${libdir}/dri@:>@])],
2586     [VA_LIB_INSTALL_DIR="$withval"],
2587     [VA_LIB_INSTALL_DIR="${libdir}/dri"])
2588 AC_SUBST([VA_LIB_INSTALL_DIR])
2589
2590 AC_ARG_WITH([d3d-libdir],
2591     [AS_HELP_STRING([--with-d3d-libdir=DIR],
2592         [directory for the D3D modules @<:@${libdir}/d3d@:>@])],
2593     [D3D_DRIVER_INSTALL_DIR="$withval"],
2594     [D3D_DRIVER_INSTALL_DIR="${libdir}/d3d"])
2595 AC_SUBST([D3D_DRIVER_INSTALL_DIR])
2596
2597 dnl Architectures to build SWR library for
2598
2599 AC_ARG_WITH([swr-archs],
2600     [AS_HELP_STRING([--with-swr-archs@<:@=DIRS...@:>@],
2601         [comma delimited swr architectures list, e.g.
2602         "avx,avx2,knl,skx" @<:@default="avx,avx2"@:>@])],
2603     [with_swr_archs="$withval"],
2604     [with_swr_archs="avx,avx2"])
2605
2606 dnl
2607 dnl r300 doesn't strictly require LLVM, but for performance reasons we
2608 dnl highly recommend LLVM usage. So require it at least on x86 and x86_64
2609 dnl architectures.
2610 dnl
2611 r300_require_llvm() {
2612     case "$host" in *gnux32) return;; esac
2613     case "$host_cpu" in
2614     i*86|x86_64|amd64) require_llvm $1
2615         ;;
2616     esac
2617 }
2618
2619 dnl
2620 dnl DRM is needed by X, Wayland, and offscreen rendering.
2621 dnl Surfaceless is an alternative for the last one.
2622 dnl
2623 require_basic_egl() {
2624     case "$with_platforms" in
2625         *drm*|*surfaceless*|*android*)
2626             ;;
2627         *)
2628             AC_MSG_ERROR([$1 requires one of these:
2629                   1) --with-platforms=drm (X, Wayland, offscreen rendering based on DRM)
2630                   2) --with-platforms=surfaceless (offscreen only)
2631                   3) --with-platforms=android (Android only)
2632                   Recommended options: drm,x11])
2633             ;;
2634     esac
2635 }
2636
2637 swr_require_cxx_feature_flags() {
2638     feature_name="$1"
2639     preprocessor_test="$2"
2640     option_list="$3"
2641     output_var="$4"
2642
2643     AC_MSG_CHECKING([whether $CXX supports $feature_name])
2644     AC_LANG_PUSH([C++])
2645     save_CXXFLAGS="$CXXFLAGS"
2646     save_IFS="$IFS"
2647     IFS=","
2648     found=0
2649     for opts in $option_list
2650     do
2651         unset IFS
2652         CXXFLAGS="$opts $save_CXXFLAGS"
2653         AC_COMPILE_IFELSE(
2654             [AC_LANG_PROGRAM(
2655                 [   #if !($preprocessor_test)
2656                     #error
2657                     #endif
2658                 ])],
2659             [found=1; break],
2660             [])
2661         IFS=","
2662     done
2663     IFS="$save_IFS"
2664     CXXFLAGS="$save_CXXFLAGS"
2665     AC_LANG_POP([C++])
2666     if test $found -eq 1; then
2667         AC_MSG_RESULT([$opts])
2668         eval "$output_var=\$opts"
2669         return 0
2670     fi
2671     AC_MSG_RESULT([no])
2672     AC_MSG_ERROR([swr requires $feature_name support])
2673     return 1
2674 }
2675
2676 dnl Duplicates in GALLIUM_DRIVERS_DIRS are removed by sorting it after this block
2677 if test -n "$with_gallium_drivers"; then
2678     gallium_drivers=`IFS=', '; echo $with_gallium_drivers`
2679     for driver in $gallium_drivers; do
2680         case "x$driver" in
2681         xsvga)
2682             HAVE_GALLIUM_SVGA=yes
2683             require_libdrm "svga"
2684             ;;
2685         xi915)
2686             HAVE_GALLIUM_I915=yes
2687             PKG_CHECK_MODULES([I915], [libdrm >= $LIBDRM_INTEL_REQUIRED libdrm_intel >= $LIBDRM_INTEL_REQUIRED])
2688             require_libdrm "Gallium i915"
2689             ;;
2690         xr300)
2691             HAVE_GALLIUM_R300=yes
2692             PKG_CHECK_MODULES([RADEON], [libdrm >= $LIBDRM_RADEON_REQUIRED libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
2693             require_libdrm "r300"
2694             r300_require_llvm "r300"
2695             ;;
2696         xr600)
2697             HAVE_GALLIUM_R600=yes
2698             PKG_CHECK_MODULES([RADEON], [libdrm >= $LIBDRM_RADEON_REQUIRED libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
2699             require_libdrm "r600"
2700             if test "x$enable_llvm" = xyes; then
2701                 radeon_llvm_check $LLVM_REQUIRED_R600 "r600"
2702
2703                 llvm_add_component "asmparser" "r600"
2704                 llvm_add_component "bitreader" "r600"
2705             fi
2706             ;;
2707         xradeonsi)
2708             HAVE_GALLIUM_RADEONSI=yes
2709             PKG_CHECK_MODULES([RADEON], [libdrm >= $LIBDRM_RADEON_REQUIRED libdrm_radeon >= $LIBDRM_RADEON_REQUIRED])
2710             PKG_CHECK_MODULES([AMDGPU], [libdrm >= $LIBDRM_AMDGPU_REQUIRED libdrm_amdgpu >= $LIBDRM_AMDGPU_REQUIRED])
2711             require_libdrm "radeonsi"
2712             radeon_llvm_check $LLVM_REQUIRED_RADEONSI "radeonsi"
2713             if test "x$enable_egl" = xyes; then
2714                 require_basic_egl "radeonsi"
2715             fi
2716             ;;
2717         xnouveau)
2718             HAVE_GALLIUM_NOUVEAU=yes
2719             PKG_CHECK_MODULES([NOUVEAU], [libdrm >= $LIBDRM_NOUVEAU_REQUIRED libdrm_nouveau >= $LIBDRM_NOUVEAU_REQUIRED])
2720             require_libdrm "nouveau"
2721             ;;
2722         xfreedreno)
2723             HAVE_GALLIUM_FREEDRENO=yes
2724             require_libdrm "freedreno"
2725             ;;
2726         xetnaviv)
2727             HAVE_GALLIUM_ETNAVIV=yes
2728             PKG_CHECK_MODULES([ETNAVIV], [libdrm >= $LIBDRM_ETNAVIV_REQUIRED libdrm_etnaviv >= $LIBDRM_ETNAVIV_REQUIRED])
2729             require_libdrm "etnaviv"
2730             ;;
2731        ximx)
2732             HAVE_GALLIUM_IMX=yes
2733             ;;
2734         xtegra)
2735             HAVE_GALLIUM_TEGRA=yes
2736             require_libdrm "tegra"
2737             ;;
2738         xswrast)
2739             HAVE_GALLIUM_SOFTPIPE=yes
2740             if test "x$enable_llvm" = xyes; then
2741                 HAVE_GALLIUM_LLVMPIPE=yes
2742             fi
2743             ;;
2744         xswr)
2745             llvm_require_version $LLVM_REQUIRED_SWR "swr"
2746
2747             if test "x$HAVE_CXX11" != "xyes"; then
2748                 AC_MSG_ERROR([swr requires c++11 support])
2749             fi
2750
2751             swr_require_cxx_feature_flags "AVX" "defined(__AVX__)" \
2752                 ",-target-cpu=sandybridge,-mavx,-march=core-avx,-tp=sandybridge" \
2753                 SWR_AVX_CXXFLAGS
2754             AC_SUBST([SWR_AVX_CXXFLAGS])
2755
2756             swr_archs=`IFS=', '; echo $with_swr_archs`
2757             for arch in $swr_archs; do
2758                 case "x$arch" in
2759                 xavx)
2760                     HAVE_SWR_AVX=yes
2761                     ;;
2762                 xavx2)
2763                     swr_require_cxx_feature_flags "AVX2" "defined(__AVX2__)" \
2764                         ",-target-cpu=haswell,-mavx2 -mfma -mbmi2 -mf16c,-march=core-avx2,-tp=haswell" \
2765                         SWR_AVX2_CXXFLAGS
2766                     AC_SUBST([SWR_AVX2_CXXFLAGS])
2767                     HAVE_SWR_AVX2=yes
2768                     ;;
2769                 xknl)
2770                     swr_require_cxx_feature_flags "KNL" "defined(__AVX512F__) && defined(__AVX512ER__)" \
2771                         ",-target-cpu=mic-knl,-march=knl,-xMIC-AVX512" \
2772                         SWR_KNL_CXXFLAGS
2773                     AC_SUBST([SWR_KNL_CXXFLAGS])
2774                     HAVE_SWR_KNL=yes
2775                     ;;
2776                 xskx)
2777                     swr_require_cxx_feature_flags "SKX" "defined(__AVX512F__) && defined(__AVX512BW__)" \
2778                         ",-target-cpu=x86-skylake,-march=skylake-avx512,-xCORE-AVX512" \
2779                         SWR_SKX_CXXFLAGS
2780                     AC_SUBST([SWR_SKX_CXXFLAGS])
2781                     HAVE_SWR_SKX=yes
2782                     ;;
2783                 *)
2784                     AC_MSG_ERROR([unknown SWR build architecture '$arch'])
2785                     ;;
2786                 esac
2787             done
2788
2789             if test "x$HAVE_SWR_AVX" != xyes -a \
2790                     "x$HAVE_SWR_AVX2" != xyes -a \
2791                     "x$HAVE_SWR_KNL" != xyes -a \
2792                     "x$HAVE_SWR_SKX" != xyes; then
2793                AC_MSG_ERROR([swr enabled but no swr architectures selected])
2794             fi
2795
2796             # test if more than one swr arch configured
2797             if test `echo $swr_archs | wc -w` -eq 1; then
2798                 HAVE_SWR_BUILTIN=yes
2799             fi
2800
2801             HAVE_GALLIUM_SWR=yes
2802             ;;
2803         xvc4)
2804             HAVE_GALLIUM_VC4=yes
2805             PKG_CHECK_MODULES([VC4], [libdrm >= $LIBDRM_VC4_REQUIRED])
2806
2807             PKG_CHECK_MODULES([SIMPENROSE], [simpenrose],
2808                               [USE_VC4_SIMULATOR=yes;
2809                                DEFINES="$DEFINES -DUSE_VC4_SIMULATOR"],
2810                               [USE_VC4_SIMULATOR=no])
2811             ;;
2812         xv3d)
2813             HAVE_GALLIUM_V3D=yes
2814
2815             PKG_CHECK_MODULES([V3D_SIMULATOR], [v3dv3],
2816                               [USE_V3D_SIMULATOR=yes;
2817                                DEFINES="$DEFINES -DUSE_V3D_SIMULATOR"],
2818                               [USE_V3D_SIMULATOR=no])
2819             ;;
2820         xpl111)
2821             HAVE_GALLIUM_PL111=yes
2822             ;;
2823         xvirgl)
2824             HAVE_GALLIUM_VIRGL=yes
2825             require_libdrm "virgl"
2826             if test "x$enable_egl" = xyes; then
2827                 require_basic_egl "virgl"
2828             fi
2829             ;;
2830         *)
2831             AC_MSG_ERROR([Unknown Gallium driver: $driver])
2832             ;;
2833         esac
2834     done
2835 fi
2836
2837 # XXX: Keep in sync with LLVM_REQUIRED_SWR
2838 AM_CONDITIONAL(SWR_INVALID_LLVM_VERSION, test "x$LLVM_VERSION" != x6.0.0 -a \
2839                                               "x$LLVM_VERSION" != x6.0.1)
2840
2841 if test "x$enable_llvm" = "xyes" -a "$with_gallium_drivers"; then
2842     llvm_require_version $LLVM_REQUIRED_GALLIUM "gallium"
2843     llvm_add_default_components "gallium"
2844 fi
2845
2846 AM_CONDITIONAL(HAVE_SWR_AVX, test "x$HAVE_SWR_AVX" = xyes)
2847 AM_CONDITIONAL(HAVE_SWR_AVX2, test "x$HAVE_SWR_AVX2" = xyes)
2848 AM_CONDITIONAL(HAVE_SWR_KNL, test "x$HAVE_SWR_KNL" = xyes)
2849 AM_CONDITIONAL(HAVE_SWR_SKX, test "x$HAVE_SWR_SKX" = xyes)
2850 AM_CONDITIONAL(HAVE_SWR_BUILTIN, test "x$HAVE_SWR_BUILTIN" = xyes)
2851
2852 dnl We need to validate some needed dependencies for renderonly drivers.
2853
2854 if test "x$HAVE_GALLIUM_ETNAVIV" != xyes -a "x$HAVE_GALLIUM_IMX" = xyes  ; then
2855     AC_MSG_ERROR([Building with imx requires etnaviv])
2856 fi
2857
2858 if test "x$HAVE_GALLIUM_VC4" != xyes -a "x$HAVE_GALLIUM_PL111" = xyes  ; then
2859     AC_MSG_ERROR([Building with pl111 requires vc4])
2860 fi
2861
2862 if test "x$HAVE_GALLIUM_NOUVEAU" != xyes -a "x$HAVE_GALLIUM_TEGRA" = xyes; then
2863     AC_MSG_ERROR([Building with tegra requires nouveau])
2864 fi
2865
2866 detect_old_buggy_llvm() {
2867     dnl llvm-config may not give the right answer when llvm is a built as a
2868     dnl single shared library, so we must work the library name out for
2869     dnl ourselves.
2870     dnl (See https://llvm.org/bugs/show_bug.cgi?id=6823)
2871     dnl We can't use $LLVM_VERSION because it has 'svn' stripped out,
2872     LLVM_SO_NAME=LLVM-`$LLVM_CONFIG --version`
2873     AS_IF([test -f "$LLVM_LIBDIR/lib$LLVM_SO_NAME.$IMP_LIB_EXT"], [llvm_have_one_so=yes])
2874
2875     if test "x$llvm_have_one_so" = xyes; then
2876         dnl LLVM was built using auto*, so there is only one shared object.
2877         LLVM_LIBS="-l$LLVM_SO_NAME"
2878     else
2879         dnl If LLVM was built with CMake, there will be one shared object per
2880         dnl component.
2881         AS_IF([test ! -f "$LLVM_LIBDIR/libLLVMTarget.$IMP_LIB_EXT"],
2882                [AC_MSG_ERROR([Could not find llvm shared libraries:
2883                 Please make sure you have built llvm with the --enable-shared option
2884                 and that your llvm libraries are installed in $LLVM_LIBDIR
2885                 If you have installed your llvm libraries to a different directory you
2886                 can use the --with-llvm-prefix= configure flag to specify this directory.
2887                 NOTE: Mesa is attempting to use llvm shared libraries by default.
2888                 If you do not want to build with llvm shared libraries and instead want to
2889                 use llvm static libraries then add --disable-llvm-shared-libs to your configure
2890                 invocation and rebuild.])])
2891
2892         dnl We don't need to update LLVM_LIBS in this case because the LLVM
2893         dnl install uses a shared object for each component and we have
2894         dnl already added all of these objects to LLVM_LIBS.
2895     fi
2896 }
2897
2898 dnl
2899 dnl Set defines and buildtime variables only when using LLVM.
2900 dnl
2901 if test "x$enable_llvm" = xyes; then
2902     DEFINES="${DEFINES} -DHAVE_LLVM=0x0$LLVM_VERSION_INT -DMESA_LLVM_VERSION_PATCH=$LLVM_VERSION_PATCH"
2903
2904     LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
2905     LLVM_CFLAGS=$LLVM_CPPFLAGS   # CPPFLAGS seem to be sufficient
2906     LLVM_CXXFLAGS=`strip_unwanted_llvm_flags "$LLVM_CONFIG --cxxflags"`
2907
2908     dnl Set LLVM_LIBS - This is done after the driver configuration so
2909     dnl that drivers can add additional components to LLVM_COMPONENTS.
2910     dnl Previously, gallium drivers were updating LLVM_LIBS directly
2911     dnl by calling llvm-config --libs ${DRIVER_LLVM_COMPONENTS}, but
2912     dnl this was causing the same libraries to be appear multiple times
2913     dnl in LLVM_LIBS.
2914
2915     if test $LLVM_VERSION_MAJOR -ge 4 -o $LLVM_VERSION_MAJOR -eq 3 -a $LLVM_VERSION_MINOR -ge 9; then
2916         if test "x$enable_llvm_shared_libs" = xyes; then
2917             LLVM_LIBS="`$LLVM_CONFIG --link-shared --libs ${LLVM_COMPONENTS}`"
2918         else
2919             dnl Invoking llvm-config with both -libs and --system-libs produces the
2920             dnl two separate lines - each for the set of libraries.
2921                 dnl Call the program twice, effectively folding them into a single line.
2922             LLVM_LIBS="`$LLVM_CONFIG --link-static --libs ${LLVM_COMPONENTS}`"
2923             dnl We need to link to llvm system libs when using static libs
2924             LLVM_LIBS="$LLVM_LIBS `$LLVM_CONFIG --link-static --system-libs`"
2925         fi
2926     else
2927         LLVM_LIBS="`$LLVM_CONFIG --libs ${LLVM_COMPONENTS}`"
2928         if test "x$enable_llvm_shared_libs" = xyes; then
2929             detect_old_buggy_llvm
2930         else
2931             AC_MSG_WARN([Building mesa with statically linked LLVM may cause compilation issues])
2932             dnl We need to link to llvm system libs when using static libs
2933             dnl However, only llvm 3.5+ provides --system-libs
2934             if test $LLVM_VERSION_MAJOR -ge 4 -o $LLVM_VERSION_MAJOR -eq 3 -a $LLVM_VERSION_MINOR -ge 5; then
2935                 LLVM_LIBS="$LLVM_LIBS `$LLVM_CONFIG --system-libs`"
2936             fi
2937         fi
2938     fi
2939
2940     dnl The gallium-xlib GLX and gallium OSMesa targets directly embed the
2941     dnl swr/llvmpipe driver into the final binary.  Adding LLVM_LIBS results in 
2942     dnl the LLVM library propagated in the Libs.private of the respective .pc
2943     dnl file which ensures complete dependency information when statically
2944     dnl linking.
2945     if test "x$enable_glx" == xgallium-xlib; then
2946         GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $LLVM_LIBS"
2947     fi
2948     if test "x$enable_gallium_osmesa" = xyes; then
2949         OSMESA_PC_LIB_PRIV="$OSMESA_PC_LIB_PRIV $LLVM_LIBS"
2950     fi
2951 fi
2952
2953 AM_CONDITIONAL(HAVE_GALLIUM_SVGA, test "x$HAVE_GALLIUM_SVGA" = xyes)
2954 AM_CONDITIONAL(HAVE_GALLIUM_I915, test "x$HAVE_GALLIUM_I915" = xyes)
2955 AM_CONDITIONAL(HAVE_GALLIUM_PL111, test "x$HAVE_GALLIUM_PL111" = xyes)
2956 AM_CONDITIONAL(HAVE_GALLIUM_R300, test "x$HAVE_GALLIUM_R300" = xyes)
2957 AM_CONDITIONAL(HAVE_GALLIUM_R600, test "x$HAVE_GALLIUM_R600" = xyes)
2958 AM_CONDITIONAL(HAVE_GALLIUM_RADEONSI, test "x$HAVE_GALLIUM_RADEONSI" = xyes)
2959 AM_CONDITIONAL(HAVE_GALLIUM_NOUVEAU, test "x$HAVE_GALLIUM_NOUVEAU" = xyes)
2960 AM_CONDITIONAL(HAVE_GALLIUM_FREEDRENO, test "x$HAVE_GALLIUM_FREEDRENO" = xyes)
2961 AM_CONDITIONAL(HAVE_GALLIUM_ETNAVIV, test "x$HAVE_GALLIUM_ETNAVIV" = xyes)
2962 AM_CONDITIONAL(HAVE_GALLIUM_IMX, test "x$HAVE_GALLIUM_IMX" = xyes)
2963 AM_CONDITIONAL(HAVE_GALLIUM_TEGRA, test "x$HAVE_GALLIUM_TEGRA" = xyes)
2964 AM_CONDITIONAL(HAVE_GALLIUM_SOFTPIPE, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes)
2965 AM_CONDITIONAL(HAVE_GALLIUM_LLVMPIPE, test "x$HAVE_GALLIUM_LLVMPIPE" = xyes)
2966 AM_CONDITIONAL(HAVE_GALLIUM_SWR, test "x$HAVE_GALLIUM_SWR" = xyes)
2967 AM_CONDITIONAL(HAVE_GALLIUM_SWRAST, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes -o \
2968                                          "x$HAVE_GALLIUM_LLVMPIPE" = xyes -o \
2969                                          "x$HAVE_GALLIUM_SWR" = xyes)
2970 AM_CONDITIONAL(HAVE_GALLIUM_V3D, test "x$HAVE_GALLIUM_V3D" = xyes)
2971 AM_CONDITIONAL(HAVE_GALLIUM_VC4, test "x$HAVE_GALLIUM_VC4" = xyes)
2972 AM_CONDITIONAL(HAVE_GALLIUM_VIRGL, test "x$HAVE_GALLIUM_VIRGL" = xyes)
2973
2974 AM_CONDITIONAL(HAVE_GALLIUM_STATIC_TARGETS, test "x$enable_shared_pipe_drivers" = xno)
2975
2976 if test "x$enable_dri" = xyes; then
2977     GALLIUM_PIPE_LOADER_DEFINES="$GALLIUM_PIPE_LOADER_DEFINES -DHAVE_PIPE_LOADER_DRI"
2978 fi
2979
2980 if test "x$have_drisw_kms" = xyes; then
2981     GALLIUM_PIPE_LOADER_DEFINES="$GALLIUM_PIPE_LOADER_DEFINES -DHAVE_PIPE_LOADER_KMS"
2982 fi
2983 AC_SUBST([GALLIUM_PIPE_LOADER_DEFINES])
2984
2985 AM_CONDITIONAL(HAVE_I915_DRI, test x$HAVE_I915_DRI = xyes)
2986 AM_CONDITIONAL(HAVE_I965_DRI, test x$HAVE_I965_DRI = xyes)
2987 AM_CONDITIONAL(HAVE_NOUVEAU_DRI, test x$HAVE_NOUVEAU_DRI = xyes)
2988 AM_CONDITIONAL(HAVE_R200_DRI, test x$HAVE_R200_DRI = xyes)
2989 AM_CONDITIONAL(HAVE_RADEON_DRI, test x$HAVE_RADEON_DRI = xyes)
2990 AM_CONDITIONAL(HAVE_SWRAST_DRI, test x$HAVE_SWRAST_DRI = xyes)
2991
2992 AM_CONDITIONAL(HAVE_RADEON_VULKAN, test "x$HAVE_RADEON_VULKAN" = xyes)
2993 AM_CONDITIONAL(HAVE_INTEL_VULKAN, test "x$HAVE_INTEL_VULKAN" = xyes)
2994
2995 AM_CONDITIONAL(HAVE_AMD_DRIVERS, test "x$HAVE_GALLIUM_RADEONSI" = xyes -o \
2996                                       "x$HAVE_RADEON_VULKAN" = xyes)
2997
2998 AM_CONDITIONAL(HAVE_BROADCOM_DRIVERS, test "x$HAVE_GALLIUM_VC4" = xyes -o \
2999                                       "x$HAVE_GALLIUM_V3D" = xyes)
3000
3001 AM_CONDITIONAL(HAVE_INTEL_DRIVERS, test "x$HAVE_INTEL_VULKAN" = xyes -o \
3002                                         "x$HAVE_I965_DRI" = xyes)
3003
3004 AM_CONDITIONAL(NEED_RADEON_DRM_WINSYS, test "x$HAVE_GALLIUM_R300" = xyes -o \
3005                                             "x$HAVE_GALLIUM_R600" = xyes -o \
3006                                             "x$HAVE_GALLIUM_RADEONSI" = xyes)
3007 AM_CONDITIONAL(NEED_WINSYS_XLIB, test "x$enable_glx" = xgallium-xlib)
3008 AM_CONDITIONAL(HAVE_GALLIUM_COMPUTE, test x$enable_opencl = xyes)
3009 AM_CONDITIONAL(HAVE_GALLIUM_LLVM, test "x$enable_llvm" = xyes)
3010 AM_CONDITIONAL(USE_V3D_SIMULATOR, test x$USE_V3D_SIMULATOR = xyes)
3011 AM_CONDITIONAL(USE_VC4_SIMULATOR, test x$USE_VC4_SIMULATOR = xyes)
3012
3013 AM_CONDITIONAL(HAVE_LIBDRM, test "x$have_libdrm" = xyes)
3014 AM_CONDITIONAL(HAVE_OSMESA, test "x$enable_osmesa" = xyes)
3015 AM_CONDITIONAL(HAVE_GALLIUM_OSMESA, test "x$enable_gallium_osmesa" = xyes)
3016 AM_CONDITIONAL(HAVE_COMMON_OSMESA, test "x$enable_osmesa" = xyes -o \
3017                                         "x$enable_gallium_osmesa" = xyes)
3018
3019 AM_CONDITIONAL(HAVE_X86_ASM, test "x$asm_arch" = xx86 -o "x$asm_arch" = xx86_64)
3020 AM_CONDITIONAL(HAVE_X86_64_ASM, test "x$asm_arch" = xx86_64)
3021 AM_CONDITIONAL(HAVE_SPARC_ASM, test "x$asm_arch" = xsparc)
3022 AM_CONDITIONAL(HAVE_PPC64LE_ASM, test "x$asm_arch" = xppc64le)
3023 AM_CONDITIONAL(HAVE_AARCH64_ASM, test "x$asm_arch" = xaarch64)
3024 AM_CONDITIONAL(HAVE_ARM_ASM, test "x$asm_arch" = xarm)
3025
3026 AC_SUBST([NINE_MAJOR], 1)
3027 AC_SUBST([NINE_MINOR], 0)
3028 AC_SUBST([NINE_PATCH], 0)
3029 AC_SUBST([NINE_VERSION], "$NINE_MAJOR.$NINE_MINOR.$NINE_PATCH")
3030
3031 AC_SUBST([VDPAU_MAJOR], 1)
3032 AC_SUBST([VDPAU_MINOR], 0)
3033
3034 if test "x$enable_va" = xyes; then
3035     VA_MAJOR=`$PKG_CONFIG --modversion libva | $SED -n 's/\([[^\.]]*\)\..*$/\1/p'`
3036     VA_MINOR=`$PKG_CONFIG --modversion libva | $SED -n 's/.*\.\(.*\)\..*$/\1/p'`
3037 fi
3038 AC_SUBST([VA_MAJOR], $VA_MAJOR)
3039 AC_SUBST([VA_MINOR], $VA_MINOR)
3040
3041 AM_CONDITIONAL(HAVE_VULKAN_COMMON, test "x$VULKAN_DRIVERS" != "x")
3042
3043 AC_SUBST([XVMC_MAJOR], 1)
3044 AC_SUBST([XVMC_MINOR], 0)
3045
3046 AC_SUBST([XA_MAJOR], 2)
3047 AC_SUBST([XA_MINOR], 4)
3048 AC_SUBST([XA_PATCH], 0)
3049 AC_SUBST([XA_VERSION], "$XA_MAJOR.$XA_MINOR.$XA_PATCH")
3050
3051 AC_ARG_ENABLE(valgrind,
3052               [AS_HELP_STRING([--enable-valgrind],
3053                              [Build mesa with valgrind support (default: auto)])],
3054                              [VALGRIND=$enableval], [VALGRIND=auto])
3055 if test "x$VALGRIND" != xno; then
3056     PKG_CHECK_MODULES(VALGRIND, [valgrind], [have_valgrind=yes], [have_valgrind=no])
3057 fi
3058 AC_MSG_CHECKING([whether to enable Valgrind support])
3059 if test "x$VALGRIND" = xauto; then
3060     VALGRIND="$have_valgrind"
3061 fi
3062
3063 if test "x$VALGRIND" = "xyes"; then
3064     if ! test "x$have_valgrind" = xyes; then
3065         AC_MSG_ERROR([Valgrind support required but not present])
3066     fi
3067     AC_DEFINE([HAVE_VALGRIND], 1, [Use valgrind intrinsics to suppress false warnings])
3068 fi
3069
3070 AC_MSG_RESULT([$VALGRIND])
3071
3072 dnl Restore LDFLAGS and CPPFLAGS
3073 LDFLAGS="$_SAVE_LDFLAGS"
3074 CPPFLAGS="$_SAVE_CPPFLAGS"
3075
3076 dnl Suppress clang's warnings about unused CFLAGS and CXXFLAGS
3077 if test "x$acv_mesa_CLANG" = xyes; then
3078     CFLAGS="$CFLAGS -Qunused-arguments"
3079     CXXFLAGS="$CXXFLAGS -Qunused-arguments"
3080 fi
3081
3082 dnl Add user CFLAGS and CXXFLAGS
3083 CFLAGS="$CFLAGS $USER_CFLAGS"
3084 CXXFLAGS="$CXXFLAGS $USER_CXXFLAGS"
3085
3086 dnl Substitute the config
3087 AC_CONFIG_FILES([Makefile
3088                  src/Makefile
3089                  src/amd/Makefile
3090                  src/amd/vulkan/Makefile
3091                  src/broadcom/Makefile
3092                  src/compiler/Makefile
3093                  src/egl/Makefile
3094                  src/egl/main/egl.pc
3095                  src/egl/wayland/wayland-drm/Makefile
3096                  src/gallium/Makefile
3097                  src/gallium/auxiliary/Makefile
3098                  src/gallium/auxiliary/pipe-loader/Makefile
3099                  src/gallium/drivers/freedreno/Makefile
3100                  src/gallium/drivers/i915/Makefile
3101                  src/gallium/drivers/llvmpipe/Makefile
3102                  src/gallium/drivers/nouveau/Makefile
3103                  src/gallium/drivers/pl111/Makefile
3104                  src/gallium/drivers/r300/Makefile
3105                  src/gallium/drivers/r600/Makefile
3106                  src/gallium/drivers/radeonsi/Makefile
3107                  src/gallium/drivers/softpipe/Makefile
3108                  src/gallium/drivers/svga/Makefile
3109                  src/gallium/drivers/swr/Makefile
3110                  src/gallium/drivers/tegra/Makefile
3111                  src/gallium/drivers/etnaviv/Makefile
3112                  src/gallium/drivers/imx/Makefile
3113                  src/gallium/drivers/v3d/Makefile
3114                  src/gallium/drivers/vc4/Makefile
3115                  src/gallium/drivers/virgl/Makefile
3116                  src/gallium/state_trackers/clover/Makefile
3117                  src/gallium/state_trackers/dri/Makefile
3118                  src/gallium/state_trackers/glx/xlib/Makefile
3119                  src/gallium/state_trackers/nine/Makefile
3120                  src/gallium/state_trackers/omx/Makefile
3121                  src/gallium/state_trackers/omx/bellagio/Makefile
3122                  src/gallium/state_trackers/omx/tizonia/Makefile
3123                  src/gallium/state_trackers/osmesa/Makefile
3124                  src/gallium/state_trackers/va/Makefile
3125                  src/gallium/state_trackers/vdpau/Makefile
3126                  src/gallium/state_trackers/xa/Makefile
3127                  src/gallium/state_trackers/xa/xa_tracker.h
3128                  src/gallium/state_trackers/xvmc/Makefile
3129                  src/gallium/targets/d3dadapter9/Makefile
3130                  src/gallium/targets/d3dadapter9/d3d.pc
3131                  src/gallium/targets/dri/Makefile
3132                  src/gallium/targets/libgl-xlib/Makefile
3133                  src/gallium/targets/omx/Makefile
3134                  src/gallium/targets/opencl/Makefile
3135                  src/gallium/targets/opencl/mesa.icd
3136                  src/gallium/targets/osmesa/Makefile
3137                  src/gallium/targets/osmesa/osmesa.pc
3138                  src/gallium/targets/pipe-loader/Makefile
3139                  src/gallium/targets/va/Makefile
3140                  src/gallium/targets/vdpau/Makefile
3141                  src/gallium/targets/xa/Makefile
3142                  src/gallium/targets/xa/xatracker.pc
3143                  src/gallium/targets/xvmc/Makefile
3144                  src/gallium/tests/trivial/Makefile
3145                  src/gallium/tests/unit/Makefile
3146                  src/gallium/winsys/etnaviv/drm/Makefile
3147                  src/gallium/winsys/imx/drm/Makefile
3148                  src/gallium/winsys/freedreno/drm/Makefile
3149                  src/gallium/winsys/i915/drm/Makefile
3150                  src/gallium/winsys/nouveau/drm/Makefile
3151                  src/gallium/winsys/pl111/drm/Makefile
3152                  src/gallium/winsys/radeon/drm/Makefile
3153                  src/gallium/winsys/amdgpu/drm/Makefile
3154                  src/gallium/winsys/svga/drm/Makefile
3155                  src/gallium/winsys/sw/dri/Makefile
3156                  src/gallium/winsys/sw/kms-dri/Makefile
3157                  src/gallium/winsys/sw/null/Makefile
3158                  src/gallium/winsys/sw/wrapper/Makefile
3159                  src/gallium/winsys/sw/xlib/Makefile
3160                  src/gallium/winsys/tegra/drm/Makefile
3161                  src/gallium/winsys/v3d/drm/Makefile
3162                  src/gallium/winsys/vc4/drm/Makefile
3163                  src/gallium/winsys/virgl/drm/Makefile
3164                  src/gallium/winsys/virgl/vtest/Makefile
3165                  src/gbm/Makefile
3166                  src/gbm/main/gbm.pc
3167                  src/glx/Makefile
3168                  src/glx/apple/Makefile
3169                  src/glx/tests/Makefile
3170                  src/glx/windows/Makefile
3171                  src/glx/windows/windowsdriproto.pc
3172                  src/gtest/Makefile
3173                  src/intel/Makefile
3174                  src/loader/Makefile
3175                  src/mapi/Makefile
3176                  src/mapi/es1api/glesv1_cm.pc
3177                  src/mapi/es2api/glesv2.pc
3178                  src/mapi/glapi/gen/Makefile
3179                  src/mesa/Makefile
3180                  src/mesa/gl.pc
3181                  src/mesa/drivers/dri/dri.pc
3182                  src/mesa/drivers/dri/common/Makefile
3183                  src/mesa/drivers/dri/i915/Makefile
3184                  src/mesa/drivers/dri/i965/Makefile
3185                  src/mesa/drivers/dri/Makefile
3186                  src/mesa/drivers/dri/nouveau/Makefile
3187                  src/mesa/drivers/dri/r200/Makefile
3188                  src/mesa/drivers/dri/radeon/Makefile
3189                  src/mesa/drivers/dri/swrast/Makefile
3190                  src/mesa/drivers/osmesa/Makefile
3191                  src/mesa/drivers/osmesa/osmesa.pc
3192                  src/mesa/drivers/x11/Makefile
3193                  src/mesa/main/tests/Makefile
3194                  src/mesa/state_tracker/tests/Makefile
3195                  src/util/Makefile
3196                  src/util/tests/fast_idiv_by_const/Makefile
3197                  src/util/tests/hash_table/Makefile
3198                  src/util/tests/set/Makefile
3199                  src/util/tests/string_buffer/Makefile
3200                  src/util/tests/vma/Makefile
3201                  src/util/xmlpool/Makefile
3202                  src/vulkan/Makefile])
3203
3204 AC_OUTPUT
3205
3206 # Fix up dependencies in *.Plo files, where we changed the extension of a
3207 # source file
3208 $SED -i -e 's/brw_blorp.cpp/brw_blorp.c/' src/mesa/drivers/dri/i965/.deps/brw_blorp.Plo
3209
3210 rm -f src/compiler/spirv/spirv_info.lo
3211 echo "# dummy" > src/compiler/spirv/.deps/spirv_info.Plo
3212
3213 rm -f src/compiler/nir/.deps/nir_intrinsics.Plo
3214 echo "# dummy" > src/compiler/nir/.deps/nir_intrinsics.Plo
3215
3216 dnl
3217 dnl Output some configuration info for the user
3218 dnl
3219 echo ""
3220 echo "        prefix:          $prefix"
3221 echo "        exec_prefix:     $exec_prefix"
3222 echo "        libdir:          $libdir"
3223 echo "        includedir:      $includedir"
3224
3225 dnl API info
3226 echo ""
3227 echo "        OpenGL:          $enable_opengl (ES1: $enable_gles1 ES2: $enable_gles2)"
3228
3229 dnl Driver info
3230 echo ""
3231 case "x$enable_osmesa$enable_gallium_osmesa" in
3232 xnoyes)
3233         echo "        OSMesa:          lib$OSMESA_LIB (Gallium)"
3234         ;;
3235 xyesno)
3236         echo "        OSMesa:          lib$OSMESA_LIB"
3237         ;;
3238 xnono)
3239         echo "        OSMesa:          no"
3240         ;;
3241 esac
3242
3243 echo ""
3244 if test "x$enable_dri" != xno; then
3245         echo "        DRI platform:    $dri_platform"
3246         if test -z "$DRI_DIRS"; then
3247             echo "        DRI drivers:     no"
3248         else
3249             echo "        DRI drivers:     $DRI_DIRS"
3250         fi
3251         echo "        DRI driver dir:  $DRI_DRIVER_INSTALL_DIR"
3252 fi
3253
3254 case "x$enable_glx" in
3255 xdri)
3256     echo "        GLX:             DRI-based"
3257     ;;
3258 xxlib)
3259     echo "        GLX:             Xlib-based"
3260     ;;
3261 xgallium-xlib)
3262     echo "        GLX:             Xlib-based (Gallium)"
3263     ;;
3264 *)
3265     echo "        GLX:             $enable_glx"
3266     ;;
3267 esac
3268
3269 dnl EGL
3270 echo ""
3271 echo "        EGL:             $enable_egl"
3272 if test "$enable_egl" = yes; then
3273
3274     egl_drivers=""
3275     if test "x$enable_dri" != "xno"; then
3276         egl_drivers="$egl_drivers builtin:egl_dri2"
3277     fi
3278     if test "x$enable_dri3" != "xno"; then
3279         egl_drivers="$egl_drivers builtin:egl_dri3"
3280     fi
3281
3282     echo "        EGL drivers:    $egl_drivers"
3283 fi
3284 if test "x$enable_gbm" = xyes; then
3285     echo "        GBM:             yes"
3286 else
3287     echo "        GBM:             no"
3288 fi
3289
3290     echo "        EGL/Vulkan/VL platforms:   $platforms"
3291
3292 # Vulkan
3293 echo ""
3294 if test "x$VULKAN_DRIVERS" != x; then
3295     echo "        Vulkan drivers:  $VULKAN_DRIVERS"
3296     echo "        Vulkan ICD dir:  $VULKAN_ICD_INSTALL_DIR"
3297 else
3298     echo "        Vulkan drivers:  no"
3299 fi
3300
3301 echo ""
3302 if test "x$enable_llvm" = xyes; then
3303     echo "        llvm:            yes"
3304     echo "        llvm-config:     $LLVM_CONFIG"
3305     echo "        llvm-version:    $LLVM_VERSION"
3306 else
3307     echo "        llvm:            no"
3308 fi
3309
3310 echo ""
3311 if test -n "$with_gallium_drivers"; then
3312     echo "        Gallium drivers: $gallium_drivers"
3313     echo "        Gallium st:      $gallium_st"
3314 else
3315     echo "        Gallium:         no"
3316 fi
3317
3318 echo ""
3319 if test "x$enable_gallium_extra_hud" != xyes; then
3320     echo "        HUD extra stats: no"
3321 else
3322     echo "        HUD extra stats: yes"
3323 fi
3324
3325 if test "x$enable_lmsensors" != xyes; then
3326     echo "        HUD lmsensors:   no"
3327 else
3328     echo "        HUD lmsensors:   yes"
3329 fi
3330
3331 echo ""
3332 if test "x$HAVE_GALLIUM_SWR" != x; then
3333     if test "x$HAVE_SWR_BUILTIN" = xyes; then
3334         echo "        SWR archs:       $swr_archs (builtin)"
3335     else
3336         echo "        SWR archs:       $swr_archs"
3337     fi
3338 fi
3339
3340 dnl Libraries
3341 echo ""
3342 echo "        Shared libs:     $enable_shared"
3343 echo "        Static libs:     $enable_static"
3344 echo "        Shared-glapi:    $enable_shared_glapi"
3345
3346 dnl Compiler options
3347 # cleanup the CFLAGS/CXXFLAGS/LDFLAGS/DEFINES vars
3348 cflags=`echo $CFLAGS | \
3349     $SED 's/^ *//;s/  */ /;s/ *$//'`
3350 cxxflags=`echo $CXXFLAGS | \
3351     $SED 's/^ *//;s/  */ /;s/ *$//'`
3352 ldflags=`echo $LDFLAGS | $SED 's/^ *//;s/  */ /;s/ *$//'`
3353 defines=`echo $DEFINES | $SED 's/^ *//;s/  */ /;s/ *$//'`
3354 echo ""
3355 echo "        CFLAGS:          $cflags"
3356 echo "        CXXFLAGS:        $cxxflags"
3357 echo "        CXX11_CXXFLAGS:  $CXX11_CXXFLAGS"
3358 echo "        LDFLAGS:         $ldflags"
3359 echo "        Macros:          $defines"
3360 echo ""
3361 if test "x$enable_llvm" = xyes; then
3362     echo "        LLVM_CFLAGS:     $LLVM_CFLAGS"
3363     echo "        LLVM_CXXFLAGS:   $LLVM_CXXFLAGS"
3364     echo "        LLVM_CPPFLAGS:   $LLVM_CPPFLAGS"
3365     echo "        LLVM_LDFLAGS:    $LLVM_LDFLAGS"
3366     echo ""
3367 fi
3368 echo "        PYTHON:         $PYTHON"
3369
3370 echo ""
3371 echo "        Run '${MAKE-make}' to build Mesa"
3372 echo ""