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