summaryrefslogtreecommitdiff
path: root/kernel/Makefile
blob: 7281a6095793e5378f5a550b734eedd43a388037 (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
#
# Makefile for the Linux Kernel iSCSI Initiator
#
# This Makefile invokes KBuild from outside the kernel directory when
# used from the main open-iscsi package. It also contains all of the
# KBuild stuff needed to build the modules.
#

# Kbuild stuff, the following is the only part of this file that KBuild
# actually uses itself.
EXTRA_CFLAGS += -I$(obj) -I$(obj)/../include 

ifeq ($(DEBUG_SCSI), 1)
EXTRA_CFLAGS += -DDEBUG_SCSI=1
endif

ifeq ($(DEBUG_TCP), 1)
EXTRA_CFLAGS += -DDEBUG_TCP=1
endif

obj-m				+= scsi_transport_iscsi.o
obj-m				+= libiscsi.o
obj-m				+= iscsi_tcp.o

# Everything beyond this point is used to call KBuild or handle support
# for multiple kernel versions.

# Kbuild verbosity
V ?= 0

# allow users to override these
# eg to compile for a kernel that you aren't currently running
KERNELRELEASE ?= $(shell uname -r)
KSRC ?= /lib/modules/$(KERNELRELEASE)/build
KBUILD_OUTPUT ?= 
# this is the basic Kbuild invocation, just append your make target
KBUILD_BASE = +$(MAKE) -C $(KSRC) M=`pwd` KBUILD_OUTPUT=$(KBUILD_OUTPUT) $(KARCH) V=$(V)

all: kernel_check
	$(KBUILD_BASE) modules

# ============ BEGIN code for kernel_check and source patching ================
# We calculate the Linux version for compilation. Than according to version,
# if needed, we patch source-code to match the compiling kernel.
# if you need a new kernel sub-version just add a target below.
#
# IMPORTANT: do "make clean" before submitting to SVN so source is in unpatched
#            form.

#some constants
14to19_patch=2.6.14-19_compat.patch
20to21_patch=2.6.20-21_compat.patch
24_patch=2.6.24_compat.patch
all_patches=14to21_patch 20to21_patch 24_patch
cur_patched=cur_patched

## fun stuff for maintaining multiple versions

# check to see if code is unpatched 
unpatch_code=$(shell test -e $(cur_patched) && echo do_unpatch_code )

KSUBLEVEL = $(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \
		sed 's/^[ \t]*//;s/[ \t]*$$//')

KERNEL_TARGET=linux_2_6_$(KSUBLEVEL)
kernel_check: $(KERNEL_TARGET)

linux_2_6_14: has_14to19_patch

linux_2_6_15: has_14to19_patch

linux_2_6_16: has_14to19_patch

linux_2_6_17: has_14to19_patch

linux_2_6_18: has_14to19_patch

linux_2_6_19: has_14to19_patch

linux_2_6_20: has_20to21_patch

linux_2_6_21: has_20to21_patch

linux_2_6_22: has_20to21_patch

linux_2_6_23: has_20to21_patch

linux_2_6_24: has_24_patch

linux_2_6_25: $(unpatch_code)

do_unpatch_code:
	echo "Un-patching source code for use with linux-2.6.14 and up ..."
	patch -R -E -p1 < $(cur_patched)
	rm -f `readlink $(cur_patched)`
	rm -f $(cur_patched)

# these below targets must be the same as the variable name prefixed by has_
# otherwise below compat_patch: target will not work
has_14to19_patch: $(14to19_patch)
	echo "Patching source code for linux-2.6.14-19 ..."
	if [ -e $(cur_patched) ]; then \
		make -C . clean; \
	fi
	patch -p1 < $(14to19_patch)
	cp $(14to19_patch) $@
	ln -s $@ $(cur_patched)

has_20to21_patch: $(20to21_patch)
	echo "Patching source code for linux-2.6.20-21 ..."
	if [ -e $(cur_patched) ]; then \
		make -C . clean; \
	fi
	patch -p1 < $(20to21_patch)
	cp $(20to21_patch) $@
	ln -s $@ $(cur_patched)

has_24_patch: $(24_patch)
	echo "Patching source code for linux-2.6.24 ..."
	if [ -e $(cur_patched) ]; then \
		make -C . clean; \
	fi
	patch -p1 < $(24_patch)
	cp $(24_patch) $@
	ln -s $@ $(cur_patched)

# ============ END code for kernel_check and source patching =================

clean: $(unpatch_code)
	$(KBUILD_BASE) clean
	rm -f Module.symvers

## The folowing compat_patch target is what we need to do to prepare a clean
# compat_patch set after new code is check-in to svn. To keep patches fuzzless.
# the new patches are writen into .new files so svn diff of next file will
# not trip on them.
compat_patch: $(unpatch_code)
	test -z "$(svn diff|head)" || { \
		echo "please run make compat_patch after changse are submited to svn"; \
		exit 1; \
	}
	for the_patch in all_patches ; do \
		make -C . has_$(the_patch); \
		svn diff > ${!the_patch}.new; \
	done

# the following is only for convienience
# do not submit to Linus
# it's also called from the toplevel makefile

# INSTALL_MOD_DIR is set so that the drivers go into the correct location using Kbuild
# it defaults to 'extra' otherwise
INSTALL_MOD_DIR ?= kernel/drivers/scsi

# this allows packaging of modules
ifdef DESTDIR
INSTALL_MOD_PATH=$(DESTDIR)
else
INSTALL_MOD_PATH=
endif

# this evil rule ensures that the modules get build if you specify $(ko)
# as a dependancy.
ko = $(patsubst %.o,%.ko,$(obj-m))
$(ko): all

# now the actual command
install_kernel: $(ko)
	$(KBUILD_BASE) modules_install INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH)

dpkg_divert:
	for module in $(ko) ; do \
		dpkg-divert --rename /lib/modules/$(KERNELRELEASE)/$(INSTALL_MOD_DIR)/$$module ; \
	done

# vim: ft=make tw=72 sw=4 ts=4: