1169695Skan# Process this file with autoconf to produce a configure script, like so:
2169695Skan# aclocal -I ../config && autoconf && autoheader && automake
3169695Skan
4169695SkanAC_PREREQ(2.59)
5169695SkanAC_INIT([GNU OpenMP Runtime Library], 1.0,,[libgomp])
6169695SkanAC_CONFIG_HEADER(config.h)
7169695Skan
8169695Skan# -------
9169695Skan# Options
10169695Skan# -------
11169695Skan
12169695SkanAC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
13169695SkanLIBGOMP_ENABLE(version-specific-runtime-libs, no, ,
14169695Skan   [Specify that runtime libraries should be installed in a compiler-specific directory],
15169695Skan   permit yes|no)
16169695SkanAC_MSG_RESULT($enable_version_specific_runtime_libs)
17169695Skan
18169695SkanAC_MSG_CHECKING([for --enable-linux-futex])
19169695SkanLIBGOMP_ENABLE(linux-futex, default, ,
20169695Skan  [Use the Linux futex system call],
21169695Skan  permit yes|no|default)
22169695SkanAC_MSG_RESULT($enable_linux_futex)
23169695Skan
24169695Skan# We would like our source tree to be readonly. However when releases or
25169695Skan# pre-releases are generated, the flex/bison generated files as well as the
26169695Skan# various formats of manuals need to be included along with the rest of the
27169695Skan# sources.  Therefore we have --enable-generated-files-in-srcdir to do 
28169695Skan# just that.
29169695SkanAC_MSG_CHECKING([for --enable-generated-files-in-srcdir])
30169695SkanLIBGOMP_ENABLE(generated-files-in-srcdir, no, ,
31169695Skan   [put copies of generated files in source dir intended for creating source 
32169695Skan    tarballs for users without texinfo bison or flex.],
33169695Skan   permit yes|no)
34169695SkanAC_MSG_RESULT($enable_generated_files_in_srcdir)
35169695SkanAM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
36169695Skan
37169695Skan
38169695Skan# -------
39169695Skan# -------
40169695Skan
41169695Skan# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
42169695Skan#
43169695Skan# You will slowly go insane if you do not grok the following fact:  when
44169695Skan# building this library, the top-level /target/ becomes the library's /host/.
45169695Skan#
46169695Skan# configure then causes --target to default to --host, exactly like any
47169695Skan# other package using autoconf.  Therefore, 'target' and 'host' will
48169695Skan# always be the same.  This makes sense both for native and cross compilers
49169695Skan# just think about it for a little while.  :-)
50169695Skan#
51169695Skan# Also, if this library is being configured as part of a cross compiler, the
52169695Skan# top-level configure script will pass the "real" host as $with_cross_host.
53169695Skan#
54169695Skan# Do not delete or change the following two lines.  For why, see
55169695Skan# http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
56169695SkanAC_CANONICAL_SYSTEM
57169695Skantarget_alias=${target_alias-$host_alias}
58169695Skan
59169695Skan# Sets up automake.  Must come after AC_CANONICAL_SYSTEM.  Each of the
60169695Skan# following is magically included in AUTOMAKE_OPTIONS in each Makefile.am.
61169695Skan#  1.9.0:  minimum required version
62169695Skan#  no-define:  PACKAGE and VERSION will not be #define'd in config.h (a bunch
63169695Skan#              of other PACKAGE_* variables will, however, and there's nothing
64169695Skan#              we can do about that; they come from AC_INIT).
65169695Skan#  foreign:  we don't follow the normal rules for GNU packages (no COPYING
66169695Skan#            file in the top srcdir, etc, etc), so stop complaining.
67169695Skan#  no-dependencies:  turns off auto dependency generation (just for now)
68169695Skan#  -Wall:  turns on all automake warnings...
69169695Skan#  -Wno-portability:  ...except this one, since GNU make is required.
70169695Skan#  -Wno-override: ... and this one, since we do want this in testsuite.
71169695SkanAM_INIT_AUTOMAKE([1.9.0 foreign -Wall -Wno-portability -Wno-override])
72169695SkanAM_ENABLE_MULTILIB(, ..)
73169695Skan
74169695Skan# Calculate toolexeclibdir
75169695Skan# Also toolexecdir, though it's only used in toolexeclibdir
76169695Skancase ${enable_version_specific_runtime_libs} in
77169695Skan  yes)
78169695Skan    # Need the gcc compiler version to know where to install libraries
79169695Skan    # and header files if --enable-version-specific-runtime-libs option
80169695Skan    # is selected.
81169695Skan    toolexecdir='$(libdir)/gcc/$(target_alias)'
82169695Skan    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
83169695Skan    ;;
84169695Skan  no)
85169695Skan    if test -n "$with_cross_host" &&
86169695Skan       test x"$with_cross_host" != x"no"; then
87169695Skan      # Install a library built with a cross compiler in tooldir, not libdir.
88169695Skan      toolexecdir='$(exec_prefix)/$(target_alias)'
89169695Skan      toolexeclibdir='$(toolexecdir)/lib'
90169695Skan    else
91169695Skan      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
92169695Skan      toolexeclibdir='$(libdir)'
93169695Skan    fi
94169695Skan    multi_os_directory=`$CC -print-multi-os-directory`
95169695Skan    case $multi_os_directory in
96169695Skan      .) ;; # Avoid trailing /.
97169695Skan      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
98169695Skan    esac
99169695Skan    ;;
100169695Skanesac
101169695SkanAC_SUBST(toolexecdir)
102169695SkanAC_SUBST(toolexeclibdir)
103169695Skan
104169695Skan# Check the compiler.
105169695Skan# The same as in boehm-gc and libstdc++. Have to borrow it from there.
106169695Skan# We must force CC to /not/ be precious variables; otherwise
107169695Skan# the wrong, non-multilib-adjusted value will be used in multilibs.
108169695Skan# As a side effect, we have to subst CFLAGS ourselves.
109169695Skan
110169695Skanm4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
111169695Skanm4_define([_AC_ARG_VAR_PRECIOUS],[])
112169695SkanAC_PROG_CC
113169695Skanm4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
114169695Skan
115169695SkanAC_SUBST(CFLAGS)
116169695Skan
117169695Skan# In order to override CFLAGS_FOR_TARGET, all of our special flags go
118169695Skan# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
119169695Skan# in both places for now and restore CFLAGS at the end of config.
120169695Skansave_CFLAGS="$CFLAGS"
121169695Skan
122169695Skan# Add -Wall -Werror if we are using GCC.
123169695Skanif test "x$GCC" = "xyes"; then
124169695Skan  XCFLAGS="$XCFLAGS -Wall -Werror"
125169695Skanfi
126169695Skan
127169695Skan# Find other programs we need.
128169695SkanAC_CHECK_TOOL(AR, ar)
129169695SkanAC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
130169695SkanAC_PATH_PROG(PERL, perl, perl-not-found-in-path-error)
131169695SkanAC_PROG_MAKE_SET
132169695SkanAC_PROG_INSTALL
133169695Skan
134169695Skan# See if makeinfo has been installed and is modern enough
135169695Skan# that we can use it.
136169695SkanACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
137169695Skan                   [GNU texinfo.* \([0-9][0-9.]*\)],
138169695Skan                   [4.[4-9]*])
139169695SkanAM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
140169695Skan
141169695Skan
142169695Skan# Configure libtool
143169695SkanAM_PROG_LIBTOOL
144169695SkanAC_SUBST(enable_shared)
145169695SkanAC_SUBST(enable_static)
146169695Skan
147169695SkanAM_MAINTAINER_MODE
148169695Skan
149169695Skan# We need gfortran to compile parts of the library
150169695Skan# We can't use AC_PROG_FC because it expects a fully working gfortran.
151169695Skan#AC_PROG_FC(gfortran)
152169695SkanFC="$GFORTRAN"
153169695SkanAC_PROG_FC(gfortran)
154169695SkanFCFLAGS="$FCFLAGS -Wall"
155169695Skan
156169695Skan# For libtool versioning info, format is CURRENT:REVISION:AGE
157169695Skanlibtool_VERSION=1:0:0
158169695SkanAC_SUBST(libtool_VERSION)
159169695Skan
160169695Skan# Check header files.
161169695SkanAC_STDC_HEADERS
162169695SkanAC_HEADER_TIME
163169695SkanAC_CHECK_HEADERS(unistd.h semaphore.h sys/loadavg.h sys/time.h)
164169695Skan
165169695SkanGCC_HEADER_STDINT(gstdint.h)
166169695Skan
167169695Skan# Check to see if -pthread or -lpthread is needed.  Prefer the former.
168169695Skan# In case the pthread.h system header is not found, this test will fail.
169169695SkanXPCFLAGS=""
170169695SkanCFLAGS="$CFLAGS -pthread"
171169695SkanAC_LINK_IFELSE(
172169695Skan [AC_LANG_PROGRAM(
173169695Skan  [#include <pthread.h>
174169695Skan   void *g(void *d) { return NULL; }],
175169695Skan  [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
176169695Skan [XPCFLAGS=" -Wc,-pthread"],
177169695Skan [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
178169695Skan  AC_LINK_IFELSE(
179169695Skan   [AC_LANG_PROGRAM(
180169695Skan    [#include <pthread.h>
181169695Skan     void *g(void *d) { return NULL; }],
182169695Skan    [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
183169695Skan   [],
184169695Skan   [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
185169695Skan
186169695Skan# Check for functions needed.
187169695SkanAC_CHECK_FUNCS(getloadavg clock_gettime)
188169695Skan
189169695Skan# Check for broken semaphore implementation on darwin.
190169695Skan# sem_init returns: sem_init error: Function not implemented.
191169695Skancase "$host" in
192169695Skan  *-darwin*)
193169695Skan    AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
194169695Skan	Define if the POSIX Semaphores do not work on your system.)
195169695Skan    ;;
196169695Skan  *-linux*)
197169695Skan    case "$enable_linux_futex" in
198169695Skan      default)
199169695Skan	# If headers don't have gettid/futex syscalls definition, then
200169695Skan	# default to no, otherwise there will be compile time failures.
201169695Skan	# Otherwise, default to yes.  If we don't detect we are
202169695Skan	# compiled/linked against NPTL and not cross-compiling, check
203169695Skan	# if programs are run by default against NPTL and if not, issue
204169695Skan	# a warning.
205169695Skan	enable_linux_futex=no
206169695Skan	AC_LINK_IFELSE(
207169695Skan	 [AC_LANG_PROGRAM(
208169695Skan	  [#include <sys/syscall.h>
209169695Skan	   int lk;],
210169695Skan	  [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],
211169695Skan	  [AC_LINK_IFELSE(
212169695Skan	   [AC_LANG_PROGRAM(
213169695Skan	    [#ifndef _GNU_SOURCE
214169695Skan	     #define _GNU_SOURCE 1
215169695Skan	     #endif
216169695Skan	     #include <pthread.h>
217169695Skan	     pthread_t th; void *status;],
218169695Skan	    [pthread_tryjoin_np (th, &status);])],[enable_linux_futex=yes],
219169695Skan	    [if test x$cross_compiling = xno; then
220169695Skan	       if getconf GNU_LIBPTHREAD_VERSION 2>/dev/null \
221169695Skan		  | LC_ALL=C grep -i NPTL > /dev/null 2>/dev/null; then
222169695Skan		 AC_MSG_WARN([The kernel might not support futex or gettid syscalls.
223169695SkanIf so, please configure with --disable-linux-futex])
224169695Skan	       fi
225169695Skan	     fi
226169695Skan	     enable_linux_futex=yes])])
227169695Skan	;;
228169695Skan      yes)
229169695Skan	AC_LINK_IFELSE(
230169695Skan	 [AC_LANG_PROGRAM(
231169695Skan	  [#include <sys/syscall.h>
232169695Skan	   int lk;],
233169695Skan	  [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],[],
234169695Skan	  [AC_MSG_ERROR([SYS_gettid and SYS_futex required for --enable-linux-futex])])
235169695Skan	;;
236169695Skan    esac
237169695Skan    ;;
238169695Skanesac
239169695Skan
240169695Skan# At least for glibc, clock_gettime is in librt.  But don't pull that
241169695Skan# in if it still doesn't give us the function we want.
242169695Skanif test $ac_cv_func_clock_gettime = no; then
243169695Skan  AC_CHECK_LIB(rt, clock_gettime,
244169695Skan    [LIBS="-lrt $LIBS"
245169695Skan     AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
246169695Skan	       [Define to 1 if you have the `clock_gettime' function.])])
247169695Skanfi
248169695Skan
249169695Skan# See if we support thread-local storage.
250169695SkanGCC_CHECK_TLS
251169695Skan
252169695Skan# See what sort of export controls are availible.
253169695SkanLIBGOMP_CHECK_ATTRIBUTE_VISIBILITY
254169695SkanLIBGOMP_CHECK_ATTRIBUTE_DLLEXPORT
255169695SkanLIBGOMP_CHECK_ATTRIBUTE_ALIAS
256169695SkanLIBGOMP_ENABLE_SYMVERS
257169695Skan
258169695Skan# Get target configury.
259169695Skan. ${srcdir}/configure.tgt
260169695SkanCFLAGS="$save_CFLAGS $XCFLAGS"
261169695Skan
262169695Skan# Check for __sync_val_compare_and_swap, but only after the target has
263169695Skan# had a chance to set XCFLAGS.
264169695SkanLIBGOMP_CHECK_SYNC_BUILTINS
265169695Skan
266169695SkanXCFLAGS="$XCFLAGS$XPCFLAGS"
267169695Skan
268169695SkanAC_SUBST(config_path)
269169695SkanAC_SUBST(XCFLAGS)
270169695SkanAC_SUBST(XLDFLAGS)
271169695Skan
272169695Skan# Cleanup and exit.
273169695SkanCFLAGS="$save_CFLAGS"
274169695SkanAC_CACHE_SAVE
275169695Skan
276169695Skanif test ${multilib} = yes; then
277169695Skan  multilib_arg="--enable-multilib"
278169695Skanelse
279169695Skan  multilib_arg=
280169695Skanfi
281169695Skan
282169695Skan# Set up the set of libraries that we need to link against for libgomp.
283169695Skan# Note that the GOMP_SELF_SPEC in gcc.c will force -pthread for -fopenmp,
284169695Skan# which will force linkage against -lpthread (or equivalent for the system).
285169695Skan# That's not 100% ideal, but about the best we can do easily.
286169695Skanif test $enable_shared = yes; then
287169695Skan  link_gomp="-lgomp %{static: $LIBS}"
288169695Skanelse
289169695Skan  link_gomp="-lgomp $LIBS"
290169695Skanfi
291169695SkanAC_SUBST(link_gomp)
292169695Skan
293169695SkanAM_CONDITIONAL([USE_FORTRAN], [test "$ac_cv_fc_compiler_gnu" = yes])
294169695Skan
295169695Skan# ??? 2006-01-24: Paulo committed to asking autoconf folk to document
296169695Skan# and export AC_COMPUTE_INT.  If that happens, then we'll need to remove
297169695Skan# the underscore here and update the PREREQ.  If it doesn't, then we'll
298169695Skan# need to copy this macro to our acinclude.m4.
299169695Skansave_CFLAGS="$CFLAGS"
300169695Skanfor i in $config_path; do
301169695Skan  if test -f $srcdir/config/$i/omp-lock.h; then
302169695Skan    CFLAGS="$CFLAGS -include $srcdir/config/$i/omp-lock.h"
303169695Skan    break
304169695Skan  fi
305169695Skandone
306169695Skan
307169695Skan_AC_COMPUTE_INT([sizeof (omp_lock_t)], [OMP_LOCK_SIZE],,
308169695Skan  [AC_MSG_ERROR([unsupported system, cannot find sizeof (omp_lock_t)])])
309169695Skan_AC_COMPUTE_INT([__alignof (omp_lock_t)], [OMP_LOCK_ALIGN])
310169695Skan_AC_COMPUTE_INT([sizeof (omp_nest_lock_t)], [OMP_NEST_LOCK_SIZE])
311169695Skan_AC_COMPUTE_INT([__alignof (omp_nest_lock_t)], [OMP_NEST_LOCK_ALIGN])
312169695Skan
313169695Skan# If the lock fits in an integer, then arrange for Fortran to use that
314169695Skan# integer.  If it doesn't, then arrange for Fortran to use a pointer.
315169695Skan# Except that we don't have a way at present to multi-lib the installed
316169695Skan# Fortran modules, so we assume 8 bytes for pointers, regardless of the
317169695Skan# actual target.
318169695SkanOMP_LOCK_KIND=$OMP_LOCK_SIZE
319169695SkanOMP_NEST_LOCK_KIND=$OMP_NEST_LOCK_SIZE
320169695Skanif test $OMP_LOCK_SIZE -gt 8 || test $OMP_LOCK_ALIGN -gt $OMP_LOCK_SIZE; then
321169695Skan  OMP_LOCK_KIND=8
322169695Skanfi
323169695Skanif test $OMP_NEST_LOCK_SIZE -gt 8 || test $OMP_NEST_LOCK_ALIGN -gt $OMP_NEST_LOCK_SIZE; then
324169695Skan  OMP_NEST_LOCK_KIND=8
325169695Skanfi
326169695Skan
327169695SkanAC_SUBST(OMP_LOCK_SIZE)
328169695SkanAC_SUBST(OMP_LOCK_ALIGN)
329169695SkanAC_SUBST(OMP_NEST_LOCK_SIZE)
330169695SkanAC_SUBST(OMP_NEST_LOCK_ALIGN)
331169695SkanAC_SUBST(OMP_LOCK_KIND)
332169695SkanAC_SUBST(OMP_NEST_LOCK_KIND)
333169695SkanCFLAGS="$save_CFLAGS"
334169695Skan
335169695SkanAC_CONFIG_FILES(omp.h omp_lib.h omp_lib.f90 libgomp_f.h)
336169695SkanAC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec)
337169695SkanAC_OUTPUT
338