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