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