# $Id: Makefile,v 1.9 2001/06/12 00:00:50 stevewilliams Exp $

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	\
		fxload	\
		debian


NAME=hotplug

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

RELEASE_DIR =	$(NAME)-$(REV)

default:	distrib

# This rule simply makes a distribution tarball. It collects the files
# from various distribution subdirectories.
distrib:
	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)
	cp -r $(DISTRIB_DIRS) $(DISTRIB_FILES) $(RELEASE_DIR)
	tar czv --exclude CVS --exclude .cvsignore \
		--exclude '.*.swp' --exclude '.#*' --exclude '*~' \
		-f $(RELEASE_DIR).tar.gz $(RELEASE_DIR)
	rm -rf $(RELEASE_DIR)

all:
	make -C fxload all

clean:
	rm -f $(NAME)-*.tar.gz Log *~
	make -C fxload clean

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
	make -C fxload prefix=$(prefix) install

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