Add support for Solaris libc atomic operations
[platform/upstream/libdrm.git] / configure.ac
1 #  Copyright 2005 Adam Jackson.
2 #
3 #  Permission is hereby granted, free of charge, to any person obtaining a
4 #  copy of this software and associated documentation files (the "Software"),
5 #  to deal in the Software without restriction, including without limitation
6 #  on the rights to use, copy, modify, merge, publish, distribute, sub
7 #  license, and/or sell copies of the Software, and to permit persons to whom
8 #  the Software is furnished to do so, subject to the following conditions:
9 #
10 #  The above copyright notice and this permission notice (including the next
11 #  paragraph) shall be included in all copies or substantial portions of the
12 #  Software.
13 #
14 #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 #  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 #  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
17 #  ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 #  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 AC_PREREQ(2.60)
22 AC_INIT([libdrm], 2.4.17, [dri-devel@lists.sourceforge.net], libdrm)
23 AC_USE_SYSTEM_EXTENSIONS
24 AC_CONFIG_SRCDIR([Makefile.am])
25 AM_INIT_AUTOMAKE([dist-bzip2])
26
27 AM_CONFIG_HEADER([config.h])
28
29 AC_DISABLE_STATIC
30 AC_PROG_LIBTOOL
31 AC_PROG_CC
32
33 AC_HEADER_STDC
34 AC_SYS_LARGEFILE
35 AC_FUNC_ALLOCA
36
37 PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
38 AC_SUBST(PTHREADSTUBS_CFLAGS)
39 AC_SUBST(PTHREADSTUBS_LIBS)
40
41 pkgconfigdir=${libdir}/pkgconfig
42 AC_SUBST(pkgconfigdir)
43 AC_ARG_ENABLE(udev,     AS_HELP_STRING([--enable-udev],
44                                 [Enable support for using udev instead of mknod (default: disabled)]),
45                                 [UDEV=$enableval], [UDEV=no])
46
47 AC_ARG_ENABLE(libkms,
48               AS_HELP_STRING([--enable-libkms],
49               [Enable KMS mm abstraction library (default: disabled)]),
50               [LIBKMS=$enableval], [LIBKMS=no])
51
52 AC_ARG_ENABLE(intel,
53               AS_HELP_STRING([--disable-intel],
54               [Enable support for intel's KMS API (default: auto)]),
55               [INTEL=$enableval], [INTEL=auto])
56
57 AC_ARG_ENABLE(vmwgfx-experimental-api,
58               AS_HELP_STRING([--enable-vmwgfx-experimental-api],
59               [Install vmwgfx's experimental kernel API header (default: disabled)]),
60               [VMWGFX=$enableval], [VMWGFX=no])
61
62 AC_ARG_ENABLE(nouveau-experimental-api,
63               AS_HELP_STRING([--enable-nouveau-experimental-api],
64               [Enable support for nouveau's experimental API (default: disabled)]),
65               [NOUVEAU=$enableval], [NOUVEAU=no])
66
67 AC_ARG_ENABLE(radeon-experimental-api,
68               AS_HELP_STRING([--enable-radeon-experimental-api],
69               [Enable support for radeon's KMS API (default: disabled)]),
70               [RADEON=$enableval], [RADEON=no])
71
72 dnl ===========================================================================
73 dnl check compiler flags
74 AC_DEFUN([LIBDRM_CC_TRY_FLAG], [
75   AC_MSG_CHECKING([whether $CC supports $1])
76
77   libdrm_save_CFLAGS="$CFLAGS"
78   CFLAGS="$CFLAGS $1"
79
80   AC_COMPILE_IFELSE([ ], [libdrm_cc_flag=yes], [libdrm_cc_flag=no])
81   CFLAGS="$libdrm_save_CFLAGS"
82
83   if test "x$libdrm_cc_flag" = "xyes"; then
84     ifelse([$2], , :, [$2])
85   else
86     ifelse([$3], , :, [$3])
87   fi
88   AC_MSG_RESULT([$libdrm_cc_flag])
89 ])
90
91 dnl We use clock_gettime to check for timeouts in drmWaitVBlank
92
93 AC_CHECK_FUNCS([clock_gettime], [CLOCK_LIB=],
94                [AC_CHECK_LIB([rt], [clock_gettime], [CLOCK_LIB=-lrt],
95                              [AC_MSG_ERROR([Couldn't find clock_gettime])])])
96 AC_SUBST([CLOCK_LIB])
97
98 dnl Use lots of warning flags with with gcc and compatible compilers
99
100 dnl Note: if you change the following variable, the cache is automatically
101 dnl skipped and all flags rechecked.  So there's no need to do anything
102 dnl else.  If for any reason you need to force a recheck, just change
103 dnl MAYBE_WARN in an ignorable way (like adding whitespace)
104
105 MAYBE_WARN="-Wall -Wextra \
106 -Wsign-compare -Werror-implicit-function-declaration \
107 -Wpointer-arith -Wwrite-strings -Wstrict-prototypes \
108 -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \
109 -Wpacked -Wswitch-enum -Wmissing-format-attribute \
110 -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
111 -Wdeclaration-after-statement -Wold-style-definition \
112 -Wno-missing-field-initializers -Wno-unused-parameter \
113 -Wno-attributes -Wno-long-long -Winline"
114
115 # invalidate cached value if MAYBE_WARN has changed
116 if test "x$libdrm_cv_warn_maybe" != "x$MAYBE_WARN"; then
117         unset libdrm_cv_warn_cflags
118 fi
119 AC_CACHE_CHECK([for supported warning flags], libdrm_cv_warn_cflags, [
120         echo
121         WARN_CFLAGS=""
122
123         # Some warning options are not supported by all versions of
124         # gcc, so test all desired options against the current
125         # compiler.
126         #
127         # Note that there are some order dependencies
128         # here. Specifically, an option that disables a warning will
129         # have no net effect if a later option then enables that
130         # warnings, (perhaps implicitly). So we put some grouped
131         # options (-Wall and -Wextra) up front and the -Wno options
132         # last.
133
134         for W in $MAYBE_WARN; do
135                 LIBDRM_CC_TRY_FLAG([$W], [WARN_CFLAGS="$WARN_CFLAGS $W"])
136         done
137
138         libdrm_cv_warn_cflags=$WARN_CFLAGS
139         libdrm_cv_warn_maybe=$MAYBE_WARN
140
141         AC_MSG_CHECKING([which warning flags were supported])])
142 WARN_CFLAGS="$libdrm_cv_warn_cflags"
143
144 if test "x$UDEV" = xyes; then
145         AC_DEFINE(UDEV, 1, [Have UDEV support])
146 fi
147
148 AM_CONDITIONAL(HAVE_LIBKMS, [test "x$LIBKMS" = xyes])
149
150 AM_CONDITIONAL(HAVE_VMWGFX, [test "x$VMWGFX" = xyes])
151 if test "x$VMWGFX" = xyes; then
152         AC_DEFINE(HAVE_VMWGFX, 1, [Have vmwgfx kernel headers])
153 fi
154
155 AM_CONDITIONAL(HAVE_NOUVEAU, [test "x$NOUVEAU" = xyes])
156
157 AM_CONDITIONAL(HAVE_RADEON, [test "x$RADEON" = xyes])
158
159 PKG_CHECK_MODULES(CAIRO, cairo, [HAVE_CAIRO=yes], [HAVE_CAIRO=no])
160 if test "x$HAVE_CAIRO" = xyes; then
161         AC_DEFINE(HAVE_CAIRO, 1, [Have cairo support])
162 fi
163 AM_CONDITIONAL(HAVE_CAIRO, [test "x$HAVE_CAIRO" = xyes])
164
165 # For enumerating devices in test case
166 PKG_CHECK_MODULES(LIBUDEV, libudev, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
167 if test "x$HAVE_LIBUDEV" = xyes; then
168         AC_DEFINE(HAVE_LIBUDEV, 1, [Have libudev support])
169 fi
170 AM_CONDITIONAL(HAVE_LIBUDEV, [test "x$HAVE_LIBUDEV" = xyes])
171
172 if test "x$INTEL" != "xno"; then
173     # Check for atomic intrinsics
174     AC_CACHE_CHECK([for native atomic primitives], drm_cv_atomic_primitives,
175     [
176             drm_cv_atomic_primitives="none"
177
178             AC_TRY_LINK([
179     int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); }
180     int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i, j, k); }
181     ], [],
182               drm_cv_atomic_primitives="Intel"
183               )
184
185             if test "x$drm_cv_atomic_primitives" = "xnone"; then
186                     AC_CHECK_HEADER([atomic_ops.h], drm_cv_atomic_primitives="libatomic-ops")
187             fi
188
189             # atomic functions defined in <atomic.h> & libc on Solaris
190             if test "x$drm_cv_atomic_primitives" = "xnone"; then
191                     AC_CHECK_FUNC([atomic_cas_uint],
192                                   drm_cv_atomic_primitives="Solaris")
193             fi
194
195     ])
196     if test "x$drm_cv_atomic_primitives" = xIntel; then
197             AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1,
198                       [Enable if your compiler supports the Intel __sync_* atomic primitives])
199     fi
200     if test "x$drm_cv_atomic_primitives" = "xlibatomic-ops"; then
201             AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, [Enable if you have libatomic-ops-dev installed])
202     fi
203
204     if test "x$drm_cv_atomic_primitives" = "xnone"; then
205             if test "x$INTEL" != "xauto"; then
206                     AC_MSG_ERROR([libdrm_intel depends upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for Intel GPUs by passing --disable-intel to ./configure])
207            else
208                     INTEL=no
209            fi
210     else
211            INTEL=yes
212     fi
213 fi
214
215 AM_CONDITIONAL(HAVE_INTEL, [test "x$INTEL" != "xno"])
216
217 AC_ARG_WITH([kernel-source],
218             [AS_HELP_STRING([--with-kernel-source],
219               [specify path to linux kernel source])],
220             [kernel_source="$with_kernel_source"])
221 AC_SUBST(kernel_source)
222
223 AC_SUBST(WARN_CFLAGS)
224 AC_OUTPUT([
225         Makefile
226         libkms/Makefile
227         libkms/libkms.pc
228         intel/Makefile
229         intel/libdrm_intel.pc
230         radeon/Makefile
231         radeon/libdrm_radeon.pc
232         nouveau/Makefile
233         nouveau/libdrm_nouveau.pc
234         tests/Makefile
235         tests/modeprint/Makefile
236         tests/modetest/Makefile
237         tests/kmstest/Makefile
238         include/Makefile
239         include/drm/Makefile
240         libdrm.pc])
241
242 echo ""
243 echo "$PACKAGE_STRING will be compiled with:"
244 echo ""
245 echo "  libkms         $LIBKMS"
246 echo "  Intel API      $INTEL"
247 echo "  vmwgfx API     $VMWGFX"
248 echo "  Radeon API     $RADEON"
249 echo "  Nouveau API    $NOUVEAU"
250 echo ""