Formatted printing for dump_* in the middle-end
[official-gcc.git] / libgomp / plugin / configfrag.ac
bloba979425a293b62af68ee4946d2702fa6277e1d0d
1 # Plugins for offload execution, configure.ac fragment.  -*- mode: autoconf -*-
3 # Copyright (C) 2014-2018 Free Software Foundation, Inc.
5 # Contributed by Mentor Embedded.
7 # This file is part of the GNU Offloading and Multi Processing Library
8 # (libgomp).
10 # Libgomp is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3, or (at your option)
13 # any later version.
15 # Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18 # more details.
20 # Under Section 7 of GPL version 3, you are granted additional
21 # permissions described in the GCC Runtime Library Exception, version
22 # 3.1, as published by the Free Software Foundation.
24 # You should have received a copy of the GNU General Public License and
25 # a copy of the GCC Runtime Library Exception along with this program;
26 # see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
27 # <http://www.gnu.org/licenses/>.
29 offload_targets=
30 AC_SUBST(offload_targets)
31 plugin_support=yes
32 AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
33 if test x"$plugin_support" = xyes; then
34   AC_DEFINE(PLUGIN_SUPPORT, 1,
35     [Define if all infrastructure, needed for plugins, is supported.])
36 elif test "x${enable_offload_targets-no}" != xno; then
37   AC_MSG_ERROR([Can't support offloading without support for plugins])
39 AC_CHECK_HEADERS_ONCE(unistd.h)
40 AC_CHECK_FUNCS_ONCE(secure_getenv __secure_getenv getuid geteuid getgid getegid)
43 # Look for the CUDA driver package.
44 CUDA_DRIVER_INCLUDE=
45 CUDA_DRIVER_LIB=
46 AC_SUBST(CUDA_DRIVER_INCLUDE)
47 AC_SUBST(CUDA_DRIVER_LIB)
48 CUDA_DRIVER_CPPFLAGS=
49 CUDA_DRIVER_LDFLAGS=
50 AC_ARG_WITH(cuda-driver,
51         [AS_HELP_STRING([--with-cuda-driver=PATH],
52                 [specify prefix directory for installed CUDA driver package.
53                  Equivalent to --with-cuda-driver-include=PATH/include
54                  plus --with-cuda-driver-lib=PATH/lib])])
55 AC_ARG_WITH(cuda-driver-include,
56         [AS_HELP_STRING([--with-cuda-driver-include=PATH],
57                 [specify directory for installed CUDA driver include files])])
58 AC_ARG_WITH(cuda-driver-lib,
59         [AS_HELP_STRING([--with-cuda-driver-lib=PATH],
60                 [specify directory for the installed CUDA driver library])])
61 case "x$with_cuda_driver" in
62   x) ;;
63   xno)
64     CUDA_DRIVER_INCLUDE=no
65     CUDA_DRIVER_LIB=no
66     ;;
67   *) CUDA_DRIVER_INCLUDE=$with_cuda_driver/include
68      CUDA_DRIVER_LIB=$with_cuda_driver/lib
69      ;;
70 esac
71 if test "x$with_cuda_driver_include" != x; then
72   CUDA_DRIVER_INCLUDE=$with_cuda_driver_include
74 if test "x$with_cuda_driver_lib" != x; then
75   CUDA_DRIVER_LIB=$with_cuda_driver_lib
77 if test "x$CUDA_DRIVER_INCLUDE" != x \
78    && test "x$CUDA_DRIVER_INCLUDE" != xno; then
79   CUDA_DRIVER_CPPFLAGS=-I$CUDA_DRIVER_INCLUDE
81 if test "x$CUDA_DRIVER_LIB" != x \
82    && test "x$CUDA_DRIVER_LIB" != xno; then
83   CUDA_DRIVER_LDFLAGS=-L$CUDA_DRIVER_LIB
86 PLUGIN_NVPTX=0
87 PLUGIN_NVPTX_CPPFLAGS=
88 PLUGIN_NVPTX_LDFLAGS=
89 PLUGIN_NVPTX_LIBS=
90 PLUGIN_NVPTX_DYNAMIC=0
91 AC_SUBST(PLUGIN_NVPTX)
92 AC_SUBST(PLUGIN_NVPTX_CPPFLAGS)
93 AC_SUBST(PLUGIN_NVPTX_LDFLAGS)
94 AC_SUBST(PLUGIN_NVPTX_LIBS)
96 # Look for HSA run-time, its includes and libraries
98 HSA_RUNTIME_INCLUDE=
99 HSA_RUNTIME_LIB=
100 AC_SUBST(HSA_RUNTIME_INCLUDE)
101 AC_SUBST(HSA_RUNTIME_LIB)
102 HSA_RUNTIME_CPPFLAGS=
103 HSA_RUNTIME_LDFLAGS=
105 AC_ARG_WITH(hsa-runtime,
106         [AS_HELP_STRING([--with-hsa-runtime=PATH],
107                 [specify prefix directory for installed HSA run-time package.
108                  Equivalent to --with-hsa-runtime-include=PATH/include
109                  plus --with-hsa-runtime-lib=PATH/lib])])
110 AC_ARG_WITH(hsa-runtime-include,
111         [AS_HELP_STRING([--with-hsa-runtime-include=PATH],
112                 [specify directory for installed HSA run-time include files])])
113 AC_ARG_WITH(hsa-runtime-lib,
114         [AS_HELP_STRING([--with-hsa-runtime-lib=PATH],
115                 [specify directory for the installed HSA run-time library])])
116 if test "x$with_hsa_runtime" != x; then
117   HSA_RUNTIME_INCLUDE=$with_hsa_runtime/include
118   HSA_RUNTIME_LIB=$with_hsa_runtime/lib
120 if test "x$with_hsa_runtime_include" != x; then
121   HSA_RUNTIME_INCLUDE=$with_hsa_runtime_include
123 if test "x$with_hsa_runtime_lib" != x; then
124   HSA_RUNTIME_LIB=$with_hsa_runtime_lib
126 if test "x$HSA_RUNTIME_INCLUDE" != x; then
127   HSA_RUNTIME_CPPFLAGS=-I$HSA_RUNTIME_INCLUDE
129 if test "x$HSA_RUNTIME_LIB" != x; then
130   HSA_RUNTIME_LDFLAGS=-L$HSA_RUNTIME_LIB
133 PLUGIN_HSA=0
134 PLUGIN_HSA_CPPFLAGS=
135 PLUGIN_HSA_LDFLAGS=
136 PLUGIN_HSA_LIBS=
137 AC_SUBST(PLUGIN_HSA)
138 AC_SUBST(PLUGIN_HSA_CPPFLAGS)
139 AC_SUBST(PLUGIN_HSA_LDFLAGS)
140 AC_SUBST(PLUGIN_HSA_LIBS)
142 # Get offload targets and path to install tree of offloading compiler.
143 offload_additional_options=
144 offload_additional_lib_paths=
145 AC_SUBST(offload_additional_options)
146 AC_SUBST(offload_additional_lib_paths)
147 if test x"$enable_offload_targets" != x; then
148   for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
149     tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
150     tgt=`echo $tgt | sed 's/=.*//'`
151     tgt_name=
152     case $tgt in
153       *-intelmic-* | *-intelmicemul-*)
154         tgt_name=intelmic
155         ;;
156       nvptx*)
157         tgt_name=nvptx
158         PLUGIN_NVPTX=$tgt
159         if test "x$CUDA_DRIVER_LIB" != xno \
160            && test "x$CUDA_DRIVER_LIB" != xno; then
161           PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
162           PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
163           PLUGIN_NVPTX_LIBS='-lcuda'
165           PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
166           CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
167           PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
168           LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
169           PLUGIN_NVPTX_save_LIBS=$LIBS
170           LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
171           AC_LINK_IFELSE(
172             [AC_LANG_PROGRAM(
173               [#include "cuda.h"],
174                 [CUresult r = cuCtxPushCurrent (NULL);])],
175             [PLUGIN_NVPTX=1])
176           CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
177           LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
178           LIBS=$PLUGIN_NVPTX_save_LIBS
179         fi
180         case $PLUGIN_NVPTX in
181           nvptx*)
182             if (test "x$CUDA_DRIVER_INCLUDE" = x \
183                 || test "x$CUDA_DRIVER_INCLUDE" = xno) \
184                && (test "x$CUDA_DRIVER_LIB" = x \
185                    || test "x$CUDA_DRIVER_LIB" = xno); then
186               PLUGIN_NVPTX=1
187               PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
188               PLUGIN_NVPTX_LIBS='-ldl'
189               PLUGIN_NVPTX_DYNAMIC=1
190             else
191               PLUGIN_NVPTX=0
192               AC_MSG_ERROR([CUDA driver package required for nvptx support])
193             fi
194           ;;
195         esac
196         ;;
197       hsa*)
198         case "${target}" in
199           x86_64-*-*)
200             case " ${CC} ${CFLAGS} " in
201               *" -m32 "*)
202                 PLUGIN_HSA=0
203                 ;;
204               *)
205                 tgt_name=hsa
206                 PLUGIN_HSA=$tgt
207                 PLUGIN_HSA_CPPFLAGS=$HSA_RUNTIME_CPPFLAGS
208                 PLUGIN_HSA_LDFLAGS="$HSA_RUNTIME_LDFLAGS"
209                 PLUGIN_HSA_LIBS="-ldl"
211                 PLUGIN_HSA_save_CPPFLAGS=$CPPFLAGS
212                 CPPFLAGS="$PLUGIN_HSA_CPPFLAGS $CPPFLAGS"
213                 PLUGIN_HSA_save_LDFLAGS=$LDFLAGS
214                 LDFLAGS="$PLUGIN_HSA_LDFLAGS $LDFLAGS"
215                 PLUGIN_HSA_save_LIBS=$LIBS
216                 LIBS="$PLUGIN_HSA_LIBS $LIBS"
218                 PLUGIN_HSA=1
219                 CPPFLAGS=$PLUGIN_HSA_save_CPPFLAGS
220                 LDFLAGS=$PLUGIN_HSA_save_LDFLAGS
221                 LIBS=$PLUGIN_HSA_save_LIBS
222                 case $PLUGIN_HSA in
223                   hsa*)
224                     HSA_PLUGIN=0
225                     AC_MSG_ERROR([HSA run-time package required for HSA support])
226                     ;;
227                 esac
228                 ;;
229               esac
230             ;;
231           *-*-*)
232             PLUGIN_HSA=0
233             ;;
234         esac
235         ;;
236       *)
237         AC_MSG_ERROR([unknown offload target specified])
238         ;;
239     esac
240     if test x"$tgt_name" = x; then
241       # Don't configure libgomp for this offloading target if we don't build
242       # the corresponding plugin.
243       continue
244     elif test x"$offload_targets" = x; then
245       offload_targets=$tgt_name
246     else
247       offload_targets=$offload_targets,$tgt_name
248     fi
249     if test "$tgt_name" = hsa; then
250       # Offloading compilation is all handled by the target compiler.
251       :
252     elif test x"$tgt_dir" != x; then
253       offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
254       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
255     else
256       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
257       offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
258     fi
259   done
261 AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
262   [Define to offload targets, separated by commas.])
263 AM_CONDITIONAL([PLUGIN_NVPTX], [test $PLUGIN_NVPTX = 1])
264 AC_DEFINE_UNQUOTED([PLUGIN_NVPTX], [$PLUGIN_NVPTX],
265   [Define to 1 if the NVIDIA plugin is built, 0 if not.])
266 AC_DEFINE_UNQUOTED([PLUGIN_NVPTX_DYNAMIC], [$PLUGIN_NVPTX_DYNAMIC],
267   [Define to 1 if the NVIDIA plugin should dlopen libcuda.so.1, 0 if it should be linked against it.])
268 AM_CONDITIONAL([PLUGIN_HSA], [test $PLUGIN_HSA = 1])
269 AC_DEFINE_UNQUOTED([PLUGIN_HSA], [$PLUGIN_HSA],
270   [Define to 1 if the HSA plugin is built, 0 if not.])
272 if test "$HSA_RUNTIME_LIB" != ""; then
273   HSA_RUNTIME_LIB="$HSA_RUNTIME_LIB/"
276 AC_DEFINE_UNQUOTED([HSA_RUNTIME_LIB], ["$HSA_RUNTIME_LIB"],
277   [Define path to HSA runtime.])