From 107042f46a78e38d10e42f33c1765281337caf18 Mon Sep 17 00:00:00 2001
From: Vasily Khoruzhick <anarsoul@gmail.com>
Date: Tue, 14 Aug 2012 16:49:54 +0300
Subject: [PATCH 2/2] Fix fprint-list-udev-rules crosscompiling issue

Build fprint-list-udev-rules using host compiler, as we need to
run it on host, not on target

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 Makefile.am                        |  2 +-
 configure.ac                       |  7 ++-
 libfprint/Makefile.am              | 11 -----
 libfprint/fprint-list-udev-rules.c | 91 --------------------------------------
 util/Makefile.am                   | 12 +++++
 util/fprint-list-udev-rules.c      | 91 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 110 insertions(+), 104 deletions(-)
 delete mode 100644 libfprint/fprint-list-udev-rules.c
 create mode 100644 util/Makefile.am
 create mode 100644 util/fprint-list-udev-rules.c

diff --git a/Makefile.am b/Makefile.am
index aff8410..8ad0e6c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I m4
 EXTRA_DIST = THANKS TODO HACKING libfprint.pc.in
 DISTCLEANFILES = ChangeLog libfprint.pc
 
-SUBDIRS = libfprint doc
+SUBDIRS = libfprint doc util
 
 if BUILD_EXAMPLES
 SUBDIRS += examples
diff --git a/configure.ac b/configure.ac
index 1d57e4e..8ae0e11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,11 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 AC_PREREQ([2.50])
 AC_PROG_CC
+if test x"$cross_compiling" = xyes; then
+	AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
+else
+	CC_FOR_BUILD="$CC"
+fi
 AC_PROG_LIBTOOL
 AC_C_INLINE
 AM_PROG_CC_C_O
@@ -285,6 +290,6 @@ else
 	AC_MSG_NOTICE([   aeslib helper functions disabled])
 fi
 
-AC_CONFIG_FILES([libfprint.pc] [Makefile] [libfprint/Makefile] [examples/Makefile] [doc/Makefile])
+AC_CONFIG_FILES([libfprint.pc] [Makefile] [libfprint/Makefile] [examples/Makefile] [doc/Makefile] [util/Makefile])
 AC_OUTPUT
 
diff --git a/libfprint/Makefile.am b/libfprint/Makefile.am
index 7953526..26ae830 100644
--- a/libfprint/Makefile.am
+++ b/libfprint/Makefile.am
@@ -1,6 +1,4 @@
 lib_LTLIBRARIES = libfprint.la
-noinst_PROGRAMS = fprint-list-udev-rules
-MOSTLYCLEANFILES = $(udev_rules_DATA)
 
 UPEKE2_SRC = drivers/upeke2.c
 UPEKTS_SRC = drivers/upekts.c
@@ -74,15 +72,6 @@ libfprint_la_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLA
 libfprint_la_LDFLAGS = -version-info @lt_major@:@lt_revision@:@lt_age@
 libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(CRYPTO_LIBS)
 
-fprint_list_udev_rules_SOURCES = fprint-list-udev-rules.c
-fprint_list_udev_rules_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(IMAGEMAGICK_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS)
-fprint_list_udev_rules_LDADD = $(builddir)/libfprint.la
-
-udev_rules_DATA = 60-fprint-autosuspend.rules
-
-$(udev_rules_DATA): fprint-list-udev-rules
-	$(builddir)/fprint-list-udev-rules > $@
-
 if ENABLE_UPEKE2
 DRIVER_SRC += $(UPEKE2_SRC)
 endif
diff --git a/libfprint/fprint-list-udev-rules.c b/libfprint/fprint-list-udev-rules.c
deleted file mode 100644
index 182ee10..0000000
--- a/libfprint/fprint-list-udev-rules.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2009 Red Hat <mjg@redhat.com> 
- * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
- * Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <config.h>
-#include <stdio.h>
-
-#include "fp_internal.h"
-
-static const struct usb_id whitelist_id_table[] = {
-    { .vendor = 0x08ff, .product = 0x2810 },
-    { 0, 0, 0, },
-};
-
-static const struct usb_id blacklist_id_table[] = {
-    { .vendor = 0x0483, .product = 0x2016 },
-    { 0, 0, 0 },
-};
-
-struct fp_driver whitelist = {
-    .id_table = whitelist_id_table,
-};
-
-GHashTable *printed = NULL;
-
-static void print_driver (struct fp_driver *driver)
-{
-    int i, j, blacklist;
-
-    for (i = 0; driver->id_table[i].vendor != 0; i++) {
-        char *key;
-
-	blacklist = 0;
-	for (j = 0; blacklist_id_table[j].vendor != 0; j++) {
-	    if (driver->id_table[i].vendor == blacklist_id_table[j].vendor &&
-		driver->id_table[j].product == blacklist_id_table[j].product) {
-		blacklist = 1;
-		break;
-	    }
-	}
-	if (blacklist)
-	    continue;
-
-	key = g_strdup_printf ("%04x:%04x", driver->id_table[i].vendor, driver->id_table[i].product);
-
-	if (g_hash_table_lookup (printed, key) != NULL) {
-	    g_free (key);
-	    continue;
-	}
-
-	g_hash_table_insert (printed, key, GINT_TO_POINTER (1));
-
-	printf ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ATTRS{dev}==\"*\", ATTR{power/control}=\"auto\"\n", driver->id_table[i].vendor, driver->id_table[i].product);
-    }
-}
-
-int main (int argc, char **argv)
-{
-    struct fp_driver **list;
-    guint i;
-
-    list = fprint_get_drivers ();
-
-    printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
-    for (i = 0; list[i] != NULL; i++) {
-	print_driver (list[i]);
-    }
-
-    print_driver (&whitelist);
-
-    g_hash_table_destroy (printed);
-
-    return 0;
-}
diff --git a/util/Makefile.am b/util/Makefile.am
new file mode 100644
index 0000000..90331e1
--- /dev/null
+++ b/util/Makefile.am
@@ -0,0 +1,12 @@
+# CC = @CC_FOR_BUILD@
+noinst_PROGRAMS = fprint-list-udev-rules
+MOSTLYCLEANFILES = $(udev_rules_DATA)
+
+fprint_list_udev_rules_SOURCES = fprint-list-udev-rules.c
+fprint_list_udev_rules_CFLAGS = -fvisibility=hidden -I$(top_srcdir)/libfprint -I$(top_srcdir)/libfprint/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(IMAGEMAGICK_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS)
+fprint_list_udev_rules_LDADD = $(top_builddir)/libfprint/libfprint.la
+
+udev_rules_DATA = 60-fprint-autosuspend.rules
+
+$(udev_rules_DATA): fprint-list-udev-rules
+	$(builddir)/fprint-list-udev-rules > $@
diff --git a/util/fprint-list-udev-rules.c b/util/fprint-list-udev-rules.c
new file mode 100644
index 0000000..182ee10
--- /dev/null
+++ b/util/fprint-list-udev-rules.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2009 Red Hat <mjg@redhat.com> 
+ * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
+ * Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+#include <stdio.h>
+
+#include "fp_internal.h"
+
+static const struct usb_id whitelist_id_table[] = {
+    { .vendor = 0x08ff, .product = 0x2810 },
+    { 0, 0, 0, },
+};
+
+static const struct usb_id blacklist_id_table[] = {
+    { .vendor = 0x0483, .product = 0x2016 },
+    { 0, 0, 0 },
+};
+
+struct fp_driver whitelist = {
+    .id_table = whitelist_id_table,
+};
+
+GHashTable *printed = NULL;
+
+static void print_driver (struct fp_driver *driver)
+{
+    int i, j, blacklist;
+
+    for (i = 0; driver->id_table[i].vendor != 0; i++) {
+        char *key;
+
+	blacklist = 0;
+	for (j = 0; blacklist_id_table[j].vendor != 0; j++) {
+	    if (driver->id_table[i].vendor == blacklist_id_table[j].vendor &&
+		driver->id_table[j].product == blacklist_id_table[j].product) {
+		blacklist = 1;
+		break;
+	    }
+	}
+	if (blacklist)
+	    continue;
+
+	key = g_strdup_printf ("%04x:%04x", driver->id_table[i].vendor, driver->id_table[i].product);
+
+	if (g_hash_table_lookup (printed, key) != NULL) {
+	    g_free (key);
+	    continue;
+	}
+
+	g_hash_table_insert (printed, key, GINT_TO_POINTER (1));
+
+	printf ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ATTRS{dev}==\"*\", ATTR{power/control}=\"auto\"\n", driver->id_table[i].vendor, driver->id_table[i].product);
+    }
+}
+
+int main (int argc, char **argv)
+{
+    struct fp_driver **list;
+    guint i;
+
+    list = fprint_get_drivers ();
+
+    printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+    for (i = 0; list[i] != NULL; i++) {
+	print_driver (list[i]);
+    }
+
+    print_driver (&whitelist);
+
+    g_hash_table_destroy (printed);
+
+    return 0;
+}
-- 
1.7.11.4

