Bugfix.
[sepia.git] / Makefile.PL
blobc56e6db9eb646b76002074350cfcddeb8e3c5c04
1 # uncomment for development
2 # use warnings;
3 # use strict;
5 use Pod::Usage;
6 use Getopt::Long;
8 use ExtUtils::MakeMaker qw(WriteMakefile prompt);
9 use 5.006;                      # for "no warnings" -- sorry!
10 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
11 # the contents of the Makefile that is written.
13 my %prereq = (
14     'Data::Dumper'    => 0,
15     'Scalar::Util'    => 0,
18 ## Poor man's optional deps.
19 sub test_for
21     my $mod = shift;
22     eval "require $mod";
23     if ($@) {
24         my $resp = prompt("@_.  Install $mod (y/n)? ", 'n');
25         $prereq{$mod} = 0 if $resp =~ /^y/i;
26     }
29 my $ELISP_FIND_SITELISP = <<'END_ELISP';
30 (dolist (x load-path) (princ x) (terpri))
31 END_ELISP
33 my $ELISP_FIND_INFODIR = <<'END_ELISP';
34 (progn
35  (require (quote info))
36  (princ (car Info-default-directory-list)))
37 END_ELISP
39 my ($EMACS, $SITE_LISP, $INSTALL_INFO, $INFO_DIR, $HELP);
41 sub escape_path
43     my ($path) = @_;
44     $path =~ s/([$?* ])/\\$1/g; # escape special characters
45     $path =~ s{/+$}{};          # remove trailing forward-slashes
46     return $path;
49 sub prompt_for_emacs
51     # try to compile and install Elisp files, but don't die if we can't.
52     my ($sysemacs) = grep { defined && -x }
53         $ENV{EMACS}, glob '/usr/bin{/local,}/emacs';
54     $sysemacs ||= q{emacs};
56     my $emacs = prompt("Where is your emacs? ", $sysemacs);
58     # Make sure emacs is a valid string/program path...
59     return undef unless $emacs;
61     # Make sure -x is passed an absolute path...
62     unless ( $emacs =~ m{^/} && -x $emacs ) { 
63         warn "$emacs is not executable! Undefined.\n";
64         return undef;
65     }
67     return escape_path( $emacs );
70 # Runs some elisp code with emacs via the command line.
71 # We must set $EMACS before running this... if it is an untrue value
72 # then we return an empty list or string, depending on what caller wants.
73 sub run_elisp
75     my ($elisp) = @_;
77     return wantarray ? qw// : q{} unless $EMACS;
78     return `$EMACS --batch --eval '$elisp' 2>/dev/null`;
81 sub prompt_for_sitelisp
83     my @lp = run_elisp( $ELISP_FIND_SITELISP );
84     chomp @lp;
86     my $site_lisp;
87     if ( scalar @lp ) {
88         ($site_lisp) = grep { /site-lisp$/ && -d $_ } @lp;
89     }
91     $site_lisp = prompt("Elisp install directory?", $site_lisp);
93     # We don't check if the directory exists, because we can create it...
94     return escape_path( $site_lisp );
97 sub prompt_for_infodir
99     chomp(my @info_dir = grep { m!/info/?$! } run_elisp( $ELISP_FIND_INFODIR ));
101     # pass prompt undef so it will not display brackets if $info_dir is ""
102     my $info_dir = prompt("Info directory?", $info_dir[0] || undef);
103     return escape_path( $info_dir );
106 # Append info page and elisp installation to the end of the install
107 # section in the Makefile...
109 sub MY::postamble
111     # Make an entry for Sepia.html as a target to make things easier...
112     my $maketxt = <<'END_MAKETXT';
113 all :: Sepia.html sepia.info
115 Sepia.html : sepia.texi
116         makeinfo --no-split --no-headers --html sepia.texi -o Sepia.html
118 sepia.info : sepia.texi
119         makeinfo --no-split -o sepia.info sepia.texi
121 END_MAKETXT
123     $maketxt .= <<"END_MAKETXT";
124 install ::
125 END_MAKETXT
127     if ( $INFO_DIR ) { $maketxt .= <<"END_MAKETXT" }
128         install -d -m755 \$(DESTDIR)$INFO_DIR
129         install -m644 sepia.info \$(DESTDIR)$INFO_DIR
130         $INSTALL_INFO \$(DESTDIR)$INFO_DIR/sepia.info \$(DESTDIR)$INFO_DIR/dir
131         
132 END_MAKETXT
134     if ( $SITE_LISP ) {
135         $maketxt .= <<"END_MAKETXT";
136         install -d -m755 \$(DESTDIR)$SITE_LISP
137         install -m644 *.el \$(DESTDIR)$SITE_LISP
138 END_MAKETXT
139           if ( $EMACS ) {
140               $maketxt .= <<"END_MAKETXT";
141         install -m644 *.elc \$(DESTDIR)$SITE_LISP
142 END_MAKETXT
143           }
144     } else {
145         print <<'END_MSG'
147 ======================================================================
148 To actually use this package, you need to move the Emacs Lisp files
149 somewhere Emacs will find them.
151 You may also want to install the HTML documentation somewhere
152 appropriate to your system.
153 ======================================================================
155 END_MSG
156     }
158     # Create a new target for compiled elisp (.elc) files...
159     # Allow the compilation to fail (it is prefixed with "-")...
160     if ( $EMACS ) {
161         $maketxt .= <<"EOS";
163 \%.elc : \%.el
164         - $EMACS -L '$ENV{PWD}' --batch -f batch-byte-compile \$? 2>/dev/null
166 all :: sepia-snippet.elc sepia.elc sepia-cpan.elc sepia-tree.elc \\
167            sepia-w3m.elc sepia-ido.elc
169     }
171     return $maketxt;
174 GetOptions( 'emacs=s' => \$EMACS,
175             'lisp=s'  => \$SITE_LISP,
176             'info=s'  => \$INFO_DIR,
177             'help'    => \$HELP,
178            );
180 exit pod2usage( '-verbose' => 1 ) if $HELP;
182 test_for 'Devel::Peek', 'Printing internals requires Devel::Peek';
183 test_for 'Devel::Size', 'Printing variable sizes requires Devel::Size';
184 test_for 'IO::Scalar', 'Printing internals requires IO::Scalar because Devel::Peek sucks';
185 test_for 'PadWalker', 'Strict mode requires PadWalker';
186 test_for 'Devel::LexAlias', 'Strict mode requires Devel::LexAlias';
187 test_for 'LWP::Simple', 'CPAN documentation browsing requires LWP::Simple';
188 test_for 'Module::CoreList', 'sepia-core-version requires Module::CoreList';
189 test_for 'Module::Info', 'Required for some Emacs functions';
190 test_for 'BSD::Resource', 'Detailed command timing';
191 test_for 'Time::HiRes', 'Basic command timing';
192 # test_for 'Pod::Webserver', 'Pod::Webserver creates nice documentation.';
193 # test_for 'Scope::Upper', 'Required for return-from-context';
195 $INSTALL_INFO = 'install-info';
197 if ( !defined $EMACS ) {
198     $EMACS = prompt_for_emacs()
199       or warn "Disabling elisp compilation and dir detection.\n";
201 $SITE_LISP    ||= prompt_for_sitelisp();
202 $INFO_DIR     ||= prompt_for_infodir();
203 $INSTALL_INFO ||= prompt("install-info program?", 'install-info')
204     if $INFO_DIR;
206 WriteMakefile(
207     NAME                => 'Sepia',
208     VERSION_FROM        => 'lib/Sepia.pm', # finds $VERSION
209     PREREQ_PM           => \%prereq,
210     EXE_FILES           => ['sepl'],
211     AUTHOR              => "Sean O'Rourke <seano\@cpan.org>",
212     ABSTRACT            => 'Simple Emacs-Perl InterAction',
213     clean           => { FILES => '*.elc' },
216 __END__
218 =head1 SYNOPSIS
220   # prompts for paths
221   perl Makefile.PL 
222   
223   # doesn't prompt for paths
224   perl Makefile.PL --emacs /usr/bin/emacs \
225       --lisp /usr/share/emacs/site-lisp/sepia \
226       --info /usr/share/info
228 =head1 OPTIONS
230 =over 4
232 =item B<--emacs>
234 Specifies the path to emacs.
236 =item B<--lisp>
238 Specifies the directory to install the elisp files to.
240 =item B<--info>
242 Specifies the directory to install the texinfo files to.
244 =item B<--help>
246 Display this help information.
248 =back