build_oxygine_with_sdl.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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", "gradlew"):
  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. FT_dest = temp + "/oxygine-freetype/"
  48. print("cleaning temp...")
  49. shutil.rmtree(temp, True)
  50. def export(repo, dest):
  51. print("exporting " + repo)
  52. cmd = "git -C %s checkout-index -a -f --prefix=%s/" % (
  53. "d:/" + repo, "d:/oxygine-framework/temp/" + dest)
  54. os.system(cmd)
  55. export("oxygine-framework", "oxygine-framework")
  56. buildzip("oxygine-framework.zip")
  57. # ALL IN ONE
  58. #cmd = "hg archive -R ../../../SDL %s" % (SDL_dest, )
  59. #os.system(cmd)
  60. export("SDL", "SDL")
  61. export("oxygine-sound", "oxygine-sound")
  62. export("oxygine-flow", "oxygine-flow")
  63. export("oxygine-freetype", "oxygine-freetype")
  64. shutil.rmtree(SDL_dest + "/test")
  65. def fix_file(name, cb):
  66. data = open(name, "rb").read()
  67. data = cb(data)
  68. open(name, "wb").write(data)
  69. fix_file(SDL_dest + "/include/SDL_config_windows.h",
  70. lambda data: data.replace(
  71. "#define SDL_AUDIO_DRIVER_XAUDIO2", "//#define SDL_AUDIO_DRIVER_XAUDIO2")
  72. )
  73. fix_file(SDL_dest + "/src/video/uikit/SDL_uikitview.h",
  74. lambda data: data.replace(
  75. "#define IPHONE_TOUCH_EFFICIENT_DANGEROUS", "//#define IPHONE_TOUCH_EFFICIENT_DANGEROUS")
  76. )
  77. def enum(folder, cb):
  78. for item in os.listdir(folder):
  79. path = folder + item
  80. if os.path.isdir(path):
  81. if item == "data":
  82. cb(path)
  83. enum(path + "/", cb)
  84. def copy(path):
  85. win32 = OXYGINE_dest + "/oxygine/third_party/win32/dlls/"
  86. items = (win32 + "zlib.dll",
  87. win32 + "pthreadVCE2.dll",
  88. "../../libs/SDL2.dll")
  89. if "Demo/" in path:
  90. items = items + (win32 + "libcurl.dll", win32 + "ssleay32.dll", win32 + "libssh2.dll", win32 + "libeay32.dll")
  91. for item in items:
  92. name = os.path.split(item)[1]
  93. shutil.copy(item, path + "/" + name)
  94. enum(OXYGINE_dest + "/examples/", copy)
  95. enum(SOUND_dest + "/examples/", copy)
  96. enum(FLOW_dest + "/examples/", copy)
  97. enum(FT_dest + "/examples/", copy)
  98. shutil.copy(SDL_dest + "/android-project/src/org/libsdl/app/SDLActivity.java",
  99. OXYGINE_dest + "/oxygine/SDL/android/lib/src/org/libsdl/app/SDLActivity.java")
  100. libs = ("SDL2.lib", "SDL2main.lib", )
  101. for lib in libs:
  102. shutil.copy("../../libs/" + lib, OXYGINE_dest + "/libs/" + lib)
  103. """
  104. libs = ("libSDL2main.a", "libSDL2.dll", "libSDL2.dll.a")
  105. for lib in libs:
  106. shutil.copy("../../libs/" + lib, OXYGINE_dest + "/libs/" + lib)
  107. """
  108. buildzip("oxygine-framework-with-sdl.zip")
  109. print("done.")