Fix typos.
[emacs.git] / vms / make-mms-derivative.el
blob5ef859f512d1bdc8ec34e239de1fe5791c232f56
1 ;;; make-mms-derivative.el --- framework to do horrible things for VMS support
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
7 ;; Keywords: maint build vms mms makefile levitte autoconf war-is-a-lose
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;; Under VMS the standard make-like program is called MMS, which looks
27 ;; for an input file in the default directory named DESCRIP.MMS and runs
28 ;; the DCL command rules therein. As of 2005, the build process
29 ;; requires a hand translation of the Makefile.in and Emacs-specific
30 ;; methodology to DCL and TPU commands, so to alleviate this pain, we
31 ;; provide `make-mms-derivative', which given a source FILENAME, inserts
32 ;; the file contents in a new buffer and loads FILENAME-2mms. The lisp
33 ;; code in the -2mms file can (do whatever -- it's emacs -- and), as
34 ;; long as it arranges to write out the modified buffer after loading by
35 ;; specifying, on a line of its own, the directive:
37 ;; :output RELATIVE-OUTPUT
39 ;; where RELATIVE-OUTPUT is a filename (a string) relative to FILENAME's
40 ;; directory, typically something simple like "descrip.mms_in_in". Only
41 ;; the first :output directive is recognized.
43 ;; The only other special directive at this time has the form:
45 ;; :gigo NAME
46 ;; ;;blah blah blah
47 ;; ;;(more text here)
49 ;; NAME is anything distinguishable w/ `eq' (number, symbol or keyword).
50 ;; This associates NAME with the block of text starting immediately below
51 ;; the :gigo directive and ending at the first line that does not begin
52 ;; with two semicolons (which are stripped from each line in the block).
53 ;; To insert this block of text, pass NAME to `make-mms-derivative-gigo'.
55 ;; Directives are scanned before normal evaluation, so their placement
56 ;; in the file is not important. During loading, plain strings are
57 ;; displayed in the echo area, prefixed with the current line number.
59 ;; Over the long run, the convenience functions provided (see source)
60 ;; will be augmented by factoring maximally the -2mms files, squeezing
61 ;; as much algorithm out of those nasty heuristics as possible. What
62 ;; makes them nasty is not that they rely on the conventions of the
63 ;; Emacs makefiles; that's no big deal. What makes them nasty is that
64 ;; they rely on the conventions of separately maintained tools (namely
65 ;; Autoconf for VMS and GNU Autoconf), and the separation of conventions
66 ;; is how people drift apart, dragging their software behind
67 ;; mercilessly.
69 ;; In general, codified thought w/o self-synchronization is doomed.
70 ;; That a generation would eat its young (most discriminatingly, even)
71 ;; is no reason GNU cannot build around such woe.
73 ;;; Code:
75 (defvar make-mms-derivative-data nil
76 "Plist of data specific to `make-mms-derivative'.")
78 (defun make-mms-derivative-data (key &optional newval)
79 (if newval (setq make-mms-derivative-data
80 (plist-put make-mms-derivative-data key newval))
81 (plist-get make-mms-derivative-data key)))
83 (defun make-mms-derivative-gigo (name)
84 "Insert the text associated with :gigo NAME."
85 (insert (cdr (assq name (make-mms-derivative-data :gigo)))))
87 (defun make-mms-derivative (filename)
88 "Take FILENAME contents, load FILENAME-2mms, and write out the result.
89 The output file is specified by the :output directive in FILENAME-2mms.
90 See commentary of make-mms-derivative.el for full documentation."
91 (interactive "fSource File: ")
92 (let* ((todo (let ((fn (concat filename "-2mms")))
93 (unless (file-exists-p fn)
94 (error "Could not find %s" fn))
95 (set-buffer (get-buffer-create " *make-mms-derivative todo*"))
96 (insert-file-contents fn)
97 (current-buffer)))
98 (deriv (get-buffer-create (format "*mms-derivative: %s"
99 (file-relative-name filename))))
100 output gigo form)
101 (set-buffer todo)
102 (re-search-forward "^:output")
103 (setq output (expand-file-name (read (current-buffer))
104 (file-name-directory filename)))
105 (goto-char (point-min))
106 (while (re-search-forward "^:gigo" (point-max) t)
107 (let ((name (read (current-buffer)))
108 (p (progn (forward-line 1) (point))))
109 (while (looking-at ";;")
110 (delete-char 2)
111 (forward-line 1))
112 (setq gigo (cons (cons name (buffer-substring p (point))) gigo))
113 (delete-region p (point))))
114 (message "Munging...")
115 (switch-to-buffer deriv)
116 (erase-buffer)
117 (insert-file-contents filename)
118 (set (make-local-variable 'make-mms-derivative-data)
119 (list :gigo gigo))
120 (set-buffer todo)
121 (goto-char (point-min))
122 (while (condition-case nil
123 (setq form (read (current-buffer)))
124 (end-of-file nil))
125 (if (stringp form)
126 (message "%d: %s" (count-lines (point-min) (point)) form)
127 (save-excursion
128 (set-buffer deriv)
129 (eval form))))
130 (set-buffer deriv)
131 (message "Munging...done")
132 (write-file output)
133 (kill-buffer todo)
134 (kill-buffer deriv)))
136 (provide 'make-mms-derivative)
138 ;; arch-tag: a5b08625-3952-4053-be16-296220e27bb0
139 ;;; make-mms-derivative.el ends here