install-asdf-as-module 3.27 KB
Newer Older
1 2 3
":" ; exec cl-launch "$0" "$@" # -*- Lisp -*-
#|
Usage: ./tools/asdf-tools install-asdf-as-module l=lispworks
4 5 6 7 8 9 10 11 12 13 14

This script will install the current version of ASDF
as a module pre-compiled for your implementation,
as specified by option -l (--lisp) of cl-launch,
so you can (require "asdf") within your implementation
and have it load a recent ASDF instead of an outdated one.

This file requires cl-launch 4 and works on most implementations.
It notably doesn't work on:
* ABCL, that keeps ASDF in its jar, but that's OK because
 ABCL has a recent enough ASDF3 that is capable of upgrading itself.
15 16 17 18 19
* On MKCL and ECL, more work is needed to take into account
 the linkable variant of ASDF, that may be a .o or a .lib.
 Also, MKCL now delivers UIOP separately from ASDF, which is great,
 but requires support. Happily, both ECL and MKCL tend to sport
 a recent ASDF 3, too.
20 21 22
* GCL, that doesn't have a usable REQUIRE mechanism.
* mocl, that doesn't support ASDF 3 yet.
* Corman Lisp, RMCL, Genera, that are obsolete anyway.
23

24
|#
25 26 27 28 29 30 31
;;; Ensure we load and configure this particular ASDF
#-cl-launch
(eval-when (:compile-toplevel :load-toplevel :execute)
  (unless (member :cl-launch *features*) ;; (not necessary if we're invoked via cl-launch)
    (load (make-pathname
           :name "load-asdf" :type "lisp" :defaults
           (or *compile-file-truename* *load-truename* (truename *default-pathname-defaults*))))))
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

(in-package :asdf)

(defvar *asdf-dir*
  (ensure-pathname (system-relative-pathname :asdf ())
                   :want-physical t :want-absolute t
                   :want-existing t :truename t))

(defun asdf-module-directory ()
  #+allegro #p"sys:code;"
  #+clisp (subpathname custom:*lib-directory* "asdf/")
  #+clozure #p"ccl:tools;"
  #+cmu #p"modules:asdf/"
  #+(or ecl mkcl) #p"sys:"
  #+gcl system:*system-directory*
  #+lispworks (system:lispworks-dir "load-on-demand/utilities/")
  #+sbcl (subpathname (sb-int:sbcl-homedir-pathname) "contrib/")
  #+scl #p"file://modules/"
  #+xcl ext:*xcl-home*
  #-(or allegro clisp clozure cmu ecl gcl lispworks mkcl sbcl scl xcl)
  (error "asdf-module-directory not implemented on ~A" (implementation-type)))

(defun asdf-module-fasl ()
  #+allegro
  (flet ((pathname-key (x)
           (let ((type (pathname-type x)))
             (cond
               ((and (stringp type) (every #'digit-char-p type)) (parse-integer type))
               ((equal type "fasl") 0)
               (t -1)))))
    (first (sort (directory (merge-pathnames* "asdf.*" (asdf-module-directory)))
                 #'> :key #'pathname-key)))
  #+(or clisp clozure cmu ecl gcl lispworks mkcl sbcl scl xcl)
  (compile-file-pathname (subpathname (truename (asdf-module-directory)) "asdf.lisp"))
66 67
  ;; ECL and MKCL not really supported at this point. See above.
  #-(or allegro clisp clozure cmu gcl lispworks sbcl scl xcl)
68 69 70
  (error "Not implemented on ~A" (implementation-type)))

(defun install-asdf-as-module ()
71 72
  (let* ((fasl (asdf-module-fasl))
         (orig (add-pathname-suffix fasl "-orig")))
73
    (ensure-directories-exist (translate-logical-pathname fasl))
74 75 76
    (when (and (probe-file* fasl) (not (probe-file* orig)))
      (rename-file-overwriting-target fasl orig))
    (compile-file* (subpathname *asdf-dir* "build/asdf.lisp") :output-file fasl)))
77

78
(uiop:writeln (multiple-value-list (install-asdf-as-module)))