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 18477729cfSJeremy L Thompsonimport re 197b8bbb42Svaleriabarrafrom cffi import FFI 207b8bbb42Svaleriabarraffibuilder = FFI() 217b8bbb42Svaleriabarra 22b3bcc043SJed Brownceed_version_ge = re.compile(r'\s+\(!?CEED_VERSION.*') 23bd4df462SJed Brown 247b8bbb42Svaleriabarra# ------------------------------------------------------------------------------ 257b8bbb42Svaleriabarra# Provide C definitions to CFFI 267b8bbb42Svaleriabarra# ------------------------------------------------------------------------------ 27ec3da8bcSJed Brownwith open(os.path.abspath("include/ceed/ceed.h")) as f: 287b8bbb42Svaleriabarra lines = [line.strip() for line in f if 297b8bbb42Svaleriabarra not line.startswith("#") and 307b8bbb42Svaleriabarra not line.startswith(" static") and 317b8bbb42Svaleriabarra "CeedErrorImpl" not in line and 327b8bbb42Svaleriabarra "const char *, ...);" not in line and 33bd4df462SJed Brown not line.startswith("CEED_EXTERN const char *const") and 34bd4df462SJed Brown not ceed_version_ge.match(line)] 357b8bbb42Svaleriabarra lines = [line.replace("CEED_EXTERN", "extern") for line in lines] 361d83af80SJed Brown header = '\n'.join(lines) 377b8bbb42Svaleriabarra header = header.split("static inline CeedInt CeedIntPow", 1)[0] 3819798369SJed Brown header += '\nextern int CeedVectorGetState(CeedVector, uint64_t*);' 39*c3a5a609SJeremy L Thompson header += '\nextern int CeedElemRestrictionGetELayout(CeedElemRestriction, CeedInt *layout);' 40477729cfSJeremy L Thompson # Note: cffi cannot handle vargs 41477729cfSJeremy L Thompson header = re.sub("va_list", "const char *", header) 427b8bbb42Svaleriabarraffibuilder.cdef(header) 437b8bbb42Svaleriabarra 447b8bbb42Svaleriabarraffibuilder.set_source("_ceed_cffi", 457b8bbb42Svaleriabarra """ 46477729cfSJeremy L Thompson #define va_list const char * 477b8bbb42Svaleriabarra #include <ceed.h> // the C header of the library 487b8bbb42Svaleriabarra """, 49450bb777Svaleriabarra include_dirs=[ 50450bb777Svaleriabarra os.path.abspath("include")], # include path 517b8bbb42Svaleriabarra libraries=["ceed"], # library name, for the linker 5237c134eaSJed Brown library_dirs=['./lib'], # library path, for the linker 537a7b0fa3SJed Brown # use libceed.so as installed 547a7b0fa3SJed Brown runtime_library_dirs=['$ORIGIN/libceed/lib'] 557b8bbb42Svaleriabarra ) 567b8bbb42Svaleriabarra 577b8bbb42Svaleriabarra# ------------------------------------------------------------------------------ 587b8bbb42Svaleriabarra# Builder 597b8bbb42Svaleriabarra# ------------------------------------------------------------------------------ 607b8bbb42Svaleriabarraif __name__ == "__main__": 617b8bbb42Svaleriabarra ffibuilder.compile(verbose=True) 627b8bbb42Svaleriabarra 637b8bbb42Svaleriabarra# ------------------------------------------------------------------------------ 64