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, 2022
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 (?:our \s+)? \$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    #<<<
86    NAME             => 'Pod',
87    DISTNAME         => 'podlators',
88    ABSTRACT         => 'Convert POD data to various other formats',
89    AUTHOR           => 'Russ Allbery <rra@cpan.org>',
90    LICENSE          => 'perl_5',
91    EXE_FILES        => [scripts('pod2text', 'pod2man')],
92    VERSION_FROM     => 'lib/Pod/Man.pm',
93    MIN_PERL_VERSION => '5.010',
94    #>>>
95
96    # Use *.PL files to generate the driver scripts so that we get the correct
97    # invocation of Perl on non-UNIX platforms.
98    PL_FILES => {
99        scripts('pod2man.PL', 'pod2man'), scripts('pod2text.PL', 'pod2text'),
100    },
101
102    # Override the files that generate section 1 man pages.
103    MAN1PODS => {
104        man1pod('scripts', 'pod2man.PL'),
105        man1pod('scripts', 'pod2text.PL'),
106
107        # Perl core uses a separate copy in the top-level pod directory.
108        ($ENV{PERL_CORE} ? () : man1pod('pod', 'perlpodstyle.pod')),
109    },
110
111    # Clean some additional files.
112    clean => { FILES => File::Spec->catdir('t', 'tmp') },
113    realclean => { FILES => scalar(scripts('pod2text', 'pod2man')) },
114
115    # Dependencies on other modules.
116    PREREQ_PM => { 'Pod::Simple' => 3.26 },
117
118    # Older versions of ExtUtils::MakeMaker don't pick up nested test
119    # directories by default.
120    test => { TESTS => 't/*/*.t' },
121
122    # For older versions of Perl, we have to force installation into the Perl
123    # module directories since site modules did not take precedence over core
124    # modules.
125    INSTALLDIRS => $] lt '5.011' ? 'perl' : 'site',
126
127    # Additional metadata.
128    META_ADD => {
129        'meta-spec' => { version => 2 },
130        provides => {
131            'Pod::Man' => {
132                file => 'lib/Pod/Man.pm',
133                version => $dist_version,
134            },
135            'Pod::ParseLink' => {
136                file => 'lib/Pod/ParseLink.pm',
137                version => $dist_version,
138            },
139            'Pod::Text' => {
140                file => 'lib/Pod/Text.pm',
141                version => $dist_version,
142            },
143            'Pod::Text::Color' => {
144                file => 'lib/Pod/Text/Color.pm',
145                version => $dist_version,
146            },
147            'Pod::Text::Overstrike' => {
148                file => 'lib/Pod/Text/Overstrike.pm',
149                version => $dist_version,
150            },
151            'Pod::Text::Termcap' => {
152                file => 'lib/Pod/Text/Termcap.pm',
153                version => $dist_version,
154            },
155        },
156        resources => {
157            bugtracker => {
158                web => 'https://github.com/rra/podlators/issues',
159            },
160            homepage => 'https://www.eyrie.org/~eagle/software/podlators/',
161            repository => {
162                url => 'https://github.com/rra/podlators.git',
163                web => 'https://github.com/rra/podlators',
164                type => 'git',
165            },
166        },
167    },
168);
169
170# Remove keys that aren't supported by this version of ExtUtils::MakeMaker.
171# This hash maps keys to the minimum supported version.
172my %supported = (
173    LICENSE => 6.31,
174    META_ADD => 6.46,
175    MIN_PERL_VERSION => 6.48,
176);
177for my $key (keys(%supported)) {
178    if ($ExtUtils::MakeMaker::VERSION < $supported{$key}) {
179        delete $metadata{$key};
180    }
181}
182
183# Generate the actual Makefile.  Pick an arbitrary module to pull the version
184# from, since they should all have the same version.
185WriteMakefile(%metadata);
186