# Makefile for tiglusb 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 = tiglusb.o
TARGETMODDIR = usb

default: $(TARGET)

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

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

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

tiglusb.o: tiglusb.c tiglusb.h 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)/tiglusb.o

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

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