1 #
   2 # Copyright (c) 2011, 2018, 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 AC_DEFUN_ONCE([LIB_SETUP_INIT],
  27 [
  28 
  29   ###############################################################################
  30   #
  31   # OS specific settings that we never will need to probe.
  32   #
  33   if test "x$OPENJDK_TARGET_OS" = xlinux; then
  34     AC_MSG_CHECKING([what is not needed on Linux?])
  35     PULSE_NOT_NEEDED=yes
  36     AC_MSG_RESULT([pulse])
  37   fi
  38 
  39   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
  40     AC_MSG_CHECKING([what is not needed on Solaris?])
  41     ALSA_NOT_NEEDED=yes
  42     PULSE_NOT_NEEDED=yes
  43     AC_MSG_RESULT([alsa pulse])
  44   fi
  45 
  46   if test "x$OPENJDK_TARGET_OS" = xaix; then
  47     AC_MSG_CHECKING([what is not needed on AIX?])
  48     ALSA_NOT_NEEDED=yes
  49     PULSE_NOT_NEEDED=yes
  50     AC_MSG_RESULT([alsa pulse])
  51   fi
  52 
  53 
  54   if test "x$OPENJDK_TARGET_OS" = xwindows; then
  55     AC_MSG_CHECKING([what is not needed on Windows?])
  56     CUPS_NOT_NEEDED=yes
  57     ALSA_NOT_NEEDED=yes
  58     PULSE_NOT_NEEDED=yes
  59     X11_NOT_NEEDED=yes
  60     AC_MSG_RESULT([alsa cups pulse x11])
  61   fi
  62 
  63   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
  64     AC_MSG_CHECKING([what is not needed on MacOSX?])
  65     ALSA_NOT_NEEDED=yes
  66     PULSE_NOT_NEEDED=yes
  67     X11_NOT_NEEDED=yes
  68     AC_MSG_RESULT([alsa pulse x11])
  69   fi
  70 
  71   if test "x$OPENJDK_TARGET_OS" = xbsd; then
  72     AC_MSG_CHECKING([what is not needed on bsd?])
  73     ALSA_NOT_NEEDED=yes
  74     AC_MSG_RESULT([alsa])
  75   fi
  76 
  77   if test "x$OPENJDK" = "xfalse"; then
  78     FREETYPE_NOT_NEEDED=yes
  79   fi
  80 
  81   if test "x$SUPPORT_HEADFUL" = xno; then
  82     X11_NOT_NEEDED=yes
  83   fi
  84 
  85   # Deprecated and now ignored
  86   BASIC_DEPRECATED_ARG_ENABLE(macosx-runtime-support, macosx_runtime_support)
  87 ])
  88 
  89 AC_DEFUN_ONCE([LIB_SETUP_X11],
  90 [
  91 
  92   ###############################################################################
  93   #
  94   # Check for X Windows
  95   #
  96 
  97   # Check if the user has specified sysroot, but not --x-includes or --x-libraries.
  98   # Make a simple check for the libraries at the sysroot, and setup --x-includes and
  99   # --x-libraries for the sysroot, if that seems to be correct.
 100   if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
 101     if test "x$SYSROOT" != "x"; then
 102       if test "x$x_includes" = xNONE; then
 103         if test -f "$SYSROOT/usr/X11R6/include/X11/Xlib.h"; then
 104           x_includes="$SYSROOT/usr/X11R6/include"
 105         elif test -f "$SYSROOT/usr/include/X11/Xlib.h"; then
 106           x_includes="$SYSROOT/usr/include"
 107         fi
 108       fi
 109       if test "x$x_libraries" = xNONE; then
 110         if test -f "$SYSROOT/usr/X11R6/lib/libX11.so"; then
 111           x_libraries="$SYSROOT/usr/X11R6/lib"
 112         elif test "$SYSROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 113           x_libraries="$SYSROOT/usr/lib64"
 114         elif test -f "$SYSROOT/usr/lib/libX11.so"; then
 115           x_libraries="$SYSROOT/usr/lib"
 116         fi
 117       fi
 118     fi
 119   fi
 120 
 121   # Now let autoconf do it's magic
 122   AC_PATH_X
 123   AC_PATH_XTRA
 124 
 125   # AC_PATH_XTRA creates X_LIBS and sometimes adds -R flags. When cross compiling
 126   # this doesn't make sense so we remove it.
 127   if test "x$COMPILE_TYPE" = xcross; then
 128     X_LIBS=`$ECHO $X_LIBS | $SED 's/-R \{0,1\}[[^ ]]*//g'`
 129   fi
 130 
 131   if test "x$no_x" = xyes && test "x$X11_NOT_NEEDED" != xyes; then
 132     HELP_MSG_MISSING_DEPENDENCY([x11])
 133     AC_MSG_ERROR([Could not find X11 libraries. $HELP_MSG])
 134   fi
 135 
 136 
 137   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
 138     OPENWIN_HOME="/usr/openwin"
 139     X_CFLAGS="-I$SYSROOT$OPENWIN_HOME/include -I$SYSROOT$OPENWIN_HOME/include/X11/extensions"
 140     X_LIBS="-L$SYSROOT$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
 141         -L$SYSROOT$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR \
 142         -R$OPENWIN_HOME/sfw/lib$OPENJDK_TARGET_CPU_ISADIR \
 143         -R$OPENWIN_HOME/lib$OPENJDK_TARGET_CPU_ISADIR"
 144   fi
 145 
 146   #
 147   # Weird Sol10 something check...TODO change to try compile
 148   #
 149   if test "x${OPENJDK_TARGET_OS}" = xsolaris; then
 150     if test "`uname -r`" = "5.10"; then
 151       if test "`${EGREP} -c XLinearGradient ${OPENWIN_HOME}/share/include/X11/extensions/Xrender.h`" = "0"; then
 152         X_CFLAGS="${X_CFLAGS} -DSOLARIS10_NO_XRENDER_STRUCTS"
 153       fi
 154     fi
 155   fi
 156 
 157   AC_LANG_PUSH(C)
 158   OLD_CFLAGS="$CFLAGS"
 159   CFLAGS="$CFLAGS $X_CFLAGS"
 160 
 161   # Need to include Xlib.h and Xutil.h to avoid "present but cannot be compiled" warnings on Solaris 10
 162   AC_CHECK_HEADERS([X11/extensions/shape.h X11/extensions/Xrender.h X11/extensions/XTest.h X11/Intrinsic.h],
 163       [X11_A_OK=yes],
 164       [X11_A_OK=no; break],
 165       [
 166         # include <X11/Xlib.h>
 167         # include <X11/Xutil.h>
 168       ]
 169   )
 170 
 171   CFLAGS="$OLD_CFLAGS"
 172   AC_LANG_POP(C)
 173 
 174   if test "x$X11_A_OK" = xno && test "x$X11_NOT_NEEDED" != xyes; then
 175     HELP_MSG_MISSING_DEPENDENCY([x11])
 176     AC_MSG_ERROR([Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). $HELP_MSG])
 177   fi
 178 
 179   AC_SUBST(X_CFLAGS)
 180   AC_SUBST(X_LIBS)
 181 ])
 182 
 183 AC_DEFUN_ONCE([LIB_SETUP_CUPS],
 184 [
 185 
 186   ###############################################################################
 187   #
 188   # The common unix printing system cups is used to print from java.
 189   #
 190   AC_ARG_WITH(cups, [AS_HELP_STRING([--with-cups],
 191       [specify prefix directory for the cups package
 192       (expecting the headers under PATH/include)])])
 193   AC_ARG_WITH(cups-include, [AS_HELP_STRING([--with-cups-include],
 194       [specify directory for the cups include files])])
 195 
 196   if test "x$CUPS_NOT_NEEDED" = xyes; then
 197     if test "x${with_cups}" != x || test "x${with_cups_include}" != x; then
 198       AC_MSG_WARN([cups not used, so --with-cups is ignored])
 199     fi
 200     CUPS_CFLAGS=
 201   else
 202     CUPS_FOUND=no
 203 
 204     if test "x${with_cups}" = xno || test "x${with_cups_include}" = xno; then
 205       AC_MSG_ERROR([It is not possible to disable the use of cups. Remove the --without-cups option.])
 206     fi
 207 
 208     if test "x${with_cups}" != x; then
 209       CUPS_CFLAGS="-I${with_cups}/include"
 210       CUPS_FOUND=yes
 211     fi
 212     if test "x${with_cups_include}" != x; then
 213       CUPS_CFLAGS="-I${with_cups_include}"
 214       CUPS_FOUND=yes
 215     fi
 216     if test "x$CUPS_FOUND" = xno; then
 217       BDEPS_CHECK_MODULE(CUPS, cups, xxx, [CUPS_FOUND=yes])
 218     fi
 219     if test "x$CUPS_FOUND" = xno; then
 220       # Are the cups headers installed in the default /usr/include location?
 221       AC_CHECK_HEADERS([cups/cups.h cups/ppd.h],
 222           [
 223             CUPS_FOUND=yes
 224             CUPS_CFLAGS=
 225             DEFAULT_CUPS=yes
 226           ]
 227       )
 228     fi
 229     if test "x$CUPS_FOUND" = xno; then
 230       # Getting nervous now? Lets poke around for standard Solaris third-party
 231       # package installation locations.
 232       AC_MSG_CHECKING([for cups headers])
 233       if test -s $SYSROOT/opt/sfw/cups/include/cups/cups.h; then
 234         # An SFW package seems to be installed!
 235         CUPS_FOUND=yes
 236         CUPS_CFLAGS="-I$SYSROOT/opt/sfw/cups/include"
 237       elif test -s $SYSROOT/opt/csw/include/cups/cups.h; then
 238         # A CSW package seems to be installed!
 239         CUPS_FOUND=yes
 240         CUPS_CFLAGS="-I$SYSROOT/opt/csw/include"
 241       fi
 242       AC_MSG_RESULT([$CUPS_FOUND])
 243     fi
 244     if test "x$CUPS_FOUND" = xno; then
 245       HELP_MSG_MISSING_DEPENDENCY([cups])
 246       AC_MSG_ERROR([Could not find cups! $HELP_MSG ])
 247     fi
 248   fi
 249 
 250   AC_SUBST(CUPS_CFLAGS)
 251 
 252 ])
 253 
 254 AC_DEFUN([LIB_CHECK_POTENTIAL_FREETYPE],
 255 [
 256   POTENTIAL_FREETYPE_INCLUDE_PATH="$1"
 257   POTENTIAL_FREETYPE_LIB_PATH="$2"
 258   METHOD="$3"
 259   
 260   # First check if the files exists.
 261   if test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
 262     # We found an arbitrary include file. That's a good sign.
 263     AC_MSG_NOTICE([Found freetype include files at $POTENTIAL_FREETYPE_INCLUDE_PATH using $METHOD])
 264     FOUND_FREETYPE=yes
 265 
 266     FREETYPE_LIB_NAME="${LIBRARY_PREFIX}freetype${SHARED_LIBRARY_SUFFIX}"
 267     if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME"; then
 268       AC_MSG_NOTICE([Could not find $POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME. Ignoring location.])
 269       FOUND_FREETYPE=no
 270     else
 271       if test "x$OPENJDK_TARGET_OS" = xwindows; then
 272         # On Windows, we will need both .lib and .dll file.
 273         if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/freetype.lib"; then
 274           AC_MSG_NOTICE([Could not find $POTENTIAL_FREETYPE_LIB_PATH/freetype.lib. Ignoring location.])
 275           FOUND_FREETYPE=no
 276         fi
 277       elif test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$OPENJDK_TARGET_CPU" = xx86_64 && test -s "$POTENTIAL_FREETYPE_LIB_PATH/amd64/$FREETYPE_LIB_NAME"; then
 278         # On solaris-x86_86, default is (normally) PATH/lib/amd64. Update our guess!
 279         POTENTIAL_FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH/amd64"
 280       fi
 281     fi
 282   fi
 283 
 284   if test "x$FOUND_FREETYPE" = xyes; then
 285     BASIC_FIXUP_PATH(POTENTIAL_FREETYPE_INCLUDE_PATH)
 286     BASIC_FIXUP_PATH(POTENTIAL_FREETYPE_LIB_PATH)
 287 
 288     FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH"
 289     AC_MSG_CHECKING([for freetype includes])
 290     AC_MSG_RESULT([$FREETYPE_INCLUDE_PATH])
 291     FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH"
 292     AC_MSG_CHECKING([for freetype libraries])
 293     AC_MSG_RESULT([$FREETYPE_LIB_PATH])
 294   fi
 295 ])
 296 
 297 AC_DEFUN_ONCE([LIB_SETUP_FREETYPE],
 298 [
 299 
 300   ###############################################################################
 301   #
 302   # The ubiquitous freetype library is used to render fonts.
 303   #
 304   AC_ARG_WITH(freetype, [AS_HELP_STRING([--with-freetype],
 305       [specify prefix directory for the freetype package
 306       (expecting the libraries under PATH/lib and the headers under PATH/include)])])
 307   AC_ARG_WITH(freetype-include, [AS_HELP_STRING([--with-freetype-include],
 308       [specify directory for the freetype include files])])
 309   AC_ARG_WITH(freetype-lib, [AS_HELP_STRING([--with-freetype-lib],
 310       [specify directory for the freetype library])])
 311   AC_ARG_ENABLE(freetype-bundling, [AS_HELP_STRING([--disable-freetype-bundling],
 312       [disable bundling of the freetype library with the build result @<:@enabled on Windows or when using --with-freetype, disabled otherwise@:>@])])
 313 
 314   FREETYPE_CFLAGS=
 315   FREETYPE_LIBS=
 316   FREETYPE_BUNDLE_LIB_PATH=
 317 
 318   if test "x$FREETYPE_NOT_NEEDED" = xyes; then
 319     if test "x$with_freetype" != x || test "x$with_freetype_include" != x || test "x$with_freetype_lib" != x; then
 320       AC_MSG_WARN([freetype not used, so --with-freetype is ignored])
 321     fi
 322     if test "x$enable_freetype_bundling" != x; then
 323       AC_MSG_WARN([freetype not used, so --enable-freetype-bundling is ignored])
 324     fi
 325   else
 326     # freetype is needed to build; go get it!
 327 
 328     BUNDLE_FREETYPE="$enable_freetype_bundling"
 329 
 330     if test "x$with_freetype" != x || test "x$with_freetype_include" != x || test "x$with_freetype_lib" != x; then
 331       # User has specified settings
 332 
 333       if test "x$BUNDLE_FREETYPE" = x; then
 334         # If not specified, default is to bundle freetype
 335         BUNDLE_FREETYPE=yes
 336       fi
 337       
 338       if test "x$with_freetype" != x; then
 339         POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype/include"
 340         POTENTIAL_FREETYPE_LIB_PATH="$with_freetype/lib"
 341       fi
 342       
 343       # Allow --with-freetype-lib and --with-freetype-include to override
 344       if test "x$with_freetype_include" != x; then
 345         POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype_include"
 346       fi
 347       if test "x$with_freetype_lib" != x; then
 348         POTENTIAL_FREETYPE_LIB_PATH="$with_freetype_lib"
 349       fi
 350 
 351       if test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" != x && test "x$POTENTIAL_FREETYPE_LIB_PATH" != x; then
 352         # Okay, we got it. Check that it works.
 353         LIB_CHECK_POTENTIAL_FREETYPE($POTENTIAL_FREETYPE_INCLUDE_PATH, $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype])
 354         if test "x$FOUND_FREETYPE" != xyes; then
 355           AC_MSG_ERROR([Can not find or use freetype at location given by --with-freetype])
 356         fi
 357       else
 358         # User specified only one of lib or include. This is an error.
 359         if test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" = x ; then
 360           AC_MSG_NOTICE([User specified --with-freetype-lib but not --with-freetype-include])
 361           AC_MSG_ERROR([Need both freetype lib and include paths. Consider using --with-freetype instead.])
 362         else
 363           AC_MSG_NOTICE([User specified --with-freetype-include but not --with-freetype-lib])
 364           AC_MSG_ERROR([Need both freetype lib and include paths. Consider using --with-freetype instead.])
 365         fi
 366       fi
 367     else
 368       # User did not specify settings, but we need freetype. Try to locate it.
 369 
 370       if test "x$BUNDLE_FREETYPE" = x; then
 371         # If not specified, default is to bundle freetype only on windows
 372         if test "x$OPENJDK_TARGET_OS" = xwindows; then
 373           BUNDLE_FREETYPE=yes
 374         else
 375           BUNDLE_FREETYPE=no
 376         fi
 377       fi
 378 
 379       if test "x$FOUND_FREETYPE" != xyes; then
 380         # Check builddeps
 381         BDEPS_CHECK_MODULE(FREETYPE, freetype2, xxx, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
 382         # BDEPS_CHECK_MODULE will set FREETYPE_CFLAGS and _LIBS, but we don't get a lib path for bundling.
 383         if test "x$FOUND_FREETYPE" = xyes; then
 384           if test "x$BUNDLE_FREETYPE" = xyes; then
 385             AC_MSG_NOTICE([Found freetype using builddeps, but ignoring since we can not bundle that])
 386             FOUND_FREETYPE=no
 387           else
 388             AC_MSG_CHECKING([for freetype])
 389             AC_MSG_RESULT([yes (using builddeps)])
 390           fi
 391         fi
 392       fi
 393 
 394       # If we have a sysroot, assume that's where we are supposed to look and skip pkg-config.
 395       if test "x$SYSROOT" = x; then
 396         if test "x$FOUND_FREETYPE" != xyes; then
 397           # Check modules using pkg-config, but only if we have it (ugly output results otherwise)
 398           if test "x$PKG_CONFIG" != x; then
 399             PKG_CHECK_MODULES(FREETYPE, freetype2, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
 400             if test "x$FOUND_FREETYPE" = xyes; then
 401               # On solaris, pkg_check adds -lz to freetype libs, which isn't necessary for us.
 402               FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's/-lz//g'`
 403               # 64-bit libs for Solaris x86 are installed in the amd64 subdirectory, change lib to lib/amd64
 404               if test "x$OPENJDK_TARGET_OS" = xsolaris && test "x$OPENJDK_TARGET_CPU" = xx86_64; then
 405                 FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's?/lib?/lib/amd64?g'`
 406               fi
 407               # BDEPS_CHECK_MODULE will set FREETYPE_CFLAGS and _LIBS, but we don't get a lib path for bundling.
 408               if test "x$BUNDLE_FREETYPE" = xyes; then
 409                 AC_MSG_NOTICE([Found freetype using pkg-config, but ignoring since we can not bundle that])
 410                 FOUND_FREETYPE=no
 411               else
 412                 AC_MSG_CHECKING([for freetype])
 413                 AC_MSG_RESULT([yes (using pkg-config)])
 414               fi
 415             fi
 416           fi
 417         fi
 418       fi
 419 
 420       if test "x$FOUND_FREETYPE" != xyes; then
 421         # Check in well-known locations
 422         if test "x$OPENJDK_TARGET_OS" = xwindows; then
 423           FREETYPE_BASE_DIR="$PROGRAMFILES/GnuWin32"
 424           BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(FREETYPE_BASE_DIR)
 425           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 426           if test "x$FOUND_FREETYPE" != xyes; then
 427             FREETYPE_BASE_DIR="$ProgramW6432/GnuWin32"
 428             BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(FREETYPE_BASE_DIR)
 429             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 430           fi
 431         else
 432           FREETYPE_BASE_DIR="$SYSROOT/usr"
 433           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 434 
 435           if test "x$FOUND_FREETYPE" != xyes; then
 436             FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
 437             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 438           fi
 439 
 440           if test "x$FOUND_FREETYPE" != xyes; then
 441             FREETYPE_BASE_DIR="$SYSROOT/usr/sfw"
 442             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 443           fi
 444 
 445           if test "x$FOUND_FREETYPE" != xyes; then
 446             FREETYPE_BASE_DIR="$SYSROOT/usr"
 447             if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
 448               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/x86_64-linux-gnu], [well-known location])
 449             else
 450               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
 451               if test "x$FOUND_FREETYPE" != xyes; then
 452                 LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib32], [well-known location])
 453               fi
 454             fi
 455           fi
 456         fi
 457       fi # end check in well-known locations
 458 
 459       if test "x$FOUND_FREETYPE" != xyes; then
 460         HELP_MSG_MISSING_DEPENDENCY([freetype])
 461         AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
 462       fi
 463     fi # end user specified settings
 464 
 465     # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
 466     if test "x$FREETYPE_CFLAGS" = x; then
 467       BASIC_FIXUP_PATH(FREETYPE_INCLUDE_PATH)
 468       if test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype; then
 469         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
 470       else
 471         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
 472       fi
 473     fi
 474     
 475     if test "x$FREETYPE_LIBS" = x; then
 476       BASIC_FIXUP_PATH(FREETYPE_LIB_PATH)
 477       if test "x$OPENJDK_TARGET_OS" = xwindows; then
 478         FREETYPE_LIBS="$FREETYPE_LIB_PATH/freetype.lib"
 479       else
 480         FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -lfreetype"
 481       fi
 482     fi
 483 
 484     # Try to compile it
 485     AC_MSG_CHECKING([if we can compile and link with freetype])
 486     AC_LANG_PUSH(C++)
 487     PREV_CXXCFLAGS="$CXXFLAGS"
 488     PREV_LIBS="$LIBS"
 489     PREV_CXX="$CXX"
 490     CXXFLAGS="$CXXFLAGS $FREETYPE_CFLAGS" 
 491     LIBS="$LIBS $FREETYPE_LIBS"
 492     CXX="$FIXPATH $CXX"
 493     AC_LINK_IFELSE([AC_LANG_SOURCE([[
 494           #include<ft2build.h>
 495           #include FT_FREETYPE_H
 496           int main () {
 497             FT_Init_FreeType(NULL);
 498             return 0;
 499           }
 500         ]])],
 501         [
 502           AC_MSG_RESULT([yes])
 503         ],
 504         [
 505           AC_MSG_RESULT([no])
 506           AC_MSG_NOTICE([Could not compile and link with freetype. This might be a 32/64-bit mismatch.])
 507           AC_MSG_NOTICE([Using FREETYPE_CFLAGS=$FREETYPE_CFLAGS and FREETYPE_LIBS=$FREETYPE_LIBS])
 508           
 509           HELP_MSG_MISSING_DEPENDENCY([freetype])
 510           
 511           AC_MSG_ERROR([Can not continue without freetype. $HELP_MSG])
 512         ]
 513     )
 514     CXXCFLAGS="$PREV_CXXFLAGS"
 515     LIBS="$PREV_LIBS"
 516     CXX="$PREV_CXX"
 517     AC_LANG_POP(C++)
 518 
 519     AC_MSG_CHECKING([if we should bundle freetype])
 520     if test "x$BUNDLE_FREETYPE" = xyes; then
 521       FREETYPE_BUNDLE_LIB_PATH="$FREETYPE_LIB_PATH"
 522     fi
 523     AC_MSG_RESULT([$BUNDLE_FREETYPE])
 524 
 525   fi # end freetype needed
 526 
 527   AC_SUBST(FREETYPE_BUNDLE_LIB_PATH)
 528   AC_SUBST(FREETYPE_CFLAGS)
 529   AC_SUBST(FREETYPE_LIBS)
 530 ])
 531 
 532 AC_DEFUN_ONCE([LIB_SETUP_ALSA],
 533 [
 534 
 535   ###############################################################################
 536   #
 537   # Check for alsa headers and libraries. Used on Linux/GNU systems.
 538   #
 539   AC_ARG_WITH(alsa, [AS_HELP_STRING([--with-alsa],
 540       [specify prefix directory for the alsa package
 541       (expecting the libraries under PATH/lib and the headers under PATH/include)])])
 542   AC_ARG_WITH(alsa-include, [AS_HELP_STRING([--with-alsa-include],
 543       [specify directory for the alsa include files])])
 544   AC_ARG_WITH(alsa-lib, [AS_HELP_STRING([--with-alsa-lib],
 545       [specify directory for the alsa library])])
 546 
 547   if test "x$ALSA_NOT_NEEDED" = xyes; then
 548     if test "x${with_alsa}" != x || test "x${with_alsa_include}" != x || test "x${with_alsa_lib}" != x; then
 549       AC_MSG_WARN([alsa not used, so --with-alsa is ignored])
 550     fi
 551     ALSA_CFLAGS=
 552     ALSA_LIBS=
 553   else
 554     ALSA_FOUND=no
 555 
 556     if test "x${with_alsa}" = xno || test "x${with_alsa_include}" = xno || test "x${with_alsa_lib}" = xno; then
 557       AC_MSG_ERROR([It is not possible to disable the use of alsa. Remove the --without-alsa option.])
 558     fi
 559 
 560     if test "x${with_alsa}" != x; then
 561       ALSA_LIBS="-L${with_alsa}/lib -lasound"
 562       ALSA_CFLAGS="-I${with_alsa}/include"
 563       ALSA_FOUND=yes
 564     fi
 565     if test "x${with_alsa_include}" != x; then
 566       ALSA_CFLAGS="-I${with_alsa_include}"
 567       ALSA_FOUND=yes
 568     fi
 569     if test "x${with_alsa_lib}" != x; then
 570       ALSA_LIBS="-L${with_alsa_lib} -lasound"
 571       ALSA_FOUND=yes
 572     fi
 573     if test "x$ALSA_FOUND" = xno; then
 574       BDEPS_CHECK_MODULE(ALSA, alsa, xxx, [ALSA_FOUND=yes], [ALSA_FOUND=no])
 575     fi
 576     # Do not try pkg-config if we have a sysroot set.
 577     if test "x$SYSROOT" = x; then
 578       if test "x$ALSA_FOUND" = xno; then
 579         PKG_CHECK_MODULES(ALSA, alsa, [ALSA_FOUND=yes], [ALSA_FOUND=no])
 580       fi
 581     fi
 582     if test "x$ALSA_FOUND" = xno; then
 583       AC_CHECK_HEADERS([alsa/asoundlib.h],
 584           [
 585             ALSA_FOUND=yes
 586             ALSA_CFLAGS=-Iignoreme
 587             ALSA_LIBS=-lasound
 588             DEFAULT_ALSA=yes
 589           ],
 590           [ALSA_FOUND=no])
 591     fi
 592     if test "x$ALSA_FOUND" = xno; then
 593       HELP_MSG_MISSING_DEPENDENCY([alsa])
 594       AC_MSG_ERROR([Could not find alsa! $HELP_MSG ])
 595     fi
 596   fi
 597 
 598   AC_SUBST(ALSA_CFLAGS)
 599   AC_SUBST(ALSA_LIBS)
 600 ])
 601 
 602 AC_DEFUN_ONCE([LIB_SETUP_MISC_LIBS],
 603 [
 604 
 605   ###############################################################################
 606   #
 607   # Check for the jpeg library
 608   #
 609 
 610   USE_EXTERNAL_LIBJPEG=true
 611   AC_CHECK_LIB(jpeg, main, [],
 612       [ USE_EXTERNAL_LIBJPEG=false
 613       AC_MSG_NOTICE([Will use jpeg decoder bundled with the OpenJDK source])
 614   ])
 615   AC_SUBST(USE_EXTERNAL_LIBJPEG)
 616 
 617   ###############################################################################
 618   #
 619   # Check for the gif library
 620   #
 621 
 622   AC_ARG_WITH(giflib, [AS_HELP_STRING([--with-giflib],
 623       [use giflib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
 624 
 625 
 626   AC_MSG_CHECKING([for which giflib to use])
 627 
 628   # default is bundled
 629   DEFAULT_GIFLIB=bundled
 630 
 631   #
 632   # if user didn't specify, use DEFAULT_GIFLIB
 633   #
 634   if test "x${with_giflib}" = "x"; then
 635     with_giflib=${DEFAULT_GIFLIB}
 636   fi
 637 
 638   AC_MSG_RESULT(${with_giflib})
 639 
 640   if test "x${with_giflib}" = "xbundled"; then
 641     USE_EXTERNAL_LIBGIF=false
 642   elif test "x${with_giflib}" = "xsystem"; then
 643     AC_CHECK_HEADER(gif_lib.h, [],
 644         [ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])])
 645     AC_CHECK_LIB(gif, DGifGetCode, [],
 646         [ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])])
 647 
 648     USE_EXTERNAL_LIBGIF=true
 649   else
 650     AC_MSG_ERROR([Invalid value of --with-giflib: ${with_giflib}, use 'system' or 'bundled'])
 651   fi
 652   AC_SUBST(USE_EXTERNAL_LIBGIF)
 653 
 654   ###############################################################################
 655   #
 656   # Check for the zlib library
 657   #
 658 
 659   AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib],
 660       [use zlib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
 661 
 662   AC_CHECK_LIB(z, compress,
 663       [ ZLIB_FOUND=yes ],
 664       [ ZLIB_FOUND=no ])
 665 
 666   AC_MSG_CHECKING([for which zlib to use])
 667 
 668   DEFAULT_ZLIB=bundled
 669   if test "x$OPENJDK_TARGET_OS" = xmacosx; then
 670     #
 671     # On macosx default is system...on others default is
 672     #
 673     DEFAULT_ZLIB=system
 674   fi
 675 
 676   if test "x${ZLIB_FOUND}" != "xyes"; then
 677     #
 678     # If we don't find any system...set default to bundled
 679     #
 680     DEFAULT_ZLIB=bundled
 681   fi
 682 
 683   #
 684   # If user didn't specify, use DEFAULT_ZLIB
 685   #
 686   if test "x${with_zlib}" = "x"; then
 687     with_zlib=${DEFAULT_ZLIB}
 688   fi
 689 
 690   if test "x${with_zlib}" = "xbundled"; then
 691     USE_EXTERNAL_LIBZ=false
 692     AC_MSG_RESULT([bundled])
 693   elif test "x${with_zlib}" = "xsystem"; then
 694     if test "x${ZLIB_FOUND}" = "xyes"; then
 695       USE_EXTERNAL_LIBZ=true
 696       AC_MSG_RESULT([system])
 697     else
 698       AC_MSG_RESULT([system not found])
 699       AC_MSG_ERROR([--with-zlib=system specified, but no zlib found!])
 700     fi
 701   else
 702     AC_MSG_ERROR([Invalid value for --with-zlib: ${with_zlib}, use 'system' or 'bundled'])
 703   fi
 704 
 705   AC_SUBST(USE_EXTERNAL_LIBZ)
 706 
 707   ###############################################################################
 708   LIBZIP_CAN_USE_MMAP=true
 709 
 710   AC_SUBST(LIBZIP_CAN_USE_MMAP)
 711 
 712   ###############################################################################
 713   #
 714   # Check if altzone exists in time.h
 715   #
 716 
 717   AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [return (int)altzone;])],
 718       [has_altzone=yes],
 719       [has_altzone=no])
 720   if test "x$has_altzone" = xyes; then
 721     AC_DEFINE([HAVE_ALTZONE], 1, [Define if you have the external 'altzone' variable in time.h])
 722   fi
 723 
 724   ###############################################################################
 725   #
 726   # Check the maths library
 727   #
 728 
 729   AC_CHECK_LIB(m, cos, [],
 730       [
 731         AC_MSG_NOTICE([Maths library was not found])
 732       ]
 733   )
 734   AC_SUBST(LIBM)
 735 
 736   ###############################################################################
 737   #
 738   # Check for libdl.so
 739 
 740   save_LIBS="$LIBS"
 741   LIBS=""
 742   AC_CHECK_LIB(dl,dlopen)
 743   LIBDL="$LIBS"
 744   AC_SUBST(LIBDL)
 745   LIBS="$save_LIBS"
 746 ])
 747 
 748 AC_DEFUN_ONCE([LIB_SETUP_STATIC_LINK_LIBSTDCPP],
 749 [
 750   ###############################################################################
 751   #
 752   # statically link libstdc++ before C++ ABI is stablized on Linux unless
 753   # dynamic build is configured on command line.
 754   #
 755   AC_ARG_WITH([stdc++lib], [AS_HELP_STRING([--with-stdc++lib=<static>,<dynamic>,<default>],
 756       [force linking of the C++ runtime on Linux to either static or dynamic, default is static with dynamic as fallback])],
 757       [
 758         if test "x$with_stdc__lib" != xdynamic && test "x$with_stdc__lib" != xstatic \
 759                 && test "x$with_stdc__lib" != xdefault; then
 760           AC_MSG_ERROR([Bad parameter value --with-stdc++lib=$with_stdc__lib!])
 761         fi
 762       ],
 763       [with_stdc__lib=default]
 764   )
 765 
 766   if test "x$OPENJDK_TARGET_OS" = xlinux; then
 767     # Test if -lstdc++ works.
 768     AC_MSG_CHECKING([if dynamic link of stdc++ is possible])
 769     AC_LANG_PUSH(C++)
 770     OLD_CXXFLAGS="$CXXFLAGS"
 771     CXXFLAGS="$CXXFLAGS -lstdc++"
 772     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
 773         [has_dynamic_libstdcxx=yes],
 774         [has_dynamic_libstdcxx=no])
 775     CXXFLAGS="$OLD_CXXFLAGS"
 776     AC_LANG_POP(C++)
 777     AC_MSG_RESULT([$has_dynamic_libstdcxx])
 778 
 779     # Test if stdc++ can be linked statically.
 780     AC_MSG_CHECKING([if static link of stdc++ is possible])
 781     STATIC_STDCXX_FLAGS="-Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic"
 782     AC_LANG_PUSH(C++)
 783     OLD_LIBS="$LIBS"
 784     OLD_CXX="$CXX"
 785     LIBS="$STATIC_STDCXX_FLAGS"
 786     CXX="$CC"
 787     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
 788         [has_static_libstdcxx=yes],
 789         [has_static_libstdcxx=no])
 790     LIBS="$OLD_LIBS"
 791     CXX="$OLD_CXX"
 792     AC_LANG_POP(C++)
 793     AC_MSG_RESULT([$has_static_libstdcxx])
 794 
 795     if test "x$has_static_libstdcxx" = xno && test "x$has_dynamic_libstdcxx" = xno; then
 796       AC_MSG_ERROR([Cannot link to stdc++, neither dynamically nor statically!])
 797     fi
 798 
 799     if test "x$with_stdc__lib" = xstatic && test "x$has_static_libstdcxx" = xno; then
 800       AC_MSG_ERROR([Static linking of libstdc++ was not possible!])
 801     fi
 802 
 803     if test "x$with_stdc__lib" = xdynamic && test "x$has_dynamic_libstdcxx" = xno; then
 804       AC_MSG_ERROR([Dynamic linking of libstdc++ was not possible!])
 805     fi
 806 
 807     AC_MSG_CHECKING([how to link with libstdc++])
 808     # If dynamic was requested, it's available since it would fail above otherwise.
 809     # If dynamic wasn't requested, go with static unless it isn't available.
 810     if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
 811       LIBCXX="$LIBCXX -lstdc++"
 812       LDCXX="$CXX"
 813       STATIC_CXX_SETTING="STATIC_CXX=false"
 814       AC_MSG_RESULT([dynamic])
 815     else
 816       LIBCXX="$LIBCXX $STATIC_STDCXX_FLAGS"
 817       LDCXX="$CC"
 818       STATIC_CXX_SETTING="STATIC_CXX=true"
 819       AC_MSG_RESULT([static])
 820     fi
 821   fi
 822   AC_SUBST(STATIC_CXX_SETTING)
 823 
 824   if test "x$JVM_VARIANT_ZERO" = xtrue || test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
 825     # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS
 826     PKG_CHECK_MODULES([LIBFFI], [libffi])
 827 
 828   fi
 829 
 830   if test "x$JVM_VARIANT_ZEROSHARK" = xtrue; then
 831     AC_CHECK_PROG([LLVM_CONFIG], [llvm-config], [llvm-config])
 832 
 833     if test "x$LLVM_CONFIG" != xllvm-config; then
 834       AC_MSG_ERROR([llvm-config not found in $PATH.])
 835     fi
 836 
 837     llvm_components="jit mcjit engine nativecodegen native"
 838     unset LLVM_CFLAGS
 839     for flag in $("$LLVM_CONFIG" --cxxflags); do
 840       if echo "${flag}" | grep -q '^-@<:@ID@:>@'; then
 841         if test "${flag}" != "-D_DEBUG" ; then
 842           if test "${LLVM_CFLAGS}" != "" ; then
 843             LLVM_CFLAGS="${LLVM_CFLAGS} "
 844           fi
 845           LLVM_CFLAGS="${LLVM_CFLAGS}${flag}"
 846         fi
 847       fi
 848     done
 849     llvm_version=$("${LLVM_CONFIG}" --version | sed 's/\.//; s/svn.*//')
 850     LLVM_CFLAGS="${LLVM_CFLAGS} -DSHARK_LLVM_VERSION=${llvm_version}"
 851 
 852     unset LLVM_LDFLAGS
 853     for flag in $("${LLVM_CONFIG}" --ldflags); do
 854       if echo "${flag}" | grep -q '^-L'; then
 855         if test "${LLVM_LDFLAGS}" != ""; then
 856           LLVM_LDFLAGS="${LLVM_LDFLAGS} "
 857         fi
 858         LLVM_LDFLAGS="${LLVM_LDFLAGS}${flag}"
 859       fi
 860     done
 861 
 862     unset LLVM_LIBS
 863     for flag in $("${LLVM_CONFIG}" --libs ${llvm_components}); do
 864       if echo "${flag}" | grep -q '^-l'; then
 865         if test "${LLVM_LIBS}" != ""; then
 866           LLVM_LIBS="${LLVM_LIBS} "
 867         fi
 868         LLVM_LIBS="${LLVM_LIBS}${flag}"
 869       fi
 870     done
 871 
 872     AC_SUBST(LLVM_CFLAGS)
 873     AC_SUBST(LLVM_LDFLAGS)
 874     AC_SUBST(LLVM_LIBS)
 875   fi
 876 
 877   # libCrun is the c++ runtime-library with SunStudio (roughly the equivalent of gcc's libstdc++.so)
 878   if test "x$TOOLCHAIN_TYPE" = xsolstudio && test "x$LIBCXX" = x; then
 879     LIBCXX="${SYSROOT}/usr/lib${OPENJDK_TARGET_CPU_ISADIR}/libCrun.so.1"
 880   fi
 881 
 882   # TODO better (platform agnostic) test
 883   if test "x$OPENJDK_TARGET_OS" = xmacosx && test "x$LIBCXX" = x && test "x$TOOLCHAIN_TYPE" = xgcc; then
 884     LIBCXX="-lstdc++"
 885   fi
 886 
 887   AC_SUBST(LIBCXX)
 888 ])
 889 
 890 AC_DEFUN_ONCE([LIB_SETUP_ON_WINDOWS],
 891 [
 892   if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
 893     TOOLCHAIN_SETUP_MSVCR_DLL
 894     BASIC_DEPRECATED_ARG_WITH([dxsdk])
 895     BASIC_DEPRECATED_ARG_WITH([dxsdk-lib])
 896     BASIC_DEPRECATED_ARG_WITH([dxsdk-include])
 897   fi
 898   AC_SUBST(MSVCR_DLL)
 899 ])