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