]> Sergey Matveev's repositories - public-inbox.git/blob - Makefile.PL
Date::Parse is now optional
[public-inbox.git] / Makefile.PL
1 #!/usr/bin/perl -w
2 # Copyright (C) 2013-2019 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use ExtUtils::MakeMaker;
6 open my $m, '<', 'MANIFEST' or die "open(MANIFEST): $!\n";
7 chomp(my @manifest = (<$m>));
8 my @EXE_FILES = grep(m!^script/!, @manifest);
9 my $v = {};
10 my $t = {};
11 $v->{txt} = [ qw(INSTALL README COPYING TODO HACKING) ];
12 my @dtxt = grep(m!\ADocumentation/.*\.txt\z!, @manifest);
13 push @dtxt, 'Documentation/standards.txt';
14 for my $txt (@dtxt) {
15         my $html = $txt;
16         $html =~ s/\.txt\z/.html/;
17         $t->{"$html : $txt"} = [ "\$(txt2pre) <$txt" ];
18 }
19 $v->{t_slash_star_dot_t} = [ grep(m!\At/.*\.t\z!, @manifest) ];
20 my @scripts = qw(scripts/ssoma-replay); # legacy
21 my @syn = (@EXE_FILES, grep(m!^lib/.*\.pm$!, @manifest), @scripts);
22 @syn = grep(!/DSKQXS\.pm/, @syn) if !eval { require IO::KQueue };
23 @syn = grep(!/Unsubscribe\.pm/, @syn) if !eval { require Crypt::CBC };
24 @syn = grep(!/SaPlugin/, @syn) if !eval { require Mail::SpamAssasin };
25 $v->{my_syntax} = [map { "$_.syntax" } @syn];
26 $v->{-m1} = [ map { (split('/'))[-1] } @EXE_FILES ];
27 $v->{-m5} = [ qw(public-inbox-config public-inbox-v1-format
28                 public-inbox-v2-format) ];
29 $v->{-m7} = [ qw(public-inbox-overview) ];
30 $v->{-m8} = [ qw(public-inbox-daemon) ];
31 my @sections = (1, 5, 7, 8);
32 $v->{check_80} = [];
33 $v->{manuals} = [];
34 $v->{mantxt} = [];
35 for my $i (@sections) {
36         my $ary = $v->{"-m$i"};
37         $v->{"m$i"} = $ary;
38         for my $m (@$ary) {
39                 my $pod = "Documentation/$m.pod";
40                 my $txt = "Documentation/$m.txt";
41                 $t->{"$m.$i : $pod"} = [ "\$(podman) -s$i $pod \$@" ];
42                 $t->{"$txt : $pod"} = [ "\$(podtext) $pod \$\@+",
43                                         "touch -r $pod \$\@+",
44                                         "mv \$\@+ \$@" ];
45                 $t->{"Documentation/$m.html : $txt"} = [ "\$(txt2pre) <$txt" ];
46                 $t->{".$m.cols : $m.$i"} = [
47                         "\@echo CHECK80 $m.$i;".
48                         "COLUMNS=80 \$(MAN) ./$m.$i | \$(check_man)" ];
49         }
50         push @{$v->{check_80}}, map { ".$_.cols" } @$ary;
51         my $manuals = $v->{"man$i"} = [ map { "$_.$i" } @$ary ];
52         push @{$v->{manuals}}, @$manuals;
53         push @{$v->{mantxt}}, map { "Documentation/$_.txt" } @$ary;
54 }
55 push @dtxt, @{$v->{mantxt}};
56 $v->{docs} = [ @dtxt, 'NEWS' ];
57 $v->{docs_html} = [ map {;
58                 my $x = $_;
59                 $x =~ s/\.txt\z//;
60                 "$x.html"
61         } @{$v->{docs}} ];
62 $v->{gz_docs} = [ map { "$_.gz" } (@{$v->{docs}},@{$v->{docs_html}}) ];
63 $v->{rsync_docs} = [ @{$v->{gz_docs}}, @{$v->{docs}},
64         @{$v->{docs_html}}, qw(NEWS.atom NEWS.atom.gz)];
65
66 # external manpages which we host ourselves, since some packages
67 # (currently just Xapian) doesn't host manpages themselves.
68 my @xman = qw(copydatabase.1 xapian-compact.1);
69 $v->{xdocs} = [ map { "Documentation/.x/.$_.txt" } @xman ];
70 $v->{xdocs_html} = [ map { "Documentation/.x/.$_.html" } @xman ];
71 for (@{$v->{xdocs}}) {
72         $t->{"$_ : | Documentation/.x"} = [
73                 '$(PERL) -w Documentation/extman.perl >$@',
74         ];
75         my $html = $_;
76         $html =~ s/\.txt\z/.html/;
77         $t->{"$html : $_"} = [ "\$(txt2pre) <$_" ];
78 }
79 $v->{gz_xdocs} = [ map { "$_.gz" } (@{$v->{xdocs_html}}, @{$v->{xdocs}}) ];
80 $v->{rsync_xdocs} = [ @{$v->{gz_xdocs}}, @{$v->{xdocs_html}}, @{$v->{xdocs}} ];
81
82 my $TGTS = join("\n", map {;
83         my $tgt_prereq = $_;
84         my $cmds = $t->{$_};
85         "$tgt_prereq\n".join('', map { "\t$_\n" } @$cmds);
86 } keys %$t);
87
88 my $VARS = join("\n", map {;
89         my $varname = $_;
90         join('', map { "$varname += $_\n" } @{$v->{$varname}});
91 } grep(!/^-/, keys %$v));
92
93 # Don't waste user's disk space by installing some pods from
94 # imported code or internal use only
95 my %man3 = map {; # semi-colon tells Perl this is a BLOCK (and not EXPR)
96         my $base = $_;
97         my $mod = $base;
98         $mod =~ s!/!::!g;
99         $mod =~ s/\.\w+\z//;
100         "lib/PublicInbox/$_" => "blib/man3/PublicInbox::$mod.3"
101 } qw(Git.pm Import.pm WWW.pod SaPlugin/ListMirror.pod);
102
103 WriteMakefile(
104         NAME => 'PublicInbox',
105         VERSION => '1.2.0',
106         AUTHOR => 'Eric Wong <e@80x24.org>',
107         ABSTRACT => 'public-inbox server infrastructure',
108         EXE_FILES => \@EXE_FILES,
109         PREREQ_PM => {
110                 # note: we use spamc(1), NOT the Perl modules
111                 # We also depend on git.
112                 # Keep this sorted and synced to the INSTALL document
113
114                 # libperl$PERL_VERSION,
115                 # `perl5' on FreeBSD
116                 # perl-Digest-SHA on RH-based
117                 'Digest::SHA' => 0,
118                 'Email::MIME' => 0,
119
120                 # the following should be pulled in by Email::MIME:
121                 'Email::MIME::ContentType' => 0,
122                 'Email::Simple' => 0,
123
124                 # libperl$PERL_VERSION or libencode-perl on Debian,
125                 # `perl5' on FreeBSD
126                 'Encode' => 0,
127
128                 # TODO: these should really be made optional...
129                 'Plack' => 0,
130                 'URI::Escape' => 0,
131
132                 # We have more test dependencies, but do not force
133                 # users to install them.  See INSTALL
134
135                 # All Perl installs I know about have these, but RH-based
136                 # distros make them separate even though 'perl' pulls them in
137                 'File::Path' => 0,
138                 'File::Temp' => '0.19',
139                 'Getopt::Long' => 0,
140                 'Exporter' => 0,
141                 # ExtUtils::MakeMaker # this file won't run w/o it...
142         },
143         MAN3PODS => \%man3,
144 );
145
146 sub MY::postamble {
147   <<EOF;
148 # support using eatmydata to speed up tests (apt-get install eatmydata):
149 # https://www.flamingspork.com/projects/libeatmydata/
150 EATMYDATA =
151 N = \$\$(( \$\$(nproc 2>/dev/null || gnproc 2>/dev/null || echo 2) + 1 ))
152 -include config.mak
153 $VARS
154 -include Documentation/include.mk
155 $TGTS
156
157 # syntax checks are currently GNU make only:
158 %.syntax :: %
159         @\$(PERL) -w -I lib -c \$<
160
161 syntax:: \$(my_syntax)
162
163 changed = \$(shell git ls-files -m)
164 dsyn :: \$(addsuffix .syntax, \$(filter \$(changed), \$(syn_files)))
165
166 check-manifest :: MANIFEST
167         if git ls-files >\$?.gen 2>&1; then diff -u \$? \$?.gen; fi
168
169 check:: pure_all check-manifest
170         \$(EATMYDATA) prove -bvw -j\$(N)
171
172 lib/PublicInbox/UserContent.pm :: contrib/css/216dark.css
173         \$(PERL) -I lib \$@ \$?
174
175 # Ensure new .pm files will always be installed by updating
176 # the timestamp of Makefile.PL which forces Makefile to be remade
177 Makefile.PL : MANIFEST
178         touch -r MANIFEST \$@
179         \$(PERLRUN) \$@
180
181 EOF
182 }