summaryrefslogtreecommitdiff
path: root/gdb/copyright.sh
blob: 2d2568ea5eac08d82c7083fd0144cbe8e29d3f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
# Automatically update copyright for GDB, the GNU debugger.
#
# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
#
# This file is part of GDB.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# 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
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Usage: cd src/gdb && sh ./copyright.sh
# To use a different version of emacs, set the EMACS environment
# variable before running.

# After running, update those files mentioned in $byhand by hand.
# Always review the output of this script before committing it!
# A useful command to review the output is:
#  filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
# This removes the bulk of the changes which are most likely
# to be correct.

####
# Configuration
####

# As of Emacs 22.0 (snapshot), wrapping and copyright updating do not
# handle these file types - all reasonable:
#  Assembly (weird comment characters, e.g. "!"); .S usually has C
#            comments, which are fine)
#  Fortran ("c" comment character)
#  igen
#  Autoconf input (dnl)
#  texinfo (@c)
#  tex (%)
#  *.defs as C
#   man
# So these need to be done by hand, as needed
byhand="
*.s
*.f
*.f90
*.igen
*.ac
*.texi
*.texinfo
*.tex
*.defs
*.1
"

# Files which should not be modified, either because they are
# generated, non-FSF, or otherwise special (e.g. license text,
# or test cases which must be sensitive to line numbering).
prunes="
COPYING
COPYING.LIB
CVS
configure
copying.c
gdbarch.c
gdbarch.h
fdl.texi
gpl.texi
gdbtk
gdb.gdbtk
osf-share
aclocal.m4
step-line.inp
step-line.c
"

####
# Main program
####

: ${EMACS:=emacs}

# Disable filename expansion, so that we can get at the glob patterns
# from $byhand.
set -f

version=`$EMACS --version | sed 's/GNU Emacs \([0-9]*\)\..*/\1/; 1q'`
if test "$version" -lt 22; then
  echo "error: $EMACS is too old; use at least an Emacs 22.0.XX snapshot." >&2
  exit 1
fi

if test $# -lt 1; then
  dir=.
else
  dir=$1
fi

if ! test -f doc/gdbint.texinfo; then
  echo "\"$dir\" is not a GDB source directory."
  exit 1
fi

cat > copytmp.el <<EOF
(load "copyright")
(setq vc-cvs-stay-local nil
      message-log-max t)
(setq fsf-regexp "Free[#; \t\n]+Software[#; \t\n]+Foundation,[#; \t\n]+Inc\."
      fsf-copyright-regexp (concat copyright-regexp "[#; \t\n]+" fsf-regexp)
      generated-regexp "THIS FILE IS MACHINE GENERATED WITH CGEN")

(defun gdb-copyright-update (filename)
  (widen)
  (goto-char (point-min))
  (if (and (not (re-search-forward generated-regexp (+ (point) copyright-limit) t))
	   (re-search-forward fsf-copyright-regexp (+ (point) copyright-limit) t))
      (progn
	(setq copyright-update t
	      copyright-query nil
	      fill-column 78
	      start (copy-marker (match-beginning 0))
	      end (progn
		    (re-search-backward fsf-regexp)
		    (re-search-forward fsf-regexp
		     (+ (point) copyright-limit) t)
		    (point-marker))
	      fsf-start (copy-marker (match-beginning 0)))
	(replace-match "Free_Software_Foundation,_Inc." t t)
	(copyright-update)
	(fill-region-as-paragraph start end)
	(replace-string "_" " " nil fsf-start end))
    (message (concat "WARNING: No copyright message found in " filename))))

EOF

for f in $prunes $byhand; do
  prune_opts="$prune_opts -name $f -prune -o"
done

for f in $(find "$dir" "$dir/../include/gdb" "$dir/../sim" \
           $prune_opts -type f -print); do
  cat >> copytmp.el <<EOF
(switch-to-buffer (find-file "$f"))
(setq backup-inhibited t)
(setq write-file-hooks '())
(gdb-copyright-update "$f")
(save-buffer)
(kill-buffer (buffer-name))
EOF
done

cat >> copytmp.el <<EOF
(delete-file "copytmp.el")
;; Comment out the next line to examine the message buffer.
(kill-emacs)
EOF

exec $EMACS --no-site-file -q -l ./copytmp.el