# $Id: Makefile,v 1.27 2005/03/19 15:32:54 akw Exp $
#
# Copyright (C) 2004 Zydas Inc.
# Copyright (C) 2005 Arno WILLIG <akw@users.sourceforge.net>
# Copyright (C) 2005 Dimitriy KOROVKIN <korovkin@users.sourceforge.net>
# Copyright (C) 2005 Todor T. ZVISKOV <warderx@users.sourceforge.net>
# Copyright (C) 2005 Markus KARG <markus-karg@users.sourceforge.net>
#
# This file is part of the ZD1211 Wireless USB Driver for Linux.
#
# This driver 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 driver 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 driver; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# common defines
DEFINES += -DAMAC
DEFINES += -DGCCK
DEFINES += -DOFDM
DEFINES += -DUSE_EP4_SET_REG
DEFINES += -DfTX_GAIN_OFDM=0
#only on 2.4 ???
#DEFINES += -DENHANCE_RX=1

SRC_DIR=src

OBJECTS=$(SRC_DIR)/zd1205.o \
    $(SRC_DIR)/zdasocsvc.o \
    $(SRC_DIR)/zdauthreq.o \
    $(SRC_DIR)/zdauthrsp.o \
    $(SRC_DIR)/zdmmrx.o \
    $(SRC_DIR)/zdshared.o \
    $(SRC_DIR)/zdhci.o \
    $(SRC_DIR)/zdglobal.o \
    $(SRC_DIR)/zdencrypt.o \
    $(SRC_DIR)/zdpmfilter.o \
    $(SRC_DIR)/zdpsmon.o \
    $(SRC_DIR)/zdsynch.o \
    $(SRC_DIR)/zdbuf.o \
    $(SRC_DIR)/zdhw.o \
    $(SRC_DIR)/zddebug.o \
    $(SRC_DIR)/zdtkipseed.o \
    $(SRC_DIR)/zdmic.o \
    $(SRC_DIR)/zdusb.o \
    $(SRC_DIR)/zd1211.o

# Some commands
CC=gcc
LD=ld
RM=rm -f -r
CVS=cvs
TAR=tar
GZIP=gzip
DATE=date
GREP=grep

# When KSRC is set, use it
ifneq (,$(srctree))
KSRC=$(srctree)
endif
ifndef KSRC
KSRC=/usr/src/linux
endif

ifeq ($(KERNELRELEASE),)
ZD_VERSION := $(shell $(DATE) +%Y%m%d)
KERNEL_VERSION = $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' \
		$(KSRC)/include/linux/version.h)

MODPATH := /lib/modules/$(KERNEL_VERSION)/kernel/net
endif

# if Rules.make exists in the kernel tree, we assume 2.4 style modules
# if it doesn't assume 2.6 style
OLDMAKE = $(wildcard $(KSRC)/Rules.make)

ifeq (,$(OLDMAKE))
MODULE = zd1211.ko

# those are exported by kbuild
#EXTRA_CFLAGS += -O2 -Wall -Wstrict-prototypes -pipe 

# ignore warnings about unused func
EXTRA_CFLAGS += -Wno-unused 

# common defines
EXTRA_CFLAGS += $(DEFINES)


ifneq ($(KERNELRELEASE),)

zd1211-objs := $(OBJECTS)

obj-$(CONFIG_ZD1211) += zd1211.o

else

PWD := $(shell pwd)
CONFIG_ZD1211=m
#	@echo -e $(KSRC)
#	@echo -e $(PWD)
#	@echo -e $(EXTRA_CFLAGS)
$(MODULE):
	$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules

endif

else # we have a 2.4 kernel

INCLUDES=-I$(KSRC)/include -I$(SRC_DIR)
DEFINES=-D__KERNEL__ -DMODULE=1

MODULE = zd1211.o


CFLAGS=-O -Wall -Wstrict-prototypes -Wno-unused -pipe

ifdef CONFIG_MODVERSIONS
CFLAGS += -DMODVERSIONS -include $(KSRC)/include/linux/modversions.h   #kernel 2.4
endif

ifndef CONFIG_FRAME_POINTER
CFLAGS += -fomit-frame-pointer
endif

ifdef CONFIG_SMP
CFLAGS += -D__SMP__ -DSMP
endif

CFLAGS += $(DEFINES)
CFLAGS += -DENHANCE_RX=1

$(MODULE): $(OBJECTS)
	ld -r $(OBJECTS) -o $(MODULE)
	chmod -x $(MODULE)

%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) $(DEBUG) -c $< -o $@                              
    
endif


apdbg:
	gcc -o apdbg tools/apdbg.c
	chmod +x apdbg

all: $(MODULE) apdbg

install: all
	if [ ! -d $(MODPATH) ]; then mkdir -p $(MODPATH); fi
	cp $(MODULE) $(MODPATH)/
	depmod -a

	cp ./apdbg /usr/local/sbin/apdbg   

clean:
	@$(RM) .tmp_versions .*.cmd *.ko *.mod.c *.mod.o *.o $(SRC_DIR)/*.o  $(SRC_DIR)/.*.o.cmd $(SRC_DIR)/*~ 

update:
	@$(CVS) update -dP

release: clean
	@echo Creating release v$(ZD_VERSION)..;\
	perl -pi  -e 's/".*"/"$(ZD_VERSION)"/' src/zdversion.h ;\
	cd ..;$(TAR) --exclude 'CVS' -c --owner=0 --group=0 zd1211 > sf_zd1211_$(ZD_VERSION)_src.tar;\
	$(GZIP) -f -9 sf_zd1211_$(ZD_VERSION)_src.tar
