source: trunk/base/src/port1.0/resources/group/xcode-1.0.tcl @ 30775

Last change on this file since 30775 was 30775, checked in by jmpp@…, 10 years ago

Include forgotten modeline.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
2# xcode.tcl
3#
4# $Id: xcode-1.0.tcl 30775 2007-11-06 20:10:11Z jmpp@macports.org $
5#
6# Copyright (c) 2005 Paul Guyot <pguyot@kallisys.net>,
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are
11# met:
12#
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Computer, Inc. nor the names of its
19#    contributors may be used to endorse or promote products derived from
20#    this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34
35# Group code for xcode-based ports.
36# These includes applications and frameworks (or actually whatever you want
37# that might usefully take advantage of the code below).
38#
39# base/ provides stuff prefixed with xcode without a dot:
40# - extraction of xcode version to $xcodeversion
41# - extraction of xcode/pbx command line tool to $xcodebuildcmd
42#
43# This group provides:
44#  categories set to aqua
45#  platforms set to macosx
46#  use_configure set to no
47#  build procedure
48#  destroot procedure
49#  build.cmd set to $xcodebuildcmd
50#  build.args set to build
51#  destroot.cmd set to $xcodebuildcmd
52#  destroot.args set to install
53#
54# build and destroot parameters use the following parameters:
55#  PortGroup specific parameters:
56#   xcode.project           name (or path relative to build.dir) of the xcode
57#                           project. Default is "" meaning let xcodebuild figure it
58#                           out.
59#   xcode.configuration     xcode buildstyle/configuration. Default is Deployment.
60#   xcode.target            if present, overrides build.target and destroot.target
61#   xcode.build.settings    additional settings passed to $xcodebuildcmd (in
62#                           the X=Y form)
63#   xcode.destroot.type     install type (application or framework). Default is
64#                           application. This setting overrides xcode.destroot.path.
65#   xcode.destroot.path     install path (INSTALL_PATH setting value).
66#   xcode.destroot.settings additional settings passed to $xcodebuildcmd (in
67#                           the X=Y form)
68#
69#  Usual parameters:
70#   destroot            where to destroot the project.
71#   build.cmd           normally set to $xcodebuildcmd earlier.
72#   build.target        xcode target(s) to build.
73#   build.pre_args      additional parameters for xcodebuildcmd when building
74#   build.args          normally set to build
75#   build.post_args     additional parameters for xcodebuildcmd when building
76#   build.dir           directory where to build the project (where xcode
77#                       project is)
78#   destroot.cmd        normally set to $xcodebuildcmd earlier.
79#   destroot.target     xcode target(s) to install
80#   destroot.pre_args   additional parameters for xcodebuildcmd when installing
81#   destroot.args       normally set to install
82#   destroot.post_args  additional parameters for xcodebuildcmd when installing
83#   destroot.dir        directory where to run destroot command the project
84#                       (where xcode project is)
85
86# Options this group provides:
87default categories          aqua
88default platforms           macosx
89default use_configure       no
90default build.cmd           $xcodebuildcmd
91default build.args          build
92default build.pre_args      {}
93default build.target        ""
94default destroot.cmd        $xcodebuildcmd
95default destroot.args       install
96default destroot.pre_args   {}
97default destroot.target     ""
98default destroot.destdir    {DSTROOT="${destroot}"}
99
100# Default values for parameters.
101options xcode.project
102default xcode.project ""
103options xcode.target
104default xcode.target ""
105options xcode.configuration
106default xcode.configuration Deployment
107options xcode.build.settings
108default xcode.build.settings ""
109options xcode.destroot.type
110default xcode.destroot.type "application"
111options xcode.destroot.path
112default xcode.destroot.path ""
113options xcode.destroot.settings
114default xcode.destroot.settings ""
115
116namespace eval xcode {}
117
118# Some utility functions.
119# get the project directory (where build/ is).
120proc xcode::get_project_path {} {
121    global xcode.project worksrcpath
122    if {${xcode.project} == ""} {
123        set suffix ""
124    } else {
125        set suffix [file dirname ${xcode.project}]
126    }
127    return [file normalize "${worksrcpath}/${suffix}"]
128}
129
130# fix resource dependencies (with Xcode >= 2.1).
131proc xcode::fix_resource_dependencies {} {
132    global xcodeversion xcode.configuration
133    if {$xcodeversion == "2.1"} {
134        set build_path "[xcode::get_project_path]/build/"
135        set config_build_path "[xcode::get_project_path]/build/${xcode.configuration}/"
136        if {[file isdirectory ${config_build_path}]} {
137            foreach resource [glob "${config_build_path}*"] {
138                set resource_name [file tail $resource]
139                if {![file exists $build_path/$resource_name]} {
140                    file link $build_path/$resource_name $config_build_path/$resource_name
141                }
142            }
143        }
144    }
145}
146
147# get the configuration/buildstyle argument.
148proc xcode::get_configuration_arg { style } {
149    global xcodeversion
150    if {$style != ""} {
151        if {$xcodeversion == "2.1"} {
152            return "-configuration $style"
153        } else {
154            return "-buildstyle $style"
155        }
156    } else {
157        return ""
158    }
159}
160
161# get the project argument.
162proc xcode::get_project_arg { project } {
163    if {$project != ""} {
164        return "-project $project"
165    } else {
166        return ""
167    }
168}
169
170# get the install path setting
171# remark: xcodebuild take care of creating the directory if required.
172proc xcode::get_install_path_setting { path type } {
173    if {$path == ""} {
174        if {$type == "application"} {
175            return "INSTALL_PATH=/Applications/MacPorts"
176        } elseif {$type == "framework"} {
177            return "INSTALL_PATH=/Library/Frameworks"
178        } else {
179            return ""
180        }
181    } else {
182        return "INSTALL_PATH=\"$path\""
183    }
184}
185
186# setup command line.
187proc xcode::setup_command_line {command args settings} {
188    global ${command}.dir ${command}.env ${command}.cmd ${command}.pre_args \
189        ${command}.args ${command}.post_args
190
191    # Check that xcode is installed.
192    if {[set ${command}.cmd] == "none"} {
193        return -code error "This port requires 'pbxbuild/xcodebuild', which \
194    couldn't be found (not MacOS X?)"
195    }
196
197    set cmdstring ""
198    if {[info exists ${command}.dir]} {
199        set cmdstring "cd \"[set ${command}.dir]\" &&"
200    }
201    if {[info exists ${command}.env]} {
202        foreach string [set ${command}.env] {
203            set cmdstring "$cmdstring $string"
204        }
205    }
206    if {[info exists ${command}.cmd]} {
207        foreach string [set ${command}.cmd] {
208            set cmdstring "$cmdstring $string"
209        }
210    } else {
211        return -code error "No ${command}.cmd was specified"
212    }
213    if {[info exists ${command}.pre_args]} {
214        foreach string [set ${command}.pre_args] {
215            set cmdstring "$cmdstring $string"
216        }
217    }
218    set cmdstring "$cmdstring $args"
219    if {[info exists ${command}.args]} {
220        foreach string [set ${command}.args] {
221            set cmdstring "$cmdstring $string"
222        }
223    }
224    set cmdstring "$cmdstring $settings"
225    if {[info exists ${command}.post_args]} {
226        foreach string [set ${command}.post_args] {
227            set cmdstring "$cmdstring $string"
228        }
229    }
230    ui_debug "Assembled command: '$cmdstring'"
231    return $cmdstring
232}
233
234# build one target.
235proc xcode::build_one_target {args settings} {
236    set cmdstring [xcode::setup_command_line build $args $settings]
237    system "$cmdstring"
238}
239
240# destroot one target.
241proc xcode::destroot_one_target {args settings} {
242    set cmdstring [xcode::setup_command_line destroot $args $settings]
243    system "$cmdstring"
244}
245
246# build procedure.
247build {
248    # determine the targets.
249    if {${xcode.target} != ""} {
250        set xcode_targets ${xcode.target}
251    } else {
252        set xcode_targets ${build.target}
253    }
254   
255    # set some arguments.
256    set xcode_configuration_arg [xcode::get_configuration_arg ${xcode.configuration}]
257    set xcode_project_arg [xcode::get_project_arg ${xcode.project}]
258    set xcode_build_args "OBJROOT=build/ SYMROOT=build/"
259   
260    # iterate on targets if there is any, do -alltargets otherwise.
261    if {"$xcode_targets" == ""} {
262        xcode::build_one_target \
263            "$xcode_project_arg -alltargets $xcode_configuration_arg" \
264            "$xcode_build_args ${xcode.build.settings}"
265    } else {
266        foreach target $xcode_targets {
267            xcode::build_one_target \
268                "$xcode_project_arg -target \"$target\" $xcode_configuration_arg" \
269                "$xcode_build_args ${xcode.build.settings}"
270        }
271    }
272}
273
274# destroot procedure.
275destroot {
276    # let Xcode 2.1+ find resources.
277    xcode::fix_resource_dependencies
278   
279    # determine the targets.
280    if {${xcode.target} != ""} {
281        set xcode_targets ${xcode.target}
282    } else {
283        set xcode_targets ${destroot.target}
284    }
285   
286    # set some arguments.
287    set xcode_configuration_arg [xcode::get_configuration_arg ${xcode.configuration}]
288    set xcode_project_arg [xcode::get_project_arg ${xcode.project}]
289    set xcode_install_path_setting [xcode::get_install_path_setting \
290                                        ${xcode.destroot.path} ${xcode.destroot.type}]
291    set xcode_build_args "OBJROOT=build/ SYMROOT=build/"
292   
293    # iterate on targets if there is any, do -alltargets otherwise.
294    if {"$xcode_targets" == ""} {
295        xcode::destroot_one_target \
296            "$xcode_project_arg -alltargets $xcode_configuration_arg" \
297            "$xcode_install_path_setting $xcode_build_args ${xcode.destroot.settings}"
298    } else {
299        foreach target $xcode_targets {
300            xcode::destroot_one_target \
301                "$xcode_project_arg -target \"$target\" $xcode_configuration_arg" \
302                "$xcode_install_path_setting $xcode_build_args ${xcode.destroot.settings}"
303        }
304    }
305}
Note: See TracBrowser for help on using the repository browser.