1 #**************************************************************************
2 #* *
3 #* OCaml *
4 #* *
5 #* Sebastien Hinderer, projet Gallium, INRIA Paris *
6 #* *
7 #* Copyright 2018 Institut National de Recherche en Informatique et *
8 #* en Automatique. *
9 #* *
10 #* All rights reserved. This file is distributed under the terms of *
11 #* the GNU Lesser General Public License version 2.1, with the *
12 #* special exception on linking described in the file LICENSE. *
13 #* *
14 #**************************************************************************
15
16 # This file is processed by autoconf.
17 # It contains macro definitions specific to the OCaml package.
18 # Every macro defined here should have its name prefixed with OCAML_.
19
20 # libtool macros
21
22 # Since the project does not use automake, the libtool macro files
23 # need to be manually included
24 m4_include([build-aux/libtool.m4])
25 m4_include([build-aux/ltoptions.m4])
26 m4_include([build-aux/ltsugar.m4])
27 m4_include([build-aux/ltversion.m4])
28 m4_include([build-aux/lt~obsolete.m4])
29
30 # Macros from the autoconf macro archive
31 m4_include([build-aux/ax_func_which_gethostbyname_r.m4])
32 m4_include([build-aux/ax_pthread.m4])
33
34 # The following macro figures out which C compiler is used.
35 # It does so by checking for compiler-specific predefined macros.
36 # A list of such macros can be found at
37 # https://sourceforge.net/p/predef/wiki/Compilers/
38 AC_DEFUN([OCAML_CC_VENDOR], [
39 AC_REQUIRE([AC_PROG_CC])
40 AC_REQUIRE([AC_PROG_CPP])
41 AC_MSG_CHECKING([C compiler vendor])
42 AC_PREPROC_IFELSE(
43 [AC_LANG_SOURCE([
44 #if defined(_MSC_VER)
45 msvc _MSC_VER
46 #elif defined(__INTEL_COMPILER)
47 icc __INTEL_COMPILER
48 #elif defined(__clang_major__) && defined(__clang_minor__)
49 clang __clang_major__ __clang_minor__
50 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
51 gcc __GNUC__ __GNUC_MINOR__
52 #elif defined(__xlc__) && defined(__xlC__)
53 xlc __xlC__ __xlC_ver__
54 #else
55 unknown
56 #endif]
57 )],
58 [AC_CACHE_VAL([ocaml_cv_cc_vendor],
59 [ocaml_cv_cc_vendor=`grep ['^[a-z]'] conftest.i | tr -s ' ' '-'`])],
60 [AC_MSG_FAILURE([unexpected preprocessor failure])])
61 AC_MSG_RESULT([$ocaml_cv_cc_vendor])
62 ])
63
64 AC_DEFUN([OCAML_SIGNAL_HANDLERS_SEMANTICS], [
65 AC_MSG_NOTICE([checking semantics of signal handlers])
66 AC_CHECK_FUNC([sigaction], [has_sigaction=true], [has_sigaction=false])
67 AC_CHECK_FUNC([sigprocmask], [has_sigprocmask=true], [has_sigprocmask=false])
68 AS_IF([$has_sigaction && $has_sigprocmask],
69 [AC_DEFINE([POSIX_SIGNALS])
70 AC_MSG_NOTICE([POSIX signal handling found.])],
71 [AC_MSG_NOTICE([assuming signals have the System V semantics.])
72 ]
73 )
74 ])
75
76 AC_DEFUN([OCAML_CC_HAS_FNO_TREE_VRP], [
77 AC_MSG_CHECKING([whether the C compiler supports -fno-tree-vrp])
78 saved_CFLAGS="$CFLAGS"
79 CFLAGS="-Werror -fno-tree-vrp $CFLAGS"
80 AC_COMPILE_IFELSE(
81 [AC_LANG_SOURCE([int main() { return 0; }])],
82 [cc_has_fno_tree_vrp=true
83 AC_MSG_RESULT([yes])],
84 [cc_has_fno_tree_vrp=false
85 AC_MSG_RESULT([no])])
86 CFLAGS="$saved_CFLAGS"
87 ])
88
89 AC_DEFUN([OCAML_CC_SUPPORTS_ALIGNED], [
90 AC_MSG_CHECKING([whether the C compiler supports __attribute__((aligned(n)))])
91 AC_COMPILE_IFELSE(
92 [AC_LANG_SOURCE([typedef struct {__attribute__((aligned(8))) int t;} t;])],
93 [AC_DEFINE([SUPPORTS_ALIGNED_ATTRIBUTE])
94 AC_MSG_RESULT([yes])],
95 [AC_MSG_RESULT([no])])])
96
97 AC_DEFUN([OCAML_CC_HAS_DEBUG_PREFIX_MAP], [
98 AC_MSG_CHECKING([whether the C compiler supports -fdebug-prefix-map])
99 saved_CFLAGS="$CFLAGS"
100 CFLAGS="-fdebug-prefix-map=old=new $CFLAGS"
101 AC_COMPILE_IFELSE(
102 [AC_LANG_SOURCE([int main() { return 0; }])],
103 [cc_has_debug_prefix_map=true
104 AC_MSG_RESULT([yes])],
105 [cc_has_debug_prefix_map=false
106 AC_MSG_RESULT([no])])
107 CFLAGS="$saved_CFLAGS"
108 ])
109
110 # Save C compiler related variables
111 AC_DEFUN([OCAML_CC_SAVE_VARIABLES], [
112 saved_CC="$CC"
113 saved_CFLAGS="$CFLAGS"
114 saved_CPPFLAGS="$CPPFLAGS"
115 saved_ac_ext="$ac_ext"
116 saved_ac_compile="$ac_compile"
117 # Move the content of confdefs.h to another file so it does not
118 # get included
119 mv confdefs.h confdefs.h.bak
120 touch confdefs.h
121 ])
122
123 # Restore the C compiler related variables
124 AC_DEFUN([OCAML_CC_RESTORE_VARIABLES], [
125 # Restore the content of confdefs.h
126 mv confdefs.h.bak confdefs.h
127 ac_compile="$saved_ac_compile"
128 ac_ext="$saved_ac_ext"
129 CPPFLAGS="$saved_CPPFLAGS"
130 CFLAGS="$saved_CFLAGS"
131 CC="$saved_CC"
132 ])
133
134 AC_DEFUN([OCAML_AS_HAS_DEBUG_PREFIX_MAP], [
135 AC_MSG_CHECKING([whether the assembler supports --debug-prefix-map])
136
137 OCAML_CC_SAVE_VARIABLES
138
139 # Modify C-compiler variables to use the assembler
140 CC="$AS"
141 CFLAGS="--debug-prefix-map old=new -o conftest.$ac_objext"
142 CPPFLAGS=""
143 ac_ext="S"
144 ac_compile='$CC $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
145
146 AC_COMPILE_IFELSE(
147 [AC_LANG_SOURCE([
148 camlPervasives__loop_1128:
149 .file 1 "pervasives.ml"
150 .loc 1 193
151 ])],
152 [as_has_debug_prefix_map=true
153 AC_MSG_RESULT([yes])],
154 [ashas_debug_prefix_map=false
155 AC_MSG_RESULT([no])])
156
157 OCAML_CC_RESTORE_VARIABLES
158 ])
159
160 AC_DEFUN([OCAML_AS_HAS_CFI_DIRECTIVES], [
161 AC_MSG_CHECKING([whether the assembler supports CFI directives])
162
163 AS_IF([test x"$enable_cfi" = "xno"],
164 [AC_MSG_RESULT([disabled])],
165 [OCAML_CC_SAVE_VARIABLES
166
167 # Modify C-compiler variables to use the assembler
168 CC="$ASPP"
169 CFLAGS="-o conftest.$ac_objext"
170 CPPFLAGS=""
171 ac_ext="S"
172 ac_compile='$CC $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
173
174 AC_COMPILE_IFELSE(
175 [AC_LANG_SOURCE([
176 camlPervasives__loop_1128:
177 .file 1 "pervasives.ml"
178 .loc 1 193
179 .cfi_startproc
180 .cfi_adjust_cfa_offset 8
181 .cfi_endproc
182 ])],
183 [aspp_ok=true],
184 [aspp_ok=false])
185
186 AS_IF([test "$AS" = "$ASPP"],
187 [as_ok="$aspp_ok"],
188 [CC="$AS"
189 ac_compile='$CC $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
190 AC_COMPILE_IFELSE(
191 [AC_LANG_SOURCE([
192 camlPervasives__loop_1128:
193 .file 1 "pervasives.ml"
194 .loc 1 193
195 .cfi_startproc
196 .cfi_adjust_cfa_offset 8
197 .cfi_endproc
198 ])],
199 [as_ok=true],
200 [as_ok=false])])
201
202 OCAML_CC_RESTORE_VARIABLES
203
204 AS_IF([$aspp_ok && $as_ok],
205 [asm_cfi_supported=true
206 AC_DEFINE([ASM_CFI_SUPPORTED])
207 AC_MSG_RESULT([yes])],
208 [AS_IF([test x"$enable_cfi" = "xyes"],
209 [AC_MSG_RESULT([requested but not available
210 AC_MSG_ERROR([exiting])])],
211 [asm_cfi_supported=false
212 AC_MSG_RESULT([no])])])
213 ])])
214
215 AC_DEFUN([OCAML_MMAP_SUPPORTS_HUGE_PAGES], [
216 AC_MSG_CHECKING([whether mmap supports huge pages])
217 AC_RUN_IFELSE(
218 [AC_LANG_SOURCE([[
219 #include <sys/mman.h>
220 #include <stdio.h>
221 #include <stdlib.h>
222
223 #define huge_page_size (4 * 1024 * 1024)
224
225 /* Test for the possible availability of huge pages. Answer yes
226 if the OS knows about huge pages, even if they are not available
227 on the build machine at configure time, because (on Linux) huge
228 pages can be activated and deactivated easily while the system
229 is running.
230 */
231
232 int main (int argc, char *argv[]){
233 void *block;
234 char *p;
235 int i, res;
236 block = mmap (NULL, huge_page_size, PROT_READ | PROT_WRITE,
237 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
238 -1, 0);
239 if (block == MAP_FAILED){
240 block = mmap (NULL, huge_page_size, PROT_READ | PROT_WRITE,
241 MAP_PRIVATE | MAP_ANONYMOUS,
242 -1, 0);
243 }
244 if (block == MAP_FAILED){
245 perror ("mmap");
246 return 3;
247 }
248 /*printf ("block = %p\n", block);*/
249 p = (char *) block;
250 for (i = 0; i < huge_page_size; i += 4096){
251 p[i] = (char) i;
252 }
253 return 0;
254 }
255 ]])],
256 [AC_DEFINE([HAS_HUGE_PAGES])
257 AC_DEFINE_UNQUOTED([HUGE_PAGE_SIZE], [(4 * 1024 * 1024)])
258 AC_MSG_RESULT([yes])],
259 [AC_MSG_RESULT([no])],
260 [AC_MSG_RESULT([no assumed])])
261 ])
262
263 AC_DEFUN([OCAML_CHECK_LIBUNWIND], [
264 SAVED_CFLAGS="$CFLAGS"
265 SAVED_LDFLAGS="$LDFLAGS"
266 CFLAGS="$CFLAGS $libunwind_include_flags"
267 LDFLAGS="$LDFLAGS $libunwind_link_flags"
268 AC_CHECK_HEADER([libunwind.h],
269 [AC_DEFINE([HAS_LIBUNWIND])
270 libunwind_available=true],
271 [libunwind_available=false])
272 LDFLAGS="$SAVED_LDFLAGS"
273 CFLAGS="$SAVED_CFLAGS"
274 ])
275