org-entities.el (org-entities): "neg" should be used in LaTeX math mode
[org-mode.git] / mk / org-fixup.el
blob7b59efb881a9fd37d1637472588a914ee2a6db41
1 ;;; org-fixup.el --- make life easier for folks without GNU make
2 ;;
3 ;; Author: Achim Gratz
4 ;; Keywords: orgmode
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 (require 'autoload)
28 (require 'org-compat "org-compat.el")
30 (defun org-make-org-version (org-release org-git-version odt-dir)
31 "Make the file org-version.el in the current directory.
32 This function is internally used by the build system and should
33 be used by foreign build systems or installers to produce this
34 file in the installation directory of org-mode. Org will not
35 work correctly if this file is not present (except directly from
36 the Git work tree)."
37 (with-temp-buffer
38 (insert "\
39 ;;; org-version.el --- autogenerated file, do not edit
41 ;;; Code:
42 ;;;\#\#\#autoload
43 \(defun org-release ()
44 \"The release version of org-mode.
45 Inserted by installing org-mode or when a release is made.\"
46 (let ((org-release \"" org-release "\"))
47 org-release))
48 ;;;\#\#\#autoload
49 \(defun org-git-version ()
50 \"The Git version of org-mode.
51 Inserted by installing org-mode or when a release is made.\"
52 (let ((org-git-version \"" org-git-version "\"))
53 org-git-version))
54 ;;;\#\#\#autoload
55 \(defvar org-odt-data-dir \"" odt-dir "\"
56 \"The location of ODT styles.\")
57 \f\n\(provide 'org-version\)
58 \f\n;; Local Variables:\n;; version-control: never
59 ;; no-byte-compile: t
60 ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
61 (toggle-read-only 0)
62 (write-file "org-version.el")))
64 (defun org-make-org-loaddefs ()
65 "Make the file org-loaddefs.el in the current directory.
66 This function is internally used by the build system and should
67 be used by foreign build systems or installers to produce this
68 file in the installation directory of org-mode. Org will not
69 work correctly if this file is not up-to-date."
70 (with-temp-buffer
71 (set-visited-file-name "org-loaddefs.el")
72 (insert ";;; org-loaddefs.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
73 (let ((files (directory-files default-directory nil "^\\(org\\|ob\\)\\(-.*\\)?\\.el$")))
74 (mapc (lambda (f) (generate-file-autoloads f)) files))
75 (insert "\f\n(provide 'org-loaddefs)\n")
76 (insert "\f\n;; Local Variables:\n;; version-control: never\n")
77 (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
78 (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
79 (toggle-read-only 0)
80 (save-buffer)))
82 (defun org-make-autoloads (&optional compile force)
83 "Make the files org-loaddefs.el and org-version.el in the install directory.
84 Finds the install directory by looking for library \"org\".
85 Optionally byte-compile lisp files in the install directory or
86 force re-compilation. This function is provided for easier
87 manual install when the build system can't be used."
88 (let* ((origin default-directory)
89 (dirlisp (org-find-library-dir "org"))
90 (dirorg (concat dirlisp "../" ))
91 (dirodt (if (boundp 'org-odt-data-dir)
92 org-odt-data-dir
93 (concat dirorg "etc/"))))
94 (unwind-protect
95 (progn
96 (cd dirlisp)
97 (org-fixup)
98 (org-make-org-version (org-release) (org-git-version) dirodt)
99 (org-make-org-loaddefs)
100 (when compile (byte-recompile-directory dirlisp 0 force)))
101 (cd origin))))
103 (defun org-make-autoloads-compile ()
104 "Call org-make-autoloads with compile argument.
105 Convenience function for easier invocation from command line."
106 (org-make-autoloads 'compile nil))
108 (defun org-make-autoloads-compile-force ()
109 "Call org-make-autoloads with compile force arguments.
110 Convenience function for easier invocation from command line."
111 (org-make-autoloads 'compile 'force))
113 ;; Internal functions
115 (defun org-make-local-mk ()
116 "Internal function for the build system."
117 (let ((default "mk/default.mk")
118 (local "local.mk"))
119 (unwind-protect
120 (with-temp-buffer
121 (insert-file-contents default)
122 (goto-char (point-min))
123 (when (search-forward "-8<-" nil t)
124 (forward-line 1)
125 (delete-region (point-min) (point)))
126 (when (search-forward "->8-" nil t)
127 (forward-line 0)
128 (delete-region (point) (point-max)))
129 (goto-char (point-min))
130 (insert "
131 # Remove \"oldorg:\" to switch to \"all\" as the default target.
132 # Change \"oldorg:\" to an existing target to make that target the default,
133 # or define your own target here to become the default target.
134 oldorg: # do what the old Makefile did by default.
136 ##----------------------------------------------------------------------
138 (goto-char (point-max))
139 (insert "\
140 # See default.mk for further configuration options.
142 (toggle-read-only 0)
143 (write-file local))
144 nil)))
146 (defun org-make-letterformat (a4name lettername)
147 "Internal function for the build system."
148 (unwind-protect
149 (with-temp-buffer
150 (insert-file-contents a4name)
151 (goto-char (point-min))
152 (while (search-forward "\\pdflayout=(0l)" nil t)
153 (replace-match "\\pdflayout=(1l)" nil t))
154 (toggle-read-only 0)
155 (write-file lettername))
156 nil))
158 ;; redefine version functions
160 (defmacro org-fixup ()
161 (let* ((origin default-directory)
162 (dirlisp (org-find-library-dir "org"))
163 (dirorg (concat dirlisp "../" ))
164 (dirgit (concat dirorg ".git/" ))
165 (org-version "N/A-fixup")
166 (org-git-version "N/A-fixup !!check installation!!"))
167 (if (and (boundp 'org-fake-release) (stringp org-fake-release)
168 (boundp 'org-fake-git-version) (stringp org-fake-git-version))
169 (setq org-version org-fake-release
170 org-git-version org-fake-git-version)
171 (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
172 (setq org-version (org-release)
173 org-git-version (org-git-version))
174 (when (and (file-exists-p dirgit)
175 (executable-find "git"))
176 (unwind-protect
177 (progn
178 (cd dirorg)
179 (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
180 (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
181 (gitd (string-match "\\S-"
182 (shell-command-to-string "git status -uno --porcelain"))))
183 (setq org-git-version (concat git6 (when gitd ".dirty") "-git"))
184 (if (string-match "^release_" git0)
185 (setq org-version (substring git0 8))
186 (setq org-version git0))))
187 (cd origin)))))
188 (message "org-fixup.el: redefined Org version")
189 `(progn
190 (defun org-release () ,org-version)
191 (defun org-git-version () ,org-git-version))))
193 (provide 'org-fixup)
195 ;; Local Variables:
196 ;; no-byte-compile: t
197 ;; coding: utf-8
198 ;; End:
199 ;;; org-fixup.el ends here