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