xref: /PHP-7.2/ext/gd/config.m4 (revision 902d39a3)
1dnl
2dnl $Id$
3dnl
4
5dnl
6dnl Configure options
7dnl
8
9PHP_ARG_WITH(gd, for GD support,
10[  --with-gd[=DIR]           Include GD support.  DIR is the GD library base
11                          install directory [BUNDLED]])
12if test -z "$PHP_WEBP_DIR"; then
13  PHP_ARG_WITH(webp-dir, for the location of libwebp,
14  [  --with-webp-dir[=DIR]      GD: Set the path to libwebp install prefix], no, no)
15fi
16
17if test -z "$PHP_JPEG_DIR"; then
18  PHP_ARG_WITH(jpeg-dir, for the location of libjpeg,
19  [  --with-jpeg-dir[=DIR]     GD: Set the path to libjpeg install prefix], no, no)
20fi
21
22if test -z "$PHP_PNG_DIR"; then
23  PHP_ARG_WITH(png-dir, for the location of libpng,
24  [  --with-png-dir[=DIR]      GD: Set the path to libpng install prefix], no, no)
25fi
26
27if test -z "$PHP_ZLIB_DIR"; then
28  PHP_ARG_WITH(zlib-dir, for the location of libz,
29  [  --with-zlib-dir[=DIR]     GD: Set the path to libz install prefix], no, no)
30fi
31
32PHP_ARG_WITH(xpm-dir, for the location of libXpm,
33[  --with-xpm-dir[=DIR]      GD: Set the path to libXpm install prefix], no, no)
34
35PHP_ARG_WITH(freetype-dir, for FreeType 2,
36[  --with-freetype-dir[=DIR] GD: Set the path to FreeType 2 install prefix], no, no)
37
38PHP_ARG_ENABLE(gd-jis-conv, whether to enable JIS-mapped Japanese font support in GD,
39[  --enable-gd-jis-conv    GD: Enable JIS-mapped Japanese font support], no, no)
40
41dnl
42dnl Checks for the configure options
43dnl
44
45AC_DEFUN([PHP_GD_ZLIB],[
46	if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
47		if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
48			PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
49			PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
50		elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
51			PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
52			PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
53		else
54			AC_MSG_ERROR([Can't find zlib headers under "$PHP_ZLIB_DIR"])
55		fi
56	else
57		for i in /usr/local /usr; do
58			if test -f "$i/include/zlib/zlib.h"; then
59				PHP_ZLIB_DIR="$i"
60				PHP_ZLIB_INCDIR="$i/include/zlib"
61			elif test -f "$i/include/zlib.h"; then
62				PHP_ZLIB_DIR="$i"
63				PHP_ZLIB_INCDIR="$i/include"
64			fi
65		done
66	fi
67])
68
69AC_DEFUN([PHP_GD_WEBP],[
70  if test "$PHP_WEBP_DIR" != "no"; then
71
72    for i in $PHP_WEBP_DIR /usr/local /usr; do
73      test -f $i/include/webp/decode.h && GD_WEBP_DIR=$i && break
74    done
75
76    if test -z "$GD_WEBP_DIR"; then
77      AC_MSG_ERROR([webp/decode.h not found.])
78    fi
79
80    for i in $PHP_WEBP_DIR /usr/local /usr; do
81      test -f $i/include/webp/encode.h && GD_WEBP_DIR=$i && break
82    done
83
84    if test -z "$GD_WEBP_DIR"; then
85      AC_MSG_ERROR([webp/encode.h not found.])
86    fi
87
88    PHP_CHECK_LIBRARY(webp,WebPGetInfo,
89    [
90      PHP_ADD_INCLUDE($GD_WEBP_DIR/include)
91      PHP_ADD_LIBRARY(pthread)
92      PHP_ADD_LIBRARY_WITH_PATH(webp, $GD_WEBP_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
93    ],[
94      AC_MSG_ERROR([Problem with libwebp.(a|so). Please check config.log for more information.])
95    ],[
96      -L$GD_WEBP_DIR/$PHP_LIBDIR
97    ])
98  else
99    AC_MSG_RESULT([If configure fails try --with-webp-dir=<DIR>])
100  fi
101])
102
103AC_DEFUN([PHP_GD_JPEG],[
104  if test "$PHP_JPEG_DIR" != "no"; then
105
106    for i in $PHP_JPEG_DIR /usr/local /usr; do
107      test -f $i/include/jpeglib.h && GD_JPEG_DIR=$i && break
108    done
109
110    if test -z "$GD_JPEG_DIR"; then
111      AC_MSG_ERROR([jpeglib.h not found.])
112    fi
113
114    PHP_CHECK_LIBRARY(jpeg,jpeg_read_header,
115    [
116      PHP_ADD_INCLUDE($GD_JPEG_DIR/include)
117      PHP_ADD_LIBRARY_WITH_PATH(jpeg, $GD_JPEG_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
118    ],[
119      AC_MSG_ERROR([Problem with libjpeg.(a|so). Please check config.log for more information.])
120    ],[
121      -L$GD_JPEG_DIR/$PHP_LIBDIR
122    ])
123  else
124    AC_MSG_RESULT([If configure fails try --with-jpeg-dir=<DIR>])
125  fi
126])
127
128AC_DEFUN([PHP_GD_PNG],[
129  if test "$PHP_PNG_DIR" != "no"; then
130
131    for i in $PHP_PNG_DIR /usr/local /usr; do
132      test -f $i/include/png.h && GD_PNG_DIR=$i && break
133    done
134
135    if test -z "$GD_PNG_DIR"; then
136      AC_MSG_ERROR([png.h not found.])
137    fi
138
139    if test "$PHP_ZLIB_DIR" = "no"; then
140      AC_MSG_ERROR([PNG support requires ZLIB. Use --with-zlib-dir=<DIR>])
141    fi
142
143    PHP_CHECK_LIBRARY(png,png_write_image,
144    [
145      PHP_ADD_INCLUDE($GD_PNG_DIR/include)
146      PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
147      PHP_ADD_LIBRARY_WITH_PATH(png, $GD_PNG_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
148    ],[
149      AC_MSG_ERROR([Problem with libpng.(a|so) or libz.(a|so). Please check config.log for more information.])
150    ],[
151      -L$PHP_ZLIB_DIR/$PHP_LIBDIR -lz -L$GD_PNG_DIR/$PHP_LIBDIR
152    ])
153
154  else
155    AC_MSG_RESULT([If configure fails try --with-png-dir=<DIR> and --with-zlib-dir=<DIR>])
156  fi
157])
158
159AC_DEFUN([PHP_GD_XPM],[
160  if test "$PHP_XPM_DIR" != "no"; then
161
162    for i in $PHP_XPM_DIR /usr/local /usr/X11R6 /usr; do
163      test -f $i/include/xpm.h && GD_XPM_DIR=$i && GD_XPM_INC=$i && break
164      test -f $i/include/X11/xpm.h && GD_XPM_DIR=$i && GD_XPM_INC=$i/X11 && break
165    done
166
167    if test -z "$GD_XPM_DIR"; then
168      AC_MSG_ERROR([xpm.h not found.])
169    fi
170
171    PHP_CHECK_LIBRARY(Xpm,XpmFreeXpmImage,
172    [
173      PHP_ADD_INCLUDE($GD_XPM_INC)
174      PHP_ADD_LIBRARY_WITH_PATH(Xpm, $GD_XPM_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
175      PHP_ADD_LIBRARY_WITH_PATH(X11, $GD_XPM_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
176    ],[
177      AC_MSG_ERROR([Problem with libXpm.(a|so) or libX11.(a|so). Please check config.log for more information.])
178    ],[
179      -L$GD_XPM_DIR/$PHP_LIBDIR -lX11
180    ])
181  else
182    AC_MSG_RESULT(If configure fails try --with-xpm-dir=<DIR>)
183  fi
184])
185
186AC_DEFUN([PHP_GD_FREETYPE2],[
187  if test "$PHP_FREETYPE_DIR" != "no"; then
188
189    for i in $PHP_FREETYPE_DIR /usr/local /usr; do
190      if test -f "$i/bin/freetype-config"; then
191        FREETYPE2_DIR=$i
192        FREETYPE2_CONFIG="$i/bin/freetype-config"
193        break
194      fi
195    done
196
197    if test -z "$FREETYPE2_DIR"; then
198      AC_MSG_ERROR([freetype-config not found.])
199    fi
200
201    FREETYPE2_CFLAGS=`$FREETYPE2_CONFIG --cflags`
202    FREETYPE2_LIBS=`$FREETYPE2_CONFIG --libs`
203
204    PHP_EVAL_INCLINE($FREETYPE2_CFLAGS)
205    PHP_EVAL_LIBLINE($FREETYPE2_LIBS, GD_SHARED_LIBADD)
206    AC_DEFINE(HAVE_LIBFREETYPE,1,[ ])
207    AC_DEFINE(ENABLE_GD_TTF,1,[ ])
208  else
209    AC_MSG_RESULT([If configure fails try --with-freetype-dir=<DIR>])
210  fi
211])
212
213AC_DEFUN([PHP_GD_JISX0208],[
214  if test "$PHP_GD_JIS_CONV" = "yes"; then
215    USE_GD_JIS_CONV=1
216  fi
217])
218
219AC_DEFUN([PHP_GD_CHECK_VERSION],[
220  PHP_CHECK_LIBRARY(gd, gdImageCreateFromPng,   [AC_DEFINE(HAVE_GD_PNG,              1, [ ])], [], [ $GD_SHARED_LIBADD ])
221  PHP_CHECK_LIBRARY(gd, gdImageCreateFromWebp,  [AC_DEFINE(HAVE_GD_WEBP,             1, [ ])], [], [ $GD_SHARED_LIBADD ])
222  PHP_CHECK_LIBRARY(gd, gdImageCreateFromJpeg,  [AC_DEFINE(HAVE_GD_JPG,              1, [ ])], [], [ $GD_SHARED_LIBADD ])
223  PHP_CHECK_LIBRARY(gd, gdImageCreateFromXpm,   [AC_DEFINE(HAVE_GD_XPM,              1, [ ])], [], [ $GD_SHARED_LIBADD ])
224  PHP_CHECK_LIBRARY(gd, gdImageCreateFromBmp,   [AC_DEFINE(HAVE_GD_BMP,              1, [ ])], [], [ $GD_SHARED_LIBADD ])
225  PHP_CHECK_LIBRARY(gd, gdImageStringFT,        [AC_DEFINE(HAVE_GD_FREETYPE,         1, [ ])], [], [ $GD_SHARED_LIBADD ])
226  PHP_CHECK_LIBRARY(gd, gdVersionString,        [AC_DEFINE(HAVE_GD_LIBVERSION,       1, [ ])], [], [ $GD_SHARED_LIBADD ])
227])
228
229dnl
230dnl Main GD configure
231dnl
232
233dnl
234dnl Common for both builtin and external GD
235dnl
236if test "$PHP_GD" != "no"; then
237
238dnl PNG is required by GD library
239  test "$PHP_PNG_DIR" = "no" && PHP_PNG_DIR=yes
240
241dnl Various checks for GD features
242  PHP_GD_ZLIB
243  PHP_GD_WEBP
244  PHP_GD_JPEG
245  PHP_GD_PNG
246  PHP_GD_XPM
247  PHP_GD_FREETYPE2
248  PHP_GD_JISX0208
249fi
250
251if test "$PHP_GD" = "yes"; then
252  GD_MODULE_TYPE=builtin
253  extra_sources="libgd/gd.c libgd/gd_gd.c libgd/gd_gd2.c libgd/gd_io.c libgd/gd_io_dp.c \
254                 libgd/gd_io_file.c libgd/gd_ss.c libgd/gd_io_ss.c libgd/gd_webp.c \
255                 libgd/gd_png.c libgd/gd_jpeg.c libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c \
256                 libgd/gdfontmb.c libgd/gdfontl.c libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c \
257                 libgd/gdcache.c libgd/gdkanji.c libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c \
258                 libgd/gd_topal.c libgd/gd_gif_in.c libgd/gd_xbm.c libgd/gd_gif_out.c libgd/gd_security.c \
259                 libgd/gd_filter.c libgd/gd_pixelate.c libgd/gd_rotate.c libgd/gd_color_match.c \
260                 libgd/gd_transform.c libgd/gd_crop.c libgd/gd_interpolation.c libgd/gd_matrix.c \
261                 libgd/gd_bmp.c"
262
263dnl check for fabsf and floorf which are available since C99
264  AC_CHECK_FUNCS(fabsf floorf)
265
266dnl These are always available with bundled library
267  AC_DEFINE(HAVE_GD_BUNDLED,          1, [ ])
268  AC_DEFINE(HAVE_GD_PNG,              1, [ ])
269  AC_DEFINE(HAVE_GD_BMP,              1, [ ])
270  AC_DEFINE(HAVE_GD_CACHE_CREATE,     1, [ ])
271
272dnl Make sure the libgd/ is first in the include path
273  GDLIB_CFLAGS="-DHAVE_LIBPNG"
274
275dnl Depending which libraries were included to PHP configure,
276dnl enable the support in bundled GD library
277
278  if test -n "$GD_WEBP_DIR"; then
279    AC_DEFINE(HAVE_GD_WEBP, 1, [ ])
280    GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBWEBP"
281  fi
282
283  if test -n "$GD_JPEG_DIR"; then
284    AC_DEFINE(HAVE_GD_JPG, 1, [ ])
285    GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBJPEG"
286  fi
287
288  if test -n "$GD_XPM_DIR"; then
289    AC_DEFINE(HAVE_GD_XPM, 1, [ ])
290    GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_XPM"
291  fi
292
293  if test -n "$FREETYPE2_DIR"; then
294    AC_DEFINE(HAVE_GD_FREETYPE,   1, [ ])
295    AC_DEFINE(ENABLE_GD_TTF, 1, [ ])
296    GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBFREETYPE -DENABLE_GD_TTF"
297  fi
298
299  if test -n "$USE_GD_JIS_CONV"; then
300    AC_DEFINE(USE_GD_JISX0208, 1, [ ])
301    GDLIB_CFLAGS="$GDLIB_CFLAGS -DJISX0208"
302  fi
303
304else
305
306 if test "$PHP_GD" != "no"; then
307  GD_MODULE_TYPE=external
308  extra_sources="gd_compat.c"
309
310dnl Various checks for GD features
311  PHP_GD_ZLIB
312  PHP_GD_WEBP
313  PHP_GD_JPEG
314  PHP_GD_PNG
315  PHP_GD_XPM
316  PHP_GD_FREETYPE2
317
318dnl Header path
319  for i in include/gd include/gd2 include gd ""; do
320    test -f "$PHP_GD/$i/gd.h" && GD_INCLUDE="$PHP_GD/$i"
321  done
322
323  if test -z "$GD_INCLUDE"; then
324    AC_MSG_ERROR([Unable to find gd.h anywhere under $PHP_GD])
325  fi
326
327dnl Library path
328
329  PHP_CHECK_LIBRARY(gd, gdSetErrorMethod,
330  [
331    PHP_ADD_LIBRARY_WITH_PATH(gd, $PHP_GD/$PHP_LIBDIR, GD_SHARED_LIBADD)
332    AC_DEFINE(HAVE_LIBGD, 1, [ ])
333  ],[
334    AC_MSG_ERROR([Unable to find libgd.(a|so) >= 2.1.0 anywhere under $PHP_GD])
335  ],[
336    -L$PHP_GD/$PHP_LIBDIR
337  ])
338  PHP_GD_CHECK_VERSION
339
340  PHP_EXPAND_PATH($GD_INCLUDE, GD_INCLUDE)
341 fi
342fi
343
344dnl
345dnl Common for both builtin and external GD
346dnl
347if test "$PHP_GD" != "no"; then
348  PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared,, \\$(GDLIB_CFLAGS))
349
350  if test "$GD_MODULE_TYPE" = "builtin"; then
351    PHP_ADD_BUILD_DIR($ext_builddir/libgd)
352    GDLIB_CFLAGS="-I$ext_srcdir/libgd $GDLIB_CFLAGS"
353    GD_HEADER_DIRS="ext/gd/ ext/gd/libgd/"
354
355    PHP_TEST_BUILD(foobar, [], [
356      AC_MSG_ERROR([GD build test failed. Please check the config.log for details.])
357    ], [ $GD_SHARED_LIBADD ], [char foobar () {}])
358  else
359    GD_HEADER_DIRS="ext/gd/"
360    GDLIB_CFLAGS="-I$GD_INCLUDE $GDLIB_CFLAGS"
361    PHP_ADD_INCLUDE($GD_INCLUDE)
362    PHP_CHECK_LIBRARY(gd, gdImageCreate, [], [
363      AC_MSG_ERROR([GD build test failed. Please check the config.log for details.])
364    ], [ $GD_SHARED_LIBADD ])
365  fi
366
367  PHP_INSTALL_HEADERS([$GD_HEADER_DIRS])
368  PHP_SUBST(GDLIB_CFLAGS)
369  PHP_SUBST(GD_SHARED_LIBADD)
370fi
371