1 #
  2 # Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 ###############################################################################
 27 # Set the debug level
 28 #    release: no debug information, all optimizations, no asserts.
 29 #    optimized: no debug information, all optimizations, no asserts, HotSpot target is 'optimized'.
 30 #    fastdebug: debug information (-g), all optimizations, all asserts
 31 #    slowdebug: debug information (-g), no optimizations, all asserts
 32 AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_LEVEL],
 33 [
 34   DEBUG_LEVEL="release"
 35 
 36   UTIL_ARG_ENABLE(NAME: debug, DEFAULT: false, RESULT: ENABLE_DEBUG,
 37       DESC: [enable debugging (shorthand for --with-debug-level=fastdebug)],
 38       IF_ENABLED: [ DEBUG_LEVEL="fastdebug" ])
 39 
 40   AC_MSG_CHECKING([which debug level to use])
 41   AC_ARG_WITH([debug-level], [AS_HELP_STRING([--with-debug-level],
 42       [set the debug level (release, fastdebug, slowdebug, optimized) @<:@release@:>@])],
 43       [
 44         DEBUG_LEVEL="${withval}"
 45         if test "x$ENABLE_DEBUG" = xtrue; then
 46           AC_MSG_ERROR([You cannot use both --enable-debug and --with-debug-level at the same time.])
 47         fi
 48       ])
 49   AC_MSG_RESULT([$DEBUG_LEVEL])
 50 
 51   if test "x$DEBUG_LEVEL" != xrelease && \
 52       test "x$DEBUG_LEVEL" != xoptimized && \
 53       test "x$DEBUG_LEVEL" != xfastdebug && \
 54       test "x$DEBUG_LEVEL" != xslowdebug; then
 55     AC_MSG_ERROR([Allowed debug levels are: release, fastdebug, slowdebug and optimized])
 56   fi
 57 
 58   # Translate DEBUG_LEVEL to debug level used by Hotspot
 59   HOTSPOT_DEBUG_LEVEL="$DEBUG_LEVEL"
 60   if test "x$DEBUG_LEVEL" = xrelease; then
 61     HOTSPOT_DEBUG_LEVEL="product"
 62   elif test "x$DEBUG_LEVEL" = xslowdebug; then
 63     HOTSPOT_DEBUG_LEVEL="debug"
 64   fi
 65 
 66   if test "x$DEBUG_LEVEL" = xoptimized; then
 67     # The debug level 'optimized' is a little special because it is currently only
 68     # applicable to the HotSpot build where it means to build a completely
 69     # optimized version of the VM without any debugging code (like for the
 70     # 'release' debug level which is called 'product' in the HotSpot build) but
 71     # with the exception that it can contain additional code which is otherwise
 72     # protected by '#ifndef PRODUCT' macros. These 'optimized' builds are used to
 73     # test new and/or experimental features which are not intended for customer
 74     # shipment. Because these new features need to be tested and benchmarked in
 75     # real world scenarios, we want to build the containing JDK at the 'release'
 76     # debug level.
 77     DEBUG_LEVEL="release"
 78   fi
 79 
 80   AC_SUBST(HOTSPOT_DEBUG_LEVEL)
 81   AC_SUBST(DEBUG_LEVEL)
 82 ])
 83 
 84 ###############################################################################
 85 #
 86 # Should we build only OpenJDK even if closed sources are present?
 87 #
 88 AC_DEFUN_ONCE([JDKOPT_SETUP_OPEN_OR_CUSTOM],
 89 [
 90   UTIL_ARG_ENABLE(NAME: openjdk-only, DEFAULT: false,
 91       RESULT: SUPPRESS_CUSTOM_EXTENSIONS,
 92       DESC: [suppress building custom source even if present],
 93       CHECKING_MSG: [if custom source is suppressed (openjdk-only)])
 94 ])
 95 
 96 AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
 97 [
 98   # Should we build a JDK without a graphical UI?
 99   UTIL_ARG_ENABLE(NAME: headless-only, DEFAULT: false,
100       RESULT: ENABLE_HEADLESS_ONLY,
101       DESC: [only build headless (no GUI) support],
102       CHECKING_MSG: [if we should build headless-only (no GUI)])
103   AC_SUBST(ENABLE_HEADLESS_ONLY)
104 
105   # should we linktime gc unused code sections in the JDK build ?
106   if test "x$OPENJDK_TARGET_OS" = "xlinux" && test "x$OPENJDK_TARGET_CPU" = xs390x; then
107     LINKTIME_GC_DEFAULT=true
108   else
109     LINKTIME_GC_DEFAULT=false
110   fi
111 
112   UTIL_ARG_ENABLE(NAME: linktime-gc, DEFAULT: $LINKTIME_GC_DEFAULT,
113       DEFAULT_DESC: [auto], RESULT: ENABLE_LINKTIME_GC,
114       DESC: [use link time gc on unused code sections in the JDK build],
115       CHECKING_MSG: [if linker should clean out unused code (linktime-gc)])
116   AC_SUBST(ENABLE_LINKTIME_GC)
117 
118   # Check for full doc dependencies
119   FULL_DOCS_AVAILABLE=true
120   AC_MSG_CHECKING([for graphviz dot])
121   if test "x$DOT" != "x"; then
122     AC_MSG_RESULT([yes])
123   else
124     AC_MSG_RESULT([no, cannot generate full docs])
125     FULL_DOCS_AVAILABLE=false
126   fi
127 
128   AC_MSG_CHECKING([for pandoc])
129   if test "x$ENABLE_PANDOC" = "xtrue"; then
130     AC_MSG_RESULT([yes])
131   else
132     AC_MSG_RESULT([no, cannot generate full docs])
133     FULL_DOCS_AVAILABLE=false
134   fi
135 
136   # Should we build the complete docs, or just a lightweight version?
137   UTIL_ARG_ENABLE(NAME: full-docs, DEFAULT: auto, RESULT: ENABLE_FULL_DOCS,
138       AVAILABLE: $FULL_DOCS_AVAILABLE, DESC: [build complete documentation],
139       DEFAULT_DESC: [enabled if all tools found])
140   AC_SUBST(ENABLE_FULL_DOCS)
141 
142   # Choose cacerts source file
143   AC_ARG_WITH(cacerts-file, [AS_HELP_STRING([--with-cacerts-file],
144       [specify alternative cacerts file])])
145   AC_MSG_CHECKING([for cacerts file])
146   if test "x$with_cacerts_file" == x; then
147     AC_MSG_RESULT([default])
148   else
149     CACERTS_FILE=$with_cacerts_file
150     if test ! -f "$CACERTS_FILE"; then
151       AC_MSG_RESULT([fail])
152       AC_MSG_ERROR([Specified cacerts file "$CACERTS_FILE" does not exist])
153     fi
154     AC_MSG_RESULT([$CACERTS_FILE])
155   fi
156   AC_SUBST(CACERTS_FILE)
157 
158   # Choose cacerts source folder for user provided PEM files
159   AC_ARG_WITH(cacerts-src, [AS_HELP_STRING([--with-cacerts-src],
160       [specify alternative cacerts source folder containing certificates])])
161   CACERTS_SRC=""
162   AC_MSG_CHECKING([for cacerts source])
163   if test "x$with_cacerts_src" == x; then
164     AC_MSG_RESULT([default])
165   else
166     CACERTS_SRC=$with_cacerts_src
167     if test ! -d "$CACERTS_SRC"; then
168       AC_MSG_RESULT([fail])
169       AC_MSG_ERROR([Specified cacerts source folder "$CACERTS_SRC" does not exist])
170     fi
171     AC_MSG_RESULT([$CACERTS_SRC])
172   fi
173   AC_SUBST(CACERTS_SRC)
174 
175   # Enable or disable unlimited crypto
176   UTIL_ARG_ENABLE(NAME: unlimited-crypto, DEFAULT: true, RESULT: UNLIMITED_CRYPTO,
177       DESC: [enable unlimited crypto policy])
178   AC_SUBST(UNLIMITED_CRYPTO)
179 
180   # Should we build the serviceability agent (SA)?
181   INCLUDE_SA=true
182   if HOTSPOT_CHECK_JVM_VARIANT(zero); then
183     INCLUDE_SA=false
184   fi
185   if test "x$OPENJDK_TARGET_OS" = xaix ; then
186     INCLUDE_SA=false
187   fi
188   if test "x$OPENJDK_TARGET_CPU" = xs390x ; then
189     INCLUDE_SA=false
190   fi
191   AC_SUBST(INCLUDE_SA)
192 
193   # Compress jars
194   COMPRESS_JARS=false
195 
196   AC_SUBST(COMPRESS_JARS)
197 
198   # Setup default copyright year. Mostly overridden when building close to a new year.
199   AC_ARG_WITH(copyright-year, [AS_HELP_STRING([--with-copyright-year],
200       [Set copyright year value for build @<:@current year/source-date@:>@])])
201   if test "x$with_copyright_year" = xyes; then
202     AC_MSG_ERROR([Copyright year must have a value])
203   elif test "x$with_copyright_year" != x; then
204     COPYRIGHT_YEAR="$with_copyright_year"
205   elif test "x$SOURCE_DATE" != xupdated; then
206     if test "x$IS_GNU_DATE" = xyes; then
207       COPYRIGHT_YEAR=`$DATE --date=@$SOURCE_DATE +%Y`
208     else
209       COPYRIGHT_YEAR=`$DATE -j -f %s $SOURCE_DATE +%Y`
210     fi
211   else
212     COPYRIGHT_YEAR=`$DATE +'%Y'`
213   fi
214   AC_SUBST(COPYRIGHT_YEAR)
215 
216   # Override default library path
217   AC_ARG_WITH([jni-libpath], [AS_HELP_STRING([--with-jni-libpath],
218       [override default JNI library search path])])
219   AC_MSG_CHECKING([for jni library path])
220   if test "x${with_jni_libpath}" = "x" || test "x${with_jni_libpath}" = "xno"; then
221     AC_MSG_RESULT([default])
222   elif test "x${with_jni_libpath}" = "xyes"; then
223     AC_MSG_RESULT([invalid])
224     AC_MSG_ERROR([The --with-jni-libpath option requires an argument.])
225   else
226     HOTSPOT_OVERRIDE_LIBPATH=${with_jni_libpath}
227     if test "x$OPENJDK_TARGET_OS" != "xlinux" &&
228          test "x$OPENJDK_TARGET_OS" != "xbsd" &&
229          test "x$OPENJDK_TARGET_OS" != "xaix"; then
230       AC_MSG_RESULT([fail])
231       AC_MSG_ERROR([Overriding JNI library path is supported only on Linux, BSD and AIX.])
232     fi
233     AC_MSG_RESULT(${HOTSPOT_OVERRIDE_LIBPATH})
234   fi
235   AC_SUBST(HOTSPOT_OVERRIDE_LIBPATH)
236 
237 ])
238 
239 ###############################################################################
240 
241 AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_SYMBOLS],
242 [
243   #
244   # Native debug symbols.
245   # This must be done after the toolchain is setup, since we're looking at objcopy.
246   #
247   AC_MSG_CHECKING([what type of native debug symbols to use])
248   AC_ARG_WITH([native-debug-symbols],
249       [AS_HELP_STRING([--with-native-debug-symbols],
250       [set the native debug symbol configuration (none, internal, external, zipped) @<:@varying@:>@])],
251       [
252         if test "x$OPENJDK_TARGET_OS" = xwindows; then
253           if test "x$withval" = xinternal; then
254             AC_MSG_ERROR([Windows does not support the parameter 'internal' for --with-native-debug-symbols])
255           fi
256         fi
257       ],
258       [
259         if test "x$STATIC_BUILD" = xtrue; then
260           with_native_debug_symbols="none"
261         else
262           with_native_debug_symbols="external"
263         fi
264       ])
265   AC_MSG_RESULT([$with_native_debug_symbols])
266 
267   if test "x$with_native_debug_symbols" = xnone; then
268     COMPILE_WITH_DEBUG_SYMBOLS=false
269     COPY_DEBUG_SYMBOLS=false
270     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
271   elif test "x$with_native_debug_symbols" = xinternal; then
272     COMPILE_WITH_DEBUG_SYMBOLS=true
273     COPY_DEBUG_SYMBOLS=false
274     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
275   elif test "x$with_native_debug_symbols" = xexternal; then
276 
277     if test "x$OPENJDK_TARGET_OS" = xlinux; then
278       if test "x$OBJCOPY" = x; then
279         # enabling of enable-debug-symbols and can't find objcopy
280         # this is an error
281         AC_MSG_ERROR([Unable to find objcopy, cannot enable native debug symbols])
282       fi
283     fi
284 
285     COMPILE_WITH_DEBUG_SYMBOLS=true
286     COPY_DEBUG_SYMBOLS=true
287     ZIP_EXTERNAL_DEBUG_SYMBOLS=false
288   elif test "x$with_native_debug_symbols" = xzipped; then
289 
290     if test "x$OPENJDK_TARGET_OS" = xlinux; then
291       if test "x$OBJCOPY" = x; then
292         # enabling of enable-debug-symbols and can't find objcopy
293         # this is an error
294         AC_MSG_ERROR([Unable to find objcopy, cannot enable native debug symbols])
295       fi
296     fi
297 
298     COMPILE_WITH_DEBUG_SYMBOLS=true
299     COPY_DEBUG_SYMBOLS=true
300     ZIP_EXTERNAL_DEBUG_SYMBOLS=true
301   else
302     AC_MSG_ERROR([Allowed native debug symbols are: none, internal, external, zipped])
303   fi
304 
305   AC_SUBST(COMPILE_WITH_DEBUG_SYMBOLS)
306   AC_SUBST(COPY_DEBUG_SYMBOLS)
307   AC_SUBST(ZIP_EXTERNAL_DEBUG_SYMBOLS)
308 
309   # Should we add external native debug symbols to the shipped bundles?
310   AC_MSG_CHECKING([if we should add external native debug symbols to the shipped bundles])
311   AC_ARG_WITH([external-symbols-in-bundles],
312       [AS_HELP_STRING([--with-external-symbols-in-bundles],
313       [which type of external native debug symbol information shall be shipped in product bundles (none, public, full)
314       (e.g. ship full/stripped pdbs on Windows) @<:@none@:>@])])
315 
316   if test "x$with_external_symbols_in_bundles" = x || test "x$with_external_symbols_in_bundles" = xnone ; then
317     AC_MSG_RESULT([no])
318   elif test "x$with_external_symbols_in_bundles" = xfull || test "x$with_external_symbols_in_bundles" = xpublic ; then
319     if test "x$OPENJDK_TARGET_OS" != xwindows ; then
320       AC_MSG_ERROR([--with-external-symbols-in-bundles currently only works on windows!])
321     elif test "x$COPY_DEBUG_SYMBOLS" != xtrue ; then
322       AC_MSG_ERROR([--with-external-symbols-in-bundles only works when --with-native-debug-symbols=external is used!])
323     elif test "x$with_external_symbols_in_bundles" = xfull ; then
324       AC_MSG_RESULT([full])
325       SHIP_DEBUG_SYMBOLS=full
326     else
327       AC_MSG_RESULT([public])
328       SHIP_DEBUG_SYMBOLS=public
329     fi
330   else
331     AC_MSG_ERROR([$with_external_symbols_in_bundles is an unknown value for --with-external-symbols-in-bundles])
332   fi
333 
334   AC_SUBST(SHIP_DEBUG_SYMBOLS)
335 ])
336 
337 ################################################################################
338 #
339 # Native and Java code coverage
340 #
341 AC_DEFUN_ONCE([JDKOPT_SETUP_CODE_COVERAGE],
342 [
343   UTIL_ARG_ENABLE(NAME: native-coverage, DEFAULT: false, RESULT: GCOV_ENABLED,
344       DESC: [enable native compilation with code coverage data],
345       CHECK_AVAILABLE: [
346         AC_MSG_CHECKING([if native coverage is available])
347         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
348             test "x$TOOLCHAIN_TYPE" = "xclang"; then
349           AC_MSG_RESULT([yes])
350         else
351           AC_MSG_RESULT([no])
352           AVAILABLE=false
353         fi
354       ],
355       IF_ENABLED: [
356         GCOV_CFLAGS="-fprofile-arcs -ftest-coverage -fno-inline"
357         GCOV_LDFLAGS="-fprofile-arcs"
358         JVM_CFLAGS="$JVM_CFLAGS $GCOV_CFLAGS"
359         JVM_LDFLAGS="$JVM_LDFLAGS $GCOV_LDFLAGS"
360         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $GCOV_CFLAGS"
361         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $GCOV_CFLAGS"
362         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $GCOV_CFLAGS"
363         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $GCOV_CFLAGS"
364         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $GCOV_LDFLAGS"
365         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $GCOV_LDFLAGS"
366       ])
367   AC_SUBST(GCOV_ENABLED)
368 
369   AC_ARG_WITH(jcov, [AS_HELP_STRING([--with-jcov],
370       [jcov library location])])
371   AC_ARG_WITH(jcov-input-jdk, [AS_HELP_STRING([--with-jcov-input-jdk],
372       [jdk image to instrument])])
373   AC_ARG_WITH(jcov-filters, [AS_HELP_STRING([--with-jcov-filters],
374       [filters to limit code for jcov instrumentation and report generation])])
375   JCOV_HOME=
376   JCOV_INPUT_JDK=
377   JCOV_ENABLED=
378   JCOV_FILTERS=
379   if test "x$with_jcov" = "x" ; then
380     JCOV_ENABLED="false"
381   else
382     JCOV_HOME="$with_jcov"
383     if test ! -f "$JCOV_HOME/lib/jcov.jar"; then
384       AC_MSG_RESULT([fail])
385       AC_MSG_ERROR([Invalid JCov bundle: "$JCOV_HOME/lib/jcov.jar" does not exist])
386     fi
387     JCOV_ENABLED="true"
388     UTIL_FIXUP_PATH(JCOV_HOME)
389     if test "x$with_jcov_input_jdk" != "x" ; then
390       JCOV_INPUT_JDK="$with_jcov_input_jdk"
391       if test ! -f "$JCOV_INPUT_JDK/bin/java" && test ! -f "$JCOV_INPUT_JDK/bin/java.exe"; then
392         AC_MSG_RESULT([fail])
393         AC_MSG_ERROR([Invalid JDK bundle: "$JCOV_INPUT_JDK/bin/java" does not exist])
394       fi
395       UTIL_FIXUP_PATH(JCOV_INPUT_JDK)
396     fi
397     if test "x$with_jcov_filters" != "x" ; then
398       JCOV_FILTERS="$with_jcov_filters"
399     fi
400   fi
401   AC_SUBST(JCOV_ENABLED)
402   AC_SUBST(JCOV_HOME)
403   AC_SUBST(JCOV_INPUT_JDK)
404   AC_SUBST(JCOV_FILTERS)
405 ])
406 
407 ###############################################################################
408 #
409 # AddressSanitizer
410 #
411 AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
412 [
413   UTIL_ARG_ENABLE(NAME: asan, DEFAULT: false, RESULT: ASAN_ENABLED,
414       DESC: [enable AddressSanitizer],
415       CHECK_AVAILABLE: [
416         AC_MSG_CHECKING([if AddressSanitizer (asan) is available])
417         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
418            test "x$TOOLCHAIN_TYPE" = "xclang" ||
419            test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
420           AC_MSG_RESULT([yes])
421         else
422           AC_MSG_RESULT([no])
423           AVAILABLE=false
424         fi
425       ],
426       IF_ENABLED: [
427         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
428            test "x$TOOLCHAIN_TYPE" = "xclang"; then
429           # ASan is simply incompatible with gcc -Wstringop-truncation. See
430           # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85650
431           # It's harmless to be suppressed in clang as well.
432           ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
433           ASAN_LDFLAGS="-fsanitize=address"
434         elif test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
435           # -Oy- is equivalent to -fno-omit-frame-pointer in GCC/Clang.
436           ASAN_CFLAGS="-fsanitize=address -Oy- -DADDRESS_SANITIZER"
437           # MSVC produces a warning if you pass -fsanitize=address to the linker. It also complains
438           $ if -DEBUG is not passed to the linker when building with ASan.
439           ASAN_LDFLAGS="-debug"
440         fi
441         JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
442         JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
443         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $ASAN_CFLAGS"
444         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $ASAN_CFLAGS"
445         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $ASAN_CFLAGS"
446         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $ASAN_CFLAGS"
447         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $ASAN_LDFLAGS"
448         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $ASAN_LDFLAGS"
449       ])
450   AC_SUBST(ASAN_ENABLED)
451 ])
452 
453 ###############################################################################
454 #
455 # LeakSanitizer
456 #
457 AC_DEFUN_ONCE([JDKOPT_SETUP_LEAK_SANITIZER],
458 [
459   UTIL_ARG_ENABLE(NAME: lsan, DEFAULT: false, RESULT: LSAN_ENABLED,
460       DESC: [enable LeakSanitizer],
461       CHECK_AVAILABLE: [
462         AC_MSG_CHECKING([if LeakSanitizer (lsan) is available])
463         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
464             test "x$TOOLCHAIN_TYPE" = "xclang"; then
465           AC_MSG_RESULT([yes])
466         else
467           AC_MSG_RESULT([no])
468           AVAILABLE=false
469         fi
470       ],
471       IF_ENABLED: [
472         LSAN_CFLAGS="-fsanitize=leak -fno-omit-frame-pointer -DLEAK_SANITIZER"
473         LSAN_LDFLAGS="-fsanitize=leak"
474         JVM_CFLAGS="$JVM_CFLAGS $LSAN_CFLAGS"
475         JVM_LDFLAGS="$JVM_LDFLAGS $LSAN_LDFLAGS"
476         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $LSAN_CFLAGS"
477         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $LSAN_CFLAGS"
478         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $LSAN_CFLAGS"
479         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $LSAN_CFLAGS"
480         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $LSAN_LDFLAGS"
481         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $LSAN_LDFLAGS"
482       ])
483   AC_SUBST(LSAN_ENABLED)
484 ])
485 
486 ###############################################################################
487 #
488 # UndefinedBehaviorSanitizer
489 #
490 AC_DEFUN_ONCE([JDKOPT_SETUP_UNDEFINED_BEHAVIOR_SANITIZER],
491 [
492   # GCC reports lots of likely false positives for stringop-truncation and format-overflow.
493   # Silence them for now.
494   UBSAN_CHECKS="-fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize=shift-base"
495   UBSAN_CFLAGS="$UBSAN_CHECKS -Wno-stringop-truncation -Wno-format-overflow -fno-omit-frame-pointer -DUNDEFINED_BEHAVIOR_SANITIZER"
496   UBSAN_LDFLAGS="$UBSAN_CHECKS"
497   UTIL_ARG_ENABLE(NAME: ubsan, DEFAULT: false, RESULT: UBSAN_ENABLED,
498       DESC: [enable UndefinedBehaviorSanitizer],
499       CHECK_AVAILABLE: [
500         AC_MSG_CHECKING([if UndefinedBehaviorSanitizer (ubsan) is available])
501         if test "x$TOOLCHAIN_TYPE" = "xgcc" ||
502             test "x$TOOLCHAIN_TYPE" = "xclang"; then
503           AC_MSG_RESULT([yes])
504         else
505           AC_MSG_RESULT([no])
506           AVAILABLE=false
507         fi
508       ],
509       IF_ENABLED: [
510         JVM_CFLAGS="$JVM_CFLAGS $UBSAN_CFLAGS"
511         JVM_LDFLAGS="$JVM_LDFLAGS $UBSAN_LDFLAGS"
512         CFLAGS_JDKLIB="$CFLAGS_JDKLIB $UBSAN_CFLAGS"
513         CFLAGS_JDKEXE="$CFLAGS_JDKEXE $UBSAN_CFLAGS"
514         CXXFLAGS_JDKLIB="$CXXFLAGS_JDKLIB $UBSAN_CFLAGS"
515         CXXFLAGS_JDKEXE="$CXXFLAGS_JDKEXE $UBSAN_CFLAGS"
516         LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $UBSAN_LDFLAGS"
517         LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $UBSAN_LDFLAGS"
518       ])
519   if test "x$UBSAN_ENABLED" = xfalse; then
520     UBSAN_CFLAGS=""
521     UBSAN_LDFLAGS=""
522   fi
523   AC_SUBST(UBSAN_CFLAGS)
524   AC_SUBST(UBSAN_LDFLAGS)
525   AC_SUBST(UBSAN_ENABLED)
526 ])
527 
528 ################################################################################
529 #
530 # Static build support.  When enabled will generate static
531 # libraries instead of shared libraries for all JDK libs.
532 #
533 AC_DEFUN_ONCE([JDKOPT_SETUP_STATIC_BUILD],
534 [
535   UTIL_ARG_ENABLE(NAME: static-build, DEFAULT: false, RESULT: STATIC_BUILD,
536       DESC: [enable static library build],
537       CHECKING_MSG: [if static build is enabled],
538       CHECK_AVAILABLE: [
539         AC_MSG_CHECKING([if static build is available])
540         if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
541           AC_MSG_RESULT([yes])
542         else
543           AC_MSG_RESULT([no])
544           AVAILABLE=false
545         fi
546       ],
547       IF_ENABLED: [
548         STATIC_BUILD_CFLAGS="-DSTATIC_BUILD=1"
549         CFLAGS_JDKLIB_EXTRA="$CFLAGS_JDKLIB_EXTRA $STATIC_BUILD_CFLAGS"
550         CXXFLAGS_JDKLIB_EXTRA="$CXXFLAGS_JDKLIB_EXTRA $STATIC_BUILD_CFLAGS"
551       ])
552   AC_SUBST(STATIC_BUILD)
553 ])
554 
555 ################################################################################
556 #
557 # jmod options.
558 #
559 AC_DEFUN_ONCE([JDKOPT_SETUP_JMOD_OPTIONS],
560 [
561   # Final JMODs are recompiled often during development, and java.base JMOD
562   # includes the JVM libraries. In release mode, prefer to compress JMODs fully.
563   # In debug mode, pay with a little extra space, but win a lot of CPU time back
564   # with the lightest (but still some) compression.
565   if test "x$DEBUG_LEVEL" = xrelease; then
566     DEFAULT_JMOD_COMPRESS="zip-6"
567   else
568     DEFAULT_JMOD_COMPRESS="zip-1"
569   fi
570 
571   UTIL_ARG_WITH(NAME: jmod-compress, TYPE: literal,
572     VALID_VALUES: [zip-0 zip-1 zip-2 zip-3 zip-4 zip-5 zip-6 zip-7 zip-8 zip-9],
573     DEFAULT: $DEFAULT_JMOD_COMPRESS,
574     CHECKING_MSG: [for JMOD compression type],
575     DESC: [specify JMOD compression type (zip-[0-9])]
576   )
577   AC_SUBST(JMOD_COMPRESS)
578 ])
579 
580 ################################################################################
581 #
582 # jlink options.
583 # We always keep packaged modules in JDK image.
584 #
585 AC_DEFUN_ONCE([JDKOPT_SETUP_JLINK_OPTIONS],
586 [
587   UTIL_ARG_ENABLE(NAME: keep-packaged-modules, DEFAULT: true,
588       RESULT: JLINK_KEEP_PACKAGED_MODULES,
589       DESC: [enable keeping of packaged modules in jdk image],
590       CHECKING_MSG: [if packaged modules are kept])
591   AC_SUBST(JLINK_KEEP_PACKAGED_MODULES)
592 ])
593 
594 ################################################################################
595 #
596 # Enable or disable generation of the classlist at build time
597 #
598 AC_DEFUN_ONCE([JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST],
599 [
600   # In GenerateLinkOptData.gmk, DumpLoadedClassList is used to generate the
601   # classlist file. It never will work if CDS is disabled, since the VM will report
602   # an error for DumpLoadedClassList.
603   UTIL_ARG_ENABLE(NAME: generate-classlist, DEFAULT: auto,
604       RESULT: ENABLE_GENERATE_CLASSLIST, AVAILABLE: $ENABLE_CDS,
605       DESC: [enable generation of a CDS classlist at build time],
606       DEFAULT_DESC: [enabled if the JVM feature 'cds' is enabled for all JVM variants],
607       CHECKING_MSG: [if the CDS classlist generation should be enabled])
608   AC_SUBST(ENABLE_GENERATE_CLASSLIST)
609 ])
610 
611 ################################################################################
612 #
613 # Optionally filter resource translations
614 #
615 AC_DEFUN([JDKOPT_EXCLUDE_TRANSLATIONS],
616 [
617   AC_ARG_WITH([exclude-translations], [AS_HELP_STRING([--with-exclude-translations],
618       [a comma separated list of locales to exclude translations for. Default is
619       to include all translations present in the source.])])
620 
621   EXCLUDE_TRANSLATIONS=""
622   AC_MSG_CHECKING([if any translations should be excluded])
623   if test "x$with_exclude_translations" != "x"; then
624     EXCLUDE_TRANSLATIONS="${with_exclude_translations//,/ }"
625     AC_MSG_RESULT([yes: $EXCLUDE_TRANSLATIONS])
626   else
627     AC_MSG_RESULT([no])
628   fi
629 
630   AC_SUBST(EXCLUDE_TRANSLATIONS)
631 ])
632 
633 ################################################################################
634 #
635 # Optionally disable man pages
636 #
637 AC_DEFUN([JDKOPT_ENABLE_DISABLE_MANPAGES],
638 [
639   UTIL_ARG_ENABLE(NAME: manpages, DEFAULT: true, RESULT: BUILD_MANPAGES,
640       DESC: [enable copying of static man pages],
641       CHECKING_MSG: [if static man pages should be copied])
642   AC_SUBST(BUILD_MANPAGES)
643 ])
644 
645 ################################################################################
646 #
647 # Disable the default CDS archive generation
648 #
649 AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE],
650 [
651   UTIL_ARG_ENABLE(NAME: cds-archive, DEFAULT: auto, RESULT: BUILD_CDS_ARCHIVE,
652       DESC: [enable generation of a default CDS archive in the product image],
653       DEFAULT_DESC: [enabled if possible],
654       CHECKING_MSG: [if a default CDS archive should be generated],
655       CHECK_AVAILABLE: [
656         AC_MSG_CHECKING([if CDS archive is available])
657         if test "x$ENABLE_CDS" = "xfalse"; then
658           AC_MSG_RESULT([no (CDS is disabled)])
659           AVAILABLE=false
660         elif test "x$COMPILE_TYPE" = "xcross"; then
661           AC_MSG_RESULT([no (not possible with cross compilation)])
662           AVAILABLE=false
663         else
664           AC_MSG_RESULT([yes])
665         fi
666       ])
667   AC_SUBST(BUILD_CDS_ARCHIVE)
668 ])
669 
670 ################################################################################
671 #
672 # Enable or disable the default CDS archive generation for Compact Object Headers
673 #
674 AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE_COH],
675 [
676   UTIL_ARG_ENABLE(NAME: cds-archive-coh, DEFAULT: auto, RESULT: BUILD_CDS_ARCHIVE_COH,
677       DESC: [enable generation of default CDS archives for compact object headers (requires --enable-cds-archive)],
678       DEFAULT_DESC: [auto],
679       CHECKING_MSG: [if default CDS archives for compact object headers should be generated],
680       CHECK_AVAILABLE: [
681         AC_MSG_CHECKING([if CDS archive with compact object headers is available])
682         if test "x$BUILD_CDS_ARCHIVE" = "xfalse"; then
683           AC_MSG_RESULT([no (CDS default archive generation is disabled)])
684           AVAILABLE=false
685         elif test "x$OPENJDK_TARGET_CPU" != "xx86_64" &&
686              test "x$OPENJDK_TARGET_CPU" != "xaarch64"; then
687           AC_MSG_RESULT([no (compact object headers not supported for this platform)])
688           AVAILABLE=false
689         else
690           AC_MSG_RESULT([yes])
691         fi
692       ])
693   AC_SUBST(BUILD_CDS_ARCHIVE_COH)
694 ])
695 
696 ################################################################################
697 #
698 # Enable the alternative CDS core region alignment
699 #
700 AC_DEFUN([JDKOPT_ENABLE_DISABLE_COMPATIBLE_CDS_ALIGNMENT],
701 [
702   UTIL_ARG_ENABLE(NAME: compatible-cds-alignment, DEFAULT: false,
703       RESULT: ENABLE_COMPATIBLE_CDS_ALIGNMENT,
704       DESC: [enable use alternative compatible cds core region alignment],
705       DEFAULT_DESC: [disabled],
706       CHECKING_MSG: [if compatible cds region alignment enabled],
707       CHECK_AVAILABLE: [
708         AC_MSG_CHECKING([if CDS archive is available])
709         if test "x$ENABLE_CDS" = "xfalse"; then
710           AVAILABLE=false
711           AC_MSG_RESULT([no (CDS is disabled)])
712         else
713           AVAILABLE=true
714           AC_MSG_RESULT([yes])
715         fi
716       ])
717   AC_SUBST(ENABLE_COMPATIBLE_CDS_ALIGNMENT)
718 ])
719 
720 ################################################################################
721 #
722 # Disallow any output from containing absolute paths from the build system.
723 # This setting defaults to allowed on debug builds and not allowed on release
724 # builds.
725 #
726 AC_DEFUN([JDKOPT_ALLOW_ABSOLUTE_PATHS_IN_OUTPUT],
727 [
728   AC_ARG_ENABLE([absolute-paths-in-output],
729       [AS_HELP_STRING([--disable-absolute-paths-in-output],
730        [Set to disable to prevent any absolute paths from the build to end up in
731         any of the build output. @<:@disabled in release builds, otherwise enabled@:>@])
732       ])
733 
734   AC_MSG_CHECKING([if absolute paths should be allowed in the build output])
735   if test "x$enable_absolute_paths_in_output" = "xno"; then
736     AC_MSG_RESULT([no, forced])
737     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
738   elif test "x$enable_absolute_paths_in_output" = "xyes"; then
739     AC_MSG_RESULT([yes, forced])
740     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
741   elif test "x$DEBUG_LEVEL" = "xrelease"; then
742     AC_MSG_RESULT([no, release build])
743     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="false"
744   else
745     AC_MSG_RESULT([yes, debug build])
746     ALLOW_ABSOLUTE_PATHS_IN_OUTPUT="true"
747   fi
748 
749   AC_SUBST(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)
750 ])
751 
752 ################################################################################
753 #
754 # Check and set options related to reproducible builds.
755 #
756 AC_DEFUN_ONCE([JDKOPT_SETUP_REPRODUCIBLE_BUILD],
757 [
758   AC_ARG_WITH([source-date], [AS_HELP_STRING([--with-source-date],
759       [how to set SOURCE_DATE_EPOCH ('updated', 'current', 'version' a timestamp or an ISO-8601 date) @<:@current/value of SOURCE_DATE_EPOCH@:>@])],
760       [with_source_date_present=true], [with_source_date_present=false])
761 
762   if test "x$SOURCE_DATE_EPOCH" != x && test "x$with_source_date" != x; then
763     AC_MSG_WARN([--with-source-date will override SOURCE_DATE_EPOCH])
764   fi
765 
766   AC_MSG_CHECKING([what source date to use])
767 
768   if test "x$with_source_date" = xyes; then
769     AC_MSG_ERROR([--with-source-date must have a value])
770   elif test "x$with_source_date" = x; then
771     if test "x$SOURCE_DATE_EPOCH" != x; then
772       SOURCE_DATE=$SOURCE_DATE_EPOCH
773       with_source_date_present=true
774       AC_MSG_RESULT([$SOURCE_DATE, from SOURCE_DATE_EPOCH])
775     else
776       # Tell makefiles to take the time from configure
777       SOURCE_DATE=$($DATE +"%s")
778       AC_MSG_RESULT([$SOURCE_DATE, from 'current' (default)])
779     fi
780   elif test "x$with_source_date" = xupdated; then
781     SOURCE_DATE=updated
782     AC_MSG_RESULT([determined at build time, from 'updated'])
783   elif test "x$with_source_date" = xcurrent; then
784     # Set the current time
785     SOURCE_DATE=$($DATE +"%s")
786     AC_MSG_RESULT([$SOURCE_DATE, from 'current'])
787   elif test "x$with_source_date" = xversion; then
788     # Use the date from version-numbers.conf
789     UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $DEFAULT_VERSION_DATE)
790     if test "x$SOURCE_DATE" = x; then
791       AC_MSG_RESULT([unavailable])
792       AC_MSG_ERROR([Cannot convert DEFAULT_VERSION_DATE to timestamp])
793     fi
794     AC_MSG_RESULT([$SOURCE_DATE, from 'version'])
795   else
796     # It's a timestamp, an ISO-8601 date, or an invalid string
797     # Additional [] needed to keep m4 from mangling shell constructs.
798     if [ [[ "$with_source_date" =~ ^[0-9][0-9]*$ ]] ] ; then
799       SOURCE_DATE=$with_source_date
800       AC_MSG_RESULT([$SOURCE_DATE, from timestamp on command line])
801     else
802       UTIL_GET_EPOCH_TIMESTAMP(SOURCE_DATE, $with_source_date)
803       if test "x$SOURCE_DATE" != x; then
804         AC_MSG_RESULT([$SOURCE_DATE, from ISO-8601 date on command line])
805       else
806         AC_MSG_RESULT([unavailable])
807         AC_MSG_ERROR([Cannot parse date string "$with_source_date"])
808       fi
809     fi
810   fi
811 
812   ISO_8601_FORMAT_STRING="%Y-%m-%dT%H:%M:%SZ"
813   if test "x$SOURCE_DATE" != xupdated; then
814     # If we have a fixed value for SOURCE_DATE, we need to set SOURCE_DATE_EPOCH
815     # for the rest of configure.
816     SOURCE_DATE_EPOCH="$SOURCE_DATE"
817     if test "x$IS_GNU_DATE" = xyes; then
818       SOURCE_DATE_ISO_8601=`$DATE --utc --date="@$SOURCE_DATE" +"$ISO_8601_FORMAT_STRING" 2> /dev/null`
819     else
820       SOURCE_DATE_ISO_8601=`$DATE -u -j -f "%s" "$SOURCE_DATE" +"$ISO_8601_FORMAT_STRING" 2> /dev/null`
821     fi
822   fi
823 
824   AC_SUBST(SOURCE_DATE)
825   AC_SUBST(ISO_8601_FORMAT_STRING)
826   AC_SUBST(SOURCE_DATE_ISO_8601)
827 
828   UTIL_DEPRECATED_ARG_ENABLE(reproducible-build)
829 ])
830 
831 ################################################################################
832 #
833 # Setup signing on macOS. This can either be setup to sign with a real identity
834 # and enabling the hardened runtime, or it can simply add the debug entitlement
835 # com.apple.security.get-task-allow without actually signing any binaries. The
836 # latter is needed to be able to debug processes and dump core files on modern
837 # versions of macOS. It can also be skipped completely.
838 #
839 # Check if codesign will run with the given parameters
840 # $1: Parameters to run with
841 # $2: Checking message
842 # Sets CODESIGN_SUCCESS=true/false
843 AC_DEFUN([JDKOPT_CHECK_CODESIGN_PARAMS],
844 [
845   PARAMS="$1"
846   MESSAGE="$2"
847   CODESIGN_TESTFILE="$CONFIGURESUPPORT_OUTPUTDIR/codesign-testfile"
848   $RM "$CODESIGN_TESTFILE"
849   $TOUCH "$CODESIGN_TESTFILE"
850   CODESIGN_SUCCESS=false
851 
852   $ECHO "check codesign, calling $CODESIGN $PARAMS $CODESIGN_TESTFILE" >&AS_MESSAGE_LOG_FD
853 
854   eval \"$CODESIGN\" $PARAMS \"$CODESIGN_TESTFILE\" 2>&AS_MESSAGE_LOG_FD \
855       >&AS_MESSAGE_LOG_FD && CODESIGN_SUCCESS=true
856   $RM "$CODESIGN_TESTFILE"
857   AC_MSG_CHECKING([$MESSAGE])
858   if test "x$CODESIGN_SUCCESS" = "xtrue"; then
859     AC_MSG_RESULT([yes])
860   else
861     AC_MSG_RESULT([no])
862   fi
863 ])
864 
865 AC_DEFUN([JDKOPT_CHECK_CODESIGN_HARDENED],
866 [
867   JDKOPT_CHECK_CODESIGN_PARAMS([-s \"$MACOSX_CODESIGN_IDENTITY\" --option runtime],
868       [if codesign with hardened runtime is possible])
869 ])
870 
871 AC_DEFUN([JDKOPT_CHECK_CODESIGN_DEBUG],
872 [
873   JDKOPT_CHECK_CODESIGN_PARAMS([-s -], [if debug mode codesign is possible])
874 ])
875 
876 AC_DEFUN([JDKOPT_SETUP_MACOSX_SIGNING],
877 [
878   ENABLE_CODESIGN=false
879   if test "x$OPENJDK_TARGET_OS" = "xmacosx" && test "x$CODESIGN" != "x"; then
880 
881     UTIL_ARG_WITH(NAME: macosx-codesign, TYPE: literal, OPTIONAL: true,
882         VALID_VALUES: [hardened debug auto], DEFAULT: auto,
883         ENABLED_DEFAULT: true,
884         CHECKING_MSG: [for macosx code signing mode],
885         DESC: [set the macosx code signing mode (hardened, debug, auto)]
886     )
887 
888     MACOSX_CODESIGN_MODE=disabled
889     if test "x$MACOSX_CODESIGN_ENABLED" = "xtrue"; then
890 
891       # Check for user provided code signing identity.
892       UTIL_ARG_WITH(NAME: macosx-codesign-identity, TYPE: string,
893           DEFAULT: openjdk_codesign, CHECK_VALUE: [UTIL_CHECK_STRING_NON_EMPTY],
894           DESC: [specify the macosx code signing identity],
895           CHECKING_MSG: [for macosx code signing identity]
896       )
897       AC_SUBST(MACOSX_CODESIGN_IDENTITY)
898 
899       if test "x$MACOSX_CODESIGN" = "xauto"; then
900         # Only try to default to hardened signing on release builds
901         if test "x$DEBUG_LEVEL" = "xrelease"; then
902           JDKOPT_CHECK_CODESIGN_HARDENED
903           if test "x$CODESIGN_SUCCESS" = "xtrue"; then
904             MACOSX_CODESIGN_MODE=hardened
905           fi
906         fi
907         if test "x$MACOSX_CODESIGN_MODE" = "xdisabled"; then
908           JDKOPT_CHECK_CODESIGN_DEBUG
909           if test "x$CODESIGN_SUCCESS" = "xtrue"; then
910             MACOSX_CODESIGN_MODE=debug
911           fi
912         fi
913         AC_MSG_CHECKING([for macosx code signing mode])
914         AC_MSG_RESULT([$MACOSX_CODESIGN_MODE])
915       elif test "x$MACOSX_CODESIGN" = "xhardened"; then
916         JDKOPT_CHECK_CODESIGN_HARDENED
917         if test "x$CODESIGN_SUCCESS" = "xfalse"; then
918           AC_MSG_ERROR([Signing with hardened runtime is not possible])
919         fi
920         MACOSX_CODESIGN_MODE=hardened
921       elif test "x$MACOSX_CODESIGN" = "xdebug"; then
922         JDKOPT_CHECK_CODESIGN_DEBUG
923         if test "x$CODESIGN_SUCCESS" = "xfalse"; then
924           AC_MSG_ERROR([Signing in debug mode is not possible])
925         fi
926         MACOSX_CODESIGN_MODE=debug
927       else
928         AC_MSG_ERROR([unknown value for --with-macosx-codesign: $MACOSX_CODESIGN])
929       fi
930     fi
931     AC_SUBST(MACOSX_CODESIGN_IDENTITY)
932     AC_SUBST(MACOSX_CODESIGN_MODE)
933   fi
934 ])
935 
936 ################################################################################
937 #
938 # fallback linker
939 #
940 AC_DEFUN_ONCE([JDKOPT_SETUP_FALLBACK_LINKER],
941 [
942   FALLBACK_LINKER_DEFAULT=false
943 
944   if HOTSPOT_CHECK_JVM_VARIANT(zero); then
945     FALLBACK_LINKER_DEFAULT=true
946   fi
947 
948   UTIL_ARG_ENABLE(NAME: fallback-linker, DEFAULT: $FALLBACK_LINKER_DEFAULT,
949       RESULT: ENABLE_FALLBACK_LINKER,
950       DESC: [enable libffi-based fallback implementation of java.lang.foreign.Linker],
951       CHECKING_MSG: [if fallback linker enabled])
952   AC_SUBST(ENABLE_FALLBACK_LINKER)
953 ])