Fix file header.
[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 ;; Set these four variables in "APEL-CFG" or in "Makefile".
12
13 ;; This variable will be detected automatically.
14 (defvar PREFIX nil)
15
16 ;; This variable will be detected automatically using PREFIX.
17 ;; v18: (no standard site-lisp directory)
18 ;; Emacs 19.28 and earlier: "PREFIX/lib/emacs/site-lisp"
19 ;; Emacs 19.29 and later: "PREFIX/share/emacs/site-lisp"
20 (defvar LISPDIR nil)
21
22 ;; This variable will be detected automatically using PREFIX.
23 ;; Emacs 19.31 and later: "PREFIX/share/emacs/VERSION/site-lisp"
24 (defvar VERSION_SPECIFIC_LISPDIR nil)
25
26 ;; This variable will be detected automatically.
27 ;; XEmacs 21.0 and later: "/usr/local/lib/xemacs/xemacs-packages"
28 (defvar PACKAGEDIR nil)
29
30 ;; Install APEL modules to "apel" subdirectory.
31 (defvar APEL_PREFIX "apel")
32
33 ;; Install EMU modules to "emu" subdirectory if emacs supports some features.
34 ;; If your emacs does not have `normal-top-level-add-subdirs-to-load-path'
35 ;; but have `normal-top-level-add-to-load-path' and you want to use it in
36 ;; "subdirs.el", put the following line to "APEL-CFG".
37 ;; (setq EMU_PREFIX "emu")
38 (defvar EMU_PREFIX
39   (if (or (featurep 'xemacs)
40           (fboundp 'normal-top-level-add-subdirs-to-load-path))
41       ;; Make "emu" subdirectory.
42       "emu"
43     ;; Don't make "emu" subdirectory.
44     ""))
45
46 ;; The directories where APEL and EMU modules will be installed.
47 ;; These two variables will be generated from other variables above.
48 (defvar APEL_DIR nil)                   ; LISPDIR/APEL_PREFIX
49 (defvar EMU_DIR nil)                    ; VERSION_SPECIFIC_LISPDIR/EMU_PREFIX
50
51
52 ;;; Utilities. (XXX: should be moved to install.el ?)
53
54 (defun install-just-print-p ()
55   (let ((flag (getenv "MAKEFLAGS"))
56         (case-fold-search nil))
57     (princ (format "%s\n" flag))
58     (if flag
59         (string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag))))
60
61 (defun install-update-package-files (package dir &optional just-print)
62   (cond
63    (just-print
64     (princ (format "Updating autoloads in directory %s..\n\n" dir))
65
66     (princ (format "Processing %s\n" dir))
67     (princ "Generating custom-load.el...\n\n")
68
69     (princ (format "Compiling %s...\n"
70                    (expand-file-name "auto-autoloads.el" dir)))
71     (princ (format "Wrote %s\n"
72                    (expand-file-name "auto-autoloads.elc" dir)))
73
74     (princ (format "Compiling %s...\n"
75                    (expand-file-name "custom-load.el" dir)))
76     (princ (format "Wrote %s\n"
77                    (expand-file-name "custom-load.elc" dir))))
78    (t
79     (setq autoload-package-name package)
80
81     (let ((command-line-args-left (list dir)))
82       (batch-update-directory))
83
84     (let ((command-line-args-left (list dir)))
85       (Custom-make-dependencies))
86
87     (byte-compile-file (expand-file-name "auto-autoloads.el" dir))
88     (byte-compile-file (expand-file-name "custom-load.el" dir)))))
89
90
91 ;;; Configure, Compile, and Install.
92
93 (defun config-apel ()
94   ;; Override everything you want.
95   (load-file "APEL-CFG")
96   ;; Override PREFIX, LISPDIR, and VERSION_SPECIFIC_LISPDIR with
97   ;; command-line options.
98   (let (prefix lisp-dir version-specific-lisp-dir)
99     (and (setq prefix
100                ;; Avoid using `pop'.
101                ;; (pop command-line-args-left)
102                (prog1
103                    (car command-line-args-left)
104                  (setq command-line-args-left
105                        (cdr command-line-args-left))))
106          (or (string-equal "NONE" prefix)
107              (setq PREFIX prefix)))
108     (and (setq lisp-dir
109                ;; Avoid using `pop'.
110                ;; (pop command-line-args-left)
111                (prog1
112                    (car command-line-args-left)
113                  (setq command-line-args-left
114                        (cdr command-line-args-left))))
115          (or (string-equal "NONE" lisp-dir)
116              (setq LISPDIR lisp-dir)))
117     (and (setq version-specific-lisp-dir
118                ;; Avoid using `pop'.
119                ;; (pop command-line-args-left)
120                (prog1
121                    (car command-line-args-left)
122                  (setq command-line-args-left
123                        (cdr command-line-args-left))))
124          (or (string-equal "NONE" version-specific-lisp-dir)
125              (setq VERSION_SPECIFIC_LISPDIR version-specific-lisp-dir))))
126   ;; Load some APEL modules from this directory.
127   (defvar default-load-path load-path)
128   (setq load-path (cons (expand-file-name ".") load-path))
129   (require 'poe)
130   (require 'path-util)
131   (require 'install)
132
133   ;; Import `apel-modules'.
134   (load-file "APEL-ELS")
135   ;; Import `emu-modules' and `emu-modules-to-compile'.
136   (load-file "EMU-ELS")
137
138   ;; Set PREFIX, LISPDIR, and VERSION_SPECIFIC_LISPDIR if not set yet.
139   (or PREFIX
140       (setq PREFIX install-prefix))
141   (or LISPDIR
142       (setq LISPDIR (install-detect-elisp-directory PREFIX)))
143   (or VERSION_SPECIFIC_LISPDIR
144       (setq VERSION_SPECIFIC_LISPDIR
145             (install-detect-elisp-directory PREFIX nil 'version-specific)))
146   ;; The directories where APEL and EMU will be installed.
147   (or APEL_DIR
148       (setq APEL_DIR (expand-file-name APEL_PREFIX LISPDIR)))
149   (or EMU_DIR
150       (setq EMU_DIR (expand-file-name EMU_PREFIX VERSION_SPECIFIC_LISPDIR)))
151   (princ (format "\nLISPDIR=%s\n" LISPDIR))
152   (princ (format "VERSION_SPECIFIC_LISPDIR=%s\n" VERSION_SPECIFIC_LISPDIR)))
153
154 (defun compile-apel ()
155   (config-apel)
156   ;; Compile emu modules first.
157   (compile-elisp-modules emu-modules-to-compile ".")
158   (compile-elisp-modules apel-modules           "."))
159
160 (defun install-apel ()
161   (config-apel)
162   (let ((just-print (install-just-print-p)))
163     (install-elisp-modules emu-modules  "." EMU_DIR  just-print)
164     (install-elisp-modules apel-modules "." APEL_DIR just-print)))
165
166 ;; For XEmacs package system.
167 (defun config-apel-package ()
168   ;; Override everything you want.
169   (load-file "APEL-CFG")
170   ;; Override PACKAGEDIR with command-line option.
171   (let (package-dir)
172     (and (setq package-dir
173                ;; Avoid using `pop'.
174                ;; (pop command-line-args-left)
175                (prog1
176                    (car command-line-args-left)
177                  (setq command-line-args-left
178                        (cdr command-line-args-left))))
179          (or (string= "NONE" package-dir)
180              (setq PACKAGEDIR package-dir))))
181   ;; Load some APEL modules from this directory.
182   (defvar default-load-path load-path)
183   (setq load-path (cons (expand-file-name ".") load-path))
184   (require 'poe)
185   (require 'path-util)
186   (require 'install)
187
188   ;; Import `apel-modules'.
189   (load-file "APEL-ELS")
190   ;; Import `emu-modules' and `emu-modules-to-compile'.
191   (load-file "EMU-ELS")
192
193   ;; Set PACKAGEDIR if not set yet.
194   (or PACKAGEDIR
195       (setq PACKAGEDIR
196             (if (boundp 'early-packages)
197                 (let ((dirs (append (if early-package-load-path
198                                         early-packages)
199                                     (if late-package-load-path
200                                         late-packages)
201                                     (if last-package-load-path
202                                         last-packages)))
203                       dir)
204                   (while (not (file-exists-p (setq dir (car dirs))))
205                     (setq dirs (cdr dirs)))
206                   dir))))
207   (if PACKAGEDIR
208       (princ (format "\nPACKAGEDIR=%s\n" PACKAGEDIR))
209     (error "XEmacs package system is not available")))
210
211 (defun compile-apel-package ()
212   (config-apel-package)
213   ;; Compile emu modules first.
214   (compile-elisp-modules emu-modules-to-compile ".")
215   (compile-elisp-modules apel-modules           "."))
216
217 (defun install-apel-package ()
218   (config-apel-package)
219   (let ((just-print (install-just-print-p))
220         (dir (expand-file-name APEL_PREFIX
221                                (expand-file-name "lisp" PACKAGEDIR))))
222     (install-elisp-modules emu-modules  "." dir just-print)
223     (install-elisp-modules apel-modules "." dir just-print)
224     (install-update-package-files "apel" dir just-print)))
225
226 (defun what-where-apel ()
227   (config-apel)
228   (princ (format "
229 The files that belong to the EMU modules:
230   %s
231   -> %s
232
233 The files that belong to the APEL modules:
234   %s
235   -> %s
236
237 Do `make elc', `make install', `make package', or `make install-package'.
238 "
239                  (mapconcat (function symbol-name) emu-modules ", ")
240                  EMU_DIR
241                  (mapconcat (function symbol-name) apel-modules ", ")
242                  APEL_DIR)))
243
244 ;;; APEL-MK ends here