source: trunk/base/src/port1.0/portmain.tcl @ 89971

Last change on this file since 89971 was 89971, checked in by jberry@…, 9 years ago

Whitespace only: tabs to spaces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.6 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# portmain.tcl
3# $Id: portmain.tcl 89971 2012-02-17 18:27:49Z jberry@macports.org $
4#
5# Copyright (c) 2004 - 2005, 2007 - 2011 The MacPorts Project
6# Copyright (c) 2002 - 2003 Apple Inc.
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
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. Neither the name of Apple Inc. nor the names of its contributors
18#    may be used to endorse or promote products derived from this software
19#    without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34# the 'main' target is provided by this package
35# main is a magic target and should not be replaced
36
37package provide portmain 1.0
38package require portutil 1.0
39
40set org.macports.main [target_new org.macports.main portmain::main]
41target_provides ${org.macports.main} main
42target_state ${org.macports.main} no
43
44namespace eval portmain {
45}
46
47set_ui_prefix
48
49# define options
50options prefix name version revision epoch categories maintainers \
51        long_description description homepage notes license \
52        provides conflicts replaced_by \
53        worksrcdir filesdir distname portdbpath libpath distpath sources_conf \
54        os.platform os.subplatform os.version os.major os.arch os.endian \
55        platforms default_variants install.user install.group \
56        macosx_deployment_target universal_variant os.universal_supported \
57        supported_archs depends_skip_archcheck installs_libs \
58        license_noconflict copy_log_files \
59        compiler.cpath compiler.library_path \
60        add_users
61
62# Order of option_proc and option_export matters. Filter before exporting.
63
64# Assign option procedure to default_variants
65option_proc default_variants handle_default_variants
66# Handle notes special for better formatting
67option_proc notes handle_option_string
68
69# Export options via PortInfo
70options_export name version revision epoch categories maintainers platforms description long_description notes homepage license provides conflicts replaced_by installs_libs license_noconflict
71
72default subport {[portmain::get_default_subport]}
73proc portmain::get_default_subport {} {
74    global name portpath
75    if {[info exists name]} {
76        return $name
77    }
78    return [file tail $portpath]
79}
80default subbuildpath {[portmain::get_subbuildpath]}
81proc portmain::get_subbuildpath {} {
82    global portpath portbuildpath subport
83    if {$subport != ""} {
84        set subdir $subport
85    } else {
86        set subdir [file tail $portpath]
87    }
88    return [file join $portbuildpath $subdir]
89}
90default workpath {[getportworkpath_from_buildpath $subbuildpath]}
91default prefix /opt/local
92default applications_dir /Applications/MacPorts
93default frameworks_dir {${prefix}/Library/Frameworks}
94default developer_dir {[portmain::get_developer_dir]}
95default destdir destroot
96default destpath {${workpath}/${destdir}}
97# destroot is provided as a clearer name for the "destpath" variable
98default destroot {${destpath}}
99default filesdir files
100default revision 0
101default epoch 0
102default license unknown
103default distname {${name}-${version}}
104default worksrcdir {$distname}
105default filespath {[file join $portpath $filesdir]}
106default worksrcpath {[file join $workpath $worksrcdir]}
107# empty list means all archs are supported
108default supported_archs {}
109default depends_skip_archcheck {}
110default add_users {}
111
112# Configure settings
113default install.user {${portutil::autoconf::install_user}}
114default install.group {${portutil::autoconf::install_group}}
115
116# Platform Settings
117default os.platform {$os_platform}
118default os.version {$os_version}
119default os.major {$os_major}
120default os.arch {$os_arch}
121default os.endian {$os_endian}
122
123set macosx_version_text {}
124if {[option os.platform] == "darwin"} {
125    set macosx_version_text "(Mac OS X ${macosx_version}) "
126}
127ui_debug "OS [option os.platform]/[option os.version] ${macosx_version_text}arch [option os.arch]"
128
129default universal_variant {${use_configure}}
130
131# sub-platforms of darwin
132if {[option os.platform] == "darwin"} {
133    if {[file isdirectory /System/Library/Frameworks/Carbon.framework]} {
134        default os.subplatform macosx
135        # we're on Mac OS X and can therefore build universal
136        default os.universal_supported yes
137    } else {
138        default os.subplatform puredarwin
139        default os.universal_supported no
140    }
141} else {
142    default os.subplatform {}
143    default os.universal_supported no
144}
145
146default compiler.cpath {${prefix}/include}
147default compiler.library_path {${prefix}/lib}
148
149
150proc is_valid_developer_dir { dir } {
151    # Check whether specified directory looks valid for an Xcode installation
152   
153    # Verify that the directory exists
154    if {![file isdirectory $dir]} {
155        return 0
156    }
157   
158    # Verify that the directory has some key subdirectories
159    foreach subdir {Headers Library usr} {
160        if {![file isdirectory "${dir}/${subdir}"]} {
161            return 0
162        }
163    }
164   
165    # The specified directory seems valid for Xcode
166    return 1
167}
168
169
170proc get_xcode_suggestions {} {
171    # Ask mdfind where Xcode is
172    set result ""
173    if {![catch {set mdfind [binaryInPath mdfind]}]} {
174        set result [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
175    }
176    return $result
177}
178
179
180proc portmain::get_developer_dir {} {
181    set devdir ""
182
183    # Look for xcodeselect, and make sure it has a valid value
184    if {![catch {set xcodeselect [binaryInPath xcode-select]}]} {
185       
186        # We have xcodeselect: ask it where xcode is
187        set devdir [exec $xcodeselect -print-path 2> /dev/null]
188
189        # If the the directory is valid, use it
190        if {[is_valid_developer_dir $devdir]} {
191            return $devdir
192        }
193       
194        # The directory from xcodeselect isn't correct.
195        # Make some suggestions for the user
196        set installed_xcodes [get_xcode_suggestions]
197        if {[llength $installed_xcodes] == 0} {
198            # No installed Xcodes found
199            ui_error "No Xcode installation was found; please install Xcode"
200        } else {
201            # One, or more than one, Xcode installations found
202            ui_error "No valid Xcode installation is properly selected"
203           
204            ui_error
205            ui_error "Please use xcode-select to select an Xcode version:"
206            foreach xcode $installed_xcodes {
207                ui_error "    sudo xcode-select -switch ${xcode}"
208            }
209            ui_error
210        }
211    }
212   
213    # xcode-select wasn't found, look for Xcode at /Developer
214    set devdir "/Developer"
215    if {[is_valid_developer_dir $devdir]} {
216        return $devdir
217    }
218   
219    ui_error
220    ui_error "No valid Xcode installation was found: please install Xcode"
221    ui_error
222   
223    # We return /Developer here even though we know it's wrong. Abort instead?
224    return "/Developer"
225}
226
227# start gsoc08-privileges
228
229# Record initial euid/egid
230set euid [geteuid]
231set egid [getegid]
232
233# resolve the alternate work path in ~/.macports
234proc portmain::set_altprefix {} {
235    global altprefix env euid
236
237    # do tilde expansion manually - Tcl won't expand tildes automatically for curl, etc.
238    if {[info exists env(HOME)]} {
239        # HOME environment var is set, use it.
240        set userhome "$env(HOME)"
241    } elseif {$euid == 0 && [info exists env(SUDO_USER)] && $env(SUDO_USER) != ""} {
242        set userhome [file normalize "~$env(SUDO_USER)"]
243    } else {
244        # the environment var isn't set, expand ~user instead
245        set username [uid_to_name [getuid]]
246        if {[catch {set userhome [file normalize "~$username"]}]} {
247            set userhome ""
248        }
249    }
250
251    set altprefix [file join $userhome .macports]
252}
253
254# if unable to write to workpath, implies running without either root privileges
255# or a shared directory owned by the group so use ~/.macports
256portmain::set_altprefix
257if { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
258
259    # set global variable indicating to other functions to use ~/.macports as well
260    set usealtworkpath yes
261
262    default worksymlink {[file join ${altprefix}${portpath} work]}
263    default distpath {[file join ${altprefix}${portdbpath} distfiles ${dist_subdir}]}
264    set portbuildpath "${altprefix}${portbuildpath}"
265
266    ui_debug "Going to use alternate build prefix: $altprefix"
267    ui_debug "workpath = $workpath"
268} else {
269    set usealtworkpath no
270    default worksymlink {[file join $portpath work]}
271    default distpath {[file join $portdbpath distfiles ${dist_subdir}]}
272}
273
274# end gsoc08-privileges
275
276proc portmain::main {args} {
277    return 0
278}
Note: See TracBrowser for help on using the repository browser.