# Makefile for tiser to be called by master Makefile that
# does the preparation work (setting up links, copying Rules.make ...)
# (w) 6/2001, Romain Lievin <rlievin@mail.com>

TARGET = tiser.o
TARGETMODDIR = misc

default: $(TARGET)

include $(KDIR)/.config
include $(KDIR)/Makefile
TOPDIR := $(KDIR)
KVERS := $(shell uname -r)

CFLAGS := -I. -I $(KDIR)/drivers/misc -I$(KDIR)/include $(CFLAGS) -DMODULE

ifdef CONFIG_MODVERSIONS
#CFLAGS += -DMODVERSIONS -include $(KDIR)/include/linux/modversions.h
endif

tiser.o: tiser.c ticable.h arch Rules.make

# 2.4 and later define PERL in the Makefile
#ifdef PERL
ifeq ($(PATCHLEVEL),4)
MODLIB := $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVERS)/kernel/drivers
else
MODLIB := $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVERS)
endif

install_mod: $(MODLIB)/$(TARGETMODDIR)/tiser.o

$(MODLIB)/$(TARGETMODDIR)/tiser.o: tiser.o
	echo "Install tiser"
	install -o root -g root -d $(MODLIB)/$(TARGETMODDIR)
	install -o root -g root -m 0644 tiser.o $(MODLIB)/$(TARGETMODDIR)/

load_module: install_mod
	@if test $(shell id -u) = 0; then \
		if test ! -z "$(shell lsmod | grep tiser)"; then echo "Remove tiser"; \
		rmmod tiser; fi; \
		echo "Load tiser"; modprobe tiser; \
	else \
		echo "Give root password for loading of kernel module"; \
		su -c \
		'if test ! -z "$(shell lsmod | grep tiser)"; then echo "Remove tiser"; \
		 rmmod tiser; fi; \
		 echo "Load tiser"; modprobe tiser'; \
	fi	
