CFLAGS=	-g 
#CFLAGS=	-O2
LDFLAGS=
#MODFLAGS=	-Wall -D__KERNEL__ -DMODULE -DDEBUG -O2 -DCONFIG_MODVERSIONS
MODFLAGS=	-Wall -D__KERNEL__ -O2 #-DCONFIG_MODVERSIONS
COFLAGS= -l
KVERSION=$(shell uname -r)

SRCS= dump.c dir.c inode.c ntgrep.c ntcat.c ntdir.c ntdump.c ntfstools.c \
	ntfs_fs.c super.c ntchange.c config.h ntfs.h Makefile
ALLFILES= $(SRCS) README PROBLEMS ntfs.lpm doc \
	COPYING INSTALL
PROGRAMS= ntdir ntcat ntdump ntgrep ntchange

all:	ntfs.o

ntdump:	dump.o inode.o ntdump.o ntfstools.o dir.o super.o

ntgrep: dump.o inode.o ntgrep.o ntfstools.o dir.o super.o

ntdir:	dir.o inode.o ntdir.o ntfstools.o dump.o super.o

ntcat:	dir.o inode.o ntcat.o ntfstools.o dump.o super.o

ntchange:	ntchange.o dir.o inode.o ntfstools.o super.o

ntfs_fs.o:	ntfs_fs.c
	$(CC) $(MODFLAGS) -c ntfs_fs.c

ntfs.o:	ntfs_fs.o inode.o dir.o super.o
	$(LD) -r $^ -o ntfs.o

ntfs2.o: ntfs_fs.c inode.o dir.o super.o
	$(CC) $(MODFLAGS) -DSECOND -c ntfs_fs.c -o ntfs_fs2.o 
	$(LD) -r ntfs_fs2.o inode.o dir.o super.o -o ntfs2.o

clean:
	rm -f core *.o $(PROGRAMS)

install:	all
	install -d /usr/local/bin /lib/modules/$(KVERSION)/fs
	install $(PROGRAMS) /usr/local/bin
	install ntfs.o /lib/modules/$(KVERSION)/fs
	depmod -a

co:	$(SRCS)

ci:	$(SRCS)
	ci $(SRCS)

mount:	ntfs.o
	sync
	/sbin/insmod ntfs.o
	mount -t ntfs -oumask=0 /dev/hdb7 mp

umount:	
	umount mp
	/sbin/rmmod ntfs

ntfs.tar.gz: $(ALLFILES)
	rm -f ntfs.tar.gz
	tar -C .. -cf ntfs.tar $(ALLFILES:%=ntfs/%)
	gzip -9 ntfs.tar

# Who knows to generate a portable makedepend output?
dir.o: dir.c ntfs.h config.h
dump.o: dump.c config.h ntfs.h
inode.o: inode.c ntfs.h config.h
ntcat.o: ntcat.c ntfs.h config.h
ntdir.o: ntdir.c ntfs.h config.h
ntdump.o: ntdump.c ntfs.h config.h
ntfs_fs.o: ntfs_fs.c config.h ntfs.h
ntfstools.o: ntfstools.c config.h ntfs.h
ntgrep.o: ntgrep.c ntfs.h config.h
stack.o: stack.c
super.o: super.c ntfs.h config.h
