ifndef MODULESDIR
MODULESDIR = ${ROOT}/lib/modules/$(shell uname -r)
endif

ifndef KERNEL_SOURCES
KERNEL_SOURCES = ${MODULESDIR}/build
endif

ifeq (${MODVERSIONS},yes)
MVER = -DMODVERSIONS -DEXPORT_SYMTAB
endif

ifndef DEBUG
DEBUG=0
endif

ALL_TARGETS := shfs.o

SEARCHDIRS := -I- -I. -I${KERNEL_SOURCES}/include -I/usr/src/linux/include/

CC     := gcc
CFLAGS  = -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -Wall ${SEARCHDIRS} -DMODULE ${MVER} -D__KERNEL__ -DLINUX -DDEBUG_LEVEL=${DEBUG}
LINKER    := ld
LDFLAGS    = -m elf_i386 -r
LOADLIBES := 

all: ${ALL_TARGETS}

%.o: %.c $(wildcard shfs*.h)
	${CC} ${CFLAGS} -c $< -o $@

shfs.o: ./dcache.o ./dir.o ./fcache.o ./file.o ./inode.o ./proc.o ./proto.o ./symlink.o
	${LINKER} ${LDFLAGS} -o $@ ${filter-out %.a %.so, $^} ${LOADLIBES}

tidy:
	@${RM} core ./dcache.o ./dir.o ./fcache.o ./file.o ./inode.o ./proc.o ./proto.o ./symlink.o

clean: tidy
	@${RM} shfs.o

install: shfs.o
	rm -f ${MODULESDIR}/kernel/fs/shfs/shfs.o
	install -m644 -b -D shfs.o ${MODULESDIR}/kernel/fs/shfs/shfs.o
	if [ -x /sbin/depmod -a "${ROOT}" == "/" ]; then /sbin/depmod -aq; fi

uninstall:
	rm -rf ${MODULESDIR}/kernel/fs/shfs
	if [ -x /sbin/depmod -a "${ROOT}" == "/" ]; then /sbin/depmod -aq; fi
	
.PHONY : all tidy clean install uninstall
