valgrind: do leak checking, and exit with code 1 on error (not 0)
[gnulib/ericb.git] / config / srclist-update
blobb528d1a40e81d10ce2bd0c74edf9db37991696f8
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.
5 # Copyright (C) 2002-2003, 2005, 2007-2011 Free Software Foundation, Inc.
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.
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.
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/>.
20 # Originally written by Karl Berry.
23 if test -n "$1"; then
24 cd "$1" || exit 1
27 verbose=false
28 #chicken="echo (would)"
30 : ${TMPDIR=/tmp}
31 dsttmp=$TMPDIR/srclist.dst
33 # Source `dirname $0`/srclistvars.sh first, if it exists.
34 mydir=`dirname $0`
35 test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh
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.\
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.\
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/>.
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.\
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.\
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/>. */
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'
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.
79 fixfile() \
81 sed_command="$remove_id_lines"
83 case " $options " in
84 *' gpl '*)
85 sed_command="$sed_command; $fixlicense";;
86 esac
88 sed "$sed_command" $1 >$2
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
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
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`
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
119 # if src was executable, make dst executable, to placate git.
120 test -x $src && chmod a+x $dst
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
131 done
133 rm -f $dsttmp