6 use ExtUtils::MakeMaker;
10 # Usage: perl Makefile.PL [options]
12 # -f file Use file for default configuration values (default is config.log)
14 # -k Keep same values as config.log (or file specified with -f)
16 ## Be sure to edit the version number in lib/Text/Restructured.pm for
19 open PM, "lib/Text/Restructured.pm";
21 if (/\$VERSION\s*=/) {
22 my $VERSION; # N.B.: Needed so $VERSION passes strict
28 use vars qw($opt_f $opt_h $opt_k);
29 my $OUTPUT_CFG_FILE = $opt_f = 'config.log';
32 usage() if ! getopts("f:hk") || $opt_h;
34 ##### Do all user prompts first
36 (taint => {default => 'No',
37 desc => 'Run perl tainted (not required for safe operation)',
42 desc => 'URL for default cascading style sheet (or "none")',
44 Generated documents need a style sheet to look good. It is recommended
45 to serve a local copy of lib/Text/Restructured/default.css as an http URL.
46 You can also specify 'None', in which case the default stylesheet will
47 be embedded within every document.
53 desc => 'URL where documentation will be installed (or "none")',
57 my @CFG_LIST = qw(defaultcss taint docurl);
58 warn "\@CFG_LIST and \%CFG_LIST have different number of elements"
59 if @CFG_LIST != keys %CFG_LIST;
61 my %CONFIG; # Our final configuration
62 my %DEFAULTS; # Default values
64 # First read the config file if it exists
66 open CF, $opt_f or die "Cannot open $opt_f";
67 my %cfg = eval(join('',<CF>));
68 @DEFAULTS{keys %cfg} = values %cfg;
72 # Set the defaults from %CFG_LIST
73 @DEFAULTS{keys %CFG_LIST} = map($_->{default}, values %CFG_LIST);
78 foreach my $cfg_item (@CFG_LIST) {
79 my $message = $CFG_LIST{$cfg_item}{desc};
80 $message = "$CFG_LIST{$cfg_item}{explain}\n$message"
81 if defined $CFG_LIST{$cfg_item}{explain};
83 my $val = prompt ($message, $DEFAULTS{$cfg_item});
84 $val =~ s/^\s*(.*?)\s*$/$1/;
85 $CONFIG{$cfg_item} = $val;
87 defined $CFG_LIST{$cfg_item}{checkfail} &&
88 &{$CFG_LIST{$cfg_item}{checkfail}}($CONFIG{$cfg_item});
89 $message = $CFG_LIST{$cfg_item}{desc};
91 $DEFAULTS{$cfg_item} = $CONFIG{$cfg_item};
97 my $okay = prompt("Does this look right?");
98 last if ($okay !~ m/^[n0]/i);
101 @CONFIG{@CFG_LIST} = @DEFAULTS{@CFG_LIST};
105 # Add the prest version to the config
106 $CONFIG{version} = $Version;
107 # Add the perl executable to the config
110 # Write the configuration file (after saving the old one)
111 rename "$OUTPUT_CFG_FILE", "$OUTPUT_CFG_FILE.bak";
112 open (CL, ">$OUTPUT_CFG_FILE") or die "Cannot write to $OUTPUT_CFG_FILE.";
113 print CL map(qq('$_'=>'$CONFIG{$_}',\n), sort keys %CONFIG);
116 ##### Figure out what version of make to use. We *require* GNU make.
117 my @path = split /:/, $ENV{PATH};
118 my ($make) = grep -x $_, map("$_/gmake", @path), map("$_/make", @path);
120 #### Write out all the .t files
121 my $generic_t = << 'EOS';
122 #!/usr/local/bin/perl5.8.8
123 use Slay::Makefile::Gress qw(do_tests);
124 do_tests('../../Common.smak', @ARGV);
128 my @generic_t_dirs = grep -d $_, <t/*>;
129 # Create generic .t files
130 foreach my $dir (@generic_t_dirs) {
132 my @need_t = grep s/\.init$/.t/, readdir(DIR);
134 foreach my $t (@need_t) {
138 push @TESTS, "$dir/$t";
142 # Make sure PrestConfig.pm gets rebuilt
143 unlink "lib/Text/Restructured/PrestConfig.pm";
145 #### Finally, create the Makefile
146 # Get list of perl modules in lib subdirectory
147 chomp (my @pm_files =
148 grep ! /\.svn|\bCVS\b|~\Z|\.PL\Z/, `find lib -type f`);
150 @pm_files{@pm_files} = map "blib/$_", @pm_files;
152 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
153 # the contents of the Makefile that is written.
154 my $pm_filter = "$^X -pe 'END { print qq{\\044VERSION = $Version\\012} }'";
156 NAME => 'Text::Restructured',
157 AUTHOR => 'Mark Nodine <mnodine@alum.mit.edu>',
158 ABSTRACT => 'Perl implementation of reStructuredText parser',
160 EXE_FILES => [qw(prest)],
163 PREREQ_PM => { 'Text::ASCIIMathML'=>0.5,
164 'Slay::Makefile::Gress'=>0,
167 }, # e.g., Module::Name => 1.1
168 PL_FILES => {'lib/Text/Restructured/PrestConfig.pm.PL' =>
169 'lib/Text/Restructured/PrestConfig.pm'},
170 PM => {'lib/Text/Restructured/PrestConfig.pm' =>
171 'blib/lib/Text/Restructured/PrestConfig.pm',
173 # PM_FILTER => qq($^X -pe "END{print qq{our \\044VERSION=$Version\\;\\n}}"),
175 test => { TESTS => join ' ',@TESTS },
176 clean => { FILES =>(join(' ', (@TESTS, map(/(.*)\.t$/ && "$1.run",
178 q[ t/Common.mk lib/Text/Restructured/PrestConfig.pm]) },
179 dist => { COMPRESS => 'gzip', SUFFIX => '.gz' },
180 realclean => { FILES => q(config.log config.log.bak) },
184 my ($self, $path) = @_;
185 return $path !~ /\.svn/ && $path;
189 return <<'MAKE_FRAG';
190 FIXIN = $(PERLRUNINST) insertperl.pl
192 $(INST_SCRIPT)/prest : lib/Text/Restructured/PrestConfig.pm
200 #### Random support subroutines
202 # Prints a summary of the configuration
204 print "Here is the summary of the configuration:\n";
205 foreach my $cfg_item (@CFG_LIST) {
206 print " $CFG_LIST{$cfg_item}{desc}: $CONFIG{$cfg_item}\n";
210 # This subroutine extracts usage information
213 $what = "Usage" if ! $what;
215 if (open(ME,$0) == 1) {
217 $print = 1 if /^# $what/o;
218 $print = 0 if ! /^#/o || ($end && /^# $end/o);
219 print substr($_,2) if $print;
224 print STDERR "Usage not available.\n";
229 # Checks for valid URL or "none"
231 my $fail = $_[0] !~ /^\w+:|none/i;
232 print STDERR "Must be either a URL reference or 'None'\n"
237 # Checks for yes or no answer
239 my $fail = !($_[0] =~ s/^y.*/Yes/i || $_[0] =~ s/^n.*/No/i);
240 print "Must be 'yes' or 'no'\n" if $fail;