detect.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. #
  2. # tested on | Windows native | Linux cross-compilation
  3. # ------------------------+-------------------+---------------------------
  4. # MSVS C++ 2010 Express | WORKS | n/a
  5. # Mingw-w64 | WORKS | WORKS
  6. # Mingw-w32 | WORKS | WORKS
  7. # MinGW | WORKS | untested
  8. #
  9. #####
  10. # Notes about MSVS C++ :
  11. #
  12. # - MSVC2010-Express compiles to 32bits only.
  13. #
  14. #####
  15. # Notes about Mingw-w64 and Mingw-w32 under Windows :
  16. #
  17. # - both can be installed using the official installer :
  18. # http://mingw-w64.sourceforge.net/download.php#mingw-builds
  19. #
  20. # - if you want to compile both 32bits and 64bits, don't forget to
  21. # run the installer twice to install them both.
  22. #
  23. # - install them into a path that does not contain spaces
  24. # ( example : "C:/Mingw-w32", "C:/Mingw-w64" )
  25. #
  26. # - if you want to compile faster using the "-j" option, don't forget
  27. # to install the appropriate version of the Pywin32 python extension
  28. # available from : http://sourceforge.net/projects/pywin32/files/
  29. #
  30. # - before running scons, you must add into the environment path
  31. # the path to the "/bin" directory of the Mingw version you want
  32. # to use :
  33. #
  34. # set PATH=C:/Mingw-w32/bin;%PATH%
  35. #
  36. # - then, scons should be able to detect gcc.
  37. # - Mingw-w32 only compiles 32bits.
  38. # - Mingw-w64 only compiles 64bits.
  39. #
  40. # - it is possible to add them both at the same time into the PATH env,
  41. # if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment
  42. # variables.
  43. # For instance, you could store that set of commands into a .bat script
  44. # that you would run just before scons :
  45. #
  46. # set PATH=C:\mingw-w32\bin;%PATH%
  47. # set PATH=C:\mingw-w64\bin;%PATH%
  48. # set MINGW32_PREFIX=C:\mingw-w32\bin\
  49. # set MINGW64_PREFIX=C:\mingw-w64\bin\
  50. #
  51. #####
  52. # Notes about Mingw, Mingw-w64 and Mingw-w32 under Linux :
  53. #
  54. # - default toolchain prefixes are :
  55. # "i586-mingw32msvc-" for MinGW
  56. # "i686-w64-mingw32-" for Mingw-w32
  57. # "x86_64-w64-mingw32-" for Mingw-w64
  58. #
  59. # - if both MinGW and Mingw-w32 are installed on your system
  60. # Mingw-w32 should take the priority over MinGW.
  61. #
  62. # - it is possible to manually override prefixes by defining
  63. # the MINGW32_PREFIX and MINGW64_PREFIX environment variables.
  64. #
  65. #####
  66. # Notes about Mingw under Windows :
  67. #
  68. # - this is the MinGW version from http://mingw.org/
  69. # - install it into a path that does not contain spaces
  70. # ( example : "C:/MinGW" )
  71. # - several DirectX headers might be missing. You can copy them into
  72. # the C:/MinGW/include" directory from this page :
  73. # https://code.google.com/p/mingw-lib/source/browse/trunk/working/avcodec_to_widget_5/directx_include/
  74. # - before running scons, add the path to the "/bin" directory :
  75. # set PATH=C:/MinGW/bin;%PATH%
  76. # - scons should be able to detect gcc.
  77. #
  78. #####
  79. # TODO :
  80. #
  81. # - finish to cleanup this script to remove all the remains of previous hacks and workarounds
  82. # - make it work with the Windows7 SDK that is supposed to enable 64bits compilation for MSVC2010-Express
  83. # - confirm it works well with other Visual Studio versions.
  84. # - update the wiki about the pywin32 extension required for the "-j" option under Windows.
  85. # - update the wiki to document MINGW32_PREFIX and MINGW64_PREFIX
  86. #
  87. import os
  88. import sys
  89. def is_active():
  90. return True
  91. def get_name():
  92. return "Windows"
  93. def can_build():
  94. if (os.name=="nt"):
  95. #building natively on windows!
  96. if (os.getenv("VSINSTALLDIR")):
  97. return True
  98. else:
  99. print("\nMSVC not detected, attempting Mingw.")
  100. mingw32 = ""
  101. mingw64 = ""
  102. if ( os.getenv("MINGW32_PREFIX") ) :
  103. mingw32 = os.getenv("MINGW32_PREFIX")
  104. if ( os.getenv("MINGW64_PREFIX") ) :
  105. mingw64 = os.getenv("MINGW64_PREFIX")
  106. test = "gcc --version > NUL 2>&1"
  107. if os.system(test)!= 0 and os.system(mingw32+test)!=0 and os.system(mingw64+test)!=0 :
  108. print("- could not detect gcc.")
  109. print("Please, make sure a path to a Mingw /bin directory is accessible into the environment PATH.\n")
  110. return False
  111. else:
  112. print("- gcc detected.")
  113. return True
  114. if (os.name=="posix"):
  115. mingw = "i586-mingw32msvc-"
  116. mingw64 = "x86_64-w64-mingw32-"
  117. mingw32 = "i686-w64-mingw32-"
  118. if (os.getenv("MINGW32_PREFIX")):
  119. mingw32=os.getenv("MINGW32_PREFIX")
  120. mingw = mingw32
  121. if (os.getenv("MINGW64_PREFIX")):
  122. mingw64=os.getenv("MINGW64_PREFIX")
  123. test = "gcc --version >/dev/null"
  124. if os.system(mingw+test) == 0 or os.system(mingw64+test) ==0 or os.system(mingw32+test) ==0 :
  125. return True
  126. return False
  127. def get_opts():
  128. mingw=""
  129. mingw32=""
  130. mingw64=""
  131. if ( os.name == "posix" ):
  132. mingw = "i586-mingw32msvc-"
  133. mingw32 = "i686-w64-mingw32-"
  134. mingw64 = "x86_64-w64-mingw32-"
  135. if os.system(mingw32+"gcc --version >/dev/null") != 0 :
  136. mingw32 = mingw
  137. if (os.getenv("MINGW32_PREFIX")):
  138. mingw32=os.getenv("MINGW32_PREFIX")
  139. mingw = mingw32
  140. if (os.getenv("MINGW64_PREFIX")):
  141. mingw64=os.getenv("MINGW64_PREFIX")
  142. return [
  143. ('mingw_prefix','Mingw Prefix',mingw32),
  144. ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64),
  145. ]
  146. def get_flags():
  147. return [
  148. ('freetype','builtin'), #use builtin freetype
  149. ('openssl','builtin'), #use builtin openssl
  150. ('theora','no'),
  151. ]
  152. def configure(env):
  153. env.Append(CPPPATH=['#platform/windows'])
  154. if (os.name=="nt" and os.getenv("VSINSTALLDIR")!=None):
  155. #build using visual studio
  156. env['ENV']['TMP'] = os.environ['TMP']
  157. env.Append(CPPPATH=['#platform/windows/include'])
  158. env.Append(LIBPATH=['#platform/windows/lib'])
  159. if (env["freetype"]!="no"):
  160. env.Append(CCFLAGS=['/DFREETYPE_ENABLED'])
  161. env.Append(CPPPATH=['#tools/freetype'])
  162. env.Append(CPPPATH=['#tools/freetype/freetype/include'])
  163. if (env["target"]=="release"):
  164. env.Append(CCFLAGS=['/O2'])
  165. env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
  166. env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
  167. elif (env["target"]=="release_debug"):
  168. env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED'])
  169. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  170. elif (env["target"]=="debug"):
  171. env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/Od'])
  172. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  173. env.Append(LINKFLAGS=['/DEBUG'])
  174. env.Append(CCFLAGS=['/MT','/Gd','/GR','/nologo'])
  175. env.Append(CXXFLAGS=['/TP'])
  176. env.Append(CPPFLAGS=['/DMSVC', '/GR', ])
  177. env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"])
  178. env.Append(CCFLAGS=['/DWINDOWS_ENABLED'])
  179. env.Append(CCFLAGS=['/DRTAUDIO_ENABLED'])
  180. env.Append(CCFLAGS=['/DWIN32'])
  181. env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
  182. env.Append(CCFLAGS=['/DGLES2_ENABLED'])
  183. env.Append(CCFLAGS=['/DGLEW_ENABLED'])
  184. LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32']
  185. env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
  186. env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"])
  187. if (os.getenv("DXSDK_DIR")):
  188. DIRECTX_PATH=os.getenv("DXSDK_DIR")
  189. else:
  190. DIRECTX_PATH="C:/Program Files/Microsoft DirectX SDK (March 2009)"
  191. if (os.getenv("VCINSTALLDIR")):
  192. VC_PATH=os.getenv("VCINSTALLDIR")
  193. else:
  194. VC_PATH=""
  195. env.Append(CCFLAGS=["/I" + p for p in os.getenv("INCLUDE").split(";")])
  196. env.Append(LIBPATH=[p for p in os.getenv("LIB").split(";")])
  197. env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"])
  198. env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"])
  199. env['ENV'] = os.environ;
  200. else:
  201. # Workaround for MinGW. See:
  202. # http://www.scons.org/wiki/LongCmdLinesOnWin32
  203. if (os.name=="nt"):
  204. import subprocess
  205. def mySubProcess(cmdline,env):
  206. #print "SPAWNED : " + cmdline
  207. startupinfo = subprocess.STARTUPINFO()
  208. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  209. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  210. stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env)
  211. data, err = proc.communicate()
  212. rv = proc.wait()
  213. if rv:
  214. print "====="
  215. print err
  216. print "====="
  217. return rv
  218. def mySpawn(sh, escape, cmd, args, env):
  219. newargs = ' '.join(args[1:])
  220. cmdline = cmd + " " + newargs
  221. rv=0
  222. if len(cmdline) > 32000 and cmd.endswith("ar") :
  223. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  224. for i in range(3,len(args)) :
  225. rv = mySubProcess( cmdline + args[i], env )
  226. if rv :
  227. break
  228. else:
  229. rv = mySubProcess( cmdline, env )
  230. return rv
  231. env['SPAWN'] = mySpawn
  232. #build using mingw
  233. if (os.name=="nt"):
  234. env['ENV']['TMP'] = os.environ['TMP'] #way to go scons, you can be so stupid sometimes
  235. else:
  236. env["PROGSUFFIX"]=env["PROGSUFFIX"]+".exe" # for linux cross-compilation
  237. mingw_prefix=""
  238. if (env["bits"]=="default"):
  239. env["bits"]="32"
  240. if (env["bits"]=="32"):
  241. env.Append(LINKFLAGS=['-static'])
  242. env.Append(LINKFLAGS=['-static-libgcc'])
  243. env.Append(LINKFLAGS=['-static-libstdc++'])
  244. mingw_prefix=env["mingw_prefix"];
  245. else:
  246. env.Append(LINKFLAGS=['-static'])
  247. mingw_prefix=env["mingw_prefix_64"];
  248. nulstr=""
  249. if (os.name=="posix"):
  250. nulstr=">/dev/null"
  251. else:
  252. nulstr=">nul"
  253. # if os.system(mingw_prefix+"gcc --version"+nulstr)!=0:
  254. # #not really super consistent but..
  255. # print("Can't find Windows compiler: "+mingw_prefix)
  256. # sys.exit(255)
  257. if (env["target"]=="release"):
  258. env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2'])
  259. env.Append(LINKFLAGS=['-Wl,--subsystem,windows'])
  260. elif (env["target"]=="release_debug"):
  261. env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED'])
  262. elif (env["target"]=="debug"):
  263. env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED'])
  264. if (env["freetype"]!="no"):
  265. env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
  266. env.Append(CPPPATH=['#tools/freetype'])
  267. env.Append(CPPPATH=['#tools/freetype/freetype/include'])
  268. env["CC"]=mingw_prefix+"gcc"
  269. env['AS']=mingw_prefix+"as"
  270. env['CXX'] = mingw_prefix+"g++"
  271. env['AR'] = mingw_prefix+"ar"
  272. env['RANLIB'] = mingw_prefix+"ranlib"
  273. env['LD'] = mingw_prefix+"g++"
  274. #env['CC'] = "winegcc"
  275. #env['CXX'] = "wineg++"
  276. env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
  277. env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
  278. env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED'])
  279. env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','shlwapi','wsock32','kernel32'])
  280. # if (env["bits"]=="32"):
  281. # # env.Append(LIBS=['gcc_s'])
  282. # #--with-arch=i686
  283. # env.Append(CPPFLAGS=['-march=i686'])
  284. # env.Append(LINKFLAGS=['-march=i686'])
  285. #'d3dx9d'
  286. env.Append(CPPFLAGS=['-DMINGW_ENABLED'])
  287. env.Append(LINKFLAGS=['-g'])
  288. import methods
  289. env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  290. env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  291. env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } )
  292. env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )