configure.ac 111 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
dnl Copyright © 2011-2014 Intel Corporation
dnl Copyright © 2011-2014 Emil Velikov <emil.l.velikov@gmail.com>
dnl Copyright © 2007-2010 Dan Nicholson
dnl Copyright © 2010-2014 Marek Olšák <maraeo@gmail.com>
dnl Copyright © 2010-2014 Christian König
dnl Copyright © 2012-2014 Tom Stellard <tstellar@gmail.com>
dnl Copyright © 2009-2012 Jakob Bornecrantz
dnl Copyright © 2009-2014 Jon TURNEY
dnl Copyright © 2011-2012 Benjamin Franzke
dnl Copyright © 2008-2014 David Airlie
dnl Copyright © 2009-2013 Brian Paul
dnl
dnl Permission is hereby granted, free of charge, to any person obtaining a
dnl copy of this software and associated documentation files (the "Software"),
dnl to deal in the Software without restriction, including without limitation
dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
dnl and/or sell copies of the Software, and to permit persons to whom the
dnl Software is furnished to do so, subject to the following conditions:
dnl
dnl The above copyright notice and this permission notice (including the next
dnl paragraph) shall be included in all copies or substantial portions of the
dnl Software.
dnl
dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
dnl DEALINGS IN THE SOFTWARE.
dnl
32
dnl Process this file with autoconf to create configure.
33

34
AC_PREREQ([2.60])
35

36 37 38 39
dnl Tell the user about autoconf.html in the --help output
m4_divert_once([HELP_END], [
See docs/autoconf.html for more details on the options for Mesa.])

40 41
m4_define(MESA_VERSION, m4_normalize(m4_include(VERSION)))
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 49 50 51 52 53 54
dnl We only support native Windows builds (MinGW/MSVC) through SCons.
case "$host_os" in
mingw*)
    AC_MSG_ERROR([MinGW build not supported through autoconf/automake, use SCons instead])
    ;;
esac

55 56 57
# Support silent build rules, requires at least automake-1.11. Disable
# by either passing --disable-silent-rules to configure or passing V=1
# to make
58 59
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
    [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
60

61 62
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])

63 64 65
dnl Set internal versions
OSMESA_VERSION=8
AC_SUBST([OSMESA_VERSION])
66 67
OPENCL_VERSION=1
AC_SUBST([OPENCL_VERSION])
68

69 70 71 72 73 74
# The idea is that libdrm is distributed as one cohesive package, even
# though it is composed of multiple libraries. However some drivers
# may have different version requirements than others. This list
# codifies which drivers need which version of libdrm. Any libdrm
# version dependencies in non-driver-specific code should be reflected
# 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 80
LIBDRM_NVVIEUX_REQUIRED=2.4.66
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 101
XSHMFENCE_REQUIRED=1.1
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 107
dnl LLVM versions
LLVM_REQUIRED_GALLIUM=3.3.0
108
LLVM_REQUIRED_OPENCL=3.9.0
109
LLVM_REQUIRED_R600=3.9.0
110 111
LLVM_REQUIRED_RADEONSI=6.0.0
LLVM_REQUIRED_RADV=6.0.0
112
LLVM_REQUIRED_SWR=6.0.0
113

114 115 116 117
dnl Check for progs
AC_PROG_CPP
AC_PROG_CC
AC_PROG_CXX
118 119 120 121
dnl add this here, so the help for this environmnet variable is close to
dnl other CC/CXX flags related help
AC_ARG_VAR([CXX11_CXXFLAGS], [Compiler flag to enable C++11 support (only needed if not
                              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 133
AC_SYS_LARGEFILE

134

135 136 137
LT_PREREQ([2.2])
LT_INIT([disable-static])

138 139
AC_CHECK_PROG(RM, rm, [rm -f])

Matt Turner's avatar
Matt Turner committed
140
AX_PROG_BISON([],
141
              AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-parse.c"],
Matt Turner's avatar
Matt Turner committed
142
                    [AC_MSG_ERROR([bison not found - unable to compile glcpp-parse.y])]))
Matt Turner's avatar
Matt Turner committed
143
AX_PROG_FLEX([],
144
             AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-lex.c"],
Matt Turner's avatar
Matt Turner committed
145
                   [AC_MSG_ERROR([flex not found - unable to compile glcpp-lex.l])]))
146

147 148
AC_CHECK_PROG(INDENT, indent, indent, cat)
if test "x$INDENT" != "xcat"; then
149 150 151 152 153 154 155
    # Only GNU indent is supported
    INDENT_VERSION=`indent --version | grep GNU`
    if test $? -eq 0; then
       AC_SUBST(INDENT_FLAGS, '-i4 -nut -br -brs -npcs -ce -TGLubyte -TGLbyte -TBool')
    else
       INDENT="cat"
    fi
156 157
fi

158
AX_CHECK_PYTHON_MAKO_MODULE($PYTHON_MAKO_REQUIRED)
159

160
if test "$PYTHON" = ":"; then
161 162 163 164 165 166 167 168 169
    if test ! -f "$srcdir/src/util/format_srgb.c"; then
        AC_MSG_ERROR([Python not found - unable to generate sources])
    fi
else
    if test "x$acv_mako_found" = xno; then
        if test ! -f "$srcdir/src/mesa/main/format_unpack.c"; then
            AC_MSG_ERROR([Python mako module v$PYTHON_MAKO_REQUIRED or higher not found])
        fi
    fi
170
fi
171

172 173
AC_PROG_INSTALL

174 175
dnl We need a POSIX shell for parts of the build. Assume we have one
dnl in most cases.
176 177 178 179
case "$host_os" in
solaris*)
    # Solaris /bin/sh is too old/non-POSIX compliant
    AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh])
180
    SHELL="$POSIX_SHELL"
181 182 183
    ;;
esac

184 185 186 187 188 189 190 191 192 193
dnl clang is mostly GCC-compatible, but its version is much lower,
dnl so we have to check for it.
AC_MSG_CHECKING([if compiling with clang])

AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [[
#ifndef __clang__
       not clang
#endif
]])],
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
Ian Romanick's avatar
Ian Romanick committed
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
Ian Romanick's avatar
Ian Romanick committed
203 204 205 206 207 208
    AC_MSG_CHECKING([whether gcc version is sufficient])
    major=0
    minor=0

    GCC_VERSION=`$CC -dumpversion`
    if test $? -eq 0; then
209 210
        GCC_VERSION_MAJOR=`echo $GCC_VERSION | cut -d. -f1`
        GCC_VERSION_MINOR=`echo $GCC_VERSION | cut -d. -f2`
Ian Romanick's avatar
Ian Romanick committed
211 212
    fi

213
    if test $GCC_VERSION_MAJOR -lt 4 -o $GCC_VERSION_MAJOR -eq 4 -a $GCC_VERSION_MINOR -lt 2 ; then
Ian Romanick's avatar
Ian Romanick committed
214
        AC_MSG_RESULT([no])
215
        AC_MSG_ERROR([If using GCC, version 4.2.0 or later is required.])
Ian Romanick's avatar
Ian Romanick committed
216 217 218
    else
        AC_MSG_RESULT([yes])
    fi
219

220 221 222
    if test $GCC_VERSION_MAJOR -lt 4 -o $GCC_VERSION_MAJOR -eq 4 -a $GCC_VERSION_MINOR -lt 6 ; then
        USE_GNU99=yes
    fi
223 224 225
    if test "x$cross_compiling" = xyes; then
        GEN_ASM_OFFSETS=yes
    fi
Ian Romanick's avatar
Ian Romanick committed
226
fi
227

228 229 230 231 232 233 234
dnl We don't support building Mesa with Sun C compiler
dnl https://bugs.freedesktop.org/show_bug.cgi?id=93189
AC_CHECK_DECL([__SUNPRO_C], [SUNCC=yes], [SUNCC=no])
if test "x$SUNCC" = xyes; then
    AC_MSG_ERROR([Building with Sun C compiler is not supported, use GCC instead.])
fi

235 236
dnl Check for compiler builtins
AX_GCC_BUILTIN([__builtin_bswap32])
237
AX_GCC_BUILTIN([__builtin_bswap64])
238 239 240 241 242 243 244 245 246
AX_GCC_BUILTIN([__builtin_clz])
AX_GCC_BUILTIN([__builtin_clzll])
AX_GCC_BUILTIN([__builtin_ctz])
AX_GCC_BUILTIN([__builtin_expect])
AX_GCC_BUILTIN([__builtin_ffs])
AX_GCC_BUILTIN([__builtin_ffsll])
AX_GCC_BUILTIN([__builtin_popcount])
AX_GCC_BUILTIN([__builtin_popcountll])
AX_GCC_BUILTIN([__builtin_unreachable])
247

248
AX_GCC_FUNC_ATTRIBUTE([const])
249 250
AX_GCC_FUNC_ATTRIBUTE([flatten])
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)
Ian Romanick's avatar
Ian Romanick committed
263

264
dnl Make sure the pkg-config macros are defined
265 266 267 268 269
m4_ifndef([PKG_PROG_PKG_CONFIG],
    [m4_fatal([Could not locate the pkg-config autoconf macros.
  These are usually located in /usr/share/aclocal/pkg.m4. If your macros
  are in a different location, try setting the environment variable
  ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])])
270 271 272 273
PKG_PROG_PKG_CONFIG()

dnl LIB_DIR - library basename
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 278 279 280
_SAVE_LDFLAGS="$LDFLAGS"
_SAVE_CPPFLAGS="$CPPFLAGS"

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 287
    android=yes
    ;;
288
linux*|*-gnu*|gnu*|cygwin*)
289
    DEFINES="$DEFINES -D_GNU_SOURCE"
290
    ;;
291
solaris*)
292
    DEFINES="$DEFINES -DSVR4"
293
    ;;
294 295
esac

296 297
AM_CONDITIONAL(HAVE_ANDROID, test "x$android" = xyes)

298 299 300 301 302 303
# Toggle Werror since at some point clang started treating unknown -W
# flags as warnings, succeeding with the build, yet issuing an annoying
# warning.
save_CFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS -Werror"

304 305 306 307 308 309 310
dnl
dnl Check compiler flags
dnl
AX_CHECK_COMPILE_FLAG([-Wall],                                 [CFLAGS="$CFLAGS -Wall"])
AX_CHECK_COMPILE_FLAG([-Werror=implicit-function-declaration], [CFLAGS="$CFLAGS -Werror=implicit-function-declaration"])
AX_CHECK_COMPILE_FLAG([-Werror=missing-prototypes],            [CFLAGS="$CFLAGS -Werror=missing-prototypes"])
AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes],                  [CFLAGS="$CFLAGS -Wmissing-prototypes"])
311 312
dnl Dylan Baker: gcc and clang always accepr -Wno-*, hence check for the original warning, then set the no-* flag
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 317 318
AX_CHECK_COMPILE_FLAG([-fno-trapping-math],                    [CFLAGS="$CFLAGS -fno-trapping-math"])
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],                   [VISIBILITY_CFLAGS="-fvisibility=hidden"])

319 320 321 322 323
CFLAGS="$save_CFLAGS"

# Toggle Werror since at some point clang started treating unknown -W
# flags as warnings, succeeding with the build, yet issuing an annoying
# warning.
324 325 326 327 328 329 330 331
dnl
dnl Check C++ compiler flags
dnl
AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([-Wall],                                 [CXXFLAGS="$CXXFLAGS -Wall"])
AX_CHECK_COMPILE_FLAG([-fno-math-errno],                       [CXXFLAGS="$CXXFLAGS -fno-math-errno"])
AX_CHECK_COMPILE_FLAG([-fno-trapping-math],                    [CXXFLAGS="$CXXFLAGS -fno-trapping-math"])
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 335 336 337 338 339 340 341
AC_LANG_POP([C++])

# Flags to help ensure that certain portions of the code -- and only those
# portions -- can be built with MSVC:
# - src/util, src/gallium/auxiliary, rc/gallium/drivers/llvmpipe, and
# - non-Linux/Posix OpenGL portions needs to build on MSVC 2013 (which
#   supports most of C99)
# - the rest has no compiler compiler restrictions
342 343
AX_CHECK_COMPILE_FLAG([-Werror=pointer-arith],                 [MSVC2013_COMPAT_CFLAGS="$MSVC2013_COMPAT_CFLAGS -Werror=pointer-arith"])
AX_CHECK_COMPILE_FLAG([-Werror=vla],                           [MSVC2013_COMPAT_CFLAGS="$MSVC2013_COMPAT_CFLAGS -Werror=vla"])
344
AC_LANG_PUSH([C++])
345 346
AX_CHECK_COMPILE_FLAG([-Werror=pointer-arith],                 [MSVC2013_COMPAT_CXXFLAGS="$MSVC2013_COMPAT_CXXFLAGS -Werror=pointer-arith"])
AX_CHECK_COMPILE_FLAG([-Werror=vla],                           [MSVC2013_COMPAT_CXXFLAGS="$MSVC2013_COMPAT_CXXFLAGS -Werror=vla"])
347
AC_LANG_POP([C++])
348

349 350 351 352
AC_SUBST([MSVC2013_COMPAT_CFLAGS])
AC_SUBST([MSVC2013_COMPAT_CXXFLAGS])

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 359
fi

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
dnl
dnl Check whether C++11 is supported, if the environment variable
dnl CXX11_CXXFLAGS is set it takes precedence.
dnl

AC_LANG_PUSH([C++])

check_cxx11_available() {
    output_support=$1
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([
             #if !(__cplusplus >= 201103L)
             #error
             #endif
             #include <tuple>
        ])
    ], [
         AC_MSG_RESULT(yes)
         cxx11_support=yes
    ], AC_MSG_RESULT(no))
    eval "$output_support=\$cxx11_support"
}

HAVE_CXX11=no
save_CXXFLAGS="$CXXFLAGS"

dnl If the user provides a flag to enable c++11, then we test only this
if test "x$CXX11_CXXFLAGS" != "x"; then
   CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
   AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
   check_cxx11_available HAVE_CXX11
else
   dnl test whether c++11 is enabled by default
   AC_MSG_CHECKING(whether c++11 is enabled by default)
   check_cxx11_available HAVE_CXX11

   dnl C++11 not enabled by default, test whether -std=c++11 does the job
   if test "x$HAVE_CXX11" != "xyes"; then
       CXX11_CXXFLAGS=-std=c++11
       CXXFLAGS="$CXXFLAGS $CXX11_CXXFLAGS"
       AC_MSG_CHECKING(whether c++11 is enabled by via $CXX11_CXXFLAGS)
       check_cxx11_available HAVE_CXX11
   fi
fi

CXXFLAGS="$save_CXXFLAGS"
AM_CONDITIONAL(HAVE_STD_CXX11, test "x$HAVE_CXX11" = "xyes")
AC_SUBST(CXX11_CXXFLAGS)
AC_LANG_POP([C++])

410 411 412 413 414 415 416 417 418
dnl even if the compiler appears to support it, using visibility attributes isn't
dnl going to do anything useful currently on cygwin apart from emit lots of warnings
case "$host_os" in
cygwin*)
    VISIBILITY_CFLAGS=""
    VISIBILITY_CXXFLAGS=""
    ;;
esac

419 420 421
AC_SUBST([VISIBILITY_CFLAGS])
AC_SUBST([VISIBILITY_CXXFLAGS])

422 423 424 425
dnl For some reason, the test for -Wno-foo always succeeds with gcc, even if the
dnl option is not supported. Hence, check for -Wfoo instead.
AX_CHECK_COMPILE_FLAG([-Woverride-init],                    [WNO_OVERRIDE_INIT="$WNO_OVERRIDE_INIT -Wno-override-init"])         # gcc
AX_CHECK_COMPILE_FLAG([-Winitializer-overrides],            [WNO_OVERRIDE_INIT="$WNO_OVERRIDE_INIT -Wno-initializer-overrides"]) # clang
426 427
AC_SUBST([WNO_OVERRIDE_INIT])

428 429 430
dnl
dnl Optional flags, check for compiler support
dnl
431 432 433 434 435 436 437 438
SSE41_CFLAGS="-msse4.1"
dnl Code compiled by GCC with -msse* assumes a 16 byte aligned
dnl stack, but on x86-32 such alignment is not guaranteed.
case "$target_cpu" in
i?86)
    SSE41_CFLAGS="$SSE41_CFLAGS -mstackrealign"
    ;;
esac
439
save_CFLAGS="$CFLAGS"
440
CFLAGS="$SSE41_CFLAGS $CFLAGS"
441 442
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#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 449
}]])], SSE41_SUPPORTED=1)
CFLAGS="$save_CFLAGS"
450 451 452
if test "x$SSE41_SUPPORTED" = x1; then
    DEFINES="$DEFINES -DUSE_SSE41"
fi
453
AM_CONDITIONAL([SSE41_SUPPORTED], [test x$SSE41_SUPPORTED = x1])
454
AC_SUBST([SSE41_CFLAGS], $SSE41_CFLAGS)
455

456 457 458 459 460
dnl Check for new-style atomic builtins. We first check without linking to
dnl -latomic.
AC_MSG_CHECKING(whether __atomic_load_n is supported)
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <stdint.h>
461
int main() {
462 463 464
    struct {
        uint64_t *v;
    } x;
465 466
    return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
           (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
467 468 469 470 471 472 473 474 475 476 477 478 479
}]])], GCC_ATOMIC_BUILTINS_SUPPORTED=yes, GCC_ATOMIC_BUILTINS_SUPPORTED=no)

dnl If that didn't work, we try linking with -latomic, which is needed on some
dnl platforms.
if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != xyes; then
   save_LDFLAGS=$LDFLAGS
   LDFLAGS="$LDFLAGS -latomic"
   AC_LINK_IFELSE([AC_LANG_SOURCE([[
   #include <stdint.h>
   int main() {
        struct {
            uint64_t *v;
        } x;
480 481
        return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
               (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
482 483 484 485 486 487 488 489
   }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=yes LIBATOMIC_LIBS="-latomic",
          GCC_ATOMIC_BUILTINS_SUPPORTED=no)
   LDFLAGS=$save_LDFLAGS
fi
AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_SUPPORTED)

if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" = xyes; then
    DEFINES="$DEFINES -DUSE_GCC_ATOMIC_BUILTINS"
490
fi
491
AC_SUBST([LIBATOMIC_LIBS])
492

493 494 495 496 497 498 499 500 501 502 503 504 505 506
dnl Check if host supports 64-bit atomics
dnl note that lack of support usually results in link (not compile) error
AC_MSG_CHECKING(whether __sync_add_and_fetch_8 is supported)
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <stdint.h>
uint64_t v;
int main() {
    return __sync_add_and_fetch(&v, (uint64_t)1);
}]])], GCC_64BIT_ATOMICS_SUPPORTED=yes, GCC_64BIT_ATOMICS_SUPPORTED=no)
if test "x$GCC_64BIT_ATOMICS_SUPPORTED" != xyes; then
    DEFINES="$DEFINES -DMISSING_64BIT_ATOMICS"
fi
AC_MSG_RESULT($GCC_64BIT_ATOMICS_SUPPORTED)

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
dnl Check for Endianness
AC_C_BIGENDIAN(
   little_endian=no,
   little_endian=yes,
   little_endian=no,
   little_endian=no
)

dnl Check for POWER8 Architecture
PWR8_CFLAGS="-mpower8-vector"
have_pwr8_intrinsics=no
AC_MSG_CHECKING(whether gcc supports -mpower8-vector)
save_CFLAGS=$CFLAGS
CFLAGS="$PWR8_CFLAGS $CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
#error "Need GCC >= 4.8 for sane POWER8 support"
#endif
#include <altivec.h>
int main () {
    vector unsigned char r;
    vector unsigned int v = vec_splat_u32 (1);
    r = __builtin_vec_vgbbd ((vector unsigned char) v);
    return 0;
}]])], have_pwr8_intrinsics=yes)
CFLAGS=$save_CFLAGS

AC_ARG_ENABLE(pwr8,
535
   [AS_HELP_STRING([--disable-pwr8],
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
                   [disable POWER8-specific instructions])],
   [enable_pwr8=$enableval], [enable_pwr8=auto])

if test "x$enable_pwr8" = xno ; then
   have_pwr8_intrinsics=disabled
fi

if test $have_pwr8_intrinsics = yes && test $little_endian = yes ; then
   DEFINES="$DEFINES -D_ARCH_PWR8"
   CXXFLAGS="$CXXFLAGS $PWR8_CFLAGS"
   CFLAGS="$CFLAGS $PWR8_CFLAGS"
else
   PWR8_CFLAGS=
fi

AC_MSG_RESULT($have_pwr8_intrinsics)
if test "x$enable_pwr8" = xyes && test $have_pwr8_intrinsics = no ; then
   AC_MSG_ERROR([POWER8 compiler support not detected])
fi

if test $have_pwr8_intrinsics = yes && test $little_endian = no ; then
   AC_MSG_WARN([POWER8 optimization is enabled only on POWER8 Little-Endian])
fi

AC_SUBST([PWR8_CFLAGS], $PWR8_CFLAGS)

562 563
dnl Can't have static and shared libraries, default to static if user
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 573
    ;;
esac

574 575
AM_CONDITIONAL(BUILD_SHARED, test "x$enable_shared" = xyes)

576 577 578
dnl
dnl other compiler options
dnl
579
AC_ARG_ENABLE([debug],
580 581
    [AS_HELP_STRING([--enable-debug],
        [use debug compiler flags and macros @<:@default=disabled@:>@])],
582 583
    [enable_debug="$enableval"],
    [enable_debug=no]
584
)
585 586 587 588 589 590 591 592

AC_ARG_ENABLE([profile],
    [AS_HELP_STRING([--enable-profile],
        [enable profiling of code @<:@default=disabled@:>@])],
    [enable_profile="$enableval"],
    [enable_profile=no]
)

593 594 595 596 597 598
AC_ARG_ENABLE([sanitize],
    [AS_HELP_STRING([--enable-sanitize@<:@=address|undefined@:>@],
        [enable code sanitizer @<:@default=disabled@:>@])],
    [enable_sanitize="$enableval"],
    [enable_sanitize=no])

599 600 601 602 603 604 605 606 607 608
if test "x$enable_profile" = xyes; then
    DEFINES="$DEFINES -DPROFILE"
    if test "x$GCC" = xyes; then
        CFLAGS="$CFLAGS -fno-omit-frame-pointer"
    fi
    if test "x$GXX" = xyes; then
        CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"
    fi
fi

609 610
if test "x$enable_debug" = xyes; then
    DEFINES="$DEFINES -DDEBUG"
611 612 613
    if test "x$enable_profile" = xyes; then
        AC_MSG_WARN([Debug and Profile are enabled at the same time])
    fi
614
    if test "x$GCC" = xyes; then
615 616 617 618 619 620
        if ! echo "$CFLAGS" | grep -q -e '-g'; then
            CFLAGS="$CFLAGS -g"
        fi
        if ! echo "$CFLAGS" | grep -q -e '-O'; then
            CFLAGS="$CFLAGS -O0"
        fi
621 622
    fi
    if test "x$GXX" = xyes; then
623 624 625 626 627 628
        if ! echo "$CXXFLAGS" | grep -q -e '-g'; then
            CXXFLAGS="$CXXFLAGS -g"
        fi
        if ! echo "$CXXFLAGS" | grep -q -e '-O'; then
            CXXFLAGS="$CXXFLAGS -O0"
        fi
629
    fi
630 631
else
   DEFINES="$DEFINES -DNDEBUG"
632
fi
633

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
if test "x$enable_sanitize" != xno; then
    if test "x$enable_profile" = xyes; then
        AC_MSG_WARN([Sanitize and Profile are enabled at the same time])
    fi

    CFLAGS="$CFLAGS -fsanitize=$enable_sanitize"
    CXXFLAGS="$CXXFLAGS -fsanitize=$enable_sanitize"
    LDFLAGS="$LDFLAGS -fsanitize=$enable_sanitize"

    AC_LINK_IFELSE(
        [AC_LANG_SOURCE([int main(){return 0;}])],
        [],
        [AC_MSG_FAILURE([sanitize flags '$enable_sanitize' not supported])])
fi

Jon Turney's avatar
Jon Turney committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
dnl
dnl Check if linker supports -Bsymbolic
dnl
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
AC_MSG_CHECKING([if ld supports -Bsymbolic])
AC_LINK_IFELSE(
    [AC_LANG_SOURCE([int main() { return 0;}])],
    [AC_MSG_RESULT([yes])
        BSYMBOLIC="-Wl,-Bsymbolic";],
    [AC_MSG_RESULT([no])
        BSYMBOLIC="";])
LDFLAGS=$save_LDFLAGS

AC_SUBST([BSYMBOLIC])

665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
dnl
dnl Check if linker supports garbage collection
dnl
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,--gc-sections"
AC_MSG_CHECKING([whether ld supports --gc-sections])
AC_LINK_IFELSE(
    [AC_LANG_SOURCE([static char UnusedFunc() { return 5; } int main() { return 0;}])],
    [AC_MSG_RESULT([yes])
        GC_SECTIONS="-Wl,--gc-sections";],
    [AC_MSG_RESULT([no])
        GC_SECTIONS="";])
LDFLAGS=$save_LDFLAGS

AC_SUBST([GC_SECTIONS])

681 682 683 684 685
dnl
dnl OpenBSD does not have DT_NEEDED entries for libc by design
dnl so when these flags are passed to ld via libtool the checks will fail
dnl
case "$host_os" in
686
openbsd* | darwin* )
687 688
    LD_NO_UNDEFINED="" ;;
*)
689 690 691 692 693 694
    if test "x$enable_sanitize" = xno; then
        LD_NO_UNDEFINED="-Wl,--no-undefined"
    else
        LD_NO_UNDEFINED=""
    fi
    ;;
695 696 697 698
esac

AC_SUBST([LD_NO_UNDEFINED])

Jon Turney's avatar
Jon Turney committed
699 700 701 702 703
dnl
dnl Check if linker supports version scripts
dnl
AC_MSG_CHECKING([if the linker supports version-scripts])
save_LDFLAGS=$LDFLAGS
704
LDFLAGS="$LDFLAGS -Wl,--version-script=$srcdir/build-support/conftest.map"
Jon Turney's avatar
Jon Turney committed
705 706 707 708 709 710 711
AC_LINK_IFELSE(
    [AC_LANG_SOURCE([int main() { return 0;}])],
    [have_ld_version_script=yes;AC_MSG_RESULT(yes)],
    [have_ld_version_script=no; AC_MSG_RESULT(no)])
LDFLAGS=$save_LDFLAGS
AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")

712 713 714 715 716
dnl
dnl Check if linker supports dynamic list files
dnl
AC_MSG_CHECKING([if the linker supports --dynamic-list])
save_LDFLAGS=$LDFLAGS
717
LDFLAGS="$LDFLAGS -Wl,--dynamic-list=$srcdir/build-support/conftest.dyn"
718 719 720 721 722 723 724
AC_LINK_IFELSE(
    [AC_LANG_SOURCE([int main() { return 0;}])],
    [have_ld_dynamic_list=yes;AC_MSG_RESULT(yes)],
    [have_ld_dynamic_list=no; AC_MSG_RESULT(no)])
LDFLAGS=$save_LDFLAGS
AM_CONDITIONAL(HAVE_LD_DYNAMIC_LIST, test "$have_ld_dynamic_list" = "yes")

725 726 727 728 729 730 731 732 733 734 735 736 737
dnl
dnl OSX linker does not support build-id
dnl
case "$host_os" in
darwin*)
    LD_BUILD_ID=""
    ;;
*)
    LD_BUILD_ID="-Wl,--build-id=sha1"
    ;;
esac
AC_SUBST([LD_BUILD_ID])

738 739 740 741 742 743 744 745 746 747 748 749
dnl
dnl compatibility symlinks
dnl
case "$host_os" in
linux* )
    HAVE_COMPAT_SYMLINKS=yes ;;
* )
    HAVE_COMPAT_SYMLINKS=no ;;
esac

AM_CONDITIONAL(HAVE_COMPAT_SYMLINKS, test "x$HAVE_COMPAT_SYMLINKS" = xyes)

750 751 752
dnl
dnl library names
dnl
753 754 755 756 757 758 759 760 761
dnl Unfortunately we need to do a few things that libtool can't help us with,
dnl so we need some knowledge of shared library filenames:
dnl
dnl LIB_EXT is the extension used when creating symlinks for alternate
dnl filenames for a shared library which will be dynamically loaded
dnl
dnl IMP_LIB_EXT is the extension used when checking for the presence of a
dnl the file for a shared library we wish to link with
dnl
762 763
case "$host_os" in
darwin* )
764 765 766
    LIB_EXT='dylib'
    IMP_LIB_EXT=$LIB_EXT
    ;;
767
cygwin* )
768 769 770
    LIB_EXT='dll'
    IMP_LIB_EXT='dll.a'
    ;;
771
aix* )
772 773 774
    LIB_EXT='a'
    IMP_LIB_EXT=$LIB_EXT
    ;;
775
* )
776 777 778
    LIB_EXT='so'
    IMP_LIB_EXT=$LIB_EXT
    ;;
779
esac
780 781 782

AC_SUBST([LIB_EXT])

783 784 785 786 787
dnl
dnl Arch/platform-specific settings
dnl
AC_ARG_ENABLE([asm],
    [AS_HELP_STRING([--disable-asm],
Vinson Lee's avatar
Vinson Lee committed
788
        [disable assembly usage @<:@default=enabled on supported platforms@:>@])],
789 790 791 792 793 794 795
    [enable_asm="$enableval"],
    [enable_asm=yes]
)
asm_arch=""
AC_MSG_CHECKING([whether to enable assembly])
test "x$enable_asm" = xno && AC_MSG_RESULT([no])
# 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 800 801 802
        if test "x$host_cpu" != "x$target_cpu"; then
            enable_asm=no
            AC_MSG_RESULT([no, cross compiling])
        fi
803 804 805 806 807 808 809 810
        ;;
    esac
fi
# check for supported arches
if test "x$enable_asm" = xyes; then
    case "$host_cpu" in
    i?86)
        case "$host_os" in
811
        linux* | *freebsd* | dragonfly* | *netbsd* | openbsd* | gnu*)
812 813
            asm_arch=x86
            ;;
814 815
        esac
        ;;
816
    x86_64|amd64)
817
        case "$host_os" in
818
        linux* | *freebsd* | dragonfly* | *netbsd* | openbsd*)
819
            asm_arch=x86_64
820 821 822
            ;;
        esac
        ;;
823 824 825 826 827 828 829
    sparc*)
        case "$host_os" in
        linux*)
            asm_arch=sparc
            ;;
        esac
        ;;
830 831 832 833 834 835 836
    powerpc64le)
        case "$host_os" in
        linux*)
            asm_arch=ppc64le
            ;;
        esac
        ;;
837 838 839 840 841 842 843 844 845 846 847 848 849 850
    aarch64)
        case "$host_os" in
        linux*)
            asm_arch=aarch64
            ;;
        esac
        ;;
    arm)
        case "$host_os" in
        linux*)
            asm_arch=arm
            ;;
        esac
        ;;
851 852 853 854
    esac

    case "$asm_arch" in
    x86)
855
        DEFINES="$DEFINES -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM"
856 857
        AC_MSG_RESULT([yes, x86])
        ;;
858
    x86_64|amd64)
859
        DEFINES="$DEFINES -DUSE_X86_64_ASM"
860 861
        AC_MSG_RESULT([yes, x86_64])
        ;;
862
    sparc)
863
        DEFINES="$DEFINES -DUSE_SPARC_ASM"
864 865
        AC_MSG_RESULT([yes, sparc])
        ;;
866 867 868 869
    ppc64le)
        DEFINES="$DEFINES -DUSE_PPC64LE_ASM"
        AC_MSG_RESULT([yes, ppc64le])
        ;;
870 871 872 873 874 875 876 877
    aarch64)
        DEFINES="$DEFINES -DUSE_AARCH64_ASM"
        AC_MSG_RESULT([yes, aarch64])
        ;;
    arm)
        DEFINES="$DEFINES -DUSE_ARM_ASM"
        AC_MSG_RESULT([yes, arm])
        ;;
878 879 880 881 882 883
    *)
        AC_MSG_RESULT([no, platform not supported])
        ;;
    esac
fi

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 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
AC_MSG_CHECKING([whether strtod has locale support])
AC_LINK_IFELSE([AC_LANG_SOURCE([[
    #define _GNU_SOURCE
    #include <stdlib.h>
    #include <locale.h>
    #ifdef HAVE_XLOCALE_H
    #include <xlocale.h>
    #endif
    int main() {
       locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
       const char *s = "1.0";
       char *end;
       double d = strtod_l(s, end, loc);
       float f = strtof_l(s, end, loc);
       freelocale(loc);
       return 0;
    }]])],
  [DEFINES="$DEFINES -DHAVE_STRTOD_L"];
   AC_MSG_RESULT([yes]),
   AC_MSG_RESULT([no]))

915 916
dnl Check to see if dlopen is in default libraries (like Solaris, which
dnl has it in libc), or if libdl is needed to get it.
Matt Turner's avatar
Matt Turner committed
917
AC_CHECK_FUNC([dlopen], [],
918
    [AC_CHECK_LIB([dl], [dlopen],
Matt Turner's avatar
Matt Turner committed
919
       [DLOPEN_LIBS="-ldl"])])
920
AC_SUBST([DLOPEN_LIBS])
921

922
dnl Check if that library also has dladdr
923 924 925 926
save_LIBS="$LIBS"
LIBS="$LIBS $DLOPEN_LIBS"
AC_CHECK_FUNCS([dladdr])
LIBS="$save_LIBS"
927

928 929
AC_CHECK_FUNC([dl_iterate_phdr], [DEFINES="$DEFINES -DHAVE_DL_ITERATE_PHDR"])

930
case "$host_os" in
931
darwin*)
932 933 934 935
    ;;
*)
    AC_CHECK_FUNCS([clock_gettime], [CLOCK_LIB=],
                   [AC_CHECK_LIB([rt], [clock_gettime], [CLOCK_LIB=-lrt],
936
                                 [AC_MSG_ERROR([Could not find clock_gettime])])])
937 938 939
    AC_SUBST([CLOCK_LIB])
    ;;
esac
940

941 942 943
dnl See if posix_memalign is available
AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"])

944 945
dnl Check for zlib
PKG_CHECK_MODULES([ZLIB], [zlib >= $ZLIB_REQUIRED])
946
DEFINES="$DEFINES -DHAVE_ZLIB"
947

948
dnl Check for pthreads
949 950 951 952
AX_PTHREAD
if test "x$ax_pthread_ok" = xno; then
    AC_MSG_ERROR([Building mesa on this platform requires pthreads])
fi
953 954
dnl AX_PTHREADS leaves PTHREAD_LIBS empty for gcc and sets PTHREAD_CFLAGS
dnl to -pthread, which causes problems if we need -lpthread to appear in
955 956 957 958 959
dnl pkgconfig files.  Since Android doesn't have a pthread lib, this check
dnl is not valid for that platform.
if test "x$android" = xno; then
    test -z "$PTHREAD_LIBS" && PTHREAD_LIBS="-lpthread"
fi
960 961 962 963 964
dnl According to the manual when using pthreads, one should add -pthread to
dnl both compile and link-time arguments.
dnl In practise that should be sufficient for all platforms, since any
dnl platforms build with GCC and Clang support the flag.
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 971 972 973 974 975 976 977
    pthread_stubs_possible="no"
    ;;
* )
    pthread_stubs_possible="yes"
    ;;
esac

if test "x$pthread_stubs_possible" = xyes; then
978
    PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs >= 0.4)
979
fi
980

981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
save_LIBS="$LIBS"
LIBS="$PTHREAD_LIBS"
AC_MSG_CHECKING(whether pthread_setaffinity_np is supported)
AC_LINK_IFELSE([AC_LANG_SOURCE([[
    #define _GNU_SOURCE
    #include <pthread.h>
    int main() {
       void *a = (void*) &pthread_setaffinity_np;
       long b = (long) a;
       return (int) b;
    }]])],
  [DEFINES="$DEFINES -DHAVE_PTHREAD_SETAFFINITY"];
   AC_MSG_RESULT([yes]),
   AC_MSG_RESULT([no]))
LIBS="$save_LIBS"

997 998 999
dnl Check for futex for fast inline simple_mtx_t.
AC_CHECK_HEADER([linux/futex.h], [DEFINES="$DEFINES -DHAVE_LINUX_FUTEX_H"])

1000 1001 1002 1003 1004 1005 1006
dnl SELinux awareness.
AC_ARG_ENABLE([selinux],
    [AS_HELP_STRING([--enable-selinux],
        [Build SELinux-aware Mesa @<:@default=disabled@:>@])],
    [MESA_SELINUX="$enableval"],
    [MESA_SELINUX=no])
if test "x$enable_selinux" = "xyes"; then
1007 1008 1009 1010 1011 1012
    PKG_CHECK_MODULES([SELINUX], [libselinux], [],
        [AC_CHECK_HEADER([selinux/selinux.h],[],
                         [AC_MSG_ERROR([SELinux headers not found])])
         AC_CHECK_LIB([selinux],[is_selinux_enabled],[],
                      [AC_MSG_ERROR([SELinux library not found])])
         SELINUX_LIBS="-lselinux"])
1013 1014
    DEFINES="$DEFINES -DMESA_SELINUX"
fi
1015
AC_SUBST([SELINUX_CFLAGS])
1016
AC_SUBST([SELINUX_LIBS])
1017

1018 1019 1020
dnl
dnl LLVM
dnl
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
AC_ARG_ENABLE([llvm-shared-libs],
    [AS_HELP_STRING([--enable-llvm-shared-libs],
        [link with LLVM shared libraries @<:@default=enabled@:>@])],
    [enable_llvm_shared_libs="$enableval"],
    [enable_llvm_shared_libs=yes])

AC_ARG_WITH([llvm-prefix],
    [AS_HELP_STRING([--with-llvm-prefix],
        [Prefix for LLVM installations in non-standard locations])],
    [llvm_prefix="$withval"],
    [llvm_prefix=''])

PKG_CHECK_MODULES([LIBELF], [libelf], [have_libelf=yes], [have_libelf=no])
if test "x$have_libelf" = xno; then
   LIBELF_LIBS=''
   LIBELF_CFLAGS=''
   AC_CHECK_LIB([elf], [elf_memory], [have_libelf=yes;LIBELF_LIBS=-lelf], [have_libelf=no])
   AC_SUBST([LIBELF_LIBS])
   AC_SUBST([LIBELF_CFLAGS])
fi

1042 1043 1044 1045 1046 1047 1048 1049
if test -z "$LLVM_CONFIG"; then
    if test -n "$llvm_prefix"; then
        AC_PATH_TOOL([LLVM_CONFIG], [llvm-config], [no], ["$llvm_prefix/bin"])
    else
        AC_PATH_TOOL([LLVM_CONFIG], [llvm-config], [no])
    fi
fi

1050 1051 1052 1053
llvm_add_component() {
    new_llvm_component=$1
    driver_name=$2

1054 1055 1056 1057 1058
    if $LLVM_CONFIG --components | grep -iqw $new_llvm_component ; then
        LLVM_COMPONENTS="${LLVM_COMPONENTS} ${new_llvm_component}"
    else
        AC_MSG_ERROR([LLVM component '$new_llvm_component' not enabled in your LLVM build. Required by $driver_name.])
    fi
1059 1060
}

1061 1062 1063 1064 1065 1066 1067 1068 1069
llvm_add_optional_component() {
    new_llvm_component=$1
    driver_name=$2

    if $LLVM_CONFIG --components | grep -iqw $new_llvm_component ; then
        LLVM_COMPONENTS="${LLVM_COMPONENTS} ${new_llvm_component}"
    fi
}

1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
llvm_add_default_components() {
    driver_name=$1

    # Required default components
    llvm_add_component "bitwriter" $driver_name
    llvm_add_component "engine" $driver_name
    llvm_add_component "mcdisassembler" $driver_name
    llvm_add_component "mcjit" $driver_name

    # Optional default components
1080
    llvm_add_optional_component "inteljitevents" $driver_name
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
}

llvm_add_target() {
    new_llvm_target=$1
    driver_name=$2

    if $LLVM_CONFIG --targets-built | grep -iqw $new_llvm_target ; then
        llvm_add_component $new_llvm_target $driver_name
    else
        AC_MSG_ERROR([LLVM target '$new_llvm_target' not enabled in your LLVM build. Required by $driver_name.])
    fi
}

1094 1095 1096
# Call this inside ` ` to get the return value.
# $1 is the llvm-config command with arguments.
strip_unwanted_llvm_flags() {
1097
    echo " `$1` " | sed -E \
1098
        -e 's/[[[:space:]]]+-m[[^[:space:]]]*//g' \
1099 1100 1101
        -e 's/[[[:space:]]]+-DNDEBUG[[[:space:]]]/ /g' \
        -e 's/[[[:space:]]]+-D_GNU_SOURCE[[[:space:]]]/ /g' \
        -e 's/[[[:space:]]]+-pedantic[[[:space:]]]/ /g' \
1102 1103 1104
        -e 's/[[[:space:]]]+-W[[^[:space:]]]*//g' \
        -e 's/[[[:space:]]]+-O[[^[:space:]]]*//g' \
        -e 's/[[[:space:]]]+-g[[^[:space:]]]*//g' \
1105
        -e 's/-fno-rtti[[[:space:]]]/-Fno-rtti /g' \
1106
        -e 's/[[[:space:]]]+-f[[^[:space:]]]*//g' \
1107 1108 1109
        -e 's/-Fno-rtti[[[:space:]]]/-fno-rtti /g' \
        -e 's/^[[[:space:]]]//' \
        -e 's/[[[:space:]]]$//'
1110 1111
}

1112 1113 1114 1115 1116 1117 1118
llvm_set_environment_variables() {
    if test "x$LLVM_CONFIG" != xno; then
        LLVM_VERSION=`$LLVM_CONFIG --version | egrep -o '^[[0-9.]]+'`
        LLVM_CPPFLAGS=`strip_unwanted_llvm_flags "$LLVM_CONFIG --cppflags"`
        LLVM_INCLUDEDIR=`$LLVM_CONFIG --includedir`
        LLVM_LIBDIR=`$LLVM_CONFIG --libdir`

1119
        # We need to respect LLVM_CPPFLAGS when compiling LLVM headers.
1120
        save_CFLAGS="$CFLAGS"
1121
        CFLAGS="$CFLAGS $LLVM_CPPFLAGS"
1122

1123 1124 1125 1126
        AC_COMPUTE_INT([LLVM_VERSION_MAJOR], [LLVM_VERSION_MAJOR],
            [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
        AC_COMPUTE_INT([LLVM_VERSION_MINOR], [LLVM_VERSION_MINOR],
            [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
1127 1128
        AC_COMPUTE_INT([LLVM_VERSION_PATCH], [LLVM_VERSION_PATCH],
            [#include "${LLVM_INCLUDEDIR}/llvm/Config/llvm-config.h"])
1129

1130 1131
        CFLAGS="$save_CFLAGS"

1132
        # Only needed for LLVM < 3.6.0
1133 1134 1135 1136
        if test -z "$LLVM_VERSION_PATCH"; then
            LLVM_VERSION_PATCH=0
        fi

1137
        LLVM_VERSION_INT="${LLVM_VERSION_MAJOR}0${LLVM_VERSION_MINOR}"
1138

1139
        FOUND_LLVM=yes
1140
    else
1141
        FOUND_LLVM=no
1142 1143 1144 1145
        LLVM_VERSION_INT=0
    fi
}

1146
require_llvm() {
1147 1148
    if test "x$enable_llvm" != "xyes"; then
        AC_MSG_ERROR([--enable-llvm is required when building $1])
1149 1150 1151
    fi
}

1152 1153
llvm_require_version() {
    require_llvm $2
1154 1155 1156 1157 1158 1159 1160 1161 1162

    llvm_target_version_major=`echo $1 | cut -d. -f1 | egrep -o '^[[0-9]]+'`
    llvm_target_version_minor=`echo $1 | cut -d. -f2 | egrep -o '^[[0-9]]+'`
    llvm_target_version_patch=`echo $1 | cut -d. -f3 | egrep -o '^[[0-9]]+'`

    if test "$LLVM_VERSION_MAJOR" -gt "$llvm_target_version_major"; then
        # major > required major
        #  --> OK
        return
1163
    fi
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184

    if test "$LLVM_VERSION_MAJOR" -eq "$llvm_target_version_major"; then
        if test "$LLVM_VERSION_MINOR" -gt "$llvm_target_version_minor"; then
            # major = required major and
            # minor > required minor
            #  --> OK
            return
        else
            if test "$LLVM_VERSION_MINOR" -eq "$llvm_target_version_minor"; then
                if test "$LLVM_VERSION_PATCH" -ge "$llvm_target_version_patch"; then
                    # major = required major and
                    # minor = required minor and
                    # patch >= required patch
                    #  --> OK
                    return
                fi
            fi
        fi
    fi

    AC_MSG_ERROR([LLVM $1 or newer is required for $2])
1185 1186 1187 1188 1189 1190 1191 1192 1193
}

radeon_llvm_check() {
    if test ${LLVM_VERSION_INT} -lt 307; then
        amdgpu_llvm_target_name='r600'
    else
        amdgpu_llvm_target_name='amdgpu'
    fi

1194
    llvm_require_version $*
1195

1196
    llvm_add_target $amdgpu_llvm_target_name $2
1197

1198 1199 1200
    llvm_add_default_components $2
    llvm_add_component "bitreader" $2
    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 1205 1206
    fi
}

1207 1208 1209 1210 1211 1212 1213 1214
llvm_set_environment_variables

AC_SUBST([LLVM_CFLAGS])
AC_SUBST([LLVM_CXXFLAGS])
AC_SUBST([LLVM_LIBS])
AC_SUBST([LLVM_LDFLAGS])
AC_SUBST([LLVM_INCLUDEDIR])

1215 1216 1217
dnl
dnl libunwind
dnl
1218
PKG_CHECK_EXISTS(libunwind, [HAVE_LIBUNWIND=yes], [HAVE_LIBUNWIND=no])
1219 1220 1221 1222
AC_ARG_ENABLE([libunwind],
    [AS_HELP_STRING([--enable-libunwind],
            [Use libunwind for backtracing (default: auto)])],
        [LIBUNWIND="$enableval"],
1223
        [LIBUNWIND="$HAVE_LIBUNWIND"])
1224 1225

if test "x$LIBUNWIND" = "xyes"; then
1226
    PKG_CHECK_MODULES(LIBUNWIND, libunwind)
1227 1228 1229 1230
    AC_DEFINE(HAVE_LIBUNWIND, 1, [Have libunwind support])
fi


1231
dnl Options for APIs
1232 1233
AC_ARG_ENABLE([opengl],
    [AS_HELP_STRING([--disable-opengl],
1234
        [disable support for standard OpenGL API @<:@default=enabled@:>@])],
1235 1236 1237
    [enable_opengl="$enableval"],
    [enable_opengl=yes])
AC_ARG_ENABLE([gles1],
1238 1239
    [AS_HELP_STRING([--disable-gles1],
        [disable support for OpenGL ES 1.x API @<:@default=enabled@:>@])],
1240
    [enable_gles1="$enableval"],
1241
    [enable_gles1=yes])
1242
AC_ARG_ENABLE([gles2],
1243 1244
    [AS_HELP_STRING([--disable-gles2],
        [disable support for OpenGL ES 2.x API @<:@default=enabled@:>@])],
1245
    [enable_gles2="$enableval"],
1246
    [enable_gles2=yes])
1247 1248 1249

AC_ARG_ENABLE([dri],
    [AS_HELP_STRING([--enable-dri],
1250
        [enable DRI modules @<:@default=enabled@:>@])],
1251
    [enable_dri="$enableval"],
1252
    [enable_dri=yes])
1253

1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
AC_ARG_ENABLE([gallium-extra-hud],
    [AS_HELP_STRING([--enable-gallium-extra-hud],
        [enable HUD block/NIC I/O HUD stats support @<:@default=disabled@:>@])],
    [enable_gallium_extra_hud="$enableval"],
    [enable_gallium_extra_hud=no])
AM_CONDITIONAL(HAVE_GALLIUM_EXTRA_HUD, test "x$enable_gallium_extra_hud" = xyes)
if test "x$enable_gallium_extra_hud" = xyes ; then
    DEFINES="${DEFINES} -DHAVE_GALLIUM_EXTRA_HUD=1"
fi

#TODO: no pkgconfig .pc available for libsensors.
#PKG_CHECK_MODULES([LIBSENSORS], [libsensors >= $LIBSENSORS_REQUIRED], [enable_lmsensors=yes], [enable_lmsensors=no])
AC_ARG_ENABLE([lmsensors],
    [AS_HELP_STRING([--enable-lmsensors],
        [enable HUD lmsensor support @<:@default=disabled@:>@])],
    [enable_lmsensors="$enableval"],
    [enable_lmsensors=no])
AM_CONDITIONAL(HAVE_LIBSENSORS, test "x$enable_lmsensors" = xyes)
if test "x$enable_lmsensors" = xyes ; then
    DEFINES="${DEFINES} -DHAVE_LIBSENSORS=1"
1274
    LIBSENSORS_LIBS="-lsensors"
1275
else
1276
    LIBSENSORS_LIBS=""
1277
fi
1278
AC_SUBST(LIBSENSORS_LIBS)
1279

1280 1281 1282 1283 1284 1285 1286 1287
case "$host_os" in
linux*)
    dri3_default=yes
    ;;
*)
    dri3_default=no
    ;;
esac
1288 1289 1290 1291 1292

if test "x$enable_dri" = xno; then
    dri3_default=no
fi

1293 1294
AC_ARG_ENABLE([dri3],
    [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 1300
    [AS_HELP_STRING([--enable-glx@<:@=dri|xlib|gallium-xlib@:>@],
        [enable the GLX library and choose an implementation @<:@default=auto@:>@])],
1301
    [enable_glx="$enableval"],
1302
    [enable_glx=yes])
1303 1304
AC_ARG_ENABLE([osmesa],
    [AS_HELP_STRING([--enable-osmesa],
1305
        [enable OSMesa library @<:@default=disabled@:>@])],
1306
    [enable_osmesa="$enableval"],
1307
    [enable_osmesa=no])
1308 1309 1310 1311 1312
AC_ARG_ENABLE([gallium-osmesa],
    [AS_HELP_STRING([--enable-gallium-osmesa],
        [enable Gallium implementation of the OSMesa library @<:@default=disabled@:>@])],
    [enable_gallium_osmesa="$enableval"],
    [enable_gallium_osmesa=no])
1313 1314 1315 1316 1317 1318
AC_ARG_ENABLE([egl],
    [AS_HELP_STRING([--disable-egl],
        [disable EGL library @<:@default=enabled@:>@])],
    [enable_egl="$enableval"],
    [enable_egl=yes])

1319 1320
AC_ARG_ENABLE([xa],
    [AS_HELP_STRING([--enable-xa],
1321
        [enable build of the XA X Acceleration API @<:@default=disabled@:>@])],
1322 1323
    [enable_xa="$enableval"],
    [enable_xa=no])
1324 1325
AC_ARG_ENABLE([gbm],
   [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 1331 1332 1333 1334 1335
          enable_gbm=no
          ;;
       *)
          enable_gbm=yes
          ;;
    esac])
1336 1337 1338 1339 1340
AC_ARG_ENABLE([nine],
    [AS_HELP_STRING([--enable-nine],
        [enable build of the nine Direct3D9 API @<:@default=no@:>@])],
    [enable_nine="$enableval"],
    [enable_nine=no])
1341

1342 1343 1344 1345
AC_ARG_ENABLE([xvmc],
   [AS_HELP_STRING([--enable-xvmc],
         [enable xvmc library @<:@default=auto@:>@])],
   [enable_xvmc="$enableval"],
1346
   [enable_xvmc=auto])
1347 1348 1349 1350 1351
AC_ARG_ENABLE([vdpau],
   [AS_HELP_STRING([--enable-vdpau],
         [enable vdpau library @<:@default=auto@:>@])],
   [enable_vdpau="$enableval"],
   [enable_vdpau=auto])
1352 1353
AC_ARG_ENABLE([omx],
   [AS_HELP_STRING([--enable-omx],
1354 1355
         [DEPRECATED: Use --enable-omx-bellagio or --enable-omx-tizonia instead @<:@default=auto@:>@])],
   [AC_MSG_ERROR([--enable-omx is deprecated. Use --enable-omx-bellagio or --enable-omx-tizonia instead.])],
1356 1357 1358 1359 1360 1361
   [])
AC_ARG_ENABLE([omx-bellagio],
   [AS_HELP_STRING([--enable-omx-bellagio],
         [enable OpenMAX Bellagio library @<:@default=disabled@:>@])],
   [enable_omx_bellagio="$enableval"],
   [enable_omx_bellagio=no])
1362 1363 1364 1365 1366
AC_ARG_ENABLE([omx-tizonia],
   [AS_HELP_STRING([--enable-omx-tizonia],
         [enable OpenMAX Tizonia library @<:@default=disabled@:>@])],
   [enable_omx_tizonia="$enableval"],
   [enable_omx_tizonia=no])
1367 1368 1369 1370 1371
AC_ARG_ENABLE([va],
   [AS_HELP_STRING([--enable-va],
         [enable va library @<:@default=auto@:>@])],
   [enable_va="$enableval"],
   [enable_va=auto])
1372 1373
AC_ARG_ENABLE([opencl],
   [AS_HELP_STRING([--enable-opencl],
1374
         [enable OpenCL library @<:@default=disabled@:>@])],
1375
   [enable_opencl="$enableval"],
1376
   [enable_opencl=no])
1377 1378 1379
AC_ARG_ENABLE([opencl_icd],
   [AS_HELP_STRING([--enable-opencl-icd],
          [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 1388 1389
    [enable_gallium_tests="$enableval"],
    [enable_gallium_tests=no])

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 1396 1397

AC_ARG_WITH([gallium-drivers],
    [AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
        [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 1401
    [with_gallium_drivers="$withval"],
    [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
1402

1403 1404 1405 1406 1407 1408 1409
# Doing '--without-gallium-drivers' will set this variable to 'no'.  Clear it
# here so that the script doesn't choke on an unknown driver name later.
case "$with_gallium_drivers" in
    yes) with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT" ;;
    no) with_gallium_drivers='' ;;
esac

1410 1411 1412
if test "x$enable_opengl" = xno -a \
        "x$enable_gles1" = xno -a \
        "x$enable_gles2" = xno -a \
1413
        "x$enable_nine" = xno -a \
1414
        "x$enable_xa" = xno -a \
1415 1416
        "x$enable_xvmc" = xno -a \
        "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 1422 1423
    AC_MSG_ERROR([at least one API should be enabled])
fi

1424 1425 1426 1427 1428
if test "x$enable_omx_bellagio" = xyes -a \
        "x$enable_omx_tizonia" = xyes; then
   AC_MSG_ERROR([Can't enable both bellagio and tizonia at same time])
fi

1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
# Building OpenGL ES1 and/or ES2 without OpenGL is not supported on mesa 9.0.x
if test "x$enable_opengl" = xno -a \
        "x$enable_gles1" = xyes; then
    AC_MSG_ERROR([Building OpenGL ES1 without OpenGL is not supported])
fi

if test "x$enable_opengl" = xno -a \
        "x$enable_gles2" = xyes; then
    AC_MSG_ERROR([Building OpenGL ES2 without OpenGL is not supported])
fi

1440 1441 1442 1443 1444 1445
AM_CONDITIONAL(HAVE_OPENGL, test "x$enable_opengl" = xyes)
AM_CONDITIONAL(HAVE_OPENGL_ES1, test "x$enable_gles1" = xyes)
AM_CONDITIONAL(HAVE_OPENGL_ES2, test "x$enable_gles2" = xyes)
AM_CONDITIONAL(NEED_OPENGL_COMMON, test "x$enable_opengl" = xyes -o \
                                        "x$enable_gles1" = xyes -o \
                                        "x$enable_gles2" = xyes)
1446
AM_CONDITIONAL(NEED_KHRPLATFORM, test "x$enable_egl" = xyes -o \
1447
                                      "x$enable_opengl" = xyes -o \
1448 1449
                                      "x$enable_gles1" = xyes -o \
                                      "x$enable_gles2" = xyes)
1450

1451 1452 1453 1454 1455 1456 1457 1458 1459
# Validate GLX options
if test "x$enable_glx" = xyes; then
    if test "x$enable_dri" = xyes; then
        enable_glx=dri
    elif test -n "$with_gallium_drivers"; then
        enable_glx=gallium-xlib
    else
        enable_glx=xlib
    fi
1460
fi
1461 1462 1463 1464 1465 1466
case "x$enable_glx" in
xdri | xxlib | xgallium-xlib)
    # GLX requires OpenGL
    if test "x$enable_opengl" = xno; then
        AC_MSG_ERROR([GLX cannot be built without OpenGL])
    fi
1467

1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    # Check individual dependencies
    case "x$enable_glx" in
    xdri)
        if test "x$enable_dri" = xno; then
            AC_MSG_ERROR([DRI-based GLX requires DRI to be enabled])
        fi
        ;;
    xxlib)
        if test "x$enable_dri" = xyes; then
            AC_MSG_ERROR([Xlib-based GLX cannot be built with DRI enabled])
        fi
        ;;
    xgallium-xlib )
        if test "x$enable_dri" = xyes; then
            AC_MSG_ERROR([Xlib-based (Gallium) GLX cannot be built with DRI enabled])
        fi
        if test -z "$with_gallium_drivers"; then
            AC_MSG_ERROR([Xlib-based (Gallium) GLX cannot be built without Gallium enabled])
        fi
        ;;
    esac
    ;;
xno)
    ;;
*)
    AC_MSG_ERROR([Illegal value for --enable-glx: $enable_glx])
    ;;
esac
1496

1497
AM_CONDITIONAL(HAVE_GLX, test "x$enable_glx" != xno)
1498 1499 1500
AM_CONDITIONAL(HAVE_DRI_GLX, test "x$enable_glx" = xdri)
AM_CONDITIONAL(HAVE_XLIB_GLX, test "x$enable_glx" = xxlib)
AM_CONDITIONAL(HAVE_GALLIUM_XLIB_GLX, test "x$enable_glx" = xgallium-xlib)
1501

1502 1503
DEFAULT_GL_LIB_NAME=GL

1504 1505 1506 1507 1508
dnl
dnl Libglvnd configuration
dnl
AC_ARG_ENABLE([libglvnd],
    [AS_HELP_STRING([--enable-libglvnd],
1509
        [Build GLX and EGL for libglvnd @<:@default=disabled@:>@])],
1510 1511
    [enable_libglvnd="$enableval"],
    [enable_libglvnd=no])
1512 1513
AM_CONDITIONAL(USE_LIBGLVND, test "x$enable_libglvnd" = xyes)

1514 1515 1516 1517 1518 1519 1520
if test "x$enable_libglvnd" = xyes ; then
    case "x$enable_glx" in
    xxlib | xgallium-xlib )
        AC_MSG_ERROR([cannot build libgvnd when Xlib-GLX or Gallium-Xlib-GLX is enabled])
        ;;
    esac

1521
    PKG_CHECK_MODULES([GLVND], libglvnd >= 0.2.0)
1522
    LIBGLVND_DATADIR=`$PKG_CONFIG --variable=datadir libglvnd`
1523 1524 1525
    AC_SUBST([LIBGLVND_DATADIR])

    DEFINES="${DEFINES} -DUSE_LIBGLVND=1"
1526
    DEFAULT_GL_LIB_NAME=GLX_mesa
1527 1528 1529 1530

    if test "x$enable_glx" = xno -a "x$enable_egl" = xno; then
        AC_MSG_ERROR([cannot build libglvnd without GLX or EGL])
    fi
1531 1532
fi

1533 1534 1535
AC_ARG_WITH([gl-lib-name],
  [AS_HELP_STRING([--with-gl-lib-name@<:@=NAME@:>@],
    [specify GL library name @<:@default=GL@:>@])],
1536 1537
  [AC_MSG_ERROR([--with-gl-lib-name is no longer supported. Rename the library manually if needed.])],
  [])
1538 1539 1540
AC_ARG_WITH([osmesa-lib-name],
  [AS_HELP_STRING([--with-osmesa-lib-name@<:@=NAME@:>@],
    [specify OSMesa library name @<:@default=OSMesa@:>@])],
1541 1542 1543 1544
  [AC_MSG_ERROR([--with-osmesa-lib-name is no longer supported. Rename the library manually if needed.])],
  [])
GL_LIB="$DEFAULT_GL_LIB_NAME"
OSMESA_LIB=OSMesa
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555

dnl
dnl Mangled Mesa support
dnl
AC_ARG_ENABLE([mangling],
  [AS_HELP_STRING([--enable-mangling],
    [enable mangled symbols and library name @<:@default=disabled@:>@])],
  [enable_mangling="${enableval}"],
  [enable_mangling=no]
)
if test "x${enable_mangling}" = "xyes" ; then
1556 1557 1558
  if test "x$enable_libglvnd" = xyes; then
    AC_MSG_ERROR([Conflicting options --enable-mangling and --enable-libglvnd.])
  fi
1559 1560 1561 1562 1563 1564 1565
  DEFINES="${DEFINES} -DUSE_MGL_NAMESPACE"
  GL_LIB="Mangled${GL_LIB}"
  OSMESA_LIB="Mangled${OSMESA_LIB}"
fi
AC_SUBST([GL_LIB])
AC_SUBST([OSMESA_LIB])

1566 1567 1568 1569 1570 1571 1572 1573 1574
dnl HACK when building glx + glvnd we ship gl.pc, despite that glvnd should do it
dnl Thus we need to use GL as a DSO name.
if test "x$enable_libglvnd" = xyes -a "x$enable_glx" != xno; then
  GL_PKGCONF_LIB="GL"
else
  GL_PKGCONF_LIB="$GL_LIB"
fi
AC_SUBST([GL_PKGCONF_LIB])

1575 1576 1577 1578
# Check for libdrm
PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED],
                  [have_libdrm=yes], [have_libdrm=no])
if test "x$have_libdrm" = xyes; then
1579
    DEFINES="$DEFINES -DHAVE_LIBDRM"
1580 1581
fi

1582 1583 1584 1585 1586 1587 1588
require_libdrm() {
    if test "x$have_libdrm" != xyes; then
       AC_MSG_ERROR([$1 requires libdrm >= $LIBDRM_REQUIRED])
    fi
}


1589 1590 1591 1592
# Select which platform-dependent DRI code gets built
case "$host_os" in
darwin*)
    dri_platform='apple' ;;
1593 1594 1595
cygwin*)
    dri_platform='windows' ;;
gnu*)
1596 1597 1598 1599 1600
    dri_platform='none' ;;
*)
    dri_platform='drm' ;;
esac

1601 1602 1603 1604
if test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes; then
    have_drisw_kms='yes'
fi

1605 1606
AM_CONDITIONAL(HAVE_DRICOMMON, test "x$enable_dri" = xyes )
AM_CONDITIONAL(HAVE_DRISW, test "x$enable_dri" = xyes )
1607
AM_CONDITIONAL(HAVE_DRISW_KMS, test "x$have_drisw_kms" = xyes )
1608 1609
AM_CONDITIONAL(HAVE_DRI2, test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )
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 1612
AM_CONDITIONAL(HAVE_LMSENSORS, test "x$enable_lmsensors" = xyes )
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 )
Matt Turner's avatar
Matt Turner committed
1615

1616 1617
AC_ARG_ENABLE([shared-glapi],
    [AS_HELP_STRING([--enable-shared-glapi],
1618
        [Enable shared glapi for OpenGL @<:@default=enabled@:>@])],
1619
    [enable_shared_glapi="$enableval"],
1620
    [enable_shared_glapi=yes])
Matt Turner's avatar