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), 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" \
 110       && test "x$OPENJDK_TARGET_OS" != "xaix"); then
 111     FREETYPE_TO_USE=system
 112   fi
 113   if (test "x$with_freetype" != "x"); then
 114     if (test "x$with_freetype" = "xsystem"); then
 115       FREETYPE_TO_USE=system
 116     elif (test "x$with_freetype" = "xbundled"); then
 117       FREETYPE_TO_USE=bundled
 118       if (test "x$with_freetype_include" != "x"  || test "x$with_freetype_lib" != "x"); then
 119         AC_MSG_ERROR(['bundled' cannot be specified with --with-freetype-include and --with-freetype-lib])
 120       fi
 121     else
 122        AC_MSG_ERROR(['valid values for --with-freetype are 'system' and 'bundled'])
 123     fi
 124   fi
 125 
 126   if (test "x$with_freetype_include" != "x"  && test "x$with_freetype_lib" != "x"); then 
 127       FREETYPE_TO_USE=system
 128   fi
 129 
 130   if (test "x$FREETYPE_TO_USE" = "xsystem") && \
 131      (test "x$OPENJDK_TARGET_OS" = "xwindows" || test "x$OPENJDK_TARGET_OS" = "xmacosx"); then
 132        AC_MSG_ERROR([Only bundled freetype can be specified on Mac and Windows])
 133   fi
 134 
 135   if (test "x$with_freetype_include" != "x"); then
 136     POTENTIAL_FREETYPE_INCLUDE_PATH="$with_freetype_include"
 137   fi
 138   if (test "x$with_freetype_lib" != "x"); then
 139     POTENTIAL_FREETYPE_LIB_PATH="$with_freetype_lib"
 140   fi
 141 
 142   if (test "x$FREETYPE_TO_USE" = "xsystem"); then
 143     if (test "x$POTENTIAL_FREETYPE_INCLUDE_PATH" != "x" && test "x$POTENTIAL_FREETYPE_LIB_PATH" != "x"); then
 144       # Okay, we got it. Check that it works.
 145       LIB_CHECK_POTENTIAL_FREETYPE($POTENTIAL_FREETYPE_INCLUDE_PATH, $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype])
 146       if (test "x$FOUND_FREETYPE" != "xyes"); then
 147         AC_MSG_ERROR([Can not find or use freetype at location given by --with-freetype-lib|include])
 148       fi
 149     else
 150       # User did not specify a location, but asked for system freetype. Try to locate it.
 151 
 152       # If we have a sysroot, assume that's where we are supposed to look and skip pkg-config.
 153       if (test "x$SYSROOT" = "x"); then
 154         if (test "x$FOUND_FREETYPE" != "xyes"); then
 155           # Check modules using pkg-config, but only if we have it (ugly output results otherwise)
 156           if (test "x$PKG_CONFIG" != "x"); then
 157             PKG_CHECK_MODULES(FREETYPE, freetype2, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
 158             if (test "x$FOUND_FREETYPE" = "xyes"); then
 159               # On solaris, pkg_check adds -lz to freetype libs, which isn't necessary for us.
 160               FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's/-lz//g'`
 161               # 64-bit libs for Solaris x86 are installed in the amd64 subdirectory, change lib to lib/amd64
 162               if (test "x$OPENJDK_TARGET_OS" = "xsolaris" && test "x$OPENJDK_TARGET_CPU" = "xx86_64"); then
 163                 FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's?/lib?/lib/amd64?g'`
 164               fi
 165               AC_MSG_CHECKING([for freetype])
 166               AC_MSG_RESULT([yes (using pkg-config)])
 167             fi
 168           fi
 169         fi
 170       fi
 171 
 172       if (test "x$FOUND_FREETYPE" != "xyes"); then
 173         # Check in well-known locations
 174         FREETYPE_BASE_DIR="$SYSROOT/usr"
 175         LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 176 
 177         if (test "x$FOUND_FREETYPE" != "xyes"); then
 178           FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
 179           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 180         fi
 181         if (test "x$FOUND_FREETYPE" != "xyes"); then
 182           FREETYPE_BASE_DIR="$SYSROOT/usr/local"
 183           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib], [well-known location])
 184         fi
 185 
 186         if (test "x$FOUND_FREETYPE" != "xyes"); then
 187           FREETYPE_BASE_DIR="$SYSROOT/usr"
 188           if (test "x$OPENJDK_TARGET_CPU_BITS" = "x64"); then
 189             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/$OPENJDK_TARGET_CPU-linux-gnu], [well-known location])
 190             if (test "x$FOUND_FREETYPE" != "xyes"); then
 191               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib64], [well-known location])
 192             fi
 193           else
 194             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
 195             if (test "x$FOUND_FREETYPE" != "xyes"); then
 196               LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include], [$FREETYPE_BASE_DIR/lib32], [well-known location])
 197             fi
 198           fi
 199         fi
 200       fi # end check in well-known locations
 201 
 202       if (test "x$FOUND_FREETYPE" != "xyes"); then
 203         HELP_MSG_MISSING_DEPENDENCY([freetype])
 204         AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
 205       fi
 206     fi # end user specified settings
 207 
 208     # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
 209     if (test "x$FREETYPE_CFLAGS" = "x"); then
 210       if (test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype); then
 211         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
 212       else
 213         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
 214       fi
 215     fi
 216 
 217     if (test "x$FREETYPE_LIBS" = "x"); then
 218       FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -l$FREETYPE_BASE_NAME"
 219     fi
 220   fi
 221 
 222 
 223     AC_MSG_RESULT([Using freetype: $FREETYPE_TO_USE])
 224 
 225 
 226   AC_SUBST(FREETYPE_TO_USE)
 227   AC_SUBST(FREETYPE_CFLAGS)
 228   AC_SUBST(FREETYPE_LIBS)
 229 ])