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