diff --git a/prepare.php b/prepare.php index b2b11ae82a..97e27e1bea 100755 --- a/prepare.php +++ b/prepare.php @@ -85,8 +85,7 @@ $p->setLogicalProcessors('$(nproc 2> /dev/null)'); } -$p->setExtraCflags('-fno-ident -Os'); -$p->withPreInstallCommand('set -x'); +$p->setExtraCflags(' -Os'); // Generate make.sh $p->execute(); diff --git a/sapi/src/Library.php b/sapi/src/Library.php index 6871dd1cb4..223a24ac77 100644 --- a/sapi/src/Library.php +++ b/sapi/src/Library.php @@ -40,7 +40,7 @@ class Library extends Project public bool $enableBuildLibraryCached = true; - public string $preInstallCommand = ''; + public array $preInstallCommands = []; public bool $enableBuildLibraryHttpProxy = false; @@ -160,9 +160,11 @@ public function withCleanPreInstallDirectory(string $preInstallDir): static return $this; } - public function withPreInstallCommand(string $preInstallCommand): static + public function withPreInstallCommand(string $os, string $preInstallCommand): static { - $this->preInstallCommand = $preInstallCommand; + if (!empty($os) && in_array($os, ['alpine','debian','ubuntu','macos']) && !empty($preInstallCommand)) { + $this->preInstallCommands[$os][] = $preInstallCommand; + } return $this; } diff --git a/sapi/src/Preprocessor.php b/sapi/src/Preprocessor.php index dd3369ee94..e7cc364c5c 100644 --- a/sapi/src/Preprocessor.php +++ b/sapi/src/Preprocessor.php @@ -72,7 +72,13 @@ class Preprocessor protected array $exportVariables = []; - protected array $preInstallCommands = []; + protected array $preInstallCommands = [ + 'alpine' => [], + 'debian' => [], + 'ubuntu' => [], + 'macos' => [] + ]; + /** * default value : CPU logical processors * @var string @@ -432,11 +438,8 @@ protected function downloadFile(string $url, string $file, string $md5sum, strin * @param string $downloadScript * @return void */ - protected function downloadFileWithScript( - string $file, - string $md5sum, - string $downloadScript, - ): void { + protected function downloadFileWithScript(string $file, string $md5sum, string $downloadScript): void + { echo PHP_EOL; echo $downloadScript; echo PHP_EOL; @@ -565,8 +568,16 @@ public function addLibrary(Library $lib): void if (empty($lib->license)) { throw new Exception("require license"); } - if (!empty($lib->preInstallCommand)) { - $this->preInstallCommands[] = $lib->preInstallCommand; + + if (!empty($lib->preInstallCommands)) { + foreach (['alpine', 'debian', 'ubuntu', 'macos'] as $os) { + if (!empty($lib->preInstallCommands[$os])) { + $this->preInstallCommands[$os] = array_merge( + $this->preInstallCommands[$os], + $lib->preInstallCommands[$os] + ); + } + } } $this->libraryList[] = $lib; @@ -671,7 +682,9 @@ public function addExtension(Extension $ext): void $this->mkdirIfNotExists($dst_dir, 0777, true); $cached = $dst_dir . '/.completed'; if (file_exists($cached) && $ext->enableBuildLibraryCached) { - echo 'ext/' . $ext_name . ' cached '; + if (in_array($this->buildType, ['dev', 'debug'])) { + echo '[ext/' . $ext_name . '] cached ' . PHP_EOL; + } } else { echo `tar --strip-components=1 -C $dst_dir -xf {$ext->path}`; if ($ext->enableBuildLibraryCached) { @@ -724,9 +737,11 @@ public function withExportVariable(string $key, string $value): static return $this; } - public function withPreInstallCommand(string $preInstallCommand): static + public function withPreInstallCommand(string $os, string $preInstallCommand): static { - $this->preInstallCommands[] = $preInstallCommand; + if (!empty($os) && in_array($os, ['alpine', 'debian', 'ubuntu', 'macos']) && !empty($preInstallCommand)) { + $this->preInstallCommands[$os][] = $preInstallCommand; + } return $this; } diff --git a/sapi/src/builder/library/dav1d.php b/sapi/src/builder/library/dav1d.php index a31b81248a..3a8cd066bf 100644 --- a/sapi/src/builder/library/dav1d.php +++ b/sapi/src/builder/library/dav1d.php @@ -5,23 +5,6 @@ return function (Preprocessor $p) { $dav1d_prefix = DAV1D_PREFIX; - $linux_pre_install=<<getOsType()=='macos' ? $macos_pre_install : $linux_pre_install; $p->addLibrary( (new Library('dav1d')) ->withHomePage('https://code.videolan.org/videolan/dav1d/') @@ -40,7 +23,27 @@ ->withBuildLibraryCached(true) ->withCleanBuildDirectory() ->withCleanPreInstallDirectory($dav1d_prefix) - ->withPreInstallCommand($pre_install) + ->withPreInstallCommand( + 'alpine', + <<withPreInstallCommand( + 'macos', + <<withBuildScript( <<withManual('https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Build-Guide.md') ->withPrefix($svt_av1_prefix) ->withPreInstallCommand( + 'alpine', <<withPreInstallCommand( + 'macos', + <<withBuildScript( diff --git a/sapi/src/template/make-install-deps.php b/sapi/src/template/make-install-deps.php index 4e47faf6cb..2f23634a3f 100644 --- a/sapi/src/template/make-install-deps.php +++ b/sapi/src/template/make-install-deps.php @@ -1,7 +1,56 @@ -echo " install deps " - -__CURRENT_DIR__=$(cd "$(dirname "$0")";pwd) +#!/usr/bin/env bash buildType, ['dev','debug'])) : ?> -set -x + set -x -preInstallCommands) .PHP_EOL ?> + +__CURRENT_DIR__=$(cd "$(dirname "$0")";pwd) + +echo " install deps " + +osType == 'macos') : ?> + preInstallCommands['macos'] as $item) :?> + + + + +osType == 'linux') : ?> +OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release |tr -d '\n' | tr -d '\"') + + + +function os_alpine_release() { + echo "${OS_RELEASE}" + preInstallCommands['alpine'] as $item) :?> + + + return 0 +} + +function os_debian_release() { + echo "${OS_RELEASE}" + preInstallCommands['debian'] as $item) :?> + + + return 0 +} + +function os_ubuntu_release() { + echo "${OS_RELEASE}" + preInstallCommands['ubuntu'] as $item) :?> + + + return 0 +} + + +if [ "$OS_RELEASE" = 'alpine' ]; then + os_alpine_release +elif [ "$OS_RELEASE" = 'debian' ]; then + os_debian_release +elif [ "$OS_RELEASE" = 'ubuntu' ]; then + os_ubuntu_release +else + echo 'no support OS' +fi + +