| 1 | package Affix::Platform::Haiku v1.3.0 { | ||
| 2 | use v5.40; | ||
| 3 | use Path::Tiny qw[path]; | ||
| 4 | use Config qw[%Config]; | ||
| 5 | use parent 'Affix::Platform::Unix'; | ||
| 6 | use parent 'Exporter'; | ||
| 7 | our @EXPORT_OK = qw[find_library]; | ||
| 8 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | ||
| 9 | my $so = $Config{so} // 'so'; | ||
| 10 | |||
| 11 | # Haiku has no separate libm/libc: the C library and the math functions are both provided by | ||
| 12 | # libroot.so. Linker probes for `-lm`/`-lc` therefore fail, so resolve those names to libroot | ||
| 13 | # instead. | ||
| 14 | my %alias = ( m => 'root', c => 'root' ); | ||
| 15 | my @lib_dirs = qw[ | ||
| 16 | /boot/system/lib | ||
| 17 | /boot/system/develop/lib | ||
| 18 | /boot/system/non-packaged/lib | ||
| 19 | /boot/home/config/lib | ||
| 20 | ]; | ||
| 21 | |||
| 22 | sub find_library ( $name, $version //= () ) { | ||
| 23 | my $base = $name; | ||
| 24 | $base =~ s[^lib][]; | ||
| 25 | if ( my $target = $alias{$base} ) { | ||
| 26 | my $found = Affix::Platform::Unix::find_library( $target, $version ); | ||
| 27 | return $found if defined $found; | ||
| 28 | for my $dir ( grep {-d} @lib_dirs ) { | ||
| 29 | my @cand = grep {/\Alib\Q$target\E\.\Q$so\E/} map { path($_) } path($dir)->children; | ||
| 30 | for my $cand (@cand) { | ||
| 31 | return $cand->realpath->stringify if -e $cand; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | return Affix::Platform::Unix::find_library( $name, $version ); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | # | ||
| 39 | 1; |