* progmodes/sh-script.el (sh-mode): Use define-derived-mode.
[bpt/emacs.git] / lisp / cedet / ede / proj-prog.el
1 ;;; ede-proj-prog.el --- EDE Generic Project program support
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2005, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: project, make
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Commentary:
25 ;;
26 ;; Handle building programs from object files in and EDE Project file.
27
28 (eval-when-compile (require 'cl))
29 (require 'ede/pmake)
30 (require 'ede/proj-obj)
31
32 (declare-function ede-shell-run-something "ede/shell")
33
34 ;;; Code:
35 (defclass ede-proj-target-makefile-program
36 (ede-proj-target-makefile-objectcode)
37 ((ldlibs :initarg :ldlibs
38 :initform nil
39 :type list
40 :custom (repeat (string :tag "Library"))
41 :documentation
42 "Libraries, such as \"m\" or \"Xt\" which this program depends on.
43 The linker flag \"-l\" is automatically prepended. Do not include a \"lib\"
44 prefix, or a \".so\" suffix.
45
46 Note: Currently only used for Automake projects."
47 )
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 ldlibs to add addition libraries. Use this to specify specific
55 options to the linker.
56
57 Note: Not currently used. This bug needs to be fixed.")
58 )
59 "This target is an executable program.")
60
61 (defmethod ede-proj-makefile-insert-automake-pre-variables
62 ((this ede-proj-target-makefile-program))
63 "Insert bin_PROGRAMS variables needed by target THIS."
64 (ede-pmake-insert-variable-shared "bin_PROGRAMS"
65 (insert (ede-name this)))
66 (call-next-method))
67
68 (defmethod ede-proj-makefile-insert-automake-post-variables
69 ((this ede-proj-target-makefile-program))
70 "Insert bin_PROGRAMS variables needed by target THIS."
71 (ede-pmake-insert-variable-shared
72 (concat (ede-name this) "_LDADD")
73 (mapc (lambda (c) (insert " -l" c)) (oref this ldlibs)))
74 ;; For other targets THIS depends on
75 ;;
76 ;; NOTE: FIX THIS
77 ;;
78 ;;(ede-pmake-insert-variable-shared
79 ;; (concat (ede-name this) "_DEPENDENCIES")
80 ;; (mapcar (lambda (d) (insert d)) (oref this FOOOOOOOO)))
81 (call-next-method))
82
83 (defmethod ede-proj-makefile-insert-rules ((this ede-proj-target-makefile-program))
84 "Insert rules needed by THIS target."
85 (let ((ede-proj-compiler-object-linkflags
86 (mapconcat 'identity (oref this ldflags) " ")))
87 (with-slots (ldlibs) this
88 (if ldlibs
89 (setq ede-proj-compiler-object-linkflags
90 (concat ede-proj-compiler-object-linkflags
91 " -l"
92 (mapconcat 'identity ldlibs " -l")))))
93 (call-next-method)))
94
95 (defmethod project-debug-target ((obj ede-proj-target-makefile-program))
96 "Debug a program target OBJ."
97 (let ((tb (get-buffer-create " *padt*"))
98 (dd (if (not (string= (oref obj path) ""))
99 (oref obj path)
100 default-directory))
101 (cmd nil))
102 (unwind-protect
103 (progn
104 (set-buffer tb)
105 (setq default-directory dd)
106 (setq cmd (read-from-minibuffer
107 "Run (like this): "
108 (concat (symbol-name ede-debug-program-function)
109 " " (ede-target-name obj))))
110 (funcall ede-debug-program-function cmd))
111 (kill-buffer tb))))
112
113 (defmethod project-run-target ((obj ede-proj-target-makefile-program) &optional command)
114 "Run a program target OBJ.
115 Optional COMMAND is the command to run in place of asking the user."
116 (require 'ede/shell)
117 (let ((tb (get-buffer-create " *padt*"))
118 (dd (if (not (string= (oref obj path) ""))
119 (oref obj path)
120 default-directory))
121 (cmd nil))
122 (unwind-protect
123 (progn
124 (set-buffer tb)
125 (setq default-directory dd)
126 (setq cmd (or command
127 (read-from-minibuffer
128 "Run (like this): "
129 (concat "./" (ede-target-name obj)))))
130 (ede-shell-run-something obj cmd)
131 )
132 (kill-buffer tb))))
133
134 (provide 'ede/proj-prog)
135
136 ;; arch-tag: 0bfa9364-f385-4745-a846-462146a79a25
137 ;;; ede/proj-prog.el ends here