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