# $Id: Makefile,v 1.11 2002/03/26 22:15:06 kroah Exp $

NAME=hotplug

REV=$(shell date "+%Y_%m_%d"| awk '{print $$1}')

# System locations
prefix =
exec_prefix = ${prefix}
etcdir = ${prefix}/etc
sbindir = ${exec_prefix}/sbin
mandir = ${prefix}/usr/share/man
srcdir = .

INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA  = ${INSTALL} -m 644
INSTALL_SCRIPT = ${INSTALL_PROGRAM}

TOPDIR=/
DIRS= 	/sbin \
	/etc/hotplug \
	/etc/init.d/ \
	/var/run/usb \
	/usr/share/man/man8

# New style, /etc/hotplug
# Driven by modutils output, and (for USB) exceptions
DISTRIB_FILES =		\
		README	\
		ChangeLog	\
		hotplug.8	\
		Makefile	\
		mkinstalldirs	\
		hotplug.spec

DISTRIB_DIRS =		\
		etc	\
		sbin	\
		debian


RELEASE_DIR =		$(NAME)-$(REV)

default:	distrib

# This rule simply makes a distribution tarball. It collects the files
# from various distribution subdirectories.

FILES_CORE = $(shell find . \( -not -name '.' \) -print | grep -v CVS | grep -v "\.tar\.gz" | grep -v "\/\." )

distrib: clean
	@chmod +x sbin/hotplug
	@chmod +x etc/rc.d/init.d/hotplug
	@chmod +x etc/hotplug/*.agent etc/hotplug/*.rc
	@-rm -rf $(RELEASE_DIR)
	@mkdir $(RELEASE_DIR)
	@for file in $(FILES_CORE); do				\
		if test -d $$file; then				\
			mkdir $(RELEASE_DIR)/$$file;		\
		else						\
			cp -p $$file $(RELEASE_DIR)/$$file;	\
		fi;						\
	done
	@tar -c $(RELEASE_DIR) | gzip -9 > $(RELEASE_DIR).tar.gz
	@rm -rf $(RELEASE_DIR)
	@echo "Built $(RELEASE_DIR).tar.gz"

all:

clean:
	@-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
	| xargs rm -f

install: installdirs
	for i in sbin/*;do [[ -d $$i ]] && continue;install -m755 $$i $(sbindir)/;done
	for i in etc/hotplug/*;do [[ $$i == *CVS* ]] && continue;cp -a -r $$i $(etcdir)/hotplug;done
	for i in etc/rc.d/init.d/*;do [[ $$i == *CVS* ]] && continue;cp -a -r $$i $(etcdir)/rc.d/init.d/;done
	$(INSTALL_DATA) hotplug.8  $(mandir)/man8/hotplug.8

installdirs: mkinstalldirs
	$(srcdir)/mkinstalldirs $(sbindir) $(etcdir)/hotplug $(etcdir)/rc.d/init.d $(mandir)/man8 $(prefix)/var/run/usb
	chmod 0700 $(prefix)/var/run/usb
