Install udev helpers in customizable directory

Add a udevhelperdir variable and evaluate it both for installation
and for udev rules generation. Fixes [1].

[1] http://bugzilla.kernel.org/show_bug.cgi?id=12471

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
diff --git a/Makefile b/Makefile
index e1d7c85..7fab1e7 100644
--- a/Makefile
+++ b/Makefile
@@ -61,13 +61,13 @@
 
 KERNEL_DIR = /lib/modules/${shell uname -r}/build
 
-# override this to make udev look in a different location for it's config files
+# override this to make pcmciautils look in a different location for its files
 prefix =
 exec_prefix =	${prefix}
 etcdir =	${prefix}/etc
 sbindir =	${exec_prefix}/sbin
 mandir =	${prefix}/usr/share/man
-srcdir = .
+udevdir =	${prefix}/lib/udev/
 
 INSTALL = /usr/bin/install -c
 INSTALL_PROGRAM = ${INSTALL}
@@ -79,7 +79,11 @@
 hotplugdir =	${etcdir}/hotplug
 
 # place to put our udev rules to
-udevrulesdir = 	${etcdir}/udev/rules.d
+udevrulesdir = 	${udevdir}/rules.d
+
+# place to put our udev helper binaries (pcmcia-socket-startup, pcmcia-check-broken-cis) to
+udevhelperdir =   ${udevdir}
+# udevhelperdir = ${sbindir}
 
 # place where PCMICIA config is put to
 pcmciaconfdir =	${etcdir}/pcmcia
@@ -247,7 +251,7 @@
 	$(QUIET) $(STRIPCMD) $@
 
 udevrules:
-	cat $(UDEV_RULES) > $(UDEV_RULES_FILE)
+	cat $(UDEV_RULES) | sed -e "s#__UDEVHELPERDIR__/#${udevhelperdir}#g" > $(UDEV_RULES_FILE)
 
 clean:
 	-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
@@ -272,22 +276,23 @@
 
 uninstall-socket-hotplug:
 	- rm -f $(DESTDIR)$(hotplugdir)/pcmcia_socket.agent $(DESTDIR)$(hotplugdir)/pcmcia_socket.rc
+
 install-socket-tools:
-	$(INSTALL_PROGRAM) -D $(PCMCIA_SOCKET_STARTUP) $(DESTDIR)$(sbindir)/$(PCMCIA_SOCKET_STARTUP)
+	$(INSTALL_PROGRAM) -D $(PCMCIA_SOCKET_STARTUP) $(DESTDIR)$(udevhelperdir)/$(PCMCIA_SOCKET_STARTUP)
 
 uninstall-socket-tools:
-	- rm -f $(DESTDIR)$(sbindir)/$(PCMCIA_SOCKET_STARTUP)
+	- rm -f $(DESTDIR)$(udevhelperdir)/$(PCMCIA_SOCKET_STARTUP)
 
 install-tools:
 	$(INSTALL) -d $(DESTDIR)$(sbindir)
 	$(INSTALL_PROGRAM) -D $(PCCARDCTL) $(DESTDIR)$(sbindir)/$(PCCARDCTL)
-	$(INSTALL_PROGRAM) -D $(PCMCIA_CHECK_BROKEN_CIS) $(DESTDIR)$(sbindir)/$(PCMCIA_CHECK_BROKEN_CIS)
 	$(SYMLINK) $(PCCARDCTL) $(DESTDIR)$(sbindir)/$(LSPCMCIA)
+	$(INSTALL_PROGRAM) -D $(PCMCIA_CHECK_BROKEN_CIS) $(DESTDIR)$(udevhelperdir)/$(PCMCIA_CHECK_BROKEN_CIS)
 
 uninstall-tools:
 	- rm -f $(DESTDIR)$(sbindir)/$(PCCARDCTL)
-	- rm -f $(DESTDIR)$(sbindir)/$(PCMCIA_CHECK_BROKEN_CIS)
 	- rm -f $(DESTDIR)$(sbindir)/$(LSPCMCIA)
+	- rm -f $(DESTDIR)$(udevhelperdir)/$(PCMCIA_CHECK_BROKEN_CIS)
 
 install-config:
 	$(INSTALL) -d $(DESTDIR)$(pcmciaconfdir)
diff --git a/udev/rules-base b/udev/rules-base
index 0227cef..f9c411f 100644
--- a/udev/rules-base
+++ b/udev/rules-base
@@ -4,7 +4,7 @@
 # instead of the manufactor, card or product ID. Then the
 # matching is done in userspace.
 SUBSYSTEM=="pcmcia", ENV{MODALIAS}=="?*", \
-		RUN+="/lib/udev/pcmcia-check-broken-cis"
+		RUN+="__UDEVHELPERDIR__/pcmcia-check-broken-cis"
 
 # However, the "weak" matching by func_id is only allowed _after_ modprobe
 # returns, so that "strong" matches have a higher priority.
diff --git a/udev/rules-nonstaticsocket b/udev/rules-nonstaticsocket
index 8b8e1c2..2d29864 100644
--- a/udev/rules-nonstaticsocket
+++ b/udev/rules-nonstaticsocket
@@ -2,4 +2,4 @@
 # if this is a PCMCIA socket which needs a resource database,
 # pcmcia-socket-startup sets it up
 SUBSYSTEM=="pcmcia_socket", \
-		RUN+="/lib/udev/pcmcia-socket-startup"
+		RUN+="__UDEVHELPERDIR__/pcmcia-socket-startup"