Merge from emacs-23; up to 2010-06-03T22:16:02Z!dann@ics.uci.edu
[bpt/emacs.git] / 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 "README" version
63 (rx (and "version" (1+ space)
64 (submatch (1+ (in "0-9."))))))
65 (set-version-in-file root "configure.in" version
66 (rx (and "AC_INIT" (1+ (not (in ?,)))
67 ?, (0+ space)
68 (submatch (1+ (in "0-9."))))))
69 (set-version-in-file root "doc/emacs/emacsver.texi" version
70 (rx (and "EMACSVER" (1+ space)
71 (submatch (1+ (in "0-9."))))))
72 (set-version-in-file root "doc/man/emacs.1" version
73 (rx (and ".TH EMACS" (1+ not-newline)
74 "GNU Emacs" (1+ space)
75 (submatch (1+ (in "0-9."))))))
76 (set-version-in-file root "nt/config.nt" version
77 (rx (and bol "#" (0+ blank) "define" (1+ blank)
78 "VERSION" (1+ blank)
79 (submatch (1+ (in "0-9."))))))
80 (set-version-in-file root "msdos/sed2v2.inp" version
81 (rx (and bol "/^#undef " (1+ not-newline)
82 "define VERSION" (1+ space)
83 (submatch (1+ (in "0-9."))))))
84 (set-version-in-file root "nt/makefile.w32-in" version
85 (rx (and "VERSION" (0+ space) "=" (0+ space)
86 (submatch (1+ (in "0-9."))))))
87 ;; nt/emacs.rc also contains the version number, but in an awkward
88 ;; format. It must contain four components, separated by commas, and
89 ;; in two places those commas are followed by space, in two other
90 ;; places they are not.
91 (let* ((version-components (append (split-string version "\\.")
92 '("0" "0")))
93 (comma-version
94 (concat (car version-components) ","
95 (cadr version-components) ","
96 (cadr (cdr version-components)) ","
97 (cadr (cdr (cdr version-components)))))
98 (comma-space-version
99 (concat (car version-components) ", "
100 (cadr version-components) ", "
101 (cadr (cdr version-components)) ", "
102 (cadr (cdr (cdr version-components))))))
103 (set-version-in-file root "nt/emacs.rc" comma-version
104 (rx (and "FILEVERSION" (1+ space)
105 (submatch (1+ (in "0-9,"))))))
106 (set-version-in-file root "nt/emacs.rc" comma-version
107 (rx (and "PRODUCTVERSION" (1+ space)
108 (submatch (1+ (in "0-9,"))))))
109 (set-version-in-file root "nt/emacs.rc" comma-space-version
110 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
111 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
112 (set-version-in-file root "nt/emacs.rc" comma-space-version
113 (rx (and "\"ProductVersion\"" (0+ space) ?,
114 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
115 "\\0\"")))
116 ;; Likewise for emacsclient.rc
117 (set-version-in-file root "nt/emacsclient.rc" comma-version
118 (rx (and "FILEVERSION" (1+ space)
119 (submatch (1+ (in "0-9,"))))))
120 (set-version-in-file root "nt/emacsclient.rc" comma-version
121 (rx (and "PRODUCTVERSION" (1+ space)
122 (submatch (1+ (in "0-9,"))))))
123 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
124 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
125 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
126 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
127 (rx (and "\"ProductVersion\"" (0+ space) ?,
128 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
129 "\\0\""))))
130 ;; nextstep.
131 (set-version-in-file
132 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
133 version (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
134 (submatch (1+ (in "0-9."))))))
135 (set-version-in-file
136 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
137 version (rx (and "CFBundleShortVersionString" (1+ not-newline) ?\n
138 (0+ not-newline) "<string>" (0+ space)
139 (submatch (1+ (in "0-9."))))))
140 (set-version-in-file
141 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
142 version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space)
143 ?\" (0+ space) "Version" (1+ space)
144 (submatch (1+ (in "0-9."))))))
145 (set-version-in-file
146 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
147 version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space)
148 ?\" (0+ space) "Emacs version" (1+ space)
149 (submatch (1+ (in "0-9."))))))
150 (set-version-in-file
151 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
152 version (rx (and "ApplicationRelease" (0+ space) ?= (0+ space)
153 ?\" (0+ space) (submatch (1+ (in "0-9."))))))
154 (set-version-in-file
155 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
156 version (rx (and "FullVersionID" (0+ space) ?= (0+ space)
157 ?\" (0+ space) "Emacs" (1+ space)
158 (submatch (1+ (in "0-9."))))))
159 (set-version-in-file
160 root "nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop"
161 version (rx (and "Version=" (submatch (1+ (in "0-9.")))))))
162
163 ;; Note this makes some assumptions about form of short copyright.
164 (defun set-copyright (root copyright)
165 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
166 Root must be the root of an Emacs source tree."
167 (interactive (list
168 (read-directory-name "Emacs root directory: " nil nil t)
169 (read-string
170 "Short copyright string: "
171 (format "Copyright (C) %s Free Software Foundation, Inc."
172 (format-time-string "%Y")))))
173 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
174 (error "%s doesn't seem to be the root of an Emacs source tree" root))
175 (set-version-in-file root "src/emacs.c" copyright
176 (rx (and "emacs_copyright" (0+ (not (in ?\")))
177 ?\" (submatch (1+ (not (in ?\")))) ?\")))
178 (set-version-in-file root "lib-src/ebrowse.c" copyright
179 (rx (and "emacs_copyright" (0+ (not (in ?\")))
180 ?\" (submatch (1+ (not (in ?\")))) ?\")))
181 (set-version-in-file root "lib-src/etags.c" copyright
182 (rx (and "emacs_copyright" (0+ (not (in ?\")))
183 ?\" (submatch (1+ (not (in ?\")))) ?\")))
184 (set-version-in-file root "lib-src/rcs2log" copyright
185 (rx (and "Copyright" (0+ space) ?= (0+ space)
186 ?\' (submatch (1+ nonl)))))
187 ;; This one is a nuisance, as it needs to be split over two lines.
188 (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
189 ;; nextstep.
190 (set-version-in-file
191 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
192 copyright (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
193 (1+ (in "0-9.")) (1+ space)
194 (submatch (1+ (not (in ?\<)))))))
195 (set-version-in-file
196 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
197 copyright (rx (and "NSHumanReadableCopyright" (0+ space) ?\= (0+ space)
198 ?\" (submatch (1+ (not (in ?\")))))))
199 (set-version-in-file
200 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
201 copyright (rx (and "Copyright" (0+ space) ?\= (0+ space)
202 ?\" (submatch (1+ (not (in ?\")))))))
203 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
204 (setq copyright (match-string 1 copyright))
205 (dolist (file (directory-files (expand-file-name "etc/refcards" root)
206 t "\\.tex\\'"))
207 (unless (string-match "gnus-refcard\\.tex" file)
208 (set-version-in-file
209 root file copyright
210 (concat (if (string-match "ru-refcard\\.tex" file)
211 "\\\\newcommand{\\\\cyear}\\[0\\]{"
212 "\\\\def\\\\year{")
213 "\\([0-9]\\{4\\}\\)}.+%.+copyright year"))))))
214
215 (provide 'admin)
216
217 ;;; admin.el ends here