-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_toolchain.pl
executable file
·99 lines (79 loc) · 2.42 KB
/
build_toolchain.pl
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
#!/usr/bin/perl
## Howto
##
## build_toolchain.pl xml_config_file user_name
##
## xml_config_file : an xml_config_file of a toolchain
## user_name : the name of the user that requested the cross toolchain to be built
##
## This file builds a crosstool-ng toolchain using a reduced number of parameters given within an xml configuration file
##
#########
use DBI;
my $HOME = '/var/www/html/home';
## Retrieving the work directory
my $WORKING_DIR = `readlink -f $0`;
$WORKING_DIR = `dirname $WORKING_DIR`;
chomp $WORKING_DIR;
if($#ARGV == 1)
{
$xml_config_file = $ARGV[0];
if( -f $xml_config_file)
{}
else
{
die 'The config file does not exist';
}
$user_name = $ARGV[1];
if( -d "$HOME/$user_name")
{}
else
{
die 'This user does not exist';
}
}
else
{
die 'Wrong number of parameters';
}
if($xml_config_file =~ m/.*\/(.*)\.xml$/)
{
$xml_file_name = $1;
}
$DIR_CROSSTOOL_NG="crosstool-ng-1.3.2";
$DIR_TARBALLS="tarballs";
$DIR_USER_TOOLCHAINS="toolchains";
chdir "$WORKING_DIR/$DIR_CROSSTOOL_NG";
## Copying sstrip with the correct name in the src directory to avoid a bug in crosstool-ng
system ("mkdir -p targets/src/sstrip");
system("cp ../tarballs/sstrip.c targets/src/sstrip/");
## Generating the .config file from the xml config file and modifying some parameters
system("perl ../xml2config.pl $xml_config_file");
my $sed_script = "sed -i '";
$sed_script = "$sed_script" . "s,CT_LOCAL_TARBALLS_DIR=.*,CT_LOCAL_TARBALLS_DIR=\"$WORKING_DIR/$DIR_TARBALLS\",;";
$sed_script = "$sed_script" . "s,CT_INSTALL_DIR_RO=.*,# CT_INSTALL_DIR_RO is not set,;";
$sed_script = "$sed_script" . "s,CT_PREFIX_DIR=.*,CT_PREFIX_DIR=\"$WORKING_DIR/$DIR_USER_TOOLCHAINS/$xml_file_name\",' .config";
system($sed_script);
## Building the toolchain
$res = system("./ct-ng build");
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $date_fin = "$mday/".($mon+1)."/$year";
if($res == 0)
{
$status = 'Chaine prête';
system("cp $HOME/$user_name/mytoolchains/$xml_file_name.xml $WORKING_DIR/config-toolchains");
}
else
{
$status = 'Echec de la génération';
}
$dsn = "dbi:mysql:vlab";
$login = "apache";
$mdp = "myvlab";
$dbh = DBI->connect($dsn, $login, $mdp) or die "Connection failure\n";
$request = "update toolchain set status='$status', build_date='$build_date' where name='$xml_file_name'";
$sth = $dbh->prepare($request);
$sth->execute();
## Cleaning up the source and build files
Clean:
#system("./ct-ng distclean");