1 ;;; package-info.el --- Generate information about an SXEmacs package
3 ;; Copyright (C) 1998 by Free Software Foundation, Inc.
5 ;; Author: SL Baur <steve@xemacs.org>
8 ;; This file is part of SXEmacs.
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.
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.
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/>.
23 ;;; Synched up with: Not in FSF
27 ;; This file is used for building package distributions.
33 (defvar package-info "package-info"
34 "File used to write out Package info")
36 (defvar package-info-template "package-info.in"
37 "Template file for package-get info.")
40 ;(defun pi-md5sum (file)
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))))
49 ;;; APA: Stolen from package-get in package-get.el
50 (defun pi-md5sum (file)
52 (insert-file-contents-literally file)
53 (md5 (current-buffer))))
55 (defun pi-update-key (key value)
57 (goto-char (point-min))
58 (let ((case-fold-search nil))
59 (when (search-forward key)
60 (replace-match value t)))))
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)
68 (string-match "[0-9]+" sxemacs-betaname)
69 (concat "b" (match-string 0 sxemacs-betaname)))
72 (defun pi-last-mod-date ()
76 (insert-file-contents-literally "ChangeLog")
77 (goto-char (point-min))
78 (looking-at "[-0-9]+")
80 (buffer-substring (match-beginning 0)
82 ;; Fallback on current date if no valid ChangeLog entry
83 (t (format-time-string "\"%Y-%m-%d\""))))
85 (defun batch-update-package-info ()
86 "Generate a package-info file for use by package-get.el.
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)))
105 (find-file package-info)
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)))
124 (provide 'package-info)
126 ;;; package-info.el ends here