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 use Config;
31
32 #
33 # Compare OS versions.
34 #
35 sub cmp_os_ver
36 {
37 our ($a, $b);
38 my @v1 = split(/\./, $a);
39 my @v2 = split(/\./, $b);
40 my $diff = 0;
41 while (@v1 || @v2) {
42 last if (($diff = shift(@v1) - shift(@v2)) != 0);
43 }
44 return ($diff);
45 }
46
47 # Check we are on a supported OS version.
48 my $rel = qx{uname -r}; chomp($rel);
49 my $arch = qx{uname -p}; chomp($arch);
50 my $pver = sprintf('%vd', $^V);
51
52 # Figure out the appropriate Config.pm. Use an older version if necessary.
53 my $perlarch = $Config{"archname"};
54
55 my $configpm = "/usr/perl5/$pver/lib/$perlarch/Config.pm";
56 if (! -f $configpm) {
57 my $p = "config/$pver";
58 my $dh;
59 opendir($dh, $p) || die("Can't read directory $_: $!\n");
60 my $old_rel = (sort(cmp_os_ver
61 grep(-d "$p/$_" && $_ =~ /^\d[\d.]+\d$/, readdir($dh))))[-1];
62 closedir($dh);
63 if (defined($old_rel)) {
64 print(STDERR "Warning: No config file for OS version $rel, " .
65 "using $old_rel file\n");
66 $rel = $old_rel;
67 $configpm = "config/$pver/$rel/$arch/Config.pm";
68 } else {
69 die("Unsupported version of Perl/OS/Architecture " .
70 "$pver/$rel/$arch\n");
71 }
72 } else {
73 open CONFIGPM, "<", $configpm or die $!;
74 open CONFIGPM_OUT, ">", "Config.pm" or die $!;
75 while(<CONFIGPM>) {
76 if (/'cc/) {
77 s/=>\s*'cc/=> 'gcc/;
78 s/=\s*'cc/='gcc/;
79 }
80 print CONFIGPM_OUT $_;
81 }
82 close CONFIGPM;
83 close CONFIGPM_OUT;
84 $configpm = "Config.pm";
85 }
86
87 WriteMakefile(
88 NAME => 'Sun::Solaris::PerlGcc',
89 VERSION_FROM => 'perlgcc.PL',
90 PM => { $configpm => '$(INST_LIBDIR)/PerlGcc/Config.pm' },
91 MAN1PODS => { },
92 MAN3PODS => { }, # Stop autopodification.
93 );