PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/opensource.apple.com/source/apache_mod_php/apache_mod_php-44.2/php/win32/build/mkdist.php

#
PHP | 445 lines | 304 code | 64 blank | 77 comment | 50 complexity | 63b250047eed66e7996a662444ebea3e MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>mkdist.php</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">mkdist.php&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. &lt;?php # $Id: mkdist.php,v 1.13.4.1 2006/12/19 10:26:01 edink Exp $
  24. /* piece together a windows binary distro */
  25. $build_dir = $argv[1];
  26. $phpdll = $argv[2];
  27. $sapi_targets = explode(&quot; &quot;, $argv[3]);
  28. $ext_targets = explode(&quot; &quot;, $argv[4]);
  29. $pecl_targets = explode(&quot; &quot;, $argv[5]);
  30. $snapshot_template = $argv[6];
  31. $is_debug = preg_match(&quot;/^debug/i&quot;, $build_dir);
  32. echo &quot;Making dist for $build_dir\n&quot;;
  33. $dist_dir = $build_dir . &quot;/php-&quot; . phpversion();
  34. $pecl_dir = $build_dir . &quot;/pecl-&quot; . phpversion();
  35. @mkdir($dist_dir);
  36. @mkdir(&quot;$dist_dir/ext&quot;);
  37. @mkdir(&quot;$dist_dir/dev&quot;);
  38. @mkdir(&quot;$dist_dir/extras&quot;);
  39. @mkdir($pecl_dir);
  40. /* figure out additional DLL's that are required */
  41. $extra_dll_deps = array();
  42. $per_module_deps = array();
  43. $pecl_dll_deps = array();
  44. function get_depends($module)
  45. {
  46. static $no_dist = array(
  47. /* windows system dlls that should not be bundled */
  48. 'advapi32.dll', 'comdlg32.dll', 'gdi32.dll', 'kernel32.dll', 'ntdll.dll',
  49. 'odbc32.dll', 'ole32.dll', 'oleaut32.dll', 'rpcrt4.dll',
  50. 'shell32.dll', 'shlwapi.dll', 'user32.dll', 'ws2_32.dll', 'ws2help.dll',
  51. 'comctl32.dll', 'winmm.dll', 'wsock32.dll', 'winspool.drv', 'msasn1.dll',
  52. 'secur32.dll', 'netapi32.dll',
  53. /* apache */
  54. 'apachecore.dll',
  55. /* apache 2 */
  56. 'libhttpd.dll', 'libapr.dll', 'libaprutil.dll',
  57. /* pi3web */
  58. 'piapi.dll', 'pi3api.dll',
  59. /* nsapi */
  60. 'ns-httpd30.dll', 'ns-httpd35.dll', 'ns-httpd36.dll', 'ns-httpd40.dll',
  61. /* oracle */
  62. 'oci.dll', 'ociw32.dll',
  63. /* sybase */
  64. 'libcs.dll', 'libct.dll',
  65. /* visual C++; mscvrt.dll is present on everyones system,
  66. * but the debug version (msvcrtd.dll) and those from visual studio.net
  67. * (msvcrt7x.dll) are not */
  68. 'msvcrt.dll',
  69. );
  70. global $build_dir, $extra_dll_deps, $ext_targets, $sapi_targets, $pecl_targets, $phpdll, $per_module_deps, $pecl_dll_deps;
  71. $bd = strtolower(realpath($build_dir));
  72. $is_pecl = in_array($module, $pecl_targets);
  73. $cmd = &quot;$GLOBALS[build_dir]\\deplister.exe \&quot;$module\&quot; \&quot;$GLOBALS[build_dir]\&quot;&quot;;
  74. $proc = proc_open($cmd,
  75. array(1 =&gt; array(&quot;pipe&quot;, &quot;w&quot;)),
  76. $pipes);
  77. $n = 0;
  78. while (($line = fgetcsv($pipes[1]))) {
  79. $n++;
  80. $dep = strtolower($line[0]);
  81. $depbase = basename($dep);
  82. /* ignore stuff in our build dir, but only if it is
  83. * one of our targets */
  84. if (((in_array($depbase, $sapi_targets) ||
  85. in_array($depbase, $ext_targets) || in_array($depbase, $pecl_targets)) ||
  86. $depbase == $phpdll) &amp;&amp; file_exists($GLOBALS['build_dir'] . &quot;/$depbase&quot;)) {
  87. continue;
  88. }
  89. /* ignore some well-known system dlls */
  90. if (in_array(basename($dep), $no_dist)) {
  91. continue;
  92. }
  93. if ($is_pecl) {
  94. if (!in_array($dep, $pecl_dll_deps)) {
  95. $pecl_dll_deps[] = $dep;
  96. }
  97. } else {
  98. if (!in_array($dep, $extra_dll_deps)) {
  99. $extra_dll_deps[] = $dep;
  100. }
  101. }
  102. $per_module_deps[basename($module)][] = $dep;
  103. }
  104. fclose($pipes[1]);
  105. proc_close($proc);
  106. //echo &quot;Module $module [$n lines]\n&quot;;
  107. }
  108. function copy_file_list($source_dir, $dest_dir, $list)
  109. {
  110. global $is_debug, $dist_dir;
  111. foreach ($list as $item) {
  112. echo &quot;Copying $item from $source_dir to $dest_dir\n&quot;;
  113. copy($source_dir . DIRECTORY_SEPARATOR . $item, $dest_dir . DIRECTORY_SEPARATOR . $item);
  114. if ($is_debug) {
  115. $itemdb = preg_replace(&quot;/\.(exe|dll|lib)$/i&quot;, &quot;.pdb&quot;, $item);
  116. if (file_exists(&quot;$source_dir/$itemdb&quot;)) {
  117. copy(&quot;$source_dir/$itemdb&quot;, &quot;$dist_dir/dev/$itemdb&quot;);
  118. }
  119. }
  120. if (preg_match(&quot;/\.(exe|dll)$/i&quot;, $item)) {
  121. get_depends($source_dir . '/' . $item);
  122. }
  123. }
  124. }
  125. function copy_text_file($source, $dest)
  126. {
  127. $text = file_get_contents($source);
  128. $text = preg_replace(&quot;/(\r\n?)|\n/&quot;, &quot;\r\n&quot;, $text);
  129. $fp = fopen($dest, &quot;w&quot;);
  130. fwrite($fp, $text);
  131. fclose($fp);
  132. }
  133. /* very light-weight function to extract a single named file from
  134. * a gzipped tarball. This makes assumptions about the files
  135. * based on the PEAR info set in $packages. */
  136. function extract_file_from_tarball($pkg, $filename, $dest_dir) /* {{{ */
  137. {
  138. global $packages;
  139. $name = $pkg . '-' . $packages[$pkg];
  140. $tarball = $dest_dir . &quot;/&quot; . $name . '.tgz';
  141. $filename = $name . '/' . $filename;
  142. $destfilename = $dest_dir . &quot;/&quot; . basename($filename);
  143. $fp = gzopen($tarball, 'rb');
  144. $done = false;
  145. do {
  146. /* read the header */
  147. $hdr_data = gzread($fp, 512);
  148. if (strlen($hdr_data) == 0)
  149. break;
  150. $checksum = 0;
  151. for ($i = 0; $i &lt; 148; $i++)
  152. $checksum += ord($hdr_data{$i});
  153. for ($i = 148; $i &lt; 156; $i++)
  154. $checksum += 32;
  155. for ($i = 156; $i &lt; 512; $i++)
  156. $checksum += ord($hdr_data{$i});
  157. $hdr = unpack(&quot;a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor&quot;, $hdr_data);
  158. $hdr['checksum'] = octdec(trim($hdr['checksum']));
  159. if ($hdr['checksum'] != $checksum) {
  160. echo &quot;Checksum for $tarball $hdr[filename] is invalid\n&quot;;
  161. print_r($hdr);
  162. return;
  163. }
  164. $hdr['size'] = octdec(trim($hdr['size']));
  165. echo &quot;File: $hdr[filename] $hdr[size]\n&quot;;
  166. if ($filename == $hdr['filename']) {
  167. echo &quot;Found the file we want\n&quot;;
  168. $dest = fopen($destfilename, 'wb');
  169. $x = stream_copy_to_stream($fp, $dest, $hdr['size']);
  170. fclose($dest);
  171. echo &quot;Wrote $x bytes into $destfilename\n&quot;;
  172. break;
  173. }
  174. /* skip body of the file */
  175. $size = 512 * ceil((int)$hdr['size'] / 512);
  176. echo &quot;Skipping $size bytes\n&quot;;
  177. gzseek($fp, gztell($fp) + $size);
  178. } while (!$done);
  179. } /* }}} */
  180. /* the core dll */
  181. copy(&quot;$build_dir/php.exe&quot;, &quot;$dist_dir/php.exe&quot;);
  182. copy(&quot;$build_dir/$phpdll&quot;, &quot;$dist_dir/$phpdll&quot;);
  183. /* and the .lib goes into dev */
  184. $phplib = str_replace(&quot;.dll&quot;, &quot;.lib&quot;, $phpdll);
  185. copy(&quot;$build_dir/$phplib&quot;, &quot;$dist_dir/dev/$phplib&quot;);
  186. /* debug builds; copy the symbols too */
  187. if ($is_debug) {
  188. $phppdb = str_replace(&quot;.dll&quot;, &quot;.pdb&quot;, $phpdll);
  189. copy(&quot;$build_dir/$phppdb&quot;, &quot;$dist_dir/dev/$phppdb&quot;);
  190. }
  191. /* copy the sapi */
  192. copy_file_list($build_dir, &quot;$dist_dir&quot;, $sapi_targets);
  193. /* copy the extensions */
  194. copy_file_list($build_dir, &quot;$dist_dir/ext&quot;, $ext_targets);
  195. /* pecl sapi and extensions */
  196. copy_file_list($build_dir, $pecl_dir, $pecl_targets);
  197. /* populate reading material */
  198. $text_files = array(
  199. &quot;LICENSE&quot; =&gt; &quot;license.txt&quot;,
  200. &quot;NEWS&quot; =&gt; &quot;news.txt&quot;,
  201. &quot;php.ini-dist&quot; =&gt; &quot;php.ini-dist&quot;,
  202. &quot;php.ini-recommended&quot; =&gt; &quot;php.ini-recommended&quot;,
  203. &quot;win32/install.txt&quot; =&gt; &quot;install.txt&quot;,
  204. &quot;win32/pws-php5cgi.reg&quot; =&gt; &quot;pws-php5cgi.reg&quot;,
  205. &quot;win32/pws-php5isapi.reg&quot; =&gt; &quot;pws-php5isapi.reg&quot;,
  206. );
  207. foreach ($text_files as $src =&gt; $dest) {
  208. copy_text_file($src, $dist_dir . '/' . $dest);
  209. }
  210. /* general other files */
  211. $general_files = array(
  212. &quot;php.gif&quot; =&gt; &quot;php.gif&quot;,
  213. );
  214. foreach ($general_files as $src =&gt; $dest) {
  215. copy($src, $dist_dir . '/' . $dest);
  216. }
  217. /* include a snapshot identifier */
  218. $branch = &quot;HEAD&quot;; // TODO - determine this from CVS/Entries
  219. $fp = fopen(&quot;$dist_dir/snapshot.txt&quot;, &quot;w&quot;);
  220. $now = date(&quot;r&quot;);
  221. $version = phpversion();
  222. fwrite($fp, &lt;&lt;&lt;EOT
  223. This snapshot was automatically generated on
  224. $now
  225. Version: $version
  226. Branch: $branch
  227. Build: $build_dir
  228. EOT
  229. );
  230. /* list build-in extensions */
  231. $exts = get_loaded_extensions();
  232. fprintf($fp, &quot;\r\nBuilt-in Extensions\r\n&quot;);
  233. fwrite($fp, &quot;===========================\r\n&quot;);
  234. foreach ($exts as $ext) {
  235. fprintf($fp, &quot;%s\r\n&quot;, $ext);
  236. }
  237. fwrite($fp, &quot;\r\n\r\n&quot;);
  238. /* list dependencies */
  239. fprintf($fp, &quot;Dependency information:\r\n&quot;);
  240. foreach ($per_module_deps as $modulename =&gt; $deps) {
  241. if (in_array($modulename, $pecl_targets))
  242. continue;
  243. fprintf($fp, &quot;Module: %s\r\n&quot;, $modulename);
  244. fwrite($fp, &quot;===========================\r\n&quot;);
  245. foreach ($deps as $dll) {
  246. fprintf($fp, &quot;\t%s\r\n&quot;, basename($dll));
  247. }
  248. fwrite($fp, &quot;\r\n&quot;);
  249. }
  250. fclose($fp);
  251. /* Now add those dependencies */
  252. foreach ($extra_dll_deps as $dll) {
  253. if (!file_exists($dll)) {
  254. /* try template dir */
  255. $tdll = $snapshot_template . &quot;/dlls/&quot; . basename($dll);
  256. if (!file_exists($tdll)) {
  257. echo &quot;WARNING: distro depends on $dll, but could not find it on your system\n&quot;;
  258. continue;
  259. }
  260. $dll = $tdll;
  261. }
  262. copy($dll, &quot;$dist_dir/&quot; . basename($dll));
  263. }
  264. /* and those for pecl */
  265. foreach ($pecl_dll_deps as $dll) {
  266. if (in_array($dll, $extra_dll_deps)) {
  267. /* already in main distro */
  268. continue;
  269. }
  270. if (!file_exists($dll)) {
  271. /* try template dir */
  272. $tdll = $snapshot_template . &quot;/dlls/&quot; . basename($dll);
  273. if (!file_exists($tdll)) {
  274. echo &quot;WARNING: distro depends on $dll, but could not find it on your system\n&quot;;
  275. continue;
  276. }
  277. $dll = $tdll;
  278. }
  279. copy($dll, &quot;$pecl_dir/&quot; . basename($dll));
  280. }
  281. function copy_dir($source, $dest)
  282. {
  283. if (!is_dir($dest)) {
  284. if (!mkdir($dest)) {
  285. return false;
  286. }
  287. }
  288. $d = opendir($source);
  289. while (($f = readdir($d)) !== false) {
  290. if ($f == '.' || $f == '..' || $f == 'CVS') {
  291. continue;
  292. }
  293. $fs = $source . '/' . $f;
  294. $fd = $dest . '/' . $f;
  295. if (is_dir($fs)) {
  296. copy_dir($fs, $fd);
  297. } else {
  298. copy($fs, $fd);
  299. }
  300. }
  301. closedir($d);
  302. }
  303. /* change this next line to true to use good-old
  304. * hand-assembled go-pear-bundle from the snapshot template */
  305. $use_pear_template = true;
  306. if (!$use_pear_template) {
  307. /* Let's do a PEAR-less pear setup */
  308. mkdir(&quot;$dist_dir/PEAR&quot;);
  309. mkdir(&quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  310. /* grab the bootstrap script */
  311. echo &quot;Downloading go-pear\n&quot;;
  312. copy(&quot;<a href="http://go-pear.org/">http://go-pear.org/</a>&quot;, &quot;$dist_dir/PEAR/go-pear.php&quot;);
  313. /* import the package list -- sets $packages variable */
  314. include &quot;pear/go-pear-list.php&quot;;
  315. /* download the packages into the destination */
  316. echo &quot;Fetching packages\n&quot;;
  317. foreach ($packages as $name =&gt; $version) {
  318. $filename = &quot;$name-$version.tgz&quot;;
  319. $destfilename = &quot;$dist_dir/PEAR/go-pear-bundle/$filename&quot;;
  320. if (file_exists($destfilename))
  321. continue;
  322. $url = &quot;<a href="http://pear.php.net/get/">http://pear.php.net/get/</a>$filename&quot;;
  323. echo &quot;Downloading $name from $url\n&quot;;
  324. flush();
  325. copy($url, $destfilename);
  326. }
  327. echo &quot;Download complete. Extracting bootstrap files\n&quot;;
  328. /* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
  329. * broken out of the tarballs */
  330. extract_file_from_tarball('PEAR', 'PEAR.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  331. extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  332. extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  333. }
  334. /* add extras from the template dir */
  335. if (file_exists($snapshot_template)) {
  336. $items = glob(&quot;$snapshot_template/*&quot;);
  337. print_r($items);
  338. foreach ($items as $item) {
  339. $bi = basename($item);
  340. if (is_dir($item)) {
  341. if ($bi == 'dlls' || $bi == 'symbols') {
  342. continue;
  343. } else if ($bi == 'PEAR') {
  344. if ($use_pear_template) {
  345. /* copy to top level */
  346. copy_dir($item, &quot;$dist_dir/$bi&quot;);
  347. }
  348. } else {
  349. /* copy that dir into extras */
  350. copy_dir($item, &quot;$dist_dir/extras/$bi&quot;);
  351. }
  352. } else {
  353. if ($bi == 'go-pear.bat') {
  354. /* copy to top level */
  355. copy($item, &quot;$dist_dir/$bi&quot;);
  356. } else {
  357. /* copy to extras */
  358. copy($item, &quot;$dist_dir/extras/$bi&quot;);
  359. }
  360. }
  361. }
  362. /* copy c++ runtime */
  363. $items = glob(&quot;$snapshot_template/dlls/*.CRT&quot;);
  364. foreach ($items as $item) {
  365. $bi = basename($item);
  366. if (is_dir($item)) {
  367. copy_dir($item, &quot;$dist_dir/$bi&quot;);
  368. copy_dir($item, &quot;$dist_dir/ext/$bi&quot;);
  369. }
  370. }
  371. } else {
  372. echo &quot;WARNING: you don't have a snapshot template\n&quot;;
  373. echo &quot; your dist will not be complete\n&quot;;
  374. }
  375. ?&gt;
  376. </pre>
  377. <hr />
  378. </body></html>