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