proj-prog.el 4.7 KB

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