Initial Commit
[packages] / xemacs-packages / ede / ede-proj-obj.el
1 ;;; ede-proj-obj.el --- EDE Generic Project Object code generation support
2
3 ;;;  Copyright (C) 1998, 1999, 2000, 2005  Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; RCS: $Id: ede-proj-obj.el,v 1.1 2007-11-26 15:22:09 michaels Exp $
8
9 ;; This software is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This software is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25 ;;
26 ;; Handles a supperclass of target types which create object code in
27 ;; and EDE Project file.
28
29 (require 'ede-proj)
30 ;; (require 'ede-pmake)
31 ;; The above require is needed for ede-pmake-varname, but introduces
32 ;; a circular dependency.  Leave it be.
33
34 (defvar ede-proj-objectcode-dodependencies nil
35   "Flag specifies to do automatic dependencies.")
36
37 ;;; Code:
38 (defclass ede-proj-target-makefile-objectcode (ede-proj-target-makefile)
39   (;; Give this a new default
40    (configuration-variables :initform ("debug" . (("CFLAGS" . "-g")
41                                                   ("LDFLAGS" . "-g"))))
42    (availablecompilers :initform (ede-gcc-compiler
43                                   ede-g++-compiler
44                                   ;; More C and C++ compilers, plus
45                                   ;; fortran or pascal can be added here
46                                   ))
47    (availablelinkers :initform (ede-g++-linker
48                                 ;; Add more linker thingies here.
49                                 ede-ld-linker
50                                 ))
51    (sourcetype :initform (ede-source-c 
52                           ede-source-c++
53                           ;; ede-source-other
54                           ;; This object should take everything that
55                           ;; gets compiled into objects like fortran
56                           ;; and pascal.
57                           ))
58    )
59   "Abstract class for Makefile based object code generating targets.
60 Belonging to this group assumes you could make a .o from an element source
61 file.")
62
63 (defclass ede-object-compiler (ede-compiler)
64   ((uselinker :initform t)
65    (dependencyvar :initarg :dependencyvar
66                   :type list
67                   :custom (cons (string :tag "Variable")
68                                 (string :tag "Value"))
69                   :documentation
70                   "A variable dedicated to dependency generation."))
71   "Ede compiler class for source which must compiler, and link.")
72
73 (defvar ede-source-c
74   (ede-sourcecode "ede-source-c"
75                   :name "C"
76                   :sourcepattern "\\.c$"
77                   :auxsourcepattern "\\.h$"
78                   :garbagepattern '("*.o" "*.obj" ".deps/*.P" ".lo"))
79   "C source code definition.")
80
81 (defvar ede-gcc-compiler
82   (ede-object-compiler
83    "ede-c-compiler-gcc"
84    :name "gcc"
85    :dependencyvar '("C_DEPENDENCIES" . "-Wp,-MD,.deps/$(*F).P")
86    :variables '(("CC" . "gcc")
87                 ("C_COMPILE" .
88                  "$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)"))
89    :rules (list (ede-makefile-rule
90                  "c-inference-rule"
91                  :target "%.o"
92                  :dependencies "%.c"
93                  :rules '("@echo '$(C_COMPILE) -c $<'; \\"
94                           "$(C_COMPILE) $(C_DEPENDENCIES) -o $@ -c $<"
95                           )
96                  ))
97    :autoconf '("AC_PROG_CC" "AC_PROG_GCC_TRADITIONAL")
98    :sourcetype '(ede-source-c)
99    :objectextention ".o"
100    :makedepends t
101    :uselinker t)
102   "Compiler for C sourcecode.")
103
104 (defvar ede-source-c++
105   (ede-sourcecode "ede-source-c++"
106                   :name "C++"
107                   :sourcepattern "\\.cpp$"
108                   :auxsourcepattern "\\.hpp$"
109                   :garbagepattern '("*.o" "*.obj" ".deps/*.P" ".lo"))
110   "C++ source code definition.")
111
112 (defvar ede-g++-compiler
113   (ede-object-compiler
114    "ede-c-compiler-g++"
115    :name "g++"
116    :dependencyvar '("CXX_DEPENDENCIES" . "-Wp,-MD,.deps/$(*F).P")
117    :variables '(("CXX" "g++")
118                 ("CXX_COMPILE" .
119                  "$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)")
120                 )
121    :rules (list (ede-makefile-rule
122                  "c++-inference-rule"
123                  :target "%.o"
124                  :dependencies "%.cpp"
125                  :rules '("@echo '$(CXX_COMPILE) -c $<'; \\"
126                           "$(CXX_COMPILE) $(CXX_DEPENDENCIES) -o $@ -c $<"
127                           )
128                  ))
129    :autoconf '("AC_PROG_CXX")
130    :sourcetype '(ede-source-c++)
131    :objectextention ".o"
132    :makedepends t
133    :uselinker t)
134   "Compiler for C sourcecode.")
135
136 (defvar ede-g++-linker
137   (ede-linker
138    "ede-g++-linker"
139    :name "g++"
140    ;; Only use this linker when c++ exists.
141    :sourcetype '(ede-source-c++)
142    :variables  '(("CXX_LINK" .
143                   "$(CXX) $(CFLAGS) $(LDFLAGS) -L. -o $@")
144                  )
145    :commands '("$(CXX_LINK) $^")
146    :autoconf '("AC_PROG_CXX")
147    :objectextention "")
148   "Linker needed for c++ programs.")
149
150 (defvar ede-ld-linker
151   (ede-linker
152    "ede-ld-linker"
153    :name "ld"
154    :variables  '(("LD" . "ld")
155                  ("LD_LINK" .
156                   "$(LD) $(LDFLAGS) -L. -o $@")
157                  )
158    :commands '("$(LD_LINK) $^")
159    :objectextention "")
160   "Linker needed for c++ programs.")
161
162 ;;; The EDE object compiler
163 ;;
164 (defmethod ede-proj-makefile-insert-variables ((this ede-object-compiler))
165   "Insert variables needed by the compiler THIS."
166   (call-next-method)
167   (if (slot-boundp this 'dependencyvar)
168       (with-slots (dependencyvar) this
169           (insert (car dependencyvar) "=")
170           (let ((cd (cdr dependencyvar)))
171             (if (listp cd)
172                 (mapc (lambda (c) (insert " " c)) cd)
173               (insert cd))
174             (insert "\n")))))
175
176 ;;; EDE Object target type methods
177 ;;
178 (defmethod ede-proj-makefile-sourcevar
179   ((this ede-proj-target-makefile-objectcode))
180   "Return the variable name for THIS's sources."
181   (concat (ede-pmake-varname this) "_SOURCES"))
182
183 (defmethod ede-proj-makefile-dependency-files
184   ((this ede-proj-target-makefile-objectcode))
185   "Return a list of source files to convert to dependencies.
186 Argument THIS is the target to get sources from."
187   (append (oref this source) (oref this auxsource)))
188
189 (defmethod ede-proj-makefile-insert-variables ((this ede-proj-target-makefile-objectcode)
190                                                &optional moresource)
191   "Insert variables needed by target THIS.
192 Optional argument MORESOURCE is not used."
193   (let ((ede-proj-objectcode-dodependencies
194          (oref (ede-target-parent this) automatic-dependencies)))
195     (call-next-method)))
196
197 (defmethod ede-buffer-header-file((this ede-proj-target-makefile-objectcode)
198                                   buffer)
199   "There are no default header files."
200   (or (call-next-method)
201       ;; Ok, nothing obvious. Try looking in ourselves.
202       (let ((h (oref this auxsource)))
203         ;; Add more logic here when the problem is better understood.
204         (car-safe h))))
205
206 (provide 'ede-proj-obj)
207
208 ;;; ede-proj-obj.el ends here