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