Commit | Line | Data |
---|---|---|
a2095e2e CY |
1 | ;;; semantic/ede-grammar.el --- EDE support for Semantic Grammar Files |
2 | ||
acaf905b | 3 | ;; Copyright (C) 2003-2004, 2007-2012 Free Software Foundation, Inc. |
a2095e2e CY |
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;" | |
07a79ce4 DE |
74 | "@echo \"(require 'semantic/load)\" >> grammar-make-script" |
75 | "@echo \"(require 'semantic/grammar)\" >> grammar-make-script" | |
a2095e2e CY |
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;" | |
07a79ce4 DE |
104 | "@echo \"(require 'semantic/load)\" >> grammar-make-script" |
105 | "@echo \"(require 'semantic/grammar)\" >> grammar-make-script" | |
a2095e2e CY |
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) | |
0816d744 | 132 | (with-current-buffer (find-file-noselect src) |
a2095e2e CY |
133 | (save-excursion |
134 | (semantic-grammar-create-package)) | |
135 | (save-buffer) | |
fd8d481e GM |
136 | (byte-recompile-file (concat (semantic-grammar-package) ".el") nil 0))) |
137 | (oref obj source))) | |
a2095e2e CY |
138 | (message "All Semantic Grammar sources are up to date in %s" (object-name obj))) |
139 | ||
140 | ;;; Makefile generation functions | |
141 | ;; | |
142 | (defmethod ede-proj-makefile-sourcevar ((this semantic-ede-proj-target-grammar)) | |
143 | "Return the variable name for THIS's sources." | |
144 | (cond ((ede-proj-automake-p) | |
145 | (error "No Automake support for Semantic Grammars")) | |
146 | (t (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR")))) | |
147 | ||
148 | (defmethod ede-proj-makefile-insert-variables :AFTER ((this semantic-ede-proj-target-grammar)) | |
149 | "Insert variables needed by target THIS." | |
150 | (ede-proj-makefile-insert-loadpath-items | |
151 | (ede-proj-elisp-packages-to-loadpath | |
152 | (list "eieio" "semantic" "inversion" "ede"))) | |
153 | ;; eieio for object system needed in ede | |
154 | ;; semantic because it is | |
155 | ;; Inversion for versioning system. | |
156 | ;; ede for project regeneration | |
157 | (ede-pmake-insert-variable-shared | |
158 | (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL") | |
159 | (insert | |
160 | (mapconcat (lambda (src) | |
0816d744 | 161 | (with-current-buffer (find-file-noselect src) |
a2095e2e CY |
162 | (concat (semantic-grammar-package) ".el"))) |
163 | (oref this source) | |
164 | " "))) | |
165 | ) | |
166 | ||
167 | (defmethod ede-proj-makefile-insert-rules ((this semantic-ede-proj-target-grammar)) | |
168 | "Insert rules needed by THIS target." | |
169 | ;; Add in some dependencies. | |
170 | ;; (mapc (lambda (src) | |
171 | ;; (let ((nm (file-name-sans-extension src))) | |
172 | ;; (insert nm "-wy.el: " src "\n" | |
173 | ;; nm "-wy.elc: " nm "-wy.el\n\n") | |
174 | ;; )) | |
175 | ;; (oref this source)) | |
176 | ;; Call the normal insertion of rules. | |
177 | (call-next-method) | |
178 | ) | |
179 | ||
180 | (defmethod ede-proj-makefile-insert-dist-dependencies ((this semantic-ede-proj-target-grammar)) | |
181 | "Insert dist dependencies, or intermediate targets. | |
182 | This makes sure that all grammar lisp files are created before the dist | |
183 | runs, so they are always up to date. | |
184 | Argument THIS is the target that should insert stuff." | |
185 | (call-next-method) | |
186 | (insert " $(" (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL)") | |
187 | ) | |
188 | ||
189 | ;; (autoload 'ede-proj-target-elisp "ede/proj-elisp" | |
190 | ;; "Target class for Emacs/Semantic grammar files." nil nil) | |
191 | ||
192 | (ede-proj-register-target "semantic grammar" | |
193 | semantic-ede-proj-target-grammar) | |
194 | ||
195 | (provide 'semantic/ede-grammar) | |
196 | ||
197 | ;;; semantic/ede-grammar.el ends here |