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