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