File: Makefile.PL

package info (click to toggle)
libmail-cclient-perl 1.12-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 744 kB
  • sloc: perl: 426; ansic: 349; makefile: 17
file content (159 lines) | stat: -rw-r--r-- 4,961 bytes parent folder | download | duplicates (3)
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
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
# Last Modification: Wed Oct  6 13:30:32 WEST 2004
use ExtUtils::MakeMaker;
use Getopt::Long();
use vars qw($opt);

my ($CCLIENTLIBS, $CCLIENT_DIR, $PAM_DIR, $SSL_DIR, $KRB_DIR, $IMAP_DIR);
my @objects = ();

my $opt = {};
Getopt::Long::GetOptions($opt,
	"help"                    => \&usage,
	"cclient_dir=s"           => \$CCLIENT_DIR,
	"with-shared_cclient"     => sub { $CCLIENTLIBS = " -lc-client"; },
	"with-pam:s"              => \$PAM_DIR,
	"with-ssl:s"              => \$SSL_DIR,
	"with-kerberos:s"         => \$KRB_DIR,
	"with-cclient-includes=s" => \$IMAP_DIR,
) or die <<EOUSAGE;
usage: $0

  --cclient_dir=/path/to/c-client
  --with-shared_cclient
  --with-pam=/path/to/libs (path optional)
  --with-ssl=/path/to/libs (path optional)
  --with-kerberos=/path/to/libs (path optional)
  --with-cclient-includes=/path/to/imap_includes
  --help

EOUSAGE

unless($CCLIENTLIBS) {
	die "Missing cclient_dir: --cclient_dir=<dir> [--help]\n"
		unless($CCLIENT_DIR);
	die "CCLIENT_DIR $CCLIENT_DIR does not contain c-client.a\n"
		if(!-r "$CCLIENT_DIR/c-client.a");
}

my %headers = ();
my $osname = lc($^O);
my @libs = "-lc";
push(@libs, "-lm") if($osname eq "aix");
$LIBS = join(" ", @libs);

if($CCLIENTLIBS) {
	print "configure with shared c-client:$CCLIENTLIBS\n";
	$LIBS .= $CCLIENTLIBS;
	if($IMAP_DIR) {
		$CCLIENT_DIR = $IMAP_DIR;
		$headers{'HAVE_IMAP_LINKAGE'} = 1 if(-e "$IMAP_DIR/linkage.c");
	}
}
if(defined($PAM_DIR)) {
	my $tmp = " -L$PAM_DIR" if($PAM_DIR);
	$tmp .= " -lpam -lpam_misc";
	print "configure with pam:$tmp\n";
	$LIBS .= $tmp;
}
if(defined($SSL_DIR)) {
	my $tmp = " -L$SSL_DIR" if($SSL_DIR);
	$tmp .= " -lcrypto -lssl";
	print "configure with ssl:$tmp\n";
	$LIBS .= $tmp;
	$headers{'HAVE_IMAP_SSL'} = 1;
}

if(defined($KRB_DIR)) {
	my $tmp = " -L$KRB_DIR" if($KRB_DIR);
	$tmp .= " -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err";
	print "configure with kerberos:$tmp\n";
	$LIBS .= $tmp;
}

unlink("Cclient.h") if(-e "Cclient.h");
open(HEADERS, ">", "Cclient.h") or die("$!");
while(my ($key, $value) = each(%headers)) {
	print HEADERS "#define $key $value\n";
}
close(HEADERS);

unless($CCLIENTLIBS) {
	#
	# We want to turn Cclient.o (ours) plus the object files in the
	# $CCLIENT_DIR/c-client.a archive into a shared object. Simply
	# including both in the MakeMaker OBJECT list works fine for Linux
	# but under Digital UNIX, the combination of its ar and "ld -shared"
	# can't cope with simply "ar cr tmp.a Cclient.o .../c-client.a".
	# To get around that look at the contents of the c-client.a archive
	# and extract all .o files from it into the current directory. Then
	# we set OBJECT to be our Cclient.o plus all of those. Blech.
	#

	my @contents = ();
	print "Examining archive file $CCLIENT_DIR/c-client.a...\n";   
	chomp(@contents = `ar t $CCLIENT_DIR/c-client.a`);
	@objects = grep(/\.o$/, @contents);
	print "Extracting object files from archive: ", join(", ", @objects), "\n";
	system("ar", "x", "$CCLIENT_DIR/c-client.a", @objects);

	my $err = $? >> 8;
	if ($err) {
		print <<END_OF_TEXT;
Extraction failed: ar returned exit code $err
Please extract them manually into the current directory
edit Makefile.PL to remove this section of code and then rerun
    perl Makefile.PL
END_OF_TEXT
		exit(1);
	}
	print "Extraction was apparently successful\n";
}
unshift(@objects, "criteria.o", "Cclient.o");

WriteMakefile(
	NAME         => "Mail::Cclient",
	VERSION_FROM => "Cclient.pm",
	INC          => "-I$CCLIENT_DIR",
	LIBS         => ["$LIBS"],
	OBJECT       => "@objects"
);

exit(0);

sub usage {
	print STDERR <<"USAGE";
Usage: perl $0 [options]

Possible options are:

  --cclient_dir=<dir>           Where <dir> is the pathname of the
                                directory which contains the c-client.a
                                archive library which you have just built.

  --with-shared_cclient         Configure with support for a shared
                                c-client library

  --with-pam=<dir>              Configure with support for PAM.
                                Where <dir> is the pathname of the
                                directory which contains the libs.
                                <dir> is optional.

  --with-ssl=<dir>              Configure with support for SSL
                                Where <dir> is the pathname of the
                                directory which contains the libs.
                                <dir> is optional.

  --with-kerberos=<dir>         Configure with support for Kerberos
                                Where <dir> is the pathname of the
                                directory which contains the libs.
                                <dir> is optional.

  --with-cclient-includes=<dir> Where the c-client header files live

  --help                        Print this message and exit

USAGE
  exit 1;
}