toolchain.m4 revision 646:a9c8a32d09f9
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
179fi
180
181AC_SUBST(MSVCR_DLL)
182
183# If --build AND --host is set, then the configure script will find any
184# cross compilation tools in the PATH. Cross compilation tools
185# follows the cross compilation standard where they are prefixed with ${host}.
186# For example the binary i686-sun-solaris2.10-gcc
187# will cross compile for i686-sun-solaris2.10
188# If neither of build and host is not set, then build=host and the
189# default compiler found in the path will be used.
190# Setting only --host, does not seem to be really supported.
191# Please set both --build and --host if you want to cross compile.
192
193if test "x$COMPILE_TYPE" = "xcross"; then
194    # Now we to find a C/C++ compiler that can build executables for the build
195    # platform. We can't use the AC_PROG_CC macro, since it can only be used
196    # once. Also, we need to do this before adding a tools dir to the path,
197    # otherwise we might pick up cross-compilers which don't use standard naming.
198    # Otherwise, we'll set the BUILD_tools to the native tools, but that'll have
199    # to wait until they are properly discovered.
200    AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
201    BASIC_FIXUP_EXECUTABLE(BUILD_CC)
202    AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
203    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
204    AC_PATH_PROG(BUILD_LD, ld)
205    BASIC_FIXUP_EXECUTABLE(BUILD_LD)
206fi
207AC_SUBST(BUILD_CC)
208AC_SUBST(BUILD_CXX)
209AC_SUBST(BUILD_LD)
210
211# If a devkit is found on the builddeps server, then prepend its path to the
212# PATH variable. If there are cross compilers available in the devkit, these
213# will be found by AC_PROG_CC et al.
214DEVKIT=
215BDEPS_CHECK_MODULE(DEVKIT, devkit, xxx,
216                    [# Found devkit
217                     PATH="$DEVKIT/bin:$PATH"
218                     SYS_ROOT="$DEVKIT/${rewritten_target}/sys-root"
219                     if test "x$x_includes" = "xNONE"; then
220                         x_includes="$SYS_ROOT/usr/include/X11"
221                     fi
222                     if test "x$x_libraries" = "xNONE"; then
223                         x_libraries="$SYS_ROOT/usr/lib"
224                     fi
225                    ],
226                    [])
227
228if test "x$SYS_ROOT" != "x/" ; then                    
229    CFLAGS="--sysroot=$SYS_ROOT $CFLAGS"
230    CXXFLAGS="--sysroot=$SYS_ROOT $CXXFLAGS"
231    OBJCFLAGS="--sysroot=$SYS_ROOT $OBJCFLAGS" 
232    OBJCXXFLAGS="--sysroot=$SYS_ROOT $OBJCFLAGS" 
233    CPPFLAGS="--sysroot=$SYS_ROOT $CPPFLAGS"
234    LDFLAGS="--sysroot=$SYS_ROOT $LDFLAGS"
235fi
236
237# Store the CFLAGS etal passed to the configure script.
238ORG_CFLAGS="$CFLAGS"
239ORG_CXXFLAGS="$CXXFLAGS"
240ORG_OBJCFLAGS="$OBJCFLAGS"
241
242# autoconf magic only relies on PATH, so update it if tools dir is specified
243OLD_PATH="$PATH"
244if test "x$TOOLS_DIR" != x; then
245  PATH=$TOOLS_DIR:$PATH
246fi
247
248
249### Locate C compiler (CC)
250
251# On windows, only cl.exe is supported.
252# On Solaris, cc is preferred to gcc.
253# Elsewhere, gcc is preferred to cc.
254
255if test "x$CC" != x; then
256  COMPILER_CHECK_LIST="$CC"
257elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
258  COMPILER_CHECK_LIST="cl"
259elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
260  COMPILER_CHECK_LIST="cc gcc"
261else
262  COMPILER_CHECK_LIST="gcc cc"
263fi
264
265TOOLCHAIN_FIND_COMPILER([CC],[C],[$COMPILER_CHECK_LIST])
266# Now that we have resolved CC ourself, let autoconf have its go at it
267AC_PROG_CC([$CC])
268
269### Locate C++ compiler (CXX)
270
271if test "x$CXX" != x; then
272  COMPILER_CHECK_LIST="$CXX"
273elif test "x$OPENJDK_TARGET_OS" = "xwindows"; then
274  COMPILER_CHECK_LIST="cl"
275elif test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
276  COMPILER_CHECK_LIST="CC g++"
277else
278  COMPILER_CHECK_LIST="g++ CC"
279fi
280
281TOOLCHAIN_FIND_COMPILER([CXX],[C++],[$COMPILER_CHECK_LIST])
282# Now that we have resolved CXX ourself, let autoconf have its go at it
283AC_PROG_CXX([$CXX])
284
285### Locate other tools
286
287if test "x$OPENJDK_TARGET_OS" = xmacosx; then
288    AC_PROG_OBJC
289    BASIC_FIXUP_EXECUTABLE(OBJC)
290else
291    OBJC=
292fi
293
294# Restore the flags to the user specified values.
295# This is necessary since AC_PROG_CC defaults CFLAGS to "-g -O2"
296CFLAGS="$ORG_CFLAGS"
297CXXFLAGS="$ORG_CXXFLAGS"
298OBJCFLAGS="$ORG_OBJCFLAGS"
299
300LD="$CC"
301LDEXE="$CC"
302LDCXX="$CXX"
303LDEXECXX="$CXX"
304AC_SUBST(LD)
305# LDEXE is the linker to use, when creating executables.
306AC_SUBST(LDEXE)
307# Linking C++ libraries.
308AC_SUBST(LDCXX)
309# Linking C++ executables.
310AC_SUBST(LDEXECXX)
311
312if test "x$OPENJDK_TARGET_OS" != xwindows; then
313    AC_CHECK_TOOL(AR, ar)
314    BASIC_FIXUP_EXECUTABLE(AR)
315fi
316if test "x$OPENJDK_TARGET_OS" = xmacosx; then
317    ARFLAGS="-r"
318else
319    ARFLAGS=""
320fi
321AC_SUBST(ARFLAGS)
322
323# For hotspot, we need these in Windows mixed path; other platforms keep them the same
324HOTSPOT_CXX="$CXX"
325HOTSPOT_LD="$LD"
326AC_SUBST(HOTSPOT_CXX)
327AC_SUBST(HOTSPOT_LD)
328
329COMPILER_NAME=gcc
330COMPILER_TYPE=CC
331AS_IF([test "x$OPENJDK_TARGET_OS" = xwindows], [
332    # For now, assume that we are always compiling using cl.exe. 
333    CC_OUT_OPTION=-Fo
334    EXE_OUT_OPTION=-out:
335    LD_OUT_OPTION=-out:
336    AR_OUT_OPTION=-out:
337    # On Windows, reject /usr/bin/link (as determined in CYGWIN_LINK), which is a cygwin
338    # program for something completely different.
339    AC_CHECK_PROG([WINLD], [link],[link],,, [$CYGWIN_LINK])
340    # Since we must ignore the first found link, WINLD will contain
341    # the full path to the link.exe program.
342    BASIC_FIXUP_EXECUTABLE(WINLD)
343    printf "Windows linker was found at $WINLD\n"
344    AC_MSG_CHECKING([if the found link.exe is actually the Visual Studio linker])
345    "$WINLD" --version > /dev/null
346    if test $? -eq 0 ; then
347      AC_MSG_RESULT([no])
348      AC_MSG_ERROR([This is the Cygwin link tool. Please check your PATH and rerun configure.])
349    else
350      AC_MSG_RESULT([yes])
351    fi
352    LD="$WINLD"
353    LDEXE="$WINLD"
354    LDCXX="$WINLD"
355    LDEXECXX="$WINLD"
356
357    AC_CHECK_PROG([MT], [mt], [mt],,, [/usr/bin/mt])
358    BASIC_FIXUP_EXECUTABLE(MT)
359    # The resource compiler
360    AC_CHECK_PROG([RC], [rc], [rc],,, [/usr/bin/rc])
361    BASIC_FIXUP_EXECUTABLE(RC)
362
363    # For hotspot, we need these in Windows mixed path,
364    # so rewrite them all. Need added .exe suffix.
365    HOTSPOT_CXX="$CXX.exe"
366    HOTSPOT_LD="$LD.exe"
367    HOTSPOT_MT="$MT.exe"
368    HOTSPOT_RC="$RC.exe"
369    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_CXX)
370    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_LD)
371    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_MT)
372    BASIC_WINDOWS_REWRITE_AS_WINDOWS_MIXED_PATH(HOTSPOT_RC)
373    AC_SUBST(HOTSPOT_MT)
374    AC_SUBST(HOTSPOT_RC)
375
376    RC_FLAGS="-nologo -l 0x409 -r"
377    AS_IF([test "x$VARIANT" = xOPT], [
378        RC_FLAGS="$RC_FLAGS -d NDEBUG"
379    ])
380    JDK_UPDATE_VERSION_NOTNULL=$JDK_UPDATE_VERSION
381    AS_IF([test "x$JDK_UPDATE_VERSION" = x], [
382        JDK_UPDATE_VERSION_NOTNULL=0
383    ])
384    RC_FLAGS="$RC_FLAGS -d \"JDK_BUILD_ID=$FULL_VERSION\""
385    RC_FLAGS="$RC_FLAGS -d \"JDK_COMPANY=$COMPANY_NAME\""
386    RC_FLAGS="$RC_FLAGS -d \"JDK_COMPONENT=$PRODUCT_NAME $JDK_RC_PLATFORM_NAME binary\""
387    RC_FLAGS="$RC_FLAGS -d \"JDK_VER=$JDK_MINOR_VERSION.$JDK_MICRO_VERSION.$JDK_UPDATE_VERSION_NOTNULL.$COOKED_BUILD_NUMBER\""
388    RC_FLAGS="$RC_FLAGS -d \"JDK_COPYRIGHT=Copyright \xA9 $COPYRIGHT_YEAR\""
389    RC_FLAGS="$RC_FLAGS -d \"JDK_NAME=$PRODUCT_NAME $JDK_RC_PLATFORM_NAME $JDK_MINOR_VERSION $JDK_UPDATE_META_TAG\""
390    RC_FLAGS="$RC_FLAGS -d \"JDK_FVER=$JDK_MINOR_VERSION,$JDK_MICRO_VERSION,$JDK_UPDATE_VERSION_NOTNULL,$COOKED_BUILD_NUMBER\""
391
392    # lib.exe is used to create static libraries.
393    AC_CHECK_PROG([WINAR], [lib],[lib],,,)
394    BASIC_FIXUP_EXECUTABLE(WINAR)
395    AR="$WINAR"
396    ARFLAGS="-nologo -NODEFAULTLIB:MSVCRT"
397
398    AC_CHECK_PROG([DUMPBIN], [dumpbin], [dumpbin],,,)
399    BASIC_FIXUP_EXECUTABLE(DUMPBIN)
400
401    COMPILER_TYPE=CL
402    CCXXFLAGS="$CCXXFLAGS -nologo"
403])
404AC_SUBST(RC_FLAGS)
405AC_SUBST(COMPILER_TYPE)
406
407AC_PROG_CPP
408BASIC_FIXUP_EXECUTABLE(CPP)
409
410AC_PROG_CXXCPP
411BASIC_FIXUP_EXECUTABLE(CXXCPP)
412
413if test "x$COMPILE_TYPE" != "xcross"; then
414    # If we are not cross compiling, use the same compilers for
415    # building the build platform executables. The cross-compilation
416    # case needed to be done earlier, but this can only be done after
417    # the native tools have been localized.
418    BUILD_CC="$CC"
419    BUILD_CXX="$CXX"
420    BUILD_LD="$LD"
421fi
422
423# for solaris we really need solaris tools, and not gnu equivalent
424#   these seems to normally reside in /usr/ccs/bin so add that to path before
425#   starting to probe
426#
427#   NOTE: I add this /usr/ccs/bin after TOOLS but before OLD_PATH
428#         so that it can be overriden --with-tools-dir
429if test "x$OPENJDK_BUILD_OS" = xsolaris; then
430    PATH="${TOOLS_DIR}:/usr/ccs/bin:${OLD_PATH}"
431fi
432
433# Find the right assembler.
434if test "x$OPENJDK_TARGET_OS" = xsolaris; then
435    AC_PATH_PROG(AS, as)
436    BASIC_FIXUP_EXECUTABLE(AS)
437else
438    AS="$CC -c"
439fi
440AC_SUBST(AS)
441
442if test "x$OPENJDK_TARGET_OS" = xsolaris; then
443    AC_PATH_PROGS(NM, [gnm nm])
444    BASIC_FIXUP_EXECUTABLE(NM)
445    AC_PATH_PROG(STRIP, strip)
446    BASIC_FIXUP_EXECUTABLE(STRIP)
447    AC_PATH_PROG(MCS, mcs)
448    BASIC_FIXUP_EXECUTABLE(MCS)
449elif test "x$OPENJDK_TARGET_OS" != xwindows; then
450    AC_CHECK_TOOL(NM, nm)
451    BASIC_FIXUP_EXECUTABLE(NM)
452    AC_CHECK_TOOL(STRIP, strip)
453    BASIC_FIXUP_EXECUTABLE(STRIP)
454fi
455
456# objcopy is used for moving debug symbols to separate files when
457# full debug symbols are enabled.
458if test "x$OPENJDK_TARGET_OS" = xsolaris || test "x$OPENJDK_TARGET_OS" = xlinux; then
459    AC_CHECK_TOOLS(OBJCOPY, [gobjcopy objcopy])
460    # Only call fixup if objcopy was found.
461    if test -n "$OBJCOPY"; then
462        BASIC_FIXUP_EXECUTABLE(OBJCOPY)
463    fi
464fi
465
466AC_CHECK_TOOLS(OBJDUMP, [gobjdump objdump])
467if test "x$OBJDUMP" != x; then
468  # Only used for compare.sh; we can live without it. BASIC_FIXUP_EXECUTABLE bails if argument is missing.
469  BASIC_FIXUP_EXECUTABLE(OBJDUMP)
470fi
471
472if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
473   AC_PATH_PROG(LIPO, lipo)
474   BASIC_FIXUP_EXECUTABLE(LIPO)
475fi
476
477# Restore old path without tools dir
478PATH="$OLD_PATH"
479])
480
481
482AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_LIBS],
483[
484
485###############################################################################
486#
487# How to compile shared libraries. 
488#
489
490if test "x$GCC" = xyes; then
491    COMPILER_NAME=gcc
492    PICFLAG="-fPIC"
493    LIBRARY_PREFIX=lib
494    SHARED_LIBRARY='lib[$]1.so'
495    STATIC_LIBRARY='lib[$]1.a'
496    SHARED_LIBRARY_FLAGS="-shared"
497    SHARED_LIBRARY_SUFFIX='.so'
498    STATIC_LIBRARY_SUFFIX='.a'
499    OBJ_SUFFIX='.o'
500    EXE_SUFFIX=''
501    SET_SHARED_LIBRARY_NAME='-Xlinker -soname=[$]1'
502    SET_SHARED_LIBRARY_MAPFILE='-Xlinker -version-script=[$]1'
503    C_FLAG_REORDER=''
504    CXX_FLAG_REORDER=''
505    SET_SHARED_LIBRARY_ORIGIN='-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
506    SET_EXECUTABLE_ORIGIN='-Xlinker -rpath -Xlinker \$$$$ORIGIN[$]1'
507    LD="$CC"
508    LDEXE="$CC"
509    LDCXX="$CXX"
510    LDEXECXX="$CXX"
511    POST_STRIP_CMD="$STRIP -g"
512
513    # Linking is different on MacOSX
514    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
515        # Might change in the future to clang.
516        COMPILER_NAME=gcc
517        SHARED_LIBRARY='lib[$]1.dylib'
518        SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $PICFLAG"
519        SHARED_LIBRARY_SUFFIX='.dylib'
520        EXE_SUFFIX=''
521        SET_SHARED_LIBRARY_NAME='-Xlinker -install_name -Xlinker @rpath/[$]1' 
522        SET_SHARED_LIBRARY_MAPFILE=''
523        SET_SHARED_LIBRARY_ORIGIN='-Xlinker -rpath -Xlinker @loader_path/.'
524        SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
525        POST_STRIP_CMD="$STRIP -S"
526    fi
527else
528    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
529        # If it is not gcc, then assume it is the Oracle Solaris Studio Compiler
530        COMPILER_NAME=ossc
531        PICFLAG="-KPIC"
532        LIBRARY_PREFIX=lib
533        SHARED_LIBRARY='lib[$]1.so'
534        STATIC_LIBRARY='lib[$]1.a'
535        SHARED_LIBRARY_FLAGS="-G"
536        SHARED_LIBRARY_SUFFIX='.so'
537        STATIC_LIBRARY_SUFFIX='.a'
538        OBJ_SUFFIX='.o'
539        EXE_SUFFIX=''
540        SET_SHARED_LIBRARY_NAME=''
541        SET_SHARED_LIBRARY_MAPFILE='-M[$]1'
542	C_FLAG_REORDER='-xF'
543	CXX_FLAG_REORDER='-xF'
544        SET_SHARED_LIBRARY_ORIGIN='-R\$$$$ORIGIN[$]1'
545        SET_EXECUTABLE_ORIGIN="$SET_SHARED_LIBRARY_ORIGIN"
546        CFLAGS_JDK="${CFLAGS_JDK} -D__solaris__"
547        CXXFLAGS_JDK="${CXXFLAGS_JDK} -D__solaris__"
548        CFLAGS_JDKLIB_EXTRA='-xstrconst'
549        POST_STRIP_CMD="$STRIP -x"
550        POST_MCS_CMD="$MCS -d -a \"JDK $FULL_VERSION\""
551    fi
552    if test "x$OPENJDK_TARGET_OS" = xwindows; then
553        # If it is not gcc, then assume it is the MS Visual Studio compiler
554        COMPILER_NAME=cl
555        PICFLAG=""
556        LIBRARY_PREFIX=
557        SHARED_LIBRARY='[$]1.dll'
558        STATIC_LIBRARY='[$]1.lib'
559        SHARED_LIBRARY_FLAGS="-LD"
560        SHARED_LIBRARY_SUFFIX='.dll'
561        STATIC_LIBRARY_SUFFIX='.lib'
562        OBJ_SUFFIX='.obj'
563        EXE_SUFFIX='.exe'
564        SET_SHARED_LIBRARY_NAME=''
565        SET_SHARED_LIBRARY_MAPFILE=''
566        SET_SHARED_LIBRARY_ORIGIN=''
567        SET_EXECUTABLE_ORIGIN=''
568    fi
569fi
570
571AC_SUBST(OBJ_SUFFIX)
572AC_SUBST(SHARED_LIBRARY)
573AC_SUBST(STATIC_LIBRARY)
574AC_SUBST(LIBRARY_PREFIX)
575AC_SUBST(SHARED_LIBRARY_SUFFIX)
576AC_SUBST(STATIC_LIBRARY_SUFFIX)
577AC_SUBST(EXE_SUFFIX)
578AC_SUBST(SHARED_LIBRARY_FLAGS)
579AC_SUBST(SET_SHARED_LIBRARY_NAME)
580AC_SUBST(SET_SHARED_LIBRARY_MAPFILE)
581AC_SUBST(C_FLAG_REORDER)
582AC_SUBST(CXX_FLAG_REORDER)
583AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
584AC_SUBST(SET_EXECUTABLE_ORIGIN)
585AC_SUBST(POST_STRIP_CMD)
586AC_SUBST(POST_MCS_CMD)
587
588# The (cross) compiler is now configured, we can now test capabilities
589# of the target platform.
590])
591
592AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_OPTIMIZATION],
593[
594
595###############################################################################
596#
597# Setup the opt flags for different compilers
598# and different operating systems.
599#
600
601#
602# NOTE: check for -mstackrealign needs to be below potential addition of -m32
603#
604if test "x$OPENJDK_TARGET_CPU_BITS" = x32 && test "x$OPENJDK_TARGET_OS" = xmacosx; then
605    # On 32-bit MacOSX the OS requires C-entry points to be 16 byte aligned.
606    # While waiting for a better solution, the current workaround is to use -mstackrealign.
607    CFLAGS="$CFLAGS -mstackrealign"
608    AC_MSG_CHECKING([if 32-bit compiler supports -mstackrealign])
609    AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
610                   [
611		        AC_MSG_RESULT([yes])
612                   ],
613	           [
614		        AC_MSG_RESULT([no])
615	                AC_MSG_ERROR([The selected compiler $CXX does not support -mstackrealign! Try to put another compiler in the path.])
616	           ])
617fi
618
619C_FLAG_DEPS="-MMD -MF"
620CXX_FLAG_DEPS="-MMD -MF"
621
622case $COMPILER_TYPE in
623  CC )
624    D_FLAG="-g"
625    case $COMPILER_NAME in
626      gcc )
627      	case $OPENJDK_TARGET_OS in
628	  macosx )
629	    # On MacOSX we optimize for size, something
630	    # we should do for all platforms?
631	    C_O_FLAG_HI="-Os"
632	    C_O_FLAG_NORM="-Os"
633	    C_O_FLAG_NONE=""
634	    ;;
635	  *)
636	    C_O_FLAG_HI="-O3"
637	    C_O_FLAG_NORM="-O2"
638	    C_O_FLAG_NONE="-O0"
639	    CFLAGS_DEBUG_SYMBOLS="-g"
640	    CXXFLAGS_DEBUG_SYMBOLS="-g"
641	    if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" && test "x$DEBUG_LEVEL" = "xfastdebug"; then
642	       CFLAGS_DEBUG_SYMBOLS="-g1"
643	       CXXFLAGS_DEBUG_SYMBOLS="-g1"
644	    fi
645	    ;;
646	esac
647        CXX_O_FLAG_HI="$C_O_FLAG_HI"
648        CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
649        CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
650        ;;
651      ossc )
652        #
653        # Forte has different names for this with their C++ compiler...
654        #
655        C_FLAG_DEPS="-xMMD -xMF"
656        CXX_FLAG_DEPS="-xMMD -xMF"
657
658        # Extra options used with HIGHEST
659        #
660        # WARNING: Use of OPTIMIZATION_LEVEL=HIGHEST in your Makefile needs to be
661        #          done with care, there are some assumptions below that need to
662        #          be understood about the use of pointers, and IEEE behavior.
663        #
664        # Use non-standard floating point mode (not IEEE 754)
665        CC_HIGHEST="$CC_HIGHEST -fns"
666        # Do some simplification of floating point arithmetic (not IEEE 754)
667        CC_HIGHEST="$CC_HIGHEST -fsimple"
668        # Use single precision floating point with 'float'
669        CC_HIGHEST="$CC_HIGHEST -fsingle"
670        # Assume memory references via basic pointer types do not alias
671        #   (Source with excessing pointer casting and data access with mixed 
672        #    pointer types are not recommended)
673        CC_HIGHEST="$CC_HIGHEST -xalias_level=basic"
674        # Use intrinsic or inline versions for math/std functions
675        #   (If you expect perfect errno behavior, do not use this)
676        CC_HIGHEST="$CC_HIGHEST -xbuiltin=%all"
677        # Loop data dependency optimizations (need -xO3 or higher)
678        CC_HIGHEST="$CC_HIGHEST -xdepend"
679        # Pointer parameters to functions do not overlap
680        #   (Similar to -xalias_level=basic usage, but less obvious sometimes.
681        #    If you pass in multiple pointers to the same data, do not use this)
682        CC_HIGHEST="$CC_HIGHEST -xrestrict"
683        # Inline some library routines
684        #   (If you expect perfect errno behavior, do not use this)
685        CC_HIGHEST="$CC_HIGHEST -xlibmil"
686        # Use optimized math routines
687        #   (If you expect perfect errno behavior, do not use this)
688        #  Can cause undefined external on Solaris 8 X86 on __sincos, removing for now
689        #CC_HIGHEST="$CC_HIGHEST -xlibmopt"
690
691        if test "x$OPENJDK_TARGET_CPU" = xsparc; then
692          CFLAGS_JDK="${CFLAGS_JDK} -xmemalign=4s"
693          CXXFLAGS_JDK="${CXXFLAGS_JDK} -xmemalign=4s"
694        fi
695
696        case $OPENJDK_TARGET_CPU_ARCH in
697          x86)
698            C_O_FLAG_HIGHEST="-xO4 -Wu,-O4~yz $CC_HIGHEST -xregs=no%frameptr"
699            C_O_FLAG_HI="-xO4 -Wu,-O4~yz -xregs=no%frameptr"
700            C_O_FLAG_NORM="-xO2 -Wu,-O2~yz -xregs=no%frameptr"
701            C_O_FLAG_NONE="-xregs=no%frameptr"
702            CXX_O_FLAG_HIGHEST="-xO4 -Qoption ube -O4~yz $CC_HIGHEST -xregs=no%frameptr"
703            CXX_O_FLAG_HI="-xO4 -Qoption ube -O4~yz -xregs=no%frameptr"
704            CXX_O_FLAG_NORM="-xO2 -Qoption ube -O2~yz -xregs=no%frameptr"
705            CXX_O_FLAG_NONE="-xregs=no%frameptr"
706            if test "x$OPENJDK_TARGET_CPU" = xx86; then
707               C_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST -xchip=pentium"
708               CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HIGHEST -xchip=pentium"
709            fi
710            ;;
711          sparc)
712            CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
713            CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
714            C_O_FLAG_HIGHEST="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
715            C_O_FLAG_HI="-xO4 -Wc,-Qrm-s -Wc,-Qiselect-T0"
716            C_O_FLAG_NORM="-xO2 -Wc,-Qrm-s -Wc,-Qiselect-T0"
717            C_O_FLAG_NONE=""
718            CXX_O_FLAG_HIGHEST="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0 $CC_HIGHEST -xprefetch=auto,explicit -xchip=ultra"
719            CXX_O_FLAG_HI="-xO4 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
720            CXX_O_FLAG_NORM="-xO2 -Qoption cg -Qrm-s -Qoption cg -Qiselect-T0"
721            CXX_O_FLAG_NONE=""
722            ;;
723        esac
724
725    CFLAGS_DEBUG_SYMBOLS="-g -xs"
726    CXXFLAGS_DEBUG_SYMBOLS="-g0 -xs"
727    esac
728    ;;
729  CL )
730    D_FLAG=
731    C_O_FLAG_HIGHEST="-O2"
732    C_O_FLAG_HI="-O1"
733    C_O_FLAG_NORM="-O1"
734    C_O_FLAG_NONE="-Od"
735    CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
736    CXX_O_FLAG_HI="$C_O_FLAG_HI"
737    CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
738    CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
739    ;;
740esac
741
742if test -z "$C_O_FLAG_HIGHEST"; then
743   C_O_FLAG_HIGHEST="$C_O_FLAG_HI"
744fi
745
746if test -z "$CXX_O_FLAG_HIGHEST"; then
747   CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_HI"
748fi
749
750AC_SUBST(C_O_FLAG_HIGHEST)
751AC_SUBST(C_O_FLAG_HI)
752AC_SUBST(C_O_FLAG_NORM)
753AC_SUBST(C_O_FLAG_NONE)
754AC_SUBST(CXX_O_FLAG_HIGHEST)
755AC_SUBST(CXX_O_FLAG_HI)
756AC_SUBST(CXX_O_FLAG_NORM)
757AC_SUBST(CXX_O_FLAG_NONE)
758AC_SUBST(C_FLAG_DEPS)
759AC_SUBST(CXX_FLAG_DEPS)
760])
761
762AC_DEFUN_ONCE([TOOLCHAIN_SETUP_COMPILER_FLAGS_FOR_JDK],
763[
764
765if test "x$CFLAGS" != "x${ADDED_CFLAGS}"; then
766   AC_MSG_WARN([Ignoring CFLAGS($CFLAGS) found in environment. Use --with-extra-cflags])
767fi
768
769if test "x$CXXFLAGS" != "x${ADDED_CXXFLAGS}"; then
770   AC_MSG_WARN([Ignoring CXXFLAGS($CXXFLAGS) found in environment. Use --with-extra-cxxflags])
771fi
772
773if test "x$LDFLAGS" != "x${ADDED_LDFLAGS}"; then
774   AC_MSG_WARN([Ignoring LDFLAGS($LDFLAGS) found in environment. Use --with-extra-ldflags])
775fi
776
777AC_ARG_WITH(extra-cflags, [AS_HELP_STRING([--with-extra-cflags],
778    [extra flags to be used when compiling jdk c-files])])
779
780AC_ARG_WITH(extra-cxxflags, [AS_HELP_STRING([--with-extra-cxxflags],
781    [extra flags to be used when compiling jdk c++-files])])
782
783AC_ARG_WITH(extra-ldflags, [AS_HELP_STRING([--with-extra-ldflags],
784    [extra flags to be used when linking jdk])])
785
786CFLAGS_JDK="${CFLAGS_JDK} $with_extra_cflags"
787CXXFLAGS_JDK="${CXXFLAGS_JDK} $with_extra_cxxflags"
788LDFLAGS_JDK="${LDFLAGS_JDK} $with_extra_ldflags"
789
790# Hotspot needs these set in their legacy form
791LEGACY_EXTRA_CFLAGS=$with_extra_cflags
792LEGACY_EXTRA_CXXFLAGS=$with_extra_cxxflags
793LEGACY_EXTRA_LDFLAGS=$with_extra_ldflags
794
795AC_SUBST(LEGACY_EXTRA_CFLAGS)
796AC_SUBST(LEGACY_EXTRA_CXXFLAGS)
797AC_SUBST(LEGACY_EXTRA_LDFLAGS)
798
799###############################################################################
800#
801# Now setup the CFLAGS and LDFLAGS for the JDK build.
802# Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
803#
804case $COMPILER_NAME in
805      gcc )
806      	  CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -W -Wall -Wno-unused -Wno-parentheses \
807                          -pipe \
808                          -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
809	  case $OPENJDK_TARGET_CPU_ARCH in
810	  arm )
811            # on arm we don't prevent gcc to omit frame pointer but do prevent strict aliasing
812	    CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
813	  ;;
814	  ppc )
815            # on ppc we don't prevent gcc to omit frame pointer nor strict-aliasing
816	  ;;
817	  * )
818	    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -fno-omit-frame-pointer"
819	    CFLAGS_JDK="${CFLAGS_JDK} -fno-strict-aliasing"
820          ;;
821	  esac
822          ;;
823      ossc )
824          CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
825          case $OPENJDK_TARGET_CPU_ARCH in
826          x86 )
827            CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DcpuIntel -Di586 -D$OPENJDK_TARGET_CPU_LEGACY_LIB"
828       	    CFLAGS_JDK="$CFLAGS_JDK -erroff=E_BAD_PRAGMA_PACK_VALUE"
829          ;;
830          esac
831
832      	  CFLAGS_JDK="$CFLAGS_JDK -xc99=%none -xCC -errshort=tags -Xa -v -mt -W0,-noglobal"
833      	  CXXFLAGS_JDK="$CXXFLAGS_JDK -errtags=yes +w -mt -features=no%except -DCC_NOEX -norunpath -xnolib"
834
835          LDFLAGS_JDK="$LDFLAGS_JDK -z defs -xildoff -ztext"
836          LDFLAGS_CXX_JDK="$LDFLAGS_CXX_JDK -norunpath -xnolib"
837          ;;
838      cl )
839          CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -Zi -MD -Zc:wchar_t- -W3 -wd4800 \
840               -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB -DWIN32_LEAN_AND_MEAN \
841	       -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
842	       -DWIN32 -DIAL"
843          case $OPENJDK_TARGET_CPU in
844              x86 )
845                  CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_X86_ -Dx86"
846                  ;;
847              x86_64 )
848                  CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_AMD64_ -Damd64"
849                  ;;
850          esac
851          ;;
852esac
853
854###############################################################################
855
856CCXXFLAGS_JDK="$CCXXFLAGS_JDK $ADD_LP64"
857
858# The package path is used only on macosx?
859PACKAGE_PATH=/opt/local
860AC_SUBST(PACKAGE_PATH)
861
862if test "x$OPENJDK_TARGET_CPU_ENDIAN" = xlittle; then
863    # The macro _LITTLE_ENDIAN needs to be defined the same to avoid the
864    #   Sun C compiler warning message: warning: macro redefined: _LITTLE_ENDIAN
865    #   (The Solaris X86 system defines this in file /usr/include/sys/isa_defs.h).
866    #   Note: -Dmacro         is the same as    #define macro 1
867    #         -Dmacro=	    is the same as    #define macro
868    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
869        CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN="
870    else
871        CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_LITTLE_ENDIAN"
872    fi
873else
874    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -D_BIG_ENDIAN"
875fi
876if test "x$OPENJDK_TARGET_OS" = xlinux; then
877    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DLINUX"
878fi
879if test "x$OPENJDK_TARGET_OS" = xwindows; then
880    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DWINDOWS"
881fi
882if test "x$OPENJDK_TARGET_OS" = xsolaris; then
883    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DSOLARIS"
884fi
885if test "x$OPENJDK_TARGET_OS" = xmacosx; then
886    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMACOSX -D_ALLBSD_SOURCE"
887    # Adding these macros will make it an error to link to mac APIs newer than OS version 10.7
888    MACOSX_REQUIRED_VERSION=1070
889    AC_SUBST(MACOSX_REQUIRED_VERSION)
890    CCXXFLAGS_JDK="$CCXXFLAGS_JDK -DMAC_OS_X_VERSION_MAX_ALLOWED=\$(MACOSX_REQUIRED_VERSION) -DMAC_OS_X_VERSION_MIN_REQUIRED=\$(MACOSX_REQUIRED_VERSION)" 
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