|
1 # Copyright (c) 2008-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 # This module provides a mapping from RVCT versions to the corresponding environment |
|
15 # settings. The information is obtained from a configuration file pointed to by the |
|
16 # environment variable ABLD_RVCT_INI. The following example shows the file's |
|
17 # structure: |
|
18 # [2.2.616] |
|
19 # bin=C:\Apps\ARM-RVCT\2.2.616\bin |
|
20 # inc=C:\Apps\ARM-RVCT\2.2.616\inc |
|
21 # lib=C:\Apps\ARM-RVCT\2.2.616\lib |
|
22 # [3.1.700] |
|
23 # bin=C:\Apps\ARM-RVCT\3.1.700\bin |
|
24 # inc=C:\Apps\ARM-RVCT\3.1.700\inc |
|
25 # lib=C:\Apps\ARM-RVCT\3.1.700\lib |
|
26 # If the file is used, it must contain at least one section. |
|
27 # |
|
28 # |
|
29 |
|
30 |
|
31 package RVCT_ver2set; |
|
32 |
|
33 # |
|
34 # PUBLIC FUNCTIONS |
|
35 # |
|
36 |
|
37 # Returns a list of available RVCT versions, for example ["2.2.435", "2.2.616"]. |
|
38 sub get_versions(); |
|
39 |
|
40 # Returns true if the given RVCT version exists. |
|
41 sub compiler_exists($); |
|
42 |
|
43 # Given an RVCT version, returns what the name and value of the RVCT??BIN |
|
44 # variable would be. |
|
45 sub get_bin_name($); |
|
46 sub get_bin_path($); |
|
47 |
|
48 # Given an RVCT version, returns what the name and value of the RVCT??INC |
|
49 # variable would be. |
|
50 sub get_inc_name($); |
|
51 sub get_inc_path($); |
|
52 |
|
53 # Given an RVCT version, returns what the name and value of the RVCT??LIB |
|
54 # variable would be. |
|
55 sub get_lib_name($); |
|
56 sub get_lib_path($); |
|
57 |
|
58 |
|
59 # |
|
60 # PRIVATE HELPER FUNCTIONS |
|
61 # |
|
62 |
|
63 # Prints an error message and then terminates. |
|
64 sub _err_and_die(@); |
|
65 |
|
66 |
|
67 # |
|
68 # GLOBAL DATA |
|
69 # |
|
70 |
|
71 # Contains all the information read from the configuration file. |
|
72 my %g_data; |
|
73 |
|
74 |
|
75 sub get_versions() |
|
76 { |
|
77 return sort(keys %g_data); |
|
78 } |
|
79 |
|
80 sub compiler_exists($) |
|
81 { |
|
82 my $vers = shift; |
|
83 return ( $g_data{$vers} ); |
|
84 } |
|
85 |
|
86 sub get_bin_name($) |
|
87 { |
|
88 my $vers = shift; |
|
89 return $g_data{$vers}->{bin_name}; |
|
90 } |
|
91 |
|
92 sub get_bin_path($) |
|
93 { |
|
94 my $vers = shift; |
|
95 return $g_data{$vers}->{bin_path}; |
|
96 } |
|
97 |
|
98 sub get_inc_name($) |
|
99 { |
|
100 my $vers = shift; |
|
101 return $g_data{$vers}->{inc_name}; |
|
102 } |
|
103 |
|
104 sub get_inc_path($) |
|
105 { |
|
106 my $vers = shift; |
|
107 return $g_data{$vers}->{inc_path}; |
|
108 } |
|
109 |
|
110 sub get_lib_name($) |
|
111 { |
|
112 my $vers = shift; |
|
113 return $g_data{$vers}->{lib_name}; |
|
114 } |
|
115 |
|
116 sub get_lib_path($) |
|
117 { |
|
118 my $vers = shift; |
|
119 return $g_data{$vers}->{lib_path}; |
|
120 } |
|
121 |
|
122 sub _err_and_die(@) |
|
123 { |
|
124 print STDERR "error: @_\n"; |
|
125 exit 1; |
|
126 } |
|
127 |
|
128 |
|
129 # initialize module |
|
130 { |
|
131 my $fname = $ENV{ABLD_RVCT_INI}; |
|
132 |
|
133 if ($fname) # The environment varaible is set. |
|
134 { |
|
135 _err_and_die("ABLD_RVCT_INI doesn't point to a file.") unless -f $fname; |
|
136 |
|
137 open (my $in, "<", $fname) or _err_and_die("couldn't open ABLD_RVCT_INI = $fname."); |
|
138 |
|
139 my @lines = (); |
|
140 |
|
141 while (<$in>) |
|
142 { |
|
143 chomp; |
|
144 |
|
145 next if /^\s*;/ ; |
|
146 next if /^\s*#/ ; |
|
147 next if /^\s*$/ ; |
|
148 |
|
149 push @lines, $_; |
|
150 } |
|
151 |
|
152 close $in or _err_and_die("couldn't close ABLD_RVCT_INI = $fname."); |
|
153 |
|
154 while (@lines) |
|
155 { |
|
156 my $ver = shift @lines; |
|
157 my $kv1 = shift @lines; |
|
158 my $kv2 = shift @lines; |
|
159 my $kv3 = shift @lines; |
|
160 |
|
161 my $Mm = ""; |
|
162 |
|
163 if ( $ver =~ /^\s*\[(\d+)\.(\d+)\.(\d+)\]\s*$/ ) |
|
164 { |
|
165 _err_and_die("$fname: duplicate section: $ver.") if $g_data{$1}; |
|
166 $ver = "$1.$2.$3"; |
|
167 $Mm = "$1$2"; |
|
168 } |
|
169 else |
|
170 { |
|
171 _err_and_die("$fname: invalid section header: $ver."); |
|
172 } |
|
173 |
|
174 my %kv = (); |
|
175 |
|
176 for ($kv1, $kv2, $kv3) |
|
177 { |
|
178 _err_and_die("$fname: not enough data in section $ver.") unless $_; |
|
179 |
|
180 if ( $_ =~ /^\s*(bin|inc|lib)\s*=(.*)$/i ) |
|
181 { |
|
182 my $key = uc($1); |
|
183 my $val = $2; |
|
184 |
|
185 $val =~ s/^\s+//; |
|
186 $val =~ s/\s+$//; |
|
187 |
|
188 _err_and_die("$fname: in section $ver: \"$key\" doesn't point to a directory.") unless -d $val; |
|
189 _err_and_die("$fname: in section $ver: duplicate key \"$key\".") if $kv{$key}; |
|
190 |
|
191 $kv{$key} = $val; |
|
192 } |
|
193 else |
|
194 { |
|
195 _err_and_die("$fname: in section $ver: invalid line \"$_\"."); |
|
196 } |
|
197 } |
|
198 |
|
199 $g_data{$ver}->{bin_name} = "RVCT${Mm}BIN"; |
|
200 $g_data{$ver}->{bin_path} = "$kv{BIN}"; |
|
201 $g_data{$ver}->{inc_name} = "RVCT${Mm}INC"; |
|
202 $g_data{$ver}->{inc_path} = "$kv{INC}"; |
|
203 $g_data{$ver}->{lib_name} = "RVCT${Mm}LIB"; |
|
204 $g_data{$ver}->{lib_path} = "$kv{LIB}"; |
|
205 } |
|
206 |
|
207 } |
|
208 else |
|
209 { |
|
210 # ABLD_RVCT_INI isn't set. This is not an error. All public functions will |
|
211 # return NULL. |
|
212 } |
|
213 } |
|
214 |
|
215 1; |
|
216 |
|
217 |