1 #
   2 # Copyright (c) 2011, 2017, 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 # Setup bundled libraries.
  28 #
  29 # For libjpeg, giflib, libpng, lcms2 and zlib, the source is present in the
  30 # OpenJDK repository. Default is to use these libraries as bundled, but they
  31 # might be replaced by en external version by the user.
  32 ################################################################################
  33 AC_DEFUN_ONCE([LIB_SETUP_BUNDLED_LIBS],
  34 [
  35   LIB_SETUP_LIBJPEG
  36   LIB_SETUP_GIFLIB
  37   LIB_SETUP_LIBPNG
  38   LIB_SETUP_ZLIB
  39   LIB_SETUP_LCMS
  40 ])
  41 
  42 ################################################################################
  43 # Setup libjpeg
  44 ################################################################################
  45 AC_DEFUN_ONCE([LIB_SETUP_LIBJPEG],
  46 [
  47   AC_ARG_WITH(libjpeg, [AS_HELP_STRING([--with-libjpeg],
  48       [use libjpeg from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
  49 
  50   AC_MSG_CHECKING([for which libjpeg to use])
  51   # default is bundled
  52   DEFAULT_LIBJPEG=bundled
  53   # if user didn't specify, use DEFAULT_LIBJPEG
  54   if test "x${with_libjpeg}" = "x"; then
  55     with_libjpeg=${DEFAULT_LIBJPEG}
  56   fi
  57   AC_MSG_RESULT(${with_libjpeg})
  58 
  59   if test "x${with_libjpeg}" = "xbundled"; then
  60     USE_EXTERNAL_LIBJPEG=false
  61   elif test "x${with_libjpeg}" = "xsystem"; then
  62     AC_CHECK_HEADER(jpeglib.h, [],
  63         [ AC_MSG_ERROR([--with-libjpeg=system specified, but jpeglib.h not found!])])
  64     AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, [],
  65         [ AC_MSG_ERROR([--with-libjpeg=system specified, but no libjpeg found])])
  66 
  67     USE_EXTERNAL_LIBJPEG=true
  68   else
  69     AC_MSG_ERROR([Invalid use of --with-libjpeg: ${with_libjpeg}, use 'system' or 'bundled'])
  70   fi
  71 
  72   AC_SUBST(USE_EXTERNAL_LIBJPEG)
  73 ])
  74 
  75 ################################################################################
  76 # Setup giflib
  77 ################################################################################
  78 AC_DEFUN_ONCE([LIB_SETUP_GIFLIB],
  79 [
  80   AC_ARG_WITH(giflib, [AS_HELP_STRING([--with-giflib],
  81       [use giflib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
  82 
  83   AC_MSG_CHECKING([for which giflib to use])
  84   # default is bundled
  85   DEFAULT_GIFLIB=bundled
  86   # if user didn't specify, use DEFAULT_GIFLIB
  87   if test "x${with_giflib}" = "x"; then
  88     with_giflib=${DEFAULT_GIFLIB}
  89   fi
  90   AC_MSG_RESULT(${with_giflib})
  91 
  92   if test "x${with_giflib}" = "xbundled"; then
  93     USE_EXTERNAL_LIBGIF=false
  94   elif test "x${with_giflib}" = "xsystem"; then
  95     AC_CHECK_HEADER(gif_lib.h, [],
  96         [ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])])
  97     AC_CHECK_LIB(gif, DGifGetCode, [],
  98         [ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])])
  99 
 100     USE_EXTERNAL_LIBGIF=true
 101   else
 102     AC_MSG_ERROR([Invalid value of --with-giflib: ${with_giflib}, use 'system' or 'bundled'])
 103   fi
 104 
 105   AC_SUBST(USE_EXTERNAL_LIBGIF)
 106 ])
 107 
 108 ################################################################################
 109 # Setup libpng
 110 ################################################################################
 111 AC_DEFUN_ONCE([LIB_SETUP_LIBPNG],
 112 [
 113   AC_ARG_WITH(libpng, [AS_HELP_STRING([--with-libpng],
 114      [use libpng from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
 115 
 116   PKG_CHECK_MODULES(PNG, libpng, [LIBPNG_FOUND=yes], [LIBPNG_FOUND=no])
 117   AC_MSG_CHECKING([for which libpng to use])
 118 
 119   # default is bundled
 120   DEFAULT_LIBPNG=bundled
 121   # if user didn't specify, use DEFAULT_LIBPNG
 122   if test "x${with_libpng}" = "x"; then
 123     with_libpng=${DEFAULT_LIBPNG}
 124   fi
 125 
 126   if test "x${with_libpng}" = "xbundled"; then
 127     USE_EXTERNAL_LIBPNG=false
 128     PNG_CFLAGS=""
 129     PNG_LIBS=""
 130     AC_MSG_RESULT([bundled])
 131   elif test "x${with_libpng}" = "xsystem"; then
 132     if test "x${LIBPNG_FOUND}" = "xyes"; then
 133       # PKG_CHECK_MODULES will set PNG_CFLAGS and PNG_LIBS
 134       USE_EXTERNAL_LIBPNG=true
 135       AC_MSG_RESULT([system])
 136     else
 137       AC_MSG_RESULT([system not found])
 138       AC_MSG_ERROR([--with-libpng=system specified, but no libpng found!])
 139     fi
 140   else
 141     AC_MSG_ERROR([Invalid value of --with-libpng: ${with_libpng}, use 'system' or 'bundled'])
 142   fi
 143 
 144   AC_SUBST(USE_EXTERNAL_LIBPNG)
 145   AC_SUBST(PNG_CFLAGS)
 146   AC_SUBST(PNG_LIBS)
 147 ])
 148 
 149 ################################################################################
 150 # Setup zlib
 151 ################################################################################
 152 AC_DEFUN_ONCE([LIB_SETUP_ZLIB],
 153 [
 154   AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib],
 155       [use zlib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
 156 
 157   AC_CHECK_LIB(z, compress,
 158       [ ZLIB_FOUND=yes ],
 159       [ ZLIB_FOUND=no ])
 160 
 161   AC_MSG_CHECKING([for which zlib to use])
 162 
 163   DEFAULT_ZLIB=system
 164   if test "x$OPENJDK_TARGET_OS" = xwindows; then
 165     # On windows default is bundled...on others default is system
 166     DEFAULT_ZLIB=bundled
 167   fi
 168 
 169   if test "x${ZLIB_FOUND}" != "xyes"; then
 170     # If we don't find any system...set default to bundled
 171     DEFAULT_ZLIB=bundled
 172   fi
 173 
 174   # If user didn't specify, use DEFAULT_ZLIB
 175   if test "x${with_zlib}" = "x"; then
 176     with_zlib=${DEFAULT_ZLIB}
 177   fi
 178 
 179   if test "x${with_zlib}" = "xbundled"; then
 180     USE_EXTERNAL_LIBZ=false
 181     AC_MSG_RESULT([bundled])
 182   elif test "x${with_zlib}" = "xsystem"; then
 183     if test "x${ZLIB_FOUND}" = "xyes"; then
 184       USE_EXTERNAL_LIBZ=true
 185       AC_MSG_RESULT([system])
 186 
 187       if test "x$USE_EXTERNAL_LIBPNG" != "xtrue"; then
 188         # If we use bundled libpng, we must verify that we have a proper zlib.
 189         # For instance zlib-ng has had issues with inflateValidate().
 190         AC_MSG_CHECKING([for system zlib functionality])
 191         AC_COMPILE_IFELSE(
 192             [AC_LANG_PROGRAM([#include "zlib.h"], [
 193                 #if ZLIB_VERNUM >= 0x1281
 194                   inflateValidate(NULL, 0);
 195                 #endif
 196             ])],
 197             [AC_MSG_RESULT([ok])],
 198             [
 199                 AC_MSG_RESULT([not ok])
 200                 AC_MSG_ERROR([System zlib not working correctly])
 201             ]
 202         )
 203       fi
 204     else
 205       AC_MSG_RESULT([system not found])
 206       AC_MSG_ERROR([--with-zlib=system specified, but no zlib found!])
 207     fi
 208   else
 209     AC_MSG_ERROR([Invalid value for --with-zlib: ${with_zlib}, use 'system' or 'bundled'])
 210   fi
 211 
 212   LIBZ_CFLAGS=""
 213   LIBZ_LIBS=""
 214   if test "x$USE_EXTERNAL_LIBZ" = "xfalse"; then
 215     LIBZ_CFLAGS="$LIBZ_CFLAGS -I$TOPDIR/src/java.base/share/native/libzip/zlib"
 216   else
 217     LIBZ_LIBS="-lz"
 218   fi
 219 
 220   AC_SUBST(USE_EXTERNAL_LIBZ)
 221   AC_SUBST(LIBZ_CFLAGS)
 222   AC_SUBST(LIBZ_LIBS)
 223 ])
 224 
 225 ################################################################################
 226 # Setup lcms (Little CMS)
 227 ################################################################################
 228 AC_DEFUN_ONCE([LIB_SETUP_LCMS],
 229 [
 230   AC_ARG_WITH(lcms, [AS_HELP_STRING([--with-lcms],
 231       [use lcms2 from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
 232 
 233   AC_MSG_CHECKING([for which lcms to use])
 234 
 235   DEFAULT_LCMS=bundled
 236   # If user didn't specify, use DEFAULT_LCMS
 237   if test "x${with_lcms}" = "x"; then
 238     with_lcms=${DEFAULT_LCMS}
 239   fi
 240 
 241   if test "x${with_lcms}" = "xbundled"; then
 242     USE_EXTERNAL_LCMS=false
 243     LCMS_CFLAGS=""
 244     LCMS_LIBS=""
 245     AC_MSG_RESULT([bundled])
 246   elif test "x${with_lcms}" = "xsystem"; then
 247     AC_MSG_RESULT([system])
 248     PKG_CHECK_MODULES([LCMS], [lcms2], [LCMS_FOUND=yes], [LCMS_FOUND=no])
 249     if test "x${LCMS_FOUND}" = "xyes"; then
 250       # PKG_CHECK_MODULES will set LCMS_CFLAGS and LCMS_LIBS
 251       USE_EXTERNAL_LCMS=true
 252     else
 253       AC_MSG_ERROR([--with-lcms=system specified, but no lcms found!])
 254     fi
 255   else
 256     AC_MSG_ERROR([Invalid value for --with-lcms: ${with_lcms}, use 'system' or 'bundled'])
 257   fi
 258 
 259   AC_SUBST(USE_EXTERNAL_LCMS)
 260   AC_SUBST(LCMS_CFLAGS)
 261   AC_SUBST(LCMS_LIBS)
 262 ])