1
1
/* eslint-disable no-console */
2
2
import fs from 'node:fs'
3
3
import path from 'node:path'
4
+ import process from 'node:process'
4
5
import { config } from './config'
5
6
6
7
/**
637
638
// Set up library paths
638
639
if ( libraryPaths . length > 0 ) {
639
640
const libraryPathString = libraryPaths . join ( ':' )
641
+ const isDarwin = process . platform === 'darwin'
640
642
scriptContent += `# Set up library paths for dynamic linking
641
- export LD_LIBRARY_PATH="${ libraryPathString } ${ process . platform === 'darwin' ? ':$LD_LIBRARY_PATH' : '' } "
642
- export DYLD_LIBRARY_PATH="${ libraryPathString } ${ process . platform === 'darwin' ? ':$DYLD_LIBRARY_PATH' : '' } "
643
+ export LD_LIBRARY_PATH="${ libraryPathString } ${ isDarwin ? ':$LD_LIBRARY_PATH' : '' } "
644
+ export DYLD_LIBRARY_PATH="${ libraryPathString } ${ isDarwin ? ':$DYLD_LIBRARY_PATH' : '' } "
643
645
export DYLD_FALLBACK_LIBRARY_PATH="${ libraryPathString } :/usr/local/lib:/lib:/usr/lib"
644
646
645
647
`
@@ -648,24 +650,54 @@ export DYLD_FALLBACK_LIBRARY_PATH="${libraryPathString}:/usr/local/lib:/lib:/usr
648
650
// Set up pkg-config paths
649
651
if ( pkgConfigPaths . length > 0 ) {
650
652
const pkgConfigPathString = pkgConfigPaths . join ( ':' )
653
+ const existingPkgConfig = process . env . PKG_CONFIG_PATH || ''
654
+ const pkgConfigPath = existingPkgConfig ? `${ pkgConfigPathString } :${ existingPkgConfig } ` : pkgConfigPathString
651
655
scriptContent += `# Set up pkg-config to find launchpad-installed libraries
652
- export PKG_CONFIG_PATH="${ pkgConfigPathString } ${ process . env . PKG_CONFIG_PATH ? ':' + process . env . PKG_CONFIG_PATH : '' } "
656
+ export PKG_CONFIG_PATH="${ pkgConfigPath } "
653
657
654
658
`
655
659
}
656
660
657
661
// Set up include and library paths for compilation
658
662
if ( includePaths . length > 0 || libraryPaths . length > 0 ) {
663
+ const existingCppflags = process . env . CPPFLAGS || ''
664
+ const existingLdflags = process . env . LDFLAGS || ''
665
+ const cppflags = existingCppflags ? `-I${ includePaths . join ( ' -I' ) } ${ existingCppflags } ` : `-I${ includePaths . join ( ' -I' ) } `
666
+ const ldflags = existingLdflags ? `-L${ libraryPaths . join ( ' -L' ) } ${ existingLdflags } ` : `-L${ libraryPaths . join ( ' -L' ) } `
659
667
scriptContent += `# Set up include paths for compilation
660
- export CPPFLAGS="-I ${ includePaths . join ( ' -I' ) } ${ process . env . CPPFLAGS ? ' ' + process . env . CPPFLAGS : '' } "
668
+ export CPPFLAGS="${ cppflags } "
661
669
662
670
# Set up library paths for linking
663
- export LDFLAGS="-L ${ libraryPaths . join ( ' -L' ) } ${ process . env . LDFLAGS ? ' ' + process . env . LDFLAGS : '' } "
671
+ export LDFLAGS="${ ldflags } "
664
672
665
673
`
666
674
}
667
675
668
- scriptContent += `# Print environment info
676
+ scriptContent += `# Create pkg-config symlinks for common naming mismatches
677
+ # This handles cases where build scripts expect different package names
678
+ for pkg_dir in "$PKG_CONFIG_PATH"; do
679
+ IFS=':' read -ra PKG_DIRS <<< "$pkg_dir"
680
+ for dir in "\${PKG_DIRS[@]}"; do
681
+ if [ -d "$dir" ]; then
682
+ # libpng16 -> libpng
683
+ if [ -f "$dir/libpng16.pc" ] && [ ! -f "$dir/libpng.pc" ]; then
684
+ ln -sf libpng16.pc "$dir/libpng.pc"
685
+ fi
686
+
687
+ # libturbojpeg -> libjpeg
688
+ if [ -f "$dir/libturbojpeg.pc" ] && [ ! -f "$dir/libjpeg.pc" ]; then
689
+ ln -sf libturbojpeg.pc "$dir/libjpeg.pc"
690
+ fi
691
+
692
+ # openssl -> libssl
693
+ if [ -f "$dir/openssl.pc" ] && [ ! -f "$dir/libssl.pc" ]; then
694
+ ln -sf openssl.pc "$dir/libssl.pc"
695
+ fi
696
+ fi
697
+ done
698
+ done
699
+
700
+ # Print environment info
669
701
echo "Launchpad build environment activated:"
670
702
echo " PATH: $PATH"
671
703
echo " LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
@@ -681,3 +713,46 @@ echo " LDFLAGS: $LDFLAGS"
681
713
console . warn ( `Created build environment script: ${ scriptPath } ` )
682
714
}
683
715
}
716
+
717
+ /**
718
+ * Create pkg-config symlinks for common naming mismatches
719
+ * This handles cases where build scripts expect different package names than what's installed
720
+ */
721
+ export async function createPkgConfigSymlinks ( packageDir : string , domain : string ) : Promise < void > {
722
+ const pkgConfigDir = path . join ( packageDir , 'lib' , 'pkgconfig' )
723
+ if ( ! fs . existsSync ( pkgConfigDir ) )
724
+ return
725
+
726
+ const pkgConfigSymlinks : Record < string , Array < { target : string , link : string } > > = {
727
+ 'libpng.org' : [
728
+ { target : 'libpng16.pc' , link : 'libpng.pc' } ,
729
+ ] ,
730
+ 'libjpeg-turbo.org' : [
731
+ { target : 'libturbojpeg.pc' , link : 'libjpeg.pc' } ,
732
+ ] ,
733
+ 'openssl.org' : [
734
+ { target : 'openssl.pc' , link : 'libssl.pc' } ,
735
+ ] ,
736
+ }
737
+
738
+ const symlinks = pkgConfigSymlinks [ domain ] || [ ]
739
+
740
+ for ( const { target, link } of symlinks ) {
741
+ const targetPath = path . join ( pkgConfigDir , target )
742
+ const linkPath = path . join ( pkgConfigDir , link )
743
+
744
+ if ( fs . existsSync ( targetPath ) && ! fs . existsSync ( linkPath ) ) {
745
+ try {
746
+ await fs . promises . symlink ( target , linkPath )
747
+ if ( config . verbose ) {
748
+ console . warn ( `Created pkg-config symlink: ${ link } -> ${ target } ` )
749
+ }
750
+ }
751
+ catch ( error ) {
752
+ if ( config . verbose ) {
753
+ console . warn ( `Failed to create pkg-config symlink ${ link } -> ${ target } :` , error )
754
+ }
755
+ }
756
+ }
757
+ }
758
+ }
0 commit comments