1# Process this file with autoreconf to produce a configure script.
2#   Copyright (C) 2011-2013 Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18AC_PREREQ(2.59)
19AC_INIT([GNU TM Runtime Library], 1.0,,[libitm])
20AC_CONFIG_HEADER(config.h)
21
22# -------
23# Options
24# -------
25
26AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
27LIBITM_ENABLE(version-specific-runtime-libs, no, ,
28   [Specify that runtime libraries should be installed in a compiler-specific directory],
29   permit yes|no)
30AC_MSG_RESULT($enable_version_specific_runtime_libs)
31
32# We would like our source tree to be readonly. However when releases or
33# pre-releases are generated, the flex/bison generated files as well as the
34# various formats of manuals need to be included along with the rest of the
35# sources.  Therefore we have --enable-generated-files-in-srcdir to do
36# just that.
37AC_MSG_CHECKING([for --enable-generated-files-in-srcdir])
38LIBITM_ENABLE(generated-files-in-srcdir, no, ,
39   [put copies of generated files in source dir intended for creating source
40    tarballs for users without texinfo bison or flex.],
41   permit yes|no)
42AC_MSG_RESULT($enable_generated_files_in_srcdir)
43AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
44
45
46# -------
47# -------
48
49# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
50#
51# You will slowly go insane if you do not grok the following fact:  when
52# building this library, the top-level /target/ becomes the library's /host/.
53#
54# configure then causes --target to default to --host, exactly like any
55# other package using autoconf.  Therefore, 'target' and 'host' will
56# always be the same.  This makes sense both for native and cross compilers
57# just think about it for a little while.  :-)
58#
59# Also, if this library is being configured as part of a cross compiler, the
60# top-level configure script will pass the "real" host as $with_cross_host.
61#
62# Do not delete or change the following two lines.  For why, see
63# http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
64AC_CANONICAL_SYSTEM
65target_alias=${target_alias-$host_alias}
66
67# Sets up automake.  Must come after AC_CANONICAL_SYSTEM.  Each of the
68# following is magically included in AUTOMAKE_OPTIONS in each Makefile.am.
69#  1.9.0:  minimum required version
70#  no-define:  PACKAGE and VERSION will not be #define'd in config.h (a bunch
71#              of other PACKAGE_* variables will, however, and there's nothing
72#              we can do about that; they come from AC_INIT).
73#  no-dist:  we don't want 'dist' and related rules.
74#  foreign:  we don't follow the normal rules for GNU packages (no COPYING
75#            file in the top srcdir, etc, etc), so stop complaining.
76#  -Wall:  turns on all automake warnings...
77#  -Wno-portability:  ...except this one, since GNU make is required.
78#  -Wno-override: ... and this one, since we do want this in testsuite.
79AM_INIT_AUTOMAKE([1.9.0 foreign no-dist -Wall -Wno-portability -Wno-override])
80AM_ENABLE_MULTILIB(, ..)
81
82# Calculate toolexeclibdir
83# Also toolexecdir, though it's only used in toolexeclibdir
84case ${enable_version_specific_runtime_libs} in
85  yes)
86    # Need the gcc compiler version to know where to install libraries
87    # and header files if --enable-version-specific-runtime-libs option
88    # is selected.
89    toolexecdir='$(libdir)/gcc/$(target_alias)'
90    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
91    ;;
92  no)
93    if test -n "$with_cross_host" &&
94       test x"$with_cross_host" != x"no"; then
95      # Install a library built with a cross compiler in tooldir, not libdir.
96      toolexecdir='$(exec_prefix)/$(target_alias)'
97      toolexeclibdir='$(toolexecdir)/lib'
98    else
99      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
100      toolexeclibdir='$(libdir)'
101    fi
102    multi_os_directory=`$CC -print-multi-os-directory`
103    case $multi_os_directory in
104      .) ;; # Avoid trailing /.
105      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
106    esac
107    ;;
108esac
109AC_SUBST(toolexecdir)
110AC_SUBST(toolexeclibdir)
111
112# Check the compiler.
113# The same as in boehm-gc and libstdc++. Have to borrow it from there.
114# We must force CC to /not/ be precious variables; otherwise
115# the wrong, non-multilib-adjusted value will be used in multilibs.
116# As a side effect, we have to subst CFLAGS ourselves.
117
118m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
119m4_define([_AC_ARG_VAR_PRECIOUS],[])
120AC_PROG_CC
121AC_PROG_CXX
122AM_PROG_AS
123m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
124
125AC_SUBST(CFLAGS)
126
127# In order to override CFLAGS_FOR_TARGET, all of our special flags go
128# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
129# in both places for now and restore CFLAGS at the end of config.
130save_CFLAGS="$CFLAGS"
131
132# Find other programs we need.
133AC_CHECK_TOOL(AR, ar)
134AC_CHECK_TOOL(NM, nm)
135AC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
136AC_PATH_PROG(PERL, perl, perl-not-found-in-path-error)
137AC_PROG_MAKE_SET
138AC_PROG_INSTALL
139
140# See if makeinfo has been installed and is modern enough
141# that we can use it.
142ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
143                   [GNU texinfo.* \([0-9][0-9.]*\)],
144                   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
145AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
146
147
148# Configure libtool
149AM_PROG_LIBTOOL
150AC_SUBST(enable_shared)
151AC_SUBST(enable_static)
152
153AM_MAINTAINER_MODE
154
155# For libtool versioning info, format is CURRENT:REVISION:AGE
156libtool_VERSION=1:0:0
157AC_SUBST(libtool_VERSION)
158
159# Check header files.
160AC_STDC_HEADERS
161AC_HEADER_TIME
162ACX_HEADER_STRING
163AC_CHECK_HEADERS(unistd.h semaphore.h sys/time.h malloc.h)
164
165GCC_HEADER_STDINT(gstdint.h)
166
167GCC_AC_FUNC_MMAP_BLACKLIST
168
169AC_C_BIGENDIAN
170# I don't like the default behaviour of WORDS_BIGENDIAN undefined for LE.
171AH_BOTTOM(
172[#ifndef WORDS_BIGENDIAN
173#define WORDS_BIGENDIAN 0
174#endif])
175
176# Check to see if -pthread or -lpthread is needed.  Prefer the former.
177# In case the pthread.h system header is not found, this test will fail.
178XPCFLAGS=""
179CFLAGS="$CFLAGS -pthread"
180AC_LINK_IFELSE(
181 [AC_LANG_PROGRAM(
182  [#include <pthread.h>
183   void *g(void *d) { return NULL; }],
184  [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
185 [XPCFLAGS=" -Wc,-pthread"],
186 [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
187  AC_LINK_IFELSE(
188   [AC_LANG_PROGRAM(
189    [#include <pthread.h>
190     void *g(void *d) { return NULL; }],
191    [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
192   [],
193   [AC_MSG_ERROR([Pthreads are required to build libitm])])])
194
195# Check for functions needed.
196AC_CHECK_FUNCS(strtoull memalign posix_memalign)
197
198# Check for broken semaphore implementation on darwin.
199# sem_init returns: sem_init error: Function not implemented.
200case "$host" in
201  *-darwin*)
202    AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
203	Define if the POSIX Semaphores do not work on your system.)
204    ;;
205esac
206
207GCC_LINUX_FUTEX(:)
208
209# See if we support thread-local storage.
210GCC_CHECK_TLS
211
212# See what sort of export controls are available.
213LIBITM_CHECK_ATTRIBUTE_VISIBILITY
214LIBITM_CHECK_ATTRIBUTE_DLLEXPORT
215LIBITM_CHECK_ATTRIBUTE_ALIAS
216
217# Check linker hardware capability support.
218LIBITM_CHECK_LINKER_HWCAP
219# If defaulting to -mavx, don't clear hwcaps.
220AC_CHECK_DECL([__AVX__], [HWCAP_LDFLAGS=''])
221
222LIBITM_ENABLE_SYMVERS
223if test $enable_symvers = gnu; then
224  AC_DEFINE(LIBITM_GNU_SYMBOL_VERSIONING, 1,
225	    [Define to 1 if GNU symbol versioning is used for libitm.])
226fi
227
228# See if we can emit unwind info in the sjlj stub.
229GCC_AS_CFI_PSEUDO_OP
230
231# Determine the proper ABI type for size_t.
232LIBITM_CHECK_SIZE_T_MANGLING
233
234# Get target configury.
235. ${srcdir}/configure.tgt
236if test -n "$UNSUPPORTED"; then
237  AC_MSG_ERROR([Configuration ${target} is unsupported.])
238fi
239
240CFLAGS="$save_CFLAGS $XCFLAGS"
241
242# Check for __sync_val_compare_and_swap, but only after the target has
243# had a chance to set XCFLAGS.
244LIBITM_CHECK_SYNC_BUILTINS
245LIBITM_CHECK_64BIT_SYNC_BUILTINS
246LIBITM_CHECK_AS_AVX
247LIBITM_CHECK_AS_RTM
248
249GCC_CHECK_ELF_STYLE_WEAKREF
250
251# Cleanup and exit.
252CFLAGS="$save_CFLAGS"
253AC_CACHE_SAVE
254
255# Add -Wall -Werror if we are using GCC.
256if test "x$GCC" = "xyes"; then
257  XCFLAGS="$XCFLAGS -Wall -Werror"
258fi
259
260XCFLAGS="$XCFLAGS $XPCFLAGS"
261
262AC_SUBST(config_path)
263AC_SUBST(XCFLAGS)
264AC_SUBST(XLDFLAGS)
265
266if test ${multilib} = yes; then
267  multilib_arg="--enable-multilib"
268else
269  multilib_arg=
270fi
271
272# Set up the set of libraries that we need to link against for libitm.
273# Note that the GTM_SELF_SPECS in gcc.c will force -pthread for -fgnu-tm,
274# which will force linkage against -lpthread (or equivalent for the system).
275# That's not 100% ideal, but about the best we can do easily.
276if test $enable_shared = yes; then
277  link_itm="-litm %{static: $LIBS}"
278else
279  link_itm="-litm $LIBS"
280fi
281AC_SUBST(link_itm)
282
283AM_CONDITIONAL([ARCH_ARM], [test "$ARCH" = arm])
284AM_CONDITIONAL([ARCH_X86], [test "$ARCH" = x86])
285AM_CONDITIONAL([ARCH_X86_AVX], [test "$libitm_cv_as_avx" = yes])
286AM_CONDITIONAL([ARCH_FUTEX], [test $enable_linux_futex = yes])
287
288AC_CONFIG_FILES(Makefile testsuite/Makefile libitm.spec)
289AC_OUTPUT
290