1N/A#
1N/A# CDDL HEADER START
1N/A#
1N/A# The contents of this file are subject to the terms of the
1N/A# Common Development and Distribution License (the "License").
1N/A# You may not use this file except in compliance with the License.
1N/A#
1N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# When distributing Covered Code, include this CDDL HEADER in each
1N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A# If applicable, add the following below this CDDL HEADER, with the
1N/A# fields enclosed by brackets "[]" replaced with your own identifying
1N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A
1N/A#
1N/A# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
1N/A#
1N/A
1N/A#
1N/A# MM_Solaris_ON.pm overrides various parts of MakeMaker so that perl modules
1N/A# build correctly as part of Solaris/ON. The changes are:
1N/A# 1. parse_args is overriden to merge the values of DEFINE specified in
1N/A# Makefile.PL and on the command line. The default behaviour is that
1N/A# the command line value overwrites any value specified in Makefile.PL.
1N/A# 2. constants() is overriden to add the include paths specified in the
1N/A# ENVCPPFLAGS[1-n] environment variables to the compiler command-line so
1N/A# that the compiler looks in the proto area for include files.
1N/A# 3. ext() is overriden to add the library paths specified in the
1N/A# ENVLDLIBS[1-n] and STUBENVLDLIBS[1-n] environment variables to
1N/A# the linker command-line so that the linker looks in the proto area
1N/A# for libraries.
1N/A#
1N/A
1N/A# Plug into Makemaker - see ExtUtils::MM_*.pm
1N/Apackage ExtUtils::MM_Solaris_ON;
1N/Ause strict;
1N/Ause warnings;
1N/Aour ($VERSION, @ISA);
1N/A$VERSION = '1.3';
1N/Arequire ExtUtils::MM_Any;
1N/Arequire ExtUtils::MM_Unix;
1N/A@ISA = qw(ExtUtils::MM_Any ExtUtils::MM_Unix);
1N/Ause ExtUtils::MakeMaker qw(&neatvalue);
1N/A
1N/A#
1N/A# The default MakeMaker parse_args function overwrites DEFINE values passed
1N/A# to WriteMakefile with the values specified on the command line, which is
1N/A# obviously broken. This overrides the default implementation and merges the
1N/A# WriteMakefile and command line versions. See ExtUtils::MakeMaker.pm for
1N/A# details of the parse_args() method. Because parse_args isn't an overrideable
1N/A# MakeMaker method, we have to pull some dirty tricks with the MakeMaker stash
1N/A# to make this work.
1N/A#
1N/Aour $real_parse_args;
1N/ABEGIN {
1N/A $real_parse_args = *ExtUtils::MakeMaker::parse_args{CODE};
1N/A no warnings qw(redefine);
1N/A *ExtUtils::MakeMaker::parse_args = \&parse_args;
1N/A}
1N/Asub parse_args
1N/A{
1N/A my ($self, @args) = @_;
1N/A
1N/A my $define = exists($self->{DEFINE}) ? $self->{DEFINE} : undef;
1N/A $self->$real_parse_args(@args);
1N/A $self->{DEFINE} = "$define $self->{DEFINE}"
1N/A if (defined($define) && exists($self->{DEFINE}));
1N/A}
1N/A
1N/A#
1N/A# The constants() method works out the compiler flags needed to build a module.
1N/A# Override it to take into account the current settings of the ENVCPPFLAGS[1-n]
1N/A# environment variables when building as part of Solaris/ON. See
1N/A# ExtUtils::MM_Unix for details of the constants() method.
1N/A#
1N/Asub constants
1N/A{
1N/A my ($self) = @_;
1N/A
1N/A # Find all the ENVCPPFLAGS[1-n] environment variables
1N/A my (%inc_seen, @newincs, %proto_seen, @protos);
1N/A
1N/A # Prepopulate @protos with $ENV{ROOT} if it is set
1N/A if (defined ($ENV{ROOT})) {
1N/A push(@protos, $ENV{ROOT});
1N/A }
1N/A
1N/A foreach my $ip (map({ /^ENVCPPFLAGS\d+$/ ? split(' ', $ENV{$_}) : () }
1N/A sort(keys(%ENV)))) {
1N/A # Ignore everything except '-I' flags.
1N/A next unless ($ip =~ s!^-I(.*)$!$1!);
1N/A
1N/A # Add to newincs if not seen before.
1N/A push(@newincs, "-I$ip") unless ($inc_seen{$ip}++);
1N/A
1N/A #
1N/A # If the path points to somewhere under a proto area,
1N/A # figure out the top of the proto area & save for later.
1N/A #
1N/A next unless ($ip =~ s!^(.*/proto/root_[^/]+)/.*$!$1!);
1N/A push(@protos, $ip) unless ($proto_seen{$ip}++);
1N/A }
1N/A
1N/A # Search INC string, prepending the proto areas to any absolute paths.
1N/A foreach (split(' ', exists($self->{INC}) ? $self->{INC} : '')) {
1N/A # Deal with -I flags
1N/A if (my ($p) = $_ =~ /^-I(.*)$/) {
1N/A # Only prepend to absolute paths
1N/A if ($self->file_name_is_absolute($p)) {
1N/A foreach my $pp (@protos) {
1N/A my $ppp = "$pp$p";
1N/A push(@newincs, "-I$ppp")
1N/A unless ($inc_seen{$ppp}++);
1N/A }
1N/A # Pass relative paths through.
1N/A } else {
1N/A push(@newincs, "-I$p") unless ($inc_seen{$p}++);
1N/A }
1N/A
1N/A # Pass anything else through.
1N/A } else {
1N/A push(@newincs, $_);
1N/A }
1N/A }
1N/A
1N/A # Call the default Unix constants() method (see MM_Unix.pm)
1N/A $self->{INC} = join(' ', @newincs);
1N/A return ($self->ExtUtils::MM_Unix::constants());
1N/A}
1N/A
1N/A#
1N/A# The ext() method works out the linker flags required to build a module.
1N/A# Override it to take into account the current settings of the ENVLDLIBS[1-n]
1N/A# and STUBENVLDLIBS[1-n] environment variables when building as part of
1N/A# Solaris/ON. Also remove the LD_RUN_PATH that is returned by the default
1N/A# implementation, as it is not correct when building as part of Solaris/ON.
1N/A# See ExtUtils::Liblist for details of the ext() method.
1N/A#
1N/Asub ext
1N/A{
1N/A my ($self, $libs, $verbose, $need_names) = @_;
1N/A
1N/A # Find all the STUBENVLDLIBS[1-n] and ENVLDLIBS[1-n] environment
1N/A # variables. The stubs must be used before the non-stubs, so use
1N/A # two passes
1N/A my (%lib_seen, @lib_prefix, @newlibs, %proto_seen, @protos);
1N/A foreach my $lp (map({ /^STUBENVLDLIBS\d+$/ ? split(' ', $ENV{$_}) : () }
1N/A sort(keys(%ENV)))) {
1N/A # Ignore everything except '-L' flags
1N/A next unless ($lp =~ s!^-L(.*)$!$1!);
1N/A
1N/A # Add to lib_prefix if not seen before
1N/A push(@lib_prefix, "-L$lp") unless ($lib_seen{$lp}++);
1N/A
1N/A #
1N/A # If the path points to somewhere under a proto area,
1N/A # figure out the top of the proto area & save for later
1N/A #
1N/A next unless ($lp =~ s!^(.*/proto/root_[^/]+)/.*$!$1!);
1N/A push(@protos, $lp) unless ($proto_seen{$lp}++);
1N/A }
1N/A foreach my $lp (map({ /^ENVLDLIBS\d+$/ ? split(' ', $ENV{$_}) : () }
1N/A sort(keys(%ENV)))) {
1N/A # Ignore everything except '-L' flags
1N/A next unless ($lp =~ s!^-L(.*)$!$1!);
1N/A
1N/A # Add to lib_prefix if not seen before
1N/A push(@lib_prefix, "-L$lp") unless ($lib_seen{$lp}++);
1N/A
1N/A #
1N/A # If the path points to somewhere under a proto area,
1N/A # figure out the top of the proto area & save for later
1N/A #
1N/A next unless ($lp =~ s!^(.*/proto/root_[^/]+)/.*$!$1!);
1N/A push(@protos, $lp) unless ($proto_seen{$lp}++);
1N/A }
1N/A
1N/A # Search libs string, prepending the proto areas to any absolute paths
1N/A %lib_seen = ();
1N/A foreach (split(' ', $libs)) {
1N/A # Deal with -L flags
1N/A if (my ($p) = $_ =~ /^-L(.*)$/) {
1N/A # Only prepend to absolute paths
1N/A if ($self->file_name_is_absolute($p)) {
1N/A foreach my $pp (@protos) {
1N/A my $ppp = "$pp$p";
1N/A push(@newlibs, "-L$ppp")
1N/A unless ($lib_seen{$ppp}++);
1N/A }
1N/A # Pass relative paths through
1N/A } else {
1N/A push(@newlibs, "-L$p") unless ($lib_seen{$p}++);
1N/A }
1N/A
1N/A # Pass anything else through
1N/A } else {
1N/A push(@newlibs, $_);
1N/A }
1N/A }
1N/A
1N/A # Call the default Unix ext() method (see Liblist.pm)
1N/A require ExtUtils::Liblist;
1N/A my @retval = $self->ExtUtils::Liblist::Kid::ext(join(' ', @newlibs),
1N/A $verbose, $need_names);
1N/A
1N/A #
1N/A # Prepend any missing members of @lib_prefix onto LDLOADLIBS.
1N/A # Do this after calling ext() as ext() will strip out all the -L flags
1N/A # if passed an empty library list. Note we don't touch EXTRALIBS as
1N/A # it is only used to create the extralibs.ld file, and we don't want
1N/A # the ON environment leaking out into shipped files.
1N/A #
1N/A my $prefix = join(' ', grep({ ! $lib_seen{$_}++ } @lib_prefix));
1N/A $prefix .= ' ';
1N/A $retval[2] = $prefix . $retval[2]; # LDLOADLIBS
1N/A
1N/A # By default any directories containing libraries are returned as part
1N/A # LD_RUN_PATH. When building Solaris/ON, we don't want this behaviour
1N/A # as it results in the proto area being stored in RPATH in the resulting
1N/A # perl module.so files, so we null it out here.
1N/A #
1N/A $retval[3] = '';
1N/A return (@retval);
1N/A}
1N/A
1N/A1;