1 ;;;; Generate WiX XML Source, from which we eventually generate the .MSI
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 (defvar *indent-level* 0)
16 (defvar *sbcl-source-root*
18 (merge-pathnames (make-pathname :directory (list :relative :up))
19 (make-pathname :name nil :type nil :defaults *load-truename*))))
21 (defun print-xml (sexp &optional (stream *standard-output*))
22 (destructuring-bind (tag &optional attributes &body children) sexp
23 (when attributes (assert (evenp (length attributes))))
24 (format stream "~VT<~A~{ ~A='~A'~}~@[/~]>~%"
25 *indent-level* tag attributes (not children))
26 (let ((*indent-level* (+ *indent-level* 3)))
27 (dolist (child children)
29 (error "Malformed child: ~S in ~S" child children))
30 (print-xml child stream)))
32 (format stream "~VT</~A>~%" *indent-level* tag))))
34 (defun xml-1.0 (pathname sexp)
35 (with-open-file (xml pathname :direction :output :if-exists :supersede
36 :external-format :ascii)
37 (format xml "<?xml version='1.0'?>")
38 (print-xml sexp xml)))
40 (defun application-name ()
41 (format nil "SBCL ~A" (lisp-implementation-version)))
45 ;;;; Apparently this willy-nilly regeneration of GUIDs is a bad thing, and
46 ;;;; we should probably have a single GUID per release / Component, so
47 ;;;; that no matter by whom the .MSI is built the GUIDs are the same.
49 ;;;; Something to twiddle on a rainy day, I think.
51 (load-shared-object "OLE32.DLL")
53 (define-alien-type uuid
56 (data2 unsigned-short)
57 (data3 unsigned-short)
58 (data4 (array unsigned-char 8))))
60 (define-alien-routine ("CoCreateGuid" co-create-guid) int (guid (* uuid)))
62 (defun uuid-string (uuid)
63 (declare (type (alien (* uuid)) uuid))
64 (let ((data4 (slot uuid 'data4)))
65 (format nil "~8,'0X-~4,'0X-~4,'0X-~2,'0X~2,'0X-~{~2,'0X~}"
71 (loop for i from 2 upto 7 collect (deref data4 i)))))
77 (setf guid (make-alien (struct uuid)))
82 (defun list-all-contribs ()
83 (loop for flag in (directory "../contrib/*/test-passed")
84 collect (car (last (pathname-directory flag)))))
86 (defvar *id-char-substitutions* '((#\\ . #\_)
92 ;; Mangle a string till it can be used as an Id. A-Z, a-z, 0-9, and
93 ;; _ are ok, nothing else is.
94 (map 'string (lambda (c)
95 (or (cdr (assoc c *id-char-substitutions*))
99 (defun directory-id (name)
100 (id (format nil "Directory_~A" (enough-namestring name *sbcl-source-root*))))
102 (defun directory-names (pathname)
103 (let ((name (car (last (pathname-directory pathname)))))
104 (if (< 8 (length name))
105 (list "Name" (subseq name 0 8)
107 (list "Name" name))))
109 (defun file-id (pathname)
110 (id (format nil "File_~A" (enough-namestring pathname *sbcl-source-root*))))
112 (defparameter *ignored-directories* '("CVS" ".svn"))
114 (defparameter *pathname-type-abbrevs*
117 ("SBCL" . "txt") ; README.SBCL -> README.txt
119 ("lisp-temp" . "lmp")
122 (defun file-names (pathname)
123 (if (or (< 8 (length (pathname-name pathname)))
124 (< 3 (length (pathname-type pathname))))
125 (let ((short-name (let ((name (pathname-name pathname)))
126 (if (< 8 (length name))
129 (short-type (let ((type (pathname-type pathname)))
130 (if (< 3 (length type))
131 (or (cdr (assoc type *pathname-type-abbrevs* :test #'equalp))
132 (error "No abbreviation for type: ~A" type))
134 (list "Name" (if short-type
135 (format nil "~A.~A" short-name short-type)
137 "LongName" (file-namestring pathname)))
138 (list "Name" (file-namestring pathname))))
140 (defparameter *components* nil)
142 (defun component-id (pathname)
143 (let ((id (id (format nil "Contrib_~A" (enough-namestring pathname *sbcl-source-root*)))))
144 (push id *components*)
147 (defun ref-all-components ()
150 `("ComponentRef" ("Id" ,id)))
152 (setf *components* nil)))
154 (defun collect-1-component (root)
155 `("Directory" ("Id" ,(directory-id root)
156 ,@(directory-names root))
157 ("Component" ("Id" ,(component-id root)
160 ,@(loop for file in (directory
161 (make-pathname :name :wild :type :wild :defaults root))
162 when (or (pathname-name file) (pathname-type file))
163 collect `("File" ("Id" ,(file-id file)
165 "Source" ,(enough-namestring file)))))))
167 (defun collect-components (root)
168 (cons (collect-1-component root)
169 (loop for directory in
171 (merge-pathnames (make-pathname
172 :directory '(:relative :wild)
175 unless (member (car (last (pathname-directory directory)))
176 *ignored-directories* :test #'equal)
177 append (collect-components directory))))
179 (defun collect-contrib-components ()
180 (loop for contrib in (directory "../contrib/*/test-passed")
181 append (collect-components (make-pathname :name nil
184 :defaults contrib))))
186 (defun make-extension (type mime)
187 `("Extension" ("Id" ,type "ContentType" ,mime)
188 ("Verb" ("Id" ,(format nil "load_~A" type)
189 "Argument" "--core \"[#sbcl.core]\" --load \"%1\""
190 "Command" "Load with SBCL"
191 "Target" "[#sbcl.exe]"))))
193 (defun write-wxs (pathname)
194 ;; both :INVERT and :PRESERVE could be used here, but this seemed
195 ;; better at the time
198 `("Wix" ("xmlns" "http://schemas.microsoft.com/wix/2003/01/wi")
199 ("Product" ("Id" "????????-????-????-????-????????????"
200 "Name" ,(application-name)
201 "Version" ,(lisp-implementation-version)
202 "Manufacturer" "http://www.sbcl.org"
204 ("Package" ("Id" "????????-????-????-????-????????????"
205 "Manufacturer" "http://www.sbcl.org"
206 "InstallerVersion" 200
211 ("Directory" ("Id" "TARGETDIR"
213 ("Directory" ("Id" "ProgramMenuFolder"
215 ("Directory" ("Id" "ProgramFilesFolder"
217 ("Directory" ("Id" "BaseFolder"
219 "LongName" "Steel Bank Common Lisp")
220 ("Directory" ("Id" "VersionFolder"
221 "Name" ,(lisp-implementation-version))
222 ("Directory" ("Id" "INSTALLDIR")
223 ("Component" ("Id" "SBCL_Base"
226 ("Environment" ("Id" "Env_SBCL_HOME"
230 "Value" "[INSTALLDIR]"))
231 ("Environment" ("Id" "Env_PATH"
235 "Value" "[INSTALLDIR]"))
236 ;; If we want to associate files with SBCL, this
237 ;; is how it's done -- but doing this by default
238 ;; and without asking the user for permission Is
239 ;; Bad. Before this is enabled we need to figure out
240 ;; how to make WiX ask for permission for this...
241 ;; ,(make-extension "fasl" "application/x-lisp-fasl")
242 ;; ,(make-extension "lisp" "text/x-lisp-source")
243 ("File" ("Id" "sbcl.exe"
245 "Source" "../src/runtime/sbcl.exe")
246 ("Shortcut" ("Id" "sbcl.lnk"
247 "Directory" "ProgramMenuFolder"
249 "LongName" ,(application-name)
250 "Arguments" "--core \"[#sbcl.core]\"")))
251 ("File" ("Id" "sbcl.core"
253 "LongName" "sbcl.core"
254 "Source" "sbcl.core")))
255 ,@(collect-contrib-components))))))
256 ("Feature" ("Id" "Minimal"
257 "ConfigurableDirectory" "INSTALLDIR"
259 ("ComponentRef" ("Id" "SBCL_Base"))
260 ,@(ref-all-components))
261 ("Property" ("Id" "WIXUI_INSTALLDIR" "Value" "INSTALLDIR"))
262 ("UIRef" ("Id" "WixUI_InstallDir"))))))