forked from bitwiseshiftleft/sjcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·149 lines (127 loc) · 3.84 KB
/
configure
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
#!/usr/bin/env perl
use strict;
my ($arg, $i, $j, $targ);
my @targets = qw/sjcl aes bitArray codecString codecHex codecBase32 codecBase64 codecBytes sha256 sha512 sha1 ccm ctr cbc ocb2 ocb2progressive gcm hmac pbkdf2 scrypt random convenience bn ecc srp ccmArrayBuffer codecArrayBuffer ripemd160/;
my %deps = ('aes'=>'sjcl',
'bitArray'=>'sjcl',
'codecString'=>'bitArray',
'codecHex'=>'bitArray',
'codecBase64'=>'bitArray',
'codecBase32'=>'bitArray',
'codecBytes'=>'bitArray',
'sha256'=>'codecString',
'sha512'=>'codecString',
'sha1'=>'codecString',
'ripemd160' => 'codecString',
'ccm'=>'bitArray,aes',
'ctr'=>'bitArray,aes',
'ocb2'=>'bitArray,aes',
'ocb2progressive'=>'ocb2',
'gcm'=>'bitArray,aes',
'hmac'=>'sha256',
'pbkdf2'=>'hmac',
'scrypt'=>'pbkdf2,codecBytes',
'srp'=>'sha1,bn,bitArray',
'bn'=>'bitArray,random',
'ecc'=>'bn',
'cbc'=>'bitArray,aes',
'random'=>'sha256,aes',
'convenience'=>'ccm,pbkdf2,random,codecBase64',
'ccmArrayBuffer'=>'bitArray,codecArrayBuffer',
'codecArrayBuffer'=>'bitArray');
my $compress = "closure";
my %enabled = ();
$enabled{$_} = 0 foreach (@targets);
# by default, all but codecBytes, srp, bn
$enabled{$_} = 1 foreach (qw/aes bitArray codecString codecHex codecBase32 codecBase64 sha256 ccm ocb2 gcm hmac pbkdf2 random convenience/);
# argument parsing
while (my $arg = shift @ARGV) {
if ($arg =~ /^--?with-all$/) {
foreach (@targets) {
if ($enabled{$_} == 0) {
$enabled{$_} = 1;
}
}
} elsif ($arg =~ /^--?without-all$/) {
foreach (@targets) {
if ($enabled{$_} == 1) {
$enabled{$_} = 0;
}
}
} elsif ($arg =~ /^--?with-(.*)$/) {
$targ = $1;
$targ =~ s/-(.)/uc $1/ge;
if (!defined $deps{$targ}) {
print STDERR "No such target $targ\n";
exit 1;
}
$enabled{$targ} = 2;
} elsif ($arg =~ /^--?without-(.*)$/) {
$targ = $1;
$targ =~ s/-(.)/uc $1/ge;
if (!defined $deps{$targ}) {
print STDERR "No such target $targ\n";
exit 1;
}
$enabled{$targ} = -1;
} elsif ($arg =~ /^--?compress(?:or|ion)?=(none|closure|yui)$/) {
$compress = $1;
} else {
my $targets = join " ", @targets;
$targets =~ s/sjcl //;
$targets =~ s/(.{50})\s+/$1\n /g;
print STDERR <<EOT;
Usage: $0 arguments...
Valid arguments are:
--with-all: by default, include all targets
--without-all: by default, include no targets
--compress=none|closure|yui
--with-TARGET: require TARGET
--without-TARGET: forbid TARGET
--help: show this message
Valid targets are:
$targets
EOT
exit 1 unless $arg =~ /^--?help$/;
exit 0;
}
}
my $config = '';
my $pconfig;
# dependency analysis: forbidden
foreach my $i (@targets) {
if ($enabled{$i} > 0) {
foreach $j (split /,/, $deps{$i}) {
if ($enabled{$j} == -1) {
if ($enabled{$i} == 2) {
print STDERR "Conflicting options: $i depends on $j\n";
exit 1;
} else {
$enabled{$i} = -1;
last;
}
}
}
}
}
# reverse
foreach my $i (reverse @targets) {
if ($enabled{$i} > 0) {
foreach $j (split /,/, $deps{$i}) {
if ($enabled{$j} < $enabled{$i}) {
$enabled{$j} = $enabled{$i};
}
}
$config = "$i $config";
}
}
open CONFIG, "> config.mk" or die "$!";
($pconfig = $config) =~ s/^sjcl //;
$pconfig =~ s/ /\n /g;
print "Enabled components:\n $pconfig\n";
print "Compression: $compress\n";
$config =~ s=\S+=core/$&.js=g;
print CONFIG "SOURCES= $config\n";
$compress = "core_$compress.js";
$compress = 'core.js' if ($compress eq 'core_none.js');
print CONFIG "COMPRESS= $compress\n";