[r144]: buildgcc.pl Maximize Restore History

Download this file

buildgcc.pl    266 lines (232 with data), 8.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env perl
# This work is partially financed by the European Commission under the
# Framework 6 Information Society Technologies Project
# "Wirelessly Accessible Sensor Populations (WASP)".
use warnings 'all';
print "\n";
print "NOTE: This SVN repository is purely for reference and use by the WASP\n";
print "Project and its users. If your MSPGCC4 interest is unrelated to WASP,\n";
print "please use MSPGCC4's Git repository instead!\n\n";
print "URL: <https://sourceforge.net/scm/?type=git&group_id=277223>\n\n";
print "Continuing in 10 seconds...\n";
sleep 10;
$g_DialogPresent = (`which dialog 2>/dev/null` ne '');
if (!grep { /--default-item/ } `dialog --help 2>&1`) {
# insufficient dialog version (FreeBSD for instance)
$g_DialogPresent = '';
}
sub SystemCheck($$); # forward declaration
sub CallDialog($)
{
my $ansfile = "/tmp/dialog-$$.ans";
my $cmd = "dialog $_[0] 2>$ansfile";
my $rc = system($cmd);
if ($rc)
{
unlink($ansfile);
SystemCheck($rc, $cmd);
die "Cannot execute dialog. Abort";
}
my $answer = `cat $ansfile` or return -1;
unlink($ansfile);
return $answer;
}
#int SelectFromList(defaultIdx, Title, Option1, Option2, ...)
sub SelectFromList
{
my $default = (shift @_) + 1;
my $title = shift @_, $optionCount = 0;
if ($g_DialogPresent)
{
my $options = '';
my $width = length($title) + 4;
$options .= ' ' . ++$optionCount . " \"$_\"" foreach (@_);
my $res = CallDialog("--default-item $default --menu \"$title\" ".($optionCount + 7)." $width $optionCount $options");
return $res - 1;
}
else
{
print "\n$title\n";
print ++$optionCount . ") $_\n" foreach @_;
print "Enter your choice (1-$optionCount) [$default]: ";
my $r = <STDIN>;
chomp $r;
$r = $default if $r eq '';
return $r-1;
}
}
#string AskForString (prompt, width, default)
sub AskForString($$$)
{
if ($g_DialogPresent)
{
return CallDialog("--inputbox \"$_[0]\" 7 $_[1] \"$_[2]\"");
}
else
{
print "\n$_[0]\n[$_[2]]: ";
my $r = <STDIN>;
chomp $r;
$r = $_[2] if $r eq '';
return $r;
}
}
#bool AskYesNo(prompt, default)
sub AskYesNo($$)
{
if ($g_DialogPresent)
{
my $def;
my $lines = 4;
my $maxlen = 0;
foreach(split(/\n/, $_[0]))
{
$lines++;
$maxlen = length($_) if length($_) > $maxlen;
}
$def = " --defaultno" if $_[1] eq '0';
system("dialog$def --yesno \"$_[0]\" $lines ".($maxlen + 6));
return $? ? 0 : 1;
}
else
{
my $def = ($_[1] eq '0') ? 'n' : 'y';
print "\n$_[0] (y/n) [$def] ";
my $r = <STDIN>;
chomp $r;
$r = $def if $r eq '';
return ($r eq 'y') ? 1 : 0;
}
}
#Convert GNU versions to comparable integers (e.g. 1.2.3 => 0x01020300, 1.2 => 0x01020000)
sub GNUVersionToInt
{
my @vn = split(/[\.-]/, $_[0]);
push @vn, 0 while $#vn < 3;
my $ret = 0;
while ($#vn != -1)
{
$ret <<= 8;
$ret += shift @vn;
}
return $ret;
}
# Check for and report errors from 'system' function (status code, command previously executed)
# returns 1 for success, 0 for failure.
sub SystemCheck($$)
{
my ($rc, $cmd) = @_;
if ($rc == -1) {
print "could not execute $cmd: $!.\n";
} elsif ($rc & 127) {
printf "$cmd terminated with signal %d.\n", ($? & 127);
} elsif ($rc == 0) {
print "$cmd completed successfully.\n";
} else {
printf "$cmd exited with status code %d.\n", $? >> 8;
}
return $rc == 0 ? 1 : 0;
}
#----------------------------------------------------------------------------------------------------------------------------------
$BINUTILS_VERSION = "2.20.1";
$GNU_MIRROR="http://ftp.uni-kl.de";
$BUILD_DIR="build";
$GMP_VERSION="4.3.1";
$MPFR_VERSION="2.4.1";
@GCC_VERSIONS = (
{'ver' => '4.4.3', 'config' => '4.x'},
{'ver' => '4.4.2', 'config' => '4.x'},
{'ver' => '4.3.4', 'config' => '4.x'},
{'ver' => '4.2.4', 'config' => '4.x'},
{'ver' => '3.3.6', 'config' => '3.4'},
{'ver' => '3.2.3', 'config' => '3.3'},
);
@LIBC_VERSIONS = ('20100430', '20100403', '20100207');
@GDB_VERSIONS = grep(/^gdb-(.*)\.patch/, split("\n", `ls -1 -r`));
s/gdb-(.*)\.patch/$1/ foreach(@GDB_VERSIONS);
@GDB_VERSIONS = sort{GNUVersionToInt($b) <=> GNUVersionToInt($a)}(@GDB_VERSIONS);
@INSIGHT_VERSIONS = grep(/^insight-(.*)\.patch/, split("\n", `ls -1 -r`));
@INSIGHT_VERSIONS = sort{GNUVersionToInt($b) <=> GNUVersionToInt($a)}(@INSIGHT_VERSIONS);
s/insight-(.*)\.patch/$1/ foreach(@INSIGHT_VERSIONS);
%GCCRELEASE = %{$GCC_VERSIONS[SelectFromList(0, "Select GCC version to build:", (map{'gcc-'.$$_{'ver'}}(@GCC_VERSIONS)), "none")]};
$GDBVERSION = $GDB_VERSIONS[SelectFromList(0, "Select GDB version to build:", (map{'gdb-'.$_}(@GDB_VERSIONS)), "none")];
$INSIGHTVERSION = $INSIGHT_VERSIONS[SelectFromList(0, "Select Insight version to build:", (map{'insight-'.$_}(@INSIGHT_VERSIONS)), "none")];
$idx = SelectFromList(1, "Select libc version to build:", "v1", @LIBC_VERSIONS);
$LIBC_ARG = "";
$LIBC_ARG = " \"http://sourceforge.net/projects/mspgcc4/files/msp430-libc/msp430-libc-$LIBC_VERSIONS[$idx-1].tar.bz2\"" if ($idx);
$STRIPBINS = AskYesNo("Strip debug information\nfrom executables after install?", 1);
$TARGETPATH = AskForString("Enter target toolchain path", 50, ((`uname -s` =~ /^MINGW/) ? "/c" : "/opt") ."/msp430-gcc-$GCCRELEASE{ver}");
$BINPACKAGE = '';
if (AskYesNo("Create binary package after build?", 1))
{
$BINPACKAGE = AskForString("Enter binary package name", 50, "msp430-gcc-$GCCRELEASE{ver}".(($GDBVERSION eq '') ? '' : "_gdb_$GDBVERSION").".tar.bz2");
}
$SKIP_BINUTILS = AskYesNo("Looks like binutils are already installed in $TARGETPATH.\nSkip building binutils?", 1) if (-e "$TARGETPATH/bin/msp430-as");
$BASEDIR = `pwd`;
chomp $BASEDIR;
$startnow = AskYesNo("Selected GCC $GCCRELEASE{ver}
GDB version: $GDBVERSION
Insight version: $INSIGHTVERSION
Target location: $TARGETPATH
Binary package name: $BINPACKAGE
-------------------------------------
Do you want to start build right now?", 0);
$SCRIPTFILE = '';
if (!$startnow)
{
$SCRIPTFILE = AskForString("Enter script name to generate", 50, "buildgcc-$GCCRELEASE{ver}".(($GDBVERSION eq '') ? '' : "_gdb_$GDBVERSION").".sh");
}
@COMMANDS = ();
if ($GCCRELEASE{ver} ne '')
{
push @COMMANDS, "sh do-binutils.sh \"$TARGETPATH\" \"$BINUTILS_VERSION\" \"$GNU_MIRROR\" \"$BUILD_DIR\"" unless $SKIP_BINUTILS;
push @COMMANDS, "sh do-gcc.sh \"$TARGETPATH\" \"$GCCRELEASE{ver}\" \"$GNU_MIRROR\" \"$BUILD_DIR\" \"gcc-$GCCRELEASE{config}\" \"$GMP_VERSION\" \"$MPFR_VERSION\"";
push @COMMANDS, "sh do-libc.sh \"$TARGETPATH\" \"$BUILD_DIR\"$LIBC_ARG";
}
# Install Insight before building GDB, because Insight installs its own
# (outdated) versions of msp430-gdb and -gdbtui.
if (defined $INSIGHTVERSION and $INSIGHTVERSION ne '') {
push @COMMANDS, "sh do-gdb.sh \"$TARGETPATH\" \"$INSIGHTVERSION\" \"$GNU_MIRROR\" \"$BUILD_DIR\" insight";
}
if (defined $GDBVERSION and $GDBVERSION ne '') {
push @COMMANDS, "sh do-gdb.sh \"$TARGETPATH\" \"$GDBVERSION\" \"$GNU_MIRROR\" \"$BUILD_DIR\" gdb";
}
push @COMMANDS, "sh stripbin.sh \"$TARGETPATH\"" if ($STRIPBINS);
if ($BINPACKAGE ne '')
{
push @COMMANDS, "echo \"Creating binary package...\"";
push @COMMANDS, "cd \"$TARGETPATH\" && tar cf - * | bzip2 -c > \"$BASEDIR/$BINPACKAGE\"";
push @COMMANDS, "ls -ldq \"$BASEDIR/$BINPACKAGE\"";
push @COMMANDS, "cd \"$BASEDIR\"" if $SCRIPTFILE ne '';
}
if ($SCRIPTFILE ne '')
{
mkdir $BUILD_DIR;
open F, ">$BUILD_DIR/$SCRIPTFILE" or die "Cannot open script $BUILD_DIR/$SCRIPTFILE for writing: $!";
print F "#!/bin/sh\ncd \"\$(dirname \$0)\"/..\nset -eu\n\n";
foreach (@COMMANDS) {
print F "$_\n" or die "Cannot write to $BUILD_DIR/$SCRIPTFILE: $!";
}
close F or die "Cannot write to $BUILD_DIR/$SCRIPTFILE: $!";
if (AskYesNo("$BUILD_DIR/$SCRIPTFILE created successfully.\nRun it now?",1))
{
chdir $BUILD_DIR;
my $cmd = "sh $SCRIPTFILE";
system($cmd);
SystemCheck($?, $cmd);
} else {
printf "Please run /bin/sh \"$BUILD_DIR/$SCRIPTFILE\" to start build process\n";
}
}
else
{
foreach my $cmd (@COMMANDS)
{
my $rc;
print "Running $cmd\n";
$rc = system($cmd);
if ($rc) {
SystemCheck($rc, $cmd) or die "Failed to execute $cmd";
}
}
}