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 ########################
26 # Convert an existing patch.
27 # $1: path of patch to be added.
28 # $2: path in kernel tree of file to be patched.
30 if [ ! -e "$1" ]; then
31 echo "Error: could not find $1." >&2
35 sed -e "s:^--- [^ ]*:--- orig/linux-${kernel_version}/$2:" \
36 -e "s:^+++ [^ ]*:+++ linux-${kernel_version}/$2:" \
40 # Generate a patch for a file to be added to the kernel source tree, and strip
41 # trailing whitespace from C source files while converting the file to patch
43 # $1: path of file to be added.
44 # $2: path in kernel tree where file should be added.
48 if [ ! -e "$1" ]; then
49 echo "Error: could not find $1." >&2
53 # Only include files that were not generated by the build process
55 if [ "$1" = "${1%.mod.c}" -a "$1" ]; then
57 diff -uprN orig/linux-${kernel_version}/$2 linux-${kernel_version}/$2
58 --- orig/linux-${kernel_version}/$2
59 +++ linux-${kernel_version}/$2
60 @@ -0,0 +1,$(wc -l "$1" | { read a b; echo $a; }) @@
62 if [ "${2%.[ch]}" != "$2" ]; then
63 sed -e 's/^ \([^ ]*:\)$/\1/' -e 's/^/+/' < "$1"
65 sed -e 's/^/+/' < "$1"
71 #########################
72 # Argument verification #
73 #########################
75 if [ ! -e scst -o ! -e iscsi-scst -o ! -e srpt ]; then
76 echo "Please run this script from inside the SCST subversion source tree."
81 echo "Usage: $0 <kernel version>."
92 "scst/kernel/scst_exec_req_fifo-${kernel_version}.patch" \
93 "iscsi-scst/kernel/patches/put_page_callback-${kernel_version}.patch" \
96 for p in "${kpatch[@]}"
98 if [ ! -e "$p" ]; then
99 echo "Error: kernel version ${kernel_version} is not supported by SCST."
100 echo "(could not find file $p)."
106 # Redirect the output of all subsequent commands to the specialize-patch script
108 trap "rm -f ${fifo}" EXIT
109 fifo=/tmp/generate-kernel-patch-fifo.$$
112 "$(dirname $0)/specialize-patch" -v kernel_version="${kernel_version}" \
116 # General kernel patches.
121 # Directory include/scst/
123 # Make sure the file iscsi-scst/iscsi_scst_itf_ver.h is up to date.
124 make -s -C iscsi-scst include/iscsi_scst_itf_ver.h
126 for f in scst/include/*h
128 add_file "${f}" "include/scst/${f#scst/include/}"
131 for f in iscsi-scst/include/*h
133 add_file "${f}" "include/scst/${f#iscsi-scst/include/}"
139 add_patch "scst/kernel/in-tree/Kconfig.drivers.Linux-${kernel_version}.patch" \
142 add_patch "scst/kernel/in-tree/Makefile.drivers.Linux-${kernel_version}.patch"\
146 # Directory drivers/scst/
148 add_file "scst/kernel/in-tree/Kconfig.scst" "drivers/scst/Kconfig"
150 add_file "scst/kernel/in-tree/Makefile.scst" "drivers/scst/Makefile"
152 add_file "scst/README" "Documentation/scst/README.scst"
154 for f in scst/src/*.[ch]
156 add_file "${f}" "drivers/scst/${f#scst/src/}"
160 # Directory drivers/scst/dev_handlers/
162 add_file "scst/kernel/in-tree/Makefile.dev_handlers" \
163 "drivers/scst/dev_handlers/Makefile"
165 for f in scst/src/dev_handlers/*.[ch]
167 add_file "${f}" "drivers/scst/dev_handlers/${f#scst/src/dev_handlers/}"
171 # Directory drivers/scst/iscsi-scst/
173 add_file "iscsi-scst/kernel/Makefile.in-kernel" \
174 "drivers/scst/iscsi-scst/Makefile"
176 add_file "iscsi-scst/kernel/Kconfig" "drivers/scst/iscsi-scst/Kconfig"
178 add_file "iscsi-scst/README" "Documentation/scst/README.iscsi"
180 for f in iscsi-scst/kernel/*.[ch]
182 add_file "${f}" "drivers/scst/iscsi-scst/${f#iscsi-scst/kernel/}"
186 # Directory drivers/scst/qla2x00-target/
190 add_file "qla2x00t/qla2x00-target/Makefile.in-kernel" \
191 "drivers/scst/qla2x00-target/Makefile"
193 add_file "qla2x00t/qla2x00-target/Kconfig" \
194 "drivers/scst/qla2x00-target/Kconfig"
196 add_file "qla2x00t/qla2x_tgt_def.h" \
197 "drivers/scst/qla2x00-target/qla2x_tgt_def.h"
199 add_file "qla2x00t/qla2x00-target/README" \
200 "Documentation/scst/README.qla2x00t"
202 for f in qla2x00t/qla2x00-target/*.[ch]
204 add_file "${f}" "drivers/scst/qla2x00-target/${f#qla2x00t/qla2x00-target/}"
210 # Directory drivers/infiniband/ulp/srpt/
212 add_patch "srpt/src/Kconfig.infiniband.Linux-${kernel_version}.patch" \
213 "drivers/infiniband/Kconfig"
215 add_patch "srpt/src/Makefile.infiniband.Linux-${kernel_version}.patch" \
216 "drivers/infiniband/Makefile"
218 add_file "srpt/src/Kconfig" "drivers/infiniband/ulp/srpt/Kconfig"
220 add_file "srpt/src/Makefile.in_kernel" "drivers/infiniband/ulp/srpt/Makefile"
222 add_file "srpt/README" "Documentation/scst/README.srpt"
224 for f in srpt/src/*.[ch]
226 add_file "${f}" "drivers/infiniband/ulp/srpt/${f#srpt/src/}"