[go: up one dir, main page]

Menu

[99352e]: / buildtool.pl  Maximize  Restore  History

Download this file

287 lines (246 with data), 9.7 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#! /usr/bin/perl -w
# main program buildtool2 for uclibc-bering
# Copyright (C) 2003 Arne Bernin
# Changes for Bering-uClibc 5.x Copyright (C) 2012 David M Brooke & Yves Blusseau
# This software is distributed under the GNU General Public Licence,
# please see the file COPYING
use FindBin qw($Bin); # where was script installed?
use lib $FindBin::Bin; # use that dir for libs, too
use File::Spec::Functions qw(:ALL);
use buildtool::buildtool;
use buildtool::Tools qw(:ALL);
use buildtool::Clean;
use buildtool::Make::Tar;
use buildtool::Make::Source;
use buildtool::Make::Build;
use buildtool::Make::Headers;
use buildtool::Make::PackageList;
use buildtool::Config;
use Config::General qw(ParseConfig);
use strict;
use vars ('%globConf');;
$::VERSION = '0.7';
our $baseDir = rel2abs($FindBin::Bin);
################################################################################
BEGIN {
my $lockfile = catfile( $FindBin::Bin, 'conf', 'lockfile');
# check for lockfile:
if (-f $lockfile){
die("\nIt seems you are already running another instance of buildtool, please wait until it finished!\n".
"if this is not true, please remove the $lockfile file yourself\n\n");
}
# else touch lockfile
die("making lockfile failed:".$!) if (system("touch $lockfile") != 0);
};
END {
my $errvar = $?;
my $lockfile = catfile( $FindBin::Bin, 'conf', 'lockfile' );
# whatever happens, remove lockfile
unlink $lockfile or die("removing lockfile '$lockfile' failed: $!");
exit($errvar);
}
sub usage {
print <<MYEOF
usage: $0 [option] command [pkgname|srcname] [...]
commands:
describe [pkgname|srcname]\t shows descriptionlines of package
list [sourced|built]\t\t shows a list of built/sourced packages and sources
dumpenv [pkgname|srcname]\t dump the environment of buildtool and package
source [pkgname|srcname] \t downloads, unpacks and patches
\t the wanted package/source
build [pkgname|srcname] \t the same as source, but builds
\t and installs sources/packages also
pkglist [pkgname|srcname] \t create a list with all dependencies
\t for the package given or all if no name given
buildclean [pkgname|srcname]\t removes everything that is outside
\t the source dir
srcclean [pkgname|srcname]\t same as buildclean + call make srcclean
remove [pkgname|srcname]\t same as buildclean + remove everything from dldir
distclean \t remove everything
maketar \t make a tar for distribution
options:
-v \t just print version and exit
-f \t allows you to force the command even if the internal
\t state of buildtool states it has nothing to do
-O \t Do not override default Server entries with the ones
\t found in package/source buildtool config
-D \t Download nothing, use files in Source dir (useful for devel)
-d \t Only to be used in conjunction with the "source" target.
\t Only download files, don't invoke the source action on buildtool.mk
-t toolchain \t Build using the specified toolchain
\t (or actually build that toolchain if srcname = "toolchain")
\t Value of "toolchain" is e.g. i486-unknown-linux-uclibc
MYEOF
;
exit(1);
}
# ' <- fix emacs fontification
sub load_global_configfile {
my ($global_config_file) = @_;
return
Config::General::ParseConfig(
"-ConfigFile" => make_absolute_path( $global_config_file, $baseDir ),
'-IncludeRelative' => 1,
'-IncludeGlob' => 1,
"-LowerCaseNames" => 1
);
}
################################################################################
my %force_config = ();
&usage() if ($#ARGV < 0);
# check the
while ( $ARGV[0] and $ARGV[0] =~ /^-.*/ ) {
my $option = $ARGV[0];
$option =~ s/^-(.*)$/$1/;
shift;
# now switch according to option:
if ($option eq "v" or $option eq "-version") {
print "Version: $::VERSION" . "\n";
exit (0);
} elsif ($option eq "h" or $option eq "-help") {
&usage();
} elsif ($option eq "f") {
$force_config{'force'} = 1;
} elsif ($option eq "D") {
$force_config{'nodownload'} = 1;
} elsif ($option eq "O") {
$force_config{'noserveroverride'} = 1;
} elsif ($option eq "d") {
$force_config{'downloadonly'} = 1;
} elsif ($option eq "t") {
$force_config{'toolchain'} = $ARGV[0];
shift;
} else {
print buildtool::Common::Object::make_text_red('',"Error:" ) . " Unknown Option -" . $option . "\n\n";
exit(1);
}
}
# load buildtool.conf and buildtool.local configurations
%globConf = readBtGlobalConfig(
ConfigFile => catfile( $baseDir, 'conf', 'buildtool.conf' ),
ForceConfig => {
%force_config,
'root_dir' => $baseDir, # inject root_dir
}
);
# make sure, log dir is there
create_dir( make_absolute_path( $globConf{'log_dir'}, $baseDir ) );
# make the logfile absolute
$globConf{'logfile'} = make_absolute_path( $globConf{'logfile'}, $baseDir );
# set kernel version
my $kver = qx(BT_BUILDROOT=$baseDir GNU_TARGET_NAME=$globConf{'toolchain'} make -s -f $baseDir/make/MasterInclude.mk kversion);
my $kbranch = qx(BT_BUILDROOT=$baseDir GNU_TARGET_NAME=$globConf{'toolchain'} make -s -f $baseDir/make/MasterInclude.mk kbranch);
chomp $kver;
chomp $kbranch;
die "Can't determine kernel version!"
unless $kver =~ /^\d+\.\d+/ && $kbranch =~ /^\d+\.\d+/;
$globConf{'kernel_branch'} = $kbranch;
$globConf{'kernel_version'} = $kver;
# read in global file-config
my %sourcesConfig;
eval {
%sourcesConfig = load_global_configfile( $globConf{globalconffile} );
}
or do {
my $path = $@;
die $@,$/ if $path =~ /\*/; # Don't try to create a file with a wildcard in is name
$path =~ s,^.*\"([^\"]*)\".*not exist.*ConfigPath: ([^!]*)!.*\n,$2/$1,;
print STDERR "Created missing file \"$path\"...\n";
open TFILE, ">", $path or die "Can't create file \"$path\"!";
close TFILE;
%sourcesConfig = load_global_configfile( $globConf{globalconffile} );
};
# now it seems we are really starting, lets put a message in
# the logfile , logdir should be created by check_env
logme( \%globConf, "==================================================" );
logme( \%globConf, "buildtool Version " . $::VERSION . " starting" );
logme( \%globConf, scalar localtime );
# Set and check the environment
check_env( \%globConf );
#???
# put in the default config stuff
my $configClass = buildtool::Config->new(\%globConf, \%sourcesConfig);
$configClass->adjustFileConfig();
# now search for real commands:
if ($ARGV[0] eq "describe") {
# show descriptions
shift;
$configClass->showDescription(@ARGV);
} elsif ($ARGV[0] eq "list") {
# show descriptions
shift;
my $list = buildtool::Common::InstalledFile->new(\%globConf);
my $what = exists $ARGV[0] ? $ARGV[0] : 'all';
if ($what eq 'all') {
$list->showList();
} elsif ($what eq 'sourced') {
$list->showSourcedList();
} elsif ($what eq 'built') {
$list->showBuiltList();
} else {
print STDERR "\nunknown parameter '" . $ARGV[0] . "' for the list command!\n\n";
usage();
}
} elsif ($ARGV[0] eq "source") {
# source packages/sources
shift;
my $make = buildtool::Make::Source->new(\%globConf, \%sourcesConfig);
$make->make(@ARGV);
} elsif ($ARGV[0] eq "pkglist") {
# just print packagelist (useful fpr other tools)
shift;
my $make = buildtool::Make::PackageList->new(\%globConf, \%sourcesConfig);
$make->make(@ARGV);
} elsif ($ARGV[0] eq "build") {
# build packages/sources
shift;
# first do a make source:
#check_lib_link();
my $source = buildtool::Make::Source->new(\%globConf, \%sourcesConfig);
$source->make(@ARGV);
# now do a make build...
my $make= buildtool::Make::Build->new(\%globConf, \%sourcesConfig);
$make->make(@ARGV);
} elsif ($ARGV[0] eq "headers") {
# make platform headers from packages/sources
shift;
my $make= buildtool::Make::Headers->new(\%globConf, \%sourcesConfig);
$make->make(@ARGV);
} elsif ($ARGV[0] eq "buildclean") {
# buildclean package/source
shift;
my $clean = buildtool::Clean::Buildclean->new(\%globConf, \%sourcesConfig);
$clean->clean(@ARGV);
} elsif ($ARGV[0] eq "srcclean") {
# srcclean package/source
shift;
my $clean = buildtool::Clean::Srcclean->new(\%globConf, \%sourcesConfig);
$clean->clean(@ARGV);
} elsif ($ARGV[0] eq "remove") {
# remove package/source
shift;
my $clean = buildtool::Clean::Remove->new(\%globConf, \%sourcesConfig);
$clean->clean(@ARGV);
} elsif ($ARGV[0] eq "maketar") {
# make a tar file
my $make = buildtool::Make::Tar->new(\%globConf);
$make->make();
} elsif ($ARGV[0] eq "distclean") {
# make it distclean
print "\nAre you sure you want to delete everything you've downloaded and built? (y/N) ";
my $ask = <STDIN>;
chop $ask;
if ($ask eq "y" or $ask eq "Y" or $ask eq "j" or $ask eq "J") {
print "making distclean:\n" ;
my $clean = buildtool::Clean::Distclean->new(\%globConf);
$clean->clean();
}
} elsif ($ARGV[0] eq "dumpenv") {
shift;
my $env = buildtool::Make::Source->new(\%globConf, \%sourcesConfig);
$env->dump_env( package => $ARGV[0], xoutput => '/tmp/toto' );
} else {
# unknown command
print "\nunknown command " . $ARGV[0] . "!\n\n";
usage();
}