# $Id: Makefile,v 1.3 2004/03/08 03:55:11 mikey Exp $

CC=cc

KERNEL_VERSION=$(shell uname -r )
KERNEL_SRC_DIR=/lib/modules/$(KERNEL_VERSION)/build
DESTDIR=/lib/modules/$(KERNEL_VERSION)/misc

INCLUDE= -I.
DEFINES=
CFLAGS= -Wall -D__KERNEL__ -I$(KERNEL_SRC_DIR)/include \
		-O2 -fomit-frame-pointer -pipe \
		-ffixed-8 -DMODULE -DMODVERSIONS -finline-functions \
		-include $(KERNEL_SRC_DIR)/include/linux/modversions.h

default: lcd.o

lcd.o: lcd.c cgram/default.h cgram/swedish.h charmap.h config.h wiring.h
	@echo -e "- Making lcd.o"
	@echo "- KERNEL_SRC_DIR: $(KERNEL_SRC_DIR)"
	@echo "- DESTDIR: $(DESTDIR)"
	$(CC) $(CFLAGS) $(DEFINES) -c lcd.c -o lcd.o

install: lcd.o
	if [[ -e /dev/lcd ]]; then exit; else mknod /dev/lcd c 120 0; fi
	if [[ -d $(DESTDIR) ]]; then exit; else mkdir -p $(DESTDIR); fi
	if [[ `uname -r | cut -d. -f 1,2` == 2.6 ]]; then \
                 cp lcd.o $(DESTDIR)/lcd.ko; \
         else \
                 cp lcd.o $(DESTDIR); \
         fi
	if [[ -z `grep lcd /etc/modules.conf` ]]; then \
		echo "alias char-major-120 lcd" >> /etc/modules.conf; \
	fi 
	depmod -a

test: install
	if [[ -n `lsmod|grep lcd` ]]; then rmmod lcd; fi
	modprobe lcd
	echo "Hello LCD world!" > /dev/lcd

clean:
	rm -f lcd.o
