org-odt.el (and org-e-odt.el): Simplify the way style/schema files are found
[org-mode/org-tableheadings.git] / mk / org-fixup.el
blob57542749ca0d627824c1971ed07d5c979fdd5b5e
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 (toggle-read-only 0)
55 (write-file "org-version.el")))
57 (defun org-make-org-loaddefs ()
58 "Make the file org-loaddefs.el in the current directory.
59 This function is internally used by the build system and should
60 be used by foreign build systems or installers to produce this
61 file in the installation directory of org-mode. Org will not
62 work correctly if this file is not up-to-date."
63 (with-temp-buffer
64 (set-visited-file-name "org-loaddefs.el")
65 (insert ";;; org-loaddefs.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
66 (let ((files (directory-files default-directory nil "^\\(org\\|ob\\)\\(-.*\\)?\\.el$")))
67 (mapc (lambda (f) (generate-file-autoloads f)) files))
68 (insert "\f\n(provide 'org-loaddefs)\n")
69 (insert "\f\n;; Local Variables:\n;; version-control: never\n")
70 (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
71 (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
72 (toggle-read-only 0)
73 (save-buffer)))
75 (defun org-make-autoloads (&optional compile force)
76 "Make the files org-loaddefs.el and org-version.el in the install directory.
77 Finds the install directory by looking for library \"org\".
78 Optionally byte-compile lisp files in the install directory or
79 force re-compilation. This function is provided for easier
80 manual install when the build system can't be used."
81 (let* ((origin default-directory)
82 (dirlisp (org-find-library-dir "org"))
83 (dirorg (concat dirlisp "../" )))
84 (unwind-protect
85 (progn
86 (cd dirlisp)
87 (org-fixup)
88 (org-make-org-version (org-release) (org-git-version) dirodt)
89 (org-make-org-loaddefs)
90 (when compile (byte-recompile-directory dirlisp 0 force)))
91 (cd origin))))
93 (defun org-make-autoloads-compile ()
94 "Call org-make-autoloads with compile argument.
95 Convenience function for easier invocation from command line."
96 (org-make-autoloads 'compile nil))
98 (defun org-make-autoloads-compile-force ()
99 "Call org-make-autoloads with compile force arguments.
100 Convenience function for easier invocation from command line."
101 (org-make-autoloads 'compile 'force))
103 ;; Internal functions
105 (defun org-make-local-mk ()
106 "Internal function for the build system."
107 (let ((default "mk/default.mk")
108 (local "local.mk"))
109 (unwind-protect
110 (with-temp-buffer
111 (insert-file-contents default)
112 (goto-char (point-min))
113 (when (search-forward "-8<-" nil t)
114 (forward-line 1)
115 (delete-region (point-min) (point)))
116 (when (search-forward "->8-" nil t)
117 (forward-line 0)
118 (delete-region (point) (point-max)))
119 (goto-char (point-min))
120 (insert "
121 # Remove \"oldorg:\" to switch to \"all\" as the default target.
122 # Change \"oldorg:\" to an existing target to make that target the default,
123 # or define your own target here to become the default target.
124 oldorg: # do what the old Makefile did by default.
126 ##----------------------------------------------------------------------
128 (goto-char (point-max))
129 (insert "\
130 # See default.mk for further configuration options.
132 (toggle-read-only 0)
133 (write-file local))
134 nil)))
136 (defun org-make-letterformat (a4name lettername)
137 "Internal function for the build system."
138 (unwind-protect
139 (with-temp-buffer
140 (insert-file-contents a4name)
141 (goto-char (point-min))
142 (while (search-forward "\\pdflayout=(0l)" nil t)
143 (replace-match "\\pdflayout=(1l)" nil t))
144 (toggle-read-only 0)
145 (write-file lettername))
146 nil))
148 ;; redefine version functions
150 (defmacro org-fixup ()
151 (let* ((origin default-directory)
152 (dirlisp (org-find-library-dir "org"))
153 (dirorg (concat dirlisp "../" ))
154 (dirgit (concat dirorg ".git/" ))
155 (org-version "N/A-fixup")
156 (org-git-version "N/A-fixup !!check installation!!"))
157 (if (and (boundp 'org-fake-release) (stringp org-fake-release)
158 (boundp 'org-fake-git-version) (stringp org-fake-git-version))
159 (setq org-version org-fake-release
160 org-git-version org-fake-git-version)
161 (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
162 (setq org-version (org-release)
163 org-git-version (org-git-version))
164 (when (and (file-exists-p dirgit)
165 (executable-find "git"))
166 (unwind-protect
167 (progn
168 (cd dirorg)
169 (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
170 (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
171 (gitd (string-match "\\S-"
172 (shell-command-to-string "git status -uno --porcelain"))))
173 (setq org-git-version (concat git6 (when gitd ".dirty") "-git"))
174 (if (string-match "^release_" git0)
175 (setq org-version (substring git0 8))
176 (setq org-version git0))))
177 (cd origin)))))
178 (message "org-fixup.el: redefined Org version")
179 `(progn
180 (defun org-release () ,org-version)
181 (defun org-git-version () ,org-git-version))))
183 (provide 'org-fixup)
185 ;; Local Variables:
186 ;; no-byte-compile: t
187 ;; coding: utf-8
188 ;; End:
189 ;;; org-fixup.el ends here