From bba1c1085fa678e856a3b1e482d68dcc81664d11 Mon Sep 17 00:00:00 2001
From: Pavel Herrman <morpheus.ibis@gmail.com>
Date: Sun, 10 Aug 2008 14:21:58 -0500
Subject: [PATCH] Allow drivers to be included/excluded at compile time

---
 THANKS                  |  1 +
 configure.ac            | 79 +++++++++++++++++++++++++++++++++++++++++
 libfprint/Makefile.am   | 56 +++++++++++++++++++++++++----
 libfprint/core.c        | 24 +++++++++++--
 libfprint/fp_internal.h | 18 ++++++++++
 libfprint/imgdev.c      |  6 ++++
 6 files changed, 176 insertions(+), 8 deletions(-)

diff --git a/THANKS b/THANKS
index 76c0817..8681271 100644
--- a/THANKS
+++ b/THANKS
@@ -6,3 +6,4 @@ Craig Watson (NIST)
 James Vasile (SFLC)
 Toby Howard (University of Manchester)
 Seemant Kulleen
+Pavel Herrman
diff --git a/configure.ac b/configure.ac
index 9f29771..d77340f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,6 +18,83 @@ AC_SUBST(lt_major)
 AC_SUBST(lt_revision)
 AC_SUBST(lt_age)
 
+all_drivers="upekts upektc upeksonly vcom5s uru4000 fdu2000 aes1610 aes2501 aes4000"
+
+require_imagemagick='no'
+require_aeslib='no'
+enable_upekts='no'
+enable_upektc='no'
+enable_upeksonly='no'
+enable_vcom5s='no'
+enable_uru4000='no'
+enable_fdu2000='no'
+enable_aes1610='no'
+enable_aes2501='no'
+enable_aes4000='no'
+
+AC_ARG_WITH([drivers],[AS_HELP_STRING([--with-drivers],
+	[List of drivers to enable])],
+	[drivers="$withval"],
+	[drivers="$all_drivers"])
+
+for driver in `echo ${drivers} | sed -e 's/,/ /g' -e 's/,$//g'`; do
+	case ${driver} in
+		upekts)
+			AC_DEFINE([ENABLE_UPEKTS], [], [Build UPEK TouchStrip driver])
+			enable_upekts="yes"
+		;;
+		upektc)
+			AC_DEFINE([ENABLE_UPEKTC], [], [Build UPEK TouchChip driver])
+			enable_upektc="yes"
+		;;
+		upeksonly)
+			AC_DEFINE([ENABLE_UPEKSONLY], [], [Build UPEK TouchStrip sensor-only driver])
+			enable_upeksonly="yes"
+		;;
+		uru4000)
+			AC_DEFINE([ENABLE_URU4000], [], [Build Digital Persona U.are.U 4000 driver])
+			enable_uru4000="yes"
+		;;
+		fdu2000)
+			AC_DEFINE([ENABLE_FDU2000], [], [Build Secugen FDU 2000 driver])
+			enable_fdu2000="yes"
+		;;
+		vcom5s)
+			AC_DEFINE([ENABLE_VCOM5S], [], [Build Veridicom 5thSense driver])
+			enable_vcom5s="yes"
+		;;
+		aes2501)
+			AC_DEFINE([ENABLE_AES2501], [], [Build AuthenTec AES2501 driver])
+			require_aeslib="yes"
+			enable_aes2501="yes"
+		;;
+		aes1610)
+			AC_DEFINE([ENABLE_AES1610], [], [Build AuthenTec AES1610 driver])
+			require_aeslib="yes"
+			enable_aes1610="yes"
+		;;
+		aes4000)
+			AC_DEFINE([ENABLE_AES4000], [], [Build AuthenTec AES4000 driver])
+			require_aeslib="yes"
+			require_imagemagick="yes"
+			enable_aes4000="yes"
+		;;
+	esac
+done
+
+AM_CONDITIONAL([ENABLE_UPEKTS], [test "$enable_upekts" != "no"])
+#AM_CONDITIONAL([ENABLE_UPEKTC], [test "$enable_upektc" != "no"])
+AM_CONDITIONAL([ENABLE_UPEKSONLY], [test "$enable_upeksonly" != "no"])
+AM_CONDITIONAL([ENABLE_VCOM5S], [test "$enable_vcom5s" != "no"])
+AM_CONDITIONAL([ENABLE_URU4000], [test "$enable_uru4000" != "no"])
+#AM_CONDITIONAL([ENABLE_FDU2000], [test "$enable_fdu2000" != "no"])
+#AM_CONDITIONAL([ENABLE_AES1610], [test "$enable_aes1610" != "no"])
+AM_CONDITIONAL([ENABLE_AES2501], [test "$enable_aes2501" != "no"])
+AM_CONDITIONAL([ENABLE_AES4000], [test "$enable_aes4000" != "no"])
+AM_CONDITIONAL([REQUIRE_IMAGEMAGICK], [test "$require_imagemagick" != "no"])
+AM_CONDITIONAL([REQUIRE_AESLIB], [test "$require_aeslib" != "no"])
+
+
 PKG_CHECK_MODULES(LIBUSB, [libusb-1.0 >= 0.9.1])
 AC_SUBST(LIBUSB_CFLAGS)
 AC_SUBST(LIBUSB_LIBS)
@@ -31,9 +108,11 @@ PKG_CHECK_MODULES(GLIB, "glib-2.0")
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
+if test "$require_imagemagick" != "no"; then
 PKG_CHECK_MODULES(IMAGEMAGICK, "ImageMagick")
 AC_SUBST(IMAGEMAGICK_CFLAGS)
 AC_SUBST(IMAGEMAGICK_LIBS)
+fi;
 
 # Examples build
 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
diff --git a/libfprint/Makefile.am b/libfprint/Makefile.am
index 468e020..9c53c89 100644
--- a/libfprint/Makefile.am
+++ b/libfprint/Makefile.am
@@ -10,8 +10,8 @@ AES4000_SRC = drivers/aes4000.c
 FDU2000_SRC = drivers/fdu2000.c
 VCOM5S_SRC = drivers/vcom5s.c
 
-DRIVER_SRC = $(UPEKTS_SRC) $(AES4000_SRC) $(AES2501_SRC) $(URU4000_SRC) $(VCOM5S_SRC) $(UPEKSONLY_SRC)
-#DRIVER_SRC = $(AES1610_SRC) $(UPEKTC_SRC) $(FDU2000_SRC)
+DRIVER_SRC = ""
+OTHER_SRC = ""
 
 NBIS_SRC = \
 	nbis/include/bozorth.h \
@@ -50,9 +50,54 @@ NBIS_SRC = \
 	nbis/mindtct/sort.c \
 	nbis/mindtct/util.c
 
-libfprint_la_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(IMAGEMAGICK_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS)
+libfprint_la_CFLAGS = -fvisibility=hidden -I$(srcdir)/nbis/include $(LIBUSB_CFLAGS) $(GLIB_CFLAGS) $(CRYPTO_CFLAGS) $(AM_CFLAGS)
 libfprint_la_LDFLAGS = -version-info @lt_major@:@lt_revision@:@lt_age@
-libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(IMAGEMAGICK_LIBS) $(CRYPTO_LIBS)
+libfprint_la_LIBADD = -lm $(LIBUSB_LIBS) $(GLIB_LIBS) $(CRYPTO_LIBS)
+
+if ENABLE_UPEKTS
+DRIVER_SRC += $(UPEKTS_SRC)
+endif
+
+if ENABLE_UPEKSONLY
+DRIVER_SRC += $(UPEKSONLY_SRC)
+endif
+
+#if ENABLE_UPEKTC
+#DRIVER_SRC += $(UPEKTC_SRC)
+#endif
+
+if ENABLE_URU4000
+DRIVER_SRC += $(URU4000_SRC)
+endif
+
+if ENABLE_VCOM5S
+DRIVER_SRC += $(VCOM5S_SRC)
+endif
+
+#if ENABLE_FDU2000
+#DRIVER_SRC += $(FDU2000_SRC)
+#endif
+
+#if ENABLE_AES1610
+#DRIVER_SRC += $(AES1610_SRC)
+#endif
+
+if ENABLE_AES2501
+DRIVER_SRC += $(AES2501_SRC)
+endif
+
+if ENABLE_AES4000
+DRIVER_SRC += $(AES4000_SRC)
+endif
+
+if REQUIRE_IMAGEMAGICK
+libfprint_la_CFLAGS += $(IMAGEMAGICK_CFLAGS) -DREQUIRE_IMAGEMAGICK
+libfprint_la_LIBADD += $(IMAGEMAGICK_LIBS)
+endif
+
+if REQUIRE_AESLIB
+OTHER_SRC += aeslib.c aeslib.h
+endif
 
 libfprint_la_SOURCES =	\
 	fp_internal.h	\
@@ -64,9 +109,8 @@ libfprint_la_SOURCES =	\
 	imgdev.c	\
 	poll.c		\
 	sync.c		\
-	aeslib.c	\
-	aeslib.h	\
 	$(DRIVER_SRC)	\
+	$(OTHER_SRC)	\
 	$(NBIS_SRC)
 
 pkginclude_HEADERS = fprint.h
diff --git a/libfprint/core.c b/libfprint/core.c
index 6cf2e38..7cfea43 100644
--- a/libfprint/core.c
+++ b/libfprint/core.c
@@ -327,18 +327,38 @@ static void register_driver(struct fp_driver *drv)
 }
 
 static struct fp_driver * const primitive_drivers[] = {
+#ifdef ENABLE_UPEKTS
 	&upekts_driver,
+#endif
 };
 
 static struct fp_img_driver * const img_drivers[] = {
+#ifdef ENABLE_AES4000
 	&aes4000_driver,
+#endif
+#ifdef ENABLE_AES2501
 	&aes2501_driver,
+#endif
+#ifdef ENABLE_URU4000
 	&uru4000_driver,
+#endif
+#ifdef ENABLE_VCOM5S
 	&vcom5s_driver,
+#endif
+#ifdef ENABLE_UPEKSONLY
 	&upeksonly_driver,
-	/* &aes1610_driver,
+#endif
+	/*
+#ifdef ENABLE_AES1610
+	&aes1610_driver,
+#endif
+#ifdef ENABLE_UPEKTC
 	&upektc_driver,
-	&fdu2000_driver, */
+#endif
+#ifdef ENABLE_FDU2000
+	&fdu2000_driver,
+#endif
+	*/
 };
 
 static void register_drivers(void)
diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h
index 027ac12..dde69cd 100644
--- a/libfprint/fp_internal.h
+++ b/libfprint/fp_internal.h
@@ -233,15 +233,33 @@ struct fp_img_driver {
 	void (*deactivate)(struct fp_img_dev *dev);
 };
 
+#ifdef ENABLE_UPEKTS
 extern struct fp_driver upekts_driver;
+#endif
+#ifdef ENABLE_UPEKTC
 extern struct fp_img_driver upektc_driver;
+#endif
+#ifdef ENABLE_UPEKSONLY
 extern struct fp_img_driver upeksonly_driver;
+#endif
+#ifdef ENABLE_URU4000
 extern struct fp_img_driver uru4000_driver;
+#endif
+#ifdef ENABLE_AES1610
 extern struct fp_img_driver aes1610_driver;
+#endif
+#ifdef ENABLE_AES2501
 extern struct fp_img_driver aes2501_driver;
+#endif
+#ifdef ENABLE_AES4000
 extern struct fp_img_driver aes4000_driver;
+#endif
+#ifdef ENABLE_FDU2000
 extern struct fp_img_driver fdu2000_driver;
+#endif
+#ifdef ENABLE_VCOM5S
 extern struct fp_img_driver vcom5s_driver;
+#endif
 
 extern libusb_context *fpi_usb_ctx;
 extern GSList *opened_devices;
diff --git a/libfprint/imgdev.c b/libfprint/imgdev.c
index 8bddd5c..e133058 100644
--- a/libfprint/imgdev.c
+++ b/libfprint/imgdev.c
@@ -20,7 +20,9 @@
 #include <errno.h>
 
 #include <glib.h>
+#ifdef REQUIRE_IMAGEMAGICK
 #include <magick/ImageMagick.h>
+#endif
 
 #include "fp_internal.h"
 
@@ -87,6 +89,7 @@ static int dev_change_state(struct fp_img_dev *imgdev,
 	return imgdrv->change_state(imgdev, state);
 }
 
+#ifdef REQUIRE_IMAGEMAGICK
 static struct fp_img *im_resize(struct fp_img *img, unsigned int factor)
 {
 	Image *mimg;
@@ -129,6 +132,7 @@ static struct fp_img *im_resize(struct fp_img *img, unsigned int factor)
 
 	return newimg;
 }
+#endif
 
 /* check image properties and resize it if necessary. potentially returns a new
  * image after freeing the old one. */
@@ -157,6 +161,7 @@ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img)
 		return -EINVAL;
 	}
 
+#ifdef REQUIRE_IMAGEMAGICK
 	if (imgdrv->enlarge_factor > 1) {
 		/* FIXME: enlarge_factor should not exist! instead, MINDTCT should
 		 * actually look at the value of the pixels-per-mm parameter and
@@ -166,6 +171,7 @@ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img)
 		fp_img_free(img);
 		*_img = tmp;
 	}
+#endif
 	return 0;
 }