2011-12-14 23:12:19 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
'''
|
2011-12-15 05:01:16 +04:00
|
|
|
emld - linker helper script
|
2011-12-14 23:12:19 +04:00
|
|
|
===========================
|
|
|
|
|
|
|
|
This script acts as a frontend replacement for the ld linker. See emcc.
|
2011-12-15 05:01:16 +04:00
|
|
|
|
|
|
|
We could use the compiler code for this, but here we want to be careful to use all the linker flags we have been passed, sending them to ld.
|
2011-12-14 23:12:19 +04:00
|
|
|
'''
|
|
|
|
|
2011-12-15 05:01:16 +04:00
|
|
|
import os, sys
|
|
|
|
from tools import shared
|
|
|
|
|
|
|
|
DEBUG = os.environ.get('EMCC_DEBUG')
|
|
|
|
|
|
|
|
if DEBUG:
|
|
|
|
print >> sys.stderr, 'emld:', sys.argv
|
|
|
|
|
2011-12-14 23:12:19 +04:00
|
|
|
ALLOWED_LINK_ARGS = ['-f', '-help', '-o', '-print-after', '-print-after-all', '-print-before',
|
|
|
|
'-print-before-all', '-time-passes', '-v', '-verify-dom-info', '-version' ]
|
|
|
|
TWO_PART_DISALLOWED_LINK_ARGS = ['-L'] # Ignore thingsl like |-L .|
|
|
|
|
|
2011-12-15 05:01:16 +04:00
|
|
|
# Check for specified target
|
|
|
|
target = None
|
|
|
|
for i in range(len(sys.argv)-1):
|
|
|
|
if sys.argv[i].startswith('-o='):
|
|
|
|
raise Exception('Invalid syntax: do not use -o=X, use -o X')
|
|
|
|
|
|
|
|
if sys.argv[i] == '-o':
|
|
|
|
target = sys.argv[i+1]
|
|
|
|
sys.argv = sys.argv[:i] + sys.argv[i+2:]
|
|
|
|
break
|
2011-12-14 23:12:19 +04:00
|
|
|
|
|
|
|
call = shared.LLVM_LD
|
|
|
|
newargs = ['-disable-opt']
|
|
|
|
i = 0
|
|
|
|
while i < len(sys.argv)-1:
|
|
|
|
i += 1
|
|
|
|
arg = sys.argv[i]
|
|
|
|
if arg.startswith('-'):
|
|
|
|
prefix = arg.split('=')[0]
|
|
|
|
if prefix in ALLOWED_LINK_ARGS:
|
|
|
|
newargs.append(arg)
|
|
|
|
if arg in TWO_PART_DISALLOWED_LINK_ARGS:
|
|
|
|
i += 1
|
|
|
|
elif arg.endswith('.so'):
|
|
|
|
continue # .so's do not exist yet, in many cases
|
|
|
|
else:
|
|
|
|
# not option, so just append
|
|
|
|
newargs.append(arg)
|
|
|
|
if target:
|
|
|
|
actual_target = target
|
|
|
|
if target.endswith('.js'):
|
|
|
|
actual_target = unsuffixed(target) + '.bc'
|
|
|
|
newargs.append('-o=' + actual_target)
|
|
|
|
|
2011-12-15 05:01:16 +04:00
|
|
|
if DEBUG: print >> sys.stderr, "emld running:", call, ' '.join(newargs)
|
|
|
|
os.execvp(call, [call] + newargs)
|
2011-12-14 23:12:19 +04:00
|
|
|
|