lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / mk / org-fixup.el
blob760e73a16311b8a3271b80a3eb07f71d7f694e7b
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" "../doc/org-guide.org"))
34 (find-file manual)
35 (org-texinfo-export-to-texinfo)))
37 (defun org-make-org-version (org-release org-git-version)
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 \f\n\(provide 'org-version\)
62 \f\n;; Local Variables:\n;; version-control: never
63 ;; no-byte-compile: t
64 ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
65 (let ((inhibit-read-only t))
66 (write-file "org-version.el"))))
68 (defun org-make-org-loaddefs ()
69 "Make the file org-loaddefs.el in the current directory.
70 This function is internally used by the build system and should
71 be used by foreign build systems or installers to produce this
72 file in the installation directory of Org mode. Org will not
73 work correctly if this file is not up-to-date."
74 (with-temp-buffer
75 (set-visited-file-name "org-loaddefs.el")
76 (insert ";;; org-loaddefs.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
77 (let ((files (directory-files default-directory
78 nil "^\\(org\\|ob\\|ox\\)\\(-.*\\)?\\.el$")))
79 (mapc (lambda (f) (generate-file-autoloads f)) files))
80 (insert "\f\n(provide 'org-loaddefs)\n")
81 (insert "\f\n;; Local Variables:\n;; version-control: never\n")
82 (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
83 (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
84 (let ((inhibit-read-only t))
85 (save-buffer))))
87 (defun org-make-autoloads (&optional compile force)
88 "Make the files org-loaddefs.el and org-version.el in the install directory.
89 Finds the install directory by looking for library \"org\".
90 Optionally byte-compile lisp files in the install directory or
91 force re-compilation. This function is provided for easier
92 manual install when the build system can't be used."
93 (let ((origin default-directory)
94 (dirlisp (org-find-library-dir "org")))
95 (unwind-protect
96 (progn
97 (cd dirlisp)
98 (org-fixup)
99 (org-make-org-version (org-release) (org-git-version))
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