xref: /libCEED/python/build_ceed_cffi.py (revision 477729cfdbe3383ce841609affbc919aa37fc70d)
1# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3# reserved. See files LICENSE and NOTICE for details.
4#
5# This file is part of CEED, a collection of benchmarks, miniapps, software
6# libraries and APIs for efficient high-order finite element and spectral
7# element discretizations for exascale applications. For more information and
8# source code availability see http://github.com/ceed.
9#
10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11# a collaborative effort of two U.S. Department of Energy organizations (Office
12# of Science and the National Nuclear Security Administration) responsible for
13# the planning and preparation of a capable exascale ecosystem, including
14# software, applications, hardware, advanced system engineering and early
15# testbed platforms, in support of the nation's exascale computing imperative.
16
17import os
18import re
19from cffi import FFI
20ffibuilder = FFI()
21
22# ------------------------------------------------------------------------------
23# Provide C definitions to CFFI
24# ------------------------------------------------------------------------------
25with open(os.path.abspath("include/ceed.h")) as f:
26    lines = [line.strip() for line in f if
27             not line.startswith("#") and
28             not line.startswith("  static") and
29             "CeedErrorImpl" not in line and
30             "const char *, ...);" not in line and
31             not line.startswith("CEED_EXTERN const char *const")]
32    lines = [line.replace("CEED_EXTERN", "extern") for line in lines]
33    header = '\n'.join(lines)
34    header = header.split("static inline CeedInt CeedIntPow", 1)[0]
35    # Note: cffi cannot handle vargs
36    header = re.sub("va_list", "const char *", header)
37ffibuilder.cdef(header)
38
39ffibuilder.set_source("_ceed_cffi",
40                      """
41  #define va_list const char *
42  #include <ceed.h>   // the C header of the library
43  """,
44                      include_dirs=[
45                          os.path.abspath("include")],  # include path
46                      libraries=["ceed"],   # library name, for the linker
47                      library_dirs=['./lib'],  # library path, for the linker
48                      # use libceed.so as installed
49                      runtime_library_dirs=['$ORIGIN/libceed/lib']
50                      )
51
52# ------------------------------------------------------------------------------
53# Builder
54# ------------------------------------------------------------------------------
55if __name__ == "__main__":
56    ffibuilder.compile(verbose=True)
57
58# ------------------------------------------------------------------------------
59