-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.py
39 lines (26 loc) · 824 Bytes
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Compile Fluid2d Fortran routines into Python modules
using f2py
March 2023: the compilation now by-pass 'make' and 'Makefile'
"""
import os
import glob
import subprocess
FFLAGS = "-O3 -march=native -fPIC"
srcs = ["core/fortran_advection.f90",
"core/fortran_diag.f90",
"core/fortran_fluxes.f90",
"core/fortran_operators.f90",
"core/gmg/fortran_multigrid.f90"]
pwd = os.getcwd()
null = subprocess.PIPE
print("Compile Fortran routines to Python modules")
for filename in srcs:
src = os.path.basename(filename)
direc = os.path.dirname(filename)
lib = os.path.splitext(src)[0]
localdir = f"{pwd}/{direc}"
cmd = ["f2py", f'--opt={FFLAGS}', "-m", lib, "-c", src]
print(" ".join(cmd))
os.chdir(localdir)
subprocess.call(cmd, stdout=null, stderr=null)