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