aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 57fe7691537b224b7065935821106f3e851e1b82 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Edit this path to match with your system (it should point to the root
# directory of the Linux kernel source)
KERNEL_PATH=/usr/src/linux

# Systems using external pcmcia-cs package (instead of kernel-tree pcmcia
# modules):
#
# hostap_cs.o can be compiled either by copying driver/* into pcmcia-cs root
# directory and compiling pcmcia-cs package or by configuring PCMCIA_PATH
# and using this Makefile with 'make pccard; make install_pccard'.
# Leave this blank for kernel-tree PCMCIA compilations (CONFIG_PCMCIA):
PCMCIA_PATH=

# This path will be prepended to every installed file
DESTDIR=

CC=gcc
CFLAGS=-O2 -D__KERNEL__ -DMODULE -Wall -g -c $(EXTRA_CFLAGS)

include $(KERNEL_PATH)/.config

INCLUDES=-I$(KERNEL_PATH)/include
ifdef PCMCIA_PATH
ifndef CONFIG_PCMCIA
INCLUDES=-I$(PCMCIA_PATH)/include -I$(KERNEL_PATH)/include
endif
ifeq (,$(wildcard $(PCMCIA_PATH)/include/pcmcia/version.h))
$(error PCMCIA_PATH doesn't contain valid pcmcia-cs source)
endif
ifdef CONFIG_PCMCIA
$(error Kernel supports PCMCIA - PCMCIA_PATH shouldn't be defined)
endif
export PCMCIA_PATH
endif

ifndef PCMCIA_PATH
ifndef CONFIG_PCMCIA
$(warning WARNING: No kernel PCMCIA support found and PCMCIA_PATH is not defined)
endif
endif

ifndef CONFIG_NET_RADIO
# Most driver configuration commands and hostapd require Linux wireless
# extensions
$(warning WARNING: Linux wireless extensions, CONFIG_NET_RADIO, not enabled in the kernel)
endif

VERFILE := $(KERNEL_PATH)/include/linux/version.h
KERNELRELEASE := $(shell if [ -r $(VERFILE) ]; \
	then (cat $(VERFILE); echo UTS_RELEASE) | $(CC) $(INCLUDES) $(CFLAGS) -E - | tail -1 | xargs echo; \
	else uname -r; fi)
KERNELVER := $(shell echo "$(KERNELRELEASE)" | \
	sed "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
MODPATH := $(DESTDIR)/lib/modules/$(KERNELRELEASE)
MODULE_CS := hostap_cs.o
MODULE_PLX := hostap_plx.o
MODULE_PCI := hostap_pci.o
MODPATH_CS := $(MODPATH)/pcmcia
MODPATH_PLX := $(MODPATH)/net
MODPATH_PCI := $(MODPATH)/net
CURRENTKV := $(shell echo `uname -r`)

MSRC=driver/modules

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


ifeq (,$(OLDMAKE))
all: 2.5
else
all: 2.4
endif

help:
	@echo "Select the version to be build:"
	@echo "make pccard      PC Card (PCMCIA) driver (Prism2 or Prism2.5)"
	@echo "make plx         PLX-based PCI card with PC Card"
	@echo "make pci         Prism 2.5 PCI Card"
	@echo "make crypt       Make hostap_crypt*.o"
	@echo "make hostap      Make hostap.o"

ifdef CONFIG_ALPHA
CFLAGS += -mno-fp-regs -ffixed-8
endif

ifdef CONFIG_MODVERSIONS
CFLAGS += -DMODVERSIONS -include $(KERNEL_PATH)/include/linux/modversions.h
endif

ifdef CONFIG_SMP
CFLAGS += -D__SMP__ -DSMP
endif

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


# Old compilation using this Makefile and not the build system in the kernel
# tree. This is used when compiling for Linux 2.2.x (or Linux 2.4.x with
# 'make pccard'). Both Linux 2.5.x and 2.4.x can use kernel tree build system
# with 'make'.

ifdef CONFIG_MODVERSIONS

VERFILES=$(MSRC)/hostap.ver $(MSRC)/hostap_crypt.ver
$(MSRC)/hostap_crypt_wep.o: $(VERFILES)
$(MSRC)/hostap.o: $(VERFILES)
$(MSRC)/hostap_cs.o: $(VERFILES)
$(MSRC)/hostap_plx.o: $(VERFILES)
$(MSRC)/hostap_pci.o: $(VERFILES)
INCLUDES_MODVER=-include $(MSRC)/hostap_crypt.ver -include $(MSRC)/hostap.ver

GENKSYMS=/sbin/genksyms
ifdef CONFIG_SMP
        GENKSYMS += -p smp_
endif

$(MSRC)/hostap_crypt.ver: $(MSRC)/hostap_crypt.c
	$(CC) $(INCLUDES) $(CFLAGS) -E -D__GENKSYMS__ $^ | \
		$(GENKSYMS) -k $(KERNELVER) > $@
$(MSRC)/hostap.ver: $(MSRC)/hostap.c
	$(CC) $(INCLUDES) $(CFLAGS) -E -D__GENKSYMS__ $^ | \
		$(GENKSYMS) -k $(KERNELVER) > $@

endif


.c.o:
	$(CC) $(INCLUDES) $(INCLUDES_MODVER) $(CFLAGS) -o $@ $<

# end of old compilation


2.4:
	@if ! echo "$(KERNELRELEASE)" | grep -q "^2\.4"; then \
		echo "*** Can't build for 2.4 with a non-2.4 source!"; \
		exit 1; \
	fi
	$(MAKE) -C $(KERNEL_PATH) SUBDIRS=$(PWD)/driver/modules modules
	$(MAKE) install_all_info

2.5:
	@if ! echo "$(KERNELRELEASE)" | grep -q "^2\.5"; then \
		echo "*** Can't build for 2.5 with a non-2.5 source!"; \
		exit 1; \
	fi
	$(MAKE) -C $(KERNEL_PATH) SUBDIRS=$(PWD)/driver/modules \
		MODVERDIR=$(PWD)/driver/modules modules
	$(MAKE) install_all_info

pccard:	$(MSRC)/$(MODULE_CS) hostap crypt install_info
plx:	$(MSRC)/$(MODULE_PLX) hostap crypt install_info
pci:	$(MSRC)/$(MODULE_PCI) hostap crypt install_info
crypt:  $(MSRC)/hostap_crypt.o $(MSRC)/hostap_crypt_wep.o
hostap: $(MSRC)/hostap.o

SRC=$(MSRC)/hostap_hw.c $(MSRC)/hostap_wlan.h $(MSRC)/hostap_config.h \
	$(MSRC)/hostap_download.c \
	$(MSRC)/hostap_ap.h \
	$(MSRC)/hostap_crypt.h $(MSRC)/hostap.h $(MSRC)/hostap_compat.h

$(MSRC)/hostap_crypt.o: $(MSRC)/hostap_crypt.c $(MSRC)/hostap_crypt.h

$(MSRC)/hostap_crypt_wep.o: $(MSRC)/hostap_crypt_wep.c $(MSRC)/hostap_crypt.h

$(MSRC)/hostap.o: $(MSRC)/hostap.c $(MSRC)/hostap.h \
	$(MSRC)/hostap_ap.h $(MSRC)/hostap_ap.c $(MSRC)/hostap_info.c \
	$(MSRC)/hostap_ioctl.c $(MSRC)/hostap_proc.c \
	$(MSRC)/hostap_wlan.h $(MSRC)/hostap_config.h \
	$(MSRC)/hostap_compat.h

$(MSRC)/$(MODULE_CS): $(MSRC)/hostap_cs.c $(SRC)

$(MSRC)/$(MODULE_PLX): $(MSRC)/hostap_plx.c $(SRC)

$(MSRC)/$(MODULE_PCI): $(MSRC)/hostap_pci.c $(SRC)


install_info:
	@echo
	@echo "Run 'make install_pccard' as root to install $(MODULE_CS)"
	@echo "Run 'make install_plx' as root to install $(MODULE_PLX)"
	@echo "Run 'make install_pci' as root to install $(MODULE_PCI)"
	@echo

install_all_info:
	@echo "*** Become superuser and 'make install' to install the modules. ***" 


ifeq (,$(OLDMAKE))
install: install_2.5
else
install: install_2.4
endif

install_check:
	@if [ ! -d "$(MODPATH)" ]; then \
		echo "Module installation directory not valid: '$(MODPATH)'"; \
		echo -n "Most probable cause for this is modified kernel "; \
		echo "headers."; \
		echo -n "You will need to install module file "; \
		echo "($(MSRC)/hostap*.{,k}o) manually."; \
		exit 1; \
	fi

install_2.4: uninstall install_pccard install_pci install_plx

install_2.5: install_conf
	$(MAKE) install_check
	@echo "*** Copying modules to: $(MODPATH)/kernel/drivers/net/wireless"
	mkdir -p $(MODPATH)/kernel/drivers/net/wireless
	cp $(MSRC)/*.ko $(MODPATH)/kernel/drivers/net/wireless
	@if [ -f "/boot/System.map-$(KERNELRELEASE)" ] || [ "$(CURRENTKV)" = "$(KERNELRELEASE)" ]; then \
		echo "*** Running depmod..."; \
		/sbin/depmod -ae; \
	else \
		echo "*** I won't run depmod because I can't find an appropriate System.map file or you are not running the same kernel as the one you are building against. Please run it manually when the conditions are correct..."; \
	fi

install_hostap: $(MSRC)/hostap.o
	@echo "Installing hostap.o to $(MODPATH_PCI)"
	mkdir -p $(MODPATH_PCI)
	cp -f $(MSRC)/hostap.o $(MODPATH_PCI)

install_crypt: $(MSRC)/hostap_crypt.o $(MSRC)/hostap_crypt_wep.o
	@echo "Installing hostap_crypt*.o to $(MODPATH_PCI)"
	mkdir -p $(MODPATH_PCI)
	cp -f $(MSRC)/hostap_crypt*.o $(MODPATH_PCI)

install_pccard: install_check install_crypt install_hostap install_conf
	@echo "Installing $(MODULE_CS) to $(MODPATH_CS)"
	mkdir -p $(MODPATH_CS)
	cp -f $(MSRC)/$(MODULE_CS) $(MODPATH_CS)
ifndef DESTDIR
	/sbin/depmod -ae
endif

install_conf:
	@if [ ! -r $(DESTDIR)/etc/pcmcia/hostap_cs.conf ]; then \
		echo "Installing $(DESTDIR)/etc/pcmcia/hostap_cs.conf"; \
		cp -f driver/etc/hostap_cs.conf $(DESTDIR)/etc/pcmcia/hostap_cs.conf; \
	fi
	@if [ -r $(DESTDIR)/etc/pcmcia/prism2.conf ]; then \
		echo "You may need to remove old $(DESTDIR)/etc/pcmcia/prism2.conf"; \
	fi

install_plx: install_check install_crypt install_hostap
	@echo "Installing $(MODULE_PLX) to $(MODPATH_PLX)"
	mkdir -p $(MODPATH_PLX)
	cp -f $(MSRC)/$(MODULE_PLX) $(MODPATH_PLX)
	/sbin/depmod -ae

install_pci: install_check install_crypt install_hostap
	@echo "Installing $(MODULE_PCI) to $(MODPATH_PCI)"
	mkdir -p $(MODPATH_PCI)
	cp -f $(MSRC)/$(MODULE_PCI) $(MODPATH_PCI)
	/sbin/depmod -ae

uninstall:
	find $(MODPATH) -name "hostap*" | xargs rm -f


clean:
	rm -f $(MSRC)/{$(MODULE_CS),$(MODULE_PLX),$(MODULE_PCI)}
	rm -f $(MSRC)/{hostap.o,hostap_crypt.o,hostap_crypt_wep.o}
	rm -f $(MSRC)/*.ko
	rm -f $(MSRC)/*.ver
	rm -f $(MSRC)/*.mod.[co]
	rm -f $(MSRC)/*.mod
	rm -f $(MSRC)/.hostap*.cmd