|
1 | 1 | #!/usr/bin/env bun
|
2 | 2 | import { execSync } from 'node:child_process'
|
3 |
| -import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs' |
| 3 | +import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync, chmodSync } from 'node:fs' |
4 | 4 | import path, { join } from 'node:path'
|
5 | 5 | import process from 'node:process'
|
6 | 6 |
|
@@ -2282,12 +2282,82 @@ exec ./configure "$@"
|
2282 | 2282 | }
|
2283 | 2283 |
|
2284 | 2284 | try {
|
| 2285 | + // First, ensure the install directory structure exists |
| 2286 | + mkdirSync(join(installPrefix, 'bin'), { recursive: true }) |
| 2287 | + mkdirSync(join(installPrefix, 'lib'), { recursive: true }) |
| 2288 | + mkdirSync(join(installPrefix, 'share'), { recursive: true }) |
| 2289 | + mkdirSync(join(installPrefix, 'sbin'), { recursive: true }) |
| 2290 | + |
| 2291 | + // Use DESTDIR to ensure make install targets the correct location |
| 2292 | + // This forces PHP's build system to install to the correct prefix |
2285 | 2293 | execSync('make install', {
|
2286 | 2294 | stdio: 'inherit',
|
2287 | 2295 | cwd: phpSourceDir,
|
2288 |
| - env: installEnv, |
| 2296 | + env: { |
| 2297 | + ...installEnv, |
| 2298 | + DESTDIR: '', // Ensure DESTDIR is empty so prefix is used directly |
| 2299 | + INSTALL_ROOT: '' // Also ensure INSTALL_ROOT doesn't interfere |
| 2300 | + }, |
2289 | 2301 | timeout: 15 * 60 * 1000, // 15 minutes timeout for install
|
2290 | 2302 | })
|
| 2303 | + |
| 2304 | + // Fallback: if make install didn't create the binary, manually copy it |
| 2305 | + const phpBinaryPath = join(installPrefix, 'bin', 'php') |
| 2306 | + const buildTimePhpBinary = join(phpSourceDir, 'sapi', 'cli', 'php') |
| 2307 | + |
| 2308 | + if (!existsSync(phpBinaryPath) && existsSync(buildTimePhpBinary)) { |
| 2309 | + log('🔧 ⚠️ make install did not create PHP binary, manually copying...') |
| 2310 | + |
| 2311 | + // Copy the main PHP binary |
| 2312 | + copyFileSync(buildTimePhpBinary, phpBinaryPath) |
| 2313 | + chmodSync(phpBinaryPath, '755') // Make executable |
| 2314 | + log(`🔧 ✅ Manually copied PHP binary from ${buildTimePhpBinary} to ${phpBinaryPath}`) |
| 2315 | + |
| 2316 | + // Also copy other important binaries if they exist and weren't installed |
| 2317 | + const otherBinaries = ['php-cgi', 'php-config', 'phpize', 'pear', 'pecl'] |
| 2318 | + for (const binary of otherBinaries) { |
| 2319 | + const sourceBinary = join(phpSourceDir, 'sapi', 'cgi', binary) // Try CGI first |
| 2320 | + const altSourceBinary = join(phpSourceDir, 'scripts', binary) // Try scripts dir |
| 2321 | + const altSource2Binary = join(phpSourceDir, binary) // Try root |
| 2322 | + const targetBinary = join(installPrefix, 'bin', binary) |
| 2323 | + |
| 2324 | + if (!existsSync(targetBinary)) { |
| 2325 | + if (existsSync(sourceBinary)) { |
| 2326 | + copyFileSync(sourceBinary, targetBinary) |
| 2327 | + chmodSync(targetBinary, '755') |
| 2328 | + log(`🔧 ✅ Manually copied ${binary}`) |
| 2329 | + } else if (existsSync(altSourceBinary)) { |
| 2330 | + copyFileSync(altSourceBinary, targetBinary) |
| 2331 | + chmodSync(targetBinary, '755') |
| 2332 | + log(`🔧 ✅ Manually copied ${binary} from scripts`) |
| 2333 | + } else if (existsSync(altSource2Binary)) { |
| 2334 | + copyFileSync(altSource2Binary, targetBinary) |
| 2335 | + chmodSync(targetBinary, '755') |
| 2336 | + log(`🔧 ✅ Manually copied ${binary} from root`) |
| 2337 | + } |
| 2338 | + } |
| 2339 | + } |
| 2340 | + |
| 2341 | + // Copy CGI binary specifically |
| 2342 | + const cgiBinarySource = join(phpSourceDir, 'sapi', 'cgi', 'php-cgi') |
| 2343 | + const cgiBinaryTarget = join(installPrefix, 'bin', 'php-cgi') |
| 2344 | + if (!existsSync(cgiBinaryTarget) && existsSync(cgiBinarySource)) { |
| 2345 | + copyFileSync(cgiBinarySource, cgiBinaryTarget) |
| 2346 | + chmodSync(cgiBinaryTarget, '755') |
| 2347 | + log(`🔧 ✅ Manually copied php-cgi binary`) |
| 2348 | + } |
| 2349 | + |
| 2350 | + // Copy FPM binary specifically |
| 2351 | + const fpmBinarySource = join(phpSourceDir, 'sapi', 'fpm', 'php-fpm') |
| 2352 | + const fpmBinaryTarget = join(installPrefix, 'sbin', 'php-fpm') |
| 2353 | + if (!existsSync(fpmBinaryTarget) && existsSync(fpmBinarySource)) { |
| 2354 | + mkdirSync(join(installPrefix, 'sbin'), { recursive: true }) |
| 2355 | + copyFileSync(fpmBinarySource, fpmBinaryTarget) |
| 2356 | + chmodSync(fpmBinaryTarget, '755') |
| 2357 | + log(`🔧 ✅ Manually copied php-fpm binary`) |
| 2358 | + } |
| 2359 | + } |
| 2360 | + |
2291 | 2361 | } catch (error) {
|
2292 | 2362 | if (config.platform === 'darwin') {
|
2293 | 2363 | log('🔧 ❌ Installation failed, checking build-time PHP binary again...')
|
|
0 commit comments