From 61d5ae2b7b86ccc1a62c66f3e3e31e7d18b2d538 Mon Sep 17 00:00:00 2001
From: Frank Mori Hess <fmhess@speakeasy.net>
Date: Wed, 1 Aug 2007 19:10:52 +0000
Subject: [PATCH] Fixed "make uninstall".  "make distcheck" passes now.

---
 comedi/Makefile.am |  7 ++++++-
 m4/as-linux.m4     | 26 ++++++++++++++------------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/comedi/Makefile.am b/comedi/Makefile.am
index f7f79419..b9dfc695 100644
--- a/comedi/Makefile.am
+++ b/comedi/Makefile.am
@@ -3,6 +3,8 @@ SUBDIRS = . kcomedilib drivers
 
 CLEANFILES = Modules.symvers Module.symvers
 
+COMEDI_MOD_DIR = "comedi"
+
 if CONFIG_KBUILD
 module_PROGRAMS =
 all-local:
@@ -24,16 +26,19 @@ all-local:
 		-I@abs_top_srcdir@/include $(RTAI_CFLAGS) $(RTLINUX_CFLAGS)" modules
 install-data-local:
 	$(MAKE) -I@abs_builddir@ -C $(LINUX_DIR) M=@abs_builddir@ CC="$(LINUX_CC) -I@abs_top_builddir@/ \
-		-I@abs_top_srcdir@/include $(RTAI_CFLAGS) $(RTLINUX_CFLAGS)" INSTALL_MOD_DIR="comedi" \
+		-I@abs_top_srcdir@/include $(RTAI_CFLAGS) $(RTLINUX_CFLAGS)" INSTALL_MOD_DIR=$(COMEDI_MOD_DIR) \
 		INSTALL_MOD_PATH="$(prefix)" modules_install
 clean-local:
 	$(MAKE) -I@abs_builddir@ -C $(LINUX_DIR) M=@abs_builddir@ CC="$(LINUX_CC) -I@abs_top_builddir@/ \
 		-I@abs_top_srcdir@/include $(RTAI_CFLAGS) $(RTLINUX_CFLAGS)" clean
+uninstall-local:
+	find $(prefix)/$(LINUX_MODLIB)/$(COMEDI_MOD_DIR) -name '*.ko' -exec $(RM) {} \;
 else
 module_PROGRAMS = comedi.ko
 all-local:
 install-data-local:
 clean-local:
+uninstall-local:
 endif
 
 EXTRA_DIST = \
diff --git a/m4/as-linux.m4 b/m4/as-linux.m4
index 03f71302..524589c4 100644
--- a/m4/as-linux.m4
+++ b/m4/as-linux.m4
@@ -58,7 +58,7 @@ dnl modulesdir
 dnl   base install path for kernel modules
 dnl modulesdeveldir
 dnl   base install path for kernel module development files
-dnl 
+dnl
 dnl End of search list.
 
 dnl main entry point
@@ -68,25 +68,25 @@ AC_DEFUN([AS_LINUX],
 	dnl check if user supplied a uname -r, and if not use the running one
 	AS_LINUX_KERNEL_RELEASE()
 	dnl check if user supplied a uname -m, and if not use the running one
-	AS_LINUX_MACHINE() 	 
+	AS_LINUX_MACHINE()
 	dnl check if the user supplied an rpm target arch
 	dnl override the LINUX_MACHINE value if he did
-	AS_LINUX_RPM_TARGET() 	 
-  	 
-	dnl find the kernel source tree for the given uname -r 	 
+	AS_LINUX_RPM_TARGET()
+
+	dnl find the kernel source tree for the given uname -r
 	AS_LINUX_DIR()
 	dnl check if user supplied an EXTRAVERSION, and if not get from uname -r
-	AS_LINUX_EXTRAVERSION($LINUX_KERNEL_RELEASE) 	 
+	AS_LINUX_EXTRAVERSION($LINUX_KERNEL_RELEASE)
 	dnl check if user supplied a config file; if not, guess a good one
-	AS_LINUX_CONFIG($LINUX_DIR, $LINUX_KERNEL_RELEASE, $LINUX_MACHINE) 	 
+	AS_LINUX_CONFIG($LINUX_DIR, $LINUX_KERNEL_RELEASE, $LINUX_MACHINE)
 	dnl check if we're building on pre-FC2 Red Hat/Fedora,
-	dnl and add some flags if we are 	 
-	AS_CHECK_REDHAT_PRE_FC2() 	 
+	dnl and add some flags if we are
+	AS_CHECK_REDHAT_PRE_FC2()
 	dnl check for where to install modules
 	AS_LINUX_MODULESDIR($LINUX_KERNEL_RELEASE)
 	dnl check for where to install module development files
 	AS_LINUX_MODULESDEVELDIR($LINUX_DIR)
-	dnl check for the MAJOR/MINOR version of Linux 	 
+	dnl check for the MAJOR/MINOR version of Linux
 	AS_LINUX_VERSION_MAJOR_MINOR($LINUX_DIR)
 
 	dnl now call the correct macro to get compiler flags
@@ -371,7 +371,7 @@ int code = RED_HAT_LINUX_KERNEL;
 	BIGMEM='0'
 	HUGEMEM='0'
 
-	dnl get variables from the currently running kernel as default 
+	dnl get variables from the currently running kernel as default
 	KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'`
 	KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'`
 	KERNEL_ARCH=`uname -m`
@@ -488,6 +488,7 @@ flags:
 	echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags
 	echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags
 	echo LINUX_AS=\"\$(AS)\" >>\$(obj)/flags
+	echo LINUX_MODLIB=\"\$(MODLIB)\" >>\$(obj)/flags
 EOF
 
 	echo ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
@@ -513,9 +514,10 @@ EOF
 	AC_SUBST(LINUX_MODULE_EXT)
 	AC_SUBST(LINUX_MODULE_STYLE)
 	AC_SUBST(LINUX_MODPOST)
+	AC_SUBST(LINUX_MODLIB)
 
 	AC_MSG_RESULT([$LINUX_CFLAGS])
-	
+
 	AC_PATH_PROG([LINUX_MODPOST], ["modpost"], ["no"], ["$LINUX_DIR/scripts:$LINUX_DIR/scripts/mod"])
 ])
 
-- 
2.26.2