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