maint: update all copyright year number ranges
[gnulib.git] / config / srclist-update
1 #!/bin/sh
2 # Check for files in directory $1 being up to date, according to the
3 # list on stdin.  Don't actually make any changes, just show the diffs.
4 #
5 # Copyright (C) 2002-2003, 2005, 2007-2013 Free Software Foundation, Inc.
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # Originally written by Karl Berry.
21
22
23 if test -n "$1"; then
24   cd "$1" || exit 1
25 fi
26
27 verbose=false
28 #chicken="echo (would)"
29
30 : ${TMPDIR=/tmp}
31 dsttmp=$TMPDIR/srclist.dst
32
33 # Source `dirname $0`/srclistvars.sh first, if it exists.
34 mydir=`dirname $0`
35 test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh
36
37
38\f
39 # sed command to fix the license to be GPL.
40 fixlicense='
41   /^[[:space:]]*#[[:space:]]*Th[ei][ s].* is free software/,/^[[:space:]]*#.*USA\./c\
42 #   This program is free software: you can redistribute it and/or modify\
43 #   it under the terms of the GNU General Public License as published by\
44 #   the Free Software Foundation; either version 3 of the License, or\
45 #   (at your option) any later version.\
46 #\
47 #   This program is distributed in the hope that it will be useful,\
48 #   but WITHOUT ANY WARRANTY; without even the implied warranty of\
49 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
50 #   GNU General Public License for more details.\
51 #\
52 #   You should have received a copy of the GNU General Public License\
53 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
54
55   /Th[ei][ s].* is free software/,/\*\//c\
56    This program is free software: you can redistribute it and/or modify\
57    it under the terms of the GNU General Public License as published by\
58    the Free Software Foundation; either version 3 of the License, or\
59    (at your option) any later version.\
60 \
61    This program is distributed in the hope that it will be useful,\
62    but WITHOUT ANY WARRANTY; without even the implied warranty of\
63    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
64    GNU General Public License for more details.\
65 \
66    You should have received a copy of the GNU General Public License\
67    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
68 '
69
70 # sed command to remove lines containing $Id lines.
71 # Quote the $ so that CVS does not expand it in this script.
72 remove_id_lines='/[$]Id:.*[$]/d'
73
74 # $1 is input file, $2 is output.
75 # Remove $Id lines, since they'll differ between source locations.
76 # If $options contains "gpl", change the license to be the standard
77 # GPL.  We use this for libc files, et al.
78 #
79 fixfile() \
80 {
81   sed_command="$remove_id_lines"
82
83   case " $options " in
84   *' gpl '*)
85     sed_command="$sed_command; $fixlicense";;
86   esac
87
88   sed "$sed_command" $1 >$2
89 }
90
91
92\f
93 cat | while read src dst options; do
94   #echo "src=$src, dst=$dst, options=$options" >&2
95   case $src:$dst in
96     *: ) continue;;    # skip lines without second element
97     '#'* ) continue;;  # skip comment-only lines
98   esac
99
100   # Expand variables and make sure we have an input file.
101   eval src=$src
102   if test ! -r $src; then
103     echo "$0: cannot read $src" >&2
104     continue
105   fi
106
107   # Ignore subdirs in src dir.  E.g., if input spec is
108   #   src/subdir/foo.c dst
109   # then write destination file dst/foo.c.
110   eval dst=$dst
111   test -d $dst && dst=$dst/`basename $src`
112
113   # Fix files in both src and dst, for the sake
114   # of a clean comparison.
115   srctmp=$TMPDIR/`basename $src`
116   fixfile $src $srctmp
117   test -r $dst && fixfile $dst $dsttmp
118
119   # if src was executable, make dst executable, to placate git.
120   test -x $src && chmod a+x $dst
121
122   if test ! -e $dst; then
123     echo "## $srctmp $dst  # new"
124     $chicken cp -p $srctmp $dst
125   elif cmp -s $srctmp $dsttmp; then
126     $verbose && echo "## $srctmp $dst  # unchanged"
127   else
128     echo "## $srctmp $dst  # changes"
129     diff -C 2 $dst $srctmp
130   fi
131 done
132
133 rm -f $dsttmp