toolchain.m4 revision 837:174a54ce39c4
1#
2# Copyright (c) 2011, 2012, 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# $1 = compiler to test (CC or CXX)
27# $2 = human readable name of compiler (C or C++)
28AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSION],
29[
30  COMPILER=[$]$1
31  COMPILER_NAME=$2
32
33  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
34    # Make sure we use the Sun Studio compiler and not gcc on Solaris, which won't work
35    COMPILER_VERSION_TEST=`$COMPILER -V 2>&1 | $HEAD -n 1`
36    $ECHO $COMPILER_VERSION_TEST | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
37    if test $? -ne 0; then
38      GCC_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
39
40      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required Sun Studio compiler.])
41      AC_MSG_NOTICE([The result from running with -V was: "$COMPILER_VERSION_TEST" and with --version: "$GCC_VERSION_TEST"])
42      AC_MSG_ERROR([Sun Studio compiler is required. Try setting --with-tools-dir.])
43    else
44      COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*@<:@ ,\t@:>@$COMPILER_NAME@<:@ ,\t@:>@\(@<:@1-9@:>@\.@<:@0-9@:>@@<:@0-9@:>@*\).*/\1/p"`
45      COMPILER_VENDOR="Sun Studio"
46    fi
47  elif test  "x$OPENJDK_TARGET_OS" = xwindows; then
48    # First line typically looks something like:
49    # Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
50    COMPILER_VERSION_TEST=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
51    COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.*Version \(@<:@1-9@:>@@<:@0-9.@:>@*\) .*/\1/p"`
52    COMPILER_VENDOR="Microsoft CL.EXE"
53    COMPILER_CPU_TEST=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.* for \(.*\)$/\1/p"`
54    if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
55      if test "x$COMPILER_CPU_TEST" != "x80x86"; then
56        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "80x86".])
57      fi
58    elif test "x$OPENJDK_TARGET_CPU" = "xx86_64"; then
59      if test "x$COMPILER_CPU_TEST" != "xx64"; then
60        AC_MSG_ERROR([Target CPU mismatch. We are building for $OPENJDK_TARGET_CPU but CL is for "$COMPILER_CPU_TEST"; expected "x64".])
61      fi
62    fi
63  else
64    COMPILER_VERSION_TEST=`$COMPILER --version 2>&1 | $HEAD -n 1`
65    # Check that this is likely to be GCC.
66    $COMPILER --version 2>&1 | $GREP "Free Software Foundation" > /dev/null
67    if test $? -ne 0; then
68      AC_MSG_NOTICE([The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required GCC compiler.])
69      AC_MSG_NOTICE([The result from running with --version was: "$COMPILER_VERSION_TEST"])
70      AC_MSG_ERROR([GCC compiler is required. Try setting --with-tools-dir.])
71    fi
72
73    # First line typically looks something like:
74    # gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
75    COMPILER_VERSION=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^.* \(@<:@1-9@:>@@<:@0-9.@:>@*\)/\1/p"`
76    COMPILER_VENDOR=`$ECHO $COMPILER_VERSION_TEST | $SED -n "s/^\(.*\) @<:@1-9@:>@@<:@0-9.@:>@*/\1/p"`
77  fi
78  # This sets CC_VERSION or CXX_VERSION. (This comment is a grep marker)
79  $1_VERSION="$COMPILER_VERSION"
80  # This sets CC_VENDOR or CXX_VENDOR. (This comment is a grep marker)
81  $1_VENDOR="$COMPILER_VENDOR"
82
83  AC_MSG_NOTICE([Using $COMPILER_VENDOR $COMPILER_NAME compiler version $COMPILER_VERSION (located at $COMPILER)])
84])
85
86
87AC_DEFUN_ONCE([TOOLCHAIN_SETUP_SYSROOT_AND_OUT_OPTIONS],
88[
89  ###############################################################################
90  #
91  # Configure the development tool paths and potential sysroot.
92  #
93  AC_LANG(C++)
94
95  # The option used to specify the target .o,.a or .so file.
96  # When compiling, how to specify the to be created object file.
97  CC_OUT_OPTION='-o$(SPACE)'
98  # When linking, how to specify the to be created executable.
99  EXE_OUT_OPTION='-o$(SPACE)'
100  # When linking, how to specify the to be created dynamically linkable library.
101  LD_OUT_OPTION='-o$(SPACE)'
102  # When archiving, how to specify the to be create static archive for object files.
103  AR_OUT_OPTION='rcs$(SPACE)'
104  AC_SUBST(CC_OUT_OPTION)
105  AC_SUBST(EXE_OUT_OPTION)
106  AC_SUBST(LD_OUT_OPTION)
107  AC_SUBST(AR_OUT_OPTION)
108])
109
110# $1 = compiler to test (CC or CXX)
111# $2 = human readable name of compiler (C or C++)
112# $3 = list of compiler names to search for
113AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
114[
115  COMPILER_NAME=$2
116
117  $1=
118  # If TOOLS_DIR is set, check for all compiler names in there first
119  # before checking the rest of the PATH.
120  if test -n "$TOOLS_DIR"; then
121    PATH_save="$PATH"
122    PATH="$TOOLS_DIR"
123    AC_PATH_PROGS(TOOLS_DIR_$1, $3)
124    $1=$TOOLS_DIR_$1
125    PATH="$PATH_save"
126  fi
127
128  # AC_PATH_PROGS can't be run multiple times with the same variable,
129  # so create a new name for this run.
130  if test "x[$]$1" = x; then
131    AC_PATH_PROGS(POTENTIAL_$1, $3)
132    $1=$POTENTIAL_$1
133  fi
134
135  if test "x[$]$1" = x; then
136    HELP_MSG_MISSING_DEPENDENCY([devkit])
137    AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
138  fi
139  BASIC_FIXUP_EXECUTABLE($1)
140  AC_MSG_CHECKING([resolved symbolic links for $1])
141  TEST_COMPILER="[$]$1"
142  BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER)
143  AC_MSG_RESULT([$TEST_COMPILER])
144  AC_MSG_CHECKING([if $1 is disguised ccache])
145
146  COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"`
147  if test "x$COMPILER_BASENAME" = "xccache"; then
148    AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler])
149    # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache.
150    # We want to control ccache invocation ourselves, so ignore this cc and try
151    # searching again.
152
153    # Remove the path to the fake ccache cc from the PATH
154    RETRY_COMPILER_SAVED_PATH="$PATH"
155    COMPILER_DIRNAME=`$DIRNAME [$]$1`
156    PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`"
157
158    # Try again looking for our compiler
159    AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3)
160    BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1)
161    PATH="$RETRY_COMPILER_SAVED_PATH"
162
163    AC_MSG_CHECKING([for resolved symbolic links for $1])
164    BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1)
165    AC_MSG_RESULT([$PROPER_COMPILER_$1])
166    $1="$PROPER_COMPILER_$1"
167  else
168    AC_MSG_RESULT([no, keeping $1])
169    $1="$TEST_COMPILER"
170  fi
171  TOOLCHAIN_CHECK_COMPILER_VERSION([$1], [$COMPILER_NAME])
172])
173
174
175AC_DEFUN([TOOLCHAIN_SETUP_PATHS],
176[
177  if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
178    TOOLCHAIN_SETUP_VISUAL_STUDIO_ENV
179    BASIC_DEPRECATED_ARG_WITH([dxsdk])
180    BASIC_DEPRECATED_ARG_WITH([dxsdk-lib])
181    BASIC_DEPRECATED_ARG_WITH([dxsdk-include])
182  fi
183
184  AC_SUBST(MSVCR_DLL)
185
186  # If --build AND --host is set, then the configure script will find any
187  # cross compilation tools in the PATH. Cross compilation tools
188  # follows the cross compilation standard where they are prefixed with ${host}.
189  # For example the binary i686-sun-solaris2.10-gcc
190  # will cross compile for i686-sun-solaris2.10
191  # If neither of build and host is not set, then build=host and the
192  # default compiler found in the path will be used.
193  # Setting only --host, does not seem to be really supported.
194  # Please set both --build and --host if you want to cross compile.
195
196  if test "x$COMPILE_TYPE" = "xcross"; then
197    # Now we to find a C/C++ compiler that can build executables for the build
198    # platform. We can't use the AC_PROG_CC macro, since it can only be used
199    # once. Also, we need to do this before adding a tools dir to the path,
200    # otherwise we might pick up cross-compilers which don't use standard naming.
201    # Otherwise, we'll set the BUILD_tools to the native tools, but that'll have
202    # to wait until they are properly discovered.
203    AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
204    BASIC_FIXUP_EXECUTABLE(BUILD_CC)
205    AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
206    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
207    AC_PATH_PROG(BUILD_LD, ld)
208    BASIC_FIXUP_EXECUTABLE(BUILD_LD)
209  fi
210  AC_SUBST(BUILD_CC)
211  AC_SUBST(BUILD_CXX)
212  AC_SUBST(BUILD_LD)
213
214  # If a devkit is found on the builddeps server, then prepend its path to the
215  # PATH variable. If there are cross compilers available in the devkit, these
216  # will be found by AC_PROG_CC et al.
217  DEVKIT=
218  BDEPS_CHECK_MODULE(DEVKIT, devkit, xxx,
219      [
220        # Found devkit
221        PATH="$DEVKIT/bin:$PATH"
222        SYS_ROOT="$DEVKIT/${rewritten_target}/sys-root"
223        if test "x$x_includes" = "xNONE"; then
224          x_includes="$SYS_ROOT/usr/include/X11"
225        fi
226        if test "x$x_libraries" = "xNONE"; then
227          x_libraries="$SYS_ROOT/usr/lib"
228        fi
229      ],
230      [])
231
232  # Store the CFLAGS etal passed to the configure script.
233  ORG_CFLAGS="$CFLAGS"
234  ORG_CXXFLAGS="$CXXFLAGS"
235  ORG_OBJCFLAGS="$OBJCFLAGS"
236
237  # autoconf magic only relies on PATH, so update it if tools dir is specified
238  OLD_PATH="$PATH"
239  if test "x$TOOLS_DIR" != x; then
240    PATH=$TOOLS_DIR:$PATH
241  fi
242
243
244  ### Locate C compiler (CC)
245
246  # On windows, only cl.exe is supported.
247  # On Solaris, cc is preferred to gcc.
248  # Elsewhere, gcc is preferred to cc.
249
250  if test "x$CC" != x; then
251    COMPILER_CHECK_LIST="$CC"
252  elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
253    COMPILER_CHECK_LIST="cl"
254  elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
255    COMPILER_CHECK_LIST="cc gcc"
256  else
257    COMPILER_CHECK_LIST="gcc cc"
258  fi
259
260  TOOLCHAIN_FIND_COMPILER([CC],[C],[$COMPILER_CHECK_LIST])
261  # Now that we have resolved CC ourself, let autoconf have its go at it
262  AC_PROG_CC([$CC])
263
264  ### Locate C++ compiler (CXX)
265
266  if test "x$CXX" != x; then
267    COMPILER_CHECK_LIST="$CXX"
268  elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
269    COMPILER_CHECK_LIST="cl"
270  elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
271    COMPILER_CHECK_LIST="CC g++"
272  else
273    COMPILER_CHECK_LIST="g++ CC"
274  fi
275
276  TOOLCHAIN_FIND_COMPILER([CXX],[C++],[$COMPILER_CHECK_LIST])
277  # Now that we have resolved CXX ourself, let autoconf have its go at it
278  AC_PROG_CXX([$CXX])
279
280  ### Locate other tools
281
282  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
283    AC_PROG_OBJC
284    BASIC_FIXUP_EXECUTABLE(OBJC)
285  else
286    OBJC=
287  fi
288
289  # Restore the flags to the user specified values.
290  # This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
291  CFLAGS="$ORG_CFLAGS"
292  CXXFLAGS="$ORG_CXXFLAGS"
293  OBJCFLAGS="$ORG_OBJCFLAGS"
294
295  LD="$CC"
296  LDEXE="$CC"
297  LDCXX="$CXX"
298  LDEXECXX="$CXX"
299  AC_SUBST(LD)
300  # LDEXE is the linker to use, when creating executables.
301  AC_SUBST(LDEXE)
302  # Linking C++ libraries.
303  AC_SUBST(LDCXX)
304  # Linking C++ executables.
305  AC_SUBST(LDEXECXX)
306
307  if test "x$OPENJDK_TARGET_OS" != xwindows; then
308    AC_CHECK_TOOL(AR, ar)
309    BASIC_FIXUP_EXECUTABLE(AR)
310  fi
311  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
312    ARFLAGS="-r"
313  else
314    ARFLAGS=""
315  fi
316  AC_SUBST(ARFLAGS)
317
318  # For hotspot, we need these in Windows mixed path; other platforms keep them the same
319  HOTSPOT_CXX="$CXX"
320  HOTSPOT_LD="$LD"
321  AC_SUBST(HOTSPOT_CXX)
322  AC_SUBST(HOTSPOT_LD)
323
324  COMPILER_NAME=gcc
325  COMPILER_TYPE=CC
326  AS_IF([test "x$OPENJDK_TARGET_OS" = xwindows], [
327    # For now, assume that we are always compiling using cl.exe.
328    CC_OUT_OPTION=-Fo
329    EXE_OUT_OPTION=-out:
330    LD_OUT_OPTION=-out:
331    AR_OUT_OPTION=-out:
332    # On Windows, reject /usr/bin/link (as determined in CYGWIN_LINK), which is a cygwin
333    # program for something completely different.
334    AC_CHECK_PROG([WINLD], [link],[link],,, [$CYGWIN_LINK])
335    # Since we must ignore the first found link, WINLD will contain
336    # the full path to the link.exe program.
337    BASIC_FIXUP_EXECUTABLE(WINLD)
338    printf "Windows linker was found at $WINLD\n"
339    AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
340    "$WINLD" --version > /dev/null
341    if test $? -eq 0 ; then
342      AC_MSG_RESULT([no])
343      AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
344    else
345      AC_MSG_RESULT([yes])
346    fi
347    LD="$WINLD"
348    LDEXE="$WINLD"
349    LDCXX="$WINLD"
350    LDEXECXX="$WINLD"
351
352    AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
353    BASIC_FIXUP_EXECUTABLE(MT)
354    # The resource compiler
355    AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
356    BASIC_FIXUP_EXECUTABLE(RC)
357
358    # For hotspot, we need these in Windows mixed path,
359    # so rewrite them all. Need added .exe suffix.
360    HOTSPOT_CXX="$CXX.exe"
361    HOTSPOT_LD="$LD.exe"
362    HOTSPOT_MT="$MT.exe"
363    HOTSPOT_RC="$RC.exe"
364    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
365    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
366    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
367    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
368    AC_SUBST(HOTSPOT_MT)
369    AC_SUBST(HOTSPOT_RC)
370
371    RC_FLAGS="-nologo -l 0x409 -r"
372    AS_IF([test "x$VARIANT" = xOPT], [
373    RC_FLAGS="$RC_FLAGS -d NDEBUG"
374  ])
375
376  # The version variables used to create RC_FLAGS may be overridden
377  # in a custom configure script, or possibly the command line.
378  # Let those variables be expanded at make time in spec.gmk.
379  # The \$ are escaped to the shell, and the $(...) variables
380  # are evaluated by make.
381  RC_FLAGS="$RC_FLAGS \
382      -d \"JDK_BUILD_ID=\$(FULL_VERSION)\" \
383      -d \"JDK_COMPANY=\$(COMPANY_NAME)\" \
384      -d \"JDK_COMPONENT=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) binary\" \
385      -d \"JDK_VER=\$(JDK_MINOR_VERSION).\$(JDK_MICRO_VERSION).\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0).\$(COOKED_BUILD_NUMBER)\" \
386      -d \"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\" \
387      -d \"JDK_NAME=\$(PRODUCT_NAME) \$(JDK_RC_PLATFORM_NAME) \$(JDK_MINOR_VERSION) \$(JDK_UPDATE_META_TAG)\" \
388      -d \"JDK_FVER=\$(JDK_MINOR_VERSION),\$(JDK_MICRO_VERSION),\$(if \$(JDK_UPDATE_VERSION),\$(JDK_UPDATE_VERSION),0),\$(COOKED_BUILD_NUMBER)\""
389
390  # lib.exe is used to create static libraries.
391  AC_CHECK_PROG([WINAR], [lib],[lib],,,)
392  BASIC_FIXUP_EXECUTABLE(WINAR)
393  AR="$WINAR"
394  ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
395
396  AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
397      BASIC_FIXUP_EXECUTABLE(DUMPBIN)
398
399      COMPILER_TYPE=CL
400      CCXXFLAGS="$CCXXFLAGS -nologo"
401  ])
402  AC_SUBST(RC_FLAGS)
403  AC_SUBST(COMPILER_TYPE)
404
405  AC_PROG_CPP
406  BASIC_FIXUP_EXECUTABLE(CPP)
407
408  AC_PROG_CXXCPP
409  BASIC_FIXUP_EXECUTABLE(CXXCPP)
410
411  if test "x$COMPILE_TYPE" != "xcross"; then
412    # If we are not cross compiling, use the same compilers for
413    # building the build platform executables. The cross-compilation
414    # case needed to be done earlier, but this can only be done after
415    # the native tools have been localized.
416    BUILD_CC="$CC"
417    BUILD_CXX="$CXX"
418    BUILD_LD="$LD"
419  fi
420
421  # for solaris we really need solaris tools, and not gnu equivalent
422  #   these seems to normally reside in /usr/ccs/bin so add that to path before
423  #   starting to probe
424  #
425  #   NOTE: I add this /usr/ccs/bin after TOOLS but before OLD_PATH
426  #         so that it can be overriden --with-tools-dir
427  if test "x$OPENJDK_BUILD_OS" = xsolaris; then
428    PATH="${TOOLS_DIR}:/usr/ccs/bin:${OLD_PATH}"
429  fi
430
431  # Find the right assembler.
432  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
433    AC_PATH_PROG(AS, as)
434    BASIC_FIXUP_EXECUTABLE(AS)
435  else
436    AS="$CC -c"
437  fi
438  AC_SUBST(AS)
439
440  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
441    AC_PATH_PROG(NM, nm)
442    BASIC_FIXUP_EXECUTABLE(NM)
443    AC_PATH_PROG(GNM, gnm)
444    BASIC_FIXUP_EXECUTABLE(GNM)
445    AC_PATH_PROG(STRIP, strip)
446    BASIC_FIXUP_EXECUTABLE(STRIP)
447    AC_PATH_PROG(MCS, mcs)
448    BASIC_FIXUP_EXECUTABLE(MCS)
449  elif test "x$OPENJDK_TARGET_OS" != xwindows; then
450    AC_CHECK_TOOL(NM, nm)
451    BASIC_FIXUP_EXECUTABLE(NM)
452    GNM="$NM"
453    AC_SUBST(GNM)
454    AC_CHECK_TOOL(STRIP, strip)
455    BASIC_FIXUP_EXECUTABLE(STRIP)
456  fi
457
458  # objcopy is used for moving debug symbols to separate files when
459  # full debug symbols are enabled.
460  if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
461    AC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
462    # Only call fixup if objcopy was found.
463    if test -n "$OBJCOPY"; then
464      BASIC_FIXUP_EXECUTABLE(OBJCOPY)
465    fi
466  fi
467
468  AC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
469  if test "x$OBJDUMP" != x; then
470    # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE bails if argument is missing.
471    BASIC_FIXUP_EXECUTABLE(OBJDUMP)
472  fi
473
474  if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
475    AC_PATH_PROG(LIPO, lipo)
476    BASIC_FIXUP_EXECUTABLE(LIPO)
477  fi
478
479  TOOLCHAIN_SETUP_JTREG
480
481  # Restore old path without tools dir
482  PATH="$OLD_PATH"
483])
484
485
486AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_LIBS],
487[
488
489  ###############################################################################
490  #
491  # How to compile shared libraries.
492  #
493
494  if test "x$GCC" = xyes; then
495    COMPILER_NAME=gcc
496    PICFLAG="-fPIC"
497    LIBRARY_PREFIX=lib
498    SHARED_LIBRARY='lib[$]1.so'
499    STATIC_LIBRARY='lib[$]1.a'
500    SHARED_LIBRARY_FLAGS="-shared"
501    SHARED_LIBRARY_SUFFIX='.so'
502    STATIC_LIBRARY_SUFFIX='.a'
503    OBJ_SUFFIX='.o'
504    EXE_SUFFIX=''
505    SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
506    SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
507    C_FLAG_REORDER=''
508    CXX_FLAG_REORDER=''
509    SET_SHARED_LIBRARY_ORIGIN='-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
510    SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
511    LD="$CC"
512    LDEXE="$CC"
513    LDCXX="$CXX"
514    LDEXECXX="$CXX"
515    POST_STRIP_CMD="$STRIP -g"
516
517    # Linking is different on MacOSX
518    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
519      # Might change in the future to clang.
520      COMPILER_NAME=gcc
521      SHARED_LIBRARY='lib[$]1.dylib'
522      SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
523      SHARED_LIBRARY_SUFFIX='.dylib'
524      EXE_SUFFIX=''
525      SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1'
526      SET_SHARED_LIBRARY_MAPFILE=''
527      SET_SHARED_LIBRARY_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
528      SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
529      POST_STRIP_CMD="$STRIP -S"
530    fi
531  else
532    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
533      # If it is not gcc, then assume it is the Oracle Solaris Studio Compiler
534      COMPILER_NAME=ossc
535      PICFLAG="-KPIC"
536      LIBRARY_PREFIX=lib
537      SHARED_LIBRARY='lib[$]1.so'
538      STATIC_LIBRARY='lib[$]1.a'
539      SHARED_LIBRARY_FLAGS="-G"
540      SHARED_LIBRARY_SUFFIX='.so'
541      STATIC_LIBRARY_SUFFIX='.a'
542      OBJ_SUFFIX='.o'
543      EXE_SUFFIX=''
544      SET_SHARED_LIBRARY_NAME=''
545      SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
546      C_FLAG_REORDER='-xF'
547      CXX_FLAG_REORDER='-xF'
548      SET_SHARED_LIBRARY_ORIGIN='-R\$$$$ORIGIN[$]1'
549      SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
550      CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
551      CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
552      CFLAGS_JDKLIB_EXTRA='-xstrconst'
553      POST_STRIP_CMD="$STRIP -x"
554      POST_MCS_CMD="$MCS -d -a \"JDK $FULL_VERSION\""
555    fi
556    if test "x$OPENJDK_TARGET_OS" = xwindows; then
557      # If it is not gcc, then assume it is the MS Visual Studio compiler
558      COMPILER_NAME=cl
559      PICFLAG=""
560      LIBRARY_PREFIX=
561      SHARED_LIBRARY='[$]1.dll'
562      STATIC_LIBRARY='[$]1.lib'
563      SHARED_LIBRARY_FLAGS="-LD"
564      SHARED_LIBRARY_SUFFIX='.dll'
565      STATIC_LIBRARY_SUFFIX='.lib'
566      OBJ_SUFFIX='.obj'
567      EXE_SUFFIX='.exe'
568      SET_SHARED_LIBRARY_NAME=''
569      SET_SHARED_LIBRARY_MAPFILE=''
570      SET_SHARED_LIBRARY_ORIGIN=''
571      SET_EXECUTABLE_ORIGIN=''
572    fi
573  fi
574
575  AC_SUBST(COMPILER_NAME)
576  AC_SUBST(OBJ_SUFFIX)
577  AC_SUBST(SHARED_LIBRARY)
578  AC_SUBST(STATIC_LIBRARY)
579  AC_SUBST(LIBRARY_PREFIX)
580  AC_SUBST(SHARED_LIBRARY_SUFFIX)
581  AC_SUBST(STATIC_LIBRARY_SUFFIX)
582  AC_SUBST(EXE_SUFFIX)
583  AC_SUBST(SHARED_LIBRARY_FLAGS)
584  AC_SUBST(SET_SHARED_LIBRARY_NAME)
585  AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
586  AC_SUBST(C_FLAG_REORDER)
587  AC_SUBST(CXX_FLAG_REORDER)
588  AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
589  AC_SUBST(SET_EXECUTABLE_ORIGIN)
590  AC_SUBST(POST_STRIP_CMD)
591  AC_SUBST(POST_MCS_CMD)
592
593  # The (cross) compiler is now configured, we can now test capabilities
594  # of the target platform.
595])
596
597AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
598[
599
600  ###############################################################################
601  #
602  # Setup the opt flags for different compilers
603  # and different operating systems.
604  #
605
606  #
607  # NOTE: check for -mstackrealign needs to be below potential addition of -m32
608  #
609  if test "x$OPENJDK_TARGET_CPU_BITS" = x32 && test "x$OPENJDK_TARGET_OS" = xmacosx; then
610    # On 32-bit MacOSX the OS requires C-entry points to be 16 byte aligned.
611    # While waiting for a better solution, the current workaround is to use -mstackrealign.
612    CFLAGS="$CFLAGS -mstackrealign"
613    AC_MSG_CHECKING([if 32-bit compiler supports -mstackrealign])
614    AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
615        [
616          AC_MSG_RESULT([yes])
617        ],
618        [
619          AC_MSG_RESULT([no])
620          AC_MSG_ERROR([The selected compiler $CXX does not support -mstackrealign! Try to put another compiler in the path.])
621        ]
622    )
623  fi
624
625  C_FLAG_DEPS="-MMD -MF"
626  CXX_FLAG_DEPS="-MMD -MF"
627
628  case $COMPILER_TYPE in
629    CC )
630      case $COMPILER_NAME in
631        gcc )
632          case $OPENJDK_TARGET_OS in
633            macosx )
634              # On MacOSX we optimize for size, something
635              # we should do for all platforms?
636              C_O_FLAG_HI="-Os"
637              C_O_FLAG_NORM="-Os"
638              C_O_FLAG_NONE=""
639              ;;
640            *)
641              C_O_FLAG_HI="-O3"
642              C_O_FLAG_NORM="-O2"
643              C_O_FLAG_NONE="-O0"
644              ;;
645          esac
646          CXX_O_FLAG_HI="$C_O_FLAG_HI"
647          CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
648          CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
649          CFLAGS_DEBUG_SYMBOLS="-g"
650          CXXFLAGS_DEBUG_SYMBOLS="-g"
651          if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
652            CFLAGS_DEBUG_SYMBOLS="-g1"
653            CXXFLAGS_DEBUG_SYMBOLS="-g1"
654          fi
655          ;;
656        ossc )
657          #
658          # Forte has different names for this with their C++ compiler...
659          #
660          C_FLAG_DEPS="-xMMD -xMF"
661          CXX_FLAG_DEPS="-xMMD -xMF"
662
663          # Extra options used with HIGHEST
664          #
665          # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
666          #          done with care, there are some assumptions below that need to
667          #          be understood about the use of pointers, and IEEE behavior.
668          #
669          # Use non-standard floating point mode (not IEEE 754)
670          CC_HIGHEST="$CC_HIGHEST -fns"
671          # Do some simplification of floating point arithmetic (not IEEE 754)
672          CC_HIGHEST="$CC_HIGHEST -fsimple"
673          # Use single precision floating point with 'float'
674          CC_HIGHEST="$CC_HIGHEST -fsingle"
675          # Assume memory references via basic pointer types do not alias
676          #   (Source with excessing pointer casting and data access with mixed
677          #    pointer types are not recommended)
678          CC_HIGHEST="$CC_HIGHEST -xalias_level=basic"
679          # Use intrinsic or inline versions for math/std functions
680          #   (If you expect perfect errno behavior, do not use this)
681          CC_HIGHEST="$CC_HIGHEST -xbuiltin=%all"
682          # Loop data dependency optimizations (need -xO3 or higher)
683          CC_HIGHEST="$CC_HIGHEST -xdepend"
684          # Pointer parameters to functions do not overlap
685          #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
686          #    If you pass in multiple pointers to the same data, do not use this)
687          CC_HIGHEST="$CC_HIGHEST -xrestrict"
688          # Inline some library routines
689          #   (If you expect perfect errno behavior, do not use this)
690          CC_HIGHEST="$CC_HIGHEST -xlibmil"
691          # Use optimized math routines
692          #   (If you expect perfect errno behavior, do not use this)
693          #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
694          #CC_HIGHEST="$CC_HIGHEST -xlibmopt"
695
696          if test "x$OPENJDK_TARGET_CPU" = xsparc; then
697            CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
698            CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
699          fi
700
701          case $OPENJDK_TARGET_CPU_ARCH in
702            x86)
703              C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xregs=no%frameptr"
704              C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
705              C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
706              C_O_FLAG_NONE="-xregs=no%frameptr"
707              CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
708              CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
709              CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
710              CXX_O_FLAG_NONE="-xregs=no%frameptr"
711              if test "x$OPENJDK_TARGET_CPU" = xx86; then
712                C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
713                CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
714              fi
715              ;;
716            sparc)
717              CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
718              CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
719              C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
720              C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
721              C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
722              C_O_FLAG_NONE=""
723              CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
724              CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
725              CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
726              CXX_O_FLAG_NONE=""
727              ;;
728          esac
729
730          CFLAGS_DEBUG_SYMBOLS="-g -xs"
731          CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
732      esac
733      ;;
734    CL )
735      C_O_FLAG_HIGHEST="-O2"
736      C_O_FLAG_HI="-O1"
737      C_O_FLAG_NORM="-O1"
738      C_O_FLAG_NONE="-Od"
739      CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
740      CXX_O_FLAG_HI="$C_O_FLAG_HI"
741      CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
742      CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
743      ;;
744  esac
745
746  if test -z "$C_O_FLAG_HIGHEST"; then
747    C_O_FLAG_HIGHEST="$C_O_FLAG_HI"
748  fi
749
750  if test -z "$CXX_O_FLAG_HIGHEST"; then
751    CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HI"
752  fi
753
754  AC_SUBST(C_O_FLAG_HIGHEST)
755  AC_SUBST(C_O_FLAG_HI)
756  AC_SUBST(C_O_FLAG_NORM)
757  AC_SUBST(C_O_FLAG_NONE)
758  AC_SUBST(CXX_O_FLAG_HIGHEST)
759  AC_SUBST(CXX_O_FLAG_HI)
760  AC_SUBST(CXX_O_FLAG_NORM)
761  AC_SUBST(CXX_O_FLAG_NONE)
762  AC_SUBST(C_FLAG_DEPS)
763  AC_SUBST(CXX_FLAG_DEPS)
764])
765
766AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_JDK],
767[
768
769  if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
770    AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
771  fi
772
773  if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
774    AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
775  fi
776
777  if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
778    AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
779  fi
780
781  AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
782      [extra flags to be used when compiling jdk c-files])])
783
784  AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
785      [extra flags to be used when compiling jdk c++-files])])
786
787  AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
788      [extra flags to be used when linking jdk])])
789
790  CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
791  CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
792  LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"
793
794  # Hotspot needs these set in their legacy form
795  LEGACY_EXTRA_CFLAGS=$with_extra_cflags
796  LEGACY_EXTRA_CXXFLAGS=$with_extra_cxxflags
797  LEGACY_EXTRA_LDFLAGS=$with_extra_ldflags
798
799  AC_SUBST(LEGACY_EXTRA_CFLAGS)
800  AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
801  AC_SUBST(LEGACY_EXTRA_LDFLAGS)
802
803  ###############################################################################
804  #
805  # Now setup the CFLAGS and LDFLAGS for the JDK build.
806  # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
807  #
808  case $COMPILER_NAME in
809    gcc )
810      CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -W -Wall -Wno-unused -Wno-parentheses \
811      -pipe \
812      -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
813      case $OPENJDK_TARGET_CPU_ARCH in
814        arm )
815          # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
816          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
817          ;;
818        ppc )
819          # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
820          ;;
821        * )
822          CCXXFLAGS_JDK="$CCXXFLAGS_JDK -fno-omit-frame-pointer"
823          CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
824          ;;
825      esac
826      ;;
827    ossc )
828      CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
829      case $OPENJDK_TARGET_CPU_ARCH in
830        x86 )
831          CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
832          CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
833          ;;
834      esac
835
836      CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
837      CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
838
839      LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
840      LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
841      ;;
842    cl )
843      CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
844      -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB -DWIN32_LEAN_AND_MEAN \
845      -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
846      -DWIN32 -DIAL"
847      case $OPENJDK_TARGET_CPU in
848        x86 )
849          CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_X86_ -Dx86"
850          ;;
851        x86_64 )
852          CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_AMD64_ -Damd64"
853          ;;
854      esac
855      ;;
856  esac
857
858  ###############################################################################
859
860  # Adjust flags according to debug level.
861  case $DEBUG_LEVEL in
862    fastdebug )
863      CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
864      CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
865      C_O_FLAG_HI="$C_O_FLAG_NORM"
866      C_O_FLAG_NORM="$C_O_FLAG_NORM"
867      CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
868      CXX_O_FLAG_NORM="$CXX_O_FLAG_NORM"
869      JAVAC_FLAGS="$JAVAC_FLAGS -g"
870      ;;
871    slowdebug )
872      CFLAGS_JDK="$CFLAGS_JDK $CFLAGS_DEBUG_SYMBOLS"
873      CXXFLAGS_JDK="$CXXFLAGS_JDK $CXXFLAGS_DEBUG_SYMBOLS"
874      C_O_FLAG_HI="$C_O_FLAG_NONE"
875      C_O_FLAG_NORM="$C_O_FLAG_NONE"
876      CXX_O_FLAG_HI="$CXX_O_FLAG_NONE"
877      CXX_O_FLAG_NORM="$CXX_O_FLAG_NONE"
878      JAVAC_FLAGS="$JAVAC_FLAGS -g"
879      ;;
880  esac
881
882  CCXXFLAGS_JDK="$CCXXFLAGS_JDK $ADD_LP64"
883
884  # The package path is used only on macosx?
885  PACKAGE_PATH=/opt/local
886  AC_SUBST(PACKAGE_PATH)
887
888  if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
889    # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
890    #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
891    #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
892    #   Note: -Dmacro         is the same as    #define macro 1
893    #         -Dmacro=        is the same as    #define macro
894    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
895      CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
896    else
897      CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
898    fi
899  else
900    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_BIG_ENDIAN"
901  fi
902  if test "x$OPENJDK_TARGET_OS" = xlinux; then
903    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DLINUX"
904  fi
905  if test "x$OPENJDK_TARGET_OS" = xwindows; then
906    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DWINDOWS"
907  fi
908  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
909    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DSOLARIS"
910  fi
911  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
912    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMACOSX -D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
913    # Setting these parameters makes it an error to link to macosx APIs that are
914    # newer than the given OS version and makes the linked binaries compatible even
915    # if built on a newer version of the OS.
916    # The expected format is X.Y.Z
917    MACOSX_VERSION_MIN=10.7.0
918    AC_SUBST(MACOSX_VERSION_MIN)
919    # The macro takes the version with no dots, ex: 1070
920    # Let the flags variables get resolved in make for easier override on make
921    # command line.
922    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(subst .,,\$(MACOSX_VERSION_MIN)) -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
923    LDFLAGS_JDK="$LDFLAGS_JDK -mmacosx-version-min=\$(MACOSX_VERSION_MIN)"
924  fi
925  if test "x$OPENJDK_TARGET_OS" = xbsd; then
926    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DBSD -D_ALLBSD_SOURCE"
927  fi
928  if test "x$DEBUG_LEVEL" = xrelease; then
929    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DNDEBUG"
930  if test "x$OPENJDK_TARGET_OS" = xsolaris; then
931    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DTRIMMED"
932  fi
933  else
934    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DDEBUG"
935  fi
936
937  CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DARCH='\"$OPENJDK_TARGET_CPU_LEGACY\"' -D$OPENJDK_TARGET_CPU_LEGACY"
938  CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DRELEASE='\"$RELEASE\"'"
939
940  CCXXFLAGS_JDK="$CCXXFLAGS_JDK \
941      -I${JDK_OUTPUTDIR}/include \
942      -I${JDK_OUTPUTDIR}/include/$OPENJDK_TARGET_OS \
943      -I${JDK_TOPDIR}/src/share/javavm/export \
944      -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/javavm/export \
945      -I${JDK_TOPDIR}/src/share/native/common \
946      -I${JDK_TOPDIR}/src/$OPENJDK_TARGET_OS_API_DIR/native/common"
947
948  # The shared libraries are compiled using the picflag.
949  CFLAGS_JDKLIB="$CCXXFLAGS_JDK $CFLAGS_JDK $PICFLAG $CFLAGS_JDKLIB_EXTRA"
950  CXXFLAGS_JDKLIB="$CCXXFLAGS_JDK $CXXFLAGS_JDK $PICFLAG $CXXFLAGS_JDKLIB_EXTRA "
951
952  # Executable flags
953  CFLAGS_JDKEXE="$CCXXFLAGS_JDK $CFLAGS_JDK"
954  CXXFLAGS_JDKEXE="$CCXXFLAGS_JDK $CXXFLAGS_JDK"
955
956  # Now this is odd. The JDK native libraries have to link against libjvm.so
957  # On 32-bit machines there is normally two distinct libjvm.so:s, client and server.
958  # Which should we link to? Are we lucky enough that the binary api to the libjvm.so library
959  # is identical for client and server? Yes. Which is picked at runtime (client or server)?
960  # Neither, since the chosen libjvm.so has already been loaded by the launcher, all the following
961  # libraries will link to whatever is in memory. Yuck.
962  #
963  # Thus we offer the compiler to find libjvm.so first in server then in client. It works. Ugh.
964  if test "x$COMPILER_NAME" = xcl; then
965    LDFLAGS_JDK="$LDFLAGS_JDK -nologo -opt:ref -incremental:no"
966    if test "x$OPENJDK_TARGET_CPU" = xx86; then
967      LDFLAGS_JDK="$LDFLAGS_JDK -safeseh"
968    fi
969    # TODO: make -debug optional "--disable-full-debug-symbols"
970    LDFLAGS_JDK="$LDFLAGS_JDK -debug"
971    LDFLAGS_JDKLIB="${LDFLAGS_JDK} -dll -libpath:${JDK_OUTPUTDIR}/lib"
972    LDFLAGS_JDKLIB_SUFFIX=""
973    if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
974      LDFLAGS_STACK_SIZE=1048576
975    else
976      LDFLAGS_STACK_SIZE=327680
977    fi
978    LDFLAGS_JDKEXE="${LDFLAGS_JDK} /STACK:$LDFLAGS_STACK_SIZE"
979  else
980    if test "x$COMPILER_NAME" = xgcc; then
981      # If this is a --hash-style=gnu system, use --hash-style=both, why?
982      HAS_GNU_HASH=`$CC -dumpspecs 2>/dev/null | $GREP 'hash-style=gnu'`
983      if test -n "$HAS_GNU_HASH"; then
984        LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker --hash-style=both "
985      fi
986      if test "x$OPENJDK_TARGET_OS" = xlinux; then
987        # And since we now know that the linker is gnu, then add -z defs, to forbid
988        # undefined symbols in object files.
989        LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -z -Xlinker defs"
990        if test "x$DEBUG_LEVEL" = "xrelease"; then
991          # When building release libraries, tell the linker optimize them.
992          # Should this be supplied to the OSS linker as well?
993          LDFLAGS_JDK="${LDFLAGS_JDK} -Xlinker -O1"
994        fi
995      fi
996    fi
997    LDFLAGS_JDKLIB="${LDFLAGS_JDK} $SHARED_LIBRARY_FLAGS \
998        -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}"
999
1000    # On some platforms (mac) the linker warns about non existing -L dirs.
1001    # Add server first if available. Linking aginst client does not always produce the same results.
1002    # Only add client dir if client is being built. Add minimal (note not minimal1) if only building minimal1.
1003    # Default to server for other variants.
1004    if test "x$JVM_VARIANT_SERVER" = xtrue; then
1005      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1006    elif test "x$JVM_VARIANT_CLIENT" = xtrue; then
1007      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/client"
1008    elif test "x$JVM_VARIANT_MINIMAL1" = xtrue; then
1009      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/minimal"
1010    else
1011      LDFLAGS_JDKLIB="${LDFLAGS_JDKLIB} -L${JDK_OUTPUTDIR}/lib${OPENJDK_TARGET_CPU_LIBDIR}/server"
1012    fi
1013
1014    LDFLAGS_JDKLIB_SUFFIX="-ljava -ljvm"
1015    if test "x$COMPILER_NAME" = xossc; then
1016      LDFLAGS_JDKLIB_SUFFIX="$LDFLAGS_JDKLIB_SUFFIX -lc"
1017    fi
1018
1019    LDFLAGS_JDKEXE="${LDFLAGS_JDK}"
1020    if test "x$OPENJDK_TARGET_OS" = xlinux; then
1021      LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE -Xlinker --allow-shlib-undefined"
1022    fi
1023  fi
1024
1025  AC_SUBST(CFLAGS_JDKLIB)
1026  AC_SUBST(CFLAGS_JDKEXE)
1027
1028  AC_SUBST(CXXFLAGS_JDKLIB)
1029  AC_SUBST(CXXFLAGS_JDKEXE)
1030
1031  AC_SUBST(LDFLAGS_JDKLIB)
1032  AC_SUBST(LDFLAGS_JDKEXE)
1033  AC_SUBST(LDFLAGS_JDKLIB_SUFFIX)
1034  AC_SUBST(LDFLAGS_JDKEXE_SUFFIX)
1035  AC_SUBST(LDFLAGS_CXX_JDK)
1036])
1037
1038
1039# TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([ARGUMENT], [RUN-IF-TRUE],
1040#                                   [RUN-IF-FALSE])
1041# ------------------------------------------------------------
1042# Check that the c and c++ compilers support an argument
1043AC_DEFUN([TOOLCHAIN_COMPILER_CHECK_ARGUMENTS],
1044[
1045  AC_MSG_CHECKING([if compiler supports "$1"])
1046  supports=yes
1047
1048  saved_cflags="$CFLAGS"
1049  CFLAGS="$CFLAGS $1"
1050  AC_LANG_PUSH([C])
1051  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
1052      [supports=no])
1053  AC_LANG_POP([C])
1054  CFLAGS="$saved_cflags"
1055
1056  saved_cxxflags="$CXXFLAGS"
1057  CXXFLAGS="$CXXFLAG $1"
1058  AC_LANG_PUSH([C++])
1059  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i;]])], [], 
1060      [supports=no])
1061  AC_LANG_POP([C++])
1062  CXXFLAGS="$saved_cxxflags"
1063
1064  AC_MSG_RESULT([$supports])
1065  if test "x$supports" = "xyes" ; then
1066    m4_ifval([$2], [$2], [:])
1067  else
1068    m4_ifval([$3], [$3], [:])
1069  fi
1070])
1071
1072AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_MISC],
1073[
1074  # Some Zero and Shark settings.
1075  # ZERO_ARCHFLAG tells the compiler which mode to build for
1076  case "${OPENJDK_TARGET_CPU}" in
1077    s390)
1078      ZERO_ARCHFLAG="-m31"
1079      ;;
1080    *)
1081      ZERO_ARCHFLAG="-m${OPENJDK_TARGET_CPU_BITS}"
1082  esac
1083  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([$ZERO_ARCHFLAG], [], [ZERO_ARCHFLAG=""])
1084  AC_SUBST(ZERO_ARCHFLAG)
1085
1086  # Check that the compiler supports -mX flags
1087  # Set COMPILER_SUPPORTS_TARGET_BITS_FLAG to 'true' if it does
1088  TOOLCHAIN_COMPILER_CHECK_ARGUMENTS([-m${OPENJDK_TARGET_CPU_BITS}],
1089      [COMPILER_SUPPORTS_TARGET_BITS_FLAG=true],
1090      [COMPILER_SUPPORTS_TARGET_BITS_FLAG=false])
1091  AC_SUBST(COMPILER_SUPPORTS_TARGET_BITS_FLAG)
1092])
1093
1094# Setup the JTREG paths
1095AC_DEFUN_ONCE([TOOLCHAIN_SETUP_JTREG],
1096[
1097  AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
1098      [Regression Test Harness @<:@probed@:>@])],
1099      [],
1100      [with_jtreg=no])
1101
1102  if test "x$with_jtreg" = xno; then
1103    # jtreg disabled
1104    AC_MSG_CHECKING([for jtreg])
1105    AC_MSG_RESULT(no)
1106  else
1107    if test "x$with_jtreg" != xyes; then
1108      # with path specified.
1109      JT_HOME="$with_jtreg"
1110    fi
1111
1112    if test "x$JT_HOME" != x; then
1113      AC_MSG_CHECKING([for jtreg])
1114
1115      # use JT_HOME enviroment var.
1116      BASIC_FIXUP_PATH([JT_HOME])
1117
1118      # jtreg win32 script works for everybody
1119      JTREGEXE="$JT_HOME/win32/bin/jtreg"
1120
1121      if test ! -f "$JTREGEXE"; then
1122        AC_MSG_ERROR([JTReg executable does not exist: $JTREGEXE])
1123      fi
1124
1125      AC_MSG_RESULT($JTREGEXE)
1126    else
1127      # try to find jtreg on path
1128      BASIC_REQUIRE_PROG(JTREGEXE, jtreg)
1129      JT_HOME="`$DIRNAME $JTREGEXE`"
1130    fi
1131  fi
1132
1133  AC_SUBST(JT_HOME)
1134  AC_SUBST(JTREGEXE)
1135])
1136