File: build

package info (click to toggle)
isa-support 6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 108 kB
  • sloc: perl: 97; sh: 46; makefile: 8
file content (114 lines) | stat: -rwxr-xr-x 3,100 bytes parent folder | download
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
#!/usr/bin/perl -w
undef $/;

sub file_replace($)
{
    my $f=$_[0];
    open IN, "<debian/$f.in" or die "Can't read debian/$f.in: $!\n";
    local $_=<IN>;
    close IN;

    s/&NAME&/$name/g;
    s/&UUENCODED&/$uue/g;
    open OUT, ">debian/$name-support.$f"
        or die "Can't write debian/$name-support.$f: $!\n";
    print OUT;
    close OUT;
}


open IN, "<debian/control.in" or die "Can't read debian/control.in: $!\n";
$_=<IN>;
close IN;
my @control_in = grep !/^\s*$/s, split /\n\s*\n/s;
die "There should be 2 entries in debian/control.in\n" unless $#control_in==1;
my $control="$control_in[0]\n";

open ISA_LIST, "<isa-list" or die "Can't read isa-list: $!\n";
$_=<ISA_LIST>;
close ISA_LIST;

for (split /\n\s*\n/s)
{
    s/^#.*//gm;
    next if /^\s*$/s;
    my %field;
    $field{$1}=$2 while (/\G^([!-9;-~]+):[ \t]*((?:[^\n]|\n[ \t]+)+)\n?/gsm);

    $name=$field{'Name'};
    $name=~/^[a-z0-9\.+_]+$/ or die "Bad package/isa name: \"$name\".\n";

    $control.="\n".$control_in[1]=~s/&NAME&/$name/gr
            ."Architecture: $field{'Architecture'}\n";

    for (split /\s+/, $field{'Architecture'})
    {
        goto ARCH_OK unless system "dpkg-architecture", "-i", $_;
    }
    print "$name: not on arch list, skipping.\n";
    next;

ARCH_OK:
    print "Building $name...\n";
    push @isa, $name;
    open C, '>', "test-$name.c";
    my $test=$field{'Test'}//"return !__builtin_cpu_supports(\"$name\");";
    print C <<END;
int main()
{
    $test;
    return 0;
}
END
    close C;
    system($ENV{CC}//"cc", "-Wall", split(/ /, $field{'CFLAGS'}//""), "-s", "test-$name.c",
            "-o", "test-$name")
        and die "Compile failed, aborting.\n";
    $uue=`gzip -9n <test-$name|uuencode meow` or die "Uuencode failed.\n";
    $uue=~s/^begin \d\d\d meow\n//s or die "Uuencode output corrupted.\n";

    unlink "debian/substvars";
    system("dpkg-shlibdeps", "test-$name") and die "dpkg-shlibdeps failed.\n";
    open SVARS, "<", "debian/substvars" or die "Can't read debian/substvars: $!\n";
    $_=<SVARS>;
    close SVARS;
    unlink "debian/substvars";
    /^shlibs:Depends=([^\n]*)$/m or die "Can't find Depends in substvars.\n";
    $control.="Pre-Depends: $1\n";

    file_replace $_ for qw(preinst templates lintian-overrides docs);
}

open CONTROL, ">debian/control" or die "Can't write to debian/control: $!\n";
print CONTROL $control;
close CONTROL;

printf "Mangling translations...\n";
mkdir "debian/po.tmp";
opendir(my $POdir, "debian/po") || die "Can't opendir debian/po: $!\n";
while (readdir $POdir)
{
    /\.po$/ or next;
    print "• $_\n";
    my $POfile = $_;

    open PO, "<", "debian/po/$POfile" or die "Can't read debian/po/$POfile: $!\n";
    $_=<PO>;
    close PO;

    open PO, ">", "debian/po.tmp/$POfile" or die "Can't write debian/po.tmp/$POfile: $!\n";
    print PO;
    for (split /\n\n/)
    {
        next unless /&NAME&/;
        my $sect = $_;
        for (@isa)
        {
            my $mangled = $sect;
            $mangled =~ s/&NAME&/$_/g;
            print PO "\n\n$mangled";
        }
    }
    close PO;
}
closedir $POdir;