Modified comment.
[elisp/apel.git] / APEL-MK
1 ;;; APEL-MK --- installer for APEL. -*-Emacs-Lisp-*-
2
3 ;;; Commentary:
4
5 ;; DON'T EDIT THIS FILE; edit APEL-CFG instead.
6
7 ;;; Code:
8
9 ;;; Configuration variables.
10
11 ;; These two variables will be generated from other variables below.
12 (defvar APEL_DIR nil)
13 (defvar EMU_DIR nil)
14
15 ;; Install to "apel" subdirectory.
16 (defvar APEL_PREFIX "apel")
17 ;; Install to "emu" subdirectory if emacs supports some features.
18 (defvar EMU_PREFIX
19   (if (or (featurep 'xemacs)
20           (fboundp 'normal-top-level-add-subdirs-to-load-path))
21       ;; Install to "emu" subdirectory.
22       "emu"
23     ;; If your emacs does not have `normal-top-level-add-subdirs-to-load-path'
24     ;; but have `normal-top-level-add-to-load-path' and you want to use it in
25     ;; "subdirs.el", put the following line to "APEL-CFG".
26     ;; (setq EMU_PREFIX "emu")
27     ""))
28
29 ;; We can load APEL modules safely;-)
30 (defvar default-load-path load-path)
31 (setq load-path (cons (expand-file-name ".") load-path))
32 (require 'poe)
33 (require 'path-util)
34 (require 'install)
35
36 ;; Override everything you want.
37 (load-file "APEL-CFG")
38
39 ;; The following four variables will be overrided by command line options.
40 (defvar PREFIX install-prefix)
41 ;; v18: (no standard site-lisp directory)
42 ;; Emacs 19.28 and earlier: "PREFIX/lib/emacs/site-lisp"
43 ;; Emacs 19.29 and later: "PREFIX/share/emacs/site-lisp"
44 (defvar LISPDIR
45   (install-detect-elisp-directory PREFIX))
46 ;; Emacs 19.31 and later: "PREFIX/share/emacs/VERSION/site-lisp".
47 (defvar VERSION_SPECIFIC_LISPDIR
48   (install-detect-elisp-directory PREFIX nil 'version-specific))
49 ;; for XEmacs package system.
50 (defvar PACKAGEDIR
51   (if (boundp 'early-packages)
52       (let ((dirs (append (if early-package-load-path
53                               early-packages)
54                           (if late-package-load-path
55                               late-packages)
56                           (if last-package-load-path
57                               last-packages)))
58             dir)
59         (while (not (file-exists-p (setq dir (car dirs))))
60           (setq dirs (cdr dirs)))
61         dir)))
62
63
64 ;;; Utilities. (XXX: should be moved to install.el ?)
65
66 (defun install-just-print-p ()
67   (let ((flag (getenv "MAKEFLAGS"))
68         case-fold-search)
69     (princ (format "%s\n" flag))
70     (if flag
71         (string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag))))
72
73 (defun install-update-package-files (package dir &optional just-print)
74   (cond
75    (just-print
76     (princ (format "Updating autoloads in directory %s..\n\n" dir))
77
78     (princ (format "Processing %s\n" dir))
79     (princ "Generating custom-load.el...\n\n")
80
81     (princ (format "Compiling %s...\n"
82                    (expand-file-name "auto-autoloads.el" dir)))
83     (princ (format "Wrote %s\n"
84                    (expand-file-name "auto-autoloads.elc" dir)))
85
86     (princ (format "Compiling %s...\n"
87                    (expand-file-name "custom-load.el" dir)))
88     (princ (format "Wrote %s\n"
89                    (expand-file-name "custom-load.elc" dir))))
90    (t
91     (setq autoload-package-name package)
92     (add-to-list 'command-line-args-left dir)
93     (batch-update-directory)
94
95     (add-to-list 'command-line-args-left dir)
96     (Custom-make-dependencies)
97
98     (byte-compile-file (expand-file-name "auto-autoloads.el" dir))
99     (byte-compile-file (expand-file-name "custom-load.el" dir)))))
100
101
102 ;;; Configure, Compile, and Install.
103
104 (defun config-apel ()
105   (let (prefix lisp-dir version-specific-lisp-dir)
106     ;; override standard PREFIX, LISPDIR, and VERSION_SPECIFIC_LISPDIR
107     ;; with command-line options.
108     (and (setq prefix (prog1
109                           ;; avoid using `pop'.
110                           (car command-line-args-left)
111                         (setq command-line-args-left
112                               (cdr command-line-args-left))))
113          (or (string-equal "NONE" prefix)
114              (setq PREFIX prefix)))
115     (and (setq lisp-dir (prog1
116                             (car command-line-args-left)
117                           (setq command-line-args-left
118                                 (cdr command-line-args-left))))
119          (or (string-equal "NONE" lisp-dir)
120              (setq LISPDIR lisp-dir)))
121     (and (setq version-specific-lisp-dir
122                (prog1
123                    (car command-line-args-left)
124                  (setq command-line-args-left
125                        (cdr command-line-args-left))))
126          (or (string-equal "NONE" version-specific-lisp-dir)
127              (setq VERSION_SPECIFIC_LISPDIR version-specific-lisp-dir)))
128     ;; directories we actually use.
129     (or APEL_DIR
130         (setq APEL_DIR (expand-file-name APEL_PREFIX LISPDIR)))
131     (or EMU_DIR
132         (setq EMU_DIR (expand-file-name EMU_PREFIX VERSION_SPECIFIC_LISPDIR)))
133     ;; import `apel-modules'.
134     (load-file "APEL-ELS")
135     ;; import `emu-modules' and `emu-modules-to-compile'.
136     (load-file "EMU-ELS")
137     (princ (format "\nLISPDIR=%s\n" LISPDIR))
138     (princ (format "VERSION_SPECIFIC_LISPDIR=%s\n" VERSION_SPECIFIC_LISPDIR))))
139
140 (defun compile-apel ()
141   (config-apel)
142   ;; compile emu modules first.
143   (compile-elisp-modules emu-modules-to-compile ".")
144   (compile-elisp-modules apel-modules           "."))
145
146 (defun install-apel ()
147   (compile-apel)
148   (let ((just-print (install-just-print-p)))
149     (install-elisp-modules emu-modules  "." EMU_DIR     just-print)
150     (install-elisp-modules apel-modules "." APEL_DIR    just-print)))
151
152 ;; for XEmacs package system.
153 (defun config-apel-package ()
154   (let (package-dir)
155     ;; override standard PACKAGEDIR with command-line option.
156     (and (setq package-dir (prog1
157                                ;; avoid using `pop'.
158                                (car command-line-args-left)
159                              (setq command-line-args-left
160                                    (cdr command-line-args-left))))
161          (or (string= "NONE" package-dir)
162              (defvar PACKAGEDIR package-dir)))
163     ;; import `apel-modules'.
164     (load-file "APEL-ELS")
165     ;; import `emu-modules' and `emu-modules-to-compile'.
166     (load-file "EMU-ELS")
167     (princ (format "\nPACKAGEDIR=%s\n" PACKAGEDIR))))
168
169 (defun compile-apel-package ()
170   (config-apel-package)
171   ;; compile emu modules first.
172   (compile-elisp-modules emu-modules-to-compile ".")
173   (compile-elisp-modules apel-modules           "."))
174
175 (defun install-apel-package ()
176   (config-apel-package)
177   (let ((just-print (install-just-print-p))
178         (dir (expand-file-name APEL_PREFIX
179                                (expand-file-name "lisp" PACKAGEDIR))))
180     (install-elisp-modules emu-modules  "." dir just-print)
181     (install-elisp-modules apel-modules "." dir just-print)
182     (install-update-package-files "apel" dir just-print)))
183
184 (defun what-where-apel ()
185   (config-apel)
186   (princ (format "
187 The files that belong to the EMU modules:
188   %s
189   -> %s
190
191 The files that belong to the APEL modules:
192   %s
193   -> %s
194 "
195                  (mapconcat (function symbol-name) emu-modules ", ")
196                  EMU_DIR
197                  (mapconcat (function symbol-name) apel-modules ", ")
198                  APEL_DIR)))
199
200 ;;; APEL-MK ends here