#
# Special Makefile for building kernel module.  Invoked both by user and
# by kernel build process.
#
here = src/kernel/linux-2.6
top = ../../..

absolute_src_dir = /home/dhildebz/src/pnfspvfs2/pvfs2/pvfs2-1.3.0-multiple-layout_driver
absolute_build_dir= /home/dhildebz/src/pnfspvfs2/pvfs2/pvfs2-1.3.0-multiple-layout_driver
src_relative_top = .
ifeq "/" "$(shell echo ${src_relative_top} | cut -c 1)"
# not actually relative (as if someone called /tmp/foo/configure
#    instead of ../foo/configure)
    relative_src_dir = ${src_relative_top}
else
    relative_src_dir = $(top)/${src_relative_top}
endif

QUIET_COMPILE = 1
ifdef V
    QUIET_COMPILE = 0
endif

ifeq ($(QUIET_COMPILE),1)
  # say a one-line description of the action, do not echo the command
  Q=@echo
  E=@
else
  # do not say the short Q lines, but do echo the entire command
  Q=@echo >/dev/null
  E=
endif

csrc = \
    pvfs2-utils.c \
    devpvfs2-req.c \
    pvfs2-cache.c \
    dcache.c \
    file.c \
    inode.c \
    dir.c \
    namei.c \
    super.c \
    pvfs2-mod.c \
    pvfs2-bufmap.c \
    symlink.c \
    xattr.c \
    acl.c \
    xattr_default.c \
    waitqueue.c
hsrc = \
    pvfs2-kernel.h \
    pvfs2-dev-proto.h \
    pvfs2-bufmap.h \
    upcall.h \
	downcall.h \
	pvfs2-pnfs.h


objs = $(csrc:.c=.o)
othergen = pvfs2-pnfs.o pvfs2-pnfs.ko pvfs2.mod.c pvfs2.mod.o
othergendir = .tmp_versions  # around 2.6.6 this is generated locally
cmds = $(patsubst %,.%.cmd,$(objs) $(othergen))

KDIR    := /home/dhildebz/src/pnfspvfs2/kernels/cvs/pnfs-foufoune/
ifneq ($(KERNELRELEASE),)

EXTRA_CFLAGS = \
    -I$(KDIR)/include/linux \
    -I$(KDIR)/arch/um/os-Linux/include \
    -I$(KDIR)/arch/um/kernel/skas \
    -I$(KDIR)/arch/um/kernel/skas/include \
    -I$(KDIR)/arch/um/include \
    -I$(absolute_src_dir)/ \
    -I$(absolute_build_dir)/ \
    -I$(absolute_src_dir)/include \
    -I$(absolute_src_dir)/src/io/dev \
    -I$(absolute_src_dir)/src/io/bmi \
    -I$(absolute_src_dir)/src/common/quickhash

EXTRA_CFLAGS += 
EXTRA_CFLAGS += -DPVFS2_VERSION="\"1.3.0\""

# uncomment the following line for kernel specific
# debugging output or features
#EXTRA_CFLAGS += -DPVFS2_KERNEL_DEBUG

obj-m += pvfs2-pnfs.o
pvfs2-pnfs-objs := $(objs)

else

#KDIR	:= /lib/modules/$(shell uname -r)/build
#KDIR	:= /usr/src/linux-$(shell uname -r)
PWD	:= $(shell pwd)

default: links
	$(E)$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

# link to real source directory if out-of-tree build
links:
	$(E)for i in $(csrc) $(hsrc); do \
	    if [[ ! -f $$i  &&  ! -L $$i ]] ; then \
		ln -s $(relative_src_dir)/$(here)/$$i ;\
	    fi ;\
	done

clean:
	$(E)for i in $(csrc) $(hsrc); do \
	    if [[ -L $$i ]] ; then \
		rm -f $$i ;\
	    fi ;\
	done
	$(E)rm -f $(objs) $(othergen) $(cmds)
	$(E)rm -rf $(othergendir)

endif

