############################ 2.6 kernel compile ###############################
ifneq ($(KERNELRELEASE),)
# We were called by kbuild
# Do NOT indent stuff in this part! It has to be like this to make the
# $(error ... ) stuff work

# only compile those modules which are enabled by global configure
ifeq ($(WCM_OPTION_HID),yes)

# check if kernel was configured to have hid as an module
ifeq ($(CONFIG_USB_HID),m)

# 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-$(CONFIG_USB_HID) += $(NEWHID)hid.o

else
ifeq ($(CONFIG_USB_HID),y)
$(error You requested to build hid with configure, but hid is configured as built-in in your kernel config)
endif

$(error You requested to build hid with configure, but hid is not configured in your kernel config)
endif # CONFIG_USB_HID
endif # WCM_OPTION_HID not

ifeq ($(WCM_OPTION_WACOM),yes)
ifneq ($(CONFIG_USB_WACOM),y)
obj-m += wacom.o
else
$(error You requested to build wacom with configure, but wacom is configured as built-in in your kernel config)
endif # CONFIG_USB_WACOM
endif # WCM_OPTION_WACOM

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

KDIR := /lib/modules/2.6.16-1.2133_FC5/build
WCM_OPTION_WACOM := no
WCM_OPTION_HID := no

export WCM_OPTION_WACOM WCM_OPTION_HID

COPY_FROM_KERNEL_TREE := hiddev.c hid.h hid-ff.c hid-input.c fixp-arith.h
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 \
		if test ! -f "$$i" && test -f $(KDIR)/drivers/usb/input/$$i ; then \
			cp $(KDIR)/drivers/usb/input/$$i .; \
		fi; \
	done
endif

	@echo '    Building linuxwacom drivers for 2.6 kernel.'
	@echo '***Note: Drivers not enabled as modules in your kernel config but requested through configure are NOT built'
	$(MAKE) -C $(KDIR) M=$(PWD)

endif  # End kbuild check

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

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

# also remove copied stuff
distclean: clean
	@for i in $(COPY_FROM_KERNEL_TREE); do \
		if test -f "$$i"; then \
			rm -f $$i ; \
		fi; \
	done

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):
