From 6a5c37799e9e30a068185693f3c9fd7dbb054e71 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 18 Jul 2018 09:32:16 -0400 Subject: [PATCH] Add support for transforming Fortran files with f2c --- pyodide_build/pywasmcross.py | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pyodide_build/pywasmcross.py b/pyodide_build/pywasmcross.py index 3fda9a726..dd2bf8ec0 100755 --- a/pyodide_build/pywasmcross.py +++ b/pyodide_build/pywasmcross.py @@ -41,6 +41,7 @@ from pyodide_build import common ROOTDIR = common.ROOTDIR symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc']) +symlinks = set(['cc', 'c++', 'ld', 'ar', 'gcc', 'gfortran']) def collect_args(basename): @@ -105,6 +106,24 @@ def capture_compile(args): sys.exit(result.returncode) +def f2c(args): + new_args = [] + found_source = False + for arg in args: + if arg.endswith('.f'): + filename = os.path.abspath(arg) + subprocess.check_call( + ['f2c', os.path.basename(filename)], + cwd=os.path.dirname(filename)) + new_args.append(arg[:-2] + '.c') + found_source = True + else: + new_args.append(arg) + if not found_source: + return None + return new_args + + def handle_command(line, args, dryrun=False): """Handle a compilation command @@ -137,8 +156,16 @@ def handle_command(line, args, dryrun=False): return if arg == '-print-multiarch': return + if arg.startswith('/tmp'): + return - if line[0] == 'ar': + if line[0] == 'gfortran': + result = f2c(line) + if result is None: + return + line = result + new_args = ['emcc'] + elif line[0] == 'ar': new_args = ['emar'] elif line[0] == 'c++': new_args = ['em++'] @@ -153,6 +180,8 @@ def handle_command(line, args, dryrun=False): new_args.extend(args.ldflags.split()) elif new_args[0] in ('emcc', 'em++'): new_args.extend(args.cflags.split()) + if new_args[0] == 'em++': + new_args.append('-std=c++98') # Go through and adjust arguments for arg in line[1:]: @@ -171,11 +200,16 @@ def handle_command(line, args, dryrun=False): arg = re.sub(r'/python([0-9]\.[0-9]+)m', r'/python\1', arg) if arg.endswith('.o'): arg = arg[:-2] + '.bc' - if shared and arg.endswith('.so'): + output = arg + elif shared and arg.endswith('.so'): arg = arg[:-3] + '.wasm' output = arg new_args.append(arg) + if os.path.isfile(output): + print('SKIPPING: ' + ' '.join(new_args)) + return + print(' '.join(new_args)) if not dryrun: