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 ################################################################################
  27 # Check if a potential freeype library match is correct and usable
  28 ################################################################################
  29 AC_DEFUN([LIB_CHECK_POTENTIAL_FREETYPE],
  30 [
  31   POTENTIAL_FREETYPE_INCLUDE_PATH="$1"
  32   POTENTIAL_FREETYPE_LIB_PATH="$2"
  33   METHOD="$3"
  34 
  35   # Let's start with an optimistic view of the world :-)
  36   FOUND_FREETYPE=yes
  37 
  38   # First look for the canonical freetype main include file ft2build.h.
  39   if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
  40     # Oh no! Let's try in the freetype2 directory.
  41     POTENTIAL_FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH/freetype2"
  42     if ! test -s "$POTENTIAL_FREETYPE_INCLUDE_PATH/ft2build.h"; then
  43       # Fail.
  44       FOUND_FREETYPE=no
  45     fi
  46   fi
  47 
  48   if test "x$FOUND_FREETYPE" = "xyes"; then
  49     # Include file found, let's continue the sanity check.
  50     AC_MSG_NOTICE([Found freetype include files at $POTENTIAL_FREETYPE_INCLUDE_PATH using $METHOD])
  51 
  52     FREETYPE_LIB_NAME="${LIBRARY_PREFIX}${FREETYPE_BASE_NAME}${SHARED_LIBRARY_SUFFIX}"
  53     if ! test -s "$POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME"; then
  54       AC_MSG_NOTICE([Could not find $POTENTIAL_FREETYPE_LIB_PATH/$FREETYPE_LIB_NAME. Ignoring location.])
  55       FOUND_FREETYPE=no
  56     else
  57       if test "x$OPENJDK_TARGET_OS" = "xsolaris" \
  58           && test -s "$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR/$FREETYPE_LIB_NAME"; then
  59         # Found lib in isa dir, use that instead.
  60         POTENTIAL_FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH$OPENJDK_TARGET_CPU_ISADIR"
  61         AC_MSG_NOTICE([Rewriting to use $POTENTIAL_FREETYPE_LIB_PATH instead])
  62       fi
  63     fi
  64   fi
  65 
  66   if test "x$FOUND_FREETYPE" = "xyes"; then
  67     FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH"
  68     AC_MSG_CHECKING([for freetype includes])
  69     AC_MSG_RESULT([$FREETYPE_INCLUDE_PATH])
  70     FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH"
  71     AC_MSG_CHECKING([for freetype libraries])
  72     AC_MSG_RESULT([$FREETYPE_LIB_PATH])
  73   fi
  74 ])
  75 
  76 ################################################################################
  77 # Setup freetype (The FreeType2 font rendering library)
  78 ################################################################################
  79 AC_DEFUN_ONCE([LIB_SETUP_FREETYPE],
  80 [
  81   AC_ARG_WITH(freetype, [AS_HELP_STRING([--with-freetype],
  82       [specify whether to use 'system' or 'bundled' freetype. Other values are errors.
  83        The selected option applies to both build time and run time.
  84        The default behaviour can be platform dependent.
  85        If using 'system' and either the include files or libraries cannot be
  86        located automatically, then additionally specify both using
  87        --with-freetype-include and --with-freetype-lib.])])
  88   AC_ARG_WITH(freetype-include, [AS_HELP_STRING([--with-freetype-include],
  89       [specify directory for the freetype include files])])
  90   AC_ARG_WITH(freetype-lib, [AS_HELP_STRING([--with-freetype-lib],
  91       [specify directory for the freetype library])])
  92 
  93   # This setup is to verify access to system installed freetype header and libraries.
  94   # On Windows and MacOS this does not apply and using these options will report an error.
  95   # On other platforms (Linux, Solaris, and perhaps AIX), they will default to using
  96   # the system libraries. If they are found automatically, nothing need be done.
  97   # If they are not found, the configure "--with-freetype-*" options may be used to fix that.
  98   # If the preference is to bundle on these platforms then use --with-freetype=bundled
  99   FREETYPE_BASE_NAME=freetype
 100   FREETYPE_CFLAGS=
 101   FREETYPE_LIBS=
 102 
 103   if (test "x$with_freetype_include" = "x"  && test "x$with_freetype_lib" != "x") || \
 104      (test "x$with_freetype_include" != "x"  && test "x$with_freetype_lib" = "x"); then
 105        AC_MSG_ERROR(['must specify both or neither of --with_freetype_include and --with_freetype_lib])
 106   fi
 107 
 108   FREETYPE_TO_USE=bundled
 109   if (test "x$OPENJDK_TARGET_OS" != "xwindows" && test "x$OPENJDK_TARGET_OS" != "xmacosx"); then
 110     FREETYPE_TO_USE=system
 111   fi
 112   if (test "x$with_freetype" != "x"); then
 113     if (test "x$with_freetype" = "xsystem"); then
 114       FREETYPE_TO_USE=system
 115     elif (test "x$with_freetype" = "xbundled"); then
 116       FREETYPE_TO_USE=bundled
 117       if (test "x$with_freetype_include" != "x"  || test "x$with_freetype_lib" != "x"); then
 118         AC_MSG_ERROR(['bundled' cannot be specified with --with_freetype_include and --with_freetype_lib])
 119       fi
 120     else
 121        AC_MSG_ERROR(['valid values for --with-freetype are 'system' and 'bundled'])
 122     fi
 123   fi
 124 
 125   if (test "x$with_freetype_include" != "x"  && test "x$with_freetype_lib" != "x"); then 
 126       FREETYPE_TO_USE=system
 127   fi
 128 
 129   if (test "x$FREETYPE_TO_USE" = "xsystem") && \
 130      (test "x$OPENJDK_TARGET_OS" = "xwindows" || test "x$OPENJDK_TARGET_OS" = "xmacosx"); then
 131        AC_MSG_ERROR([Only bundled freetype can be specified on Mac and Windows])
 132   fi
 133 
 134   if (test "x$with_freetype_include" != "x"); then
 135     POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype_include"
 136   fi
 137   if (test "x$with_freetype_lib" != "x"); then
 138     POTENTIAL_FREETYPE_LIB_PATH="$with_freetype_lib"
 139   fi
 140 
 141   if (test "x$FREETYPE_TO_USE" = "xsystem"); then
 142     if (test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" != "x" && test "x$POTENTIAL_FREETYPE_LIB_PATH" != "x"); then
 143       # Okay, we got it. Check that it works.
 144       LIB_CHECK_POTENTIAL_FREETYPE($POTENTIAL_FREETYPE_INCLUDE_PATH, $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype])
 145       if (test "x$FOUND_FREETYPE" != "xyes"); then
 146         AC_MSG_ERROR([Can not find or use freetype at location given by --with-freetype-lib|include])
 147       fi
 148     else
 149       # User did not specify a location, but asked for system freetype. Try to locate it.
 150 
 151       # If we have a sysroot, assume that's where we are supposed to look and skip pkg-config.
 152       if (test "x$SYSROOT" = "x"); then
 153         if (test "x$FOUND_FREETYPE" != "xyes"); then
 154           # Check modules using pkg-config, but only if we have it (ugly output results otherwise)
 155           if (test "x$PKG_CONFIG" != "x"); then
 156             PKG_CHECK_MODULES(FREETYPE, freetype2, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
 157             if (test "x$FOUND_FREETYPE" = "xyes"); then
 158               # On solaris, pkg_check adds -lz to freetype libs, which isn't necessary for us.
 159               FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's/-lz//g'`
 160               # 64-bit libs for Solaris x86 are installed in the amd64 subdirectory, change lib to lib/amd64
 161               if (test "x$OPENJDK_TARGET_OS" = "xsolaris" && test "x$OPENJDK_TARGET_CPU" = "xx86_64"); then
 162                 FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's?/lib?/lib/amd64?g'`
 163               fi
 164               AC_MSG_CHECKING([for freetype])
 165               AC_MSG_RESULT([yes (using pkg-config)])
 166             fi
 167           fi
 168         fi
 169       fi
 170 
 171       if (test "x$FOUND_FREETYPE" != "xyes"); then
 172         # Check in well-known locations
 173         FREETYPE_BASE_DIR="$SYSROOT/usr"
 174         LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 175 
 176         if (test "x$FOUND_FREETYPE" != "xyes"); then
 177           FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
 178           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 179         fi
 180         if (test "x$FOUND_FREETYPE" != "xyes"); then
 181           FREETYPE_BASE_DIR="$SYSROOT/usr/local"
 182           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 183         fi
 184 
 185         if (test "x$FOUND_FREETYPE" != "xyes"); then
 186           FREETYPE_BASE_DIR="$SYSROOT/usr"
 187           if (test "x$OPENJDK_TARGET_CPU_BITS" = "x64"); then
 188             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/$OPENJDK_TARGET_CPU-linux-gnu], [well-known location])
 189             if (test "x$FOUND_FREETYPE" != "xyes"); then
 190               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib64], [well-known location])
 191             fi
 192           else
 193             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
 194             if (test "x$FOUND_FREETYPE" != "xyes"); then
 195               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib32], [well-known location])
 196             fi
 197           fi
 198         fi
 199       fi # end check in well-known locations
 200 
 201       if (test "x$FOUND_FREETYPE" != "xyes"); then
 202         HELP_MSG_MISSING_DEPENDENCY([freetype])
 203         AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
 204       fi
 205     fi # end user specified settings
 206 
 207     # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
 208     if (test "x$FREETYPE_CFLAGS" = "x"); then
 209       if (test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype); then
 210         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
 211       else
 212         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
 213       fi
 214     fi
 215 
 216     if (test "x$FREETYPE_LIBS" = "x"); then
 217       FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -l$FREETYPE_BASE_NAME"
 218     fi
 219   fi
 220 
 221 
 222     AC_MSG_RESULT([Using freetype: $FREETYPE_TO_USE])
 223 
 224 
 225   AC_SUBST(FREETYPE_TO_USE)
 226   AC_SUBST(FREETYPE_CFLAGS)
 227   AC_SUBST(FREETYPE_LIBS)
 228 ])