summaryrefslogtreecommitdiff
blob: 4b8971f1e302b2e971f3b295c0389b157526d4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use libpng's pkg-config files rather than the ugly xxx-config scripts

--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,7 @@ AC_PROG_LIBTOOL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 #AC_PROG_RANLIB
+PKG_PROG_PKG_CONFIG
 
 dnl may be required for freetype and Xpm
 AC_PATH_X
@@ -340,74 +341,26 @@ AC_CHECK_LIB(z,deflate,
 dnl libpng is required
 AC_ARG_WITH(png,dnl
 [  --with-png=DIR          where to find the png library],,
-  withval=yes)
-
-# libpng12.so is a nightmare. We have to test separately for
-# libpng12-config and libpng-config. If we find libpng12-config,
-# we don't look for the other, which will just be a symlink to it,
-# confusing autoconf into thinking the library itself will be named -lpng,
-# which it won't be. Awful. This code will suffice unless the libpng
-# authors decide to do this AGAIN. Which I really hope they won't. TBB
-
-if test "$withval" != no; then
-  AC_PATH_PROG([LIBPNG12_CONFIG], [libpng12-config])
-  AC_PATH_PROG([LIBPNG_CONFIG], [libpng-config])
-  if test -n "$LIBPNG12_CONFIG"; then
-    libpng_CPPFLAGS=`libpng12-config --cflags`
-    # should be --ldopts, but it's currently broken
-    libpng_LDFLAGS=`libpng12-config --ldflags`
-    libpng_LDFLAGS=`echo " $libpng_LDFLAGS" | sed 's/ -l[[^ ]][[^ ]]*//g'`
-  elif test -n "$LIBPNG_CONFIG"; then
-    libpng_CPPFLAGS=`libpng-config --cflags`
-    # should be --ldopts, but it's currently broken
-    libpng_LDFLAGS=`libpng-config --ldflags`
-    libpng_LDFLAGS=`echo " $libpng_LDFLAGS" | sed 's/ -l[[^ ]][[^ ]]*//g'`
-  elif test -d "$withval"; then
-    libpng_CPPFLAGS="-I$withval/include"
-    libpng_LDFLAGS="-L$withval/lib"
-  fi
-
-  AC_CHECK_HEADERS(png.h,,
-    [AC_CHECK_HEADERS(libpng/png.h,
-       [CPPFLAGS="$CPPFLAGS $libpng_CPPFLAGS/libpng"],
-       [CPPFLAGS="$_cppflags"])])
-
-  _ldflags="$LDFLAGS"
-  LDFLAGS="$libpng_LDFLAGS $LDFLAGS"
-
-  if test -n "$LIBPNG12_CONFIG"; then
-    AC_CHECK_LIB(png12,png_create_read_struct,
-      [LIBS="-lpng12 $LIBS"
-       FEATURES="GD_PNG $FEATURES"
-       AC_DEFINE(HAVE_LIBPNG, 1, [ Define if you have the png library. ])],
-      [LDFLAGS="$_ldflags"  
-       AC_MSG_WARN([libpng is required - see http://www.libpng.org/pub/png/])])
-  elif test -n "$LIBPNG_CONFIG"; then
-    AC_CHECK_LIB(png,png_create_read_struct,
-      [LIBS="-lpng $LIBS" 
-       FEATURES="GD_PNG $FEATURES"
-       AC_DEFINE(HAVE_LIBPNG, 1, [ Define if you have the png library. ])],
-      [LDFLAGS="$_ldflags"  
-       AC_MSG_WARN([libpng is required - see http://www.libpng.org/pub/png/])])
-  else
-    AC_CHECK_LIB(png,png_create_read_struct,
-      [LIBS="-lpng $LIBS" 
-       FEATURES="GD_PNG $FEATURES"
-       AC_DEFINE(HAVE_LIBPNG, 1, [ Define if you have the png library. ])],
-      [LDFLAGS="$_ldflags"  
-       AC_MSG_WARN([libpng is required - see http://www.libpng.org/pub/png/])])
-  fi
-else
-  ac_cv_lib_png_png_create_read_struct=no
+  with_png=detect)
+
+if test "$with_png" != no; then
+  PKG_CHECK_MODULES([LIBPNG], libpng, [
+    FEATURES="GD_PNG $FEATURES"
+    AC_DEFINE(HAVE_LIBPNG, 1, [ Define if you have the png library. ])
+    CPPFLAGS="$CPPFLAGS $LIBPNG_CFLAGS"
+    LDFLAGS="$LDFLAGS $LIBPNG_LIBS"
+    with_png=yes
+  ],[
+    if test "$with_png" = yes; then
+      AC_MSG_ERROR([png support requested, but not found])
+    fi
+    with_png=no
+  ])
+fi
+if test "$with_png" = no; then
   AC_MSG_WARN([libpng is required - see http://www.libpng.org/pub/png/])
 fi
 
-#TBB: png12's png_create_read_struct is just as good 
-#2.0.23: should be = not ==  
-if test "$ac_cv_lib_png12_png_create_read_struct" = yes; then
-  ac_cv_lib_png_png_create_read_struct=yes
-fi 
-
 dnl FreeType configure tests snarfed from libwmf ..
 AC_ARG_WITH(freetype,dnl
 [  --with-freetype=DIR     where to find the freetype 2.x library],
@@ -528,7 +481,7 @@ dnl report configuration
 AC_MSG_RESULT([
 ** Configuration summary for $PACKAGE $VERSION:
 
-   Support for PNG library:          $ac_cv_lib_png_png_create_read_struct
+   Support for PNG library:          $with_png
    Support for JPEG library:         $ac_cv_lib_jpeg_jpeg_set_defaults
    Support for Freetype 2.x library: $ac_cv_lib_freetype_FT_Init_FreeType
    Support for Fontconfig library:   $ac_cv_lib_fontconfig_FcInit