1# Process this file with autoreconf to produce a configure script.
2#  Copyright (C) 2012-2018 Free Software Foundation, Inc.
3#
4#  This file is part of the GNU Atomic Library (libatomic).
5#
6#  Libatomic is free software; you can redistribute it and/or modify it
7#  under the terms of the GNU General Public License as published by
8#  the Free Software Foundation; either version 3 of the License, or
9#  (at your option) any later version.
10#
11#  Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
12#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14#  more details.
15#
16#  Under Section 7 of GPL version 3, you are granted additional
17#  permissions described in the GCC Runtime Library Exception, version
18#  3.1, as published by the Free Software Foundation.
19#
20#  You should have received a copy of the GNU General Public License and
21#  a copy of the GCC Runtime Library Exception along with this program;
22#  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23#  <http://www.gnu.org/licenses/>.
24
25AC_PREREQ(2.59)
26AC_INIT([GNU Atomic Library], 1.0,,[libatomic])
27AC_CONFIG_HEADER(auto-config.h)
28
29# -------
30# Options
31# -------
32
33AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
34LIBAT_ENABLE(version-specific-runtime-libs, no, ,
35   [Specify that runtime libraries should be installed in a compiler-specific directory],
36   permit yes|no)
37AC_MSG_RESULT($enable_version_specific_runtime_libs)
38
39# We would like our source tree to be readonly. However when releases or
40# pre-releases are generated, the flex/bison generated files as well as the
41# various formats of manuals need to be included along with the rest of the
42# sources.  Therefore we have --enable-generated-files-in-srcdir to do
43# just that.
44AC_MSG_CHECKING([for --enable-generated-files-in-srcdir])
45LIBAT_ENABLE(generated-files-in-srcdir, no, ,
46   [put copies of generated files in source dir intended for creating source
47    tarballs for users without texinfo bison or flex.],
48   permit yes|no)
49AC_MSG_RESULT($enable_generated_files_in_srcdir)
50AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
51
52
53# -------
54
55# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
56#
57# You will slowly go insane if you do not grok the following fact:  when
58# building this library, the top-level /target/ becomes the library's /host/.
59#
60# configure then causes --target to default to --host, exactly like any
61# other package using autoconf.  Therefore, 'target' and 'host' will
62# always be the same.  This makes sense both for native and cross compilers
63# just think about it for a little while.  :-)
64#
65# Also, if this library is being configured as part of a cross compiler, the
66# top-level configure script will pass the "real" host as $with_cross_host.
67#
68# Do not delete or change the following two lines.  For why, see
69# http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
70AC_CANONICAL_SYSTEM
71target_alias=${target_alias-$host_alias}
72
73# Sets up automake.  Must come after AC_CANONICAL_SYSTEM.  Each of the
74# following is magically included in AUTOMAKE_OPTIONS in each Makefile.am.
75#  1.9.0:  minimum required version
76#  no-define:  PACKAGE and VERSION will not be #define'd in config.h (a bunch
77#              of other PACKAGE_* variables will, however, and there's nothing
78#              we can do about that; they come from AC_INIT).
79#  no-dist:  we don't want 'dist' and related rules.
80#  foreign:  we don't follow the normal rules for GNU packages (no COPYING
81#            file in the top srcdir, etc, etc), so stop complaining.
82#  -Wall:  turns on all automake warnings...
83#  -Wno-portability:  ...except this one, since GNU make is required.
84#  -Wno-override: ... and this one, since we do want this in testsuite.
85AM_INIT_AUTOMAKE([1.9.0 foreign no-dist -Wall -Wno-portability -Wno-override])
86AM_ENABLE_MULTILIB(, ..)
87
88# Calculate toolexeclibdir
89# Also toolexecdir, though it's only used in toolexeclibdir
90case ${enable_version_specific_runtime_libs} in
91  yes)
92    # Need the gcc compiler version to know where to install libraries
93    # and header files if --enable-version-specific-runtime-libs option
94    # is selected.
95    toolexecdir='$(libdir)/gcc/$(target_alias)'
96    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
97    ;;
98  no)
99    if test -n "$with_cross_host" &&
100       test x"$with_cross_host" != x"no"; then
101      # Install a library built with a cross compiler in tooldir, not libdir.
102      toolexecdir='$(exec_prefix)/$(target_alias)'
103      toolexeclibdir='$(toolexecdir)/lib'
104    else
105      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
106      toolexeclibdir='$(libdir)'
107    fi
108    multi_os_directory=`$CC -print-multi-os-directory`
109    case $multi_os_directory in
110      .) ;; # Avoid trailing /.
111      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
112    esac
113    ;;
114esac
115AC_SUBST(toolexecdir)
116AC_SUBST(toolexeclibdir)
117
118# Check the compiler.
119# The same as in boehm-gc and libstdc++. Have to borrow it from there.
120# We must force CC to /not/ be precious variables; otherwise
121# the wrong, non-multilib-adjusted value will be used in multilibs.
122# As a side effect, we have to subst CFLAGS ourselves.
123
124m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
125m4_define([_AC_ARG_VAR_PRECIOUS],[])
126AC_PROG_CC
127AM_PROG_AS
128m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
129
130AC_SUBST(CFLAGS)
131
132# In order to override CFLAGS_FOR_TARGET, all of our special flags go
133# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
134# in both places for now and restore CFLAGS at the end of config.
135save_CFLAGS="$CFLAGS"
136
137# Find other programs we need.
138AC_CHECK_TOOL(AR, ar)
139AC_CHECK_TOOL(NM, nm)
140AC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
141AC_PATH_PROG(PERL, perl, perl-not-found-in-path-error)
142AC_PROG_INSTALL
143
144# Configure libtool
145AM_PROG_LIBTOOL
146ACX_LT_HOST_FLAGS
147AC_SUBST(enable_shared)
148AC_SUBST(enable_static)
149AM_MAINTAINER_MODE
150
151# For libtool versioning info, format is CURRENT:REVISION:AGE
152libtool_VERSION=3:0:2
153AC_SUBST(libtool_VERSION)
154
155# Check for used threading-model
156AC_MSG_CHECKING([for thread model used by GCC])
157target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
158AC_MSG_RESULT([$target_thread_file])
159
160case "$target" in
161 *aarch64*)
162    ACX_PROG_CC_WARNING_OPTS([-march=armv8-a+lse],[enable_aarch64_lse])
163    ;;
164esac
165
166# Get target configury.
167. ${srcdir}/configure.tgt
168if test -n "$UNSUPPORTED"; then
169  AC_MSG_ERROR([Configuration ${target} is unsupported.])
170fi
171
172# Write out the ifunc resolver arg type.
173AC_DEFINE_UNQUOTED(IFUNC_RESOLVER_ARGS, $IFUNC_RESOLVER_ARGS,
174	[Define ifunc resolver function argument.])
175
176# Disable fallbacks to __sync routines from libgcc.  Otherwise we'll
177# make silly decisions about what the cpu can do.
178CFLAGS="$save_CFLAGS -fno-sync-libcalls $XCFLAGS"
179
180# Check header files.
181AC_STDC_HEADERS
182ACX_HEADER_STRING
183GCC_HEADER_STDINT(gstdint.h)
184AC_CHECK_HEADERS([fenv.h])
185
186# Check for common type sizes
187LIBAT_FORALL_MODES([LIBAT_HAVE_INT_MODE])
188
189# Check for compiler builtins of atomic operations.
190LIBAT_TEST_ATOMIC_INIT
191LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_LOADSTORE])
192LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_TAS])
193LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_EXCHANGE])
194LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_CAS])
195LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_FETCH_ADD])
196LIBAT_FORALL_MODES([LIBAT_HAVE_ATOMIC_FETCH_OP])
197
198AC_C_BIGENDIAN
199# I don't like the default behaviour of WORDS_BIGENDIAN undefined for LE.
200AH_BOTTOM(
201[#ifndef WORDS_BIGENDIAN
202#define WORDS_BIGENDIAN 0
203#endif])
204
205LIBAT_WORDSIZE
206
207# Check to see if -pthread or -lpthread is needed.  Prefer the former.
208# In case the pthread.h system header is not found, this test will fail.
209case " $config_path " in
210 *" posix "*)
211  XPCFLAGS=""
212  CFLAGS="$CFLAGS -pthread"
213  AC_LINK_IFELSE(
214    [AC_LANG_PROGRAM(
215     [#include <pthread.h>
216      void *g(void *d) { return NULL; }],
217     [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
218    [XPCFLAGS=" -pthread"],
219    [CFLAGS="$save_CFLAGS $XCFLAGS" LIBS="-lpthread $LIBS"
220     AC_LINK_IFELSE(
221      [AC_LANG_PROGRAM(
222       [#include <pthread.h>
223        void *g(void *d) { return NULL; }],
224       [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
225      [],
226      [AC_MSG_ERROR([Pthreads are required to build libatomic])])])
227  CFLAGS="$save_CFLAGS $XPCFLAGS"
228  ;;
229esac
230
231# See what sort of export controls are available.
232LIBAT_CHECK_ATTRIBUTE_VISIBILITY
233LIBAT_CHECK_ATTRIBUTE_DLLEXPORT
234LIBAT_CHECK_ATTRIBUTE_ALIAS
235if test x$try_ifunc = xyes; then
236  LIBAT_CHECK_IFUNC
237fi
238
239# Check linker support.
240LIBAT_ENABLE_SYMVERS
241
242# Cleanup and exit.
243CFLAGS="$save_CFLAGS"
244AC_CACHE_SAVE
245
246# Add -Wall -Werror if we are using GCC.
247if test "x$GCC" = "xyes"; then
248  XCFLAGS="$XCFLAGS -Wall -Werror"
249fi
250
251# Add CET specific flags if CET is enabled
252GCC_CET_FLAGS(CET_FLAGS)
253XCFLAGS="$XCFLAGS $CET_FLAGS"
254
255XCFLAGS="$XCFLAGS $XPCFLAGS"
256
257AC_SUBST(config_path)
258AC_SUBST(XCFLAGS)
259AC_SUBST(XLDFLAGS)
260AC_SUBST(LIBS)
261AC_SUBST(SIZES)
262
263AM_CONDITIONAL(HAVE_IFUNC, test x$libat_cv_have_ifunc = xyes)
264AM_CONDITIONAL(ARCH_AARCH64_LINUX,
265	       [expr "$config_path" : ".* linux/aarch64 .*" > /dev/null])
266AM_CONDITIONAL(ARCH_ARM_LINUX,
267	       [expr "$config_path" : ".* linux/arm .*" > /dev/null])
268AM_CONDITIONAL(ARCH_I386,
269	       [test "$ARCH" = x86 && test x$libat_cv_wordsize = x4])
270AM_CONDITIONAL(ARCH_X86_64,
271	       [test "$ARCH" = x86 && test x$libat_cv_wordsize = x8])
272
273# Determine what GCC version number to use in filesystem paths.
274GCC_BASE_VER
275
276if test ${multilib} = yes; then
277  multilib_arg="--enable-multilib"
278else
279  multilib_arg=
280fi
281
282AC_CONFIG_FILES(Makefile testsuite/Makefile)
283AC_OUTPUT
284