xref: /aosp_15_r20/external/webp/configure.ac (revision b2055c353e87c8814eb2b6b1b11112a1562253bd)
1AC_INIT([libwebp], [1.4.0],
2        [https://bugs.chromium.org/p/webp],,
3        [https://developers.google.com/speed/webp])
4AC_CANONICAL_HOST
5AC_PREREQ([2.60])
6AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
7
8dnl === automake >= 1.12 requires this for 'unusual archivers' support.
9dnl === it must occur before LT_INIT (AC_PROG_LIBTOOL).
10m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
11
12dnl === AC_PROG_LIBTOOL is deprecated.
13m4_ifdef([LT_INIT], [LT_INIT], [AC_PROG_LIBTOOL])
14AC_PROG_SED
15AM_PROG_CC_C_O
16
17dnl === Enable less verbose output when building.
18m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
19
20dnl == test endianness
21AC_C_BIGENDIAN
22
23dnl === SET_IF_UNSET(shell_var, value)
24dnl ===   Set the shell variable 'shell_var' to 'value' if it is unset.
25AC_DEFUN([SET_IF_UNSET], [test "${$1+set}" = "set" || $1=$2])
26
27AC_ARG_ENABLE([everything],
28              AS_HELP_STRING([--enable-everything],
29                             [Enable all optional targets. These can still be
30                              disabled with --disable-target]),
31              [SET_IF_UNSET([enable_libsharpyuv], [$enableval])
32               SET_IF_UNSET([enable_libwebpdecoder], [$enableval])
33               SET_IF_UNSET([enable_libwebpdemux], [$enableval])
34               SET_IF_UNSET([enable_libwebpextras], [$enableval])
35               SET_IF_UNSET([enable_libwebpmux], [$enableval])])
36
37dnl === Check whether libwebpmux should be built
38AC_MSG_CHECKING(whether libwebpmux is to be built)
39AC_ARG_ENABLE([libwebpmux],
40              AS_HELP_STRING([--disable-libwebpmux],
41                             [Disable libwebpmux @<:@default=no@:>@]),
42              [], [enable_libwebpmux=yes])
43AC_MSG_RESULT(${enable_libwebpmux-no})
44AM_CONDITIONAL([BUILD_MUX], [test "$enable_libwebpmux" = "yes"])
45
46dnl === Check whether libwebpdemux should be built
47AC_MSG_CHECKING(whether libwebpdemux is to be built)
48AC_ARG_ENABLE([libwebpdemux],
49              AS_HELP_STRING([--disable-libwebpdemux],
50                             [Disable libwebpdemux @<:@default=no@:>@]),
51              [], [enable_libwebpdemux=yes])
52AC_MSG_RESULT(${enable_libwebpdemux-no})
53AM_CONDITIONAL([BUILD_DEMUX], [test "$enable_libwebpdemux" = "yes"])
54
55dnl === Check whether decoder library should be built.
56AC_MSG_CHECKING(whether decoder library is to be built)
57AC_ARG_ENABLE([libwebpdecoder],
58              AS_HELP_STRING([--enable-libwebpdecoder],
59                             [Build libwebpdecoder @<:@default=no@:>@]))
60AC_MSG_RESULT(${enable_libwebpdecoder-no})
61AM_CONDITIONAL([BUILD_LIBWEBPDECODER], [test "$enable_libwebpdecoder" = "yes"])
62
63dnl === Check whether libwebpextras should be built
64AC_MSG_CHECKING(whether libwebpextras is to be built)
65AC_ARG_ENABLE([libwebpextras],
66              AS_HELP_STRING([--enable-libwebpextras],
67                             [Build libwebpextras @<:@default=no@:>@]))
68AC_MSG_RESULT(${enable_libwebpextras-no})
69AM_CONDITIONAL([BUILD_EXTRAS], [test "$enable_libwebpextras" = "yes"])
70
71dnl === If --enable-asserts is not defined, define NDEBUG
72
73AC_MSG_CHECKING(whether asserts are enabled)
74AC_ARG_ENABLE([asserts],
75              AS_HELP_STRING([--enable-asserts],
76                             [Enable assert checks]))
77if test "x${enable_asserts-no}" = "xno"; then
78  AM_CPPFLAGS="${AM_CPPFLAGS} -DNDEBUG"
79fi
80AC_MSG_RESULT(${enable_asserts-no})
81AC_SUBST([AM_CPPFLAGS])
82
83AC_ARG_WITH([pkgconfigdir], AS_HELP_STRING([--with-pkgconfigdir=DIR],
84            [Path to the pkgconfig directory @<:@LIBDIR/pkgconfig@:>@]),
85            [pkgconfigdir="$withval"], [pkgconfigdir='${libdir}/pkgconfig'])
86AC_SUBST([pkgconfigdir])
87
88dnl === TEST_AND_ADD_CFLAGS(var, flag)
89dnl ===   Checks whether $CC supports 'flag' and adds it to 'var'
90dnl ===   on success.
91AC_DEFUN([TEST_AND_ADD_CFLAGS],
92         [SAVED_CFLAGS="$CFLAGS"
93          CFLAGS="-Werror $2"
94          AC_MSG_CHECKING([whether $CC supports $2])
95          dnl Note AC_LANG_PROGRAM([]) uses an old-style main definition.
96          AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
97                            [AC_MSG_RESULT([yes])]
98                            dnl Simply append the variable avoiding a
99                            dnl compatibility ifdef for AS_VAR_APPEND as this
100                            dnl variable shouldn't grow all that large.
101                            [$1="${$1} $2"],
102                            [AC_MSG_RESULT([no])])
103          CFLAGS="$SAVED_CFLAGS"])
104TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-fvisibility=hidden])
105TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wall])
106TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wconstant-conversion])
107TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wdeclaration-after-statement])
108TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wextra])
109TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wextra-semi-stmt])
110TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wfloat-conversion])
111TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wformat -Wformat-nonliteral])
112TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wformat -Wformat-security])
113TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wmissing-declarations])
114TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wmissing-prototypes])
115TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wold-style-definition])
116TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wparentheses-equality])
117TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshadow])
118TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshorten-64-to-32])
119TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wstrict-prototypes])
120TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wundef])
121TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunreachable-code-aggressive])
122TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunreachable-code])
123TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunused-but-set-variable])
124TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunused])
125TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wvla])
126# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62040
127# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61622
128AS_IF([test "$GCC" = "yes" ], [
129       gcc_version=`$CC -dumpversion`
130       gcc_wht_bug=""
131       case "$host_cpu" in
132         aarch64|arm64)
133          case "$gcc_version" in
134            4.9|4.9.0|4.9.1) gcc_wht_bug=yes ;;
135          esac
136       esac
137       AS_IF([test "$gcc_wht_bug" = "yes"], [
138              TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-frename-registers])])])
139# Use -flax-vector-conversions, if available, when building intrinsics with
140# older versions of gcc. The flag appeared in 4.3.x, but if backported, and
141# -fno-lax-vector-conversions is set, errors may occur with the intrinsics
142# files along with the older system includes, e.g., emmintrin.h.
143# Originally observed with cc (GCC) 4.2.1 20070831 patched [FreeBSD] (9.3).
144# https://bugs.chromium.org/p/webp/issues/detail?id=274
145AS_IF([test "$GCC" = "yes" ], [
146       case "$host_cpu" in
147         amd64|i?86|x86_64)
148           AC_COMPILE_IFELSE(
149             dnl only check for -flax-vector-conversions with older gcc, skip
150             dnl clang as it reports itself as 4.2.1, but the flag isn't needed.
151             [AC_LANG_SOURCE([#if !defined(__clang__) && defined(__GNUC__) && \
152                                  ((__GNUC__ << 8) | __GNUC_MINOR__) < 0x403
153                              #error old gcc
154                              #endif
155                              int main(void) { return 0; }
156                             ])],,
157              [TEST_AND_ADD_CFLAGS([INTRINSICS_CFLAGS],
158                                   [-flax-vector-conversions])])
159           ;;
160       esac])
161AC_SUBST([AM_CFLAGS])
162
163dnl === Check for machine specific flags
164AC_ARG_ENABLE([sse4.1],
165              AS_HELP_STRING([--disable-sse4.1],
166                             [Disable detection of SSE4.1 support
167                              @<:@default=auto@:>@]))
168
169AS_IF([test "x$enable_sse4_1" != "xno" -a "x$enable_sse2" != "xno"], [
170  SSE41_FLAGS="$INTRINSICS_CFLAGS $SSE41_FLAGS"
171  TEST_AND_ADD_CFLAGS([SSE41_FLAGS], [-msse4.1])
172  AS_IF([test -n "$SSE41_FLAGS"], [
173    SAVED_CFLAGS=$CFLAGS
174    CFLAGS="$CFLAGS $SSE41_FLAGS"
175    AC_CHECK_HEADER([smmintrin.h],
176                    [AC_DEFINE(WEBP_HAVE_SSE41, [1],
177                     [Set to 1 if SSE4.1 is supported])],
178                    [SSE41_FLAGS=""])
179    CFLAGS=$SAVED_CFLAGS])
180  AC_SUBST([SSE41_FLAGS])])
181
182AC_ARG_ENABLE([sse2],
183              AS_HELP_STRING([--disable-sse2],
184                             [Disable detection of SSE2 support
185                              @<:@default=auto@:>@]))
186
187AS_IF([test "x$enable_sse2" != "xno"], [
188  SSE2_FLAGS="$INTRINSICS_CFLAGS $SSE2_FLAGS"
189  TEST_AND_ADD_CFLAGS([SSE2_FLAGS], [-msse2])
190  AS_IF([test -n "$SSE2_FLAGS"], [
191    SAVED_CFLAGS=$CFLAGS
192    CFLAGS="$CFLAGS $SSE2_FLAGS"
193    AC_CHECK_HEADER([emmintrin.h],
194                    [AC_DEFINE(WEBP_HAVE_SSE2, [1],
195                     [Set to 1 if SSE2 is supported])],
196                    [SSE2_FLAGS=""])
197    CFLAGS=$SAVED_CFLAGS])
198  AC_SUBST([SSE2_FLAGS])])
199
200AC_ARG_ENABLE([neon],
201              AS_HELP_STRING([--disable-neon],
202                             [Disable detection of NEON support
203                              @<:@default=auto@:>@]))
204
205AC_ARG_ENABLE([neon_rtcd],
206              AS_HELP_STRING([--disable-neon-rtcd],
207                             [Disable runtime detection of NEON support via
208                              /proc/cpuinfo on Linux hosts
209                              @<:@default=auto@:>@]))
210# For ARM(7) hosts:
211# Both NEON flags unset and NEON support detected = build all modules with NEON
212# NEON detected with the use of -mfpu=neon = build only NEON modules with NEON
213AS_IF([test "x$enable_neon" != "xno"], [
214  case "$host_cpu" in
215    arm|armv7*)
216      # Test for NEON support without flags before falling back to -mfpu=neon
217      for flag in '' '-mfpu=neon'; do
218        LOCAL_NEON_FLAGS="$INTRINSICS_CFLAGS $NEON_FLAGS"
219        TEST_AND_ADD_CFLAGS([LOCAL_NEON_FLAGS], [$flag])
220        SAVED_CFLAGS=$CFLAGS
221        CFLAGS="$CFLAGS $LOCAL_NEON_FLAGS"
222
223        dnl Note AC_LANG_PROGRAM([]) uses an old-style main definition.
224        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
225          #include <arm_neon.h>
226          int main(void) {
227            int8x8_t v = vdup_n_s8(0);
228            (void)v;
229            return 0;
230          }])],
231          [NEON_FLAGS="$(echo $LOCAL_NEON_FLAGS | $SED 's/^ *//')"
232           AS_IF([test -n "$NEON_FLAGS"], [
233             AS_IF([test "${host_os%%-*}" = "linux" -o \
234                         "x$enable_neon_rtcd" = "xno"], [
235               CFLAGS=$SAVED_CFLAGS
236               AC_DEFINE(WEBP_HAVE_NEON, [1], [Set to 1 if NEON is supported])
237               break
238             ],[
239               AC_MSG_WARN(m4_normalize([NEON runtime cpu-detection is
240                                         unavailable for ${host_os%%-*}. Force
241                                         with CFLAGS=-mfpu=neon or
242                                         --disable-neon-rtcd.]))
243               enable_neon_rtcd=no
244               NEON_FLAGS=""
245             ])
246           ],[
247             CFLAGS=$SAVED_CFLAGS
248             AC_DEFINE(WEBP_HAVE_NEON, [1], [Set to 1 if NEON is supported])
249             break
250           ])])
251        CFLAGS=$SAVED_CFLAGS
252      done
253
254      AS_IF([test -n "$NEON_FLAGS"], [
255        # If NEON is available and rtcd is disabled apply NEON_FLAGS globally.
256        AS_IF([test "x$enable_neon_rtcd" = "xno"], [
257          AM_CFLAGS="$AM_CFLAGS $NEON_FLAGS"
258          NEON_FLAGS=""],
259          [AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1],
260                     [Set to 1 if runtime detection of NEON is enabled])])])
261
262      case "$host_os" in
263        *android*) AC_CHECK_HEADERS([cpu-features.h]) ;;
264      esac
265      ;;
266    aarch64*|arm64*)
267      AC_DEFINE(WEBP_HAVE_NEON, [1], [Set to 1 if NEON is supported])
268      ;;
269  esac
270  AC_SUBST([NEON_FLAGS])])
271
272dnl === CLEAR_LIBVARS([var_pfx])
273dnl ===   Clears <var_pfx>_{INCLUDES,LIBS}.
274AC_DEFUN([CLEAR_LIBVARS], [$1_INCLUDES=""; $1_LIBS=""])
275
276dnl === WITHLIB_OPTION([opt_pfx], [outvar_pfx])
277dnl ===   Defines --with-<opt_pfx>{include,lib}dir options which set
278dnl ===   the variables <outvar_pfx>_{INCLUDES,LIBS}.
279AC_DEFUN([WITHLIB_OPTION],
280  [AC_ARG_WITH([$1includedir],
281               AS_HELP_STRING([--with-$1includedir=DIR],
282                              [use $2 includes from DIR]),
283               $2_INCLUDES="-I$withval")
284   AC_ARG_WITH([$1libdir],
285               AS_HELP_STRING([--with-$1libdir=DIR],
286                              [use $2 libraries from DIR]),
287               [$2_LIBS="-L$withval"])])
288
289dnl === LIBCHECK_PROLOGUE([var_pfx])
290dnl ===   Caches the current values of CPPFLAGS/LIBS in SAVED_* then
291dnl ===   prepends the current values with <var_pfx>_{INCLUDES,LIBS}.
292AC_DEFUN([LIBCHECK_PROLOGUE],
293         [SAVED_CPPFLAGS=$CPPFLAGS
294          SAVED_LIBS=$LIBS
295          CPPFLAGS="$$1_INCLUDES $CPPFLAGS"
296          LIBS="$$1_LIBS $LIBS"])
297
298dnl === LIBCHECK_EPILOGUE([var_pfx])
299dnl ===   Restores the values of CPPFLAGS/LIBS from SAVED_* and exports
300dnl ===   <var_pfx>_{INCLUDES,LIBS} with AC_SUBST.
301AC_DEFUN([LIBCHECK_EPILOGUE],
302         [AC_SUBST($1_LIBS)
303          AC_SUBST($1_INCLUDES)
304          CPPFLAGS=$SAVED_CPPFLAGS
305          LIBS=$SAVED_LIBS])
306
307dnl === Check for gcc builtins
308
309dnl === CHECK_FOR_BUILTIN([builtin], [param], [define])
310dnl ===   links a C AC_LANG_PROGRAM, with <builtin>(<param>)
311dnl ===   AC_DEFINE'ing <define> if successful.
312AC_DEFUN([CHECK_FOR_BUILTIN],
313         [AC_LANG_PUSH([C])
314          AC_MSG_CHECKING([for $1])
315          AC_LINK_IFELSE([AC_LANG_PROGRAM([], [(void)$1($2)])],
316                         [AC_MSG_RESULT([yes])
317                          AC_DEFINE([$3], [1],
318                                    [Set to 1 if $1 is available])],
319                         [AC_MSG_RESULT([no])]),
320          AC_LANG_POP])
321
322dnl AC_CHECK_FUNC doesn't work with builtin's.
323CHECK_FOR_BUILTIN([__builtin_bswap16], [1u << 15], [HAVE_BUILTIN_BSWAP16])
324CHECK_FOR_BUILTIN([__builtin_bswap32], [1u << 31], [HAVE_BUILTIN_BSWAP32])
325CHECK_FOR_BUILTIN([__builtin_bswap64], [1ull << 63], [HAVE_BUILTIN_BSWAP64])
326
327dnl === Check for pthread support
328AC_ARG_ENABLE([threading],
329              AS_HELP_STRING([--disable-threading],
330                             [Disable detection of thread support]),,
331              [enable_threading=yes])
332if test "$enable_threading" = "yes"; then
333  AC_MSG_NOTICE([checking for threading support...])
334  AX_PTHREAD([AC_DEFINE([WEBP_USE_THREAD], [1],
335                        [Undefine this to disable thread support.])
336              LIBS="$PTHREAD_LIBS $LIBS"
337              CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
338              CC="$PTHREAD_CC"
339             ],
340             [AC_CHECK_FUNC([_beginthreadex],
341                            [AC_DEFINE([WEBP_USE_THREAD], [1],
342                                       [Undefine this to disable thread
343                                        support.])],
344                            [enable_threading=no])])
345fi
346AC_MSG_NOTICE([checking if threading is enabled... ${enable_threading-no}])
347
348dnl === check for OpenGL/GLUT support ===
349
350AC_ARG_ENABLE([gl], AS_HELP_STRING([--disable-gl],
351                                   [Disable detection of OpenGL support
352                                    @<:@default=auto@:>@]))
353AS_IF([test "x$enable_gl" != "xno"], [
354  CLEAR_LIBVARS([GL])
355  WITHLIB_OPTION([gl], [GL])
356
357  LIBCHECK_PROLOGUE([GL])
358
359  glut_cflags="none"
360  glut_ldflags="none"
361  case $host_os in
362    darwin*)
363      # Special case for OSX builds. Append these to give the user a chance to
364      # override with --with-gl*
365      glut_cflags="$glut_cflags|-framework GLUT -framework OpenGL"
366      glut_ldflags="$glut_ldflags|-framework GLUT -framework OpenGL"
367      # quiet deprecation warnings for glut
368      TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wno-deprecated-declarations])
369      ;;
370  esac
371
372  GLUT_SAVED_CPPFLAGS="$CPPFLAGS"
373  SAVED_IFS="$IFS"
374  IFS="|"
375  for flag in $glut_cflags; do
376    # restore IFS immediately as the autoconf macros may need the default.
377    IFS="$SAVED_IFS"
378    unset ac_cv_header_GL_glut_h
379    unset ac_cv_header_OpenGL_glut_h
380
381    case $flag in
382      none) ;;
383      *) CPPFLAGS="$flag $CPPFLAGS";;
384    esac
385    AC_CHECK_HEADERS([GL/glut.h GLUT/glut.h OpenGL/glut.h],
386                     [glut_headers=yes;
387                      test "$flag" = "none" || GL_INCLUDES="$CPPFLAGS";
388                      break])
389    CPPFLAGS="$GLUT_SAVED_CPPFLAGS"
390    test "$glut_headers" = "yes" && break
391  done
392  IFS="$SAVED_IFS"
393
394  if test "$glut_headers" = "yes"; then
395    AC_LANG_PUSH([C])
396    GLUT_SAVED_LDFLAGS="$LDFLAGS"
397    SAVED_IFS="$IFS"
398    IFS="|"
399    for flag in $glut_ldflags; do
400      # restore IFS immediately as the autoconf macros may need the default.
401      IFS="$SAVED_IFS"
402      unset ac_cv_search_glBegin
403
404      case $flag in
405        none) ;;
406        *) LDFLAGS="$flag $LDFLAGS";;
407      esac
408
409      # find libGL
410      GL_SAVED_LIBS="$LIBS"
411      AC_SEARCH_LIBS([glBegin], [GL OpenGL opengl32])
412      LIBS="$GL_SAVED_LIBS"
413
414      # A direct link to libGL may not be necessary on e.g., linux.
415      GLUT_SAVED_LIBS="$LIBS"
416      for lib in "" "-lglut" "-lglut $ac_cv_search_glBegin"; do
417        LIBS="$lib"
418        AC_LINK_IFELSE(
419          [AC_LANG_PROGRAM([
420             #ifdef __cplusplus
421             # define EXTERN_C extern "C"
422             #else
423             # define EXTERN_C
424             #endif
425             EXTERN_C char glOrtho();
426             EXTERN_C char glutMainLoop();
427            ],[
428             glOrtho();
429             glutMainLoop();
430            ])
431          ],
432          AC_DEFINE(WEBP_HAVE_GL, [1],
433                    [Set to 1 if OpenGL is supported])
434          [glut_support=yes], []
435        )
436        if test "$glut_support" = "yes"; then
437          GL_LIBS="$LDFLAGS $lib"
438          break
439        fi
440      done
441      LIBS="$GLUT_SAVED_LIBS"
442      LDFLAGS="$GLUT_SAVED_LDFLAGS"
443      test "$glut_support" = "yes" && break
444    done
445    IFS="$SAVED_IFS"
446    AC_LANG_POP
447  fi
448
449  LIBCHECK_EPILOGUE([GL])
450
451  if test "$glut_support" = "yes" -a "$enable_libwebpdemux" = "yes"; then
452    build_vwebp=yes
453  else
454    AC_MSG_NOTICE(
455      m4_normalize([Not building vwebp.
456                    OpenGL libraries and --enable-libwebpdemux are required.]))
457  fi
458])
459AM_CONDITIONAL([BUILD_VWEBP], [test "$build_vwebp" = "yes"])
460
461dnl === check for SDL support ===
462
463AC_ARG_ENABLE([sdl],
464              AS_HELP_STRING([--disable-sdl],
465                             [Disable detection of SDL support
466                              @<:@default=auto@:>@]))
467AS_IF([test "x$enable_sdl" != "xno"], [
468  CLEAR_LIBVARS([SDL])
469  AC_PATH_PROGS([LIBSDL_CONFIG], [sdl2-config])
470  if test -n "$LIBSDL_CONFIG"; then
471    SDL_INCLUDES=`$LIBSDL_CONFIG --cflags`
472    SDL_LIBS="`$LIBSDL_CONFIG --libs`"
473  fi
474
475  WITHLIB_OPTION([sdl], [SDL])
476
477  sdl_header="no"
478  LIBCHECK_PROLOGUE([SDL])
479  AC_CHECK_HEADER([SDL2/SDL.h], [sdl_header="SDL2/SDL.h"],
480                  [AC_MSG_WARN(SDL2 library not available - no SDL.h)])
481  if test x"$sdl_header" != "xno"; then
482    AC_LANG_PUSH(C)
483    SDL_SAVED_LIBS="$LIBS"
484    for lib in "" "-lSDL2" "-lSDL2main -lSDL2"; do
485      LIBS="$SDL_SAVED_LIBS $lib"
486      # Perform a full link to ensure SDL_main is resolved if needed.
487      AC_LINK_IFELSE(
488        [AC_LANG_SOURCE([
489           #include <$sdl_header>
490           int main(int argc, char** argv) {
491             SDL_Init(0);
492             return 0;
493           }])],
494        [SDL_LIBS="$LDFLAGS $LIBS"
495         SDL_INCLUDES="$SDL_INCLUDES -DWEBP_HAVE_SDL"
496         AC_DEFINE(WEBP_HAVE_SDL, [1],
497                   [Set to 1 if SDL library is installed])
498         sdl_support=yes]
499      )
500      if test x"$sdl_support" = "xyes"; then
501        break
502      fi
503    done
504    # LIBS is restored by LIBCHECK_EPILOGUE
505    AC_LANG_POP
506    if test x"$sdl_header" = "xSDL.h"; then
507      SDL_INCLUDES="$SDL_INCLUDES -DWEBP_HAVE_JUST_SDL_H"
508    fi
509  fi
510  LIBCHECK_EPILOGUE([SDL])
511
512  if test x"$sdl_support" = "xyes"; then
513    build_vwebp_sdl=yes
514  else
515    AC_MSG_NOTICE([Not building vwebp-sdl. SDL library is required.])
516  fi
517])
518
519AM_CONDITIONAL([BUILD_VWEBP_SDL], [test "$build_vwebp_sdl" = "yes"])
520
521dnl === check for PNG support ===
522
523AC_ARG_ENABLE([png], AS_HELP_STRING([--disable-png],
524                                    [Disable detection of PNG format support
525                                     @<:@default=auto@:>@]))
526AS_IF([test "x$enable_png" != "xno"], [
527  CLEAR_LIBVARS([PNG])
528  AC_PATH_PROGS([LIBPNG_CONFIG],
529                [libpng-config libpng16-config libpng15-config libpng14-config \
530                 libpng12-config])
531  if test -n "$LIBPNG_CONFIG"; then
532    PNG_INCLUDES=`$LIBPNG_CONFIG --cflags`
533    PNG_LIBS="`$LIBPNG_CONFIG --ldflags`"
534  fi
535
536  WITHLIB_OPTION([png], [PNG])
537
538  LIBCHECK_PROLOGUE([PNG])
539  AC_CHECK_HEADER(png.h,
540    AC_SEARCH_LIBS(png_get_libpng_ver, [png],
541                   [test "$ac_cv_search_png_get_libpng_ver" = "none required" \
542                      || PNG_LIBS="$PNG_LIBS $ac_cv_search_png_get_libpng_ver"
543                    PNG_INCLUDES="$PNG_INCLUDES -DWEBP_HAVE_PNG"
544                    AC_DEFINE(WEBP_HAVE_PNG, [1],
545                              [Set to 1 if PNG library is installed])
546                    png_support=yes
547                   ],
548                   [AC_MSG_WARN(Optional png library not found)
549                    PNG_LIBS=""
550                    PNG_INCLUDES=""
551                   ],
552                   [$MATH_LIBS]),
553    [AC_MSG_WARN(png library not available - no png.h)
554     PNG_LIBS=""
555     PNG_INCLUDES=""
556    ],
557  )
558  LIBCHECK_EPILOGUE([PNG])
559])
560
561dnl === check for JPEG support ===
562
563AC_ARG_ENABLE([jpeg],
564              AS_HELP_STRING([--disable-jpeg],
565                             [Disable detection of JPEG format support
566                              @<:@default=auto@:>@]))
567AS_IF([test "x$enable_jpeg" != "xno"], [
568  CLEAR_LIBVARS([JPEG])
569  WITHLIB_OPTION([jpeg], [JPEG])
570
571  LIBCHECK_PROLOGUE([JPEG])
572  AC_CHECK_HEADER(jpeglib.h,
573    AC_CHECK_LIB(jpeg, jpeg_set_defaults,
574                 [JPEG_LIBS="$JPEG_LIBS -ljpeg"
575                  JPEG_INCLUDES="$JPEG_INCLUDES -DWEBP_HAVE_JPEG"
576                  AC_DEFINE(WEBP_HAVE_JPEG, [1],
577                            [Set to 1 if JPEG library is installed])
578                  jpeg_support=yes
579                 ],
580                 AC_MSG_WARN(Optional jpeg library not found),
581                 [$MATH_LIBS]),
582    AC_MSG_WARN(jpeg library not available - no jpeglib.h)
583  )
584  LIBCHECK_EPILOGUE([JPEG])
585])
586
587dnl === check for TIFF support ===
588
589AC_ARG_ENABLE([tiff],
590              AS_HELP_STRING([--disable-tiff],
591                             [Disable detection of TIFF format support
592                              @<:@default=auto@:>@]))
593AS_IF([test "x$enable_tiff" != "xno"], [
594  CLEAR_LIBVARS([TIFF])
595  WITHLIB_OPTION([tiff], [TIFF])
596
597  LIBCHECK_PROLOGUE([TIFF])
598  AC_CHECK_HEADER(tiffio.h,
599    AC_CHECK_LIB(tiff, TIFFGetVersion,
600                 [TIFF_LIBS="$TIFF_LIBS -ltiff"
601                  TIFF_INCLUDES="$TIFF_INCLUDES -DWEBP_HAVE_TIFF"
602                  AC_DEFINE(WEBP_HAVE_TIFF, [1],
603                            [Set to 1 if TIFF library is installed])
604                  tiff_support=yes
605                 ],
606                 AC_MSG_WARN(Optional tiff library not found),
607                 [$MATH_LIBS]),
608    AC_MSG_WARN(tiff library not available - no tiffio.h)
609  )
610  LIBCHECK_EPILOGUE([TIFF])
611])
612
613dnl === check for GIF support ===
614
615AC_ARG_ENABLE([gif], AS_HELP_STRING([--disable-gif],
616                                    [Disable detection of GIF format support
617                                     @<:@default=auto@:>@]))
618AS_IF([test "x$enable_gif" != "xno"], [
619  CLEAR_LIBVARS([GIF])
620  WITHLIB_OPTION([gif], [GIF])
621
622  LIBCHECK_PROLOGUE([GIF])
623  AC_CHECK_HEADER(gif_lib.h,
624    AC_CHECK_LIB([gif], [DGifOpenFileHandle],
625                 [GIF_LIBS="$GIF_LIBS -lgif"
626                  AC_DEFINE(WEBP_HAVE_GIF, [1],
627                            [Set to 1 if GIF library is installed])
628                  gif_support=yes
629                 ],
630                 AC_MSG_WARN(Optional gif library not found),
631                 [$MATH_LIBS]),
632    AC_MSG_WARN(gif library not available - no gif_lib.h)
633  )
634  LIBCHECK_EPILOGUE([GIF])
635
636  if test "$gif_support" = "yes" -a \
637          "$enable_libwebpdemux" = "yes"; then
638    build_anim_diff=yes
639  else
640    AC_MSG_NOTICE(
641      [Not building anim_diff. libgif and --enable-libwebpdemux are required.])
642  fi
643
644  if test "$gif_support" = "yes" -a \
645          "$enable_libwebpmux" = "yes"; then
646    build_gif2webp=yes
647  else
648    AC_MSG_NOTICE(
649      [Not building gif2webp. libgif and --enable-libwebpmux are required.])
650  fi
651])
652AM_CONDITIONAL([BUILD_ANIMDIFF], [test "${build_anim_diff}" = "yes"])
653AM_CONDITIONAL([BUILD_GIF2WEBP], [test "${build_gif2webp}" = "yes"])
654
655if test "$enable_libwebpdemux" = "yes" -a "$enable_libwebpmux" = "yes"; then
656  build_img2webp=yes
657else
658  AC_MSG_NOTICE(
659    m4_normalize([Not building img2webp.
660                  --enable-libwebpdemux & --enable-libwebpmux are required.]))
661fi
662AM_CONDITIONAL([BUILD_IMG2WEBP], [test "${build_img2webp}" = "yes"])
663
664if test "$enable_libwebpmux" = "yes"; then
665  build_webpinfo=yes
666else
667  AC_MSG_NOTICE([Not building webpinfo. --enable-libwebpdemux is required.])
668fi
669AM_CONDITIONAL([BUILD_WEBPINFO], [test "${build_webpinfo}" = "yes"])
670
671dnl === check for WIC support ===
672
673AC_ARG_ENABLE([wic],
674              AS_HELP_STRING([--disable-wic],
675                             [Disable Windows Imaging Component (WIC) detection.
676                              @<:@default=auto@:>@]),,
677              [enable_wic=yes])
678
679case $host_os in
680mingw*)
681if test "$enable_wic" = "yes"; then
682  AC_CHECK_HEADERS([wincodec.h shlwapi.h windows.h])
683  if test "$ac_cv_header_wincodec_h" = "yes"; then
684    AC_MSG_CHECKING(for Windows Imaging Component support)
685    SAVED_LIBS=$LIBS
686    LIBS="-lshlwapi -lole32 $LIBS"
687    # match include structure from [cd]webp.c
688    wic_headers="
689      #define INITGUID
690      #define CINTERFACE
691      #define COBJMACROS
692      #define _WIN32_IE 0x500
693
694      #include <shlwapi.h>
695      #include <windows.h>
696      #include <wincodec.h>
697      "
698    # test for functions from each lib and the GUID is created properly
699    wic_main="
700      int main(void) {
701        CLSID_WICImagingFactory;
702        CoInitialize(NULL);
703        SHCreateStreamOnFile(NULL, 0, NULL);
704        return 0;
705      }
706      "
707    AC_LANG_PUSH(C)
708    AC_LINK_IFELSE(
709      [AC_LANG_SOURCE([
710         $wic_headers
711         $wic_main])],
712      [wic_support=yes],
713      [wic_support=no]
714    )
715    AC_LANG_POP
716
717    test "$wic_support" = "yes" || LIBS=$SAVED_LIBS
718    AC_MSG_RESULT(${wic_support-no})
719  fi
720fi
721esac
722
723dnl === If --enable-swap-16bit-csp is defined, add -DWEBP_SWAP_16BIT_CSP=1
724
725USE_SWAP_16BIT_CSP=""
726AC_MSG_CHECKING(if --enable-swap-16bit-csp option is specified)
727AC_ARG_ENABLE([swap-16bit-csp],
728              AS_HELP_STRING([--enable-swap-16bit-csp],
729                             [Enable byte swap for 16 bit colorspaces]))
730if test "$enable_swap_16bit_csp" = "yes"; then
731  USE_SWAP_16BIT_CSP="-DWEBP_SWAP_16BIT_CSP=1"
732fi
733AC_MSG_RESULT(${enable_swap_16bit_csp-no})
734AC_SUBST(USE_SWAP_16BIT_CSP)
735
736dnl === If --disable-near-lossless is defined, add -DWEBP_NEAR_LOSSLESS=0
737
738AC_DEFINE(WEBP_NEAR_LOSSLESS, [1], [Enable near lossless encoding])
739AC_MSG_CHECKING(if --disable-near-lossless option is specified)
740AC_ARG_ENABLE([near_lossless],
741              AS_HELP_STRING([--disable-near-lossless],
742                             [Disable near lossless encoding]),
743              [], [enable_near_lossless=yes])
744if test "$enable_near_lossless" = "no"; then
745  AC_DEFINE(WEBP_NEAR_LOSSLESS, [0], [Enable near lossless encoding])
746  AC_MSG_RESULT([yes])
747else
748  AC_MSG_RESULT([no])
749fi
750
751dnl =========================
752
753dnl Add an empty webp_libname_prefix variable for use in *.pc.in.
754AC_SUBST([webp_libname_prefix])
755AC_CONFIG_MACRO_DIR([m4])
756AC_CONFIG_HEADERS([src/webp/config.h])
757AC_CONFIG_FILES([Makefile src/Makefile man/Makefile \
758                 examples/Makefile extras/Makefile imageio/Makefile \
759                 sharpyuv/Makefile sharpyuv/libsharpyuv.pc \
760                 src/dec/Makefile src/enc/Makefile src/dsp/Makefile \
761                 src/demux/Makefile src/mux/Makefile \
762                 src/utils/Makefile \
763                 src/libwebp.pc src/libwebpdecoder.pc \
764                 src/demux/libwebpdemux.pc src/mux/libwebpmux.pc])
765
766dnl fix exports from MinGW builds
767AC_CONFIG_COMMANDS_POST([$SED -i 's/-DDLL_EXPORT/-DWEBP_DLL/' config.status])
768AC_OUTPUT
769
770AC_MSG_NOTICE([
771WebP Configuration Summary
772--------------------------
773
774Shared libraries: ${enable_shared}
775Static libraries: ${enable_static}
776Threading support: ${enable_threading-no}
777libwebp: yes
778libwebpdecoder: ${enable_libwebpdecoder-no}
779libwebpdemux: ${enable_libwebpdemux-no}
780libwebpmux: ${enable_libwebpmux-no}
781libwebpextras: ${enable_libwebpextras-no}
782
783Tools:
784cwebp : ${enable_libwebpdemux-no}
785  Input format support
786  ====================
787  JPEG : ${jpeg_support-no}
788  PNG  : ${png_support-no}
789  TIFF : ${tiff_support-no}
790  WIC  : ${wic_support-no}
791dwebp : ${enable_libwebpdemux-no}
792  Output format support
793  =====================
794  PNG  : ${png_support-no}
795  WIC  : ${wic_support-no}
796GIF support : ${gif_support-no}
797anim_diff   : ${build_anim_diff-no}
798gif2webp    : ${build_gif2webp-no}
799img2webp    : ${build_img2webp-no}
800webpmux     : ${enable_libwebpmux-no}
801vwebp       : ${build_vwebp-no}
802webpinfo    : ${build_webpinfo-no}
803SDL support : ${sdl_support-no}
804vwebp_sdl   : ${build_vwebp_sdl-no}
805])
806