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