org-fixup.el 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ;;; org-fixup.el --- make life easier for folks without GNU make
  2. ;;
  3. ;; Author: Achim Gratz
  4. ;; Keywords: orgmode
  5. ;; URL: 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.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  19. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. ;; Boston, MA 02110-1301, USA.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. (require 'autoload)
  25. (require 'org-compat "org-compat.el")
  26. (defun org-make-manual ()
  27. "Generate the Texinfo file out of the Org manual."
  28. (require 'ox-texinfo)
  29. (find-file "../doc/org-manual.org")
  30. (org-texinfo-export-to-texinfo))
  31. (defun org-make-guide ()
  32. "Generate the Texinfo file out of the Org guide."
  33. (require 'ox-texinfo)
  34. (find-file "../doc/org-guide.org")
  35. (org-texinfo-export-to-texinfo))
  36. (make-obsolete 'org-make-manuals
  37. "use org-make-manual and org-make-guide."
  38. "9.6")
  39. (defun org-make-manuals ()
  40. "Generate the Texinfo files out of Org manuals."
  41. (require 'ox-texinfo)
  42. (dolist (manual '("../doc/org-manual.org" "../doc/org-guide.org"))
  43. (find-file manual)
  44. (org-texinfo-export-to-texinfo)))
  45. (defun org-make-org-version (org-release org-git-version)
  46. "Make the file org-version.el in the current directory.
  47. This function is internally used by the build system and should
  48. be used by foreign build systems or installers to produce this
  49. file in the installation directory of Org mode. Org will not
  50. work correctly if this file is not present (except directly from
  51. the Git work tree)."
  52. (with-temp-buffer
  53. (insert "\
  54. ;;; org-version.el --- autogenerated file, do not edit -*- lexical-binding: t -*-
  55. ;;
  56. ;;; Code:
  57. ;;;\#\#\#autoload
  58. \(defun org-release ()
  59. \"The release version of Org.
  60. Inserted by installing Org mode or when a release is made.\"
  61. (let ((org-release \"" org-release "\"))
  62. org-release))
  63. ;;;\#\#\#autoload
  64. \(defun org-git-version ()
  65. \"The Git version of Org mode.
  66. Inserted by installing Org or when a release is made.\"
  67. (let ((org-git-version \"" org-git-version "\"))
  68. org-git-version))
  69. \f\n\(provide 'org-version\)
  70. \f\n;; Local Variables:\n;; version-control: never
  71. ;; no-byte-compile: t
  72. ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
  73. (let ((inhibit-read-only t))
  74. (write-file "org-version.el"))))
  75. (defun org-make-org-loaddefs ()
  76. "Make the file org-loaddefs.el in the current directory.
  77. This function is internally used by the build system and should
  78. be used by foreign build systems or installers to produce this
  79. file in the installation directory of Org mode. Org will not
  80. work correctly if this file is not up-to-date."
  81. (with-temp-buffer
  82. (set-visited-file-name "org-loaddefs.el")
  83. (insert ";;; org-loaddefs.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
  84. (let ((files (directory-files default-directory
  85. nil "^\\(org\\|ob\\|ox\\|ol\\|oc\\)\\(-.*\\)?\\.el$")))
  86. (mapc (lambda (f) (generate-file-autoloads f)) files))
  87. (insert "\f\n(provide 'org-loaddefs)\n")
  88. (insert "\f\n;; Local Variables:\n;; version-control: never\n")
  89. (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
  90. (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
  91. (let ((inhibit-read-only t))
  92. (save-buffer))))
  93. (defun org-make-autoloads (&optional compile force)
  94. "Make the files org-loaddefs.el and org-version.el in the install directory.
  95. Finds the install directory by looking for library \"org\".
  96. Optionally byte-compile lisp files in the install directory or
  97. force re-compilation. This function is provided for easier
  98. manual install when the build system can't be used."
  99. (let ((origin default-directory)
  100. (dirlisp (org-find-library-dir "org")))
  101. (unwind-protect
  102. (progn
  103. (cd dirlisp)
  104. (org-fixup)
  105. (org-make-org-version (org-release) (org-git-version))
  106. (org-make-org-loaddefs)
  107. (when compile (byte-recompile-directory dirlisp 0 force)))
  108. (cd origin))))
  109. (defun org-make-autoloads-compile ()
  110. "Call org-make-autoloads with compile argument.
  111. Convenience function for easier invocation from command line."
  112. (org-make-autoloads 'compile nil))
  113. (defun org-make-autoloads-compile-force ()
  114. "Call org-make-autoloads with compile force arguments.
  115. Convenience function for easier invocation from command line."
  116. (org-make-autoloads 'compile 'force))
  117. ;; Internal functions
  118. (defun org-make-local-mk ()
  119. "Internal function for the build system."
  120. (let ((default "mk/default.mk")
  121. (local "local.mk"))
  122. (unwind-protect
  123. (with-temp-buffer
  124. (insert-file-contents default)
  125. (goto-char (point-min))
  126. (when (search-forward "-8<-" nil t)
  127. (forward-line 1)
  128. (delete-region (point-min) (point)))
  129. (when (search-forward "->8-" nil t)
  130. (forward-line 0)
  131. (delete-region (point) (point-max)))
  132. (goto-char (point-min))
  133. (insert "
  134. # Remove \"oldorg:\" to switch to \"all\" as the default target.
  135. # Change \"oldorg:\" to an existing target to make that target the default,
  136. # or define your own target here to become the default target.
  137. oldorg: # do what the old Makefile did by default.
  138. ##----------------------------------------------------------------------
  139. ")
  140. (goto-char (point-max))
  141. (insert "\
  142. # See default.mk for further configuration options.
  143. ")
  144. (let ((inhibit-read-only t))
  145. (write-file local)))
  146. 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))
  158. ;; redefine version functions
  159. (defmacro org-fixup ()
  160. (let* ((origin default-directory)
  161. (dirlisp (org-find-library-dir "org"))
  162. (dirorg (concat dirlisp "../" ))
  163. (dirgit (concat dirorg ".git/" ))
  164. (org-version "N/A-fixup")
  165. (org-git-version "N/A-fixup !!check installation!!"))
  166. (if (and (boundp 'org-fake-release) (stringp org-fake-release)
  167. (boundp 'org-fake-git-version) (stringp org-fake-git-version))
  168. (setq org-version org-fake-release
  169. org-git-version org-fake-git-version)
  170. (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
  171. (setq org-version (org-release)
  172. org-git-version (org-git-version))
  173. (when (and (file-exists-p dirgit)
  174. (executable-find "git"))
  175. (unwind-protect
  176. (progn
  177. (cd dirorg)
  178. (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
  179. (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
  180. (gitd (string-match "\\S-"
  181. (shell-command-to-string "git status -uno --porcelain"))))
  182. (setq org-git-version (concat git6 (when gitd ".dirty") "-git"))
  183. (if (string-match "^release_" git0)
  184. (setq org-version (substring git0 8))
  185. (setq org-version git0))))
  186. (cd origin)))))
  187. (message "org-fixup.el: redefined Org version")
  188. `(progn
  189. (defun org-release () ,org-version)
  190. (defun org-git-version () ,org-git-version))))
  191. (provide 'org-fixup)
  192. ;; Local Variables:
  193. ;; no-byte-compile: t
  194. ;; coding: utf-8
  195. ;; End:
  196. ;;; org-fixup.el ends here