Take care of fallout from updating/fixing #'eval-after-load
[sxemacs] / lisp / package-info.el
1 ;;; package-info.el --- Generate information about an SXEmacs package
2
3 ;; Copyright (C) 1998 by Free Software Foundation, Inc.
4
5 ;; Author: SL Baur <steve@xemacs.org>
6 ;; Keywords: internal
7
8 ;; This file is part of SXEmacs.
9
10 ;; SXEmacs 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 ;; SXEmacs 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 this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Synched up with: Not in FSF
24
25 ;;; Commentary:
26
27 ;; This file is used for building package distributions.
28
29 ;;; Change Log:
30
31 ;;; Code:
32
33 (defvar package-info "package-info"
34   "File used to write out Package info")
35
36 (defvar package-info-template "package-info.in"
37   "Template file for package-get info.")
38
39 ;; Loses with Mule
40 ;(defun pi-md5sum (file)
41 ;  (let (result)
42 ;    (with-temp-buffer
43 ;      (let ((buffer-file-coding-system-for-read 'binary))
44 ;       (insert-file-contents-literally file))
45 ;      ;; (write-file "/tmp/x.x")
46 ;      (setq result (md5 (current-buffer))))
47 ;    result))
48
49 ;;; APA: Stolen from package-get in package-get.el
50 (defun pi-md5sum (file)
51   (with-temp-buffer
52         (insert-file-contents-literally file)
53         (md5 (current-buffer))))
54
55 (defun pi-update-key (key value)
56   (save-excursion
57     (goto-char (point-min))
58     (let ((case-fold-search nil))
59       (when (search-forward key)
60         (replace-match value t)))))
61
62 (defun pi-author-version (author-version)
63   (if (> (length author-version) 0)
64       (format "\"%s\"" author-version)
65     (format "\"%d.%d%s\"" emacs-major-version emacs-minor-version
66             (if (and (boundp 'sxemacs-betaname) sxemacs-betaname)
67                 (progn
68                   (string-match "[0-9]+" sxemacs-betaname)
69                   (concat "b" (match-string 0 sxemacs-betaname)))
70               ""))))
71
72 (defun pi-last-mod-date ()
73   (condition-case nil
74       (save-excursion
75         (with-temp-buffer
76           (insert-file-contents-literally "ChangeLog")
77           (goto-char (point-min))
78           (looking-at "[-0-9]+")
79           (format "\"%s\""
80                   (buffer-substring (match-beginning 0)
81                                     (match-end 0)))))
82     ;; Fallback on current date if no valid ChangeLog entry
83     (t (format-time-string "\"%Y-%m-%d\""))))
84
85 (defun batch-update-package-info ()
86   "Generate a package-info file for use by package-get.el.
87 Parameters are:
88 version -- Package version number
89 filename -- Filename of tarball to generate info for.
90 requires -- Packages necessary for bytecompiling.
91 author-version -- The original Author's version #.
92 maintainer -- The package maintainer.
93 category -- The build category."
94   (unless noninteractive
95     (error 'invalid-operation
96            "`batch-update-package-info' is to be used only with -batch"))
97   (let ((version (nth 0 command-line-args-left))
98         (filename (nth 1 command-line-args-left))
99         (requires (nth 2 command-line-args-left))
100         (author-version (nth 3 command-line-args-left))
101         (maintainer (nth 4 command-line-args-left))
102         (category (nth 5 command-line-args-left)))
103     (unless requires
104       (setq requires ""))
105     (find-file package-info)
106     (erase-buffer)
107     (insert-file-contents-literally package-info-template)
108     (goto-char (point-min))
109     (pi-update-key "VERSION" (format "\"%s\"" version))
110     (pi-update-key "MD5SUM" (format "\"%s\""
111                                     (pi-md5sum filename)))
112     (pi-update-key "FILENAME" (format "\"%s\""
113                                       (file-name-nondirectory filename)))
114     (pi-update-key "SIZE" (format "%d"
115                                   (nth 7 (file-attributes filename))))
116     (pi-update-key "REQUIRES" requires)
117     (pi-update-key "AUTHOR_VERSION" (pi-author-version author-version))
118     (pi-update-key "MAINTAINER" (format "\"%s\"" maintainer))
119     (pi-update-key "CATEGORY" (format "\"%s\"" category))
120     (pi-update-key "BUILD_DATE" (format-time-string "\"%Y-%m-%d\""))
121     (pi-update-key "DATE" (pi-last-mod-date))
122     (save-buffers-kill-emacs 0)))
123
124 (provide 'package-info)
125
126 ;;; package-info.el ends here