Move libraries version info to the beginning of Makefile.am
[platform/upstream/libatomic_ops.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 AC_INIT([libatomic_ops],[7.4.4],bdwgc@lists.opendylan.org)
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 dist-bzip2 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   case "$host" in
27     *-*-cygwin* | *-*-mingw*)
28       # Cygwin and Mingw[-w32/64] do not need -fPIC.
29       AC_MSG_RESULT("<none>")
30       ;;
31     *)
32       AC_MSG_RESULT(-fPIC)
33       PICFLAG=-fPIC
34       AC_MSG_CHECKING(whether gcc -fPIC causes __PIC__ definition)
35       # Workaround: at least GCC 3.4.6 (Solaris) does not define this macro.
36       old_CFLAGS="$CFLAGS"
37       CFLAGS="$PICFLAG $CFLAGS"
38       AC_TRY_COMPILE([],[
39  #ifndef __PIC__
40  # error
41  #endif
42       ], [ac_cv_pic_macro=yes], [ac_cv_pic_macro=no])
43       CFLAGS="$old_CFLAGS"
44       AC_MSG_RESULT($ac_cv_pic_macro)
45       AS_IF([test "$ac_cv_pic_macro" = yes], [],
46             [PICFLAG="-D__PIC__=1 $PICFLAG"])
47       ;;
48   esac
49
50   # Output all warnings.
51   AC_MSG_CHECKING(for gcc -Wextra)
52   old_CFLAGS="$CFLAGS"
53   CFLAGS="-Wextra $CFLAGS"
54   AC_TRY_COMPILE([],[], [ac_cv_cc_wextra=yes], [ac_cv_cc_wextra=no])
55   CFLAGS="$old_CFLAGS"
56   AC_MSG_RESULT($ac_cv_cc_wextra)
57   AS_IF([test "$ac_cv_cc_wextra" = yes], [WEXTRA="-Wextra"], [WEXTRA="-W"])
58   CFLAGS="-Wall $WEXTRA $CFLAGS"
59 else
60   case "$host" in
61     *-*-hpux*)
62       AC_MSG_RESULT("+Z")
63       PICFLAG="+Z"
64       CFLAGS="+O2 -mt $CFLAGS"
65       ;;
66     *-*-solaris*)
67       AC_MSG_RESULT(-Kpic)
68       PICFLAG=-Kpic
69       CFLAGS="-O $CFLAGS"
70       need_asm=true
71       ;;
72     *-*-linux*)
73       AC_MSG_RESULT(-fPIC)
74       PICFLAG=-fPIC
75       # Any Linux compiler had better be gcc compatible.
76       ;;
77     *)
78       AC_MSG_RESULT("<none>")
79       ;;
80   esac
81 fi
82
83 AC_ARG_ENABLE(assertions,
84         [AC_HELP_STRING([--enable-assertions], [Assertion checking])])
85 if test "$enable_assertions" != yes; then
86   AC_DEFINE([NDEBUG], 1, [Define to disable assertion checking.])
87 fi
88
89 AC_ARG_ENABLE(gcov, AC_HELP_STRING([--enable-gcov],
90                                    [Turn on code coverage analysis]))
91 if test "$enable_gcov" = "yes"; then
92   CFLAGS="$CFLAGS --coverage"
93   # Turn off code optimization to get accurate line numbers.
94   CFLAGS=`echo "$CFLAGS" | sed -e 's/-O\(1\|2\|3\|4\|s\|fast\)\?//g'`
95 fi
96
97 AC_SUBST(PICFLAG)
98 AC_SUBST(DEFS)
99
100 # Extra user-defined C flags.
101 AC_SUBST([CFLAGS_EXTRA])
102
103 AH_TEMPLATE([_PTHREADS], [Indicates the use of pthreads (NetBSD).])
104
105 AH_TEMPLATE([AO_USE_NANOSLEEP],
106         [Use nanosleep() instead of select() (only if atomic operations \
107          are emulated)])
108 AH_TEMPLATE([AO_USE_NO_SIGNALS],
109         [Do not block signals in compare_and_swap (only if atomic operations \
110          are emulated)])
111 AH_TEMPLATE([AO_USE_WIN32_PTHREADS],
112         [Use Win32 Sleep() instead of select() (only if atomic operations \
113          are emulated)])
114 AH_TEMPLATE([AO_TRACE_MALLOC], [Trace AO_malloc/free calls (for debug only)])
115
116 # These macros are tested in public headers
117 AH_TEMPLATE([AO_GENERALIZE_ASM_BOOL_CAS],
118         [Force compare_and_swap definition via fetch_compare_and_swap])
119 AH_TEMPLATE([AO_PREFER_GENERALIZED],
120         [Prefer generalized definitions to direct assembly-based ones])
121 AH_TEMPLATE([AO_USE_PTHREAD_DEFS],
122         [Emulate atomic operations via slow and async-signal-unsafe \
123          pthread locking])
124 AH_TEMPLATE([AO_ASM_X64_AVAILABLE],
125         [Inline assembly available (only VC/x86_64)])
126 AH_TEMPLATE([AO_ASSUME_VISTA],
127         [Assume Windows Server 2003, Vista or later target (only VC/x86)])
128 AH_TEMPLATE([AO_ASSUME_WINDOWS98],
129         [Assume hardware compare-and-swap functionality available \
130          on target (only VC/x86)])
131 AH_TEMPLATE([AO_CMPXCHG16B_AVAILABLE],
132         [Assume target is not old AMD Opteron chip (only x86_64)])
133 AH_TEMPLATE([AO_FORCE_USE_SWP],
134         [Force test_and_set to use SWP instruction instead of LDREX/STREX \
135          (only arm v6+)])
136 AH_TEMPLATE([AO_NO_SPARC_V9], [Assume target is not sparc v9+ (only sparc)])
137 AH_TEMPLATE([AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE],
138         [Assume ancient MS VS Win32 headers (only VC/arm v6+, VC/x86)])
139 AH_TEMPLATE([AO_UNIPROCESSOR], [Assume single-core target (only arm v6+)])
140 AH_TEMPLATE([AO_USE_INTERLOCKED_INTRINSICS],
141         [Assume Win32 _Interlocked primitives available as intrinsics \
142          (only VC/arm)])
143 AH_TEMPLATE([AO_USE_PENTIUM4_INSTRS],
144         [Use Pentium 4 'mfence' instruction (only x86)])
145 AH_TEMPLATE([AO_USE_SYNC_CAS_BUILTIN],
146         [Prefer GCC built-in CAS intrinsics in favor of inline assembly \
147          (only gcc/x86, gcc/x86_64)])
148 AH_TEMPLATE([AO_WEAK_DOUBLE_CAS_EMULATION],
149         [Emulate double-width CAS via pthread locking in case of no hardware \
150          support (only gcc/x86_64, the emulation is unsafe)])
151
152 AC_DEFINE(_REENTRANT, 1, [Required define if using POSIX threads.])
153
154 # Libraries needed to support threads (if any).
155 have_pthreads=false
156 AC_CHECK_LIB(pthread, pthread_self, have_pthreads=true)
157 if test x$have_pthreads = xtrue; then
158   THREADDLLIBS=-lpthread
159   case "$host" in
160     *-*-netbsd*)
161       # Indicates the use of pthreads.
162       AC_DEFINE(_PTHREADS)
163       ;;
164     *-*-openbsd* | *-*-kfreebsd*-gnu | *-*-dgux*)
165       THREADDLLIBS=-pthread
166       ;;
167     *-*-cygwin* | *-*-darwin*)
168       # Cygwin does not have a real libpthread, so Libtool cannot link
169       # against it.
170       THREADDLLIBS=
171       ;;
172     *-*-mingw*)
173       # Use Win32 threads for tests anyway.
174       THREADDLLIBS=
175       # Skip test_atomic_pthreads.
176       have_pthreads=false
177       ;;
178   esac
179 else
180   AC_DEFINE([AO_NO_PTHREADS], 1, [No pthreads library available])
181   # Assume VxWorks or Win32.
182   THREADDLLIBS=
183 fi
184 AC_SUBST(THREADDLLIBS)
185
186 AM_CONDITIONAL(HAVE_PTHREAD_H, test x$have_pthreads = xtrue)
187 AM_CONDITIONAL(NEED_ASM, test x$need_asm = xtrue)
188
189 AC_CONFIG_FILES([
190         Makefile
191         doc/Makefile
192         src/Makefile
193         tests/Makefile
194         pkgconfig/atomic_ops.pc
195         pkgconfig/atomic_ops-uninstalled.pc ])
196
197 AC_CONFIG_COMMANDS([default],[[]],[[
198 PICFLAG="${PICFLAG}"
199 CC="${CC}"
200 DEFS="${DEFS}"
201 ]])
202 AC_OUTPUT