summaryrefslogtreecommitdiffstats
path: root/debian/ada/libgnat_alihash
blob: 26b223ee1cb83e8b8a2e467d8217abeba8272c99 (plain)
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
#!/usr/bin/perl

# Helper for debian/rules2.

# Exit silently during builds without Ada.

# If .ali (Ada Library Information) files are found in gnat RTS directory,
# output a dpkg-gencontrol command line argument setting the
# libgnat:Provides substitution variable
# to the XOR of the checksums in all such files,
# as 8 lowercase hexadecimal digits.

# See https://people.debian.org/~lbrenta/debian-ada-policy.html.

# Should be in sync with dh_ada_library in the dh-ada-library package.

# perl -c $script
# perltidy $script -st | diff -u $script -
# perlcritic -1 --verbose=11 --exclude=Modules::RequireVersionVar $script

use autodie;
use re '/amsx';
use strict;
use warnings;

my @ali_files = glob 'build/gcc/ada/rts/*.ali';
if (@ali_files) {
    my $result = 0;
    for my $path (@ali_files) {
        open my $fh, q{<}, $path;
        while (<$fh>) {
            if (m/ ^ D [ ] [^\t]+ \t+ \d{14} [ ] ( [[:xdigit:]]{8} ) /) {
                $result ^= hex $1;
            }
        }
        close $fh;
    }
    printf '-Vlibgnat:alihash=%08x', $result;
}