#!/bin/bash ############################################################################ # # Script for converting the SCST source tree as it exists in the Subversion # repository to a Linux kernel patch. # # Copyright (C) 2008 Bart Van Assche # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation, version 2 # of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ############################################################################ ######################## # Function definitions # ######################## # Convert an existing patch. # $1: path of patch to be added. # $2: path in kernel tree of file to be patched. function add_patch { if [ ! -e "$1" ]; then echo "Error: could not find $1." >&2 exit 1 fi sed -e "s:^--- [^ ]*:--- orig/$2:" -e "s:^+++ [^ ]*:+++ $2:" < "$1" } # Generate a patch for a file to be added to the kernel source tree, and strip # trailing whitespace from C source files while converting the file to patch # format. # $1: path of file to be added. # $2: path in kernel tree where file should be added. function add_file { local a b if [ ! -e "$1" ]; then echo "Error: could not find $1." >&2 exit 1 fi # Skip any files generated by the kernel build process (*.mod.c). if [ "${1%.mod.c}" != "$1" ]; then return 0; fi cat <." exit 1 fi #################### # Patch Generation # #################### kernel_version="$1" kpatch=( \ "scst/kernel/scst_exec_req_fifo-${kernel_version}.patch" \ "iscsi-scst/kernel/patches/put_page_callback-${kernel_version}.patch" \ ) for p in "${kpatch[@]}" do if [ ! -e "$p" ]; then echo "Error: kernel version ${kernel_version} is not supported by SCST." echo "(could not find file $p)." exit 1 fi >&2 done # General kernel patches. for p in "${kpatch[@]}" do cat "$p" echo '' echo '' done # Directory include/scst/ for f in scst/include/*h do add_file "${f}" "linux-${kernel_version}/include/scst/${f#scst/include/}" done for f in iscsi-scst/include/*h do add_file "${f}" "linux-${kernel_version}/include/scst/${f#iscsi-scst/include/}" done # Directory drivers/ add_patch "scst/kernel/in-tree/Kconfig.drivers.Linux-${kernel_version}.patch" \ "linux-${kernel_version}/drivers/Kconfig" add_patch "scst/kernel/in-tree/Makefile.drivers.Linux-${kernel_version}.patch"\ "linux-${kernel_version}/drivers/Makefile" # Directory drivers/scst/ add_file "scst/kernel/in-tree/Kconfig.scst" \ "linux-${kernel_version}/drivers/scst/Kconfig" add_file "scst/kernel/in-tree/Makefile.scst" \ "linux-${kernel_version}/drivers/scst/Makefile" for f in scst/src/*.[ch] do add_file ${f} linux-${kernel_version}/drivers/scst/${f#scst/src/} echo '' echo '' done # Directory drivers/scst/dev_handlers/ add_file "scst/kernel/in-tree/Makefile.dev_handlers" \ "linux-${kernel_version}/drivers/scst/dev_handlers/Makefile" for f in scst/src/dev_handlers/*.[ch] do add_file ${f} linux-${kernel_version}/drivers/scst/dev_handlers/${f#scst/src/dev_handlers/} echo '' echo '' done # Directory drivers/scst/iscsi-scst/ add_file "iscsi-scst/kernel/Makefile.in-kernel" \ "linux-${kernel_version}/drivers/scst/iscsi-scst/Makefile" add_file "iscsi-scst/kernel/Kconfig" \ "linux-${kernel_version}/drivers/scst/iscsi-scst/Kconfig" for f in iscsi-scst/kernel/*.[ch] do add_file "${f}" \ "linux-${kernel_version}/drivers/scst/iscsi-scst/${f#iscsi-scst/kernel/}" echo '' echo '' done # Directory drivers/scst/qla2x00-target/ if false; then add_file "qla2x00t/qla2x00-target/Makefile.in-kernel" \ "linux-${kernel_version}/drivers/scst/qla2x00-target/Makefile" add_file "qla2x00t/qla2x00-target/Kconfig" \ "linux-${kernel_version}/drivers/scst/qla2x00-target/Kconfig" add_file "qla2x00t/qla2x_tgt_def.h" \ "linux-${kernel_version}/drivers/scst/qla2x00-target/qla2x_tgt_def.h" for f in qla2x00t/qla2x00-target/*.[ch] do add_file "${f}" \ "linux-${kernel_version}/drivers/scst/qla2x00-target/${f#qla2x00t/qla2x00-target/}" echo '' echo '' done fi # Directory drivers/infiniband/ulp/srpt/ add_patch "srpt/src/Kconfig.infiniband.Linux-${kernel_version}.patch" \ "linux-${kernel_version}/drivers/infiniband/Kconfig" add_patch "srpt/src/Makefile.infiniband.Linux-${kernel_version}.patch" \ "linux-${kernel_version}/drivers/infiniband/Makefile" add_file "srpt/src/Kconfig" "drivers/infiniband/ulp/srpt/Kconfig" add_file "srpt/src/Makefile.in_kernel" "drivers/infiniband/ulp/srpt/Makefile" for f in srpt/src/*.[ch] do add_file ${f} linux-${kernel_version}/drivers/infiniband/ulp/srpt/${f#srpt/src/} echo '' echo '' done