diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-02-23 11:14:52 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-02-23 11:14:52 -0800 |
commit | d125f1bd3df204658fac85cd152e737ef51e49ee (patch) | |
tree | 793cd92e2a68c61ac51acdefdc19eceb29b3d5a2 | |
parent | 6a5df316993975177b8d8a5056926a7696308784 (diff) |
support -L/-l syntax in emcc
-rwxr-xr-x | emcc | 29 | ||||
-rwxr-xr-x | tests/runner.py | 28 |
2 files changed, 57 insertions, 0 deletions
@@ -241,7 +241,9 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ') SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc') BITCODE_SUFFIXES = ('.bc', '.o') SHAREDLIB_SUFFIXES = ('.dylib', '.so', '.dll') +STATICLIB_SUFFIXES = ('.a',) ASSEMBLY_SUFFIXES = ('.ll',) +LIB_PREFIXES = ('', 'lib') def suffix(name): return name.split('.')[:-1] @@ -376,8 +378,12 @@ try: newargs[i+1] = '' newargs = [ arg for arg in newargs if arg is not '' ] + # Find input files + input_files = [] has_source_inputs = False + lib_dirs = [] + libs = [] for i in range(len(newargs)): # find input files XXX this a simple heuristic. we should really analyze based on a full understanding of gcc params, # right now we just assume that what is left contains no more |-x OPT| things arg = newargs[i] @@ -395,8 +401,31 @@ try: print >> sys.stderr, 'emcc: %s: warning: Not valid LLVM bitcode' % arg else: print >> sys.stderr, 'emcc: %s: warning: No such file or directory' % arg + elif arg.startswith('-L'): + lib_dirs.append(arg[2:]) + newargs[i] = '' + elif arg.startswith('-l'): + libs.append(arg[2:]) + newargs[i] = '' newargs = [ arg for arg in newargs if arg is not '' ] + # Find library files + for lib in libs: + if DEBUG: print >> sys.stderr, 'emcc: looking for library "%s"' % lib + found = False + for prefix in LIB_PREFIXES: + for suffix in STATICLIB_SUFFIXES + SHAREDLIB_SUFFIXES: + name = prefix + lib + suffix + for lib_dir in lib_dirs: + path = os.path.join(lib_dir, name) + if os.path.exists(path): + if DEBUG: print >> sys.stderr, 'emcc: found library "%s" at %s' % (lib, path) + input_files.append(path) + found = True + break + if found: break + if found: break + assert len(input_files) > 0, 'emcc: no input files' newargs += CC_ADDITIONAL_ARGS diff --git a/tests/runner.py b/tests/runner.py index ca8648dd..a95dfff0 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6122,6 +6122,34 @@ f.close() assert os.path.exists('something.html'), output run_browser('something.html', 'You should not see animating gears.', '/report_gl_result?false') + def test_emcc_l_link(self): + # Linking with -lLIBNAME and -L/DIRNAME should work + + open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(''' + extern void printey(); + int main() { + printey(); + return 0; + } + ''') + + try: + os.makedirs(os.path.join(self.get_dir(), 'libdir')); + except: + pass + + open(os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), 'w').write(''' + #include <stdio.h> + void printey() { + printf("hello from lib\\n"); + } + ''') + + Popen([EMCC, os.path.join(self.get_dir(), 'libdir', 'libfile.cpp'), '-c'], stdout=PIPE, stderr=STDOUT).communicate() + shutil.move(os.path.join(self.get_dir(), 'libfile.o'), os.path.join(self.get_dir(), 'libdir', 'libfile.so')) + Popen([EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile'], stdout=PIPE, stderr=STDOUT).communicate() + self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_eliminator(self): input = open(path_from_root('tools', 'eliminator', 'eliminator-test.js')).read() expected = open(path_from_root('tools', 'eliminator', 'eliminator-test-output.js')).read() |