Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
5.9 KiB

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. goto endofperl
  11. @rem ';
  12. #!perl
  13. #line 14
  14. #
  15. # Given that you are in a razzle window and given a command line like:
  16. #
  17. # release_files.bat @files=qw(sxs.dll kernel32.dll) ; @release=qw(%computername% release)
  18. #
  19. # This will iterate through %_Nttree%, altering the path to name each build
  20. # "flavor" (x86chk, x86fre, ia64chk, etc.), copying the stated .dll to
  21. # \\%computername%\release. It also copies the .pdb, and is wow6432-aware.
  22. #
  23. # This works well in conjunction with build4, which builds all the flavors,
  24. # using seperate .obj directories.
  25. #
  26. # defaults if command line doesn't change them
  27. #@files=qw(sxs.dll kernel32.dll ntdll.dll);
  28. #@release=qw(jaykrell101 release); # array of path elements
  29. @procs = qw(ia64 x86);
  30. @chkfres = qw(chk fre);
  31. sub Run
  32. {
  33. print($_[0] . "\n");
  34. system($_[0]);
  35. }
  36. sub Map32To64
  37. {
  38. $_ = $_[0];
  39. s/x86/ia64/g;
  40. s/i386/ia64/g;
  41. $_;
  42. }
  43. sub Map64To32
  44. {
  45. $_ = $_[0];
  46. s/ia64/x86/gi;
  47. s/amd64/x86/gi;
  48. #s/64/32/gi;
  49. $_;
  50. }
  51. sub MakeDirectoryForFile
  52. {
  53. my($dir) = ($_[0]);
  54. ($dir) = ($dir =~ /(.*)\\.*/);
  55. if (!-e $dir)
  56. {
  57. Run("mkdir " . $dir);
  58. system("mkdir " . $dir);
  59. }
  60. }
  61. sub DeleteFile
  62. {
  63. my($file) = ($_[0]);
  64. if (-e $file)
  65. {
  66. Run("del " . $file);
  67. }
  68. }
  69. sub SignFile
  70. {
  71. Run("signcode -sha1 " . $ENV{"NT_CERTHASH"} . " " . $_[0]);
  72. }
  73. sub CopyFile
  74. {
  75. my($source, $dest) = ($_[0], $_[1]);
  76. DeleteFile($dest);
  77. MakeDirectoryForFile($dest);
  78. Run("copy " . $source . " " . $dest);
  79. }
  80. sub Wow6432FriendlyName
  81. {
  82. $_ = $_[0];
  83. if (/amd64/i)
  84. {
  85. s/wow6432/x86-on-amd64/gi;
  86. }
  87. elsif (/ia64/i || /x86/i || /i386/i)
  88. {
  89. s/wow6432/x86-on-ia64/gi;
  90. }
  91. else
  92. {
  93. s/wow6432/32bit-on-64bit/gi;
  94. }
  95. $_;
  96. }
  97. sub Wow6432InstallName
  98. {
  99. $_ = $_[0];
  100. s/(.*)\\x86-on-amd64\\(.*)/$1\\w$2/gi;
  101. s/(.*)\\32bit-on-64bit\\(.*)/$1\\w$2/gi;
  102. s/(.*)\\x86-on-ia64\\(.*)/$1\\w$2/gi;
  103. s/(.*)\\wow6432\\(.*)/$1\\w$2/gi;
  104. $_;
  105. }
  106. sub MakeLower
  107. {
  108. my($x) = ($_[0]);
  109. return "\L$x";
  110. }
  111. sub Is32bit
  112. {
  113. my($x) = $_[0];
  114. $x = MakeLower($x);
  115. if ($x eq "x86")
  116. {
  117. return 1;
  118. }
  119. if ($x eq "i386")
  120. {
  121. return 1;
  122. }
  123. if ($x eq "386")
  124. {
  125. return 1;
  126. }
  127. return 0;
  128. }
  129. sub Is64bit
  130. {
  131. my($x) = $_[0];
  132. $x = MakeLower($x);
  133. if ($x eq "ia64")
  134. {
  135. return 1;
  136. }
  137. if ($x eq "amd64")
  138. {
  139. return 1;
  140. }
  141. return 0;
  142. # return ($x ~= /64/);
  143. }
  144. $nttree = $ENV{"_NTTREE"};
  145. for $proc (@procs)
  146. {
  147. $nttree =~ s/$proc//;
  148. }
  149. for $chkfre (@chkfres)
  150. {
  151. $nttree =~ s/$chkfre//;
  152. }
  153. #print(@ARGV);
  154. eval(join(" ", @ARGV));
  155. $release = "\\\\" . join("\\", @release);
  156. #print($release);
  157. foreach $proc (@procs)
  158. {
  159. foreach $chkfre (@chkfres)
  160. {
  161. foreach $file (@files)
  162. {
  163. ($base, $extension) = ($file =~ /(.*)\.(.*)/);
  164. # UNDONE we need to crack the pe to really find the pdb name.
  165. $pe_source_wow6432 = $nttree . $proc . $chkfre . "\\wow6432\\" . $base . "." . $extension;
  166. $pdb_source_wow6432 = $nttree . $proc . $chkfre . "\\wow6432\\symbols.pri\\retail\\" . $extension . "\\w" . $base . ".pdb";
  167. $pe_dest_wow6432 = $release . "\\" . $proc . $chkfre . "\\wow6432\\" . $base . "." . $extension;
  168. $pdb_dest_wow6432 = $release . "\\" . $proc . $chkfre . "\\wow6432\\" . $base . ".pdb";
  169. $pe_source = $pe_source_wow6432;
  170. $pdb_source = $pdb_source_wow6432;
  171. $pe_dest = $pe_dest_wow6432;
  172. $pdb_dest = $pdb_dest_wow6432;
  173. $pe_source =~ s/\\wow6432\\/\\/gi;
  174. $pdb_source =~ s/\\wow6432\\/\\/gi;
  175. $pdb_source =~ s/(.*)\\w(.*)/$1\\$2/gi;
  176. $pe_dest =~ s/\\wow6432\\/\\/gi;
  177. $pdb_dest =~ s/\\wow6432\\/\\/gi;
  178. $pdb_dest =~ s/\\w\\/\\/gi;
  179. if (-e $pe_source)
  180. {
  181. SignFile($pe_source);
  182. CopyFile($pe_source, $pe_dest);
  183. CopyFile($pdb_source, $pdb_dest);
  184. }
  185. if (Is64bit($proc))
  186. {
  187. # find the 32bit binary
  188. # reset to the "special" paths
  189. $pe_source = $pe_source_wow6432;
  190. $pdb_source = $pdb_source_wow6432;
  191. $pe_dest = $pe_dest_wow6432;
  192. $pdb_dest = $pdb_dest_wow6432;
  193. # dest is 64bitish, map source back to 32bit
  194. # first check for "special" wow6432 binary
  195. $pe_source = Map64To32($pe_source);
  196. $pdb_source = Map64To32($pdb_source);
  197. if (!-e $pe_source)
  198. {
  199. # otherwise use "regular" 32bit binary
  200. $pe_source =~ s/\\wow6432\\/\\/g;
  201. $pdb_source =~ s/\\wow6432\\/\\/g;
  202. }
  203. if (-e $pe_source)
  204. {
  205. # first look for pdb prefixed with "w"
  206. if (!-e $pdb_source)
  207. {
  208. # otherwise use "regular" pdb name
  209. $pdb_source =~ s/(.*)\\w(.*)/$1\\$2/gi;
  210. }
  211. $pe_dest = Wow6432FriendlyName($pe_dest);
  212. $pdb_dest = Wow6432FriendlyName($pdb_dest);
  213. SignFile($pe_source);
  214. CopyFile($pe_source, $pe_dest);
  215. CopyFile($pdb_source, $pdb_dest);
  216. CopyFile($pe_source, Wow6432InstallName($pe_dest));
  217. CopyFile($pdb_source, Wow6432InstallName($pdb_dest));
  218. }
  219. }
  220. }
  221. }
  222. }
  223. print("\n\n\n");
  224. Run("dir /s/b/a-d " . $release . "\\*.dll " . $release . "\\*.exe " . $release . "\\*.pdb");
  225. __END__
  226. :endofperl