Merge branch 'maint'
[org-mode/org-tableheadings.git] / mk / org-fixup.el
blobac289637913bebaefe6ffd52336c5f0487c0efe7
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.
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 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 (let ((inhibit-read-only t))
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
74 nil "^\\(org\\|ob\\|ox\\)\\(-.*\\)?\\.el$")))
75 (mapc (lambda (f) (generate-file-autoloads f)) files))
76 (insert "\f\n(provide 'org-loaddefs)\n")
77 (insert "\f\n;; Local Variables:\n;; version-control: never\n")
78 (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
79 (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
80 (let ((inhibit-read-only t))
81 (save-buffer))))
83 (defun org-make-autoloads (&optional compile force)
84 "Make the files org-loaddefs.el and org-version.el in the install directory.
85 Finds the install directory by looking for library \"org\".
86 Optionally byte-compile lisp files in the install directory or
87 force re-compilation. This function is provided for easier
88 manual install when the build system can't be used."
89 (let* ((origin default-directory)
90 (dirlisp (org-find-library-dir "org"))
91 (dirorg (concat dirlisp "../" ))
92 (dirodt (if (boundp 'org-odt-data-dir)
93 org-odt-data-dir
94 (concat dirorg "etc/"))))
95 (unwind-protect
96 (progn
97 (cd dirlisp)
98 (org-fixup)
99 (org-make-org-version (org-release) (org-git-version) dirodt)
100 (org-make-org-loaddefs)
101 (when compile (byte-recompile-directory dirlisp 0 force)))
102 (cd origin))))
104 (defun org-make-autoloads-compile ()
105 "Call org-make-autoloads with compile argument.
106 Convenience function for easier invocation from command line."
107 (org-make-autoloads 'compile nil))
109 (defun org-make-autoloads-compile-force ()
110 "Call org-make-autoloads with compile force arguments.
111 Convenience function for easier invocation from command line."
112 (org-make-autoloads 'compile 'force))
114 ;; Internal functions
116 (defun org-make-local-mk ()
117 "Internal function for the build system."
118 (let ((default "mk/default.mk")
119 (local "local.mk"))
120 (unwind-protect
121 (with-temp-buffer
122 (insert-file-contents default)
123 (goto-char (point-min))
124 (when (search-forward "-8<-" nil t)
125 (forward-line 1)
126 (delete-region (point-min) (point)))
127 (when (search-forward "->8-" nil t)
128 (forward-line 0)
129 (delete-region (point) (point-max)))
130 (goto-char (point-min))
131 (insert "
132 # Remove \"oldorg:\" to switch to \"all\" as the default target.
133 # Change \"oldorg:\" to an existing target to make that target the default,
134 # or define your own target here to become the default target.
135 oldorg: # do what the old Makefile did by default.
137 ##----------------------------------------------------------------------
139 (goto-char (point-max))
140 (insert "\
141 # See default.mk for further configuration options.
143 (let ((inhibit-read-only t))
144 (write-file local)))
145 nil)))
147 (defun org-make-letterformat (a4name lettername)
148 "Internal function for the build system."
149 (unwind-protect
150 (with-temp-buffer
151 (insert-file-contents a4name)
152 (goto-char (point-min))
153 (while (search-forward "\\pdflayout=(0l)" nil t)
154 (replace-match "\\pdflayout=(1l)" nil t))
155 (let ((inhibit-read-only t))
156 (write-file lettername)))
157 nil))
159 ;; redefine version functions
161 (defmacro org-fixup ()
162 (let* ((origin default-directory)
163 (dirlisp (org-find-library-dir "org"))
164 (dirorg (concat dirlisp "../" ))
165 (dirgit (concat dirorg ".git/" ))
166 (org-version "N/A-fixup")
167 (org-git-version "N/A-fixup !!check installation!!"))
168 (if (and (boundp 'org-fake-release) (stringp org-fake-release)
169 (boundp 'org-fake-git-version) (stringp org-fake-git-version))
170 (setq org-version org-fake-release
171 org-git-version org-fake-git-version)
172 (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
173 (setq org-version (org-release)
174 org-git-version (org-git-version))
175 (when (and (file-exists-p dirgit)
176 (executable-find "git"))
177 (unwind-protect
178 (progn
179 (cd dirorg)
180 (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
181 (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
182 (gitd (string-match "\\S-"
183 (shell-command-to-string "git status -uno --porcelain"))))
184 (setq org-git-version (concat git6 (when gitd ".dirty") "-git"))
185 (if (string-match "^release_" git0)
186 (setq org-version (substring git0 8))
187 (setq org-version git0))))
188 (cd origin)))))
189 (message "org-fixup.el: redefined Org version")
190 `(progn
191 (defun org-release () ,org-version)
192 (defun org-git-version () ,org-git-version))))
194 (provide 'org-fixup)
196 ;; Local Variables:
197 ;; no-byte-compile: t
198 ;; coding: utf-8
199 ;; End:
200 ;;; org-fixup.el ends here