#
# ServerU PLCM Utility
#
# ServerU - http://www.ServerU.com.br http://www.ServerU.us
# PLCM with 2 lines with 4 keys pad model Netmap L100 & Netmap L800
#
# Developed and tested for/on Linux 2.4, Linux 2.6, Linux 3.1, Linux 3.2
#
# This Makefile requires /usr/src as well as /lib/modules/XXXX/build
# because we will use the very same stub for modules compiling on Linux.
# We will also compile the whole thing with clang prefferably.
# -- Patrick Tracanelli
#
# Testa versao do kernel
KVER=$(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
KVERSUB=$(shell uname -r | cut -c5-6)
KVER3=$(shell uname -r | cut -c1-1)

KINC=
ifeq ($(KINC),)
KINC=$(shell uname -r)
endif
#CC=clang # Tem CLANG nesse Linux?
CC=gcc

MODCFLAGS=-DMODULE -D__KERNEL__ -DLINUX -DOLDKERNEL -O -I/usr/src/linux-$(KINC)/include

# 2.6.x
obj-m = plcm_drv.o
KDIR  = /lib/modules/$(shell uname -r)/build
PWD   = $(shell pwd)

default:
ifeq ($(wildcard /dev/plcm_drv),)
	mknod /dev/plcm_drv c 666 0
endif
	#$(CC) -O2 serveru-plcm-util.c -o serveru-plcm-util
ifeq ($(KVER3),3)
	$(MAKE) -C $(KDIR) M=$(PWD) modules
endif
ifeq ($(KVER),2.6)
	$(MAKE) -C $(KDIR) M=$(PWD) modules
endif
ifeq ($(KVER),2.4)
	$(CC) $(MODCFLAGS) -c plcm_drv.c
endif
ifeq ($(wildcard Test),)
ifeq ($(KVER3),3)
endif
ifeq ($(KVER),2.6)
endif
ifeq ($(KVER),2.4)
	echo "Use o plcm_drv.o e nao o .ko"
endif
endif
serveru-plcm-util:
	$(CC) -O2 serveru-plcm-util.c -o serveru-plcm-util
clean:
	rm -f serveru-plcm-util escreve_sample *.ko *.o
sample:
	$(CC) -O2 sample_src/escreve_sample.c -o escreve_sample

ifeq ($(KVER3),3)
	$(MAKE) -C $(KDIR) M=$(PWD) clean
endif
ifeq ($(KVER),2.6)
	$(MAKE) -C $(KDIR) M=$(PWD) clean
endif
ifeq ($(KVER),2.4)
	rm -f *.o *.ko
endif

