4 unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
11 my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild);
14 if ($ARGV[0] eq '--dist') {
19 if ($ARGV[0] eq '--depfile') {
21 $rpmdeps = shift @ARGV;
24 if ($ARGV[0] eq '--archpath') {
29 if ($ARGV[0] eq '--configdir') {
31 $configdir = shift @ARGV;
34 if ($ARGV[0] eq '--useusedforbuild') {
39 if ($ARGV[0] eq '--define') {
41 my $def = shift @ARGV;
45 if ($ARGV[0] eq '--with') {
47 my $def = shift @ARGV;
48 Build::define("_with_$def --with-$def");
51 if ($ARGV[0] eq '--without') {
53 my $def = shift @ARGV;
54 Build::define("_without_$def --without-$def");
59 $configdir = '.' unless defined $configdir;
60 $archs = '' unless defined $archs;
61 die("you must specfiy a depfile!\n") unless defined $rpmdeps;
63 my @extradeps = grep {!/(^|\/)(?:PKGBUILD|_preinstallimage)$/ && !/\.(?:spec|dsc|kiwi)$/} @ARGV;
64 my @specs = grep {/(^|\/)(?:PKGBUILD|_preinstallimage)$/ || /\.(?:spec|dsc|kiwi)$/} @ARGV;
65 die("can only work with at most one spec\n") if @specs > 1;
68 my @archs = split(':', $archs);
69 if ($spec =~ /(^|\/)PKGBUILD$/) {
70 push @archs, 'any' unless grep {$_ eq 'any'} @archs;
72 push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
75 my (%fn, %prov, %req);
83 open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
84 # WARNING: the following code assumes that the 'I' tag comes last
85 my ($pkgF, $pkgP, $pkgR);
88 if (/^F:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
93 $pack =~ /^(.*)\.([^\.]+)$/ or die;
94 push @{$packs_arch{$2}}, $1;
95 } elsif (/^P:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
99 } elsif (/^R:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
103 } elsif (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
104 if ($ids{$1} && !$packs_done{$1} && defined($pkgF) && defined($pkgP) && defined($pkgR)) {
106 my $oldid = $ids{$1};
108 if (Build::Rpm::verscmp($oldid, $newid) < 0) {
121 } elsif ($_ eq 'D:') {
127 for my $arch (@archs) {
128 $packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
131 # XXX: move to separate tool
132 if (!defined($dist) || $dist eq '') {
133 my $rpmarch = (grep {$fn{"rpm.$_"}} @archs)[0];
137 my $rpmfn = $fn{"rpm.$rpmarch"};
138 if ($rpmfn =~ /^[a-z]+:\/\//) {
140 my $tmpdir = File::Temp::tempdir('CLEANUP' => 1);
141 $rpmfn =~ s/.*\//$tmpdir\// unless system("$INC[0]/download", $tmpdir, $rpmfn);
144 if ($rpmfn =~ /^\// && -e $rpmfn) {
145 my %res = Build::Rpm::rpmq($rpmfn, 1010);
146 $rpmdist = $res{1010}->[0] || '';
148 $dist = Build::dist_canon($rpmdist, $archs[0]);
149 # need some extra work for sles11 :(
150 if ($dist =~ /^sles11-/) {
151 my %res = Build::Rpm::rpmq($rpmfn, 1049);
152 $dist =~ s/^sles11-/sles11sp2-/ if grep {/^liblzma/} @{$res{1049} || []};
155 print STDERR "Warning: distribution not specified, assuming '$dist' (see $configdir).\n";
158 my $cf = Build::read_config_dist($dist, $archs[0], $configdir);
159 $cf->{'warnings'} = 1;
161 my $dofileprovides = %{$cf->{'fileprovides'}};
163 for my $pack (keys %packs) {
165 my (@s, $s, @pr, @re);
166 @s = split(' ', $prov{$packs{$pack}} || '');
169 next if !$dofileprovides && $s =~ /^\//;
170 if ($s =~ /^rpmlib\(/) {
175 splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
177 @s = split(' ', $req{$packs{$pack}} || '');
180 next if !$dofileprovides && $s =~ /^\//;
181 if ($s =~ /^rpmlib\(/) {
186 splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
188 $r->{'provides'} = \@pr;
189 $r->{'requires'} = \@re;
194 #######################################################################
199 print "$_ $fn{$packs{$_}}\n";
200 print "rpmid: $_:$ids{$packs{$_}}\n" if exists $ids{$packs{$_}};
202 print "preinstall: @{$cf->{'preinstall'} || []}\n";
203 print "vminstall: @{$cf->{'vminstall'} || []}\n";
204 print "cbpreinstall: @{$cf->{'cbpreinstall'} || []}\n"; # preinstall if is_emulator_arch
205 print "cbinstall: @{$cf->{'cbinstall'} || []}\n"; # install if is_emulator_arch
206 print "runscripts: @{$cf->{'runscripts'} || []}\n";
207 print "dist: $dist\n" if defined $dist;
210 if ($useusedforbuild) {
211 die("Need a specfile/dscfile for --usedforbuild\n") unless defined $spec;
213 open(F, '<', $spec) || die("$spec: $!\n");
218 if (/^#\s*usedforbuild\s*(.*)$/) {
219 push @usedforbuild, split(' ', $1);
221 if (/^buildrequires:\s*(.*)$/i) {
222 push @buildrequires, split(' ', $1);
226 @usedforbuild = @buildrequires unless @usedforbuild;
227 @usedforbuild = Build::unify(@usedforbuild) if @usedforbuild;
229 for (@usedforbuild) {
230 push @errors, "package $_ not found" unless $packs{$_} && $fn{$packs{$_}};
233 print STDERR "expansion error\n";
234 print STDERR " $_\n" for @errors;
237 print_rpmlist(@usedforbuild);
241 #######################################################################
243 my ($packname, $packvers, $subpacks, @packdeps);
248 if ($spec =~ /\.kiwi$/) {
249 # just set up kiwi root for now
251 'deps' => [ 'kiwi', 'zypper', 'createrepo', 'squashfs' ],
255 $d = Build::parse($cf, $spec);
257 $packname = $d->{'name'};
258 $packvers = $d->{'version'};
259 $subpacks = $d->{'subpacks'};
260 @packdeps = @{$d->{'deps'} || []};
261 if ($d->{'prereqs'}) {
262 my %deps = map {$_ => 1} (@packdeps, @{$d->{'subpacks'} || []});
263 push @packdeps, grep {!$deps{$_} && !/^%/} @{$d->{'prereqs'}};
267 Build::readdeps($cf, undef, \%repo);
269 #######################################################################
271 my @bdeps = Build::get_build($cf, $subpacks, @packdeps, @extradeps);
274 print STDERR "expansion error\n";
275 print STDERR " $_\n" for @bdeps;
279 print_rpmlist(@bdeps);