1 #
   2 # Copyright (c) 2011, 2020, 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     fi
  57   fi
  58 
  59   if test "x$FOUND_FREETYPE" = "xyes"; then
  60     FREETYPE_INCLUDE_PATH="$POTENTIAL_FREETYPE_INCLUDE_PATH"
  61     AC_MSG_CHECKING([for freetype includes])
  62     AC_MSG_RESULT([$FREETYPE_INCLUDE_PATH])
  63     FREETYPE_LIB_PATH="$POTENTIAL_FREETYPE_LIB_PATH"
  64     AC_MSG_CHECKING([for freetype libraries])
  65     AC_MSG_RESULT([$FREETYPE_LIB_PATH])
  66   fi
  67 ])
  68 
  69 ################################################################################
  70 # Setup freetype (The FreeType2 font rendering library)
  71 ################################################################################
  72 AC_DEFUN_ONCE([LIB_SETUP_FREETYPE],
  73 [
  74   AC_ARG_WITH(freetype, [AS_HELP_STRING([--with-freetype],
  75       [specify whether to use 'system' or 'bundled' freetype.
  76        The selected option applies to both build time and run time.
  77        The default behaviour can be platform dependent.
  78        If using 'system' and either the include files or libraries cannot be
  79        located automatically, then additionally specify both using
  80        --with-freetype-include and --with-freetype-lib.])])
  81   AC_ARG_WITH(freetype-include, [AS_HELP_STRING([--with-freetype-include],
  82       [specify directory for the freetype include files])])
  83   AC_ARG_WITH(freetype-lib, [AS_HELP_STRING([--with-freetype-lib],
  84       [specify directory for the freetype library])])
  85 
  86   # This setup is to verify access to system installed freetype header and
  87   # libraries. On Windows and MacOS this does not apply and using these options
  88   # will report an error. On other platforms (Linux), they will
  89   # default to using the system libraries. If they are found automatically,
  90   # nothing need be done. If they are not found, the configure
  91   # "--with-freetype-*" options may be used to fix that. If the preference is
  92   # to bundle on these platforms then use --with-freetype=bundled.
  93 
  94   FREETYPE_BASE_NAME=freetype
  95   FREETYPE_CFLAGS=
  96   FREETYPE_LIBS=
  97 
  98   if (test "x$with_freetype_include" = "x" && test "x$with_freetype_lib" != "x") || \
  99      (test "x$with_freetype_include" != "x" && test "x$with_freetype_lib" = "x"); then
 100     AC_MSG_ERROR([Must specify both or neither of --with-freetype-include and --with-freetype-lib])
 101   fi
 102 
 103   FREETYPE_TO_USE=bundled
 104   if test "x$OPENJDK_TARGET_OS" != "xwindows" && \
 105       test "x$OPENJDK_TARGET_OS" != "xmacosx" && \
 106       test "x$OPENJDK_TARGET_OS" != "xaix"; then
 107     FREETYPE_TO_USE=system
 108   fi
 109   if test "x$with_freetype" != "x" ; then
 110     if test "x$with_freetype" = "xsystem" ; then
 111       FREETYPE_TO_USE=system
 112     elif test "x$with_freetype" = "xbundled" ; then
 113       FREETYPE_TO_USE=bundled
 114       if test "x$with_freetype_include" != "x" || \
 115           test "x$with_freetype_lib" != "x" ; then
 116         AC_MSG_ERROR(['bundled' cannot be specified with --with-freetype-include and --with-freetype-lib])
 117       fi
 118     else
 119       AC_MSG_ERROR([Valid values for --with-freetype are 'system' and 'bundled'])
 120     fi
 121   fi
 122 
 123   if test "x$with_freetype_include" != "x" && \
 124       test "x$with_freetype_lib" != "x" ; then
 125     FREETYPE_TO_USE=system
 126   fi
 127 
 128   if test "x$FREETYPE_TO_USE" = "xsystem" && \
 129      (test "x$OPENJDK_TARGET_OS" = "xwindows" || \
 130      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" && \
 143         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,
 146           $POTENTIAL_FREETYPE_LIB_PATH, [--with-freetype])
 147       if test "x$FOUND_FREETYPE" != "xyes" ; then
 148         AC_MSG_ERROR([Can not find or use freetype at location given by --with-freetype-lib|include])
 149       fi
 150     else
 151       # User did not specify a location, but asked for system freetype.
 152       # Try to locate it.
 153 
 154       # If we have a sysroot, assume that's where we are supposed to look and
 155       # skip pkg-config.
 156       if test "x$SYSROOT" = "x" ; then
 157         if test "x$FOUND_FREETYPE" != "xyes" ; then
 158           # Check modules using pkg-config, but only if we have it (ugly output
 159           # results otherwise)
 160           if test "x$PKG_CONFIG" != "x" ; then
 161             PKG_CHECK_MODULES(FREETYPE, freetype2, [FOUND_FREETYPE=yes], [FOUND_FREETYPE=no])
 162             if test "x$FOUND_FREETYPE" = "xyes" ; then
 163               # On solaris, pkg_check adds -lz to freetype libs, which isn't
 164               # necessary for us.
 165               FREETYPE_LIBS=`$ECHO $FREETYPE_LIBS | $SED 's/-lz//g'`
 166               AC_MSG_CHECKING([for freetype])
 167               AC_MSG_RESULT([yes (using pkg-config)])
 168             fi
 169           fi
 170         fi
 171       fi
 172 
 173       if test "x$FOUND_FREETYPE" != "xyes" ; then
 174         # Check in well-known locations
 175         FREETYPE_BASE_DIR="$SYSROOT/usr"
 176 
 177         if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" ; then
 178           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 179               [$FREETYPE_BASE_DIR/lib/$OPENJDK_TARGET_CPU-linux-gnu], [well-known location])
 180           if test "x$FOUND_FREETYPE" != "xyes" ; then
 181             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 182                 [$FREETYPE_BASE_DIR/lib64], [well-known location])
 183           fi
 184         else
 185           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 186               [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
 187           if test "x$FOUND_FREETYPE" != "xyes" ; then
 188             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 189                 [$FREETYPE_BASE_DIR/lib32], [well-known location])
 190           fi
 191         fi
 192 
 193         if test "x$FOUND_FREETYPE" != "xyes" ; then
 194           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 195               [$FREETYPE_BASE_DIR/lib], [well-known location])
 196         fi
 197 
 198         if test "x$FOUND_FREETYPE" != "xyes" ; then
 199           FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
 200           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 201               [$FREETYPE_BASE_DIR/lib], [well-known location])
 202         fi
 203 
 204         if test "x$FOUND_FREETYPE" != "xyes" ; then
 205           FREETYPE_BASE_DIR="$SYSROOT/usr/local"
 206           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 207               [$FREETYPE_BASE_DIR/lib], [well-known location])
 208         fi
 209       fi # end check in well-known locations
 210 
 211       if test "x$FOUND_FREETYPE" != "xyes" ; then
 212         HELP_MSG_MISSING_DEPENDENCY([freetype])
 213         AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
 214       fi
 215     fi # end user specified settings
 216 
 217     # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
 218     if test "x$FREETYPE_CFLAGS" = "x" ; then
 219       if test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype ; then
 220         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
 221       else
 222         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
 223       fi
 224     fi
 225 
 226     if test "x$FREETYPE_LIBS" = "x" ; then
 227       FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -l$FREETYPE_BASE_NAME"
 228     fi
 229   fi
 230 
 231   AC_MSG_RESULT([Using freetype: $FREETYPE_TO_USE])
 232 
 233   AC_SUBST(FREETYPE_TO_USE)
 234   AC_SUBST(FREETYPE_CFLAGS)
 235   AC_SUBST(FREETYPE_LIBS)
 236 ])