Home | History | Annotate | Line # | Download | only in OpenSSL
      1 #! /usr/bin/env perl
      2 # Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
      3 #
      4 # Licensed under the Apache License 2.0 (the "License").  You may not use
      5 # this file except in compliance with the License.  You can obtain a copy
      6 # in the file LICENSE in the source distribution or at
      7 # https://www.openssl.org/source/license.html
      8 
      9 use strict;
     10 use warnings;
     11 
     12 package OpenSSL::copyright;
     13 
     14 sub year_of {
     15     my $file = shift;
     16 
     17     return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
     18 
     19     # Use the file date for backward compatibility.
     20     my $YEAR = [localtime([stat($file)]->[9])]->[5] + 1900;
     21 
     22     # See if git's available
     23     open my $FH,
     24        "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
     25            or return $YEAR;
     26     my $LINE = <$FH>;
     27     close $FH;
     28     $LINE =~ s/^([0-9]*)-.*/$1/ if $LINE;
     29     $YEAR = $LINE if $LINE;
     30     return $YEAR;
     31 }
     32 
     33 sub latest {
     34     my $l = 0;
     35     foreach my $f (@_ ) {
     36         my $y = year_of($f);
     37         $l = $y if $y > $l;
     38     }
     39     return $l
     40 }
     41 1;
     42