xref: /netbsd-src/crypto/external/bsd/openssl/dist/util/perl/OpenSSL/copyright.pm (revision b0d1725196a7921d003d2c66a14f186abda4176b)
16f6db51eSchristos#! /usr/bin/env perl
2*b0d17251Schristos# Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
36f6db51eSchristos#
46f6db51eSchristos# Licensed under the Apache License 2.0 (the "License").  You may not use
56f6db51eSchristos# this file except in compliance with the License.  You can obtain a copy
66f6db51eSchristos# in the file LICENSE in the source distribution or at
76f6db51eSchristos# https://www.openssl.org/source/license.html
86f6db51eSchristos
96f6db51eSchristosuse strict;
106f6db51eSchristosuse warnings;
116f6db51eSchristos
126f6db51eSchristospackage OpenSSL::copyright;
136f6db51eSchristos
146f6db51eSchristossub year_of {
156f6db51eSchristos    my $file = shift;
166f6db51eSchristos
176f6db51eSchristos    return $ENV{'OSSL_COPYRIGHT_YEAR'} if defined $ENV{'OSSL_COPYRIGHT_YEAR'};
186f6db51eSchristos
19*b0d17251Schristos    # Get the current year.  We use that as the default because the other
20*b0d17251Schristos    # common case is that someone unpacked a tarfile and the file dates
21*b0d17251Schristos    # are't properly set on extract.
22*b0d17251Schristos    my $YEAR = [localtime()]->[5] + 1900;
236f6db51eSchristos
246f6db51eSchristos    # See if git's available
256f6db51eSchristos    open my $FH,
266f6db51eSchristos       "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
276f6db51eSchristos           or return $YEAR;
286f6db51eSchristos    my $LINE = <$FH>;
296f6db51eSchristos    close $FH;
30*b0d17251Schristos    $LINE =~ s/^([0-9]*)-.*/$1/;
316f6db51eSchristos    $YEAR = $LINE if $LINE;
326f6db51eSchristos    return $YEAR;
336f6db51eSchristos}
346f6db51eSchristos
356f6db51eSchristossub latest {
366f6db51eSchristos    my $l = 0;
376f6db51eSchristos    foreach my $f (@_ ) {
386f6db51eSchristos        my $y = year_of($f);
396f6db51eSchristos        $l = $y if $y > $l;
406f6db51eSchristos    }
416f6db51eSchristos    return $l
426f6db51eSchristos}
436f6db51eSchristos1;
44