#
# Makefile for the PCI-954/16C950 serial drivers
#
# Advantech eAutomation Division
#

ADVMOD := adv950


CONFIG_PATH = config-$(shell uname -r)
RESULT = $(shell grep CONFIG_DEVFS_FS=y /boot/$(CONFIG_PATH))

ifeq ($(RESULT),CONFIG_DEVFS_FS=y)
SERIAL_NAME = ttap
SERIAL_FOLDER = ttap/%d
CALLOUT_NAME= ttac
CALLOUT_FOLDER = ttac/%d
TEST_NAME = ttap/
else
SERIAL_NAME = ttyAP
SERIAL_FOLDER = ttyAP
CALLOUT_NAME= ttyAC
CALLOUT_FOLDER = ttyAC
TEST_NAME = ttyAP
endif

MAX_TTY= 16
MAX_TTY= 16
ADV_TTY_MAJOR= 30
ADV_TTY_CUMAJOR= 35


install: 
	$(shell if grep $(ADVMOD) /proc/modules > /dev/null ; then \
         rmmod $(ADVMOD) ; fi)
	insmod ./$(ADVMOD).o

node: 
	@echo "Creating serial device nodes $(SERIAL_NAME) ..."
	@echo "The Result is $(RESULT)"
	@./advmknod $(SERIAL_NAME) \
	 $$(awk '$$2=="$(SERIAL_FOLDER)" {print $$1}' /proc/devices) $(MAX_TTY)
	@echo "Creating callout device nodes $(CALLOUT_NAME) ..."
	@./advmknod $(CALLOUT_NAME) \
	 $$(awk '$$2=="$(CALLOUT_FOLDER)" {print $$1}' /proc/devices) $(MAX_TTY)
	@echo "Done"

uninstall:
	$(shell if grep $(ADVMOD) /proc/modules > /dev/null ; then \
        rmmod $(ADVMOD) ; fi)

test:
	@cd ./getconfig; make; ./getconfig $(TEST_NAME) $(MAX_TTY)
