# src/prism2/sta_cs/Makefile
# --------------------------------------------------------------------
#
# 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.
#
#   The initial developer of the original code is Mark S. Mathews
#   <mark@absoval.com>.  Portions created by Mark S. Mathews are 
#   Copyright (C) 1999 AbsoluteValue Software, Inc.  All Rights Reserved.
#
#   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.
#
# --------------------------------------------------------------------
#
# The initial author may be reached as mark@absoval.com, or 
# C/O AbsoluteValue Software Inc., P.O. Box 941149, 
# Maitland, FL, 32794-1149
#
# --------------------------------------------------------------------
#
# Portions of the development of this software were funded by 
# Intersil Corporation as part of PRISM(R) chipset product development.
#
# --------------------------------------------------------------------

include ../../../config.mk

# -E outputs preprocessed, just noted here because I forget 

# Build options (just comment out the ones you don't want)
ifeq ($(WLAN_DEBUG), y)
WLAN_INCLUDE_DEBUG="-DWLAN_INCLUDE_DEBUG"
endif

# Source and obj and target definitions
STA_CS_OBJ_DIR=obj_sta_cs
 AP_CS_OBJ_DIR=obj_ap_cs

SRC=prism2sta.c prism2mgmt.c prism2mib.c hfa384x.c

STA_CS_MODULE=prism2sta_cs.o
 AP_CS_MODULE=prism2ap_cs.o

STA_CS_OBJ=	$(STA_CS_OBJ_DIR)/prism2sta.o \
		$(STA_CS_OBJ_DIR)/prism2mgmt.o \
		$(STA_CS_OBJ_DIR)/prism2mib.o \
		$(STA_CS_OBJ_DIR)/hfa384x.o

AP_CS_OBJ=	$(AP_CS_OBJ_DIR)/prism2sta.o \
		$(AP_CS_OBJ_DIR)/prism2mgmt.o \
		$(AP_CS_OBJ_DIR)/prism2mib.o \
		$(AP_CS_OBJ_DIR)/hfa384x.o

# List of modules to build
MODULES=
MODULES+=$(STA_CS_MODULE)
MODULES+=$(AP_CS_MODULE)

# Install dir
MODDIR = $(DESTDIR)$(MODULES_DIR)

# Implicit rules to handle the separate obj dirs
$(OBJ_DIR)/%.o : ../shared/%.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

$(OBJ_DIR)/%.o : %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

$(STA_CS_OBJ_DIR)/%.o : %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) \
	-DWLAN_STA -DWLAN_HOSTIF=WLAN_PCMCIA $< -o $@

$(AP_CS_OBJ_DIR)/%.o : %.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) \
	-DWLAN_AP -DWLAN_HOSTIF=WLAN_PCMCIA $< -o $@


# Compiler Options
ifndef CFLAGS
CFLAGS = -O2 -Wall -Wstrict-prototypes -Winline -fomit-frame-pointer -pipe
endif

# Preprocessor Options
CPPFLAGS=-D__LINUX_WLAN__ -D__KERNEL__ -DMODULE=1 \
	-I../include -I../../include \
	-I$(LINUX_SRC)/include -I$(PCMCIA_SRC)/include \
	$(WLAN_INCLUDE_DEBUG)

# Dependency Source List
DEP_SRC=$(SRC)

# Rules
all : .depend dirs $(MODULES)

dirs : 
	mkdir -p $(STA_CS_OBJ_DIR)
	mkdir -p $(AP_CS_OBJ_DIR)

$(STA_CS_MODULE) : $(STA_CS_OBJ)
	$(LD) -r -o $@ $(STA_CS_OBJ)
	chmod -x $@

$(AP_CS_MODULE) : $(AP_CS_OBJ)
	$(LD) -r -o $@ $(AP_CS_OBJ)
	chmod -x $@

install : $(MODULES)
	cp -p $(MODULES) $(MODDIR)/pcmcia
ifeq ($(WLAN_INSTALL_TYPE), ap)
	ln -sf $(MODDIR)/pcmcia/$(AP_CS_MODULE) $(MODDIR)/pcmcia/prism2_cs.o
else
	ln -sf $(MODDIR)/pcmcia/$(STA_CS_MODULE) $(MODDIR)/pcmcia/prism2_cs.o
endif

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

# This probably isn't the best way to handle the dependencies, but it works.

dep .depend: .depend.sta_cs .depend.ap_cs
	cat .depend.sta_cs .depend.ap_cs > .depend

.depend.sta_cs: $(DEP_SRC) ../../../config.mk
	rm -f .depend.sta_cs
	for i in $(DEP_SRC); \
	do (/bin/echo -n $(STA_CS_OBJ_DIR)/ ; \
	$(CPP) -DWLAN_STA -M $(CPPFLAGS) $$i ) >> .depend.sta_cs; done


.depend.ap_cs: $(DEP_SRC) ../../../config.mk
	for i in $(DEP_SRC); \
	do (/bin/echo -n $(AP_CS_OBJ_DIR)/ ; \
	$(CPP) -DWLAN_AP -M $(CPPFLAGS) $$i ) >> .depend.ap_cs; done
#
# Include a dependency file (if one exists)
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
