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