# KERNEL_PATH is the path to the Linux kernel build tree.  It is usually
# the same as the kernel tree, except when a separate directory was used
# for the binaries.  By default, we try to compile the modules for the
# currently running kernel.
KERNEL_PATH ?= $(shell readlink -f /lib/modules/`uname -r`/build)

ifeq (,$(KERNEL_PATH))
$(error Kernel tree not found - please set KERNEL_PATH)
endif

VERSION_HEADER = $(KERNEL_PATH)/include/linux/utsrelease.h
ifeq (,$(wildcard $(VERSION_HEADER)))
VERSION_HEADER = $(KERNEL_PATH)/include/linux/version.h
ifeq (,$(wildcard $(VERSION_HEADER)))
$(error Kernel in $(KERNEL_PATH) is not configured)
endif
endif

# Kernel Makefile doesn't always know the exact kernel version, so we
# get it from the kernel headers instead and pass it to make.
KERNELRELEASE = $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' \
		  $(VERSION_HEADER))

SRCS = airport.c hermes.c hermes.h hermes_rid.h orinoco.c orinoco.h \
	orinoco_cs.c orinoco_nortel.c orinoco_pci.c orinoco_pci.h \
	orinoco_plx.c orinoco_tmd.c spectrum_cs.c

TAR = tar
DEPMOD = /sbin/depmod

SPARSE_FLAGS = -Wbitwise -Wcast-to-as -Wcontext -Wdefault-bitfield-sign \
	-Wtransparent-union -Wptr-subtraction-blows -Wundef -Wdecl \
	-Wone-bit-signed-bitfield -Wtypesign -D__CHECK_ENDIAN__

DISTFILES = $(SRCS) Kbuild Makefile NEWS README.orinoco compat.h \
	net/ieee80211.h
DISTNAME = orinoco-$(VERSION)

PWD = $(shell pwd)
VERSION = $(shell sed -ne 's/"//g;s/^\#define DRIVER_VERSION //p' \
	    orinoco.h)

KBUILD_FLAGS = -C $(KERNEL_PATH) M=$(PWD) KERNELRELEASE=$(KERNELRELEASE)


all: modules

modules:
	$(MAKE) $(KBUILD_FLAGS) modules

install: all
	$(MAKE) $(KBUILD_FLAGS) modules_install \
		INSTALL_MOD_DIR=kernel/drivers/net/wireless
	$(DEPMOD) -ae

clean:
	$(MAKE) $(KBUILD_FLAGS) NOCHECK=1 clean
	rm -f *.symvers

check:
	$(MAKE) $(KBUILD_FLAGS) C=2 CF="$(SPARSE_FLAGS)"

ChangeLog: CVS/Entries
	cvs2cl

dist:
	rm -rf $(DISTNAME)
	mkdir -p $(DISTNAME)
	for f in $(DISTFILES); do \
		mkdir -p `dirname $(DISTNAME)/$$f`; \
		cp -f $$f $(DISTNAME)/$$f || exit 1; \
	done
	$(TAR) cvfz $(DISTNAME).tar.gz $(DISTNAME)

.PHONY: all clean dist modules
