10 public function findPackageInfo($path) {
12 if (!strlen($name = $this->findPackageName($path, $header))) {
15 if (!$release = $this->findPackageReleaseVersion($path, $header, strtoupper($name))) {
18 } catch (Exception
$e) {
22 return compact("name", "release");
25 private function findPackageName($path, &$header = null) {
26 $grep_res = (new ExecCmd("grep"))->run(
28 ["-HEo", "phpext_[^ ]+_ptr"],
29 explode("\n", (new ExecCmd("find"))->run([
30 $path, "-type", "f", "-name", "php_*.h"
34 if (!list($header, $phpext_ptr) = explode(":", $grep_res)) {
37 if (!$name = substr($phpext_ptr, 7, -4)) {
44 private function findPackageReleaseVersion($path, $header, $uname) {
45 $cpp_tmp = new Tempfile("cpp");
46 $cpp_hnd = $cpp_tmp->getStream();
47 fprintf($cpp_hnd, "#include \"%s\"\n", $header);
48 fprintf($cpp_hnd, "#if defined(PHP_PECL_%s_VERSION)\n", $uname);
49 fprintf($cpp_hnd, "PHP_PECL_%s_VERSION\n", $uname);
50 fprintf($cpp_hnd, "#elif defined(PHP_%s_VERSION)\n", $uname);
51 fprintf($cpp_hnd, "PHP_%s_VERSION\n", $uname);
52 fprintf($cpp_hnd, "#elif defined(%s_VERSION)\n", $uname);
53 fprintf($cpp_hnd, "%s_VERSION\n", $uname);
54 fprintf($cpp_hnd, "#endif\n");
56 $php_inc = (new ExecCmd((PHP_BINARY ??
"php")."-config"))->run([
59 $ext_inc = (new ExecCmd("find"))->run([
60 $path, "-not", "-path", "*/.*", "-type", "d", "-printf", "-I'%p' "
62 $cpp_res = (new ExecCmd("cpp $php_inc $ext_inc"))->run([
65 return trim(substr($cpp_res, strrpos($cpp_res, "\n")), "\"\n");