1dnl 2dnl Configure options 3dnl 4PHP_ARG_ENABLE([gd], 5 [for GD support], 6 [AS_HELP_STRING([--enable-gd], 7 [Include GD support])]) 8 9PHP_ARG_WITH([external-gd], 10 [for external libgd], 11 [AS_HELP_STRING([--with-external-gd], 12 [Use external libgd])], 13 [no], 14 [no]) 15 16PHP_ARG_WITH([avif], 17 [for libavif], 18 [AS_HELP_STRING([--with-avif], 19 [GD: Enable AVIF support (only for bundled libgd)])], 20 [no], 21 [no]) 22 23PHP_ARG_WITH([webp], 24 [for libwebp], 25 [AS_HELP_STRING([--with-webp], 26 [GD: Enable WEBP support (only for bundled libgd)])], 27 [no], 28 [no]) 29 30PHP_ARG_WITH([jpeg], 31 [for libjpeg], 32 [AS_HELP_STRING([--with-jpeg], 33 [GD: Enable JPEG support (only for bundled libgd)])], 34 [no], 35 [no]) 36 37PHP_ARG_WITH([xpm], 38 [for libXpm], 39 [AS_HELP_STRING([--with-xpm], 40 [GD: Enable XPM support (only for bundled libgd)])], 41 [no], 42 [no]) 43 44PHP_ARG_WITH([freetype], 45 [for FreeType 2], 46 [AS_HELP_STRING([--with-freetype], 47 [GD: Enable FreeType 2 support (only for bundled libgd)])], 48 [no], 49 [no]) 50 51PHP_ARG_ENABLE([gd-jis-conv], 52 [whether to enable JIS-mapped Japanese font support in GD], 53 [AS_HELP_STRING([--enable-gd-jis-conv], 54 [GD: Enable JIS-mapped Japanese font support (only for bundled libgd)])], 55 [no], 56 [no]) 57 58dnl 59dnl Checks for the configure options 60dnl 61 62dnl libpng is always required 63AC_DEFUN([PHP_GD_PNG],[ 64 PKG_CHECK_MODULES([PNG], [libpng]) 65 PHP_EVAL_LIBLINE([$PNG_LIBS], [GD_SHARED_LIBADD]) 66 PHP_EVAL_INCLINE([$PNG_CFLAGS]) 67 AC_DEFINE([HAVE_LIBPNG], [1], [Define to 1 if you have the libpng library.]) 68]) 69 70AC_DEFUN([PHP_GD_AVIF], [ 71 AS_VAR_IF([PHP_AVIF], [no],, [ 72 PKG_CHECK_MODULES([AVIF], [libavif >= 0.8.2]) 73 PHP_EVAL_LIBLINE([$AVIF_LIBS], [GD_SHARED_LIBADD]) 74 PHP_EVAL_INCLINE([$AVIF_CFLAGS]) 75 AC_DEFINE([HAVE_LIBAVIF], [1], 76 [Define to 1 if you have the libavif library.]) 77 AC_DEFINE([HAVE_GD_AVIF], [1], 78 [Define to 1 if gd extension has AVIF support.]) 79 ]) 80]) 81 82AC_DEFUN([PHP_GD_WEBP],[ 83 AS_VAR_IF([PHP_WEBP], [no],, [ 84 PKG_CHECK_MODULES([WEBP], [libwebp >= 0.2.0]) 85 PHP_EVAL_LIBLINE([$WEBP_LIBS], [GD_SHARED_LIBADD]) 86 PHP_EVAL_INCLINE([$WEBP_CFLAGS]) 87 AC_DEFINE([HAVE_LIBWEBP], [1], 88 [Define to 1 if you have the libwebp library.]) 89 AC_DEFINE([HAVE_GD_WEBP], [1], 90 [Define to 1 if gd extension has WebP support.]) 91 ]) 92]) 93 94AC_DEFUN([PHP_GD_JPEG],[ 95 AS_VAR_IF([PHP_JPEG], [no],, [ 96 PKG_CHECK_MODULES([JPEG], [libjpeg]) 97 PHP_EVAL_LIBLINE([$JPEG_LIBS], [GD_SHARED_LIBADD]) 98 PHP_EVAL_INCLINE([$JPEG_CFLAGS]) 99 AC_DEFINE([HAVE_LIBJPEG], [1], 100 [Define to 1 if you have the libjpeg library.]) 101 AC_DEFINE([HAVE_GD_JPG], [1], 102 [Define to 1 if gd extension has JPEG support.]) 103 ]) 104]) 105 106AC_DEFUN([PHP_GD_XPM],[ 107 AS_VAR_IF([PHP_XPM], [no],, [ 108 PKG_CHECK_MODULES([XPM], [xpm]) 109 PHP_EVAL_LIBLINE([$XPM_LIBS], [GD_SHARED_LIBADD]) 110 PHP_EVAL_INCLINE([$XPM_CFLAGS]) 111 AC_DEFINE([HAVE_XPM], [1], [Define to 1 if you have the xpm library.]) 112 AC_DEFINE([HAVE_GD_XPM], [1], 113 [Define to 1 if gd extension has XPM support.]) 114 ]) 115]) 116 117AC_DEFUN([PHP_GD_FREETYPE2],[ 118 AS_VAR_IF([PHP_FREETYPE], [no],, [ 119 PKG_CHECK_MODULES([FREETYPE2], [freetype2]) 120 PHP_EVAL_INCLINE([$FREETYPE2_CFLAGS]) 121 PHP_EVAL_LIBLINE([$FREETYPE2_LIBS], [GD_SHARED_LIBADD]) 122 AC_DEFINE([HAVE_LIBFREETYPE], [1], 123 [Define to 1 if you have the FreeType library.]) 124 AC_DEFINE([HAVE_GD_FREETYPE], [1], 125 [Define to 1 if gd extension has FreeType support.]) 126 ]) 127]) 128 129AC_DEFUN([PHP_GD_JISX0208],[ 130 AS_VAR_IF([PHP_GD_JIS_CONV], [yes], [ 131 AC_DEFINE([USE_GD_JISX0208], [1], 132 [Define to 1 if gd extension has JIS-mapped Japanese font support.]) 133 AC_DEFINE([JISX0208], [1], 134 [Define to 1 if GD library has JIS-mapped Japanese font support.]) 135 ]) 136]) 137 138dnl 139dnl PHP_GD_CHECK_FORMAT(format, [action-if-found]) 140dnl 141dnl Build and run a program to determine if GD has support for the given 142dnl format. The first argument is the proper-noun-capitalized name of the 143dnl format -- basically the word Foo in gdImageCreateFromFoo -- such as 144dnl Png. If support for "format" Foo exists, the "action-if-found" is executed. 145dnl The reason for this charade is that gd defines no-op versions of each 146dnl gdImageCreateFromFoo function even when it does not support the Foo format. 147dnl Those no-op functions display a warning but eventually return normally, 148dnl making a simple link or run test insufficient. 149dnl 150AC_DEFUN([PHP_GD_CHECK_FORMAT], 151[AS_VAR_PUSHDEF([php_var], [php_cv_lib_gd_gdImageCreateFrom$1]) 152old_LIBS="${LIBS}" 153LIBS="${LIBS} ${GD_SHARED_LIBADD}" 154old_CFLAGS="${CFLAGS}" 155CFLAGS="${CFLAGS} ${GDLIB_CFLAGS}" 156AC_LANG_PUSH([C]) 157AC_CACHE_CHECK([for working gdImageCreateFrom$1 in libgd], [php_var], 158 [AC_RUN_IFELSE([AC_LANG_SOURCE([ 159#include <stdio.h> 160#include <unistd.h> 161#include <gd.h> 162 163/* A custom gdErrorMethod */ 164void exit1(int priority, const char *format, va_list args) { 165 _exit(1); 166} 167 168/* Override the default gd_error_method with one that 169 actually causes the program to return an error. */ 170int main(int argc, char** argv) { 171 m4_if([$1],[Xpm], 172 [char* f = "test.xpm"], 173 [FILE* f = NULL]); 174 gdSetErrorMethod(exit1); 175 gdImagePtr p = gdImageCreateFrom$1(f); 176 return 0; 177}])], 178 [AS_VAR_SET([php_var], [yes])], 179 [AS_VAR_SET([php_var], [no])], 180 [AS_VAR_SET([php_var], [no])])]) 181AS_VAR_IF([php_var], [yes], [$2]) 182AC_LANG_POP([C]) 183CFLAGS="${old_CFLAGS}" 184LIBS="${old_LIBS}" 185AS_VAR_POPDEF([php_var]) 186]) 187 188AC_DEFUN([PHP_GD_CHECK_VERSION],[ 189 PHP_GD_CHECK_FORMAT([Png], [AC_DEFINE([HAVE_GD_PNG], [1])]) 190 PHP_GD_CHECK_FORMAT([Avif], [AC_DEFINE([HAVE_GD_AVIF], [1])]) 191 PHP_GD_CHECK_FORMAT([Webp], [AC_DEFINE([HAVE_GD_WEBP], [1])]) 192 PHP_GD_CHECK_FORMAT([Jpeg], [AC_DEFINE([HAVE_GD_JPG], [1])]) 193 PHP_GD_CHECK_FORMAT([Xpm], [AC_DEFINE([HAVE_GD_XPM], [1])]) 194 PHP_GD_CHECK_FORMAT([Bmp], [AC_DEFINE([HAVE_GD_BMP], [1])]) 195 PHP_GD_CHECK_FORMAT([Tga], [AC_DEFINE([HAVE_GD_TGA], [1])]) 196 PHP_CHECK_LIBRARY([gd], [gdFontCacheShutdown], 197 [AC_DEFINE([HAVE_GD_FREETYPE], [1])], 198 [], 199 [$GD_SHARED_LIBADD]) 200 PHP_CHECK_LIBRARY([gd], [gdVersionString], 201 [AC_DEFINE([HAVE_GD_LIBVERSION], [1], 202 [Define to 1 if GD library has the 'gdVersionString' function.])], 203 [], 204 [$GD_SHARED_LIBADD]) 205 PHP_CHECK_LIBRARY([gd], [gdImageGetInterpolationMethod], 206 [AC_DEFINE([HAVE_GD_GET_INTERPOLATION], [1], 207 [Define to 1 if GD library has the 'gdImageGetInterpolationMethod' 208 function.])], 209 [], 210 [$GD_SHARED_LIBADD]) 211]) 212 213dnl 214dnl Main GD configure 215dnl 216 217if test "$PHP_GD" != "no"; then 218 if test "$PHP_EXTERNAL_GD" = "no"; then 219 extra_sources=m4_normalize([" 220 libgd/gd_avif.c 221 libgd/gd_bmp.c 222 libgd/gd_color_match.c 223 libgd/gd_crop.c 224 libgd/gd_filter.c 225 libgd/gd_gd.c 226 libgd/gd_gd2.c 227 libgd/gd_gif_in.c 228 libgd/gd_gif_out.c 229 libgd/gd_interpolation.c 230 libgd/gd_io_dp.c 231 libgd/gd_io_file.c 232 libgd/gd_io_ss.c 233 libgd/gd_io.c 234 libgd/gd_jpeg.c 235 libgd/gd_matrix.c 236 libgd/gd_pixelate.c 237 libgd/gd_png.c 238 libgd/gd_rotate.c 239 libgd/gd_security.c 240 libgd/gd_ss.c 241 libgd/gd_tga.c 242 libgd/gd_topal.c 243 libgd/gd_transform.c 244 libgd/gd_wbmp.c 245 libgd/gd_webp.c 246 libgd/gd_xbm.c 247 libgd/gd.c 248 libgd/gdcache.c 249 libgd/gdfontg.c 250 libgd/gdfontl.c 251 libgd/gdfontmb.c 252 libgd/gdfonts.c 253 libgd/gdfontt.c 254 libgd/gdft.c 255 libgd/gdhelpers.c 256 libgd/gdkanji.c 257 libgd/gdtables.c 258 libgd/gdxpm.c 259 libgd/wbmp.c 260 "]) 261 262dnl These are always available with bundled library 263 AC_DEFINE([HAVE_GD_BUNDLED], [1], 264 [Define to 1 if gd extension uses GD library bundled in PHP.]) 265 AC_DEFINE([HAVE_GD_PNG], [1], 266 [Define to 1 if gd extension has PNG support.]) 267 AC_DEFINE([HAVE_GD_BMP], [1], 268 [Define to 1 if gd extension has BMP support.]) 269 AC_DEFINE([HAVE_GD_TGA], [1], 270 [Define to 1 if gd extension has TGA support.]) 271 272dnl Various checks for GD features 273 PHP_SETUP_ZLIB([GD_SHARED_LIBADD]) 274 PHP_GD_PNG 275 PHP_GD_AVIF 276 PHP_GD_WEBP 277 PHP_GD_JPEG 278 PHP_GD_XPM 279 PHP_GD_FREETYPE2 280 PHP_GD_JISX0208 281 282 PHP_NEW_EXTENSION([gd], 283 [gd.c $extra_sources], 284 [$ext_shared],, 285 [-Wno-strict-prototypes -I@ext_srcdir@/libgd]) 286 PHP_ADD_BUILD_DIR([$ext_builddir/libgd]) 287 288 PHP_INSTALL_HEADERS([ext/gd], [php_gd.h libgd/]) 289 290 dnl Sanity check. 291 AC_CACHE_CHECK([whether build works], [php_cv_lib_gd_works], [ 292 LIBS_SAVED=$LIBS 293 LIBS="$GD_SHARED_LIBADD $LIBS" 294 AC_LINK_IFELSE([AC_LANG_PROGRAM()], 295 [php_cv_lib_gd_works=yes], 296 [php_cv_lib_gd_works=no]) 297 LIBS=$LIBS_SAVED 298 ]) 299 AS_VAR_IF([php_cv_lib_gd_works], [yes],, 300 [AC_MSG_FAILURE([GD library build test failed.])]) 301 else 302 extra_sources="gd_compat.c" 303 PKG_CHECK_MODULES([GDLIB], [gdlib >= 2.1.0]) 304 PHP_EVAL_LIBLINE([$GDLIB_LIBS], [GD_SHARED_LIBADD]) 305 PHP_EVAL_INCLINE([$GDLIB_CFLAGS]) 306 AC_DEFINE([HAVE_LIBGD], [1], 307 [Define to 1 if gd extension uses external system GD library.]) 308 PHP_GD_CHECK_VERSION 309 310 PHP_NEW_EXTENSION([gd], [gd.c $extra_sources], [$ext_shared]) 311 PHP_INSTALL_HEADERS([ext/gd], [php_gd.h]) 312 PHP_CHECK_LIBRARY([gd], [gdImageCreate], 313 [], 314 [AC_MSG_FAILURE([GD library build test failed.])], 315 [$GD_SHARED_LIBADD]) 316 fi 317 318 PHP_SUBST([GD_SHARED_LIBADD]) 319fi 320