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
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
AC_INIT(image_tiff.c) 
AC_CONFIG_HEADER(config.h) 
AC_ARG_WITH(tifflib,     [  --with(out)-tifflib       Support TIFF (Image.TIFF)],[],[with_tifflib=yes]) 
 
AC_MODULE_INIT() 
 
PIKE_FEATURE_WITHOUT(Image.TIFF) 
 
if test x$with_tifflib = xyes ; then 
  PIKE_FEATURE_NODEP(Image.TIFF) 
 
  AC_CHECK_HEADERS(tiff.h tiffvers.h tiffio.h tiffiop.h) 
  if test $ac_cv_header_tiff_h = yes ; then 
    AC_CHECK_LIB(m, floor) 
    AC_CHECK_LIB(jpeg, jpeg_CreateCompress) 
    AC_SEARCH_LIBS(inflate, z gz zlib) 
    AC_SEARCH_LIBS(TIFFOpen, tiff libtiff) 
 
    AC_MSG_CHECKING([if this tifflib is working]) 
    AC_CACHE_VAL(pike_cv_working_tiff, [ 
      # Some tiff libraries are broken, and will thrash memory. 
      # eg the one on RedHat 7.1/ia64. 
 
      # Copy the test image to the build directory, so that our 
      # test program can find it. 
      if cmp "$srcdir/test_image.tiff" "test_image.tiff" 2>/dev/null; then 
        : 
      else 
        if test -f "test_image.tiff"; then 
          rm -f "test_image.tiff" 
        fi 
        cp "$srcdir/test_image.tiff" "test_image.tiff" 
      fi 
      AC_TRY_RUN([ 
#ifdef INLINE 
#undef INLINE 
#endif 
#include <tiff.h> 
#ifdef HAVE_TIFFIOP_H 
#include <tiffiop.h> 
#endif 
#include <tiffio.h> 
#include <stdio.h> 
#include <errno.h> 
int main(int argc, char **argv) 
{ 
  TIFF *tif = TIFFOpen("test_image.tiff", "r"); 
  uint32 w, h, *raster; 
 
  if (!tif) { 
    fprintf(stderr, "Failed to open image. errno:%d\n", errno); 
    return 1; 
  } 
 
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); 
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); 
 
  if (!(raster = (void *)malloc(w*h*sizeof(uint32)))) { 
    fprintf(stderr, "Failed to allocate memory for image (%d * %d).\n", w, h); 
    return 1; 
  } 
 
  if (!TIFFReadRGBAImage(tif, w, h, raster, 0)) { 
    fprintf(stderr, "Failed to decode image.\n"); 
    return 1; 
  } 
  return 0; 
} 
      ], [ pike_cv_working_tiff=yes ], [ pike_cv_working_tiff=no ], [ 
         AC_TRY_COMPILE([ 
#ifdef INLINE 
#undef INLINE 
#endif 
#include <tiff.h> 
#ifdef HAVE_TIFFIOP_H 
#include <tiffiop.h> 
#endif 
#include <tiffio.h> 
#include <stdio.h> 
#include <errno.h> 
         ], [ 
{ 
  TIFF *tif = TIFFOpen("test_image.tiff", "r"); 
  uint32 w, h, *raster; 
 
  if (!tif) { 
    fprintf(stderr, "Failed to open image. errno:%d\n", errno); 
    return 1; 
  } 
 
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); 
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); 
 
  if (!(raster = (void *)malloc(w*h*sizeof(uint32)))) { 
    fprintf(stderr, "Failed to allocate memory for image (%d * %d).\n", w, h); 
    return 1; 
  } 
 
  if (!TIFFReadRGBAImage(tif, w, h, raster, 0)) { 
    fprintf(stderr, "Failed to decode image.\n"); 
    return 1; 
  } 
  return 0; 
} 
         ], [ pike_cv_working_tiff=yes ], [ pike_cv_working_tiff=no ]) 
      ]) 
    ]) 
    if test "x$pike_cv_working_tiff" = "xno"; then 
      AC_MSG_RESULT([no]) 
      PIKE_FEATURE([Image.TIFF],[no (tifflib version 42)]) 
    else 
      AC_MSG_RESULT([yes]) 
      AC_DEFINE(HAVE_WORKING_LIBTIFF) 
      PIKE_FEATURE_OK(Image.TIFF) 
      AC_MSG_CHECKING(for version of tifflib) 
      if test "x$ac_cv_header_tiffvers_h" = "xyes"; then 
        cat >conftest.$ac_ext <<EOF 
#include <tiffvers.h> 
VERSION:TIFFLIB_VERSION 
EOF 
        vers=`eval "$ac_cpp conftest.$ac_ext" 2>&5 | sed -e '/VERSION:/s/VERSION://p' -ed` 
        if test "x$vers" = "x"; then 
          AC_MSG_RESULT([Unknown (failed to parse tiffvers.h)]) 
        else 
          AC_MSG_RESULT([$vers]) 
        fi 
        rm -f conftest* 
      else 
        AC_MSG_RESULT([Unknown (no tiffvers.h)]) 
      fi 
    fi 
  fi 
fi 
 
AC_OUTPUT(Makefile,echo FOO >stamp-h )