]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/plugin/configfrag.ac
Refactor '-ldl' handling for libgomp proper and plugins
[thirdparty/gcc.git] / libgomp / plugin / configfrag.ac
1 # Plugins for offload execution, configure.ac fragment. -*- mode: autoconf -*-
2 #
3 # Copyright (C) 2014-2022 Free Software Foundation, Inc.
4 #
5 # Contributed by Mentor Embedded.
6 #
7 # This file is part of the GNU Offloading and Multi Processing Library
8 # (libgomp).
9 #
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.
14 #
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.
19 #
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.
23 #
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/>.
28
29 plugin_support=yes
30 DL_LIBS=
31 AC_SUBST(DL_LIBS)
32 AC_CHECK_LIB(dl, dlsym, [DL_LIBS=-ldl], [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])
38 fi
39 AC_CHECK_HEADERS_ONCE(unistd.h)
40 AC_CHECK_FUNCS_ONCE(secure_getenv __secure_getenv getuid geteuid getgid getegid)
41
42
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
73 fi
74 if test "x$with_cuda_driver_lib" != x; then
75 CUDA_DRIVER_LIB=$with_cuda_driver_lib
76 fi
77 if test "x$CUDA_DRIVER_INCLUDE" != x \
78 && test "x$CUDA_DRIVER_INCLUDE" != xno; then
79 CUDA_DRIVER_CPPFLAGS=-I$CUDA_DRIVER_INCLUDE
80 fi
81 if test "x$CUDA_DRIVER_LIB" != x \
82 && test "x$CUDA_DRIVER_LIB" != xno; then
83 CUDA_DRIVER_LDFLAGS=-L$CUDA_DRIVER_LIB
84 fi
85
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_CPPFLAGS)
92 AC_SUBST(PLUGIN_NVPTX_LDFLAGS)
93 AC_SUBST(PLUGIN_NVPTX_LIBS)
94
95 PLUGIN_GCN=0
96
97 # Parse '--enable-offload-targets', figure out the corresponding libgomp
98 # plugins, and configure to find the corresponding offload compilers.
99 # 'offload_plugins' and 'offload_targets' will be populated in the same order.
100 offload_plugins=
101 offload_targets=
102 AC_SUBST(offload_plugins)
103 AC_SUBST(offload_targets)
104 offload_additional_options=
105 offload_additional_lib_paths=
106 AC_SUBST(offload_additional_options)
107 AC_SUBST(offload_additional_lib_paths)
108 if test x"$enable_offload_targets" != x; then
109 for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
110 tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
111 tgt=`echo $tgt | sed 's/=.*//'`
112 tgt_plugin=
113 case $tgt in
114 *-intelmic-* | *-intelmicemul-*)
115 tgt_plugin=intelmic
116 ;;
117 nvptx*)
118 case "${target}" in
119 aarch64*-*-* | powerpc64le-*-* | x86_64-*-*)
120 case "$ac_cv_sizeof_void_p" in
121 4)
122 # PR libgomp/65099: Currently, we only support offloading in
123 # 64-bit configurations.
124 PLUGIN_NVPTX=0
125 ;;
126 *)
127 tgt_plugin=nvptx
128 PLUGIN_NVPTX=$tgt
129 if test "x$CUDA_DRIVER_LIB" != xno \
130 && test "x$CUDA_DRIVER_LIB" != xno; then
131 PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
132 PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
133 PLUGIN_NVPTX_LIBS='-lcuda'
134
135 PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
136 CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
137 PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
138 LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
139 PLUGIN_NVPTX_save_LIBS=$LIBS
140 LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
141 AC_LINK_IFELSE(
142 [AC_LANG_PROGRAM(
143 [#include "cuda.h"],
144 [CUresult r = cuCtxPushCurrent (NULL);])],
145 [PLUGIN_NVPTX=1])
146 CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
147 LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
148 LIBS=$PLUGIN_NVPTX_save_LIBS
149 fi
150 case $PLUGIN_NVPTX in
151 nvptx*)
152 if (test "x$CUDA_DRIVER_INCLUDE" = x \
153 || test "x$CUDA_DRIVER_INCLUDE" = xno) \
154 && (test "x$CUDA_DRIVER_LIB" = x \
155 || test "x$CUDA_DRIVER_LIB" = xno); then
156 PLUGIN_NVPTX=1
157 PLUGIN_NVPTX_DYNAMIC=1
158 else
159 PLUGIN_NVPTX=0
160 AC_MSG_ERROR([CUDA driver package required for nvptx support])
161 fi
162 ;;
163 esac
164 ;;
165 esac
166 ;;
167 *-*-*)
168 # Target architecture not supported.
169 PLUGIN_NVPTX=0
170 ;;
171 esac
172 ;;
173 amdgcn*)
174 case "${target}" in
175 x86_64-*-*)
176 case "$ac_cv_sizeof_void_p" in
177 4)
178 PLUGIN_GCN=0
179 ;;
180 *)
181 tgt_plugin=gcn
182 PLUGIN_GCN=1
183 ;;
184 esac
185 ;;
186 *-*-*)
187 PLUGIN_GCN=0
188 ;;
189 esac
190 ;;
191 *)
192 AC_MSG_ERROR([unknown offload target specified])
193 ;;
194 esac
195 if test x"$tgt_plugin" = x; then
196 # Not configuring libgomp for this offload target if we're not building
197 # the corresponding offload plugin.
198 continue
199 elif test x"$offload_plugins" = x; then
200 offload_plugins=$tgt_plugin
201 offload_targets=$tgt
202 else
203 offload_plugins=$offload_plugins,$tgt_plugin
204 offload_targets=$offload_targets,$tgt
205 fi
206 # Configure additional search paths.
207 if test x"$tgt_dir" != x; then
208 offload_additional_options="$offload_additional_options -B$tgt_dir/\$(libexecdir:\$(exec_prefix)/%=%)/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
209 offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
210 else
211 offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
212 offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
213 fi
214 done
215 fi
216 AC_DEFINE_UNQUOTED(OFFLOAD_PLUGINS, "$offload_plugins",
217 [Define to offload plugins, separated by commas.])
218 AM_CONDITIONAL([PLUGIN_NVPTX], [test $PLUGIN_NVPTX = 1])
219 AM_CONDITIONAL([PLUGIN_NVPTX_DYNAMIC], [test $PLUGIN_NVPTX_DYNAMIC = 1])
220 AM_CONDITIONAL([PLUGIN_GCN], [test $PLUGIN_GCN = 1])