FreeCalypso > hg > tcs211-fcmodem
comparison g23m/nds_generatemakefile.pl @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 #!perl -w | |
2 #------------------------------------------------------------------------------- | |
3 # Project : Nice Delivery System | |
4 # Module : nds_generate_makefile | |
5 #------------------------------------------------------------------------------- | |
6 # Copyright: 2003 Texas Instruments Deutschland GmbH | |
7 # 2004 Texas Instruments France SA | |
8 # All rights reserved. | |
9 # | |
10 # This file is confidential and a trade secret of Texas | |
11 # Instruments. | |
12 # The receipt of or possession of this file does not convey | |
13 # any rights to reproduce or disclose its contents or to | |
14 # manufacture, use, or sell anything it may describe, in | |
15 # whole, or in part, without the specific written consent of | |
16 # Texas Instruments Framce SA. | |
17 #------------------------------------------------------------------------------- | |
18 # Authors : jr Joachim Richter | |
19 # mo Martin Osieka | |
20 # ib Isabelle Biffi | |
21 #------------------------------------------------------------------------------- | |
22 # Versions: 2.0 ib | |
23 #------------------------------------------------------------------------------- | |
24 | |
25 | |
26 use strict; | |
27 use File::Copy; | |
28 use File::Find; | |
29 use File::Spec; | |
30 use Cwd; | |
31 use Getopt::Long qw(:config pass_through); | |
32 | |
33 | |
34 #------------------------------------------------------------------------------- | |
35 # Variables | |
36 #------------------------------------------------------------------------------- | |
37 | |
38 my $command; | |
39 | |
40 # makefile file name | |
41 my $makeFile; | |
42 | |
43 # do not only store the drive in $current_drive, but rather store the path | |
44 # to the current dir (necessary to work directly on V:\<view>\...) | |
45 my $current_drive = cwd; | |
46 $current_drive =~ s|[\\/][^\\/]+$||; | |
47 | |
48 # specifies whether output is being redirected (logged to a file) or not | |
49 my $outerr_redirected; | |
50 | |
51 # command line options | |
52 my $o_file; | |
53 my $o_logfile = "report.txt"; | |
54 my $o_shell = 0; | |
55 my $o_help = 0; | |
56 # my $o_dlvcfg = "dlv_cfg0"; | |
57 my $o_dlvcfg = ""; | |
58 my $dlv_cfg_path = "system\\busyb\\deliverydefs\\"; | |
59 my $dlv_cfg; | |
60 | |
61 # make pass-through options | |
62 my $make_opt; | |
63 | |
64 | |
65 #------------------------------------------------------------------------------- | |
66 # Main Program | |
67 #------------------------------------------------------------------------------- | |
68 | |
69 # parse command line, passing through all unknown options to make | |
70 parse_command_line(); | |
71 | |
72 # logging is enabled by default (unless $o_shell is set, done by option "-s") | |
73 if (!$o_shell) | |
74 { | |
75 # attempt to redirect STDOUT+STDERR | |
76 $outerr_redirected = redirect_output(); | |
77 } | |
78 else | |
79 { | |
80 # do not redirect output, it is being sent to shell | |
81 $outerr_redirected = 0; | |
82 } | |
83 | |
84 # ib | |
85 my $build_message = "\nStarting generate makefile for configuration " . $o_file . ". | |
86 REDIRECT_PLACEHOLDER | |
87 \n"; | |
88 | |
89 if ($outerr_redirected) | |
90 { | |
91 $build_message =~ s/REDIRECT_PLACEHOLDER/output is being logged to $o_logfile,/; | |
92 print CONSOLE_OUT $build_message; | |
93 } | |
94 else | |
95 { | |
96 $build_message =~ s/REDIRECT_PLACEHOLDER/output is not being logged!/; | |
97 print $build_message; | |
98 } | |
99 step__check_environment (1); | |
100 &step__update_busyb_makefile (2, "system/unbusy_g23m.ini"); | |
101 | |
102 # restore redirected STDOUT+STDERR, if necessary | |
103 restore_redirection() | |
104 if $outerr_redirected; | |
105 | |
106 | |
107 exit 0; | |
108 | |
109 | |
110 #------------------------------------------------------------------------------- | |
111 # SUBROUTINES | |
112 #------------------------------------------------------------------------------- | |
113 | |
114 | |
115 #------------------------------------------------------------------------------- | |
116 # parses the command line, sets global $o_* variables to all specified options, | |
117 # checks which options/parameters are passed through to make or ABC | |
118 #------------------------------------------------------------------------------- | |
119 sub parse_command_line | |
120 { | |
121 GetOptions ( | |
122 "file=s"=>\$o_file, | |
123 "log=s"=>\$o_logfile, | |
124 "shell"=>\$o_shell, | |
125 "dlv=s"=>\$o_dlvcfg, | |
126 "help|?" =>\$o_help); | |
127 | |
128 if ($o_help) | |
129 { | |
130 usage(); | |
131 exit 0; | |
132 } | |
133 | |
134 # determine make/BuSyB pass-through options from @ARGV | |
135 $make_opt = ""; | |
136 foreach (@ARGV) | |
137 { | |
138 # make/BuSyB pass-through option: all else | |
139 $make_opt .= " " . $_; | |
140 } | |
141 | |
142 # sanity checks: | |
143 # due to enabled 'pass_through' and 'permute' of GetOptions(), | |
144 # some busyb.pl options may end up in other option parameters instead | |
145 # e.g. if options which require a parameter are specified w/o any parameter: | |
146 # "... -m", or "... -m -l", ... | |
147 foreach ($o_file, $o_logfile) | |
148 { | |
149 # check all options which should take a parameter | |
150 # if they actually contain another option and no parameter | |
151 if (defined($_) and /^-/) | |
152 { | |
153 print "\nERROR: Option missing mandatory parameter!\n\n"; | |
154 usage(); | |
155 exit 1; | |
156 } | |
157 } | |
158 foreach ("-f", "-l") | |
159 { | |
160 # check if the pass-through options to make contain on of the busyb.pl | |
161 # options | |
162 if ($make_opt =~ /$_/i) | |
163 { | |
164 print "\nERROR: Option missing mandatory parameter!\n\n"; | |
165 usage(); | |
166 exit 1; | |
167 } | |
168 } | |
169 | |
170 if (!$o_file) | |
171 { | |
172 print "\nERROR: No input/configuration file specified with \"-f file\"!\n\n"; | |
173 usage(); | |
174 exit 1; | |
175 } | |
176 die "\nERROR: Input/configuration file \"" . $o_file . "\" not found, aborting" | |
177 unless -e $o_file; | |
178 # replace backslash with slash in filename | |
179 $o_file =~ s:\\:/:g; | |
180 | |
181 | |
182 if ($o_dlvcfg) | |
183 { | |
184 $dlv_cfg=$dlv_cfg_path.$o_dlvcfg.".xml"; | |
185 die "\nERROR: delivery configuration file \"" . $dlv_cfg . "\" not found, aborting" | |
186 unless -e $dlv_cfg; | |
187 # replace backslash with slash in filename | |
188 $dlv_cfg =~ s:\\:/:g; | |
189 } | |
190 } | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 #------------------------------------------------------------------------------- | |
200 # print short usage notes | |
201 #------------------------------------------------------------------------------- | |
202 sub usage | |
203 { | |
204 print "\nUSAGE: | |
205 perl xxx.pl -f XML-File [OPTIONS] | |
206 | |
207 Generate makefile for building Chipset software | |
208 Logging all output to report.txt by default. | |
209 | |
210 OPTIONS: | |
211 -l LOGFILE log to LOGFILE (default is report.txt) | |
212 -S output to current shell, no logging to report.txt | |
213 -dlv DLVCFG delivery configuration, dlv_cfg0 by default | |
214 | |
215 EXAMPLES: | |
216 perl busyb.pl -f system\\busyb\\productdefs\\sample.xml | |
217 perl busyb.pl -f system\\busyb\\productdefs\\sample.xml -dlv dlvcfg2 | |
218 "; | |
219 } | |
220 | |
221 | |
222 #------------------------------------------------------------------------------- | |
223 # print current step to STDOUT (usually redirected to report.txt) and | |
224 # additionally to CONSOLE_OUT | |
225 #------------------------------------------------------------------------------- | |
226 sub print_status | |
227 { | |
228 print "\n----------------------------------------------------------------"; | |
229 print "\n$_[0]\n"; | |
230 print "----------------------------------------------------------------\n\n"; | |
231 | |
232 print CONSOLE_OUT "$_[0]\n" | |
233 if $outerr_redirected; | |
234 } | |
235 | |
236 | |
237 | |
238 #------------------------------------------------------------------------------- | |
239 # Check/Initialize some necessary env. variables: | |
240 # - %PATH must contain gpf/bin, gpf/tools/bin, chipsetsw/system (in that order) | |
241 # - %PATH* variables must only contain slashes (no backslashes, semicolons) | |
242 #------------------------------------------------------------------------------- | |
243 sub init_environment | |
244 { | |
245 my $current_drive_winformat = $current_drive; | |
246 $current_drive_winformat =~ s:/:\\:g; | |
247 | |
248 # check if all necessary paths are in %PATH, add them if not (this removes | |
249 # the dependency on initvars.bat) | |
250 if (!($ENV{'PATH'} =~ m:[\\/]chipsetsw[\\/]system:)) | |
251 { | |
252 # add \chipsetsw\system to %PATH (should be third) | |
253 $ENV{'PATH'} = "$current_drive_winformat\\chipsetsw\\system;" . $ENV{'PATH'}; | |
254 print "%PATH : \"$current_drive_winformat\\chipsetsw\\system\" + %PATH\n"; | |
255 } | |
256 | |
257 if (!($ENV{'PATH'} =~ m:[\\/]gpf[\\/]tools[\\/]bin:)) | |
258 { | |
259 # add \gpf\tools\bin to %PATH (should be second) | |
260 $ENV{'PATH'} = "$current_drive_winformat\\gpf\\tools\\bin;" . $ENV{'PATH'}; | |
261 print "%PATH : \"$current_drive_winformat\\gpf\\tools\\bin\" + %PATH\n"; | |
262 } | |
263 | |
264 if (!($ENV{'PATH'} =~ m:[\\/]gpf[\\/]bin:)) | |
265 { | |
266 # add \gpf\bin to %PATH (should be first) | |
267 $ENV{'PATH'} = "$current_drive_winformat\\gpf\\bin;" . $ENV{'PATH'}; | |
268 print "%PATH : \"$current_drive_winformat\\gpf\\bin\" + %PATH\n"; | |
269 } | |
270 | |
271 # check correct setting of environment variables for TI compiler and linker | |
272 # PATH_CC_1_22e=C:\tools\TMS4701x_1.22e\NT | |
273 die "\nERROR: environment variable %PATH_CC_1_22e must be set!\n" | |
274 unless exists($ENV{'PATH_CC_1_22e'}); | |
275 $ENV{'PATH_CC_1_22e'} =~ s|\\|/|g; | |
276 $ENV{'PATH_CC_1_22e'} =~ s|;.*||; | |
277 print "%PATH_CC_1_22e : \"" . $ENV{'PATH_CC_1_22e'} . "\"\n"; | |
278 | |
279 | |
280 # PATH_LNK_1_9902=C:\tools\vislink_1.9902 | |
281 die "\nERROR: environment variable %PATH_LNK_1_9902 must be set!\n" | |
282 unless exists($ENV{'PATH_LNK_1_9902'}); | |
283 $ENV{'PATH_LNK_1_9902'} =~ s|\\|/|g; | |
284 $ENV{'PATH_LNK_1_9902'} =~ s|;.*||; | |
285 print "%PATH_LNK_1_9902 : \"" . $ENV{'PATH_LNK_1_9902'} . "\"\n"; | |
286 | |
287 | |
288 } # init_environment | |
289 | |
290 | |
291 #------------------------------------------------------------------------------- | |
292 # Check for gnumake availability, returns gnumake depending or die | |
293 #------------------------------------------------------------------------------- | |
294 sub check_gnumake_available | |
295 { | |
296 my ($rc) = int (system("gnumake -ver > NUL 2>&1") / 256); | |
297 if(!$rc == 0){ | |
298 die "\nERROR: No make gnumake tool found, aborting"; | |
299 } | |
300 } | |
301 | |
302 #------------------------------------------------------------------------------- | |
303 # Check if Java is installed (in the path), return version string of Java. | |
304 #------------------------------------------------------------------------------- | |
305 sub determine_java_version | |
306 { | |
307 my $java_ver = `java -version 2>&1`; | |
308 if ($? == 0) | |
309 { | |
310 # only keep the first line of java version string and remove "java", if present | |
311 $java_ver =~ s/\n.*$//s; | |
312 $java_ver =~ s/\s*java\s*//; | |
313 print "Java : " . $java_ver . "\n"; | |
314 } | |
315 else | |
316 { | |
317 die "\nERROR: Java not found (not installed or not in the path), aborting"; | |
318 } | |
319 } | |
320 | |
321 | |
322 sub step__check_environment | |
323 { | |
324 print_status ($_[0] . ". Checking environment"); | |
325 | |
326 # create the makefile filename | |
327 # param = system\productdefs\sample.xml | |
328 # o_file = system/productdefs/sample.xml | |
329 # print_status ($_[0] . " 1 " .$makeFile); | |
330 # print_status ($_[0] . " 2 " .$o_file); | |
331 # print_status ($_[2] . " 3 " .$o_dlvcfg); | |
332 | |
333 $makeFile = (File::Spec->splitpath($o_file))[2]; | |
334 $makeFile =~ s/(\.xml)$//; | |
335 if ($o_dlvcfg) | |
336 { | |
337 $makeFile =$makeFile."_".$o_dlvcfg; | |
338 } | |
339 $makeFile =$makeFile.".mak"; | |
340 | |
341 # initialize necessary env. variables (%PATH, %C_DIR) | |
342 init_environment(); | |
343 check_gnumake_available(); | |
344 determine_java_version(); | |
345 | |
346 } | |
347 | |
348 | |
349 #------------------------------------------------------------------------------- | |
350 # update BuSyB makefile, if necessary; takes an additional second parameter | |
351 # to specify the BuSyB .ini file | |
352 #------------------------------------------------------------------------------- | |
353 sub step__update_busyb_makefile | |
354 { | |
355 | |
356 my $temp_xml = "dlv_mak.xml"; | |
357 open( MSL_FD,">$temp_xml") | |
358 or die "ERROR: Can't open file \"$temp_xml\" ($!), aborting"; | |
359 | |
360 print MSL_FD "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
361 print MSL_FD "<configDef name=\"dlv_mak\" description=\"\" reference=\"\">\n"; | |
362 print MSL_FD "<property include=\"$o_file\"/>\n"; | |
363 | |
364 if ($o_dlvcfg) | |
365 { | |
366 print MSL_FD "<property include=\"$dlv_cfg\"/>\n"; | |
367 } | |
368 print MSL_FD "</configDef>\n"; | |
369 | |
370 close( MSL_FD) | |
371 or die "ERROR: Can't close file \"$temp_xml\" ($!), aborting"; | |
372 | |
373 use constant UBB_MAKETOOL => "gnumake "; | |
374 use constant UBB_UPDATE_MAKE => "-f system/nds_update_makefile.mak "; | |
375 | |
376 print_status ($_[0] . ". Generate BuSyB makefile ($makeFile)"); | |
377 # $command = UBB_MAKETOOL.UBB_UPDATE_MAKE." MFILE=$makeFile XMLFILE=$o_file"; | |
378 $command = UBB_MAKETOOL.UBB_UPDATE_MAKE." MFILE=$makeFile XMLFILE=$temp_xml"; | |
379 print "$command\n\n"; | |
380 | |
381 system($command) == 0 | |
382 or die "ERROR: Can't create makefile \"$makeFile\" ($!), aborting"; | |
383 print "\n"; | |
384 | |
385 $command = "rm $temp_xml"; | |
386 print "$command\n\n"; | |
387 system($command) == 0 | |
388 or die "ERROR: Can't remove temporary file \"$temp_xml\" ($!), aborting"; | |
389 | |
390 } | |
391 | |
392 | |
393 #------------------------------------------------------------------------------- | |
394 # redirect STDOUT+STDERR to $o_logfile, return 1 if redirection successful or | |
395 # 0 if redirection failed | |
396 #------------------------------------------------------------------------------- | |
397 sub redirect_output | |
398 { | |
399 my $redirected = 1; | |
400 | |
401 open (CONSOLE_OUT, ">&STDOUT"); | |
402 open (CONSOLE_ERR, ">&STDERR"); | |
403 | |
404 open (STDOUT, '>', $o_logfile) | |
405 or $redirected = 0; | |
406 open (STDERR, ">&STDOUT") | |
407 or $redirected = 0; | |
408 | |
409 if ($redirected) | |
410 { | |
411 # make output unbuffered | |
412 select (STDERR); $| = 1; | |
413 select (STDOUT); $| = 1; | |
414 | |
415 # install signal handler function for die() | |
416 $SIG{__DIE__} = \&die_handler | |
417 or print CONSOLE_ERR "WARNING: Could not install die() signal handler, | |
418 console output may be corrupted when exiting with an error!\n"; | |
419 } | |
420 else | |
421 { | |
422 # redirection failed: use old STDOUT+STDERR | |
423 restore_redirection(); | |
424 print "WARNING: Could not redirect STDOUT+STDERR to " . $o_logfile . ", not logging output!\n"; | |
425 } | |
426 return $redirected; | |
427 } | |
428 | |
429 | |
430 #------------------------------------------------------------------------------- | |
431 # close logging to $o_logfile and restore old STDOUT+STDERR | |
432 # (pointing to console) | |
433 #------------------------------------------------------------------------------- | |
434 sub restore_redirection | |
435 { | |
436 # restore redirected STDOUT+STDERR | |
437 close (STDOUT); | |
438 close (STDERR); | |
439 open (STDOUT, ">&CONSOLE_OUT"); | |
440 open (STDERR, ">&CONSOLE_ERR"); | |
441 } | |
442 | |
443 | |
444 #------------------------------------------------------------------------------- | |
445 # print die() error message, to also log it to $o_logfile and then restore | |
446 # the STDOUT+STDERR redirection | |
447 #------------------------------------------------------------------------------- | |
448 sub die_handler | |
449 { | |
450 print STDERR $_[0]; | |
451 restore_redirection(); | |
452 } |