proj-prog.el 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ;;; ede-proj-prog.el --- EDE Generic Project program support
  2. ;; Copyright (C) 1998-2001, 2005, 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: project, make
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; Handle building programs from object files in and EDE Project file.
  19. (eval-when-compile (require 'cl))
  20. (require 'ede/pmake)
  21. (require 'ede/proj-obj)
  22. (declare-function ede-shell-run-something "ede/shell")
  23. ;;; Code:
  24. (defclass ede-proj-target-makefile-program
  25. (ede-proj-target-makefile-objectcode)
  26. ((ldlibs-local :initarg :ldlibs-local
  27. :initform nil
  28. :type list
  29. :custom (repeat (string :tag "Local Library"))
  30. :documentation
  31. "Libraries that are part of this project.
  32. The full path to these libraries should be specified, such as:
  33. ../lib/libMylib.la or ../ar/myArchive.a
  34. Note: Currently only used for Automake projects."
  35. )
  36. (ldflags :initarg :ldflags
  37. :initform nil
  38. :type list
  39. :custom (repeat (string :tag "Link Flag"))
  40. :documentation
  41. "Additional flags to add when linking this target.
  42. Use this to specify specific options to the linker.
  43. A Common use may be to add -L to specify in-project locations of libraries
  44. specified with ldlibs.")
  45. (ldlibs :initarg :ldlibs
  46. :initform nil
  47. :type list
  48. :custom (repeat (string :tag "Library"))
  49. :documentation
  50. "Libraries, such as \"m\" or \"Xt\" which this program depends on.
  51. The linker flag \"-l\" is automatically prepended. Do not include a \"lib\"
  52. prefix, or a \".so\" suffix.
  53. Use the 'ldflags' slot to specify where in-project libraries might be.
  54. Note: Currently only used for Automake projects."
  55. )
  56. )
  57. "This target is an executable program.")
  58. (defmethod ede-proj-makefile-insert-automake-pre-variables
  59. ((this ede-proj-target-makefile-program))
  60. "Insert bin_PROGRAMS variables needed by target THIS."
  61. (ede-pmake-insert-variable-shared "bin_PROGRAMS"
  62. (insert (ede-name this)))
  63. (call-next-method))
  64. (defmethod ede-proj-makefile-insert-automake-post-variables
  65. ((this ede-proj-target-makefile-program))
  66. "Insert bin_PROGRAMS variables needed by target THIS."
  67. (ede-pmake-insert-variable-shared
  68. (concat (ede-name this) "_LDADD")
  69. (mapc (lambda (l) (insert " " l)) (oref this ldlibs-local))
  70. (mapc (lambda (c) (insert " " c)) (oref this ldflags))
  71. (when (oref this ldlibs)
  72. (mapc (lambda (d) (insert " -l" d)) (oref this ldlibs)))
  73. )
  74. (call-next-method))
  75. (defmethod ede-proj-makefile-insert-variables ((this ede-proj-target-makefile-program))
  76. "Insert variables needed by the compiler THIS."
  77. (call-next-method)
  78. (let ((lf (mapconcat 'identity (oref this ldflags) " ")))
  79. (with-slots (ldlibs) this
  80. (if ldlibs
  81. (setq lf
  82. (concat lf " -l" (mapconcat 'identity ldlibs " -l")))))
  83. ;; LDFLAGS as needed.
  84. (when (and lf (not (string= "" lf)))
  85. (ede-pmake-insert-variable-once "LDDEPS" (insert lf)))))
  86. (defmethod project-debug-target ((obj ede-proj-target-makefile-program))
  87. "Debug a program target OBJ."
  88. (let ((tb (get-buffer-create " *padt*"))
  89. (dd (if (not (string= (oref obj path) ""))
  90. (oref obj path)
  91. default-directory))
  92. (cmd nil))
  93. (unwind-protect
  94. (progn
  95. (set-buffer tb)
  96. (setq default-directory dd)
  97. (setq cmd (read-from-minibuffer
  98. "Run (like this): "
  99. (concat (symbol-name ede-debug-program-function)
  100. " " (ede-target-name obj))))
  101. (funcall ede-debug-program-function cmd))
  102. (kill-buffer tb))))
  103. (defmethod project-run-target ((obj ede-proj-target-makefile-program) &optional command)
  104. "Run a program target OBJ.
  105. Optional COMMAND is the command to run in place of asking the user."
  106. (require 'ede/shell)
  107. (let ((tb (get-buffer-create " *padt*"))
  108. (dd (if (not (string= (oref obj path) ""))
  109. (oref obj path)
  110. default-directory))
  111. (cmd nil))
  112. (unwind-protect
  113. (progn
  114. (set-buffer tb)
  115. (setq default-directory dd)
  116. (setq cmd (or command
  117. (read-from-minibuffer
  118. "Run (like this): "
  119. (concat "./" (ede-target-name obj)))))
  120. (ede-shell-run-something obj cmd)
  121. )
  122. (kill-buffer tb))))
  123. (provide 'ede/proj-prog)
  124. ;;; ede/proj-prog.el ends here