2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
11 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
12 sys
.path
.append(os
.path
.join(os
.path
.dirname(SCRIPT_DIR
), 'tools'))
16 valid_tools
= ['newlib', 'glibc', getos
.GetPlatform()]
26 'includes': ['%s/build_tools/nacl.gypi'],
31 'target_name': '%(NAME)s_x86_32%(EXT)s',
32 'product_name': '%(NAME)s_x86_32%(EXT)s',
33 'type': '%(GYP_TYPE)s',
34 'sources': %(SOURCES)s,
35 'libraries': %(LIBS)s,
36 'include_dirs': %(INCLUDES)s,
37 'cflags': ['-m32', '-pedantic'] + %(CFLAGS)s,
38 'make_valid_configurations': ['newlib-debug', 'newlib-release',
39 'glibc-debug', 'glibc-release'],
40 'ldflags': ['-m32', '-L../../lib/x86_32/<(CONFIGURATION_NAME)'],
45 'target_name': '%(NAME)s_x86_64%(EXT)s',
46 'product_name': '%(NAME)s_x86_64%(EXT)s',
47 'type': '%(GYP_TYPE)s',
48 'sources': %(SOURCES)s,
49 'libraries': %(LIBS)s,
50 'include_dirs': %(INCLUDES)s,
51 'make_valid_configurations': ['newlib-debug', 'newlib-release',
52 'glibc-debug', 'glibc-release'],
53 'cflags': ['-m64', '-pedantic'] + %(CFLAGS)s,
54 'ldflags': ['-m64', '-L../../lib/x86_64/<(CONFIGURATION_NAME)'],
62 'target_name': '%(NAME)s_x86_32%(EXT)s',
63 'product_name': 'lib%(NAME)s%(EXT)s',
64 'product_dir': '../../lib/x86_32/<(CONFIGURATION_NAME)',
65 'type': '%(GYP_TYPE)s',
66 'sources': %(SOURCES)s,
67 'libraries': %(LIBS)s,
68 'include_dirs': %(INCLUDES)s,
69 'cflags': ['-m32', '-pedantic'] + %(CFLAGS)s,
70 'make_valid_configurations': ['newlib-debug', 'newlib-release',
71 'glibc-debug', 'glibc-release'],
77 'target_name': '%(NAME)s_x86_64%(EXT)s',
78 'product_name': 'lib%(NAME)s%(EXT)s',
79 'product_dir': '../../lib/x86_64/<(CONFIGURATION_NAME)',
80 'type': '%(GYP_TYPE)s',
81 'sources': %(SOURCES)s,
82 'libraries': %(LIBS)s,
83 'include_dirs': %(INCLUDES)s,
84 'make_valid_configurations': ['newlib-debug', 'newlib-release',
85 'glibc-debug', 'glibc-release'],
86 'cflags': ['-m64', '-pedantic'] + %(CFLAGS)s,
93 HOST_LIB_TARGET
= """\
95 'target_name': '%(NAME)s%(EXT)s',
96 'type': '%(GYP_TYPE)s',
98 'sources': %(SOURCES)s,
100 'cflags_c': ['-std=gnu99'],
101 'include_dirs': %(INCLUDES)s,
102 'make_valid_configurations': ['host-debug', 'host-release'],
103 'product_dir': '../../lib/%(ARCH)s/<(CONFIGURATION_NAME)',
104 'product_name': '%(NAME)s%(EXT)s',
109 HOST_EXE_TARGET
= """\
111 'target_name': '%(NAME)s%(EXT)s',
112 'type': '%(GYP_TYPE)s',
114 'sources': %(SOURCES)s,
115 'cflags': %(CFLAGS)s,
116 'cflags_c': ['-std=gnu99'],
117 'ldflags': ['-L../../lib/%(ARCH)s/<(CONFIGURATION_NAME)'],
118 'libraries': %(LIBS)s,
119 'include_dirs': %(INCLUDES)s,
120 'make_valid_configurations': ['host-debug', 'host-release'],
123 'AdditionalLibraryDirectories':
124 ['../../lib/%(ARCH)s/<(CONFIGURATION_NAME)'],
133 'target_name': '%(NAME)s_%(TOOLCHAIN)s.nmf',
134 'product_name': '%(NAME)s.nmf',
135 'product_dir': '<(PRODUCT_DIR)/%(TOOLCHAIN)s',
137 'make_valid_configurations': ['%(TOOLCHAIN)s-debug', '%(TOOLCHAIN)s-release'],
140 'action_name': 'nmf',
141 'inputs': ['<(PRODUCT_DIR)/%(NAME)s_x86_32.nexe',
142 '<(PRODUCT_DIR)/%(NAME)s_x86_64.nexe'] + %(SODEPS)s,
143 'outputs': ['<(PRODUCT_DIR)/%(NAME)s.nmf'],
144 'action': ['../../tools/create_nmf.py', '-t', '%(TOOLCHAIN)s', '-s',
145 '<(PRODUCT_DIR)'] + %(NMFACTION)s,
151 TOOLCHAIN_CONFIG
= """\
152 '%(toolchain)s-release' : {
155 '%(toolchain)s-debug' : {
156 'cflags' : ['-g', '-O0'],
161 '%(toolchain)s-release' : {
162 'cflags' : ['--%(toolchain)s', '-O2',
163 '-idirafter', '../../include'],
164 'ldflags' : ['--%(toolchain)s'],
165 'arflags' : ['--%(toolchain)s'],
167 '%(toolchain)s-debug' : {
168 'cflags' : ['--%(toolchain)s', '-g', '-O0',
169 '-idirafter', '../../include'],
170 'ldflags' : ['--%(toolchain)s'],
171 'arflags' : ['--%(toolchain)s'],
177 'default_configuration': 'Debug_PPAPI',
180 'msvs_configuration_platform': 'PPAPI',
181 'msbuild_configuration_attributes': {
182 'ConfigurationType': 'DynamicLibrary'
184 'include_dirs': ['../../include/win'],
185 'defines': ['_WINDOWS', '_DEBUG', 'WIN32'],
188 'msvs_configuration_platform': 'PPAPI',
189 'msbuild_configuration_attributes': {
190 'ConfigurationType': 'DynamicLibrary'
192 'include_dirs': ['../../include/win'],
193 'defines': ['_WINDOWS', 'NDEBUG', 'WIN32'],
196 'msvs_configuration_platform': 'NaCl',
197 'msbuild_configuration_attributes': {
198 'ConfigurationType': 'Application'
202 'msvs_configuration_platform': 'NaCl',
203 'msbuild_configuration_attributes': {
204 'ConfigurationType': 'Application'
212 def WriteNaClTargets(output
, target
, tools
):
213 configs
= "'configurations' : {\n"
215 if tc
not in valid_tools
:
217 if tc
in ['newlib', 'glibc']:
218 configs
+= NEXE_CONFIG
% {'toolchain': tc
}
220 target
['CONFIGS'] = configs
221 if target
['TYPE'] == 'lib':
222 output
.write(NLIB_TARGET
% target
)
224 output
.write(NEXE_TARGET
% target
)
227 def ConfigName(toolchain
):
228 if toolchain
== getos
.GetPlatform():
234 def ProcessDSC(filename
, outfile
=None):
235 if not os
.path
.exists(filename
):
236 Error("file not found: %s" % filename
)
238 desc
= open(filename
).read()
239 desc
= eval(desc
, {}, {})
240 if not desc
.get('TARGETS'):
241 Error("no TARGETS found in dsc")
244 outfile
= desc
['NAME'] + '.gyp'
245 outfile
= os
.path
.join(os
.path
.dirname(filename
), outfile
)
247 output
= StringIO
.StringIO()
249 srcdir
= os
.path
.dirname(SCRIPT_DIR
)
250 output
.write(PREAMBLE
% srcdir
.replace("\\", '/'))
252 win32
= sys
.platform
in ('win32', 'cygwin')
254 output
.write(WIN32_CONFIGS
)
256 for tc
in desc
['TOOLS']:
257 if tc
in valid_tools
:
258 default
= '%s-debug' % ConfigName(tc
)
263 'default_configuration': '%s',
264 'configurations' : {\n""" % default
)
266 for tc
in desc
['TOOLS']:
267 if tc
not in valid_tools
:
269 output
.write(TOOLCHAIN_CONFIG
% {'toolchain': ConfigName(tc
)})
271 output
.write(" }\n },\n")
273 output
.write("\n 'targets': [\n")
275 # make a list of all the so target names so that the nmf rules
276 # can depend on them all
279 for target
in desc
['TARGETS']:
280 if target
['TYPE'] == 'so':
281 name
= target
['NAME']
282 sofiles
.append('<(PRODUCT_DIR)/%s_x86_64.so' % name
)
283 sofiles
.append('<(PRODUCT_DIR)/%s_x86_32.so' % name
)
284 soremap
+= ['-n', '%s_x86_64.so,%s.so' % (name
, name
)]
285 soremap
+= ['-n', '%s_x86_32.so,%s.so' % (name
, name
)]
288 # iterate through dsc targets generating gyp targets
289 for target
in desc
['TARGETS']:
290 target
.setdefault('INCLUDES', [])
291 target
['INCLUDES'] = [x
.replace("$(NACL_SDK_ROOT)", "../..")
292 for x
in target
['INCLUDES']]
294 libs
= target
.get('LIBS', [])
296 libs
= [l
for l
in libs
if l
not in ('ppapi', 'ppapi_cpp')]
297 target
['LIBS'] = ['-l' + l
+ '.lib' for l
in libs
]
299 target
['LIBS'] = ['-l' + l
for l
in libs
]
300 if target
['TYPE'] == 'so':
304 target
['EXT'] = '.so'
305 target
['GYP_TYPE'] = 'shared_library'
306 elif target
['TYPE'] == 'lib':
311 target
['GYP_TYPE'] = 'static_library'
312 elif target
['TYPE'] == 'main':
313 target
['EXT'] = '.nexe'
314 target
['GYP_TYPE'] = 'executable'
316 Error("unknown type: %s" % target
['TYPE'])
318 target
['CFLAGS'] = target
.get('CXXFLAGS', [])
320 if not win32
and ('newlib' in desc
['TOOLS'] or 'glibc' in desc
['TOOLS']):
321 WriteNaClTargets(output
, target
, desc
['TOOLS'])
322 if target
['TYPE'] == 'main':
323 target
['SODEPS'] = sofiles
324 target
['NMFACTION'] = ['-o', '<@(_outputs)', '-L<(NMF_PATH1)',
325 '-L<(NMF_PATH2)', '-D', '<(OBJDUMP)',
327 target
['NMFACTION'] += soremap
328 if 'newlib' in desc
['TOOLS']:
329 target
['TOOLCHAIN'] = 'newlib'
330 output
.write(NMF_TARGET
% target
)
331 if 'glibc' in desc
['TOOLS']:
332 target
['TOOLCHAIN'] = 'glibc'
333 output
.write(NMF_TARGET
% target
)
335 if win32
or getos
.GetPlatform() in desc
['TOOLS']:
336 target
['ARCH'] = 'x86_32'
337 target
['INCLUDES'].append('../../include')
339 target
['HOST'] = 'win'
340 target
['CONFIGS'] = ''
341 target
['CFLAGS'] = []
343 target
['CONFIGS'] = ''
344 target
['HOST'] = 'linux'
345 target
['CFLAGS'].append('-fPIC')
346 if target
['TYPE'] == 'main':
347 target
['GYP_TYPE'] = 'shared_library'
351 target
['EXT'] = '.so'
352 output
.write(HOST_EXE_TARGET
% target
)
354 output
.write(HOST_LIB_TARGET
% target
)
356 output
.write(' ],\n}\n')
358 print('Writing: ' + outfile
)
359 open(outfile
, 'w').write(output
.getvalue())
363 parser
= argparse
.ArgumentParser()
364 parser
.add_argument('-o', help='Set output filename.', dest
='output')
365 parser
.add_argument('dsc', help='dsc to convert')
366 options
= parser
.parse_args(args
)
369 outdir
= os
.path
.dirname(options
.output
)
370 if not os
.path
.exists(outdir
):
373 ProcessDSC(options
.dsc
, options
.output
)
377 if __name__
== '__main__':
378 sys
.exit(main(sys
.argv
[1:]))