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.

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