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