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