xap_helper.h: fix CPP error on non-glibc
[public-inbox.git] / Makefile.PL
blob27fe02ff27135869a4e4fd11a64afcfc58048ff3
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 = {};
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);
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 \$@" ];
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 %native = (
38 XapHelperCxx => [ qw(xh_cidx.h xh_mset.h xap_helper.h) ],
40 my @ck_build;
41 for my $m (sort keys %native) {
42 my $hdr = $native{$m};
43 my @dep = map { "lib/PublicInbox/$_" } ("$m.pm", @$hdr);
44 $t->{"$m.check_build: @dep"} = [ "\$(PERL) -w -I lib ".
45 "-MPublicInbox::$m -e PublicInbox::${m}::check_build" ];
46 push @ck_build, "$m.check_build";
48 $t->{"check-build: @ck_build"} = [];
50 my @no_pod;
51 $v->{-m1} = [ map {
52 my $x = (split('/'))[-1];
53 my $pod = "Documentation/$x.pod";
54 if (-f $pod) {
55 $x;
56 } else {
57 warn "W: $pod missing\n";
58 push @no_pod, $x;
59 ();
61 } @EXE_FILES,
62 qw(
63 lei-add-external lei-add-watch lei-blob lei-config lei-convert
64 lei-daemon-kill lei-daemon-pid lei-edit-search lei-export-kw
65 lei-forget-external lei-forget-mail-sync lei-forget-search
66 lei-import lei-index lei-init lei-inspect lei-lcat
67 lei-ls-external lei-ls-label lei-ls-mail-source lei-ls-mail-sync
68 lei-ls-search lei-ls-watch lei-mail-diff lei-p2q lei-q
69 lei-rediff lei-refresh-mail-sync lei-reindex
70 lei-rm lei-rm-watch lei-tag
71 lei-up)];
72 $v->{-m5} = [ qw(public-inbox-config public-inbox-v1-format
73 public-inbox-v2-format public-inbox-extindex-format
74 lei-mail-formats lei-store-format
75 ) ];
76 $v->{-m7} = [ qw(lei-mail-sync-overview lei-overview lei-security
77 public-inbox-overview public-inbox-tuning
78 public-inbox-glossary) ];
79 $v->{-m8} = [ qw(public-inbox-daemon lei-daemon) ];
80 my @sections = (1, 5, 7, 8);
81 $v->{check_80} = [];
82 $v->{manuals} = [];
83 $v->{mantxt} = [];
84 for my $i (@sections) {
85 my $ary = $v->{"-m$i"};
86 $v->{"m$i"} = $ary;
87 for my $m (@$ary) {
88 my $pod = "Documentation/$m.pod";
89 my $txt = "Documentation/$m.txt";
90 $t->{"$m.$i : $pod"} = [ "\$(podman) -s$i $pod \$@" ];
91 $t->{"$txt : $m.$i"} = [ "\$(man2text) ./$m.$i >\$\@+",
92 "touch -r $pod \$\@+ ./$m.$i",
93 "mv \$\@+ \$@" ];
94 $t->{"Documentation/$m.html : $txt"} = [ "\$(txt2pre) <$txt",
95 "touch -r $txt \$@" ];
96 $t->{".$m.cols : $m.$i"} = [
97 "\@echo CHECK80 $m.$i; LC_ALL=C LANG=C ".
98 "COLUMNS=80 \$(MAN) ./$m.$i | \$(check_man)",
99 '>$@' ];
100 $t->{".$m.lexgrog: $m.$i"} = [
101 "\@echo LEXGROG $m.$i;" .
102 "\$(LEXGROG) ./$m.$i >\$\@+ && mv \$\@+ \$@" ];
104 push @{$v->{check_80}}, map { ".$_.cols" } @$ary;
105 push @{$v->{check_lexgrog}}, map { ".$_.lexgrog" } @$ary;
106 my $manuals = $v->{"man$i"} = [ map { "$_.$i" } @$ary ];
107 push @{$v->{manuals}}, @$manuals;
108 push @{$v->{mantxt}}, map { "Documentation/$_.txt" } @$ary;
110 $v->{docs} = [ @dtxt, 'NEWS' ];
111 $v->{docs_html} = [ map {;
112 my $x = $_;
113 $x =~ s/\.txt\z//;
114 "$x.html"
115 } (@{$v->{docs}}, @{$v->{mantxt}}) ];
116 $v->{gz_docs} = [ map { "$_.gz" } (@{$v->{docs}},@{$v->{docs_html}}) ];
117 $v->{rsync_docs} = [ @{$v->{gz_docs}}, @{$v->{docs}},
118 @{$v->{docs_html}}, qw(NEWS.atom NEWS.atom.gz)];
120 my $TGTS = join("\n", map {;
121 my $tgt_prereq = $_;
122 my $cmds = $t->{$_};
123 "$tgt_prereq\n".join('', map { "\t$_\n" } @$cmds);
124 } sort keys %$t);
126 my $VARS = join("\n", map {;
127 my $varname = $_;
128 join('', map { "$varname += $_\n" } sort @{$v->{$varname}});
129 } grep(!/^-/, sort keys %$v));
130 $VARS .= "\nRELEASES = ".join(' ', @RELEASES)."\n";
132 # Don't waste user's disk space by installing some pods from
133 # imported code or internal use only
134 my %man3 = map {; # semi-colon tells Perl this is a BLOCK (and not EXPR)
135 my $base = $_;
136 my $mod = $base;
137 $mod =~ s!/!::!g;
138 $mod =~ s/\.\w+\z//;
139 "lib/PublicInbox/$_" => "blib/man3/PublicInbox::$mod.\$(MAN3EXT)"
140 } qw(Git.pm Import.pm WWW.pod SaPlugin/ListMirror.pod);
141 my $warn_no_pod = @no_pod ? "\n\t\@echo W: missing .pod: @no_pod\n" : '';
142 chomp(my $lexgrog = `command -v lexgrog 2>/dev/null`);
143 my $check_lexgrog = $lexgrog ? 'check-lexgrog' : '';
145 WriteMakefile(
146 NAME => 'PublicInbox', # n.b. camel-case is not our choice
148 # XXX drop "PENDING" in .pod before updating this!
149 VERSION => '2.0.0.PENDING',
151 AUTHOR => 'public-inbox hackers <meta@public-inbox.org>',
152 ABSTRACT => 'an "archives first" approach to mailing lists',
153 EXE_FILES => \@EXE_FILES,
155 # DO NOT blindly put "use v5.12" in *.pm files, unicode_strings
156 # causes known breakages. "use v5.10.1" is safe, though
157 MIN_PERL_VERSION => '5.12.0',
158 LICENSE => 'agpl_3', # AGPL-3.0+, CPAN::Meta::Spec doesn't have '+'
159 PREREQ_PM => {
160 # note: we use spamc(1), NOT the Perl modules
161 # We also depend on git.
162 # Keep this sorted and synced to the INSTALL document
164 # perl-modules-5.xx or libperl5.xx in Debian-based
165 # part of "perl5" on FreeBSD
166 'autodie' => 0, # rpm: perl-autodie
167 'Compress::Raw::Zlib' => 0, # rpm: perl-Compress-Raw-Zlib
168 'Compress::Zlib' => 0, # rpm: perl-IO-Compress
169 'Data::Dumper' => 0, # rpm: perl-Data-Dumper
170 'Digest::SHA' => 0, # rpm: perl-Digest-SHA
171 'IO::Compress::Gzip' => 0, # rpm: perl-IO-Compress
172 'IO::Uncompress::Gunzip' => 0, # rpm: perl-IO-Compress
173 'Sys::Syslog' => 0, # rpm: perl-Sys-Syslog
174 'Text::ParseWords' => 0, # rpm: perl-Text-ParseWords
176 # Plack is needed for public-inbox-httpd and PublicInbox::WWW
177 # 'Plack' => 0,
179 'URI' => 0,
181 # We have more test dependencies, but do not force
182 # users to install them. See INSTALL
184 # All Perl installs I know about have these, but RH-based
185 # distros can separate these even if `perl' depends on them:
186 'constant' => 0, # rpm: perl-constant
187 'Encode' => 2.35, # rpm: perl-Encode # 2.35 shipped with 5.10.1
188 'File::Path' => 0,
189 'File::Temp' => '0.19', # for ->tmpdir support
190 'Getopt::Long' => 0, # rpm: perl-Getopt-Long
191 'Exporter' => 0, # rpm: perl-Exporter
192 'IO::Poll' => 0,
193 'Storable' => 0, # rpm: perl-Storable
194 'Time::HiRes' => 0, # rpm: perl-Time-HiRes
195 # ExtUtils::MakeMaker # this file won't run w/o it...
197 MAN3PODS => \%man3,
198 clean => {
199 FILES => 't/home*/setup* t/home*/t* t/home*/.public-inbox '.
200 't/data-gen/*'
202 PM => {
203 map {
204 s[^lib/][]s;
205 +('lib/' . $_ => '$(INST_LIB)/' . $_);
206 } grep {
207 # Will include *.pod and an *.h file, but so
208 # would ExtUtils::MakeMaker.
209 m[^lib/];
210 } @manifest
214 sub MY::postamble {
215 my $N = (`{ getconf _NPROCESSORS_ONLN ||
216 getconf NPROCESSORS_ONLN; } 2>/dev/null` || 1);
217 $N += 1; # account for sleeps in some tests (and makes an IV)
218 <<EOF;
219 PROVE = prove
220 # support using eatmydata to speed up tests (apt-get install eatmydata):
221 # https://www.flamingspork.com/projects/libeatmydata/
222 EATMYDATA =
223 N = $N
224 -include config.mak
225 $VARS
226 -include Documentation/include.mk
227 $TGTS
229 check-man : $check_lexgrog$warn_no_pod
231 # syntax checks are currently GNU make only:
232 %.syntax :: %
233 @\$(PERL) -w -I lib -c \$<
235 syntax:: \$(my_syntax)
237 changed = \$(shell git ls-files -m)
238 dsyn :: \$(addsuffix .syntax, \$(filter \$(changed), \$(syn_files)))
240 check_manifest := if test -e .git && git ls-files >MANIFEST.gen 2>&1; then \\
241 diff -u MANIFEST MANIFEST.gen; fi
243 check-manifest : MANIFEST
244 \$(check_manifest)
246 # the traditional way running per-*.t processes:
247 check-each : pure_all
248 \$(EATMYDATA) \$(PROVE) --state=save -bvw -j\$(N)
249 -@\$(check_manifest)
251 # check-run relies "--state=save" in check-each for best performance
252 check-run : check-man
254 # n.b. while `-' isn't specified as an allowed make(1posix) macro name,
255 # GNU and *BSD both allow it.
256 check-run_T_ARGS = -j\$(N)
258 check-xh0 :
259 \$(MAKE) check-run TEST_DAEMON_XH='-X0'
261 check-xh1 :
262 \$(MAKE) check-run TEST_DAEMON_XH='-X1'
264 check-debris check-run : pure_all
265 \$(EATMYDATA) \$(PROVE) -bvw xt/\$@.t :: \$(\$\@_T_ARGS)
266 -@\$(check_manifest)
268 check : check-each
270 lib/PublicInbox/UserContent.pm : contrib/css/216dark.css
271 \$(PERL) -I lib \$@ \$?
273 # Ensure new .pm files will always be installed by updating
274 # the timestamp of Makefile.PL which forces Makefile to be remade
275 Makefile.PL : MANIFEST
276 touch -r MANIFEST \$@
277 \$(PERLRUN) \$@
279 # Install symlinks to ~/bin (which is hopefuly in PATH) which point to
280 # this source tree.
281 # prefix + bindir matches git.git Makefile:
282 prefix = \$(HOME)
283 bindir = \$(prefix)/bin
284 symlink-install : lib/PublicInbox.pm
285 mkdir -p \$(bindir)
286 lei="\$(PWD)/lei.sh" && cd \$(bindir) && \\
287 for x in \$(EXE_FILES); do \\
288 ln -sf "\$\$lei" \$\$(basename "\$\$x"); \\
289 done
291 pm_to_blib : lib/PublicInbox.pm
292 lib/PublicInbox.pm : FORCE
293 VERSION=\$(VERSION) \$(PERL) -w ./version-gen.perl
295 XH_TESTS = t/xap_helper.t t/cindex.t
297 test-asan : pure_all
298 TEST_XH_CXX_ONLY=1 CXXFLAGS='-Wall -ggdb3 -fsanitize=address' \\
299 prove -bvw \$(XH_TESTS)
301 VG_OPT = -v --trace-children=yes --track-fds=yes
302 VG_OPT += --leak-check=yes --track-origins=yes
303 test-valgrind : pure_all
304 TEST_XH_CXX_ONLY=1 VALGRIND="valgrind \$(VG_OPT)" \\
305 prove -bvw \$(XH_TESTS)