3 ############################################################################
5 # Script for converting the SCST source tree as it exists in the Subversion
6 # repository to a Linux kernel patch.
8 # Copyright (C) 2008 Bart Van Assche <bart.vanassche@gmail.com>
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation, version 2
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 ############################################################################
22 ########################
23 # Function definitions #
24 ########################
27 echo "Usage: $0 [-m] [-q] <kernel version>."
30 # Convert an existing patch.
31 # $1: path of patch to be added.
32 # $2: path in kernel tree of file to be patched.
34 if [ ! -e "$1" ]; then
35 echo "Error: could not find $1." >&2
39 sed -e "s:^--- [^ ]*:--- orig/linux-${kernel_version}/$2:" \
40 -e "s:^+++ [^ ]*:+++ linux-${kernel_version}/$2:" \
44 # Generate a patch for a file to be added to the kernel source tree, and strip
45 # trailing whitespace from C source files while converting the file to patch
47 # $1: path of file to be added.
48 # $2: path in kernel tree where file should be added.
52 if [ ! -e "$1" ]; then
53 echo "Error: could not find $1." >&2
57 # Only include files that were not generated by the build process
59 if [ "$1" = "${1%.mod.c}" -a "$1" ]; then
61 diff -uprN orig/linux-${kernel_version}/$2 linux-${kernel_version}/$2
62 --- orig/linux-${kernel_version}/$2
63 +++ linux-${kernel_version}/$2
64 @@ -0,0 +1,$(wc -l "$1" | { read a b; echo $a; }) @@
66 if [ "${2%.[ch]}" != "$2" ]; then
67 sed -e 's/^ \([^ ]*:\)$/\1/' -e 's/^/+/' < "$1"
69 sed -e 's/^/+/' < "$1"
75 #########################
76 # Argument verification #
77 #########################
82 if [ ! -e scst -o ! -e iscsi-scst -o ! -e srpt ]; then
83 echo "Please run this script from inside the SCST subversion source tree."
87 set -- $(/usr/bin/getopt mq "$@")
88 while [ "$1" != "${1#-}" ]
91 '-m') mpt_scst="true"; shift;;
92 '-q') qla2x00t="true"; shift;;
110 "scst/kernel/scst_exec_req_fifo-${kernel_version}.patch" \
111 "iscsi-scst/kernel/patches/put_page_callback-${kernel_version}.patch" \
114 for p in "${kpatch[@]}"
116 if [ ! -e "$p" ]; then
117 echo "Error: kernel version ${kernel_version} is not supported by SCST."
118 echo "(could not find file $p)."
124 # Redirect the output of all subsequent commands to the specialize-patch script
126 trap "rm -f ${fifo}" EXIT
127 fifo=/tmp/generate-kernel-patch-fifo.$$
130 "$(dirname $0)/specialize-patch" -v kernel_version="${kernel_version}" \
134 # General kernel patches.
139 # Directory include/scst/
141 # Make sure the file iscsi-scst/iscsi_scst_itf_ver.h is up to date.
142 make -s -C iscsi-scst include/iscsi_scst_itf_ver.h
144 for f in scst/include/*h
146 add_file "${f}" "include/scst/${f#scst/include/}"
149 for f in iscsi-scst/include/*h
151 add_file "${f}" "include/scst/${f#iscsi-scst/include/}"
157 add_patch "scst/kernel/in-tree/Kconfig.drivers.Linux-${kernel_version}.patch" \
160 add_patch "scst/kernel/in-tree/Makefile.drivers.Linux-${kernel_version}.patch"\
164 # Directory drivers/scst/
166 add_file "scst/kernel/in-tree/Kconfig.scst" "drivers/scst/Kconfig"
168 add_file "scst/kernel/in-tree/Makefile.scst" "drivers/scst/Makefile"
170 add_file "scst/README" "Documentation/scst/README.scst"
172 for f in scst/src/*.[ch]
174 add_file "${f}" "drivers/scst/${f#scst/src/}"
178 # Directory drivers/scst/dev_handlers/
180 add_file "scst/kernel/in-tree/Makefile.dev_handlers" \
181 "drivers/scst/dev_handlers/Makefile"
183 for f in scst/src/dev_handlers/*.[ch]
185 add_file "${f}" "drivers/scst/dev_handlers/${f#scst/src/dev_handlers/}"
189 # Directory drivers/scst/iscsi-scst/
191 add_file "iscsi-scst/kernel/Makefile.in-kernel" \
192 "drivers/scst/iscsi-scst/Makefile"
194 add_file "iscsi-scst/kernel/Kconfig" "drivers/scst/iscsi-scst/Kconfig"
196 add_file "iscsi-scst/README" "Documentation/scst/README.iscsi"
198 for f in iscsi-scst/kernel/*.[ch]
200 add_file "${f}" "drivers/scst/iscsi-scst/${f#iscsi-scst/kernel/}"
204 # Directory drivers/scst/qla2x00-target/
206 if [ "${qla2x00t}" = "true" ]; then
208 #add_file "qla2x00t/qla2x00-target/Makefile.in-kernel" \
209 # "drivers/scst/qla2x00-target/Makefile"
211 #add_file "qla2x00t/qla2x00-target/Kconfig" \
212 # "drivers/scst/qla2x00-target/Kconfig"
214 add_file "qla2x00t/qla2x_tgt_def.h" \
215 "drivers/scst/qla2x00-target/qla2x_tgt_def.h"
217 add_file "qla2x00t/qla2x00-target/README" \
218 "Documentation/scst/README.qla2x00t"
220 for f in qla2x00t/qla2x00-target/*.[ch]
222 add_file "${f}" "drivers/scst/qla2x00-target/${f#qla2x00t/qla2x00-target/}"
228 # Directory drivers/infiniband/ulp/srpt/
230 add_patch "srpt/src/Kconfig.infiniband.Linux-${kernel_version}.patch" \
231 "drivers/infiniband/Kconfig"
233 add_patch "srpt/src/Makefile.infiniband.Linux-${kernel_version}.patch" \
234 "drivers/infiniband/Makefile"
236 add_file "srpt/src/Kconfig" "drivers/infiniband/ulp/srpt/Kconfig"
238 add_file "srpt/src/Makefile.in_kernel" "drivers/infiniband/ulp/srpt/Makefile"
240 add_file "srpt/README" "Documentation/scst/README.srpt"
242 for f in srpt/src/*.[ch]
244 add_file "${f}" "drivers/infiniband/ulp/srpt/${f#srpt/src/}"
248 # Directory drivers/message/fusion/mpt_scst
250 if [ "$mpt_scst" = "true" ]; then
252 add_patch "mpt/in-tree/Kconfig-2.6.24.diff" "drivers/message/fusion/Kconfig"
254 add_patch "mpt/in-tree/Makefile.diff" "drivers/message/fusion/Makefile"
256 add_file "mpt/Makefile" "drivers/message/fusion/mpt_scst/Makefile"
258 add_file "mpt/Kconfig" "drivers/message/fusion/mpt_scst/Kconfig"
262 add_file "${f}" "drivers/message/fusion/mpt_scst/${f#mpt/}"