| 1 |
package platform::BASE; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Carp; |
| 6 |
|
| 7 |
# Assume someone set @INC right before loading this module |
| 8 |
use configdata; |
| 9 |
|
| 10 |
# Globally defined "platform specific" extensions, available for uniformity |
| 11 |
sub depext { '.d' } |
| 12 |
|
| 13 |
# Functions to convert internal file representations to platform specific |
| 14 |
# ones. Note that these all depend on extension functions that MUST be |
| 15 |
# defined per platform. |
| 16 |
# |
| 17 |
# Currently known internal or semi-internal extensions are: |
| 18 |
# |
| 19 |
# .a For libraries that are made static only. |
| 20 |
# Internal libraries only. |
| 21 |
# .o For object files. |
| 22 |
# .s, .S Assembler files. This is an actual extension on Unix |
| 23 |
# .res Resource file. This is an actual extension on Windows |
| 24 |
|
| 25 |
sub binname { return $_[1] } # Name of executable binary |
| 26 |
sub dsoname { return $_[1] } # Name of dynamic shared object (DSO) |
| 27 |
sub sharedname { return __isshared($_[1]) ? $_[1] : undef } # Name of shared lib |
| 28 |
sub staticname { return __base($_[1], '.a') } # Name of static lib |
| 29 |
|
| 30 |
# Convenience function to convert the shlib version to an acceptable part |
| 31 |
# of a file or directory name. By default, we consider it acceptable as is. |
| 32 |
sub shlib_version_as_filename { return $config{shlib_version} } |
| 33 |
|
| 34 |
# Convenience functions to convert the possible extension of an input file name |
| 35 |
sub bin { return $_[0]->binname($_[1]) . $_[0]->binext() } |
| 36 |
sub dso { return $_[0]->dsoname($_[1]) . $_[0]->dsoext() } |
| 37 |
sub sharedlib { return __concat($_[0]->sharedname($_[1]), $_[0]->shlibext()) } |
| 38 |
sub staticlib { return $_[0]->staticname($_[1]) . $_[0]->libext() } |
| 39 |
|
| 40 |
# More convenience functions for intermediary files |
| 41 |
sub def { return __base($_[1], '.ld') . $_[0]->defext() } |
| 42 |
sub obj { return __base($_[1], '.o') . $_[0]->objext() } |
| 43 |
sub res { return __base($_[1], '.res') . $_[0]->resext() } |
| 44 |
sub dep { return __base($_[1], '.o') . $_[0]->depext() } # <- objname |
| 45 |
sub asm { return __base($_[1], '.s') . $_[0]->asmext() } |
| 46 |
|
| 47 |
# Another set of convenience functions for standard checks of certain |
| 48 |
# internal extensions and conversion from internal to platform specific |
| 49 |
# extension. Note that the latter doesn't deal with libraries because |
| 50 |
# of ambivalence |
| 51 |
sub isdef { return $_[1] =~ m|\.ld$|; } |
| 52 |
sub isobj { return $_[1] =~ m|\.o$|; } |
| 53 |
sub isres { return $_[1] =~ m|\.res$|; } |
| 54 |
sub isasm { return $_[1] =~ m|\.s$|; } |
| 55 |
sub iscppasm { return $_[1] =~ m|\.S$|; } |
| 56 |
sub isstaticlib { return $_[1] =~ m|\.a$|; } |
| 57 |
sub convertext { |
| 58 |
if ($_[0]->isdef($_[1])) { return $_[0]->def($_[1]); } |
| 59 |
if ($_[0]->isobj($_[1])) { return $_[0]->obj($_[1]); } |
| 60 |
if ($_[0]->isres($_[1])) { return $_[0]->res($_[1]); } |
| 61 |
if ($_[0]->isasm($_[1])) { return $_[0]->asm($_[1]); } |
| 62 |
if ($_[0]->isstaticlib($_[1])) { return $_[0]->staticlib($_[1]); } |
| 63 |
return $_[1]; |
| 64 |
} |
| 65 |
|
| 66 |
# Helpers ############################################################ |
| 67 |
|
| 68 |
# __base EXPR, LIST |
| 69 |
# This returns the given path (EXPR) with the matching suffix from LIST stripped |
| 70 |
sub __base { |
| 71 |
my $path = shift; |
| 72 |
foreach (@_) { |
| 73 |
if ($path =~ m|\Q${_}\E$|) { |
| 74 |
return $`; |
| 75 |
} |
| 76 |
} |
| 77 |
return $path; |
| 78 |
} |
| 79 |
|
| 80 |
# __isshared EXPR |
| 81 |
# EXPR is supposed to be a library name. This will return true if that library |
| 82 |
# can be assumed to be a shared library, otherwise false |
| 83 |
sub __isshared { |
| 84 |
return !($disabled{shared} || $_[0] =~ /\.a$/); |
| 85 |
} |
| 86 |
|
| 87 |
# __concat LIST |
| 88 |
# Returns the concatenation of all elements of LIST if none of them is |
| 89 |
# undefined. If one of them is undefined, returns undef instead. |
| 90 |
sub __concat { |
| 91 |
my $result = ''; |
| 92 |
foreach (@_) { |
| 93 |
return undef unless defined $_; |
| 94 |
$result .= $_; |
| 95 |
} |
| 96 |
return $result; |
| 97 |
} |
| 98 |
|
| 99 |
1; |