#SYSSRC= path-to-src/xnu/bsd 

DEFS= -D_KERNEL -DKERNEL -DKERNEL_PRIVATE -DDIAGNOSTIC -DUSE_SELECT \
      -DMACH_USER -DMACH_USER_API -DMACH_KERNEL -DNFS_NOSERVER \
      -DRPCCLNT_DEBUG
#-DRPCDEVVERBOSE 

OPTS= -static -fno-common -finline -fno-keep-inline-functions \
       -force_cpusubtype_ALL -msoft-float -mlong-branch -fno-builtin

CFLAGS=-I. -Infs -Infs4client $(OPTS) $(DEFS) \
       -I/System/Library/Frameworks/Kernel.framework/Headers/ -I$(SYSSRC) \
       -Wall  -g

OBJS= nfs4client/nfs4_vfsops.o nfs4client/nfs4_vnops.o \
      nfs4client/nfs4_vfs_subs.o nfs4client/nfs4_vn_subs.o \
      nfs4client/nfs4_subs.o nfs4client/nfs4m_glue.o \
      rpc/rpc_dev.o nfs4client/nfs4_glue.o \
      rpc/rpcclnt.o nfs/nfs_vnops.o nfs/nfs_socket.o \
      nfs4client/nfs4_module.o nfs/nfs_bio.o nfs/nfs_subs.o \
      nfs/nfs_vfsops.o nfs/nfs_lock.o nfs/nfs_superglue.o \
      nfs/nfs_node.o nfs4client/nfs4_idmap.o nfs4client/nfs4_syscall.o


ifndef SYSSRC
all:
	echo && echo "ERROR: you must set the environment variable \"SYSSRC\" to the xnu/bsd directory of the darwin source."
else
all: $(OBJS) idmap
	ld -r -o NFSv4.kext/Contents/MacOS/NFSv4 $(OBJS)
endif

install:
	cp nfsv4client nfsv4client.kext/Contents/MacOS

idmap:
	gcc -I. -Infs -Infs4client -I$(SYSSRC) idmapd.c -o idmapd

nfs4d:
	gcc userland/nfs4d.c -o nfs4d


clean:
	@rm -f */*.o *~ */*~ NFSv4.kext/Contents/MacOS/NFSv4 cscope.out idmapd

