Skip to content

Commit c8409fd

Browse files
committed
Fix library/plugin install locations
Install according to MakeMaker INSTALLDIRS setting: http://perldoc.perl.org/ExtUtils/MakeMaker.html#make-install
1 parent 71e4bec commit c8409fd

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

Makefile.PL

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ unless ( eval { ExtUtils::MakeMaker->VERSION(6.52) } ) {
499499

500500
# See lib/ExtUtils/MakeMaker.pm for details of how to
501501
# influence content of the Makefile that is written.
502-
WriteMakefile(%WriteMakefile);
502+
my $mm = WriteMakefile(%WriteMakefile);
503503

504504
################################################################################
505505
# extend EU::MM to compile additional LibSass tools
@@ -516,9 +516,22 @@ my @targets;
516516
my @cleanups;
517517
my @commands;
518518
my $static = 0;
519+
my $reported = 0;
520+
521+
# http://perldoc.perl.org/ExtUtils/MakeMaker.html#make-install
522+
sub inst_lib {
523+
my ($mm) = @_;
524+
warn "Installing as a ", $mm->{INSTALLDIRS}, " module\n"
525+
unless $reported; $reported = 1;
526+
return '$(INSTALLARCHLIB)' if $mm->{INSTALLDIRS} eq "perl";
527+
return '$(INSTALLSITEARCH)' if $mm->{INSTALLDIRS} eq "site";
528+
return '$(INSTALLVENDORLIB)' if $mm->{INSTALLDIRS} eq "vendor";
529+
die "invalid INSTALLDIRS setting, abort";
530+
}
531+
519532

520533
sub compile_lib {
521-
my ($name) = @_;
534+
my ($mm, $name) = @_;
522535
my @args = (
523536
'$(LD) $(OPTIMIZE) -lstdc++ -shared', "-o ${name}",
524537
);
@@ -534,7 +547,7 @@ sub compile_lib {
534547
# add explicit path to libsass lib
535548
# needed to resolve lib from plugins
536549
unless ($^O eq 'MSWin32' && $Config{cc} =~ /^cl/) {
537-
push @args, '-Wl,-rpath,$(INSTALLARCHLIB)';
550+
push @args, '-Wl,-rpath,' . inst_lib($mm);
538551
}
539552
# -static-libgcc -static-libstdc++
540553
return join(' ', @args, @libs);
@@ -560,7 +573,7 @@ sub libsass_sassc
560573
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass')
561574
. ' $(OPTIMIZE) -lstdc++ -std=c++0x ' . join(" ", @libs)
562575
. ($^O eq "linux" ? ' -ldl' : '')
563-
. ' -Wl,-rpath,$(INSTALLARCHLIB)';
576+
. ' -Wl,-rpath,' . inst_lib($_[0]);
564577
}
565578
# add target to virtual "pure_all"
566579
push @cleanups, '$(SASSC_OBJ)';
@@ -579,7 +592,7 @@ sub libsass_lib
579592
# create the target for the makefile
580593
push @ret, '$(LIBSASS_LIB): $(LIBSASS_OBJ)';
581594
# create the libsass shared library by linking against all objects
582-
push @ret, "\t" . compile_lib('$(LIBSASS_LIB)') . ' $(LIBSASS_OBJ)';
595+
push @ret, "\t" . compile_lib($_[0], '$(LIBSASS_LIB)') . ' $(LIBSASS_OBJ)';
583596
# add target to virtual "pure_all"
584597
push @cleanups, '$(LIBSASS_OBJ)';
585598
push @cleanups, '$(LIBSASS_LIB)';
@@ -598,7 +611,7 @@ sub libsass_plugin_math
598611
# make sure the plugin path exists for output
599612
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/math';
600613
# create the libsass shared library by linking against all objects
601-
push @ret, "\t" . compile_lib('$(MATH_LIB)') . ' $(MATH_OBJ)'
614+
push @ret, "\t" . compile_lib($_[0], '$(MATH_LIB)') . ' $(MATH_OBJ)'
602615
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
603616
# add target to virtual "pure_all"
604617
push @cleanups, '$(MATH_OBJ)';
@@ -618,7 +631,7 @@ sub libsass_plugin_img_size
618631
# make sure the plugin path exists for output
619632
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/img-size';
620633
# create the libsass shared library by linking against all objects
621-
push @ret, "\t" . compile_lib('$(IMG_SIZE_LIB)') . ' $(IMG_SIZE_OBJ)'
634+
push @ret, "\t" . compile_lib($_[0], '$(IMG_SIZE_LIB)') . ' $(IMG_SIZE_OBJ)'
622635
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
623636
# add target to virtual "pure_all"
624637
push @cleanups, '$(IMG_SIZE_OBJ)';
@@ -643,7 +656,7 @@ sub libsass_plugin_digest
643656
# make sure the plugin path exists for output
644657
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/digest';
645658
# create the libsass shared library by linking against all objects
646-
push @ret, "\t" . compile_lib('$(DIGEST_LIB)') . ' $(DIGEST_OBJ)'
659+
push @ret, "\t" . compile_lib($_[0], '$(DIGEST_LIB)') . ' $(DIGEST_OBJ)'
647660
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
648661
# add target to virtual "pure_all"
649662
push @cleanups, '$(DIGEST_OBJ)';
@@ -668,7 +681,7 @@ sub libsass_plugin_glob
668681
# make sure the plugin path exists for output
669682
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/glob';
670683
# create the libsass shared library by linking against all objects
671-
push @ret, "\t" . compile_lib('$(GLOB_LIB)') . ' $(GLOB_OBJ)'
684+
push @ret, "\t" . compile_lib($_[0], '$(GLOB_LIB)') . ' $(GLOB_OBJ)'
672685
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
673686
# add target to virtual "pure_all"
674687
push @cleanups, '$(GLOB_OBJ)';
@@ -683,22 +696,22 @@ sub runOnce
683696
{
684697
return if $ran;
685698
# get instance
686-
my $self = shift;
699+
my $mm = shift;
687700
# collect Makefile commands
688701
@commands = (
689702
# call parent class first
690-
$self->SUPER::postamble,
703+
$mm->SUPER::postamble,
691704
);
692705
if ($install_plugins || $install_sassc) {
693-
push @commands, '', libsass_lib();
706+
push @commands, '', libsass_lib($mm);
694707
}
695708
if ($install_sassc) {
696-
push @commands, '', libsass_sassc();
709+
push @commands, '', libsass_sassc($mm);
697710
}
698711
if ($install_plugins) {
699-
push @commands, '', libsass_plugin_glob();
700-
push @commands, '', libsass_plugin_math();
701-
push @commands, '', libsass_plugin_img_size();
712+
push @commands, '', libsass_plugin_glob($mm);
713+
push @commands, '', libsass_plugin_math($mm);
714+
push @commands, '', libsass_plugin_img_size($mm);
702715
# needs a few C-API changes not yet released
703716
# push @commands, '', libsass_plugin_digest();
704717
}
@@ -712,8 +725,8 @@ sub runOnce
712725
sub postamble
713726
{
714727
# get instance
715-
my $self = shift;
716-
runOnce($self);
728+
my $mm = shift;
729+
runOnce($mm);
717730
# return code for Makefile
718731
return join "\n", @commands;
719732
}
@@ -722,9 +735,9 @@ sub postamble
722735
sub clean
723736
{
724737
# get instance
725-
my $self = shift;
726-
runOnce($self);
738+
my $mm = shift;
739+
runOnce($mm);
727740
# collect parent clean targets
728-
return $self->SUPER::clean . "\t- \$(RM_F) \\\n"
741+
return $mm->SUPER::clean . "\t- \$(RM_F) \\\n"
729742
. join("\n", map { "\t $_ \\" } @cleanups);
730743
}

0 commit comments

Comments
 (0)