Debugging: Add code to print backtrace for guest on SIGSEGV
[nativeclient.git] / site_scons / site_tools / target_platform_mac.py
blob51fd58fcc5d14d1391d13a927530de2a286b174c
1 #!/usr/bin/python2.4
2 # Copyright 2009, Google Inc.
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 """Build tool setup for MacOS.
33 This module is a SCons tool which should be include in the topmost mac
34 environment.
35 It is used as follows:
36 env = base_env.Clone(tools = ['component_setup'])
37 mac_env = base_env.Clone(tools = ['target_platform_mac'])
38 """
41 import SCons.Script
44 def ComponentPlatformSetup(env, builder_name):
45 """Hook to allow platform to modify environment inside a component builder.
47 Args:
48 env: Environment to modify
49 builder_name: Name of the builder
50 """
51 if env.get('ENABLE_EXCEPTIONS'):
52 env.FilterOut(CCFLAGS=['-fno-exceptions'])
53 env.Append(CCFLAGS=['-fexceptions'])
55 #------------------------------------------------------------------------------
56 # TODO: This bundle builder here needs refactoring to use ComponentPackage().
57 # Until that refactoring, consider this code very experimental (i.e., don't use
58 # it unless you're ok with it changing out from underneath you).
60 def BundlePseudoBuilder(env, target, **kwargs):
61 """MacOS Bundle PseudoBuilder.
63 Args:
64 env: Environment in which to build
65 target: Name of the bundle to build
66 kwargs: Additional parameters to set in the environment
68 Returns:
69 The target is returned.
70 """
71 # Don't change the environment passed into the pseudo-builder
72 env = env.Clone()
74 # Bring keywords args into the environment.
75 for k, v in kwargs.items():
76 env[k] = v
77 # Make sure BUNDLE_RESOURCES is set and not empty; force it to be a list
78 bundle_resources = env.Flatten(env.get('BUNDLE_RESOURCES', []))
79 if not bundle_resources:
80 raise ValueError('BUNDLE_RESOURCES must be set and non-empty')
82 # Make each resource into a directory node.
83 # TODO: this seems a little too restrictive.
84 # bundle_resources = [env.Dir(i) for i in bundle_resources]
85 bundle_resources = [i for i in bundle_resources]
87 # Create a PkgInfo file only if BUNDLE_PKGINFO_FILENAME is useful.
88 # (NPAPI bundles are unhappy with PkgInfo files.)
89 if env.get('BUNDLE_PKGINFO_FILENAME'):
90 pkginfo_create_command = ('$BUNDLE_GENERATE_PKGINFO '
91 '>$TARGET/$BUNDLE_PKGINFO_FILENAME')
92 else:
93 pkginfo_create_command = '/bin/echo no PkgInfo will be created' # noop
95 # Add the build step for the bundle.
96 p = env.Command(env.Dir(target),
97 [env.File('$BUNDLE_EXE'),
98 env.File('$BUNDLE_INFO_PLIST')] +
99 bundle_resources,
100 [SCons.Script.Delete('$TARGET'),
101 SCons.Script.Mkdir('$TARGET/Contents'),
102 SCons.Script.Mkdir('$TARGET/Contents/MacOS'),
103 SCons.Script.Mkdir('$TARGET/Contents/Resources'),
104 'cp -f $SOURCE $TARGET/Contents/MacOS',
105 'cp -f ${SOURCES[1]} $TARGET/Contents',
106 pkginfo_create_command,
107 'cp -rf ${SOURCES[2:]} $TARGET/Contents/Resources'])
109 # Add an alias for this target.
110 # This also allows the 'all_bundles' target to build me.
111 a = env.Alias(target, p)
112 for group in env['COMPONENT_BUNDLE_GROUPS']:
113 SCons.Script.Alias(group, a)
115 return env.Dir(target)
117 #------------------------------------------------------------------------------
120 def generate(env):
121 # NOTE: SCons requires the use of this name, which fails gpylint.
122 """SCons entry point for this tool."""
124 # Preserve some variables that get blown away by the tools.
125 saved = dict()
126 for k in ['CFLAGS', 'CCFLAGS', 'CXXFLAGS', 'LINKFLAGS', 'LIBS']:
127 saved[k] = env.get(k, [])
128 env[k] = []
130 # Use g++
131 env.Tool('g++')
132 env.Tool('gcc')
133 env.Tool('gnulink')
134 env.Tool('ar')
135 env.Tool('as')
136 env.Tool('applelink')
138 # Set target platform bits
139 env.SetBits('mac', 'posix')
141 env.Replace(
142 TARGET_PLATFORM='MAC',
143 COMPONENT_PLATFORM_SETUP=ComponentPlatformSetup,
144 CCFLAG_INCLUDE='-include', # Command line option to include a header
146 # Code coverage related.
147 COVERAGE_CCFLAGS=['-ftest-coverage', '-fprofile-arcs'],
148 COVERAGE_LIBS='gcov',
149 COVERAGE_STOP_CMD=[
150 '$COVERAGE_MCOV --directory "$TARGET_ROOT" --output "$TARGET"',
151 ('$COVERAGE_GENHTML --output-directory $COVERAGE_HTML_DIR '
152 '$COVERAGE_OUTPUT_FILE'),
155 # Libraries expect to be in the same directory as their executables.
156 # This is correct for unit tests, and for libraries which are published
157 # in Contents/MacOS next to their executables.
158 DYLIB_INSTALL_NAME_FLAGS=[
159 '-install_name',
160 '@loader_path/${TARGET.file}'
164 env.Append(
165 HOST_PLATFORMS=['MAC'],
166 CPPDEFINES=['OS_MACOSX=OS_MACOSX'],
168 # Mac apps and dylibs have a more strict relationship about where they
169 # expect to find each other. When an app is linked, it stores the
170 # relative path from itself to any dylibs it links against. Override
171 # this so that it will store the relative path from $LIB_DIR instead.
172 # This is similar to RPATH on Linux.
173 LINKFLAGS = [
174 '-Xlinker', '-executable_path',
175 '-Xlinker', '$LIB_DIR',
177 # Similarly, tell the library where it expects to find itself once it's
178 # installed.
179 SHLINKFLAGS = ['$DYLIB_INSTALL_NAME_FLAGS'],
181 # Settings for debug
182 CCFLAGS_DEBUG=['-g'],
183 LINKFLAGS_DEBUG=['-g'],
185 # Settings for optimized
186 # Optimized for space by default, which is what Xcode does
187 CCFLAGS_OPTIMIZED=['-Os'],
189 # Settings for component_builders
190 COMPONENT_LIBRARY_LINK_SUFFIXES=['.dylib', '.a'],
191 COMPONENT_LIBRARY_DEBUG_SUFFIXES=[],
193 # New 'all' target. Helpful: "hammer -h" now lists it!
194 COMPONENT_BUNDLE_GROUPS=['all_bundles'],
198 # Set default values used by the Bundle pseudobuilder.
199 env.Replace(
200 BUNDLE_TYPE='APPL',
201 BUNDLE_STRING='${BUNDLE_TYPE}????',
202 BUNDLE_GENERATE_PKGINFO='echo "${BUNDLE_STRING}"',
203 BUNDLE_PKGINFO_FILENAME='PkgInfo',
204 BUNDLE_INFO_PLIST='Info.plist',
207 # Add the Bundle pseudobuilder.
208 env.AddMethod(BundlePseudoBuilder, 'Bundle')
210 # Add our target groups
211 AddTargetGroup('all_bundles', 'bundles can be built')
213 # Restore saved flags.
214 env.Append(**saved)