# src/prism2/driver/Makefile
#
# Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
# --------------------------------------------------------------------
#
# linux-wlan
#
#   The contents of this file are subject to the Mozilla Public
#   License Version 1.1 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.mozilla.org/MPL/
#
#   Software distributed under the License is distributed on an "AS
#   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
#   implied. See the License for the specific language governing
#   rights and limitations under the License.
#
#   Alternatively, the contents of this file may be used under the
#   terms of the GNU Public License version 2 (the "GPL"), in which
#   case the provisions of the GPL are applicable instead of the
#   above.  If you wish to allow the use of your version of this file
#   only under the terms of the GPL and not to allow others to use
#   your version of this file under the MPL, indicate your decision
#   by deleting the provisions above and replace them with the notice
#   and other provisions required by the GPL.  If you do not delete
#   the provisions above, a recipient may use your version of this
#   file under either the MPL or the GPL.
#
# --------------------------------------------------------------------
#
# Inquiries regarding the linux-wlan Open Source project can be
# made directly to:
#
# AbsoluteValue Systems Inc.
# info@linux-wlan.com
# http://www.linux-wlan.com
#
# --------------------------------------------------------------------
#
# Portions of the development of this software were funded by 
# Intersil Corporation as part of PRISM(R) chipset product development.
#
# --------------------------------------------------------------------

include $(WLAN_SRC)../../../config.mk

ifeq ($(WLAN_DEBUG), y)
WLAN_INCLUDE_DEBUG=-DWLAN_INCLUDE_DEBUG
endif

ifeq ($(KERN_25), y)
ifneq ($(KERNELRELEASE),)

EXTRA_CFLAGS += -I$(src)/../../include -I$(src)/../include $(WLAN_INCLUDE_DEBUG)

ifeq ($(PRISM2_PCMCIA), y)
	obj-m += prism2_cs.o
endif

ifeq ($(PRISM2_PCI), y)
	obj-m += prism2_pci.o
endif

ifeq ($(PRISM2_PLX), y)
	obj-m += prism2_plx.o
endif

ifeq ($(PRISM2_USB), y)
	obj-m += prism2_usb.o
endif

else

PWD := $(shell pwd)
default:
	if test ! -d $(PWD)/../../.tmp_versions; then \
		cp -rf $(LINUX_SRC)/.tmp_versions $(PWD)/../../ ; \
	fi
	$(MAKE) -C $(LINUX_SRC) SUBDIRS=$(PWD) WLAN_SRC=$(PWD)/ \
		MODVERDIR=$(PWD)/../../.tmp_versions modules

endif  #KERNELRELEASE

clean:
	rm -f *.o *.ko .*.cmd *.mod.c

install:
	mkdir -p $(TARGET_MODDIR)/kernel/drivers/net
	cp *.ko	$(TARGET_MODDIR)/kernel/drivers/net

else  # not KERN_25

SRC=prism2sta.c prism2mgmt.c prism2mib.c 

CS_MODULE=prism2_cs.o
PLX_MODULE=prism2_plx.o
PCI_MODULE=prism2_pci.o
USB_MODULE=prism2_usb.o

CS_MODULE_SRC=prism2_cs.c
PLX_MODULE_SRC=prism2_plx.c
PCI_MODULE_SRC=prism2_pci.c
USB_MODULE_SRC=prism2_usb.c

# List of modules to build
MODULES=
ifeq ($(PRISM2_PCMCIA), y)
MODULES+=$(CS_MODULE)
endif
ifeq ($(PRISM2_PLX), y)
MODULES+=$(PLX_MODULE)
endif
ifeq ($(PRISM2_PCI), y)
MODULES+=$(PCI_MODULE)
endif
ifeq ($(PRISM2_USB), y)
MODULES+=$(USB_MODULE)
endif

# Preprocessor Options
CPPFLAGS=-I../../include -I../include $(WLAN_INCLUDE_DEBUG)
CFLAGS = $(KERNEL_CFLAGS) $(KERNEL_MODFLAGS)

# Use the following if building for kernel pcmcia
ifeq ($(WLAN_KERN_PCMCIA), y)
CS_CFLAGS= $(CFLAGS)
else
CS_CFLAGS=-I$(PCMCIA_SRC)/include $(KERNEL_CFLAGS) $(PCMCIA_MODFLAGS)
endif

# Dependency Source List
DEP_SRC=$(SRC)

# Rules
all : .depend $(MODULES)

$(CS_MODULE) : $(CS_MODULE_SRC)
	$(CC) -c $(CS_CFLAGS) $(CPPFLAGS) $< -o $@

$(PLX_MODULE) : $(PLX_MODULE_SRC)
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

$(PCI_MODULE) : $(PCI_MODULE_SRC)
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

$(USB_MODULE) : $(USB_MODULE_SRC)
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

install : $(MODULES)
ifeq ($(PRISM2_PCMCIA), y)
	mkdir -p $(TARGET_MODDIR)/pcmcia
	cp -f $(CS_MODULE) $(TARGET_MODDIR)/pcmcia 
endif
ifeq ($(PRISM2_PCI), y)
	mkdir -p $(TARGET_MODDIR)/net
	cp -f $(PCI_MODULE) $(TARGET_MODDIR)/net 
endif
ifeq ($(PRISM2_PLX), y)
	mkdir -p $(TARGET_MODDIR)/net
	cp -f $(PLX_MODULE) $(TARGET_MODDIR)/net 
endif
ifeq ($(PRISM2_USB), y)
	mkdir -p $(TARGET_MODDIR)/usb
	cp -f $(USB_MODULE) $(TARGET_MODDIR)/usb 
endif

clean: 
	rm -f .depend*
	rm -f core core.* *.o .*.o *.s *.a .depend tmp_make *~ tags
	rm -fr $(MODULES)

# This probably isn't the best way to handle the dependencies, but it works.
DEPLIST=
ifeq ($(PRISM2_PCMCIA), y)
DEPLIST+=.depend.cs
endif
ifeq ($(PRISM2_PLX), y)
DEPLIST+=.depend.plx
endif
ifeq ($(PRISM2_PCI), y)
DEPLIST+=.depend.pci
endif
ifeq ($(PRISM2_USB), y)
DEPLIST+=.depend.usb
endif

dep depend .depend: $(DEPLIST) ../../../config.mk $(wildcard $(LINUX_SRC)/.config)

.depend.plx:
	rm -f $@
	/bin/echo -n "$@ " >> $@
	$(CPP) -M $(CFLAGS) $(CPPFLAGS) $(PLX_MODULE_SRC) >> $@

.depend.pci:
	rm -f $@
	/bin/echo -n "$@ " >> $@
	$(CPP) -M $(CFLAGS) $(CPPFLAGS) $(PCI_MODULE_SRC) >> $@

.depend.cs:
	rm -f $@
	/bin/echo -n "$@ " >> $@
	$(CPP) -M $(CS_CFLAGS) $(CPPFLAGS) $(CS_MODULE_SRC) >> $@

.depend.usb:
	rm -f $@
	/bin/echo -n "$@ " >> $@
	$(CPP) -M $(CFLAGS) $(CPPFLAGS) $(USB_MODULE_SRC) >> $@

#
# Include a dependency file (if one exists)
#
ifneq ($(MAKECMDGOALS), clean)
ifeq ($(PRISM2_PCMCIA), y)
-include .depend.cs
endif
ifeq ($(PRISM2_PLX), y)
-include .depend.plx
endif
ifeq ($(PRISM2_PCI), y)
-include .depend.pci
endif
ifeq ($(PRISM2_USB), y)
-include .depend.usb
endif
endif

endif # KERN_25
