OpenMake Meister

Section III: Executing and Logging the Step (Lines 35 - 43)

 

35 $StepDescription = "Performing C/C++ Compile for $TargetFile";

36 $CompilerArguments = "$Defines $Flags";

37

38 omlogger("Begin",$StepDescription,"ERROR:","$StepDescription succeeded.",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut);

39 @CompilerOut = `$Compiler /nologo \@$rsp 2>&1`;

40 $RC = $?;

41 $StepError = "$StepDescription failed!";

42 omlogger("Abort",$StepDescription,"ERROR:","ERROR: $StepDescription failed!",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut), $RC = 1 if ($RC != 0);

43 omlogger("Final",$StepDescription,"ERROR:","$StepDescription succeeded.",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut), push(@DeleteFileList,$rsp) if ($RC == 0);

 

     The first line sets the version of the Build Method script which is displayed upon execution.

$ScriptVersion = "6.0";

     The following lines extract the compiler to be used and then search for that compiler.

@CompilersPassedInFlags = ("cl");

$DefaultCompiler  = "cl";

$Compiler,$Flags) = get_compiler($DebugFlags,$ReleaseFlags,$DefaultCompiler,@CompilersPassedInFlags);

     The list variable @CompilersPassedInFlags contains the list of compilers that can be passed via the flags. 

     $DefaultCompiler is the default compiler to be used if none was passed in the flags.

     The subroutine get_compiler, determines which compiler to use based on the values of @CompilersPassedInFlags, $DefaultCompiler and the Flags to be used (Debug or Release).  It then returns the the full path to the compiler to be used, $Compiler, as well as the flags to be used (with the compiler name removed), $Flags

     Line 6 defines the variable $TargetFileName, which is obtained from the generated File Object, $Target.

$TargetFile = $Target->get;

When using this Build Method script for the compilation radius.obj a header section that initializes the values of these variables specifically for the task at hand is prepended (shown below), so that as a result of the declaration in line 6, $TargetFileName is set to bin/radius.obj (This information is determined from the Target, the Build Method and Build Rules associated with it as well as the Dependency Directory  used).

     Line 7 extracts the Intermediate Directory to be used

$IntDirName = $IntDir -> get;

     Lines 8 and 9 derives the name of the .pch and .pdb files from the name of the Final Target

$Pch       = '"' . $IntDirName . "\\" . $FinalTarget->getF . '.pch"';

$Pdb       = '"' . $IntDirName . "\\" . $FinalTarget->getF . '.pdb"';

 

     Line 10 determines the Source File to be compiled by extracting the dependency whose extension matches .C, .CPP or .CXX from a generated FileList object of Target Dependencies of bin/radius.obj. Note how the method getExtQuoted applied to the FileList object $TargetDeps does this in a single step.

$Source = $TargetDeps->getExtQuoted(qw(.C .CPP .CXX));

 

     Lines 11 – 34 completes the steps necessary for the construction of the compile steps, creates a temporary resource file and adds the compiler flags and #Defines.

if ($Target->getExt =~ /pch/i && $Source =~ /stdafx\.cpp/i)}

 $TargetFile = '"' . $Target->getPath . "\\stdafx.obj\""; }

 else {

  $TargetFile = $Target->getQuoted;}

$ENV{'LIB'}     = '';

$ENV{'INCLUDE'} = '';

$Flags .= ' /Fp' . $Pch . ' /Fo' . $TargetFile . ' /Fd' . $Pdb . ' /c ' . $Source if ($CFG eq 'DEBUG');

$Flags .= ' /Fp' . $Pch . ' /Fo' . $TargetFile .                 ' /c ' . $Source if ($CFG ne 'DEBUG');

$Flags =~ s/\/Yu/\/Yc/ if ($Target->getE =~ /pch/i || $Target->getFE =~ /stdafx\.obj/i);

#print "$Compiler $Defines $Flags\n$IncludeNL\n\n" if ($Silent ne 'Yes');

($tmpfh, $rsp) = tempfile('omXXXXX', SUFFIX => '.rsp', UNLINK => 1 );

print $tmpfh "$Defines $Include $Flags";

close $tmpfh;

     Line 35 prepares and writes out the command to be executed. The actual compiler step is carried out on line 39 and the remaining lines capture the return code and log the output.

$StepDescription = "Performing C/C++ Compile for $TargetFile";

$CompilerArguments = "$Defines $Flags";

omlogger("Begin",$StepDescription,"ERROR:","$StepDescription succeeded.",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut);

@CompilerOut = `$Compiler /nologo \@$rsp 2>&1`;

$RC = $?;

$StepError = "$StepDescription failed!";

omlogger("Abort",$StepDescription,"ERROR:","ERROR: $StepDescription failed!",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut), $RC = 1 if ($RC != 0);

omlogger("Final",$StepDescription,"ERROR:","$StepDescription succeeded.",$Compiler,$CompilerArguments,$IncludeNL,$RC,@CompilerOut), push(@DeleteFileList,$rsp) if ($RC == 0);