1dnl
2dnl Copyright © 2013 Keith Packard
3dnl
4dnl Permission to use, copy, modify, distribute, and sell this software and its
5dnl documentation for any purpose is hereby granted without fee, provided that
6dnl the above copyright notice appear in all copies and that both that copyright
7dnl notice and this permission notice appear in supporting documentation, and
8dnl that the name of the copyright holders not be used in advertising or
9dnl publicity pertaining to distribution of the software without specific,
10dnl written prior permission.  The copyright holders make no representations
11dnl about the suitability of this software for any purpose.  It is provided "as
12dnl is" without express or implied warranty.
13dnl
14dnl THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15dnl INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16dnl EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17dnl CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18dnl DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19dnl TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20dnl OF THIS SOFTWARE.
21dnl
22dnl
23dnl Process this file with autoconf to create configure.
24
25AC_PREREQ([2.60])
26AC_INIT([libxshmfence], [1.3.3],
27        [https://gitlab.freedesktop.org/xorg/lib/libxshmfence/-/issues],
28        [libxshmfence])
29AC_CONFIG_SRCDIR([Makefile.am])
30AC_CONFIG_HEADERS([config.h])
31AC_CONFIG_MACRO_DIRS([m4])
32
33# Set common system defines for POSIX extensions, such as _GNU_SOURCE
34# Must be called before any macros that run the compiler (like LT_INIT
35# or XORG_DEFAULT_OPTIONS) to avoid autoconf errors.
36AC_USE_SYSTEM_EXTENSIONS
37
38# Initialize Automake
39AM_INIT_AUTOMAKE([foreign dist-xz])
40
41# Initialize libtool
42LT_INIT
43
44# Require xorg-macros: XORG_DEFAULT_OPTIONS, XORG_WITH_LINT
45m4_ifndef([XORG_MACROS_VERSION],
46          [m4_fatal([must install xorg-macros 1.3 or later before running autoconf/autogen])])
47XORG_MACROS_VERSION(1.3)
48XORG_DEFAULT_OPTIONS
49
50dnl Allow checking code with lint, sparse, etc.
51XORG_WITH_LINT
52LINT_FLAGS="${LINT_FLAGS} ${FONTENC_CFLAGS}"
53
54# Checks for typedefs, structures, and compiler characteristics.
55AC_SYS_LARGEFILE
56
57dnl
58dnl Locate a suitable tmp file system for creating shared memory files
59dnl
60
61AC_ARG_ENABLE(futex,	AS_HELP_STRING([--enable-futex], [Enable futexes (default: auto)]),
62		[FUTEX=$enableval], [FUTEX=auto])
63
64if test "x$FUTEX" = "xauto"; then
65	AC_CHECK_HEADER([linux/futex.h], [FUTEX=yes])
66fi
67
68if test "x$FUTEX" = "xauto"; then
69	AC_CHECK_HEADER([sys/umtx.h], [FUTEX=yes], [FUTEX=no],
70	    [#include <errno.h>
71	     #include <sys/types.h>])
72	if test "x$FUTEX" = "xyes"; then
73		AC_DEFINE(HAVE_UMTX, 1, [Use umtx])
74	fi
75fi
76
77if test "x$FUTEX" = "xyes"; then
78	PTHREAD=no
79	AC_DEFINE(HAVE_FUTEX,1,[Use futexes])
80else
81	PTHREAD=yes
82	AC_DEFINE(HAVE_PTHREAD,1,[Use pthread primitives])
83fi
84
85PTHREAD_LIBS=
86if test "x$PTHREAD" = "xyes"; then
87	AC_CHECK_LIB(pthread,pthread_create,[PTHREAD_LIBS=-lpthread],[PTHREAD_LIBS=])
88fi
89
90AC_SUBST([PTHREAD_LIBS])
91
92AM_CONDITIONAL([FUTEX], [test x"$FUTEX" = xyes])
93AM_CONDITIONAL([PTHREAD], [test x"$PTHREAD" = xyes])
94
95PKG_CHECK_MODULES(XPROTO, xproto)
96
97AC_SUBST([XPROTO_CFLAGS])
98
99CFLAGS="$CFLAGS $XPROTO_CFLAGS"
100
101AC_CHECK_FUNCS(memfd_create mkostemp)
102
103AC_CHECK_DECLS([__NR_memfd_create], [], [], [[#include <asm/unistd.h>]])
104
105AC_CHECK_HEADERS([sys/memfd.h], [AC_DEFINE([HAVE_MEMFD_H], 1, [Has sys/memfd.h header])])
106
107AC_ARG_ENABLE(visibility,     AS_HELP_STRING([--enable-visibility], [Enable symbol visibility (default: auto)]),
108				[SYMBOL_VISIBILITY=$enableval],
109				[SYMBOL_VISIBILITY=auto])
110
111dnl ==================================================================
112dnl symbol visibility
113symbol_visibility=
114have_visibility=disabled
115if test x$SYMBOL_VISIBILITY != xno; then
116    AC_MSG_CHECKING(for symbol visibility support)
117    if test x$GCC = xyes; then
118	VISIBILITY_CFLAGS="-fvisibility=hidden"
119    else
120	if test x$SUNCC = xyes; then
121	    VISIBILITY_CFLAGS="-xldscope=hidden"
122	else
123	    have_visibility=no
124	fi
125    fi
126    if test x$have_visibility != xno; then
127	AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
128           [[#include <X11/Xfuncproto.h>
129	     extern _X_HIDDEN int hidden_int;
130	     extern _X_EXPORT int public_int;
131	     extern _X_HIDDEN int hidden_int_func(void);
132	     extern _X_EXPORT int public_int_func(void);]],
133            [[]])],
134           [have_visibility=yes],
135           [have_visibility=no])
136    fi
137    AC_MSG_RESULT([$have_visibility])
138    if test x$have_visibility != xno; then
139	symbol_visibility=$VISIBILITY_CFLAGS
140	CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
141    fi
142fi
143
144AC_ARG_WITH(shared-memory-dir, AS_HELP_STRING([--with-shared-memory-dir=PATH], [Path to directory in a world-writable temporary directory for anonymous shared memory (default: auto)]),
145[],
146[with_shared_memory_dir=yes])
147
148shmdirs="/run/shm /dev/shm /var/tmp /tmp"
149
150case x"$with_shared_memory_dir" in
151xyes)
152	for dir in $shmdirs; do
153		case x"$with_shared_memory_dir" in
154		xyes)
155			echo Checking temp dir "$dir"
156			if test -d "$dir"; then
157				with_shared_memory_dir="$dir"
158			fi
159			;;
160		esac
161	done
162	;;
163x/*)
164	;;
165xno)
166	;;
167*)
168	AC_MSG_ERROR([Invalid directory specified for --with-shared-memory-dir: $with_shared_memory_dir])
169	;;
170esac
171
172case x"$with_shared_memory_dir" in
173xyes)
174	AC_MSG_ERROR([No directory found for shared memory temp files.])
175	;;
176xno)
177	;;
178*)
179	AC_DEFINE_UNQUOTED(SHMDIR, ["$with_shared_memory_dir"], [Directory for shared memory temp files])
180	;;
181esac
182
183AC_CONFIG_FILES([Makefile
184                 src/Makefile
185		 test/Makefile
186                 xshmfence.pc])
187AC_OUTPUT
188