xref: /memcached-1.4.29/version.pl (revision 2906fae0)
1*2906fae0Sdormando#!/usr/bin/perl
2*2906fae0Sdormando# If you think this is stupid/overkill, blame dormando
3*2906fae0Sdormando
4*2906fae0Sdormandouse warnings;
5*2906fae0Sdormandouse strict;
6*2906fae0Sdormando
7*2906fae0Sdormandomy $version = `git describe`;
8*2906fae0Sdormandochomp $version;
9*2906fae0Sdormando# Test the various versions.
10*2906fae0Sdormando#my $version = 'foob';
11*2906fae0Sdormando#my $version = '1.4.2-30-gf966dba';
12*2906fae0Sdormando#my $version = '1.4.3-rc1';
13*2906fae0Sdormando#my $version = '1.4.3';
14*2906fae0Sdormandounless ($version =~ m/^\d+\.\d+\.\d+/) {
15*2906fae0Sdormando    write_file('version.m4', "m4_define([VERSION_NUMBER], [UNKNOWN])\n");
16*2906fae0Sdormando    exit;
17*2906fae0Sdormando}
18*2906fae0Sdormando
19*2906fae0Sdormando$version =~ s/-/_/g;
20*2906fae0Sdormandowrite_file('version.m4', "m4_define([VERSION_NUMBER], [$version])\n");
21*2906fae0Sdormandomy ($VERSION, $FULLVERSION, $RELEASE);
22*2906fae0Sdormando
23*2906fae0Sdormandoif ($version =~ m/^(\d+\.\d+\.\d+)_rc(\d+)$/) {
24*2906fae0Sdormando    $VERSION = $1;
25*2906fae0Sdormando    $FULLVERSION = $version;
26*2906fae0Sdormando    $RELEASE = '0.1.rc' . $2;
27*2906fae0Sdormando} elsif ($version =~ m/^(\d+\.\d+\.\d+)_(.+)$/) {
28*2906fae0Sdormando    $VERSION = $1;
29*2906fae0Sdormando    $FULLVERSION = $version;
30*2906fae0Sdormando    $RELEASE = '1.' . $2;
31*2906fae0Sdormando} elsif ($version =~ m/^(\d+\.\d+\.\d+)$/) {
32*2906fae0Sdormando    $VERSION = $1;
33*2906fae0Sdormando    $FULLVERSION = $version;
34*2906fae0Sdormando    $RELEASE = '1';
35*2906fae0Sdormando}
36*2906fae0Sdormando
37*2906fae0Sdormandomy $spec = read_file('memcached.spec.in');
38*2906fae0Sdormando$spec =~ s/\@VERSION\@/$VERSION/gm;
39*2906fae0Sdormando$spec =~ s/\@FULLVERSION\@/$FULLVERSION/gm;
40*2906fae0Sdormando$spec =~ s/\@RELEASE\@/$RELEASE/gm;
41*2906fae0Sdormando
42*2906fae0Sdormandowrite_file('memcached.spec', $spec);
43*2906fae0Sdormando
44*2906fae0Sdormandosub write_file {
45*2906fae0Sdormando    my $file = shift;
46*2906fae0Sdormando    my $data = shift;
47*2906fae0Sdormando    open(my $fh, "> $file") or die "Can't open $file: $!";
48*2906fae0Sdormando    print $fh $data;
49*2906fae0Sdormando    close($fh);
50*2906fae0Sdormando}
51*2906fae0Sdormando
52*2906fae0Sdormandosub read_file {
53*2906fae0Sdormando    my $file = shift;
54*2906fae0Sdormando    local $/ = undef;
55*2906fae0Sdormando    open(my $fh, "< $file") or die "Can't open $file: $!";
56*2906fae0Sdormando    my $data = <$fh>;
57*2906fae0Sdormando    close($fh);
58*2906fae0Sdormando    return $data;
59*2906fae0Sdormando}
60