BuildTarget.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2012 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. class BuildTarget
  24. {
  25. private static $instances = array();
  26. public $name;
  27. public $output_dir;
  28. public $project_dir;
  29. public $project_rel_path;
  30. public $base_dir;
  31. public $template_app;
  32. public $template_shared_app;
  33. public $template_lib;
  34. public $template_shared_lib;
  35. public $template_activex;
  36. public $template_sln;
  37. public $template_user;
  38. public $template_csproj;
  39. public $solution_ext;
  40. public $output_ext;
  41. public $file_exts;
  42. public $reject_patternss;
  43. public $dont_compile_patterns;
  44. public $source_file_exts;
  45. public $platforms;
  46. public $ldelim;
  47. public $rdelim;
  48. static function add( $name, $out, $project, $base, $template_app, $template_shared_app, $template_lib, $template_shared_lib, $template_activex, $out_ext )
  49. {
  50. $c = new BuildTarget( $name, $out, $project, $base, $template_app, $template_shared_app, $template_lib, $template_shared_lib, $template_activex, $out_ext );
  51. self::$instances[ $name ] = $c;
  52. return $c;
  53. }
  54. static function getInstances()
  55. {
  56. return self::$instances;
  57. }
  58. function BuildTarget( $name, $out, $project, $base, $template_app, $template_shared_app, $template_lib, $template_shared_lib, $template_activex, $out_ext )
  59. {
  60. $this->name = $name;
  61. $this->output_dir = $out;
  62. $this->project_dir = $project;
  63. $this->output_ext = $out_ext;
  64. $this->base_dir = $base;
  65. $this->template_app = $template_app;
  66. $this->template_shared_app = $template_shared_app;
  67. $this->template_lib = $template_lib;
  68. $this->template_shared_lib = $template_shared_lib;
  69. $this->template_activex = $template_activex;
  70. $this->template_csproj = "";
  71. $this->template_user = "";
  72. // The template for a filters file used by VS2010.
  73. $this->template_filter = "";
  74. $p = explode( '/', $project );
  75. $o = array();
  76. for( $i = 0; $i < sizeof( $p ); $i++ )
  77. {
  78. // Skip meaningless . or empty terms.
  79. if( $p[ $i ] == '' || $p[ $i ] == '.' )
  80. continue;
  81. array_push( $o, '..' );
  82. }
  83. $this->project_rel_path = implode( '/', $o );
  84. if (strlen($this->project_rel_path) > 0)
  85. $this->project_rel_path = $this->project_rel_path . "/";
  86. }
  87. function setDelimiters( $l, $r )
  88. {
  89. $this->ldelim = $l;
  90. $this->rdelim = $r;
  91. }
  92. function setSolutionInfo( $template_sln, $template_user, $output_ext, $template_filter = "" )
  93. {
  94. $this->template_sln = $template_sln;
  95. $this->solution_ext = $output_ext;
  96. $this->template_user = $template_user;
  97. $this->template_filter = $template_filter;
  98. }
  99. function setDotNetInfo($template_csprog)
  100. {
  101. $this->template_csproj = $template_csprog;
  102. }
  103. function setFileExtensions()
  104. {
  105. $args = func_get_args();
  106. $count = func_num_args();
  107. $this->file_exts = $args;
  108. }
  109. function setSourceFileExtensions()
  110. {
  111. $args = func_get_args();
  112. $count = func_num_args();
  113. $this->source_file_exts = $args;
  114. }
  115. function setRejectPatterns()
  116. {
  117. $args = func_get_args();
  118. $this->reject_patterns = $args;
  119. }
  120. function setDontCompilePatterns()
  121. {
  122. $args = func_get_args();
  123. $this->dont_compile_patterns = $args;
  124. }
  125. function setPlatforms()
  126. {
  127. $args = func_get_args();
  128. $this->platforms = $args;
  129. }
  130. function supportsPlatform( $platform )
  131. {
  132. if( isset( $this->platforms ) )
  133. foreach( $this->platforms as $rule )
  134. if( strcmp( $rule, $platform ) == 0 )
  135. return true;
  136. return false;
  137. }
  138. function ruleReject( $file )
  139. {
  140. if( isset( $this->reject_patterns ) )
  141. foreach( $this->reject_patterns as $rule )
  142. if( preg_match( $rule, $file ) )
  143. return true;
  144. return false;
  145. }
  146. function allowedFileExt( $file )
  147. {
  148. foreach( $this->file_exts as $ext )
  149. {
  150. $ext = ".{$ext}";
  151. $extLen = strlen( $ext );
  152. $possibleMatch = substr( $file, -$extLen, $extLen );
  153. if( $possibleMatch == $ext )
  154. return true;
  155. }
  156. return false;
  157. }
  158. function isSourceFile( $file )
  159. {
  160. foreach( $this->source_file_exts as $ext )
  161. {
  162. $ext = ".{$ext}";
  163. $extLen = strlen( $ext );
  164. $possibleMatch = substr( $file, -$extLen, $extLen );
  165. if( $possibleMatch == $ext )
  166. return true;
  167. }
  168. return false;
  169. }
  170. function isResourceFile( $file )
  171. {
  172. $ext = ".rc";
  173. $extLen = strlen( $ext );
  174. $possibleMatch = substr( $file, -$extLen, $extLen );
  175. if( $possibleMatch == $ext )
  176. return true;
  177. return false;
  178. }
  179. }
  180. ?>