]> git.proxmox.com Git - pve-kernel.git/blame - debian/scripts/abi-generate
buildsys: abi-generate: add usage output
[pve-kernel.git] / debian / scripts / abi-generate
CommitLineData
2132f071
FG
1#!/usr/bin/perl -w
2
3use PVE::Tools;
4
5use IO::File;
6
a4ed0977
TL
7sub usage {
8 die "USAGE: $0 INFILE OUTFILE ABI [INFILE-IS-DEB]\n";
9}
10
11my $input_file = shift // usage();
12my $output_file = shift // usage();
13my $abi = shift // usage();
2132f071
FG
14my $extract_deb = shift;
15
16die "input file '$input_file' does not exist\n" if ! -e $input_file;
17
18my $modules_symver_fh;
19
20if ($extract_deb) {
21 my $cmd = [];
22 push @$cmd, ['dpkg', '--fsys-tarfile', $input_file];
23 push @$cmd, ['tar', '-xOf', '-', "./usr/src/linux-headers-${abi}/Module.symvers"];
24 $modules_symver_fh = IO::File->new_tmpfile();
25 PVE::Tools::run_command($cmd, output => '>&'.fileno($modules_symver_fh));
26 seek($modules_symver_fh, 0, 0);
27} else {
28 open($modules_symver_fh, '<', $input_file) or die "can't open '$input_file' - $!\n";
29}
30
31my $lines = [];
32while(my $line = <$modules_symver_fh>) {
33 if ($line =~ /^(.+)\s+(.+)\s+(.+)$/) {
34 push @$lines, "$3 $2 $1";
35 } else {
36 warn "malformed symvers line: '$line'\n";
37 }
38}
39close($modules_symver_fh);
40
41PVE::Tools::file_set_contents($output_file, join("\n", sort @$lines));