detect.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import os
  2. import sys
  3. def is_active():
  4. return True
  5. def get_name():
  6. return "OSX"
  7. def can_build():
  8. if (sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ)):
  9. return True
  10. return False
  11. def get_opts():
  12. from SCons.Variables import BoolVariable, EnumVariable
  13. return [
  14. ('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
  15. EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
  16. BoolVariable('separate_debug_symbols', 'Create a separate file with the debug symbols', False),
  17. ]
  18. def get_flags():
  19. return [
  20. ]
  21. def configure(env):
  22. ## Build type
  23. if (env["target"] == "release"):
  24. env.Prepend(CCFLAGS=['-O3', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
  25. if (env["debug_symbols"] == "yes"):
  26. env.Prepend(CCFLAGS=['-g1'])
  27. if (env["debug_symbols"] == "full"):
  28. env.Prepend(CCFLAGS=['-g2'])
  29. elif (env["target"] == "release_debug"):
  30. env.Prepend(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  31. if (env["debug_symbols"] == "yes"):
  32. env.Prepend(CCFLAGS=['-g1'])
  33. if (env["debug_symbols"] == "full"):
  34. env.Prepend(CCFLAGS=['-g2'])
  35. elif (env["target"] == "debug"):
  36. env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  37. ## Architecture
  38. is64 = sys.maxsize > 2**32
  39. if (env["bits"] == "default"):
  40. env["bits"] = "64" if is64 else "32"
  41. ## Compiler configuration
  42. if "OSXCROSS_ROOT" not in os.environ: # regular native build
  43. if (env["bits"] == "fat"):
  44. env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  45. env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  46. elif (env["bits"] == "32"):
  47. env.Append(CCFLAGS=['-arch', 'i386'])
  48. env.Append(LINKFLAGS=['-arch', 'i386'])
  49. else: # 64-bit, default
  50. env.Append(CCFLAGS=['-arch', 'x86_64'])
  51. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  52. if (env["macports_clang"] != 'no'):
  53. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  54. mpclangver = env["macports_clang"]
  55. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  56. env["LINK"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  57. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  58. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  59. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  60. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  61. env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  62. else: # osxcross build
  63. root = os.environ.get("OSXCROSS_ROOT", 0)
  64. if env["bits"] == "fat":
  65. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  66. env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  67. env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  68. elif env["bits"] == "32":
  69. basecmd = root + "/target/bin/i386-apple-" + env["osxcross_sdk"] + "-"
  70. else: # 64-bit, default
  71. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  72. ccache_path = os.environ.get("CCACHE")
  73. if ccache_path == None:
  74. env['CC'] = basecmd + "cc"
  75. env['CXX'] = basecmd + "c++"
  76. else:
  77. # there aren't any ccache wrappers available for OS X cross-compile,
  78. # to enable caching we need to prepend the path to the ccache binary
  79. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  80. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  81. env['AR'] = basecmd + "ar"
  82. env['RANLIB'] = basecmd + "ranlib"
  83. env['AS'] = basecmd + "as"
  84. env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  85. if (env["CXX"] == "clang++"):
  86. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  87. env["CC"] = "clang"
  88. env["LINK"] = "clang++"
  89. ## Dependencies
  90. if env['builtin_libtheora']:
  91. env["x86_libtheora_opt_gcc"] = True
  92. ## Flags
  93. env.Append(CPPPATH=['#platform/osx'])
  94. env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED'])
  95. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo'])
  96. env.Append(LIBS=['pthread'])
  97. env.Append(CPPFLAGS=['-mmacosx-version-min=10.9'])
  98. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])