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