generator.py 612 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import os
  3. import os.path
  4. import sys
  5. def main():
  6. name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
  7. out = sys.argv[2]
  8. hname = os.path.join(out, name + '.h')
  9. cname = os.path.join(out, name + '.c')
  10. print(os.getcwd(), hname)
  11. with open(hname, 'w') as hfile:
  12. hfile.write('''
  13. #pragma once
  14. #include "export.h"
  15. int DLL_PUBLIC {name}();
  16. '''.format(name=name))
  17. with open(cname, 'w') as cfile:
  18. cfile.write('''
  19. #include "{name}.h"
  20. int {name}() {{
  21. return {size};
  22. }}
  23. '''.format(name=name, size=len(name)))
  24. if __name__ == '__main__':
  25. main()