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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
|
#!/usr/bin/perl
require 5.6.1;
use strict;
use warnings;
use Config;
use ExtUtils::MakeMaker 5.45;
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 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/perl5-porters@perl.org/msg94113.html>
# <https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=78053>
# <http://www.mail-archive.com/makemaker@perl.org/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',
'PERL_BIN', # Sets the Perl interpreter used by the scripts.
'PERL_VERSION', # Some parts in SpamAssassin were dependant on the version
'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.
'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,
'enable_ssl' => undef,
'contact_address' => undef,
'destdir' => undef,
);
ARGV: foreach (@ARGV) {
foreach my $key (keys %opt) {
my $val;
$val = parse_arg($_, uc($key));
if (defined $val) {
$opt{$key} = $val;
next ARGV;
}
}
}
# Gather some information about what EU::MM offers and/or needs
my(
$mm_version,
$mm_knows_destdir,
$mm_has_destdir,
$mm_has_good_destdir,
$mm_needs_destdir,
);
# Store the version for later use
$mm_version = $ExtUtils::MakeMaker::VERSION;
# MakeMaker prior to 6.11 doesn't support DESTDIR which is needed for
# packaging with builddir!=destdir. See bug 2388.
$mm_knows_destdir = $ExtUtils::MakeMaker::Recognized_Att_Keys{DESTDIR};
$mm_has_good_destdir = $mm_version >= 6.11;
# Add DESTDIR hack only if it's requested (and necessary)
$mm_needs_destdir = $opt{'destdir'} && !$mm_has_good_destdir;
$mm_has_destdir = $mm_knows_destdir || $mm_needs_destdir;
push(@ATT_KEYS, 'DESTDIR') if $mm_needs_destdir;
# Now make EU::MM understand our extended vars
foreach my $key (@ATT_KEYS) {
$ExtUtils::MakeMaker::Recognized_Att_Keys{$key} = 1;
}
# Gather the rules files in the range 00-69; we do this in perl because it's more portable
my @datafiles = map { s,^rules/,,; $_ } (<rules/*.cf>);
my $datafiles = join(' ', (grep { /^(?:[0-6][0-9]|72)_/ } @datafiles), qw(user_prefs.template triplets.txt languages sa-update-pubkey.txt));
# 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',
'spamc/spamc.c' => 'spamc/spamc$(EXE_EXT)',
'spamd/spamd.raw' => 'spamd/spamd',
},
'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)',
'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 => $datafiles,
},
# be quite explicit about this; afaik CPAN.pm is sensible using this
# also see CURRENT_PM below
'PREREQ_PM' => {
'Digest::SHA1' => 0, # 2.0 is oldest tested version
'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.24, # the HTML code is based on this parser
'Text::Wrap' => 98.112902, # this version is shipped with 5.005_03, the oldest version known to work
'Sys::Hostname' => 0,
'Time::Local' => 0,
'Errno' => 0,
},
'dist' => {
COMPRESS => 'gzip -9f',
SUFFIX => 'gz',
DIST_DEFAULT => 'tardist',
CI => 'svn commit',
RCS_LABEL => 'true',
},
'clean' => { FILES => join(' ' =>
'sa-learn', 'sa-update', 'spamassassin',
'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/config.cache', 'spamc/config.log', 'spamc/autom4te.cache',
'spamd/*spamc*', 'qmail',
'doc', 'pod2htm*',
'version.env',
't/bayessql.cf', 't/do_net', 't/log', 't/sql_based_whitelist.cf',
)
},
'AUTHOR' => 'The Apache SpamAssassin Project <dev at spamassassin.apache.org>',
'ABSTRACT' => '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,
# Don't add META.yml to the MANIFEST for god's sake!
'NO_META' => 1,
);
# That META.yml stuff was introduced with Perl 6.06_03, see
# <http://archive.develooper.com/makemaker@perl.org/msg00922.html>
# <http://archive.develooper.com/makemaker@perl.org/msg00984.html>
delete $makefile{'NO_META'} if $mm_version < 6.06_03;
# make sure certain optional modules are up-to-date if they are installed
# also see PREREQ_PM above
my %CURRENT_PM = (
'Net::DNS' => (RUNNING_ON_WINDOWS ? 0.46 : 0.34),
'Razor2::Client::Agent' => 2.40,
);
if ($mm_needs_destdir) {
my $error = <<DESTDIR_HACK;
***********************************************************************
ExtUtils::MakeMaker ${mm_version} doesn't include support for DESTDIR,
so if you want to be on the safe side, you might want to upgrade your
ExtUtils::MakeMaker to version 6.11 or later. It is available via CPAN.
You can use either the CPAN shell or go to
<http://search.cpan.org/search?module=ExtUtils::MakeMaker>
to get an up-to-date version.
This should only be necessary if you are creating binary packages.
***********************************************************************
DESTDIR_HACK
$error =~ s/^ {4}//gm;
warn $error;
}
elsif ($opt{'destdir'} and !$mm_has_good_destdir) {
my $error = <<DESTDIR_BUG;
***********************************************************************
ExtUtils::MakeMaker ${mm_version} contains bugs that may cause problems
in the \"make\" process. It is recommended that you upgrade
ExtUtils::MakeMaker to version 6.11 or later. It is available via CPAN.
You can use either the CPAN shell or go to
<http://search.cpan.org/search?module=ExtUtils::MakeMaker>
to get an up-to-date version.
This should only be necessary if you are creating binary packages.
***********************************************************************
DESTDIR_BUG
$error =~ s/^ {4}//gm;
warn $error;
}
# All the $(*MAN1*) stuff is empty/zero if Perl was Configured with -Dman1dir=none
unless($Config{installman1dir}) {
delete $makefile{MAN1PODS};
}
# Windows platforms need some adjustments
if (RUNNING_ON_WINDOWS) {
# Don't 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)",
'y'));
} 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 customise what tests are run, and how.
';
# check optional module versions
use lib 'lib';
use Mail::SpamAssassin::Util::DependencyInfo;
if (Mail::SpamAssassin::Util::DependencyInfo::long_diagnostics() != 0) {
# missing required module? die!
exit 1;
}
#######################################################################
# 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 ${mm_version}\n";
#######################################################################
package MY;
use vars qw(
$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/perl5-porters@perl.org/msg94113.html>
# <https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=78053>
# <http://www.mail-archive.com/makemaker@perl.org/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 <http://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 routine determines the value of the app given in PERL_BIN.
#
# There are no parameters.
#
# If PERL_VERSION wasn't set at the command line, it will try to call
# the app given in PERL_BIN and ask it for its version. If that doesn't
# work for some reason, it will use the version of the current Perl
# interpreter.
sub _set_macro_PERL_VERSION {
return if get_macro('PERL_VERSION');
my($perl, $ver);
#
$perl = get_expanded_macro('PERL_BIN');
if (-x $perl) {
$ver = qx{$perl -V:version};
$ver =~ s/^version='([0-9.]+).*$/$1/s;
}
$ver = $] unless $ver;
set_macro('PERL_VERSION', float_to_version($ver));
}
# 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');
set_macro('PREPROCESS', join(' ', macro_ref('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/;
# Now do the DESTDIR hack, if necessary.
next if !$mm_needs_destdir;
# Write the correct path to perllocal.pod
next if /installed into/;
# Replace all other $(INSTALL*) vars (except $(INSTALLDIRS) of course)
# with their $(DESTINSTALL*) counterparts
s/\Q$(\E(INSTALL(?!DIRS)${MACRO_RE})\Q)\E/\$(DEST$1)/g;
}
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);
}
}
}
if (line_has_macro_def($line, 'MM_VERSION')) {
# These macros are just for debugging purposes.
$line = join("\n", $line,
macro_def(MM_HAS_DESTDIR => ::yesno($mm_has_destdir)),
macro_def(MM_HAS_GOOD_DESTDIR => ::yesno($mm_has_good_destdir)),
macro_def(MM_KNOWS_DESTDIR => ::yesno($mm_knows_destdir)),
macro_def(MM_NEEDS_DESTDIR => ::yesno($mm_needs_destdir)),
);
}
# Add DESTDIR support if necessary
if ($mm_needs_destdir) {
if (line_has_macro_def($line, 'INSTALLDIRS')) {
$line .= "\n" . macro_def('DESTDIR');
}
elsif (line_has_macro_def($line, qr/INSTALL${MACRO_RE}/)) {
my $macro = get_macro_name_from_line($line);
$line .= "\n" . macro_def('DEST' . $macro,
macro_ref('DESTDIR') . macro_ref($macro));
}
}
}
push(@code, qq{});
# Add some additional target dirs
{
set_macro('SYSCONFDIR', "") unless get_macro('SYSCONFDIR');
set_macro('LOCALSTATEDIR', "") unless get_macro('LOCALSTATEDIR');
# 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)))
if $mm_has_destdir;
}
}
}
# Set the PERL_* stuff
{
_set_macro_PERL_BIN;
_set_macro_PERL_VERSION;
_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 VERSION 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'));
}
# Set some additional helper/shortcut macros; the B_FOO are the ones which
# can be temporary locations if DESTDIR is used, I_FOO are the final
# destinations.
{
my($repository);
$repository = uc($SELF->{INSTALLDIRS}) || 'SITE';
# For these the install paths are needed only.
foreach my $macro (qw(PREFIX SYSCONFDIR LOCALSTATEDIR)) {
push(@code, macro_def('I_' . $macro,
macro_ref($repository . $macro)));
}
# For the following we need bot the B_- and the I_-variants. But the
# SCRIPT macro is the same for all repositories.
foreach my $macro (qw(SCRIPT DATA CONF LIB)) {
push(@code, macro_def('I_' . $macro . 'DIR',
macro_ref('INSTALL' . repository($repository, $macro eq 'SCRIPT') . $macro)));
if ($mm_has_destdir) {
push(@code, macro_def('B_' . $macro . 'DIR',
macro_ref('DESTINSTALL' . repository($repository, $macro eq 'SCRIPT') . $macro)));
} else {
push(@code, macro_def('B_' . $macro . 'DIR',
macro_ref('I_' . $macro . 'DIR')));
}
}
}
clean_MY_globals($self);
return join("\n", @code);
}
# Override some vars in the dist section.
sub MY::dist {
my $self = shift;
my @code = split(/\n/, $self->SUPER::dist(@_));
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);
if (line_has_macro_def($line, 'DISTVNAME') && get_macro('VERSION_COOL')) {
set_macro('DISTVNAME', '$(DISTNAME)-$(VERSION_COOL)');
$line = macro_def('DISTVNAME');
}
}
clean_MY_globals($self);
return join("\n", @code);
}
sub MY::postamble {
my $self = shift;
my $code = "";
init_MY_globals($self);
$code .= <<' EOD';
FIXVARS = -Mvars \
-DVERSION="$(VERSION)" \
-DPREFIX="$(I_PREFIX)" \
-DDEF_RULES_DIR="$(I_DATADIR)" \
-DLOCAL_RULES_DIR="$(I_CONFDIR)" \
-DLOCAL_STATE_DIR="$(I_LOCALSTATEDIR)" \
-DINSTALLSITELIB="$(I_LIBDIR)" \
-DCONTACT_ADDRESS="$(CONTACT_ADDRESS)"
FIXBANG = -Msharpbang \
-DPERL_BIN="$(PERL_BIN)" \
-DPERL_WARN="$(PERL_WARN)" \
-DPERL_TAINT="$(PERL_TAINT)"
spamassassin: spamassassin.raw
$(PREPROCESS) $(FIXBYTES) $(FIXVARS) $(FIXBANG) -m$(PERM_RWX) -i$? -o$@
sa-learn: sa-learn.raw
$(PREPROCESS) $(FIXBYTES) $(FIXVARS) $(FIXBANG) -m$(PERM_RWX) -i$? -o$@
sa-update: sa-update.raw
$(PREPROCESS) $(FIXBYTES) $(FIXVARS) $(FIXBANG) -m$(PERM_RWX) -i$? -o$@
spamd/spamd: spamd/spamd.raw
$(PREPROCESS) $(FIXBYTES) $(FIXVARS) $(FIXBANG) -m$(PERM_RWX) -i$? -o$@
SPAMC_MAKEFILE = spamc/Makefile
MAKE_SPAMC = $(MAKE) -f $(SPAMC_MAKEFILE)
MAKE_SPAMC_OLD = $(MAKE) SOURCE=$< TARGET=$@ spamc_has_moved
SPAMC_SRC = spamc/spamc.c spamc/utils.c
QSPAMC_SRC = spamc/qmail-spamc.c spamc/utils.c
LIBSPAMC_SRC = spamc/libspamc.c spamc/utils.c
$(SPAMC_MAKEFILE): $(SPAMC_MAKEFILE).in $(SPAMC_MAKEFILE).win spamc/spamc.h.in
$(CONFIGURE) --prefix="$(I_PREFIX)" --sysconfdir="$(I_CONFDIR)" --datadir="$(I_DATADIR)" --enable-ssl="$(ENABLE_SSL)"
spamc_has_moved:
$(NOECHO) echo "***"
$(NOECHO) echo "*** spamc now has its own directory: $(TARGET) is $(SOURCE)"
$(NOECHO) echo "***"
$(PERL) -MFile::Spec -MFile::Copy \
-e "copy(q{$(SOURCE)}, q{$(TARGET)});"
spamc/libspamc.so: $(SPAMC_MAKEFILE) $(LIBSPAMC_SRC)
$(MAKE_SPAMC) $@
spamd/libspamc.so: spamc/libspamc.so
$(MAKE_SPAMC_OLD)
spamc/libsslspamc.so: $(SPAMC_MAKEFILE) $(LIBSPAMC_SRC)
$(MAKE_SPAMC) $@
spamd/libsslspamc.so: spamc/libsslspamc.so
$(MAKE_SPAMC_OLD)
spamc/spamc$(EXE_EXT): $(SPAMC_MAKEFILE) $(SPAMC_SRC) $(LIBSPAMC_SRC)
$(MAKE_SPAMC) $@
spamd/spamc$(EXE_EXT): spamc/spamc$(EXE_EXT)
$(MAKE_SPAMC_OLD)
$(CHMOD) $(PERM_RWX) $@
spamc/qmail-spamc$(EXE_EXT): $(SPAMC_MAKEFILE) $(QSPAMC_SRC)
$(MAKE_SPAMC) $@
qmail/qmail-spamc$(EXE_EXT): spamc/qmail-spamc$(EXE_EXT)
$(MKPATH) qmail
$(MAKE_SPAMC_OLD)
$(CHMOD) $(PERM_RWX) $@
# needs to be added to MY::install if used
#bin__install: $(INST_SCRIPT)/sa-filter
# # $(RM_F) $(B_SCRIPTDIR)/spamassassin
# # $(SYMLINK) $(INST_SCRIPT)/sa-filter $(B_SCRIPTDIR)/spamassassin
conf__install:
-$(MKPATH) $(B_CONFDIR)
$(PERL) -MFile::Copy -e "copy(q{rules/local.cf}, q{$(B_CONFDIR)/local.cf}) unless -f q{$(B_CONFDIR)/local.cf}"
$(PERL) -MFile::Copy -e "copy(q{rules/init.pre}, q{$(B_CONFDIR)/init.pre}) unless -f q{$(B_CONFDIR)/init.pre}"
$(PERL) -MFile::Copy -e "copy(q{rules/v310.pre}, q{$(B_CONFDIR)/v310.pre}) unless -f q{$(B_CONFDIR)/v310.pre}"
$(PERL) -MFile::Copy -e "copy(q{rules/v312.pre}, q{$(B_CONFDIR)/v312.pre}) unless -f q{$(B_CONFDIR)/v312.pre}"
data__install:
-$(MKPATH) $(B_DATADIR)
$(PERL) -e "map unlink, <$(B_DATADIR)/*>"
$(PREPROCESS) $(FIXVARS) -m$(PERM_RW) -Irules -O$(B_DATADIR) $(DATAFILES)
$(CHMOD) $(PERM_RWX) $(B_DATADIR)
text_html_doc: made-doc-stamp
$(NOOP)
doc:
$(MKPATH) $@
made-doc-stamp: doc $(MAN1PODS) $(MAN3PODS) $(EXTRAPODS)
$(PERL) build/convert_pods_to_doc $(MAN1PODS) $(MAN3PODS) $(EXTRAPODS)
$(TOUCH) made-doc-stamp
$(RM_F) pod2htm*
version.env: lib/Mail/SpamAssassin.pm Makefile
$(RM_F) $@
$(PERL) -Ilib -MMail::SpamAssassin -e 'printf("FULL_VERSION=%s\n", Mail::SpamAssassin::Version())' >> $@
$(PERL) -e 'print "DIST_VERSION=$(VERSION_COOL)\n"' >> $@
$(PERL) -e 'print "CPAN_VERSION=$(VERSION)\n"' >> $@
manifest_skip:
sort -f < MANIFEST.SKIP > MANIFEST.SKIP.tmp
mv MANIFEST.SKIP.tmp MANIFEST.SKIP
sysreport:
$(NOECHO) $(PERL) tools/sysreport CC=$(CC) PERL=$(PERL) PERL_BIN=$(PERL_BIN) PERL_VERSION=$(PERL_VERSION)
EOD
clean_MY_globals($self);
return $code;
}
|