Initial Commit
[packages] / xemacs-packages / ede / ede-source.el
1 ;;; ede-source.el --- EDE source code object
2
3 ;;;  Copyright (C) 2000  Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; RCS: $Id: ede-source.el,v 1.1 2007-11-26 15:22:11 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 ;; Manage different types of source code.  A master list of source code types
27 ;; will be maintained, and used to track target objects, what they accept,
28 ;; and what compilers can be used.
29
30 (require 'eieio-base)
31
32 ;;; Code:
33 (defclass ede-sourcecode (eieio-instance-inheritor)
34   ((name :initarg :name
35          :type string
36          :documentation
37          "The name of this type of source code.
38 Such as \"C\" or \"Emacs Lisp\"")
39    (sourcepattern :initarg :sourcepattern
40                   :initform ".*"
41                   :type string
42                   :documentation
43                   "Emacs regex matching sourcecode this target accepts.")
44    (auxsourcepattern :initarg :auxsourcepattern
45                      :initform nil
46                      :type (or null string)
47                      :documentation
48                      "Emacs regex matching auxiliary source code this target accepts.
49 Aux source are source code files needed for compilation, which are not comiled
50 themselves.")
51    (enable-subdirectories :initarg :enable-subdirectories
52                           :initform nil
53                           :type boolean
54                           :documentation
55                           "Non nil if this sourcecode type uses subdirectores.
56 If sourcecode always lives near the target creating it, this should be nil.
57 If sourcecode can, or typically lives in a subdirectory of the owning
58 target, set this to t.")
59    (garbagepattern :initarg :garbagepattern
60                    :initform nil
61                    :type list
62                    :documentation
63                    "Shell file regex matching files considered as garbage.
64 This is a list of items added to an `rm' command when executing a `clean'
65 type directive.")
66    )
67   "Description of some type of source code.
68 Objects will use sourcecode objects to define the types of source
69 that they are willing to use.")
70
71 (defvar ede-sourcecode-list nil
72   "The master list of all EDE compilers.")
73
74 ;;; Methods
75 ;;
76 (defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
77   "Make sure that all ede compiler objects are cached in 
78 `ede-compiler-list'."
79   (let ((lst ede-sourcecode-list))
80     ;; Find an object of the same name.
81     (while (and lst (not (string= (oref this name) (oref (car lst) name))))
82       (setq lst (cdr lst)))
83     (if lst
84         ;; Replace old definition
85         (setcar lst this)
86       ;; Add to the beginning of the list.
87       (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))
88
89 (defmethod ede-want-file-p ((this ede-sourcecode) filename)
90   "Return non-nil if sourcecode definition THIS will take FILENAME."
91   (or (ede-want-file-source-p this filename)
92       (ede-want-file-auxiliary-p this filename)))
93
94 (defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
95   "Return non-nil if THIS will take FILENAME as an auxiliary ."
96   (let ((case-fold-search nil))
97     (string-match (oref this sourcepattern) filename)))
98
99 (defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
100   "Return non-nil if THIS will take FILENAME as an auxiliary ."
101   (let ((case-fold-search nil))
102     (and (slot-boundp this 'auxsourcepattern)
103          (oref this auxsourcepattern)
104          (string-match (oref this auxsourcepattern) filename))))
105
106 (defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
107   "Return non-nil if THIS will accept any source files in FILENAMES."
108   (ede-or (mapcar (lambda (c) (ede-want-file-source-p this c))
109                   filenames)))
110
111 (defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
112   "Return non-nil if THIS will accept any aux files in FILENAMES."
113   (ede-or (mapcar (lambda (c) (ede-want-file-auxiliary-p this c))
114                   filenames)))
115
116 (defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
117   "Return non-nil if THIS will accept any files in FILENAMES."
118   (ede-or (mapcar (lambda (c) (ede-want-file-p this c))
119                   filenames)))
120
121 (defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
122   "Return a list of file names of header files for THIS with FILENAME.
123 Used to guess header files, but uses the auxsource regular expression."
124   (let ((dn (file-name-directory filename))
125         (ts (file-name-sans-extension (file-name-nondirectory filename)))
126         (ae (oref this auxsourcepattern)))
127     (if (not ae)
128         nil
129       (directory-files dn t (concat (regexp-quote ts) ae)))))
130
131 ;;; Utility functions
132 ;;
133 (when nil
134   ;; not used at the moment.
135 (defun ede-source-find (name)
136   "Find the sourcecode object based on NAME."
137   (object-assoc name :name ede-sourcecode-list))
138
139 (defun ede-source-match (file)
140   "Find the list of soucecode objects which matches FILE."
141   (let ((lst ede-sourcecode-list)
142         (match nil))
143     (while lst
144       ;; ede-file-mine doesn't exist yet
145       (if (ede-file-mine (car lst) file)
146           (setq match (cons (car lst) match)))
147       (setq lst (cdr lst)))
148     match))
149 )
150 ;;; Master list of source code types
151 ;;
152 ;; This must appear at the end so that the init method will work.
153 (defvar ede-source-scheme
154   (ede-sourcecode "ede-source-scheme"
155                   :name "Scheme"
156                   :sourcepattern "\\.scm$")
157   "Scheme source code definition.")
158
159 ;;(defvar ede-source-
160 ;;  (ede-sourcecode "ede-source-"
161 ;;                  :name ""
162 ;;                  :sourcepattern "\\.$"
163 ;;                  :garbagepattern '("*."))
164 ;;  " source code definition.")
165
166 (provide 'ede-source)
167
168 ;;; ede-source.el ends here