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