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