Made building against OFED more robust.
[mirror/scst/.git] / srpt / Makefile
1 #
2 # Makefile for the Linux kernel device drivers.
3 #
4 # Note! Dependencies are done automagically by 'make dep', which also
5 # removes any old dependencies. DON'T put your own dependencies here
6 # unless it's something special (not a .c file).
7 #
8 # Note 2! The CFLAGS definitions are now in the main makefile.
9
10 SCST_DIR := $(shell pwd)/../scst/src
11 SUBDIRS := $(shell pwd)
12
13 ifeq ($(KVER),)
14   ifeq ($(KDIR),)
15     KVER = $(shell uname -r)
16     KDIR ?= /lib/modules/$(KVER)/build
17   else
18     KVER = $$KERNELRELEASE
19   endif
20 else
21   KDIR ?= /lib/modules/$(KVER)/build
22 endif
23
24 # The file Modules.symvers has been renamed in the 2.6.18 kernel to
25 # Module.symvers. Find out which name to use by looking in $(KDIR).
26 MODULE_SYMVERS=$(shell if [ -e $(KDIR)/Module.symvers ]; then \
27                        echo Module.symvers; else echo Modules.symvers; fi)
28
29 all: $(MODULE_SYMVERS)
30         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src modules
31
32 install: all src/ib_srpt.ko
33         @eval `sed -n 's/#define UTS_RELEASE /KERNELRELEASE=/p' $(KDIR)/include/linux/version.h $(KDIR)/include/linux/utsrelease.h 2>/dev/null`; \
34         install -vD -m 644 src/ib_srpt.ko \
35         $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVER)/extra/ib_srpt.ko
36         -/sbin/depmod -aq $(KVER)
37
38 Module.symvers: src/Module.symvers
39
40 Modules.symvers: src/Modules.symvers
41
42 .PHONY: Module.symvers Modules.symvers
43
44 src/Module.symvers src/Modules.symvers: $(SCST_DIR)/$(MODULE_SYMVERS)
45         if [ -e /lib/modules/$(KVER)/updates/kernel/drivers/infiniband ]; then\
46           if [ ! -e /usr/src/ofa_kernel/Module.symvers ]; then                \
47             echo "Error: the OFED package kernel-ib-devel has not yet been"   \
48                  "installed.";                                                \
49             false;                                                            \
50           elif [ -e /lib/modules/$(KVER)/kernel/drivers/infiniband ]; then    \
51             echo "Error: OFED has not been installed correctly.";             \
52             false;                                                            \
53           else                                                                \
54             (                                                                 \
55               grep -v drivers/infiniband/ $<;                                 \
56               cat /usr/src/ofa_kernel/Module.symvers                          \
57             ) >$@;                                                            \
58           fi                                                                  \
59         else                                                                  \
60           cp $< $@;                                                           \
61         fi
62
63 clean:
64         $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src clean
65         rm -f src/Modules.symvers src/Module.symvers src/Module.markers \
66                 src/modules.order
67
68 extraclean: clean
69
70 .PHONY: all install clean extraclean