#	Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
#	<http://rt2x00.serialmonkey.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 - Suite 330, Boston, MA  02111-1307, USA.

#	Module: Makefile
#	Abstract: Makefile for rt2x00 kernel module

#
# Set the enviroment variables.
#
ifndef SUBDIRS
	SUBDIRS=$(shell pwd)
endif

ifdef KERNDIR
	KERNEL_SOURCES := $(KERNDIR)
else
	KERNEL_SOURCES := /lib/modules/$(shell uname -r)/build
endif

ifdef KERNOUT
	KERNEL_OUTPUT := KBUILD_OUTPUT=$(KERNOUT)
else
	KERNEL_OUTPUT :=
endif

ifdef KBUILD_EXTMOD
	IEEE80211_DIR := $(KBUILD_EXTMOD)/ieee80211
	RADIOBTN_DIR := $(KBUILD_EXTMOD)/radiobtn
	LAPTOPKEY_DIR := $(KBUILD_EXTMOD)/laptopkey
else
	IEEE80211_DIR := ieee80211
	RADIOBTN_DIR := radiobtn
	LAPTOPKEY_DIR := laptopkey
endif

#
# Include kernel and rt2x00 config.
#
include $(KERNEL_SOURCES)/.config
include $(SUBDIRS)/config

#
# Determine if and with what options the dscape stack should be build
#
80211-objs := \
	ieee80211/ieee80211.o \
	ieee80211/ieee80211_ioctl.o \
	ieee80211/sta_info.o \
	ieee80211/wep.o \
	ieee80211/wpa.o \
	ieee80211/ieee80211_proc.o \
	ieee80211/ieee80211_scan.o \
	ieee80211/ieee80211_sta.o \
	ieee80211/ieee80211_dev.o \
	ieee80211/ieee80211_iface.o \
	ieee80211/ieee80211_sysfs.o \
	ieee80211/michael.o \
	ieee80211/tkip.o \
	ieee80211/aes_ccm.o \
	ieee80211/wme.o

ifeq ($(CONFIG_NET_SCHED),)
	80211-objs += ieee80211/fifo_qdisc.o
endif

rate_control-objs := ieee80211/rate_control.o

ifeq ($(CONFIG_D80211),y)
	obj-m += 80211.o rate_control.o
endif

ifeq ($(CONFIG_D80211_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_IEEE80211_DEBUG
endif

ifeq ($(CONFIG_D80211_ASM),y)
	always += $(80211-objs:.o=.s) $(rate_control-objs:.o=.s)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

#
# Determine if and with what options the radiobtn driver should be build
#
radiobtn-objs := radiobtn/radiobtn.o

ifeq ($(CONFIG_RADIOBTN),y)
	obj-m += radiobtn.o
endif

ifeq ($(CONFIG_RADIOBTN_ASM),y)
	always += $(radiobtn-objs:.o=.s)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

#
# Determine if and with what options the laptopkey driver should be build
#
laptopkey-objs := laptopkey/laptopkey.o

ifeq ($(CONFIG_LAPTOPKEY),y)
	obj-m += laptopkey.o
endif

ifeq ($(CONFIG_LAPTOPKEY_ASM),y)
	always += $(laptopkey-objs:.o=.s)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

#
# Determine which drivers should be build.
#
ifeq ($(CONFIG_RT2400PCI),y)
	obj-m += rt2400pci.o
endif

ifeq ($(CONFIG_RT2500PCI),y)
	obj-m += rt2500pci.o
endif

ifeq ($(CONFIG_RT2500USB),y)
	obj-m += rt2500usb.o
endif

ifeq ($(CONFIG_RT61PCI),y)
	obj-m += rt61pci.o
endif

ifeq ($(CONFIG_RT73USB),y)
	obj-m += rt73usb.o
endif

#
# Determine which drivers should be build with hardware button support.
#
ifeq ($(CONFIG_RT2400PCI_BUTTON),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT2400PCI_BUTTON
endif

ifeq ($(CONFIG_RT2500PCI_BUTTON),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT2500PCI_BUTTON
endif

ifeq ($(CONFIG_RT61PCI_BUTTON),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT61PCI_BUTTON
endif

#
# Determine which drivers should enable debug output.
#
ifeq ($(CONFIG_RT2400PCI_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT2400PCI_DEBUG
endif

ifeq ($(CONFIG_RT2500PCI_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT2500PCI_DEBUG
endif

ifeq ($(CONFIG_RT2500USB_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT2500USB_DEBUG
endif

ifeq ($(CONFIG_RT61PCI_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT61PCI_DEBUG
endif

ifeq ($(CONFIG_RT73USB_DEBUG),y)
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -DCONFIG_RT73USB_DEBUG
endif

#
# Determine which drivers should create the assembler file
#
ifeq ($(CONFIG_RT2400PCI_ASM),y)
	always += rt2400pci.s
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

ifeq ($(CONFIG_RT2500PCI_ASM),y)
	always += rt2500pci.s
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

ifeq ($(CONFIG_RT2500USB_ASM),y)
	always += rt2500usb.s
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

ifeq ($(CONFIG_RT61PCI_ASM),y)
	always += rt61pci.s
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

ifeq ($(CONFIG_RT73USB_ASM),y)
	always += rt73usb.s
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -fverbose-asm
endif

MAKEFLAGS += --no-print-directory
CFLAGS := -I$(IEEE80211_DIR) -I$(RADIOBTN_DIR) -I$(LAPTOPKEY_DIR) \
	-include $(SUBDIRS)/rt2x00_compat.h $(CFLAGS)
CPPFLAGS := -I$(IEEE80211_DIR) -I$(RADIOBTN_DIR) -I$(LAPTOPKEY_DIR) \
	-include $(SUBDIRS)/rt2x00_compat.h $(CPPFLAGS)

all: default

default:
	@$(MAKE) -C $(KERNEL_SOURCES) SUBDIRS=$(SUBDIRS) $(KERNEL_OUTPUT) \
	modules

install:
	@$(MAKE) -C $(KERNEL_SOURCES) SUBDIRS=$(SUBDIRS) $(KERNEL_OUTPUT) \
		INSTALL_MOD_DIR=rt2x00 $(KERNEL_OUTPUT) modules_install
	/sbin/depmod -a

clean:
	@rm -f *.o ieee80211/*.o radiobtn/*.o laptopkey/*.o
	@rm -f *.ko ieee80211/*.ko radiobtn/*.ko laptopkey/*.ko
	@rm -f *.s ieee80211/*.s radiobtn/*.s laptopkey/*.s
	@rm -f *.mod.c ieee80211/*.mod.c radiobtn/*.mod.c laptopkey/*.mod.c
	@rm -f *~ ieee80211/*~ ieee80211/net/*~ radiobtn/*~ radiobtn/linux/*~ laptopkey/*~ laptopkey/linux/*~
	@rm -f .*.cmd ieee80211/.*.cmd radiobtn/.*.cmd laptopkey/.*.cmd
	@rm -f .*.flags ieee80211/.*.flags  radiobtn/.*.flags laptopkey/.*.flags
	@rm -f .*.o.d ieee80211/.*.o.d radiobtn/.*.o.d laptopkey/.*.o.d
	@rm -f .*.s.d ieee80211/.*.s.d radiobtn/.*.s.d laptopkey/.*.s.d
	@rm -fr .tmp_versions ieee80211/.tmp_versions radiobtn/.tmp_versions laptopkey/.tmp_versions
