1118611Snjl#! /usr/bin/env perl
2118611Snjl# Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
3118611Snjl#
4118611Snjl# Licensed under the Apache License 2.0 (the "License").  You may not use
5118611Snjl# this file except in compliance with the License.  You can obtain a copy
6118611Snjl# in the file LICENSE in the source distribution or at
7217365Sjkim# https://www.openssl.org/source/license.html
8245582Sjkim
9118611Snjluse strict;
10118611Snjluse warnings;
11217365Sjkim
12217365Sjkimpackage OpenSSL::copyright;
13217365Sjkim
14217365Sjkimsub year_of {
15217365Sjkim    my $file = shift;
16217365Sjkim
17217365Sjkim    return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
18217365Sjkim
19217365Sjkim    # Get the current year.  We use that as the default because the other
20217365Sjkim    # common case is that someone unpacked a tarfile and the file dates
21217365Sjkim    # are't properly set on extract.
22217365Sjkim    my $YEAR = [localtime()]->[5] + 1900;
23217365Sjkim
24217365Sjkim    # See if git's available
25118611Snjl    open my $FH,
26217365Sjkim       "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
27217365Sjkim           or return $YEAR;
28217365Sjkim    my $LINE = <$FH>;
29118611Snjl    close $FH;
30217365Sjkim    $LINE =~ s/^([0-9]*)-.*/$1/;
31217365Sjkim    $YEAR = $LINE if $LINE;
32217365Sjkim    return $YEAR;
33217365Sjkim}
34217365Sjkim
35217365Sjkimsub latest {
36217365Sjkim    my $l = 0;
37217365Sjkim    foreach my $f (@_ ) {
38217365Sjkim        my $y = year_of($f);
39217365Sjkim        $l = $y if $y > $l;
40217365Sjkim    }
41217365Sjkim    return $l
42217365Sjkim}
43118611Snjl1;
44118611Snjl