Skip to content

Commit bed5b9d

Browse files
authored
Merge pull request #751 from crazywhalecc/shell-improvement
Extract default build env to unix shell
2 parents 104038b + 13540c8 commit bed5b9d

33 files changed

+186
-202
lines changed

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ docker/extensions/
55
docker/source/
66

77
# Vendor files
8-
/vendor/
8+
/vendor/**
99

1010
# default source extract directory
11-
/source/
11+
/source/**
1212

1313
# default source download directory
14-
/downloads/
14+
/downloads/**
1515

1616
# default source build root directory
17-
/buildroot/
17+
/buildroot/**
1818

1919
# default package root directory
20-
/pkgroot/
20+
/pkgroot/**
2121

2222
# default pack:lib and release directory
23-
/dist/
23+
/dist/**
2424
packlib_files.txt
2525

2626
# tools cache files

src/SPC/builder/Extension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ public function buildUnixShared(): void
301301
// prepare configure args
302302
shell()->cd($this->source_dir)
303303
->setEnv($env)
304-
->execWithEnv(BUILD_BIN_PATH . '/phpize')
305-
->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static')
306-
->execWithEnv('make clean')
307-
->execWithEnv('make -j' . $this->builder->concurrency);
304+
->exec(BUILD_BIN_PATH . '/phpize')
305+
->exec('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static')
306+
->exec('make clean')
307+
->exec('make -j' . $this->builder->concurrency);
308308

309309
// copy shared library
310310
copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so');

src/SPC/builder/linux/library/libffi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function build(): void
2121
$arch = getenv('SPC_ARCH');
2222

2323
shell()->cd($this->source_dir)
24-
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
25-
->execWithEnv(
24+
->initializeEnv($this)
25+
->exec(
2626
'./configure ' .
2727
'--enable-static ' .
2828
'--disable-shared ' .
@@ -31,9 +31,9 @@ public function build(): void
3131
'--prefix= ' .
3232
"--libdir={$lib}"
3333
)
34-
->execWithEnv('make clean')
35-
->execWithEnv("make -j{$this->builder->concurrency}")
36-
->execWithEnv("make install DESTDIR={$destdir}");
34+
->exec('make clean')
35+
->exec("make -j{$this->builder->concurrency}")
36+
->exec("make install DESTDIR={$destdir}");
3737

3838
if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) {
3939
copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a');

src/SPC/builder/linux/library/libpng.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,10 @@ public function build(): void
4141
'aarch64' => '--enable-arm-neon ',
4242
default => '',
4343
};
44-
shell()->cd($this->source_dir)
44+
shell()->cd($this->source_dir)->initializeEnv($this)
4545
->exec('chmod +x ./configure')
4646
->exec('chmod +x ./install-sh')
47-
->setEnv([
48-
'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags),
49-
'LDFLAGS' => $this->getLibExtraLdFlags(),
50-
'LIBS' => $this->getLibExtraLibs(),
51-
])
52-
->execWithEnv(
47+
->exec(
5348
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
5449
'./configure ' .
5550
'--disable-shared ' .
@@ -59,9 +54,9 @@ public function build(): void
5954
$optimizations .
6055
'--prefix='
6156
)
62-
->execWithEnv('make clean')
63-
->execWithEnv("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
64-
->execWithEnv('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
57+
->exec('make clean')
58+
->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
59+
->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
6560
$this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX);
6661
$this->cleanLaFiles();
6762
}

src/SPC/builder/linux/library/openssl.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ public function build(): void
6464

6565
$clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : '';
6666

67-
shell()->cd($this->source_dir)
68-
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
69-
->execWithEnv(
67+
shell()->cd($this->source_dir)->initializeEnv($this)
68+
->exec(
7069
"{$env} ./Configure no-shared {$extra} " .
7170
'--prefix=/ ' .
7271
'--libdir=lib ' .
@@ -76,7 +75,7 @@ public function build(): void
7675
"linux-{$arch}{$clang_postfix}"
7776
)
7877
->exec('make clean')
79-
->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
78+
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
8079
->exec("make install_sw DESTDIR={$destdir}");
8180
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
8281
// patch for openssl 3.3.0+

src/SPC/builder/macos/library/openssl.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ protected function build(): void
4949
}
5050
$arch = getenv('SPC_ARCH');
5151

52-
shell()->cd($this->source_dir)
53-
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
52+
shell()->cd($this->source_dir)->initializeEnv($this)
5453
->exec(
5554
"./Configure no-shared {$extra} " .
5655
'--prefix=/ ' . // use prefix=/
@@ -59,7 +58,7 @@ protected function build(): void
5958
"darwin64-{$arch}-cc"
6059
)
6160
->exec('make clean')
62-
->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
61+
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
6362
->exec("make install_sw DESTDIR={$destdir}");
6463
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
6564
// patch for openssl 3.3.0+

src/SPC/builder/traits/UnixLibraryTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,13 @@ public function getLibExtraLibs(): string
118118
{
119119
return getenv($this->getSnakeCaseName() . '_LIBS') ?: '';
120120
}
121+
122+
public function getLibExtraCXXFlags(): string
123+
{
124+
$env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: '';
125+
if (!str_contains($env, $this->builder->arch_cxx_flags)) {
126+
$env .= $this->builder->arch_cxx_flags;
127+
}
128+
return $env;
129+
}
121130
}

src/SPC/builder/unix/library/attr.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ trait attr
1313
*/
1414
protected function build(): void
1515
{
16-
shell()->cd($this->source_dir)
17-
->setEnv([
18-
'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()),
19-
'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()),
20-
'LIBS' => $this->getLibExtraLibs(),
21-
])
22-
->execWithEnv('libtoolize --force --copy')
23-
->execWithEnv('./autogen.sh || autoreconf -if')
24-
->execWithEnv('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls')
25-
->execWithEnv("make -j {$this->builder->concurrency}")
16+
shell()->cd($this->source_dir)->initializeEnv($this)
17+
->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"])
18+
->exec('libtoolize --force --copy')
19+
->exec('./autogen.sh || autoreconf -if')
20+
->exec('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls')
21+
->exec("make -j {$this->builder->concurrency}")
2622
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
2723

2824
$this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX);

src/SPC/builder/unix/library/brotli.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected function build(): void
1919
{
2020
UnixCMakeExecutor::create($this)
2121
->setBuildDir("{$this->getSourceDir()}/build-dir")
22+
->addConfigureArgs("-DSHARE_INSTALL_PREFIX={$this->getBuildRootPath()}")
2223
->build();
2324

2425
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);

src/SPC/builder/unix/library/bzip2.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ public function patchBeforeBuild(): bool
1616

1717
protected function build(): void
1818
{
19-
shell()->cd($this->source_dir)
20-
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
21-
->execWithEnv("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
22-
->execWithEnv("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
19+
shell()->cd($this->source_dir)->initializeEnv($this)
20+
->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
21+
->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
2322
->exec('cp libbz2.a ' . BUILD_LIB_PATH)
2423
->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH);
2524
}

0 commit comments

Comments
 (0)