FreeCalypso > hg > leo2moko-debug
comparison g23m/system/busyb/tools/gen_targetSet.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 use strict; | |
3 | |
4 # import some modules | |
5 use File::Spec; | |
6 | |
7 # define global variables | |
8 my $inputDir=$ARGV[0]; | |
9 my $outFile=$ARGV[1]; | |
10 my $pathSetDir=$ARGV[2]; | |
11 my $condition; | |
12 | |
13 my @TI_LIBS; | |
14 my @TI_MAIN_LIBS; | |
15 my (@TI_BSS_LIBS, @TI_CONST_LIBS, @CONST_BOOT_LIB, @BSS_BOOT_LIB,@BSS_DAR_LIB); | |
16 my (@SP_LIB, @SP_LOC); | |
17 my @CMD_TEMPLATE; | |
18 | |
19 if ($#ARGV < 0) { | |
20 print "usage: gen_targetSet <inputDir> <outputFile> <pathSetDir>\n"; | |
21 print "example: gen_targetSet busyb_integration busyb_integration/tsFragment.xml x:/g23m/system/busyb\n"; | |
22 exit; | |
23 } | |
24 | |
25 # Find the target set files | |
26 # | |
27 my @tsFiles = glob("$inputDir/*.ts"); | |
28 $#tsFiles >= 0 || die "No *.ts files found\n"; | |
29 | |
30 # open the output file | |
31 # | |
32 open (OUT,">$outFile")||die "can't open $outFile \n"; | |
33 | |
34 # process all input files | |
35 # | |
36 foreach (@tsFiles) { | |
37 my $line; | |
38 # open the input file | |
39 # | |
40 open (IN,"<$_")||die "can't open $_ \n"; | |
41 | |
42 # calculate the condition | |
43 # | |
44 $condition = calcConditionFromFileName($_); | |
45 | |
46 # read the input file | |
47 # | |
48 while(defined($line = <IN>)) | |
49 { | |
50 # remove trailing \n | |
51 chomp($line); | |
52 | |
53 # now find all entries and generate corresponding output strings | |
54 # | |
55 | |
56 # first the "normal" libs | |
57 if ($line =~ /^\[TI_LIBS\]\s*/) { | |
58 my @tmp = split(/\s+/,$'); | |
59 my $element; | |
60 foreach $element(@tmp) { | |
61 my $libName = calcRelativePathFromPathset ($element, $pathSetDir); | |
62 # all *main* libs must be placed at the very beginning, | |
63 # otherwise the Visual Linker complains | |
64 if ($libName =~ /\\main_/) { | |
65 push(@TI_MAIN_LIBS, "<sourceFile pathRef=\"\" path=\"$libName\" require=\"$condition\"/>"); | |
66 } | |
67 else { | |
68 push(@TI_LIBS, "<sourceFile pathRef=\"\" path=\"$libName\" require=\"$condition\"/>"); | |
69 } | |
70 } | |
71 } | |
72 # now the linker command file templates | |
73 elsif ($line =~ /^\[CMD_TEMPLATE\]\s*/) { | |
74 my $fileName = calcRelativePathFromPathset ($', $pathSetDir); | |
75 push (@CMD_TEMPLATE, "<sourceFile pathRef=\"\" path=\"$fileName\" require=\"$condition\"/>"); | |
76 } | |
77 | |
78 # now all others: that are those that need memory placement | |
79 # (TI_BSS_LIBS, TI_CONST_LIBS, CONST_BOOT_LIB, CONST_BOOT_LIB, BSS_BOOT_LIB, BSS_DAR_LIB) | |
80 elsif ($line =~ /^\[(\w+)\]\s*/) { | |
81 my $restLine = $'; | |
82 my $pattern = $1; | |
83 | |
84 # replace TI_BSS_LIBS with BSS_LIBS and TI_CONST_LIBS with CONST_LIBS | |
85 $pattern =~ s/TI_BSS_LIBS/BSS_LIBS/; | |
86 $pattern =~ s/TI_CONST_LIBS/CONST_LIBS/; | |
87 | |
88 my @AoA; | |
89 my @tmp = split(/\s+\(|\)\s+/,$restLine); | |
90 @AoA = createLibAndLocArrays(\@tmp, "$pattern", $condition); | |
91 push(@SP_LIB, @{$AoA[0]}); | |
92 push(@SP_LOC, @{$AoA[1]}); | |
93 } | |
94 } | |
95 # close the input file | |
96 # | |
97 close IN; | |
98 } | |
99 | |
100 # now generate the output file | |
101 # | |
102 print OUT "<!-- This is a generated file! Do not change ! -->\n\n"; | |
103 print OUT "<!-- It's output is based on the information in the following files:\n"; | |
104 foreach (@tsFiles) { | |
105 print OUT "\t$_\n"; | |
106 } | |
107 | |
108 print OUT "-->\n<!-- All of it must be placed somewhere in a targetSet document! -->\n\n\n"; | |
109 | |
110 print OUT "<!-- The next lines contain all SSA lib's that DO NOT NEED special memory placement! -->\n\n"; | |
111 foreach (@TI_MAIN_LIBS,@TI_LIBS) { | |
112 print OUT "$_\n"; | |
113 } | |
114 print OUT "\n\n\n\n\n"; | |
115 | |
116 print OUT "<!-- The next lines contain all linker command file templates! -->\n\n"; | |
117 foreach (@CMD_TEMPLATE) { | |
118 print OUT "$_\n"; | |
119 } | |
120 print OUT "\n\n\n\n\n"; | |
121 | |
122 print OUT "<!-- The next lines contain memory placement commands for all SSA lib's that DO NEED special memory placement! -->\n\n"; | |
123 foreach (@SP_LOC) { | |
124 print OUT "$_\n"; | |
125 } | |
126 print OUT "\n\n\n\n\n"; | |
127 | |
128 print OUT "<!-- The next lines contain all SSA lib's that DO NEED special memory placement!\nThe order corresponds with the previews section. Do not change it!-->\n\n"; | |
129 foreach (@SP_LIB) { | |
130 print OUT "$_\n"; | |
131 } | |
132 | |
133 | |
134 # close the file | |
135 # | |
136 close OUT; | |
137 | |
138 | |
139 ###################################################################################################### | |
140 # this function takes as the input the output of split for all libs that need special memory placement | |
141 # this is an array which looks as follows | |
142 # Array: liba (.text) libb (.const) ... | |
143 # | |
144 # it returns two arrays which lokk as follows | |
145 # Array A: liba libb .. | |
146 # Array B: (.text) (.const) | |
147 # | |
148 sub createLibAndLocArrays | |
149 { | |
150 my @libsAndSections = @{$_[0]}; | |
151 my $section = $_[1]; | |
152 my $condition = $_[2]; | |
153 my $i = 0; | |
154 my (@libs, @places); | |
155 | |
156 foreach (@libsAndSections) { | |
157 if($i==0) { | |
158 my $libName = calcRelativePathFromPathset ($_, $pathSetDir); | |
159 push(@libs, "<sourceFile pathRef=\"\" path=\"$libName\" require=\"$condition\"/>"); | |
160 $i++; | |
161 } | |
162 else { | |
163 my $location = "($section)-($_)+"; | |
164 push(@places, "<condValue value=\"$location\" require=\"$condition\" />" ); | |
165 $i--; | |
166 } | |
167 } | |
168 | |
169 return (\@libs, \@places); | |
170 } | |
171 | |
172 | |
173 ########################################### | |
174 # calculate the condition from the filename | |
175 # make aaa==1 & bbb==2 from aaa1_bbb2.ts | |
176 # | |
177 sub calcConditionFromFileName | |
178 { | |
179 my $condition = ""; | |
180 my @cond; | |
181 my $i = 0; | |
182 | |
183 # remove directory part | |
184 my ($drive,$directories,$file); | |
185 ($drive,$directories,$file) = File::Spec->splitpath($_[0]); | |
186 | |
187 # now remove file extension | |
188 $file =~ /\.\w*/; | |
189 | |
190 # now split the name into sub conditions e.g. aaa1 bbb2 | |
191 @cond = split(/_/,$`); | |
192 | |
193 foreach (@cond) { | |
194 while (s/([a-zA-Z0-9]+)-(\d+)//) { | |
195 $condition = $condition . "(" . $1 . "==" . $2 .")"; | |
196 defined($cond[++$i]) && ($condition = $condition . " && "); | |
197 } | |
198 } | |
199 $condition =~ s/ && $//; | |
200 return $condition; | |
201 } | |
202 ########################################### | |
203 | |
204 ######################################################## | |
205 # correct obscure behavior of File::Spec->abs2rel, | |
206 # which inserts a drive letter befor a relative path !!! | |
207 # | |
208 sub calcRelativePathFromPathset | |
209 { | |
210 my ($drive,$directories,$file); | |
211 | |
212 ($drive,$directories,$file) = File::Spec->splitpath( File::Spec->abs2rel ($_[0], $_[1]) ); | |
213 | |
214 return File::Spec->catpath("",$directories,$file); | |
215 } | |
216 ######################################################## |