build_oxygine_with_sdl.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import unicode_literals, print_function
  4. import os
  5. import sys
  6. import shutil
  7. import zipfile
  8. import time
  9. def recursive_zip(zipf, directory, folder=""):
  10. for item in os.listdir(directory):
  11. if os.path.isfile(os.path.join(directory, item)):
  12. src = os.path.join(directory, item)
  13. dest = folder + os.sep + item
  14. ext = os.path.splitext(dest)[1]
  15. st = os.stat(src)
  16. mtime = time.localtime(st.st_mtime)
  17. date_time = mtime[0:6]
  18. info = zipfile.ZipInfo(dest, date_time)
  19. bts = open(src, "rb").read()
  20. if ext == ".sh" or item in ("PVRTexToolCLI", "oxyresbuild.py", "gen_template.py", "png_strip.py"):
  21. info.external_attr = 0755 << 16L # a+x
  22. # zipf.writestr(info, bts, zipfile.ZIP_DEFLATED)
  23. zipf.write(os.path.join(directory, item), folder + os.sep + item)
  24. elif os.path.isdir(os.path.join(directory, item)):
  25. recursive_zip(zipf, os.path.join(
  26. directory, item), folder + os.sep + item)
  27. def buildzip(name):
  28. print("building zip: " + name)
  29. destzip = "../../" + name
  30. with zipfile.ZipFile(destzip, "w", compression=zipfile.ZIP_DEFLATED) as zp:
  31. recursive_zip(zp, "../../temp")
  32. # return
  33. try:
  34. shutil.copyfile(destzip, "../../../gdrive/oxygine/" + name)
  35. except IOError, e:
  36. pass
  37. try:
  38. shutil.copyfile(destzip, "../../../Dropbox/Public/oxygine/" + name)
  39. except IOError, e:
  40. pass
  41. print("zip created: " + name)
  42. temp = "../../temp"
  43. SDL_dest = temp + "/SDL"
  44. OXYGINE_dest = temp + "/oxygine-framework/"
  45. SOUND_dest = temp + "/oxygine-sound/"
  46. FLOW_dest = temp + "/oxygine-flow/"
  47. print("cleaning temp...")
  48. shutil.rmtree(temp, True)
  49. def export(repo, dest):
  50. cmd = "git -C %s checkout-index -a -f --prefix=%s/" % (
  51. "d:/" + repo, "d:/oxygine-framework/temp/" + dest)
  52. os.system(cmd)
  53. export("oxygine-framework", "oxygine-framework")
  54. buildzip("oxygine-framework.zip")
  55. # ALL IN ONE
  56. #cmd = "hg archive -R ../../../SDL %s" % (SDL_dest, )
  57. #os.system(cmd)
  58. export("SDL", "SDL")
  59. export("oxygine-sound", "oxygine-sound")
  60. export("oxygine-flow", "oxygine-flow")
  61. shutil.rmtree(SDL_dest + "/test")
  62. def fix_file(name, cb):
  63. data = open(name, "rb").read()
  64. data = cb(data)
  65. open(name, "wb").write(data)
  66. fix_file(SDL_dest + "/include/SDL_config_windows.h",
  67. lambda data: data.replace(
  68. "#define SDL_AUDIO_DRIVER_XAUDIO2", "//#define SDL_AUDIO_DRIVER_XAUDIO2")
  69. )
  70. fix_file(SDL_dest + "/src/video/uikit/SDL_uikitview.h",
  71. lambda data: data.replace(
  72. "#define IPHONE_TOUCH_EFFICIENT_DANGEROUS", "//#define IPHONE_TOUCH_EFFICIENT_DANGEROUS")
  73. )
  74. def enum(folder, cb):
  75. for item in os.listdir(folder):
  76. path = folder + item
  77. if os.path.isdir(path):
  78. if item == "data":
  79. cb(path)
  80. enum(path + "/", cb)
  81. def copy(path):
  82. win32 = OXYGINE_dest + "/oxygine/third_party/win32/dlls/"
  83. items = (win32 + "zlib.dll",
  84. win32 + "pthreadVCE2.dll",
  85. "../../libs/SDL2.dll")
  86. if "Demo/" in path:
  87. items = items + (win32 + "libcurl.dll", )
  88. for item in items:
  89. name = os.path.split(item)[1]
  90. shutil.copy(item, path + "/" + name)
  91. enum(OXYGINE_dest + "/examples/", copy)
  92. enum(SOUND_dest + "/examples/", copy)
  93. enum(FLOW_dest + "/examples/", copy)
  94. shutil.copy(SDL_dest + "/android-project/src/org/libsdl/app/SDLActivity.java",
  95. OXYGINE_dest + "/oxygine/SDL/android/lib/src/org/libsdl/app/SDLActivity.java")
  96. libs = ("SDL2.lib", "SDL2main.lib", )
  97. for lib in libs:
  98. shutil.copy("../../libs/" + lib, OXYGINE_dest + "/libs/" + lib)
  99. """
  100. libs = ("libSDL2main.a", "libSDL2.dll", "libSDL2.dll.a")
  101. for lib in libs:
  102. shutil.copy("../../libs/" + lib, OXYGINE_dest + "/libs/" + lib)
  103. """
  104. buildzip("oxygine-framework-with-sdl.zip")
  105. print("done.")