############################ 2.6 kernel compile ###############################
ifneq ($(KERNELRELEASE),)
# We were called by kbuild

# only compile those modules which are enabled by global configure
ifeq ($(WCM_OPTION_HID),yes)
# check if HID module should be usbhid.ko or hid.ko
NEWHID := $(shell test $(SUBLEVEL) -ge 6 && echo usb)

$(NEWHID)hid-objs := hid-core.o

# behave exactly as kernel config wants us to behave
ifeq ($(CONFIG_USB_HIDDEV),y)
	$(NEWHID)hid-objs += hiddev.o
endif
ifeq ($(CONFIG_USB_HIDINPUT),y)
	$(NEWHID)hid-objs += hid-input.o
endif
ifeq ($(CONFIG_HID_PID),y)
	$(NEWHID)hid-objs += pid.o
endif
ifeq ($(CONFIG_LOGITECH_FF),y)
	$(NEWHID)hid-objs += hid-lgff.o
endif
ifeq ($(CONFIG_THRUSTMASTER_FF),y)
	$(NEWHID)hid-objs += hid-tmff.o
endif

ifeq ($(CONFIG_HID_FF),y)
	$(NEWHID)hid-objs += hid-ff.o
endif

	obj-m += $(NEWHID)hid.o
endif # WCM_OPTION_HID

ifeq ($(WCM_OPTION_WACOM),yes)
	obj-m += wacom.o
endif

ifeq ($(WCM_OPTION_EVDEV),yes)
	obj-m += evdev.o
endif

ifeq ($(WCM_OPTION_MOUSEDEV),yes)
	obj-m += mousedev.o
endif

ifeq ($(WCM_OPTION_USBMOUSE),yes)
	obj-m += usbmouse.o
endif

else  # We were called from command line
PWD  := $(shell pwd)

KDIR := @WCM_KERNELDIR@
WCM_OPTION_WACOM := @WCM_OPTION_WACOM@
WCM_OPTION_HID := @WCM_OPTION_HID@
WCM_OPTION_EVDEV := @WCM_OPTION_EVDEV@
WCM_OPTION_MOUSEDEV := @WCM_OPTION_MOUSEDEV@
WCM_OPTION_USBMOUSE := @WCM_OPTION_USBMOUSE@
WCM_OPTION_INPUT := @WCM_OPTION_INPUT@

export WCM_OPTION_WACOM WCM_OPTION_HID WCM_OPTION_EVDEV WCM_OPTION_MOUSEDEV \
	WCM_OPTION_USBMOUSE WCM_OPTION_INPUT

COPY_FROM_KERNEL_TREE := hiddev.c hid.h hid-ff.c hid-input.c
COPY_FROM_KERNEL_TREE += hid-lgff.c hid-tmff.c pid.c pid.h

all:
# Copy hid-stuff from kernel-dir to local dir
ifeq ($(WCM_OPTION_HID),yes)
	@for i in $(COPY_FROM_KERNEL_TREE); do \
		cp $(KDIR)/drivers/usb/input/$$i .; \
	done
endif

	@echo '    Building linuxwacom drivers for 2.6 kernel.'
	@echo '    PLEASE IGNORE THE "Overriding SUBDIRS" WARNING'
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

endif  # End kbuild check

######################### Version independent targets ##########################

clean:
	rm -rf *.o *.ko *.mod.* .[a-z]* core *.i

EMPTY_AUTOMAKE_TARGETS = distdir install install-data install-exec uninstall install-info
EMPTY_AUTOMAKE_TARGETS += installdirs check dvi pdf ps info html tags ctags mostlyclean distclean maintainer-clean
.PHONY: $(EMPTY_AUTOMAKE_TARGETS)
	$(EMPTY_AUTOMAKE_TARGETS):
