copyright.pm 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. use strict;
  9. use warnings;
  10. package OpenSSL::copyright;
  11. sub year_of {
  12. my $file = shift;
  13. return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
  14. # Use the file date for backward compatibility.
  15. my $YEAR = [localtime([stat($file)]->[9])]->[5] + 1900;
  16. # See if git's available
  17. open my $FH,
  18. "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
  19. or return $YEAR;
  20. my $LINE = <$FH>;
  21. close $FH;
  22. $LINE =~ s/^([0-9]*)-.*/$1/ if $LINE;
  23. $YEAR = $LINE if $LINE;
  24. return $YEAR;
  25. }
  26. sub latest {
  27. my $l = 0;
  28. foreach my $f (@_ ) {
  29. my $y = year_of($f);
  30. $l = $y if $y > $l;
  31. }
  32. return $l
  33. }
  34. 1;