aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 1a0aeaf87c7ee4bc8125b26e237de5c41e670bec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#$Id: Makefile,v 1.48 2006/07/15 02:31:09 proski Exp $
#
# Copyright (c) 2002 - 2003 Oliver Kurth
#           (c) 2003 - 2004 Jörg Albert <joerg.albert@gmx.de>
#
#	This program 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.
#

# 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))


FW_DL=

# compile for firmware download from user space
# if no firmware header files are available
ifneq ($(wildcard fw-pkg*.h),)
FW_DL += -DCOMPILE_FIRMWARE_INTO_DRIVER
endif

MODULES = at76c503-i3861.o at76c503-rfmd.o at76c503-rfmd-acc.o \
          at76c505-rfmd.o at76c503-i3863.o at76c505-rfmd2958.o at76c505a-rfmd2958.o \
	  at76c503.o at76_usbdfu.o 

SRCS = at76c503.c at76_usbdfu.c at76c503-rfmd.c at76c505-rfmd.c at76c503-rfmd-acc.c \
       at76c503-i3861.c at76c503-i3863.c at76c505-rfmd2958.c at76c505a-rfmd2958.c

HDRS = at76c503.h at76_ieee802_11.h at76_usbdfu.h at76c503-fw_skel.c
FW_HDRS = fw-pkg-505-rfmd2958-1.101.0-86.h fw-pkg-i3863.h \
	fw-pkg-rfmd-1.101.0-84.h fw-pkg-i3861.h \
	fw-pkg-rfmd-0.90.2-140.h \
	fw-pkg-r505.h fw-pkg-rfmd-acc-1.101.0-84.h \
	fw-pkg-505a-rfmd2958-1.102.0-113.h

SCRIPTS = fwbin2h fwbin2pkg.sh fwconvert fwversion

DISTFILES = $(SRCS) $(HDRS) $(FW_HDRS) Makefile README COPYING \
            CHANGELOG gen_fw.c kernel_patch.sh Makefile.k26

# get the version from at76c503.h
ifndef M
VERSION = $(shell sed -n 's/^\#define.*DRIVER_VERSION.*"\(.*\)".*$$/\1/p' at76c503.h)
DISTNAME = at76c503-$(VERSION)
DISTDIR = $(DISTNAME)
endif

# delete any old module in this tree before installing a new one
DEL_MODULE_DIR = $(DESTDIR)/lib/modules/$(KERNELRELEASE)
MODULE_DIR = $(DESTDIR)/lib/modules/$(KERNELRELEASE)/kernel/drivers/net/wireless/at76c503
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__

SRCDIR = $(shell pwd)
MODVERDIR = $(SRCDIR)/.tmp_versions

obj-m := $(MODULES)

all: modules

modules:
	mkdir -p .tmp_versions
	$(MAKE) -C $(KERNEL_PATH) M=$(SRCDIR) MODVERDIR=$(MODVERDIR) \
		EXTRA_CFLAGS="$(FW_DL)" modules

check:
	mkdir -p .tmp_versions
	$(MAKE) -C $(KERNEL_PATH) M=$(SRCDIR) MODVERDIR=$(MODVERDIR) \
		EXTRA_CFLAGS="$(FW_DL)" modules C=2 CF="$(SPARSE_FLAGS)"

mv_old:
	for i in $(MODULES:%.o=%.ko); do \
	  find $(DEL_MODULE_DIR) -name $$i -exec rm -f {} {}.orig \; ;done 

install-modules: all
	mkdir -p $(MODULE_DIR)
	install -m 644 -o 0 -g 0 $(MODULES:%.o=%.ko) $(MODULE_DIR)

install: mv_old install-modules
	$(DEPMOD) -ae

uninstall:
	for f in $(MODULES:%.o=%.ko); do rm $(MODULE_DIR)/$$f; done

.PHONY: all dist kernel_patch rmmod mv_old install-modules install modules

TAGS:
	rm -f TAGS
	etags --append $(SRCS) $(HDRS)

clean:
	rm -f core *.o *~ a.out *.d
	rm -f *.ko *.mod.c .*.cmd
	rm -f *.s *.i
	rm -rf .tmp_versions

dist:
	[ -d $(DISTNAME) ] && rm -rf $(DISTNAME) || true
	mkdir $(DISTNAME)
	cp -f $(DISTFILES) $(DISTNAME)
	mkdir $(DISTNAME)/scripts
	for f in $(SCRIPTS); do \
		cp -f scripts/$$f $(DISTNAME)/scripts/ || exit 1; \
	done
	tar zcvf $(DISTNAME).tar.gz $(DISTNAME)
	rm -f $(DISTNAME)/fw-pkg-*.h
	mv $(DISTNAME) $(DISTNAME)-fwdl
	tar zcvf $(DISTNAME)-fwdl.tar.gz $(DISTNAME)-fwdl
	rm -rf $(DISTNAME)-fwdl

kernel_patch:
	 DRV_SRC="$(SRCS)" DRV_HDR="$(HDRS)" ./kernel_patch.sh $(KERNEL_PATH)

rmmod:
	-rmmod $(MODULES:%.o=%)