detect.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import os
  2. import sys
  3. import platform
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "X11"
  8. def can_build():
  9. if (os.name != "posix"):
  10. return False
  11. if sys.platform == "darwin":
  12. return False # no x11 on mac for now
  13. errorval = os.system("pkg-config --version > /dev/null")
  14. if (errorval):
  15. print("pkg-config not found.. x11 disabled.")
  16. return False
  17. x11_error = os.system("pkg-config x11 --modversion > /dev/null ")
  18. if (x11_error):
  19. print("X11 not found.. x11 disabled.")
  20. return False
  21. ssl_error = os.system("pkg-config openssl --modversion > /dev/null ")
  22. if (ssl_error):
  23. print("OpenSSL not found.. x11 disabled.")
  24. return False
  25. x11_error = os.system("pkg-config xcursor --modversion > /dev/null ")
  26. if (x11_error):
  27. print("xcursor not found.. x11 disabled.")
  28. return False
  29. x11_error = os.system("pkg-config xinerama --modversion > /dev/null ")
  30. if (x11_error):
  31. print("xinerama not found.. x11 disabled.")
  32. return False
  33. x11_error = os.system("pkg-config xrandr --modversion > /dev/null ")
  34. if (x11_error):
  35. print("xrandr not found.. x11 disabled.")
  36. return False
  37. return True # X11 enabled
  38. def get_opts():
  39. return [
  40. ('use_llvm', 'Use llvm compiler', 'no'),
  41. ('use_static_cpp', 'link stdc++ statically', 'no'),
  42. ('use_sanitizer', 'Use llvm compiler sanitize address', 'no'),
  43. ('use_leak_sanitizer', 'Use llvm compiler sanitize memory leaks', 'no'),
  44. ('pulseaudio', 'Detect & Use pulseaudio', 'yes'),
  45. ('udev', 'Use udev for gamepad connection callbacks', 'no'),
  46. ('debug_release', 'Add debug symbols to release version', 'no'),
  47. ]
  48. def get_flags():
  49. return [
  50. ('builtin_freetype', 'no'),
  51. ('builtin_libpng', 'no'),
  52. ('builtin_openssl', 'no'),
  53. ('builtin_zlib', 'no'),
  54. ]
  55. def configure(env):
  56. is64 = sys.maxsize > 2**32
  57. if (env["bits"] == "default"):
  58. if (is64):
  59. env["bits"] = "64"
  60. else:
  61. env["bits"] = "32"
  62. env.Append(CPPPATH=['#platform/x11'])
  63. if (env["use_llvm"] == "yes"):
  64. if 'clang++' not in env['CXX']:
  65. env["CC"] = "clang"
  66. env["CXX"] = "clang++"
  67. env["LD"] = "clang++"
  68. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  69. env.extra_suffix = ".llvm"
  70. if (env["use_sanitizer"] == "yes"):
  71. env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
  72. env.Append(LINKFLAGS=['-fsanitize=address'])
  73. env.extra_suffix += "s"
  74. if (env["use_leak_sanitizer"] == "yes"):
  75. env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer'])
  76. env.Append(LINKFLAGS=['-fsanitize=address'])
  77. env.extra_suffix += "s"
  78. # if (env["tools"]=="no"):
  79. # #no tools suffix
  80. # env['OBJSUFFIX'] = ".nt"+env['OBJSUFFIX']
  81. # env['LIBSUFFIX'] = ".nt"+env['LIBSUFFIX']
  82. if (env["target"] == "release"):
  83. if (env["debug_release"] == "yes"):
  84. env.Append(CCFLAGS=['-g2'])
  85. else:
  86. env.Append(CCFLAGS=['-O3', '-ffast-math'])
  87. elif (env["target"] == "release_debug"):
  88. env.Append(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
  89. if (env["debug_release"] == "yes"):
  90. env.Append(CCFLAGS=['-g2'])
  91. elif (env["target"] == "debug"):
  92. env.Append(CCFLAGS=['-g2', '-Wall', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  93. env.ParseConfig('pkg-config x11 --cflags --libs')
  94. env.ParseConfig('pkg-config xinerama --cflags --libs')
  95. env.ParseConfig('pkg-config xcursor --cflags --libs')
  96. env.ParseConfig('pkg-config xrandr --cflags --libs')
  97. if (env['builtin_openssl'] == 'no'):
  98. env.ParseConfig('pkg-config openssl --cflags --libs')
  99. if (env['builtin_libwebp'] == 'no'):
  100. env.ParseConfig('pkg-config libwebp --cflags --libs')
  101. if (env['builtin_freetype'] == 'no'):
  102. env['builtin_libpng'] = 'no' # Freetype links against libpng
  103. env.ParseConfig('pkg-config freetype2 --cflags --libs')
  104. if (env['builtin_libpng'] == 'no'):
  105. env.ParseConfig('pkg-config libpng16 --cflags --libs')
  106. if (env['builtin_enet'] == 'no'):
  107. env.ParseConfig('pkg-config libenet --cflags --libs')
  108. if (env['builtin_squish'] == 'no' and env["tools"] == "yes"):
  109. env.ParseConfig('pkg-config libsquish --cflags --libs')
  110. # Sound and video libraries
  111. # Keep the order as it triggers chained dependencies (ogg needed by others, etc.)
  112. if (env['builtin_libtheora'] == 'no'):
  113. env['builtin_libogg'] = 'no' # Needed to link against system libtheora
  114. env['builtin_libvorbis'] = 'no' # Needed to link against system libtheora
  115. env.ParseConfig('pkg-config theora theoradec --cflags --libs')
  116. if (env['builtin_libvpx'] == 'no'):
  117. env.ParseConfig('pkg-config vpx --cflags --libs')
  118. if (env['builtin_libvorbis'] == 'no'):
  119. env['builtin_libogg'] = 'no' # Needed to link against system libvorbis
  120. env.ParseConfig('pkg-config vorbis vorbisfile --cflags --libs')
  121. if (env['builtin_opus'] == 'no'):
  122. env['builtin_libogg'] = 'no' # Needed to link against system opus
  123. env.ParseConfig('pkg-config opus opusfile --cflags --libs')
  124. if (env['builtin_libogg'] == 'no'):
  125. env.ParseConfig('pkg-config ogg --cflags --libs')
  126. env.Append(CPPFLAGS=['-DOPENGL_ENABLED'])
  127. if (env['builtin_glew'] == 'no'):
  128. env.ParseConfig('pkg-config glew --cflags --libs')
  129. if os.system("pkg-config --exists alsa") == 0:
  130. print("Enabling ALSA")
  131. env.Append(CPPFLAGS=["-DALSA_ENABLED"])
  132. env.ParseConfig('pkg-config alsa --cflags --libs')
  133. else:
  134. print("ALSA libraries not found, disabling driver")
  135. if (platform.system() == "Linux"):
  136. env.Append(CPPFLAGS=["-DJOYDEV_ENABLED"])
  137. if (env["udev"] == "yes"):
  138. # pkg-config returns 0 when the lib exists...
  139. found_udev = not os.system("pkg-config --exists libudev")
  140. if (found_udev):
  141. print("Enabling udev support")
  142. env.Append(CPPFLAGS=["-DUDEV_ENABLED"])
  143. env.ParseConfig('pkg-config libudev --cflags --libs')
  144. else:
  145. print("libudev development libraries not found, disabling udev support")
  146. if (env["pulseaudio"] == "yes"):
  147. if not os.system("pkg-config --exists libpulse-simple"):
  148. print("Enabling PulseAudio")
  149. env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
  150. env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
  151. else:
  152. print("PulseAudio development libraries not found, disabling driver")
  153. env.Append(CPPFLAGS=['-DX11_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL'])
  154. env.Append(LIBS=['GL', 'pthread', 'z'])
  155. if (platform.system() == "Linux"):
  156. env.Append(LIBS='dl')
  157. # env.Append(CPPFLAGS=['-DMPC_FIXED_POINT'])
  158. # host compiler is default..
  159. if (is64 and env["bits"] == "32"):
  160. env.Append(CPPFLAGS=['-m32'])
  161. env.Append(LINKFLAGS=['-m32', '-L/usr/lib/i386-linux-gnu'])
  162. elif (not is64 and env["bits"] == "64"):
  163. env.Append(CPPFLAGS=['-m64'])
  164. env.Append(LINKFLAGS=['-m64', '-L/usr/lib/i686-linux-gnu'])
  165. import methods
  166. env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')})
  167. env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')})
  168. env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')})
  169. #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } )
  170. if (env["use_static_cpp"] == "yes"):
  171. env.Append(LINKFLAGS=['-static-libstdc++'])
  172. list_of_x86 = ['x86_64', 'x86', 'i386', 'i586']
  173. if any(platform.machine() in s for s in list_of_x86):
  174. env["x86_libtheora_opt_gcc"] = True