#
# Makefile for the kernel serial device drivers.
#
# Advantech eAutomation Division
#

obj-m := adv950.o
adv950-objs := 8250.o 8250_pci.o serial_core.o
UNAME := $(shell uname -r)
PWD := $(shell pwd)
ADVMOD := adv950

SERIAL_NAME= ttyAP
MAX_TTY= 16
ADV_TTY_MAJOR= 30
SERIAL_FLAGS= -DSERIAL_NAME=\"$(SERIAL_NAME)\" \
              -DADV_TTY_MAJOR=$(ADV_TTY_MAJOR) \
              -DADV_TTY_CUMAJOR=$(ADV_TTY_CUMAJOR)

ifeq "$(UNAME)""2.6.15-26-386" 
CFLAGS:= $(CFLAGS) $(SERIAL_FLAGS) -DUBUNTU_2_6_15=1
else
CFLAGS:= $(CFLAGS) $(SERIAL_FLAGS) -DUBUNTU_2_6_15=0
endif
ifeq "$(UNAME)""2.6.9-34.EL" 
CFLAGS:= $(CFLAGS) $(SERIAL_FLAGS) -DRHE4SMP=0
endif
ifeq "$(UNAME)""2.6.9-34.ELsmp" 
CFLAGS:= $(CFLAGS) $(SERIAL_FLAGS) -DRHE4SMP=1
endif

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

node: 
	@echo "Creating serial device nodes $(SERIAL_NAME) ..."
	@chmod 777 ./advmknod
	@./advmknod $(SERIAL_NAME) \
	 $$(awk '$$2=="$(SERIAL_NAME)" {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 $(SERIAL_NAME) $(MAX_TTY)

