1# Process this file with autoconf to produce a configure script, like so:
2# aclocal -I ../config && autoconf && autoheader && automake
3
4AC_INIT([GNU Offloading and Multi Processing Runtime Library], 1.0,,[libgomp])
5AC_CONFIG_HEADER(config.h)
6
7# -------
8# Options
9# -------
10
11AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
12LIBGOMP_ENABLE(version-specific-runtime-libs, no, ,
13   [Specify that runtime libraries should be installed in a compiler-specific directory],
14   permit yes|no)
15AC_MSG_RESULT($enable_version_specific_runtime_libs)
16
17# We would like our source tree to be readonly. However when releases or
18# pre-releases are generated, the flex/bison generated files as well as the
19# various formats of manuals need to be included along with the rest of the
20# sources.  Therefore we have --enable-generated-files-in-srcdir to do
21# just that.
22AC_MSG_CHECKING([for --enable-generated-files-in-srcdir])
23LIBGOMP_ENABLE(generated-files-in-srcdir, no, ,
24   [put copies of generated files in source dir intended for creating source
25    tarballs for users without texinfo bison or flex.],
26   permit yes|no)
27AC_MSG_RESULT($enable_generated_files_in_srcdir)
28AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
29
30
31# -------
32# -------
33
34# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
35#
36# You will slowly go insane if you do not grok the following fact:  when
37# building this library, the top-level /target/ becomes the library's /host/.
38#
39# configure then causes --target to default to --host, exactly like any
40# other package using autoconf.  Therefore, 'target' and 'host' will
41# always be the same.  This makes sense both for native and cross compilers
42# just think about it for a little while.  :-)
43#
44# Also, if this library is being configured as part of a cross compiler, the
45# top-level configure script will pass the "real" host as $with_cross_host.
46#
47# Do not delete or change the following two lines.  For why, see
48# http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
49AC_CANONICAL_SYSTEM
50target_alias=${target_alias-$host_alias}
51
52# Sets up automake.  Must come after AC_CANONICAL_SYSTEM.  Each of the
53# following is magically included in AUTOMAKE_OPTIONS in each Makefile.am.
54#  1.9.0:  minimum required version
55#  no-define:  PACKAGE and VERSION will not be #define'd in config.h (a bunch
56#              of other PACKAGE_* variables will, however, and there's nothing
57#              we can do about that; they come from AC_INIT).
58#  foreign:  we don't follow the normal rules for GNU packages (no COPYING
59#            file in the top srcdir, etc, etc), so stop complaining.
60#  no-dist:  we don't want 'dist' and related rules.
61#  -Wall:  turns on all automake warnings...
62#  -Wno-portability:  ...except this one, since GNU make is required.
63#  -Wno-override: ... and this one, since we do want this in testsuite.
64AM_INIT_AUTOMAKE([1.9.0 foreign no-dist -Wall -Wno-portability -Wno-override])
65AM_ENABLE_MULTILIB(, ..)
66
67GCC_WITH_TOOLEXECLIBDIR
68
69# Calculate toolexeclibdir
70# Also toolexecdir, though it's only used in toolexeclibdir
71case ${enable_version_specific_runtime_libs} in
72  yes)
73    # Need the gcc compiler version to know where to install libraries
74    # and header files if --enable-version-specific-runtime-libs option
75    # is selected.
76    toolexecdir='$(libdir)/gcc/$(target_alias)'
77    toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
78    ;;
79  no)
80    if test -n "$with_cross_host" &&
81       test x"$with_cross_host" != x"no"; then
82      # Install a library built with a cross compiler in tooldir, not libdir.
83      toolexecdir='$(exec_prefix)/$(target_alias)'
84      case ${with_toolexeclibdir} in
85	no)
86	  toolexeclibdir='$(toolexecdir)/lib'
87	  ;;
88	*)
89	  toolexeclibdir=${with_toolexeclibdir}
90	  ;;
91      esac
92    else
93      toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
94      toolexeclibdir='$(libdir)'
95    fi
96    multi_os_directory=`$CC -print-multi-os-directory`
97    case $multi_os_directory in
98      .) ;; # Avoid trailing /.
99      *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
100    esac
101    ;;
102esac
103AC_SUBST(toolexecdir)
104AC_SUBST(toolexeclibdir)
105
106# Check the compiler.
107# The same as in boehm-gc and libstdc++. Have to borrow it from there.
108# We must force CC to /not/ be precious variables; otherwise
109# the wrong, non-multilib-adjusted value will be used in multilibs.
110# As a side effect, we have to subst CFLAGS ourselves.
111
112m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
113m4_define([_AC_ARG_VAR_PRECIOUS],[])
114AC_PROG_CC
115m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
116
117AC_SUBST(CFLAGS)
118
119# In order to override CFLAGS_FOR_TARGET, all of our special flags go
120# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
121# in both places for now and restore CFLAGS at the end of config.
122save_CFLAGS="$CFLAGS"
123
124# Add -Wall -Werror if we are using GCC.
125if test "x$GCC" = "xyes"; then
126  XCFLAGS="$XCFLAGS -Wall -Werror"
127fi
128
129# Find other programs we need.
130AC_CHECK_TOOL(AR, ar)
131AC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
132AC_PATH_PROG(PERL, perl, perl-not-found-in-path-error)
133AC_PROG_MAKE_SET
134AC_PROG_INSTALL
135
136# See if makeinfo has been installed and is modern enough
137# that we can use it.
138ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
139                   [GNU texinfo.* \([0-9][0-9.]*\)],
140                   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
141AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
142
143
144# Configure libtool
145AM_PROG_LIBTOOL
146ACX_LT_HOST_FLAGS
147AC_SUBST(enable_shared)
148AC_SUBST(enable_static)
149
150AM_MAINTAINER_MODE
151
152# Create a spec file, so that compile/link tests don't fail
153test -f libgfortran.spec || touch libgfortran.spec
154FCFLAGS="$FCFLAGS -L."
155
156# We need gfortran to compile parts of the library
157# We can't use AC_PROG_FC because it expects a fully working gfortran.
158#AC_PROG_FC(gfortran)
159case `echo $GFORTRAN` in
160  -* | no* )
161    FC=no ;;
162  *)
163    set dummy $GFORTRAN; ac_word=$2
164    if test -x "$ac_word"; then
165      FC="$GFORTRAN"
166    else
167      FC=no
168    fi ;;
169esac
170AC_PROG_FC(gfortran)
171FCFLAGS="$FCFLAGS -Wall -L../libgfortran"
172
173# For libtool versioning info, format is CURRENT:REVISION:AGE
174libtool_VERSION=1:0:0
175AC_SUBST(libtool_VERSION)
176
177# Check header files.
178AC_STDC_HEADERS
179AC_HEADER_TIME
180ACX_HEADER_STRING
181AC_CHECK_HEADERS(pthread.h unistd.h semaphore.h sys/loadavg.h sys/sysctl.h sys/time.h)
182
183XPCFLAGS=""
184case "$host" in
185  *-*-rtems*)
186    # RTEMS supports Pthreads, but the library is not available at GCC build time.
187    ;;
188  nvptx*-*-* | amdgcn*-*-*)
189    # NVPTX does not support Pthreads, has its own code replacement.
190    libgomp_use_pthreads=no
191    # NVPTX is an accelerator-only target
192    libgomp_offloaded_only=yes
193    ;;
194  *)
195    # Check to see if -pthread or -lpthread is needed.  Prefer the former.
196    # In case the pthread.h system header is not found, this test will fail.
197    CFLAGS="$CFLAGS -pthread"
198    AC_LINK_IFELSE(
199     [AC_LANG_PROGRAM(
200      [#include <pthread.h>
201       void *g(void *d) { return NULL; }],
202      [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
203     [XPCFLAGS=" -Wc,-pthread"],
204     [CFLAGS="$save_CFLAGS" LIBS="-lpthread $LIBS"
205      AC_LINK_IFELSE(
206       [AC_LANG_PROGRAM(
207        [#include <pthread.h>
208         void *g(void *d) { return NULL; }],
209        [pthread_t t; pthread_create(&t,NULL,g,NULL);])],
210       [],
211       [AC_MSG_ERROR([Pthreads are required to build libgomp])])])
212esac
213
214if test x$libgomp_use_pthreads != xno; then
215  AC_DEFINE(LIBGOMP_USE_PTHREADS, 1,
216            [Define to 1 if libgomp should use POSIX threads.])
217fi
218
219if test x$libgomp_offloaded_only = xyes; then
220  AC_DEFINE(LIBGOMP_OFFLOADED_ONLY, 1,
221            [Define to 1 if building libgomp for an accelerator-only target.])
222fi
223
224AC_CHECK_SIZEOF([void *])
225
226m4_include([plugin/configfrag.ac])
227
228# Check for functions needed.
229AC_CHECK_FUNCS(getloadavg clock_gettime strtoull)
230AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
231
232# Check for broken semaphore implementation on darwin.
233# sem_init returns: sem_init error: Function not implemented.
234case "$host" in
235  *-darwin*)
236    AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
237	Define if the POSIX Semaphores do not work on your system.)
238    ;;
239esac
240
241# RTEMS specific checks
242case "$host" in
243  *-*-rtems*)
244    AC_CHECK_TYPES([struct _Mutex_Control],[],[],[#include <sys/lock.h>])
245    ;;
246esac
247
248GCC_LINUX_FUTEX(:)
249
250# Check for pthread_{,attr_}[sg]etaffinity_np.
251AC_LINK_IFELSE(
252 [AC_LANG_PROGRAM(
253  [#define _GNU_SOURCE
254   #include <pthread.h>],
255  [cpu_set_t cpuset;
256   pthread_attr_t attr;
257   pthread_getaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
258   if (CPU_ISSET (0, &cpuset))
259     CPU_SET (1, &cpuset);
260   else
261     CPU_ZERO (&cpuset);
262   pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
263   pthread_attr_init (&attr);
264   pthread_attr_getaffinity_np (&attr, sizeof (cpu_set_t), &cpuset);
265   pthread_attr_setaffinity_np (&attr, sizeof (cpu_set_t), &cpuset);])],
266  AC_DEFINE(HAVE_PTHREAD_AFFINITY_NP, 1,
267[	Define if pthread_{,attr_}{g,s}etaffinity_np is supported.]))
268
269# At least for glibc, clock_gettime is in librt.  But don't pull that
270# in if it still doesn't give us the function we want.
271if test $ac_cv_func_clock_gettime = no; then
272  AC_CHECK_LIB(rt, clock_gettime,
273    [LIBS="-lrt $LIBS"
274     AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
275	       [Define to 1 if you have the `clock_gettime' function.])])
276fi
277
278# Check for uname.
279AC_COMPILE_IFELSE(
280 [AC_LANG_PROGRAM(
281  [#include <string.h>
282   #include <stdlib.h>
283   #include <sys/utsname.h>],
284  [struct utsname buf;
285   volatile size_t len = 0;
286   if (!uname (buf))
287     len = strlen (buf.nodename);])],
288  AC_DEFINE(HAVE_UNAME, 1,
289[	Define if uname is supported and struct utsname has nodename field.]))
290
291# Check for gethostname.
292AC_COMPILE_IFELSE(
293 [AC_LANG_PROGRAM(
294  [#include <unistd.h>],
295  [
296changequote(,)dnl
297   char buf[256];
298   if (gethostname (buf, sizeof (buf) - 1) == 0)
299     buf[255] = '\0';
300changequote([,])dnl
301  ])],
302  AC_DEFINE(HAVE_GETHOSTNAME, 1,
303[	Define if gethostname is supported.]))
304
305# Check for getpid.
306AC_COMPILE_IFELSE(
307 [AC_LANG_PROGRAM(
308  [#include <unistd.h>],
309  [int pid = getpid ();])],
310  AC_DEFINE(HAVE_GETPID, 1,
311[	Define if getpid is supported.]))
312
313# See if we support thread-local storage.
314GCC_CHECK_TLS
315
316# See if we have emulated thread-local storage.
317GCC_CHECK_EMUTLS
318
319# See what sort of export controls are available.
320LIBGOMP_CHECK_ATTRIBUTE_VISIBILITY
321LIBGOMP_CHECK_ATTRIBUTE_DLLEXPORT
322LIBGOMP_CHECK_ATTRIBUTE_ALIAS
323LIBGOMP_ENABLE_SYMVERS
324
325if test $enable_symvers = gnu; then
326  AC_DEFINE(LIBGOMP_GNU_SYMBOL_VERSIONING, 1,
327	    [Define to 1 if GNU symbol versioning is used for libgomp.])
328fi
329
330# Determine cpu count to limit testsuite parallelism.
331AX_COUNT_CPUS
332AC_SUBST(CPU_COUNT)
333
334# Get target configury.
335. ${srcdir}/configure.tgt
336CFLAGS="$save_CFLAGS $XCFLAGS"
337
338# Check for __sync_val_compare_and_swap, but only after the target has
339# had a chance to set XCFLAGS.
340LIBGOMP_CHECK_SYNC_BUILTINS
341
342XCFLAGS="$XCFLAGS$XPCFLAGS"
343
344# Add CET specific flags if CET is enabled
345GCC_CET_FLAGS(CET_FLAGS)
346XCFLAGS="$XCFLAGS $CET_FLAGS"
347FCFLAGS="$FCFLAGS $CET_FLAGS"
348
349AC_SUBST(config_path)
350AC_SUBST(XCFLAGS)
351AC_SUBST(XLDFLAGS)
352
353# Conditionalize the makefile for this target machine.
354tmake_file_=
355for f in ${tmake_file}
356do
357	if test -f ${srcdir}/config/$f
358	then
359		tmake_file_="${tmake_file_} \$(srcdir)/config/$f"
360	fi
361done
362tmake_file="${tmake_file_}"
363AC_SUBST(tmake_file)
364
365# Cleanup and exit.
366CFLAGS="$save_CFLAGS"
367AC_CACHE_SAVE
368
369if test ${multilib} = yes; then
370  multilib_arg="--enable-multilib"
371else
372  multilib_arg=
373fi
374
375# Set up the set of libraries that we need to link against for libgomp.
376# Note that the GOMP_SELF_SPEC in gcc.c may force -pthread,
377# which will force linkage against -lpthread (or equivalent for the system).
378# That's not 100% ideal, but about the best we can do easily.
379if test $enable_shared = yes; then
380  link_gomp="-lgomp %{static: $LIBS}"
381else
382  link_gomp="-lgomp $LIBS"
383fi
384AC_SUBST(link_gomp)
385
386AM_CONDITIONAL([USE_FORTRAN], [test "$ac_cv_fc_compiler_gnu" = yes])
387
388# ??? 2006-01-24: Paulo committed to asking autoconf folk to document
389# and export AC_COMPUTE_INT.  If that happens, then we'll need to remove
390# the underscore here and update the PREREQ.  If it doesn't, then we'll
391# need to copy this macro to our acinclude.m4.
392save_CFLAGS="$CFLAGS"
393for i in $config_path; do
394  if test -f $srcdir/config/$i/omp-lock.h; then
395    CFLAGS="$CFLAGS -include confdefs.h -include $srcdir/config/$i/omp-lock.h"
396    break
397  fi
398done
399
400_AC_COMPUTE_INT([sizeof (__INTPTR_TYPE__)], [INTPTR_T_KIND])
401_AC_COMPUTE_INT([sizeof (__int128)], [OMP_INT128_SIZE],,[OMP_INT128_SIZE=0])
402_AC_COMPUTE_INT([2*sizeof (__INTPTR_TYPE__)], [OMP_DEPEND_KIND],,
403		[OMP_DEPEND_KIND=0])
404_AC_COMPUTE_INT([sizeof (omp_lock_t)], [OMP_LOCK_SIZE],,
405  [AC_MSG_ERROR([unsupported system, cannot find sizeof (omp_lock_t)])])
406_AC_COMPUTE_INT([__alignof (omp_lock_t)], [OMP_LOCK_ALIGN])
407_AC_COMPUTE_INT([sizeof (omp_nest_lock_t)], [OMP_NEST_LOCK_SIZE])
408_AC_COMPUTE_INT([__alignof (omp_nest_lock_t)], [OMP_NEST_LOCK_ALIGN])
409_AC_COMPUTE_INT([sizeof (omp_lock_25_t)], [OMP_LOCK_25_SIZE],,
410  [AC_MSG_ERROR([unsupported system, cannot find sizeof (omp_lock_25_t)])])
411_AC_COMPUTE_INT([__alignof (omp_lock_25_t)], [OMP_LOCK_25_ALIGN])
412_AC_COMPUTE_INT([sizeof (omp_nest_lock_25_t)], [OMP_NEST_LOCK_25_SIZE])
413_AC_COMPUTE_INT([__alignof (omp_nest_lock_25_t)], [OMP_NEST_LOCK_25_ALIGN])
414
415# If the lock fits in an integer, then arrange for Fortran to use that
416# integer.  If it doesn't, then arrange for Fortran to use a pointer.
417# Except that we don't have a way at present to multi-lib the installed
418# Fortran modules, so we assume 8 bytes for pointers, regardless of the
419# actual target.
420OMP_LOCK_KIND=$OMP_LOCK_SIZE
421OMP_NEST_LOCK_KIND=$OMP_NEST_LOCK_SIZE
422if test $OMP_LOCK_SIZE -gt 8 || test $OMP_LOCK_ALIGN -gt $OMP_LOCK_SIZE; then
423  OMP_LOCK_KIND=8
424fi
425if test $OMP_NEST_LOCK_SIZE -gt 8 || test $OMP_NEST_LOCK_ALIGN -gt $OMP_NEST_LOCK_SIZE; then
426  OMP_NEST_LOCK_KIND=8
427fi
428OMP_LOCK_25_KIND=$OMP_LOCK_25_SIZE
429OMP_NEST_LOCK_25_KIND=$OMP_NEST_LOCK_25_SIZE
430if test $OMP_LOCK_25_SIZE -gt 8 || test $OMP_LOCK_25_ALIGN -gt $OMP_LOCK_25_SIZE; then
431  OMP_LOCK_25_KIND=8
432fi
433if test $OMP_NEST_LOCK_25_SIZE -gt 8 || test $OMP_NEST_LOCK_25_ALIGN -gt $OMP_NEST_LOCK_25_SIZE; then
434  OMP_NEST_LOCK_25_KIND=8
435fi
436if test $OMP_DEPEND_KIND -eq 16; then
437  if test $OMP_INT128_SIZE -ne 16; then
438    AC_MSG_ERROR([unsupported system, cannot find Fortran int kind=16, needed for omp_depend_kind])
439  fi
440else
441  if test $OMP_DEPEND_KIND -ne 8; then
442    AC_MSG_ERROR([unsupported system, cannot find Fortran integer kind for omp_depend_kind])
443  fi
444fi
445
446AC_SUBST(INTPTR_T_KIND)
447AC_SUBST(OMP_LOCK_SIZE)
448AC_SUBST(OMP_LOCK_ALIGN)
449AC_SUBST(OMP_NEST_LOCK_SIZE)
450AC_SUBST(OMP_NEST_LOCK_ALIGN)
451AC_SUBST(OMP_LOCK_KIND)
452AC_SUBST(OMP_NEST_LOCK_KIND)
453AC_SUBST(OMP_LOCK_25_SIZE)
454AC_SUBST(OMP_LOCK_25_ALIGN)
455AC_SUBST(OMP_NEST_LOCK_25_SIZE)
456AC_SUBST(OMP_NEST_LOCK_25_ALIGN)
457AC_SUBST(OMP_LOCK_25_KIND)
458AC_SUBST(OMP_NEST_LOCK_25_KIND)
459AC_SUBST(OMP_DEPEND_KIND)
460CFLAGS="$save_CFLAGS"
461
462# Determine what GCC version number to use in filesystem paths.
463GCC_BASE_VER
464
465AC_CONFIG_FILES(omp.h omp_lib.h omp_lib.f90 libgomp_f.h)
466AC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec)
467AC_CONFIG_FILES([testsuite/libgomp-test-support.pt.exp:testsuite/libgomp-test-support.exp.in])
468AC_CONFIG_FILES([testsuite/libgomp-site-extra.exp])
469AC_OUTPUT
470