+# Check for atomic intrinsics
+AC_CACHE_CHECK([for native atomic primitives], drm_cv_atomic_primitives, [
+ drm_cv_atomic_primitives="none"
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
+ int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
+ ]],[[]])], [drm_cv_atomic_primitives="Intel"],[])
+
+ if test "x$drm_cv_atomic_primitives" = "xnone"; then
+ AC_CHECK_HEADER([atomic_ops.h], drm_cv_atomic_primitives="libatomic-ops")
+ fi
+
+ # atomic functions defined in <atomic.h> & libc on Solaris
+ if test "x$drm_cv_atomic_primitives" = "xnone"; then
+ AC_CHECK_FUNC([atomic_cas_uint], drm_cv_atomic_primitives="Solaris")
+ fi
+])
+
+if test "x$drm_cv_atomic_primitives" = xIntel; then
+ AC_DEFINE(HAVE_LIBDRM_ATOMIC_PRIMITIVES, 1,
+ [Enable if your compiler supports the Intel __sync_* atomic primitives])
+fi
+if test "x$drm_cv_atomic_primitives" = "xlibatomic-ops"; then
+ AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, [Enable if you have libatomic-ops-dev installed])
+fi
+
+dnl Print out the approapriate message considering the value set be the
+dnl respective in $1.
+dnl $1 - value to be evaluated. Eg. $INTEL, $NOUVEAU, ...
+dnl $2 - libdrm shortname. Eg. intel, freedreno, ...
+dnl $3 - GPU name/brand. Eg. Intel, NVIDIA Tegra, ...
+dnl $4 - Configure switch. Eg. intel, omap-experimental-api, ...
+AC_DEFUN([LIBDRM_ATOMICS_NOT_FOUND_MSG], [
+ case "x$1" in
+ xyes) AC_MSG_ERROR([libdrm_$2 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 $3 GPUs by passing --disable-$4 to ./configure]) ;;
+ xauto) AC_MSG_WARN([Disabling $2. It depends on atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package.]) ;;
+ *) ;;
+ esac
+])
+
+if test "x$drm_cv_atomic_primitives" = "xnone"; then
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($INTEL, intel, Intel, intel)
+ INTEL=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($RADEON, radeon, Radeon, radeon)
+ RADEON=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($AMDGPU, amdgpu, AMD, amdgpu)
+ AMDGPU=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($NOUVEAU, nouveau, NVIDIA, nouveau)
+ NOUVEAU=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($OMAP, omap, OMAP, omap-experimental-api)
+ OMAP=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($FREEDRENO, freedreno, Qualcomm Adreno, freedreno)
+ FREEDRENO=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($TEGRA, tegra, NVIDIA Tegra, tegra-experimental-api)
+ TEGRA=no
+
+ LIBDRM_ATOMICS_NOT_FOUND_MSG($ETNAVIV, etnaviv, Vivante, etnaviv-experimental-api)
+ ETNAVIV=no
+else
+ if test "x$INTEL" = xauto; then
+ case $host_cpu in
+ i?86|x86_64) INTEL=yes ;;
+ *) INTEL=no ;;
+ esac
+ fi
+ if test "x$RADEON" = xauto; then
+ RADEON=yes
+ fi
+ if test "x$AMDGPU" = xauto; then
+ AMDGPU=yes
+ fi
+ if test "x$NOUVEAU" = xauto; then
+ NOUVEAU=yes
+ fi
+ if test "x$FREEDRENO" = xauto; then
+ case $host_cpu in
+ arm*|aarch64) FREEDRENO=yes ;;
+ *) FREEDRENO=no ;;
+ esac
+ fi
+ if test "x$VC4" = xauto; then
+ case $host_cpu in
+ arm*|aarch64) VC4=yes ;;
+ *) VC4=no ;;
+ esac
+ fi
+fi
+
+if test "x$INTEL" != "xno"; then
+ PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
+fi
+AC_SUBST(PCIACCESS_CFLAGS)
+AC_SUBST(PCIACCESS_LIBS)
+