Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / cedet / ede / proj-obj.el
bloba97fc033ead707daa788563e24ee0db6ce559346
1 ;;; ede/proj-obj.el --- EDE Generic Project Object code generation support
3 ;;; Copyright (C) 1998-2000, 2005, 2008-2014 Free Software Foundation,
4 ;;; Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: project, make
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;; Handles a superclass of target types which create object code in
27 ;; and EDE Project file.
29 (eval-when-compile (require 'cl))
30 (require 'ede/proj)
31 (declare-function ede-pmake-varname "ede/pmake")
33 (defvar ede-proj-objectcode-dodependencies nil
34 "Flag specifies to do automatic dependencies.")
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 ede-lex-compiler
47 ede-yacc-compiler
48 ;; More C and C++ compilers, plus
49 ;; fortran or pascal can be added here
51 (availablelinkers :initform '(ede-g++-linker
52 ede-cc-linker
53 ede-ld-linker
54 ede-gfortran-linker
55 ;; Add more linker thingies here.
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.
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.")
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.")
83 ;;; C/C++ Compilers and Linkers
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.")
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 $<"
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.")
116 (defvar ede-cc-linker
117 (ede-linker
118 "ede-cc-linker"
119 :name "cc"
120 :sourcetype '(ede-source-c)
121 :variables '(("C_LINK" . "$(CC) $(CFLAGS) $(LDFLAGS) -L."))
122 :commands '("$(C_LINK) -o $@ $^ $(LDDEPS)")
123 :objectextention "")
124 "Linker for C sourcecode.")
126 (defvar ede-source-c++
127 (ede-sourcecode "ede-source-c++"
128 :name "C++"
129 :sourcepattern "\\.\\(c\\(pp?\\|c\\|xx\\|++\\)\\|C\\\(PP\\)?\\)$"
130 :auxsourcepattern "\\.\\(hpp?\\|hh?\\|hxx\\|H\\)$"
131 :garbagepattern '("*.o" "*.obj" ".deps/*.P" ".lo"))
132 "C++ source code definition.")
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)")
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 $<"
151 :autoconf '("AC_PROG_CXX")
152 :sourcetype '(ede-source-c++)
153 :objectextention ".o"
154 :makedepends t
155 :uselinker t)
156 "Compiler for C sourcecode.")
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++)
164 :variables '(("CXX_LINK" . "$(CXX) $(CFLAGS) $(LDFLAGS) -L."))
165 :commands '("$(CXX_LINK) -o $@ $^ $(LDDEPS)")
166 :autoconf '("AC_PROG_CXX")
167 :objectextention "")
168 "Linker needed for c++ programs.")
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.")
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.")
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.")
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.")
202 ;;; Fortran Compiler/Linker
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.")
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.")
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 $<"
237 :sourcetype '(ede-source-f90 ede-source-f77)
238 :objectextention ".o"
239 :makedepends t
240 :uselinker t)
241 "Compiler for Fortran sourcecode.")
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.")
254 (defvar ede-gfortran-linker
255 (ede-linker
256 "ede-gfortran-linker"
257 :name "gfortran"
258 :sourcetype '(ede-source-f90 ede-source-f77)
259 :variables '(("F90_LINK" . "$(F90) $(CFLAGS) $(LDFLAGS) -L."))
260 :commands '("$(F90_LINK) -o $@ $^")
261 :objectextention "")
262 "Linker needed for Fortran programs.")
264 ;;; Generic Linker
266 (defvar ede-ld-linker
267 (ede-linker
268 "ede-ld-linker"
269 :name "ld"
270 :variables '(("LD" . "ld")
271 ("LD_LINK" . "$(LD) $(LDFLAGS) -L."))
272 :commands '("$(LD_LINK) -o $@ $^ $(LDDEPS)")
273 :objectextention "")
274 "Linker needed for c++ programs.")
276 ;;; The EDE object compiler
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")))))
290 ;;; EDE Object target type methods
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"))
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)))
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)))
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))))
321 (provide 'ede/proj-obj)
323 ;;; ede/proj-obj.el ends here