#
# Makefile for the linux ncp-filesystem routines.
#

VERSION = 2.0.6

# If you are using kerneld to autoload ncp support,
# uncomment this (kerneld is in linux since about 1.3.57):
#KERNELD = -DHAVE_KERNELD

# If your system is ELF, either also do a 'make install', or append the util/
# directory where the dynamic library resides to the environment
# variable LD_LIBRARY_PATH
HAVE_ELF=$(shell file `which gcc`|grep ELF >/dev/null && echo -n yes )


TOPDIR = $(shell pwd)
BINDIR = /usr/local/bin
SBINDIR = /sbin
INTERM_BINDIR = $(TOPDIR)/bin
SUBDIRS = util ipx-1.0 man

KVERSION=$(shell uname -r | cut -b1-3)

ifeq ($(KVERSION),1.2)
SUBDIRS += kernel-1.2/src
INCLUDES = -I$(TOPDIR)/kernel-1.2
endif

export INCLUDES BINDIR INTERM_BINDIR SBINDIR KERNELD VERSION HAVE_ELF

all:
	for i in $(SUBDIRS); do make -C $$i all; done
	@if [ "$(HAVE_ELF)" = yes ] ;\
	then \
	echo ; echo ; echo ;\
	echo Please add \'`pwd`/util\' to the environment ; \
	echo variable LD_LIBRARY_PATH by executing ; \
	echo ;\
	echo export LD_LIBRARY_PATH=\"\$$LD_LIBRARY_PATH:`pwd`/util\" ; \
	echo ;\
	echo or do a \'make install\'. ;\
	echo ;\
	fi	

dep:
	for i in $(SUBDIRS); do	make -C $$i dep; done

install:
	for i in $(SUBDIRS); do	make -C $$i install; done

clean:
	rm -f `find . -type f -name '*.o' -print`
	rm -f `find . -type f -name '*~' -print`
	rm -f `find . -type f -name '.depend' -print`
	rm -f `find . -type f -name '*.out' -print`
	for i in $(SUBDIRS); do	make -C $$i clean; done

mrproper: clean
	rm -fr $(INTERM_BINDIR)/* ncpfs.tgz
	make -C util mrproper
	make -C ipxdump mrproper

modules: ncpfs.o

SRCPATH=$(shell pwd)
SRCDIR=$(shell basename $(SRCPATH))
DISTFILE=$(SRCDIR).tgz

dist: mrproper
	(cd ..; \
         tar cvf - $(SRCDIR) | \
            gzip -9 > $(DISTFILE); \
         mv $(DISTFILE) $(SRCDIR))
	make dep
	make all

tgz: mrproper
	(cd ..; \
         tar cvf - $(SRCDIR) | \
            gzip -9 > $(DISTFILE); \
         mv $(DISTFILE) $(SRCDIR))

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
