xref: /netbsd-src/external/lgpl3/mpfr/dist/tools/ck-version-info (revision ba125506a622fe649968631a56eba5d42ff57863)
1#!/usr/bin/env perl
2
3# Note: this script must not be used to build MPFR due to the
4# dependency on perl, but this is OK for "make dist".
5
6# Copyright 2010-2023 Free Software Foundation, Inc.
7# This script is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it,
9# with or without modifications, as long as this notice is preserved.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
13# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14# PARTICULAR PURPOSE.
15
16use strict;
17use Cwd;
18
19if (! -d 'src')
20  {
21    getcwd() =~ m,/tools$,
22      or die "Execute $0 from the MPFR source directory\n";
23    chdir '..' or die "$!\n$0: can't change cwd\n";
24  }
25
26open VERSION, '<', 'VERSION'
27  or die "$!\n$0: can't open VERSION file\n";
28my $version = do { local $/; <VERSION> };
29close VERSION or die "$!\n$0: can't close VERSION file\n";
30
31my ($mv,$pl,$suf) = $version =~ /^(\d+\.\d+)\.(\d+)(-\S+)?/
32  or die "$0: bad VERSION format\n";
33
34open MF, '<', 'src/Makefile.am'
35  or die "$!\n$0: can't open Makefile.am file\n";
36my $cur = 0;
37my $age = -1;
38my $vinfo;  # expected -version-info value
39while (<MF>)
40  {
41    last if $cur && ! /^\s*(#.*)$/;
42    /^#\s+(\d+\.\d+)\.x\s+(\d+):x:(\d+)/ or next;
43    $2 == ++$cur or die "$0: bad CURRENT ($2)";
44    $3 == 0 || $3 == $age + 1 or die "$0: bad AGE ($3)";
45    $age = $3;
46    $mv eq $1 and $vinfo = "$cur:$pl:$age";
47  }
48/^libmpfr_la_LDFLAGS\s+=.*\s-version-info\s+(\d+:\d+:\d+)\s/
49  or die "$0: missing correct libmpfr_la_LDFLAGS line";
50close MF or die "$!\n$0: can't close Makefile.am file\n";
51
52if (defined $vinfo)
53  {
54    # Check that the -version-info value in the libmpfr_la_LDFLAGS line
55    # corresponds to the expected value from the comment ($vinfo).
56    $vinfo eq $1
57      or die "$0: bad -version-info value ($1 instead of $vinfo)\n";
58  }
59else
60  {
61    # If this is a release or a release candidate, make sure that $vinfo
62    # is defined. For intermediate versions, this value may not be known
63    # yet (for instance, the ABI may be broken some time later), so that
64    # defining $vinfo is not required.
65    $suf =~ /^(-rc.*)?$/
66      and die "$0: missing comment with -version-info value for MPFR $mv.x";
67  }
68
69open CONFIGURE, '<', 'configure.ac'
70  or die "$!\n$0: can't open configure.ac file\n";
71my $dllversion = $cur - $age;
72my $dllvinconf;
73while (<CONFIGURE>)
74  {
75    /^\s*LIBMPFR_LDFLAGS\s*=.*-Wl,--output-def,\.libs\/libmpfr-(\d+)\.dll\.def/
76      and $dllvinconf = $1, last;
77  }
78close CONFIGURE or die "$!\n$0: can't close configure.ac file\n";
79defined $dllvinconf or die "$0: missing correct LIBMPFR_LDFLAGS line\n";
80$suf eq '-dev' || $dllversion eq $dllvinconf
81  or die "$0: bad libmpfr.dll-version value (libmpfr-$dllvinconf.dll.def".
82  " instead of libmpfr-$dllversion.dll.def)\n";
83