2011-10-05 07:01:45 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use File::Copy;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
my $dir = ".";
|
2016-09-28 10:07:34 +02:00
|
|
|
my $rpmrelease;
|
2011-10-05 07:01:45 +02:00
|
|
|
my $patches="";
|
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
"patches=s" => \$patches,
|
|
|
|
"release=s" => \$rpmrelease
|
|
|
|
) or die "Usage: $0 [--release <release>] [--patches <dir>]\n";
|
|
|
|
|
|
|
|
# flavor -> [supported archs]
|
|
|
|
my %flavor_archs = parse_config_conf();
|
|
|
|
# subset to include in kernel-syms
|
|
|
|
my %syms_flavor_archs = parse_config_conf("syms");
|
|
|
|
|
|
|
|
# template name -> template body
|
|
|
|
my %templates = read_spec_templates();
|
|
|
|
|
2016-06-26 16:47:43 +02:00
|
|
|
my @kmps = read_kmps();
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
# config.sh variables
|
|
|
|
my %vars = parse_config_sh();
|
2011-02-11 07:03:11 +01:00
|
|
|
my ($srcversion, $variant, $vanilla_only) =
|
|
|
|
($vars{'SRCVERSION'}, $vars{'VARIANT'}, $vars{'VANILLA_ONLY'});
|
|
|
|
$vanilla_only ||= "0";
|
2016-09-28 10:07:34 +02:00
|
|
|
if (!defined ($rpmrelease)) {
|
|
|
|
$rpmrelease = $vars{'RELEASE'} || 0;
|
|
|
|
}
|
2010-12-01 11:20:27 +01:00
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
# package name -> [summary, description]
|
|
|
|
my %binary_descriptions = parse_descriptions();
|
|
|
|
|
2013-10-03 08:02:42 +02:00
|
|
|
# arch -> flavor -> [obsoleted packages]
|
|
|
|
my %obsolete_packages = parse_old_flavors();
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
$patches="--patches $patches" if $patches;
|
|
|
|
my $patchversion = `$dir/compute-PATCHVERSION.sh $patches`;
|
|
|
|
chomp $patchversion;
|
2011-07-25 07:01:42 +02:00
|
|
|
my $rpmversion = $patchversion;
|
|
|
|
# stuff the -rcX tag into the rpm version if possible;
|
|
|
|
$rpmversion =~ s/\.0-rc/.rc/;
|
|
|
|
$rpmversion =~ s/-rc\d+//;
|
|
|
|
$rpmversion =~ s/-/./g;
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
$rpmrelease =~ s/-/./g;
|
|
|
|
|
2014-02-02 08:01:46 +01:00
|
|
|
my $sources = join("\n", $templates{source} =~ /^Source\d+:[^\n]*/msg);
|
2014-01-23 08:04:33 +01:00
|
|
|
# Find all SourceN: foo.tar.(bz2|xz) lines and generate the NoSource:
|
2011-10-05 07:01:45 +02:00
|
|
|
# lines and the %setup line
|
2014-02-02 08:01:46 +01:00
|
|
|
my @tarballs = ($sources =~ /^Source(\d+):[^\n]*\.tar\.(?:bz2|xz)/msg);
|
2014-02-15 08:03:13 +01:00
|
|
|
my $nosource = $sources;
|
2014-04-01 08:03:05 +02:00
|
|
|
$nosource =~ s/^Source(\d+):.*?$/NoSource: $1/mg;
|
2014-02-15 08:03:13 +01:00
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
# Source0 (the linux tarball) is unpacked manually
|
|
|
|
@tarballs = grep { $_ > 0 } @tarballs;
|
|
|
|
my $unpack_patches = join(" ", map { "-a $_" } @tarballs);
|
|
|
|
# List of scripts to automatically chmod +x before build
|
|
|
|
my $scripts = join(",", grep { is_script($_) }
|
|
|
|
($sources =~ /\nSource\d+:\s*([^\s]*)/mg));
|
|
|
|
|
2012-01-06 07:02:55 +01:00
|
|
|
my $tarball_url;
|
|
|
|
if ($srcversion =~ /^(\d+)(?:\.\d+)*(-rc\d+)?$/) {
|
|
|
|
$tarball_url = "http://www.kernel.org/pub/linux/kernel/v$1.x/";
|
|
|
|
$tarball_url .= "testing/" if $2;
|
|
|
|
} else {
|
|
|
|
# kernel.org has no tarballs for linux-next or vanilla snapshots
|
|
|
|
$tarball_url = "";
|
|
|
|
}
|
|
|
|
|
2013-10-03 08:02:42 +02:00
|
|
|
my $commit = get_commit();
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
my %macros = (
|
|
|
|
VARIANT => $variant,
|
2011-02-11 07:03:11 +01:00
|
|
|
VANILLA_ONLY => $vanilla_only,
|
2011-10-05 07:01:45 +02:00
|
|
|
SRCVERSION => $srcversion,
|
|
|
|
PATCHVERSION => $patchversion,
|
|
|
|
RPMVERSION => $rpmversion,
|
2012-01-06 07:02:55 +01:00
|
|
|
TARBALL_URL => $tarball_url,
|
2011-10-25 07:02:09 +02:00
|
|
|
RELEASE => $rpmrelease,
|
2013-10-03 08:02:42 +02:00
|
|
|
COMMIT => $commit,
|
2011-10-05 07:01:45 +02:00
|
|
|
SOURCES => $sources,
|
|
|
|
NOSOURCE => $nosource,
|
|
|
|
UNPACK_PATCHES => $unpack_patches,
|
|
|
|
SCRIPTS => $scripts,
|
2011-10-25 07:02:09 +02:00
|
|
|
YEAR => (localtime time)[5] + 1900,
|
2011-10-05 07:01:45 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# binary spec files
|
2016-06-26 16:47:43 +02:00
|
|
|
my $kmp_definitions = "";
|
|
|
|
for my $kmp (@kmps) {
|
|
|
|
my ($summary, $description);
|
|
|
|
if (!exists($binary_descriptions{$kmp})) {
|
|
|
|
print STDERR "warning: no description for $kmp found\n";
|
|
|
|
($summary = $kmp) =~ s/-kmp$//;
|
|
|
|
$summary .= " kernel modules";
|
|
|
|
$description = "$summary.";
|
|
|
|
} else {
|
|
|
|
$summary = $binary_descriptions{$kmp}->[0];
|
|
|
|
$description = $binary_descriptions{$kmp}->[1];
|
|
|
|
}
|
|
|
|
$kmp_definitions .= expand_template("kmp",
|
|
|
|
KMP_NAME => $kmp,
|
|
|
|
KMP_SUMMARY => $summary,
|
|
|
|
KMP_DESCRIPTION => $description);
|
|
|
|
}
|
2011-10-05 07:01:45 +02:00
|
|
|
for my $flavor (sort keys(%flavor_archs)) {
|
|
|
|
my ($summary, $description);
|
|
|
|
if (!exists($binary_descriptions{"kernel-$flavor"})) {
|
|
|
|
print STDERR "warning: no description for kernel-$flavor found\n";
|
|
|
|
$summary = "The Linux Kernel";
|
|
|
|
$description = "The Linux Kernel.";
|
|
|
|
} else {
|
|
|
|
$summary = $binary_descriptions{"kernel-$flavor"}->[0];
|
|
|
|
$description = $binary_descriptions{"kernel-$flavor"}->[1];
|
|
|
|
}
|
|
|
|
|
2015-04-17 08:05:31 +02:00
|
|
|
my %obsolete_macros;
|
|
|
|
for my $subpac ("", "-base", "-extra", "-devel", "-hmac") {
|
|
|
|
(my $macro = "PROVIDES_OBSOLETES" . uc($subpac)) =~ s/-/_/;
|
|
|
|
$obsolete_macros{$macro} =
|
|
|
|
provides_obsoletes($flavor, $subpac, @{$flavor_archs{$flavor}});
|
|
|
|
}
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
do_spec('binary', "kernel-$flavor.spec", %macros,
|
|
|
|
FLAVOR => $flavor,
|
|
|
|
SUMMARY => $summary,
|
|
|
|
DESCRIPTION => $description,
|
|
|
|
ARCHS => join(" ", arch2rpm(@{$flavor_archs{$flavor}})),
|
2016-03-15 08:05:00 +01:00
|
|
|
COMMON_DEPS => $templates{common_deps},
|
2016-06-26 16:47:43 +02:00
|
|
|
KMPS => join(" ", @kmps),
|
|
|
|
KMP_DEFINITIONS => $kmp_definitions,
|
2015-04-17 08:05:31 +02:00
|
|
|
%obsolete_macros
|
2011-10-05 07:01:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
# kernel-source.spec
|
|
|
|
do_spec('source', "kernel-source$variant.spec", %macros);
|
|
|
|
|
|
|
|
# kernel-docs.spec
|
|
|
|
do_spec('docs', "kernel-docs$variant.spec", %macros);
|
|
|
|
|
|
|
|
# kernel-syms.spec
|
|
|
|
{
|
|
|
|
my $requires = "";
|
|
|
|
my %all_archs;
|
2014-04-15 08:02:51 +02:00
|
|
|
my $all_archs;
|
2011-10-05 07:01:45 +02:00
|
|
|
for my $flavor (sort keys(%syms_flavor_archs)) {
|
|
|
|
next if $flavor eq "vanilla";
|
|
|
|
my @archs = arch2rpm(@{$syms_flavor_archs{$flavor}});
|
|
|
|
$all_archs{$_} = 1 for @archs;
|
|
|
|
$requires .= "%ifarch @archs\n";
|
|
|
|
$requires .= "Requires: kernel-$flavor-devel = \%version-\%source_rel\n";
|
|
|
|
$requires .= "%endif\n";
|
|
|
|
}
|
|
|
|
chomp $requires;
|
2014-04-15 08:02:51 +02:00
|
|
|
$all_archs = join(" ", sort(keys(%all_archs)));
|
2011-03-16 07:03:17 +01:00
|
|
|
if (keys(%all_archs)) {
|
|
|
|
do_spec('syms', "kernel-syms$variant.spec", %macros,
|
|
|
|
REQUIRES => $requires,
|
2014-04-15 08:02:51 +02:00
|
|
|
ARCHS => $all_archs);
|
|
|
|
}
|
2014-04-28 08:02:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# kernel-obs-*.spec
|
|
|
|
{
|
2015-04-22 08:05:37 +02:00
|
|
|
my @default_archs = arch2rpm(@{$flavor_archs{default}});
|
|
|
|
# No kernel-obs-* for 32bit ppc
|
|
|
|
@default_archs = grep { $_ ne "ppc" } @default_archs;
|
|
|
|
my $default_archs = join(" ", @default_archs);
|
2014-04-28 08:02:09 +02:00
|
|
|
my $xen_archs = join(" ", arch2rpm(@{$flavor_archs{xen} || []}));
|
2014-04-15 08:02:51 +02:00
|
|
|
if (!$variant) {
|
|
|
|
do_spec('obs-build', "kernel-obs-build.spec", %macros,
|
2014-04-28 08:02:09 +02:00
|
|
|
ARCHS => $default_archs);
|
2014-04-15 08:02:51 +02:00
|
|
|
do_spec('obs-qa', "kernel-obs-qa.spec", %macros,
|
2014-04-28 08:02:09 +02:00
|
|
|
ARCHS => $default_archs,
|
|
|
|
NAME => "kernel-obs-qa",
|
|
|
|
FLAVOR => "default");
|
|
|
|
}
|
|
|
|
if ($xen_archs) {
|
|
|
|
do_spec('obs-qa', "kernel-obs-qa-xen.spec", %macros,
|
|
|
|
ARCHS => $xen_archs,
|
|
|
|
NAME => "kernel-obs-qa-xen",
|
|
|
|
FLAVOR => "xen");
|
2011-03-16 07:03:17 +01:00
|
|
|
}
|
2014-03-08 08:01:14 +01:00
|
|
|
}
|
2014-04-15 08:02:51 +02:00
|
|
|
|
2014-01-23 08:04:33 +01:00
|
|
|
copy_changes();
|
2014-03-08 08:01:14 +01:00
|
|
|
|
2014-04-01 08:03:05 +02:00
|
|
|
# _constraints
|
|
|
|
{
|
|
|
|
my @packages = map { "<package>kernel-$_</package>" } sort keys(%flavor_archs);
|
|
|
|
my $packages = join("\n", @packages);
|
|
|
|
do_spec('constraints', "_constraints",
|
|
|
|
BINARY_PACKAGES_XML => $packages);
|
|
|
|
}
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
exit 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub parse_config_conf {
|
|
|
|
my @symbols = @_;
|
|
|
|
my $symbols = join(' ', @symbols);
|
|
|
|
my %res;
|
|
|
|
|
|
|
|
for my $arch (split(/\s+/, `$dir/arch-symbols --list`)) {
|
|
|
|
my @flavors = `$dir/guards $arch $symbols < $dir/config.conf`;
|
|
|
|
next if @flavors == 0;
|
|
|
|
chomp @flavors;
|
|
|
|
@flavors = map { s/.*\///; $_ } @flavors;
|
|
|
|
for my $flavor (@flavors) {
|
|
|
|
$res{$flavor} ||= [];
|
|
|
|
push(@{$res{$flavor}}, $arch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for my $flavor (keys(%res)) {
|
|
|
|
$res{$flavor} = [sort @{$res{$flavor}}];
|
|
|
|
}
|
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_spec_templates {
|
|
|
|
my %res;
|
|
|
|
|
2014-04-15 08:02:51 +02:00
|
|
|
for my $template (qw(binary source syms docs obs-build obs-qa)) {
|
2011-10-05 07:01:45 +02:00
|
|
|
xopen(my $fh, '<', "$dir/kernel-$template.spec.in");
|
|
|
|
local $/ = undef;
|
|
|
|
$res{$template} = <$fh>;
|
|
|
|
close($fh);
|
2016-03-15 08:05:00 +01:00
|
|
|
next unless $template eq "binary";
|
|
|
|
if ($res{$template} =~ /^# BEGIN COMMON DEPS\n?(.*)^# END COMMON DEPS/ms) {
|
|
|
|
$res{common_deps} = $1;
|
|
|
|
} else {
|
|
|
|
print STDERR "warning: Expected # BEGIN COMMON DEPS in kernel-binary.spec.in\n";
|
|
|
|
$res{common_deps} = "";
|
|
|
|
}
|
2016-06-26 16:47:43 +02:00
|
|
|
if ($res{$template} =~ s/^# BEGIN KMP\n?(.*)^# END KMP/\@KMP_DEFINITIONS\@/ms) {
|
|
|
|
$res{kmp} = $1;
|
|
|
|
} else {
|
|
|
|
print STDERR "warning: Expected # BEGIN KMP in kernel-binary.spec.in\n";
|
|
|
|
$res{kmp} = "";
|
|
|
|
}
|
2011-10-05 07:01:45 +02:00
|
|
|
}
|
2014-04-01 08:03:05 +02:00
|
|
|
{
|
|
|
|
xopen(my $fh, '<', "$dir/constraints.in");
|
|
|
|
local $/ = undef;
|
|
|
|
$res{constraints} = <$fh>;
|
|
|
|
close($fh);
|
|
|
|
}
|
2011-10-05 07:01:45 +02:00
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
|
|
|
# return a hash of config.sh variables
|
|
|
|
sub parse_config_sh {
|
|
|
|
my %res;
|
|
|
|
|
|
|
|
xopen(my $fh, '<', "$dir/config.sh");
|
|
|
|
while (<$fh>) {
|
|
|
|
chomp;
|
|
|
|
if (/^\s*([A-Z_]+)=(.*)/) {
|
2016-09-28 10:07:34 +02:00
|
|
|
my ($key, $val) = ($1, $2);
|
|
|
|
$val =~ s/^"(.*)"$/$1/;
|
|
|
|
$res{$key} = $val;
|
2011-10-05 07:01:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_descriptions {
|
|
|
|
my %res;
|
|
|
|
my $current;
|
|
|
|
my $blank = "";
|
|
|
|
# 0 - expect summary, 1 - eating blank lines, 2 - reading description
|
|
|
|
my $state = 0;
|
|
|
|
|
|
|
|
xopen(my $fh, '<', "$dir/package-descriptions");
|
|
|
|
while (<$fh>) {
|
|
|
|
next if /^\s*#/;
|
|
|
|
|
|
|
|
if (/^==+\s+([^\s]+)\s+==+\s*$/) {
|
|
|
|
my $package = $1;
|
|
|
|
if ($current) {
|
|
|
|
chomp $current->[1];
|
|
|
|
}
|
|
|
|
$current = ["", ""];
|
|
|
|
$res{$package} = $current;
|
|
|
|
$state = 0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (/^$/) {
|
|
|
|
if ($state == 2) {
|
|
|
|
$blank .= $_;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# non-blank line and not === package ===
|
|
|
|
if ($state == 0) {
|
|
|
|
chomp;
|
|
|
|
$current->[0] = $_;
|
|
|
|
$state = 1;
|
|
|
|
} elsif ($state == 1) {
|
|
|
|
$current->[1] = $_;
|
|
|
|
$blank = "";
|
|
|
|
$state = 2;
|
|
|
|
} else {
|
|
|
|
$current->[1] .= $blank;
|
|
|
|
$blank = "";
|
|
|
|
$current->[1] .= $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($current) {
|
|
|
|
chomp $current->[1];
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
2016-06-26 16:47:43 +02:00
|
|
|
sub read_kmps {
|
|
|
|
my %res;
|
|
|
|
|
|
|
|
open(my $fh, '-|', "$dir/guards", "--list", "--with-guards",
|
|
|
|
"-c", "$dir/supported.conf") or die "Error running guards: $!\n";
|
|
|
|
while (<$fh>) {
|
|
|
|
my @guards = split(' ');
|
|
|
|
pop(@guards);
|
|
|
|
for my $g (@guards) {
|
|
|
|
if ($g =~ /^\+(.*-kmp)$/) {
|
|
|
|
$res{$1} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close($fh) or die "Error running guards: $!\n";
|
|
|
|
return sort(keys(%res));
|
|
|
|
}
|
|
|
|
|
2013-10-03 08:02:42 +02:00
|
|
|
sub parse_old_flavors{
|
|
|
|
my %res;
|
|
|
|
|
|
|
|
|
|
|
|
xopen(my $fh, '<', "$dir/old-flavors");
|
|
|
|
while (<$fh>) {
|
|
|
|
chomp;
|
|
|
|
next if /^\s*(#|$)/;
|
|
|
|
if (!m:^\s*(\w+)/([\w-]+)\s+([\w-]+)\s+([\w.-]+)\s*$:) {
|
|
|
|
print STDERR "$dir/old-flavors:$.: expected arch/flavor <old flavor> <old version>\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
my ($arch, $flavor, $old_flavor, $old_version) = ($1, $2, $3, $4);
|
|
|
|
$res{$arch} ||= {};
|
|
|
|
$res{$arch}{$flavor} ||= [];
|
|
|
|
push(@{$res{$arch}{$flavor}},
|
|
|
|
["kernel-$old_flavor", $old_version]);
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
sub is_script {
|
|
|
|
my $script = shift;
|
|
|
|
|
|
|
|
return undef if $script =~ /\.(tar\.(gz|bz2)|in|conf)$/;
|
|
|
|
return undef if $script =~ /^README/;
|
|
|
|
return 1 if $script =~ /\.pl$/;
|
|
|
|
open(my $fh, '<', $script) or return undef;
|
|
|
|
sysread($fh, my $shebang, 2);
|
|
|
|
close($fh);
|
|
|
|
return 1 if $shebang eq "#!";
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub arch2rpm {
|
|
|
|
if (wantarray) {
|
|
|
|
return map { _arch2rpm($_) } @_;
|
|
|
|
}
|
|
|
|
return _arch2rpm($_[0]);
|
|
|
|
}
|
|
|
|
sub _arch2rpm {
|
|
|
|
my $arch = shift;
|
|
|
|
return "\%ix86" if $arch eq "i386";
|
2013-03-02 08:07:41 +01:00
|
|
|
return "aarch64" if $arch eq "arm64";
|
2011-10-05 07:01:45 +02:00
|
|
|
return $arch;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub provides_obsoletes {
|
|
|
|
my $flavor = shift;
|
2015-04-17 08:05:31 +02:00
|
|
|
my $subpac = shift;
|
2011-10-05 07:01:45 +02:00
|
|
|
my @archs = @_;
|
|
|
|
my $res = "";
|
|
|
|
|
|
|
|
for my $arch (@archs) {
|
2013-10-03 08:02:42 +02:00
|
|
|
my @packs = @{$obsolete_packages{$arch}{$flavor} || []};
|
2015-04-17 08:05:31 +02:00
|
|
|
my $printed;
|
|
|
|
|
2011-10-05 07:01:45 +02:00
|
|
|
next if (!@packs);
|
|
|
|
my $rpmarch = arch2rpm($arch);
|
|
|
|
chomp $rpmarch;
|
2013-10-03 08:02:42 +02:00
|
|
|
for my $pack (@packs) {
|
2015-04-17 08:05:31 +02:00
|
|
|
my $name = $pack->[0] . $subpac;
|
2013-10-03 08:02:42 +02:00
|
|
|
my $version = $pack->[1];
|
2015-04-17 08:05:31 +02:00
|
|
|
if ($subpac) {
|
|
|
|
# The -base and -extra split has been
|
|
|
|
# introduced in SLE11 (2.6.27)
|
|
|
|
my ($v1, $v2, $v3) = split(/\./, $version);
|
|
|
|
next if ($v1 <= 2 && $v2 <= 6 && $v3 < 27);
|
|
|
|
}
|
|
|
|
if (!$printed) {
|
|
|
|
$res .= "\%ifarch $rpmarch\n";
|
|
|
|
$printed = 1;
|
|
|
|
}
|
2013-10-03 08:02:42 +02:00
|
|
|
$res .= "Provides: $name = $version\n";
|
|
|
|
$res .= "Obsoletes: $name <= $version\n";
|
|
|
|
}
|
2015-04-17 08:05:31 +02:00
|
|
|
$res .= "\%endif\n" if $printed;
|
2011-10-05 07:01:45 +02:00
|
|
|
}
|
|
|
|
chomp $res;
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2013-10-03 08:02:42 +02:00
|
|
|
sub get_commit {
|
|
|
|
my ($commit, $fh);
|
|
|
|
|
|
|
|
if (!open($fh, '<', "source-timestamp")) {
|
|
|
|
print STDERR "warning: source-timestamp: $!\n";
|
|
|
|
print STDERR "warning: Cannot determine commit id\n";
|
|
|
|
return "0000000";
|
|
|
|
}
|
|
|
|
while (<$fh>) {
|
|
|
|
if (/^GIT Revision: ([0-9a-f]{7})/) {
|
|
|
|
$commit = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
if (!$commit) {
|
|
|
|
print STDERR "warning: Commit id missing in source-timestamp file\n";
|
|
|
|
return "0000000";
|
|
|
|
}
|
|
|
|
return $commit;
|
|
|
|
}
|
|
|
|
|
2016-06-26 16:47:43 +02:00
|
|
|
sub expand_template {
|
2011-10-05 07:01:45 +02:00
|
|
|
my $template = shift;
|
|
|
|
my %macros = @_;
|
|
|
|
|
|
|
|
my $text = $templates{$template};
|
2012-01-06 07:02:55 +01:00
|
|
|
my $prev_text;
|
|
|
|
do {
|
|
|
|
$prev_text = $text;
|
|
|
|
for my $m (keys %macros) {
|
|
|
|
$text =~ s/\@$m\@/$macros{$m}/g;
|
|
|
|
}
|
|
|
|
} while ($prev_text ne $text);
|
2016-06-26 16:47:43 +02:00
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub do_spec {
|
|
|
|
my $template = shift;
|
|
|
|
my $specfile = shift;
|
|
|
|
my %macros = @_;
|
|
|
|
|
|
|
|
my $text = expand_template($template, %macros);
|
2011-10-05 07:01:45 +02:00
|
|
|
print "$specfile\n";
|
|
|
|
xopen(my $fh, '>', "$dir/$specfile");
|
|
|
|
print $fh $text;
|
|
|
|
close($fh);
|
2014-01-23 08:04:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub copy_changes {
|
|
|
|
|
|
|
|
opendir(my $dh, $dir) or die "$dir: $!\n";
|
|
|
|
|
|
|
|
while (my $name = readdir $dh) {
|
|
|
|
next unless $name =~ /\.spec$/;
|
|
|
|
next if $name eq "kernel-source$variant.spec";
|
|
|
|
|
|
|
|
$name =~ s/\.spec$/.changes/;
|
|
|
|
copy("$dir/kernel-source$variant.changes", "$dir/$name");
|
|
|
|
}
|
|
|
|
closedir($dh);
|
2011-10-05 07:01:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub xopen {
|
|
|
|
open($_[0], $_[1], $_[2]) or die "$_[2]: $!\n";
|
|
|
|
}
|
|
|
|
|