1<?php
2
3require_once(dirname(__FILE__).'/../../lib/plugins.php');
4
5class projects_plugin_link extends MakeRule {
6	/**
7	 * The name of the rule, a human readable string, a unique identifier
8	 */
9	public function name() { return "link"; }
10
11	/**
12	 * whether this rule can make a given target
13	 */
14	public function can_handle($project, $file) {
15		$deps = $file->dependency();
16		if (!$deps) return false;
17		foreach ($deps as $dep) {
18			if (has_extension($dep, ".o")) continue;
19			if (has_extension($dep, ".a")) continue;
20			return false;
21		}
22		return true;
23	}
24
25	/**
26	 * The dependent recipe
27	 */
28	protected function recipe($project, $file) {
29		$deps = $file->dependency();
30		$args = implode(" ", $deps);
31		$name = $file->name();
32		if (has_extension($name, ".a"))
33			return "ar rcs $name $args";
34		return "g++ -static -o $name $args";
35	}
36}
37
38?>