ensure that M-x org-version always delivers something useful
[org-mode.git] / UTILITIES / org-fixup.el
blob9d0dfa28cb501ef6adf5622df0b098808481055e
1 ;;; org-fixup.el - to make life easier for folks without GNU make
2 ;;
3 ;; Author: Achim Gratz
4 ;; Keywords: outlines, hypermedia, calendar, wp
5 ;; Homepage: http://orgmode.org
6 ;;
7 ;; This file is not yet part of GNU Emacs.
8 ;;
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 (require 'org-compat)
28 (require 'autoload)
30 (defun org-make-org-version (org-release org-git-version odt-dir)
31 (find-file "org-version.el")
32 (erase-buffer)
33 (insert "\
34 ;;; org-version.el --- autogenerated file, do not edit
36 ;;; Code:
37 ;;;\#\#\#autoload
38 \(defun org-release ()
39 \"The release version of org-mode.
40 Inserted by installing org-mode or when a release is made.\"
41 (let ((org-release \"" org-release "\"))
42 org-release))
43 ;;;\#\#\#autoload
44 \(defun org-git-version ()
45 \"The Git version of org-mode.
46 Inserted by installing org-mode or when a release is made.\"
47 (let ((org-git-version \"" org-git-version "\"))
48 org-git-version))
49 ;;;\#\#\#autoload
50 \(defconst org-odt-data-dir \"" odt-dir "\"
51 \"The location of ODT styles.\")
52 \f\n;; Local Variables:\n;; version-control: never
53 ;; no-byte-compile: t
54 ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
55 (save-buffer))
57 (defun org-make-org-install (absfile)
58 (find-file absfile)
59 (erase-buffer)
60 (insert ";;; org-install.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
61 (let ((files (directory-files (file-name-directory absfile) 'full "^[^.#~]*\\.el$")))
62 (mapc (lambda (f) (generate-file-autoloads f)) files))
63 (insert "\f\n(provide 'org-install)\n")
64 (insert "\f\n;; Local Variables:\n;; version-control: never\n")
65 (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
66 (insert ";; coding: utf-8\n;; End:\n;;; org-install.el ends here\n")
67 (save-buffer))
69 (defmacro org-fixup ()
70 (let* ((origin default-directory)
71 (dirlisp (org-find-library-name "org"))
72 (dirorg (concat dirlisp "../" ))
73 (dirgit (concat dirorg ".git/" ))
74 (org-version "N/A-fixup")
75 (org-git-version "N/A-fixup !!check installation!!"))
76 (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix 'mustsuffix)
77 (setq org-version (org-release)
78 org-git-version (org-git-version))
79 (when (and (file-exists-p dirgit)
80 (executable-find "git"))
81 (unwind-protect
82 (progn
83 (cd dirorg)
84 (when (eql 0 (shell-command "git describe --abbrev=6 HEAD"))
85 (with-current-buffer "*Shell Command Output*"
86 (goto-char (point-min))
87 (setq git-version (buffer-substring (point) (point-at-eol))))
88 (when (string-match "\\S-"
89 (shell-command-to-string
90 "git diff-index --name-only HEAD --"))
91 (setq git-version (concat git-version "-dirty")))
92 (setq org-version (and (string-match "_\\([^-]+\\)-" git-version)
93 (match-string 1 git-version)))
94 (setq org-git-version git-version)))
95 (cd origin))))
96 `(progn
97 (defun org-release () ,org-version)
98 (defun org-git-version () ,org-git-version)
99 "org-fixup.el: redefined org version."
102 (provide 'org-fixup)
104 ;; Local Variables:
105 ;; no-byte-compile: t
106 ;; coding: utf-8
107 ;; End:
108 ;;; org-fixup.el ends here