srclist-update 4.94 KB
Newer Older
1
#!/bin/sh
2 3
# Check for files in directory $1 being up to date, according to the
# list on stdin.  Don't actually make any changes, just show the diffs.
Karl Berry's avatar
Karl Berry committed
4
#
Karl Berry's avatar
Karl Berry committed
5 6 7 8 9 10 11 12 13 14
# Empty (or only whitespace) input lines are ignored.
# Lines beginning with # are ignored.
# Lines with just one word are ignored.
# Otherwise, the line has two or more whitespace-separated words:
#   the first word is the source, the second word is the destination,
#   other optional words are options.
# The possible options are "gpl" (to replace the license with the GPL)
#   and "doclicense" (to replace @include doclicense.texi with fdl.texi).
#   Unrecognized options are ignored.
# $VARIABLE expansions are done (with sh eval).
Karl Berry's avatar
Karl Berry committed
15
#
Karl Berry's avatar
Karl Berry committed
16 17
# This script is used in gnulib and texinfo; the input files are named
# srclist.txt.
Jim Meyering's avatar
Jim Meyering committed
18
#
Paul Eggert's avatar
Paul Eggert committed
19
# Copyright (C) 2002-2003, 2005, 2007-2016 Free Software Foundation, Inc.
20
#
21
# This program is free software: you can redistribute it and/or modify
22
# it under the terms of the GNU General Public License as published by
23 24
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
25 26 27 28 29 30 31
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
32
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
33

Karl Berry's avatar
Karl Berry committed
34
# Originally written by Karl Berry.
35 36


37 38 39 40 41 42 43
if test -n "$1"; then
  cd "$1" || exit 1
fi

verbose=false
#chicken="echo (would)"

44 45
: ${TMPDIR=/tmp}
dsttmp=$TMPDIR/srclist.dst
46

47
# Source `dirname $0`/srclistvars.sh first, if it exists.
48 49 50
mydir=`dirname $0`
test -r $mydir/srclistvars.sh && . $mydir/srclistvars.sh

51 52

# 
53 54
# sed command to fix the license to be GPL.
fixlicense='
55
  /^[[:space:]]*#[[:space:]]*Th[ei][ s].* is free software/,/^[[:space:]]*#.*USA\./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 59
#   the Free Software Foundation; either version 3 of the License, or\
#   (at your option) any later version.\
60
#\
61 62 63 64
#   This program is distributed in the hope that it will be useful,\
#   but WITHOUT ANY WARRANTY; without even the implied warranty of\
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
#   GNU General Public License for more details.\
65
#\
66 67
#   You should have received a copy of the GNU General Public License\
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
68

69
  /Th[ei][ s].* is free software/,/\*\//c\
70
   This program is free software: you can redistribute it and/or modify\
71
   it under the terms of the GNU General Public License as published by\
72 73
   the Free Software Foundation; either version 3 of the License, or\
   (at your option) any later version.\
74 75 76 77 78 79
\
   This program is distributed in the hope that it will be useful,\
   but WITHOUT ANY WARRANTY; without even the implied warranty of\
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\
   GNU General Public License for more details.\
\
80 81
   You should have received a copy of the GNU General Public License\
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
82
'
83 84

# sed command to remove lines containing $Id lines.
85
# Quote the $ so that CVS does not expand it in this script.
86 87
remove_id_lines='/[$]Id:.*[$]/d'

88 89 90
# $1 is input file, $2 is output.
# Remove $Id lines, since they'll differ between source locations.
# If $options contains "gpl", change the license to be the standard
91
# GPL.  We use this for libc files, et al.
Jim Meyering's avatar
Jim Meyering committed
92
#
93 94
fixfile() \
{
95 96
  sed_command="$remove_id_lines"

97 98
  case " $options " in
  *' gpl '*)
99
    sed_command="$sed_command; $fixlicense";;
Karl Berry's avatar
Karl Berry committed
100 101 102

  *' doclicense '*)
    sed_command="$sed_command; s/@include doclicense.texi/@include fdl.texi/";;
103 104 105
  esac

  sed "$sed_command" $1 >$2
106 107 108 109 110
}


# 
cat | while read src dst options; do
111
  #echo "src=$src, dst=$dst, options=$options" >&2
112
  case $src:$dst in
113
    *: ) continue;;    # skip lines without second element
114 115
    '#'* ) continue;;  # skip comment-only lines
  esac
Jim Meyering's avatar
Jim Meyering committed
116

117
  # Expand variables and make sure we have an input file.
118
  eval src=$src
119 120 121 122
  if test ! -r $src; then
    echo "$0: cannot read $src" >&2
    continue
  fi
Jim Meyering's avatar
Jim Meyering committed
123

124 125
  # Ignore subdirs in src dir.  E.g., if input spec is
  #   src/subdir/foo.c dst
126
  # then write destination file dst/foo.c.
127
  eval dst=$dst
128
  test -d $dst && dst=$dst/`basename $src`
Jim Meyering's avatar
Jim Meyering committed
129

130
  # Fix files in both src and dst, for the sake
131 132
  # of a clean comparison.
  srctmp=$TMPDIR/`basename $src`
133 134
  fixfile $src $srctmp
  test -r $dst && fixfile $dst $dsttmp
Jim Meyering's avatar
Jim Meyering committed
135

Karl Berry's avatar
Karl Berry committed
136 137
  # if src was executable, make dst executable, to placate git.
  test -x $src && chmod a+x $dst
Jim Meyering's avatar
Jim Meyering committed
138

139
  if test ! -e $dst; then
140 141
    echo "## $srctmp $dst  # new"
    $chicken cp -p $srctmp $dst
142
  elif cmp -s $srctmp $dsttmp; then
143
    $verbose && echo "## $srctmp $dst  # unchanged"
144
  else
145 146
    echo "## $srctmp $dst  # changes"
    diff -C 2 $dst $srctmp
147 148 149
  fi
done

150
rm -f $dsttmp