#!/usr/bin/perl -w # Simple script to apply a whole bunch of patches to Freeciv. # Usage: # apply.pl [-p patch] # apply all patches in order to the current directory # (should be run within the freeciv-patched directory) # If the -p option is specified, only patches up to (but not including) # the named patch are applied # apply.pl -R [-p patch] # remove all patches (in reverse order) from the current directory # apply.pl -f # recreate all patches; requires "makefreepatch.sh" in $toppath. use Getopt::Std; # The directory where you keep all your Freeciv CVS builds $toppath = "/scratch/ben/freeciv"; # The directory where the impr-gen patches are stored $patchpath = "$toppath/impr-gen-patches"; # Clean Freeciv CVS $origpath = "$toppath/freeciv-cvs"; # Freeciv CVS + impr-gen patches $newpath = "$toppath/freeciv-patched"; # Directory where the -f option puts new, recreated patches $newpatchpath = "$patchpath/new"; $errors = 0; # The patches to apply, in order @patches = ( "neweff-implement-update-v11.patch", "neweff-iterator-v6.patch", "numbuildings-v2.patch", "effect-update-defer-v10.patch", "effect-city-bonuses-v14.patch", "effect-citydlg-happiness-v4.patch", "effect-tile-bonuses-v10.patch", "effect-unit-mods-v11.patch", "effect-boost-research-v12.patch", "effect-corrupt-revolt-v5.patch", "effect-upgrades-v11.patch", "effect-global-city-v41.patch", "effect-combat-v7.patch", "effect-govchange-v4.patch", "impr-gen-readme-v7.patch", "effect-no-sink-deep-v3.patch", "effect-spy-resistant-v3.patch", "helpdata-v4.patch", "effect-palace-walls-v9.patch", "destroyed-effects-v20.patch", "effect-unit-v20.patch", "effect-nationgov-v11.patch", "effect-outside-v10.patch", "effect-cost-v2.patch" ); my (%opts, $lastpatch); getopts('Rfp:', \%opts); $lastpatch = $#patches + 1; if (defined($opts{p})) { for ($i = 0; $i <= $#patches; $i++) { if ($patches[$i] =~ /^$opts{p}/) { $lastpatch = $i; last; } } } if (defined($opts{R})) { for ($i = $lastpatch - 1; $i >= 0; $i--) { print "### Removing $patches[$i]\n"; system("patch -p1 -R < $patchpath/$patches[$i]"); if ($? >> 8) { $errors++; } } if ($lastpatch <= $#patches) { print "\nPatches removed up to (but not including) ". "$patches[$lastpatch]\n\n"; } } elsif (defined($opts{f})) { chdir($newpath); for ($i = 0; $i < $lastpatch; $i++) { print "### Fixing up $patches[$i]\n"; chdir($newpath); print "### Applying $patches[$i] to freeciv-patched\n"; system("patch -p1 < $patchpath/$patches[$i]"); if ($? >> 8) { $errors++; } chdir($toppath); print "### Generating new $patches[$i]\n"; system("./makefreecivpatch.sh > $newpatchpath/$patches[$i]"); chdir($origpath); print "### Applying $patches[$i] to freeciv-cvs\n"; system("patch -p1 < $patchpath/$patches[$i]"); if ($? >> 8) { $errors++; } } chdir($origpath); for ($i = $lastpatch - 1; $i >= 0; $i--) { print "### Removing $patches[$i] from freeciv-cvs\n"; system("patch -p1 -R < $patchpath/$patches[$i]"); if ($? >> 8) { $errors++; } } } else { for ($i = 0; $i < $lastpatch; $i++) { print "### Applying $patches[$i]\n"; system("patch -p1 < $patchpath/$patches[$i]"); if ($? >> 8) { $errors++; } } if ($lastpatch <= $#patches) { print "\nPatches added up to (but not including) ". "$patches[$lastpatch]\n\n"; } } if ($errors > 0) { print "\n\nWARNING: $errors errors were encountered while applying ". "patches - check output!\n\n"; }