obj-m += rts-cpu-isolator.o

ccflags-y := -std=gnu99 -Wno-declaration-after-statement


MODULENAME 	:= rts-cpu-isolator
KDIR		:= /lib/modules/$(shell uname -r)/build
KVER		:= $(shell uname -r)
PWD		:= $(shell pwd)

TARGET		:= rts-cpu-isolator.ko
INSTDIR		:= /lib/modules/$(KVER)/extra
SYMVERSDIR	:= /var/cache/$(MODULENAME)

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

install:
	#remove all old versions of the driver
	find $(INSTALL_MOD_PATH)/lib/modules/$(KVER) -name $(TARGET) -exec rm -f {} \; || true
	find $(INSTALL_MOD_PATH)/lib/modules/$(KVER) -name $(TARGET).gz -exec rm -f {} \; || true
	#Install the new driver
	install -D -m 644 $(TARGET) $(INSTALL_MOD_PATH)$(INSTDIR)/$(TARGET)
	/sbin/depmod -a || true
	/sbin/modprobe $(MODULENAME)
	# save Module.symvers if possible
	mkdir -p $(SYMVERSDIR) || true
	if [ -w $(SYMVERSDIR) ]; then cp Module.symvers $(SYMVERSDIR); fi

uninstall:
	/sbin/rmmod $(MODULENAME) || true
	if [ -e $(INSTDIR)/$(TARGET) ] ; then \
	  rm -f $(INSTDIR)/$(TARGET) ; \
	  rmdir $(INSTDIR); \
	fi
	/sbin/depmod -a
