Fix commentary.
[emacs.git] / admin / admin.el
blob05cd7f944671d040810a466b540915df70a0dfab
1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs 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 3, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs 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.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;; add-release-logs Add ``Version X released'' change log entries.
26 ;; set-version Change Emacs version number in source tree.
27 ;; set-copyright Change emacs short copyright string (eg as
28 ;; printed by --version) in source tree.
30 ;;; Code:
32 (defun add-release-logs (root version)
33 "Add \"Version VERSION released.\" change log entries in ROOT.
34 Root must be the root of an Emacs source tree."
35 (interactive "DEmacs root directory: \nNVersion number: ")
36 (setq root (expand-file-name root))
37 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
38 (error "%s doesn't seem to be the root of an Emacs source tree" root))
39 (require 'add-log)
40 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
41 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
42 (funcall add-log-time-format)
43 (or add-log-full-name (user-full-name))
44 (or add-log-mailing-address user-mail-address)
45 version)))
46 (dolist (log logs)
47 (unless (string-match "/gnus/" log)
48 (find-file log)
49 (goto-char (point-min))
50 (insert entry)))))
52 (defun set-version-in-file (root file version rx)
53 (find-file (expand-file-name file root))
54 (goto-char (point-min))
55 (unless (re-search-forward rx nil t)
56 (error "Version not found in %s" file))
57 (replace-match (format "%s" version) nil nil nil 1))
59 (defun set-version (root version)
60 "Set Emacs version to VERSION in relevant files under ROOT.
61 Root must be the root of an Emacs source tree."
62 (interactive "DEmacs root directory: \nsVersion number: ")
63 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
64 (error "%s doesn't seem to be the root of an Emacs source tree" root))
65 (set-version-in-file root "lisp/version.el" version
66 (rx (and "emacs-version" (0+ space)
67 ?\" (submatch (1+ (not (in ?\")))) ?\")))
68 (set-version-in-file root "README" version
69 (rx (and "version" (1+ space)
70 (submatch (1+ (in "0-9."))))))
71 (set-version-in-file root "configure.in" version
72 (rx (and "AC_INIT" (1+ (not (in ?,)))
73 ?, (0+ space)
74 (submatch (1+ (in "0-9."))))))
75 (set-version-in-file root "doc/emacs/emacs.texi" version
76 (rx (and "EMACSVER" (1+ space)
77 (submatch (1+ (in "0-9."))))))
78 (set-version-in-file root "doc/lispref/elisp.texi" version
79 (rx (and "EMACSVER" (1+ space)
80 (submatch (1+ (in "0-9."))))))
81 (set-version-in-file root "doc/man/emacs.1" version
82 (rx (and ".TH EMACS" (1+ not-newline)
83 "GNU Emacs" (1+ space)
84 (submatch (1+ (in "0-9."))))))
85 (set-version-in-file root "lib-src/makefile.w32-in" version
86 (rx (and "VERSION" (0+ space) "=" (0+ space)
87 (submatch (1+ (in "0-9."))))))
88 ;; nt/emacs.rc also contains the version number, but in an awkward
89 ;; format. It must contain four components, separated by commas, and
90 ;; in two places those commas are followed by space, in two other
91 ;; places they are not.
92 (let* ((version-components (append (split-string version "\\.")
93 '("0" "0")))
94 (comma-version
95 (concat (car version-components) ","
96 (cadr version-components) ","
97 (cadr (cdr version-components)) ","
98 (cadr (cdr (cdr version-components)))))
99 (comma-space-version
100 (concat (car version-components) ", "
101 (cadr version-components) ", "
102 (cadr (cdr version-components)) ", "
103 (cadr (cdr (cdr version-components))))))
104 (set-version-in-file root "nt/emacs.rc" comma-version
105 (rx (and "FILEVERSION" (1+ space)
106 (submatch (1+ (in "0-9,"))))))
107 (set-version-in-file root "nt/emacs.rc" comma-version
108 (rx (and "PRODUCTVERSION" (1+ space)
109 (submatch (1+ (in "0-9,"))))))
110 (set-version-in-file root "nt/emacs.rc" comma-space-version
111 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
112 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
113 (set-version-in-file root "nt/emacs.rc" comma-space-version
114 (rx (and "\"ProductVersion\"" (0+ space) ?,
115 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
116 "\\0\"")))
117 ;; Some files in the "mac" subdirectory also contain the version
118 ;; number.
119 (set-version-in-file
120 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
121 version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space) ?\"
122 (submatch (1+ (in "0-9."))))))
123 (set-version-in-file
124 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
125 version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space) ?\"
126 (submatch (1+ (in "0-9."))))))
127 (set-version-in-file root "mac/src/Emacs.r" (car version-components)
128 (rx (and "GNU Emacs " (submatch (1+ (in "0-9")))
129 " for Mac OS")))
130 (set-version-in-file root "mac/src/Emacs.r" (car version-components)
131 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
132 (0+ space) "/* Major revision in BCD */")))
133 (set-version-in-file root "mac/src/Emacs.r" (cadr version-components)
134 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
135 (0+ space) "/* Minor revision in BCD */")))
136 (set-version-in-file root "mac/src/Emacs.r" (cadr (cdr version-components))
137 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
138 (0+ space) "/* Non-final release # */")))
139 (set-version-in-file root "mac/src/Emacs.r" version
140 (rx (and (submatch (1+ (in "0-9."))) (0+ space) ?\" ?\,
141 (0+ space) "/* Short version number */")))
142 (set-version-in-file root "mac/src/Emacs.r" version
143 (rx (and "/* Short version number */" (0+ space) ?\"
144 (submatch (1+ (in "0-9."))))))
145 (let* ((third-component (string-to-number (cadr (cdr version-components))))
146 (release (cond ((>= third-component 90) "alpha")
147 ((>= third-component 50) "development")
148 (t "final"))))
149 (set-version-in-file
150 root "mac/src/Emacs.r" release
151 (rx (and (submatch (1+ (in "a-z"))) (0+ space) ?\, (0+ space)
152 "/* development, alpha, beta, or final (release) */"))))))
154 ;; Note this makes some assumptions about form of short copyright.
155 ;; FIXME add the \year in the refcards/*.tex files.
156 (defun set-copyright (root copyright)
157 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
158 Root must be the root of an Emacs source tree."
159 (interactive (list
160 (read-directory-name "Emacs root directory: " nil nil t)
161 (read-string
162 "Short copyright string: "
163 (format "Copyright (C) %s Free Software Foundation, Inc."
164 (format-time-string "%Y")))))
165 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
166 (error "%s doesn't seem to be the root of an Emacs source tree" root))
167 (set-version-in-file root "lisp/version.el" copyright
168 (rx (and "emacs-copyright" (0+ space)
169 ?\" (submatch (1+ (not (in ?\")))) ?\")))
170 (set-version-in-file root "lib-src/ebrowse.c" copyright
171 (rx (and "emacs_copyright" (0+ (not (in ?\")))
172 ?\" (submatch (1+ (not (in ?\")))) ?\")))
173 (set-version-in-file root "lib-src/etags.c" copyright
174 (rx (and "emacs_copyright" (0+ (not (in ?\")))
175 ?\" (submatch (1+ (not (in ?\")))) ?\")))
176 (set-version-in-file root "lib-src/rcs2log" copyright
177 (rx (and "Copyright" (0+ space) ?= (0+ space)
178 ?\' (submatch (1+ nonl)))))
179 (set-version-in-file
180 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
181 copyright (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space) ?\"
182 (1+ anything)
183 (submatch "Copyright" (1+ (not (in ?\")))))))
184 ;; This one is a nuisance, as it needs to be split over two lines.
185 (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
186 (let ((csign "\\0xa9")
187 (cyear (match-string 1 copyright)) ; "Copyright (C) 2007 "
188 (owner (match-string 2 copyright))) ; "Free Software Foundation, Inc."
189 (set-version-in-file root "mac/src/Emacs.r"
190 (regexp-quote
191 (replace-regexp-in-string "(C)"
192 (regexp-quote csign) cyear))
193 (rx (and
194 (submatch "Copyright" (0+ space) (eval csign)
195 (0+ space) (= 4 num)
196 (0+ (not (in ?\")))) ?\")))
197 (set-version-in-file root "mac/src/Emacs.r" owner
198 (rx (and ?\"
199 (submatch (1+ (not (in ?\"))))
200 ?\" (0+ space)
201 "/* Long version number */")))))
203 (provide 'admin)
205 ;;; arch-tag: 4ea83636-2293-408b-884e-ad64f22a3bf5
206 ;; admin.el ends here.