]> Sergey Matveev's repositories - public-inbox.git/blob - Makefile.PL
doc: add lei-overview(7)
[public-inbox.git] / Makefile.PL
1 #!/usr/bin/perl -w
2 # Copyright (C) 2013-2021 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
12 # do not sort
13 my @RELEASES = qw(v1.6.1 v1.6.0 v1.5.0 v1.4.0 v1.3.0 v1.2.0 v1.1.0-pre1 v1.0.0);
14
15 $v->{news_deps} = [ map { "Documentation/RelNotes/$_.eml" } @RELEASES ];
16 $v->{txt} = [ qw(INSTALL README COPYING TODO HACKING) ];
17 my @dtxt = grep(m!\ADocumentation/[^/]+\.txt\z!, @manifest);
18 push @dtxt, 'Documentation/standards.txt';
19 push @dtxt, 'Documentation/flow.txt';
20 push @dtxt, @{$v->{txt}};
21 for my $txt (@dtxt) {
22         my $html = $txt;
23         $html =~ s/\.txt\z/.html/ or $html .= '.html';
24         $t->{"$html : $txt"} = [ "\$(txt2pre) <$txt" ];
25 }
26 $v->{t_slash_star_dot_t} = [ grep(m!\At/.*\.t\z!, @manifest) ];
27 my @scripts = qw(scripts/ssoma-replay); # legacy
28 my @syn = (@EXE_FILES, grep(m!^lib/.*\.pm$!, @manifest), @scripts);
29 @syn = grep(!/DSKQXS\.pm/, @syn) if !eval { require IO::KQueue };
30 @syn = grep(!/Unsubscribe\.pm/, @syn) if !eval { require Crypt::CBC };
31 @syn = grep(!/SaPlugin/, @syn) if !eval { require Mail::SpamAssasin };
32 $v->{syn_files} = \@syn;
33 $v->{my_syntax} = [map { "$_.syntax" } @syn];
34 my @no_pod;
35 $v->{-m1} = [ map {
36                 my $x = (split('/'))[-1];
37                 my $pod = "Documentation/$x.pod";
38                 if (-f $pod) {
39                         $x;
40                 } else {
41                         warn "W: $pod missing\n";
42                         push @no_pod, $x;
43                         ();
44                 }
45         } @EXE_FILES,
46         qw(
47         lei-add-external lei-config lei-daemon-kill lei-daemon-pid
48         lei-forget-external lei-init lei-ls-external lei-q)];
49 $v->{-m5} = [ qw(public-inbox-config public-inbox-v1-format
50                 public-inbox-v2-format public-inbox-extindex-format) ];
51 $v->{-m7} = [ qw(lei-overview public-inbox-overview public-inbox-tuning) ];
52 $v->{-m8} = [ qw(public-inbox-daemon) ];
53 my @sections = (1, 5, 7, 8);
54 $v->{check_80} = [];
55 $v->{manuals} = [];
56 $v->{mantxt} = [];
57 for my $i (@sections) {
58         my $ary = $v->{"-m$i"};
59         $v->{"m$i"} = $ary;
60         for my $m (@$ary) {
61                 my $pod = "Documentation/$m.pod";
62                 my $txt = "Documentation/$m.txt";
63                 $t->{"$m.$i : $pod"} = [ "\$(podman) -s$i $pod \$@" ];
64                 $t->{"$txt : $pod"} = [ "\$(podtext) $pod \$\@+",
65                                         "touch -r $pod \$\@+",
66                                         "mv \$\@+ \$@" ];
67                 $t->{"Documentation/$m.html : $txt"} = [ "\$(txt2pre) <$txt" ];
68                 $t->{".$m.cols : $m.$i"} = [
69                         "\@echo CHECK80 $m.$i;".
70                         "COLUMNS=80 \$(MAN) ./$m.$i | \$(check_man)" ];
71                 $t->{".$m.lexgrog: $m.$i"} = [
72                         "\@echo LEXGROG $m.$i;" .
73                         "\$(LEXGROG) ./$m.$i >\$\@+ && mv \$\@+ \$@" ];
74         }
75         push @{$v->{check_80}}, map { ".$_.cols" } @$ary;
76         push @{$v->{check_lexgrog}}, map { ".$_.lexgrog" } @$ary;
77         my $manuals = $v->{"man$i"} = [ map { "$_.$i" } @$ary ];
78         push @{$v->{manuals}}, @$manuals;
79         push @{$v->{mantxt}}, map { "Documentation/$_.txt" } @$ary;
80 }
81 push @dtxt, @{$v->{mantxt}};
82 $v->{docs} = [ @dtxt, 'NEWS' ];
83 $v->{docs_html} = [ map {;
84                 my $x = $_;
85                 $x =~ s/\.txt\z//;
86                 "$x.html"
87         } @{$v->{docs}} ];
88 $v->{gz_docs} = [ map { "$_.gz" } (@{$v->{docs}},@{$v->{docs_html}}) ];
89 $v->{rsync_docs} = [ @{$v->{gz_docs}}, @{$v->{docs}},
90         @{$v->{docs_html}}, qw(NEWS.atom NEWS.atom.gz)];
91
92 # external manpages which we host ourselves, since some packages
93 # (currently just Xapian) doesn't host manpages themselves.
94 my @xman = qw(copydatabase.1 xapian-compact.1);
95 $v->{xdocs} = [ map { "Documentation/.$_.txt" } @xman ];
96 $v->{xdocs_html} = [ map { "Documentation/.$_.html" } @xman ];
97 for (@{$v->{xdocs}}) {
98         $t->{"$_:"} = [
99                 '$(PERL) -w Documentation/extman.perl $@ >$@+',
100                 'mv $@+ $@'
101         ];
102         my $html = $_;
103         $html =~ s/\.txt\z/.html/;
104         $t->{"$html : $_"} = [ "\$(txt2pre) <$_" ];
105 }
106 $v->{gz_xdocs} = [ map { "$_.gz" } (@{$v->{xdocs_html}}, @{$v->{xdocs}}) ];
107 $v->{rsync_xdocs} = [ @{$v->{gz_xdocs}}, @{$v->{xdocs_html}}, @{$v->{xdocs}} ];
108
109 my $TGTS = join("\n", map {;
110         my $tgt_prereq = $_;
111         my $cmds = $t->{$_};
112         "$tgt_prereq\n".join('', map { "\t$_\n" } @$cmds);
113 } sort keys %$t);
114
115 my $VARS = join("\n", map {;
116         my $varname = $_;
117         join('', map { "$varname += $_\n" } sort @{$v->{$varname}});
118 } grep(!/^-/, sort keys %$v));
119 $VARS .= "\nRELEASES = ".join(' ', @RELEASES)."\n";
120
121 # Don't waste user's disk space by installing some pods from
122 # imported code or internal use only
123 my %man3 = map {; # semi-colon tells Perl this is a BLOCK (and not EXPR)
124         my $base = $_;
125         my $mod = $base;
126         $mod =~ s!/!::!g;
127         $mod =~ s/\.\w+\z//;
128         "lib/PublicInbox/$_" => "blib/man3/PublicInbox::$mod.\$(MAN3EXT)"
129 } qw(Git.pm Import.pm WWW.pod SaPlugin/ListMirror.pod);
130 my $warn_no_pod = @no_pod ? "\n\t\@echo W: missing .pod: @no_pod\n" : '';
131 chomp(my $lexgrog = `which lexgrog 2>/dev/null`);
132 my $check_lexgrog = $lexgrog ? 'check-lexgrog' : '';
133
134 WriteMakefile(
135         NAME => 'PublicInbox', # n.b. camel-case is not our choice
136
137         # XXX drop "PENDING" in .pod before updating this!
138         VERSION => '1.6.1',
139
140         AUTHOR => 'Eric Wong <e@80x24.org>',
141         ABSTRACT => 'public-inbox server infrastructure',
142         EXE_FILES => \@EXE_FILES,
143         PREREQ_PM => {
144                 # note: we use spamc(1), NOT the Perl modules
145                 # We also depend on git.
146                 # Keep this sorted and synced to the INSTALL document
147
148                 # libperl$PERL_VERSION,
149                 # `perl5' on FreeBSD
150                 # perl-Digest-SHA on RH-based
151                 'Digest::SHA' => 0,
152
153                 # libperl$PERL_VERSION or libencode-perl on Debian,
154                 # `perl5' on FreeBSD
155                 'Encode' => 2.35, # 2.35 shipped with 5.10.1
156
157                 # libperl$PERL_VERSION + perl-modules-$PERL_VERSION
158                 'Compress::Raw::Zlib' => 0,
159                 'Compress::Zlib' => 0,
160                 'IO::Compress::Gzip' => 0,
161
162                 # Plack is needed for public-inbox-httpd and PublicInbox::WWW
163                 # 'Plack' => 0,
164
165                 # TODO: this should really be made optional...
166                 'URI::Escape' => 0,
167
168                 # We have more test dependencies, but do not force
169                 # users to install them.  See INSTALL
170
171                 # All Perl installs I know about have these, but RH-based
172                 # distros make them separate even though 'perl' pulls them in
173                 'File::Path' => 0,
174                 'File::Temp' => '0.19', # for ->tmpdir support
175                 'Getopt::Long' => 0,
176                 'Exporter' => 0,
177                 # ExtUtils::MakeMaker # this file won't run w/o it...
178         },
179         MAN3PODS => \%man3,
180 );
181
182 sub MY::postamble {
183         my $N = (`{ getconf _NPROCESSORS_ONLN || nproc; } 2>/dev/null` || 1);
184         $N += 1; # account for sleeps in some tests (and makes an IV)
185         <<EOF;
186 PROVE = prove
187 # support using eatmydata to speed up tests (apt-get install eatmydata):
188 # https://www.flamingspork.com/projects/libeatmydata/
189 EATMYDATA =
190 N = $N
191 -include config.mak
192 $VARS
193 -include Documentation/include.mk
194 $TGTS
195
196 check-man :: $check_lexgrog$warn_no_pod
197
198 # syntax checks are currently GNU make only:
199 %.syntax :: %
200         @\$(PERL) -w -I lib -c \$<
201
202 syntax:: \$(my_syntax)
203
204 changed = \$(shell git ls-files -m)
205 dsyn :: \$(addsuffix .syntax, \$(filter \$(changed), \$(syn_files)))
206
207 check_manifest := if test -e .git && git ls-files >MANIFEST.gen 2>&1; then \\
208                 diff -u MANIFEST MANIFEST.gen; fi
209
210 check-manifest : MANIFEST
211         \$(check_manifest)
212
213 # the traditional way running per-*.t processes:
214 check-each :: pure_all
215         \$(EATMYDATA) \$(PROVE) --state=save -bvw -j\$(N)
216         -@\$(check_manifest)
217
218 # lightly-tested way to run tests, relies "--state=save" in check-each
219 # for best performance
220 check-run :: pure_all check-man
221         \$(EATMYDATA) \$(PROVE) -bvw t/run.perl :: -j\$(N)
222         -@\$(check_manifest)
223
224 check :: check-each
225
226 lib/PublicInbox/UserContent.pm :: contrib/css/216dark.css
227         \$(PERL) -I lib \$@ \$?
228
229 # Ensure new .pm files will always be installed by updating
230 # the timestamp of Makefile.PL which forces Makefile to be remade
231 Makefile.PL : MANIFEST
232         touch -r MANIFEST \$@
233         \$(PERLRUN) \$@
234
235 # Install symlinks to ~/bin (which is hopefuly in PATH) which point to
236 # this source tree.
237 # prefix + bindir matches git.git Makefile:
238 prefix = \$(HOME)
239 bindir = \$(prefix)/bin
240 symlink-install :
241         mkdir -p \$(bindir)
242         lei=\$\$(realpath lei.sh) && cd \$(bindir) && \\
243         for x in \$(EXE_FILES); do \\
244                 ln -sf "\$\$lei" \$\$(basename "\$\$x"); \\
245         done
246
247 update-copyrights :
248         \@case '\$(GNULIB_PATH)' in '') echo >&2 GNULIB_PATH unset; false;; esac
249         git ls-files | UPDATE_COPYRIGHT_HOLDER='all contributors' \\
250                 UPDATE_COPYRIGHT_USE_INTERVALS=2 \\
251                 xargs \$(GNULIB_PATH)/build-aux/update-copyright
252 EOF
253 }