diff --git a/scripts/filter-trace-entry-exit b/scripts/filter-trace-entry-exit index 6d9c49dd3..0ce861cc1 100755 --- a/scripts/filter-trace-entry-exit +++ b/scripts/filter-trace-entry-exit @@ -23,6 +23,9 @@ function categorize_line(line) { is_blank = 0 is_trace_entry = 0 is_trace_exit = 0 + is_label = 0 + is_return_void = 0 + is_brace_at_start_of_line = 0 if (line ~ "^+$") is_blank = 1 else if (line ~ "^+\tTRACE_ENTRY\\(\\);$") @@ -31,6 +34,12 @@ function categorize_line(line) { || line ~ "^+\tTRACE_EXIT_RES\\(.*\\);$" \ || line ~ "^+\tTRACE_EXIT_HRES\\(.*\\);$") is_trace_exit = 1 + else if (line ~ ":$") + is_label = 1 + else if (line ~ "^+\treturn;$") + is_return_void = 1 + else if (line ~ "^+}$") + is_brace_at_start_of_line = 1 } # Leave out TRACE_ENTRY() and the blank line below it and also TRACE_EXIT() @@ -39,10 +48,14 @@ function print_conditionally() { if (previous_is_trace_entry \ || (before_previous_is_trace_entry && previous_is_blank) \ || previous_is_trace_exit \ - || (previous_is_blank && is_trace_exit)) + || (previous_is_blank && is_trace_exit) \ + || (!before_previous_is_label \ + && previous_is_return_void \ + && is_brace_at_start_of_line)) { # print "deleted", previous_line lines_deleted++ + reverse_shift_state_variables() } else { @@ -56,9 +69,19 @@ function shift_state_variables(line) { before_previous_is_blank = previous_is_blank before_previous_is_trace_entry = previous_is_trace_entry before_previous_is_trace_exit = previous_is_trace_exit + before_previous_is_label = previous_is_label previous_is_blank = is_blank previous_is_trace_entry = is_trace_entry previous_is_trace_exit = is_trace_exit + previous_is_label = is_label + previous_is_return_void = is_return_void +} + +function reverse_shift_state_variables() { + previous_is_blank = before_previous_is_blank + previous_is_trace_entry = before_previous_is_trace_entry + previous_is_trace_exit = before_previous_is_trace_exit + previous_is_label = before_previous_is_label } function reset_hunk_state_variables() { @@ -68,9 +91,12 @@ function reset_hunk_state_variables() { before_previous_is_blank = 0 before_previous_is_trace_entry = 0 before_previous_is_trace_exit = 0 + before_previous_is_label = 0 previous_is_blank = 0 previous_is_trace_entry = 0 previous_is_trace_exit = 0 + previous_is_label = 0 + previous_is_return_void = 0 } function dump_lines() { @@ -130,3 +156,8 @@ END { print_conditionally() dump_lines() } + +# Local variables: +# indent-tabs-mode: nil +# c-basic-offset: 2 +# End: diff --git a/scripts/generate-kernel-patch b/scripts/generate-kernel-patch index d7a23c4a0..59bd22cd7 100755 --- a/scripts/generate-kernel-patch +++ b/scripts/generate-kernel-patch @@ -23,6 +23,8 @@ # Function definitions # ######################## +source $(dirname $0)/kernel-version + function usage { echo "Usage: $0 [-d] [-h] [-m] [-n] [-p ] [-s] [-u] " echo "where: " @@ -45,8 +47,8 @@ function add_patch { exit 1 fi - sed -e "s:^--- [^ ]*:--- orig/linux-${kernel_version}/$2:" \ - -e "s:^+++ [^ ]*:+++ linux-${kernel_version}/$2:" \ + sed -e "s:^--- [^ ]*:--- orig/linux-${kver}/$2:" \ + -e "s:^+++ [^ ]*:+++ linux-${kver}/$2:" \ < "$1" } @@ -67,9 +69,9 @@ function add_file { # -- skip *.mod.c. if [ "$1" = "${1%.mod.c}" -a "$1" ]; then cat <"${tmp_Kconfig}" add_file "${tmp_Kconfig}" "drivers/scst/Kconfig" -tmp_Makefile="${tmpdir}/Makefile.scst-${kernel_version}" -cat "scst/kernel/in-tree/Makefile.scst-${kernel_version}" | \ +tmp_Makefile="${tmpdir}/Makefile.scst-${kver}" +cat "scst/kernel/in-tree/Makefile.scst-${kver}" | \ if [ "${generating_upstream_patch}" = "true" ]; then grep -v 'scst_proc' else @@ -371,7 +368,7 @@ done # Directory drivers/scst/dev_handlers/ -add_file "scst/kernel/in-tree/Makefile.dev_handlers-${kernel_version}" \ +add_file "scst/kernel/in-tree/Makefile.dev_handlers-${kver}" \ "drivers/scst/dev_handlers/Makefile" \ | process_patch "scst_11_dev_handlers_makefile.diff" @@ -460,7 +457,7 @@ if [ "${qla2x00t}" = "true" ]; then add_file "qla2x00t/qla2x_tgt_def.h" \ "drivers/scsi/qla2xxx/qla2x_tgt_def.h" - add_file "qla2x00t/qla2x00-target/Makefile_in-tree-${kernel_version}" \ + add_file "qla2x00t/qla2x00-target/Makefile_in-tree-${kver}" \ "drivers/scst/qla2xxx-target/Makefile" add_file "qla2x00t/qla2x00-target/Kconfig" \ @@ -558,7 +555,7 @@ fi add_file "scst_local/in-tree/Kconfig" "drivers/scst/scst_local/Kconfig" - add_file "scst_local/in-tree/Makefile-${kernel_version}" "drivers/scst/scst_local/Makefile" + add_file "scst_local/in-tree/Makefile-${kver}" "drivers/scst/scst_local/Makefile" add_file "scst_local/scst_local.c" "drivers/scst/scst_local/scst_local.c" ) \ @@ -569,8 +566,8 @@ fi # Directory drivers/scsi/ibmvstgt { - ( cd ibmvstgt && ./generate-in-tree-patches "${kernel_version}" ) - if [ -e "ibmvstgt/in-tree-patches/${kernel_version}" ]; then + ( cd ibmvstgt && ./generate-in-tree-patches "${kver}" ) + if [ -e "ibmvstgt/in-tree-patches/${kver}" ]; then if [ "${multiple_patches}" = "true" ]; then cat < +# +# 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. +# +############################################################################ + +############################################################################ +# +# The recommended way to use this script is as follows: +# - Create an additional user, e.g. builder +# - Add a line to the sudoers file that allows that user to invoke yum and +# yum-builddep. +# - Add the source repositories in /etc/yum.repos.d. +# - One way to do that is by invoking the following shell commands as root: +# useradd builder +# echo 'builder ALL=(ALL) NOPASSWD: /usr/bin/yum, /usr/bin/yum-builddep' >>/etc/sudoers +# visudo -sc +# +# For more information about building a custom RHEL / CentOS / Scientific Linux +# kernel RPM, see also: +# * CentOS wiki, "I Need to Build a Custom Kernel" +# (http://wiki.centos.org/HowTos/Custom_Kernel). +# * Fedora wiki, "Building a custom kernel" +# (http://fedoraproject.org/wiki/Building_a_custom_kernel). +# +############################################################################ + +scst_dir="$(dirname "$(dirname "$0")")" +downloaddir=$HOME/software/downloads +rpmbuild_dir=$HOME/rpmbuild +if [ "$1" = "" ]; then + kernel="kernel-$(uname -r)" +else + kernel="$1" +fi +arch="$(uname -m)" +kernel="${kernel%.${arch}}" +kernel_src_rpm="${kernel}.src.rpm" +kver="${kernel#kernel-}" +distro="$(sed -n -e 's/^\(.*\) release .*$/\1/p' /etc/issue)" +releasever="$(sed -n -e 's/^.* release \([0-9.]*\) .*$/\1/p' /etc/issue)" +releasevermajor="$(echo $releasever | cut -f1 -d.)" +releaseverminor="$(echo $releasever | cut -f2 -d.)" +case "$distro" in + "CentOS"*) + if [ $releasevermajor = 5 ]; then + srpm_url=("http://vault.centos.org/${releasever}/os/SRPMS" "http://vault.centos.org/${releasever}/updates/SRPMS") + else + srpm_url=("http://mirror.centos.org/centos/${releasever}/os/SRPMS/Packages" "http://mirror.centos.org/centos/${releasever}/updates/SRPMS") + fi + ;; + "Red Hat Enterprise Linux"*) + srpm_url=("http://ftp.redhat.com/pub/redhat/linux/enterprise/${releasevermajor}Server/en/os/SRPMS") + ;; + "Scientific Linux") + if [ "$releasevermajor" = 6 ]; then + srpm_url=("http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor") + else + srpm_url=("http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor") + fi + ;; + *) + echo "Unknown type of distribution: $distro" + exit 1 + ;; +esac + +function log { + echo + echo "$@" + echo +} + +function copy_patch { + local p="$1" + while [ ! -e "$p" ] + do + local q="$(echo "$p" | sed 's/[.-][a-z0-9]*\.patch$/.patch/')" + if [ "$q" = "$p" ]; then + break; + fi + p="$q" + done + if [ ! -e "$p" ]; then + echo "Error: patch $1 not found" + echo "Please report this on the scst-devel mailing list" + exit 1 + fi + ln -s "$p" "$2" +} + +if [ -e ${rpmbuild_dir} ]; then + echo "You have to remove the ${rpmbuild_dir} directory before starting $0" + exit 1 +fi + +if [ ! -e "${scst_dir}" ]; then + echo "Error: directory ${scst_dir} not found. Please modify scst_dir in $0." + exit 1 +fi + +log "Installing prerequisites" + +sudo yum install -y -q asciidoc binutils-devel elfutils-libelf-devel hmaccalc ncurses-devel newt-devel patchutils 'perl(ExtUtils::Embed)' python-devel redhat-rpm-config rpmdevtools rng-tools rpm-build unifdef xmlto yum-utils zlib-devel + +rc=$?; if [ $rc != 0 ]; then exit $rc; fi + +log "Creating directory ${rpmbuild_dir}" + +mkdir -p ${rpmbuild_dir}/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + +log "Updating ~/.rpmmacros" + +if [ -e ~/.rpmmacros ]; then + cp ~/.rpmmacros ~/.rpmmacros.tmp +else + touch ~/.rpmmacros.tmp +fi +{ cat ~/.rpmmacros.tmp | grep -v '^%_topdir '; \ + echo "%_topdir ${rpmbuild_dir}"; } > ~/.rpmmacros +rm -f ~/.rpmmacros.tmp + +log "Installing, unpacking and preparing kernel source files" + +mkdir -p ${downloaddir} +if [ ! -e ${downloaddir}/${kernel_src_rpm} ]; then + cd ${downloaddir} + for dir in ${srpm_url[@]} + do + url="$dir/${kernel_src_rpm}" + echo "Trying $url ..." + if wget -q "$url"; then + break + fi + done + if [ ! -e ${downloaddir}/${kernel_src_rpm} ]; then + echo "Downloading kernel source failed. Has the yum source repository been configured in /etc/yum.repos.d ?" + exit 1 + fi +fi + +log "Installing kernel build prerequisites" + +sudo yum-builddep -q -y ${downloaddir}/${kernel_src_rpm} + +log "Installing kernel sources in ${rpmbuild_dir}" + +cd ${rpmbuild_dir} +{ rpm -i ${downloaddir}/${kernel_src_rpm} 2>&1 \ + | grep -v ' does not exist'; } +cd SPECS +{ rpmbuild -bp --target=${arch} kernel*.spec; \ + rc=$?; if [ rc != 0 ]; then exit $rc; fi; } 2>&1 \ + | tee prep-err.log + +log "Copying SCST patches to the SOURCES directory" + +cd ${rpmbuild_dir}/SOURCES +copy_patch $scst_dir/scst/kernel/rhel/scst_exec_req_fifo-${kver}.patch scst_exec_req_fifo.patch +copy_patch $scst_dir/iscsi-scst/kernel/patches/rhel/put_page_callback-${kver}.patch put_page_callback.patch + +log "Adding SCST patches in kernel.spec" + +if [ ${kver#2.6.18} != $kver ]; then +if [ -e ${rpmbuild_dir}/SPECS/kernel-2.6.spec ]; then +# RHEL/CentOS/SL 5.6 +patch -p1 ${rpmbuild_dir}/SPECS/kernel-2.6.spec <<'EOF' || exit $? +diff -u SPECS/kernel-2.6.spec{.orig,} +--- SPECS/kernel-2.6.spec.orig ++++ SPECS/kernel-2.6.spec +@@ -6386,6 +6386,9 @@ + # empty final patch file to facilitate testing of kernel patches + Patch99999: linux-kernel-test.patch + ++Patch200: scst_exec_req_fifo.patch ++Patch201: put_page_callback.patch ++ + # END OF PATCH DEFINITIONS + + BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root +@@ -12593,6 +12596,9 @@ + rm -f kernel-%{kversion}-*-debug.config + %endif + ++%patch200 -p1 ++%patch201 -p1 ++ + # now run oldconfig over all the config files + for i in *.config + do +EOF +else +# RHEL/CentOS/SL 5.7 +patch -p1 ${rpmbuild_dir}/SPECS/kernel.spec <<'EOF' || exit $? +--- SPECS/kernel.spec.orig ++++ SPECS/kernel.spec +@@ -425,6 +425,9 @@ + Patch2: xen-config-2.6.18-redhat.patch + Patch3: xen-2.6.18-redhat.patch + ++Patch200: scst_exec_req_fifo.patch ++Patch201: put_page_callback.patch ++ + # empty final patch file to facilitate testing of kernel patches + Patch99999: linux-kernel-test.patch + +@@ -733,6 +736,9 @@ + rm -f kernel-%{version}-*-debug.config + %endif + ++%patch200 -p1 ++%patch201 -p1 ++ + # now run oldconfig over all the config files + for i in *.config + do +EOF +fi +elif [ ${kver#2.6.32-71} != $kver ]; then +# RHEL/CentOS/SL 6.0 +patch -p1 ${rpmbuild_dir}/SPECS/kernel.spec <<'EOF' || exit $? +diff -u SPECS/kernel.spec{.orig,} +--- SPECS/kernel.spec.orig ++++ SPECS/kernel.spec +@@ -601,6 +601,9 @@ + Source82: config-s390x-debug + Source83: config-s390x-debug-rhel + ++Patch200: scst_exec_req_fifo.patch ++Patch201: put_page_callback.patch ++ + # empty final patch file to facilitate testing of kernel patches + Patch999999: linux-kernel-test.patch + +@@ -891,6 +894,9 @@ + # Dynamically generate kernel .config files from config-* files + make -f %{SOURCE20} VERSION=%{version} configs + ++ApplyPatch scst_exec_req_fifo.patch ++ApplyPatch put_page_callback.patch ++ + ApplyOptionalPatch linux-kernel-test.patch + + # Any further pre-build tree manipulations happen here. +@@ -917,6 +923,7 @@ + for i in *.config + do + mv $i .config ++ echo "CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION=y" >> .config + Arch=`head -1 .config | cut -b 3-` + make ARCH=$Arch %{oldconfig_target} > /dev/null + echo "# $Arch" > configs/$i +EOF +elif [ ${kver#2.6.32-131} != $kver ]; then +# RHEL/CentOS/SL 6.1 +patch -p1 ${rpmbuild_dir}/SPECS/kernel.spec <<'EOF' || exit $? +# RHEL/CentOS/SL 6.x +diff -u SPECS/kernel.spec{.orig,} +--- SPECS/kernel.spec.orig ++++ SPECS/kernel.spec +@@ -601,6 +601,9 @@ + Source82: config-generic + Source83: config-x86_64-debug-rhel + ++Patch200: scst_exec_req_fifo.patch ++Patch201: put_page_callback.patch ++ + # empty final patch file to facilitate testing of kernel patches + Patch999999: linux-kernel-test.patch + +@@ -891,6 +894,9 @@ + # Dynamically generate kernel .config files from config-* files + make -f %{SOURCE20} VERSION=%{version} configs + ++ApplyPatch scst_exec_req_fifo.patch ++ApplyPatch put_page_callback.patch ++ + ApplyOptionalPatch linux-kernel-test.patch + + # Any further pre-build tree manipulations happen here. +@@ -917,6 +923,7 @@ + for i in *.config + do + mv $i .config ++ echo "CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION=y" >> .config + Arch=`head -1 .config | cut -b 3-` + make ARCH=$Arch %{oldconfig_target} > /dev/null + echo "# $Arch" > configs/$i +EOF +fi + +log "Rebuilding kernel" + +cd ${rpmbuild_dir}/SPECS +{ rpmbuild -bb --target=${arch} --with baseonly --with firmware --without kabichk kernel*.spec; rc=$?; if [ $rc != 0 ]; then exit $rc; fi; } 2>&1 \ + | tee build.log + + +log "Ready. You can now install the freshly built kernel RPM as follows:\n"\ + "sudo rpm -ivh --force $HOME/rpmbuild/RPMS/${arch}/kernel-*.rpm" diff --git a/scripts/run-regression-tests b/scripts/run-regression-tests index 8e067e8b3..7fb0575ce 100755 --- a/scripts/run-regression-tests +++ b/scripts/run-regression-tests @@ -27,7 +27,7 @@ # - Duplicates the entire source tree to the temporary directory and # compiles the SCST source code. # - Duplicates the entire source tree to the temporary directory, runs -# 'make debug2release' and again compiles the SCST source code. +# 'make 2release' and again compiles the SCST source code. # - Checks whether the specified kernel version is present # in the directory specified through option -c. # - If the source code of the specified kernel version is not present, @@ -54,6 +54,8 @@ # Function definitions # ######################## +source $(dirname $0)/kernel-version + function usage { echo "Usage: $0 [-c ] [-d ] [-f] [-h] [-j ] [-p ] [-q] ..." echo " -c - cache directory for Linux kernel tarballs." @@ -65,17 +67,6 @@ function usage { echo " ... - kernel versions to test." } -# First three components of the kernel version number. -function kernel_version { - echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/p' -} - -# Last component of the kernel version, or the empty string if $1 has only -# three components. -function patchlevel { - echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\)[.-]\(.*\)$/\2/p' -} - # Create a linux-$1 tree in the current directory, where $1 is a kernel # version number with either three or four components. function extract_kernel_tree { @@ -184,9 +175,9 @@ EOF function test_scst_tree_patches { local rc=0 echo "Testing whether the SCST patches apply cleanly to the SCST tree ..." - for p in *.patch srpt/patches/scst_increase_max_tgt_cmds.patch + for p in *.patch srpt/patches/scst*.patch do - if ! patch -p0 -f --dry-run -s <$p &>/dev/null; then + if [ -e "$p" ] && ! patch -p0 -f --dry-run -s <$p &>/dev/null; then echo "ERROR: patch $p does not apply cleanly." rc=1 fi @@ -219,7 +210,8 @@ function compile_scst_unpatched { if mkdir -p "${workingdirectory}" \ && cd "${workingdirectory}" \ && duplicate_scst_source_tree "${scst}" \ - && (make -s clean \ + && (export KCFLAGS=-DCONFIG_SCST_MEASURE_LATENCY; \ + make -s clean \ && make -s scst iscsi-scst \ && if "${scst_local}" = "true" ; then make -C scst_local clean; fi \ && if "${scst_local}" = "true" ; then make -C scst_local -s ; fi \ @@ -249,7 +241,8 @@ function compile_scst_patched { && cd "${workingdirectory}" \ && duplicate_scst_source_tree "${scst}" \ && make -s "$1" \ - && (make -s clean \ + && (export KCFLAGS=-DCONFIG_SCST_MEASURE_LATENCY; \ + make -s clean \ && make -s scst iscsi-scst \ && if "${scst_local}" = "true" ; then make -C scst_local clean; fi \ && if "${scst_local}" = "true" ; then make -C scst_local -s ; fi \ @@ -284,16 +277,22 @@ function download_file { function download_kernel { local kver="$(kernel_version $1)" local plevel="$(patchlevel $1)" + local series="$1" + if [ "${series:0:2}" = "3." ]; then + series="3.x" + else + series="${series:0:3}" + fi mkdir -p "${kernel_sources}" || return $? test -w "${kernel_sources}" || return $? ( cd "${kernel_sources}" || return $? - download_file "${kernel_mirror}/linux-$(kernel_version $1).tar.bz2" \ + download_file "${kernel_mirror}/v$series/linux-$kver.tar.bz2" \ || return $? if [ "${plevel}" != "" ]; then - download_file "${kernel_mirror}/patch-$1.bz2" \ - || download_file "${kernel_longterm}/v$(kernel_version $1)/patch-$1.bz2" \ + download_file "${kernel_mirror}/v$series/patch-$1.bz2" \ + || download_file "${kernel_longterm}/v$series/longterm/patch-$1.bz2" \ || return $? fi ) @@ -547,8 +546,8 @@ fi # Where to store persistenly downloaded kernel tarballs and kernel patches. kernel_sources="$HOME/software/downloads" # URL for downloading kernel tarballs and kernel patches. -kernel_mirror="ftp://ftp.eu.kernel.org/pub/linux/kernel/v2.6" -kernel_longterm="http://www.kernel.org/pub/linux/kernel/v2.6/longterm" +kernel_mirror="ftp://ftp.kernel.org/pub/linux/kernel" +kernel_longterm="http://www.kernel.org/pub/linux/kernel" kernel_versions="" # Directory in which the regression test output files will be stored. Must be # an absolute path. @@ -615,8 +614,8 @@ fi test_scst_tree_patches || exit $? if [ "${run_local_compilation}" = "true" ]; then compile_scst_unpatched || exit $? - compile_scst_patched debug2release || exit $? - compile_scst_patched debug2perf || exit $? + compile_scst_patched 2release || exit $? + compile_scst_patched 2perf || exit $? compile_scst_patched enable_proc || exit $? fi diff --git a/scripts/specialize-patch b/scripts/specialize-patch index 0737325cd..ee06c5989 100755 --- a/scripts/specialize-patch +++ b/scripts/specialize-patch @@ -31,7 +31,8 @@ # the KERNEL_VERSION() macro. function version_code(kver, array) { - match(kver, "([0-9]+).([0-9]+).([0-9]+)", array) + if (!match(kver, "([0-9]+).([0-9]+).([0-9]+)", array)) + match(kver, "([0-9]+).([0-9]+)", array) return 65536*array[1] + 256*array[2] + array[3] } @@ -59,7 +60,7 @@ function evaluate(stmnt, pattern, arg, op, result) { if (match(stmnt, "^+#ifndef (.*)$", arg)) { - stmnt = "+#if ! defined(" arg[1] ")" + stmnt = "+#if !defined(" arg[1] ")" } gsub("LINUX_VERSION_CODE", LINUX_VERSION_CODE, stmnt) @@ -165,8 +166,8 @@ function evaluate(stmnt, pattern, arg, op, result) { while (match(stmnt, pattern, op) != 0) { result="error" - if (op[2] == "+") result = op[1] * op[3] - else if (op[2] == "-") result = op[1] / op[3] + if (op[2] == "+") result = op[1] + op[3] + else if (op[2] == "-") result = op[1] - op[3] sub(pattern, result, stmnt) } @@ -195,6 +196,18 @@ function evaluate(stmnt, pattern, arg, op, result) { stmnt = "+#if " (op[1] != 0 ? op[2] : op[1]) } + pattern="^+#if[ ]*(!*[ ]*defined[ ]*\\([ ]*[A-Za-z_]*[ ]*\\))\\&\\&[ ]*([01])[ ]*$" + while (match(stmnt, pattern, op) != 0) + { + stmnt = "+#if " (op[2] != 0 ? op[1] : op[2]) + } + + pattern="^+#if[ ]*(!*[ ]*[A-Za-z_]*[ ]*)\\&\\&[ ]*([01])[ ]*$" + while (match(stmnt, pattern, op) != 0) + { + stmnt = "+#if " (op[2] != 0 ? op[1] : op[2]) + } + pattern="(-*[0-9]+)[ ]*\\|\\|[ ]*(-*[0-9]+)" while (match(stmnt, pattern, op) != 0) { @@ -228,9 +241,9 @@ function evaluate(stmnt, pattern, arg, op, result) { } -# Evaluate ! stmnt +# Evaluate !stmnt function invert(stmnt) { - return evaluate(gensub("^+#if (.*)$", "+#if ! (\\1)", "g", stmnt)) + return evaluate(gensub("^+#if (.*)$", "+#if !(\\1)", "g", stmnt)) } @@ -246,14 +259,13 @@ function handle_if(evaluated) || $0 ~ "RHEL_MAJOR" \ || $0 ~ "RHEL_MINOR" \ || $0 ~ "RHEL_RELEASE_CODE" \ - || $0 ~ "GENERATING_UPSTREAM_PATCH" \ + || generating_upstream_patch_defined \ + && $0 ~ "GENERATING_UPSTREAM_PATCH" \ || $0 ~ "CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION" \ || ($0 ~ "CONFIG_SCST_PROC" && config_scst_proc_undefined) \ || ($0 ~ "SCSI_EXEC_REQ_FIFO_DEFINED" && SCSI_EXEC_REQ_FIFO_DEFINED!="") \ || ($0 ~ "SCST_IO_CONTEXT" && SCST_IO_CONTEXT != "")) { - #print $0 " -> " evaluated - $0 = evaluated } else { @@ -268,7 +280,7 @@ function handle_if(evaluated) if_stmnt[if_nesting_level] = evaluated any_section_output[if_nesting_level] = 0 decision[if_nesting_level] = evaluated - inv_decision[if_nesting_level] = evaluate(sprintf("+#if ! %s", substr(evaluated, 6))) + inv_decision[if_nesting_level] = evaluate(sprintf("+#if !%s", substr(evaluated, 6))) if (debug) printf "/* debug specialize-patch: (f) %s / %s */\n", \ decision[if_nesting_level], inv_decision[if_nesting_level] @@ -283,7 +295,7 @@ function handle_if(evaluated) evaluated = evaluate(evaluated) decision[if_nesting_level] = evaluated inv_decision[if_nesting_level] \ - = evaluate(sprintf("+#if %s && ! %s", \ + = evaluate(sprintf("+#if %s && !%s", \ substr(inv_decision[if_nesting_level], 6), \ substr(evaluated, 6))) if (debug) @@ -300,9 +312,11 @@ function handle_if(evaluated) function process_preprocessor_statement(evaluated, condition) { evaluated = evaluate($0) condition = 1 + ei = evaluated_if_stmnt[if_nesting_level]; if (evaluated ~ "^+#if") { if_nesting_level++ + evaluated_if_stmnt[if_nesting_level] = evaluated evaluated = handle_if(evaluated) } else if (evaluated ~ "^+#elif") @@ -326,12 +340,17 @@ function process_preprocessor_statement(evaluated, condition) { if (condition) { output = 1 - for (i = if_nesting_level; i >= 0; i--) - { - output = output && decision[i] != "+#if 0" + for (i = if_nesting_level; i >= 0; i--) { + if (debug) + printf "/* debug specialize-patch: (g1) %s: decision[%d] = %s */\n", \ + evaluated, i, decision[i] + output = output && decision[i] != "+#if 0" && decision[i] != "+#elif 0" } if (output) any_section_output[if_nesting_level] = 1 + if (debug) + printf "/* debug specialize-patch: (g2) %s: output = %d */\n", \ + evaluated, output } if (evaluated ~ "^+#define SCSI_EXEC_REQ_FIFO_DEFINED$" \ && SCSI_EXEC_REQ_FIFO_DEFINED != "" \ @@ -343,10 +362,48 @@ function process_preprocessor_statement(evaluated, condition) { discard = 1 delete_next_blank_line = 1 } - else if (output && (! condition || condition && matching_if !~ "^+#if [01]")) + else if (output && (!condition \ + || condition && matching_if !~ "^+#if [01]" \ + && matching_if !~ "^+#elif [01]")) { - for (i = 0; i < input_line_count; i++) - line[lines++] = input_line[i] + if (evaluated == "+#if undecided" \ + || (evaluated !~ "^+#if" \ + && evaluated !~ "^+#elif" \ + && evaluated !~ "^+#endif")) + { + for (i = 0; i < input_line_count; i++) + line[lines++] = input_line[i] + } else { + # If the statement being processed is an #else or #endif that is not a + # header file include guard and if that statement has a trailing comment, + # replace that comment by the partially evaluated matching #if expression. + if (evaluated ~ "^+#else" || evaluated ~ "^+#endif") { + if ($0 ~ "\\*/") { + if ($0 ~ "_H_* \\*/$") { + evaluated = $0 + } else { + if (ei ~ "^+#if ") + ei = substr(ei, 6) + else if (ei ~ "^+#ifdef") + ei = substr(ei, 9) + evaluated = sprintf("%s /* %s */", + $0 ~ " " ? substr($0, 1, index($0, " ")) : $0, + ei); + if (match(evaluated, "([^/ ]*) */\\* defined\\(([^()]*)\\) \\*/", + arg)) + { + evaluated = sprintf("%s /* %s */", arg[1], arg[2]) + } + } + } else { + evaluated = $0 + } + if (debug) + printf "/* debug specialize-patch: (h) %s */\n", evaluated + } + line[lines++] = evaluated + lines_less_added += input_line_count - 1 + } } else { @@ -396,7 +453,7 @@ BEGIN { exit 1 } LINUX_VERSION_CODE = version_code(kernel_version) - if (LINUX_VERSION_CODE < 2*65536 || LINUX_VERSION_CODE > 3*65536) + if (LINUX_VERSION_CODE < 2*65536 || LINUX_VERSION_CODE > 4*65536) { printf "Error: kernel version (%s) is out of range.\n", kernel_version exit 1 @@ -517,3 +574,8 @@ END { # Dump processed contents of the last read hunk. dump_lines() } + +# Local variables: +# indent-tabs-mode: nil +# c-basic-offset: 2 +# End: