Bump libatomic_ops version to 7.6.4
[platform/upstream/libatomic_ops.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 AC_INIT([libatomic_ops],[7.6.4],https://github.com/ivmai/libatomic_ops/issues)
3
4 AC_PREREQ(2.61)
5 AC_CANONICAL_TARGET([])
6 AC_CONFIG_SRCDIR(src/atomic_ops.c)
7 AC_CONFIG_MACRO_DIR([m4])
8 AM_INIT_AUTOMAKE([foreign nostdinc])
9 AM_MAINTAINER_MODE
10
11 AC_CONFIG_HEADERS([src/config.h])
12
13 # Checks for programs.
14 AM_PROG_CC_C_O
15 AM_PROG_AS
16 LT_INIT([disable-shared])
17
18 # Checks for functions.
19 AC_FUNC_MMAP
20
21 # Determine PIC flag.
22 need_asm=false
23 PICFLAG=
24 AC_MSG_CHECKING(for PIC compiler flag)
25 if test "$GCC" = yes; then
26   old_CC="$CC"
27   if test -n "$CROSS_CC"; then
28     CC="$CROSS_CC"
29   fi
30
31   case "$host" in
32     *-*-cygwin* | *-*-mingw*)
33       # Cygwin and Mingw[-w32/64] do not need -fPIC.
34       AC_MSG_RESULT([not needed])
35       ;;
36     *)
37       AC_MSG_RESULT(-fPIC)
38       PICFLAG=-fPIC
39       AC_MSG_CHECKING(whether -fPIC compiler option causes __PIC__ definition)
40       # Workaround: at least GCC 3.4.6 (Solaris) does not define this macro.
41       old_CFLAGS="$CFLAGS"
42       CFLAGS="$PICFLAG $CFLAGS"
43       AC_TRY_COMPILE([],[
44  #ifndef __PIC__
45  # error
46  #endif
47       ], [ac_cv_pic_macro=yes], [ac_cv_pic_macro=no])
48       CFLAGS="$old_CFLAGS"
49       AC_MSG_RESULT($ac_cv_pic_macro)
50       AS_IF([test "$ac_cv_pic_macro" = yes], [],
51             [PICFLAG="-D__PIC__=1 $PICFLAG"])
52       ;;
53   esac
54
55   # Output all warnings.
56   AC_MSG_CHECKING([whether compiler supports -Wextra])
57   old_CFLAGS="$CFLAGS"
58   CFLAGS="-Wextra $CFLAGS"
59   AC_TRY_COMPILE([],[], [ac_cv_cc_wextra=yes], [ac_cv_cc_wextra=no])
60   CFLAGS="$old_CFLAGS"
61   AC_MSG_RESULT($ac_cv_cc_wextra)
62   AS_IF([test "$ac_cv_cc_wextra" = yes], [WEXTRA="-Wextra"], [WEXTRA="-W"])
63   AC_MSG_CHECKING([whether compiler supports -Wpedantic])
64   CFLAGS="-Wpedantic -Wno-long-long $CFLAGS"
65   AC_TRY_COMPILE([],[
66 extern int quiet;
67   ], [ac_cv_cc_pedantic=yes], [ac_cv_cc_pedantic=no])
68   CFLAGS="$old_CFLAGS"
69   AC_MSG_RESULT($ac_cv_cc_pedantic)
70   WPEDANTIC=
71   AS_IF([test "$ac_cv_cc_pedantic" = yes],
72         [WPEDANTIC="-Wpedantic -Wno-long-long"])
73   CFLAGS="-Wall $WEXTRA $WPEDANTIC $CFLAGS"
74
75   AC_ARG_ENABLE(werror, [AC_HELP_STRING([--enable-werror],
76                             [Pass -Werror to the C compiler])])
77   if test "$enable_werror" = yes; then
78     CFLAGS="-Werror $CFLAGS"
79   fi
80
81   CC="$old_CC"
82 else
83   case "$host" in
84     *-*-hpux*)
85       AC_MSG_RESULT([+Z])
86       PICFLAG="+Z"
87       CFLAGS="+O2 -mt $CFLAGS"
88       ;;
89     *-*-solaris*)
90       AC_MSG_RESULT(-Kpic)
91       PICFLAG=-Kpic
92       CFLAGS="-O $CFLAGS"
93       need_asm=true
94       ;;
95     *-*-linux*)
96       AC_MSG_RESULT(-fPIC)
97       PICFLAG=-fPIC
98       # Any Linux compiler had better be gcc compatible.
99       ;;
100     *)
101       AC_MSG_RESULT([none])
102       ;;
103   esac
104 fi
105
106 AC_ARG_ENABLE(assertions,
107         [AC_HELP_STRING([--enable-assertions], [Assertion checking])])
108 if test "$enable_assertions" != yes; then
109   AC_DEFINE([NDEBUG], 1, [Define to disable assertion checking.])
110 fi
111
112 AC_ARG_ENABLE(atomic-intrinsics,
113         [AC_HELP_STRING([--disable-atomic-intrinsics],
114                         [Do not use C11 atomic intrinsics])])
115 if test "$enable_atomic_intrinsics" = no; then
116   AC_DEFINE([AO_DISABLE_GCC_ATOMICS], 1,
117             [Define to avoid C11 atomic intrinsics even if available.])
118 fi
119
120 AC_ARG_ENABLE(gcov, AC_HELP_STRING([--enable-gcov],
121                                    [Turn on code coverage analysis]))
122 if test "$enable_gcov" = "yes"; then
123   CFLAGS="$CFLAGS --coverage"
124   # Turn off code optimization to get accurate line numbers.
125   CFLAGS=`echo "$CFLAGS" | sed -e 's/-O\(1\|2\|3\|4\|s\|fast\)\?//g'`
126 fi
127
128 AC_ARG_ENABLE(docs,
129         [AC_HELP_STRING([--disable-docs],
130                         [Do not build and install documentation])])
131 AM_CONDITIONAL(ENABLE_DOCS, test x$enable_docs != xno)
132
133 AC_SUBST(PICFLAG)
134 AC_SUBST(DEFS)
135
136 # Extra user-defined C flags.
137 AC_SUBST([CFLAGS_EXTRA])
138
139 AH_TEMPLATE([_PTHREADS], [Indicates the use of pthreads (NetBSD).])
140
141 AH_TEMPLATE([AO_USE_NANOSLEEP],
142         [Use nanosleep() instead of select() (only if atomic operations \
143          are emulated)])
144 AH_TEMPLATE([AO_USE_NO_SIGNALS],
145         [Do not block signals in compare_and_swap (only if atomic operations \
146          are emulated)])
147 AH_TEMPLATE([AO_USE_WIN32_PTHREADS],
148         [Use Win32 Sleep() instead of select() (only if atomic operations \
149          are emulated)])
150 AH_TEMPLATE([AO_TRACE_MALLOC], [Trace AO_malloc/free calls (for debug only)])
151
152 # These macros are tested in public headers
153 AH_TEMPLATE([AO_GENERALIZE_ASM_BOOL_CAS],
154         [Force compare_and_swap definition via fetch_compare_and_swap])
155 AH_TEMPLATE([AO_PREFER_GENERALIZED],
156         [Prefer generalized definitions to direct assembly-based ones])
157 AH_TEMPLATE([AO_USE_PTHREAD_DEFS],
158         [Emulate atomic operations via slow and async-signal-unsafe \
159          pthread locking])
160 AH_TEMPLATE([AO_ASM_X64_AVAILABLE],
161         [Inline assembly available (only VC/x86_64)])
162 AH_TEMPLATE([AO_ASSUME_VISTA],
163         [Assume Windows Server 2003, Vista or later target (only VC/x86)])
164 AH_TEMPLATE([AO_CMPXCHG16B_AVAILABLE],
165         [Assume target is not old AMD Opteron chip (only x86_64)])
166 AH_TEMPLATE([AO_FORCE_USE_SWP],
167         [Force test_and_set to use SWP instruction instead of LDREX/STREX \
168          (only arm v6+)])
169 AH_TEMPLATE([AO_NO_SPARC_V9], [Assume target is not sparc v9+ (only sparc)])
170 AH_TEMPLATE([AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE],
171         [Assume ancient MS VS Win32 headers (only VC/arm v6+, VC/x86)])
172 AH_TEMPLATE([AO_UNIPROCESSOR], [Assume single-core target (only arm v6+)])
173 AH_TEMPLATE([AO_USE_INTERLOCKED_INTRINSICS],
174         [Assume Win32 _Interlocked primitives available as intrinsics \
175          (only VC/arm)])
176 AH_TEMPLATE([AO_USE_PENTIUM4_INSTRS],
177         [Use Pentium 4 'mfence' instruction (only x86)])
178 AH_TEMPLATE([AO_USE_SYNC_CAS_BUILTIN],
179         [Prefer GCC built-in CAS intrinsics in favor of inline assembly \
180          (only gcc/x86, gcc/x86_64)])
181 AH_TEMPLATE([AO_WEAK_DOUBLE_CAS_EMULATION],
182         [Emulate double-width CAS via pthread locking in case of no hardware \
183          support (only gcc/x86_64, the emulation is unsafe)])
184 AH_TEMPLATE([AO_PREFER_BUILTIN_ATOMICS],
185         [Prefer C11 atomic intrinsics over assembly-based implementation \
186         even in case of inefficient implementation (do not use assembly for \
187         any atomic_ops primitive if C11/GCC atomic intrinsics available)])
188
189 AC_DEFINE(_REENTRANT, 1, [Required define if using POSIX threads.])
190
191 # Libraries needed to support threads (if any).
192 have_pthreads=false
193 AC_CHECK_LIB(pthread, pthread_self, have_pthreads=true)
194 if test x$have_pthreads = xtrue; then
195   THREADDLLIBS=-lpthread
196   case "$host" in
197     *-*-netbsd*)
198       # Indicates the use of pthreads.
199       AC_DEFINE(_PTHREADS)
200       ;;
201     *-*-openbsd* | *-*-kfreebsd*-gnu | *-*-dgux*)
202       THREADDLLIBS=-pthread
203       ;;
204     *-*-cygwin* | *-*-darwin*)
205       # Cygwin does not have a real libpthread, so Libtool cannot link
206       # against it.
207       THREADDLLIBS=
208       ;;
209     *-*-mingw*)
210       # Use Win32 threads for tests anyway.
211       THREADDLLIBS=
212       # Skip test_atomic_pthreads.
213       have_pthreads=false
214       ;;
215   esac
216 else
217   AC_DEFINE([AO_NO_PTHREADS], 1, [No pthreads library available])
218   # Assume VxWorks or Win32.
219   THREADDLLIBS=
220 fi
221 AC_SUBST(THREADDLLIBS)
222
223 AM_CONDITIONAL(HAVE_PTHREAD_H, test x$have_pthreads = xtrue)
224 AM_CONDITIONAL(NEED_ASM, test x$need_asm = xtrue)
225
226 AC_CONFIG_FILES([
227         Makefile
228         doc/Makefile
229         src/Makefile
230         tests/Makefile
231         pkgconfig/atomic_ops.pc
232         pkgconfig/atomic_ops-uninstalled.pc ])
233
234 AC_CONFIG_COMMANDS([default],[[]],[[
235 PICFLAG="${PICFLAG}"
236 CC="${CC}"
237 DEFS="${DEFS}"
238 ]])
239 AC_OUTPUT