Stefan Reinauer | 564e90f | 2012-05-04 15:37:18 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # This script has been honed over quite a few iterations. The trick is to make |
| 3 | # it easy for you to see what transformations occur |
| 4 | # without burying you in files. |
| 5 | # Also, coccinelle is not perfect, so we have to help her at times. As she |
| 6 | # gets smarter, we can shrink thigns we do in here. |
| 7 | # So we get input files, then do per-file changes, then do all-file changes |
| 8 | # I've deliberately made this script simple. Please don't decide it needs to |
| 9 | # be automagic. Just let it work in its simple way. Also, if you change even |
| 10 | # one simple thing, ALWAYS rerun this script do make sure you did not make a |
| 11 | # global test. NEVER test one little thing in isolation. That way |
| 12 | # lies madness. |
| 13 | # The only thing you need to set is |
| 14 | # export LINUX=/path/to/your/linux/tree. |
| 15 | # Order in which we do things. |
| 16 | # 1. Get source files into inputs. |
| 17 | # 2. cp them to per-file-changes |
| 18 | # Note that we even copy ones that might not currently need per-file |
| 19 | # changes. Because they may in future and it keeps the script simple. |
| 20 | # We tried both ways and like this best. |
| 21 | # 3. run 'ed' across a few files that need it |
| 22 | # 4. run coccinelle with any per-file changes |
| 23 | # There is some ugliness here as we have to do a reverse patch step. Sorry. |
| 24 | # 5. cp per-file-changes/* to final |
| 25 | # 6. run coccinelle files that apply to more than one file |
| 26 | # it's best to run coccinelle on as many files as possible, she's pretty |
| 27 | # smart about |
| 28 | # certain transformations, e.g. if you remove a function definition she can |
| 29 | # remove all calls to that function (usually) |
| 30 | # |
| 31 | # Now you can |
| 32 | # make (will build all working tools) |
| 33 | # or |
| 34 | # make broken |
| 35 | # for things that don't build yet. |
| 36 | |
| 37 | # Step 1 |
| 38 | rm inputs/* per-file-changes/* final/* tmp/* |
| 39 | cp $LINUX/drivers/gpu/drm/i915/i915_reg.h inputs |
| 40 | cp $LINUX/drivers/gpu/drm/i915/i915_drv.? inputs |
| 41 | cp $LINUX/drivers/gpu/drm/i915/intel_display.c inputs |
| 42 | cp $LINUX/drivers/gpu/drm/i915/intel_bios.c inputs |
| 43 | cp $LINUX/drivers/gpu/drm/i915/intel_bios.h inputs |
| 44 | cp $LINUX/drivers/gpu/drm/i915/intel_ringbuffer.h inputs |
| 45 | cp $LINUX/drivers/gpu/drm/i915/i915_dma.c inputs |
| 46 | cp $LINUX/include/drm/drm_crtc.h inputs |
| 47 | cp $LINUX/include/drm/drm_mode.h inputs |
| 48 | cp $LINUX/include/drm/drm_dp_helper.h inputs |
| 49 | cp $LINUX/drivers/gpu/drm/drm_modes.c inputs |
| 50 | |
| 51 | # Step 2 |
| 52 | cp inputs/* per-file-changes |
| 53 | |
| 54 | # Step 3 |
| 55 | # We tried sed but it had some issues that ed did not |
| 56 | # coccinelle can't handle anonymous structs |
| 57 | # also some stuff is easier with ed. |
| 58 | # also there are bugs spatches/in coccinelle it seems :-( |
| 59 | # the literal deletes below suck and we need to figure |
| 60 | # out wtf went wrong. |
| 61 | ed per-file-changes/i915_drv.h << EOF |
| 62 | /intel_gtt/ |
| 63 | . |
| 64 | ?struct *{?,/mm;/d |
| 65 | . |
| 66 | /i915_trace.h/ |
| 67 | . |
| 68 | .,/#define POSTING_READ16/d |
| 69 | /struct *intel_gmbus/ |
| 70 | .,/\*gmb/d |
| 71 | . |
| 72 | g/notifier_block/d |
| 73 | g/struct *drm_i915_display_funcs *display;/d |
| 74 | g/struct *completion *[a-z].*;/d |
| 75 | w |
| 76 | q |
| 77 | EOF |
| 78 | |
| 79 | ed per-file-changes/drm_crtc.h <<EOF |
| 80 | /drm_crtc_init/,/endif/-d |
| 81 | w |
| 82 | q |
| 83 | EOF |
| 84 | |
| 85 | ed per-file-changes/intel_display.c << EOF |
| 86 | g/mode_config.funcs *=/d |
| 87 | g/fb_base/d |
| 88 | g/const/s/// |
| 89 | w |
| 90 | q |
| 91 | EOF |
| 92 | |
| 93 | # Reverse patches. We hope these will go away someday. |
| 94 | >per-file-changes/intel_bios.c |
| 95 | spatch -sp_file spatches/getfn.cocci inputs/intel_bios.c -U 0 > tmp/res |
| 96 | ./plusplusplus tmp/res per-file-changes/intel_bios.c |
| 97 | (cd per-file-changes/; patch -p1 -R ) < tmp/res.pat |
| 98 | |
| 99 | >per-file-changes/drm_modes.c |
| 100 | spatch -sp_file spatches/getdrmmodefn.cocci inputs/drm_modes.c -U 0 \ |
| 101 | > tmp/drm_modes |
| 102 | ./plusplusplus tmp/drm_modes per-file-changes/drm_modes.c |
| 103 | (cd per-file-changes/; patch -p1 -R ) < tmp/drm_modes.pat |
| 104 | |
| 105 | spatch -sp_file spatches/i915_dma.c.cocci inputs/i915_dma.c -U 0 \ |
| 106 | > tmp/i915_dma.c.patch |
| 107 | ./plusplusplus tmp/i915_dma.c.patch per-file-changes/i915_dma.c |
| 108 | # This is the only way I can make sure the right file gets patched! |
| 109 | # someone tell me why. It keeps picking the wrong one. |
| 110 | (cd per-file-changes/; patch -p1 -R ) < tmp/i915_dma.c.patch.pat |
| 111 | spatch --in-place -sp_file spatches/fixcalls.cocci per-file-changes/i915_dma.c |
| 112 | #patch -p0 -R < tmp/i915_dma.c.patch.pat |
| 113 | |
| 114 | #echo '#include "video.h"' |
| 115 | >per-file-changes/i915_drv.c |
| 116 | spatch -sp_file spatches/i915_drv.c.cocci inputs/i915_drv.c -U 0 \ |
| 117 | > tmp/i915_drv.c.patch |
| 118 | ./plusplusplus tmp/i915_drv.c.patch per-file-changes/i915_drv.c |
| 119 | # This is the only way I can make sure the right file gets patched! |
| 120 | # someone tell me why. It keeps picking the wrong one. |
| 121 | (cd per-file-changes/; patch -p1 -R ) < tmp/i915_drv.c.patch.pat |
| 122 | spatch --in-place -sp_file spatches/fixcalls.cocci per-file-changes/i915_drv.c |
| 123 | |
| 124 | # Finally, a basic spatch sequence! |
| 125 | |
| 126 | spatch --in-place -sp_file \ |
| 127 | spatches/intel_display.c.cocci per-file-changes/intel_display.c \ |
| 128 | > /dev/null |
| 129 | |
| 130 | spatch --in-place -sp_file spatches/i915_drv.cocci \ |
| 131 | per-file-changes/i915_drv.h >/dev/null |
| 132 | |
| 133 | # Now do the common changes to all files. |
| 134 | cp per-file-changes/* final |
| 135 | spatch --in-place -sp_file spatches/ringbuffer.cocci \ |
| 136 | final/intel_ringbuffer.h >/dev/null |
| 137 | spatch --in-place -sp_file spatches/removeinclude.cocci \ |
| 138 | final/intel_display.c > /dev/null |
| 139 | spatch --in-place -sp_file spatches/fixcalls.cocci final/intel_display.c \ |
| 140 | >/dev/null |
| 141 | spatch --in-place -sp_file spatches/ringbuffer.cocci final/drm_dp_helper.h\ |
| 142 | >/dev/null |
| 143 | spatch --in-place -sp_file spatches/removeinclude.cocci final/drm_dp_helper.h\ |
| 144 | >/dev/null |
| 145 | spatch --in-place -sp_file spatches/i915_drv.cocci final/intel_ringbuffer.h\ |
| 146 | >/dev/null |
| 147 | spatch --in-place -sp_file spatches/deldev.cocci final/intel_bios.c \ |
| 148 | final/intel_bios.h final/i915_drv.h final/intel_ringbuffer.h>/dev/null |
| 149 | spatch --in-place -sp_file spatches/fixcalls.cocci final/intel_bios.c \ |
| 150 | >/dev/null |
| 151 | spatch --in-place -sp_file spatches/drm_crtc.cocci final/drm_crtc.h >/dev/null |