* copyright.sh: New file.
[binutils-gdb.git] / gdb / copyright.sh
1 #!/bin/sh
2 # Automatically update copyright for GDB, the GNU debugger.
3 #
4 # Copyright (C) 2007 Free Software Foundation, Inc.
5 #
6 # This file is part of GDB.
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 2 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, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
22
23 # Usage: cd src/gdb && sh ./copyright.sh
24 # To use a different version of emacs, set the EMACS environment
25 # variable before running.
26
27 # After running, update those files mentioned in $byhand by hand.
28 # Always review the output of this script before committing it!
29 # A useful command to review the output is:
30 # filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
31 # This removes the bulk of the changes which are most likely
32 # to be correct.
33
34 ####
35 # Configuration
36 ####
37
38 # As of Emacs 22.0 (snapshot), wrapping and copyright updating do not
39 # handle these file types - all reasonable:
40 # Assembly (weird comment characters, e.g. "!"); .S usually has C
41 # comments, which are fine)
42 # Fortran ("c" comment character)
43 # igen
44 # Autoconf input (dnl)
45 # texinfo (@c)
46 # tex (%)
47 # *.defs as C
48 # man
49 # So these need to be done by hand, as needed
50 byhand="
51 *.s
52 *.f
53 *.f90
54 *.igen
55 *.ac
56 *.texi
57 *.texinfo
58 *.tex
59 *.defs
60 *.1
61 "
62
63 # Files which should not be modified, either because they are
64 # generated, non-FSF, or otherwise special (e.g. license text).
65 prunes="
66 COPYING
67 COPYING.LIB
68 CVS
69 configure
70 copying.c
71 gdbarch.c
72 gdbarch.h
73 fdl.texi
74 gpl.texi
75 gdbtk
76 gdb.gdbtk
77 osf-share
78 aclocal.m4
79 "
80
81 ####
82 # Main program
83 ####
84
85 : ${EMACS:=emacs}
86
87 # Disable filename expansion, so that we can get at the glob patterns
88 # from $byhand.
89 set -f
90
91 version=`$EMACS --version | sed 's/GNU Emacs \([0-9]*\)\..*/\1/; 1q'`
92 if test "$version" -lt 22; then
93 echo "error: $EMACS is too old; use at least an Emacs 22 snapshot." >&2
94 exit 1
95 fi
96
97 if test $# -lt 1; then
98 dir=.
99 else
100 dir=$1
101 fi
102
103 if ! test -f doc/gdbint.texinfo; then
104 echo "\"$dir\" is not a GDB source directory."
105 exit 1
106 fi
107
108 cat > copytmp.el <<EOF
109 (load "copyright")
110 (setq vc-cvs-stay-local nil
111 message-log-max t)
112 (setq fsf-regexp "Free[#; \t\n]+Software[#; \t\n]+Foundation,[#; \t\n]+Inc\."
113 fsf-copyright-regexp (concat copyright-regexp "[#; \t\n]+" fsf-regexp)
114 generated-regexp "THIS FILE IS MACHINE GENERATED WITH CGEN")
115
116 (defun gdb-copyright-update (filename)
117 (widen)
118 (goto-char (point-min))
119 (if (and (not (re-search-forward generated-regexp (+ (point) copyright-limit) t))
120 (re-search-forward fsf-copyright-regexp (+ (point) copyright-limit) t))
121 (progn
122 (setq copyright-update t
123 copyright-query nil
124 fill-column 78
125 start (copy-marker (match-beginning 0))
126 end (progn
127 (re-search-backward fsf-regexp)
128 (re-search-forward fsf-regexp
129 (+ (point) copyright-limit) t)
130 (point-marker))
131 fsf-start (copy-marker (match-beginning 0)))
132 (replace-match "Free_Software_Foundation,_Inc." t t)
133 (copyright-update)
134 (fill-region-as-paragraph start end)
135 (replace-string "_" " " nil fsf-start end))
136 (message (concat "WARNING: No copyright message found in " filename))))
137
138 EOF
139
140 for f in $prunes $byhand; do
141 prune_opts="$prune_opts -name $f -prune -o"
142 done
143
144 for f in $(find "$dir" "$dir/../include/gdb" "$dir/../sim" \
145 $prune_opts -type f -print); do
146 cat >> copytmp.el <<EOF
147 (switch-to-buffer (find-file "$f"))
148 (setq backup-inhibited t)
149 (setq write-file-hooks '())
150 (gdb-copyright-update "$f")
151 (save-buffer)
152 (kill-buffer (buffer-name))
153 EOF
154 done
155
156 cat >> copytmp.el <<EOF
157 (delete-file "copytmp.el")
158 ;; Comment out the next line to examine the message buffer.
159 (kill-emacs)
160 EOF
161
162 exec $EMACS --no-site-file -q -l ./copytmp.el