* give sepia-pod-follow-link-at-point a keybinding, M-. l.
[sepia.git] / Makefile.PL
blob1f1278ede945f66e82f74602cbdddb96326da128
1 use warnings;
2 use strict;
4 use Pod::Usage;
5 use Getopt::Long;
7 use ExtUtils::MakeMaker qw(WriteMakefile prompt);
8 use 5.006;                      # for "no warnings" -- sorry!
9 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
10 # the contents of the Makefile that is written.
12 my %prereq = (
13     'Data::Dumper'    => 0,
14     'Scalar::Util'    => 0,
17 ## Poor man's optional deps.
18 sub test_for
20     my $mod = shift;
21     eval "require $mod";
22     if ($@) {
23         my $resp = prompt("@_.  Install $mod (y/n)? ", 'n');
24         $prereq{$mod} = 0 if $resp =~ /^y/i;
25     }
28 my $ELISP_FIND_SITELISP = <<'END_ELISP';
29 (dolist (x load-path) (princ x) (terpri))
30 END_ELISP
32 my $ELISP_FIND_INFODIR = <<'END_ELISP';
33 (progn
34  (require (quote info))
35  (princ (car Info-default-directory-list)))
36 END_ELISP
38 my ($EMACS, $SITE_LISP, $INSTALL_INFO, $INFO_DIR, $HELP);
40 sub escape_path
42     my ($path) = @_;
43     $path =~ s/([$?* ])/\\$1/g; # escape special characters
44     $path =~ s{/+$}{};          # remove trailing forward-slashes
45     return $path;
48 sub prompt_for_emacs
50     # try to compile and install Elisp files, but don't die if we can't.
51     my ($sysemacs) = grep { defined && -x }
52         $ENV{EMACS}, glob '/usr/bin{/local,}/emacs';
53     $sysemacs ||= q{emacs};
55     my $emacs = prompt("Where is your emacs? ", $sysemacs);
57     # Make sure emacs is a valid string/program path...
58     return undef unless $emacs;
60     # Make sure -x is passed an absolute path...
61     unless ( $emacs =~ m{^/} && -x $emacs ) { 
62         warn "$emacs is not executable! Undefined.\n";
63         return undef;
64     }
66     return escape_path( $emacs );
69 # Runs some elisp code with emacs via the command line.
70 # We must set $EMACS before running this... if it is an untrue value
71 # then we return an empty list or string, depending on what caller wants.
72 sub run_elisp
74     my ($elisp) = @_;
76     return wantarray ? qw// : q{} unless $EMACS;
77     return `$EMACS --batch --eval '$elisp' 2>/dev/null`;
80 sub prompt_for_sitelisp
82     my @lp = run_elisp( $ELISP_FIND_SITELISP );
83     chomp @lp;
85     my $site_lisp;
86     if ( scalar @lp ) {
87         ($site_lisp) = grep { /site-lisp$/ && -d $_ } @lp;
88     }
90     $site_lisp = prompt("Elisp install directory?", $site_lisp);
92     # We don't check if the directory exists, because we can create it...
93     return escape_path( $site_lisp );
96 sub prompt_for_infodir
98     chomp(my @info_dir = grep { m!/info/?$! } run_elisp( $ELISP_FIND_INFODIR ));
100     # pass prompt undef so it will not display brackets if $info_dir is ""
101     my $info_dir = prompt("Info directory?", $info_dir[0] || undef);
102     return escape_path( $info_dir );
105 # Append info page and elisp installation to the end of the install
106 # section in the Makefile...
108 sub MY::postamble
110     # Make an entry for Sepia.html as a target to make things easier...
111     my $maketxt = <<'END_MAKETXT';
112 all :: Sepia.html sepia.info
114 Sepia.html : sepia.texi
115         makeinfo --no-split --no-headers --html sepia.texi -o Sepia.html
117 sepia.info : sepia.texi
118         makeinfo --no-split -o sepia.info sepia.texi
120 END_MAKETXT
122     $maketxt .= <<"END_MAKETXT";
123 install ::
124 END_MAKETXT
126     if ( $INFO_DIR ) { $maketxt .= <<"END_MAKETXT" }
127         install -d -m755 \$(DESTDIR)$INFO_DIR
128         install -m644 sepia.info \$(DESTDIR)$INFO_DIR
129         $INSTALL_INFO \$(DESTDIR)$INFO_DIR/sepia.info \$(DESTDIR)$INFO_DIR/dir
130         
131 END_MAKETXT
133     if ( $SITE_LISP ) {
134         $maketxt .= <<"END_MAKETXT";
135         install -d -m755 \$(DESTDIR)$SITE_LISP
136         install -m644 *.el \$(DESTDIR)$SITE_LISP
137 END_MAKETXT
138           if ( $EMACS ) {
139               $maketxt .= <<"END_MAKETXT";
140         install -m644 *.elc \$(DESTDIR)$SITE_LISP
141 END_MAKETXT
142           }
143     } else {
144         print <<'END_MSG'
146 ======================================================================
147 To actually use this package, you need to move the Emacs Lisp files
148 somewhere Emacs will find them.
150 You may also want to install the HTML documentation somewhere
151 appropriate to your system.
152 ======================================================================
154 END_MSG
155     }
157     # Create a new target for compiled elisp (.elc) files...
158     # Allow the compilation to fail (it is prefixed with "-")...
159     if ( $EMACS ) {
160         $maketxt .= <<"EOS";
162 \%.elc : \%.el
163         - $EMACS -L '$ENV{PWD}' --batch -f batch-byte-compile \$? 2>/dev/null
165 all :: sepia-snippet.elc sepia.elc sepia-cpan.elc sepia-tree.elc \\
166            sepia-w3m.elc sepia-ido.elc
168     }
170     return $maketxt;
173 GetOptions( 'emacs=s' => \$EMACS,
174             'lisp=s'  => \$SITE_LISP,
175             'info=s'  => \$INFO_DIR,
176             'help'    => \$HELP,
177            );
179 exit pod2usage( '-verbose' => 1 ) if $HELP;
181 test_for 'Devel::Peek', 'Printing internals requires Devel::Peek';
182 test_for 'Devel::Size', 'Printing variable sizes requires Devel::Size';
183 test_for 'IO::Scalar', 'Printing internals requires IO::Scalar because Devel::Peek sucks';
184 test_for 'Lexical::Persistence', 'Strict mode requires Lexical::Persistence';
185 test_for 'LWP::Simple', 'CPAN documentation browsing requires LWP::Simple';
186 test_for 'Module::CoreList', 'sepia-core-version requires Module::CoreList';
187 test_for 'Module::Info', 'Required for some Emacs functions';
188 test_for 'PadWalker', 'Stack/lexical inspection requires PadWalker >= 1.0';
189 test_for 'BSD::Resource', 'Detailed command timing';
190 test_for 'Time::HiRes', 'Basic command timing';
191 # test_for 'Pod::Webserver', 'Pod::Webserver creates nice documentation.';
192 # test_for 'Scope::Upper', 'Required for return-from-context';
194 $INSTALL_INFO = 'install-info';
196 if ( !defined $EMACS ) {
197     $EMACS = prompt_for_emacs()
198       or warn "Disabling elisp compilation and dir detection.\n";
200 $SITE_LISP    ||= prompt_for_sitelisp();
201 $INFO_DIR     ||= prompt_for_infodir();
202 $INSTALL_INFO ||= prompt("install-info program?", 'install-info')
203     if $INFO_DIR;
205 WriteMakefile(
206     NAME                => 'Sepia',
207     VERSION_FROM        => 'lib/Sepia.pm', # finds $VERSION
208     PREREQ_PM           => \%prereq,
209     EXE_FILES           => ['sepl'],
210     AUTHOR              => "Sean O'Rourke <seano\@cpan.org>",
211     ABSTRACT            => 'Simple Emacs-Perl InterAction',
212     clean           => { FILES => '*.elc' },
215 __END__
217 =head1 SYNOPSIS
219   # prompts for paths
220   perl Makefile.PL 
221   
222   # doesn't prompt for paths
223   perl Makefile.PL --emacs /usr/bin/emacs \
224       --lisp /usr/share/emacs/site-lisp/sepia \
225       --info /usr/share/info
227 =head1 OPTIONS
229 =over 4
231 =item B<--emacs>
233 Specifies the path to emacs.
235 =item B<--lisp>
237 Specifies the directory to install the elisp files to.
239 =item B<--info>
241 Specifies the directory to install the texinfo files to.
243 =item B<--help>
245 Display this help information.
247 =back