Merge remote-tracking branch 'origin/maint'
[org-mode.git] / UTILITIES / org-fixup.el
blob1e03801cd9e0e3d54b0b6cbe652f0cfccb26c5a2
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 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 (load "autoload" nil 'nomessage)
28 (load "org-compat.el" nil 'nomessage 'nosuffix)
30 (defun org-make-org-version (org-release org-git-version odt-dir)
31 (with-temp-buffer
32 (insert "\
33 ;;; org-version.el --- autogenerated file, do not edit
35 ;;; Code:
36 ;;;\#\#\#autoload
37 \(defun org-release ()
38 \"The release version of org-mode.
39 Inserted by installing org-mode or when a release is made.\"
40 (let ((org-release \"" org-release "\"))
41 org-release))
42 ;;;\#\#\#autoload
43 \(defun org-git-version ()
44 \"The Git version of org-mode.
45 Inserted by installing org-mode or when a release is made.\"
46 (let ((org-git-version \"" org-git-version "\"))
47 org-git-version))
48 ;;;\#\#\#autoload
49 \(defconst org-odt-data-dir \"" odt-dir "\"
50 \"The location of ODT styles.\")
51 \f\n;; Local Variables:\n;; version-control: never
52 ;; no-byte-compile: t
53 ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
54 (toggle-read-only 0)
55 (write-file "org-version.el")))
57 (defun org-make-org-install ()
58 (with-temp-buffer
59 (set-visited-file-name "org-install.el")
60 (insert ";;; org-install.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
61 (let ((files (directory-files default-directory nil "^\\(org\\|ob\\)\\(-.*\\)?\\.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 (toggle-read-only 0)
68 (save-buffer)))
70 (defun org-make-autoloads ()
71 (let* ((origin default-directory)
72 (dirlisp (org-find-library-dir "org"))
73 (dirorg (concat dirlisp "../" ))
74 (dirodt (if (boundp 'org-odt-data-dir)
75 org-odt-data-dir
76 (concat dirorg "etc/"))))
77 (unwind-protect
78 (progn
79 (cd dirlisp)
80 (org-fixup)
81 (org-make-org-version (org-release) (org-git-version) dirodt)
82 (org-make-org-install))
83 (cd origin))))
85 (defun org-make-autoloads-compile (&rest force)
86 (let* ((origin default-directory)
87 (dirlisp (org-find-library-dir "org")))
88 (unwind-protect
89 (progn
90 (cd dirlisp)
91 (org-make-autoloads)
92 (byte-recompile-directory dirlisp 0 force))
93 (cd origin))))
95 (defun org-make-local-mk ()
96 (let ((default "default.mk")
97 (local "local.mk"))
98 (unwind-protect
99 (with-temp-buffer
100 (insert-file-contents default)
101 (goto-char (point-min))
102 (when (search-forward "-8<-" nil t)
103 (forward-line 1)
104 (delete-region (point-min) (point)))
105 (when (search-forward "->8-" nil t)
106 (forward-line 0)
107 (delete-region (point) (point-max)))
108 (goto-char (point-min))
109 (insert "
110 # Remove \"oldorg:\" to switch to \"all\" as the default target.
111 # Change \"oldorg:\" to an existing target to make that target the default,
112 # or define your own target here to become the default target.
113 oldorg: # do what the old Makfile did by default
115 ##----------------------------------------------------------------------
117 (goto-char (point-max))
118 (insert "\
119 # See default.mk for further configuration options.
121 (toggle-read-only 0)
122 (write-file local))
123 nil)))
125 (defun org-make-letterformat (a4name lettername)
126 (unwind-protect
127 (with-temp-buffer
128 (insert-file-contents a4name)
129 (goto-char (point-min))
130 (while (search-forward "\\pdflayout=(0l)" nil t)
131 (replace-match "\\pdflayout=(1l)" nil t))
132 (toggle-read-only 0)
133 (write-file lettername))
134 nil))
136 (defmacro org-fixup ()
137 (let* ((origin default-directory)
138 (dirlisp (org-find-library-dir "org"))
139 (dirorg (concat dirlisp "../" ))
140 (dirgit (concat dirorg ".git/" ))
141 (org-version "N/A-fixup")
142 (org-git-version "N/A-fixup !!check installation!!"))
143 (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
144 (setq org-version (org-release)
145 org-git-version (org-git-version))
146 (when (and (file-exists-p dirgit)
147 (executable-find "git"))
148 (unwind-protect
149 (progn
150 (cd dirorg)
151 (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
152 (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
153 (gitd (string-match "\\S-" (shell-command-to-string "git status -uno --porcelain"))))
154 (setq org-git-version (concat git6 (when gitd ".dirty")))
155 (if (string-match "^release_" git0)
156 (setq org-version (substring git0 8))
157 (setq org-version git0))))
158 (cd origin))))
159 `(progn
160 (defun org-release () ,org-version)
161 (defun org-git-version () ,org-git-version)
162 "org-fixup.el: redefined org version.")))
164 (provide 'org-fixup)
166 ;; Local Variables:
167 ;; no-byte-compile: t
168 ;; coding: utf-8
169 ;; End:
170 ;;; org-fixup.el ends here