build.py 733 B

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