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.

171 lines
4.7 KiB

  1. @rem = '
  2. @echo off
  3. goto End_PERL
  4. rem ';
  5. ## ======================= Perl program start
  6. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts"; # for cmdevt.pl
  7. use Win32;
  8. use Win32::Process;
  9. use Cwd;
  10. require 5.003;
  11. $CDIR = cwd;
  12. $CDIR = join("_", split(/[\/\:]+/, $CDIR));
  13. $SYSGEN = shift @ARGV if ($ARGV[0]=~/sysgen/i);
  14. my $num=$ARGV[0];
  15. my ($chars, $total, $LOGFILE, $ERRFILE, $ExitCode, %PROCESS, $PROCESSITEM) = ();
  16. $num=16 if(!defined $num);
  17. die "The parameter is incorrect!!!" if ($num!~/\d/);
  18. open(F, "..\\makefile.mak");
  19. @text=<F>;
  20. close(F);
  21. ## $#text + 1 // The lines of the makefile.mak is
  22. ## = 1 + 2 + 4 + ... + $total * 2 // the first 1 is the all: target in makefile.mak
  23. ## // the remains are the total of process(n)'s line, ex: process04 has 8 lines
  24. ## <Mathmetic calculate>
  25. ## => $#text = 2 + 4 + ... + $total * 2 // remove + 1 in two side
  26. ## => $#text = 2 * (1 + 2 + ... + $total) // take 2 out of the sum serious
  27. ## => $#text = 2 * ((1 + $total) * $total) / 2 // the formula of the sum serious
  28. ## => $#text = (1 + $total) * $total // remove *2 & /2
  29. ## => $#text = $total^2 + $total // expand
  30. ## => $total^2 + $total - $#text = 0 // get =0 equation
  31. ## => $total = (-1 + sqrt(1^2 - 4 * 1 * (-$#text)) / (2 * 1) // the roots is (-b + sqrt(b^2 - 4*a*c) / 2a. ignore the negative one
  32. ## => $total = (sqrt(4 * $#text + 1) -1) / 2
  33. $total= (sqrt(4 * $#text + 1) - 1) / 2;
  34. if ((int($total) ne $total) || ($text[$#text]!~/process\Q${total}${total}\E/)) {
  35. $total=$_[0]=16;
  36. print "The makefile.mak is incorrect, set process to $total, re-generate.....\n";
  37. require "dispatch.pl";
  38. }
  39. # Get the number of characters of the $total
  40. $chars=int(1+log($total)/log(10));
  41. # Search \\\makedir\makedir
  42. open(F, "makefile");
  43. for ($t=0; $t<100; $t++) {
  44. $_=<F>;
  45. last if (/\\\\\\makedir\\makedir/i);
  46. }
  47. close(F);
  48. $LOGFILE = (defined $ENV{LOGFILE})?$ENV{LOGFILE} : ((defined $SYSGEN)?"SYSGEN.LOG":die "ERROR: Not Define LOGFILE");
  49. $ERRFILE = (defined $ENG{ERRFILE})?$ENV{ERRFILE} : ((defined $SYSGEN)?"SYSGEN.ERR":die "ERROR: Not Define ERRFILE");
  50. if ($t < 100) {
  51. system("nmake /NOLOGO /R /S /C /F makefile \\\\\\makedir\\makedir");
  52. }
  53. for($i=1; $i <= $num; $i++) {
  54. $PROCESS{$i}->{LOGFILE} = $ENV{LOGFILE} = "${LOGFILE}.0${i}";
  55. $PROCESS{$i}->{ERRFILE} = $ENV{ERRFILE} = "${ERRFILE}.0${i}";
  56. system(sprintf("start /MIN $0 -w ${CDIR}_process\%0${chars}d\%0${chars}d nmake /NOLOGO /f ..\\makefile.mak process\%0${chars}d\%0${chars}d", $num, $i, $num, $i));
  57. $PROCESSITEM .= sprintf("${CDIR}_process\%0${chars}d\%0${chars}d ", $num, $i);
  58. }
  59. system("\%PERLEXE\% \%RazzleToolPath\%\\postbuildscripts\\cmdevt.pl -w $PROCESSITEM");
  60. 1;
  61. __END__
  62. :End_PERL
  63. if not "%_echo%" == "" echo on
  64. if not "%verbose%" == "" echo on
  65. for %%a in (./ .- .) do if ".%1." == "%%a?." goto Usage
  66. if "%3"=="nmake" goto NMake
  67. SETLOCAL ENABLEDELAYEDEXPANSION
  68. for %%i in (perl.exe) do if not defined PERLEXE set PERLEXE=%%~$PATH:i
  69. %PERLEXE% %~f0 %*
  70. IF /I "%1"=="SYSGEN" (
  71. IF NOT defined LOGFILE set LOGFILE=sysgen.log
  72. IF NOT defined ERRFILE set ERRFILE=sysgen.err
  73. )
  74. SET FILES=
  75. IF EXIST %LOGFILE% set FILES= + %LOGFILE%
  76. FOR %%f in (%LOGFILE%.0*) do if "%%~zf" neq "0" set FILES=!FILES! + %%f
  77. IF defined FILES (
  78. IF "%FILES%" neq " + %LOGFILE%" copy /A /Y %FILES:~3% %LOGFILE%
  79. )
  80. DEL %LOGFILE%.0*
  81. SET FILES=
  82. IF EXIST %ERRFILE% set FILES= + %ERRFILE%
  83. FOR %%f in (%ERRFILE%.0*) do if "%%~zf" neq "0" set FILES=!FILES! + %%f
  84. IF defined FILES (
  85. IF "%FILES%" neq " + %ERRFILE%" copy /A /Y %FILES:~3% %ERRFILE%
  86. )
  87. DEL %ERRFILE%.0*
  88. set RET_VALUE=0
  89. for /f %%i in ('findstr /c:"**** ERROR :" *') do set /A RET_VALUE+=1
  90. ENDLOCAL && seterror "%RET_VALUE%"
  91. goto :EXIT
  92. :Usage
  93. echo %0 - Multi-Taskly NMake makefile with process^<total^>^<id^>
  94. echo ====================================================================
  95. echo Syntax:
  96. echo %0 [SYSGEN] ^<numprocess^>
  97. echo.
  98. echo Argument :
  99. echo SYSGEN : by default it will define sysgen.err and sysgen.log for
  100. echo it's standard input / output file
  101. echo.
  102. echo numprocess : number of session you want to run at the same time.
  103. echo.
  104. echo Example:
  105. echo 1. run nmake at 4 sessions
  106. echo =^> $0 4
  107. echo 2. run nmake for sysgen with 8 sessions
  108. echo =^> $0 SYSGEN 8
  109. echo.
  110. echo Parameter:
  111. echo numrpcess : number of process
  112. goto :EXIT
  113. :NMake
  114. set myswitch=%1
  115. set mytitle=%2
  116. Title %mytitle%
  117. shift
  118. shift
  119. %PERLEXE% %RazzleToolPath%\PostbuildScripts\cmdevt.pl -h %mytitle%
  120. del %logfile% 2>nul
  121. del %errfile% 2>nul
  122. %1 %2 %3 %4 %5 %6 %7 %8 %9
  123. if errorlevel 1 echo **** ERROR : %mytitle% - ErrorLevel %errorlevel%>>%ERRFILE%
  124. %PERLEXE% %RazzleToolPath%\PostbuildScripts\cmdevt.pl -s %mytitle%
  125. exit
  126. goto :EXIT
  127. :EXIT