You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
6.1 KiB

  1. // Copyright 2005-2013 Intel Corporation. All Rights Reserved.
  2. //
  3. // This file is part of Threading Building Blocks.
  4. //
  5. // Threading Building Blocks is free software; you can redistribute it
  6. // and/or modify it under the terms of the GNU General Public License
  7. // version 2 as published by the Free Software Foundation.
  8. //
  9. // Threading Building Blocks is distributed in the hope that it will be
  10. // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  11. // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Threading Building Blocks; if not, write to the Free Software
  16. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // As a special exception, you may use this file as part of a free software
  19. // library without restriction. Specifically, if other files instantiate
  20. // templates or use macros or inline functions from this file, or you compile
  21. // this file and link it with other files to produce an executable, this
  22. // file does not by itself cause the resulting executable to be covered by
  23. // the GNU General Public License. This exception does not however
  24. // invalidate any other reasons why the executable file might be covered by
  25. // the GNU General Public License.
  26. function doWork() {
  27. var WshShell = WScript.CreateObject("WScript.Shell");
  28. var fso = new ActiveXObject("Scripting.FileSystemObject");
  29. var tmpExec;
  30. tmpExec = WshShell.Run("cmd /c echo int main(){return 0;} >detect.c", 0, true);
  31. // The next block deals with GCC (MinGW)
  32. if ( WScript.Arguments.Count() > 1 && WScript.Arguments(1) == "gcc" ) {
  33. if ( WScript.Arguments(0) == "/arch" ) {
  34. // Get predefined macros
  35. tmpExec = WshShell.Run("cmd /C gcc -dM -E detect.c > detect.map", 0, true);
  36. var file = fso.OpenTextFile("detect.map", 1, 0);
  37. var defs = file.readAll();
  38. file.Close();
  39. //detect target architecture
  40. var intel64=/x86_64|amd64/mgi;
  41. var ia32=/i386/mgi;
  42. if ( defs.match(intel64) ) {
  43. WScript.Echo( "intel64" );
  44. } else if ( defs.match(ia32) ) {
  45. WScript.Echo( "ia32" );
  46. } else {
  47. WScript.Echo( "unknown" );
  48. }
  49. } else {
  50. tmpExec = WshShell.Exec("gcc -dumpversion");
  51. var gcc_version = tmpExec.StdOut.ReadLine();
  52. if ( WScript.Arguments(0) == "/runtime" ) {
  53. WScript.Echo( "mingw"+gcc_version );
  54. }
  55. else if ( WScript.Arguments(0) == "/minversion" ) {
  56. // Comparing strings, not numbers; will not work for two-digit versions
  57. if ( gcc_version >= WScript.Arguments(2) ) {
  58. WScript.Echo( "ok" );
  59. } else {
  60. WScript.Echo( "fail" );
  61. }
  62. }
  63. }
  64. return;
  65. }
  66. //Compile binary
  67. tmpExec = WshShell.Exec("cl /MD detect.c /link /MAP");
  68. while ( tmpExec.Status == 0 ) {
  69. WScript.Sleep(100);
  70. }
  71. //compiler banner that includes version and target arch was printed to stderr
  72. var clVersion = tmpExec.StdErr.ReadAll();
  73. if ( WScript.Arguments(0) == "/arch" ) {
  74. //detect target architecture
  75. var intel64=/AMD64|EM64T|x64/mgi;
  76. var ia64=/IA-64|Itanium/mgi;
  77. var ia32=/[80|\s]x86/mgi;
  78. if ( clVersion.match(intel64) ) {
  79. WScript.Echo( "intel64" );
  80. } else if ( clVersion.match(ia64) ) {
  81. WScript.Echo( "ia64" );
  82. } else if ( clVersion.match(ia32) ) {
  83. WScript.Echo( "ia32" );
  84. } else {
  85. WScript.Echo( "unknown" );
  86. }
  87. return;
  88. }
  89. if ( WScript.Arguments(0) == "/runtime" ) {
  90. //read map-file
  91. var map = fso.OpenTextFile("detect.map", 1, 0);
  92. var mapContext = map.readAll();
  93. map.Close();
  94. //detect runtime
  95. var vc71=/MSVCR71\.DLL/mgi;
  96. var vc80=/MSVCR80\.DLL/mgi;
  97. var vc90=/MSVCR90\.DLL/mgi;
  98. var vc100=/MSVCR100\.DLL/mgi;
  99. var vc110=/MSVCR110\.DLL/mgi;
  100. var psdk=/MSVCRT\.DLL/mgi;
  101. if ( mapContext.match(vc71) ) {
  102. WScript.Echo( "vc7.1" );
  103. } else if ( mapContext.match(vc80) ) {
  104. WScript.Echo( "vc8" );
  105. } else if ( mapContext.match(vc90) ) {
  106. WScript.Echo( "vc9" );
  107. } else if ( mapContext.match(vc100) ) {
  108. WScript.Echo( "vc10" );
  109. } else if ( mapContext.match(vc110) ) {
  110. WScript.Echo( "vc11" );
  111. } else {
  112. WScript.Echo( "unknown" );
  113. }
  114. return;
  115. }
  116. if ( WScript.Arguments(0) == "/minversion" ) {
  117. var compiler_version;
  118. if ( WScript.Arguments(1) == "cl" ) {
  119. compiler_version = clVersion.match(/Compiler Version ([0-9.]+)\s/mi)[1];
  120. // compiler_version is in xx.xx.xxxxx.xx format, i.e. a string.
  121. // It will compare well with major.minor versions where major has two digits,
  122. // which is sufficient as the versions of interest start from 13 (for VC7).
  123. } else if ( WScript.Arguments(1) == "icl" ) {
  124. // Get predefined ICL macros
  125. tmpExec = WshShell.Run("cmd /C icl /QdM /E detect.c > detect.map", 0, true);
  126. var file = fso.OpenTextFile("detect.map", 1, 0);
  127. var defs = file.readAll();
  128. file.Close();
  129. // In #define __INTEL_COMPILER XXYY, XX is the major ICL version, YY is minor
  130. compiler_version = defs.match(/__INTEL_COMPILER[ \t]*([0-9]+).*$/mi)[1]/100;
  131. // compiler version is a number; it compares well with another major.minor
  132. // version number, where major has one, two, and perhaps more digits (9.1, 11, etc).
  133. }
  134. if ( compiler_version >= WScript.Arguments(2) ) {
  135. WScript.Echo( "ok" );
  136. } else {
  137. WScript.Echo( "fail" );
  138. }
  139. return;
  140. }
  141. }
  142. function doClean() {
  143. var fso = new ActiveXObject("Scripting.FileSystemObject");
  144. // delete intermediate files
  145. if ( fso.FileExists("detect.c") )
  146. fso.DeleteFile ("detect.c", false);
  147. if ( fso.FileExists("detect.obj") )
  148. fso.DeleteFile ("detect.obj", false);
  149. if ( fso.FileExists("detect.map") )
  150. fso.DeleteFile ("detect.map", false);
  151. if ( fso.FileExists("detect.exe") )
  152. fso.DeleteFile ("detect.exe", false);
  153. if ( fso.FileExists("detect.exe.manifest") )
  154. fso.DeleteFile ("detect.exe.manifest", false);
  155. }
  156. if ( WScript.Arguments.Count() > 0 ) {
  157. try {
  158. doWork();
  159. } catch( error ) {
  160. WScript.Echo( "unknown" );
  161. }
  162. doClean();
  163. } else {
  164. WScript.Echo( "Supported options:\n"
  165. + "\t/arch [compiler]\n"
  166. + "\t/runtime [compiler]\n"
  167. + "\t/minversion compiler version" );
  168. }