use 5.014002;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    NAME              => 'Link::Accounts::Remote',
    VERSION_FROM      => 'lib/Link/Accounts/Remote.pm', # finds $VERSION
    PREREQ_PM         => {}, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
      (ABSTRACT_FROM  => 'lib/Link/Accounts/Remote.pm', # retrieve abstract from module
       AUTHOR         => 'Olivier Thauvin <olivier.thauvin@latmos.ipsl.fr>') : ()),
    macro             => {
        DESTRPMDIR    => '$(shell pwd)'
    },
    EXE_FILES         => [ qw(
        bin/la-chpasswd        
    ) ]
);

package MY;

sub postamble {
    <<EOF;
#.PHONY .= svnmanifest

svnmanifest:
\tsvn ls -R| grep -v "/\$\$"  > MANIFEST

ChangeLog:
\tsvn log > ChangeLog

link-accounts-remote.spec: link-accounts-remote.spec.in Makefile
\tsed -e 's/\@VERSION@/\$(VERSION)/' < \$< > \$@

rpm: \$(DISTVNAME).tar.gz link-accounts-remote.spec
\tmkdir ./noarch || :
\trpmbuild -ba --clean\\
\t --define "_sourcedir `pwd`" \\
\t --define "_specdir `pwd`" \\
\t --define "_srcrpmdir \$(DESTRPMDIR)" \\
\t --define "_rpmdir \$(DESTRPMDIR)" \\
\t link-accounts-remote.spec

svnrpm: \$(DISTVNAME).tar.gz link-accounts-remote.spec
\tmkdir \$(DESTRPMDIR)/noarch || :
\trpmbuild -ba --clean\\
\t --define "_sourcedir `pwd`" \\
\t --define "_specdir `pwd`" \\
\t --define "_srcrpmdir \$(DESTRPMDIR)" \\
\t --define "_rpmdir \$(DESTRPMDIR)" \\
\t --define "svnrelease `LC_ALL=C svn info | grep '^Revision:' | sed 's/Revision: //'`" \\
\t link-accounts-remote.spec

EOF
}

sub installbin {
    my $self = shift;
    my $inherited = $self->SUPER::installbin(@_);
    # how to create needed directories under blib
    #$inherited .= $self->dir_target("\$(INST_$_)") for qw(MAN5DIR);
    $inherited;
}

sub top_targets {
    my $inherited = shift->SUPER::top_targets(@_);
    #$inherited =~ s/^config ::/$& \$(INST_MAN5DIR)\$(DIRFILESEP).exists/m;
    $inherited;
}

sub install {
    my ($self) = @_;
    my $section = $self->SUPER::install();

    $section =~ s/(^install ::.*)/$1 install_config/m;
    $section =~ s/\$\(INST_BIN\) \$\(DESTINSTALL(\w*)BIN\)/$& \$(INST_MAN5DIR) \$(DESTINSTALLMAN5DIR)/g;

    $section .= q[

install_config ::
	install -d $(DESTDIR)/etc

];
  
    return $section;
}
