detect.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import os
  2. import sys
  3. def is_active():
  4. return True
  5. def get_name():
  6. return "Windows"
  7. def can_build():
  8. if (os.name=="nt"):
  9. #building natively on windows!
  10. if (os.getenv("VSINSTALLDIR")):
  11. return True
  12. else:
  13. print("MSVC Not detected, attempting mingw.")
  14. return True
  15. if (os.name=="posix"):
  16. mingw = "i586-mingw32msvc-"
  17. mingw64 = "i686-w64-mingw32-"
  18. if (os.getenv("MINGW32_PREFIX")):
  19. mingw=os.getenv("MINGW32_PREFIX")
  20. if (os.getenv("MINGW64_PREFIX")):
  21. mingw64=os.getenv("MINGW64_PREFIX")
  22. if os.system(mingw+"gcc --version >/dev/null") == 0 or os.system(mingw64+"gcc --version >/dev/null") ==0:
  23. return True
  24. return False
  25. def get_opts():
  26. mingw=""
  27. mingw64=""
  28. if (os.name!="nt"):
  29. mingw = "i586-mingw32msvc-"
  30. mingw64 = "i686-w64-mingw32-"
  31. if (os.getenv("MINGW32_PREFIX")):
  32. mingw=os.getenv("MINGW32_PREFIX")
  33. if (os.getenv("MINGW64_PREFIX")):
  34. mingw64=os.getenv("MINGW64_PREFIX")
  35. return [
  36. ('mingw_prefix','Mingw Prefix',mingw),
  37. ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64),
  38. ('mingw64_for_32','Use Mingw 64 for 32 Bits Build',"no"),
  39. ]
  40. def get_flags():
  41. return [
  42. ('freetype','builtin'), #use builtin freetype
  43. ('openssl','builtin'), #use builtin openssl
  44. ]
  45. def configure(env):
  46. env.Append(CPPPATH=['#platform/windows'])
  47. if (os.name=="nt" and os.getenv("VSINSTALLDIR")!=None):
  48. #build using visual studio
  49. env['ENV']['TMP'] = os.environ['TMP']
  50. env.Append(CPPPATH=['#platform/windows/include'])
  51. env.Append(LIBPATH=['#platform/windows/lib'])
  52. if (env["freetype"]!="no"):
  53. env.Append(CCFLAGS=['/DFREETYPE_ENABLED'])
  54. env.Append(CPPPATH=['#tools/freetype'])
  55. env.Append(CPPPATH=['#tools/freetype/freetype/include'])
  56. if (env["target"]=="release"):
  57. env.Append(CCFLAGS=['/O2'])
  58. env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
  59. env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
  60. elif (env["target"]=="release_debug"):
  61. env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED'])
  62. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  63. elif (env["target"]=="debug"):
  64. env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/O1'])
  65. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  66. env.Append(LINKFLAGS=['/DEBUG'])
  67. env.Append(CCFLAGS=['/MT','/Gd','/GR','/nologo'])
  68. env.Append(CXXFLAGS=['/TP'])
  69. env.Append(CPPFLAGS=['/DMSVC', '/GR', ])
  70. env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"])
  71. env.Append(CCFLAGS=['/DWINDOWS_ENABLED'])
  72. env.Append(CCFLAGS=['/DRTAUDIO_ENABLED'])
  73. env.Append(CCFLAGS=['/DWIN32'])
  74. env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
  75. env.Append(CCFLAGS=['/DGLES2_ENABLED'])
  76. env.Append(CCFLAGS=['/DGLES1_ENABLED'])
  77. env.Append(CCFLAGS=['/DGLEW_ENABLED'])
  78. LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI', 'wsock32', 'shell32','advapi32']
  79. env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
  80. env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"])
  81. if (os.getenv("DXSDK_DIR")):
  82. DIRECTX_PATH=os.getenv("DXSDK_DIR")
  83. else:
  84. DIRECTX_PATH="C:/Program Files/Microsoft DirectX SDK (March 2009)"
  85. if (os.getenv("VCINSTALLDIR")):
  86. VC_PATH=os.getenv("VCINSTALLDIR")
  87. else:
  88. VC_PATH=""
  89. env.Append(CCFLAGS=["/I" + p for p in os.getenv("INCLUDE").split(";")])
  90. env.Append(LIBPATH=[p for p in os.getenv("LIB").split(";")])
  91. env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"])
  92. env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"])
  93. env['ENV'] = os.environ;
  94. else:
  95. #build using mingw
  96. if (os.name=="nt"):
  97. env['ENV']['TMP'] = os.environ['TMP'] #way to go scons, you can be so stupid sometimes
  98. mingw_prefix=""
  99. if (env["bits"]=="default"):
  100. env["bits"]="32"
  101. use64=False
  102. if (env["bits"]=="32"):
  103. if (env["mingw64_for_32"]=="yes"):
  104. env.Append(CCFLAGS=['-m32'])
  105. env.Append(LINKFLAGS=['-m32'])
  106. env.Append(LINKFLAGS=['-static-libgcc'])
  107. env.Append(LINKFLAGS=['-static-libstdc++'])
  108. mingw_prefix=env["mingw_prefix_64"];
  109. else:
  110. mingw_prefix=env["mingw_prefix"];
  111. else:
  112. mingw_prefix=env["mingw_prefix_64"];
  113. env.Append(LINKFLAGS=['-static'])
  114. nulstr=""
  115. if (os.name=="posix"):
  116. nulstr=">/dev/null"
  117. else:
  118. nulstr=">nul"
  119. if os.system(mingw_prefix+"gcc --version"+nulstr)!=0:
  120. #not really super consistent but..
  121. print("Can't find Windows compiler: "+mingw_prefix)
  122. sys.exit(255)
  123. if (env["target"]=="release"):
  124. env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2'])
  125. env.Append(LINKFLAGS=['-Wl,--subsystem,windows'])
  126. elif (env["target"]=="release_debug"):
  127. env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED'])
  128. elif (env["target"]=="debug"):
  129. env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED'])
  130. if (env["freetype"]!="no"):
  131. env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
  132. env.Append(CPPPATH=['#tools/freetype'])
  133. env.Append(CPPPATH=['#tools/freetype/freetype/include'])
  134. env["CC"]=mingw_prefix+"gcc"
  135. env['AS']=mingw_prefix+"as"
  136. env['CXX'] = mingw_prefix+"g++"
  137. env['AR'] = mingw_prefix+"ar"
  138. env['RANLIB'] = mingw_prefix+"ranlib"
  139. env['LD'] = mingw_prefix+"g++"
  140. #env['CC'] = "winegcc"
  141. #env['CXX'] = "wineg++"
  142. env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
  143. env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
  144. env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLEW_ENABLED'])
  145. env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','wsock32','kernel32'])
  146. #'d3dx9d'
  147. env.Append(CPPFLAGS=['-DMINGW_ENABLED'])
  148. env.Append(LINKFLAGS=['-g'])
  149. import methods
  150. env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  151. env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  152. env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } )
  153. env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )