MXVER:=1.1
TARGET_DRIVER:=mxuport2000
LVER:=$(shell uname -r)

##############################################################
ifneq	"$(findstring 2.4, $(shell uname -a))" "2.4"

all: module

install: module
	@mkdir -p /lib/modules/$(LVER)/kernel/drivers/usb/serial/
	@cp -f ./$(TARGET_DRIVER).ko /lib/modules/$(LVER)/kernel/drivers/usb/serial/
	@depmod -a
	@echo " "
	@echo "**********************************************************************"
	@echo " MOXA UPort 2000 series driver ver $(MXVER) installed successfully."
	@echo "**********************************************************************"

ifneq ($(KERNELRELEASE),)
obj-m := $(TARGET_DRIVER).o
else
KDIR	:= /lib/modules/$(LVER)/build
PWD	:= $(shell pwd)

module: envchk
	@$(MAKE) -s -C $(KDIR) SUBDIRS=$(PWD) modules 2>> build.log \
	&& cp -f ./build.log ../build.log \
	&& exit 0 \
	|| echo "Build Fail! Please chech build.log for further information." \
	&& cp -f ./build.log ../build.log \
	&& exit 1
endif

envchk:
	@./mxconf | tee build.log

remove: clean_lib

cleanall: clean

clean: clean_local clean_lib

clean_local:
	@echo "Removing driver files..."
	@rm -f *.o
	@rm -rf ./.tmp_versions
	@rm -f $(TARGET_DRIVER).mod*
	@rm -f .$(TARGET_DRIVER)*
	@rm -f $(TARGET_DRIVER).ko
	@rm -f *.symvers
	@rm -f *.log
	
clean_lib:
	@rm -f /lib/modules/$(LVER)/kernel/drivers/usb/serial/$(TARGET_DRIVER).ko
	@rm -f ../*log
	@rm -f ./*log
	@rm -f ./*.markers
	@rm -f ./*.order
	@echo ""
	@echo "**********************************************************************"
	@echo " MOXA UPort 2000 series driver ver $(MXVER) removed successfully."
	@echo "**********************************************************************"

endif
