1 | ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: cl-user -*- |
---|
2 | ;;;; *********************************************************************** |
---|
3 | ;;;; FILE IDENTIFICATION |
---|
4 | ;;;; |
---|
5 | ;;;; Name: build-application.lisp |
---|
6 | ;;;; Version: 0.9 |
---|
7 | ;;;; Project: Cocoa application builder |
---|
8 | ;;;; Purpose: the in-process application builder |
---|
9 | ;;;; |
---|
10 | ;;;; *********************************************************************** |
---|
11 | |
---|
12 | (require "builder-utilities") |
---|
13 | |
---|
14 | (in-package :ccl) |
---|
15 | |
---|
16 | ;;; about copying nibfiles |
---|
17 | |
---|
18 | ;;; when building an app bundle, we copy nibfiles from the development |
---|
19 | ;;; environment appplication bundle into the newly-created application |
---|
20 | ;;; bundle. If user-supplied nibfiles are given the same names as |
---|
21 | ;;; nibfiles from the development environment, we signal an error and |
---|
22 | ;;; refuse to copy the user nibfiles. This treatment ensures that users |
---|
23 | ;;; will not accidentally clobber dev-environment nibfiles, but also |
---|
24 | ;;; means that they must give unique names to their own nibs in order |
---|
25 | ;;; to use them with their saved applications. |
---|
26 | |
---|
27 | ;;; in future, we may add options to suppress the copying of |
---|
28 | ;;; dev-environment nibfiles. |
---|
29 | |
---|
30 | (defun build-application (&key |
---|
31 | (name $default-application-bundle-name) |
---|
32 | (type-string $default-application-type-string) |
---|
33 | (creator-string $default-application-creator-string) |
---|
34 | (directory (current-directory)) |
---|
35 | (copy-ide-resources t) ; whether to copy the IDE's resources |
---|
36 | (nibfiles nil) ; a list of user-specified nibfiles |
---|
37 | ; to be copied into the app bundle |
---|
38 | (main-nib-name) ; the name of the nib that is to be loaded |
---|
39 | ; as the app's main. this name gets written |
---|
40 | ; into the Info.plist on the "NSMainNibFile" key |
---|
41 | (application-class 'gui::cocoa-application) |
---|
42 | (toplevel-function nil)) |
---|
43 | |
---|
44 | (let* ((ide-bundle (#/mainBundle ns:ns-bundle)) |
---|
45 | (ide-bundle-path-nsstring (#/bundlePath ide-bundle)) |
---|
46 | (ide-bundle-path (pathname |
---|
47 | (ensure-directory-pathname |
---|
48 | (lisp-string-from-nsstring ide-bundle-path-nsstring)))) |
---|
49 | ;; create the bundle directory |
---|
50 | (app-bundle (make-application-bundle name type-string creator-string directory |
---|
51 | :main-nib-name main-nib-name)) |
---|
52 | (image-path (namestring (path app-bundle "Contents" "MacOS" name)))) |
---|
53 | ;; copy IDE resources to the bundle |
---|
54 | (when copy-ide-resources |
---|
55 | (recursive-copy-directory (path ide-bundle-path "Contents" "Resources/") |
---|
56 | (path app-bundle "Contents" "Resources/") |
---|
57 | :if-exists :overwrite)) |
---|
58 | ;; copy user nibfiles into the bundle |
---|
59 | (when nibfiles |
---|
60 | (let ((nib-paths (mapcar #'pathname nibfiles))) |
---|
61 | (assert (and (every #'probe-file nib-paths)) |
---|
62 | (nibfiles) |
---|
63 | "The nibfiles parameter must be a list of valid pathnames to existing files or directories") |
---|
64 | (dolist (n nib-paths) |
---|
65 | (let ((dest (path app-bundle "Contents" "Resources" "English.lproj/"))) |
---|
66 | (copy-nibfile n dest :if-exists :overwrite))))) |
---|
67 | ;; save the application image into the bundle |
---|
68 | (save-application image-path |
---|
69 | :application-class application-class |
---|
70 | :toplevel-function toplevel-function |
---|
71 | :prepend-kernel t))) |
---|
72 | |
---|
73 | #| |
---|
74 | (require :build-application) |
---|
75 | (load "/usr/local/ccl/trunk/source/cocoa-ide/builder-utilities.lisp") |
---|
76 | (ccl::build-application :name "Foo" |
---|
77 | :directory "/Users/mikel/Desktop" |
---|
78 | :copy-ide-resources t) |
---|
79 | |# |
---|