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.

1370 lines
44 KiB

  1. @perl -x -w %0 %*
  2. @goto :eof
  3. #!perl
  4. # line 5
  5. ################################################################################
  6. # 05-Jun-00 : skupec: Add fail safes to avoid hangs in post build
  7. # 1) delete all old lock files before we start
  8. # 2) set max. wait limit for new process to 30*2 seconds
  9. #
  10. # 01-Jul-00 : skupec: Convert to use Win32::Process to avoid sporadic hangs
  11. # that are showing up in postbuild.
  12. #
  13. # 10-Nov-00 : skupec: Add Verbose mode
  14. # No longer use \lib[fre|chk]\%arch%. Now just \lib\%arch%
  15. #
  16. # 11-Jan-01 : skupec: Don't ship checked versions of the tools.
  17. #
  18. # 10-Feb-01 : skupec: Create per-architecture cabs for tools. Instead of just
  19. # TOOL_*.cab, we now also have TOOL_*x.cab and TOOL_*i.cab
  20. # (x86/ia64 respectively) IFF per-arch directories exist
  21. # when cabbing is done. TOOL_*.cab should still be the
  22. # primary cab in cabs.ini so a single checkbox will install
  23. # on either platform.
  24. #
  25. # 27-Feb-01 : skupec: Modify the cabbing of \incs to properly handle the new
  26. # platform specific subdir layout.
  27. #
  28. # 04-Apr-01 : skupec: Add cabbing of legacy libs for Win2K DDK env
  29. #
  30. # 17-May-01 : skupec: Add DDK_DBG[i|x] cabs only on CHK builds
  31. #
  32. # 02-May-02 : skupec: forked for XPSP builds
  33. #
  34. # 09-Jul-02 : skupec: add QFE build num to cabs.ini
  35. #
  36. use lib $ENV{RAZZLETOOLPATH} . '\\postbuildscripts';
  37. use PbuildEnv;
  38. use BuildName;
  39. # Only accept one parameter which must be numeric
  40. my ($numproc, $lpCount, $force, $spoof,$verbose) = (2,0,0,0,0);
  41. for ($lpCount=0; $lpCount <= ($#ARGV); $lpCount++) {
  42. SWITCH: {
  43. Dependencies() if lc $ARGV[$lpCount] eq "-plan";
  44. if ((substr($ARGV[$lpCount],0,1) eq "-") or (substr($ARGV[$lpCount],0,1) eq "/")) {
  45. for ($i=1;$i<length($ARGV[$lpCount]);$i++) {
  46. exit(Usage()) if uc(substr($ARGV[$lpCount],$i,1)) eq "?";
  47. exit(Usage()) if uc(substr($ARGV[$lpCount],$i,1)) eq "H";
  48. if (uc substr($ARGV[$lpCount],$i,1) eq "L") {
  49. if ($ARGV[$lpCount] =~ /:+(.*)/) {
  50. if ((defined $1) and ($1 ne "")) { # handle -l:<language>
  51. $lang = $1;
  52. } else { # handle -l: where language was forgotten
  53. $lang = "usa";
  54. }
  55. $ARGV[$lpCount] =~ s/:+(.*)//;
  56. } elsif (defined $ARGV[$lpCount+1]) { # handle -l <language>
  57. $lang = $ARGV[$lpCount+1];
  58. splice(@ARGV,$lpCount+1,1);
  59. } else { # handle -l where language was forgotten
  60. $lang = "usa"; # default
  61. }
  62. unless (uc $lang eq "USA") { # only execute on USA
  63. exit 0;
  64. }
  65. next;
  66. } elsif (uc substr($ARGV[$lpCount],$i,1) eq "N") {
  67. if (defined($ARGV[$lpCount+1]) and ($ARGV[$lpCount+1] =~ /^\d*$/)) {
  68. $numproc=$ARGV[$lpCount+1];
  69. splice(@ARGV,$lpCount+1,1);
  70. } else {
  71. exit(Usage());
  72. }
  73. } elsif (uc substr($ARGV[$lpCount],$i,1) eq "F") {
  74. $force = 1;
  75. } elsif (uc substr($ARGV[$lpCount],$i,1) eq "S") {
  76. $spoof = 1;
  77. } elsif (uc substr($ARGV[$lpCount],$i,1) eq "V") {
  78. $verbose = 1;
  79. } else {
  80. print("-",substr($ARGV[$lpCount],$i,1)," switch ignored. Use '-?' or '-h' to get usage.\n");
  81. }
  82. }
  83. } else {
  84. print("$ARGV[$lpCount] argument ignored.\n");
  85. }
  86. 1; #Last line should do nothing
  87. }
  88. }
  89. if ( -f "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  90. if ( !open SKIP, "$ENV{_NTPOSTBLD}\\..\\build_logs\\skip.txt" ) {
  91. print STDERR "ERROR: Unable to open skip list file.\n";
  92. die;
  93. }
  94. while (<SKIP>) {
  95. chomp;
  96. exit if lc$_ eq lc$0;
  97. }
  98. close SKIP;
  99. }
  100. if ($spoof) {
  101. # nothing to do for spoofing in XPSP builds, we're currently hardcoding $bldno=2600
  102. }
  103. # Only build if (1) -f is passed, (2) %OFFICIAL_BUILD_MACHINE% is set, or (3) %__BUILDMACHINE__% == LB6RI
  104. if (! defined $ENV{OFFICIAL_BUILD_MACHINE} && (! $force) && (uc($ENV{__BUILDMACHINE__}) ne "LB6RI") ) {
  105. print STDERR "Not building because this isn't an official build machine. Use -f to force.\n";
  106. exit 0;
  107. };
  108. print(STDERR "$0: Started. ");
  109. use strict;
  110. # use Win32;
  111. use Win32::Process;
  112. # Set %temp% as working directory
  113. Win32::SetCwd $ENV{Temp};
  114. my $time = time();
  115. my $hLogFile;
  116. my $handle;
  117. ################################################################################
  118. #
  119. # Create .tmp file so postbuild.cmd knows we're running.
  120. #
  121. ################################################################################
  122. open (hLogFile, ">$ENV{TEMP}\\ddkcabs.tmp") || die("Can't open $ENV{TEMP}\\ddkcabs.tmp for writing: $!\n");
  123. print (hLogFile "1");
  124. close (hLogFile);
  125. ################################################################################
  126. #
  127. # Find the correct logfile to use
  128. #
  129. ################################################################################
  130. # Either use the defined log file
  131. if (defined $ENV{LOGFILE}) {
  132. $handle="$ENV{LOGFILE}";
  133. # or use our default log file.
  134. } else {
  135. $handle="$ENV{TEMP}\\ddkcabs.log";
  136. }
  137. print(STDERR "Writing log to $handle.\n");
  138. ################################################################################
  139. #
  140. # Test for all conditions that require us to terminate early.
  141. #
  142. ################################################################################
  143. # If %_DDK_NOCAB% is defined, don't make CABS
  144. if (defined $ENV{_DDK_NOCAB} ) {
  145. logmsg("_DDK_NOCAB is set. Not making CABS.");
  146. unlink("$ENV{TEMP}\\ddkcabs.tmp");
  147. exit(0);
  148. }
  149. # If any of the needed environment variables aren't defined, output an
  150. # error and abort the cabbing process
  151. foreach ("_NTDRIVE","_NTROOT","_BUILDARCH","_BUILDTYPE","_NTPOSTBLD","RazzleToolPath","PROCESSOR_ARCHITECTURE","NUMBER_OF_PROCESSORS") {
  152. unless (defined $ENV{$_}) {
  153. logerror("Aborting: \%$_\% is not defined.");
  154. unlink("$ENV{TEMP}\\ddkcabs.tmp");
  155. exit(0);
  156. }
  157. }
  158. # Don't build on AXP64 or Alpha
  159. if ($ENV{_BuildArch} =~ /^(axp64|alpha)/i) {
  160. unlink("$ENV{TEMP}\\ddkcabs.tmp");
  161. logmsg("DDK unsupported on $ENV{_BuildArch}. Exiting.");
  162. exit(0);
  163. }
  164. ################################################################################
  165. #
  166. # Global Variables
  167. #
  168. ################################################################################
  169. my $bldno = 2600;
  170. #
  171. # Add QFE build num if available
  172. #
  173. if (-e "$ENV{_NTPOSTBLD}\\ddk_cd\\common\\QFE_NUM.TXT") {
  174. if ( open(hQFE,"$ENV{_NTPOSTBLD}\\ddk_cd\\common\\QFE_NUM.TXT") ) {
  175. my $QFENum = <hQFE>;
  176. close(hQFE);
  177. chomp $QFENum;
  178. $QFENum =~ s/^\s*//;
  179. $QFENum =~ s/\s*$//;
  180. $bldno = "$bldno.$QFENum";
  181. }
  182. }
  183. logdebug("$numproc processes per processor");
  184. my $MAX_PROCESSES = $ENV{NUMBER_OF_PROCESSORS}*$numproc;
  185. my @Processes;
  186. my $exe = "$ENV{RazzleToolPath}\\$ENV{PROCESSOR_ARCHITECTURE}\\cabarc.exe";
  187. my $global_param = " -s 6144 -m MSZIP -i 1 N ";
  188. my $INCREMENTAL = 0; # Full build by default
  189. my %MAKECAB;
  190. my @dir_list1;
  191. my @dir_list2;
  192. my $dir;
  193. my $dir2;
  194. my $file;
  195. my $cabname;
  196. my $samplename;
  197. my $friendlyname;
  198. my $kit;
  199. my $i;
  200. sub TRUE {return(1);} # BOOLEAN TRUE
  201. sub FALSE {return(0);} # BOOLEAN FALSE
  202. my $CABDEBUG = FALSE;
  203. $CABDEBUG = TRUE if (defined($ENV{_CABDEBUG}));
  204. my $bindir;
  205. my $sdkincs = "$ENV{_NTPOSTBLD}\\ddk_flat\\inc";
  206. # Directory to look for .lib's in
  207. my $libdir = "lib\\wxp";
  208. if (uc($ENV{_BuildArch}) eq "IA64") {
  209. $libdir .= "\\ia64";
  210. } else {
  211. $libdir .= "\\i386";
  212. }
  213. ################################################################################
  214. #
  215. # Determine if we should build incrementally
  216. #
  217. ################################################################################
  218. #
  219. # Incremental DDKs disabled for XPSP
  220. #
  221. # --------------------------------------------------------------------------
  222. # Make the samples CABs. One cab per 2nd level directory under src. Name of each cab is
  223. # the first 4 character of the first level directory + the first 6 of the second level
  224. # directory.
  225. # --------------------------------------------------------------------------
  226. SAMPLES:{
  227. foreach $kit ("ddk","ifs", "hal", "processor") {
  228. mkdir("$ENV{_NTPOSTBLD}\\${kit}_cd\\common", 777) unless (-e "$ENV{_NTPOSTBLD}\\${kit}_cd\\common");
  229. opendir(hDIR, "$ENV{_NTPOSTBLD}\\${kit}_flat\\src"); # Get the first level directories
  230. @dir_list1=readdir(hDIR);
  231. closedir(hDIR);
  232. foreach $dir (@dir_list1) {
  233. # Skip . & .. as well as non-directory files (which shouldn't be there anyhow).
  234. next unless ((-d "$ENV{_NTPOSTBLD}\\${kit}_flat\\src\\$dir") and ($dir ne ".") and ($dir ne ".."));
  235. chomp $dir;
  236. opendir(hDIR, "$ENV{_NTPOSTBLD}\\${kit}_flat\\src\\$dir"); # Get the second level directories
  237. @dir_list2=readdir(hDIR);
  238. closedir(hDIR);
  239. foreach $dir2 (@dir_list2) {
  240. # Skip . & .. as well as non-directory files (which shouldn't be there anyhow).
  241. next unless ((-d "$ENV{_NTPOSTBLD}\\${kit}_flat\\src\\$dir\\$dir2") and ($dir2 ne ".") and ($dir2 ne ".."));
  242. chomp $dir2;
  243. $cabname=sprintf("%s_%s\n",uc(substr($dir,0,4)),lc(substr($dir2,0,6)));
  244. chomp $cabname;
  245. next if (($INCREMENTAL) and (! defined $MAKECAB{$cabname}));
  246. # Create a complete listing of files under the second level directory
  247. system("dir $ENV{_NTPOSTBLD}\\${kit}_flat\\src\\$dir\\$dir2 /s/b/a-d > ${dir}${dir2}.ddk.ini 2>nul");
  248. # Create the .ini
  249. CreateCAB ("${dir}${dir2}.ddk.ini","$cabname","Samples","$dir", "$kit", "$bldno");
  250. }
  251. }
  252. }
  253. }
  254. # --------------------------------------------------------------------------
  255. DDKINCS: {
  256. if ($INCREMENTAL) {
  257. last DDKINCS unless ( defined $MAKECAB{DDKINCS} );
  258. }
  259. # Get the WXP INCS
  260. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\inc\\ddk\\wxp /s/b/a-d > ddkincs.ddk.ini 2>nul");
  261. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\inc\\ddk\\wdm\\wxp /s/b/a-d >> ddkincs.ddk.ini 2>nul");
  262. # Create the .ini
  263. CreateCAB( "ddkincs.ddk.ini","DDKINCS","Build_Environment",
  264. "DDK_Include_Files", "DDK", $bldno);
  265. # Get the W2K backport incs
  266. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\inc\\ddk\\w2k /s/b/a-d > w2k_incs.ddk.ini 2>nul");
  267. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\inc\\ddk\\wdm\\w2k /s/b/a-d >> w2k_incs.ddk.ini 2>nul");
  268. # Create the .ini
  269. CreateCAB( "w2k_incs.ddk.ini","W2K_INCS","Build_Environment",
  270. "DDK_Include_Files", "DDK", $bldno);
  271. }
  272. # --------------------------------------------------------------------------
  273. IFSINCS: {
  274. if ($INCREMENTAL) {
  275. last IFSINCS unless ( defined $MAKECAB{IFSINCS} );
  276. }
  277. system("dir $ENV{_NTPOSTBLD}\\ifs_flat\\inc /s/b/a-d > ifsincs.ddk.ini 2>nul");
  278. # Create the .ini
  279. CreateCAB( "ifsincs.ddk.ini","IFSINCS","Build_Environment",
  280. "IFS_Include_Files","IFS",$bldno);
  281. }
  282. # --------------------------------------------------------------------------
  283. PDKINCS: {
  284. if ($INCREMENTAL) {
  285. last PDKINCS unless ( defined $MAKECAB{PDKINCS} );
  286. }
  287. system("dir $ENV{_NTPOSTBLD}\\processor_flat\\inc /s/b/a-d > pdkincs.ddk.ini 2>nul");
  288. # Create the .ini
  289. CreateCAB( "pdkincs.ddk.ini","PDKINCS","Build_Environment",
  290. "PDK_Include_Files","processor",$bldno);
  291. }
  292. # --------------------------------------------------------------------------
  293. HALINCS: {
  294. if ($INCREMENTAL) {
  295. last HALINCS unless ( defined $MAKECAB{HALINCS} );
  296. }
  297. system("dir $ENV{_NTPOSTBLD}\\HAL_flat\\inc /s/b/a-d > HALincs.ddk.ini 2>nul");
  298. # Create the .ini
  299. CreateCAB( "HALincs.ddk.ini","HALINCS","Build_Environment",
  300. "HAL_Include_Files","HAL",$bldno);
  301. }
  302. # --------------------------------------------------------------------------
  303. HALBINS: {
  304. if ($INCREMENTAL) {
  305. last HALBINS unless ( defined $MAKECAB{HALBINS} );
  306. }
  307. # List all files under \inc\ddk\...
  308. system("dir $ENV{_NTPOSTBLD}\\HAL_flat\\bin /s/b/a-d > HALbins.ddk.ini 2>nul");
  309. # Create the .ini
  310. CreateCAB( "HALbins.ddk.ini","HALBINS","Build_Environment",
  311. "HAL_Binary_Files","HAL",$bldno);
  312. }
  313. # --------------------------------------------------------------------------
  314. DDKDBG: {
  315. if ($INCREMENTAL) {
  316. last DDKDBG unless ( defined $MAKECAB{DDKDBG} );
  317. }
  318. # Make DBG cabs only on CHK builds
  319. last DDKDBG if (uc $ENV{_BuildType} ne "CHK");
  320. my $plat = substr($ENV{_BUILDARCH}, 0, 1);
  321. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\debug /s/b/a-d > ddkdbg.ddk.ini 2>nul");
  322. # Create the .ini
  323. CreateCAB( "ddkdbg.ddk.ini","DDK_DBG${plat}","Build_Environment",
  324. "Extra_Debug_Files","DDK",$bldno);
  325. }
  326. # --------------------------------------------------------------------------
  327. DDKTOOLS: {
  328. if ($INCREMENTAL) {
  329. last DDKTOOLS unless ( defined $MAKECAB{DDKTOOLS} );
  330. }
  331. # We don't want to ship checked versions of the tools
  332. last DDKTOOLS if (uc $ENV{_BuildType} eq "CHK");
  333. opendir(hDIR, "$ENV{_NTPOSTBLD}\\DDK_flat\\tools"); # Get the first level directories
  334. @dir_list1=readdir(hDIR);
  335. closedir(hDIR);
  336. foreach $dir (@dir_list1) {
  337. # Skip . & .. as well as non-directory files (which shouldn't be there anyhow).
  338. next unless ((-d "$ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir") and ($dir ne ".") and ($dir ne ".."));
  339. chomp $dir;
  340. $cabname=sprintf("%s_%s\n","TOOL",lc substr($dir,0,6) );
  341. chomp $cabname;
  342. next if (($INCREMENTAL) and (! defined $MAKECAB{$cabname}));
  343. ##
  344. ## Need to handle tools on the per-arch basis. Can't just look for \%arch, since
  345. ## the tools may also have files in root. (.htm's, etc). Instead, break we'll
  346. ## break this into 3 cabs per tool, TOOL_%tool%, TOOL_%tool%x (x86) TOOL_%tool%i (ia64)
  347. ##
  348. # At tools\\$dir, now, we need all the sub dirs
  349. my @subs = `dir $ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir /s/b/ad`;
  350. my $sub;
  351. my $plat = substr($ENV{_BUILDARCH}, 0, 1);
  352. # Drop in an empty file as placeholder so we can force the general cab for this tool
  353. # to be built.
  354. system("echo. >$ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir\\.empty");
  355. # Make sure we're not appending to old .ini's
  356. unlink("TOOLS${dir}${plat}.ddk.ini") if (-e "TOOLS${dir}${plat}.ddk.ini");
  357. unlink("TOOLS${dir}.ddk.ini") if (-e "TOOLS${dir}.ddk.ini");
  358. # Now, create the .ini for the common cab
  359. foreach (`dir $ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir /b/a-d`) {
  360. chomp;
  361. system("echo $ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir\\$_ >> TOOLS${dir}.ddk.ini");
  362. }
  363. # For every subdir, if it ends in %arch%, create the arch specific cab, otherwise
  364. # create the general cab.
  365. foreach $sub (@subs) {
  366. chomp $sub;
  367. if ($sub =~ /DDK_flat\\.*\\$ENV{_BUILDARCH}/i) {
  368. system("dir $ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir /s/b/a-d >> TOOLS${dir}${plat}.ddk.ini 2>nul");
  369. } elsif ( uc($ENV{_BUILDARCH}) eq "X86" ) {
  370. # i386 is a valid alias of x86
  371. if ($sub =~ /DDK_flat\\.*\\i386/i) {
  372. system("dir $ENV{_NTPOSTBLD}\\DDK_flat\\tools\\$dir /s/b/a-d >> TOOLS${dir}${plat}.ddk.ini 2>nul");
  373. }
  374. }
  375. }
  376. # Create the cabs
  377. CreateCAB ("TOOLS${dir}.ddk.ini","${cabname}","Build_Environment","${dir}_TOOL", "ddk", "$bldno");
  378. CreateCAB ("TOOLS${dir}${plat}.ddk.ini","${cabname}${plat}","Build_Environment","${dir}_TOOL", "ddk", "$bldno")
  379. if (-e "TOOLS${dir}${plat}.ddk.ini"); # May not have arch-specific cab
  380. }
  381. }
  382. # --------------------------------------------------------------------------
  383. IFSTOOLS: {
  384. if ($INCREMENTAL) {
  385. last IFSTOOLS unless ( defined $MAKECAB{IFSTOOLS} );
  386. }
  387. # List all files under \inc\ddk\...
  388. system("dir $ENV{_NTPOSTBLD}\\IFS_flat\\tools /s/b/a-d > ifstools.ddk.ini 2>nul");
  389. # Create the .ini
  390. CreateCAB( "ifstools.ddk.ini","IFSTOOLS","Build_Environment",
  391. "Development_Tools","IFS",$bldno);
  392. }
  393. # --------------------------------------------------------------------------
  394. SDKINCS: {
  395. if ($INCREMENTAL) {
  396. last SDKINCS unless ( defined $MAKECAB{SDKINCS} );
  397. }
  398. # List all files under \inc\.
  399. opendir(hDIR, "$sdkincs");
  400. @dir_list1 = readdir(hDIR);
  401. closedir(hDIR);
  402. #
  403. # Look for all WXP specific headers
  404. #
  405. opendir(hDIR, "$sdkincs\\wxp");
  406. @dir_list2 = readdir(hDIR);
  407. closedir(hDIR);
  408. foreach (@dir_list2) {
  409. $_ = "wxp\\$_";
  410. }
  411. push(@dir_list1, @dir_list2);
  412. undef(@dir_list2);
  413. #
  414. # Look for all CRT headers
  415. #
  416. opendir(hDIR, "$sdkincs\\crt");
  417. @dir_list2 = readdir(hDIR);
  418. closedir(hDIR);
  419. foreach (@dir_list2) {
  420. $_ = "crt\\$_";
  421. }
  422. push(@dir_list1, @dir_list2);
  423. undef(@dir_list2);
  424. opendir(hDIR, "$sdkincs\\crt\\sys");
  425. @dir_list2 = readdir(hDIR);
  426. closedir(hDIR);
  427. foreach (@dir_list2) {
  428. $_ = "crt\\sys\\$_";
  429. }
  430. push(@dir_list1, @dir_list2);
  431. undef(@dir_list2);
  432. opendir(hDIR, "$sdkincs\\crt\\gl");
  433. @dir_list2 = readdir(hDIR);
  434. closedir(hDIR);
  435. foreach (@dir_list2) {
  436. $_ = "crt\\gl\\$_";
  437. }
  438. push(@dir_list1, @dir_list2);
  439. undef(@dir_list2);
  440. opendir(hDIR, "$sdkincs\\crt\\wxp");
  441. @dir_list2 = readdir(hDIR);
  442. closedir(hDIR);
  443. foreach (@dir_list2) {
  444. $_ = "crt\\wxp\\$_";
  445. }
  446. push(@dir_list1, @dir_list2);
  447. undef(@dir_list2);
  448. open(sdk1, ">sdk1.ddk.ini");
  449. open(sdk2, ">sdk2.ddk.ini");
  450. open(sdk3, ">sdk3.ddk.ini");
  451. for ($i=0;$i<=$#dir_list1;$i++) {
  452. next if ($dir_list1[$i] =~ /\.$/);
  453. next if (-d "$sdkincs\\$dir_list1[$i]");
  454. if (($i%3) == 0) {
  455. print(sdk1 "$sdkincs\\$dir_list1[$i]\n");
  456. } elsif (($i%3) == 1) {
  457. print(sdk2 "$sdkincs\\$dir_list1[$i]\n");
  458. } else {
  459. print(sdk3 "$sdkincs\\$dir_list1[$i]\n");
  460. }
  461. }
  462. close(sdk1);
  463. close(sdk2);
  464. close(sdk3);
  465. # CAB 1
  466. # Create the .ini
  467. CreateCAB( "sdk1.ddk.ini","SDKINCS1","Build_Environment",
  468. "SDK_Include_Files","DDK",$bldno);
  469. # CAB 2
  470. # Create the .ini
  471. CreateCAB( "sdk2.ddk.ini","SDKINCS2","Build_Environment",
  472. "SDK_Include_Files","DDK",$bldno);
  473. # CAB 3
  474. # Create the .ini
  475. CreateCAB( "sdk3.ddk.ini","SDKINCS3","Build_Environment",
  476. "SDK_Include_Files","DDK",$bldno);
  477. }
  478. # --------------------------------------------------------------------------
  479. DDKLIBS: {
  480. if ($INCREMENTAL) {
  481. last DDKLIBS unless ( defined $MAKECAB{DDKLIBS} );
  482. }
  483. if ( -e "$ENV{_NTPOSTBLD}\\ddk_flat\\lib\\w2k\\i386" && (uc($ENV{_BuildArch}) eq "X86")) {
  484. # List all files under \inc\ddk\...
  485. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\lib\\w2k /s/b/a-d > w2klibs.ddk.ini 2>nul");
  486. # Create the .ini
  487. CreateCAB( "w2klibs.ddk.ini","W2K_LIBS","Build_Environment",
  488. "W2K_Library_Files","DDK",$bldno);
  489. }
  490. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  491. $cabname="IA6dLIB";
  492. } else {
  493. $cabname="X86dLIB";
  494. }
  495. $samplename ="$ENV{_BuildArch}_Libraries";
  496. $friendlyname="$ENV{_BuildArch}_Libraries";
  497. # List all files under \tools
  498. opendir(hDIR, "$ENV{_NTPOSTBLD}\\ddk_flat\\$libdir");
  499. @dir_list1=readdir hDIR;
  500. closedir(hDIR);
  501. open(LIBS1, ">libs1.ddk.ini");
  502. open(LIBS2, ">libs2.ddk.ini");
  503. open(LIBS3, ">libs3.ddk.ini");
  504. for ($i=0;$i<=$#dir_list1;$i++) {
  505. next if ($dir_list1[$i] =~ /^\./);
  506. if (($i % 3) == 0) {
  507. print(LIBS1 "$ENV{_NTPOSTBLD}\\ddk_flat\\$libdir\\$dir_list1[$i]\n");
  508. } elsif (($i % 3) == 1) {
  509. print(LIBS2 "$ENV{_NTPOSTBLD}\\ddk_flat\\$libdir\\$dir_list1[$i]\n");
  510. } else {
  511. print(LIBS3 "$ENV{_NTPOSTBLD}\\ddk_flat\\$libdir\\$dir_list1[$i]\n");
  512. }
  513. }
  514. close(LIBS1);
  515. close(LIBS2);
  516. close(LIBS3);
  517. # CAB 1
  518. # Create the .ini
  519. CreateCAB( "libs1.ddk.ini","${cabname}1","Build_Environment",
  520. "${samplename}","DDK",$bldno);
  521. # CAB 2
  522. # Create the .ini
  523. CreateCAB( "libs2.ddk.ini","${cabname}2","Build_Environment",
  524. "$samplename","DDK",$bldno);
  525. # CAB 3
  526. # Create the .ini
  527. CreateCAB( "libs3.ddk.ini","${cabname}3","Build_Environment",
  528. "$samplename","DDK",$bldno);
  529. }
  530. # --------------------------------------------------------------------------
  531. IFSLIBS: {
  532. if ($INCREMENTAL) {
  533. last IFSLIBS unless ( defined $MAKECAB{IFSLIBS} );
  534. }
  535. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  536. $cabname="IA6iLIB";
  537. } else {
  538. $cabname="X86iLIB";
  539. }
  540. # List all files under \inc\ddk\...
  541. system("dir $ENV{_NTPOSTBLD}\\ifs_flat\\$libdir /s/b/a-d > ifslibs.ddk.ini 2>nul");
  542. # Create the .ini
  543. CreateCAB( "ifslibs.ddk.ini","${cabname}1","Build_Environment",
  544. "Library_Files","IFS",$bldno);
  545. }
  546. # --------------------------------------------------------------------------
  547. PDKLIBS: {
  548. if ($INCREMENTAL) {
  549. last PDKLIBS unless ( defined $MAKECAB{PDKLIBS} );
  550. }
  551. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  552. $cabname="IA6pLIB";
  553. } else {
  554. $cabname="X86pLIB";
  555. }
  556. # List all files under \inc\ddk\...
  557. system("dir $ENV{_NTPOSTBLD}\\processor_flat\\$libdir /s/b/a-d > pdklibs.ddk.ini 2>nul");
  558. # Create the .ini
  559. CreateCAB( "pdklibs.ddk.ini","${cabname}1","Build_Environment",
  560. "Library_Files","processor",$bldno);
  561. }
  562. # --------------------------------------------------------------------------
  563. HALLIBS: {
  564. if ($INCREMENTAL) {
  565. last HALLIBS unless ( defined $MAKECAB{HALLIBS} );
  566. }
  567. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  568. $cabname="IA6hLIB";
  569. } else {
  570. $cabname="X86hLIB";
  571. }
  572. # List all files under \inc\ddk\...
  573. system("dir $ENV{_NTPOSTBLD}\\hal_flat\\$libdir /s/b/a-d > hallibs.ddk.ini 2>nul");
  574. # Create the .ini
  575. CreateCAB( "hallibs.ddk.ini","${cabname}1","Build_Environment",
  576. "Library_Files","HAL",$bldno);
  577. }
  578. # --------------------------------------------------------------------------
  579. DDKBINS: {
  580. if ($INCREMENTAL) {
  581. last DDKBINS unless ( defined $MAKECAB{DDKBINS} );
  582. }
  583. $bindir ="$ENV{_NTPOSTBLD}\\ddk_flat\\bin";
  584. # List all files under bin
  585. opendir(hDIR, "$bindir"); # Get the first level directories
  586. @dir_list1=readdir(hDIR);
  587. closedir(hDIR);
  588. open(hDIR, ">cmnbins.ddk.ini");
  589. foreach $dir (@dir_list1) {
  590. # Skip . & .. as well as files.
  591. next if ( -d "$bindir\\$dir");
  592. next if (($dir eq ".") or ($dir eq ".."));
  593. print(hDIR "$bindir\\$dir\n");
  594. }
  595. close(hDIR);
  596. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\bin\\wppconfig /s/b/a-d >>cmnbins.ddk.ini 2>nul");
  597. # Create the .ini
  598. CreateCAB( "cmnbins.ddk.ini","CMNBINS","Build_Environment",
  599. "Comon_Build_Tools","DDK",$bldno);
  600. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  601. $cabname="IA6dBIN";
  602. } else {
  603. $cabname="X86bBIN";
  604. }
  605. $samplename ="$ENV{_BuildArch}_$ENV{_BuildType}_Binaries";
  606. $friendlyname="$ENV{_BuildArch}_$ENV{_BuildType}_Binaries";
  607. if (-e "$bindir\\x86") {
  608. # List all files under bin\x86
  609. opendir(hDIR, "$bindir\\x86"); # Get the first level directories
  610. @dir_list1=readdir(hDIR);
  611. closedir(hDIR);
  612. open(hDIR, ">x86bins.ddk.ini");
  613. foreach $dir (@dir_list1) {
  614. # Skip . & .. as well as directory files (which shouldn't be there anyhow).
  615. next unless ((! -d "$bindir\\x86\\$dir") and ($dir ne ".") and ($dir ne ".."));
  616. print(hDIR "$bindir\\x86\\$dir\n");
  617. }
  618. close(hDIR);
  619. # Create the .ini
  620. CreateCAB( "x86bins.ddk.ini","X86dBINS","Build_Environment",
  621. "X86_Build_Tools","DDK",$bldno);
  622. }
  623. if (-e "$bindir\\ia64") {
  624. # List all files under bin\ia64
  625. opendir(hDIR, "$bindir\\ia64"); # Get the first level directories
  626. @dir_list1=readdir(hDIR);
  627. closedir(hDIR);
  628. open(hDIR, ">ia64bins.ddk.ini");
  629. foreach $dir (@dir_list1) {
  630. # Skip . & .. as well as directory files (which shouldn't be there anyhow).
  631. next unless ((! -d "$bindir\\ia64\\$dir") and ($dir ne ".") and ($dir ne ".."));
  632. print(hDIR "$bindir\\ia64\\$dir\n");
  633. }
  634. close(hDIR);
  635. # Create the .ini
  636. CreateCAB( "ia64bins.ddk.ini","IA6dBINS","Build_Environment",
  637. "IA64_Build_Tools","DDK",$bldno);
  638. }
  639. }
  640. # --------------------------------------------------------------------------
  641. COREDDK: {
  642. if ($INCREMENTAL) {
  643. last COREDDK unless ( defined $MAKECAB{COREDDK} );
  644. }
  645. system("dir $ENV{_NTPOSTBLD}\\ddk_flat /b/a-d > core.ddk.ini 2>nul");
  646. # Create the .ini
  647. CreateCAB( "core.ddk.ini","COREDDK","Build_Environment",
  648. "DDK_Core_Files","DDK",$bldno);
  649. }
  650. # --------------------------------------------------------------------------
  651. COREPDK: {
  652. if ($INCREMENTAL) {
  653. last COREPDK unless ( defined $MAKECAB{COREPDK} );
  654. }
  655. last COREPDK unless (-e "$ENV{_NTPOSTBLD}\\processor_flat\\src\\processor");
  656. @dir_list1=`dir $ENV{_NTPOSTBLD}\\processor_flat\\src\\processor /b/a-d`;
  657. foreach (@dir_list1) {
  658. next if (m/^\s*$/);
  659. chomp;
  660. system("echo $ENV{_NTPOSTBLD}\\processor_flat\\src\\processor\\$_ >> pdkcore.ddk.ini");
  661. }
  662. # Create the .ini
  663. CreateCAB( "pdkcore.ddk.ini","COREPDK","Build_Environment",
  664. "PDK_Core_Files","processor",$bldno);
  665. }
  666. # --------------------------------------------------------------------------
  667. COREHAL: {
  668. if ($INCREMENTAL) {
  669. last COREHAL unless ( defined $MAKECAB{COREHAL} );
  670. }
  671. last COREHAL unless (-e "$ENV{_NTPOSTBLD}\\hal_flat\\src\\hals");
  672. @dir_list1=`dir $ENV{_NTPOSTBLD}\\hal_flat\\src\\hals /b/a-d`;
  673. foreach (@dir_list1) {
  674. next if (m/^\s*$/);
  675. chomp;
  676. system("echo $ENV{_NTPOSTBLD}\\hal_flat\\src\\hals\\$_ >> halcore.ddk.ini");
  677. }
  678. # Create the .ini
  679. CreateCAB( "halcore.ddk.ini","COREHAL","Build_Environment",
  680. "HAL_Core_Files","HAL",$bldno);
  681. }
  682. # --------------------------------------------------------------------------
  683. COREIFS: {
  684. if ($INCREMENTAL) {
  685. last COREIFS unless ( defined $MAKECAB{COREIFS} );
  686. }
  687. last COREIFS unless (-e "$ENV{_NTPOSTBLD}\\ifs_flat");
  688. @dir_list1=`dir $ENV{_NTPOSTBLD}\\ifs_flat\\src\\filesys /b/a-d`;
  689. foreach (@dir_list1) {
  690. next if (m/^\s*$/);
  691. chomp;
  692. system("echo $ENV{_NTPOSTBLD}\\ifs_flat\\src\\filesys\\$_ >> ifscore.ddk.ini");
  693. }
  694. # Create the .ini
  695. CreateCAB( "ifscore.ddk.ini","COREIFS","Build_Environment",
  696. "IFS_Core_Files","IFS",$bldno);
  697. }
  698. # --------------------------------------------------------------------------
  699. DDKDOCS: {
  700. if ($INCREMENTAL) {
  701. last DDKDOCS unless ( defined $MAKECAB{DDKDOCS} );
  702. }
  703. # Make the Docs
  704. opendir(hDir, "$ENV{_NTPOSTBLD}\\ddk_flat\\help")||warn("Can't open $ENV{_NTPOSTBLD}\\ddk_flat\\help: $!\n");
  705. @dir_list1=readdir(hDir);
  706. closedir(hDir);
  707. my @general_cab;
  708. foreach $file (@dir_list1) {
  709. next if ($file =~ /^\./);
  710. next if ($file =~ /\.chi$/); # Don't use .chi, use .chm below
  711. next if (-d "$ENV{_NTPOSTBLD}\\ddk_flat\\help\\$file");
  712. if ($file =~ /\.chm$/i) {
  713. # We have a .chm
  714. $file =~ s/\.chm$//i; # Remove the extension
  715. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\help\\$file.* /s/b/a-d > $file.ddk.ini 2>nul");
  716. $file=uc($file); # Force uppercase
  717. # Create the .ini
  718. CreateCAB( "$file.ddk.ini","$file","Documentation",
  719. "${file}_Doc","DDK",$bldno);
  720. } else {
  721. system("dir $ENV{_NTPOSTBLD}\\ddk_flat\\help\\$file /s/b/a-d >> general_docs.ddk.ini 2>nul");
  722. }
  723. }
  724. CreateCAB("general_docs.ddk.ini","CMNDOCS", "Documentation", "Common_Docs_Files", "DDK",$bldno);
  725. }
  726. # --------------------------------------------------------------------------
  727. IFSDOCS: {
  728. if ($INCREMENTAL) {
  729. last IFSDOCS unless ( defined $MAKECAB{IFSDOCS} );
  730. }
  731. # Make the Docs
  732. opendir(hDir, "$ENV{_NTPOSTBLD}\\ifs_flat\\help")||warn("Can't open $ENV{_NTPOSTBLD}\\ifs_flat\\help: $!\n");
  733. @dir_list1=readdir(hDir);
  734. closedir(hDir);
  735. foreach $file (@dir_list1) {
  736. next if ($file =~ /^\./);
  737. next if ($file =~ /\.chi$/); # Don't use .chi, use .chm below
  738. next if (-d "$ENV{_NTPOSTBLD}\\ifs_flat\\help\\$file");
  739. if ($file =~ /\.chm$/i) {
  740. # We have a .chm
  741. $file =~ s/\.chm$//i; # Remove the extension
  742. system("dir $ENV{_NTPOSTBLD}\\ifs_flat\\help\\$file.* /s/b/a-d > $file.ddk.ini 2>nul");
  743. $file=uc($file); # Force uppercase
  744. # Create the .ini
  745. CreateCAB( "$file.ddk.ini","$file","Documentation",
  746. "${file}_Doc","IFS",$bldno);
  747. } else {
  748. logdebug("Not including \\help\\$file\n");
  749. }
  750. }
  751. }
  752. # Don't exit until all subprocesses have completed.
  753. WaitForAllProcesses();
  754. if (-e "$ENV{_NTPOSTBLD}\\ddk_cd\\common\\cabs.in_") {
  755. system("copy $ENV{_NTPOSTBLD}\\ddk_cd\\common\\cabs.in_ $ENV{_NTPOSTBLD}\\ddk_cd\\common\\cabs.ini >nul");
  756. open(hF, ">>$ENV{_NTPOSTBLD}\\ddk_cd\\common\\cabs.ini");
  757. print(hF "Build=$bldno\n");
  758. close(hF);
  759. }
  760. if (-e "$ENV{_NTPOSTBLD}\\ifs_cd\\common\\cabs.in_") {
  761. system("copy $ENV{_NTPOSTBLD}\\ifs_cd\\common\\cabs.in_ $ENV{_NTPOSTBLD}\\ifs_cd\\common\\cabs.ini >nul");
  762. open(hF, ">>$ENV{_NTPOSTBLD}\\ifs_cd\\common\\cabs.ini");
  763. print(hF "Build=$bldno\n");
  764. close(hF);
  765. }
  766. if (-e "$ENV{_NTPOSTBLD}\\hal_cd\\common\\cabs.in_") {
  767. system("copy $ENV{_NTPOSTBLD}\\hal_cd\\common\\cabs.in_ $ENV{_NTPOSTBLD}\\hal_cd\\common\\cabs.ini >nul");
  768. open(hF, ">>$ENV{_NTPOSTBLD}\\hal_cd\\common\\cabs.ini");
  769. print(hF "Build=$bldno\n");
  770. close(hF);
  771. }
  772. if (-e "$ENV{_NTPOSTBLD}\\processor_cd\\common\\cabs.in_") {
  773. system("copy $ENV{_NTPOSTBLD}\\processor_cd\\common\\cabs.in_ $ENV{_NTPOSTBLD}\\processor_cd\\common\\cabs.ini >nul");
  774. open(hF, ">>$ENV{_NTPOSTBLD}\\processor_cd\\common\\cabs.ini");
  775. print(hF "Build=$bldno\n");
  776. close(hF);
  777. }
  778. $time = time() - $time;
  779. logmsg("Total run time: $time seconds.\n");
  780. print(STDERR "$0: Finished.\n\n");
  781. END {
  782. # Delete .tmp file so postbuild.cmd knows the script has finished
  783. unlink ("$ENV{TEMP}\\ddkcabs.tmp");
  784. }
  785. # --------------------------------------------------------------------------
  786. # Creates a CAB and INF from a list of files
  787. # --------------------------------------------------------------------------
  788. sub CreateCAB {
  789. print(".") unless ($verbose); # Print something so the user knows the script is still running
  790. my $filelist = shift;
  791. my $cabname = shift;
  792. my $groupname = shift;
  793. my $samplename = shift;
  794. my $kit = shift;
  795. my $bldno = shift;
  796. my $FileIndex = -1;
  797. my $friendlyname = $samplename;
  798. my $GroupIndex = -1;
  799. my $InfCopyFileList = "InfFiles";
  800. my $PrevCommand = "";
  801. my $PrevDestDir = "";
  802. my $TotalSize = 0;
  803. my @files;
  804. my $file;
  805. my $FileProcessed;
  806. my $hFILE;
  807. my $NewSection;
  808. my $source_file;
  809. my $source_dir;
  810. my $dest_dir;
  811. my $ERRORLEVEL;
  812. my $FileSize;
  813. my $CabFileName;
  814. chomp($cabname);
  815. unless (-e $filelist) {
  816. logerror("$filelist did not exist - cannot build cab.");
  817. return(5);
  818. }
  819. # These files get rolled into the INF once the entire filelist
  820. # is processed.
  821. open(hFILE, ">${cabname}_DestDirsFiles")
  822. || die("Couldn't write to ${cabname}_DestDirsFile: $!\n");
  823. printf(hFILE "[DestinationDirs]\n");
  824. close(hFILE);
  825. open(hFILE, ">${cabname}_SourceFiles")
  826. || die("Couldn't write to ${cabname}_SourceFiles: $!\n");
  827. printf(hFILE "\n");
  828. close(hFILE);
  829. open(hFILE, ">${cabname}_SourceDisk")
  830. || die("Couldn't write to ${cabname}_SourceDisk: $!\n");
  831. printf(hFILE "[SourceDisksFiles]\n");
  832. close(hFILE);
  833. #
  834. # Process the filelist
  835. #
  836. open(hFILE, "$filelist");
  837. @files=<hFILE>;
  838. close(hFILE);
  839. # For every file in the list, split it up into the format expected by genddkcab.bat:
  840. # $source_dir, $source_file, $dest_dir, $dest_file, $command
  841. foreach $file (@files) {
  842. chomp($file);
  843. $file =~ m/^(.*)\\.*$/;
  844. # source_dir is %_NTPOSTBLD%\[ddk|hal|ifs]_flat + dest_dir
  845. if (! defined($1)) {
  846. $source_dir = "$ENV{_NTPOSTBLD}\\ddk_flat";
  847. } else {
  848. $source_dir = $1;
  849. }
  850. $file =~ m/^.*\\(.*)$/;
  851. # source_file is filename
  852. if (! defined($1)) {
  853. $source_file = $file;
  854. } else {
  855. $source_file = $1;
  856. }
  857. $file =~ m/^.*_flat(\\.*\\).*$/;
  858. # dest_dir is dir less %_NTPOSTBLD%\[ddk|hal|ifs]_flat
  859. if (! defined($1)) {
  860. $dest_dir= "\\";
  861. } else {
  862. $dest_dir= $1;
  863. }
  864. $FileProcessed=FALSE;
  865. # Optimization to not generate excessive install sections in the inf.
  866. $NewSection=TRUE;
  867. $NewSection=FALSE if (uc($dest_dir) eq uc($PrevDestDir));
  868. $PrevDestDir=$dest_dir;
  869. if ($NewSection) {
  870. $GroupIndex+=1;
  871. open(hDDF, ">>${cabname}_DestDirsFiles");
  872. printf(hDDF "Files_${GroupIndex}=49000,\"$dest_dir\"\n");
  873. close(hDDF);
  874. $InfCopyFileList="${InfCopyFileList},Files_${GroupIndex}";
  875. open(hDDF, ">>${cabname}_SourceFiles");
  876. printf(hDDF "[Files_${GroupIndex}]\n");
  877. close(hDDF);
  878. }
  879. if (! -e "$source_dir\\$source_file") {
  880. logerror("489: File $source_dir\\$source_file does not exist");
  881. next;
  882. }
  883. # Move on to the next file number
  884. $FileIndex += 1;
  885. # Generate the name of the file within the cabfile.
  886. $CabFileName="${cabname}_FILE_${FileIndex}";
  887. # process the source file into the temporary cabfile name
  888. $ERRORLEVEL=system("COPY $source_dir\\$source_file $CabFileName >nul 2>nul");
  889. # check for errors
  890. if ($ERRORLEVEL) {
  891. logerror("545: COPY of file $source_dir\\$source_file failed (ErrorLevel $ERRORLEVEL)");
  892. }
  893. # Get the size of the file, so the size requirements of the cab can be computed.
  894. $FileSize = (stat("$CabFileName"))[7];
  895. printf("adding $CabFileName size $FileSize\n") if ($CABDEBUG);
  896. $TotalSize += $FileSize;
  897. # Write the DestinationFileName, CabFileName into the inf so the files
  898. # can be extracted and installed properly.
  899. open(hDDF, ">>${cabname}_SourceDisk")
  900. || die("Couldn't write to ${cabname}_SourceDisk: $!\n");;
  901. printf(hDDF "${CabFileName}=1,,$FileSize\n");
  902. close(hDDF);
  903. open(hDDF, ">>${cabname}_SourceFiles");
  904. printf(hDDF "$source_file,$CabFileName,,\n");
  905. close(hDDF);
  906. }
  907. # If there were not files, just leave
  908. if ($FileIndex == -1) {
  909. logdebug("241: Skipping $cabname - no files in the cab");
  910. unlink("$filelist") ||die("$!\n");;
  911. unlink("${cabname}_SourceFiles") ||die("$!\n");;
  912. unlink("${cabname}_SourceDisk") ||die("$!\n");;
  913. unlink("${cabname}_DestDirsFiles")||die("$!\n");;
  914. return(15);
  915. }
  916. if ($verbose) {
  917. print STDERR "Creating $cabname\n";
  918. }
  919. # Create the INF
  920. CreateINF($cabname, $friendlyname, $InfCopyFileList, $FileIndex, $TotalSize);
  921. # start cabarc
  922. CreateNewProcess($cabname, $kit);
  923. # Delete the temporary file list
  924. unlink("$filelist");
  925. return(1);
  926. }
  927. # --------------------------------------------------------------------------
  928. # Builds the installation inf
  929. # --------------------------------------------------------------------------
  930. sub CreateINF {
  931. my $CabName = shift;
  932. my $FriendlyName = shift;
  933. my $InfCopyFileList = shift;
  934. my $FileIndex = shift;
  935. my $TotalSize = shift;
  936. my @lines;
  937. open(hFILE, ">>${CabName}.inf")||return(25);
  938. print hFILE<<EOF;
  939. [Version]
  940. AdvancedInf = 2
  941. Signature =\"\$CHICAGO\$\"
  942. SetupClass = Base
  943. [DefaultInstall]
  944. CopyFiles=${InfCopyFileList}
  945. CustomDestination= PDCDest
  946. RequiredEngine = setupapi;
  947. AddReg = RegVersion,DocKey
  948. [DefaultUninstall]
  949. DelFiles=${InfCopyFileList}
  950. CustomDestination= PDCDest
  951. DelReg = RegVersion,DocKey
  952. EOF
  953. open(hADDFILE, "<${CabName}_DestDirsFiles");
  954. @lines=<hADDFILE>;
  955. close(hADDFILE);
  956. foreach (@lines) {
  957. printf(hFILE "$_");
  958. }
  959. unlink("${CabName}_DestDirsFiles")||die("$!\n");;
  960. print hFILE<<EOF;
  961. InfFiles=17,\"msddk\\${bldno}\"
  962. DefaultDestDir=49000,\"${CabName}\"
  963. [RegVersion]
  964. \"HKLM\",\"SOFTWARE\\Microsoft\\WINDDK\\Restart\\Cabs\",\"${CabName}\",0,\"done\"
  965. [PDCDest]
  966. 49000,49001,49002=SDKCust, 17
  967. [SDKCust]
  968. ;if key below exists, use this string to seed install path
  969. \"HKLM\", \"Software\\Microsoft\\WINDDK\", \"SFNDirectory\",,\"%DefaultDir%\"
  970. [DocKey]
  971. [InfFiles]
  972. ${CabName}.inf
  973. EOF
  974. open(hADDFILE, "<${CabName}_SourceFiles");
  975. @lines=<hADDFILE>;
  976. close(hADDFILE);
  977. foreach (@lines) {
  978. printf(hFILE "$_");
  979. }
  980. unlink("${CabName}_SourceFiles")||die("$!\n");;
  981. printf(hFILE "\n");
  982. printf(hFILE "[SourceDisksNames]\n");
  983. printf(hFILE "1=\"${CabName}.cab\",${CabName}.cab,0\n");
  984. open(hADDFILE, "<${CabName}_SourceDisk");
  985. @lines=<hADDFILE>;
  986. close(hADDFILE);
  987. foreach (@lines) {
  988. printf(hFILE "$_");
  989. }
  990. unlink("${CabName}_SourceDisk")||die("$!\n");
  991. $FileIndex++;
  992. printf(hFILE "\n\n");
  993. printf(hFILE "[Strings]\n");
  994. printf(hFILE "FriendlyName=${FriendlyName}\n");
  995. printf(hFILE "AppKey=SOFTWARE\\Microsoft\\WINDDK\n");
  996. printf(hFILE "FileCount=${FileIndex}\n");
  997. printf(hFILE "TotalSize=${TotalSize}\n");
  998. close(hFILE);
  999. return(0);
  1000. }
  1001. # --------------------------------------------------------------------------
  1002. # Starts a new process once there is room in the process table
  1003. # --------------------------------------------------------------------------
  1004. sub CreateNewProcess {
  1005. my $CabName = shift;
  1006. my $kit = shift;
  1007. my $ERRORLEVEL = 0;
  1008. my $ExitCode = 0;
  1009. my $i;
  1010. # Limit total running processes- label/goto construct needed because otherwise
  1011. # all processes are tested for instead of just finding the first one that has
  1012. # finished.
  1013. top:
  1014. while (@Processes >= $MAX_PROCESSES) {
  1015. for ($i=0;$i<=$#Processes;$i++) {
  1016. $Processes[$i][0]->GetExitCode( $ExitCode );
  1017. if ($ExitCode != 259 ) {
  1018. # Do post processes commands before removing it
  1019. $ERRORLEVEL= system("move /Y $Processes[$i][1].CAB $ENV{_NTPOSTBLD}\\$Processes[$i][2]_cd\\Common >nul 2>nul");
  1020. logerror("341: $Processes[$i][1].CAB could not be placed") if ($ERRORLEVEL);
  1021. $ERRORLEVEL= system("move /Y $Processes[$i][1].INF $ENV{_NTPOSTBLD}\\$Processes[$i][2]_cd\\Common >nul 2>nul");
  1022. logerror("342: $Processes[$i][1].INF could not be placed") if ($ERRORLEVEL);
  1023. $ERRORLEVEL=system("del /f $Processes[$i][1]_FILE_* 2>nul");
  1024. splice(@Processes,$i,1);
  1025. $i--; # Decrement count since the array changed
  1026. goto top;
  1027. }
  1028. }
  1029. sleep(2);
  1030. }
  1031. # Create the new process
  1032. Win32::Process::Create($i, $exe, "$exe $global_param ${CabName}.cab ${CabName}_FILE_*",
  1033. 0, DETACHED_PROCESS, "$ENV{TEMP}");
  1034. # Update the process table
  1035. push(@Processes, [$i,$CabName,$kit]);
  1036. }
  1037. # --------------------------------------------------------------------------
  1038. # Waits for all currently running processes to finish
  1039. # --------------------------------------------------------------------------
  1040. sub WaitForAllProcesses {
  1041. my $i;
  1042. my $ERRORLEVEL = 0;
  1043. for ($i=0;$i<=$#Processes;$i++) {
  1044. # Wait for current process to end
  1045. print(".") unless ($verbose);
  1046. $Processes[$i][0]->Wait( INFINITE );
  1047. # Do post processes commands
  1048. $ERRORLEVEL= system("move /Y $Processes[$i][1].CAB $ENV{_NTPOSTBLD}\\$Processes[$i][2]_cd\\Common >nul 2>nul");
  1049. $ERRORLEVEL+=system("move /Y $Processes[$i][1].INF $ENV{_NTPOSTBLD}\\$Processes[$i][2]_cd\\Common >nul 2>nul");
  1050. logerror(__LINE__.": $Processes[$i][1] could not be placed") if ($ERRORLEVEL);
  1051. $ERRORLEVEL=system("del /f $Processes[$i][1]_FILE_* 2>nul");
  1052. }
  1053. print("\n");
  1054. }
  1055. # --------------------------------------------------------------------------
  1056. # Error logging routines
  1057. # --------------------------------------------------------------------------
  1058. sub logdebug { my($errormsg)="DEBUG_MSG : @_";
  1059. logprint($errormsg);
  1060. return(TRUE);}
  1061. sub logerror { my($errormsg)="ERROR_MSG : @_";
  1062. logprint($errormsg);
  1063. return(TRUE);}
  1064. sub logmsg { my($errormsg)="BUILD_MSG : @_";
  1065. logprint($errormsg);
  1066. return(TRUE);}
  1067. sub logprint { open(hLogFile,">>$handle")||warn("@_\n");
  1068. printf(hLogFile "$0 : @_\n");
  1069. close(hLogFile);
  1070. return(TRUE);}
  1071. # --------------------------------------------------------------------------
  1072. # Program description and usage
  1073. # --------------------------------------------------------------------------
  1074. sub Usage {
  1075. print "
  1076. Usage: $0 [-n <N>] [-f] [-l <language>] [-s] [-v]
  1077. This tool requires a Razzle window.
  1078. Generates CABs for the Kernelmode Development Kits. N, which is
  1079. optional, indicates the number of processes to start per processor.
  1080. The default value is 2.
  1081. By default, $0 will exit early if the environment variable
  1082. OFFICAL_BUILD_MACHINE is not defined. To override this behavior,
  1083. and for CAB generation, use -F.
  1084. -L is used, and any language other than 'usa' is passed, CAB
  1085. generation will not take place.
  1086. -V turns on verbose mode. See what cabs are being built.
  1087. -S spoofs full postbuild. (DDKCabs.bat otherwise relies upon build_number.cmd)
  1088. Dependencies:
  1089. o The following environment variables are expected to be defined:
  1090. %_NTDRIVE%, %_NTROOT%, %_BUILDARCH%, %_BUILDTYPE%, %_NTPOSTBLD%,
  1091. %RazzleToolPath%, %NUMBER_OF_PROCESSORS%, %TEMP%, and
  1092. %PROCESSOR_ARCHITECTURE%.
  1093. o The following directory trees are assumed to exist:
  1094. 1) %_NTPOSTBLD%\\ddk_cd
  1095. 2) %_NTPOSTBLD%\\ddk_flat
  1096. 3) %_NTPOSTBLD%\\ifs_cd
  1097. 4) %_NTPOSTBLD%\\ifs_flat
  1098. 5) %_NTPOSTBLD%\\hal_cd
  1099. 6) %_NTPOSTBLD%\\hal_flat
  1100. ";
  1101. return(30);
  1102. }
  1103. # --------------------------------------------------------------------------
  1104. # List dependencies needed for this script.
  1105. # --------------------------------------------------------------------------
  1106. sub Dependencies {
  1107. if ( !open DEPEND, ">>$ENV{_NTPOSTBLD}\\..\\build_logs\\dependencies.txt" ) {
  1108. print STDERR "ERROR: Unable to open dependency list file.\n";
  1109. die;
  1110. }
  1111. print DEPEND<<DEPENDENCIES;
  1112. \[$0\]
  1113. IF {...} ADD {}
  1114. DEPENDENCIES
  1115. close DEPEND;
  1116. exit;
  1117. }
  1118. __END__
  1119. :endofperl