org-fixup.el 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.
  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-manuals ()
  27. "Generate the Texinfo files out of Org manuals."
  28. (require 'ox-texinfo)
  29. (dolist (manual '("../doc/org-manual.org" "../doc/org-guide.org"))
  30. (find-file manual)
  31. (org-texinfo-export-to-texinfo)))
  32. (defun org-make-org-version (org-release org-git-version)
  33. "Make the file org-version.el in the current directory.
  34. This function is internally used by the build system and should
  35. be used by foreign build systems or installers to produce this
  36. file in the installation directory of Org mode. Org will not
  37. work correctly if this file is not present (except directly from
  38. the Git work tree)."
  39. (with-temp-buffer
  40. (insert "\
  41. ;;; org-version.el --- autogenerated file, do not edit
  42. ;;
  43. ;;; Code:
  44. ;;;\#\#\#autoload
  45. \(defun org-release ()
  46. \"The release version of Org.
  47. Inserted by installing Org mode or when a release is made.\"
  48. (let ((org-release \"" org-release "\"))
  49. org-release))
  50. ;;;\#\#\#autoload
  51. \(defun org-git-version ()
  52. \"The Git version of Org mode.
  53. Inserted by installing Org or when a release is made.\"
  54. (let ((org-git-version \"" org-git-version "\"))
  55. org-git-version))
  56. \f\n\(provide 'org-version\)
  57. \f\n;; Local Variables:\n;; version-control: never
  58. ;; no-byte-compile: t
  59. ;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
  60. (let ((inhibit-read-only t))
  61. (write-file "org-version.el"))))
  62. (defun org-make-org-loaddefs ()
  63. "Make the file org-loaddefs.el in the current directory.
  64. This function is internally used by the build system and should
  65. be used by foreign build systems or installers to produce this
  66. file in the installation directory of Org mode. Org will not
  67. work correctly if this file is not up-to-date."
  68. (with-temp-buffer
  69. (set-visited-file-name "org-loaddefs.el")
  70. (insert ";;; org-loaddefs.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
  71. (let ((files (directory-files default-directory
  72. nil "^\\(org\\|ob\\|ox\\)\\(-.*\\)?\\.el$")))
  73. (mapc (lambda (f) (generate-file-autoloads f)) files))
  74. (insert "\f\n(provide 'org-loaddefs)\n")
  75. (insert "\f\n;; Local Variables:\n;; version-control: never\n")
  76. (insert ";; no-byte-compile: t\n;; no-update-autoloads: t\n")
  77. (insert ";; coding: utf-8\n;; End:\n;;; org-loaddefs.el ends here\n")
  78. (let ((inhibit-read-only t))
  79. (save-buffer))))
  80. (defun org-make-autoloads (&optional compile force)
  81. "Make the files org-loaddefs.el and org-version.el in the install directory.
  82. Finds the install directory by looking for library \"org\".
  83. Optionally byte-compile lisp files in the install directory or
  84. force re-compilation. This function is provided for easier
  85. manual install when the build system can't be used."
  86. (let ((origin default-directory)
  87. (dirlisp (org-find-library-dir "org")))
  88. (unwind-protect
  89. (progn
  90. (cd dirlisp)
  91. (org-fixup)
  92. (org-make-org-version (org-release) (org-git-version))
  93. (org-make-org-loaddefs)
  94. (when compile (byte-recompile-directory dirlisp 0 force)))
  95. (cd origin))))
  96. (defun org-make-autoloads-compile ()
  97. "Call org-make-autoloads with compile argument.
  98. Convenience function for easier invocation from command line."
  99. (org-make-autoloads 'compile nil))
  100. (defun org-make-autoloads-compile-force ()
  101. "Call org-make-autoloads with compile force arguments.
  102. Convenience function for easier invocation from command line."
  103. (org-make-autoloads 'compile 'force))
  104. ;; 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.
  125. ##----------------------------------------------------------------------
  126. ")
  127. (goto-char (point-max))
  128. (insert "\
  129. # See default.mk for further configuration options.
  130. ")
  131. (let ((inhibit-read-only t))
  132. (write-file local)))
  133. nil)))
  134. (defun org-make-letterformat (a4name lettername)
  135. "Internal function for the build system."
  136. (unwind-protect
  137. (with-temp-buffer
  138. (insert-file-contents a4name)
  139. (goto-char (point-min))
  140. (while (search-forward "\\pdflayout=(0l)" nil t)
  141. (replace-match "\\pdflayout=(1l)" nil t))
  142. (let ((inhibit-read-only t))
  143. (write-file lettername)))
  144. nil))
  145. ;; redefine version functions
  146. (defmacro org-fixup ()
  147. (let* ((origin default-directory)
  148. (dirlisp (org-find-library-dir "org"))
  149. (dirorg (concat dirlisp "../" ))
  150. (dirgit (concat dirorg ".git/" ))
  151. (org-version "N/A-fixup")
  152. (org-git-version "N/A-fixup !!check installation!!"))
  153. (if (and (boundp 'org-fake-release) (stringp org-fake-release)
  154. (boundp 'org-fake-git-version) (stringp org-fake-git-version))
  155. (setq org-version org-fake-release
  156. org-git-version org-fake-git-version)
  157. (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix)
  158. (setq org-version (org-release)
  159. org-git-version (org-git-version))
  160. (when (and (file-exists-p dirgit)
  161. (executable-find "git"))
  162. (unwind-protect
  163. (progn
  164. (cd dirorg)
  165. (let ((git6 (substring (shell-command-to-string "git describe --abbrev=6 HEAD") 0 -1))
  166. (git0 (substring (shell-command-to-string "git describe --abbrev=0 HEAD") 0 -1))
  167. (gitd (string-match "\\S-"
  168. (shell-command-to-string "git status -uno --porcelain"))))
  169. (setq org-git-version (concat git6 (when gitd ".dirty") "-git"))
  170. (if (string-match "^release_" git0)
  171. (setq org-version (substring git0 8))
  172. (setq org-version git0))))
  173. (cd origin)))))
  174. (message "org-fixup.el: redefined Org version")
  175. `(progn
  176. (defun org-release () ,org-version)
  177. (defun org-git-version () ,org-git-version))))
  178. (provide 'org-fixup)
  179. ;; Local Variables:
  180. ;; no-byte-compile: t
  181. ;; coding: utf-8
  182. ;; End:
  183. ;;; org-fixup.el ends here