#
# Makefile -- makefile for the radeonlcd module
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# Written by Sos Pter <sp@osb.hu>, 2002-2004
#

MODULE_NAME = radeonlcd

MODDIR	= /lib/modules
KVER	= $(shell uname -r)
VMODDIR = $(MODDIR)/$(KVER)
DESTDIR	= $(VMODDIR)/kernel/drivers/char/
#KSRC	= /usr/src/linux
KSRC	= $(VMODDIR)/build
KINCDIR	= $(KSRC)/include/linux
BDIR	= $(shell pwd)
TODAY	= $(shell date +%Y-%m-%d)
KERNEL	= $(shell uname -r | cut -c 1-3)

CC	= gcc
LD	= ld
DEPMOD	= depmod -a
RMMOD	= rmmod
#INSMOD	= insmod
INSMOD	= modprobe
INSTALL	= install -m 644
MKDIR	= mkdir -p
RM	= rm -f
FIND	= find

ifneq ($(KERNEL),2.6)
# These are now dealt with automagically
CFLAGS	= -O2 -Wall -D__KERNEL__ -DMODULE -I$(KSRC)/include $(EXTRA_CFLAGS)

CFLAGS 	+= $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
	 echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h")
CFLAGS	+= -DEXPORT_SYMTAB #-fno-strict-aliasing -fno-common
else
EXTRA_CFLAGS = -Wall
EXTRA_LDFLAGS = -d
endif

ifeq ($(KERNEL),2.4)
# Not needed for 2.6 
export-objs := radeonlcd.o
endif

# All extra flags delt with automagically
obj-m         += $(MODULE_NAME).o

ifneq ($(KERNEL),2.6)
all:		 $(MODULE_NAME).o
else
all:		 $(MODULE_NAME).ko
endif		

clean:
		$(RM) .*.cmd *.map *.mod.c *.o *.ko *~ "#*#"

install:	all
ifeq ($(KERNEL),2.4)
		$(INSTALL) $(MODULE_NAME).o $(DESTDIR)
else
		$(INSTALL) $(MODULE_NAME).ko $(DESTDIR)
endif
		$(DEPMOD)

unload:
ifeq ($(KERNEL),2.4)
		$(RMMOD) $(MODULE_NAME) || :
endif

load:		install unload
		$(INSMOD) $(MODULE_NAME)

uninstall: unload
		$(FIND) $(VMODDIR) -name "$(MODULE_NAME).*o" -exec $(RM) {} \;
		$(DEPMOD)

uninstall-all: unload
		$(FIND) $(MODDIR) -name "$(MODULE_NAME).*o" -exec $(RM) {} \;
		$(DEPMOD)

$(MODULE_NAME).o: $(MODULE_NAME).c

$(MODULE_NAME).ko: $(MODULE_NAME).c
		PWD=$(shell pwd)
		$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules

release:	clean
		mkdir -p ../$(MODULE_NAME)-$(TODAY)
		cp -a * ../$(MODULE_NAME)-$(TODAY)
		sed "s|^\(#define RADEONLCD_VERSION.*\)\".*\"|\1\"$(TODAY)\"|" radeonlcd.c > ../$(MODULE_NAME)-$(TODAY)/radeonlcd.c
		rm -f ../$(MODULE_NAME)-$(TODAY).tar ../$(MODULE_NAME)-$(TODAY).tar.gz
		(cd ..; tar cvf $(MODULE_NAME)-$(TODAY).tar $(MODULE_NAME)-$(TODAY); gzip -9 $(MODULE_NAME)-$(TODAY).tar)

current:	clean
		rm -f ../$(MODULE_NAME)-current.tar ../$(MODULE_NAME)-current.tar.gz
		(cd ..; tar cvf $(MODULE_NAME)-current.tar $(MODULE_NAME)-current; gzip -9 $(MODULE_NAME)-current.tar)

# End of file
