# 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

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

SRCS = airport.c hermes.c orinoco.c orinoco_cs.c orinoco_nortel.c \
	orinoco_pci.c orinoco_plx.c orinoco_tmd.c spectrum_cs.c
HDRS = hermes.h hermes_rid.h orinoco.h orinoco_pci.h net/ieee80211.h \
	net/ieee80211_crypt.h
TAR = tar
DEPMOD = /sbin/depmod

SPARSE_FLAGS = -Wbitwise -Wcast-to-as -Wcontext -Wdefault-bitfield-sign \
	-Wno-transparent-union -Wptr-subtraction-blows -Wundef \
	-D__CHECK_ENDIAN__

CONF_DIR = /etc/pcmcia
CONF = hermes.conf

DISTFILES = $(SRCS) $(HDRS) Kbuild Makefile NEWS README.orinoco mkconf
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

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

ChangeLog: CVS/Entries
	cvs2cl

$(CONF): orinoco_cs.c spectrum_cs.c
	$(SHELL) mkconf $@ $^

installconf: $(CONF)
	mkdir -p $(CONF_DIR)
	install -m 644 -o 0 -g 0 $(CONF) $(CONF_DIR)/$(CONF)

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
