comparison scripts/ti/make_cmd.pl @ 17:021ac9f5a765

scripts/ti/make_cmd.pl: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 07:24:56 +0000
parents
children
comparison
equal deleted inserted replaced
16:84160e9a0383 17:021ac9f5a765
1 #!perl
2
3 # generate a dynamic Linker command file
4 # PARAMETER ARE:
5
6 # 0 : Name of the file with the parameters
7 # 1 : Name of the Linker command file (output)
8 # 2 : value of the TOOL_CHOICE variable
9 # 3 : Name of the Linker command file template
10 # 4 - (n-1) : Name of the libraries
11
12 #$argcount = @ARGV;
13 my $lnk_opt_file=$ARGV[0];
14 my $cmd_file=$ARGV[1];
15 my $toolchoice_type = $ARGV[2];
16 my $cmd_file_temp=$ARGV[3];
17 my %section;
18
19
20 open (TMP,$lnk_opt_file)||die "can't open file\n";
21
22 # parse the parameter file and construct replacement strings
23 #
24 # the file contains entries of the following form
25 # (BSS_LIBS (.bss))
26 # or
27 # (BSS_LIBS (.bss) CONST_LIBS (.text, .const))
28 # or
29 # (BSS_LIBS (.bss)) (BSS_LIBS (.bss) CONST_LIBS (.text, .const))
30 #
31 # the syntax is as follows, white space and line breaks are not significant
32 # <ENTRY> := <lp> <PAIR><lp>
33 # <PAIR> := <name> <SECTION>
34 # <SECTION> := <lp><free_text><lp>
35 # <lp> := (
36 # <rp> := )
37 # <name> := [A-Za-z_]+
38 # <free_text> := [^()]+
39 #
40 # each entry will be linked with one library passed on the command line
41
42 my $line;
43 my $count;
44 while ($line=<TMP>) {
45 # find <ENTRY>
46 while ($line =~ /\((\s*\w+\s*\([^\(\)]+\))+\)/) {
47 $line = $';
48 $match = $&;
49 # find <PAIR>
50 while ($match =~ /\s*(\w+)\s*(\([^\(\)]+\))/ ) {
51 $match = $';
52 $section{"$1"} .= "$ARGV[$count+4] $2\n";
53 }
54 $count++;
55 }
56 }
57
58 open (TMP1, ">$cmd_file");
59 open (TMP,$cmd_file_temp);
60 while ($line=<TMP>) {
61 my $replaced = 0;
62 foreach $key (keys(%section)) {
63 if ($line =~ /\($key\)/g) {
64 # insert the Libs
65 $line = $section{$key};
66 $replaced = 1;
67 }
68 }
69 # NEW COMPILER MANAGEMENT
70 # If use of VISUAL LINKER, needs to manage trampoline download.
71 # Case of:
72 # - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
73 # - TOOL_CHOICE == 3 => compiler & linker v2.54
74
75 if ($toolchoice_type == 0) {
76 $line =~ s(COMMENT1START)(/*);
77 $line =~ s(COMMENT1END)(*/);
78 $line =~ s(COMMENT2START)();
79 $line =~ s(COMMENT2END)();
80 } else {
81 $line =~ s(COMMENT1START)();
82 $line =~ s(COMMENT1END)();
83 $line =~ s(COMMENT2START)(/*);
84 $line =~ s(COMMENT2END)(*/);
85 }
86
87 if ($replaced || !($line =~ /^\s*\$\(\s*\w+\s*\)\s*$/ )) {
88 print TMP1 $line;
89 }
90 }
91 close TMP;
92 close TMP1;
93 unlink $tmp_file;