diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2021-10-25 21:41:17 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2021-11-03 22:02:49 +0100 |
commit | ea00220b6f44a00c2efa792c538f1804ebe183c2 (patch) | |
tree | 6963c78b1c21441bfad8e3f181862837b38df413 /gphoto-m4 | |
parent | 9878f31b79bd0dcc9c6ae7ab7083410c30bbd404 (diff) | |
download | libgphoto2-ea00220b6f44a00c2efa792c538f1804ebe183c2.tar.gz |
Update the checks for libjpeg (GP_LIBJPEG)
Update the checks for libjpeg to try libjpeg.pc with
PKG_CHECK_MODULES first, and also to allow explicitly
set LIBJPEG_CFLAGS and LIBJPEG_LIBS.
The old detection logic did not allow specifying the location
of libjpeg at all. It only allowed either disabling libjpeg
or using libjpeg from the default include and linker paths.
So this also changes the places in the Makefiles where we
used to add @LIBJPEG@ to the linker to both link with
$(LIBJPEG_LIBS) and compile with $(LIBJPEG_CFLAGS).
The new configure logic keeps --without-jpeg to force-
disable libjpeg, but updates the detection of libjpeg
to first try the LIBJPEG_* variables if given, otherwise
try PKG_CHECK_MODULES for libjpeg, and only then falls
back to the old way of just trying the default include
and link locations for libjpeg.
This mentions more information in the configure summary
if not building with libjpeg.
This is the first time we make it possible to build with
libjpeg from e.g. FreeBSD ports' or MacOS homebrew's
jpeg-turbo packages.
Diffstat (limited to 'gphoto-m4')
-rw-r--r-- | gphoto-m4/Makefile-files | 1 | ||||
-rw-r--r-- | gphoto-m4/gp-libjpeg.m4 | 139 |
2 files changed, 140 insertions, 0 deletions
diff --git a/gphoto-m4/Makefile-files b/gphoto-m4/Makefile-files index 2a89dd2d8..70fc5439a 100644 --- a/gphoto-m4/Makefile-files +++ b/gphoto-m4/Makefile-files @@ -14,6 +14,7 @@ EXTRA_DIST += %reldir%/gp-documentation.m4 EXTRA_DIST += %reldir%/gp-driverdir.m4 EXTRA_DIST += %reldir%/gp-gettext-hack.m4 EXTRA_DIST += %reldir%/gp-internal-docs.m4 +EXTRA_DIST += %reldir%/gp-libjpeg.m4 EXTRA_DIST += %reldir%/gp-libltdl.m4 EXTRA_DIST += %reldir%/gp-manual-docbook-xml.m4 EXTRA_DIST += %reldir%/gp-manual-documentation.m4 diff --git a/gphoto-m4/gp-libjpeg.m4 b/gphoto-m4/gp-libjpeg.m4 new file mode 100644 index 000000000..841fd0af3 --- /dev/null +++ b/gphoto-m4/gp-libjpeg.m4 @@ -0,0 +1,139 @@ +dnl #################################################################### +dnl GP_LIBJPEG +dnl #################################################################### +dnl +dnl * If --without-jpeg or --with-jpeg=no is given, build without +dnl libjpeg support. +dnl * If not explicitly disabled by --without-jpeg, autodetect libjpeg. +dnl * If any of LIBJPEG_(CFLAGS|LIBS) is explicitly given, try +dnl compile+link using that. +dnl * If compile+link works, use that. +dnl * If compile+link fails, abort with error message. +dnl * If none of LIBJPEG_(CFLAGS|LIBS) are explicitly given, try +dnl pkg-config to find libjpeg.pc. +dnl * If libjpeg.pc has been found, try compile+link. +dnl * If compile+link works, use that. +dnl * If compile+link fails, build without libjpeg. +dnl * If libjpeg.pc has not been found, try default location. +dnl * If compile+link works, use that. +dnl * If compile+link fails, build without libjpeg. +dnl +AC_DEFUN([GP_LIBJPEG], [dnl +dnl +AC_MSG_CHECKING([whether to build with libjpeg]) +AC_ARG_WITH([jpeg], [dnl + AS_HELP_STRING([--without-jpeg], + [Build without libjpeg (default: with libjpeg)]) +], [dnl just keep the with-jpeg however it is given + AS_VAR_IF([with_jpeg], [no], [], [dnl + AC_MSG_ERROR([ +Unhandled value given to --with-jpeg / --without-jpeg: '$with_jpeg' +]) + ]) +], [dnl + with_jpeg=autodetect +]) +AC_MSG_RESULT([$with_jpeg]) +dnl +AS_VAR_IF([with_jpeg], [no], [dnl Not using libjpeg, so no checks are needed + # libjpeg explictly disabled from command line + GP_CONFIG_MSG([JPEG mangling support], + [no (disabled by --without-jpeg)]) +], [dnl + have_libjpeg=no + + AC_MSG_CHECKING([for libjpeg via variables]) + AS_IF([test "x$LIBJPEG_LIBS$LIBJPEG_CFLAGS" != x], [dnl + GP_LINK_LIBJPEG_IFELSE([ + AC_MSG_RESULT([found and works]) + have_libjpeg=yes + ], [dnl + AC_MSG_RESULT([found but fails to link]) + AC_MSG_ERROR([ +libjpeg not found despite LIBJPEG_CFLAGS and/or LIBJPEG_LIBS being set. +]) + ]) + ], [dnl + AC_MSG_RESULT([no]) + ]) + + AS_VAR_IF([have_libjpeg], [no], [dnl + PKG_CHECK_MODULES([LIBJPEG], [libjpeg], [dnl + AC_MSG_CHECKING([linking with libjpeg works]) + GP_LINK_LIBJPEG_IFELSE([dnl + have_libjpeg=yes + AC_MSG_RESULT([yes]) + ], [dnl + AC_MSG_RESULT([no]) + ]) + ], [dnl + LIBJPEG_LIBS="-ljpeg" + AC_MSG_CHECKING([for libjpeg at default location]) + GP_LINK_LIBJPEG_IFELSE([dnl + have_libjpeg=yes + AC_MSG_RESULT([yes]) + ], [dnl + AC_MSG_RESULT([no]) + AS_UNSET([LIBJPEG_LIBS]) + ]) + ]) + ]) + + AS_VAR_IF([have_libjpeg], [no], [dnl + GP_CONFIG_MSG([JPEG mangling support], + [${have_libjpeg} (requires libjpeg)]) + ], [dnl + AC_DEFINE([HAVE_LIBJPEG], [1], + [define if building with libjpeg]) + GP_CONFIG_MSG([JPEG mangling support], + [${have_libjpeg}]) + ]) +]) +])dnl +dnl +dnl +dnl #################################################################### +dnl GP_LINK_LIBJPEG_IFELSE([if-true], [if-false]) +dnl Make sure we can actually compile and link against libjpeg. +dnl #################################################################### +dnl +AC_DEFUN([GP_LINK_LIBJPEG_IFELSE], [dnl +AC_LANG_PUSH([C]) +saved_CPPFLAGS="$CPPFLAGS" +saved_LIBS="$LIBS" +CPPFLAGS="$CPPFLAGS $LIBJPEG_CFLAGS" +LIBS="$LIBS $LIBJPEG_LIBS" +AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +/* jpeglib.h fails to include all required system headers, so jpeglib.h + * must be included after stddef.h (size_t) and stdio.h (FILE). + */ +#include <jpeglib.h> + +int main(int argc, char **argv) +{ + j_decompress_ptr cinfo = NULL; + (void) argc; + (void) argv; + /* Running this will give a segfault */ + if (jpeg_start_decompress(cinfo)) { + printf("true\n"); + } else { + printf("false\n"); + } + return 0; +} +]])], [$1], [$2]) +CPPFLAGS="$saved_CPPFLAGS" +LIBS="$saved_LIBS" +AC_LANG_POP([C]) +])dnl +dnl +dnl +dnl #################################################################### +dnl +dnl Local Variables: +dnl mode: autoconf +dnl End: |