Blob Blame History Raw
commit e4a01aa9f45cd2420bed7a9131a6d0044c182a05
Author: Nils Philippsen <nils@redhat.com>
Date:   Wed Jun 17 13:10:47 2009 +0200

    patch: pkgconfig
    
    Squashed commit of the following:
    
    commit 52ef5f47ccc0128c78ab3ad38ac7b7918dd7ac88
    Author: Nils Philippsen <nils@redhat.com>
    Date:   Wed Jun 17 13:09:51 2009 +0200
    
        make sane-config multilib-aware on Linux
    
    commit 7787640dd567b93dd0a458fd5fb662bb7b85ff36
    Author: Nils Philippsen <nils@redhat.com>
    Date:   Fri Jun 5 12:55:39 2009 +0200
    
        use pkg-config in sane-config

diff --git a/configure.in b/configure.in
index 126edbf..7199c44 100644
--- a/configure.in
+++ b/configure.in
@@ -161,6 +161,8 @@ AC_CHECK_HEADER(resmgr.h,[
 		rsm_open_device,[
 			AC_DEFINE(HAVE_RESMGR,1,[define if you have the resmgr library])
 			LIBS="$LIBS -lresmgr"
+            RESMGR_LIB="-lresmgr"
+            AC_SUBST(RESMGR_LIB)
 		]
 	)
 ])
@@ -673,6 +675,7 @@ AC_CONFIG_FILES([Makefile lib/Makefile sanei/Makefile frontend/Makefile \
   japi/Makefile backend/Makefile include/Makefile doc/Makefile \
   po/Makefile testsuite/Makefile tools/Makefile doc/doxygen-sanei.conf])
 AC_CONFIG_FILES([tools/sane-config], [chmod a+x tools/sane-config])
+AC_CONFIG_FILES([tools/sane-backends.pc])
 AC_OUTPUT
 
 dnl ***********************************************************************
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 0932e45..bd6dd9d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -7,6 +7,10 @@
 AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include \
  -I$(top_srcdir)/include
 
+SUFFIXES = .pc.in .pc
+
+pkgconfigdir = ${libdir}/pkgconfig
+
 bin_PROGRAMS = sane-find-scanner gamma4scanimage
 noinst_PROGRAMS = sane-desc umax_pp
 
@@ -26,6 +30,12 @@ noinst_SCRIPTS = $(HOTPLUG)
 BUILT_SOURCES = $(HOTPLUG_DIR)
 CLEANFILES = $(bin_SCRIPTS) $(dist_noinst_SCRIPTS)
 
+pkgconfig_PROGRAMS = sane-backends.pc
+sane_backends_pc_SOURCES = sane-backends.pc.in
+.pc.in.pc:
+	cd $(top_builddir) \
+		&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
 EXTRA_DIST = check-po.awk libtool-get-dll-ext mustek600iin-off.c \
 	     RenSaneDlls.cmd README xerox
 
@@ -72,5 +82,7 @@ hal/libsane.fdi: $(wildcard ${top_srcdir}/doc/descriptions/*.desc) $(wildcard ${
 	@./sane-desc -m hal -s ${top_srcdir}/doc/descriptions:${top_srcdir}/doc/descriptions-external \
 	   -d 0 > $@
 
+sane-backends.pc:	$(top_builddir)/config.status
+
 clean-local:
 	rm -f $(HOTPLUG)
diff --git a/tools/sane-backends.pc.in b/tools/sane-backends.pc.in
new file mode 100644
index 0000000..fb64e3b
--- /dev/null
+++ b/tools/sane-backends.pc.in
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+pc_libs=@RESMGR_LIB@ @DL_LIBS@ @IEEE1284_LIBS@ @PTHREAD_LIBS@ @JPEG_LIBS@ @USB_LIBS@
+pc_reqs=libusb
+
+Name: SANE Backends
+Description: Backends for SANE, the universal scanner interface
+Version: @VERSION@
+Requires: ${pc_reqs}
+Libs: -L${libdir} -lsane ${pc_libs}
+Cflags:
diff --git a/tools/sane-config.in b/tools/sane-config.in
index 85add1a..c0450d4 100644
--- a/tools/sane-config.in
+++ b/tools/sane-config.in
@@ -18,7 +18,7 @@ pkglibdir="@pkglibdir@"
 includedir="@includedir@"
 mandir="@mandir@"
 infodir="@infodir@"
-libdir="@libdir@"
+#libdir=
 localstatedir="@localstatedir@"
 sysconfdir="@sysconfdir@"
 datarootdir="@datarootdir@"
@@ -32,6 +32,30 @@ srcdir="@srcdir@"
 top_srcdir="@top_srcdir@"
 cflags=
 
+pkgconfig_package=sane-backends
+use_pkgconfig=0
+if test -x "@bindir@/pkg-config" && "@bindir@/pkg-config" --exists "$pkgconfig_package"; then
+    use_pkgconfig=1
+else
+    libdir=
+    if kernel="`uname -s 2>/dev/null`"; then
+        case "$kernel" in
+            Linux)
+            if hw="`uname -i 2>/dev/null`"; then
+                case "$hw" in
+                    *64)
+                    libdir="@exec_prefix@/lib64"
+                    ;;
+                esac
+            fi
+            ;;
+        esac
+    fi
+    if test "x$libdir" = "x"; then
+        libdir="@exec_prefix@/lib"
+    fi
+fi
+
 usage ()
 {
   echo "Usage: "  1>&2
@@ -85,26 +109,38 @@ if test $# -gt 0; then
       ;;
     --ldflags)
 
-      if test -z "$LINKER_RPATH"; then
-        echo "-L${libdir}"
+      if test "x$use_pkgconfig" = "x0"; then
+        if test -z "$LINKER_RPATH"; then
+          echo "-L${libdir}"
+        else
+          echo "-L${libdir} ${LINKER_RPATH}${libdir}"
+        fi
       else
-        echo "-L${libdir} ${LINKER_RPATH}${libdir}"
+        pkg-config --libs-only-L "$pkgconfig_package"
       fi
       ;;
     --libs)
-      echo "-lsane ${LIBS}"
+      if test "x$use_pkgconfig" = "x0"; then
+        echo "-lsane ${LIBS}"
+      else
+        pkg-config --libs "$pkgconfig_package"
+      fi
       ;;
     --cflags)
-      unique_cflags=
-      if test "${includedir}" != "/usr/include"; then
-        unique_cflags="${unique_cflags} -I${includedir}"
-      fi
-      for i in $cflags; do
-        if test "${i}" != "-I${includedir}"; then
-          unique_cflags="${unique_cflags} $i"
+      if test "x$use_pkgconfig" = "x0"; then
+        unique_cflags=
+        if test "${includedir}" != "/usr/include"; then
+          unique_cflags="${unique_cflags} -I${includedir}"
         fi
-      done
-      echo ${unique_cflags}
+        for i in $cflags; do
+          if test "${i}" != "-I${includedir}"; then
+            unique_cflags="${unique_cflags} $i"
+          fi
+        done
+        echo ${unique_cflags}
+      else
+        pkg-config --cflags "$pkgconfig_package"
+      fi
       ;;
     --prefix)
       echo ${prefix}