xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/util/perl/OpenSSL/copyright.pm (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos#! /usr/bin/env perl
2*4724848cSchristos# Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3*4724848cSchristos#
4*4724848cSchristos# Licensed under the Apache License 2.0 (the "License").  You may not use
5*4724848cSchristos# this file except in compliance with the License.  You can obtain a copy
6*4724848cSchristos# in the file LICENSE in the source distribution or at
7*4724848cSchristos# https://www.openssl.org/source/license.html
8*4724848cSchristos
9*4724848cSchristosuse strict;
10*4724848cSchristosuse warnings;
11*4724848cSchristos
12*4724848cSchristospackage OpenSSL::copyright;
13*4724848cSchristos
14*4724848cSchristossub year_of {
15*4724848cSchristos    my $file = shift;
16*4724848cSchristos
17*4724848cSchristos    return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
18*4724848cSchristos
19*4724848cSchristos    # Use the file date for backward compatibility.
20*4724848cSchristos    my $YEAR = [localtime([stat($file)]->[9])]->[5] + 1900;
21*4724848cSchristos
22*4724848cSchristos    # See if git's available
23*4724848cSchristos    open my $FH,
24*4724848cSchristos       "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
25*4724848cSchristos           or return $YEAR;
26*4724848cSchristos    my $LINE = <$FH>;
27*4724848cSchristos    close $FH;
28*4724848cSchristos    $LINE =~ s/^([0-9]*)-.*/$1/ if $LINE;
29*4724848cSchristos    $YEAR = $LINE if $LINE;
30*4724848cSchristos    return $YEAR;
31*4724848cSchristos}
32*4724848cSchristos
33*4724848cSchristossub latest {
34*4724848cSchristos    my $l = 0;
35*4724848cSchristos    foreach my $f (@_ ) {
36*4724848cSchristos        my $y = year_of($f);
37*4724848cSchristos        $l = $y if $y > $l;
38*4724848cSchristos    }
39*4724848cSchristos    return $l
40*4724848cSchristos}
41*4724848cSchristos1;
42