Merge changes from emacs-23 branch
[bpt/emacs.git] / admin / admin.el
CommitLineData
74499542
GM
1;;; admin.el --- utilities for Emacs administration
2
73b0cd50 3;; Copyright (C) 2001-2011 Free Software Foundation, Inc.
74499542
GM
4
5;; This file is part of GNU Emacs.
6
9ad5de0c 7;; GNU Emacs is free software: you can redistribute it and/or modify
74499542 8;; it under the terms of the GNU General Public License as published by
9ad5de0c
GM
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
74499542
GM
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
9ad5de0c 18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
74499542
GM
19
20;;; Commentary:
21
54381691
LK
22;; add-release-logs Add ``Version X released'' change log entries.
23;; set-version Change Emacs version number in source tree.
a3045b7e
GM
24;; set-copyright Change emacs short copyright string (eg as
25;; printed by --version) in source tree.
74499542
GM
26
27;;; Code:
28
74499542
GM
29(defun add-release-logs (root version)
30 "Add \"Version VERSION released.\" change log entries in ROOT.
31Root must be the root of an Emacs source tree."
32 (interactive "DEmacs root directory: \nNVersion number: ")
3f4a4bdf 33 (setq root (expand-file-name root))
74499542
GM
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))
54381691 36 (require 'add-log)
74499542
GM
37 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
38 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
3f4a4bdf
FP
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)))
74499542 43 (dolist (log logs)
e568708b 44 (unless (string-match "/gnus/" log)
74499542
GM
45 (find-file log)
46 (goto-char (point-min))
47 (insert entry)))))
48
74499542
GM
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
74499542
GM
56(defun set-version (root version)
57 "Set Emacs version to VERSION in relevant files under ROOT.
58Root must be the root of an Emacs source tree."
91ebb8c9 59 (interactive "DEmacs root directory: \nsVersion number: ")
74499542
GM
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))
74499542
GM
62 (set-version-in-file root "README" version
63 (rx (and "version" (1+ space)
64 (submatch (1+ (in "0-9."))))))
24bbe01e
GM
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."))))))
f4f358f1
GM
69 (set-version-in-file root "doc/emacs/emacsver.texi" version
70 (rx (and "EMACSVER" (1+ space)
71 (submatch (1+ (in "0-9."))))))
adf94aa6
GM
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."))))))
70b0d280
EZ
76 (set-version-in-file root "nt/config.nt" version
77 (rx (and bol "#" (0+ blank) "define" (1+ blank)
78 "VERSION" (1+ blank)
1fe1ef05 79 (submatch (1+ (in "0-9."))))))
e3aef5c6
CS
80 (set-version-in-file root "nt/makefile.w32-in" version
81 (rx (and "VERSION" (0+ space) "=" (0+ space)
82 (submatch (1+ (in "0-9."))))))
95f76284
JR
83 ;; nt/emacs.rc also contains the version number, but in an awkward
84 ;; format. It must contain four components, separated by commas, and
85 ;; in two places those commas are followed by space, in two other
86 ;; places they are not.
87 (let* ((version-components (append (split-string version "\\.")
88 '("0" "0")))
89 (comma-version
90 (concat (car version-components) ","
91 (cadr version-components) ","
d0834a5c 92 (cadr (cdr version-components)) ","
95f76284
JR
93 (cadr (cdr (cdr version-components)))))
94 (comma-space-version
95 (concat (car version-components) ", "
96 (cadr version-components) ", "
d0834a5c 97 (cadr (cdr version-components)) ", "
95f76284
JR
98 (cadr (cdr (cdr version-components))))))
99 (set-version-in-file root "nt/emacs.rc" comma-version
100 (rx (and "FILEVERSION" (1+ space)
101 (submatch (1+ (in "0-9,"))))))
102 (set-version-in-file root "nt/emacs.rc" comma-version
103 (rx (and "PRODUCTVERSION" (1+ space)
104 (submatch (1+ (in "0-9,"))))))
105 (set-version-in-file root "nt/emacs.rc" comma-space-version
106 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
107 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
108 (set-version-in-file root "nt/emacs.rc" comma-space-version
109 (rx (and "\"ProductVersion\"" (0+ space) ?,
110 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
b7063e7e
JR
111 "\\0\"")))
112 ;; Likewise for emacsclient.rc
113 (set-version-in-file root "nt/emacsclient.rc" comma-version
114 (rx (and "FILEVERSION" (1+ space)
115 (submatch (1+ (in "0-9,"))))))
116 (set-version-in-file root "nt/emacsclient.rc" comma-version
117 (rx (and "PRODUCTVERSION" (1+ space)
118 (submatch (1+ (in "0-9,"))))))
119 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
120 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
121 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
122 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
95f76284
JR
123 (rx (and "\"ProductVersion\"" (0+ space) ?,
124 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
9e2a2647 125 "\\0\""))))
d3841127
GM
126 ;; nextstep.
127 (set-version-in-file
128 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
129 version (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
130 (submatch (1+ (in "0-9."))))))
131 (set-version-in-file
132 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
91236f63
GM
133 version (rx (and "CFBundleShortVersionString" (1+ not-newline) ?\n
134 (0+ not-newline) "<string>" (0+ space)
d3841127
GM
135 (submatch (1+ (in "0-9."))))))
136 (set-version-in-file
137 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
138 version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space)
139 ?\" (0+ space) "Version" (1+ space)
140 (submatch (1+ (in "0-9."))))))
141 (set-version-in-file
142 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
143 version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space)
144 ?\" (0+ space) "Emacs version" (1+ space)
145 (submatch (1+ (in "0-9."))))))
91236f63
GM
146 (set-version-in-file
147 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
148 version (rx (and "ApplicationRelease" (0+ space) ?= (0+ space)
149 ?\" (0+ space) (submatch (1+ (in "0-9."))))))
d3841127
GM
150 (set-version-in-file
151 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
152 version (rx (and "FullVersionID" (0+ space) ?= (0+ space)
153 ?\" (0+ space) "Emacs" (1+ space)
91236f63
GM
154 (submatch (1+ (in "0-9."))))))
155 (set-version-in-file
156 root "nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop"
157 version (rx (and "Version=" (submatch (1+ (in "0-9.")))))))
3f4a4bdf 158
a3045b7e
GM
159;; Note this makes some assumptions about form of short copyright.
160(defun set-copyright (root copyright)
161 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
162Root must be the root of an Emacs source tree."
163 (interactive (list
164 (read-directory-name "Emacs root directory: " nil nil t)
165 (read-string
166 "Short copyright string: "
167 (format "Copyright (C) %s Free Software Foundation, Inc."
168 (format-time-string "%Y")))))
169 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
170 (error "%s doesn't seem to be the root of an Emacs source tree" root))
e45b9e19
KR
171 (set-version-in-file root "src/emacs.c" copyright
172 (rx (and "emacs_copyright" (0+ (not (in ?\")))
287d4c2c 173 ?\" (submatch (1+ (not (in ?\")))) ?\")))
a70c9a7a
GM
174 (set-version-in-file root "lib-src/ebrowse.c" copyright
175 (rx (and "emacs_copyright" (0+ (not (in ?\")))
287d4c2c 176 ?\" (submatch (1+ (not (in ?\")))) ?\")))
a3045b7e
GM
177 (set-version-in-file root "lib-src/etags.c" copyright
178 (rx (and "emacs_copyright" (0+ (not (in ?\")))
287d4c2c 179 ?\" (submatch (1+ (not (in ?\")))) ?\")))
a3045b7e 180 (set-version-in-file root "lib-src/rcs2log" copyright
287d4c2c
GM
181 (rx (and "Copyright" (0+ space) ?= (0+ space)
182 ?\' (submatch (1+ nonl)))))
a3045b7e
GM
183 ;; This one is a nuisance, as it needs to be split over two lines.
184 (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
d3841127
GM
185 ;; nextstep.
186 (set-version-in-file
187 root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
188 copyright (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
189 (1+ (in "0-9.")) (1+ space)
190 (submatch (1+ (not (in ?\<)))))))
191 (set-version-in-file
192 root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
193 copyright (rx (and "NSHumanReadableCopyright" (0+ space) ?\= (0+ space)
7963f8ab
GM
194 ?\" (submatch (1+ (not (in ?\")))))))
195 (set-version-in-file
196 root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
197 copyright (rx (and "Copyright" (0+ space) ?\= (0+ space)
287d4c2c
GM
198 ?\" (submatch (1+ (not (in ?\")))))))
199 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
200 (setq copyright (match-string 1 copyright))
201 (dolist (file (directory-files (expand-file-name "etc/refcards" root)
202 t "\\.tex\\'"))
203 (unless (string-match "gnus-refcard\\.tex" file)
204 (set-version-in-file
205 root file copyright
206 (concat (if (string-match "ru-refcard\\.tex" file)
207 "\\\\newcommand{\\\\cyear}\\[0\\]{"
208 "\\\\def\\\\year{")
209 "\\([0-9]\\{4\\}\\)}.+%.+copyright year"))))))
a3045b7e 210
69c52df1
GM
211(provide 'admin)
212
d3841127 213;;; admin.el ends here