1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24 #
  25 
  26 require 5.8.4;
  27 use strict;
  28 use warnings;
  29 use ExtUtils::MakeMaker;
  30 
  31 #
  32 # Compare OS versions.
  33 #
  34 sub cmp_os_ver
  35 {
  36         our ($a, $b);
  37         my @v1 = split(/\./, $a);
  38         my @v2 = split(/\./, $b);
  39         my $diff = 0;
  40         while (@v1 || @v2) {
  41                 last if (($diff = shift(@v1) - shift(@v2)) != 0);
  42         }
  43         return ($diff);
  44 }
  45 
  46 # Check we are on a supported OS version.
  47 my $rel = qx{uname -r}; chomp($rel);
  48 my $arch = qx{uname -p}; chomp($arch);
  49 my $pver = sprintf('%vd', $^V);
  50 
  51 # Figure out the appropriate Config.pm.  Use an older version if necessary.
  52 my $perlarch = ($arch eq "sparc") ? "sun4-solaris-64int":"i86pc-solaris-64int";
  53 
  54 my $configpm = "/usr/perl5/$pver/lib/$perlarch/Config.pm";
  55 if (! -f $configpm) {
  56         my $p = "config/$pver";
  57         my $dh;
  58         opendir($dh, $p) || die("Can't read directory $_: $!\n");
  59         my $old_rel = (sort(cmp_os_ver
  60             grep(-d "$p/$_" && $_ =~ /^\d[\d.]+\d$/, readdir($dh))))[-1];
  61         closedir($dh);
  62         if (defined($old_rel)) {
  63                 print(STDERR "Warning: No config file for OS version $rel, " .
  64                     "using $old_rel file\n");
  65                 $rel = $old_rel;
  66                 $configpm = "config/$pver/$rel/$arch/Config.pm";
  67         } else {
  68                 die("Unsupported version of Perl/OS/Architecture " .
  69                     "$pver/$rel/$arch\n");
  70         }
  71 } else {
  72         open CONFIGPM, "<", $configpm or die $!;
  73         open CONFIGPM_OUT, ">", "Config.pm" or die $!;
  74         while(<CONFIGPM>) {
  75                 if (/'cc/) {
  76                         s/=>\s*'cc/=> 'gcc/;
  77                         s/=\s*'cc/='gcc/;
  78                 }
  79                 print CONFIGPM_OUT $_;
  80         }
  81         close CONFIGPM;
  82         close CONFIGPM_OUT;
  83         $configpm = "Config.pm";
  84 }
  85 
  86 our %man1pods;
  87 # Only install the pods for onn-ON builds.
  88 if (! exists($ENV{CODEMGR_WS}) && ! exists($ENV{ENVCPPFLAGS1})) {
  89         $man1pods{'pod/perlgcc.pod'} = '$(INST_MAN1DIR)/perlgcc.$(MAN1EXT)';
  90 }
  91 
  92 WriteMakefile(
  93     NAME         => 'Sun::Solaris::PerlGcc',
  94     VERSION_FROM => 'perlgcc.PL',
  95     PL_FILES     => { 'perlgcc.PL' => 'perlgcc' },
  96     EXE_FILES    => [ 'perlgcc' ],
  97     PM           => { $configpm => '$(INST_LIBDIR)/PerlGcc/Config.pm' },
  98     MAN1PODS     => \%man1pods,
  99     MAN3PODS     => { }, # Stop autopodification.
 100     clean        => { FILES => 'perlgcc' },
 101 );