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