#    Copyright (C) 2006 rtl818x Driver Project
#
#    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 - Suite 330, Boston, MA  02111-1307, USA.
#
#    $Id: Makefile,v 1.4 2006/06/30 19:20:32 bsd3 Exp $
#    Abstract: Makefile for rtl818x kernel modules
#
# NOTE: This makefile is for building out-of-tree modules


# --- Kernel Configuration (Comment/UN-Comment, if needed and, or works
#     edit the /usr/src/linux-2.6.*/.config file otherwise
MODULE_NAME := rtl818x
DRV_VERSION := 1.0.1-b


# --- Main Rules (MODIFY, ONLY IF YOU KNOW WHAT YOU'RE DOING)
CFLAGS += -I$(TOPDIR)/drivers/net/wireless/rtl818x
CFLAGS += -DDRV_VERSION=\"$(DRV_VERSION)\"

CFLAGS += -DCONFIG_IEEE80211_SOFTMAC_DEBUG=1
CFLAGS += -DIEEE80211_DEBUG=1

KDIR ?= /lib/modules/`uname -r`/build
MODPATH ?= /lib/modules/`uname -r`/kernel/net/ieee80211
DRVPATH ?= /lib/modules/`uname -r`/kernel/drivers/net/wireless/rtl818x

modules:
	make -C $(KDIR) SUBDIRS=`pwd`/net/ieee80211 CONFIG_IEEE80211=m CONFIG_IEEE80211_CRYPT=m CONFIG_IEEE80211_CRYPT_WEP=m CONFIG_IEEE80211_CRYPT_CCMP=m CONFIG_IEEE80211_CRYPT_TKIP=m CC="${CROSS_COMPILE}gcc -I`pwd`/include" modules
	make -C $(KDIR) SUBDIRS=`pwd`/drivers/net/wireless/rtl818x CONFIG_RTL818X=m CC="${CROSS_COMPILE}gcc -I`pwd`/include" modules

install: modules
	install -d /lib/modules/`uname -r`/kernel/net/ieee80211
	install -m 644 -c `pwd`/net/ieee80211/ieee80211-rtl.ko $(MODPATH)
	install -m 644 -c `pwd`/net/ieee80211/ieee80211_crypt-rtl.ko $(MODPATH)
	install -m 644 -c `pwd`/net/ieee80211/ieee80211_crypt_ccmp-rtl.ko $(MODPATH)
	install -m 644 -c `pwd`/net/ieee80211/ieee80211_crypt_tkip-rtl.ko $(MODPATH)
	install -m 644 -c `pwd`/net/ieee80211/ieee80211_crypt_wep-rtl.ko $(MODPATH)
	install -d /lib/modules/`uname -r`/kernel/drivers/net/wireless/rtl818x
	install -m 644 -c `pwd`/drivers/net/wireless/rtl818x/rtl818x.ko $(DRVPATH)
	/sbin/depmod -a

uninstall:
	rm -rf $(MODPATH)
	rm -rf $(DRVPATH)
	/sbin/depmod -a

clean:
	@find . \( -name '*.ko' -o -name '*.o' -o -name '.tmp_versions' -o -name '*~' -o -name '.*.cmd' -o -name '*.symvers' \
		-o -name '*.mod.c' -o -name '*.tar.bz2' -o -name '*.rej' -o -name '*.orig' -o -name '*.o.d' \)\
		-print | xargs rm -Rf

.PHONY: rdoc
rdoc: DOWNLOAD README README.adhoc README.master INSTALL
	rdoc README README.adhoc README.master DOWNLOAD INSTALL

.PHONY: release tarball tar
release: tar
tarball: tar
tar: clean
	tar czvf ../$(MODULE_NAME)-$(DRV_VERSION).tar.gz \
	    `find ../$(MODULE_NAME)-$(DRV_VERSION) -type f |egrep -v 'CVS|\.cvs'`
