1 ;;; semantic/ede-grammar.el --- EDE support for Semantic Grammar Files
3 ;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
25 ;; Handle .by or .wy files.
31 (require 'ede
/proj-elisp
)
32 (require 'semantic
/grammar
)
35 (defclass semantic-ede-proj-target-grammar
(ede-proj-target-makefile)
37 (keybindings :initform nil
)
40 (semantic-ede-source-grammar-wisent
41 semantic-ede-source-grammar-bovine
43 (availablecompilers :initform
44 (semantic-ede-grammar-compiler-wisent
45 semantic-ede-grammar-compiler-bovine
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.")
52 (defvar semantic-ede-source-grammar-wisent
53 (ede-sourcecode "semantic-ede-grammar-source-wisent"
54 :name
"Wisent Grammar"
55 :sourcepattern
"\\.wy$"
57 "Semantic Grammar source code definition for wisent.")
59 (defclass semantic-ede-grammar-compiler-class
(ede-compiler)
61 "Specialized compiler for semantic grammars.")
63 (defvar semantic-ede-grammar-compiler-wisent
64 (semantic-ede-grammar-compiler-class
65 "ede-emacs-wisent-compiler"
67 :variables
'(("EMACS" .
"emacs"))
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; \\"
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 $^"
79 ;; :autoconf '("AM_PATH_LISPDIR")
80 :sourcetype
'(semantic-ede-source-grammar-wisent)
81 :objectextention
"-wy.elc"
83 "Compile Emacs Lisp programs.")
86 (defvar semantic-ede-source-grammar-bovine
87 (ede-sourcecode "semantic-ede-grammar-source-bovine"
88 :name
"Bovine Grammar"
89 :sourcepattern
"\\.by$"
91 "Semantic Grammar source code definition for the bovinator.")
93 (defvar semantic-ede-grammar-compiler-bovine
94 (semantic-ede-grammar-compiler-class
95 "ede-emacs-wisent-compiler"
97 :variables
'(("EMACS" .
"emacs"))
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; \\"
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 $^"
109 ;; :autoconf '("AM_PATH_LISPDIR")
110 :sourcetype
'(semantic-ede-source-grammar-bovine)
111 :objectextention
"-by.elc"
113 "Compile Emacs Lisp programs.")
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
))
123 (call-next-method) ; The usual thing.
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
)))
133 (set-buffer (find-file-noselect src
))
135 (semantic-grammar-create-package))
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
)))))
142 (message "All Semantic Grammar sources are up to date in %s" (object-name obj
)))
144 ;;; Makefile generation functions
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"))))
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")
164 (mapconcat (lambda (src)
166 (set-buffer (find-file-noselect src
))
167 (concat (semantic-grammar-package) ".el")))
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")
180 ;; (oref this source))
181 ;; Call the normal insertion of rules.
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."
191 (insert " $(" (ede-pmake-varname this
) "_SEMANTIC_GRAMMAR_EL)")
194 ;; (autoload 'ede-proj-target-elisp "ede/proj-elisp"
195 ;; "Target class for Emacs/Semantic grammar files." nil nil)
197 (ede-proj-register-target "semantic grammar"
198 semantic-ede-proj-target-grammar
)
200 (provide 'semantic
/ede-grammar
)
202 ;;; semantic/ede-grammar.el ends here