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