Subject: Re: bug#30346: lcms.c doesn't compile when lcms.h isn't in default search path

From: Noam Postavsky <[email-masked]>
Date: Sun, 04 Feb 2018 20:54:45 -0500

Rainer Orth <[email-masked]> writes:

> I just tried to compile emacs 26.0.91 on Solaris 11.4 Beta.  This failed
> building lcms.o:
>
>   CC       lcms.o
> /vol/gnu/src/emacs/emacs-26.0.91/src/lcms.c:23:19: fatal error: lcms2.h: No such file or directory
>
> lcms.h lives in /usr/include/lcms/lcms.h and lcms2.pc correctly adds a
> matching -I to Cflags.  However, configure.ac just does a link test for
> cmsCreateTransform, which succeeds.  I can work around this by adding a
> matching -I option to CPPFLAGS at configure time, but it seems silly
> having to do so if the information can be derived automatically.

Does the below work?  (I notice that all of a sudden this bug's severity
has been set to "important", although it looks more like it should be
"minor" to me.  And I would intend the patch for master, not emacs-26.)

>From 30b2c9bcc26739cc6634f496b3dc415cf5310555 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Sun, 4 Feb 2018 20:43:26 -0500
Subject: [PATCH v1] Use pkg-config to find lcms2 CFLAGS and LIBS (Bug#30346)

* configure.ac: Use EMACS_CHECK_MODULES fors LCMS2 rather than
AC_SEARCH_LIBS.
* src/Makefile.in: Get LCMS2_LIBS and LCMS2_CFLAGS from configure,
instead of just LIBLCMS2.
---
 configure.ac    | 12 +++++-------
 src/Makefile.in |  7 ++++---
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index f9c7bb76e5..7ee1fae83b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3469,12 +3469,9 @@ AC_DEFUN
 HAVE_LCMS2=no
 LIBLCMS2=
 if test "${with_lcms2}" != "no"; then
-  OLIBS=$LIBS
-  AC_SEARCH_LIBS([cmsCreateTransform], [lcms2], [HAVE_LCMS2=yes])
-  LIBS=$OLIBS
-  case $ac_cv_search_cmsCreateTransform in
-    -*) LIBLCMS2=$ac_cv_search_cmsCreateTransform ;;
-  esac
+  EMACS_CHECK_MODULES([LCMS2], [lcms2])
+  AC_CHECK_HEADER([lcms2.h])
+  AC_CHECK_LIB([lcms2], [cmsCreateTransform])
 fi
 if test "${HAVE_LCMS2}" = "yes"; then
   AC_DEFINE([HAVE_LCMS2], 1, [Define to 1 if you have the lcms2 library (-llcms2).])
@@ -3483,7 +3480,8 @@ AC_DEFUN
      LIBLCMS2=
   fi
 fi
-AC_SUBST(LIBLCMS2)
+AC_SUBST(LCMS2_CFLAGS)
+AC_SUBST(LCMS2_LIBS)
 
 HAVE_ZLIB=no
 LIBZ=
diff --git a/src/Makefile.in b/src/Makefile.in
index 15ca1667d6..9fa1d7b6f2 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -234,7 +234,8 @@ LIBXML2_CFLAGS =
 
 GETADDRINFO_A_LIBS = @GETADDRINFO_A_LIBS@
 
-LIBLCMS2 = @LIBLCMS2@
+LCMS2_LIBS = @LCMS2_LIBS@
+LCMS2_CFLAGS = @LCMS2_CFLAGS@
 
 LIBZ = @LIBZ@
 
@@ -360,7 +361,7 @@ EMACS_CFLAGS=
   $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
   $(PNG_CFLAGS) $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \
   $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) $(XFIXES_CFLAGS) $(XDBE_CFLAGS) \
-  $(WEBKIT_CFLAGS) \
+  $(WEBKIT_CFLAGS) $(LCMS2_CFLAGS) \
   $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
   $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
   $(LIBSYSTEMD_CFLAGS) \
@@ -492,7 +493,7 @@ LIBES =
    $(LIBXML2_LIBS) $(LIBGPM) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
    $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
    $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
-   $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) $(LIBLCMS2) \
+   $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) $(LCMS2_LIBS) \
    $(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) $(LIBMODULES) $(LIBSYSTEMD_LIBS)
 
 ## FORCE it so that admin/unidata can decide whether these files
-- 
2.11.0