1e1051a39Sopenharmony_ci#! /usr/bin/env perl
2e1051a39Sopenharmony_ci# Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci#
4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci# this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci
9e1051a39Sopenharmony_ciuse strict;
10e1051a39Sopenharmony_ciuse warnings;
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_cipackage OpenSSL::copyright;
13e1051a39Sopenharmony_ci
14e1051a39Sopenharmony_cisub year_of {
15e1051a39Sopenharmony_ci    my $file = shift;
16e1051a39Sopenharmony_ci
17e1051a39Sopenharmony_ci    return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
18e1051a39Sopenharmony_ci
19e1051a39Sopenharmony_ci    # Get the current year.  We use that as the default because the other
20e1051a39Sopenharmony_ci    # common case is that someone unpacked a tarfile and the file dates
21e1051a39Sopenharmony_ci    # are't properly set on extract.
22e1051a39Sopenharmony_ci    my $YEAR = [localtime()]->[5] + 1900;
23e1051a39Sopenharmony_ci
24e1051a39Sopenharmony_ci    # See if git's available
25e1051a39Sopenharmony_ci    open my $FH,
26e1051a39Sopenharmony_ci       "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
27e1051a39Sopenharmony_ci           or return $YEAR;
28e1051a39Sopenharmony_ci    my $LINE = <$FH>;
29e1051a39Sopenharmony_ci    close $FH;
30e1051a39Sopenharmony_ci    $LINE =~ s/^([0-9]*)-.*/$1/;
31e1051a39Sopenharmony_ci    $YEAR = $LINE if $LINE;
32e1051a39Sopenharmony_ci    return $YEAR;
33e1051a39Sopenharmony_ci}
34e1051a39Sopenharmony_ci
35e1051a39Sopenharmony_cisub latest {
36e1051a39Sopenharmony_ci    my $l = 0;
37e1051a39Sopenharmony_ci    foreach my $f (@_ ) {
38e1051a39Sopenharmony_ci        my $y = year_of($f);
39e1051a39Sopenharmony_ci        $l = $y if $y > $l;
40e1051a39Sopenharmony_ci    }
41e1051a39Sopenharmony_ci    return $l
42e1051a39Sopenharmony_ci}
43e1051a39Sopenharmony_ci1;
44