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 22ceed_version_ge = re.compile('\s+\(!?CEED_VERSION.*') 23 24# ------------------------------------------------------------------------------ 25# Provide C definitions to CFFI 26# ------------------------------------------------------------------------------ 27with open(os.path.abspath("include/ceed.h")) as f: 28 lines = [line.strip() for line in f if 29 not line.startswith("#") and 30 not line.startswith(" static") and 31 "CeedErrorImpl" not in line and 32 "const char *, ...);" not in line and 33 not line.startswith("CEED_EXTERN const char *const") and 34 not ceed_version_ge.match(line)] 35 lines = [line.replace("CEED_EXTERN", "extern") for line in lines] 36 header = '\n'.join(lines) 37 header = header.split("static inline CeedInt CeedIntPow", 1)[0] 38 header += '\nextern int CeedVectorGetState(CeedVector, uint64_t*);' 39 # Note: cffi cannot handle vargs 40 header = re.sub("va_list", "const char *", header) 41ffibuilder.cdef(header) 42 43ffibuilder.set_source("_ceed_cffi", 44 """ 45 #define va_list const char * 46 #include <ceed.h> // the C header of the library 47 """, 48 include_dirs=[ 49 os.path.abspath("include")], # include path 50 libraries=["ceed"], # library name, for the linker 51 library_dirs=['./lib'], # library path, for the linker 52 # use libceed.so as installed 53 runtime_library_dirs=['$ORIGIN/libceed/lib'] 54 ) 55 56# ------------------------------------------------------------------------------ 57# Builder 58# ------------------------------------------------------------------------------ 59if __name__ == "__main__": 60 ffibuilder.compile(verbose=True) 61 62# ------------------------------------------------------------------------------ 63