TOP	= ..
HDRS	= $(TOP)/crash.h $(TOP)/def.h

include	$(TOP)/Rules.make

ifeq ($(XFS),yes)
CSRCS		= table.c clean_mount.c mount.c pagebuf.c clean_vfs.c vfs.c\
		  clean_inode.c inode.c clean_log.c log.c clean_trans.c \
		  trans.c clean_ag.c
CSRCS_pagebuf	= clean_pagebuf.c
GENHEAD		= flags_inode.h flags_mount.h flags_pagebuf.h flags_trans.h
else
CSRCS		= noxfs.c
endif

OBJS		= $(CSRCS:.c=.o)
OBJS_pagebuf	= $(CSRCS_pagebuf:.c=.o)
INCLUDE		= -I$(TOP) -I$(INCDIR)
ifeq ($(ARCH),i386)
INCLUDE		+= -I$(KERNELDIR)/include/asm/mach-default
endif
CFLAGS		= $(CDEBUG) $(INCLUDE)
XFSINCDIR	= -I$(KERNELDIR)/fs/xfs -I$(KERNELDIR)/fs
PB_INCDIR	= -I$(KERNELDIR)/fs/xfs/pagebuf
TARGET		= libxfs.a
DEPFILE		= Makefile.dep

ifeq ($(wildcard $(KERNELDIR)/fs/xfs/pagebuf/avl.h),$(KERNELDIR)/fs/xfs/pagebuf/avl.h)
PB_INCLUDES	+= -DHAVE_AVL
endif

ifeq ($(wildcard $(KERNELDIR)/fs/xfs/pagebuf/page_buf_internal.h),$(KERNELDIR)/fs/xfs/pagebuf/page_buf_internal.h)
PB_INCLUDES	+= -DHAVE_PB_INTERNAL
endif

all:	$(TARGET)

$(TARGET): $(GENHEAD) $(OBJS) $(OBJS_pagebuf)
	$(AR) cr $(TARGET) $(OBJS) $(OBJS_pagebuf)

$(OBJS) %(OBJS_pagebuf): $(HDRS)

$(OBJS): %.o: %.c
	$(CC) -c $(CFLAGS) $(XFSINCDIR) $*.c

$(OBJS_pagebuf): %.o: %.c
	$(CC) -c $(CFLAGS) $(PB_INCDIR) $(PB_INCLUDES) $*.c

flags_inode.h:
	$(TOP)/script/bitname $(KERNELDIR)/fs/xfs/xfs_inode.h > $@

flags_mount.h:
	$(TOP)/script/bitname mflags:XFS_MOUNT_ $(KERNELDIR)/fs/xfs/xfs_mount.h > $@

flags_trans.h:
	$(TOP)/script/bitname $(KERNELDIR)/fs/xfs/xfs_trans.h > $@

ifeq ($(XFSDIR),old)
flags_pagebuf.h:
	$(TOP)/script/bitname $(KERNELDIR)/include/linux/page_buf.h > $@
else
flags_pagebuf.h:
	$(TOP)/script/bitname $(KERNELDIR)/fs/xfs/pagebuf/page_buf.h > $@
endif

clean:
	/bin/rm -f $(TARGET) $(DEPFILE) *.o *~ *.swp $(GENHEAD)

depend:
	makedepend -f- $(INCLUDE) $(XFSINCDIR) $(PB_INCDIR) $(CSRCS) > $(DEPFILE)

ifeq ($(wildcard $(DEPFILE)),$(DEPFILE))
include $(DEPFILE)
endif
