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