aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-14 11:12:19 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-14 11:12:19 -0800
commit5322f208ad2126038456c90860970739c6e36556 (patch)
tree7f6ddd4f20d09de6e21faeee6504e08226c08f9a
parent6c2ee0edcff41748ac4bd771a3fdc7be03b1e084 (diff)
initial work to refactor emcc into emcc, emld, emar, emranlib
-rwxr-xr-xemar13
-rwxr-xr-xemcc85
-rwxr-xr-xemld42
-rwxr-xr-xemranlib9
-rw-r--r--tests/runner.py5
5 files changed, 80 insertions, 74 deletions
diff --git a/emar b/emar
new file mode 100755
index 00000000..65e106f9
--- /dev/null
+++ b/emar
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+'''
+emcc - ar helper script
+=======================
+
+This script acts as a frontend replacement for ar. See emcc.
+'''
+
+if set(sys.argv[1]).issubset(set('-cruqs')): # ar
+ sys.argv = sys.argv[:1] + sys.argv[3:] + ['-o='+sys.argv[2]]
+ assert use_linker, 'Linker should be used in this case'
+
diff --git a/emcc b/emcc
index 7cd1b758..89a6bdf8 100755
--- a/emcc
+++ b/emcc
@@ -6,11 +6,8 @@ emcc - compiler helper script
emcc is a drop-in replacement for a compiler like gcc or clang.
-Tell your build system to use this instead of the compiler, linker, ar and
-ranlib. All the normal build commands will be sent to this script, which
-will proxy them to the appropriate build commands. For example, compilation
-will be translated into calls to clang with -emit-llvm, and linking will
-be translated into calls to llvm-link, and so forth.
+Tell your build system to use this instead of the compiler, and similarly
+use emar, emld and emranlib instead of the same command without 'em'.
Example uses:
@@ -22,7 +19,7 @@ Example uses:
emconfiguren.py is a tiny script that just sets some environment vars
as a convenience. The command just shown is equivalent to
- EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emcc AR=PATH/emcc CXX=PATH/em++ CC=PATH/emcc ./configure [options]
+ EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emranlib AR=PATH/emar CXX=PATH/em++ CC=PATH/emcc ./configure [options]
where PATH is the path to this file.
@@ -35,12 +32,12 @@ Example uses:
SET(CMAKE_C_COMPILER "PATH/emcc")
SET(CMAKE_CXX_COMPILER "PATH/em++")
- SET(CMAKE_LINKER "PATH/emcc")
- SET(CMAKE_CXX_LINKER "PATH/emcc")
- SET(CMAKE_C_LINK_EXECUTABLE "PATH/emcc")
- SET(CMAKE_CXX_LINK_EXECUTABLE "PATH/emcc")
- SET(CMAKE_AR "PATH/emcc")
- SET(CMAKE_RANLIB "PATH/emcc")
+ SET(CMAKE_LINKER "PATH/emld")
+ SET(CMAKE_CXX_LINKER "PATH/emld")
+ SET(CMAKE_C_LINK_EXECUTABLE "PATH/emld")
+ SET(CMAKE_CXX_LINK_EXECUTABLE "PATH/emld")
+ SET(CMAKE_AR "PATH/emar")
+ SET(CMAKE_RANLIB "PATH/emranlib")
* For SCons the shared.py can be imported like so:
__file__ = str(Dir('#/project_path_to_emscripten/dummy/dummy'))
@@ -169,9 +166,6 @@ if os.environ.get('EMMAKEN_CXX'):
CC = CXX
CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS # + ['-g']?
-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 .|
EMMAKEN_CFLAGS = os.environ.get('EMMAKEN_CFLAGS')
if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ')
@@ -192,33 +186,15 @@ if len(sys.argv) == 1 or sys.argv[1] in ['x', 't']:
sys.exit(0)
use_cxx = True
-use_linker = True
header = False # pre-compiled headers. We fake that by just copying the file
-opts = []
-files = []
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
- if arg.startswith('-'):
- opts.append(arg)
- else:
- files.append(arg)
+ if not arg.startswith('-'):
if arg.endswith('.c'):
use_cxx = False
- if arg.endswith(('.c', '.cc', '.cpp', '.dT')):
- use_linker = False
if arg.endswith('.h') and sys.argv[i-1] != '-include':
header = True
- use_linker = False
-
-if '--version' in opts:
- use_linker = False
-
-use_compiler = not use_linker and not header
-
-if set(sys.argv[1]).issubset(set('-cruqs')): # ar
- sys.argv = sys.argv[:1] + sys.argv[3:] + ['-o='+sys.argv[2]]
- assert use_linker, 'Linker should be used in this case'
# Check if a target is specified
target = None
@@ -231,44 +207,7 @@ for i in range(len(sys.argv)-1):
sys.argv = sys.argv[:i] + sys.argv[i+2:]
break
-if use_linker:
- # 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
- 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)
-
- if DEBUG: print >> sys.stderr, "Running:", call, ' '.join(newargs)
- Popen([call] + newargs).communicate()
-
- # If we were not asked to generate JavaScript, stop
- if not target.endswith('.js'):
- exit(0)
-
- # Do not pass go, go directly to the compiler
- sys.argv = [sys.argv[0], actual_target]
- shutil.move(actual_target + '.bc', actual_target)
- use_compiler = True
-
-if use_compiler:
+if not header:
call = CXX if use_cxx else CC
## Parse args
@@ -437,5 +376,3 @@ else: # header or such
shutil.copy(sys.argv[-1], sys.argv[-2])
exit(0)
-
-
diff --git a/emld b/emld
new file mode 100755
index 00000000..c2056e68
--- /dev/null
+++ b/emld
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+'''
+emcc - linker helper script
+===========================
+
+This script acts as a frontend replacement for the ld linker. See emcc.
+'''
+
+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 .|
+
+#
+
+# 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
+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)
+
+if DEBUG: print >> sys.stderr, "Running:", call, ' '.join(newargs)
+Popen([call] + newargs).communicate()
+
diff --git a/emranlib b/emranlib
new file mode 100755
index 00000000..1405320b
--- /dev/null
+++ b/emranlib
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+
+'''
+emcc - ranlib helper script
+===========================
+
+This script acts as a frontend replacement for ranlib. See emcc.
+'''
+
diff --git a/tests/runner.py b/tests/runner.py
index abb4660a..8154be8b 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -4974,6 +4974,11 @@ Options that are modified or new in %s include:
clear()
output = Popen([compiler, path_from_root('tests', 'twopart_main.cpp'), path_from_root('tests', 'twopart_side.cpp'), '-c'],
stdout=PIPE, stderr=PIPE).communicate()
+ if '-o' in args:
+ # specifying -o and -c is an error
+ assert 'fatal error' in output[1], output[1]
+ continue
+
assert os.path.exists('twopart_main.bc'), '\n'.join(output)
assert os.path.exists('twopart_side.bc'), '\n'.join(output)
assert not os.path.exists(target), 'We should only have created bitcode here: ' + '\n'.join(output)