org-fixup.el 6.9 KB

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