dxu1x00_check := $(shell (uname -r | awk -F- '{print $$2}') )
arch := $(shell arch)
ubuntu_version := $(shell cat /etc/issue | head -n 1 | awk '{print $$2}' | awk -F. '{print $$1"."$$2 }' )
kernel_version := $(shell uname -r | awk -F. '{print $$1"."$$2}')
tinker_board_check = 0

ifneq ("$(wildcard /proc/device-tree/model)", "")
ifeq ("$(shell (cat /proc/device-tree/model | awk '{print $$2$$3}'))", "TinkerBoard")
	tinker_board_check = 1
endif
endif

all:
ifeq ("$(dxu1x00_check)", "tegra")
	cd /lib/modules/`uname -r`/ && ln -sf /usr/src/linux-headers-`uname -r`-ubuntu$(ubuntu_version)_$(arch)/kernel-$(kernel_version) build
endif
	$(MAKE) -C driver/module
	$(MAKE) -C driver/module_usb

install:
ifeq ($(tinker_board_check), 0)
	modprobe -r cdc-acm
	$(MAKE) -C driver/module install
	$(MAKE) -C driver/module_usb install
	depmod
endif
	cp driver/rules/180-contec-com.rules /etc/udev/rules.d
	sleep 5
	udevadm trigger

clean:
ifeq ($(tinker_board_check), 0)
	modprobe -r comdrv
	modprobe -r ccomdrvusb
	modprobe -r ftdi_sio
endif
	rm -rf /etc/udev/rules.d/180-contec-com.rules
	$(MAKE) -C driver/module clean
	$(MAKE) -C driver/module_usb clean
ifeq ($(tinker_board_check), 0)
	modprobe cdc-acm
endif
