--- tools/Makefile.in.old	2010-05-31 07:18:31.000000000 -0400
+++ tools/Makefile.in	2010-12-13 13:15:22.000000000 -0500
@@ -60,17 +60,23 @@
 ifeq ("@KLIBC@", "no")
 	ifeq ("@STATIC_LINK@", "no")
 		LDFLAGS += -rdynamic
+		MYLIBOBJ=$(top_builddir)/lib/libdmraid.so
 	else
 		LDFLAGS += -static
+		MYLIBOBJ=$(top_builddir)/lib/libdmraid.a
+		DMRAIDLIBS += \
+			$(DEVMAPPEREVENT_LIBS) \
+			$(DEVMAPPER_LIBS) \
+			$(DL_LIBS)
 	endif
 endif
 
 .PHONY: install_dmraid_tools
 
-dmraid: $(OBJECTS) $(top_builddir)/lib/libdmraid.a
+dmraid: $(OBJECTS) $(MYLIBOBJ)
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) -L$(top_builddir)/lib $(DMRAIDLIBS) $(LIBS)
 
-dmevent_tool: $(OBJECTS2) $(top_builddir)/lib/libdmraid.a
+dmevent_tool: $(OBJECTS2) $(MYLIBOBJ)
 	$(CC) -o $@ $(OBJECTS2) $(INCLUDES) $(LDFLAGS) -L$(top_builddir)/lib \
 		$(DMEVENTTOOLLIBS) $(DMRAIDLIBS) $(LIBS)
 
--- lib/Makefile.in.old	2010-10-27 07:31:46.000000000 -0400
+++ lib/Makefile.in	2010-12-13 13:04:16.000000000 -0500
@@ -60,11 +60,11 @@
 USRLIB_RELPATH = $(shell echo $(abspath $(usrlibdir) $(libdir)) | \
   $(AWK) -f $(top_srcdir)/tools/relpath.awk)
 
-TARGETS = $(LIB_STATIC)
+TARGETS = $(LIB_STATIC) $(LIB_SHARED) $(LIB_EVENTS_SHARED)
 
 ifeq ("@KLIBC@", "no")
 	ifeq ("@STATIC_LINK@", "no")
-		TARGETS += $(LIB_SHARED) $(LIB_EVENTS_SHARED)
+		TARGETS = $(LIB_SHARED) $(LIB_EVENTS_SHARED)
 	endif
 endif
 
--- configure.in	2010-05-31 07:18:30.000000000 -0400
+++ configure.in.new	2010-12-07 13:30:40.000000000 -0500
@@ -155,6 +155,15 @@
     Default is dynamic linking]),
   [STATIC_LINK=$enableval], [STATIC_LINK=no])
 
+if test "x$STATIC_LINK" != "xno"; then
+  if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+        AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+  fi
+  PKG_CONFIG="${PKG_CONFIG} --static"
+  ac_cv_env_PKG_CONFIG_set=set
+fi
+PKG_PROG_PKG_CONFIG([0.2])
+
 dnl Enables shared libdmraid
 AC_ARG_ENABLE(shared_lib,
   AC_HELP_STRING([--enable-shared_lib], [Use this to generate shared
@@ -248,23 +257,31 @@
 	AC_HELP_STRING([--with-devmapper-prefix=PFX],
 		[Where is devmapper library installed]),
 	[DEVMAPPER_LIBS="-L$withval/lib"
-	 DEVMAPPER_CFLAGS="-I$withval/include"],
+	 DEVMAPPER_CFLAGS="-I$withval/include"
+	 dmprefix=$withval],
 	[DEVMAPPER_LIBS=
-	 DEVMAPPER_CFLAGS=])
-save_LDFLAGS=$LDFLAGS
-save_CPPFLAGS=$CPPFLAGS
-LDFLAGS="$LDFLAGS $DEVMAPPER_LIBS"
-CPPFLAGS="$CPPFLAGS $DEVMAPPER_CFLAGS"
-AC_CHECK_LIB(devmapper-event, dm_event_handler_create,
-	[DEVMAPPEREVENT_LIBS="$DEVMAPPER_LIBS -ldevmapper-event"],
-	[AC_MSG_ERROR([device-mapper-event library is either missing or is too old and badly linked])])
-AC_CHECK_LIB(devmapper, dm_task_set_name,
-	[DEVMAPPER_LIBS="$DEVMAPPER_LIBS -ldevmapper"],
-	[AC_MSG_ERROR([device-mapper library is missing])])
-AC_CHECK_HEADERS(libdevmapper.h libdevmapper-event.h,,
-	[AC_MSG_ERROR([Missing headers device-mapper headers])])
-CPPFLAGS=$save_CPPFLAGS
-LDFLAGS=$save_LDFLAGS
+	 DEVMAPPER_CFLAGS=
+	 dmprefix=no])
+if test "x$dmprefix" = xno ; then
+	PKG_CHECK_MODULES([DEVMAPPER],[devmapper],
+		[PKG_CHECK_MODULES([DEVMAPPEREVENT],[devmapper-event])
+		])
+else
+	save_LDFLAGS=$LDFLAGS
+	save_CPPFLAGS=$CPPFLAGS
+	LDFLAGS="$LDFLAGS $DEVMAPPER_LIBS"
+	CPPFLAGS="$CPPFLAGS $DEVMAPPER_CFLAGS"
+	AC_CHECK_LIB(devmapper-event, dm_event_handler_create,
+		[DEVMAPPEREVENT_LIBS="$DEVMAPPER_LIBS -ldevmapper-event"],
+		[AC_MSG_ERROR([device-mapper-event library is either missing or is too old and badly linked])])
+	AC_CHECK_LIB(devmapper, dm_task_set_name,
+		[DEVMAPPER_LIBS="$DEVMAPPER_LIBS -ldevmapper"],
+		[AC_MSG_ERROR([device-mapper library is missing])])
+	AC_CHECK_HEADERS(libdevmapper.h libdevmapper-event.h,,
+		[AC_MSG_ERROR([Missing headers device-mapper headers])])
+	CPPFLAGS=$save_CPPFLAGS
+	LDFLAGS=$save_LDFLAGS
+fi
 
 VERSION=$srcdir/tools/VERSION
 DMRAID_LIB_MAJOR=$(cut -d. -f1 $VERSION)