* cedet/ede/system.el (ede-upload-html-documentation)
[bpt/emacs.git] / lisp / cedet / semantic / ede-grammar.el
1 ;;; semantic/ede-grammar.el --- EDE support for Semantic Grammar Files
2
3 ;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 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 ;; Handle .by or .wy files.
26
27 (require 'semantic)
28 (require 'ede/proj)
29 (require 'ede/pmake)
30 (require 'ede/pconf)
31 (require 'ede/proj-elisp)
32 (require 'semantic/grammar)
33
34 ;;; Code:
35 (defclass semantic-ede-proj-target-grammar (ede-proj-target-makefile)
36 ((menu :initform nil)
37 (keybindings :initform nil)
38 (phony :initform t)
39 (sourcetype :initform
40 (semantic-ede-source-grammar-wisent
41 semantic-ede-source-grammar-bovine
42 ))
43 (availablecompilers :initform
44 (semantic-ede-grammar-compiler-wisent
45 semantic-ede-grammar-compiler-bovine
46 ))
47 )
48 "This target consists of a group of grammar files.
49 A grammar target consists of grammar files that build Emacs Lisp programs for
50 parsing different languages.")
51
52 (defvar semantic-ede-source-grammar-wisent
53 (ede-sourcecode "semantic-ede-grammar-source-wisent"
54 :name "Wisent Grammar"
55 :sourcepattern "\\.wy$"
56 )
57 "Semantic Grammar source code definition for wisent.")
58
59 (defclass semantic-ede-grammar-compiler-class (ede-compiler)
60 nil
61 "Specialized compiler for semantic grammars.")
62
63 (defvar semantic-ede-grammar-compiler-wisent
64 (semantic-ede-grammar-compiler-class
65 "ede-emacs-wisent-compiler"
66 :name "emacs"
67 :variables '(("EMACS" . "emacs"))
68 :commands
69 '(
70 "@echo \"(add-to-list 'load-path nil)\" > grammar-make-script"
71 "@for loadpath in . ${LOADPATH}; do \\"
72 " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> grammar-make-script; \\"
73 "done;"
74 "@echo \"(require 'semantic-load)\" >> grammar-make-script"
75 "@echo \"(require 'semantic-grammar)\" >> grammar-make-script"
76 ;; "@echo \"(setq debug-on-error t)\" >> grammar-make-script"
77 "\"$(EMACS)\" -batch --no-site-file -l grammar-make-script -f semantic-grammar-batch-build-packages $^"
78 )
79 ;; :autoconf '("AM_PATH_LISPDIR")
80 :sourcetype '(semantic-ede-source-grammar-wisent)
81 :objectextention "-wy.elc"
82 )
83 "Compile Emacs Lisp programs.")
84
85
86 (defvar semantic-ede-source-grammar-bovine
87 (ede-sourcecode "semantic-ede-grammar-source-bovine"
88 :name "Bovine Grammar"
89 :sourcepattern "\\.by$"
90 )
91 "Semantic Grammar source code definition for the bovinator.")
92
93 (defvar semantic-ede-grammar-compiler-bovine
94 (semantic-ede-grammar-compiler-class
95 "ede-emacs-wisent-compiler"
96 :name "emacs"
97 :variables '(("EMACS" . "emacs"))
98 :commands
99 '(
100 "@echo \"(add-to-list 'load-path nil)\" > grammar-make-script"
101 "@for loadpath in . ${LOADPATH}; do \\"
102 " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> grammar-make-script; \\"
103 "done;"
104 "@echo \"(require 'semantic-load)\" >> grammar-make-script"
105 "@echo \"(require 'semantic-grammar)\" >> grammar-make-script"
106 ;; "@echo \"(setq debug-on-error t)\" >> grammar-make-script"
107 "\"$(EMACS)\" -batch --no-site-file -l grammar-make-script -f semantic-grammar-batch-build-packages $^"
108 )
109 ;; :autoconf '("AM_PATH_LISPDIR")
110 :sourcetype '(semantic-ede-source-grammar-bovine)
111 :objectextention "-by.elc"
112 )
113 "Compile Emacs Lisp programs.")
114
115 ;;; Target options.
116 (defmethod ede-buffer-mine ((this semantic-ede-proj-target-grammar) buffer)
117 "Return t if object THIS lays claim to the file in BUFFER.
118 Lays claim to all -by.el, and -wy.el files."
119 ;; We need to be a little more careful than this, but at the moment it
120 ;; is common to have only one target of this class per directory.
121 (if (string-match "-[bw]y\\.elc?$" (buffer-file-name buffer))
122 t
123 (call-next-method) ; The usual thing.
124 ))
125
126 (defmethod project-compile-target ((obj semantic-ede-proj-target-grammar))
127 "Compile all sources in a Lisp target OBJ."
128 (let* ((cb (current-buffer))
129 (proj (ede-target-parent obj))
130 (default-directory (oref proj directory)))
131 (mapc (lambda (src)
132 (save-excursion
133 (set-buffer (find-file-noselect src))
134 (save-excursion
135 (semantic-grammar-create-package))
136 (save-buffer)
137 (let ((cf (concat (semantic-grammar-package) ".el")))
138 (if (or (not (file-exists-p cf))
139 (file-newer-than-file-p src cf))
140 (byte-compile-file cf)))))
141 (oref obj source)))
142 (message "All Semantic Grammar sources are up to date in %s" (object-name obj)))
143
144 ;;; Makefile generation functions
145 ;;
146 (defmethod ede-proj-makefile-sourcevar ((this semantic-ede-proj-target-grammar))
147 "Return the variable name for THIS's sources."
148 (cond ((ede-proj-automake-p)
149 (error "No Automake support for Semantic Grammars"))
150 (t (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR"))))
151
152 (defmethod ede-proj-makefile-insert-variables :AFTER ((this semantic-ede-proj-target-grammar))
153 "Insert variables needed by target THIS."
154 (ede-proj-makefile-insert-loadpath-items
155 (ede-proj-elisp-packages-to-loadpath
156 (list "eieio" "semantic" "inversion" "ede")))
157 ;; eieio for object system needed in ede
158 ;; semantic because it is
159 ;; Inversion for versioning system.
160 ;; ede for project regeneration
161 (ede-pmake-insert-variable-shared
162 (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL")
163 (insert
164 (mapconcat (lambda (src)
165 (save-excursion
166 (set-buffer (find-file-noselect src))
167 (concat (semantic-grammar-package) ".el")))
168 (oref this source)
169 " ")))
170 )
171
172 (defmethod ede-proj-makefile-insert-rules ((this semantic-ede-proj-target-grammar))
173 "Insert rules needed by THIS target."
174 ;; Add in some dependencies.
175 ;; (mapc (lambda (src)
176 ;; (let ((nm (file-name-sans-extension src)))
177 ;; (insert nm "-wy.el: " src "\n"
178 ;; nm "-wy.elc: " nm "-wy.el\n\n")
179 ;; ))
180 ;; (oref this source))
181 ;; Call the normal insertion of rules.
182 (call-next-method)
183 )
184
185 (defmethod ede-proj-makefile-insert-dist-dependencies ((this semantic-ede-proj-target-grammar))
186 "Insert dist dependencies, or intermediate targets.
187 This makes sure that all grammar lisp files are created before the dist
188 runs, so they are always up to date.
189 Argument THIS is the target that should insert stuff."
190 (call-next-method)
191 (insert " $(" (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL)")
192 )
193
194 ;; (autoload 'ede-proj-target-elisp "ede/proj-elisp"
195 ;; "Target class for Emacs/Semantic grammar files." nil nil)
196
197 (ede-proj-register-target "semantic grammar"
198 semantic-ede-proj-target-grammar)
199
200 (provide 'semantic/ede-grammar)
201
202 ;;; semantic/ede-grammar.el ends here