copyright.pm 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #! /usr/bin/env perl
  2. # Copyright 2021-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. # Get the current year. We use that as the default because the other
  15. # common case is that someone unpacked a tarfile and the file dates
  16. # are't properly set on extract.
  17. my $YEAR = [localtime()]->[5] + 1900;
  18. # See if git's available
  19. open my $FH,
  20. "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
  21. or return $YEAR;
  22. my $LINE = <$FH>;
  23. close $FH;
  24. $LINE =~ s/^([0-9]*)-.*/$1/;
  25. $YEAR = $LINE if $LINE;
  26. return $YEAR;
  27. }
  28. sub latest {
  29. my $l = 0;
  30. foreach my $f (@_ ) {
  31. my $y = year_of($f);
  32. $l = $y if $y > $l;
  33. }
  34. return $l
  35. }
  36. 1;