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