##############################################################################
#
#   Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
#
#	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 of the License, 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.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place Ste 330, Boston MA 02111, USA
#
##############################################################################

IRDA4210_VERSION = 0.1
LINUX_VERSION = 2.4
SRC=/usr/src
INCLUDEDIR = $(SRC)/linux-$(LINUX_VERSION)/include
MODPATH=/lib/modules/$(LINUX_VERSION)/kernel/drivers/net/irda

CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR) -DIRDA4210_VERSION=$(IRDA4210_VERSION)
#CFLAGS:=$(CFLAGS) -DLOCAL_DEBUG
#CFLAGS:=$(CFLAGS) -DDEBUG_LEVEL=9
#CFLAGS:=$(CFLAGS) -DIRDA_DEBUG_MSG_DUMP_XMIT=1
#CFLAGS:=$(CFLAGS) -DIRDA_DEBUG_MSG_DUMP_RCV=1
#CFLAGS:=$(CFLAGS) -DIU_DUMP_CLASS_DESC

OBJS = irda4210.o

TARFILES=\
	Makefile \
	README \
	gpl.txt \
	irda-ioctl.h \
	irda-usb.c \
	irda-usb.h \
	tools/Makefile \
	tools/getargs.c \
	tools/stir42xxi.h \
	tools/stir42xx.c \
	tools/sgtlpatch

all: $(OBJS)
	(cd tools && $(MAKE))

.PHONY: uninstall
uninstall: rmmod
	-rm $(MODPATH)/irda4210.o >/dev/null 2>&1

.PHONY: install
install: irda4210.o uninstall
	install -D irda4210.o $(MODPATH)/irda4210.o

.PHONY: rmmod
rmmod:
	-rmmod irda4210 >/dev/null 2>&1

.PHONY: insmod
insmod: rmmod install
	insmod irda4210

.PHONY: clean
clean: 
	-rm -f *.o \
		$(SRC)/irda4210-$(IRDA4210_VERSION).tar \
		$(SRC)/irda4210-$(IRDA4210_VERSION).tar.gz
	(cd tools && $(MAKE) clean)

.PHONY: tar
tar: $(SRC)/irda4210-$(IRDA4210_VERSION).tar

.PHONY: targz
targz: $(SRC)/irda4210-$(IRDA4210_VERSION).tar.gz

.PHONY: tarbz2
tarbz2: $(SRC)/irda4210-$(IRDA4210_VERSION).tar.bz2

.PHONY: tarballs
tarballs: tar targz tarbz2

irda-usb.o: irda-usb.c $(INCLUDEDIR)/linux/irda.h

irda4210.o: irda-usb.o
	$(LD) -r $^ -o $@

$(SRC)/irda4210-$(IRDA4210_VERSION).tar: $(TARFILES)
	(cd $(SRC) && tar --group 99 -cvf irda4210-$(IRDA4210_VERSION).tar $(patsubst %,irda4210/%,$(TARFILES)) )

$(SRC)/irda4210-$(IRDA4210_VERSION).tar.gz: $(SRC)/irda4210-$(IRDA4210_VERSION).tar
	gzip -c -f $(SRC)/irda4210-$(IRDA4210_VERSION).tar >$@

$(SRC)/irda4210-$(IRDA4210_VERSION).tar.bz2: $(SRC)/irda4210-$(IRDA4210_VERSION).tar
	bzip2 -c -f $(SRC)/irda4210-$(IRDA4210_VERSION).tar >$@

.PHONY: irdaup
irdaup:
	-insmod usbcore >/dev/null 2>&1
	-insmod uhci >/dev/null 2>&1
	-insmod irda

.PHONY: irdadown
irdadown:
	-ifconfig irda0 down
	-rmmod irda4210
	-rmmod irda

ifndef IRDA_DEBUG_LEVEL
IRDA_DEBUG_LEVEL=9
endif
.PHONY: irda_debug
irda_debug:
	@test -w /proc/sys/net/irda/debug || (echo irda not debugging version 1>&2 && false )
	echo $(IRDA_DEBUG_LEVEL) >/proc/sys/net/irda/debug

