Commit | Line | Data |
---|---|---|
acc33231 CY |
1 | ;;; ede/proj-obj.el --- EDE Generic Project Object code generation support |
2 | ||
114f9c96 | 3 | ;;; Copyright (C) 1998, 1999, 2000, 2005, 2008, 2009, 2010 |
acc33231 CY |
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 | ;; | |
4706ff89 | 26 | ;; Handles a superclass of target types which create object code in |
acc33231 CY |
27 | ;; and EDE Project file. |
28 | ||
67d3ffe4 | 29 | (eval-when-compile (require 'cl)) |
acc33231 CY |
30 | (require 'ede/proj) |
31 | (declare-function ede-pmake-varname "ede/pmake") | |
32 | ||
33 | (defvar ede-proj-objectcode-dodependencies nil | |
34 | "Flag specifies to do automatic dependencies.") | |
35 | ||
36 | ;;; Code: | |
37 | (defclass ede-proj-target-makefile-objectcode (ede-proj-target-makefile) | |
38 | (;; Give this a new default | |
39 | (configuration-variables :initform ("debug" . (("CFLAGS" . "-g") | |
40 | ("LDFLAGS" . "-g")))) | |
41 | ;; @TODO - add an include path. | |
42 | (availablecompilers :initform (ede-gcc-compiler | |
43 | ede-g++-compiler | |
44 | ede-gfortran-compiler | |
45 | ede-gfortran-module-compiler | |
46 | ;; More C and C++ compilers, plus | |
47 | ;; fortran or pascal can be added here | |
48 | )) | |
49 | (availablelinkers :initform (ede-g++-linker | |
67d3ffe4 | 50 | ede-cc-linker |
acc33231 | 51 | ede-gfortran-linker |
a6b98754 CY |
52 | ede-ld-linker |
53 | ;; Add more linker thingies here. | |
acc33231 CY |
54 | )) |
55 | (sourcetype :initform (ede-source-c | |
56 | ede-source-c++ | |
57 | ede-source-f77 | |
58 | ede-source-f90 | |
59 | ;; ede-source-other | |
60 | ;; This object should take everything that | |
61 | ;; gets compiled into objects like fortran | |
62 | ;; and pascal. | |
63 | )) | |
64 | ) | |
65 | "Abstract class for Makefile based object code generating targets. | |
66 | Belonging to this group assumes you could make a .o from an element source | |
67 | file.") | |
68 | ||
69 | (defclass ede-object-compiler (ede-compiler) | |
70 | ((uselinker :initform t) | |
71 | (dependencyvar :initarg :dependencyvar | |
72 | :type list | |
73 | :custom (cons (string :tag "Variable") | |
74 | (string :tag "Value")) | |
75 | :documentation | |
76 | "A variable dedicated to dependency generation.")) | |
77 | "Ede compiler class for source which must compiler, and link.") | |
78 | ||
79 | ;;; C/C++ Compilers and Linkers | |
80 | ;; | |
81 | (defvar ede-source-c | |
82 | (ede-sourcecode "ede-source-c" | |
83 | :name "C" | |
84 | :sourcepattern "\\.c$" | |
85 | :auxsourcepattern "\\.h$" | |
86 | :garbagepattern '("*.o" "*.obj" ".deps/*.P" ".lo")) | |
87 | "C source code definition.") | |
88 | ||
89 | (defvar ede-gcc-compiler | |
90 | (ede-object-compiler | |
91 | "ede-c-compiler-gcc" | |
92 | :name "gcc" | |
93 | :dependencyvar '("C_DEPENDENCIES" . "-Wp,-MD,.deps/$(*F).P") | |
94 | :variables '(("CC" . "gcc") | |
95 | ("C_COMPILE" . | |
96 | "$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)")) | |
97 | :rules (list (ede-makefile-rule | |
98 | "c-inference-rule" | |
99 | :target "%.o" | |
100 | :dependencies "%.c" | |
101 | :rules '("@echo '$(C_COMPILE) -c $<'; \\" | |
102 | "$(C_COMPILE) $(C_DEPENDENCIES) -o $@ -c $<" | |
103 | ) | |
104 | )) | |
105 | :autoconf '("AC_PROG_CC" "AC_PROG_GCC_TRADITIONAL") | |
106 | :sourcetype '(ede-source-c) | |
107 | :objectextention ".o" | |
108 | :makedepends t | |
109 | :uselinker t) | |
110 | "Compiler for C sourcecode.") | |
111 | ||
67d3ffe4 | 112 | (defvar ede-cc-linker |
a6b98754 | 113 | (ede-linker |
67d3ffe4 CY |
114 | "ede-cc-linker" |
115 | :name "cc" | |
a6b98754 CY |
116 | :sourcetype '(ede-source-c) |
117 | :variables '(("C_LINK" . "$(CC) $(CFLAGS) $(LDFLAGS) -L.")) | |
118 | :commands '("$(C_LINK) -o $@ $^") | |
119 | :objectextention "") | |
120 | "Linker for C sourcecode.") | |
121 | ||
acc33231 CY |
122 | (defvar ede-source-c++ |
123 | (ede-sourcecode "ede-source-c++" | |
124 | :name "C++" | |
125 | :sourcepattern "\\.\\(cpp\\|cc\\|cxx\\)$" | |
126 | :auxsourcepattern "\\.\\(hpp\\|hh?\\|hxx\\)$" | |
127 | :garbagepattern '("*.o" "*.obj" ".deps/*.P" ".lo")) | |
128 | "C++ source code definition.") | |
129 | ||
130 | (defvar ede-g++-compiler | |
131 | (ede-object-compiler | |
132 | "ede-c-compiler-g++" | |
133 | :name "g++" | |
134 | :dependencyvar '("CXX_DEPENDENCIES" . "-Wp,-MD,.deps/$(*F).P") | |
135 | :variables '(("CXX" "g++") | |
136 | ("CXX_COMPILE" . | |
137 | "$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)") | |
138 | ) | |
139 | :rules (list (ede-makefile-rule | |
140 | "c++-inference-rule" | |
141 | :target "%.o" | |
142 | :dependencies "%.cpp" | |
143 | :rules '("@echo '$(CXX_COMPILE) -c $<'; \\" | |
144 | "$(CXX_COMPILE) $(CXX_DEPENDENCIES) -o $@ -c $<" | |
145 | ) | |
146 | )) | |
147 | :autoconf '("AC_PROG_CXX") | |
148 | :sourcetype '(ede-source-c++) | |
149 | :objectextention ".o" | |
150 | :makedepends t | |
151 | :uselinker t) | |
152 | "Compiler for C sourcecode.") | |
153 | ||
154 | (defvar ede-g++-linker | |
155 | (ede-linker | |
156 | "ede-g++-linker" | |
157 | :name "g++" | |
158 | ;; Only use this linker when c++ exists. | |
159 | :sourcetype '(ede-source-c++) | |
a6b98754 CY |
160 | :variables '(("CXX_LINK" . "$(CXX) $(CFLAGS) $(LDFLAGS) -L.")) |
161 | :commands '("$(CXX_LINK) -o $@ $^") | |
acc33231 CY |
162 | :autoconf '("AC_PROG_CXX") |
163 | :objectextention "") | |
164 | "Linker needed for c++ programs.") | |
165 | ||
166 | ;;; Fortran Compiler/Linker | |
167 | ;; | |
168 | ;; Contributed by David Engster | |
169 | (defvar ede-source-f90 | |
170 | (ede-sourcecode "ede-source-f90" | |
171 | :name "Fortran 90/95" | |
172 | :sourcepattern "\\.[fF]9[05]$" | |
173 | :auxsourcepattern "\\.incf$" | |
174 | :garbagepattern '("*.o" "*.mod" ".deps/*.P")) | |
175 | "Fortran 90/95 source code definition.") | |
176 | ||
177 | (defvar ede-source-f77 | |
178 | (ede-sourcecode "ede-source-f77" | |
179 | :name "Fortran 77" | |
180 | :sourcepattern "\\.\\([fF]\\|for\\)$" | |
181 | :auxsourcepattern "\\.incf$" | |
182 | :garbagepattern '("*.o" ".deps/*.P")) | |
183 | "Fortran 77 source code definition.") | |
184 | ||
185 | (defvar ede-gfortran-compiler | |
186 | (ede-object-compiler | |
187 | "ede-f90-compiler-gfortran" | |
188 | :name "gfortran" | |
189 | :dependencyvar '("F90_DEPENDENCIES" . "-Wp,-MD,.deps/$(*F).P") | |
190 | :variables '(("F90" . "gfortran") | |
191 | ("F90_COMPILE" . | |
192 | "$(F90) $(DEFS) $(INCLUDES) $(F90FLAGS)")) | |
193 | :rules (list (ede-makefile-rule | |
194 | "f90-inference-rule" | |
195 | :target "%.o" | |
196 | :dependencies "%.f90" | |
197 | :rules '("@echo '$(F90_COMPILE) -c $<'; \\" | |
198 | "$(F90_COMPILE) $(F90_DEPENDENCIES) -o $@ -c $<" | |
199 | ) | |
200 | )) | |
201 | :sourcetype '(ede-source-f90 ede-source-f77) | |
202 | :objectextention ".o" | |
203 | :makedepends t | |
204 | :uselinker t) | |
205 | "Compiler for Fortran sourcecode.") | |
206 | ||
207 | (defvar ede-gfortran-module-compiler | |
208 | (clone ede-gfortran-compiler | |
209 | "ede-f90-module-compiler-gfortran" | |
210 | :name "gfortranmod" | |
211 | :sourcetype '(ede-source-f90) | |
212 | :commands '("$(F90_COMPILE) -c $^") | |
213 | :objectextention ".mod" | |
214 | :uselinker nil) | |
215 | "Compiler for Fortran 90/95 modules.") | |
216 | ||
217 | ||
218 | (defvar ede-gfortran-linker | |
219 | (ede-linker | |
220 | "ede-gfortran-linker" | |
221 | :name "gfortran" | |
222 | :sourcetype '(ede-source-f90 ede-source-f77) | |
a6b98754 CY |
223 | :variables '(("F90_LINK" . "$(F90) $(CFLAGS) $(LDFLAGS) -L.")) |
224 | :commands '("$(F90_LINK) -o $@ $^") | |
acc33231 CY |
225 | :objectextention "") |
226 | "Linker needed for Fortran programs.") | |
227 | ||
228 | ;;; Generic Linker | |
229 | ;; | |
230 | (defvar ede-ld-linker | |
231 | (ede-linker | |
232 | "ede-ld-linker" | |
233 | :name "ld" | |
234 | :variables '(("LD" . "ld") | |
a6b98754 CY |
235 | ("LD_LINK" . "$(LD) $(LDFLAGS) -L.")) |
236 | :commands '("$(LD_LINK) -o $@ $^") | |
acc33231 CY |
237 | :objectextention "") |
238 | "Linker needed for c++ programs.") | |
239 | ||
240 | ;;; The EDE object compiler | |
241 | ;; | |
242 | (defmethod ede-proj-makefile-insert-variables ((this ede-object-compiler)) | |
243 | "Insert variables needed by the compiler THIS." | |
244 | (call-next-method) | |
245 | (if (eieio-instance-inheritor-slot-boundp this 'dependencyvar) | |
246 | (with-slots (dependencyvar) this | |
247 | (insert (car dependencyvar) "=") | |
248 | (let ((cd (cdr dependencyvar))) | |
249 | (if (listp cd) | |
250 | (mapc (lambda (c) (insert " " c)) cd) | |
251 | (insert cd)) | |
252 | (insert "\n"))))) | |
253 | ||
254 | ;;; EDE Object target type methods | |
255 | ;; | |
256 | (defmethod ede-proj-makefile-sourcevar | |
257 | ((this ede-proj-target-makefile-objectcode)) | |
258 | "Return the variable name for THIS's sources." | |
259 | (require 'ede/pmake) | |
260 | (concat (ede-pmake-varname this) "_SOURCES")) | |
261 | ||
262 | (defmethod ede-proj-makefile-dependency-files | |
263 | ((this ede-proj-target-makefile-objectcode)) | |
264 | "Return a list of source files to convert to dependencies. | |
265 | Argument THIS is the target to get sources from." | |
266 | (append (oref this source) (oref this auxsource))) | |
267 | ||
268 | (defmethod ede-proj-makefile-insert-variables ((this ede-proj-target-makefile-objectcode) | |
269 | &optional moresource) | |
270 | "Insert variables needed by target THIS. | |
271 | Optional argument MORESOURCE is not used." | |
272 | (let ((ede-proj-objectcode-dodependencies | |
273 | (oref (ede-target-parent this) automatic-dependencies))) | |
274 | (call-next-method))) | |
275 | ||
276 | (defmethod ede-buffer-header-file((this ede-proj-target-makefile-objectcode) | |
277 | buffer) | |
278 | "There are no default header files." | |
279 | (or (call-next-method) | |
280 | ;; Ok, nothing obvious. Try looking in ourselves. | |
281 | (let ((h (oref this auxsource))) | |
282 | ;; Add more logic here when the problem is better understood. | |
283 | (car-safe h)))) | |
284 | ||
285 | (provide 'ede/proj-obj) | |
286 | ||
3999968a | 287 | ;; arch-tag: f521b89f-1a3f-4910-ba81-65de3f421698 |
acc33231 | 288 | ;;; ede/proj-obj.el ends here |