#
# Makefile for the Linux kernel device drivers.
#
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (not a .c file).
#
# Note 2! The CFLAGS definitions are now in the main makefile.

#KERNELSRC := /usr/src/linux

ifeq ("$(KERNELSRC)","")
all:
	@echo 'set $$KERNELSRC!'
else
all: progs mods

mods:
	$(MAKE) modules -C $(KERNELSRC) SUBDIRS=$(shell pwd)/kernel

progs:
	$(MAKE) -C iscsid

install: kernel/iscsi_trgt.o kernel/file-io.o iscsid/ietd
	@install -v iscsid/ietd /usr/sbin/ietd
	if [ -d /etc/init.d ] ; then \
		install -v -m 755 initd /etc/init.d/iscsi-target; \
	fi
	@eval `sed -n '1,5s/^\([A-Z]*\) *= *\(.*\)$$/\1=\2/p' $(KERNELSRC)/Makefile`; \
	KERNELRELEASE=$$VERSION.$$PATCHLEVEL.$$SUBLEVEL$$EXTRAVERSION; \
	install -vD kernel/iscsi_trgt.o \
	$(INSTALL_MOD_PATH)/lib/modules/$$KERNELRELEASE/kernel/iscsi/iscsi_trgt.o; \
	install -vD kernel/file-io.o \
	$(INSTALL_MOD_PATH)/lib/modules/$$KERNELRELEASE/kernel/iscsi/fileio.o
	depmod -aq

realclean: clean
	find -name "*~" -o -name "cscope.*" | xargs rm -rf

endif

clean:
	find -name "*.o" -o -name "*.a" -o -name ".*.flags" | xargs rm -f
	rm -f iscsid/ietd
