PACKAGE = rockplug
VERSION = 0.0.0

prefix      = @prefix@
sbindir     = @sbindir@
etcdir      = @etcdir@
vardir      = @vardir@
subsysdir   = @subsysdir@

CP          = cp
MKDIR       = mkdir
RM          = rm -f
CHMOD       = @CHMOD@

EXEC_ETC_FILES = \
 $(wildcard etc/rockplug/*.plug) \
 $(wildcard etc/rockplug/*.scan) \
 $(wildcard etc/rockplug/*.init) 

ETC_FILES = \
 etc/rockplug/functions

ETC_CONF_FILES = \
 etc/rockplug/conf/blacklist

SBIN_FILES = \
 sbin/rockplug \
 src/hwhex

CLEANFILES = \
 $(wildcard etc/rockplug/*~) \
 $(wildcard sbin/*~) \
 $(wildcard src/*~) \
 src/hwhex \
 $(wildcard *~)

DIST_FILES = \
 $(EXEC_ETC_FILES) \
 $(ETC_FILES) \
 etc/rockplug/functions.in \
 $(ETC_CONF_FILES) \
 sbin/rockplug \
 src/Makefile.in \
 src/hwhex.c \
 Makefile.in \
 configure

all:
	cd src; make

clean:
	test -z "$(CLEANFILES)" || $(RM) $(CLEANFILES)
	rm -f subs.sed

install: install-dirs install-etc install-sbin

install-etc:
	for i in $(EXEC_ETC_FILES); do \
		n="`basename $$i`"; \
		$(CP) $$i $(etcdir)/rockplug/$$n; \
		$(CHMOD) 0755 $(etcdir)/rockplug/$$n; \
	done
	for i in $(ETC_FILES); do \
		n="`basename $$i`"; \
		$(CP) $$i $(etcdir)/rockplug/$$n; \
		$(CHMOD) 0644 $(etcdir)/rockplug/$$n; \
	done
	for i in $(ETC_CONF_FILES); do \
		n="`basename $$i`"; \
		$(CP) $$i $(etcdir)/rockplug/conf/$$n; \
		$(CHMOD) 0644 $(etcdir)/rockplug/conf/$$n; \
	done

install-sbin:
	for i in $(SBIN_FILES); do \
		n="`basename $$i`"; \
		$(CP) $$i $(sbindir)/$$n; \
		$(CHMOD) 0755 $(sbindir)/$$n; \
	done

install-dirs:
	for i in pci usb ieee1394 net; do \
		$(MKDIR) -p $(subsysdir)/$$i; \
	done
	$(MKDIR) -p $(etcdir)/rockplug/conf
	$(MKDIR) -p $(etcdir)/rockplug/scripts

dist:
	distdir=$(PACKAGE)-$(VERSION); mkdir $$distdir; \
	list="$(DIST_FILES)"; for i in $$list; do \
	d="`dirname $$i`"; mkdir -p $$distdir/$$d; \
	cp $$i $$distdir/$$i; \
	done; \
	tar -cvf $(PACKAGE)-$(VERSION).tar $$distdir; \
	rm -rf $$distdir;
