diff --git a/scripts/generate-kernel-patch b/scripts/generate-kernel-patch index 3f4e67893..900d2a0d5 100755 --- a/scripts/generate-kernel-patch +++ b/scripts/generate-kernel-patch @@ -136,9 +136,13 @@ function process_patch { ) >"${tmppatch}" touch "${tmppatch}" { - awk 'BEGIN{h=1}/^diff/{h=0}/^---/{h=0}h!=0{print}' < "${tmppatch}"; - echo "---"; diffstat "${tmppatch}"; echo ""; - awk 'BEGIN{h=1}/^diff/{h=0}/^---/{h=0}h==0{print}' < "${tmppatch}"; + if [ -e /usr/bin/diffstat ]; then + awk 'BEGIN{h=1}/^diff/{h=0}/^---/{h=0}h!=0{print}' < "${tmppatch}" + echo "---" + diffstat "${tmppatch}" + echo "" + awk 'BEGIN{h=1}/^diff/{h=0}/^---/{h=0}h==0{print}' < "${tmppatch}" + fi } \ > "${patchdir}/$(basename $1)" rm -f "${tmppatch}" @@ -578,7 +582,8 @@ EOF for f in \ drivers/scsi/ibmvscsi/ibmvstgt.c \ drivers/scsi/libsrp.c \ - include/scsi/libsrp.h + include/scsi/libsrp.h \ + include/scsi/srp.h do add_patch "ibmvstgt/in-tree-patches/${kernel_version}/$(basename $f).patch" $f done diff --git a/scripts/specialize-patch b/scripts/specialize-patch index e9c2c7a72..cfce9c54a 100755 --- a/scripts/specialize-patch +++ b/scripts/specialize-patch @@ -41,7 +41,7 @@ function version_code(kver, array) { # Note: the order in which the substitutions appear below is important -- # it is the same order as the order of operators in C. -function evaluate(stmnt, pattern, arg, op) { +function evaluate(stmnt, pattern, arg, op, result) { if (debug) printf "/* debug specialize-patch: (a) %s */\n", stmnt @@ -230,7 +230,7 @@ function invert(stmnt) { # Handle #if or #elif -function handle_if() +function handle_if(evaluated) { # Only act on preprocessor conditional expressions with regard to the Linux # kernel version, and do not interpret other expressions. @@ -284,24 +284,23 @@ function handle_if() decision[if_nesting_level], inv_decision[if_nesting_level] } matching_if = if_stmnt[if_nesting_level] + return evaluated } # Decide whether or not to print the preprocessor statement $0. -function process_preprocessor_statement() { - orig_stmnt = $0 +function process_preprocessor_statement(evaluated, condition) { evaluated = evaluate($0) condition = 1 - delete_next_blank_line = 0 if (evaluated ~ "^+#if") { if_nesting_level++ - handle_if() + evaluated = handle_if(evaluated) } else if (evaluated ~ "^+#elif") { - handle_if() + evaluated = handle_if(evaluated) } else if (evaluated ~ "^+#else") { @@ -334,13 +333,7 @@ function process_preprocessor_statement() { || (evaluated ~ "^+#define CONFIG_SCST_PROC$" \ && config_scst_proc_undefined)) { - if (blank_deleted_code) - for (i = 0; i < input_line_count; i++) - line[lines++] = "+" - else - { - lines_deleted += input_line_count - } + discard = 1 delete_next_blank_line = 1 } else if (output && (! condition || condition && matching_if !~ "^+#if [01]")) @@ -350,23 +343,20 @@ function process_preprocessor_statement() { } else { - if (blank_deleted_code) - for (i = 0; i < input_line_count; i++) - line[lines++] = "+" - else - lines_deleted += input_line_count + discard = 1 if (lines >= 1 && line[lines - 1] == "+") delete_next_blank_line = 1 } } function reset_hunk_state_variables() { - lines = 0 - lines_deleted = 0 - output = 1 - if_nesting_level = -1 - delete_next_blank_line = 0 - h[0] = "" + lines = 0 + lines_less_added = 0 + lines_less_removed = 0 + output = 1 + if_nesting_level = -1 + delete_next_blank_line = 0 + h[0] = "" } function dump_lines() { @@ -385,9 +375,9 @@ function dump_lines() { if (first_modif >= 0) { if (h[0] != "") - printf "@@ -%d,%d +%d,%d @@%s\n",h[1],h[2],h[3],h[4]-lines_deleted,h[5] + printf "@@ -%d,%d +%d,%d @@%s\n",h[1],h[2]-lines_less_deleted,h[3],h[4]-lines_less_added,h[5] for (i = 0; i < lines; i++) - print line[i] + print line[i] } } @@ -456,6 +446,7 @@ BEGIN { $0 = previous_line $0 } + discard = 0 # If the line currently being processed is a hunk header, print all lines # that were stored in the array line[] since the last hunk header was read. if (match($0, "^@@ -([0-9]*),([0-9]*) \\+([0-9]*),([0-9]*) @@(.*)$")) @@ -467,13 +458,7 @@ BEGIN { } else if (delete_next_blank_line && match($0, "^+$")) { - if (blank_deleted_code) - for (i = 0; i < input_line_count; i++) - line[lines++] = "+" - else - { - lines_deleted += input_line_count - } + discard = 1 delete_next_blank_line = 0 } else @@ -494,18 +479,31 @@ BEGIN { } else { - # Discard the last read lines. - if (blank_deleted_code) - { - for (i = 0; i < input_line_count; i++) - line[lines++] = "+" - } - else - lines_deleted += input_line_count + discard = 1 if (lines >= 1 && line[lines-1] == "+") delete_next_blank_line = 1 } } + if (discard) + { + for (i = 0; i < input_line_count; i++) + { + if (blank_deleted_code) + { + if (input_line[i] ~ "^+") + line[lines++] = "+" + else + line[lines++] = input_line[i] + } + else + { + if (input_line[i] ~ "^+") + lines_less_added++ + else if (input_line[i] ~ "^-") + lines_less_deleted++ + } + } + } } END {