xref: /PHP-8.3/ext/gd/config.m4 (revision f6669654)
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
16if test -z "$PHP_AVIF"; then
17  PHP_ARG_WITH([avif],
18    [for libavif],
19    [AS_HELP_STRING([--with-avif],
20      [GD: Enable AVIF support (only for bundled libgd)])],
21    [no],
22    [no])
23fi
24
25if test -z "$PHP_WEBP"; then
26  PHP_ARG_WITH([webp],
27    [for libwebp],
28    [AS_HELP_STRING([--with-webp],
29      [GD: Enable WEBP support (only for bundled libgd)])],
30    [no],
31    [no])
32fi
33
34if test -z "$PHP_JPEG"; then
35  PHP_ARG_WITH([jpeg],
36    [for libjpeg],
37    [AS_HELP_STRING([--with-jpeg],
38      [GD: Enable JPEG support (only for bundled libgd)])],
39    [no],
40    [no])
41fi
42
43PHP_ARG_WITH([xpm],
44  [for libXpm],
45  [AS_HELP_STRING([--with-xpm],
46    [GD: Enable XPM support  (only for bundled libgd)])],
47  [no],
48  [no])
49
50PHP_ARG_WITH([freetype],
51  [for FreeType 2],
52  [AS_HELP_STRING([--with-freetype],
53    [GD: Enable FreeType 2 support (only for bundled libgd)])],
54  [no],
55  [no])
56
57PHP_ARG_ENABLE([gd-jis-conv],
58  [whether to enable JIS-mapped Japanese font support in GD],
59  [AS_HELP_STRING([--enable-gd-jis-conv],
60    [GD: Enable JIS-mapped Japanese font support (only for bundled libgd)])],
61  [no],
62  [no])
63
64dnl
65dnl Checks for the configure options
66dnl
67
68dnl zlib is always required
69AC_DEFUN([PHP_GD_ZLIB],[
70  PKG_CHECK_MODULES([ZLIB], [zlib])
71  PHP_EVAL_LIBLINE($ZLIB_LIBS, GD_SHARED_LIBADD)
72  PHP_EVAL_INCLINE($ZLIB_CFLAGS)
73])
74
75dnl libpng is always required
76AC_DEFUN([PHP_GD_PNG],[
77  PKG_CHECK_MODULES([PNG], [libpng])
78  PHP_EVAL_LIBLINE($PNG_LIBS, GD_SHARED_LIBADD)
79  PHP_EVAL_INCLINE($PNG_CFLAGS)
80  AC_DEFINE(HAVE_LIBPNG, 1, [ ])
81])
82
83AC_DEFUN([PHP_GD_AVIF],[
84  if test "$PHP_AVIF" != "no"; then
85    PKG_CHECK_MODULES([AVIF], [libavif >= 0.8.2])
86    PHP_EVAL_LIBLINE($AVIF_LIBS, GD_SHARED_LIBADD)
87    PHP_EVAL_INCLINE($AVIF_CFLAGS)
88    AC_DEFINE(HAVE_LIBAVIF, 1, [ ])
89    AC_DEFINE(HAVE_GD_AVIF, 1, [ ])
90  fi
91])
92
93AC_DEFUN([PHP_GD_WEBP],[
94  if test "$PHP_WEBP" != "no"; then
95    PKG_CHECK_MODULES([WEBP], [libwebp >= 0.2.0])
96    PHP_EVAL_LIBLINE($WEBP_LIBS, GD_SHARED_LIBADD)
97    PHP_EVAL_INCLINE($WEBP_CFLAGS)
98    AC_DEFINE(HAVE_LIBWEBP, 1, [ ])
99    AC_DEFINE(HAVE_GD_WEBP, 1, [ ])
100  fi
101])
102
103AC_DEFUN([PHP_GD_JPEG],[
104  if test "$PHP_JPEG" != "no"; then
105    PKG_CHECK_MODULES([JPEG], [libjpeg])
106    PHP_EVAL_LIBLINE($JPEG_LIBS, GD_SHARED_LIBADD)
107    PHP_EVAL_INCLINE($JPEG_CFLAGS)
108    AC_DEFINE(HAVE_LIBJPEG, 1, [ ])
109    AC_DEFINE(HAVE_GD_JPG, 1, [ ])
110  fi
111])
112
113AC_DEFUN([PHP_GD_XPM],[
114  if test "$PHP_XPM" != "no"; then
115    PKG_CHECK_MODULES([XPM], [xpm])
116    PHP_EVAL_LIBLINE($XPM_LIBS, GD_SHARED_LIBADD)
117    PHP_EVAL_INCLINE($XPM_CFLAGS)
118    AC_DEFINE(HAVE_XPM, 1, [ ])
119    AC_DEFINE(HAVE_GD_XPM, 1, [ ])
120  fi
121])
122
123AC_DEFUN([PHP_GD_FREETYPE2],[
124  if test "$PHP_FREETYPE" != "no"; then
125    PKG_CHECK_MODULES([FREETYPE2], [freetype2], [FREETYPE2_FOUND=true])
126
127    PHP_EVAL_INCLINE($FREETYPE2_CFLAGS)
128    PHP_EVAL_LIBLINE($FREETYPE2_LIBS, GD_SHARED_LIBADD)
129    AC_DEFINE(HAVE_LIBFREETYPE, 1, [ ])
130    AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])
131  fi
132])
133
134AC_DEFUN([PHP_GD_JISX0208],[
135  if test "$PHP_GD_JIS_CONV" = "yes"; then
136    AC_DEFINE(USE_GD_JISX0208, 1, [ ])
137    AC_DEFINE(JISX0208, 1, [ ])
138  fi
139])
140
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 second argument (the name
145dnl of a constant) will be defined to 1. The reason for this charade is
146dnl that gd defines "junk" versions of each gdImageCreateFromFoo function
147dnl even when it does not support the Foo format. Those junk functions
148dnl display a warning but eventually return normally, making a simple link
149dnl or run test insufficient.
150AC_DEFUN([PHP_GD_CHECK_FORMAT],[
151  old_LIBS="${LIBS}"
152  LIBS="${LIBS} ${GD_SHARED_LIBADD}"
153  old_CFLAGS="${CFLAGS}"
154  CFLAGS="${CFLAGS} ${GDLIB_CFLAGS}"
155  AC_MSG_CHECKING([for working gdImageCreateFrom$1 in libgd])
156  AC_LANG_PUSH([C])
157  AC_RUN_IFELSE([AC_LANG_SOURCE([
158#include <stdio.h>
159#include <unistd.h>
160#include <gd.h>
161
162/* A custom gdErrorMethod */
163void exit1(int priority, const char *format, va_list args) {
164  _exit(1);
165}
166
167/* Override the default gd_error_method with one that
168   actually causes the program to return an error. */
169int main(int argc, char** argv) {
170  m4_if([$1],[Xpm],
171  [char* f = "test.xpm"],
172  [FILE* f = NULL]);
173  gdSetErrorMethod(exit1);
174  gdImagePtr p = gdImageCreateFrom$1(f);
175  return 0;
176}])],[
177    AC_MSG_RESULT([yes])
178    AC_DEFINE($2, 1, [Does gdImageCreateFrom$1 work?])
179  ],[
180    AC_MSG_RESULT([no])
181  ],[
182    AC_MSG_RESULT([no])
183  ])
184  AC_LANG_POP([C])
185  CFLAGS="${old_CFLAGS}"
186  LIBS="${old_LIBS}"
187])
188
189AC_DEFUN([PHP_GD_CHECK_VERSION],[
190  PHP_GD_CHECK_FORMAT([Png],  [HAVE_GD_PNG])
191  PHP_GD_CHECK_FORMAT([Avif], [HAVE_GD_AVIF])
192  PHP_GD_CHECK_FORMAT([Webp], [HAVE_GD_WEBP])
193  PHP_GD_CHECK_FORMAT([Jpeg], [HAVE_GD_JPG])
194  PHP_GD_CHECK_FORMAT([Xpm],  [HAVE_GD_XPM])
195  PHP_GD_CHECK_FORMAT([Bmp],  [HAVE_GD_BMP])
196  PHP_GD_CHECK_FORMAT([Tga],  [HAVE_GD_TGA])
197  PHP_CHECK_LIBRARY(gd, gdFontCacheShutdown,           [AC_DEFINE(HAVE_GD_FREETYPE,          1, [ ])], [], [ $GD_SHARED_LIBADD ])
198  PHP_CHECK_LIBRARY(gd, gdVersionString,               [AC_DEFINE(HAVE_GD_LIBVERSION,        1, [ ])], [], [ $GD_SHARED_LIBADD ])
199  PHP_CHECK_LIBRARY(gd, gdImageGetInterpolationMethod, [AC_DEFINE(HAVE_GD_GET_INTERPOLATION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
200])
201
202dnl
203dnl Main GD configure
204dnl
205
206if test "$PHP_GD" != "no"; then
207
208  if test "$PHP_EXTERNAL_GD" = "no"; then
209    extra_sources="libgd/gd.c libgd/gd_gd.c libgd/gd_gd2.c libgd/gd_io.c libgd/gd_io_dp.c \
210                  libgd/gd_io_file.c libgd/gd_ss.c libgd/gd_io_ss.c libgd/gd_webp.c libgd/gd_avif.c \
211                  libgd/gd_png.c libgd/gd_jpeg.c libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c \
212                  libgd/gdfontmb.c libgd/gdfontl.c libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c \
213                  libgd/gdcache.c libgd/gdkanji.c libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c \
214                  libgd/gd_topal.c libgd/gd_gif_in.c libgd/gd_xbm.c libgd/gd_gif_out.c libgd/gd_security.c \
215                  libgd/gd_filter.c libgd/gd_pixelate.c libgd/gd_rotate.c libgd/gd_color_match.c \
216                  libgd/gd_transform.c libgd/gd_crop.c libgd/gd_interpolation.c libgd/gd_matrix.c \
217                  libgd/gd_bmp.c libgd/gd_tga.c"
218
219dnl check for fabsf and floorf which are available since C99
220    AC_CHECK_FUNCS(fabsf floorf)
221
222dnl These are always available with bundled library
223    AC_DEFINE(HAVE_GD_BUNDLED,          1, [ ])
224    AC_DEFINE(HAVE_GD_PNG,              1, [ ])
225    AC_DEFINE(HAVE_GD_BMP,              1, [ ])
226    AC_DEFINE(HAVE_GD_TGA,              1, [ ])
227
228dnl Various checks for GD features
229    PHP_GD_ZLIB
230    PHP_GD_PNG
231    PHP_GD_AVIF
232    PHP_GD_WEBP
233    PHP_GD_JPEG
234    PHP_GD_XPM
235    PHP_GD_FREETYPE2
236    PHP_GD_JISX0208
237
238    PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared,, \\$(GD_CFLAGS))
239    PHP_ADD_BUILD_DIR($ext_builddir/libgd)
240    GD_CFLAGS="-Wno-strict-prototypes -I$ext_srcdir/libgd $GD_CFLAGS"
241    GD_HEADER_DIRS="ext/gd/ ext/gd/libgd/"
242
243    PHP_TEST_BUILD(foobar, [], [
244      AC_MSG_ERROR([GD build test failed. Please check the config.log for details.])
245    ], [ $GD_SHARED_LIBADD ], [char foobar(void) { return '\0'; }])
246
247  else
248    extra_sources="gd_compat.c"
249    PKG_CHECK_MODULES([GDLIB], [gdlib >= 2.1.0])
250    PHP_EVAL_LIBLINE($GDLIB_LIBS, GD_SHARED_LIBADD)
251    PHP_EVAL_INCLINE($GDLIB_CFLAGS)
252    AC_DEFINE(HAVE_LIBGD, 1, [ ])
253    PHP_GD_CHECK_VERSION
254
255    PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared)
256    GD_HEADER_DIRS="ext/gd/"
257    PHP_CHECK_LIBRARY(gd, gdImageCreate, [], [
258      AC_MSG_ERROR([GD build test failed. Please check the config.log for details.])
259    ], [ $GD_SHARED_LIBADD ])
260  fi
261
262  PHP_INSTALL_HEADERS([$GD_HEADER_DIRS])
263  PHP_SUBST(GD_CFLAGS)
264  PHP_SUBST(GDLIB_CFLAGS)
265  PHP_SUBST(GDLIB_LIBS)
266  PHP_SUBST(GD_SHARED_LIBADD)
267fi
268