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