-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.php
84 lines (73 loc) · 1.58 KB
/
generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @param string $dir
* @param \Closure $callback
* @return void
*/
function rscan_callback(string $dir, Closure $callback)
{
$dir = realpath($dir);
$scan = scandir($dir);
unset($scan[0], $scan[1]);
foreach ($scan as $k => $file) {
if (is_dir($dir."/".$file)) {
rscan_callback($dir."/".$file, $callback);
} else {
$callback($dir."/".$file);
}
}
}
/**
* @param string $str
* @return string
*/
function iescape(string $str): string
{
return str_replace(
["\\", "\""],
["\\\\", "\\\""],
$str
);
}
/**
* @param string $str
* @return string
*/
function rd(string $str): string
{
return "\"".iescape($str)."\"";
}
$noCompile = true;
$closure = function (string $file) use ($argv, &$noCompile) {
if (preg_match("/(.+)(?:\.frag\.)(h|c|cc|cpp)$/", $file, $f)) {
$targetFile = $f[1].".".$f[2];
$dontCompile = file_exists($targetFile) && (filemtime($file) < filemtime($targetFile));
if (isset($argv[1])) {
$noCompile = false;
if ($argv[1] === "deps") {
print $targetFile."\n";
return;
} else if ($argv[1] === "build") {
print $file."\n";
return;
} else if ($argv[1] === "clean") {
unlink($targetFile);
}
}
if ($dontCompile) {
return;
}
$noCompile = false;
print "Compiling {$targetFile}...\n";
$content = file_get_contents($file);
ob_start();
eval("?>".$content);
file_put_contents($targetFile, ob_get_clean());
}
};
rscan_callback(__DIR__."/src", $closure);
rscan_callback(__DIR__."/include", $closure);
if ($noCompile) {
print "generator.php: Nothing to be done for 'all'\n";
exit(0);
}