Updates for the OFED 1.5 + kernel 2.6.30 combination.
[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 ifeq ($(OFED_KERNEL_IB_DEVEL_RPM_INSTALLED),true)
31 # Read OFED's config.mk, which contains the definition of the variable
32 # BACKPORT_INCLUDES.
33 include /usr/src/ofa_kernel/config.mk
34 endif
35
36 OFED_CFLAGS:=$(shell if $(OFED_KERNEL_IB_DEVEL_RPM_INSTALLED); then echo $(BACKPORT_INCLUDES) -I/usr/src/ofa_kernel/include; fi)
37
38 # Path of the OFED ib_srpt.ko kernel module.
39 OFED_SRPT_PATH:=/lib/modules/$(KVER)/updates/kernel/drivers/infiniband/ulp/srpt/ib_srpt.ko
40
41 # Whether or not the OFED ib_srpt.ko kernel module has been installed.
42 OFED_SRPT_INSTALLED:=$(shell if [ -e $(OFED_SRPT_PATH) ]; then echo true; else echo false; fi)
43
44
45 all: src/$(MODULE_SYMVERS)
46         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src \
47           PRE_CFLAGS="$(OFED_CFLAGS)" modules
48
49 install: all src/ib_srpt.ko
50         @eval `sed -n 's/#define UTS_RELEASE /KERNELRELEASE=/p' $(KDIR)/include/linux/version.h $(KDIR)/include/linux/utsrelease.h 2>/dev/null`; \
51         install -vD -m 644 src/ib_srpt.ko \
52         $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVER)/extra/ib_srpt.ko
53         -/sbin/depmod -aq $(KVER)
54
55 src/Module.symvers src/Modules.symvers: $(SCST_DIR)/$(MODULE_SYMVERS)
56         @if $(OFED_KERNEL_IB_RPM_INSTALLED); then                           \
57           if ! $(OFED_KERNEL_IB_DEVEL_RPM_INSTALLED); then                  \
58             echo "Error: the OFED package kernel-ib-devel has not yet been" \
59                  "installed.";                                              \
60             false;                                                          \
61           elif [ -e /lib/modules/$(KVER)/kernel/drivers/infiniband ]; then  \
62             echo "Error: the distro-provided InfiniBand kernel drivers"     \
63                  "must be removed first.";                                  \
64             false;                                                          \
65           elif $(OFED_SRPT_INSTALLED); then                                 \
66             echo "Error: OFED has been built with srpt=y in ofed.conf.";    \
67             echo "Rebuild OFED with srpt=n.";                               \
68             false;                                                          \
69           elif [ -e $(KDIR)/scripts/Makefile.lib ]                          \
70                && ! grep -wq '^c_flags .*PRE_CFLAGS'                        \
71                   $(KDIR)/scripts/Makefile.lib                              \
72                && ! grep -wq '^LINUXINCLUDE .*PRE_CFLAGS'                   \
73                   $(KDIR)/Makefile; then                                    \
74             echo "Error: the kernel build system has not yet been patched.";\
75             false;                                                          \
76           else                                                              \
77             echo "  Building against OFED InfiniBand kernel headers.";      \
78             (                                                               \
79               grep -v drivers/infiniband/ $<;                               \
80               cat /usr/src/ofa_kernel/Module.symvers                        \
81             ) >$@;                                                          \
82           fi                                                                \
83         else                                                                \
84           echo "  Building against non-OFED InfiniBand kernel headers.";    \
85           cp $< $@;                                                         \
86         fi
87
88 clean:
89         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src clean
90         rm -f src/Modules.symvers src/Module.symvers src/Module.markers \
91                 src/modules.order
92
93 extraclean: clean
94
95 .PHONY: all install clean extraclean