|
1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 package E32Variant; |
|
17 |
|
18 require Exporter; |
|
19 |
|
20 @ISA = qw(Exporter); |
|
21 |
|
22 @EXPORT = qw(Variant_GetMacroList Variant_GetMacroHRHFile Variant_GetMacro); |
|
23 |
|
24 use Pathutl; |
|
25 |
|
26 # using $FindBin::Bin to figure out the location of the epoc32\tools directory as |
|
27 # IDE doesn't understand env{EPOCROOT} |
|
28 |
|
29 my $PerlBinPath; # fully qualified pathname of the directory containing this script |
|
30 |
|
31 BEGIN { |
|
32 require 5.005_03; # check user has a version of perl that will cope |
|
33 $PerlBinPath = $FindBin::Bin; # X:/epoc32/tools |
|
34 $PerlBinPath =~ s/\//\\/g; # X:\epoc32\tools |
|
35 } |
|
36 |
|
37 # get epocroot if it is set |
|
38 my $epocroot = $ENV{EPOCROOT}; |
|
39 my $toolspath; |
|
40 |
|
41 #if epocroot is not set figure it out |
|
42 if(!$epocroot){ |
|
43 $epocroot = $PerlBinPath . "\\..\\..\\" ; #infer epocroot |
|
44 $toolspath = $PerlBinPath; |
|
45 }else{ |
|
46 $toolspath = $epocroot . "epoc32\\tools\\"; |
|
47 } |
|
48 |
|
49 $epocroot=~s/^(.:)//io; # remove drive letter |
|
50 $epocroot=&Path_Strip($epocroot); # collapse |
|
51 |
|
52 my $cfgFile = $toolspath . "variant\\variant.cfg"; # default location |
|
53 $cfgFile =~ /^(.:)/i; # match the drive |
|
54 my $MacroHRHLocation_Drive = lc($1); # save the drive |
|
55 |
|
56 sub Variant_GetMacroHRHFile{ |
|
57 my $file; |
|
58 if(-e $cfgFile){ |
|
59 open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n"; |
|
60 while (<FILE>) { |
|
61 # strip comments |
|
62 s/^([^#]*)#.*$/$1/o; |
|
63 # skip blank lines |
|
64 if (/^\s*$/o) { |
|
65 next; |
|
66 } |
|
67 # get the hrh file |
|
68 if($_ =~ /\.hrh/xi){ |
|
69 $file = $_; |
|
70 last; |
|
71 } |
|
72 } |
|
73 close FILE; |
|
74 die "\nERROR: No variant file specified in $cfgFile!\n" unless $file; |
|
75 $file =~ s/\s+//g; |
|
76 $file=~s/^(.:)//io; # remove drive letter |
|
77 my $paths_drive = lc($1); |
|
78 |
|
79 $file = Path_MakeEAbs($epocroot."EPOC32\\", $epocroot, $file); # assume relative to EPOCROOT |
|
80 |
|
81 if($paths_drive){ |
|
82 die "\nERROR: Variant file specified in $cfgFile is not on the same drive as \\epoc32\\\n" |
|
83 unless ($paths_drive eq $MacroHRHLocation_Drive); |
|
84 } |
|
85 if(!(-e $file)) { |
|
86 die "\nERROR: $cfgFile specifies $file which doesn't exist!\n"; |
|
87 } |
|
88 |
|
89 # make sure it is in dos syntax |
|
90 $file=~ s/\//\\/g; |
|
91 } |
|
92 return $file; |
|
93 } |
|
94 |
|
95 |
|
96 # returns the variant specific macro definitions as a list |
|
97 sub Variant_GetMacroList{ |
|
98 |
|
99 my @macros = (); |
|
100 my $vfile = Variant_GetMacroHRHFile(); |
|
101 |
|
102 if($vfile) |
|
103 { |
|
104 my $VariantFilePath = Path_Split('Path',$vfile); |
|
105 chop( $VariantFilePath ); |
|
106 $VariantFilePath = &Path_PrefixWithDriveAndQuote($VariantFilePath); |
|
107 $vfile = &Path_PrefixWithDriveAndQuote($vfile); |
|
108 my $e32Path = &Path_PrefixWithDriveAndQuote($epocroot."epoc32\\include"); |
|
109 |
|
110 open CPPPIPE,"cpp -I $e32Path -I $VariantFilePath -undef -dM $vfile |" or die "ERROR: Can't invoke CPP.EXE\n"; |
|
111 while(<CPPPIPE>){ |
|
112 if($_ =~ /(\#define)(\s+)(.+)/){ |
|
113 push @macros, $3; |
|
114 } |
|
115 } |
|
116 close CPPPIPE; |
|
117 } |
|
118 return @macros; |
|
119 } |
|
120 |
|
121 sub Variant_GetMacro{ |
|
122 |
|
123 my $file; |
|
124 if(-e $cfgFile){ |
|
125 open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n"; |
|
126 while (<FILE>) { |
|
127 # strip comments |
|
128 s/^([^#]*)#.*$/$1/o; |
|
129 # skip blank lines |
|
130 if (/^\s*$/o) { |
|
131 next; |
|
132 } |
|
133 # get the hrh file |
|
134 if($_ =~ /^ENABLE_ABIV2_MODE$/xi){ |
|
135 close FILE; |
|
136 return 1; |
|
137 } |
|
138 } |
|
139 close FILE; |
|
140 } |
|
141 return 0; |
|
142 } |
|
143 |
|
144 1; |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |