Initial Commit
[packages] / xemacs-packages / liece / lisp / liece-make.el
1 ;;; liece-make.el --- Generic make procedures.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Revised: 1999-03-02
7 ;; Keywords: IRC, liece, APEL
8
9 ;; This file is part of Liece.
10
11 ;; This program 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 2, or (at your option)
14 ;; any later version.
15
16 ;; This program 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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31
32 (require 'cl)
33
34 (defun install-just-print-p ()
35   (let ((flag (getenv "MAKEFLAGS"))
36         case-fold-search)
37     (princ (format "%s\n" flag))
38     (if flag
39         (string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag))))
40
41 (defun config-liece ()
42   (let (prefix exec-prefix lisp-dir version-specific-lisp-dir)
43     (and (setq prefix (car command-line-args-left))
44          (or (string-equal "NONE" prefix)
45              (setq PREFIX prefix)))
46     (setq command-line-args-left (cdr command-line-args-left))
47     (and (setq lisp-dir (car command-line-args-left))
48          (or (string-equal "NONE" lisp-dir)
49              (setq LISPDIR lisp-dir)))
50     (setq command-line-args-left (cdr command-line-args-left))
51     (and (setq version-specific-lisp-dir (car command-line-args-left))
52          (or (string-equal "NONE" version-specific-lisp-dir)
53              (progn
54                (defvar VERSION_SPECIFIC_LISPDIR version-specific-lisp-dir)
55                (princ (format "VERSION_SPECIFIC_LISPDIR=%s\n"
56                               VERSION_SPECIFIC_LISPDIR)))))
57     (setq command-line-args-left (cdr command-line-args-left))
58     (setq load-path (cons (expand-file-name ".") load-path))
59     (load "liece-config")
60     (or (boundp 'liece-modules-to-compile)
61         (load "liece-modules"))
62     (princ (format "PREFIX=%s\tLISPDIR=%s\n" PREFIX LISPDIR))))
63
64 (defun compile-liece ()
65   ;;(setq byte-compile-dynamic t)
66   (config-liece)
67   (compile-elisp-modules liece-modules-to-compile "."))
68
69 (defun install-liece ()
70   (compile-liece)
71   (let ((just-print (install-just-print-p))
72         (dir (expand-file-name "liece" LISPDIR)))
73     (princ (format "%s\n" emacs-version))
74     (install-elisp-modules liece-modules "." dir just-print)))
75
76 (defun install-update-manifest-file (package dir &optional just-print)
77   (message "Generating MANIFEST.%s for the package..." package)
78   (unless just-print
79     (with-temp-buffer
80       (insert "pkginfo/MANIFEST." package "\n"
81               "lisp/" package "/"
82               (mapconcat #'identity
83                          (sort
84                           (mapcar (lambda (symbol)
85                                     (format "%s.el\nlisp/%s/%s.elc"
86                                             symbol package symbol))
87                                   liece-modules-to-compile)
88                           #'string-lessp)
89                          (concat "\nlisp/" package "/"))
90               "\n")
91       (when (file-directory-p "../doc")
92         (insert "info/"
93                 (mapconcat #'identity
94                            (sort
95                             (directory-files
96                              "../doc" nil liece-config-info-file-regexp)
97                             #'string-lessp)
98                            "\ninfo/")
99                 "\n"))
100       (let ((dirs '("icons" "po" "styles")))
101         (dolist (dir dirs)
102           (when (file-directory-p (concat "../etc/" dir))
103             (insert "etc/" package "/" dir "/"
104                     (mapconcat #'identity
105                                (sort (directory-files (concat "../etc/" dir)
106                                                       nil nil nil t)
107                                      #'string-lessp)
108                                (concat "\netc/" package "/" dir "/"))
109                     "\n"))))
110       (write-file (expand-file-name (concat "MANIFEST." package) dir)))))
111
112 (defun install-update-package-files (package dir &optional just-print)
113   (cond (just-print
114          (princ (format "Updating autoloads in directory %s..\n\n" dir))
115            
116          (princ (format "Processing %s\n" dir))
117          (princ "Generating custom-load.el...\n\n")
118             
119          (princ (format "Compiling %s...\n"
120                         (expand-file-name "auto-autoloads.el" dir)))
121          (princ (format "Wrote %s\n"
122                         (expand-file-name "auto-autoloads.elc" dir)))
123            
124          (princ (format "Compiling %s...\n"
125                         (expand-file-name "custom-load.el" dir)))
126          (princ (format "Wrote %s\n"
127                         (expand-file-name "custom-load.elc" dir))))
128         (t
129          (if (fboundp 'batch-update-directory-autoloads)
130              (progn
131                (setq command-line-args-left
132                      (cons package (cons dir command-line-args-left)))
133                (batch-update-directory-autoloads))
134            (setq autoload-package-name package)
135            (add-to-list 'command-line-args-left dir)
136            (batch-update-directory))
137         
138          (add-to-list 'command-line-args-left dir)
139          (Custom-make-dependencies)
140            
141          (byte-compile-file (expand-file-name "auto-autoloads.el" dir))
142          (byte-compile-file (expand-file-name "custom-load.el" dir)))))
143
144 (defun config-liece-package-directory ()
145   (if (boundp 'early-packages)
146       (let ((dirs (append (if early-package-load-path
147                               early-packages)
148                           (if late-package-load-path
149                               late-packages)
150                           (if last-package-load-path
151                               last-packages)))
152             dir)
153         (while (and dirs (not (file-exists-p
154                                (setq dir (car dirs)))))
155           (setq dirs (cdr dirs)))
156         (defvar PACKAGEDIR dir)
157         (princ (format "PACKAGEDIR=%s\n" PACKAGEDIR)))))
158
159 (defun config-liece-package ()
160   (let (package-dir)
161     (and (setq package-dir (car command-line-args-left))
162          (or (string= "NONE" package-dir)
163              (defvar PACKAGEDIR package-dir)))
164     (config-liece)
165     (config-liece-package-directory)
166     (setq command-line-args-left (cdr command-line-args-left))))
167
168 (defun compile-liece-package ()
169   (config-liece-package)
170   (compile-elisp-modules liece-modules-to-compile "."))
171
172 (defun install-liece-package ()
173   (config-liece-package)
174   (let ((just-print (install-just-print-p))
175         (dir (expand-file-name "lisp/liece" PACKAGEDIR))
176         (pkginfo-dir (expand-file-name "pkginfo" PACKAGEDIR)))
177     (install-elisp-modules liece-modules "." dir just-print)
178     (install-update-package-files "liece" dir just-print)
179     (install-update-manifest-file "liece" pkginfo-dir just-print)))
180
181 (defun autoload-liece ()
182   (config-liece)
183   (require 'autoload)
184   (let* ((generated-autoload-file "liece-setup.el")
185          (generate-autoload-cookie ";;;###liece-autoload")
186          (buf (find-file-noselect generated-autoload-file))
187          make-backup-files)
188     (set-buffer buf)
189     (delete-region (point-min) (point-max))
190     (insert-string
191      (format "(if (not (featurep '%s)) (progn\n"
192              (file-name-sans-extension generated-autoload-file)))
193     (mapcar
194      (function
195       (lambda (file)
196         (generate-file-autoloads
197          (concat (symbol-name file) ".el"))))
198      liece-modules-to-compile)
199     (goto-char (point-max))
200     (insert-string
201      (format "(provide '%s)))\n"
202              (file-name-sans-extension generated-autoload-file)))
203     (save-buffer)))
204
205 (provide 'liece-make)
206
207 ;;; liece-make.el ends here