#CFLAGS=	-g 
CFLAGS=	-O2 -fno-strength-reduce
#LDFLAGS= -static
#MODFLAGS=	-Wall -D__KERNEL__ -DMODULE -DDEBUG -O2
MODFLAGS=	-Wall -D__KERNEL__ -DMODULE -O2
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 config.h ntfs.h Makefile
ALLFILES= $(SRCS) README PROBLEMS ChangeLog ntfs.lpm doc \
	COPYING INSTALL INSTALL.old
PROGRAMS= ntdir ntcat ntdump ntgrep 

all:	$(PROGRAMS) 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

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 $^ /usr/src/linux/lib/lib.a -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)/misc
	depmod -a

co:	$(SRCS)

ci:	$(SRCS)
	ci $(SRCS)

mount:	ntfs.o
	sync
	insmod ntfs.o
	mount -t ntfs /dev/hdb7 mp

umount:	
	umount mp
	rmmod ntfs

ntfs.tar.gz: $(ALLFILES)
	rm -f ntfs.tar.gz
	tar cf ntfs.tar $(ALLFILES)
	gzip 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
