1153838Sdfr# Process this file with autoconf to produce a configure script, like so:
2153838Sdfr# aclocal -I ../config && autoconf && autoheader && automake
3153838Sdfr
4153838SdfrAC_PREREQ(2.59)
5153838SdfrAC_INIT([GNU OpenMP Runtime Library], 1.0,,[libgomp])
6153838SdfrAC_CONFIG_HEADER(config.h)
7153838Sdfr
8153838Sdfr# -------
9153838Sdfr# Options
10153838Sdfr# -------
11153838Sdfr
12153838SdfrAC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
13153838SdfrLIBGOMP_ENABLE(version-specific-runtime-libs, no, ,
14153838Sdfr   [Specify that runtime libraries should be installed in a compiler-specific directory],
15153838Sdfr   permit yes|no)
16153838SdfrAC_MSG_RESULT($enable_version_specific_runtime_libs)
17153838Sdfr
18153838Sdfr# We would like our source tree to be readonly. However when releases or
19153838Sdfr# pre-releases are generated, the flex/bison generated files as well as the
20153838Sdfr# various formats of manuals need to be included along with the rest of the
21153838Sdfr# sources.  Therefore we have --enable-generated-files-in-srcdir to do 
22153838Sdfr# just that.
23153838SdfrAC_MSG_CHECKING([for --enable-generated-files-in-srcdir])
24153838SdfrLIBGOMP_ENABLE(generated-files-in-srcdir, no, ,
25153838Sdfr   [put copies of generated files in source dir intended for creating source 
26153838Sdfr    tarballs for users without texinfo bison or flex.],
27153838Sdfr   permit yes|no)
28153838SdfrAC_MSG_RESULT($enable_generated_files_in_srcdir)
29153838SdfrAM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
30153838Sdfr
31168340Skan
32153838Sdfr# -------
33153838Sdfr# -------
34153838Sdfr
35153838Sdfr# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
36153838Sdfr#
37153838Sdfr# You will slowly go insane if you do not grok the following fact:  when
38153838Sdfr# building this library, the top-level /target/ becomes the library's /host/.
39153838Sdfr#
40153838Sdfr# configure then causes --target to default to --host, exactly like any
41153838Sdfr# other package using autoconf.  Therefore, 'target' and 'host' will
42153838Sdfr# always be the same.  This makes sense both for native and cross compilers
43153838Sdfr# just think about it for a little while.  :-)
44153838Sdfr#
45153838Sdfr# Also, if this library is being configured as part of a cross compiler, the
46153838Sdfr# top-level configure script will pass the "real" host as $with_cross_host.
47153838Sdfr#
48153838Sdfr# Do not delete or change the following two lines.  For why, see
49153838Sdfr# http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
50153838SdfrAC_CANONICAL_SYSTEM
51153838Sdfrtarget_alias=${target_alias-$host_alias}
52153838Sdfr
53153838Sdfr# Sets up automake.  Must come after AC_CANONICAL_SYSTEM.  Each of the
54153838Sdfr# following is magically included in AUTOMAKE_OPTIONS in each Makefile.am.
55153838Sdfr#  1.9.0:  minimum required version
56153838Sdfr#  no-define:  PACKAGE and VERSION will not be #define'd in config.h (a bunch
57153838Sdfr#              of other PACKAGE_* variables will, however, and there's nothing
58153838Sdfr#              we can do about that; they come from AC_INIT).
59153838Sdfr#  foreign:  we don't follow the normal rules for GNU packages (no COPYING
60153838Sdfr#            file in the top srcdir, etc, etc), so stop complaining.
61153838Sdfr#  no-dist:  we don't want 'dist' and related rules.
62153838Sdfr#  -Wall:  turns on all automake warnings...
63153838Sdfr#  -Wno-portability:  ...except this one, since GNU make is required.
64153838Sdfr#  -Wno-override: ... and this one, since we do want this in testsuite.
65153838SdfrAM_INIT_AUTOMAKE([1.9.0 foreign no-dist -Wall -Wno-portability -Wno-override])
66153838SdfrAM_ENABLE_MULTILIB(, ..)
67153838Sdfr
68153838Sdfr# Calculate toolexeclibdir
69153838Sdfr# Also toolexecdir, though it's only used in toolexeclibdir
70153838Sdfrcase ${enable_version_specific_runtime_libs} in
71153838Sdfr  yes)
72153838Sdfr    # Need the gcc compiler version to know where to install libraries
73153838Sdfr    # and header files if --enable-version-specific-runtime-libs option
74153838Sdfr    # is selected.
75153838Sdfr    toolexecdir='$(libdir)/gcc/$(target_alias)'
76153838Sdfr    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
77153838Sdfr    ;;
78153838Sdfr  no)
79153838Sdfr    if test -n "$with_cross_host" &&
80153838Sdfr       test x"$with_cross_host" != x"no"; then
81153838Sdfr      # Install a library built with a cross compiler in tooldir, not libdir.
82153838Sdfr      toolexecdir='$(exec_prefix)/$(target_alias)'
83153838Sdfr      toolexeclibdir='$(toolexecdir)/lib'
84153838Sdfr    else
85153838Sdfr      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
86153838Sdfr      toolexeclibdir='$(libdir)'
87153838Sdfr    fi
88153838Sdfr    multi_os_directory=`$CC -print-multi-os-directory`
89153838Sdfr    case $multi_os_directory in
90153838Sdfr      .) ;; # Avoid trailing /.
91153838Sdfr      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
92153838Sdfr    esac
93153838Sdfr    ;;
94153838Sdfresac
95153838SdfrAC_SUBST(toolexecdir)
96153838SdfrAC_SUBST(toolexeclibdir)
97153838Sdfr
98153838Sdfr# Check the compiler.
99153838Sdfr# The same as in boehm-gc and libstdc++. Have to borrow it from there.
100153838Sdfr# We must force CC to /not/ be precious variables; otherwise
101153838Sdfr# the wrong, non-multilib-adjusted value will be used in multilibs.
102153838Sdfr# As a side effect, we have to subst CFLAGS ourselves.
103153838Sdfr
104153838Sdfrm4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
105153838Sdfrm4_define([_AC_ARG_VAR_PRECIOUS],[])
106153838SdfrAC_PROG_CC
107153838Sdfrm4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
108153838Sdfr
109153838SdfrAC_SUBST(CFLAGS)
110153838Sdfr
111153838Sdfr# In order to override CFLAGS_FOR_TARGET, all of our special flags go
112153838Sdfr# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
113153838Sdfr# in both places for now and restore CFLAGS at the end of config.
114153838Sdfrsave_CFLAGS="$CFLAGS"
115153838Sdfr
116153838Sdfr# Add -Wall -Werror if we are using GCC.
117153838Sdfrif test "x$GCC" = "xyes"; then
118153838Sdfr  XCFLAGS="$XCFLAGS -Wall -Werror"
119153838Sdfrfi
120153838Sdfr
121153838Sdfr# Find other programs we need.
122153838SdfrAC_CHECK_TOOL(AR, ar)
123153838SdfrAC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
124153838SdfrAC_PATH_PROG(PERL, perl, perl-not-found-in-path-error)
125153838SdfrAC_PROG_MAKE_SET
126153838SdfrAC_PROG_INSTALL
127153838Sdfr
128178828Sdfr# See if makeinfo has been installed and is modern enough
129178828Sdfr# that we can use it.
130178828SdfrACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
131178828Sdfr                   [GNU texinfo.* \([0-9][0-9.]*\)],
132153838Sdfr                   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
133153838SdfrAM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
134153838Sdfr
135153838Sdfr
136153838Sdfr# Configure libtool
137153838SdfrAM_PROG_LIBTOOL
138153838SdfrAC_SUBST(enable_shared)
139153838SdfrAC_SUBST(enable_static)
140153838Sdfr
141153838SdfrAM_MAINTAINER_MODE
142153838Sdfr
143153838Sdfr# We need gfortran to compile parts of the library
144153838Sdfr# We can't use AC_PROG_FC because it expects a fully working gfortran.
145153838Sdfr#AC_PROG_FC(gfortran)
146153838SdfrFC="$GFORTRAN"
147153838SdfrAC_PROG_FC(gfortran)
148153838SdfrFCFLAGS="$FCFLAGS -Wall"
149153838Sdfr
150153838Sdfr# For libtool versioning info, format is CURRENT:REVISION:AGE
151153838Sdfrlibtool_VERSION=1:0:0
152153838SdfrAC_SUBST(libtool_VERSION)
153153838Sdfr
154153838Sdfr# Check header files.
155153838SdfrAC_STDC_HEADERS
156153838SdfrAC_HEADER_TIME
157153838SdfrAC_CHECK_HEADERS(unistd.h semaphore.h sys/loadavg.h sys/sysctl.h sys/time.h)
158178828Sdfr
159178828SdfrGCC_HEADER_STDINT(gstdint.h)
160153838Sdfr
161153838Sdfr# Check to see if -pthread or -lpthread is needed.  Prefer the former.
162153838Sdfr# In case the pthread.h system header is not found, this test will fail.
163153838SdfrXPCFLAGS=""
164153838SdfrCFLAGS="$CFLAGS -pthread"
165153838SdfrAC_LINK_IFELSE(
166153838Sdfr [AC_LANG_PROGRAM(
167153838Sdfr  [#include <pthread.h>
168153838Sdfr   void *g(void *d) { return NULL; }],
169153838Sdfr  [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
170153838Sdfr [XPCFLAGS=" -Wc,-pthread"],
171153838Sdfr [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
172153838Sdfr  AC_LINK_IFELSE(
173153838Sdfr   [AC_LANG_PROGRAM(
174153838Sdfr    [#include <pthread.h>
175153838Sdfr     void *g(void *d) { return NULL; }],
176178828Sdfr    [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
177153838Sdfr   [],
178153838Sdfr   [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
179153838Sdfr
180153838Sdfr# Check for functions needed.
181153838SdfrAC_CHECK_FUNCS(getloadavg clock_gettime)
182153838Sdfr
183153838Sdfr# Check for broken semaphore implementation on darwin.
184153838Sdfr# sem_init returns: sem_init error: Function not implemented.
185153838Sdfrcase "$host" in
186178828Sdfr  *-darwin*)
187178828Sdfr    AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
188178828Sdfr	Define if the POSIX Semaphores do not work on your system.)
189178828Sdfr    ;;
190178828Sdfresac
191178828Sdfr
192178828SdfrGCC_LINUX_FUTEX(:)
193153838Sdfr
194153838Sdfr# Check for pthread_{,attr_}[sg]etaffinity_np.
195153838SdfrAC_LINK_IFELSE(
196153838Sdfr [AC_LANG_PROGRAM(
197153838Sdfr  [#define _GNU_SOURCE
198153838Sdfr   #include <pthread.h>],
199153838Sdfr  [cpu_set_t cpuset;
200153838Sdfr   pthread_attr_t attr;
201153838Sdfr   pthread_getaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
202153838Sdfr   if (CPU_ISSET (0, &cpuset))
203153838Sdfr     CPU_SET (1, &cpuset);
204153838Sdfr   else
205153838Sdfr     CPU_ZERO (&cpuset);
206153838Sdfr   pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
207153838Sdfr   pthread_attr_init (&attr);
208153838Sdfr   pthread_attr_getaffinity_np (&attr, sizeof (cpu_set_t), &cpuset);
209153838Sdfr   pthread_attr_setaffinity_np (&attr, sizeof (cpu_set_t), &cpuset);])],
210153838Sdfr  AC_DEFINE(HAVE_PTHREAD_AFFINITY_NP, 1,
211153838Sdfr[	Define if pthread_{,attr_}{g,s}etaffinity_np is supported.]))
212153838Sdfr
213153838Sdfr# At least for glibc, clock_gettime is in librt.  But don't pull that
214153838Sdfr# in if it still doesn't give us the function we want.
215178828Sdfrif test $ac_cv_func_clock_gettime = no; then
216178828Sdfr  AC_CHECK_LIB(rt, clock_gettime,
217153838Sdfr    [LIBS="-lrt $LIBS"
218153838Sdfr     AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
219153838Sdfr	       [Define to 1 if you have the `clock_gettime' function.])])
220153838Sdfrfi
221153838Sdfr
222153838Sdfr# See if we support thread-local storage.
223153838SdfrGCC_CHECK_TLS
224153838Sdfr
225# See what sort of export controls are availible.
226LIBGOMP_CHECK_ATTRIBUTE_VISIBILITY
227LIBGOMP_CHECK_ATTRIBUTE_DLLEXPORT
228LIBGOMP_CHECK_ATTRIBUTE_ALIAS
229LIBGOMP_ENABLE_SYMVERS
230
231# Get target configury.
232. ${srcdir}/configure.tgt
233CFLAGS="$save_CFLAGS $XCFLAGS"
234
235# Check for __sync_val_compare_and_swap, but only after the target has
236# had a chance to set XCFLAGS.
237LIBGOMP_CHECK_SYNC_BUILTINS
238
239XCFLAGS="$XCFLAGS$XPCFLAGS"
240
241AC_SUBST(config_path)
242AC_SUBST(XCFLAGS)
243AC_SUBST(XLDFLAGS)
244
245# Cleanup and exit.
246CFLAGS="$save_CFLAGS"
247AC_CACHE_SAVE
248
249if test ${multilib} = yes; then
250  multilib_arg="--enable-multilib"
251else
252  multilib_arg=
253fi
254
255# Set up the set of libraries that we need to link against for libgomp.
256# Note that the GOMP_SELF_SPEC in gcc.c will force -pthread for -fopenmp,
257# which will force linkage against -lpthread (or equivalent for the system).
258# That's not 100% ideal, but about the best we can do easily.
259if test $enable_shared = yes; then
260  link_gomp="-lgomp %{static: $LIBS}"
261else
262  link_gomp="-lgomp $LIBS"
263fi
264AC_SUBST(link_gomp)
265
266AM_CONDITIONAL([USE_FORTRAN], [test "$ac_cv_fc_compiler_gnu" = yes])
267
268# ??? 2006-01-24: Paulo committed to asking autoconf folk to document
269# and export AC_COMPUTE_INT.  If that happens, then we'll need to remove
270# the underscore here and update the PREREQ.  If it doesn't, then we'll
271# need to copy this macro to our acinclude.m4.
272save_CFLAGS="$CFLAGS"
273for i in $config_path; do
274  if test -f $srcdir/config/$i/omp-lock.h; then
275    CFLAGS="$CFLAGS -include $srcdir/config/$i/omp-lock.h"
276    break
277  fi
278done
279
280_AC_COMPUTE_INT([sizeof (omp_lock_t)], [OMP_LOCK_SIZE],,
281  [AC_MSG_ERROR([unsupported system, cannot find sizeof (omp_lock_t)])])
282_AC_COMPUTE_INT([__alignof (omp_lock_t)], [OMP_LOCK_ALIGN])
283_AC_COMPUTE_INT([sizeof (omp_nest_lock_t)], [OMP_NEST_LOCK_SIZE])
284_AC_COMPUTE_INT([__alignof (omp_nest_lock_t)], [OMP_NEST_LOCK_ALIGN])
285
286# If the lock fits in an integer, then arrange for Fortran to use that
287# integer.  If it doesn't, then arrange for Fortran to use a pointer.
288# Except that we don't have a way at present to multi-lib the installed
289# Fortran modules, so we assume 8 bytes for pointers, regardless of the
290# actual target.
291OMP_LOCK_KIND=$OMP_LOCK_SIZE
292OMP_NEST_LOCK_KIND=$OMP_NEST_LOCK_SIZE
293if test $OMP_LOCK_SIZE -gt 8 || test $OMP_LOCK_ALIGN -gt $OMP_LOCK_SIZE; then
294  OMP_LOCK_KIND=8
295fi
296if test $OMP_NEST_LOCK_SIZE -gt 8 || test $OMP_NEST_LOCK_ALIGN -gt $OMP_NEST_LOCK_SIZE; then
297  OMP_NEST_LOCK_KIND=8
298fi
299
300AC_SUBST(OMP_LOCK_SIZE)
301AC_SUBST(OMP_LOCK_ALIGN)
302AC_SUBST(OMP_NEST_LOCK_SIZE)
303AC_SUBST(OMP_NEST_LOCK_ALIGN)
304AC_SUBST(OMP_LOCK_KIND)
305AC_SUBST(OMP_NEST_LOCK_KIND)
306CFLAGS="$save_CFLAGS"
307
308AC_CONFIG_FILES(omp.h omp_lib.h omp_lib.f90 libgomp_f.h)
309AC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec)
310AC_OUTPUT
311