# Makefile

# configurable values specified from command line
KSRC =
KBIN =

# environments
ORIG_KSRC = /lib/modules/`uname -r`/source
ORIG_KBIN = /lib/modules/`uname -r`/build

SUBDIRS = module src 
CLEANUPS = $(PRJNAME)*.tar.bz2 *~ cscope.out

TARGETS = $(SUBDIRS) LICENSE Makefile README ChangeLog script docs
TEST_TARGETS = 
RM_TARGETS =

PRJNAME = kstrax
VERSION = `date +%Y%m%d`

ifeq (,$(KSRC))
KSRC = $(ORIG_KSRC)
KBIN = $(ORIG_KBIN)
endif

.PHONY:	all dist distclean clean help

all:
	@( for dir in $(SUBDIRS) ; do \
		( cd $$dir ; \
		[ -f Makefile ] && make all ; \
		cd .. ); \
	done )

dist: distclean
	@mkdir $(PRJNAME)-$(VERSION)
	@cp -a $(TARGETS) $(PRJNAME)-$(VERSION)
	@(cd $(PRJNAME)-$(VERSION); \
	  rm -rf `find ./ -name CVS -a -type d`;\
	  find ./ -name *~ | xargs rm -f;\
	  rm -rf $(RM_TARGETS))
	tar cjvf $(PRJNAME)-$(VERSION).tar.bz2 $(PRJNAME)-$(VERSION)
	@rm -rf $(PRJNAME)-$(VERSION)

distclean:
	@( for dir in $(SUBDIRS) ; do \
		( cd $$dir ; \
		[ -f Makefile ] && make distclean ; \
		cd .. ); \
	done )
	rm -rf $(CLEANUPS)

clean:
	@( for dir in $(SUBDIRS) ; do \
		( cd $$dir ; \
		[ -f Makefile ] && make clean ; \
		cd .. ); \
	done )

install:
	@( for dir in $(SUBDIRS) ; do \
		( cd $$dir ; \
		[ -f Makefile ] && make install ; \
		cd ..); \
	done )

uninstall:
	@( for dir in $(SUBDIRS) ; do \
		( cd $$dir ; \
		[ -f Makefile ] && make uninstall ; \
		cd ..); \
	done )


help:
	@echo "Building targets:"
	@echo "  all (default) - build all"
	@echo
	@echo "Cleaning targets:"
	@echo "  clean        - remove most generated files but keep the config"
	@echo "  distclean    - remove all generated files + config files"
	@echo 
	@echo "Other targets:"
	@echo "  install      - install all binaries"
	@echo "  uninstall    - uninstall all binaries"
	@echo "  dist         - generate a package"
	@echo 
