build.py 857 B

12345678910111213141516171819202122232425262728293031
  1. from cffi import FFI, __version__ as cffi_version
  2. def get_header():
  3. fix = 'struct timeval { uint32_t tv_sec; uint32_t tv_usec; };'
  4. f = open('/usr/local/include/pcilib.h')
  5. lines = [x for x in f if not x.startswith('#') and not 'logger' in x and not 'extern "C"' in x]
  6. # cut last 4 lines because they contain the rest of the extern "C" bits
  7. lines = lines[:-4]
  8. # hack because we cannot figure out the system-dependent timeval structure
  9. lines.insert(0, 'struct timeval { uint32_t tv_sec; uint32_t tv_usec; };')
  10. return '\n'.join(lines)
  11. def build():
  12. builder = FFI()
  13. builder.set_source("_pciffi",
  14. r"""
  15. #include <sys/time.h>
  16. #include <pcilib.h>
  17. """,
  18. libraries=['pcilib'])
  19. builder.cdef(get_header())
  20. builder.compile(verbose=True)
  21. if __name__ == '__main__':
  22. build()