forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·200 lines (176 loc) · 10.3 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
import sys
import os
import argparse
import json
import glob
from lib.config import Configuration
from lib.path import Path
from lib.phases import CompileSources
from lib.phases import CompileSwiftSources
from lib.phases import CopyResources
from lib.phases import CopyHeaders
from lib.phases import SwiftExecutable
from lib.product import DynamicLibrary
from lib.product import Framework
from lib.product import StaticLibrary
from lib.product import Application
from lib.product import Executable
from lib.script import Script
from lib.target import ArchSubType
from lib.target import ArchType
from lib.target import EnvironmentType
from lib.target import ObjectFormat
from lib.target import OSType
from lib.target import Target
from lib.target import Vendor
from lib.workspace import Workspace
import sys
def reconfigure(config, path):
with open(path, 'r') as infile:
info = json.load(infile)
config.requires_pkg_config = info['requires_pkg_config']
if 'version' in info and info['version'] == config.version:
if 'command' in info and info['command'] is not None:
config.command = info['command']
if 'project' in info and info['project'] is not None:
config.command = info['project']
if 'script_path' in info and info['script_path'] is not None:
config.script_path = Path(info['script_path'])
if 'build_script_path' in info and info['build_script_path'] is not None:
config.build_script_path = Path(info['build_script_path'])
if 'source_root' in info and info['source_root'] is not None:
config.source_root = Path(info['source_root'])
if 'target' in info and info['target'] is not None:
config.target = Target(info['target'])
if 'system_root' in info and info['system_root'] is not None:
config.system_root = Path(info['system_root'])
if 'toolchain' in info and info['toolchain'] is not None:
config.toolchain = Path(info['toolchain'])
if 'linker' in info and info['linker'] is not None:
config.linker = info['linker']
if 'build_directory' in info and info['build_directory'] is not None:
config.build_directory = Path(info['build_directory'])
if 'intermediate_directory' in info and info['intermediate_directory'] is not None:
config.intermediate_directory = Path(info['intermediate_directory'])
if 'module_cache_directory' in info and info['module_cache_directory'] is not None:
config.module_cache_directory = Path(info['module_cache_directory'])
if 'install_directory' in info and info['install_directory'] is not None:
config.install_directory = Path(info['install_directory'])
if 'prefix' in info and info['prefix'] is not None:
config.prefix = info['prefix']
if 'swift_install' in info and info['swift_install'] is not None:
config.swift_install = info['swift_install']
if 'pkg_config' in info and info['pkg_config'] is not None:
config.pkg_config = info['pkg_config']
if 'clang' in info and info['clang'] is not None:
config.clang = info['clang']
if 'clangxx' in info and info['clangxx'] is not None:
config.clangxx = info['clangxx']
if 'swift' in info and info['swift'] is not None:
config.swift = info['swift']
if 'swiftc' in info and info['swiftc'] is not None:
config.swiftc = info['swiftc']
if 'ar' in info and info['ar'] is not None:
config.ar = info['ar']
if 'swift_sdk' in info and info['swift_sdk'] is not None:
config.swift_sdk = info['swift_sdk']
if 'bootstrap_directory' in info and info['bootstrap_directory'] is not None:
config.bootstrap_directory = Path(info['bootstrap_directory'])
if 'verbose' in info and info['verbose'] is not None:
config.verbose = info['verbose']
if 'extra_c_flags' in info and info['extra_c_flags'] is not None:
config.extra_c_flags = info['extra_c_flags']
if 'extra_swift_flags' in info and info['extra_swift_flags'] is not None:
config.extra_swift_flags = info['extra_swift_flags']
if 'extra_ld_flags' in info and info['extra_ld_flags'] is not None:
config.extra_ld_flags = info['extra_ld_flags']
if 'build_mode' in info and info['build_mode'] is not None:
config.build_mode = info['build_mode']
if 'variables' in info and info['variables'] is not None:
config.variables = info['variables']
else:
sys.exit("invalid version")
def main():
config = Configuration()
CWD = Path.path(os.getcwd())
config.build_directory = Path.path(os.getenv("BUILD_DIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "Build")))
config.module_cache_directory = Path.path(os.getenv("BUILD_DIR", config.build_directory.path_by_appending("ModuleCache")))
config.intermediate_directory = Path.path(os.getenv("INTERMEDIATE_DIR", config.build_directory.path_by_appending("Intermediates")))
config.install_directory = Path.path(os.getenv("DSTROOT", "/"))
config.prefix = os.getenv("PREFIX", "/usr")
config.clang = os.getenv("CLANG", "clang")
config.clangxx = os.getenv("CLANGXX", "clang")
config.swift = os.getenv("SWIFT", "swift")
config.swiftc = os.getenv("SWIFTC", "swiftc")
config.ar = os.getenv("AR", None)
config.source_root = Path.path(os.getenv("SRCROOT", CWD))
config.extra_c_flags = os.getenv("CFLAGS", "")
config.extra_swift_flags = os.getenv("SWIFTCFLAGS", "")
config.extra_ld_flags = os.getenv("LDFLAGS", "")
config.swift_sdk = os.getenv("SDKROOT", None)
config.script_path = config.source_root.path_by_appending("build.py")
config.build_script_path = config.source_root.path_by_appending("build.ninja")
config.config_path = config.source_root.path_by_appending(".configuration")
parser = argparse.ArgumentParser(description='Configure and emit ninja build scripts for building.')
parser.add_argument('--target', dest='target', type=str, default=Target.default(), help="specify the deployment target")
parser.add_argument('--sysroot', dest='sysroot', type=str, default=None, help="the system root directory for building")
parser.add_argument('--toolchain', dest='toolchain', type=str, default=None, help="the base location for finding tools to compile")
parser.add_argument('--linker', dest='linker', type=str, default=None, help="which linker program to use")
parser.add_argument('--pkg-config', dest='pkg_config', type=str, default="pkg-config")
parser.add_argument('--bootstrap', dest='bootstrap', type=str, default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "bootstrap"), help="a directory for bootstrapping commonly used headers and libraries not associated directly with the target operating system")
parser.add_argument('--reconfigure', dest='reconfigure', action="store_true", help="re-generate the build script given the previous configuration")
parser.add_argument('-v', '--verbose', dest='verbose', action="store_true")
args, extras = parser.parse_known_args()
if args.reconfigure:
reconfigure(config, config.config_path.absolute())
for arg in extras:
if arg.lower() == 'debug':
config.build_mode = Configuration.Debug
elif arg.lower() == 'release':
config.build_mode = Configuration.Release
else:
config.build_mode = Configuration.Debug # by default build in debug mode
for arg in extras:
if arg.lower() == 'debug':
config.build_mode = Configuration.Debug
elif arg.lower() == 'release':
config.build_mode = Configuration.Release
elif arg.startswith('-D'): # accept -DNAME=value as extra parameters to the configuration of the build.ninja
key, val = arg[2:].split("=", 1)
config.variables[key] = val
config.command = [os.path.abspath(__file__)] + sys.argv[1:]
config.target = Target(args.target)
config.system_root = Path.path(args.sysroot)
if config.target.sdk == OSType.MacOSX and config.system_root is None and Target(Target.default()).sdk == OSType.MacOSX:
import subprocess
config.system_root = Path.path(subprocess.Popen(['xcrun', '--show-sdk-path'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).communicate()[0])
swift_path = Path.path(subprocess.Popen(['xcrun', '--find', 'swift'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).communicate()[0]).parent().parent()
config.swift_sdk = swift_path.absolute()
elif config.swift_sdk is None:
config.swift_sdk = "/usr"
config.toolchain = Path.path(args.toolchain)
config.pkg_config = args.pkg_config
config.linker = args.linker
config.bootstrap_directory = Path.path(args.bootstrap)
config.verbose = args.verbose
if config.toolchain is not None:
ar_path = os.path.join(config.toolchain.relative(), "ar")
if not os.path.exists(ar_path):
ar_path = os.path.join(config.toolchain.relative(), "bin", "ar")
config.ar = ar_path
elif config.ar is None:
config.ar = "ar"
config.write(config.config_path.absolute())
Configuration.current = config
exec(compile(open(config.script_path.absolute()).read(), config.script_path.absolute(), 'exec'))
if __name__ == "__main__":
main()