upgrade-pcre.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // script to upgrade PCRE. just drop the pcre-x.x.tar.xx here and run the script
  3. $pattern = 'pcre-*.tar.*';
  4. $newpcre = glob($pattern);
  5. if (count($newpcre) > 1) {
  6. echo "more than one '$pattern' file. aborting\n";
  7. print_r($newpcre);
  8. exit;
  9. }
  10. if (count($newpcre) == 0) {
  11. die("need one '$pattern' file. aborting.\n");
  12. }
  13. $newpcre = $newpcre[0];
  14. if (strpos($newpcre, 'gz')) {
  15. system("tar xfz $newpcre");
  16. } elseif (strpos($newpcre, 'bz2')) {
  17. system("tar xfj $newpcre");
  18. } else {
  19. die("file type not recognized: $newpcre\n");
  20. }
  21. $newpcre = substr($newpcre, 0, strpos($newpcre, '.tar'));
  22. $dirlen = strlen('pcrelib');
  23. function recurse($path)
  24. {
  25. global $newpcre, $dirlen;
  26. foreach (scandir($path) as $file) {
  27. if ($file[0] === '.' ||
  28. $file === 'CVS' ||
  29. @substr_compare($file, '.lo', -3, 3) === 0 ||
  30. @substr_compare($file, '.loT', -4, 4) === 0 ||
  31. @substr_compare($file, '.o', -2, 2) === 0) continue;
  32. $file = "$path/$file";
  33. if (is_dir($file)) {
  34. recurse($file);
  35. continue;
  36. }
  37. echo "processing $file... ";
  38. $newfile = $newpcre . substr($file, $dirlen);
  39. if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
  40. $newfile = $tmp;
  41. }
  42. if (!is_file($newfile)) {
  43. die("$newfile is not available any more\n");
  44. }
  45. // maintain file mtimes so that cvs doesnt get crazy
  46. if (file_get_contents($newfile) !== file_get_contents($file)) {
  47. copy($newfile, $file);
  48. }
  49. // always include the config.h file
  50. $content = file_get_contents($newfile);
  51. //$newcontent = preg_replace('/#\s*ifdef HAVE_CONFIG_H\s*(.+)\s*#\s*endif/', '$1', $content);
  52. //if ($content !== $newcontent) {
  53. // file_put_contents($file, $newcontent);
  54. //}
  55. echo "OK\n";
  56. }
  57. }
  58. recurse('pcrelib');
  59. $dirorig = scandir('pcrelib/testdata');
  60. $k = array_search('CVS', $dirorig);
  61. if ($k !== false)
  62. unset($dirorig[$k]);
  63. $k = array_search('.svn', $dirorig);
  64. if ($k !== false)
  65. unset($dirorig[$k]);
  66. $dirnew = scandir("$newpcre/testdata");
  67. $diff = array_diff($dirorig, $dirnew);
  68. foreach ($diff as $file) {
  69. $file2 = 'pcrelib'.substr($file, strlen($newpcre));
  70. copy($file, $file2);
  71. }
  72. // the config.h needs special care
  73. $prepend_config_h = '
  74. #include <php_compat.h>
  75. #ifndef PHP_WIN32
  76. # include <php_config.h>
  77. #endif
  78. #undef PACKAGE_NAME
  79. #undef PACKAGE_VERSION
  80. #undef PACKAGE_TARNAME
  81. #undef PACKAGE_STRING
  82. #define SUPPORT_UCP
  83. #define SUPPORT_UTF8
  84. #if defined(__GNUC__) && __GNUC__ >= 4
  85. # ifdef __cplusplus
  86. # define PCRE_EXP_DECL extern "C" __attribute__ ((visibility("default")))
  87. # else
  88. # define PCRE_EXP_DECL extern __attribute__ ((visibility("default")))
  89. # endif
  90. # define PCRE_EXP_DEFN __attribute__ ((visibility("default")))
  91. # define PCRE_EXP_DATA_DEFN __attribute__ ((visibility("default")))
  92. #endif
  93. ';
  94. file_put_contents('pcrelib/config.h', $prepend_config_h . file_get_contents('pcrelib/config.h'));
  95. echo "\nThe End :-)\n\n"
  96. ?>