requirements.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import subprocess
  2. import os
  3. import shutil
  4. import sys
  5. def compile_it():
  6. if (sys.platform == 'win32'):
  7. subprocess.call(['cmake', '-G', 'Ninja', '..'])
  8. subprocess.call(['ninja'])
  9. else:
  10. subprocess.call(['cmake', '..'])
  11. subprocess.call(['make'])
  12. def get_extension():
  13. if (sys.platform == 'linux') or (sys.platform == 'linux2'):
  14. extension = "so"
  15. elif (sys.platform == 'darwin'):
  16. extension = "dylib"
  17. elif (sys.platform == 'win32'):
  18. extension = "dll"
  19. else:
  20. raise Exception("Unexpected platform: {0}".format(sys.platform))
  21. return extension
  22. def nfsim():
  23. os.chdir('nfsim')
  24. try:
  25. os.mkdir('lib')
  26. except OSError:
  27. pass
  28. os.chdir('lib')
  29. compile_it()
  30. os.chdir('..')
  31. os.chdir('..')
  32. def nfsim_lib():
  33. os.chdir('nfsimCInterface')
  34. try:
  35. os.mkdir('lib')
  36. except OSError:
  37. pass
  38. os.chdir('lib')
  39. extension = get_extension()
  40. if (sys.platform == 'win32'):
  41. subprocess.call(['cmd', '/c', 'mklink', '.\libNFsim.{0}'.format(extension), os.path.join('..', '..', 'nfsim', 'lib', 'libNFsim.{0}'.format(extension))])
  42. os.chdir('..')
  43. subprocess.call(['cmd', '/c', 'mklink', '/D', '.\include', os.path.join('..', 'nfsim', 'include')])
  44. else:
  45. subprocess.call(['ln', '-s', os.path.join('..', '..', 'nfsim', 'lib', 'libNFsim.{0}'.format(extension))])
  46. os.chdir('..')
  47. subprocess.call(['ln', '-s', os.path.join('..', 'nfsim', 'include')])
  48. try:
  49. os.mkdir('build')
  50. except OSError:
  51. pass
  52. os.chdir('build')
  53. compile_it()
  54. os.chdir('..')
  55. os.chdir('..')
  56. def copy_library_files():
  57. try:
  58. os.mkdir('build/lib')
  59. except OSError:
  60. pass
  61. os.chdir('build')
  62. extension = get_extension()
  63. # XXX: For some reason, Windows will build MCell with the files in
  64. # ./build/lib but will fail at runtime if they aren't in the same directory
  65. # as the executable itself (i.e. the libs must be in ./build at runtime)
  66. if (sys.platform == 'win32'):
  67. shutil.copy(os.path.join('..', 'nfsim', 'lib', 'libNFsim.{0}'.format(extension)), ".")
  68. shutil.copy(os.path.join('..', 'nfsimCInterface', 'build', 'libnfsim_c.{0}'.format(extension)), ".")
  69. shutil.copy(os.path.join('..', 'nfsim', 'lib', 'libNFsim.{0}'.format(extension)), "lib")
  70. shutil.copy(os.path.join('..', 'nfsimCInterface', 'build', 'libnfsim_c.{0}'.format(extension)), "lib")
  71. if __name__ == "__main__":
  72. subprocess.call(['git', 'submodule', 'init'])
  73. subprocess.call(['git', 'submodule', 'update'])
  74. os.chdir("..")
  75. nfsim()
  76. nfsim_lib()
  77. copy_library_files()