sbsv1_os/e32toolp/platform/winutl.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 
       
     2 # Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # this package does various ancillary things for windows modules
       
    16 # 
       
    17 #
       
    18 
       
    19 package Winutl;
       
    20 
       
    21 my $BaseAddress='';
       
    22 my @Win32LibList=();
       
    23 my $Win32Resrc='';
       
    24 my $CopyForStaticLinkage=0;
       
    25 my $Win32StdHeaders=0;
       
    26 my $MSVCVer=0;
       
    27 my $MSVCSubVer=0;
       
    28 
       
    29 require Exporter;
       
    30 @ISA=qw(Exporter);
       
    31 @EXPORT=qw(
       
    32 	Winutl_Help_Mmp
       
    33 
       
    34 	Winutl_DoMmp_Parse
       
    35 	Winutl_DoMmp
       
    36 
       
    37 	Winutl_BaseAddress
       
    38 	Winutl_Win32LibList
       
    39 	Winutl_Win32Resrc
       
    40 	Winutl_CopyForStaticLinkage
       
    41 	Winutl_Win32StdHeaders
       
    42 
       
    43 	Winutl_AdjustTargetPath
       
    44 
       
    45 	Winutl_MSVCVer
       
    46 	Winutl_MSVCSubVer
       
    47 
       
    48 	Winutl_CheckSourceMMPMetaData
       
    49 );
       
    50 
       
    51 use strict;
       
    52 use Genutl;
       
    53 use E32Variant;
       
    54 use CheckSource;
       
    55 use Pathutl;
       
    56 use Cwd;
       
    57 
       
    58 my %CheckSourceMMPMetaData;
       
    59 
       
    60 sub Winutl_Help_Mmp {
       
    61 # provide the help text for START <windows platforms> END blocks
       
    62 
       
    63 	print
       
    64 		"BASEADDRESS    [base address for dll loading]\n",
       
    65 		"WIN32_LIBRARY  [win32 libraries]\n",
       
    66 		"WIN32_RESOURCE  [win32 resource]\n",
       
    67 		"COPY_FOR_STATIC_LINKAGE   // copy dll from emulated Z drive\n",
       
    68 		"WIN32_HEADERS // instruct compiler to look into standard header directories\n",
       
    69 		"              // (implied by WIN32_LIBRARY)\n"
       
    70 	;
       
    71 }
       
    72 
       
    73 sub Winutl_DoMmp_Parse ($$) {
       
    74 	# takes reference to platform text and semicolon-separated list
       
    75 	# of compiler-specific include directories
       
    76 	my @PlatTxt=@{$_[0]};
       
    77 	my $CompilerIncPaths=$_[1];
       
    78 
       
    79 # process the START <windows platforms> END blocks
       
    80 
       
    81 	my $BaseTrg=&main::BaseTrg;
       
    82 	my $BasicTrgType=&main::BasicTrgType;
       
    83 	my $MakeFilePath=&main::MakeFilePath;
       
    84 	my $MMPFILE=&main::MmpFile;
       
    85 
       
    86 	# set up START WINS ... END block module variables
       
    87 	my @MmpWarn=();
       
    88 	my $Line;
       
    89 	LINE: foreach $Line (@PlatTxt) {
       
    90 		my $LineInfo=shift @$Line;
       
    91 
       
    92 		$LineInfo =~ /^(.+)\((\d+)\)$/;
       
    93 		my $CurFile = $1;
       
    94 		my $LineNum = $2;
       
    95 		my $BldInfDir = cwd;
       
    96 		$BldInfDir =~ s/\//\\/g;
       
    97 		$BldInfDir =~ s/^\w+://;
       
    98 		$BldInfDir .= "\\";
       
    99 		
       
   100 		$_=shift @$Line;
       
   101 		
       
   102 		if (/^BASEADDRESS$/oi) {
       
   103 			if (@$Line) {
       
   104 				$BaseAddress=shift @$Line;
       
   105 				$BaseAddress=~s/X/x/o;
       
   106 				next LINE;
       
   107 			}
       
   108 			push @MmpWarn, "$LineInfo : No base address specified for keyword BASEADDRESS\n";
       
   109 			next LINE;
       
   110 		}
       
   111 		if (/^WIN32_LIBRARY$/oi) {
       
   112 			if (@$Line)
       
   113 				{
       
   114 				$Win32StdHeaders = 1;
       
   115 
       
   116 				foreach (@$Line)
       
   117 					{
       
   118 					if (/^\./)
       
   119 						{
       
   120 						# local - check for UNIX slash and physical consistency of file as it exists relative to the bld.inf
       
   121 						CheckSource_MetaData(%CheckSourceMMPMetaData, $CurFile, "WIN32_LIBRARY", $_, $LineNum, $CheckSource_PhysicalCheck, $BldInfDir);
       
   122 						}
       
   123 					else
       
   124 						{
       
   125 						# global - check for UNIX slash and assume that it must be lower case
       
   126 						CheckSource_MetaData(%CheckSourceMMPMetaData, $CurFile, "WIN32_LIBRARY", $_, $LineNum);
       
   127 						}
       
   128 					$_ = &Path_Norm($_);
       
   129 					push @Win32LibList, $_;
       
   130 					}
       
   131 				}
       
   132 			else
       
   133 				{
       
   134 				push @MmpWarn, "$LineInfo : No libraries specified for keyword WIN32_LIBRARY\n";
       
   135 				}
       
   136 			next LINE;
       
   137 		}
       
   138 		if (/^WIN32_RESOURCE$/oi) {
       
   139 			if (@$Line) {
       
   140 				$Win32Resrc=shift @$Line;
       
   141 
       
   142 				CheckSource_MetaData(%CheckSourceMMPMetaData, $CurFile, "WIN32_RESOURCE", $Win32Resrc, $LineNum, $CheckSource_PhysicalCheck);
       
   143 				$Win32Resrc = &Path_Norm($Win32Resrc);
       
   144 				
       
   145 				$Win32Resrc=&main::Path_MakeAbs($MMPFILE, $Win32Resrc);
       
   146 				next LINE;
       
   147 			}
       
   148 			push @MmpWarn, "$LineInfo : No resource specified for keyword WIN32_RESOURCE\n";
       
   149 			next LINE;
       
   150 		}
       
   151 		if (/^COPY_FOR_STATIC_LINKAGE$/oi) {
       
   152 			if ($BasicTrgType!~/^DLL$/oi) {
       
   153 				push @MmpWarn, "$LineInfo : COPY_FOR_STATIC_LINKAGE only applies to DLLs\n";
       
   154 				next LINE;
       
   155 			}
       
   156 			if (&main::TrgPath eq "") {
       
   157 				push @MmpWarn, "$LineInfo : COPY_FOR_STATIC_LINKAGE requires TARGETPATH\n";
       
   158 				next LINE;
       
   159 			}
       
   160 			$CopyForStaticLinkage=1;
       
   161 			next LINE;
       
   162 		}
       
   163 		if (/^WIN32_HEADERS$/oi) {
       
   164 			$Win32StdHeaders = 1;
       
   165 			next LINE;
       
   166 		}
       
   167 		
       
   168 		push @MmpWarn, "$LineInfo : Unrecognised Keyword \"$_\"\n";
       
   169 	}
       
   170 
       
   171 	undef $Line;
       
   172 	if (@MmpWarn) {
       
   173 		warn
       
   174 			"\nMMPFILE \"",$MMPFILE,"\"\n",
       
   175 			"START .. END BLOCK WARNINGS(S)\n",
       
   176 			@MmpWarn,
       
   177 			"\n"
       
   178 		;
       
   179 	}
       
   180 	undef @MmpWarn;
       
   181 
       
   182 	# if Win32 Libraries required - set the Windows standard include paths
       
   183 	if ($Win32StdHeaders || $Win32Resrc || &main::Plat eq 'TOOLS' || &main::Plat eq 'CWTOOLS'
       
   184 		|| &main::Plat eq 'TOOLS2')
       
   185 	{	# show where to find win32 libraries
       
   186 		# include env variable takes everything between ';', including spaces and '"', as part of path
       
   187 		my @StdIncPaths=split ';', $CompilerIncPaths;
       
   188 		my $path;
       
   189 		foreach $path (@StdIncPaths) {
       
   190 			$path =~ s-/-\\-go;	# for those working with UNIX shells
       
   191 			if ($path =~ /^\+/) {
       
   192 				# expand CodeWarrior "recursive" entries
       
   193 				$path =~ s-^\+--go;		# remove the + from the current entry
       
   194 				if (opendir DIR, $path) {
       
   195 					my @list = grep !/^\.\.?$/, readdir DIR;
       
   196 					closedir DIR;
       
   197 					foreach (@list) {
       
   198 						my $newpath="$path\\$_";
       
   199 						if (-d $newpath) {
       
   200 							push @StdIncPaths,"+$newpath";	# add subdirs for later expansion
       
   201 						}
       
   202 					}
       
   203 				}
       
   204 			}
       
   205 		}
       
   206 		&main::SetStdIncPaths(@StdIncPaths);
       
   207 		&main::AddPlatMacros('WIN32','_WINDOWS');
       
   208 	}
       
   209 }
       
   210 
       
   211 sub Winutl_DoMmp ($$) {
       
   212 	# takes reference to platform text and semicolon-separated list
       
   213 	# of compiler-specific include directories
       
   214 	my @PlatTxt=@{$_[0]};
       
   215 	my $CompilerIncPaths=$_[1];
       
   216 
       
   217 	my $Plat=&main::Plat;
       
   218 	if ($Plat ne "WINSCW" and $Plat ne "CWTOOLS" and $Plat ne "TOOLS2") {
       
   219 		#	check that we're using VC6 SP3
       
   220 		&Winutl_MSVCVer();
       
   221 	}
       
   222 
       
   223 	&Winutl_DoMmp_Parse(\@PlatTxt, $CompilerIncPaths);
       
   224 	
       
   225 	my $BaseTrg=&main::BaseTrg;
       
   226 	my $BasicTrgType=&main::BasicTrgType;
       
   227 	my $MakeFilePath=&main::MakeFilePath;
       
   228 	my $MMPFILE=&main::MmpFile;
       
   229 	my @UidList=&main::UidList;
       
   230 	
       
   231 	if ($BasicTrgType=~/^(EXE|DLL)$/oi) {
       
   232 		# create the UID source file
       
   233 		my $priority = "EPriorityForeground";
       
   234 		if (&main::ProcessPriority) {
       
   235 			$priority="EPriority".&main::ProcessPriority;
       
   236 		}
       
   237 
       
   238 		my $UidText=join(
       
   239 			"\n",
       
   240 			'// Makmake-generated uid source file',
       
   241 			'#include <e32cmn.h>',
       
   242 			'#pragma data_seg(".SYMBIAN")',
       
   243 			'__EMULATOR_IMAGE_HEADER2('
       
   244 		);
       
   245 		foreach (@UidList) {
       
   246 			$UidText.="$_,";
       
   247 		}
       
   248 		my $vstr = "0x".&Genutl_VersionToHexString(&main::Version);
       
   249 		my $vid = &main::VendorId;
       
   250 		if(!$vid) { $vid="0"; }
       
   251 		$UidText.="$priority,".(&main::CapabilityFlags)[0]."u,".(&main::CapabilityFlags)[1]."u,".&main::SecureId.",".$vid.",$vstr,";	# second capability word always 0 for now
       
   252 		if (&main::AllowDllData) {
       
   253 			$UidText.="1,";
       
   254 		} else {
       
   255 			$UidText.="0,";
       
   256 		}
       
   257 		chop $UidText;
       
   258 		$UidText.=")\n";
       
   259 		$UidText.="#pragma data_seg()\n";
       
   260 		unless (&main::Plat eq 'TOOLS' || &main::Plat eq 'CWTOOLS' || &main::Plat eq 'TOOLS2' ) {
       
   261 			&main::AddSrc("$MakeFilePath$BaseTrg.UID.CPP", $UidText);
       
   262 		};
       
   263 	}
       
   264 
       
   265 }
       
   266 
       
   267 sub Winutl_BaseAddress () {
       
   268 	$BaseAddress;
       
   269 }
       
   270 
       
   271 sub Winutl_Win32LibList () {
       
   272 	@Win32LibList;
       
   273 }
       
   274 
       
   275 sub Winutl_Win32Resrc () {
       
   276 	$Win32Resrc;
       
   277 }
       
   278 
       
   279 sub Winutl_CopyForStaticLinkage () {
       
   280 	$CopyForStaticLinkage;
       
   281 }
       
   282 
       
   283 sub Winutl_Win32StdHeaders () {
       
   284 	$Win32StdHeaders;
       
   285 }
       
   286 
       
   287 sub Winutl_AdjustTargetPath () {
       
   288 	my ($TrgPathRef) = @_;
       
   289 
       
   290 	if (&main::EPOCSecurePlatform) {
       
   291 
       
   292 		my $plan=1;
       
   293 		my @macros = &Variant_GetMacroList;
       
   294 		foreach my $macro (@macros) {
       
   295 			if ($macro =~ m/^SYMBIAN_IGNORE_BIN_TARGETPATH.*/) {
       
   296 				$plan = 2;
       
   297 				last;
       
   298 			}
       
   299 		}
       
   300 
       
   301 		if ($plan == 1) {
       
   302 			# Intermediate step: TARGETPATH => COPY_FOR_STATIC_LINKAGE
       
   303 			$CopyForStaticLinkage = 1 if ($$TrgPathRef ne "");
       
   304 		} else {
       
   305 			# Finally: Ignore TARGETPATH and COPY_FOR_STATIC_LINKAGE
       
   306 			# unless it's a subdir of sys\bin
       
   307 			if (&main::TrgPath !~ /^Z\\sys\\bin\\.+/i) {
       
   308 				$$TrgPathRef = "";
       
   309 				$CopyForStaticLinkage = 0;
       
   310 			}
       
   311 		}
       
   312 	}
       
   313 }
       
   314 
       
   315 sub Winutl_MSVCVer ($) {
       
   316 	my $platcommand=shift;
       
   317 	if(!defined $platcommand) {
       
   318 		$platcommand=0; }
       
   319 	open PIPE, "LINK.EXE 2>&1 |" or die "ERROR: Can't invoke LINK.EXE\n";
       
   320 	my $DoneCheck=0;
       
   321 	while (<PIPE>) {
       
   322 		unless ($DoneCheck) {
       
   323 			if (/^.+\s+Version\s+(\d)\.(\d{2})\.((\d{4})|(\d{5})(.\d{2}))\s*$/o) {
       
   324 				if (($1<6) or ($1==6 and $2<0) or ($1==6 and $2==0 and $3<8447)) {
       
   325 					warn "WARNING: Should install MSVC6 Service Pack 3\n";
       
   326 				}
       
   327 				$MSVCVer = $1;
       
   328 				$MSVCSubVer = $2;
       
   329 				$DoneCheck=1;
       
   330 			}
       
   331 		}
       
   332 	}
       
   333 	close PIPE;
       
   334 	# Do not throw any error when link.exe not present  while displaying
       
   335 	# a list of the supported platforms using bldmake plat command.
       
   336 	if (!$DoneCheck && !$platcommand) {
       
   337 		# Couldn't find version information? Might not have link.exe at all
       
   338 		die "ERROR: failed to find version information for LINK.EXE\n";
       
   339 	}
       
   340 
       
   341 	$MSVCVer;
       
   342 }
       
   343 
       
   344 sub Winutl_MSVCSubVer ($) {
       
   345 	my $platcommand=@_;
       
   346 	&Winutl_MSVCVer($platcommand);
       
   347 
       
   348 	$MSVCSubVer;
       
   349 }
       
   350 
       
   351 sub Winutl_CheckSourceMMPMetaData () {
       
   352 	%CheckSourceMMPMetaData;
       
   353 }
       
   354 
       
   355 1;