From 11fe51b61b21bdaa517657f80d8e833c3bf0acf3 Mon Sep 17 00:00:00 2001
From: Francois Gouget <fgouget@free.fr>
Date: Mon, 6 May 2013 01:05:33 +0200
Subject: [PATCH] gphoto2.ds: Check for libgphoto2 and libgphoto2_port
 independently.

---
 configure                      | 87 ++++++++++++++++++++++++++++++++--
 configure.ac                   | 18 +++++--
 dlls/gphoto2.ds/Makefile.in    |  4 +-
 dlls/gphoto2.ds/gphoto2_main.c | 10 ++--
 include/config.h.in            |  5 +-
 5 files changed, 109 insertions(+), 15 deletions(-)

diff --git a/configure b/configure
index 90109d1a2af..3b1b38cef9c 100755
--- a/configure
+++ b/configure
@@ -654,6 +654,8 @@ FREETYPE_LIBS
 FREETYPE_CFLAGS
 LCMSLIBS
 RESOLVLIBS
+GPHOTO2_PORT_LIBS
+GPHOTO2_PORT_CFLAGS
 GPHOTO2_LIBS
 GPHOTO2_CFLAGS
 SANE_LIBS
@@ -874,6 +876,8 @@ SANE_CFLAGS
 SANE_LIBS
 GPHOTO2_CFLAGS
 GPHOTO2_LIBS
+GPHOTO2_PORT_CFLAGS
+GPHOTO2_PORT_LIBS
 FREETYPE_CFLAGS
 FREETYPE_LIBS
 GSTREAMER_CFLAGS
@@ -1582,6 +1586,10 @@ Some influential environment variables:
               C compiler flags for libgphoto2, overriding pkg-config
   GPHOTO2_LIBS
               Linker flags for libgphoto2, overriding pkg-config
+  GPHOTO2_PORT_CFLAGS
+              C compiler flags for libgphoto2_port, overriding pkg-config
+  GPHOTO2_PORT_LIBS
+              Linker flags for libgphoto2_port, overriding pkg-config
   FREETYPE_CFLAGS
               C compiler flags for freetype2, overriding pkg-config
   FREETYPE_LIBS
@@ -10653,14 +10661,14 @@ then
 elif test -n "$PKG_CONFIG"; then :
   GPHOTO2_CFLAGS=`$PKG_CONFIG --cflags libgphoto2 2>/dev/null`
 fi
-GPHOTO2_CFLAGS=${GPHOTO2_CFLAGS:-`(gphoto2-config --cflags || gphoto2-port-config --cflags) 2>/dev/null`}
+GPHOTO2_CFLAGS=${GPHOTO2_CFLAGS:-`gphoto2-config --cflags 2>/dev/null`}
 CPPFLAGS="$CPPFLAGS $GPHOTO2_CFLAGS"
 if test -n "$GPHOTO2_LIBS"; then :
 
 elif test -n "$PKG_CONFIG"; then :
   GPHOTO2_LIBS=`$PKG_CONFIG --libs libgphoto2 2>/dev/null`
 fi
-GPHOTO2_LIBS=${GPHOTO2_LIBS:-`(gphoto2-config --libs || gphoto2-port-config --libs) 2>/dev/null`}
+GPHOTO2_LIBS=${GPHOTO2_LIBS:-`gphoto2-config --libs 2>/dev/null`}
 GPHOTO2_LIBS=${GPHOTO2_LIBS:-"-lgphoto2"}
     ac_fn_c_check_header_mongrel "$LINENO" "gphoto2-camera.h" "ac_cv_header_gphoto2_camera_h" "$ac_includes_default"
 if test "x$ac_cv_header_gphoto2_camera_h" = xyes; then :
@@ -10713,6 +10721,71 @@ else
 fi
 
 
+    if test -n "$GPHOTO2_PORT_CFLAGS"; then :
+
+elif test -n "$PKG_CONFIG"; then :
+  GPHOTO2_PORT_CFLAGS=`$PKG_CONFIG --cflags libgphoto2_port 2>/dev/null`
+fi
+GPHOTO2_PORT_CFLAGS=${GPHOTO2_PORT_CFLAGS:-`gphoto2-port-config --cflags 2>/dev/null`}
+CPPFLAGS="$CPPFLAGS $GPHOTO2_PORT_CFLAGS"
+if test -n "$GPHOTO2_PORT_LIBS"; then :
+
+elif test -n "$PKG_CONFIG"; then :
+  GPHOTO2_PORT_LIBS=`$PKG_CONFIG --libs libgphoto2_port 2>/dev/null`
+fi
+GPHOTO2_PORT_LIBS=${GPHOTO2_PORT_LIBS:-`gphoto2-port-config --libs 2>/dev/null`}
+GPHOTO2_PORT_LIBS=${GPHOTO2_PORT_LIBS:-"-lgphoto2_port"}
+    ac_fn_c_check_header_mongrel "$LINENO" "gphoto2-port.h" "ac_cv_header_gphoto2_port_h" "$ac_includes_default"
+if test "x$ac_cv_header_gphoto2_port_h" = xyes; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gp_port_info_list_new in -lgphoto2_port" >&5
+$as_echo_n "checking for gp_port_info_list_new in -lgphoto2_port... " >&6; }
+if ${ac_cv_lib_gphoto2_port_gp_port_info_list_new+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lgphoto2_port $GPHOTO2_PORT_LIBS $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gp_port_info_list_new ();
+int
+main ()
+{
+return gp_port_info_list_new ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_gphoto2_port_gp_port_info_list_new=yes
+else
+  ac_cv_lib_gphoto2_port_gp_port_info_list_new=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gphoto2_port_gp_port_info_list_new" >&5
+$as_echo "$ac_cv_lib_gphoto2_port_gp_port_info_list_new" >&6; }
+if test "x$ac_cv_lib_gphoto2_port_gp_port_info_list_new" = xyes; then :
+
+$as_echo "#define HAVE_GPHOTO2_PORT 1" >>confdefs.h
+
+else
+  GPHOTO2_PORT_LIBS=""; GPHOTO2_PORT_CFLAGS=""
+fi
+
+else
+  GPHOTO2_PORT_LIBS=""; GPHOTO2_PORT_CFLAGS=""
+fi
+
+
     CPPFLAGS="$ac_save_CPPFLAGS"
 fi
 if test "$ac_cv_lib_gphoto2_gp_camera_new" != "yes"; then :
@@ -10723,6 +10796,14 @@ if test "$ac_cv_lib_gphoto2_gp_camera_new" != "yes"; then :
 This is an error since --with-gphoto was requested." "$LINENO" 5 ;;
 esac
 fi
+if test "$ac_cv_lib_gphoto2_port_gp_port_info_list_new" != "yes"; then :
+  case "x$with_gphoto" in
+  x)   as_fn_append wine_notices "|libgphoto2_port ${notice_platform}development files not found, digital cameras won't be auto-detected." ;;
+  xno) ;;
+  *)   as_fn_error $? "libgphoto2_port ${notice_platform}development files not found, digital cameras won't be auto-detected.
+This is an error since --with-gphoto was requested." "$LINENO" 5 ;;
+esac
+fi
 
 
 if test "$ac_cv_header_resolv_h" = "yes"
@@ -16356,7 +16437,7 @@ wine_fn_config_makefile documentation enable_documentation
 wine_fn_config_makefile fonts enable_fonts install-lib
 wine_fn_config_makefile include enable_include install-dev
 wine_fn_config_makefile libs/port enable_libs_port
-wine_fn_config_makefile libs/wine enable_libs_wine install-dev,install-lib
+wine_fn_config_makefile libs/wine enable_libs_wine
 wine_fn_config_makefile libs/wpp enable_libs_wpp
 wine_fn_config_makefile loader enable_loader install-lib,manpage
 wine_fn_config_program aspnet_regiis enable_aspnet_regiis install
diff --git a/configure.ac b/configure.ac
index 97da660710e..c6b04eab051 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1400,18 +1400,28 @@ if test "x$with_gphoto" != "xno"
 then
     ac_save_CPPFLAGS="$CPPFLAGS"
     WINE_PACKAGE_FLAGS(GPHOTO2,[libgphoto2],[-lgphoto2],
-                       [(gphoto2-config --cflags || gphoto2-port-config --cflags)],
-                       [(gphoto2-config --libs || gphoto2-port-config --libs)])
+                       [gphoto2-config --cflags], [gphoto2-config --libs])
     AC_CHECK_HEADER(gphoto2-camera.h,
                     [AC_CHECK_LIB(gphoto2,gp_camera_new,
-                                  [AC_DEFINE(HAVE_GPHOTO2, 1, [Define if we have libgphoto2 development environment])],
+                                  [AC_DEFINE(HAVE_GPHOTO2, 1, [Define if we have the libgphoto2 development environment])],
                                   [GPHOTO2_LIBS=""; GPHOTO2_CFLAGS=""],
                                   [$GPHOTO2_LIBS])],
                     [GPHOTO2_LIBS=""; GPHOTO2_CFLAGS=""])
+    WINE_PACKAGE_FLAGS(GPHOTO2_PORT,[libgphoto2_port],[-lgphoto2_port],
+                       [gphoto2-port-config --cflags],
+                       [gphoto2-port-config --libs])
+    AC_CHECK_HEADER(gphoto2-port.h,
+                    [AC_CHECK_LIB(gphoto2_port,gp_port_info_list_new,
+                                  [AC_DEFINE(HAVE_GPHOTO2_PORT, 1, [Define if we have the libgphoto2_port development environment])],
+                                  [GPHOTO2_PORT_LIBS=""; GPHOTO2_PORT_CFLAGS=""],
+                                  [$GPHOTO2_PORT_LIBS])],
+                    [GPHOTO2_PORT_LIBS=""; GPHOTO2_PORT_CFLAGS=""])
     CPPFLAGS="$ac_save_CPPFLAGS"
 fi
 WINE_NOTICE_WITH(gphoto,[test "$ac_cv_lib_gphoto2_gp_camera_new" != "yes"],
                  [libgphoto2 ${notice_platform}development files not found, digital cameras won't be supported.])
+WINE_NOTICE_WITH(gphoto,[test "$ac_cv_lib_gphoto2_port_gp_port_info_list_new" != "yes"],
+                 [libgphoto2_port ${notice_platform}development files not found, digital cameras won't be auto-detected.])
 
 
 dnl **** Check for resolver library ***
@@ -3162,7 +3172,7 @@ WINE_CONFIG_MAKEFILE([documentation])
 WINE_CONFIG_MAKEFILE([fonts],,[install-lib])
 WINE_CONFIG_MAKEFILE([include],,[install-dev])
 WINE_CONFIG_MAKEFILE([libs/port])
-WINE_CONFIG_MAKEFILE([libs/wine],,[install-dev,install-lib])
+WINE_CONFIG_MAKEFILE([libs/wine])
 WINE_CONFIG_MAKEFILE([libs/wpp])
 WINE_CONFIG_MAKEFILE([loader],,[install-lib,manpage])
 WINE_CONFIG_PROGRAM(aspnet_regiis,,[install])
diff --git a/dlls/gphoto2.ds/Makefile.in b/dlls/gphoto2.ds/Makefile.in
index e77de86d28f..1e716fc4df9 100644
--- a/dlls/gphoto2.ds/Makefile.in
+++ b/dlls/gphoto2.ds/Makefile.in
@@ -1,7 +1,7 @@
 MODULE    = gphoto2.ds
 IMPORTS   = comctl32 user32 gdi32 advapi32
-EXTRALIBS = @GPHOTO2_LIBS@
-EXTRAINCL = @GPHOTO2_CFLAGS@
+EXTRALIBS = @GPHOTO2_LIBS@ @GPHOTO2_PORT_LIBS@
+EXTRAINCL = @GPHOTO2_CFLAGS@ @GPHOTO2_PORT_CFLAGS@
 
 C_SRCS = \
 	capability.c \
diff --git a/dlls/gphoto2.ds/gphoto2_main.c b/dlls/gphoto2.ds/gphoto2_main.c
index 005fece0f70..bb8104e1c1b 100644
--- a/dlls/gphoto2.ds/gphoto2_main.c
+++ b/dlls/gphoto2.ds/gphoto2_main.c
@@ -578,7 +578,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
     return TRUE;
 }
 
-#ifdef HAVE_GPHOTO2
+#if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
 static TW_UINT16 GPHOTO2_GetIdentity( pTW_IDENTITY, pTW_IDENTITY);
 static TW_UINT16 GPHOTO2_OpenDS( pTW_IDENTITY, pTW_IDENTITY);
 #endif
@@ -597,7 +597,7 @@ static TW_UINT16 GPHOTO2_SourceControlHandler (
 	    switch (MSG)
 	    {
 		case MSG_CLOSEDS:
-#ifdef HAVE_GPHOTO2
+#if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
 		     if (activeDS.camera) {
 			gp_camera_free (activeDS.camera);
 			activeDS.camera = NULL;
@@ -605,14 +605,14 @@ static TW_UINT16 GPHOTO2_SourceControlHandler (
 #endif
 		     break;
 		case MSG_GET:
-#ifdef HAVE_GPHOTO2
+#if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
 		     twRC = GPHOTO2_GetIdentity(pOrigin,(pTW_IDENTITY)pData);
 #else
 		     twRC = TWRC_FAILURE;
 #endif
 		     break;
 		case MSG_OPENDS:
-#ifdef HAVE_GPHOTO2
+#if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
 		     twRC = GPHOTO2_OpenDS(pOrigin,(pTW_IDENTITY)pData);
 #else
 		     twRC = TWRC_FAILURE;
@@ -1024,7 +1024,7 @@ DS_Entry ( pTW_IDENTITY pOrigin,
     return twRC;
 }
 
-#ifdef HAVE_GPHOTO2
+#if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
 static GPPortInfoList *port_list;
 static int curcamera;
 static CameraList *detected_cameras;
diff --git a/include/config.h.in b/include/config.h.in
index 0a1d78a581b..91bfdcbc699 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -236,9 +236,12 @@
 /* Define to 1 if you have the `getuid' function. */
 #undef HAVE_GETUID
 
-/* Define if we have libgphoto2 development environment */
+/* Define if we have the libgphoto2 development environment */
 #undef HAVE_GPHOTO2
 
+/* Define if we have the libgphoto2_port development environment */
+#undef HAVE_GPHOTO2_PORT
+
 /* Define to 1 if you have the <grp.h> header file. */
 #undef HAVE_GRP_H
 
-- 
GitLab