-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
build-ext
executable file
·58 lines (40 loc) · 1.28 KB
/
build-ext
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
#!/usr/bin/env php
<?php
const CONFIG_M4_PATH = './ext/config.m4';
const EXECINFO_MATCH = "PHP_SUBST(TENSOR_SHARED_LIBADD)\n";
const EXECINFO_PATCH = <<<'EOT'
AC_CANONICAL_BUILD
if test "$build_os" = linux-musl; then
CPPFLAGS="${CPPFLAGS:-} -DALPINE_LINUX"
else
AC_CHECK_FUNC(backtrace_symbols, have_backtrace_symbols=yes, have_backtrace_symbols=no)
if test $have_backtrace_symbols = no; then
LDFLAGS="${LDFLAGS:-} -lexecinfo"
fi
fi
EOT
;
chdir(__DIR__);
echo 'Reading config.m4 file... ';
$configM4Contents = file_get_contents(CONFIG_M4_PATH);
if (!$configM4Contents) {
fwrite(STDERR, "Failed to read the config.m4 file!\n");
exit(1);
}
echo "done.\n";
echo 'Applying libexec patch... ';
if (strpos($configM4Contents, EXECINFO_MATCH) === false) {
fwrite(STDERR, "patch entrypoint not found!\n");
exit(1);
} elseif (strpos($configM4Contents, trim(EXECINFO_PATCH)) !== false) {
echo "already applied.\n";
} else {
$configM4Contents = str_replace(EXECINFO_MATCH, EXECINFO_MATCH . EXECINFO_PATCH, $configM4Contents);
echo "done.\n";
echo 'Saving config.m4 file... ';
if (!file_put_contents(CONFIG_M4_PATH, $configM4Contents)) {
fwrite(STDERR, "Failed to write the config.m4 file\n");
exit(1);
}
echo "done.\n";
}