2023-04-30 15:04:50 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
2024-07-09 15:05:53 +08:00
|
|
|
use SPC\store\FileSystem;
|
2025-06-09 19:32:31 +08:00
|
|
|
use SPC\util\executor\UnixAutoconfExecutor;
|
2025-07-01 18:09:17 +07:00
|
|
|
use SPC\util\SPCTarget;
|
2024-07-09 15:05:53 +08:00
|
|
|
|
2023-04-30 15:04:50 +08:00
|
|
|
trait ncurses
|
|
|
|
|
{
|
2026-05-06 09:35:20 +07:00
|
|
|
public function patchBeforeBuild(): bool
|
|
|
|
|
{
|
|
|
|
|
// MKlib_gen.sh feeds preprocessor stdout through a sed/awk pipeline into lib_gen.c.
|
|
|
|
|
// zig-cc/clang leaks the "N warning(s) generated." summary onto stdout (not stderr),
|
|
|
|
|
// and that line ends up as invalid C in the generated source. Filter it out of the pipe.
|
|
|
|
|
FileSystem::replaceFileStr(
|
|
|
|
|
$this->source_dir . '/ncurses/base/MKlib_gen.sh',
|
|
|
|
|
'$preprocessor $TMP 2>/dev/null \\',
|
|
|
|
|
"\$preprocessor \$TMP 2>/dev/null \\\n| grep -v ' generated\\.\$' \\",
|
|
|
|
|
);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
protected function build(): void
|
2023-04-30 15:04:50 +08:00
|
|
|
{
|
2024-07-09 15:05:53 +08:00
|
|
|
$filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
|
|
|
|
|
|
2025-06-09 19:32:31 +08:00
|
|
|
UnixAutoconfExecutor::create($this)
|
2025-06-27 18:21:22 +07:00
|
|
|
->appendEnv([
|
2026-05-06 09:35:20 +07:00
|
|
|
'CFLAGS' => '-std=c17 -w',
|
2025-07-01 18:09:17 +07:00
|
|
|
'LDFLAGS' => SPCTarget::isStatic() ? '-static' : '',
|
2025-06-27 18:21:22 +07:00
|
|
|
])
|
2025-06-09 19:32:31 +08:00
|
|
|
->configure(
|
|
|
|
|
'--enable-overwrite',
|
|
|
|
|
'--with-curses-h',
|
2025-06-09 22:54:44 +08:00
|
|
|
'--enable-pc-files',
|
2025-06-09 19:32:31 +08:00
|
|
|
'--enable-echo',
|
|
|
|
|
'--disable-widec',
|
|
|
|
|
'--with-normal',
|
|
|
|
|
'--with-ticlib',
|
|
|
|
|
'--without-tests',
|
|
|
|
|
'--without-dlsym',
|
|
|
|
|
'--without-debug',
|
2025-12-10 15:43:24 +08:00
|
|
|
'--enable-symlinks',
|
2025-06-09 19:32:31 +08:00
|
|
|
"--bindir={$this->getBinDir()}",
|
|
|
|
|
"--includedir={$this->getIncludeDir()}",
|
|
|
|
|
"--libdir={$this->getLibDir()}",
|
|
|
|
|
"--prefix={$this->getBuildRootPath()}",
|
|
|
|
|
)
|
|
|
|
|
->make();
|
2024-07-09 15:05:53 +08:00
|
|
|
$final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
|
|
|
|
|
// Remove the new files
|
2025-09-07 14:10:28 +08:00
|
|
|
$new_files = array_diff($final, $filelist ?: []);
|
2024-07-09 15:05:53 +08:00
|
|
|
foreach ($new_files as $file) {
|
|
|
|
|
@unlink(BUILD_BIN_PATH . '/' . $file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
|
|
|
|
|
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
|
|
|
|
|
|
|
|
|
|
$pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc'];
|
|
|
|
|
$this->patchPkgconfPrefix($pkgconf_list);
|
|
|
|
|
|
|
|
|
|
foreach ($pkgconf_list as $pkgconf) {
|
|
|
|
|
FileSystem::replaceFileStr(BUILD_LIB_PATH . '/pkgconfig/' . $pkgconf, '-L' . BUILD_LIB_PATH, '-L${libdir}');
|
|
|
|
|
}
|
2023-04-30 15:04:50 +08:00
|
|
|
}
|
|
|
|
|
}
|