xref: /libCEED/python/build_ceed_cffi.py (revision 37c134ea1c2371023999bef9ff6137dbfc025c20)
17b8bbb42Svaleriabarra# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
27b8bbb42Svaleriabarra# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
37b8bbb42Svaleriabarra# reserved. See files LICENSE and NOTICE for details.
47b8bbb42Svaleriabarra#
57b8bbb42Svaleriabarra# This file is part of CEED, a collection of benchmarks, miniapps, software
67b8bbb42Svaleriabarra# libraries and APIs for efficient high-order finite element and spectral
77b8bbb42Svaleriabarra# element discretizations for exascale applications. For more information and
87b8bbb42Svaleriabarra# source code availability see http://github.com/ceed.
97b8bbb42Svaleriabarra#
107b8bbb42Svaleriabarra# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
117b8bbb42Svaleriabarra# a collaborative effort of two U.S. Department of Energy organizations (Office
127b8bbb42Svaleriabarra# of Science and the National Nuclear Security Administration) responsible for
137b8bbb42Svaleriabarra# the planning and preparation of a capable exascale ecosystem, including
147b8bbb42Svaleriabarra# software, applications, hardware, advanced system engineering and early
157b8bbb42Svaleriabarra# testbed platforms, in support of the nation's exascale computing imperative.
167b8bbb42Svaleriabarra
177b8bbb42Svaleriabarraimport os
187b8bbb42Svaleriabarrafrom cffi import FFI
197b8bbb42Svaleriabarraffibuilder = FFI()
207b8bbb42Svaleriabarra
217b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
227b8bbb42Svaleriabarra# Provide C definitions to CFFI
237b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
247b8bbb42Svaleriabarrawith open(os.path.abspath("include/ceed.h")) as f:
257b8bbb42Svaleriabarra    lines = [line.strip() for line in f if
267b8bbb42Svaleriabarra               not line.startswith("#") and
277b8bbb42Svaleriabarra               not line.startswith("  static") and
287b8bbb42Svaleriabarra               "CeedErrorImpl" not in line and
297b8bbb42Svaleriabarra               "const char *, ...);" not in line and
307b8bbb42Svaleriabarra               not line.startswith("CEED_EXTERN const char *const")]
317b8bbb42Svaleriabarra    lines = [line.replace("CEED_EXTERN", "extern") for line in lines]
321d83af80SJed Brown    header = '\n'.join(lines)
337b8bbb42Svaleriabarra    header = header.split("static inline CeedInt CeedIntPow", 1)[0]
347b8bbb42Svaleriabarraffibuilder.cdef(header)
357b8bbb42Svaleriabarra
367b8bbb42Svaleriabarraffibuilder.set_source("_ceed_cffi",
377b8bbb42Svaleriabarra  """
387b8bbb42Svaleriabarra  #include <ceed.h>   // the C header of the library
397b8bbb42Svaleriabarra  """,
407b8bbb42Svaleriabarra  include_dirs = [os.path.abspath("include")], # include path
417b8bbb42Svaleriabarra  libraries = ["ceed"],   # library name, for the linker
42*37c134eaSJed Brown  library_dirs = ['./lib'], # library path, for the linker
43*37c134eaSJed Brown  runtime_library_dirs = ['$ORIGIN/libceed/lib'] # use libceed.so as installed
447b8bbb42Svaleriabarra)
457b8bbb42Svaleriabarra
467b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
477b8bbb42Svaleriabarra# Builder
487b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
497b8bbb42Svaleriabarraif __name__ == "__main__":
507b8bbb42Svaleriabarra    ffibuilder.compile(verbose=True)
517b8bbb42Svaleriabarra
527b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
53