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