|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Package\Library; |
| 6 | + |
| 7 | +use StaticPHP\Attribute\Package\BuildFor; |
| 8 | +use StaticPHP\Attribute\Package\Library; |
| 9 | +use StaticPHP\Package\LibraryPackage; |
| 10 | +use StaticPHP\Runtime\Executor\UnixAutoconfExecutor; |
| 11 | +use StaticPHP\Toolchain\Interface\ToolchainInterface; |
| 12 | +use StaticPHP\Util\DirDiff; |
| 13 | +use StaticPHP\Util\FileSystem; |
| 14 | + |
| 15 | +#[Library('ncurses')] |
| 16 | +class ncurses |
| 17 | +{ |
| 18 | + #[BuildFor('Darwin')] |
| 19 | + #[BuildFor('Linux')] |
| 20 | + public function build(LibraryPackage $package, ToolchainInterface $toolchain): void |
| 21 | + { |
| 22 | + $dirdiff = new DirDiff(BUILD_BIN_PATH); |
| 23 | + |
| 24 | + UnixAutoconfExecutor::create($package) |
| 25 | + ->appendEnv([ |
| 26 | + 'LDFLAGS' => $toolchain->isStatic() ? '-static' : '', |
| 27 | + ]) |
| 28 | + ->configure( |
| 29 | + '--enable-overwrite', |
| 30 | + '--with-curses-h', |
| 31 | + '--enable-pc-files', |
| 32 | + '--enable-echo', |
| 33 | + '--disable-widec', |
| 34 | + '--with-normal', |
| 35 | + '--with-ticlib', |
| 36 | + '--without-tests', |
| 37 | + '--without-dlsym', |
| 38 | + '--without-debug', |
| 39 | + '--enable-symlinks', |
| 40 | + "--bindir={$package->getBinDir()}", |
| 41 | + "--includedir={$package->getIncludeDir()}", |
| 42 | + "--libdir={$package->getLibDir()}", |
| 43 | + "--prefix={$package->getBuildRootPath()}", |
| 44 | + ) |
| 45 | + ->make(); |
| 46 | + $new_files = $dirdiff->getIncrementFiles(true); |
| 47 | + foreach ($new_files as $file) { |
| 48 | + @unlink(BUILD_BIN_PATH . '/' . $file); |
| 49 | + } |
| 50 | + |
| 51 | + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo'); |
| 52 | + shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo'); |
| 53 | + |
| 54 | + $pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc']; |
| 55 | + $package->patchPkgconfPrefix($pkgconf_list); |
| 56 | + |
| 57 | + foreach ($pkgconf_list as $pkgconf) { |
| 58 | + FileSystem::replaceFileStr("{$package->getLibDir()}/pkgconfig/{$pkgconf}", "-L{$package->getLibDir()}", '-L${libdir}'); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments