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