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.

546 lines
20 KiB

  1. @perl -x -w %0 %*
  2. @goto :eof
  3. #!perl
  4. # Copyright 1999 Microsoft Corporation
  5. ################################################################################
  6. #
  7. # Script begins here. Above is overhead to make a happy batch file.
  8. #
  9. # Revision history:
  10. # 5/18/00 - Use binplace instead of copy for all 'COPY*' ops. except when
  11. # renaming the file.
  12. # 11/10/00 - CopyLIB no longer uses lib[fre|chk]. Now just goes to lib in
  13. # order to match razzle more closely
  14. ################################################################################
  15. use strict;
  16. my($WarnLevel);
  17. #if (@ARGV != 3 ) {
  18. # print(STDERR "Usage: $0 <ini_file> <kit_name> [ProjectRoot value]\n");
  19. # exit(0);
  20. #}
  21. die ("nmake : $0: DDK_ERROR_FATAL: ProjectRoot is not defined. Aborting DDK scripts.\n") unless defined($ARGV[2]);
  22. die ("nmake : $0: DDK_ERROR_FATAL: Kit is not defined. Aborting DDK scripts.\n") unless defined($ARGV[1]);
  23. # ---------------------------------------------------------
  24. # Make sure our dependent variables are defined.
  25. # ---------------------------------------------------------
  26. if (! defined $ENV{_NTTREE}) {
  27. print(STDERR "$0 \%_NTTREE\% not defined - assuming a 'no_binaries' build. Script aborted.\n");
  28. exit(0);
  29. }
  30. # ---------------------------------------------------------
  31. # The default is to build samples on X86Fre machines only.
  32. # Set _DDK_SAMPLES = FALSE to disable
  33. # ---------------------------------------------------------
  34. if (defined $ENV{_NO_DDK}) {
  35. print("BUILDMSG: $0: Not building the DDK because \%_NO_DDK\% is set.\n");
  36. exit(0);
  37. }
  38. #
  39. # Setting the warning level based on %_DDK_WARN_LEVEL%, else default to
  40. # 0. Valid values are 0-4 with increasingly restrictive checking.
  41. #
  42. # All level 0 errors and warnings are DDK requirements.
  43. #
  44. if (defined($ENV{_DDK_WARN_LEVEL})) {
  45. if ($ENV{_DDK_WARN_LEVEL} =~ /^\d*$/) {
  46. if (($ENV{_DDK_WARN_LEVEL} >= 0) && ($ENV{_DDK_WARN_LEVEL} <= 4)) {
  47. $WarnLevel = $ENV{_DDK_WARN_LEVEL};
  48. } else {
  49. warn("\%_DDK_WARN_LEVEL\% out of range. (Expected 0-4). Using default value.\n");
  50. }
  51. } else {
  52. warn("\%_DDK_WARN_LEVEL\% is not numeric. Using default value.\n");
  53. }
  54. } else {
  55. $WarnLevel = 0;
  56. }
  57. $0 =~ /.*\\(.*)$/;
  58. $0=$1 if (defined($1));
  59. sub FALSE {return(0);} # BOOLEAN FALSE
  60. sub TRUE {return(1);} # BOOLEAN TRUE
  61. #
  62. # Global variables
  63. #
  64. my($Version) = "2000.02.29.1"; # Version of this file (YYYY.MM.DD.#)
  65. my($DEBUG) = FALSE; # Set to TRUE for testing
  66. my($ini_file)=$ARGV[0]; # File we're processing
  67. my($hFILE, $hDIR); # File handle, Directory handle
  68. my($kit) =$ARGV[1]; # Kit file is for
  69. my(@lines_to_process); # Array to hold file contents
  70. my($current_line); # Hold ini line to be processed
  71. my($cur_line_num)=0; # Count which line we're on
  72. my($token,@dirs); # Temp Var
  73. my($dest_root); # Root to base destination on
  74. my($cd_root); # Root to CD image of kit
  75. my($hsplit);
  76. my(@files); # Array for directory-level ops
  77. my($ProjectRoot)=$ARGV[2]; # Root of the project use
  78. $dest_root="$ENV{_NTTREE}\\${kit}_flat";
  79. $cd_root ="$ENV{_NTTREE}\\${kit}_cd";
  80. my($source_dir, $source_file); # Contents of the current line
  81. my($dest_dir, $dest_file, $operation);
  82. # Make sure our tree exists
  83. system("mkdir $dest_root 2> NUL");
  84. system("mkdir $cd_root 2> NUL");
  85. #
  86. # Open the ini, slurp the contents to an array, close the ini
  87. #
  88. open(hFILE, $ini_file) || die("nmake : $0: DDK_ERROR_FATAL: $ini_file could not be opened!\n");
  89. print("Processing $ini_file...\n");
  90. @lines_to_process = <hFILE>;
  91. close(hFILE);
  92. #
  93. # Loop through the contents
  94. #
  95. foreach $current_line (@lines_to_process) {
  96. chomp $current_line;
  97. $cur_line_num++;
  98. # If the first character on the line is a ';' or is blank, skip it
  99. next if ($current_line =~ /^[\s\t]*\;/);
  100. next if (($current_line =~ /^[\s\t]*$/) or ($current_line =~ /^$/));
  101. # Swap out environment variables
  102. while ($current_line =~ /\%(.+?)\%/) {
  103. $token=$1;
  104. $current_line =~ s/\%$token\%/$ENV{$token}/;
  105. }
  106. if ($current_line =~ /\%PROJECT_ROOT\%/i) {
  107. warn("BUILDMSG: Warning $0: DDK_WARNING: Correct reference to \%_DDK_CONTENT\% ($ini_file: $cur_line_num) \n");
  108. next;
  109. }
  110. ($source_dir, $source_file, $dest_dir, $dest_file, $operation) =
  111. split(/,/,$current_line);
  112. #
  113. # Break on undefined op!
  114. #
  115. if (not defined $operation) {
  116. warn("BUILDMSG: Warning $0: DDK_WARNING: Line is malformed ($ini_file: $cur_line_num) \n");
  117. next;
  118. }
  119. $source_dir =~ s/^[\s\t]*//; # Kill leading and trailing spaces
  120. $source_dir =~ s/[\s\t]*$//;
  121. $source_dir =~ s/^/$ProjectRoot\\/;
  122. $source_file=~ s/^[\s\t]*//; # Kill leading and trailing spaces
  123. $source_file=~ s/[\s\t]*$//;
  124. $dest_dir =~ s/^[\s\t]*//; # Kill leading and trailing spaces
  125. $dest_dir =~ s/[\s\t]*$//;
  126. $dest_file =~ s/^[\s\t]*//; # Kill leading and trailing spaces
  127. $dest_file =~ s/[\s\t]*$//;
  128. $operation =~ s/^[\s\t]*//; # Kill leading and trailing spaces
  129. $operation =~ s/[\s\t]*$//;
  130. ###############################################
  131. #+-------------------------------------------+#
  132. #| DDK ERROR REPORTING RULES SHOULD GO HERE! |#
  133. #+-------------------------------------------+#
  134. ###############################################
  135. # This variable was only valid during porting/testing.
  136. if ($current_line =~ /\%_DDK_CONTENT\%/i) {
  137. warn("BUILDMSG: Warning $0: DDK_WARNING: Correct reference to \%_DDK_CONTENT\% ($ini_file: $cur_line_num) \n");
  138. next;
  139. }
  140. # Don't allow files that have 'internal' in the source path
  141. if ($source_dir =~ /internal/i) {
  142. # except termsrv.
  143. if ($kit eq "termsrv") {
  144. # termsrv ddk is exception to above rule, this ddk goes only to citrix.
  145. }
  146. else {
  147. warn("nmake : $0: DDK_ERROR: Attempting to copy a file from path with 'internal' ($ini_file: $cur_line_num)\n");
  148. next;
  149. }
  150. }
  151. # Watch what gets copied to %NTDDK%\inc
  152. if (($dest_dir =~ /^inc$/i) and
  153. (($source_dir !~ /public.*inc?/) and ($source_dir !~ /legacy_files/i) and ($source_dir !~ /sdktools\\ddk\\inc$/i)))
  154. {
  155. warn("nmake : $0: DDK_ERROR: Only files from the public depot can be copied into the \%DDK_ROOT\%\\incs directory. ($ini_file: $cur_line_num)\n");
  156. next;
  157. }
  158. # Look for files marked with MS Confidential
  159. (CheckForMSConfidential("${source_dir}","${source_file}")||next) unless ($operation =~ /^COPYLIB/i);
  160. #####################################################################
  161. #+-----------------------------------------------------------------+#
  162. #| |#
  163. #| Remainder of script 'does the right thing' based on $operation. |#
  164. #| |#
  165. #+-----------------------------------------------------------------+#
  166. #####################################################################
  167. #
  168. # COPYX86CHK - Use COPYX86 if platform is CHK
  169. #
  170. if (uc($operation) eq "COPYX86CHK") {
  171. if (uc($ENV{_BUILDTYPE}) eq "CHK") {
  172. $operation = "COPYX86";
  173. } else {
  174. next;
  175. }
  176. }
  177. #
  178. # COPYX86FRE - Use COPYX86 if platform is FRE
  179. #
  180. if (uc($operation) eq "COPYX86FRE") {
  181. if (uc($ENV{_BUILDTYPE}) eq "FRE") {
  182. $operation = "COPYX86";
  183. } else {
  184. next;
  185. }
  186. }
  187. #
  188. # COPYAMD64CHK - Use COPYAMD64 if platform is CHK
  189. #
  190. if (uc($operation) eq "COPYAMD64CHK") {
  191. if (uc($ENV{_BUILDTYPE}) eq "CHK") {
  192. $operation = "COPYAMD64";
  193. } else {
  194. next;
  195. }
  196. }
  197. #
  198. # COPYAMD64FRE - Use COPYAMD64 if platform is FRE
  199. #
  200. if (uc($operation) eq "COPYAMD64FRE") {
  201. if (uc($ENV{_BUILDTYPE}) eq "FRE") {
  202. $operation = "COPYAMD64";
  203. } else {
  204. next;
  205. }
  206. }
  207. #
  208. # COPYIA64CHK - Use COPYIA64 if platform is CHK
  209. #
  210. if (uc($operation) eq "COPYIA64CHK") {
  211. if (uc($ENV{_BUILDTYPE}) eq "CHK") {
  212. $operation = "COPYIA64";
  213. } else {
  214. next;
  215. }
  216. }
  217. #
  218. # COPYIA64FRE - Use COPYIA64 if platform is FRE
  219. #
  220. if (uc($operation) eq "COPYIA64FRE") {
  221. if (uc($ENV{_BUILDTYPE}) eq "FRE") {
  222. $operation = "COPYIA64";
  223. } else {
  224. next;
  225. }
  226. }
  227. #
  228. # COPYX86 - Use COPY if platform is x86
  229. #
  230. if (uc($operation) eq "COPYX86") {
  231. if (uc($ENV{_BUILDARCH}) eq "X86") {
  232. $operation = "COPY";
  233. } else {
  234. next;
  235. }
  236. }
  237. #
  238. # COPYAMD64 - Use COPY if platform is AMD64
  239. #
  240. if (uc($operation) eq "COPYAMD64") {
  241. if (uc($ENV{_BUILDARCH}) eq "AMD64") {
  242. $operation = "COPY";
  243. } else {
  244. next;
  245. }
  246. }
  247. #
  248. # COPYIA64 - Use COPY if platform is IA64
  249. #
  250. if (uc($operation) eq "COPYIA64") {
  251. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  252. $operation = "COPY";
  253. } else {
  254. next;
  255. }
  256. }
  257. #
  258. # COPYLIB32 - Do the right thing with libs on 32-bit platforms
  259. #
  260. if (uc($operation) eq "COPYLIB32") {
  261. if (uc($ENV{_BUILDARCH}) eq "X86") {
  262. $operation = "COPYLIB";
  263. } else {
  264. next;
  265. }
  266. }
  267. #
  268. # COPYLIB64 - Do the right thing with libs on 64-bit platforms
  269. #
  270. if (uc($operation) eq "COPYLIB64") {
  271. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  272. $operation = "COPYLIB";
  273. } elsif (uc($ENV{_BUILDARCH}) eq "AMD64") {
  274. $operation = "COPYLIB";
  275. } else {
  276. next;
  277. }
  278. }
  279. #
  280. # COPYLIBAMD64 - Do the right thing with libs on AMD64 64-bit platforms
  281. #
  282. if (uc($operation) eq "COPYLIBAMD64") {
  283. if (uc($ENV{_BUILDARCH}) eq "AMD64") {
  284. $operation = "COPYLIB";
  285. } else {
  286. next;
  287. }
  288. }
  289. #
  290. # COPYLIBIA64 - Do the right thing with libs on IA64 64-bit platforms
  291. #
  292. if (uc($operation) eq "COPYLIBIA64") {
  293. if (uc($ENV{_BUILDARCH}) eq "IA64") {
  294. $operation = "COPYLIB";
  295. } else {
  296. next;
  297. }
  298. }
  299. #
  300. # COPYLIB - Do the right thing with libs
  301. #
  302. if (uc($operation) eq "COPYLIB") {
  303. # Determine base dest_dir
  304. $dest_dir = "lib\\wxp";
  305. # Determine subdir for both dest and source
  306. if (uc($ENV{_BUILDARCH}) eq "X86") {
  307. $source_dir .= "\\i386";
  308. $dest_dir .= "\\i386";
  309. } elsif (uc($ENV{_BUILDARCH}) eq "AMD64") {
  310. $source_dir .= "\\amd64";
  311. $dest_dir .= "\\amd64";
  312. } elsif (uc($ENV{_BUILDARCH}) eq "IA64") {
  313. $source_dir .= "\\ia64";
  314. $dest_dir .= "\\ia64";
  315. }
  316. $operation = "COPY";
  317. }
  318. ## Uncomment the following line to turn off HSPLITting
  319. ##$operation = "COPY" if (uc($operation) eq "HSPLIT");
  320. # Always make sure the destination dir exists. A little wastefull, but worthwhile
  321. if (uc($operation) eq "COPYCDFILE") {
  322. $token="$cd_root";
  323. } else {
  324. $token="$dest_root";
  325. }
  326. @dirs=split(/\\/,$dest_dir);
  327. foreach (@dirs) {
  328. next if (/.:/);
  329. $token.="\\$_";
  330. system("md $token 2>NUL") unless -e($token);
  331. }
  332. #
  333. # COPY
  334. #
  335. if (uc($operation) eq "COPY") {
  336. if ($dest_file eq "*") {
  337. if ($source_file =~ "[\*|\?]+") {
  338. warn("nmake : $0: DDK_ERROR: ${source_dir} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}"));
  339. system("binplace -e -:DEST $dest_dir -r ${dest_root} ${source_dir}\\${source_file}");
  340. } else {
  341. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  342. system("binplace -e -:DEST $dest_dir -r ${dest_root} ${source_dir}\\${source_file}");
  343. }
  344. } else {
  345. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  346. system("copy /y ${source_dir}\\${source_file} ${dest_root}\\${dest_dir}\\${dest_file} > NUL");
  347. }
  348. #
  349. # COPYCDFILE
  350. # use binplace -f to force the updates.
  351. } elsif (uc($operation) eq "COPYCDFILE") {
  352. if ($dest_file eq "*") {
  353. if ($source_file =~ "[\*|\?]+") {
  354. warn("nmake : $0: DDK_ERROR: ${source_dir} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}"));
  355. system("binplace -f -e -:DEST ${dest_dir} -r ${cd_root} ${source_dir}\\${source_file}");
  356. } else {
  357. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  358. system("binplace -f -e -:DEST ${dest_dir} -r ${cd_root} ${source_dir}\\${source_file}");
  359. }
  360. } else {
  361. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  362. system("copy /y ${source_dir}\\${source_file} ${cd_root}\\${dest_dir}\\${dest_file} >NUL");
  363. }
  364. #
  365. # APPENDCDFILE
  366. # ugly hack, but should only be used for cabs.ini. If it gets more use, this should be
  367. # made more efficent.
  368. } elsif (uc($operation) eq "APPENDCDFILE") {
  369. if ($dest_file eq "*") {
  370. if ($source_file =~ "[\*|\?]+") {
  371. warn("nmake : $0: DDK_ERROR: APPENDCDFILE cannot be used on wildcards.");
  372. next;
  373. } else {
  374. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  375. system("cat -o ${source_dir}\\${source_file} >> ${cd_root}\\${dest_dir}\\${dest_file} 2>NUL");
  376. }
  377. } else {
  378. warn("nmake : $0: DDK_ERROR: ${source_file} not found. ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  379. system("cat -o ${source_dir}\\${source_file} >> ${cd_root}\\${dest_dir}\\${dest_file} 2>NUL");
  380. }
  381. #
  382. # HSPLIT
  383. #
  384. } elsif (uc($operation) eq "HSPLIT") {
  385. # Look to see if we're using a wildcard
  386. if (($source_file =~ /\*/) || ($source_file =~ /\?/)) {
  387. # CMD Wildcard to RegExp Wildcard
  388. $source_file =~ s/\./\\\./g;
  389. $source_file =~ s/\?/\./g;
  390. $source_file =~ s/\*/\.\*/g;
  391. opendir(hDIR, ${source_dir});
  392. @files=readdir(hDIR);
  393. closedir(hDIR);
  394. foreach $token (@files) {
  395. next unless -e("${source_dir}\\${token}");
  396. next if -d("${source_dir}\\${token}");
  397. if ($token =~ /$source_file/i) {
  398. # Don't try to HSPLIT not text files
  399. # GIF files not correctly detected as binary.
  400. if (( -B "${source_dir}\\${token}") || ($token =~ /\.gif$/i)) {
  401. if ($WarnLevel > 1) { # This is an info message, require a higher warning level
  402. warn("BUILDMSG: $0: DDK_INFO: Not HSPLITTING ${token} - Detected as binary. ($ini_file: $cur_line_num) \n");
  403. }
  404. system("copy ${source_dir}\\${token} ${dest_root}\\${dest_dir} > NUL ");
  405. } else {
  406. system("hsplit -o ${dest_root}\\${dest_dir}\\${token} nul -bt2 BEGIN_DDKSPLIT END_DDKSPLIT -c \@\@ -i ${source_dir}\\${token} ");
  407. ## This was a bad mistake- we need to split to a temp file, then split the temp file again to get cumlative hsplits. Pulling thi
  408. ## extra split for a quick fix so we can RI. A proper fix that uses both hsplits will be test and checked in for the next RI.
  409. ##system("hsplit -o ${dest_root}\\${dest_dir}\\${token} nul -bt2 BEGIN_MSINTERNAL END_MSINTERNAL -c \@\@ -i ${source_dir}\\${token} ");
  410. }
  411. }
  412. }
  413. } else {
  414. # No wildcard- just do the split
  415. $dest_file=$source_file if ($dest_file eq "*");
  416. warn("nmake : $0: DDK_ERROR: ${source_file} not found ($ini_file: $cur_line_num) \n"), next unless (-e("${source_dir}\\${source_file}"));
  417. # Don't try to HSPLIT not text files.
  418. # GIF files not correctly detected as binary.
  419. if (( -B "${source_dir}\\${source_file}") || ($token =~ /\.gif$/i)){
  420. if ($WarnLevel > 0) { # This is an explicit HSPLIT of a binary file. Warn at a low warning level.
  421. warn("BUILDMSG: Warning $0: DDK_WARNING: Binary files cannot be HSPLIT- ${source_file} ($ini_file: $cur_line_num)\n");
  422. }
  423. system("copy ${source_dir}\\${source_file} ${dest_root}\\${dest_dir} > NUL ");
  424. } else {
  425. system("hsplit -o ${dest_root}\\${dest_dir}\\${dest_file} nul -bt2 BEGIN_DDKSPLIT END_DDKSPLIT -c \@\@ -i ${source_dir}\\${source_file} ");
  426. ## This was a bad mistake- we need to split to a temp file, then split the temp file again to get cumlative hsplits. Pulling thi
  427. ## extra split for a quick fix so we can RI. A proper fix that uses both hsplits will be test and checked in for the next RI.
  428. ##system("hsplit -o ${dest_root}\\${dest_dir}\\${dest_file} nul -bt2 BEGIN_MSINTERNAL END_MSINTERNAL -c \@\@ -i ${source_dir}\\${source_file} ");
  429. }
  430. }
  431. } else {
  432. warn("nmake : $0: DDK_ERROR: Unknown operation ($operation) ($ini_file: $cur_line_num)\n");
  433. }
  434. }
  435. #
  436. # Check file or glob for " Confidential"
  437. #
  438. sub CheckForMSConfidential {
  439. my($dir) = shift;
  440. my($source) = shift;
  441. my($return) = 1;
  442. my($file, @files);
  443. my($hDIR, $hFILE);
  444. my(@lines);
  445. # Files that have the string 'Confidential' but are shippable
  446. my(%exclusions) = ( "LICENSE.RTF" => TRUE,
  447. "NTLMSP.H" => TRUE,
  448. "MMREG.H" => TRUE );
  449. if (($source =~ /\*/) || ($source =~ /\?/)) {
  450. # CMD Wildcard to RegExp Wildcard
  451. $source =~ s/\?/\./g;
  452. $source =~ s/\*/\.\*/g;
  453. opendir(hDIR, ${dir});
  454. @files=readdir(hDIR);
  455. closedir(hDIR);
  456. foreach $file (@files) {
  457. next unless -e("${dir}\\${file}");
  458. next if -d("${dir}\\${file}");
  459. next if (( -B "${dir}\\${file}") || ($file =~ /\.gif$/));
  460. if ($file =~ /$source/i) {
  461. return(11) unless (-e "$dir\\$file");
  462. return(12) if (( -B "${dir}\\${file}") || ($file =~ /\.gif$/i));
  463. open(hFILE, "${dir}\\${file}") || die("nmake : $0: DDK_ERROR_FATAL: $dir\\$file could not be opened!\n");
  464. @lines=<hFILE>;
  465. close(hFILE);
  466. if (grep(/\ Confidential/i,@lines) > 0) {
  467. warn("nmake : $0: DDK_ERROR: $file contains \"Confidential\". ($ini_file: $cur_line_num)\n"),
  468. $return=0 unless(defined($exclusions{uc($file)}));
  469. }
  470. }
  471. }
  472. } else {
  473. # No wildcard
  474. return(21) unless (-e "$dir\\$source");
  475. return(22) if (( -B "${dir}\\${source}") || ($source =~ /\.gif$/i));
  476. open(hFILE, "$dir\\$source") || die("nmake : $0: DDK_ERROR_FATAL: $dir\\$source could not be opened!\n");
  477. @lines=<hFILE>;
  478. close(hFILE);
  479. if (grep(/\ Confidential/i,@lines) > 0) {
  480. warn("nmake : $0: DDK_ERROR: $source contains \"Confidential\". ($ini_file: $cur_line_num)\n"),
  481. $return=0 unless(defined($exclusions{uc($source)}));
  482. }
  483. }
  484. return($return);
  485. }
  486. __END__
  487. :endofperl