X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=build-aux%2Fupdate-copyright;h=ef0b1ce668372283a740abfaf0cbe9ae729f43f4;hb=49c136f53f6b22e91f2bb4c636e81e5930613d04;hp=bbd2a04ad2517a43b0294e27b65f4ee0deb7ee93;hpb=db430480e121625e8a1e5fac54157887aa08fe80;p=gnulib.git diff --git a/build-aux/update-copyright b/build-aux/update-copyright index bbd2a04ad..ef0b1ce66 100755 --- a/build-aux/update-copyright +++ b/build-aux/update-copyright @@ -1,11 +1,13 @@ -#!/usr/bin/perl -0777 -pi +eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" ${1+"$@"}' + & eval 'exec perl -wS -0777 -pi "$0" $argv:q' + if 0; # Update an FSF copyright year list to include the current year. -my $VERSION = '2009-08-06.01:08'; # UTC +my $VERSION = '2011-01-02.20:59'; # UTC -# Copyright (C) 2009 Free Software Foundation, Inc. +# Copyright (C) 2009-2011 Free Software Foundation, Inc. # -# This program is free software; you can redistribute it and/or modify +# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. @@ -20,28 +22,28 @@ my $VERSION = '2009-08-06.01:08'; # UTC # Written by Jim Meyering and Joel E. Denny -# The arguments to this script should be names of files that contain FSF -# copyright statements to be updated. For example, you may wish to -# place a target like the following in the top-level makefile in your -# project: +# The arguments to this script should be names of files that contain +# copyright statements to be updated. The copyright holder's name +# defaults to "Free Softward Foundation, Inc." but may be changed to +# any other name by using the "UPDATE_COPYRIGHT_HOLDER" environment +# variable. # -# .PHONY: update-copyright -# update-copyright: -# if test -d .git; then \ -# git grep -l -w Copyright \ -# | grep -v -E '(^|/)(COPYING|ChangeLog)' \ -# | xargs $(srcdir)/build-aux/$@; \ -# fi +# For example, you might wish to use the update-copyright target rule +# in maint.mk from gnulib's maintainer-makefile module. # -# In the second grep, you can build a list of files to skip within your -# project. +# Iff a copyright statement is recognized in a file and the final +# year is not the current year, then the statement is updated for the +# new year and it is reformatted to: # -# Iff an FSF copyright statement is discovered in a file and the final -# year is not the current year, the statement is updated for the new -# year and reformatted to fit within 72 columns. A warning is printed -# for every file for which no FSF copyright statement is discovered. +# 1. Fit within 72 columns. +# 2. Convert 2-digit years to 4-digit years by prepending "19". +# 3. Expand copyright year intervals. (See "Environment variables" +# below.) # -# Each file's FSF copyright statement must be formated correctly in +# A warning is printed for every file for which no copyright +# statement is recognized. +# +# Each file's copyright statement must be formated correctly in # order to be recognized. For example, each of these is fine: # # Copyright @copyright{} 1990-2005, 2007-2009 Free Software @@ -61,23 +63,17 @@ my $VERSION = '2009-08-06.01:08'; # UTC # ## Copyright (C) 1990-2005, 2007-2009 Free Software # # Foundation, Inc. # -# The following copyright statement is not recognized because the -# copyright holder is not the FSF: -# -# Copyright (C) 1990-2005, 2007-2009 Acme, Inc. -# -# However, any correctly formatted FSF copyright statement following -# either of the previous two copyright statements would be recognized. +# However, any correctly formatted copyright statement following +# a non-matching copyright statements would be recognized. # -# The exact conditions that a file's FSF copyright statement must meet +# The exact conditions that a file's copyright statement must meet # to be recognized are: # -# 1. It is the first FSF copyright statement that meets all of the -# following conditions. Subsequent FSF copyright statements are +# 1. It is the first copyright statement that meets all of the +# following conditions. Subsequent copyright statements are # ignored. # 2. Its format is "Copyright (C)", then a list of copyright years, -# and then the name of the copyright holder, which is "Free -# Software Foundation, Inc.". +# and then the name of the copyright holder. # 3. The "(C)" takes one of the following forms or is omitted # entirely: # @@ -86,9 +82,9 @@ my $VERSION = '2009-08-06.01:08'; # UTC # C. @copyright{} # D. © # -# 4. The "Copyright" appears at the beginning of a line except that it +# 4. The "Copyright" appears at the beginning of a line, except that it # may be prefixed by any sequence (e.g., a comment) of no more than -# 5 characters. +# 5 characters -- including white space. # 5. Iff such a prefix is present, the same prefix appears at the # beginning of each remaining line within the FSF copyright # statement. There is one exception in order to support C-style @@ -100,16 +96,39 @@ my $VERSION = '2009-08-06.01:08'; # UTC # 6. Blank lines, even if preceded by the prefix, do not appear # within the FSF copyright statement. # 7. Each copyright year is 2 or 4 digits, and years are separated by -# commas or dashes. Whitespace may occur after commas. +# commas or dashes. Whitespace may appear after commas. +# +# Environment variables: +# +# 1. If UPDATE_COPYRIGHT_FORCE=1, a recognized FSF copyright statement +# is reformatted even if it does not need updating for the new +# year. If unset or set to 0, only updated FSF copyright +# statements are reformatted. +# 2. If UPDATE_COPYRIGHT_USE_INTERVALS=1, every series of consecutive +# copyright years (such as 90, 1991, 1992-2007, 2008) in a +# reformatted FSF copyright statement is collapsed to a single +# interval (such as 1990-2008). If unset or set to 0, all existing +# copyright year intervals in a reformatted FSF copyright statement +# are expanded instead. +# 3. For testing purposes, you can set the assumed current year in +# UPDATE_COPYRIGHT_YEAR. +# 4. The default maximum line length for a copyright line is 72. +# Set UPDATE_COPYRIGHT_MAX_LINE_LENGTH to use a different length. +# 5. Set UPDATE_COPYRIGHT_HOLDER if the copyright holder is other +# than "Free Software Foundation, Inc.". use strict; use warnings; my $copyright_re = 'Copyright'; my $circle_c_re = '(?:\([cC]\)|@copyright{}|©)'; -my $holder = 'Free Software Foundation, Inc.'; +my $holder = $ENV{UPDATE_COPYRIGHT_HOLDER}; +$holder ||= 'Free Software Foundation, Inc.'; my $prefix_max = 5; -my $margin = 72; +my $margin = $ENV{UPDATE_COPYRIGHT_MAX_LINE_LENGTH}; +!$margin || $margin !~ m/^\d+$/ + and $margin = 72; + my $tab_width = 8; my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR}; @@ -147,7 +166,7 @@ while (/(^|\n)(.{0,$prefix_max})$copyright_re/g) $holder_re =~ s/\s/$ws_re/g; my $stmt_remainder_re = "(?:$ws_re$circle_c_re)?" - . "$ws_re(?:(?:\\d\\d)?\\d\\d(,$ws_re?|-))*" + . "$ws_re(?:(?:\\d\\d)?\\d\\d(?:,$ws_re?|-))*" . "((?:\\d\\d)?\\d\\d)$ws_re$holder_re"; if (/\G$stmt_remainder_re/) { @@ -160,8 +179,7 @@ if (defined $stmt_re) { /$stmt_re/ or die; # Should never die. my $stmt = $1; - my $sep = $2 ? $2 : ""; - my $final_year_orig = $3; + my $final_year_orig = $2; # Handle two-digit year numbers like "98" and "99". my $final_year = $final_year_orig; @@ -171,25 +189,40 @@ if (defined $stmt_re) if ($final_year != $this_year) { # Update the year. - if ($sep eq '-' && $final_year + 1 == $this_year) - { - $stmt =~ s/$final_year_orig/$this_year/; - } - elsif ($sep ne '-' && $final_year + 1 == $this_year) - { - $stmt =~ s/$final_year_orig/$final_year-$this_year/; - } - else - { - $stmt =~ s/$final_year_orig/$final_year, $this_year/; - } - + $stmt =~ s/$final_year_orig/$final_year, $this_year/; + } + if ($final_year != $this_year || $ENV{'UPDATE_COPYRIGHT_FORCE'}) + { # Normalize all whitespace including newline-prefix sequences. $stmt =~ s/$ws_re/ /g; # Put spaces after commas. $stmt =~ s/, ?/, /g; + # Convert 2-digit to 4-digit years. + $stmt =~ s/(\b\d\d\b)/19$1/g; + + # Make the use of intervals consistent. + if (!$ENV{UPDATE_COPYRIGHT_USE_INTERVALS}) + { + $stmt =~ s/(\d{4})-(\d{4})/join(', ', $1..$2)/eg; + } + else + { + $stmt =~ + s/ + (\d{4}) + (?: + (,\ |-) + ((??{ + if ($2 eq '-') { '\d{4}'; } + elsif (!$3) { $1 + 1; } + else { $3 + 1; } + })) + )+ + /$1-$3/gx; + } + # Format within margin. my $stmt_wrapped; my $text_margin = $margin - length($prefix); @@ -220,10 +253,11 @@ if (defined $stmt_re) } else { - print STDERR "$ARGV: warning: FSF copyright statement not found\n"; + print STDERR "$ARGV: warning: copyright statement not found\n"; } # Local variables: +# mode: perl # indent-tabs-mode: nil # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "my $VERSION = '"