228f5faabb40647097a294b0d34cac05a95d1bdc
[mirror/scst/.git] / srpt / Makefile
1 #
2 # Makefile for ib_srpt.ko.
3 #
4
5 SCST_DIR := $(shell pwd)/../scst/src
6 SUBDIRS := $(shell pwd)
7
8 ifeq ($(KVER),)
9   ifeq ($(KDIR),)
10     KVER = $(shell uname -r)
11     KDIR ?= /lib/modules/$(KVER)/build
12   else
13     KVER = $$KERNELRELEASE
14   endif
15 else
16   KDIR ?= /lib/modules/$(KVER)/build
17 endif
18
19 # The file Modules.symvers has been renamed in the 2.6.18 kernel to
20 # Module.symvers. Find out which name to use by looking in $(KDIR).
21 MODULE_SYMVERS:=$(shell if [ -e $(KDIR)/Module.symvers ]; then \
22                        echo Module.symvers; else echo Modules.symvers; fi)
23
24 # Whether or not the OFED kernel modules have been installed.
25 OFED_KERNEL_IB_RPM_INSTALLED:=$(shell if rpm -q kernel-ib >/dev/null 2>&1; then echo true; else echo false; fi)
26
27 # Whether or not the OFED kernel-ib-devel RPM has been installed.
28 OFED_KERNEL_IB_DEVEL_RPM_INSTALLED:=$(shell if rpm -q kernel-ib-devel >/dev/null 2>&1; then echo true; else echo false; fi)
29
30 # Path of the OFED ib_srpt.ko kernel module.
31 OFED_SRPT_PATH:=/lib/modules/$(KVER)/updates/kernel/drivers/infiniband/ulp/srpt/ib_srpt.ko
32
33 # Whether or not the OFED ib_srpt.ko kernel module has been installed.
34 OFED_SRPT_INSTALLED:=$(shell if [ -e $(OFED_SRPT_PATH) ]; then echo true; else echo false; fi)
35
36
37 all: src/$(MODULE_SYMVERS)
38         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src modules
39
40 install: all src/ib_srpt.ko
41         @eval `sed -n 's/#define UTS_RELEASE /KERNELRELEASE=/p' $(KDIR)/include/linux/version.h $(KDIR)/include/linux/utsrelease.h 2>/dev/null`; \
42         install -vD -m 644 src/ib_srpt.ko \
43         $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVER)/extra/ib_srpt.ko
44         -/sbin/depmod -aq $(KVER)
45
46 src/Module.symvers src/Modules.symvers: $(SCST_DIR)/$(MODULE_SYMVERS)
47         if $(OFED_KERNEL_IB_RPM_INSTALLED); then                            \
48           if ! $(OFED_KERNEL_IB_DEVEL_RPM_INSTALLED); then                  \
49             echo "Error: the OFED package kernel-ib-devel has not yet been" \
50                  "installed.";                                              \
51             false;                                                          \
52           elif [ -e /lib/modules/$(KVER)/kernel/drivers/infiniband ]; then  \
53             echo "Error: OFED has not been installed correctly.";           \
54             false;                                                          \
55           elif $(OFED_SRPT_INSTALLED); then                                 \
56             echo "Error: OFED has been built with srpt=y in ofed.conf.";    \
57             echo "Rebuild OFED with srpt=n.";                               \
58             false;                                                          \
59           else                                                              \
60             (                                                               \
61               grep -v drivers/infiniband/ $<;                               \
62               cat /usr/src/ofa_kernel/Module.symvers                        \
63             ) >$@;                                                          \
64           fi                                                                \
65         else                                                                \
66           cp $< $@;                                                         \
67         fi
68
69 clean:
70         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src clean
71         rm -f src/Modules.symvers src/Module.symvers src/Module.markers \
72                 src/modules.order
73
74 extraclean: clean
75
76 .PHONY: all install clean extraclean