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

all : spadfs mkspadfs spadfsck

spadfs :
	$(MAKE) -C $(KERNELDIR) M=`pwd`

CFLAGS := -D__NOT_FROM_SPAD -D__NOT_FROM_SPAD_TREE -Wall -fdollars-in-identifiers -O2 -g
#-fomit-frame-pointer
#CC := icc
#CFLAGS := -D__NOT_FROM_SPAD -D__NOT_FROM_SPAD_TREE -ipo

%.o : %.C
	$(CC) $(CFLAGS) -c -o $@ -x c $<

mkspadfs : UTILS/MKSPADFS/MKSPADFS.o UTILS/MKSPADFS/SFSAPAGE.o
	$(CC) $(CFLAGS) -o $@ $^

spadfsck : UTILS/SPAD-API.o UTILS/SPADFSCK/SCK.o UTILS/SPADFSCK/SCKALLOC.o UTILS/SPADFSCK/SCKAPAGE.o UTILS/SPADFSCK/SCKBUF.o UTILS/SPADFSCK/SCKCCT.o UTILS/SPADFSCK/SCKCRT.o UTILS/SPADFSCK/SCKDIR.o UTILS/SPADFSCK/SCKEA.o UTILS/SPADFSCK/SCKFBLK.o UTILS/SPADFSCK/SCKFILE.o UTILS/SPADFSCK/SCKFN.o UTILS/SPADFSCK/SCKFXFN.o UTILS/SPADFSCK/SCKHDLNK.o UTILS/SPADFSCK/SCKLOG.o UTILS/SPADFSCK/SCKRCV.o UTILS/SPADFSCK/SCKSUPER.o UTILS/SPADFSCK/SCKXL.o
	$(CC) $(CFLAGS) -o $@ $^

clean :
	-$(MAKE) -C $(KERNELDIR) M=$$PWD clean
	-rm -f *.o UTILS/*.o UTILS/*/*.o mkspadfs spadfsck Module.symvers modules.order
