def build_c(src_name, include_files): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run(["gcc", *c_opts, dst_folder / src_name, "-o", target_o]) return target_o
def build(source_dir, output_dir, force=False): flann_include_folder = "/usr/include/flann/" c_common_folder = source_dir / "plaster/tools/c_common" dst_folder = source_dir / "plaster/run/nn_v2/c" c_opts = [ "-c", "-fpic", "-O3", "-I", c_common_folder, "-I", flann_include_folder, "-DDEBUG", ] def build_c(src_name, include_files): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run(["gcc", *c_opts, src_name, "-o", target_o]) return target_o common_include_files = [ f"{c_common_folder}/c_common.h", ] nn_v2_o = build_c(f"{dst_folder}/nn_v2.c", common_include_files) c_common_o = build_c(f"{c_common_folder}/c_common.c", common_include_files) output_so = output_dir / "plaster/run/nn_v2/c/_nn_v2.so" if force or any_out_of_date(parents=[nn_v2_o, c_common_o], children=[output_so]): subprocess.run( [ "gcc", "-shared", nn_v2_o, c_common_o, "-lflann", "-llz4", "-o", output_so, ] ) assert output_so.exists()
def build(source_dir, output_dir, force=False): # In order to build survey_v2, libflann-dev (debian) or flann-devel (centos/manylinux) must be installed flann_include_folder = "/usr/include/flann/" c_common_folder = source_dir / "plaster/tools/c_common" dst_folder = source_dir / "plaster/run/survey_v2/c" c_opts = [ "-c", "-fpic", "-O3", "-I", c_common_folder, "-I", flann_include_folder, "-DDEBUG", ] def build_c(src_name, include_files): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run(["gcc", *c_opts, src_name, "-o", target_o]) return target_o common_include_files = [ f"{c_common_folder}/c_common.h", ] survey_v2_o = build_c(f"{dst_folder}/survey_v2.c", common_include_files) c_common_o = build_c(f"{c_common_folder}/c_common.c", common_include_files) survey_v2_so = output_dir / "plaster/run/survey_v2/c/_survey_v2.so" if force or any_out_of_date(parents=[survey_v2_o, c_common_o], children=[survey_v2_so]): subprocess.run([ "gcc", "-shared", survey_v2_o, c_common_o, "-lflann", "-llz4", "-o", survey_v2_so, ]) assert survey_v2_so.exists()
def build(source_dir, output_dir, force=False): c_common_folder = source_dir / "plaster/tools/c_common" dst_folder = source_dir / "plaster/run/sigproc_v3/c" c_opts = [ "-c", "-fpic", "-O3", "-I", c_common_folder, "-DDEBUG", ] def build_c(src_name, include_files=tuple()): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run( ["gcc", *c_opts, dst_folder / src_name, "-o", target_o]).check_returncode() return target_o include_files = ( f"{c_common_folder}/c_common.h", f"./_sigproc_v3.h", ) sigproc_v3_o = build_c("sigproc_v3.c", include_files) c_common_o = build_c(f"{c_common_folder}/c_common.c", include_files) sigproc_v3_so = output_dir / "plaster/run/sigproc_v3/c/_sigproc_v3.so" if force or any_out_of_date(parents=[sigproc_v3_o, c_common_o], children=[sigproc_v3_so]): subprocess.run([ "gcc", "-shared", "-o", sigproc_v3_so, sigproc_v3_o, c_common_o, "-lm", ]).check_returncode() assert sigproc_v3_so.exists()
def build(source_dir, output_dir, force=False): c_common_folder = source_dir / "plaster/tools/c_common" dst_folder = source_dir / "plaster/run/sim_v2/c" c_opts = [ "-c", "-fpic", "-O3", "-I", c_common_folder, "-DDEBUG", ] def build_c(src_name, include_files): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run(["gcc", *c_opts, src_name, "-o", target_o]) return target_o common_include_files = [ f"{c_common_folder}/c_common.h", ] o_filename = build_c(f"{dst_folder}/sim_v2.c", common_include_files) c_common_o = build_c(f"{c_common_folder}/c_common.c", common_include_files) so_filename = output_dir / "plaster/run/sim_v2/c/_sim_v2.so" if force or any_out_of_date(parents=[o_filename, c_common_o], children=[so_filename]): subprocess.run([ "gcc", "-shared", "-o", so_filename, o_filename, c_common_o, "-lm", ]) assert so_filename.exists()
def build(source_dir, output_dir, force=False): cwd = pathlib.Path().absolute() c_common_folder = source_dir / "plaster/tools/c_common" dst_folder = source_dir / "plaster/run/sigproc_v2/c_gauss2_fitter" levmar_folder = dst_folder / "levmar-2.6" # It might be more correct to not version control the output of cmake in levmar-2.6 and # run cmake during build os.chdir(str(levmar_folder)) make_env = os.environ.copy() make_env["ENV_OPTS"] = "-fPIC" subprocess.run(["make"], env=make_env, capture_output=True) os.chdir(str(cwd)) c_opts = [ "-c", "-fpic", "-O3", "-I", c_common_folder, "-I", levmar_folder, # "./levmar-2.6", "-DDEBUG", ] def build_c(src_name, include_files): base_src_name = pathlib.Path(src_name).stem target_o = f"{dst_folder}/_{base_src_name}.o" if force or any_out_of_date( parents=[src_name, *include_files], children=[target_o], ): subprocess.run(["gcc", *c_opts, dst_folder / src_name, "-o", target_o]) return target_o common_include_files = [ f"{c_common_folder}/c_common.h", ] gauss2_fitter_o = build_c("gauss2_fitter.c", common_include_files) c_common_o = build_c(f"{c_common_folder}/c_common.c", common_include_files) gauss2_fitter_so = ( output_dir / "plaster/run/sigproc_v2/c_gauss2_fitter/_gauss2_fitter.so" ) if force or any_out_of_date( parents=[gauss2_fitter_o, c_common_o], children=[gauss2_fitter_so] ): subprocess.run( [ "gcc", "-shared", "-o", str(gauss2_fitter_so), gauss2_fitter_o, c_common_o, "-L", "./levmar-2.6", "-llevmar", "-lm", "-llapack", "-lblas", ] ) assert gauss2_fitter_so.exists()