#KDIR	:= /lib/modules/$(shell uname -r)/build
KDIR	:= /home/s0mbre/aWork/git/linux-2.6/linux-2.6.kevent-mainstream
PWD	:= $(shell pwd)
CC	:= gcc

ARCH ?= $(shell uname -m | sed -e 's/i.86/i386/')

CFLAGS	:= -I$(KDIR)/include -I$(PWD) -I$(PWD)/arch/$(ARCH) -W -Wall -g -O3 -fno-inline
LDFLAGS := -shared -rdynamic -lpthread

TARGETS	:= libntl.so ntl_test
LIB_OBJS := ntl.o ntl_kevent.o ntl_mutex.o ntl_sched.o arch/$(ARCH)/context.o

all: $(TARGETS)
	@echo "Compilation has been successfully finished."

libntl.so: $(LIB_OBJS)
	$(CC) $(LDFLAGS) -Wl,-soname,$@ -o $@ $(LIB_OBJS)

ntl.o: ntl.c ntl.h ntl_mutex.h list.h ntl_user.h ntl_kevent.h
	$(CC) $(CFLAGS) ntl.c -c -o $@

ntl_kevent.o: ntl_kevent.c ntl.h ntl_kevent.h ntl.h
	$(CC) $(CFLAGS) ntl_kevent.c -c -o $@

ntl_mutex.o: ntl_mutex.c ntl_mutex.h
	$(CC) $(CFLAGS) ntl_mutex.c -c -o $@

ntl_sched.o: ntl_sched.c ntl_sched.h ntl_mutex.h ntl.h
	$(CC) $(CFLAGS) ntl_sched.c -c -o $@

ntl_test: ntl_test.c ntl_user.h
	$(CC) $(CFLAGS) ntl_test.c -o $@ -L. -lntl

arch/$(ARCH)/context.o: arch/$(ARCH)/context.c arch/$(ARCH)/context.h arch/$(ARCH)/lock.h ntl.h
	$(CC) $(CFLAGS) arch/$(ARCH)/context.c -c -o $@

clean:
	@rm -f *.o *~ $(TARGETS) arch/$(ARCH)/*.o arch/$(ARCH)/*~
