Changeset 12676


Ignore:
Timestamp:
Aug 25, 2009, 5:51:59 PM (10 years ago)
Author:
palter
Message:

Beginnings of support for building standalone Windows applications using Cocotron.
Tweak SAVE-APPLICATION to set the Windows subsystem byte in the executable file's
header appropriately (i.e., to either GUI or console). Update BUILD-APPLICATION
and BUILD-IDE to save GUI applications.

The IDE actually runs standalone!

BUILD-APPLICATION needs more work to get the frameworks into the bundle.
(The code which does that is only loaded when building the IDE so a bit of
refactoring is in order.)

Location:
trunk/source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/build-application.lisp

    r9827 r12676  
    5151         ;; create the bundle directory
    5252         (app-bundle (make-application-bundle :name name :project-path directory))
    53          (image-path (namestring (path app-bundle "Contents" "MacOS" name))))
     53         (image-path (namestring (path (bundle-executable-path app-bundle)
     54                                       (bundle-executable-name name)))))
    5455    ;; maybe copy IDE resources to the bundle
    5556    (when copy-ide-resources
     
    7576                      :application-class application-class
    7677                      :toplevel-function toplevel-function
    77                       :prepend-kernel t)))
     78                      :prepend-kernel t
     79                      #+windows-target #+windows-target
     80                      :application-type :gui)))
    7881
    7982
  • trunk/source/cocoa-ide/builder-utilities.lisp

    r11593 r12676  
    263263           (type-str (%make-nsstring package-type))
    264264           (sig-str (%make-nsstring bundle-signature))
    265            (app-name-str (%make-nsstring name))
     265           (app-name-str (%make-nsstring (bundle-executable-name name)))
    266266           (app-plist-path-str (%make-nsstring (namestring out-path))))
    267267      (#/setValue:forKey: info-dict bundle-name-str $cfbundle-bundle-name-key)
     
    300300    (read-info-plist ide-plist-path-str)))
    301301
     302;;; BUNNDLE-EXECUTABLE-PATH app-path
     303;;; ------------------------------------------------------------------------
     304;;; Returns the pathname of the executable directory given the pathname of
     305;;; an application bundle
     306(defun bundle-executable-path (app-path)
     307  (path app-path "Contents"
     308        #-windows-target (ensure-directory-pathname "MacOS")
     309        #+windows-target (ensure-directory-pathname "Windows")))
     310
     311;;; BUNNDLE-EXECUTABLE-NAME name
     312;;; ------------------------------------------------------------------------
     313;;; Returns the name of the executable file for an application bundle
     314(defun bundle-executable-name (name)
     315  #-windows-target name
     316  #+windows-target (concatenate 'string name ".exe"))
     317
    302318;;; MAKE-APPLICATION-BUNDLE name package-type bundle-signature project-path
    303319;;; ------------------------------------------------------------------------
     
    310326                           (ensure-directory-pathname (concatenate 'string name ".app"))))
    311327         (contents-dir (path app-bundle (ensure-directory-pathname "Contents")))
    312          (macos-dir (path contents-dir (ensure-directory-pathname "MacOS")))
     328         (executable-dir (bundle-executable-path app-bundle))
    313329         (rsrc-dir (path contents-dir  "Resources"
    314330                         (ensure-directory-pathname "English.lproj"))))
    315     (ensure-directories-exist macos-dir)
     331    (ensure-directories-exist executable-dir)
    316332    (ensure-directories-exist rsrc-dir)
    317333    app-bundle))
  • trunk/source/cocoa-ide/start.lisp

    r12641 r12676  
    153153      (save-application image-file
    154154                        :prepend-kernel t
    155                         :application-class 'cocoa-application)))
     155                        :application-class 'cocoa-application
     156                        #+windows-target #+windows-target
     157                        :application-type :gui)))
    156158
    157159;;; If we're running as a standalone .app, try to see if a bundle named
  • trunk/source/lib/dumplisp.lisp

    r12167 r12676  
    7373                         (mode #o644)
    7474                         prepend-kernel
    75                          )
     75                         #+windows-target (application-type :console))
    7676  (declare (ignore toplevel-function error-handler application-class
    7777                   clear-clos-caches init-file impurify))
     78  #+windows-target (check-type application-type (member :console :gui))
    7879  (unless (probe-file (make-pathname :defaults nil
    7980                                     :directory (pathname-directory (translate-logical-pathname filename))))
     
    8788      (let* ((fd (open-dumplisp-file filename
    8889                                     :mode mode
    89                                      :prepend-kernel prepend-kernel)))
     90                                     :prepend-kernel prepend-kernel
     91                                     #+windows-target  #+windows-target
     92                                     :application-type application-type)))
    9093        (process-interrupt ip
    9194                           #'(lambda ()
     
    109112                                      (init-file nil init-file-p)
    110113                                      (clear-clos-caches t)
    111                                       prepend-kernel)
    112   (declare (ignore mode prepend-kernel))
     114                                      prepend-kernel
     115                                      #+windows-target application-type)
     116  (declare (ignore mode prepend-kernel #+windows-target application-type))
    113117  (when (and application-class (neq  (class-of *application*)
    114118                                     (if (symbolp application-class)
     
    190194                 
    191195 
    192 (defun %prepend-file (out-fd in-fd len)
     196(defun %prepend-file (out-fd in-fd len #+windows-target application-type)
    193197  (declare (fixnum out-fd in-fd len))
    194198  (fd-lseek in-fd 0 #$SEEK_SET)
    195   (let* ((bufsize (ash 1 15)))
     199  (let* ((bufsize (ash 1 15))
     200         #+windows-target (first-buf t))
    196201    (%stack-block ((buf bufsize))
    197202      (loop
     
    201206            (if (< nread 0)
    202207              (%errno-disp nread))
    203             (let* ((nwritten (fd-write out-fd buf nread)))
     208            #+windows-target
     209            (when (shiftf first-buf nil)
     210              (let* ((application-byte (ecase application-type
     211                                         (:console #$IMAGE_SUBSYSTEM_WINDOWS_CUI)
     212                                         (:gui #$IMAGE_SUBSYSTEM_WINDOWS_GUI)))
     213                     (offset (%get-long buf #x3c)))
     214                (assert (< offset bufsize) () "PEF header not within first ~D bytes" bufsize)
     215                (assert (= (%get-byte buf (+ offset 0)) (char-code #\P)) ()
     216                        "File does not appear to be a PEF file")
     217                (assert (= (%get-byte buf (+ offset 1)) (char-code #\E)) ()
     218                        "File does not appear to be a PEF file")
     219                (assert (= (%get-byte buf (+ offset 2)) 0) ()
     220                        "File does not appear to be a PEF file")
     221                (assert (= (%get-byte buf (+ offset 3)) 0) ()
     222                        "File does not appear to be a PEF file")
     223                ;; File is a PEF file -- Windows subsystem byte goes at offset 68 in the
     224                ;;  "optional header" which appears right after the standard header (20 bytes)
     225                ;;  and the PEF cookie (4 bytes)
     226                (setf (%get-byte buf (+ offset 4 20 68)) application-byte)))
     227            (let* ((nwritten (fd-write out-fd buf nread)))
    204228              (declare (fixnum nwritten))
    205229              (unless (= nwritten nread)
     
    221245
    222246
    223 (defun open-dumplisp-file (path &key (mode #o666) prepend-kernel)
     247(defun open-dumplisp-file (path &key (mode #o666) prepend-kernel
     248                           #+windows-target application-type)
    224249  (let* ((prepend-path (if prepend-kernel
    225250                         (if (eq prepend-kernel t)
     
    239264    (let* ((image-fd (fd-open filename (logior #$O_WRONLY #$O_CREAT) mode)))
    240265      (unless (>= image-fd 0) (signal-file-error image-fd filename))
     266      (when prepend-fd
     267        (%prepend-file image-fd prepend-fd prepend-len #+windows-target application-type))
    241268      (fd-chmod image-fd mode)
    242       (when prepend-fd
    243         (%prepend-file image-fd prepend-fd prepend-len))
    244269      image-fd)))
    245270
Note: See TracChangeset for help on using the changeset viewer.