1<?php 2 3require_once(dirname(__FILE__).'/../../lib/plugins.php'); 4 5class projects_plugin_gcc extends MakeRule { 6 /** 7 * The name of the rule, a human readable string, a unique identifier 8 */ 9 public function name() { return "gcc"; } 10 11 /** 12 * whether this rule can make a given target 13 */ 14 public function can_handle($project, $file) { 15 $name = $file->name(); 16 if (!has_extension($name, ".o")) return false; 17 $cpp = $this->replace_extension($name, ".o", ".cpp"); 18 if ($project->file($cpp) != NULL) return true; 19 $c = $this->replace_extension($name, ".o", ".c"); 20 if ($project->file($c) != NULL) return true; 21 return false; 22 } 23 24 /** 25 * The dependent files needed by this rule 26 */ 27 protected function dependency($project, $file) { 28 $deps = $file->dependency(); 29 $cpp = $this->replace_extension($file->name(), ".o", ".cpp"); 30 if ($project->file($cpp) != NULL && !in_array($cpp, $deps)) { 31 $deps[] = $cpp; 32 return $deps; 33 } 34 $c = $this->replace_extension($file->name(), ".o", ".c"); 35 if ($project->file($c) != NULL && !in_array($c, $deps)) { 36 $deps[] = $c; 37 return $deps; 38 } 39 return $deps; 40 } 41 42 /** 43 * The default recipe 44 */ 45 protected function recipe($project, $file) { 46 $cpp = $this->replace_extension($file->name(), ".o", ".cpp"); 47 if ($project->file($cpp) != NULL) 48 return "g++ -O3 -c -I. -o " . $file->name() . " $cpp"; 49 $c = $this->replace_extension($file->name(), ".o", ".c"); 50 if ($project->file($c) != NULL) 51 return "gcc -O3 -c -I. -o " . $file->name() . " $c"; 52 return NULL; 53 } 54} 55 56?>