forked from apache/spamassassin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.PL
1202 lines (993 loc) · 36.8 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
require v5.14.0;
use strict;
use warnings;
use Config;
use ExtUtils::MakeMaker 6.64;
# raising the version of makemaker to 6.64 to use TEST_REQUIRES
use constant MIN_MAKEMAKER_VERSION => 6.64;
use constant RUNNING_ON_WINDOWS => ($^O =~ /^(mswin|dos|os2)/oi);
use constant HAS_DBI => eval { require DBI; };
my @ATT_KEYS = (
# PLEASE READ THE FILE 'PACKAGING' FOR INFORMATION ON THESE VARIABLES.
#
# (Current) EU::MMs make a difference between these three possible general
# install destinations. One can set INSTALLDIRS to 'perl', 'site' or
# 'vendor' to choose one explicitly (the default is 'site'). They have the
# following meaning:
# * PERL: Only essential modules shipped with Perl should be installed
# there. Don't put Apache SpamAssassin there.
# * SITE: The default. Normal installations via CPAN or from the sources
# should use these dirs.
# * VENDOR: A special set of paths for packaged (RPM, deb, portage, ...)
# Perl modules. Not always (correctly) used but the intention
# is to keep the system from overwriting the modules installed
# by the user.
#
# See also
# <http://search.cpan.org/author/MSCHWERN/ExtUtils-MakeMaker-6.16/lib/ExtUtils/MakeMaker.pm#Default_Makefile_Behaviour>
# <http://www.debian.org/doc/packaging-manuals/perl-policy/ch-module_packages.html#s-vendor_dirs>
# <http://archive.develooper.com/[email protected]/msg94113.html>
# <https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=78053>
# <http://www.mail-archive.com/[email protected]/msg00779.html>
#
# The options SYSCONFDIR, DATADIR and CONFDIR all support those three
# possibilities. The '*' in the following comments refers to those.
'SYSCONFDIR', # Overwrite all $*SYSCONFDIRs; normally determined
'PERLSYSCONFDIR', # based on $*PREFIX.
'SITESYSCONFDIR', #
'VENDORSYSCONFDIR', #
'DATADIR', # Overwrite all INSTALL*DATAs; normally determined
'INSTALLDATA', # based on $*PREFIX.
'INSTALLSITEDATA', #
'INSTALLVENDORDATA',#
'CONFDIR', # Overwrite all INSTALL*CONFs; normally determined
'INSTALLCONF', # based on $*SYSCONFDIR.
'INSTALLSITECONF', #
'INSTALLVENDORCONF',#
'DEFRULESDIR', # A synonym for 'DATADIR'.
'LOCALRULESDIR', # " " " 'CONFDIR'.
'LOCALSTATEDIR', # normally determined based on $*PREFIX.
'PERLLOCALSTATEDIR',
'SITELOCALSTATEDIR',
'VENDORLOCALSTATEDIR',
'RE2C_BIN', # hard code the path for re2c if possible
'PERL_BIN', # Sets the Perl interpreter used by the scripts.
'PERL_WARN', # Can be used to disable warnings in the scripts
'PERL_TAINT', # " " " " " taint mode for the scripts (DON'T)
'BUILD_SPAMC' , # Set to 'no' to skip build of spamc on Windows.
'BUILD_SPAMD', # Set to 'no' to skip build of spamd on Windows.
'ENABLE_SSL', # Set to 'yes' to build spamc with SSL support.
'CONTACT_ADDRESS', # To not ask for the contact address, use this.
);
sub parse_arg {
my($val, $name) = (@_);
if ($val =~ /^($name)=["']?(.*?)["']?$/) {
return $2;
} else {
return undef;
}
}
sub bool {
my($val, $def) = (@_, undef, undef);
$def = 0 unless defined $def;
return bool($def) unless defined $val;
$val =~ s/^\s+|\s+$//g;
return 0 if $val =~ /^(0|N(o)?|Off)$/i;
return 1 if $val =~ /^(1|Y(es)?|On)$/i;
return bool($def);
}
sub yesno {
my($val, $def) = (@_, undef, undef);
return 'yes' if bool($val, $def);
return 'no';
}
my %opt = (
'build_spamc' => undef,
'build_spamd' => undef,
'enable_ssl' => undef,
'contact_address' => undef,
'destdir' => undef,
're2c_bin' => 're2c',
);
ARGV: foreach (@ARGV) {
foreach my $key (keys %opt) {
my $val = parse_arg($_, uc($key));
if (defined $val) {
$opt{$key} = $val;
next ARGV;
}
}
}
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
my %makefile = (
'NAME' => 'Mail::SpamAssassin',
'VERSION_FROM' => 'lib/Mail/SpamAssassin.pm', # finds $VERSION
# This is not the standard EU::MM array, we use a hash instead (which
# will be converted later on). Use the source file name as the key and
# the executable as the value.
'EXE_FILES' => {
'spamassassin.raw' => 'spamassassin',
'sa-learn.raw' => 'sa-learn',
'sa-update.raw' => 'sa-update',
'sa-compile.raw' => 'sa-compile',
'sa-awl.raw' => 'sa-awl',
'sa-check_spamd.raw' => 'sa-check_spamd',
'spamc/spamc.c' => 'spamc/spamc$(EXE_EXT)',
'spamd/spamd.raw' => 'spamd/spamd',
},
# TODO: the rule compilation is hooked into the build step for "sa-update"
# as the make target "build_rules".
# This is kludgy, and it'd be nice to find a cleaner way to do this.
'MAN1PODS' => {
'spamassassin' => '$(INST_MAN1DIR)/spamassassin.$(MAN1EXT)',
'lib/spamassassin-run.pod' => '$(INST_MAN1DIR)/spamassassin-run.$(MAN1EXT)',
'sa-learn' => '$(INST_MAN1DIR)/sa-learn.$(MAN1EXT)',
'sa-update' => '$(INST_MAN1DIR)/sa-update.$(MAN1EXT)',
'sa-compile' => '$(INST_MAN1DIR)/sa-compile.$(MAN1EXT)',
'sa-awl' => '$(INST_MAN1DIR)/sa-awl.$(MAN1EXT)',
'sa-check_spamd' => '$(INST_MAN1DIR)/sa-check_spamd.$(MAN1EXT)',
'spamc/spamc.pod' => '$(INST_MAN1DIR)/spamc.$(MAN1EXT)',
'spamd/spamd' => '$(INST_MAN1DIR)/spamd.$(MAN1EXT)',
},
'PL_FILES' => { },
'PMLIBDIRS' => [ 'lib' ],
'PM_FILTER' => '$(PREPROCESS) -Mconditional -Mvars -DVERSION="$(VERSION)" \
-DPREFIX="$(I_PREFIX)" \
-DDEF_RULES_DIR="$(I_DATADIR)" \
-DLOCAL_RULES_DIR="$(I_CONFDIR)" \
-DLOCAL_STATE_DIR="$(I_LOCALSTATEDIR)"',
'macro' => {
DATAFILES => 'user_prefs.template languages sa-update-pubkey.txt'
},
# be quite explicit about this; afaik CPAN.pm is sensible using this
'PREREQ_PM' => {
'File::Spec' => 0.8, # older versions lack some routines we need
'File::Copy' => 2.02, # this version is shipped with 5.005_03, the oldest version known to work
'Pod::Usage' => 1.10, # all versions prior to this do seem to be buggy
'HTML::Parser' => 3.43, # the HTML code is based on this parser, older versions have utf-8 bugs
'Archive::Tar' => 1.23, # for sa-update
'IO::Zlib' => 1.04, # for sa-update
'Mail::DKIM' => 0.31,
'Net::DNS' => 0.69,
'NetAddr::IP' => 4.010,
'Sys::Hostname' => 0,
'Time::HiRes' => 0,
'Time::Local' => 0,
'Errno' => 0,
},
# In case MIN_MAKEMAKER_VERSION is greater than the version bundled in the core of MIN_PERL_VERSION
# use this to ensure CPAN will automatically upgrade MakeMaker if needed
'BUILD_REQUIRES' => {
'ExtUtils::MakeMaker' => MIN_MAKEMAKER_VERSION,
},
'CONFIGURE_REQUIRES' => {
'ExtUtils::MakeMaker' => MIN_MAKEMAKER_VERSION,
},
# The modules that are not core or that require a minimum version that are used in default tests
'TEST_REQUIRES' => {
'Devel::Cycle' => 0,
'Test::Simple' => 1.302067,
'Text::Diff' => 0,
'Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict' => 0,
'Perl::Critic::Policy::Perlsecret' => 0,
},
'dist' => {
COMPRESS => 'gzip -9f',
SUFFIX => '.gz',
TARFLAGS => 'cf',
DIST_DEFAULT => 'tardist',
CI => 'svn commit',
RCS_LABEL => 'true',
},
'clean' => { FILES => join(' ' =>
'sa-learn', 'sa-update', 'spamassassin', 'sa-compile', 'sa-awl', 'sa-check_spamd',
'spamd/spamd',
'spamc/spamc$(EXE_EXT)',
'spamc/spamc.h',
'spamc/qmail-spamc$(EXE_EXT)',
'spamc/*.o*', 'spamc/replace/*.o*',
'spamc/*.so',
'spamc/Makefile',
'spamc/config.h', 'spamc/version.h', 'spamc/spamc.h',
'spamc/config.status', 'spamc/*.cache', 'spamc/config.log',
'spamd/*spamc*', 'qmail',
'doc', 'pod2htm*', '*.cache',
'version.env',
't/bayessql.cf', 't/do_net', 't/log', 't/sql_based_whitelist.cf',
'rules/*.pm',
'rules/70_sandbox.cf',
'rules/72_active.cf',
'rules/70_inactive.cf',
)
},
'AUTHOR' => 'The Apache SpamAssassin Project <dev at spamassassin.apache.org>',
'ABSTRACT' => 'Apache SpamAssassin is an extensible email filter which is used to identify spam',
# We have only this Makefile.PL and this option keeps MakeMaker from
# asking all questions twice after a 'make dist*'.
'NORECURS' => 1,
'MIN_PERL_VERSION'=> 5.014000,
);
# rules/72_active.cf is built from "rulesrc", but *must* exist before
# WriteMakefile() is called due to shortcomings in MakeMaker.
my @FILES_THAT_MUST_EXIST = qw(
rules/72_active.cf
);
# All the $(*MAN1*) stuff is empty/zero if Perl was Configured with -Dman1dir=none;
# however, support site/vendor man1 dirs (bug 5338)
unless($Config{installman1dir}
|| $Config{installsiteman1dir}
|| $Config{installvendorman1dir})
{
warn "not installing man pages in man1; no man1 dir found";
delete $makefile{MAN1PODS};
}
# Windows platforms need some adjustments
if (RUNNING_ON_WINDOWS) {
# Building spamd is optional on Windows because it still is somewhat
# experimental.
if (!defined $opt{'build_spamd'}) {
$opt{'build_spamd'} = bool(prompt(
"Build spamd.exe (experimental on windows platforms)? (y/n)",
'n'));
} else {
$opt{'build_spamd'} = bool($opt{'build_spamd'});
}
if (!$opt{'build_spamd'}) {
delete $makefile{EXE_FILES}{'spamd/spamd.raw'};
delete $makefile{MAN1PODS}{'spamd/spamd'};
}
# building spamc is optional under Win32 because not everyone has compiler
if (!defined $opt{'build_spamc'}) {
$opt{'build_spamc'} = bool(prompt(
"Build spamc.exe (environment must be set up for C compiler)? (y/n)",
'n'));
} else {
$opt{'build_spamc'} = bool($opt{'build_spamc'});
}
if (!$opt{'build_spamc'}) {
delete $makefile{EXE_FILES}{'spamc/spamc.c'};
delete $makefile{MAN1PODS}{'spamc/spamc.pod'};
}
}
$makefile{'macro'}{'ENABLE_SSL'} = yesno($opt{'enable_ssl'});
if (!defined $opt{'contact_address'}) {
$opt{'contact_address'} = prompt(
"What email address or URL should be used in the suspected-spam report\n".
"text for users who want more information on your filter installation?\n".
"(In particular, ISPs should change this to a local Postmaster contact)\n".
"default text:", "the administrator of that system"
);
print "\n";
}
$makefile{'macro'}{'CONTACT_ADDRESS'} = $opt{'contact_address'};
print
'NOTE: settings for "make test" are now controlled using "t/config.dist".
See that file if you wish to customize what tests are run, and how.
';
# check optional module versions
use lib 'lib';
require Mail::SpamAssassin::Util::DependencyInfo;
if (Mail::SpamAssassin::Util::DependencyInfo::long_diagnostics(1) != 0) {
# This prints a full report of missing required and optional modules and binaries
# but only exit 0 without creating Makefile if there are missing required binaries.
# See http://cpantest.grango.org/wiki/CPANAuthorNotes
# Continuing when there are missing required CPAN modules allows cpan to install them
# before it runs make on the Makefile
exit 0;
}
foreach my $file (@FILES_THAT_MUST_EXIST) {
open (TOUCH, ">>$file") or die "cannot touch '$file'";
close TOUCH;
}
#######################################################################
# See Bug 6131 & 6598 for changes to META_MERGE and increased requirement
# for MakeMaker version
#
$makefile{META_MERGE} = {
'meta-spec' => {
version => '2',
url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
},
license => 'apache_2_0',
resources => {
license => 'http://www.apache.org/licenses/LICENSE-2.0.html',
homepage => 'https://spamassassin.apache.org/',
bugtracker => 'https://issues.apache.org/SpamAssassin/',
repository => {
url=>'http://svn.apache.org/repos/asf/spamassassin/',
type=>'svn'
},
MailingList => 'http://wiki.apache.org/spamassassin/MailingLists',
},
prereqs => {
runtime => {
recommends => {
'MIME::Base64' => 0,
'DB_File' => 0,
'Net::SMTP' => 0,
'Net::LibIDN2' => 0,
'Net::LibIDN' => 0,
'Mail::SPF' => 0,
'MaxMind::DB::Reader' => 0,
'MaxMind::DB::Reader::XS' => 0,
'Geo::IP' => 0,
'IP::Country::DB_File' => 0,
'IP::Country::Fast' => 0,
'Razor2::Client::Agent' => 2.61,
'IO::Socket::IP' => 0.09,
'IO::Socket::INET6' => 0,
'IO::Socket::SSL' => 1.76,
'Compress::Zlib' => 0,
'Mail::DKIM' => 0.37,
'DBI' => 0,
'DBD::SQLite' => 1.59_01,
'LWP::UserAgent' => 0,
'Encode::Detect::Detector' => 0,
'Net::Patricia' => 1.16,
'Net::CIDR::Lite' => 0,
'BSD::Resource' => 0,
'Archive::Zip' => 0,
'IO::String' => 0,
'Email::Address::XS' => 0,
'Mail::DMARC' => 0,
},
},
test => {
recommends => {
'Net::DNS::Nameserver' => 0,
},
},
},
};
#######################################################################
# Now finish the meta hash and dump the Makefile
$makefile{EXE_FILES} = [ values %{$makefile{EXE_FILES}} ];
$makefile{AUTHOR} =~ s/(<.+) at (.+>)/$1\@$2/;
WriteMakefile(%makefile);
print "Makefile written by ExtUtils::MakeMaker $ExtUtils::MakeMaker::VERSION\n";
#######################################################################
package MY;
our ($MY_GLOBALS_ARE_SANE,
$RUNNING_ON_WINDOWS,
@REPOSITORIES,
$MACRO_RE,
$EQ_RE,
$EQ,
$SELF);
# For some reason initializing the vars on the global scope doesn't work;
# guess its some weird Perl behaviour in combination with bless().
sub init_MY_globals {
my $self = shift;
# Keep a reference to ourselves so we don't have to feed it to the helper
# scripts.
$SELF = $self;
return if $MY_GLOBALS_ARE_SANE;
$MY_GLOBALS_ARE_SANE = 1;
# (Current) EU::MMs make a difference between these three possible general
# install destinations. See also
# <http://archive.develooper.com/[email protected]/msg94113.html>
# <https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=78053>
# <http://www.mail-archive.com/[email protected]/msg00779.html>
# <http://www.debian.org/doc/packaging-manuals/perl-policy/ch-module_packages.html#s-vendor_dirs>
@REPOSITORIES = qw(
PERL
SITE
VENDOR
);
# Macro names follow this RE -- at least stricly enough for our purposes.
$MACRO_RE = qr/[A-Z0-9_]+/;
# Normally macros are assigned via FOO = bar. But the part with the equal
# sign might differ from platform to platform. So we use this RE:
$EQ_RE = qr/\s*:?=\s*/;
# To assign or own macros we'll follow the first assignment string we find;
# normally " = ".
$EQ = undef;
# Inherit our Windows-Flag.
$RUNNING_ON_WINDOWS = ::RUNNING_ON_WINDOWS;
}
# Unset $SELF to avoid any leaking memory.
sub clean_MY_globals {
my $self = shift;
$SELF = undef;
}
sub set_EQ_from_line {
my($line) = (@_);
return if defined($EQ);
$line =~ /\S(${EQ_RE})/;
$EQ = $1;
}
# Converts a version represented as a float to a real three-part version,
# eg.:
# 5.006001 -> 5.6.1
# 5.005_03 -> 5.5.30
#
# The first parameter should be a version, in what format ever.
sub float_to_version {
my($ver) = (@_);
if ($ver =~ /^\d\.\d+$/) {
$ver = sprintf("%1.6f", $ver);
$ver =~ s/[.0]+([1-9]+)/.$1/g;
}
return $ver;
}
# Generates a Makefile-reference to another macro; something like $(FOO).
#
# The first and only parameter should be the name of the referred macro,
# eg. 'FOO' (will return '$(FOO)').
sub macro_ref {
my($name) = (@_);
return sprintf('$(%s)', $name);
}
# Generates a line which defines a Makefile macro. Something like FOO = bar.
# The line is *not* followed by a newline!
#
# The first parameter must be the name of the macro. The second is optional.
# If it is omitted, the value set in the current EU::MM instance is used.
sub macro_def {
my($name, $val) = (@_, undef);
my $MUST_NOT_HAPPEN = "THIS MUST NOT HAPPEN. PLEASE REPORT A BUG VIA <https://issues.apache.org/SpamAssassin/>";
die $MUST_NOT_HAPPEN unless defined $name;
die $MUST_NOT_HAPPEN unless defined $EQ;
$val = $SELF->{$name} unless defined $val;
return $name . $EQ . $val;
}
# Returns true if the given line defines a macro.
#
# The first parameter must be the line to inspect. With the second optional
# parameter the name of a specific macro might be given. If its omitted, any
# macro matching the MACRO_RE pattern will fit.
sub line_has_macro_def {
my($line, $name) = (@_, undef);
$name = $MACRO_RE unless defined $name;
return $line =~ /^($name)${EQ_RE}/;
}
# Reads the name of the macro defined on the given line.
#
# The first parameter must be the line to be expected. If the line doesn't
# contain a macro definition, weird things may happen. So check with
# line_has_macro_def() before!
sub get_macro_name_from_line {
my($line) = (@_);
$line =~ /^(${MACRO_RE})${EQ_RE}/;
return $1;
}
# Reads the value of the given macro from the current instance of EU::MM.
#
# The first parameter must be the name of a macro.
sub get_macro {
my($name) = (@_);
return $SELF->{$name};
}
# Reads the value of the given macro from the current instance of EU::MM and
# expands all contained macros. So reading BAZ with these declarations
# FOO = blah
# BAR = $(FOO)
# BAZ = $(BAR)
# gives 'blah'.
#
# The first parameter must be the name of a macro.
sub get_expanded_macro {
my($name) = (@_);
my($val);
$val = get_macro($name);
# Now expand all macros...
while ($val =~ s/\Q$(\E(${MACRO_RE})\Q)\E/$SELF->{$1} || ''/ge) {};
return $val;
}
# Sets the value of the macro with the given name to the given value in the
# current instance of EU::MM. Just sets, doesn't write to the Makefile!
#
# The first parameter must be the macro's name, the second the value.
sub set_macro {
my($name, $val) = (@_);
$SELF->{$name} = $val;
}
# Returns the actual "repository" name used in macro names; the point is that
# EU::MM leaves out the name if the repository is 'PERL'. But only for macros
# which don't start with the repository name (like the INSTALL* ones). So the
# following mapping should be made:
# PERLPREFIX -> PERLPREFIX
# PERLSYSCONFDIR -> PERLSYSCONFDIR
# INSTALLSITECONF -> INSTALLSITECONF
# INSTALLPERLCONF -> INSTALLCONF
# Actually, its a bit more complex than that but we follow that simple mapping
# for our vars; one also has to know when to call this function and when not.
# If the second parameter is set, always the PERL variant is used.
sub repository {
my($repository, $default) = (@_);
return '' if $default;
return '' if $repository eq 'PERL';
return $repository;
}
# This routine determines the correct SYSCONFDIR to use for the given
# repository.
#
# The first parameter must be one value from @REPOSITORIES.
#
# *SYSCONFDIR can be overwritten with:
# *SYSCONFDIR
# SYSCONFDIR
# If none of those is specified, it will chose an FHS-compliant dir
# based on the corresponding *PREFIX:
# *PREFIX *SYSCONFDIR
# /usr /etc
# /usr/local /etc
# /opt/* /etc/opt
# /foo/* /foo/*/etc
sub _set_macro_SYSCONFDIR {
my($repository) = (@_);
my($macro);
$macro = $repository . "SYSCONFDIR";
# Is this macro already set?
return if get_macro($macro);
# Is this macro supposed to be overwritten?
if (get_macro('SYSCONFDIR')) {
set_macro($macro, macro_ref('SYSCONFDIR'));
return;
}
my($rprefix);
$rprefix = get_expanded_macro("${repository}PREFIX");
# Set the default, depending on the corresponding full PREFIX
set_macro($macro,
($rprefix =~ m{^$}) ? '' :
($rprefix =~ m{^/usr(/local)?/?$}) ? '/etc' :
($rprefix =~ m{^/opt(/|$)}) ? '/etc/opt' :
macro_ref("${repository}PREFIX") . '/etc'
);
}
# This routine determines the correct LOCALSTATEDIR to use for the given
# repository.
#
# The first parameter must be one value from @REPOSITORIES.
#
# *LOCALSTATEDIR can be overwritten with:
# *LOCALSTATEDIR
# LOCALSTATEDIR
# If none of those is specified, it will chose an FHS-compliant dir
# based on the corresponding *PREFIX:
# *PREFIX *LOCALSTATEDIR
# /usr /etc
# /usr/local /etc
# /opt/* /etc/opt
# /foo/* /foo/*/etc
sub _set_macro_LOCALSTATEDIR {
my($repository) = (@_);
my($macro);
$macro = $repository . "LOCALSTATEDIR";
# Is this macro already set?
return if get_macro($macro);
# Is this macro supposed to be overwritten?
if (get_macro('LOCALSTATEDIR')) {
set_macro($macro, macro_ref('LOCALSTATEDIR'));
return;
}
my($rprefix);
$rprefix = get_expanded_macro("${repository}PREFIX");
# Set the default, depending on the corresponding full PREFIX
set_macro($macro,
($rprefix =~ m{^$}) ? '' :
($rprefix =~ m{^/usr(/local)?/?$}) ? '/var/lib/spamassassin' :
($rprefix =~ m{^/opt(/|$)}) ? '/var/opt/spamassassin' :
macro_ref("${repository}PREFIX") . '/var/spamassassin'
);
}
# This routine determines the correct INSTALLDATADIR (aka DEFRULESDIR)
# to use for the given repository.
#
# The first parameter must be one value from @REPOSITORIES.
#
# INSTALL*DATADIR can be overwritten with:
# INSTALL*DATADIR
# DATADIR
# DEFRULESDIR
# If none of those is specified, it will chose an FHS-compliant dir,
# namely *PREFIX/share/spamassassin.
sub _set_macro_DATADIR {
my($repository) = (@_);
my($macro);
$macro = "INSTALL" . repository($repository) . "DATA";
# Is this macro already set?
return if get_macro($macro);
# Is this macro supposed to be overwritten?
foreach my $omacro (qw(DATADIR DEFRULESDIR)) {
if (get_macro($omacro)) {
set_macro($macro, get_macro($omacro));
return;
}
}
# Set the default value based on the corresponding PREFIX
set_macro($macro,
macro_ref("${repository}PREFIX") . '/share/spamassassin'
);
}
# This routine determines the correct INSTALLCONFDIR (aka LOCALRULESDIR)
# to use for the given repository.
#
# The first parameter must be one value from @REPOSITORIES.
#
# INSTALL*CONFDIR can be overwritten with:
# INSTALL*CONFDIR
# CONFDIR
# LOCALRULESDIR
# If none of those is specified, it will chose an FHS-compliant dir,
# namely *SYSCONFDIR/mail/spamassassin.
sub _set_macro_CONFDIR {
my($repository) = (@_);
my($macro);
$macro = "INSTALL" . repository($repository) . "CONF";
# Is this macro already set?
return if get_macro($macro);
# Is this macro supposed to be overwritten?
foreach my $omacro (qw(CONFDIR LOCALRULESDIR)) {
if (get_macro($omacro)) {
set_macro($macro, get_macro($omacro));
return;
}
}
# Set the default value based on the corresponding SYSCONFDIR
set_macro($macro,
macro_ref("${repository}SYSCONFDIR") . '/mail/spamassassin'
);
}
# This routine determines the correct value for PERL_BIN.
#
# There are no parameters.
#
# If PERL_BIN wasn't set at the command line, it will fall back to
# $(FULLPERL) which should refer to the current Perl interpreter.
sub _set_macro_PERL_BIN {
return if get_macro('PERL_BIN');
set_macro('PERL_BIN', macro_ref('FULLPERL'));
}
# This is a helper routine for PERL_WARN and PERL_TAINT.
#
# The first parameter must be either 'WARN' or 'TAINT'.
sub _set_macro_PERL_yesno {
my($macro) = (@_);
my($val);
$macro = 'PERL_' . $macro;
$val = "";
if (get_macro($macro)) {
$val = ::yesno(get_macro($macro));
}
set_macro($macro, $val);
}
# This routine sets the value for PERL_WARN.
#
# There are no parameters.
#
# If PERL_WARN wasn't set at the command line, PERL_WARN will be left
# empty (ie: the default is used). If it was set, the value is fed to
# yesno().
sub _set_macro_PERL_WARN {
_set_macro_PERL_yesno('WARN');
}
# This routine sets the value for PERL_TAINT.
#
# There are no parameters.
#
# If PERL_TAINT wasn't set at the command line, PERL_TAINT will be left
# empty (ie: the default is used). If it was set, the value is fed to
# yesno().
sub _set_macro_PERL_TAINT {
_set_macro_PERL_yesno('TAINT');
}
# This routine sets the value for PREPROCESS.
#
# There are no parameters.
#
# If PREPROCESS wasn't set at the command line, it chooses our default
# perl-called preprocessor.
sub _set_macro_PREPROCESS {
return if get_macro('PREPROCESS');
# Bug 8038 - work around quirk of newer Extutils::MakeMaker on Windows with dmake
my $perl_bin = get_expanded_macro('FULLPERL');
if ($RUNNING_ON_WINDOWS and ($::Config{make} eq 'dmake') and ($perl_bin =~ /^([a-zA-Z]:)?\\"(.*)$/)) {
$perl_bin = "\"$1\\$2";
} else {
$perl_bin = macro_ref('PERL_BIN');
}
set_macro('PREPROCESS', join(' ', $perl_bin, qq{build/preprocessor}));
}
# This routine sets the value for CONFIGURE (spamc only).
#
# There are no parameters.
#
# If CONFIGURE wasn't set at the command line, it chooses our default
# perl-wrapped configure.
sub _set_macro_CONFIGURE {
return if get_macro('CONFIGURE');
set_macro('CONFIGURE', join(' ', macro_ref('PERL_BIN'), qq{spamc/configure.pl}));
}
# This routine sets the value for the SYMLINK command.
#
# There are no parameters.
#
# $(SYMLINK) calls Perl's symlink() function if available, else falls back
# to $(CP).
sub _set_macro_SYMLINK {
return if get_macro('SYMLINK');
if (eval { symlink("", "") or 1 }) {
my $code = q{symlink((splitpath($ARGV[0]))[2], $ARGV[1]) || die qq{$!\n}};
$code =~ s/(\$)/$1$1/g;
$code = qq{'$code'};
set_macro('SYMLINK', join(' ', macro_ref('PERL_BIN'), q{-MFile::Spec::Functions=splitpath}, q{-e}, $code));
}
else {
set_macro('SYMLINK', macro_ref('CP'));
}
}
# Override the libscan routine so it skips SVN/CVS stuff and some common
# patch/backup extensions.
sub MY::libscan {
my $self = shift;
my($path) = @_;
init_MY_globals($self);
return q{} if $path =~ m{
(^|/)(CVS|\.svn)(/|$)|
[/.](orig|old|rej|r\d+|diff|patch|bak|backup|mine|my|swp)$
}ix;
clean_MY_globals($self);
return $path; #/
}
# Override the install routine to add our additional install dirs and
# hack DESTDIR support into old EU::MMs.
sub MY::install {
my $self = shift;
my @code = split(/\n/, $self->SUPER::install(@_));
init_MY_globals($self);
foreach (@code) {
# Add our install targets as a dependency to all top-level install targets
s/^(install(?:_[a-z]+)?\s*::?\s*.*)$/$1 conf__install data__install/;
}
clean_MY_globals($self);
return join("\n", @code);
}
# Now override the constants routine to add our own macros.
sub MY::constants {
my $self = shift;
my @code = split(/\n/, $self->SUPER::constants(@_));
init_MY_globals($self);
foreach my $line (@code) {
# Skip comments
next if $line =~ /^\s*#/;
# Skip everything which isn't a var assignment.
next unless line_has_macro_def($line);
# Store the assignment string if necessary.
set_EQ_from_line($line);
# Store a nicer version string for later use.
if (line_has_macro_def($line, 'VERSION')) {
get_macro('VERSION') =~ /^(\d)\.(\d\d\d)_?(\d\d\d)/;
set_macro('VERSION_COOL', join(".", $1*1, $2*1, $3*1));
$line .= "\n" . macro_def('VERSION_COOL');
}
# Add some "dummy" (PERL|SITE|VENDOR)PREFIX macros for later use (only if
# necessary for old EU::MMs of course)
if (line_has_macro_def($line, 'PREFIX')) {
foreach my $r (@REPOSITORIES) {
my $rprefix = "${r}PREFIX";
if (!defined(get_macro($rprefix))) {
set_macro($rprefix, macro_ref('PREFIX'));
$line .= "\n" . macro_def($rprefix);
}
}
}
}
push(@code, qq{});
# Add some additional target dirs
{
set_macro('SYSCONFDIR', "") unless get_macro('SYSCONFDIR');
set_macro('LOCALSTATEDIR', "") unless get_macro('LOCALSTATEDIR');
set_macro('RE2C_BIN', $opt{'re2c_bin'});
# Determine the correct settings for each repository...
foreach my $r (@REPOSITORIES) {
_set_macro_SYSCONFDIR($r);
_set_macro_LOCALSTATEDIR($r);
_set_macro_DATADIR($r);
_set_macro_CONFDIR($r);
}
# ... and add it to the Makefile.
push(@code, qq{});
push(@code, qq{# Where to install config files});
push(@code, macro_def('SYSCONFDIR'));
foreach my $r (@REPOSITORIES) {
push(@code, macro_def($r . 'SYSCONFDIR'));
}
push(@code, qq{});
push(@code, qq{# Where to install local state files});
push(@code, macro_def('LOCALSTATEDIR'));
foreach my $r (@REPOSITORIES) {
push(@code, macro_def($r . 'LOCALSTATEDIR'));
}
foreach my $m (qw(DATA CONF)) {
foreach my $r (@REPOSITORIES) {
my $macro = 'INSTALL' . repository($r) . $m;
# The INSTALL* macros.
push(@code, macro_def($macro));
# The DESTINSTALL* macros.
push(@code, macro_def('DEST' . $macro, macro_ref('DESTDIR') . macro_ref($macro)));
}
}
}
# Set the PERL_* stuff
{
_set_macro_PERL_BIN;
_set_macro_PERL_WARN;
_set_macro_PERL_TAINT;
# Add it to the Makefile.
push(@code, qq{});
push(@code, qq{# Some details about our Perl});
foreach my $m (qw(BIN WARN TAINT)) {
push(@code, macro_def('PERL_' . $m));
}
}
# Set the preprocessor and configure scripts
{
_set_macro_PREPROCESS;
_set_macro_CONFIGURE;
_set_macro_SYMLINK;
# Add it to the Makefile.
push(@code, qq{});
push(@code, macro_def('PREPROCESS'));
push(@code, macro_def('CONFIGURE'));
push(@code, macro_def('SYMLINK'));
push(@code, macro_def('RE2C_BIN'));
}