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