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