FreeCalypso > hg > leo2moko-debug
comparison g23m/system/busyb/tools/tune_mak.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 # This script modifies a BUSYB generated makefile. Once BUSYB generates variables it | |
4 # won't be needed anymore. | |
5 # It collects all *.obj *.lib ... files and writes them into variables. | |
6 use strict; | |
7 | |
8 my %objects; | |
9 my %libs; | |
10 my %cs; | |
11 my %pdfs; | |
12 my %mdfs; | |
13 my $mconst; | |
14 my $rvswe; | |
15 | |
16 (@ARGV == 3) || die "Usage: tune_mak <in_file> <out_file> <abc_exp_name>"; | |
17 | |
18 open(IN, $ARGV[0]) || die "Could not open file $ARGV[0]: $!"; | |
19 | |
20 while (<IN>) { | |
21 if (/\%/) { | |
22 # ignore lines that contain the % charater | |
23 } | |
24 elsif (/ (__out__.+?\.obj)\b/) { | |
25 $objects{$1} = ""; | |
26 } | |
27 elsif (/ (__out__.+?\.lib)\b/) { | |
28 $libs{$1} = ""; | |
29 } | |
30 elsif (/ (__out__.+?\.c)\b/) { | |
31 $cs{$1} = ""; | |
32 } | |
33 elsif (/ (__out__.+?\.pdf)\b/) { | |
34 $pdfs{$1} = ""; | |
35 } | |
36 elsif (/ (__out__.+?\.mdf)\b/) { | |
37 my $doc = $1; | |
38 # special handling for m_rrlp_asn1_msg.mdf, m_rrlp_asn1_inc.mdf | |
39 # remove m_ to allow name deduction for TDC | |
40 if ($doc =~ /m_(rrlp_asn1)/) { | |
41 $mdfs{"$`$1$'"} = ""; | |
42 } | |
43 else { | |
44 $mdfs{$doc} = ""; | |
45 } | |
46 } | |
47 elsif (/ (__out__.+?mconst\.cdg)\b/) { | |
48 $mconst = $1; | |
49 } | |
50 elsif (/ (__out__.+?rv_swe\.h)\b/) { | |
51 $rvswe = $1; | |
52 } | |
53 } | |
54 | |
55 | |
56 my @objects = sort(keys(%objects)); | |
57 my @libs = sort(keys(%libs)); | |
58 my @cs = sort(keys(%cs)); | |
59 my @pdfs = sort(keys(%pdfs)); | |
60 my @mdfs = sort(keys(%mdfs)); | |
61 | |
62 close IN; | |
63 | |
64 # reopen and modify the file | |
65 open(IN, $ARGV[0]) || die "Could not open file $ARGV[0]: $!"; | |
66 open(OUT, ">$ARGV[1]") || die "Could not open file $ARGV[1]: $!"; | |
67 | |
68 my $i; | |
69 my $line; | |
70 my $tdcSpecial = 0; | |
71 while (defined ($line = <IN>)) { | |
72 if (($line =~ /###BSB_OUT_MCONST/) && defined($mconst)) { | |
73 print OUT "BSB_OUT_MCONST = $mconst\n"; | |
74 } | |
75 elsif (($line =~ /###BSB_OUT_RVSWE/) && defined($rvswe)) { | |
76 print OUT "BSB_OUT_RVSWE = $rvswe\n"; | |
77 } | |
78 elsif (($line =~ /###BSB_OUT_OBJS/) && @objects > 0) { | |
79 print OUT "BSB_OUT_OBJS = "; | |
80 for ($i=0;$i<@objects;$i++) { | |
81 print OUT "$objects[$i] "; | |
82 # if ($i<(@objects-1)) { | |
83 # print " \\"; | |
84 # } | |
85 # print "\n"; | |
86 } | |
87 print OUT "\n"; | |
88 } | |
89 elsif (($line =~ /###BSB_OUT_CS/) && @cs > 0) { | |
90 print OUT "BSB_OUT_CS = "; | |
91 for ($i=0;$i<@cs;$i++) { | |
92 print OUT "$cs[$i] "; | |
93 } | |
94 print OUT "\n"; | |
95 } | |
96 elsif (($line =~ /###BSB_OUT_LIBS/) && @libs > 0) { | |
97 print OUT "BSB_OUT_LIBS = "; | |
98 for ($i=0;$i<@libs;$i++) { | |
99 print OUT "$libs[$i] "; | |
100 } | |
101 print OUT "\n"; | |
102 } | |
103 elsif (($line =~ /###BSB_OUT_PDFS/) && @pdfs > 0) { | |
104 print OUT "BSB_OUT_PDFS = "; | |
105 for ($i=0;$i<@pdfs;$i++) { | |
106 print OUT "$pdfs[$i] "; | |
107 } | |
108 print OUT "\n"; | |
109 } | |
110 elsif (($line =~ /###BSB_OUT_MDFS/) && @mdfs > 0) { | |
111 print OUT "BSB_OUT_MDFS = "; | |
112 for ($i=0;$i<@mdfs;$i++) { | |
113 print OUT "$mdfs[$i] "; | |
114 } | |
115 print OUT "\n"; | |
116 } | |
117 # same condition as in first run - this needs a cleanup | |
118 elsif ($line =~ s/^(__out__.+?)(rv_swe\.h):/$1$2 $1%\.cfg:/) { | |
119 print OUT $line; | |
120 } | |
121 # same condition as in first run - this needs a cleanup | |
122 elsif ($line =~ s/^(__out__.+?)(cdginc\/)(mconst\.cdg):/$1$2$3 $1$2%\.cdg $1$2%\.h $1$2%\.val $1tdcinc\/%\.cpp:/) { | |
123 print OUT $line; | |
124 } | |
125 # BuSyB generates a fixed "-include abc_exports.mak" statement but we want | |
126 # to include <makefile>.abc_exports.mak, given as 3rd parameter. | |
127 elsif ($line =~ s/ abc_exports.mak$/ $ARGV[2]/) { | |
128 print OUT $line; | |
129 } | |
130 elsif ($line =~ /^(__out__.+?)(tdclib\.lib):/) { | |
131 $tdcSpecial = 1; | |
132 print OUT $line; | |
133 } | |
134 elsif ($tdcSpecial) { | |
135 $tdcSpecial = 1; | |
136 if ($line =~ /(__out__.+?)p_(%.*?)(_dsc)?\.obj/ ) { | |
137 print OUT "\$(patsubst __out__/g23m_dfile/prim/%.pdf,$&,\$(BSB_OUT_PDFS))$'"; | |
138 } | |
139 elsif ($line =~ /(__out__.+?)m_(%.*?)(_dsc)?\.obj/ ) { | |
140 print OUT "\$(patsubst __out__/g23m_dfile/msg/%.mdf,$&,\$(BSB_OUT_MDFS))$'"; | |
141 } | |
142 else { | |
143 print OUT $line; | |
144 } | |
145 if ($line =~ /\\$/) { | |
146 } | |
147 else { | |
148 $tdcSpecial = 0; | |
149 } | |
150 } | |
151 else { | |
152 print OUT $line; | |
153 } | |
154 } |