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 they will default to using the
  89   # system libraries. If they are found automatically, nothing need be done.
  90   # If they are not found, the configure "--with-freetype-*" options may be
  91   # used to fix that. If the preference is to bundle on these platforms then
  92   # 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               AC_MSG_CHECKING([for freetype])
 164               AC_MSG_RESULT([yes (using pkg-config)])
 165             fi
 166           fi
 167         fi
 168       fi
 169 
 170       if test "x$FOUND_FREETYPE" != "xyes" ; then
 171         # Check in well-known locations
 172         FREETYPE_BASE_DIR="$SYSROOT/usr"
 173 
 174         if test "x$OPENJDK_TARGET_CPU_BITS" = "x64" ; then
 175           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 176               [$FREETYPE_BASE_DIR/lib/$OPENJDK_TARGET_CPU-linux-gnu], [well-known location])
 177           if test "x$FOUND_FREETYPE" != "xyes" ; then
 178             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 179                 [$FREETYPE_BASE_DIR/lib64], [well-known location])
 180           fi
 181         else
 182           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 183               [$FREETYPE_BASE_DIR/lib/i386-linux-gnu], [well-known location])
 184           if test "x$FOUND_FREETYPE" != "xyes" ; then
 185             LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 186                 [$FREETYPE_BASE_DIR/lib32], [well-known location])
 187           fi
 188         fi
 189 
 190         if test "x$FOUND_FREETYPE" != "xyes" ; then
 191           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 192               [$FREETYPE_BASE_DIR/lib], [well-known location])
 193         fi
 194 
 195         if test "x$FOUND_FREETYPE" != "xyes" ; then
 196           FREETYPE_BASE_DIR="$SYSROOT/usr/X11"
 197           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 198               [$FREETYPE_BASE_DIR/lib], [well-known location])
 199         fi
 200 
 201         if test "x$FOUND_FREETYPE" != "xyes" ; then
 202           FREETYPE_BASE_DIR="$SYSROOT/usr/local"
 203           LIB_CHECK_POTENTIAL_FREETYPE([$FREETYPE_BASE_DIR/include],
 204               [$FREETYPE_BASE_DIR/lib], [well-known location])
 205         fi
 206       fi # end check in well-known locations
 207 
 208       if test "x$FOUND_FREETYPE" != "xyes" ; then
 209         HELP_MSG_MISSING_DEPENDENCY([freetype])
 210         AC_MSG_ERROR([Could not find freetype! $HELP_MSG ])
 211       fi
 212     fi # end user specified settings
 213 
 214     # Set FREETYPE_CFLAGS, _LIBS and _LIB_PATH from include and lib dir.
 215     if test "x$FREETYPE_CFLAGS" = "x" ; then
 216       if test -d $FREETYPE_INCLUDE_PATH/freetype2/freetype ; then
 217         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH/freetype2 -I$FREETYPE_INCLUDE_PATH"
 218       else
 219         FREETYPE_CFLAGS="-I$FREETYPE_INCLUDE_PATH"
 220       fi
 221     fi
 222 
 223     if test "x$FREETYPE_LIBS" = "x" ; then
 224       FREETYPE_LIBS="-L$FREETYPE_LIB_PATH -l$FREETYPE_BASE_NAME"
 225     fi
 226   fi
 227 
 228   AC_MSG_RESULT([Using freetype: $FREETYPE_TO_USE])
 229 
 230   AC_SUBST(FREETYPE_TO_USE)
 231   AC_SUBST(FREETYPE_CFLAGS)
 232   AC_SUBST(FREETYPE_LIBS)
 233 ])