Merge from emacs-24; up to 2012-04-24T08:35:02Z!lekktu@gmail.com
[bpt/emacs.git] / lisp / version.el
1 ;;; version.el --- record version number of Emacs
2
3 ;; Copyright (C) 1985, 1992, 1994-1995, 1999-2012
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8 ;; Package: emacs
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (defconst emacs-major-version
30 (progn (string-match "^[0-9]+" emacs-version)
31 (string-to-number (match-string 0 emacs-version)))
32 "Major version number of this version of Emacs.
33 This variable first existed in version 19.23.")
34
35 (defconst emacs-minor-version
36 (progn (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version)
37 (string-to-number (match-string 1 emacs-version)))
38 "Minor version number of this version of Emacs.
39 This variable first existed in version 19.23.")
40
41 (defconst emacs-build-time (current-time)
42 "Time at which Emacs was dumped out.")
43
44 (defconst emacs-build-system (system-name)
45 "Name of the system on which Emacs was built.")
46
47 (defun emacs-version (&optional here)
48 "Return string describing the version of Emacs that is running.
49 If optional argument HERE is non-nil, insert string at point.
50 Don't use this function in programs to choose actions according
51 to the system configuration; look at `system-configuration' instead."
52 (interactive "P")
53 (let ((version-string
54 (format (if (not (called-interactively-p 'interactive))
55 "GNU Emacs %s (%s%s%s)\n of %s on %s"
56 "GNU Emacs %s (%s%s%s) of %s on %s")
57 emacs-version
58 system-configuration
59 (cond ((featurep 'motif)
60 (concat ", " (substring motif-version-string 4)))
61 ((featurep 'gtk)
62 (concat ", GTK+ Version " gtk-version-string))
63 ((featurep 'x-toolkit) ", X toolkit")
64 ((featurep 'ns)
65 (format ", NS %s" ns-version-string))
66 (t ""))
67 (if (and (boundp 'x-toolkit-scroll-bars)
68 (memq x-toolkit-scroll-bars '(xaw xaw3d)))
69 (format ", %s scroll bars"
70 (capitalize (symbol-name x-toolkit-scroll-bars)))
71 "")
72 (format-time-string "%Y-%m-%d" emacs-build-time)
73 emacs-build-system)))
74 (if here
75 (insert version-string)
76 (if (called-interactively-p 'interactive)
77 (message "%s" version-string)
78 version-string))))
79
80 ;; We hope that this alias is easier for people to find.
81 (defalias 'version 'emacs-version)
82
83 ;; Set during dumping, this is a defvar so that it can be setq'd.
84 (defvar emacs-bzr-version nil
85 "String giving the bzr revision from which this Emacs was built.
86 Value is the bzr revision number and a revision ID separated by a blank.
87 Value is nil if Emacs was not built from a bzr checkout, or if we could
88 not determine the revision.")
89
90 (defun emacs-bzr-get-version (&optional dir)
91 "Try to return as a string the bzr revision number of the Emacs sources.
92 Value is the bzr revision number and a revision ID separated by a blank.
93 Value is nil if the sources do not seem to be under bzr, or if we could
94 not determine the revision. Note that this reports on the current state
95 of the sources, which may not correspond to the running Emacs.
96
97 Optional argument DIR is a directory to use instead of `source-directory'."
98 (or dir (setq dir source-directory))
99 (when (file-directory-p (setq dir (expand-file-name ".bzr/branch" dir)))
100 (let (file loc)
101 (cond ((file-readable-p
102 (setq file (expand-file-name "last-revision" dir)))
103 (with-temp-buffer
104 (insert-file-contents file)
105 (goto-char (point-max))
106 (if (looking-back "\n")
107 (delete-char -1))
108 (buffer-string)))
109 ;; OK, no last-revision. Is it a lightweight checkout?
110 ((file-readable-p
111 (setq file (expand-file-name "location" dir)))
112 ;; If the parent branch is local, try looking there for the revid.
113 (if (setq loc (with-temp-buffer
114 (insert-file-contents file)
115 (if (looking-at "file://\\(.*\\)")
116 (match-string 1))))
117 (emacs-bzr-get-version loc)))
118 ;; Could fall back to eg `bzr testament' at this point.
119 ))))
120
121 ;; We put version info into the executable in the form that `ident' uses.
122 (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))
123 " $\n"))
124
125 ;;; version.el ends here