]> code.delx.au - gnu-emacs/blob - admin/admin.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / admin / admin.el
1 ;;; admin.el --- utilities for Emacs administration
2
3 ;; Copyright (C) 2001-2011 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs 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.
11
12 ;; GNU Emacs 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.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; add-release-logs Add ``Version X released'' change log entries.
23 ;; set-version Change Emacs version number in source tree.
24 ;; set-copyright Change emacs short copyright string (eg as
25 ;; printed by --version) in source tree.
26
27 ;;; Code:
28
29 (defun add-release-logs (root version)
30 "Add \"Version VERSION released.\" change log entries in ROOT.
31 Root must be the root of an Emacs source tree."
32 (interactive "DEmacs root directory: \nNVersion number: ")
33 (setq root (expand-file-name root))
34 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
35 (error "%s doesn't seem to be the root of an Emacs source tree" root))
36 (require 'add-log)
37 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
38 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
39 (funcall add-log-time-format)
40 (or add-log-full-name (user-full-name))
41 (or add-log-mailing-address user-mail-address)
42 version)))
43 (dolist (log logs)
44 (unless (string-match "/gnus/" log)
45 (find-file log)
46 (goto-char (point-min))
47 (insert entry)))))
48
49 (defun set-version-in-file (root file version rx)
50 (find-file (expand-file-name file root))
51 (goto-char (point-min))
52 (unless (re-search-forward rx nil t)
53 (error "Version not found in %s" file))
54 (replace-match (format "%s" version) nil nil nil 1))
55
56 (defun set-version (root version)
57 "Set Emacs version to VERSION in relevant files under ROOT.
58 Root must be the root of an Emacs source tree."
59 (interactive "DEmacs root directory: \nsVersion number: ")
60 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
61 (error "%s doesn't seem to be the root of an Emacs source tree" root))
62 (set-version-in-file root "src/emacs.c" version
63 (rx (and "emacs_version" (0+ (not (in ?\")))
64 ?\" (submatch (1+ (not (in ?\")))) ?\")))
65 (set-version-in-file root "README" version
66 (rx (and "version" (1+ space)
67 (submatch (1+ (in "0-9."))))))
68 (set-version-in-file root "configure.in" version
69 (rx (and "AC_INIT" (1+ (not (in ?,)))
70 ?, (0+ space)
71 (submatch (1+ (in "0-9."))))))
72 (set-version-in-file root "doc/emacs/emacsver.texi" version
73 (rx (and "EMACSVER" (1+ space)
74 (submatch (1+ (in "0-9."))))))
75 (set-version-in-file root "doc/man/emacs.1" version
76 (rx (and ".TH EMACS" (1+ not-newline)
77 "GNU Emacs" (1+ space)
78 (submatch (1+ (in "0-9."))))))
79 (set-version-in-file root "lib-src/makefile.w32-in" version
80 (rx (and "VERSION" (0+ space) "=" (0+ space)
81 (submatch (1+ (in "0-9."))))))
82 (set-version-in-file root "nt/makefile.w32-in" version
83 (rx (and "VERSION" (0+ space) "=" (0+ space)
84 (submatch (1+ (in "0-9."))))))
85 ;; nt/emacs.rc also contains the version number, but in an awkward
86 ;; format. It must contain four components, separated by commas, and
87 ;; in two places those commas are followed by space, in two other
88 ;; places they are not.
89 (let* ((version-components (append (split-string version "\\.")
90 '("0" "0")))
91 (comma-version
92 (concat (car version-components) ","
93 (cadr version-components) ","
94 (cadr (cdr version-components)) ","
95 (cadr (cdr (cdr version-components)))))
96 (comma-space-version
97 (concat (car version-components) ", "
98 (cadr version-components) ", "
99 (cadr (cdr version-components)) ", "
100 (cadr (cdr (cdr version-components))))))
101 (set-version-in-file root "nt/emacs.rc" comma-version
102 (rx (and "FILEVERSION" (1+ space)
103 (submatch (1+ (in "0-9,"))))))
104 (set-version-in-file root "nt/emacs.rc" comma-version
105 (rx (and "PRODUCTVERSION" (1+ space)
106 (submatch (1+ (in "0-9,"))))))
107 (set-version-in-file root "nt/emacs.rc" comma-space-version
108 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
109 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
110 (set-version-in-file root "nt/emacs.rc" comma-space-version
111 (rx (and "\"ProductVersion\"" (0+ space) ?,
112 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
113 "\\0\"")))
114 ;; Likewise for emacsclient.rc
115 (set-version-in-file root "nt/emacsclient.rc" comma-version
116 (rx (and "FILEVERSION" (1+ space)
117 (submatch (1+ (in "0-9,"))))))
118 (set-version-in-file root "nt/emacsclient.rc" comma-version
119 (rx (and "PRODUCTVERSION" (1+ space)
120 (submatch (1+ (in "0-9,"))))))
121 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
122 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
123 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
124 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
125 (rx (and "\"ProductVersion\"" (0+ space) ?,
126 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
127 "\\0\""))))
128 ;; nextstep.
129 (set-version-in-file
130 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
131 version (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
132 (submatch (1+ (in "0-9."))))))
133 (set-version-in-file
134 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
135 version (rx (and "CFBundleShortVersionString" (1+ not-newline) ?\n
136 (0+ not-newline) "<string>" (0+ space)
137 (submatch (1+ (in "0-9."))))))
138 (set-version-in-file
139 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
140 version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space)
141 ?\" (0+ space) "Version" (1+ space)
142 (submatch (1+ (in "0-9."))))))
143 (set-version-in-file
144 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
145 version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space)
146 ?\" (0+ space) "Emacs version" (1+ space)
147 (submatch (1+ (in "0-9."))))))
148 (set-version-in-file
149 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
150 version (rx (and "ApplicationRelease" (0+ space) ?= (0+ space)
151 ?\" (0+ space) (submatch (1+ (in "0-9."))))))
152 (set-version-in-file
153 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
154 version (rx (and "FullVersionID" (0+ space) ?= (0+ space)
155 ?\" (0+ space) "Emacs" (1+ space)
156 (submatch (1+ (in "0-9."))))))
157 (set-version-in-file
158 root "nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop"
159 version (rx (and "Version=" (submatch (1+ (in "0-9.")))))))
160
161 ;; Note this makes some assumptions about form of short copyright.
162 (defun set-copyright (root copyright)
163 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
164 Root must be the root of an Emacs source tree."
165 (interactive (list
166 (read-directory-name "Emacs root directory: " nil nil t)
167 (read-string
168 "Short copyright string: "
169 (format "Copyright (C) %s Free Software Foundation, Inc."
170 (format-time-string "%Y")))))
171 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
172 (error "%s doesn't seem to be the root of an Emacs source tree" root))
173 (set-version-in-file root "src/emacs.c" copyright
174 (rx (and "emacs_copyright" (0+ (not (in ?\")))
175 ?\" (submatch (1+ (not (in ?\")))) ?\")))
176 (set-version-in-file root "lib-src/ebrowse.c" copyright
177 (rx (and "emacs_copyright" (0+ (not (in ?\")))
178 ?\" (submatch (1+ (not (in ?\")))) ?\")))
179 (set-version-in-file root "lib-src/etags.c" copyright
180 (rx (and "emacs_copyright" (0+ (not (in ?\")))
181 ?\" (submatch (1+ (not (in ?\")))) ?\")))
182 (set-version-in-file root "lib-src/rcs2log" copyright
183 (rx (and "Copyright" (0+ space) ?= (0+ space)
184 ?\' (submatch (1+ nonl)))))
185 ;; This one is a nuisance, as it needs to be split over two lines.
186 (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
187 ;; nextstep.
188 (set-version-in-file
189 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
190 copyright (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
191 (1+ (in "0-9.")) (1+ space)
192 (submatch (1+ (not (in ?\<)))))))
193 (set-version-in-file
194 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
195 copyright (rx (and "NSHumanReadableCopyright" (0+ space) ?\= (0+ space)
196 ?\" (submatch (1+ (not (in ?\")))))))
197 (set-version-in-file
198 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
199 copyright (rx (and "Copyright" (0+ space) ?\= (0+ space)
200 ?\" (submatch (1+ (not (in ?\")))))))
201 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
202 (setq copyright (match-string 1 copyright))
203 (dolist (file (directory-files (expand-file-name "etc/refcards" root)
204 t "\\.tex\\'"))
205 (unless (string-match "gnus-refcard\\.tex" file)
206 (set-version-in-file
207 root file copyright
208 (concat (if (string-match "ru-refcard\\.tex" file)
209 "\\\\newcommand{\\\\cyear}\\[0\\]{"
210 "\\\\def\\\\year{")
211 "\\([0-9]\\{4\\}\\)}.+%.+copyright year"))))))
212
213 (provide 'admin)
214
215 ;;; admin.el ends here