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