forked from jettero/crypt--pbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.PL
160 lines (123 loc) · 4.43 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
use strict;
use lib qw(inc);
use Devel::CheckLib;
use ExtUtils::MakeMaker;
my @libpath = qw(/lib /usr/lib /usr/local/lib);
my @incpath = qw(/usr/include/pbc /usr/local/include/pbc /usr/include /usr/local/include);
my $ver = "0.5.14";
my @extra = (
LIBS => ['-lpbc'],
INC => join(" ", map {"-I$_"} (@incpath)),
);
eval { assert_lib( lib => 'pbc', libpath=>\@libpath, incpath=>\@incpath, header => "pbc.h" ); };
if( $@ ) {
warn "Error locating libpbc version 0.5.1: $@";
warn "\nYou can get the latest debian binaries from http://crypto.stanford.edu/pbc/files/\n\n";
sleep 1;
my $res = ($ENV{BUILD_HERE} || prompt("Would you like to download and build libpbc from tarball automatically? [y/N]", "n"));
if( $res =~ m/y/i ) {
exit 0 unless grab_libpbc($ver);
exit 0 unless unpack_libpbc($ver);
exit 0 unless build_libpbc($ver);
} else {
exit 0;
}
}
WriteMakefile(
NAME => 'Crypt::PBC',
VERSION_FROM => 'PBC.pm',
PREREQ_PM => {
'MIME::Base64' => 0,
'Math::BigInt::GMP' => 0,
'Math::BigInt' => 0,
},
($] >= 5.005 ?
(ABSTRACT_FROM => 'lib/Crypt/PBC.pod',
AUTHOR => 'Paul Miller <[email protected]>') : ()),
($ExtUtils::MakeMaker::VERSION ge '6.48'?
(MIN_PERL_VERSION => 5.006001,
META_MERGE => {
keywords => [qw(pbc ecc crypt boneh ibe)],
resources=> {
repository => 'http://github.com/jettero/crypt--pbc/',
},
},
LICENSE => 'LGPL',
) : ()),
@extra,
clean => { FILES => "libpbc.a .pbctest pbc-$ver.tar.gz pbc-$ver slamtest.log " . join(" ", grep {s/\.c$//} <*.c>) },
depend => {
"PBC.c" => " earith.xs ecomp.xs einit.xs pairing.xs ",
},
);
sub build_libpbc {
my $ver = shift;
@extra = (
MYEXTLIB => "libpbc.a",
INC => "-Ipbc-$ver/include",
LIBS => "-lgmp",
);
warn "(You do need libgmp installed in order for this PBC.so to function...)\n";
check_lib_or_exit( lib => 'gmp', libpath=>\@libpath, incpath=>\@incpath, header=>"gmp.h" );
warn "(... it seems you have libgmp. Nevermind.)\n";
# we don't literally build it, we add things to the makefile
*MY::postamble = \&postamble;
}
sub postamble {
my @CFLAGS = map {"-I$_"} @incpath;
my @LFLAGS = map {"-L$_"} @libpath;
"
PBC\$(OBJ_EXT) : \$(MYEXTLIB)
\$(MYEXTLIB): pbc-$ver/.libs/libpbc.so
\$(AR) \$(AR_STATIC_ARGS) \$@ pbc-$ver/.libs/*.o
pbc-$ver/.libs/libpbc.so:
cd pbc-$ver && CFLAGS='@CFLAGS' CPPFLAGS='@CFLAGS' LDFLAGS='@LFLAGS' ./configure && \$(MAKE) \$(PASTHRU)
";
}
sub unpack_libpbc {
my $ver = shift;
return 1 if -d "pbc-$ver" or $ENV{SKIP_DOWNLOAD};
warn "unpacking libpbc from pbc-$ver.tar.gz...\n";
my $worked = 0;
eval {
eval "require Archive::Tar;"; die $@ if $@;
my $tar = Archive::Tar->new;
$tar->read("pbc-$ver.tar.gz", 1);
$tar->extract;
$worked = 1 if -x "pbc-$ver/configure";
};
warn "Archive::Tar unpack problem: $@\n" if $@;
unless( $worked ) {
if( system("gzip -dc pbc-$ver.tar.gz | tar -xvf -") == 0 ) {
$worked = 1 if -x "pbc-$ver/configure";
}
}
warn "failed to unpack pbc\n" unless $worked;
$worked;
}
sub grab_libpbc {
my $ver = shift;
return 1 if -f "pbc-$ver.tar.gz" or $ENV{SKIP_DOWNLOAD};
warn "downloading libpbc from http://crypto.stanford.edu/pbc/files/pbc-$ver.tar.gz...\n";
my $worked = 0;
eval {
eval "require LWP::UserAgent"; die $@ if $@;
my $ua = LWP::UserAgent->new;
$ua->agent("crypt-pbc-fetcher/1.0");
my $req = HTTP::Request->new(GET => "http://crypto.stanford.edu/pbc/files/pbc-$ver.tar.gz");
my $res = $ua->request($req, "pbc-$ver.tar.gz");
$worked = 1 if $res->is_success;
};
warn "LWP fetch problem: $@\n" if $@;
unless( $worked ) {
if( 0 != system(wget => '-O', "pbc-$ver.tar.gz", "http://crypto.stanford.edu/pbc/files/pbc-$ver.tar.gz") ) {
warn "couldn't fetch with wget...\n";
if( 0 != system(curl => '-o', "pbc-$ver.tar.gz", "http://crypto.stanford.edu/pbc/files/pbc-$ver.tar.gz") ) {
warn "couldn't fetch with curl ...\n";
}
}
$worked = 1 if -f "pbc-$ver.tar.gz";
}
warn "failed to download pbc\n" unless $worked;
$worked;
}