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