1# Build instructions for podlators. 2# 3# We need to use ExtUtils::MakeMaker since this module is part of Perl core, 4# which only supports that build method, and because it is a dependency of 5# other build systems like Module::Build. 6# 7# Copyright 1999-2001, 2008, 2010, 2012, 2014-2016, 2018-2019 8# Russ Allbery <rra@cpan.org> 9# 10# This program is free software; you may redistribute it and/or modify it 11# under the same terms as Perl itself. 12# 13# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 14 15use 5.008; 16use strict; 17use warnings; 18 19use Config; 20use ExtUtils::MakeMaker; 21use File::Spec; 22 23# Determine the version of the distribution so that we can construct the 24# provides metadata that unfortunately ExtUtils::MakeMaker does not build. 25# This is a very simple $VERSION parser, since it only has to handle the 26# syntax Pod::Man uses. 27# 28# Returns: Distribution version as a string 29sub dist_version { 30 open(my $fh, '<', File::Spec->catfile('lib', 'Pod', 'Man.pm')) 31 or die "$0: cannot open lib/Pod/Man.pm: $!\n"; 32 while (defined(my $line = <$fh>)) { 33 if ($line =~ m{ \A \$VERSION \s+ = \s+ '([^\']+)' }xms) { 34 close($fh) or die "$0: cannot close lib/Pod/Man.pm\n"; 35 return $1; 36 } 37 } 38 close($fh) or die "$0: cannot close lib/Pod/Man.pm\n"; 39 die "$0: cannot find version in lib/Pod/Man.pm\n"; 40} 41 42# Generate full paths for scripts distributed in the bin directory. Appends 43# the .com extension to scripts on VMS, unless they already have the .PL 44# extension. 45# 46# @scripts - List of script names 47# 48# Returns: (Array) List of relative paths from top of distribution 49# (Scalar) Space-separated relative paths from top of distribution 50sub scripts { 51 my (@scripts) = @_; 52 my @paths = map { File::Spec->catfile('scripts', $_) } @scripts; 53 if ($^O eq 'VMS') { 54 @paths = map { m{ [.] PL \z }xms ? $_ : $_ . '.com' } @paths; 55 } 56 return wantarray ? @paths : join(q{ }, @paths); 57} 58 59# Generate an association between a source file and a destination man page for 60# non-module man pages. ExtUtils::MakeMaker only really understands how to 61# generate man pages for modules, so we need to help it for the script man 62# pages and (particularly) the perlpodstyle man page. 63# 64# $directory - Directory containing the file 65# $file - File containing POD in that directory 66# 67# Returns: The path to the file with POD and the output man page, as a pair 68sub man1pod { 69 my ($directory, $file) = @_; 70 71 # Build the base name of the file by stripping any *.pod or *.PL suffix. 72 my $basename = $file; 73 $basename =~ s{ [.] (?: pod | PL ) \z }{}xms; 74 75 # Determine the output file name for the generated man page. 76 my $outname = $basename . q{.} . $Config{man1ext}; 77 my $outpath = File::Spec->catfile(qw(blib man1), $outname); 78 return (File::Spec->catfile($directory, $file), $outpath); 79} 80 81# The hash of all the metadata. This will be modified before WriteMakefile to 82# remove keys not supported by the local version of ExtUtils::MakeMaker. 83my $dist_version = dist_version(); 84my %metadata = ( 85 NAME => 'Pod', 86 DISTNAME => 'podlators', 87 ABSTRACT => 'Convert POD data to various other formats', 88 AUTHOR => 'Russ Allbery <rra@cpan.org>', 89 LICENSE => 'perl_5', 90 EXE_FILES => [scripts('pod2text', 'pod2man')], 91 VERSION_FROM => 'lib/Pod/Man.pm', 92 MIN_PERL_VERSION => '5.008', 93 94 # Use *.PL files to generate the driver scripts so that we get the correct 95 # invocation of Perl on non-UNIX platforms. 96 PL_FILES => { 97 scripts('pod2man.PL', 'pod2man'), scripts('pod2text.PL', 'pod2text'), 98 }, 99 100 # Override the files that generate section 1 man pages. 101 MAN1PODS => { 102 man1pod('scripts', 'pod2man.PL'), 103 man1pod('scripts', 'pod2text.PL'), 104 105 # Perl core uses a separate copy in the top-level pod directory. 106 ($ENV{PERL_CORE} ? () : man1pod('pod', 'perlpodstyle.pod')), 107 }, 108 109 # Clean some additional files. 110 clean => { FILES => File::Spec->catdir('t', 'tmp') }, 111 realclean => { FILES => scalar(scripts('pod2text', 'pod2man')) }, 112 113 # Dependencies on other modules. 114 PREREQ_PM => { 'Pod::Simple' => 3.06 }, 115 116 # Older versions of ExtUtils::MakeMaker don't pick up nested test 117 # directories by default. 118 test => { TESTS => 't/*/*.t' }, 119 120 # For older versions of Perl, we have to force installation into the Perl 121 # module directories since site modules did not take precedence over core 122 # modules. 123 INSTALLDIRS => $] lt '5.011' ? 'perl' : 'site', 124 125 # Additional metadata. 126 META_ADD => { 127 'meta-spec' => { version => 2 }, 128 provides => { 129 'Pod::Man' => { 130 file => 'lib/Pod/Man.pm', 131 version => $dist_version, 132 }, 133 'Pod::ParseLink' => { 134 file => 'lib/Pod/ParseLink.pm', 135 version => $dist_version, 136 }, 137 'Pod::Text' => { 138 file => 'lib/Pod/Text.pm', 139 version => $dist_version, 140 }, 141 'Pod::Text::Color' => { 142 file => 'lib/Pod/Text/Color.pm', 143 version => $dist_version, 144 }, 145 'Pod::Text::Overstrike' => { 146 file => 'lib/Pod/Text/Overstrike.pm', 147 version => $dist_version, 148 }, 149 'Pod::Text::Termcap' => { 150 file => 'lib/Pod/Text/Termcap.pm', 151 version => $dist_version, 152 }, 153 }, 154 resources => { 155 bugtracker => { 156 mailto => 'bug-podlators@rt.cpan.org', 157 web => 'https://rt.cpan.org/Dist/Display.html?Name=podlators', 158 }, 159 homepage => 'https://www.eyrie.org/~eagle/software/podlators/', 160 repository => { 161 url => 'https://github.com/rra/podlators.git', 162 web => 'https://github.com/rra/podlators', 163 type => 'git', 164 }, 165 }, 166 }, 167); 168 169# Remove keys that aren't supported by this version of ExtUtils::MakeMaker. 170# This hash maps keys to the minimum supported version. 171my %supported = ( 172 LICENSE => 6.31, 173 META_ADD => 6.46, 174 MIN_PERL_VERSION => 6.48, 175); 176for my $key (keys(%supported)) { 177 if ($ExtUtils::MakeMaker::VERSION < $supported{$key}) { 178 delete $metadata{$key}; 179 } 180} 181 182# Generate the actual Makefile. Pick an arbitrary module to pull the version 183# from, since they should all have the same version. 184WriteMakefile(%metadata); 185