b96100cfc44789f5b4fad378bd3861d09f438930
[elisp/liece.git] / 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          (setq autoload-package-name package)
130          (add-to-list 'command-line-args-left dir)
131          (batch-update-directory)
132         
133          (add-to-list 'command-line-args-left dir)
134          (Custom-make-dependencies)
135            
136          (byte-compile-file (expand-file-name "auto-autoloads.el" dir))
137          (byte-compile-file (expand-file-name "custom-load.el" dir)))))
138
139 (defun config-liece-package-directory ()
140   (if (boundp 'early-packages)
141       (let ((dirs (append (if early-package-load-path
142                               early-packages)
143                           (if late-package-load-path
144                               late-packages)
145                           (if last-package-load-path
146                               last-packages)))
147             dir)
148         (while (not (file-exists-p
149                      (setq dir (car dirs))))
150           (setq dirs (cdr dirs)))
151         (defvar PACKAGEDIR dir)
152         (princ (format "PACKAGEDIR=%s\n" PACKAGEDIR)))))
153
154 (defun config-liece-package ()
155   (let (package-dir)
156     (and (setq package-dir (car command-line-args-left))
157          (or (string= "NONE" package-dir)
158              (defvar PACKAGEDIR package-dir)))
159     (config-liece)
160     (config-liece-package-directory)
161     (setq command-line-args-left (cdr command-line-args-left))))
162
163 (defun compile-liece-package ()
164   (config-liece-package)
165   (compile-elisp-modules liece-modules-to-compile "."))
166
167 (defun install-liece-package ()
168   (config-liece-package)
169   (let ((just-print (install-just-print-p))
170         (dir (expand-file-name "lisp/liece" PACKAGEDIR))
171         (pkginfo-dir (expand-file-name "pkginfo" PACKAGEDIR)))
172     (install-elisp-modules liece-modules "." dir just-print)
173     (install-update-package-files "liece" dir just-print)
174     (install-update-manifest-file "liece" pkginfo-dir just-print)))
175
176 (defun autoload-liece ()
177   (config-liece)
178   (require 'autoload)
179   (let* ((generated-autoload-file "liece-setup.el")
180          (generate-autoload-cookie ";;;###liece-autoload")
181          (buf (find-file-noselect generated-autoload-file))
182          make-backup-files)
183     (set-buffer buf)
184     (delete-region (point-min) (point-max))
185     (insert-string
186      (format "(if (not (featurep '%s)) (progn\n"
187              (file-name-sans-extension generated-autoload-file)))
188     (mapcar
189      (function
190       (lambda (file)
191         (generate-file-autoloads
192          (concat (symbol-name file) ".el"))))
193      liece-modules-to-compile)
194     (goto-char (point-max))
195     (insert-string
196      (format "(provide '%s)))\n"
197              (file-name-sans-extension generated-autoload-file)))
198     (save-buffer)))
199
200 (provide 'liece-make)
201
202 ;;; liece-make.el ends here