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")))
121 (defun file-names (pathname)
122 (if (or (< 8 (length (pathname-name pathname)))
123 (< 3 (length (pathname-type pathname))))
124 (let ((short-name (let ((name (pathname-name pathname)))
125 (if (< 8 (length name))
128 (short-type (let ((type (pathname-type pathname)))
129 (if (< 3 (length type))
130 (or (cdr (assoc type *pathname-type-abbrevs* :test #'equalp))
131 (error "No abbreviation for type: ~A" type))
133 (list "Name" (if short-type
134 (format nil "~A.~A" short-name short-type)
136 "LongName" (file-namestring pathname)))
137 (list "Name" (file-namestring pathname))))
139 (defparameter *components* nil)
141 (defun component-id (pathname)
142 (let ((id (id (format nil "Contrib_~A" (enough-namestring pathname *sbcl-source-root*)))))
143 (push id *components*)
146 (defun ref-all-components ()
149 `("ComponentRef" ("Id" ,id)))
151 (setf *components* nil)))
153 (defun collect-1-component (root)
154 `("Directory" ("Id" ,(directory-id root)
155 ,@(directory-names root))
156 ("Component" ("Id" ,(component-id root)
159 ,@(loop for file in (directory
160 (make-pathname :name :wild :type :wild :defaults root))
161 when (or (pathname-name file) (pathname-type file))
162 collect `("File" ("Id" ,(file-id file)
164 "Source" ,(enough-namestring file)))))))
166 (defun collect-components (root)
167 (cons (collect-1-component root)
168 (loop for directory in
170 (merge-pathnames (make-pathname
171 :directory '(:relative :wild)
174 unless (member (car (last (pathname-directory directory)))
175 *ignored-directories* :test #'equal)
176 append (collect-components directory))))
178 (defun collect-contrib-components ()
179 (loop for contrib in (directory "../contrib/*/test-passed")
180 append (collect-components (make-pathname :name nil
183 :defaults contrib))))
185 (defun make-extension (type mime)
186 `("Extension" ("Id" ,type "ContentType" ,mime)
187 ("Verb" ("Id" ,(format nil "load_~A" type)
188 "Argument" "--core \"[#sbcl.core]\" --load \"%1\""
189 "Command" "Load with SBCL"
190 "Target" "[#sbcl.exe]"))))
192 (defun write-wxs (pathname)
193 ;; both :INVERT and :PRESERVE could be used here, but this seemed
194 ;; better at the time
197 `("Wix" ("xmlns" "http://schemas.microsoft.com/wix/2003/01/wi")
198 ("Product" ("Id" "????????-????-????-????-????????????"
199 "Name" ,(application-name)
200 "Version" ,(lisp-implementation-version)
201 "Manufacturer" "http://www.sbcl.org"
203 ("Package" ("Id" "????????-????-????-????-????????????"
204 "Manufacturer" "http://www.sbcl.org"
205 "InstallerVersion" 200
210 ("Directory" ("Id" "TARGETDIR"
212 ("Directory" ("Id" "ProgramMenuFolder"
214 ("Directory" ("Id" "ProgramFilesFolder"
216 ("Directory" ("Id" "BaseFolder"
218 "LongName" "Steel Bank Common Lisp")
219 ("Directory" ("Id" "VersionFolder"
220 "Name" ,(lisp-implementation-version))
221 ("Directory" ("Id" "INSTALLDIR")
222 ("Component" ("Id" "SBCL_Base"
225 ("Environment" ("Id" "Env_SBCL_HOME"
229 "Value" "[INSTALLDIR]"))
230 ("Environment" ("Id" "Env_PATH"
234 "Value" "[INSTALLDIR]"))
235 ,(make-extension "fasl" "application/x-lisp-fasl")
236 ,(make-extension "lisp" "text/x-lisp-source")
237 ("File" ("Id" "sbcl.exe"
239 "Source" "../src/runtime/sbcl.exe")
240 ("Shortcut" ("Id" "sbcl.lnk"
241 "Directory" "ProgramMenuFolder"
243 "LongName" ,(application-name)
244 "Arguments" "--core \"[#sbcl.core]\"")))
245 ("File" ("Id" "sbcl.core"
247 "LongName" "sbcl.core"
248 "Source" "sbcl.core")))
249 ,@(collect-contrib-components))))))
250 ("Feature" ("Id" "Minimal"
251 "ConfigurableDirectory" "INSTALLDIR"
253 ("ComponentRef" ("Id" "SBCL_Base"))
254 ,@(ref-all-components))
255 ("Property" ("Id" "WIXUI_INSTALLDIR" "Value" "INSTALLDIR"))
256 ("UIRef" ("Id" "WixUI_InstallDir"))))))